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/sched.h>
12 #include <linux/wait.h>
13 #include <linux/slab.h>
14 #include <linux/ieee80211.h>
15 #include <net/cfg80211.h>
16 #include <asm/unaligned.h>
23 #define CHAN2G(_channel, _freq, _flags) { \
24 .band = IEEE80211_BAND_2GHZ, \
25 .center_freq = (_freq), \
26 .hw_value = (_channel), \
28 .max_antenna_gain = 0, \
32 static struct ieee80211_channel lbs_2ghz_channels[] = {
49 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
51 .hw_value = (_hw_value), \
56 /* Table 6 in section 3.2.1.1 */
57 static struct ieee80211_rate lbs_rates[] = {
58 RATETAB_ENT(10, 0, 0),
59 RATETAB_ENT(20, 1, 0),
60 RATETAB_ENT(55, 2, 0),
61 RATETAB_ENT(110, 3, 0),
62 RATETAB_ENT(60, 9, 0),
63 RATETAB_ENT(90, 6, 0),
64 RATETAB_ENT(120, 7, 0),
65 RATETAB_ENT(180, 8, 0),
66 RATETAB_ENT(240, 9, 0),
67 RATETAB_ENT(360, 10, 0),
68 RATETAB_ENT(480, 11, 0),
69 RATETAB_ENT(540, 12, 0),
72 static struct ieee80211_supported_band lbs_band_2ghz = {
73 .channels = lbs_2ghz_channels,
74 .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
75 .bitrates = lbs_rates,
76 .n_bitrates = ARRAY_SIZE(lbs_rates),
80 static const u32 cipher_suites[] = {
81 WLAN_CIPHER_SUITE_WEP40,
82 WLAN_CIPHER_SUITE_WEP104,
83 WLAN_CIPHER_SUITE_TKIP,
84 WLAN_CIPHER_SUITE_CCMP,
87 /* Time to stay on the channel */
88 #define LBS_DWELL_PASSIVE 100
89 #define LBS_DWELL_ACTIVE 40
92 /***************************************************************************
93 * Misc utility functions
95 * TLVs are Marvell specific. They are very similar to IEs, they have the
96 * same structure: type, length, data*. The only difference: for IEs, the
97 * type and length are u8, but for TLVs they're __le16.
101 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
102 * in the firmware spec
104 static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
109 case NL80211_AUTHTYPE_OPEN_SYSTEM:
110 case NL80211_AUTHTYPE_SHARED_KEY:
113 case NL80211_AUTHTYPE_AUTOMATIC:
114 ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
116 case NL80211_AUTHTYPE_NETWORK_EAP:
120 /* silence compiler */
128 * Various firmware commands need the list of supported rates, but with
129 * the hight-bit set for basic rates
131 static int lbs_add_rates(u8 *rates)
135 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
136 u8 rate = lbs_rates[i].bitrate / 5;
137 if (rate == 0x02 || rate == 0x04 ||
138 rate == 0x0b || rate == 0x16)
142 return ARRAY_SIZE(lbs_rates);
146 /***************************************************************************
147 * TLV utility functions
149 * TLVs are Marvell specific. They are very similar to IEs, they have the
150 * same structure: type, length, data*. The only difference: for IEs, the
151 * type and length are u8, but for TLVs they're __le16.
158 #define LBS_MAX_SSID_TLV_SIZE \
159 (sizeof(struct mrvl_ie_header) \
160 + IEEE80211_MAX_SSID_LEN)
162 static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
164 struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
169 * ssid 4d 4e 54 45 53 54
171 ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
172 ssid_tlv->header.len = cpu_to_le16(ssid_len);
173 memcpy(ssid_tlv->ssid, ssid, ssid_len);
174 return sizeof(ssid_tlv->header) + ssid_len;
179 * Add channel list TLV (section 8.4.2)
181 * Actual channel data comes from priv->wdev->wiphy->channels.
183 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
184 (sizeof(struct mrvl_ie_header) \
185 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
187 static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
188 int last_channel, int active_scan)
190 int chanscanparamsize = sizeof(struct chanscanparamset) *
191 (last_channel - priv->scan_channel);
193 struct mrvl_ie_header *header = (void *) tlv;
196 * TLV-ID CHANLIST 01 01
198 * channel 00 01 00 00 00 64 00
202 * min scan time 00 00
203 * max scan time 64 00
204 * channel 2 00 02 00 00 00 64 00
208 header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
209 header->len = cpu_to_le16(chanscanparamsize);
210 tlv += sizeof(struct mrvl_ie_header);
212 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
214 memset(tlv, 0, chanscanparamsize);
216 while (priv->scan_channel < last_channel) {
217 struct chanscanparamset *param = (void *) tlv;
219 param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
221 priv->scan_req->channels[priv->scan_channel]->hw_value;
223 param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
225 param->chanscanmode.passivescan = 1;
226 param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
228 tlv += sizeof(struct chanscanparamset);
229 priv->scan_channel++;
231 return sizeof(struct mrvl_ie_header) + chanscanparamsize;
238 * The rates are in lbs_bg_rates[], but for the 802.11b
239 * rates the high bit is set. We add this TLV only because
240 * there's a firmware which otherwise doesn't report all
243 #define LBS_MAX_RATES_TLV_SIZE \
244 (sizeof(struct mrvl_ie_header) \
245 + (ARRAY_SIZE(lbs_rates)))
247 /* Adds a TLV with all rates the hardware supports */
248 static int lbs_add_supported_rates_tlv(u8 *tlv)
251 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
256 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
258 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
259 tlv += sizeof(rate_tlv->header);
260 i = lbs_add_rates(tlv);
262 rate_tlv->header.len = cpu_to_le16(i);
263 return sizeof(rate_tlv->header) + i;
266 /* Add common rates from a TLV and return the new end of the TLV */
268 add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
270 int hw, ap, ap_max = ie[1];
273 /* Advance past IE header */
276 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
278 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
279 hw_rate = lbs_rates[hw].bitrate / 5;
280 for (ap = 0; ap < ap_max; ap++) {
281 if (hw_rate == (ie[ap] & 0x7f)) {
283 *nrates = *nrates + 1;
291 * Adds a TLV with all rates the hardware *and* BSS supports.
293 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
295 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
296 const u8 *rates_eid, *ext_rates_eid;
299 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
300 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
303 * 01 00 TLV_TYPE_RATES
307 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
308 tlv += sizeof(rate_tlv->header);
310 /* Add basic rates */
312 tlv = add_ie_rates(tlv, rates_eid, &n);
314 /* Add extended rates, if any */
316 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
318 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
319 /* Fallback: add basic 802.11b rates */
327 rate_tlv->header.len = cpu_to_le16(n);
328 return sizeof(rate_tlv->header) + n;
335 * This is only needed for newer firmware (V9 and up).
337 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
338 sizeof(struct mrvl_ie_auth_type)
340 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
342 struct mrvl_ie_auth_type *auth = (void *) tlv;
345 * 1f 01 TLV_TYPE_AUTH_TYPE
349 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
350 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
351 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
352 return sizeof(*auth);
357 * Add channel (phy ds) TLV
359 #define LBS_MAX_CHANNEL_TLV_SIZE \
360 sizeof(struct mrvl_ie_header)
362 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
364 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
367 * 03 00 TLV_TYPE_PHY_DS
371 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
372 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
373 ds->channel = channel;
379 * Add (empty) CF param TLV of the form:
381 #define LBS_MAX_CF_PARAM_TLV_SIZE \
382 sizeof(struct mrvl_ie_header)
384 static int lbs_add_cf_param_tlv(u8 *tlv)
386 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
393 * 00 00 cfpmaxduration
394 * 00 00 cfpdurationremaining
396 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
397 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
404 #define LBS_MAX_WPA_TLV_SIZE \
405 (sizeof(struct mrvl_ie_header) \
406 + 128 /* TODO: I guessed the size */)
408 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
413 * We need just convert an IE to an TLV. IEs use u8 for the header,
417 * but TLVs use __le16 instead:
424 tlv_len = *tlv++ = *ie++;
428 /* the TLV is two bytes larger than the IE */
436 static int lbs_cfg_set_channel(struct wiphy *wiphy,
437 struct net_device *netdev,
438 struct ieee80211_channel *channel,
439 enum nl80211_channel_type channel_type)
441 struct lbs_private *priv = wiphy_priv(wiphy);
444 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
445 channel->center_freq, channel_type);
447 if (channel_type != NL80211_CHAN_NO_HT)
450 ret = lbs_set_channel(priv, channel->hw_value);
453 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
464 * When scanning, the firmware doesn't send a nul packet with the power-safe
465 * bit to the AP. So we cannot stay away from our current channel too long,
466 * otherwise we loose data. So take a "nap" while scanning every other
469 #define LBS_SCAN_BEFORE_NAP 4
473 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
474 * which isn't really an RSSI, as it becomes larger when moving away from
475 * the AP. Anyway, we need to convert that into mBm.
477 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
478 ((-(int)rssi + 3)*100)
480 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
481 struct cmd_header *resp)
483 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
491 lbs_deb_enter(LBS_DEB_CFG80211);
493 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
495 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
496 scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
498 if (scanresp->nr_sets == 0) {
504 * The general layout of the scan response is described in chapter
505 * 5.7.1. Basically we have a common part, then any number of BSS
506 * descriptor sections. Finally we have section with the same number
509 * cmd_ds_802_11_scan_rsp
522 * MrvlIEtypes_TsfFimestamp_t
528 pos = scanresp->bssdesc_and_tlvbuffer;
530 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
531 scanresp->bssdescriptsize);
533 tsfdesc = pos + bsssize;
534 tsfsize = 4 + 8 * scanresp->nr_sets;
535 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
537 /* Validity check: we expect a Marvell-Local TLV */
538 i = get_unaligned_le16(tsfdesc);
540 if (i != TLV_TYPE_TSFTIMESTAMP) {
541 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
546 * Validity check: the TLV holds TSF values with 8 bytes each, so
547 * the size in the TLV must match the nr_sets value
549 i = get_unaligned_le16(tsfdesc);
551 if (i / 8 != scanresp->nr_sets) {
552 lbs_deb_scan("scan response: invalid number of TSF timestamp "
553 "sets (expected %d got %d)\n", scanresp->nr_sets,
558 for (i = 0; i < scanresp->nr_sets; i++) {
567 const u8 *ssid = NULL;
569 DECLARE_SSID_BUF(ssid_buf);
571 int len = get_unaligned_le16(pos);
579 /* Packet time stamp */
581 /* Beacon interval */
582 intvl = get_unaligned_le16(pos);
585 capa = get_unaligned_le16(pos);
588 /* To find out the channel, we must parse the IEs */
591 * 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
592 * interval, capabilities
594 ielen = left = len - (6 + 1 + 8 + 2 + 2);
600 if (elen > left || elen == 0) {
601 lbs_deb_scan("scan response: invalid IE fmt\n");
605 if (id == WLAN_EID_DS_PARAMS)
607 if (id == WLAN_EID_SSID) {
615 /* No channel, no luck */
617 struct wiphy *wiphy = priv->wdev->wiphy;
618 int freq = ieee80211_channel_to_frequency(chan_no,
619 IEEE80211_BAND_2GHZ);
620 struct ieee80211_channel *channel =
621 ieee80211_get_channel(wiphy, freq);
623 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
625 bssid, capa, chan_no,
626 print_ssid(ssid_buf, ssid, ssid_len),
627 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
630 !(channel->flags & IEEE80211_CHAN_DISABLED))
631 cfg80211_inform_bss(wiphy, channel,
632 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
633 capa, intvl, ie, ielen,
634 LBS_SCAN_RSSI_TO_MBM(rssi),
637 lbs_deb_scan("scan response: missing BSS channel IE\n");
644 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
650 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
651 * TLV and a rates TLV. Determine the maximum size of them:
653 #define LBS_SCAN_MAX_CMD_SIZE \
654 (sizeof(struct cmd_ds_802_11_scan) \
655 + LBS_MAX_SSID_TLV_SIZE \
656 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
657 + LBS_MAX_RATES_TLV_SIZE)
660 * Assumes priv->scan_req is initialized and valid
661 * Assumes priv->scan_channel is initialized
663 static void lbs_scan_worker(struct work_struct *work)
665 struct lbs_private *priv =
666 container_of(work, struct lbs_private, scan_work.work);
667 struct cmd_ds_802_11_scan *scan_cmd;
668 u8 *tlv; /* pointer into our current, growing TLV storage area */
670 int running, carrier;
672 lbs_deb_enter(LBS_DEB_SCAN);
674 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
675 if (scan_cmd == NULL)
676 goto out_no_scan_cmd;
678 /* prepare fixed part of scan command */
679 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
681 /* stop network while we're away from our main channel */
682 running = !netif_queue_stopped(priv->dev);
683 carrier = netif_carrier_ok(priv->dev);
685 netif_stop_queue(priv->dev);
687 netif_carrier_off(priv->dev);
689 /* prepare fixed part of scan command */
690 tlv = scan_cmd->tlvbuffer;
693 if (priv->scan_req->n_ssids)
694 tlv += lbs_add_ssid_tlv(tlv,
695 priv->scan_req->ssids[0].ssid,
696 priv->scan_req->ssids[0].ssid_len);
698 /* add channel TLVs */
699 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
700 if (last_channel > priv->scan_req->n_channels)
701 last_channel = priv->scan_req->n_channels;
702 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
703 priv->scan_req->n_ssids);
706 tlv += lbs_add_supported_rates_tlv(tlv);
708 if (priv->scan_channel < priv->scan_req->n_channels) {
709 cancel_delayed_work(&priv->scan_work);
711 queue_delayed_work(priv->work_thread, &priv->scan_work,
712 msecs_to_jiffies(300));
715 /* This is the final data we are about to send */
716 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
717 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
719 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
720 tlv - scan_cmd->tlvbuffer);
722 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
723 le16_to_cpu(scan_cmd->hdr.size),
726 if (priv->scan_channel >= priv->scan_req->n_channels) {
728 if (priv->internal_scan)
729 kfree(priv->scan_req);
731 cfg80211_scan_done(priv->scan_req, false);
733 priv->scan_req = NULL;
734 priv->last_scan = jiffies;
737 /* Restart network */
739 netif_carrier_on(priv->dev);
740 if (running && !priv->tx_pending_len)
741 netif_wake_queue(priv->dev);
745 /* Wake up anything waiting on scan completion */
746 if (priv->scan_req == NULL) {
747 lbs_deb_scan("scan: waking up waiters\n");
748 wake_up_all(&priv->scan_q);
752 lbs_deb_leave(LBS_DEB_SCAN);
755 static void _internal_start_scan(struct lbs_private *priv, bool internal,
756 struct cfg80211_scan_request *request)
758 lbs_deb_enter(LBS_DEB_CFG80211);
760 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
761 request->n_ssids, request->n_channels, request->ie_len);
763 priv->scan_channel = 0;
764 queue_delayed_work(priv->work_thread, &priv->scan_work,
765 msecs_to_jiffies(50));
767 priv->scan_req = request;
768 priv->internal_scan = internal;
770 lbs_deb_leave(LBS_DEB_CFG80211);
773 static int lbs_cfg_scan(struct wiphy *wiphy,
774 struct net_device *dev,
775 struct cfg80211_scan_request *request)
777 struct lbs_private *priv = wiphy_priv(wiphy);
780 lbs_deb_enter(LBS_DEB_CFG80211);
782 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
783 /* old scan request not yet processed */
788 _internal_start_scan(priv, false, request);
790 if (priv->surpriseremoved)
794 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
805 void lbs_send_disconnect_notification(struct lbs_private *priv)
807 lbs_deb_enter(LBS_DEB_CFG80211);
809 cfg80211_disconnected(priv->dev,
814 lbs_deb_leave(LBS_DEB_CFG80211);
817 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
819 lbs_deb_enter(LBS_DEB_CFG80211);
821 cfg80211_michael_mic_failure(priv->dev,
823 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
824 NL80211_KEYTYPE_GROUP :
825 NL80211_KEYTYPE_PAIRWISE,
830 lbs_deb_leave(LBS_DEB_CFG80211);
842 * This removes all WEP keys
844 static int lbs_remove_wep_keys(struct lbs_private *priv)
846 struct cmd_ds_802_11_set_wep cmd;
849 lbs_deb_enter(LBS_DEB_CFG80211);
851 memset(&cmd, 0, sizeof(cmd));
852 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
853 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
854 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
856 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
858 lbs_deb_leave(LBS_DEB_CFG80211);
865 static int lbs_set_wep_keys(struct lbs_private *priv)
867 struct cmd_ds_802_11_set_wep cmd;
871 lbs_deb_enter(LBS_DEB_CFG80211);
878 * action 02 00 ACT_ADD
880 * type for key 1 01 WEP40
884 * key 1 39 39 39 39 39 00 00 00
885 * 00 00 00 00 00 00 00 00
886 * key 2 00 00 00 00 00 00 00 00
887 * 00 00 00 00 00 00 00 00
888 * key 3 00 00 00 00 00 00 00 00
889 * 00 00 00 00 00 00 00 00
890 * key 4 00 00 00 00 00 00 00 00
892 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
893 priv->wep_key_len[2] || priv->wep_key_len[3]) {
894 /* Only set wep keys if we have at least one of them */
895 memset(&cmd, 0, sizeof(cmd));
896 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
897 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
898 cmd.action = cpu_to_le16(CMD_ACT_ADD);
900 for (i = 0; i < 4; i++) {
901 switch (priv->wep_key_len[i]) {
902 case WLAN_KEY_LEN_WEP40:
903 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
905 case WLAN_KEY_LEN_WEP104:
906 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
912 memcpy(cmd.keymaterial[i], priv->wep_key[i],
913 priv->wep_key_len[i]);
916 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
918 /* Otherwise remove all wep keys */
919 ret = lbs_remove_wep_keys(priv);
922 lbs_deb_leave(LBS_DEB_CFG80211);
928 * Enable/Disable RSN status
930 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
932 struct cmd_ds_802_11_enable_rsn cmd;
935 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
942 * action 01 00 ACT_SET
945 memset(&cmd, 0, sizeof(cmd));
946 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
947 cmd.action = cpu_to_le16(CMD_ACT_SET);
948 cmd.enable = cpu_to_le16(enable);
950 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
952 lbs_deb_leave(LBS_DEB_CFG80211);
958 * Set WPA/WPA key material
962 * like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
963 * get rid of WEXT, this should go into host.h
966 struct cmd_key_material {
967 struct cmd_header hdr;
970 struct MrvlIEtype_keyParamSet param;
973 static int lbs_set_key_material(struct lbs_private *priv,
976 u8 *key, u16 key_len)
978 struct cmd_key_material cmd;
981 lbs_deb_enter(LBS_DEB_CFG80211);
984 * Example for WPA (TKIP):
991 * TLV type 00 01 key param
993 * key type 01 00 TKIP
994 * key info 06 00 UNICAST | ENABLED
998 memset(&cmd, 0, sizeof(cmd));
999 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1000 cmd.action = cpu_to_le16(CMD_ACT_SET);
1001 cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
1002 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
1003 cmd.param.keytypeid = cpu_to_le16(key_type);
1004 cmd.param.keyinfo = cpu_to_le16(key_info);
1005 cmd.param.keylen = cpu_to_le16(key_len);
1007 memcpy(cmd.param.key, key, key_len);
1009 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
1011 lbs_deb_leave(LBS_DEB_CFG80211);
1017 * Sets the auth type (open, shared, etc) in the firmware. That
1018 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
1019 * command doesn't send an authentication frame at all, it just
1020 * stores the auth_type.
1022 static int lbs_set_authtype(struct lbs_private *priv,
1023 struct cfg80211_connect_params *sme)
1025 struct cmd_ds_802_11_authenticate cmd;
1028 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
1035 * BSS id 00 13 19 80 da 30
1037 * reserved 00 00 00 00 00 00 00 00 00 00
1039 memset(&cmd, 0, sizeof(cmd));
1040 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1042 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
1043 /* convert auth_type */
1044 ret = lbs_auth_to_authtype(sme->auth_type);
1049 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
1052 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1058 * Create association request
1060 #define LBS_ASSOC_MAX_CMD_SIZE \
1061 (sizeof(struct cmd_ds_802_11_associate) \
1062 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1063 + LBS_MAX_SSID_TLV_SIZE \
1064 + LBS_MAX_CHANNEL_TLV_SIZE \
1065 + LBS_MAX_CF_PARAM_TLV_SIZE \
1066 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1067 + LBS_MAX_WPA_TLV_SIZE)
1069 static int lbs_associate(struct lbs_private *priv,
1070 struct cfg80211_bss *bss,
1071 struct cfg80211_connect_params *sme)
1073 struct cmd_ds_802_11_associate_response *resp;
1074 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
1077 size_t len, resp_ie_len;
1080 u8 *pos = &(cmd->iebuf[0]);
1083 lbs_deb_enter(LBS_DEB_CFG80211);
1095 * BSS id 00 13 19 80 da 30
1096 * capabilities 11 00
1097 * listen interval 0a 00
1098 * beacon interval 00 00
1100 * TLVs xx (up to 512 bytes)
1102 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1104 /* Fill in static fields */
1105 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1106 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1107 cmd->capability = cpu_to_le16(bss->capability);
1110 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1112 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1114 lbs_deb_assoc("no SSID\n");
1116 /* add DS param TLV */
1118 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1120 lbs_deb_assoc("no channel\n");
1122 /* add (empty) CF param TLV */
1123 pos += lbs_add_cf_param_tlv(pos);
1126 tmp = pos + 4; /* skip Marvell IE header */
1127 pos += lbs_add_common_rates_tlv(pos, bss);
1128 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1130 /* add auth type TLV */
1131 if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
1132 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1134 /* add WPA/WPA2 TLV */
1135 if (sme->ie && sme->ie_len)
1136 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1138 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1139 (u16)(pos - (u8 *) &cmd->iebuf);
1140 cmd->hdr.size = cpu_to_le16(len);
1142 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
1143 le16_to_cpu(cmd->hdr.size));
1145 /* store for later use */
1146 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1148 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1152 /* generate connect message to cfg80211 */
1154 resp = (void *) cmd; /* recast for easier field access */
1155 status = le16_to_cpu(resp->statuscode);
1157 /* Older FW versions map the IEEE 802.11 Status Code in the association
1158 * response to the following values returned in resp->statuscode:
1160 * IEEE Status Code Marvell Status Code
1161 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1162 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1163 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1164 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1165 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1166 * others -> 0x0003 ASSOC_RESULT_REFUSED
1168 * Other response codes:
1169 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1170 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1171 * association response from the AP)
1173 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1178 lbs_deb_assoc("invalid association parameters\n");
1179 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1182 lbs_deb_assoc("timer expired while waiting for AP\n");
1183 status = WLAN_STATUS_AUTH_TIMEOUT;
1186 lbs_deb_assoc("association refused by AP\n");
1187 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1190 lbs_deb_assoc("authentication refused by AP\n");
1191 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1194 lbs_deb_assoc("association failure %d\n", status);
1195 /* v5 OLPC firmware does return the AP status code if
1196 * it's not one of the values above. Let that through.
1202 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1203 "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
1204 le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
1206 resp_ie_len = le16_to_cpu(resp->hdr.size)
1209 cfg80211_connect_result(priv->dev,
1211 sme->ie, sme->ie_len,
1212 resp->iebuf, resp_ie_len,
1217 /* TODO: get rid of priv->connect_status */
1218 priv->connect_status = LBS_CONNECTED;
1219 netif_carrier_on(priv->dev);
1220 if (!priv->tx_pending_len)
1221 netif_tx_wake_all_queues(priv->dev);
1225 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1229 static struct cfg80211_scan_request *
1230 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
1232 struct cfg80211_scan_request *creq = NULL;
1233 int i, n_channels = 0;
1234 enum ieee80211_band band;
1236 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1237 if (wiphy->bands[band])
1238 n_channels += wiphy->bands[band]->n_channels;
1241 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1242 n_channels * sizeof(void *),
1247 /* SSIDs come after channels */
1248 creq->ssids = (void *)&creq->channels[n_channels];
1249 creq->n_channels = n_channels;
1252 /* Scan all available channels */
1254 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1257 if (!wiphy->bands[band])
1260 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
1261 /* ignore disabled channels */
1262 if (wiphy->bands[band]->channels[j].flags &
1263 IEEE80211_CHAN_DISABLED)
1266 creq->channels[i] = &wiphy->bands[band]->channels[j];
1271 /* Set real number of channels specified in creq->channels[] */
1272 creq->n_channels = i;
1274 /* Scan for the SSID we're going to connect to */
1275 memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
1276 creq->ssids[0].ssid_len = sme->ssid_len;
1278 /* No channels found... */
1286 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1287 struct cfg80211_connect_params *sme)
1289 struct lbs_private *priv = wiphy_priv(wiphy);
1290 struct cfg80211_bss *bss = NULL;
1292 u8 preamble = RADIO_PREAMBLE_SHORT;
1294 lbs_deb_enter(LBS_DEB_CFG80211);
1297 /* Run a scan if one isn't in-progress already and if the last
1298 * scan was done more than 2 seconds ago.
1300 if (priv->scan_req == NULL &&
1301 time_after(jiffies, priv->last_scan + (2 * HZ))) {
1302 struct cfg80211_scan_request *creq;
1304 creq = _new_connect_scan_req(wiphy, sme);
1310 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1311 _internal_start_scan(priv, true, creq);
1314 /* Wait for any in-progress scan to complete */
1315 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1316 wait_event_interruptible_timeout(priv->scan_q,
1317 (priv->scan_req == NULL),
1319 lbs_deb_assoc("assoc: scanning competed\n");
1322 /* Find the BSS we want using available scan results */
1323 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1324 sme->ssid, sme->ssid_len,
1325 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1327 wiphy_err(wiphy, "assoc: bss %pM not in scan results\n",
1332 lbs_deb_assoc("trying %pM\n", bss->bssid);
1333 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1334 sme->crypto.cipher_group,
1335 sme->key_idx, sme->key_len);
1337 /* As this is a new connection, clear locally stored WEP keys */
1338 priv->wep_tx_key = 0;
1339 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1340 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1342 /* set/remove WEP keys */
1343 switch (sme->crypto.cipher_group) {
1344 case WLAN_CIPHER_SUITE_WEP40:
1345 case WLAN_CIPHER_SUITE_WEP104:
1346 /* Store provided WEP keys in priv-> */
1347 priv->wep_tx_key = sme->key_idx;
1348 priv->wep_key_len[sme->key_idx] = sme->key_len;
1349 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1350 /* Set WEP keys and WEP mode */
1351 lbs_set_wep_keys(priv);
1352 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1353 lbs_set_mac_control(priv);
1354 /* No RSN mode for WEP */
1355 lbs_enable_rsn(priv, 0);
1357 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1359 * If we don't have no WEP, no WPA and no WPA2,
1360 * we remove all keys like in the WPA/WPA2 setup,
1361 * we just don't set RSN.
1363 * Therefore: fall-through
1365 case WLAN_CIPHER_SUITE_TKIP:
1366 case WLAN_CIPHER_SUITE_CCMP:
1367 /* Remove WEP keys and WEP mode */
1368 lbs_remove_wep_keys(priv);
1369 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1370 lbs_set_mac_control(priv);
1372 /* clear the WPA/WPA2 keys */
1373 lbs_set_key_material(priv,
1374 KEY_TYPE_ID_WEP, /* doesn't matter */
1375 KEY_INFO_WPA_UNICAST,
1377 lbs_set_key_material(priv,
1378 KEY_TYPE_ID_WEP, /* doesn't matter */
1381 /* RSN mode for WPA/WPA2 */
1382 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1385 wiphy_err(wiphy, "unsupported cipher group 0x%x\n",
1386 sme->crypto.cipher_group);
1391 lbs_set_authtype(priv, sme);
1392 lbs_set_radio(priv, preamble, 1);
1394 /* Do the actual association */
1395 ret = lbs_associate(priv, bss, sme);
1399 cfg80211_put_bss(bss);
1400 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1404 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1407 struct lbs_private *priv = wiphy_priv(wiphy);
1408 struct cmd_ds_802_11_deauthenticate cmd;
1410 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1412 /* store for lbs_cfg_ret_disconnect() */
1413 priv->disassoc_reason = reason_code;
1415 memset(&cmd, 0, sizeof(cmd));
1416 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1417 /* Mildly ugly to use a locally store my own BSSID ... */
1418 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1419 cmd.reasoncode = cpu_to_le16(reason_code);
1421 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1424 cfg80211_disconnected(priv->dev,
1425 priv->disassoc_reason,
1428 priv->connect_status = LBS_DISCONNECTED;
1434 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1435 struct net_device *netdev,
1436 u8 key_index, bool unicast,
1439 struct lbs_private *priv = wiphy_priv(wiphy);
1441 lbs_deb_enter(LBS_DEB_CFG80211);
1443 if (key_index != priv->wep_tx_key) {
1444 lbs_deb_assoc("set_default_key: to %d\n", key_index);
1445 priv->wep_tx_key = key_index;
1446 lbs_set_wep_keys(priv);
1453 static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1454 u8 idx, bool pairwise, const u8 *mac_addr,
1455 struct key_params *params)
1457 struct lbs_private *priv = wiphy_priv(wiphy);
1462 lbs_deb_enter(LBS_DEB_CFG80211);
1464 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1465 params->cipher, mac_addr);
1466 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1467 idx, params->key_len);
1468 if (params->key_len)
1469 lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
1470 params->key, params->key_len);
1472 lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
1473 if (params->seq_len)
1474 lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
1475 params->seq, params->seq_len);
1477 switch (params->cipher) {
1478 case WLAN_CIPHER_SUITE_WEP40:
1479 case WLAN_CIPHER_SUITE_WEP104:
1480 /* actually compare if something has changed ... */
1481 if ((priv->wep_key_len[idx] != params->key_len) ||
1482 memcmp(priv->wep_key[idx],
1483 params->key, params->key_len) != 0) {
1484 priv->wep_key_len[idx] = params->key_len;
1485 memcpy(priv->wep_key[idx],
1486 params->key, params->key_len);
1487 lbs_set_wep_keys(priv);
1490 case WLAN_CIPHER_SUITE_TKIP:
1491 case WLAN_CIPHER_SUITE_CCMP:
1492 key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
1493 ? KEY_INFO_WPA_UNICAST
1494 : KEY_INFO_WPA_MCAST);
1495 key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1498 lbs_set_key_material(priv,
1501 params->key, params->key_len);
1504 wiphy_err(wiphy, "unhandled cipher 0x%x\n", params->cipher);
1513 static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1514 u8 key_index, bool pairwise, const u8 *mac_addr)
1517 lbs_deb_enter(LBS_DEB_CFG80211);
1519 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1520 key_index, mac_addr);
1523 struct lbs_private *priv = wiphy_priv(wiphy);
1525 * I think can keep this a NO-OP, because:
1527 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1528 * - neither "iw" nor "wpa_supplicant" won't call this during
1529 * an ongoing connection
1530 * - TODO: but I have to check if this is still true when
1531 * I set the AP to periodic re-keying
1532 * - we've not kzallec() something when we've added a key at
1533 * lbs_cfg_connect() or lbs_cfg_add_key().
1535 * This causes lbs_cfg_del_key() only called at disconnect time,
1536 * where we'd just waste time deleting a key that is not going
1537 * to be used anyway.
1539 if (key_index < 3 && priv->wep_key_len[key_index]) {
1540 priv->wep_key_len[key_index] = 0;
1541 lbs_set_wep_keys(priv);
1553 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1554 u8 *mac, struct station_info *sinfo)
1556 struct lbs_private *priv = wiphy_priv(wiphy);
1561 lbs_deb_enter(LBS_DEB_CFG80211);
1563 sinfo->filled |= STATION_INFO_TX_BYTES |
1564 STATION_INFO_TX_PACKETS |
1565 STATION_INFO_RX_BYTES |
1566 STATION_INFO_RX_PACKETS;
1567 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1568 sinfo->tx_packets = priv->dev->stats.tx_packets;
1569 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1570 sinfo->rx_packets = priv->dev->stats.rx_packets;
1572 /* Get current RSSI */
1573 ret = lbs_get_rssi(priv, &signal, &noise);
1575 sinfo->signal = signal;
1576 sinfo->filled |= STATION_INFO_SIGNAL;
1579 /* Convert priv->cur_rate from hw_value to NL80211 value */
1580 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1581 if (priv->cur_rate == lbs_rates[i].hw_value) {
1582 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1583 sinfo->filled |= STATION_INFO_TX_BITRATE;
1595 * "Site survey", here just current channel and noise level
1598 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1599 int idx, struct survey_info *survey)
1601 struct lbs_private *priv = wiphy_priv(wiphy);
1608 lbs_deb_enter(LBS_DEB_CFG80211);
1610 survey->channel = ieee80211_get_channel(wiphy,
1611 ieee80211_channel_to_frequency(priv->channel,
1612 IEEE80211_BAND_2GHZ));
1614 ret = lbs_get_rssi(priv, &signal, &noise);
1616 survey->filled = SURVEY_INFO_NOISE_DBM;
1617 survey->noise = noise;
1620 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1631 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1632 enum nl80211_iftype type, u32 *flags,
1633 struct vif_params *params)
1635 struct lbs_private *priv = wiphy_priv(wiphy);
1638 lbs_deb_enter(LBS_DEB_CFG80211);
1641 case NL80211_IFTYPE_MONITOR:
1642 ret = lbs_set_monitor_mode(priv, 1);
1644 case NL80211_IFTYPE_STATION:
1645 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1646 ret = lbs_set_monitor_mode(priv, 0);
1648 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1650 case NL80211_IFTYPE_ADHOC:
1651 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1652 ret = lbs_set_monitor_mode(priv, 0);
1654 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1661 priv->wdev->iftype = type;
1663 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1674 * The firmware needs the following bits masked out of the beacon-derived
1675 * capability field when associating/joining to a BSS:
1676 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1678 #define CAPINFO_MASK (~(0xda00))
1681 static void lbs_join_post(struct lbs_private *priv,
1682 struct cfg80211_ibss_params *params,
1683 u8 *bssid, u16 capability)
1685 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1686 2 + 4 + /* basic rates */
1687 2 + 1 + /* DS parameter */
1689 2 + 8]; /* extended rates */
1692 lbs_deb_enter(LBS_DEB_CFG80211);
1695 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1696 * the real IE from the firmware. So we fabricate a fake IE based on
1697 * what the firmware actually sends (sniffed with wireshark).
1700 *fake++ = WLAN_EID_SSID;
1701 *fake++ = params->ssid_len;
1702 memcpy(fake, params->ssid, params->ssid_len);
1703 fake += params->ssid_len;
1704 /* Fake supported basic rates IE */
1705 *fake++ = WLAN_EID_SUPP_RATES;
1711 /* Fake DS channel IE */
1712 *fake++ = WLAN_EID_DS_PARAMS;
1714 *fake++ = params->channel->hw_value;
1715 /* Fake IBSS params IE */
1716 *fake++ = WLAN_EID_IBSS_PARAMS;
1718 *fake++ = 0; /* ATIM=0 */
1720 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1721 * but I don't know how this could be checked */
1722 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1732 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1734 cfg80211_inform_bss(priv->wdev->wiphy,
1739 params->beacon_interval,
1740 fake_ie, fake - fake_ie,
1743 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1744 priv->wdev->ssid_len = params->ssid_len;
1746 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1748 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1749 priv->connect_status = LBS_CONNECTED;
1750 netif_carrier_on(priv->dev);
1751 if (!priv->tx_pending_len)
1752 netif_wake_queue(priv->dev);
1754 lbs_deb_leave(LBS_DEB_CFG80211);
1757 static int lbs_ibss_join_existing(struct lbs_private *priv,
1758 struct cfg80211_ibss_params *params,
1759 struct cfg80211_bss *bss)
1761 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1762 struct cmd_ds_802_11_ad_hoc_join cmd;
1763 u8 preamble = RADIO_PREAMBLE_SHORT;
1766 lbs_deb_enter(LBS_DEB_CFG80211);
1768 /* TODO: set preamble based on scan result */
1769 ret = lbs_set_radio(priv, preamble, 1);
1774 * Example CMD_802_11_AD_HOC_JOIN command:
1776 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1780 * bssid 02 27 27 97 2f 96
1781 * ssid 49 42 53 53 00 00 00 00
1782 * 00 00 00 00 00 00 00 00
1783 * 00 00 00 00 00 00 00 00
1784 * 00 00 00 00 00 00 00 00
1785 * type 02 CMD_BSS_TYPE_IBSS
1786 * beacon period 64 00
1788 * timestamp 00 00 00 00 00 00 00 00
1789 * localtime 00 00 00 00 00 00 00 00
1793 * reserveed 00 00 00 00
1796 * IE IBSS atim 00 00
1797 * reserved 00 00 00 00
1799 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1800 * fail timeout ff 00
1803 memset(&cmd, 0, sizeof(cmd));
1804 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1806 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1807 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1808 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1809 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1810 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1811 cmd.bss.ds.header.len = 1;
1812 cmd.bss.ds.channel = params->channel->hw_value;
1813 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1814 cmd.bss.ibss.header.len = 2;
1815 cmd.bss.ibss.atimwindow = 0;
1816 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1818 /* set rates to the intersection of our rates and the rates in the
1821 lbs_add_rates(cmd.bss.rates);
1824 u8 rates_max = rates_eid[1];
1825 u8 *rates = cmd.bss.rates;
1826 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1827 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1828 for (i = 0; i < rates_max; i++) {
1829 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1830 u8 rate = rates_eid[i+2];
1831 if (rate == 0x02 || rate == 0x04 ||
1832 rate == 0x0b || rate == 0x16)
1840 /* Only v8 and below support setting this */
1841 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1842 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1843 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1845 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1850 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1858 lbs_join_post(priv, params, bss->bssid, bss->capability);
1861 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1867 static int lbs_ibss_start_new(struct lbs_private *priv,
1868 struct cfg80211_ibss_params *params)
1870 struct cmd_ds_802_11_ad_hoc_start cmd;
1871 struct cmd_ds_802_11_ad_hoc_result *resp =
1872 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1873 u8 preamble = RADIO_PREAMBLE_SHORT;
1877 lbs_deb_enter(LBS_DEB_CFG80211);
1879 ret = lbs_set_radio(priv, preamble, 1);
1884 * Example CMD_802_11_AD_HOC_START command:
1886 * command 2b 00 CMD_802_11_AD_HOC_START
1890 * ssid 54 45 53 54 00 00 00 00
1891 * 00 00 00 00 00 00 00 00
1892 * 00 00 00 00 00 00 00 00
1893 * 00 00 00 00 00 00 00 00
1895 * beacon period 64 00
1899 * IE IBSS atim 00 00
1900 * reserved 00 00 00 00
1904 * reserved 00 00 00 00
1907 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1908 * 0c 12 18 24 30 48 60 6c
1911 memset(&cmd, 0, sizeof(cmd));
1912 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1913 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1914 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1915 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1916 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1917 cmd.ibss.header.len = 2;
1918 cmd.ibss.atimwindow = 0;
1919 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1920 cmd.ds.header.len = 1;
1921 cmd.ds.channel = params->channel->hw_value;
1922 /* Only v8 and below support setting probe delay */
1923 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1924 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1925 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1926 capability = WLAN_CAPABILITY_IBSS;
1927 cmd.capability = cpu_to_le16(capability);
1928 lbs_add_rates(cmd.rates);
1931 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1936 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1943 * bssid 02 2b 7b 0f 86 0e
1945 lbs_join_post(priv, params, resp->bssid, capability);
1948 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1953 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1954 struct cfg80211_ibss_params *params)
1956 struct lbs_private *priv = wiphy_priv(wiphy);
1958 struct cfg80211_bss *bss;
1959 DECLARE_SSID_BUF(ssid_buf);
1961 lbs_deb_enter(LBS_DEB_CFG80211);
1963 if (!params->channel) {
1968 ret = lbs_set_channel(priv, params->channel->hw_value);
1972 /* Search if someone is beaconing. This assumes that the
1973 * bss list is populated already */
1974 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1975 params->ssid, params->ssid_len,
1976 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1979 ret = lbs_ibss_join_existing(priv, params, bss);
1980 cfg80211_put_bss(bss);
1982 ret = lbs_ibss_start_new(priv, params);
1986 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1991 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1993 struct lbs_private *priv = wiphy_priv(wiphy);
1994 struct cmd_ds_802_11_ad_hoc_stop cmd;
1997 lbs_deb_enter(LBS_DEB_CFG80211);
1999 memset(&cmd, 0, sizeof(cmd));
2000 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2001 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
2003 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
2004 lbs_mac_event_disconnected(priv);
2006 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2017 static struct cfg80211_ops lbs_cfg80211_ops = {
2018 .set_channel = lbs_cfg_set_channel,
2019 .scan = lbs_cfg_scan,
2020 .connect = lbs_cfg_connect,
2021 .disconnect = lbs_cfg_disconnect,
2022 .add_key = lbs_cfg_add_key,
2023 .del_key = lbs_cfg_del_key,
2024 .set_default_key = lbs_cfg_set_default_key,
2025 .get_station = lbs_cfg_get_station,
2026 .dump_survey = lbs_get_survey,
2027 .change_virtual_intf = lbs_change_intf,
2028 .join_ibss = lbs_join_ibss,
2029 .leave_ibss = lbs_leave_ibss,
2034 * At this time lbs_private *priv doesn't even exist, so we just allocate
2035 * memory and don't initialize the wiphy further. This is postponed until we
2036 * can talk to the firmware and happens at registration time in
2037 * lbs_cfg_wiphy_register().
2039 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
2042 struct wireless_dev *wdev;
2044 lbs_deb_enter(LBS_DEB_CFG80211);
2046 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2048 dev_err(dev, "cannot allocate wireless device\n");
2049 return ERR_PTR(-ENOMEM);
2052 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
2054 dev_err(dev, "cannot allocate wiphy\n");
2059 lbs_deb_leave(LBS_DEB_CFG80211);
2064 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2065 return ERR_PTR(ret);
2069 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
2071 struct region_code_mapping {
2076 /* Section 5.17.2 */
2077 static const struct region_code_mapping regmap[] = {
2078 {"US ", 0x10}, /* US FCC */
2079 {"CA ", 0x20}, /* Canada */
2080 {"EU ", 0x30}, /* ETSI */
2081 {"ES ", 0x31}, /* Spain */
2082 {"FR ", 0x32}, /* France */
2083 {"JP ", 0x40}, /* Japan */
2087 lbs_deb_enter(LBS_DEB_CFG80211);
2089 for (i = 0; i < ARRAY_SIZE(regmap); i++)
2090 if (regmap[i].code == priv->regioncode) {
2091 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
2095 lbs_deb_leave(LBS_DEB_CFG80211);
2100 * This function get's called after lbs_setup_firmware() determined the
2101 * firmware capabities. So we can setup the wiphy according to our
2102 * hardware/firmware.
2104 int lbs_cfg_register(struct lbs_private *priv)
2106 struct wireless_dev *wdev = priv->wdev;
2109 lbs_deb_enter(LBS_DEB_CFG80211);
2111 wdev->wiphy->max_scan_ssids = 1;
2112 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2114 wdev->wiphy->interface_modes =
2115 BIT(NL80211_IFTYPE_STATION) |
2116 BIT(NL80211_IFTYPE_ADHOC);
2117 if (lbs_rtap_supported(priv))
2118 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
2120 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
2123 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2124 * never seen a firmware without WPA
2126 wdev->wiphy->cipher_suites = cipher_suites;
2127 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2128 wdev->wiphy->reg_notifier = lbs_reg_notifier;
2130 ret = wiphy_register(wdev->wiphy);
2132 pr_err("cannot register wiphy device\n");
2134 priv->wiphy_registered = true;
2136 ret = register_netdev(priv->dev);
2138 pr_err("cannot register network device\n");
2140 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2142 lbs_cfg_set_regulatory_hint(priv);
2144 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2148 int lbs_reg_notifier(struct wiphy *wiphy,
2149 struct regulatory_request *request)
2151 struct lbs_private *priv = wiphy_priv(wiphy);
2154 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
2155 "callback for domain %c%c\n", request->alpha2[0],
2156 request->alpha2[1]);
2158 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
2160 lbs_deb_leave(LBS_DEB_CFG80211);
2164 void lbs_scan_deinit(struct lbs_private *priv)
2166 lbs_deb_enter(LBS_DEB_CFG80211);
2167 cancel_delayed_work_sync(&priv->scan_work);
2171 void lbs_cfg_free(struct lbs_private *priv)
2173 struct wireless_dev *wdev = priv->wdev;
2175 lbs_deb_enter(LBS_DEB_CFG80211);
2180 if (priv->wiphy_registered)
2181 wiphy_unregister(wdev->wiphy);
2184 wiphy_free(wdev->wiphy);