• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "fillpinc.h"
17 #include "socket_app.h"
18 #include "socket_opt.h"
19 #include "spunge.h"
20 #include "res.h"
21 #include "callbacks.h"
22 #include "epoll_app.h"
23 #include "fillp_dfx.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*
29 Description: Trce callback and trce flag info
30 Value Range: None
31 Access: Used to maintain trce callback and trce flag
32 Remarks:
33 */
34 struct TraceInfo g_traceInfo = {
35     FILLP_NULL_PTR,
36     FILLP_FALSE,
37     {
38         /* For padd[3] */
39         FILLP_FALSE,
40         FILLP_FALSE,
41         FILLP_FALSE
42     },
43 #ifdef FILLP_64BIT_ALIGN
44     {
45         /* For padd1[4] */
46         FILLP_FALSE,
47         FILLP_FALSE,
48         FILLP_FALSE,
49         FILLP_FALSE
50     }
51 #endif
52 };
53 
54 /**
55 * @Description: bind to a socket, which is create by FtSocket,
56 *               the usage is the same with bind function of linux socket
57 * @param : fd: a socket, which is create by FtSocket
58 *          name: the SockAddr that need to bind
59 *          nameLen: length of the SockAddr structure
60 * @return : success: ERR_OK  fail: error code
61 */
FtBind(FILLP_INT fd,FILLP_CONST struct sockaddr * name,FILLP_UINT32 nameLen)62 FILLP_INT DLL_API FtBind(
63     FILLP_INT fd,
64     FILLP_CONST struct sockaddr *name,
65     FILLP_UINT32 nameLen)
66 {
67     return SockBind(fd, name, nameLen);
68 }
69 
70 /**
71 * @Description : creates an endpoint for communication and returns a descriptor,
72 *                is the same with socket function of linux socket
73 * @param : NA
74 * @return : success: ERR_OK  fail: error code
75 */
FtSocket(IN FILLP_INT domain,IN FILLP_INT type,IN FILLP_INT protocol)76 FILLP_INT  DLL_API  FtSocket(
77     IN FILLP_INT domain,
78     IN FILLP_INT type,
79     IN FILLP_INT protocol)
80 {
81     return SockSocket(domain, type, protocol);
82 }
83 
84 /**
85 * @Description : initiate a connection on a socket, is the same with connect function of linux socket
86 * @param : fd: a socket, which is create by FtSocket
87 *          name: the SockAddr that need to connect
88 *          nameLen: length of the SockAddr structure
89 * @return : success: ERR_OK  fail: error code
90 */
FtConnect(FILLP_INT fd,FILLP_CONST FILLP_SOCKADDR * name,socklen_t nameLen)91 FILLP_INT DLL_API  FtConnect(
92     FILLP_INT fd,
93     FILLP_CONST FILLP_SOCKADDR *name,
94     socklen_t nameLen)
95 {
96 #ifdef FILLP_SUPPORT_SERVER_ONLY
97     FILLP_LOGERR("FILLP_SUPPORT_SERVER_ONLY Macro is enabled. i.e. Client Functionality "
98                  "not supported. but still invoking FtConnect!!! Index: %d", fd);
99 
100     FILLP_UNUSED_PARA(fd);
101     FILLP_UNUSED_PARA(name);
102     FILLP_UNUSED_PARA(nameLen);
103     SET_ERRNO(FILLP_EOPNOTSUPP);
104     return -1;
105 #else
106     return SockConnect(fd, name, nameLen);
107 
108 #endif
109 }
110 
FtGetRtt(FILLP_INT fd)111 FILLP_ULLONG DLL_API FtGetRtt(FILLP_INT fd)
112 {
113     return SockGetRtt(fd);
114 }
115 
116 /**
117 * @Description : receive messages from a socket, is the same with recv function of linux socket
118 * @param : fd: a socket, which is create by FtSocket
119 *          mem: Points to the buffer where the message should be stored
120 *          len: Specifies the length in bytes of the buffer pointed to by the mem argument
121 *          flag: Indicates the status
122 * @return : success: Number of bytes received  fail: error code
123 */
FtRecv(FILLP_INT fd,void * mem,size_t len,FILLP_INT flag)124 FILLP_INT DLL_API FtRecv(FILLP_INT fd, void *mem, size_t len, FILLP_INT flag)
125 {
126     return SockRecv(fd, mem, len, flag);
127 }
128 
129 /**
130 * @Description : send a message on a socket, is the same with send function of linux socket
131 * @param : fd: a socket, which is create by FtSocket
132 *          data: Points to the buffer where the message should be stored
133 *          size: Specifies the length in bytes of the buffer pointed to by the data argument
134 *          flag: Indicates the status
135 * @return : success: Number of bytes sent fail: error code
136 */
FtSend(FILLP_INT fd,FILLP_CONST void * data,size_t size,FILLP_INT flag)137 FILLP_INT DLL_API FtSend(FILLP_INT fd, FILLP_CONST void *data, size_t size, FILLP_INT flag)
138 {
139     return SockSend(fd, data, size, flag);
140 }
141 
142 /**
143 * @Description : send a video/audio frame on a socket. All the arguments is same with FtSend except
144 *                the argument 'frame'
145 * @param : fd: a socket, which is create by FtSocket
146 *          data: Points to the buffer where the message should be stored
147 *          size: Specifies the length in bytes of the buffer pointed to by the data argument
148 *          flag: Indicates the status
149 *          frame: Specifies the frame information of the frame
150 * @return : success: Number of bytes sent, fail: error code
151 */
FtSendFrame(FILLP_INT fd,FILLP_CONST void * data,size_t size,FILLP_INT flag,FILLP_CONST struct FrameInfo * frame)152 FILLP_INT DLL_API FtSendFrame(FILLP_INT fd, FILLP_CONST void *data, size_t size, FILLP_INT flag,
153     FILLP_CONST struct FrameInfo *frame)
154 {
155     if (frame != FILLP_NULL_PTR) {
156         FILLP_LOGDTL("get frame, type: %d, size: %u, seq: %d, sub seq: %d, level: %d, bitmap: 0x%x",
157             frame->frameType, (FILLP_UINT32)size, frame->seqNum, frame->subSeqNum, frame->level, frame->bitMap);
158     }
159 
160     return SockSendFrame(fd, data, size, flag, frame);
161 }
162 
163 #if defined(FILLP_LINUX) && defined(FILLP_MMSG_SUPPORT)
164 /**
165 * @Description : send messages on a socket
166 * @param : fd: a socket, which is create by FtSocket
167 *          iov: A pointer which points to an array of iovec structures.
168 *          iovCount: buffer count of data described by iov.
169 * @return : These calls return the number of bytes written, or -1 if an error occurred.
170 *           In the event of an error, errno is set to indicate the error
171 */
FtWritev(FILLP_INT fd,const struct iovec * iov,FILLP_INT iovCount)172 FILLP_INT DLL_API FtWritev(FILLP_INT fd, const struct iovec *iov, FILLP_INT iovCount)
173 {
174     return SockWritev(fd, iov, iovCount);
175 }
176 
177 /**
178 * @Description : receive messages on a socket
179 * @param : fd: a socket, which is create by FtSocket
180 *          iov: A pointer which points to an array of iovec structures.
181 *          iovCount: buffer count of data described by iov.
182 * @return : These calls return the number of bytes read, or -1 if an error occurred.
183 *           In the event of an error, errno is set to indicate the error
184 */
FtReadv(FILLP_INT fd,const struct iovec * iov,FILLP_INT iovCount)185 FILLP_INT DLL_API FtReadv(FILLP_INT fd, const struct iovec *iov, FILLP_INT iovCount)
186 {
187     return SockReadv(fd, iov, iovCount);
188 }
189 
190 #endif
191 /**
192 * @Description : Closes the Socket connection and releases all associated resources,
193 *                is the same with close function of linux socket
194 
195 * @param : fd: a socket, which is create by FtSocket
196 * @return : success: ERR_OK  fail: error code
197 */
FtClose(FILLP_INT fd)198 FILLP_INT DLL_API FtClose(FILLP_INT fd)
199 {
200     return SockClose(fd);
201 }
202 
203 /**
204 * @Description : initiates the graceful Closure of the Socket connection from initiating side (uni-directional).
205 *                the local user can still recv data from peer.
206 * @param : fd: a socket, which is create by FtSocket
207 * @return : success: ERR_OK  fail: error code
208 */
FtShutDown(FILLP_INT fd,FILLP_INT how)209 FILLP_INT DLL_API FtShutDown(FILLP_INT fd, FILLP_INT how)
210 {
211     return SockShutdown(fd, how);
212 }
213 
214 /**
215 * @Description : accept a connection on a socket, is the same with accept function of linux socket
216 * @param : fd: a socket, which is create by FtSocket
217 *          addr: pointer to a SockAddr structure that filled in with the address of the peer socket
218 *          addrlen: length of the SockAddr structure
219 * @return : success: a descriptor for the accepted socket  fail: -1
220 */
FtAccept(FILLP_INT fd,struct sockaddr * addr,socklen_t * addrLen)221 FILLP_INT DLL_API FtAccept(FILLP_INT fd, struct sockaddr *addr, socklen_t *addrLen)
222 {
223 #ifdef FILLP_SERVER_SUPPORT
224     return SockAccept(fd, addr, addrLen);
225 #else
226     FILLP_LOGERR("FILLP_SERVER_SUPPORT Macro is not enabled. i.e. Server Functionality "
227                  "not supported. but still invoking FtAccept!!! Index: %d", fd);
228 
229     FILLP_UNUSED_PARA(fd);
230     FILLP_UNUSED_PARA(addr);
231     FILLP_UNUSED_PARA(addrLen);
232     SET_ERRNO(FILLP_EOPNOTSUPP);
233     return -1;
234 
235 #endif
236 }
237 
238 /**
239 * @Description : listen for connections on a socket, is the same with listen function of linux socket
240 * @param : fd: a socket, which is create by FtSocket
241 *          backLog: defines the maximum length to which the queue of pending connections for fd, may grow
242 * @return : success: ERR_OK  fail: error code
243 */
FtListen(FILLP_INT fd,FILLP_INT backLog)244 FILLP_INT DLL_API FtListen(FILLP_INT fd, FILLP_INT backLog)
245 {
246 #ifdef FILLP_SERVER_SUPPORT
247     return SockListen(fd, backLog);
248 #else
249     FILLP_LOGERR("FILLP_SERVER_SUPPORT Macro is not enabled. i.e. Server Functionality "
250                  "not supported. but still invoking FtListen!!! Index: %d", s);
251 
252     FILLP_UNUSED_PARA(fd);
253     FILLP_UNUSED_PARA(backLog);
254     SET_ERRNO(FILLP_EOPNOTSUPP);
255     return -1;
256 #endif
257 }
258 
259 /*******************************************************************
260   Function      : FtEpollCreate
261   Description   : This API is used to open an epoll file descriptor.
262 
263   Return        : Index to the list of FtSocket : On success.
264                       Error code : On failure.
265 ********************************************************************/
FtEpollCreate(void)266 FILLP_INT DLL_API FtEpollCreate(void)
267 {
268     return SpungeEpollCreate();
269 }
270 
271 /*******************************************************************
272   Function      : FtEpollCreate
273   Description   : This API is used to open an epoll file descriptor.
274   Return        : Index to the list of FtSocket : On success.
275                       Error code : On failure.
276 ********************************************************************/
FtEpollCreateLinux(FILLP_INT epNum)277 FILLP_INT DLL_API FtEpollCreateLinux(FILLP_INT epNum)
278 {
279     if (epNum <= 0) {
280         FILLP_LOGERR("Error number");
281         SET_ERRNO(FILLP_EINVAL);
282         return -1;
283     }
284 
285     return FtEpollCreate();
286 }
287 
288 /*******************************************************************
289   Function      : FtEpollCtl
290   Description   : This API indicates control interface for epoll file descriptor.
291 
292   Return        : FILLP_OK on success.
293                       Error code on failure.
294 ********************************************************************/
FtEpollCtl(FILLP_INT epFd,FILLP_INT op,FILLP_INT fd,FILLP_CONST struct SpungeEpollEvent * event)295 FILLP_INT DLL_API FtEpollCtl(FILLP_INT epFd, FILLP_INT op, FILLP_INT fd, FILLP_CONST struct SpungeEpollEvent *event)
296 {
297     return SpungeEpollCtl(epFd, op, fd, event);
298 }
299 
FtEpollWait(FILLP_INT epFd,struct SpungeEpollEvent * events,FILLP_INT maxEvents,FILLP_INT timeout)300 FILLP_INT DLL_API FtEpollWait(FILLP_INT epFd, struct SpungeEpollEvent *events, FILLP_INT maxEvents, FILLP_INT timeout)
301 {
302     return SpungeEpollWait(epFd, events, maxEvents, timeout);
303 }
304 
305 /*******************************************************************
306   Function      : FtFcntl
307   Description   : This function used to manipulate file descriptor.
308   Return        : Value returned depends on cmd upon success.
309                       Error code on failure.
310 ********************************************************************/
FtFcntl(FILLP_INT fd,FILLP_INT cmd,FILLP_INT val)311 FILLP_INT DLL_API FtFcntl(FILLP_INT fd, FILLP_INT cmd, FILLP_INT val)
312 {
313 #ifdef FILLP_LINUX
314     return SockFcntl(fd, cmd, val);
315 #else
316     FILLP_LOGERR("FILLP_LINUX Macro is not enabled. i.e. fcntl Functionality "
317                  "not supported in OS other than Linux. but still invoked , index : %d", fd);
318 
319     FILLP_UNUSED_PARA(fd);
320     FILLP_UNUSED_PARA(cmd);
321     FILLP_UNUSED_PARA(val);
322     SET_ERRNO(FILLP_EOPNOTSUPP);
323     return -1;
324 #endif
325 }
326 
327 /*******************************************************************
328   Function      : FtIoctl
329   Description   : This function controls the I/O mode of a socket.
330   Return        : FILLP_OK on success.
331                       Error code on failure.
332 ********************************************************************/
FtIoctl(FILLP_INT fd,FILLP_ULONG cmd,FILLP_CONST FILLP_INT * val)333 FILLP_INT DLL_API FtIoctl(FILLP_INT fd, FILLP_ULONG cmd, FILLP_CONST FILLP_INT *val)
334 {
335 #ifdef FILLP_LINUX
336     return SockIoctlsocket(fd, (FILLP_SLONG)cmd, val);
337 #else
338     FILLP_LOGERR("FILLP_LINUX Macro is not enabled. i.e. fcntl Functionality "
339                  "not supported in OS other than Linux. but still invoked , index : %d", fd);
340     FILLP_UNUSED_PARA(cmd);
341     FILLP_UNUSED_PARA(fd);
342     FILLP_UNUSED_PARA(val);
343     SET_ERRNO(FILLP_EOPNOTSUPP);
344     return -1;
345 #endif
346 }
347 
FtInnerStartTrace(IN FILLP_UINT8 traceObjType,IN FILLP_CONST void * traceHandle,IO FILLP_UINT8 * sockTraceFlag,OUT void ** sockTraceHandle)348 FILLP_INT32 FtInnerStartTrace(
349     IN FILLP_UINT8 traceObjType,         /* FILLP_TRACE_OBJ_TYPE_ENUM */
350     IN FILLP_CONST void *traceHandle,    /* Handle to be Stored in the FtSocket */
351     IO FILLP_UINT8 *sockTraceFlag,       /* FtSocket's traceFlag */
352     OUT void **sockTraceHandle)          /* FtSocket's traceHandle */
353 {
354     switch (traceObjType) {
355         case FILLP_TRACE_DIRECT_USER:
356             if ((*sockTraceFlag == FILLP_TRACE_DIRECT_NETWORK) ||
357                 (*sockTraceFlag == FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE)) {
358                 *sockTraceFlag = FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE;
359             } else {
360                 *sockTraceFlag = FILLP_TRACE_DIRECT_USER;
361             }
362 
363             g_traceInfo.cmdTraceFlag = FILLP_TRUE;
364             *sockTraceHandle = (void *)traceHandle;
365             break;
366 
367         case FILLP_TRACE_DIRECT_NETWORK:
368             if ((*sockTraceFlag == FILLP_TRACE_DIRECT_USER) ||
369                 (*sockTraceFlag == FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE)) {
370                 *sockTraceFlag = FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE;
371             } else {
372                 *sockTraceFlag = FILLP_TRACE_DIRECT_NETWORK;
373             }
374             *sockTraceHandle = (void *)traceHandle;
375             break;
376 
377         case FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE:
378             *sockTraceFlag = FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE;
379             *sockTraceHandle = (void *)traceHandle;
380             g_traceInfo.cmdTraceFlag = FILLP_TRUE;
381             break;
382 
383         default: /* Unknown trc object type */
384             FILLP_LOGERR("Unknown trc object type (%u) received", traceObjType);
385             SET_ERRNO(FILLP_EINVAL);
386             return ERR_TRACE_OBJ_TYPE_INVALID;
387     }
388 
389     return FILLP_OK;
390 }
391 
FtInnerStopTrace(IN FILLP_UINT8 traceObjType,IO FILLP_UINT8 * sockTraceFlag,OUT void ** sockTraceHandle)392 FILLP_INT32 FtInnerStopTrace(
393     IN FILLP_UINT8 traceObjType,         /* Type */
394     IO FILLP_UINT8 *sockTraceFlag,       /* FtSocket's traceFlag */
395     OUT void **sockTraceHandle)          /* FtSocket's traceHandle */
396 {
397     switch (traceObjType) {
398         case FILLP_TRACE_DIRECT_USER:
399             if (*sockTraceFlag == FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE) {
400                 *sockTraceFlag = FILLP_TRACE_DIRECT_NETWORK;
401             } else if (*sockTraceFlag == FILLP_TRACE_DIRECT_USER) {
402                 *sockTraceFlag = FILLP_TRACE_DIRECT_DISABLE;
403                 *sockTraceHandle = FILLP_NULL_PTR;
404             }
405 
406             g_traceInfo.cmdTraceFlag = FILLP_FALSE;
407             break;
408 
409         case FILLP_TRACE_DIRECT_NETWORK:
410             if (*sockTraceFlag == FILLP_TRACE_DIRECT_USER_NETWORK_ENABLE) {
411                 *sockTraceFlag = FILLP_TRACE_DIRECT_USER;
412             } else if (*sockTraceFlag == FILLP_TRACE_DIRECT_NETWORK) {
413                 *sockTraceFlag = FILLP_TRACE_DIRECT_DISABLE;
414                 *sockTraceHandle = FILLP_NULL_PTR;
415             }
416             break;
417 
418         case FILLP_TRACE_DIRECT_DISABLE:
419             *sockTraceFlag = FILLP_TRACE_DIRECT_DISABLE;
420             *sockTraceHandle = FILLP_NULL_PTR;
421             g_traceInfo.cmdTraceFlag = FILLP_FALSE;
422             break;
423 
424         default: /* Unknown trc object type */
425             FILLP_LOGERR("Unknown trc object type (%u) received", traceObjType);
426             return ERR_TRACE_OBJ_TYPE_INVALID;
427     }
428 
429     return FILLP_OK;
430 }
431 
FtStartStopTraceSock(IN struct FtSocket * sockft,IN FILLP_UINT8 traceObjType,IN FILLP_INT traceObj,IN FILLP_CONST void * traceHandle,FILLP_BOOL isStart)432 static FILLP_INT32 FtStartStopTraceSock(IN struct FtSocket *sockft, IN FILLP_UINT8 traceObjType,
433     IN FILLP_INT traceObj, IN FILLP_CONST void *traceHandle, FILLP_BOOL isStart)
434 {
435     FILLP_INT32 ret;
436     if (SYS_ARCH_RWSEM_TRYRDWAIT(&sockft->sockConnSem) != ERR_OK) {
437         FILLP_LOGERR("Socket-%d state is changing,maybe closing", sockft->index);
438         /* Socket state is changing, continue try read wait again */
439         if (traceObj != FILLP_CONFIG_ALL_SOCKET) {
440             return ERR_FT_SOCKET_INVALID;
441         }
442         return ERR_OK;
443     }
444 
445     if ((sockft->allocState == SOCK_ALLOC_STATE_FREE) || (sockft->allocState == SOCK_ALLOC_STATE_ERR)) {
446         (void)SYS_ARCH_RWSEM_RDPOST(&sockft->sockConnSem);
447         if (traceObj != FILLP_CONFIG_ALL_SOCKET) {
448             FILLP_LOGERR("Socket is not in use, fillp_sock_id:%d", sockft->index);
449             return ERR_FT_SOCKET_INVALID;
450         }
451         return ERR_OK;
452     }
453 
454     ret = (isStart == FILLP_TRUE) ?
455         FtInnerStartTrace(traceObjType, traceHandle, &sockft->traceFlag, &sockft->traceHandle) :
456         FtInnerStopTrace(traceObjType, &sockft->traceFlag, &sockft->traceHandle);
457 
458     (void)SYS_ARCH_RWSEM_RDPOST(&sockft->sockConnSem);
459     return ret;
460 }
461 
FtStartStopTrace(IN FILLP_UINT8 traceObjType,IN FILLP_INT traceObj,IN FILLP_CONST void * traceHandle,FILLP_BOOL isStart)462 FILLP_INT32 FtStartStopTrace(IN FILLP_UINT8 traceObjType, IN FILLP_INT traceObj,
463                              IN FILLP_CONST void *traceHandle, FILLP_BOOL isStart)
464 {
465     /* If Trance Obj is INVALID_INT, means need to set to all socket */
466     FILLP_INT sockIndex = (traceObj != FILLP_CONFIG_ALL_SOCKET) ? traceObj : 0;
467     FILLP_INT32 ret;
468     struct FtSocket *sockft = FILLP_NULL_PTR;
469 
470     /* Check the state of stack */
471     if ((g_spunge == FILLP_NULL_PTR) || (g_spunge->hasInited == FILLP_FALSE)) {
472         FILLP_LOGERR("Stack is not in ACTIVE state");
473         return ERR_STACK_NOT_INITED;
474     }
475 
476     FILLP_LOGINF("Trace type:%u, traceObj:%d, isStart:%u", traceObjType, traceObj, isStart);
477     if (traceObj == FILLP_CONFIG_ALL_SOCKET) {
478         ret = (isStart == FILLP_TRUE) ?
479             FtInnerStartTrace(traceObjType, traceHandle, &g_spunge->traceFlag, &g_spunge->traceHandle) :
480             FtInnerStopTrace(traceObjType, &g_spunge->traceFlag, &g_spunge->traceHandle);
481         if (ret != FILLP_OK) {
482             FILLP_LOGERR("Start/Stop Trace fail ret %d", ret);
483             return ret;
484         }
485     }
486 
487     if (SYS_ARCH_ATOMIC_READ(&g_spunge->sockTable->used) <= 0) {
488         FILLP_LOGINF("No Socket is created");
489         return FILLP_OK;
490     }
491 
492     do {
493         sockft = SockGetSocket(sockIndex);
494         if (sockft == FILLP_NULL_PTR) {
495             FILLP_LOGERR("Invalid fillp_sock_id:%d", sockIndex);
496             return ERR_FT_SOCKET_INVALID;
497         }
498         sockIndex++;
499 
500         if ((sockft->allocState == SOCK_ALLOC_STATE_FREE) || (sockft->allocState == SOCK_ALLOC_STATE_ERR)) {
501             if (traceObj != FILLP_CONFIG_ALL_SOCKET) {
502                 FILLP_LOGERR("Socket is not in use, fillp_sock_id:%d", sockft->index);
503                 return ERR_FT_SOCKET_INVALID;
504             }
505             continue;
506         }
507 
508         ret = FtStartStopTraceSock(sockft, traceObjType, traceObj, traceHandle, isStart);
509         if (ret != ERR_OK) {
510             FILLP_LOGINF("Start/Stop Trace fail fillp_sock_id:%d", sockft->index);
511             return ret;
512         }
513     } while ((traceObj == FILLP_CONFIG_ALL_SOCKET) && (sockIndex < SYS_ARCH_ATOMIC_READ(&g_spunge->sockTable->used)));
514 
515     return FILLP_OK;
516 }
517 
518 /*******************************************************************************
519     Function    : FtStartTrace
520 
521     Description : This function is called by the FILLP Adapter to start the indication of
522                   user apis and/network messages for a particular socket.
523 
524     Input       : traceObjType - Indication object as defined in FILLP_TRACE_OBJ_TYPE_ENUM.
525                           and tell what kind indication should be done.
526                   traceObj    - user should pass the FtSocket identification.
527                           to set the indication for that particular socket.
528                           (0xFFFFFFFF - means for all the sockets)
529                   traceHandle  - traceHandle which will be transparently
530                           passed to user while giving indication. 0xFFFFFFFF is the invalid handle.
531 
532     Output      : None
533 
534     Return      : FILLP_SUCCESS - In success case
535                   Other error code in case of failure
536 *******************************************************************************/
FtStartTrace(IN FILLP_UINT8 traceObjType,IN FILLP_INT traceObj,IN FILLP_CONST void * traceHandle)537 FILLP_INT32 FtStartTrace(
538     IN FILLP_UINT8 traceObjType,        /* Type */
539     IN FILLP_INT traceObj,             /* FtSocket index */
540     IN FILLP_CONST void *traceHandle)    /* Handle to be Stored in the FtSocket */
541 {
542     return FtStartStopTrace(traceObjType, traceObj, traceHandle, FILLP_TRUE);
543 }
544 
545 /*******************************************************************************
546     Function    : FtStopTrace
547 
548     Description : This function is called by the FILLP Adapter to stop the indication
549                   for a particular socket.
550 
551     Input       : traceObjType - indication object as defined in FILLP_TRACE_OBJ_TYPE_ENUM.
552                           and tell what kind indication should be done.
553                   traceObj    - For a particular socket or for all the association(0xFFFFFFFF)
554 
555     Output      : None
556 
557     Return      : FILLP_SUCCESS - In success case
558                   Other error code in case of failure
559 *******************************************************************************/
FtStopTrace(IN FILLP_UINT8 traceObjType,IN FILLP_INT traceObj)560 FILLP_INT32 FtStopTrace(
561     IN FILLP_UINT8 traceObjType,   /* Type */
562     IN FILLP_INT traceObj)        /* Socket index */
563 {
564     return FtStartStopTrace(traceObjType, traceObj, FILLP_NULL_PTR, FILLP_FALSE);
565 }
566 
567 /*******************************************************************************
568     Function    : FtRegTraceCallbackFn
569 
570     Description : This function is to register trce/ callback function for Fillp message trce and Fillp command Trce.
571 
572     Input       : traceFuncCallback -> Trce callback
573 
574     Output      : None
575 
576     Return      : FILLP_SUCCESS - In success case
577                   Other error code in case of failure
578 *******************************************************************************/
FtRegTraceCallbackFn(IN FILLP_CONST FillpTraceSend traceFuncCallback)579 FILLP_INT32 FtRegTraceCallbackFn(IN FILLP_CONST FillpTraceSend traceFuncCallback)
580 {
581     if (traceFuncCallback == FILLP_NULL_PTR) {
582         SET_ERRNO(FILLP_EINVAL);
583         return -1;
584     }
585 
586     g_traceInfo.fillpTraceSend = traceFuncCallback;
587     return FILLP_OK;
588 }
589 
590 /*******************************************************************************
591     Function    : FillpDebugCmdHelp
592 
593     Description : This function will be invoked by the Adapter to print debg/
594                     related help information.
595 
596     Input       : None
597 
598     Output      : None
599 
600     Return      : None
601 *******************************************************************************/
FillpDebugCmdHelp(void)602 static void FillpDebugCmdHelp(void)
603 {
604     /* Invoke LM macro to dbg output the help info with type  */
605     FILLP_HELPBUTT("The Dbg Command Usage are as follows");
606 
607     FILLP_HELPBUTT("FILLP_DBGCMD_HELP(%d) - To show the dbg command help", FILLP_DBGCMD_HELP);
608 
609     FILLP_HELPBUTT("FILLP_DBGCMD_SET_PRINT_LEVEL(%d) - To set the dbg print level", FILLP_DBGCMD_SET_PRINT_LEVEL);
610 
611     FILLP_HELPBUTT("FILLP_DBGCMD_SHOW_PRINT_LEVEL(%d) - To show the current dbg level", FILLP_DBGCMD_SHOW_PRINT_LEVEL);
612 
613     FILLP_HELPBUTT("FILLP_DBGCMD_SHOW_SOCKET_INFO(%d) - To show important data of a particular socket",
614                    FILLP_DBGCMD_SHOW_SOCKET_INFO);
615 
616     FILLP_HELPBUTT("FILLP_DBGCMD_SHOW_INIT_RESOURCE(%d) - To show the initialisation parameters",
617                    FILLP_DBGCMD_SHOW_INIT_RESOURCE);
618 
619     FILLP_HELPBUTT("FILLP_DBGCMD_SHOW_GLOBAL_CONFIG_RESOURCE(%d) - Show all the GLOBAL configuration"
620                    "parametrs of FillP STACK",
621                    FILLP_DBGCMD_SHOW_GLOBAL_CONFIG_RESOURCE);
622 
623     FILLP_HELPBUTT("FILLP_DBGCMD_SHOW_SOCKET_CONFIG_RESOURCE(%d) - Show all the Socket level configuration parametrs"
624                    " of FillP STACK (socket index 0xFFFF will display config common to all sockets)",
625                    FILLP_DBGCMD_SHOW_SOCKET_CONFIG_RESOURCE);
626 
627     return;
628 }
629 
630 /*******************************************************************************
631     Function    : FillpDebugCmdGlobalConfigRes
632 
633     Description : This function will be invoked by the Adapter to print debg/
634                     information related global stack config.
635 
636     Input       : None
637 
638     Output      : None
639 
640     Return      : None
641 *******************************************************************************/
FillpDebugCmdGlobalConfigRes(void)642 static void FillpDebugCmdGlobalConfigRes(void)
643 {
644     FILLP_SHOWDATABUTT("\r ------- FOLLOWING ARE FillP GLOBAL (STACK) level configuration parameters -------");
645 
646     FILLP_SHOWDATABUTT("FillP max UDP RX burst number is (FT_CONF_RX_BURST) = %u", g_resource.udp.rxBurst);
647 
648     FILLP_SHOWDATABUTT("FillP max socket number is (FT_CONF_MAX_SOCK_NUM) = %u", g_resource.common.maxSockNum);
649 
650     FILLP_SHOWDATABUTT("FillP Max Connection number is (FT_CONF_MAX_CONNECTION_NUM) =%u ",
651                        g_resource.common.maxConnNum);
652 
653     FILLP_SHOWDATABUTT("FillP max Instance number is  = %u", g_resource.common.maxInstNum);
654 
655     FILLP_SHOWDATABUTT("FillP max receive cache packet number buffer size is"
656                        "(FT_CONF_RECV_CACHE_PKT_NUM_BUFF_SIZE) = %u",
657                        g_resource.common.recvCachePktNumBufferSize);
658 
659     FILLP_SHOWDATABUTT("FillP avoid core thread when CPU full is (FT_CONF_FULL_CPU) = %u",
660                        g_resource.common.fullCpuEnable);
661 
662     FILLP_SHOWDATABUTT("FillP data message cache feature status is (FT_CONF_OUT_OF_ORDER_CATCHE_FEATURE) = %u",
663                        g_resource.common.outOfOrderCacheEnable);
664 
665     FILLP_SHOWDATABUTT("FillP Flow control : Opposite set percentage (FT_CONF_OPPOSITE_SET_PERCENTAGE) = %u",
666                        g_resource.flowControl.oppositeSetPercentage);
667 
668     FILLP_SHOWDATABUTT("FillP Flow control : MAX Rate percentage (FT_CONF_MAX_RATE_PERCENTAGE) = %u",
669                        g_resource.flowControl.maxRatePercentage);
670 
671     FILLP_SHOWDATABUTT("FillP Flow control : NACK repeat times (FT_CONF_NACK_REPEAT_TIMES) = %u",
672                        g_resource.flowControl.nackRepeatTimes);
673 
674     FILLP_SHOWDATABUTT("FillP Flow control : Packet loss allowed(FT_CONF_PACKET_LOSS_ALLOWED) = %u",
675                        g_resource.flowControl.pktLossAllow);
676 
677     FILLP_SHOWDATABUTT("FillP Flow control : Support Rate Detection(FILLP_STACK_SUPPORT_RATE_DETECTIVE)"
678                       " = NOT supported");
679 
680     FILLP_SHOWDATABUTT("FillP Flow control : Support Fairness (FT_CONF_SUPPORT_FAIRNESS) = %u",
681                        g_resource.flowControl.supportFairness);
682 
683     FILLP_SHOWDATABUTT("FillP Flow control Fair Bandwidth support: Stack Send rate (FT_CONF_CORE_MAX_RATE) = %u Kbps",
684                        g_resource.flowControl.maxRate);
685 
686     FILLP_SHOWDATABUTT("FillP Flow control Fair Bandwidth support: Stack Receive rate "
687                        "(FT_CONF_CORE_MAX_RECV_RATE) = %u Kbps",
688                        g_resource.flowControl.maxRecvRate);
689 
690     FILLP_SHOWDATABUTT("FillP Flow control : Stack Initial rate (FT_CONF_INITIAL_RATE) = %u Kbps",
691                        g_resource.flowControl.initialRate);
692 
693     FILLP_SHOWDATABUTT("Timer Config : Data cache flush timer (FT_CONF_TIMER_RECV_CACHE_PKT_NUMBUFF) = %u",
694                        g_resource.common.recvCachePktNumBufferTimeout);
695 
696     FILLP_SHOWDATABUTT("------- END OF FillP GLOBAL (STACK) level configuration parameters -------");
697 
698     return;
699 }
700 
701 /*******************************************************************************
702     Function    : FillpDebugCmdSetPrintLevel
703 
704     Description : This function will be invoked by the fillp debg/ function to
705                 set the print level
706 
707     Input       : content  : print level to set.
708 
709     Output      : None
710 
711     Return      : None
712 *******************************************************************************/
FillpDebugCmdSetPrintLevel(FILLP_CONST void * content)713 void FillpDebugCmdSetPrintLevel(FILLP_CONST void  *content)
714 {
715     FILLP_UINT8 temp;
716     if (content == FILLP_NULL_PTR) {
717         FILLP_LOGERR("Input pointer is NULL");
718 
719         return;
720     }
721 
722     temp = *((FILLP_UINT8 *)content);
723 
724     /* validate the dbg level in pucContent */
725     if ((temp > FILLP_DBG_LVL_ERROR) || (temp < FILLP_DBG_LVL_DEBUG)) {
726         FILLP_LOGERR("Dbg Level %u is not supported", temp);
727 
728         return;
729     }
730     g_fillpLmGlobal.debugLevel = temp;
731 }
732 
733 /*******************************************************************************
734     Function    : FillpDebugSocketConfigRes
735 
736     Description : This function will be invoked by the Adapter to print debg/
737                     information related socket level stack config.
738 
739     Input       : resource : config resource structure to print info
740 
741     Output      : None
742 
743     Return      : None
744 *******************************************************************************/
FillpDebugSocketConfigRes(FILLP_CONST struct GlobalAppResource * resource)745 void FillpDebugSocketConfigRes(FILLP_CONST struct GlobalAppResource *resource)
746 {
747     FILLP_SHOWDATABUTT("\r FillP max UDP TX burst number is (FT_CONF_TX_BURST) = %u", resource->udp.txBurst);
748 
749     FILLP_SHOWDATABUTT("FillP keep alive timeout is (FT_CONF_TIMER_KEEP_ALIVE) = %u", resource->common.keepAliveTime);
750 
751     FILLP_SHOWDATABUTT("FillP max server allow send cache is (FT_CONF_MAX_SERVER_ALLOW_SEND_CACHE) = %u",
752                        resource->common.maxServerAllowSendCache);
753 
754     FILLP_SHOWDATABUTT("FillP max server allow receive cache is (FT_CONF_MAX_SERVER_ALLOW_RECV_CACHE) = %u",
755                        resource->common.maxServerAllowRecvCache);
756 
757     FILLP_SHOWDATABUTT("FillP max send cache is (FT_CONF_SEND_CACHE) = %u", resource->common.sendCache);
758 
759     FILLP_SHOWDATABUTT("FillP max receive cache is (FT_CONF_RECV_CACHE) = %u", resource->common.recvCache);
760 
761     FILLP_SHOWDATABUTT("FillP max send buffer size is (FILLP_STACK_UDP_SEND_BUFFER_SIZE) = %u",
762                        resource->common.udpSendBufSize);
763 
764     FILLP_SHOWDATABUTT("FillP enableNackDelay flag is (FT_CONF_ENABLE_NACK_DELAY) = %u",
765                        resource->common.enableNackDelay);
766 
767     FILLP_SHOWDATABUTT("FillP nackDelayTimeout is (FT_CONF_NACK_DELAY_TIMEOUT) = %lld",
768                        resource->common.nackDelayTimeout);
769 
770     FILLP_SHOWDATABUTT("FillP EnlargePaxkInterval is (FT_CONF_ENLARGE_PACK_INTERVAL) = %u",
771                        resource->common.enlargePackIntervalFlag);
772 
773     FILLP_SHOWDATABUTT("FillP max receive buffer size is (FT_CONF_RECV_BUFFER_SIZE) = %u",
774                        resource->common.recvBufSize);
775 
776     FILLP_SHOWDATABUTT("FillP Flow control : Opposite set rate(FT_CONF_OPPOSITE_SET_RATE) = %u",
777                        resource->flowControl.oppositeSetRate);
778 
779     FILLP_SHOWDATABUTT("FillP Flow control : Use Const Stack Send rate (FT_CONF_CONST_RATE) = %u",
780                        resource->flowControl.constRateEnbale);
781 
782     FILLP_SHOWDATABUTT("FillP Flow control : maxRate(FT_CONF_MAX_RATE) = %u Kbps",
783                        resource->flowControl.maxRate);
784 
785     FILLP_SHOWDATABUTT("FillP Flow control : maxRecvRate(FT_CONF_MAX_RECV_RATE) = %u Kbps",
786                        resource->flowControl.maxRecvRate);
787 
788     FILLP_SHOWDATABUTT("FillP Flow control : packet size (FT_CONF_PACKET_SIZE) = %u", resource->flowControl.pktSize);
789 
790     FILLP_SHOWDATABUTT("FillP Flow control : Slow start (FT_CONF_SLOW_START) = %u", resource->flowControl.slowStart);
791 
792     FILLP_SHOWDATABUTT("Timer Config : Connection Timer (FT_CONF_TIMER_CONNECT) = %u", resource->common.connectTimeout);
793 
794     FILLP_SHOWDATABUTT("Timer Config : Connection retry Timer (FT_CONF_TIMER_CONNECTION_RETRY) = %u",
795                        resource->common.connRetryTimeout);
796 
797     FILLP_SHOWDATABUTT("Timer Config : Disconnect retry Timer (FT_CONF_TIMER_DISCONNECT_RETRY_TIMEOUT) = %u",
798                        resource->common.disconnectRetryTimeout);
799 
800     FILLP_SHOWDATABUTT("Timer Config : Keep alive Timer (FT_CONF_TIMER_KEEP_ALIVE) = %u",
801                        resource->common.keepAliveTime);
802 
803     FILLP_SHOWDATABUTT("------- End OF FillP APP Config Resource Data -------");
804 }
805 
806 /*******************************************************************************
807     Function    : FillpDebugCmdSocketConfigRes
808 
809     Description : This function will be invoked by the Adapter to print debg/
810                     information related socket level stack config.
811 
812     Input       : void  *content  : socket id for which information needs
813                 to be printed. 0xffff will print global resource.
814 
815     Output      : None
816 
817     Return      : None
818 *******************************************************************************/
FillpDebugCmdSocketConfigRes(FILLP_CONST void * content)819 void FillpDebugCmdSocketConfigRes(FILLP_CONST void  *content)
820 {
821     struct GlobalAppResource *resource = FILLP_NULL_PTR;
822     struct FtSocket *sock = FILLP_NULL_PTR;
823     FILLP_INT sockIndex;
824 
825     if (content == FILLP_NULL_PTR) {
826         FILLP_LOGERR("Input pointer is NULL");
827 
828         return;
829     }
830 
831     sockIndex = *((FILLP_INT *)content);
832 
833     if ((sockIndex != FILLP_CONFIG_ALL_SOCKET) &&
834         ((g_spunge == FILLP_NULL_PTR) || (g_spunge->hasInited == FILLP_FALSE))) {
835         FILLP_LOGERR("Cannot set Socket level config value before stack initialization!!!");
836         return;
837     }
838 
839     if (sockIndex != FILLP_CONFIG_ALL_SOCKET) {
840         sock = SockGetSocket(sockIndex);
841         if (sock == FILLP_NULL_PTR) {
842             FILLP_LOGERR("Invalid fillp_sock_id:%d", sockIndex);
843             SET_ERRNO(FILLP_EBADF);
844             return;
845         }
846 
847         /* All configuration changes are not write protected, so other thread can read old value when this
848         function is getting executed. but this is ok as per fillp design. */
849         if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
850             FILLP_LOGERR("Socket-%d state is changing,maybe closing", sockIndex);
851             SET_ERRNO(FILLP_EBUSY);
852             return;
853         }
854 
855         if ((sock->allocState == SOCK_ALLOC_STATE_FREE) || (sock->allocState == SOCK_ALLOC_STATE_ERR)) {
856             (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
857             FILLP_LOGERR("Invalid fillp_sock_id:%d \r", sockIndex);
858             return;
859         }
860 
861         resource = &sock->resConf;
862 
863         FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Config Resource Data For Socket %d -------", sockIndex);
864 
865         FillpDebugSocketConfigRes(resource);
866         (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
867     } else {
868         resource = &g_appResource;
869 
870         FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Config Resource Common At FILLP level-------");
871         FillpDebugSocketConfigRes(resource);
872     }
873 
874     return;
875 }
876 
877 /*******************************************************************************
878     Function    : FillpDebugCmdShowInitRes
879 
880     Description : This function will be invoked by the Adapter to print debg/
881                     information related stack initialization.
882 
883     Input       : None
884 
885     Output      : None
886 
887     Return      : None
888 *******************************************************************************/
FillpDebugCmdShowInitRes(void)889 static void FillpDebugCmdShowInitRes(void)
890 {
891     FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Init Resource Data -------");
892 
893     FILLP_SHOWDATABUTT("FillP max socket number is (FT_CONF_MAX_SOCK_NUM) = %u", g_resource.common.maxSockNum);
894 
895     FILLP_SHOWDATABUTT("FillP max Connection number is (FT_CONF_MAX_CONNECTION_NUM) = %u",
896                        g_resource.common.maxConnNum);
897 
898     FILLP_SHOWDATABUTT("FillP max Instance number is = %u", g_resource.common.maxInstNum);
899 
900     FILLP_SHOWDATABUTT("------- End OF FillP Init Resource Data -------");
901 
902     return;
903 }
904 /*******************************************************************************
905     Function    : FillpDebugControl
906 
907     Description : This function will be invoked by the Adapter to control the
908                   output of the maintenance information.
909 
910     Input       :
911                   ucCommand  -  The debugging command
912                   pContent -  parameter of debugging command, this will be
913                                 NULL depending upon the command type
914 
915     Output      : None
916 
917     Return      : None
918 *******************************************************************************/
FillpDebugControl(IN FILLP_UINT8 ucCommand,IN FILLP_CONST void * pContent)919 void FillpDebugControl(
920     IN FILLP_UINT8  ucCommand, /* FillpDebugCmdEn */
921     IN FILLP_CONST void *pContent)
922 {
923     switch (ucCommand) {
924         case FILLP_DBGCMD_HELP:
925             FillpDebugCmdHelp();
926             break;
927 
928         case FILLP_DBGCMD_SHOW_GLOBAL_CONFIG_RESOURCE:
929             FillpDebugCmdGlobalConfigRes();
930             break;
931 
932         case FILLP_DBGCMD_SHOW_SOCKET_CONFIG_RESOURCE:
933 
934             FillpDebugCmdSocketConfigRes(pContent);
935 
936             break;
937         case FILLP_DBGCMD_SET_PRINT_LEVEL:
938 
939             FillpDebugCmdSetPrintLevel(pContent);
940             break;
941 
942         case FILLP_DBGCMD_SHOW_PRINT_LEVEL:
943 
944             FILLP_SHOWLEVELBUTT("Current dbg level : %u", g_fillpLmGlobal.debugLevel);
945             break;
946 
947         case FILLP_DBGCMD_SHOW_INIT_RESOURCE: /* Show all the INIT configuration of STACK */
948 
949             FillpDebugCmdShowInitRes();
950             break;
951 
952         case FILLP_DBGCMD_SHOW_SOCKET_INFO: /* SHOW all the information about the FILLP socket/connection */
953 
954             FILLP_SHOWDATABUTT("Operation Not Supported ");
955 
956             break;
957 
958         default:
959 
960             FILLP_LOGERR("Unknown dbg command (%u) received", ucCommand);
961             break;
962     }
963 
964     return;
965 }
966 
967 /*******************************************************************************
968     Function    : FillpRegLMCallbackFn
969 
970     Description : This function is called by the Fillp Adapter to register the
971                   Adapter's callback function for LM functionality.
972                   If A function Pointer is passed as NULL, then it is omitted
973                   to Copy. So User/Adapter can call this function to Register
974                   the function pointers separately also.
975 
976     Input       :
977                   lmFuncCallback - Pointer to LM callback function struct
978 
979     Output      : None
980 
981     Return      : ERR_OK - In success case
982                   Other error code in case of failure
983 *******************************************************************************/
FillpRegLMCallbackFn(IN FILLP_CONST FillpLmCallbackFunc * lmFuncCallback)984 FILLP_INT32 FillpRegLMCallbackFn(IN FILLP_CONST FillpLmCallbackFunc *lmFuncCallback)
985 {
986     if ((lmFuncCallback == FILLP_NULL_PTR) || (lmFuncCallback->debugCallbackFunc == FILLP_NULL_PTR)) {
987         SET_ERRNO(FILLP_EINVAL);
988         return -1;
989     }
990 
991     g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc = lmFuncCallback->debugCallbackFunc;
992 
993     return ERR_OK;
994 }
995 
996 /**
997 * @Description : This function is called by the Fillp Adapter to get the
998                 address which the requested socket bound to.
999 * @param : fd: a socket, which is create by FtSocket
1000 *          name: the SockAddr that need to connect
1001 *          namelen: length of the SockAddr structure
1002 * @return : success: ERR_OK  fail: error code
1003 */
FtGetSockName(FILLP_INT fd,FILLP_SOCKADDR * name,socklen_t * namelen)1004 FILLP_INT DLL_API FtGetSockName(
1005     FILLP_INT fd,
1006     FILLP_SOCKADDR *name,
1007     socklen_t *namelen)
1008 {
1009     return SockGetsockname(fd, name, namelen);
1010 }
1011 
1012 /**
1013 * @Description : This function is called by the Fillp Adapter to get the
1014                 peer address to which the requested socket is connected.
1015 * @param : fd: a socket, which is create by FtSocket
1016 *          name: the SockAddr
1017 *          nameLen: length of the SockAddr structure
1018 * @return : success: ERR_OK  fail: error code
1019 */
FtGetPeerName(FILLP_INT fd,FILLP_SOCKADDR * name,socklen_t * nameLen)1020 FILLP_INT DLL_API FtGetPeerName(
1021     FILLP_INT fd,
1022     FILLP_SOCKADDR *name,
1023     socklen_t *nameLen)
1024 {
1025     return SockGetpeername(fd, name, nameLen);
1026 }
1027 
1028 /**
1029 * @Description : This function is called by the Fillp Adapter to get system
1030 *                socket parameters.
1031 * @note: All parameters are passed uninterpreted to system interface, for RAW socket it always return failure
1032 
1033 * @param : fd: a socket, which is create by FtSocket
1034 *          level: When manipulating socket options, the level at which the option resides and the name of
1035 *                 the option must be specified.
1036 *          optName: Optname options are passed uninterpreted to system interface.
1037 *          optVal: value is accessed by underlying system
1038 *          optLen: value is accessed by underlying system
1039 * @return : success: ERR_OK  fail: error code
1040 */
FtGetSockOpt(FILLP_INT fd,FILLP_INT level,FILLP_INT optName,void * optVal,FILLP_INT * optLen)1041 FILLP_INT DLL_API FtGetSockOpt(
1042     FILLP_INT           fd,
1043     FILLP_INT           level,
1044     FILLP_INT           optName,
1045     void               *optVal,
1046     FILLP_INT          *optLen)
1047 {
1048     return SockGetSockOpt(fd, level, optName, optVal, optLen);
1049 }
1050 
1051 /**
1052 * @Description : This function is called by the Fillp Adapter to set system
1053 *                socket parameters.
1054 * @note: All parameters are passed uninterpreted to system interface, for RAW socket it always return failure
1055 *
1056 * @param : fd: a socket, which is create by FtSocket
1057 *          level: When manipulating socket options, the level at which the option resides and the name of
1058 *                 the option must be specified.
1059 *          optName: Optname options are passed uninterpreted to system interface.
1060 *          optVal: value is accessed by underlying system
1061 *          optLen: value is accessed by underlying system
1062 * @return : success: ERR_OK  fail: error code
1063 */
FtSetSockOpt(FILLP_INT fd,FILLP_INT level,FILLP_INT optName,FILLP_CONST void * optVal,socklen_t optLen)1064 FILLP_INT DLL_API FtSetSockOpt(
1065     FILLP_INT           fd,
1066     FILLP_INT           level,
1067     FILLP_INT           optName,
1068     FILLP_CONST void   *optVal,
1069     socklen_t           optLen)
1070 {
1071     return SockSetSockOpt(fd, level, optName, optVal, optLen);
1072 }
1073 
1074 /*******************************************************************
1075   Function      : FtIoctlSocket
1076   Description   : This function controls the I/O mode of a socket.
1077   Return        : FILLP_OK on success.
1078                       Error code on failure.
1079 ********************************************************************/
FtIoctlSocket(FILLP_INT fd,FILLP_SLONG cmd,FILLP_CONST FILLP_INT * val)1080 FILLP_INT DLL_API FtIoctlSocket(FILLP_INT fd, FILLP_SLONG cmd, FILLP_CONST FILLP_INT *val)
1081 {
1082 #if defined(_WINDOWS) || defined(FILLP_WIN32)
1083     return SockIoctlsocket(fd, cmd, val);
1084 #else
1085     FILLP_LOGERR("FILLP_WIN32 or _WINDOWS Macro is not enabled. i.e. ioctlsocket Functionality "
1086                  "not supported in OS other than windows. but still invoked , socket index : %d", fd);
1087     FILLP_UNUSED_PARA(fd);
1088     FILLP_UNUSED_PARA(cmd);
1089     FILLP_UNUSED_PARA(val);
1090     SET_ERRNO(FILLP_EOPNOTSUPP);
1091     return -1;
1092 #endif
1093 }
1094 
1095 
1096 /*******************************************************************************
1097     Function    : FtFillpStatsGet
1098 
1099     Description : This function is called by the fillp Adapter to get the
1100                   statistics information for a each type.
1101 
1102     Input       : fd - socket index for which stats need to be provided
1103                   OutStats - fillp_statistics_pc, to which statistics will be copied.
1104                   user has to provide and free the buffer.
1105     Output      : pucStatsData - stats Data
1106 
1107     Return      : FILLP_SUCCESS - In success case
1108                   Other error code in case of failure
1109 *******************************************************************************/
FtFillpStatsGet(IN FILLP_INT fd,OUT struct FillpStatisticsPcb * outStats)1110 FILLP_INT FtFillpStatsGet(
1111     IN FILLP_INT fd,
1112     OUT struct FillpStatisticsPcb *outStats)
1113 {
1114     struct FtSocket *sock = FILLP_NULL_PTR;
1115 
1116     if (outStats == FILLP_NULL_PTR) {
1117         FILLP_LOGERR(" error: out parameter is NULLPTR");
1118         return ERR_NULLPTR;
1119     }
1120 
1121     sock = SockGetSocket(fd);
1122     if (sock == FILLP_NULL_PTR) {
1123         FILLP_LOGERR("Invalid fillp_sock_id:%d", fd);
1124         SET_ERRNO(FILLP_EBADF);
1125         return -1;
1126     }
1127 
1128     /* All configuration changes are not write protected, so other thread can read old value when this
1129             function is getting executed. but this is ok as per fillp design. */
1130     if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
1131         FILLP_LOGERR("Socket-%d state is changing,maybe closing", fd);
1132         SET_ERRNO(FILLP_EBUSY);
1133         return -1;
1134     }
1135 
1136     if (sock->allocState == SOCK_ALLOC_STATE_FREE) {
1137         (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1138         SET_ERRNO(FILLP_ENOTSOCK);
1139         return -1;
1140     }
1141 
1142     if ((sock->netconn != FILLP_NULL_PTR) && (((struct FtNetconn *)sock->netconn)->pcb != FILLP_NULL_PTR)) {
1143         (void)memcpy_s(outStats, sizeof(struct FillpStatisticsPcb),
1144             &((struct FtNetconn *)sock->netconn)->pcb->fpcb.statistics, sizeof(struct FillpStatisticsPcb));
1145     } else {
1146         FILLP_LOGERR(" error: netconn/pcb is NULLPTR");
1147         (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1148         SET_ERRNO(FILLP_ENOTCONN);
1149         return -1;
1150     }
1151     (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1152     return FILLP_SUCCESS;
1153 }
1154 
1155 /*******************************************************************************
1156     Function    : FtFillpStatPackStat
1157 
1158     Description : This function is called by the FtFillpStatShow to show the
1159                   statistics info related to pack.
1160     Input       : pcb - socket pcb for which pack info needs to be displayed.
1161 
1162     Output      : None
1163 
1164     Return      : None
1165 *******************************************************************************/
FtFillpStatPackStat(FILLP_CONST struct FillpStatisticsPcb * pcb)1166 void FtFillpStatPackStat(FILLP_CONST struct FillpStatisticsPcb *pcb)
1167 {
1168     FILLP_SHOWDATABUTT("FillpPackStastics :-");
1169     FILLP_SHOWDATABUTT("packInterval: %u", pcb->pack.packInterval);
1170     FILLP_SHOWDATABUTT("packTimePassed: %lld", pcb->pack.packTimePassed);
1171 
1172     FILLP_SHOWDATABUTT("periodRecvRate: %u", pcb->pack.periodRecvRate);
1173     FILLP_SHOWDATABUTT("maxRecvRate: %u", pcb->pack.maxRecvRate);
1174     FILLP_SHOWDATABUTT("packLostSeq: %u", pcb->pack.packLostSeq);
1175     FILLP_SHOWDATABUTT("packPktNum: %u", pcb->pack.packPktNum);
1176     FILLP_SHOWDATABUTT("periodRecvedOnes: %u", pcb->pack.periodRecvedOnes);
1177     FILLP_SHOWDATABUTT("periodDroped: %u", pcb->pack.periodDroped);
1178     FILLP_SHOWDATABUTT("periodRecvBits: %llu", pcb->pack.periodRecvBits);
1179     FILLP_SHOWDATABUTT("periodRecvPktLoss: %u", pcb->pack.periodRecvPktLoss);
1180     FILLP_SHOWDATABUTT("peerRtt: %u", pcb->pack.peerRtt);
1181     FILLP_SHOWDATABUTT("packSendTime: %lld", pcb->pack.packSendTime);
1182     FILLP_SHOWDATABUTT("periodSendRate: %u", pcb->pack.periodSendRate);
1183     FILLP_SHOWDATABUTT("periodAckByPackRate: %u", pcb->pack.periodAckByPackRate);
1184     FILLP_SHOWDATABUTT("packIntervalBackup: %u", pcb->pack.packIntervalBackup);
1185     FILLP_SHOWDATABUTT("packRttDetectTime: %lld", pcb->pack.packRttDetectTime);
1186 
1187     FILLP_SHOWDATABUTT("FillpPackStastics End's");
1188 
1189     return;
1190 }
1191 
1192 /*******************************************************************************
1193     Function    : FtFillpStatKeepAlive
1194 
1195     Description : This function is called by the FtFillpStatShow to show the
1196                   statistics info related to keep alive.
1197     Input       : pcb - socket pcb for which keep alive info needs to be displayed.
1198 
1199     Output      : None
1200 
1201     Return      : none
1202 *******************************************************************************/
FtFillpStatKeepAlive(FILLP_CONST struct FillpStatisticsPcb * pcb)1203 void FtFillpStatKeepAlive(FILLP_CONST struct FillpStatisticsPcb *pcb)
1204 {
1205     FILLP_SHOWDATABUTT("FillpKeepAliveStastics :-");
1206     FILLP_SHOWDATABUTT("lastRecvTime: %lld", pcb->keepAlive.lastRecvTime);
1207     FILLP_SHOWDATABUTT("lastDataRecvTime: %lld", pcb->keepAlive.lastDataRecvTime);
1208     FILLP_SHOWDATABUTT("lastSendTime: %lld", pcb->keepAlive.lastSendTime);
1209     FILLP_SHOWDATABUTT("FillpKeepAliveStastics End's");
1210 
1211     return;
1212 }
1213 
1214 /*******************************************************************************
1215     Function    : FtFillpStatDebugStat
1216 
1217     Description : This function is called by the FtFillpStatShow to show the
1218                   statistics info related to debg/.
1219     Input       : pcb - socket pcb for which debg/ info needs to be displayed.
1220 
1221     Output      : None
1222 
1223     Return      : None
1224 *******************************************************************************/
FtFillpStatDebugStat(FILLP_CONST struct FillpStatisticsPcb * pcb)1225 void FtFillpStatDebugStat(FILLP_CONST struct FillpStatisticsPcb *pcb)
1226 {
1227     FILLP_SHOWDATABUTT("FillpStatatisticsDebugPcb :-");
1228 
1229     FILLP_SHOWDATABUTT("multiRetry: %d ", pcb->debugPcb.multiRetry);
1230     FILLP_SHOWDATABUTT("retryOne: %d ", pcb->debugPcb.retryOne);
1231     FILLP_SHOWDATABUTT("retryThreeTimes: %d ", pcb->debugPcb.retryThreeTimes);
1232     FILLP_SHOWDATABUTT("retryFourthTimes: %d ", pcb->debugPcb.retryFourthTimes);
1233     FILLP_SHOWDATABUTT("retryMore: %d ", pcb->debugPcb.retryMore);
1234     FILLP_SHOWDATABUTT("maxRetry: %d ", pcb->debugPcb.maxRetry);
1235     FILLP_SHOWDATABUTT("connReqSend: %u ", pcb->debugPcb.connReqSend);
1236     FILLP_SHOWDATABUTT("connReqFailed: %u ", pcb->debugPcb.connReqFailed);
1237     FILLP_SHOWDATABUTT("connReqAckSend: %u ", pcb->debugPcb.connReqAckSend);
1238     FILLP_SHOWDATABUTT("connReqAckFailed: %u ", pcb->debugPcb.connReqAckFailed);
1239     FILLP_SHOWDATABUTT("connConfirmSend: %u ", pcb->debugPcb.connConfirmSend);
1240     FILLP_SHOWDATABUTT("connConfirmFailed: %u ", pcb->debugPcb.connConfirmFailed);
1241     FILLP_SHOWDATABUTT("connConfirmAckSend: %u ", pcb->debugPcb.connConfirmAckSend);
1242     FILLP_SHOWDATABUTT("connConfirmAckFailed: %u ", pcb->debugPcb.connConfirmAckFailed);
1243     FILLP_SHOWDATABUTT("disconnReqSend: %u ", pcb->debugPcb.disconnReqSend);
1244     FILLP_SHOWDATABUTT("disconnReqFailed: %u ", pcb->debugPcb.disconnReqFailed);
1245     FILLP_SHOWDATABUTT("disconnRspSend: %u ", pcb->debugPcb.disconnRspSend);
1246     FILLP_SHOWDATABUTT("disconnRspFailed: %u ", pcb->debugPcb.disconnRspFailed);
1247     FILLP_SHOWDATABUTT("keepAliveProbeReqSend: %u ", pcb->debugPcb.keepAliveProbeReqSend);
1248     FILLP_SHOWDATABUTT("keepAliveProbeReqFailed: %u ", pcb->debugPcb.keepAliveProbeReqFailed);
1249     FILLP_SHOWDATABUTT("keepAliveProbeRspSend: %u ", pcb->debugPcb.keepAliveProbeRspSend);
1250     FILLP_SHOWDATABUTT("keepAliveProbeRspFailed: %u ", pcb->debugPcb.keepAliveProbeRspFailed);
1251     FILLP_SHOWDATABUTT("nackSend: %u ", pcb->debugPcb.nackSend);
1252     FILLP_SHOWDATABUTT("nackFailed: %u ", pcb->debugPcb.nackFailed);
1253     FILLP_SHOWDATABUTT("nackRcv: %u ", pcb->debugPcb.nackRcv);
1254     FILLP_SHOWDATABUTT("packSend: %u ", pcb->debugPcb.packSend);
1255     FILLP_SHOWDATABUTT("packFailed: %u ", pcb->debugPcb.packFailed);
1256     FILLP_SHOWDATABUTT("packRcv: %u ", pcb->debugPcb.packRcv);
1257     FILLP_SHOWDATABUTT("nackPktNum: %u ", pcb->debugPcb.nackPktNum);
1258     FILLP_SHOWDATABUTT("packIntervalPktNum: %u ", pcb->debugPcb.packIntervalPktNum);
1259     FILLP_SHOWDATABUTT("packIntervalSendBytes: %u ", pcb->debugPcb.packIntervalSendBytes);
1260     FILLP_SHOWDATABUTT("packIntervalSendPkt: %u ", pcb->debugPcb.packIntervalSendPkt);
1261     FILLP_SHOWDATABUTT("FillpStatatisticsDebugPcb End's ");
1262 
1263     return;
1264 }
1265 
1266 /*******************************************************************************
1267     Function    : FtFillpStatTraffic
1268 
1269     Description : This function is called by the FtFillpStatShow to show the
1270                   statistics info related to traffic.
1271     Input       : pcb - socket pcb for which traffic info needs to be displayed.
1272 
1273     Output      : None
1274 
1275     Return      : None
1276 *******************************************************************************/
FtFillpStatTraffic(FILLP_CONST struct FillpStatisticsPcb * pcb)1277 void FtFillpStatTraffic(FILLP_CONST struct FillpStatisticsPcb *pcb)
1278 {
1279     FILLP_SHOWDATABUTT("Total Send Ones : %u,Bytes Sent %u, Send Failed ones : %u ",
1280                        pcb->traffic.totalSend, pcb->traffic.totalSendBytes, pcb->traffic.totalSendFailed);
1281     FILLP_SHOWDATABUTT("pktReceived %u,Bytes Received %u, invalid Ones : %u",
1282                        pcb->traffic.totalRecved, pcb->traffic.totalRecvedBytes, pcb->traffic.totalDroped);
1283     FILLP_SHOWDATABUTT("Retry Send Ones : %u ", pcb->traffic.totalRetryed);
1284     FILLP_SHOWDATABUTT("Out-of-order Ones : %u", pcb->traffic.totalOutOfOrder);
1285     FILLP_SHOWDATABUTT("Recv Lost : %u", pcb->traffic.totalRecvLost);
1286 
1287     return;
1288 }
1289 
1290 /*******************************************************************************
1291     Function    : FtFillpInnerStatShow
1292 
1293     Description : This function is called by the fillp Adapter to show the
1294                   statistics info.
1295     Input       : ulStatsType - Statistics type as defined in
1296                 Different Statistics will be defined based on the Product requirements
1297                 sockFd - Socket Index
1298     Output      : None
1299 *******************************************************************************/
FtFillpInnerStatShow(IN FILLP_UINT32 fillpStatsType,IN FILLP_CONST struct FillpStatisticsPcb * pcb)1300 void FtFillpInnerStatShow(
1301     IN FILLP_UINT32 fillpStatsType,
1302     IN FILLP_CONST struct FillpStatisticsPcb *pcb)
1303 {
1304     if ((fillpStatsType == FILLP_STATS_DIRECT_PACK) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1305         FtFillpStatPackStat(pcb);
1306     }
1307 
1308     if ((fillpStatsType == FILLP_STATS_DIRECT_KEEP_ALIVE) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1309         FtFillpStatKeepAlive(pcb);
1310     }
1311 
1312     if ((fillpStatsType == FILLP_STATS_DIRECT_DEBUG) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1313         FtFillpStatDebugStat(pcb);
1314     }
1315 
1316     if ((fillpStatsType == FILLP_STATS_DIRECT_TRAFFIC) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1317         FtFillpStatTraffic(pcb);
1318     }
1319 
1320     return;
1321 }
1322 
1323 /*******************************************************************************
1324     Function    : FtFillpStatShow
1325 
1326     Description : This function is called by the fillp Adapter to show the
1327                   statistics info.
1328     Input       : ulFillpStatsType - Statistics type as defined in
1329                 Different Statistics will be defined based on the Product requirements
1330                 fd - Socket Index
1331     Output      : None
1332 
1333     Return      : FILLP_SUCCESS - In success case
1334                   Other error code in case of failure
1335 *******************************************************************************/
FtFillpStatShow(IN FILLP_UINT32 fillpStatsType,IN FILLP_INT fd)1336 FILLP_INT FtFillpStatShow(
1337     IN FILLP_UINT32 fillpStatsType,
1338     IN FILLP_INT    fd)
1339 {
1340     struct FillpStatisticsPcb *pcb = FILLP_NULL_PTR;
1341     struct FtSocket *sock = SockGetSocket(fd);
1342 
1343     if (sock == FILLP_NULL_PTR) {
1344         FILLP_LOGERR("ERR_NULLPTR FtSocket sockFd = %d \r", fd);
1345         SET_ERRNO(FILLP_EBADF);
1346         return -1;
1347     }
1348 
1349     if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
1350         FILLP_LOGERR("Socket-%d state is changing,maybe closing", fd);
1351         SET_ERRNO(FILLP_EBUSY);
1352         return -1;
1353     }
1354 
1355     if ((sock->allocState == SOCK_ALLOC_STATE_FREE) ||
1356         (sock->netconn == FILLP_NULL_PTR) ||
1357         (((struct FtNetconn *)sock->netconn)->pcb) == FILLP_NULL_PTR) {
1358         FILLP_LOGERR("ERR_NULLPTR FtSocket sockFd = %d", fd);
1359         SET_ERRNO(FILLP_EBADF);
1360         (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1361         return -1;
1362     }
1363 
1364     if (fillpStatsType > FILLP_STATS_DIRECT_ALL) {
1365         FILLP_LOGERR("invalid fillpStatsType = %u \r", fillpStatsType);
1366         SET_ERRNO(FILLP_EINVAL);
1367         (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1368         return -1;
1369     }
1370 
1371     pcb = &(((struct FtNetconn *)sock->netconn)->pcb->fpcb.statistics);
1372 
1373     FtFillpInnerStatShow(fillpStatsType, pcb);
1374 
1375     FILLP_SHOWDATABUTT("Total Sockets : %d,Total Free Sockets : %d", g_spunge->sockTable->size,
1376                        FillpRingFreeEntries(&(g_spunge->sockTable->freeQueqe->ring)));
1377     (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1378     return FILLP_SUCCESS;
1379 }
1380 
1381 #define FILLP_REG_OS_BASIC_LIB_FUNC(funSt, func) do { \
1382     if ((funSt)->sysLibBasicFunc.func != FILLP_NULL_PTR) { \
1383         g_fillpOsBasicLibFun.func = (funSt)->sysLibBasicFunc.func; \
1384     } \
1385 } while (0)
1386 
FtRegCopyOsBasicLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1387 void FtRegCopyOsBasicLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1388 {
1389     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memCalloc);
1390     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memAlloc);
1391     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memFree);
1392     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpStrLen);
1393     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpRand);
1394     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpCreateThread);
1395     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArcInit);
1396     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArcGetCurTimeLongLong);
1397     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicInc);
1398     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicDec);
1399     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicRead);
1400     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicSet);
1401     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchCompAndSwap);
1402     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysSleepMs);
1403     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysUsleep);
1404     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, rtePause);
1405     FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, cryptoRand);
1406     /* This is mandatory callback, so if it is NULL then it will fail in FillpApiRegLibSysFunc itself */
1407     g_fillpOsBasicLibFun.cryptoRand = libSysFunc->sysLibBasicFunc.cryptoRand;
1408 }
1409 
1410 #define FILLP_REG_OS_SEM_LIB_FUNC(funSt, func) do { \
1411     if ((funSt)->sysLibSemFunc.func != FILLP_NULL_PTR) { \
1412         g_fillpOsSemLibFun.func = (funSt)->sysLibSemFunc.func; \
1413     } \
1414 } while (0)
1415 
FtRegCopyOsSemLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1416 void FtRegCopyOsSemLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1417 {
1418     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemClose);
1419     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemInit);
1420     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemTryWait);
1421     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemWait);
1422     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemPost);
1423     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemDestroy);
1424     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemWaitTimeout);
1425     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemInit);
1426     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemTryRDWait);
1427     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemTryWRWait);
1428     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemRDPost);
1429     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemWRPost);
1430     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemDestroy);
1431     FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSchedYield);
1432 }
1433 
1434 #define FILLP_REG_OS_SOCKET_LIB_FUNC(funSt, func) do { \
1435     if ((funSt)->sysLibSockFunc.func != FILLP_NULL_PTR) { \
1436         g_fillpOsSocketLibFun.func = (funSt)->sysLibSockFunc.func; \
1437     } \
1438 } while (0)
1439 
FtRegCopyOsSocketLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1440 void FtRegCopyOsSocketLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1441 {
1442     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, socketCallbackFunc);
1443     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, select);
1444     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, bindCallbackFunc);
1445     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, closeSocketCallbackFunc);
1446     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, recvFromCallbackFunc);
1447     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, sendtoCallbackFunc);
1448     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, ioctl);
1449     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fcntl);
1450     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, setSockOpt);
1451     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, getSockOpt);
1452     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, sendCallbackFunc);
1453     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, getSockNameCallbackFunc);
1454     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, connectCallbackFunc);
1455     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdClr);
1456     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdSet);
1457     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdIsSet);
1458     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncCreateFdSet);
1459     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncDestroyFdSet);
1460     FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncCopyFdSet);
1461 }
1462 
FillpApiRegLibSysFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc,IN FILLP_CONST void * para)1463 FILLP_INT32 FillpApiRegLibSysFunc(
1464     IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc,
1465     IN FILLP_CONST void *para)  /* For random function */
1466 {
1467     if (g_spunge != FILLP_NULL_PTR) {
1468         SET_ERRNO(FILLP_EOPNOTSUPP);
1469         return -1;
1470     }
1471 
1472     if (FILLP_INVALID_PTR(libSysFunc)) {
1473         SET_ERRNO(FILLP_EINVAL);
1474         return -1;
1475     }
1476 
1477     FillpRegLibSysFunc();
1478 
1479     if (FILLP_INVALID_PTR(libSysFunc->sysLibBasicFunc.cryptoRand)) {
1480         SET_ERRNO(FILLP_EINVAL);
1481         return -1;
1482     }
1483 
1484     /* Basic Os function Registration */
1485     FtRegCopyOsBasicLibFunc(libSysFunc);
1486 
1487     /* Semaphore function Registration */
1488     FtRegCopyOsSemLibFunc(libSysFunc);
1489 
1490     /* Socket function registration */
1491     FtRegCopyOsSocketLibFunc(libSysFunc);
1492 
1493     FILLP_UNUSED_PARA(para);
1494     return FILLP_SUCCESS;
1495 }
1496 
FillpApiRegAppCallbackFunc(IN FILLP_CONST FillpAppCallbackFunc * appCbkFunc)1497 FILLP_INT32 FillpApiRegAppCallbackFunc(IN FILLP_CONST FillpAppCallbackFunc *appCbkFunc)
1498 {
1499     if (FILLP_INVALID_PTR(appCbkFunc)) {
1500         SET_ERRNO(FILLP_EINVAL);
1501         return -1;
1502     }
1503 
1504     g_fillpAppCbkFun.fillpSockCloseCbkFunc = appCbkFunc->fillpSockCloseCbkFunc;
1505 
1506     return FILLP_SUCCESS;
1507 }
1508 
FtGetVersion(void)1509 FILLP_CHAR_PTR DLL_API FtGetVersion(void)
1510 {
1511     return (FILLP_VERSION);
1512 }
1513 
FtGetErrno(void)1514 FILLP_INT DLL_API FtGetErrno(void)
1515 {
1516 #ifdef FILLP_LINUX
1517     return errno;
1518 #elif defined(FILLP_WIN32)
1519     return WSAGetLastError();
1520 #endif
1521 }
1522 
FtGetStackTime(FILLP_INT instInx)1523 FILLP_ULLONG DLL_API FtGetStackTime(FILLP_INT instInx)
1524 {
1525     if ((g_spunge == FILLP_NULL_PTR) || (g_spunge->hasInited == FILLP_FALSE)) {
1526         FILLP_LOGERR("Stack not ready");
1527         return 0;
1528     }
1529 
1530     if ((instInx < 0) || ((FILLP_UINT)instInx >= g_spunge->insNum)) {
1531         FILLP_LOGERR("Inst index is out of range it should be [0,%u)", g_spunge->insNum);
1532         return 0;
1533     }
1534 
1535     return (FILLP_ULLONG)g_spunge->instPool[instInx].curTime;
1536 }
1537 
1538 /*******************************************************************************
1539     Function    : FtApiRegEventCallbackFunc
1540 
1541     Description : Register the event callback function on the socket.
1542 
1543     Input       : fd          -  Indicates a socket created by the FtSocket API.
1544                   evtCbkFunc  -  Pointer to event callback function FillpEvtCbkFunc.
1545 
1546     Output      : None.
1547 
1548     Return      :
1549                   0 : Success
1550                  -1 : Failure
1551 *******************************************************************************/
FtApiRegEventCallbackFunc(IN FILLP_INT fd,IN FillpEvtCbkFunc evtCbkFunc)1552 FILLP_INT DLL_API FtApiRegEventCallbackFunc(IN FILLP_INT fd, IN FillpEvtCbkFunc evtCbkFunc)
1553 {
1554     FILLP_UNUSED_PARA(fd);
1555     FILLP_UNUSED_PARA(evtCbkFunc);
1556     FILLP_LOGERR("regist evt callback not support yet");
1557     SET_ERRNO(FILLP_EOPNOTSUPP);
1558     return -1;
1559 }
1560 
1561 /*******************************************************************************
1562     Function    : FtApiUnregEventCallbackFunc
1563 
1564     Description : unregister the event callback function on the socket.
1565 
1566     Input       : fd          -  Indicates a socket created by the FtSocket API.
1567                   evtCbkFunc  -  Pointer to event callback function FillpEvtCbkFunc.
1568 
1569     Output      : None.
1570 
1571     Return      :
1572                   0 : Success
1573                  -1 : Failure
1574 *******************************************************************************/
FtApiUnregEventCallbackFunc(IN FILLP_INT fd,IN FillpEvtCbkFunc evtCbkFunc)1575 FILLP_INT DLL_API FtApiUnregEventCallbackFunc(IN FILLP_INT fd, IN FillpEvtCbkFunc evtCbkFunc)
1576 {
1577     FILLP_UNUSED_PARA(fd);
1578     FILLP_UNUSED_PARA(evtCbkFunc);
1579     FILLP_LOGERR("unregist evt callback not support yet");
1580     SET_ERRNO(FILLP_EOPNOTSUPP);
1581     return -1;
1582 }
1583 
1584 /*******************************************************************************
1585     Function    : FtApiEventInfoGet
1586 
1587     Description : Get the event info on the socket.
1588 
1589     Input       : fd          -  Indicates a socket created by the FtSocket API.
1590                   info->evt   -  Indicates the event type.
1591 
1592     Output      : info->info  -  Indicates the event info according to the event type.
1593 
1594     Return      :
1595                   0 : Success
1596                  -1 : Failure
1597 *******************************************************************************/
FtApiEventInfoGet(IN FILLP_INT fd,IO FtEventCbkInfo * info)1598 FILLP_INT DLL_API FtApiEventInfoGet(IN FILLP_INT fd, IO FtEventCbkInfo *info)
1599 {
1600     return SockEventInfoGet(fd, info);
1601 }
1602 
FtSetDfxEventCb(void * softObj,FillpDfxEventCb evtCb)1603 FILLP_INT DLL_API FtSetDfxEventCb(void *softObj, FillpDfxEventCb evtCb)
1604 {
1605     return FillpDfxEvtCbSet(softObj, evtCb);
1606 }
1607 
FtDfxHiDumper(FILLP_UINT32 argc,const FILLP_CHAR ** argv,void * softObj,FillpDfxDumpFunc dump)1608 FILLP_INT FtDfxHiDumper(FILLP_UINT32 argc, const FILLP_CHAR **argv, void *softObj, FillpDfxDumpFunc dump)
1609 {
1610 #ifdef FILLP_ENABLE_DFX_HIDUMPER
1611     return FillpDfxDump(argc, argv, softObj, dump);
1612 #else
1613     (void)argc;
1614     (void)argv;
1615     (void)softObj;
1616     (void)dump;
1617     FILLP_LOGERR("unsupport FtFillpDfxDump");
1618     return -1;
1619 #endif /* FILLP_ENABLE_DFX_HIDUMPER */
1620 }
1621 
1622 #ifdef __cplusplus
1623 }
1624 #endif
1625 
1626