9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/sched.h>
13 #include <linux/wait.h>
14 #include <linux/slab.h>
17 #include <asm/unaligned.h>
25 #define CHAN2G(_channel, _freq, _flags) { \
26 .band = IEEE80211_BAND_2GHZ, \
27 .center_freq = (_freq), \
28 .hw_value = (_channel), \
30 .max_antenna_gain = 0, \
51 #define RATETAB_ENT(_rate, _hw_value, _flags) { \
53 .hw_value = (_hw_value), \
75 .channels = lbs_2ghz_channels,
77 .bitrates = lbs_rates,
82 static const u32 cipher_suites[] = {
90 #define LBS_DWELL_PASSIVE 100
91 #define LBS_DWELL_ACTIVE 40
133 static int lbs_add_rates(
u8 *rates)
139 if (rate == 0x02 || rate == 0x04 ||
140 rate == 0x0b || rate == 0x16)
160 #define LBS_MAX_SSID_TLV_SIZE \
161 (sizeof(struct mrvl_ie_header) \
162 + IEEE80211_MAX_SSID_LEN)
164 static int lbs_add_ssid_tlv(
u8 *
tlv,
const u8 *
ssid,
int ssid_len)
176 return sizeof(ssid_tlv->
header) + ssid_len;
185 #define LBS_MAX_CHANNEL_LIST_TLV_SIZE \
186 (sizeof(struct mrvl_ie_header) \
187 + (LBS_SCAN_BEFORE_NAP * sizeof(struct chanscanparamset)))
190 int last_channel,
int active_scan)
216 memset(tlv, 0, chanscanparamsize);
245 #define LBS_MAX_RATES_TLV_SIZE \
246 (sizeof(struct mrvl_ie_header) \
247 + (ARRAY_SIZE(lbs_rates)))
250 static int lbs_add_supported_rates_tlv(
u8 *
tlv)
261 tlv +=
sizeof(rate_tlv->
header);
262 i = lbs_add_rates(tlv);
265 return sizeof(rate_tlv->
header) + i;
270 add_ie_rates(
u8 *
tlv,
const u8 *ie,
int *nrates)
272 int hw, ap, ap_max = ie[1];
280 for (hw = 0; hw <
ARRAY_SIZE(lbs_rates); hw++) {
282 for (ap = 0; ap < ap_max; ap++) {
283 if (hw_rate == (ie[ap] & 0x7f)) {
285 *nrates = *nrates + 1;
295 static int lbs_add_common_rates_tlv(
u8 *tlv,
struct cfg80211_bss *bss)
298 const u8 *rates_eid, *ext_rates_eid;
310 tlv +=
sizeof(rate_tlv->
header);
314 tlv = add_ie_rates(tlv, rates_eid, &n);
318 tlv = add_ie_rates(tlv, ext_rates_eid, &n);
330 return sizeof(rate_tlv->
header) + n;
339 #define LBS_MAX_AUTH_TYPE_TLV_SIZE \
340 sizeof(struct mrvl_ie_auth_type)
354 return sizeof(*auth);
361 #define LBS_MAX_CHANNEL_TLV_SIZE \
362 sizeof(struct mrvl_ie_header)
364 static int lbs_add_channel_tlv(
u8 *tlv,
u8 channel)
383 #define LBS_MAX_CF_PARAM_TLV_SIZE \
384 sizeof(struct mrvl_ie_header)
386 static int lbs_add_cf_param_tlv(
u8 *tlv)
406 #define LBS_MAX_WPA_TLV_SIZE \
407 (sizeof(struct mrvl_ie_header) \
410 static int lbs_add_wpa_tlv(
u8 *tlv,
const u8 *ie,
u8 ie_len)
426 tlv_len = *tlv++ = *ie++;
438 static int lbs_cfg_set_monitor_channel(
struct wiphy *
wiphy,
458 static int lbs_cfg_set_mesh_channel(
struct wiphy *wiphy,
490 #define LBS_SCAN_BEFORE_NAP 4
498 #define LBS_SCAN_RSSI_TO_MBM(rssi) \
499 ((-(int)rssi + 3)*100)
517 lbs_deb_scan(
"scan response: %d BSSs (%d bytes); resp size %d bytes\n",
555 tsfdesc = pos + bsssize;
556 tsfsize = 4 + 8 * scanresp->
nr_sets;
560 i = get_unaligned_le16(tsfdesc);
563 lbs_deb_scan(
"scan response: invalid TSF Timestamp %d\n", i);
571 i = get_unaligned_le16(tsfdesc);
573 if (i / 8 != scanresp->
nr_sets) {
574 lbs_deb_scan(
"scan response: invalid number of TSF timestamp "
575 "sets (expected %d got %d)\n", scanresp->
nr_sets,
580 for (i = 0; i < scanresp->
nr_sets; i++) {
593 int len = get_unaligned_le16(pos);
604 intvl = get_unaligned_le16(pos);
607 capa = get_unaligned_le16(pos);
616 ielen = left = len - (6 + 1 + 8 + 2 + 2);
622 if (elen > left || elen == 0) {
639 struct wiphy *wiphy = priv->
wdev->wiphy;
643 ieee80211_get_channel(wiphy, freq);
647 bssid, capa, chan_no,
655 capa, intvl, ie, ielen,
661 lbs_deb_scan(
"scan response: missing BSS channel IE\n");
677 #define LBS_SCAN_MAX_CMD_SIZE \
678 (sizeof(struct cmd_ds_802_11_scan) \
679 + LBS_MAX_SSID_TLV_SIZE \
680 + LBS_MAX_CHANNEL_LIST_TLV_SIZE \
681 + LBS_MAX_RATES_TLV_SIZE)
699 if (scan_cmd ==
NULL)
700 goto out_no_scan_cmd;
706 running = !netif_queue_stopped(priv->
dev);
707 carrier = netif_carrier_ok(priv->
dev);
709 netif_stop_queue(priv->
dev);
718 tlv += lbs_add_ssid_tlv(tlv,
724 if (last_channel > priv->
scan_req->n_channels)
725 last_channel = priv->
scan_req->n_channels;
726 tlv += lbs_add_channel_list_tlv(priv, tlv, last_channel,
730 tlv += lbs_add_supported_rates_tlv(tlv);
734 if (netif_running(priv->
dev))
760 netif_wake_queue(priv->
dev);
774 static void _internal_start_scan(
struct lbs_private *priv,
bool internal,
779 lbs_deb_scan(
"scan: ssids %d, channels %d, ie_len %zd\n",
807 static int lbs_cfg_scan(
struct wiphy *wiphy,
821 _internal_start_scan(priv,
false, request);
877 static int lbs_remove_wep_keys(
struct lbs_private *priv)
898 static int lbs_set_wep_keys(
struct lbs_private *priv)
933 for (i = 0; i < 4; i++) {
952 ret = lbs_remove_wep_keys(priv);
1006 static int lbs_set_key_material(
struct lbs_private *priv,
1055 static int lbs_set_authtype(
struct lbs_private *priv,
1077 ret = lbs_auth_to_authtype(sme->
auth_type);
1093 #define LBS_ASSOC_MAX_CMD_SIZE \
1094 (sizeof(struct cmd_ds_802_11_associate) \
1096 + LBS_MAX_SSID_TLV_SIZE \
1097 + LBS_MAX_CHANNEL_TLV_SIZE \
1098 + LBS_MAX_CF_PARAM_TLV_SIZE \
1099 + LBS_MAX_AUTH_TYPE_TLV_SIZE \
1100 + LBS_MAX_WPA_TLV_SIZE)
1102 static int lbs_associate(
struct lbs_private *priv,
1110 size_t len, resp_ie_len;
1145 pos += lbs_add_ssid_tlv(pos, ssid_eid + 2, ssid_eid[1]);
1151 pos += lbs_add_channel_tlv(pos, bss->
channel->hw_value);
1156 pos += lbs_add_cf_param_tlv(pos);
1160 pos += lbs_add_common_rates_tlv(pos, bss);
1165 pos += lbs_add_auth_type_tlv(pos, sme->
auth_type);
1169 pos += lbs_add_wpa_tlv(pos, sme->
ie, sme->
ie_len);
1171 len = (
sizeof(*cmd) -
sizeof(cmd->
iebuf)) +
1187 resp = (
void *) cmd;
1235 lbs_deb_assoc(
"status %d, statuscode 0x%04x, capability 0x%04x, "
1245 resp->
iebuf, resp_ie_len,
1254 netif_tx_wake_all_queues(priv->
dev);
1271 if (wiphy->
bands[band])
1272 n_channels += wiphy->
bands[band]->n_channels;
1275 creq = kzalloc(
sizeof(*creq) +
sizeof(
struct cfg80211_ssid) +
1276 n_channels *
sizeof(
void *),
1291 if (!wiphy->
bands[band])
1294 for (j = 0; j < wiphy->
bands[band]->n_channels; j++) {
1296 if (wiphy->
bands[band]->channels[j].flags &
1320 static int lbs_cfg_connect(
struct wiphy *wiphy,
struct net_device *
dev,
1345 creq = _new_connect_scan_req(wiphy, sme);
1352 _internal_start_scan(priv,
true, creq);
1366 wiphy_err(wiphy,
"assoc: bss %pM not in scan results\n",
1373 sme->
crypto.cipher_group,
1382 switch (sme->
crypto.cipher_group) {
1390 lbs_set_wep_keys(priv);
1394 lbs_enable_rsn(priv, 0);
1407 lbs_remove_wep_keys(priv);
1412 lbs_set_key_material(priv,
1416 lbs_set_key_material(priv,
1421 lbs_enable_rsn(priv, sme->
crypto.cipher_group != 0);
1424 wiphy_err(wiphy,
"unsupported cipher group 0x%x\n",
1425 sme->
crypto.cipher_group);
1430 ret = lbs_set_authtype(priv, sme);
1439 ret = lbs_associate(priv, bss, sme);
1453 memset(&cmd, 0,
sizeof(cmd));
1472 static int lbs_cfg_disconnect(
struct wiphy *wiphy,
struct net_device *dev,
1488 static int lbs_cfg_set_default_key(
struct wiphy *wiphy,
1503 lbs_set_wep_keys(priv);
1510 static int lbs_cfg_add_key(
struct wiphy *wiphy,
struct net_device *netdev,
1525 params->
cipher, mac_addr);
1537 switch (params->
cipher) {
1547 lbs_set_wep_keys(priv);
1558 lbs_set_key_material(priv,
1573 static int lbs_cfg_del_key(
struct wiphy *wiphy,
struct net_device *netdev,
1574 u8 key_index,
bool pairwise,
const u8 *mac_addr)
1580 key_index, mac_addr);
1601 lbs_set_wep_keys(priv);
1613 static int lbs_cfg_get_station(
struct wiphy *wiphy,
struct net_device *dev,
1640 for (i = 0; i <
ARRAY_SIZE(lbs_rates); i++) {
1658 static int lbs_change_intf(
struct wiphy *wiphy,
struct net_device *dev,
1700 #define CAPINFO_MASK (~(0xda00))
1703 static void lbs_join_post(
struct lbs_private *priv,
1737 *fake++ = params->
channel->hw_value;
1763 fake_ie, fake - fake_ie,
1776 netif_wake_queue(priv->
dev);
1781 static int lbs_ibss_join_existing(
struct lbs_private *priv,
1835 cmd.bss.ds.header.len = 1;
1836 cmd.bss.ds.channel = params->
channel->hw_value;
1838 cmd.bss.ibss.header.len = 2;
1839 cmd.bss.ibss.atimwindow = 0;
1845 lbs_add_rates(
cmd.bss.rates);
1848 u8 rates_max = rates_eid[1];
1849 u8 *rates =
cmd.bss.rates;
1850 for (hw = 0; hw <
ARRAY_SIZE(lbs_rates); hw++) {
1852 for (i = 0; i < rates_max; i++) {
1853 if (hw_rate == (rates_eid[i+2] & 0x7f)) {
1854 u8 rate = rates_eid[i+2];
1855 if (rate == 0x02 || rate == 0x04 ||
1856 rate == 0x0b || rate == 0x16)
1891 static int lbs_ibss_start_new(
struct lbs_private *priv,
1941 cmd.ibss.header.len = 2;
1942 cmd.ibss.atimwindow = 0;
1944 cmd.ds.header.len = 1;
1952 lbs_add_rates(
cmd.rates);
1969 lbs_join_post(priv, params, resp->
bssid, capability);
1977 static int lbs_join_ibss(
struct wiphy *wiphy,
struct net_device *dev,
2006 ret = lbs_ibss_join_existing(priv, params, bss);
2009 ret = lbs_ibss_start_new(priv, params);
2018 static int lbs_leave_ibss(
struct wiphy *wiphy,
struct net_device *dev)
2048 .set_monitor_channel = lbs_cfg_set_monitor_channel,
2049 .libertas_set_mesh_channel = lbs_cfg_set_mesh_channel,
2050 .scan = lbs_cfg_scan,
2051 .connect = lbs_cfg_connect,
2052 .disconnect = lbs_cfg_disconnect,
2053 .add_key = lbs_cfg_add_key,
2054 .del_key = lbs_cfg_del_key,
2055 .set_default_key = lbs_cfg_set_default_key,
2056 .get_station = lbs_cfg_get_station,
2057 .change_virtual_intf = lbs_change_intf,
2058 .join_ibss = lbs_join_ibss,
2059 .leave_ibss = lbs_leave_ibss,
2078 dev_err(dev,
"cannot allocate wireless device\n");
2084 dev_err(dev,
"cannot allocate wiphy\n");
2095 return ERR_PTR(ret);
2099 static void lbs_cfg_set_regulatory_hint(
struct lbs_private *priv)
2141 wdev->
wiphy->max_scan_ssids = 1;
2144 wdev->
wiphy->interface_modes =
2158 wdev->
wiphy->cipher_suites = cipher_suites;
2164 pr_err(
"cannot register wiphy device\n");
2170 pr_err(
"cannot register network device\n");
2174 lbs_cfg_set_regulatory_hint(priv);
2187 "callback for domain %c%c\n", request->
alpha2[0],
2191 if (lbs_iface_active(priv))