2 * Copyright 2013-2014 Intel Corporation - All Rights Reserved
5 #include <syslinux/firmware.h>
6 #include <syslinux/pxe_api.h>
9 #include "fs/pxe/pxe.h"
11 const struct url_scheme url_schemes
[] = {
12 { "tftp", tftp_open
, 0 },
13 { "http", http_open
, O_DIRECTORY
},
14 { "ftp", ftp_open
, O_DIRECTORY
},
19 * Network stack-specific initialization
21 void net_core_init(void)
26 void pxe_init_isr(void) {}
27 void gpxe_init(void) {}
28 void pxe_idle_init(void) {}
35 #define DNS_MAX_SERVERS 4 /* Max no of DNS servers */
36 uint32_t dns_server
[DNS_MAX_SERVERS
] = {0, };
38 __export
uint32_t pxe_dns(const char *name
)
41 * Return failure on an empty input... this can happen during
42 * some types of URL parsing, and this is the easiest place to
51 int pxe_init(bool quiet
)
57 status
= LibLocateHandle(ByProtocol
, &PxeBaseCodeProtocol
,
58 NULL
, &nr_handles
, &handles
);
59 if (status
!= EFI_SUCCESS
) {
61 Print(L
"No PXE Base Code Protocol\n");
68 #define EDHCP_BUF_LEN 8192
70 struct embedded_dhcp_options
{
76 uint8_t dhcp_data
[EDHCP_BUF_LEN
];
77 } __attribute__((aligned(16)));
79 struct embedded_dhcp_options embedded_dhcp_options
=
81 .magic
[0] = 0x2a171ead,
82 .magic
[1] = 0x0600e65e,
83 .magic
[2] = 0x4025a4e4,
84 .magic
[3] = 0x42388fc8,
87 .buffer_size
= EDHCP_BUF_LEN
,
90 void net_parse_dhcp(void)
92 EFI_PXE_BASE_CODE_MODE
*mode
;
93 EFI_PXE_BASE_CODE
*bc
;
94 unsigned int pkt_len
= sizeof(EFI_PXE_BASE_CODE_PACKET
);
100 status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, image_device_handle
,
101 &PxeBaseCodeProtocol
, (void **)&bc
);
102 if (status
!= EFI_SUCCESS
) {
103 Print(L
"Failed to lookup PxeBaseCodeProtocol\n");
110 * Parse any "before" hardcoded options
112 parse_dhcp_options(embedded_dhcp_options
.dhcp_data
,
113 embedded_dhcp_options
.bdhcp_len
, 0);
116 * Get the DHCP client identifiers (BIOS/PXE query info 1)
118 Print(L
"Getting cached packet ");
119 parse_dhcp(&mode
->DhcpDiscover
.Dhcpv4
, pkt_len
, 1);
121 * We don't use flags from the request packet, so
122 * this is a good time to initialize DHCPMagic...
123 * Initialize it to 1 meaning we will accept options found;
124 * in earlier versions of PXELINUX bit 0 was used to indicate
125 * we have found option 208 with the appropriate magic number;
126 * we no longer require that, but MAY want to re-introduce
127 * it in the future for vendor encapsulated options.
129 *(char *)&DHCPMagic
= 1;
132 * Get the BOOTP/DHCP packet that brought us file (and an IP
133 * address). This lives in the DHCPACK packet (BIOS/PXE query info 2)
135 parse_dhcp(&mode
->DhcpAck
.Dhcpv4
, pkt_len
, 2);
138 * Get the boot file and other info. This lives in the CACHED_REPLY
139 * packet (BIOS/PXE query info 3)
141 EFI_PXE_BASE_CODE_DHCPV4_PACKET
* pkt_v4
= NULL
;
143 if (mode
->PxeReplyReceived
)
144 pkt_v4
= &mode
->PxeReply
.Dhcpv4
;
145 else if (mode
->ProxyOfferReceived
)
146 pkt_v4
= &mode
->ProxyOffer
.Dhcpv4
;
149 parse_dhcp(pkt_v4
, pkt_len
, 3);
152 * Save away MAC address (assume this is in query info 2. If this
153 * turns out to be problematic it might be better getting it from
154 * the query info 1 packet
156 hardlen
= mode
->DhcpAck
.Dhcpv4
.BootpHwAddrLen
;
157 MAC_len
= hardlen
> 16 ? 0 : hardlen
;
158 MAC_type
= mode
->DhcpAck
.Dhcpv4
.BootpHwType
;
159 memcpy(MAC
, mode
->DhcpAck
.Dhcpv4
.BootpHwAddr
, MAC_len
);
164 * Parse any "after" hardcoded options
166 parse_dhcp_options(embedded_dhcp_options
.dhcp_data
+
167 embedded_dhcp_options
.bdhcp_len
,
168 embedded_dhcp_options
.adhcp_len
, 0);
171 sprintf(dst
, "%u.%u.%u.%u",
172 ((const uint8_t *)&ip
)[0],
173 ((const uint8_t *)&ip
)[1],
174 ((const uint8_t *)&ip
)[2],
175 ((const uint8_t *)&ip
)[3]);
177 Print(L
"My IP is %a\n", dst
);
179 Print(L
" NO valid IP found.\n");