10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51230Sss146032 * Common Development and Distribution License (the "License").
61230Sss146032 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211230Sss146032
220Sstevel@tonic-gate /*
23*6747Sga159272 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <socket_impl.h>
310Sstevel@tonic-gate #include <socket_inet.h>
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <sys/time.h>
340Sstevel@tonic-gate #include <sys/socket.h>
350Sstevel@tonic-gate #include <net/if.h>
360Sstevel@tonic-gate #include <net/if_arp.h>
370Sstevel@tonic-gate #include <net/if_types.h>
380Sstevel@tonic-gate #include <netinet/in_systm.h>
390Sstevel@tonic-gate #include <netinet/in.h>
400Sstevel@tonic-gate #include <netinet/if_ether.h>
410Sstevel@tonic-gate #include <sys/promif.h>
420Sstevel@tonic-gate #include <sys/prom_plat.h>
430Sstevel@tonic-gate #include <sys/salib.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate #include "mac.h"
460Sstevel@tonic-gate #include "mac_impl.h"
470Sstevel@tonic-gate #include "atm_inet.h"
480Sstevel@tonic-gate #include "ethernet_inet.h"
490Sstevel@tonic-gate #include "fddi_inet.h"
500Sstevel@tonic-gate #include "token_inet.h"
510Sstevel@tonic-gate #include "ibd_inet.h"
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * MAC layer interface
550Sstevel@tonic-gate */
560Sstevel@tonic-gate boolean_t initialized; /* Boolean state */
570Sstevel@tonic-gate struct mac_type mac_state;
580Sstevel@tonic-gate int arp_index; /* current arp table index */
590Sstevel@tonic-gate static struct arptable atable[ARP_TABLE_SIZE];
600Sstevel@tonic-gate
610Sstevel@tonic-gate struct ofw_net_types {
620Sstevel@tonic-gate char *n_name; /* OFW network media name */
630Sstevel@tonic-gate int n_type; /* IFT */
640Sstevel@tonic-gate } ofw_types[] = {
650Sstevel@tonic-gate { "atm", IFT_ATM },
660Sstevel@tonic-gate { "ethernet", IFT_ETHER },
670Sstevel@tonic-gate { "fddi", IFT_FDDI },
680Sstevel@tonic-gate { "token-ring", IFT_ISO88025 },
690Sstevel@tonic-gate { "ipib", IFT_IB }
700Sstevel@tonic-gate };
710Sstevel@tonic-gate
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * given the mac type, initialize the mac interface state.
740Sstevel@tonic-gate */
750Sstevel@tonic-gate void
mac_init(char * bootdevicename)760Sstevel@tonic-gate mac_init(char *bootdevicename)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate int type = 0;
790Sstevel@tonic-gate static char *mtu_name = "max-frame-size";
800Sstevel@tonic-gate static char *chosen_net = "chosen-network-type";
810Sstevel@tonic-gate static char *supported_net = "supported-network-types";
820Sstevel@tonic-gate static char *netiftype = "network-interface-type";
83789Sahrens pnode_t node;
840Sstevel@tonic-gate char *wp, *media_type;
850Sstevel@tonic-gate int len = 0, i;
860Sstevel@tonic-gate char tmpbuf[MAXNAMELEN];
870Sstevel@tonic-gate char devname[MAXNAMELEN];
880Sstevel@tonic-gate
890Sstevel@tonic-gate if (initialized)
900Sstevel@tonic-gate return;
910Sstevel@tonic-gate
920Sstevel@tonic-gate mac_state.mac_in_timeout = MAC_IN_TIMEOUT;
930Sstevel@tonic-gate
940Sstevel@tonic-gate #ifdef DEBUG
950Sstevel@tonic-gate printf("mac_init: device path: %s\n", bootdevicename);
960Sstevel@tonic-gate #endif /* DEBUG */
970Sstevel@tonic-gate
980Sstevel@tonic-gate if ((mac_state.mac_dev = prom_open(bootdevicename)) == 0) {
990Sstevel@tonic-gate (void) snprintf(tmpbuf, sizeof (tmpbuf),
1000Sstevel@tonic-gate "Cannot prom_open network device %s.", bootdevicename);
1010Sstevel@tonic-gate prom_panic(tmpbuf);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate (void) prom_devname_from_pathname(bootdevicename, devname);
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate #ifdef DEBUG
1070Sstevel@tonic-gate printf("mac_init: Network device name: %s\n", devname);
1080Sstevel@tonic-gate #endif /* DEBUG */
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * Ask the prom for our MTU and media type. "chosen-network-type"
1120Sstevel@tonic-gate * is of the form of "<network type>,<speed (Mbps)>,<connector type>,
1130Sstevel@tonic-gate * <duplex mode>: e.g.: "ethernet,100,rj45,full"
1140Sstevel@tonic-gate */
1150Sstevel@tonic-gate node = prom_finddevice(devname);
1160Sstevel@tonic-gate if (node != OBP_NONODE && node != OBP_BADNODE) {
1170Sstevel@tonic-gate if (prom_getproplen(node, mtu_name) == sizeof (ihandle_t)) {
1180Sstevel@tonic-gate (void) prom_getprop(node, mtu_name,
1190Sstevel@tonic-gate (caddr_t)&mac_state.mac_mtu);
1200Sstevel@tonic-gate }
1210Sstevel@tonic-gate bzero(tmpbuf, sizeof (tmpbuf));
1220Sstevel@tonic-gate /*
1230Sstevel@tonic-gate * The following order of looking for properties is
1240Sstevel@tonic-gate * from FWARC 2002/345.
1250Sstevel@tonic-gate */
1260Sstevel@tonic-gate if ((len = prom_getproplen(node, netiftype)) > 0 &&
1270Sstevel@tonic-gate len < sizeof (tmpbuf)) {
1280Sstevel@tonic-gate (void) prom_getprop(node, netiftype, tmpbuf);
1290Sstevel@tonic-gate } else if ((len = prom_getproplen(node, chosen_net)) > 0 &&
1300Sstevel@tonic-gate len < sizeof (tmpbuf)) {
1310Sstevel@tonic-gate (void) prom_getprop(node, chosen_net, tmpbuf);
1320Sstevel@tonic-gate } else if ((len = prom_getproplen(node, supported_net)) > 0 &&
1330Sstevel@tonic-gate len < sizeof (tmpbuf)) {
1340Sstevel@tonic-gate (void) prom_getprop(node, supported_net, tmpbuf);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate media_type = NULL;
1370Sstevel@tonic-gate if (len > 0) {
1380Sstevel@tonic-gate if ((wp = strstr(tmpbuf, ",")) != NULL)
1390Sstevel@tonic-gate *wp = '\0';
1400Sstevel@tonic-gate media_type = tmpbuf;
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate if (media_type != NULL) {
1430Sstevel@tonic-gate #ifdef DEBUG
1440Sstevel@tonic-gate printf("mac_init: Media type: %s\n", media_type);
1450Sstevel@tonic-gate #endif /* DEBUG */
1460Sstevel@tonic-gate for (i = 0; i < sizeof (ofw_types) /
1470Sstevel@tonic-gate sizeof (struct ofw_net_types); i++) {
1480Sstevel@tonic-gate if (strcmp(ofw_types[i].n_name,
1490Sstevel@tonic-gate media_type) == 0) {
1500Sstevel@tonic-gate type = ofw_types[i].n_type;
1510Sstevel@tonic-gate break;
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate }
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate switch (type) {
1580Sstevel@tonic-gate case IFT_ATM:
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate * ATM is currently treated mostly like ethernet,
1610Sstevel@tonic-gate * with the exception that the MTU is most likely
1620Sstevel@tonic-gate * different.
1630Sstevel@tonic-gate */
1640Sstevel@tonic-gate mac_state.mac_type = IFT_ATM;
1650Sstevel@tonic-gate mac_state.mac_arp_timeout = ATM_ARP_TIMEOUT;
1660Sstevel@tonic-gate mac_state.mac_in_timeout = ATM_IN_TIMEOUT;
1670Sstevel@tonic-gate if (mac_state.mac_mtu == 0)
1680Sstevel@tonic-gate mac_state.mac_mtu = ATMSIZE;
1690Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t);
1700Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len);
1710Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL)
1720Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory.");
1730Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev,
1740Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0)
1750Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address.");
1760Sstevel@tonic-gate mac_state.mac_arp = ether_arp;
1770Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp;
1780Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len;
1790Sstevel@tonic-gate mac_state.mac_input = ether_input;
1800Sstevel@tonic-gate mac_state.mac_output = ether_output;
1810Sstevel@tonic-gate break;
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate case IFT_FDDI:
1840Sstevel@tonic-gate /*
1850Sstevel@tonic-gate * FDDI is currently treated mostly like ethernet,
1860Sstevel@tonic-gate * with the exception that the MTU is most likely
1870Sstevel@tonic-gate * different.
1880Sstevel@tonic-gate */
1890Sstevel@tonic-gate mac_state.mac_type = IFT_FDDI;
1900Sstevel@tonic-gate mac_state.mac_arp_timeout = FDDI_ARP_TIMEOUT;
1910Sstevel@tonic-gate mac_state.mac_in_timeout = FDDI_IN_TIMEOUT;
1920Sstevel@tonic-gate if (mac_state.mac_mtu == 0)
1930Sstevel@tonic-gate mac_state.mac_mtu = FDDISIZE;
1940Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t);
1950Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len);
1960Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL)
1970Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory.");
1980Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev,
1990Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0)
2000Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address.");
2010Sstevel@tonic-gate mac_state.mac_arp = ether_arp;
2020Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp;
2030Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len;
2040Sstevel@tonic-gate mac_state.mac_input = ether_input;
2050Sstevel@tonic-gate mac_state.mac_output = ether_output;
2060Sstevel@tonic-gate break;
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate case IFT_ISO88025:
2090Sstevel@tonic-gate /*
2100Sstevel@tonic-gate * Token ring is currently treated mostly like ethernet,
2110Sstevel@tonic-gate * with the exception that the MTU is most likely different.
2120Sstevel@tonic-gate */
2130Sstevel@tonic-gate mac_state.mac_type = IFT_ISO88025;
2140Sstevel@tonic-gate mac_state.mac_arp_timeout = TOKEN_ARP_TIMEOUT;
2150Sstevel@tonic-gate mac_state.mac_in_timeout = TOKEN_IN_TIMEOUT;
2160Sstevel@tonic-gate if (mac_state.mac_mtu == 0)
2170Sstevel@tonic-gate mac_state.mac_mtu = TOKENSIZE;
2180Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t);
2190Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len);
2200Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL)
2210Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory.");
2220Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev,
2230Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0)
2240Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address.");
2250Sstevel@tonic-gate mac_state.mac_arp = ether_arp;
2260Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp;
2270Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len;
2280Sstevel@tonic-gate mac_state.mac_input = ether_input;
2290Sstevel@tonic-gate mac_state.mac_output = ether_output;
2300Sstevel@tonic-gate break;
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate case IFT_IB:
2330Sstevel@tonic-gate mac_state.mac_type = IFT_IB;
2340Sstevel@tonic-gate ibd_init();
2350Sstevel@tonic-gate break;
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate case IFT_ETHER:
2380Sstevel@tonic-gate /* FALLTHRU - default to ethernet */
2390Sstevel@tonic-gate default:
2400Sstevel@tonic-gate mac_state.mac_type = IFT_ETHER;
2410Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE;
2420Sstevel@tonic-gate mac_state.mac_arp_timeout = ETHER_ARP_TIMEOUT;
2430Sstevel@tonic-gate mac_state.mac_in_timeout = ETHER_IN_TIMEOUT;
2440Sstevel@tonic-gate if (mac_state.mac_mtu == 0)
2450Sstevel@tonic-gate mac_state.mac_mtu = ETHERSIZE;
2460Sstevel@tonic-gate mac_state.mac_addr_len = sizeof (ether_addr_t);
2470Sstevel@tonic-gate mac_state.mac_addr_buf = bkmem_alloc(mac_state.mac_addr_len);
2480Sstevel@tonic-gate if (mac_state.mac_addr_buf == NULL)
2490Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate memory.");
2500Sstevel@tonic-gate if (prom_getmacaddr(mac_state.mac_dev,
2510Sstevel@tonic-gate (caddr_t)mac_state.mac_addr_buf) != 0)
2520Sstevel@tonic-gate prom_panic("mac_init: Cannot obtain MAC address.");
2530Sstevel@tonic-gate mac_state.mac_arp = ether_arp;
2540Sstevel@tonic-gate mac_state.mac_rarp = ether_revarp;
2550Sstevel@tonic-gate mac_state.mac_header_len = ether_header_len;
2560Sstevel@tonic-gate mac_state.mac_input = ether_input;
2570Sstevel@tonic-gate mac_state.mac_output = ether_output;
2580Sstevel@tonic-gate break;
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate mac_state.mac_buf = bkmem_alloc(mac_state.mac_mtu);
2620Sstevel@tonic-gate if (mac_state.mac_buf == NULL)
2630Sstevel@tonic-gate prom_panic("mac_init: Cannot allocate netbuf memory.");
2640Sstevel@tonic-gate else
2650Sstevel@tonic-gate initialized = B_TRUE;
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate void
mac_fini()2690Sstevel@tonic-gate mac_fini()
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate if (mac_state.mac_addr_buf != NULL) {
2720Sstevel@tonic-gate bkmem_free((caddr_t)mac_state.mac_addr_buf,
2730Sstevel@tonic-gate mac_state.mac_addr_len);
2740Sstevel@tonic-gate mac_state.mac_addr_buf = NULL;
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate if (mac_state.mac_buf != NULL) {
2770Sstevel@tonic-gate bkmem_free(mac_state.mac_buf, mac_state.mac_mtu);
2780Sstevel@tonic-gate mac_state.mac_buf = NULL;
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate (void) prom_close(mac_state.mac_dev);
2810Sstevel@tonic-gate initialized = B_FALSE;
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate /* MAC layer specific socket initialization */
2850Sstevel@tonic-gate void
mac_socket_init(struct inetboot_socket * isp)2860Sstevel@tonic-gate mac_socket_init(struct inetboot_socket *isp)
2870Sstevel@tonic-gate {
2880Sstevel@tonic-gate isp->input[MEDIA_LVL] = mac_state.mac_input;
2890Sstevel@tonic-gate isp->output[MEDIA_LVL] = mac_state.mac_output;
2900Sstevel@tonic-gate isp->close[MEDIA_LVL] = NULL;
2910Sstevel@tonic-gate isp->headerlen[MEDIA_LVL] = mac_state.mac_header_len;
2920Sstevel@tonic-gate isp->in_timeout = mac_state.mac_in_timeout;
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate /*
2960Sstevel@tonic-gate * Add an entry to the ARP table. All values in table are network order.
2970Sstevel@tonic-gate * No checking is done to determine whether there's duplicates.
2980Sstevel@tonic-gate */
2990Sstevel@tonic-gate void
mac_set_arp(struct in_addr * ip,void * hp,int hl)3000Sstevel@tonic-gate mac_set_arp(struct in_addr *ip, void *hp, int hl)
3010Sstevel@tonic-gate {
3020Sstevel@tonic-gate atable[arp_index].ia.s_addr = ip->s_addr;
3030Sstevel@tonic-gate bcopy(hp, (char *)atable[arp_index].ha, hl);
3040Sstevel@tonic-gate atable[arp_index].hl = hl;
3050Sstevel@tonic-gate arp_index++;
3060Sstevel@tonic-gate if (arp_index >= ARP_TABLE_SIZE)
3070Sstevel@tonic-gate arp_index = 0;
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /*
3110Sstevel@tonic-gate * Retrieve an entry from the ARP table using network-order IP address as
3120Sstevel@tonic-gate * search criteria. HW address buffer is filled in up to hl in len. (make
3130Sstevel@tonic-gate * sure the buffer is big enough given the mac type)
3140Sstevel@tonic-gate *
3150Sstevel@tonic-gate * Returns TRUE if successful, FALSE otherwise. Will wait timeout milliseconds
3160Sstevel@tonic-gate * for a response.
3170Sstevel@tonic-gate */
3180Sstevel@tonic-gate int
mac_get_arp(struct in_addr * ip,void * hp,int hl,uint32_t timeout)3190Sstevel@tonic-gate mac_get_arp(struct in_addr *ip, void *hp, int hl, uint32_t timeout)
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate int i, result;
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate for (i = 0; i < ARP_TABLE_SIZE; i++) {
3240Sstevel@tonic-gate if (ip->s_addr == atable[i].ia.s_addr) {
3250Sstevel@tonic-gate bcopy((char *)atable[i].ha, hp, hl);
3260Sstevel@tonic-gate return (TRUE);
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate /* Not found. ARP for it. */
3310Sstevel@tonic-gate bzero(hp, hl);
3320Sstevel@tonic-gate result = mac_state.mac_arp(ip, hp, timeout);
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if (result) {
3350Sstevel@tonic-gate /* Cool - add it to the arp table */
3360Sstevel@tonic-gate mac_set_arp(ip, hp, hl);
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate return (result);
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate int
mac_get_mtu(void)3420Sstevel@tonic-gate mac_get_mtu(void)
3430Sstevel@tonic-gate {
3440Sstevel@tonic-gate if (!initialized)
3450Sstevel@tonic-gate return (-1);
3460Sstevel@tonic-gate else
3470Sstevel@tonic-gate return (mac_state.mac_mtu);
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate int
mac_get_dev(void)3510Sstevel@tonic-gate mac_get_dev(void)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate if (!initialized)
3540Sstevel@tonic-gate return (-1);
3550Sstevel@tonic-gate else
3560Sstevel@tonic-gate return (mac_state.mac_dev);
3570Sstevel@tonic-gate }
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate uint8_t *
mac_get_addr_buf(void)3600Sstevel@tonic-gate mac_get_addr_buf(void)
3610Sstevel@tonic-gate {
3620Sstevel@tonic-gate if (!initialized)
3630Sstevel@tonic-gate return (NULL);
3640Sstevel@tonic-gate else
3650Sstevel@tonic-gate return (mac_state.mac_addr_buf);
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate int
mac_get_addr_len(void)3690Sstevel@tonic-gate mac_get_addr_len(void)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate if (!initialized)
3720Sstevel@tonic-gate return (-1);
3730Sstevel@tonic-gate else
3740Sstevel@tonic-gate return (mac_state.mac_addr_len);
3750Sstevel@tonic-gate }
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate int
mac_get_type(void)3780Sstevel@tonic-gate mac_get_type(void)
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate if (!initialized)
3810Sstevel@tonic-gate return (-1);
3820Sstevel@tonic-gate else
3830Sstevel@tonic-gate return (mac_state.mac_type);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3861230Sss146032 void
mac_set_arp_timeout(unsigned int timeout)3871230Sss146032 mac_set_arp_timeout(unsigned int timeout)
3881230Sss146032 {
3891230Sss146032 mac_state.mac_arp_timeout =
3901230Sss146032 timeout;
3911230Sss146032 }
3921230Sss146032
3930Sstevel@tonic-gate int
mac_get_arp_timeout(void)3940Sstevel@tonic-gate mac_get_arp_timeout(void)
3950Sstevel@tonic-gate {
3960Sstevel@tonic-gate if (!initialized)
3970Sstevel@tonic-gate return (-1);
3980Sstevel@tonic-gate else
3990Sstevel@tonic-gate return (mac_state.mac_arp_timeout);
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate int
mac_get_hdr_len(void)4030Sstevel@tonic-gate mac_get_hdr_len(void)
4040Sstevel@tonic-gate {
4050Sstevel@tonic-gate if (!initialized)
4060Sstevel@tonic-gate return (-1);
4070Sstevel@tonic-gate else
4080Sstevel@tonic-gate return (mac_state.mac_header_len(NULL));
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate
4110Sstevel@tonic-gate int
mac_call_arp(struct in_addr * addr,void * buf,uint32_t timeout)4120Sstevel@tonic-gate mac_call_arp(struct in_addr *addr, void *buf, uint32_t timeout)
4130Sstevel@tonic-gate {
4140Sstevel@tonic-gate return (mac_state.mac_arp(addr, buf, timeout));
4150Sstevel@tonic-gate }
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate void
mac_call_rarp(void)4180Sstevel@tonic-gate mac_call_rarp(void)
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate mac_state.mac_rarp();
4210Sstevel@tonic-gate }
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate /*
4240Sstevel@tonic-gate * Map a IFT_ type to an RFC 1700 arp hwtype.
4250Sstevel@tonic-gate */
4260Sstevel@tonic-gate uint8_t
mac_arp_type(uint8_t ift_type)4270Sstevel@tonic-gate mac_arp_type(uint8_t ift_type)
4280Sstevel@tonic-gate {
4290Sstevel@tonic-gate uint8_t arptype;
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate switch (ift_type) {
4320Sstevel@tonic-gate case IFT_ISO88025:
4330Sstevel@tonic-gate arptype = 4; /* token ring */
4340Sstevel@tonic-gate break;
4350Sstevel@tonic-gate case IFT_ATM:
4360Sstevel@tonic-gate arptype = 16; /* ATM */
4370Sstevel@tonic-gate break;
4380Sstevel@tonic-gate case IFT_FDDI:
4390Sstevel@tonic-gate arptype = 18; /* Fiber Channel */
4400Sstevel@tonic-gate break;
4410Sstevel@tonic-gate case IFT_IB:
4420Sstevel@tonic-gate arptype = 32; /* Infiniband */
4430Sstevel@tonic-gate break;
4440Sstevel@tonic-gate case IFT_ETHER:
4450Sstevel@tonic-gate /* FALLTHRU */
4460Sstevel@tonic-gate default:
4470Sstevel@tonic-gate arptype = 1; /* default to ethernet */
4480Sstevel@tonic-gate break;
4490Sstevel@tonic-gate }
4500Sstevel@tonic-gate return (arptype);
4510Sstevel@tonic-gate }
452