PxeBcSupport.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /** @file
  2. Support functions declaration for UefiPxeBc Driver.
  3. Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef __EFI_PXEBC_SUPPORT_H__
  7. #define __EFI_PXEBC_SUPPORT_H__
  8. #define ICMP_DEST_UNREACHABLE 3
  9. #define ICMP_SOURCE_QUENCH 4
  10. #define ICMP_REDIRECT 5
  11. #define ICMP_ECHO_REQUEST 8
  12. #define ICMP_TIME_EXCEEDED 11
  13. #define ICMP_PARAMETER_PROBLEM 12
  14. /**
  15. Flush the previous configuration using the new station Ip address.
  16. @param[in] Private Pointer to PxeBc private data.
  17. @param[in] StationIp Pointer to the station Ip address.
  18. @param[in] SubnetMask Pointer to the subnet mask address for v4.
  19. @retval EFI_SUCCESS Successfully flushed the previous config.
  20. @retval Others Failed to flush using the new station Ip.
  21. **/
  22. EFI_STATUS
  23. PxeBcFlushStationIp (
  24. PXEBC_PRIVATE_DATA *Private,
  25. EFI_IP_ADDRESS *StationIp OPTIONAL,
  26. EFI_IP_ADDRESS *SubnetMask OPTIONAL
  27. );
  28. /**
  29. Notify callback function when an event is triggered.
  30. @param[in] Event The triggered event.
  31. @param[in] Context The opaque parameter to the function.
  32. **/
  33. VOID
  34. EFIAPI
  35. PxeBcCommonNotify (
  36. IN EFI_EVENT Event,
  37. IN VOID *Context
  38. );
  39. /**
  40. Perform arp resolution from the arp cache in PxeBcMode.
  41. @param Mode Pointer to EFI_PXE_BASE_CODE_MODE.
  42. @param Ip4Addr The Ip4 address for resolution.
  43. @param MacAddress The resolved MAC address if the resolution is successful.
  44. The value is undefined if resolution fails.
  45. @retval TRUE Found a matched entry.
  46. @retval FALSE Did not find a matched entry.
  47. **/
  48. BOOLEAN
  49. PxeBcCheckArpCache (
  50. IN EFI_PXE_BASE_CODE_MODE *Mode,
  51. IN EFI_IPv4_ADDRESS *Ip4Addr,
  52. OUT EFI_MAC_ADDRESS *MacAddress
  53. );
  54. /**
  55. Update arp cache periodically.
  56. @param Event Pointer to EFI_PXE_BC_PROTOCOL.
  57. @param Context Context of the timer event.
  58. **/
  59. VOID
  60. EFIAPI
  61. PxeBcArpCacheUpdate (
  62. IN EFI_EVENT Event,
  63. IN VOID *Context
  64. );
  65. /**
  66. xxx
  67. @param Event The event signaled.
  68. @param Context The context passed in by the event notifier.
  69. **/
  70. VOID
  71. EFIAPI
  72. PxeBcIcmpErrorUpdate (
  73. IN EFI_EVENT Event,
  74. IN VOID *Context
  75. );
  76. /**
  77. xxx
  78. @param Event The event signaled.
  79. @param Context The context passed in by the event notifier.
  80. **/
  81. VOID
  82. EFIAPI
  83. PxeBcIcmp6ErrorUpdate (
  84. IN EFI_EVENT Event,
  85. IN VOID *Context
  86. );
  87. /**
  88. This function is to configure a UDPv4 instance for UdpWrite.
  89. @param[in] Udp4 The pointer to EFI_UDP4_PROTOCOL.
  90. @param[in] StationIp The pointer to the station address.
  91. @param[in] SubnetMask The pointer to the subnet mask.
  92. @param[in] Gateway The pointer to the gateway address.
  93. @param[in, out] SrcPort The pointer to the source port.
  94. @param[in] DoNotFragment If TRUE, fragment is not enabled.
  95. Otherwise, fragment is enabled.
  96. @param[in] Ttl The time to live field of the IP header.
  97. @param[in] ToS The type of service field of the IP header.
  98. @retval EFI_SUCCESS Successfully configured this instance.
  99. @retval Others Failed to configure this instance.
  100. **/
  101. EFI_STATUS
  102. PxeBcConfigUdp4Write (
  103. IN EFI_UDP4_PROTOCOL *Udp4,
  104. IN EFI_IPv4_ADDRESS *StationIp,
  105. IN EFI_IPv4_ADDRESS *SubnetMask,
  106. IN EFI_IPv4_ADDRESS *Gateway,
  107. IN OUT UINT16 *SrcPort,
  108. IN BOOLEAN DoNotFragment,
  109. IN UINT8 Ttl,
  110. IN UINT8 ToS
  111. );
  112. /**
  113. This function is to configure a UDPv6 instance for UdpWrite.
  114. @param[in] Udp6 Pointer to EFI_UDP6_PROTOCOL.
  115. @param[in] StationIp Pointer to the station address.
  116. @param[in, out] SrcPort Pointer to the source port.
  117. @retval EFI_SUCCESS Successfully configured this instance.
  118. @retval Others Failed to configure this instance.
  119. **/
  120. EFI_STATUS
  121. PxeBcConfigUdp6Write (
  122. IN EFI_UDP6_PROTOCOL *Udp6,
  123. IN EFI_IPv6_ADDRESS *StationIp,
  124. IN OUT UINT16 *SrcPort
  125. );
  126. /**
  127. This function is to configure a UDPv4 instance for UdpWrite.
  128. @param[in] Udp4 Pointer to EFI_UDP4_PROTOCOL.
  129. @param[in] Session Pointer to the UDP4 session data.
  130. @param[in] TimeoutEvent The event for timeout.
  131. @param[in] Gateway Pointer to the gateway address.
  132. @param[in] HeaderSize An optional field which may be set to the length of a header
  133. at HeaderPtr to be prefixed to the data at BufferPtr.
  134. @param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
  135. prefixed to the data at BufferPtr.
  136. @param[in] BufferSize A pointer to the size of the data at BufferPtr.
  137. @param[in] BufferPtr A pointer to the data to be written.
  138. @retval EFI_SUCCESS Successfully sent out data with Udp4Write.
  139. @retval Others Failed to send out data.
  140. **/
  141. EFI_STATUS
  142. PxeBcUdp4Write (
  143. IN EFI_UDP4_PROTOCOL *Udp4,
  144. IN EFI_UDP4_SESSION_DATA *Session,
  145. IN EFI_EVENT TimeoutEvent,
  146. IN EFI_IPv4_ADDRESS *Gateway OPTIONAL,
  147. IN UINTN *HeaderSize OPTIONAL,
  148. IN VOID *HeaderPtr OPTIONAL,
  149. IN UINTN *BufferSize,
  150. IN VOID *BufferPtr
  151. );
  152. /**
  153. This function is to configure a UDPv6 instance for UdpWrite.
  154. @param[in] Udp6 Pointer to EFI_UDP6_PROTOCOL.
  155. @param[in] Session Pointer to the UDP6 session data.
  156. @param[in] TimeoutEvent The event for timeout.
  157. @param[in] HeaderSize An optional field which may be set to the length of a header
  158. at HeaderPtr to be prefixed to the data at BufferPtr.
  159. @param[in] HeaderPtr If HeaderSize is not NULL, a pointer to a header to be
  160. prefixed to the data at BufferPtr.
  161. @param[in] BufferSize A pointer to the size of the data at BufferPtr.
  162. @param[in] BufferPtr A pointer to the data to be written.
  163. @retval EFI_SUCCESS Successfully to send out data with Udp6Write.
  164. @retval Others Failed to send out data.
  165. **/
  166. EFI_STATUS
  167. PxeBcUdp6Write (
  168. IN EFI_UDP6_PROTOCOL *Udp6,
  169. IN EFI_UDP6_SESSION_DATA *Session,
  170. IN EFI_EVENT TimeoutEvent,
  171. IN UINTN *HeaderSize OPTIONAL,
  172. IN VOID *HeaderPtr OPTIONAL,
  173. IN UINTN *BufferSize,
  174. IN VOID *BufferPtr
  175. );
  176. /**
  177. Check the received packet with the Ip filter.
  178. @param[in] Mode Pointer to mode data of PxeBc.
  179. @param[in] Session Pointer to the current UDPv4 session.
  180. @param[in] OpFlags Operation flag for UdpRead/UdpWrite.
  181. @retval TRUE Successfully passed the Ip filter.
  182. @retval FALSE Failed to pass the Ip filter.
  183. **/
  184. BOOLEAN
  185. PxeBcCheckByIpFilter (
  186. IN EFI_PXE_BASE_CODE_MODE *Mode,
  187. IN VOID *Session,
  188. IN UINT16 OpFlags
  189. );
  190. /**
  191. Filter the received packet with the destination Ip.
  192. @param[in] Mode Pointer to mode data of PxeBc.
  193. @param[in] Session Pointer to the current UDPv4 session.
  194. @param[in, out] DestIp Pointer to the dest Ip address.
  195. @param[in] OpFlags Operation flag for UdpRead/UdpWrite.
  196. @retval TRUE Successfully passed the IPv4 filter.
  197. @retval FALSE Failed to pass the IPv4 filter.
  198. **/
  199. BOOLEAN
  200. PxeBcCheckByDestIp (
  201. IN EFI_PXE_BASE_CODE_MODE *Mode,
  202. IN VOID *Session,
  203. IN OUT EFI_IP_ADDRESS *DestIp,
  204. IN UINT16 OpFlags
  205. );
  206. /**
  207. Check the received packet with the destination port.
  208. @param[in] Mode Pointer to mode data of PxeBc.
  209. @param[in] Session Pointer to the current UDPv4 session.
  210. @param[in, out] DestPort Pointer to the destination port.
  211. @param[in] OpFlags Operation flag for UdpRead/UdpWrite.
  212. @retval TRUE Successfully passed the IPv4 filter.
  213. @retval FALSE Failed to pass the IPv4 filter.
  214. **/
  215. BOOLEAN
  216. PxeBcCheckByDestPort (
  217. IN EFI_PXE_BASE_CODE_MODE *Mode,
  218. IN VOID *Session,
  219. IN OUT UINT16 *DestPort,
  220. IN UINT16 OpFlags
  221. );
  222. /**
  223. Filter the received packet with the source Ip.
  224. @param[in] Mode Pointer to mode data of PxeBc.
  225. @param[in] Session Pointer to the current UDPv4 session.
  226. @param[in, out] SrcIp Pointer to the source Ip address.
  227. @param[in] OpFlags Operation flag for UdpRead/UdpWrite.
  228. @retval TRUE Successfully passed the IPv4 filter.
  229. @retval FALSE Failed to pass the IPv4 filter.
  230. **/
  231. BOOLEAN
  232. PxeBcFilterBySrcIp (
  233. IN EFI_PXE_BASE_CODE_MODE *Mode,
  234. IN VOID *Session,
  235. IN OUT EFI_IP_ADDRESS *SrcIp,
  236. IN UINT16 OpFlags
  237. );
  238. /**
  239. Filter the received packet with the source port.
  240. @param[in] Mode Pointer to mode data of PxeBc.
  241. @param[in] Session Pointer to the current UDPv4 session.
  242. @param[in, out] SrcPort Pointer to the source port.
  243. @param[in] OpFlags Operation flag for UdpRead/UdpWrite.
  244. @retval TRUE Successfully passed the IPv4 filter.
  245. @retval FALSE Failed to pass the IPv4 filter.
  246. **/
  247. BOOLEAN
  248. PxeBcFilterBySrcPort (
  249. IN EFI_PXE_BASE_CODE_MODE *Mode,
  250. IN VOID *Session,
  251. IN OUT UINT16 *SrcPort,
  252. IN UINT16 OpFlags
  253. );
  254. /**
  255. This function is to receive packet with Udp4Read.
  256. @param[in] Udp4 Pointer to EFI_UDP4_PROTOCOL.
  257. @param[in] Token Pointer to EFI_UDP4_COMPLETION_TOKEN.
  258. @param[in] Mode Pointer to EFI_PXE_BASE_CODE_MODE.
  259. @param[in] TimeoutEvent The event for timeout.
  260. @param[in] OpFlags The UDP operation flags.
  261. @param[in] IsDone Pointer to IsDone flag.
  262. @param[out] IsMatched Pointer to IsMatched flag.
  263. @param[in, out] DestIp Pointer to destination address.
  264. @param[in, out] DestPort Pointer to destination port.
  265. @param[in, out] SrcIp Pointer to source address.
  266. @param[in, out] SrcPort Pointer to source port.
  267. @retval EFI_SUCCESS Successfully read data with Udp4.
  268. @retval Others Failed to send out data.
  269. **/
  270. EFI_STATUS
  271. PxeBcUdp4Read (
  272. IN EFI_UDP4_PROTOCOL *Udp4,
  273. IN EFI_UDP4_COMPLETION_TOKEN *Token,
  274. IN EFI_PXE_BASE_CODE_MODE *Mode,
  275. IN EFI_EVENT TimeoutEvent,
  276. IN UINT16 OpFlags,
  277. IN BOOLEAN *IsDone,
  278. OUT BOOLEAN *IsMatched,
  279. IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,
  280. IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,
  281. IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,
  282. IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL
  283. );
  284. /**
  285. This function is to receive packet with Udp6Read.
  286. @param[in] Udp6 Pointer to EFI_UDP6_PROTOCOL.
  287. @param[in] Token Pointer to EFI_UDP6_COMPLETION_TOKEN.
  288. @param[in] Mode Pointer to EFI_PXE_BASE_CODE_MODE.
  289. @param[in] TimeoutEvent The event for timeout.
  290. @param[in] OpFlags The UDP operation flags.
  291. @param[in] IsDone Pointer to IsDone flag.
  292. @param[out] IsMatched Pointer to IsMatched flag.
  293. @param[in, out] DestIp Pointer to destination address.
  294. @param[in, out] DestPort Pointer to destination port.
  295. @param[in, out] SrcIp Pointer to source address.
  296. @param[in, out] SrcPort Pointer to source port.
  297. @retval EFI_SUCCESS Successfully read data with Udp6.
  298. @retval Others Failed to send out data.
  299. **/
  300. EFI_STATUS
  301. PxeBcUdp6Read (
  302. IN EFI_UDP6_PROTOCOL *Udp6,
  303. IN EFI_UDP6_COMPLETION_TOKEN *Token,
  304. IN EFI_PXE_BASE_CODE_MODE *Mode,
  305. IN EFI_EVENT TimeoutEvent,
  306. IN UINT16 OpFlags,
  307. IN BOOLEAN *IsDone,
  308. OUT BOOLEAN *IsMatched,
  309. IN OUT EFI_IP_ADDRESS *DestIp OPTIONAL,
  310. IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort OPTIONAL,
  311. IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,
  312. IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL
  313. );
  314. /**
  315. This function is to display the IPv4 address.
  316. @param[in] Ip Pointer to the IPv4 address.
  317. **/
  318. VOID
  319. PxeBcShowIp4Addr (
  320. IN EFI_IPv4_ADDRESS *Ip
  321. );
  322. /**
  323. This function is to display the IPv6 address.
  324. @param[in] Ip Pointer to the IPv6 address.
  325. **/
  326. VOID
  327. PxeBcShowIp6Addr (
  328. IN EFI_IPv6_ADDRESS *Ip
  329. );
  330. /**
  331. This function is to convert UINTN to ASCII string with required format.
  332. @param[in] Number Numeric value to be converted.
  333. @param[in] Buffer Pointer to the buffer for ASCII string.
  334. @param[in] Length Length of the required format.
  335. **/
  336. VOID
  337. PxeBcUintnToAscDecWithFormat (
  338. IN UINTN Number,
  339. IN UINT8 *Buffer,
  340. IN INTN Length
  341. );
  342. /**
  343. This function is to convert a UINTN to a ASCII string, and return the
  344. actual length of the buffer.
  345. @param[in] Number Numeric value to be converted.
  346. @param[in] Buffer Pointer to the buffer for ASCII string.
  347. @param[in] BufferSize The maxsize of the buffer.
  348. @return Length The actual length of the ASCII string.
  349. **/
  350. UINTN
  351. PxeBcUintnToAscDec (
  352. IN UINTN Number,
  353. IN UINT8 *Buffer,
  354. IN UINTN BufferSize
  355. );
  356. /**
  357. This function is to convert unicode hex number to a UINT8.
  358. @param[out] Digit The converted UINT8 for output.
  359. @param[in] Char The unicode hex number to be converted.
  360. @retval EFI_SUCCESS Successfully converted the unicode hex.
  361. @retval EFI_INVALID_PARAMETER Failed to convert the unicode hex.
  362. **/
  363. EFI_STATUS
  364. PxeBcUniHexToUint8 (
  365. OUT UINT8 *Digit,
  366. IN CHAR16 Char
  367. );
  368. /**
  369. Calculate the elapsed time.
  370. @param[in] Private The pointer to PXE private data
  371. **/
  372. VOID
  373. CalcElapsedTime (
  374. IN PXEBC_PRIVATE_DATA *Private
  375. );
  376. /**
  377. Get the Nic handle using any child handle in the IPv4 stack.
  378. @param[in] ControllerHandle Pointer to child handle over IPv4.
  379. @return NicHandle The pointer to the Nic handle.
  380. **/
  381. EFI_HANDLE
  382. PxeBcGetNicByIp4Children (
  383. IN EFI_HANDLE ControllerHandle
  384. );
  385. /**
  386. Get the Nic handle using any child handle in the IPv6 stack.
  387. @param[in] ControllerHandle Pointer to child handle over IPv6.
  388. @return NicHandle The pointer to the Nic handle.
  389. **/
  390. EFI_HANDLE
  391. PxeBcGetNicByIp6Children (
  392. IN EFI_HANDLE ControllerHandle
  393. );
  394. #endif