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