1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef FILLP_CALLBACKS_H
17#define FILLP_CALLBACKS_H
18
19#include "fillptypes.h"
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/**
25 * @ingroup Callbacks
26 * @brief
27 * This callback is for calloc system function to allocate the requested memory.
28 *
29 * @param[in] items Indicates the number of elements to be allocated.
30 * @param[in] size size of elements.
31 * @return
32 * This function returns a pointer to the allocated memory or return NULL in case of failure of the request.
33 */
34typedef void  *(*FillpMemCallocFunc)(IN FILLP_UINT32 items, IN FILLP_UINT32 size);
35
36/**
37 * @ingroup Callbacks
38 * @brief
39 * This callback is for malloc system function to allocate the requested memory.
40 *
41 * @param[in] size Indicates the memory size to be allocated.
42 * @return
43 * This function returns a pointer to the allocated memory or returns NULL if the request fails.
44 */
45typedef void *(*FillpMemAllocFunc)(IN FILLP_UINT32 size);
46
47/**
48 * @ingroup Callbacks
49 * @brief
50 * This callback is for free system function to free the memory block.
51 *
52 * @param[in] addr Indicates the address of the memory to be freed.
53 * @return
54 * On success : FILLP_SUCCESS
55 * On failure : other error codes.
56 */
57typedef void (*FillpMemFreeFunc)(IN void *addr);
58
59/**
60 * @ingroup Callbacks
61 * @brief
62 * This is a callback for memset_s system function to fill the specified memory block with the specified characters.
63 *
64 * @param[in] dest Pointer to destination memory buffer.
65 * @param[in] destMax Length of destination memory buffer.
66 * @param[in] character Character to be set.
67 * @param[in] count Number of bytes to set.
68 * @return
69 * On success : FILLP_SUCCESS
70 * On failure : other error codes.
71 */
72typedef FILLP_INT (*FillpMemSetFunc)(void *dest, size_t destMax, int c, size_t count);
73
74/**
75 * @ingroup Callbacks
76 * @brief
77 * This callback is for memcpy_s system function to copy memory.
78 *
79 * @param[out] dest Indicates a pointer to the destination memory buffer.
80 * @param[in] destMax Indicates the size of the destination memory buffer.
81 * @param[in] src Indicates a pointer to the source memory buffer.
82 * @param[in] count Indicates the number of bytes to copy.
83 * @return
84 * On success : FILLP_SUCCESS
85 * On failure : other error codes.
86 */
87typedef FILLP_INT (*FillpMemCopyFunc)(void *dest, size_t destMax, const void *src, size_t count);
88
89/**
90 * @ingroup Callbacks
91 * @brief
92 * This callback is for string concatenations system function to concatenate strings.
93 *
94 * @param[out] dest Indicates a pointer to the destination memory buffer.
95 * @param[in] destMax Indicates the length of the destination memory buffer.
96 * @param[in] src Indicates a pointer to the source memory buffer.
97 * @param[in] count Indicates the number of bytes to be copy.
98 * @return
99 * On success : 0
100 * On failure : other error codes.
101 */
102typedef FILLP_INT (*FillpStrncatFunc)(char *strDest, size_t destMax, const char *strSrc, size_t count);
103
104/**
105 * @ingroup Callbacks
106 * @brief
107 * Callback for string copy system function.
108 *
109 * @param[out] dest Indicates a pointer to  the  destination memory buffer.
110 * @param[in] destMax Indicates the length of the destination memory buffer.
111 * @param[in] src Indicates a pointer to the source memory buffer.
112 * @param[in] count Indicates the number of bytes to be copied.
113 * @return
114 * On success : 0
115 * On truncation : STRUNCATE
116 * On failure : other error codes.
117 */
118typedef FILLP_INT (*FillpStrncpyFunc)(char *strDest, size_t destMax, const char *strSrc, size_t count);
119
120/**
121 * @ingroup Callbacks
122 * @brief
123 * This is a callback for strlen system function to get the length of a string.
124 *
125 * @param[in] str Pointer to string.
126 * @return
127 * This returns length of the string.
128 */
129typedef FILLP_UINT32 (*FillpStrLenFunc)(IN FILLP_CHAR *str);
130
131/**
132 * @ingroup Callbacks
133 * @brief
134 * This is a callback for select system function to allow a program to check multiple file descriptors.
135 *
136 * @param[in] maxFd Indicates the fd value to be selected.
137 * @param[in] readFds Indicates the fd for read.
138 * @param[in] writeFds Indicates the fd for write.
139 * @param[out] exceptFds Indicates the fd for errors.
140 * @param[in] timeVal Indicates the max time for select to wait.
141 * @return
142 * On success : Total number of socket handles that are ready.
143 * On failure : other error codes.
144 */
145typedef FILLP_INT (*FillpSelectFunc)(IN FILLP_INT maxFd, IN void *readFds,
146    IN void *writeFds, IO void *exceptFds, IN void *timeVal);
147
148/**
149 * @ingroup Callbacks
150 * @brief
151 * This callback is for the ioctl socket to control the I/O mode of a socket.
152 *
153 * @param[in] fd Indicates the connection fd.
154 * @param[in] cmd Indicates the command to perform on socket.
155 * @param[in] args Indicates arguments for socket.
156 * @return
157 * On success : 0
158 * On failure : other error codes.
159 */
160typedef FILLP_INT (*FillpIoctlFunc)(IN FILLP_INT fd, IN FILLP_INT cmd, IN FILLP_ULONG *args);
161
162/**
163 * @ingroup Callbacks
164 * @brief
165 * This callback is for the fcntl system function to manipulate file descriptor.
166 *
167 * @param[in] fd Indicates a connection file descriptor.
168 * @param[in] cmd Indicates the command to perform on socket.
169 * @param[in] val Indicates the arguments for socket.
170 * @return
171 * On success : value based on command
172 * On failure : other error codes.
173 */
174typedef FILLP_INT (*FillpFcntlFunc)(IN FILLP_INT fd, IN FILLP_INT cmd, IN FILLP_INT val);
175
176/**
177 * @ingroup Callbacks
178 * @brief
179 * This callback is to set the socket option.
180 *
181 * @param[in] fd Indicates the socket file descriptor.
182 * @param[in] level Indicates the socket level.
183 * @param[in] optName Indicates the socket option name.
184 * @param[in] optVal Indicates the socket option value.
185 * @param[in] optLen Indicates the socket option length.
186 * @return
187 * On success : FILLP_SUCCESS
188 * On failure : other error codes.
189 */
190typedef FILLP_INT (*FillpSetSockOptFunc)(IN FILLP_INT fd, IN FILLP_INT level,
191    IN FILLP_INT optName, IN FILLP_CONST void *optVal, IN FILLP_INT optLen);
192
193/**
194 * @ingroup Callbacks
195 * @brief
196 * This callback is to get the socket options.
197 *
198 * @param[in] fd Indicates the socket file descriptor.
199 * @param[in] level Indicates the socket level.
200 * @param[in] optName Indicates the socket option name.
201 * @param[out] optVal Indicates the socket option value.
202 * @param[out] optLen Indicates the socket option length.
203 * @return
204 * On success : FILLP_SUCCESS
205 * On failure : other error codes.
206 */
207typedef FILLP_INT (*FillpGetSockOptFunc)(IN FILLP_INT fd, IN FILLP_INT level,
208    IN FILLP_INT optName, IO void *optVal, IO FILLP_INT *optLen);
209
210/**
211 * @ingroup Callbacks
212 * @brief
213 * This callback is for the rand system function to generate random number.
214 *
215 * @return
216 * On success : integer value between 0 and RAND_MAX
217 * On failure : other error codes.
218 */
219typedef FILLP_UINT32 (*FillpRandFunc)(IN void);
220
221/**
222 * @ingroup Callbacks
223 * @brief
224 * This callback is for generating the cryptographic quality random number.
225 *
226 * @return
227 * On success : integer value between 0 and RAND_MAX
228 * On failure : other error codes.
229 */
230typedef FILLP_UINT32 (*FillpCryptoRandFunc)(IN void);
231
232/**
233 * @ingroup Callbacks
234 * @brief
235 * This callback is for memchr system function to search the first occurrence of the character
236 * in the first n bytes of the string.
237 *
238 * @param[in] fd Indicates the pointer to the block of memory where the search is performed.
239 * @param[in] c Indicates the value to be passed as an int, but the function performs a
240 * byte by per byte search using the unsigned char conversion of this value.
241 * @param[in] n Indicates the number of bytes to be analyzed.
242 * @return
243 * This returns a pointer to the matching byte or FILLP_NULL_PTR if the character does not
244 * occur in the given memory area.
245 */
246typedef void *(*FillpMemChrFunc)(IN FILLP_CONST void *fd, IN FILLP_INT c, IN FILLP_SIZE_T n);
247
248/**
249 * @ingroup Callbacks
250 * @brief
251 * This callback is to create the thread.
252 *
253 * @param[in] param Indicates a pointer to the ThreadParam struct.
254 * @param[out] threadId O|Indicates the thread ID.
255 * @return
256 * On success : 0
257 * On failure : other error codes.
258 */
259typedef FILLP_INT (*FillpCreateThreadFunc)(IN void *param, IO void *threadId);
260
261/**
262 * @ingroup Callbacks
263 * @brief
264 * This is a callback for the system architecture initialization function.
265 *
266 * @return
267 * On success : ERR_OK
268 * On failure : ERR_FAILURE.
269 */
270typedef FILLP_INT (*FillpSysArcInitFunc)(IN void);
271
272/**
273 * @ingroup Callbacks
274 * @brief
275 * This callback is to get the system current time in long format.
276 *
277 * @return
278 * On success : FILLP_SUCCESS
279 * On failure : error.
280 */
281typedef FILLP_LLONG (*FillpSysArcGetCurTimeFunc)(IN void);
282
283/**
284 * @ingroup Callbacks
285 * @brief
286 * This callback is to increment(increases by 1) the value of the specified variable as an atomic operation.
287 *
288 * @param[in,out] var Indicates the variable to increment.
289 * @param[in] val Indicates the value of the variable.
290 * @return
291 * Returns the resulting incremented value.
292 */
293typedef FILLP_INT (*FillpSysArchAtomicIncFunc)(IO SysArchAtomic *var, FILLP_INT val);
294
295/**
296 * @ingroup Callbacks
297 * @brief
298 * This callback is to increment(increases by 1) the value of the specified variable and
299 * test whether the resulting incremented value is 0 as an atomic operation.
300 *
301 * @param[in,out] var Indicates the variable to increment.
302 * @return
303 * Returns the checking result whether the resulting incremented value is 0 or not.
304 */
305typedef FILLP_BOOL (*FillpSysArchAtomicIncAndTestFunc)(IO SysArchAtomic *var);
306
307/**
308 * @ingroup Callbacks
309 * @brief
310 * This callback is to decrement(decreases by 1) the value of the specified variable as an atomic operation.
311 *
312 * @param[in,out] var Indicates the variable to decrement.
313 * @param[in] val Indicates the value of the variable.
314 * @return
315 * It returns the resulting decremented value.
316 */
317typedef FILLP_INT (*FillpSysArchAtomicDecFunc)(IO SysArchAtomic *var, FILLP_INT val);
318
319/**
320 * @ingroup Callbacks
321 * @brief
322 * This callback is to decrement(decreases by 1) the value of the specified variable and
323 * test whether the resulting decremented value is 0 as an atomic operation.
324 *
325 * @param[in,out] var Indicates the variable to increment.
326 * @return
327 * Returns the checking result whether the resulting decremented value is 0 or not.
328 */
329typedef FILLP_BOOL (*FillpSysArchAtomicDecAndTestFunc)(IO SysArchAtomic *var);
330
331/**
332 * @ingroup Callbacks
333 * @brief
334 * This callback is to read the value of the specified variable as an atomic operation.
335 *
336 * @param[out] var Variable to read.
337 * @return
338 * This return the read atomic variable.
339 */
340typedef FILLP_INT (*FillpSysArchAtomicReadFunc)(IO SysArchAtomic *var);
341
342/**
343 * @ingroup Callbacks
344 * @brief
345 * This callback is to set the value of the specified variable as an atomic operation.
346 *
347 * @param[in] var A pointer to the value to be exchanged.
348 * @param[in] newValue The value to be exchanged with the value pointed to by var.
349 * @return
350 * It return the initial value of var parameter.
351 */
352typedef FILLP_INT (*FillpSysArchAtomicSetFunc)(IN SysArchAtomic *var, IN FILLP_INT newValue);
353
354/**
355 * @ingroup Callbacks
356 * @brief
357 * This callback is to perform an atomic compare-and-exchange operation on the specified values.
358 *
359 * @param[out] sem Indicates a pointer to the destination value.
360 * @param[in] oldValue Indicates the exchange value.
361 * @param[in] newValue Indicates the value to compare to sem.
362 * @return
363 * This returns the initial value of sem parameter.
364 */
365typedef FILLP_INT (*FillpSysArchCompAndSwapFunc)(IO volatile FILLP_ULONG *sem,
366    IN volatile FILLP_ULONG oldValue, IN volatile FILLP_ULONG newValue);
367
368/**
369 * @ingroup Callbacks
370 * @brief
371 * This callback is for sleep system function.
372 *
373 * @param[in] time The time interval(in milliseconds)for which execution is to be suspended.
374 * @return
375 * void
376 */
377typedef void (*FillpSysSleepMsFunc)(IN FILLP_UINT time); /* In Millseconds */
378
379/**
380 * @ingroup Callbacks
381 * @brief
382 * This callback for the usleep system function to suspend execution for microsecond intervals.
383 *
384 * @param[in] time The time interval for which execution is to be suspended, in microseconds.
385 * @return
386 * It returns 0 on success or -1 on error.
387 */
388typedef FILLP_INT (*FillpSysUSleepFunc)(IN FILLP_UINT time); /* us */
389
390/**
391 * @ingroup Callbacks
392 * @brief
393 * This callback is for _mm_pause function to PAUSE instruction for tight loops (avoid busy waiting).
394 *
395 * @return
396 * void
397 */
398typedef void (*FillpRtePauseFunc)(void);
399
400/**
401 * @ingroup Callbacks
402 * @brief
403 * This callback is for init_sem system function to initialize the semaphore.
404 *
405 * @param[in] sem Indicates a pointer to semaphore.
406 * @param[in] value Indicates the value of the initialized semaphore.
407 * @return
408 * Initialize the semaphore in sem on successful or error on failure.
409 */
410typedef FILLP_INT (*FillpSemFunc)(IO SYS_ARCH_SEM *sem, IN FILLP_ULONG value);
411
412/**
413 * @ingroup Callbacks
414 * @brief
415 * This callback is to lock the semaphore referenced by sem only if the semaphore is currently not locked.
416 *
417 * @param[out] sem Indicates a pointer to a semaphore to be locked.
418 * @return
419 * On success : FILLP_SUCCESS
420 * On failure : error.
421 */
422typedef FILLP_INT (*FillpSemTryWaitFunc)(IN SYS_ARCH_SEM *sem);
423
424/**
425 * @ingroup Callbacks
426 * @brief
427 * This callback is to lock the semaphore referenced by sem by performing a semaphore lock operation on that semaphore.
428 *
429 * @param[in] sem Indicates a pointer to a semaphore to be locked.
430 * @return
431 * On success : FILLP_SUCCESS
432 * On failure : error.
433 *
434 */
435typedef FILLP_INT (*FillpSemWaitFunc)(IN SYS_ARCH_SEM *sem);
436
437/**
438 * @ingroup Callbacks
439 * @brief
440 * This callback unlocks the semaphore referenced by the sem parameter by performing a semaphore
441 * unlock operation on that semaphore.
442 *
443 * @param[in] sem Indicates a pointer to the semaphore to be unlocked.
444 * @return
445 * On success : FILLP_SUCCESS
446 * On failure : error.
447 */
448typedef FILLP_INT (*FillpSemPostFunc)(IN SYS_ARCH_SEM *sem);
449
450/**
451 * @ingroup Callbacks
452 * @brief
453 * This callback is to destroy the unnamed semaphore indicated by sem.
454 *
455 * @param[in] sem Indicates a pointer to the semaphore to be destroyed.
456 * @return
457 * On success : FILLP_SUCCESS
458 * On failure : error.
459 */
460typedef FILLP_INT (*FillpSemDestroyFunc)(IN SYS_ARCH_SEM *sem);
461
462/**
463 * @ingroup Callbacks
464 * @brief
465 * This is a callback for SYS_ARCH_SEM_CLOSE.
466 *
467 * @param[in] sem Indicates a pointer to SYS_ARCH_RW_SEM.
468 *
469 * @return
470 * On success : zero
471 * On failure : error.
472 *
473 */
474typedef FILLP_INT (*FillpRWSemInitFunc)(IO SYS_ARCH_RW_SEM *sem);
475
476/**
477 * @ingroup Callbacks
478 * @brief
479 * This callback is to lock the read semaphore referenced by sem only if the semaphore is currently not locked.
480 *
481 * @param[in] *sem Indicates a pointer to semaphore to be locked.
482 *
483 * @return
484 * On success : zero
485 * On failure : error.
486 */
487typedef FILLP_INT (*FillpRWSemTryRDWaitFunc)(IN SYS_ARCH_RW_SEM *sem);
488
489/**
490 * @ingroup Callbacks
491 * @brief
492 * This callback is used to lock the write semaphore referenced by sem only if the semaphore is currently not locked.
493 *
494 * @param[in] *sem Indicates a pointer to the semaphore to be locked.
495 * @return
496 * On success : zero
497 * On failure : error.
498 */
499typedef FILLP_INT (*FillpRWSemTryWRWaitFunc)(IN SYS_ARCH_RW_SEM *sem);
500
501/**
502 * @ingroup Callbacks
503 * @brief
504 * This callback for sem_wait system function.
505 *
506 * @param[in] *sem Indicates a pointer to SYS_ARCH_RW_SEM.
507 * @return
508 * On success : zero
509 * On failure : error.
510 */
511typedef FILLP_INT (*FillpRWSemWRWaitFunc)(IN SYS_ARCH_RW_SEM *sem);
512
513/**
514 * @ingroup Callbacks
515 * @brief
516 * Callback for sem_post system function.
517 *
518 * @param[in] *sem Indicates a pointer to SYS_ARCH_RW_SEM.
519 * @return
520 * On success : zero
521 * On failure : error.
522 */
523typedef FILLP_INT (*FillpRWSemRDPostFunc)(IN SYS_ARCH_RW_SEM *sem);
524
525/**
526 * @ingroup Callbacks
527 * @brief
528 * Callback for sem_post system function.
529 *
530 * @param[in] *sem Indicates a pointer to SYS_ARCH_RW_SEM.
531 * @return
532 * On success : zero
533 * On failure : error.
534 */
535typedef FILLP_INT (*FillpRWSemWRPostFunc)(IN SYS_ARCH_RW_SEM *sem);
536
537/**
538 * @ingroup Callbacks
539 * @brief
540 * Callback for sem_destroy system function.
541 *
542 * @param[in] *sem Indicates a pointer to SYS_ARCH_RW_SEM.
543 * @return
544 * On success : zero
545 * On failure : error.
546 */
547typedef FILLP_INT (*FillpRWSemDestroyFunc)(IN SYS_ARCH_RW_SEM *sem);
548
549/**
550 * @ingroup Callbacks
551 * @brief
552 * This is a callback for creating a socket.
553 *
554 * @param[in] domain Indicates the address family.
555 * @param[in] type Indicates the new socket.
556 * @param[in] protocol Indicates the protocol to be used.
557 * @return
558 * On success : zero
559 * On failure : error.
560 */
561typedef FILLP_INT32 (*FillpCreateSocketFunc)(IN FILLP_INT32 domain, IN FILLP_INT32 type, IN FILLP_INT32 protocol);
562
563/**
564 * @ingroup Callbacks
565 * @brief
566 * This callback associates(bind) a local address with a socket.
567 *
568 * @param[in] fd Specifies the file descriptor of the socket to be bound.
569 * @param[in] myAddr Points to a SockAddr structure containing the address to be bound to the socket.
570 * @param[in] addrLen Specifies the length of the SockAddr structure pointed to by the pvMyaddr argument.
571 * @return
572 * On success : zero
573 * On failure : error.
574 */
575typedef FILLP_INT32 (*FillpBindSocketFunc)(IN FILLP_INT32 fd, IN FILLP_CONST void *myAddr, IN FILLP_INT32 addrLen);
576
577/**
578 * @ingroup Callbacks
579 * @brief
580 * This callback is to close an existing socket.
581 *
582 * @param[in] ifd Indicates the descriptor identifying the socket to close.
583 * @return
584 * On success : zero
585 * On failure : error.
586 */
587typedef FILLP_INT32 (*FillpCloseSocketFunc)(IN FILLP_INT32 fd);
588
589/**
590 * @ingroup Callbacks
591 * @brief
592 * This callback is used to send system function to send messages on socket.
593 *
594 * @param[in] fd Specifies the socket file descriptor.
595 * @param[in] buf Points to a buffer containing the message to be sent.
596 * @param[in] len Specifies the buffer length.
597 * @param[in] flags Specifies the type of message transmission.
598 * @param[in] to Points to a SockAddr structure containing the destination address.
599 * @param[in] toLen Specifies the length of the SockAddr structure.
600 * @return
601 * On success :  Number of bytes sent
602 * On failure : error.
603 */
604typedef FILLP_INT (*FillpSendtoFunc)(IN FILLP_INT fd, IN FILLP_CONST void *buf,
605    IN FILLP_SIZE_T len, IN FILLP_INT flags, IN FILLP_CONST void *to, IN FILLP_SIZE_T toLen);
606
607/**
608 * @ingroup Callbacks
609 * @brief
610 * This is a callback for the send system function to send a message on a socket.
611 *
612 * @param[in] fd Specifies the socket file descriptor.
613 * @param[in] buffer Points to the buffer containing the message to send.
614 * @param[in] bytes Specifies the length of the message in bytes.
615 * @param[in] flags Specifies the type of message transmission.
616 * @return
617 * On success :  Number of bytes sent
618 * On failure : error.
619 */
620typedef FILLP_INT (*FillpSendFunc)(IN FILLP_INT fd, IN FILLP_CONST void *buffer,
621    IN FILLP_INT bytes, IN FILLP_INT flags);
622
623/**
624 * @ingroup Callbacks
625 * @brief
626 * This is a callback for for sending multiple messages on a socket in a single
627 * system call. Equivalent to sendmmsg() in kernel.
628 *
629 * @param[in] fd Specifies the socket file descriptor.
630 * @param[in] buffer Points to the buffer containing the message to send.
631 * @param[in] size Specifies the number of elements sent out.
632 * @param[in] flags Indicates the flags.
633 * @return
634 * On success : Number of data elements sent
635 * On failure : error.
636 */
637typedef FILLP_INT (*FillpSendFuncmmsg)(IN FILLP_INT fd, IN FILLP_CONST void *buffer,
638    IN FILLP_UINT32 size, IN FILLP_UINT32 flags);
639
640/**
641 * @ingroup Callbacks
642 * @brief
643 * This is a callback for the receiving multiple messages on a socket in a
644 * single system call. equivalent to recvmmsg( ) in kernel.
645 *
646 * @param[in] fd Specifies the socket file descriptor.
647 * @param[in] buffer Points to the buffer containing the message to receive.
648 * @param[in] size Specifies the number of elements which can be received.
649 * @param[in] flags Indicates the flags.
650 * @param[in] timeout Indicates the timeout value.
651 * @return
652 * On success : Number of data elements received.
653 * On failure : error.
654 */
655typedef FILLP_INT (*FillpRecvmmsgFunc)(IN FILLP_INT fd, IN FILLP_CONST void *buffer,
656    IN FILLP_UINT32 size, IN FILLP_UINT32 flags, IN void *timeout);
657
658/**
659 * @ingroup Callbacks
660 * @brief
661 * This is a callback for the getsockname system function to get the socket name.
662 *
663 * @param[in] fd Indicates the socket file descriptor.
664 * @param[in] myAddr Indicates the address which the socket is bound to.
665 * @param[out] addrLen Indicates the address length.
666 * @return
667 * On success :  Number of bytes sent
668 * On failure : error.
669 */
670typedef FILLP_INT32 (*FillpGetSockNameFunc)(IN FILLP_INT32 fd, IN void *myAddr, IO void *addrLen);
671
672/**
673 * @ingroup Callbacks
674 * @brief
675 * This is a callback to connect system function to initiate a connection on a socket.
676 *
677 * @param[in] fd Indicates the socket file descriptor.
678 * @param[in] myAddr Indicates the address which the socket is bound to.
679 * @param[out] addrLen Indicates the address length.
680 * @return
681 * On success : Number of bytes sent
682 * On failure : error.
683 */
684typedef FILLP_INT32 (*FillpConnectFunc)(IN FILLP_INT32 fd, IN FILLP_CONST void *myAddr,
685    IN FILLP_INT32 addrLen);
686
687typedef void *FT_FD_SET;
688
689/**
690 * @ingroup Callbacks
691 * @brief
692 * This callback is to clear the file descriptor set.
693 *
694 * @param[in] fd socket fd.
695 * @param[in] socketDescriptorSet socket descriptor set
696 * @return
697 */
698typedef void (*FillpFdClrFunc)(IN FILLP_UINT fd, IN FT_FD_SET socketDescriptorSet);
699
700/**
701 * @ingroup Callbacks
702 * @brief
703 * This callback is set the socket in the file descriptor set.
704 *
705 * @param[in] fd Indicates the socket file descriptor.
706 * @param[in] socketDescriptorSet Indicates the socket descriptor set.
707 * @return
708 */
709typedef void (*FillpFdSetFunc)(IN FILLP_UINT fd, IN FT_FD_SET socketDescriptorSet);
710
711/**
712 * @ingroup Callbacks
713 * @brief
714 * This callback is check if this socket ID is already set in the file descriptor set.
715 *
716 * @param[in] fd Indicates the socket file descriptor.
717 * @param[in] socketDescriptorSet Indicates the socket descriptor set.
718 * @return
719 */
720typedef FILLP_INT (*FillpFdIsSetFunc)(IN FILLP_INT fd, IN FT_FD_SET socketDescriptorSet);
721
722/**
723 * @ingroup Callbacks
724 * @brief
725 * This callback is to create a file descriptor set.
726 *
727 * @return
728 * FT_FD_SET File Descriptor set
729 *
730 */
731typedef FT_FD_SET (*FillpCreateFdSetFunc)(void);
732
733/**
734 * @ingroup Callbacks
735 * @brief
736 * This callback is to free the file descriptor set which was created using the
737 * callback function FillpCreateFdSetFunc.
738 *
739 * @return
740 */
741typedef void (*FillpDestroyFdSetFunc)(IN FT_FD_SET destroySocketFdSet);
742
743/**
744 * @ingroup Callbacks
745 * @brief
746 * This callback is to copy from one file descriptor set to another
747 *
748 * @param[out] dstFdSet Indicates the destination file descriptor set to which it is copied.
749 * @param[in] srcFdSet Indicates the source file descriptor set from which it is being copied.
750 * @return
751 */
752typedef FILLP_INT32 (*FillpCopyFdSetFunc)(IO FT_FD_SET dstFdSet, IN FT_FD_SET srcFdSet);
753
754/**
755 * @ingroup Callbacks
756 * @brief
757 * This callback to receive from system callback to receive a message from a socket.
758 *
759 * @param[in] fd Specifies the socket file descriptor.
760 * @param[out] *buf Points to the buffer where the message should be stored.
761 * @param[in] len Specifies the length in bytes of the buffer pointed to by the buff argument.
762 * @param[in] flags Specifies the type of message reception.
763 * @param[out] *from Points to a SockAddr structure in which the sending address is to be stored.
764 * @param[in] *fromLen Specifies the length of the SockAddr structure pointed to by the from argument.
765 * @return
766 * On success : Length of the message in bytes.
767 * On failure : error.
768 */
769typedef FILLP_INT (*FillpRecvfromFunc)(IN FILLP_INT fd, OUT void *buf,
770    IN FILLP_SIZE_T len, IN FILLP_INT flags, OUT void *from, IO FILLP_SIZE_T *fromLen);
771
772/**
773 * @ingroup Callbacks
774 * @brief
775 * This callback is to send a message to a socket.
776 *
777 * @param[in] fd Indicates a socket ID.
778 * @param[in] *msg Specifies the message which needs to be sent.
779 * @param[in] flags Specifies the type of message.
780 * @return
781 * On success : Sends the message.
782 * On failure : error code.
783 */
784typedef FILLP_INT (*FillpSendFuncmsg)(IN FILLP_INT fd,
785    IN FILLP_CONST void *msg, IN FILLP_INT flags);
786
787/**
788 * @ingroup Callbacks
789 * @brief
790 * This callback is to receive a message from a socket.
791 *
792 * @param[in] fd Indicates a socket file descriptor.
793 * @param[in] *msg Indicates a message received.
794 * @param[in] flags Specifies the type of message.
795 * @return
796 * On success : Receives the message.
797 * On failure : error code.
798 */
799typedef FILLP_INT (*FillpRecvmsgFunc)(IN FILLP_INT fd, IN void *msg, IN FILLP_INT flags);
800
801/**
802 * @ingroup Callbacks
803 * @brief
804 * This callback is for sys_arch_sem_close.
805 *
806 * @param[in] sem Indicates the shared memory.
807 * @return
808 * On success : FILLP_SUCCESS
809 * On failure : FILLP_FAILURE
810 */
811typedef FILLP_INT (*FillpSysArchSemCloseFunc)(SYS_ARCH_SEM *sem);
812
813/**
814 * @ingroup Callbacks
815 * @brief
816 * This callback is to lock the semaphore referenced by the sem parameter as in the semaphore wait function.
817 * However, if the semaphore cannot be locked without waiting for another process or *thread to unlock the semaphore
818 * by performing a semaphore post  function, this wait shall be terminated when the specified timeout expires.
819 *
820 * @param[in] sem Pointer to named semaphore structure.
821 * @param[in] timeout Indicates the time to wait.
822 * @return
823 * On success : Zero
824 * On failure : FILLP_FAILURE
825 * @note Application must provide functionality which does not have impact with system time change.
826 */
827 /* callback for SYS_ARCH_SEM_WAIT_TIMEOUT */
828typedef FILLP_INT (*FillpSysArchSemWaitTimeoutFunc)(SYS_ARCH_SEM *sem, FILLP_SLONG timeout);
829
830/**
831 * @ingroup Callbacks
832 * @brief
833 * This callback is for sched_yield system function to yield the processor.
834 *
835 * @return
836 * Zero on success OR Error code on failure.
837 */
838 /* callback for SYS_ARCH_SCHED_YIELD */
839typedef FILLP_INT (*FillpSysArchSchedYieldFunc)(void);
840
841/* lower layer call back function structure */
842typedef struct FillpSysLibSockCallbackFuncStruct {
843    /* Function pointer variable to register the create socket callback function. */
844    FillpCreateSocketFunc socketCallbackFunc;
845    /* Function pointer variable to register bind socket callback function. */
846    FillpBindSocketFunc bindCallbackFunc;
847    /* Function pointer variable to register close socket callback function. */
848    FillpCloseSocketFunc closeSocketCallbackFunc;
849    /* Indicates a variable to register select callback function. */
850    FillpSelectFunc select;
851    /* Indicates a variable to register ioctl callback function. */
852    FillpIoctlFunc ioctl;
853    /* Indicates a variable to register fcntl callback function. */
854    FillpFcntlFunc fcntl;
855    /* Indicates a variable to register fcntl callback function. */
856    FillpSetSockOptFunc setSockOpt;
857    /* Indicates a variable to register fcntl callback function. */
858    FillpGetSockOptFunc getSockOpt;
859    /* Indicates a pointer to a variable to register  set socket option. */
860    FillpRecvfromFunc recvFromCallbackFunc;
861    /* Indicates a pointer to a variable to register  get socket option. */
862    FillpSendtoFunc sendtoCallbackFunc;
863    /* Indicates a function pointer variable to register  Sendto callback function. */
864    FillpSendFunc sendCallbackFunc;
865    /* Indicates a function pointer variable to register get socket name callback function. */
866    FillpGetSockNameFunc getSockNameCallbackFunc;
867    /* Indicates a function pointer variable to register the connect callback function. */
868    FillpConnectFunc connectCallbackFunc;
869    /* Indicates a function pointer variable to register callback function to call the required FD_CLR macro. */
870    FillpFdClrFunc fillpFuncFdClr;
871    /* Indicates a function pointer variable to register callback function to call the required FD_SET macro. */
872    FillpFdSetFunc fillpFuncFdSet;
873    /* Indicates a function pointer variable to register callback function to call the required FD_ISSET macro. */
874    FillpFdIsSetFunc fillpFuncFdIsSet;
875    /* Indicates a function pointer variable to register callback function to call fd_set. */
876    FillpCreateFdSetFunc fillpFuncCreateFdSet;
877    /* Indicates a function pointer variable to register callback function to
878     * destroy fd_set which was created by FillpCreateFdSetFunc. */
879    FillpDestroyFdSetFunc fillpFuncDestroyFdSet;
880    /* Indicates a function pointer variable to register callback function to copy fd_set. */
881    FillpCopyFdSetFunc fillpFuncCopyFdSet;
882} FillpSysLibSockCallbackFuncSt;
883
884/**
885 * Provides variables to semaphore callback functions.
886 */
887typedef struct FillpSysLibSemCallbackFuncStruct {
888    /* Function pointer variable to register semaphore close callback function. */
889    FillpSysArchSemCloseFunc sysArchSemClose;
890    /* Function pointer variable to semaphore Init callback function. */
891    FillpSemFunc sysArchSemInit;
892    /* Function pointer variable to semaphore try wait callback function. */
893    FillpSemTryWaitFunc sysArchSemTryWait;
894    /* Function pointer variable to semaphore wait callback function. */
895    FillpSemWaitFunc sysArchSemWait;
896    /* Function pointer variable to semaphore post callback function. */
897    FillpSemPostFunc sysArchSemPost;
898    /* Function pointer variable to register semaphore destroy callback function. */
899    FillpSemDestroyFunc sysArchSemDestroy;
900    /* Function pointer variable to FillpRWSemInitFunc. */
901    FillpRWSemInitFunc sysArchRWSemInit;
902    /* Function pointer variable to FillpRWSemTryRDWaitFunc. */
903    FillpRWSemTryRDWaitFunc sysArchRWSemTryRDWait;
904    /* Function pointer variable to FillpRWSemTryWRWaitFunc. */
905    FillpRWSemTryWRWaitFunc sysArchRWSemTryWRWait;
906    /* Function pointer variable to FillpRWSemRDPostFunc. */
907    FillpRWSemRDPostFunc sysArchRWSemRDPost;
908    /* Function pointer variable to FillpRWSemWRPostFunc. */
909    FillpRWSemWRPostFunc sysArchRWSemWRPost;
910    /* Function pointer variable to FillpRWSemDestroyFunc. */
911    FillpRWSemDestroyFunc sysArchRWSemDestroy;
912    /* Function pointer variable to semaphore wait timeout callback function. */
913    FillpSysArchSemWaitTimeoutFunc sysArchSemWaitTimeout;
914    /* Function pointer variable to register system shared yield  callback function. */
915    FillpSysArchSchedYieldFunc sysArchSchedYield;
916} FillpSysLibSemCallbackFuncSt;
917
918
919/**
920* Structure of basic callback functions.
921*/
922typedef struct FillpSysLibBasicCallbackFuncStruct {
923    FillpMemCallocFunc memCalloc; /* Memory  calloc callback function. */
924    FillpMemAllocFunc memAlloc; /* Memory  allocation callback function. */
925    FillpMemFreeFunc memFree; /* Memory  free callback function. */
926    FillpStrLenFunc fillpStrLen; /* String length callback function. */
927    FillpRandFunc fillpRand; /* String SprintfS callback function. */
928    FillpCreateThreadFunc fillpCreateThread; /* String SprintfS callback function. */
929    FillpSysArcInitFunc sysArcInit; /* SYS_ARCH_INIT callback function. */
930    FillpSysArcGetCurTimeFunc sysArcGetCurTimeLongLong; /* sys_arch_get_cur_time_longlong callback function. */
931    FillpSysArchAtomicIncFunc sysArchAtomicInc; /* SYS_ARCH_ATOMIC_INC callback function. */
932    FillpSysArchAtomicIncAndTestFunc sysArchAtomicIncAndTest; /* SYS_ARCH_ATOMIC_INC_AND_TEST callback function. */
933    FillpSysArchAtomicDecFunc sysArchAtomicDec; /* SysArchAtomic_DEC callback function. */
934    FillpSysArchAtomicDecAndTestFunc sysArchAtomicDecAndTest; /* SYS_ARCH_ATOMIC_DEC_AND_TEST callback function. */
935    FillpSysArchAtomicReadFunc sysArchAtomicRead; /* SYS_ARCH_ATOMIC_READ callback function. */
936    FillpSysArchAtomicSetFunc sysArchAtomicSet; /* SYS_ARCH_ATOMIC_SET callback function. */
937    FillpSysArchCompAndSwapFunc sysArchCompAndSwap; /* SYS_ARCH_SEM_WAIT_TIMEOUT callback function. */
938    FillpSysSleepMsFunc sysSleepMs; /* FILLP_SLEEP_MS callback function. */
939    FillpSysUSleepFunc sysUsleep; /* sleep in seconds callback function. */
940    FillpRtePauseFunc rtePause; /* rte_pause callback function. */
941    FillpCryptoRandFunc cryptoRand; /* Cryptographic quality random number callback function. */
942    FillpMemChrFunc memChr; /* MemChr callback function. */
943} FillpSysLibBasicCallbackFuncSt;
944
945/**
946* Provides callbacks for FillP SysLib.
947*/
948typedef struct FillpSysLibCallbackFuncStruct {
949    FillpSysLibBasicCallbackFuncSt sysLibBasicFunc; /* Indicates a callback to SystLibBasicFunc. */
950    FillpSysLibSemCallbackFuncSt sysLibSemFunc; /* Indicates a callback to SysLibSemFunc. */
951    FillpSysLibSockCallbackFuncSt sysLibSockFunc; /* Indicates a callback to SysLibSockFunc. */
952} FillpSysLibCallbackFuncSt;
953
954#ifdef __cplusplus
955}
956#endif
957
958#endif
959