Home | History | Annotate | Line # | Download | only in net
if_media.h revision 1.63
      1 /*	$NetBSD: if_media.h,v 1.63 2019/04/24 05:07:20 msaitoh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1997
     35  *	Jonathan Stone and Jason R. Thorpe.  All rights reserved.
     36  *
     37  * This software is derived from information provided by Matt Thomas.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. All advertising materials mentioning features or use of this software
     48  *    must display the following acknowledgement:
     49  *	This product includes software developed by Jonathan Stone
     50  *	and Jason R. Thorpe for the NetBSD Project.
     51  * 4. The names of the authors may not be used to endorse or promote products
     52  *    derived from this software without specific prior written permission.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     55  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     56  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     57  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     58  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     59  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     60  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     61  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     62  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  * SUCH DAMAGE.
     65  */
     66 
     67 #ifndef _NET_IF_MEDIA_H_
     68 #define _NET_IF_MEDIA_H_
     69 
     70 /*
     71  * Prototypes and definitions for BSD/OS-compatible network interface
     72  * media selection.
     73  *
     74  * Where it is safe to do so, this code strays slightly from the BSD/OS
     75  * design.  Software which uses the API (device drivers, basically)
     76  * shouldn't notice any difference.
     77  *
     78  * Many thanks to Matt Thomas for providing the information necessary
     79  * to implement this interface.
     80  */
     81 
     82 #ifdef _KERNEL
     83 #include <sys/queue.h>
     84 #endif /*_KERNEL */
     85 
     86 /*
     87  * Status bits. THIS IS NOT A MEDIA WORD.
     88  */
     89 #define	IFM_AVALID	0x00000001	/* Active bit valid */
     90 #define	IFM_ACTIVE	0x00000002	/* Interface attached to working net */
     91 
     92 /*
     93  * if_media Options word:
     94  *	Bits	Use
     95  *	----	-------
     96  *	0-4	Media subtype		MAX SUBTYPE == 31!
     97  *	5-7	Media type
     98  *	8-15	Type specific options
     99  *	16-18	Mode (for multi-mode devices)
    100  *	19	(Reserved for Future Use)
    101  *	20-27	Shared (global) options
    102  *	28-31	Instance
    103  *
    104  *   3                     2                   1
    105  *   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
    106  *  +-------+---------------+-+-----+---------------+-----+---------+
    107  *  |       |               |R|     |               |     |         |
    108  *  | IMASK |     GMASK     |F|MMASK|     OMASK     |NMASK|  TMASK  |
    109  *  |       |               |U|     |               |     |         |
    110  *  +-------+---------------+-+-----+---------------+-----+---------+
    111  *   <----->                   <--->                 <--->
    112  *  IFM_INST()               IFM_MODE()            IFM_TYPE()
    113  *
    114  *           <------------->         <------------->       <------->
    115  *                        IFM_OPTIONS()                  IFM_SUBTYPE()
    116  */
    117 
    118 /*
    119  * Masks
    120  */
    121 #define	IFM_NMASK	0x000000e0	/* Network type */
    122 #define	IFM_TMASK	0x0000001f	/* Media sub-type */
    123 #define	IFM_IMASK	0xf0000000	/* Instance */
    124 #define	IFM_ISHIFT	28		/* Instance shift */
    125 #define	IFM_OMASK	0x0000ff00	/* Type specific options */
    126 #define	IFM_MMASK	0x00070000	/* Mode */
    127 #define	IFM_MSHIFT	16		/* Mode shift */
    128 #define	IFM_GMASK	0x0ff00000	/* Global options */
    129 
    130 /*
    131  * Macros to extract various bits of information from the media word.
    132  */
    133 #define	IFM_TYPE(x)	((x) & IFM_NMASK)
    134 #define	IFM_SUBTYPE(x)	((x) & IFM_TMASK)
    135 #define	IFM_INST(x)	(((x) & IFM_IMASK) >> IFM_ISHIFT)
    136 #define	IFM_OPTIONS(x)	((x) & (IFM_OMASK | IFM_GMASK))
    137 #define	IFM_MODE(x)	((x) & IFM_MMASK)
    138 
    139 #define	IFM_TYPE_MATCH(dt, t)						\
    140 	(IFM_TYPE((dt)) == 0 || IFM_TYPE((dt)) == IFM_TYPE((t)))
    141 
    142 #define	IFM_INST_MAX	IFM_INST(IFM_IMASK)
    143 #define	IFM_INST_ANY	((u_int) -1)
    144 
    145 /* Mask of "status valid" bits, for ifconfig(8). */
    146 #define	IFM_STATUS_VALID IFM_AVALID
    147 
    148 /* List of "status valid" bits, for ifconfig(8). */
    149 #define	IFM_STATUS_VALID_LIST {						\
    150 	IFM_AVALID,							\
    151 	0,								\
    152 }
    153 
    154 /*
    155  * Macro to create a media word.
    156  */
    157 #define	IFM_MAKEWORD(type, subtype, options, instance)			\
    158 	((type) | (subtype) | (options) | ((instance) << IFM_ISHIFT))
    159 #define	IFM_MAKEMODE(mode) \
    160 	(((mode) << IFM_MSHIFT) & IFM_MMASK)
    161 
    162 /*
    163  * Media type (IFM_NMASK).
    164  */
    165 #define	IFM_GENERIC	0x00000000    /* Only used for link status reporting */
    166 #define	IFM_ETHER	0x00000020
    167 #define	IFM_TOKEN	0x00000040
    168 #define	IFM_FDDI	0x00000060
    169 #define	IFM_IEEE80211	0x00000080
    170 #define	IFM_CARP	0x000000c0     /* Common Address Redundancy Protocol */
    171 
    172 #define	IFM_NMIN	IFM_ETHER	/* lowest Network type */
    173 #define	IFM_NMAX	IFM_NMASK	/* highest Network type */
    174 
    175 /*
    176  * Shared media sub-types (IFM_TMASK)
    177  */
    178 #define	IFM_AUTO	0		/* Autoselect best media */
    179 #define	IFM_MANUAL	1		/* Jumper/dipswitch selects media */
    180 #define	IFM_NONE	2		/* Deselect all media */
    181 
    182 /*
    183  * Shared (global) options (IFM_GMASK)
    184  */
    185 #define	IFM_FDX		0x00100000	/* Force full duplex */
    186 #define	IFM_HDX		0x00200000	/* Force half duplex */
    187 #define	IFM_FLOW	0x00400000	/* enable hardware flow control */
    188 #define	IFM_FLAG0	0x01000000	/* Driver defined flag */
    189 #define	IFM_FLAG1	0x02000000	/* Driver defined flag */
    190 #define	IFM_FLAG2	0x04000000	/* Driver defined flag */
    191 #define	IFM_LOOP	0x08000000	/* Put hardware in loopback */
    192 
    193 /*
    194  * 0: Generic (IFM_GENERIC). Only used for link status reporting.
    195  * No any media specific flag.
    196  */
    197 
    198 /*
    199  * 1: Ethernet (IFM_ETHER)
    200  */
    201 #define	IFM_10_T	3		/* 10BaseT - RJ45 */
    202 #define	IFM_10_2	4		/* 10Base2 - Thinnet */
    203 #define	IFM_10_5	5		/* 10Base5 - AUI */
    204 #define	IFM_100_TX	6		/* 100BaseTX - RJ45 */
    205 #define	IFM_100_FX	7		/* 100BaseFX - Fiber */
    206 #define	IFM_100_T4	8		/* 100BaseT4 - 4 pair cat 3 */
    207 #define	IFM_100_VG	9		/* 100VG-AnyLAN */
    208 #define	IFM_100_T2	10		/* 100BaseT2 */
    209 #define	IFM_1000_SX	11		/* 1000BaseSX - multi-mode fiber */
    210 #define	IFM_10_STP	12		/* 10BaseT over shielded TP */
    211 #define	IFM_10_FL	13		/* 10BaseFL - Fiber */
    212 #define	IFM_1000_LX	14		/* 1000baseLX - single-mode fiber */
    213 #define	IFM_1000_CX	15		/* 1000baseCX - 150ohm STP */
    214 #define	IFM_1000_T	16		/* 1000baseT - 4 pair cat 5 */
    215 #define	IFM_HPNA_1	17		/* HomePNA 1.0 (1Mb/s) */
    216 #define	IFM_10G_LR	18		/* 10GbaseLR - single-mode fiber */
    217 #define	IFM_10G_SR	19		/* 10GBase-SR 850nm Multi-mode */
    218 #define	IFM_10G_CX4	20		/* 10GBase CX4 copper */
    219 #define	IFM_2500_SX	21		/* 2500baseSX - multi-mode fiber */
    220 #define	IFM_1000_BX10	22		/* 1000base-BX10 */
    221 #define	IFM_10G_TWINAX	23		/* 10GBase Twinax copper */
    222 #define	IFM_10G_TWINAX_LONG	24	/* 10GBase Twinax Long copper */
    223 #define	IFM_10G_LRM	25		/* 10GBase-LRM 850nm Multi-mode */
    224 #define	IFM_10G_T	26		/* 10GBase-T - RJ45 */
    225 #define	IFM_1000_KX	27		/* 1000base-KX backplane */
    226 #define	IFM_2500_KX	28		/* 2500base-KX backplane */
    227 #define	IFM_2500_T	29		/* 2500base-T - RJ45 */
    228 #define	IFM_5000_T	30		/* 5Gbase-T - RJ45 */
    229 /* IFM_OMASK bits */
    230 #define	IFM_ETH_MASTER	0x00000100	/* master mode (1000baseT) */
    231 #define	IFM_ETH_RXPAUSE	0x00000200	/* receive PAUSE frames */
    232 #define	IFM_ETH_TXPAUSE	0x00000400	/* transmit PAUSE frames */
    233 
    234 /* Ethernet flow control mask */
    235 #define	IFM_ETH_FMASK	(IFM_FLOW | IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE)
    236 
    237 /*
    238  * 2: Token ring (IFM_TOKEN)
    239  */
    240 #define	IFM_TOK_STP4	3		/* Shielded twisted pair 4m - DB9 */
    241 #define	IFM_TOK_STP16	4		/* Shielded twisted pair 16m - DB9 */
    242 #define	IFM_TOK_UTP4	5		/* Unshielded twisted pair 4m - RJ45 */
    243 #define	IFM_TOK_UTP16	6		/* Unshielded twisted pair 16m - RJ45 */
    244 /* IFM_OMASK bits */
    245 #define	IFM_TOK_ETR	0x00000200	/* Early token release */
    246 #define	IFM_TOK_SRCRT	0x00000400	/* Enable source routing features */
    247 #define	IFM_TOK_ALLR	0x00000800	/* All routes / Single route bcast */
    248 
    249 /*
    250  * 3: FDDI (IFM_FDDI)
    251  */
    252 #define	IFM_FDDI_SMF	3		/* Single-mode fiber */
    253 #define	IFM_FDDI_MMF	4		/* Multi-mode fiber */
    254 #define	IFM_FDDI_UTP	5		/* CDDI / UTP */
    255 #define	IFM_FDDI_DA	0x00000100	/* Dual attach / single attach */
    256 
    257 /*
    258  * 4: IEEE 802.11 Wireless (IFM_IEEE80211)
    259  */
    260 #define	IFM_IEEE80211_FH1	3	/* Frequency Hopping 1Mbps */
    261 #define	IFM_IEEE80211_FH2	4	/* Frequency Hopping 2Mbps */
    262 #define	IFM_IEEE80211_DS2	5	/* Direct Sequence 2Mbps */
    263 #define	IFM_IEEE80211_DS5	6	/* Direct Sequence 5Mbps*/
    264 #define	IFM_IEEE80211_DS11	7	/* Direct Sequence 11Mbps*/
    265 #define	IFM_IEEE80211_DS1	8	/* Direct Sequence 1Mbps */
    266 #define	IFM_IEEE80211_DS22	9	/* Direct Sequence 22Mbps */
    267 #define	IFM_IEEE80211_OFDM6	10	/* OFDM 6Mbps */
    268 #define	IFM_IEEE80211_OFDM9	11	/* OFDM 9Mbps */
    269 #define	IFM_IEEE80211_OFDM12	12	/* OFDM 12Mbps */
    270 #define	IFM_IEEE80211_OFDM18	13	/* OFDM 18Mbps */
    271 #define	IFM_IEEE80211_OFDM24	14	/* OFDM 24Mbps */
    272 #define	IFM_IEEE80211_OFDM36	15	/* OFDM 36Mbps */
    273 #define	IFM_IEEE80211_OFDM48	16	/* OFDM 48Mbps */
    274 #define	IFM_IEEE80211_OFDM54	17	/* OFDM 54Mbps */
    275 #define	IFM_IEEE80211_OFDM72	18	/* OFDM 72Mbps */
    276 #define	IFM_IEEE80211_DS354k	19	/* Direct Sequence 354Kbps */
    277 #define	IFM_IEEE80211_DS512k	20	/* Direct Sequence 512Kbps */
    278 #define	IFM_IEEE80211_OFDM3	21	/* OFDM 3Mbps */
    279 #define	IFM_IEEE80211_OFDM4	22	/* OFDM 4.5Mbps */
    280 #define	IFM_IEEE80211_OFDM27	23	/* OFDM 27Mbps */
    281 /* NB: not enough bits to express MCS fully */
    282 #define	IFM_IEEE80211_MCS	24	/* HT MCS rate */
    283 
    284 /* IFM_OMASK bits */
    285 #define	IFM_IEEE80211_ADHOC	0x00000100	/* Operate in Adhoc mode */
    286 #define	IFM_IEEE80211_HOSTAP	0x00000200	/* Operate in Host AP mode */
    287 #define	IFM_IEEE80211_MONITOR	0x00000400	/* Operate in Monitor mode */
    288 #define	IFM_IEEE80211_TURBO	0x00000800	/* Operate in Turbo mode */
    289 #define	IFM_IEEE80211_IBSS	0x00001000	/* Operate in IBSS mode */
    290 #define	IFM_IEEE80211_WDS 	0x00002000	/* Operate as an WDS master */
    291 #define	IFM_IEEE80211_MBSS	0x00004000	/* Operate in MBSS mode */
    292 
    293 /* Operating mode (IFM_MMASK) for multi-mode devices */
    294 #define	IFM_IEEE80211_11A	0x00010000	/* 5 GHz, OFDM mode */
    295 #define	IFM_IEEE80211_11B	0x00020000	/* Direct Sequence mode */
    296 #define	IFM_IEEE80211_11G	0x00030000	/* 2 GHz, CCK mode */
    297 #define	IFM_IEEE80211_FH	0x00040000	/* 2 GHz, GFSK mode */
    298 #define	IFM_IEEE80211_11NA	0x00050000	/* 5Ghz, HT mode */
    299 #define	IFM_IEEE80211_11NG	0x00060000	/* 2Ghz, HT mode */
    300 
    301 
    302 /*
    303  * 6: Common Address Redundancy Protocol (IFM_CARP)
    304  * No any media specific flag.
    305  */
    306 
    307 /*
    308  * NetBSD extension not defined in the BSDI API.  This is used in various
    309  * places to get the canonical description for a given type/subtype.
    310  *
    311  * In the subtype and mediaopt descriptions, the valid TYPE bits are OR'd
    312  * in to indicate which TYPE the subtype/option corresponds to.  If no
    313  * TYPE is present, it is a shared media/mediaopt.
    314  *
    315  * Note that these are parsed case-insensitive.
    316  *
    317  * Order is important.  The first matching entry is the canonical name
    318  * for a media type; subsequent matches are aliases.
    319  */
    320 struct ifmedia_description {
    321 	int	ifmt_word;		/* word value; may be masked */
    322 	const char *ifmt_string;	/* description */
    323 };
    324 
    325 #define	IFM_TYPE_DESCRIPTIONS {						\
    326 	{ IFM_ETHER,			"Ethernet" },			\
    327 	{ IFM_ETHER,			"ether" },			\
    328 	{ IFM_TOKEN,			"TokenRing" },			\
    329 	{ IFM_TOKEN,			"token" },			\
    330 	{ IFM_FDDI,			"FDDI" },			\
    331 	{ IFM_IEEE80211,		"IEEE802.11" },			\
    332 	{ IFM_CARP,			"CARP" },			\
    333 	{ 0, NULL },							\
    334 }
    335 
    336 #define	IFM_SUBTYPE_DESCRIPTIONS {					\
    337 	{ IFM_AUTO,			"autoselect" },			\
    338 	{ IFM_AUTO,			"auto" },			\
    339 	{ IFM_MANUAL,			"manual" },			\
    340 	{ IFM_NONE,			"none" },			\
    341 									\
    342 	{ IFM_ETHER | IFM_10_T,		"10baseT" },			\
    343 	{ IFM_ETHER | IFM_10_T,		"10baseT/UTP" },		\
    344 	{ IFM_ETHER | IFM_10_T,		"UTP" },			\
    345 	{ IFM_ETHER | IFM_10_T,		"10UTP" },			\
    346 	{ IFM_ETHER | IFM_10_T,		"10BASE-T" },			\
    347 	{ IFM_ETHER | IFM_10_2,		"10base2" },			\
    348 	{ IFM_ETHER | IFM_10_2,		"10base2/BNC" },		\
    349 	{ IFM_ETHER | IFM_10_2,		"BNC" },			\
    350 	{ IFM_ETHER | IFM_10_2,		"10BNC" },			\
    351 	{ IFM_ETHER | IFM_10_2,		"10BASE2" },			\
    352 	{ IFM_ETHER | IFM_10_5,		"10base5" },			\
    353 	{ IFM_ETHER | IFM_10_5,		"10base5/AUI" },		\
    354 	{ IFM_ETHER | IFM_10_5,		"AUI" },			\
    355 	{ IFM_ETHER | IFM_10_5,		"10AUI" },			\
    356 	{ IFM_ETHER | IFM_10_5,		"10BASE5" },			\
    357 	{ IFM_ETHER | IFM_100_TX,	"100baseTX" },			\
    358 	{ IFM_ETHER | IFM_100_TX,	"100TX" },			\
    359 	{ IFM_ETHER | IFM_100_TX,	"100BASE-TX" },			\
    360 	{ IFM_ETHER | IFM_100_FX,	"100baseFX" },			\
    361 	{ IFM_ETHER | IFM_100_FX,	"100FX" },			\
    362 	{ IFM_ETHER | IFM_100_FX,	"100BASE-FX" },			\
    363 	{ IFM_ETHER | IFM_100_T4,	"100baseT4" },			\
    364 	{ IFM_ETHER | IFM_100_T4,	"100T4" },			\
    365 	{ IFM_ETHER | IFM_100_T4,	"100BASE-T4" },			\
    366 	{ IFM_ETHER | IFM_100_VG,	"100baseVG" },			\
    367 	{ IFM_ETHER | IFM_100_VG,	"100VG" },			\
    368 	{ IFM_ETHER | IFM_100_VG,	"100VG-AnyLAN" },		\
    369 	{ IFM_ETHER | IFM_100_T2,	"100baseT2" },			\
    370 	{ IFM_ETHER | IFM_100_T2,	"100T2" },			\
    371 	{ IFM_ETHER | IFM_100_T2,	"100BASE-T2" },			\
    372 	{ IFM_ETHER | IFM_1000_SX,	"1000baseSX" },			\
    373 	{ IFM_ETHER | IFM_1000_SX,	"1000SX" },			\
    374 	{ IFM_ETHER | IFM_1000_SX,	"1000BASE-SX" },		\
    375 	{ IFM_ETHER | IFM_10_STP,	"10baseSTP" },			\
    376 	{ IFM_ETHER | IFM_10_STP,	"STP" },			\
    377 	{ IFM_ETHER | IFM_10_STP,	"10STP" },			\
    378 	{ IFM_ETHER | IFM_10_STP,	"10BASE-STP" },			\
    379 	{ IFM_ETHER | IFM_10_FL,	"10baseFL" },			\
    380 	{ IFM_ETHER | IFM_10_FL,	"FL" },				\
    381 	{ IFM_ETHER | IFM_10_FL,	"10FL" },			\
    382 	{ IFM_ETHER | IFM_10_FL,	"10BASE-FL" },			\
    383 	{ IFM_ETHER | IFM_1000_LX,	"1000baseLX" },			\
    384 	{ IFM_ETHER | IFM_1000_LX,	"1000LX" },			\
    385 	{ IFM_ETHER | IFM_1000_LX,	"1000BASE-LX" },		\
    386 	{ IFM_ETHER | IFM_1000_CX,	"1000baseCX" },			\
    387 	{ IFM_ETHER | IFM_1000_CX,	"1000CX" },			\
    388 	{ IFM_ETHER | IFM_1000_CX,	"1000BASE-CX" },		\
    389 	{ IFM_ETHER | IFM_1000_BX10,	"1000BASE-BX10" },		\
    390 	{ IFM_ETHER | IFM_1000_KX,	"1000BASE-KX" },		\
    391 	{ IFM_ETHER | IFM_1000_KX,	"1000baseKX" },			\
    392 	{ IFM_ETHER | IFM_1000_T,	"1000baseT" },			\
    393 	{ IFM_ETHER | IFM_1000_T,	"1000T" },			\
    394 	{ IFM_ETHER | IFM_1000_T,	"1000BASE-T" },			\
    395 	{ IFM_ETHER | IFM_HPNA_1,	"HomePNA1" },			\
    396 	{ IFM_ETHER | IFM_HPNA_1,	"HPNA1" },			\
    397 	{ IFM_ETHER | IFM_2500_KX | IFM_FDX,	"2500BASE-KX" },	\
    398 	{ IFM_ETHER | IFM_2500_KX | IFM_FDX,	"2500baseKX" },		\
    399 	{ IFM_ETHER | IFM_2500_T | IFM_FDX,	"2.5GBASE-T" },		\
    400 	{ IFM_ETHER | IFM_2500_T | IFM_FDX,	"2500baseT" },		\
    401 	{ IFM_ETHER | IFM_5000_T | IFM_FDX,	"5GBASE-T" },		\
    402 	{ IFM_ETHER | IFM_5000_T | IFM_FDX,	"5GbaseT" },		\
    403 	{ IFM_ETHER | IFM_10G_LR | IFM_FDX,	"10GbaseLR" },		\
    404 	{ IFM_ETHER | IFM_10G_LR | IFM_FDX,	"10GLR" },		\
    405 	{ IFM_ETHER | IFM_10G_LR | IFM_FDX,	"10GBASE-LR" },		\
    406 	{ IFM_ETHER | IFM_10G_SR | IFM_FDX,	"10GbaseSR" },		\
    407 	{ IFM_ETHER | IFM_10G_SR | IFM_FDX,	"10GSR" },		\
    408 	{ IFM_ETHER | IFM_10G_SR | IFM_FDX,	"10GBASE-SR" },		\
    409 	{ IFM_ETHER | IFM_10G_LRM | IFM_FDX,	"10Gbase-LRM" },	\
    410 	{ IFM_ETHER | IFM_10G_TWINAX | IFM_FDX,	"10Gbase-Twinax" },	\
    411 	{ IFM_ETHER | IFM_10G_TWINAX_LONG | IFM_FDX, "10Gbase-Twinax-Long" },\
    412 	{ IFM_ETHER | IFM_10G_T | IFM_FDX,	"10Gbase-T" },		\
    413 	{ IFM_ETHER | IFM_10G_CX4 | IFM_FDX,	"10GbaseCX4" },		\
    414 	{ IFM_ETHER | IFM_10G_CX4 | IFM_FDX,	"10GCX4" },		\
    415 	{ IFM_ETHER | IFM_10G_CX4 | IFM_FDX,	"10GBASE-CX4" },	\
    416 	{ IFM_ETHER | IFM_2500_SX | IFM_FDX,	"2500baseSX" },		\
    417 	{ IFM_ETHER | IFM_2500_SX | IFM_FDX,	"2500SX" },		\
    418 									\
    419 	{ IFM_TOKEN | IFM_TOK_STP4,	"DB9/4Mbit" },			\
    420 	{ IFM_TOKEN | IFM_TOK_STP4,	"4STP" },			\
    421 	{ IFM_TOKEN | IFM_TOK_STP16,	"DB9/16Mbit" },			\
    422 	{ IFM_TOKEN | IFM_TOK_STP16,	"16STP" },			\
    423 	{ IFM_TOKEN | IFM_TOK_UTP4,	"UTP/4Mbit" },			\
    424 	{ IFM_TOKEN | IFM_TOK_UTP4,	"4UTP" },			\
    425 	{ IFM_TOKEN | IFM_TOK_UTP16,	"UTP/16Mbit" },			\
    426 	{ IFM_TOKEN | IFM_TOK_UTP16,	"16UTP" },			\
    427 									\
    428 	{ IFM_FDDI | IFM_FDDI_SMF,	"Single-mode" },		\
    429 	{ IFM_FDDI | IFM_FDDI_SMF,	"SMF" },			\
    430 	{ IFM_FDDI | IFM_FDDI_MMF,	"Multi-mode" },			\
    431 	{ IFM_FDDI | IFM_FDDI_MMF,	"MMF" },			\
    432 	{ IFM_FDDI | IFM_FDDI_UTP,	"UTP" },			\
    433 	{ IFM_FDDI | IFM_FDDI_UTP,	"CDDI" },			\
    434 									\
    435 	/*								\
    436 	 * Short-hand for common media+option combos.			\
    437 	 */								\
    438 	{ IFM_ETHER | IFM_10_T | IFM_FDX,	"10baseT-FDX" },	\
    439 	{ IFM_ETHER | IFM_10_T | IFM_FDX,	"10BASE-T-FDX" },	\
    440 	{ IFM_ETHER | IFM_100_TX | IFM_FDX,	"100baseTX-FDX" },	\
    441 	{ IFM_ETHER | IFM_100_TX | IFM_FDX,	"100BASE-TX-FDX" },	\
    442 	{ IFM_ETHER | IFM_1000_T | IFM_FDX,	"1000baseT-FDX" },	\
    443 									\
    444 	/*								\
    445 	 * IEEE 802.11							\
    446 	 */								\
    447 	{ IFM_IEEE80211 | IFM_IEEE80211_FH1,	"FH1" },		\
    448 	{ IFM_IEEE80211 | IFM_IEEE80211_FH2,	"FH2" },		\
    449 	{ IFM_IEEE80211 | IFM_IEEE80211_DS1,	"DS1" },		\
    450 	{ IFM_IEEE80211 | IFM_IEEE80211_DS2,	"DS2" },		\
    451 	{ IFM_IEEE80211 | IFM_IEEE80211_DS5,	"DS5" },		\
    452 	{ IFM_IEEE80211 | IFM_IEEE80211_DS11,	"DS11" },		\
    453 	{ IFM_IEEE80211 | IFM_IEEE80211_DS22,	"DS22" },		\
    454 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM6,	"OFDM6" },		\
    455 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM9,	"OFDM9" },		\
    456 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM12,	"OFDM12" },		\
    457 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM18,	"OFDM18" },		\
    458 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM24,	"OFDM24" },		\
    459 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM36,	"OFDM36" },		\
    460 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM48,	"OFDM48" },		\
    461 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM54,	"OFDM54" },		\
    462 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM72,	"OFDM72" },		\
    463 	{ IFM_IEEE80211 | IFM_IEEE80211_DS354k, "DS/354Kbps" },		\
    464 	{ IFM_IEEE80211 | IFM_IEEE80211_DS512k, "DS/512Kbps" },		\
    465 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM3,	"OFDM/3Mbps" },		\
    466 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM4,	"OFDM/4.5Mbps" },	\
    467 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM27, "OFDM/27Mbps" },	\
    468 									\
    469 	{ 0, NULL },							\
    470 }
    471 
    472 #define IFM_MODE_DESCRIPTIONS {						\
    473 	{ IFM_AUTO,				"autoselect" },		\
    474 	{ IFM_AUTO,				"auto" },		\
    475 	{ IFM_IEEE80211 | IFM_IEEE80211_11A,	"11a" },		\
    476 	{ IFM_IEEE80211 | IFM_IEEE80211_11B,	"11b" },		\
    477 	{ IFM_IEEE80211 | IFM_IEEE80211_11G,	"11g" },		\
    478 	{ IFM_IEEE80211 | IFM_IEEE80211_FH,	"fh" },			\
    479 	{ IFM_IEEE80211 | IFM_IEEE80211_11NA,	"11na" },		\
    480 	{ IFM_IEEE80211 | IFM_IEEE80211_11NG,	"11ng" },		\
    481 	{ 0, NULL },							\
    482 }
    483 
    484 #define	IFM_OPTION_DESCRIPTIONS {					\
    485 	{ IFM_FDX,			"full-duplex" },		\
    486 	{ IFM_FDX,			"fdx" },			\
    487 	{ IFM_HDX,			"half-duplex" },		\
    488 	{ IFM_HDX,			"hdx" },			\
    489 	{ IFM_FLOW,			"flowcontrol" },		\
    490 	{ IFM_FLOW,			"flow" },			\
    491 	{ IFM_FLAG0,			"flag0" },			\
    492 	{ IFM_FLAG1,			"flag1" },			\
    493 	{ IFM_FLAG2,			"flag2" },			\
    494 	{ IFM_LOOP,			"loopback" },			\
    495 	{ IFM_LOOP,			"hw-loopback"},			\
    496 	{ IFM_LOOP,			"loop" },			\
    497 									\
    498 	{ IFM_ETHER | IFM_ETH_MASTER,	"master" },			\
    499 	{ IFM_ETHER | IFM_ETH_RXPAUSE,	"rxpause" },			\
    500 	{ IFM_ETHER | IFM_ETH_TXPAUSE,	"txpause" },			\
    501 									\
    502 	{ IFM_TOKEN | IFM_TOK_ETR,	"EarlyTokenRelease" },		\
    503 	{ IFM_TOKEN | IFM_TOK_ETR,	"ETR" },			\
    504 	{ IFM_TOKEN | IFM_TOK_SRCRT,	"SourceRouting" },		\
    505 	{ IFM_TOKEN | IFM_TOK_SRCRT,	"SRCRT" },			\
    506 	{ IFM_TOKEN | IFM_TOK_ALLR,	"AllRoutes" },			\
    507 	{ IFM_TOKEN | IFM_TOK_ALLR,	"ALLR" },			\
    508 									\
    509 	{ IFM_FDDI | IFM_FDDI_DA,	"dual-attach" },		\
    510 	{ IFM_FDDI | IFM_FDDI_DA,	"das" },			\
    511 									\
    512 	{ IFM_IEEE80211 | IFM_IEEE80211_ADHOC,	"adhoc" },		\
    513 	{ IFM_IEEE80211 | IFM_IEEE80211_HOSTAP,	"hostap" },		\
    514 	{ IFM_IEEE80211 | IFM_IEEE80211_MONITOR,"monitor" },		\
    515 	{ IFM_IEEE80211 | IFM_IEEE80211_TURBO,	"turbo" },		\
    516 	{ IFM_IEEE80211 | IFM_IEEE80211_IBSS,	"ibss" },		\
    517 	{ IFM_IEEE80211 | IFM_IEEE80211_WDS,	"wds" },		\
    518 	{ IFM_IEEE80211 | IFM_IEEE80211_MBSS,	"mesh" },		\
    519 									\
    520 	{ 0, NULL },							\
    521 }
    522 
    523 /*
    524  * Baudrate descriptions for the various media types.
    525  */
    526 struct ifmedia_baudrate {
    527 	int	ifmb_word;		/* media word */
    528 	uint64_t	ifmb_baudrate;		/* corresponding baudrate */
    529 };
    530 
    531 #define	IFM_BAUDRATE_DESCRIPTIONS {					\
    532 	{ IFM_ETHER | IFM_10_T,		IF_Mbps(10) },			\
    533 	{ IFM_ETHER | IFM_10_2,		IF_Mbps(10) },			\
    534 	{ IFM_ETHER | IFM_10_5,		IF_Mbps(10) },			\
    535 	{ IFM_ETHER | IFM_100_TX,	IF_Mbps(100) },			\
    536 	{ IFM_ETHER | IFM_100_FX,	IF_Mbps(100) },			\
    537 	{ IFM_ETHER | IFM_100_T4,	IF_Mbps(100) },			\
    538 	{ IFM_ETHER | IFM_100_VG,	IF_Mbps(100) },			\
    539 	{ IFM_ETHER | IFM_100_T2,	IF_Mbps(100) },			\
    540 	{ IFM_ETHER | IFM_1000_SX,	IF_Mbps(1000) },		\
    541 	{ IFM_ETHER | IFM_10_STP,	IF_Mbps(10) },			\
    542 	{ IFM_ETHER | IFM_10_FL,	IF_Mbps(10) },			\
    543 	{ IFM_ETHER | IFM_1000_LX,	IF_Mbps(1000) },		\
    544 	{ IFM_ETHER | IFM_1000_CX,	IF_Mbps(1000) },		\
    545 	{ IFM_ETHER | IFM_1000_T,	IF_Mbps(1000) },		\
    546 	{ IFM_ETHER | IFM_HPNA_1,	IF_Mbps(1) },			\
    547 	{ IFM_ETHER | IFM_10G_LR,	IF_Gbps(10ULL) },		\
    548 	{ IFM_ETHER | IFM_10G_SR,	IF_Gbps(10ULL) },		\
    549 	{ IFM_ETHER | IFM_10G_CX4,	IF_Gbps(10ULL) },		\
    550 	{ IFM_ETHER | IFM_2500_SX,	IF_Mbps(2500ULL) },		\
    551 	{ IFM_ETHER | IFM_1000_BX10,	IF_Mbps(1000ULL) },		\
    552 	{ IFM_ETHER | IFM_10G_TWINAX,	IF_Gbps(10) },			\
    553 	{ IFM_ETHER | IFM_10G_TWINAX_LONG, IF_Gbps(10) },		\
    554 	{ IFM_ETHER | IFM_10G_LRM,	IF_Gbps(10) },			\
    555 	{ IFM_ETHER | IFM_10G_T,	IF_Gbps(10) },			\
    556 	{ IFM_ETHER | IFM_1000_KX,	IF_Mbps(1000ULL) },		\
    557 	{ IFM_ETHER | IFM_2500_KX,	IF_Mbps(2500ULL) },		\
    558 	{ IFM_ETHER | IFM_2500_T,	IF_Mbps(2500ULL) },		\
    559 	{ IFM_ETHER | IFM_5000_T,	IF_Mbps(5000ULL) },		\
    560 									\
    561 	{ IFM_TOKEN | IFM_TOK_STP4,	IF_Mbps(4) },			\
    562 	{ IFM_TOKEN | IFM_TOK_STP16,	IF_Mbps(16) },			\
    563 	{ IFM_TOKEN | IFM_TOK_UTP4,	IF_Mbps(4) },			\
    564 	{ IFM_TOKEN | IFM_TOK_UTP16,	IF_Mbps(16) },			\
    565 									\
    566 	{ IFM_FDDI | IFM_FDDI_SMF,	IF_Mbps(100) },			\
    567 	{ IFM_FDDI | IFM_FDDI_MMF,	IF_Mbps(100) },			\
    568 	{ IFM_FDDI | IFM_FDDI_UTP,	IF_Mbps(100) },			\
    569 									\
    570 	{ IFM_IEEE80211 | IFM_IEEE80211_FH1,	IF_Mbps(1) },		\
    571 	{ IFM_IEEE80211 | IFM_IEEE80211_FH2,	IF_Mbps(2) },		\
    572 	{ IFM_IEEE80211 | IFM_IEEE80211_DS2,	IF_Mbps(2) },		\
    573 	{ IFM_IEEE80211 | IFM_IEEE80211_DS5,	IF_Kbps(5500) },	\
    574 	{ IFM_IEEE80211 | IFM_IEEE80211_DS11,	IF_Mbps(11) },		\
    575 	{ IFM_IEEE80211 | IFM_IEEE80211_DS1,	IF_Mbps(1) },		\
    576 	{ IFM_IEEE80211 | IFM_IEEE80211_DS22,	IF_Mbps(22) },		\
    577 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM6,	IF_Mbps(6) },		\
    578 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM9,	IF_Mbps(9) },		\
    579 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM12,	IF_Mbps(12) },		\
    580 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM18,	IF_Mbps(18) },		\
    581 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM24,	IF_Mbps(24) },		\
    582 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM36,	IF_Mbps(36) },		\
    583 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM48,	IF_Mbps(48) },		\
    584 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM54,	IF_Mbps(54) },		\
    585 	{ IFM_IEEE80211 | IFM_IEEE80211_OFDM72,	IF_Mbps(72) },		\
    586 									\
    587 	{ 0, 0 },							\
    588 }
    589 
    590 /*
    591  * Status bit descriptions for the various media types.
    592  */
    593 struct ifmedia_status_description {
    594 	int	ifms_type;
    595 	int	ifms_valid;
    596 	int	ifms_bit;
    597 	const char *ifms_string[2];
    598 };
    599 
    600 #define	IFM_STATUS_DESC(ifms, bit)					\
    601 	(ifms)->ifms_string[((ifms)->ifms_bit & (bit)) ? 1 : 0]
    602 
    603 #define	IFM_STATUS_DESCRIPTIONS {					\
    604 	{ IFM_GENERIC,		IFM_AVALID,	IFM_ACTIVE,		\
    605 	  { "no network", "active" } },					\
    606 									\
    607 	{ IFM_ETHER,		IFM_AVALID,	IFM_ACTIVE,		\
    608 	  { "no carrier", "active" } },					\
    609 									\
    610 	{ IFM_FDDI,		IFM_AVALID,	IFM_ACTIVE,		\
    611 	  { "no ring", "inserted" } },					\
    612 									\
    613 	{ IFM_TOKEN,		IFM_AVALID,	IFM_ACTIVE,		\
    614 	  { "no ring", "inserted" } },					\
    615 									\
    616 	{ IFM_IEEE80211,	IFM_AVALID,	IFM_ACTIVE,		\
    617 	  { "no network", "active" } },					\
    618 									\
    619 	{ IFM_CARP,		IFM_AVALID,	IFM_ACTIVE,		\
    620 	    { "backup", "master" } },					\
    621 									\
    622 	{ 0,			0,		0,			\
    623 	  { NULL, NULL } },						\
    624 }
    625 
    626 #ifdef _KERNEL
    627 /*
    628  * Driver callbacks for media status and change requests.
    629  */
    630 typedef	int (*ifm_change_cb_t)(struct ifnet *);
    631 typedef	void (*ifm_stat_cb_t)(struct ifnet *, struct ifmediareq *);
    632 
    633 /*
    634  * In-kernel representation of a single supported media type.
    635  */
    636 struct ifmedia_entry {
    637 	TAILQ_ENTRY(ifmedia_entry) ifm_list;
    638 	u_int	ifm_media;	/* description of this media attachment */
    639 	u_int	ifm_data;	/* for driver-specific use */
    640 	void	*ifm_aux;	/* for driver-specific use */
    641 };
    642 
    643 /*
    644  * One of these goes into a network interface's softc structure.
    645  * It is used to keep general media state.
    646  */
    647 struct ifmedia {
    648 	u_int	ifm_mask;	/* mask of changes we don't care about */
    649 	u_int	ifm_media;	/* current user-set media word */
    650 	struct ifmedia_entry *ifm_cur;	/* currently selected media */
    651 	TAILQ_HEAD(, ifmedia_entry) ifm_list; /* list of all supported media */
    652 	ifm_change_cb_t	ifm_change;	/* media change driver callback */
    653 	ifm_stat_cb_t	ifm_status;	/* media status driver callback */
    654 };
    655 
    656 /* Initialize an interface's struct if_media field. */
    657 void	ifmedia_init(struct ifmedia *, int, ifm_change_cb_t, ifm_stat_cb_t);
    658 
    659 int	ifmedia_change(struct ifmedia *, struct ifnet *);
    660 
    661 /* Add one supported medium to a struct ifmedia. */
    662 void	ifmedia_add(struct ifmedia *, int, int, void *);
    663 
    664 /* Add an array (of ifmedia_entry) media to a struct ifmedia. */
    665 void	ifmedia_list_add(struct ifmedia *, struct ifmedia_entry *, int);
    666 
    667 /* Set default media type on initialization. */
    668 void	ifmedia_set(struct ifmedia *ifm, int mword);
    669 
    670 /* Common ioctl function for getting/setting media, called by driver. */
    671 int	ifmedia_ioctl(struct ifnet *, struct ifreq *, struct ifmedia *, u_long);
    672 
    673 /* Look up a media entry. */
    674 struct ifmedia_entry *ifmedia_match(struct ifmedia *, u_int, u_int);
    675 
    676 /* Delete all media for a given media instance */
    677 void	ifmedia_delete_instance(struct ifmedia *, u_int);
    678 
    679 /* Compute baudrate for a given media. */
    680 uint64_t ifmedia_baudrate(int);
    681 
    682 /* Remove all media */
    683 void	ifmedia_removeall(struct ifmedia *);
    684 
    685 #else
    686 /* Functions for converting media to/from strings, in libutil/if_media.c */
    687 const char *get_media_type_string(int);
    688 const char *get_media_subtype_string(int);
    689 const char *get_media_mode_string(int);
    690 const char *get_media_option_string(int *);
    691 int	get_media_mode(int, const char *);
    692 int	get_media_subtype(int, const char *);
    693 int	get_media_options(int, const char *, char **);
    694 int	lookup_media_word(struct ifmedia_description *, int, const char *);
    695 #endif /* _KERNEL */
    696 
    697 #endif /* !_NET_IF_MEDIA_H_ */
    698