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;
260 /* Add common rates from a TLV and return the new end of the TLV */
262 add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
264 int hw, ap, ap_max = ie[1];
267 /* Advance past IE header */
270 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
272 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
273 hw_rate = lbs_rates[hw].bitrate / 5;
274 for (ap = 0; ap < ap_max; ap++) {
275 if (hw_rate == (ie[ap] & 0x7f)) {
277 *nrates = *nrates + 1;
285 * Adds a TLV with all rates the hardware *and* BSS supports.
287 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
289 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
290 const u8 *rates_eid, *ext_rates_eid;
293 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
294 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
297 * 01 00 TLV_TYPE_RATES
301 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
302 tlv += sizeof(rate_tlv->header);
304 /* Add basic rates */
306 tlv = add_ie_rates(tlv, rates_eid, &n);
308 /* Add extended rates, if any */
310 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
312 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
313 /* Fallback: add basic 802.11b rates */
321 rate_tlv->header.len = cpu_to_le16(n);
322 return sizeof(rate_tlv->header) + n;
329 * This is only needed for newer firmware (V9 and up).
331 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
332 sizeof(struct mrvl_ie_auth_type)
334 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
336 struct mrvl_ie_auth_type *auth = (void *) tlv;
339 * 1f 01 TLV_TYPE_AUTH_TYPE
343 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
344 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
345 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
346 return sizeof(*auth);
351 * Add channel (phy ds) TLV
353 #define LBS_MAX_CHANNEL_TLV_SIZE \
354 sizeof(struct mrvl_ie_header)
356 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
358 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
361 * 03 00 TLV_TYPE_PHY_DS
365 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
366 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
367 ds->channel = channel;
373 * Add (empty) CF param TLV of the form:
375 #define LBS_MAX_CF_PARAM_TLV_SIZE \
376 sizeof(struct mrvl_ie_header)
378 static int lbs_add_cf_param_tlv(u8 *tlv)
380 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
387 * 00 00 cfpmaxduration
388 * 00 00 cfpdurationremaining
390 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
391 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
398 #define LBS_MAX_WPA_TLV_SIZE \
399 (sizeof(struct mrvl_ie_header) \
400 + 128 /* TODO: I guessed the size */)
402 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
407 * We need just convert an IE to an TLV. IEs use u8 for the header,
411 * but TLVs use __le16 instead:
418 tlv_len = *tlv++ = *ie++;
422 /* the TLV is two bytes larger than the IE */
426 /***************************************************************************
430 static int lbs_cfg_set_channel(struct wiphy *wiphy,
431 struct net_device *netdev,
432 struct ieee80211_channel *channel,
433 enum nl80211_channel_type channel_type)
435 struct lbs_private *priv = wiphy_priv(wiphy);
438 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
439 channel->center_freq, channel_type);
441 if (channel_type != NL80211_CHAN_NO_HT)
444 ret = lbs_set_channel(priv, channel->hw_value);
447 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
453 /***************************************************************************
458 * When scanning, the firmware doesn't send a nul packet with the power-safe
459 * bit to the AP. So we cannot stay away from our current channel too long,
460 * otherwise we loose data. So take a "nap" while scanning every other
463 #define LBS_SCAN_BEFORE_NAP 4
467 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
468 * which isn't really an RSSI, as it becomes larger when moving away from
469 * the AP. Anyway, we need to convert that into mBm.
471 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
472 ((-(int)rssi + 3)*100)
474 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
475 struct cmd_header *resp)
477 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
486 lbs_deb_enter(LBS_DEB_CFG80211);
488 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
489 nr_sets = le16_to_cpu(scanresp->nr_sets);
491 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
492 nr_sets, bsssize, le16_to_cpu(resp->size));
500 * The general layout of the scan response is described in chapter
501 * 5.7.1. Basically we have a common part, then any number of BSS
502 * descriptor sections. Finally we have section with the same number
505 * cmd_ds_802_11_scan_rsp
518 * MrvlIEtypes_TsfFimestamp_t
524 pos = scanresp->bssdesc_and_tlvbuffer;
526 tsfdesc = pos + bsssize;
527 tsfsize = 4 + 8 * scanresp->nr_sets;
529 /* Validity check: we expect a Marvell-Local TLV */
530 i = get_unaligned_le16(tsfdesc);
532 if (i != TLV_TYPE_TSFTIMESTAMP)
534 /* Validity check: the TLV holds TSF values with 8 bytes each, so
535 * the size in the TLV must match the nr_sets value */
536 i = get_unaligned_le16(tsfdesc);
538 if (i / 8 != scanresp->nr_sets)
541 for (i = 0; i < scanresp->nr_sets; i++) {
550 const u8 *ssid = NULL;
552 DECLARE_SSID_BUF(ssid_buf);
554 int len = get_unaligned_le16(pos);
562 /* Packet time stamp */
564 /* Beacon interval */
565 intvl = get_unaligned_le16(pos);
568 capa = get_unaligned_le16(pos);
571 /* To find out the channel, we must parse the IEs */
573 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
574 interval, capabilities */
575 ielen = left = len - (6 + 1 + 8 + 2 + 2);
581 if (elen > left || elen == 0)
583 if (id == WLAN_EID_DS_PARAMS)
585 if (id == WLAN_EID_SSID) {
593 /* No channel, no luck */
595 struct wiphy *wiphy = priv->wdev->wiphy;
596 int freq = ieee80211_channel_to_frequency(chan_no);
597 struct ieee80211_channel *channel =
598 ieee80211_get_channel(wiphy, freq);
600 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
602 bssid, capa, chan_no,
603 print_ssid(ssid_buf, ssid, ssid_len),
604 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
607 !(channel->flags & IEEE80211_CHAN_DISABLED))
608 cfg80211_inform_bss(wiphy, channel,
609 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
610 capa, intvl, ie, ielen,
611 LBS_SCAN_RSSI_TO_MBM(rssi),
619 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
625 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
626 * TLV and a rates TLV. Determine the maximum size of them:
628 #define LBS_SCAN_MAX_CMD_SIZE \
629 (sizeof(struct cmd_ds_802_11_scan) \
630 + LBS_MAX_SSID_TLV_SIZE \
631 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
632 + LBS_MAX_RATES_TLV_SIZE)
635 * Assumes priv->scan_req is initialized and valid
636 * Assumes priv->scan_channel is initialized
638 static void lbs_scan_worker(struct work_struct *work)
640 struct lbs_private *priv =
641 container_of(work, struct lbs_private, scan_work.work);
642 struct cmd_ds_802_11_scan *scan_cmd;
643 u8 *tlv; /* pointer into our current, growing TLV storage area */
645 int running, carrier;
647 lbs_deb_enter(LBS_DEB_SCAN);
649 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
650 if (scan_cmd == NULL)
651 goto out_no_scan_cmd;
653 /* prepare fixed part of scan command */
654 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
656 /* stop network while we're away from our main channel */
657 running = !netif_queue_stopped(priv->dev);
658 carrier = netif_carrier_ok(priv->dev);
660 netif_stop_queue(priv->dev);
662 netif_carrier_off(priv->dev);
664 /* prepare fixed part of scan command */
665 tlv = scan_cmd->tlvbuffer;
668 if (priv->scan_req->n_ssids)
669 tlv += lbs_add_ssid_tlv(tlv,
670 priv->scan_req->ssids[0].ssid,
671 priv->scan_req->ssids[0].ssid_len);
673 /* add channel TLVs */
674 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
675 if (last_channel > priv->scan_req->n_channels)
676 last_channel = priv->scan_req->n_channels;
677 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
678 priv->scan_req->n_ssids);
681 tlv += lbs_add_supported_rates_tlv(tlv);
683 if (priv->scan_channel < priv->scan_req->n_channels) {
684 cancel_delayed_work(&priv->scan_work);
685 queue_delayed_work(priv->work_thread, &priv->scan_work,
686 msecs_to_jiffies(300));
689 /* This is the final data we are about to send */
690 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
691 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
693 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
694 tlv - scan_cmd->tlvbuffer);
696 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
697 le16_to_cpu(scan_cmd->hdr.size),
700 if (priv->scan_channel >= priv->scan_req->n_channels) {
702 cfg80211_scan_done(priv->scan_req, false);
703 priv->scan_req = NULL;
706 /* Restart network */
708 netif_carrier_on(priv->dev);
709 if (running && !priv->tx_pending_len)
710 netif_wake_queue(priv->dev);
715 lbs_deb_leave(LBS_DEB_SCAN);
719 static int lbs_cfg_scan(struct wiphy *wiphy,
720 struct net_device *dev,
721 struct cfg80211_scan_request *request)
723 struct lbs_private *priv = wiphy_priv(wiphy);
726 lbs_deb_enter(LBS_DEB_CFG80211);
728 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
729 /* old scan request not yet processed */
734 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
735 request->n_ssids, request->n_channels, request->ie_len);
737 priv->scan_channel = 0;
738 queue_delayed_work(priv->work_thread, &priv->scan_work,
739 msecs_to_jiffies(50));
741 if (priv->surpriseremoved)
744 priv->scan_req = request;
747 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
754 /***************************************************************************
758 void lbs_send_disconnect_notification(struct lbs_private *priv)
760 lbs_deb_enter(LBS_DEB_CFG80211);
762 cfg80211_disconnected(priv->dev,
767 lbs_deb_leave(LBS_DEB_CFG80211);
770 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
772 lbs_deb_enter(LBS_DEB_CFG80211);
774 cfg80211_michael_mic_failure(priv->dev,
776 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
777 NL80211_KEYTYPE_GROUP :
778 NL80211_KEYTYPE_PAIRWISE,
783 lbs_deb_leave(LBS_DEB_CFG80211);
789 /***************************************************************************
795 * This removes all WEP keys
797 static int lbs_remove_wep_keys(struct lbs_private *priv)
799 struct cmd_ds_802_11_set_wep cmd;
802 lbs_deb_enter(LBS_DEB_CFG80211);
804 memset(&cmd, 0, sizeof(cmd));
805 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
806 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
807 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
809 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
811 lbs_deb_leave(LBS_DEB_CFG80211);
818 static int lbs_set_wep_keys(struct lbs_private *priv)
820 struct cmd_ds_802_11_set_wep cmd;
824 lbs_deb_enter(LBS_DEB_CFG80211);
831 * action 02 00 ACT_ADD
833 * type for key 1 01 WEP40
837 * key 1 39 39 39 39 39 00 00 00
838 * 00 00 00 00 00 00 00 00
839 * key 2 00 00 00 00 00 00 00 00
840 * 00 00 00 00 00 00 00 00
841 * key 3 00 00 00 00 00 00 00 00
842 * 00 00 00 00 00 00 00 00
843 * key 4 00 00 00 00 00 00 00 00
845 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
846 priv->wep_key_len[2] || priv->wep_key_len[3]) {
847 /* Only set wep keys if we have at least one of them */
848 memset(&cmd, 0, sizeof(cmd));
849 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
850 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
851 cmd.action = cpu_to_le16(CMD_ACT_ADD);
853 for (i = 0; i < 4; i++) {
854 switch (priv->wep_key_len[i]) {
855 case WLAN_KEY_LEN_WEP40:
856 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
858 case WLAN_KEY_LEN_WEP104:
859 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
865 memcpy(cmd.keymaterial[i], priv->wep_key[i],
866 priv->wep_key_len[i]);
869 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
871 /* Otherwise remove all wep keys */
872 ret = lbs_remove_wep_keys(priv);
875 lbs_deb_leave(LBS_DEB_CFG80211);
881 * Enable/Disable RSN status
883 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
885 struct cmd_ds_802_11_enable_rsn cmd;
888 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
895 * action 01 00 ACT_SET
898 memset(&cmd, 0, sizeof(cmd));
899 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
900 cmd.action = cpu_to_le16(CMD_ACT_SET);
901 cmd.enable = cpu_to_le16(enable);
903 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
905 lbs_deb_leave(LBS_DEB_CFG80211);
911 * Set WPA/WPA key material
914 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
915 * get rid of WEXT, this should go into host.h */
917 struct cmd_key_material {
918 struct cmd_header hdr;
921 struct MrvlIEtype_keyParamSet param;
924 static int lbs_set_key_material(struct lbs_private *priv,
927 u8 *key, u16 key_len)
929 struct cmd_key_material cmd;
932 lbs_deb_enter(LBS_DEB_CFG80211);
935 * Example for WPA (TKIP):
942 * TLV type 00 01 key param
944 * key type 01 00 TKIP
945 * key info 06 00 UNICAST | ENABLED
949 memset(&cmd, 0, sizeof(cmd));
950 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
951 cmd.action = cpu_to_le16(CMD_ACT_SET);
952 cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
953 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
954 cmd.param.keytypeid = cpu_to_le16(key_type);
955 cmd.param.keyinfo = cpu_to_le16(key_info);
956 cmd.param.keylen = cpu_to_le16(key_len);
958 memcpy(cmd.param.key, key, key_len);
960 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
962 lbs_deb_leave(LBS_DEB_CFG80211);
968 * Sets the auth type (open, shared, etc) in the firmware. That
969 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
970 * command doesn't send an authentication frame at all, it just
971 * stores the auth_type.
973 static int lbs_set_authtype(struct lbs_private *priv,
974 struct cfg80211_connect_params *sme)
976 struct cmd_ds_802_11_authenticate cmd;
979 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
986 * BSS id 00 13 19 80 da 30
988 * reserved 00 00 00 00 00 00 00 00 00 00
990 memset(&cmd, 0, sizeof(cmd));
991 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
993 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
994 /* convert auth_type */
995 ret = lbs_auth_to_authtype(sme->auth_type);
1000 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
1003 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1009 * Create association request
1011 #define LBS_ASSOC_MAX_CMD_SIZE \
1012 (sizeof(struct cmd_ds_802_11_associate) \
1013 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1014 + LBS_MAX_SSID_TLV_SIZE \
1015 + LBS_MAX_CHANNEL_TLV_SIZE \
1016 + LBS_MAX_CF_PARAM_TLV_SIZE \
1017 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1018 + LBS_MAX_WPA_TLV_SIZE)
1020 static int lbs_associate(struct lbs_private *priv,
1021 struct cfg80211_bss *bss,
1022 struct cfg80211_connect_params *sme)
1024 struct cmd_ds_802_11_associate_response *resp;
1025 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
1028 size_t len, resp_ie_len;
1031 u8 *pos = &(cmd->iebuf[0]);
1034 lbs_deb_enter(LBS_DEB_CFG80211);
1046 * BSS id 00 13 19 80 da 30
1047 * capabilities 11 00
1048 * listen interval 0a 00
1049 * beacon interval 00 00
1051 * TLVs xx (up to 512 bytes)
1053 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1055 /* Fill in static fields */
1056 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1057 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1058 cmd->capability = cpu_to_le16(bss->capability);
1061 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1063 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1065 lbs_deb_assoc("no SSID\n");
1067 /* add DS param TLV */
1069 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1071 lbs_deb_assoc("no channel\n");
1073 /* add (empty) CF param TLV */
1074 pos += lbs_add_cf_param_tlv(pos);
1077 tmp = pos + 4; /* skip Marvell IE header */
1078 pos += lbs_add_common_rates_tlv(pos, bss);
1079 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1081 /* add auth type TLV */
1082 if (priv->fwrelease >= 0x09000000)
1083 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1085 /* add WPA/WPA2 TLV */
1086 if (sme->ie && sme->ie_len)
1087 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1089 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1090 (u16)(pos - (u8 *) &cmd->iebuf);
1091 cmd->hdr.size = cpu_to_le16(len);
1093 /* store for later use */
1094 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1096 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1101 /* generate connect message to cfg80211 */
1103 resp = (void *) cmd; /* recast for easier field access */
1104 status = le16_to_cpu(resp->statuscode);
1106 /* Convert statis code of old firmware */
1107 if (priv->fwrelease < 0x09000000)
1112 lbs_deb_assoc("invalid association parameters\n");
1113 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1116 lbs_deb_assoc("timer expired while waiting for AP\n");
1117 status = WLAN_STATUS_AUTH_TIMEOUT;
1120 lbs_deb_assoc("association refused by AP\n");
1121 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1124 lbs_deb_assoc("authentication refused by AP\n");
1125 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1128 lbs_deb_assoc("association failure %d\n", status);
1129 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1132 lbs_deb_assoc("status %d, capability 0x%04x\n", status,
1133 le16_to_cpu(resp->capability));
1135 resp_ie_len = le16_to_cpu(resp->hdr.size)
1138 cfg80211_connect_result(priv->dev,
1140 sme->ie, sme->ie_len,
1141 resp->iebuf, resp_ie_len,
1146 /* TODO: get rid of priv->connect_status */
1147 priv->connect_status = LBS_CONNECTED;
1148 netif_carrier_on(priv->dev);
1149 if (!priv->tx_pending_len)
1150 netif_tx_wake_all_queues(priv->dev);
1155 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1161 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1162 struct cfg80211_connect_params *sme)
1164 struct lbs_private *priv = wiphy_priv(wiphy);
1165 struct cfg80211_bss *bss = NULL;
1167 u8 preamble = RADIO_PREAMBLE_SHORT;
1169 lbs_deb_enter(LBS_DEB_CFG80211);
1172 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1173 sme->ssid, sme->ssid_len,
1174 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1177 * Here we have an impedance mismatch. The firmware command
1178 * CMD_802_11_ASSOCIATE always needs a BSSID, it cannot
1179 * connect otherwise. However, for the connect-API of
1180 * cfg80211 the bssid is purely optional. We don't get one,
1181 * except the user specifies one on the "iw" command line.
1183 * If we don't got one, we could initiate a scan and look
1184 * for the best matching cfg80211_bss entry.
1186 * Or, better yet, net/wireless/sme.c get's rewritten into
1187 * something more generally useful.
1189 lbs_pr_err("TODO: no BSS specified\n");
1196 lbs_pr_err("assicate: bss %pM not in scan results\n",
1201 lbs_deb_assoc("trying %pM", sme->bssid);
1202 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1203 sme->crypto.cipher_group,
1204 sme->key_idx, sme->key_len);
1206 /* As this is a new connection, clear locally stored WEP keys */
1207 priv->wep_tx_key = 0;
1208 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1209 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1211 /* set/remove WEP keys */
1212 switch (sme->crypto.cipher_group) {
1213 case WLAN_CIPHER_SUITE_WEP40:
1214 case WLAN_CIPHER_SUITE_WEP104:
1215 /* Store provided WEP keys in priv-> */
1216 priv->wep_tx_key = sme->key_idx;
1217 priv->wep_key_len[sme->key_idx] = sme->key_len;
1218 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1219 /* Set WEP keys and WEP mode */
1220 lbs_set_wep_keys(priv);
1221 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1222 lbs_set_mac_control(priv);
1223 /* No RSN mode for WEP */
1224 lbs_enable_rsn(priv, 0);
1226 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1228 * If we don't have no WEP, no WPA and no WPA2,
1229 * we remove all keys like in the WPA/WPA2 setup,
1230 * we just don't set RSN.
1232 * Therefore: fall-throught
1234 case WLAN_CIPHER_SUITE_TKIP:
1235 case WLAN_CIPHER_SUITE_CCMP:
1236 /* Remove WEP keys and WEP mode */
1237 lbs_remove_wep_keys(priv);
1238 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1239 lbs_set_mac_control(priv);
1241 /* clear the WPA/WPA2 keys */
1242 lbs_set_key_material(priv,
1243 KEY_TYPE_ID_WEP, /* doesn't matter */
1244 KEY_INFO_WPA_UNICAST,
1246 lbs_set_key_material(priv,
1247 KEY_TYPE_ID_WEP, /* doesn't matter */
1250 /* RSN mode for WPA/WPA2 */
1251 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1254 lbs_pr_err("unsupported cipher group 0x%x\n",
1255 sme->crypto.cipher_group);
1260 lbs_set_authtype(priv, sme);
1261 lbs_set_radio(priv, preamble, 1);
1263 /* Do the actual association */
1264 lbs_associate(priv, bss, sme);
1268 cfg80211_put_bss(bss);
1269 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1273 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1276 struct lbs_private *priv = wiphy_priv(wiphy);
1277 struct cmd_ds_802_11_deauthenticate cmd;
1279 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1281 /* store for lbs_cfg_ret_disconnect() */
1282 priv->disassoc_reason = reason_code;
1284 memset(&cmd, 0, sizeof(cmd));
1285 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1286 /* Mildly ugly to use a locally store my own BSSID ... */
1287 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1288 cmd.reasoncode = cpu_to_le16(reason_code);
1290 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1293 cfg80211_disconnected(priv->dev,
1294 priv->disassoc_reason,
1297 priv->connect_status = LBS_DISCONNECTED;
1303 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1304 struct net_device *netdev,
1307 struct lbs_private *priv = wiphy_priv(wiphy);
1309 lbs_deb_enter(LBS_DEB_CFG80211);
1311 if (key_index != priv->wep_tx_key) {
1312 lbs_deb_assoc("set_default_key: to %d\n", key_index);
1313 priv->wep_tx_key = key_index;
1314 lbs_set_wep_keys(priv);
1321 static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1322 u8 idx, const u8 *mac_addr,
1323 struct key_params *params)
1325 struct lbs_private *priv = wiphy_priv(wiphy);
1330 lbs_deb_enter(LBS_DEB_CFG80211);
1332 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1333 params->cipher, mac_addr);
1334 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1335 idx, params->key_len);
1336 if (params->key_len)
1337 lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
1338 params->key, params->key_len);
1340 lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
1341 if (params->seq_len)
1342 lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
1343 params->seq, params->seq_len);
1345 switch (params->cipher) {
1346 case WLAN_CIPHER_SUITE_WEP40:
1347 case WLAN_CIPHER_SUITE_WEP104:
1348 /* actually compare if something has changed ... */
1349 if ((priv->wep_key_len[idx] != params->key_len) ||
1350 memcmp(priv->wep_key[idx],
1351 params->key, params->key_len) != 0) {
1352 priv->wep_key_len[idx] = params->key_len;
1353 memcpy(priv->wep_key[idx],
1354 params->key, params->key_len);
1355 lbs_set_wep_keys(priv);
1358 case WLAN_CIPHER_SUITE_TKIP:
1359 case WLAN_CIPHER_SUITE_CCMP:
1360 key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
1361 ? KEY_INFO_WPA_UNICAST
1362 : KEY_INFO_WPA_MCAST);
1363 key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1366 lbs_set_key_material(priv,
1369 params->key, params->key_len);
1372 lbs_pr_err("unhandled cipher 0x%x\n", params->cipher);
1381 static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1382 u8 key_index, const u8 *mac_addr)
1385 lbs_deb_enter(LBS_DEB_CFG80211);
1387 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1388 key_index, mac_addr);
1391 struct lbs_private *priv = wiphy_priv(wiphy);
1393 * I think can keep this a NO-OP, because:
1395 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1396 * - neither "iw" nor "wpa_supplicant" won't call this during
1397 * an ongoing connection
1398 * - TODO: but I have to check if this is still true when
1399 * I set the AP to periodic re-keying
1400 * - we've not kzallec() something when we've added a key at
1401 * lbs_cfg_connect() or lbs_cfg_add_key().
1403 * This causes lbs_cfg_del_key() only called at disconnect time,
1404 * where we'd just waste time deleting a key that is not going
1405 * to be used anyway.
1407 if (key_index < 3 && priv->wep_key_len[key_index]) {
1408 priv->wep_key_len[key_index] = 0;
1409 lbs_set_wep_keys(priv);
1417 /***************************************************************************
1421 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1422 u8 *mac, struct station_info *sinfo)
1424 struct lbs_private *priv = wiphy_priv(wiphy);
1429 lbs_deb_enter(LBS_DEB_CFG80211);
1431 sinfo->filled |= STATION_INFO_TX_BYTES |
1432 STATION_INFO_TX_PACKETS |
1433 STATION_INFO_RX_BYTES |
1434 STATION_INFO_RX_PACKETS;
1435 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1436 sinfo->tx_packets = priv->dev->stats.tx_packets;
1437 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1438 sinfo->rx_packets = priv->dev->stats.rx_packets;
1440 /* Get current RSSI */
1441 ret = lbs_get_rssi(priv, &signal, &noise);
1443 sinfo->signal = signal;
1444 sinfo->filled |= STATION_INFO_SIGNAL;
1447 /* Convert priv->cur_rate from hw_value to NL80211 value */
1448 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1449 if (priv->cur_rate == lbs_rates[i].hw_value) {
1450 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1451 sinfo->filled |= STATION_INFO_TX_BITRATE;
1462 /***************************************************************************
1463 * "Site survey", here just current channel and noise level
1466 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1467 int idx, struct survey_info *survey)
1469 struct lbs_private *priv = wiphy_priv(wiphy);
1476 lbs_deb_enter(LBS_DEB_CFG80211);
1478 survey->channel = ieee80211_get_channel(wiphy,
1479 ieee80211_channel_to_frequency(priv->channel));
1481 ret = lbs_get_rssi(priv, &signal, &noise);
1483 survey->filled = SURVEY_INFO_NOISE_DBM;
1484 survey->noise = noise;
1487 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1494 /***************************************************************************
1498 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1499 enum nl80211_iftype type, u32 *flags,
1500 struct vif_params *params)
1502 struct lbs_private *priv = wiphy_priv(wiphy);
1505 lbs_deb_enter(LBS_DEB_CFG80211);
1508 case NL80211_IFTYPE_MONITOR:
1509 ret = lbs_set_monitor_mode(priv, 1);
1511 case NL80211_IFTYPE_STATION:
1512 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1513 ret = lbs_set_monitor_mode(priv, 0);
1515 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1517 case NL80211_IFTYPE_ADHOC:
1518 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1519 ret = lbs_set_monitor_mode(priv, 0);
1521 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1528 priv->wdev->iftype = type;
1530 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1536 /***************************************************************************
1540 /* The firmware needs the following bits masked out of the beacon-derived
1541 * capability field when associating/joining to a BSS:
1542 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1544 #define CAPINFO_MASK (~(0xda00))
1547 static void lbs_join_post(struct lbs_private *priv,
1548 struct cfg80211_ibss_params *params,
1549 u8 *bssid, u16 capability)
1551 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1552 2 + 4 + /* basic rates */
1553 2 + 1 + /* DS parameter */
1555 2 + 8]; /* extended rates */
1558 lbs_deb_enter(LBS_DEB_CFG80211);
1561 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1562 * the real IE from the firmware. So we fabricate a fake IE based on
1563 * what the firmware actually sends (sniffed with wireshark).
1566 *fake++ = WLAN_EID_SSID;
1567 *fake++ = params->ssid_len;
1568 memcpy(fake, params->ssid, params->ssid_len);
1569 fake += params->ssid_len;
1570 /* Fake supported basic rates IE */
1571 *fake++ = WLAN_EID_SUPP_RATES;
1577 /* Fake DS channel IE */
1578 *fake++ = WLAN_EID_DS_PARAMS;
1580 *fake++ = params->channel->hw_value;
1581 /* Fake IBSS params IE */
1582 *fake++ = WLAN_EID_IBSS_PARAMS;
1584 *fake++ = 0; /* ATIM=0 */
1586 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1587 * but I don't know how this could be checked */
1588 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1598 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1600 cfg80211_inform_bss(priv->wdev->wiphy,
1605 params->beacon_interval,
1606 fake_ie, fake - fake_ie,
1609 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1610 priv->wdev->ssid_len = params->ssid_len;
1612 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1614 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1615 priv->connect_status = LBS_CONNECTED;
1616 netif_carrier_on(priv->dev);
1617 if (!priv->tx_pending_len)
1618 netif_wake_queue(priv->dev);
1620 lbs_deb_leave(LBS_DEB_CFG80211);
1623 static int lbs_ibss_join_existing(struct lbs_private *priv,
1624 struct cfg80211_ibss_params *params,
1625 struct cfg80211_bss *bss)
1627 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1628 struct cmd_ds_802_11_ad_hoc_join cmd;
1629 u8 preamble = RADIO_PREAMBLE_SHORT;
1632 lbs_deb_enter(LBS_DEB_CFG80211);
1634 /* TODO: set preamble based on scan result */
1635 ret = lbs_set_radio(priv, preamble, 1);
1640 * Example CMD_802_11_AD_HOC_JOIN command:
1642 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1646 * bssid 02 27 27 97 2f 96
1647 * ssid 49 42 53 53 00 00 00 00
1648 * 00 00 00 00 00 00 00 00
1649 * 00 00 00 00 00 00 00 00
1650 * 00 00 00 00 00 00 00 00
1651 * type 02 CMD_BSS_TYPE_IBSS
1652 * beacon period 64 00
1654 * timestamp 00 00 00 00 00 00 00 00
1655 * localtime 00 00 00 00 00 00 00 00
1659 * reserveed 00 00 00 00
1662 * IE IBSS atim 00 00
1663 * reserved 00 00 00 00
1665 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1666 * fail timeout ff 00
1669 memset(&cmd, 0, sizeof(cmd));
1670 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1672 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1673 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1674 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1675 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1676 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1677 cmd.bss.ds.header.len = 1;
1678 cmd.bss.ds.channel = params->channel->hw_value;
1679 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1680 cmd.bss.ibss.header.len = 2;
1681 cmd.bss.ibss.atimwindow = 0;
1682 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1684 /* set rates to the intersection of our rates and the rates in the
1687 lbs_add_rates(cmd.bss.rates);
1690 u8 rates_max = rates_eid[1];
1691 u8 *rates = cmd.bss.rates;
1692 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1693 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1694 for (i = 0; i < rates_max; i++) {
1695 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1696 u8 rate = rates_eid[i+2];
1697 if (rate == 0x02 || rate == 0x04 ||
1698 rate == 0x0b || rate == 0x16)
1706 /* Only v8 and below support setting this */
1707 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1708 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1709 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1711 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1716 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1724 lbs_join_post(priv, params, bss->bssid, bss->capability);
1727 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1733 static int lbs_ibss_start_new(struct lbs_private *priv,
1734 struct cfg80211_ibss_params *params)
1736 struct cmd_ds_802_11_ad_hoc_start cmd;
1737 struct cmd_ds_802_11_ad_hoc_result *resp =
1738 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1739 u8 preamble = RADIO_PREAMBLE_SHORT;
1743 lbs_deb_enter(LBS_DEB_CFG80211);
1745 ret = lbs_set_radio(priv, preamble, 1);
1750 * Example CMD_802_11_AD_HOC_START command:
1752 * command 2b 00 CMD_802_11_AD_HOC_START
1756 * ssid 54 45 53 54 00 00 00 00
1757 * 00 00 00 00 00 00 00 00
1758 * 00 00 00 00 00 00 00 00
1759 * 00 00 00 00 00 00 00 00
1761 * beacon period 64 00
1765 * IE IBSS atim 00 00
1766 * reserved 00 00 00 00
1770 * reserved 00 00 00 00
1773 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1774 * 0c 12 18 24 30 48 60 6c
1777 memset(&cmd, 0, sizeof(cmd));
1778 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1779 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1780 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1781 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1782 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1783 cmd.ibss.header.len = 2;
1784 cmd.ibss.atimwindow = 0;
1785 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1786 cmd.ds.header.len = 1;
1787 cmd.ds.channel = params->channel->hw_value;
1788 /* Only v8 and below support setting probe delay */
1789 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1790 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1791 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1792 capability = WLAN_CAPABILITY_IBSS;
1793 cmd.capability = cpu_to_le16(capability);
1794 lbs_add_rates(cmd.rates);
1797 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1802 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1809 * bssid 02 2b 7b 0f 86 0e
1811 lbs_join_post(priv, params, resp->bssid, capability);
1814 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1819 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1820 struct cfg80211_ibss_params *params)
1822 struct lbs_private *priv = wiphy_priv(wiphy);
1824 struct cfg80211_bss *bss;
1825 DECLARE_SSID_BUF(ssid_buf);
1827 lbs_deb_enter(LBS_DEB_CFG80211);
1829 if (!params->channel) {
1834 ret = lbs_set_channel(priv, params->channel->hw_value);
1838 /* Search if someone is beaconing. This assumes that the
1839 * bss list is populated already */
1840 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1841 params->ssid, params->ssid_len,
1842 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1845 ret = lbs_ibss_join_existing(priv, params, bss);
1846 cfg80211_put_bss(bss);
1848 ret = lbs_ibss_start_new(priv, params);
1852 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1857 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1859 struct lbs_private *priv = wiphy_priv(wiphy);
1860 struct cmd_ds_802_11_ad_hoc_stop cmd;
1863 lbs_deb_enter(LBS_DEB_CFG80211);
1865 memset(&cmd, 0, sizeof(cmd));
1866 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1867 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1869 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1870 lbs_mac_event_disconnected(priv);
1872 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1879 /***************************************************************************
1883 static struct cfg80211_ops lbs_cfg80211_ops = {
1884 .set_channel = lbs_cfg_set_channel,
1885 .scan = lbs_cfg_scan,
1886 .connect = lbs_cfg_connect,
1887 .disconnect = lbs_cfg_disconnect,
1888 .add_key = lbs_cfg_add_key,
1889 .del_key = lbs_cfg_del_key,
1890 .set_default_key = lbs_cfg_set_default_key,
1891 .get_station = lbs_cfg_get_station,
1892 .dump_survey = lbs_get_survey,
1893 .change_virtual_intf = lbs_change_intf,
1894 .join_ibss = lbs_join_ibss,
1895 .leave_ibss = lbs_leave_ibss,
1900 * At this time lbs_private *priv doesn't even exist, so we just allocate
1901 * memory and don't initialize the wiphy further. This is postponed until we
1902 * can talk to the firmware and happens at registration time in
1903 * lbs_cfg_wiphy_register().
1905 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
1908 struct wireless_dev *wdev;
1910 lbs_deb_enter(LBS_DEB_CFG80211);
1912 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
1914 dev_err(dev, "cannot allocate wireless device\n");
1915 return ERR_PTR(-ENOMEM);
1918 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
1920 dev_err(dev, "cannot allocate wiphy\n");
1925 lbs_deb_leave(LBS_DEB_CFG80211);
1930 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1931 return ERR_PTR(ret);
1935 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
1937 struct region_code_mapping {
1942 /* Section 5.17.2 */
1943 static struct region_code_mapping regmap[] = {
1944 {"US ", 0x10}, /* US FCC */
1945 {"CA ", 0x20}, /* Canada */
1946 {"EU ", 0x30}, /* ETSI */
1947 {"ES ", 0x31}, /* Spain */
1948 {"FR ", 0x32}, /* France */
1949 {"JP ", 0x40}, /* Japan */
1953 lbs_deb_enter(LBS_DEB_CFG80211);
1955 for (i = 0; i < ARRAY_SIZE(regmap); i++)
1956 if (regmap[i].code == priv->regioncode) {
1957 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
1961 lbs_deb_leave(LBS_DEB_CFG80211);
1966 * This function get's called after lbs_setup_firmware() determined the
1967 * firmware capabities. So we can setup the wiphy according to our
1968 * hardware/firmware.
1970 int lbs_cfg_register(struct lbs_private *priv)
1972 struct wireless_dev *wdev = priv->wdev;
1975 lbs_deb_enter(LBS_DEB_CFG80211);
1977 wdev->wiphy->max_scan_ssids = 1;
1978 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
1980 wdev->wiphy->interface_modes =
1981 BIT(NL80211_IFTYPE_STATION) |
1982 BIT(NL80211_IFTYPE_ADHOC);
1983 if (lbs_rtap_supported(priv))
1984 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
1986 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
1989 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
1990 * never seen a firmware without WPA
1992 wdev->wiphy->cipher_suites = cipher_suites;
1993 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
1994 wdev->wiphy->reg_notifier = lbs_reg_notifier;
1996 ret = wiphy_register(wdev->wiphy);
1998 lbs_pr_err("cannot register wiphy device\n");
2000 priv->wiphy_registered = true;
2002 ret = register_netdev(priv->dev);
2004 lbs_pr_err("cannot register network device\n");
2006 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2008 lbs_cfg_set_regulatory_hint(priv);
2010 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2014 int lbs_reg_notifier(struct wiphy *wiphy,
2015 struct regulatory_request *request)
2017 struct lbs_private *priv = wiphy_priv(wiphy);
2020 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
2021 "callback for domain %c%c\n", request->alpha2[0],
2022 request->alpha2[1]);
2024 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
2026 lbs_deb_leave(LBS_DEB_CFG80211);
2030 void lbs_scan_deinit(struct lbs_private *priv)
2032 lbs_deb_enter(LBS_DEB_CFG80211);
2033 cancel_delayed_work_sync(&priv->scan_work);
2037 void lbs_cfg_free(struct lbs_private *priv)
2039 struct wireless_dev *wdev = priv->wdev;
2041 lbs_deb_enter(LBS_DEB_CFG80211);
2046 if (priv->wiphy_registered)
2047 wiphy_unregister(wdev->wiphy);
2050 wiphy_free(wdev->wiphy);