Home | History | Annotate | Line # | Download | only in pxeboot
pxe.c revision 1.9
      1  1.9     perry /*	$NetBSD: pxe.c,v 1.9 2005/12/26 19:24:00 perry Exp $	*/
      2  1.1   thorpej 
      3  1.1   thorpej /*
      4  1.1   thorpej  * Copyright 2001 Wasabi Systems, Inc.
      5  1.1   thorpej  * All rights reserved.
      6  1.1   thorpej  *
      7  1.1   thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.1   thorpej  *
      9  1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.1   thorpej  * modification, are permitted provided that the following conditions
     11  1.1   thorpej  * are met:
     12  1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.1   thorpej  *    must display the following acknowledgement:
     19  1.1   thorpej  *	This product includes software developed for the NetBSD Project by
     20  1.1   thorpej  *	Wasabi Systems, Inc.
     21  1.1   thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1   thorpej  *    or promote products derived from this software without specific prior
     23  1.1   thorpej  *    written permission.
     24  1.1   thorpej  *
     25  1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1   thorpej  */
     37  1.1   thorpej 
     38  1.1   thorpej /*
     39  1.1   thorpej  * Copyright (c) 2000 Alfred Perlstein <alfred (at) freebsd.org>
     40  1.1   thorpej  * All rights reserved.
     41  1.1   thorpej  * Copyright (c) 2000 Paul Saab <ps (at) freebsd.org>
     42  1.1   thorpej  * All rights reserved.
     43  1.1   thorpej  * Copyright (c) 2000 John Baldwin <jhb (at) freebsd.org>
     44  1.1   thorpej  * All rights reserved.
     45  1.1   thorpej  *
     46  1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     47  1.1   thorpej  * modification, are permitted provided that the following conditions
     48  1.1   thorpej  * are met:
     49  1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     50  1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     51  1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     53  1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     54  1.1   thorpej  *
     55  1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     56  1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57  1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58  1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     59  1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60  1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61  1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  1.1   thorpej  * SUCH DAMAGE.
     66  1.1   thorpej  */
     67  1.1   thorpej 
     68  1.1   thorpej /*
     69  1.1   thorpej  * Support for the Intel Preboot Execution Environment (PXE).
     70  1.1   thorpej  *
     71  1.1   thorpej  * PXE provides a UDP implementation as well as a UNDI network device
     72  1.1   thorpej  * driver.  UNDI is much more complicated to use than PXE UDP, so we
     73  1.1   thorpej  * use PXE UDP as a cheap and easy way to get PXE support.
     74  1.1   thorpej  */
     75  1.1   thorpej 
     76  1.1   thorpej #include <sys/param.h>
     77  1.1   thorpej #include <sys/socket.h>
     78  1.1   thorpej 
     79  1.1   thorpej #ifdef _STANDALONE
     80  1.1   thorpej #include <lib/libkern/libkern.h>
     81  1.1   thorpej #else
     82  1.1   thorpej #include <string.h>
     83  1.1   thorpej #endif
     84  1.1   thorpej 
     85  1.1   thorpej #include <netinet/in.h>
     86  1.1   thorpej #include <netinet/in_systm.h>
     87  1.1   thorpej #include <netinet/ip.h>
     88  1.1   thorpej #include <netinet/ip_var.h>
     89  1.1   thorpej #include <netinet/udp.h>
     90  1.1   thorpej #include <netinet/udp_var.h>
     91  1.1   thorpej 
     92  1.1   thorpej #include <net/if_ether.h>
     93  1.1   thorpej 
     94  1.1   thorpej #include <lib/libsa/stand.h>
     95  1.1   thorpej #include <lib/libsa/net.h>
     96  1.1   thorpej #include <lib/libsa/bootp.h>
     97  1.1   thorpej 
     98  1.1   thorpej #include <libi386.h>
     99  1.1   thorpej #include <bootinfo.h>
    100  1.1   thorpej 
    101  1.1   thorpej #include "pxeboot.h"
    102  1.1   thorpej #include "pxe.h"
    103  1.6  drochner #include "pxe_netif.h"
    104  1.1   thorpej 
    105  1.9     perry void	(*pxe_call)(uint16_t);
    106  1.1   thorpej 
    107  1.9     perry void	pxecall_bangpxe(uint16_t);	/* pxe_call.S */
    108  1.9     perry void	pxecall_pxenv(uint16_t);	/* pxe_call.S */
    109  1.1   thorpej 
    110  1.1   thorpej char pxe_command_buf[256];
    111  1.1   thorpej 
    112  1.1   thorpej BOOTPLAYER bootplayer;
    113  1.1   thorpej 
    114  1.6  drochner static struct btinfo_netif bi_netif;
    115  1.6  drochner 
    116  1.1   thorpej /*****************************************************************************
    117  1.1   thorpej  * This section is a replacement for libsa/udp.c
    118  1.1   thorpej  *****************************************************************************/
    119  1.1   thorpej 
    120  1.1   thorpej /* Caller must leave room for ethernet, ip, and udp headers in front!! */
    121  1.1   thorpej ssize_t
    122  1.1   thorpej sendudp(struct iodesc *d, void *pkt, size_t len)
    123  1.1   thorpej {
    124  1.1   thorpej 	t_PXENV_UDP_WRITE *uw = (void *) pxe_command_buf;
    125  1.1   thorpej 
    126  1.1   thorpej 	uw->status = 0;
    127  1.1   thorpej 
    128  1.1   thorpej 	uw->ip = d->destip.s_addr;
    129  1.1   thorpej 	uw->gw = gateip.s_addr;
    130  1.1   thorpej 	uw->src_port = d->myport;
    131  1.1   thorpej 	uw->dst_port = d->destport;
    132  1.1   thorpej 	uw->buffer_size = len;
    133  1.1   thorpej 	uw->buffer.segment = VTOPSEG(pkt);
    134  1.1   thorpej 	uw->buffer.offset = VTOPOFF(pkt);
    135  1.1   thorpej 
    136  1.1   thorpej 	pxe_call(PXENV_UDP_WRITE);
    137  1.1   thorpej 
    138  1.1   thorpej 	if (uw->status != PXENV_STATUS_SUCCESS) {
    139  1.1   thorpej 		/* XXX This happens a lot; it shouldn't. */
    140  1.1   thorpej 		if (uw->status != PXENV_STATUS_FAILURE)
    141  1.1   thorpej 			printf("sendudp: PXENV_UDP_WRITE failed: 0x%x\n",
    142  1.1   thorpej 			    uw->status);
    143  1.1   thorpej 		return (-1);
    144  1.1   thorpej 	}
    145  1.1   thorpej 
    146  1.1   thorpej 	return (len);
    147  1.1   thorpej }
    148  1.1   thorpej 
    149  1.1   thorpej /*
    150  1.1   thorpej  * Receive a UDP packet and validate it for us.
    151  1.1   thorpej  * Caller leaves room for the headers (Ether, IP, UDP).
    152  1.1   thorpej  */
    153  1.1   thorpej ssize_t
    154  1.1   thorpej readudp(struct iodesc *d, void *pkt, size_t len, time_t tleft)
    155  1.1   thorpej {
    156  1.1   thorpej 	t_PXENV_UDP_READ *ur = (void *) pxe_command_buf;
    157  1.1   thorpej 	struct udphdr *uh;
    158  1.1   thorpej 	struct ip *ip;
    159  1.1   thorpej 
    160  1.1   thorpej 	uh = (struct udphdr *)pkt - 1;
    161  1.1   thorpej 	ip = (struct ip *)uh - 1;
    162  1.1   thorpej 
    163  1.1   thorpej 	bzero(ur, sizeof(*ur));
    164  1.1   thorpej 
    165  1.1   thorpej 	ur->dest_ip = d->myip.s_addr;
    166  1.1   thorpej 	ur->d_port = d->myport;
    167  1.1   thorpej 	ur->buffer_size = len;
    168  1.1   thorpej 	ur->buffer.segment = VTOPSEG(pkt);
    169  1.1   thorpej 	ur->buffer.offset = VTOPOFF(pkt);
    170  1.1   thorpej 
    171  1.1   thorpej 	/* XXX Timeout unused. */
    172  1.1   thorpej 
    173  1.1   thorpej 	pxe_call(PXENV_UDP_READ);
    174  1.1   thorpej 
    175  1.1   thorpej 	if (ur->status != PXENV_STATUS_SUCCESS) {
    176  1.1   thorpej 		/* XXX This happens a lot; it shouldn't. */
    177  1.1   thorpej 		if (ur->status != PXENV_STATUS_FAILURE)
    178  1.1   thorpej 			printf("readudp: PXENV_UDP_READ_failed: 0x%0x\n",
    179  1.1   thorpej 			    ur->status);
    180  1.1   thorpej 		return (-1);
    181  1.1   thorpej 	}
    182  1.1   thorpej 
    183  1.1   thorpej 	ip->ip_src.s_addr = ur->src_ip;
    184  1.1   thorpej 	uh->uh_sport = ur->s_port;
    185  1.1   thorpej 	uh->uh_dport = d->myport;
    186  1.1   thorpej 
    187  1.5  drochner 	return (ur->buffer_size);
    188  1.1   thorpej }
    189  1.1   thorpej 
    190  1.6  drochner /*
    191  1.6  drochner  * netif layer:
    192  1.6  drochner  *  open, close, shutdown: called from dev_net.c
    193  1.6  drochner  *  socktodesc: called by network protocol modules
    194  1.6  drochner  *
    195  1.6  drochner  * We only allow one open socket.
    196  1.6  drochner  */
    197  1.1   thorpej 
    198  1.6  drochner static int pxe_inited;
    199  1.6  drochner static struct iodesc desc;
    200  1.1   thorpej 
    201  1.1   thorpej int
    202  1.6  drochner pxe_netif_open()
    203  1.1   thorpej {
    204  1.1   thorpej 	t_PXENV_UDP_OPEN *uo = (void *) pxe_command_buf;
    205  1.1   thorpej 
    206  1.6  drochner 	if (!pxe_inited) {
    207  1.6  drochner 		if (pxe_init() != 0)
    208  1.6  drochner 			return (-1);
    209  1.6  drochner 		pxe_inited = 1;
    210  1.6  drochner 	}
    211  1.6  drochner 	BI_ADD(&bi_netif, BTINFO_NETIF, sizeof(bi_netif));
    212  1.1   thorpej 
    213  1.1   thorpej 	bzero(uo, sizeof(*uo));
    214  1.1   thorpej 
    215  1.1   thorpej 	uo->src_ip = bootplayer.yip;
    216  1.1   thorpej 
    217  1.1   thorpej 	pxe_call(PXENV_UDP_OPEN);
    218  1.1   thorpej 
    219  1.1   thorpej 	if (uo->status != PXENV_STATUS_SUCCESS) {
    220  1.1   thorpej 		printf("pxe_netif_probe: PXENV_UDP_OPEN failed: 0x%x\n",
    221  1.1   thorpej 		    uo->status);
    222  1.6  drochner 		return (-1);
    223  1.1   thorpej 	}
    224  1.1   thorpej 
    225  1.6  drochner 	bcopy(bootplayer.CAddr, desc.myea, ETHER_ADDR_LEN);
    226  1.1   thorpej 
    227  1.1   thorpej 	/*
    228  1.1   thorpej 	 * Since the PXE BIOS has already done DHCP, make sure we
    229  1.1   thorpej 	 * don't reuse any of its transaction IDs.
    230  1.1   thorpej 	 */
    231  1.6  drochner 	desc.xid = bootplayer.ident;
    232  1.1   thorpej 
    233  1.6  drochner 	return (0);
    234  1.1   thorpej }
    235  1.1   thorpej 
    236  1.1   thorpej void
    237  1.6  drochner pxe_netif_close(sock)
    238  1.6  drochner 	int sock;
    239  1.1   thorpej {
    240  1.1   thorpej 	t_PXENV_UDP_CLOSE *uc = (void *) pxe_command_buf;
    241  1.1   thorpej 
    242  1.6  drochner #ifdef NETIF_DEBUG
    243  1.6  drochner 	if (sock != 0)
    244  1.6  drochner 		printf("pxe_netif_close: sock=%d\n", sock);
    245  1.6  drochner #endif
    246  1.6  drochner 
    247  1.1   thorpej 	uc->status = 0;
    248  1.1   thorpej 
    249  1.1   thorpej 	pxe_call(PXENV_UDP_CLOSE);
    250  1.1   thorpej 
    251  1.1   thorpej 	if (uc->status != PXENV_STATUS_SUCCESS)
    252  1.1   thorpej 		printf("pxe_netif_end: PXENV_UDP_CLOSE failed: 0x%x\n",
    253  1.1   thorpej 		    uc->status);
    254  1.6  drochner }
    255  1.6  drochner 
    256  1.6  drochner void
    257  1.6  drochner pxe_netif_shutdown()
    258  1.6  drochner {
    259  1.2   thorpej 
    260  1.2   thorpej 	pxe_fini();
    261  1.1   thorpej }
    262  1.1   thorpej 
    263  1.6  drochner struct iodesc *
    264  1.6  drochner socktodesc(sock)
    265  1.6  drochner 	int sock;
    266  1.6  drochner {
    267  1.6  drochner 
    268  1.6  drochner #ifdef NETIF_DEBUG
    269  1.6  drochner 	if (sock != 0)
    270  1.6  drochner 		return (0);
    271  1.6  drochner 	else
    272  1.6  drochner #endif
    273  1.6  drochner 		return (&desc);
    274  1.6  drochner }
    275  1.6  drochner 
    276  1.1   thorpej /*****************************************************************************
    277  1.1   thorpej  * PXE initialization and support routines
    278  1.1   thorpej  *****************************************************************************/
    279  1.1   thorpej 
    280  1.9     perry uint16_t pxe_command_buf_seg;
    281  1.9     perry uint16_t pxe_command_buf_off;
    282  1.1   thorpej 
    283  1.9     perry extern uint16_t bangpxe_off, bangpxe_seg;
    284  1.9     perry extern uint16_t pxenv_off, pxenv_seg;
    285  1.1   thorpej 
    286  1.1   thorpej static struct btinfo_netif bi_netif;
    287  1.1   thorpej 
    288  1.1   thorpej int
    289  1.1   thorpej pxe_init(void)
    290  1.1   thorpej {
    291  1.1   thorpej 	t_PXENV_GET_CACHED_INFO *gci = (void *) pxe_command_buf;
    292  1.1   thorpej 	t_PXENV_UNDI_GET_NIC_TYPE *gnt = (void *) pxe_command_buf;
    293  1.1   thorpej 	pxenv_t *pxenv;
    294  1.1   thorpej 	pxe_t *pxe;
    295  1.1   thorpej 	char *cp;
    296  1.1   thorpej 	int i;
    297  1.9     perry 	uint8_t cksum, *ucp;
    298  1.1   thorpej 
    299  1.1   thorpej 	/*
    300  1.1   thorpej 	 * Checking for the presence of PXE is a machine-dependent
    301  1.1   thorpej 	 * operation.  On the IA-32, this can be done two ways:
    302  1.1   thorpej 	 *
    303  1.1   thorpej 	 *	Int 0x1a function 0x5650
    304  1.1   thorpej 	 *
    305  1.1   thorpej 	 *	Scan memory for the !PXE or PXENV+ signatures
    306  1.1   thorpej 	 *
    307  1.1   thorpej 	 * We do the latter, since the Int method returns a pointer
    308  1.1   thorpej 	 * to a deprecated structure (PXENV+).
    309  1.1   thorpej 	 */
    310  1.1   thorpej 
    311  1.1   thorpej 	pxenv = NULL;
    312  1.1   thorpej 	pxe = NULL;
    313  1.1   thorpej 
    314  1.4   kanaoka 	for (cp = (char *)0xa0000; cp > (char *)0x10000; cp -= 2) {
    315  1.1   thorpej 		if (pxenv == NULL) {
    316  1.1   thorpej 			pxenv = (pxenv_t *)cp;
    317  1.7      tron 			if (MEMSTRCMP(pxenv->Signature, "PXENV+"))
    318  1.1   thorpej 				pxenv = NULL;
    319  1.1   thorpej 			else {
    320  1.9     perry 				for (i = 0, ucp = (uint8_t *)cp, cksum = 0;
    321  1.1   thorpej 				     i < pxenv->Length; i++)
    322  1.1   thorpej 					cksum += ucp[i];
    323  1.1   thorpej 				if (cksum != 0) {
    324  1.1   thorpej 					printf("pxe_init: bad cksum (0x%x) "
    325  1.1   thorpej 					    "for PXENV+ at 0x%lx\n", cksum,
    326  1.1   thorpej 					    (u_long) cp);
    327  1.1   thorpej 					pxenv = NULL;
    328  1.1   thorpej 				}
    329  1.1   thorpej 			}
    330  1.1   thorpej 		}
    331  1.1   thorpej 
    332  1.1   thorpej 		if (pxe == NULL) {
    333  1.1   thorpej 			pxe = (pxe_t *)cp;
    334  1.7      tron 			if (MEMSTRCMP(pxe->Signature, "!PXE"))
    335  1.1   thorpej 				pxe = NULL;
    336  1.1   thorpej 			else {
    337  1.9     perry 				for (i = 0, ucp = (uint8_t *)cp, cksum = 0;
    338  1.1   thorpej 				     i < pxe->StructLength; i++)
    339  1.1   thorpej 					cksum += ucp[i];
    340  1.1   thorpej 				if (cksum != 0) {
    341  1.1   thorpej 					printf("pxe_init: bad cksum (0x%x) "
    342  1.1   thorpej 					    "for !PXE at 0x%lx\n", cksum,
    343  1.1   thorpej 					    (u_long) cp);
    344  1.1   thorpej 					pxe = NULL;
    345  1.1   thorpej 				}
    346  1.1   thorpej 			}
    347  1.1   thorpej 		}
    348  1.1   thorpej 
    349  1.1   thorpej 		if (pxe != NULL && pxenv != NULL)
    350  1.1   thorpej 			break;
    351  1.1   thorpej 	}
    352  1.1   thorpej 
    353  1.1   thorpej 	if (pxe == NULL && pxenv == NULL) {
    354  1.1   thorpej 		printf("pxe_init: No PXE BIOS found.\n");
    355  1.1   thorpej 		return (1);
    356  1.1   thorpej 	}
    357  1.1   thorpej 
    358  1.1   thorpej 	if (pxenv != NULL) {
    359  1.1   thorpej 		printf("PXE BIOS Version %d.%d\n",
    360  1.1   thorpej 		    (pxenv->Version >> 8) & 0xff, pxenv->Version & 0xff);
    361  1.1   thorpej 		if (pxenv->Version >= 0x0201 && pxe != NULL) {
    362  1.1   thorpej 			/* 2.1 or greater -- don't use PXENV+ */
    363  1.1   thorpej 			pxenv = NULL;
    364  1.1   thorpej 		}
    365  1.1   thorpej 	}
    366  1.1   thorpej 
    367  1.1   thorpej 	if (pxe != NULL) {
    368  1.1   thorpej 		pxe_call = pxecall_bangpxe;
    369  1.1   thorpej 		bangpxe_off = pxe->EntryPointSP.offset;
    370  1.1   thorpej 		bangpxe_seg = pxe->EntryPointSP.segment;
    371  1.1   thorpej 	} else {
    372  1.1   thorpej 		pxe_call = pxecall_pxenv;
    373  1.1   thorpej 		pxenv_off = pxenv->RMEntry.offset;
    374  1.1   thorpej 		pxenv_seg = pxenv->RMEntry.segment;
    375  1.1   thorpej 	}
    376  1.1   thorpej 
    377  1.1   thorpej 	/*
    378  1.1   thorpej 	 * Pre-compute the segment/offset of the pxe_command_buf
    379  1.1   thorpej 	 * to make things nicer in the low-level calling glue.
    380  1.1   thorpej 	 */
    381  1.1   thorpej 	pxe_command_buf_seg = VTOPSEG(pxe_command_buf);
    382  1.1   thorpej 	pxe_command_buf_off = VTOPOFF(pxe_command_buf);
    383  1.1   thorpej 
    384  1.1   thorpej 	/*
    385  1.1   thorpej 	 * Get the cached info from the server's Discovery reply packet.
    386  1.1   thorpej 	 */
    387  1.1   thorpej 	bzero(gci, sizeof(*gci));
    388  1.1   thorpej 	gci->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
    389  1.1   thorpej 	pxe_call(PXENV_GET_CACHED_INFO);
    390  1.1   thorpej 	if (gci->Status != PXENV_STATUS_SUCCESS) {
    391  1.1   thorpej 		printf("pxe_init: PXENV_GET_CACHED_INFO failed: 0x%x\n",
    392  1.1   thorpej 		    gci->Status);
    393  1.1   thorpej 		return (1);
    394  1.1   thorpej 	}
    395  1.1   thorpej 	pvbcopy((void *)((gci->Buffer.segment << 4) + gci->Buffer.offset),
    396  1.1   thorpej 	    &bootplayer, gci->BufferSize);
    397  1.1   thorpej 
    398  1.1   thorpej 	/*
    399  1.1   thorpej 	 * Get network interface information.
    400  1.1   thorpej 	 */
    401  1.1   thorpej 	bzero(gnt, sizeof(*gnt));
    402  1.1   thorpej 	pxe_call(PXENV_UNDI_GET_NIC_TYPE);
    403  1.1   thorpej 
    404  1.1   thorpej 	if (gnt->Status != PXENV_STATUS_SUCCESS) {
    405  1.1   thorpej 		printf("pxe_init: PXENV_UNDI_GET_NIC_TYPE failed: 0x%x\n",
    406  1.1   thorpej 		    gnt->Status);
    407  1.1   thorpej 		return (0);
    408  1.1   thorpej 	}
    409  1.1   thorpej 
    410  1.1   thorpej 	switch (gnt->NicType) {
    411  1.1   thorpej 	case PCI_NIC:
    412  1.1   thorpej 	case CardBus_NIC:
    413  1.1   thorpej 		strncpy(bi_netif.ifname, "pxe", sizeof(bi_netif.ifname));
    414  1.1   thorpej 		bi_netif.bus = BI_BUS_PCI;
    415  1.1   thorpej 		bi_netif.addr.tag = gnt->info.pci.BusDevFunc;
    416  1.1   thorpej 
    417  1.1   thorpej 		printf("Using %s device at bus %d device %d function %d\n",
    418  1.1   thorpej 		    gnt->NicType == PCI_NIC ? "PCI" : "CardBus",
    419  1.1   thorpej 		    (gnt->info.pci.BusDevFunc >> 8) & 0xff,
    420  1.1   thorpej 		    (gnt->info.pci.BusDevFunc >> 3) & 0x1f,
    421  1.1   thorpej 		    gnt->info.pci.BusDevFunc & 0x7);
    422  1.1   thorpej 		break;
    423  1.1   thorpej 
    424  1.1   thorpej 	case PnP_NIC:
    425  1.1   thorpej 		/* XXX Make bootinfo work with this. */
    426  1.1   thorpej 		printf("Using PnP device at 0x%x\n", gnt->info.pnp.CardSelNum);
    427  1.1   thorpej 	}
    428  1.6  drochner 
    429  1.6  drochner 	printf("Ethernet address %s\n", ether_sprintf(bootplayer.CAddr));
    430  1.1   thorpej 
    431  1.1   thorpej 	return (0);
    432  1.1   thorpej }
    433  1.1   thorpej 
    434  1.1   thorpej void
    435  1.1   thorpej pxe_fini(void)
    436  1.1   thorpej {
    437  1.1   thorpej 	t_PXENV_UNLOAD_STACK *unload = (void *) pxe_command_buf;
    438  1.1   thorpej 	t_PXENV_UNDI_SHUTDOWN *shutdown = (void *) pxe_command_buf;
    439  1.1   thorpej 
    440  1.1   thorpej 	if (pxe_call == NULL)
    441  1.1   thorpej 		return;
    442  1.1   thorpej 
    443  1.1   thorpej 	pxe_call(PXENV_UNDI_SHUTDOWN);
    444  1.1   thorpej 
    445  1.1   thorpej 	if (shutdown->Status != PXENV_STATUS_SUCCESS)
    446  1.1   thorpej 		printf("pxe_fini: PXENV_UNDI_SHUTDOWN failed: 0x%x\n",
    447  1.1   thorpej 		    shutdown->Status);
    448  1.1   thorpej 
    449  1.1   thorpej 	pxe_call(PXENV_UNLOAD_STACK);
    450  1.1   thorpej 
    451  1.1   thorpej 	if (unload->Status != PXENV_STATUS_SUCCESS)
    452  1.1   thorpej 		printf("pxe_fini: PXENV_UNLOAD_STACK failed: 0x%x\n",
    453  1.1   thorpej 		    unload->Status);
    454  1.1   thorpej }
    455