WIFI_API_20150524e

Committer:
Marcomissyou
Date:
Tue Jun 09 06:04:13 2015 +0000
Revision:
0:a2de37bf5f3d
update to WIFI_API_20150524e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcomissyou 0:a2de37bf5f3d 1 /*
Marcomissyou 0:a2de37bf5f3d 2 @file
Marcomissyou 0:a2de37bf5f3d 3 socket.h
Marcomissyou 0:a2de37bf5f3d 4
Marcomissyou 0:a2de37bf5f3d 5 @brief Socket Interface APIs
Marcomissyou 0:a2de37bf5f3d 6
Marcomissyou 0:a2de37bf5f3d 7 The file defines APIs and types of socket layer for the NMC1500 IoT solution. The APIs are very similar
Marcomissyou 0:a2de37bf5f3d 8 to the standard POSIX sockets APIs. The socket layer operates in asynchronus mode which means socket
Marcomissyou 0:a2de37bf5f3d 9 functions are non-blocking functions, requiring the result of a socket operation (eg. bind) is delivered later
Marcomissyou 0:a2de37bf5f3d 10 in a callback function [APPSocketEventHandler](@ref APPSocketEventHandler).
Marcomissyou 0:a2de37bf5f3d 11 */
Marcomissyou 0:a2de37bf5f3d 12 #ifndef __SOCKET_NMC_H__
Marcomissyou 0:a2de37bf5f3d 13 #define __SOCKET_NMC_H__
Marcomissyou 0:a2de37bf5f3d 14
Marcomissyou 0:a2de37bf5f3d 15 #include "nmi_wlan_if.h"
Marcomissyou 0:a2de37bf5f3d 16 #include "nmi_wlan.h"
Marcomissyou 0:a2de37bf5f3d 17
Marcomissyou 0:a2de37bf5f3d 18 #ifdef __cplusplus
Marcomissyou 0:a2de37bf5f3d 19 extern "C" {
Marcomissyou 0:a2de37bf5f3d 20 #endif
Marcomissyou 0:a2de37bf5f3d 21
Marcomissyou 0:a2de37bf5f3d 22 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Marcomissyou 0:a2de37bf5f3d 23 INCLUDES
Marcomissyou 0:a2de37bf5f3d 24 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
Marcomissyou 0:a2de37bf5f3d 25
Marcomissyou 0:a2de37bf5f3d 26 //#include "common\include\nm_common.h"
Marcomissyou 0:a2de37bf5f3d 27
Marcomissyou 0:a2de37bf5f3d 28 #define NMI_API
Marcomissyou 0:a2de37bf5f3d 29
Marcomissyou 0:a2de37bf5f3d 30 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Marcomissyou 0:a2de37bf5f3d 31 MACROS
Marcomissyou 0:a2de37bf5f3d 32 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
Marcomissyou 0:a2de37bf5f3d 33
Marcomissyou 0:a2de37bf5f3d 34
Marcomissyou 0:a2de37bf5f3d 35 #define HOSTNAME_MAX_SIZE 64
Marcomissyou 0:a2de37bf5f3d 36 /*< Maximum allowed size for a host domain name.
Marcomissyou 0:a2de37bf5f3d 37 */
Marcomissyou 0:a2de37bf5f3d 38
Marcomissyou 0:a2de37bf5f3d 39
Marcomissyou 0:a2de37bf5f3d 40
Marcomissyou 0:a2de37bf5f3d 41 #define SOCKET_BUFFER_MAX_LENGTH 1400
Marcomissyou 0:a2de37bf5f3d 42 /*< Maximum allowed size for a socket Data buffer.
Marcomissyou 0:a2de37bf5f3d 43 */
Marcomissyou 0:a2de37bf5f3d 44
Marcomissyou 0:a2de37bf5f3d 45
Marcomissyou 0:a2de37bf5f3d 46 #define AF_INET 2
Marcomissyou 0:a2de37bf5f3d 47 /*< Supported socket family.
Marcomissyou 0:a2de37bf5f3d 48 */
Marcomissyou 0:a2de37bf5f3d 49
Marcomissyou 0:a2de37bf5f3d 50
Marcomissyou 0:a2de37bf5f3d 51 #define SOCK_STREAM 1
Marcomissyou 0:a2de37bf5f3d 52 /*< This is the identifier of TCP socket type.
Marcomissyou 0:a2de37bf5f3d 53 */
Marcomissyou 0:a2de37bf5f3d 54
Marcomissyou 0:a2de37bf5f3d 55
Marcomissyou 0:a2de37bf5f3d 56 #define SOCK_DGRAM 2
Marcomissyou 0:a2de37bf5f3d 57 /*< This is the identifier of UDP socket type.
Marcomissyou 0:a2de37bf5f3d 58 */
Marcomissyou 0:a2de37bf5f3d 59
Marcomissyou 0:a2de37bf5f3d 60
Marcomissyou 0:a2de37bf5f3d 61 #define SOCKET_FLAGS_SSL 0x01
Marcomissyou 0:a2de37bf5f3d 62 /*< This flag shall be passed to the
Marcomissyou 0:a2de37bf5f3d 63 socket API for SSL session.
Marcomissyou 0:a2de37bf5f3d 64 */
Marcomissyou 0:a2de37bf5f3d 65
Marcomissyou 0:a2de37bf5f3d 66
Marcomissyou 0:a2de37bf5f3d 67 #define TCP_SOCK_MAX 2//(7)
Marcomissyou 0:a2de37bf5f3d 68 /*< Maximum number of simultaneous TCP sockets.
Marcomissyou 0:a2de37bf5f3d 69 */
Marcomissyou 0:a2de37bf5f3d 70
Marcomissyou 0:a2de37bf5f3d 71
Marcomissyou 0:a2de37bf5f3d 72 #define UDP_SOCK_MAX 2//4
Marcomissyou 0:a2de37bf5f3d 73 /*< Maximum number of simultaneous UDP sockets.
Marcomissyou 0:a2de37bf5f3d 74 */
Marcomissyou 0:a2de37bf5f3d 75
Marcomissyou 0:a2de37bf5f3d 76
Marcomissyou 0:a2de37bf5f3d 77 #define MAX_SOCKET (TCP_SOCK_MAX + UDP_SOCK_MAX)
Marcomissyou 0:a2de37bf5f3d 78 /*< Maximum number of Sockets.
Marcomissyou 0:a2de37bf5f3d 79 */
Marcomissyou 0:a2de37bf5f3d 80
Marcomissyou 0:a2de37bf5f3d 81
Marcomissyou 0:a2de37bf5f3d 82 /**************
Marcomissyou 0:a2de37bf5f3d 83 Socket Errors
Marcomissyou 0:a2de37bf5f3d 84 **************/
Marcomissyou 0:a2de37bf5f3d 85
Marcomissyou 0:a2de37bf5f3d 86 #define SOCK_ERR_NO_ERROR 0
Marcomissyou 0:a2de37bf5f3d 87 /*< Every thing is OK.
Marcomissyou 0:a2de37bf5f3d 88 */
Marcomissyou 0:a2de37bf5f3d 89
Marcomissyou 0:a2de37bf5f3d 90
Marcomissyou 0:a2de37bf5f3d 91 #define SOCK_ERR_INVALID_ADDRESS -1
Marcomissyou 0:a2de37bf5f3d 92 /*< Socket address is invalid. The socket operation cannot
Marcomissyou 0:a2de37bf5f3d 93 be completed without address is specified. For example,
Marcomissyou 0:a2de37bf5f3d 94 Bind is called without specifying a port number.
Marcomissyou 0:a2de37bf5f3d 95 */
Marcomissyou 0:a2de37bf5f3d 96
Marcomissyou 0:a2de37bf5f3d 97
Marcomissyou 0:a2de37bf5f3d 98 #define SOCK_ERR_ADDR_ALREADY_IN_USE -2
Marcomissyou 0:a2de37bf5f3d 99 /*< Cannot bind on the given address. It is already bound
Marcomissyou 0:a2de37bf5f3d 100 by another opened socket.
Marcomissyou 0:a2de37bf5f3d 101 */
Marcomissyou 0:a2de37bf5f3d 102
Marcomissyou 0:a2de37bf5f3d 103
Marcomissyou 0:a2de37bf5f3d 104 #define SOCK_ERR_MAX_TCP_SOCK -3
Marcomissyou 0:a2de37bf5f3d 105 /*< The maximum number of TCP sockets is reached. Socket
Marcomissyou 0:a2de37bf5f3d 106 creation failed.
Marcomissyou 0:a2de37bf5f3d 107 */
Marcomissyou 0:a2de37bf5f3d 108
Marcomissyou 0:a2de37bf5f3d 109
Marcomissyou 0:a2de37bf5f3d 110 #define SOCK_ERR_MAX_UDP_SOCK -4
Marcomissyou 0:a2de37bf5f3d 111 /*< The maximum number of UDP sockets is reached. Socket
Marcomissyou 0:a2de37bf5f3d 112 creation failed.
Marcomissyou 0:a2de37bf5f3d 113 */
Marcomissyou 0:a2de37bf5f3d 114
Marcomissyou 0:a2de37bf5f3d 115
Marcomissyou 0:a2de37bf5f3d 116 #define SOCK_ERR_INVALID_ARG -6
Marcomissyou 0:a2de37bf5f3d 117 /*< An invalid arguement is passed to a function.
Marcomissyou 0:a2de37bf5f3d 118 */
Marcomissyou 0:a2de37bf5f3d 119
Marcomissyou 0:a2de37bf5f3d 120
Marcomissyou 0:a2de37bf5f3d 121 #define SOCK_ERR_MAX_LISTEN_SOCK -7
Marcomissyou 0:a2de37bf5f3d 122 /*< The maximum number of TCP passive listening sockets is
Marcomissyou 0:a2de37bf5f3d 123 reached. Listen function fails.
Marcomissyou 0:a2de37bf5f3d 124 */
Marcomissyou 0:a2de37bf5f3d 125
Marcomissyou 0:a2de37bf5f3d 126
Marcomissyou 0:a2de37bf5f3d 127 #define SOCK_ERR_INVALID -9
Marcomissyou 0:a2de37bf5f3d 128 /*< The requested socket operation is not valid in the
Marcomissyou 0:a2de37bf5f3d 129 current socket state. For Example, accept is called on a
Marcomissyou 0:a2de37bf5f3d 130 TCP socket before bind or listen.
Marcomissyou 0:a2de37bf5f3d 131 */
Marcomissyou 0:a2de37bf5f3d 132
Marcomissyou 0:a2de37bf5f3d 133
Marcomissyou 0:a2de37bf5f3d 134 #define SOCK_ERR_ADDR_IS_REQUIRED -11
Marcomissyou 0:a2de37bf5f3d 135 /*< The socket address is required for the operation to
Marcomissyou 0:a2de37bf5f3d 136 be completed. It is generated from sendto when there is
Marcomissyou 0:a2de37bf5f3d 137 no valid address found to send the data to.
Marcomissyou 0:a2de37bf5f3d 138 */
Marcomissyou 0:a2de37bf5f3d 139
Marcomissyou 0:a2de37bf5f3d 140
Marcomissyou 0:a2de37bf5f3d 141 #define SOCK_ERR_CONN_ABORTED -12
Marcomissyou 0:a2de37bf5f3d 142 /*< The socket is closed by the peer. The local socket is
Marcomissyou 0:a2de37bf5f3d 143 closed also.
Marcomissyou 0:a2de37bf5f3d 144 */
Marcomissyou 0:a2de37bf5f3d 145
Marcomissyou 0:a2de37bf5f3d 146
Marcomissyou 0:a2de37bf5f3d 147 #define SOCK_ERR_TIMEOUT -13
Marcomissyou 0:a2de37bf5f3d 148 /*< The socket pending operation has been timedout.
Marcomissyou 0:a2de37bf5f3d 149 */
Marcomissyou 0:a2de37bf5f3d 150
Marcomissyou 0:a2de37bf5f3d 151
Marcomissyou 0:a2de37bf5f3d 152 #define SOCK_ERR_BUFFER_FULL -14
Marcomissyou 0:a2de37bf5f3d 153 /*< The send operation could not be performed before the
Marcomissyou 0:a2de37bf5f3d 154 transmission buffer corresponding to this socket is busy.
Marcomissyou 0:a2de37bf5f3d 155 */
Marcomissyou 0:a2de37bf5f3d 156
Marcomissyou 0:a2de37bf5f3d 157 #ifndef _NM_BSP_BIG_END
Marcomissyou 0:a2de37bf5f3d 158
Marcomissyou 0:a2de37bf5f3d 159 #define _htonl(m) (m)
Marcomissyou 0:a2de37bf5f3d 160 #define _htons(A) (A)
Marcomissyou 0:a2de37bf5f3d 161
Marcomissyou 0:a2de37bf5f3d 162 #else
Marcomissyou 0:a2de37bf5f3d 163
Marcomissyou 0:a2de37bf5f3d 164 #define _htonl(m) \
Marcomissyou 0:a2de37bf5f3d 165 (uint32)(((uint32)(m << 24)) | ((uint32)((m & 0x0000FF00) << 8)) | ((uint32)((m & 0x00FF0000) >> 8)) | ((uint32)(m >> 24)))
Marcomissyou 0:a2de37bf5f3d 166 /*< Convert a 4-byte integer from the host representation to the Network byte order representation.
Marcomissyou 0:a2de37bf5f3d 167 */
Marcomissyou 0:a2de37bf5f3d 168
Marcomissyou 0:a2de37bf5f3d 169
Marcomissyou 0:a2de37bf5f3d 170 #define _htons(A) (uint16)((((uint16) (A)) << 8) | (((uint16) (A)) >> 8))
Marcomissyou 0:a2de37bf5f3d 171 /*< Convert a 2-byte integer (short) from the host representation to the Network byte order representation.
Marcomissyou 0:a2de37bf5f3d 172 */
Marcomissyou 0:a2de37bf5f3d 173
Marcomissyou 0:a2de37bf5f3d 174
Marcomissyou 0:a2de37bf5f3d 175 #endif
Marcomissyou 0:a2de37bf5f3d 176
Marcomissyou 0:a2de37bf5f3d 177
Marcomissyou 0:a2de37bf5f3d 178 #define _ntohl _htonl
Marcomissyou 0:a2de37bf5f3d 179 /*< Convert a 4-byte integer from the Network byte order representation to the host representation .
Marcomissyou 0:a2de37bf5f3d 180 */
Marcomissyou 0:a2de37bf5f3d 181
Marcomissyou 0:a2de37bf5f3d 182
Marcomissyou 0:a2de37bf5f3d 183 #define _ntohs _htons
Marcomissyou 0:a2de37bf5f3d 184 /*< Convert a 2-byte integer from the Network byte order representation to the host representation .
Marcomissyou 0:a2de37bf5f3d 185 */
Marcomissyou 0:a2de37bf5f3d 186
Marcomissyou 0:a2de37bf5f3d 187
Marcomissyou 0:a2de37bf5f3d 188 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Marcomissyou 0:a2de37bf5f3d 189 DATA TYPES
Marcomissyou 0:a2de37bf5f3d 190 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
Marcomissyou 0:a2de37bf5f3d 191
Marcomissyou 0:a2de37bf5f3d 192 /*
Marcomissyou 0:a2de37bf5f3d 193 @typedef \
Marcomissyou 0:a2de37bf5f3d 194 SOCKET
Marcomissyou 0:a2de37bf5f3d 195
Marcomissyou 0:a2de37bf5f3d 196 @brief
Marcomissyou 0:a2de37bf5f3d 197 Data type definition for socket handlers.
Marcomissyou 0:a2de37bf5f3d 198 */
Marcomissyou 0:a2de37bf5f3d 199 typedef sint8 SOCKET;
Marcomissyou 0:a2de37bf5f3d 200
Marcomissyou 0:a2de37bf5f3d 201
Marcomissyou 0:a2de37bf5f3d 202 /*
Marcomissyou 0:a2de37bf5f3d 203 @struct \
Marcomissyou 0:a2de37bf5f3d 204 in_addr
Marcomissyou 0:a2de37bf5f3d 205
Marcomissyou 0:a2de37bf5f3d 206 @brief
Marcomissyou 0:a2de37bf5f3d 207 IPv4 address representation.
Marcomissyou 0:a2de37bf5f3d 208 */
Marcomissyou 0:a2de37bf5f3d 209 typedef struct{
Marcomissyou 0:a2de37bf5f3d 210 uint32 s_addr;
Marcomissyou 0:a2de37bf5f3d 211 /*< Network Byte Order representation of the IPv4 address.
Marcomissyou 0:a2de37bf5f3d 212 */
Marcomissyou 0:a2de37bf5f3d 213 }in_addr_nmc;//Tsungta
Marcomissyou 0:a2de37bf5f3d 214
Marcomissyou 0:a2de37bf5f3d 215
Marcomissyou 0:a2de37bf5f3d 216 /*
Marcomissyou 0:a2de37bf5f3d 217 @struct \
Marcomissyou 0:a2de37bf5f3d 218 sockaddr
Marcomissyou 0:a2de37bf5f3d 219
Marcomissyou 0:a2de37bf5f3d 220 @brief
Marcomissyou 0:a2de37bf5f3d 221 Generic socket address structure.
Marcomissyou 0:a2de37bf5f3d 222 */
Marcomissyou 0:a2de37bf5f3d 223 struct sockaddr{
Marcomissyou 0:a2de37bf5f3d 224 uint16 sa_family;
Marcomissyou 0:a2de37bf5f3d 225 uint8 sa_data[14];
Marcomissyou 0:a2de37bf5f3d 226 };
Marcomissyou 0:a2de37bf5f3d 227
Marcomissyou 0:a2de37bf5f3d 228
Marcomissyou 0:a2de37bf5f3d 229 /*
Marcomissyou 0:a2de37bf5f3d 230 @struct \
Marcomissyou 0:a2de37bf5f3d 231 sockaddr_in
Marcomissyou 0:a2de37bf5f3d 232
Marcomissyou 0:a2de37bf5f3d 233 @brief
Marcomissyou 0:a2de37bf5f3d 234 Socket address structure for IPV4 addresses.
Marcomissyou 0:a2de37bf5f3d 235 */
Marcomissyou 0:a2de37bf5f3d 236 struct sockaddr_in_nmc{//Tsungta
Marcomissyou 0:a2de37bf5f3d 237 uint16 sin_family;
Marcomissyou 0:a2de37bf5f3d 238 /*< The only supported value for this is AF_INET.
Marcomissyou 0:a2de37bf5f3d 239 */
Marcomissyou 0:a2de37bf5f3d 240 uint16 sin_port;
Marcomissyou 0:a2de37bf5f3d 241 /*< Port number of the socket address. It must be set in the
Marcomissyou 0:a2de37bf5f3d 242 Network Byte Order format (e.g. _htons(80)).
Marcomissyou 0:a2de37bf5f3d 243 */
Marcomissyou 0:a2de37bf5f3d 244 in_addr_nmc sin_addr; //Tsungta
Marcomissyou 0:a2de37bf5f3d 245 /*< IP Address [in_addr].
Marcomissyou 0:a2de37bf5f3d 246 */
Marcomissyou 0:a2de37bf5f3d 247 uint8 sin_zero[8];
Marcomissyou 0:a2de37bf5f3d 248 /*< Dummy bytes.
Marcomissyou 0:a2de37bf5f3d 249 */
Marcomissyou 0:a2de37bf5f3d 250 };
Marcomissyou 0:a2de37bf5f3d 251
Marcomissyou 0:a2de37bf5f3d 252
Marcomissyou 0:a2de37bf5f3d 253 /*******************************************
Marcomissyou 0:a2de37bf5f3d 254 Specific Definitions for Asynchronous implementation
Marcomissyou 0:a2de37bf5f3d 255 *******************************************/
Marcomissyou 0:a2de37bf5f3d 256
Marcomissyou 0:a2de37bf5f3d 257 /*
Marcomissyou 0:a2de37bf5f3d 258 @enum \
Marcomissyou 0:a2de37bf5f3d 259 tenuSocketCallbackMsgType
Marcomissyou 0:a2de37bf5f3d 260
Marcomissyou 0:a2de37bf5f3d 261 @brief
Marcomissyou 0:a2de37bf5f3d 262 Socket message types for socket callback notifications.
Marcomissyou 0:a2de37bf5f3d 263 */
Marcomissyou 0:a2de37bf5f3d 264 typedef enum{
Marcomissyou 0:a2de37bf5f3d 265 SOCKET_MSG_BIND = 1,
Marcomissyou 0:a2de37bf5f3d 266 SOCKET_MSG_LISTEN,
Marcomissyou 0:a2de37bf5f3d 267 SOCKET_MSG_DNS_RESOLVE,
Marcomissyou 0:a2de37bf5f3d 268 SOCKET_MSG_ACCEPT,
Marcomissyou 0:a2de37bf5f3d 269 SOCKET_MSG_CONNECT,
Marcomissyou 0:a2de37bf5f3d 270 SOCKET_MSG_RECV,
Marcomissyou 0:a2de37bf5f3d 271 SOCKET_MSG_SEND,
Marcomissyou 0:a2de37bf5f3d 272 SOCKET_MSG_SENDTO,
Marcomissyou 0:a2de37bf5f3d 273 SOCKET_MSG_RECVFROM,
Marcomissyou 0:a2de37bf5f3d 274 SOCKET_MSG_DHCP_OFFER,
Marcomissyou 0:a2de37bf5f3d 275 SOCKET_MSG_TCPERROR
Marcomissyou 0:a2de37bf5f3d 276 }tenuSocketCallbackMsgType;
Marcomissyou 0:a2de37bf5f3d 277
Marcomissyou 0:a2de37bf5f3d 278 /*
Marcomissyou 0:a2de37bf5f3d 279 @struct \
Marcomissyou 0:a2de37bf5f3d 280 tstrSocketBindMsg
Marcomissyou 0:a2de37bf5f3d 281
Marcomissyou 0:a2de37bf5f3d 282 @brief Socket bind status.
Marcomissyou 0:a2de37bf5f3d 283
Marcomissyou 0:a2de37bf5f3d 284 It is passed to the APPSocketEventHandler with SOCKET_MSG_BIND message type
Marcomissyou 0:a2de37bf5f3d 285 in a response to a user call to bind.
Marcomissyou 0:a2de37bf5f3d 286 */
Marcomissyou 0:a2de37bf5f3d 287 typedef struct{
Marcomissyou 0:a2de37bf5f3d 288 sint8 status;
Marcomissyou 0:a2de37bf5f3d 289 /*< The result of the bind operation.
Marcomissyou 0:a2de37bf5f3d 290 */
Marcomissyou 0:a2de37bf5f3d 291 }tstrSocketBindMsg;
Marcomissyou 0:a2de37bf5f3d 292
Marcomissyou 0:a2de37bf5f3d 293
Marcomissyou 0:a2de37bf5f3d 294 /*
Marcomissyou 0:a2de37bf5f3d 295 @struct \
Marcomissyou 0:a2de37bf5f3d 296 tstrSocketListenMsg
Marcomissyou 0:a2de37bf5f3d 297
Marcomissyou 0:a2de37bf5f3d 298 @brief Socket listen status.
Marcomissyou 0:a2de37bf5f3d 299
Marcomissyou 0:a2de37bf5f3d 300 It is passed to the APPSocketEventHandler with SOCKET_MSG_LISTEN message type
Marcomissyou 0:a2de37bf5f3d 301 in a response to a user call to listen.
Marcomissyou 0:a2de37bf5f3d 302 */
Marcomissyou 0:a2de37bf5f3d 303 typedef struct{
Marcomissyou 0:a2de37bf5f3d 304 sint8 status;
Marcomissyou 0:a2de37bf5f3d 305 /*< Result of the listen operation.
Marcomissyou 0:a2de37bf5f3d 306 */
Marcomissyou 0:a2de37bf5f3d 307 }tstrSocketListenMsg;
Marcomissyou 0:a2de37bf5f3d 308
Marcomissyou 0:a2de37bf5f3d 309
Marcomissyou 0:a2de37bf5f3d 310
Marcomissyou 0:a2de37bf5f3d 311 /*
Marcomissyou 0:a2de37bf5f3d 312 @struct \
Marcomissyou 0:a2de37bf5f3d 313 tstrSocketAcceptMsg
Marcomissyou 0:a2de37bf5f3d 314
Marcomissyou 0:a2de37bf5f3d 315 @brief Socket accept status.
Marcomissyou 0:a2de37bf5f3d 316
Marcomissyou 0:a2de37bf5f3d 317 It is passed to the APPSocketEventHandler with SOCKET_MSG_ACCEPT message type
Marcomissyou 0:a2de37bf5f3d 318 in a response to a user call to accept.
Marcomissyou 0:a2de37bf5f3d 319 */
Marcomissyou 0:a2de37bf5f3d 320 typedef struct{
Marcomissyou 0:a2de37bf5f3d 321 SOCKET sock;
Marcomissyou 0:a2de37bf5f3d 322 /*< Socket ID for the accepted connection with a remote peer. If it is a negative value, it refers to
Marcomissyou 0:a2de37bf5f3d 323 an accept error (accept failed).
Marcomissyou 0:a2de37bf5f3d 324 */
Marcomissyou 0:a2de37bf5f3d 325 struct sockaddr_in_nmc strAddr;//Tsungta
Marcomissyou 0:a2de37bf5f3d 326 /*< Socket address structure for the remote peer.
Marcomissyou 0:a2de37bf5f3d 327 */
Marcomissyou 0:a2de37bf5f3d 328 }tstrSocketAcceptMsg;
Marcomissyou 0:a2de37bf5f3d 329
Marcomissyou 0:a2de37bf5f3d 330
Marcomissyou 0:a2de37bf5f3d 331 /*
Marcomissyou 0:a2de37bf5f3d 332 @struct \
Marcomissyou 0:a2de37bf5f3d 333 tstrSocketConnectMsg
Marcomissyou 0:a2de37bf5f3d 334
Marcomissyou 0:a2de37bf5f3d 335 @brief Socket connect status.
Marcomissyou 0:a2de37bf5f3d 336
Marcomissyou 0:a2de37bf5f3d 337 It is passed to the APPSocketEventHandler with SOCKET_MSG_CONNECT message type
Marcomissyou 0:a2de37bf5f3d 338 in a response to a user call to connect.
Marcomissyou 0:a2de37bf5f3d 339 */
Marcomissyou 0:a2de37bf5f3d 340 typedef struct{
Marcomissyou 0:a2de37bf5f3d 341 SOCKET sock;
Marcomissyou 0:a2de37bf5f3d 342 /*< Socket ID referring to the socket passed to the connect function call.
Marcomissyou 0:a2de37bf5f3d 343 */
Marcomissyou 0:a2de37bf5f3d 344 sint8 s8Error;
Marcomissyou 0:a2de37bf5f3d 345 /*< Connect error code. It shall be ZERO for successful connect and a negative number otherwise.
Marcomissyou 0:a2de37bf5f3d 346 */
Marcomissyou 0:a2de37bf5f3d 347 }tstrSocketConnectMsg;
Marcomissyou 0:a2de37bf5f3d 348
Marcomissyou 0:a2de37bf5f3d 349
Marcomissyou 0:a2de37bf5f3d 350 /*
Marcomissyou 0:a2de37bf5f3d 351 @struct \
Marcomissyou 0:a2de37bf5f3d 352 tstrSocketTCPErrorMsg
Marcomissyou 0:a2de37bf5f3d 353
Marcomissyou 0:a2de37bf5f3d 354 @brief Socket connect status.
Marcomissyou 0:a2de37bf5f3d 355
Marcomissyou 0:a2de37bf5f3d 356 It is passed to the APPSocketEventHandler with SOCKET_MSG_TCPERROR message type
Marcomissyou 0:a2de37bf5f3d 357 in a response for TCP socket error.
Marcomissyou 0:a2de37bf5f3d 358 */
Marcomissyou 0:a2de37bf5f3d 359 typedef struct{
Marcomissyou 0:a2de37bf5f3d 360 SOCKET sock;
Marcomissyou 0:a2de37bf5f3d 361 /*< Socket ID referring to the socket passed to the TCP socket control function call.
Marcomissyou 0:a2de37bf5f3d 362 */
Marcomissyou 0:a2de37bf5f3d 363 sint8 s8Error;
Marcomissyou 0:a2de37bf5f3d 364 /*< Connect error code. TCP socket handling errors.
Marcomissyou 0:a2de37bf5f3d 365 */
Marcomissyou 0:a2de37bf5f3d 366 }tstrSocketTCPErrorMsg;
Marcomissyou 0:a2de37bf5f3d 367
Marcomissyou 0:a2de37bf5f3d 368 /*
Marcomissyou 0:a2de37bf5f3d 369 @struct \
Marcomissyou 0:a2de37bf5f3d 370
Marcomissyou 0:a2de37bf5f3d 371 tstrSocketRecvMsg
Marcomissyou 0:a2de37bf5f3d 372
Marcomissyou 0:a2de37bf5f3d 373 @brief Socket recv status.
Marcomissyou 0:a2de37bf5f3d 374
Marcomissyou 0:a2de37bf5f3d 375 It is passed to the APPSocketEventHandler with SOCKET_MSG_RECV or SOCKET_MSG_RECVFROM message type
Marcomissyou 0:a2de37bf5f3d 376 in a response to a user call to the recv or recvfrom.
Marcomissyou 0:a2de37bf5f3d 377 If the received data from the remote peer is larger than the USER Buffer size (given at recv call), the data is
Marcomissyou 0:a2de37bf5f3d 378 delivered to the user in a number of consecutive chunks according to the USER Buffer size.
Marcomissyou 0:a2de37bf5f3d 379 */
Marcomissyou 0:a2de37bf5f3d 380 typedef struct{
Marcomissyou 0:a2de37bf5f3d 381 uint8 *pu8Buffer;
Marcomissyou 0:a2de37bf5f3d 382 /*< Pointer to the USER buffer (passed to recv or recvfrom) containing a received data chunk.
Marcomissyou 0:a2de37bf5f3d 383 */
Marcomissyou 0:a2de37bf5f3d 384 sint16 s16BufferSize;
Marcomissyou 0:a2de37bf5f3d 385 /*< The recevied data chunk size. It will be negative value if there is a recv error.
Marcomissyou 0:a2de37bf5f3d 386 */
Marcomissyou 0:a2de37bf5f3d 387 uint16 u16RemainingSize;
Marcomissyou 0:a2de37bf5f3d 388 /*< The number of bytes remaining in the current recv operation.
Marcomissyou 0:a2de37bf5f3d 389 */
Marcomissyou 0:a2de37bf5f3d 390 struct sockaddr_in_nmc strRemoteAddr;//Tsungta
Marcomissyou 0:a2de37bf5f3d 391 /*< Socket address structure for the remote peer.
Marcomissyou 0:a2de37bf5f3d 392 */
Marcomissyou 0:a2de37bf5f3d 393 }tstrSocketRecvMsg;
Marcomissyou 0:a2de37bf5f3d 394
Marcomissyou 0:a2de37bf5f3d 395
Marcomissyou 0:a2de37bf5f3d 396 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Marcomissyou 0:a2de37bf5f3d 397 FUNCTION PROTOTYPES
Marcomissyou 0:a2de37bf5f3d 398 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
Marcomissyou 0:a2de37bf5f3d 399
Marcomissyou 0:a2de37bf5f3d 400 /*
Marcomissyou 0:a2de37bf5f3d 401 @fn \
Marcomissyou 0:a2de37bf5f3d 402 NMI_API void socketInit(void);
Marcomissyou 0:a2de37bf5f3d 403
Marcomissyou 0:a2de37bf5f3d 404 @brief Socket Layer Initialization
Marcomissyou 0:a2de37bf5f3d 405
Marcomissyou 0:a2de37bf5f3d 406 The function performs the necessary initializations for the socket library.
Marcomissyou 0:a2de37bf5f3d 407 It must be invoked before any socket operation is performed.
Marcomissyou 0:a2de37bf5f3d 408 */
Marcomissyou 0:a2de37bf5f3d 409 NMI_API void socketInit(void);
Marcomissyou 0:a2de37bf5f3d 410
Marcomissyou 0:a2de37bf5f3d 411
Marcomissyou 0:a2de37bf5f3d 412 /*
Marcomissyou 0:a2de37bf5f3d 413 @fn \
Marcomissyou 0:a2de37bf5f3d 414 NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags);
Marcomissyou 0:a2de37bf5f3d 415
Marcomissyou 0:a2de37bf5f3d 416 @brief
Marcomissyou 0:a2de37bf5f3d 417 Creates a socket with a given type.
Marcomissyou 0:a2de37bf5f3d 418
Marcomissyou 0:a2de37bf5f3d 419 @param [in] u16Domain
Marcomissyou 0:a2de37bf5f3d 420 Socket family. The only allowed value is AF_INET for TCP/UDP sockets.
Marcomissyou 0:a2de37bf5f3d 421
Marcomissyou 0:a2de37bf5f3d 422 @param [in] u8Type
Marcomissyou 0:a2de37bf5f3d 423 Socket type. Allowed values are:
Marcomissyou 0:a2de37bf5f3d 424 - [SOCK_STREAM](@ref SOCK_STREAM)
Marcomissyou 0:a2de37bf5f3d 425 - [SOCK_DGRAM](@ref SOCK_DGRAM)
Marcomissyou 0:a2de37bf5f3d 426
Marcomissyou 0:a2de37bf5f3d 427 @param [in] u8Flags
Marcomissyou 0:a2de37bf5f3d 428 Used to specify the socket creation flags. It shall be set to zero for normal TCP/UDP sockets.
Marcomissyou 0:a2de37bf5f3d 429 If could be SOCKET_FLAGS_SSL if the socket is used for SSL session. The use of the flag
Marcomissyou 0:a2de37bf5f3d 430 [SOCKET_FLAGS_SSL](@ref SOCKET_FLAGS_SSL) has no meaning in case of UDP sockets.
Marcomissyou 0:a2de37bf5f3d 431
Marcomissyou 0:a2de37bf5f3d 432 @return
Marcomissyou 0:a2de37bf5f3d 433 The function shall return a negative value for socket creation failed and a nonnegative value
Marcomissyou 0:a2de37bf5f3d 434 representing the socket ID otherwise.
Marcomissyou 0:a2de37bf5f3d 435 */
Marcomissyou 0:a2de37bf5f3d 436 NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags);
Marcomissyou 0:a2de37bf5f3d 437
Marcomissyou 0:a2de37bf5f3d 438
Marcomissyou 0:a2de37bf5f3d 439 /*
Marcomissyou 0:a2de37bf5f3d 440 @fn \
Marcomissyou 0:a2de37bf5f3d 441 NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 442
Marcomissyou 0:a2de37bf5f3d 443 @brief
Marcomissyou 0:a2de37bf5f3d 444 Binds a socket on a local port.
Marcomissyou 0:a2de37bf5f3d 445
Marcomissyou 0:a2de37bf5f3d 446 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 447 Socket ID.
Marcomissyou 0:a2de37bf5f3d 448
Marcomissyou 0:a2de37bf5f3d 449 @param [in] pstrAddr
Marcomissyou 0:a2de37bf5f3d 450 Socket address for the address to be bound.
Marcomissyou 0:a2de37bf5f3d 451
Marcomissyou 0:a2de37bf5f3d 452 @param [in] u8AddrLen
Marcomissyou 0:a2de37bf5f3d 453 Size of the given address in bytes.
Marcomissyou 0:a2de37bf5f3d 454
Marcomissyou 0:a2de37bf5f3d 455 @return
Marcomissyou 0:a2de37bf5f3d 456 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 457 */
Marcomissyou 0:a2de37bf5f3d 458 NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 459
Marcomissyou 0:a2de37bf5f3d 460
Marcomissyou 0:a2de37bf5f3d 461 /*
Marcomissyou 0:a2de37bf5f3d 462 @fn \
Marcomissyou 0:a2de37bf5f3d 463 NMI_API sint8 listen(SOCKET sock, uint8 backlog);
Marcomissyou 0:a2de37bf5f3d 464
Marcomissyou 0:a2de37bf5f3d 465 @brief
Marcomissyou 0:a2de37bf5f3d 466 Start listening on a passive socket for incoming connections. The socket must be bound on a local port
Marcomissyou 0:a2de37bf5f3d 467 or the listen fails. The listen function must be called at receiving [SOCKET_MSG_BIND](@ref SOCKET_MSG_BIND)
Marcomissyou 0:a2de37bf5f3d 468 in the socket callback.
Marcomissyou 0:a2de37bf5f3d 469
Marcomissyou 0:a2de37bf5f3d 470 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 471 Socket ID.
Marcomissyou 0:a2de37bf5f3d 472
Marcomissyou 0:a2de37bf5f3d 473 @param [in] backlog
Marcomissyou 0:a2de37bf5f3d 474 Number of maximum allowed connections that will be accepted on the given socket.
Marcomissyou 0:a2de37bf5f3d 475 It is not used by the current implementation.
Marcomissyou 0:a2de37bf5f3d 476
Marcomissyou 0:a2de37bf5f3d 477 @return
Marcomissyou 0:a2de37bf5f3d 478 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 479 */
Marcomissyou 0:a2de37bf5f3d 480 NMI_API sint8 listen(SOCKET sock, uint8 backlog);
Marcomissyou 0:a2de37bf5f3d 481
Marcomissyou 0:a2de37bf5f3d 482
Marcomissyou 0:a2de37bf5f3d 483 /*
Marcomissyou 0:a2de37bf5f3d 484 @fn \
Marcomissyou 0:a2de37bf5f3d 485 NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen);
Marcomissyou 0:a2de37bf5f3d 486
Marcomissyou 0:a2de37bf5f3d 487 @brief
Marcomissyou 0:a2de37bf5f3d 488 Retrieve a successful connection .
Marcomissyou 0:a2de37bf5f3d 489
Marcomissyou 0:a2de37bf5f3d 490 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 491 Socket ID.
Marcomissyou 0:a2de37bf5f3d 492
Marcomissyou 0:a2de37bf5f3d 493 @param [in] addr
Marcomissyou 0:a2de37bf5f3d 494 It is not used in the current implementation.
Marcomissyou 0:a2de37bf5f3d 495
Marcomissyou 0:a2de37bf5f3d 496 @param [in] addrlen
Marcomissyou 0:a2de37bf5f3d 497 It is not used in the current implementation.
Marcomissyou 0:a2de37bf5f3d 498
Marcomissyou 0:a2de37bf5f3d 499 @return
Marcomissyou 0:a2de37bf5f3d 500 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 501 */
Marcomissyou 0:a2de37bf5f3d 502 NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen);
Marcomissyou 0:a2de37bf5f3d 503
Marcomissyou 0:a2de37bf5f3d 504
Marcomissyou 0:a2de37bf5f3d 505 /*
Marcomissyou 0:a2de37bf5f3d 506 @fn \
Marcomissyou 0:a2de37bf5f3d 507 NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 508
Marcomissyou 0:a2de37bf5f3d 509 @brief
Marcomissyou 0:a2de37bf5f3d 510 Establishes a TCP connection with a remote server.
Marcomissyou 0:a2de37bf5f3d 511
Marcomissyou 0:a2de37bf5f3d 512 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 513 Socket ID.
Marcomissyou 0:a2de37bf5f3d 514
Marcomissyou 0:a2de37bf5f3d 515 @param [in] pstrAddr
Marcomissyou 0:a2de37bf5f3d 516 Address of the remote server.
Marcomissyou 0:a2de37bf5f3d 517
Marcomissyou 0:a2de37bf5f3d 518 @param [in] u8AddrLen
Marcomissyou 0:a2de37bf5f3d 519 Address length in bytes.
Marcomissyou 0:a2de37bf5f3d 520
Marcomissyou 0:a2de37bf5f3d 521 @return
Marcomissyou 0:a2de37bf5f3d 522 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 523 */
Marcomissyou 0:a2de37bf5f3d 524 NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 525
Marcomissyou 0:a2de37bf5f3d 526
Marcomissyou 0:a2de37bf5f3d 527 /*
Marcomissyou 0:a2de37bf5f3d 528 @fn \
Marcomissyou 0:a2de37bf5f3d 529 NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32TimeoutSeconds);
Marcomissyou 0:a2de37bf5f3d 530
Marcomissyou 0:a2de37bf5f3d 531 @brief
Marcomissyou 0:a2de37bf5f3d 532 Recieves data from a TCP Scoket.
Marcomissyou 0:a2de37bf5f3d 533
Marcomissyou 0:a2de37bf5f3d 534 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 535 Socket handler.
Marcomissyou 0:a2de37bf5f3d 536
Marcomissyou 0:a2de37bf5f3d 537 @param [in] pvRecvBuf
Marcomissyou 0:a2de37bf5f3d 538 Pointer to a buffer that will hold the received data. The buffer shall be used
Marcomissyou 0:a2de37bf5f3d 539 in the recv callback to deliver the received data to the caller. The buffer must
Marcomissyou 0:a2de37bf5f3d 540 be resident in memory (heap or global buffer).
Marcomissyou 0:a2de37bf5f3d 541
Marcomissyou 0:a2de37bf5f3d 542 @param [in] u16BufLen
Marcomissyou 0:a2de37bf5f3d 543 The buffer size in bytes.
Marcomissyou 0:a2de37bf5f3d 544
Marcomissyou 0:a2de37bf5f3d 545 @param [in] u32Timeoutmsec
Marcomissyou 0:a2de37bf5f3d 546 Timeout for the recv function in milli-seconds. If the value is set to ZERO, the timeout
Marcomissyou 0:a2de37bf5f3d 547 will be set to infinite (the recv function waits forever). If the timeout period is
Marcomissyou 0:a2de37bf5f3d 548 elapsed with no data received, the socket will get a timeout error in the function
Marcomissyou 0:a2de37bf5f3d 549 [APPSocketEventHandler](@ref APPSocketEventHandler).
Marcomissyou 0:a2de37bf5f3d 550
Marcomissyou 0:a2de37bf5f3d 551 @return
Marcomissyou 0:a2de37bf5f3d 552 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR)
Marcomissyou 0:a2de37bf5f3d 553 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG)
Marcomissyou 0:a2de37bf5f3d 554 */
Marcomissyou 0:a2de37bf5f3d 555 NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec);
Marcomissyou 0:a2de37bf5f3d 556
Marcomissyou 0:a2de37bf5f3d 557
Marcomissyou 0:a2de37bf5f3d 558 /*
Marcomissyou 0:a2de37bf5f3d 559 @fn \
Marcomissyou 0:a2de37bf5f3d 560 NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32TimeoutSeconds);
Marcomissyou 0:a2de37bf5f3d 561
Marcomissyou 0:a2de37bf5f3d 562 @brief
Marcomissyou 0:a2de37bf5f3d 563 Recieves data from a UDP Scoket.
Marcomissyou 0:a2de37bf5f3d 564
Marcomissyou 0:a2de37bf5f3d 565 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 566 Socket handler.
Marcomissyou 0:a2de37bf5f3d 567
Marcomissyou 0:a2de37bf5f3d 568 @param [in] pvRecvBuf
Marcomissyou 0:a2de37bf5f3d 569 Pointer to a buffer that will hold the received data. The buffer shall be used
Marcomissyou 0:a2de37bf5f3d 570 in the recv callback to deliver the received data to the caller. The buffer must
Marcomissyou 0:a2de37bf5f3d 571 be resident in memory (heap or global buffer).
Marcomissyou 0:a2de37bf5f3d 572
Marcomissyou 0:a2de37bf5f3d 573 @param [in] u16BufLen
Marcomissyou 0:a2de37bf5f3d 574 The buffer size in bytes.
Marcomissyou 0:a2de37bf5f3d 575
Marcomissyou 0:a2de37bf5f3d 576 @param [in] u32TimeoutSeconds
Marcomissyou 0:a2de37bf5f3d 577 Timeout for the recv function in milli-seconds. If the value is set to ZERO, the timeout
Marcomissyou 0:a2de37bf5f3d 578 will be set to infinite (the recv function waits forever).
Marcomissyou 0:a2de37bf5f3d 579
Marcomissyou 0:a2de37bf5f3d 580 @return
Marcomissyou 0:a2de37bf5f3d 581 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR)
Marcomissyou 0:a2de37bf5f3d 582 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG)
Marcomissyou 0:a2de37bf5f3d 583 */
Marcomissyou 0:a2de37bf5f3d 584 NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec);
Marcomissyou 0:a2de37bf5f3d 585
Marcomissyou 0:a2de37bf5f3d 586
Marcomissyou 0:a2de37bf5f3d 587 /*
Marcomissyou 0:a2de37bf5f3d 588 @fn \
Marcomissyou 0:a2de37bf5f3d 589 NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags);
Marcomissyou 0:a2de37bf5f3d 590
Marcomissyou 0:a2de37bf5f3d 591 @brief
Marcomissyou 0:a2de37bf5f3d 592 Sends data on a TCP Scoket.
Marcomissyou 0:a2de37bf5f3d 593
Marcomissyou 0:a2de37bf5f3d 594 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 595 Socket handler.
Marcomissyou 0:a2de37bf5f3d 596
Marcomissyou 0:a2de37bf5f3d 597 @param [in] pvSendBuffer
Marcomissyou 0:a2de37bf5f3d 598 Pointer to a buffer that holding data to be transmitted.
Marcomissyou 0:a2de37bf5f3d 599
Marcomissyou 0:a2de37bf5f3d 600 @param [in] u16SendLength
Marcomissyou 0:a2de37bf5f3d 601 The buffer size in bytes. It must not exceed [SOCKET_BUFFER_MAX_LENGTH](@ref SOCKET_BUFFER_MAX_LENGTH).
Marcomissyou 0:a2de37bf5f3d 602
Marcomissyou 0:a2de37bf5f3d 603 @param [in] u16Flags
Marcomissyou 0:a2de37bf5f3d 604 It is not used in the current implementation
Marcomissyou 0:a2de37bf5f3d 605
Marcomissyou 0:a2de37bf5f3d 606 @return
Marcomissyou 0:a2de37bf5f3d 607 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 608 */
Marcomissyou 0:a2de37bf5f3d 609 NMI_API sint16 send_nmc(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags);
Marcomissyou 0:a2de37bf5f3d 610
Marcomissyou 0:a2de37bf5f3d 611
Marcomissyou 0:a2de37bf5f3d 612 /*
Marcomissyou 0:a2de37bf5f3d 613 @fn \
Marcomissyou 0:a2de37bf5f3d 614 NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 615
Marcomissyou 0:a2de37bf5f3d 616 @brief
Marcomissyou 0:a2de37bf5f3d 617 Sends data on a UDP Scoket.
Marcomissyou 0:a2de37bf5f3d 618
Marcomissyou 0:a2de37bf5f3d 619 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 620 Socket handler.
Marcomissyou 0:a2de37bf5f3d 621
Marcomissyou 0:a2de37bf5f3d 622 @param [in] pvSendBuffer
Marcomissyou 0:a2de37bf5f3d 623 Pointer to a buffer that holding data to be transmitted.
Marcomissyou 0:a2de37bf5f3d 624
Marcomissyou 0:a2de37bf5f3d 625 @param [in] u16SendLength
Marcomissyou 0:a2de37bf5f3d 626 The buffer size in bytes. It must not exceed [SOCKET_BUFFER_MAX_LENGTH](@ref SOCKET_BUFFER_MAX_LENGTH).
Marcomissyou 0:a2de37bf5f3d 627
Marcomissyou 0:a2de37bf5f3d 628 @param [in] flags
Marcomissyou 0:a2de37bf5f3d 629 It is not used in the current implementation
Marcomissyou 0:a2de37bf5f3d 630
Marcomissyou 0:a2de37bf5f3d 631 @param [in] pstrDestAddr
Marcomissyou 0:a2de37bf5f3d 632 The destination address.
Marcomissyou 0:a2de37bf5f3d 633
Marcomissyou 0:a2de37bf5f3d 634 @param [in] u8AddrLen
Marcomissyou 0:a2de37bf5f3d 635 Destination address length in bytes.
Marcomissyou 0:a2de37bf5f3d 636
Marcomissyou 0:a2de37bf5f3d 637 @return
Marcomissyou 0:a2de37bf5f3d 638 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 639 */
Marcomissyou 0:a2de37bf5f3d 640 NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen);
Marcomissyou 0:a2de37bf5f3d 641
Marcomissyou 0:a2de37bf5f3d 642
Marcomissyou 0:a2de37bf5f3d 643 /*
Marcomissyou 0:a2de37bf5f3d 644 @fn \
Marcomissyou 0:a2de37bf5f3d 645 NMI_API sint8 close(SOCKET sock);
Marcomissyou 0:a2de37bf5f3d 646
Marcomissyou 0:a2de37bf5f3d 647 @brief
Marcomissyou 0:a2de37bf5f3d 648 Closes a socket.
Marcomissyou 0:a2de37bf5f3d 649
Marcomissyou 0:a2de37bf5f3d 650 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 651 Socket handler.
Marcomissyou 0:a2de37bf5f3d 652
Marcomissyou 0:a2de37bf5f3d 653 @return
Marcomissyou 0:a2de37bf5f3d 654 The function shall return ZERO for successful operation and a negative value otherwise.
Marcomissyou 0:a2de37bf5f3d 655 */
Marcomissyou 0:a2de37bf5f3d 656 NMI_API sint8 close_nmc(SOCKET sock);
Marcomissyou 0:a2de37bf5f3d 657
Marcomissyou 0:a2de37bf5f3d 658
Marcomissyou 0:a2de37bf5f3d 659 /*
Marcomissyou 0:a2de37bf5f3d 660 @fn \
Marcomissyou 0:a2de37bf5f3d 661 NMI_API sint8 gethostbyname(uint8 * pcHostName);
Marcomissyou 0:a2de37bf5f3d 662
Marcomissyou 0:a2de37bf5f3d 663 @brief
Marcomissyou 0:a2de37bf5f3d 664 Use DNS to resolve a domain name into the corresponding IP Address.
Marcomissyou 0:a2de37bf5f3d 665
Marcomissyou 0:a2de37bf5f3d 666 @param [in] pcHostName
Marcomissyou 0:a2de37bf5f3d 667 NULL terminated string containing the domain name for the remote host.
Marcomissyou 0:a2de37bf5f3d 668 Its size must not exceed [HOSTNAME_MAX_SIZE](@ref HOSTNAME_MAX_SIZE).
Marcomissyou 0:a2de37bf5f3d 669
Marcomissyou 0:a2de37bf5f3d 670 @return
Marcomissyou 0:a2de37bf5f3d 671 - [SOCK_ERR_NO_ERROR](@ref SOCK_ERR_NO_ERROR)
Marcomissyou 0:a2de37bf5f3d 672 - [SOCK_ERR_INVALID_ARG](@ref SOCK_ERR_INVALID_ARG)
Marcomissyou 0:a2de37bf5f3d 673 */
Marcomissyou 0:a2de37bf5f3d 674 NMI_API sint8 gethostbyname(uint8 * pcHostName);
Marcomissyou 0:a2de37bf5f3d 675
Marcomissyou 0:a2de37bf5f3d 676
Marcomissyou 0:a2de37bf5f3d 677 /*
Marcomissyou 0:a2de37bf5f3d 678 @fn \
Marcomissyou 0:a2de37bf5f3d 679 NMI_API uint32 nmi_inet_addr(char *pcIpAddr);
Marcomissyou 0:a2de37bf5f3d 680
Marcomissyou 0:a2de37bf5f3d 681 @brief
Marcomissyou 0:a2de37bf5f3d 682 Convert the IPv4 from the dotted decimal notation to an integer represented in Network Byte Order.
Marcomissyou 0:a2de37bf5f3d 683
Marcomissyou 0:a2de37bf5f3d 684 @param [in] pcIpAddr
Marcomissyou 0:a2de37bf5f3d 685 NULL terminated string containing the dotted decimal notation for an IP "a.b.c.d".
Marcomissyou 0:a2de37bf5f3d 686
Marcomissyou 0:a2de37bf5f3d 687 @return
Marcomissyou 0:a2de37bf5f3d 688 The integer representation of the IPv4 address in network byte order.
Marcomissyou 0:a2de37bf5f3d 689 */
Marcomissyou 0:a2de37bf5f3d 690 NMI_API uint32 nmi_inet_addr(char *pcIpAddr);
Marcomissyou 0:a2de37bf5f3d 691
Marcomissyou 0:a2de37bf5f3d 692
Marcomissyou 0:a2de37bf5f3d 693 /*
Marcomissyou 0:a2de37bf5f3d 694 @fn \
Marcomissyou 0:a2de37bf5f3d 695 NMI_API void APPSocketEventHandler(SOCKET sock, uint8 u8Msg, void * pvMsg);
Marcomissyou 0:a2de37bf5f3d 696
Marcomissyou 0:a2de37bf5f3d 697 @brief Socket Callback Function
Marcomissyou 0:a2de37bf5f3d 698
Marcomissyou 0:a2de37bf5f3d 699 A function used by the socket layer to convey a socket operation callback to the user. This function MUST be
Marcomissyou 0:a2de37bf5f3d 700 implemeneted by the application developer.
Marcomissyou 0:a2de37bf5f3d 701
Marcomissyou 0:a2de37bf5f3d 702 @param [in] sock
Marcomissyou 0:a2de37bf5f3d 703 Socket ID.
Marcomissyou 0:a2de37bf5f3d 704
Marcomissyou 0:a2de37bf5f3d 705 @param [in] u8Msg
Marcomissyou 0:a2de37bf5f3d 706 Socket message type [tenuSocketCallbackMsgType](@ref tenuSocketCallbackMsgType).
Marcomissyou 0:a2de37bf5f3d 707
Marcomissyou 0:a2de37bf5f3d 708 @param [in] pvMsg
Marcomissyou 0:a2de37bf5f3d 709 Msg parameters corresponding to the message type.
Marcomissyou 0:a2de37bf5f3d 710
Marcomissyou 0:a2de37bf5f3d 711 @sa tstrSocketBindMsg
Marcomissyou 0:a2de37bf5f3d 712 tstrSocketListenMsg
Marcomissyou 0:a2de37bf5f3d 713 tstrSocketAcceptMsg
Marcomissyou 0:a2de37bf5f3d 714 tstrSocketConnectMsg
Marcomissyou 0:a2de37bf5f3d 715 tstrSocketRecvMsg
Marcomissyou 0:a2de37bf5f3d 716 */
Marcomissyou 0:a2de37bf5f3d 717 NMI_API void APPSocketEventHandler(SOCKET sock, uint8 u8Msg, void * pvMsg);
Marcomissyou 0:a2de37bf5f3d 718
Marcomissyou 0:a2de37bf5f3d 719
Marcomissyou 0:a2de37bf5f3d 720 /*
Marcomissyou 0:a2de37bf5f3d 721 @fn \
Marcomissyou 0:a2de37bf5f3d 722 NMI_API void AppServerCb(uint8* pu8DomainName, uint32 u32ServerIP);
Marcomissyou 0:a2de37bf5f3d 723
Marcomissyou 0:a2de37bf5f3d 724 @brief
Marcomissyou 0:a2de37bf5f3d 725 DNS host name resolution callback.
Marcomissyou 0:a2de37bf5f3d 726
Marcomissyou 0:a2de37bf5f3d 727 @param [in] pu8DomainName
Marcomissyou 0:a2de37bf5f3d 728 NULL terminated string containing the Domain name of a host (eg. "www.Google.com").
Marcomissyou 0:a2de37bf5f3d 729
Marcomissyou 0:a2de37bf5f3d 730 @param [in] u32ServerIP
Marcomissyou 0:a2de37bf5f3d 731 IP Address corresponding to the domain name. It is formatted in network byte order.
Marcomissyou 0:a2de37bf5f3d 732 */
Marcomissyou 0:a2de37bf5f3d 733 NMI_API void AppServerCb(uint8* pu8DomainName, uint32 u32ServerIP);
Marcomissyou 0:a2de37bf5f3d 734
Marcomissyou 0:a2de37bf5f3d 735 //Ryan
Marcomissyou 0:a2de37bf5f3d 736 typedef void (*tf_APPSocketEventHandler)(SOCKET sock, uint8 u8Msg, void * pvMsg);
Marcomissyou 0:a2de37bf5f3d 737
Marcomissyou 0:a2de37bf5f3d 738 NMI_API void m2m_set_app(tf_APPSocketEventHandler str);
Marcomissyou 0:a2de37bf5f3d 739
Marcomissyou 0:a2de37bf5f3d 740 #define M2M_HIF_HDR_OFFSET (sizeof(tstrHifHdr))
Marcomissyou 0:a2de37bf5f3d 741
Marcomissyou 0:a2de37bf5f3d 742 /*
Marcomissyou 0:a2de37bf5f3d 743 * @struct tstrHifHdr
Marcomissyou 0:a2de37bf5f3d 744 * @brief Structure to hold HIF header
Marcomissyou 0:a2de37bf5f3d 745 * @author Mahfouz Sheref
Marcomissyou 0:a2de37bf5f3d 746 * @version 1.0
Marcomissyou 0:a2de37bf5f3d 747 */
Marcomissyou 0:a2de37bf5f3d 748 typedef struct
Marcomissyou 0:a2de37bf5f3d 749 {
Marcomissyou 0:a2de37bf5f3d 750 uint8 u8Gid; /*< Group ID */
Marcomissyou 0:a2de37bf5f3d 751 uint8 u8Opcode; /*< OP code */
Marcomissyou 0:a2de37bf5f3d 752 uint16 u16Length; /*< Payload length */
Marcomissyou 0:a2de37bf5f3d 753 }tstrHifHdr;
Marcomissyou 0:a2de37bf5f3d 754
Marcomissyou 0:a2de37bf5f3d 755 #ifdef __cplusplus
Marcomissyou 0:a2de37bf5f3d 756 }
Marcomissyou 0:a2de37bf5f3d 757 #endif /* __cplusplus */
Marcomissyou 0:a2de37bf5f3d 758
Marcomissyou 0:a2de37bf5f3d 759 #endif /* __SOCKET_H__ */