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 return;
828 }
829
830 sockIndex = *((FILLP_INT *)content);
831
832 if ((sockIndex != FILLP_CONFIG_ALL_SOCKET) &&
833 ((g_spunge == FILLP_NULL_PTR) || (g_spunge->hasInited == FILLP_FALSE))) {
834 FILLP_LOGERR("Cannot set Socket level config value before stack initialization!!!");
835 return;
836 }
837
838 if (sockIndex != FILLP_CONFIG_ALL_SOCKET) {
839 sock = SockGetSocket(sockIndex);
840 if (sock == FILLP_NULL_PTR) {
841 FILLP_LOGERR("Invalid fillp_sock_id:%d", sockIndex);
842 SET_ERRNO(FILLP_EBADF);
843 return;
844 }
845
846 /* All configuration changes are not write protected, so other thread can read old value when this
847 function is getting executed. but this is ok as per fillp design. */
848 if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
849 FILLP_LOGERR("Socket-%d state is changing,maybe closing", sockIndex);
850 SET_ERRNO(FILLP_EBUSY);
851 return;
852 }
853
854 if ((sock->allocState == SOCK_ALLOC_STATE_FREE) || (sock->allocState == SOCK_ALLOC_STATE_ERR)) {
855 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
856 FILLP_LOGERR("Invalid fillp_sock_id:%d \r", sockIndex);
857 return;
858 }
859
860 resource = &sock->resConf;
861
862 FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Config Resource Data For Socket %d -------", sockIndex);
863
864 FillpDebugSocketConfigRes(resource);
865 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
866 } else {
867 resource = &g_appResource;
868
869 FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Config Resource Common At FILLP level-------");
870 FillpDebugSocketConfigRes(resource);
871 }
872
873 return;
874 }
875
876 /*******************************************************************************
877 Function : FillpDebugCmdShowInitRes
878
879 Description : This function will be invoked by the Adapter to print debg/
880 information related stack initialization.
881
882 Input : None
883
884 Output : None
885
886 Return : None
887 *******************************************************************************/
FillpDebugCmdShowInitRes(void)888 static void FillpDebugCmdShowInitRes(void)
889 {
890 FILLP_SHOWDATABUTT("------- FOLLOWING ARE FillP Init Resource Data -------");
891
892 FILLP_SHOWDATABUTT("FillP max socket number is (FT_CONF_MAX_SOCK_NUM) = %u", g_resource.common.maxSockNum);
893
894 FILLP_SHOWDATABUTT("FillP max Connection number is (FT_CONF_MAX_CONNECTION_NUM) = %u",
895 g_resource.common.maxConnNum);
896
897 FILLP_SHOWDATABUTT("FillP max Instance number is = %u", g_resource.common.maxInstNum);
898
899 FILLP_SHOWDATABUTT("------- End OF FillP Init Resource Data -------");
900
901 return;
902 }
903 /*******************************************************************************
904 Function : FillpDebugControl
905
906 Description : This function will be invoked by the Adapter to control the
907 output of the maintenance information.
908
909 Input :
910 ucCommand - The debugging command
911 pContent - parameter of debugging command, this will be
912 NULL depending upon the command type
913
914 Output : None
915
916 Return : None
917 *******************************************************************************/
FillpDebugControl(IN FILLP_UINT8 ucCommand,IN FILLP_CONST void * pContent)918 void FillpDebugControl(
919 IN FILLP_UINT8 ucCommand, /* FillpDebugCmdEn */
920 IN FILLP_CONST void *pContent)
921 {
922 switch (ucCommand) {
923 case FILLP_DBGCMD_HELP:
924 FillpDebugCmdHelp();
925 break;
926
927 case FILLP_DBGCMD_SHOW_GLOBAL_CONFIG_RESOURCE:
928 FillpDebugCmdGlobalConfigRes();
929 break;
930
931 case FILLP_DBGCMD_SHOW_SOCKET_CONFIG_RESOURCE:
932
933 FillpDebugCmdSocketConfigRes(pContent);
934
935 break;
936 case FILLP_DBGCMD_SET_PRINT_LEVEL:
937
938 FillpDebugCmdSetPrintLevel(pContent);
939 break;
940
941 case FILLP_DBGCMD_SHOW_PRINT_LEVEL:
942
943 FILLP_SHOWLEVELBUTT("Current dbg level : %u", g_fillpLmGlobal.debugLevel);
944 break;
945
946 case FILLP_DBGCMD_SHOW_INIT_RESOURCE: /* Show all the INIT configuration of STACK */
947
948 FillpDebugCmdShowInitRes();
949 break;
950
951 case FILLP_DBGCMD_SHOW_SOCKET_INFO: /* SHOW all the information about the FILLP socket/connection */
952
953 FILLP_SHOWDATABUTT("Operation Not Supported ");
954
955 break;
956
957 default:
958
959 FILLP_LOGERR("Unknown dbg command (%u) received", ucCommand);
960 break;
961 }
962
963 return;
964 }
965
966 /*******************************************************************************
967 Function : FillpRegLMCallbackFn
968
969 Description : This function is called by the Fillp Adapter to register the
970 Adapter's callback function for LM functionality.
971 If A function Pointer is passed as NULL, then it is omitted
972 to Copy. So User/Adapter can call this function to Register
973 the function pointers separately also.
974
975 Input :
976 lmFuncCallback - Pointer to LM callback function struct
977
978 Output : None
979
980 Return : ERR_OK - In success case
981 Other error code in case of failure
982 *******************************************************************************/
FillpRegLMCallbackFn(IN FILLP_CONST FillpLmCallbackFunc * lmFuncCallback)983 FILLP_INT32 FillpRegLMCallbackFn(IN FILLP_CONST FillpLmCallbackFunc *lmFuncCallback)
984 {
985 if ((lmFuncCallback == FILLP_NULL_PTR) || (lmFuncCallback->debugCallbackFunc == FILLP_NULL_PTR)) {
986 SET_ERRNO(FILLP_EINVAL);
987 return -1;
988 }
989
990 g_fillpLmGlobal.lmCallbackFn.debugCallbackFunc = lmFuncCallback->debugCallbackFunc;
991
992 return ERR_OK;
993 }
994
995 /**
996 * @Description : This function is called by the Fillp Adapter to get the
997 address which the requested socket bound to.
998 * @param : fd: a socket, which is create by FtSocket
999 * name: the SockAddr that need to connect
1000 * namelen: length of the SockAddr structure
1001 * @return : success: ERR_OK fail: error code
1002 */
FtGetSockName(FILLP_INT fd,FILLP_SOCKADDR * name,socklen_t * namelen)1003 FILLP_INT DLL_API FtGetSockName(
1004 FILLP_INT fd,
1005 FILLP_SOCKADDR *name,
1006 socklen_t *namelen)
1007 {
1008 return SockGetsockname(fd, name, namelen);
1009 }
1010
1011 /**
1012 * @Description : This function is called by the Fillp Adapter to get the
1013 peer address to which the requested socket is connected.
1014 * @param : fd: a socket, which is create by FtSocket
1015 * name: the SockAddr
1016 * nameLen: length of the SockAddr structure
1017 * @return : success: ERR_OK fail: error code
1018 */
FtGetPeerName(FILLP_INT fd,FILLP_SOCKADDR * name,socklen_t * nameLen)1019 FILLP_INT DLL_API FtGetPeerName(
1020 FILLP_INT fd,
1021 FILLP_SOCKADDR *name,
1022 socklen_t *nameLen)
1023 {
1024 return SockGetpeername(fd, name, nameLen);
1025 }
1026
1027 /**
1028 * @Description : This function is called by the Fillp Adapter to get system
1029 * socket parameters.
1030 * @note: All parameters are passed uninterpreted to system interface, for RAW socket it always return failure
1031
1032 * @param : fd: a socket, which is create by FtSocket
1033 * level: When manipulating socket options, the level at which the option resides and the name of
1034 * the option must be specified.
1035 * optName: Optname options are passed uninterpreted to system interface.
1036 * optVal: value is accessed by underlying system
1037 * optLen: value is accessed by underlying system
1038 * @return : success: ERR_OK fail: error code
1039 */
FtGetSockOpt(FILLP_INT fd,FILLP_INT level,FILLP_INT optName,void * optVal,FILLP_INT * optLen)1040 FILLP_INT DLL_API FtGetSockOpt(
1041 FILLP_INT fd,
1042 FILLP_INT level,
1043 FILLP_INT optName,
1044 void *optVal,
1045 FILLP_INT *optLen)
1046 {
1047 return SockGetSockOpt(fd, level, optName, optVal, optLen);
1048 }
1049
1050 /**
1051 * @Description : This function is called by the Fillp Adapter to set system
1052 * socket parameters.
1053 * @note: All parameters are passed uninterpreted to system interface, for RAW socket it always return failure
1054 *
1055 * @param : fd: a socket, which is create by FtSocket
1056 * level: When manipulating socket options, the level at which the option resides and the name of
1057 * the option must be specified.
1058 * optName: Optname options are passed uninterpreted to system interface.
1059 * optVal: value is accessed by underlying system
1060 * optLen: value is accessed by underlying system
1061 * @return : success: ERR_OK fail: error code
1062 */
FtSetSockOpt(FILLP_INT fd,FILLP_INT level,FILLP_INT optName,FILLP_CONST void * optVal,socklen_t optLen)1063 FILLP_INT DLL_API FtSetSockOpt(
1064 FILLP_INT fd,
1065 FILLP_INT level,
1066 FILLP_INT optName,
1067 FILLP_CONST void *optVal,
1068 socklen_t optLen)
1069 {
1070 return SockSetSockOpt(fd, level, optName, optVal, optLen);
1071 }
1072
1073 /*******************************************************************
1074 Function : FtIoctlSocket
1075 Description : This function controls the I/O mode of a socket.
1076 Return : FILLP_OK on success.
1077 Error code on failure.
1078 ********************************************************************/
FtIoctlSocket(FILLP_INT fd,FILLP_SLONG cmd,FILLP_CONST FILLP_INT * val)1079 FILLP_INT DLL_API FtIoctlSocket(FILLP_INT fd, FILLP_SLONG cmd, FILLP_CONST FILLP_INT *val)
1080 {
1081 #if defined(_WINDOWS) || defined(FILLP_WIN32)
1082 return SockIoctlsocket(fd, cmd, val);
1083 #else
1084 FILLP_LOGERR("FILLP_WIN32 or _WINDOWS Macro is not enabled. i.e. ioctlsocket Functionality "
1085 "not supported in OS other than windows. but still invoked , socket index : %d", fd);
1086 FILLP_UNUSED_PARA(fd);
1087 FILLP_UNUSED_PARA(cmd);
1088 FILLP_UNUSED_PARA(val);
1089 SET_ERRNO(FILLP_EOPNOTSUPP);
1090 return -1;
1091 #endif
1092 }
1093
1094
1095 /*******************************************************************************
1096 Function : FtFillpStatsGet
1097
1098 Description : This function is called by the fillp Adapter to get the
1099 statistics information for a each type.
1100
1101 Input : fd - socket index for which stats need to be provided
1102 OutStats - fillp_statistics_pc, to which statistics will be copied.
1103 user has to provide and free the buffer.
1104 Output : pucStatsData - stats Data
1105
1106 Return : FILLP_SUCCESS - In success case
1107 Other error code in case of failure
1108 *******************************************************************************/
FtFillpStatsGet(IN FILLP_INT fd,OUT struct FillpStatisticsPcb * outStats)1109 FILLP_INT FtFillpStatsGet(
1110 IN FILLP_INT fd,
1111 OUT struct FillpStatisticsPcb *outStats)
1112 {
1113 struct FtSocket *sock = FILLP_NULL_PTR;
1114
1115 if (outStats == FILLP_NULL_PTR) {
1116 FILLP_LOGERR(" error: out parameter is NULLPTR");
1117 return ERR_NULLPTR;
1118 }
1119
1120 sock = SockGetSocket(fd);
1121 if (sock == FILLP_NULL_PTR) {
1122 FILLP_LOGERR("Invalid fillp_sock_id:%d", fd);
1123 SET_ERRNO(FILLP_EBADF);
1124 return -1;
1125 }
1126
1127 /* All configuration changes are not write protected, so other thread can read old value when this
1128 function is getting executed. but this is ok as per fillp design. */
1129 if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
1130 FILLP_LOGERR("Socket-%d state is changing,maybe closing", fd);
1131 SET_ERRNO(FILLP_EBUSY);
1132 return -1;
1133 }
1134
1135 if (sock->allocState == SOCK_ALLOC_STATE_FREE) {
1136 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1137 SET_ERRNO(FILLP_ENOTSOCK);
1138 return -1;
1139 }
1140
1141 if ((sock->netconn != FILLP_NULL_PTR) && (((struct FtNetconn *)sock->netconn)->pcb != FILLP_NULL_PTR)) {
1142 (void)memcpy_s(outStats, sizeof(struct FillpStatisticsPcb),
1143 &((struct FtNetconn *)sock->netconn)->pcb->fpcb.statistics, sizeof(struct FillpStatisticsPcb));
1144 } else {
1145 FILLP_LOGERR(" error: netconn/pcb is NULLPTR");
1146 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1147 SET_ERRNO(FILLP_ENOTCONN);
1148 return -1;
1149 }
1150 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1151 return FILLP_SUCCESS;
1152 }
1153
1154 /*******************************************************************************
1155 Function : FtFillpStatPackStat
1156
1157 Description : This function is called by the FtFillpStatShow to show the
1158 statistics info related to pack.
1159 Input : pcb - socket pcb for which pack info needs to be displayed.
1160
1161 Output : None
1162
1163 Return : None
1164 *******************************************************************************/
FtFillpStatPackStat(FILLP_CONST struct FillpStatisticsPcb * pcb)1165 void FtFillpStatPackStat(FILLP_CONST struct FillpStatisticsPcb *pcb)
1166 {
1167 FILLP_SHOWDATABUTT("FillpPackStastics :-");
1168 FILLP_SHOWDATABUTT("packInterval: %u", pcb->pack.packInterval);
1169 FILLP_SHOWDATABUTT("packTimePassed: %lld", pcb->pack.packTimePassed);
1170
1171 FILLP_SHOWDATABUTT("periodRecvRate: %u", pcb->pack.periodRecvRate);
1172 FILLP_SHOWDATABUTT("maxRecvRate: %u", pcb->pack.maxRecvRate);
1173 FILLP_SHOWDATABUTT("packLostSeq: %u", pcb->pack.packLostSeq);
1174 FILLP_SHOWDATABUTT("packPktNum: %u", pcb->pack.packPktNum);
1175 FILLP_SHOWDATABUTT("periodRecvedOnes: %u", pcb->pack.periodRecvedOnes);
1176 FILLP_SHOWDATABUTT("periodDroped: %u", pcb->pack.periodDroped);
1177 FILLP_SHOWDATABUTT("periodRecvBits: %llu", pcb->pack.periodRecvBits);
1178 FILLP_SHOWDATABUTT("periodRecvPktLoss: %u", pcb->pack.periodRecvPktLoss);
1179 FILLP_SHOWDATABUTT("peerRtt: %u", pcb->pack.peerRtt);
1180 FILLP_SHOWDATABUTT("packSendTime: %lld", pcb->pack.packSendTime);
1181 FILLP_SHOWDATABUTT("periodSendRate: %u", pcb->pack.periodSendRate);
1182 FILLP_SHOWDATABUTT("periodAckByPackRate: %u", pcb->pack.periodAckByPackRate);
1183 FILLP_SHOWDATABUTT("packIntervalBackup: %u", pcb->pack.packIntervalBackup);
1184 FILLP_SHOWDATABUTT("packRttDetectTime: %lld", pcb->pack.packRttDetectTime);
1185
1186 FILLP_SHOWDATABUTT("FillpPackStastics End's");
1187
1188 return;
1189 }
1190
1191 /*******************************************************************************
1192 Function : FtFillpStatKeepAlive
1193
1194 Description : This function is called by the FtFillpStatShow to show the
1195 statistics info related to keep alive.
1196 Input : pcb - socket pcb for which keep alive info needs to be displayed.
1197
1198 Output : None
1199
1200 Return : none
1201 *******************************************************************************/
FtFillpStatKeepAlive(FILLP_CONST struct FillpStatisticsPcb * pcb)1202 void FtFillpStatKeepAlive(FILLP_CONST struct FillpStatisticsPcb *pcb)
1203 {
1204 FILLP_SHOWDATABUTT("FillpKeepAliveStastics :-");
1205 FILLP_SHOWDATABUTT("lastRecvTime: %lld", pcb->keepAlive.lastRecvTime);
1206 FILLP_SHOWDATABUTT("lastDataRecvTime: %lld", pcb->keepAlive.lastDataRecvTime);
1207 FILLP_SHOWDATABUTT("lastSendTime: %lld", pcb->keepAlive.lastSendTime);
1208 FILLP_SHOWDATABUTT("FillpKeepAliveStastics End's");
1209
1210 return;
1211 }
1212
1213 /*******************************************************************************
1214 Function : FtFillpStatDebugStat
1215
1216 Description : This function is called by the FtFillpStatShow to show the
1217 statistics info related to debg/.
1218 Input : pcb - socket pcb for which debg/ info needs to be displayed.
1219
1220 Output : None
1221
1222 Return : None
1223 *******************************************************************************/
FtFillpStatDebugStat(FILLP_CONST struct FillpStatisticsPcb * pcb)1224 void FtFillpStatDebugStat(FILLP_CONST struct FillpStatisticsPcb *pcb)
1225 {
1226 FILLP_SHOWDATABUTT("FillpStatatisticsDebugPcb :-");
1227
1228 FILLP_SHOWDATABUTT("multiRetry: %d ", pcb->debugPcb.multiRetry);
1229 FILLP_SHOWDATABUTT("retryOne: %d ", pcb->debugPcb.retryOne);
1230 FILLP_SHOWDATABUTT("retryThreeTimes: %d ", pcb->debugPcb.retryThreeTimes);
1231 FILLP_SHOWDATABUTT("retryFourthTimes: %d ", pcb->debugPcb.retryFourthTimes);
1232 FILLP_SHOWDATABUTT("retryMore: %d ", pcb->debugPcb.retryMore);
1233 FILLP_SHOWDATABUTT("maxRetry: %d ", pcb->debugPcb.maxRetry);
1234 FILLP_SHOWDATABUTT("connReqSend: %u ", pcb->debugPcb.connReqSend);
1235 FILLP_SHOWDATABUTT("connReqFailed: %u ", pcb->debugPcb.connReqFailed);
1236 FILLP_SHOWDATABUTT("connReqAckSend: %u ", pcb->debugPcb.connReqAckSend);
1237 FILLP_SHOWDATABUTT("connReqAckFailed: %u ", pcb->debugPcb.connReqAckFailed);
1238 FILLP_SHOWDATABUTT("connConfirmSend: %u ", pcb->debugPcb.connConfirmSend);
1239 FILLP_SHOWDATABUTT("connConfirmFailed: %u ", pcb->debugPcb.connConfirmFailed);
1240 FILLP_SHOWDATABUTT("connConfirmAckSend: %u ", pcb->debugPcb.connConfirmAckSend);
1241 FILLP_SHOWDATABUTT("connConfirmAckFailed: %u ", pcb->debugPcb.connConfirmAckFailed);
1242 FILLP_SHOWDATABUTT("disconnReqSend: %u ", pcb->debugPcb.disconnReqSend);
1243 FILLP_SHOWDATABUTT("disconnReqFailed: %u ", pcb->debugPcb.disconnReqFailed);
1244 FILLP_SHOWDATABUTT("disconnRspSend: %u ", pcb->debugPcb.disconnRspSend);
1245 FILLP_SHOWDATABUTT("disconnRspFailed: %u ", pcb->debugPcb.disconnRspFailed);
1246 FILLP_SHOWDATABUTT("keepAliveProbeReqSend: %u ", pcb->debugPcb.keepAliveProbeReqSend);
1247 FILLP_SHOWDATABUTT("keepAliveProbeReqFailed: %u ", pcb->debugPcb.keepAliveProbeReqFailed);
1248 FILLP_SHOWDATABUTT("keepAliveProbeRspSend: %u ", pcb->debugPcb.keepAliveProbeRspSend);
1249 FILLP_SHOWDATABUTT("keepAliveProbeRspFailed: %u ", pcb->debugPcb.keepAliveProbeRspFailed);
1250 FILLP_SHOWDATABUTT("nackSend: %u ", pcb->debugPcb.nackSend);
1251 FILLP_SHOWDATABUTT("nackFailed: %u ", pcb->debugPcb.nackFailed);
1252 FILLP_SHOWDATABUTT("nackRcv: %u ", pcb->debugPcb.nackRcv);
1253 FILLP_SHOWDATABUTT("packSend: %u ", pcb->debugPcb.packSend);
1254 FILLP_SHOWDATABUTT("packFailed: %u ", pcb->debugPcb.packFailed);
1255 FILLP_SHOWDATABUTT("packRcv: %u ", pcb->debugPcb.packRcv);
1256 FILLP_SHOWDATABUTT("nackPktNum: %u ", pcb->debugPcb.nackPktNum);
1257 FILLP_SHOWDATABUTT("packIntervalPktNum: %u ", pcb->debugPcb.packIntervalPktNum);
1258 FILLP_SHOWDATABUTT("packIntervalSendBytes: %u ", pcb->debugPcb.packIntervalSendBytes);
1259 FILLP_SHOWDATABUTT("packIntervalSendPkt: %u ", pcb->debugPcb.packIntervalSendPkt);
1260 FILLP_SHOWDATABUTT("FillpStatatisticsDebugPcb End's ");
1261
1262 return;
1263 }
1264
1265 /*******************************************************************************
1266 Function : FtFillpStatTraffic
1267
1268 Description : This function is called by the FtFillpStatShow to show the
1269 statistics info related to traffic.
1270 Input : pcb - socket pcb for which traffic info needs to be displayed.
1271
1272 Output : None
1273
1274 Return : None
1275 *******************************************************************************/
FtFillpStatTraffic(FILLP_CONST struct FillpStatisticsPcb * pcb)1276 void FtFillpStatTraffic(FILLP_CONST struct FillpStatisticsPcb *pcb)
1277 {
1278 FILLP_SHOWDATABUTT("Total Send Ones : %u,Bytes Sent %u, Send Failed ones : %u ",
1279 pcb->traffic.totalSend, pcb->traffic.totalSendBytes, pcb->traffic.totalSendFailed);
1280 FILLP_SHOWDATABUTT("pktReceived %u,Bytes Received %u, invalid Ones : %u",
1281 pcb->traffic.totalRecved, pcb->traffic.totalRecvedBytes, pcb->traffic.totalDroped);
1282 FILLP_SHOWDATABUTT("Retry Send Ones : %u ", pcb->traffic.totalRetryed);
1283 FILLP_SHOWDATABUTT("Out-of-order Ones : %u", pcb->traffic.totalOutOfOrder);
1284 FILLP_SHOWDATABUTT("Recv Lost : %u", pcb->traffic.totalRecvLost);
1285
1286 return;
1287 }
1288
1289 /*******************************************************************************
1290 Function : FtFillpInnerStatShow
1291
1292 Description : This function is called by the fillp Adapter to show the
1293 statistics info.
1294 Input : ulStatsType - Statistics type as defined in
1295 Different Statistics will be defined based on the Product requirements
1296 sockFd - Socket Index
1297 Output : None
1298 *******************************************************************************/
FtFillpInnerStatShow(IN FILLP_UINT32 fillpStatsType,IN FILLP_CONST struct FillpStatisticsPcb * pcb)1299 void FtFillpInnerStatShow(
1300 IN FILLP_UINT32 fillpStatsType,
1301 IN FILLP_CONST struct FillpStatisticsPcb *pcb)
1302 {
1303 if ((fillpStatsType == FILLP_STATS_DIRECT_PACK) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1304 FtFillpStatPackStat(pcb);
1305 }
1306
1307 if ((fillpStatsType == FILLP_STATS_DIRECT_KEEP_ALIVE) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1308 FtFillpStatKeepAlive(pcb);
1309 }
1310
1311 if ((fillpStatsType == FILLP_STATS_DIRECT_DEBUG) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1312 FtFillpStatDebugStat(pcb);
1313 }
1314
1315 if ((fillpStatsType == FILLP_STATS_DIRECT_TRAFFIC) || (fillpStatsType == FILLP_STATS_DIRECT_ALL)) {
1316 FtFillpStatTraffic(pcb);
1317 }
1318
1319 return;
1320 }
1321
1322 /*******************************************************************************
1323 Function : FtFillpStatShow
1324
1325 Description : This function is called by the fillp Adapter to show the
1326 statistics info.
1327 Input : ulFillpStatsType - Statistics type as defined in
1328 Different Statistics will be defined based on the Product requirements
1329 fd - Socket Index
1330 Output : None
1331
1332 Return : FILLP_SUCCESS - In success case
1333 Other error code in case of failure
1334 *******************************************************************************/
FtFillpStatShow(IN FILLP_UINT32 fillpStatsType,IN FILLP_INT fd)1335 FILLP_INT FtFillpStatShow(
1336 IN FILLP_UINT32 fillpStatsType,
1337 IN FILLP_INT fd)
1338 {
1339 struct FillpStatisticsPcb *pcb = FILLP_NULL_PTR;
1340 struct FtSocket *sock = SockGetSocket(fd);
1341
1342 if (sock == FILLP_NULL_PTR) {
1343 FILLP_LOGERR("ERR_NULLPTR FtSocket sockFd = %d \r", fd);
1344 SET_ERRNO(FILLP_EBADF);
1345 return -1;
1346 }
1347
1348 if (SYS_ARCH_RWSEM_TRYRDWAIT(&sock->sockConnSem) != ERR_OK) {
1349 FILLP_LOGERR("Socket-%d state is changing,maybe closing", fd);
1350 SET_ERRNO(FILLP_EBUSY);
1351 return -1;
1352 }
1353
1354 if ((sock->allocState == SOCK_ALLOC_STATE_FREE) ||
1355 (sock->netconn == FILLP_NULL_PTR) ||
1356 (((struct FtNetconn *)sock->netconn)->pcb) == FILLP_NULL_PTR) {
1357 FILLP_LOGERR("ERR_NULLPTR FtSocket sockFd = %d", fd);
1358 SET_ERRNO(FILLP_EBADF);
1359 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1360 return -1;
1361 }
1362
1363 if (fillpStatsType > FILLP_STATS_DIRECT_ALL) {
1364 FILLP_LOGERR("invalid fillpStatsType = %u \r", fillpStatsType);
1365 SET_ERRNO(FILLP_EINVAL);
1366 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1367 return -1;
1368 }
1369
1370 pcb = &(((struct FtNetconn *)sock->netconn)->pcb->fpcb.statistics);
1371
1372 FtFillpInnerStatShow(fillpStatsType, pcb);
1373
1374 FILLP_SHOWDATABUTT("Total Sockets : %d,Total Free Sockets : %d", g_spunge->sockTable->size,
1375 FillpRingFreeEntries(&(g_spunge->sockTable->freeQueqe->ring)));
1376 (void)SYS_ARCH_RWSEM_RDPOST(&sock->sockConnSem);
1377 return FILLP_SUCCESS;
1378 }
1379
1380 #define FILLP_REG_OS_BASIC_LIB_FUNC(funSt, func) do { \
1381 if ((funSt)->sysLibBasicFunc.func != FILLP_NULL_PTR) { \
1382 g_fillpOsBasicLibFun.func = (funSt)->sysLibBasicFunc.func; \
1383 } \
1384 } while (0)
1385
FtRegCopyOsBasicLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1386 void FtRegCopyOsBasicLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1387 {
1388 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memCalloc);
1389 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memAlloc);
1390 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, memFree);
1391 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpStrLen);
1392 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpRand);
1393 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, fillpCreateThread);
1394 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArcInit);
1395 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArcGetCurTimeLongLong);
1396 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicInc);
1397 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicDec);
1398 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicRead);
1399 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchAtomicSet);
1400 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysArchCompAndSwap);
1401 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysSleepMs);
1402 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, sysUsleep);
1403 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, rtePause);
1404 FILLP_REG_OS_BASIC_LIB_FUNC(libSysFunc, cryptoRand);
1405 /* This is mandatory callback, so if it is NULL then it will fail in FillpApiRegLibSysFunc itself */
1406 g_fillpOsBasicLibFun.cryptoRand = libSysFunc->sysLibBasicFunc.cryptoRand;
1407 }
1408
1409 #define FILLP_REG_OS_SEM_LIB_FUNC(funSt, func) do { \
1410 if ((funSt)->sysLibSemFunc.func != FILLP_NULL_PTR) { \
1411 g_fillpOsSemLibFun.func = (funSt)->sysLibSemFunc.func; \
1412 } \
1413 } while (0)
1414
FtRegCopyOsSemLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1415 void FtRegCopyOsSemLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1416 {
1417 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemClose);
1418 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemInit);
1419 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemTryWait);
1420 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemWait);
1421 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemPost);
1422 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemDestroy);
1423 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSemWaitTimeout);
1424 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemInit);
1425 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemTryRDWait);
1426 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemTryWRWait);
1427 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemRDPost);
1428 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemWRPost);
1429 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchRWSemDestroy);
1430 FILLP_REG_OS_SEM_LIB_FUNC(libSysFunc, sysArchSchedYield);
1431 }
1432
1433 #define FILLP_REG_OS_SOCKET_LIB_FUNC(funSt, func) do { \
1434 if ((funSt)->sysLibSockFunc.func != FILLP_NULL_PTR) { \
1435 g_fillpOsSocketLibFun.func = (funSt)->sysLibSockFunc.func; \
1436 } \
1437 } while (0)
1438
FtRegCopyOsSocketLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc)1439 void FtRegCopyOsSocketLibFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc)
1440 {
1441 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, socketCallbackFunc);
1442 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, select);
1443 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, bindCallbackFunc);
1444 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, closeSocketCallbackFunc);
1445 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, recvFromCallbackFunc);
1446 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, sendtoCallbackFunc);
1447 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, ioctl);
1448 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fcntl);
1449 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, setSockOpt);
1450 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, getSockOpt);
1451 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, sendCallbackFunc);
1452 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, getSockNameCallbackFunc);
1453 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, connectCallbackFunc);
1454 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdClr);
1455 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdSet);
1456 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncFdIsSet);
1457 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncCreateFdSet);
1458 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncDestroyFdSet);
1459 FILLP_REG_OS_SOCKET_LIB_FUNC(libSysFunc, fillpFuncCopyFdSet);
1460 }
1461
FillpApiRegLibSysFunc(IN FILLP_CONST FillpSysLibCallbackFuncSt * libSysFunc,IN FILLP_CONST void * para)1462 FILLP_INT32 FillpApiRegLibSysFunc(
1463 IN FILLP_CONST FillpSysLibCallbackFuncSt *libSysFunc,
1464 IN FILLP_CONST void *para) /* For random function */
1465 {
1466 if (g_spunge != FILLP_NULL_PTR) {
1467 SET_ERRNO(FILLP_EOPNOTSUPP);
1468 return -1;
1469 }
1470
1471 if (FILLP_INVALID_PTR(libSysFunc)) {
1472 SET_ERRNO(FILLP_EINVAL);
1473 return -1;
1474 }
1475
1476 FillpRegLibSysFunc();
1477
1478 if (FILLP_INVALID_PTR(libSysFunc->sysLibBasicFunc.cryptoRand)) {
1479 SET_ERRNO(FILLP_EINVAL);
1480 return -1;
1481 }
1482
1483 /* Basic Os function Registration */
1484 FtRegCopyOsBasicLibFunc(libSysFunc);
1485
1486 /* Semaphore function Registration */
1487 FtRegCopyOsSemLibFunc(libSysFunc);
1488
1489 /* Socket function registration */
1490 FtRegCopyOsSocketLibFunc(libSysFunc);
1491
1492 FILLP_UNUSED_PARA(para);
1493 return FILLP_SUCCESS;
1494 }
1495
FillpApiRegAppCallbackFunc(IN FILLP_CONST FillpAppCallbackFunc * appCbkFunc)1496 FILLP_INT32 FillpApiRegAppCallbackFunc(IN FILLP_CONST FillpAppCallbackFunc *appCbkFunc)
1497 {
1498 if (FILLP_INVALID_PTR(appCbkFunc)) {
1499 SET_ERRNO(FILLP_EINVAL);
1500 return -1;
1501 }
1502
1503 g_fillpAppCbkFun.fillpSockCloseCbkFunc = appCbkFunc->fillpSockCloseCbkFunc;
1504
1505 return FILLP_SUCCESS;
1506 }
1507
FtGetVersion(void)1508 FILLP_CHAR_PTR DLL_API FtGetVersion(void)
1509 {
1510 return (FILLP_VERSION);
1511 }
1512
FtGetErrno(void)1513 FILLP_INT DLL_API FtGetErrno(void)
1514 {
1515 #ifdef FILLP_LINUX
1516 return errno;
1517 #elif defined(FILLP_WIN32)
1518 return WSAGetLastError();
1519 #endif
1520 }
1521
FtGetStackTime(FILLP_INT instInx)1522 FILLP_ULLONG DLL_API FtGetStackTime(FILLP_INT instInx)
1523 {
1524 if ((g_spunge == FILLP_NULL_PTR) || (g_spunge->hasInited == FILLP_FALSE)) {
1525 FILLP_LOGERR("Stack not ready");
1526 return 0;
1527 }
1528
1529 if ((instInx < 0) || ((FILLP_UINT)instInx >= g_spunge->insNum)) {
1530 FILLP_LOGERR("Inst index is out of range it should be [0,%u)", g_spunge->insNum);
1531 return 0;
1532 }
1533
1534 return (FILLP_ULLONG)g_spunge->instPool[instInx].curTime;
1535 }
1536
1537 /*******************************************************************************
1538 Function : FtApiRegEventCallbackFunc
1539
1540 Description : Register the event callback function on the socket.
1541
1542 Input : fd - Indicates a socket created by the FtSocket API.
1543 evtCbkFunc - Pointer to event callback function FillpEvtCbkFunc.
1544
1545 Output : None.
1546
1547 Return :
1548 0 : Success
1549 -1 : Failure
1550 *******************************************************************************/
FtApiRegEventCallbackFunc(IN FILLP_INT fd,IN FillpEvtCbkFunc evtCbkFunc)1551 FILLP_INT DLL_API FtApiRegEventCallbackFunc(IN FILLP_INT fd, IN FillpEvtCbkFunc evtCbkFunc)
1552 {
1553 FILLP_UNUSED_PARA(fd);
1554 FILLP_UNUSED_PARA(evtCbkFunc);
1555 FILLP_LOGERR("regist evt callback not support yet");
1556 SET_ERRNO(FILLP_EOPNOTSUPP);
1557 return -1;
1558 }
1559
1560 /*******************************************************************************
1561 Function : FtApiUnregEventCallbackFunc
1562
1563 Description : unregister the event callback function on the socket.
1564
1565 Input : fd - Indicates a socket created by the FtSocket API.
1566 evtCbkFunc - Pointer to event callback function FillpEvtCbkFunc.
1567
1568 Output : None.
1569
1570 Return :
1571 0 : Success
1572 -1 : Failure
1573 *******************************************************************************/
FtApiUnregEventCallbackFunc(IN FILLP_INT fd,IN FillpEvtCbkFunc evtCbkFunc)1574 FILLP_INT DLL_API FtApiUnregEventCallbackFunc(IN FILLP_INT fd, IN FillpEvtCbkFunc evtCbkFunc)
1575 {
1576 FILLP_UNUSED_PARA(fd);
1577 FILLP_UNUSED_PARA(evtCbkFunc);
1578 FILLP_LOGERR("unregist evt callback not support yet");
1579 SET_ERRNO(FILLP_EOPNOTSUPP);
1580 return -1;
1581 }
1582
1583 /*******************************************************************************
1584 Function : FtApiEventInfoGet
1585
1586 Description : Get the event info on the socket.
1587
1588 Input : fd - Indicates a socket created by the FtSocket API.
1589 info->evt - Indicates the event type.
1590
1591 Output : info->info - Indicates the event info according to the event type.
1592
1593 Return :
1594 0 : Success
1595 -1 : Failure
1596 *******************************************************************************/
FtApiEventInfoGet(IN FILLP_INT fd,IO FtEventCbkInfo * info)1597 FILLP_INT DLL_API FtApiEventInfoGet(IN FILLP_INT fd, IO FtEventCbkInfo *info)
1598 {
1599 return SockEventInfoGet(fd, info);
1600 }
1601
FtSetDfxEventCb(void * softObj,FillpDfxEventCb evtCb)1602 FILLP_INT DLL_API FtSetDfxEventCb(void *softObj, FillpDfxEventCb evtCb)
1603 {
1604 return FillpDfxEvtCbSet(softObj, evtCb);
1605 }
1606
FtDfxHiDumper(FILLP_UINT32 argc,const FILLP_CHAR ** argv,void * softObj,FillpDfxDumpFunc dump)1607 FILLP_INT FtDfxHiDumper(FILLP_UINT32 argc, const FILLP_CHAR **argv, void *softObj, FillpDfxDumpFunc dump)
1608 {
1609 #ifdef FILLP_ENABLE_DFX_HIDUMPER
1610 return FillpDfxDump(argc, argv, softObj, dump);
1611 #else
1612 (void)argc;
1613 (void)argv;
1614 (void)softObj;
1615 (void)dump;
1616 FILLP_LOGERR("unsupport FtFillpDfxDump");
1617 return -1;
1618 #endif /* FILLP_ENABLE_DFX_HIDUMPER */
1619 }
1620
1621 #ifdef __cplusplus
1622 }
1623 #endif
1624
1625