2 * Implement cfg80211 ("iw") support.
4 * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
5 * Holger Schurig <hs4233@mail.mn-solutions.de>
9 #include <linux/slab.h>
10 #include <linux/ieee80211.h>
11 #include <net/cfg80211.h>
12 #include <asm/unaligned.h>
19 #define CHAN2G(_channel, _freq, _flags) { \
20 .band = IEEE80211_BAND_2GHZ, \
21 .center_freq = (_freq), \
22 .hw_value = (_channel), \
24 .max_antenna_gain = 0, \
28 static struct ieee80211_channel lbs_2ghz_channels[] = {
45 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
47 .hw_value = (_hw_value), \
52 /* Table 6 in section 3.2.1.1 */
53 static struct ieee80211_rate lbs_rates[] = {
54 RATETAB_ENT(10, 0, 0),
55 RATETAB_ENT(20, 1, 0),
56 RATETAB_ENT(55, 2, 0),
57 RATETAB_ENT(110, 3, 0),
58 RATETAB_ENT(60, 9, 0),
59 RATETAB_ENT(90, 6, 0),
60 RATETAB_ENT(120, 7, 0),
61 RATETAB_ENT(180, 8, 0),
62 RATETAB_ENT(240, 9, 0),
63 RATETAB_ENT(360, 10, 0),
64 RATETAB_ENT(480, 11, 0),
65 RATETAB_ENT(540, 12, 0),
68 static struct ieee80211_supported_band lbs_band_2ghz = {
69 .channels = lbs_2ghz_channels,
70 .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
71 .bitrates = lbs_rates,
72 .n_bitrates = ARRAY_SIZE(lbs_rates),
76 static const u32 cipher_suites[] = {
77 WLAN_CIPHER_SUITE_WEP40,
78 WLAN_CIPHER_SUITE_WEP104,
79 WLAN_CIPHER_SUITE_TKIP,
80 WLAN_CIPHER_SUITE_CCMP,
83 /* Time to stay on the channel */
84 #define LBS_DWELL_PASSIVE 100
85 #define LBS_DWELL_ACTIVE 40
88 /***************************************************************************
89 * Misc utility functions
91 * TLVs are Marvell specific. They are very similar to IEs, they have the
92 * same structure: type, length, data*. The only difference: for IEs, the
93 * type and length are u8, but for TLVs they're __le16.
97 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
98 * in the firmware spec
100 static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
105 case NL80211_AUTHTYPE_OPEN_SYSTEM:
106 case NL80211_AUTHTYPE_SHARED_KEY:
109 case NL80211_AUTHTYPE_AUTOMATIC:
110 ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
112 case NL80211_AUTHTYPE_NETWORK_EAP:
116 /* silence compiler */
123 /* Various firmware commands need the list of supported rates, but with
124 the hight-bit set for basic rates */
125 static int lbs_add_rates(u8 *rates)
129 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
130 u8 rate = lbs_rates[i].bitrate / 5;
131 if (rate == 0x02 || rate == 0x04 ||
132 rate == 0x0b || rate == 0x16)
136 return ARRAY_SIZE(lbs_rates);
140 /***************************************************************************
141 * TLV utility functions
143 * TLVs are Marvell specific. They are very similar to IEs, they have the
144 * same structure: type, length, data*. The only difference: for IEs, the
145 * type and length are u8, but for TLVs they're __le16.
152 #define LBS_MAX_SSID_TLV_SIZE \
153 (sizeof(struct mrvl_ie_header) \
154 + IEEE80211_MAX_SSID_LEN)
156 static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
158 struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
163 * ssid 4d 4e 54 45 53 54
165 ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
166 ssid_tlv->header.len = cpu_to_le16(ssid_len);
167 memcpy(ssid_tlv->ssid, ssid, ssid_len);
168 return sizeof(ssid_tlv->header) + ssid_len;
173 * Add channel list TLV (section 8.4.2)
175 * Actual channel data comes from priv->wdev->wiphy->channels.
177 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
178 (sizeof(struct mrvl_ie_header) \
179 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
181 static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
182 int last_channel, int active_scan)
184 int chanscanparamsize = sizeof(struct chanscanparamset) *
185 (last_channel - priv->scan_channel);
187 struct mrvl_ie_header *header = (void *) tlv;
190 * TLV-ID CHANLIST 01 01
192 * channel 00 01 00 00 00 64 00
196 * min scan time 00 00
197 * max scan time 64 00
198 * channel 2 00 02 00 00 00 64 00
202 header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
203 header->len = cpu_to_le16(chanscanparamsize);
204 tlv += sizeof(struct mrvl_ie_header);
206 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
208 memset(tlv, 0, chanscanparamsize);
210 while (priv->scan_channel < last_channel) {
211 struct chanscanparamset *param = (void *) tlv;
213 param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
215 priv->scan_req->channels[priv->scan_channel]->hw_value;
217 param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
219 param->chanscanmode.passivescan = 1;
220 param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
222 tlv += sizeof(struct chanscanparamset);
223 priv->scan_channel++;
225 return sizeof(struct mrvl_ie_header) + chanscanparamsize;
232 * The rates are in lbs_bg_rates[], but for the 802.11b
233 * rates the high bit is set. We add this TLV only because
234 * there's a firmware which otherwise doesn't report all
237 #define LBS_MAX_RATES_TLV_SIZE \
238 (sizeof(struct mrvl_ie_header) \
239 + (ARRAY_SIZE(lbs_rates)))
241 /* Adds a TLV with all rates the hardware supports */
242 static int lbs_add_supported_rates_tlv(u8 *tlv)
245 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
250 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
252 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
253 tlv += sizeof(rate_tlv->header);
254 i = lbs_add_rates(tlv);
256 rate_tlv->header.len = cpu_to_le16(i);
257 return sizeof(rate_tlv->header) + i;
262 * Adds a TLV with all rates the hardware *and* BSS supports.
264 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
266 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
267 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
271 * 01 00 TLV_TYPE_RATES
275 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
276 tlv += sizeof(rate_tlv->header);
279 /* Fallback: add basic 802.11b rates */
287 u8 ap_max = rates_eid[1];
289 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
290 u8 hw_rate = lbs_rates[hw].bitrate / 5;
291 for (ap = 0; ap < ap_max; ap++) {
292 if (hw_rate == (rates_eid[ap+2] & 0x7f)) {
293 *tlv++ = rates_eid[ap+2];
300 rate_tlv->header.len = cpu_to_le16(n);
301 return sizeof(rate_tlv->header) + n;
308 * This is only needed for newer firmware (V9 and up).
310 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
311 sizeof(struct mrvl_ie_auth_type)
313 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
315 struct mrvl_ie_auth_type *auth = (void *) tlv;
318 * 1f 01 TLV_TYPE_AUTH_TYPE
322 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
323 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
324 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
325 return sizeof(*auth);
330 * Add channel (phy ds) TLV
332 #define LBS_MAX_CHANNEL_TLV_SIZE \
333 sizeof(struct mrvl_ie_header)
335 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
337 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
340 * 03 00 TLV_TYPE_PHY_DS
344 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
345 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
346 ds->channel = channel;
352 * Add (empty) CF param TLV of the form:
354 #define LBS_MAX_CF_PARAM_TLV_SIZE \
355 sizeof(struct mrvl_ie_header)
357 static int lbs_add_cf_param_tlv(u8 *tlv)
359 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
366 * 00 00 cfpmaxduration
367 * 00 00 cfpdurationremaining
369 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
370 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
377 #define LBS_MAX_WPA_TLV_SIZE \
378 (sizeof(struct mrvl_ie_header) \
379 + 128 /* TODO: I guessed the size */)
381 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
386 * We need just convert an IE to an TLV. IEs use u8 for the header,
390 * but TLVs use __le16 instead:
397 tlv_len = *tlv++ = *ie++;
401 /* the TLV is two bytes larger than the IE */
405 /***************************************************************************
409 static int lbs_cfg_set_channel(struct wiphy *wiphy,
410 struct net_device *netdev,
411 struct ieee80211_channel *channel,
412 enum nl80211_channel_type channel_type)
414 struct lbs_private *priv = wiphy_priv(wiphy);
417 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
418 channel->center_freq, channel_type);
420 if (channel_type != NL80211_CHAN_NO_HT)
423 ret = lbs_set_channel(priv, channel->hw_value);
426 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
432 /***************************************************************************
437 * When scanning, the firmware doesn't send a nul packet with the power-safe
438 * bit to the AP. So we cannot stay away from our current channel too long,
439 * otherwise we loose data. So take a "nap" while scanning every other
442 #define LBS_SCAN_BEFORE_NAP 4
446 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
447 * which isn't really an RSSI, as it becomes larger when moving away from
448 * the AP. Anyway, we need to convert that into mBm.
450 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
451 ((-(int)rssi + 3)*100)
453 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
454 struct cmd_header *resp)
456 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
465 lbs_deb_enter(LBS_DEB_CFG80211);
467 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
468 nr_sets = le16_to_cpu(resp->size);
471 * The general layout of the scan response is described in chapter
472 * 5.7.1. Basically we have a common part, then any number of BSS
473 * descriptor sections. Finally we have section with the same number
476 * cmd_ds_802_11_scan_rsp
489 * MrvlIEtypes_TsfFimestamp_t
495 pos = scanresp->bssdesc_and_tlvbuffer;
497 tsfdesc = pos + bsssize;
498 tsfsize = 4 + 8 * scanresp->nr_sets;
500 /* Validity check: we expect a Marvell-Local TLV */
501 i = get_unaligned_le16(tsfdesc);
503 if (i != TLV_TYPE_TSFTIMESTAMP)
505 /* Validity check: the TLV holds TSF values with 8 bytes each, so
506 * the size in the TLV must match the nr_sets value */
507 i = get_unaligned_le16(tsfdesc);
509 if (i / 8 != scanresp->nr_sets)
512 for (i = 0; i < scanresp->nr_sets; i++) {
521 const u8 *ssid = NULL;
523 DECLARE_SSID_BUF(ssid_buf);
525 int len = get_unaligned_le16(pos);
533 /* Packet time stamp */
535 /* Beacon interval */
536 intvl = get_unaligned_le16(pos);
539 capa = get_unaligned_le16(pos);
542 /* To find out the channel, we must parse the IEs */
544 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
545 interval, capabilities */
546 ielen = left = len - (6 + 1 + 8 + 2 + 2);
552 if (elen > left || elen == 0)
554 if (id == WLAN_EID_DS_PARAMS)
556 if (id == WLAN_EID_SSID) {
564 /* No channel, no luck */
566 struct wiphy *wiphy = priv->wdev->wiphy;
567 int freq = ieee80211_channel_to_frequency(chan_no);
568 struct ieee80211_channel *channel =
569 ieee80211_get_channel(wiphy, freq);
571 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
573 bssid, capa, chan_no,
574 print_ssid(ssid_buf, ssid, ssid_len),
575 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
578 !(channel->flags & IEEE80211_CHAN_DISABLED))
579 cfg80211_inform_bss(wiphy, channel,
580 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
581 capa, intvl, ie, ielen,
582 LBS_SCAN_RSSI_TO_MBM(rssi),
590 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
596 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
597 * TLV and a rates TLV. Determine the maximum size of them:
599 #define LBS_SCAN_MAX_CMD_SIZE \
600 (sizeof(struct cmd_ds_802_11_scan) \
601 + LBS_MAX_SSID_TLV_SIZE \
602 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
603 + LBS_MAX_RATES_TLV_SIZE)
606 * Assumes priv->scan_req is initialized and valid
607 * Assumes priv->scan_channel is initialized
609 static void lbs_scan_worker(struct work_struct *work)
611 struct lbs_private *priv =
612 container_of(work, struct lbs_private, scan_work.work);
613 struct cmd_ds_802_11_scan *scan_cmd;
614 u8 *tlv; /* pointer into our current, growing TLV storage area */
616 int running, carrier;
618 lbs_deb_enter(LBS_DEB_SCAN);
620 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
621 if (scan_cmd == NULL)
622 goto out_no_scan_cmd;
624 /* prepare fixed part of scan command */
625 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
627 /* stop network while we're away from our main channel */
628 running = !netif_queue_stopped(priv->dev);
629 carrier = netif_carrier_ok(priv->dev);
631 netif_stop_queue(priv->dev);
633 netif_carrier_off(priv->dev);
635 /* prepare fixed part of scan command */
636 tlv = scan_cmd->tlvbuffer;
639 if (priv->scan_req->n_ssids)
640 tlv += lbs_add_ssid_tlv(tlv,
641 priv->scan_req->ssids[0].ssid,
642 priv->scan_req->ssids[0].ssid_len);
644 /* add channel TLVs */
645 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
646 if (last_channel > priv->scan_req->n_channels)
647 last_channel = priv->scan_req->n_channels;
648 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
649 priv->scan_req->n_ssids);
652 tlv += lbs_add_supported_rates_tlv(tlv);
654 if (priv->scan_channel < priv->scan_req->n_channels) {
655 cancel_delayed_work(&priv->scan_work);
656 queue_delayed_work(priv->work_thread, &priv->scan_work,
657 msecs_to_jiffies(300));
660 /* This is the final data we are about to send */
661 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
662 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
664 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
665 tlv - scan_cmd->tlvbuffer);
667 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
668 le16_to_cpu(scan_cmd->hdr.size),
671 if (priv->scan_channel >= priv->scan_req->n_channels) {
673 cfg80211_scan_done(priv->scan_req, false);
674 priv->scan_req = NULL;
677 /* Restart network */
679 netif_carrier_on(priv->dev);
680 if (running && !priv->tx_pending_len)
681 netif_wake_queue(priv->dev);
686 lbs_deb_leave(LBS_DEB_SCAN);
690 static int lbs_cfg_scan(struct wiphy *wiphy,
691 struct net_device *dev,
692 struct cfg80211_scan_request *request)
694 struct lbs_private *priv = wiphy_priv(wiphy);
697 lbs_deb_enter(LBS_DEB_CFG80211);
699 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
700 /* old scan request not yet processed */
705 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
706 request->n_ssids, request->n_channels, request->ie_len);
708 priv->scan_channel = 0;
709 queue_delayed_work(priv->work_thread, &priv->scan_work,
710 msecs_to_jiffies(50));
712 if (priv->surpriseremoved)
715 priv->scan_req = request;
718 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
725 /***************************************************************************
729 void lbs_send_disconnect_notification(struct lbs_private *priv)
731 lbs_deb_enter(LBS_DEB_CFG80211);
733 cfg80211_disconnected(priv->dev,
738 lbs_deb_leave(LBS_DEB_CFG80211);
741 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
743 lbs_deb_enter(LBS_DEB_CFG80211);
745 cfg80211_michael_mic_failure(priv->dev,
747 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
748 NL80211_KEYTYPE_GROUP :
749 NL80211_KEYTYPE_PAIRWISE,
754 lbs_deb_leave(LBS_DEB_CFG80211);
760 /***************************************************************************
766 * This removes all WEP keys
768 static int lbs_remove_wep_keys(struct lbs_private *priv)
770 struct cmd_ds_802_11_set_wep cmd;
773 lbs_deb_enter(LBS_DEB_CFG80211);
775 memset(&cmd, 0, sizeof(cmd));
776 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
777 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
778 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
780 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
782 lbs_deb_leave(LBS_DEB_CFG80211);
789 static int lbs_set_wep_keys(struct lbs_private *priv)
791 struct cmd_ds_802_11_set_wep cmd;
795 lbs_deb_enter(LBS_DEB_CFG80211);
802 * action 02 00 ACT_ADD
804 * type for key 1 01 WEP40
808 * key 1 39 39 39 39 39 00 00 00
809 * 00 00 00 00 00 00 00 00
810 * key 2 00 00 00 00 00 00 00 00
811 * 00 00 00 00 00 00 00 00
812 * key 3 00 00 00 00 00 00 00 00
813 * 00 00 00 00 00 00 00 00
814 * key 4 00 00 00 00 00 00 00 00
816 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
817 priv->wep_key_len[2] || priv->wep_key_len[3]) {
818 /* Only set wep keys if we have at least one of them */
819 memset(&cmd, 0, sizeof(cmd));
820 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
821 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
822 cmd.action = cpu_to_le16(CMD_ACT_ADD);
824 for (i = 0; i < 4; i++) {
825 switch (priv->wep_key_len[i]) {
826 case WLAN_KEY_LEN_WEP40:
827 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
829 case WLAN_KEY_LEN_WEP104:
830 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
836 memcpy(cmd.keymaterial[i], priv->wep_key[i],
837 priv->wep_key_len[i]);
840 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
842 /* Otherwise remove all wep keys */
843 ret = lbs_remove_wep_keys(priv);
846 lbs_deb_leave(LBS_DEB_CFG80211);
852 * Enable/Disable RSN status
854 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
856 struct cmd_ds_802_11_enable_rsn cmd;
859 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
866 * action 01 00 ACT_SET
869 memset(&cmd, 0, sizeof(cmd));
870 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
871 cmd.action = cpu_to_le16(CMD_ACT_SET);
872 cmd.enable = cpu_to_le16(enable);
874 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
876 lbs_deb_leave(LBS_DEB_CFG80211);
882 * Set WPA/WPA key material
885 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
886 * get rid of WEXT, this should go into host.h */
888 struct cmd_key_material {
889 struct cmd_header hdr;
892 struct MrvlIEtype_keyParamSet param;
895 static int lbs_set_key_material(struct lbs_private *priv,
898 u8 *key, u16 key_len)
900 struct cmd_key_material cmd;
903 lbs_deb_enter(LBS_DEB_CFG80211);
906 * Example for WPA (TKIP):
913 * TLV type 00 01 key param
915 * key type 01 00 TKIP
916 * key info 06 00 UNICAST | ENABLED
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.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
924 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
925 cmd.param.keytypeid = cpu_to_le16(key_type);
926 cmd.param.keyinfo = cpu_to_le16(key_info);
927 cmd.param.keylen = cpu_to_le16(key_len);
929 memcpy(cmd.param.key, key, key_len);
931 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
933 lbs_deb_leave(LBS_DEB_CFG80211);
939 * Sets the auth type (open, shared, etc) in the firmware. That
940 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
941 * command doesn't send an authentication frame at all, it just
942 * stores the auth_type.
944 static int lbs_set_authtype(struct lbs_private *priv,
945 struct cfg80211_connect_params *sme)
947 struct cmd_ds_802_11_authenticate cmd;
950 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
957 * BSS id 00 13 19 80 da 30
959 * reserved 00 00 00 00 00 00 00 00 00 00
961 memset(&cmd, 0, sizeof(cmd));
962 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
964 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
965 /* convert auth_type */
966 ret = lbs_auth_to_authtype(sme->auth_type);
971 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
974 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
980 * Create association request
982 #define LBS_ASSOC_MAX_CMD_SIZE \
983 (sizeof(struct cmd_ds_802_11_associate) \
984 - 512 /* cmd_ds_802_11_associate.iebuf */ \
985 + LBS_MAX_SSID_TLV_SIZE \
986 + LBS_MAX_CHANNEL_TLV_SIZE \
987 + LBS_MAX_CF_PARAM_TLV_SIZE \
988 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
989 + LBS_MAX_WPA_TLV_SIZE)
991 static int lbs_associate(struct lbs_private *priv,
992 struct cfg80211_bss *bss,
993 struct cfg80211_connect_params *sme)
995 struct cmd_ds_802_11_associate_response *resp;
996 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
999 size_t len, resp_ie_len;
1002 u8 *pos = &(cmd->iebuf[0]);
1004 lbs_deb_enter(LBS_DEB_CFG80211);
1016 * BSS id 00 13 19 80 da 30
1017 * capabilities 11 00
1018 * listen interval 0a 00
1019 * beacon interval 00 00
1021 * TLVs xx (up to 512 bytes)
1023 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1025 /* Fill in static fields */
1026 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1027 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1028 cmd->capability = cpu_to_le16(bss->capability);
1031 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1033 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1035 lbs_deb_assoc("no SSID\n");
1037 /* add DS param TLV */
1039 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1041 lbs_deb_assoc("no channel\n");
1043 /* add (empty) CF param TLV */
1044 pos += lbs_add_cf_param_tlv(pos);
1047 pos += lbs_add_common_rates_tlv(pos, bss);
1049 /* add auth type TLV */
1050 if (priv->fwrelease >= 0x09000000)
1051 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1053 /* add WPA/WPA2 TLV */
1054 if (sme->ie && sme->ie_len)
1055 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1057 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1058 (u16)(pos - (u8 *) &cmd->iebuf);
1059 cmd->hdr.size = cpu_to_le16(len);
1061 /* store for later use */
1062 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1064 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1069 /* generate connect message to cfg80211 */
1071 resp = (void *) cmd; /* recast for easier field access */
1072 status = le16_to_cpu(resp->statuscode);
1074 /* Convert statis code of old firmware */
1075 if (priv->fwrelease < 0x09000000)
1080 lbs_deb_assoc("invalid association parameters\n");
1081 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1084 lbs_deb_assoc("timer expired while waiting for AP\n");
1085 status = WLAN_STATUS_AUTH_TIMEOUT;
1088 lbs_deb_assoc("association refused by AP\n");
1089 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1092 lbs_deb_assoc("authentication refused by AP\n");
1093 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1096 lbs_deb_assoc("association failure %d\n", status);
1097 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1100 lbs_deb_assoc("status %d, capability 0x%04x\n", status,
1101 le16_to_cpu(resp->capability));
1103 resp_ie_len = le16_to_cpu(resp->hdr.size)
1106 cfg80211_connect_result(priv->dev,
1108 sme->ie, sme->ie_len,
1109 resp->iebuf, resp_ie_len,
1114 /* TODO: get rid of priv->connect_status */
1115 priv->connect_status = LBS_CONNECTED;
1116 netif_carrier_on(priv->dev);
1117 if (!priv->tx_pending_len)
1118 netif_tx_wake_all_queues(priv->dev);
1123 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1129 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1130 struct cfg80211_connect_params *sme)
1132 struct lbs_private *priv = wiphy_priv(wiphy);
1133 struct cfg80211_bss *bss = NULL;
1135 u8 preamble = RADIO_PREAMBLE_SHORT;
1137 lbs_deb_enter(LBS_DEB_CFG80211);
1140 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1141 sme->ssid, sme->ssid_len,
1142 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1145 * Here we have an impedance mismatch. The firmware command
1146 * CMD_802_11_ASSOCIATE always needs a BSSID, it cannot
1147 * connect otherwise. However, for the connect-API of
1148 * cfg80211 the bssid is purely optional. We don't get one,
1149 * except the user specifies one on the "iw" command line.
1151 * If we don't got one, we could initiate a scan and look
1152 * for the best matching cfg80211_bss entry.
1154 * Or, better yet, net/wireless/sme.c get's rewritten into
1155 * something more generally useful.
1157 lbs_pr_err("TODO: no BSS specified\n");
1164 lbs_pr_err("assicate: bss %pM not in scan results\n",
1169 lbs_deb_assoc("trying %pM", sme->bssid);
1170 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1171 sme->crypto.cipher_group,
1172 sme->key_idx, sme->key_len);
1174 /* As this is a new connection, clear locally stored WEP keys */
1175 priv->wep_tx_key = 0;
1176 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1177 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1179 /* set/remove WEP keys */
1180 switch (sme->crypto.cipher_group) {
1181 case WLAN_CIPHER_SUITE_WEP40:
1182 case WLAN_CIPHER_SUITE_WEP104:
1183 /* Store provided WEP keys in priv-> */
1184 priv->wep_tx_key = sme->key_idx;
1185 priv->wep_key_len[sme->key_idx] = sme->key_len;
1186 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1187 /* Set WEP keys and WEP mode */
1188 lbs_set_wep_keys(priv);
1189 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1190 lbs_set_mac_control(priv);
1191 /* No RSN mode for WEP */
1192 lbs_enable_rsn(priv, 0);
1194 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1196 * If we don't have no WEP, no WPA and no WPA2,
1197 * we remove all keys like in the WPA/WPA2 setup,
1198 * we just don't set RSN.
1200 * Therefore: fall-throught
1202 case WLAN_CIPHER_SUITE_TKIP:
1203 case WLAN_CIPHER_SUITE_CCMP:
1204 /* Remove WEP keys and WEP mode */
1205 lbs_remove_wep_keys(priv);
1206 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1207 lbs_set_mac_control(priv);
1209 /* clear the WPA/WPA2 keys */
1210 lbs_set_key_material(priv,
1211 KEY_TYPE_ID_WEP, /* doesn't matter */
1212 KEY_INFO_WPA_UNICAST,
1214 lbs_set_key_material(priv,
1215 KEY_TYPE_ID_WEP, /* doesn't matter */
1218 /* RSN mode for WPA/WPA2 */
1219 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1222 lbs_pr_err("unsupported cipher group 0x%x\n",
1223 sme->crypto.cipher_group);
1228 lbs_set_authtype(priv, sme);
1229 lbs_set_radio(priv, preamble, 1);
1231 /* Do the actual association */
1232 lbs_associate(priv, bss, sme);
1236 cfg80211_put_bss(bss);
1237 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1241 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1244 struct lbs_private *priv = wiphy_priv(wiphy);
1245 struct cmd_ds_802_11_deauthenticate cmd;
1247 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1249 /* store for lbs_cfg_ret_disconnect() */
1250 priv->disassoc_reason = reason_code;
1252 memset(&cmd, 0, sizeof(cmd));
1253 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1254 /* Mildly ugly to use a locally store my own BSSID ... */
1255 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1256 cmd.reasoncode = cpu_to_le16(reason_code);
1258 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1261 cfg80211_disconnected(priv->dev,
1262 priv->disassoc_reason,
1265 priv->connect_status = LBS_DISCONNECTED;
1271 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1272 struct net_device *netdev,
1275 struct lbs_private *priv = wiphy_priv(wiphy);
1277 lbs_deb_enter(LBS_DEB_CFG80211);
1279 if (key_index != priv->wep_tx_key) {
1280 lbs_deb_assoc("set_default_key: to %d\n", key_index);
1281 priv->wep_tx_key = key_index;
1282 lbs_set_wep_keys(priv);
1289 static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1290 u8 idx, const u8 *mac_addr,
1291 struct key_params *params)
1293 struct lbs_private *priv = wiphy_priv(wiphy);
1298 lbs_deb_enter(LBS_DEB_CFG80211);
1300 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1301 params->cipher, mac_addr);
1302 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1303 idx, params->key_len);
1304 if (params->key_len)
1305 lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
1306 params->key, params->key_len);
1308 lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
1309 if (params->seq_len)
1310 lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
1311 params->seq, params->seq_len);
1313 switch (params->cipher) {
1314 case WLAN_CIPHER_SUITE_WEP40:
1315 case WLAN_CIPHER_SUITE_WEP104:
1316 /* actually compare if something has changed ... */
1317 if ((priv->wep_key_len[idx] != params->key_len) ||
1318 memcmp(priv->wep_key[idx],
1319 params->key, params->key_len) != 0) {
1320 priv->wep_key_len[idx] = params->key_len;
1321 memcpy(priv->wep_key[idx],
1322 params->key, params->key_len);
1323 lbs_set_wep_keys(priv);
1326 case WLAN_CIPHER_SUITE_TKIP:
1327 case WLAN_CIPHER_SUITE_CCMP:
1328 key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
1329 ? KEY_INFO_WPA_UNICAST
1330 : KEY_INFO_WPA_MCAST);
1331 key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1334 lbs_set_key_material(priv,
1337 params->key, params->key_len);
1340 lbs_pr_err("unhandled cipher 0x%x\n", params->cipher);
1349 static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1350 u8 key_index, const u8 *mac_addr)
1353 lbs_deb_enter(LBS_DEB_CFG80211);
1355 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1356 key_index, mac_addr);
1359 struct lbs_private *priv = wiphy_priv(wiphy);
1361 * I think can keep this a NO-OP, because:
1363 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1364 * - neither "iw" nor "wpa_supplicant" won't call this during
1365 * an ongoing connection
1366 * - TODO: but I have to check if this is still true when
1367 * I set the AP to periodic re-keying
1368 * - we've not kzallec() something when we've added a key at
1369 * lbs_cfg_connect() or lbs_cfg_add_key().
1371 * This causes lbs_cfg_del_key() only called at disconnect time,
1372 * where we'd just waste time deleting a key that is not going
1373 * to be used anyway.
1375 if (key_index < 3 && priv->wep_key_len[key_index]) {
1376 priv->wep_key_len[key_index] = 0;
1377 lbs_set_wep_keys(priv);
1385 /***************************************************************************
1389 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1390 u8 *mac, struct station_info *sinfo)
1392 struct lbs_private *priv = wiphy_priv(wiphy);
1397 lbs_deb_enter(LBS_DEB_CFG80211);
1399 sinfo->filled |= STATION_INFO_TX_BYTES |
1400 STATION_INFO_TX_PACKETS |
1401 STATION_INFO_RX_BYTES |
1402 STATION_INFO_RX_PACKETS;
1403 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1404 sinfo->tx_packets = priv->dev->stats.tx_packets;
1405 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1406 sinfo->rx_packets = priv->dev->stats.rx_packets;
1408 /* Get current RSSI */
1409 ret = lbs_get_rssi(priv, &signal, &noise);
1411 sinfo->signal = signal;
1412 sinfo->filled |= STATION_INFO_SIGNAL;
1415 /* Convert priv->cur_rate from hw_value to NL80211 value */
1416 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1417 if (priv->cur_rate == lbs_rates[i].hw_value) {
1418 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1419 sinfo->filled |= STATION_INFO_TX_BITRATE;
1430 /***************************************************************************
1431 * "Site survey", here just current channel and noise level
1434 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1435 int idx, struct survey_info *survey)
1437 struct lbs_private *priv = wiphy_priv(wiphy);
1444 lbs_deb_enter(LBS_DEB_CFG80211);
1446 survey->channel = ieee80211_get_channel(wiphy,
1447 ieee80211_channel_to_frequency(priv->channel));
1449 ret = lbs_get_rssi(priv, &signal, &noise);
1451 survey->filled = SURVEY_INFO_NOISE_DBM;
1452 survey->noise = noise;
1455 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1462 /***************************************************************************
1466 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1467 enum nl80211_iftype type, u32 *flags,
1468 struct vif_params *params)
1470 struct lbs_private *priv = wiphy_priv(wiphy);
1473 lbs_deb_enter(LBS_DEB_CFG80211);
1476 case NL80211_IFTYPE_MONITOR:
1477 ret = lbs_set_monitor_mode(priv, 1);
1479 case NL80211_IFTYPE_STATION:
1480 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1481 ret = lbs_set_monitor_mode(priv, 0);
1483 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1485 case NL80211_IFTYPE_ADHOC:
1486 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1487 ret = lbs_set_monitor_mode(priv, 0);
1489 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1496 priv->wdev->iftype = type;
1498 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1504 /***************************************************************************
1508 /* The firmware needs the following bits masked out of the beacon-derived
1509 * capability field when associating/joining to a BSS:
1510 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1512 #define CAPINFO_MASK (~(0xda00))
1515 static void lbs_join_post(struct lbs_private *priv,
1516 struct cfg80211_ibss_params *params,
1517 u8 *bssid, u16 capability)
1519 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1520 2 + 4 + /* basic rates */
1521 2 + 1 + /* DS parameter */
1523 2 + 8]; /* extended rates */
1526 lbs_deb_enter(LBS_DEB_CFG80211);
1529 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1530 * the real IE from the firmware. So we fabricate a fake IE based on
1531 * what the firmware actually sends (sniffed with wireshark).
1534 *fake++ = WLAN_EID_SSID;
1535 *fake++ = params->ssid_len;
1536 memcpy(fake, params->ssid, params->ssid_len);
1537 fake += params->ssid_len;
1538 /* Fake supported basic rates IE */
1539 *fake++ = WLAN_EID_SUPP_RATES;
1545 /* Fake DS channel IE */
1546 *fake++ = WLAN_EID_DS_PARAMS;
1548 *fake++ = params->channel->hw_value;
1549 /* Fake IBSS params IE */
1550 *fake++ = WLAN_EID_IBSS_PARAMS;
1552 *fake++ = 0; /* ATIM=0 */
1554 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1555 * but I don't know how this could be checked */
1556 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1566 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1568 cfg80211_inform_bss(priv->wdev->wiphy,
1573 params->beacon_interval,
1574 fake_ie, fake - fake_ie,
1577 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1578 priv->wdev->ssid_len = params->ssid_len;
1580 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1582 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1583 priv->connect_status = LBS_CONNECTED;
1584 netif_carrier_on(priv->dev);
1585 if (!priv->tx_pending_len)
1586 netif_wake_queue(priv->dev);
1588 lbs_deb_leave(LBS_DEB_CFG80211);
1591 static int lbs_ibss_join_existing(struct lbs_private *priv,
1592 struct cfg80211_ibss_params *params,
1593 struct cfg80211_bss *bss)
1595 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1596 struct cmd_ds_802_11_ad_hoc_join cmd;
1597 u8 preamble = RADIO_PREAMBLE_SHORT;
1600 lbs_deb_enter(LBS_DEB_CFG80211);
1602 /* TODO: set preamble based on scan result */
1603 ret = lbs_set_radio(priv, preamble, 1);
1608 * Example CMD_802_11_AD_HOC_JOIN command:
1610 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1614 * bssid 02 27 27 97 2f 96
1615 * ssid 49 42 53 53 00 00 00 00
1616 * 00 00 00 00 00 00 00 00
1617 * 00 00 00 00 00 00 00 00
1618 * 00 00 00 00 00 00 00 00
1619 * type 02 CMD_BSS_TYPE_IBSS
1620 * beacon period 64 00
1622 * timestamp 00 00 00 00 00 00 00 00
1623 * localtime 00 00 00 00 00 00 00 00
1627 * reserveed 00 00 00 00
1630 * IE IBSS atim 00 00
1631 * reserved 00 00 00 00
1633 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1634 * fail timeout ff 00
1637 memset(&cmd, 0, sizeof(cmd));
1638 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1640 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1641 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1642 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1643 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1644 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1645 cmd.bss.ds.header.len = 1;
1646 cmd.bss.ds.channel = params->channel->hw_value;
1647 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1648 cmd.bss.ibss.header.len = 2;
1649 cmd.bss.ibss.atimwindow = 0;
1650 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1652 /* set rates to the intersection of our rates and the rates in the
1655 lbs_add_rates(cmd.bss.rates);
1658 u8 rates_max = rates_eid[1];
1659 u8 *rates = cmd.bss.rates;
1660 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1661 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1662 for (i = 0; i < rates_max; i++) {
1663 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1664 u8 rate = rates_eid[i+2];
1665 if (rate == 0x02 || rate == 0x04 ||
1666 rate == 0x0b || rate == 0x16)
1674 /* Only v8 and below support setting this */
1675 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1676 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1677 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1679 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1684 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1692 lbs_join_post(priv, params, bss->bssid, bss->capability);
1695 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1701 static int lbs_ibss_start_new(struct lbs_private *priv,
1702 struct cfg80211_ibss_params *params)
1704 struct cmd_ds_802_11_ad_hoc_start cmd;
1705 struct cmd_ds_802_11_ad_hoc_result *resp =
1706 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1707 u8 preamble = RADIO_PREAMBLE_SHORT;
1711 lbs_deb_enter(LBS_DEB_CFG80211);
1713 ret = lbs_set_radio(priv, preamble, 1);
1718 * Example CMD_802_11_AD_HOC_START command:
1720 * command 2b 00 CMD_802_11_AD_HOC_START
1724 * ssid 54 45 53 54 00 00 00 00
1725 * 00 00 00 00 00 00 00 00
1726 * 00 00 00 00 00 00 00 00
1727 * 00 00 00 00 00 00 00 00
1729 * beacon period 64 00
1733 * IE IBSS atim 00 00
1734 * reserved 00 00 00 00
1738 * reserved 00 00 00 00
1741 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1742 * 0c 12 18 24 30 48 60 6c
1745 memset(&cmd, 0, sizeof(cmd));
1746 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1747 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1748 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1749 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1750 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1751 cmd.ibss.header.len = 2;
1752 cmd.ibss.atimwindow = 0;
1753 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1754 cmd.ds.header.len = 1;
1755 cmd.ds.channel = params->channel->hw_value;
1756 /* Only v8 and below support setting probe delay */
1757 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1758 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1759 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1760 capability = WLAN_CAPABILITY_IBSS;
1761 cmd.capability = cpu_to_le16(capability);
1762 lbs_add_rates(cmd.rates);
1765 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1770 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1777 * bssid 02 2b 7b 0f 86 0e
1779 lbs_join_post(priv, params, resp->bssid, capability);
1782 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1787 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1788 struct cfg80211_ibss_params *params)
1790 struct lbs_private *priv = wiphy_priv(wiphy);
1792 struct cfg80211_bss *bss;
1793 DECLARE_SSID_BUF(ssid_buf);
1795 lbs_deb_enter(LBS_DEB_CFG80211);
1797 if (!params->channel) {
1802 ret = lbs_set_channel(priv, params->channel->hw_value);
1806 /* Search if someone is beaconing. This assumes that the
1807 * bss list is populated already */
1808 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1809 params->ssid, params->ssid_len,
1810 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1813 ret = lbs_ibss_join_existing(priv, params, bss);
1814 cfg80211_put_bss(bss);
1816 ret = lbs_ibss_start_new(priv, params);
1820 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1825 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1827 struct lbs_private *priv = wiphy_priv(wiphy);
1828 struct cmd_ds_802_11_ad_hoc_stop cmd;
1831 lbs_deb_enter(LBS_DEB_CFG80211);
1833 memset(&cmd, 0, sizeof(cmd));
1834 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1835 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1837 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1838 lbs_mac_event_disconnected(priv);
1840 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1847 /***************************************************************************
1851 static struct cfg80211_ops lbs_cfg80211_ops = {
1852 .set_channel = lbs_cfg_set_channel,
1853 .scan = lbs_cfg_scan,
1854 .connect = lbs_cfg_connect,
1855 .disconnect = lbs_cfg_disconnect,
1856 .add_key = lbs_cfg_add_key,
1857 .del_key = lbs_cfg_del_key,
1858 .set_default_key = lbs_cfg_set_default_key,
1859 .get_station = lbs_cfg_get_station,
1860 .dump_survey = lbs_get_survey,
1861 .change_virtual_intf = lbs_change_intf,
1862 .join_ibss = lbs_join_ibss,
1863 .leave_ibss = lbs_leave_ibss,
1868 * At this time lbs_private *priv doesn't even exist, so we just allocate
1869 * memory and don't initialize the wiphy further. This is postponed until we
1870 * can talk to the firmware and happens at registration time in
1871 * lbs_cfg_wiphy_register().
1873 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
1876 struct wireless_dev *wdev;
1878 lbs_deb_enter(LBS_DEB_CFG80211);
1880 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1882 dev_err(dev, "cannot allocate wireless device\n");
1883 return ERR_PTR(-ENOMEM);
1886 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
1888 dev_err(dev, "cannot allocate wiphy\n");
1893 lbs_deb_leave(LBS_DEB_CFG80211);
1898 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1899 return ERR_PTR(ret);
1903 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
1905 struct region_code_mapping {
1910 /* Section 5.17.2 */
1911 static struct region_code_mapping regmap[] = {
1912 {"US ", 0x10}, /* US FCC */
1913 {"CA ", 0x20}, /* Canada */
1914 {"EU ", 0x30}, /* ETSI */
1915 {"ES ", 0x31}, /* Spain */
1916 {"FR ", 0x32}, /* France */
1917 {"JP ", 0x40}, /* Japan */
1921 lbs_deb_enter(LBS_DEB_CFG80211);
1923 for (i = 0; i < ARRAY_SIZE(regmap); i++)
1924 if (regmap[i].code == priv->regioncode) {
1925 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
1929 lbs_deb_leave(LBS_DEB_CFG80211);
1934 * This function get's called after lbs_setup_firmware() determined the
1935 * firmware capabities. So we can setup the wiphy according to our
1936 * hardware/firmware.
1938 int lbs_cfg_register(struct lbs_private *priv)
1940 struct wireless_dev *wdev = priv->wdev;
1943 lbs_deb_enter(LBS_DEB_CFG80211);
1945 wdev->wiphy->max_scan_ssids = 1;
1946 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1948 wdev->wiphy->interface_modes =
1949 BIT(NL80211_IFTYPE_STATION) |
1950 BIT(NL80211_IFTYPE_ADHOC);
1951 if (lbs_rtap_supported(priv))
1952 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
1954 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
1957 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
1958 * never seen a firmware without WPA
1960 wdev->wiphy->cipher_suites = cipher_suites;
1961 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1962 wdev->wiphy->reg_notifier = lbs_reg_notifier;
1964 ret = wiphy_register(wdev->wiphy);
1966 lbs_pr_err("cannot register wiphy device\n");
1968 priv->wiphy_registered = true;
1970 ret = register_netdev(priv->dev);
1972 lbs_pr_err("cannot register network device\n");
1974 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
1976 lbs_cfg_set_regulatory_hint(priv);
1978 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1982 int lbs_reg_notifier(struct wiphy *wiphy,
1983 struct regulatory_request *request)
1985 struct lbs_private *priv = wiphy_priv(wiphy);
1988 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
1989 "callback for domain %c%c\n", request->alpha2[0],
1990 request->alpha2[1]);
1992 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
1994 lbs_deb_leave(LBS_DEB_CFG80211);
1998 void lbs_scan_deinit(struct lbs_private *priv)
2000 lbs_deb_enter(LBS_DEB_CFG80211);
2001 cancel_delayed_work_sync(&priv->scan_work);
2005 void lbs_cfg_free(struct lbs_private *priv)
2007 struct wireless_dev *wdev = priv->wdev;
2009 lbs_deb_enter(LBS_DEB_CFG80211);
2014 if (priv->wiphy_registered)
2015 wiphy_unregister(wdev->wiphy);
2018 wiphy_free(wdev->wiphy);