/*-
* Copyright (c) 2001 Doug Rabson
* Copyright (c) 2002, 2006 Marcel Moolenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
status = uefi_call_wrapper(net->Transmit, 7, net, 0, (UINTN)len, pkt, NULL,
NULL, NULL);
if (EFI_ERROR(status))
return -1;
/* Wait for the buffer to be transmitted */
do {
buf = NULL; /* XXX Is this needed? */
status = uefi_call_wrapper(net->GetStatus, 3, net, NULL, &buf);
/*
* XXX EFI1.1 and the E1000 card returns a different
* address than we gave. Sigh.
*/
} while (!EFI_ERROR(status) && buf == NULL);
/* XXX How do we deal with status != EFI_SUCCESS now? */
return EFI_ERROR(status) ? -1 : len;
}
nifs = 0;
for (i = 0; i < nhandles; i++) {
status = uefi_call_wrapper(BS->HandleProtocol, 3, handles[i],
&DevicePathProtocol, (void **)&dp0);
if (EFI_ERROR(status))
continue;
found = false;
for (dp = dp0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
if (DevicePathType(dp) == MESSAGING_DEVICE_PATH &&
DevicePathSubType(dp) == MSG_MAC_ADDR_DP) {
found = true;
break;
}
}
if (!found)
continue;
status = uefi_call_wrapper(BS->OpenProtocol, 6, handles[i],
&SimpleNetworkProtocol, (void **)&net, IH, NULL,
EFI_OPEN_PROTOCOL_EXCLUSIVE);
if (EFI_ERROR(status)) {
printf("Unable to open network interface %" PRIuMAX
" for exclusive access: %" PRIxMAX "\n",
(uintmax_t)i, (uintmax_t)status);
}
found = false;
for (pdp = NULL, dp = dp0;
!IsDevicePathEnd(dp);
pdp = dp, dp = NextDevicePathNode(dp)) {
if (DevicePathType(dp) == HARDWARE_DEVICE_PATH) {
if (DevicePathSubType(dp) == HW_PCI_DP)
found = efi_net_pci_probe(&enis[nifs],
dp, pdp);
break;
}
}
if (found) {
enis[nifs].net = net;
enis[nifs].bootdev = efi_pxe_match_booted_interface(
&net->Mode->CurrentAddress, net->Mode->HwAddressSize);
enis[nifs].pktbufsz = net->Mode->MaxPacketSize +
ETHER_EXT_LEN;
enis[nifs].pktbuf = alloc(enis[nifs].pktbufsz);
if (enis[nifs].pktbuf == NULL) {
while (i-- > 0) {
dealloc(enis[i].pktbuf, enis[i].pktbufsz);
if (i == 0)
break;
}
dealloc(enis, nhandles * sizeof(*enis));
FreePool(handles);
return;
}
nifs++;
}
}
for (i = 0; i < efinetif.netif_nifs; i++) {
dif = &efinetif.netif_ifs[i];
eni = dif->dif_private;
net = eni->net;
printf("net net%d", dif->dif_unit);
if (net->Mode != NULL) {
for (UINT32 x = 0; x < net->Mode->HwAddressSize; x++) {
printf("%c%02x", x == 0 ? ' ' : ':',
net->Mode->CurrentAddress.Addr[x]);
}
}
if (eni->bus.type == BI_BUS_PCI) {
printf(" pci%d,%d,%d", (eni->bus.tag >> 8) & 0xff,
(eni->bus.tag >> 3) & 0x1f, eni->bus.tag & 0x7);
}
if (eni->bootdev)
printf(" pxeboot");
printf("\n");
}
}
int
efi_net_get_booted_interface_unit(void)
{
const struct netif_dif *dif;
const struct efinetinfo *eni;
int i;
for (i = 0; i < efinetif.netif_nifs; i++) {
dif = &efinetif.netif_ifs[i];
eni = dif->dif_private;
if (eni->bootdev)
return dif->dif_unit;
}
return -1;
}