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>
25 #define CHAN2G(_channel, _freq, _flags) { \
26 .band = NL80211_BAND_2GHZ, \
27 .center_freq = (_freq), \
28 .hw_value = (_channel), \
30 .max_antenna_gain = 0, \
34 static struct ieee80211_channel lbs_2ghz_channels
[] = {
51 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
53 .hw_value = (_hw_value), \
58 /* Table 6 in section 3.2.1.1 */
59 static struct ieee80211_rate lbs_rates
[] = {
60 RATETAB_ENT(10, 0, 0),
61 RATETAB_ENT(20, 1, 0),
62 RATETAB_ENT(55, 2, 0),
63 RATETAB_ENT(110, 3, 0),
64 RATETAB_ENT(60, 9, 0),
65 RATETAB_ENT(90, 6, 0),
66 RATETAB_ENT(120, 7, 0),
67 RATETAB_ENT(180, 8, 0),
68 RATETAB_ENT(240, 9, 0),
69 RATETAB_ENT(360, 10, 0),
70 RATETAB_ENT(480, 11, 0),
71 RATETAB_ENT(540, 12, 0),
74 static struct ieee80211_supported_band lbs_band_2ghz
= {
75 .channels
= lbs_2ghz_channels
,
76 .n_channels
= ARRAY_SIZE(lbs_2ghz_channels
),
77 .bitrates
= lbs_rates
,
78 .n_bitrates
= ARRAY_SIZE(lbs_rates
),
82 static const u32 cipher_suites
[] = {
83 WLAN_CIPHER_SUITE_WEP40
,
84 WLAN_CIPHER_SUITE_WEP104
,
85 WLAN_CIPHER_SUITE_TKIP
,
86 WLAN_CIPHER_SUITE_CCMP
,
89 /* Time to stay on the channel */
90 #define LBS_DWELL_PASSIVE 100
91 #define LBS_DWELL_ACTIVE 40
94 /***************************************************************************
95 * Misc utility functions
97 * TLVs are Marvell specific. They are very similar to IEs, they have the
98 * same structure: type, length, data*. The only difference: for IEs, the
99 * type and length are u8, but for TLVs they're __le16.
103 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
104 * in the firmware spec
106 static int lbs_auth_to_authtype(enum nl80211_auth_type auth_type
)
111 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
112 case NL80211_AUTHTYPE_SHARED_KEY
:
115 case NL80211_AUTHTYPE_AUTOMATIC
:
116 ret
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
118 case NL80211_AUTHTYPE_NETWORK_EAP
:
122 /* silence compiler */
130 * Various firmware commands need the list of supported rates, but with
131 * the hight-bit set for basic rates
133 static int lbs_add_rates(u8
*rates
)
137 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
138 u8 rate
= lbs_rates
[i
].bitrate
/ 5;
139 if (rate
== 0x02 || rate
== 0x04 ||
140 rate
== 0x0b || rate
== 0x16)
144 return ARRAY_SIZE(lbs_rates
);
148 /***************************************************************************
149 * TLV utility functions
151 * TLVs are Marvell specific. They are very similar to IEs, they have the
152 * same structure: type, length, data*. The only difference: for IEs, the
153 * type and length are u8, but for TLVs they're __le16.
160 #define LBS_MAX_SSID_TLV_SIZE \
161 (sizeof(struct mrvl_ie_header) \
162 + IEEE80211_MAX_SSID_LEN)
164 static int lbs_add_ssid_tlv(u8
*tlv
, const u8
*ssid
, int ssid_len
)
166 struct mrvl_ie_ssid_param_set
*ssid_tlv
= (void *)tlv
;
171 * ssid 4d 4e 54 45 53 54
173 ssid_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
174 ssid_tlv
->header
.len
= cpu_to_le16(ssid_len
);
175 memcpy(ssid_tlv
->ssid
, ssid
, ssid_len
);
176 return sizeof(ssid_tlv
->header
) + ssid_len
;
181 * Add channel list TLV (section 8.4.2)
183 * Actual channel data comes from priv->wdev->wiphy->channels.
185 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
186 (sizeof(struct mrvl_ie_header) \
187 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
189 static int lbs_add_channel_list_tlv(struct lbs_private
*priv
, u8
*tlv
,
190 int last_channel
, int active_scan
)
192 int chanscanparamsize
= sizeof(struct chanscanparamset
) *
193 (last_channel
- priv
->scan_channel
);
195 struct mrvl_ie_header
*header
= (void *) tlv
;
198 * TLV-ID CHANLIST 01 01
200 * channel 00 01 00 00 00 64 00
204 * min scan time 00 00
205 * max scan time 64 00
206 * channel 2 00 02 00 00 00 64 00
210 header
->type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
211 header
->len
= cpu_to_le16(chanscanparamsize
);
212 tlv
+= sizeof(struct mrvl_ie_header
);
214 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
216 memset(tlv
, 0, chanscanparamsize
);
218 while (priv
->scan_channel
< last_channel
) {
219 struct chanscanparamset
*param
= (void *) tlv
;
221 param
->radiotype
= CMD_SCAN_RADIO_TYPE_BG
;
223 priv
->scan_req
->channels
[priv
->scan_channel
]->hw_value
;
225 param
->maxscantime
= cpu_to_le16(LBS_DWELL_ACTIVE
);
227 param
->chanscanmode
.passivescan
= 1;
228 param
->maxscantime
= cpu_to_le16(LBS_DWELL_PASSIVE
);
230 tlv
+= sizeof(struct chanscanparamset
);
231 priv
->scan_channel
++;
233 return sizeof(struct mrvl_ie_header
) + chanscanparamsize
;
240 * The rates are in lbs_bg_rates[], but for the 802.11b
241 * rates the high bit is set. We add this TLV only because
242 * there's a firmware which otherwise doesn't report all
245 #define LBS_MAX_RATES_TLV_SIZE \
246 (sizeof(struct mrvl_ie_header) \
247 + (ARRAY_SIZE(lbs_rates)))
249 /* Adds a TLV with all rates the hardware supports */
250 static int lbs_add_supported_rates_tlv(u8
*tlv
)
253 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
258 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
260 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
261 tlv
+= sizeof(rate_tlv
->header
);
262 i
= lbs_add_rates(tlv
);
264 rate_tlv
->header
.len
= cpu_to_le16(i
);
265 return sizeof(rate_tlv
->header
) + i
;
268 /* Add common rates from a TLV and return the new end of the TLV */
270 add_ie_rates(u8
*tlv
, const u8
*ie
, int *nrates
)
272 int hw
, ap
, ap_max
= ie
[1];
275 /* Advance past IE header */
278 lbs_deb_hex(LBS_DEB_ASSOC
, "AP IE Rates", (u8
*) ie
, ap_max
);
280 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
281 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
282 for (ap
= 0; ap
< ap_max
; ap
++) {
283 if (hw_rate
== (ie
[ap
] & 0x7f)) {
285 *nrates
= *nrates
+ 1;
293 * Adds a TLV with all rates the hardware *and* BSS supports.
295 static int lbs_add_common_rates_tlv(u8
*tlv
, struct cfg80211_bss
*bss
)
297 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
298 const u8
*rates_eid
, *ext_rates_eid
;
302 rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
303 ext_rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_EXT_SUPP_RATES
);
306 * 01 00 TLV_TYPE_RATES
310 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
311 tlv
+= sizeof(rate_tlv
->header
);
313 /* Add basic rates */
315 tlv
= add_ie_rates(tlv
, rates_eid
, &n
);
317 /* Add extended rates, if any */
319 tlv
= add_ie_rates(tlv
, ext_rates_eid
, &n
);
321 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
322 /* Fallback: add basic 802.11b rates */
331 rate_tlv
->header
.len
= cpu_to_le16(n
);
332 return sizeof(rate_tlv
->header
) + n
;
339 * This is only needed for newer firmware (V9 and up).
341 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
342 sizeof(struct mrvl_ie_auth_type)
344 static int lbs_add_auth_type_tlv(u8
*tlv
, enum nl80211_auth_type auth_type
)
346 struct mrvl_ie_auth_type
*auth
= (void *) tlv
;
349 * 1f 01 TLV_TYPE_AUTH_TYPE
353 auth
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
354 auth
->header
.len
= cpu_to_le16(sizeof(*auth
)-sizeof(auth
->header
));
355 auth
->auth
= cpu_to_le16(lbs_auth_to_authtype(auth_type
));
356 return sizeof(*auth
);
361 * Add channel (phy ds) TLV
363 #define LBS_MAX_CHANNEL_TLV_SIZE \
364 sizeof(struct mrvl_ie_header)
366 static int lbs_add_channel_tlv(u8
*tlv
, u8 channel
)
368 struct mrvl_ie_ds_param_set
*ds
= (void *) tlv
;
371 * 03 00 TLV_TYPE_PHY_DS
375 ds
->header
.type
= cpu_to_le16(TLV_TYPE_PHY_DS
);
376 ds
->header
.len
= cpu_to_le16(sizeof(*ds
)-sizeof(ds
->header
));
377 ds
->channel
= channel
;
383 * Add (empty) CF param TLV of the form:
385 #define LBS_MAX_CF_PARAM_TLV_SIZE \
386 sizeof(struct mrvl_ie_header)
388 static int lbs_add_cf_param_tlv(u8
*tlv
)
390 struct mrvl_ie_cf_param_set
*cf
= (void *)tlv
;
397 * 00 00 cfpmaxduration
398 * 00 00 cfpdurationremaining
400 cf
->header
.type
= cpu_to_le16(TLV_TYPE_CF
);
401 cf
->header
.len
= cpu_to_le16(sizeof(*cf
)-sizeof(cf
->header
));
408 #define LBS_MAX_WPA_TLV_SIZE \
409 (sizeof(struct mrvl_ie_header) \
410 + 128 /* TODO: I guessed the size */)
412 static int lbs_add_wpa_tlv(u8
*tlv
, const u8
*ie
, u8 ie_len
)
417 * We need just convert an IE to an TLV. IEs use u8 for the header,
421 * but TLVs use __le16 instead:
428 tlv_len
= *tlv
++ = *ie
++;
432 /* the TLV is two bytes larger than the IE */
440 static int lbs_cfg_set_monitor_channel(struct wiphy
*wiphy
,
441 struct cfg80211_chan_def
*chandef
)
443 struct lbs_private
*priv
= wiphy_priv(wiphy
);
446 lbs_deb_enter_args(LBS_DEB_CFG80211
, "freq %d, type %d",
447 chandef
->chan
->center_freq
,
448 cfg80211_get_chandef_type(chandef
));
450 if (cfg80211_get_chandef_type(chandef
) != NL80211_CHAN_NO_HT
)
453 ret
= lbs_set_channel(priv
, chandef
->chan
->hw_value
);
456 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
460 static int lbs_cfg_set_mesh_channel(struct wiphy
*wiphy
,
461 struct net_device
*netdev
,
462 struct ieee80211_channel
*channel
)
464 struct lbs_private
*priv
= wiphy_priv(wiphy
);
467 lbs_deb_enter_args(LBS_DEB_CFG80211
, "iface %s freq %d",
468 netdev_name(netdev
), channel
->center_freq
);
470 if (netdev
!= priv
->mesh_dev
)
473 ret
= lbs_mesh_set_channel(priv
, channel
->hw_value
);
476 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
487 * When scanning, the firmware doesn't send a nul packet with the power-safe
488 * bit to the AP. So we cannot stay away from our current channel too long,
489 * otherwise we loose data. So take a "nap" while scanning every other
492 #define LBS_SCAN_BEFORE_NAP 4
496 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
497 * which isn't really an RSSI, as it becomes larger when moving away from
498 * the AP. Anyway, we need to convert that into mBm.
500 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
501 ((-(int)rssi + 3)*100)
503 static int lbs_ret_scan(struct lbs_private
*priv
, unsigned long dummy
,
504 struct cmd_header
*resp
)
506 struct cfg80211_bss
*bss
;
507 struct cmd_ds_802_11_scan_rsp
*scanresp
= (void *)resp
;
515 lbs_deb_enter(LBS_DEB_CFG80211
);
517 bsssize
= get_unaligned_le16(&scanresp
->bssdescriptsize
);
519 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
520 scanresp
->nr_sets
, bsssize
, le16_to_cpu(resp
->size
));
522 if (scanresp
->nr_sets
== 0) {
528 * The general layout of the scan response is described in chapter
529 * 5.7.1. Basically we have a common part, then any number of BSS
530 * descriptor sections. Finally we have section with the same number
533 * cmd_ds_802_11_scan_rsp
546 * MrvlIEtypes_TsfFimestamp_t
552 pos
= scanresp
->bssdesc_and_tlvbuffer
;
554 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_RSP", scanresp
->bssdesc_and_tlvbuffer
,
555 scanresp
->bssdescriptsize
);
557 tsfdesc
= pos
+ bsssize
;
558 tsfsize
= 4 + 8 * scanresp
->nr_sets
;
559 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TSF", (u8
*) tsfdesc
, tsfsize
);
561 /* Validity check: we expect a Marvell-Local TLV */
562 i
= get_unaligned_le16(tsfdesc
);
564 if (i
!= TLV_TYPE_TSFTIMESTAMP
) {
565 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i
);
570 * Validity check: the TLV holds TSF values with 8 bytes each, so
571 * the size in the TLV must match the nr_sets value
573 i
= get_unaligned_le16(tsfdesc
);
575 if (i
/ 8 != scanresp
->nr_sets
) {
576 lbs_deb_scan("scan response: invalid number of TSF timestamp "
577 "sets (expected %d got %d)\n", scanresp
->nr_sets
,
582 for (i
= 0; i
< scanresp
->nr_sets
; i
++) {
591 const u8
*ssid
= NULL
;
594 int len
= get_unaligned_le16(pos
);
602 /* Packet time stamp */
604 /* Beacon interval */
605 intvl
= get_unaligned_le16(pos
);
608 capa
= get_unaligned_le16(pos
);
611 /* To find out the channel, we must parse the IEs */
614 * 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
615 * interval, capabilities
617 ielen
= left
= len
- (6 + 1 + 8 + 2 + 2);
624 lbs_deb_scan("scan response: invalid IE fmt\n");
628 if (id
== WLAN_EID_DS_PARAMS
)
630 if (id
== WLAN_EID_SSID
) {
638 /* No channel, no luck */
640 struct wiphy
*wiphy
= priv
->wdev
->wiphy
;
641 int freq
= ieee80211_channel_to_frequency(chan_no
,
643 struct ieee80211_channel
*channel
=
644 ieee80211_get_channel(wiphy
, freq
);
646 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %*pE, %d dBm\n",
647 bssid
, capa
, chan_no
, ssid_len
, ssid
,
648 LBS_SCAN_RSSI_TO_MBM(rssi
)/100);
651 !(channel
->flags
& IEEE80211_CHAN_DISABLED
)) {
652 bss
= cfg80211_inform_bss(wiphy
, channel
,
653 CFG80211_BSS_FTYPE_UNKNOWN
,
654 bssid
, get_unaligned_le64(tsfdesc
),
655 capa
, intvl
, ie
, ielen
,
656 LBS_SCAN_RSSI_TO_MBM(rssi
),
658 cfg80211_put_bss(wiphy
, bss
);
661 lbs_deb_scan("scan response: missing BSS channel IE\n");
668 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
674 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
675 * TLV and a rates TLV. Determine the maximum size of them:
677 #define LBS_SCAN_MAX_CMD_SIZE \
678 (sizeof(struct cmd_ds_802_11_scan) \
679 + LBS_MAX_SSID_TLV_SIZE \
680 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
681 + LBS_MAX_RATES_TLV_SIZE)
684 * Assumes priv->scan_req is initialized and valid
685 * Assumes priv->scan_channel is initialized
687 static void lbs_scan_worker(struct work_struct
*work
)
689 struct lbs_private
*priv
=
690 container_of(work
, struct lbs_private
, scan_work
.work
);
691 struct cmd_ds_802_11_scan
*scan_cmd
;
692 u8
*tlv
; /* pointer into our current, growing TLV storage area */
694 int running
, carrier
;
696 lbs_deb_enter(LBS_DEB_SCAN
);
698 scan_cmd
= kzalloc(LBS_SCAN_MAX_CMD_SIZE
, GFP_KERNEL
);
699 if (scan_cmd
== NULL
)
700 goto out_no_scan_cmd
;
702 /* prepare fixed part of scan command */
703 scan_cmd
->bsstype
= CMD_BSS_TYPE_ANY
;
705 /* stop network while we're away from our main channel */
706 running
= !netif_queue_stopped(priv
->dev
);
707 carrier
= netif_carrier_ok(priv
->dev
);
709 netif_stop_queue(priv
->dev
);
711 netif_carrier_off(priv
->dev
);
713 /* prepare fixed part of scan command */
714 tlv
= scan_cmd
->tlvbuffer
;
717 if (priv
->scan_req
->n_ssids
&& priv
->scan_req
->ssids
[0].ssid_len
> 0)
718 tlv
+= lbs_add_ssid_tlv(tlv
,
719 priv
->scan_req
->ssids
[0].ssid
,
720 priv
->scan_req
->ssids
[0].ssid_len
);
722 /* add channel TLVs */
723 last_channel
= priv
->scan_channel
+ LBS_SCAN_BEFORE_NAP
;
724 if (last_channel
> priv
->scan_req
->n_channels
)
725 last_channel
= priv
->scan_req
->n_channels
;
726 tlv
+= lbs_add_channel_list_tlv(priv
, tlv
, last_channel
,
727 priv
->scan_req
->n_ssids
);
730 tlv
+= lbs_add_supported_rates_tlv(tlv
);
732 if (priv
->scan_channel
< priv
->scan_req
->n_channels
) {
733 cancel_delayed_work(&priv
->scan_work
);
734 if (netif_running(priv
->dev
))
735 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
736 msecs_to_jiffies(300));
739 /* This is the final data we are about to send */
740 scan_cmd
->hdr
.size
= cpu_to_le16(tlv
- (u8
*)scan_cmd
);
741 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_CMD", (void *)scan_cmd
,
743 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TLV", scan_cmd
->tlvbuffer
,
744 tlv
- scan_cmd
->tlvbuffer
);
746 __lbs_cmd(priv
, CMD_802_11_SCAN
, &scan_cmd
->hdr
,
747 le16_to_cpu(scan_cmd
->hdr
.size
),
750 if (priv
->scan_channel
>= priv
->scan_req
->n_channels
) {
752 cancel_delayed_work(&priv
->scan_work
);
756 /* Restart network */
758 netif_carrier_on(priv
->dev
);
759 if (running
&& !priv
->tx_pending_len
)
760 netif_wake_queue(priv
->dev
);
764 /* Wake up anything waiting on scan completion */
765 if (priv
->scan_req
== NULL
) {
766 lbs_deb_scan("scan: waking up waiters\n");
767 wake_up_all(&priv
->scan_q
);
771 lbs_deb_leave(LBS_DEB_SCAN
);
774 static void _internal_start_scan(struct lbs_private
*priv
, bool internal
,
775 struct cfg80211_scan_request
*request
)
777 lbs_deb_enter(LBS_DEB_CFG80211
);
779 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
780 request
->n_ssids
, request
->n_channels
, request
->ie_len
);
782 priv
->scan_channel
= 0;
783 priv
->scan_req
= request
;
784 priv
->internal_scan
= internal
;
786 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
787 msecs_to_jiffies(50));
789 lbs_deb_leave(LBS_DEB_CFG80211
);
793 * Clean up priv->scan_req. Should be used to handle the allocation details.
795 void lbs_scan_done(struct lbs_private
*priv
)
797 WARN_ON(!priv
->scan_req
);
799 if (priv
->internal_scan
) {
800 kfree(priv
->scan_req
);
802 struct cfg80211_scan_info info
= {
806 cfg80211_scan_done(priv
->scan_req
, &info
);
809 priv
->scan_req
= NULL
;
812 static int lbs_cfg_scan(struct wiphy
*wiphy
,
813 struct cfg80211_scan_request
*request
)
815 struct lbs_private
*priv
= wiphy_priv(wiphy
);
818 lbs_deb_enter(LBS_DEB_CFG80211
);
820 if (priv
->scan_req
|| delayed_work_pending(&priv
->scan_work
)) {
821 /* old scan request not yet processed */
826 _internal_start_scan(priv
, false, request
);
828 if (priv
->surpriseremoved
)
832 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
843 void lbs_send_disconnect_notification(struct lbs_private
*priv
,
844 bool locally_generated
)
846 lbs_deb_enter(LBS_DEB_CFG80211
);
848 cfg80211_disconnected(priv
->dev
, 0, NULL
, 0, locally_generated
,
851 lbs_deb_leave(LBS_DEB_CFG80211
);
854 void lbs_send_mic_failureevent(struct lbs_private
*priv
, u32 event
)
856 lbs_deb_enter(LBS_DEB_CFG80211
);
858 cfg80211_michael_mic_failure(priv
->dev
,
860 event
== MACREG_INT_CODE_MIC_ERR_MULTICAST
?
861 NL80211_KEYTYPE_GROUP
:
862 NL80211_KEYTYPE_PAIRWISE
,
867 lbs_deb_leave(LBS_DEB_CFG80211
);
879 * This removes all WEP keys
881 static int lbs_remove_wep_keys(struct lbs_private
*priv
)
883 struct cmd_ds_802_11_set_wep cmd
;
886 lbs_deb_enter(LBS_DEB_CFG80211
);
888 memset(&cmd
, 0, sizeof(cmd
));
889 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
890 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
891 cmd
.action
= cpu_to_le16(CMD_ACT_REMOVE
);
893 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
895 lbs_deb_leave(LBS_DEB_CFG80211
);
902 static int lbs_set_wep_keys(struct lbs_private
*priv
)
904 struct cmd_ds_802_11_set_wep cmd
;
908 lbs_deb_enter(LBS_DEB_CFG80211
);
915 * action 02 00 ACT_ADD
917 * type for key 1 01 WEP40
921 * key 1 39 39 39 39 39 00 00 00
922 * 00 00 00 00 00 00 00 00
923 * key 2 00 00 00 00 00 00 00 00
924 * 00 00 00 00 00 00 00 00
925 * key 3 00 00 00 00 00 00 00 00
926 * 00 00 00 00 00 00 00 00
927 * key 4 00 00 00 00 00 00 00 00
929 if (priv
->wep_key_len
[0] || priv
->wep_key_len
[1] ||
930 priv
->wep_key_len
[2] || priv
->wep_key_len
[3]) {
931 /* Only set wep keys if we have at least one of them */
932 memset(&cmd
, 0, sizeof(cmd
));
933 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
934 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
935 cmd
.action
= cpu_to_le16(CMD_ACT_ADD
);
937 for (i
= 0; i
< 4; i
++) {
938 switch (priv
->wep_key_len
[i
]) {
939 case WLAN_KEY_LEN_WEP40
:
940 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
942 case WLAN_KEY_LEN_WEP104
:
943 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
949 memcpy(cmd
.keymaterial
[i
], priv
->wep_key
[i
],
950 priv
->wep_key_len
[i
]);
953 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
955 /* Otherwise remove all wep keys */
956 ret
= lbs_remove_wep_keys(priv
);
959 lbs_deb_leave(LBS_DEB_CFG80211
);
965 * Enable/Disable RSN status
967 static int lbs_enable_rsn(struct lbs_private
*priv
, int enable
)
969 struct cmd_ds_802_11_enable_rsn cmd
;
972 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", enable
);
979 * action 01 00 ACT_SET
982 memset(&cmd
, 0, sizeof(cmd
));
983 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
984 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
985 cmd
.enable
= cpu_to_le16(enable
);
987 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
989 lbs_deb_leave(LBS_DEB_CFG80211
);
995 * Set WPA/WPA key material
999 * like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
1000 * get rid of WEXT, this should go into host.h
1003 struct cmd_key_material
{
1004 struct cmd_header hdr
;
1007 struct MrvlIEtype_keyParamSet param
;
1010 static int lbs_set_key_material(struct lbs_private
*priv
,
1011 int key_type
, int key_info
,
1012 const u8
*key
, u16 key_len
)
1014 struct cmd_key_material cmd
;
1017 lbs_deb_enter(LBS_DEB_CFG80211
);
1020 * Example for WPA (TKIP):
1027 * TLV type 00 01 key param
1029 * key type 01 00 TKIP
1030 * key info 06 00 UNICAST | ENABLED
1034 memset(&cmd
, 0, sizeof(cmd
));
1035 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1036 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1037 cmd
.param
.type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
1038 cmd
.param
.length
= cpu_to_le16(sizeof(cmd
.param
) - 4);
1039 cmd
.param
.keytypeid
= cpu_to_le16(key_type
);
1040 cmd
.param
.keyinfo
= cpu_to_le16(key_info
);
1041 cmd
.param
.keylen
= cpu_to_le16(key_len
);
1043 memcpy(cmd
.param
.key
, key
, key_len
);
1045 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
1047 lbs_deb_leave(LBS_DEB_CFG80211
);
1053 * Sets the auth type (open, shared, etc) in the firmware. That
1054 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
1055 * command doesn't send an authentication frame at all, it just
1056 * stores the auth_type.
1058 static int lbs_set_authtype(struct lbs_private
*priv
,
1059 struct cfg80211_connect_params
*sme
)
1061 struct cmd_ds_802_11_authenticate cmd
;
1064 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", sme
->auth_type
);
1071 * BSS id 00 13 19 80 da 30
1073 * reserved 00 00 00 00 00 00 00 00 00 00
1075 memset(&cmd
, 0, sizeof(cmd
));
1076 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1078 memcpy(cmd
.bssid
, sme
->bssid
, ETH_ALEN
);
1079 /* convert auth_type */
1080 ret
= lbs_auth_to_authtype(sme
->auth_type
);
1085 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AUTHENTICATE
, &cmd
);
1088 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1094 * Create association request
1096 #define LBS_ASSOC_MAX_CMD_SIZE \
1097 (sizeof(struct cmd_ds_802_11_associate) \
1098 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1099 + LBS_MAX_SSID_TLV_SIZE \
1100 + LBS_MAX_CHANNEL_TLV_SIZE \
1101 + LBS_MAX_CF_PARAM_TLV_SIZE \
1102 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1103 + LBS_MAX_WPA_TLV_SIZE)
1105 static int lbs_associate(struct lbs_private
*priv
,
1106 struct cfg80211_bss
*bss
,
1107 struct cfg80211_connect_params
*sme
)
1109 struct cmd_ds_802_11_associate_response
*resp
;
1110 struct cmd_ds_802_11_associate
*cmd
= kzalloc(LBS_ASSOC_MAX_CMD_SIZE
,
1113 size_t len
, resp_ie_len
;
1119 lbs_deb_enter(LBS_DEB_CFG80211
);
1125 pos
= &cmd
->iebuf
[0];
1132 * BSS id 00 13 19 80 da 30
1133 * capabilities 11 00
1134 * listen interval 0a 00
1135 * beacon interval 00 00
1137 * TLVs xx (up to 512 bytes)
1139 cmd
->hdr
.command
= cpu_to_le16(CMD_802_11_ASSOCIATE
);
1141 /* Fill in static fields */
1142 memcpy(cmd
->bssid
, bss
->bssid
, ETH_ALEN
);
1143 cmd
->listeninterval
= cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL
);
1144 cmd
->capability
= cpu_to_le16(bss
->capability
);
1148 ssid_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SSID
);
1150 pos
+= lbs_add_ssid_tlv(pos
, ssid_eid
+ 2, ssid_eid
[1]);
1152 lbs_deb_assoc("no SSID\n");
1155 /* add DS param TLV */
1157 pos
+= lbs_add_channel_tlv(pos
, bss
->channel
->hw_value
);
1159 lbs_deb_assoc("no channel\n");
1161 /* add (empty) CF param TLV */
1162 pos
+= lbs_add_cf_param_tlv(pos
);
1165 tmp
= pos
+ 4; /* skip Marvell IE header */
1166 pos
+= lbs_add_common_rates_tlv(pos
, bss
);
1167 lbs_deb_hex(LBS_DEB_ASSOC
, "Common Rates", tmp
, pos
- tmp
);
1169 /* add auth type TLV */
1170 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= 9)
1171 pos
+= lbs_add_auth_type_tlv(pos
, sme
->auth_type
);
1173 /* add WPA/WPA2 TLV */
1174 if (sme
->ie
&& sme
->ie_len
)
1175 pos
+= lbs_add_wpa_tlv(pos
, sme
->ie
, sme
->ie_len
);
1177 len
= (sizeof(*cmd
) - sizeof(cmd
->iebuf
)) +
1178 (u16
)(pos
- (u8
*) &cmd
->iebuf
);
1179 cmd
->hdr
.size
= cpu_to_le16(len
);
1181 lbs_deb_hex(LBS_DEB_ASSOC
, "ASSOC_CMD", (u8
*) cmd
,
1182 le16_to_cpu(cmd
->hdr
.size
));
1184 /* store for later use */
1185 memcpy(priv
->assoc_bss
, bss
->bssid
, ETH_ALEN
);
1187 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ASSOCIATE
, cmd
);
1191 /* generate connect message to cfg80211 */
1193 resp
= (void *) cmd
; /* recast for easier field access */
1194 status
= le16_to_cpu(resp
->statuscode
);
1196 /* Older FW versions map the IEEE 802.11 Status Code in the association
1197 * response to the following values returned in resp->statuscode:
1199 * IEEE Status Code Marvell Status Code
1200 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1201 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1202 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1203 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1204 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1205 * others -> 0x0003 ASSOC_RESULT_REFUSED
1207 * Other response codes:
1208 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1209 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1210 * association response from the AP)
1212 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1217 lbs_deb_assoc("invalid association parameters\n");
1218 status
= WLAN_STATUS_CAPS_UNSUPPORTED
;
1221 lbs_deb_assoc("timer expired while waiting for AP\n");
1222 status
= WLAN_STATUS_AUTH_TIMEOUT
;
1225 lbs_deb_assoc("association refused by AP\n");
1226 status
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1229 lbs_deb_assoc("authentication refused by AP\n");
1230 status
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1233 lbs_deb_assoc("association failure %d\n", status
);
1234 /* v5 OLPC firmware does return the AP status code if
1235 * it's not one of the values above. Let that through.
1241 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1242 "aid 0x%04x\n", status
, le16_to_cpu(resp
->statuscode
),
1243 le16_to_cpu(resp
->capability
), le16_to_cpu(resp
->aid
));
1245 resp_ie_len
= le16_to_cpu(resp
->hdr
.size
)
1248 cfg80211_connect_result(priv
->dev
,
1250 sme
->ie
, sme
->ie_len
,
1251 resp
->iebuf
, resp_ie_len
,
1256 /* TODO: get rid of priv->connect_status */
1257 priv
->connect_status
= LBS_CONNECTED
;
1258 netif_carrier_on(priv
->dev
);
1259 if (!priv
->tx_pending_len
)
1260 netif_tx_wake_all_queues(priv
->dev
);
1265 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1269 static struct cfg80211_scan_request
*
1270 _new_connect_scan_req(struct wiphy
*wiphy
, struct cfg80211_connect_params
*sme
)
1272 struct cfg80211_scan_request
*creq
= NULL
;
1273 int i
, n_channels
= ieee80211_get_num_supported_channels(wiphy
);
1274 enum nl80211_band band
;
1276 creq
= kzalloc(sizeof(*creq
) + sizeof(struct cfg80211_ssid
) +
1277 n_channels
* sizeof(void *),
1282 /* SSIDs come after channels */
1283 creq
->ssids
= (void *)&creq
->channels
[n_channels
];
1284 creq
->n_channels
= n_channels
;
1287 /* Scan all available channels */
1289 for (band
= 0; band
< NUM_NL80211_BANDS
; band
++) {
1292 if (!wiphy
->bands
[band
])
1295 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
1296 /* ignore disabled channels */
1297 if (wiphy
->bands
[band
]->channels
[j
].flags
&
1298 IEEE80211_CHAN_DISABLED
)
1301 creq
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
1306 /* Set real number of channels specified in creq->channels[] */
1307 creq
->n_channels
= i
;
1309 /* Scan for the SSID we're going to connect to */
1310 memcpy(creq
->ssids
[0].ssid
, sme
->ssid
, sme
->ssid_len
);
1311 creq
->ssids
[0].ssid_len
= sme
->ssid_len
;
1313 /* No channels found... */
1321 static int lbs_cfg_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1322 struct cfg80211_connect_params
*sme
)
1324 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1325 struct cfg80211_bss
*bss
= NULL
;
1327 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1329 if (dev
== priv
->mesh_dev
)
1332 lbs_deb_enter(LBS_DEB_CFG80211
);
1335 struct cfg80211_scan_request
*creq
;
1338 * Scan for the requested network after waiting for existing
1341 lbs_deb_assoc("assoc: waiting for existing scans\n");
1342 wait_event_interruptible_timeout(priv
->scan_q
,
1343 (priv
->scan_req
== NULL
),
1346 creq
= _new_connect_scan_req(wiphy
, sme
);
1352 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1353 _internal_start_scan(priv
, true, creq
);
1355 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1356 wait_event_interruptible_timeout(priv
->scan_q
,
1357 (priv
->scan_req
== NULL
),
1359 lbs_deb_assoc("assoc: scanning completed\n");
1362 /* Find the BSS we want using available scan results */
1363 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
,
1364 sme
->ssid
, sme
->ssid_len
, IEEE80211_BSS_TYPE_ESS
,
1365 IEEE80211_PRIVACY_ANY
);
1367 wiphy_err(wiphy
, "assoc: bss %pM not in scan results\n",
1372 lbs_deb_assoc("trying %pM\n", bss
->bssid
);
1373 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1374 sme
->crypto
.cipher_group
,
1375 sme
->key_idx
, sme
->key_len
);
1377 /* As this is a new connection, clear locally stored WEP keys */
1378 priv
->wep_tx_key
= 0;
1379 memset(priv
->wep_key
, 0, sizeof(priv
->wep_key
));
1380 memset(priv
->wep_key_len
, 0, sizeof(priv
->wep_key_len
));
1382 /* set/remove WEP keys */
1383 switch (sme
->crypto
.cipher_group
) {
1384 case WLAN_CIPHER_SUITE_WEP40
:
1385 case WLAN_CIPHER_SUITE_WEP104
:
1386 /* Store provided WEP keys in priv-> */
1387 priv
->wep_tx_key
= sme
->key_idx
;
1388 priv
->wep_key_len
[sme
->key_idx
] = sme
->key_len
;
1389 memcpy(priv
->wep_key
[sme
->key_idx
], sme
->key
, sme
->key_len
);
1390 /* Set WEP keys and WEP mode */
1391 lbs_set_wep_keys(priv
);
1392 priv
->mac_control
|= CMD_ACT_MAC_WEP_ENABLE
;
1393 lbs_set_mac_control(priv
);
1394 /* No RSN mode for WEP */
1395 lbs_enable_rsn(priv
, 0);
1397 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1399 * If we don't have no WEP, no WPA and no WPA2,
1400 * we remove all keys like in the WPA/WPA2 setup,
1401 * we just don't set RSN.
1403 * Therefore: fall-through
1405 case WLAN_CIPHER_SUITE_TKIP
:
1406 case WLAN_CIPHER_SUITE_CCMP
:
1407 /* Remove WEP keys and WEP mode */
1408 lbs_remove_wep_keys(priv
);
1409 priv
->mac_control
&= ~CMD_ACT_MAC_WEP_ENABLE
;
1410 lbs_set_mac_control(priv
);
1412 /* clear the WPA/WPA2 keys */
1413 lbs_set_key_material(priv
,
1414 KEY_TYPE_ID_WEP
, /* doesn't matter */
1415 KEY_INFO_WPA_UNICAST
,
1417 lbs_set_key_material(priv
,
1418 KEY_TYPE_ID_WEP
, /* doesn't matter */
1421 /* RSN mode for WPA/WPA2 */
1422 lbs_enable_rsn(priv
, sme
->crypto
.cipher_group
!= 0);
1425 wiphy_err(wiphy
, "unsupported cipher group 0x%x\n",
1426 sme
->crypto
.cipher_group
);
1431 ret
= lbs_set_authtype(priv
, sme
);
1432 if (ret
== -ENOTSUPP
) {
1433 wiphy_err(wiphy
, "unsupported authtype 0x%x\n", sme
->auth_type
);
1437 lbs_set_radio(priv
, preamble
, 1);
1439 /* Do the actual association */
1440 ret
= lbs_associate(priv
, bss
, sme
);
1444 cfg80211_put_bss(wiphy
, bss
);
1445 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1449 int lbs_disconnect(struct lbs_private
*priv
, u16 reason
)
1451 struct cmd_ds_802_11_deauthenticate cmd
;
1454 memset(&cmd
, 0, sizeof(cmd
));
1455 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1456 /* Mildly ugly to use a locally store my own BSSID ... */
1457 memcpy(cmd
.macaddr
, &priv
->assoc_bss
, ETH_ALEN
);
1458 cmd
.reasoncode
= cpu_to_le16(reason
);
1460 ret
= lbs_cmd_with_response(priv
, CMD_802_11_DEAUTHENTICATE
, &cmd
);
1464 cfg80211_disconnected(priv
->dev
,
1468 priv
->connect_status
= LBS_DISCONNECTED
;
1473 static int lbs_cfg_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1476 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1478 if (dev
== priv
->mesh_dev
)
1481 lbs_deb_enter_args(LBS_DEB_CFG80211
, "reason_code %d", reason_code
);
1483 /* store for lbs_cfg_ret_disconnect() */
1484 priv
->disassoc_reason
= reason_code
;
1486 return lbs_disconnect(priv
, reason_code
);
1489 static int lbs_cfg_set_default_key(struct wiphy
*wiphy
,
1490 struct net_device
*netdev
,
1491 u8 key_index
, bool unicast
,
1494 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1496 if (netdev
== priv
->mesh_dev
)
1499 lbs_deb_enter(LBS_DEB_CFG80211
);
1501 if (key_index
!= priv
->wep_tx_key
) {
1502 lbs_deb_assoc("set_default_key: to %d\n", key_index
);
1503 priv
->wep_tx_key
= key_index
;
1504 lbs_set_wep_keys(priv
);
1511 static int lbs_cfg_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1512 u8 idx
, bool pairwise
, const u8
*mac_addr
,
1513 struct key_params
*params
)
1515 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1520 if (netdev
== priv
->mesh_dev
)
1523 lbs_deb_enter(LBS_DEB_CFG80211
);
1525 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1526 params
->cipher
, mac_addr
);
1527 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1528 idx
, params
->key_len
);
1529 if (params
->key_len
)
1530 lbs_deb_hex(LBS_DEB_CFG80211
, "KEY",
1531 params
->key
, params
->key_len
);
1533 lbs_deb_assoc("add_key: seq len %d\n", params
->seq_len
);
1534 if (params
->seq_len
)
1535 lbs_deb_hex(LBS_DEB_CFG80211
, "SEQ",
1536 params
->seq
, params
->seq_len
);
1538 switch (params
->cipher
) {
1539 case WLAN_CIPHER_SUITE_WEP40
:
1540 case WLAN_CIPHER_SUITE_WEP104
:
1541 /* actually compare if something has changed ... */
1542 if ((priv
->wep_key_len
[idx
] != params
->key_len
) ||
1543 memcmp(priv
->wep_key
[idx
],
1544 params
->key
, params
->key_len
) != 0) {
1545 priv
->wep_key_len
[idx
] = params
->key_len
;
1546 memcpy(priv
->wep_key
[idx
],
1547 params
->key
, params
->key_len
);
1548 lbs_set_wep_keys(priv
);
1551 case WLAN_CIPHER_SUITE_TKIP
:
1552 case WLAN_CIPHER_SUITE_CCMP
:
1553 key_info
= KEY_INFO_WPA_ENABLED
| ((idx
== 0)
1554 ? KEY_INFO_WPA_UNICAST
1555 : KEY_INFO_WPA_MCAST
);
1556 key_type
= (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1559 lbs_set_key_material(priv
,
1562 params
->key
, params
->key_len
);
1565 wiphy_err(wiphy
, "unhandled cipher 0x%x\n", params
->cipher
);
1574 static int lbs_cfg_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1575 u8 key_index
, bool pairwise
, const u8
*mac_addr
)
1578 lbs_deb_enter(LBS_DEB_CFG80211
);
1580 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1581 key_index
, mac_addr
);
1584 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1586 * I think can keep this a NO-OP, because:
1588 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1589 * - neither "iw" nor "wpa_supplicant" won't call this during
1590 * an ongoing connection
1591 * - TODO: but I have to check if this is still true when
1592 * I set the AP to periodic re-keying
1593 * - we've not kzallec() something when we've added a key at
1594 * lbs_cfg_connect() or lbs_cfg_add_key().
1596 * This causes lbs_cfg_del_key() only called at disconnect time,
1597 * where we'd just waste time deleting a key that is not going
1598 * to be used anyway.
1600 if (key_index
< 3 && priv
->wep_key_len
[key_index
]) {
1601 priv
->wep_key_len
[key_index
] = 0;
1602 lbs_set_wep_keys(priv
);
1614 static int lbs_cfg_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1615 const u8
*mac
, struct station_info
*sinfo
)
1617 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1622 lbs_deb_enter(LBS_DEB_CFG80211
);
1624 sinfo
->filled
|= BIT(NL80211_STA_INFO_TX_BYTES
) |
1625 BIT(NL80211_STA_INFO_TX_PACKETS
) |
1626 BIT(NL80211_STA_INFO_RX_BYTES
) |
1627 BIT(NL80211_STA_INFO_RX_PACKETS
);
1628 sinfo
->tx_bytes
= priv
->dev
->stats
.tx_bytes
;
1629 sinfo
->tx_packets
= priv
->dev
->stats
.tx_packets
;
1630 sinfo
->rx_bytes
= priv
->dev
->stats
.rx_bytes
;
1631 sinfo
->rx_packets
= priv
->dev
->stats
.rx_packets
;
1633 /* Get current RSSI */
1634 ret
= lbs_get_rssi(priv
, &signal
, &noise
);
1636 sinfo
->signal
= signal
;
1637 sinfo
->filled
|= BIT(NL80211_STA_INFO_SIGNAL
);
1640 /* Convert priv->cur_rate from hw_value to NL80211 value */
1641 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
1642 if (priv
->cur_rate
== lbs_rates
[i
].hw_value
) {
1643 sinfo
->txrate
.legacy
= lbs_rates
[i
].bitrate
;
1644 sinfo
->filled
|= BIT(NL80211_STA_INFO_TX_BITRATE
);
1659 static int lbs_change_intf(struct wiphy
*wiphy
, struct net_device
*dev
,
1660 enum nl80211_iftype type
, u32
*flags
,
1661 struct vif_params
*params
)
1663 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1666 if (dev
== priv
->mesh_dev
)
1670 case NL80211_IFTYPE_MONITOR
:
1671 case NL80211_IFTYPE_STATION
:
1672 case NL80211_IFTYPE_ADHOC
:
1678 lbs_deb_enter(LBS_DEB_CFG80211
);
1680 if (priv
->iface_running
)
1681 ret
= lbs_set_iface_type(priv
, type
);
1684 priv
->wdev
->iftype
= type
;
1686 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1697 * The firmware needs the following bits masked out of the beacon-derived
1698 * capability field when associating/joining to a BSS:
1699 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1701 #define CAPINFO_MASK (~(0xda00))
1704 static void lbs_join_post(struct lbs_private
*priv
,
1705 struct cfg80211_ibss_params
*params
,
1706 u8
*bssid
, u16 capability
)
1708 u8 fake_ie
[2 + IEEE80211_MAX_SSID_LEN
+ /* ssid */
1709 2 + 4 + /* basic rates */
1710 2 + 1 + /* DS parameter */
1712 2 + 8]; /* extended rates */
1714 struct cfg80211_bss
*bss
;
1716 lbs_deb_enter(LBS_DEB_CFG80211
);
1719 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1720 * the real IE from the firmware. So we fabricate a fake IE based on
1721 * what the firmware actually sends (sniffed with wireshark).
1724 *fake
++ = WLAN_EID_SSID
;
1725 *fake
++ = params
->ssid_len
;
1726 memcpy(fake
, params
->ssid
, params
->ssid_len
);
1727 fake
+= params
->ssid_len
;
1728 /* Fake supported basic rates IE */
1729 *fake
++ = WLAN_EID_SUPP_RATES
;
1735 /* Fake DS channel IE */
1736 *fake
++ = WLAN_EID_DS_PARAMS
;
1738 *fake
++ = params
->chandef
.chan
->hw_value
;
1739 /* Fake IBSS params IE */
1740 *fake
++ = WLAN_EID_IBSS_PARAMS
;
1742 *fake
++ = 0; /* ATIM=0 */
1744 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1745 * but I don't know how this could be checked */
1746 *fake
++ = WLAN_EID_EXT_SUPP_RATES
;
1756 lbs_deb_hex(LBS_DEB_CFG80211
, "IE", fake_ie
, fake
- fake_ie
);
1758 bss
= cfg80211_inform_bss(priv
->wdev
->wiphy
,
1759 params
->chandef
.chan
,
1760 CFG80211_BSS_FTYPE_UNKNOWN
,
1764 params
->beacon_interval
,
1765 fake_ie
, fake
- fake_ie
,
1767 cfg80211_put_bss(priv
->wdev
->wiphy
, bss
);
1769 memcpy(priv
->wdev
->ssid
, params
->ssid
, params
->ssid_len
);
1770 priv
->wdev
->ssid_len
= params
->ssid_len
;
1772 cfg80211_ibss_joined(priv
->dev
, bssid
, params
->chandef
.chan
,
1775 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1776 priv
->connect_status
= LBS_CONNECTED
;
1777 netif_carrier_on(priv
->dev
);
1778 if (!priv
->tx_pending_len
)
1779 netif_wake_queue(priv
->dev
);
1781 lbs_deb_leave(LBS_DEB_CFG80211
);
1784 static int lbs_ibss_join_existing(struct lbs_private
*priv
,
1785 struct cfg80211_ibss_params
*params
,
1786 struct cfg80211_bss
*bss
)
1788 const u8
*rates_eid
;
1789 struct cmd_ds_802_11_ad_hoc_join cmd
;
1790 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1793 lbs_deb_enter(LBS_DEB_CFG80211
);
1795 /* TODO: set preamble based on scan result */
1796 ret
= lbs_set_radio(priv
, preamble
, 1);
1801 * Example CMD_802_11_AD_HOC_JOIN command:
1803 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1807 * bssid 02 27 27 97 2f 96
1808 * ssid 49 42 53 53 00 00 00 00
1809 * 00 00 00 00 00 00 00 00
1810 * 00 00 00 00 00 00 00 00
1811 * 00 00 00 00 00 00 00 00
1812 * type 02 CMD_BSS_TYPE_IBSS
1813 * beacon period 64 00
1815 * timestamp 00 00 00 00 00 00 00 00
1816 * localtime 00 00 00 00 00 00 00 00
1820 * reserveed 00 00 00 00
1823 * IE IBSS atim 00 00
1824 * reserved 00 00 00 00
1826 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1827 * fail timeout ff 00
1830 memset(&cmd
, 0, sizeof(cmd
));
1831 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1833 memcpy(cmd
.bss
.bssid
, bss
->bssid
, ETH_ALEN
);
1834 memcpy(cmd
.bss
.ssid
, params
->ssid
, params
->ssid_len
);
1835 cmd
.bss
.type
= CMD_BSS_TYPE_IBSS
;
1836 cmd
.bss
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1837 cmd
.bss
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1838 cmd
.bss
.ds
.header
.len
= 1;
1839 cmd
.bss
.ds
.channel
= params
->chandef
.chan
->hw_value
;
1840 cmd
.bss
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1841 cmd
.bss
.ibss
.header
.len
= 2;
1842 cmd
.bss
.ibss
.atimwindow
= 0;
1843 cmd
.bss
.capability
= cpu_to_le16(bss
->capability
& CAPINFO_MASK
);
1845 /* set rates to the intersection of our rates and the rates in the
1848 rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
1850 lbs_add_rates(cmd
.bss
.rates
);
1853 u8 rates_max
= rates_eid
[1];
1854 u8
*rates
= cmd
.bss
.rates
;
1855 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
1856 u8 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
1857 for (i
= 0; i
< rates_max
; i
++) {
1858 if (hw_rate
== (rates_eid
[i
+2] & 0x7f)) {
1859 u8 rate
= rates_eid
[i
+2];
1860 if (rate
== 0x02 || rate
== 0x04 ||
1861 rate
== 0x0b || rate
== 0x16)
1870 /* Only v8 and below support setting this */
1871 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1872 cmd
.failtimeout
= cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT
);
1873 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1875 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_JOIN
, &cmd
);
1880 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1888 lbs_join_post(priv
, params
, bss
->bssid
, bss
->capability
);
1891 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1897 static int lbs_ibss_start_new(struct lbs_private
*priv
,
1898 struct cfg80211_ibss_params
*params
)
1900 struct cmd_ds_802_11_ad_hoc_start cmd
;
1901 struct cmd_ds_802_11_ad_hoc_result
*resp
=
1902 (struct cmd_ds_802_11_ad_hoc_result
*) &cmd
;
1903 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1907 lbs_deb_enter(LBS_DEB_CFG80211
);
1909 ret
= lbs_set_radio(priv
, preamble
, 1);
1914 * Example CMD_802_11_AD_HOC_START command:
1916 * command 2b 00 CMD_802_11_AD_HOC_START
1920 * ssid 54 45 53 54 00 00 00 00
1921 * 00 00 00 00 00 00 00 00
1922 * 00 00 00 00 00 00 00 00
1923 * 00 00 00 00 00 00 00 00
1925 * beacon period 64 00
1929 * IE IBSS atim 00 00
1930 * reserved 00 00 00 00
1934 * reserved 00 00 00 00
1937 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1938 * 0c 12 18 24 30 48 60 6c
1941 memset(&cmd
, 0, sizeof(cmd
));
1942 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1943 memcpy(cmd
.ssid
, params
->ssid
, params
->ssid_len
);
1944 cmd
.bsstype
= CMD_BSS_TYPE_IBSS
;
1945 cmd
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1946 cmd
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1947 cmd
.ibss
.header
.len
= 2;
1948 cmd
.ibss
.atimwindow
= 0;
1949 cmd
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1950 cmd
.ds
.header
.len
= 1;
1951 cmd
.ds
.channel
= params
->chandef
.chan
->hw_value
;
1952 /* Only v8 and below support setting probe delay */
1953 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8)
1954 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1955 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1956 capability
= WLAN_CAPABILITY_IBSS
;
1957 cmd
.capability
= cpu_to_le16(capability
);
1958 lbs_add_rates(cmd
.rates
);
1961 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_START
, &cmd
);
1966 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1973 * bssid 02 2b 7b 0f 86 0e
1975 lbs_join_post(priv
, params
, resp
->bssid
, capability
);
1978 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1983 static int lbs_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1984 struct cfg80211_ibss_params
*params
)
1986 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1988 struct cfg80211_bss
*bss
;
1990 if (dev
== priv
->mesh_dev
)
1993 lbs_deb_enter(LBS_DEB_CFG80211
);
1995 if (!params
->chandef
.chan
) {
2000 ret
= lbs_set_channel(priv
, params
->chandef
.chan
->hw_value
);
2004 /* Search if someone is beaconing. This assumes that the
2005 * bss list is populated already */
2006 bss
= cfg80211_get_bss(wiphy
, params
->chandef
.chan
, params
->bssid
,
2007 params
->ssid
, params
->ssid_len
,
2008 IEEE80211_BSS_TYPE_IBSS
, IEEE80211_PRIVACY_ANY
);
2011 ret
= lbs_ibss_join_existing(priv
, params
, bss
);
2012 cfg80211_put_bss(wiphy
, bss
);
2014 ret
= lbs_ibss_start_new(priv
, params
);
2018 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2023 static int lbs_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
2025 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2026 struct cmd_ds_802_11_ad_hoc_stop cmd
;
2029 if (dev
== priv
->mesh_dev
)
2032 lbs_deb_enter(LBS_DEB_CFG80211
);
2034 memset(&cmd
, 0, sizeof(cmd
));
2035 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
2036 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_STOP
, &cmd
);
2038 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
2039 lbs_mac_event_disconnected(priv
, true);
2041 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2047 static int lbs_set_power_mgmt(struct wiphy
*wiphy
, struct net_device
*dev
,
2048 bool enabled
, int timeout
)
2050 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2052 if (!(priv
->fwcapinfo
& FW_CAPINFO_PS
)) {
2058 /* firmware does not work well with too long latency with power saving
2059 * enabled, so do not enable it if there is only polling, no
2060 * interrupts (like in some sdio hosts which can only
2061 * poll for sdio irqs)
2063 if (priv
->is_polling
) {
2070 priv
->psmode
= LBS802_11POWERMODECAM
;
2071 if (priv
->psstate
!= PS_STATE_FULL_POWER
)
2072 lbs_set_ps_mode(priv
,
2073 PS_MODE_ACTION_EXIT_PS
,
2077 if (priv
->psmode
!= LBS802_11POWERMODECAM
)
2079 priv
->psmode
= LBS802_11POWERMODEMAX_PSP
;
2080 if (priv
->connect_status
== LBS_CONNECTED
)
2081 lbs_set_ps_mode(priv
, PS_MODE_ACTION_ENTER_PS
, true);
2089 static struct cfg80211_ops lbs_cfg80211_ops
= {
2090 .set_monitor_channel
= lbs_cfg_set_monitor_channel
,
2091 .libertas_set_mesh_channel
= lbs_cfg_set_mesh_channel
,
2092 .scan
= lbs_cfg_scan
,
2093 .connect
= lbs_cfg_connect
,
2094 .disconnect
= lbs_cfg_disconnect
,
2095 .add_key
= lbs_cfg_add_key
,
2096 .del_key
= lbs_cfg_del_key
,
2097 .set_default_key
= lbs_cfg_set_default_key
,
2098 .get_station
= lbs_cfg_get_station
,
2099 .change_virtual_intf
= lbs_change_intf
,
2100 .join_ibss
= lbs_join_ibss
,
2101 .leave_ibss
= lbs_leave_ibss
,
2102 .set_power_mgmt
= lbs_set_power_mgmt
,
2107 * At this time lbs_private *priv doesn't even exist, so we just allocate
2108 * memory and don't initialize the wiphy further. This is postponed until we
2109 * can talk to the firmware and happens at registration time in
2110 * lbs_cfg_wiphy_register().
2112 struct wireless_dev
*lbs_cfg_alloc(struct device
*dev
)
2115 struct wireless_dev
*wdev
;
2117 lbs_deb_enter(LBS_DEB_CFG80211
);
2119 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
2121 return ERR_PTR(-ENOMEM
);
2123 wdev
->wiphy
= wiphy_new(&lbs_cfg80211_ops
, sizeof(struct lbs_private
));
2125 dev_err(dev
, "cannot allocate wiphy\n");
2130 lbs_deb_leave(LBS_DEB_CFG80211
);
2135 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2136 return ERR_PTR(ret
);
2140 static void lbs_cfg_set_regulatory_hint(struct lbs_private
*priv
)
2142 struct region_code_mapping
{
2147 /* Section 5.17.2 */
2148 static const struct region_code_mapping regmap
[] = {
2149 {"US ", 0x10}, /* US FCC */
2150 {"CA ", 0x20}, /* Canada */
2151 {"EU ", 0x30}, /* ETSI */
2152 {"ES ", 0x31}, /* Spain */
2153 {"FR ", 0x32}, /* France */
2154 {"JP ", 0x40}, /* Japan */
2158 lbs_deb_enter(LBS_DEB_CFG80211
);
2160 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
2161 if (regmap
[i
].code
== priv
->regioncode
) {
2162 regulatory_hint(priv
->wdev
->wiphy
, regmap
[i
].cn
);
2166 lbs_deb_leave(LBS_DEB_CFG80211
);
2169 static void lbs_reg_notifier(struct wiphy
*wiphy
,
2170 struct regulatory_request
*request
)
2172 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2174 lbs_deb_enter_args(LBS_DEB_CFG80211
, "cfg80211 regulatory domain "
2175 "callback for domain %c%c\n", request
->alpha2
[0],
2176 request
->alpha2
[1]);
2178 memcpy(priv
->country_code
, request
->alpha2
, sizeof(request
->alpha2
));
2179 if (lbs_iface_active(priv
))
2180 lbs_set_11d_domain_info(priv
);
2182 lbs_deb_leave(LBS_DEB_CFG80211
);
2186 * This function get's called after lbs_setup_firmware() determined the
2187 * firmware capabities. So we can setup the wiphy according to our
2188 * hardware/firmware.
2190 int lbs_cfg_register(struct lbs_private
*priv
)
2192 struct wireless_dev
*wdev
= priv
->wdev
;
2195 lbs_deb_enter(LBS_DEB_CFG80211
);
2197 wdev
->wiphy
->max_scan_ssids
= 1;
2198 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
2200 wdev
->wiphy
->interface_modes
=
2201 BIT(NL80211_IFTYPE_STATION
) |
2202 BIT(NL80211_IFTYPE_ADHOC
);
2203 if (lbs_rtap_supported(priv
))
2204 wdev
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_MONITOR
);
2205 if (lbs_mesh_activated(priv
))
2206 wdev
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_MESH_POINT
);
2208 wdev
->wiphy
->bands
[NL80211_BAND_2GHZ
] = &lbs_band_2ghz
;
2211 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2212 * never seen a firmware without WPA
2214 wdev
->wiphy
->cipher_suites
= cipher_suites
;
2215 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
2216 wdev
->wiphy
->reg_notifier
= lbs_reg_notifier
;
2218 ret
= wiphy_register(wdev
->wiphy
);
2220 pr_err("cannot register wiphy device\n");
2222 priv
->wiphy_registered
= true;
2224 ret
= register_netdev(priv
->dev
);
2226 pr_err("cannot register network device\n");
2228 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
2230 lbs_cfg_set_regulatory_hint(priv
);
2232 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2236 void lbs_scan_deinit(struct lbs_private
*priv
)
2238 lbs_deb_enter(LBS_DEB_CFG80211
);
2239 cancel_delayed_work_sync(&priv
->scan_work
);
2243 void lbs_cfg_free(struct lbs_private
*priv
)
2245 struct wireless_dev
*wdev
= priv
->wdev
;
2247 lbs_deb_enter(LBS_DEB_CFG80211
);
2252 if (priv
->wiphy_registered
)
2253 wiphy_unregister(wdev
->wiphy
);
2256 wiphy_free(wdev
->wiphy
);