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/sched.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;
261 /* Add common rates from a TLV and return the new end of the TLV */
263 add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
265 int hw, ap, ap_max = ie[1];
268 /* Advance past IE header */
271 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
273 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
274 hw_rate = lbs_rates[hw].bitrate / 5;
275 for (ap = 0; ap < ap_max; ap++) {
276 if (hw_rate == (ie[ap] & 0x7f)) {
278 *nrates = *nrates + 1;
286 * Adds a TLV with all rates the hardware *and* BSS supports.
288 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
290 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
291 const u8 *rates_eid, *ext_rates_eid;
294 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
295 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
298 * 01 00 TLV_TYPE_RATES
302 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
303 tlv += sizeof(rate_tlv->header);
305 /* Add basic rates */
307 tlv = add_ie_rates(tlv, rates_eid, &n);
309 /* Add extended rates, if any */
311 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
313 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
314 /* Fallback: add basic 802.11b rates */
322 rate_tlv->header.len = cpu_to_le16(n);
323 return sizeof(rate_tlv->header) + n;
330 * This is only needed for newer firmware (V9 and up).
332 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
333 sizeof(struct mrvl_ie_auth_type)
335 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
337 struct mrvl_ie_auth_type *auth = (void *) tlv;
340 * 1f 01 TLV_TYPE_AUTH_TYPE
344 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
345 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
346 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
347 return sizeof(*auth);
352 * Add channel (phy ds) TLV
354 #define LBS_MAX_CHANNEL_TLV_SIZE \
355 sizeof(struct mrvl_ie_header)
357 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
359 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
362 * 03 00 TLV_TYPE_PHY_DS
366 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
367 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
368 ds->channel = channel;
374 * Add (empty) CF param TLV of the form:
376 #define LBS_MAX_CF_PARAM_TLV_SIZE \
377 sizeof(struct mrvl_ie_header)
379 static int lbs_add_cf_param_tlv(u8 *tlv)
381 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
388 * 00 00 cfpmaxduration
389 * 00 00 cfpdurationremaining
391 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
392 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
399 #define LBS_MAX_WPA_TLV_SIZE \
400 (sizeof(struct mrvl_ie_header) \
401 + 128 /* TODO: I guessed the size */)
403 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
408 * We need just convert an IE to an TLV. IEs use u8 for the header,
412 * but TLVs use __le16 instead:
419 tlv_len = *tlv++ = *ie++;
423 /* the TLV is two bytes larger than the IE */
427 /***************************************************************************
431 static int lbs_cfg_set_channel(struct wiphy *wiphy,
432 struct net_device *netdev,
433 struct ieee80211_channel *channel,
434 enum nl80211_channel_type channel_type)
436 struct lbs_private *priv = wiphy_priv(wiphy);
439 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
440 channel->center_freq, channel_type);
442 if (channel_type != NL80211_CHAN_NO_HT)
445 ret = lbs_set_channel(priv, channel->hw_value);
448 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
454 /***************************************************************************
459 * When scanning, the firmware doesn't send a nul packet with the power-safe
460 * bit to the AP. So we cannot stay away from our current channel too long,
461 * otherwise we loose data. So take a "nap" while scanning every other
464 #define LBS_SCAN_BEFORE_NAP 4
468 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
469 * which isn't really an RSSI, as it becomes larger when moving away from
470 * the AP. Anyway, we need to convert that into mBm.
472 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
473 ((-(int)rssi + 3)*100)
475 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
476 struct cmd_header *resp)
478 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
487 lbs_deb_enter(LBS_DEB_CFG80211);
489 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
490 nr_sets = le16_to_cpu(scanresp->nr_sets);
492 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
493 nr_sets, bsssize, le16_to_cpu(resp->size));
501 * The general layout of the scan response is described in chapter
502 * 5.7.1. Basically we have a common part, then any number of BSS
503 * descriptor sections. Finally we have section with the same number
506 * cmd_ds_802_11_scan_rsp
519 * MrvlIEtypes_TsfFimestamp_t
525 pos = scanresp->bssdesc_and_tlvbuffer;
527 tsfdesc = pos + bsssize;
528 tsfsize = 4 + 8 * scanresp->nr_sets;
530 /* Validity check: we expect a Marvell-Local TLV */
531 i = get_unaligned_le16(tsfdesc);
533 if (i != TLV_TYPE_TSFTIMESTAMP)
535 /* Validity check: the TLV holds TSF values with 8 bytes each, so
536 * the size in the TLV must match the nr_sets value */
537 i = get_unaligned_le16(tsfdesc);
539 if (i / 8 != scanresp->nr_sets)
542 for (i = 0; i < scanresp->nr_sets; i++) {
551 const u8 *ssid = NULL;
553 DECLARE_SSID_BUF(ssid_buf);
555 int len = get_unaligned_le16(pos);
563 /* Packet time stamp */
565 /* Beacon interval */
566 intvl = get_unaligned_le16(pos);
569 capa = get_unaligned_le16(pos);
572 /* To find out the channel, we must parse the IEs */
574 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
575 interval, capabilities */
576 ielen = left = len - (6 + 1 + 8 + 2 + 2);
582 if (elen > left || elen == 0)
584 if (id == WLAN_EID_DS_PARAMS)
586 if (id == WLAN_EID_SSID) {
594 /* No channel, no luck */
596 struct wiphy *wiphy = priv->wdev->wiphy;
597 int freq = ieee80211_channel_to_frequency(chan_no);
598 struct ieee80211_channel *channel =
599 ieee80211_get_channel(wiphy, freq);
601 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
603 bssid, capa, chan_no,
604 print_ssid(ssid_buf, ssid, ssid_len),
605 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
608 !(channel->flags & IEEE80211_CHAN_DISABLED))
609 cfg80211_inform_bss(wiphy, channel,
610 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
611 capa, intvl, ie, ielen,
612 LBS_SCAN_RSSI_TO_MBM(rssi),
620 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
626 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
627 * TLV and a rates TLV. Determine the maximum size of them:
629 #define LBS_SCAN_MAX_CMD_SIZE \
630 (sizeof(struct cmd_ds_802_11_scan) \
631 + LBS_MAX_SSID_TLV_SIZE \
632 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
633 + LBS_MAX_RATES_TLV_SIZE)
636 * Assumes priv->scan_req is initialized and valid
637 * Assumes priv->scan_channel is initialized
639 static void lbs_scan_worker(struct work_struct *work)
641 struct lbs_private *priv =
642 container_of(work, struct lbs_private, scan_work.work);
643 struct cmd_ds_802_11_scan *scan_cmd;
644 u8 *tlv; /* pointer into our current, growing TLV storage area */
646 int running, carrier;
648 lbs_deb_enter(LBS_DEB_SCAN);
650 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
651 if (scan_cmd == NULL)
652 goto out_no_scan_cmd;
654 /* prepare fixed part of scan command */
655 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
657 /* stop network while we're away from our main channel */
658 running = !netif_queue_stopped(priv->dev);
659 carrier = netif_carrier_ok(priv->dev);
661 netif_stop_queue(priv->dev);
663 netif_carrier_off(priv->dev);
665 /* prepare fixed part of scan command */
666 tlv = scan_cmd->tlvbuffer;
669 if (priv->scan_req->n_ssids)
670 tlv += lbs_add_ssid_tlv(tlv,
671 priv->scan_req->ssids[0].ssid,
672 priv->scan_req->ssids[0].ssid_len);
674 /* add channel TLVs */
675 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
676 if (last_channel > priv->scan_req->n_channels)
677 last_channel = priv->scan_req->n_channels;
678 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
679 priv->scan_req->n_ssids);
682 tlv += lbs_add_supported_rates_tlv(tlv);
684 if (priv->scan_channel < priv->scan_req->n_channels) {
685 cancel_delayed_work(&priv->scan_work);
686 queue_delayed_work(priv->work_thread, &priv->scan_work,
687 msecs_to_jiffies(300));
690 /* This is the final data we are about to send */
691 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
692 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
694 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
695 tlv - scan_cmd->tlvbuffer);
697 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
698 le16_to_cpu(scan_cmd->hdr.size),
701 if (priv->scan_channel >= priv->scan_req->n_channels) {
703 if (priv->internal_scan)
704 kfree(priv->scan_req);
706 cfg80211_scan_done(priv->scan_req, false);
708 priv->scan_req = NULL;
709 priv->last_scan = jiffies;
712 /* Restart network */
714 netif_carrier_on(priv->dev);
715 if (running && !priv->tx_pending_len)
716 netif_wake_queue(priv->dev);
720 /* Wake up anything waiting on scan completion */
721 if (priv->scan_req == NULL) {
722 lbs_deb_scan("scan: waking up waiters\n");
723 wake_up_all(&priv->scan_q);
727 lbs_deb_leave(LBS_DEB_SCAN);
730 static void _internal_start_scan(struct lbs_private *priv, bool internal,
731 struct cfg80211_scan_request *request)
733 lbs_deb_enter(LBS_DEB_CFG80211);
735 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
736 request->n_ssids, request->n_channels, request->ie_len);
738 priv->scan_channel = 0;
739 queue_delayed_work(priv->work_thread, &priv->scan_work,
740 msecs_to_jiffies(50));
742 priv->scan_req = request;
743 priv->internal_scan = internal;
745 lbs_deb_leave(LBS_DEB_CFG80211);
748 static int lbs_cfg_scan(struct wiphy *wiphy,
749 struct net_device *dev,
750 struct cfg80211_scan_request *request)
752 struct lbs_private *priv = wiphy_priv(wiphy);
755 lbs_deb_enter(LBS_DEB_CFG80211);
757 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
758 /* old scan request not yet processed */
763 _internal_start_scan(priv, false, request);
765 if (priv->surpriseremoved)
769 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
776 /***************************************************************************
780 void lbs_send_disconnect_notification(struct lbs_private *priv)
782 lbs_deb_enter(LBS_DEB_CFG80211);
784 cfg80211_disconnected(priv->dev,
789 lbs_deb_leave(LBS_DEB_CFG80211);
792 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
794 lbs_deb_enter(LBS_DEB_CFG80211);
796 cfg80211_michael_mic_failure(priv->dev,
798 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
799 NL80211_KEYTYPE_GROUP :
800 NL80211_KEYTYPE_PAIRWISE,
805 lbs_deb_leave(LBS_DEB_CFG80211);
811 /***************************************************************************
817 * This removes all WEP keys
819 static int lbs_remove_wep_keys(struct lbs_private *priv)
821 struct cmd_ds_802_11_set_wep cmd;
824 lbs_deb_enter(LBS_DEB_CFG80211);
826 memset(&cmd, 0, sizeof(cmd));
827 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
828 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
829 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
831 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
833 lbs_deb_leave(LBS_DEB_CFG80211);
840 static int lbs_set_wep_keys(struct lbs_private *priv)
842 struct cmd_ds_802_11_set_wep cmd;
846 lbs_deb_enter(LBS_DEB_CFG80211);
853 * action 02 00 ACT_ADD
855 * type for key 1 01 WEP40
859 * key 1 39 39 39 39 39 00 00 00
860 * 00 00 00 00 00 00 00 00
861 * key 2 00 00 00 00 00 00 00 00
862 * 00 00 00 00 00 00 00 00
863 * key 3 00 00 00 00 00 00 00 00
864 * 00 00 00 00 00 00 00 00
865 * key 4 00 00 00 00 00 00 00 00
867 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
868 priv->wep_key_len[2] || priv->wep_key_len[3]) {
869 /* Only set wep keys if we have at least one of them */
870 memset(&cmd, 0, sizeof(cmd));
871 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
872 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
873 cmd.action = cpu_to_le16(CMD_ACT_ADD);
875 for (i = 0; i < 4; i++) {
876 switch (priv->wep_key_len[i]) {
877 case WLAN_KEY_LEN_WEP40:
878 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
880 case WLAN_KEY_LEN_WEP104:
881 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
887 memcpy(cmd.keymaterial[i], priv->wep_key[i],
888 priv->wep_key_len[i]);
891 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
893 /* Otherwise remove all wep keys */
894 ret = lbs_remove_wep_keys(priv);
897 lbs_deb_leave(LBS_DEB_CFG80211);
903 * Enable/Disable RSN status
905 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
907 struct cmd_ds_802_11_enable_rsn cmd;
910 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
917 * action 01 00 ACT_SET
920 memset(&cmd, 0, sizeof(cmd));
921 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
922 cmd.action = cpu_to_le16(CMD_ACT_SET);
923 cmd.enable = cpu_to_le16(enable);
925 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
927 lbs_deb_leave(LBS_DEB_CFG80211);
933 * Set WPA/WPA key material
936 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
937 * get rid of WEXT, this should go into host.h */
939 struct cmd_key_material {
940 struct cmd_header hdr;
943 struct MrvlIEtype_keyParamSet param;
946 static int lbs_set_key_material(struct lbs_private *priv,
949 u8 *key, u16 key_len)
951 struct cmd_key_material cmd;
954 lbs_deb_enter(LBS_DEB_CFG80211);
957 * Example for WPA (TKIP):
964 * TLV type 00 01 key param
966 * key type 01 00 TKIP
967 * key info 06 00 UNICAST | ENABLED
971 memset(&cmd, 0, sizeof(cmd));
972 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
973 cmd.action = cpu_to_le16(CMD_ACT_SET);
974 cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
975 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
976 cmd.param.keytypeid = cpu_to_le16(key_type);
977 cmd.param.keyinfo = cpu_to_le16(key_info);
978 cmd.param.keylen = cpu_to_le16(key_len);
980 memcpy(cmd.param.key, key, key_len);
982 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
984 lbs_deb_leave(LBS_DEB_CFG80211);
990 * Sets the auth type (open, shared, etc) in the firmware. That
991 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
992 * command doesn't send an authentication frame at all, it just
993 * stores the auth_type.
995 static int lbs_set_authtype(struct lbs_private *priv,
996 struct cfg80211_connect_params *sme)
998 struct cmd_ds_802_11_authenticate cmd;
1001 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
1008 * BSS id 00 13 19 80 da 30
1010 * reserved 00 00 00 00 00 00 00 00 00 00
1012 memset(&cmd, 0, sizeof(cmd));
1013 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1015 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
1016 /* convert auth_type */
1017 ret = lbs_auth_to_authtype(sme->auth_type);
1022 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
1025 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1031 * Create association request
1033 #define LBS_ASSOC_MAX_CMD_SIZE \
1034 (sizeof(struct cmd_ds_802_11_associate) \
1035 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1036 + LBS_MAX_SSID_TLV_SIZE \
1037 + LBS_MAX_CHANNEL_TLV_SIZE \
1038 + LBS_MAX_CF_PARAM_TLV_SIZE \
1039 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1040 + LBS_MAX_WPA_TLV_SIZE)
1042 static int lbs_associate(struct lbs_private *priv,
1043 struct cfg80211_bss *bss,
1044 struct cfg80211_connect_params *sme)
1046 struct cmd_ds_802_11_associate_response *resp;
1047 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
1050 size_t len, resp_ie_len;
1053 u8 *pos = &(cmd->iebuf[0]);
1056 lbs_deb_enter(LBS_DEB_CFG80211);
1068 * BSS id 00 13 19 80 da 30
1069 * capabilities 11 00
1070 * listen interval 0a 00
1071 * beacon interval 00 00
1073 * TLVs xx (up to 512 bytes)
1075 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1077 /* Fill in static fields */
1078 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1079 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1080 cmd->capability = cpu_to_le16(bss->capability);
1083 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1085 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1087 lbs_deb_assoc("no SSID\n");
1089 /* add DS param TLV */
1091 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1093 lbs_deb_assoc("no channel\n");
1095 /* add (empty) CF param TLV */
1096 pos += lbs_add_cf_param_tlv(pos);
1099 tmp = pos + 4; /* skip Marvell IE header */
1100 pos += lbs_add_common_rates_tlv(pos, bss);
1101 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1103 /* add auth type TLV */
1104 if (priv->fwrelease >= 0x09000000)
1105 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1107 /* add WPA/WPA2 TLV */
1108 if (sme->ie && sme->ie_len)
1109 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1111 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1112 (u16)(pos - (u8 *) &cmd->iebuf);
1113 cmd->hdr.size = cpu_to_le16(len);
1115 /* store for later use */
1116 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1118 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1123 /* generate connect message to cfg80211 */
1125 resp = (void *) cmd; /* recast for easier field access */
1126 status = le16_to_cpu(resp->statuscode);
1128 /* Convert statis code of old firmware */
1129 if (priv->fwrelease < 0x09000000)
1134 lbs_deb_assoc("invalid association parameters\n");
1135 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1138 lbs_deb_assoc("timer expired while waiting for AP\n");
1139 status = WLAN_STATUS_AUTH_TIMEOUT;
1142 lbs_deb_assoc("association refused by AP\n");
1143 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1146 lbs_deb_assoc("authentication refused by AP\n");
1147 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1150 lbs_deb_assoc("association failure %d\n", status);
1151 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1154 lbs_deb_assoc("status %d, capability 0x%04x\n", status,
1155 le16_to_cpu(resp->capability));
1157 resp_ie_len = le16_to_cpu(resp->hdr.size)
1160 cfg80211_connect_result(priv->dev,
1162 sme->ie, sme->ie_len,
1163 resp->iebuf, resp_ie_len,
1168 /* TODO: get rid of priv->connect_status */
1169 priv->connect_status = LBS_CONNECTED;
1170 netif_carrier_on(priv->dev);
1171 if (!priv->tx_pending_len)
1172 netif_tx_wake_all_queues(priv->dev);
1177 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1181 static struct cfg80211_scan_request *
1182 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
1184 struct cfg80211_scan_request *creq = NULL;
1185 int i, n_channels = 0;
1186 enum ieee80211_band band;
1188 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1189 if (wiphy->bands[band])
1190 n_channels += wiphy->bands[band]->n_channels;
1193 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1194 n_channels * sizeof(void *),
1199 /* SSIDs come after channels */
1200 creq->ssids = (void *)&creq->channels[n_channels];
1201 creq->n_channels = n_channels;
1204 /* Scan all available channels */
1206 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1209 if (!wiphy->bands[band])
1212 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
1213 /* ignore disabled channels */
1214 if (wiphy->bands[band]->channels[j].flags &
1215 IEEE80211_CHAN_DISABLED)
1218 creq->channels[i] = &wiphy->bands[band]->channels[j];
1223 /* Set real number of channels specified in creq->channels[] */
1224 creq->n_channels = i;
1226 /* Scan for the SSID we're going to connect to */
1227 memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
1228 creq->ssids[0].ssid_len = sme->ssid_len;
1230 /* No channels found... */
1238 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1239 struct cfg80211_connect_params *sme)
1241 struct lbs_private *priv = wiphy_priv(wiphy);
1242 struct cfg80211_bss *bss = NULL;
1244 u8 preamble = RADIO_PREAMBLE_SHORT;
1246 lbs_deb_enter(LBS_DEB_CFG80211);
1249 /* Run a scan if one isn't in-progress already and if the last
1250 * scan was done more than 2 seconds ago.
1252 if (priv->scan_req == NULL &&
1253 time_after(jiffies, priv->last_scan + (2 * HZ))) {
1254 struct cfg80211_scan_request *creq;
1256 creq = _new_connect_scan_req(wiphy, sme);
1262 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1263 _internal_start_scan(priv, true, creq);
1266 /* Wait for any in-progress scan to complete */
1267 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1268 wait_event_interruptible_timeout(priv->scan_q,
1269 (priv->scan_req == NULL),
1271 lbs_deb_assoc("assoc: scanning competed\n");
1274 /* Find the BSS we want using available scan results */
1275 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1276 sme->ssid, sme->ssid_len,
1277 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1279 lbs_pr_err("assoc: bss %pM not in scan results\n",
1284 lbs_deb_assoc("trying %pM\n", bss->bssid);
1285 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1286 sme->crypto.cipher_group,
1287 sme->key_idx, sme->key_len);
1289 /* As this is a new connection, clear locally stored WEP keys */
1290 priv->wep_tx_key = 0;
1291 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1292 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1294 /* set/remove WEP keys */
1295 switch (sme->crypto.cipher_group) {
1296 case WLAN_CIPHER_SUITE_WEP40:
1297 case WLAN_CIPHER_SUITE_WEP104:
1298 /* Store provided WEP keys in priv-> */
1299 priv->wep_tx_key = sme->key_idx;
1300 priv->wep_key_len[sme->key_idx] = sme->key_len;
1301 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1302 /* Set WEP keys and WEP mode */
1303 lbs_set_wep_keys(priv);
1304 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1305 lbs_set_mac_control(priv);
1306 /* No RSN mode for WEP */
1307 lbs_enable_rsn(priv, 0);
1309 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1311 * If we don't have no WEP, no WPA and no WPA2,
1312 * we remove all keys like in the WPA/WPA2 setup,
1313 * we just don't set RSN.
1315 * Therefore: fall-throught
1317 case WLAN_CIPHER_SUITE_TKIP:
1318 case WLAN_CIPHER_SUITE_CCMP:
1319 /* Remove WEP keys and WEP mode */
1320 lbs_remove_wep_keys(priv);
1321 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1322 lbs_set_mac_control(priv);
1324 /* clear the WPA/WPA2 keys */
1325 lbs_set_key_material(priv,
1326 KEY_TYPE_ID_WEP, /* doesn't matter */
1327 KEY_INFO_WPA_UNICAST,
1329 lbs_set_key_material(priv,
1330 KEY_TYPE_ID_WEP, /* doesn't matter */
1333 /* RSN mode for WPA/WPA2 */
1334 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1337 lbs_pr_err("unsupported cipher group 0x%x\n",
1338 sme->crypto.cipher_group);
1343 lbs_set_authtype(priv, sme);
1344 lbs_set_radio(priv, preamble, 1);
1346 /* Do the actual association */
1347 ret = lbs_associate(priv, bss, sme);
1351 cfg80211_put_bss(bss);
1352 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1356 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1359 struct lbs_private *priv = wiphy_priv(wiphy);
1360 struct cmd_ds_802_11_deauthenticate cmd;
1362 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1364 /* store for lbs_cfg_ret_disconnect() */
1365 priv->disassoc_reason = reason_code;
1367 memset(&cmd, 0, sizeof(cmd));
1368 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1369 /* Mildly ugly to use a locally store my own BSSID ... */
1370 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1371 cmd.reasoncode = cpu_to_le16(reason_code);
1373 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1376 cfg80211_disconnected(priv->dev,
1377 priv->disassoc_reason,
1380 priv->connect_status = LBS_DISCONNECTED;
1386 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1387 struct net_device *netdev,
1390 struct lbs_private *priv = wiphy_priv(wiphy);
1392 lbs_deb_enter(LBS_DEB_CFG80211);
1394 if (key_index != priv->wep_tx_key) {
1395 lbs_deb_assoc("set_default_key: to %d\n", key_index);
1396 priv->wep_tx_key = key_index;
1397 lbs_set_wep_keys(priv);
1404 static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1405 u8 idx, const u8 *mac_addr,
1406 struct key_params *params)
1408 struct lbs_private *priv = wiphy_priv(wiphy);
1413 lbs_deb_enter(LBS_DEB_CFG80211);
1415 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1416 params->cipher, mac_addr);
1417 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1418 idx, params->key_len);
1419 if (params->key_len)
1420 lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
1421 params->key, params->key_len);
1423 lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
1424 if (params->seq_len)
1425 lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
1426 params->seq, params->seq_len);
1428 switch (params->cipher) {
1429 case WLAN_CIPHER_SUITE_WEP40:
1430 case WLAN_CIPHER_SUITE_WEP104:
1431 /* actually compare if something has changed ... */
1432 if ((priv->wep_key_len[idx] != params->key_len) ||
1433 memcmp(priv->wep_key[idx],
1434 params->key, params->key_len) != 0) {
1435 priv->wep_key_len[idx] = params->key_len;
1436 memcpy(priv->wep_key[idx],
1437 params->key, params->key_len);
1438 lbs_set_wep_keys(priv);
1441 case WLAN_CIPHER_SUITE_TKIP:
1442 case WLAN_CIPHER_SUITE_CCMP:
1443 key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
1444 ? KEY_INFO_WPA_UNICAST
1445 : KEY_INFO_WPA_MCAST);
1446 key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1449 lbs_set_key_material(priv,
1452 params->key, params->key_len);
1455 lbs_pr_err("unhandled cipher 0x%x\n", params->cipher);
1464 static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1465 u8 key_index, const u8 *mac_addr)
1468 lbs_deb_enter(LBS_DEB_CFG80211);
1470 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1471 key_index, mac_addr);
1474 struct lbs_private *priv = wiphy_priv(wiphy);
1476 * I think can keep this a NO-OP, because:
1478 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1479 * - neither "iw" nor "wpa_supplicant" won't call this during
1480 * an ongoing connection
1481 * - TODO: but I have to check if this is still true when
1482 * I set the AP to periodic re-keying
1483 * - we've not kzallec() something when we've added a key at
1484 * lbs_cfg_connect() or lbs_cfg_add_key().
1486 * This causes lbs_cfg_del_key() only called at disconnect time,
1487 * where we'd just waste time deleting a key that is not going
1488 * to be used anyway.
1490 if (key_index < 3 && priv->wep_key_len[key_index]) {
1491 priv->wep_key_len[key_index] = 0;
1492 lbs_set_wep_keys(priv);
1500 /***************************************************************************
1504 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1505 u8 *mac, struct station_info *sinfo)
1507 struct lbs_private *priv = wiphy_priv(wiphy);
1512 lbs_deb_enter(LBS_DEB_CFG80211);
1514 sinfo->filled |= STATION_INFO_TX_BYTES |
1515 STATION_INFO_TX_PACKETS |
1516 STATION_INFO_RX_BYTES |
1517 STATION_INFO_RX_PACKETS;
1518 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1519 sinfo->tx_packets = priv->dev->stats.tx_packets;
1520 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1521 sinfo->rx_packets = priv->dev->stats.rx_packets;
1523 /* Get current RSSI */
1524 ret = lbs_get_rssi(priv, &signal, &noise);
1526 sinfo->signal = signal;
1527 sinfo->filled |= STATION_INFO_SIGNAL;
1530 /* Convert priv->cur_rate from hw_value to NL80211 value */
1531 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1532 if (priv->cur_rate == lbs_rates[i].hw_value) {
1533 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1534 sinfo->filled |= STATION_INFO_TX_BITRATE;
1545 /***************************************************************************
1546 * "Site survey", here just current channel and noise level
1549 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1550 int idx, struct survey_info *survey)
1552 struct lbs_private *priv = wiphy_priv(wiphy);
1559 lbs_deb_enter(LBS_DEB_CFG80211);
1561 survey->channel = ieee80211_get_channel(wiphy,
1562 ieee80211_channel_to_frequency(priv->channel));
1564 ret = lbs_get_rssi(priv, &signal, &noise);
1566 survey->filled = SURVEY_INFO_NOISE_DBM;
1567 survey->noise = noise;
1570 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1577 /***************************************************************************
1581 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1582 enum nl80211_iftype type, u32 *flags,
1583 struct vif_params *params)
1585 struct lbs_private *priv = wiphy_priv(wiphy);
1588 lbs_deb_enter(LBS_DEB_CFG80211);
1591 case NL80211_IFTYPE_MONITOR:
1592 ret = lbs_set_monitor_mode(priv, 1);
1594 case NL80211_IFTYPE_STATION:
1595 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1596 ret = lbs_set_monitor_mode(priv, 0);
1598 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1600 case NL80211_IFTYPE_ADHOC:
1601 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1602 ret = lbs_set_monitor_mode(priv, 0);
1604 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1611 priv->wdev->iftype = type;
1613 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1619 /***************************************************************************
1623 /* The firmware needs the following bits masked out of the beacon-derived
1624 * capability field when associating/joining to a BSS:
1625 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1627 #define CAPINFO_MASK (~(0xda00))
1630 static void lbs_join_post(struct lbs_private *priv,
1631 struct cfg80211_ibss_params *params,
1632 u8 *bssid, u16 capability)
1634 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1635 2 + 4 + /* basic rates */
1636 2 + 1 + /* DS parameter */
1638 2 + 8]; /* extended rates */
1641 lbs_deb_enter(LBS_DEB_CFG80211);
1644 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1645 * the real IE from the firmware. So we fabricate a fake IE based on
1646 * what the firmware actually sends (sniffed with wireshark).
1649 *fake++ = WLAN_EID_SSID;
1650 *fake++ = params->ssid_len;
1651 memcpy(fake, params->ssid, params->ssid_len);
1652 fake += params->ssid_len;
1653 /* Fake supported basic rates IE */
1654 *fake++ = WLAN_EID_SUPP_RATES;
1660 /* Fake DS channel IE */
1661 *fake++ = WLAN_EID_DS_PARAMS;
1663 *fake++ = params->channel->hw_value;
1664 /* Fake IBSS params IE */
1665 *fake++ = WLAN_EID_IBSS_PARAMS;
1667 *fake++ = 0; /* ATIM=0 */
1669 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1670 * but I don't know how this could be checked */
1671 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1681 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1683 cfg80211_inform_bss(priv->wdev->wiphy,
1688 params->beacon_interval,
1689 fake_ie, fake - fake_ie,
1692 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1693 priv->wdev->ssid_len = params->ssid_len;
1695 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1697 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1698 priv->connect_status = LBS_CONNECTED;
1699 netif_carrier_on(priv->dev);
1700 if (!priv->tx_pending_len)
1701 netif_wake_queue(priv->dev);
1703 lbs_deb_leave(LBS_DEB_CFG80211);
1706 static int lbs_ibss_join_existing(struct lbs_private *priv,
1707 struct cfg80211_ibss_params *params,
1708 struct cfg80211_bss *bss)
1710 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1711 struct cmd_ds_802_11_ad_hoc_join cmd;
1712 u8 preamble = RADIO_PREAMBLE_SHORT;
1715 lbs_deb_enter(LBS_DEB_CFG80211);
1717 /* TODO: set preamble based on scan result */
1718 ret = lbs_set_radio(priv, preamble, 1);
1723 * Example CMD_802_11_AD_HOC_JOIN command:
1725 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1729 * bssid 02 27 27 97 2f 96
1730 * ssid 49 42 53 53 00 00 00 00
1731 * 00 00 00 00 00 00 00 00
1732 * 00 00 00 00 00 00 00 00
1733 * 00 00 00 00 00 00 00 00
1734 * type 02 CMD_BSS_TYPE_IBSS
1735 * beacon period 64 00
1737 * timestamp 00 00 00 00 00 00 00 00
1738 * localtime 00 00 00 00 00 00 00 00
1742 * reserveed 00 00 00 00
1745 * IE IBSS atim 00 00
1746 * reserved 00 00 00 00
1748 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1749 * fail timeout ff 00
1752 memset(&cmd, 0, sizeof(cmd));
1753 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1755 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1756 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1757 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1758 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1759 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1760 cmd.bss.ds.header.len = 1;
1761 cmd.bss.ds.channel = params->channel->hw_value;
1762 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1763 cmd.bss.ibss.header.len = 2;
1764 cmd.bss.ibss.atimwindow = 0;
1765 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1767 /* set rates to the intersection of our rates and the rates in the
1770 lbs_add_rates(cmd.bss.rates);
1773 u8 rates_max = rates_eid[1];
1774 u8 *rates = cmd.bss.rates;
1775 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1776 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1777 for (i = 0; i < rates_max; i++) {
1778 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1779 u8 rate = rates_eid[i+2];
1780 if (rate == 0x02 || rate == 0x04 ||
1781 rate == 0x0b || rate == 0x16)
1789 /* Only v8 and below support setting this */
1790 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1791 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1792 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1794 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1799 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1807 lbs_join_post(priv, params, bss->bssid, bss->capability);
1810 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1816 static int lbs_ibss_start_new(struct lbs_private *priv,
1817 struct cfg80211_ibss_params *params)
1819 struct cmd_ds_802_11_ad_hoc_start cmd;
1820 struct cmd_ds_802_11_ad_hoc_result *resp =
1821 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1822 u8 preamble = RADIO_PREAMBLE_SHORT;
1826 lbs_deb_enter(LBS_DEB_CFG80211);
1828 ret = lbs_set_radio(priv, preamble, 1);
1833 * Example CMD_802_11_AD_HOC_START command:
1835 * command 2b 00 CMD_802_11_AD_HOC_START
1839 * ssid 54 45 53 54 00 00 00 00
1840 * 00 00 00 00 00 00 00 00
1841 * 00 00 00 00 00 00 00 00
1842 * 00 00 00 00 00 00 00 00
1844 * beacon period 64 00
1848 * IE IBSS atim 00 00
1849 * reserved 00 00 00 00
1853 * reserved 00 00 00 00
1856 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1857 * 0c 12 18 24 30 48 60 6c
1860 memset(&cmd, 0, sizeof(cmd));
1861 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1862 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1863 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1864 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1865 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1866 cmd.ibss.header.len = 2;
1867 cmd.ibss.atimwindow = 0;
1868 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1869 cmd.ds.header.len = 1;
1870 cmd.ds.channel = params->channel->hw_value;
1871 /* Only v8 and below support setting probe delay */
1872 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1873 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1874 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1875 capability = WLAN_CAPABILITY_IBSS;
1876 cmd.capability = cpu_to_le16(capability);
1877 lbs_add_rates(cmd.rates);
1880 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1885 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1892 * bssid 02 2b 7b 0f 86 0e
1894 lbs_join_post(priv, params, resp->bssid, capability);
1897 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1902 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1903 struct cfg80211_ibss_params *params)
1905 struct lbs_private *priv = wiphy_priv(wiphy);
1907 struct cfg80211_bss *bss;
1908 DECLARE_SSID_BUF(ssid_buf);
1910 lbs_deb_enter(LBS_DEB_CFG80211);
1912 if (!params->channel) {
1917 ret = lbs_set_channel(priv, params->channel->hw_value);
1921 /* Search if someone is beaconing. This assumes that the
1922 * bss list is populated already */
1923 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1924 params->ssid, params->ssid_len,
1925 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1928 ret = lbs_ibss_join_existing(priv, params, bss);
1929 cfg80211_put_bss(bss);
1931 ret = lbs_ibss_start_new(priv, params);
1935 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1940 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1942 struct lbs_private *priv = wiphy_priv(wiphy);
1943 struct cmd_ds_802_11_ad_hoc_stop cmd;
1946 lbs_deb_enter(LBS_DEB_CFG80211);
1948 memset(&cmd, 0, sizeof(cmd));
1949 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1950 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1952 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1953 lbs_mac_event_disconnected(priv);
1955 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1962 /***************************************************************************
1966 static struct cfg80211_ops lbs_cfg80211_ops = {
1967 .set_channel = lbs_cfg_set_channel,
1968 .scan = lbs_cfg_scan,
1969 .connect = lbs_cfg_connect,
1970 .disconnect = lbs_cfg_disconnect,
1971 .add_key = lbs_cfg_add_key,
1972 .del_key = lbs_cfg_del_key,
1973 .set_default_key = lbs_cfg_set_default_key,
1974 .get_station = lbs_cfg_get_station,
1975 .dump_survey = lbs_get_survey,
1976 .change_virtual_intf = lbs_change_intf,
1977 .join_ibss = lbs_join_ibss,
1978 .leave_ibss = lbs_leave_ibss,
1983 * At this time lbs_private *priv doesn't even exist, so we just allocate
1984 * memory and don't initialize the wiphy further. This is postponed until we
1985 * can talk to the firmware and happens at registration time in
1986 * lbs_cfg_wiphy_register().
1988 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
1991 struct wireless_dev *wdev;
1993 lbs_deb_enter(LBS_DEB_CFG80211);
1995 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1997 dev_err(dev, "cannot allocate wireless device\n");
1998 return ERR_PTR(-ENOMEM);
2001 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
2003 dev_err(dev, "cannot allocate wiphy\n");
2008 lbs_deb_leave(LBS_DEB_CFG80211);
2013 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2014 return ERR_PTR(ret);
2018 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
2020 struct region_code_mapping {
2025 /* Section 5.17.2 */
2026 static struct region_code_mapping regmap[] = {
2027 {"US ", 0x10}, /* US FCC */
2028 {"CA ", 0x20}, /* Canada */
2029 {"EU ", 0x30}, /* ETSI */
2030 {"ES ", 0x31}, /* Spain */
2031 {"FR ", 0x32}, /* France */
2032 {"JP ", 0x40}, /* Japan */
2036 lbs_deb_enter(LBS_DEB_CFG80211);
2038 for (i = 0; i < ARRAY_SIZE(regmap); i++)
2039 if (regmap[i].code == priv->regioncode) {
2040 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
2044 lbs_deb_leave(LBS_DEB_CFG80211);
2049 * This function get's called after lbs_setup_firmware() determined the
2050 * firmware capabities. So we can setup the wiphy according to our
2051 * hardware/firmware.
2053 int lbs_cfg_register(struct lbs_private *priv)
2055 struct wireless_dev *wdev = priv->wdev;
2058 lbs_deb_enter(LBS_DEB_CFG80211);
2060 wdev->wiphy->max_scan_ssids = 1;
2061 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2063 wdev->wiphy->interface_modes =
2064 BIT(NL80211_IFTYPE_STATION) |
2065 BIT(NL80211_IFTYPE_ADHOC);
2066 if (lbs_rtap_supported(priv))
2067 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
2069 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
2072 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2073 * never seen a firmware without WPA
2075 wdev->wiphy->cipher_suites = cipher_suites;
2076 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2077 wdev->wiphy->reg_notifier = lbs_reg_notifier;
2079 ret = wiphy_register(wdev->wiphy);
2081 lbs_pr_err("cannot register wiphy device\n");
2083 priv->wiphy_registered = true;
2085 ret = register_netdev(priv->dev);
2087 lbs_pr_err("cannot register network device\n");
2089 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2091 lbs_cfg_set_regulatory_hint(priv);
2093 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2097 int lbs_reg_notifier(struct wiphy *wiphy,
2098 struct regulatory_request *request)
2100 struct lbs_private *priv = wiphy_priv(wiphy);
2103 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
2104 "callback for domain %c%c\n", request->alpha2[0],
2105 request->alpha2[1]);
2107 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
2109 lbs_deb_leave(LBS_DEB_CFG80211);
2113 void lbs_scan_deinit(struct lbs_private *priv)
2115 lbs_deb_enter(LBS_DEB_CFG80211);
2116 cancel_delayed_work_sync(&priv->scan_work);
2120 void lbs_cfg_free(struct lbs_private *priv)
2122 struct wireless_dev *wdev = priv->wdev;
2124 lbs_deb_enter(LBS_DEB_CFG80211);
2129 if (priv->wiphy_registered)
2130 wiphy_unregister(wdev->wiphy);
2133 wiphy_free(wdev->wiphy);