2 * Implement cfg80211 ("iw") support.
4 * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
5 * Holger Schurig <hs4233@mail.mn-solutions.de>
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/hardirq.h>
12 #include <linux/sched.h>
13 #include <linux/wait.h>
14 #include <linux/slab.h>
15 #include <linux/ieee80211.h>
16 #include <net/cfg80211.h>
17 #include <asm/unaligned.h>
24 #define CHAN2G(_channel, _freq, _flags) { \
25 .band = IEEE80211_BAND_2GHZ, \
26 .center_freq = (_freq), \
27 .hw_value = (_channel), \
29 .max_antenna_gain = 0, \
33 static struct ieee80211_channel lbs_2ghz_channels
[] = {
50 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
52 .hw_value = (_hw_value), \
57 /* Table 6 in section 3.2.1.1 */
58 static struct ieee80211_rate lbs_rates
[] = {
59 RATETAB_ENT(10, 0, 0),
60 RATETAB_ENT(20, 1, 0),
61 RATETAB_ENT(55, 2, 0),
62 RATETAB_ENT(110, 3, 0),
63 RATETAB_ENT(60, 9, 0),
64 RATETAB_ENT(90, 6, 0),
65 RATETAB_ENT(120, 7, 0),
66 RATETAB_ENT(180, 8, 0),
67 RATETAB_ENT(240, 9, 0),
68 RATETAB_ENT(360, 10, 0),
69 RATETAB_ENT(480, 11, 0),
70 RATETAB_ENT(540, 12, 0),
73 static struct ieee80211_supported_band lbs_band_2ghz
= {
74 .channels
= lbs_2ghz_channels
,
75 .n_channels
= ARRAY_SIZE(lbs_2ghz_channels
),
76 .bitrates
= lbs_rates
,
77 .n_bitrates
= ARRAY_SIZE(lbs_rates
),
81 static const u32 cipher_suites
[] = {
82 WLAN_CIPHER_SUITE_WEP40
,
83 WLAN_CIPHER_SUITE_WEP104
,
84 WLAN_CIPHER_SUITE_TKIP
,
85 WLAN_CIPHER_SUITE_CCMP
,
88 /* Time to stay on the channel */
89 #define LBS_DWELL_PASSIVE 100
90 #define LBS_DWELL_ACTIVE 40
93 /***************************************************************************
94 * Misc utility functions
96 * TLVs are Marvell specific. They are very similar to IEs, they have the
97 * same structure: type, length, data*. The only difference: for IEs, the
98 * type and length are u8, but for TLVs they're __le16.
102 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
103 * in the firmware spec
105 static u8
lbs_auth_to_authtype(enum nl80211_auth_type auth_type
)
110 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
111 case NL80211_AUTHTYPE_SHARED_KEY
:
114 case NL80211_AUTHTYPE_AUTOMATIC
:
115 ret
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
117 case NL80211_AUTHTYPE_NETWORK_EAP
:
121 /* silence compiler */
129 * Various firmware commands need the list of supported rates, but with
130 * the hight-bit set for basic rates
132 static int lbs_add_rates(u8
*rates
)
136 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
137 u8 rate
= lbs_rates
[i
].bitrate
/ 5;
138 if (rate
== 0x02 || rate
== 0x04 ||
139 rate
== 0x0b || rate
== 0x16)
143 return ARRAY_SIZE(lbs_rates
);
147 /***************************************************************************
148 * TLV utility functions
150 * TLVs are Marvell specific. They are very similar to IEs, they have the
151 * same structure: type, length, data*. The only difference: for IEs, the
152 * type and length are u8, but for TLVs they're __le16.
159 #define LBS_MAX_SSID_TLV_SIZE \
160 (sizeof(struct mrvl_ie_header) \
161 + IEEE80211_MAX_SSID_LEN)
163 static int lbs_add_ssid_tlv(u8
*tlv
, const u8
*ssid
, int ssid_len
)
165 struct mrvl_ie_ssid_param_set
*ssid_tlv
= (void *)tlv
;
170 * ssid 4d 4e 54 45 53 54
172 ssid_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
173 ssid_tlv
->header
.len
= cpu_to_le16(ssid_len
);
174 memcpy(ssid_tlv
->ssid
, ssid
, ssid_len
);
175 return sizeof(ssid_tlv
->header
) + ssid_len
;
180 * Add channel list TLV (section 8.4.2)
182 * Actual channel data comes from priv->wdev->wiphy->channels.
184 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
185 (sizeof(struct mrvl_ie_header) \
186 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
188 static int lbs_add_channel_list_tlv(struct lbs_private
*priv
, u8
*tlv
,
189 int last_channel
, int active_scan
)
191 int chanscanparamsize
= sizeof(struct chanscanparamset
) *
192 (last_channel
- priv
->scan_channel
);
194 struct mrvl_ie_header
*header
= (void *) tlv
;
197 * TLV-ID CHANLIST 01 01
199 * channel 00 01 00 00 00 64 00
203 * min scan time 00 00
204 * max scan time 64 00
205 * channel 2 00 02 00 00 00 64 00
209 header
->type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
210 header
->len
= cpu_to_le16(chanscanparamsize
);
211 tlv
+= sizeof(struct mrvl_ie_header
);
213 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
215 memset(tlv
, 0, chanscanparamsize
);
217 while (priv
->scan_channel
< last_channel
) {
218 struct chanscanparamset
*param
= (void *) tlv
;
220 param
->radiotype
= CMD_SCAN_RADIO_TYPE_BG
;
222 priv
->scan_req
->channels
[priv
->scan_channel
]->hw_value
;
224 param
->maxscantime
= cpu_to_le16(LBS_DWELL_ACTIVE
);
226 param
->chanscanmode
.passivescan
= 1;
227 param
->maxscantime
= cpu_to_le16(LBS_DWELL_PASSIVE
);
229 tlv
+= sizeof(struct chanscanparamset
);
230 priv
->scan_channel
++;
232 return sizeof(struct mrvl_ie_header
) + chanscanparamsize
;
239 * The rates are in lbs_bg_rates[], but for the 802.11b
240 * rates the high bit is set. We add this TLV only because
241 * there's a firmware which otherwise doesn't report all
244 #define LBS_MAX_RATES_TLV_SIZE \
245 (sizeof(struct mrvl_ie_header) \
246 + (ARRAY_SIZE(lbs_rates)))
248 /* Adds a TLV with all rates the hardware supports */
249 static int lbs_add_supported_rates_tlv(u8
*tlv
)
252 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
257 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
259 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
260 tlv
+= sizeof(rate_tlv
->header
);
261 i
= lbs_add_rates(tlv
);
263 rate_tlv
->header
.len
= cpu_to_le16(i
);
264 return sizeof(rate_tlv
->header
) + i
;
267 /* Add common rates from a TLV and return the new end of the TLV */
269 add_ie_rates(u8
*tlv
, const u8
*ie
, int *nrates
)
271 int hw
, ap
, ap_max
= ie
[1];
274 /* Advance past IE header */
277 lbs_deb_hex(LBS_DEB_ASSOC
, "AP IE Rates", (u8
*) ie
, ap_max
);
279 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
280 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
281 for (ap
= 0; ap
< ap_max
; ap
++) {
282 if (hw_rate
== (ie
[ap
] & 0x7f)) {
284 *nrates
= *nrates
+ 1;
292 * Adds a TLV with all rates the hardware *and* BSS supports.
294 static int lbs_add_common_rates_tlv(u8
*tlv
, struct cfg80211_bss
*bss
)
296 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
297 const u8
*rates_eid
, *ext_rates_eid
;
300 rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
301 ext_rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_EXT_SUPP_RATES
);
304 * 01 00 TLV_TYPE_RATES
308 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
309 tlv
+= sizeof(rate_tlv
->header
);
311 /* Add basic rates */
313 tlv
= add_ie_rates(tlv
, rates_eid
, &n
);
315 /* Add extended rates, if any */
317 tlv
= add_ie_rates(tlv
, ext_rates_eid
, &n
);
319 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
320 /* Fallback: add basic 802.11b rates */
328 rate_tlv
->header
.len
= cpu_to_le16(n
);
329 return sizeof(rate_tlv
->header
) + n
;
336 * This is only needed for newer firmware (V9 and up).
338 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
339 sizeof(struct mrvl_ie_auth_type)
341 static int lbs_add_auth_type_tlv(u8
*tlv
, enum nl80211_auth_type auth_type
)
343 struct mrvl_ie_auth_type
*auth
= (void *) tlv
;
346 * 1f 01 TLV_TYPE_AUTH_TYPE
350 auth
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
351 auth
->header
.len
= cpu_to_le16(sizeof(*auth
)-sizeof(auth
->header
));
352 auth
->auth
= cpu_to_le16(lbs_auth_to_authtype(auth_type
));
353 return sizeof(*auth
);
358 * Add channel (phy ds) TLV
360 #define LBS_MAX_CHANNEL_TLV_SIZE \
361 sizeof(struct mrvl_ie_header)
363 static int lbs_add_channel_tlv(u8
*tlv
, u8 channel
)
365 struct mrvl_ie_ds_param_set
*ds
= (void *) tlv
;
368 * 03 00 TLV_TYPE_PHY_DS
372 ds
->header
.type
= cpu_to_le16(TLV_TYPE_PHY_DS
);
373 ds
->header
.len
= cpu_to_le16(sizeof(*ds
)-sizeof(ds
->header
));
374 ds
->channel
= channel
;
380 * Add (empty) CF param TLV of the form:
382 #define LBS_MAX_CF_PARAM_TLV_SIZE \
383 sizeof(struct mrvl_ie_header)
385 static int lbs_add_cf_param_tlv(u8
*tlv
)
387 struct mrvl_ie_cf_param_set
*cf
= (void *)tlv
;
394 * 00 00 cfpmaxduration
395 * 00 00 cfpdurationremaining
397 cf
->header
.type
= cpu_to_le16(TLV_TYPE_CF
);
398 cf
->header
.len
= cpu_to_le16(sizeof(*cf
)-sizeof(cf
->header
));
405 #define LBS_MAX_WPA_TLV_SIZE \
406 (sizeof(struct mrvl_ie_header) \
407 + 128 /* TODO: I guessed the size */)
409 static int lbs_add_wpa_tlv(u8
*tlv
, const u8
*ie
, u8 ie_len
)
414 * We need just convert an IE to an TLV. IEs use u8 for the header,
418 * but TLVs use __le16 instead:
425 tlv_len
= *tlv
++ = *ie
++;
429 /* the TLV is two bytes larger than the IE */
437 static int lbs_cfg_set_channel(struct wiphy
*wiphy
,
438 struct net_device
*netdev
,
439 struct ieee80211_channel
*channel
,
440 enum nl80211_channel_type channel_type
)
442 struct lbs_private
*priv
= wiphy_priv(wiphy
);
445 lbs_deb_enter_args(LBS_DEB_CFG80211
, "freq %d, type %d",
446 channel
->center_freq
, channel_type
);
448 if (channel_type
!= NL80211_CHAN_NO_HT
)
451 ret
= lbs_set_channel(priv
, channel
->hw_value
);
454 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
465 * When scanning, the firmware doesn't send a nul packet with the power-safe
466 * bit to the AP. So we cannot stay away from our current channel too long,
467 * otherwise we loose data. So take a "nap" while scanning every other
470 #define LBS_SCAN_BEFORE_NAP 4
474 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
475 * which isn't really an RSSI, as it becomes larger when moving away from
476 * the AP. Anyway, we need to convert that into mBm.
478 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
479 ((-(int)rssi + 3)*100)
481 static int lbs_ret_scan(struct lbs_private
*priv
, unsigned long dummy
,
482 struct cmd_header
*resp
)
484 struct cmd_ds_802_11_scan_rsp
*scanresp
= (void *)resp
;
492 lbs_deb_enter(LBS_DEB_CFG80211
);
494 bsssize
= get_unaligned_le16(&scanresp
->bssdescriptsize
);
496 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
497 scanresp
->nr_sets
, bsssize
, le16_to_cpu(resp
->size
));
499 if (scanresp
->nr_sets
== 0) {
505 * The general layout of the scan response is described in chapter
506 * 5.7.1. Basically we have a common part, then any number of BSS
507 * descriptor sections. Finally we have section with the same number
510 * cmd_ds_802_11_scan_rsp
523 * MrvlIEtypes_TsfFimestamp_t
529 pos
= scanresp
->bssdesc_and_tlvbuffer
;
531 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_RSP", scanresp
->bssdesc_and_tlvbuffer
,
532 scanresp
->bssdescriptsize
);
534 tsfdesc
= pos
+ bsssize
;
535 tsfsize
= 4 + 8 * scanresp
->nr_sets
;
536 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TSF", (u8
*) tsfdesc
, tsfsize
);
538 /* Validity check: we expect a Marvell-Local TLV */
539 i
= get_unaligned_le16(tsfdesc
);
541 if (i
!= TLV_TYPE_TSFTIMESTAMP
) {
542 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i
);
547 * Validity check: the TLV holds TSF values with 8 bytes each, so
548 * the size in the TLV must match the nr_sets value
550 i
= get_unaligned_le16(tsfdesc
);
552 if (i
/ 8 != scanresp
->nr_sets
) {
553 lbs_deb_scan("scan response: invalid number of TSF timestamp "
554 "sets (expected %d got %d)\n", scanresp
->nr_sets
,
559 for (i
= 0; i
< scanresp
->nr_sets
; i
++) {
568 const u8
*ssid
= NULL
;
570 DECLARE_SSID_BUF(ssid_buf
);
572 int len
= get_unaligned_le16(pos
);
580 /* Packet time stamp */
582 /* Beacon interval */
583 intvl
= get_unaligned_le16(pos
);
586 capa
= get_unaligned_le16(pos
);
589 /* To find out the channel, we must parse the IEs */
592 * 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
593 * interval, capabilities
595 ielen
= left
= len
- (6 + 1 + 8 + 2 + 2);
601 if (elen
> left
|| elen
== 0) {
602 lbs_deb_scan("scan response: invalid IE fmt\n");
606 if (id
== WLAN_EID_DS_PARAMS
)
608 if (id
== WLAN_EID_SSID
) {
616 /* No channel, no luck */
618 struct wiphy
*wiphy
= priv
->wdev
->wiphy
;
619 int freq
= ieee80211_channel_to_frequency(chan_no
,
620 IEEE80211_BAND_2GHZ
);
621 struct ieee80211_channel
*channel
=
622 ieee80211_get_channel(wiphy
, freq
);
624 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
626 bssid
, capa
, chan_no
,
627 print_ssid(ssid_buf
, ssid
, ssid_len
),
628 LBS_SCAN_RSSI_TO_MBM(rssi
)/100);
631 !(channel
->flags
& IEEE80211_CHAN_DISABLED
))
632 cfg80211_inform_bss(wiphy
, channel
,
633 bssid
, le64_to_cpu(*(__le64
*)tsfdesc
),
634 capa
, intvl
, ie
, ielen
,
635 LBS_SCAN_RSSI_TO_MBM(rssi
),
638 lbs_deb_scan("scan response: missing BSS channel IE\n");
645 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
651 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
652 * TLV and a rates TLV. Determine the maximum size of them:
654 #define LBS_SCAN_MAX_CMD_SIZE \
655 (sizeof(struct cmd_ds_802_11_scan) \
656 + LBS_MAX_SSID_TLV_SIZE \
657 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
658 + LBS_MAX_RATES_TLV_SIZE)
661 * Assumes priv->scan_req is initialized and valid
662 * Assumes priv->scan_channel is initialized
664 static void lbs_scan_worker(struct work_struct
*work
)
666 struct lbs_private
*priv
=
667 container_of(work
, struct lbs_private
, scan_work
.work
);
668 struct cmd_ds_802_11_scan
*scan_cmd
;
669 u8
*tlv
; /* pointer into our current, growing TLV storage area */
671 int running
, carrier
;
673 lbs_deb_enter(LBS_DEB_SCAN
);
675 scan_cmd
= kzalloc(LBS_SCAN_MAX_CMD_SIZE
, GFP_KERNEL
);
676 if (scan_cmd
== NULL
)
677 goto out_no_scan_cmd
;
679 /* prepare fixed part of scan command */
680 scan_cmd
->bsstype
= CMD_BSS_TYPE_ANY
;
682 /* stop network while we're away from our main channel */
683 running
= !netif_queue_stopped(priv
->dev
);
684 carrier
= netif_carrier_ok(priv
->dev
);
686 netif_stop_queue(priv
->dev
);
688 netif_carrier_off(priv
->dev
);
690 /* prepare fixed part of scan command */
691 tlv
= scan_cmd
->tlvbuffer
;
694 if (priv
->scan_req
->n_ssids
)
695 tlv
+= lbs_add_ssid_tlv(tlv
,
696 priv
->scan_req
->ssids
[0].ssid
,
697 priv
->scan_req
->ssids
[0].ssid_len
);
699 /* add channel TLVs */
700 last_channel
= priv
->scan_channel
+ LBS_SCAN_BEFORE_NAP
;
701 if (last_channel
> priv
->scan_req
->n_channels
)
702 last_channel
= priv
->scan_req
->n_channels
;
703 tlv
+= lbs_add_channel_list_tlv(priv
, tlv
, last_channel
,
704 priv
->scan_req
->n_ssids
);
707 tlv
+= lbs_add_supported_rates_tlv(tlv
);
709 if (priv
->scan_channel
< priv
->scan_req
->n_channels
) {
710 cancel_delayed_work(&priv
->scan_work
);
712 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
713 msecs_to_jiffies(300));
716 /* This is the final data we are about to send */
717 scan_cmd
->hdr
.size
= cpu_to_le16(tlv
- (u8
*)scan_cmd
);
718 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_CMD", (void *)scan_cmd
,
720 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TLV", scan_cmd
->tlvbuffer
,
721 tlv
- scan_cmd
->tlvbuffer
);
723 __lbs_cmd(priv
, CMD_802_11_SCAN
, &scan_cmd
->hdr
,
724 le16_to_cpu(scan_cmd
->hdr
.size
),
727 if (priv
->scan_channel
>= priv
->scan_req
->n_channels
) {
729 if (priv
->internal_scan
)
730 kfree(priv
->scan_req
);
732 cfg80211_scan_done(priv
->scan_req
, false);
734 priv
->scan_req
= NULL
;
735 priv
->last_scan
= jiffies
;
738 /* Restart network */
740 netif_carrier_on(priv
->dev
);
741 if (running
&& !priv
->tx_pending_len
)
742 netif_wake_queue(priv
->dev
);
746 /* Wake up anything waiting on scan completion */
747 if (priv
->scan_req
== NULL
) {
748 lbs_deb_scan("scan: waking up waiters\n");
749 wake_up_all(&priv
->scan_q
);
753 lbs_deb_leave(LBS_DEB_SCAN
);
756 static void _internal_start_scan(struct lbs_private
*priv
, bool internal
,
757 struct cfg80211_scan_request
*request
)
759 lbs_deb_enter(LBS_DEB_CFG80211
);
761 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
762 request
->n_ssids
, request
->n_channels
, request
->ie_len
);
764 priv
->scan_channel
= 0;
765 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
766 msecs_to_jiffies(50));
768 priv
->scan_req
= request
;
769 priv
->internal_scan
= internal
;
771 lbs_deb_leave(LBS_DEB_CFG80211
);
774 static int lbs_cfg_scan(struct wiphy
*wiphy
,
775 struct net_device
*dev
,
776 struct cfg80211_scan_request
*request
)
778 struct lbs_private
*priv
= wiphy_priv(wiphy
);
781 lbs_deb_enter(LBS_DEB_CFG80211
);
783 if (priv
->scan_req
|| delayed_work_pending(&priv
->scan_work
)) {
784 /* old scan request not yet processed */
789 _internal_start_scan(priv
, false, request
);
791 if (priv
->surpriseremoved
)
795 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
806 void lbs_send_disconnect_notification(struct lbs_private
*priv
)
808 lbs_deb_enter(LBS_DEB_CFG80211
);
810 cfg80211_disconnected(priv
->dev
,
815 lbs_deb_leave(LBS_DEB_CFG80211
);
818 void lbs_send_mic_failureevent(struct lbs_private
*priv
, u32 event
)
820 lbs_deb_enter(LBS_DEB_CFG80211
);
822 cfg80211_michael_mic_failure(priv
->dev
,
824 event
== MACREG_INT_CODE_MIC_ERR_MULTICAST
?
825 NL80211_KEYTYPE_GROUP
:
826 NL80211_KEYTYPE_PAIRWISE
,
831 lbs_deb_leave(LBS_DEB_CFG80211
);
843 * This removes all WEP keys
845 static int lbs_remove_wep_keys(struct lbs_private
*priv
)
847 struct cmd_ds_802_11_set_wep cmd
;
850 lbs_deb_enter(LBS_DEB_CFG80211
);
852 memset(&cmd
, 0, sizeof(cmd
));
853 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
854 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
855 cmd
.action
= cpu_to_le16(CMD_ACT_REMOVE
);
857 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
859 lbs_deb_leave(LBS_DEB_CFG80211
);
866 static int lbs_set_wep_keys(struct lbs_private
*priv
)
868 struct cmd_ds_802_11_set_wep cmd
;
872 lbs_deb_enter(LBS_DEB_CFG80211
);
879 * action 02 00 ACT_ADD
881 * type for key 1 01 WEP40
885 * key 1 39 39 39 39 39 00 00 00
886 * 00 00 00 00 00 00 00 00
887 * key 2 00 00 00 00 00 00 00 00
888 * 00 00 00 00 00 00 00 00
889 * key 3 00 00 00 00 00 00 00 00
890 * 00 00 00 00 00 00 00 00
891 * key 4 00 00 00 00 00 00 00 00
893 if (priv
->wep_key_len
[0] || priv
->wep_key_len
[1] ||
894 priv
->wep_key_len
[2] || priv
->wep_key_len
[3]) {
895 /* Only set wep keys if we have at least one of them */
896 memset(&cmd
, 0, sizeof(cmd
));
897 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
898 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
899 cmd
.action
= cpu_to_le16(CMD_ACT_ADD
);
901 for (i
= 0; i
< 4; i
++) {
902 switch (priv
->wep_key_len
[i
]) {
903 case WLAN_KEY_LEN_WEP40
:
904 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
906 case WLAN_KEY_LEN_WEP104
:
907 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
913 memcpy(cmd
.keymaterial
[i
], priv
->wep_key
[i
],
914 priv
->wep_key_len
[i
]);
917 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
919 /* Otherwise remove all wep keys */
920 ret
= lbs_remove_wep_keys(priv
);
923 lbs_deb_leave(LBS_DEB_CFG80211
);
929 * Enable/Disable RSN status
931 static int lbs_enable_rsn(struct lbs_private
*priv
, int enable
)
933 struct cmd_ds_802_11_enable_rsn cmd
;
936 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", enable
);
943 * action 01 00 ACT_SET
946 memset(&cmd
, 0, sizeof(cmd
));
947 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
948 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
949 cmd
.enable
= cpu_to_le16(enable
);
951 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
953 lbs_deb_leave(LBS_DEB_CFG80211
);
959 * Set WPA/WPA key material
963 * like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
964 * get rid of WEXT, this should go into host.h
967 struct cmd_key_material
{
968 struct cmd_header hdr
;
971 struct MrvlIEtype_keyParamSet param
;
974 static int lbs_set_key_material(struct lbs_private
*priv
,
977 u8
*key
, u16 key_len
)
979 struct cmd_key_material cmd
;
982 lbs_deb_enter(LBS_DEB_CFG80211
);
985 * Example for WPA (TKIP):
992 * TLV type 00 01 key param
994 * key type 01 00 TKIP
995 * key info 06 00 UNICAST | ENABLED
999 memset(&cmd
, 0, sizeof(cmd
));
1000 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1001 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1002 cmd
.param
.type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
1003 cmd
.param
.length
= cpu_to_le16(sizeof(cmd
.param
) - 4);
1004 cmd
.param
.keytypeid
= cpu_to_le16(key_type
);
1005 cmd
.param
.keyinfo
= cpu_to_le16(key_info
);
1006 cmd
.param
.keylen
= cpu_to_le16(key_len
);
1008 memcpy(cmd
.param
.key
, key
, key_len
);
1010 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
1012 lbs_deb_leave(LBS_DEB_CFG80211
);
1018 * Sets the auth type (open, shared, etc) in the firmware. That
1019 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
1020 * command doesn't send an authentication frame at all, it just
1021 * stores the auth_type.
1023 static int lbs_set_authtype(struct lbs_private
*priv
,
1024 struct cfg80211_connect_params
*sme
)
1026 struct cmd_ds_802_11_authenticate cmd
;
1029 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", sme
->auth_type
);
1036 * BSS id 00 13 19 80 da 30
1038 * reserved 00 00 00 00 00 00 00 00 00 00
1040 memset(&cmd
, 0, sizeof(cmd
));
1041 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1043 memcpy(cmd
.bssid
, sme
->bssid
, ETH_ALEN
);
1044 /* convert auth_type */
1045 ret
= lbs_auth_to_authtype(sme
->auth_type
);
1050 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AUTHENTICATE
, &cmd
);
1053 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1059 * Create association request
1061 #define LBS_ASSOC_MAX_CMD_SIZE \
1062 (sizeof(struct cmd_ds_802_11_associate) \
1063 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1064 + LBS_MAX_SSID_TLV_SIZE \
1065 + LBS_MAX_CHANNEL_TLV_SIZE \
1066 + LBS_MAX_CF_PARAM_TLV_SIZE \
1067 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1068 + LBS_MAX_WPA_TLV_SIZE)
1070 static int lbs_associate(struct lbs_private
*priv
,
1071 struct cfg80211_bss
*bss
,
1072 struct cfg80211_connect_params
*sme
)
1074 struct cmd_ds_802_11_associate_response
*resp
;
1075 struct cmd_ds_802_11_associate
*cmd
= kzalloc(LBS_ASSOC_MAX_CMD_SIZE
,
1078 size_t len
, resp_ie_len
;
1081 u8
*pos
= &(cmd
->iebuf
[0]);
1084 lbs_deb_enter(LBS_DEB_CFG80211
);
1096 * BSS id 00 13 19 80 da 30
1097 * capabilities 11 00
1098 * listen interval 0a 00
1099 * beacon interval 00 00
1101 * TLVs xx (up to 512 bytes)
1103 cmd
->hdr
.command
= cpu_to_le16(CMD_802_11_ASSOCIATE
);
1105 /* Fill in static fields */
1106 memcpy(cmd
->bssid
, bss
->bssid
, ETH_ALEN
);
1107 cmd
->listeninterval
= cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL
);
1108 cmd
->capability
= cpu_to_le16(bss
->capability
);
1111 ssid_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SSID
);
1113 pos
+= lbs_add_ssid_tlv(pos
, ssid_eid
+ 2, ssid_eid
[1]);
1115 lbs_deb_assoc("no SSID\n");
1117 /* add DS param TLV */
1119 pos
+= lbs_add_channel_tlv(pos
, bss
->channel
->hw_value
);
1121 lbs_deb_assoc("no channel\n");
1123 /* add (empty) CF param TLV */
1124 pos
+= lbs_add_cf_param_tlv(pos
);
1127 tmp
= pos
+ 4; /* skip Marvell IE header */
1128 pos
+= lbs_add_common_rates_tlv(pos
, bss
);
1129 lbs_deb_hex(LBS_DEB_ASSOC
, "Common Rates", tmp
, pos
- tmp
);
1131 /* add auth type TLV */
1132 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= 9)
1133 pos
+= lbs_add_auth_type_tlv(pos
, sme
->auth_type
);
1135 /* add WPA/WPA2 TLV */
1136 if (sme
->ie
&& sme
->ie_len
)
1137 pos
+= lbs_add_wpa_tlv(pos
, sme
->ie
, sme
->ie_len
);
1139 len
= (sizeof(*cmd
) - sizeof(cmd
->iebuf
)) +
1140 (u16
)(pos
- (u8
*) &cmd
->iebuf
);
1141 cmd
->hdr
.size
= cpu_to_le16(len
);
1143 lbs_deb_hex(LBS_DEB_ASSOC
, "ASSOC_CMD", (u8
*) cmd
,
1144 le16_to_cpu(cmd
->hdr
.size
));
1146 /* store for later use */
1147 memcpy(priv
->assoc_bss
, bss
->bssid
, ETH_ALEN
);
1149 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ASSOCIATE
, cmd
);
1153 /* generate connect message to cfg80211 */
1155 resp
= (void *) cmd
; /* recast for easier field access */
1156 status
= le16_to_cpu(resp
->statuscode
);
1158 /* Older FW versions map the IEEE 802.11 Status Code in the association
1159 * response to the following values returned in resp->statuscode:
1161 * IEEE Status Code Marvell Status Code
1162 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1163 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1164 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1165 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1166 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1167 * others -> 0x0003 ASSOC_RESULT_REFUSED
1169 * Other response codes:
1170 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1171 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1172 * association response from the AP)
1174 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1179 lbs_deb_assoc("invalid association parameters\n");
1180 status
= WLAN_STATUS_CAPS_UNSUPPORTED
;
1183 lbs_deb_assoc("timer expired while waiting for AP\n");
1184 status
= WLAN_STATUS_AUTH_TIMEOUT
;
1187 lbs_deb_assoc("association refused by AP\n");
1188 status
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1191 lbs_deb_assoc("authentication refused by AP\n");
1192 status
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1195 lbs_deb_assoc("association failure %d\n", status
);
1196 /* v5 OLPC firmware does return the AP status code if
1197 * it's not one of the values above. Let that through.
1203 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1204 "aid 0x%04x\n", status
, le16_to_cpu(resp
->statuscode
),
1205 le16_to_cpu(resp
->capability
), le16_to_cpu(resp
->aid
));
1207 resp_ie_len
= le16_to_cpu(resp
->hdr
.size
)
1210 cfg80211_connect_result(priv
->dev
,
1212 sme
->ie
, sme
->ie_len
,
1213 resp
->iebuf
, resp_ie_len
,
1218 /* TODO: get rid of priv->connect_status */
1219 priv
->connect_status
= LBS_CONNECTED
;
1220 netif_carrier_on(priv
->dev
);
1221 if (!priv
->tx_pending_len
)
1222 netif_tx_wake_all_queues(priv
->dev
);
1226 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1230 static struct cfg80211_scan_request
*
1231 _new_connect_scan_req(struct wiphy
*wiphy
, struct cfg80211_connect_params
*sme
)
1233 struct cfg80211_scan_request
*creq
= NULL
;
1234 int i
, n_channels
= 0;
1235 enum ieee80211_band band
;
1237 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1238 if (wiphy
->bands
[band
])
1239 n_channels
+= wiphy
->bands
[band
]->n_channels
;
1242 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1243 n_channels
* sizeof(void *),
1248 /* SSIDs come after channels */
1249 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1250 creq
->n_channels
= n_channels
;
1253 /* Scan all available channels */
1255 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1258 if (!wiphy
->bands
[band
])
1261 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1262 /* ignore disabled channels */
1263 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1264 IEEE80211_CHAN_DISABLED
)
1267 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1272 /* Set real number of channels specified in creq->channels[] */
1273 creq
->n_channels
= i
;
1275 /* Scan for the SSID we're going to connect to */
1276 memcpy(creq
->ssids
[0].ssid
, sme
->ssid
, sme
->ssid_len
);
1277 creq
->ssids
[0].ssid_len
= sme
->ssid_len
;
1279 /* No channels found... */
1287 static int lbs_cfg_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1288 struct cfg80211_connect_params
*sme
)
1290 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1291 struct cfg80211_bss
*bss
= NULL
;
1293 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1295 lbs_deb_enter(LBS_DEB_CFG80211
);
1298 /* Run a scan if one isn't in-progress already and if the last
1299 * scan was done more than 2 seconds ago.
1301 if (priv
->scan_req
== NULL
&&
1302 time_after(jiffies
, priv
->last_scan
+ (2 * HZ
))) {
1303 struct cfg80211_scan_request
*creq
;
1305 creq
= _new_connect_scan_req(wiphy
, sme
);
1311 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1312 _internal_start_scan(priv
, true, creq
);
1315 /* Wait for any in-progress scan to complete */
1316 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1317 wait_event_interruptible_timeout(priv
->scan_q
,
1318 (priv
->scan_req
== NULL
),
1320 lbs_deb_assoc("assoc: scanning competed\n");
1323 /* Find the BSS we want using available scan results */
1324 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
,
1325 sme
->ssid
, sme
->ssid_len
,
1326 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
1328 wiphy_err(wiphy
, "assoc: bss %pM not in scan results\n",
1333 lbs_deb_assoc("trying %pM\n", bss
->bssid
);
1334 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1335 sme
->crypto
.cipher_group
,
1336 sme
->key_idx
, sme
->key_len
);
1338 /* As this is a new connection, clear locally stored WEP keys */
1339 priv
->wep_tx_key
= 0;
1340 memset(priv
->wep_key
, 0, sizeof(priv
->wep_key
));
1341 memset(priv
->wep_key_len
, 0, sizeof(priv
->wep_key_len
));
1343 /* set/remove WEP keys */
1344 switch (sme
->crypto
.cipher_group
) {
1345 case WLAN_CIPHER_SUITE_WEP40
:
1346 case WLAN_CIPHER_SUITE_WEP104
:
1347 /* Store provided WEP keys in priv-> */
1348 priv
->wep_tx_key
= sme
->key_idx
;
1349 priv
->wep_key_len
[sme
->key_idx
] = sme
->key_len
;
1350 memcpy(priv
->wep_key
[sme
->key_idx
], sme
->key
, sme
->key_len
);
1351 /* Set WEP keys and WEP mode */
1352 lbs_set_wep_keys(priv
);
1353 priv
->mac_control
|= CMD_ACT_MAC_WEP_ENABLE
;
1354 lbs_set_mac_control(priv
);
1355 /* No RSN mode for WEP */
1356 lbs_enable_rsn(priv
, 0);
1358 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1360 * If we don't have no WEP, no WPA and no WPA2,
1361 * we remove all keys like in the WPA/WPA2 setup,
1362 * we just don't set RSN.
1364 * Therefore: fall-through
1366 case WLAN_CIPHER_SUITE_TKIP
:
1367 case WLAN_CIPHER_SUITE_CCMP
:
1368 /* Remove WEP keys and WEP mode */
1369 lbs_remove_wep_keys(priv
);
1370 priv
->mac_control
&= ~CMD_ACT_MAC_WEP_ENABLE
;
1371 lbs_set_mac_control(priv
);
1373 /* clear the WPA/WPA2 keys */
1374 lbs_set_key_material(priv
,
1375 KEY_TYPE_ID_WEP
, /* doesn't matter */
1376 KEY_INFO_WPA_UNICAST
,
1378 lbs_set_key_material(priv
,
1379 KEY_TYPE_ID_WEP
, /* doesn't matter */
1382 /* RSN mode for WPA/WPA2 */
1383 lbs_enable_rsn(priv
, sme
->crypto
.cipher_group
!= 0);
1386 wiphy_err(wiphy
, "unsupported cipher group 0x%x\n",
1387 sme
->crypto
.cipher_group
);
1392 lbs_set_authtype(priv
, sme
);
1393 lbs_set_radio(priv
, preamble
, 1);
1395 /* Do the actual association */
1396 ret
= lbs_associate(priv
, bss
, sme
);
1400 cfg80211_put_bss(bss
);
1401 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1405 static int lbs_cfg_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1408 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1409 struct cmd_ds_802_11_deauthenticate cmd
;
1411 lbs_deb_enter_args(LBS_DEB_CFG80211
, "reason_code %d", reason_code
);
1413 /* store for lbs_cfg_ret_disconnect() */
1414 priv
->disassoc_reason
= reason_code
;
1416 memset(&cmd
, 0, sizeof(cmd
));
1417 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1418 /* Mildly ugly to use a locally store my own BSSID ... */
1419 memcpy(cmd
.macaddr
, &priv
->assoc_bss
, ETH_ALEN
);
1420 cmd
.reasoncode
= cpu_to_le16(reason_code
);
1422 if (lbs_cmd_with_response(priv
, CMD_802_11_DEAUTHENTICATE
, &cmd
))
1425 cfg80211_disconnected(priv
->dev
,
1426 priv
->disassoc_reason
,
1429 priv
->connect_status
= LBS_DISCONNECTED
;
1435 static int lbs_cfg_set_default_key(struct wiphy
*wiphy
,
1436 struct net_device
*netdev
,
1437 u8 key_index
, bool unicast
,
1440 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1442 lbs_deb_enter(LBS_DEB_CFG80211
);
1444 if (key_index
!= priv
->wep_tx_key
) {
1445 lbs_deb_assoc("set_default_key: to %d\n", key_index
);
1446 priv
->wep_tx_key
= key_index
;
1447 lbs_set_wep_keys(priv
);
1454 static int lbs_cfg_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1455 u8 idx
, bool pairwise
, const u8
*mac_addr
,
1456 struct key_params
*params
)
1458 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1463 lbs_deb_enter(LBS_DEB_CFG80211
);
1465 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1466 params
->cipher
, mac_addr
);
1467 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1468 idx
, params
->key_len
);
1469 if (params
->key_len
)
1470 lbs_deb_hex(LBS_DEB_CFG80211
, "KEY",
1471 params
->key
, params
->key_len
);
1473 lbs_deb_assoc("add_key: seq len %d\n", params
->seq_len
);
1474 if (params
->seq_len
)
1475 lbs_deb_hex(LBS_DEB_CFG80211
, "SEQ",
1476 params
->seq
, params
->seq_len
);
1478 switch (params
->cipher
) {
1479 case WLAN_CIPHER_SUITE_WEP40
:
1480 case WLAN_CIPHER_SUITE_WEP104
:
1481 /* actually compare if something has changed ... */
1482 if ((priv
->wep_key_len
[idx
] != params
->key_len
) ||
1483 memcmp(priv
->wep_key
[idx
],
1484 params
->key
, params
->key_len
) != 0) {
1485 priv
->wep_key_len
[idx
] = params
->key_len
;
1486 memcpy(priv
->wep_key
[idx
],
1487 params
->key
, params
->key_len
);
1488 lbs_set_wep_keys(priv
);
1491 case WLAN_CIPHER_SUITE_TKIP
:
1492 case WLAN_CIPHER_SUITE_CCMP
:
1493 key_info
= KEY_INFO_WPA_ENABLED
| ((idx
== 0)
1494 ? KEY_INFO_WPA_UNICAST
1495 : KEY_INFO_WPA_MCAST
);
1496 key_type
= (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1499 lbs_set_key_material(priv
,
1502 params
->key
, params
->key_len
);
1505 wiphy_err(wiphy
, "unhandled cipher 0x%x\n", params
->cipher
);
1514 static int lbs_cfg_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1515 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
1518 lbs_deb_enter(LBS_DEB_CFG80211
);
1520 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1521 key_index
, mac_addr
);
1524 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1526 * I think can keep this a NO-OP, because:
1528 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1529 * - neither "iw" nor "wpa_supplicant" won't call this during
1530 * an ongoing connection
1531 * - TODO: but I have to check if this is still true when
1532 * I set the AP to periodic re-keying
1533 * - we've not kzallec() something when we've added a key at
1534 * lbs_cfg_connect() or lbs_cfg_add_key().
1536 * This causes lbs_cfg_del_key() only called at disconnect time,
1537 * where we'd just waste time deleting a key that is not going
1538 * to be used anyway.
1540 if (key_index
< 3 && priv
->wep_key_len
[key_index
]) {
1541 priv
->wep_key_len
[key_index
] = 0;
1542 lbs_set_wep_keys(priv
);
1554 static int lbs_cfg_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1555 u8
*mac
, struct station_info
*sinfo
)
1557 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1562 lbs_deb_enter(LBS_DEB_CFG80211
);
1564 sinfo
->filled
|= STATION_INFO_TX_BYTES
|
1565 STATION_INFO_TX_PACKETS
|
1566 STATION_INFO_RX_BYTES
|
1567 STATION_INFO_RX_PACKETS
;
1568 sinfo
->tx_bytes
= priv
->dev
->stats
.tx_bytes
;
1569 sinfo
->tx_packets
= priv
->dev
->stats
.tx_packets
;
1570 sinfo
->rx_bytes
= priv
->dev
->stats
.rx_bytes
;
1571 sinfo
->rx_packets
= priv
->dev
->stats
.rx_packets
;
1573 /* Get current RSSI */
1574 ret
= lbs_get_rssi(priv
, &signal
, &noise
);
1576 sinfo
->signal
= signal
;
1577 sinfo
->filled
|= STATION_INFO_SIGNAL
;
1580 /* Convert priv->cur_rate from hw_value to NL80211 value */
1581 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
1582 if (priv
->cur_rate
== lbs_rates
[i
].hw_value
) {
1583 sinfo
->txrate
.legacy
= lbs_rates
[i
].bitrate
;
1584 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
1596 * "Site survey", here just current channel and noise level
1599 static int lbs_get_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
1600 int idx
, struct survey_info
*survey
)
1602 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1609 lbs_deb_enter(LBS_DEB_CFG80211
);
1611 survey
->channel
= ieee80211_get_channel(wiphy
,
1612 ieee80211_channel_to_frequency(priv
->channel
,
1613 IEEE80211_BAND_2GHZ
));
1615 ret
= lbs_get_rssi(priv
, &signal
, &noise
);
1617 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1618 survey
->noise
= noise
;
1621 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1632 static int lbs_change_intf(struct wiphy
*wiphy
, struct net_device
*dev
,
1633 enum nl80211_iftype type
, u32
*flags
,
1634 struct vif_params
*params
)
1636 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1639 lbs_deb_enter(LBS_DEB_CFG80211
);
1642 case NL80211_IFTYPE_MONITOR
:
1643 ret
= lbs_set_monitor_mode(priv
, 1);
1645 case NL80211_IFTYPE_STATION
:
1646 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1647 ret
= lbs_set_monitor_mode(priv
, 0);
1649 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 1);
1651 case NL80211_IFTYPE_ADHOC
:
1652 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1653 ret
= lbs_set_monitor_mode(priv
, 0);
1655 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 2);
1662 priv
->wdev
->iftype
= type
;
1664 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1675 * The firmware needs the following bits masked out of the beacon-derived
1676 * capability field when associating/joining to a BSS:
1677 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1679 #define CAPINFO_MASK (~(0xda00))
1682 static void lbs_join_post(struct lbs_private
*priv
,
1683 struct cfg80211_ibss_params
*params
,
1684 u8
*bssid
, u16 capability
)
1686 u8 fake_ie
[2 + IEEE80211_MAX_SSID_LEN
+ /* ssid */
1687 2 + 4 + /* basic rates */
1688 2 + 1 + /* DS parameter */
1690 2 + 8]; /* extended rates */
1693 lbs_deb_enter(LBS_DEB_CFG80211
);
1696 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1697 * the real IE from the firmware. So we fabricate a fake IE based on
1698 * what the firmware actually sends (sniffed with wireshark).
1701 *fake
++ = WLAN_EID_SSID
;
1702 *fake
++ = params
->ssid_len
;
1703 memcpy(fake
, params
->ssid
, params
->ssid_len
);
1704 fake
+= params
->ssid_len
;
1705 /* Fake supported basic rates IE */
1706 *fake
++ = WLAN_EID_SUPP_RATES
;
1712 /* Fake DS channel IE */
1713 *fake
++ = WLAN_EID_DS_PARAMS
;
1715 *fake
++ = params
->channel
->hw_value
;
1716 /* Fake IBSS params IE */
1717 *fake
++ = WLAN_EID_IBSS_PARAMS
;
1719 *fake
++ = 0; /* ATIM=0 */
1721 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1722 * but I don't know how this could be checked */
1723 *fake
++ = WLAN_EID_EXT_SUPP_RATES
;
1733 lbs_deb_hex(LBS_DEB_CFG80211
, "IE", fake_ie
, fake
- fake_ie
);
1735 cfg80211_inform_bss(priv
->wdev
->wiphy
,
1740 params
->beacon_interval
,
1741 fake_ie
, fake
- fake_ie
,
1744 memcpy(priv
->wdev
->ssid
, params
->ssid
, params
->ssid_len
);
1745 priv
->wdev
->ssid_len
= params
->ssid_len
;
1747 cfg80211_ibss_joined(priv
->dev
, bssid
, GFP_KERNEL
);
1749 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1750 priv
->connect_status
= LBS_CONNECTED
;
1751 netif_carrier_on(priv
->dev
);
1752 if (!priv
->tx_pending_len
)
1753 netif_wake_queue(priv
->dev
);
1755 lbs_deb_leave(LBS_DEB_CFG80211
);
1758 static int lbs_ibss_join_existing(struct lbs_private
*priv
,
1759 struct cfg80211_ibss_params
*params
,
1760 struct cfg80211_bss
*bss
)
1762 const u8
*rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
1763 struct cmd_ds_802_11_ad_hoc_join cmd
;
1764 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1767 lbs_deb_enter(LBS_DEB_CFG80211
);
1769 /* TODO: set preamble based on scan result */
1770 ret
= lbs_set_radio(priv
, preamble
, 1);
1775 * Example CMD_802_11_AD_HOC_JOIN command:
1777 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1781 * bssid 02 27 27 97 2f 96
1782 * ssid 49 42 53 53 00 00 00 00
1783 * 00 00 00 00 00 00 00 00
1784 * 00 00 00 00 00 00 00 00
1785 * 00 00 00 00 00 00 00 00
1786 * type 02 CMD_BSS_TYPE_IBSS
1787 * beacon period 64 00
1789 * timestamp 00 00 00 00 00 00 00 00
1790 * localtime 00 00 00 00 00 00 00 00
1794 * reserveed 00 00 00 00
1797 * IE IBSS atim 00 00
1798 * reserved 00 00 00 00
1800 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1801 * fail timeout ff 00
1804 memset(&cmd
, 0, sizeof(cmd
));
1805 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1807 memcpy(cmd
.bss
.bssid
, bss
->bssid
, ETH_ALEN
);
1808 memcpy(cmd
.bss
.ssid
, params
->ssid
, params
->ssid_len
);
1809 cmd
.bss
.type
= CMD_BSS_TYPE_IBSS
;
1810 cmd
.bss
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1811 cmd
.bss
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1812 cmd
.bss
.ds
.header
.len
= 1;
1813 cmd
.bss
.ds
.channel
= params
->channel
->hw_value
;
1814 cmd
.bss
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1815 cmd
.bss
.ibss
.header
.len
= 2;
1816 cmd
.bss
.ibss
.atimwindow
= 0;
1817 cmd
.bss
.capability
= cpu_to_le16(bss
->capability
& CAPINFO_MASK
);
1819 /* set rates to the intersection of our rates and the rates in the
1822 lbs_add_rates(cmd
.bss
.rates
);
1825 u8 rates_max
= rates_eid
[1];
1826 u8
*rates
= cmd
.bss
.rates
;
1827 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
1828 u8 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
1829 for (i
= 0; i
< rates_max
; i
++) {
1830 if (hw_rate
== (rates_eid
[i
+2] & 0x7f)) {
1831 u8 rate
= rates_eid
[i
+2];
1832 if (rate
== 0x02 || rate
== 0x04 ||
1833 rate
== 0x0b || rate
== 0x16)
1841 /* Only v8 and below support setting this */
1842 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1843 cmd
.failtimeout
= cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT
);
1844 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1846 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_JOIN
, &cmd
);
1851 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1859 lbs_join_post(priv
, params
, bss
->bssid
, bss
->capability
);
1862 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1868 static int lbs_ibss_start_new(struct lbs_private
*priv
,
1869 struct cfg80211_ibss_params
*params
)
1871 struct cmd_ds_802_11_ad_hoc_start cmd
;
1872 struct cmd_ds_802_11_ad_hoc_result
*resp
=
1873 (struct cmd_ds_802_11_ad_hoc_result
*) &cmd
;
1874 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1878 lbs_deb_enter(LBS_DEB_CFG80211
);
1880 ret
= lbs_set_radio(priv
, preamble
, 1);
1885 * Example CMD_802_11_AD_HOC_START command:
1887 * command 2b 00 CMD_802_11_AD_HOC_START
1891 * ssid 54 45 53 54 00 00 00 00
1892 * 00 00 00 00 00 00 00 00
1893 * 00 00 00 00 00 00 00 00
1894 * 00 00 00 00 00 00 00 00
1896 * beacon period 64 00
1900 * IE IBSS atim 00 00
1901 * reserved 00 00 00 00
1905 * reserved 00 00 00 00
1908 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1909 * 0c 12 18 24 30 48 60 6c
1912 memset(&cmd
, 0, sizeof(cmd
));
1913 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1914 memcpy(cmd
.ssid
, params
->ssid
, params
->ssid_len
);
1915 cmd
.bsstype
= CMD_BSS_TYPE_IBSS
;
1916 cmd
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1917 cmd
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1918 cmd
.ibss
.header
.len
= 2;
1919 cmd
.ibss
.atimwindow
= 0;
1920 cmd
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1921 cmd
.ds
.header
.len
= 1;
1922 cmd
.ds
.channel
= params
->channel
->hw_value
;
1923 /* Only v8 and below support setting probe delay */
1924 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8)
1925 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1926 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1927 capability
= WLAN_CAPABILITY_IBSS
;
1928 cmd
.capability
= cpu_to_le16(capability
);
1929 lbs_add_rates(cmd
.rates
);
1932 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_START
, &cmd
);
1937 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1944 * bssid 02 2b 7b 0f 86 0e
1946 lbs_join_post(priv
, params
, resp
->bssid
, capability
);
1949 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1954 static int lbs_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1955 struct cfg80211_ibss_params
*params
)
1957 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1959 struct cfg80211_bss
*bss
;
1960 DECLARE_SSID_BUF(ssid_buf
);
1962 lbs_deb_enter(LBS_DEB_CFG80211
);
1964 if (!params
->channel
) {
1969 ret
= lbs_set_channel(priv
, params
->channel
->hw_value
);
1973 /* Search if someone is beaconing. This assumes that the
1974 * bss list is populated already */
1975 bss
= cfg80211_get_bss(wiphy
, params
->channel
, params
->bssid
,
1976 params
->ssid
, params
->ssid_len
,
1977 WLAN_CAPABILITY_IBSS
, WLAN_CAPABILITY_IBSS
);
1980 ret
= lbs_ibss_join_existing(priv
, params
, bss
);
1981 cfg80211_put_bss(bss
);
1983 ret
= lbs_ibss_start_new(priv
, params
);
1987 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1992 static int lbs_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
1994 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1995 struct cmd_ds_802_11_ad_hoc_stop cmd
;
1998 lbs_deb_enter(LBS_DEB_CFG80211
);
2000 memset(&cmd
, 0, sizeof(cmd
));
2001 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
2002 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_STOP
, &cmd
);
2004 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
2005 lbs_mac_event_disconnected(priv
);
2007 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2018 static struct cfg80211_ops lbs_cfg80211_ops
= {
2019 .set_channel
= lbs_cfg_set_channel
,
2020 .scan
= lbs_cfg_scan
,
2021 .connect
= lbs_cfg_connect
,
2022 .disconnect
= lbs_cfg_disconnect
,
2023 .add_key
= lbs_cfg_add_key
,
2024 .del_key
= lbs_cfg_del_key
,
2025 .set_default_key
= lbs_cfg_set_default_key
,
2026 .get_station
= lbs_cfg_get_station
,
2027 .dump_survey
= lbs_get_survey
,
2028 .change_virtual_intf
= lbs_change_intf
,
2029 .join_ibss
= lbs_join_ibss
,
2030 .leave_ibss
= lbs_leave_ibss
,
2035 * At this time lbs_private *priv doesn't even exist, so we just allocate
2036 * memory and don't initialize the wiphy further. This is postponed until we
2037 * can talk to the firmware and happens at registration time in
2038 * lbs_cfg_wiphy_register().
2040 struct wireless_dev
*lbs_cfg_alloc(struct device
*dev
)
2043 struct wireless_dev
*wdev
;
2045 lbs_deb_enter(LBS_DEB_CFG80211
);
2047 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
2049 dev_err(dev
, "cannot allocate wireless device\n");
2050 return ERR_PTR(-ENOMEM
);
2053 wdev
->wiphy
= wiphy_new(&lbs_cfg80211_ops
, sizeof(struct lbs_private
));
2055 dev_err(dev
, "cannot allocate wiphy\n");
2060 lbs_deb_leave(LBS_DEB_CFG80211
);
2065 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2066 return ERR_PTR(ret
);
2070 static void lbs_cfg_set_regulatory_hint(struct lbs_private
*priv
)
2072 struct region_code_mapping
{
2077 /* Section 5.17.2 */
2078 static const struct region_code_mapping regmap
[] = {
2079 {"US ", 0x10}, /* US FCC */
2080 {"CA ", 0x20}, /* Canada */
2081 {"EU ", 0x30}, /* ETSI */
2082 {"ES ", 0x31}, /* Spain */
2083 {"FR ", 0x32}, /* France */
2084 {"JP ", 0x40}, /* Japan */
2088 lbs_deb_enter(LBS_DEB_CFG80211
);
2090 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
2091 if (regmap
[i
].code
== priv
->regioncode
) {
2092 regulatory_hint(priv
->wdev
->wiphy
, regmap
[i
].cn
);
2096 lbs_deb_leave(LBS_DEB_CFG80211
);
2101 * This function get's called after lbs_setup_firmware() determined the
2102 * firmware capabities. So we can setup the wiphy according to our
2103 * hardware/firmware.
2105 int lbs_cfg_register(struct lbs_private
*priv
)
2107 struct wireless_dev
*wdev
= priv
->wdev
;
2110 lbs_deb_enter(LBS_DEB_CFG80211
);
2112 wdev
->wiphy
->max_scan_ssids
= 1;
2113 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
2115 wdev
->wiphy
->interface_modes
=
2116 BIT(NL80211_IFTYPE_STATION
) |
2117 BIT(NL80211_IFTYPE_ADHOC
);
2118 if (lbs_rtap_supported(priv
))
2119 wdev
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_MONITOR
);
2121 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &lbs_band_2ghz
;
2124 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2125 * never seen a firmware without WPA
2127 wdev
->wiphy
->cipher_suites
= cipher_suites
;
2128 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
2129 wdev
->wiphy
->reg_notifier
= lbs_reg_notifier
;
2131 ret
= wiphy_register(wdev
->wiphy
);
2133 pr_err("cannot register wiphy device\n");
2135 priv
->wiphy_registered
= true;
2137 ret
= register_netdev(priv
->dev
);
2139 pr_err("cannot register network device\n");
2141 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
2143 lbs_cfg_set_regulatory_hint(priv
);
2145 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2149 int lbs_reg_notifier(struct wiphy
*wiphy
,
2150 struct regulatory_request
*request
)
2152 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2155 lbs_deb_enter_args(LBS_DEB_CFG80211
, "cfg80211 regulatory domain "
2156 "callback for domain %c%c\n", request
->alpha2
[0],
2157 request
->alpha2
[1]);
2159 ret
= lbs_set_11d_domain_info(priv
, request
, wiphy
->bands
);
2161 lbs_deb_leave(LBS_DEB_CFG80211
);
2165 void lbs_scan_deinit(struct lbs_private
*priv
)
2167 lbs_deb_enter(LBS_DEB_CFG80211
);
2168 cancel_delayed_work_sync(&priv
->scan_work
);
2172 void lbs_cfg_free(struct lbs_private
*priv
)
2174 struct wireless_dev
*wdev
= priv
->wdev
;
2176 lbs_deb_enter(LBS_DEB_CFG80211
);
2181 if (priv
->wiphy_registered
)
2182 wiphy_unregister(wdev
->wiphy
);
2185 wiphy_free(wdev
->wiphy
);