2 * Implement cfg80211 ("iw") support.
4 * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
9 #include <linux/sched.h>
10 #include <linux/wait.h>
11 #include <linux/slab.h>
12 #include <linux/ieee80211.h>
13 #include <net/cfg80211.h>
14 #include <asm/unaligned.h>
21 #define CHAN2G(_channel, _freq, _flags) { \
22 .band = IEEE80211_BAND_2GHZ, \
23 .center_freq = (_freq), \
24 .hw_value = (_channel), \
26 .max_antenna_gain = 0, \
30 static struct ieee80211_channel lbs_2ghz_channels[] = {
47 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
49 .hw_value = (_hw_value), \
54 /* Table 6 in section 3.2.1.1 */
55 static struct ieee80211_rate lbs_rates[] = {
56 RATETAB_ENT(10, 0, 0),
57 RATETAB_ENT(20, 1, 0),
58 RATETAB_ENT(55, 2, 0),
59 RATETAB_ENT(110, 3, 0),
60 RATETAB_ENT(60, 9, 0),
61 RATETAB_ENT(90, 6, 0),
62 RATETAB_ENT(120, 7, 0),
63 RATETAB_ENT(180, 8, 0),
64 RATETAB_ENT(240, 9, 0),
65 RATETAB_ENT(360, 10, 0),
66 RATETAB_ENT(480, 11, 0),
67 RATETAB_ENT(540, 12, 0),
70 static struct ieee80211_supported_band lbs_band_2ghz = {
71 .channels = lbs_2ghz_channels,
72 .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
73 .bitrates = lbs_rates,
74 .n_bitrates = ARRAY_SIZE(lbs_rates),
78 static const u32 cipher_suites[] = {
79 WLAN_CIPHER_SUITE_WEP40,
80 WLAN_CIPHER_SUITE_WEP104,
81 WLAN_CIPHER_SUITE_TKIP,
82 WLAN_CIPHER_SUITE_CCMP,
85 /* Time to stay on the channel */
86 #define LBS_DWELL_PASSIVE 100
87 #define LBS_DWELL_ACTIVE 40
90 /***************************************************************************
91 * Misc utility functions
93 * TLVs are Marvell specific. They are very similar to IEs, they have the
94 * same structure: type, length, data*. The only difference: for IEs, the
95 * type and length are u8, but for TLVs they're __le16.
99 * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
100 * in the firmware spec
102 static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
107 case NL80211_AUTHTYPE_OPEN_SYSTEM:
108 case NL80211_AUTHTYPE_SHARED_KEY:
111 case NL80211_AUTHTYPE_AUTOMATIC:
112 ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
114 case NL80211_AUTHTYPE_NETWORK_EAP:
118 /* silence compiler */
125 /* Various firmware commands need the list of supported rates, but with
126 the hight-bit set for basic rates */
127 static int lbs_add_rates(u8 *rates)
131 for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
132 u8 rate = lbs_rates[i].bitrate / 5;
133 if (rate == 0x02 || rate == 0x04 ||
134 rate == 0x0b || rate == 0x16)
138 return ARRAY_SIZE(lbs_rates);
142 /***************************************************************************
143 * TLV utility functions
145 * TLVs are Marvell specific. They are very similar to IEs, they have the
146 * same structure: type, length, data*. The only difference: for IEs, the
147 * type and length are u8, but for TLVs they're __le16.
154 #define LBS_MAX_SSID_TLV_SIZE \
155 (sizeof(struct mrvl_ie_header) \
156 + IEEE80211_MAX_SSID_LEN)
158 static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
160 struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
165 * ssid 4d 4e 54 45 53 54
167 ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
168 ssid_tlv->header.len = cpu_to_le16(ssid_len);
169 memcpy(ssid_tlv->ssid, ssid, ssid_len);
170 return sizeof(ssid_tlv->header) + ssid_len;
175 * Add channel list TLV (section 8.4.2)
177 * Actual channel data comes from priv->wdev->wiphy->channels.
179 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
180 (sizeof(struct mrvl_ie_header) \
181 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
183 static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
184 int last_channel, int active_scan)
186 int chanscanparamsize = sizeof(struct chanscanparamset) *
187 (last_channel - priv->scan_channel);
189 struct mrvl_ie_header *header = (void *) tlv;
192 * TLV-ID CHANLIST 01 01
194 * channel 00 01 00 00 00 64 00
198 * min scan time 00 00
199 * max scan time 64 00
200 * channel 2 00 02 00 00 00 64 00
204 header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
205 header->len = cpu_to_le16(chanscanparamsize);
206 tlv += sizeof(struct mrvl_ie_header);
208 /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
210 memset(tlv, 0, chanscanparamsize);
212 while (priv->scan_channel < last_channel) {
213 struct chanscanparamset *param = (void *) tlv;
215 param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
217 priv->scan_req->channels[priv->scan_channel]->hw_value;
219 param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
221 param->chanscanmode.passivescan = 1;
222 param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
224 tlv += sizeof(struct chanscanparamset);
225 priv->scan_channel++;
227 return sizeof(struct mrvl_ie_header) + chanscanparamsize;
234 * The rates are in lbs_bg_rates[], but for the 802.11b
235 * rates the high bit is set. We add this TLV only because
236 * there's a firmware which otherwise doesn't report all
239 #define LBS_MAX_RATES_TLV_SIZE \
240 (sizeof(struct mrvl_ie_header) \
241 + (ARRAY_SIZE(lbs_rates)))
243 /* Adds a TLV with all rates the hardware supports */
244 static int lbs_add_supported_rates_tlv(u8 *tlv)
247 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
252 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c
254 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
255 tlv += sizeof(rate_tlv->header);
256 i = lbs_add_rates(tlv);
258 rate_tlv->header.len = cpu_to_le16(i);
259 return sizeof(rate_tlv->header) + i;
262 /* Add common rates from a TLV and return the new end of the TLV */
264 add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
266 int hw, ap, ap_max = ie[1];
269 /* Advance past IE header */
272 lbs_deb_hex(LBS_DEB_ASSOC, "AP IE Rates", (u8 *) ie, ap_max);
274 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
275 hw_rate = lbs_rates[hw].bitrate / 5;
276 for (ap = 0; ap < ap_max; ap++) {
277 if (hw_rate == (ie[ap] & 0x7f)) {
279 *nrates = *nrates + 1;
287 * Adds a TLV with all rates the hardware *and* BSS supports.
289 static int lbs_add_common_rates_tlv(u8 *tlv, struct cfg80211_bss *bss)
291 struct mrvl_ie_rates_param_set *rate_tlv = (void *)tlv;
292 const u8 *rates_eid, *ext_rates_eid;
295 rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
296 ext_rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
299 * 01 00 TLV_TYPE_RATES
303 rate_tlv->header.type = cpu_to_le16(TLV_TYPE_RATES);
304 tlv += sizeof(rate_tlv->header);
306 /* Add basic rates */
308 tlv = add_ie_rates(tlv, rates_eid, &n);
310 /* Add extended rates, if any */
312 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
314 lbs_deb_assoc("assoc: bss had no basic rate IE\n");
315 /* Fallback: add basic 802.11b rates */
323 rate_tlv->header.len = cpu_to_le16(n);
324 return sizeof(rate_tlv->header) + n;
331 * This is only needed for newer firmware (V9 and up).
333 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
334 sizeof(struct mrvl_ie_auth_type)
336 static int lbs_add_auth_type_tlv(u8 *tlv, enum nl80211_auth_type auth_type)
338 struct mrvl_ie_auth_type *auth = (void *) tlv;
341 * 1f 01 TLV_TYPE_AUTH_TYPE
345 auth->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
346 auth->header.len = cpu_to_le16(sizeof(*auth)-sizeof(auth->header));
347 auth->auth = cpu_to_le16(lbs_auth_to_authtype(auth_type));
348 return sizeof(*auth);
353 * Add channel (phy ds) TLV
355 #define LBS_MAX_CHANNEL_TLV_SIZE \
356 sizeof(struct mrvl_ie_header)
358 static int lbs_add_channel_tlv(u8 *tlv, u8 channel)
360 struct mrvl_ie_ds_param_set *ds = (void *) tlv;
363 * 03 00 TLV_TYPE_PHY_DS
367 ds->header.type = cpu_to_le16(TLV_TYPE_PHY_DS);
368 ds->header.len = cpu_to_le16(sizeof(*ds)-sizeof(ds->header));
369 ds->channel = channel;
375 * Add (empty) CF param TLV of the form:
377 #define LBS_MAX_CF_PARAM_TLV_SIZE \
378 sizeof(struct mrvl_ie_header)
380 static int lbs_add_cf_param_tlv(u8 *tlv)
382 struct mrvl_ie_cf_param_set *cf = (void *)tlv;
389 * 00 00 cfpmaxduration
390 * 00 00 cfpdurationremaining
392 cf->header.type = cpu_to_le16(TLV_TYPE_CF);
393 cf->header.len = cpu_to_le16(sizeof(*cf)-sizeof(cf->header));
400 #define LBS_MAX_WPA_TLV_SIZE \
401 (sizeof(struct mrvl_ie_header) \
402 + 128 /* TODO: I guessed the size */)
404 static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
409 * We need just convert an IE to an TLV. IEs use u8 for the header,
413 * but TLVs use __le16 instead:
420 tlv_len = *tlv++ = *ie++;
424 /* the TLV is two bytes larger than the IE */
428 /***************************************************************************
432 static int lbs_cfg_set_channel(struct wiphy *wiphy,
433 struct net_device *netdev,
434 struct ieee80211_channel *channel,
435 enum nl80211_channel_type channel_type)
437 struct lbs_private *priv = wiphy_priv(wiphy);
440 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
441 channel->center_freq, channel_type);
443 if (channel_type != NL80211_CHAN_NO_HT)
446 ret = lbs_set_channel(priv, channel->hw_value);
449 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
455 /***************************************************************************
460 * When scanning, the firmware doesn't send a nul packet with the power-safe
461 * bit to the AP. So we cannot stay away from our current channel too long,
462 * otherwise we loose data. So take a "nap" while scanning every other
465 #define LBS_SCAN_BEFORE_NAP 4
469 * When the firmware reports back a scan-result, it gives us an "u8 rssi",
470 * which isn't really an RSSI, as it becomes larger when moving away from
471 * the AP. Anyway, we need to convert that into mBm.
473 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
474 ((-(int)rssi + 3)*100)
476 static int lbs_ret_scan(struct lbs_private *priv, unsigned long dummy,
477 struct cmd_header *resp)
479 struct cmd_ds_802_11_scan_rsp *scanresp = (void *)resp;
487 lbs_deb_enter(LBS_DEB_CFG80211);
489 bsssize = get_unaligned_le16(&scanresp->bssdescriptsize);
491 lbs_deb_scan("scan response: %d BSSs (%d bytes); resp size %d bytes\n",
492 scanresp->nr_sets, bsssize, le16_to_cpu(resp->size));
494 if (scanresp->nr_sets == 0) {
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 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_RSP", scanresp->bssdesc_and_tlvbuffer,
527 scanresp->bssdescriptsize);
529 tsfdesc = pos + bsssize;
530 tsfsize = 4 + 8 * scanresp->nr_sets;
531 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TSF", (u8 *) tsfdesc, tsfsize);
533 /* Validity check: we expect a Marvell-Local TLV */
534 i = get_unaligned_le16(tsfdesc);
536 if (i != TLV_TYPE_TSFTIMESTAMP) {
537 lbs_deb_scan("scan response: invalid TSF Timestamp %d\n", i);
541 /* Validity check: the TLV holds TSF values with 8 bytes each, so
542 * the size in the TLV must match the nr_sets value */
543 i = get_unaligned_le16(tsfdesc);
545 if (i / 8 != scanresp->nr_sets) {
546 lbs_deb_scan("scan response: invalid number of TSF timestamp "
547 "sets (expected %d got %d)\n", scanresp->nr_sets,
552 for (i = 0; i < scanresp->nr_sets; i++) {
561 const u8 *ssid = NULL;
563 DECLARE_SSID_BUF(ssid_buf);
565 int len = get_unaligned_le16(pos);
573 /* Packet time stamp */
575 /* Beacon interval */
576 intvl = get_unaligned_le16(pos);
579 capa = get_unaligned_le16(pos);
582 /* To find out the channel, we must parse the IEs */
584 /* 6+1+8+2+2: size of BSSID, RSSI, time stamp, beacon
585 interval, capabilities */
586 ielen = left = len - (6 + 1 + 8 + 2 + 2);
592 if (elen > left || elen == 0) {
593 lbs_deb_scan("scan response: invalid IE fmt\n");
597 if (id == WLAN_EID_DS_PARAMS)
599 if (id == WLAN_EID_SSID) {
607 /* No channel, no luck */
609 struct wiphy *wiphy = priv->wdev->wiphy;
610 int freq = ieee80211_channel_to_frequency(chan_no,
611 IEEE80211_BAND_2GHZ);
612 struct ieee80211_channel *channel =
613 ieee80211_get_channel(wiphy, freq);
615 lbs_deb_scan("scan: %pM, capa %04x, chan %2d, %s, "
617 bssid, capa, chan_no,
618 print_ssid(ssid_buf, ssid, ssid_len),
619 LBS_SCAN_RSSI_TO_MBM(rssi)/100);
622 !(channel->flags & IEEE80211_CHAN_DISABLED))
623 cfg80211_inform_bss(wiphy, channel,
624 bssid, le64_to_cpu(*(__le64 *)tsfdesc),
625 capa, intvl, ie, ielen,
626 LBS_SCAN_RSSI_TO_MBM(rssi),
629 lbs_deb_scan("scan response: missing BSS channel IE\n");
636 lbs_deb_leave_args(LBS_DEB_SCAN, "ret %d", ret);
642 * Our scan command contains a TLV, consting of a SSID TLV, a channel list
643 * TLV and a rates TLV. Determine the maximum size of them:
645 #define LBS_SCAN_MAX_CMD_SIZE \
646 (sizeof(struct cmd_ds_802_11_scan) \
647 + LBS_MAX_SSID_TLV_SIZE \
648 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
649 + LBS_MAX_RATES_TLV_SIZE)
652 * Assumes priv->scan_req is initialized and valid
653 * Assumes priv->scan_channel is initialized
655 static void lbs_scan_worker(struct work_struct *work)
657 struct lbs_private *priv =
658 container_of(work, struct lbs_private, scan_work.work);
659 struct cmd_ds_802_11_scan *scan_cmd;
660 u8 *tlv; /* pointer into our current, growing TLV storage area */
662 int running, carrier;
664 lbs_deb_enter(LBS_DEB_SCAN);
666 scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL);
667 if (scan_cmd == NULL)
668 goto out_no_scan_cmd;
670 /* prepare fixed part of scan command */
671 scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
673 /* stop network while we're away from our main channel */
674 running = !netif_queue_stopped(priv->dev);
675 carrier = netif_carrier_ok(priv->dev);
677 netif_stop_queue(priv->dev);
679 netif_carrier_off(priv->dev);
681 /* prepare fixed part of scan command */
682 tlv = scan_cmd->tlvbuffer;
685 if (priv->scan_req->n_ssids)
686 tlv += lbs_add_ssid_tlv(tlv,
687 priv->scan_req->ssids[0].ssid,
688 priv->scan_req->ssids[0].ssid_len);
690 /* add channel TLVs */
691 last_channel = priv->scan_channel + LBS_SCAN_BEFORE_NAP;
692 if (last_channel > priv->scan_req->n_channels)
693 last_channel = priv->scan_req->n_channels;
694 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
695 priv->scan_req->n_ssids);
698 tlv += lbs_add_supported_rates_tlv(tlv);
700 if (priv->scan_channel < priv->scan_req->n_channels) {
701 cancel_delayed_work(&priv->scan_work);
703 queue_delayed_work(priv->work_thread, &priv->scan_work,
704 msecs_to_jiffies(300));
707 /* This is the final data we are about to send */
708 scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
709 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd,
711 lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
712 tlv - scan_cmd->tlvbuffer);
714 __lbs_cmd(priv, CMD_802_11_SCAN, &scan_cmd->hdr,
715 le16_to_cpu(scan_cmd->hdr.size),
718 if (priv->scan_channel >= priv->scan_req->n_channels) {
720 if (priv->internal_scan)
721 kfree(priv->scan_req);
723 cfg80211_scan_done(priv->scan_req, false);
725 priv->scan_req = NULL;
726 priv->last_scan = jiffies;
729 /* Restart network */
731 netif_carrier_on(priv->dev);
732 if (running && !priv->tx_pending_len)
733 netif_wake_queue(priv->dev);
737 /* Wake up anything waiting on scan completion */
738 if (priv->scan_req == NULL) {
739 lbs_deb_scan("scan: waking up waiters\n");
740 wake_up_all(&priv->scan_q);
744 lbs_deb_leave(LBS_DEB_SCAN);
747 static void _internal_start_scan(struct lbs_private *priv, bool internal,
748 struct cfg80211_scan_request *request)
750 lbs_deb_enter(LBS_DEB_CFG80211);
752 lbs_deb_scan("scan: ssids %d, channels %d, ie_len %zd\n",
753 request->n_ssids, request->n_channels, request->ie_len);
755 priv->scan_channel = 0;
756 queue_delayed_work(priv->work_thread, &priv->scan_work,
757 msecs_to_jiffies(50));
759 priv->scan_req = request;
760 priv->internal_scan = internal;
762 lbs_deb_leave(LBS_DEB_CFG80211);
765 static int lbs_cfg_scan(struct wiphy *wiphy,
766 struct net_device *dev,
767 struct cfg80211_scan_request *request)
769 struct lbs_private *priv = wiphy_priv(wiphy);
772 lbs_deb_enter(LBS_DEB_CFG80211);
774 if (priv->scan_req || delayed_work_pending(&priv->scan_work)) {
775 /* old scan request not yet processed */
780 _internal_start_scan(priv, false, request);
782 if (priv->surpriseremoved)
786 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
793 /***************************************************************************
797 void lbs_send_disconnect_notification(struct lbs_private *priv)
799 lbs_deb_enter(LBS_DEB_CFG80211);
801 cfg80211_disconnected(priv->dev,
806 lbs_deb_leave(LBS_DEB_CFG80211);
809 void lbs_send_mic_failureevent(struct lbs_private *priv, u32 event)
811 lbs_deb_enter(LBS_DEB_CFG80211);
813 cfg80211_michael_mic_failure(priv->dev,
815 event == MACREG_INT_CODE_MIC_ERR_MULTICAST ?
816 NL80211_KEYTYPE_GROUP :
817 NL80211_KEYTYPE_PAIRWISE,
822 lbs_deb_leave(LBS_DEB_CFG80211);
828 /***************************************************************************
834 * This removes all WEP keys
836 static int lbs_remove_wep_keys(struct lbs_private *priv)
838 struct cmd_ds_802_11_set_wep cmd;
841 lbs_deb_enter(LBS_DEB_CFG80211);
843 memset(&cmd, 0, sizeof(cmd));
844 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
845 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
846 cmd.action = cpu_to_le16(CMD_ACT_REMOVE);
848 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
850 lbs_deb_leave(LBS_DEB_CFG80211);
857 static int lbs_set_wep_keys(struct lbs_private *priv)
859 struct cmd_ds_802_11_set_wep cmd;
863 lbs_deb_enter(LBS_DEB_CFG80211);
870 * action 02 00 ACT_ADD
872 * type for key 1 01 WEP40
876 * key 1 39 39 39 39 39 00 00 00
877 * 00 00 00 00 00 00 00 00
878 * key 2 00 00 00 00 00 00 00 00
879 * 00 00 00 00 00 00 00 00
880 * key 3 00 00 00 00 00 00 00 00
881 * 00 00 00 00 00 00 00 00
882 * key 4 00 00 00 00 00 00 00 00
884 if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
885 priv->wep_key_len[2] || priv->wep_key_len[3]) {
886 /* Only set wep keys if we have at least one of them */
887 memset(&cmd, 0, sizeof(cmd));
888 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
889 cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
890 cmd.action = cpu_to_le16(CMD_ACT_ADD);
892 for (i = 0; i < 4; i++) {
893 switch (priv->wep_key_len[i]) {
894 case WLAN_KEY_LEN_WEP40:
895 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
897 case WLAN_KEY_LEN_WEP104:
898 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
904 memcpy(cmd.keymaterial[i], priv->wep_key[i],
905 priv->wep_key_len[i]);
908 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
910 /* Otherwise remove all wep keys */
911 ret = lbs_remove_wep_keys(priv);
914 lbs_deb_leave(LBS_DEB_CFG80211);
920 * Enable/Disable RSN status
922 static int lbs_enable_rsn(struct lbs_private *priv, int enable)
924 struct cmd_ds_802_11_enable_rsn cmd;
927 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", enable);
934 * action 01 00 ACT_SET
937 memset(&cmd, 0, sizeof(cmd));
938 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
939 cmd.action = cpu_to_le16(CMD_ACT_SET);
940 cmd.enable = cpu_to_le16(enable);
942 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
944 lbs_deb_leave(LBS_DEB_CFG80211);
950 * Set WPA/WPA key material
953 /* like "struct cmd_ds_802_11_key_material", but with cmd_header. Once we
954 * get rid of WEXT, this should go into host.h */
956 struct cmd_key_material {
957 struct cmd_header hdr;
960 struct MrvlIEtype_keyParamSet param;
963 static int lbs_set_key_material(struct lbs_private *priv,
966 u8 *key, u16 key_len)
968 struct cmd_key_material cmd;
971 lbs_deb_enter(LBS_DEB_CFG80211);
974 * Example for WPA (TKIP):
981 * TLV type 00 01 key param
983 * key type 01 00 TKIP
984 * key info 06 00 UNICAST | ENABLED
988 memset(&cmd, 0, sizeof(cmd));
989 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
990 cmd.action = cpu_to_le16(CMD_ACT_SET);
991 cmd.param.type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
992 cmd.param.length = cpu_to_le16(sizeof(cmd.param) - 4);
993 cmd.param.keytypeid = cpu_to_le16(key_type);
994 cmd.param.keyinfo = cpu_to_le16(key_info);
995 cmd.param.keylen = cpu_to_le16(key_len);
997 memcpy(cmd.param.key, key, key_len);
999 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
1001 lbs_deb_leave(LBS_DEB_CFG80211);
1007 * Sets the auth type (open, shared, etc) in the firmware. That
1008 * we use CMD_802_11_AUTHENTICATE is misleading, this firmware
1009 * command doesn't send an authentication frame at all, it just
1010 * stores the auth_type.
1012 static int lbs_set_authtype(struct lbs_private *priv,
1013 struct cfg80211_connect_params *sme)
1015 struct cmd_ds_802_11_authenticate cmd;
1018 lbs_deb_enter_args(LBS_DEB_CFG80211, "%d", sme->auth_type);
1025 * BSS id 00 13 19 80 da 30
1027 * reserved 00 00 00 00 00 00 00 00 00 00
1029 memset(&cmd, 0, sizeof(cmd));
1030 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1032 memcpy(cmd.bssid, sme->bssid, ETH_ALEN);
1033 /* convert auth_type */
1034 ret = lbs_auth_to_authtype(sme->auth_type);
1039 ret = lbs_cmd_with_response(priv, CMD_802_11_AUTHENTICATE, &cmd);
1042 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1048 * Create association request
1050 #define LBS_ASSOC_MAX_CMD_SIZE \
1051 (sizeof(struct cmd_ds_802_11_associate) \
1052 - 512 /* cmd_ds_802_11_associate.iebuf */ \
1053 + LBS_MAX_SSID_TLV_SIZE \
1054 + LBS_MAX_CHANNEL_TLV_SIZE \
1055 + LBS_MAX_CF_PARAM_TLV_SIZE \
1056 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1057 + LBS_MAX_WPA_TLV_SIZE)
1059 static int lbs_associate(struct lbs_private *priv,
1060 struct cfg80211_bss *bss,
1061 struct cfg80211_connect_params *sme)
1063 struct cmd_ds_802_11_associate_response *resp;
1064 struct cmd_ds_802_11_associate *cmd = kzalloc(LBS_ASSOC_MAX_CMD_SIZE,
1067 size_t len, resp_ie_len;
1070 u8 *pos = &(cmd->iebuf[0]);
1073 lbs_deb_enter(LBS_DEB_CFG80211);
1085 * BSS id 00 13 19 80 da 30
1086 * capabilities 11 00
1087 * listen interval 0a 00
1088 * beacon interval 00 00
1090 * TLVs xx (up to 512 bytes)
1092 cmd->hdr.command = cpu_to_le16(CMD_802_11_ASSOCIATE);
1094 /* Fill in static fields */
1095 memcpy(cmd->bssid, bss->bssid, ETH_ALEN);
1096 cmd->listeninterval = cpu_to_le16(MRVDRV_DEFAULT_LISTEN_INTERVAL);
1097 cmd->capability = cpu_to_le16(bss->capability);
1100 ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
1102 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1104 lbs_deb_assoc("no SSID\n");
1106 /* add DS param TLV */
1108 pos += lbs_add_channel_tlv(pos, bss->channel->hw_value);
1110 lbs_deb_assoc("no channel\n");
1112 /* add (empty) CF param TLV */
1113 pos += lbs_add_cf_param_tlv(pos);
1116 tmp = pos + 4; /* skip Marvell IE header */
1117 pos += lbs_add_common_rates_tlv(pos, bss);
1118 lbs_deb_hex(LBS_DEB_ASSOC, "Common Rates", tmp, pos - tmp);
1120 /* add auth type TLV */
1121 if (MRVL_FW_MAJOR_REV(priv->fwrelease) >= 9)
1122 pos += lbs_add_auth_type_tlv(pos, sme->auth_type);
1124 /* add WPA/WPA2 TLV */
1125 if (sme->ie && sme->ie_len)
1126 pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
1128 len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
1129 (u16)(pos - (u8 *) &cmd->iebuf);
1130 cmd->hdr.size = cpu_to_le16(len);
1132 lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
1133 le16_to_cpu(cmd->hdr.size));
1135 /* store for later use */
1136 memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
1138 ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd);
1142 /* generate connect message to cfg80211 */
1144 resp = (void *) cmd; /* recast for easier field access */
1145 status = le16_to_cpu(resp->statuscode);
1147 /* Older FW versions map the IEEE 802.11 Status Code in the association
1148 * response to the following values returned in resp->statuscode:
1150 * IEEE Status Code Marvell Status Code
1151 * 0 -> 0x0000 ASSOC_RESULT_SUCCESS
1152 * 13 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1153 * 14 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1154 * 15 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1155 * 16 -> 0x0004 ASSOC_RESULT_AUTH_REFUSED
1156 * others -> 0x0003 ASSOC_RESULT_REFUSED
1158 * Other response codes:
1159 * 0x0001 -> ASSOC_RESULT_INVALID_PARAMETERS (unused)
1160 * 0x0002 -> ASSOC_RESULT_TIMEOUT (internal timer expired waiting for
1161 * association response from the AP)
1163 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1168 lbs_deb_assoc("invalid association parameters\n");
1169 status = WLAN_STATUS_CAPS_UNSUPPORTED;
1172 lbs_deb_assoc("timer expired while waiting for AP\n");
1173 status = WLAN_STATUS_AUTH_TIMEOUT;
1176 lbs_deb_assoc("association refused by AP\n");
1177 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1180 lbs_deb_assoc("authentication refused by AP\n");
1181 status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1184 lbs_deb_assoc("association failure %d\n", status);
1185 /* v5 OLPC firmware does return the AP status code if
1186 * it's not one of the values above. Let that through.
1192 lbs_deb_assoc("status %d, statuscode 0x%04x, capability 0x%04x, "
1193 "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
1194 le16_to_cpu(resp->capability), le16_to_cpu(resp->aid));
1196 resp_ie_len = le16_to_cpu(resp->hdr.size)
1199 cfg80211_connect_result(priv->dev,
1201 sme->ie, sme->ie_len,
1202 resp->iebuf, resp_ie_len,
1207 /* TODO: get rid of priv->connect_status */
1208 priv->connect_status = LBS_CONNECTED;
1209 netif_carrier_on(priv->dev);
1210 if (!priv->tx_pending_len)
1211 netif_tx_wake_all_queues(priv->dev);
1215 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1219 static struct cfg80211_scan_request *
1220 _new_connect_scan_req(struct wiphy *wiphy, struct cfg80211_connect_params *sme)
1222 struct cfg80211_scan_request *creq = NULL;
1223 int i, n_channels = 0;
1224 enum ieee80211_band band;
1226 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1227 if (wiphy->bands[band])
1228 n_channels += wiphy->bands[band]->n_channels;
1231 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1232 n_channels * sizeof(void *),
1237 /* SSIDs come after channels */
1238 creq->ssids = (void *)&creq->channels[n_channels];
1239 creq->n_channels = n_channels;
1242 /* Scan all available channels */
1244 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1247 if (!wiphy->bands[band])
1250 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
1251 /* ignore disabled channels */
1252 if (wiphy->bands[band]->channels[j].flags &
1253 IEEE80211_CHAN_DISABLED)
1256 creq->channels[i] = &wiphy->bands[band]->channels[j];
1261 /* Set real number of channels specified in creq->channels[] */
1262 creq->n_channels = i;
1264 /* Scan for the SSID we're going to connect to */
1265 memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
1266 creq->ssids[0].ssid_len = sme->ssid_len;
1268 /* No channels found... */
1276 static int lbs_cfg_connect(struct wiphy *wiphy, struct net_device *dev,
1277 struct cfg80211_connect_params *sme)
1279 struct lbs_private *priv = wiphy_priv(wiphy);
1280 struct cfg80211_bss *bss = NULL;
1282 u8 preamble = RADIO_PREAMBLE_SHORT;
1284 lbs_deb_enter(LBS_DEB_CFG80211);
1287 /* Run a scan if one isn't in-progress already and if the last
1288 * scan was done more than 2 seconds ago.
1290 if (priv->scan_req == NULL &&
1291 time_after(jiffies, priv->last_scan + (2 * HZ))) {
1292 struct cfg80211_scan_request *creq;
1294 creq = _new_connect_scan_req(wiphy, sme);
1300 lbs_deb_assoc("assoc: scanning for compatible AP\n");
1301 _internal_start_scan(priv, true, creq);
1304 /* Wait for any in-progress scan to complete */
1305 lbs_deb_assoc("assoc: waiting for scan to complete\n");
1306 wait_event_interruptible_timeout(priv->scan_q,
1307 (priv->scan_req == NULL),
1309 lbs_deb_assoc("assoc: scanning competed\n");
1312 /* Find the BSS we want using available scan results */
1313 bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
1314 sme->ssid, sme->ssid_len,
1315 WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
1317 lbs_pr_err("assoc: bss %pM not in scan results\n",
1322 lbs_deb_assoc("trying %pM\n", bss->bssid);
1323 lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
1324 sme->crypto.cipher_group,
1325 sme->key_idx, sme->key_len);
1327 /* As this is a new connection, clear locally stored WEP keys */
1328 priv->wep_tx_key = 0;
1329 memset(priv->wep_key, 0, sizeof(priv->wep_key));
1330 memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
1332 /* set/remove WEP keys */
1333 switch (sme->crypto.cipher_group) {
1334 case WLAN_CIPHER_SUITE_WEP40:
1335 case WLAN_CIPHER_SUITE_WEP104:
1336 /* Store provided WEP keys in priv-> */
1337 priv->wep_tx_key = sme->key_idx;
1338 priv->wep_key_len[sme->key_idx] = sme->key_len;
1339 memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len);
1340 /* Set WEP keys and WEP mode */
1341 lbs_set_wep_keys(priv);
1342 priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
1343 lbs_set_mac_control(priv);
1344 /* No RSN mode for WEP */
1345 lbs_enable_rsn(priv, 0);
1347 case 0: /* there's no WLAN_CIPHER_SUITE_NONE definition */
1349 * If we don't have no WEP, no WPA and no WPA2,
1350 * we remove all keys like in the WPA/WPA2 setup,
1351 * we just don't set RSN.
1353 * Therefore: fall-through
1355 case WLAN_CIPHER_SUITE_TKIP:
1356 case WLAN_CIPHER_SUITE_CCMP:
1357 /* Remove WEP keys and WEP mode */
1358 lbs_remove_wep_keys(priv);
1359 priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
1360 lbs_set_mac_control(priv);
1362 /* clear the WPA/WPA2 keys */
1363 lbs_set_key_material(priv,
1364 KEY_TYPE_ID_WEP, /* doesn't matter */
1365 KEY_INFO_WPA_UNICAST,
1367 lbs_set_key_material(priv,
1368 KEY_TYPE_ID_WEP, /* doesn't matter */
1371 /* RSN mode for WPA/WPA2 */
1372 lbs_enable_rsn(priv, sme->crypto.cipher_group != 0);
1375 lbs_pr_err("unsupported cipher group 0x%x\n",
1376 sme->crypto.cipher_group);
1381 lbs_set_authtype(priv, sme);
1382 lbs_set_radio(priv, preamble, 1);
1384 /* Do the actual association */
1385 ret = lbs_associate(priv, bss, sme);
1389 cfg80211_put_bss(bss);
1390 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1394 static int lbs_cfg_disconnect(struct wiphy *wiphy, struct net_device *dev,
1397 struct lbs_private *priv = wiphy_priv(wiphy);
1398 struct cmd_ds_802_11_deauthenticate cmd;
1400 lbs_deb_enter_args(LBS_DEB_CFG80211, "reason_code %d", reason_code);
1402 /* store for lbs_cfg_ret_disconnect() */
1403 priv->disassoc_reason = reason_code;
1405 memset(&cmd, 0, sizeof(cmd));
1406 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1407 /* Mildly ugly to use a locally store my own BSSID ... */
1408 memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
1409 cmd.reasoncode = cpu_to_le16(reason_code);
1411 if (lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd))
1414 cfg80211_disconnected(priv->dev,
1415 priv->disassoc_reason,
1418 priv->connect_status = LBS_DISCONNECTED;
1424 static int lbs_cfg_set_default_key(struct wiphy *wiphy,
1425 struct net_device *netdev,
1426 u8 key_index, bool unicast,
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,
1602 IEEE80211_BAND_2GHZ));
1604 ret = lbs_get_rssi(priv, &signal, &noise);
1606 survey->filled = SURVEY_INFO_NOISE_DBM;
1607 survey->noise = noise;
1610 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1617 /***************************************************************************
1621 static int lbs_change_intf(struct wiphy *wiphy, struct net_device *dev,
1622 enum nl80211_iftype type, u32 *flags,
1623 struct vif_params *params)
1625 struct lbs_private *priv = wiphy_priv(wiphy);
1628 lbs_deb_enter(LBS_DEB_CFG80211);
1631 case NL80211_IFTYPE_MONITOR:
1632 ret = lbs_set_monitor_mode(priv, 1);
1634 case NL80211_IFTYPE_STATION:
1635 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1636 ret = lbs_set_monitor_mode(priv, 0);
1638 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 1);
1640 case NL80211_IFTYPE_ADHOC:
1641 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR)
1642 ret = lbs_set_monitor_mode(priv, 0);
1644 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_BSS_TYPE, 2);
1651 priv->wdev->iftype = type;
1653 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1659 /***************************************************************************
1663 /* The firmware needs the following bits masked out of the beacon-derived
1664 * capability field when associating/joining to a BSS:
1665 * 9 (QoS), 11 (APSD), 12 (unused), 14 (unused), 15 (unused)
1667 #define CAPINFO_MASK (~(0xda00))
1670 static void lbs_join_post(struct lbs_private *priv,
1671 struct cfg80211_ibss_params *params,
1672 u8 *bssid, u16 capability)
1674 u8 fake_ie[2 + IEEE80211_MAX_SSID_LEN + /* ssid */
1675 2 + 4 + /* basic rates */
1676 2 + 1 + /* DS parameter */
1678 2 + 8]; /* extended rates */
1681 lbs_deb_enter(LBS_DEB_CFG80211);
1684 * For cfg80211_inform_bss, we'll need a fake IE, as we can't get
1685 * the real IE from the firmware. So we fabricate a fake IE based on
1686 * what the firmware actually sends (sniffed with wireshark).
1689 *fake++ = WLAN_EID_SSID;
1690 *fake++ = params->ssid_len;
1691 memcpy(fake, params->ssid, params->ssid_len);
1692 fake += params->ssid_len;
1693 /* Fake supported basic rates IE */
1694 *fake++ = WLAN_EID_SUPP_RATES;
1700 /* Fake DS channel IE */
1701 *fake++ = WLAN_EID_DS_PARAMS;
1703 *fake++ = params->channel->hw_value;
1704 /* Fake IBSS params IE */
1705 *fake++ = WLAN_EID_IBSS_PARAMS;
1707 *fake++ = 0; /* ATIM=0 */
1709 /* Fake extended rates IE, TODO: don't add this for 802.11b only,
1710 * but I don't know how this could be checked */
1711 *fake++ = WLAN_EID_EXT_SUPP_RATES;
1721 lbs_deb_hex(LBS_DEB_CFG80211, "IE", fake_ie, fake - fake_ie);
1723 cfg80211_inform_bss(priv->wdev->wiphy,
1728 params->beacon_interval,
1729 fake_ie, fake - fake_ie,
1732 memcpy(priv->wdev->ssid, params->ssid, params->ssid_len);
1733 priv->wdev->ssid_len = params->ssid_len;
1735 cfg80211_ibss_joined(priv->dev, bssid, GFP_KERNEL);
1737 /* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
1738 priv->connect_status = LBS_CONNECTED;
1739 netif_carrier_on(priv->dev);
1740 if (!priv->tx_pending_len)
1741 netif_wake_queue(priv->dev);
1743 lbs_deb_leave(LBS_DEB_CFG80211);
1746 static int lbs_ibss_join_existing(struct lbs_private *priv,
1747 struct cfg80211_ibss_params *params,
1748 struct cfg80211_bss *bss)
1750 const u8 *rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
1751 struct cmd_ds_802_11_ad_hoc_join cmd;
1752 u8 preamble = RADIO_PREAMBLE_SHORT;
1755 lbs_deb_enter(LBS_DEB_CFG80211);
1757 /* TODO: set preamble based on scan result */
1758 ret = lbs_set_radio(priv, preamble, 1);
1763 * Example CMD_802_11_AD_HOC_JOIN command:
1765 * command 2c 00 CMD_802_11_AD_HOC_JOIN
1769 * bssid 02 27 27 97 2f 96
1770 * ssid 49 42 53 53 00 00 00 00
1771 * 00 00 00 00 00 00 00 00
1772 * 00 00 00 00 00 00 00 00
1773 * 00 00 00 00 00 00 00 00
1774 * type 02 CMD_BSS_TYPE_IBSS
1775 * beacon period 64 00
1777 * timestamp 00 00 00 00 00 00 00 00
1778 * localtime 00 00 00 00 00 00 00 00
1782 * reserveed 00 00 00 00
1785 * IE IBSS atim 00 00
1786 * reserved 00 00 00 00
1788 * rates 82 84 8b 96 0c 12 18 24 30 48 60 6c 00
1789 * fail timeout ff 00
1792 memset(&cmd, 0, sizeof(cmd));
1793 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1795 memcpy(cmd.bss.bssid, bss->bssid, ETH_ALEN);
1796 memcpy(cmd.bss.ssid, params->ssid, params->ssid_len);
1797 cmd.bss.type = CMD_BSS_TYPE_IBSS;
1798 cmd.bss.beaconperiod = cpu_to_le16(params->beacon_interval);
1799 cmd.bss.ds.header.id = WLAN_EID_DS_PARAMS;
1800 cmd.bss.ds.header.len = 1;
1801 cmd.bss.ds.channel = params->channel->hw_value;
1802 cmd.bss.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1803 cmd.bss.ibss.header.len = 2;
1804 cmd.bss.ibss.atimwindow = 0;
1805 cmd.bss.capability = cpu_to_le16(bss->capability & CAPINFO_MASK);
1807 /* set rates to the intersection of our rates and the rates in the
1810 lbs_add_rates(cmd.bss.rates);
1813 u8 rates_max = rates_eid[1];
1814 u8 *rates = cmd.bss.rates;
1815 for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
1816 u8 hw_rate = lbs_rates[hw].bitrate / 5;
1817 for (i = 0; i < rates_max; i++) {
1818 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1819 u8 rate = rates_eid[i+2];
1820 if (rate == 0x02 || rate == 0x04 ||
1821 rate == 0x0b || rate == 0x16)
1829 /* Only v8 and below support setting this */
1830 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
1831 cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
1832 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1834 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd);
1839 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1847 lbs_join_post(priv, params, bss->bssid, bss->capability);
1850 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1856 static int lbs_ibss_start_new(struct lbs_private *priv,
1857 struct cfg80211_ibss_params *params)
1859 struct cmd_ds_802_11_ad_hoc_start cmd;
1860 struct cmd_ds_802_11_ad_hoc_result *resp =
1861 (struct cmd_ds_802_11_ad_hoc_result *) &cmd;
1862 u8 preamble = RADIO_PREAMBLE_SHORT;
1866 lbs_deb_enter(LBS_DEB_CFG80211);
1868 ret = lbs_set_radio(priv, preamble, 1);
1873 * Example CMD_802_11_AD_HOC_START command:
1875 * command 2b 00 CMD_802_11_AD_HOC_START
1879 * ssid 54 45 53 54 00 00 00 00
1880 * 00 00 00 00 00 00 00 00
1881 * 00 00 00 00 00 00 00 00
1882 * 00 00 00 00 00 00 00 00
1884 * beacon period 64 00
1888 * IE IBSS atim 00 00
1889 * reserved 00 00 00 00
1893 * reserved 00 00 00 00
1896 * rates 82 84 8b 96 (basic rates with have bit 7 set)
1897 * 0c 12 18 24 30 48 60 6c
1900 memset(&cmd, 0, sizeof(cmd));
1901 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1902 memcpy(cmd.ssid, params->ssid, params->ssid_len);
1903 cmd.bsstype = CMD_BSS_TYPE_IBSS;
1904 cmd.beaconperiod = cpu_to_le16(params->beacon_interval);
1905 cmd.ibss.header.id = WLAN_EID_IBSS_PARAMS;
1906 cmd.ibss.header.len = 2;
1907 cmd.ibss.atimwindow = 0;
1908 cmd.ds.header.id = WLAN_EID_DS_PARAMS;
1909 cmd.ds.header.len = 1;
1910 cmd.ds.channel = params->channel->hw_value;
1911 /* Only v8 and below support setting probe delay */
1912 if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8)
1913 cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
1914 /* TODO: mix in WLAN_CAPABILITY_PRIVACY */
1915 capability = WLAN_CAPABILITY_IBSS;
1916 cmd.capability = cpu_to_le16(capability);
1917 lbs_add_rates(cmd.rates);
1920 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_START, &cmd);
1925 * This is a sample response to CMD_802_11_AD_HOC_JOIN:
1932 * bssid 02 2b 7b 0f 86 0e
1934 lbs_join_post(priv, params, resp->bssid, capability);
1937 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1942 static int lbs_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1943 struct cfg80211_ibss_params *params)
1945 struct lbs_private *priv = wiphy_priv(wiphy);
1947 struct cfg80211_bss *bss;
1948 DECLARE_SSID_BUF(ssid_buf);
1950 lbs_deb_enter(LBS_DEB_CFG80211);
1952 if (!params->channel) {
1957 ret = lbs_set_channel(priv, params->channel->hw_value);
1961 /* Search if someone is beaconing. This assumes that the
1962 * bss list is populated already */
1963 bss = cfg80211_get_bss(wiphy, params->channel, params->bssid,
1964 params->ssid, params->ssid_len,
1965 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
1968 ret = lbs_ibss_join_existing(priv, params, bss);
1969 cfg80211_put_bss(bss);
1971 ret = lbs_ibss_start_new(priv, params);
1975 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
1980 static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1982 struct lbs_private *priv = wiphy_priv(wiphy);
1983 struct cmd_ds_802_11_ad_hoc_stop cmd;
1986 lbs_deb_enter(LBS_DEB_CFG80211);
1988 memset(&cmd, 0, sizeof(cmd));
1989 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1990 ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_STOP, &cmd);
1992 /* TODO: consider doing this at MACREG_INT_CODE_ADHOC_BCN_LOST time */
1993 lbs_mac_event_disconnected(priv);
1995 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2002 /***************************************************************************
2006 static struct cfg80211_ops lbs_cfg80211_ops = {
2007 .set_channel = lbs_cfg_set_channel,
2008 .scan = lbs_cfg_scan,
2009 .connect = lbs_cfg_connect,
2010 .disconnect = lbs_cfg_disconnect,
2011 .add_key = lbs_cfg_add_key,
2012 .del_key = lbs_cfg_del_key,
2013 .set_default_key = lbs_cfg_set_default_key,
2014 .get_station = lbs_cfg_get_station,
2015 .dump_survey = lbs_get_survey,
2016 .change_virtual_intf = lbs_change_intf,
2017 .join_ibss = lbs_join_ibss,
2018 .leave_ibss = lbs_leave_ibss,
2023 * At this time lbs_private *priv doesn't even exist, so we just allocate
2024 * memory and don't initialize the wiphy further. This is postponed until we
2025 * can talk to the firmware and happens at registration time in
2026 * lbs_cfg_wiphy_register().
2028 struct wireless_dev *lbs_cfg_alloc(struct device *dev)
2031 struct wireless_dev *wdev;
2033 lbs_deb_enter(LBS_DEB_CFG80211);
2035 wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
2037 dev_err(dev, "cannot allocate wireless device\n");
2038 return ERR_PTR(-ENOMEM);
2041 wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
2043 dev_err(dev, "cannot allocate wiphy\n");
2048 lbs_deb_leave(LBS_DEB_CFG80211);
2053 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2054 return ERR_PTR(ret);
2058 static void lbs_cfg_set_regulatory_hint(struct lbs_private *priv)
2060 struct region_code_mapping {
2065 /* Section 5.17.2 */
2066 static const struct region_code_mapping regmap[] = {
2067 {"US ", 0x10}, /* US FCC */
2068 {"CA ", 0x20}, /* Canada */
2069 {"EU ", 0x30}, /* ETSI */
2070 {"ES ", 0x31}, /* Spain */
2071 {"FR ", 0x32}, /* France */
2072 {"JP ", 0x40}, /* Japan */
2076 lbs_deb_enter(LBS_DEB_CFG80211);
2078 for (i = 0; i < ARRAY_SIZE(regmap); i++)
2079 if (regmap[i].code == priv->regioncode) {
2080 regulatory_hint(priv->wdev->wiphy, regmap[i].cn);
2084 lbs_deb_leave(LBS_DEB_CFG80211);
2089 * This function get's called after lbs_setup_firmware() determined the
2090 * firmware capabities. So we can setup the wiphy according to our
2091 * hardware/firmware.
2093 int lbs_cfg_register(struct lbs_private *priv)
2095 struct wireless_dev *wdev = priv->wdev;
2098 lbs_deb_enter(LBS_DEB_CFG80211);
2100 wdev->wiphy->max_scan_ssids = 1;
2101 wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
2103 wdev->wiphy->interface_modes =
2104 BIT(NL80211_IFTYPE_STATION) |
2105 BIT(NL80211_IFTYPE_ADHOC);
2106 if (lbs_rtap_supported(priv))
2107 wdev->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
2109 wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &lbs_band_2ghz;
2112 * We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
2113 * never seen a firmware without WPA
2115 wdev->wiphy->cipher_suites = cipher_suites;
2116 wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2117 wdev->wiphy->reg_notifier = lbs_reg_notifier;
2119 ret = wiphy_register(wdev->wiphy);
2121 lbs_pr_err("cannot register wiphy device\n");
2123 priv->wiphy_registered = true;
2125 ret = register_netdev(priv->dev);
2127 lbs_pr_err("cannot register network device\n");
2129 INIT_DELAYED_WORK(&priv->scan_work, lbs_scan_worker);
2131 lbs_cfg_set_regulatory_hint(priv);
2133 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
2137 int lbs_reg_notifier(struct wiphy *wiphy,
2138 struct regulatory_request *request)
2140 struct lbs_private *priv = wiphy_priv(wiphy);
2143 lbs_deb_enter_args(LBS_DEB_CFG80211, "cfg80211 regulatory domain "
2144 "callback for domain %c%c\n", request->alpha2[0],
2145 request->alpha2[1]);
2147 ret = lbs_set_11d_domain_info(priv, request, wiphy->bands);
2149 lbs_deb_leave(LBS_DEB_CFG80211);
2153 void lbs_scan_deinit(struct lbs_private *priv)
2155 lbs_deb_enter(LBS_DEB_CFG80211);
2156 cancel_delayed_work_sync(&priv->scan_work);
2160 void lbs_cfg_free(struct lbs_private *priv)
2162 struct wireless_dev *wdev = priv->wdev;
2164 lbs_deb_enter(LBS_DEB_CFG80211);
2169 if (priv->wiphy_registered)
2170 wiphy_unregister(wdev->wiphy);
2173 wiphy_free(wdev->wiphy);