/* *ConvertNL80211'sauth_typetotheonefromLibertas,seechapter5.9.1 *inthefirmwarespec
*/ staticint 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;
}
/* Add common rates from a TLV and return the new end of the TLV */ static u8 *
add_ie_rates(u8 *tlv, const u8 *ie, int *nrates)
{ int hw, ap, ap_max = ie[1];
u8 hw_rate;
if (ap_max > MAX_RATES) {
lbs_deb_assoc("invalid rates\n"); return tlv;
} /* Advance past IE header */
ie += 2;
/* Find the first RSN or WPA IE to use */
wpaie = cfg80211_find_elem(WLAN_EID_RSN, ie, ie_len); if (!wpaie)
wpaie = cfg80211_find_vendor_elem(WLAN_OUI_MICROSOFT,
WLAN_OUI_TYPE_MICROSOFT_WPA,
ie, ie_len); if (!wpaie || wpaie->datalen > 128) return0;
/* Look for a WPS IE and add it to the probe request */
wpsie = cfg80211_find_vendor_elem(WLAN_OUI_MICROSOFT,
WLAN_OUI_TYPE_MICROSOFT_WPS,
ie, ie_len); if (!wpsie) return0;
/* Convert the WPS IE to a TLV. The IE looks like this: *u8type(WLAN_EID_VENDOR_SPECIFIC) *u8len *u8[]data *buttheTLVwilllooklikethisinstead: *__le16type(TLV_TYPE_WPS_ENROLLEE) *__le16len *u8[]data
*/
wpstlv->header.type = cpu_to_le16(TLV_TYPE_WPS_ENROLLEE);
wpstlv->header.len = cpu_to_le16(wpsie->datalen);
memcpy(wpstlv->data, wpsie->data, wpsie->datalen);
/* Return the total number of bytes added to the TLV buffer */ returnsizeof(struct mrvl_ie_header) + wpsie->datalen;
}
/* *SetChannel
*/
staticint lbs_cfg_set_monitor_channel(struct wiphy *wiphy, struct net_device *dev, struct cfg80211_chan_def *chandef)
{ struct lbs_private *priv = wiphy_priv(wiphy); int ret = -ENOTSUPP;
if (cfg80211_get_chandef_type(chandef) != NL80211_CHAN_NO_HT) goto out;
ret = lbs_set_channel(priv, chandef->chan->hw_value);
out: return ret;
}
staticint lbs_cfg_set_mesh_channel(struct wiphy *wiphy, struct net_device *netdev, struct ieee80211_channel *channel)
{ struct lbs_private *priv = wiphy_priv(wiphy); int ret = -ENOTSUPP;
if (netdev != priv->mesh_dev) goto out;
ret = lbs_mesh_set_channel(priv, channel->hw_value);
/* *Assumespriv->scan_reqisinitializedandvalid *Assumespriv->scan_channelisinitialized
*/ staticvoid lbs_scan_worker(struct work_struct *work)
{ struct lbs_private *priv =
container_of(work, struct lbs_private, scan_work.work); struct cmd_ds_802_11_scan *scan_cmd;
u8 *tlv; /* pointer into our current, growing TLV storage area */ int last_channel; int running, carrier;
scan_cmd = kzalloc(LBS_SCAN_MAX_CMD_SIZE, GFP_KERNEL); if (scan_cmd == NULL) return;
/* prepare fixed part of scan command */
scan_cmd->bsstype = CMD_BSS_TYPE_ANY;
/* stop network while we're away from our main channel */
running = !netif_queue_stopped(priv->dev);
carrier = netif_carrier_ok(priv->dev); if (running)
netif_stop_queue(priv->dev); if (carrier)
netif_carrier_off(priv->dev);
/* prepare fixed part of scan command */
tlv = scan_cmd->tlvbuffer;
if (priv->scan_channel < priv->scan_req->n_channels) {
cancel_delayed_work(&priv->scan_work); if (netif_running(priv->dev))
queue_delayed_work(priv->work_thread, &priv->scan_work,
msecs_to_jiffies(300));
}
/* This is the final data we are about to send */
scan_cmd->hdr.size = cpu_to_le16(tlv - (u8 *)scan_cmd);
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_CMD", (void *)scan_cmd, sizeof(*scan_cmd));
lbs_deb_hex(LBS_DEB_SCAN, "SCAN_TLV", scan_cmd->tlvbuffer,
tlv - scan_cmd->tlvbuffer);
if (priv->scan_channel >= priv->scan_req->n_channels) { /* Mark scan done */
cancel_delayed_work(&priv->scan_work);
lbs_scan_done(priv);
}
/* Restart network */ if (carrier)
netif_carrier_on(priv->dev); if (running && !priv->tx_pending_len)
netif_wake_queue(priv->dev);
kfree(scan_cmd);
/* Wake up anything waiting on scan completion */ if (priv->scan_req == NULL) {
lbs_deb_scan("scan: waking up waiters\n");
wake_up_all(&priv->scan_q);
}
}
ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
return ret;
}
/* *SetWEPkeys
*/ staticint lbs_set_wep_keys(struct lbs_private *priv)
{ struct cmd_ds_802_11_set_wep cmd; int i; int ret;
/* *command1300 *size5000 *sequencexxxx *result0000 *action0200ACT_ADD *transmitkey0000 *typeforkey101WEP40 *typeforkey200 *typeforkey300 *typeforkey400 *key13939393939000000 *0000000000000000 *key20000000000000000 *0000000000000000 *key30000000000000000 *0000000000000000 *key40000000000000000
*/ if (priv->wep_key_len[0] || priv->wep_key_len[1] ||
priv->wep_key_len[2] || priv->wep_key_len[3]) { /* Only set wep keys if we have at least one of them */
memset(&cmd, 0, sizeof(cmd));
cmd.hdr.size = cpu_to_le16(sizeof(cmd));
cmd.keyindex = cpu_to_le16(priv->wep_tx_key);
cmd.action = cpu_to_le16(CMD_ACT_ADD);
for (i = 0; i < 4; i++) { switch (priv->wep_key_len[i]) { case WLAN_KEY_LEN_WEP40:
cmd.keytype[i] = CMD_TYPE_WEP_40_BIT; break; case WLAN_KEY_LEN_WEP104:
cmd.keytype[i] = CMD_TYPE_WEP_104_BIT; break; default:
cmd.keytype[i] = 0; break;
}
memcpy(cmd.keymaterial[i], priv->wep_key[i],
priv->wep_key_len[i]);
}
ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
} else { /* Otherwise remove all wep keys */
ret = lbs_remove_wep_keys(priv);
}
return ret;
}
/* *Enable/DisableRSNstatus
*/ staticint lbs_enable_rsn(struct lbs_private *priv, int enable)
{ struct cmd_ds_802_11_enable_rsn cmd; int ret;
/* store for later use */
memcpy(priv->assoc_bss, bss->bssid, ETH_ALEN);
ret = lbs_cmd_with_response(priv, CMD_802_11_ASSOCIATE, cmd); if (ret) goto done;
/* generate connect message to cfg80211 */
resp = (void *) cmd; /* recast for easier field access */
status = le16_to_cpu(resp->statuscode);
/* Older FW versions map the IEEE 802.11 Status Code in the association *responsetothefollowingvaluesreturnedinresp->statuscode: * *IEEEStatusCodeMarvellStatusCode *0->0x0000ASSOC_RESULT_SUCCESS *13->0x0004ASSOC_RESULT_AUTH_REFUSED *14->0x0004ASSOC_RESULT_AUTH_REFUSED *15->0x0004ASSOC_RESULT_AUTH_REFUSED *16->0x0004ASSOC_RESULT_AUTH_REFUSED *others->0x0003ASSOC_RESULT_REFUSED * *Otherresponsecodes: *0x0001->ASSOC_RESULT_INVALID_PARAMETERS(unused) *0x0002->ASSOC_RESULT_TIMEOUT(internaltimerexpiredwaitingfor *associationresponsefromtheAP)
*/ if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) { switch (status) { case0: break; case1:
lbs_deb_assoc("invalid association parameters\n");
status = WLAN_STATUS_CAPS_UNSUPPORTED; break; case2:
lbs_deb_assoc("timer expired while waiting for AP\n");
status = WLAN_STATUS_AUTH_TIMEOUT; break; case3:
lbs_deb_assoc("association refused by AP\n");
status = WLAN_STATUS_ASSOC_DENIED_UNSPEC; break; case4:
lbs_deb_assoc("authentication refused by AP\n");
status = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; break; default:
lbs_deb_assoc("association failure %d\n", status); /* v5 OLPC firmware does return the AP status code if *it'snotoneofthevaluesabove.Letthatthrough.
*/ break;
}
}
if (status == 0) { /* TODO: get rid of priv->connect_status */
priv->connect_status = LBS_CONNECTED;
netif_carrier_on(priv->dev); if (!priv->tx_pending_len)
netif_tx_wake_all_queues(priv->dev);
}
/* SSIDs come after channels */
creq->ssids = (void *)&creq->channels[n_channels];
creq->n_channels = n_channels;
creq->n_ssids = 1;
/* Scan all available channels */
i = 0; for (band = 0; band < NUM_NL80211_BANDS; band++) { int j;
if (!wiphy->bands[band]) continue;
for (j = 0; j < wiphy->bands[band]->n_channels; j++) { /* ignore disabled channels */ if (wiphy->bands[band]->channels[j].flags &
IEEE80211_CHAN_DISABLED) continue;
creq->channels[i] = &wiphy->bands[band]->channels[j];
i++;
}
} if (i) { /* Set real number of channels specified in creq->channels[] */
creq->n_channels = i;
/* Scan for the SSID we're going to connect to */
memcpy(creq->ssids[0].ssid, sme->ssid, sme->ssid_len);
creq->ssids[0].ssid_len = sme->ssid_len;
} else { /* No channels found... */
kfree(creq);
creq = NULL;
}
creq = _new_connect_scan_req(wiphy, sme); if (!creq) {
ret = -EINVAL; goto done;
}
lbs_deb_assoc("assoc: scanning for compatible AP\n");
_internal_start_scan(priv, true, creq);
lbs_deb_assoc("assoc: waiting for scan to complete\n");
wait_event_interruptible_timeout(priv->scan_q,
(priv->scan_req == NULL),
(15 * HZ));
lbs_deb_assoc("assoc: scanning completed\n");
}
/* Find the BSS we want using available scan results */
bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
sme->ssid, sme->ssid_len, IEEE80211_BSS_TYPE_ESS,
IEEE80211_PRIVACY_ANY); if (!bss) {
wiphy_err(wiphy, "assoc: bss %pM not in scan results\n",
sme->bssid);
ret = -ENOENT; goto done;
}
lbs_deb_assoc("trying %pM\n", bss->bssid);
lbs_deb_assoc("cipher 0x%x, key index %d, key len %d\n",
sme->crypto.cipher_group,
sme->key_idx, sme->key_len);
/* As this is a new connection, clear locally stored WEP keys */
priv->wep_tx_key = 0;
memset(priv->wep_key, 0, sizeof(priv->wep_key));
memset(priv->wep_key_len, 0, sizeof(priv->wep_key_len));
/* set/remove WEP keys */ switch (sme->crypto.cipher_group) { case WLAN_CIPHER_SUITE_WEP40: case WLAN_CIPHER_SUITE_WEP104: /* Store provided WEP keys in priv-> */
priv->wep_tx_key = sme->key_idx;
priv->wep_key_len[sme->key_idx] = sme->key_len;
memcpy(priv->wep_key[sme->key_idx], sme->key, sme->key_len); /* Set WEP keys and WEP mode */
lbs_set_wep_keys(priv);
priv->mac_control |= CMD_ACT_MAC_WEP_ENABLE;
lbs_set_mac_control(priv); /* No RSN mode for WEP */
lbs_enable_rsn(priv, 0); break; case0: /* there's no WLAN_CIPHER_SUITE_NONE definition */ /* *Ifwedon'thavenoWEP,noWPAandnoWPA2, *weremoveallkeyslikeintheWPA/WPA2setup, *wejustdon'tsetRSN. * *Therefore:fall-through
*/ case WLAN_CIPHER_SUITE_TKIP: case WLAN_CIPHER_SUITE_CCMP: /* Remove WEP keys and WEP mode */
lbs_remove_wep_keys(priv);
priv->mac_control &= ~CMD_ACT_MAC_WEP_ENABLE;
lbs_set_mac_control(priv);
ret = lbs_set_authtype(priv, sme); if (ret == -ENOTSUPP) {
wiphy_err(wiphy, "unsupported authtype 0x%x\n", sme->auth_type); goto done;
}
lbs_set_radio(priv, preamble, 1);
/* Do the actual association */
ret = lbs_associate(priv, bss, sme);
done: if (bss)
cfg80211_put_bss(wiphy, bss); return ret;
}
int lbs_disconnect(struct lbs_private *priv, u16 reason)
{ struct cmd_ds_802_11_deauthenticate cmd; int ret;
memset(&cmd, 0, sizeof(cmd));
cmd.hdr.size = cpu_to_le16(sizeof(cmd)); /* Mildly ugly to use a locally store my own BSSID ... */
memcpy(cmd.macaddr, &priv->assoc_bss, ETH_ALEN);
cmd.reasoncode = cpu_to_le16(reason);
ret = lbs_cmd_with_response(priv, CMD_802_11_DEAUTHENTICATE, &cmd); if (ret) return ret;
/* Get current RSSI */
ret = lbs_get_rssi(priv, &signal, &noise); if (ret == 0) {
sinfo->signal = signal;
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
}
/* Convert priv->cur_rate from hw_value to NL80211 value */ for (i = 0; i < ARRAY_SIZE(lbs_rates); i++) { if (priv->cur_rate == lbs_rates[i].hw_value) {
sinfo->txrate.legacy = lbs_rates[i].bitrate;
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); break;
}
}
/* TODO: consider doing this at MACREG_INT_CODE_LINK_SENSED time */
priv->connect_status = LBS_CONNECTED;
netif_carrier_on(priv->dev); if (!priv->tx_pending_len)
netif_wake_queue(priv->dev);
}
/* set rates to the intersection of our rates and the rates in the
bss */
rcu_read_lock();
rates_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SUPP_RATES); if (!rates_eid) {
lbs_add_rates(cmd.bss.rates);
} else {
rates_max = rates_eid[1]; if (rates_max > MAX_RATES) {
lbs_deb_join("invalid rates");
rcu_read_unlock();
ret = -EINVAL; goto out;
}
rates = cmd.bss.rates; for (hw = 0; hw < ARRAY_SIZE(lbs_rates); hw++) {
u8 hw_rate = lbs_rates[hw].bitrate / 5; for (i = 0; i < rates_max; i++) { if (hw_rate == (rates_eid[i+2] & 0x7f)) {
u8 rate = rates_eid[i+2]; if (rate == 0x02 || rate == 0x04 ||
rate == 0x0b || rate == 0x16)
rate |= 0x80;
*rates++ = rate;
}
}
}
}
rcu_read_unlock();
/* Only v8 and below support setting this */ if (MRVL_FW_MAJOR_REV(priv->fwrelease) <= 8) {
cmd.failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
cmd.probedelay = cpu_to_le16(CMD_SCAN_PROBE_DELAY_TIME);
}
ret = lbs_cmd_with_response(priv, CMD_802_11_AD_HOC_JOIN, &cmd); if (ret) goto out;
if (!params->chandef.chan) {
ret = -ENOTSUPP; goto out;
}
ret = lbs_set_channel(priv, params->chandef.chan->hw_value); if (ret) goto out;
/* Search if someone is beaconing. This assumes that the
* bss list is populated already */
bss = cfg80211_get_bss(wiphy, params->chandef.chan, params->bssid,
params->ssid, params->ssid_len,
IEEE80211_BSS_TYPE_IBSS, IEEE80211_PRIVACY_ANY);
if (bss) {
ret = lbs_ibss_join_existing(priv, params, bss);
cfg80211_put_bss(wiphy, bss);
} else
ret = lbs_ibss_start_new(priv, params);
out: return ret;
}
staticint lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
{ struct lbs_private *priv = wiphy_priv(wiphy); struct cmd_ds_802_11_ad_hoc_stop cmd; int ret = 0;
if (!(priv->fwcapinfo & FW_CAPINFO_PS)) { if (!enabled) return0; else return -EINVAL;
} /* firmware does not work well with too long latency with power saving *enabled,sodonotenableitifthereisonlypolling,no *interrupts(likeinsomesdiohostswhichcanonly *pollforsdioirqs)
*/ if (priv->is_polling) { if (!enabled) return0; else return -EINVAL;
} if (!enabled) {
priv->psmode = LBS802_11POWERMODECAM; if (priv->psstate != PS_STATE_FULL_POWER)
lbs_set_ps_mode(priv,
PS_MODE_ACTION_EXIT_PS, true); return0;
} if (priv->psmode != LBS802_11POWERMODECAM) return0;
priv->psmode = LBS802_11POWERMODEMAX_PSP; if (priv->connect_status == LBS_CONNECTED)
lbs_set_ps_mode(priv, PS_MODE_ACTION_ENTER_PS, true); return0;
}
/*
* At this time lbs_private *priv doesn't even exist, so we just allocate
* memory and don't initialize the wiphy further. This is postponed until we
* can talk to the firmware and happens at registration time in
* lbs_cfg_wiphy_register().
*/
struct wireless_dev *lbs_cfg_alloc(struct device *dev)
{
int ret = 0;
struct wireless_dev *wdev;
wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
if (!wdev)
return ERR_PTR(-ENOMEM);
wdev->wiphy = wiphy_new(&lbs_cfg80211_ops, sizeof(struct lbs_private));
if (!wdev->wiphy) {
dev_err(dev, "cannot allocate wiphy\n");
ret = -ENOMEM;
goto err_wiphy_new;
}
memcpy(priv->country_code, request->alpha2, sizeof(request->alpha2));
if (lbs_iface_active(priv))
lbs_set_11d_domain_info(priv);
}
/*
* This function gets called after lbs_setup_firmware() determined the
* firmware capabilities. So we can setup the wiphy according to our
* hardware/firmware.
*/
int lbs_cfg_register(struct lbs_private *priv)
{
struct wireless_dev *wdev = priv->wdev;
int ret;
/*
* We could check priv->fwcapinfo && FW_CAPINFO_WPA, but I have
* never seen a firmware without WPA
*/
wdev->wiphy->cipher_suites = cipher_suites;
wdev->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
wdev->wiphy->reg_notifier = lbs_reg_notifier;
ret = wiphy_register(wdev->wiphy);
if (ret < 0)
pr_err("cannot register wiphy device\n");
priv->wiphy_registered = true;
ret = register_netdev(priv->dev);
if (ret)
pr_err("cannot register network device\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.