Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
socket_nmc.h
00001 /* 00002 @file 00003 socket.h 00004 00005 @brief Socket Interface APIs 00006 00007 The file defines APIs and types of socket layer for the NMC1500 IoT solution. The APIs are very similar 00008 to the standard POSIX sockets APIs. The socket layer operates in asynchronus mode which means socket 00009 functions are non-blocking functions, requiring the result of a socket operation (eg. bind) is delivered later 00010 in a callback function [APPSocketEventHandler](@ref APPSocketEventHandler). 00011 */ 00012 #ifndef __SOCKET_NMC_H__ 00013 #define __SOCKET_NMC_H__ 00014 00015 #include "nmi_wlan_if.h" 00016 #include "nmi_wlan.h" 00017 00018 #ifdef __cplusplus 00019 extern "C" { 00020 #endif 00021 00022 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 00023 INCLUDES 00024 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 00025 00026 //#include "common\include\nm_common.h" 00027 00028 #define NMI_API 00029 00030 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 00031 MACROS 00032 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 00033 00034 00035 #define HOSTNAME_MAX_SIZE 64 00036 /*< Maximum allowed size for a host domain name. 00037 */ 00038 00039 00040 00041 #define SOCKET_BUFFER_MAX_LENGTH 1400 00042 /*< Maximum allowed size for a socket Data buffer. 00043 */ 00044 00045 00046 #define AF_INET 2 00047 /*< Supported socket family. 00048 */ 00049 00050 00051 #define SOCK_STREAM 1 00052 /*< This is the identifier of TCP socket type. 00053 */ 00054 00055 00056 #define SOCK_DGRAM 2 00057 /*< This is the identifier of UDP socket type. 00058 */ 00059 00060 00061 #define SOCKET_FLAGS_SSL 0x01 00062 /*< This flag shall be passed to the 00063 socket API for SSL session. 00064 */ 00065 00066 00067 #define TCP_SOCK_MAX 2//(7) 00068 /*< Maximum number of simultaneous TCP sockets. 00069 */ 00070 00071 00072 #define UDP_SOCK_MAX 2//4 00073 /*< Maximum number of simultaneous UDP sockets. 00074 */ 00075 00076 00077 #define MAX_SOCKET (TCP_SOCK_MAX + UDP_SOCK_MAX) 00078 /*< Maximum number of Sockets. 00079 */ 00080 00081 00082 /************** 00083 Socket Errors 00084 **************/ 00085 00086 #define SOCK_ERR_NO_ERROR 0 00087 /*< Every thing is OK. 00088 */ 00089 00090 00091 #define SOCK_ERR_INVALID_ADDRESS -1 00092 /*< Socket address is invalid. The socket operation cannot 00093 be completed without address is specified. For example, 00094 Bind is called without specifying a port number. 00095 */ 00096 00097 00098 #define SOCK_ERR_ADDR_ALREADY_IN_USE -2 00099 /*< Cannot bind on the given address. It is already bound 00100 by another opened socket. 00101 */ 00102 00103 00104 #define SOCK_ERR_MAX_TCP_SOCK -3 00105 /*< The maximum number of TCP sockets is reached. Socket 00106 creation failed. 00107 */ 00108 00109 00110 #define SOCK_ERR_MAX_UDP_SOCK -4 00111 /*< The maximum number of UDP sockets is reached. Socket 00112 creation failed. 00113 */ 00114 00115 00116 #define SOCK_ERR_INVALID_ARG -6 00117 /*< An invalid arguement is passed to a function. 00118 */ 00119 00120 00121 #define SOCK_ERR_MAX_LISTEN_SOCK -7 00122 /*< The maximum number of TCP passive listening sockets is 00123 reached. Listen function fails. 00124 */ 00125 00126 00127 #define SOCK_ERR_INVALID -9 00128 /*< The requested socket operation is not valid in the 00129 current socket state. For Example, accept is called on a 00130 TCP socket before bind or listen. 00131 */ 00132 00133 00134 #define SOCK_ERR_ADDR_IS_REQUIRED -11 00135 /*< The socket address is required for the operation to 00136 be completed. It is generated from sendto when there is 00137 no valid address found to send the data to. 00138 */ 00139 00140 00141 #define SOCK_ERR_CONN_ABORTED -12 00142 /*< The socket is closed by the peer. The local socket is 00143 closed also. 00144 */ 00145 00146 00147 #define SOCK_ERR_TIMEOUT -13 00148 /*< The socket pending operation has been timedout. 00149 */ 00150 00151 00152 #define SOCK_ERR_BUFFER_FULL -14 00153 /*< The send operation could not be performed before the 00154 transmission buffer corresponding to this socket is busy. 00155 */ 00156 00157 #ifndef _NM_BSP_BIG_END 00158 00159 #define _htonl(m) (m) 00160 #define _htons(A) (A) 00161 00162 #else 00163 00164 #define _htonl(m) \ 00165 (uint32)(((uint32)(m << 24)) | ((uint32)((m & 0x0000FF00) << 8)) | ((uint32)((m & 0x00FF0000) >> 8)) | ((uint32)(m >> 24))) 00166 /*< Convert a 4-byte integer from the host representation to the Network byte order representation. 00167 */ 00168 00169 00170 #define _htons(A) (uint16)((((uint16) (A)) << 8) | (((uint16) (A)) >> 8)) 00171 /*< Convert a 2-byte integer (short) from the host representation to the Network byte order representation. 00172 */ 00173 00174 00175 #endif 00176 00177 00178 #define _ntohl _htonl 00179 /*< Convert a 4-byte integer from the Network byte order representation to the host representation . 00180 */ 00181 00182 00183 #define _ntohs _htons 00184 /*< Convert a 2-byte integer from the Network byte order representation to the host representation . 00185 */ 00186 00187 00188 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 00189 DATA TYPES 00190 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 00191 00192 /* 00193 @typedef \ 00194 SOCKET 00195 00196 @brief 00197 Data type definition for socket handlers. 00198 */ 00199 typedef sint8 SOCKET; 00200 00201 00202 /* 00203 @struct \ 00204 in_addr 00205 00206 @brief 00207 IPv4 address representation. 00208 */ 00209 typedef struct{ 00210 uint32 s_addr; 00211 /*< Network Byte Order representation of the IPv4 address. 00212 */ 00213 }in_addr_nmc;//Tsungta 00214 00215 00216 /* 00217 @struct \ 00218 sockaddr 00219 00220 @brief 00221 Generic socket address structure. 00222 */ 00223 struct sockaddr{ 00224 uint16 sa_family; 00225 uint8 sa_data[14]; 00226 }; 00227 00228 00229 /* 00230 @struct \ 00231 sockaddr_in 00232 00233 @brief 00234 Socket address structure for IPV4 addresses. 00235 */ 00236 struct sockaddr_in_nmc{//Tsungta 00237 uint16 sin_family; 00238 /*< The only supported value for this is AF_INET. 00239 */ 00240 uint16 sin_port; 00241 /*< Port number of the socket address. It must be set in the 00242 Network Byte Order format (e.g. _htons(80)). 00243 */ 00244 in_addr_nmc sin_addr; //Tsungta 00245 /*< IP Address [in_addr]. 00246 */ 00247 uint8 sin_zero[8]; 00248 /*< Dummy bytes. 00249 */ 00250 }; 00251 00252 00253 /******************************************* 00254 Specific Definitions for Asynchronous implementation 00255 *******************************************/ 00256 00257 /* 00258 @enum \ 00259 tenuSocketCallbackMsgType 00260 00261 @brief 00262 Socket message types for socket callback notifications. 00263 */ 00264 typedef enum{ 00265 SOCKET_MSG_BIND = 1, 00266 SOCKET_MSG_LISTEN, 00267 SOCKET_MSG_DNS_RESOLVE, 00268 SOCKET_MSG_ACCEPT, 00269 SOCKET_MSG_CONNECT, 00270 SOCKET_MSG_RECV, 00271 SOCKET_MSG_SEND, 00272 SOCKET_MSG_SENDTO, 00273 SOCKET_MSG_RECVFROM, 00274 SOCKET_MSG_DHCP_OFFER, 00275 SOCKET_MSG_TCPERROR 00276 }tenuSocketCallbackMsgType; 00277 00278 /* 00279 @struct \ 00280 tstrSocketBindMsg 00281 00282 @brief Socket bind status. 00283 00284 It is passed to the APPSocketEventHandler with SOCKET_MSG_BIND message type 00285 in a response to a user call to bind. 00286 */ 00287 typedef struct{ 00288 sint8 status; 00289 /*< The result of the bind operation. 00290 */ 00291 }tstrSocketBindMsg; 00292 00293 00294 /* 00295 @struct \ 00296 tstrSocketListenMsg 00297 00298 @brief Socket listen status. 00299 00300 It is passed to the APPSocketEventHandler with SOCKET_MSG_LISTEN message type 00301 in a response to a user call to listen. 00302 */ 00303 typedef struct{ 00304 sint8 status; 00305 /*< Result of the listen operation. 00306 */ 00307 }tstrSocketListenMsg; 00308 00309 00310 00311 /* 00312 @struct \ 00313 tstrSocketAcceptMsg 00314 00315 @brief Socket accept status. 00316 00317 It is passed to the APPSocketEventHandler with SOCKET_MSG_ACCEPT message type 00318 in a response to a user call to accept. 00319 */ 00320 typedef struct{ 00321 SOCKET sock; 00322 /*< Socket ID for the accepted connection with a remote peer. If it is a negative value, it refers to 00323 an accept error (accept failed). 00324 */ 00325 struct sockaddr_in_nmc strAddr;//Tsungta 00326 /*< Socket address structure for the remote peer. 00327 */ 00328 }tstrSocketAcceptMsg; 00329 00330 00331 /* 00332 @struct \ 00333 tstrSocketConnectMsg 00334 00335 @brief Socket connect status. 00336 00337 It is passed to the APPSocketEventHandler with SOCKET_MSG_CONNECT message type 00338 in a response to a user call to connect. 00339 */ 00340 typedef struct{ 00341 SOCKET sock; 00342 /*< Socket ID referring to the socket passed to the connect function call. 00343 */ 00344 sint8 s8Error; 00345 /*< Connect error code. It shall be ZERO for successful connect and a negative number otherwise. 00346 */ 00347 }tstrSocketConnectMsg; 00348 00349 00350 /* 00351 @struct \ 00352 tstrSocketTCPErrorMsg 00353 00354 @brief Socket connect status. 00355 00356 It is passed to the APPSocketEventHandler with SOCKET_MSG_TCPERROR message type 00357 in a response for TCP socket error. 00358 */ 00359 typedef struct{ 00360 SOCKET sock; 00361 /*< Socket ID referring to the socket passed to the TCP socket control function call. 00362 */ 00363 sint8 s8Error; 00364 /*< Connect error code. TCP socket handling errors. 00365 */ 00366 }tstrSocketTCPErrorMsg; 00367 00368 /* 00369 @struct \ 00370 00371 tstrSocketRecvMsg 00372 00373 @brief Socket recv status. 00374 00375 It is passed to the APPSocketEventHandler with SOCKET_MSG_RECV or SOCKET_MSG_RECVFROM message type 00376 in a response to a user call to the recv or recvfrom. 00377 If the received data from the remote peer is larger than the USER Buffer size (given at recv call), the data is 00378 delivered to the user in a number of consecutive chunks according to the USER Buffer size. 00379 */ 00380 typedef struct{ 00381 uint8 *pu8Buffer; 00382 /*< Pointer to the USER buffer (passed to recv or recvfrom) containing a received data chunk. 00383 */ 00384 sint16 s16BufferSize; 00385 /*< The recevied data chunk size. It will be negative value if there is a recv error. 00386 */ 00387 uint16 u16RemainingSize; 00388 /*< The number of bytes remaining in the current recv operation. 00389 */ 00390 struct sockaddr_in_nmc strRemoteAddr;//Tsungta 00391 /*< Socket address structure for the remote peer. 00392 */ 00393 }tstrSocketRecvMsg; 00394 00395 00396 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* 00397 FUNCTION PROTOTYPES 00398 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/ 00399 00400 /* 00401 @fn \ 00402 NMI_API void socketInit(void); 00403 00404 @brief Socket Layer Initialization 00405 00406 The function performs the necessary initializations for the socket library. 00407 It must be invoked before any socket operation is performed. 00408 */ 00409 NMI_API void socketInit(void); 00410 00411 00412 /* 00413 @fn \ 00414 NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags); 00415 00416 @brief 00417 Creates a socket with a given type. 00418 00419 @param [in] u16Domain 00420 Socket family. The only allowed value is AF_INET for TCP/UDP sockets. 00421 00422 @param [in] u8Type 00423 Socket type. Allowed values are: 00424 - [SOCK_STREAM](@ref SOCK_STREAM) 00425 - [SOCK_DGRAM](@ref SOCK_DGRAM) 00426 00427 @param [in] u8Flags 00428 Used to specify the socket creation flags. It shall be set to zero for normal TCP/UDP sockets. 00429 If could be SOCKET_FLAGS_SSL if the socket is used for SSL session. The use of the flag 00430 [SOCKET_FLAGS_SSL](@ref SOCKET_FLAGS_SSL) has no meaning in case of UDP sockets. 00431 00432 @return 00433 The function shall return a negative value for socket creation failed and a nonnegative value 00434 representing the socket ID otherwise. 00435 */ 00436 NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags); 00437 00438 00439 /* 00440 @fn \ 00441 NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 00442 00443 @brief 00444 Binds a socket on a local port. 00445 00446 @param [in] sock 00447 Socket ID. 00448 00449 @param [in] pstrAddr 00450 Socket address for the address to be bound. 00451 00452 @param [in] u8AddrLen 00453 Size of the given address in bytes. 00454 00455 @return 00456 The function shall return ZERO for successful operation and a negative value otherwise. 00457 */ 00458 NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 00459 00460 00461 /* 00462 @fn \ 00463 NMI_API sint8 listen(SOCKET sock, uint8 backlog); 00464 00465 @brief 00466 Start listening on a passive socket for incoming connections. The socket must be bound on a local port 00467 or the listen fails. The listen function must be called at receiving [SOCKET_MSG_BIND](@ref SOCKET_MSG_BIND) 00468 in the socket callback. 00469 00470 @param [in] sock 00471 Socket ID. 00472 00473 @param [in] backlog 00474 Number of maximum allowed connections that will be accepted on the given socket. 00475 It is not used by the current implementation. 00476 00477 @return 00478 The function shall return ZERO for successful operation and a negative value otherwise. 00479 */ 00480 NMI_API sint8 listen(SOCKET sock, uint8 backlog); 00481 00482 00483 /* 00484 @fn \ 00485 NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen); 00486 00487 @brief 00488 Retrieve a successful connection . 00489 00490 @param [in] sock 00491 Socket ID. 00492 00493 @param [in] addr 00494 It is not used in the current implementation. 00495 00496 @param [in] addrlen 00497 It is not used in the current implementation. 00498 00499 @return 00500 The function shall return ZERO for successful operation and a negative value otherwise. 00501 */ 00502 NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen); 00503 00504 00505 /* 00506 @fn \ 00507 NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 00508 00509 @brief 00510 Establishes a TCP connection with a remote server. 00511 00512 @param [in] sock 00513 Socket ID. 00514 00515 @param [in] pstrAddr 00516 Address of the remote server. 00517 00518 @param [in] u8AddrLen 00519 Address length in bytes. 00520 00521 @return 00522 The function shall return ZERO for successful operation and a negative value otherwise. 00523 */ 00524 NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen); 00525 00526 00527 /* 00528 @fn \ 00529 NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32TimeoutSeconds); 00530 00531 @brief 00532 Recieves data from a TCP Scoket. 00533 00534 @param [in] sock 00535 Socket handler. 00536 00537 @param [in] pvRecvBuf 00538 Pointer to a buffer that will hold the received data. The buffer shall be used 00539 in the recv callback to deliver the received data to the caller. The buffer must 00540 be resident in memory (heap or global buffer). 00541 00542 @param [in] u16BufLen 00543 The buffer size in bytes. 00544 00545 @param [in] u32Timeoutmsec 00546 Timeout for the recv function in milli-seconds. If the value is set to ZERO, the timeout 00547 will be set to infinite (the recv function waits forever). If the timeout period is 00548 elapsed with no data received, the socket will get a timeout error in the function 00549 [APPSocketEventHandler](@ref APPSocketEventHandler). 00550 00551 @return 00552 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) 00553 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) 00554 */ 00555 NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec); 00556 00557 00558 /* 00559 @fn \ 00560 NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32TimeoutSeconds); 00561 00562 @brief 00563 Recieves data from a UDP Scoket. 00564 00565 @param [in] sock 00566 Socket handler. 00567 00568 @param [in] pvRecvBuf 00569 Pointer to a buffer that will hold the received data. The buffer shall be used 00570 in the recv callback to deliver the received data to the caller. The buffer must 00571 be resident in memory (heap or global buffer). 00572 00573 @param [in] u16BufLen 00574 The buffer size in bytes. 00575 00576 @param [in] u32TimeoutSeconds 00577 Timeout for the recv function in milli-seconds. If the value is set to ZERO, the timeout 00578 will be set to infinite (the recv function waits forever). 00579 00580 @return 00581 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) 00582 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) 00583 */ 00584 NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec); 00585 00586 00587 /* 00588 @fn \ 00589 NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags); 00590 00591 @brief 00592 Sends data on a TCP Scoket. 00593 00594 @param [in] sock 00595 Socket handler. 00596 00597 @param [in] pvSendBuffer 00598 Pointer to a buffer that holding data to be transmitted. 00599 00600 @param [in] u16SendLength 00601 The buffer size in bytes. It must not exceed [SOCKET_BUFFER_MAX_LENGTH](@ref SOCKET_BUFFER_MAX_LENGTH). 00602 00603 @param [in] u16Flags 00604 It is not used in the current implementation 00605 00606 @return 00607 The function shall return ZERO for successful operation and a negative value otherwise. 00608 */ 00609 NMI_API sint16 send_nmc(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags); 00610 00611 00612 /* 00613 @fn \ 00614 NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen); 00615 00616 @brief 00617 Sends data on a UDP Scoket. 00618 00619 @param [in] sock 00620 Socket handler. 00621 00622 @param [in] pvSendBuffer 00623 Pointer to a buffer that holding data to be transmitted. 00624 00625 @param [in] u16SendLength 00626 The buffer size in bytes. It must not exceed [SOCKET_BUFFER_MAX_LENGTH](@ref SOCKET_BUFFER_MAX_LENGTH). 00627 00628 @param [in] flags 00629 It is not used in the current implementation 00630 00631 @param [in] pstrDestAddr 00632 The destination address. 00633 00634 @param [in] u8AddrLen 00635 Destination address length in bytes. 00636 00637 @return 00638 The function shall return ZERO for successful operation and a negative value otherwise. 00639 */ 00640 NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen); 00641 00642 00643 /* 00644 @fn \ 00645 NMI_API sint8 close(SOCKET sock); 00646 00647 @brief 00648 Closes a socket. 00649 00650 @param [in] sock 00651 Socket handler. 00652 00653 @return 00654 The function shall return ZERO for successful operation and a negative value otherwise. 00655 */ 00656 NMI_API sint8 close_nmc(SOCKET sock); 00657 00658 00659 /* 00660 @fn \ 00661 NMI_API sint8 gethostbyname(uint8 * pcHostName); 00662 00663 @brief 00664 Use DNS to resolve a domain name into the corresponding IP Address. 00665 00666 @param [in] pcHostName 00667 NULL terminated string containing the domain name for the remote host. 00668 Its size must not exceed [HOSTNAME_MAX_SIZE](@ref HOSTNAME_MAX_SIZE). 00669 00670 @return 00671 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR) 00672 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG) 00673 */ 00674 NMI_API sint8 gethostbyname(uint8 * pcHostName); 00675 00676 00677 /* 00678 @fn \ 00679 NMI_API uint32 nmi_inet_addr(char *pcIpAddr); 00680 00681 @brief 00682 Convert the IPv4 from the dotted decimal notation to an integer represented in Network Byte Order. 00683 00684 @param [in] pcIpAddr 00685 NULL terminated string containing the dotted decimal notation for an IP "a.b.c.d". 00686 00687 @return 00688 The integer representation of the IPv4 address in network byte order. 00689 */ 00690 NMI_API uint32 nmi_inet_addr(char *pcIpAddr); 00691 00692 00693 /* 00694 @fn \ 00695 NMI_API void APPSocketEventHandler(SOCKET sock, uint8 u8Msg, void * pvMsg); 00696 00697 @brief Socket Callback Function 00698 00699 A function used by the socket layer to convey a socket operation callback to the user. This function MUST be 00700 implemeneted by the application developer. 00701 00702 @param [in] sock 00703 Socket ID. 00704 00705 @param [in] u8Msg 00706 Socket message type [tenuSocketCallbackMsgType](@ref tenuSocketCallbackMsgType). 00707 00708 @param [in] pvMsg 00709 Msg parameters corresponding to the message type. 00710 00711 @sa tstrSocketBindMsg 00712 tstrSocketListenMsg 00713 tstrSocketAcceptMsg 00714 tstrSocketConnectMsg 00715 tstrSocketRecvMsg 00716 */ 00717 NMI_API void APPSocketEventHandler(SOCKET sock, uint8 u8Msg, void * pvMsg); 00718 00719 00720 /* 00721 @fn \ 00722 NMI_API void AppServerCb(uint8* pu8DomainName, uint32 u32ServerIP); 00723 00724 @brief 00725 DNS host name resolution callback. 00726 00727 @param [in] pu8DomainName 00728 NULL terminated string containing the Domain name of a host (eg. "www.Google.com"). 00729 00730 @param [in] u32ServerIP 00731 IP Address corresponding to the domain name. It is formatted in network byte order. 00732 */ 00733 NMI_API void AppServerCb(uint8* pu8DomainName, uint32 u32ServerIP); 00734 00735 //Ryan 00736 typedef void (*tf_APPSocketEventHandler)(SOCKET sock, uint8 u8Msg, void * pvMsg); 00737 00738 NMI_API void m2m_set_app(tf_APPSocketEventHandler str); 00739 00740 #define M2M_HIF_HDR_OFFSET (sizeof(tstrHifHdr)) 00741 00742 /* 00743 * @struct tstrHifHdr 00744 * @brief Structure to hold HIF header 00745 * @author Mahfouz Sheref 00746 * @version 1.0 00747 */ 00748 typedef struct 00749 { 00750 uint8 u8Gid; /*< Group ID */ 00751 uint8 u8Opcode; /*< OP code */ 00752 uint16 u16Length; /*< Payload length */ 00753 }tstrHifHdr; 00754 00755 #ifdef __cplusplus 00756 } 00757 #endif /* __cplusplus */ 00758 00759 #endif /* __SOCKET_H__ */
Generated on Mon Jul 25 2022 10:33:26 by
1.7.2