ieee80211.c (254082) | ieee80211.c (254315) |
---|---|
1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211.c 254082 2013-08-08 05:09:35Z adrian $"); | 28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211.c 254315 2013-08-14 04:24:25Z rpaulo $"); |
29 30/* 31 * IEEE 802.11 generic handler 32 */ 33#include "opt_wlan.h" 34 35#include <sys/param.h> 36#include <sys/systm.h> --- 1476 unchanged lines hidden (view full) --- 1513/* 1514 * Convert IEEE80211 rate value to ifmedia subtype. 1515 * Rate is either a legacy rate in units of 0.5Mbps 1516 * or an MCS index. 1517 */ 1518int 1519ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode) 1520{ | 29 30/* 31 * IEEE 802.11 generic handler 32 */ 33#include "opt_wlan.h" 34 35#include <sys/param.h> 36#include <sys/systm.h> --- 1476 unchanged lines hidden (view full) --- 1513/* 1514 * Convert IEEE80211 rate value to ifmedia subtype. 1515 * Rate is either a legacy rate in units of 0.5Mbps 1516 * or an MCS index. 1517 */ 1518int 1519ieee80211_rate2media(struct ieee80211com *ic, int rate, enum ieee80211_phymode mode) 1520{ |
1521#define N(a) (sizeof(a) / sizeof(a[0])) | |
1522 static const struct ratemedia rates[] = { 1523 { 2 | IFM_IEEE80211_FH, IFM_IEEE80211_FH1 }, 1524 { 4 | IFM_IEEE80211_FH, IFM_IEEE80211_FH2 }, 1525 { 2 | IFM_IEEE80211_11B, IFM_IEEE80211_DS1 }, 1526 { 4 | IFM_IEEE80211_11B, IFM_IEEE80211_DS2 }, 1527 { 11 | IFM_IEEE80211_11B, IFM_IEEE80211_DS5 }, 1528 { 22 | IFM_IEEE80211_11B, IFM_IEEE80211_DS11 }, 1529 { 44 | IFM_IEEE80211_11B, IFM_IEEE80211_DS22 }, --- 104 unchanged lines hidden (view full) --- 1634 int m; 1635 1636 /* 1637 * Check 11n rates first for match as an MCS. 1638 */ 1639 if (mode == IEEE80211_MODE_11NA) { 1640 if (rate & IEEE80211_RATE_MCS) { 1641 rate &= ~IEEE80211_RATE_MCS; | 1521 static const struct ratemedia rates[] = { 1522 { 2 | IFM_IEEE80211_FH, IFM_IEEE80211_FH1 }, 1523 { 4 | IFM_IEEE80211_FH, IFM_IEEE80211_FH2 }, 1524 { 2 | IFM_IEEE80211_11B, IFM_IEEE80211_DS1 }, 1525 { 4 | IFM_IEEE80211_11B, IFM_IEEE80211_DS2 }, 1526 { 11 | IFM_IEEE80211_11B, IFM_IEEE80211_DS5 }, 1527 { 22 | IFM_IEEE80211_11B, IFM_IEEE80211_DS11 }, 1528 { 44 | IFM_IEEE80211_11B, IFM_IEEE80211_DS22 }, --- 104 unchanged lines hidden (view full) --- 1633 int m; 1634 1635 /* 1636 * Check 11n rates first for match as an MCS. 1637 */ 1638 if (mode == IEEE80211_MODE_11NA) { 1639 if (rate & IEEE80211_RATE_MCS) { 1640 rate &= ~IEEE80211_RATE_MCS; |
1642 m = findmedia(htrates, N(htrates), rate); | 1641 m = findmedia(htrates, nitems(htrates), rate); |
1643 if (m != IFM_AUTO) 1644 return m | IFM_IEEE80211_11NA; 1645 } 1646 } else if (mode == IEEE80211_MODE_11NG) { 1647 /* NB: 12 is ambiguous, it will be treated as an MCS */ 1648 if (rate & IEEE80211_RATE_MCS) { 1649 rate &= ~IEEE80211_RATE_MCS; | 1642 if (m != IFM_AUTO) 1643 return m | IFM_IEEE80211_11NA; 1644 } 1645 } else if (mode == IEEE80211_MODE_11NG) { 1646 /* NB: 12 is ambiguous, it will be treated as an MCS */ 1647 if (rate & IEEE80211_RATE_MCS) { 1648 rate &= ~IEEE80211_RATE_MCS; |
1650 m = findmedia(htrates, N(htrates), rate); | 1649 m = findmedia(htrates, nitems(htrates), rate); |
1651 if (m != IFM_AUTO) 1652 return m | IFM_IEEE80211_11NG; 1653 } 1654 } 1655 rate &= IEEE80211_RATE_VAL; 1656 switch (mode) { 1657 case IEEE80211_MODE_11A: 1658 case IEEE80211_MODE_HALF: /* XXX good 'nuf */ 1659 case IEEE80211_MODE_QUARTER: 1660 case IEEE80211_MODE_11NA: 1661 case IEEE80211_MODE_TURBO_A: 1662 case IEEE80211_MODE_STURBO_A: | 1650 if (m != IFM_AUTO) 1651 return m | IFM_IEEE80211_11NG; 1652 } 1653 } 1654 rate &= IEEE80211_RATE_VAL; 1655 switch (mode) { 1656 case IEEE80211_MODE_11A: 1657 case IEEE80211_MODE_HALF: /* XXX good 'nuf */ 1658 case IEEE80211_MODE_QUARTER: 1659 case IEEE80211_MODE_11NA: 1660 case IEEE80211_MODE_TURBO_A: 1661 case IEEE80211_MODE_STURBO_A: |
1663 return findmedia(rates, N(rates), rate | IFM_IEEE80211_11A); | 1662 return findmedia(rates, nitems(rates), 1663 rate | IFM_IEEE80211_11A); |
1664 case IEEE80211_MODE_11B: | 1664 case IEEE80211_MODE_11B: |
1665 return findmedia(rates, N(rates), rate | IFM_IEEE80211_11B); | 1665 return findmedia(rates, nitems(rates), 1666 rate | IFM_IEEE80211_11B); |
1666 case IEEE80211_MODE_FH: | 1667 case IEEE80211_MODE_FH: |
1667 return findmedia(rates, N(rates), rate | IFM_IEEE80211_FH); | 1668 return findmedia(rates, nitems(rates), 1669 rate | IFM_IEEE80211_FH); |
1668 case IEEE80211_MODE_AUTO: 1669 /* NB: ic may be NULL for some drivers */ 1670 if (ic != NULL && ic->ic_phytype == IEEE80211_T_FH) | 1670 case IEEE80211_MODE_AUTO: 1671 /* NB: ic may be NULL for some drivers */ 1672 if (ic != NULL && ic->ic_phytype == IEEE80211_T_FH) |
1671 return findmedia(rates, N(rates), | 1673 return findmedia(rates, nitems(rates), |
1672 rate | IFM_IEEE80211_FH); 1673 /* NB: hack, 11g matches both 11b+11a rates */ 1674 /* fall thru... */ 1675 case IEEE80211_MODE_11G: 1676 case IEEE80211_MODE_11NG: 1677 case IEEE80211_MODE_TURBO_G: | 1674 rate | IFM_IEEE80211_FH); 1675 /* NB: hack, 11g matches both 11b+11a rates */ 1676 /* fall thru... */ 1677 case IEEE80211_MODE_11G: 1678 case IEEE80211_MODE_11NG: 1679 case IEEE80211_MODE_TURBO_G: |
1678 return findmedia(rates, N(rates), rate | IFM_IEEE80211_11G); | 1680 return findmedia(rates, nitems(rates), rate | IFM_IEEE80211_11G); |
1679 } 1680 return IFM_AUTO; | 1681 } 1682 return IFM_AUTO; |
1681#undef N | |
1682} 1683 1684int 1685ieee80211_media2rate(int mword) 1686{ | 1683} 1684 1685int 1686ieee80211_media2rate(int mword) 1687{ |
1687#define N(a) (sizeof(a) / sizeof(a[0])) | |
1688 static const int ieeerates[] = { 1689 -1, /* IFM_AUTO */ 1690 0, /* IFM_MANUAL */ 1691 0, /* IFM_NONE */ 1692 2, /* IFM_IEEE80211_FH1 */ 1693 4, /* IFM_IEEE80211_FH2 */ 1694 2, /* IFM_IEEE80211_DS1 */ 1695 4, /* IFM_IEEE80211_DS2 */ --- 11 unchanged lines hidden (view full) --- 1707 144, /* IFM_IEEE80211_OFDM72 */ 1708 0, /* IFM_IEEE80211_DS354k */ 1709 0, /* IFM_IEEE80211_DS512k */ 1710 6, /* IFM_IEEE80211_OFDM3 */ 1711 9, /* IFM_IEEE80211_OFDM4 */ 1712 54, /* IFM_IEEE80211_OFDM27 */ 1713 -1, /* IFM_IEEE80211_MCS */ 1714 }; | 1688 static const int ieeerates[] = { 1689 -1, /* IFM_AUTO */ 1690 0, /* IFM_MANUAL */ 1691 0, /* IFM_NONE */ 1692 2, /* IFM_IEEE80211_FH1 */ 1693 4, /* IFM_IEEE80211_FH2 */ 1694 2, /* IFM_IEEE80211_DS1 */ 1695 4, /* IFM_IEEE80211_DS2 */ --- 11 unchanged lines hidden (view full) --- 1707 144, /* IFM_IEEE80211_OFDM72 */ 1708 0, /* IFM_IEEE80211_DS354k */ 1709 0, /* IFM_IEEE80211_DS512k */ 1710 6, /* IFM_IEEE80211_OFDM3 */ 1711 9, /* IFM_IEEE80211_OFDM4 */ 1712 54, /* IFM_IEEE80211_OFDM27 */ 1713 -1, /* IFM_IEEE80211_MCS */ 1714 }; |
1715 return IFM_SUBTYPE(mword) < N(ieeerates) ? | 1715 return IFM_SUBTYPE(mword) < nitems(ieeerates) ? |
1716 ieeerates[IFM_SUBTYPE(mword)] : 0; | 1716 ieeerates[IFM_SUBTYPE(mword)] : 0; |
1717#undef N | |
1718} 1719 1720/* 1721 * The following hash function is adapted from "Hash Functions" by Bob Jenkins 1722 * ("Algorithm Alley", Dr. Dobbs Journal, September 1997). 1723 */ 1724#define mix(a, b, c) \ 1725do { \ --- 29 unchanged lines hidden --- | 1717} 1718 1719/* 1720 * The following hash function is adapted from "Hash Functions" by Bob Jenkins 1721 * ("Algorithm Alley", Dr. Dobbs Journal, September 1997). 1722 */ 1723#define mix(a, b, c) \ 1724do { \ --- 29 unchanged lines hidden --- |