TianoCore EDK2 master
Loading...
Searching...
No Matches
Dhcp6Impl.h
Go to the documentation of this file.
1
10#ifndef __EFI_DHCP6_IMPL_H__
11#define __EFI_DHCP6_IMPL_H__
12
13#include <Uefi.h>
14
16
17#include <Protocol/Dhcp6.h>
18#include <Protocol/Udp6.h>
19#include <Protocol/Ip6Config.h>
22
23#include <Library/UdpIoLib.h>
24#include <Library/DebugLib.h>
29#include <Library/UefiLib.h>
30#include <Library/BaseLib.h>
31#include <Library/NetLib.h>
32#include <Library/PrintLib.h>
33#include <Guid/ZeroGuid.h>
34
35typedef struct _DHCP6_IA_CB DHCP6_IA_CB;
36typedef struct _DHCP6_INF_CB DHCP6_INF_CB;
37typedef struct _DHCP6_TX_CB DHCP6_TX_CB;
38typedef struct _DHCP6_SERVICE DHCP6_SERVICE;
39typedef struct _DHCP6_INSTANCE DHCP6_INSTANCE;
40
41#include "Dhcp6Utility.h"
42#include "Dhcp6Io.h"
43#include "Dhcp6Driver.h"
44
45#define DHCP6_SERVICE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'S')
46#define DHCP6_INSTANCE_SIGNATURE SIGNATURE_32 ('D', 'H', '6', 'I')
47
48#define DHCP6_PACKET_ALL 0
49#define DHCP6_PACKET_STATEFUL 1
50#define DHCP6_PACKET_STATELESS 2
51
52#define DHCP6_BASE_PACKET_SIZE 1024
53
54#define DHCP6_PORT_CLIENT 546
55#define DHCP6_PORT_SERVER 547
56
57#define DHCP_CHECK_MEDIA_WAITING_TIME EFI_TIMER_PERIOD_SECONDS(20)
58
59#define DHCP6_INSTANCE_FROM_THIS(Instance) CR ((Instance), DHCP6_INSTANCE, Dhcp6, DHCP6_INSTANCE_SIGNATURE)
60#define DHCP6_SERVICE_FROM_THIS(Service) CR ((Service), DHCP6_SERVICE, ServiceBinding, DHCP6_SERVICE_SIGNATURE)
61
62//
63// For more information on DHCP options see RFC 8415, Section 21.1
64//
65// The format of DHCP options is:
66//
67// 0 1 2 3
68// 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
69// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70// | option-code | option-len |
71// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72// | option-data |
73// | (option-len octets) |
74// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75//
76#define DHCP6_SIZE_OF_OPT_CODE (sizeof (((EFI_DHCP6_PACKET_OPTION *)0)->OpCode))
77#define DHCP6_SIZE_OF_OPT_LEN (sizeof (((EFI_DHCP6_PACKET_OPTION *)0)->OpLen))
78
79// Combined size of Code and Length
80#define DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN (DHCP6_SIZE_OF_OPT_CODE + \
81 DHCP6_SIZE_OF_OPT_LEN)
82
84 DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN == 4,
85 "Combined size of Code and Length must be 4 per RFC 8415"
86 );
87
88// Offset to the length is just past the code
89#define DHCP6_OFFSET_OF_OPT_LEN(a) (a + DHCP6_SIZE_OF_OPT_CODE)
91 DHCP6_OFFSET_OF_OPT_LEN (0) == 2,
92 "Offset of length is + 2 past start of option"
93 );
94
95#define DHCP6_OFFSET_OF_OPT_DATA(a) (a + DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN)
97 DHCP6_OFFSET_OF_OPT_DATA (0) == 4,
98 "Offset to option data should be +4 from start of option"
99 );
100//
101// Identity Association options (both NA (Non-Temporary) and TA (Temporary Association))
102// are defined in RFC 8415 and are a deriviation of a TLV stucture
103// For more information on IA_NA see Section 21.4
104// For more information on IA_TA see Section 21.5
105//
106//
107// The format of IA_NA and IA_TA option:
108//
109// 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
110// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
111// | OPTION_IA_NA | option-len |
112// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
113// | IAID (4 octets) |
114// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
115// | T1 (only for IA_NA) |
116// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
117// | T2 (only for IA_NA) |
118// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119// | |
120// . IA_NA-options/IA_TA-options .
121// . .
122// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
123//
124#define DHCP6_SIZE_OF_IAID (sizeof(UINT32))
125#define DHCP6_SIZE_OF_TIME_INTERVAL (sizeof(UINT32))
126
127// Combined size of IAID, T1, and T2
128#define DHCP6_SIZE_OF_COMBINED_IAID_T1_T2 (DHCP6_SIZE_OF_IAID + \
129 DHCP6_SIZE_OF_TIME_INTERVAL + \
130 DHCP6_SIZE_OF_TIME_INTERVAL)
132 DHCP6_SIZE_OF_COMBINED_IAID_T1_T2 == 12,
133 "Combined size of IAID, T1, T2 must be 12 per RFC 8415"
134 );
135
136// This is the size of IA_TA without options
137#define DHCP6_MIN_SIZE_OF_IA_TA (DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + \
138 DHCP6_SIZE_OF_IAID)
140 DHCP6_MIN_SIZE_OF_IA_TA == 8,
141 "Minimum combined size of IA_TA per RFC 8415"
142 );
143
144// Offset to a IA_TA inner option
145#define DHCP6_OFFSET_OF_IA_TA_INNER_OPT(a) (a + DHCP6_MIN_SIZE_OF_IA_TA)
147 DHCP6_OFFSET_OF_IA_TA_INNER_OPT (0) == 8,
148 "Offset of IA_TA Inner option is + 8 past start of option"
149 );
150
151// This is the size of IA_NA without options (16)
152#define DHCP6_MIN_SIZE_OF_IA_NA DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + \
153 DHCP6_SIZE_OF_COMBINED_IAID_T1_T2
155 DHCP6_MIN_SIZE_OF_IA_NA == 16,
156 "Minimum combined size of IA_TA per RFC 8415"
157 );
158
159#define DHCP6_OFFSET_OF_IA_NA_INNER_OPT(a) (a + DHCP6_MIN_SIZE_OF_IA_NA)
161 DHCP6_OFFSET_OF_IA_NA_INNER_OPT (0) == 16,
162 "Offset of IA_NA Inner option is + 16 past start of option"
163 );
164
165#define DHCP6_OFFSET_OF_IA_NA_T1(a) (a + \
166 DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN + \
167 DHCP6_SIZE_OF_IAID)
169 DHCP6_OFFSET_OF_IA_NA_T1 (0) == 8,
170 "Offset of IA_NA Inner option is + 8 past start of option"
171 );
172
173#define DHCP6_OFFSET_OF_IA_NA_T2(a) (a + \
174 DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN +\
175 DHCP6_SIZE_OF_IAID + \
176 DHCP6_SIZE_OF_TIME_INTERVAL)
178 DHCP6_OFFSET_OF_IA_NA_T2 (0) == 12,
179 "Offset of IA_NA Inner option is + 12 past start of option"
180 );
181
182//
183// For more information see RFC 8415 Section 21.13
184//
185// The format of the Status Code Option:
186//
187// 0 1 2 3
188// 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
189// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
190// | OPTION_STATUS_CODE | option-len |
191// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
192// | status-code | |
193// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
194// . .
195// . status-message .
196// . .
197// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198//
199#define DHCP6_OFFSET_OF_STATUS_CODE(a) (a + DHCP6_SIZE_OF_COMBINED_CODE_AND_LEN)
201 DHCP6_OFFSET_OF_STATUS_CODE (0) == 4,
202 "Offset of status is + 4 past start of option"
203 );
204
205extern EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress;
206extern EFI_DHCP6_PROTOCOL gDhcp6ProtocolTemplate;
207
208//
209// Control block for each IA.
210//
212 EFI_DHCP6_IA *Ia;
213 UINT32 T1;
214 UINT32 T2;
215 UINT32 AllExpireTime;
216 UINT32 LeaseTime;
217};
218
219//
220// Control block for each transmitted message.
221//
223 LIST_ENTRY Link;
224 UINT32 Xid;
225 EFI_DHCP6_PACKET *TxPacket;
227 UINT32 RetryCnt;
228 UINT32 RetryExp;
229 UINT32 RetryLos;
230 UINT32 TickTime;
231 UINT16 *Elapsed;
232 BOOLEAN SolicitRetry;
233};
234
235//
236// Control block for each info-request message.
237//
239 LIST_ENTRY Link;
240 UINT32 Xid;
241 EFI_DHCP6_INFO_CALLBACK ReplyCallback;
242 VOID *CallbackContext;
243 EFI_EVENT TimeoutEvent;
244};
245
246//
247// Control block for Dhcp6 instance, it's per configuration data.
248//
250 UINT32 Signature;
251 EFI_HANDLE Handle;
252 DHCP6_SERVICE *Service;
253 LIST_ENTRY Link;
254 EFI_DHCP6_PROTOCOL Dhcp6;
255 EFI_EVENT Timer;
256 EFI_DHCP6_CONFIG_DATA *Config;
257 EFI_DHCP6_IA *CacheIa;
258 DHCP6_IA_CB IaCb;
259 LIST_ENTRY TxList;
260 LIST_ENTRY InfList;
261 EFI_DHCP6_PACKET *AdSelect;
262 UINT8 AdPref;
263 EFI_IPv6_ADDRESS *Unicast;
264 volatile EFI_STATUS UdpSts;
265 BOOLEAN InDestroy;
266 BOOLEAN MediaPresent;
267 //
268 // StartTime is used to calculate the 'elapsed-time' option. Refer to RFC3315,
269 // the elapsed-time is amount of time since the client began its current DHCP transaction.
270 //
271 UINT64 StartTime;
272};
273
274//
275// Control block for Dhcp6 service, it's per Nic handle.
276//
278 UINT32 Signature;
279 EFI_HANDLE Controller;
280 EFI_HANDLE Image;
281 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
284 EFI_DHCP6_DUID *ClientId;
285 UDP_IO *UdpIo;
286 UINT32 Xid;
287 LIST_ENTRY Child;
288 UINTN NumOfChild;
289};
290
321EFIAPI
324 );
325
342EFIAPI
345 );
346
364EFIAPI
367 OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL,
368 OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL
369 );
370
401EFIAPI
404 IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL
405 );
406
449EFIAPI
452 IN BOOLEAN SendClientId,
453 IN EFI_DHCP6_PACKET_OPTION *OptionRequest,
454 IN UINT32 OptionCount,
455 IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL,
456 IN EFI_DHCP6_RETRANSMISSION *Retransmission,
457 IN EFI_EVENT TimeoutEvent OPTIONAL,
458 IN EFI_DHCP6_INFO_CALLBACK ReplyCallback,
459 IN VOID *CallbackContext OPTIONAL
460 );
461
508EFIAPI
511 IN BOOLEAN RebindRequest
512 );
513
547EFIAPI
550 IN UINT32 AddressCount,
551 IN EFI_IPv6_ADDRESS *Addresses
552 );
553
588EFIAPI
591 IN UINT32 AddressCount,
592 IN EFI_IPv6_ADDRESS *Addresses
593 );
594
612EFIAPI
615 IN EFI_DHCP6_PACKET *Packet,
616 IN OUT UINT32 *OptionCount,
617 OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL
618 );
619
620#endif
UINT64 UINTN
EFI_STATUS(EFIAPI * EFI_DHCP6_INFO_CALLBACK)(IN EFI_DHCP6_PROTOCOL *This, IN VOID *Context, IN EFI_DHCP6_PACKET *Packet)
Definition: Dhcp6.h:397
EFI_STATUS EFIAPI EfiDhcp6Release(IN EFI_DHCP6_PROTOCOL *This, IN UINT32 AddressCount, IN EFI_IPv6_ADDRESS *Addresses)
Definition: Dhcp6Impl.c:1027
EFI_STATUS EFIAPI EfiDhcp6Decline(IN EFI_DHCP6_PROTOCOL *This, IN UINT32 AddressCount, IN EFI_IPv6_ADDRESS *Addresses)
Definition: Dhcp6Impl.c:886
EFI_STATUS EFIAPI EfiDhcp6Parse(IN EFI_DHCP6_PROTOCOL *This, IN EFI_DHCP6_PACKET *Packet, IN OUT UINT32 *OptionCount, OUT EFI_DHCP6_PACKET_OPTION *PacketOptionList[] OPTIONAL)
Definition: Dhcp6Impl.c:1150
EFI_STATUS EFIAPI EfiDhcp6Configure(IN EFI_DHCP6_PROTOCOL *This, IN EFI_DHCP6_CONFIG_DATA *Dhcp6CfgData OPTIONAL)
Definition: Dhcp6Impl.c:411
EFI_STATUS EFIAPI EfiDhcp6InfoRequest(IN EFI_DHCP6_PROTOCOL *This, IN BOOLEAN SendClientId, IN EFI_DHCP6_PACKET_OPTION *OptionRequest, IN UINT32 OptionCount, IN EFI_DHCP6_PACKET_OPTION *OptionList[] OPTIONAL, IN EFI_DHCP6_RETRANSMISSION *Retransmission, IN EFI_EVENT TimeoutEvent OPTIONAL, IN EFI_DHCP6_INFO_CALLBACK ReplyCallback, IN VOID *CallbackContext OPTIONAL)
Definition: Dhcp6Impl.c:602
EFI_STATUS EFIAPI EfiDhcp6RenewRebind(IN EFI_DHCP6_PROTOCOL *This, IN BOOLEAN RebindRequest)
Definition: Dhcp6Impl.c:765
EFI_STATUS EFIAPI EfiDhcp6Start(IN EFI_DHCP6_PROTOCOL *This)
Definition: Dhcp6Impl.c:65
EFI_STATUS EFIAPI EfiDhcp6GetModeData(IN EFI_DHCP6_PROTOCOL *This, OUT EFI_DHCP6_MODE_DATA *Dhcp6ModeData OPTIONAL, OUT EFI_DHCP6_CONFIG_DATA *Dhcp6ConfigData OPTIONAL)
Definition: Dhcp6Impl.c:264
EFI_STATUS EFIAPI EfiDhcp6Stop(IN EFI_DHCP6_PROTOCOL *This)
Definition: Dhcp6Impl.c:173
#define STATIC_ASSERT
Definition: Base.h:808
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33