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
19 /* FIXME: add A freqs */
21 const long rtllib_wlan_frequencies
[] = {
22 2412, 2417, 2422, 2427,
23 2432, 2437, 2442, 2447,
24 2452, 2457, 2462, 2467,
27 EXPORT_SYMBOL(rtllib_wlan_frequencies
);
30 int rtllib_wx_set_freq(struct rtllib_device
*ieee
, struct iw_request_info
*a
,
31 union iwreq_data
*wrqu
, char *b
)
34 struct iw_freq
*fwrq
= &wrqu
->freq
;
38 if (ieee
->iw_mode
== IW_MODE_INFRA
) {
43 /* if setting by freq convert to channel */
45 if ((fwrq
->m
>= (int) 2.412e8
&&
46 fwrq
->m
<= (int) 2.487e8
)) {
47 int f
= fwrq
->m
/ 100000;
50 while ((c
< 14) && (f
!= rtllib_wlan_frequencies
[c
]))
53 /* hack to fall through */
59 if (fwrq
->e
> 0 || fwrq
->m
> 14 || fwrq
->m
< 1) {
63 } else { /* Set the channel */
65 if (ieee
->active_channel_map
[fwrq
->m
] != 1) {
69 ieee
->current_network
.channel
= fwrq
->m
;
70 ieee
->set_chan(ieee
->dev
, ieee
->current_network
.channel
);
72 if (ieee
->iw_mode
== IW_MODE_ADHOC
||
73 ieee
->iw_mode
== IW_MODE_MASTER
)
74 if (ieee
->state
== RTLLIB_LINKED
) {
75 rtllib_stop_send_beacons(ieee
);
76 rtllib_start_send_beacons(ieee
);
85 EXPORT_SYMBOL(rtllib_wx_set_freq
);
88 int rtllib_wx_get_freq(struct rtllib_device
*ieee
,
89 struct iw_request_info
*a
,
90 union iwreq_data
*wrqu
, char *b
)
92 struct iw_freq
*fwrq
= &wrqu
->freq
;
94 if (ieee
->current_network
.channel
== 0)
96 fwrq
->m
= rtllib_wlan_frequencies
[ieee
->current_network
.channel
-1] *
101 EXPORT_SYMBOL(rtllib_wx_get_freq
);
103 int rtllib_wx_get_wap(struct rtllib_device
*ieee
,
104 struct iw_request_info
*info
,
105 union iwreq_data
*wrqu
, char *extra
)
109 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
111 if (ieee
->iw_mode
== IW_MODE_MONITOR
)
114 /* We want avoid to give to the user inconsistent infos*/
115 spin_lock_irqsave(&ieee
->lock
, flags
);
117 if (ieee
->state
!= RTLLIB_LINKED
&&
118 ieee
->state
!= RTLLIB_LINKED_SCANNING
&&
121 memset(wrqu
->ap_addr
.sa_data
, 0, ETH_ALEN
);
123 memcpy(wrqu
->ap_addr
.sa_data
,
124 ieee
->current_network
.bssid
, ETH_ALEN
);
126 spin_unlock_irqrestore(&ieee
->lock
, flags
);
130 EXPORT_SYMBOL(rtllib_wx_get_wap
);
133 int rtllib_wx_set_wap(struct rtllib_device
*ieee
,
134 struct iw_request_info
*info
,
135 union iwreq_data
*awrq
,
140 u8 zero
[] = {0, 0, 0, 0, 0, 0};
143 short ifup
= ieee
->proto_started
;
144 struct sockaddr
*temp
= (struct sockaddr
*)awrq
;
146 rtllib_stop_scan_syncro(ieee
);
149 /* use ifconfig hw ether */
150 if (ieee
->iw_mode
== IW_MODE_MASTER
) {
155 if (temp
->sa_family
!= ARPHRD_ETHER
) {
160 if (memcmp(temp
->sa_data
, zero
, ETH_ALEN
) == 0) {
161 spin_lock_irqsave(&ieee
->lock
, flags
);
162 memcpy(ieee
->current_network
.bssid
, temp
->sa_data
, ETH_ALEN
);
164 spin_unlock_irqrestore(&ieee
->lock
, flags
);
171 rtllib_stop_protocol(ieee
, true);
173 /* just to avoid to give inconsistent infos in the
174 * get wx method. not really needed otherwise
176 spin_lock_irqsave(&ieee
->lock
, flags
);
178 ieee
->cannot_notify
= false;
179 memcpy(ieee
->current_network
.bssid
, temp
->sa_data
, ETH_ALEN
);
180 ieee
->wap_set
= (memcmp(temp
->sa_data
, zero
, ETH_ALEN
) != 0);
182 spin_unlock_irqrestore(&ieee
->lock
, flags
);
185 rtllib_start_protocol(ieee
);
190 EXPORT_SYMBOL(rtllib_wx_set_wap
);
192 int rtllib_wx_get_essid(struct rtllib_device
*ieee
, struct iw_request_info
*a
,
193 union iwreq_data
*wrqu
, char *b
)
198 if (ieee
->iw_mode
== IW_MODE_MONITOR
)
201 /* We want avoid to give to the user inconsistent infos*/
202 spin_lock_irqsave(&ieee
->lock
, flags
);
204 if (ieee
->current_network
.ssid
[0] == '\0' ||
205 ieee
->current_network
.ssid_len
== 0) {
210 if (ieee
->state
!= RTLLIB_LINKED
&&
211 ieee
->state
!= RTLLIB_LINKED_SCANNING
&&
212 ieee
->ssid_set
== 0) {
216 len
= ieee
->current_network
.ssid_len
;
217 wrqu
->essid
.length
= len
;
218 strncpy(b
, ieee
->current_network
.ssid
, len
);
219 wrqu
->essid
.flags
= 1;
222 spin_unlock_irqrestore(&ieee
->lock
, flags
);
227 EXPORT_SYMBOL(rtllib_wx_get_essid
);
229 int rtllib_wx_set_rate(struct rtllib_device
*ieee
,
230 struct iw_request_info
*info
,
231 union iwreq_data
*wrqu
, char *extra
)
234 u32 target_rate
= wrqu
->bitrate
.value
;
236 ieee
->rate
= target_rate
/100000;
239 EXPORT_SYMBOL(rtllib_wx_set_rate
);
241 int rtllib_wx_get_rate(struct rtllib_device
*ieee
,
242 struct iw_request_info
*info
,
243 union iwreq_data
*wrqu
, char *extra
)
246 tmp_rate
= TxCountToDataRate(ieee
,
247 ieee
->softmac_stats
.CurrentShowTxate
);
248 wrqu
->bitrate
.value
= tmp_rate
* 500000;
252 EXPORT_SYMBOL(rtllib_wx_get_rate
);
255 int rtllib_wx_set_rts(struct rtllib_device
*ieee
,
256 struct iw_request_info
*info
,
257 union iwreq_data
*wrqu
, char *extra
)
259 if (wrqu
->rts
.disabled
|| !wrqu
->rts
.fixed
)
260 ieee
->rts
= DEFAULT_RTS_THRESHOLD
;
262 if (wrqu
->rts
.value
< MIN_RTS_THRESHOLD
||
263 wrqu
->rts
.value
> MAX_RTS_THRESHOLD
)
265 ieee
->rts
= wrqu
->rts
.value
;
269 EXPORT_SYMBOL(rtllib_wx_set_rts
);
271 int rtllib_wx_get_rts(struct rtllib_device
*ieee
,
272 struct iw_request_info
*info
,
273 union iwreq_data
*wrqu
, char *extra
)
275 wrqu
->rts
.value
= ieee
->rts
;
276 wrqu
->rts
.fixed
= 0; /* no auto select */
277 wrqu
->rts
.disabled
= (wrqu
->rts
.value
== DEFAULT_RTS_THRESHOLD
);
280 EXPORT_SYMBOL(rtllib_wx_get_rts
);
282 int rtllib_wx_set_mode(struct rtllib_device
*ieee
, struct iw_request_info
*a
,
283 union iwreq_data
*wrqu
, char *b
)
285 int set_mode_status
= 0;
287 rtllib_stop_scan_syncro(ieee
);
289 switch (wrqu
->mode
) {
290 case IW_MODE_MONITOR
:
295 wrqu
->mode
= IW_MODE_INFRA
;
298 set_mode_status
= -EINVAL
;
302 if (wrqu
->mode
== ieee
->iw_mode
)
305 if (wrqu
->mode
== IW_MODE_MONITOR
) {
306 ieee
->dev
->type
= ARPHRD_IEEE80211
;
307 rtllib_EnableNetMonitorMode(ieee
->dev
, false);
309 ieee
->dev
->type
= ARPHRD_ETHER
;
310 if (ieee
->iw_mode
== IW_MODE_MONITOR
)
311 rtllib_DisableNetMonitorMode(ieee
->dev
, false);
314 if (!ieee
->proto_started
) {
315 ieee
->iw_mode
= wrqu
->mode
;
317 rtllib_stop_protocol(ieee
, true);
318 ieee
->iw_mode
= wrqu
->mode
;
319 rtllib_start_protocol(ieee
);
324 return set_mode_status
;
326 EXPORT_SYMBOL(rtllib_wx_set_mode
);
328 void rtllib_wx_sync_scan_wq(void *data
)
330 struct rtllib_device
*ieee
= container_of_work_rsl(data
,
331 struct rtllib_device
, wx_sync_scan_wq
);
333 enum ht_extchnl_offset chan_offset
= 0;
334 enum ht_channel_width bandwidth
= 0;
338 if (!(ieee
->softmac_features
& IEEE_SOFTMAC_SCAN
)) {
339 rtllib_start_scan_syncro(ieee
, 0);
343 chan
= ieee
->current_network
.channel
;
345 if (ieee
->LeisurePSLeave
)
346 ieee
->LeisurePSLeave(ieee
->dev
);
347 /* notify AP to be in PS mode */
348 rtllib_sta_ps_send_null_frame(ieee
, 1);
349 rtllib_sta_ps_send_null_frame(ieee
, 1);
351 rtllib_stop_all_queues(ieee
);
353 if (ieee
->data_hard_stop
)
354 ieee
->data_hard_stop(ieee
->dev
);
355 rtllib_stop_send_beacons(ieee
);
356 ieee
->state
= RTLLIB_LINKED_SCANNING
;
357 ieee
->link_change(ieee
->dev
);
358 /* wait for ps packet to be kicked out successfully */
361 if (ieee
->ScanOperationBackupHandler
)
362 ieee
->ScanOperationBackupHandler(ieee
->dev
, SCAN_OPT_BACKUP
);
364 if (ieee
->pHTInfo
->bCurrentHTSupport
&& ieee
->pHTInfo
->bEnableHT
&&
365 ieee
->pHTInfo
->bCurBW40MHz
) {
367 chan_offset
= ieee
->pHTInfo
->CurSTAExtChnlOffset
;
368 bandwidth
= (enum ht_channel_width
)ieee
->pHTInfo
->bCurBW40MHz
;
369 RT_TRACE(COMP_DBG
, "Scan in 40M, force to 20M first:%d, %d\n",
370 chan_offset
, bandwidth
);
371 ieee
->SetBWModeHandler(ieee
->dev
, HT_CHANNEL_WIDTH_20
,
372 HT_EXTCHNL_OFFSET_NO_EXT
);
375 rtllib_start_scan_syncro(ieee
, 0);
378 RT_TRACE(COMP_DBG
, "Scan in 20M, back to 40M\n");
379 if (chan_offset
== HT_EXTCHNL_OFFSET_UPPER
)
380 ieee
->set_chan(ieee
->dev
, chan
+ 2);
381 else if (chan_offset
== HT_EXTCHNL_OFFSET_LOWER
)
382 ieee
->set_chan(ieee
->dev
, chan
- 2);
384 ieee
->set_chan(ieee
->dev
, chan
);
385 ieee
->SetBWModeHandler(ieee
->dev
, bandwidth
, chan_offset
);
387 ieee
->set_chan(ieee
->dev
, chan
);
390 if (ieee
->ScanOperationBackupHandler
)
391 ieee
->ScanOperationBackupHandler(ieee
->dev
, SCAN_OPT_RESTORE
);
393 ieee
->state
= RTLLIB_LINKED
;
394 ieee
->link_change(ieee
->dev
);
396 /* Notify AP that I wake up again */
397 rtllib_sta_ps_send_null_frame(ieee
, 0);
399 if (ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
== 0 ||
400 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
== 0) {
401 ieee
->LinkDetectInfo
.NumRecvBcnInPeriod
= 1;
402 ieee
->LinkDetectInfo
.NumRecvDataInPeriod
= 1;
405 if (ieee
->data_hard_resume
)
406 ieee
->data_hard_resume(ieee
->dev
);
408 if (ieee
->iw_mode
== IW_MODE_ADHOC
|| ieee
->iw_mode
== IW_MODE_MASTER
)
409 rtllib_start_send_beacons(ieee
);
411 rtllib_wake_all_queues(ieee
);
419 int rtllib_wx_set_scan(struct rtllib_device
*ieee
, struct iw_request_info
*a
,
420 union iwreq_data
*wrqu
, char *b
)
426 if (ieee
->iw_mode
== IW_MODE_MONITOR
|| !(ieee
->proto_started
)) {
431 if (ieee
->state
== RTLLIB_LINKED
) {
432 queue_work_rsl(ieee
->wq
, &ieee
->wx_sync_scan_wq
);
433 /* intentionally forget to up sem */
441 EXPORT_SYMBOL(rtllib_wx_set_scan
);
443 int rtllib_wx_set_essid(struct rtllib_device
*ieee
,
444 struct iw_request_info
*a
,
445 union iwreq_data
*wrqu
, char *extra
)
452 rtllib_stop_scan_syncro(ieee
);
455 proto_started
= ieee
->proto_started
;
457 len
= (wrqu
->essid
.length
< IW_ESSID_MAX_SIZE
) ? wrqu
->essid
.length
:
460 if (len
> IW_ESSID_MAX_SIZE
) {
465 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
470 for (i
= 0; i
< len
; i
++) {
478 rtllib_stop_protocol(ieee
, true);
481 /* this is just to be sure that the GET wx callback
482 * has consistent infos. not needed otherwise
484 spin_lock_irqsave(&ieee
->lock
, flags
);
486 if (wrqu
->essid
.flags
&& wrqu
->essid
.length
) {
487 strncpy(ieee
->current_network
.ssid
, extra
, len
);
488 ieee
->current_network
.ssid_len
= len
;
489 ieee
->cannot_notify
= false;
493 ieee
->current_network
.ssid
[0] = '\0';
494 ieee
->current_network
.ssid_len
= 0;
496 spin_unlock_irqrestore(&ieee
->lock
, flags
);
499 rtllib_start_protocol(ieee
);
504 EXPORT_SYMBOL(rtllib_wx_set_essid
);
506 int rtllib_wx_get_mode(struct rtllib_device
*ieee
, struct iw_request_info
*a
,
507 union iwreq_data
*wrqu
, char *b
)
509 wrqu
->mode
= ieee
->iw_mode
;
512 EXPORT_SYMBOL(rtllib_wx_get_mode
);
514 int rtllib_wx_set_rawtx(struct rtllib_device
*ieee
,
515 struct iw_request_info
*info
,
516 union iwreq_data
*wrqu
, char *extra
)
519 int *parms
= (int *)extra
;
520 int enable
= (parms
[0] > 0);
521 short prev
= ieee
->raw_tx
;
530 printk(KERN_INFO
"raw TX is %s\n",
531 ieee
->raw_tx
? "enabled" : "disabled");
533 if (ieee
->iw_mode
== IW_MODE_MONITOR
) {
534 if (prev
== 0 && ieee
->raw_tx
) {
535 if (ieee
->data_hard_resume
)
536 ieee
->data_hard_resume(ieee
->dev
);
538 netif_carrier_on(ieee
->dev
);
541 if (prev
&& ieee
->raw_tx
== 1)
542 netif_carrier_off(ieee
->dev
);
549 EXPORT_SYMBOL(rtllib_wx_set_rawtx
);
551 int rtllib_wx_get_name(struct rtllib_device
*ieee
,
552 struct iw_request_info
*info
,
553 union iwreq_data
*wrqu
, char *extra
)
555 strcpy(wrqu
->name
, "802.11");
557 if (ieee
->modulation
& RTLLIB_CCK_MODULATION
)
558 strcat(wrqu
->name
, "b");
559 if (ieee
->modulation
& RTLLIB_OFDM_MODULATION
)
560 strcat(wrqu
->name
, "g");
561 if (ieee
->mode
& (IEEE_N_24G
| IEEE_N_5G
))
562 strcat(wrqu
->name
, "n");
565 EXPORT_SYMBOL(rtllib_wx_get_name
);
568 /* this is mostly stolen from hostap */
569 int rtllib_wx_set_power(struct rtllib_device
*ieee
,
570 struct iw_request_info
*info
,
571 union iwreq_data
*wrqu
, char *extra
)
575 if ((!ieee
->sta_wake_up
) ||
576 (!ieee
->enter_sleep_state
) ||
577 (!ieee
->ps_is_queue_empty
)) {
578 RTLLIB_DEBUG(RTLLIB_DL_ERR
, "%s(): PS mode is tried to be use "
579 "but driver missed a callback\n\n", __func__
);
585 if (wrqu
->power
.disabled
) {
586 RT_TRACE(COMP_DBG
, "===>%s(): power disable\n", __func__
);
587 ieee
->ps
= RTLLIB_PS_DISABLED
;
590 if (wrqu
->power
.flags
& IW_POWER_TIMEOUT
) {
591 ieee
->ps_timeout
= wrqu
->power
.value
/ 1000;
592 RT_TRACE(COMP_DBG
, "===>%s():ps_timeout is %d\n", __func__
,
596 if (wrqu
->power
.flags
& IW_POWER_PERIOD
)
597 ieee
->ps_period
= wrqu
->power
.value
/ 1000;
599 switch (wrqu
->power
.flags
& IW_POWER_MODE
) {
600 case IW_POWER_UNICAST_R
:
601 ieee
->ps
= RTLLIB_PS_UNICAST
;
603 case IW_POWER_MULTICAST_R
:
604 ieee
->ps
= RTLLIB_PS_MBCAST
;
607 ieee
->ps
= RTLLIB_PS_UNICAST
| RTLLIB_PS_MBCAST
;
623 EXPORT_SYMBOL(rtllib_wx_set_power
);
625 /* this is stolen from hostap */
626 int rtllib_wx_get_power(struct rtllib_device
*ieee
,
627 struct iw_request_info
*info
,
628 union iwreq_data
*wrqu
, char *extra
)
634 if (ieee
->ps
== RTLLIB_PS_DISABLED
) {
635 wrqu
->power
.disabled
= 1;
639 wrqu
->power
.disabled
= 0;
641 if ((wrqu
->power
.flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
642 wrqu
->power
.flags
= IW_POWER_TIMEOUT
;
643 wrqu
->power
.value
= ieee
->ps_timeout
* 1000;
645 wrqu
->power
.flags
= IW_POWER_PERIOD
;
646 wrqu
->power
.value
= ieee
->ps_period
* 1000;
649 if ((ieee
->ps
& (RTLLIB_PS_MBCAST
| RTLLIB_PS_UNICAST
)) ==
650 (RTLLIB_PS_MBCAST
| RTLLIB_PS_UNICAST
))
651 wrqu
->power
.flags
|= IW_POWER_ALL_R
;
652 else if (ieee
->ps
& RTLLIB_PS_MBCAST
)
653 wrqu
->power
.flags
|= IW_POWER_MULTICAST_R
;
655 wrqu
->power
.flags
|= IW_POWER_UNICAST_R
;
662 EXPORT_SYMBOL(rtllib_wx_get_power
);