1 /** @file
2   Functions declaration related with DHCPv6 for UefiPxeBc Driver.
3 
4   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
5 
6   This program and the accompanying materials
7   are licensed and made available under the terms and conditions of the BSD License
8   which accompanies this distribution.  The full text of the license may be found at
9   http://opensource.org/licenses/bsd-license.php.
10 
11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 
14 **/
15 
16 #ifndef __EFI_PXEBC_DHCP6_H__
17 #define __EFI_PXEBC_DHCP6_H__
18 
19 #define PXEBC_DHCP6_OPTION_MAX_NUM        16
20 #define PXEBC_DHCP6_OPTION_MAX_SIZE       312
21 #define PXEBC_DHCP6_PACKET_MAX_SIZE       1472
22 #define PXEBC_IP6_POLICY_MAX              0xff
23 #define PXEBC_IP6_ROUTE_TABLE_TIMEOUT     10
24 
25 #define PXEBC_DHCP6_S_PORT                547
26 #define PXEBC_DHCP6_C_PORT                546
27 
28 #define PXEBC_DHCP6_OPT_CLIENT_ID         1
29 #define PXEBC_DHCP6_OPT_SERVER_ID         2
30 #define PXEBC_DHCP6_OPT_IA_NA             3
31 #define PXEBC_DHCP6_OPT_IA_TA             4
32 #define PXEBC_DHCP6_OPT_IAADDR            5
33 #define PXEBC_DHCP6_OPT_ORO               6
34 #define PXEBC_DHCP6_OPT_PREFERENCE        7
35 #define PXEBC_DHCP6_OPT_ELAPSED_TIME      8
36 #define PXEBC_DHCP6_OPT_REPLAY_MSG        9
37 #define PXEBC_DHCP6_OPT_AUTH              11
38 #define PXEBC_DHCP6_OPT_UNICAST           12
39 #define PXEBC_DHCP6_OPT_STATUS_CODE       13
40 #define PXEBC_DHCP6_OPT_RAPID_COMMIT      14
41 #define PXEBC_DHCP6_OPT_USER_CLASS        15
42 #define PXEBC_DHCP6_OPT_VENDOR_CLASS      16
43 #define PXEBC_DHCP6_OPT_VENDOR_OPTS       17
44 #define PXEBC_DHCP6_OPT_INTERFACE_ID      18
45 #define PXEBC_DHCP6_OPT_RECONFIG_MSG      19
46 #define PXEBC_DHCP6_OPT_RECONFIG_ACCEPT   20
47 #define PXEBC_DHCP6_OPT_BOOT_FILE_URL     59    // Assigned by IANA, RFC 5970
48 #define PXEBC_DHCP6_OPT_BOOT_FILE_PARAM   60    // Assigned by IANA, RFC 5970
49 #define PXEBC_DHCP6_OPT_ARCH              61    // Assigned by IANA, RFC 5970
50 #define PXEBC_DHCP6_OPT_UNDI              62    // Assigned by IANA, RFC 5970
51 #define PXEBC_DHCP6_ENTERPRISE_NUM        343   // TODO: IANA TBD: temporarily using Intel's
52 #define PXEBC_DHCP6_MAX_BOOT_FILE_SIZE    65535 //   It's a limitation of bit length, 65535*512 bytes.
53 
54 
55 #define PXEBC_DHCP6_IDX_IA_NA             0
56 #define PXEBC_DHCP6_IDX_BOOT_FILE_URL     1
57 #define PXEBC_DHCP6_IDX_BOOT_FILE_PARAM   2
58 #define PXEBC_DHCP6_IDX_VENDOR_CLASS      3
59 #define PXEBC_DHCP6_IDX_MAX               4
60 
61 #define PXEBC_DHCP6_BOOT_FILE_URL_PREFIX  "tftp://"
62 #define PXEBC_TFTP_URL_SEPARATOR          '/'
63 #define PXEBC_ADDR_START_DELIMITER        '['
64 #define PXEBC_ADDR_END_DELIMITER          ']'
65 
66 #define GET_NEXT_DHCP6_OPTION(Opt) \
67   (EFI_DHCP6_PACKET_OPTION *) ((UINT8 *) (Opt) + \
68   sizeof (EFI_DHCP6_PACKET_OPTION) + (NTOHS ((Opt)->OpLen)) - 1)
69 
70 #define GET_DHCP6_OPTION_SIZE(Pkt)  \
71   ((Pkt)->Length - sizeof (EFI_DHCP6_HEADER))
72 
73 #define IS_PROXY_OFFER(Type) \
74   ((Type) == PxeOfferTypeProxyBinl || \
75    (Type) == PxeOfferTypeProxyPxe10 || \
76    (Type) == PxeOfferTypeProxyWfm11a)
77 
78 
79 #pragma pack(1)
80 typedef struct {
81   UINT16 OpCode[256];
82 } PXEBC_DHCP6_OPTION_ORO;
83 
84 typedef struct {
85   UINT8 Type;
86   UINT8 MajorVer;
87   UINT8 MinorVer;
88 } PXEBC_DHCP6_OPTION_UNDI;
89 
90 typedef struct {
91   UINT16 Type;
92 } PXEBC_DHCP6_OPTION_ARCH;
93 
94 typedef struct {
95   UINT8 ClassIdentifier[10];
96   UINT8 ArchitecturePrefix[5];
97   UINT8 ArchitectureType[5];
98   UINT8 Lit3[1];
99   UINT8 InterfaceName[4];
100   UINT8 Lit4[1];
101   UINT8 UndiMajor[3];
102   UINT8 UndiMinor[3];
103 } PXEBC_CLASS_ID;
104 
105 typedef struct {
106   UINT32         Vendor;
107   UINT16         ClassLen;
108   PXEBC_CLASS_ID ClassId;
109 } PXEBC_DHCP6_OPTION_VENDOR_CLASS;
110 
111 #pragma pack()
112 
113 typedef union {
114   PXEBC_DHCP6_OPTION_ORO            *Oro;
115   PXEBC_DHCP6_OPTION_UNDI           *Undi;
116   PXEBC_DHCP6_OPTION_ARCH           *Arch;
117   PXEBC_DHCP6_OPTION_VENDOR_CLASS   *VendorClass;
118 } PXEBC_DHCP6_OPTION_ENTRY;
119 
120 typedef struct {
121   LIST_ENTRY              Link;
122   EFI_DHCP6_PACKET_OPTION *Option;
123   UINT8                   Precedence;
124 } PXEBC_DHCP6_OPTION_NODE;
125 
126 typedef union {
127   EFI_DHCP6_PACKET        Offer;
128   EFI_DHCP6_PACKET        Ack;
129   UINT8                   Buffer[PXEBC_DHCP6_PACKET_MAX_SIZE];
130 } PXEBC_DHCP6_PACKET;
131 
132 typedef struct {
133   PXEBC_DHCP6_PACKET      Packet;
134   PXEBC_OFFER_TYPE        OfferType;
135   EFI_DHCP6_PACKET_OPTION *OptList[PXEBC_DHCP6_IDX_MAX];
136 } PXEBC_DHCP6_PACKET_CACHE;
137 
138 
139 /**
140   Free all the nodes in the boot file list.
141 
142   @param[in]  Head            The pointer to the head of the list.
143 
144 **/
145 VOID
146 PxeBcFreeBootFileOption (
147   IN LIST_ENTRY               *Head
148   );
149 
150 
151 /**
152   Parse the Boot File URL option.
153 
154   @param[out]     FileName     The pointer to the boot file name.
155   @param[in, out] SrvAddr      The pointer to the boot server address.
156   @param[in]      BootFile     The pointer to the boot file URL option data.
157   @param[in]      Length       Length of the boot file URL option data.
158 
159   @retval EFI_ABORTED     User canceled the operation.
160   @retval EFI_SUCCESS     Selected the boot menu successfully.
161   @retval EFI_NOT_READY   Read the input key from the keybroad has not finish.
162 
163 **/
164 EFI_STATUS
165 PxeBcExtractBootFileUrl (
166      OUT UINT8               **FileName,
167   IN OUT EFI_IPv6_ADDRESS    *SrvAddr,
168   IN     CHAR8               *BootFile,
169   IN     UINT16              Length
170   );
171 
172 
173 /**
174   Parse the Boot File Parameter option.
175 
176   @param[in]  BootFilePara      The pointer to the boot file parameter option data.
177   @param[out] BootFileSize      The pointer to the parsed boot file size.
178 
179   @retval EFI_SUCCESS     Successfully obtained the boot file size from parameter option.
180   @retval EFI_NOT_FOUND   Failed to extract the boot file size from parameter option.
181 
182 **/
183 EFI_STATUS
184 PxeBcExtractBootFileParam (
185   IN  CHAR8                  *BootFilePara,
186   OUT UINT16                 *BootFileSize
187   );
188 
189 
190 /**
191   Parse the cached DHCPv6 packet, including all the options.
192 
193   @param[in]  Cache6           The pointer to a cached DHCPv6 packet.
194 
195   @retval     EFI_SUCCESS      Parsed the DHCPv6 packet successfully.
196   @retval     EFI_DEVICE_ERROR Failed to parse and invalid packet.
197 
198 **/
199 EFI_STATUS
200 PxeBcParseDhcp6Packet (
201   IN PXEBC_DHCP6_PACKET_CACHE  *Cache6
202   );
203 
204 
205 /**
206   Register the ready address by Ip6Config protocol.
207 
208   @param[in]  Private             The pointer to the PxeBc private data.
209   @param[in]  Address             The pointer to the ready address.
210 
211   @retval     EFI_SUCCESS         Registered the address succesfully.
212   @retval     Others              Failed to register the address.
213 
214 **/
215 EFI_STATUS
216 PxeBcRegisterIp6Address (
217   IN PXEBC_PRIVATE_DATA            *Private,
218   IN EFI_IPv6_ADDRESS              *Address
219   );
220 
221 
222 /**
223   Unregister the address by Ip6Config protocol.
224 
225   @param[in]  Private             The pointer to the PxeBc private data.
226 
227 **/
228 VOID
229 PxeBcUnregisterIp6Address (
230   IN PXEBC_PRIVATE_DATA            *Private
231   );
232 
233 
234 /**
235   Build and send out the request packet for the bootfile, and parse the reply.
236 
237   @param[in]  Private               The pointer to the PxeBc private data.
238   @param[in]  Type                  PxeBc option boot item type.
239   @param[in]  Layer                 The pointer to the option boot item layer.
240   @param[in]  UseBis                Use BIS or not.
241   @param[in]  DestIp                The pointer to the server address.
242 
243   @retval     EFI_SUCCESS           Successfully discovered theboot file.
244   @retval     EFI_OUT_OF_RESOURCES  Failed to allocate resource.
245   @retval     EFI_NOT_FOUND         Can't get the PXE reply packet.
246   @retval     Others                Failed to discover boot file.
247 
248 **/
249 EFI_STATUS
250 PxeBcDhcp6Discover (
251   IN  PXEBC_PRIVATE_DATA            *Private,
252   IN  UINT16                        Type,
253   IN  UINT16                        *Layer,
254   IN  BOOLEAN                       UseBis,
255   IN  EFI_IP_ADDRESS                *DestIp
256   );
257 
258 /**
259   Set the IP6 policy to Automatic.
260 
261   @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.
262 
263   @retval     EFI_SUCCESS         Switch the IP policy succesfully.
264   @retval     Others              Unexpect error happened.
265 
266 **/
267 EFI_STATUS
268 PxeBcSetIp6Policy (
269   IN PXEBC_PRIVATE_DATA            *Private
270   );
271 
272 /**
273   This function will register the station IP address and flush IP instance to start using the new IP address.
274 
275   @param[in]  Private             The pointer to PXEBC_PRIVATE_DATA.
276 
277   @retval     EFI_SUCCESS         The new IP address has been configured successfully.
278   @retval     Others              Failed to configure the address.
279 
280 **/
281 EFI_STATUS
282 PxeBcSetIp6Address (
283   IN  PXEBC_PRIVATE_DATA              *Private
284   );
285 
286 /**
287   Start the DHCPv6 S.A.R.R. process to acquire the IPv6 address and other PXE boot information.
288 
289   @param[in]  Private           The pointer to the PxeBc private data.
290   @param[in]  Dhcp6             The pointer to EFI_DHCP6_PROTOCOL.
291 
292   @retval EFI_SUCCESS           The S.A.R.R. process successfully finished.
293   @retval Others                Failed to finish the S.A.R.R. process.
294 
295 **/
296 EFI_STATUS
297 PxeBcDhcp6Sarr (
298   IN PXEBC_PRIVATE_DATA            *Private,
299   IN EFI_DHCP6_PROTOCOL            *Dhcp6
300   );
301 
302 #endif
303 
304