You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Udp4.h 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /** @file
  2. UDP4 Service Binding Protocol as defined in UEFI specification.
  3. The EFI UDPv4 Protocol provides simple packet-oriented services
  4. to transmit and receive UDP packets.
  5. Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
  6. This program and the accompanying materials are licensed and made available under
  7. the terms and conditions of the BSD License that accompanies this distribution.
  8. The full text of the license may be found at
  9. http://opensource.org/licenses/bsd-license.php.
  10. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  12. @par Revision Reference:
  13. This Protocol is introduced in UEFI Specification 2.0.
  14. **/
  15. #ifndef __EFI_UDP4_PROTOCOL_H__
  16. #define __EFI_UDP4_PROTOCOL_H__
  17. FILE_LICENCE ( BSD3 );
  18. #include <ipxe/efi/Protocol/Ip4.h>
  19. //
  20. //GUID definitions
  21. //
  22. #define EFI_UDP4_SERVICE_BINDING_PROTOCOL_GUID \
  23. { \
  24. 0x83f01464, 0x99bd, 0x45e5, {0xb3, 0x83, 0xaf, 0x63, 0x05, 0xd8, 0xe9, 0xe6 } \
  25. }
  26. #define EFI_UDP4_PROTOCOL_GUID \
  27. { \
  28. 0x3ad9df29, 0x4501, 0x478d, {0xb1, 0xf8, 0x7f, 0x7f, 0xe7, 0x0e, 0x50, 0xf3 } \
  29. }
  30. typedef struct _EFI_UDP4_PROTOCOL EFI_UDP4_PROTOCOL;
  31. ///
  32. /// EFI_UDP4_SERVICE_POINT is deprecated in the UEFI 2.4B and should not be used any more.
  33. /// The definition in here is only present to provide backwards compatability.
  34. ///
  35. typedef struct {
  36. EFI_HANDLE InstanceHandle;
  37. EFI_IPv4_ADDRESS LocalAddress;
  38. UINT16 LocalPort;
  39. EFI_IPv4_ADDRESS RemoteAddress;
  40. UINT16 RemotePort;
  41. } EFI_UDP4_SERVICE_POINT;
  42. ///
  43. /// EFI_UDP4_VARIABLE_DATA is deprecated in the UEFI 2.4B and should not be used any more.
  44. /// The definition in here is only present to provide backwards compatability.
  45. ///
  46. typedef struct {
  47. EFI_HANDLE DriverHandle;
  48. UINT32 ServiceCount;
  49. EFI_UDP4_SERVICE_POINT Services[1];
  50. } EFI_UDP4_VARIABLE_DATA;
  51. typedef struct {
  52. UINT32 FragmentLength;
  53. VOID *FragmentBuffer;
  54. } EFI_UDP4_FRAGMENT_DATA;
  55. typedef struct {
  56. EFI_IPv4_ADDRESS SourceAddress;
  57. UINT16 SourcePort;
  58. EFI_IPv4_ADDRESS DestinationAddress;
  59. UINT16 DestinationPort;
  60. } EFI_UDP4_SESSION_DATA;
  61. typedef struct {
  62. //
  63. // Receiving Filters
  64. //
  65. BOOLEAN AcceptBroadcast;
  66. BOOLEAN AcceptPromiscuous;
  67. BOOLEAN AcceptAnyPort;
  68. BOOLEAN AllowDuplicatePort;
  69. //
  70. // I/O parameters
  71. //
  72. UINT8 TypeOfService;
  73. UINT8 TimeToLive;
  74. BOOLEAN DoNotFragment;
  75. UINT32 ReceiveTimeout;
  76. UINT32 TransmitTimeout;
  77. //
  78. // Access Point
  79. //
  80. BOOLEAN UseDefaultAddress;
  81. EFI_IPv4_ADDRESS StationAddress;
  82. EFI_IPv4_ADDRESS SubnetMask;
  83. UINT16 StationPort;
  84. EFI_IPv4_ADDRESS RemoteAddress;
  85. UINT16 RemotePort;
  86. } EFI_UDP4_CONFIG_DATA;
  87. typedef struct {
  88. EFI_UDP4_SESSION_DATA *UdpSessionData; //OPTIONAL
  89. EFI_IPv4_ADDRESS *GatewayAddress; //OPTIONAL
  90. UINT32 DataLength;
  91. UINT32 FragmentCount;
  92. EFI_UDP4_FRAGMENT_DATA FragmentTable[1];
  93. } EFI_UDP4_TRANSMIT_DATA;
  94. typedef struct {
  95. EFI_TIME TimeStamp;
  96. EFI_EVENT RecycleSignal;
  97. EFI_UDP4_SESSION_DATA UdpSession;
  98. UINT32 DataLength;
  99. UINT32 FragmentCount;
  100. EFI_UDP4_FRAGMENT_DATA FragmentTable[1];
  101. } EFI_UDP4_RECEIVE_DATA;
  102. typedef struct {
  103. EFI_EVENT Event;
  104. EFI_STATUS Status;
  105. union {
  106. EFI_UDP4_RECEIVE_DATA *RxData;
  107. EFI_UDP4_TRANSMIT_DATA *TxData;
  108. } Packet;
  109. } EFI_UDP4_COMPLETION_TOKEN;
  110. /**
  111. Reads the current operational settings.
  112. The GetModeData() function copies the current operational settings of this EFI
  113. UDPv4 Protocol instance into user-supplied buffers. This function is used
  114. optionally to retrieve the operational mode data of underlying networks or
  115. drivers.
  116. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  117. @param Udp4ConfigData The pointer to the buffer to receive the current configuration data.
  118. @param Ip4ModeData The pointer to the EFI IPv4 Protocol mode data structure.
  119. @param MnpConfigData The pointer to the managed network configuration data structure.
  120. @param SnpModeData The pointer to the simple network mode data structure.
  121. @retval EFI_SUCCESS The mode data was read.
  122. @retval EFI_NOT_STARTED When Udp4ConfigData is queried, no configuration data is
  123. available because this instance has not been started.
  124. @retval EFI_INVALID_PARAMETER This is NULL.
  125. **/
  126. typedef
  127. EFI_STATUS
  128. (EFIAPI *EFI_UDP4_GET_MODE_DATA)(
  129. IN EFI_UDP4_PROTOCOL *This,
  130. OUT EFI_UDP4_CONFIG_DATA *Udp4ConfigData OPTIONAL,
  131. OUT EFI_IP4_MODE_DATA *Ip4ModeData OPTIONAL,
  132. OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
  133. OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
  134. );
  135. /**
  136. Initializes, changes, or resets the operational parameters for this instance of the EFI UDPv4
  137. Protocol.
  138. The Configure() function is used to do the following:
  139. * Initialize and start this instance of the EFI UDPv4 Protocol.
  140. * Change the filtering rules and operational parameters.
  141. * Reset this instance of the EFI UDPv4 Protocol.
  142. Until these parameters are initialized, no network traffic can be sent or
  143. received by this instance. This instance can be also reset by calling Configure()
  144. with UdpConfigData set to NULL. Once reset, the receiving queue and transmitting
  145. queue are flushed and no traffic is allowed through this instance.
  146. With different parameters in UdpConfigData, Configure() can be used to bind
  147. this instance to specified port.
  148. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  149. @param Udp4ConfigData The pointer to the buffer to receive the current configuration data.
  150. @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
  151. @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
  152. RARP, etc.) is not finished yet.
  153. @retval EFI_INVALID_PARAMETER This is NULL.
  154. @retval EFI_INVALID_PARAMETER UdpConfigData.StationAddress is not a valid unicast IPv4 address.
  155. @retval EFI_INVALID_PARAMETER UdpConfigData.SubnetMask is not a valid IPv4 address mask. The subnet
  156. mask must be contiguous.
  157. @retval EFI_INVALID_PARAMETER UdpConfigData.RemoteAddress is not a valid unicast IPv4 address if it
  158. is not zero.
  159. @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
  160. and must be stopped/reset before it can be reconfigured.
  161. @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
  162. and UdpConfigData.StationPort is already used by
  163. other instance.
  164. @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
  165. EFI UDPv4 Protocol instance.
  166. @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
  167. was not opened.
  168. **/
  169. typedef
  170. EFI_STATUS
  171. (EFIAPI *EFI_UDP4_CONFIGURE)(
  172. IN EFI_UDP4_PROTOCOL *This,
  173. IN EFI_UDP4_CONFIG_DATA *UdpConfigData OPTIONAL
  174. );
  175. /**
  176. Joins and leaves multicast groups.
  177. The Groups() function is used to enable and disable the multicast group
  178. filtering. If the JoinFlag is FALSE and the MulticastAddress is NULL, then all
  179. currently joined groups are left.
  180. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  181. @param JoinFlag Set to TRUE to join a multicast group. Set to FALSE to leave one
  182. or all multicast groups.
  183. @param MulticastAddress The pointer to multicast group address to join or leave.
  184. @retval EFI_SUCCESS The operation completed successfully.
  185. @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
  186. @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
  187. RARP, etc.) is not finished yet.
  188. @retval EFI_OUT_OF_RESOURCES Could not allocate resources to join the group.
  189. @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
  190. - This is NULL.
  191. - JoinFlag is TRUE and MulticastAddress is NULL.
  192. - JoinFlag is TRUE and *MulticastAddress is not
  193. a valid multicast address.
  194. @retval EFI_ALREADY_STARTED The group address is already in the group table (when
  195. JoinFlag is TRUE).
  196. @retval EFI_NOT_FOUND The group address is not in the group table (when JoinFlag is
  197. FALSE).
  198. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  199. **/
  200. typedef
  201. EFI_STATUS
  202. (EFIAPI *EFI_UDP4_GROUPS)(
  203. IN EFI_UDP4_PROTOCOL *This,
  204. IN BOOLEAN JoinFlag,
  205. IN EFI_IPv4_ADDRESS *MulticastAddress OPTIONAL
  206. );
  207. /**
  208. Adds and deletes routing table entries.
  209. The Routes() function adds a route to or deletes a route from the routing table.
  210. Routes are determined by comparing the SubnetAddress with the destination IP
  211. address and arithmetically AND-ing it with the SubnetMask. The gateway address
  212. must be on the same subnet as the configured station address.
  213. The default route is added with SubnetAddress and SubnetMask both set to 0.0.0.0.
  214. The default route matches all destination IP addresses that do not match any
  215. other routes.
  216. A zero GatewayAddress is a nonroute. Packets are sent to the destination IP
  217. address if it can be found in the Address Resolution Protocol (ARP) cache or
  218. on the local subnet. One automatic nonroute entry will be inserted into the
  219. routing table for outgoing packets that are addressed to a local subnet
  220. (gateway address of 0.0.0.0).
  221. Each instance of the EFI UDPv4 Protocol has its own independent routing table.
  222. Instances of the EFI UDPv4 Protocol that use the default IP address will also
  223. have copies of the routing table provided by the EFI_IP4_CONFIG_PROTOCOL. These
  224. copies will be updated automatically whenever the IP driver reconfigures its
  225. instances; as a result, the previous modification to these copies will be lost.
  226. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  227. @param DeleteRoute Set to TRUE to delete this route from the routing table.
  228. Set to FALSE to add this route to the routing table.
  229. @param SubnetAddress The destination network address that needs to be routed.
  230. @param SubnetMask The subnet mask of SubnetAddress.
  231. @param GatewayAddress The gateway IP address for this route.
  232. @retval EFI_SUCCESS The operation completed successfully.
  233. @retval EFI_NOT_STARTED The EFI UDPv4 Protocol instance has not been started.
  234. @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
  235. - RARP, etc.) is not finished yet.
  236. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  237. @retval EFI_OUT_OF_RESOURCES Could not add the entry to the routing table.
  238. @retval EFI_NOT_FOUND This route is not in the routing table.
  239. @retval EFI_ACCESS_DENIED The route is already defined in the routing table.
  240. **/
  241. typedef
  242. EFI_STATUS
  243. (EFIAPI *EFI_UDP4_ROUTES)(
  244. IN EFI_UDP4_PROTOCOL *This,
  245. IN BOOLEAN DeleteRoute,
  246. IN EFI_IPv4_ADDRESS *SubnetAddress,
  247. IN EFI_IPv4_ADDRESS *SubnetMask,
  248. IN EFI_IPv4_ADDRESS *GatewayAddress
  249. );
  250. /**
  251. Polls for incoming data packets and processes outgoing data packets.
  252. The Poll() function can be used by network drivers and applications to increase
  253. the rate that data packets are moved between the communications device and the
  254. transmit and receive queues.
  255. In some systems, the periodic timer event in the managed network driver may not
  256. poll the underlying communications device fast enough to transmit and/or receive
  257. all data packets without missing incoming packets or dropping outgoing packets.
  258. Drivers and applications that are experiencing packet loss should try calling
  259. the Poll() function more often.
  260. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  261. @retval EFI_SUCCESS Incoming or outgoing data was processed.
  262. @retval EFI_INVALID_PARAMETER This is NULL.
  263. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  264. @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive queue.
  265. **/
  266. typedef
  267. EFI_STATUS
  268. (EFIAPI *EFI_UDP4_POLL)(
  269. IN EFI_UDP4_PROTOCOL *This
  270. );
  271. /**
  272. Places an asynchronous receive request into the receiving queue.
  273. The Receive() function places a completion token into the receive packet queue.
  274. This function is always asynchronous.
  275. The caller must fill in the Token.Event field in the completion token, and this
  276. field cannot be NULL. When the receive operation completes, the EFI UDPv4 Protocol
  277. driver updates the Token.Status and Token.Packet.RxData fields and the Token.Event
  278. is signaled. Providing a proper notification function and context for the event
  279. will enable the user to receive the notification and receiving status. That
  280. notification function is guaranteed to not be re-entered.
  281. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  282. @param Token The pointer to a token that is associated with the receive data
  283. descriptor.
  284. @retval EFI_SUCCESS The receive completion token was cached.
  285. @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
  286. @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP, RARP, etc.)
  287. is not finished yet.
  288. @retval EFI_INVALID_PARAMETER This is NULL.
  289. @retval EFI_INVALID_PARAMETER Token is NULL.
  290. @retval EFI_INVALID_PARAMETER Token.Event is NULL.
  291. @retval EFI_OUT_OF_RESOURCES The receive completion token could not be queued due to a lack of system
  292. resources (usually memory).
  293. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  294. @retval EFI_ACCESS_DENIED A receive completion token with the same Token.Event was already in
  295. the receive queue.
  296. @retval EFI_NOT_READY The receive request could not be queued because the receive queue is full.
  297. **/
  298. typedef
  299. EFI_STATUS
  300. (EFIAPI *EFI_UDP4_RECEIVE)(
  301. IN EFI_UDP4_PROTOCOL *This,
  302. IN EFI_UDP4_COMPLETION_TOKEN *Token
  303. );
  304. /**
  305. Queues outgoing data packets into the transmit queue.
  306. The Transmit() function places a sending request to this instance of the EFI
  307. UDPv4 Protocol, alongside the transmit data that was filled by the user. Whenever
  308. the packet in the token is sent out or some errors occur, the Token.Event will
  309. be signaled and Token.Status is updated. Providing a proper notification function
  310. and context for the event will enable the user to receive the notification and
  311. transmitting status.
  312. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  313. @param Token The pointer to the completion token that will be placed into the
  314. transmit queue.
  315. @retval EFI_SUCCESS The data has been queued for transmission.
  316. @retval EFI_NOT_STARTED This EFI UDPv4 Protocol instance has not been started.
  317. @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
  318. RARP, etc.) is not finished yet.
  319. @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  320. @retval EFI_ACCESS_DENIED The transmit completion token with the same
  321. Token.Event was already in the transmit queue.
  322. @retval EFI_NOT_READY The completion token could not be queued because the
  323. transmit queue is full.
  324. @retval EFI_OUT_OF_RESOURCES Could not queue the transmit data.
  325. @retval EFI_NOT_FOUND There is no route to the destination network or address.
  326. @retval EFI_BAD_BUFFER_SIZE The data length is greater than the maximum UDP packet
  327. size. Or the length of the IP header + UDP header + data
  328. length is greater than MTU if DoNotFragment is TRUE.
  329. **/
  330. typedef
  331. EFI_STATUS
  332. (EFIAPI *EFI_UDP4_TRANSMIT)(
  333. IN EFI_UDP4_PROTOCOL *This,
  334. IN EFI_UDP4_COMPLETION_TOKEN *Token
  335. );
  336. /**
  337. Aborts an asynchronous transmit or receive request.
  338. The Cancel() function is used to abort a pending transmit or receive request.
  339. If the token is in the transmit or receive request queues, after calling this
  340. function, Token.Status will be set to EFI_ABORTED and then Token.Event will be
  341. signaled. If the token is not in one of the queues, which usually means that
  342. the asynchronous operation has completed, this function will not signal the
  343. token and EFI_NOT_FOUND is returned.
  344. @param This The pointer to the EFI_UDP4_PROTOCOL instance.
  345. @param Token The pointer to a token that has been issued by
  346. EFI_UDP4_PROTOCOL.Transmit() or
  347. EFI_UDP4_PROTOCOL.Receive().If NULL, all pending
  348. tokens are aborted.
  349. @retval EFI_SUCCESS The asynchronous I/O request was aborted and Token.Event
  350. was signaled. When Token is NULL, all pending requests are
  351. aborted and their events are signaled.
  352. @retval EFI_INVALID_PARAMETER This is NULL.
  353. @retval EFI_NOT_STARTED This instance has not been started.
  354. @retval EFI_NO_MAPPING When using the default address, configuration (DHCP, BOOTP,
  355. RARP, etc.) is not finished yet.
  356. @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O request was
  357. not found in the transmit or receive queue. It has either completed
  358. or was not issued by Transmit() and Receive().
  359. **/
  360. typedef
  361. EFI_STATUS
  362. (EFIAPI *EFI_UDP4_CANCEL)(
  363. IN EFI_UDP4_PROTOCOL *This,
  364. IN EFI_UDP4_COMPLETION_TOKEN *Token OPTIONAL
  365. );
  366. ///
  367. /// The EFI_UDP4_PROTOCOL defines an EFI UDPv4 Protocol session that can be used
  368. /// by any network drivers, applications, or daemons to transmit or receive UDP packets.
  369. /// This protocol instance can either be bound to a specified port as a service or
  370. /// connected to some remote peer as an active client. Each instance has its own settings,
  371. /// such as the routing table and group table, which are independent from each other.
  372. ///
  373. struct _EFI_UDP4_PROTOCOL {
  374. EFI_UDP4_GET_MODE_DATA GetModeData;
  375. EFI_UDP4_CONFIGURE Configure;
  376. EFI_UDP4_GROUPS Groups;
  377. EFI_UDP4_ROUTES Routes;
  378. EFI_UDP4_TRANSMIT Transmit;
  379. EFI_UDP4_RECEIVE Receive;
  380. EFI_UDP4_CANCEL Cancel;
  381. EFI_UDP4_POLL Poll;
  382. };
  383. extern EFI_GUID gEfiUdp4ServiceBindingProtocolGuid;
  384. extern EFI_GUID gEfiUdp4ProtocolGuid;
  385. #endif