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/if_arp.h>
11 #include <linux/ieee80211.h>
12 #include <net/cfg80211.h>
13 #include <asm/unaligned.h>
20 #define CHAN2G(_channel, _freq, _flags) { \
21 .band = IEEE80211_BAND_2GHZ, \
22 .center_freq = (_freq), \
23 .hw_value = (_channel), \
25 .max_antenna_gain = 0, \
29 static struct ieee80211_channel lbs_2ghz_channels
[] = {
46 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
48 .hw_value = (_hw_value), \
53 /* Table 6 in section 3.2.1.1 */
54 static struct ieee80211_rate lbs_rates
[] = {
55 RATETAB_ENT(10, 0, 0),
56 RATETAB_ENT(20, 1, 0),
57 RATETAB_ENT(55, 2, 0),
58 RATETAB_ENT(110, 3, 0),
59 RATETAB_ENT(60, 9, 0),
60 RATETAB_ENT(90, 6, 0),
61 RATETAB_ENT(120, 7, 0),
62 RATETAB_ENT(180, 8, 0),
63 RATETAB_ENT(240, 9, 0),
64 RATETAB_ENT(360, 10, 0),
65 RATETAB_ENT(480, 11, 0),
66 RATETAB_ENT(540, 12, 0),
69 static struct ieee80211_supported_band lbs_band_2ghz
= {
70 .channels
= lbs_2ghz_channels
,
71 .n_channels
= ARRAY_SIZE(lbs_2ghz_channels
),
72 .bitrates
= lbs_rates
,
73 .n_bitrates
= ARRAY_SIZE(lbs_rates
),
77 static const u32 cipher_suites
[] = {
78 WLAN_CIPHER_SUITE_WEP40
,
79 WLAN_CIPHER_SUITE_WEP104
,
80 WLAN_CIPHER_SUITE_TKIP
,
81 WLAN_CIPHER_SUITE_CCMP
,
84 /* Time to stay on the channel */
85 #define LBS_DWELL_PASSIVE 100
86 #define LBS_DWELL_ACTIVE 40
89 /***************************************************************************
90 * Misc utility functions
92 * TLVs are Marvell specific. They are very similar to IEs, they have the
93 * same structure: type, length, data*. The only difference: for IEs, the
94 * type and length are u8, but for TLVs they're __le16.
98 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
99 * in the firmware spec
101 static u8
lbs_auth_to_authtype(enum nl80211_auth_type auth_type
)
106 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
107 case NL80211_AUTHTYPE_SHARED_KEY
:
110 case NL80211_AUTHTYPE_AUTOMATIC
:
111 ret
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
113 case NL80211_AUTHTYPE_NETWORK_EAP
:
117 /* silence compiler */
124 /* Various firmware commands need the list of supported rates, but with
125 the hight-bit set for basic rates */
126 static int lbs_add_rates(u8
*rates
)
130 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
131 u8 rate
= lbs_rates
[i
].bitrate
/ 5;
132 if (rate
== 0x02 || rate
== 0x04 ||
133 rate
== 0x0b || rate
== 0x16)
137 return ARRAY_SIZE(lbs_rates
);
141 /***************************************************************************
142 * TLV utility functions
144 * TLVs are Marvell specific. They are very similar to IEs, they have the
145 * same structure: type, length, data*. The only difference: for IEs, the
146 * type and length are u8, but for TLVs they're __le16.
153 #define LBS_MAX_SSID_TLV_SIZE \
154 (sizeof(struct mrvl_ie_header) \
155 + IEEE80211_MAX_SSID_LEN)
157 static int lbs_add_ssid_tlv(u8
*tlv
, const u8
*ssid
, int ssid_len
)
159 struct mrvl_ie_ssid_param_set
*ssid_tlv
= (void *)tlv
;
164 * ssid 4d 4e 54 45 53 54
166 ssid_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_SSID
);
167 ssid_tlv
->header
.len
= cpu_to_le16(ssid_len
);
168 memcpy(ssid_tlv
->ssid
, ssid
, ssid_len
);
169 return sizeof(ssid_tlv
->header
) + ssid_len
;
174 * Add channel list TLV (section 8.4.2)
176 * Actual channel data comes from priv->wdev->wiphy->channels.
178 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
179 (sizeof(struct mrvl_ie_header) \
180 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
182 static int lbs_add_channel_list_tlv(struct lbs_private
*priv
, u8
*tlv
,
183 int last_channel
, int active_scan
)
185 int chanscanparamsize
= sizeof(struct chanscanparamset
) *
186 (last_channel
- priv
->scan_channel
);
188 struct mrvl_ie_header
*header
= (void *) tlv
;
191 * TLV-ID CHANLIST 01 01
193 * channel 00 01 00 00 00 64 00
197 * min scan time 00 00
198 * max scan time 64 00
199 * channel 2 00 02 00 00 00 64 00
203 header
->type
= cpu_to_le16(TLV_TYPE_CHANLIST
);
204 header
->len
= cpu_to_le16(chanscanparamsize
);
205 tlv
+= sizeof(struct mrvl_ie_header
);
207 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
209 memset(tlv
, 0, chanscanparamsize
);
211 while (priv
->scan_channel
< last_channel
) {
212 struct chanscanparamset
*param
= (void *) tlv
;
214 param
->radiotype
= CMD_SCAN_RADIO_TYPE_BG
;
216 priv
->scan_req
->channels
[priv
->scan_channel
]->hw_value
;
218 param
->maxscantime
= cpu_to_le16(LBS_DWELL_ACTIVE
);
220 param
->chanscanmode
.passivescan
= 1;
221 param
->maxscantime
= cpu_to_le16(LBS_DWELL_PASSIVE
);
223 tlv
+= sizeof(struct chanscanparamset
);
224 priv
->scan_channel
++;
226 return sizeof(struct mrvl_ie_header
) + chanscanparamsize
;
233 * The rates are in lbs_bg_rates[], but for the 802.11b
234 * rates the high bit is set. We add this TLV only because
235 * there's a firmware which otherwise doesn't report all
238 #define LBS_MAX_RATES_TLV_SIZE \
239 (sizeof(struct mrvl_ie_header) \
240 + (ARRAY_SIZE(lbs_rates)))
242 /* Adds a TLV with all rates the hardware supports */
243 static int lbs_add_supported_rates_tlv(u8
*tlv
)
246 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
251 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
253 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
254 tlv
+= sizeof(rate_tlv
->header
);
255 i
= lbs_add_rates(tlv
);
257 rate_tlv
->header
.len
= cpu_to_le16(i
);
258 return sizeof(rate_tlv
->header
) + i
;
263 * Adds a TLV with all rates the hardware *and* BSS supports.
265 static int lbs_add_common_rates_tlv(u8
*tlv
, struct cfg80211_bss
*bss
)
267 struct mrvl_ie_rates_param_set
*rate_tlv
= (void *)tlv
;
268 const u8
*rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
272 * 01 00 TLV_TYPE_RATES
276 rate_tlv
->header
.type
= cpu_to_le16(TLV_TYPE_RATES
);
277 tlv
+= sizeof(rate_tlv
->header
);
280 /* Fallback: add basic 802.11b rates */
288 u8 ap_max
= rates_eid
[1];
290 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
291 u8 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
292 for (ap
= 0; ap
< ap_max
; ap
++) {
293 if (hw_rate
== (rates_eid
[ap
+2] & 0x7f)) {
294 *tlv
++ = rates_eid
[ap
+2];
301 rate_tlv
->header
.len
= cpu_to_le16(n
);
302 return sizeof(rate_tlv
->header
) + n
;
309 * This is only needed for newer firmware (V9 and up).
311 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
312 sizeof(struct mrvl_ie_auth_type)
314 static int lbs_add_auth_type_tlv(u8
*tlv
, enum nl80211_auth_type auth_type
)
316 struct mrvl_ie_auth_type
*auth
= (void *) tlv
;
319 * 1f 01 TLV_TYPE_AUTH_TYPE
323 auth
->header
.type
= cpu_to_le16(TLV_TYPE_AUTH_TYPE
);
324 auth
->header
.len
= cpu_to_le16(sizeof(*auth
)-sizeof(auth
->header
));
325 auth
->auth
= cpu_to_le16(lbs_auth_to_authtype(auth_type
));
326 return sizeof(*auth
);
331 * Add channel (phy ds) TLV
333 #define LBS_MAX_CHANNEL_TLV_SIZE \
334 sizeof(struct mrvl_ie_header)
336 static int lbs_add_channel_tlv(u8
*tlv
, u8 channel
)
338 struct mrvl_ie_ds_param_set
*ds
= (void *) tlv
;
341 * 03 00 TLV_TYPE_PHY_DS
345 ds
->header
.type
= cpu_to_le16(TLV_TYPE_PHY_DS
);
346 ds
->header
.len
= cpu_to_le16(sizeof(*ds
)-sizeof(ds
->header
));
347 ds
->channel
= channel
;
353 * Add (empty) CF param TLV of the form:
355 #define LBS_MAX_CF_PARAM_TLV_SIZE \
356 sizeof(struct mrvl_ie_header)
358 static int lbs_add_cf_param_tlv(u8
*tlv
)
360 struct mrvl_ie_cf_param_set
*cf
= (void *)tlv
;
367 * 00 00 cfpmaxduration
368 * 00 00 cfpdurationremaining
370 cf
->header
.type
= cpu_to_le16(TLV_TYPE_CF
);
371 cf
->header
.len
= cpu_to_le16(sizeof(*cf
)-sizeof(cf
->header
));
378 #define LBS_MAX_WPA_TLV_SIZE \
379 (sizeof(struct mrvl_ie_header) \
380 + 128 /* TODO: I guessed the size */)
382 static int lbs_add_wpa_tlv(u8
*tlv
, const u8
*ie
, u8 ie_len
)
387 * We need just convert an IE to an TLV. IEs use u8 for the header,
391 * but TLVs use __le16 instead:
398 tlv_len
= *tlv
++ = *ie
++;
402 /* the TLV is two bytes larger than the IE */
406 /***************************************************************************
410 static int lbs_cfg_set_channel(struct wiphy
*wiphy
,
411 struct net_device
*netdev
,
412 struct ieee80211_channel
*channel
,
413 enum nl80211_channel_type channel_type
)
415 struct lbs_private
*priv
= wiphy_priv(wiphy
);
418 lbs_deb_enter_args(LBS_DEB_CFG80211
, "freq %d, type %d",
419 channel
->center_freq
, channel_type
);
421 if (channel_type
!= NL80211_CHAN_NO_HT
)
424 ret
= lbs_set_channel(priv
, channel
->hw_value
);
427 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
433 /***************************************************************************
438 * When scanning, the firmware doesn't send a nul packet with the power-safe
439 * bit to the AP. So we cannot stay away from our current channel too long,
440 * otherwise we loose data. So take a "nap" while scanning every other
443 #define LBS_SCAN_BEFORE_NAP 4
447 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
448 * which isn't really an RSSI, as it becomes larger when moving away from
449 * the AP. Anyway, we need to convert that into mBm.
451 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
452 ((-(int)rssi + 3)*100)
454 static int lbs_ret_scan(struct lbs_private
*priv
, unsigned long dummy
,
455 struct cmd_header
*resp
)
457 struct cmd_ds_802_11_scan_rsp
*scanresp
= (void *)resp
;
466 lbs_deb_enter(LBS_DEB_CFG80211
);
468 bsssize
= get_unaligned_le16(&scanresp
->bssdescriptsize
);
469 nr_sets
= le16_to_cpu(resp
->size
);
472 * The general layout of the scan response is described in chapter
473 * 5.7.1. Basically we have a common part, then any number of BSS
474 * descriptor sections. Finally we have section with the same number
477 * cmd_ds_802_11_scan_rsp
490 * MrvlIEtypes_TsfFimestamp_t
496 pos
= scanresp
->bssdesc_and_tlvbuffer
;
498 tsfdesc
= pos
+ bsssize
;
499 tsfsize
= 4 + 8 * scanresp
->nr_sets
;
501 /* Validity check: we expect a Marvell-Local TLV */
502 i
= get_unaligned_le16(tsfdesc
);
504 if (i
!= TLV_TYPE_TSFTIMESTAMP
)
506 /* Validity check: the TLV holds TSF values with 8 bytes each, so
507 * the size in the TLV must match the nr_sets value */
508 i
= get_unaligned_le16(tsfdesc
);
510 if (i
/ 8 != scanresp
->nr_sets
)
513 for (i
= 0; i
< scanresp
->nr_sets
; i
++) {
522 const u8
*ssid
= NULL
;
524 DECLARE_SSID_BUF(ssid_buf
);
526 int len
= get_unaligned_le16(pos
);
534 /* Packet time stamp */
536 /* Beacon interval */
537 intvl
= get_unaligned_le16(pos
);
540 capa
= get_unaligned_le16(pos
);
543 /* To find out the channel, we must parse the IEs */
545 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
546 interval, capabilities */
547 ielen
= left
= len
- (6 + 1 + 8 + 2 + 2);
553 if (elen
> left
|| elen
== 0)
555 if (id
== WLAN_EID_DS_PARAMS
)
557 if (id
== WLAN_EID_SSID
) {
565 /* No channel, no luck */
567 struct wiphy
*wiphy
= priv
->wdev
->wiphy
;
568 int freq
= ieee80211_channel_to_frequency(chan_no
);
569 struct ieee80211_channel
*channel
=
570 ieee80211_get_channel(wiphy
, freq
);
572 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
574 bssid
, capa
, chan_no
,
575 print_ssid(ssid_buf
, ssid
, ssid_len
),
576 LBS_SCAN_RSSI_TO_MBM(rssi
)/100);
579 !(channel
->flags
& IEEE80211_CHAN_DISABLED
))
580 cfg80211_inform_bss(wiphy
, channel
,
581 bssid
, le64_to_cpu(*(__le64
*)tsfdesc
),
582 capa
, intvl
, ie
, ielen
,
583 LBS_SCAN_RSSI_TO_MBM(rssi
),
591 lbs_deb_leave_args(LBS_DEB_SCAN
, "ret %d", ret
);
597 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
598 * TLV and a rates TLV. Determine the maximum size of them:
600 #define LBS_SCAN_MAX_CMD_SIZE \
601 (sizeof(struct cmd_ds_802_11_scan) \
602 + LBS_MAX_SSID_TLV_SIZE \
603 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
604 + LBS_MAX_RATES_TLV_SIZE)
607 * Assumes priv->scan_req is initialized and valid
608 * Assumes priv->scan_channel is initialized
610 static void lbs_scan_worker(struct work_struct
*work
)
612 struct lbs_private
*priv
=
613 container_of(work
, struct lbs_private
, scan_work
.work
);
614 struct cmd_ds_802_11_scan
*scan_cmd
;
615 u8
*tlv
; /* pointer into our current, growing TLV storage area */
617 int running
, carrier
;
619 lbs_deb_enter(LBS_DEB_SCAN
);
621 scan_cmd
= kzalloc(LBS_SCAN_MAX_CMD_SIZE
, GFP_KERNEL
);
622 if (scan_cmd
== NULL
)
623 goto out_no_scan_cmd
;
625 /* prepare fixed part of scan command */
626 scan_cmd
->bsstype
= CMD_BSS_TYPE_ANY
;
628 /* stop network while we're away from our main channel */
629 running
= !netif_queue_stopped(priv
->dev
);
630 carrier
= netif_carrier_ok(priv
->dev
);
632 netif_stop_queue(priv
->dev
);
634 netif_carrier_off(priv
->dev
);
636 /* prepare fixed part of scan command */
637 tlv
= scan_cmd
->tlvbuffer
;
640 if (priv
->scan_req
->n_ssids
)
641 tlv
+= lbs_add_ssid_tlv(tlv
,
642 priv
->scan_req
->ssids
[0].ssid
,
643 priv
->scan_req
->ssids
[0].ssid_len
);
645 /* add channel TLVs */
646 last_channel
= priv
->scan_channel
+ LBS_SCAN_BEFORE_NAP
;
647 if (last_channel
> priv
->scan_req
->n_channels
)
648 last_channel
= priv
->scan_req
->n_channels
;
649 tlv
+= lbs_add_channel_list_tlv(priv
, tlv
, last_channel
,
650 priv
->scan_req
->n_ssids
);
653 tlv
+= lbs_add_supported_rates_tlv(tlv
);
655 if (priv
->scan_channel
< priv
->scan_req
->n_channels
) {
656 cancel_delayed_work(&priv
->scan_work
);
657 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
658 msecs_to_jiffies(300));
661 /* This is the final data we are about to send */
662 scan_cmd
->hdr
.size
= cpu_to_le16(tlv
- (u8
*)scan_cmd
);
663 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_CMD", (void *)scan_cmd
,
665 lbs_deb_hex(LBS_DEB_SCAN
, "SCAN_TLV", scan_cmd
->tlvbuffer
,
666 tlv
- scan_cmd
->tlvbuffer
);
668 __lbs_cmd(priv
, CMD_802_11_SCAN
, &scan_cmd
->hdr
,
669 le16_to_cpu(scan_cmd
->hdr
.size
),
672 if (priv
->scan_channel
>= priv
->scan_req
->n_channels
) {
674 cfg80211_scan_done(priv
->scan_req
, false);
675 priv
->scan_req
= NULL
;
678 /* Restart network */
680 netif_carrier_on(priv
->dev
);
681 if (running
&& !priv
->tx_pending_len
)
682 netif_wake_queue(priv
->dev
);
687 lbs_deb_leave(LBS_DEB_SCAN
);
691 static int lbs_cfg_scan(struct wiphy
*wiphy
,
692 struct net_device
*dev
,
693 struct cfg80211_scan_request
*request
)
695 struct lbs_private
*priv
= wiphy_priv(wiphy
);
698 lbs_deb_enter(LBS_DEB_CFG80211
);
700 if (priv
->scan_req
|| delayed_work_pending(&priv
->scan_work
)) {
701 /* old scan request not yet processed */
706 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
707 request
->n_ssids
, request
->n_channels
, request
->ie_len
);
709 priv
->scan_channel
= 0;
710 queue_delayed_work(priv
->work_thread
, &priv
->scan_work
,
711 msecs_to_jiffies(50));
713 if (priv
->surpriseremoved
)
716 priv
->scan_req
= request
;
719 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
726 /***************************************************************************
730 void lbs_send_disconnect_notification(struct lbs_private
*priv
)
732 lbs_deb_enter(LBS_DEB_CFG80211
);
734 cfg80211_disconnected(priv
->dev
,
739 lbs_deb_leave(LBS_DEB_CFG80211
);
742 void lbs_send_mic_failureevent(struct lbs_private
*priv
, u32 event
)
744 lbs_deb_enter(LBS_DEB_CFG80211
);
746 cfg80211_michael_mic_failure(priv
->dev
,
748 event
== MACREG_INT_CODE_MIC_ERR_MULTICAST
?
749 NL80211_KEYTYPE_GROUP
:
750 NL80211_KEYTYPE_PAIRWISE
,
755 lbs_deb_leave(LBS_DEB_CFG80211
);
761 /***************************************************************************
767 * This removes all WEP keys
769 static int lbs_remove_wep_keys(struct lbs_private
*priv
)
771 struct cmd_ds_802_11_set_wep cmd
;
774 lbs_deb_enter(LBS_DEB_CFG80211
);
776 memset(&cmd
, 0, sizeof(cmd
));
777 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
778 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
779 cmd
.action
= cpu_to_le16(CMD_ACT_REMOVE
);
781 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
783 lbs_deb_leave(LBS_DEB_CFG80211
);
790 static int lbs_set_wep_keys(struct lbs_private
*priv
)
792 struct cmd_ds_802_11_set_wep cmd
;
796 lbs_deb_enter(LBS_DEB_CFG80211
);
803 * action 02 00 ACT_ADD
805 * type for key 1 01 WEP40
809 * key 1 39 39 39 39 39 00 00 00
810 * 00 00 00 00 00 00 00 00
811 * key 2 00 00 00 00 00 00 00 00
812 * 00 00 00 00 00 00 00 00
813 * key 3 00 00 00 00 00 00 00 00
814 * 00 00 00 00 00 00 00 00
815 * key 4 00 00 00 00 00 00 00 00
817 if (priv
->wep_key_len
[0] || priv
->wep_key_len
[1] ||
818 priv
->wep_key_len
[2] || priv
->wep_key_len
[3]) {
819 /* Only set wep keys if we have at least one of them */
820 memset(&cmd
, 0, sizeof(cmd
));
821 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
822 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_key
);
823 cmd
.action
= cpu_to_le16(CMD_ACT_ADD
);
825 for (i
= 0; i
< 4; i
++) {
826 switch (priv
->wep_key_len
[i
]) {
827 case WLAN_KEY_LEN_WEP40
:
828 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
830 case WLAN_KEY_LEN_WEP104
:
831 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
837 memcpy(cmd
.keymaterial
[i
], priv
->wep_key
[i
],
838 priv
->wep_key_len
[i
]);
841 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
843 /* Otherwise remove all wep keys */
844 ret
= lbs_remove_wep_keys(priv
);
847 lbs_deb_leave(LBS_DEB_CFG80211
);
853 * Enable/Disable RSN status
855 static int lbs_enable_rsn(struct lbs_private
*priv
, int enable
)
857 struct cmd_ds_802_11_enable_rsn cmd
;
860 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", enable
);
867 * action 01 00 ACT_SET
870 memset(&cmd
, 0, sizeof(cmd
));
871 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
872 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
873 cmd
.enable
= cpu_to_le16(enable
);
875 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
877 lbs_deb_leave(LBS_DEB_CFG80211
);
883 * Set WPA/WPA key material
886 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
887 * get rid of WEXT, this should go into host.h */
889 struct cmd_key_material
{
890 struct cmd_header hdr
;
893 struct MrvlIEtype_keyParamSet param
;
894 } __attribute__ ((packed
));
896 static int lbs_set_key_material(struct lbs_private
*priv
,
899 u8
*key
, u16 key_len
)
901 struct cmd_key_material cmd
;
904 lbs_deb_enter(LBS_DEB_CFG80211
);
907 * Example for WPA (TKIP):
914 * TLV type 00 01 key param
916 * key type 01 00 TKIP
917 * key info 06 00 UNICAST | ENABLED
921 memset(&cmd
, 0, sizeof(cmd
));
922 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
923 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
924 cmd
.param
.type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
925 cmd
.param
.length
= cpu_to_le16(sizeof(cmd
.param
) - 4);
926 cmd
.param
.keytypeid
= cpu_to_le16(key_type
);
927 cmd
.param
.keyinfo
= cpu_to_le16(key_info
);
928 cmd
.param
.keylen
= cpu_to_le16(key_len
);
930 memcpy(cmd
.param
.key
, key
, key_len
);
932 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
934 lbs_deb_leave(LBS_DEB_CFG80211
);
940 * Sets the auth type (open, shared, etc) in the firmware. That
941 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
942 * command doesn't send an authentication frame at all, it just
943 * stores the auth_type.
945 static int lbs_set_authtype(struct lbs_private
*priv
,
946 struct cfg80211_connect_params
*sme
)
948 struct cmd_ds_802_11_authenticate cmd
;
951 lbs_deb_enter_args(LBS_DEB_CFG80211
, "%d", sme
->auth_type
);
958 * BSS id 00 13 19 80 da 30
960 * reserved 00 00 00 00 00 00 00 00 00 00
962 memset(&cmd
, 0, sizeof(cmd
));
963 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
965 memcpy(cmd
.bssid
, sme
->bssid
, ETH_ALEN
);
966 /* convert auth_type */
967 ret
= lbs_auth_to_authtype(sme
->auth_type
);
972 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AUTHENTICATE
, &cmd
);
975 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
981 * Create association request
983 #define LBS_ASSOC_MAX_CMD_SIZE \
984 (sizeof(struct cmd_ds_802_11_associate) \
985 - 512 /* cmd_ds_802_11_associate.iebuf */ \
986 + LBS_MAX_SSID_TLV_SIZE \
987 + LBS_MAX_CHANNEL_TLV_SIZE \
988 + LBS_MAX_CF_PARAM_TLV_SIZE \
989 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
990 + LBS_MAX_WPA_TLV_SIZE)
992 static int lbs_associate(struct lbs_private
*priv
,
993 struct cfg80211_bss
*bss
,
994 struct cfg80211_connect_params
*sme
)
996 struct cmd_ds_802_11_associate_response
*resp
;
997 struct cmd_ds_802_11_associate
*cmd
= kzalloc(LBS_ASSOC_MAX_CMD_SIZE
,
1000 size_t len
, resp_ie_len
;
1003 u8
*pos
= &(cmd
->iebuf
[0]);
1005 lbs_deb_enter(LBS_DEB_CFG80211
);
1017 * BSS id 00 13 19 80 da 30
1018 * capabilities 11 00
1019 * listen interval 0a 00
1020 * beacon interval 00 00
1022 * TLVs xx (up to 512 bytes)
1024 cmd
->hdr
.command
= cpu_to_le16(CMD_802_11_ASSOCIATE
);
1026 /* Fill in static fields */
1027 memcpy(cmd
->bssid
, bss
->bssid
, ETH_ALEN
);
1028 cmd
->listeninterval
= cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL
);
1029 cmd
->capability
= cpu_to_le16(bss
->capability
);
1032 ssid_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SSID
);
1034 pos
+= lbs_add_ssid_tlv(pos
, ssid_eid
+ 2, ssid_eid
[1]);
1036 lbs_deb_assoc("no SSID\n");
1038 /* add DS param TLV */
1040 pos
+= lbs_add_channel_tlv(pos
, bss
->channel
->hw_value
);
1042 lbs_deb_assoc("no channel\n");
1044 /* add (empty) CF param TLV */
1045 pos
+= lbs_add_cf_param_tlv(pos
);
1048 pos
+= lbs_add_common_rates_tlv(pos
, bss
);
1050 /* add auth type TLV */
1051 if (priv
->fwrelease
>= 0x09000000)
1052 pos
+= lbs_add_auth_type_tlv(pos
, sme
->auth_type
);
1054 /* add WPA/WPA2 TLV */
1055 if (sme
->ie
&& sme
->ie_len
)
1056 pos
+= lbs_add_wpa_tlv(pos
, sme
->ie
, sme
->ie_len
);
1058 len
= (sizeof(*cmd
) - sizeof(cmd
->iebuf
)) +
1059 (u16
)(pos
- (u8
*) &cmd
->iebuf
);
1060 cmd
->hdr
.size
= cpu_to_le16(len
);
1062 /* store for later use */
1063 memcpy(priv
->assoc_bss
, bss
->bssid
, ETH_ALEN
);
1065 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ASSOCIATE
, cmd
);
1070 /* generate connect message to cfg80211 */
1072 resp
= (void *) cmd
; /* recast for easier field access */
1073 status
= le16_to_cpu(resp
->statuscode
);
1075 /* Convert statis code of old firmware */
1076 if (priv
->fwrelease
< 0x09000000)
1081 lbs_deb_assoc("invalid association parameters\n");
1082 status
= WLAN_STATUS_CAPS_UNSUPPORTED
;
1085 lbs_deb_assoc("timer expired while waiting for AP\n");
1086 status
= WLAN_STATUS_AUTH_TIMEOUT
;
1089 lbs_deb_assoc("association refused by AP\n");
1090 status
= WLAN_STATUS_ASSOC_DENIED_UNSPEC
;
1093 lbs_deb_assoc("authentication refused by AP\n");
1094 status
= WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION
;
1097 lbs_deb_assoc("association failure %d\n", status
);
1098 status
= WLAN_STATUS_UNSPECIFIED_FAILURE
;
1101 lbs_deb_assoc("status %d, capability 0x%04x\n", status
,
1102 le16_to_cpu(resp
->capability
));
1104 resp_ie_len
= le16_to_cpu(resp
->hdr
.size
)
1107 cfg80211_connect_result(priv
->dev
,
1109 sme
->ie
, sme
->ie_len
,
1110 resp
->iebuf
, resp_ie_len
,
1115 /* TODO: get rid of priv->connect_status */
1116 priv
->connect_status
= LBS_CONNECTED
;
1117 netif_carrier_on(priv
->dev
);
1118 if (!priv
->tx_pending_len
)
1119 netif_tx_wake_all_queues(priv
->dev
);
1124 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1130 static int lbs_cfg_connect(struct wiphy
*wiphy
, struct net_device
*dev
,
1131 struct cfg80211_connect_params
*sme
)
1133 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1134 struct cfg80211_bss
*bss
= NULL
;
1136 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1138 lbs_deb_enter(LBS_DEB_CFG80211
);
1141 bss
= cfg80211_get_bss(wiphy
, sme
->channel
, sme
->bssid
,
1142 sme
->ssid
, sme
->ssid_len
,
1143 WLAN_CAPABILITY_ESS
, WLAN_CAPABILITY_ESS
);
1146 * Here we have an impedance mismatch. The firmware command
1147 * CMD_802_11_ASSOCIATE always needs a BSSID, it cannot
1148 * connect otherwise. However, for the connect-API of
1149 * cfg80211 the bssid is purely optional. We don't get one,
1150 * except the user specifies one on the "iw" command line.
1152 * If we don't got one, we could initiate a scan and look
1153 * for the best matching cfg80211_bss entry.
1155 * Or, better yet, net/wireless/sme.c get's rewritten into
1156 * something more generally useful.
1158 lbs_pr_err("TODO: no BSS specified\n");
1165 lbs_pr_err("assicate: bss %pM not in scan results\n",
1170 lbs_deb_assoc("trying %pM", sme
->bssid
);
1171 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1172 sme
->crypto
.cipher_group
,
1173 sme
->key_idx
, sme
->key_len
);
1175 /* As this is a new connection, clear locally stored WEP keys */
1176 priv
->wep_tx_key
= 0;
1177 memset(priv
->wep_key
, 0, sizeof(priv
->wep_key
));
1178 memset(priv
->wep_key_len
, 0, sizeof(priv
->wep_key_len
));
1180 /* set/remove WEP keys */
1181 switch (sme
->crypto
.cipher_group
) {
1182 case WLAN_CIPHER_SUITE_WEP40
:
1183 case WLAN_CIPHER_SUITE_WEP104
:
1184 /* Store provided WEP keys in priv-> */
1185 priv
->wep_tx_key
= sme
->key_idx
;
1186 priv
->wep_key_len
[sme
->key_idx
] = sme
->key_len
;
1187 memcpy(priv
->wep_key
[sme
->key_idx
], sme
->key
, sme
->key_len
);
1188 /* Set WEP keys and WEP mode */
1189 lbs_set_wep_keys(priv
);
1190 priv
->mac_control
|= CMD_ACT_MAC_WEP_ENABLE
;
1191 lbs_set_mac_control(priv
);
1192 /* No RSN mode for WEP */
1193 lbs_enable_rsn(priv
, 0);
1195 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1197 * If we don't have no WEP, no WPA and no WPA2,
1198 * we remove all keys like in the WPA/WPA2 setup,
1199 * we just don't set RSN.
1201 * Therefore: fall-throught
1203 case WLAN_CIPHER_SUITE_TKIP
:
1204 case WLAN_CIPHER_SUITE_CCMP
:
1205 /* Remove WEP keys and WEP mode */
1206 lbs_remove_wep_keys(priv
);
1207 priv
->mac_control
&= ~CMD_ACT_MAC_WEP_ENABLE
;
1208 lbs_set_mac_control(priv
);
1210 /* clear the WPA/WPA2 keys */
1211 lbs_set_key_material(priv
,
1212 KEY_TYPE_ID_WEP
, /* doesn't matter */
1213 KEY_INFO_WPA_UNICAST
,
1215 lbs_set_key_material(priv
,
1216 KEY_TYPE_ID_WEP
, /* doesn't matter */
1219 /* RSN mode for WPA/WPA2 */
1220 lbs_enable_rsn(priv
, sme
->crypto
.cipher_group
!= 0);
1223 lbs_pr_err("unsupported cipher group 0x%x\n",
1224 sme
->crypto
.cipher_group
);
1229 lbs_set_authtype(priv
, sme
);
1230 lbs_set_radio(priv
, preamble
, 1);
1232 /* Do the actual association */
1233 lbs_associate(priv
, bss
, sme
);
1237 cfg80211_put_bss(bss
);
1238 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1242 static int lbs_cfg_disconnect(struct wiphy
*wiphy
, struct net_device
*dev
,
1245 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1246 struct cmd_ds_802_11_deauthenticate cmd
;
1248 lbs_deb_enter_args(LBS_DEB_CFG80211
, "reason_code %d", reason_code
);
1250 /* store for lbs_cfg_ret_disconnect() */
1251 priv
->disassoc_reason
= reason_code
;
1253 memset(&cmd
, 0, sizeof(cmd
));
1254 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1255 /* Mildly ugly to use a locally store my own BSSID ... */
1256 memcpy(cmd
.macaddr
, &priv
->assoc_bss
, ETH_ALEN
);
1257 cmd
.reasoncode
= cpu_to_le16(reason_code
);
1259 if (lbs_cmd_with_response(priv
, CMD_802_11_DEAUTHENTICATE
, &cmd
))
1262 cfg80211_disconnected(priv
->dev
,
1263 priv
->disassoc_reason
,
1266 priv
->connect_status
= LBS_DISCONNECTED
;
1272 static int lbs_cfg_set_default_key(struct wiphy
*wiphy
,
1273 struct net_device
*netdev
,
1276 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1278 lbs_deb_enter(LBS_DEB_CFG80211
);
1280 if (key_index
!= priv
->wep_tx_key
) {
1281 lbs_deb_assoc("set_default_key: to %d\n", key_index
);
1282 priv
->wep_tx_key
= key_index
;
1283 lbs_set_wep_keys(priv
);
1290 static int lbs_cfg_add_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1291 u8 idx
, const u8
*mac_addr
,
1292 struct key_params
*params
)
1294 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1299 lbs_deb_enter(LBS_DEB_CFG80211
);
1301 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1302 params
->cipher
, mac_addr
);
1303 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1304 idx
, params
->key_len
);
1305 if (params
->key_len
)
1306 lbs_deb_hex(LBS_DEB_CFG80211
, "KEY",
1307 params
->key
, params
->key_len
);
1309 lbs_deb_assoc("add_key: seq len %d\n", params
->seq_len
);
1310 if (params
->seq_len
)
1311 lbs_deb_hex(LBS_DEB_CFG80211
, "SEQ",
1312 params
->seq
, params
->seq_len
);
1314 switch (params
->cipher
) {
1315 case WLAN_CIPHER_SUITE_WEP40
:
1316 case WLAN_CIPHER_SUITE_WEP104
:
1317 /* actually compare if something has changed ... */
1318 if ((priv
->wep_key_len
[idx
] != params
->key_len
) ||
1319 memcmp(priv
->wep_key
[idx
],
1320 params
->key
, params
->key_len
) != 0) {
1321 priv
->wep_key_len
[idx
] = params
->key_len
;
1322 memcpy(priv
->wep_key
[idx
],
1323 params
->key
, params
->key_len
);
1324 lbs_set_wep_keys(priv
);
1327 case WLAN_CIPHER_SUITE_TKIP
:
1328 case WLAN_CIPHER_SUITE_CCMP
:
1329 key_info
= KEY_INFO_WPA_ENABLED
| ((idx
== 0)
1330 ? KEY_INFO_WPA_UNICAST
1331 : KEY_INFO_WPA_MCAST
);
1332 key_type
= (params
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1335 lbs_set_key_material(priv
,
1338 params
->key
, params
->key_len
);
1341 lbs_pr_err("unhandled cipher 0x%x\n", params
->cipher
);
1350 static int lbs_cfg_del_key(struct wiphy
*wiphy
, struct net_device
*netdev
,
1351 u8 key_index
, const u8
*mac_addr
)
1354 lbs_deb_enter(LBS_DEB_CFG80211
);
1356 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1357 key_index
, mac_addr
);
1360 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1362 * I think can keep this a NO-OP, because:
1364 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1365 * - neither "iw" nor "wpa_supplicant" won't call this during
1366 * an ongoing connection
1367 * - TODO: but I have to check if this is still true when
1368 * I set the AP to periodic re-keying
1369 * - we've not kzallec() something when we've added a key at
1370 * lbs_cfg_connect() or lbs_cfg_add_key().
1372 * This causes lbs_cfg_del_key() only called at disconnect time,
1373 * where we'd just waste time deleting a key that is not going
1374 * to be used anyway.
1376 if (key_index
< 3 && priv
->wep_key_len
[key_index
]) {
1377 priv
->wep_key_len
[key_index
] = 0;
1378 lbs_set_wep_keys(priv
);
1387 /***************************************************************************
1391 /* like "struct cmd_ds_802_11_monitor_mode", but with cmd_header. Once we
1392 * get rid of WEXT, this should go into host.h */
1393 struct cmd_monitor_mode
{
1394 struct cmd_header hdr
;
1398 } __attribute__ ((packed
));
1400 static int lbs_enable_monitor_mode(struct lbs_private
*priv
, int mode
)
1402 struct cmd_monitor_mode cmd
;
1405 lbs_deb_enter(LBS_DEB_CFG80211
);
1412 * action 01 00 ACT_SET
1415 memset(&cmd
, 0, sizeof(cmd
));
1416 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1417 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1418 cmd
.mode
= cpu_to_le16(mode
);
1420 ret
= lbs_cmd_with_response(priv
, CMD_802_11_MONITOR_MODE
, &cmd
);
1423 priv
->dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
1425 priv
->dev
->type
= ARPHRD_ETHER
;
1427 lbs_deb_leave(LBS_DEB_CFG80211
);
1436 /***************************************************************************
1441 * Returns the signal or 0 in case of an error.
1444 /* like "struct cmd_ds_802_11_rssi", but with cmd_header. Once we get rid
1445 * of WEXT, this should go into host.h */
1447 struct cmd_header hdr
;
1453 } __attribute__ ((packed
));
1455 static int lbs_get_signal(struct lbs_private
*priv
, s8
*signal
, s8
*noise
)
1457 struct cmd_rssi cmd
;
1460 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1461 cmd
.n_or_snr
= cpu_to_le16(DEFAULT_BCN_AVG_FACTOR
);
1462 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RSSI
, &cmd
);
1465 *signal
= CAL_RSSI(le16_to_cpu(cmd
.n_or_snr
),
1466 le16_to_cpu(cmd
.nf
));
1467 *noise
= CAL_NF(le16_to_cpu(cmd
.nf
));
1473 static int lbs_cfg_get_station(struct wiphy
*wiphy
, struct net_device
*dev
,
1474 u8
*mac
, struct station_info
*sinfo
)
1476 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1481 lbs_deb_enter(LBS_DEB_CFG80211
);
1483 sinfo
->filled
|= STATION_INFO_TX_BYTES
|
1484 STATION_INFO_TX_PACKETS
|
1485 STATION_INFO_RX_BYTES
|
1486 STATION_INFO_RX_PACKETS
;
1487 sinfo
->tx_bytes
= priv
->dev
->stats
.tx_bytes
;
1488 sinfo
->tx_packets
= priv
->dev
->stats
.tx_packets
;
1489 sinfo
->rx_bytes
= priv
->dev
->stats
.rx_bytes
;
1490 sinfo
->rx_packets
= priv
->dev
->stats
.rx_packets
;
1492 /* Get current RSSI */
1493 ret
= lbs_get_signal(priv
, &signal
, &noise
);
1495 sinfo
->signal
= signal
;
1496 sinfo
->filled
|= STATION_INFO_SIGNAL
;
1499 /* Convert priv->cur_rate from hw_value to NL80211 value */
1500 for (i
= 0; i
< ARRAY_SIZE(lbs_rates
); i
++) {
1501 if (priv
->cur_rate
== lbs_rates
[i
].hw_value
) {
1502 sinfo
->txrate
.legacy
= lbs_rates
[i
].bitrate
;
1503 sinfo
->filled
|= STATION_INFO_TX_BITRATE
;
1514 /***************************************************************************
1515 * "Site survey", here just current channel and noise level
1518 static int lbs_get_survey(struct wiphy
*wiphy
, struct net_device
*dev
,
1519 int idx
, struct survey_info
*survey
)
1521 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1528 lbs_deb_enter(LBS_DEB_CFG80211
);
1530 survey
->channel
= ieee80211_get_channel(wiphy
,
1531 ieee80211_channel_to_frequency(priv
->channel
));
1533 ret
= lbs_get_signal(priv
, &signal
, &noise
);
1535 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
1536 survey
->noise
= noise
;
1539 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1546 /***************************************************************************
1550 static int lbs_change_intf(struct wiphy
*wiphy
, struct net_device
*dev
,
1551 enum nl80211_iftype type
, u32
*flags
,
1552 struct vif_params
*params
)
1554 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1557 lbs_deb_enter(LBS_DEB_CFG80211
);
1560 case NL80211_IFTYPE_MONITOR
:
1561 ret
= lbs_enable_monitor_mode(priv
, 1);
1563 case NL80211_IFTYPE_STATION
:
1564 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1565 ret
= lbs_enable_monitor_mode(priv
, 0);
1567 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 1);
1569 case NL80211_IFTYPE_ADHOC
:
1570 if (priv
->wdev
->iftype
== NL80211_IFTYPE_MONITOR
)
1571 ret
= lbs_enable_monitor_mode(priv
, 0);
1573 ret
= lbs_set_snmp_mib(priv
, SNMP_MIB_OID_BSS_TYPE
, 2);
1580 priv
->wdev
->iftype
= type
;
1582 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1588 /***************************************************************************
1592 /* The firmware needs the following bits masked out of the beacon-derived
1593 * capability field when associating/joining to a BSS:
1594 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1596 #define CAPINFO_MASK (~(0xda00))
1599 static void lbs_join_post(struct lbs_private
*priv
,
1600 struct cfg80211_ibss_params
*params
,
1601 u8
*bssid
, u16 capability
)
1603 u8 fake_ie
[2 + IEEE80211_MAX_SSID_LEN
+ /* ssid */
1604 2 + 4 + /* basic rates */
1605 2 + 1 + /* DS parameter */
1607 2 + 8]; /* extended rates */
1610 lbs_deb_enter(LBS_DEB_CFG80211
);
1613 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1614 * the real IE from the firmware. So we fabricate a fake IE based on
1615 * what the firmware actually sends (sniffed with wireshark).
1618 *fake
++ = WLAN_EID_SSID
;
1619 *fake
++ = params
->ssid_len
;
1620 memcpy(fake
, params
->ssid
, params
->ssid_len
);
1621 fake
+= params
->ssid_len
;
1622 /* Fake supported basic rates IE */
1623 *fake
++ = WLAN_EID_SUPP_RATES
;
1629 /* Fake DS channel IE */
1630 *fake
++ = WLAN_EID_DS_PARAMS
;
1632 *fake
++ = params
->channel
->hw_value
;
1633 /* Fake IBSS params IE */
1634 *fake
++ = WLAN_EID_IBSS_PARAMS
;
1636 *fake
++ = 0; /* ATIM=0 */
1638 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1639 * but I don't know how this could be checked */
1640 *fake
++ = WLAN_EID_EXT_SUPP_RATES
;
1650 lbs_deb_hex(LBS_DEB_CFG80211
, "IE", fake_ie
, fake
- fake_ie
);
1652 cfg80211_inform_bss(priv
->wdev
->wiphy
,
1657 params
->beacon_interval
,
1658 fake_ie
, fake
- fake_ie
,
1661 memcpy(priv
->wdev
->ssid
, params
->ssid
, params
->ssid_len
);
1662 priv
->wdev
->ssid_len
= params
->ssid_len
;
1664 cfg80211_ibss_joined(priv
->dev
, bssid
, GFP_KERNEL
);
1666 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1667 priv
->connect_status
= LBS_CONNECTED
;
1668 netif_carrier_on(priv
->dev
);
1669 if (!priv
->tx_pending_len
)
1670 netif_wake_queue(priv
->dev
);
1672 lbs_deb_leave(LBS_DEB_CFG80211
);
1675 static int lbs_ibss_join_existing(struct lbs_private
*priv
,
1676 struct cfg80211_ibss_params
*params
,
1677 struct cfg80211_bss
*bss
)
1679 const u8
*rates_eid
= ieee80211_bss_get_ie(bss
, WLAN_EID_SUPP_RATES
);
1680 struct cmd_ds_802_11_ad_hoc_join cmd
;
1681 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1684 lbs_deb_enter(LBS_DEB_CFG80211
);
1686 /* TODO: set preamble based on scan result */
1687 ret
= lbs_set_radio(priv
, preamble
, 1);
1692 * Example CMD_802_11_AD_HOC_JOIN command:
1694 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1698 * bssid 02 27 27 97 2f 96
1699 * ssid 49 42 53 53 00 00 00 00
1700 * 00 00 00 00 00 00 00 00
1701 * 00 00 00 00 00 00 00 00
1702 * 00 00 00 00 00 00 00 00
1703 * type 02 CMD_BSS_TYPE_IBSS
1704 * beacon period 64 00
1706 * timestamp 00 00 00 00 00 00 00 00
1707 * localtime 00 00 00 00 00 00 00 00
1711 * reserveed 00 00 00 00
1714 * IE IBSS atim 00 00
1715 * reserved 00 00 00 00
1717 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1718 * fail timeout ff 00
1721 memset(&cmd
, 0, sizeof(cmd
));
1722 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1724 memcpy(cmd
.bss
.bssid
, bss
->bssid
, ETH_ALEN
);
1725 memcpy(cmd
.bss
.ssid
, params
->ssid
, params
->ssid_len
);
1726 cmd
.bss
.type
= CMD_BSS_TYPE_IBSS
;
1727 cmd
.bss
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1728 cmd
.bss
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1729 cmd
.bss
.ds
.header
.len
= 1;
1730 cmd
.bss
.ds
.channel
= params
->channel
->hw_value
;
1731 cmd
.bss
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1732 cmd
.bss
.ibss
.header
.len
= 2;
1733 cmd
.bss
.ibss
.atimwindow
= 0;
1734 cmd
.bss
.capability
= cpu_to_le16(bss
->capability
& CAPINFO_MASK
);
1736 /* set rates to the intersection of our rates and the rates in the
1739 lbs_add_rates(cmd
.bss
.rates
);
1742 u8 rates_max
= rates_eid
[1];
1743 u8
*rates
= cmd
.bss
.rates
;
1744 for (hw
= 0; hw
< ARRAY_SIZE(lbs_rates
); hw
++) {
1745 u8 hw_rate
= lbs_rates
[hw
].bitrate
/ 5;
1746 for (i
= 0; i
< rates_max
; i
++) {
1747 if (hw_rate
== (rates_eid
[i
+2] & 0x7f)) {
1748 u8 rate
= rates_eid
[i
+2];
1749 if (rate
== 0x02 || rate
== 0x04 ||
1750 rate
== 0x0b || rate
== 0x16)
1758 /* Only v8 and below support setting this */
1759 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8) {
1760 cmd
.failtimeout
= cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT
);
1761 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1763 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_JOIN
, &cmd
);
1768 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1776 lbs_join_post(priv
, params
, bss
->bssid
, bss
->capability
);
1779 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1785 static int lbs_ibss_start_new(struct lbs_private
*priv
,
1786 struct cfg80211_ibss_params
*params
)
1788 struct cmd_ds_802_11_ad_hoc_start cmd
;
1789 struct cmd_ds_802_11_ad_hoc_result
*resp
=
1790 (struct cmd_ds_802_11_ad_hoc_result
*) &cmd
;
1791 u8 preamble
= RADIO_PREAMBLE_SHORT
;
1795 lbs_deb_enter(LBS_DEB_CFG80211
);
1797 ret
= lbs_set_radio(priv
, preamble
, 1);
1802 * Example CMD_802_11_AD_HOC_START command:
1804 * command 2b 00 CMD_802_11_AD_HOC_START
1808 * ssid 54 45 53 54 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
1813 * beacon period 64 00
1817 * IE IBSS atim 00 00
1818 * reserved 00 00 00 00
1822 * reserved 00 00 00 00
1825 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1826 * 0c 12 18 24 30 48 60 6c
1829 memset(&cmd
, 0, sizeof(cmd
));
1830 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1831 memcpy(cmd
.ssid
, params
->ssid
, params
->ssid_len
);
1832 cmd
.bsstype
= CMD_BSS_TYPE_IBSS
;
1833 cmd
.beaconperiod
= cpu_to_le16(params
->beacon_interval
);
1834 cmd
.ibss
.header
.id
= WLAN_EID_IBSS_PARAMS
;
1835 cmd
.ibss
.header
.len
= 2;
1836 cmd
.ibss
.atimwindow
= 0;
1837 cmd
.ds
.header
.id
= WLAN_EID_DS_PARAMS
;
1838 cmd
.ds
.header
.len
= 1;
1839 cmd
.ds
.channel
= params
->channel
->hw_value
;
1840 /* Only v8 and below support setting probe delay */
1841 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) <= 8)
1842 cmd
.probedelay
= cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME
);
1843 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1844 capability
= WLAN_CAPABILITY_IBSS
;
1845 cmd
.capability
= cpu_to_le16(capability
);
1846 lbs_add_rates(cmd
.rates
);
1849 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_START
, &cmd
);
1854 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1861 * bssid 02 2b 7b 0f 86 0e
1863 lbs_join_post(priv
, params
, resp
->bssid
, capability
);
1866 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1871 static int lbs_join_ibss(struct wiphy
*wiphy
, struct net_device
*dev
,
1872 struct cfg80211_ibss_params
*params
)
1874 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1876 struct cfg80211_bss
*bss
;
1877 DECLARE_SSID_BUF(ssid_buf
);
1879 lbs_deb_enter(LBS_DEB_CFG80211
);
1881 if (!params
->channel
) {
1886 ret
= lbs_set_channel(priv
, params
->channel
->hw_value
);
1890 /* Search if someone is beaconing. This assumes that the
1891 * bss list is populated already */
1892 bss
= cfg80211_get_bss(wiphy
, params
->channel
, params
->bssid
,
1893 params
->ssid
, params
->ssid_len
,
1894 WLAN_CAPABILITY_IBSS
, WLAN_CAPABILITY_IBSS
);
1897 ret
= lbs_ibss_join_existing(priv
, params
, bss
);
1898 cfg80211_put_bss(bss
);
1900 ret
= lbs_ibss_start_new(priv
, params
);
1904 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1909 static int lbs_leave_ibss(struct wiphy
*wiphy
, struct net_device
*dev
)
1911 struct lbs_private
*priv
= wiphy_priv(wiphy
);
1912 struct cmd_ds_802_11_ad_hoc_stop cmd
;
1915 lbs_deb_enter(LBS_DEB_CFG80211
);
1917 memset(&cmd
, 0, sizeof(cmd
));
1918 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1919 ret
= lbs_cmd_with_response(priv
, CMD_802_11_AD_HOC_STOP
, &cmd
);
1921 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1922 lbs_mac_event_disconnected(priv
);
1924 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1931 /***************************************************************************
1935 static struct cfg80211_ops lbs_cfg80211_ops
= {
1936 .set_channel
= lbs_cfg_set_channel
,
1937 .scan
= lbs_cfg_scan
,
1938 .connect
= lbs_cfg_connect
,
1939 .disconnect
= lbs_cfg_disconnect
,
1940 .add_key
= lbs_cfg_add_key
,
1941 .del_key
= lbs_cfg_del_key
,
1942 .set_default_key
= lbs_cfg_set_default_key
,
1943 .get_station
= lbs_cfg_get_station
,
1944 .dump_survey
= lbs_get_survey
,
1945 .change_virtual_intf
= lbs_change_intf
,
1946 .join_ibss
= lbs_join_ibss
,
1947 .leave_ibss
= lbs_leave_ibss
,
1952 * At this time lbs_private *priv doesn't even exist, so we just allocate
1953 * memory and don't initialize the wiphy further. This is postponed until we
1954 * can talk to the firmware and happens at registration time in
1955 * lbs_cfg_wiphy_register().
1957 struct wireless_dev
*lbs_cfg_alloc(struct device
*dev
)
1960 struct wireless_dev
*wdev
;
1962 lbs_deb_enter(LBS_DEB_CFG80211
);
1964 wdev
= kzalloc(sizeof(struct wireless_dev
), GFP_KERNEL
);
1966 dev_err(dev
, "cannot allocate wireless device\n");
1967 return ERR_PTR(-ENOMEM
);
1970 wdev
->wiphy
= wiphy_new(&lbs_cfg80211_ops
, sizeof(struct lbs_private
));
1972 dev_err(dev
, "cannot allocate wiphy\n");
1977 lbs_deb_leave(LBS_DEB_CFG80211
);
1982 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
1983 return ERR_PTR(ret
);
1987 static void lbs_cfg_set_regulatory_hint(struct lbs_private
*priv
)
1989 struct region_code_mapping
{
1994 /* Section 5.17.2 */
1995 static struct region_code_mapping regmap
[] = {
1996 {"US ", 0x10}, /* US FCC */
1997 {"CA ", 0x20}, /* Canada */
1998 {"EU ", 0x30}, /* ETSI */
1999 {"ES ", 0x31}, /* Spain */
2000 {"FR ", 0x32}, /* France */
2001 {"JP ", 0x40}, /* Japan */
2005 lbs_deb_enter(LBS_DEB_CFG80211
);
2007 for (i
= 0; i
< ARRAY_SIZE(regmap
); i
++)
2008 if (regmap
[i
].code
== priv
->regioncode
) {
2009 regulatory_hint(priv
->wdev
->wiphy
, regmap
[i
].cn
);
2013 lbs_deb_leave(LBS_DEB_CFG80211
);
2018 * This function get's called after lbs_setup_firmware() determined the
2019 * firmware capabities. So we can setup the wiphy according to our
2020 * hardware/firmware.
2022 int lbs_cfg_register(struct lbs_private
*priv
)
2024 struct wireless_dev
*wdev
= priv
->wdev
;
2027 lbs_deb_enter(LBS_DEB_CFG80211
);
2029 wdev
->wiphy
->max_scan_ssids
= 1;
2030 wdev
->wiphy
->signal_type
= CFG80211_SIGNAL_TYPE_MBM
;
2032 wdev
->wiphy
->interface_modes
=
2033 BIT(NL80211_IFTYPE_STATION
) |
2034 BIT(NL80211_IFTYPE_ADHOC
);
2035 if (lbs_rtap_supported(priv
))
2036 wdev
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_MONITOR
);
2038 wdev
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &lbs_band_2ghz
;
2041 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2042 * never seen a firmware without WPA
2044 wdev
->wiphy
->cipher_suites
= cipher_suites
;
2045 wdev
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
2046 wdev
->wiphy
->reg_notifier
= lbs_reg_notifier
;
2048 ret
= wiphy_register(wdev
->wiphy
);
2050 lbs_pr_err("cannot register wiphy device\n");
2052 priv
->wiphy_registered
= true;
2054 ret
= register_netdev(priv
->dev
);
2056 lbs_pr_err("cannot register network device\n");
2058 INIT_DELAYED_WORK(&priv
->scan_work
, lbs_scan_worker
);
2060 lbs_cfg_set_regulatory_hint(priv
);
2062 lbs_deb_leave_args(LBS_DEB_CFG80211
, "ret %d", ret
);
2067 * @brief This function sets DOMAIN INFO to FW
2068 * @param priv pointer to struct lbs_private
2071 static int lbs_11d_set_domain_info(struct lbs_private
*priv
)
2075 ret
= lbs_prepare_and_send_command(priv
, CMD_802_11D_DOMAIN_INFO
,
2077 CMD_OPTION_WAITFORRSP
, 0, NULL
);
2079 lbs_deb_11d("fail to dnld domain info\n");
2084 static void lbs_send_domain_info_cmd_fw(struct wiphy
*wiphy
,
2085 struct regulatory_request
*request
)
2087 u8 no_of_triplet
= 0;
2088 u8 no_of_parsed_chan
= 0;
2089 u8 first_channel
= 0, next_chan
= 0, max_pwr
= 0;
2091 enum ieee80211_band band
;
2092 struct ieee80211_supported_band
*sband
;
2093 struct ieee80211_channel
*ch
;
2094 struct lbs_private
*priv
= wiphy_priv(wiphy
);
2095 struct lbs_802_11d_domain_reg
*domain_info
= &priv
->domain_reg
;
2098 lbs_deb_enter(LBS_DEB_CFG80211
);
2100 /* Set country code */
2101 domain_info
->country_code
[0] = request
->alpha2
[0];
2102 domain_info
->country_code
[1] = request
->alpha2
[1];
2103 domain_info
->country_code
[2] = ' ';
2105 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2107 if (!wiphy
->bands
[band
])
2110 sband
= wiphy
->bands
[band
];
2112 for (i
= 0; i
< sband
->n_channels
; i
++) {
2113 ch
= &sband
->channels
[i
];
2114 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
2119 next_chan
= first_channel
= (u32
) ch
->hw_value
;
2120 max_pwr
= ch
->max_power
;
2121 no_of_parsed_chan
= 1;
2125 if (ch
->hw_value
== next_chan
+ 1 &&
2126 ch
->max_power
== max_pwr
) {
2128 no_of_parsed_chan
++;
2130 domain_info
->triplet
[no_of_triplet
]
2131 .chans
.first_channel
= first_channel
;
2132 domain_info
->triplet
[no_of_triplet
]
2133 .chans
.num_channels
= no_of_parsed_chan
;
2134 domain_info
->triplet
[no_of_triplet
]
2135 .chans
.max_power
= max_pwr
;
2141 domain_info
->triplet
[no_of_triplet
]
2142 .chans
.first_channel
= first_channel
;
2143 domain_info
->triplet
[no_of_triplet
]
2144 .chans
.num_channels
= no_of_parsed_chan
;
2145 domain_info
->triplet
[no_of_triplet
]
2146 .chans
.max_power
= max_pwr
;
2151 domain_info
->no_triplet
= no_of_triplet
;
2153 /* Set domain info */
2154 ret
= lbs_11d_set_domain_info(priv
);
2156 lbs_pr_err("11D: error setting domain info in FW\n");
2158 lbs_deb_leave(LBS_DEB_CFG80211
);
2161 int lbs_reg_notifier(struct wiphy
*wiphy
,
2162 struct regulatory_request
*request
)
2164 lbs_deb_enter_args(LBS_DEB_CFG80211
, "cfg80211 regulatory domain "
2165 "callback for domain %c%c\n", request
->alpha2
[0],
2166 request
->alpha2
[1]);
2168 lbs_send_domain_info_cmd_fw(wiphy
, request
);
2170 lbs_deb_leave(LBS_DEB_CFG80211
);
2175 void lbs_scan_deinit(struct lbs_private
*priv
)
2177 lbs_deb_enter(LBS_DEB_CFG80211
);
2178 cancel_delayed_work_sync(&priv
->scan_work
);
2182 void lbs_cfg_free(struct lbs_private
*priv
)
2184 struct wireless_dev
*wdev
= priv
->wdev
;
2186 lbs_deb_enter(LBS_DEB_CFG80211
);
2191 if (priv
->wiphy_registered
)
2192 wiphy_unregister(wdev
->wiphy
);
2195 wiphy_free(wdev
->wiphy
);