diff options
Diffstat (limited to 'net/mac80211/util.c')
-rw-r--r-- | net/mac80211/util.c | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 6513bc2d2707..ce62b163b82c 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c | |||
@@ -45,38 +45,37 @@ const unsigned char bridge_tunnel_header[] __aligned(2) = | |||
45 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, | 45 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
46 | enum ieee80211_if_types type) | 46 | enum ieee80211_if_types type) |
47 | { | 47 | { |
48 | u16 fc; | 48 | __le16 fc = hdr->frame_control; |
49 | 49 | ||
50 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ | 50 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
51 | if (len < 16) | 51 | if (len < 16) |
52 | return NULL; | 52 | return NULL; |
53 | 53 | ||
54 | fc = le16_to_cpu(hdr->frame_control); | 54 | if (ieee80211_is_data(fc)) { |
55 | |||
56 | switch (fc & IEEE80211_FCTL_FTYPE) { | ||
57 | case IEEE80211_FTYPE_DATA: | ||
58 | if (len < 24) /* drop incorrect hdr len (data) */ | 55 | if (len < 24) /* drop incorrect hdr len (data) */ |
59 | return NULL; | 56 | return NULL; |
60 | switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { | 57 | |
61 | case IEEE80211_FCTL_TODS: | 58 | if (ieee80211_has_a4(fc)) |
62 | return hdr->addr1; | ||
63 | case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): | ||
64 | return NULL; | 59 | return NULL; |
65 | case IEEE80211_FCTL_FROMDS: | 60 | if (ieee80211_has_tods(fc)) |
61 | return hdr->addr1; | ||
62 | if (ieee80211_has_fromds(fc)) | ||
66 | return hdr->addr2; | 63 | return hdr->addr2; |
67 | case 0: | 64 | |
68 | return hdr->addr3; | 65 | return hdr->addr3; |
69 | } | 66 | } |
70 | break; | 67 | |
71 | case IEEE80211_FTYPE_MGMT: | 68 | if (ieee80211_is_mgmt(fc)) { |
72 | if (len < 24) /* drop incorrect hdr len (mgmt) */ | 69 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
73 | return NULL; | 70 | return NULL; |
74 | return hdr->addr3; | 71 | return hdr->addr3; |
75 | case IEEE80211_FTYPE_CTL: | 72 | } |
76 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL) | 73 | |
74 | if (ieee80211_is_ctl(fc)) { | ||
75 | if(ieee80211_is_pspoll(fc)) | ||
77 | return hdr->addr1; | 76 | return hdr->addr1; |
78 | else if ((fc & IEEE80211_FCTL_STYPE) == | 77 | |
79 | IEEE80211_STYPE_BACK_REQ) { | 78 | if (ieee80211_is_back_req(fc)) { |
80 | switch (type) { | 79 | switch (type) { |
81 | case IEEE80211_IF_TYPE_STA: | 80 | case IEEE80211_IF_TYPE_STA: |
82 | return hdr->addr2; | 81 | return hdr->addr2; |
@@ -84,11 +83,9 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, | |||
84 | case IEEE80211_IF_TYPE_VLAN: | 83 | case IEEE80211_IF_TYPE_VLAN: |
85 | return hdr->addr1; | 84 | return hdr->addr1; |
86 | default: | 85 | default: |
87 | return NULL; | 86 | break; /* fall through to the return */ |
88 | } | 87 | } |
89 | } | 88 | } |
90 | else | ||
91 | return NULL; | ||
92 | } | 89 | } |
93 | 90 | ||
94 | return NULL; | 91 | return NULL; |
@@ -133,14 +130,46 @@ int ieee80211_get_hdrlen(u16 fc) | |||
133 | } | 130 | } |
134 | EXPORT_SYMBOL(ieee80211_get_hdrlen); | 131 | EXPORT_SYMBOL(ieee80211_get_hdrlen); |
135 | 132 | ||
136 | int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) | 133 | unsigned int ieee80211_hdrlen(__le16 fc) |
134 | { | ||
135 | unsigned int hdrlen = 24; | ||
136 | |||
137 | if (ieee80211_is_data(fc)) { | ||
138 | if (ieee80211_has_a4(fc)) | ||
139 | hdrlen = 30; | ||
140 | if (ieee80211_is_data_qos(fc)) | ||
141 | hdrlen += IEEE80211_QOS_CTL_LEN; | ||
142 | goto out; | ||
143 | } | ||
144 | |||
145 | if (ieee80211_is_ctl(fc)) { | ||
146 | /* | ||
147 | * ACK and CTS are 10 bytes, all others 16. To see how | ||
148 | * to get this condition consider | ||
149 | * subtype mask: 0b0000000011110000 (0x00F0) | ||
150 | * ACK subtype: 0b0000000011010000 (0x00D0) | ||
151 | * CTS subtype: 0b0000000011000000 (0x00C0) | ||
152 | * bits that matter: ^^^ (0x00E0) | ||
153 | * value of those: 0b0000000011000000 (0x00C0) | ||
154 | */ | ||
155 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) | ||
156 | hdrlen = 10; | ||
157 | else | ||
158 | hdrlen = 16; | ||
159 | } | ||
160 | out: | ||
161 | return hdrlen; | ||
162 | } | ||
163 | EXPORT_SYMBOL(ieee80211_hdrlen); | ||
164 | |||
165 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) | ||
137 | { | 166 | { |
138 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) skb->data; | 167 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data; |
139 | int hdrlen; | 168 | unsigned int hdrlen; |
140 | 169 | ||
141 | if (unlikely(skb->len < 10)) | 170 | if (unlikely(skb->len < 10)) |
142 | return 0; | 171 | return 0; |
143 | hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)); | 172 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
144 | if (unlikely(hdrlen > skb->len)) | 173 | if (unlikely(hdrlen > skb->len)) |
145 | return 0; | 174 | return 0; |
146 | return hdrlen; | 175 | return hdrlen; |