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