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