Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

417 linhas
8.3 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief BSD compatible socket interface internal types.
  6. *
  7. * Copyright (c) 2014 - 2017 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * 4. This software may only be redistributed and used in connection with an
  27. * Atmel microcontroller product.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  30. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  32. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  33. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  37. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * \asf_license_stop
  42. *
  43. */
  44. #ifndef __M2M_SOCKET_HOST_IF_H__
  45. #define __M2M_SOCKET_HOST_IF_H__
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  50. INCLUDES
  51. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  52. #ifndef _BOOT_
  53. #ifndef _FIRMWARE_
  54. #include "socket/include/socket.h"
  55. #else
  56. #include "m2m_types.h"
  57. #endif
  58. #endif
  59. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  60. MACROS
  61. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  62. /*
  63. * HOSTNAME_MAX_SIZE is defined here and also in host_drv/socket/include/socket.h
  64. * The two definitions must match.
  65. */
  66. #ifdef _FIRMWARE_
  67. #define HOSTNAME_MAX_SIZE (64)
  68. #endif
  69. #define SSL_MAX_OPT_LEN HOSTNAME_MAX_SIZE
  70. #define SOCKET_CMD_INVALID 0x00
  71. /*!<
  72. Invlaid Socket command value.
  73. */
  74. #define SOCKET_CMD_BIND 0x41
  75. /*!<
  76. Socket Binding command value.
  77. */
  78. #define SOCKET_CMD_LISTEN 0x42
  79. /*!<
  80. Socket Listening command value.
  81. */
  82. #define SOCKET_CMD_ACCEPT 0x43
  83. /*!<
  84. Socket Accepting command value.
  85. */
  86. #define SOCKET_CMD_CONNECT 0x44
  87. /*!<
  88. Socket Connecting command value.
  89. */
  90. #define SOCKET_CMD_SEND 0x45
  91. /*!<
  92. Socket send command value.
  93. */
  94. #define SOCKET_CMD_RECV 0x46
  95. /*!<
  96. Socket Recieve command value.
  97. */
  98. #define SOCKET_CMD_SENDTO 0x47
  99. /*!<
  100. Socket sendTo command value.
  101. */
  102. #define SOCKET_CMD_RECVFROM 0x48
  103. /*!<
  104. Socket RecieveFrom command value.
  105. */
  106. #define SOCKET_CMD_CLOSE 0x49
  107. /*!<
  108. Socket Close command value.
  109. */
  110. #define SOCKET_CMD_DNS_RESOLVE 0x4A
  111. /*!<
  112. Socket DNS Resolve command value.
  113. */
  114. #define SOCKET_CMD_SSL_CONNECT 0x4B
  115. /*!<
  116. SSL-Socket Connect command value.
  117. */
  118. #define SOCKET_CMD_SSL_SEND 0x4C
  119. /*!<
  120. SSL-Socket Send command value.
  121. */
  122. #define SOCKET_CMD_SSL_RECV 0x4D
  123. /*!<
  124. SSL-Socket Recieve command value.
  125. */
  126. #define SOCKET_CMD_SSL_CLOSE 0x4E
  127. /*!<
  128. SSL-Socket Close command value.
  129. */
  130. #define SOCKET_CMD_SET_SOCKET_OPTION 0x4F
  131. /*!<
  132. Set Socket Option command value.
  133. */
  134. #define SOCKET_CMD_SSL_CREATE 0x50
  135. /*!<
  136. */
  137. #define SOCKET_CMD_SSL_SET_SOCK_OPT 0x51
  138. /*!<
  139. */
  140. #define SOCKET_CMD_PING 0x52
  141. /*!<
  142. */
  143. #define SOCKET_CMD_SSL_SET_CS_LIST 0x53
  144. /*!<
  145. Recommend instead using @ref M2M_SSL_REQ_SET_CS_LIST and
  146. associated response @ref M2M_SSL_RESP_SET_CS_LIST
  147. */
  148. #define SOCKET_CMD_SSL_BIND 0x54
  149. /*!<
  150. */
  151. #define SOCKET_CMD_SSL_EXP_CHECK 0x55
  152. /*!<
  153. */
  154. #define PING_ERR_SUCCESS 0
  155. #define PING_ERR_DEST_UNREACH 1
  156. #define PING_ERR_TIMEOUT 2
  157. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  158. DATA TYPES
  159. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  160. /*!
  161. * @brief
  162. */
  163. typedef struct {
  164. uint16 u16Family;
  165. uint16 u16Port;
  166. uint32 u32IPAddr;
  167. } tstrSockAddr;
  168. //typedef sint8 SOCKET;
  169. typedef tstrSockAddr tstrUIPSockAddr;
  170. /*!
  171. @struct \
  172. tstrDnsReply
  173. @brief
  174. DNS Reply, contains hostName and HostIP.
  175. */
  176. typedef struct {
  177. char acHostName[HOSTNAME_MAX_SIZE];
  178. uint32 u32HostIP;
  179. } tstrDnsReply;
  180. /*!
  181. @brief
  182. */
  183. typedef struct {
  184. tstrSockAddr strAddr;
  185. SOCKET sock;
  186. uint8 u8Void;
  187. uint16 u16SessionID;
  188. } tstrBindCmd;
  189. /*!
  190. @brief
  191. */
  192. typedef struct {
  193. SOCKET sock;
  194. sint8 s8Status;
  195. uint16 u16SessionID;
  196. } tstrBindReply;
  197. /*!
  198. * @brief
  199. */
  200. typedef struct {
  201. SOCKET sock;
  202. uint8 u8BackLog;
  203. uint16 u16SessionID;
  204. } tstrListenCmd;
  205. /*!
  206. @struct \
  207. tstrSocketRecvMsg
  208. @brief Socket recv status.
  209. It is passed to the APPSocketEventHandler with SOCKET_MSG_RECV or SOCKET_MSG_RECVFROM message type
  210. in a response to a user call to the recv or recvfrom.
  211. If the received data from the remote peer is larger than the USER Buffer size (given at recv call), the data is
  212. delivered to the user in a number of consecutive chunks according to the USER Buffer size.
  213. */
  214. typedef struct {
  215. SOCKET sock;
  216. sint8 s8Status;
  217. uint16 u16SessionID;
  218. } tstrListenReply;
  219. /*!
  220. * @brief
  221. */
  222. typedef struct {
  223. tstrSockAddr strAddr;
  224. SOCKET sListenSock;
  225. SOCKET sConnectedSock;
  226. uint16 u16AppDataOffset;
  227. /*!<
  228. In further packet send requests the host interface should put the user application
  229. data at this offset in the allocated shared data packet.
  230. */
  231. } tstrAcceptReply;
  232. /*!
  233. * @brief
  234. */
  235. typedef struct {
  236. tstrSockAddr strAddr;
  237. SOCKET sock;
  238. uint8 u8SslFlags;
  239. uint16 u16SessionID;
  240. } tstrConnectCmd;
  241. /*!
  242. @struct \
  243. tstrConnectReply
  244. @brief
  245. Connect Reply, contains sock number and error value
  246. */
  247. typedef struct {
  248. SOCKET sock;
  249. sint8 s8Error;
  250. uint16 u16AppDataOffset;
  251. /*!<
  252. In further packet send requests the host interface should put the user application
  253. data at this offset in the allocated shared data packet.
  254. */
  255. } tstrConnectReply;
  256. /*!
  257. @brief
  258. */
  259. typedef struct {
  260. SOCKET sock;
  261. uint8 u8Void;
  262. uint16 u16DataSize;
  263. tstrSockAddr strAddr;
  264. uint16 u16SessionID;
  265. uint16 u16Void;
  266. } tstrSendCmd;
  267. /*!
  268. @struct \
  269. tstrSendReply
  270. @brief
  271. Send Reply, contains socket number and number of sent bytes.
  272. */
  273. typedef struct {
  274. SOCKET sock;
  275. uint8 u8Void;
  276. sint16 s16SentBytes;
  277. uint16 u16SessionID;
  278. uint16 u16Void;
  279. } tstrSendReply;
  280. /*!
  281. * @brief
  282. */
  283. typedef struct {
  284. uint32 u32Timeoutmsec;
  285. SOCKET sock;
  286. uint8 u8Void;
  287. uint16 u16SessionID;
  288. } tstrRecvCmd;
  289. /*!
  290. @struct
  291. @brief
  292. */
  293. typedef struct {
  294. tstrSockAddr strRemoteAddr;
  295. sint16 s16RecvStatus;
  296. uint16 u16DataOffset;
  297. SOCKET sock;
  298. uint8 u8Void;
  299. uint16 u16SessionID;
  300. } tstrRecvReply;
  301. /*!
  302. * @brief
  303. */
  304. typedef struct {
  305. uint32 u32OptionValue;
  306. SOCKET sock;
  307. uint8 u8Option;
  308. uint16 u16SessionID;
  309. } tstrSetSocketOptCmd;
  310. typedef struct {
  311. SOCKET sslSock;
  312. uint8 __PAD24__[3];
  313. } tstrSSLSocketCreateCmd;
  314. /*!
  315. * @brief
  316. */
  317. typedef struct {
  318. SOCKET sock;
  319. uint8 u8Option;
  320. uint16 u16SessionID;
  321. uint32 u32OptLen;
  322. uint8 au8OptVal[SSL_MAX_OPT_LEN];
  323. } tstrSSLSetSockOptCmd;
  324. /*!
  325. */
  326. typedef struct {
  327. uint32 u32DestIPAddr;
  328. uint32 u32CmdPrivate;
  329. uint16 u16PingCount;
  330. uint8 u8TTL;
  331. uint8 __PAD8__;
  332. } tstrPingCmd;
  333. typedef struct {
  334. uint32 u32IPAddr;
  335. uint32 u32CmdPrivate;
  336. uint32 u32RTT;
  337. uint16 u16Success;
  338. uint16 u16Fail;
  339. uint8 u8ErrorCode;
  340. uint8 __PAD24__[3];
  341. } tstrPingReply;
  342. /*!
  343. @struct\
  344. tstrSslCertExpSettings
  345. @brief SSL Certificate Expiry Validation Settings
  346. @sa tenuSslCertExpSettings
  347. */
  348. typedef struct {
  349. uint32 u32CertExpValidationOpt;
  350. /*!<
  351. See @tenuSslCertExpSettings for possible values.
  352. */
  353. } tstrSslCertExpSettings;
  354. #ifdef __cplusplus
  355. }
  356. #endif /* __cplusplus */
  357. #endif /* __M2M_SOCKET_HOST_IF_H__ */