1 /* IEEE 802.11 SoftMAC layer
2 * Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
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, struct iw_request_info *a,
32 union iwreq_data *wrqu, char *b)
35 struct iw_freq *fwrq = &wrqu->freq;
36 // printk("in %s\n",__func__);
39 if (ieee->iw_mode == IW_MODE_INFRA) {
44 /* if setting by freq convert to channel */
46 if ((fwrq->m >= (int) 2.412e8 &&
47 fwrq->m <= (int) 2.487e8)) {
48 int f = fwrq->m / 100000;
51 while ((c < 14) && (f != ieee80211_wlan_frequencies[c]))
54 /* hack to fall through */
60 if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1) {
64 } else { /* Set the channel */
67 ieee->current_network.channel = fwrq->m;
68 ieee->set_chan(ieee->dev, ieee->current_network.channel);
70 if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
71 if (ieee->state == IEEE80211_LINKED) {
72 ieee80211_stop_send_beacons(ieee);
73 ieee80211_start_send_beacons(ieee);
84 int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
85 struct iw_request_info *a,
86 union iwreq_data *wrqu, char *b)
88 struct iw_freq *fwrq = &wrqu->freq;
90 if (ieee->current_network.channel == 0)
93 fwrq->m = ieee->current_network.channel;
99 int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
100 struct iw_request_info *info,
101 union iwreq_data *wrqu, char *extra)
105 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
107 if (ieee->iw_mode == IW_MODE_MONITOR)
110 /* We want avoid to give to the user inconsistent infos*/
111 spin_lock_irqsave(&ieee->lock, flags);
113 if (ieee->state != IEEE80211_LINKED &&
114 ieee->state != IEEE80211_LINKED_SCANNING &&
117 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
119 memcpy(wrqu->ap_addr.sa_data,
120 ieee->current_network.bssid, ETH_ALEN);
122 spin_unlock_irqrestore(&ieee->lock, flags);
128 int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
129 struct iw_request_info *info,
130 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, struct iw_request_info *a,
178 union iwreq_data *wrqu, char *b)
183 if (ieee->iw_mode == IW_MODE_MONITOR)
186 /* We want avoid to give to the user inconsistent infos*/
187 spin_lock_irqsave(&ieee->lock, flags);
189 if (ieee->current_network.ssid[0] == '\0' ||
190 ieee->current_network.ssid_len == 0){
195 if (ieee->state != IEEE80211_LINKED &&
196 ieee->state != IEEE80211_LINKED_SCANNING &&
197 ieee->ssid_set == 0){
201 len = ieee->current_network.ssid_len;
202 wrqu->essid.length = len;
203 strncpy(b, ieee->current_network.ssid, len);
204 wrqu->essid.flags = 1;
207 spin_unlock_irqrestore(&ieee->lock, flags);
213 int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
214 struct iw_request_info *info,
215 union iwreq_data *wrqu, char *extra)
218 u32 target_rate = wrqu->bitrate.value;
220 //added by lizhaoming for auto mode
221 if (target_rate == -1)
224 ieee->rate = target_rate/100000;
226 //FIXME: we might want to limit rate also in management protocols.
232 int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
233 struct iw_request_info *info,
234 union iwreq_data *wrqu, char *extra)
237 wrqu->bitrate.value = ieee->rate * 100000;
242 int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
243 union iwreq_data *wrqu, char *b)
246 ieee->sync_scan_hurryup = 1;
250 if (wrqu->mode == ieee->iw_mode)
253 if (wrqu->mode == IW_MODE_MONITOR)
254 ieee->dev->type = ARPHRD_IEEE80211;
256 ieee->dev->type = ARPHRD_ETHER;
258 if (!ieee->proto_started) {
259 ieee->iw_mode = wrqu->mode;
261 ieee80211_stop_protocol(ieee);
262 ieee->iw_mode = wrqu->mode;
263 ieee80211_start_protocol(ieee);
272 void ieee80211_wx_sync_scan_wq(struct work_struct *work)
274 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq);
277 chan = ieee->current_network.channel;
279 if (ieee->data_hard_stop)
280 ieee->data_hard_stop(ieee->dev);
282 ieee80211_stop_send_beacons(ieee);
284 ieee->state = IEEE80211_LINKED_SCANNING;
285 ieee->link_change(ieee->dev);
287 ieee80211_start_scan_syncro(ieee);
289 ieee->set_chan(ieee->dev, chan);
291 ieee->state = IEEE80211_LINKED;
292 ieee->link_change(ieee->dev);
294 if (ieee->data_hard_resume)
295 ieee->data_hard_resume(ieee->dev);
297 if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
298 ieee80211_start_send_beacons(ieee);
300 //YJ,add,080828, In prevent of lossing ping packet during scanning
301 //ieee80211_sta_ps_send_null_frame(ieee, false);
308 int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
309 union iwreq_data *wrqu, char *b)
315 if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) {
320 //In prevent of lossing ping packet during scanning
321 //ieee80211_sta_ps_send_null_frame(ieee, true);
324 if (ieee->state == IEEE80211_LINKED) {
325 queue_work(ieee->wq, &ieee->wx_sync_scan_wq);
326 /* intentionally forget to up sem */
335 int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
336 struct iw_request_info *a,
337 union iwreq_data *wrqu, char *extra)
344 ieee->sync_scan_hurryup = 1;
348 proto_started = ieee->proto_started;
350 if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
355 if (ieee->iw_mode == IW_MODE_MONITOR) {
361 ieee80211_stop_protocol(ieee);
363 /* this is just to be sure that the GET wx callback
364 * has consistent infos. not needed otherwise
366 spin_lock_irqsave(&ieee->lock, flags);
368 if (wrqu->essid.flags && wrqu->essid.length) {
370 len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length) : IW_ESSID_MAX_SIZE;
371 memset(ieee->current_network.ssid, 0, ieee->current_network.ssid_len); //YJ,add,080819
372 strncpy(ieee->current_network.ssid, extra, len);
373 ieee->current_network.ssid_len = len;
375 //YJ,modified,080819,end
377 //YJ,add,080819,for hidden ap
379 memset(ieee->current_network.bssid, 0, ETH_ALEN);
380 ieee->current_network.capability = 0;
382 //YJ,add,080819,for hidden ap,end
385 ieee->current_network.ssid[0] = '\0';
386 ieee->current_network.ssid_len = 0;
388 //printk("==========set essid %s!\n",ieee->current_network.ssid);
389 spin_unlock_irqrestore(&ieee->lock, flags);
392 ieee80211_start_protocol(ieee);
398 int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
399 union iwreq_data *wrqu, char *b)
402 wrqu->mode = ieee->iw_mode;
406 int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
407 struct iw_request_info *info,
408 union iwreq_data *wrqu, char *extra)
411 int *parms = (int *)extra;
412 int enable = (parms[0] > 0);
413 short prev = ieee->raw_tx;
422 netdev_info(ieee->dev, "raw TX is %s\n",
423 ieee->raw_tx ? "enabled" : "disabled");
425 if (ieee->iw_mode == IW_MODE_MONITOR) {
426 if (prev == 0 && ieee->raw_tx) {
427 if (ieee->data_hard_resume)
428 ieee->data_hard_resume(ieee->dev);
430 netif_carrier_on(ieee->dev);
433 if (prev && ieee->raw_tx == 1)
434 netif_carrier_off(ieee->dev);
442 int ieee80211_wx_get_name(struct ieee80211_device *ieee,
443 struct iw_request_info *info,
444 union iwreq_data *wrqu, char *extra)
446 strlcpy(wrqu->name, "802.11", IFNAMSIZ);
447 if (ieee->modulation & IEEE80211_CCK_MODULATION) {
448 strlcat(wrqu->name, "b", IFNAMSIZ);
449 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
450 strlcat(wrqu->name, "/g", IFNAMSIZ);
451 } else if (ieee->modulation & IEEE80211_OFDM_MODULATION)
452 strlcat(wrqu->name, "g", IFNAMSIZ);
454 if ((ieee->state == IEEE80211_LINKED) ||
455 (ieee->state == IEEE80211_LINKED_SCANNING))
456 strlcat(wrqu->name, " link", IFNAMSIZ);
457 else if (ieee->state != IEEE80211_NOLINK)
458 strlcat(wrqu->name, " .....", IFNAMSIZ);
465 /* this is mostly stolen from hostap */
466 int ieee80211_wx_set_power(struct ieee80211_device *ieee,
467 struct iw_request_info *info,
468 union iwreq_data *wrqu, char *extra)
472 if ((!ieee->sta_wake_up) ||
473 (!ieee->ps_request_tx_ack) ||
474 (!ieee->enter_sleep_state) ||
475 (!ieee->ps_is_queue_empty)) {
477 printk("ERROR. PS mode tried to be use but driver missed a callback\n\n");
484 if (wrqu->power.disabled) {
485 ieee->ps = IEEE80211_PS_DISABLED;
489 switch (wrqu->power.flags & IW_POWER_MODE) {
490 case IW_POWER_UNICAST_R:
491 ieee->ps = IEEE80211_PS_UNICAST;
495 ieee->ps = IEEE80211_PS_UNICAST | IEEE80211_PS_MBCAST;
499 ieee->ps = IEEE80211_PS_DISABLED;
507 if (wrqu->power.flags & IW_POWER_TIMEOUT) {
509 ieee->ps_timeout = wrqu->power.value / 1000;
510 printk("Timeout %d\n", ieee->ps_timeout);
513 if (wrqu->power.flags & IW_POWER_PERIOD) {
526 /* this is stolen from hostap */
527 int ieee80211_wx_get_power(struct ieee80211_device *ieee,
528 struct iw_request_info *info,
529 union iwreq_data *wrqu, char *extra)
535 if (ieee->ps == IEEE80211_PS_DISABLED) {
536 wrqu->power.disabled = 1;
540 wrqu->power.disabled = 0;
542 // if ((wrqu->power.flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
543 wrqu->power.flags = IW_POWER_TIMEOUT;
544 wrqu->power.value = ieee->ps_timeout * 1000;
546 // ret = -EOPNOTSUPP;
548 //wrqu->power.flags = IW_POWER_PERIOD;
549 //wrqu->power.value = ieee->current_network.dtim_period *
550 // ieee->current_network.beacon_interval * 1024;
554 if (ieee->ps & IEEE80211_PS_MBCAST)
555 wrqu->power.flags |= IW_POWER_ALL_R;
557 wrqu->power.flags |= IW_POWER_UNICAST_R;