FreeRTOS_IP_Private.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. /*
  2. * FreeRTOS+TCP V2.3.2 LTS Patch 1
  3. * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://aws.amazon.com/freertos
  23. * http://www.FreeRTOS.org
  24. */
  25. #ifndef FREERTOS_IP_PRIVATE_H
  26. #define FREERTOS_IP_PRIVATE_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Application level configuration options. */
  31. #include "FreeRTOSIPConfig.h"
  32. #include "FreeRTOSIPConfigDefaults.h"
  33. #include "FreeRTOS_Sockets.h"
  34. #include "IPTraceMacroDefaults.h"
  35. #include "FreeRTOS_Stream_Buffer.h"
  36. #if ( ipconfigUSE_TCP == 1 )
  37. #include "FreeRTOS_TCP_WIN.h"
  38. #include "FreeRTOS_TCP_IP.h"
  39. #endif
  40. #include "semphr.h"
  41. #include "event_groups.h"
  42. /*-----------------------------------------------------------*/
  43. /* Utility macros for marking casts as recognized during */
  44. /* static analysis. */
  45. /*-----------------------------------------------------------*/
  46. #define ipCAST_PTR_TO_TYPE_PTR( TYPE, pointer ) ( vCastPointerTo_ ## TYPE( ( void * ) ( pointer ) ) )
  47. #define ipCAST_CONST_PTR_TO_CONST_TYPE_PTR( TYPE, pointer ) ( vCastConstPointerTo_ ## TYPE( ( const void * ) ( pointer ) ) )
  48. /*-----------------------------------------------------------*/
  49. /* Utility macros for declaring cast utility functions in */
  50. /* order to centralize typecasting for static analysis. */
  51. /*-----------------------------------------------------------*/
  52. #define ipDECL_CAST_PTR_FUNC_FOR_TYPE( TYPE ) TYPE * vCastPointerTo_ ## TYPE( void * pvArgument )
  53. #define ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TYPE ) const TYPE * vCastConstPointerTo_ ## TYPE( const void * pvArgument )
  54. /**
  55. * Structure to hold the information about the Network parameters.
  56. */
  57. typedef struct xNetworkAddressingParameters
  58. {
  59. uint32_t ulDefaultIPAddress; /**< The default IP address */
  60. uint32_t ulNetMask; /**< The netmask */
  61. uint32_t ulGatewayAddress; /**< The gateway address */
  62. uint32_t ulDNSServerAddress; /**< The DNS server address */
  63. uint32_t ulBroadcastAddress; /**< The Broadcast address */
  64. } NetworkAddressingParameters_t;
  65. extern BaseType_t xTCPWindowLoggingLevel;
  66. extern QueueHandle_t xNetworkEventQueue;
  67. /*-----------------------------------------------------------*/
  68. /* Protocol headers. */
  69. /*-----------------------------------------------------------*/
  70. #include "pack_struct_start.h"
  71. struct xETH_HEADER
  72. {
  73. MACAddress_t xDestinationAddress; /**< Destination address 0 + 6 = 6 */
  74. MACAddress_t xSourceAddress; /**< Source address 6 + 6 = 12 */
  75. uint16_t usFrameType; /**< The EtherType field 12 + 2 = 14 */
  76. };
  77. #include "pack_struct_end.h"
  78. typedef struct xETH_HEADER EthernetHeader_t;
  79. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( EthernetHeader_t )
  80. {
  81. return ( EthernetHeader_t * ) pvArgument;
  82. }
  83. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( EthernetHeader_t )
  84. {
  85. return ( const EthernetHeader_t * ) pvArgument;
  86. }
  87. #include "pack_struct_start.h"
  88. struct xARP_HEADER
  89. {
  90. uint16_t usHardwareType; /**< Network Link Protocol type 0 + 2 = 2 */
  91. uint16_t usProtocolType; /**< The internetwork protocol 2 + 2 = 4 */
  92. uint8_t ucHardwareAddressLength; /**< Length in octets of a hardware address 4 + 1 = 5 */
  93. uint8_t ucProtocolAddressLength; /**< Length in octets of the internetwork protocol 5 + 1 = 6 */
  94. uint16_t usOperation; /**< Operation that the sender is performing 6 + 2 = 8 */
  95. MACAddress_t xSenderHardwareAddress; /**< Media address of the sender 8 + 6 = 14 */
  96. uint8_t ucSenderProtocolAddress[ 4 ]; /**< Internetwork address of sender 14 + 4 = 18 */
  97. MACAddress_t xTargetHardwareAddress; /**< Media address of the intended receiver 18 + 6 = 24 */
  98. uint32_t ulTargetProtocolAddress; /**< Internetwork address of the intended receiver 24 + 4 = 28 */
  99. };
  100. #include "pack_struct_end.h"
  101. typedef struct xARP_HEADER ARPHeader_t;
  102. #include "pack_struct_start.h"
  103. struct xIP_HEADER
  104. {
  105. uint8_t ucVersionHeaderLength; /**< The version field + internet header length 0 + 1 = 1 */
  106. uint8_t ucDifferentiatedServicesCode; /**< Differentiated services code point + ECN 1 + 1 = 2 */
  107. uint16_t usLength; /**< Entire Packet size 2 + 2 = 4 */
  108. uint16_t usIdentification; /**< Identification field 4 + 2 = 6 */
  109. uint16_t usFragmentOffset; /**< Fragment flags and fragment offset 6 + 2 = 8 */
  110. uint8_t ucTimeToLive; /**< Time to live field 8 + 1 = 9 */
  111. uint8_t ucProtocol; /**< Protocol used in the IP-datagram 9 + 1 = 10 */
  112. uint16_t usHeaderChecksum; /**< Checksum of the IP-header 10 + 2 = 12 */
  113. uint32_t ulSourceIPAddress; /**< IP address of the source 12 + 4 = 16 */
  114. uint32_t ulDestinationIPAddress; /**< IP address of the destination 16 + 4 = 20 */
  115. };
  116. #include "pack_struct_end.h"
  117. typedef struct xIP_HEADER IPHeader_t;
  118. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPHeader_t )
  119. {
  120. return ( IPHeader_t * ) pvArgument;
  121. }
  122. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPHeader_t )
  123. {
  124. return ( const IPHeader_t * ) pvArgument;
  125. }
  126. #include "pack_struct_start.h"
  127. struct xICMP_HEADER
  128. {
  129. uint8_t ucTypeOfMessage; /**< The ICMP type 0 + 1 = 1 */
  130. uint8_t ucTypeOfService; /**< The ICMP subtype 1 + 1 = 2 */
  131. uint16_t usChecksum; /**< The checksum of whole ICMP packet 2 + 2 = 4 */
  132. uint16_t usIdentifier; /**< Used in some types of ICMP 4 + 2 = 6 */
  133. uint16_t usSequenceNumber; /**< Used in some types of ICMP 6 + 2 = 8 */
  134. };
  135. #include "pack_struct_end.h"
  136. typedef struct xICMP_HEADER ICMPHeader_t;
  137. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPHeader_t )
  138. {
  139. return ( ICMPHeader_t * ) pvArgument;
  140. }
  141. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ICMPHeader_t )
  142. {
  143. return ( const ICMPHeader_t * ) pvArgument;
  144. }
  145. #include "pack_struct_start.h"
  146. struct xUDP_HEADER
  147. {
  148. uint16_t usSourcePort; /**< The source port 0 + 2 = 2 */
  149. uint16_t usDestinationPort; /**< The destination port 2 + 2 = 4 */
  150. uint16_t usLength; /**< The size of the whole UDP packet 4 + 2 = 6 */
  151. uint16_t usChecksum; /**< The checksum of the whole UDP Packet 6 + 2 = 8 */
  152. };
  153. #include "pack_struct_end.h"
  154. typedef struct xUDP_HEADER UDPHeader_t;
  155. #include "pack_struct_start.h"
  156. struct xTCP_HEADER
  157. {
  158. uint16_t usSourcePort; /**< The Source port + 2 = 2 */
  159. uint16_t usDestinationPort; /**< The destination port + 2 = 4 */
  160. uint32_t ulSequenceNumber; /**< The Sequence number + 4 = 8 */
  161. uint32_t ulAckNr; /**< The acknowledgement number + 4 = 12 */
  162. uint8_t ucTCPOffset; /**< The value of TCP offset + 1 = 13 */
  163. uint8_t ucTCPFlags; /**< The TCP-flags field + 1 = 14 */
  164. uint16_t usWindow; /**< The size of the receive window + 2 = 15 */
  165. uint16_t usChecksum; /**< The checksum of the header + 2 = 18 */
  166. uint16_t usUrgent; /**< Pointer to the last urgent data byte + 2 = 20 */
  167. #if ipconfigUSE_TCP == 1
  168. uint8_t ucOptdata[ ipSIZE_TCP_OPTIONS ]; /**< The options + 12 = 32 */
  169. #endif
  170. };
  171. #include "pack_struct_end.h"
  172. typedef struct xTCP_HEADER TCPHeader_t;
  173. /*-----------------------------------------------------------*/
  174. /* Nested protocol packets. */
  175. /*-----------------------------------------------------------*/
  176. #include "pack_struct_start.h"
  177. struct xARP_PACKET
  178. {
  179. EthernetHeader_t xEthernetHeader; /**< The ethernet header of an ARP Packet 0 + 14 = 14 */
  180. ARPHeader_t xARPHeader; /**< The ARP header of an ARP Packet 14 + 28 = 42 */
  181. };
  182. #include "pack_struct_end.h"
  183. typedef struct xARP_PACKET ARPPacket_t;
  184. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ARPPacket_t )
  185. {
  186. return ( ARPPacket_t * ) pvArgument;
  187. }
  188. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ARPPacket_t )
  189. {
  190. return ( const ARPPacket_t * ) pvArgument;
  191. }
  192. #include "pack_struct_start.h"
  193. struct xIP_PACKET
  194. {
  195. EthernetHeader_t xEthernetHeader;
  196. IPHeader_t xIPHeader;
  197. };
  198. #include "pack_struct_end.h"
  199. typedef struct xIP_PACKET IPPacket_t;
  200. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( IPPacket_t )
  201. {
  202. return ( IPPacket_t * ) pvArgument;
  203. }
  204. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( IPPacket_t )
  205. {
  206. return ( const IPPacket_t * ) pvArgument;
  207. }
  208. #include "pack_struct_start.h"
  209. struct xICMP_PACKET
  210. {
  211. EthernetHeader_t xEthernetHeader; /**< The Ethernet header of an ICMP packet. */
  212. IPHeader_t xIPHeader; /**< The IP header of an ICMP packet. */
  213. ICMPHeader_t xICMPHeader; /**< The ICMP header of an ICMP packet. */
  214. };
  215. #include "pack_struct_end.h"
  216. typedef struct xICMP_PACKET ICMPPacket_t;
  217. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ICMPPacket_t )
  218. {
  219. return ( ICMPPacket_t * ) pvArgument;
  220. }
  221. #include "pack_struct_start.h"
  222. struct xUDP_PACKET
  223. {
  224. EthernetHeader_t xEthernetHeader; /**< UDP-Packet ethernet header 0 + 14 = 14 */
  225. IPHeader_t xIPHeader; /**< UDP-Packet IP header 14 + 20 = 34 */
  226. UDPHeader_t xUDPHeader; /**< UDP-Packet UDP header 34 + 8 = 42 */
  227. };
  228. #include "pack_struct_end.h"
  229. typedef struct xUDP_PACKET UDPPacket_t;
  230. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
  231. {
  232. return ( UDPPacket_t * ) pvArgument;
  233. }
  234. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( UDPPacket_t )
  235. {
  236. return ( const UDPPacket_t * ) pvArgument;
  237. }
  238. #include "pack_struct_start.h"
  239. struct xTCP_PACKET
  240. {
  241. EthernetHeader_t xEthernetHeader; /**< The ethernet header 0 + 14 = 14 */
  242. IPHeader_t xIPHeader; /**< The IP header 14 + 20 = 34 */
  243. TCPHeader_t xTCPHeader; /**< The TCP header 34 + 32 = 66 */
  244. };
  245. #include "pack_struct_end.h"
  246. typedef struct xTCP_PACKET TCPPacket_t;
  247. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
  248. {
  249. return ( TCPPacket_t * ) pvArgument;
  250. }
  251. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( TCPPacket_t )
  252. {
  253. return ( const TCPPacket_t * ) pvArgument;
  254. }
  255. /**
  256. * Union for the protocol packet to save space. Any packet cannot have more than one
  257. * of the below protocol packets.
  258. */
  259. typedef union XPROT_PACKET
  260. {
  261. ARPPacket_t xARPPacket; /**< Union member: ARP packet struct */
  262. TCPPacket_t xTCPPacket; /**< Union member: TCP packet struct */
  263. UDPPacket_t xUDPPacket; /**< Union member: UDP packet struct */
  264. ICMPPacket_t xICMPPacket; /**< Union member: ICMP packet struct */
  265. } ProtocolPacket_t;
  266. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t )
  267. {
  268. return ( ProtocolPacket_t * ) pvArgument;
  269. }
  270. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolPacket_t )
  271. {
  272. return ( const ProtocolPacket_t * ) pvArgument;
  273. }
  274. /**
  275. * Union for protocol headers to save space (RAM). Any packet cannot have more than one of
  276. * the below protocols.
  277. */
  278. typedef union xPROT_HEADERS
  279. {
  280. ICMPHeader_t xICMPHeader; /**< Union member: ICMP header */
  281. UDPHeader_t xUDPHeader; /**< Union member: UDP header */
  282. TCPHeader_t xTCPHeader; /**< Union member: TCP header */
  283. } ProtocolHeaders_t;
  284. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
  285. {
  286. return ( ProtocolHeaders_t * ) pvArgument;
  287. }
  288. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( ProtocolHeaders_t )
  289. {
  290. return ( const ProtocolHeaders_t * ) pvArgument;
  291. }
  292. /* The maximum UDP payload length. */
  293. #define ipMAX_UDP_PAYLOAD_LENGTH ( ( ipconfigNETWORK_MTU - ipSIZE_OF_IPv4_HEADER ) - ipSIZE_OF_UDP_HEADER )
  294. typedef enum
  295. {
  296. eReleaseBuffer = 0, /* Processing the frame did not find anything to do - just release the buffer. */
  297. eProcessBuffer, /* An Ethernet frame has a valid address - continue process its contents. */
  298. eReturnEthernetFrame, /* The Ethernet frame contains an ARP or ICMP packet that can be returned to its source. */
  299. eFrameConsumed /* Processing the Ethernet packet contents resulted in the payload being sent to the stack. */
  300. } eFrameProcessingResult_t;
  301. typedef enum
  302. {
  303. eNoEvent = -1,
  304. eNetworkDownEvent, /* 0: The network interface has been lost and/or needs [re]connecting. */
  305. eNetworkRxEvent, /* 1: The network interface has queued a received Ethernet frame. */
  306. eNetworkTxEvent, /* 2: Let the IP-task send a network packet. */
  307. eARPTimerEvent, /* 3: The ARP timer expired. */
  308. eStackTxEvent, /* 4: The software stack has queued a packet to transmit. */
  309. eDHCPEvent, /* 5: Process the DHCP state machine. */
  310. eTCPTimerEvent, /* 6: See if any TCP socket needs attention. */
  311. eTCPAcceptEvent, /* 7: Client API FreeRTOS_accept() waiting for client connections. */
  312. eTCPNetStat, /* 8: IP-task is asked to produce a netstat listing. */
  313. eSocketBindEvent, /* 9: Send a message to the IP-task to bind a socket to a port. */
  314. eSocketCloseEvent, /*10: Send a message to the IP-task to close a socket. */
  315. eSocketSelectEvent, /*11: Send a message to the IP-task for select(). */
  316. eSocketSignalEvent, /*12: A socket must be signalled. */
  317. } eIPEvent_t;
  318. /**
  319. * Structure for the information of the commands issued to the IP task.
  320. */
  321. typedef struct IP_TASK_COMMANDS
  322. {
  323. eIPEvent_t eEventType; /**< The event-type enum */
  324. void * pvData; /**< The data in the event */
  325. } IPStackEvent_t;
  326. #define ipBROADCAST_IP_ADDRESS 0xffffffffUL
  327. /* Offset into the Ethernet frame that is used to temporarily store information
  328. * on the fragmentation status of the packet being sent. The value is important,
  329. * as it is past the location into which the destination address will get placed. */
  330. #define ipFRAGMENTATION_PARAMETERS_OFFSET ( 6 )
  331. #define ipSOCKET_OPTIONS_OFFSET ( 6 )
  332. /* Only used when outgoing fragmentation is being used (FreeRTOSIPConfig.h
  333. * setting. */
  334. #define ipGET_UDP_PAYLOAD_OFFSET_FOR_FRAGMENT( usFragmentOffset ) ( ( ( usFragmentOffset ) == 0 ) ? ipUDP_PAYLOAD_OFFSET_IPv4 : ipIP_PAYLOAD_OFFSET )
  335. /* The offset into a UDP packet at which the UDP data (payload) starts. */
  336. #define ipUDP_PAYLOAD_OFFSET_IPv4 ( sizeof( UDPPacket_t ) )
  337. /* The offset into an IP packet into which the IP data (payload) starts. */
  338. #define ipIP_PAYLOAD_OFFSET ( sizeof( IPPacket_t ) )
  339. #if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN )
  340. /* Ethernet frame types. */
  341. #define ipARP_FRAME_TYPE ( 0x0608U )
  342. #define ipIPv4_FRAME_TYPE ( 0x0008U )
  343. /* ARP related definitions. */
  344. #define ipARP_PROTOCOL_TYPE ( 0x0008U )
  345. #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0100U )
  346. #define ipARP_REQUEST ( 0x0100U )
  347. #define ipARP_REPLY ( 0x0200U )
  348. #else /* if ( ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN ) */
  349. /* Ethernet frame types. */
  350. #define ipARP_FRAME_TYPE ( 0x0806U )
  351. #define ipIPv4_FRAME_TYPE ( 0x0800U )
  352. /* ARP related definitions. */
  353. #define ipARP_PROTOCOL_TYPE ( 0x0800U )
  354. #define ipARP_HARDWARE_TYPE_ETHERNET ( 0x0001U )
  355. #define ipARP_REQUEST ( 0x0001 )
  356. #define ipARP_REPLY ( 0x0002 )
  357. #endif /* ipconfigBYTE_ORDER == pdFREERTOS_LITTLE_ENDIAN */
  358. /* For convenience, a MAC address of all zeros and another of all 0xffs are
  359. * defined const for quick reference. */
  360. extern const MACAddress_t xBroadcastMACAddress; /* all 0xff's */
  361. extern uint16_t usPacketIdentifier;
  362. /**
  363. * Define a default UDP packet header (declared in FreeRTOS_UDP_IP.c)
  364. */
  365. typedef union xUDPPacketHeader
  366. {
  367. uint8_t ucBytes[ 24 ]; /**< Member: 8-bit array */
  368. uint32_t ulWords[ 6 ]; /**< Member: 32-bit array */
  369. } UDPPacketHeader_t;
  370. extern UDPPacketHeader_t xDefaultPartUDPPacketHeader;
  371. /* Structure that stores the netmask, gateway address and DNS server addresses. */
  372. extern NetworkAddressingParameters_t xNetworkAddressing;
  373. /* Structure that stores the defaults for netmask, gateway address and DNS.
  374. * These values will be copied to 'xNetworkAddressing' in case DHCP is not used,
  375. * and also in case DHCP does not lead to a confirmed request. */
  376. /*lint -e9003*/
  377. extern NetworkAddressingParameters_t xDefaultAddressing; /*lint !e9003 could define variable 'xDefaultAddressing' at block scope [MISRA 2012 Rule 8.9, advisory]. */
  378. /* True when BufferAllocation_1.c was included, false for BufferAllocation_2.c */
  379. extern const BaseType_t xBufferAllocFixedSize;
  380. /* Defined in FreeRTOS_Sockets.c */
  381. #if ( ipconfigUSE_TCP == 1 )
  382. extern List_t xBoundTCPSocketsList;
  383. #endif
  384. /* The local IP address is accessed from within xDefaultPartUDPPacketHeader,
  385. * rather than duplicated in its own variable. */
  386. #define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[ 20U / sizeof( uint32_t ) ] ) )
  387. /* The local MAC address is accessed from within xDefaultPartUDPPacketHeader,
  388. * rather than duplicated in its own variable. */
  389. #define ipLOCAL_MAC_ADDRESS ( xDefaultPartUDPPacketHeader.ucBytes )
  390. /* In this library, there is often a cast from a character pointer
  391. * to a pointer to a struct.
  392. * In order to suppress MISRA warnings, do the cast within a macro,
  393. * which can be exempt from warnings:
  394. *
  395. * 3 required by MISRA:
  396. * -emacro(740,ipPOINTER_CAST) // 750: Unusual pointer cast (incompatible indirect types) [MISRA 2012 Rule 1.3, required])
  397. * -emacro(9005,ipPOINTER_CAST) // 9005: attempt to cast away const/volatile from a pointer or reference [MISRA 2012 Rule 11.8, required]
  398. * -emacro(9087,ipPOINTER_CAST) // 9087: cast performed between a pointer to object type and a pointer to a different object type [MISRA 2012 Rule 11.3, required]
  399. *
  400. * 2 advisory by MISRA:
  401. * -emacro(9079,ipPOINTER_CAST) // 9079: conversion from pointer to void to pointer to other type [MISRA 2012 Rule 11.5, advisory])
  402. * --emacro((826),ipPOINTER_CAST) // 826: Suspicious pointer-to-pointer conversion (area too small)
  403. *
  404. * The MISRA warnings can safely be suppressed because all casts are planned with care.
  405. */
  406. #define ipPOINTER_CAST( TYPE, pointer ) ( ( TYPE ) ( pointer ) )
  407. /* Sequence and ACK numbers are essentially unsigned (uint32_t). But when
  408. * a distance is calculated, it is useful to use signed numbers:
  409. * int32_t lDistance = ( int32_t ) ( ulSeq1 - ulSeq2 );
  410. *
  411. * 1 required by MISRA:
  412. * -emacro(9033,ipNUMERIC_CAST) // 9033: Impermissible cast of composite expression (different essential type categories) [MISRA 2012 Rule 10.8, required])
  413. *
  414. * 1 advisory by MISRA:
  415. * -emacro(9030,ipNUMERIC_CAST) // 9030: Impermissible cast; cannot cast from 'essentially Boolean' to 'essentially signed' [MISRA 2012 Rule 10.5, advisory])
  416. */
  417. #define ipNUMERIC_CAST( TYPE, expression ) ( ( TYPE ) ( expression ) )
  418. /* ICMP packets are sent using the same function as UDP packets. The port
  419. * number is used to distinguish between the two, as 0 is an invalid UDP port. */
  420. #define ipPACKET_CONTAINS_ICMP_DATA ( 0 )
  421. /* For now, the lower 8 bits in 'xEventBits' will be reserved for the above
  422. * socket events. */
  423. #define SOCKET_EVENT_BIT_COUNT 8
  424. #define vSetField16( pxBase, xType, xField, usValue ) \
  425. { \
  426. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( usValue ) >> 8 ); \
  427. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( usValue ) & 0xffU ); \
  428. }
  429. #define vSetField32( pxBase, xType, xField, ulValue ) \
  430. { \
  431. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 0 ] = ( uint8_t ) ( ( ulValue ) >> 24 ); \
  432. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 1 ] = ( uint8_t ) ( ( ( ulValue ) >> 16 ) & 0xffU ); \
  433. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 2 ] = ( uint8_t ) ( ( ( ulValue ) >> 8 ) & 0xffU ); \
  434. ( ( uint8_t * ) ( pxBase ) )[ offsetof( xType, xField ) + 3 ] = ( uint8_t ) ( ( ulValue ) & 0xffU ); \
  435. }
  436. #define vFlip_16( left, right ) \
  437. do { \
  438. uint16_t tmp = ( left ); \
  439. ( left ) = ( right ); \
  440. ( right ) = tmp; \
  441. } while( ipFALSE_BOOL )
  442. #define vFlip_32( left, right ) \
  443. do { \
  444. uint32_t tmp = ( left ); \
  445. ( left ) = ( right ); \
  446. ( right ) = tmp; \
  447. } while( ipFALSE_BOOL )
  448. /* WARNING: Do NOT use this macro when the array was received as a parameter. */
  449. #ifndef ARRAY_SIZE
  450. #define ARRAY_SIZE( x ) ( ( BaseType_t ) ( sizeof( x ) / sizeof( ( x )[ 0 ] ) ) )
  451. #endif
  452. /*
  453. * Create a message that contains a command to initialise the network interface.
  454. * This is used during initialisation, and at any time the network interface
  455. * goes down thereafter. The network interface hardware driver is responsible
  456. * for sending the message that contains the network interface down command/
  457. * event.
  458. *
  459. * Only use the FreeRTOS_NetworkDownFromISR() version if the function is to be
  460. * called from an interrupt service routine. If FreeRTOS_NetworkDownFromISR()
  461. * returns a non-zero value then a context switch should be performed before
  462. * the interrupt is exited.
  463. */
  464. void FreeRTOS_NetworkDown( void );
  465. BaseType_t FreeRTOS_NetworkDownFromISR( void );
  466. /*
  467. * Processes incoming ARP packets.
  468. */
  469. eFrameProcessingResult_t eARPProcessPacket( ARPPacket_t * const pxARPFrame );
  470. /*
  471. * Inspect an Ethernet frame to see if it contains data that the stack needs to
  472. * process. eProcessBuffer is returned if the frame should be processed by the
  473. * stack. eReleaseBuffer is returned if the frame should be discarded.
  474. */
  475. eFrameProcessingResult_t eConsiderFrameForProcessing( const uint8_t * const pucEthernetBuffer );
  476. /*
  477. * Return the checksum generated over xDataLengthBytes from pucNextData.
  478. */
  479. uint16_t usGenerateChecksum( uint16_t usSum,
  480. const uint8_t * pucNextData,
  481. size_t uxByteCount );
  482. /* Socket related private functions. */
  483. /*
  484. * The caller must ensure that pxNetworkBuffer->xDataLength is the UDP packet
  485. * payload size (excluding packet headers) and that the packet in pucEthernetBuffer
  486. * is at least the size of UDPPacket_t.
  487. */
  488. BaseType_t xProcessReceivedUDPPacket( NetworkBufferDescriptor_t * pxNetworkBuffer,
  489. uint16_t usPort );
  490. /*
  491. * Initialize the socket list data structures for TCP and UDP.
  492. */
  493. void vNetworkSocketsInit( void );
  494. /*
  495. * Returns pdTRUE if the IP task has been created and is initialised. Otherwise
  496. * returns pdFALSE.
  497. */
  498. BaseType_t xIPIsNetworkTaskReady( void );
  499. #if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
  500. struct xSOCKET;
  501. typedef void (* SocketWakeupCallback_t)( struct xSOCKET * pxSocket );
  502. #endif
  503. #if ( ipconfigUSE_TCP == 1 )
  504. /*
  505. * Actually a user thing, but because xBoundTCPSocketsList, let it do by the
  506. * IP-task
  507. */
  508. #if ( ipconfigHAS_PRINTF != 0 )
  509. void vTCPNetStat( void );
  510. #endif
  511. /*
  512. * At least one socket needs to check for timeouts
  513. */
  514. TickType_t xTCPTimerCheck( BaseType_t xWillSleep );
  515. /**
  516. * Every TCP socket has a buffer space just big enough to store
  517. * the last TCP header received.
  518. * As a reference of this field may be passed to DMA, force the
  519. * alignment to 8 bytes.
  520. */
  521. typedef union
  522. {
  523. struct
  524. {
  525. uint64_t ullAlignmentWord; /**< Increase the alignment of this union by adding a 64-bit variable. */
  526. } a; /**< A struct to increase alignment. */
  527. struct
  528. {
  529. /* The next field only serves to give 'ucLastPacket' a correct
  530. * alignment of 8 + 2. See comments in FreeRTOS_IP.h */
  531. uint8_t ucFillPacket[ ipconfigPACKET_FILLER_SIZE ];
  532. uint8_t ucLastPacket[ sizeof( TCPPacket_t ) ];
  533. } u; /**< The structure to give an alignment of 8 + 2 */
  534. } LastTCPPacket_t;
  535. /**
  536. * Note that the values of all short and long integers in these structs
  537. * are being stored in the native-endian way
  538. * Translation should take place when accessing any structure which defines
  539. * network packets, such as IPHeader_t and TCPHeader_t
  540. */
  541. typedef struct TCPSOCKET
  542. {
  543. uint32_t ulRemoteIP; /**< IP address of remote machine */
  544. uint16_t usRemotePort; /**< Port on remote machine */
  545. struct
  546. {
  547. /* Most compilers do like bit-flags */
  548. uint32_t
  549. bMssChange : 1, /**< This socket has seen a change in MSS */
  550. bPassAccept : 1, /**< when true, this socket may be returned in a call to accept() */
  551. bPassQueued : 1, /**< when true, this socket is an orphan until it gets connected
  552. * Why an orphan? Because it may not be returned in a accept() call until it
  553. * gets the state eESTABLISHED */
  554. bReuseSocket : 1, /**< When a listening socket gets a connection, do not create a new instance but keep on using it */
  555. bCloseAfterSend : 1, /**< As soon as the last byte has been transmitted, finalise the connection
  556. * Useful in e.g. FTP connections, where the last data bytes are sent along with the FIN flag */
  557. bUserShutdown : 1, /**< User requesting a graceful shutdown */
  558. bCloseRequested : 1, /**< Request to finalise the connection */
  559. bLowWater : 1, /**< high-water level has been reached. Cleared as soon as 'rx-count < lo-water' */
  560. bWinChange : 1, /**< The value of bLowWater has changed, must send a window update */
  561. bSendKeepAlive : 1, /**< When this flag is true, a TCP keep-alive message must be send */
  562. bWaitKeepAlive : 1, /**< When this flag is true, a TCP keep-alive reply is expected */
  563. bConnPrepared : 1, /**< Connecting socket: Message has been prepared */
  564. #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
  565. bConnPassed : 1, /**< Connecting socket: Socket has been passed in a successful select() */
  566. #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
  567. bFinAccepted : 1, /**< This socket has received (or sent) a FIN and accepted it */
  568. bFinSent : 1, /**< We've sent out a FIN */
  569. bFinRecv : 1, /**< We've received a FIN from our peer */
  570. bFinAcked : 1, /**< Our FIN packet has been acked */
  571. bFinLast : 1, /**< The last ACK (after FIN and FIN+ACK) has been sent or will be sent by the peer */
  572. bRxStopped : 1, /**< Application asked to temporarily stop reception */
  573. bMallocError : 1, /**< There was an error allocating a stream */
  574. bWinScaling : 1; /**< A TCP-Window Scaling option was offered and accepted in the SYN phase. */
  575. } bits; /**< The bits structure */
  576. uint32_t ulHighestRxAllowed; /**< The highest sequence number that we can receive at any moment */
  577. uint16_t usTimeout; /**< Time (in ticks) after which this socket needs attention */
  578. uint16_t usCurMSS; /**< Current Maximum Segment Size */
  579. uint16_t usInitMSS; /**< Initial maximum segment Size */
  580. uint16_t usChildCount; /**< In case of a listening socket: number of connections on this port number */
  581. uint16_t usBacklog; /**< In case of a listening socket: maximum number of concurrent connections on this port number */
  582. uint8_t ucRepCount; /**< Send repeat count, for retransmissions
  583. * This counter is separate from the xmitCount in the
  584. * TCP win segments */
  585. uint8_t ucTCPState; /**< TCP state: see eTCP_STATE */
  586. struct xSOCKET * pxPeerSocket; /**< for server socket: child, for child socket: parent */
  587. #if ( ipconfigTCP_KEEP_ALIVE == 1 )
  588. uint8_t ucKeepRepCount;
  589. TickType_t xLastAliveTime; /**< The last value of keepalive time.*/
  590. #endif /* ipconfigTCP_KEEP_ALIVE */
  591. #if ( ipconfigTCP_HANG_PROTECTION == 1 )
  592. TickType_t xLastActTime; /**< The last time when hang-protection was done.*/
  593. #endif /* ipconfigTCP_HANG_PROTECTION */
  594. size_t uxLittleSpace; /**< The value deemed as low amount of space. */
  595. size_t uxEnoughSpace; /**< The value deemed as enough space. */
  596. size_t uxRxStreamSize; /**< The Receive stream size */
  597. size_t uxTxStreamSize; /**< The transmit stream size */
  598. StreamBuffer_t * rxStream; /**< The pointer to the receive stream buffer. */
  599. StreamBuffer_t * txStream; /**< The pointer to the transmit stream buffer. */
  600. #if ( ipconfigUSE_TCP_WIN == 1 )
  601. NetworkBufferDescriptor_t * pxAckMessage; /**< The pointer to the ACK message */
  602. #endif /* ipconfigUSE_TCP_WIN */
  603. LastTCPPacket_t xPacket; /**< Buffer space to store the last TCP header received. */
  604. uint8_t tcpflags; /**< TCP flags */
  605. #if ( ipconfigUSE_TCP_WIN != 0 )
  606. uint8_t ucMyWinScaleFactor; /**< Scaling factor of this device. */
  607. uint8_t ucPeerWinScaleFactor; /**< Scaling factor of the peer. */
  608. #endif
  609. #if ( ipconfigUSE_CALLBACKS == 1 )
  610. FOnTCPReceive_t pxHandleReceive; /**<
  611. * In case of a TCP socket:
  612. * typedef void (* FOnTCPReceive_t) (Socket_t xSocket, void *pData, size_t xLength );
  613. */
  614. FOnTCPSent_t pxHandleSent; /**< Function pointer to handle a successful send event. */
  615. FOnConnected_t pxHandleConnected; /**< Actually type: typedef void (* FOnConnected_t) (Socket_t xSocket, BaseType_t ulConnected ); */
  616. #endif /* ipconfigUSE_CALLBACKS */
  617. uint32_t ulWindowSize; /**< Current Window size advertised by peer */
  618. size_t uxRxWinSize; /**< Fixed value: size of the TCP reception window */
  619. size_t uxTxWinSize; /**< Fixed value: size of the TCP transmit window */
  620. TCPWindow_t xTCPWindow; /**< The TCP window struct*/
  621. } IPTCPSocket_t;
  622. #endif /* ipconfigUSE_TCP */
  623. /**
  624. * Structure to hold the information about a UDP socket.
  625. */
  626. typedef struct UDPSOCKET
  627. {
  628. List_t xWaitingPacketsList; /**< Incoming packets */
  629. #if ( ipconfigUDP_MAX_RX_PACKETS > 0 )
  630. UBaseType_t uxMaxPackets; /**< Protection: limits the number of packets buffered per socket */
  631. #endif /* ipconfigUDP_MAX_RX_PACKETS */
  632. #if ( ipconfigUSE_CALLBACKS == 1 )
  633. FOnUDPReceive_t pxHandleReceive; /**<
  634. * In case of a UDP socket:
  635. * typedef void (* FOnUDPReceive_t) (Socket_t xSocket, void *pData, size_t xLength, struct freertos_sockaddr *pxAddr );
  636. */
  637. FOnUDPSent_t pxHandleSent; /**< Function pointer to handle the events after a successful send. */
  638. #endif /* ipconfigUSE_CALLBACKS */
  639. } IPUDPSocket_t;
  640. /* Formally typedef'd as eSocketEvent_t. */
  641. enum eSOCKET_EVENT
  642. {
  643. eSOCKET_RECEIVE = 0x0001,
  644. eSOCKET_SEND = 0x0002,
  645. eSOCKET_ACCEPT = 0x0004,
  646. eSOCKET_CONNECT = 0x0008,
  647. eSOCKET_BOUND = 0x0010,
  648. eSOCKET_CLOSED = 0x0020,
  649. eSOCKET_INTR = 0x0040,
  650. eSOCKET_ALL = 0x007F,
  651. };
  652. /**
  653. * Structure to hold information for a socket.
  654. */
  655. typedef struct xSOCKET
  656. {
  657. EventBits_t xEventBits; /**< The eventbits to keep track of events. */
  658. EventGroupHandle_t xEventGroup; /**< The event group for this socket. */
  659. ListItem_t xBoundSocketListItem; /**< Used to reference the socket from a bound sockets list. */
  660. TickType_t xReceiveBlockTime; /**< if recv[to] is called while no data is available, wait this amount of time. Unit in clock-ticks */
  661. TickType_t xSendBlockTime; /**< if send[to] is called while there is not enough space to send, wait this amount of time. Unit in clock-ticks */
  662. uint16_t usLocalPort; /**< Local port on this machine */
  663. uint8_t ucSocketOptions; /**< Socket options */
  664. uint8_t ucProtocol; /**< choice of FREERTOS_IPPROTO_UDP/TCP */
  665. #if ( ipconfigSOCKET_HAS_USER_SEMAPHORE == 1 )
  666. SemaphoreHandle_t pxUserSemaphore; /**< The user semaphore */
  667. #endif /* ipconfigSOCKET_HAS_USER_SEMAPHORE */
  668. #if ( ipconfigSOCKET_HAS_USER_WAKE_CALLBACK == 1 )
  669. SocketWakeupCallback_t pxUserWakeCallback; /**< Pointer to the callback function. */
  670. #endif /* ipconfigSOCKET_HAS_USER_WAKE_CALLBACK */
  671. #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
  672. struct xSOCKET_SET * pxSocketSet; /**< Pointer to the socket set structure */
  673. EventBits_t xSelectBits; /**< User may indicate which bits are interesting for this socket. */
  674. EventBits_t xSocketBits; /**< These bits indicate the events which have actually occurred.
  675. * They are maintained by the IP-task */
  676. #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
  677. /* TCP/UDP specific fields: */
  678. /* Before accessing any member of this structure, it should be confirmed */
  679. /* that the protocol corresponds with the type of structure */
  680. union
  681. {
  682. IPUDPSocket_t xUDP; /**< Union member: UDP socket*/
  683. #if ( ipconfigUSE_TCP == 1 )
  684. IPTCPSocket_t xTCP; /**< Union member: TCP socket */
  685. uint64_t ullTCPAlignment; /**< Make sure that xTCP is 8-bytes aligned by
  686. * declaring a 64-bit variable in the same union */
  687. #endif /* ipconfigUSE_TCP */
  688. } u; /**< Union of TCP/UDP socket */
  689. } FreeRTOS_Socket_t;
  690. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t )
  691. {
  692. return ( FreeRTOS_Socket_t * ) pvArgument;
  693. }
  694. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( FreeRTOS_Socket_t )
  695. {
  696. return ( const FreeRTOS_Socket_t * ) pvArgument;
  697. }
  698. #if ( ipconfigUSE_TCP == 1 )
  699. /*
  700. * Lookup a TCP socket, using a multiple matching: both port numbers and
  701. * return IP address.
  702. */
  703. FreeRTOS_Socket_t * pxTCPSocketLookup( uint32_t ulLocalIP,
  704. UBaseType_t uxLocalPort,
  705. uint32_t ulRemoteIP,
  706. UBaseType_t uxRemotePort );
  707. #endif /* ipconfigUSE_TCP */
  708. /*
  709. * Look up a local socket by finding a match with the local port.
  710. */
  711. FreeRTOS_Socket_t * pxUDPSocketLookup( UBaseType_t uxLocalPort );
  712. /*
  713. * Called when the application has generated a UDP packet to send.
  714. */
  715. void vProcessGeneratedUDPPacket( NetworkBufferDescriptor_t * const pxNetworkBuffer );
  716. /*
  717. * Calculate the upper-layer checksum
  718. * Works both for UDP, ICMP and TCP packages
  719. * bOut = true: checksum will be set in outgoing packets
  720. * bOut = false: checksum will be calculated for incoming packets
  721. * returning 0xffff means: checksum was correct
  722. */
  723. uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer,
  724. size_t uxBufferLength,
  725. BaseType_t xOutgoingPacket );
  726. /*
  727. * An Ethernet frame has been updated (maybe it was an ARP request or a PING
  728. * request?) and is to be sent back to its source.
  729. */
  730. void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer,
  731. BaseType_t xReleaseAfterSend );
  732. /*
  733. * The internal version of bind()
  734. * If 'ulInternal' is true, it is called by the driver
  735. * The TCP driver needs to bind a socket at the moment a listening socket
  736. * creates a new connected socket
  737. */
  738. BaseType_t vSocketBind( FreeRTOS_Socket_t * pxSocket,
  739. struct freertos_sockaddr * pxBindAddress,
  740. size_t uxAddressLength,
  741. BaseType_t xInternal );
  742. /*
  743. * Internal function to add streaming data to a TCP socket. If ulIn == true,
  744. * data will be added to the rxStream, otherwise to the tXStream. Normally data
  745. * will be written with ulOffset == 0, meaning: at the end of the FIFO. When
  746. * packet come in out-of-order, an offset will be used to put it in front and
  747. * the head will not change yet.
  748. */
  749. int32_t lTCPAddRxdata( FreeRTOS_Socket_t * pxSocket,
  750. size_t uxOffset,
  751. const uint8_t * pcData,
  752. uint32_t ulByteCount );
  753. /*
  754. * Currently called for any important event.
  755. */
  756. void vSocketWakeUpUser( FreeRTOS_Socket_t * pxSocket );
  757. /*
  758. * Some helping function, their meaning should be clear.
  759. * Going by MISRA rules, these utility functions should not be defined
  760. * if they are not being used anywhere. But their use depends on the
  761. * application and hence these functions are defined unconditionally.
  762. */
  763. static portINLINE uint32_t ulChar2u32( const uint8_t * apChr );
  764. static portINLINE uint32_t ulChar2u32( const uint8_t * apChr )
  765. {
  766. return ( ( ( uint32_t ) apChr[ 0 ] ) << 24 ) |
  767. ( ( ( uint32_t ) apChr[ 1 ] ) << 16 ) |
  768. ( ( ( uint32_t ) apChr[ 2 ] ) << 8 ) |
  769. ( ( ( uint32_t ) apChr[ 3 ] ) );
  770. }
  771. static portINLINE uint16_t usChar2u16( const uint8_t * apChr );
  772. static portINLINE uint16_t usChar2u16( const uint8_t * apChr )
  773. {
  774. return ( uint16_t )
  775. ( ( ( ( uint32_t ) apChr[ 0 ] ) << 8 ) |
  776. ( ( ( uint32_t ) apChr[ 1 ] ) ) );
  777. }
  778. /* Check a single socket for retransmissions and timeouts */
  779. BaseType_t xTCPSocketCheck( FreeRTOS_Socket_t * pxSocket );
  780. BaseType_t xTCPCheckNewClient( FreeRTOS_Socket_t * pxSocket );
  781. /* Defined in FreeRTOS_Sockets.c
  782. * Close a socket
  783. */
  784. void * vSocketClose( FreeRTOS_Socket_t * pxSocket );
  785. /*
  786. * Send the event eEvent to the IP task event queue, using a block time of
  787. * zero. Return pdPASS if the message was sent successfully, otherwise return
  788. * pdFALSE.
  789. */
  790. BaseType_t xSendEventToIPTask( eIPEvent_t eEvent );
  791. /*
  792. * The same as above, but a struct as a parameter, containing:
  793. * eIPEvent_t eEventType;
  794. * void *pvData;
  795. */
  796. BaseType_t xSendEventStructToIPTask( const IPStackEvent_t * pxEvent,
  797. TickType_t uxTimeout );
  798. /*
  799. * Returns a pointer to the original NetworkBuffer from a pointer to a UDP
  800. * payload buffer.
  801. */
  802. NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer );
  803. #if ( ipconfigZERO_COPY_TX_DRIVER != 0 )
  804. /*
  805. * For the case where the network driver passes a buffer directly to a DMA
  806. * descriptor, this function can be used to translate a 'network buffer' to
  807. * a 'network buffer descriptor'.
  808. */
  809. NetworkBufferDescriptor_t * pxPacketBuffer_to_NetworkBuffer( const void * pvBuffer );
  810. #endif
  811. /*
  812. * Internal: Sets a new state for a TCP socket and performs the necessary
  813. * actions like calling a OnConnected handler to notify the socket owner.
  814. */
  815. #if ( ipconfigUSE_TCP == 1 )
  816. void vTCPStateChange( FreeRTOS_Socket_t * pxSocket,
  817. enum eTCP_STATE eTCPState );
  818. #endif /* ipconfigUSE_TCP */
  819. /* Returns pdTRUE is this function is called from the IP-task */
  820. BaseType_t xIsCallingFromIPTask( void );
  821. #if ( ipconfigSUPPORT_SELECT_FUNCTION == 1 )
  822. /** @brief Structure for event groups of the Socket Select functions */
  823. typedef struct xSOCKET_SET
  824. {
  825. /** @brief Event group for the socket select function.
  826. */
  827. EventGroupHandle_t xSelectGroup;
  828. } SocketSelect_t;
  829. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelect_t )
  830. {
  831. return ( SocketSelect_t * ) pvArgument;
  832. }
  833. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelect_t )
  834. {
  835. return ( const SocketSelect_t * ) pvArgument;
  836. }
  837. extern void vSocketSelect( SocketSelect_t * pxSocketSet );
  838. /** @brief Define the data that must be passed for a 'eSocketSelectEvent'. */
  839. typedef struct xSocketSelectMessage
  840. {
  841. TaskHandle_t xTaskhandle; /**< Task handle for use in the socket select functionality. */
  842. SocketSelect_t * pxSocketSet; /**< The event group for the socket select functionality. */
  843. } SocketSelectMessage_t;
  844. static portINLINE ipDECL_CAST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t )
  845. {
  846. return ( SocketSelectMessage_t * ) pvArgument;
  847. }
  848. static portINLINE ipDECL_CAST_CONST_PTR_FUNC_FOR_TYPE( SocketSelectMessage_t )
  849. {
  850. return ( const SocketSelectMessage_t * ) pvArgument;
  851. }
  852. #endif /* ipconfigSUPPORT_SELECT_FUNCTION */
  853. void vIPSetDHCPTimerEnableState( BaseType_t xEnableState );
  854. void vIPReloadDHCPTimer( uint32_t ulLeaseTime );
  855. #if ( ipconfigDNS_USE_CALLBACKS != 0 )
  856. void vIPReloadDNSTimer( uint32_t ulCheckTime );
  857. void vIPSetDnsTimerEnableState( BaseType_t xEnableState );
  858. #endif
  859. /* Send the network-up event and start the ARP timer. */
  860. void vIPNetworkUpCalls( void );
  861. #ifdef __cplusplus
  862. } /* extern "C" */
  863. #endif
  864. #endif /* FREERTOS_IP_PRIVATE_H */