/drivers/net/wireless/libertas/cfg.c
C | 2187 lines | 1310 code | 365 blank | 512 comment | 163 complexity | 6064a321533146716a53f88ea90eb21a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
Large files files are truncated, but you can click here to view the full file
- /*
- * Implement cfg80211 ("iw") support.
- *
- * Copyright (C) 2009 M&N Solutions GmbH, 61191 Rosbach, Germany
- * Holger Schurig <hs4233@mail.mn-solutions.de>
- *
- */
- #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
- #include <linux/sched.h>
- #include <linux/wait.h>
- #include <linux/slab.h>
- #include <linux/ieee80211.h>
- #include <net/cfg80211.h>
- #include <asm/unaligned.h>
- #include "decl.h"
- #include "cfg.h"
- #include "cmd.h"
- #define CHAN2G(_channel, _freq, _flags) { \
- .band = IEEE80211_BAND_2GHZ, \
- .center_freq = (_freq), \
- .hw_value = (_channel), \
- .flags = (_flags), \
- .max_antenna_gain = 0, \
- .max_power = 30, \
- }
- static struct ieee80211_channel lbs_2ghz_channels[] = {
- CHAN2G(1, 2412, 0),
- CHAN2G(2, 2417, 0),
- CHAN2G(3, 2422, 0),
- CHAN2G(4, 2427, 0),
- CHAN2G(5, 2432, 0),
- CHAN2G(6, 2437, 0),
- CHAN2G(7, 2442, 0),
- CHAN2G(8, 2447, 0),
- CHAN2G(9, 2452, 0),
- CHAN2G(10, 2457, 0),
- CHAN2G(11, 2462, 0),
- CHAN2G(12, 2467, 0),
- CHAN2G(13, 2472, 0),
- CHAN2G(14, 2484, 0),
- };
- #define RATETAB_ENT(_rate, _hw_value, _flags) { \
- .bitrate = (_rate), \
- .hw_value = (_hw_value), \
- .flags = (_flags), \
- }
- /* Table 6 in section 3.2.1.1 */
- static struct ieee80211_rate lbs_rates[] = {
- RATETAB_ENT(10, 0, 0),
- RATETAB_ENT(20, 1, 0),
- RATETAB_ENT(55, 2, 0),
- RATETAB_ENT(110, 3, 0),
- RATETAB_ENT(60, 9, 0),
- RATETAB_ENT(90, 6, 0),
- RATETAB_ENT(120, 7, 0),
- RATETAB_ENT(180, 8, 0),
- RATETAB_ENT(240, 9, 0),
- RATETAB_ENT(360, 10, 0),
- RATETAB_ENT(480, 11, 0),
- RATETAB_ENT(540, 12, 0),
- };
- static struct ieee80211_supported_band lbs_band_2ghz = {
- .channels = lbs_2ghz_channels,
- .n_channels = ARRAY_SIZE(lbs_2ghz_channels),
- .bitrates = lbs_rates,
- .n_bitrates = ARRAY_SIZE(lbs_rates),
- };
- static const u32 cipher_suites[] = {
- WLAN_CIPHER_SUITE_WEP40,
- WLAN_CIPHER_SUITE_WEP104,
- WLAN_CIPHER_SUITE_TKIP,
- WLAN_CIPHER_SUITE_CCMP,
- };
- /* Time to stay on the channel */
- #define LBS_DWELL_PASSIVE 100
- #define LBS_DWELL_ACTIVE 40
- /***************************************************************************
- * Misc utility functions
- *
- * TLVs are Marvell specific. They are very similar to IEs, they have the
- * same structure: type, length, data*. The only difference: for IEs, the
- * type and length are u8, but for TLVs they're __le16.
- */
- /*
- * Convert NL80211's auth_type to the one from Libertas, see chapter 5.9.1
- * in the firmware spec
- */
- static u8 lbs_auth_to_authtype(enum nl80211_auth_type auth_type)
- {
- int ret = -ENOTSUPP;
- switch (auth_type) {
- case NL80211_AUTHTYPE_OPEN_SYSTEM:
- case NL80211_AUTHTYPE_SHARED_KEY:
- ret = auth_type;
- break;
- case NL80211_AUTHTYPE_AUTOMATIC:
- ret = NL80211_AUTHTYPE_OPEN_SYSTEM;
- break;
- case NL80211_AUTHTYPE_NETWORK_EAP:
- ret = 0x80;
- break;
- default:
- /* silence compiler */
- break;
- }
- return ret;
- }
- /*
- * Various firmware commands need the list of supported rates, but with
- * the hight-bit set for basic rates
- */
- static int lbs_add_rates(u8 *rates)
- {
- size_t i;
- for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) {
- u8 rate = lbs_rates[i].bitrate / 5;
- if (rate == 0x02 || rate == 0x04 ||
- rate == 0x0b || rate == 0x16)
- rate |= 0x80;
- rates[i] = rate;
- }
- return ARRAY_SIZE(lbs_rates);
- }
- /***************************************************************************
- * TLV utility functions
- *
- * TLVs are Marvell specific. They are very similar to IEs, they have the
- * same structure: type, length, data*. The only difference: for IEs, the
- * type and length are u8, but for TLVs they're __le16.
- */
- /*
- * Add ssid TLV
- */
- #define LBS_MAX_SSID_TLV_SIZE \
- (sizeof(struct mrvl_ie_header) \
- + IEEE80211_MAX_SSID_LEN)
- static int lbs_add_ssid_tlv(u8 *tlv, const u8 *ssid, int ssid_len)
- {
- struct mrvl_ie_ssid_param_set *ssid_tlv = (void *)tlv;
- /*
- * TLV-ID SSID 00 00
- * length 06 00
- * ssid 4d 4e 54 45 53 54
- */
- ssid_tlv->header.type = cpu_to_le16(TLV_TYPE_SSID);
- ssid_tlv->header.len = cpu_to_le16(ssid_len);
- memcpy(ssid_tlv->ssid, ssid, ssid_len);
- return sizeof(ssid_tlv->header) + ssid_len;
- }
- /*
- * Add channel list TLV (section 8.4.2)
- *
- * Actual channel data comes from priv->wdev->wiphy->channels.
- */
- #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
- (sizeof(struct mrvl_ie_header) \
- + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
- static int lbs_add_channel_list_tlv(struct lbs_private *priv, u8 *tlv,
- int last_channel, int active_scan)
- {
- int chanscanparamsize = sizeof(struct chanscanparamset) *
- (last_channel - priv->scan_channel);
- struct mrvl_ie_header *header = (void *) tlv;
- /*
- * TLV-ID CHANLIST 01 01
- * length 0e 00
- * channel 00 01 00 00 00 64 00
- * radio type 00
- * channel 01
- * scan type 00
- * min scan time 00 00
- * max scan time 64 00
- * channel 2 00 02 00 00 00 64 00
- *
- */
- header->type = cpu_to_le16(TLV_TYPE_CHANLIST);
- header->len = cpu_to_le16(chanscanparamsize);
- tlv += sizeof(struct mrvl_ie_header);
- /* lbs_deb_scan("scan: channels %d to %d\n", priv->scan_channel,
- last_channel); */
- memset(tlv, 0, chanscanparamsize);
- while (priv->scan_channel < last_channel) {
- struct chanscanparamset *param = (void *) tlv;
- param->radiotype = CMD_SCAN_RADIO_TYPE_BG;
- param->channumber =
- priv->scan_req->channels[priv->scan_channel]->hw_value;
- if (active_scan) {
- param->maxscantime = cpu_to_le16(LBS_DWELL_ACTIVE);
- } else {
- param->chanscanmode.passivescan = 1;
- param->maxscantime = cpu_to_le16(LBS_DWELL_PASSIVE);
- }
- tlv += sizeof(struct chanscanparamset);
- priv->scan_channel++;
- }
- return sizeof(struct mrvl_ie_header) + chanscanparamsize;
- }
- /*
- * Add rates TLV
- *
- * The rates are in lbs_bg_rates[], but for the 802.11b
- * rates the high bit is set. We add this TLV only because
- * there's a firmware which otherwise doesn't report all
- * APs in range.
- */
- #define LBS_MAX_RATES_TLV_SIZE \
- (sizeof(struct mrvl_ie_header) \
- + (ARRAY_SIZE(lbs_rates)))
- /* Adds a TLV with all rates the hardware supports */