Home | History | Annotate | Line # | Download | only in pxeboot
      1  1.18  christos /*	$NetBSD: pxe.c,v 1.18 2013/10/20 19:47:28 christos 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.18  christos extern 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.12   tsutsui readudp(struct iodesc *d, void *pkt, size_t len, saseconds_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.11  christos 	(void)memset(ur, 0, 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.14    cegger pxe_netif_open(void)
    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.11  christos 	(void)memset(uo, 0, 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.16    cegger 	memcpy(desc.myea, bootplayer.CAddr, 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.13       dsl pxe_netif_close(int sock)
    238   1.1   thorpej {
    239   1.1   thorpej 	t_PXENV_UDP_CLOSE *uc = (void *) pxe_command_buf;
    240   1.1   thorpej 
    241   1.6  drochner #ifdef NETIF_DEBUG
    242   1.6  drochner 	if (sock != 0)
    243   1.6  drochner 		printf("pxe_netif_close: sock=%d\n", sock);
    244   1.6  drochner #endif
    245   1.6  drochner 
    246   1.1   thorpej 	uc->status = 0;
    247   1.1   thorpej 
    248   1.1   thorpej 	pxe_call(PXENV_UDP_CLOSE);
    249   1.1   thorpej 
    250   1.1   thorpej 	if (uc->status != PXENV_STATUS_SUCCESS)
    251   1.1   thorpej 		printf("pxe_netif_end: PXENV_UDP_CLOSE failed: 0x%x\n",
    252   1.1   thorpej 		    uc->status);
    253   1.6  drochner }
    254   1.6  drochner 
    255   1.6  drochner struct iodesc *
    256  1.13       dsl socktodesc(int sock)
    257   1.6  drochner {
    258   1.6  drochner 
    259   1.6  drochner #ifdef NETIF_DEBUG
    260   1.6  drochner 	if (sock != 0)
    261   1.6  drochner 		return (0);
    262   1.6  drochner 	else
    263   1.6  drochner #endif
    264   1.6  drochner 		return (&desc);
    265   1.6  drochner }
    266   1.6  drochner 
    267   1.1   thorpej /*****************************************************************************
    268   1.1   thorpej  * PXE initialization and support routines
    269   1.1   thorpej  *****************************************************************************/
    270   1.1   thorpej 
    271   1.9     perry uint16_t pxe_command_buf_seg;
    272   1.9     perry uint16_t pxe_command_buf_off;
    273   1.1   thorpej 
    274   1.9     perry extern uint16_t bangpxe_off, bangpxe_seg;
    275   1.9     perry extern uint16_t pxenv_off, pxenv_seg;
    276   1.1   thorpej 
    277   1.1   thorpej static struct btinfo_netif bi_netif;
    278   1.1   thorpej 
    279   1.1   thorpej int
    280   1.1   thorpej pxe_init(void)
    281   1.1   thorpej {
    282   1.1   thorpej 	t_PXENV_GET_CACHED_INFO *gci = (void *) pxe_command_buf;
    283   1.1   thorpej 	t_PXENV_UNDI_GET_NIC_TYPE *gnt = (void *) pxe_command_buf;
    284   1.1   thorpej 	pxenv_t *pxenv;
    285   1.1   thorpej 	pxe_t *pxe;
    286   1.1   thorpej 	char *cp;
    287   1.1   thorpej 	int i;
    288   1.9     perry 	uint8_t cksum, *ucp;
    289   1.1   thorpej 
    290   1.1   thorpej 	/*
    291   1.1   thorpej 	 * Checking for the presence of PXE is a machine-dependent
    292   1.1   thorpej 	 * operation.  On the IA-32, this can be done two ways:
    293   1.1   thorpej 	 *
    294   1.1   thorpej 	 *	Int 0x1a function 0x5650
    295   1.1   thorpej 	 *
    296   1.1   thorpej 	 *	Scan memory for the !PXE or PXENV+ signatures
    297   1.1   thorpej 	 *
    298   1.1   thorpej 	 * We do the latter, since the Int method returns a pointer
    299   1.1   thorpej 	 * to a deprecated structure (PXENV+).
    300   1.1   thorpej 	 */
    301   1.1   thorpej 
    302   1.1   thorpej 	pxenv = NULL;
    303   1.1   thorpej 	pxe = NULL;
    304   1.1   thorpej 
    305   1.4   kanaoka 	for (cp = (char *)0xa0000; cp > (char *)0x10000; cp -= 2) {
    306   1.1   thorpej 		if (pxenv == NULL) {
    307   1.1   thorpej 			pxenv = (pxenv_t *)cp;
    308   1.7      tron 			if (MEMSTRCMP(pxenv->Signature, "PXENV+"))
    309   1.1   thorpej 				pxenv = NULL;
    310   1.1   thorpej 			else {
    311   1.9     perry 				for (i = 0, ucp = (uint8_t *)cp, cksum = 0;
    312   1.1   thorpej 				     i < pxenv->Length; i++)
    313   1.1   thorpej 					cksum += ucp[i];
    314   1.1   thorpej 				if (cksum != 0) {
    315   1.1   thorpej 					printf("pxe_init: bad cksum (0x%x) "
    316   1.1   thorpej 					    "for PXENV+ at 0x%lx\n", cksum,
    317   1.1   thorpej 					    (u_long) cp);
    318   1.1   thorpej 					pxenv = NULL;
    319   1.1   thorpej 				}
    320   1.1   thorpej 			}
    321   1.1   thorpej 		}
    322   1.1   thorpej 
    323   1.1   thorpej 		if (pxe == NULL) {
    324   1.1   thorpej 			pxe = (pxe_t *)cp;
    325   1.7      tron 			if (MEMSTRCMP(pxe->Signature, "!PXE"))
    326   1.1   thorpej 				pxe = NULL;
    327   1.1   thorpej 			else {
    328   1.9     perry 				for (i = 0, ucp = (uint8_t *)cp, cksum = 0;
    329   1.1   thorpej 				     i < pxe->StructLength; i++)
    330   1.1   thorpej 					cksum += ucp[i];
    331   1.1   thorpej 				if (cksum != 0) {
    332   1.1   thorpej 					printf("pxe_init: bad cksum (0x%x) "
    333   1.1   thorpej 					    "for !PXE at 0x%lx\n", cksum,
    334   1.1   thorpej 					    (u_long) cp);
    335   1.1   thorpej 					pxe = NULL;
    336   1.1   thorpej 				}
    337   1.1   thorpej 			}
    338   1.1   thorpej 		}
    339   1.1   thorpej 
    340   1.1   thorpej 		if (pxe != NULL && pxenv != NULL)
    341   1.1   thorpej 			break;
    342   1.1   thorpej 	}
    343   1.1   thorpej 
    344   1.1   thorpej 	if (pxe == NULL && pxenv == NULL) {
    345   1.1   thorpej 		printf("pxe_init: No PXE BIOS found.\n");
    346   1.1   thorpej 		return (1);
    347   1.1   thorpej 	}
    348   1.1   thorpej 
    349   1.1   thorpej 	if (pxenv != NULL) {
    350   1.1   thorpej 		printf("PXE BIOS Version %d.%d\n",
    351   1.1   thorpej 		    (pxenv->Version >> 8) & 0xff, pxenv->Version & 0xff);
    352   1.1   thorpej 		if (pxenv->Version >= 0x0201 && pxe != NULL) {
    353   1.1   thorpej 			/* 2.1 or greater -- don't use PXENV+ */
    354   1.1   thorpej 			pxenv = NULL;
    355   1.1   thorpej 		}
    356   1.1   thorpej 	}
    357   1.1   thorpej 
    358   1.1   thorpej 	if (pxe != NULL) {
    359   1.1   thorpej 		pxe_call = pxecall_bangpxe;
    360   1.1   thorpej 		bangpxe_off = pxe->EntryPointSP.offset;
    361   1.1   thorpej 		bangpxe_seg = pxe->EntryPointSP.segment;
    362   1.1   thorpej 	} else {
    363   1.1   thorpej 		pxe_call = pxecall_pxenv;
    364   1.1   thorpej 		pxenv_off = pxenv->RMEntry.offset;
    365   1.1   thorpej 		pxenv_seg = pxenv->RMEntry.segment;
    366   1.1   thorpej 	}
    367   1.1   thorpej 
    368   1.1   thorpej 	/*
    369   1.1   thorpej 	 * Pre-compute the segment/offset of the pxe_command_buf
    370   1.1   thorpej 	 * to make things nicer in the low-level calling glue.
    371   1.1   thorpej 	 */
    372   1.1   thorpej 	pxe_command_buf_seg = VTOPSEG(pxe_command_buf);
    373   1.1   thorpej 	pxe_command_buf_off = VTOPOFF(pxe_command_buf);
    374   1.1   thorpej 
    375   1.1   thorpej 	/*
    376   1.1   thorpej 	 * Get the cached info from the server's Discovery reply packet.
    377   1.1   thorpej 	 */
    378  1.11  christos 	(void)memset(gci, 0, sizeof(*gci));
    379   1.1   thorpej 	gci->PacketType = PXENV_PACKET_TYPE_BINL_REPLY;
    380   1.1   thorpej 	pxe_call(PXENV_GET_CACHED_INFO);
    381   1.1   thorpej 	if (gci->Status != PXENV_STATUS_SUCCESS) {
    382   1.1   thorpej 		printf("pxe_init: PXENV_GET_CACHED_INFO failed: 0x%x\n",
    383   1.1   thorpej 		    gci->Status);
    384   1.1   thorpej 		return (1);
    385   1.1   thorpej 	}
    386   1.1   thorpej 	pvbcopy((void *)((gci->Buffer.segment << 4) + gci->Buffer.offset),
    387   1.1   thorpej 	    &bootplayer, gci->BufferSize);
    388   1.1   thorpej 
    389   1.1   thorpej 	/*
    390   1.1   thorpej 	 * Get network interface information.
    391   1.1   thorpej 	 */
    392  1.11  christos 	(void)memset(gnt, 0, sizeof(*gnt));
    393   1.1   thorpej 	pxe_call(PXENV_UNDI_GET_NIC_TYPE);
    394   1.1   thorpej 
    395   1.1   thorpej 	if (gnt->Status != PXENV_STATUS_SUCCESS) {
    396   1.1   thorpej 		printf("pxe_init: PXENV_UNDI_GET_NIC_TYPE failed: 0x%x\n",
    397   1.1   thorpej 		    gnt->Status);
    398   1.1   thorpej 		return (0);
    399   1.1   thorpej 	}
    400   1.1   thorpej 
    401   1.1   thorpej 	switch (gnt->NicType) {
    402   1.1   thorpej 	case PCI_NIC:
    403   1.1   thorpej 	case CardBus_NIC:
    404   1.1   thorpej 		strncpy(bi_netif.ifname, "pxe", sizeof(bi_netif.ifname));
    405   1.1   thorpej 		bi_netif.bus = BI_BUS_PCI;
    406   1.1   thorpej 		bi_netif.addr.tag = gnt->info.pci.BusDevFunc;
    407   1.1   thorpej 
    408   1.1   thorpej 		printf("Using %s device at bus %d device %d function %d\n",
    409   1.1   thorpej 		    gnt->NicType == PCI_NIC ? "PCI" : "CardBus",
    410   1.1   thorpej 		    (gnt->info.pci.BusDevFunc >> 8) & 0xff,
    411   1.1   thorpej 		    (gnt->info.pci.BusDevFunc >> 3) & 0x1f,
    412   1.1   thorpej 		    gnt->info.pci.BusDevFunc & 0x7);
    413   1.1   thorpej 		break;
    414   1.1   thorpej 
    415   1.1   thorpej 	case PnP_NIC:
    416   1.1   thorpej 		/* XXX Make bootinfo work with this. */
    417   1.1   thorpej 		printf("Using PnP device at 0x%x\n", gnt->info.pnp.CardSelNum);
    418   1.1   thorpej 	}
    419   1.6  drochner 
    420   1.6  drochner 	printf("Ethernet address %s\n", ether_sprintf(bootplayer.CAddr));
    421   1.1   thorpej 
    422   1.1   thorpej 	return (0);
    423   1.1   thorpej }
    424   1.1   thorpej 
    425   1.1   thorpej void
    426   1.1   thorpej pxe_fini(void)
    427   1.1   thorpej {
    428   1.1   thorpej 	t_PXENV_UNDI_SHUTDOWN *shutdown = (void *) pxe_command_buf;
    429   1.1   thorpej 
    430   1.1   thorpej 	if (pxe_call == NULL)
    431   1.1   thorpej 		return;
    432   1.1   thorpej 
    433   1.1   thorpej 	pxe_call(PXENV_UNDI_SHUTDOWN);
    434   1.1   thorpej 
    435   1.1   thorpej 	if (shutdown->Status != PXENV_STATUS_SUCCESS)
    436   1.1   thorpej 		printf("pxe_fini: PXENV_UNDI_SHUTDOWN failed: 0x%x\n",
    437   1.1   thorpej 		    shutdown->Status);
    438   1.1   thorpej }
    439