ieee80211_input.h revision 186904
1145519Sdarrenr/*- 2145510Sdarrenr * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting 3145510Sdarrenr * All rights reserved. 4255332Scy * 5145510Sdarrenr * Redistribution and use in source and binary forms, with or without 6145510Sdarrenr * modification, are permitted provided that the following conditions 7145510Sdarrenr * are met: 8255332Scy * 1. Redistributions of source code must retain the above copyright 9145510Sdarrenr * notice, this list of conditions and the following disclaimer. 10145510Sdarrenr * 2. Redistributions in binary form must reproduce the above copyright 11145510Sdarrenr * notice, this list of conditions and the following disclaimer in the 12145510Sdarrenr * documentation and/or other materials provided with the distribution. 13145510Sdarrenr * 14145510Sdarrenr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15145510Sdarrenr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16145510Sdarrenr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17145510Sdarrenr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18255332Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19145510Sdarrenr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20145510Sdarrenr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21255332Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22145510Sdarrenr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23255332Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24145510Sdarrenr * 25255332Scy * $FreeBSD: head/sys/net80211/ieee80211_input.h 186904 2009-01-08 17:12:47Z sam $ 26145510Sdarrenr */ 27255332Scy#ifndef _NET80211_IEEE80211_INPUT_H_ 28255332Scy#define _NET80211_IEEE80211_INPUT_H_ 29255332Scy 30255332Scy/* Verify the existence and length of __elem or get out. */ 31145510Sdarrenr#define IEEE80211_VERIFY_ELEMENT(__elem, __maxlen, _action) do { \ 32145510Sdarrenr if ((__elem) == NULL) { \ 33145510Sdarrenr IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ 34145510Sdarrenr wh, NULL, "%s", "no " #__elem ); \ 35145510Sdarrenr vap->iv_stats.is_rx_elem_missing++; \ 36145510Sdarrenr _action; \ 37255332Scy } else if ((__elem)[1] > (__maxlen)) { \ 38255332Scy IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ 39255332Scy wh, NULL, "bad " #__elem " len %d", (__elem)[1]); \ 40255332Scy vap->iv_stats.is_rx_elem_toobig++; \ 41255332Scy _action; \ 42255332Scy } \ 43255332Scy} while (0) 44255332Scy 45255332Scy#define IEEE80211_VERIFY_LENGTH(_len, _minlen, _action) do { \ 46255332Scy if ((_len) < (_minlen)) { \ 47255332Scy IEEE80211_DISCARD(vap, IEEE80211_MSG_ELEMID, \ 48255332Scy wh, NULL, "ie too short, got %d, expected %d", \ 49255332Scy (_len), (_minlen)); \ 50255332Scy vap->iv_stats.is_rx_elem_toosmall++; \ 51255332Scy _action; \ 52255332Scy } \ 53255332Scy} while (0) 54255332Scy 55145510Sdarrenr#ifdef IEEE80211_DEBUG 56255332Scyvoid ieee80211_ssid_mismatch(struct ieee80211vap *, const char *tag, 57145510Sdarrenr uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid); 58145510Sdarrenr 59#define IEEE80211_VERIFY_SSID(_ni, _ssid, _action) do { \ 60 if ((_ssid)[1] != 0 && \ 61 ((_ssid)[1] != (_ni)->ni_esslen || \ 62 memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) { \ 63 if (ieee80211_msg_input(vap)) \ 64 ieee80211_ssid_mismatch(vap, \ 65 ieee80211_mgt_subtype_name[subtype >> \ 66 IEEE80211_FC0_SUBTYPE_SHIFT], \ 67 wh->i_addr2, _ssid); \ 68 vap->iv_stats.is_rx_ssidmismatch++; \ 69 _action; \ 70 } \ 71} while (0) 72#else /* !IEEE80211_DEBUG */ 73#define IEEE80211_VERIFY_SSID(_ni, _ssid, _action) do { \ 74 if ((_ssid)[1] != 0 && \ 75 ((_ssid)[1] != (_ni)->ni_esslen || \ 76 memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) { \ 77 vap->iv_stats.is_rx_ssidmismatch++; \ 78 _action; \ 79 } \ 80} while (0) 81#endif /* !IEEE80211_DEBUG */ 82 83/* unalligned little endian access */ 84#define LE_READ_2(p) \ 85 ((uint16_t) \ 86 ((((const uint8_t *)(p))[0] ) | \ 87 (((const uint8_t *)(p))[1] << 8))) 88#define LE_READ_4(p) \ 89 ((uint32_t) \ 90 ((((const uint8_t *)(p))[0] ) | \ 91 (((const uint8_t *)(p))[1] << 8) | \ 92 (((const uint8_t *)(p))[2] << 16) | \ 93 (((const uint8_t *)(p))[3] << 24))) 94 95static __inline int 96iswpaoui(const uint8_t *frm) 97{ 98 return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI); 99} 100 101static __inline int 102iswmeoui(const uint8_t *frm) 103{ 104 return frm[1] > 3 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI); 105} 106 107static __inline int 108iswmeparam(const uint8_t *frm) 109{ 110 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 111 frm[6] == WME_PARAM_OUI_SUBTYPE; 112} 113 114static __inline int 115iswmeinfo(const uint8_t *frm) 116{ 117 return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) && 118 frm[6] == WME_INFO_OUI_SUBTYPE; 119} 120 121static __inline int 122isatherosoui(const uint8_t *frm) 123{ 124 return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI); 125} 126 127static __inline int 128istdmaoui(const uint8_t *frm) 129{ 130 return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI); 131} 132 133static __inline int 134ishtcapoui(const uint8_t *frm) 135{ 136 return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTCAP<<24)|BCM_OUI); 137} 138 139static __inline int 140ishtinfooui(const uint8_t *frm) 141{ 142 return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTINFO<<24)|BCM_OUI); 143} 144 145void ieee80211_deliver_data(struct ieee80211vap *, 146 struct ieee80211_node *, struct mbuf *); 147struct mbuf *ieee80211_defrag(struct ieee80211_node *, 148 struct mbuf *, int); 149struct mbuf *ieee80211_decap(struct ieee80211vap *, struct mbuf *, int); 150struct mbuf *ieee80211_decap1(struct mbuf *, int *); 151struct mbuf *ieee80211_decap_fastframe(struct ieee80211_node *, 152 struct mbuf *); 153int ieee80211_setup_rates(struct ieee80211_node *ni, 154 const uint8_t *rates, const uint8_t *xrates, int flags); 155void ieee80211_send_error(struct ieee80211_node *, 156 const uint8_t mac[IEEE80211_ADDR_LEN], int subtype, int arg); 157int ieee80211_alloc_challenge(struct ieee80211_node *); 158void ieee80211_parse_ath(struct ieee80211_node *, uint8_t *); 159int ieee80211_parse_beacon(struct ieee80211_node *, struct mbuf *, 160 struct ieee80211_scanparams *); 161int ieee80211_parse_action(struct ieee80211_node *, struct mbuf *); 162#endif /* _NET80211_IEEE80211_INPUT_H_ */ 163