1 #include <syslinux/firmware.h>
2 #include <syslinux/pxe_api.h>
5 #include "fs/pxe/pxe.h"
7 const struct url_scheme url_schemes
[] = {
8 { "tftp", tftp_open
, 0 },
9 { "http", http_open
, O_DIRECTORY
},
10 { "ftp", ftp_open
, O_DIRECTORY
},
15 * Network stack-specific initialization
17 void net_core_init(void)
22 void pxe_init_isr(void) {}
23 void gpxe_init(void) {}
24 void pxe_idle_init(void) {}
31 #define DNS_MAX_SERVERS 4 /* Max no of DNS servers */
32 uint32_t dns_server
[DNS_MAX_SERVERS
] = {0, };
34 __export
uint32_t dns_resolv(const char *name
)
37 * Return failure on an empty input... this can happen during
38 * some types of URL parsing, and this is the easiest place to
47 int pxe_init(bool quiet
)
53 status
= LibLocateHandle(ByProtocol
, &PxeBaseCodeProtocol
,
54 NULL
, &nr_handles
, &handles
);
55 if (status
!= EFI_SUCCESS
) {
57 Print(L
"No PXE Base Code Protocol\n");
64 void net_parse_dhcp(void)
66 EFI_PXE_BASE_CODE_MODE
*mode
;
67 EFI_PXE_BASE_CODE
*bc
;
68 unsigned int pkt_len
= sizeof(EFI_PXE_BASE_CODE_PACKET
);
70 EFI_HANDLE
*handles
= NULL
;
76 status
= LibLocateHandle(ByProtocol
, &PxeBaseCodeProtocol
,
77 NULL
, &nr_handles
, &handles
);
78 if (status
!= EFI_SUCCESS
)
81 /* Probably want to use IPv4 protocol to decide which handle to use */
82 status
= uefi_call_wrapper(BS
->HandleProtocol
, 3, handles
[0],
83 &PxeBaseCodeProtocol
, (void **)&bc
);
84 if (status
!= EFI_SUCCESS
) {
85 Print(L
"Failed to lookup PxeBaseCodeProtocol\n");
91 * Get the DHCP client identifiers (query info 1)
93 Print(L
"Getting cached packet ");
94 parse_dhcp(&mode
->DhcpDiscover
.Dhcpv4
, pkt_len
);
96 * We don't use flags from the request packet, so
97 * this is a good time to initialize DHCPMagic...
98 * Initialize it to 1 meaning we will accept options found;
99 * in earlier versions of PXELINUX bit 0 was used to indicate
100 * we have found option 208 with the appropriate magic number;
101 * we no longer require that, but MAY want to re-introduce
102 * it in the future for vendor encapsulated options.
104 *(char *)&DHCPMagic
= 1;
107 * Get the BOOTP/DHCP packet that brought us file (and an IP
108 * address). This lives in the DHCPACK packet (query info 2)
110 parse_dhcp(&mode
->DhcpAck
.Dhcpv4
, pkt_len
);
112 * Save away MAC address (assume this is in query info 2. If this
113 * turns out to be problematic it might be better getting it from
114 * the query info 1 packet
116 hardlen
= mode
->DhcpAck
.Dhcpv4
.BootpHwAddrLen
;
117 MAC_len
= hardlen
> 16 ? 0 : hardlen
;
118 MAC_type
= mode
->DhcpAck
.Dhcpv4
.BootpHwType
;
119 memcpy(MAC
, mode
->DhcpAck
.Dhcpv4
.BootpHwAddr
, MAC_len
);
122 * Get the boot file and other info. This lives in the CACHED_REPLY
123 * packet (query info 3)
125 parse_dhcp(&mode
->PxeReply
.Dhcpv4
, pkt_len
);
129 sprintf(dst
, "%u.%u.%u.%u",
130 ((const uint8_t *)&ip
)[0],
131 ((const uint8_t *)&ip
)[1],
132 ((const uint8_t *)&ip
)[2],
133 ((const uint8_t *)&ip
)[3]);
135 Print(L
"My IP is %a\n", dst
);