Commit | Line | Data |
---|---|---|
94a79942 | 1 | /* IEEE 802.11 SoftMAC layer |
559a4c31 | 2 | * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> |
94a79942 LF |
3 | * |
4 | * Mostly extracted from the rtl8180-sa2400 driver for the | |
5 | * in-kernel generic ieee802.11 stack. | |
6 | * | |
7 | * Few lines might be stolen from other part of the rtllib | |
8 | * stack. Copyright who own it's copyright | |
9 | * | |
10 | * WPA code stolen from the ipw2200 driver. | |
11 | * Copyright who own it's copyright. | |
12 | * | |
13 | * released under the GPL | |
14 | */ | |
15 | ||
16 | ||
17 | #include "rtllib.h" | |
94a79942 LF |
18 | |
19 | #include <linux/random.h> | |
20 | #include <linux/delay.h> | |
9d92ece8 | 21 | #include <linux/uaccess.h> |
0c43e56c | 22 | #include <linux/etherdevice.h> |
acd442db | 23 | #include <linux/ieee80211.h> |
94a79942 | 24 | #include "dot11d.h" |
94a79942 | 25 | |
94a79942 LF |
26 | short rtllib_is_54g(struct rtllib_network *net) |
27 | { | |
9d92ece8 | 28 | return (net->rates_ex_len > 0) || (net->rates_len > 4); |
94a79942 LF |
29 | } |
30 | ||
cd017123 | 31 | /* returns the total length needed for placing the RATE MFIE |
94a79942 LF |
32 | * tag and the EXTENDED RATE MFIE tag if needed. |
33 | * It encludes two bytes per tag for the tag itself and its len | |
34 | */ | |
ec0dc6be | 35 | static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee) |
94a79942 LF |
36 | { |
37 | unsigned int rate_len = 0; | |
38 | ||
39 | if (ieee->modulation & RTLLIB_CCK_MODULATION) | |
40 | rate_len = RTLLIB_CCK_RATE_LEN + 2; | |
41 | ||
42 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) | |
43 | ||
44 | rate_len += RTLLIB_OFDM_RATE_LEN + 2; | |
45 | ||
46 | return rate_len; | |
47 | } | |
48 | ||
cd017123 | 49 | /* place the MFIE rate, tag to the memory (double) pointed. |
94a79942 LF |
50 | * Then it updates the pointer so that |
51 | * it points after the new MFIE tag added. | |
52 | */ | |
ec0dc6be | 53 | static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p) |
94a79942 LF |
54 | { |
55 | u8 *tag = *tag_p; | |
56 | ||
9d92ece8 | 57 | if (ieee->modulation & RTLLIB_CCK_MODULATION) { |
94a79942 LF |
58 | *tag++ = MFIE_TYPE_RATES; |
59 | *tag++ = 4; | |
60 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB; | |
61 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB; | |
62 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB; | |
63 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB; | |
64 | } | |
65 | ||
9d92ece8 | 66 | /* We may add an option for custom rates that specific HW |
14b40d92 MK |
67 | * might support |
68 | */ | |
94a79942 LF |
69 | *tag_p = tag; |
70 | } | |
71 | ||
ec0dc6be | 72 | static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p) |
94a79942 LF |
73 | { |
74 | u8 *tag = *tag_p; | |
75 | ||
9d92ece8 | 76 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) { |
94a79942 LF |
77 | *tag++ = MFIE_TYPE_RATES_EX; |
78 | *tag++ = 8; | |
79 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB; | |
80 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB; | |
81 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB; | |
82 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB; | |
83 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB; | |
84 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB; | |
85 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB; | |
86 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB; | |
94a79942 | 87 | } |
9d92ece8 | 88 | /* We may add an option for custom rates that specific HW might |
14b40d92 MK |
89 | * support |
90 | */ | |
94a79942 LF |
91 | *tag_p = tag; |
92 | } | |
93 | ||
ec0dc6be | 94 | static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p) |
9d92ece8 | 95 | { |
94a79942 LF |
96 | u8 *tag = *tag_p; |
97 | ||
98 | *tag++ = MFIE_TYPE_GENERIC; | |
99 | *tag++ = 7; | |
100 | *tag++ = 0x00; | |
101 | *tag++ = 0x50; | |
102 | *tag++ = 0xf2; | |
103 | *tag++ = 0x02; | |
104 | *tag++ = 0x00; | |
105 | *tag++ = 0x01; | |
94a79942 | 106 | *tag++ = MAX_SP_Len; |
94a79942 LF |
107 | *tag_p = tag; |
108 | } | |
109 | ||
9d92ece8 LF |
110 | void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p) |
111 | { | |
94a79942 LF |
112 | u8 *tag = *tag_p; |
113 | ||
9d92ece8 LF |
114 | *tag++ = MFIE_TYPE_GENERIC; |
115 | *tag++ = 7; | |
116 | *tag++ = 0x00; | |
117 | *tag++ = 0xe0; | |
118 | *tag++ = 0x4c; | |
119 | *tag++ = 0x01; | |
120 | *tag++ = 0x02; | |
121 | *tag++ = 0x11; | |
94a79942 LF |
122 | *tag++ = 0x00; |
123 | ||
124 | *tag_p = tag; | |
d69d2054 | 125 | netdev_alert(ieee->dev, "This is enable turbo mode IE process\n"); |
94a79942 LF |
126 | } |
127 | ||
ec0dc6be | 128 | static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb) |
94a79942 LF |
129 | { |
130 | int nh; | |
3a6b70c3 | 131 | |
9d92ece8 | 132 | nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM; |
94a79942 | 133 | |
14b40d92 | 134 | /* if the queue is full but we have newer frames then |
94a79942 LF |
135 | * just overwrites the oldest. |
136 | * | |
137 | * if (nh == ieee->mgmt_queue_tail) | |
138 | * return -1; | |
139 | */ | |
140 | ieee->mgmt_queue_head = nh; | |
141 | ieee->mgmt_queue_ring[nh] = skb; | |
142 | ||
143 | } | |
144 | ||
ec0dc6be | 145 | static void init_mgmt_queue(struct rtllib_device *ieee) |
94a79942 LF |
146 | { |
147 | ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0; | |
148 | } | |
149 | ||
150 | ||
151 | u8 | |
152 | MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee) | |
153 | { | |
154 | u16 i; | |
155 | u8 QueryRate = 0; | |
156 | u8 BasicRate; | |
157 | ||
158 | ||
9d92ece8 | 159 | for (i = 0; i < ieee->current_network.rates_len; i++) { |
94a79942 | 160 | BasicRate = ieee->current_network.rates[i]&0x7F; |
9d92ece8 LF |
161 | if (!rtllib_is_cck_rate(BasicRate)) { |
162 | if (QueryRate == 0) { | |
94a79942 | 163 | QueryRate = BasicRate; |
9d92ece8 | 164 | } else { |
94a79942 | 165 | if (BasicRate < QueryRate) |
94a79942 | 166 | QueryRate = BasicRate; |
94a79942 LF |
167 | } |
168 | } | |
169 | } | |
170 | ||
9d92ece8 | 171 | if (QueryRate == 0) { |
94a79942 | 172 | QueryRate = 12; |
d69d2054 | 173 | netdev_info(ieee->dev, "No BasicRate found!!\n"); |
94a79942 LF |
174 | } |
175 | return QueryRate; | |
176 | } | |
177 | ||
d82f0029 | 178 | static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee) |
94a79942 | 179 | { |
7796d93e | 180 | struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; |
94a79942 LF |
181 | u8 rate; |
182 | ||
183 | if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M) | |
184 | rate = 0x0c; | |
185 | else | |
186 | rate = ieee->basic_rate & 0x7f; | |
187 | ||
9d92ece8 LF |
188 | if (rate == 0) { |
189 | if (ieee->mode == IEEE_A || | |
190 | ieee->mode == IEEE_N_5G || | |
191 | (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK)) | |
94a79942 LF |
192 | rate = 0x0c; |
193 | else | |
194 | rate = 0x02; | |
195 | } | |
196 | ||
197 | return rate; | |
198 | } | |
199 | ||
94a79942 LF |
200 | inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee) |
201 | { | |
202 | unsigned long flags; | |
203 | short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; | |
9d92ece8 | 204 | struct rtllib_hdr_3addr *header = |
94a79942 LF |
205 | (struct rtllib_hdr_3addr *) skb->data; |
206 | ||
3b83db43 | 207 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8); |
3a6b70c3 | 208 | |
94a79942 LF |
209 | spin_lock_irqsave(&ieee->lock, flags); |
210 | ||
211 | /* called with 2nd param 0, no mgmt lock required */ | |
9d92ece8 | 212 | rtllib_sta_wakeup(ieee, 0); |
94a79942 | 213 | |
f7df1918 | 214 | if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON) |
94a79942 LF |
215 | tcb_desc->queue_index = BEACON_QUEUE; |
216 | else | |
217 | tcb_desc->queue_index = MGNT_QUEUE; | |
218 | ||
219 | if (ieee->disable_mgnt_queue) | |
220 | tcb_desc->queue_index = HIGH_QUEUE; | |
221 | ||
222 | tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee); | |
223 | tcb_desc->RATRIndex = 7; | |
224 | tcb_desc->bTxDisableRateFallBack = 1; | |
225 | tcb_desc->bTxUseDriverAssingedRate = 1; | |
226 | if (single) { | |
9d92ece8 LF |
227 | if (ieee->queue_stop) { |
228 | enqueue_mgmt(ieee, skb); | |
229 | } else { | |
94a79942 LF |
230 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4); |
231 | ||
232 | if (ieee->seq_ctrl[0] == 0xFFF) | |
233 | ieee->seq_ctrl[0] = 0; | |
234 | else | |
235 | ieee->seq_ctrl[0]++; | |
236 | ||
237 | /* avoid watchdog triggers */ | |
9d92ece8 LF |
238 | ieee->softmac_data_hard_start_xmit(skb, ieee->dev, |
239 | ieee->basic_rate); | |
94a79942 LF |
240 | } |
241 | ||
242 | spin_unlock_irqrestore(&ieee->lock, flags); | |
9d92ece8 | 243 | } else { |
94a79942 LF |
244 | spin_unlock_irqrestore(&ieee->lock, flags); |
245 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags); | |
246 | ||
247 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); | |
248 | ||
249 | if (ieee->seq_ctrl[0] == 0xFFF) | |
250 | ieee->seq_ctrl[0] = 0; | |
251 | else | |
252 | ieee->seq_ctrl[0]++; | |
253 | ||
f2635894 | 254 | /* check whether the managed packet queued greater than 5 */ |
35e33b04 MK |
255 | if (!ieee->check_nic_enough_desc(ieee->dev, |
256 | tcb_desc->queue_index) || | |
257 | skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) || | |
258 | ieee->queue_stop) { | |
14b40d92 MK |
259 | /* insert the skb packet to the management queue |
260 | * | |
261 | * as for the completion function, it does not need | |
94a79942 | 262 | * to check it any more. |
14b40d92 | 263 | */ |
d69d2054 | 264 | netdev_info(ieee->dev, |
0822339b MK |
265 | "%s():insert to waitqueue, queue_index:%d!\n", |
266 | __func__, tcb_desc->queue_index); | |
9d92ece8 LF |
267 | skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index], |
268 | skb); | |
94a79942 | 269 | } else { |
9d92ece8 | 270 | ieee->softmac_hard_start_xmit(skb, ieee->dev); |
94a79942 LF |
271 | } |
272 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags); | |
273 | } | |
274 | } | |
275 | ||
276 | inline void softmac_ps_mgmt_xmit(struct sk_buff *skb, | |
277 | struct rtllib_device *ieee) | |
278 | { | |
279 | short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; | |
280 | struct rtllib_hdr_3addr *header = | |
281 | (struct rtllib_hdr_3addr *) skb->data; | |
9d92ece8 | 282 | u16 fc, type, stype; |
3b83db43 | 283 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8); |
94a79942 | 284 | |
1830a6d8 | 285 | fc = le16_to_cpu(header->frame_ctl); |
94a79942 LF |
286 | type = WLAN_FC_GET_TYPE(fc); |
287 | stype = WLAN_FC_GET_STYPE(fc); | |
288 | ||
289 | ||
290 | if (stype != RTLLIB_STYPE_PSPOLL) | |
291 | tcb_desc->queue_index = MGNT_QUEUE; | |
292 | else | |
293 | tcb_desc->queue_index = HIGH_QUEUE; | |
294 | ||
295 | if (ieee->disable_mgnt_queue) | |
296 | tcb_desc->queue_index = HIGH_QUEUE; | |
297 | ||
298 | ||
299 | tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee); | |
300 | tcb_desc->RATRIndex = 7; | |
301 | tcb_desc->bTxDisableRateFallBack = 1; | |
302 | tcb_desc->bTxUseDriverAssingedRate = 1; | |
303 | if (single) { | |
304 | if (type != RTLLIB_FTYPE_CTL) { | |
305 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); | |
306 | ||
307 | if (ieee->seq_ctrl[0] == 0xFFF) | |
308 | ieee->seq_ctrl[0] = 0; | |
309 | else | |
310 | ieee->seq_ctrl[0]++; | |
311 | ||
312 | } | |
313 | /* avoid watchdog triggers */ | |
9d92ece8 LF |
314 | ieee->softmac_data_hard_start_xmit(skb, ieee->dev, |
315 | ieee->basic_rate); | |
94a79942 LF |
316 | |
317 | } else { | |
318 | if (type != RTLLIB_FTYPE_CTL) { | |
319 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); | |
320 | ||
321 | if (ieee->seq_ctrl[0] == 0xFFF) | |
322 | ieee->seq_ctrl[0] = 0; | |
323 | else | |
324 | ieee->seq_ctrl[0]++; | |
325 | } | |
9d92ece8 | 326 | ieee->softmac_hard_start_xmit(skb, ieee->dev); |
94a79942 LF |
327 | |
328 | } | |
329 | } | |
330 | ||
6d91857d | 331 | static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee) |
94a79942 | 332 | { |
9d92ece8 | 333 | unsigned int len, rate_len; |
94a79942 LF |
334 | u8 *tag; |
335 | struct sk_buff *skb; | |
336 | struct rtllib_probe_request *req; | |
337 | ||
338 | len = ieee->current_network.ssid_len; | |
339 | ||
340 | rate_len = rtllib_MFIE_rate_len(ieee); | |
341 | ||
94a79942 LF |
342 | skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) + |
343 | 2 + len + rate_len + ieee->tx_headroom); | |
94a79942 LF |
344 | |
345 | if (!skb) | |
346 | return NULL; | |
347 | ||
94a79942 LF |
348 | skb_reserve(skb, ieee->tx_headroom); |
349 | ||
9d92ece8 LF |
350 | req = (struct rtllib_probe_request *) skb_put(skb, |
351 | sizeof(struct rtllib_probe_request)); | |
94a79942 LF |
352 | req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ); |
353 | req->header.duration_id = 0; | |
354 | ||
355 | memset(req->header.addr1, 0xff, ETH_ALEN); | |
b57ceb19 | 356 | ether_addr_copy(req->header.addr2, ieee->dev->dev_addr); |
94a79942 LF |
357 | memset(req->header.addr3, 0xff, ETH_ALEN); |
358 | ||
9d92ece8 | 359 | tag = (u8 *) skb_put(skb, len + 2 + rate_len); |
94a79942 LF |
360 | |
361 | *tag++ = MFIE_TYPE_SSID; | |
362 | *tag++ = len; | |
363 | memcpy(tag, ieee->current_network.ssid, len); | |
364 | tag += len; | |
365 | ||
9d92ece8 LF |
366 | rtllib_MFIE_Brate(ieee, &tag); |
367 | rtllib_MFIE_Grate(ieee, &tag); | |
94a79942 LF |
368 | |
369 | return skb; | |
370 | } | |
371 | ||
372 | struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee); | |
373 | ||
ec0dc6be | 374 | static void rtllib_send_beacon(struct rtllib_device *ieee) |
94a79942 LF |
375 | { |
376 | struct sk_buff *skb; | |
3a6b70c3 | 377 | |
94a79942 LF |
378 | if (!ieee->ieee_up) |
379 | return; | |
380 | skb = rtllib_get_beacon_(ieee); | |
381 | ||
9d92ece8 | 382 | if (skb) { |
94a79942 LF |
383 | softmac_mgmt_xmit(skb, ieee); |
384 | ieee->softmac_stats.tx_beacons++; | |
385 | } | |
386 | ||
9d92ece8 LF |
387 | if (ieee->beacon_txing && ieee->ieee_up) |
388 | mod_timer(&ieee->beacon_timer, jiffies + | |
8b9733c1 | 389 | (msecs_to_jiffies(ieee->current_network.beacon_interval - 5))); |
94a79942 LF |
390 | } |
391 | ||
392 | ||
ec0dc6be | 393 | static void rtllib_send_beacon_cb(unsigned long _ieee) |
94a79942 LF |
394 | { |
395 | struct rtllib_device *ieee = | |
396 | (struct rtllib_device *) _ieee; | |
397 | unsigned long flags; | |
398 | ||
399 | spin_lock_irqsave(&ieee->beacon_lock, flags); | |
400 | rtllib_send_beacon(ieee); | |
401 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); | |
402 | } | |
403 | ||
14b40d92 | 404 | /* Enables network monitor mode, all rx packets will be received. */ |
9d92ece8 LF |
405 | void rtllib_EnableNetMonitorMode(struct net_device *dev, |
406 | bool bInitState) | |
94a79942 | 407 | { |
9d92ece8 | 408 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
94a79942 | 409 | |
d69d2054 | 410 | netdev_info(dev, "========>Enter Monitor Mode\n"); |
94a79942 | 411 | |
9d92ece8 | 412 | ieee->AllowAllDestAddrHandler(dev, true, !bInitState); |
94a79942 LF |
413 | } |
414 | ||
415 | ||
14b40d92 MK |
416 | /* Disables network monitor mode. Only packets destinated to |
417 | * us will be received. | |
94a79942 | 418 | */ |
9d92ece8 LF |
419 | void rtllib_DisableNetMonitorMode(struct net_device *dev, |
420 | bool bInitState) | |
94a79942 | 421 | { |
9d92ece8 | 422 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
94a79942 | 423 | |
d69d2054 | 424 | netdev_info(dev, "========>Exit Monitor Mode\n"); |
94a79942 | 425 | |
9d92ece8 | 426 | ieee->AllowAllDestAddrHandler(dev, false, !bInitState); |
94a79942 LF |
427 | } |
428 | ||
429 | ||
14b40d92 | 430 | /* Enables the specialized promiscuous mode required by Intel. |
9d92ece8 LF |
431 | * In this mode, Intel intends to hear traffics from/to other STAs in the |
432 | * same BSS. Therefore we don't have to disable checking BSSID and we only need | |
433 | * to allow all dest. BUT: if we enable checking BSSID then we can't recv | |
434 | * packets from other STA. | |
94a79942 | 435 | */ |
9d92ece8 LF |
436 | void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, |
437 | bool bInitState) | |
94a79942 | 438 | { |
9d92ece8 | 439 | bool bFilterOutNonAssociatedBSSID = false; |
94a79942 | 440 | |
9d92ece8 | 441 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
94a79942 | 442 | |
d69d2054 | 443 | netdev_info(dev, "========>Enter Intel Promiscuous Mode\n"); |
94a79942 | 444 | |
9d92ece8 LF |
445 | ieee->AllowAllDestAddrHandler(dev, true, !bInitState); |
446 | ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID, | |
447 | (u8 *)&bFilterOutNonAssociatedBSSID); | |
94a79942 | 448 | |
9d92ece8 | 449 | ieee->bNetPromiscuousMode = true; |
94a79942 | 450 | } |
3b28499c | 451 | EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode); |
94a79942 LF |
452 | |
453 | ||
14b40d92 MK |
454 | /* Disables the specialized promiscuous mode required by Intel. |
455 | * See MgntEnableIntelPromiscuousMode for detail. | |
94a79942 | 456 | */ |
9d92ece8 LF |
457 | void rtllib_DisableIntelPromiscuousMode(struct net_device *dev, |
458 | bool bInitState) | |
94a79942 | 459 | { |
9d92ece8 | 460 | bool bFilterOutNonAssociatedBSSID = true; |
94a79942 | 461 | |
9d92ece8 | 462 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
94a79942 | 463 | |
d69d2054 | 464 | netdev_info(dev, "========>Exit Intel Promiscuous Mode\n"); |
94a79942 | 465 | |
9d92ece8 LF |
466 | ieee->AllowAllDestAddrHandler(dev, false, !bInitState); |
467 | ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID, | |
468 | (u8 *)&bFilterOutNonAssociatedBSSID); | |
94a79942 | 469 | |
9d92ece8 | 470 | ieee->bNetPromiscuousMode = false; |
94a79942 | 471 | } |
3b28499c | 472 | EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode); |
94a79942 | 473 | |
ec0dc6be | 474 | static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh) |
94a79942 LF |
475 | { |
476 | struct sk_buff *skb; | |
3a6b70c3 | 477 | |
94a79942 | 478 | skb = rtllib_probe_req(ieee); |
9d92ece8 | 479 | if (skb) { |
94a79942 LF |
480 | softmac_mgmt_xmit(skb, ieee); |
481 | ieee->softmac_stats.tx_probe_rq++; | |
482 | } | |
483 | } | |
484 | ||
485 | ||
486 | void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh) | |
487 | { | |
488 | if (ieee->active_scan && (ieee->softmac_features & | |
489 | IEEE_SOFTMAC_PROBERQ)) { | |
490 | rtllib_send_probe(ieee, 0); | |
491 | rtllib_send_probe(ieee, 0); | |
492 | } | |
493 | } | |
494 | ||
94a79942 LF |
495 | void rtllib_update_active_chan_map(struct rtllib_device *ieee) |
496 | { | |
9d92ece8 LF |
497 | memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map, |
498 | MAX_CHANNEL_NUMBER+1); | |
94a79942 LF |
499 | } |
500 | ||
501 | /* this performs syncro scan blocking the caller until all channels | |
502 | * in the allowed channel map has been checked. | |
503 | */ | |
504 | void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh) | |
505 | { | |
9d92ece8 | 506 | union iwreq_data wrqu; |
94a79942 LF |
507 | short ch = 0; |
508 | ||
509 | rtllib_update_active_chan_map(ieee); | |
510 | ||
511 | ieee->be_scan_inprogress = true; | |
512 | ||
513 | down(&ieee->scan_sem); | |
514 | ||
9d92ece8 | 515 | while (1) { |
94a79942 LF |
516 | do { |
517 | ch++; | |
518 | if (ch > MAX_CHANNEL_NUMBER) | |
519 | goto out; /* scan completed */ | |
9d92ece8 | 520 | } while (!ieee->active_channel_map[ch]); |
94a79942 | 521 | |
430fb250 | 522 | /* this function can be called in two situations |
94a79942 LF |
523 | * 1- We have switched to ad-hoc mode and we are |
524 | * performing a complete syncro scan before conclude | |
525 | * there are no interesting cell and to create a | |
526 | * new one. In this case the link state is | |
527 | * RTLLIB_NOLINK until we found an interesting cell. | |
528 | * If so the ieee8021_new_net, called by the RX path | |
529 | * will set the state to RTLLIB_LINKED, so we stop | |
530 | * scanning | |
531 | * 2- We are linked and the root uses run iwlist scan. | |
532 | * So we switch to RTLLIB_LINKED_SCANNING to remember | |
533 | * that we are still logically linked (not interested in | |
534 | * new network events, despite for updating the net list, | |
535 | * but we are temporarly 'unlinked' as the driver shall | |
536 | * not filter RX frames and the channel is changing. | |
cd017123 | 537 | * So the only situation in which are interested is to check |
94a79942 LF |
538 | * if the state become LINKED because of the #1 situation |
539 | */ | |
540 | ||
541 | if (ieee->state == RTLLIB_LINKED) | |
542 | goto out; | |
9d92ece8 | 543 | if (ieee->sync_scan_hurryup) { |
d69d2054 MK |
544 | netdev_info(ieee->dev, |
545 | "============>sync_scan_hurryup out\n"); | |
94a79942 LF |
546 | goto out; |
547 | } | |
548 | ||
549 | ieee->set_chan(ieee->dev, ch); | |
550 | if (ieee->active_channel_map[ch] == 1) | |
9d92ece8 | 551 | rtllib_send_probe_requests(ieee, 0); |
94a79942 LF |
552 | |
553 | /* this prevent excessive time wait when we | |
554 | * need to wait for a syncro scan to end.. | |
555 | */ | |
556 | msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME); | |
557 | } | |
558 | out: | |
559 | ieee->actscanning = false; | |
560 | ieee->sync_scan_hurryup = 0; | |
561 | ||
9d92ece8 | 562 | if (ieee->state >= RTLLIB_LINKED) { |
94a79942 LF |
563 | if (IS_DOT11D_ENABLE(ieee)) |
564 | DOT11D_ScanComplete(ieee); | |
94a79942 LF |
565 | } |
566 | up(&ieee->scan_sem); | |
567 | ||
568 | ieee->be_scan_inprogress = false; | |
569 | ||
94a79942 | 570 | memset(&wrqu, 0, sizeof(wrqu)); |
9d92ece8 | 571 | wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL); |
94a79942 LF |
572 | } |
573 | ||
ec0dc6be | 574 | static void rtllib_softmac_scan_wq(void *data) |
94a79942 | 575 | { |
9d92ece8 LF |
576 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
577 | struct rtllib_device, softmac_scan_wq); | |
94a79942 LF |
578 | u8 last_channel = ieee->current_network.channel; |
579 | ||
580 | rtllib_update_active_chan_map(ieee); | |
581 | ||
582 | if (!ieee->ieee_up) | |
583 | return; | |
4bb01423 | 584 | if (rtllib_act_scanning(ieee, true)) |
94a79942 LF |
585 | return; |
586 | ||
587 | down(&ieee->scan_sem); | |
588 | ||
9d92ece8 | 589 | if (ieee->eRFPowerState == eRfOff) { |
d69d2054 MK |
590 | netdev_info(ieee->dev, |
591 | "======>%s():rf state is eRfOff, return\n", | |
592 | __func__); | |
94a79942 LF |
593 | goto out1; |
594 | } | |
595 | ||
9d92ece8 | 596 | do { |
94a79942 | 597 | ieee->current_network.channel = |
9d92ece8 LF |
598 | (ieee->current_network.channel + 1) % |
599 | MAX_CHANNEL_NUMBER; | |
600 | if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) { | |
94a79942 LF |
601 | if (!ieee->active_channel_map[ieee->current_network.channel]) |
602 | ieee->current_network.channel = 6; | |
603 | goto out; /* no good chans */ | |
604 | } | |
9d92ece8 | 605 | } while (!ieee->active_channel_map[ieee->current_network.channel]); |
94a79942 | 606 | |
9d92ece8 | 607 | if (ieee->scanning_continue == 0) |
94a79942 LF |
608 | goto out; |
609 | ||
610 | ieee->set_chan(ieee->dev, ieee->current_network.channel); | |
611 | ||
612 | if (ieee->active_channel_map[ieee->current_network.channel] == 1) | |
9d92ece8 | 613 | rtllib_send_probe_requests(ieee, 0); |
94a79942 | 614 | |
9d92ece8 | 615 | queue_delayed_work_rsl(ieee->wq, &ieee->softmac_scan_wq, |
8b9733c1 | 616 | msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME)); |
94a79942 LF |
617 | |
618 | up(&ieee->scan_sem); | |
619 | return; | |
620 | ||
621 | out: | |
94a79942 LF |
622 | if (IS_DOT11D_ENABLE(ieee)) |
623 | DOT11D_ScanComplete(ieee); | |
94a79942 LF |
624 | ieee->current_network.channel = last_channel; |
625 | ||
626 | out1: | |
627 | ieee->actscanning = false; | |
628 | ieee->scan_watch_dog = 0; | |
629 | ieee->scanning_continue = 0; | |
630 | up(&ieee->scan_sem); | |
631 | } | |
632 | ||
633 | ||
634 | ||
ec0dc6be | 635 | static void rtllib_beacons_start(struct rtllib_device *ieee) |
94a79942 LF |
636 | { |
637 | unsigned long flags; | |
3a6b70c3 | 638 | |
9d92ece8 | 639 | spin_lock_irqsave(&ieee->beacon_lock, flags); |
94a79942 LF |
640 | |
641 | ieee->beacon_txing = 1; | |
642 | rtllib_send_beacon(ieee); | |
643 | ||
9d92ece8 | 644 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); |
94a79942 LF |
645 | } |
646 | ||
ec0dc6be | 647 | static void rtllib_beacons_stop(struct rtllib_device *ieee) |
94a79942 LF |
648 | { |
649 | unsigned long flags; | |
650 | ||
9d92ece8 | 651 | spin_lock_irqsave(&ieee->beacon_lock, flags); |
94a79942 LF |
652 | |
653 | ieee->beacon_txing = 0; | |
654 | del_timer_sync(&ieee->beacon_timer); | |
655 | ||
9d92ece8 | 656 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); |
94a79942 LF |
657 | |
658 | } | |
659 | ||
660 | ||
661 | void rtllib_stop_send_beacons(struct rtllib_device *ieee) | |
662 | { | |
663 | if (ieee->stop_send_beacons) | |
664 | ieee->stop_send_beacons(ieee->dev); | |
665 | if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) | |
666 | rtllib_beacons_stop(ieee); | |
667 | } | |
3b28499c | 668 | EXPORT_SYMBOL(rtllib_stop_send_beacons); |
94a79942 LF |
669 | |
670 | ||
671 | void rtllib_start_send_beacons(struct rtllib_device *ieee) | |
672 | { | |
673 | if (ieee->start_send_beacons) | |
674 | ieee->start_send_beacons(ieee->dev); | |
675 | if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) | |
676 | rtllib_beacons_start(ieee); | |
677 | } | |
3b28499c | 678 | EXPORT_SYMBOL(rtllib_start_send_beacons); |
94a79942 LF |
679 | |
680 | ||
ec0dc6be | 681 | static void rtllib_softmac_stop_scan(struct rtllib_device *ieee) |
94a79942 | 682 | { |
94a79942 LF |
683 | down(&ieee->scan_sem); |
684 | ieee->scan_watch_dog = 0; | |
cb762154 | 685 | if (ieee->scanning_continue == 1) { |
94a79942 | 686 | ieee->scanning_continue = 0; |
014e4c27 | 687 | ieee->actscanning = false; |
94a79942 | 688 | |
94a79942 | 689 | cancel_delayed_work(&ieee->softmac_scan_wq); |
94a79942 LF |
690 | } |
691 | ||
692 | up(&ieee->scan_sem); | |
693 | } | |
694 | ||
695 | void rtllib_stop_scan(struct rtllib_device *ieee) | |
696 | { | |
9d92ece8 | 697 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
94a79942 | 698 | rtllib_softmac_stop_scan(ieee); |
9d92ece8 | 699 | } else { |
94a79942 LF |
700 | if (ieee->rtllib_stop_hw_scan) |
701 | ieee->rtllib_stop_hw_scan(ieee->dev); | |
702 | } | |
703 | } | |
3b28499c | 704 | EXPORT_SYMBOL(rtllib_stop_scan); |
94a79942 LF |
705 | |
706 | void rtllib_stop_scan_syncro(struct rtllib_device *ieee) | |
707 | { | |
9d92ece8 | 708 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
94a79942 | 709 | ieee->sync_scan_hurryup = 1; |
9d92ece8 | 710 | } else { |
94a79942 LF |
711 | if (ieee->rtllib_stop_hw_scan) |
712 | ieee->rtllib_stop_hw_scan(ieee->dev); | |
713 | } | |
714 | } | |
3b28499c | 715 | EXPORT_SYMBOL(rtllib_stop_scan_syncro); |
94a79942 LF |
716 | |
717 | bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan) | |
718 | { | |
9d92ece8 LF |
719 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
720 | if (sync_scan) | |
94a79942 | 721 | return ieee->be_scan_inprogress; |
9d92ece8 LF |
722 | else |
723 | return ieee->actscanning || ieee->be_scan_inprogress; | |
724 | } else { | |
94a79942 LF |
725 | return test_bit(STATUS_SCANNING, &ieee->status); |
726 | } | |
727 | } | |
3b28499c | 728 | EXPORT_SYMBOL(rtllib_act_scanning); |
94a79942 LF |
729 | |
730 | /* called with ieee->lock held */ | |
ec0dc6be | 731 | static void rtllib_start_scan(struct rtllib_device *ieee) |
94a79942 | 732 | { |
9d92ece8 | 733 | RT_TRACE(COMP_DBG, "===>%s()\n", __func__); |
94a79942 | 734 | if (ieee->rtllib_ips_leave_wq != NULL) |
9d92ece8 | 735 | ieee->rtllib_ips_leave_wq(ieee->dev); |
94a79942 | 736 | |
9d92ece8 | 737 | if (IS_DOT11D_ENABLE(ieee)) { |
94a79942 | 738 | if (IS_COUNTRY_IE_VALID(ieee)) |
94a79942 | 739 | RESET_CIE_WATCHDOG(ieee); |
94a79942 | 740 | } |
94a79942 LF |
741 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
742 | if (ieee->scanning_continue == 0) { | |
743 | ieee->actscanning = true; | |
744 | ieee->scanning_continue = 1; | |
9d92ece8 LF |
745 | queue_delayed_work_rsl(ieee->wq, |
746 | &ieee->softmac_scan_wq, 0); | |
94a79942 LF |
747 | } |
748 | } else { | |
749 | if (ieee->rtllib_start_hw_scan) | |
750 | ieee->rtllib_start_hw_scan(ieee->dev); | |
751 | } | |
94a79942 LF |
752 | } |
753 | ||
94a79942 LF |
754 | /* called with wx_sem held */ |
755 | void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh) | |
756 | { | |
9d92ece8 | 757 | if (IS_DOT11D_ENABLE(ieee)) { |
94a79942 | 758 | if (IS_COUNTRY_IE_VALID(ieee)) |
94a79942 | 759 | RESET_CIE_WATCHDOG(ieee); |
94a79942 | 760 | } |
94a79942 | 761 | ieee->sync_scan_hurryup = 0; |
9d92ece8 | 762 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
94a79942 | 763 | rtllib_softmac_scan_syncro(ieee, is_mesh); |
9d92ece8 | 764 | } else { |
94a79942 LF |
765 | if (ieee->rtllib_start_hw_scan) |
766 | ieee->rtllib_start_hw_scan(ieee->dev); | |
767 | } | |
94a79942 | 768 | } |
3b28499c | 769 | EXPORT_SYMBOL(rtllib_start_scan_syncro); |
94a79942 LF |
770 | |
771 | inline struct sk_buff *rtllib_authentication_req(struct rtllib_network *beacon, | |
9d92ece8 | 772 | struct rtllib_device *ieee, int challengelen, u8 *daddr) |
94a79942 LF |
773 | { |
774 | struct sk_buff *skb; | |
775 | struct rtllib_authentication *auth; | |
776 | int len = 0; | |
3a6b70c3 | 777 | |
9d92ece8 LF |
778 | len = sizeof(struct rtllib_authentication) + challengelen + |
779 | ieee->tx_headroom + 4; | |
94a79942 | 780 | skb = dev_alloc_skb(len); |
94a79942 | 781 | |
9d92ece8 LF |
782 | if (!skb) |
783 | return NULL; | |
94a79942 | 784 | |
94a79942 LF |
785 | skb_reserve(skb, ieee->tx_headroom); |
786 | ||
787 | auth = (struct rtllib_authentication *) | |
788 | skb_put(skb, sizeof(struct rtllib_authentication)); | |
789 | ||
1830a6d8 | 790 | auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH); |
9d92ece8 | 791 | if (challengelen) |
7fe30a7d | 792 | auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP); |
94a79942 | 793 | |
1830a6d8 | 794 | auth->header.duration_id = cpu_to_le16(0x013a); |
b57ceb19 MK |
795 | ether_addr_copy(auth->header.addr1, beacon->bssid); |
796 | ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr); | |
797 | ether_addr_copy(auth->header.addr3, beacon->bssid); | |
94a79942 LF |
798 | if (ieee->auth_mode == 0) |
799 | auth->algorithm = WLAN_AUTH_OPEN; | |
800 | else if (ieee->auth_mode == 1) | |
1830a6d8 | 801 | auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY); |
94a79942 LF |
802 | else if (ieee->auth_mode == 2) |
803 | auth->algorithm = WLAN_AUTH_OPEN; | |
804 | auth->transaction = cpu_to_le16(ieee->associate_seq); | |
805 | ieee->associate_seq++; | |
806 | ||
807 | auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS); | |
808 | ||
809 | return skb; | |
94a79942 LF |
810 | } |
811 | ||
c7ddc288 MK |
812 | static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, |
813 | const u8 *dest) | |
94a79942 LF |
814 | { |
815 | u8 *tag; | |
816 | int beacon_size; | |
817 | struct rtllib_probe_response *beacon_buf; | |
818 | struct sk_buff *skb = NULL; | |
819 | int encrypt; | |
9d92ece8 | 820 | int atim_len, erp_len; |
32c44cb5 | 821 | struct lib80211_crypt_data *crypt; |
94a79942 LF |
822 | |
823 | char *ssid = ieee->current_network.ssid; | |
824 | int ssid_len = ieee->current_network.ssid_len; | |
825 | int rate_len = ieee->current_network.rates_len+2; | |
826 | int rate_ex_len = ieee->current_network.rates_ex_len; | |
827 | int wpa_ie_len = ieee->wpa_ie_len; | |
828 | u8 erpinfo_content = 0; | |
829 | ||
9d92ece8 | 830 | u8 *tmp_ht_cap_buf = NULL; |
94a79942 | 831 | u8 tmp_ht_cap_len = 0; |
9d92ece8 | 832 | u8 *tmp_ht_info_buf = NULL; |
94a79942 | 833 | u8 tmp_ht_info_len = 0; |
7796d93e | 834 | struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; |
9d92ece8 | 835 | u8 *tmp_generic_ie_buf = NULL; |
94a79942 LF |
836 | u8 tmp_generic_ie_len = 0; |
837 | ||
838 | if (rate_ex_len > 0) | |
9d92ece8 | 839 | rate_ex_len += 2; |
94a79942 LF |
840 | |
841 | if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS) | |
842 | atim_len = 4; | |
843 | else | |
844 | atim_len = 0; | |
845 | ||
9d92ece8 LF |
846 | if ((ieee->current_network.mode == IEEE_G) || |
847 | (ieee->current_network.mode == IEEE_N_24G && | |
848 | ieee->pHTInfo->bCurSuppCCK)) { | |
94a79942 LF |
849 | erp_len = 3; |
850 | erpinfo_content = 0; | |
851 | if (ieee->current_network.buseprotection) | |
852 | erpinfo_content |= ERP_UseProtection; | |
9d92ece8 | 853 | } else |
94a79942 LF |
854 | erp_len = 0; |
855 | ||
0ddcf5fd | 856 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
94a79942 | 857 | encrypt = ieee->host_encrypt && crypt && crypt->ops && |
3b148be0 | 858 | ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len)); |
9d92ece8 LF |
859 | if (ieee->pHTInfo->bCurrentHTSupport) { |
860 | tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap); | |
94a79942 | 861 | tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap); |
9d92ece8 | 862 | tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo); |
94a79942 | 863 | tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo); |
9d92ece8 LF |
864 | HTConstructCapabilityElement(ieee, tmp_ht_cap_buf, |
865 | &tmp_ht_cap_len, encrypt, false); | |
866 | HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len, | |
867 | encrypt); | |
94a79942 | 868 | |
9d92ece8 | 869 | if (pHTInfo->bRegRT2RTAggregation) { |
94a79942 | 870 | tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer; |
9d92ece8 LF |
871 | tmp_generic_ie_len = |
872 | sizeof(ieee->pHTInfo->szRT2RTAggBuffer); | |
873 | HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf, | |
874 | &tmp_generic_ie_len); | |
94a79942 LF |
875 | } |
876 | } | |
877 | ||
878 | beacon_size = sizeof(struct rtllib_probe_response)+2+ | |
9d92ece8 LF |
879 | ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len |
880 | + wpa_ie_len + ieee->tx_headroom; | |
94a79942 | 881 | skb = dev_alloc_skb(beacon_size); |
94a79942 LF |
882 | if (!skb) |
883 | return NULL; | |
884 | ||
94a79942 LF |
885 | skb_reserve(skb, ieee->tx_headroom); |
886 | ||
9d92ece8 LF |
887 | beacon_buf = (struct rtllib_probe_response *) skb_put(skb, |
888 | (beacon_size - ieee->tx_headroom)); | |
b57ceb19 MK |
889 | ether_addr_copy(beacon_buf->header.addr1, dest); |
890 | ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr); | |
891 | ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid); | |
94a79942 LF |
892 | |
893 | beacon_buf->header.duration_id = 0; | |
894 | beacon_buf->beacon_interval = | |
895 | cpu_to_le16(ieee->current_network.beacon_interval); | |
896 | beacon_buf->capability = | |
9d92ece8 LF |
897 | cpu_to_le16(ieee->current_network.capability & |
898 | WLAN_CAPABILITY_IBSS); | |
94a79942 | 899 | beacon_buf->capability |= |
9d92ece8 LF |
900 | cpu_to_le16(ieee->current_network.capability & |
901 | WLAN_CAPABILITY_SHORT_PREAMBLE); | |
94a79942 | 902 | |
9d92ece8 LF |
903 | if (ieee->short_slot && (ieee->current_network.capability & |
904 | WLAN_CAPABILITY_SHORT_SLOT_TIME)) | |
7fe30a7d RK |
905 | beacon_buf->capability |= |
906 | cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
94a79942 | 907 | |
0ddcf5fd | 908 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
94a79942 LF |
909 | if (encrypt) |
910 | beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); | |
911 | ||
912 | ||
913 | beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP); | |
914 | beacon_buf->info_element[0].id = MFIE_TYPE_SSID; | |
915 | beacon_buf->info_element[0].len = ssid_len; | |
916 | ||
9d92ece8 | 917 | tag = (u8 *) beacon_buf->info_element[0].data; |
94a79942 LF |
918 | |
919 | memcpy(tag, ssid, ssid_len); | |
920 | ||
921 | tag += ssid_len; | |
922 | ||
923 | *(tag++) = MFIE_TYPE_RATES; | |
924 | *(tag++) = rate_len-2; | |
9d92ece8 LF |
925 | memcpy(tag, ieee->current_network.rates, rate_len-2); |
926 | tag += rate_len-2; | |
94a79942 LF |
927 | |
928 | *(tag++) = MFIE_TYPE_DS_SET; | |
929 | *(tag++) = 1; | |
930 | *(tag++) = ieee->current_network.channel; | |
931 | ||
9d92ece8 LF |
932 | if (atim_len) { |
933 | u16 val16; | |
94a79942 LF |
934 | *(tag++) = MFIE_TYPE_IBSS_SET; |
935 | *(tag++) = 2; | |
1830a6d8 | 936 | val16 = ieee->current_network.atim_window; |
94a79942 | 937 | memcpy((u8 *)tag, (u8 *)&val16, 2); |
9d92ece8 | 938 | tag += 2; |
94a79942 LF |
939 | } |
940 | ||
9d92ece8 | 941 | if (erp_len) { |
94a79942 LF |
942 | *(tag++) = MFIE_TYPE_ERP; |
943 | *(tag++) = 1; | |
944 | *(tag++) = erpinfo_content; | |
945 | } | |
9d92ece8 | 946 | if (rate_ex_len) { |
94a79942 LF |
947 | *(tag++) = MFIE_TYPE_RATES_EX; |
948 | *(tag++) = rate_ex_len-2; | |
9d92ece8 LF |
949 | memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2); |
950 | tag += rate_ex_len-2; | |
94a79942 LF |
951 | } |
952 | ||
9d92ece8 | 953 | if (wpa_ie_len) { |
94a79942 | 954 | if (ieee->iw_mode == IW_MODE_ADHOC) |
94a79942 | 955 | memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4); |
94a79942 LF |
956 | memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); |
957 | tag += ieee->wpa_ie_len; | |
958 | } | |
94a79942 LF |
959 | return skb; |
960 | } | |
961 | ||
ec0dc6be | 962 | static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest) |
94a79942 LF |
963 | { |
964 | struct sk_buff *skb; | |
9d92ece8 | 965 | u8 *tag; |
94a79942 | 966 | |
32c44cb5 | 967 | struct lib80211_crypt_data *crypt; |
94a79942 LF |
968 | struct rtllib_assoc_response_frame *assoc; |
969 | short encrypt; | |
970 | ||
971 | unsigned int rate_len = rtllib_MFIE_rate_len(ieee); | |
9d92ece8 LF |
972 | int len = sizeof(struct rtllib_assoc_response_frame) + rate_len + |
973 | ieee->tx_headroom; | |
94a79942 | 974 | |
94a79942 | 975 | skb = dev_alloc_skb(len); |
94a79942 LF |
976 | |
977 | if (!skb) | |
978 | return NULL; | |
979 | ||
94a79942 LF |
980 | skb_reserve(skb, ieee->tx_headroom); |
981 | ||
982 | assoc = (struct rtllib_assoc_response_frame *) | |
9d92ece8 | 983 | skb_put(skb, sizeof(struct rtllib_assoc_response_frame)); |
94a79942 LF |
984 | |
985 | assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP); | |
b57ceb19 MK |
986 | ether_addr_copy(assoc->header.addr1, dest); |
987 | ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr); | |
988 | ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr); | |
94a79942 LF |
989 | assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ? |
990 | WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS); | |
991 | ||
992 | ||
993 | if (ieee->short_slot) | |
9d92ece8 LF |
994 | assoc->capability |= |
995 | cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
94a79942 LF |
996 | |
997 | if (ieee->host_encrypt) | |
0ddcf5fd | 998 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
94a79942 LF |
999 | else |
1000 | crypt = NULL; | |
1001 | ||
9d92ece8 | 1002 | encrypt = (crypt && crypt->ops); |
94a79942 LF |
1003 | |
1004 | if (encrypt) | |
1005 | assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); | |
1006 | ||
1007 | assoc->status = 0; | |
1008 | assoc->aid = cpu_to_le16(ieee->assoc_id); | |
1009 | if (ieee->assoc_id == 0x2007) | |
9d92ece8 | 1010 | ieee->assoc_id = 0; |
94a79942 LF |
1011 | else |
1012 | ieee->assoc_id++; | |
1013 | ||
9d92ece8 | 1014 | tag = (u8 *) skb_put(skb, rate_len); |
94a79942 LF |
1015 | rtllib_MFIE_Brate(ieee, &tag); |
1016 | rtllib_MFIE_Grate(ieee, &tag); | |
1017 | ||
1018 | return skb; | |
1019 | } | |
1020 | ||
ec0dc6be | 1021 | static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status, |
9d92ece8 | 1022 | u8 *dest) |
94a79942 LF |
1023 | { |
1024 | struct sk_buff *skb = NULL; | |
1025 | struct rtllib_authentication *auth; | |
9d92ece8 | 1026 | int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1; |
3a6b70c3 | 1027 | |
94a79942 | 1028 | skb = dev_alloc_skb(len); |
94a79942 LF |
1029 | if (!skb) |
1030 | return NULL; | |
1031 | ||
1032 | skb->len = sizeof(struct rtllib_authentication); | |
1033 | ||
94a79942 LF |
1034 | skb_reserve(skb, ieee->tx_headroom); |
1035 | ||
1036 | auth = (struct rtllib_authentication *) | |
1037 | skb_put(skb, sizeof(struct rtllib_authentication)); | |
1038 | ||
1039 | auth->status = cpu_to_le16(status); | |
1040 | auth->transaction = cpu_to_le16(2); | |
1041 | auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN); | |
1042 | ||
b57ceb19 MK |
1043 | ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr); |
1044 | ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr); | |
1045 | ether_addr_copy(auth->header.addr1, dest); | |
94a79942 LF |
1046 | auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH); |
1047 | return skb; | |
1048 | ||
1049 | ||
1050 | } | |
1051 | ||
ec0dc6be | 1052 | static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr) |
94a79942 LF |
1053 | { |
1054 | struct sk_buff *skb; | |
9d92ece8 | 1055 | struct rtllib_hdr_3addr *hdr; |
94a79942 | 1056 | |
94a79942 | 1057 | skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom); |
94a79942 LF |
1058 | if (!skb) |
1059 | return NULL; | |
1060 | ||
94a79942 LF |
1061 | skb_reserve(skb, ieee->tx_headroom); |
1062 | ||
9d92ece8 LF |
1063 | hdr = (struct rtllib_hdr_3addr *)skb_put(skb, |
1064 | sizeof(struct rtllib_hdr_3addr)); | |
94a79942 | 1065 | |
b57ceb19 MK |
1066 | ether_addr_copy(hdr->addr1, ieee->current_network.bssid); |
1067 | ether_addr_copy(hdr->addr2, ieee->dev->dev_addr); | |
1068 | ether_addr_copy(hdr->addr3, ieee->current_network.bssid); | |
94a79942 LF |
1069 | |
1070 | hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA | | |
1071 | RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS | | |
9d92ece8 | 1072 | (pwr ? RTLLIB_FCTL_PM : 0)); |
94a79942 LF |
1073 | |
1074 | return skb; | |
1075 | ||
1076 | ||
1077 | } | |
1078 | ||
ec0dc6be | 1079 | static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee) |
94a79942 LF |
1080 | { |
1081 | struct sk_buff *skb; | |
9d92ece8 | 1082 | struct rtllib_pspoll_hdr *hdr; |
94a79942 | 1083 | |
94a79942 | 1084 | skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom); |
94a79942 LF |
1085 | if (!skb) |
1086 | return NULL; | |
1087 | ||
94a79942 LF |
1088 | skb_reserve(skb, ieee->tx_headroom); |
1089 | ||
9d92ece8 LF |
1090 | hdr = (struct rtllib_pspoll_hdr *)skb_put(skb, |
1091 | sizeof(struct rtllib_pspoll_hdr)); | |
94a79942 | 1092 | |
b57ceb19 MK |
1093 | ether_addr_copy(hdr->bssid, ieee->current_network.bssid); |
1094 | ether_addr_copy(hdr->ta, ieee->dev->dev_addr); | |
94a79942 LF |
1095 | |
1096 | hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000); | |
9d92ece8 LF |
1097 | hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL | |
1098 | RTLLIB_FCTL_PM); | |
94a79942 LF |
1099 | |
1100 | return skb; | |
1101 | ||
1102 | } | |
1103 | ||
ec0dc6be | 1104 | static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest) |
94a79942 LF |
1105 | { |
1106 | struct sk_buff *buf = rtllib_assoc_resp(ieee, dest); | |
1107 | ||
1108 | if (buf) | |
1109 | softmac_mgmt_xmit(buf, ieee); | |
1110 | } | |
1111 | ||
1112 | ||
ec0dc6be | 1113 | static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest) |
94a79942 LF |
1114 | { |
1115 | struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest); | |
1116 | ||
1117 | if (buf) | |
1118 | softmac_mgmt_xmit(buf, ieee); | |
1119 | } | |
1120 | ||
1121 | ||
ec0dc6be | 1122 | static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest) |
94a79942 | 1123 | { |
94a79942 | 1124 | struct sk_buff *buf = rtllib_probe_resp(ieee, dest); |
3a6b70c3 | 1125 | |
94a79942 LF |
1126 | if (buf) |
1127 | softmac_mgmt_xmit(buf, ieee); | |
1128 | } | |
1129 | ||
1130 | ||
1131 | inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid) | |
1132 | { | |
1133 | int i = 0; | |
1134 | ||
9d92ece8 LF |
1135 | do { |
1136 | if ((ieee->PMKIDList[i].bUsed) && | |
1137 | (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0)) | |
94a79942 | 1138 | break; |
92db2a27 | 1139 | i++; |
94a79942 LF |
1140 | } while (i < NUM_PMKID_CACHE); |
1141 | ||
1142 | if (i == NUM_PMKID_CACHE) | |
94a79942 | 1143 | i = -1; |
9d92ece8 | 1144 | return i; |
94a79942 LF |
1145 | } |
1146 | ||
9d92ece8 LF |
1147 | inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon, |
1148 | struct rtllib_device *ieee) | |
94a79942 LF |
1149 | { |
1150 | struct sk_buff *skb; | |
94a79942 LF |
1151 | struct rtllib_assoc_request_frame *hdr; |
1152 | u8 *tag, *ies; | |
1153 | int i; | |
9d92ece8 LF |
1154 | u8 *ht_cap_buf = NULL; |
1155 | u8 ht_cap_len = 0; | |
1156 | u8 *realtek_ie_buf = NULL; | |
1157 | u8 realtek_ie_len = 0; | |
1158 | int wpa_ie_len = ieee->wpa_ie_len; | |
94a79942 | 1159 | int wps_ie_len = ieee->wps_ie_len; |
9d92ece8 LF |
1160 | unsigned int ckip_ie_len = 0; |
1161 | unsigned int ccxrm_ie_len = 0; | |
1162 | unsigned int cxvernum_ie_len = 0; | |
32c44cb5 | 1163 | struct lib80211_crypt_data *crypt; |
94a79942 LF |
1164 | int encrypt; |
1165 | int PMKCacheIdx; | |
1166 | ||
9d92ece8 LF |
1167 | unsigned int rate_len = (beacon->rates_len ? |
1168 | (beacon->rates_len + 2) : 0) + | |
1169 | (beacon->rates_ex_len ? (beacon->rates_ex_len) + | |
1170 | 2 : 0); | |
94a79942 | 1171 | |
9d92ece8 LF |
1172 | unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0; |
1173 | unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0; | |
94a79942 LF |
1174 | |
1175 | int len = 0; | |
3a6b70c3 | 1176 | |
0ddcf5fd | 1177 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
9d92ece8 LF |
1178 | if (crypt != NULL) |
1179 | encrypt = ieee->host_encrypt && crypt && crypt->ops && | |
3b148be0 | 1180 | ((0 == strcmp(crypt->ops->name, "R-WEP") || |
9d92ece8 LF |
1181 | wpa_ie_len)); |
1182 | else | |
94a79942 | 1183 | encrypt = 0; |
94a79942 | 1184 | |
9d92ece8 LF |
1185 | if ((ieee->rtllib_ap_sec_type && |
1186 | (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) || | |
4bb01423 | 1187 | ieee->bForcedBgMode) { |
94a79942 LF |
1188 | ieee->pHTInfo->bEnableHT = 0; |
1189 | ieee->mode = WIRELESS_MODE_G; | |
1190 | } | |
1191 | ||
9d92ece8 LF |
1192 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
1193 | ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap); | |
94a79942 | 1194 | ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap); |
9d92ece8 LF |
1195 | HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len, |
1196 | encrypt, true); | |
94a79942 LF |
1197 | if (ieee->pHTInfo->bCurrentRT2RTAggregation) { |
1198 | realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer; | |
9d92ece8 LF |
1199 | realtek_ie_len = |
1200 | sizeof(ieee->pHTInfo->szRT2RTAggBuffer); | |
1201 | HTConstructRT2RTAggElement(ieee, realtek_ie_buf, | |
1202 | &realtek_ie_len); | |
94a79942 LF |
1203 | } |
1204 | } | |
1205 | ||
1206 | if (beacon->bCkipSupported) | |
94a79942 | 1207 | ckip_ie_len = 30+2; |
94a79942 | 1208 | if (beacon->bCcxRmEnable) |
94a79942 | 1209 | ccxrm_ie_len = 6+2; |
9d92ece8 | 1210 | if (beacon->BssCcxVerNumber >= 2) |
94a79942 | 1211 | cxvernum_ie_len = 5+2; |
94a79942 LF |
1212 | |
1213 | PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid); | |
9d92ece8 | 1214 | if (PMKCacheIdx >= 0) { |
94a79942 | 1215 | wpa_ie_len += 18; |
d69d2054 MK |
1216 | netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n", |
1217 | wpa_ie_len); | |
94a79942 | 1218 | } |
9d92ece8 | 1219 | len = sizeof(struct rtllib_assoc_request_frame) + 2 |
94a79942 LF |
1220 | + beacon->ssid_len |
1221 | + rate_len | |
1222 | + wpa_ie_len | |
1223 | + wps_ie_len | |
1224 | + wmm_info_len | |
1225 | + turbo_info_len | |
9d92ece8 | 1226 | + ht_cap_len |
94a79942 LF |
1227 | + realtek_ie_len |
1228 | + ckip_ie_len | |
1229 | + ccxrm_ie_len | |
1230 | + cxvernum_ie_len | |
1231 | + ieee->tx_headroom; | |
1232 | ||
94a79942 | 1233 | skb = dev_alloc_skb(len); |
94a79942 LF |
1234 | |
1235 | if (!skb) | |
1236 | return NULL; | |
1237 | ||
94a79942 LF |
1238 | skb_reserve(skb, ieee->tx_headroom); |
1239 | ||
1240 | hdr = (struct rtllib_assoc_request_frame *) | |
9d92ece8 | 1241 | skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2); |
94a79942 LF |
1242 | |
1243 | ||
fa70ae09 | 1244 | hdr->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_REQ); |
1830a6d8 | 1245 | hdr->header.duration_id = cpu_to_le16(37); |
b57ceb19 MK |
1246 | ether_addr_copy(hdr->header.addr1, beacon->bssid); |
1247 | ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr); | |
1248 | ether_addr_copy(hdr->header.addr3, beacon->bssid); | |
94a79942 | 1249 | |
b57ceb19 | 1250 | ether_addr_copy(ieee->ap_mac_addr, beacon->bssid); |
94a79942 LF |
1251 | |
1252 | hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS); | |
9d92ece8 | 1253 | if (beacon->capability & WLAN_CAPABILITY_PRIVACY) |
94a79942 LF |
1254 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); |
1255 | ||
1256 | if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) | |
1257 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); | |
1258 | ||
9d92ece8 LF |
1259 | if (ieee->short_slot && |
1260 | (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME)) | |
94a79942 LF |
1261 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
1262 | ||
1263 | ||
1830a6d8 | 1264 | hdr->listen_interval = cpu_to_le16(beacon->listen_interval); |
94a79942 LF |
1265 | |
1266 | hdr->info_element[0].id = MFIE_TYPE_SSID; | |
1267 | ||
1268 | hdr->info_element[0].len = beacon->ssid_len; | |
1269 | tag = skb_put(skb, beacon->ssid_len); | |
1270 | memcpy(tag, beacon->ssid, beacon->ssid_len); | |
1271 | ||
1272 | tag = skb_put(skb, rate_len); | |
1273 | ||
9d92ece8 | 1274 | if (beacon->rates_len) { |
94a79942 LF |
1275 | *tag++ = MFIE_TYPE_RATES; |
1276 | *tag++ = beacon->rates_len; | |
9d92ece8 | 1277 | for (i = 0; i < beacon->rates_len; i++) |
94a79942 | 1278 | *tag++ = beacon->rates[i]; |
94a79942 LF |
1279 | } |
1280 | ||
9d92ece8 | 1281 | if (beacon->rates_ex_len) { |
94a79942 LF |
1282 | *tag++ = MFIE_TYPE_RATES_EX; |
1283 | *tag++ = beacon->rates_ex_len; | |
9d92ece8 | 1284 | for (i = 0; i < beacon->rates_ex_len; i++) |
94a79942 | 1285 | *tag++ = beacon->rates_ex[i]; |
94a79942 LF |
1286 | } |
1287 | ||
9d92ece8 | 1288 | if (beacon->bCkipSupported) { |
16fc54ee | 1289 | static const u8 AironetIeOui[] = {0x00, 0x01, 0x66}; |
94a79942 | 1290 | u8 CcxAironetBuf[30]; |
8310b6c0 | 1291 | struct octet_string osCcxAironetIE; |
94a79942 | 1292 | |
9d92ece8 | 1293 | memset(CcxAironetBuf, 0, 30); |
94a79942 LF |
1294 | osCcxAironetIE.Octet = CcxAironetBuf; |
1295 | osCcxAironetIE.Length = sizeof(CcxAironetBuf); | |
9d92ece8 LF |
1296 | memcpy(osCcxAironetIE.Octet, AironetIeOui, |
1297 | sizeof(AironetIeOui)); | |
94a79942 | 1298 | |
9d92ece8 LF |
1299 | osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |= |
1300 | (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC); | |
94a79942 LF |
1301 | tag = skb_put(skb, ckip_ie_len); |
1302 | *tag++ = MFIE_TYPE_AIRONET; | |
1303 | *tag++ = osCcxAironetIE.Length; | |
9d92ece8 | 1304 | memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length); |
94a79942 LF |
1305 | tag += osCcxAironetIE.Length; |
1306 | } | |
1307 | ||
9d92ece8 | 1308 | if (beacon->bCcxRmEnable) { |
16fc54ee BW |
1309 | static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01, |
1310 | 0x00}; | |
8310b6c0 | 1311 | struct octet_string osCcxRmCap; |
94a79942 | 1312 | |
16fc54ee | 1313 | osCcxRmCap.Octet = (u8 *) CcxRmCapBuf; |
94a79942 | 1314 | osCcxRmCap.Length = sizeof(CcxRmCapBuf); |
9d92ece8 | 1315 | tag = skb_put(skb, ccxrm_ie_len); |
94a79942 LF |
1316 | *tag++ = MFIE_TYPE_GENERIC; |
1317 | *tag++ = osCcxRmCap.Length; | |
9d92ece8 | 1318 | memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length); |
94a79942 LF |
1319 | tag += osCcxRmCap.Length; |
1320 | } | |
1321 | ||
9d92ece8 LF |
1322 | if (beacon->BssCcxVerNumber >= 2) { |
1323 | u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00}; | |
8310b6c0 | 1324 | struct octet_string osCcxVerNum; |
3a6b70c3 | 1325 | |
94a79942 LF |
1326 | CcxVerNumBuf[4] = beacon->BssCcxVerNumber; |
1327 | osCcxVerNum.Octet = CcxVerNumBuf; | |
1328 | osCcxVerNum.Length = sizeof(CcxVerNumBuf); | |
9d92ece8 | 1329 | tag = skb_put(skb, cxvernum_ie_len); |
94a79942 LF |
1330 | *tag++ = MFIE_TYPE_GENERIC; |
1331 | *tag++ = osCcxVerNum.Length; | |
9d92ece8 | 1332 | memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length); |
94a79942 LF |
1333 | tag += osCcxVerNum.Length; |
1334 | } | |
9d92ece8 LF |
1335 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
1336 | if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) { | |
94a79942 LF |
1337 | tag = skb_put(skb, ht_cap_len); |
1338 | *tag++ = MFIE_TYPE_HT_CAP; | |
1339 | *tag++ = ht_cap_len - 2; | |
9d92ece8 LF |
1340 | memcpy(tag, ht_cap_buf, ht_cap_len - 2); |
1341 | tag += ht_cap_len - 2; | |
94a79942 LF |
1342 | } |
1343 | } | |
1344 | ||
9d92ece8 | 1345 | if (wpa_ie_len) { |
94a79942 LF |
1346 | tag = skb_put(skb, ieee->wpa_ie_len); |
1347 | memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); | |
1348 | ||
9d92ece8 | 1349 | if (PMKCacheIdx >= 0) { |
94a79942 LF |
1350 | tag = skb_put(skb, 18); |
1351 | *tag = 1; | |
1352 | *(tag + 1) = 0; | |
9d92ece8 LF |
1353 | memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID, |
1354 | 16); | |
94a79942 LF |
1355 | } |
1356 | } | |
1357 | if (wmm_info_len) { | |
9d92ece8 | 1358 | tag = skb_put(skb, wmm_info_len); |
94a79942 LF |
1359 | rtllib_WMM_Info(ieee, &tag); |
1360 | } | |
1361 | ||
1362 | if (wps_ie_len && ieee->wps_ie) { | |
1363 | tag = skb_put(skb, wps_ie_len); | |
1364 | memcpy(tag, ieee->wps_ie, wps_ie_len); | |
1365 | } | |
1366 | ||
9d92ece8 LF |
1367 | tag = skb_put(skb, turbo_info_len); |
1368 | if (turbo_info_len) | |
1369 | rtllib_TURBO_Info(ieee, &tag); | |
94a79942 | 1370 | |
9d92ece8 LF |
1371 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
1372 | if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) { | |
94a79942 LF |
1373 | tag = skb_put(skb, ht_cap_len); |
1374 | *tag++ = MFIE_TYPE_GENERIC; | |
1375 | *tag++ = ht_cap_len - 2; | |
9d92ece8 LF |
1376 | memcpy(tag, ht_cap_buf, ht_cap_len - 2); |
1377 | tag += ht_cap_len - 2; | |
94a79942 LF |
1378 | } |
1379 | ||
9d92ece8 | 1380 | if (ieee->pHTInfo->bCurrentRT2RTAggregation) { |
94a79942 LF |
1381 | tag = skb_put(skb, realtek_ie_len); |
1382 | *tag++ = MFIE_TYPE_GENERIC; | |
1383 | *tag++ = realtek_ie_len - 2; | |
9d92ece8 | 1384 | memcpy(tag, realtek_ie_buf, realtek_ie_len - 2); |
94a79942 LF |
1385 | } |
1386 | } | |
1387 | ||
9d92ece8 LF |
1388 | kfree(ieee->assocreq_ies); |
1389 | ieee->assocreq_ies = NULL; | |
94a79942 LF |
1390 | ies = &(hdr->info_element[0].id); |
1391 | ieee->assocreq_ies_len = (skb->data + skb->len) - ies; | |
1392 | ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC); | |
1393 | if (ieee->assocreq_ies) | |
1394 | memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len); | |
9d92ece8 | 1395 | else { |
d69d2054 MK |
1396 | netdev_info(ieee->dev, |
1397 | "%s()Warning: can't alloc memory for assocreq_ies\n", | |
1398 | __func__); | |
94a79942 LF |
1399 | ieee->assocreq_ies_len = 0; |
1400 | } | |
94a79942 LF |
1401 | return skb; |
1402 | } | |
1403 | ||
1404 | void rtllib_associate_abort(struct rtllib_device *ieee) | |
1405 | { | |
94a79942 | 1406 | unsigned long flags; |
3a6b70c3 | 1407 | |
94a79942 LF |
1408 | spin_lock_irqsave(&ieee->lock, flags); |
1409 | ||
1410 | ieee->associate_seq++; | |
1411 | ||
1412 | /* don't scan, and avoid to have the RX path possibily | |
1413 | * try again to associate. Even do not react to AUTH or | |
1414 | * ASSOC response. Just wait for the retry wq to be scheduled. | |
1415 | * Here we will check if there are good nets to associate | |
1416 | * with, so we retry or just get back to NO_LINK and scanning | |
1417 | */ | |
9d92ece8 | 1418 | if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) { |
e9fea2ec | 1419 | netdev_dbg(ieee->dev, "Authentication failed\n"); |
94a79942 | 1420 | ieee->softmac_stats.no_auth_rs++; |
9d92ece8 | 1421 | } else { |
e9fea2ec | 1422 | netdev_dbg(ieee->dev, "Association failed\n"); |
94a79942 LF |
1423 | ieee->softmac_stats.no_ass_rs++; |
1424 | } | |
1425 | ||
1426 | ieee->state = RTLLIB_ASSOCIATING_RETRY; | |
1427 | ||
9d92ece8 LF |
1428 | queue_delayed_work_rsl(ieee->wq, &ieee->associate_retry_wq, |
1429 | RTLLIB_SOFTMAC_ASSOC_RETRY_TIME); | |
94a79942 LF |
1430 | |
1431 | spin_unlock_irqrestore(&ieee->lock, flags); | |
1432 | } | |
1433 | ||
ec0dc6be | 1434 | static void rtllib_associate_abort_cb(unsigned long dev) |
94a79942 LF |
1435 | { |
1436 | rtllib_associate_abort((struct rtllib_device *) dev); | |
1437 | } | |
1438 | ||
a0711c4d | 1439 | static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr) |
94a79942 LF |
1440 | { |
1441 | struct rtllib_network *beacon = &ieee->current_network; | |
1442 | struct sk_buff *skb; | |
1443 | ||
e9fea2ec | 1444 | netdev_dbg(ieee->dev, "Stopping scan\n"); |
94a79942 LF |
1445 | |
1446 | ieee->softmac_stats.tx_auth_rq++; | |
1447 | ||
9d92ece8 | 1448 | skb = rtllib_authentication_req(beacon, ieee, 0, daddr); |
94a79942 LF |
1449 | |
1450 | if (!skb) | |
1451 | rtllib_associate_abort(ieee); | |
9d92ece8 | 1452 | else { |
dc986e3e | 1453 | ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING; |
e9fea2ec | 1454 | netdev_dbg(ieee->dev, "Sending authentication request\n"); |
94a79942 | 1455 | softmac_mgmt_xmit(skb, ieee); |
9d92ece8 | 1456 | if (!timer_pending(&ieee->associate_timer)) { |
94a79942 LF |
1457 | ieee->associate_timer.expires = jiffies + (HZ / 2); |
1458 | add_timer(&ieee->associate_timer); | |
1459 | } | |
1460 | } | |
1461 | } | |
1462 | ||
35e33b04 MK |
1463 | static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge, |
1464 | int chlen) | |
94a79942 LF |
1465 | { |
1466 | u8 *c; | |
1467 | struct sk_buff *skb; | |
1468 | struct rtllib_network *beacon = &ieee->current_network; | |
1469 | ||
1470 | ieee->associate_seq++; | |
1471 | ieee->softmac_stats.tx_auth_rq++; | |
1472 | ||
9d92ece8 | 1473 | skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid); |
94a79942 LF |
1474 | |
1475 | if (!skb) | |
1476 | rtllib_associate_abort(ieee); | |
9d92ece8 | 1477 | else { |
94a79942 LF |
1478 | c = skb_put(skb, chlen+2); |
1479 | *(c++) = MFIE_TYPE_CHALLENGE; | |
1480 | *(c++) = chlen; | |
1481 | memcpy(c, challenge, chlen); | |
1482 | ||
e9fea2ec MK |
1483 | netdev_dbg(ieee->dev, |
1484 | "Sending authentication challenge response\n"); | |
94a79942 | 1485 | |
9d92ece8 LF |
1486 | rtllib_encrypt_fragment(ieee, skb, |
1487 | sizeof(struct rtllib_hdr_3addr)); | |
94a79942 LF |
1488 | |
1489 | softmac_mgmt_xmit(skb, ieee); | |
1490 | mod_timer(&ieee->associate_timer, jiffies + (HZ/2)); | |
1491 | } | |
1492 | kfree(challenge); | |
1493 | } | |
1494 | ||
ec0dc6be | 1495 | static void rtllib_associate_step2(struct rtllib_device *ieee) |
94a79942 | 1496 | { |
9d92ece8 | 1497 | struct sk_buff *skb; |
94a79942 LF |
1498 | struct rtllib_network *beacon = &ieee->current_network; |
1499 | ||
1500 | del_timer_sync(&ieee->associate_timer); | |
1501 | ||
e9fea2ec | 1502 | netdev_dbg(ieee->dev, "Sending association request\n"); |
94a79942 LF |
1503 | |
1504 | ieee->softmac_stats.tx_ass_rq++; | |
9d92ece8 | 1505 | skb = rtllib_association_req(beacon, ieee); |
94a79942 LF |
1506 | if (!skb) |
1507 | rtllib_associate_abort(ieee); | |
9d92ece8 | 1508 | else { |
94a79942 LF |
1509 | softmac_mgmt_xmit(skb, ieee); |
1510 | mod_timer(&ieee->associate_timer, jiffies + (HZ/2)); | |
1511 | } | |
1512 | } | |
1513 | ||
1514 | #define CANCELLED 2 | |
ec0dc6be | 1515 | static void rtllib_associate_complete_wq(void *data) |
94a79942 | 1516 | { |
9d92ece8 LF |
1517 | struct rtllib_device *ieee = (struct rtllib_device *) |
1518 | container_of_work_rsl(data, | |
1519 | struct rtllib_device, | |
1520 | associate_complete_wq); | |
1521 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) | |
1522 | (&(ieee->PowerSaveControl)); | |
d69d2054 | 1523 | netdev_info(ieee->dev, "Associated successfully\n"); |
4bb01423 | 1524 | if (!ieee->is_silent_reset) { |
d69d2054 | 1525 | netdev_info(ieee->dev, "normal associate\n"); |
9d92ece8 LF |
1526 | notify_wx_assoc_event(ieee); |
1527 | } | |
94a79942 LF |
1528 | |
1529 | netif_carrier_on(ieee->dev); | |
1530 | ieee->is_roaming = false; | |
1531 | if (rtllib_is_54g(&ieee->current_network) && | |
9d92ece8 | 1532 | (ieee->modulation & RTLLIB_OFDM_MODULATION)) { |
94a79942 | 1533 | ieee->rate = 108; |
d69d2054 | 1534 | netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate); |
9d92ece8 | 1535 | } else { |
94a79942 LF |
1536 | ieee->rate = 22; |
1537 | ieee->SetWirelessMode(ieee->dev, IEEE_B); | |
d69d2054 | 1538 | netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate); |
94a79942 | 1539 | } |
9d92ece8 | 1540 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
d69d2054 | 1541 | netdev_info(ieee->dev, "Successfully associated, ht enabled\n"); |
94a79942 LF |
1542 | HTOnAssocRsp(ieee); |
1543 | } else { | |
d69d2054 MK |
1544 | netdev_info(ieee->dev, |
1545 | "Successfully associated, ht not enabled(%d, %d)\n", | |
1546 | ieee->pHTInfo->bCurrentHTSupport, | |
1547 | ieee->pHTInfo->bEnableHT); | |
94a79942 LF |
1548 | memset(ieee->dot11HTOperationalRateSet, 0, 16); |
1549 | } | |
9d92ece8 LF |
1550 | ieee->LinkDetectInfo.SlotNum = 2 * (1 + |
1551 | ieee->current_network.beacon_interval / | |
1552 | 500); | |
1553 | if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 || | |
1554 | ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) { | |
94a79942 | 1555 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1; |
9d92ece8 | 1556 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 1; |
94a79942 LF |
1557 | } |
1558 | pPSC->LpsIdleCount = 0; | |
1559 | ieee->link_change(ieee->dev); | |
1560 | ||
4bb01423 | 1561 | if (ieee->is_silent_reset) { |
d69d2054 | 1562 | netdev_info(ieee->dev, "silent reset associate\n"); |
014e4c27 | 1563 | ieee->is_silent_reset = false; |
9d92ece8 | 1564 | } |
94a79942 LF |
1565 | |
1566 | if (ieee->data_hard_resume) | |
1567 | ieee->data_hard_resume(ieee->dev); | |
1568 | ||
94a79942 LF |
1569 | } |
1570 | ||
1571 | static void rtllib_sta_send_associnfo(struct rtllib_device *ieee) | |
1572 | { | |
94a79942 LF |
1573 | } |
1574 | ||
ec0dc6be | 1575 | static void rtllib_associate_complete(struct rtllib_device *ieee) |
94a79942 LF |
1576 | { |
1577 | del_timer_sync(&ieee->associate_timer); | |
1578 | ||
1579 | ieee->state = RTLLIB_LINKED; | |
1580 | rtllib_sta_send_associnfo(ieee); | |
1581 | ||
1582 | queue_work_rsl(ieee->wq, &ieee->associate_complete_wq); | |
1583 | } | |
1584 | ||
ec0dc6be | 1585 | static void rtllib_associate_procedure_wq(void *data) |
94a79942 | 1586 | { |
9d92ece8 LF |
1587 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
1588 | struct rtllib_device, | |
1589 | associate_procedure_wq); | |
94a79942 LF |
1590 | rtllib_stop_scan_syncro(ieee); |
1591 | if (ieee->rtllib_ips_leave != NULL) | |
1592 | ieee->rtllib_ips_leave(ieee->dev); | |
1593 | down(&ieee->wx_sem); | |
1594 | ||
1595 | if (ieee->data_hard_stop) | |
1596 | ieee->data_hard_stop(ieee->dev); | |
1597 | ||
1598 | rtllib_stop_scan(ieee); | |
9d92ece8 LF |
1599 | RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__, |
1600 | ieee->current_network.channel); | |
94a79942 | 1601 | HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); |
9d92ece8 | 1602 | if (ieee->eRFPowerState == eRfOff) { |
0822339b MK |
1603 | RT_TRACE(COMP_DBG, |
1604 | "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n", | |
1605 | __func__); | |
94a79942 LF |
1606 | if (ieee->rtllib_ips_leave_wq != NULL) |
1607 | ieee->rtllib_ips_leave_wq(ieee->dev); | |
1608 | up(&ieee->wx_sem); | |
1609 | return; | |
1610 | } | |
1611 | ieee->associate_seq = 1; | |
1612 | ||
1613 | rtllib_associate_step1(ieee, ieee->current_network.bssid); | |
1614 | ||
1615 | up(&ieee->wx_sem); | |
1616 | } | |
1617 | ||
9d92ece8 LF |
1618 | inline void rtllib_softmac_new_net(struct rtllib_device *ieee, |
1619 | struct rtllib_network *net) | |
94a79942 | 1620 | { |
9d92ece8 | 1621 | u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1]; |
94a79942 LF |
1622 | int tmp_ssid_len = 0; |
1623 | ||
9d92ece8 | 1624 | short apset, ssidset, ssidbroad, apmatch, ssidmatch; |
94a79942 LF |
1625 | |
1626 | /* we are interested in new new only if we are not associated | |
1627 | * and we are not associating / authenticating | |
1628 | */ | |
1629 | if (ieee->state != RTLLIB_NOLINK) | |
1630 | return; | |
1631 | ||
9d92ece8 LF |
1632 | if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & |
1633 | WLAN_CAPABILITY_ESS)) | |
94a79942 LF |
1634 | return; |
1635 | ||
9d92ece8 LF |
1636 | if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & |
1637 | WLAN_CAPABILITY_IBSS)) | |
94a79942 LF |
1638 | return; |
1639 | ||
9d92ece8 LF |
1640 | if ((ieee->iw_mode == IW_MODE_ADHOC) && |
1641 | (net->channel > ieee->ibss_maxjoin_chal)) | |
94a79942 | 1642 | return; |
9d92ece8 | 1643 | if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) { |
94a79942 LF |
1644 | /* if the user specified the AP MAC, we need also the essid |
1645 | * This could be obtained by beacons or, if the network does not | |
1646 | * broadcast it, it can be put manually. | |
1647 | */ | |
1648 | apset = ieee->wap_set; | |
1649 | ssidset = ieee->ssid_set; | |
9d92ece8 LF |
1650 | ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0'); |
1651 | apmatch = (memcmp(ieee->current_network.bssid, net->bssid, | |
1652 | ETH_ALEN) == 0); | |
1653 | if (!ssidbroad) { | |
1654 | ssidmatch = (ieee->current_network.ssid_len == | |
1655 | net->hidden_ssid_len) && | |
1656 | (!strncmp(ieee->current_network.ssid, | |
1657 | net->hidden_ssid, net->hidden_ssid_len)); | |
1658 | if (net->hidden_ssid_len > 0) { | |
1659 | strncpy(net->ssid, net->hidden_ssid, | |
1660 | net->hidden_ssid_len); | |
1661 | net->ssid_len = net->hidden_ssid_len; | |
1662 | ssidbroad = 1; | |
1663 | } | |
1664 | } else | |
1665 | ssidmatch = | |
1666 | (ieee->current_network.ssid_len == net->ssid_len) && | |
1667 | (!strncmp(ieee->current_network.ssid, net->ssid, | |
1668 | net->ssid_len)); | |
1669 | ||
1670 | /* if the user set the AP check if match. | |
1671 | * if the network does not broadcast essid we check the | |
cd017123 | 1672 | * user supplied ANY essid |
9d92ece8 LF |
1673 | * if the network does broadcast and the user does not set |
1674 | * essid it is OK | |
1675 | * if the network does broadcast and the user did set essid | |
1676 | * check if essid match | |
1677 | * if the ap is not set, check that the user set the bssid | |
db2c8da0 | 1678 | * and the network does broadcast and that those two bssid match |
9d92ece8 LF |
1679 | */ |
1680 | if ((apset && apmatch && | |
1681 | ((ssidset && ssidbroad && ssidmatch) || | |
1682 | (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || | |
1683 | (!apset && ssidset && ssidbroad && ssidmatch) || | |
1684 | (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) { | |
1685 | /* if the essid is hidden replace it with the | |
14b40d92 MK |
1686 | * essid provided by the user. |
1687 | */ | |
9d92ece8 LF |
1688 | if (!ssidbroad) { |
1689 | strncpy(tmp_ssid, ieee->current_network.ssid, | |
1690 | IW_ESSID_MAX_SIZE); | |
1691 | tmp_ssid_len = ieee->current_network.ssid_len; | |
1692 | } | |
1693 | memcpy(&ieee->current_network, net, | |
1694 | sizeof(struct rtllib_network)); | |
1695 | if (!ssidbroad) { | |
1696 | strncpy(ieee->current_network.ssid, tmp_ssid, | |
1697 | IW_ESSID_MAX_SIZE); | |
1698 | ieee->current_network.ssid_len = tmp_ssid_len; | |
1699 | } | |
d69d2054 MK |
1700 | netdev_info(ieee->dev, |
1701 | "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n", | |
1702 | ieee->current_network.ssid, | |
1703 | ieee->current_network.channel, | |
1704 | ieee->current_network.qos_data.supported, | |
1705 | ieee->pHTInfo->bEnableHT, | |
1706 | ieee->current_network.bssht.bdSupportHT, | |
1707 | ieee->current_network.mode, | |
1708 | ieee->current_network.flags); | |
9d92ece8 LF |
1709 | |
1710 | if ((rtllib_act_scanning(ieee, false)) && | |
1711 | !(ieee->softmac_features & IEEE_SOFTMAC_SCAN)) | |
1712 | rtllib_stop_scan_syncro(ieee); | |
1713 | ||
9d92ece8 LF |
1714 | HTResetIOTSetting(ieee->pHTInfo); |
1715 | ieee->wmm_acm = 0; | |
1716 | if (ieee->iw_mode == IW_MODE_INFRA) { | |
1717 | /* Join the network for the first time */ | |
1718 | ieee->AsocRetryCount = 0; | |
1719 | if ((ieee->current_network.qos_data.supported == 1) && | |
35e33b04 | 1720 | ieee->current_network.bssht.bdSupportHT) |
9d92ece8 LF |
1721 | HTResetSelfAndSavePeerSetting(ieee, |
1722 | &(ieee->current_network)); | |
1723 | else | |
1724 | ieee->pHTInfo->bCurrentHTSupport = | |
1725 | false; | |
1726 | ||
1727 | ieee->state = RTLLIB_ASSOCIATING; | |
1728 | if (ieee->LedControlHandler != NULL) | |
1729 | ieee->LedControlHandler(ieee->dev, | |
1730 | LED_CTL_START_TO_LINK); | |
1731 | queue_delayed_work_rsl(ieee->wq, | |
1732 | &ieee->associate_procedure_wq, 0); | |
1733 | } else { | |
1734 | if (rtllib_is_54g(&ieee->current_network) && | |
35e33b04 MK |
1735 | (ieee->modulation & |
1736 | RTLLIB_OFDM_MODULATION)) { | |
9d92ece8 | 1737 | ieee->rate = 108; |
35e33b04 MK |
1738 | ieee->SetWirelessMode(ieee->dev, |
1739 | IEEE_G); | |
1740 | netdev_info(ieee->dev, | |
1741 | "Using G rates\n"); | |
94a79942 | 1742 | } else { |
9d92ece8 | 1743 | ieee->rate = 22; |
35e33b04 MK |
1744 | ieee->SetWirelessMode(ieee->dev, |
1745 | IEEE_B); | |
1746 | netdev_info(ieee->dev, | |
1747 | "Using B rates\n"); | |
94a79942 | 1748 | } |
9d92ece8 LF |
1749 | memset(ieee->dot11HTOperationalRateSet, 0, 16); |
1750 | ieee->state = RTLLIB_LINKED; | |
1751 | } | |
94a79942 LF |
1752 | } |
1753 | } | |
94a79942 LF |
1754 | } |
1755 | ||
1756 | void rtllib_softmac_check_all_nets(struct rtllib_device *ieee) | |
1757 | { | |
1758 | unsigned long flags; | |
1759 | struct rtllib_network *target; | |
1760 | ||
1761 | spin_lock_irqsave(&ieee->lock, flags); | |
1762 | ||
1763 | list_for_each_entry(target, &ieee->network_list, list) { | |
1764 | ||
1765 | /* if the state become different that NOLINK means | |
1766 | * we had found what we are searching for | |
1767 | */ | |
1768 | ||
1769 | if (ieee->state != RTLLIB_NOLINK) | |
1770 | break; | |
1771 | ||
9d92ece8 LF |
1772 | if (ieee->scan_age == 0 || time_after(target->last_scanned + |
1773 | ieee->scan_age, jiffies)) | |
1774 | rtllib_softmac_new_net(ieee, target); | |
94a79942 | 1775 | } |
94a79942 | 1776 | spin_unlock_irqrestore(&ieee->lock, flags); |
94a79942 LF |
1777 | } |
1778 | ||
e9fea2ec MK |
1779 | static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb, |
1780 | u8 **challenge, int *chlen) | |
94a79942 LF |
1781 | { |
1782 | struct rtllib_authentication *a; | |
1783 | u8 *t; | |
3a6b70c3 | 1784 | |
9d92ece8 LF |
1785 | if (skb->len < (sizeof(struct rtllib_authentication) - |
1786 | sizeof(struct rtllib_info_element))) { | |
e9fea2ec | 1787 | netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len); |
94a79942 LF |
1788 | return 0xcafe; |
1789 | } | |
1790 | *challenge = NULL; | |
9d92ece8 LF |
1791 | a = (struct rtllib_authentication *) skb->data; |
1792 | if (skb->len > (sizeof(struct rtllib_authentication) + 3)) { | |
94a79942 LF |
1793 | t = skb->data + sizeof(struct rtllib_authentication); |
1794 | ||
9d92ece8 | 1795 | if (*(t++) == MFIE_TYPE_CHALLENGE) { |
94a79942 | 1796 | *chlen = *(t++); |
6dea0da1 | 1797 | *challenge = kmemdup(t, *chlen, GFP_ATOMIC); |
ae053253 HP |
1798 | if (!*challenge) |
1799 | return -ENOMEM; | |
94a79942 LF |
1800 | } |
1801 | } | |
640f7d69 | 1802 | return le16_to_cpu(a->status); |
94a79942 LF |
1803 | } |
1804 | ||
e9fea2ec | 1805 | static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest) |
94a79942 LF |
1806 | { |
1807 | struct rtllib_authentication *a; | |
1808 | ||
9d92ece8 LF |
1809 | if (skb->len < (sizeof(struct rtllib_authentication) - |
1810 | sizeof(struct rtllib_info_element))) { | |
e9fea2ec | 1811 | netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len); |
94a79942 LF |
1812 | return -1; |
1813 | } | |
9d92ece8 | 1814 | a = (struct rtllib_authentication *) skb->data; |
94a79942 | 1815 | |
b57ceb19 | 1816 | ether_addr_copy(dest, a->header.addr2); |
94a79942 LF |
1817 | |
1818 | if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN) | |
1819 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; | |
1820 | ||
1821 | return WLAN_STATUS_SUCCESS; | |
1822 | } | |
1823 | ||
9d92ece8 LF |
1824 | static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb, |
1825 | u8 *src) | |
94a79942 LF |
1826 | { |
1827 | u8 *tag; | |
1828 | u8 *skbend; | |
9d92ece8 | 1829 | u8 *ssid = NULL; |
94a79942 | 1830 | u8 ssidlen = 0; |
94a79942 LF |
1831 | struct rtllib_hdr_3addr *header = |
1832 | (struct rtllib_hdr_3addr *) skb->data; | |
9d92ece8 | 1833 | bool bssid_match; |
94a79942 | 1834 | |
9d92ece8 | 1835 | if (skb->len < sizeof(struct rtllib_hdr_3addr)) |
94a79942 | 1836 | return -1; /* corrupted */ |
94a79942 | 1837 | |
9d92ece8 | 1838 | bssid_match = |
c2f8b4ab | 1839 | (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) && |
0c43e56c | 1840 | (!is_broadcast_ether_addr(header->addr3)); |
9d92ece8 LF |
1841 | if (bssid_match) |
1842 | return -1; | |
94a79942 | 1843 | |
b57ceb19 | 1844 | ether_addr_copy(src, header->addr2); |
94a79942 | 1845 | |
9d92ece8 | 1846 | skbend = (u8 *)skb->data + skb->len; |
94a79942 | 1847 | |
9d92ece8 | 1848 | tag = skb->data + sizeof(struct rtllib_hdr_3addr); |
94a79942 | 1849 | |
9d92ece8 LF |
1850 | while (tag + 1 < skbend) { |
1851 | if (*tag == 0) { | |
1852 | ssid = tag + 2; | |
1853 | ssidlen = *(tag + 1); | |
94a79942 LF |
1854 | break; |
1855 | } | |
1856 | tag++; /* point to the len field */ | |
1857 | tag = tag + *(tag); /* point to the last data byte of the tag */ | |
1858 | tag++; /* point to the next tag */ | |
1859 | } | |
1860 | ||
9d92ece8 LF |
1861 | if (ssidlen == 0) |
1862 | return 1; | |
94a79942 | 1863 | |
9d92ece8 LF |
1864 | if (!ssid) |
1865 | return 1; /* ssid not found in tagged param */ | |
94a79942 | 1866 | |
9d92ece8 | 1867 | return !strncmp(ssid, ieee->current_network.ssid, ssidlen); |
94a79942 LF |
1868 | } |
1869 | ||
e9fea2ec | 1870 | static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest) |
94a79942 LF |
1871 | { |
1872 | struct rtllib_assoc_request_frame *a; | |
1873 | ||
1874 | if (skb->len < (sizeof(struct rtllib_assoc_request_frame) - | |
1875 | sizeof(struct rtllib_info_element))) { | |
e9fea2ec | 1876 | netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len); |
94a79942 LF |
1877 | return -1; |
1878 | } | |
1879 | ||
9d92ece8 | 1880 | a = (struct rtllib_assoc_request_frame *) skb->data; |
94a79942 | 1881 | |
b57ceb19 | 1882 | ether_addr_copy(dest, a->header.addr2); |
94a79942 LF |
1883 | |
1884 | return 0; | |
1885 | } | |
1886 | ||
9d92ece8 LF |
1887 | static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb, |
1888 | int *aid) | |
94a79942 LF |
1889 | { |
1890 | struct rtllib_assoc_response_frame *response_head; | |
1891 | u16 status_code; | |
1892 | ||
9d92ece8 | 1893 | if (skb->len < sizeof(struct rtllib_assoc_response_frame)) { |
e9fea2ec MK |
1894 | netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n", |
1895 | skb->len); | |
94a79942 LF |
1896 | return 0xcafe; |
1897 | } | |
1898 | ||
9d92ece8 | 1899 | response_head = (struct rtllib_assoc_response_frame *) skb->data; |
94a79942 LF |
1900 | *aid = le16_to_cpu(response_head->aid) & 0x3fff; |
1901 | ||
1902 | status_code = le16_to_cpu(response_head->status); | |
9d92ece8 LF |
1903 | if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES || |
1904 | status_code == WLAN_STATUS_CAPS_UNSUPPORTED) && | |
94a79942 | 1905 | ((ieee->mode == IEEE_G) && |
9d92ece8 LF |
1906 | (ieee->current_network.mode == IEEE_N_24G) && |
1907 | (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) { | |
1908 | ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE; | |
1909 | } else { | |
1910 | ieee->AsocRetryCount = 0; | |
94a79942 LF |
1911 | } |
1912 | ||
1913 | return le16_to_cpu(response_head->status); | |
1914 | } | |
1915 | ||
1916 | void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb) | |
1917 | { | |
1918 | u8 dest[ETH_ALEN]; | |
3a6b70c3 | 1919 | |
94a79942 | 1920 | ieee->softmac_stats.rx_probe_rq++; |
9d92ece8 | 1921 | if (probe_rq_parse(ieee, skb, dest) > 0) { |
94a79942 LF |
1922 | ieee->softmac_stats.tx_probe_rs++; |
1923 | rtllib_resp_to_probe(ieee, dest); | |
94a79942 LF |
1924 | } |
1925 | } | |
1926 | ||
9d92ece8 LF |
1927 | static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee, |
1928 | struct sk_buff *skb) | |
94a79942 LF |
1929 | { |
1930 | u8 dest[ETH_ALEN]; | |
1931 | int status; | |
3a6b70c3 | 1932 | |
94a79942 LF |
1933 | ieee->softmac_stats.rx_auth_rq++; |
1934 | ||
e9fea2ec | 1935 | status = auth_rq_parse(ieee->dev, skb, dest); |
9d92ece8 | 1936 | if (status != -1) |
94a79942 | 1937 | rtllib_resp_to_auth(ieee, status, dest); |
94a79942 LF |
1938 | } |
1939 | ||
9d92ece8 LF |
1940 | static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee, |
1941 | struct sk_buff *skb) | |
94a79942 | 1942 | { |
94a79942 LF |
1943 | u8 dest[ETH_ALEN]; |
1944 | ||
06c11107 | 1945 | |
94a79942 | 1946 | ieee->softmac_stats.rx_ass_rq++; |
e9fea2ec | 1947 | if (assoc_rq_parse(ieee->dev, skb, dest) != -1) |
94a79942 | 1948 | rtllib_resp_to_assoc_rq(ieee, dest); |
94a79942 | 1949 | |
d69d2054 | 1950 | netdev_info(ieee->dev, "New client associated: %pM\n", dest); |
94a79942 LF |
1951 | } |
1952 | ||
94a79942 LF |
1953 | void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr) |
1954 | { | |
1955 | ||
1956 | struct sk_buff *buf = rtllib_null_func(ieee, pwr); | |
1957 | ||
1958 | if (buf) | |
1959 | softmac_ps_mgmt_xmit(buf, ieee); | |
94a79942 | 1960 | } |
3b28499c | 1961 | EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame); |
94a79942 LF |
1962 | |
1963 | void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee) | |
1964 | { | |
94a79942 LF |
1965 | struct sk_buff *buf = rtllib_pspoll_func(ieee); |
1966 | ||
1967 | if (buf) | |
1968 | softmac_ps_mgmt_xmit(buf, ieee); | |
94a79942 LF |
1969 | } |
1970 | ||
0dd56506 | 1971 | static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time) |
94a79942 LF |
1972 | { |
1973 | int timeout = ieee->ps_timeout; | |
1974 | u8 dtim; | |
9d92ece8 LF |
1975 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) |
1976 | (&(ieee->PowerSaveControl)); | |
94a79942 | 1977 | |
9d92ece8 LF |
1978 | if (ieee->LPSDelayCnt) { |
1979 | ieee->LPSDelayCnt--; | |
94a79942 LF |
1980 | return 0; |
1981 | } | |
1982 | ||
1983 | dtim = ieee->current_network.dtim_data; | |
1984 | if (!(dtim & RTLLIB_DTIM_VALID)) | |
1985 | return 0; | |
1986 | timeout = ieee->current_network.beacon_interval; | |
1987 | ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID; | |
9d92ece8 | 1988 | /* there's no need to nofity AP that I find you buffered |
14b40d92 MK |
1989 | * with broadcast packet |
1990 | */ | |
94a79942 LF |
1991 | if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps)) |
1992 | return 2; | |
1993 | ||
8b9733c1 VT |
1994 | if (!time_after(jiffies, |
1995 | ieee->dev->trans_start + msecs_to_jiffies(timeout))) | |
94a79942 | 1996 | return 0; |
8b9733c1 VT |
1997 | if (!time_after(jiffies, |
1998 | ieee->last_rx_ps_time + msecs_to_jiffies(timeout))) | |
94a79942 | 1999 | return 0; |
9d92ece8 LF |
2000 | if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) && |
2001 | (ieee->mgmt_queue_tail != ieee->mgmt_queue_head)) | |
94a79942 LF |
2002 | return 0; |
2003 | ||
9d92ece8 | 2004 | if (time) { |
4bb01423 | 2005 | if (ieee->bAwakePktSent) { |
94a79942 LF |
2006 | pPSC->LPSAwakeIntvl = 1; |
2007 | } else { | |
35e33b04 | 2008 | u8 MaxPeriod = 1; |
94a79942 LF |
2009 | |
2010 | if (pPSC->LPSAwakeIntvl == 0) | |
2011 | pPSC->LPSAwakeIntvl = 1; | |
2012 | if (pPSC->RegMaxLPSAwakeIntvl == 0) | |
2013 | MaxPeriod = 1; | |
2014 | else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF) | |
2015 | MaxPeriod = ieee->current_network.dtim_period; | |
2016 | else | |
2017 | MaxPeriod = pPSC->RegMaxLPSAwakeIntvl; | |
9d92ece8 LF |
2018 | pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >= |
2019 | MaxPeriod) ? MaxPeriod : | |
2020 | (pPSC->LPSAwakeIntvl + 1); | |
94a79942 LF |
2021 | } |
2022 | { | |
2023 | u8 LPSAwakeIntvl_tmp = 0; | |
2024 | u8 period = ieee->current_network.dtim_period; | |
2025 | u8 count = ieee->current_network.tim.tim_count; | |
3a6b70c3 | 2026 | |
9d92ece8 | 2027 | if (count == 0) { |
94a79942 | 2028 | if (pPSC->LPSAwakeIntvl > period) |
9d92ece8 LF |
2029 | LPSAwakeIntvl_tmp = period + |
2030 | (pPSC->LPSAwakeIntvl - | |
2031 | period) - | |
2032 | ((pPSC->LPSAwakeIntvl-period) % | |
2033 | period); | |
94a79942 LF |
2034 | else |
2035 | LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl; | |
2036 | ||
2037 | } else { | |
9d92ece8 LF |
2038 | if (pPSC->LPSAwakeIntvl > |
2039 | ieee->current_network.tim.tim_count) | |
2040 | LPSAwakeIntvl_tmp = count + | |
2041 | (pPSC->LPSAwakeIntvl - count) - | |
2042 | ((pPSC->LPSAwakeIntvl-count)%period); | |
94a79942 LF |
2043 | else |
2044 | LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl; | |
2045 | } | |
2046 | ||
0dd56506 | 2047 | *time = ieee->current_network.last_dtim_sta_time |
8b9733c1 | 2048 | + msecs_to_jiffies(ieee->current_network.beacon_interval * |
9d92ece8 | 2049 | LPSAwakeIntvl_tmp); |
94a79942 LF |
2050 | } |
2051 | } | |
2052 | ||
94a79942 LF |
2053 | return 1; |
2054 | ||
2055 | ||
2056 | } | |
2057 | ||
ec0dc6be | 2058 | static inline void rtllib_sta_ps(struct rtllib_device *ieee) |
94a79942 | 2059 | { |
0dd56506 | 2060 | u64 time; |
94a79942 | 2061 | short sleep; |
9d92ece8 | 2062 | unsigned long flags, flags2; |
94a79942 LF |
2063 | |
2064 | spin_lock_irqsave(&ieee->lock, flags); | |
2065 | ||
2066 | if ((ieee->ps == RTLLIB_PS_DISABLED || | |
9d92ece8 LF |
2067 | ieee->iw_mode != IW_MODE_INFRA || |
2068 | ieee->state != RTLLIB_LINKED)) { | |
0822339b MK |
2069 | RT_TRACE(COMP_DBG, |
2070 | "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n", | |
2071 | __func__, ieee->ps, ieee->iw_mode, ieee->state); | |
94a79942 | 2072 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
94a79942 LF |
2073 | rtllib_sta_wakeup(ieee, 1); |
2074 | ||
2075 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); | |
2076 | } | |
0dd56506 | 2077 | sleep = rtllib_sta_ps_sleep(ieee, &time); |
94a79942 LF |
2078 | /* 2 wake, 1 sleep, 0 do nothing */ |
2079 | if (sleep == 0) | |
94a79942 | 2080 | goto out; |
9d92ece8 LF |
2081 | if (sleep == 1) { |
2082 | if (ieee->sta_sleep == LPS_IS_SLEEP) { | |
0dd56506 | 2083 | ieee->enter_sleep_state(ieee->dev, time); |
9d92ece8 | 2084 | } else if (ieee->sta_sleep == LPS_IS_WAKE) { |
94a79942 LF |
2085 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
2086 | ||
9d92ece8 | 2087 | if (ieee->ps_is_queue_empty(ieee->dev)) { |
94a79942 LF |
2088 | ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND; |
2089 | ieee->ack_tx_to_ieee = 1; | |
9d92ece8 | 2090 | rtllib_sta_ps_send_null_frame(ieee, 1); |
0dd56506 | 2091 | ieee->ps_time = time; |
94a79942 LF |
2092 | } |
2093 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); | |
2094 | ||
2095 | } | |
2096 | ||
2097 | ieee->bAwakePktSent = false; | |
2098 | ||
9d92ece8 | 2099 | } else if (sleep == 2) { |
94a79942 LF |
2100 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
2101 | ||
9d92ece8 | 2102 | rtllib_sta_wakeup(ieee, 1); |
94a79942 LF |
2103 | |
2104 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); | |
2105 | } | |
2106 | ||
2107 | out: | |
2108 | spin_unlock_irqrestore(&ieee->lock, flags); | |
2109 | ||
2110 | } | |
2111 | ||
2112 | void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl) | |
2113 | { | |
9d92ece8 LF |
2114 | if (ieee->sta_sleep == LPS_IS_WAKE) { |
2115 | if (nl) { | |
2116 | if (ieee->pHTInfo->IOTAction & | |
2117 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) { | |
94a79942 LF |
2118 | ieee->ack_tx_to_ieee = 1; |
2119 | rtllib_sta_ps_send_null_frame(ieee, 0); | |
9d92ece8 | 2120 | } else { |
94a79942 LF |
2121 | ieee->ack_tx_to_ieee = 1; |
2122 | rtllib_sta_ps_send_pspoll_frame(ieee); | |
2123 | } | |
2124 | } | |
2125 | return; | |
2126 | ||
2127 | } | |
2128 | ||
2129 | if (ieee->sta_sleep == LPS_IS_SLEEP) | |
2130 | ieee->sta_wake_up(ieee->dev); | |
9d92ece8 LF |
2131 | if (nl) { |
2132 | if (ieee->pHTInfo->IOTAction & | |
2133 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) { | |
94a79942 | 2134 | ieee->ack_tx_to_ieee = 1; |
94a79942 | 2135 | rtllib_sta_ps_send_null_frame(ieee, 0); |
9d92ece8 | 2136 | } else { |
94a79942 LF |
2137 | ieee->ack_tx_to_ieee = 1; |
2138 | ieee->polling = true; | |
2139 | rtllib_sta_ps_send_pspoll_frame(ieee); | |
2140 | } | |
2141 | ||
2142 | } else { | |
2143 | ieee->sta_sleep = LPS_IS_WAKE; | |
2144 | ieee->polling = false; | |
2145 | } | |
2146 | } | |
2147 | ||
2148 | void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success) | |
2149 | { | |
9d92ece8 | 2150 | unsigned long flags, flags2; |
94a79942 LF |
2151 | |
2152 | spin_lock_irqsave(&ieee->lock, flags); | |
2153 | ||
9d92ece8 | 2154 | if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) { |
94a79942 | 2155 | /* Null frame with PS bit set */ |
9d92ece8 | 2156 | if (success) { |
94a79942 | 2157 | ieee->sta_sleep = LPS_IS_SLEEP; |
0dd56506 | 2158 | ieee->enter_sleep_state(ieee->dev, ieee->ps_time); |
94a79942 LF |
2159 | } |
2160 | /* if the card report not success we can't be sure the AP | |
2161 | * has not RXed so we can't assume the AP believe us awake | |
2162 | */ | |
2163 | } else {/* 21112005 - tx again null without PS bit if lost */ | |
2164 | ||
9d92ece8 | 2165 | if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) { |
94a79942 | 2166 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
9d92ece8 LF |
2167 | if (ieee->pHTInfo->IOTAction & |
2168 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) | |
94a79942 | 2169 | rtllib_sta_ps_send_null_frame(ieee, 0); |
94a79942 | 2170 | else |
94a79942 | 2171 | rtllib_sta_ps_send_pspoll_frame(ieee); |
94a79942 LF |
2172 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); |
2173 | } | |
2174 | } | |
2175 | spin_unlock_irqrestore(&ieee->lock, flags); | |
2176 | } | |
3b28499c | 2177 | EXPORT_SYMBOL(rtllib_ps_tx_ack); |
94a79942 | 2178 | |
35e33b04 MK |
2179 | static void rtllib_process_action(struct rtllib_device *ieee, |
2180 | struct sk_buff *skb) | |
94a79942 LF |
2181 | { |
2182 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; | |
9d92ece8 | 2183 | u8 *act = rtllib_get_payload((struct rtllib_hdr *)header); |
94a79942 LF |
2184 | u8 category = 0; |
2185 | ||
2186 | if (act == NULL) { | |
11e672c3 MK |
2187 | netdev_warn(ieee->dev, |
2188 | "Error getting payload of action frame\n"); | |
94a79942 LF |
2189 | return; |
2190 | } | |
2191 | ||
2192 | category = *act; | |
9d92ece8 | 2193 | act++; |
94a79942 | 2194 | switch (category) { |
9d92ece8 LF |
2195 | case ACT_CAT_BA: |
2196 | switch (*act) { | |
2197 | case ACT_ADDBAREQ: | |
2198 | rtllib_rx_ADDBAReq(ieee, skb); | |
2199 | break; | |
2200 | case ACT_ADDBARSP: | |
2201 | rtllib_rx_ADDBARsp(ieee, skb); | |
94a79942 | 2202 | break; |
9d92ece8 LF |
2203 | case ACT_DELBA: |
2204 | rtllib_rx_DELBA(ieee, skb); | |
94a79942 | 2205 | break; |
9d92ece8 LF |
2206 | } |
2207 | break; | |
2208 | default: | |
2209 | break; | |
94a79942 | 2210 | } |
94a79942 LF |
2211 | } |
2212 | ||
9d92ece8 LF |
2213 | inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, |
2214 | struct rtllib_rx_stats *rx_stats) | |
94a79942 LF |
2215 | { |
2216 | u16 errcode; | |
2217 | int aid; | |
9d92ece8 | 2218 | u8 *ies; |
94a79942 LF |
2219 | struct rtllib_assoc_response_frame *assoc_resp; |
2220 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; | |
fa70ae09 | 2221 | u16 frame_ctl = le16_to_cpu(header->frame_ctl); |
94a79942 | 2222 | |
e9fea2ec | 2223 | netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n", |
fa70ae09 | 2224 | WLAN_FC_GET_STYPE(frame_ctl)); |
94a79942 LF |
2225 | |
2226 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && | |
9d92ece8 LF |
2227 | ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED && |
2228 | (ieee->iw_mode == IW_MODE_INFRA)) { | |
2229 | errcode = assoc_parse(ieee, skb, &aid); | |
2230 | if (0 == errcode) { | |
2231 | struct rtllib_network *network = | |
2232 | kzalloc(sizeof(struct rtllib_network), | |
2233 | GFP_ATOMIC); | |
94a79942 LF |
2234 | |
2235 | if (!network) | |
2236 | return 1; | |
9d92ece8 | 2237 | ieee->state = RTLLIB_LINKED; |
94a79942 LF |
2238 | ieee->assoc_id = aid; |
2239 | ieee->softmac_stats.rx_ass_ok++; | |
2240 | /* station support qos */ | |
9d92ece8 LF |
2241 | /* Let the register setting default with Legacy station */ |
2242 | assoc_resp = (struct rtllib_assoc_response_frame *)skb->data; | |
94a79942 | 2243 | if (ieee->current_network.qos_data.supported == 1) { |
9d92ece8 LF |
2244 | if (rtllib_parse_info_param(ieee, assoc_resp->info_element, |
2245 | rx_stats->len - sizeof(*assoc_resp), | |
2246 | network, rx_stats)) { | |
94a79942 LF |
2247 | kfree(network); |
2248 | return 1; | |
94a79942 | 2249 | } |
92db2a27 MC |
2250 | memcpy(ieee->pHTInfo->PeerHTCapBuf, |
2251 | network->bssht.bdHTCapBuf, | |
2252 | network->bssht.bdHTCapLen); | |
2253 | memcpy(ieee->pHTInfo->PeerHTInfoBuf, | |
2254 | network->bssht.bdHTInfoBuf, | |
2255 | network->bssht.bdHTInfoLen); | |
94a79942 | 2256 | if (ieee->handle_assoc_response != NULL) |
9d92ece8 LF |
2257 | ieee->handle_assoc_response(ieee->dev, |
2258 | (struct rtllib_assoc_response_frame *)header, | |
2259 | network); | |
94a79942 | 2260 | } |
33750343 | 2261 | kfree(network); |
94a79942 | 2262 | |
9d92ece8 LF |
2263 | kfree(ieee->assocresp_ies); |
2264 | ieee->assocresp_ies = NULL; | |
94a79942 LF |
2265 | ies = &(assoc_resp->info_element[0].id); |
2266 | ieee->assocresp_ies_len = (skb->data + skb->len) - ies; | |
9d92ece8 LF |
2267 | ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len, |
2268 | GFP_ATOMIC); | |
94a79942 | 2269 | if (ieee->assocresp_ies) |
9d92ece8 LF |
2270 | memcpy(ieee->assocresp_ies, ies, |
2271 | ieee->assocresp_ies_len); | |
2272 | else { | |
d69d2054 MK |
2273 | netdev_info(ieee->dev, |
2274 | "%s()Warning: can't alloc memory for assocresp_ies\n", | |
2275 | __func__); | |
94a79942 LF |
2276 | ieee->assocresp_ies_len = 0; |
2277 | } | |
2278 | rtllib_associate_complete(ieee); | |
2279 | } else { | |
2280 | /* aid could not been allocated */ | |
2281 | ieee->softmac_stats.rx_ass_err++; | |
d69d2054 MK |
2282 | netdev_info(ieee->dev, |
2283 | "Association response status code 0x%x\n", | |
2284 | errcode); | |
9d92ece8 LF |
2285 | if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) |
2286 | queue_delayed_work_rsl(ieee->wq, | |
2287 | &ieee->associate_procedure_wq, 0); | |
2288 | else | |
94a79942 | 2289 | rtllib_associate_abort(ieee); |
94a79942 LF |
2290 | } |
2291 | } | |
94a79942 LF |
2292 | return 0; |
2293 | } | |
2294 | ||
e8f05b0b | 2295 | static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb) |
94a79942 LF |
2296 | { |
2297 | u16 errcode; | |
9d92ece8 LF |
2298 | u8 *challenge; |
2299 | int chlen = 0; | |
94a79942 LF |
2300 | bool bSupportNmode = true, bHalfSupportNmode = false; |
2301 | ||
e9fea2ec | 2302 | errcode = auth_parse(ieee->dev, skb, &challenge, &chlen); |
94a79942 | 2303 | |
f7567e20 | 2304 | if (errcode) { |
e8f05b0b | 2305 | ieee->softmac_stats.rx_auth_rs_err++; |
e8f05b0b | 2306 | netdev_info(ieee->dev, |
e725fb6f | 2307 | "Authentication respose status code 0x%x", errcode); |
e8f05b0b | 2308 | rtllib_associate_abort(ieee); |
f7567e20 MK |
2309 | return; |
2310 | } | |
2311 | ||
2312 | if (ieee->open_wep || !challenge) { | |
2313 | ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED; | |
2314 | ieee->softmac_stats.rx_auth_rs_ok++; | |
e725fb6f | 2315 | if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) { |
f7567e20 MK |
2316 | if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) { |
2317 | if (IsHTHalfNmodeAPs(ieee)) { | |
2318 | bSupportNmode = true; | |
2319 | bHalfSupportNmode = true; | |
2320 | } else { | |
2321 | bSupportNmode = false; | |
2322 | bHalfSupportNmode = false; | |
2323 | } | |
2324 | } | |
2325 | } | |
14b40d92 | 2326 | /* Dummy wirless mode setting to avoid encryption issue */ |
f7567e20 MK |
2327 | if (bSupportNmode) { |
2328 | ieee->SetWirelessMode(ieee->dev, | |
e725fb6f | 2329 | ieee->current_network.mode); |
f7567e20 MK |
2330 | } else { |
2331 | /*TODO*/ | |
e725fb6f | 2332 | ieee->SetWirelessMode(ieee->dev, IEEE_G); |
f7567e20 MK |
2333 | } |
2334 | ||
e725fb6f MK |
2335 | if ((ieee->current_network.mode == IEEE_N_24G) && |
2336 | bHalfSupportNmode) { | |
2337 | netdev_info(ieee->dev, "======>enter half N mode\n"); | |
2338 | ieee->bHalfWirelessN24GMode = true; | |
2339 | } else { | |
2340 | ieee->bHalfWirelessN24GMode = false; | |
2341 | } | |
f7567e20 MK |
2342 | rtllib_associate_step2(ieee); |
2343 | } else { | |
e725fb6f | 2344 | rtllib_auth_challenge(ieee, challenge, chlen); |
e8f05b0b MK |
2345 | } |
2346 | } | |
94a79942 | 2347 | |
e8f05b0b MK |
2348 | inline int rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb, |
2349 | struct rtllib_rx_stats *rx_stats) | |
2350 | { | |
2351 | ||
2352 | if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) { | |
2353 | if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING && | |
2354 | (ieee->iw_mode == IW_MODE_INFRA)) { | |
e9fea2ec MK |
2355 | netdev_dbg(ieee->dev, |
2356 | "Received authentication response"); | |
e8f05b0b | 2357 | rtllib_rx_auth_resp(ieee, skb); |
9d92ece8 | 2358 | } else if (ieee->iw_mode == IW_MODE_MASTER) { |
94a79942 LF |
2359 | rtllib_rx_auth_rq(ieee, skb); |
2360 | } | |
2361 | } | |
94a79942 LF |
2362 | return 0; |
2363 | } | |
2364 | ||
2365 | inline int rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb) | |
2366 | { | |
2367 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; | |
fa70ae09 | 2368 | u16 frame_ctl; |
94a79942 LF |
2369 | |
2370 | if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) | |
2371 | return 0; | |
2372 | ||
2373 | /* FIXME for now repeat all the association procedure | |
14b40d92 MK |
2374 | * both for disassociation and deauthentication |
2375 | */ | |
94a79942 LF |
2376 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && |
2377 | ieee->state == RTLLIB_LINKED && | |
2378 | (ieee->iw_mode == IW_MODE_INFRA)) { | |
fa70ae09 | 2379 | frame_ctl = le16_to_cpu(header->frame_ctl); |
d69d2054 MK |
2380 | netdev_info(ieee->dev, |
2381 | "==========>received disassoc/deauth(%x) frame, reason code:%x\n", | |
fa70ae09 | 2382 | WLAN_FC_GET_STYPE(frame_ctl), |
d69d2054 | 2383 | ((struct rtllib_disassoc *)skb->data)->reason); |
94a79942 LF |
2384 | ieee->state = RTLLIB_ASSOCIATING; |
2385 | ieee->softmac_stats.reassoc++; | |
2386 | ieee->is_roaming = true; | |
2387 | ieee->LinkDetectInfo.bBusyTraffic = false; | |
2388 | rtllib_disassociate(ieee); | |
2389 | RemovePeerTS(ieee, header->addr2); | |
2390 | if (ieee->LedControlHandler != NULL) | |
9d92ece8 LF |
2391 | ieee->LedControlHandler(ieee->dev, |
2392 | LED_CTL_START_TO_LINK); | |
94a79942 | 2393 | |
9d92ece8 LF |
2394 | if (!(ieee->rtllib_ap_sec_type(ieee) & |
2395 | (SEC_ALG_CCMP|SEC_ALG_TKIP))) | |
2396 | queue_delayed_work_rsl(ieee->wq, | |
2397 | &ieee->associate_procedure_wq, 5); | |
94a79942 | 2398 | } |
94a79942 LF |
2399 | return 0; |
2400 | } | |
2401 | ||
9d92ece8 LF |
2402 | inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee, |
2403 | struct sk_buff *skb, | |
2404 | struct rtllib_rx_stats *rx_stats, u16 type, | |
2405 | u16 stype) | |
94a79942 LF |
2406 | { |
2407 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; | |
fa70ae09 | 2408 | u16 frame_ctl; |
94a79942 LF |
2409 | |
2410 | if (!ieee->proto_started) | |
2411 | return 0; | |
2412 | ||
fa70ae09 GD |
2413 | frame_ctl = le16_to_cpu(header->frame_ctl); |
2414 | switch (WLAN_FC_GET_STYPE(frame_ctl)) { | |
9d92ece8 LF |
2415 | case RTLLIB_STYPE_ASSOC_RESP: |
2416 | case RTLLIB_STYPE_REASSOC_RESP: | |
2417 | if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1) | |
2418 | return 1; | |
2419 | break; | |
2420 | case RTLLIB_STYPE_ASSOC_REQ: | |
2421 | case RTLLIB_STYPE_REASSOC_REQ: | |
2422 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && | |
2423 | ieee->iw_mode == IW_MODE_MASTER) | |
2424 | rtllib_rx_assoc_rq(ieee, skb); | |
2425 | break; | |
2426 | case RTLLIB_STYPE_AUTH: | |
2427 | rtllib_rx_auth(ieee, skb, rx_stats); | |
2428 | break; | |
2429 | case RTLLIB_STYPE_DISASSOC: | |
2430 | case RTLLIB_STYPE_DEAUTH: | |
2431 | rtllib_rx_deauth(ieee, skb); | |
2432 | break; | |
2433 | case RTLLIB_STYPE_MANAGE_ACT: | |
2434 | rtllib_process_action(ieee, skb); | |
2435 | break; | |
2436 | default: | |
2437 | return -1; | |
94a79942 | 2438 | } |
94a79942 LF |
2439 | return 0; |
2440 | } | |
2441 | ||
db2c8da0 | 2442 | /* following are for a simpler TX queue management. |
94a79942 | 2443 | * Instead of using netif_[stop/wake]_queue the driver |
cd017123 JM |
2444 | * will use these two functions (plus a reset one), that |
2445 | * will internally use the kernel netif_* and takes | |
94a79942 LF |
2446 | * care of the ieee802.11 fragmentation. |
2447 | * So the driver receives a fragment per time and might | |
cd017123 JM |
2448 | * call the stop function when it wants to not |
2449 | * have enough room to TX an entire packet. | |
2450 | * This might be useful if each fragment needs it's own | |
94a79942 | 2451 | * descriptor, thus just keep a total free memory > than |
cd017123 JM |
2452 | * the max fragmentation threshold is not enough.. If the |
2453 | * ieee802.11 stack passed a TXB struct then you need | |
94a79942 LF |
2454 | * to keep N free descriptors where |
2455 | * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD | |
2456 | * In this way you need just one and the 802.11 stack | |
2457 | * will take care of buffering fragments and pass them to | |
2458 | * to the driver later, when it wakes the queue. | |
2459 | */ | |
2460 | void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee) | |
2461 | { | |
2462 | ||
2463 | unsigned int queue_index = txb->queue_index; | |
2464 | unsigned long flags; | |
2465 | int i; | |
3b83db43 | 2466 | struct cb_desc *tcb_desc = NULL; |
94a79942 LF |
2467 | unsigned long queue_len = 0; |
2468 | ||
9d92ece8 | 2469 | spin_lock_irqsave(&ieee->lock, flags); |
94a79942 LF |
2470 | |
2471 | /* called with 2nd parm 0, no tx mgmt lock required */ | |
9d92ece8 | 2472 | rtllib_sta_wakeup(ieee, 0); |
94a79942 LF |
2473 | |
2474 | /* update the tx status */ | |
9d92ece8 LF |
2475 | tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + |
2476 | MAX_DEV_ADDR_SIZE); | |
2477 | if (tcb_desc->bMulticast) | |
94a79942 | 2478 | ieee->stats.multicast++; |
4f6807e8 | 2479 | |
9d92ece8 | 2480 | /* if xmit available, just xmit it immediately, else just insert it to |
14b40d92 MK |
2481 | * the wait queue |
2482 | */ | |
94a79942 | 2483 | for (i = 0; i < txb->nr_frags; i++) { |
94a79942 | 2484 | queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]); |
e2ac0431 | 2485 | if ((queue_len != 0) || |
9d92ece8 LF |
2486 | (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) || |
2487 | (ieee->queue_stop)) { | |
14b40d92 MK |
2488 | /* insert the skb packet to the wait queue |
2489 | * as for the completion function, it does not need | |
94a79942 | 2490 | * to check it any more. |
14b40d92 | 2491 | */ |
94a79942 | 2492 | if (queue_len < 200) |
9d92ece8 LF |
2493 | skb_queue_tail(&ieee->skb_waitQ[queue_index], |
2494 | txb->fragments[i]); | |
2495 | else | |
94a79942 | 2496 | kfree_skb(txb->fragments[i]); |
9d92ece8 | 2497 | } else { |
94a79942 LF |
2498 | ieee->softmac_data_hard_start_xmit( |
2499 | txb->fragments[i], | |
9d92ece8 | 2500 | ieee->dev, ieee->rate); |
94a79942 LF |
2501 | } |
2502 | } | |
4f6807e8 | 2503 | |
94a79942 LF |
2504 | rtllib_txb_free(txb); |
2505 | ||
9d92ece8 | 2506 | spin_unlock_irqrestore(&ieee->lock, flags); |
94a79942 LF |
2507 | |
2508 | } | |
2509 | ||
94a79942 LF |
2510 | void rtllib_reset_queue(struct rtllib_device *ieee) |
2511 | { | |
2512 | unsigned long flags; | |
2513 | ||
9d92ece8 | 2514 | spin_lock_irqsave(&ieee->lock, flags); |
94a79942 | 2515 | init_mgmt_queue(ieee); |
9d92ece8 | 2516 | if (ieee->tx_pending.txb) { |
94a79942 LF |
2517 | rtllib_txb_free(ieee->tx_pending.txb); |
2518 | ieee->tx_pending.txb = NULL; | |
2519 | } | |
2520 | ieee->queue_stop = 0; | |
9d92ece8 | 2521 | spin_unlock_irqrestore(&ieee->lock, flags); |
94a79942 LF |
2522 | |
2523 | } | |
3b28499c | 2524 | EXPORT_SYMBOL(rtllib_reset_queue); |
94a79942 | 2525 | |
94a79942 LF |
2526 | void rtllib_stop_all_queues(struct rtllib_device *ieee) |
2527 | { | |
94a79942 | 2528 | unsigned int i; |
3a6b70c3 | 2529 | |
9d92ece8 LF |
2530 | for (i = 0; i < ieee->dev->num_tx_queues; i++) |
2531 | netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies; | |
94a79942 | 2532 | |
94a79942 | 2533 | netif_tx_stop_all_queues(ieee->dev); |
94a79942 LF |
2534 | } |
2535 | ||
2536 | void rtllib_wake_all_queues(struct rtllib_device *ieee) | |
2537 | { | |
94a79942 | 2538 | netif_tx_wake_all_queues(ieee->dev); |
94a79942 LF |
2539 | } |
2540 | ||
2541 | inline void rtllib_randomize_cell(struct rtllib_device *ieee) | |
2542 | { | |
2543 | ||
71cd7913 | 2544 | random_ether_addr(ieee->current_network.bssid); |
94a79942 LF |
2545 | } |
2546 | ||
2547 | /* called in user context only */ | |
2548 | void rtllib_start_master_bss(struct rtllib_device *ieee) | |
2549 | { | |
2550 | ieee->assoc_id = 1; | |
2551 | ||
9d92ece8 | 2552 | if (ieee->current_network.ssid_len == 0) { |
94a79942 LF |
2553 | strncpy(ieee->current_network.ssid, |
2554 | RTLLIB_DEFAULT_TX_ESSID, | |
2555 | IW_ESSID_MAX_SIZE); | |
2556 | ||
9d92ece8 LF |
2557 | ieee->current_network.ssid_len = |
2558 | strlen(RTLLIB_DEFAULT_TX_ESSID); | |
94a79942 LF |
2559 | ieee->ssid_set = 1; |
2560 | } | |
2561 | ||
b57ceb19 | 2562 | ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr); |
94a79942 LF |
2563 | |
2564 | ieee->set_chan(ieee->dev, ieee->current_network.channel); | |
2565 | ieee->state = RTLLIB_LINKED; | |
2566 | ieee->link_change(ieee->dev); | |
2567 | notify_wx_assoc_event(ieee); | |
2568 | ||
2569 | if (ieee->data_hard_resume) | |
2570 | ieee->data_hard_resume(ieee->dev); | |
2571 | ||
2572 | netif_carrier_on(ieee->dev); | |
2573 | } | |
2574 | ||
ec0dc6be | 2575 | static void rtllib_start_monitor_mode(struct rtllib_device *ieee) |
94a79942 LF |
2576 | { |
2577 | /* reset hardware status */ | |
9d92ece8 | 2578 | if (ieee->raw_tx) { |
94a79942 LF |
2579 | if (ieee->data_hard_resume) |
2580 | ieee->data_hard_resume(ieee->dev); | |
2581 | ||
2582 | netif_carrier_on(ieee->dev); | |
2583 | } | |
2584 | } | |
2585 | ||
ec0dc6be | 2586 | static void rtllib_start_ibss_wq(void *data) |
94a79942 | 2587 | { |
9d92ece8 LF |
2588 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
2589 | struct rtllib_device, start_ibss_wq); | |
94a79942 LF |
2590 | /* iwconfig mode ad-hoc will schedule this and return |
2591 | * on the other hand this will block further iwconfig SET | |
2592 | * operations because of the wx_sem hold. | |
2593 | * Anyway some most set operations set a flag to speed-up | |
2594 | * (abort) this wq (when syncro scanning) before sleeping | |
2595 | * on the semaphore | |
2596 | */ | |
9d92ece8 | 2597 | if (!ieee->proto_started) { |
d69d2054 | 2598 | netdev_info(ieee->dev, "==========oh driver down return\n"); |
94a79942 LF |
2599 | return; |
2600 | } | |
2601 | down(&ieee->wx_sem); | |
2602 | ||
9d92ece8 LF |
2603 | if (ieee->current_network.ssid_len == 0) { |
2604 | strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID); | |
94a79942 LF |
2605 | ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID); |
2606 | ieee->ssid_set = 1; | |
2607 | } | |
2608 | ||
2609 | ieee->state = RTLLIB_NOLINK; | |
94a79942 | 2610 | ieee->mode = IEEE_G; |
94a79942 LF |
2611 | /* check if we have this cell in our network list */ |
2612 | rtllib_softmac_check_all_nets(ieee); | |
2613 | ||
2614 | ||
cd017123 | 2615 | /* if not then the state is not linked. Maybe the user switched to |
94a79942 LF |
2616 | * ad-hoc mode just after being in monitor mode, or just after |
2617 | * being very few time in managed mode (so the card have had no | |
2618 | * time to scan all the chans..) or we have just run up the iface | |
2619 | * after setting ad-hoc mode. So we have to give another try.. | |
2620 | * Here, in ibss mode, should be safe to do this without extra care | |
cd017123 | 2621 | * (in bss mode we had to make sure no-one tried to associate when |
94a79942 | 2622 | * we had just checked the ieee->state and we was going to start the |
cd017123 | 2623 | * scan) because in ibss mode the rtllib_new_net function, when |
94a79942 LF |
2624 | * finds a good net, just set the ieee->state to RTLLIB_LINKED, |
2625 | * so, at worst, we waste a bit of time to initiate an unneeded syncro | |
2626 | * scan, that will stop at the first round because it sees the state | |
2627 | * associated. | |
2628 | */ | |
2629 | if (ieee->state == RTLLIB_NOLINK) | |
2630 | rtllib_start_scan_syncro(ieee, 0); | |
2631 | ||
2632 | /* the network definitively is not here.. create a new cell */ | |
9d92ece8 | 2633 | if (ieee->state == RTLLIB_NOLINK) { |
d69d2054 | 2634 | netdev_info(ieee->dev, "creating new IBSS cell\n"); |
94a79942 LF |
2635 | ieee->current_network.channel = ieee->IbssStartChnl; |
2636 | if (!ieee->wap_set) | |
2637 | rtllib_randomize_cell(ieee); | |
2638 | ||
9d92ece8 | 2639 | if (ieee->modulation & RTLLIB_CCK_MODULATION) { |
94a79942 LF |
2640 | |
2641 | ieee->current_network.rates_len = 4; | |
2642 | ||
9d92ece8 LF |
2643 | ieee->current_network.rates[0] = |
2644 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB; | |
2645 | ieee->current_network.rates[1] = | |
2646 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB; | |
2647 | ieee->current_network.rates[2] = | |
2648 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB; | |
2649 | ieee->current_network.rates[3] = | |
2650 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB; | |
94a79942 | 2651 | |
9d92ece8 | 2652 | } else |
94a79942 LF |
2653 | ieee->current_network.rates_len = 0; |
2654 | ||
9d92ece8 | 2655 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) { |
94a79942 LF |
2656 | ieee->current_network.rates_ex_len = 8; |
2657 | ||
9d92ece8 LF |
2658 | ieee->current_network.rates_ex[0] = |
2659 | RTLLIB_OFDM_RATE_6MB; | |
2660 | ieee->current_network.rates_ex[1] = | |
2661 | RTLLIB_OFDM_RATE_9MB; | |
2662 | ieee->current_network.rates_ex[2] = | |
2663 | RTLLIB_OFDM_RATE_12MB; | |
2664 | ieee->current_network.rates_ex[3] = | |
2665 | RTLLIB_OFDM_RATE_18MB; | |
2666 | ieee->current_network.rates_ex[4] = | |
2667 | RTLLIB_OFDM_RATE_24MB; | |
2668 | ieee->current_network.rates_ex[5] = | |
2669 | RTLLIB_OFDM_RATE_36MB; | |
2670 | ieee->current_network.rates_ex[6] = | |
2671 | RTLLIB_OFDM_RATE_48MB; | |
2672 | ieee->current_network.rates_ex[7] = | |
2673 | RTLLIB_OFDM_RATE_54MB; | |
94a79942 LF |
2674 | |
2675 | ieee->rate = 108; | |
9d92ece8 | 2676 | } else { |
94a79942 LF |
2677 | ieee->current_network.rates_ex_len = 0; |
2678 | ieee->rate = 22; | |
2679 | } | |
2680 | ||
94a79942 LF |
2681 | ieee->current_network.qos_data.supported = 0; |
2682 | ieee->SetWirelessMode(ieee->dev, IEEE_G); | |
94a79942 LF |
2683 | ieee->current_network.mode = ieee->mode; |
2684 | ieee->current_network.atim_window = 0; | |
2685 | ieee->current_network.capability = WLAN_CAPABILITY_IBSS; | |
2686 | } | |
2687 | ||
d69d2054 | 2688 | netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode); |
94a79942 LF |
2689 | if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G)) |
2690 | HTUseDefaultSetting(ieee); | |
2691 | else | |
2692 | ieee->pHTInfo->bCurrentHTSupport = false; | |
2693 | ||
9d92ece8 LF |
2694 | ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS, |
2695 | (u8 *)(&ieee->state)); | |
94a79942 LF |
2696 | |
2697 | ieee->state = RTLLIB_LINKED; | |
2698 | ieee->link_change(ieee->dev); | |
2699 | ||
2700 | HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); | |
2701 | if (ieee->LedControlHandler != NULL) | |
9d92ece8 | 2702 | ieee->LedControlHandler(ieee->dev, LED_CTL_LINK); |
94a79942 LF |
2703 | |
2704 | rtllib_start_send_beacons(ieee); | |
2705 | ||
2706 | notify_wx_assoc_event(ieee); | |
2707 | ||
2708 | if (ieee->data_hard_resume) | |
2709 | ieee->data_hard_resume(ieee->dev); | |
2710 | ||
2711 | netif_carrier_on(ieee->dev); | |
2712 | ||
2713 | up(&ieee->wx_sem); | |
2714 | } | |
2715 | ||
2716 | inline void rtllib_start_ibss(struct rtllib_device *ieee) | |
2717 | { | |
8b9733c1 VT |
2718 | queue_delayed_work_rsl(ieee->wq, &ieee->start_ibss_wq, |
2719 | msecs_to_jiffies(150)); | |
94a79942 LF |
2720 | } |
2721 | ||
2722 | /* this is called only in user context, with wx_sem held */ | |
2723 | void rtllib_start_bss(struct rtllib_device *ieee) | |
2724 | { | |
2725 | unsigned long flags; | |
3a6b70c3 | 2726 | |
9d92ece8 LF |
2727 | if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) { |
2728 | if (!ieee->bGlobalDomain) | |
94a79942 | 2729 | return; |
94a79942 | 2730 | } |
94a79942 LF |
2731 | /* check if we have already found the net we |
2732 | * are interested in (if any). | |
2733 | * if not (we are disassociated and we are not | |
2734 | * in associating / authenticating phase) start the background scanning. | |
2735 | */ | |
2736 | rtllib_softmac_check_all_nets(ieee); | |
2737 | ||
2738 | /* ensure no-one start an associating process (thus setting | |
2739 | * the ieee->state to rtllib_ASSOCIATING) while we | |
cd017123 | 2740 | * have just checked it and we are going to enable scan. |
94a79942 LF |
2741 | * The rtllib_new_net function is always called with |
2742 | * lock held (from both rtllib_softmac_check_all_nets and | |
2743 | * the rx path), so we cannot be in the middle of such function | |
2744 | */ | |
2745 | spin_lock_irqsave(&ieee->lock, flags); | |
2746 | ||
9d92ece8 | 2747 | if (ieee->state == RTLLIB_NOLINK) |
94a79942 | 2748 | rtllib_start_scan(ieee); |
94a79942 LF |
2749 | spin_unlock_irqrestore(&ieee->lock, flags); |
2750 | } | |
2751 | ||
ec0dc6be | 2752 | static void rtllib_link_change_wq(void *data) |
94a79942 | 2753 | { |
9d92ece8 LF |
2754 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
2755 | struct rtllib_device, link_change_wq); | |
94a79942 LF |
2756 | ieee->link_change(ieee->dev); |
2757 | } | |
2758 | /* called only in userspace context */ | |
2759 | void rtllib_disassociate(struct rtllib_device *ieee) | |
2760 | { | |
2761 | netif_carrier_off(ieee->dev); | |
2762 | if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) | |
2763 | rtllib_reset_queue(ieee); | |
2764 | ||
2765 | if (ieee->data_hard_stop) | |
2766 | ieee->data_hard_stop(ieee->dev); | |
94a79942 LF |
2767 | if (IS_DOT11D_ENABLE(ieee)) |
2768 | Dot11d_Reset(ieee); | |
94a79942 LF |
2769 | ieee->state = RTLLIB_NOLINK; |
2770 | ieee->is_set_key = false; | |
2771 | ieee->wap_set = 0; | |
2772 | ||
2773 | queue_delayed_work_rsl(ieee->wq, &ieee->link_change_wq, 0); | |
2774 | ||
94a79942 | 2775 | notify_wx_assoc_event(ieee); |
94a79942 LF |
2776 | } |
2777 | ||
ec0dc6be | 2778 | static void rtllib_associate_retry_wq(void *data) |
94a79942 | 2779 | { |
9d92ece8 LF |
2780 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
2781 | struct rtllib_device, associate_retry_wq); | |
94a79942 LF |
2782 | unsigned long flags; |
2783 | ||
2784 | down(&ieee->wx_sem); | |
2785 | if (!ieee->proto_started) | |
2786 | goto exit; | |
2787 | ||
2788 | if (ieee->state != RTLLIB_ASSOCIATING_RETRY) | |
2789 | goto exit; | |
2790 | ||
2791 | /* until we do not set the state to RTLLIB_NOLINK | |
14b40d92 MK |
2792 | * there are no possibility to have someone else trying |
2793 | * to start an association procedure (we get here with | |
2794 | * ieee->state = RTLLIB_ASSOCIATING). | |
2795 | * When we set the state to RTLLIB_NOLINK it is possible | |
2796 | * that the RX path run an attempt to associate, but | |
2797 | * both rtllib_softmac_check_all_nets and the | |
2798 | * RX path works with ieee->lock held so there are no | |
2799 | * problems. If we are still disassociated then start a scan. | |
2800 | * the lock here is necessary to ensure no one try to start | |
2801 | * an association procedure when we have just checked the | |
2802 | * state and we are going to start the scan. | |
2803 | */ | |
94a79942 LF |
2804 | ieee->beinretry = true; |
2805 | ieee->state = RTLLIB_NOLINK; | |
2806 | ||
2807 | rtllib_softmac_check_all_nets(ieee); | |
2808 | ||
2809 | spin_lock_irqsave(&ieee->lock, flags); | |
2810 | ||
2811 | if (ieee->state == RTLLIB_NOLINK) | |
94a79942 | 2812 | rtllib_start_scan(ieee); |
94a79942 LF |
2813 | spin_unlock_irqrestore(&ieee->lock, flags); |
2814 | ||
2815 | ieee->beinretry = false; | |
2816 | exit: | |
2817 | up(&ieee->wx_sem); | |
2818 | } | |
2819 | ||
2820 | struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee) | |
2821 | { | |
06c11107 | 2822 | const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
94a79942 LF |
2823 | |
2824 | struct sk_buff *skb; | |
2825 | struct rtllib_probe_response *b; | |
3a6b70c3 | 2826 | |
94a79942 LF |
2827 | skb = rtllib_probe_resp(ieee, broadcast_addr); |
2828 | ||
2829 | if (!skb) | |
2830 | return NULL; | |
2831 | ||
2832 | b = (struct rtllib_probe_response *) skb->data; | |
2833 | b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON); | |
2834 | ||
2835 | return skb; | |
2836 | ||
2837 | } | |
2838 | ||
2839 | struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee) | |
2840 | { | |
2841 | struct sk_buff *skb; | |
2842 | struct rtllib_probe_response *b; | |
2843 | ||
2844 | skb = rtllib_get_beacon_(ieee); | |
2845 | if (!skb) | |
2846 | return NULL; | |
2847 | ||
2848 | b = (struct rtllib_probe_response *) skb->data; | |
2849 | b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); | |
2850 | ||
2851 | if (ieee->seq_ctrl[0] == 0xFFF) | |
2852 | ieee->seq_ctrl[0] = 0; | |
2853 | else | |
2854 | ieee->seq_ctrl[0]++; | |
2855 | ||
2856 | return skb; | |
2857 | } | |
3b28499c | 2858 | EXPORT_SYMBOL(rtllib_get_beacon); |
94a79942 | 2859 | |
9d92ece8 LF |
2860 | void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag, |
2861 | u8 shutdown) | |
94a79942 LF |
2862 | { |
2863 | rtllib_stop_scan_syncro(ieee); | |
2864 | down(&ieee->wx_sem); | |
9d92ece8 | 2865 | rtllib_stop_protocol(ieee, shutdown); |
94a79942 LF |
2866 | up(&ieee->wx_sem); |
2867 | } | |
3b28499c | 2868 | EXPORT_SYMBOL(rtllib_softmac_stop_protocol); |
94a79942 LF |
2869 | |
2870 | ||
2871 | void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown) | |
2872 | { | |
2873 | if (!ieee->proto_started) | |
2874 | return; | |
2875 | ||
9d92ece8 LF |
2876 | if (shutdown) { |
2877 | ieee->proto_started = 0; | |
94a79942 LF |
2878 | ieee->proto_stoppping = 1; |
2879 | if (ieee->rtllib_ips_leave != NULL) | |
2880 | ieee->rtllib_ips_leave(ieee->dev); | |
2881 | } | |
2882 | ||
2883 | rtllib_stop_send_beacons(ieee); | |
2884 | del_timer_sync(&ieee->associate_timer); | |
2885 | cancel_delayed_work(&ieee->associate_retry_wq); | |
2886 | cancel_delayed_work(&ieee->start_ibss_wq); | |
2887 | cancel_delayed_work(&ieee->link_change_wq); | |
2888 | rtllib_stop_scan(ieee); | |
2889 | ||
2890 | if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED) | |
2891 | ieee->state = RTLLIB_NOLINK; | |
2892 | ||
9d92ece8 | 2893 | if (ieee->state == RTLLIB_LINKED) { |
94a79942 | 2894 | if (ieee->iw_mode == IW_MODE_INFRA) |
acd442db | 2895 | SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING); |
94a79942 LF |
2896 | rtllib_disassociate(ieee); |
2897 | } | |
2898 | ||
9d92ece8 | 2899 | if (shutdown) { |
94a79942 LF |
2900 | RemoveAllTS(ieee); |
2901 | ieee->proto_stoppping = 0; | |
2902 | } | |
9d92ece8 LF |
2903 | kfree(ieee->assocreq_ies); |
2904 | ieee->assocreq_ies = NULL; | |
2905 | ieee->assocreq_ies_len = 0; | |
2906 | kfree(ieee->assocresp_ies); | |
2907 | ieee->assocresp_ies = NULL; | |
2908 | ieee->assocresp_ies_len = 0; | |
94a79942 LF |
2909 | } |
2910 | ||
2911 | void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag) | |
2912 | { | |
2913 | down(&ieee->wx_sem); | |
2914 | rtllib_start_protocol(ieee); | |
2915 | up(&ieee->wx_sem); | |
2916 | } | |
3b28499c | 2917 | EXPORT_SYMBOL(rtllib_softmac_start_protocol); |
94a79942 LF |
2918 | |
2919 | void rtllib_start_protocol(struct rtllib_device *ieee) | |
2920 | { | |
2921 | short ch = 0; | |
2922 | int i = 0; | |
2923 | ||
2924 | rtllib_update_active_chan_map(ieee); | |
2925 | ||
2926 | if (ieee->proto_started) | |
2927 | return; | |
2928 | ||
2929 | ieee->proto_started = 1; | |
2930 | ||
2931 | if (ieee->current_network.channel == 0) { | |
2932 | do { | |
2933 | ch++; | |
2934 | if (ch > MAX_CHANNEL_NUMBER) | |
2935 | return; /* no channel found */ | |
9d92ece8 | 2936 | } while (!ieee->active_channel_map[ch]); |
94a79942 LF |
2937 | ieee->current_network.channel = ch; |
2938 | } | |
2939 | ||
2940 | if (ieee->current_network.beacon_interval == 0) | |
2941 | ieee->current_network.beacon_interval = 100; | |
2942 | ||
2943 | for (i = 0; i < 17; i++) { | |
2944 | ieee->last_rxseq_num[i] = -1; | |
2945 | ieee->last_rxfrag_num[i] = -1; | |
2946 | ieee->last_packet_time[i] = 0; | |
2947 | } | |
2948 | ||
2949 | if (ieee->UpdateBeaconInterruptHandler) | |
2950 | ieee->UpdateBeaconInterruptHandler(ieee->dev, false); | |
2951 | ||
2952 | ieee->wmm_acm = 0; | |
2953 | /* if the user set the MAC of the ad-hoc cell and then | |
2954 | * switch to managed mode, shall we make sure that association | |
2955 | * attempts does not fail just because the user provide the essid | |
2956 | * and the nic is still checking for the AP MAC ?? | |
2957 | */ | |
2958 | if (ieee->iw_mode == IW_MODE_INFRA) { | |
2959 | rtllib_start_bss(ieee); | |
2960 | } else if (ieee->iw_mode == IW_MODE_ADHOC) { | |
2961 | if (ieee->UpdateBeaconInterruptHandler) | |
2962 | ieee->UpdateBeaconInterruptHandler(ieee->dev, true); | |
2963 | ||
2964 | rtllib_start_ibss(ieee); | |
2965 | ||
2966 | } else if (ieee->iw_mode == IW_MODE_MASTER) { | |
2967 | rtllib_start_master_bss(ieee); | |
2968 | } else if (ieee->iw_mode == IW_MODE_MONITOR) { | |
2969 | rtllib_start_monitor_mode(ieee); | |
2970 | } | |
2971 | } | |
2972 | ||
2973 | void rtllib_softmac_init(struct rtllib_device *ieee) | |
2974 | { | |
2975 | int i; | |
3a6b70c3 | 2976 | |
94a79942 LF |
2977 | memset(&ieee->current_network, 0, sizeof(struct rtllib_network)); |
2978 | ||
2979 | ieee->state = RTLLIB_NOLINK; | |
9d92ece8 LF |
2980 | for (i = 0; i < 5; i++) |
2981 | ieee->seq_ctrl[i] = 0; | |
929fa2a4 | 2982 | ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC); |
94a79942 | 2983 | if (!ieee->pDot11dInfo) |
11e672c3 | 2984 | netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n"); |
94a79942 LF |
2985 | ieee->LinkDetectInfo.SlotIndex = 0; |
2986 | ieee->LinkDetectInfo.SlotNum = 2; | |
9d92ece8 LF |
2987 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0; |
2988 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 0; | |
2989 | ieee->LinkDetectInfo.NumTxOkInPeriod = 0; | |
2990 | ieee->LinkDetectInfo.NumRxOkInPeriod = 0; | |
2991 | ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; | |
94a79942 LF |
2992 | ieee->bIsAggregateFrame = false; |
2993 | ieee->assoc_id = 0; | |
2994 | ieee->queue_stop = 0; | |
2995 | ieee->scanning_continue = 0; | |
2996 | ieee->softmac_features = 0; | |
2997 | ieee->wap_set = 0; | |
2998 | ieee->ssid_set = 0; | |
2999 | ieee->proto_started = 0; | |
3000 | ieee->proto_stoppping = 0; | |
3001 | ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE; | |
3002 | ieee->rate = 22; | |
3003 | ieee->ps = RTLLIB_PS_DISABLED; | |
3004 | ieee->sta_sleep = LPS_IS_WAKE; | |
3005 | ||
9d92ece8 LF |
3006 | ieee->Regdot11HTOperationalRateSet[0] = 0xff; |
3007 | ieee->Regdot11HTOperationalRateSet[1] = 0xff; | |
3008 | ieee->Regdot11HTOperationalRateSet[4] = 0x01; | |
94a79942 | 3009 | |
9d92ece8 LF |
3010 | ieee->Regdot11TxHTOperationalRateSet[0] = 0xff; |
3011 | ieee->Regdot11TxHTOperationalRateSet[1] = 0xff; | |
3012 | ieee->Regdot11TxHTOperationalRateSet[4] = 0x01; | |
94a79942 LF |
3013 | |
3014 | ieee->FirstIe_InScan = false; | |
3015 | ieee->actscanning = false; | |
3016 | ieee->beinretry = false; | |
3017 | ieee->is_set_key = false; | |
3018 | init_mgmt_queue(ieee); | |
3019 | ||
94a79942 | 3020 | ieee->aggregation = true; |
94a79942 LF |
3021 | ieee->tx_pending.txb = NULL; |
3022 | ||
3023 | _setup_timer(&ieee->associate_timer, | |
3024 | rtllib_associate_abort_cb, | |
3025 | (unsigned long) ieee); | |
3026 | ||
3027 | _setup_timer(&ieee->beacon_timer, | |
3028 | rtllib_send_beacon_cb, | |
3029 | (unsigned long) ieee); | |
3030 | ||
94a79942 | 3031 | |
94a79942 | 3032 | ieee->wq = create_workqueue(DRV_NAME); |
94a79942 | 3033 | |
9d92ece8 LF |
3034 | INIT_DELAYED_WORK_RSL(&ieee->link_change_wq, |
3035 | (void *)rtllib_link_change_wq, ieee); | |
3036 | INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq, | |
3037 | (void *)rtllib_start_ibss_wq, ieee); | |
3038 | INIT_WORK_RSL(&ieee->associate_complete_wq, | |
3039 | (void *)rtllib_associate_complete_wq, ieee); | |
3040 | INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq, | |
3041 | (void *)rtllib_associate_procedure_wq, ieee); | |
3042 | INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq, | |
3043 | (void *)rtllib_softmac_scan_wq, ieee); | |
9d92ece8 LF |
3044 | INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq, |
3045 | (void *)rtllib_associate_retry_wq, ieee); | |
3046 | INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq, | |
3047 | ieee); | |
94a79942 LF |
3048 | |
3049 | sema_init(&ieee->wx_sem, 1); | |
3050 | sema_init(&ieee->scan_sem, 1); | |
9d92ece8 | 3051 | sema_init(&ieee->ips_sem, 1); |
94a79942 LF |
3052 | |
3053 | spin_lock_init(&ieee->mgmt_tx_lock); | |
3054 | spin_lock_init(&ieee->beacon_lock); | |
3055 | ||
3056 | tasklet_init(&ieee->ps_task, | |
3057 | (void(*)(unsigned long)) rtllib_sta_ps, | |
3058 | (unsigned long)ieee); | |
3059 | ||
3060 | } | |
3061 | ||
3062 | void rtllib_softmac_free(struct rtllib_device *ieee) | |
3063 | { | |
3064 | down(&ieee->wx_sem); | |
d7613e53 LF |
3065 | kfree(ieee->pDot11dInfo); |
3066 | ieee->pDot11dInfo = NULL; | |
94a79942 LF |
3067 | del_timer_sync(&ieee->associate_timer); |
3068 | ||
94a79942 LF |
3069 | cancel_delayed_work(&ieee->associate_retry_wq); |
3070 | destroy_workqueue(ieee->wq); | |
94a79942 | 3071 | up(&ieee->wx_sem); |
876e20d3 | 3072 | tasklet_kill(&ieee->ps_task); |
94a79942 LF |
3073 | } |
3074 | ||
3075 | /******************************************************** | |
9d92ece8 LF |
3076 | * Start of WPA code. * |
3077 | * this is stolen from the ipw2200 driver * | |
94a79942 LF |
3078 | ********************************************************/ |
3079 | ||
3080 | ||
3081 | static int rtllib_wpa_enable(struct rtllib_device *ieee, int value) | |
3082 | { | |
3083 | /* This is called when wpa_supplicant loads and closes the driver | |
14b40d92 MK |
3084 | * interface. |
3085 | */ | |
d69d2054 | 3086 | netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling"); |
94a79942 LF |
3087 | ieee->wpa_enabled = value; |
3088 | memset(ieee->ap_mac_addr, 0, 6); | |
3089 | return 0; | |
3090 | } | |
3091 | ||
3092 | ||
ec0dc6be LF |
3093 | static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie, |
3094 | int wpa_ie_len) | |
94a79942 LF |
3095 | { |
3096 | /* make sure WPA is enabled */ | |
3097 | rtllib_wpa_enable(ieee, 1); | |
3098 | ||
3099 | rtllib_disassociate(ieee); | |
3100 | } | |
3101 | ||
3102 | ||
3103 | static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason) | |
3104 | { | |
3105 | ||
3106 | int ret = 0; | |
3107 | ||
3108 | switch (command) { | |
3109 | case IEEE_MLME_STA_DEAUTH: | |
3110 | break; | |
3111 | ||
3112 | case IEEE_MLME_STA_DISASSOC: | |
3113 | rtllib_disassociate(ieee); | |
3114 | break; | |
3115 | ||
3116 | default: | |
d69d2054 | 3117 | netdev_info(ieee->dev, "Unknown MLME request: %d\n", command); |
94a79942 LF |
3118 | ret = -EOPNOTSUPP; |
3119 | } | |
3120 | ||
3121 | return ret; | |
3122 | } | |
3123 | ||
3124 | ||
3125 | static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee, | |
3126 | struct ieee_param *param, int plen) | |
3127 | { | |
3128 | u8 *buf; | |
3129 | ||
3130 | if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || | |
3131 | (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) | |
3132 | return -EINVAL; | |
3133 | ||
3134 | if (param->u.wpa_ie.len) { | |
d9317533 TM |
3135 | buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, |
3136 | GFP_KERNEL); | |
94a79942 LF |
3137 | if (buf == NULL) |
3138 | return -ENOMEM; | |
3139 | ||
94a79942 LF |
3140 | kfree(ieee->wpa_ie); |
3141 | ieee->wpa_ie = buf; | |
3142 | ieee->wpa_ie_len = param->u.wpa_ie.len; | |
3143 | } else { | |
3144 | kfree(ieee->wpa_ie); | |
3145 | ieee->wpa_ie = NULL; | |
3146 | ieee->wpa_ie_len = 0; | |
3147 | } | |
3148 | ||
3149 | rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len); | |
3150 | return 0; | |
3151 | } | |
3152 | ||
3153 | #define AUTH_ALG_OPEN_SYSTEM 0x1 | |
3154 | #define AUTH_ALG_SHARED_KEY 0x2 | |
3155 | #define AUTH_ALG_LEAP 0x4 | |
3156 | static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value) | |
3157 | { | |
3158 | ||
3159 | struct rtllib_security sec = { | |
3160 | .flags = SEC_AUTH_MODE, | |
3161 | }; | |
94a79942 LF |
3162 | |
3163 | if (value & AUTH_ALG_SHARED_KEY) { | |
3164 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; | |
3165 | ieee->open_wep = 0; | |
3166 | ieee->auth_mode = 1; | |
9d92ece8 | 3167 | } else if (value & AUTH_ALG_OPEN_SYSTEM) { |
94a79942 LF |
3168 | sec.auth_mode = WLAN_AUTH_OPEN; |
3169 | ieee->open_wep = 1; | |
3170 | ieee->auth_mode = 0; | |
9d92ece8 | 3171 | } else if (value & AUTH_ALG_LEAP) { |
94a79942 LF |
3172 | sec.auth_mode = WLAN_AUTH_LEAP >> 6; |
3173 | ieee->open_wep = 1; | |
3174 | ieee->auth_mode = 2; | |
3175 | } | |
3176 | ||
3177 | ||
3178 | if (ieee->set_security) | |
3179 | ieee->set_security(ieee->dev, &sec); | |
3180 | ||
4764ca98 | 3181 | return 0; |
94a79942 LF |
3182 | } |
3183 | ||
3184 | static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value) | |
3185 | { | |
9d92ece8 | 3186 | int ret = 0; |
94a79942 LF |
3187 | unsigned long flags; |
3188 | ||
3189 | switch (name) { | |
3190 | case IEEE_PARAM_WPA_ENABLED: | |
3191 | ret = rtllib_wpa_enable(ieee, value); | |
3192 | break; | |
3193 | ||
3194 | case IEEE_PARAM_TKIP_COUNTERMEASURES: | |
9d92ece8 | 3195 | ieee->tkip_countermeasures = value; |
94a79942 LF |
3196 | break; |
3197 | ||
9d92ece8 LF |
3198 | case IEEE_PARAM_DROP_UNENCRYPTED: |
3199 | { | |
94a79942 LF |
3200 | /* HACK: |
3201 | * | |
3202 | * wpa_supplicant calls set_wpa_enabled when the driver | |
3203 | * is loaded and unloaded, regardless of if WPA is being | |
3204 | * used. No other calls are made which can be used to | |
3205 | * determine if encryption will be used or not prior to | |
3206 | * association being expected. If encryption is not being | |
3207 | * used, drop_unencrypted is set to false, else true -- we | |
3208 | * can use this to determine if the CAP_PRIVACY_ON bit should | |
3209 | * be set. | |
3210 | */ | |
3211 | struct rtllib_security sec = { | |
3212 | .flags = SEC_ENABLED, | |
3213 | .enabled = value, | |
3214 | }; | |
3215 | ieee->drop_unencrypted = value; | |
3216 | /* We only change SEC_LEVEL for open mode. Others | |
3217 | * are set by ipw_wpa_set_encryption. | |
3218 | */ | |
3219 | if (!value) { | |
3220 | sec.flags |= SEC_LEVEL; | |
3221 | sec.level = SEC_LEVEL_0; | |
9d92ece8 | 3222 | } else { |
94a79942 LF |
3223 | sec.flags |= SEC_LEVEL; |
3224 | sec.level = SEC_LEVEL_1; | |
3225 | } | |
3226 | if (ieee->set_security) | |
3227 | ieee->set_security(ieee->dev, &sec); | |
3228 | break; | |
3229 | } | |
3230 | ||
3231 | case IEEE_PARAM_PRIVACY_INVOKED: | |
9d92ece8 | 3232 | ieee->privacy_invoked = value; |
94a79942 LF |
3233 | break; |
3234 | ||
3235 | case IEEE_PARAM_AUTH_ALGS: | |
3236 | ret = rtllib_wpa_set_auth_algs(ieee, value); | |
3237 | break; | |
3238 | ||
3239 | case IEEE_PARAM_IEEE_802_1X: | |
9d92ece8 | 3240 | ieee->ieee802_1x = value; |
94a79942 LF |
3241 | break; |
3242 | case IEEE_PARAM_WPAX_SELECT: | |
9d92ece8 LF |
3243 | spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags); |
3244 | spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags); | |
94a79942 LF |
3245 | break; |
3246 | ||
3247 | default: | |
d69d2054 | 3248 | netdev_info(ieee->dev, "Unknown WPA param: %d\n", name); |
94a79942 LF |
3249 | ret = -EOPNOTSUPP; |
3250 | } | |
3251 | ||
3252 | return ret; | |
3253 | } | |
3254 | ||
3255 | /* implementation borrowed from hostap driver */ | |
3256 | static int rtllib_wpa_set_encryption(struct rtllib_device *ieee, | |
9d92ece8 LF |
3257 | struct ieee_param *param, int param_len, |
3258 | u8 is_mesh) | |
94a79942 LF |
3259 | { |
3260 | int ret = 0; | |
32c44cb5 SM |
3261 | struct lib80211_crypto_ops *ops; |
3262 | struct lib80211_crypt_data **crypt; | |
94a79942 LF |
3263 | |
3264 | struct rtllib_security sec = { | |
3265 | .flags = 0, | |
3266 | }; | |
3267 | ||
3268 | param->u.crypt.err = 0; | |
3269 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; | |
3270 | ||
3271 | if (param_len != | |
3272 | (int) ((char *) param->u.crypt.key - (char *) param) + | |
3273 | param->u.crypt.key_len) { | |
d69d2054 MK |
3274 | netdev_info(ieee->dev, "Len mismatch %d, %d\n", param_len, |
3275 | param->u.crypt.key_len); | |
94a79942 LF |
3276 | return -EINVAL; |
3277 | } | |
0c43e56c | 3278 | if (is_broadcast_ether_addr(param->sta_addr)) { |
184f1938 | 3279 | if (param->u.crypt.idx >= NUM_WEP_KEYS) |
94a79942 | 3280 | return -EINVAL; |
0ddcf5fd | 3281 | crypt = &ieee->crypt_info.crypt[param->u.crypt.idx]; |
94a79942 LF |
3282 | } else { |
3283 | return -EINVAL; | |
3284 | } | |
3285 | ||
3286 | if (strcmp(param->u.crypt.alg, "none") == 0) { | |
3287 | if (crypt) { | |
3288 | sec.enabled = 0; | |
3289 | sec.level = SEC_LEVEL_0; | |
3290 | sec.flags |= SEC_ENABLED | SEC_LEVEL; | |
3b148be0 | 3291 | lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); |
94a79942 LF |
3292 | } |
3293 | goto done; | |
3294 | } | |
3295 | sec.enabled = 1; | |
3296 | sec.flags |= SEC_ENABLED; | |
3297 | ||
3298 | /* IPW HW cannot build TKIP MIC, host decryption still needed. */ | |
3299 | if (!(ieee->host_encrypt || ieee->host_decrypt) && | |
3b148be0 | 3300 | strcmp(param->u.crypt.alg, "R-TKIP")) |
94a79942 LF |
3301 | goto skip_host_crypt; |
3302 | ||
3b148be0 SM |
3303 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
3304 | if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) { | |
94a79942 | 3305 | request_module("rtllib_crypt_wep"); |
3b148be0 SM |
3306 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
3307 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) { | |
94a79942 | 3308 | request_module("rtllib_crypt_tkip"); |
3b148be0 SM |
3309 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
3310 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) { | |
94a79942 | 3311 | request_module("rtllib_crypt_ccmp"); |
3b148be0 | 3312 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
94a79942 LF |
3313 | } |
3314 | if (ops == NULL) { | |
d69d2054 MK |
3315 | netdev_info(ieee->dev, "unknown crypto alg '%s'\n", |
3316 | param->u.crypt.alg); | |
94a79942 LF |
3317 | param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG; |
3318 | ret = -EINVAL; | |
3319 | goto done; | |
3320 | } | |
3321 | if (*crypt == NULL || (*crypt)->ops != ops) { | |
32c44cb5 | 3322 | struct lib80211_crypt_data *new_crypt; |
94a79942 | 3323 | |
3b148be0 | 3324 | lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); |
94a79942 | 3325 | |
d272f9dd | 3326 | new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); |
94a79942 LF |
3327 | if (new_crypt == NULL) { |
3328 | ret = -ENOMEM; | |
3329 | goto done; | |
3330 | } | |
94a79942 LF |
3331 | new_crypt->ops = ops; |
3332 | if (new_crypt->ops) | |
3333 | new_crypt->priv = | |
3334 | new_crypt->ops->init(param->u.crypt.idx); | |
3335 | ||
3336 | if (new_crypt->priv == NULL) { | |
3337 | kfree(new_crypt); | |
3338 | param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED; | |
3339 | ret = -EINVAL; | |
3340 | goto done; | |
3341 | } | |
3342 | ||
3343 | *crypt = new_crypt; | |
3344 | } | |
3345 | ||
3346 | if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key && | |
3347 | (*crypt)->ops->set_key(param->u.crypt.key, | |
3348 | param->u.crypt.key_len, param->u.crypt.seq, | |
3349 | (*crypt)->priv) < 0) { | |
d69d2054 | 3350 | netdev_info(ieee->dev, "key setting failed\n"); |
94a79942 LF |
3351 | param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED; |
3352 | ret = -EINVAL; | |
3353 | goto done; | |
3354 | } | |
3355 | ||
3356 | skip_host_crypt: | |
3357 | if (param->u.crypt.set_tx) { | |
0ddcf5fd | 3358 | ieee->crypt_info.tx_keyidx = param->u.crypt.idx; |
94a79942 LF |
3359 | sec.active_key = param->u.crypt.idx; |
3360 | sec.flags |= SEC_ACTIVE_KEY; | |
3361 | } else | |
3362 | sec.flags &= ~SEC_ACTIVE_KEY; | |
3363 | ||
3364 | if (param->u.crypt.alg != NULL) { | |
3365 | memcpy(sec.keys[param->u.crypt.idx], | |
3366 | param->u.crypt.key, | |
3367 | param->u.crypt.key_len); | |
3368 | sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; | |
3369 | sec.flags |= (1 << param->u.crypt.idx); | |
3370 | ||
3b148be0 | 3371 | if (strcmp(param->u.crypt.alg, "R-WEP") == 0) { |
94a79942 LF |
3372 | sec.flags |= SEC_LEVEL; |
3373 | sec.level = SEC_LEVEL_1; | |
3b148be0 | 3374 | } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) { |
94a79942 LF |
3375 | sec.flags |= SEC_LEVEL; |
3376 | sec.level = SEC_LEVEL_2; | |
3b148be0 | 3377 | } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) { |
94a79942 LF |
3378 | sec.flags |= SEC_LEVEL; |
3379 | sec.level = SEC_LEVEL_3; | |
3380 | } | |
3381 | } | |
3382 | done: | |
3383 | if (ieee->set_security) | |
3384 | ieee->set_security(ieee->dev, &sec); | |
3385 | ||
3386 | /* Do not reset port if card is in Managed mode since resetting will | |
3387 | * generate new IEEE 802.11 authentication which may end up in looping | |
3388 | * with IEEE 802.1X. If your hardware requires a reset after WEP | |
3389 | * configuration (for example... Prism2), implement the reset_port in | |
14b40d92 MK |
3390 | * the callbacks structures used to initialize the 802.11 stack. |
3391 | */ | |
94a79942 LF |
3392 | if (ieee->reset_on_keychange && |
3393 | ieee->iw_mode != IW_MODE_INFRA && | |
3394 | ieee->reset_port && | |
3395 | ieee->reset_port(ieee->dev)) { | |
d69d2054 | 3396 | netdev_info(ieee->dev, "reset_port failed\n"); |
94a79942 LF |
3397 | param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED; |
3398 | return -EINVAL; | |
3399 | } | |
3400 | ||
3401 | return ret; | |
3402 | } | |
3403 | ||
9d92ece8 | 3404 | inline struct sk_buff *rtllib_disauth_skb(struct rtllib_network *beacon, |
94a79942 LF |
3405 | struct rtllib_device *ieee, u16 asRsn) |
3406 | { | |
3407 | struct sk_buff *skb; | |
3408 | struct rtllib_disauth *disauth; | |
94a79942 LF |
3409 | int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom; |
3410 | ||
94a79942 | 3411 | skb = dev_alloc_skb(len); |
9d92ece8 | 3412 | if (!skb) |
94a79942 | 3413 | return NULL; |
94a79942 | 3414 | |
94a79942 LF |
3415 | skb_reserve(skb, ieee->tx_headroom); |
3416 | ||
9d92ece8 LF |
3417 | disauth = (struct rtllib_disauth *) skb_put(skb, |
3418 | sizeof(struct rtllib_disauth)); | |
94a79942 LF |
3419 | disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH); |
3420 | disauth->header.duration_id = 0; | |
3421 | ||
b57ceb19 MK |
3422 | ether_addr_copy(disauth->header.addr1, beacon->bssid); |
3423 | ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr); | |
3424 | ether_addr_copy(disauth->header.addr3, beacon->bssid); | |
94a79942 LF |
3425 | |
3426 | disauth->reason = cpu_to_le16(asRsn); | |
3427 | return skb; | |
3428 | } | |
3429 | ||
9d92ece8 | 3430 | inline struct sk_buff *rtllib_disassociate_skb(struct rtllib_network *beacon, |
94a79942 LF |
3431 | struct rtllib_device *ieee, u16 asRsn) |
3432 | { | |
3433 | struct sk_buff *skb; | |
3434 | struct rtllib_disassoc *disass; | |
94a79942 | 3435 | int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom; |
3a6b70c3 | 3436 | |
94a79942 LF |
3437 | skb = dev_alloc_skb(len); |
3438 | ||
9d92ece8 | 3439 | if (!skb) |
94a79942 | 3440 | return NULL; |
94a79942 | 3441 | |
94a79942 LF |
3442 | skb_reserve(skb, ieee->tx_headroom); |
3443 | ||
9d92ece8 LF |
3444 | disass = (struct rtllib_disassoc *) skb_put(skb, |
3445 | sizeof(struct rtllib_disassoc)); | |
94a79942 LF |
3446 | disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC); |
3447 | disass->header.duration_id = 0; | |
3448 | ||
b57ceb19 MK |
3449 | ether_addr_copy(disass->header.addr1, beacon->bssid); |
3450 | ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr); | |
3451 | ether_addr_copy(disass->header.addr3, beacon->bssid); | |
94a79942 LF |
3452 | |
3453 | disass->reason = cpu_to_le16(asRsn); | |
3454 | return skb; | |
3455 | } | |
3456 | ||
3457 | void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn) | |
3458 | { | |
3459 | struct rtllib_network *beacon = &ieee->current_network; | |
3460 | struct sk_buff *skb; | |
3461 | ||
9d92ece8 LF |
3462 | if (deauth) |
3463 | skb = rtllib_disauth_skb(beacon, ieee, asRsn); | |
3464 | else | |
3465 | skb = rtllib_disassociate_skb(beacon, ieee, asRsn); | |
94a79942 | 3466 | |
9d92ece8 | 3467 | if (skb) |
94a79942 | 3468 | softmac_mgmt_xmit(skb, ieee); |
94a79942 LF |
3469 | } |
3470 | ||
3471 | u8 rtllib_ap_sec_type(struct rtllib_device *ieee) | |
3472 | { | |
9d92ece8 | 3473 | static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04}; |
94a79942 | 3474 | static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04}; |
9d92ece8 | 3475 | int wpa_ie_len = ieee->wpa_ie_len; |
32c44cb5 | 3476 | struct lib80211_crypt_data *crypt; |
94a79942 LF |
3477 | int encrypt; |
3478 | ||
0ddcf5fd | 3479 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
9d92ece8 LF |
3480 | encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) |
3481 | || (ieee->host_encrypt && crypt && crypt->ops && | |
3b148be0 | 3482 | (0 == strcmp(crypt->ops->name, "R-WEP"))); |
94a79942 LF |
3483 | |
3484 | /* simply judge */ | |
3485 | if (encrypt && (wpa_ie_len == 0)) { | |
3486 | return SEC_ALG_WEP; | |
3487 | } else if ((wpa_ie_len != 0)) { | |
9d92ece8 LF |
3488 | if (((ieee->wpa_ie[0] == 0xdd) && |
3489 | (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) || | |
3490 | ((ieee->wpa_ie[0] == 0x30) && | |
3491 | (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4)))) | |
94a79942 LF |
3492 | return SEC_ALG_CCMP; |
3493 | else | |
3494 | return SEC_ALG_TKIP; | |
3495 | } else { | |
3496 | return SEC_ALG_NONE; | |
3497 | } | |
3498 | } | |
3499 | ||
9d92ece8 LF |
3500 | int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p, |
3501 | u8 is_mesh) | |
94a79942 LF |
3502 | { |
3503 | struct ieee_param *param; | |
9d92ece8 | 3504 | int ret = 0; |
94a79942 LF |
3505 | |
3506 | down(&ieee->wx_sem); | |
3507 | ||
9d92ece8 | 3508 | if (p->length < sizeof(struct ieee_param) || !p->pointer) { |
94a79942 LF |
3509 | ret = -EINVAL; |
3510 | goto out; | |
3511 | } | |
3512 | ||
21624981 TB |
3513 | param = memdup_user(p->pointer, p->length); |
3514 | if (IS_ERR(param)) { | |
3515 | ret = PTR_ERR(param); | |
94a79942 LF |
3516 | goto out; |
3517 | } | |
3518 | ||
3519 | switch (param->cmd) { | |
94a79942 LF |
3520 | case IEEE_CMD_SET_WPA_PARAM: |
3521 | ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name, | |
3522 | param->u.wpa_param.value); | |
3523 | break; | |
3524 | ||
3525 | case IEEE_CMD_SET_WPA_IE: | |
3526 | ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length); | |
3527 | break; | |
3528 | ||
3529 | case IEEE_CMD_SET_ENCRYPTION: | |
3530 | ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0); | |
3531 | break; | |
3532 | ||
3533 | case IEEE_CMD_MLME: | |
3534 | ret = rtllib_wpa_mlme(ieee, param->u.mlme.command, | |
3535 | param->u.mlme.reason_code); | |
3536 | break; | |
3537 | ||
3538 | default: | |
d69d2054 MK |
3539 | netdev_info(ieee->dev, "Unknown WPA supplicant request: %d\n", |
3540 | param->cmd); | |
94a79942 LF |
3541 | ret = -EOPNOTSUPP; |
3542 | break; | |
3543 | } | |
3544 | ||
3545 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) | |
3546 | ret = -EFAULT; | |
3547 | ||
3548 | kfree(param); | |
3549 | out: | |
3550 | up(&ieee->wx_sem); | |
3551 | ||
3552 | return ret; | |
3553 | } | |
3b28499c | 3554 | EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl); |
94a79942 | 3555 | |
c5654c0b | 3556 | static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib) |
94a79942 LF |
3557 | { |
3558 | u8 OpMode; | |
3559 | u8 i; | |
3560 | bool bFilterOutNonAssociatedBSSID = false; | |
3561 | ||
3562 | rtllib->state = RTLLIB_NOLINK; | |
3563 | ||
9d92ece8 LF |
3564 | for (i = 0; i < 6; i++) |
3565 | rtllib->current_network.bssid[i] = 0x55; | |
94a79942 LF |
3566 | |
3567 | rtllib->OpMode = RT_OP_MODE_NO_LINK; | |
9d92ece8 LF |
3568 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID, |
3569 | rtllib->current_network.bssid); | |
94a79942 LF |
3570 | OpMode = RT_OP_MODE_NO_LINK; |
3571 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode); | |
3572 | rtllib_stop_send_beacons(rtllib); | |
3573 | ||
3574 | bFilterOutNonAssociatedBSSID = false; | |
9d92ece8 LF |
3575 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID, |
3576 | (u8 *)(&bFilterOutNonAssociatedBSSID)); | |
94a79942 LF |
3577 | notify_wx_assoc_event(rtllib); |
3578 | ||
3579 | } | |
3580 | ||
35e33b04 MK |
3581 | static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, |
3582 | u8 *asSta, u8 asRsn) | |
94a79942 LF |
3583 | { |
3584 | u8 i; | |
3585 | u8 OpMode; | |
3586 | ||
3587 | RemovePeerTS(rtllib, asSta); | |
3588 | ||
ea9f10f2 | 3589 | if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) { |
94a79942 LF |
3590 | rtllib->state = RTLLIB_NOLINK; |
3591 | ||
9d92ece8 LF |
3592 | for (i = 0; i < 6; i++) |
3593 | rtllib->current_network.bssid[i] = 0x22; | |
94a79942 LF |
3594 | OpMode = RT_OP_MODE_NO_LINK; |
3595 | rtllib->OpMode = RT_OP_MODE_NO_LINK; | |
9d92ece8 LF |
3596 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, |
3597 | (u8 *)(&OpMode)); | |
94a79942 LF |
3598 | rtllib_disassociate(rtllib); |
3599 | ||
9d92ece8 LF |
3600 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID, |
3601 | rtllib->current_network.bssid); | |
94a79942 LF |
3602 | |
3603 | } | |
3604 | ||
3605 | } | |
3606 | ||
c5654c0b | 3607 | static void |
94a79942 | 3608 | rtllib_MgntDisconnectAP( |
9d92ece8 | 3609 | struct rtllib_device *rtllib, |
94a79942 LF |
3610 | u8 asRsn |
3611 | ) | |
3612 | { | |
3613 | bool bFilterOutNonAssociatedBSSID = false; | |
3614 | ||
94a79942 | 3615 | bFilterOutNonAssociatedBSSID = false; |
9d92ece8 LF |
3616 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID, |
3617 | (u8 *)(&bFilterOutNonAssociatedBSSID)); | |
3618 | rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid, | |
3619 | asRsn); | |
94a79942 LF |
3620 | |
3621 | rtllib->state = RTLLIB_NOLINK; | |
3622 | } | |
3623 | ||
9d92ece8 | 3624 | bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn) |
94a79942 LF |
3625 | { |
3626 | if (rtllib->ps != RTLLIB_PS_DISABLED) | |
9d92ece8 | 3627 | rtllib->sta_wake_up(rtllib->dev); |
94a79942 | 3628 | |
9d92ece8 LF |
3629 | if (rtllib->state == RTLLIB_LINKED) { |
3630 | if (rtllib->iw_mode == IW_MODE_ADHOC) | |
94a79942 | 3631 | rtllib_MgntDisconnectIBSS(rtllib); |
9d92ece8 | 3632 | if (rtllib->iw_mode == IW_MODE_INFRA) |
94a79942 | 3633 | rtllib_MgntDisconnectAP(rtllib, asRsn); |
94a79942 LF |
3634 | |
3635 | } | |
3636 | ||
3637 | return true; | |
3638 | } | |
3b28499c | 3639 | EXPORT_SYMBOL(rtllib_MgntDisconnect); |
94a79942 LF |
3640 | |
3641 | void notify_wx_assoc_event(struct rtllib_device *ieee) | |
3642 | { | |
3643 | union iwreq_data wrqu; | |
3644 | ||
3645 | if (ieee->cannot_notify) | |
3646 | return; | |
3647 | ||
3648 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
3649 | if (ieee->state == RTLLIB_LINKED) | |
9d92ece8 LF |
3650 | memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, |
3651 | ETH_ALEN); | |
3652 | else { | |
94a79942 | 3653 | |
d69d2054 MK |
3654 | netdev_info(ieee->dev, "%s(): Tell user space disconnected\n", |
3655 | __func__); | |
cdbaf3f6 | 3656 | eth_zero_addr(wrqu.ap_addr.sa_data); |
94a79942 LF |
3657 | } |
3658 | wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL); | |
3659 | } | |
3b28499c | 3660 | EXPORT_SYMBOL(notify_wx_assoc_event); |