Dhcp6Impl.c 38 KB

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