1 /**
2  *
3  * \file
4  *
5  * \brief BSD compatible socket interface internal types.
6  *
7  * Copyright (c) 2016-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  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
27  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
29  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
30  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * \asf_license_stop
39  *
40  */
41 #ifndef __M2M_SOCKET_HOST_IF_H__
42 #define __M2M_SOCKET_HOST_IF_H__
43 
44 
45 #ifdef  __cplusplus
46 extern "C" {
47 #endif
48 
49 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
50 INCLUDES
51 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
52 
53 #ifndef	_BOOT_
54 #ifndef _FIRMWARE_
55 #include "socket/include/socket.h"
56 #else
57 #include "m2m_types.h"
58 #endif
59 #endif
60 
61 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
62 MACROS
63 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
64 
65 /*
66  *	HOSTNAME_MAX_SIZE is defined here and also in host_drv/socket/include/socket.h
67  *	The two definitions must match.
68 */
69 #ifdef _FIRMWARE_
70 #define HOSTNAME_MAX_SIZE					(64)
71 #endif
72 
73 #define SSL_MAX_OPT_LEN						HOSTNAME_MAX_SIZE
74 
75 
76 
77 #define SOCKET_CMD_INVALID					0x00
78 /*!<
79 	Invlaid Socket command value.
80 */
81 
82 
83 #define SOCKET_CMD_BIND						0x41
84 /*!<
85 	Socket Binding command value.
86 */
87 
88 
89 #define SOCKET_CMD_LISTEN					0x42
90 /*!<
91 	Socket Listening command value.
92 */
93 
94 
95 #define SOCKET_CMD_ACCEPT					0x43
96 /*!<
97 	Socket Accepting command value.
98 */
99 
100 
101 #define SOCKET_CMD_CONNECT					0x44
102 /*!<
103 	Socket Connecting command value.
104 */
105 
106 
107 #define SOCKET_CMD_SEND						0x45
108 /*!<
109 	Socket send command value.
110 */
111 
112 
113 #define SOCKET_CMD_RECV						0x46
114 /*!<
115 	Socket Recieve command value.
116 */
117 
118 
119 #define SOCKET_CMD_SENDTO					0x47
120 /*!<
121 	Socket sendTo command value.
122 */
123 
124 
125 #define SOCKET_CMD_RECVFROM					0x48
126 /*!<
127 	Socket RecieveFrom command value.
128 */
129 
130 
131 #define SOCKET_CMD_CLOSE					0x49
132 /*!<
133 	Socket Close command value.
134 */
135 
136 
137 #define SOCKET_CMD_DNS_RESOLVE				0x4A
138 /*!<
139 	Socket DNS Resolve command value.
140 */
141 
142 
143 #define SOCKET_CMD_SSL_CONNECT				0x4B
144 /*!<
145 	SSL-Socket Connect command value.
146 */
147 
148 
149 #define SOCKET_CMD_SSL_SEND					0x4C
150 /*!<
151 	SSL-Socket Send command value.
152 */
153 
154 
155 #define SOCKET_CMD_SSL_RECV					0x4D
156 /*!<
157 	SSL-Socket Recieve command value.
158 */
159 
160 
161 #define SOCKET_CMD_SSL_CLOSE				0x4E
162 /*!<
163 	SSL-Socket Close command value.
164 */
165 
166 
167 #define SOCKET_CMD_SET_SOCKET_OPTION		0x4F
168 /*!<
169 	Set Socket Option command value.
170 */
171 
172 
173 #define SOCKET_CMD_SSL_CREATE				0x50
174 /*!<
175 */
176 
177 
178 #define SOCKET_CMD_SSL_SET_SOCK_OPT			0x51
179 /*!<
180 */
181 
182 
183 #define SOCKET_CMD_PING						0x52
184 /*!<
185 */
186 
187 
188 #define SOCKET_CMD_SSL_SET_CS_LIST			0x53
189 /*!<
190 	Recommend instead using @ref M2M_SSL_REQ_SET_CS_LIST and
191 	associated response @ref M2M_SSL_RESP_SET_CS_LIST
192 */
193 
194 
195 #define SOCKET_CMD_SSL_BIND					0x54
196 /*!<
197 */
198 
199 
200 #define SOCKET_CMD_SSL_EXP_CHECK			0x55
201 /*!<
202 */
203 
204 
205 
206 #define PING_ERR_SUCCESS					0
207 #define PING_ERR_DEST_UNREACH				1
208 #define PING_ERR_TIMEOUT					2
209 
210 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
211 DATA TYPES
212 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
213 
214 
215 /*!
216 *  @brief
217 */
218 typedef struct{
219 	uint16		u16Family;
220 	uint16		u16Port;
221 	uint32		u32IPAddr;
222 }tstrSockAddr;
223 
224 
225 typedef sint8			SOCKET;
226 typedef tstrSockAddr	tstrUIPSockAddr;
227 
228 
229 
230 /*!
231 @struct	\
232 	tstrDnsReply
233 
234 @brief
235 	DNS Reply, contains hostName and HostIP.
236 */
237 typedef struct{
238 	char		acHostName[HOSTNAME_MAX_SIZE];
239 	uint32		u32HostIP;
240 }tstrDnsReply;
241 
242 
243 /*!
244 @brief
245 */
246 typedef struct{
247 	tstrSockAddr	strAddr;
248 	SOCKET			sock;
249 	uint8			u8Void;
250 	uint16			u16SessionID;
251 }tstrBindCmd;
252 
253 
254 /*!
255 @brief
256 */
257 typedef struct{
258 	SOCKET		sock;
259 	sint8		s8Status;
260 	uint16		u16SessionID;
261 }tstrBindReply;
262 
263 
264 /*!
265 *  @brief
266 */
267 typedef struct{
268 	SOCKET	sock;
269 	uint8	u8BackLog;
270 	uint16	u16SessionID;
271 }tstrListenCmd;
272 
273 
274 /*!
275 @struct	\
276 	tstrSocketRecvMsg
277 
278 @brief	Socket recv status.
279 
280 	It is passed to the APPSocketEventHandler with SOCKET_MSG_RECV or SOCKET_MSG_RECVFROM message type
281 	in a response to a user call to the recv or recvfrom.
282 	If the received data from the remote peer is larger than the USER Buffer size (given at recv call), the data is
283 	delivered to the user in a number of consecutive chunks according to the USER Buffer size.
284 */
285 typedef struct{
286 	SOCKET		sock;
287 	sint8		s8Status;
288 	uint16		u16SessionID;
289 }tstrListenReply;
290 
291 
292 /*!
293 *  @brief
294 */
295 typedef struct{
296 	tstrSockAddr	strAddr;
297 	SOCKET			sListenSock;
298 	SOCKET			sConnectedSock;
299 	uint16			u16AppDataOffset;
300 	/*!<
301 		In further packet send requests the host interface should put the user application
302 		data at this offset in the allocated shared data packet.
303 	*/
304 }tstrAcceptReply;
305 
306 
307 /*!
308 *  @brief
309 */
310 typedef struct{
311 	tstrSockAddr	strAddr;
312 	SOCKET			sock;
313 	uint8			u8SslFlags;
314 	uint16			u16SessionID;
315 }tstrConnectCmd;
316 
317 
318 /*!
319 @struct	\
320 	tstrConnectReply
321 
322 @brief
323 	Connect Reply, contains sock number and error value
324 */
325 typedef struct{
326 	SOCKET		sock;
327 	sint8		s8Error;
328 	uint16		u16AppDataOffset;
329 	/*!<
330 		In further packet send requests the host interface should put the user application
331 		data at this offset in the allocated shared data packet.
332 	*/
333 }tstrConnectReply;
334 
335 
336 /*!
337 @brief
338 */
339 typedef struct{
340 	SOCKET			sock;
341 	uint8			u8Void;
342 	uint16			u16DataSize;
343 	tstrSockAddr	strAddr;
344 	uint16			u16SessionID;
345 	uint16			u16Void;
346 }tstrSendCmd;
347 
348 
349 /*!
350 @struct	\
351 	tstrSendReply
352 
353 @brief
354 	Send Reply, contains socket number and number of sent bytes.
355 */
356 typedef struct{
357 	SOCKET		sock;
358 	uint8		u8Void;
359 	sint16		s16SentBytes;
360 	uint16		u16SessionID;
361 	uint16		u16Void;
362 }tstrSendReply;
363 
364 
365 /*!
366 *  @brief
367 */
368 typedef struct{
369 	uint32		u32Timeoutmsec;
370 	SOCKET		sock;
371 	uint8		u8Void;
372 	uint16		u16SessionID;
373 }tstrRecvCmd;
374 
375 
376 /*!
377 @struct
378 @brief
379 */
380 typedef struct{
381 	tstrSockAddr	strRemoteAddr;
382 	sint16			s16RecvStatus;
383 	uint16			u16DataOffset;
384 	SOCKET			sock;
385 	uint8			u8Void;
386 	uint16			u16SessionID;
387 }tstrRecvReply;
388 
389 
390 /*!
391 *  @brief
392 */
393 typedef struct{
394 	uint32		u32OptionValue;
395 	SOCKET		sock;
396 	uint8 		u8Option;
397 	uint16		u16SessionID;
398 }tstrSetSocketOptCmd;
399 
400 
401 typedef struct{
402 	SOCKET		sslSock;
403 	uint8		__PAD24__[3];
404 }tstrSSLSocketCreateCmd;
405 
406 
407 /*!
408 *  @brief
409 */
410 typedef struct{
411 	SOCKET		sock;
412 	uint8 		u8Option;
413 	uint16		u16SessionID;
414 	uint32		u32OptLen;
415 	uint8		au8OptVal[SSL_MAX_OPT_LEN];
416 }tstrSSLSetSockOptCmd;
417 
418 
419 /*!
420 */
421 typedef struct{
422 	uint32	u32DestIPAddr;
423 	uint32	u32CmdPrivate;
424 	uint16	u16PingCount;
425 	uint8	u8TTL;
426 	uint8	__PAD8__;
427 }tstrPingCmd;
428 
429 
430 typedef struct{
431 	uint32	u32IPAddr;
432 	uint32	u32CmdPrivate;
433 	uint32	u32RTT;
434 	uint16	u16Success;
435 	uint16	u16Fail;
436 	uint8	u8ErrorCode;
437 	uint8	__PAD24__[3];
438 }tstrPingReply;
439 
440 
441 /*!
442 @struct\
443 	tstrSslCertExpSettings
444 
445 @brief	SSL Certificate Expiry Validation Settings
446 
447 @sa		tenuSslCertExpSettings
448 */
449 typedef struct{
450 	uint32	u32CertExpValidationOpt;
451 	/*!<
452 		See @tenuSslCertExpSettings for possible values.
453 	*/
454 }tstrSslCertExpSettings;
455 
456 
457 #ifdef  __cplusplus
458 }
459 #endif /* __cplusplus */
460 
461 #endif /* __M2M_SOCKET_HOST_IF_H__ */
462