Dhcp6Impl.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. /** @file
  2. This EFI_DHCP6_PROTOCOL interface implementation.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Dhcp6Impl.h"
  7. //
  8. // Well-known multi-cast address defined in section-24.1 of rfc-3315
  9. //
  10. // ALL_DHCP_Relay_Agents_and_Servers address: FF02::1:2
  11. //
  12. EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress = {{0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2}};
  13. EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate = {
  14. EfiDhcp6GetModeData,
  15. EfiDhcp6Configure,
  16. EfiDhcp6Start,
  17. EfiDhcp6InfoRequest,
  18. EfiDhcp6RenewRebind,
  19. EfiDhcp6Decline,
  20. EfiDhcp6Release,
  21. EfiDhcp6Stop,
  22. EfiDhcp6Parse
  23. };
  24. /**
  25. Starts the DHCPv6 standard S.A.R.R. process.
  26. The Start() function starts the DHCPv6 standard process. This function can
  27. be called only when the state of Dhcp6 instance is in the Dhcp6Init state.
  28. If the DHCP process completes successfully, the state of the Dhcp6 instance
  29. will be transferred through Dhcp6Selecting and Dhcp6Requesting to the
  30. Dhcp6Bound state.
  31. Refer to rfc-3315 for precise state transitions during this process. At the
  32. time when each event occurs in this process, the callback function that was set
  33. by EFI_DHCP6_PROTOCOL.Configure() will be called, and the user can take this
  34. opportunity to control the process.
  35. @param[in] This The pointer to Dhcp6 protocol.
  36. @retval EFI_SUCCESS The DHCPv6 standard process has started, or it has
  37. completed when CompletionEvent is NULL.
  38. @retval EFI_ACCESS_DENIED The EFI DHCPv6 Child instance hasn't been configured.
  39. @retval EFI_INVALID_PARAMETER This is NULL.
  40. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  41. @retval EFI_TIMEOUT The DHCPv6 configuration process failed because no
  42. response was received from the server within the
  43. specified timeout value.
  44. @retval EFI_ABORTED The user aborted the DHCPv6 process.
  45. @retval EFI_ALREADY_STARTED Some other Dhcp6 instance already started the DHCPv6
  46. standard process.
  47. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  48. @retval EFI_NO_MEDIA There was a media error.
  49. **/
  50. EFI_STATUS
  51. EFIAPI
  52. EfiDhcp6Start (
  53. IN EFI_DHCP6_PROTOCOL *This
  54. )
  55. {
  56. EFI_STATUS Status;
  57. EFI_TPL OldTpl;
  58. DHCP6_INSTANCE *Instance;
  59. DHCP6_SERVICE *Service;
  60. EFI_STATUS MediaStatus;
  61. if (This == NULL) {
  62. return EFI_INVALID_PARAMETER;
  63. }
  64. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  65. Service = Instance->Service;
  66. //
  67. // The instance hasn't been configured.
  68. //
  69. if (Instance->Config == NULL) {
  70. return EFI_ACCESS_DENIED;
  71. }
  72. ASSERT (Instance->IaCb.Ia != NULL);
  73. //
  74. // The instance has already been started.
  75. //
  76. if (Instance->IaCb.Ia->State != Dhcp6Init) {
  77. return EFI_ALREADY_STARTED;
  78. }
  79. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  80. //
  81. // Check Media Satus.
  82. //
  83. MediaStatus = EFI_SUCCESS;
  84. NetLibDetectMediaWaitTimeout (Service->Controller, DHCP_CHECK_MEDIA_WAITING_TIME, &MediaStatus);
  85. if (MediaStatus != EFI_SUCCESS) {
  86. Status = EFI_NO_MEDIA;
  87. goto ON_ERROR;
  88. }
  89. Instance->UdpSts = EFI_ALREADY_STARTED;
  90. //
  91. // Send the solicit message to start S.A.R.R process.
  92. //
  93. Status = Dhcp6SendSolicitMsg (Instance);
  94. if (EFI_ERROR (Status)) {
  95. goto ON_ERROR;
  96. }
  97. //
  98. // Register receive callback for the stateful exchange process.
  99. //
  100. Status = UdpIoRecvDatagram(
  101. Service->UdpIo,
  102. Dhcp6ReceivePacket,
  103. Service,
  104. 0
  105. );
  106. if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
  107. goto ON_ERROR;
  108. }
  109. gBS->RestoreTPL (OldTpl);
  110. //
  111. // Poll udp out of the net tpl if synchronous call.
  112. //
  113. if (Instance->Config->IaInfoEvent == NULL) {
  114. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  115. Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
  116. }
  117. return Instance->UdpSts;
  118. }
  119. return EFI_SUCCESS;
  120. ON_ERROR:
  121. gBS->RestoreTPL (OldTpl);
  122. return Status;
  123. }
  124. /**
  125. Stops the DHCPv6 standard S.A.R.R. process.
  126. The Stop() function is used to stop the DHCPv6 standard process. After this
  127. function is called successfully, the state of Dhcp6 instance is transferred
  128. into Dhcp6Init. EFI_DHCP6_PROTOCOL.Configure() needs to be called
  129. before DHCPv6 standard process can be started again. This function can be
  130. called when the Dhcp6 instance is in any state.
  131. @param[in] This The pointer to the Dhcp6 protocol.
  132. @retval EFI_SUCCESS The Dhcp6 instance is now in the Dhcp6Init state.
  133. @retval EFI_INVALID_PARAMETER This is NULL.
  134. **/
  135. EFI_STATUS
  136. EFIAPI
  137. EfiDhcp6Stop (
  138. IN EFI_DHCP6_PROTOCOL *This
  139. )
  140. {
  141. EFI_TPL OldTpl;
  142. EFI_STATUS Status;
  143. EFI_UDP6_PROTOCOL *Udp6;
  144. DHCP6_INSTANCE *Instance;
  145. DHCP6_SERVICE *Service;
  146. if (This == NULL) {
  147. return EFI_INVALID_PARAMETER;
  148. }
  149. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  150. Service = Instance->Service;
  151. Udp6 = Service->UdpIo->Protocol.Udp6;
  152. Status = EFI_SUCCESS;
  153. //
  154. // The instance hasn't been configured.
  155. //
  156. if (Instance->Config == NULL) {
  157. return Status;
  158. }
  159. ASSERT (Instance->IaCb.Ia != NULL);
  160. //
  161. // No valid REPLY message received yet, cleanup this instance directly.
  162. //
  163. if (Instance->IaCb.Ia->State == Dhcp6Init ||
  164. Instance->IaCb.Ia->State == Dhcp6Selecting ||
  165. Instance->IaCb.Ia->State == Dhcp6Requesting
  166. ) {
  167. goto ON_EXIT;
  168. }
  169. //
  170. // Release the current ready Ia.
  171. //
  172. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  173. Instance->UdpSts = EFI_ALREADY_STARTED;
  174. Status = Dhcp6SendReleaseMsg (Instance, Instance->IaCb.Ia);
  175. gBS->RestoreTPL (OldTpl);
  176. if (EFI_ERROR (Status)) {
  177. goto ON_EXIT;
  178. }
  179. //
  180. // Poll udp out of the net tpl if synchoronus call.
  181. //
  182. if (Instance->Config->IaInfoEvent == NULL) {
  183. ASSERT (Udp6 != NULL);
  184. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  185. Udp6->Poll (Udp6);
  186. }
  187. Status = Instance->UdpSts;
  188. }
  189. ON_EXIT:
  190. //
  191. // Clean up the session data for the released Ia.
  192. //
  193. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  194. Dhcp6CleanupSession (Instance, EFI_SUCCESS);
  195. gBS->RestoreTPL (OldTpl);
  196. return Status;
  197. }
  198. /**
  199. Returns the current operating mode data for the Dhcp6 instance.
  200. The GetModeData() function returns the current operating mode and
  201. cached data packet for the Dhcp6 instance.
  202. @param[in] This The pointer to the Dhcp6 protocol.
  203. @param[out] Dhcp6ModeData The pointer to the Dhcp6 mode data.
  204. @param[out] Dhcp6ConfigData The pointer to the Dhcp6 configure data.
  205. @retval EFI_SUCCESS The mode data was returned.
  206. @retval EFI_INVALID_PARAMETER This is NULL.
  207. @retval EFI_ACCESS_DENIED The EFI DHCPv6 Protocol instance was not
  208. configured.
  209. **/
  210. EFI_STATUS
  211. EFIAPI
  212. EfiDhcp6GetModeData (
  213. IN EFI_DHCP6_PROTOCOL *This,
  214. OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,
  215. OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL
  216. )
  217. {
  218. EFI_TPL OldTpl;
  219. EFI_DHCP6_IA *Ia;
  220. DHCP6_INSTANCE *Instance;
  221. DHCP6_SERVICE *Service;
  222. UINT32 IaSize;
  223. UINT32 IdSize;
  224. if (This == NULL || (Dhcp6ModeData == NULL && Dhcp6ConfigData == NULL)) {
  225. return EFI_INVALID_PARAMETER;
  226. }
  227. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  228. Service = Instance->Service;
  229. if (Instance->Config == NULL && Dhcp6ConfigData != NULL) {
  230. return EFI_ACCESS_DENIED;
  231. }
  232. ASSERT (Service->ClientId != NULL);
  233. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  234. //
  235. // User needs a copy of instance config data.
  236. //
  237. if (Dhcp6ConfigData != NULL) {
  238. ZeroMem (Dhcp6ConfigData, sizeof(EFI_DHCP6_CONFIG_DATA));
  239. //
  240. // Duplicate config data, including all reference buffers.
  241. //
  242. if (EFI_ERROR (Dhcp6CopyConfigData (Dhcp6ConfigData, Instance->Config))) {
  243. goto ON_ERROR;
  244. }
  245. }
  246. //
  247. // User need a copy of instance mode data.
  248. //
  249. if (Dhcp6ModeData != NULL) {
  250. ZeroMem (Dhcp6ModeData, sizeof (EFI_DHCP6_MODE_DATA));
  251. //
  252. // Duplicate a copy of EFI_DHCP6_DUID for client Id.
  253. //
  254. IdSize = Service->ClientId->Length + sizeof (Service->ClientId->Length);
  255. Dhcp6ModeData->ClientId = AllocateZeroPool (IdSize);
  256. if (Dhcp6ModeData->ClientId == NULL) {
  257. goto ON_ERROR;
  258. }
  259. CopyMem (
  260. Dhcp6ModeData->ClientId,
  261. Service->ClientId,
  262. IdSize
  263. );
  264. Ia = Instance->IaCb.Ia;
  265. if (Ia != NULL) {
  266. //
  267. // Duplicate a copy of EFI_DHCP6_IA for configured Ia.
  268. //
  269. IaSize = sizeof (EFI_DHCP6_IA) + (Ia->IaAddressCount -1) * sizeof (EFI_DHCP6_IA_ADDRESS);
  270. Dhcp6ModeData->Ia = AllocateZeroPool (IaSize);
  271. if (Dhcp6ModeData->Ia == NULL) {
  272. goto ON_ERROR;
  273. }
  274. CopyMem (
  275. Dhcp6ModeData->Ia,
  276. Ia,
  277. IaSize
  278. );
  279. //
  280. // Duplicate a copy of reply packet if has.
  281. //
  282. if (Ia->ReplyPacket != NULL) {
  283. Dhcp6ModeData->Ia->ReplyPacket = AllocateZeroPool (Ia->ReplyPacket->Size);
  284. if (Dhcp6ModeData->Ia->ReplyPacket == NULL) {
  285. goto ON_ERROR;
  286. }
  287. CopyMem (
  288. Dhcp6ModeData->Ia->ReplyPacket,
  289. Ia->ReplyPacket,
  290. Ia->ReplyPacket->Size
  291. );
  292. }
  293. }
  294. }
  295. gBS->RestoreTPL (OldTpl);
  296. return EFI_SUCCESS;
  297. ON_ERROR:
  298. if (Dhcp6ConfigData != NULL) {
  299. Dhcp6CleanupConfigData (Dhcp6ConfigData);
  300. }
  301. if (Dhcp6ModeData != NULL) {
  302. Dhcp6CleanupModeData (Dhcp6ModeData);
  303. }
  304. gBS->RestoreTPL (OldTpl);
  305. return EFI_OUT_OF_RESOURCES;
  306. }
  307. /**
  308. Initializes, changes, or resets the operational settings for the Dhcp6 instance.
  309. The Configure() function is used to initialize or clean up the configuration
  310. data of the Dhcp6 instance:
  311. - When Dhcp6CfgData is not NULL and Configure() is called successfully, the
  312. configuration data will be initialized in the Dhcp6 instance, and the state
  313. of the configured IA will be transferred into Dhcp6Init.
  314. - When Dhcp6CfgData is NULL and Configure() is called successfully, the
  315. configuration data will be cleaned up and no IA will be associated with
  316. the Dhcp6 instance.
  317. To update the configuration data for an Dhcp6 instance, the original data
  318. must be cleaned up before setting the new configuration data.
  319. @param[in] This The pointer to the Dhcp6 protocol
  320. @param[in] Dhcp6CfgData The pointer to the EFI_DHCP6_CONFIG_DATA.
  321. @retval EFI_SUCCESS The Dhcp6 is configured successfully with the
  322. Dhcp6Init state, or cleaned up the original
  323. configuration setting.
  324. @retval EFI_ACCESS_DENIED The Dhcp6 instance was already configured.
  325. The Dhcp6 instance has already started the
  326. DHCPv6 S.A.R.R when Dhcp6CfgData is NULL.
  327. @retval EFI_INVALID_PARAMETER Some of the parameter is invalid.
  328. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  329. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  330. **/
  331. EFI_STATUS
  332. EFIAPI
  333. EfiDhcp6Configure (
  334. IN EFI_DHCP6_PROTOCOL *This,
  335. IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL
  336. )
  337. {
  338. EFI_TPL OldTpl;
  339. EFI_STATUS Status;
  340. LIST_ENTRY *Entry;
  341. DHCP6_INSTANCE *Other;
  342. DHCP6_INSTANCE *Instance;
  343. DHCP6_SERVICE *Service;
  344. UINTN Index;
  345. if (This == NULL) {
  346. return EFI_INVALID_PARAMETER;
  347. }
  348. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  349. Service = Instance->Service;
  350. //
  351. // Check the parameter of configure data.
  352. //
  353. if (Dhcp6CfgData != NULL) {
  354. if (Dhcp6CfgData->OptionCount > 0 && Dhcp6CfgData->OptionList == NULL) {
  355. return EFI_INVALID_PARAMETER;
  356. }
  357. if (Dhcp6CfgData->OptionList != NULL) {
  358. for (Index = 0; Index < Dhcp6CfgData->OptionCount; Index++) {
  359. if (Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptClientId ||
  360. Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptRapidCommit ||
  361. Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptReconfigureAccept ||
  362. Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIana ||
  363. Dhcp6CfgData->OptionList[Index]->OpCode == Dhcp6OptIata
  364. ) {
  365. return EFI_INVALID_PARAMETER;
  366. }
  367. }
  368. }
  369. if (Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_NA &&
  370. Dhcp6CfgData->IaDescriptor.Type != EFI_DHCP6_IA_TYPE_TA
  371. ) {
  372. return EFI_INVALID_PARAMETER;
  373. }
  374. if (Dhcp6CfgData->IaInfoEvent == NULL && Dhcp6CfgData->SolicitRetransmission == NULL) {
  375. return EFI_INVALID_PARAMETER;
  376. }
  377. if (Dhcp6CfgData->SolicitRetransmission != NULL &&
  378. Dhcp6CfgData->SolicitRetransmission->Mrc == 0 &&
  379. Dhcp6CfgData->SolicitRetransmission->Mrd == 0
  380. ) {
  381. return EFI_INVALID_PARAMETER;
  382. }
  383. //
  384. // Make sure the (IaId, IaType) is unique over all the instances.
  385. //
  386. NET_LIST_FOR_EACH (Entry, &Service->Child) {
  387. Other = NET_LIST_USER_STRUCT (Entry, DHCP6_INSTANCE, Link);
  388. if (Other->IaCb.Ia != NULL &&
  389. Other->IaCb.Ia->Descriptor.Type == Dhcp6CfgData->IaDescriptor.Type &&
  390. Other->IaCb.Ia->Descriptor.IaId == Dhcp6CfgData->IaDescriptor.IaId
  391. ) {
  392. return EFI_INVALID_PARAMETER;
  393. }
  394. }
  395. }
  396. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  397. if (Dhcp6CfgData != NULL) {
  398. //
  399. // It's not allowed to configure one instance twice without configure null.
  400. //
  401. if (Instance->Config != NULL) {
  402. gBS->RestoreTPL (OldTpl);
  403. return EFI_ACCESS_DENIED;
  404. }
  405. //
  406. // Duplicate config data including all reference buffers.
  407. //
  408. Instance->Config = AllocateZeroPool (sizeof (EFI_DHCP6_CONFIG_DATA));
  409. if (Instance->Config == NULL) {
  410. gBS->RestoreTPL (OldTpl);
  411. return EFI_OUT_OF_RESOURCES;
  412. }
  413. Status = Dhcp6CopyConfigData (Instance->Config, Dhcp6CfgData);
  414. if (EFI_ERROR(Status)) {
  415. FreePool (Instance->Config);
  416. gBS->RestoreTPL (OldTpl);
  417. return EFI_OUT_OF_RESOURCES;
  418. }
  419. //
  420. // Initialize the Ia descriptor from the config data, and leave the other
  421. // fields of the Ia as default value 0.
  422. //
  423. Instance->IaCb.Ia = AllocateZeroPool (sizeof(EFI_DHCP6_IA));
  424. if (Instance->IaCb.Ia == NULL) {
  425. Dhcp6CleanupConfigData (Instance->Config);
  426. FreePool (Instance->Config);
  427. gBS->RestoreTPL (OldTpl);
  428. return EFI_OUT_OF_RESOURCES;
  429. }
  430. CopyMem (
  431. &Instance->IaCb.Ia->Descriptor,
  432. &Dhcp6CfgData->IaDescriptor,
  433. sizeof(EFI_DHCP6_IA_DESCRIPTOR)
  434. );
  435. } else {
  436. if (Instance->Config == NULL) {
  437. ASSERT (Instance->IaCb.Ia == NULL);
  438. gBS->RestoreTPL (OldTpl);
  439. return EFI_SUCCESS;
  440. }
  441. //
  442. // It's not allowed to configure a started instance as null.
  443. //
  444. if (Instance->IaCb.Ia->State != Dhcp6Init) {
  445. gBS->RestoreTPL (OldTpl);
  446. return EFI_ACCESS_DENIED;
  447. }
  448. Dhcp6CleanupConfigData (Instance->Config);
  449. FreePool (Instance->Config);
  450. Instance->Config = NULL;
  451. FreePool (Instance->IaCb.Ia);
  452. Instance->IaCb.Ia = NULL;
  453. }
  454. gBS->RestoreTPL (OldTpl);
  455. return EFI_SUCCESS;
  456. }
  457. /**
  458. Request configuration information without the assignment of any
  459. Ia addresses of the client.
  460. The InfoRequest() function is used to request configuration information
  461. without the assignment of any IPv6 address of the client. The client sends
  462. out an Information Request packet to obtain the required configuration
  463. information, and DHCPv6 server responds with a Reply packet containing
  464. the information for the client. The received Reply packet will be passed
  465. to the user by ReplyCallback function. If the user returns EFI_NOT_READY from
  466. ReplyCallback, the Dhcp6 instance will continue to receive other Reply
  467. packets unless timeout according to the Retransmission parameter.
  468. Otherwise, the Information Request exchange process will be finished
  469. successfully if user returns EFI_SUCCESS from ReplyCallback.
  470. @param[in] This The pointer to the Dhcp6 protocol.
  471. @param[in] SendClientId If TRUE, the DHCPv6 protocol instance will build Client
  472. Identifier option and include it into Information Request
  473. packet. Otherwise, Client Identifier option will not be included.
  474. @param[in] OptionRequest The pointer to the buffer of option request options.
  475. @param[in] OptionCount The option number in the OptionList.
  476. @param[in] OptionList The list of appended options.
  477. @param[in] Retransmission The pointer to the retransmission of the message.
  478. @param[in] TimeoutEvent The event of timeout.
  479. @param[in] ReplyCallback The callback function when the reply was received.
  480. @param[in] CallbackContext The pointer to the parameter passed to the callback.
  481. @retval EFI_SUCCESS The DHCPv6 information request exchange process
  482. completed when TimeoutEvent is NULL. Information
  483. Request packet has been sent to DHCPv6 server when
  484. TimeoutEvent is not NULL.
  485. @retval EFI_NO_RESPONSE The DHCPv6 information request exchange process failed
  486. because of no response, or not all requested-options
  487. are responded by DHCPv6 servers when Timeout happened.
  488. @retval EFI_ABORTED The DHCPv6 information request exchange process was aborted
  489. by user.
  490. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  491. @retval EFI_OUT_OF_RESOURCES Required system resources could not be allocated.
  492. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  493. **/
  494. EFI_STATUS
  495. EFIAPI
  496. EfiDhcp6InfoRequest (
  497. IN EFI_DHCP6_PROTOCOL *This,
  498. IN BOOLEAN SendClientId,
  499. IN EFI_DHCP6_PACKET_OPTION *OptionRequest,
  500. IN UINT32 OptionCount,
  501. IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,
  502. IN EFI_DHCP6_RETRANSMISSION *Retransmission,
  503. IN EFI_EVENT TimeoutEvent OPTIONAL,
  504. IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,
  505. IN VOID *CallbackContext OPTIONAL
  506. )
  507. {
  508. EFI_STATUS Status;
  509. DHCP6_INSTANCE *Instance;
  510. DHCP6_SERVICE *Service;
  511. UINTN Index;
  512. EFI_EVENT Timer;
  513. EFI_STATUS TimerStatus;
  514. UINTN GetMappingTimeOut;
  515. if (This == NULL || OptionRequest == NULL || Retransmission == NULL || ReplyCallback == NULL) {
  516. return EFI_INVALID_PARAMETER;
  517. }
  518. if (Retransmission != NULL && Retransmission->Mrc == 0 && Retransmission->Mrd == 0) {
  519. return EFI_INVALID_PARAMETER;
  520. }
  521. if (OptionCount > 0 && OptionList == NULL) {
  522. return EFI_INVALID_PARAMETER;
  523. }
  524. if (OptionList != NULL) {
  525. for (Index = 0; Index < OptionCount; Index++) {
  526. if (OptionList[Index]->OpCode == Dhcp6OptClientId || OptionList[Index]->OpCode == Dhcp6OptRequestOption) {
  527. return EFI_INVALID_PARAMETER;
  528. }
  529. }
  530. }
  531. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  532. Service = Instance->Service;
  533. Status = Dhcp6StartInfoRequest (
  534. Instance,
  535. SendClientId,
  536. OptionRequest,
  537. OptionCount,
  538. OptionList,
  539. Retransmission,
  540. TimeoutEvent,
  541. ReplyCallback,
  542. CallbackContext
  543. );
  544. if (Status == EFI_NO_MAPPING) {
  545. //
  546. // The link local address is not ready, wait for some time and restart
  547. // the DHCP6 information request process.
  548. //
  549. Status = Dhcp6GetMappingTimeOut(Service->Ip6Cfg, &GetMappingTimeOut);
  550. if (EFI_ERROR(Status)) {
  551. return Status;
  552. }
  553. Status = gBS->CreateEvent (EVT_TIMER, TPL_CALLBACK, NULL, NULL, &Timer);
  554. if (EFI_ERROR (Status)) {
  555. return Status;
  556. }
  557. //
  558. // Start the timer, wait for link local address DAD to finish.
  559. //
  560. Status = gBS->SetTimer (Timer, TimerRelative, GetMappingTimeOut);
  561. if (EFI_ERROR (Status)) {
  562. gBS->CloseEvent (Timer);
  563. return Status;
  564. }
  565. do {
  566. TimerStatus = gBS->CheckEvent (Timer);
  567. if (!EFI_ERROR (TimerStatus)) {
  568. Status = Dhcp6StartInfoRequest (
  569. Instance,
  570. SendClientId,
  571. OptionRequest,
  572. OptionCount,
  573. OptionList,
  574. Retransmission,
  575. TimeoutEvent,
  576. ReplyCallback,
  577. CallbackContext
  578. );
  579. }
  580. } while (TimerStatus == EFI_NOT_READY);
  581. gBS->CloseEvent (Timer);
  582. }
  583. if (EFI_ERROR (Status)) {
  584. return Status;
  585. }
  586. //
  587. // Poll udp out of the net tpl if synchoronus call.
  588. //
  589. if (TimeoutEvent == NULL) {
  590. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  591. Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
  592. }
  593. return Instance->UdpSts;
  594. }
  595. return EFI_SUCCESS;
  596. }
  597. /**
  598. Manually extend the valid and preferred lifetimes for the IPv6 addresses
  599. of the configured IA and update other configuration parameters by sending a
  600. Renew or Rebind packet.
  601. The RenewRebind() function is used to manually extend the valid and preferred
  602. lifetimes for the IPv6 addresses of the configured IA, and update other
  603. configuration parameters by sending Renew or Rebind packet.
  604. - When RebindRequest is FALSE and the state of the configured IA is Dhcp6Bound,
  605. it sends Renew packet to the previously DHCPv6 server and transfer the
  606. state of the configured IA to Dhcp6Renewing. If valid Reply packet received,
  607. the state transfers to Dhcp6Bound and the valid and preferred timer restarts.
  608. If fails, the state transfers to Dhcp6Bound, but the timer continues.
  609. - When RebindRequest is TRUE and the state of the configured IA is Dhcp6Bound,
  610. it will send a Rebind packet. If valid Reply packet is received, the state transfers
  611. to Dhcp6Bound and the valid and preferred timer restarts. If it fails, the state
  612. transfers to Dhcp6Init, and the IA can't be used.
  613. @param[in] This The pointer to the Dhcp6 protocol.
  614. @param[in] RebindRequest If TRUE, Rebind packet will be sent and enter Dhcp6Rebinding state.
  615. Otherwise, Renew packet will be sent and enter Dhcp6Renewing state.
  616. @retval EFI_SUCCESS The DHCPv6 renew/rebind exchange process has
  617. completed and at least one IPv6 address of the
  618. configured IA has been bound again when
  619. EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL.
  620. The EFI DHCPv6 Protocol instance has sent Renew
  621. or Rebind packet when
  622. EFI_DHCP6_CONFIG_DATA.IaInfoEvent is not NULL.
  623. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  624. state of the configured IA is not in Dhcp6Bound.
  625. @retval EFI_ALREADY_STARTED The state of the configured IA has already entered
  626. Dhcp6Renewing when RebindRequest is FALSE.
  627. The state of the configured IA has already entered
  628. Dhcp6Rebinding when RebindRequest is TRUE.
  629. @retval EFI_ABORTED The DHCPv6 renew/rebind exchange process aborted
  630. by the user.
  631. @retval EFI_NO_RESPONSE The DHCPv6 renew/rebind exchange process failed
  632. because of no response.
  633. @retval EFI_NO_MAPPING No IPv6 address has been bound to the configured
  634. IA after the DHCPv6 renew/rebind exchange process.
  635. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  636. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  637. **/
  638. EFI_STATUS
  639. EFIAPI
  640. EfiDhcp6RenewRebind (
  641. IN EFI_DHCP6_PROTOCOL *This,
  642. IN BOOLEAN RebindRequest
  643. )
  644. {
  645. EFI_STATUS Status;
  646. EFI_TPL OldTpl;
  647. DHCP6_INSTANCE *Instance;
  648. DHCP6_SERVICE *Service;
  649. if (This == NULL) {
  650. return EFI_INVALID_PARAMETER;
  651. }
  652. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  653. Service = Instance->Service;
  654. //
  655. // The instance hasn't been configured.
  656. //
  657. if (Instance->Config == NULL) {
  658. return EFI_ACCESS_DENIED;
  659. }
  660. ASSERT (Instance->IaCb.Ia != NULL);
  661. //
  662. // The instance has already entered renewing or rebinding state.
  663. //
  664. if ((Instance->IaCb.Ia->State == Dhcp6Rebinding && RebindRequest) ||
  665. (Instance->IaCb.Ia->State == Dhcp6Renewing && !RebindRequest)
  666. ) {
  667. return EFI_ALREADY_STARTED;
  668. }
  669. if (Instance->IaCb.Ia->State != Dhcp6Bound) {
  670. return EFI_ACCESS_DENIED;
  671. }
  672. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  673. Instance->UdpSts = EFI_ALREADY_STARTED;
  674. //
  675. // Send renew/rebind message to start exchange process.
  676. //
  677. Status = Dhcp6SendRenewRebindMsg (Instance, RebindRequest);
  678. if (EFI_ERROR (Status)) {
  679. goto ON_ERROR;
  680. }
  681. //
  682. // Register receive callback for the stateful exchange process.
  683. //
  684. Status = UdpIoRecvDatagram(
  685. Service->UdpIo,
  686. Dhcp6ReceivePacket,
  687. Service,
  688. 0
  689. );
  690. if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
  691. goto ON_ERROR;
  692. }
  693. gBS->RestoreTPL (OldTpl);
  694. //
  695. // Poll udp out of the net tpl if synchoronus call.
  696. //
  697. if (Instance->Config->IaInfoEvent == NULL) {
  698. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  699. Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
  700. }
  701. return Instance->UdpSts;
  702. }
  703. return EFI_SUCCESS;
  704. ON_ERROR:
  705. gBS->RestoreTPL (OldTpl);
  706. return Status;
  707. }
  708. /**
  709. Inform that one or more addresses assigned by a server are already
  710. in use by another node.
  711. The Decline() function is used to manually decline the assignment of
  712. IPv6 addresses, which have been already used by another node. If all
  713. IPv6 addresses of the configured IA are declined through this function,
  714. the state of the IA will switch through Dhcp6Declining to Dhcp6Init.
  715. Otherwise, the state of the IA will restore to Dhcp6Bound after the
  716. declining process. The Decline() can only be called when the IA is in
  717. Dhcp6Bound state. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL,
  718. this function is a blocking operation. It will return after the
  719. declining process finishes, or aborted by user.
  720. @param[in] This The pointer to EFI_DHCP6_PROTOCOL.
  721. @param[in] AddressCount The number of declining addresses.
  722. @param[in] Addresses The pointer to the buffer stored the declining
  723. addresses.
  724. @retval EFI_SUCCESS The DHCPv6 decline exchange process completed
  725. when EFI_DHCP6_CONFIG_DATA.IaInfoEvent was NULL.
  726. The Dhcp6 instance sent Decline packet when
  727. EFI_DHCP6_CONFIG_DATA.IaInfoEvent was not NULL.
  728. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  729. state of the configured IA is not in Dhcp6Bound.
  730. @retval EFI_ABORTED The DHCPv6 decline exchange process aborted by user.
  731. @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
  732. the configured IA for this instance.
  733. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  734. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  735. **/
  736. EFI_STATUS
  737. EFIAPI
  738. EfiDhcp6Decline (
  739. IN EFI_DHCP6_PROTOCOL *This,
  740. IN UINT32 AddressCount,
  741. IN EFI_IPv6_ADDRESS *Addresses
  742. )
  743. {
  744. EFI_STATUS Status;
  745. EFI_TPL OldTpl;
  746. EFI_DHCP6_IA *DecIa;
  747. DHCP6_INSTANCE *Instance;
  748. DHCP6_SERVICE *Service;
  749. if (This == NULL || AddressCount == 0 || Addresses == NULL) {
  750. return EFI_INVALID_PARAMETER;
  751. }
  752. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  753. Service = Instance->Service;
  754. //
  755. // The instance hasn't been configured.
  756. //
  757. if (Instance->Config == NULL) {
  758. return EFI_ACCESS_DENIED;
  759. }
  760. ASSERT (Instance->IaCb.Ia != NULL);
  761. if (Instance->IaCb.Ia->State != Dhcp6Bound) {
  762. return EFI_ACCESS_DENIED;
  763. }
  764. //
  765. // Check whether all the declined addresses belongs to the configured Ia.
  766. //
  767. Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);
  768. if (EFI_ERROR(Status)) {
  769. return Status;
  770. }
  771. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  772. Instance->UdpSts = EFI_ALREADY_STARTED;
  773. //
  774. // Deprive of all the declined addresses from the configured Ia, and create a
  775. // DeclineIa used to create decline message.
  776. //
  777. DecIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);
  778. if (DecIa == NULL) {
  779. Status = EFI_OUT_OF_RESOURCES;
  780. goto ON_ERROR;
  781. }
  782. //
  783. // Send the decline message to start exchange process.
  784. //
  785. Status = Dhcp6SendDeclineMsg (Instance, DecIa);
  786. if (EFI_ERROR (Status)) {
  787. goto ON_ERROR;
  788. }
  789. //
  790. // Register receive callback for the stateful exchange process.
  791. //
  792. Status = UdpIoRecvDatagram(
  793. Service->UdpIo,
  794. Dhcp6ReceivePacket,
  795. Service,
  796. 0
  797. );
  798. if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
  799. goto ON_ERROR;
  800. }
  801. FreePool (DecIa);
  802. gBS->RestoreTPL (OldTpl);
  803. //
  804. // Poll udp out of the net tpl if synchoronus call.
  805. //
  806. if (Instance->Config->IaInfoEvent == NULL) {
  807. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  808. Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
  809. }
  810. return Instance->UdpSts;
  811. }
  812. return EFI_SUCCESS;
  813. ON_ERROR:
  814. if (DecIa != NULL) {
  815. FreePool (DecIa);
  816. }
  817. gBS->RestoreTPL (OldTpl);
  818. return Status;
  819. }
  820. /**
  821. Release one or more addresses associated with the configured Ia
  822. for current instance.
  823. The Release() function is used to manually release one or more
  824. IPv6 addresses. If AddressCount is zero, it will release all IPv6
  825. addresses of the configured IA. If all IPv6 addresses of the IA are
  826. released through this function, the state of the IA will switch
  827. through Dhcp6Releasing to Dhcp6Init, otherwise, the state of the
  828. IA will restore to Dhcp6Bound after the releasing process.
  829. The Release() can only be called when the IA is in Dhcp6Bound state.
  830. If the EFI_DHCP6_CONFIG_DATA.IaInfoEvent is NULL, the function is
  831. a blocking operation. It will return after the releasing process
  832. finishes, or is aborted by user.
  833. @param[in] This The pointer to the Dhcp6 protocol.
  834. @param[in] AddressCount The number of releasing addresses.
  835. @param[in] Addresses The pointer to the buffer stored the releasing
  836. addresses.
  837. @retval EFI_SUCCESS The DHCPv6 release exchange process
  838. completed when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
  839. was NULL. The Dhcp6 instance was sent Release
  840. packet when EFI_DHCP6_CONFIG_DATA.IaInfoEvent
  841. was not NULL.
  842. @retval EFI_ACCESS_DENIED The Dhcp6 instance hasn't been configured, or the
  843. state of the configured IA is not in Dhcp6Bound.
  844. @retval EFI_ABORTED The DHCPv6 release exchange process aborted by user.
  845. @retval EFI_NOT_FOUND Any specified IPv6 address is not correlated with
  846. the configured IA for this instance.
  847. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  848. @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.
  849. **/
  850. EFI_STATUS
  851. EFIAPI
  852. EfiDhcp6Release (
  853. IN EFI_DHCP6_PROTOCOL *This,
  854. IN UINT32 AddressCount,
  855. IN EFI_IPv6_ADDRESS *Addresses
  856. )
  857. {
  858. EFI_STATUS Status;
  859. EFI_TPL OldTpl;
  860. EFI_DHCP6_IA *RelIa;
  861. DHCP6_INSTANCE *Instance;
  862. DHCP6_SERVICE *Service;
  863. if (This == NULL || (AddressCount != 0 && Addresses == NULL)) {
  864. return EFI_INVALID_PARAMETER;
  865. }
  866. Instance = DHCP6_INSTANCE_FROM_THIS (This);
  867. Service = Instance->Service;
  868. //
  869. // The instance hasn't been configured.
  870. //
  871. if (Instance->Config == NULL) {
  872. return EFI_ACCESS_DENIED;
  873. }
  874. ASSERT (Instance->IaCb.Ia != NULL);
  875. if (Instance->IaCb.Ia->State != Dhcp6Bound) {
  876. return EFI_ACCESS_DENIED;
  877. }
  878. //
  879. // Check whether all the released addresses belongs to the configured Ia.
  880. //
  881. Status = Dhcp6CheckAddress (Instance->IaCb.Ia, AddressCount, Addresses);
  882. if (EFI_ERROR(Status)) {
  883. return Status;
  884. }
  885. OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
  886. Instance->UdpSts = EFI_ALREADY_STARTED;
  887. //
  888. // Deprive of all the released addresses from the configured Ia, and create a
  889. // ReleaseIa used to create release message.
  890. //
  891. RelIa = Dhcp6DepriveAddress (Instance->IaCb.Ia, AddressCount, Addresses);
  892. if (RelIa == NULL) {
  893. Status = EFI_OUT_OF_RESOURCES;
  894. goto ON_ERROR;
  895. }
  896. //
  897. // Send the release message to start exchange process.
  898. //
  899. Status = Dhcp6SendReleaseMsg (Instance, RelIa);
  900. if (EFI_ERROR (Status)) {
  901. goto ON_ERROR;
  902. }
  903. //
  904. // Register receive callback for the stateful exchange process.
  905. //
  906. Status = UdpIoRecvDatagram(
  907. Service->UdpIo,
  908. Dhcp6ReceivePacket,
  909. Service,
  910. 0
  911. );
  912. if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
  913. goto ON_ERROR;
  914. }
  915. FreePool (RelIa);
  916. gBS->RestoreTPL (OldTpl);
  917. //
  918. // Poll udp out of the net tpl if synchoronus call.
  919. //
  920. if (Instance->Config->IaInfoEvent == NULL) {
  921. while (Instance->UdpSts == EFI_ALREADY_STARTED) {
  922. Service->UdpIo->Protocol.Udp6->Poll (Service->UdpIo->Protocol.Udp6);
  923. }
  924. return Instance->UdpSts;
  925. }
  926. return EFI_SUCCESS;
  927. ON_ERROR:
  928. if (RelIa != NULL) {
  929. FreePool (RelIa);
  930. }
  931. gBS->RestoreTPL (OldTpl);
  932. return Status;
  933. }
  934. /**
  935. Parse the option data in the Dhcp6 packet.
  936. The Parse() function is used to retrieve the option list in the DHCPv6 packet.
  937. @param[in] This The pointer to the Dhcp6 protocol.
  938. @param[in] Packet The pointer to the Dhcp6 packet.
  939. @param[in, out] OptionCount The number of option in the packet.
  940. @param[out] PacketOptionList The array of pointers to each option in the packet.
  941. @retval EFI_SUCCESS The packet was successfully parsed.
  942. @retval EFI_INVALID_PARAMETER Some parameter is NULL.
  943. @retval EFI_BUFFER_TOO_SMALL *OptionCount is smaller than the number of options
  944. that were found in the Packet.
  945. **/
  946. EFI_STATUS
  947. EFIAPI
  948. EfiDhcp6Parse (
  949. IN EFI_DHCP6_PROTOCOL *This,
  950. IN EFI_DHCP6_PACKET *Packet,
  951. IN OUT UINT32 *OptionCount,
  952. OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL
  953. )
  954. {
  955. UINT32 OptCnt;
  956. UINT32 OptLen;
  957. UINT16 DataLen;
  958. UINT8 *Start;
  959. UINT8 *End;
  960. if (This == NULL || Packet == NULL || OptionCount == NULL) {
  961. return EFI_INVALID_PARAMETER;
  962. }
  963. if (*OptionCount != 0 && PacketOptionList == NULL) {
  964. return EFI_INVALID_PARAMETER;
  965. }
  966. if (Packet->Length > Packet->Size || Packet->Length < sizeof (EFI_DHCP6_HEADER)) {
  967. return EFI_INVALID_PARAMETER;
  968. }
  969. //
  970. // The format of Dhcp6 option:
  971. //
  972. // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  973. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  974. // | option-code | option-len (option data) |
  975. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  976. // | option-data |
  977. // | (option-len octets) |
  978. // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  979. //
  980. OptCnt = 0;
  981. OptLen = Packet->Length - sizeof (EFI_DHCP6_HEADER);
  982. Start = Packet->Dhcp6.Option;
  983. End = Start + OptLen;
  984. //
  985. // Calculate the number of option in the packet.
  986. //
  987. while (Start < End) {
  988. DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;
  989. Start += (NTOHS (DataLen) + 4);
  990. OptCnt++;
  991. }
  992. //
  993. // It will return buffer too small if pass-in option count is smaller than the
  994. // actual count of options in the packet.
  995. //
  996. if (OptCnt > *OptionCount) {
  997. *OptionCount = OptCnt;
  998. return EFI_BUFFER_TOO_SMALL;
  999. }
  1000. ZeroMem (
  1001. PacketOptionList,
  1002. (*OptionCount * sizeof (EFI_DHCP6_PACKET_OPTION *))
  1003. );
  1004. OptCnt = 0;
  1005. Start = Packet->Dhcp6.Option;
  1006. while (Start < End) {
  1007. PacketOptionList[OptCnt] = (EFI_DHCP6_PACKET_OPTION *) Start;
  1008. DataLen = ((EFI_DHCP6_PACKET_OPTION *) Start)->OpLen;
  1009. Start += (NTOHS (DataLen) + 4);
  1010. OptCnt++;
  1011. }
  1012. return EFI_SUCCESS;
  1013. }