ARM: debug: qcom: add UART addresses to Kconfig help for APQ8084
[pandora-kernel.git] / drivers / staging / rtl8187se / ieee80211 / ieee80211_softmac_wx.c
1 /* IEEE 802.11 SoftMAC layer
2  * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
3  *
4  * Mostly extracted from the rtl8180-sa2400 driver for the
5  * in-kernel generic ieee802.11 stack.
6  *
7  * Some pieces of code might be stolen from ipw2100 driver
8  * copyright of who own it's copyright ;-)
9  *
10  * PS wx handler mostly stolen from hostap, copyright who
11  * own it's copyright ;-)
12  *
13  * released under the GPL
14  */
15
16
17 #include <linux/etherdevice.h>
18
19 #include "ieee80211.h"
20
21 /* FIXME: add A freqs */
22
23 const long ieee80211_wlan_frequencies[] = {
24         2412, 2417, 2422, 2427,
25         2432, 2437, 2442, 2447,
26         2452, 2457, 2462, 2467,
27         2472, 2484
28 };
29
30
31 int ieee80211_wx_set_freq(struct ieee80211_device *ieee,
32                           struct iw_request_info *a, union iwreq_data *wrqu,
33                           char *b)
34 {
35         int ret;
36         struct iw_freq *fwrq = &wrqu->freq;
37 //      printk("in %s\n",__func__);
38         down(&ieee->wx_sem);
39
40         if (ieee->iw_mode == IW_MODE_INFRA) {
41                 ret = -EOPNOTSUPP;
42                 goto out;
43         }
44
45         /* if setting by freq convert to channel */
46         if (fwrq->e == 1) {
47                 if ((fwrq->m >= (int) 2.412e8 &&
48                      fwrq->m <= (int) 2.487e8)) {
49                         int f = fwrq->m / 100000;
50                         int c = 0;
51
52                         while ((c < 14) && (f != ieee80211_wlan_frequencies[c]))
53                                 c++;
54
55                         /* hack to fall through */
56                         fwrq->e = 0;
57                         fwrq->m = c + 1;
58                 }
59         }
60
61         if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1) {
62                 ret = -EOPNOTSUPP;
63                 goto out;
64
65         } else { /* Set the channel */
66
67
68                 ieee->current_network.channel = fwrq->m;
69                 ieee->set_chan(ieee->dev, ieee->current_network.channel);
70
71                 if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
72                         if (ieee->state == IEEE80211_LINKED) {
73                                 ieee80211_stop_send_beacons(ieee);
74                                 ieee80211_start_send_beacons(ieee);
75                         }
76         }
77
78         ret = 0;
79 out:
80         up(&ieee->wx_sem);
81         return ret;
82 }
83
84
85 int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
86                           struct iw_request_info *a, union iwreq_data *wrqu,
87                           char *b)
88 {
89         struct iw_freq *fwrq = &wrqu->freq;
90
91         if (ieee->current_network.channel == 0)
92                 return -1;
93
94         fwrq->m = ieee->current_network.channel;
95         fwrq->e = 0;
96
97         return 0;
98 }
99
100 int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
101                          struct iw_request_info *info, union iwreq_data *wrqu,
102                          char *extra)
103 {
104         unsigned long flags;
105
106         wrqu->ap_addr.sa_family = ARPHRD_ETHER;
107
108         if (ieee->iw_mode == IW_MODE_MONITOR)
109                 return -1;
110
111         /* We want avoid to give to the user inconsistent infos*/
112         spin_lock_irqsave(&ieee->lock, flags);
113
114         if (ieee->state != IEEE80211_LINKED &&
115                 ieee->state != IEEE80211_LINKED_SCANNING &&
116                 ieee->wap_set == 0)
117
118                 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
119         else
120                 memcpy(wrqu->ap_addr.sa_data,
121                        ieee->current_network.bssid, ETH_ALEN);
122
123         spin_unlock_irqrestore(&ieee->lock, flags);
124
125         return 0;
126 }
127
128
129 int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
130                          struct iw_request_info *info, union iwreq_data *awrq,
131                          char *extra)
132 {
133
134         int ret = 0;
135         unsigned long flags;
136
137         short ifup = ieee->proto_started;//dev->flags & IFF_UP;
138         struct sockaddr *temp = (struct sockaddr *)awrq;
139
140         //printk("=======Set WAP:");
141         ieee->sync_scan_hurryup = 1;
142
143         down(&ieee->wx_sem);
144         /* use ifconfig hw ether */
145         if (ieee->iw_mode == IW_MODE_MASTER) {
146                 ret = -1;
147                 goto out;
148         }
149
150         if (temp->sa_family != ARPHRD_ETHER) {
151                 ret = -EINVAL;
152                 goto out;
153         }
154
155         if (ifup)
156                 ieee80211_stop_protocol(ieee);
157
158         /* just to avoid to give inconsistent infos in the
159          * get wx method. not really needed otherwise
160          */
161         spin_lock_irqsave(&ieee->lock, flags);
162
163         memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
164         ieee->wap_set = !is_zero_ether_addr(temp->sa_data);
165         //printk(" %x:%x:%x:%x:%x:%x\n", ieee->current_network.bssid[0],ieee->current_network.bssid[1],ieee->current_network.bssid[2],ieee->current_network.bssid[3],ieee->current_network.bssid[4],ieee->current_network.bssid[5]);
166
167         spin_unlock_irqrestore(&ieee->lock, flags);
168
169         if (ifup)
170                 ieee80211_start_protocol(ieee);
171
172 out:
173         up(&ieee->wx_sem);
174         return ret;
175 }
176
177 int ieee80211_wx_get_essid(struct ieee80211_device *ieee,
178                            struct iw_request_info *a, union iwreq_data *wrqu,
179                            char *b)
180 {
181         int len, ret = 0;
182         unsigned long flags;
183
184         if (ieee->iw_mode == IW_MODE_MONITOR)
185                 return -1;
186
187         /* We want avoid to give to the user inconsistent infos*/
188         spin_lock_irqsave(&ieee->lock, flags);
189
190         if (ieee->current_network.ssid[0] == '\0' ||
191                 ieee->current_network.ssid_len == 0){
192                 ret = -1;
193                 goto out;
194         }
195
196         if (ieee->state != IEEE80211_LINKED &&
197                 ieee->state != IEEE80211_LINKED_SCANNING &&
198                 ieee->ssid_set == 0){
199                 ret = -1;
200                 goto out;
201         }
202         len = ieee->current_network.ssid_len;
203         wrqu->essid.length = len;
204         strncpy(b, ieee->current_network.ssid, len);
205         wrqu->essid.flags = 1;
206
207 out:
208         spin_unlock_irqrestore(&ieee->lock, flags);
209
210         return ret;
211
212 }
213
214 int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
215                           struct iw_request_info *info, union iwreq_data *wrqu,
216                           char *extra)
217 {
218
219         u32 target_rate = wrqu->bitrate.value;
220
221         //added by lizhaoming for auto mode
222         if (target_rate == -1)
223                 ieee->rate = 110;
224         else
225                 ieee->rate = target_rate/100000;
226
227         //FIXME: we might want to limit rate also in management protocols.
228         return 0;
229 }
230
231
232
233 int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
234                           struct iw_request_info *info, union iwreq_data *wrqu,
235                           char *extra)
236 {
237
238         wrqu->bitrate.value = ieee->rate * 100000;
239
240         return 0;
241 }
242
243 int ieee80211_wx_set_mode(struct ieee80211_device *ieee,
244                           struct iw_request_info *a, union iwreq_data *wrqu,
245                           char *b)
246 {
247
248         ieee->sync_scan_hurryup = 1;
249
250         down(&ieee->wx_sem);
251
252         if (wrqu->mode == ieee->iw_mode)
253                 goto out;
254
255         if (wrqu->mode == IW_MODE_MONITOR)
256                 ieee->dev->type = ARPHRD_IEEE80211;
257         else
258                 ieee->dev->type = ARPHRD_ETHER;
259
260         if (!ieee->proto_started) {
261                 ieee->iw_mode = wrqu->mode;
262         } else {
263                 ieee80211_stop_protocol(ieee);
264                 ieee->iw_mode = wrqu->mode;
265                 ieee80211_start_protocol(ieee);
266         }
267
268 out:
269         up(&ieee->wx_sem);
270         return 0;
271 }
272
273
274 void ieee80211_wx_sync_scan_wq(struct work_struct *work)
275 {
276         struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq);
277         short chan;
278
279         chan = ieee->current_network.channel;
280
281         if (ieee->data_hard_stop)
282                 ieee->data_hard_stop(ieee->dev);
283
284         ieee80211_stop_send_beacons(ieee);
285
286         ieee->state = IEEE80211_LINKED_SCANNING;
287         ieee->link_change(ieee->dev);
288
289         ieee80211_start_scan_syncro(ieee);
290
291         ieee->set_chan(ieee->dev, chan);
292
293         ieee->state = IEEE80211_LINKED;
294         ieee->link_change(ieee->dev);
295
296         if (ieee->data_hard_resume)
297                 ieee->data_hard_resume(ieee->dev);
298
299         if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
300                 ieee80211_start_send_beacons(ieee);
301
302         //YJ,add,080828, In prevent of lossing ping packet during scanning
303         //ieee80211_sta_ps_send_null_frame(ieee, false);
304         //YJ,add,080828,end
305
306         up(&ieee->wx_sem);
307
308 }
309
310 int ieee80211_wx_set_scan(struct ieee80211_device *ieee,
311                           struct iw_request_info *a, union iwreq_data *wrqu,
312                           char *b)
313 {
314         int ret = 0;
315
316         down(&ieee->wx_sem);
317
318         if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) {
319                 ret = -1;
320                 goto out;
321         }
322         //YJ,add,080828
323         //In prevent of lossing ping packet during scanning
324         //ieee80211_sta_ps_send_null_frame(ieee, true);
325         //YJ,add,080828,end
326
327         if (ieee->state == IEEE80211_LINKED) {
328                 queue_work(ieee->wq, &ieee->wx_sync_scan_wq);
329                 /* intentionally forget to up sem */
330                 return 0;
331         }
332
333 out:
334         up(&ieee->wx_sem);
335         return ret;
336 }
337
338 int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
339                            struct iw_request_info *a, union iwreq_data *wrqu,
340                            char *extra)
341 {
342
343         int ret = 0, len;
344         short proto_started;
345         unsigned long flags;
346
347         ieee->sync_scan_hurryup = 1;
348
349         down(&ieee->wx_sem);
350
351         proto_started = ieee->proto_started;
352
353         if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
354                 ret = -E2BIG;
355                 goto out;
356         }
357
358         if (ieee->iw_mode == IW_MODE_MONITOR) {
359                 ret = -1;
360                 goto out;
361         }
362
363         if (proto_started)
364                 ieee80211_stop_protocol(ieee);
365
366         /* this is just to be sure that the GET wx callback
367          * has consistent infos. not needed otherwise
368          */
369         spin_lock_irqsave(&ieee->lock, flags);
370
371         if (wrqu->essid.flags && wrqu->essid.length) {
372 //YJ,modified,080819
373                 len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length) : IW_ESSID_MAX_SIZE;
374                 memset(ieee->current_network.ssid, 0, ieee->current_network.ssid_len); //YJ,add,080819
375                 strncpy(ieee->current_network.ssid, extra, len);
376                 ieee->current_network.ssid_len = len;
377                 ieee->ssid_set = 1;
378 //YJ,modified,080819,end
379
380                 //YJ,add,080819,for hidden ap
381                 if (len == 0) {
382                         memset(ieee->current_network.bssid, 0, ETH_ALEN);
383                         ieee->current_network.capability = 0;
384                 }
385                 //YJ,add,080819,for hidden ap,end
386         } else {
387                 ieee->ssid_set = 0;
388                 ieee->current_network.ssid[0] = '\0';
389                 ieee->current_network.ssid_len = 0;
390         }
391         //printk("==========set essid %s!\n",ieee->current_network.ssid);
392         spin_unlock_irqrestore(&ieee->lock, flags);
393
394         if (proto_started)
395                 ieee80211_start_protocol(ieee);
396 out:
397         up(&ieee->wx_sem);
398         return ret;
399 }
400
401 int ieee80211_wx_get_mode(struct ieee80211_device *ieee,
402                           struct iw_request_info *a, union iwreq_data *wrqu,
403                           char *b)
404 {
405
406         wrqu->mode = ieee->iw_mode;
407         return 0;
408 }
409
410 int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
411                            struct iw_request_info *info, union iwreq_data *wrqu,
412                            char *extra)
413 {
414
415         int *parms = (int *)extra;
416         int enable = (parms[0] > 0);
417         short prev = ieee->raw_tx;
418
419         down(&ieee->wx_sem);
420
421         if (enable)
422                 ieee->raw_tx = 1;
423         else
424                 ieee->raw_tx = 0;
425
426         netdev_info(ieee->dev, "raw TX is %s\n",
427                     ieee->raw_tx ? "enabled" : "disabled");
428
429         if (ieee->iw_mode == IW_MODE_MONITOR) {
430                 if (prev == 0 && ieee->raw_tx) {
431                         if (ieee->data_hard_resume)
432                                 ieee->data_hard_resume(ieee->dev);
433
434                         netif_carrier_on(ieee->dev);
435                 }
436
437                 if (prev && ieee->raw_tx == 1)
438                         netif_carrier_off(ieee->dev);
439         }
440
441         up(&ieee->wx_sem);
442
443         return 0;
444 }
445
446 int ieee80211_wx_get_name(struct ieee80211_device *ieee,
447                           struct iw_request_info *info, union iwreq_data *wrqu,
448                           char *extra)
449 {
450         strlcpy(wrqu->name, "802.11", IFNAMSIZ);
451         if (ieee->modulation & IEEE80211_CCK_MODULATION) {
452                 strlcat(wrqu->name, "b", IFNAMSIZ);
453                 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
454                         strlcat(wrqu->name, "/g", IFNAMSIZ);
455         } else if (ieee->modulation & IEEE80211_OFDM_MODULATION)
456                 strlcat(wrqu->name, "g", IFNAMSIZ);
457
458         if ((ieee->state == IEEE80211_LINKED) ||
459                 (ieee->state == IEEE80211_LINKED_SCANNING))
460                 strlcat(wrqu->name, "  link", IFNAMSIZ);
461         else if (ieee->state != IEEE80211_NOLINK)
462                 strlcat(wrqu->name, " .....", IFNAMSIZ);
463
464
465         return 0;
466 }
467
468
469 /* this is mostly stolen from hostap */
470 int ieee80211_wx_set_power(struct ieee80211_device *ieee,
471                            struct iw_request_info *info, union iwreq_data *wrqu,
472                            char *extra)
473 {
474         int ret = 0;
475
476         if ((!ieee->sta_wake_up) ||
477             (!ieee->ps_request_tx_ack) ||
478             (!ieee->enter_sleep_state) ||
479             (!ieee->ps_is_queue_empty)) {
480
481                 printk("ERROR. PS mode tried to be use but driver missed a callback\n\n");
482
483                 return -1;
484         }
485
486         down(&ieee->wx_sem);
487
488         if (wrqu->power.disabled) {
489                 ieee->ps = IEEE80211_PS_DISABLED;
490
491                 goto exit;
492         }
493         switch (wrqu->power.flags & IW_POWER_MODE) {
494         case IW_POWER_UNICAST_R:
495                 ieee->ps = IEEE80211_PS_UNICAST;
496
497                 break;
498         case IW_POWER_ALL_R:
499                 ieee->ps = IEEE80211_PS_UNICAST | IEEE80211_PS_MBCAST;
500                 break;
501
502         case IW_POWER_ON:
503                 ieee->ps = IEEE80211_PS_DISABLED;
504                 break;
505
506         default:
507                 ret = -EINVAL;
508                 goto exit;
509         }
510
511         if (wrqu->power.flags & IW_POWER_TIMEOUT) {
512
513                 ieee->ps_timeout = wrqu->power.value / 1000;
514                 printk("Timeout %d\n", ieee->ps_timeout);
515         }
516
517         if (wrqu->power.flags & IW_POWER_PERIOD) {
518
519                 ret = -EOPNOTSUPP;
520                 goto exit;
521                 //wrq->value / 1024;
522
523         }
524 exit:
525         up(&ieee->wx_sem);
526         return ret;
527
528 }
529
530 /* this is stolen from hostap */
531 int ieee80211_wx_get_power(struct ieee80211_device *ieee,
532                            struct iw_request_info *info, union iwreq_data *wrqu,
533                            char *extra)
534 {
535         int ret = 0;
536
537         down(&ieee->wx_sem);
538
539         if (ieee->ps == IEEE80211_PS_DISABLED) {
540                 wrqu->power.disabled = 1;
541                 goto exit;
542         }
543
544         wrqu->power.disabled = 0;
545
546 //      if ((wrqu->power.flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
547                 wrqu->power.flags = IW_POWER_TIMEOUT;
548                 wrqu->power.value = ieee->ps_timeout * 1000;
549 //      } else {
550 //              ret = -EOPNOTSUPP;
551 //              goto exit;
552                 //wrqu->power.flags = IW_POWER_PERIOD;
553                 //wrqu->power.value = ieee->current_network.dtim_period *
554                 //      ieee->current_network.beacon_interval * 1024;
555 //      }
556
557
558         if (ieee->ps & IEEE80211_PS_MBCAST)
559                 wrqu->power.flags |= IW_POWER_ALL_R;
560         else
561                 wrqu->power.flags |= IW_POWER_UNICAST_R;
562
563 exit:
564         up(&ieee->wx_sem);
565         return ret;
566
567 }