Ip4If.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /** @file
  2. Definition for IP4 pseudo interface structure.
  3. Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_IP4_IF_H__
  7. #define __EFI_IP4_IF_H__
  8. #define IP4_FRAME_RX_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'R')
  9. #define IP4_FRAME_TX_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'T')
  10. #define IP4_FRAME_ARP_SIGNATURE SIGNATURE_32 ('I', 'P', 'F', 'A')
  11. #define IP4_INTERFACE_SIGNATURE SIGNATURE_32 ('I', 'P', 'I', 'F')
  12. /**
  13. This prototype is used by both receive and transmission.
  14. When receiving Netbuf is allocated by IP4_INTERFACE, and
  15. released by IP4. Flag shows whether the frame is received
  16. as link broadcast/multicast...
  17. When transmitting, the Netbuf is from IP4, and provided
  18. to the callback as a reference. Flag isn't used.
  19. @param[in] IpInstance The instance that sent or received the packet.
  20. IpInstance can be NULL which means that it is the IP4 driver
  21. itself sending the packets. IP4 driver may send packets that
  22. don't belong to any instance, such as ICMP errors, ICMP echo
  23. responses, or IGMP packets. IpInstance is used as a tag in
  24. this module.
  25. @param[in] Packet The sent or received packet.
  26. @param[in] IoStatus Status of sending or receiving.
  27. @param[in] LinkFlag Indicate if the frame is received as link broadcast/multicast.
  28. When transmitting, it is not used.
  29. @param[in] Context Additional data for callback.
  30. @retval None.
  31. **/
  32. typedef
  33. VOID
  34. (*IP4_FRAME_CALLBACK)(
  35. IN IP4_PROTOCOL *IpInstance OPTIONAL,
  36. IN NET_BUF *Packet,
  37. IN EFI_STATUS IoStatus,
  38. IN UINT32 LinkFlag,
  39. IN VOID *Context
  40. );
  41. ///
  42. /// Each receive request is wrapped in an IP4_LINK_RX_TOKEN.
  43. /// Upon completion, the Callback will be called. Only one
  44. /// receive request is send to MNP. IpInstance is always NULL.
  45. /// Reference MNP's spec for information.
  46. ///
  47. typedef struct {
  48. UINT32 Signature;
  49. IP4_INTERFACE *Interface;
  50. IP4_PROTOCOL *IpInstance;
  51. IP4_FRAME_CALLBACK CallBack;
  52. VOID *Context;
  53. EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
  54. } IP4_LINK_RX_TOKEN;
  55. ///
  56. /// Each transmit request is wrapped in an IP4_LINK_TX_TOKEN.
  57. /// Upon completion, the Callback will be called.
  58. ///
  59. typedef struct {
  60. UINT32 Signature;
  61. LIST_ENTRY Link;
  62. IP4_INTERFACE *Interface;
  63. IP4_SERVICE *IpSb;
  64. IP4_PROTOCOL *IpInstance;
  65. IP4_FRAME_CALLBACK CallBack;
  66. NET_BUF *Packet;
  67. VOID *Context;
  68. EFI_MAC_ADDRESS DstMac;
  69. EFI_MAC_ADDRESS SrcMac;
  70. EFI_MANAGED_NETWORK_COMPLETION_TOKEN MnpToken;
  71. EFI_MANAGED_NETWORK_TRANSMIT_DATA MnpTxData;
  72. } IP4_LINK_TX_TOKEN;
  73. ///
  74. /// Only one ARP request is requested for all the frames in
  75. /// a time. It is started for the first frames to the Ip. Any
  76. /// subsequent transmission frame will be linked to Frames, and
  77. /// be sent all at once the ARP requests succeed.
  78. ///
  79. typedef struct {
  80. UINT32 Signature;
  81. LIST_ENTRY Link;
  82. LIST_ENTRY Frames;
  83. IP4_INTERFACE *Interface;
  84. //
  85. // ARP requesting staffs
  86. //
  87. EFI_EVENT OnResolved;
  88. IP4_ADDR Ip;
  89. EFI_MAC_ADDRESS Mac;
  90. } IP4_ARP_QUE;
  91. /**
  92. Callback to select which frame to cancel. Caller can cancel a
  93. single frame, or all the frame from an IP instance.
  94. @param Frame The sending frame to check for cancellation.
  95. @param Context Additional data for callback.
  96. @retval TRUE The sending of the frame should be cancelled.
  97. @retval FALSE Do not cancel the frame sending.
  98. **/
  99. typedef
  100. BOOLEAN
  101. (*IP4_FRAME_TO_CANCEL)(
  102. IP4_LINK_TX_TOKEN *Frame,
  103. VOID *Context
  104. );
  105. //
  106. // Each IP4 instance has its own station address. All the instances
  107. // with the same station address share a single interface structure.
  108. // Each interface has its own ARP child, and shares one MNP child.
  109. // Notice the special cases that DHCP can configure the interface
  110. // with 0.0.0.0/0.0.0.0.
  111. //
  112. struct _IP4_INTERFACE {
  113. UINT32 Signature;
  114. LIST_ENTRY Link;
  115. INTN RefCnt;
  116. //
  117. // IP address and subnet mask of the interface. It also contains
  118. // the subnet/net broadcast address for quick access. The fields
  119. // are invalid if (Configured == FALSE)
  120. //
  121. IP4_ADDR Ip;
  122. IP4_ADDR SubnetMask;
  123. IP4_ADDR SubnetBrdcast;
  124. IP4_ADDR NetBrdcast;
  125. BOOLEAN Configured;
  126. //
  127. // Handle used to create/destroy ARP child. All the IP children
  128. // share one MNP which is owned by IP service binding.
  129. //
  130. EFI_HANDLE Controller;
  131. EFI_HANDLE Image;
  132. EFI_MANAGED_NETWORK_PROTOCOL *Mnp;
  133. EFI_ARP_PROTOCOL *Arp;
  134. EFI_HANDLE ArpHandle;
  135. //
  136. // Queues to keep the frames sent and waiting ARP request.
  137. //
  138. LIST_ENTRY ArpQues;
  139. LIST_ENTRY SentFrames;
  140. IP4_LINK_RX_TOKEN *RecvRequest;
  141. //
  142. // The interface's MAC and broadcast MAC address.
  143. //
  144. EFI_MAC_ADDRESS Mac;
  145. EFI_MAC_ADDRESS BroadcastMac;
  146. UINT32 HwaddrLen;
  147. //
  148. // All the IP instances that have the same IP/SubnetMask are linked
  149. // together through IpInstances. If any of the instance enables
  150. // promiscuous receive, PromiscRecv is true.
  151. //
  152. LIST_ENTRY IpInstances;
  153. BOOLEAN PromiscRecv;
  154. };
  155. /**
  156. Create an IP4_INTERFACE. Delay the creation of ARP instance until
  157. the interface is configured.
  158. @param[in] Mnp The shared MNP child of this IP4 service binding
  159. instance.
  160. @param[in] Controller The controller this IP4 service binding instance
  161. is installed. Most like the UNDI handle.
  162. @param[in] ImageHandle This driver's image handle.
  163. @return Point to the created IP4_INTERFACE, otherwise NULL.
  164. **/
  165. IP4_INTERFACE *
  166. Ip4CreateInterface (
  167. IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp,
  168. IN EFI_HANDLE Controller,
  169. IN EFI_HANDLE ImageHandle
  170. );
  171. /**
  172. Set the interface's address, create and configure
  173. the ARP child if necessary.
  174. @param Interface The interface to set the address.
  175. @param IpAddr The interface's IP address.
  176. @param SubnetMask The interface's netmask.
  177. @retval EFI_SUCCESS The interface is configured with Ip/netmask pair,
  178. and a ARP is created for it.
  179. @retval Others Failed to set the interface's address.
  180. **/
  181. EFI_STATUS
  182. Ip4SetAddress (
  183. IN OUT IP4_INTERFACE *Interface,
  184. IN IP4_ADDR IpAddr,
  185. IN IP4_ADDR SubnetMask
  186. );
  187. /**
  188. Free the interface used by IpInstance. All the IP instance with
  189. the same Ip/Netmask pair share the same interface. It is reference
  190. counted. All the frames haven't been sent will be cancelled.
  191. Because the IpInstance is optional, the caller must remove
  192. IpInstance from the interface's instance list itself.
  193. @param[in] Interface The interface used by the IpInstance.
  194. @param[in] IpInstance The Ip instance that free the interface. NULL if
  195. the Ip driver is releasing the default interface.
  196. @retval EFI_SUCCESS The interface use IpInstance is freed.
  197. **/
  198. EFI_STATUS
  199. Ip4FreeInterface (
  200. IN IP4_INTERFACE *Interface,
  201. IN IP4_PROTOCOL *IpInstance OPTIONAL
  202. );
  203. /**
  204. Send a frame from the interface. If the next hop is broadcast or
  205. multicast address, it is transmitted immediately. If the next hop
  206. is a unicast, it will consult ARP to resolve the NextHop's MAC.
  207. If some error happened, the CallBack won't be called. So, the caller
  208. must test the return value, and take action when there is an error.
  209. @param[in] Interface The interface to send the frame from
  210. @param[in] IpInstance The IP child that request the transmission. NULL
  211. if it is the IP4 driver itself.
  212. @param[in] Packet The packet to transmit.
  213. @param[in] NextHop The immediate destination to transmit the packet
  214. to.
  215. @param[in] CallBack Function to call back when transmit finished.
  216. @param[in] Context Opaque parameter to the call back.
  217. @param[in] IpSb The pointer to the IP4 service binding instance.
  218. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to send the frame
  219. @retval EFI_NO_MAPPING Can't resolve the MAC for the nexthop
  220. @retval EFI_SUCCESS The packet is successfully transmitted.
  221. @retval other Other error occurs.
  222. **/
  223. EFI_STATUS
  224. Ip4SendFrame (
  225. IN IP4_INTERFACE *Interface,
  226. IN IP4_PROTOCOL *IpInstance OPTIONAL,
  227. IN NET_BUF *Packet,
  228. IN IP4_ADDR NextHop,
  229. IN IP4_FRAME_CALLBACK CallBack,
  230. IN VOID *Context,
  231. IN IP4_SERVICE *IpSb
  232. );
  233. /**
  234. Remove all the frames on the interface that pass the FrameToCancel,
  235. either queued on ARP queues or that have already been delivered to
  236. MNP and not yet recycled.
  237. @param[in] Interface Interface to remove the frames from.
  238. @param[in] IoStatus The transmit status returned to the frames'
  239. callback.
  240. @param[in] FrameToCancel Function to select the frame to cancel, NULL to
  241. select all.
  242. @param[in] Context Opaque parameters passed to FrameToCancel.
  243. **/
  244. VOID
  245. Ip4CancelFrames (
  246. IN IP4_INTERFACE *Interface,
  247. IN EFI_STATUS IoStatus,
  248. IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL,
  249. IN VOID *Context
  250. );
  251. /**
  252. If there is a pending receive request, cancel it. Don't call
  253. the receive request's callback because this function can be only
  254. called if the instance or driver is tearing itself down. It
  255. doesn't make sense to call it back. But it is necessary to call
  256. the transmit token's callback to give it a chance to free the
  257. packet and update the upper layer's transmit request status, say
  258. that from the UDP.
  259. @param[in] Interface The interface used by the IpInstance
  260. **/
  261. VOID
  262. Ip4CancelReceive (
  263. IN IP4_INTERFACE *Interface
  264. );
  265. /**
  266. Request to receive the packet from the interface.
  267. @param[in] Interface The interface to receive the frames from.
  268. @param[in] IpInstance The instance that requests the receive. NULL for
  269. the driver itself.
  270. @param[in] CallBack Function to call when receive finished.
  271. @param[in] Context Opaque parameter to the callback.
  272. @retval EFI_ALREADY_STARTED There is already a pending receive request.
  273. @retval EFI_OUT_OF_RESOURCES Failed to allocate resource to receive.
  274. @retval EFI_SUCCESS The receive request has been started.
  275. @retval other Other error occurs.
  276. **/
  277. EFI_STATUS
  278. Ip4ReceiveFrame (
  279. IN IP4_INTERFACE *Interface,
  280. IN IP4_PROTOCOL *IpInstance OPTIONAL,
  281. IN IP4_FRAME_CALLBACK CallBack,
  282. IN VOID *Context
  283. );
  284. #endif