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 #include <linux/slab.h>
10 #include <linux/ieee80211.h>
11 #include <net/cfg80211.h>
12 #include <asm/unaligned.h>
19 #define CHAN2G(_channel, _freq, _flags) { \
20 .band = IEEE80211_BAND_2GHZ, \
21 .center_freq = (_freq), \
22 .hw_value = (_channel), \
24 .max_antenna_gain = 0, \
28 static struct ieee80211_channel lbs_2ghz_channels
[] = {
45 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
47 .hw_value = (_hw_value), \
52 /* Table 6 in section 3.2.1.1 */
53 static struct ieee80211_rate lbs_rates
[] = {
54 RATETAB_ENT(10, 0, 0),
55 RATETAB_ENT(20, 1, 0),
56 RATETAB_ENT(55, 2, 0),
57 RATETAB_ENT(110, 3, 0),
58 RATETAB_ENT(60, 9, 0),
59 RATETAB_ENT(90, 6, 0),
60 RATETAB_ENT(120, 7, 0),
61 RATETAB_ENT(180, 8, 0),
62 RATETAB_ENT(240, 9, 0),
63 RATETAB_ENT(360, 10, 0),
64 RATETAB_ENT(480, 11, 0),
65 RATETAB_ENT(540, 12, 0),
68 static struct ieee80211_supported_band lbs_band_2ghz
= {
69 .channels
= lbs_2ghz_channels
,
70 .n_channels
= ARRAY_SIZE(lbs_2ghz_channels
),
71 .bitrates
= lbs_rates
,
72 .n_bitrates
= ARRAY_SIZE(lbs_rates
),
76 static const u32 cipher_suites
[] = {
77 WLAN_CIPHER_SUITE_WEP40
,
78 WLAN_CIPHER_SUITE_WEP104
,
79 WLAN_CIPHER_SUITE_TKIP
,
80 WLAN_CIPHER_SUITE_CCMP
,
83 /* Time to stay on the channel */
84 #define LBS_DWELL_PASSIVE 100
85 #define LBS_DWELL_ACTIVE 40
88 /***************************************************************************
89 * Misc utility functions
91 * TLVs are Marvell specific. They are very similar to IEs, they have the
92 * same structure: type, length, data*. The only difference: for IEs, the
93 * type and length are u8, but for TLVs they're __le16.
97 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
98 * in the firmware spec
100 static u8
lbs_auth_to_authtype(enum nl80211_auth_type auth_type
)
105 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
106 case NL80211_AUTHTYPE_SHARED_KEY
:
109 case NL80211_AUTHTYPE_AUTOMATIC
:
110 ret
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
112 case NL80211_AUTHTYPE_NETWORK_EAP
:
116 /* silence compiler */
123 /* Various firmware commands need the list of supported rates, but with
124 the hight-bit set for basic rates */
125 static int lbs_add_rates(u8
*rates
)
129 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
130 u8 rate
= lbs_rates
[i
].bitrate
/ 5;
131 if (rate
== 0x02 || rate
== 0x04 ||
132 rate
== 0x0b || rate
== 0x16)
136 return ARRAY_SIZE(lbs_rates
);
140 /***************************************************************************
141 * TLV utility functions
143 * TLVs are Marvell specific. They are very similar to IEs, they have the
144 * same structure: type, length, data*. The only difference: for IEs, the
145 * type and length are u8, but for TLVs they're __le16.
152 #define LBS_MAX_SSID_TLV_SIZE \
153 (sizeof(struct mrvl_ie_header) \
154 + IEEE80211_MAX_SSID_LEN)
156 static int lbs_add_ssid_tlv(u8
*tlv
, const u8
*ssid
, int ssid_len
)
158 struct mrvl_ie_ssid_param_set
*ssid_tlv
= (void *)tlv
;
163 * ssid 4d 4e 54 45 53 54
165 ssid_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
166 ssid_tlv
->header
.len
= cpu_to_le16(ssid_len
);
167 memcpy(ssid_tlv
->ssid
, ssid
, ssid_len
);
168 return sizeof(ssid_tlv
->header
) + ssid_len
;
173 * Add channel list TLV (section 8.4.2)
175 * Actual channel data comes from priv->wdev->wiphy->channels.
177 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
178 (sizeof(struct mrvl_ie_header) \
179 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
181 static int lbs_add_channel_list_tlv(struct lbs_private
*priv
, u8
*tlv
,
182 int last_channel
, int active_scan
)
184 int chanscanparamsize
= sizeof(struct chanscanparamset
) *
185 (last_channel
- priv
->scan_channel
);
187 struct mrvl_ie_header
*header
= (void *) tlv
;
190 * TLV-ID CHANLIST 01 01
192 * channel 00 01 00 00 00 64 00
196 * min scan time 00 00
197 * max scan time 64 00
198 * channel 2 00 02 00 00 00 64 00
202 header
->type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
203 header
->len
= cpu_to_le16(chanscanparamsize
);
204 tlv
+= sizeof(struct mrvl_ie_header
);
206 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
208 memset(tlv
, 0, chanscanparamsize
);
210 while (priv
->scan_channel
< last_channel
) {
211 struct chanscanparamset
*param
= (void *) tlv
;
213 param
->radiotype
= CMD_SCAN_RADIO_TYPE_BG
;
215 priv
->scan_req
->channels
[priv
->scan_channel
]->hw_value
;
217 param
->maxscantime
= cpu_to_le16(LBS_DWELL_ACTIVE
);
219 param
->chanscanmode
.passivescan
= 1;
220 param
->maxscantime
= cpu_to_le16(LBS_DWELL_PASSIVE
);
222 tlv
+= sizeof(struct chanscanparamset
);
223 priv
->scan_channel
++;
225 return sizeof(struct mrvl_ie_header
) + chanscanparamsize
;
232 * The rates are in lbs_bg_rates[], but for the 802.11b
233 * rates the high bit is set. We add this TLV only because
234 * there's a firmware which otherwise doesn't report all
237 #define LBS_MAX_RATES_TLV_SIZE \
238 (sizeof(struct mrvl_ie_header) \
239 + (ARRAY_SIZE(lbs_rates)))
241 /* Adds a TLV with all rates the hardware supports */
242 static int lbs_add_supported_rates_tlv(u8
*tlv
)
245 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
250 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
252 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
253 tlv
+= sizeof(rate_tlv
->header
);
254 i
= lbs_add_rates(tlv
);
256 rate_tlv
->header
.len
= cpu_to_le16(i
);
257 return sizeof(rate_tlv
->header
) + i
;
260 /* Add common rates from a TLV and return the new end of the TLV */
262 add_ie_rates(u8
*tlv
, const u8
*ie
, int *nrates
)
264 int hw
, ap
, ap_max
= ie
[1];
267 /* Advance past IE header */
270 lbs_deb_hex(LBS_DEB_ASSOC
, "AP IE Rates", (u8
*) ie
, ap_max
);
272 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
273 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
274 for (ap
= 0; ap
< ap_max
; ap
++) {
275 if (hw_rate
== (ie
[ap
] & 0x7f)) {
277 *nrates
= *nrates
+ 1;
285 * Adds a TLV with all rates the hardware *and* BSS supports.
287 static int lbs_add_common_rates_tlv(u8
*tlv
, struct cfg80211_bss
*bss
)
289 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
290 const u8
*rates_eid
, *ext_rates_eid
;
293 rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
294 ext_rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_EXT_SUPP_RATES
);
297 * 01 00 TLV_TYPE_RATES
301 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
302 tlv
+= sizeof(rate_tlv
->header
);
304 /* Add basic rates */
306 tlv
= add_ie_rates(tlv
, rates_eid
, &n
);
308 /* Add extended rates, if any */
310 tlv
= add_ie_rates(tlv
, ext_rates_eid
, &n
);
312 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
313 /* Fallback: add basic 802.11b rates */
321 rate_tlv
->header
.len
= cpu_to_le16(n
);
322 return sizeof(rate_tlv
->header
) + n
;
329 * This is only needed for newer firmware (V9 and up).
331 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
332 sizeof(struct mrvl_ie_auth_type)
334 static int lbs_add_auth_type_tlv(u8
*tlv
, enum nl80211_auth_type auth_type
)
336 struct mrvl_ie_auth_type
*auth
= (void *) tlv
;
339 * 1f 01 TLV_TYPE_AUTH_TYPE
343 auth
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
344 auth
->header
.len
= cpu_to_le16(sizeof(*auth
)-sizeof(auth
->header
));
345 auth
->auth
= cpu_to_le16(lbs_auth_to_authtype(auth_type
));
346 return sizeof(*auth
);
351 * Add channel (phy ds) TLV
353 #define LBS_MAX_CHANNEL_TLV_SIZE \
354 sizeof(struct mrvl_ie_header)
356 static int lbs_add_channel_tlv(u8
*tlv
, u8 channel
)
358 struct mrvl_ie_ds_param_set
*ds
= (void *) tlv
;
361 * 03 00 TLV_TYPE_PHY_DS
365 ds
->header
.type
= cpu_to_le16(TLV_TYPE_PHY_DS
);
366 ds
->header
.len
= cpu_to_le16(sizeof(*ds
)-sizeof(ds
->header
));
367 ds
->channel
= channel
;
373 * Add (empty) CF param TLV of the form:
375 #define LBS_MAX_CF_PARAM_TLV_SIZE \
376 sizeof(struct mrvl_ie_header)
378 static int lbs_add_cf_param_tlv(u8
*tlv
)
380 struct mrvl_ie_cf_param_set
*cf
= (void *)tlv
;
387 * 00 00 cfpmaxduration
388 * 00 00 cfpdurationremaining
390 cf
->header
.type
= cpu_to_le16(TLV_TYPE_CF
);
391 cf
->header
.len
= cpu_to_le16(sizeof(*cf
)-sizeof(cf
->header
));
398 #define LBS_MAX_WPA_TLV_SIZE \
399 (sizeof(struct mrvl_ie_header) \
400 + 128 /* TODO: I guessed the size */)
402 static int lbs_add_wpa_tlv(u8
*tlv
, const u8
*ie
, u8 ie_len
)
407 * We need just convert an IE to an TLV. IEs use u8 for the header,
411 * but TLVs use __le16 instead:
418 tlv_len
= *tlv
++ = *ie
++;
422 /* the TLV is two bytes larger than the IE */
426 /***************************************************************************
430 static int lbs_cfg_set_channel(struct wiphy
*wiphy
,
431 struct net_device
*netdev
,
432 struct ieee80211_channel
*channel
,
433 enum nl80211_channel_type channel_type
)
435 struct lbs_private
*priv
= wiphy_priv(wiphy
);
438 lbs_deb_enter_args(LBS_DEB_CFG80211
, "freq %d, type %d",
439 channel
->center_freq
, channel_type
);
441 if (channel_type
!= NL80211_CHAN_NO_HT
)
444 ret
= lbs_set_channel(priv
, channel
->hw_value
);
447 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
453 /***************************************************************************
458 * When scanning, the firmware doesn't send a nul packet with the power-safe
459 * bit to the AP. So we cannot stay away from our current channel too long,
460 * otherwise we loose data. So take a "nap" while scanning every other
463 #define LBS_SCAN_BEFORE_NAP 4
467 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
468 * which isn't really an RSSI, as it becomes larger when moving away from
469 * the AP. Anyway, we need to convert that into mBm.
471 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
472 ((-(int)rssi + 3)*100)
474 static int lbs_ret_scan(struct lbs_private
*priv
, unsigned long dummy
,
475 struct cmd_header
*resp
)
477 struct cmd_ds_802_11_scan_rsp
*scanresp
= (void *)resp
;
486 lbs_deb_enter(LBS_DEB_CFG80211
);
488 bsssize
= get_unaligned_le16(&scanresp
->bssdescriptsize
);
489 nr_sets
= le16_to_cpu(scanresp
->nr_sets
);
491 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
492 nr_sets
, bsssize
, le16_to_cpu(resp
->size
));
500 * The general layout of the scan response is described in chapter
501 * 5.7.1. Basically we have a common part, then any number of BSS
502 * descriptor sections. Finally we have section with the same number
505 * cmd_ds_802_11_scan_rsp
518 * MrvlIEtypes_TsfFimestamp_t
524 pos
= scanresp
->bssdesc_and_tlvbuffer
;
526 tsfdesc
= pos
+ bsssize
;
527 tsfsize
= 4 + 8 * scanresp
->nr_sets
;
529 /* Validity check: we expect a Marvell-Local TLV */
530 i
= get_unaligned_le16(tsfdesc
);
532 if (i
!= TLV_TYPE_TSFTIMESTAMP
)
534 /* Validity check: the TLV holds TSF values with 8 bytes each, so
535 * the size in the TLV must match the nr_sets value */
536 i
= get_unaligned_le16(tsfdesc
);
538 if (i
/ 8 != scanresp
->nr_sets
)
541 for (i
= 0; i
< scanresp
->nr_sets
; i
++) {
550 const u8
*ssid
= NULL
;
552 DECLARE_SSID_BUF(ssid_buf
);
554 int len
= get_unaligned_le16(pos
);
562 /* Packet time stamp */
564 /* Beacon interval */
565 intvl
= get_unaligned_le16(pos
);
568 capa
= get_unaligned_le16(pos
);
571 /* To find out the channel, we must parse the IEs */
573 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
574 interval, capabilities */
575 ielen
= left
= len
- (6 + 1 + 8 + 2 + 2);
581 if (elen
> left
|| elen
== 0)
583 if (id
== WLAN_EID_DS_PARAMS
)
585 if (id
== WLAN_EID_SSID
) {
593 /* No channel, no luck */
595 struct wiphy
*wiphy
= priv
->wdev
->wiphy
;
596 int freq
= ieee80211_channel_to_frequency(chan_no
);
597 struct ieee80211_channel
*channel
=
598 ieee80211_get_channel(wiphy
, freq
);
600 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
602 bssid
, capa
, chan_no
,
603 print_ssid(ssid_buf
, ssid
, ssid_len
),
604 LBS_SCAN_RSSI_TO_MBM(rssi
)/100);
607 !(channel
->flags
& IEEE80211_CHAN_DISABLED
))
608 cfg80211_inform_bss(wiphy
, channel
,
609 bssid
, le64_to_cpu(*(__le64
*)tsfdesc
),
610 capa
, intvl
, ie
, ielen
,
611 LBS_SCAN_RSSI_TO_MBM(rssi
),
619 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
625 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
626 * TLV and a rates TLV. Determine the maximum size of them:
628 #define LBS_SCAN_MAX_CMD_SIZE \
629 (sizeof(struct cmd_ds_802_11_scan) \
630 + LBS_MAX_SSID_TLV_SIZE \
631 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
632 + LBS_MAX_RATES_TLV_SIZE)
635 * Assumes priv->scan_req is initialized and valid
636 * Assumes priv->scan_channel is initialized
638 static void lbs_scan_worker(struct work_struct
*work
)
640 struct lbs_private
*priv
=
641 container_of(work
, struct lbs_private
, scan_work
.work
);
642 struct cmd_ds_802_11_scan
*scan_cmd
;
643 u8
*tlv
; /* pointer into our current, growing TLV storage area */
645 int running
, carrier
;
647 lbs_deb_enter(LBS_DEB_SCAN
);
649 scan_cmd
= kzalloc(LBS_SCAN_MAX_CMD_SIZE
, GFP_KERNEL
);
650 if (scan_cmd
== NULL
)
651 goto out_no_scan_cmd
;
653 /* prepare fixed part of scan command */
654 scan_cmd
->bsstype
= CMD_BSS_TYPE_ANY
;
656 /* stop network while we're away from our main channel */
657 running
= !netif_queue_stopped(priv
->dev
);
658 carrier
= netif_carrier_ok(priv
->dev
);
660 netif_stop_queue(priv
->dev
);
662 netif_carrier_off(priv
->dev
);
664 /* prepare fixed part of scan command */
665 tlv
= scan_cmd
->tlvbuffer
;
668 if (priv
->scan_req
->n_ssids
)
669 tlv
+= lbs_add_ssid_tlv(tlv
,
670 priv
->scan_req
->ssids
[0].ssid
,
671 priv
->scan_req
->ssids
[0].ssid_len
);
673 /* add channel TLVs */
674 last_channel
= priv
->scan_channel
+ LBS_SCAN_BEFORE_NAP
;
675 if (last_channel
> priv
->scan_req
->n_channels
)
676 last_channel
= priv
->scan_req
->n_channels
;
677 tlv
+= lbs_add_channel_list_tlv(priv
, tlv
, last_channel
,
678 priv
->scan_req
->n_ssids
);
681 tlv
+= lbs_add_supported_rates_tlv(tlv
);
683 if (priv
->scan_channel
< priv
->scan_req
->n_channels
) {
684 cancel_delayed_work(&priv
->scan_work
);
685 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
686 msecs_to_jiffies(300));
689 /* This is the final data we are about to send */
690 scan_cmd
->hdr
.size
= cpu_to_le16(tlv
- (u8
*)scan_cmd
);
691 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_CMD", (void *)scan_cmd
,
693 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TLV", scan_cmd
->tlvbuffer
,
694 tlv
- scan_cmd
->tlvbuffer
);
696 __lbs_cmd(priv
, CMD_802_11_SCAN
, &scan_cmd
->hdr
,
697 le16_to_cpu(scan_cmd
->hdr
.size
),
700 if (priv
->scan_channel
>= priv
->scan_req
->n_channels
) {
702 if (priv
->internal_scan
)
703 kfree(priv
->scan_req
);
705 cfg80211_scan_done(priv
->scan_req
, false);
707 priv
->scan_req
= NULL
;
708 priv
->last_scan
= jiffies
;
711 /* Restart network */
713 netif_carrier_on(priv
->dev
);
714 if (running
&& !priv
->tx_pending_len
)
715 netif_wake_queue(priv
->dev
);
719 /* Wake up anything waiting on scan completion */
720 if (priv
->scan_req
== NULL
) {
721 lbs_deb_scan("scan: waking up waiters\n");
722 wake_up_all(&priv
->scan_q
);
726 lbs_deb_leave(LBS_DEB_SCAN
);
729 static void _internal_start_scan(struct lbs_private
*priv
, bool internal
,
730 struct cfg80211_scan_request
*request
)
732 lbs_deb_enter(LBS_DEB_CFG80211
);
734 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
735 request
->n_ssids
, request
->n_channels
, request
->ie_len
);
737 priv
->scan_channel
= 0;
738 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
739 msecs_to_jiffies(50));
741 priv
->scan_req
= request
;
742 priv
->internal_scan
= internal
;
744 lbs_deb_leave(LBS_DEB_CFG80211
);
747 static int lbs_cfg_scan(struct wiphy
*wiphy
,
748 struct net_device
*dev
,
749 struct cfg80211_scan_request
*request
)
751 struct lbs_private
*priv
= wiphy_priv(wiphy
);
754 lbs_deb_enter(LBS_DEB_CFG80211
);
756 if (priv
->scan_req
|| delayed_work_pending(&priv
->scan_work
)) {
757 /* old scan request not yet processed */
762 _internal_start_scan(priv
, false, request
);
764 if (priv
->surpriseremoved
)
768 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
775 /***************************************************************************
779 void lbs_send_disconnect_notification(struct lbs_private
*priv
)
781 lbs_deb_enter(LBS_DEB_CFG80211
);
783 cfg80211_disconnected(priv
->dev
,
788 lbs_deb_leave(LBS_DEB_CFG80211
);
791 void lbs_send_mic_failureevent(struct lbs_private
*priv
, u32 event
)
793 lbs_deb_enter(LBS_DEB_CFG80211
);
795 cfg80211_michael_mic_failure(priv
->dev
,
797 event
== MACREG_INT_CODE_MIC_ERR_MULTICAST
?
798 NL80211_KEYTYPE_GROUP
:
799 NL80211_KEYTYPE_PAIRWISE
,
804 lbs_deb_leave(LBS_DEB_CFG80211
);
810 /***************************************************************************
816 * This removes all WEP keys
818 static int lbs_remove_wep_keys(struct lbs_private
*priv
)
820 struct cmd_ds_802_11_set_wep cmd
;
823 lbs_deb_enter(LBS_DEB_CFG80211
);
825 memset(&cmd
, 0, sizeof(cmd
));
826 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
827 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
828 cmd
.action
= cpu_to_le16(CMD_ACT_REMOVE
);
830 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
832 lbs_deb_leave(LBS_DEB_CFG80211
);
839 static int lbs_set_wep_keys(struct lbs_private
*priv
)
841 struct cmd_ds_802_11_set_wep cmd
;
845 lbs_deb_enter(LBS_DEB_CFG80211
);
852 * action 02 00 ACT_ADD
854 * type for key 1 01 WEP40
858 * key 1 39 39 39 39 39 00 00 00
859 * 00 00 00 00 00 00 00 00
860 * key 2 00 00 00 00 00 00 00 00
861 * 00 00 00 00 00 00 00 00
862 * key 3 00 00 00 00 00 00 00 00
863 * 00 00 00 00 00 00 00 00
864 * key 4 00 00 00 00 00 00 00 00
866 if (priv
->wep_key_len
[0] || priv
->wep_key_len
[1] ||
867 priv
->wep_key_len
[2] || priv
->wep_key_len
[3]) {
868 /* Only set wep keys if we have at least one of them */
869 memset(&cmd
, 0, sizeof(cmd
));
870 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
871 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
872 cmd
.action
= cpu_to_le16(CMD_ACT_ADD
);
874 for (i
= 0; i
< 4; i
++) {
875 switch (priv
->wep_key_len
[i
]) {
876 case WLAN_KEY_LEN_WEP40
:
877 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
879 case WLAN_KEY_LEN_WEP104
:
880 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
886 memcpy(cmd
.keymaterial
[i
], priv
->wep_key
[i
],
887 priv
->wep_key_len
[i
]);
890 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
892 /* Otherwise remove all wep keys */
893 ret
= lbs_remove_wep_keys(priv
);
896 lbs_deb_leave(LBS_DEB_CFG80211
);
902 * Enable/Disable RSN status
904 static int lbs_enable_rsn(struct lbs_private
*priv
, int enable
)
906 struct cmd_ds_802_11_enable_rsn cmd
;
909 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", enable
);
916 * action 01 00 ACT_SET
919 memset(&cmd
, 0, sizeof(cmd
));
920 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
921 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
922 cmd
.enable
= cpu_to_le16(enable
);
924 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
926 lbs_deb_leave(LBS_DEB_CFG80211
);
932 * Set WPA/WPA key material
935 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
936 * get rid of WEXT, this should go into host.h */
938 struct cmd_key_material
{
939 struct cmd_header hdr
;
942 struct MrvlIEtype_keyParamSet param
;
945 static int lbs_set_key_material(struct lbs_private
*priv
,
948 u8
*key
, u16 key_len
)
950 struct cmd_key_material cmd
;
953 lbs_deb_enter(LBS_DEB_CFG80211
);
956 * Example for WPA (TKIP):
963 * TLV type 00 01 key param
965 * key type 01 00 TKIP
966 * key info 06 00 UNICAST | ENABLED
970 memset(&cmd
, 0, sizeof(cmd
));
971 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
972 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
973 cmd
.param
.type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
974 cmd
.param
.length
= cpu_to_le16(sizeof(cmd
.param
) - 4);
975 cmd
.param
.keytypeid
= cpu_to_le16(key_type
);
976 cmd
.param
.keyinfo
= cpu_to_le16(key_info
);
977 cmd
.param
.keylen
= cpu_to_le16(key_len
);
979 memcpy(cmd
.param
.key
, key
, key_len
);
981 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
983 lbs_deb_leave(LBS_DEB_CFG80211
);
989 * Sets the auth type (open, shared, etc) in the firmware. That
990 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
991 * command doesn't send an authentication frame at all, it just
992 * stores the auth_type.
994 static int lbs_set_authtype(struct lbs_private
*priv
,
995 struct cfg80211_connect_params
*sme
)
997 struct cmd_ds_802_11_authenticate cmd
;
1000 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", sme
->auth_type
);
1007 * BSS id 00 13 19 80 da 30
1009 * reserved 00 00 00 00 00 00 00 00 00 00
1011 memset(&cmd
, 0, sizeof(cmd
));
1012 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1014 memcpy(cmd
.bssid
, sme
->bssid
, ETH_ALEN
);
1015 /* convert auth_type */
1016 ret
= lbs_auth_to_authtype(sme
->auth_type
);
1021 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AUTHENTICATE
, &cmd
);
1024 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1030 * Create association request
1032 #define LBS_ASSOC_MAX_CMD_SIZE \
1033 (sizeof(struct cmd_ds_802_11_associate) \
1034 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1035 + LBS_MAX_SSID_TLV_SIZE \
1036 + LBS_MAX_CHANNEL_TLV_SIZE \
1037 + LBS_MAX_CF_PARAM_TLV_SIZE \
1038 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1039 + LBS_MAX_WPA_TLV_SIZE)
1041 static int lbs_associate(struct lbs_private
*priv
,
1042 struct cfg80211_bss
*bss
,
1043 struct cfg80211_connect_params
*sme
)
1045 struct cmd_ds_802_11_associate_response
*resp
;
1046 struct cmd_ds_802_11_associate
*cmd
= kzalloc(LBS_ASSOC_MAX_CMD_SIZE
,
1049 size_t len
, resp_ie_len
;
1052 u8
*pos
= &(cmd
->iebuf
[0]);
1055 lbs_deb_enter(LBS_DEB_CFG80211
);
1067 * BSS id 00 13 19 80 da 30
1068 * capabilities 11 00
1069 * listen interval 0a 00
1070 * beacon interval 00 00
1072 * TLVs xx (up to 512 bytes)
1074 cmd
->hdr
.command
= cpu_to_le16(CMD_802_11_ASSOCIATE
);
1076 /* Fill in static fields */
1077 memcpy(cmd
->bssid
, bss
->bssid
, ETH_ALEN
);
1078 cmd
->listeninterval
= cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL
);
1079 cmd
->capability
= cpu_to_le16(bss
->capability
);
1082 ssid_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SSID
);
1084 pos
+= lbs_add_ssid_tlv(pos
, ssid_eid
+ 2, ssid_eid
[1]);
1086 lbs_deb_assoc("no SSID\n");
1088 /* add DS param TLV */
1090 pos
+= lbs_add_channel_tlv(pos
, bss
->channel
->hw_value
);
1092 lbs_deb_assoc("no channel\n");
1094 /* add (empty) CF param TLV */
1095 pos
+= lbs_add_cf_param_tlv(pos
);
1098 tmp
= pos
+ 4; /* skip Marvell IE header */
1099 pos
+= lbs_add_common_rates_tlv(pos
, bss
);
1100 lbs_deb_hex(LBS_DEB_ASSOC
, "Common Rates", tmp
, pos
- tmp
);
1102 /* add auth type TLV */
1103 if (priv
->fwrelease
>= 0x09000000)
1104 pos
+= lbs_add_auth_type_tlv(pos
, sme
->auth_type
);
1106 /* add WPA/WPA2 TLV */
1107 if (sme
->ie
&& sme
->ie_len
)
1108 pos
+= lbs_add_wpa_tlv(pos
, sme
->ie
, sme
->ie_len
);
1110 len
= (sizeof(*cmd
) - sizeof(cmd
->iebuf
)) +
1111 (u16
)(pos
- (u8
*) &cmd
->iebuf
);
1112 cmd
->hdr
.size
= cpu_to_le16(len
);
1114 /* store for later use */
1115 memcpy(priv
->assoc_bss
, bss
->bssid
, ETH_ALEN
);
1117 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ASSOCIATE
, cmd
);
1122 /* generate connect message to cfg80211 */
1124 resp
= (void *) cmd
; /* recast for easier field access */
1125 status
= le16_to_cpu(resp
->statuscode
);
1127 /* Convert statis code of old firmware */
1128 if (priv
->fwrelease
< 0x09000000)
1133 lbs_deb_assoc("invalid association parameters\n");
1134 status
= WLAN_STATUS_CAPS_UNSUPPORTED
;
1137 lbs_deb_assoc("timer expired while waiting for AP\n");
1138 status
= WLAN_STATUS_AUTH_TIMEOUT
;
1141 lbs_deb_assoc("association refused by AP\n");
1142 status
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1145 lbs_deb_assoc("authentication refused by AP\n");
1146 status
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1149 lbs_deb_assoc("association failure %d\n", status
);
1150 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1153 lbs_deb_assoc("status %d, capability 0x%04x\n", status
,
1154 le16_to_cpu(resp
->capability
));
1156 resp_ie_len
= le16_to_cpu(resp
->hdr
.size
)
1159 cfg80211_connect_result(priv
->dev
,
1161 sme
->ie
, sme
->ie_len
,
1162 resp
->iebuf
, resp_ie_len
,
1167 /* TODO: get rid of priv->connect_status */
1168 priv
->connect_status
= LBS_CONNECTED
;
1169 netif_carrier_on(priv
->dev
);
1170 if (!priv
->tx_pending_len
)
1171 netif_tx_wake_all_queues(priv
->dev
);
1176 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1180 static struct cfg80211_scan_request
*
1181 _new_connect_scan_req(struct wiphy
*wiphy
, struct cfg80211_connect_params
*sme
)
1183 struct cfg80211_scan_request
*creq
= NULL
;
1184 int i
, n_channels
= 0;
1185 enum ieee80211_band band
;
1187 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1188 if (wiphy
->bands
[band
])
1189 n_channels
+= wiphy
->bands
[band
]->n_channels
;
1192 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1193 n_channels
* sizeof(void *),
1198 /* SSIDs come after channels */
1199 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1200 creq
->n_channels
= n_channels
;
1203 /* Scan all available channels */
1205 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
1208 if (!wiphy
->bands
[band
])
1211 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1212 /* ignore disabled channels */
1213 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1214 IEEE80211_CHAN_DISABLED
)
1217 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1222 /* Set real number of channels specified in creq->channels[] */
1223 creq
->n_channels
= i
;
1225 /* Scan for the SSID we're going to connect to */
1226 memcpy(creq
->ssids
[0].ssid
, sme
->ssid
, sme
->ssid_len
);
1227 creq
->ssids
[0].ssid_len
= sme
->ssid_len
;
1229 /* No channels found... */
1237 static int lbs_cfg_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1238 struct cfg80211_connect_params
*sme
)
1240 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1241 struct cfg80211_bss
*bss
= NULL
;
1243 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1245 lbs_deb_enter(LBS_DEB_CFG80211
);
1248 /* Run a scan if one isn't in-progress already and if the last
1249 * scan was done more than 2 seconds ago.
1251 if (priv
->scan_req
== NULL
&&
1252 time_after(jiffies
, priv
->last_scan
+ (2 * HZ
))) {
1253 struct cfg80211_scan_request
*creq
;
1255 creq
= _new_connect_scan_req(wiphy
, sme
);
1261 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1262 _internal_start_scan(priv
, true, creq
);
1265 /* Wait for any in-progress scan to complete */
1266 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1267 wait_event_interruptible_timeout(priv
->scan_q
,
1268 (priv
->scan_req
== NULL
),
1270 lbs_deb_assoc("assoc: scanning competed\n");
1273 /* Find the BSS we want using available scan results */
1274 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
,
1275 sme
->ssid
, sme
->ssid_len
,
1276 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
1278 lbs_pr_err("assoc: bss %pM not in scan results\n",
1283 lbs_deb_assoc("trying %pM\n", bss
->bssid
);
1284 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1285 sme
->crypto
.cipher_group
,
1286 sme
->key_idx
, sme
->key_len
);
1288 /* As this is a new connection, clear locally stored WEP keys */
1289 priv
->wep_tx_key
= 0;
1290 memset(priv
->wep_key
, 0, sizeof(priv
->wep_key
));
1291 memset(priv
->wep_key_len
, 0, sizeof(priv
->wep_key_len
));
1293 /* set/remove WEP keys */
1294 switch (sme
->crypto
.cipher_group
) {
1295 case WLAN_CIPHER_SUITE_WEP40
:
1296 case WLAN_CIPHER_SUITE_WEP104
:
1297 /* Store provided WEP keys in priv-> */
1298 priv
->wep_tx_key
= sme
->key_idx
;
1299 priv
->wep_key_len
[sme
->key_idx
] = sme
->key_len
;
1300 memcpy(priv
->wep_key
[sme
->key_idx
], sme
->key
, sme
->key_len
);
1301 /* Set WEP keys and WEP mode */
1302 lbs_set_wep_keys(priv
);
1303 priv
->mac_control
|= CMD_ACT_MAC_WEP_ENABLE
;
1304 lbs_set_mac_control(priv
);
1305 /* No RSN mode for WEP */
1306 lbs_enable_rsn(priv
, 0);
1308 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1310 * If we don't have no WEP, no WPA and no WPA2,
1311 * we remove all keys like in the WPA/WPA2 setup,
1312 * we just don't set RSN.
1314 * Therefore: fall-throught
1316 case WLAN_CIPHER_SUITE_TKIP
:
1317 case WLAN_CIPHER_SUITE_CCMP
:
1318 /* Remove WEP keys and WEP mode */
1319 lbs_remove_wep_keys(priv
);
1320 priv
->mac_control
&= ~CMD_ACT_MAC_WEP_ENABLE
;
1321 lbs_set_mac_control(priv
);
1323 /* clear the WPA/WPA2 keys */
1324 lbs_set_key_material(priv
,
1325 KEY_TYPE_ID_WEP
, /* doesn't matter */
1326 KEY_INFO_WPA_UNICAST
,
1328 lbs_set_key_material(priv
,
1329 KEY_TYPE_ID_WEP
, /* doesn't matter */
1332 /* RSN mode for WPA/WPA2 */
1333 lbs_enable_rsn(priv
, sme
->crypto
.cipher_group
!= 0);
1336 lbs_pr_err("unsupported cipher group 0x%x\n",
1337 sme
->crypto
.cipher_group
);
1342 lbs_set_authtype(priv
, sme
);
1343 lbs_set_radio(priv
, preamble
, 1);
1345 /* Do the actual association */
1346 ret
= lbs_associate(priv
, bss
, sme
);
1350 cfg80211_put_bss(bss
);
1351 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1355 static int lbs_cfg_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1358 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1359 struct cmd_ds_802_11_deauthenticate cmd
;
1361 lbs_deb_enter_args(LBS_DEB_CFG80211
, "reason_code %d", reason_code
);
1363 /* store for lbs_cfg_ret_disconnect() */
1364 priv
->disassoc_reason
= reason_code
;
1366 memset(&cmd
, 0, sizeof(cmd
));
1367 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1368 /* Mildly ugly to use a locally store my own BSSID ... */
1369 memcpy(cmd
.macaddr
, &priv
->assoc_bss
, ETH_ALEN
);
1370 cmd
.reasoncode
= cpu_to_le16(reason_code
);
1372 if (lbs_cmd_with_response(priv
, CMD_802_11_DEAUTHENTICATE
, &cmd
))
1375 cfg80211_disconnected(priv
->dev
,
1376 priv
->disassoc_reason
,
1379 priv
->connect_status
= LBS_DISCONNECTED
;
1385 static int lbs_cfg_set_default_key(struct wiphy
*wiphy
,
1386 struct net_device
*netdev
,
1389 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1391 lbs_deb_enter(LBS_DEB_CFG80211
);
1393 if (key_index
!= priv
->wep_tx_key
) {
1394 lbs_deb_assoc("set_default_key: to %d\n", key_index
);
1395 priv
->wep_tx_key
= key_index
;
1396 lbs_set_wep_keys(priv
);
1403 static int lbs_cfg_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1404 u8 idx
, const u8
*mac_addr
,
1405 struct key_params
*params
)
1407 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1412 lbs_deb_enter(LBS_DEB_CFG80211
);
1414 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1415 params
->cipher
, mac_addr
);
1416 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1417 idx
, params
->key_len
);
1418 if (params
->key_len
)
1419 lbs_deb_hex(LBS_DEB_CFG80211
, "KEY",
1420 params
->key
, params
->key_len
);
1422 lbs_deb_assoc("add_key: seq len %d\n", params
->seq_len
);
1423 if (params
->seq_len
)
1424 lbs_deb_hex(LBS_DEB_CFG80211
, "SEQ",
1425 params
->seq
, params
->seq_len
);
1427 switch (params
->cipher
) {
1428 case WLAN_CIPHER_SUITE_WEP40
:
1429 case WLAN_CIPHER_SUITE_WEP104
:
1430 /* actually compare if something has changed ... */
1431 if ((priv
->wep_key_len
[idx
] != params
->key_len
) ||
1432 memcmp(priv
->wep_key
[idx
],
1433 params
->key
, params
->key_len
) != 0) {
1434 priv
->wep_key_len
[idx
] = params
->key_len
;
1435 memcpy(priv
->wep_key
[idx
],
1436 params
->key
, params
->key_len
);
1437 lbs_set_wep_keys(priv
);
1440 case WLAN_CIPHER_SUITE_TKIP
:
1441 case WLAN_CIPHER_SUITE_CCMP
:
1442 key_info
= KEY_INFO_WPA_ENABLED
| ((idx
== 0)
1443 ? KEY_INFO_WPA_UNICAST
1444 : KEY_INFO_WPA_MCAST
);
1445 key_type
= (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1448 lbs_set_key_material(priv
,
1451 params
->key
, params
->key_len
);
1454 lbs_pr_err("unhandled cipher 0x%x\n", params
->cipher
);
1463 static int lbs_cfg_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1464 u8 key_index
, const u8
*mac_addr
)
1467 lbs_deb_enter(LBS_DEB_CFG80211
);
1469 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1470 key_index
, mac_addr
);
1473 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1475 * I think can keep this a NO-OP, because:
1477 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1478 * - neither "iw" nor "wpa_supplicant" won't call this during
1479 * an ongoing connection
1480 * - TODO: but I have to check if this is still true when
1481 * I set the AP to periodic re-keying
1482 * - we've not kzallec() something when we've added a key at
1483 * lbs_cfg_connect() or lbs_cfg_add_key().
1485 * This causes lbs_cfg_del_key() only called at disconnect time,
1486 * where we'd just waste time deleting a key that is not going
1487 * to be used anyway.
1489 if (key_index
< 3 && priv
->wep_key_len
[key_index
]) {
1490 priv
->wep_key_len
[key_index
] = 0;
1491 lbs_set_wep_keys(priv
);
1499 /***************************************************************************
1503 static int lbs_cfg_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1504 u8
*mac
, struct station_info
*sinfo
)
1506 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1511 lbs_deb_enter(LBS_DEB_CFG80211
);
1513 sinfo
->filled
|= STATION_INFO_TX_BYTES
|
1514 STATION_INFO_TX_PACKETS
|
1515 STATION_INFO_RX_BYTES
|
1516 STATION_INFO_RX_PACKETS
;
1517 sinfo
->tx_bytes
= priv
->dev
->stats
.tx_bytes
;
1518 sinfo
->tx_packets
= priv
->dev
->stats
.tx_packets
;
1519 sinfo
->rx_bytes
= priv
->dev
->stats
.rx_bytes
;
1520 sinfo
->rx_packets
= priv
->dev
->stats
.rx_packets
;
1522 /* Get current RSSI */
1523 ret
= lbs_get_rssi(priv
, &signal
, &noise
);
1525 sinfo
->signal
= signal
;
1526 sinfo
->filled
|= STATION_INFO_SIGNAL
;
1529 /* Convert priv->cur_rate from hw_value to NL80211 value */
1530 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
1531 if (priv
->cur_rate
== lbs_rates
[i
].hw_value
) {
1532 sinfo
->txrate
.legacy
= lbs_rates
[i
].bitrate
;
1533 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
1544 /***************************************************************************
1545 * "Site survey", here just current channel and noise level
1548 static int lbs_get_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
1549 int idx
, struct survey_info
*survey
)
1551 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1558 lbs_deb_enter(LBS_DEB_CFG80211
);
1560 survey
->channel
= ieee80211_get_channel(wiphy
,
1561 ieee80211_channel_to_frequency(priv
->channel
));
1563 ret
= lbs_get_rssi(priv
, &signal
, &noise
);
1565 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1566 survey
->noise
= noise
;
1569 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1576 /***************************************************************************
1580 static int lbs_change_intf(struct wiphy
*wiphy
, struct net_device
*dev
,
1581 enum nl80211_iftype type
, u32
*flags
,
1582 struct vif_params
*params
)
1584 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1587 lbs_deb_enter(LBS_DEB_CFG80211
);
1590 case NL80211_IFTYPE_MONITOR
:
1591 ret
= lbs_set_monitor_mode(priv
, 1);
1593 case NL80211_IFTYPE_STATION
:
1594 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1595 ret
= lbs_set_monitor_mode(priv
, 0);
1597 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 1);
1599 case NL80211_IFTYPE_ADHOC
:
1600 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1601 ret
= lbs_set_monitor_mode(priv
, 0);
1603 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 2);
1610 priv
->wdev
->iftype
= type
;
1612 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1618 /***************************************************************************
1622 /* The firmware needs the following bits masked out of the beacon-derived
1623 * capability field when associating/joining to a BSS:
1624 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1626 #define CAPINFO_MASK (~(0xda00))
1629 static void lbs_join_post(struct lbs_private
*priv
,
1630 struct cfg80211_ibss_params
*params
,
1631 u8
*bssid
, u16 capability
)
1633 u8 fake_ie
[2 + IEEE80211_MAX_SSID_LEN
+ /* ssid */
1634 2 + 4 + /* basic rates */
1635 2 + 1 + /* DS parameter */
1637 2 + 8]; /* extended rates */
1640 lbs_deb_enter(LBS_DEB_CFG80211
);
1643 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1644 * the real IE from the firmware. So we fabricate a fake IE based on
1645 * what the firmware actually sends (sniffed with wireshark).
1648 *fake
++ = WLAN_EID_SSID
;
1649 *fake
++ = params
->ssid_len
;
1650 memcpy(fake
, params
->ssid
, params
->ssid_len
);
1651 fake
+= params
->ssid_len
;
1652 /* Fake supported basic rates IE */
1653 *fake
++ = WLAN_EID_SUPP_RATES
;
1659 /* Fake DS channel IE */
1660 *fake
++ = WLAN_EID_DS_PARAMS
;
1662 *fake
++ = params
->channel
->hw_value
;
1663 /* Fake IBSS params IE */
1664 *fake
++ = WLAN_EID_IBSS_PARAMS
;
1666 *fake
++ = 0; /* ATIM=0 */
1668 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1669 * but I don't know how this could be checked */
1670 *fake
++ = WLAN_EID_EXT_SUPP_RATES
;
1680 lbs_deb_hex(LBS_DEB_CFG80211
, "IE", fake_ie
, fake
- fake_ie
);
1682 cfg80211_inform_bss(priv
->wdev
->wiphy
,
1687 params
->beacon_interval
,
1688 fake_ie
, fake
- fake_ie
,
1691 memcpy(priv
->wdev
->ssid
, params
->ssid
, params
->ssid_len
);
1692 priv
->wdev
->ssid_len
= params
->ssid_len
;
1694 cfg80211_ibss_joined(priv
->dev
, bssid
, GFP_KERNEL
);
1696 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1697 priv
->connect_status
= LBS_CONNECTED
;
1698 netif_carrier_on(priv
->dev
);
1699 if (!priv
->tx_pending_len
)
1700 netif_wake_queue(priv
->dev
);
1702 lbs_deb_leave(LBS_DEB_CFG80211
);
1705 static int lbs_ibss_join_existing(struct lbs_private
*priv
,
1706 struct cfg80211_ibss_params
*params
,
1707 struct cfg80211_bss
*bss
)
1709 const u8
*rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
1710 struct cmd_ds_802_11_ad_hoc_join cmd
;
1711 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1714 lbs_deb_enter(LBS_DEB_CFG80211
);
1716 /* TODO: set preamble based on scan result */
1717 ret
= lbs_set_radio(priv
, preamble
, 1);
1722 * Example CMD_802_11_AD_HOC_JOIN command:
1724 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1728 * bssid 02 27 27 97 2f 96
1729 * ssid 49 42 53 53 00 00 00 00
1730 * 00 00 00 00 00 00 00 00
1731 * 00 00 00 00 00 00 00 00
1732 * 00 00 00 00 00 00 00 00
1733 * type 02 CMD_BSS_TYPE_IBSS
1734 * beacon period 64 00
1736 * timestamp 00 00 00 00 00 00 00 00
1737 * localtime 00 00 00 00 00 00 00 00
1741 * reserveed 00 00 00 00
1744 * IE IBSS atim 00 00
1745 * reserved 00 00 00 00
1747 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1748 * fail timeout ff 00
1751 memset(&cmd
, 0, sizeof(cmd
));
1752 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1754 memcpy(cmd
.bss
.bssid
, bss
->bssid
, ETH_ALEN
);
1755 memcpy(cmd
.bss
.ssid
, params
->ssid
, params
->ssid_len
);
1756 cmd
.bss
.type
= CMD_BSS_TYPE_IBSS
;
1757 cmd
.bss
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1758 cmd
.bss
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1759 cmd
.bss
.ds
.header
.len
= 1;
1760 cmd
.bss
.ds
.channel
= params
->channel
->hw_value
;
1761 cmd
.bss
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1762 cmd
.bss
.ibss
.header
.len
= 2;
1763 cmd
.bss
.ibss
.atimwindow
= 0;
1764 cmd
.bss
.capability
= cpu_to_le16(bss
->capability
& CAPINFO_MASK
);
1766 /* set rates to the intersection of our rates and the rates in the
1769 lbs_add_rates(cmd
.bss
.rates
);
1772 u8 rates_max
= rates_eid
[1];
1773 u8
*rates
= cmd
.bss
.rates
;
1774 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
1775 u8 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
1776 for (i
= 0; i
< rates_max
; i
++) {
1777 if (hw_rate
== (rates_eid
[i
+2] & 0x7f)) {
1778 u8 rate
= rates_eid
[i
+2];
1779 if (rate
== 0x02 || rate
== 0x04 ||
1780 rate
== 0x0b || rate
== 0x16)
1788 /* Only v8 and below support setting this */
1789 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1790 cmd
.failtimeout
= cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT
);
1791 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1793 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_JOIN
, &cmd
);
1798 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1806 lbs_join_post(priv
, params
, bss
->bssid
, bss
->capability
);
1809 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1815 static int lbs_ibss_start_new(struct lbs_private
*priv
,
1816 struct cfg80211_ibss_params
*params
)
1818 struct cmd_ds_802_11_ad_hoc_start cmd
;
1819 struct cmd_ds_802_11_ad_hoc_result
*resp
=
1820 (struct cmd_ds_802_11_ad_hoc_result
*) &cmd
;
1821 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1825 lbs_deb_enter(LBS_DEB_CFG80211
);
1827 ret
= lbs_set_radio(priv
, preamble
, 1);
1832 * Example CMD_802_11_AD_HOC_START command:
1834 * command 2b 00 CMD_802_11_AD_HOC_START
1838 * ssid 54 45 53 54 00 00 00 00
1839 * 00 00 00 00 00 00 00 00
1840 * 00 00 00 00 00 00 00 00
1841 * 00 00 00 00 00 00 00 00
1843 * beacon period 64 00
1847 * IE IBSS atim 00 00
1848 * reserved 00 00 00 00
1852 * reserved 00 00 00 00
1855 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1856 * 0c 12 18 24 30 48 60 6c
1859 memset(&cmd
, 0, sizeof(cmd
));
1860 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1861 memcpy(cmd
.ssid
, params
->ssid
, params
->ssid_len
);
1862 cmd
.bsstype
= CMD_BSS_TYPE_IBSS
;
1863 cmd
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1864 cmd
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1865 cmd
.ibss
.header
.len
= 2;
1866 cmd
.ibss
.atimwindow
= 0;
1867 cmd
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1868 cmd
.ds
.header
.len
= 1;
1869 cmd
.ds
.channel
= params
->channel
->hw_value
;
1870 /* Only v8 and below support setting probe delay */
1871 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8)
1872 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1873 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1874 capability
= WLAN_CAPABILITY_IBSS
;
1875 cmd
.capability
= cpu_to_le16(capability
);
1876 lbs_add_rates(cmd
.rates
);
1879 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_START
, &cmd
);
1884 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1891 * bssid 02 2b 7b 0f 86 0e
1893 lbs_join_post(priv
, params
, resp
->bssid
, capability
);
1896 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1901 static int lbs_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1902 struct cfg80211_ibss_params
*params
)
1904 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1906 struct cfg80211_bss
*bss
;
1907 DECLARE_SSID_BUF(ssid_buf
);
1909 lbs_deb_enter(LBS_DEB_CFG80211
);
1911 if (!params
->channel
) {
1916 ret
= lbs_set_channel(priv
, params
->channel
->hw_value
);
1920 /* Search if someone is beaconing. This assumes that the
1921 * bss list is populated already */
1922 bss
= cfg80211_get_bss(wiphy
, params
->channel
, params
->bssid
,
1923 params
->ssid
, params
->ssid_len
,
1924 WLAN_CAPABILITY_IBSS
, WLAN_CAPABILITY_IBSS
);
1927 ret
= lbs_ibss_join_existing(priv
, params
, bss
);
1928 cfg80211_put_bss(bss
);
1930 ret
= lbs_ibss_start_new(priv
, params
);
1934 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1939 static int lbs_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
1941 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1942 struct cmd_ds_802_11_ad_hoc_stop cmd
;
1945 lbs_deb_enter(LBS_DEB_CFG80211
);
1947 memset(&cmd
, 0, sizeof(cmd
));
1948 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1949 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_STOP
, &cmd
);
1951 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1952 lbs_mac_event_disconnected(priv
);
1954 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1961 /***************************************************************************
1965 static struct cfg80211_ops lbs_cfg80211_ops
= {
1966 .set_channel
= lbs_cfg_set_channel
,
1967 .scan
= lbs_cfg_scan
,
1968 .connect
= lbs_cfg_connect
,
1969 .disconnect
= lbs_cfg_disconnect
,
1970 .add_key
= lbs_cfg_add_key
,
1971 .del_key
= lbs_cfg_del_key
,
1972 .set_default_key
= lbs_cfg_set_default_key
,
1973 .get_station
= lbs_cfg_get_station
,
1974 .dump_survey
= lbs_get_survey
,
1975 .change_virtual_intf
= lbs_change_intf
,
1976 .join_ibss
= lbs_join_ibss
,
1977 .leave_ibss
= lbs_leave_ibss
,
1982 * At this time lbs_private *priv doesn't even exist, so we just allocate
1983 * memory and don't initialize the wiphy further. This is postponed until we
1984 * can talk to the firmware and happens at registration time in
1985 * lbs_cfg_wiphy_register().
1987 struct wireless_dev
*lbs_cfg_alloc(struct device
*dev
)
1990 struct wireless_dev
*wdev
;
1992 lbs_deb_enter(LBS_DEB_CFG80211
);
1994 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
1996 dev_err(dev
, "cannot allocate wireless device\n");
1997 return ERR_PTR(-ENOMEM
);
2000 wdev
->wiphy
= wiphy_new(&lbs_cfg80211_ops
, sizeof(struct lbs_private
));
2002 dev_err(dev
, "cannot allocate wiphy\n");
2007 lbs_deb_leave(LBS_DEB_CFG80211
);
2012 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2013 return ERR_PTR(ret
);
2017 static void lbs_cfg_set_regulatory_hint(struct lbs_private
*priv
)
2019 struct region_code_mapping
{
2024 /* Section 5.17.2 */
2025 static struct region_code_mapping regmap
[] = {
2026 {"US ", 0x10}, /* US FCC */
2027 {"CA ", 0x20}, /* Canada */
2028 {"EU ", 0x30}, /* ETSI */
2029 {"ES ", 0x31}, /* Spain */
2030 {"FR ", 0x32}, /* France */
2031 {"JP ", 0x40}, /* Japan */
2035 lbs_deb_enter(LBS_DEB_CFG80211
);
2037 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
2038 if (regmap
[i
].code
== priv
->regioncode
) {
2039 regulatory_hint(priv
->wdev
->wiphy
, regmap
[i
].cn
);
2043 lbs_deb_leave(LBS_DEB_CFG80211
);
2048 * This function get's called after lbs_setup_firmware() determined the
2049 * firmware capabities. So we can setup the wiphy according to our
2050 * hardware/firmware.
2052 int lbs_cfg_register(struct lbs_private
*priv
)
2054 struct wireless_dev
*wdev
= priv
->wdev
;
2057 lbs_deb_enter(LBS_DEB_CFG80211
);
2059 wdev
->wiphy
->max_scan_ssids
= 1;
2060 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
2062 wdev
->wiphy
->interface_modes
=
2063 BIT(NL80211_IFTYPE_STATION
) |
2064 BIT(NL80211_IFTYPE_ADHOC
);
2065 if (lbs_rtap_supported(priv
))
2066 wdev
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_MONITOR
);
2068 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &lbs_band_2ghz
;
2071 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2072 * never seen a firmware without WPA
2074 wdev
->wiphy
->cipher_suites
= cipher_suites
;
2075 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
2076 wdev
->wiphy
->reg_notifier
= lbs_reg_notifier
;
2078 ret
= wiphy_register(wdev
->wiphy
);
2080 lbs_pr_err("cannot register wiphy device\n");
2082 priv
->wiphy_registered
= true;
2084 ret
= register_netdev(priv
->dev
);
2086 lbs_pr_err("cannot register network device\n");
2088 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
2090 lbs_cfg_set_regulatory_hint(priv
);
2092 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2096 int lbs_reg_notifier(struct wiphy
*wiphy
,
2097 struct regulatory_request
*request
)
2099 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2102 lbs_deb_enter_args(LBS_DEB_CFG80211
, "cfg80211 regulatory domain "
2103 "callback for domain %c%c\n", request
->alpha2
[0],
2104 request
->alpha2
[1]);
2106 ret
= lbs_set_11d_domain_info(priv
, request
, wiphy
->bands
);
2108 lbs_deb_leave(LBS_DEB_CFG80211
);
2112 void lbs_scan_deinit(struct lbs_private
*priv
)
2114 lbs_deb_enter(LBS_DEB_CFG80211
);
2115 cancel_delayed_work_sync(&priv
->scan_work
);
2119 void lbs_cfg_free(struct lbs_private
*priv
)
2121 struct wireless_dev
*wdev
= priv
->wdev
;
2123 lbs_deb_enter(LBS_DEB_CFG80211
);
2128 if (priv
->wiphy_registered
)
2129 wiphy_unregister(wdev
->wiphy
);
2132 wiphy_free(wdev
->wiphy
);