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/sched.h>
10 #include <linux/wait.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <linux/wait.h>
14 #include <linux/ieee80211.h>
15 #include <net/cfg80211.h>
16 #include <asm/unaligned.h>
23 #define CHAN2G(_channel, _freq, _flags) { \
24 .band = IEEE80211_BAND_2GHZ, \
25 .center_freq = (_freq), \
26 .hw_value = (_channel), \
28 .max_antenna_gain = 0, \
32 static struct ieee80211_channel lbs_2ghz_channels[] = {
49 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
51 .hw_value = (_hw_value), \
56 /* Table 6 in section 3.2.1.1 */
57 static struct ieee80211_rate lbs_rates[] = {
58 RATETAB_ENT(10, 0, 0),
59 RATETAB_ENT(20, 1, 0),
60 RATETAB_ENT(55, 2, 0),
61 RATETAB_ENT(110, 3, 0),
62 RATETAB_ENT(60, 9, 0),
63 RATETAB_ENT(90, 6, 0),
64 RATETAB_ENT(120, 7, 0),
65 RATETAB_ENT(180, 8, 0),
66 RATETAB_ENT(240, 9, 0),
67 RATETAB_ENT(360, 10, 0),
68 RATETAB_ENT(480, 11, 0),
69 RATETAB_ENT(540, 12, 0),
72 static struct ieee80211_supported_band lbs_band_2ghz = {
73 .channels = lbs_2ghz_channels,
74 .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
75 .bitrates = lbs_rates,
76 .n_bitrates = ARRAY_SIZE(lbs_rates),
80 static const u32 cipher_suites[] = {
81 WLAN_CIPHER_SUITE_WEP40,
82 WLAN_CIPHER_SUITE_WEP104,
83 WLAN_CIPHER_SUITE_TKIP,
84 WLAN_CIPHER_SUITE_CCMP,
87 /* Time to stay on the channel */
88 #define LBS_DWELL_PASSIVE 100
89 #define LBS_DWELL_ACTIVE 40
92 /***************************************************************************
93 * Misc utility functions
95 * TLVs are Marvell specific. They are very similar to IEs, they have the
96 * same structure: type, length, data*. The only difference: for IEs, the
97 * type and length are u8, but for TLVs they're __le16.
101 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
102 * in the firmware spec
104 static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
109 case NL80211_AUTHTYPE_OPEN_SYSTEM:
110 case NL80211_AUTHTYPE_SHARED_KEY:
113 case NL80211_AUTHTYPE_AUTOMATIC:
114 ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
116 case NL80211_AUTHTYPE_NETWORK_EAP:
120 /* silence compiler */
127 /* Various firmware commands need the list of supported rates, but with
128 the hight-bit set for basic rates */
129 static int lbs_add_rates(u8 *rates)
133 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
134 u8 rate = lbs_rates[i].bitrate / 5;
135 if (rate == 0x02 || rate == 0x04 ||
136 rate == 0x0b || rate == 0x16)
140 return ARRAY_SIZE(lbs_rates);
144 /***************************************************************************
145 * TLV utility functions
147 * TLVs are Marvell specific. They are very similar to IEs, they have the
148 * same structure: type, length, data*. The only difference: for IEs, the
149 * type and length are u8, but for TLVs they're __le16.
156 #define LBS_MAX_SSID_TLV_SIZE \
157 (sizeof(struct mrvl_ie_header) \
158 + IEEE80211_MAX_SSID_LEN)
160 static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
162 struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
167 * ssid 4d 4e 54 45 53 54
169 ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
170 ssid_tlv->header.len = cpu_to_le16(ssid_len);
171 memcpy(ssid_tlv->ssid, ssid, ssid_len);
172 return sizeof(ssid_tlv->header) + ssid_len;
177 * Add channel list TLV (section 8.4.2)
179 * Actual channel data comes from priv->wdev->wiphy->channels.
181 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
182 (sizeof(struct mrvl_ie_header) \
183 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
185 static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
186 int last_channel, int active_scan)
188 int chanscanparamsize = sizeof(struct chanscanparamset) *
189 (last_channel - priv->scan_channel);
191 struct mrvl_ie_header *header = (void *) tlv;
194 * TLV-ID CHANLIST 01 01
196 * channel 00 01 00 00 00 64 00
200 * min scan time 00 00
201 * max scan time 64 00
202 * channel 2 00 02 00 00 00 64 00
206 header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
207 header->len = cpu_to_le16(chanscanparamsize);
208 tlv += sizeof(struct mrvl_ie_header);
210 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
212 memset(tlv, 0, chanscanparamsize);
214 while (priv->scan_channel < last_channel) {
215 struct chanscanparamset *param = (void *) tlv;
217 param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
219 priv->scan_req->channels[priv->scan_channel]->hw_value;
221 param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
223 param->chanscanmode.passivescan = 1;
224 param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
226 tlv += sizeof(struct chanscanparamset);
227 priv->scan_channel++;
229 return sizeof(struct mrvl_ie_header) + chanscanparamsize;
236 * The rates are in lbs_bg_rates[], but for the 802.11b
237 * rates the high bit is set. We add this TLV only because
238 * there's a firmware which otherwise doesn't report all
241 #define LBS_MAX_RATES_TLV_SIZE \
242 (sizeof(struct mrvl_ie_header) \
243 + (ARRAY_SIZE(lbs_rates)))
245 /* Adds a TLV with all rates the hardware supports */
246 static int lbs_add_supported_rates_tlv(u8 *tlv)
249 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
254 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
256 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
257 tlv += sizeof(rate_tlv->header);
258 i = lbs_add_rates(tlv);
260 rate_tlv->header.len = cpu_to_le16(i);
261 return sizeof(rate_tlv->header) + i;
264 /* Add common rates from a TLV and return the new end of the TLV */
266 add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
268 int hw, ap, ap_max = ie[1];
271 /* Advance past IE header */
274 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
276 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
277 hw_rate = lbs_rates[hw].bitrate / 5;
278 for (ap = 0; ap < ap_max; ap++) {
279 if (hw_rate == (ie[ap] & 0x7f)) {
281 *nrates = *nrates + 1;
289 * Adds a TLV with all rates the hardware *and* BSS supports.
291 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
293 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
294 const u8 *rates_eid, *ext_rates_eid;
297 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
298 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
301 * 01 00 TLV_TYPE_RATES
305 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
306 tlv += sizeof(rate_tlv->header);
308 /* Add basic rates */
310 tlv = add_ie_rates(tlv, rates_eid, &n);
312 /* Add extended rates, if any */
314 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
316 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
317 /* Fallback: add basic 802.11b rates */
325 rate_tlv->header.len = cpu_to_le16(n);
326 return sizeof(rate_tlv->header) + n;
333 * This is only needed for newer firmware (V9 and up).
335 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
336 sizeof(struct mrvl_ie_auth_type)
338 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
340 struct mrvl_ie_auth_type *auth = (void *) tlv;
343 * 1f 01 TLV_TYPE_AUTH_TYPE
347 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
348 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
349 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
350 return sizeof(*auth);
355 * Add channel (phy ds) TLV
357 #define LBS_MAX_CHANNEL_TLV_SIZE \
358 sizeof(struct mrvl_ie_header)
360 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
362 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
365 * 03 00 TLV_TYPE_PHY_DS
369 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
370 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
371 ds->channel = channel;
377 * Add (empty) CF param TLV of the form:
379 #define LBS_MAX_CF_PARAM_TLV_SIZE \
380 sizeof(struct mrvl_ie_header)
382 static int lbs_add_cf_param_tlv(u8 *tlv)
384 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
391 * 00 00 cfpmaxduration
392 * 00 00 cfpdurationremaining
394 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
395 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
402 #define LBS_MAX_WPA_TLV_SIZE \
403 (sizeof(struct mrvl_ie_header) \
404 + 128 /* TODO: I guessed the size */)
406 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
411 * We need just convert an IE to an TLV. IEs use u8 for the header,
415 * but TLVs use __le16 instead:
422 tlv_len = *tlv++ = *ie++;
426 /* the TLV is two bytes larger than the IE */
430 /***************************************************************************
434 static int lbs_cfg_set_channel(struct wiphy *wiphy,
435 struct net_device *netdev,
436 struct ieee80211_channel *channel,
437 enum nl80211_channel_type channel_type)
439 struct lbs_private *priv = wiphy_priv(wiphy);
442 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
443 channel->center_freq, channel_type);
445 if (channel_type != NL80211_CHAN_NO_HT)
448 ret = lbs_set_channel(priv, channel->hw_value);
451 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
457 /***************************************************************************
462 * When scanning, the firmware doesn't send a nul packet with the power-safe
463 * bit to the AP. So we cannot stay away from our current channel too long,
464 * otherwise we loose data. So take a "nap" while scanning every other
467 #define LBS_SCAN_BEFORE_NAP 4
471 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
472 * which isn't really an RSSI, as it becomes larger when moving away from
473 * the AP. Anyway, we need to convert that into mBm.
475 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
476 ((-(int)rssi + 3)*100)
478 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
479 struct cmd_header *resp)
481 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
489 lbs_deb_enter(LBS_DEB_CFG80211);
491 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
493 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
494 scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
496 if (scanresp->nr_sets == 0) {
502 * The general layout of the scan response is described in chapter
503 * 5.7.1. Basically we have a common part, then any number of BSS
504 * descriptor sections. Finally we have section with the same number
507 * cmd_ds_802_11_scan_rsp
520 * MrvlIEtypes_TsfFimestamp_t
526 pos = scanresp->bssdesc_and_tlvbuffer;
528 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
529 scanresp->bssdescriptsize);
531 tsfdesc = pos + bsssize;
532 tsfsize = 4 + 8 * scanresp->nr_sets;
533 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
535 /* Validity check: we expect a Marvell-Local TLV */
536 i = get_unaligned_le16(tsfdesc);
538 if (i != TLV_TYPE_TSFTIMESTAMP) {
539 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
543 /* Validity check: the TLV holds TSF values with 8 bytes each, so
544 * the size in the TLV must match the nr_sets value */
545 i = get_unaligned_le16(tsfdesc);
547 if (i / 8 != scanresp->nr_sets) {
548 lbs_deb_scan("scan response: invalid number of TSF timestamp "
549 "sets (expected %d got %d)\n", scanresp->nr_sets,
554 for (i = 0; i < scanresp->nr_sets; i++) {
563 const u8 *ssid = NULL;
565 DECLARE_SSID_BUF(ssid_buf);
567 int len = get_unaligned_le16(pos);
575 /* Packet time stamp */
577 /* Beacon interval */
578 intvl = get_unaligned_le16(pos);
581 capa = get_unaligned_le16(pos);
584 /* To find out the channel, we must parse the IEs */
586 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
587 interval, capabilities */
588 ielen = left = len - (6 + 1 + 8 + 2 + 2);
594 if (elen > left || elen == 0) {
595 lbs_deb_scan("scan response: invalid IE fmt\n");
599 if (id == WLAN_EID_DS_PARAMS)
601 if (id == WLAN_EID_SSID) {
609 /* No channel, no luck */
611 struct wiphy *wiphy = priv->wdev->wiphy;
612 int freq = ieee80211_channel_to_frequency(chan_no);
613 struct ieee80211_channel *channel =
614 ieee80211_get_channel(wiphy, freq);
616 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
618 bssid, capa, chan_no,
619 print_ssid(ssid_buf, ssid, ssid_len),
620 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
623 !(channel->flags & IEEE80211_CHAN_DISABLED))
624 cfg80211_inform_bss(wiphy, channel,
625 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
626 capa, intvl, ie, ielen,
627 LBS_SCAN_RSSI_TO_MBM(rssi),
630 lbs_deb_scan("scan response: missing BSS channel IE\n");
637 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
643 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
644 * TLV and a rates TLV. Determine the maximum size of them:
646 #define LBS_SCAN_MAX_CMD_SIZE \
647 (sizeof(struct cmd_ds_802_11_scan) \
648 + LBS_MAX_SSID_TLV_SIZE \
649 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
650 + LBS_MAX_RATES_TLV_SIZE)
653 * Assumes priv->scan_req is initialized and valid
654 * Assumes priv->scan_channel is initialized
656 static void lbs_scan_worker(struct work_struct *work)
658 struct lbs_private *priv =
659 container_of(work, struct lbs_private, scan_work.work);
660 struct cmd_ds_802_11_scan *scan_cmd;
661 u8 *tlv; /* pointer into our current, growing TLV storage area */
663 int running, carrier;
665 lbs_deb_enter(LBS_DEB_SCAN);
667 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
668 if (scan_cmd == NULL)
669 goto out_no_scan_cmd;
671 /* prepare fixed part of scan command */
672 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
674 /* stop network while we're away from our main channel */
675 running = !netif_queue_stopped(priv->dev);
676 carrier = netif_carrier_ok(priv->dev);
678 netif_stop_queue(priv->dev);
680 netif_carrier_off(priv->dev);
682 /* prepare fixed part of scan command */
683 tlv = scan_cmd->tlvbuffer;
686 if (priv->scan_req->n_ssids)
687 tlv += lbs_add_ssid_tlv(tlv,
688 priv->scan_req->ssids[0].ssid,
689 priv->scan_req->ssids[0].ssid_len);
691 /* add channel TLVs */
692 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
693 if (last_channel > priv->scan_req->n_channels)
694 last_channel = priv->scan_req->n_channels;
695 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
696 priv->scan_req->n_ssids);
699 tlv += lbs_add_supported_rates_tlv(tlv);
701 if (priv->scan_channel < priv->scan_req->n_channels) {
702 cancel_delayed_work(&priv->scan_work);
704 queue_delayed_work(priv->work_thread, &priv->scan_work,
705 msecs_to_jiffies(300));
708 /* This is the final data we are about to send */
709 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
710 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
712 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
713 tlv - scan_cmd->tlvbuffer);
715 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
716 le16_to_cpu(scan_cmd->hdr.size),
719 if (priv->scan_channel >= priv->scan_req->n_channels) {
721 if (priv->internal_scan)
722 kfree(priv->scan_req);
724 cfg80211_scan_done(priv->scan_req, false);
726 priv->scan_req = NULL;
727 priv->last_scan = jiffies;
730 /* Restart network */
732 netif_carrier_on(priv->dev);
733 if (running && !priv->tx_pending_len)
734 netif_wake_queue(priv->dev);
738 /* Wake up anything waiting on scan completion */
739 if (priv->scan_req == NULL) {
740 lbs_deb_scan("scan: waking up waiters\n");
741 wake_up_all(&priv->scan_q);
745 lbs_deb_leave(LBS_DEB_SCAN);
748 static void _internal_start_scan(struct lbs_private *priv, bool internal,
749 struct cfg80211_scan_request *request)
751 lbs_deb_enter(LBS_DEB_CFG80211);
753 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
754 request->n_ssids, request->n_channels, request->ie_len);
756 priv->scan_channel = 0;
757 queue_delayed_work(priv->work_thread, &priv->scan_work,
758 msecs_to_jiffies(50));
760 priv->scan_req = request;
761 priv->internal_scan = internal;
763 lbs_deb_leave(LBS_DEB_CFG80211);
766 static int lbs_cfg_scan(struct wiphy *wiphy,
767 struct net_device *dev,
768 struct cfg80211_scan_request *request)
770 struct lbs_private *priv = wiphy_priv(wiphy);
773 lbs_deb_enter(LBS_DEB_CFG80211);
775 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
776 /* old scan request not yet processed */
781 _internal_start_scan(priv, false, request);
783 if (priv->surpriseremoved)
787 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
794 /***************************************************************************
798 void lbs_send_disconnect_notification(struct lbs_private *priv)
800 lbs_deb_enter(LBS_DEB_CFG80211);
802 cfg80211_disconnected(priv->dev,
807 lbs_deb_leave(LBS_DEB_CFG80211);
810 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
812 lbs_deb_enter(LBS_DEB_CFG80211);
814 cfg80211_michael_mic_failure(priv->dev,
816 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
817 NL80211_KEYTYPE_GROUP :
818 NL80211_KEYTYPE_PAIRWISE,
823 lbs_deb_leave(LBS_DEB_CFG80211);
829 /***************************************************************************
835 * This removes all WEP keys
837 static int lbs_remove_wep_keys(struct lbs_private *priv)
839 struct cmd_ds_802_11_set_wep cmd;
842 lbs_deb_enter(LBS_DEB_CFG80211);
844 memset(&cmd, 0, sizeof(cmd));
845 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
846 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
847 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
849 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
851 lbs_deb_leave(LBS_DEB_CFG80211);
858 static int lbs_set_wep_keys(struct lbs_private *priv)
860 struct cmd_ds_802_11_set_wep cmd;
864 lbs_deb_enter(LBS_DEB_CFG80211);
871 * action 02 00 ACT_ADD
873 * type for key 1 01 WEP40
877 * key 1 39 39 39 39 39 00 00 00
878 * 00 00 00 00 00 00 00 00
879 * key 2 00 00 00 00 00 00 00 00
880 * 00 00 00 00 00 00 00 00
881 * key 3 00 00 00 00 00 00 00 00
882 * 00 00 00 00 00 00 00 00
883 * key 4 00 00 00 00 00 00 00 00
885 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
886 priv->wep_key_len[2] || priv->wep_key_len[3]) {
887 /* Only set wep keys if we have at least one of them */
888 memset(&cmd, 0, sizeof(cmd));
889 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
890 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
891 cmd.action = cpu_to_le16(CMD_ACT_ADD);
893 for (i = 0; i < 4; i++) {
894 switch (priv->wep_key_len[i]) {
895 case WLAN_KEY_LEN_WEP40:
896 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
898 case WLAN_KEY_LEN_WEP104:
899 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
905 memcpy(cmd.keymaterial[i], priv->wep_key[i],
906 priv->wep_key_len[i]);
909 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
911 /* Otherwise remove all wep keys */
912 ret = lbs_remove_wep_keys(priv);
915 lbs_deb_leave(LBS_DEB_CFG80211);
921 * Enable/Disable RSN status
923 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
925 struct cmd_ds_802_11_enable_rsn cmd;
928 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
935 * action 01 00 ACT_SET
938 memset(&cmd, 0, sizeof(cmd));
939 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
940 cmd.action = cpu_to_le16(CMD_ACT_SET);
941 cmd.enable = cpu_to_le16(enable);
943 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
945 lbs_deb_leave(LBS_DEB_CFG80211);
951 * Set WPA/WPA key material
954 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
955 * get rid of WEXT, this should go into host.h */
957 struct cmd_key_material {
958 struct cmd_header hdr;
961 struct MrvlIEtype_keyParamSet param;
964 static int lbs_set_key_material(struct lbs_private *priv,
967 u8 *key, u16 key_len)
969 struct cmd_key_material cmd;
972 lbs_deb_enter(LBS_DEB_CFG80211);
975 * Example for WPA (TKIP):
982 * TLV type 00 01 key param
984 * key type 01 00 TKIP
985 * key info 06 00 UNICAST | ENABLED
989 memset(&cmd, 0, sizeof(cmd));
990 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
991 cmd.action = cpu_to_le16(CMD_ACT_SET);
992 cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
993 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
994 cmd.param.keytypeid = cpu_to_le16(key_type);
995 cmd.param.keyinfo = cpu_to_le16(key_info);
996 cmd.param.keylen = cpu_to_le16(key_len);
998 memcpy(cmd.param.key, key, key_len);
1000 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
1002 lbs_deb_leave(LBS_DEB_CFG80211);
1008 * Sets the auth type (open, shared, etc) in the firmware. That
1009 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
1010 * command doesn't send an authentication frame at all, it just
1011 * stores the auth_type.
1013 static int lbs_set_authtype(struct lbs_private *priv,
1014 struct cfg80211_connect_params *sme)
1016 struct cmd_ds_802_11_authenticate cmd;
1019 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
1026 * BSS id 00 13 19 80 da 30
1028 * reserved 00 00 00 00 00 00 00 00 00 00
1030 memset(&cmd, 0, sizeof(cmd));
1031 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1033 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
1034 /* convert auth_type */
1035 ret = lbs_auth_to_authtype(sme->auth_type);
1040 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
1043 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1049 * Create association request
1051 #define LBS_ASSOC_MAX_CMD_SIZE \
1052 (sizeof(struct cmd_ds_802_11_associate) \
1053 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1054 + LBS_MAX_SSID_TLV_SIZE \
1055 + LBS_MAX_CHANNEL_TLV_SIZE \
1056 + LBS_MAX_CF_PARAM_TLV_SIZE \
1057 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1058 + LBS_MAX_WPA_TLV_SIZE)
1060 static int lbs_associate(struct lbs_private *priv,
1061 struct cfg80211_bss *bss,
1062 struct cfg80211_connect_params *sme)
1064 struct cmd_ds_802_11_associate_response *resp;
1065 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
1068 size_t len, resp_ie_len;
1071 u8 *pos = &(cmd->iebuf[0]);
1074 lbs_deb_enter(LBS_DEB_CFG80211);
1086 * BSS id 00 13 19 80 da 30
1087 * capabilities 11 00
1088 * listen interval 0a 00
1089 * beacon interval 00 00
1091 * TLVs xx (up to 512 bytes)
1093 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1095 /* Fill in static fields */
1096 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1097 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1098 cmd->capability = cpu_to_le16(bss->capability);
1101 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1103 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1105 lbs_deb_assoc("no SSID\n");
1107 /* add DS param TLV */
1109 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1111 lbs_deb_assoc("no channel\n");
1113 /* add (empty) CF param TLV */
1114 pos += lbs_add_cf_param_tlv(pos);
1117 tmp = pos + 4; /* skip Marvell IE header */
1118 pos += lbs_add_common_rates_tlv(pos, bss);
1119 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1121 /* add auth type TLV */
1122 if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
1123 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1125 /* add WPA/WPA2 TLV */
1126 if (sme->ie && sme->ie_len)
1127 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1129 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1130 (u16)(pos - (u8 *) &cmd->iebuf);
1131 cmd->hdr.size = cpu_to_le16(len);
1133 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
1134 le16_to_cpu(cmd->hdr.size));
1136 /* store for later use */
1137 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1139 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1143 /* generate connect message to cfg80211 */
1145 resp = (void *) cmd; /* recast for easier field access */
1146 status = le16_to_cpu(resp->statuscode);
1148 /* Older FW versions map the IEEE 802.11 Status Code in the association
1149 * response to the following values returned in resp->statuscode:
1151 * IEEE Status Code Marvell Status Code
1152 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1153 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1154 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1155 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1156 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1157 * others -> 0x0003 ASSOC_RESULT_REFUSED
1159 * Other response codes:
1160 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1161 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1162 * association response from the AP)
1164 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1169 lbs_deb_assoc("invalid association parameters\n");
1170 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1173 lbs_deb_assoc("timer expired while waiting for AP\n");
1174 status = WLAN_STATUS_AUTH_TIMEOUT;
1177 lbs_deb_assoc("association refused by AP\n");
1178 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1181 lbs_deb_assoc("authentication refused by AP\n");
1182 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1185 lbs_deb_assoc("association failure %d\n", status);
1186 /* v5 OLPC firmware does return the AP status code if
1187 * it's not one of the values above. Let that through.
1193 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1194 "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
1195 le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
1197 resp_ie_len = le16_to_cpu(resp->hdr.size)
1200 cfg80211_connect_result(priv->dev,
1202 sme->ie, sme->ie_len,
1203 resp->iebuf, resp_ie_len,
1208 /* TODO: get rid of priv->connect_status */
1209 priv->connect_status = LBS_CONNECTED;
1210 netif_carrier_on(priv->dev);
1211 if (!priv->tx_pending_len)
1212 netif_tx_wake_all_queues(priv->dev);
1216 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1220 static struct cfg80211_scan_request *
1221 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
1223 struct cfg80211_scan_request *creq = NULL;
1224 int i, n_channels = 0;
1225 enum ieee80211_band band;
1227 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1228 if (wiphy->bands[band])
1229 n_channels += wiphy->bands[band]->n_channels;
1232 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1233 n_channels * sizeof(void *),
1238 /* SSIDs come after channels */
1239 creq->ssids = (void *)&creq->channels[n_channels];
1240 creq->n_channels = n_channels;
1243 /* Scan all available channels */
1245 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1248 if (!wiphy->bands[band])
1251 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
1252 /* ignore disabled channels */
1253 if (wiphy->bands[band]->channels[j].flags &
1254 IEEE80211_CHAN_DISABLED)
1257 creq->channels[i] = &wiphy->bands[band]->channels[j];
1262 /* Set real number of channels specified in creq->channels[] */
1263 creq->n_channels = i;
1265 /* Scan for the SSID we're going to connect to */
1266 memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
1267 creq->ssids[0].ssid_len = sme->ssid_len;
1269 /* No channels found... */
1277 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1278 struct cfg80211_connect_params *sme)
1280 struct lbs_private *priv = wiphy_priv(wiphy);
1281 struct cfg80211_bss *bss = NULL;
1283 u8 preamble = RADIO_PREAMBLE_SHORT;
1285 lbs_deb_enter(LBS_DEB_CFG80211);
1288 /* Run a scan if one isn't in-progress already and if the last
1289 * scan was done more than 2 seconds ago.
1291 if (priv->scan_req == NULL &&
1292 time_after(jiffies, priv->last_scan + (2 * HZ))) {
1293 struct cfg80211_scan_request *creq;
1295 creq = _new_connect_scan_req(wiphy, sme);
1301 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1302 _internal_start_scan(priv, true, creq);
1305 /* Wait for any in-progress scan to complete */
1306 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1307 wait_event_interruptible_timeout(priv->scan_q,
1308 (priv->scan_req == NULL),
1310 lbs_deb_assoc("assoc: scanning competed\n");
1313 /* Find the BSS we want using available scan results */
1314 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1315 sme->ssid, sme->ssid_len,
1316 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1318 lbs_pr_err("assoc: bss %pM not in scan results\n",
1323 lbs_deb_assoc("trying %pM\n", bss->bssid);
1324 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1325 sme->crypto.cipher_group,
1326 sme->key_idx, sme->key_len);
1328 /* As this is a new connection, clear locally stored WEP keys */
1329 priv->wep_tx_key = 0;
1330 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1331 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1333 /* set/remove WEP keys */
1334 switch (sme->crypto.cipher_group) {
1335 case WLAN_CIPHER_SUITE_WEP40:
1336 case WLAN_CIPHER_SUITE_WEP104:
1337 /* Store provided WEP keys in priv-> */
1338 priv->wep_tx_key = sme->key_idx;
1339 priv->wep_key_len[sme->key_idx] = sme->key_len;
1340 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1341 /* Set WEP keys and WEP mode */
1342 lbs_set_wep_keys(priv);
1343 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1344 lbs_set_mac_control(priv);
1345 /* No RSN mode for WEP */
1346 lbs_enable_rsn(priv, 0);
1348 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1350 * If we don't have no WEP, no WPA and no WPA2,
1351 * we remove all keys like in the WPA/WPA2 setup,
1352 * we just don't set RSN.
1354 * Therefore: fall-throught
1356 case WLAN_CIPHER_SUITE_TKIP:
1357 case WLAN_CIPHER_SUITE_CCMP:
1358 /* Remove WEP keys and WEP mode */
1359 lbs_remove_wep_keys(priv);
1360 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1361 lbs_set_mac_control(priv);
1363 /* clear the WPA/WPA2 keys */
1364 lbs_set_key_material(priv,
1365 KEY_TYPE_ID_WEP, /* doesn't matter */
1366 KEY_INFO_WPA_UNICAST,
1368 lbs_set_key_material(priv,
1369 KEY_TYPE_ID_WEP, /* doesn't matter */
1372 /* RSN mode for WPA/WPA2 */
1373 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1376 lbs_pr_err("unsupported cipher group 0x%x\n",
1377 sme->crypto.cipher_group);
1382 lbs_set_authtype(priv, sme);
1383 lbs_set_radio(priv, preamble, 1);
1385 /* Do the actual association */
1386 ret = lbs_associate(priv, bss, sme);
1390 cfg80211_put_bss(bss);
1391 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1395 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1398 struct lbs_private *priv = wiphy_priv(wiphy);
1399 struct cmd_ds_802_11_deauthenticate cmd;
1401 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1403 /* store for lbs_cfg_ret_disconnect() */
1404 priv->disassoc_reason = reason_code;
1406 memset(&cmd, 0, sizeof(cmd));
1407 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1408 /* Mildly ugly to use a locally store my own BSSID ... */
1409 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1410 cmd.reasoncode = cpu_to_le16(reason_code);
1412 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1415 cfg80211_disconnected(priv->dev,
1416 priv->disassoc_reason,
1419 priv->connect_status = LBS_DISCONNECTED;
1425 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1426 struct net_device *netdev,
1429 struct lbs_private *priv = wiphy_priv(wiphy);
1431 lbs_deb_enter(LBS_DEB_CFG80211);
1433 if (key_index != priv->wep_tx_key) {
1434 lbs_deb_assoc("set_default_key: to %d\n", key_index);
1435 priv->wep_tx_key = key_index;
1436 lbs_set_wep_keys(priv);
1443 static int lbs_cfg_add_key(struct wiphy *wiphy, struct net_device *netdev,
1444 u8 idx, bool pairwise, const u8 *mac_addr,
1445 struct key_params *params)
1447 struct lbs_private *priv = wiphy_priv(wiphy);
1452 lbs_deb_enter(LBS_DEB_CFG80211);
1454 lbs_deb_assoc("add_key: cipher 0x%x, mac_addr %pM\n",
1455 params->cipher, mac_addr);
1456 lbs_deb_assoc("add_key: key index %d, key len %d\n",
1457 idx, params->key_len);
1458 if (params->key_len)
1459 lbs_deb_hex(LBS_DEB_CFG80211, "KEY",
1460 params->key, params->key_len);
1462 lbs_deb_assoc("add_key: seq len %d\n", params->seq_len);
1463 if (params->seq_len)
1464 lbs_deb_hex(LBS_DEB_CFG80211, "SEQ",
1465 params->seq, params->seq_len);
1467 switch (params->cipher) {
1468 case WLAN_CIPHER_SUITE_WEP40:
1469 case WLAN_CIPHER_SUITE_WEP104:
1470 /* actually compare if something has changed ... */
1471 if ((priv->wep_key_len[idx] != params->key_len) ||
1472 memcmp(priv->wep_key[idx],
1473 params->key, params->key_len) != 0) {
1474 priv->wep_key_len[idx] = params->key_len;
1475 memcpy(priv->wep_key[idx],
1476 params->key, params->key_len);
1477 lbs_set_wep_keys(priv);
1480 case WLAN_CIPHER_SUITE_TKIP:
1481 case WLAN_CIPHER_SUITE_CCMP:
1482 key_info = KEY_INFO_WPA_ENABLED | ((idx == 0)
1483 ? KEY_INFO_WPA_UNICAST
1484 : KEY_INFO_WPA_MCAST);
1485 key_type = (params->cipher == WLAN_CIPHER_SUITE_TKIP)
1488 lbs_set_key_material(priv,
1491 params->key, params->key_len);
1494 lbs_pr_err("unhandled cipher 0x%x\n", params->cipher);
1503 static int lbs_cfg_del_key(struct wiphy *wiphy, struct net_device *netdev,
1504 u8 key_index, bool pairwise, const u8 *mac_addr)
1507 lbs_deb_enter(LBS_DEB_CFG80211);
1509 lbs_deb_assoc("del_key: key_idx %d, mac_addr %pM\n",
1510 key_index, mac_addr);
1513 struct lbs_private *priv = wiphy_priv(wiphy);
1515 * I think can keep this a NO-OP, because:
1517 * - we clear all keys whenever we do lbs_cfg_connect() anyway
1518 * - neither "iw" nor "wpa_supplicant" won't call this during
1519 * an ongoing connection
1520 * - TODO: but I have to check if this is still true when
1521 * I set the AP to periodic re-keying
1522 * - we've not kzallec() something when we've added a key at
1523 * lbs_cfg_connect() or lbs_cfg_add_key().
1525 * This causes lbs_cfg_del_key() only called at disconnect time,
1526 * where we'd just waste time deleting a key that is not going
1527 * to be used anyway.
1529 if (key_index < 3 && priv->wep_key_len[key_index]) {
1530 priv->wep_key_len[key_index] = 0;
1531 lbs_set_wep_keys(priv);
1539 /***************************************************************************
1543 static int lbs_cfg_get_station(struct wiphy *wiphy, struct net_device *dev,
1544 u8 *mac, struct station_info *sinfo)
1546 struct lbs_private *priv = wiphy_priv(wiphy);
1551 lbs_deb_enter(LBS_DEB_CFG80211);
1553 sinfo->filled |= STATION_INFO_TX_BYTES |
1554 STATION_INFO_TX_PACKETS |
1555 STATION_INFO_RX_BYTES |
1556 STATION_INFO_RX_PACKETS;
1557 sinfo->tx_bytes = priv->dev->stats.tx_bytes;
1558 sinfo->tx_packets = priv->dev->stats.tx_packets;
1559 sinfo->rx_bytes = priv->dev->stats.rx_bytes;
1560 sinfo->rx_packets = priv->dev->stats.rx_packets;
1562 /* Get current RSSI */
1563 ret = lbs_get_rssi(priv, &signal, &noise);
1565 sinfo->signal = signal;
1566 sinfo->filled |= STATION_INFO_SIGNAL;
1569 /* Convert priv->cur_rate from hw_value to NL80211 value */
1570 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
1571 if (priv->cur_rate == lbs_rates[i].hw_value) {
1572 sinfo->txrate.legacy = lbs_rates[i].bitrate;
1573 sinfo->filled |= STATION_INFO_TX_BITRATE;
1584 /***************************************************************************
1585 * "Site survey", here just current channel and noise level
1588 static int lbs_get_survey(struct wiphy *wiphy, struct net_device *dev,
1589 int idx, struct survey_info *survey)
1591 struct lbs_private *priv = wiphy_priv(wiphy);
1598 lbs_deb_enter(LBS_DEB_CFG80211);
1600 survey->channel = ieee80211_get_channel(wiphy,
1601 ieee80211_channel_to_frequency(priv->channel));
1603 ret = lbs_get_rssi(priv, &signal, &noise);
1605 survey->filled = SURVEY_INFO_NOISE_DBM;
1606 survey->noise = noise;
1609 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1616 /***************************************************************************
1620 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1621 enum nl80211_iftype type, u32 *flags,
1622 struct vif_params *params)
1624 struct lbs_private *priv = wiphy_priv(wiphy);
1627 lbs_deb_enter(LBS_DEB_CFG80211);
1630 case NL80211_IFTYPE_MONITOR:
1631 ret = lbs_set_monitor_mode(priv, 1);
1633 case NL80211_IFTYPE_STATION:
1634 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1635 ret = lbs_set_monitor_mode(priv, 0);
1637 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1639 case NL80211_IFTYPE_ADHOC:
1640 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1641 ret = lbs_set_monitor_mode(priv, 0);
1643 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1650 priv->wdev->iftype = type;
1652 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1658 /***************************************************************************
1662 /* The firmware needs the following bits masked out of the beacon-derived
1663 * capability field when associating/joining to a BSS:
1664 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1666 #define CAPINFO_MASK (~(0xda00))
1669 static void lbs_join_post(struct lbs_private *priv,
1670 struct cfg80211_ibss_params *params,
1671 u8 *bssid, u16 capability)
1673 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1674 2 + 4 + /* basic rates */
1675 2 + 1 + /* DS parameter */
1677 2 + 8]; /* extended rates */
1680 lbs_deb_enter(LBS_DEB_CFG80211);
1683 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1684 * the real IE from the firmware. So we fabricate a fake IE based on
1685 * what the firmware actually sends (sniffed with wireshark).
1688 *fake++ = WLAN_EID_SSID;
1689 *fake++ = params->ssid_len;
1690 memcpy(fake, params->ssid, params->ssid_len);
1691 fake += params->ssid_len;
1692 /* Fake supported basic rates IE */
1693 *fake++ = WLAN_EID_SUPP_RATES;
1699 /* Fake DS channel IE */
1700 *fake++ = WLAN_EID_DS_PARAMS;
1702 *fake++ = params->channel->hw_value;
1703 /* Fake IBSS params IE */
1704 *fake++ = WLAN_EID_IBSS_PARAMS;
1706 *fake++ = 0; /* ATIM=0 */
1708 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1709 * but I don't know how this could be checked */
1710 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1720 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1722 cfg80211_inform_bss(priv->wdev->wiphy,
1727 params->beacon_interval,
1728 fake_ie, fake - fake_ie,
1731 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1732 priv->wdev->ssid_len = params->ssid_len;
1734 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1736 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1737 priv->connect_status = LBS_CONNECTED;
1738 netif_carrier_on(priv->dev);
1739 if (!priv->tx_pending_len)
1740 netif_wake_queue(priv->dev);
1742 lbs_deb_leave(LBS_DEB_CFG80211);
1745 static int lbs_ibss_join_existing(struct lbs_private *priv,
1746 struct cfg80211_ibss_params *params,
1747 struct cfg80211_bss *bss)
1749 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1750 struct cmd_ds_802_11_ad_hoc_join cmd;
1751 u8 preamble = RADIO_PREAMBLE_SHORT;
1754 lbs_deb_enter(LBS_DEB_CFG80211);
1756 /* TODO: set preamble based on scan result */
1757 ret = lbs_set_radio(priv, preamble, 1);
1762 * Example CMD_802_11_AD_HOC_JOIN command:
1764 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1768 * bssid 02 27 27 97 2f 96
1769 * ssid 49 42 53 53 00 00 00 00
1770 * 00 00 00 00 00 00 00 00
1771 * 00 00 00 00 00 00 00 00
1772 * 00 00 00 00 00 00 00 00
1773 * type 02 CMD_BSS_TYPE_IBSS
1774 * beacon period 64 00
1776 * timestamp 00 00 00 00 00 00 00 00
1777 * localtime 00 00 00 00 00 00 00 00
1781 * reserveed 00 00 00 00
1784 * IE IBSS atim 00 00
1785 * reserved 00 00 00 00
1787 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1788 * fail timeout ff 00
1791 memset(&cmd, 0, sizeof(cmd));
1792 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1794 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1795 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1796 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1797 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1798 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1799 cmd.bss.ds.header.len = 1;
1800 cmd.bss.ds.channel = params->channel->hw_value;
1801 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1802 cmd.bss.ibss.header.len = 2;
1803 cmd.bss.ibss.atimwindow = 0;
1804 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1806 /* set rates to the intersection of our rates and the rates in the
1809 lbs_add_rates(cmd.bss.rates);
1812 u8 rates_max = rates_eid[1];
1813 u8 *rates = cmd.bss.rates;
1814 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1815 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1816 for (i = 0; i < rates_max; i++) {
1817 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1818 u8 rate = rates_eid[i+2];
1819 if (rate == 0x02 || rate == 0x04 ||
1820 rate == 0x0b || rate == 0x16)
1828 /* Only v8 and below support setting this */
1829 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1830 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1831 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1833 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1838 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1846 lbs_join_post(priv, params, bss->bssid, bss->capability);
1849 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1855 static int lbs_ibss_start_new(struct lbs_private *priv,
1856 struct cfg80211_ibss_params *params)
1858 struct cmd_ds_802_11_ad_hoc_start cmd;
1859 struct cmd_ds_802_11_ad_hoc_result *resp =
1860 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1861 u8 preamble = RADIO_PREAMBLE_SHORT;
1865 lbs_deb_enter(LBS_DEB_CFG80211);
1867 ret = lbs_set_radio(priv, preamble, 1);
1872 * Example CMD_802_11_AD_HOC_START command:
1874 * command 2b 00 CMD_802_11_AD_HOC_START
1878 * ssid 54 45 53 54 00 00 00 00
1879 * 00 00 00 00 00 00 00 00
1880 * 00 00 00 00 00 00 00 00
1881 * 00 00 00 00 00 00 00 00
1883 * beacon period 64 00
1887 * IE IBSS atim 00 00
1888 * reserved 00 00 00 00
1892 * reserved 00 00 00 00
1895 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1896 * 0c 12 18 24 30 48 60 6c
1899 memset(&cmd, 0, sizeof(cmd));
1900 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1901 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1902 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1903 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1904 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1905 cmd.ibss.header.len = 2;
1906 cmd.ibss.atimwindow = 0;
1907 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1908 cmd.ds.header.len = 1;
1909 cmd.ds.channel = params->channel->hw_value;
1910 /* Only v8 and below support setting probe delay */
1911 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1912 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1913 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1914 capability = WLAN_CAPABILITY_IBSS;
1915 cmd.capability = cpu_to_le16(capability);
1916 lbs_add_rates(cmd.rates);
1919 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1924 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1931 * bssid 02 2b 7b 0f 86 0e
1933 lbs_join_post(priv, params, resp->bssid, capability);
1936 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1941 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1942 struct cfg80211_ibss_params *params)
1944 struct lbs_private *priv = wiphy_priv(wiphy);
1946 struct cfg80211_bss *bss;
1947 DECLARE_SSID_BUF(ssid_buf);
1949 lbs_deb_enter(LBS_DEB_CFG80211);
1951 if (!params->channel) {
1956 ret = lbs_set_channel(priv, params->channel->hw_value);
1960 /* Search if someone is beaconing. This assumes that the
1961 * bss list is populated already */
1962 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1963 params->ssid, params->ssid_len,
1964 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1967 ret = lbs_ibss_join_existing(priv, params, bss);
1968 cfg80211_put_bss(bss);
1970 ret = lbs_ibss_start_new(priv, params);
1974 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1979 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1981 struct lbs_private *priv = wiphy_priv(wiphy);
1982 struct cmd_ds_802_11_ad_hoc_stop cmd;
1985 lbs_deb_enter(LBS_DEB_CFG80211);
1987 memset(&cmd, 0, sizeof(cmd));
1988 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1989 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1991 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1992 lbs_mac_event_disconnected(priv);
1994 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2001 /***************************************************************************
2005 static struct cfg80211_ops lbs_cfg80211_ops = {
2006 .set_channel = lbs_cfg_set_channel,
2007 .scan = lbs_cfg_scan,
2008 .connect = lbs_cfg_connect,
2009 .disconnect = lbs_cfg_disconnect,
2010 .add_key = lbs_cfg_add_key,
2011 .del_key = lbs_cfg_del_key,
2012 .set_default_key = lbs_cfg_set_default_key,
2013 .get_station = lbs_cfg_get_station,
2014 .dump_survey = lbs_get_survey,
2015 .change_virtual_intf = lbs_change_intf,
2016 .join_ibss = lbs_join_ibss,
2017 .leave_ibss = lbs_leave_ibss,
2022 * At this time lbs_private *priv doesn't even exist, so we just allocate
2023 * memory and don't initialize the wiphy further. This is postponed until we
2024 * can talk to the firmware and happens at registration time in
2025 * lbs_cfg_wiphy_register().
2027 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
2030 struct wireless_dev *wdev;
2032 lbs_deb_enter(LBS_DEB_CFG80211);
2034 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2036 dev_err(dev, "cannot allocate wireless device\n");
2037 return ERR_PTR(-ENOMEM);
2040 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
2042 dev_err(dev, "cannot allocate wiphy\n");
2047 lbs_deb_leave(LBS_DEB_CFG80211);
2052 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2053 return ERR_PTR(ret);
2057 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
2059 struct region_code_mapping {
2064 /* Section 5.17.2 */
2065 static struct region_code_mapping regmap[] = {
2066 {"US ", 0x10}, /* US FCC */
2067 {"CA ", 0x20}, /* Canada */
2068 {"EU ", 0x30}, /* ETSI */
2069 {"ES ", 0x31}, /* Spain */
2070 {"FR ", 0x32}, /* France */
2071 {"JP ", 0x40}, /* Japan */
2075 lbs_deb_enter(LBS_DEB_CFG80211);
2077 for (i = 0; i < ARRAY_SIZE(regmap); i++)
2078 if (regmap[i].code == priv->regioncode) {
2079 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
2083 lbs_deb_leave(LBS_DEB_CFG80211);
2088 * This function get's called after lbs_setup_firmware() determined the
2089 * firmware capabities. So we can setup the wiphy according to our
2090 * hardware/firmware.
2092 int lbs_cfg_register(struct lbs_private *priv)
2094 struct wireless_dev *wdev = priv->wdev;
2097 lbs_deb_enter(LBS_DEB_CFG80211);
2099 wdev->wiphy->max_scan_ssids = 1;
2100 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2102 wdev->wiphy->interface_modes =
2103 BIT(NL80211_IFTYPE_STATION) |
2104 BIT(NL80211_IFTYPE_ADHOC);
2105 if (lbs_rtap_supported(priv))
2106 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
2108 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
2111 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2112 * never seen a firmware without WPA
2114 wdev->wiphy->cipher_suites = cipher_suites;
2115 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2116 wdev->wiphy->reg_notifier = lbs_reg_notifier;
2118 ret = wiphy_register(wdev->wiphy);
2120 lbs_pr_err("cannot register wiphy device\n");
2122 priv->wiphy_registered = true;
2124 ret = register_netdev(priv->dev);
2126 lbs_pr_err("cannot register network device\n");
2128 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2130 lbs_cfg_set_regulatory_hint(priv);
2132 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2136 int lbs_reg_notifier(struct wiphy *wiphy,
2137 struct regulatory_request *request)
2139 struct lbs_private *priv = wiphy_priv(wiphy);
2142 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
2143 "callback for domain %c%c\n", request->alpha2[0],
2144 request->alpha2[1]);
2146 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
2148 lbs_deb_leave(LBS_DEB_CFG80211);
2152 void lbs_scan_deinit(struct lbs_private *priv)
2154 lbs_deb_enter(LBS_DEB_CFG80211);
2155 cancel_delayed_work_sync(&priv->scan_work);
2159 void lbs_cfg_free(struct lbs_private *priv)
2161 struct wireless_dev *wdev = priv->wdev;
2163 lbs_deb_enter(LBS_DEB_CFG80211);
2168 if (priv->wiphy_registered)
2169 wiphy_unregister(wdev->wiphy);
2172 wiphy_free(wdev->wiphy);