2 * Implement cfg80211 ("iw") support.
4 * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
5 * Holger Schurig <hs4233@mail.mn-solutions.de>
9 #include <linux/slab.h>
10 #include <linux/if_arp.h>
11 #include <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;
893 } __attribute__ ((packed));
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);
1386 /***************************************************************************
1390 /* like "struct cmd_ds_802_11_monitor_mode", but with cmd_header. Once we
1391 * get rid of WEXT, this should go into host.h */
1392 struct cmd_monitor_mode {
1393 struct cmd_header hdr;
1397 } __attribute__ ((packed));
1399 static int lbs_enable_monitor_mode(struct lbs_private *priv, int mode)
1401 struct cmd_monitor_mode cmd;
1404 lbs_deb_enter(LBS_DEB_CFG80211);
1411 * action 01 00 ACT_SET
1414 memset(&cmd, 0, sizeof(cmd));
1415 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1416 cmd.action = cpu_to_le16(CMD_ACT_SET);
1417 cmd.mode = cpu_to_le16(mode);
1419 ret = lbs_cmd_with_response(priv, CMD_802_11_MONITOR_MODE, &cmd);
1422 priv->dev->type = ARPHRD_IEEE80211_RADIOTAP;
1424 priv->dev->type = ARPHRD_ETHER;
1426 lbs_deb_leave(LBS_DEB_CFG80211);
1435 /***************************************************************************
1440 * Returns the signal or 0 in case of an error.
1443 /* like "struct cmd_ds_802_11_rssi", but with cmd_header. Once we get rid
1444 * of WEXT, this should go into host.h */
1446 struct cmd_header hdr;
1452 } __attribute__ ((packed));
1454 static int lbs_get_signal(struct lbs_private *priv, s8 *signal, s8 *noise)
1456 struct cmd_rssi cmd;
1459 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1460 cmd.n_or_snr = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
1461 ret = lbs_cmd_with_response(priv, CMD_802_11_RSSI, &cmd);
1464 *signal = CAL_RSSI(le16_to_cpu(cmd.n_or_snr),
1465 le16_to_cpu(cmd.nf));
1466 *noise = CAL_NF(le16_to_cpu(cmd.nf));
1472 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1473 u8 *mac, struct station_info *sinfo)
1475 struct lbs_private *priv = wiphy_priv(wiphy);
1480 lbs_deb_enter(LBS_DEB_CFG80211);
1482 sinfo->filled |= STATION_INFO_TX_BYTES |
1483 STATION_INFO_TX_PACKETS |
1484 STATION_INFO_RX_BYTES |
1485 STATION_INFO_RX_PACKETS;
1486 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1487 sinfo->tx_packets = priv->dev->stats.tx_packets;
1488 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1489 sinfo->rx_packets = priv->dev->stats.rx_packets;
1491 /* Get current RSSI */
1492 ret = lbs_get_signal(priv, &signal, &noise);
1494 sinfo->signal = signal;
1495 sinfo->filled |= STATION_INFO_SIGNAL;
1498 /* Convert priv->cur_rate from hw_value to NL80211 value */
1499 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1500 if (priv->cur_rate == lbs_rates[i].hw_value) {
1501 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1502 sinfo->filled |= STATION_INFO_TX_BITRATE;
1513 /***************************************************************************
1514 * "Site survey", here just current channel and noise level
1517 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1518 int idx, struct survey_info *survey)
1520 struct lbs_private *priv = wiphy_priv(wiphy);
1527 lbs_deb_enter(LBS_DEB_CFG80211);
1529 survey->channel = ieee80211_get_channel(wiphy,
1530 ieee80211_channel_to_frequency(priv->channel));
1532 ret = lbs_get_signal(priv, &signal, &noise);
1534 survey->filled = SURVEY_INFO_NOISE_DBM;
1535 survey->noise = noise;
1538 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1545 /***************************************************************************
1549 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1550 enum nl80211_iftype type, u32 *flags,
1551 struct vif_params *params)
1553 struct lbs_private *priv = wiphy_priv(wiphy);
1556 lbs_deb_enter(LBS_DEB_CFG80211);
1559 case NL80211_IFTYPE_MONITOR:
1560 ret = lbs_enable_monitor_mode(priv, 1);
1562 case NL80211_IFTYPE_STATION:
1563 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1564 ret = lbs_enable_monitor_mode(priv, 0);
1566 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1568 case NL80211_IFTYPE_ADHOC:
1569 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1570 ret = lbs_enable_monitor_mode(priv, 0);
1572 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1579 priv->wdev->iftype = type;
1581 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1587 /***************************************************************************
1591 /* The firmware needs the following bits masked out of the beacon-derived
1592 * capability field when associating/joining to a BSS:
1593 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1595 #define CAPINFO_MASK (~(0xda00))
1598 static void lbs_join_post(struct lbs_private *priv,
1599 struct cfg80211_ibss_params *params,
1600 u8 *bssid, u16 capability)
1602 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1603 2 + 4 + /* basic rates */
1604 2 + 1 + /* DS parameter */
1606 2 + 8]; /* extended rates */
1609 lbs_deb_enter(LBS_DEB_CFG80211);
1612 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1613 * the real IE from the firmware. So we fabricate a fake IE based on
1614 * what the firmware actually sends (sniffed with wireshark).
1617 *fake++ = WLAN_EID_SSID;
1618 *fake++ = params->ssid_len;
1619 memcpy(fake, params->ssid, params->ssid_len);
1620 fake += params->ssid_len;
1621 /* Fake supported basic rates IE */
1622 *fake++ = WLAN_EID_SUPP_RATES;
1628 /* Fake DS channel IE */
1629 *fake++ = WLAN_EID_DS_PARAMS;
1631 *fake++ = params->channel->hw_value;
1632 /* Fake IBSS params IE */
1633 *fake++ = WLAN_EID_IBSS_PARAMS;
1635 *fake++ = 0; /* ATIM=0 */
1637 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1638 * but I don't know how this could be checked */
1639 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1649 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1651 cfg80211_inform_bss(priv->wdev->wiphy,
1656 params->beacon_interval,
1657 fake_ie, fake - fake_ie,
1660 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1661 priv->wdev->ssid_len = params->ssid_len;
1663 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1665 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1666 priv->connect_status = LBS_CONNECTED;
1667 netif_carrier_on(priv->dev);
1668 if (!priv->tx_pending_len)
1669 netif_wake_queue(priv->dev);
1671 lbs_deb_leave(LBS_DEB_CFG80211);
1674 static int lbs_ibss_join_existing(struct lbs_private *priv,
1675 struct cfg80211_ibss_params *params,
1676 struct cfg80211_bss *bss)
1678 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1679 struct cmd_ds_802_11_ad_hoc_join cmd;
1680 u8 preamble = RADIO_PREAMBLE_SHORT;
1683 lbs_deb_enter(LBS_DEB_CFG80211);
1685 /* TODO: set preamble based on scan result */
1686 ret = lbs_set_radio(priv, preamble, 1);
1691 * Example CMD_802_11_AD_HOC_JOIN command:
1693 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1697 * bssid 02 27 27 97 2f 96
1698 * ssid 49 42 53 53 00 00 00 00
1699 * 00 00 00 00 00 00 00 00
1700 * 00 00 00 00 00 00 00 00
1701 * 00 00 00 00 00 00 00 00
1702 * type 02 CMD_BSS_TYPE_IBSS
1703 * beacon period 64 00
1705 * timestamp 00 00 00 00 00 00 00 00
1706 * localtime 00 00 00 00 00 00 00 00
1710 * reserveed 00 00 00 00
1713 * IE IBSS atim 00 00
1714 * reserved 00 00 00 00
1716 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1717 * fail timeout ff 00
1720 memset(&cmd, 0, sizeof(cmd));
1721 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1723 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1724 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1725 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1726 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1727 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1728 cmd.bss.ds.header.len = 1;
1729 cmd.bss.ds.channel = params->channel->hw_value;
1730 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1731 cmd.bss.ibss.header.len = 2;
1732 cmd.bss.ibss.atimwindow = 0;
1733 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1735 /* set rates to the intersection of our rates and the rates in the
1738 lbs_add_rates(cmd.bss.rates);
1741 u8 rates_max = rates_eid[1];
1742 u8 *rates = cmd.bss.rates;
1743 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1744 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1745 for (i = 0; i < rates_max; i++) {
1746 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1747 u8 rate = rates_eid[i+2];
1748 if (rate == 0x02 || rate == 0x04 ||
1749 rate == 0x0b || rate == 0x16)
1757 /* Only v8 and below support setting this */
1758 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1759 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1760 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1762 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1767 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1775 lbs_join_post(priv, params, bss->bssid, bss->capability);
1778 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1784 static int lbs_ibss_start_new(struct lbs_private *priv,
1785 struct cfg80211_ibss_params *params)
1787 struct cmd_ds_802_11_ad_hoc_start cmd;
1788 struct cmd_ds_802_11_ad_hoc_result *resp =
1789 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1790 u8 preamble = RADIO_PREAMBLE_SHORT;
1794 lbs_deb_enter(LBS_DEB_CFG80211);
1796 ret = lbs_set_radio(priv, preamble, 1);
1801 * Example CMD_802_11_AD_HOC_START command:
1803 * command 2b 00 CMD_802_11_AD_HOC_START
1807 * ssid 54 45 53 54 00 00 00 00
1808 * 00 00 00 00 00 00 00 00
1809 * 00 00 00 00 00 00 00 00
1810 * 00 00 00 00 00 00 00 00
1812 * beacon period 64 00
1816 * IE IBSS atim 00 00
1817 * reserved 00 00 00 00
1821 * reserved 00 00 00 00
1824 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1825 * 0c 12 18 24 30 48 60 6c
1828 memset(&cmd, 0, sizeof(cmd));
1829 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1830 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1831 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1832 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1833 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1834 cmd.ibss.header.len = 2;
1835 cmd.ibss.atimwindow = 0;
1836 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1837 cmd.ds.header.len = 1;
1838 cmd.ds.channel = params->channel->hw_value;
1839 /* Only v8 and below support setting probe delay */
1840 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1841 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1842 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1843 capability = WLAN_CAPABILITY_IBSS;
1844 cmd.capability = cpu_to_le16(capability);
1845 lbs_add_rates(cmd.rates);
1848 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1853 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1860 * bssid 02 2b 7b 0f 86 0e
1862 lbs_join_post(priv, params, resp->bssid, capability);
1865 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1870 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1871 struct cfg80211_ibss_params *params)
1873 struct lbs_private *priv = wiphy_priv(wiphy);
1875 struct cfg80211_bss *bss;
1876 DECLARE_SSID_BUF(ssid_buf);
1878 lbs_deb_enter(LBS_DEB_CFG80211);
1880 if (!params->channel) {
1885 ret = lbs_set_channel(priv, params->channel->hw_value);
1889 /* Search if someone is beaconing. This assumes that the
1890 * bss list is populated already */
1891 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1892 params->ssid, params->ssid_len,
1893 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1896 ret = lbs_ibss_join_existing(priv, params, bss);
1897 cfg80211_put_bss(bss);
1899 ret = lbs_ibss_start_new(priv, params);
1903 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1908 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1910 struct lbs_private *priv = wiphy_priv(wiphy);
1911 struct cmd_ds_802_11_ad_hoc_stop cmd;
1914 lbs_deb_enter(LBS_DEB_CFG80211);
1916 memset(&cmd, 0, sizeof(cmd));
1917 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1918 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1920 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1921 lbs_mac_event_disconnected(priv);
1923 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1930 /***************************************************************************
1934 static struct cfg80211_ops lbs_cfg80211_ops = {
1935 .set_channel = lbs_cfg_set_channel,
1936 .scan = lbs_cfg_scan,
1937 .connect = lbs_cfg_connect,
1938 .disconnect = lbs_cfg_disconnect,
1939 .add_key = lbs_cfg_add_key,
1940 .del_key = lbs_cfg_del_key,
1941 .set_default_key = lbs_cfg_set_default_key,
1942 .get_station = lbs_cfg_get_station,
1943 .dump_survey = lbs_get_survey,
1944 .change_virtual_intf = lbs_change_intf,
1945 .join_ibss = lbs_join_ibss,
1946 .leave_ibss = lbs_leave_ibss,
1951 * At this time lbs_private *priv doesn't even exist, so we just allocate
1952 * memory and don't initialize the wiphy further. This is postponed until we
1953 * can talk to the firmware and happens at registration time in
1954 * lbs_cfg_wiphy_register().
1956 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
1959 struct wireless_dev *wdev;
1961 lbs_deb_enter(LBS_DEB_CFG80211);
1963 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1965 dev_err(dev, "cannot allocate wireless device\n");
1966 return ERR_PTR(-ENOMEM);
1969 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
1971 dev_err(dev, "cannot allocate wiphy\n");
1976 lbs_deb_leave(LBS_DEB_CFG80211);
1981 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1982 return ERR_PTR(ret);
1986 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
1988 struct region_code_mapping {
1993 /* Section 5.17.2 */
1994 static struct region_code_mapping regmap[] = {
1995 {"US ", 0x10}, /* US FCC */
1996 {"CA ", 0x20}, /* Canada */
1997 {"EU ", 0x30}, /* ETSI */
1998 {"ES ", 0x31}, /* Spain */
1999 {"FR ", 0x32}, /* France */
2000 {"JP ", 0x40}, /* Japan */
2004 lbs_deb_enter(LBS_DEB_CFG80211);
2006 for (i = 0; i < ARRAY_SIZE(regmap); i++)
2007 if (regmap[i].code == priv->regioncode) {
2008 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
2012 lbs_deb_leave(LBS_DEB_CFG80211);
2017 * This function get's called after lbs_setup_firmware() determined the
2018 * firmware capabities. So we can setup the wiphy according to our
2019 * hardware/firmware.
2021 int lbs_cfg_register(struct lbs_private *priv)
2023 struct wireless_dev *wdev = priv->wdev;
2026 lbs_deb_enter(LBS_DEB_CFG80211);
2028 wdev->wiphy->max_scan_ssids = 1;
2029 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2031 wdev->wiphy->interface_modes =
2032 BIT(NL80211_IFTYPE_STATION) |
2033 BIT(NL80211_IFTYPE_ADHOC);
2034 if (lbs_rtap_supported(priv))
2035 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
2037 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
2040 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2041 * never seen a firmware without WPA
2043 wdev->wiphy->cipher_suites = cipher_suites;
2044 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2046 ret = wiphy_register(wdev->wiphy);
2048 lbs_pr_err("cannot register wiphy device\n");
2050 priv->wiphy_registered = true;
2052 ret = register_netdev(priv->dev);
2054 lbs_pr_err("cannot register network device\n");
2056 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2058 lbs_cfg_set_regulatory_hint(priv);
2060 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2065 void lbs_scan_deinit(struct lbs_private *priv)
2067 lbs_deb_enter(LBS_DEB_CFG80211);
2068 cancel_delayed_work_sync(&priv->scan_work);
2072 void lbs_cfg_free(struct lbs_private *priv)
2074 struct wireless_dev *wdev = priv->wdev;
2076 lbs_deb_enter(LBS_DEB_CFG80211);
2081 if (priv->wiphy_registered)
2082 wiphy_unregister(wdev->wiphy);
2085 wiphy_free(wdev->wiphy);