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