]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/net80211/ieee80211_input.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / net80211 / ieee80211_input.h
1 /*-
2  * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 #ifndef _NET80211_IEEE80211_INPUT_H_
28 #define _NET80211_IEEE80211_INPUT_H_
29
30 /* Verify the existence and length of __elem or get out. */
31 #define IEEE80211_VERIFY_ELEMENT(__elem, __maxlen) do {                 \
32         if ((__elem) == NULL) {                                         \
33                 IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,             \
34                     wh, ieee80211_mgt_subtype_name[subtype >>           \
35                         IEEE80211_FC0_SUBTYPE_SHIFT],                   \
36                     "%s", "no " #__elem );                              \
37                 ic->ic_stats.is_rx_elem_missing++;                      \
38                 return;                                                 \
39         }                                                               \
40         if ((__elem)[1] > (__maxlen)) {                                 \
41                 IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,             \
42                     wh, ieee80211_mgt_subtype_name[subtype >>           \
43                         IEEE80211_FC0_SUBTYPE_SHIFT],                   \
44                     "bad " #__elem " len %d", (__elem)[1]);             \
45                 ic->ic_stats.is_rx_elem_toobig++;                       \
46                 return;                                                 \
47         }                                                               \
48 } while (0)
49
50 #define IEEE80211_VERIFY_LENGTH(_len, _minlen, _action) do {            \
51         if ((_len) < (_minlen)) {                                       \
52                 IEEE80211_DISCARD(ic, IEEE80211_MSG_ELEMID,             \
53                     wh, ieee80211_mgt_subtype_name[subtype >>           \
54                         IEEE80211_FC0_SUBTYPE_SHIFT],                   \
55                     "ie too short, got %d, expected %d",                \
56                     (_len), (_minlen));                                 \
57                 ic->ic_stats.is_rx_elem_toosmall++;                     \
58                 _action;                                                \
59         }                                                               \
60 } while (0)
61
62 #ifdef IEEE80211_DEBUG
63 void    ieee80211_ssid_mismatch(struct ieee80211com *, const char *tag,
64         uint8_t mac[IEEE80211_ADDR_LEN], uint8_t *ssid);
65
66 #define IEEE80211_VERIFY_SSID(_ni, _ssid) do {                          \
67         if ((_ssid)[1] != 0 &&                                          \
68             ((_ssid)[1] != (_ni)->ni_esslen ||                          \
69             memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) {   \
70                 if (ieee80211_msg_input(ic))                            \
71                         ieee80211_ssid_mismatch(ic,                     \
72                             ieee80211_mgt_subtype_name[subtype >>       \
73                                 IEEE80211_FC0_SUBTYPE_SHIFT],           \
74                                 wh->i_addr2, _ssid);                    \
75                 ic->ic_stats.is_rx_ssidmismatch++;                      \
76                 return;                                                 \
77         }                                                               \
78 } while (0)
79 #else /* !IEEE80211_DEBUG */
80 #define IEEE80211_VERIFY_SSID(_ni, _ssid) do {                          \
81         if ((_ssid)[1] != 0 &&                                          \
82             ((_ssid)[1] != (_ni)->ni_esslen ||                          \
83             memcmp((_ssid) + 2, (_ni)->ni_essid, (_ssid)[1]) != 0)) {   \
84                 ic->ic_stats.is_rx_ssidmismatch++;                      \
85                 return;                                                 \
86         }                                                               \
87 } while (0)
88 #endif /* !IEEE80211_DEBUG */
89
90 /* unalligned little endian access */     
91 #define LE_READ_2(p)                                    \
92         ((uint16_t)                                     \
93          ((((const uint8_t *)(p))[0]      ) |           \
94           (((const uint8_t *)(p))[1] <<  8)))
95 #define LE_READ_4(p)                                    \
96         ((uint32_t)                                     \
97          ((((const uint8_t *)(p))[0]      ) |           \
98           (((const uint8_t *)(p))[1] <<  8) |           \
99           (((const uint8_t *)(p))[2] << 16) |           \
100           (((const uint8_t *)(p))[3] << 24)))
101
102 static __inline int
103 iswpaoui(const uint8_t *frm)
104 {
105         return frm[1] > 3 && LE_READ_4(frm+2) == ((WPA_OUI_TYPE<<24)|WPA_OUI);
106 }
107
108 static __inline int
109 iswmeoui(const uint8_t *frm)
110 {
111         return frm[1] > 3 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI);
112 }
113
114 static __inline int
115 iswmeparam(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_PARAM_OUI_SUBTYPE;
119 }
120
121 static __inline int
122 iswmeinfo(const uint8_t *frm)
123 {
124         return frm[1] > 5 && LE_READ_4(frm+2) == ((WME_OUI_TYPE<<24)|WME_OUI) &&
125                 frm[6] == WME_INFO_OUI_SUBTYPE;
126 }
127
128 static __inline int
129 isatherosoui(const uint8_t *frm)
130 {
131         return frm[1] > 3 && LE_READ_4(frm+2) == ((ATH_OUI_TYPE<<24)|ATH_OUI);
132 }
133
134 static __inline int
135 ishtcapoui(const uint8_t *frm)
136 {
137         return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTCAP<<24)|BCM_OUI);
138 }
139
140 static __inline int
141 ishtinfooui(const uint8_t *frm)
142 {
143         return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTINFO<<24)|BCM_OUI);
144 }
145
146 void    ieee80211_parse_ath(struct ieee80211_node *, uint8_t *);
147 #endif /* _NET80211_IEEE80211_INPUT_H_ */