1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
4 * Mostly extracted from the rtl8180-sa2400 driver for the
5 * in-kernel generic ieee802.11 stack.
7 * Some pieces of code might be stolen from ipw2100 driver
8 * copyright of who own it's copyright ;-)
10 * PS wx handler mostly stolen from hostap, copyright who
11 * own it's copyright ;-)
13 * released under the GPL
17 #include <linux/etherdevice.h>
19 #include "ieee80211.h"
21 /* FIXME: add A freqs */
23 const long ieee80211_wlan_frequencies[] = {
24 2412, 2417, 2422, 2427,
25 2432, 2437, 2442, 2447,
26 2452, 2457, 2462, 2467,
31 int ieee80211_wx_set_freq(struct ieee80211_device *ieee,
32 struct iw_request_info *a, union iwreq_data *wrqu,
36 struct iw_freq *fwrq = &wrqu->freq;
37 // printk("in %s\n",__func__);
40 if (ieee->iw_mode == IW_MODE_INFRA) {
45 /* if setting by freq convert to channel */
47 if ((fwrq->m >= (int) 2.412e8 &&
48 fwrq->m <= (int) 2.487e8)) {
49 int f = fwrq->m / 100000;
52 while ((c < 14) && (f != ieee80211_wlan_frequencies[c]))
55 /* hack to fall through */
61 if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1) {
65 } else { /* Set the channel */
68 ieee->current_network.channel = fwrq->m;
69 ieee->set_chan(ieee->dev, ieee->current_network.channel);
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);
85 int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
86 struct iw_request_info *a, union iwreq_data *wrqu,
89 struct iw_freq *fwrq = &wrqu->freq;
91 if (ieee->current_network.channel == 0)
94 fwrq->m = ieee->current_network.channel;
100 int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
101 struct iw_request_info *info, union iwreq_data *wrqu,
106 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
108 if (ieee->iw_mode == IW_MODE_MONITOR)
111 /* We want avoid to give to the user inconsistent infos*/
112 spin_lock_irqsave(&ieee->lock, flags);
114 if (ieee->state != IEEE80211_LINKED &&
115 ieee->state != IEEE80211_LINKED_SCANNING &&
118 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
120 memcpy(wrqu->ap_addr.sa_data,
121 ieee->current_network.bssid, ETH_ALEN);
123 spin_unlock_irqrestore(&ieee->lock, flags);
129 int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
130 struct iw_request_info *info, union iwreq_data *awrq,
137 short ifup = ieee->proto_started;//dev->flags & IFF_UP;
138 struct sockaddr *temp = (struct sockaddr *)awrq;
140 //printk("=======Set WAP:");
141 ieee->sync_scan_hurryup = 1;
144 /* use ifconfig hw ether */
145 if (ieee->iw_mode == IW_MODE_MASTER) {
150 if (temp->sa_family != ARPHRD_ETHER) {
156 ieee80211_stop_protocol(ieee);
158 /* just to avoid to give inconsistent infos in the
159 * get wx method. not really needed otherwise
161 spin_lock_irqsave(&ieee->lock, flags);
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]);
167 spin_unlock_irqrestore(&ieee->lock, flags);
170 ieee80211_start_protocol(ieee);
177 int ieee80211_wx_get_essid(struct ieee80211_device *ieee,
178 struct iw_request_info *a, union iwreq_data *wrqu,
184 if (ieee->iw_mode == IW_MODE_MONITOR)
187 /* We want avoid to give to the user inconsistent infos*/
188 spin_lock_irqsave(&ieee->lock, flags);
190 if (ieee->current_network.ssid[0] == '\0' ||
191 ieee->current_network.ssid_len == 0){
196 if (ieee->state != IEEE80211_LINKED &&
197 ieee->state != IEEE80211_LINKED_SCANNING &&
198 ieee->ssid_set == 0){
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;
208 spin_unlock_irqrestore(&ieee->lock, flags);
214 int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
215 struct iw_request_info *info, union iwreq_data *wrqu,
219 u32 target_rate = wrqu->bitrate.value;
221 //added by lizhaoming for auto mode
222 if (target_rate == -1)
225 ieee->rate = target_rate/100000;
227 //FIXME: we might want to limit rate also in management protocols.
233 int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
234 struct iw_request_info *info, union iwreq_data *wrqu,
238 wrqu->bitrate.value = ieee->rate * 100000;
243 int ieee80211_wx_set_mode(struct ieee80211_device *ieee,
244 struct iw_request_info *a, union iwreq_data *wrqu,
248 ieee->sync_scan_hurryup = 1;
252 if (wrqu->mode == ieee->iw_mode)
255 if (wrqu->mode == IW_MODE_MONITOR)
256 ieee->dev->type = ARPHRD_IEEE80211;
258 ieee->dev->type = ARPHRD_ETHER;
260 if (!ieee->proto_started) {
261 ieee->iw_mode = wrqu->mode;
263 ieee80211_stop_protocol(ieee);
264 ieee->iw_mode = wrqu->mode;
265 ieee80211_start_protocol(ieee);
274 void ieee80211_wx_sync_scan_wq(struct work_struct *work)
276 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq);
279 chan = ieee->current_network.channel;
281 if (ieee->data_hard_stop)
282 ieee->data_hard_stop(ieee->dev);
284 ieee80211_stop_send_beacons(ieee);
286 ieee->state = IEEE80211_LINKED_SCANNING;
287 ieee->link_change(ieee->dev);
289 ieee80211_start_scan_syncro(ieee);
291 ieee->set_chan(ieee->dev, chan);
293 ieee->state = IEEE80211_LINKED;
294 ieee->link_change(ieee->dev);
296 if (ieee->data_hard_resume)
297 ieee->data_hard_resume(ieee->dev);
299 if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
300 ieee80211_start_send_beacons(ieee);
302 //YJ,add,080828, In prevent of lossing ping packet during scanning
303 //ieee80211_sta_ps_send_null_frame(ieee, false);
310 int ieee80211_wx_set_scan(struct ieee80211_device *ieee,
311 struct iw_request_info *a, union iwreq_data *wrqu,
318 if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) {
323 //In prevent of lossing ping packet during scanning
324 //ieee80211_sta_ps_send_null_frame(ieee, true);
327 if (ieee->state == IEEE80211_LINKED) {
328 queue_work(ieee->wq, &ieee->wx_sync_scan_wq);
329 /* intentionally forget to up sem */
338 int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
339 struct iw_request_info *a, union iwreq_data *wrqu,
347 ieee->sync_scan_hurryup = 1;
351 proto_started = ieee->proto_started;
353 if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
358 if (ieee->iw_mode == IW_MODE_MONITOR) {
364 ieee80211_stop_protocol(ieee);
366 /* this is just to be sure that the GET wx callback
367 * has consistent infos. not needed otherwise
369 spin_lock_irqsave(&ieee->lock, flags);
371 if (wrqu->essid.flags && wrqu->essid.length) {
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;
378 //YJ,modified,080819,end
380 //YJ,add,080819,for hidden ap
382 memset(ieee->current_network.bssid, 0, ETH_ALEN);
383 ieee->current_network.capability = 0;
385 //YJ,add,080819,for hidden ap,end
388 ieee->current_network.ssid[0] = '\0';
389 ieee->current_network.ssid_len = 0;
391 //printk("==========set essid %s!\n",ieee->current_network.ssid);
392 spin_unlock_irqrestore(&ieee->lock, flags);
395 ieee80211_start_protocol(ieee);
401 int ieee80211_wx_get_mode(struct ieee80211_device *ieee,
402 struct iw_request_info *a, union iwreq_data *wrqu,
406 wrqu->mode = ieee->iw_mode;
410 int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
411 struct iw_request_info *info, union iwreq_data *wrqu,
415 int *parms = (int *)extra;
416 int enable = (parms[0] > 0);
417 short prev = ieee->raw_tx;
426 netdev_info(ieee->dev, "raw TX is %s\n",
427 ieee->raw_tx ? "enabled" : "disabled");
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);
434 netif_carrier_on(ieee->dev);
437 if (prev && ieee->raw_tx == 1)
438 netif_carrier_off(ieee->dev);
446 int ieee80211_wx_get_name(struct ieee80211_device *ieee,
447 struct iw_request_info *info, union iwreq_data *wrqu,
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);
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);
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,
476 if ((!ieee->sta_wake_up) ||
477 (!ieee->ps_request_tx_ack) ||
478 (!ieee->enter_sleep_state) ||
479 (!ieee->ps_is_queue_empty)) {
481 printk("ERROR. PS mode tried to be use but driver missed a callback\n\n");
488 if (wrqu->power.disabled) {
489 ieee->ps = IEEE80211_PS_DISABLED;
493 switch (wrqu->power.flags & IW_POWER_MODE) {
494 case IW_POWER_UNICAST_R:
495 ieee->ps = IEEE80211_PS_UNICAST;
499 ieee->ps = IEEE80211_PS_UNICAST | IEEE80211_PS_MBCAST;
503 ieee->ps = IEEE80211_PS_DISABLED;
511 if (wrqu->power.flags & IW_POWER_TIMEOUT) {
513 ieee->ps_timeout = wrqu->power.value / 1000;
514 printk("Timeout %d\n", ieee->ps_timeout);
517 if (wrqu->power.flags & IW_POWER_PERIOD) {
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,
539 if (ieee->ps == IEEE80211_PS_DISABLED) {
540 wrqu->power.disabled = 1;
544 wrqu->power.disabled = 0;
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;
550 // ret = -EOPNOTSUPP;
552 //wrqu->power.flags = IW_POWER_PERIOD;
553 //wrqu->power.value = ieee->current_network.dtim_period *
554 // ieee->current_network.beacon_interval * 1024;
558 if (ieee->ps & IEEE80211_PS_MBCAST)
559 wrqu->power.flags |= IW_POWER_ALL_R;
561 wrqu->power.flags |= IW_POWER_UNICAST_R;