blob: d0da7a3427a6fc5db305cf2495b147465e5afd3f [file] [log] [blame]
/*-
* Copyright (c) 2001 Atsushi Onoe
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: ieee80211_node.c 2366 2007-05-23 08:43:05Z mrenzmann $
*/
#ifndef EXPORT_SYMTAB
#define EXPORT_SYMTAB
#endif
/*
* IEEE 802.11 node handling support.
*/
#ifndef AUTOCONF_INCLUDED
#include <linux/config.h>
#endif
#include <linux/version.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/random.h>
#include <linux/workqueue.h>
#include <linux/jiffies.h>
#include <qtn/qdrv_sch.h>
#include "net80211/if_media.h"
#include "net80211/ieee80211_var.h"
#include "net80211/ieee80211_node.h"
#include "net80211/ieee80211_dot11_msg.h"
#include "net80211/if_ethersubr.h"
#include "net80211/ieee80211_tpc.h"
#include "net80211/ieee80211_tdls.h"
#if defined(CONFIG_QTN_BSA_SUPPORT)
#include "net80211/ieee80211_bsa.h"
#endif
#include <qtn/qtn_net_packet.h>
#include <qtn/skb_recycle.h>
#include "qdrv_sch_const.h"
#include <qtn/qtn_pcap.h>
#include <qtn/shared_params.h>
#include <qtn/qtn_vlan.h>
#include "qtn_logging.h"
#include <asm/board/pm.h>
#include <asm/board/kdump.h>
#define IEEE80211_OBSS_AP_SCAN_INT 25
#define IEEE80211_BSS_DELETE_DELAY 5
#define FREQ_2_4_GHZ 0
#define FREQ_5_GHZ 1
#define DBGMAC "%02X:%02X:%02X:%02X:%02X:%02X"
#define ETHERFMT(a) \
(a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
static void ieee80211_aid_remove(struct ieee80211_node *);
static void ieee80211_idx_remove(struct ieee80211_node *);
static void ieee80211_node_cleanup(struct ieee80211_node *);
static void ieee80211_node_exit(struct ieee80211_node *);
static u_int8_t ieee80211_node_getrssi(const struct ieee80211_node *);
static void _ieee80211_free_node(struct ieee80211_node *);
static void ieee80211_node_timeout(unsigned long);
static void ieee80211_node_table_init(struct ieee80211com *,
struct ieee80211_node_table *, const char *, int);
static void ieee80211_node_table_cleanup(struct ieee80211com *, struct ieee80211_node_table *);
static void ieee80211_node_table_reset(struct ieee80211com *, struct ieee80211_node_table *,
struct ieee80211vap *);
static void ieee80211_node_wds_ageout(unsigned long);
static void ieee80211_timeout_station_work(struct work_struct *work);
void ieee80211_wireless_reassoc(struct ieee80211vap *vap, int debug, int rescan);
static int v_wait = 0;
#define V_WAIT_REASSOC (10)
#define IEEE80211_REAUTH_ENABLE 1
MALLOC_DEFINE(M_80211_NODE, "80211node", "802.11 node state");
struct ieee80211_v_cnt {
uint32_t total;
uint32_t v;
};
#ifdef IEEE80211_DEBUG_REFCNT
static struct ieee80211_node_table *nt_refdebug = NULL;
static void ieee80211_node_show_refdebug_info(struct ieee80211_node *ni)
{
struct node_refdebug_info *info = ni->ni_refdebug_info_p;
struct node_refdebug_info_entry *entry;
int i;
if (info) {
printk("\nnode %p, MAC %pM, ref count %d, entry count %d:\n",
ni,
ni->ni_macaddr,
ieee80211_node_refcnt(ni),
info->entry_count);
for (i = 0; i< info->entry_count; i++) {
entry = &info->entry[i];
/* INC count line filename */
printk("%4s %10d %9d %s\n",
(entry->line & 0xffff0000) ? "dec" : "inc",
entry->count,
(entry->line & 0x0000ffff),
entry->fname);
}
if (info->entry_count == REFDEBUG_ENTRY_MAX) {
printk("%4s %10d %9s %s\n",
"inc", info->inc_count, "unknown", "unknown");
printk("%4s %10d %9s %s\n",
"dec", info->dec_count, "unknown", "unknown");
}
}
}
#endif
void ieee80211_node_dbgref_history_dump(void)
{
#ifdef IEEE80211_DEBUG_REFCNT
struct ieee80211_node *ni, *next;
if (!nt_refdebug)
return;
IEEE80211_NODE_LOCK_IRQ(nt_refdebug);
TAILQ_FOREACH_SAFE(ni, &nt_refdebug->nt_node, ni_list, next) {
ieee80211_node_show_refdebug_info(ni);
}
IEEE80211_NODE_UNLOCK_IRQ(nt_refdebug);
#else
printk("%s: not enabled\n", __func__);
#endif
}
#ifdef IEEE80211_DEBUG_REFCNT
static __sram_text void
ieee80211_node_dbgref_history(const struct ieee80211_node *ni,
const char *filename, int line, int is_increased)
{
unsigned long flags;
struct node_refdebug_info *info;
struct node_refdebug_info_entry *entry;
int i;
info = ni->ni_refdebug_info_p;
if (!info)
return;
line = is_increased ? line : (0xffff0000 | line);
local_irq_save(flags);
for (i = 0; i < REFDEBUG_ENTRY_MAX; i++) {
entry = &info->entry[i];
if (entry->fname == NULL) {
entry->fname = filename;
entry->line = line;
info->entry_count++;
break;
}
if (entry->line == line &&
strcmp(filename, entry->fname) == 0)
break;
}
if (unlikely(i == REFDEBUG_ENTRY_MAX)) {
printk_once("%s: Table is full\n", __FUNCTION__);
if (is_increased)
info->inc_count++;
else
info->dec_count++;
} else {
entry->count++;
}
local_irq_restore(flags);
}
void __sram_text
ieee80211_node_dbgref(const struct ieee80211_node *ni, const char *filename,
const int line, int is_increased)
{
ieee80211_node_dbgref_history(ni, filename, line, is_increased);
}
EXPORT_SYMBOL(ieee80211_node_dbgref);
#endif
/*
* Caller must lock the IEEE80211_NODE_LOCK
* Context: hwIRQ, softIRQ and process context
*/
static void __sram_text
_ieee80211_remove_node(struct ieee80211_node *ni)
{
struct ieee80211_node_table *nt = ni->ni_table;
if (nt != NULL) {
TAILQ_REMOVE(&nt->nt_node, ni, ni_list);
LIST_REMOVE(ni, ni_hash);
ni->ni_table = NULL;
ieee80211_aid_remove(ni);
ieee80211_idx_remove(ni);
}
}
/*
* Reclaim a node. If this is the last reference count then
* do the normal free work. Otherwise remove it from the node
* table and mark it gone by clearing the back-reference.
*/
static void
#ifdef IEEE80211_DEBUG_REFCNT
#define ieee80211_node_reclaim(_nt, _ni) \
ieee80211_node_reclaim_debug(_nt, _ni, __FILE__, __LINE__)
ieee80211_node_reclaim_debug(struct ieee80211_node_table *nt, struct ieee80211_node *ni,
const char *filename, int line)
#else
ieee80211_node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
#endif
{
struct ieee80211com *ic = ni->ni_ic;
IEEE80211_LOCK_IRQ(ic);
if (!ieee80211_node_dectestref(ni)) {
ieee80211_node_dbgref(ni, filename, line, IEEE80211_NODEREF_DECR);
/*
* Other references are present, just remove the
* node from the table so it cannot be found. When
* the references are dropped storage will be
* reclaimed.
*/
_ieee80211_remove_node(ni);
} else {
ieee80211_node_dbgref(ni, filename, line, IEEE80211_NODEREF_DECR);
_ieee80211_free_node(ni);
}
IEEE80211_UNLOCK_IRQ(ic);
}
void
indicate_association(void)
{
}
EXPORT_SYMBOL(indicate_association);
void
indicate_disassociation(void)
{
}
EXPORT_SYMBOL(indicate_disassociation);
void
ieee80211_node_attach(struct ieee80211com *ic)
{
ieee80211_node_table_init(ic, &ic->ic_sta, "station",
IEEE80211_INACT_INIT);
init_timer(&ic->ic_inact);
ic->ic_inact.function = ieee80211_node_timeout;
ic->ic_inact.data = (unsigned long) ic;
ic->ic_inact.expires = jiffies + IEEE80211_INACT_WAIT * HZ;
#if IEEE80211_REAUTH_ENABLE
add_timer(&ic->ic_inact);
#endif
/* copy default check interval from inactivity timer */
ic->ic_scan_results_check = IEEE80211_INACT_WAIT;
init_timer(&ic->ic_scan_results_expire);
ic->ic_scan_results_expire.function = ieee80211_scan_timeout;
ic->ic_scan_results_expire.data = (unsigned long) ic;
ic->ic_scan_results_expire.expires = jiffies + ic->ic_scan_results_check * HZ;
add_timer(&ic->ic_scan_results_expire);
ic->ic_node_free = ieee80211_node_exit;
ic->ic_node_cleanup = ieee80211_node_cleanup;
ic->ic_node_getrssi = ieee80211_node_getrssi;
ic->ic_iterate_nodes = ieee80211_iterate_nodes;
ic->ic_iterate_dev_nodes = ieee80211_iterate_dev_nodes;
#ifdef IEEE80211_DEBUG_REFCNT
kdump_add_troubleshooter(&ieee80211_node_dbgref_history_dump);
nt_refdebug = &ic->ic_sta;
#endif
}
void
ieee80211_node_detach(struct ieee80211com *ic)
{
#if IEEE80211_REAUTH_ENABLE
del_timer(&ic->ic_inact);
#endif
del_timer(&ic->ic_scan_results_expire);
ieee80211_node_table_cleanup(ic, &ic->ic_sta);
}
void
ieee80211_node_vattach(struct ieee80211vap *vap)
{
/* default station inactivity timer setings */
vap->iv_inact_init = IEEE80211_INACT_INIT;
vap->iv_inact_auth = IEEE80211_INACT_AUTH;
vap->iv_inact_probe = IEEE80211_INACT_PROBE;
if (vap->iv_opmode == IEEE80211_M_STA)
vap->iv_inact_run = IEEE80211_INACT_RUN_STA;
else if (vap->iv_opmode == IEEE80211_M_WDS)
vap->iv_inact_run = IEEE80211_INACT_RUN_WDS;
else
vap->iv_inact_run = IEEE80211_INACT_RUN;
}
void
ieee80211_node_latevattach(struct ieee80211vap *vap)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_rsnparms *rsn;
/*
* Allocate these only if needed. On STA, only needed for TDLS
* connections. Beware that adhoc mode doesn't support ATIM yet
*/
if (vap->iv_opmode == IEEE80211_M_HOSTAP ||
vap->iv_opmode == IEEE80211_M_STA ||
vap->iv_opmode == IEEE80211_M_WDS) {
if (vap->iv_max_aid == 0)
vap->iv_max_aid = IEEE80211_AID_DEF;
else if (vap->iv_max_aid > IEEE80211_AID_MAX)
vap->iv_max_aid = IEEE80211_AID_MAX;
}
ieee80211_reset_bss(vap);
if (vap->iv_opmode == IEEE80211_M_WDS) {
vap->iv_bss = NULL;
vap->iv_auth = ieee80211_authenticator_get(IEEE80211_AUTH_AUTO);
return;
}
/*
* Set up "global settings" in the bss node so that
* each new station automatically inherits them.
*/
rsn = &vap->iv_bss->ni_rsn;
rsn->rsn_ucastcipherset |= 1 << IEEE80211_CIPHER_AES_CCM;
rsn->rsn_ucastcipherset |= 1 << IEEE80211_CIPHER_WEP;
if (IEEE80211_IS_TKIP_ALLOWED(ic))
rsn->rsn_ucastcipherset |= 1 << IEEE80211_CIPHER_TKIP;
if (ic->ic_caps & IEEE80211_C_AES)
rsn->rsn_ucastcipherset |= 1 << IEEE80211_CIPHER_AES_OCB;
if (ic->ic_caps & IEEE80211_C_CKIP)
rsn->rsn_ucastcipherset |= 1 << IEEE80211_CIPHER_CKIP;
/*
* Default unicast cipher to WEP for 802.1x use. If
* WPA is enabled the management code will set these
* values to reflect.
*/
rsn->rsn_ucastcipher = IEEE80211_CIPHER_WEP;
rsn->rsn_ucastkeylen = 104 / NBBY;
/* Initialise with the lowest allowed mcast cipher */
if (!IEEE80211_IS_TKIP_ALLOWED(ic))
rsn->rsn_mcastcipher = IEEE80211_CIPHER_AES_CCM;
else
rsn->rsn_mcastcipher = IEEE80211_CIPHER_TKIP;
rsn->rsn_mcastkeylen = 128 / NBBY;
/*
* We support both WPA-PSK and 802.1x; the one used
* is determined by the authentication mode and the
* setting of the PSK state.
*/
rsn->rsn_keymgmtset = WPA_ASE_8021X_UNSPEC | WPA_ASE_8021X_PSK;
rsn->rsn_keymgmt = WPA_ASE_8021X_PSK;
vap->iv_auth = ieee80211_authenticator_get(vap->iv_bss->ni_authmode);
}
void
ieee80211_node_vdetach(struct ieee80211vap *vap)
{
struct ieee80211com *ic = vap->iv_ic;
if (vap->iv_bss != NULL)
ieee80211_ref_node(vap->iv_bss);
ieee80211_node_table_reset(ic, &ic->ic_sta, vap);
if (vap->iv_bss != NULL) {
ieee80211_free_node(vap->iv_bss);
vap->iv_bss = NULL;
}
}
/*
* Empty data frame used to do rate training. Goes through the normal
* data path, to trigger the rate adaptation algorithm to find the optimal rate
* before we send traffic.
*
* OUI extended Ethertype frame for Quantenna OUI is used for rate training
* packets. The bridge at the other end of the link will discard these frames
* as they are destined for the address of the WiFi interface, and there is
* no handler installed for this frame type.
*/
static void ieee80211_send_dummy_data(struct ieee80211_node *ni,
struct ieee80211vap *vap, int skb_flags)
{
struct qtn_skb_recycle_list *recycle_list = qtn_get_shared_recycle_list();
struct sk_buff *skb = qtn_skb_recycle_list_pop(recycle_list, &recycle_list->stats_qdrv);
struct qtn_dummy_frame *df;
int total_len = QTN_RATE_TRAIN_DATA_LEN + sizeof(*df) - sizeof(df->eh);
uint32_t *payload;
uint32_t *data;
if (!skb) {
/* If the recycle list is empty, use a smaller buffer to reduce memory pressure */
skb = dev_alloc_skb(QTN_RATE_TRAIN_DATA_LEN * 3);
if (!skb) {
return;
}
}
df = (struct qtn_dummy_frame *)skb_put(skb, sizeof(df->eh));
payload = (uint32_t *)skb_put(skb, total_len);
skb_reset_network_header(skb);
memcpy(df->eh.ether_shost, vap->iv_myaddr, sizeof(df->eh.ether_shost));
memcpy(df->eh.ether_dhost, ni->ni_macaddr, sizeof(df->eh.ether_dhost));
memset(payload, QTN_RATE_TRAIN_BYTE, total_len);
df->llc.llc_dsap = LLC_SNAP_LSAP;
df->llc.llc_ssap = LLC_SNAP_LSAP;
df->llc.llc_un.type_snap.control = LLC_UI;
df->llc.llc_un.type_snap.org_code[0] = 0;
df->llc.llc_un.type_snap.org_code[1] = 0;
df->llc.llc_un.type_snap.org_code[2] = 0;
df->llc.llc_un.type_snap.ether_type = htons(ETHERTYPE_802A);
ieee80211_oui_add_qtn(df->ouie.oui);
put_unaligned(htons(QTN_OUIE_TYPE_TRAINING), &df->ouie.type);
df->eh.ether_type = htons(total_len);
if (ni->ni_rate_train_hash) {
data = (uint32_t *)(df + 1);
put_unaligned(htonl(ni->ni_rate_train_hash), data + 1);
}
skb->dev = vap->iv_dev;
qdrv_sch_classify_bk(skb);
ieee80211_ref_node(ni);
QTN_SKB_CB_NI(skb) = ni;
M_FLAG_SET(skb, M_RATE_TRAINING);
M_FLAG_SET(skb, M_NO_AMSDU);
M_FLAG_SET(skb, M_VSP_CHK);
if (skb_flags != 0)
M_FLAG_SET(skb, (skb_flags));
dev_queue_xmit(skb);
}
/*
* Rate training - send a bunch of NULL data packets to get the rate
* retry algorithm to converge quickly.
*/
static void ieee80211_sta_add_training(unsigned long arg)
{
struct ieee80211_node *ni = (struct ieee80211_node *)arg;
struct ieee80211com *ic = ni->ni_ic;
struct ieee80211vap *vap = ni->ni_vap;
int i;
spin_lock(&ni->ni_lock);
if (ni->ni_training_count < vap->iv_rate_training_count) {
ni->ni_training_count++;
spin_unlock(&ni->ni_lock);
mod_timer(&ni->ni_training_timer, jiffies + 1);
for (i = 0; i < vap->iv_rate_training_burst_count; ++i) {
ieee80211_send_dummy_data(ni, vap, 0);
}
} else {
ni->ni_training_flag = NI_TRAINING_END;
spin_unlock(&ni->ni_lock);
printk("%s: [%pM] %s ends\n",
vap->iv_dev->name, ni->ni_macaddr,
ic->ic_ocac.ocac_running ? "T process" : "training");
ieee80211_free_node(ni);
}
}
/*
* Rate detecting - send a bunch of NULL data packets to get
* the current Tx rate.
*/
static void ieee80211_tdls_rate_detection(unsigned long arg)
{
struct ieee80211_node *ni = (struct ieee80211_node *)arg;
struct ieee80211vap *vap = ni->ni_vap;
int i;
if (ni->ni_training_count < vap->tdls_training_pkt_cnt) {
for (i = 0; i < DEFAULT_TDLS_RATE_DETECTION_BURST_CNT; ++i) {
ieee80211_send_dummy_data(ni, vap, 0);
}
ni->ni_training_count++;
mod_timer(&ni->ni_training_timer, jiffies + 2);
} else {
IEEE80211_TDLS_DPRINTF(vap, IEEE80211_MSG_TDLS, IEEE80211_TDLS_MSG_WARN,
"[%pM] rate detecting ends\n", ni->ni_macaddr);
spin_lock(&ni->ni_lock);
ni->ni_training_flag = NI_TRAINING_END;
spin_unlock(&ni->ni_lock);
ieee80211_free_node(ni);
}
}
static void ieee80211_add_assoc_record(struct ieee80211com *ic, struct ieee80211_node *ni)
{
struct ieee80211_assoc_history *ah = &ic->ic_assoc_history;
struct timeval time;
time_t oldest_time = ah->ah_timestamp[0];
int i, index = 0;
if (ni->ni_associd == 0) {
return;
}
do_gettimeofday(&time);
for (i = 0; i < IEEE80211_MAX_ASSOC_HISTORY; i++) {
if (IEEE80211_ADDR_EQ(ah->ah_macaddr_table[i], ni->ni_macaddr)) {
ah->ah_timestamp[i] = time.tv_sec;
return;
}
}
for (i = 0; i < IEEE80211_MAX_ASSOC_HISTORY; i++) {
if (ah->ah_timestamp[i] <= 0) {
IEEE80211_ADDR_COPY(ah->ah_macaddr_table[i], ni->ni_macaddr);
ah->ah_timestamp[i] = time.tv_sec;
return;
}
}
for (i = 1; i < IEEE80211_MAX_ASSOC_HISTORY; i++) {
if (ah->ah_timestamp[i] < oldest_time) {
oldest_time = ah->ah_timestamp[i];
index = i;
}
}
IEEE80211_ADDR_COPY(ah->ah_macaddr_table[index], ni->ni_macaddr);
ah->ah_timestamp[index] = time.tv_sec;
}
void ieee80211_active_training_timer(struct ieee80211_node *ni,
void (*call_back)(unsigned long), unsigned int interval)
{
if ((!ni) || (!call_back)) {
printk("%s: Get invalid arguments\n", __func__);
return;
}
/* Reference for the timer below */
spin_lock_bh(&ni->ni_lock);
/* If training already started, don't start new training. */
if (ni->ni_training_flag == NI_TRAINING_RUNNING) {
printk("%s: Rate training is running\n", __func__);
spin_unlock_bh(&ni->ni_lock);
return;
} else {
ieee80211_ref_node(ni);
}
ni->ni_training_count = 0;
ni->ni_training_flag = NI_TRAINING_RUNNING;
ni->ni_training_start = jiffies + interval;
spin_unlock_bh(&ni->ni_lock);
ni->ni_training_timer.function = call_back;
ni->ni_training_timer.data = (unsigned long)ni;
/*
* We stagger the start of the training for the node to prevent situations
* where all nodes associate immediately, causing out of resource due to
* allocating too many training packets.
*/
mod_timer(&ni->ni_training_timer, jiffies + interval);
}
static int ieee80211_node_training_required(const struct ieee80211_node *ni)
{
const int skip_training = TOPAZ_FPGA_PLATFORM || QTN_GENPCAP;
struct ieee80211vap *vap = ni->ni_vap;
uint32_t ret = 0;
/* We only do rate training for Q->Q links */
if (!skip_training && (ni->ni_qtn_assoc_ie != NULL)
&& (vap->iv_opmode != IEEE80211_M_WDS)) {
if (((vap->iv_opmode == IEEE80211_M_HOSTAP) && (ni != vap->iv_bss))
|| ((vap->iv_opmode == IEEE80211_M_STA) && (ni == vap->iv_bss))) {
ret = IEEE80211_NODE_TRAINING_NORMAL_MODE;
} else if (((vap->iv_opmode == IEEE80211_M_STA)
&& (vap->tdls_discovery_interval == 0)
&& IEEE80211_NODE_IS_TDLS_ACTIVE(ni))) {
ret = IEEE80211_NODE_TRAINING_TDLS_MODE;
}
}
return ret;
}
void ieee80211_node_training_start(struct ieee80211_node *ni, int immediate)
{
struct ieee80211com *ic = ni->ni_ic;
uint32_t training_delay_secs;
/*
* We stagger the start of the training for the node to prevent situations
* where all nodes associate immediately, causing out of resource due to
* allocating too many training packets.
*/
training_delay_secs = 1 + (immediate ? 0 : (IEEE80211_NODE_AID(ni) % 10));
/* Reference for the timer below */
spin_lock_bh(&ni->ni_lock);
/*
* If training already started, don't reference the node again or
* we could leak the node if it's discarded.
*
* This happens on the STA side as the BSS node is retained longer
* than on the AP side.
*/
if (ni->ni_training_flag != NI_TRAINING_RUNNING) {
ieee80211_ref_node(ni);
}
ni->ni_training_count = 0;
ni->ni_training_flag = NI_TRAINING_RUNNING;
spin_unlock_bh(&ni->ni_lock);
ni->ni_training_timer.function = ieee80211_sta_add_training;
ni->ni_training_timer.data = (unsigned long)ni;
mod_timer(&ni->ni_training_timer, jiffies + (training_delay_secs * HZ));
printk("%s: [%pM] %s starts in %d seconds, idx %u\n",
ni->ni_vap->iv_dev->name, ni->ni_macaddr,
ic->ic_ocac.ocac_running ? "T process" : "training",
training_delay_secs,
IEEE80211_NODE_IDX_UNMAP(ni->ni_node_idx));
}
void
_ieee80211_node_authorize(struct ieee80211_node *ni)
{
struct ieee80211vap *vap= ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
uint32_t ret;
ieee80211_add_assoc_record(ic, ni);
ni->ni_flags |= IEEE80211_NODE_AUTH;
ni->ni_inact_reload = vap->iv_inact_run;
ic->ic_node_auth_state_change(ni, 1);
ret = ieee80211_node_training_required(ni);
if (ret == IEEE80211_NODE_TRAINING_NORMAL_MODE) {
ieee80211_node_training_start(ni, 0);
} else if (ret == IEEE80211_NODE_TRAINING_TDLS_MODE) {
ieee80211_tdls_add_rate_detection(ni);
}
}
void
ieee80211_tdls_add_rate_detection(struct ieee80211_node *ni)
{
struct ieee80211vap *vap= ni->ni_vap;
struct ieee80211_node *ap_ni = vap->iv_bss;
unsigned int interval;
int smthd_rssi;
if (ap_ni == NULL)
return;
smthd_rssi = ieee80211_tdls_get_smoothed_rssi(vap, ni);
if (smthd_rssi < vap->tdls_min_valid_rssi)
return;
interval = HZ + (HZ * IEEE80211_NODE_AID(ap_ni) % 5) +
(HZ / 2 * (IEEE80211_NODE_AID(ni) % 10));
ieee80211_active_training_timer(ni, ieee80211_tdls_rate_detection, interval);
IEEE80211_TDLS_DPRINTF(vap, IEEE80211_MSG_TDLS, IEEE80211_TDLS_MSG_WARN,
"TDLS %s: Rate detection starts for %s AID %d at %lu\n", __func__,
ether_sprintf(ni->ni_macaddr), IEEE80211_NODE_AID(ni), jiffies + interval);
}
EXPORT_SYMBOL(ieee80211_tdls_add_rate_detection);
/*
* Port authorize/unauthorize interfaces for use by an authenticator.
*/
void
ieee80211_node_authorize(struct ieee80211_node *ni)
{
int msg = IEEE80211_DOT11_MSG_CLIENT_CONNECTED;
_ieee80211_node_authorize(ni);
if (ni->ni_vap->iv_opmode == IEEE80211_M_STA) {
msg = IEEE80211_DOT11_MSG_AP_CONNECTED;
}
if (ni->ni_authmode <= IEEE80211_AUTH_SHARED) {
ieee80211_eventf(ni->ni_vap->iv_dev, QEVT_COMMON_PREFIX" %s ["DBGMAC"] [%s/%s] SSID %s",
d11_m[msg],
ETHERFMT(ni->ni_bssid),
ni->ni_authmode <= IEEE80211_AUTH_OPEN ? "OPEN" : "SHARED",
"NONE",
ni->ni_essid);
}
}
EXPORT_SYMBOL(ieee80211_node_authorize);
void
ieee80211_node_unauthorize(struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
struct ieee80211vap *vap = ni->ni_vap;
if (ieee80211_node_is_authorized(ni) &&
!IEEE80211_ADDR_EQ(vap->iv_myaddr, ni->ni_macaddr))
vap->iv_disconn_cnt++;
ni->ni_flags &= ~IEEE80211_NODE_AUTH;
ic->ic_node_auth_state_change(ni, 0);
}
EXPORT_SYMBOL(ieee80211_node_unauthorize);
/*
* Set/change the channel. The rate set is also updated
* to ensure a consistent view by drivers.
*/
void
ieee80211_node_set_chan(struct ieee80211com *ic, struct ieee80211_node *ni)
{
struct ieee80211_channel *chan = ic->ic_bsschan;
KASSERT(chan != IEEE80211_CHAN_ANYC, ("BSS channel not set up"));
ni->ni_chan = chan;
if (IEEE80211_IS_CHAN_HALF(ic->ic_curchan)) {
ni->ni_rates = ic->ic_sup_half_rates;
} else if (IEEE80211_IS_CHAN_QUARTER(ic->ic_curchan)) {
ni->ni_rates = ic->ic_sup_quarter_rates;
} else {
ni->ni_rates = ic->ic_sup_rates[ic->ic_curmode];
}
}
static __inline void
copy_bss(struct ieee80211_node *nbss, const struct ieee80211_node *obss)
{
/* propagate useful state */
nbss->ni_authmode = obss->ni_authmode;
nbss->ni_ath_flags = obss->ni_ath_flags;
nbss->ni_txpower = obss->ni_txpower;
nbss->ni_vlan = obss->ni_vlan;
nbss->ni_rsn = obss->ni_rsn;
/* XXX statistics? */
}
/*
* Create an IBSS or BSS.
*/
void
ieee80211_create_bss(struct ieee80211vap* vap, struct ieee80211_channel *chan)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *ni;
struct ieee80211_channel *previous_chann = NULL;
if (vap->iv_opmode == IEEE80211_M_WDS) {
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
"%s: skipping for WDS mode\n",
__func__);
if (ic->ic_bsschan == IEEE80211_CHAN_ANYC) {
ni = ieee80211_find_node(&ic->ic_sta, vap->iv_myaddr);
if (!ni)
return;
/* Ensure ic_bsschan is set if WDS has been created first */
ic->ic_bsschan = chan;
ieee80211_node_set_chan(ic, ni);
ieee80211_free_node(ni);
}
return;
}
IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN,
"%s: creating on channel %u\n", __func__,
ieee80211_chan2ieee(ic, chan));
/* Check to see if we already have a node for this mac */
ni = ieee80211_find_node(&ic->ic_sta, vap->iv_myaddr);
if (ni == NULL) {
ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr, "bss create");
}
KASSERT(ni != NULL, ("unable to find or create BSS node"));
ni->ni_node_idx = vap->iv_vapnode_idx;
ni->ni_vhtop.chanwidth = ic->ic_vhtop.chanwidth;
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
ni->ni_esslen = vap->iv_des_ssid[0].len;
memcpy(ni->ni_essid, vap->iv_des_ssid[0].ssid, ni->ni_esslen);
if (vap->iv_bss != NULL)
copy_bss(ni, vap->iv_bss);
ni->ni_intval = ic->ic_lintval;
if (vap->iv_flags & IEEE80211_F_PRIVACY)
ni->ni_capinfo |= IEEE80211_CAPINFO_PRIVACY;
if (ic->ic_phytype == IEEE80211_T_FH) {
ni->ni_fhdwell = 200; /* XXX */
ni->ni_fhindex = 1;
}
if (vap->iv_opmode == IEEE80211_M_IBSS) {
vap->iv_flags |= IEEE80211_F_SIBSS;
ni->ni_capinfo |= IEEE80211_CAPINFO_IBSS; /* XXX */
if (vap->iv_flags & IEEE80211_F_DESBSSID)
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
else
ni->ni_bssid[0] |= 0x02; /* local bit for IBSS */
} else if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
if (vap->iv_flags & IEEE80211_F_DESBSSID)
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
else {
ni->ni_bssid[0] = 0x00;
ni->ni_bssid[1] = 0x00;
ni->ni_bssid[2] = 0x00;
ni->ni_bssid[3] = 0x00;
ni->ni_bssid[4] = 0x00;
ni->ni_bssid[5] = 0x00;
}
}
ni->ni_vendor = PEER_VENDOR_QTN;
if (vap->iv_opmode == IEEE80211_M_HOSTAP)
ni->ni_node_type = IEEE80211_NODE_TYPE_VAP;
else if (vap->iv_opmode == IEEE80211_M_STA)
ni->ni_node_type = IEEE80211_NODE_TYPE_STA;
/* clear DFS CAC state on previous channel */
if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
ic->ic_bsschan->ic_freq != chan->ic_freq &&
IEEE80211_IS_CHAN_CACDONE(ic->ic_bsschan)) {
/*
* IEEE80211_CHAN_DFS_CAC_DONE indicates whether or not to do CAC afresh.
* US : IEEE80211_CHAN_DFS_CAC_DONE shall be cleared whenver we move to
* a different channel
* ETSI : IEEE80211_CHAN_DFS_CAC_DONE shall be retained; Only event which
* would mark the channel as unusable is the radar indication
*/
if (ic->ic_dfs_is_eu_region() == false) {
previous_chann = ic->ic_bsschan;
previous_chann->ic_flags &= ~IEEE80211_CHAN_DFS_CAC_DONE;
if (ic->ic_mark_channel_dfs_cac_status) {
ic->ic_mark_channel_dfs_cac_status(ic, previous_chann, IEEE80211_CHAN_DFS_CAC_DONE, false);
ic->ic_mark_channel_dfs_cac_status(ic, previous_chann, IEEE80211_CHAN_DFS_CAC_IN_PROGRESS, false);
}
/* Mark the channel as not_available and ready for cac */
if (ic->ic_mark_channel_availability_status) {
ic->ic_mark_channel_availability_status(ic, previous_chann,
IEEE80211_CHANNEL_STATUS_NOT_AVAILABLE_CAC_REQUIRED);
}
printk(KERN_DEBUG "ieee80211_create_bss:"
"Clearing CAC_DONE Status for chan %d\n",
previous_chann->ic_ieee);
}
}
/*
* Fix the channel and related attributes.
* If a channel change was initiated, ieee80211_channel_switch_post will handle it
*/
ic->ic_bsschan = chan;
ieee80211_node_set_chan(ic, ni);
ieee80211_sta_join1(vap, ni, 0);
ieee80211_free_node(ni);
}
EXPORT_SYMBOL(ieee80211_create_bss);
/*
* Reset bss state on transition to the INIT state.
* Clear any stations from the table (they have been
* deauth'd) and reset the bss node (clears key, rate,
* etc. state).
*/
void
ieee80211_reset_bss(struct ieee80211vap *vap)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *obss = vap->iv_bss;
struct ieee80211_node *ni;
if (vap->iv_opmode == IEEE80211_M_WDS) {
vap->iv_bss = NULL;
return;
}
if (obss != NULL) {
ieee80211_ref_node(obss);
}
ieee80211_node_table_reset(ic, &ic->ic_sta, vap);
ieee80211_reset_erp(ic, ic->ic_curmode);
ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr, "bss reset");
KASSERT(ni != NULL, ("unable to set up BSS node"));
ni->ni_vendor = PEER_VENDOR_QTN;
if (vap->iv_opmode == IEEE80211_M_HOSTAP)
ni->ni_node_type = IEEE80211_NODE_TYPE_VAP;
else if (vap->iv_opmode == IEEE80211_M_STA)
ni->ni_node_type = IEEE80211_NODE_TYPE_STA;
vap->iv_bss = ni;
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_myaddr);
if (obss != NULL) {
copy_bss(ni, obss);
ni->ni_intval = ic->ic_lintval;
ieee80211_free_node(obss);
}
ieee80211_free_node(ni);
}
static int
match_ssid(const struct ieee80211_node *ni,
int nssid, const struct ieee80211_scan_ssid ssids[])
{
int i;
if (!ni)
return 0;
for (i = 0; i < nssid; i++) {
if (ni->ni_esslen == ssids[i].len &&
memcmp(ni->ni_essid, ssids[i].ssid, ni->ni_esslen) == 0)
return 1;
}
return 0;
}
/*
* Test a node for suitability/compatibility.
*/
static int
check_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
uint8_t rate;
unsigned int chan;
chan = ieee80211_chan2ieee(ic, ni->ni_chan);
if (unlikely(chan == IEEE80211_CHAN_ANY))
return 0;
if (isclr(ic->ic_chan_active, chan))
return 0;
if (vap->iv_opmode == IEEE80211_M_IBSS) {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
return 0;
} else {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
return 0;
}
if (vap->iv_flags & IEEE80211_F_PRIVACY) {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
return 0;
} else {
/* Reference: IEEE802.11 7.3.1.4
* This means that the data confidentiality service is required
* for all frames exchanged with this STA in IBSS and for all
* frames exchanged within the entire BSS otherwise
*/
if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
return 0;
}
rate = ieee80211_fix_rate(ni, IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
if (rate & IEEE80211_RATE_BASIC)
return 0;
if (vap->iv_des_nssid != 0 &&
!match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
return 0;
if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
!IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
return 0;
return 1;
}
#ifdef IEEE80211_DEBUG
/*
* Display node suitability/compatibility.
*/
static void
check_bss_debug(struct ieee80211vap *vap, struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
uint8_t rate;
unsigned int chan;
int fail;
chan = ieee80211_chan2ieee(ic, ni->ni_chan);
fail = 0;
if (chan == IEEE80211_CHAN_ANY || isclr(ic->ic_chan_active, chan))
fail |= 0x01;
if (vap->iv_opmode == IEEE80211_M_IBSS) {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
fail |= 0x02;
} else {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_ESS) == 0)
fail |= 0x02;
}
if (vap->iv_flags & IEEE80211_F_PRIVACY) {
if ((ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) == 0)
fail |= 0x04;
} else {
/* This means that the data confidentiality service is required
* for all frames exchanged within this BSS. (IEEE802.11 7.3.1.4)
*/
if (ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY)
fail |= 0x04;
}
rate = ieee80211_fix_rate(ni, IEEE80211_F_DONEGO | IEEE80211_F_DOFRATE);
if (rate & IEEE80211_RATE_BASIC)
fail |= 0x08;
if (vap->iv_des_nssid != 0 &&
!match_ssid(ni, vap->iv_des_nssid, vap->iv_des_ssid))
fail |= 0x10;
if ((vap->iv_flags & IEEE80211_F_DESBSSID) &&
!IEEE80211_ADDR_EQ(vap->iv_des_bssid, ni->ni_bssid))
fail |= 0x20;
printk(" %c %s", fail ? '-' : '+', ether_sprintf(ni->ni_macaddr));
printk(" %s%c", ether_sprintf(ni->ni_bssid), fail & 0x20 ? '!' : ' ');
printk(" %3d%c",
chan, fail & 0x01 ? '!' : ' ');
printk(" %+4d", ni->ni_rssi);
printk(" %2dM%c", (rate & IEEE80211_RATE_VAL) / 2,
fail & 0x08 ? '!' : ' ');
printk(" %4s%c",
(ni->ni_capinfo & IEEE80211_CAPINFO_ESS) ? "ess" :
(ni->ni_capinfo & IEEE80211_CAPINFO_IBSS) ? "ibss" :
"????",
fail & 0x02 ? '!' : ' ');
printk(" %3s%c ",
(ni->ni_capinfo & IEEE80211_CAPINFO_PRIVACY) ? "wep" : "no",
fail & 0x04 ? '!' : ' ');
ieee80211_print_essid(ni->ni_essid, ni->ni_esslen);
printk("%s\n", fail & 0x10 ? "!" : "");
}
#endif /* IEEE80211_DEBUG */
/*
* Handle 802.11 ad hoc network merge. The
* convention, set by the Wireless Ethernet Compatibility Alliance
* (WECA), is that an 802.11 station will change its BSSID to match
* the "oldest" 802.11 ad hoc network, on the same channel, that
* has the station's desired SSID. The "oldest" 802.11 network
* sends beacons with the greatest TSF timestamp.
*
* The caller is assumed to validate TSF's before attempting a merge.
*
* Return !0 if the BSSID changed, 0 otherwise.
*/
int
ieee80211_ibss_merge(struct ieee80211_node *ni)
{
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = ni->ni_ic;
if (ni == vap->iv_bss ||
IEEE80211_ADDR_EQ(ni->ni_bssid, vap->iv_bss->ni_bssid)) {
/* unchanged, nothing to do */
return 0;
}
if (!check_bss(vap, ni)) {
/* capabilities mismatch */
IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
"%s: merge failed, capabilities mismatch\n", __func__);
#ifdef IEEE80211_DEBUG
if (ieee80211_msg_assoc(vap))
check_bss_debug(vap, ni);
#endif
vap->iv_stats.is_ibss_capmismatch++;
return 0;
}
IEEE80211_DPRINTF(vap, IEEE80211_MSG_ASSOC,
"%s: new bssid %s: %s preamble, %s slot time%s\n", __func__,
ether_sprintf(ni->ni_bssid),
ic->ic_flags & IEEE80211_F_SHPREAMBLE ? "short" : "long",
ic->ic_flags & IEEE80211_F_SHSLOT ? "short" : "long",
ic->ic_flags & IEEE80211_F_USEPROT ? ", protection" : "");
ieee80211_ref_node(ni);
ieee80211_sta_join1(vap, ni, 0);
return 1;
}
EXPORT_SYMBOL(ieee80211_ibss_merge);
static __inline int
ssid_equal(const struct ieee80211_node *a, const struct ieee80211_node *b)
{
if (!a || !b)
return 0;
return (a->ni_esslen == b->ni_esslen &&
memcmp(a->ni_essid, b->ni_essid, a->ni_esslen) == 0);
}
void ieee80211_update_active_chanlist(struct ieee80211com *ic, int bw)
{
COMPILE_TIME_ASSERT(sizeof(ic->ic_chan_active) == sizeof(ic->ic_chan_active_80));
COMPILE_TIME_ASSERT(sizeof(ic->ic_chan_active) == sizeof(ic->ic_chan_active_40));
COMPILE_TIME_ASSERT(sizeof(ic->ic_chan_active) == sizeof(ic->ic_chan_active_20));
switch(bw) {
case BW_HT80:
memcpy(ic->ic_chan_active, ic->ic_chan_active_80, sizeof(ic->ic_chan_active));
break;
case BW_HT40:
memcpy(ic->ic_chan_active, ic->ic_chan_active_40, sizeof(ic->ic_chan_active));
break;
default:
memcpy(ic->ic_chan_active, ic->ic_chan_active_20, sizeof(ic->ic_chan_active));
break;
}
}
void ieee80211_nonqtn_sta_join(struct ieee80211vap *vap,
struct ieee80211_node *ni, const char *caller)
{
struct ieee80211com *ic = vap->iv_ic;
if (!ieee80211_node_is_qtn(ni)) {
vap->iv_non_qtn_sta_assoc++;
ic->ic_nonqtn_sta++;
ieee80211_set_recv_ctrlpkts(vap);
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
"%s - increases counter ic_nonqtn_sta %u, iv_non_qtn_sta_assoc %u\n",
caller, ic->ic_nonqtn_sta, vap->iv_non_qtn_sta_assoc);
}
}
void ieee80211_nonqtn_sta_leave(struct ieee80211vap *vap,
struct ieee80211_node *ni, const char *caller)
{
struct ieee80211com *ic = vap->iv_ic;
if (!ieee80211_node_is_qtn(ni)) {
WARN_ON(ic->ic_nonqtn_sta == 0);
WARN_ON(vap->iv_non_qtn_sta_assoc == 0);
if (ic->ic_nonqtn_sta > 0)
ic->ic_nonqtn_sta--;
if (vap->iv_non_qtn_sta_assoc > 0)
vap->iv_non_qtn_sta_assoc--;
ieee80211_set_recv_ctrlpkts(vap);
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
"%s - reduces counter ic_nonqtn_sta %u, iv_non_qtn_sta_assoc %u\n",
caller, ic->ic_nonqtn_sta, vap->iv_non_qtn_sta_assoc);
}
}
static void
ieee80211_reset_bw(struct ieee80211vap *vap, struct ieee80211com *ic, int channel, int delay_ch_switch)
{
int bw;
int max_channel_bw;
int cur_bw = ieee80211_get_cap_bw(ic);
if (vap->iv_opmode != IEEE80211_M_STA) {
return;
}
max_channel_bw = ieee80211_get_max_channel_bw(ic, channel);
bw = MIN(MIN(ic->ic_max_system_bw, max_channel_bw), ic->ic_bss_bw);
if (bw >= BW_HT80 && !IS_IEEE80211_VHT_ENABLED(ic)) {
bw = BW_HT40;
}
if ((bw > BW_HT40) && !ieee80211_swfeat_is_supported(SWFEAT_ID_VHT, 1)) {
printk("BW %d is not supported on this device\n", bw);
bw = BW_HT40;
}
if ((bw >= BW_HT40) && (ic->ic_curmode == IEEE80211_MODE_11A)) {
bw = BW_HT20;
}
if ((ic->ic_curmode == IEEE80211_MODE_11B) ||
(ic->ic_curmode == IEEE80211_MODE_11G) ||
(ic->ic_curmode == IEEE80211_MODE_11NG)) {
bw = BW_HT20;
}
if (ic->ic_curmode == IEEE80211_MODE_11NG_HT40PM) {
bw = BW_HT40;
}
if (bw == cur_bw)
return;
ieee80211_change_bw(vap, bw, delay_ch_switch);
}
/*
* Restore bandwidth to initial state.
*/
void
ieee80211_restore_bw(struct ieee80211vap *vap, struct ieee80211com *ic)
{
int bw = ic->ic_max_system_bw;
int cur_bw = ieee80211_get_cap_bw(ic);
if (vap->iv_opmode != IEEE80211_M_STA)
return;
if ((bw >= BW_HT80) &&
(!IS_IEEE80211_VHT_ENABLED(ic) ||
!ieee80211_swfeat_is_supported(SWFEAT_ID_VHT, 1)))
bw = BW_HT40;
if ((bw >= BW_HT40) &&
((ic->ic_curmode == IEEE80211_MODE_11A) ||
(ic->ic_curmode == IEEE80211_MODE_11B) ||
(ic->ic_curmode == IEEE80211_MODE_11G) ||
(ic->ic_curmode == IEEE80211_MODE_11NG) ||
(ic->ic_curmode == IEEE80211_MODE_11NA)))
bw = BW_HT20;
ic->ic_bss_bw = bw;
if (bw == cur_bw)
return;
ieee80211_change_bw(vap, bw, 0);
}
/*
* Set phymode, bw and vht params specific to band
*/
void
configure_phy_mode(struct ieee80211vap *vap, struct ieee80211_node *selbs)
{
struct ieee80211com *ic = selbs->ni_ic;
int aggr = 1;
if (selbs->ni_chan->ic_ieee > QTN_2G_LAST_OPERATING_CHAN) {
if (vap->iv_5ghz_prof.phy_mode == IEEE80211_MODE_11NA) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11NA;
vap->iv_5ghz_prof.bw = BW_HT20;
vap->iv_5ghz_prof.vht = 0;
} else if (vap->iv_5ghz_prof.phy_mode == IEEE80211_MODE_11NA_HT40PM) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11NA_HT40PM;
vap->iv_5ghz_prof.bw = BW_HT40;
vap->iv_5ghz_prof.vht = 0;
} else if (vap->iv_5ghz_prof.phy_mode == IEEE80211_MODE_11AC_VHT20PM) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11AC_VHT20PM;
vap->iv_5ghz_prof.bw = BW_HT20;
vap->iv_5ghz_prof.vht = 1;
} else if (vap->iv_5ghz_prof.phy_mode == IEEE80211_MODE_11AC_VHT40PM) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11AC_VHT40PM;
vap->iv_5ghz_prof.bw = BW_HT40;
vap->iv_5ghz_prof.vht = 1;
} else {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11AC_VHT80PM;
vap->iv_5ghz_prof.bw = BW_HT80;
vap->iv_5ghz_prof.vht = 1;
}
ieee80211_setmode(ic, ic->ic_des_mode);
ic->ic_csw_reason = IEEE80211_CSW_REASON_CONFIG;
ieee80211_change_bw(vap, vap->iv_5ghz_prof.bw, 0);
ieee80211_param_to_qdrv(vap, IEEE80211_PARAM_MODE, vap->iv_5ghz_prof.vht, NULL, 0);
} else {
if (vap->iv_2_4ghz_prof.phy_mode == IEEE80211_MODE_11B) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11B;
vap->iv_2_4ghz_prof.bw = BW_HT20;
} else if (vap->iv_2_4ghz_prof.phy_mode == IEEE80211_MODE_11G) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11G;
vap->iv_2_4ghz_prof.bw = BW_HT20;
} else if (vap->iv_2_4ghz_prof.phy_mode == IEEE80211_MODE_11NG) {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11NG;
vap->iv_2_4ghz_prof.bw = BW_HT20;
} else {
ic->ic_des_mode = ic->ic_phymode = IEEE80211_MODE_11NG_HT40PM;
vap->iv_2_4ghz_prof.bw = BW_HT40;
}
ieee80211_setmode(ic, ic->ic_des_mode);
ieee80211_start_obss_scan_timer(vap);
ieee80211_change_bw(vap, vap->iv_2_4ghz_prof.bw, 0);
ieee80211_param_to_qdrv(vap, IEEE80211_PARAM_PHY_MODE, ic->ic_phymode, NULL, 0);
}
ieee80211_param_to_qdrv(vap, IEEE80211_PARAM_TX_AMSDU, aggr, NULL, 0);
ieee80211_param_to_qdrv(vap, IEEE80211_PARAM_AGGREGATION, aggr, NULL, 0);
}
static void ieee80211_repeater_csa_finish(unsigned long arg)
{
struct ieee80211com *ic = (struct ieee80211com *)arg;
struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
KASSERT((vap->iv_opmode == IEEE80211_M_STA
&& (ic->ic_flags_ext & IEEE80211_FEXT_REPEATER)), ("Should only be called for repeater STA interface"));
ieee80211_finish_csa(arg);
/* finish the undone job left by ieee80211_sta_join1 */
IEEE80211_SCHEDULE_TQUEUE(&vap->iv_stajoin1tq);
}
/*
* Join the specified IBSS/BSS network. The node is assumed to
* be passed in with a reference already held for use in assigning
* to iv_bss.
*/
void
ieee80211_sta_join1(struct ieee80211vap *vap, struct ieee80211_node *selbs, int reauth)
{
struct ieee80211com *ic = selbs->ni_ic;
struct ieee80211_node *obss = vap->iv_bss;
struct ieee80211_node_table *nt = &ic->ic_sta;
struct ieee80211com *ic_sta = vap->iv_ic;
int canreassoc;
int cur_band, new_band;
u_int8_t bridge_mode_changed;
int start_csa = (vap->iv_opmode == IEEE80211_M_STA
&& (ic->ic_flags_ext & IEEE80211_FEXT_REPEATER));
cur_band = new_band = 0;
if (vap->iv_opmode == IEEE80211_M_IBSS) {
/*
* Delete unusable rates; we've already checked
* that the negotiated rate set is acceptable.
*/
ieee80211_fix_rate(selbs, IEEE80211_F_DODEL);
ieee80211_fix_ht_rate(selbs, IEEE80211_F_DODEL);
}
/* Set bridge mode according to AP's capabilities and local config */
bridge_mode_changed = ieee80211_bridgemode_set(vap, 0);
/*
* Check if old+new node have the same ssid in which
* case we can reassociate when operating in sta mode.
*/
canreassoc = (obss != NULL &&
vap->iv_state >= IEEE80211_S_ASSOC &&
ssid_equal(obss, selbs) &&
!bridge_mode_changed);
if ((obss != NULL) && (obss != selbs) &&
(vap->iv_state >= IEEE80211_S_ASSOC)) {
#if defined(QBMPS_ENABLE)
if ((ic->ic_flags_qtn & IEEE80211_QTN_BMPS) &&
(vap->iv_opmode == IEEE80211_M_STA)) {
/* exit power-saving */
ic->ic_pm_reason = IEEE80211_PM_LEVEL_JOIN_BSS;
ieee80211_pm_queue_work(ic);
}
#endif
IEEE80211_SEND_MGMT(obss,
IEEE80211_FC0_SUBTYPE_DISASSOC,
IEEE80211_REASON_ASSOC_LEAVE);
/*
* Ensure that the deauth/disassoc frame is sent
* before the node is deleted.
*/
ieee80211_safe_wait_ms(50, !in_interrupt());
}
vap->iv_bss = selbs;
if ((obss != NULL) && (obss != selbs)) {
if (vap->iv_opmode == IEEE80211_M_STA) {
ic->ic_new_assoc(selbs);
}
ic->ic_disassoc(obss);
IEEE80211_NODE_LOCK_IRQ(nt);
ieee80211_node_reclaim(nt, obss);
IEEE80211_NODE_UNLOCK_IRQ(nt);
}
/* Update secondary channel offset base on htop */
if (selbs->ni_chan->ic_ieee <= QTN_2G_LAST_OPERATING_CHAN)
ieee80211_update_sec_chan_offset(selbs->ni_chan, selbs->ni_htinfo.choffset);
/* check if required to update phymode and bandwidth */
if (ic->ic_rf_chipid == CHIPID_DUAL) {
if (selbs->ni_chan->ic_ieee > QTN_2G_LAST_OPERATING_CHAN)
new_band = FREQ_5_GHZ;
else
new_band = FREQ_2_4_GHZ;
if (ic_sta->ic_curchan->ic_ieee > QTN_2G_LAST_OPERATING_CHAN)
cur_band = FREQ_5_GHZ;
else
cur_band = FREQ_2_4_GHZ;
if (cur_band != new_band)
configure_phy_mode(vap, selbs);
}
ic->ic_bsschan = selbs->ni_chan;
ic->ic_curchan = selbs->ni_chan;
ic->ic_fast_reass_chan = selbs->ni_chan;
ic->ic_fast_reass_scan_cnt = 0;
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE | IEEE80211_MSG_SCAN,
"Fast reassoc chan=%u fast=%u state=%u\n",
(ic->ic_fast_reass_chan && (ic->ic_fast_reass_chan != IEEE80211_CHAN_ANYC)) ?
ic->ic_fast_reass_chan->ic_ieee : 0,
canreassoc,
vap->iv_state);
if (start_csa) {
ieee80211_cancel_scan_no_wait(vap);
ieee80211_enter_csa(ic, ic->ic_curchan,
ieee80211_repeater_csa_finish,
IEEE80211_CSW_REASON_SCAN,
IEEE80211_DEFAULT_CHANCHANGE_TBTT_COUNT,
IEEE80211_CSA_MUST_STOP_TX,
IEEE80211_CSA_F_BEACON | IEEE80211_CSA_F_ACTION);
} else {
ic->ic_set_channel(ic);
}
if ((vap->iv_opmode == IEEE80211_M_HOSTAP) ||
(vap->iv_opmode == IEEE80211_M_STA))
ieee80211_build_countryie(ic);
/*
* Set the erp state (mostly the slot time) to deal with
* the auto-select case; this should be redundant if the
* mode is locked.
*/
if (ic->ic_curmode != IEEE80211_MODE_11B) {
ieee80211_reset_erp(ic, ic->ic_curmode);
}
if (reauth && vap->iv_opmode == IEEE80211_M_STA) {
/*
* Reset the bw before association to minimum of
* max_system_bw and max_channel_bw.
*/
ieee80211_reset_bw(vap, ic, selbs->ni_chan->ic_ieee, start_csa);
/*
* Act as if we received a DEAUTH frame in case we are
* invoked from the RUN state. This will cause us to try
* to re-authenticate if we are operating as a station.
*/
if (canreassoc) {
vap->iv_nsparams.newstate = IEEE80211_S_ASSOC;
vap->iv_nsparams.arg = 0;
} else {
vap->iv_nsparams.newstate = IEEE80211_S_AUTH;
vap->iv_nsparams.arg = IEEE80211_FC0_SUBTYPE_DEAUTH;
}
} else {
vap->iv_nsparams.newstate = IEEE80211_S_RUN;
vap->iv_nsparams.arg = -1;
}
if (!start_csa)
IEEE80211_SCHEDULE_TQUEUE(&vap->iv_stajoin1tq);
}
static void ieee80211_bringup_repeater_sta(struct ieee80211com *ic, struct ieee80211vap *ap_vap)
{
struct ieee80211vap *vap;
if (ap_vap->iv_opmode != IEEE80211_M_HOSTAP)
return;
vap = TAILQ_FIRST(&ic->ic_vaps);
if (vap->iv_state == IEEE80211_S_INIT
&& (ic->ic_flags_ext & IEEE80211_FEXT_REPEATER)) {
if ((ic->ic_flags & IEEE80211_F_SCAN)
#ifdef QTN_BG_SCAN
|| (ic->ic_flags_qtn & IEEE80211_QTN_BGSCAN)
#endif
)
IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE,
"%s:Scan in progress\n",__func__);
ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
}
}
void
ieee80211_sta_join1_tasklet(IEEE80211_TQUEUE_ARG data)
{
struct ieee80211vap *vap= (struct ieee80211vap *) data;
int rc;
rc = ieee80211_new_state(vap, vap->iv_nsparams.newstate, vap->iv_nsparams.arg);
vap->iv_nsparams.result = rc;
vap->iv_nsdone = 1;
/* Enable system xmit for DFS slave */
vap->iv_ic->ic_sta_set_xmit(true);
ieee80211_bringup_repeater_sta(vap->iv_ic, vap);
}
EXPORT_SYMBOL(ieee80211_sta_join1_tasklet);
extern int
ieee80211_get_rsn_from_ie(struct ieee80211vap *vap, u_int8_t *frm,
struct ieee80211_rsnparms *rsn_parm);
int
ieee80211_sta_join(struct ieee80211vap *vap,
const struct ieee80211_scan_entry *se)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *bss_ni = vap->iv_bss;
struct ieee80211_node *ni;
uint8_t bss_bw;
if (!bss_ni) {
bss_ni = TAILQ_FIRST(&ic->ic_vaps)->iv_bss;
if (!bss_ni) {
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
"%s: no bss node\n", __func__);
return 0;
}
}
ni = ieee80211_find_node(&ic->ic_sta, se->se_macaddr);
if (ni == NULL) {
ni = ieee80211_alloc_node(&ic->ic_sta, vap, se->se_macaddr, "join");
if (ni == NULL) {
IEEE80211_DPRINTF(vap, IEEE80211_MSG_NODE,
"%s: failed to alloc node\n", __func__);
return 0;
}
}
/* Inherit some params from BSS */
ni->ni_authmode = bss_ni->ni_authmode;
ni->ni_rsn = bss_ni->ni_rsn;
/* Expand scan state into node's format */
IEEE80211_ADDR_COPY(ni->ni_bssid, se->se_bssid);
ni->ni_esslen = se->se_ssid[1];
memcpy(ni->ni_essid, se->se_ssid + 2, ni->ni_esslen);
ni->ni_rstamp = se->se_rstamp;
ni->ni_tstamp.tsf = se->se_tstamp.tsf;
ni->ni_intval = IEEE80211_BINTVAL_SANITISE(se->se_intval);
ni->ni_capinfo = se->se_capinfo;
ni->ni_chan = se->se_chan;
ni->ni_timoff = se->se_timoff;
ni->ni_fhdwell = se->se_fhdwell;
ni->ni_fhindex = se->se_fhindex;
ni->ni_erp = se->se_erp;
ni->ni_rssi = se->se_rssi;
ni->ni_node_type = IEEE80211_NODE_TYPE_VAP;
ni->tdls_status = IEEE80211_TDLS_NODE_STATUS_NONE;
if (se->se_htcap_ie != NULL) {
ieee80211_parse_htcap(ni, se->se_htcap_ie);
ni->ni_flags |= IEEE80211_NODE_HT;
} else {
ni->ni_flags &= ~IEEE80211_NODE_HT;
}
if (se->se_htinfo_ie != NULL)
ieee80211_parse_htinfo(ni, se->se_htinfo_ie);
if (se->se_vhtcap_ie != NULL)
ieee80211_parse_vhtcap(ni, se->se_vhtcap_ie);
if (se->se_vhtop_ie != NULL)
ieee80211_parse_vhtop(ni, se->se_vhtop_ie);
if (se->se_wpa_ie != NULL)
ieee80211_saveie(&ni->ni_wpa_ie, se->se_wpa_ie);
if (se->se_rsn_ie != NULL)
ieee80211_saveie(&ni->ni_rsn_ie, se->se_rsn_ie);
if (se->se_wme_ie != NULL)
ieee80211_saveie(&ni->ni_wme_ie, se->se_wme_ie);
if (se->se_qtn_ie != NULL)
ieee80211_saveie(&ni->ni_qtn_assoc_ie, se->se_qtn_ie);
if (se->se_ath_ie != NULL)
ieee80211_saveath(ni, se->se_ath_ie);
ni->ni_ext_role = se->se_ext_role;
if (se->se_ext_bssid_ie != NULL)
ieee80211_saveie(&ni->ni_ext_bssid_ie, se->se_ext_bssid_ie);
/*
* Parse and fill the rsn_cap here only. The remaining of rsn params is gotten from bss above
*/
if(ni->ni_rsn_ie) {
struct ieee80211_rsnparms rsn_param;
u_int8_t res = 0;
memset((u_int8_t*)&rsn_param, 0, sizeof(rsn_param));
res = ieee80211_get_rsn_from_ie(vap, ni->ni_rsn_ie, &rsn_param);
if(res == 0) {
ni->ni_rsn.rsn_caps = rsn_param.rsn_caps;
if (!vap->iv_pmf) {
ni->ni_rsn.rsn_caps &= ~(RSN_CAP_MFP_REQ | RSN_CAP_MFP_CAP);
}
}
}
vap->iv_qtn_ap_cap = se->se_qtn_ie_flags;
vap->iv_is_qtn_dev = se->se_is_qtn_dev;
vap->iv_dtim_period = se->se_dtimperiod;
vap->iv_dtim_count = 0;
vap->iv_local_max_txpow = se->local_max_txpwr;
/* NB: must be after ni_chan is set up */
ieee80211_setup_rates(ni, se->se_rates, se->se_xrates,
IEEE80211_F_DOSORT | IEEE80211_F_DONEGO | IEEE80211_F_DODEL);
if (IEEE80211_VHTOP_GET_CHANWIDTH(&ni->ni_ie_vhtop)
>= IEEE80211_VHTOP_CHAN_WIDTH_80MHZ)
bss_bw = BW_HT80;
else if (ni->ni_ie_htinfo.hi_byte1 & IEEE80211_HTINFO_B1_REC_TXCHWIDTH_40)
bss_bw = BW_HT40;
else
bss_bw = BW_HT20;
ic->ic_bss_bw = MIN(bss_bw, ic->ic_max_system_bw);
if (ic->sta_dfs_info.sta_dfs_strict_mode &&
ieee80211_is_chan_not_available(ni->ni_chan) &&
ic->ic_mark_channel_availability_status) {
ic->ic_mark_channel_availability_status(ic, ni->ni_chan,
IEEE80211_CHANNEL_STATUS_AVAILABLE);
}
ieee80211_sta_join1(vap, ni, 1);
ieee80211_free_node(ni);
return 1;
}
EXPORT_SYMBOL(ieee80211_sta_join);
static __inline void
ieee80211_clear_aid_bitmap(struct ieee80211com *ic, uint16_t aid)
{
if (IEEE80211_AID(aid) < QTN_NODE_TBL_SIZE_LHOST)
IEEE80211_AID_CLR(ic, aid);
}
static void
ieee80211_aid_remove(struct ieee80211_node *ni)
{
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = vap->iv_ic;
if (ni->ni_associd) {
ieee80211_clear_aid_bitmap(ic, ni->ni_associd);
ic->ic_node_auth_state_change(ni, 0);
ni->ni_associd = 0;
}
}
static void
ieee80211_idx_remove(struct ieee80211_node *ni)
{
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = vap->iv_ic;
if (ni->ni_node_idx) {
if (ic->ic_node_idx_ni[IEEE80211_NODE_IDX_UNMAP(ni->ni_node_idx)] == ni) {
ic->ic_node_idx_ni[IEEE80211_NODE_IDX_UNMAP(ni->ni_node_idx)] = NULL;
}
ic->ic_unregister_node(ni);
ni->ni_node_idx = 0;
}
}
/*
* Leave the specified IBSS/BSS network. The node is assumed to
* be passed in with a held reference.
*/
void
ieee80211_sta_leave(struct ieee80211_node *ni)
{
struct ieee80211vap *vap = ni->ni_vap;
struct ieee80211com *ic = vap->iv_ic;
ieee80211_ref_node(ni);
ieee80211_ppqueue_remove_node_leave(&vap->iv_ppqueue, ni);
if ((ic->ic_measure_info.ni == ni) &&
(ic->ic_measure_info.status == MEAS_STATUS_RUNNING)) {
ic->ic_measure_info.status = MEAS_STATUS_DISCRAD;
}
#if defined(QBMPS_ENABLE)
if (ic->ic_flags_qtn & IEEE80211_QTN_BMPS) {
/* exit power-saving */
ic->ic_pm_reason = IEEE80211_PM_LEVEL_LEAVE_BSS;
ieee80211_pm_queue_work(ic);
}
#endif
/* WDS/Repeater: Stop software beacon timer for STA */
if (vap->iv_opmode == IEEE80211_M_STA &&
vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS) {
del_timer(&vap->iv_swbmiss);
}
/* Clear up the training timer */
if (vap->iv_opmode != IEEE80211_M_WDS) {
if (ni) {
int free_node = 0;
del_timer_sync(&ni->ni_training_timer);
spin_lock(&ni->ni_lock);
if (ni->ni_training_flag == NI_TRAINING_RUNNING) {
free_node = 1;
ni->ni_training_flag = NI_TRAINING_END;
}
spin_unlock(&ni->ni_lock);
if (free_node) {
printk("%s: [%pM] %s stopped\n",
vap->iv_dev->name, ni->ni_macaddr,
ic->ic_ocac.ocac_running ? "T process" : "training");
ieee80211_free_node(ni);
}
}
}
if (vap->iv_opmode == IEEE80211_M_STA)
ieee80211_param_to_qdrv(vap, IEEE80211_PARAM_PWR_ADJUST_AUTO, 0, NULL, 0);
if (vap->iv_opmode == IEEE80211_M_HOSTAP)
del_timer_sync(&ni->ni_btm_resp_wait_timer);
/*
* Make sure the node index is removed after the state change, which is below. Otherwise, fdb will not be cleared.
*/
ic->ic_node_auth_state_change(ni, 0);
/*
* Make sure the node index is removed before deleting the MuC/AuC node structure, else
* packets will be dropped.
*/
ieee80211_idx_remove(ni);
ic->ic_node_cleanup(ni);
ic->ic_disassoc(ni);
ieee80211_notify_node_leave(ni);
ieee80211_free_node(ni);
}
/*
* Node table support.
*/
static void
ieee80211_node_table_init(struct ieee80211com *ic,
struct ieee80211_node_table *nt, const char *name, int inact)
{
nt->nt_ic = ic;
IEEE80211_NODE_LOCK_INIT(nt, "");
IEEE80211_SCAN_LOCK_INIT(nt, "");
TAILQ_INIT(&nt->nt_node);
nt->nt_name = name;
nt->nt_scangen = 1;
nt->nt_inact_init = inact;
init_timer(&nt->nt_wds_aging_timer);
nt->nt_wds_aging_timer.function = ieee80211_node_wds_ageout;
nt->nt_wds_aging_timer.data = (unsigned long) nt;
mod_timer(&nt->nt_wds_aging_timer, jiffies + HZ * WDS_AGING_TIMER_VAL);
}
/*
* Reclaim any resources in a node and reset any critical
* state. Typically nodes are free'd immediately after,
* but in some cases the storage may be reused so we need
* to ensure consistent state (should probably fix that).
*
* Context: hwIRQ, softIRQ and process context
*/
static void
ieee80211_node_cleanup(struct ieee80211_node *ni)
{
struct ieee80211vap *vap = ni->ni_vap;
IEEE80211_LOCK_IRQ(ni->ni_ic);
/* NB: preserve ni_table */
if (ni->ni_flags & IEEE80211_NODE_PWR_MGT) {
if (vap->iv_opmode != IEEE80211_M_STA)
vap->iv_ps_sta--;
if (WMM_UAPSD_NODE_IS_PWR_MGT(ni)) {
ni->ni_ic->ic_uapsdmaxtriggers--;
}
ni->ni_flags &= ~IEEE80211_NODE_PWR_MGT;
IEEE80211_NOTE(vap, IEEE80211_MSG_POWER, ni,
"power save mode off, %u sta's in ps mode",
vap->iv_ps_sta);
}
ni->ni_flags &= ~IEEE80211_NODE_HT;
ieee80211_node_saveq_drain(ni);
if (vap->iv_set_tim != NULL) {
vap->iv_set_tim(ni, 0);
}
ieee80211_aid_remove(ni);
memset(&ni->ni_stats, 0, sizeof(ni->ni_stats));
if (ni->ni_challenge != NULL) {
FREE(ni->ni_challenge, M_DEVBUF);
ni->ni_challenge = NULL;
}
if (ni->ni_qtn_brmacs != NULL) {
FREE(ni->ni_qtn_brmacs, M_DEVBUF);
ni->ni_qtn_brmacs = NULL;
}
/*
* Preserve SSID, WPA, and WME ie's so the bss node is
* reusable during a re-auth/re-assoc state transition.
* If we remove these data they will not be recreated
* because they come from a probe-response or beacon frame
* which cannot be expected prior to the association-response.
* This should not be an issue when operating in other modes
* as stations leaving always go through a full state transition
* which will rebuild this state.
*
* XXX does this leave us open to inheriting old state?
*/
if (ni->ni_rxfrag != NULL) {
dev_kfree_skb_any(ni->ni_rxfrag);
ni->ni_rxfrag = NULL;
}
/*
* If there are related frames have been pushed to HW, clear the security bit in Node Cache.
* Don't delete the key here, disassoc will release the node cache later.
*/
#if 0
ieee80211_crypto_delkey(vap, &ni->ni_ucastkey, ni);
ni->ni_rxkeyoff = 0;
#endif
/* Deauthorize - remove from various linked lists. */
ieee80211_node_unauthorize(ni);
IEEE80211_UNLOCK_IRQ(ni->ni_ic);
}
static void
ieee80211_node_exit(struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
ic->ic_node_count--;
ic->ic_node_cleanup(ni);
if (ni->ni_wpa_ie != NULL) {
FREE(ni->ni_wpa_ie, M_DEVBUF);
ni->ni_wpa_ie = NULL;
}
if (ni->ni_rsn_ie != NULL) {
FREE(ni->ni_rsn_ie, M_DEVBUF);
ni->ni_rsn_ie = NULL;
}
if (ni->ni_osen_ie != NULL) {
FREE(ni->ni_osen_ie, M_DEVBUF);
ni->ni_osen_ie = NULL;
}
if (ni->ni_wme_ie != NULL) {
FREE(ni->ni_wme_ie, M_DEVBUF);
ni->ni_wme_ie = NULL;
}
if (ni->ni_wsc_ie != NULL) {
FREE(ni->ni_wsc_ie, M_DEVBUF);
ni->ni_wsc_ie = NULL;
}
if (ni->ni_ath_ie != NULL) {
FREE(ni->ni_ath_ie, M_DEVBUF);
ni->ni_ath_ie = NULL;
}
if (ni->ni_qtn_assoc_ie != NULL) {
FREE(ni->ni_qtn_assoc_ie, M_DEVBUF);
ni->ni_qtn_assoc_ie = NULL;
}
if (ni->ni_qtn_pairing_ie != NULL) {
FREE(ni->ni_qtn_pairing_ie, M_DEVBUF);
ni->ni_qtn_pairing_ie = NULL;
}
if (ni->ni_qtn_brmacs != NULL) {
FREE(ni->ni_qtn_brmacs, M_DEVBUF);
ni->ni_qtn_brmacs = NULL;
}
if (ni->ni_ext_bssid_ie != NULL) {
FREE(ni->ni_ext_bssid_ie, M_DEVBUF);
ni->ni_ext_bssid_ie = NULL;
}
if (ni->ni_tx_md_ie != NULL) {
FREE(ni->ni_tx_md_ie, M_DEVBUF);
ni->ni_tx_md_ie = NULL;
}
if (ni->ni_rx_md_ie != NULL) {
FREE(ni->ni_rx_md_ie, M_DEVBUF);
ni->ni_rx_md_ie = NULL;
}
if (ni->ni_tx_ft_ie != NULL) {
FREE(ni->ni_tx_ft_ie, M_DEVBUF);
ni->ni_tx_ft_ie = NULL;
}
if (ni->ni_rx_ft_ie != NULL) {
FREE(ni->ni_rx_ft_ie, M_DEVBUF);
ni->ni_rx_ft_ie = NULL;
}
if (ni->ni_tx_rsn_ie != NULL) {
FREE(ni->ni_tx_rsn_ie, M_DEVBUF);
ni->ni_tx_rsn_ie = NULL;
}
ieee80211_scs_free_node_tdls_stats(ic, ni);
ic->ic_qdrv_node_free(ni);
IEEE80211_NODE_SAVEQ_DESTROY(ni);
FREE(ni, M_80211_NODE);
}
static u_int8_t
ieee80211_node_getrssi(const struct ieee80211_node *ni)
{
return ni->ni_rssi;
}
/*
* Configure block ack agreements for a node.
*/
static void ieee80211_tx_addba(struct ieee80211_node *ni)
{
struct ieee80211com *ic = ni->ni_ic;
struct ieee80211vap *vap = ni->ni_vap;
int tid;
if (ni->ni_associd == 0) {
ieee80211_free_node(ni);
return;
}
for (tid = 0; tid < 7; tid++) {
if (ni->ni_ba_tx[tid].state == IEEE80211_BA_REQUESTED) {
ic->ic_setparam(ni, IEEE80211_PARAM_HTBA_SEQ_CTRL,
tid << 16, 0, 0);
if (ni->ni_vap->iv_opmode == IEEE80211_M_WDS &&
tid == IEEE80211_WDS_LINK_MAINTAIN_BA_TID &&
ni->ni_qtn_assoc_ie) {
/* For Q WDS peer, use larger buffer size for TID 0 to get more throughput */
ic->ic_setparam(ni, IEEE80211_PARAM_HTBA_SIZE_CTRL,
tid << 16 | IEEE80211_DEFAULT_BA_WINSIZE_H, 0, 0);
} else {
ic->ic_setparam(ni, IEEE80211_PARAM_HTBA_SIZE_CTRL,
tid << 16 | vap->iv_max_ba_win_size, 0, 0);
}
ic->ic_setparam(ni, IEEE80211_PARAM_HTBA_TIME_CTRL,
tid << 16 | 0x0, 0, 0);
ic->ic_setparam(ni, IEEE80211_PARAM_HT_ADDBA,
tid, 0, 0);
}
}
ieee80211_free_node(ni);
}
/*
* Configure block agreements for a node, workqueue version.
* The node structure must be locked before scheduling this workqueue.
*/
static void ieee80211_tx_addba_work(struct work_struct *work)
{
struct ieee80211_node *ni =
container_of(work, struct ieee80211_node, ni_tx_addba_task);
ieee80211_tx_addba(ni);
}
/*
* Create an entry in the specified node table. The node
* is set up with the mac address, an initial reference count,
* and some basic parameters obtained from global state.
* This interface is not intended for general use, it is
* used by the routines below to create entries with a
* specific purpose.
*/
struct ieee80211_node *
ieee80211_alloc_node(struct ieee80211_node_table *nt,
struct ieee80211vap *vap, const u_int8_t *macaddr, const char *caller)
{
struct ieee80211com *ic = nt->nt_ic;
struct ieee80211_node *ni;
int hash;
int i;
ni = ic->ic_node_alloc(nt, vap, macaddr, 0);
if (ni == NULL) {
/*
* Free the expired tdls node first and then try to
* allocate new node again
*/
if (vap->iv_opmode == IEEE80211_M_STA) {
ieee80211_tdls_node_expire((unsigned long)vap);
ni = ic->ic_node_alloc(nt, vap, macaddr, 0);
}
if (ni == NULL) {
printk(KERN_WARNING "Failed to allocate node for %s\n", caller);
vap->iv_stats.is_rx_nodealloc++;
return NULL;
}
}
IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
hash = IEEE80211_NODE_HASH(macaddr);
ni->ni_vap = vap;
ni->ni_ic = ic;
#ifdef IEEE80211_DEBUG_REFCNT
ni->ni_refdebug_info_p = kmalloc(sizeof(*ni->ni_refdebug_info_p), GFP_ATOMIC);
if (ni->ni_refdebug_info_p)
memset(ni->ni_refdebug_info_p, 0, sizeof(*ni->ni_refdebug_info_p));
#endif
ieee80211_node_initref(ni);
ieee80211_ref_node(ni);
ni->ni_tbtt = 0;
ni->ni_dtim_tbtt = 0;
ni->ni_flags |= (IS_IEEE80211_VHT_ENABLED(ic) ? IEEE80211_NODE_VHT:IEEE80211_NODE_HT);
ni->ni_htcap = ic->ic_htcap;
ni->ni_vhtcap = ic->ic_vhtcap;
ni->ni_chan = IEEE80211_CHAN_ANYC;
ni->ni_authmode = IEEE80211_AUTH_OPEN;
ni->ni_txpower = ic->ic_txpowlimit; /* max power */
ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey, IEEE80211_KEYIX_NONE);
ni->ni_inact_reload = nt->nt_inact_init;
ni->ni_inact = ni->ni_inact_reload;
ni->ni_ath_defkeyindex = IEEE80211_INVAL_DEFKEY;
ni->ni_rxkeyoff = 0;
ni->ni_recent_cca_idle = SCS_CCA_IDLE_INVALID;
INIT_WORK(&ni->ni_tx_addba_task, ieee80211_tx_addba_work);
INIT_WORK(&ni->ni_inact_work, ieee80211_timeout_station_work);
init_timer(&ni->ni_training_timer);
ni->ni_training_flag = NI_TRAINING_INIT;
ni->ni_node_type = IEEE80211_NODE_TYPE_NONE;
spin_lock_init(&ni->ni_lock);
ni->ni_training_count = 0;
ni->ni_training_start = 0;
ni->tdls_initiator = 0;
ni->last_tx_phy_rate = -1;
ni->tdls_path_sel_num = 0;
ni->tdls_last_path_sel = 0;
ni->tdls_no_send_cs_resp = 0;
ni->tdls_send_cs_req = 0;
ni->ni_chan_num = 0;
memset(ni->ni_supp_chans, 0, sizeof(ni->ni_supp_chans));
memset(&ni->ni_obss_ie, 0, sizeof(struct ieee80211_obss_scan_ie));
ni->ni_ext_role = IEEE80211_EXTENDER_ROLE_NONE;
ni->ni_ext_bssid_ie = NULL;
get_random_bytes(&ni->ni_rate_train, sizeof(ni->ni_rate_train));
init_timer(&ni->ni_btm_resp_wait_timer);
ni->ni_btm_req = 0;
ni->tdls_peer_associd = 0;
ni->tdls_status = IEEE80211_TDLS_NODE_STATUS_NONE;
IEEE80211_NODE_SAVEQ_INIT(ni, "unknown");
#if defined(CONFIG_QTN_80211K_SUPPORT)
init_waitqueue_head(&ni->ni_dotk_waitq);
#endif
init_waitqueue_head(&ni->ni_meas_info.meas_waitq);
init_waitqueue_head(&ni->ni_tpc_info.tpc_wait_info.tpc_waitq);
for (i = 0; i < WME_NUM_TID; ++i) {
ni->ni_ba_rx[i].state = IEEE80211_BA_NOT_ESTABLISHED;
seqlock_init(&ni->ni_ba_rx[i].state_lock);
ni->ni_ba_tx[i].state = IEEE80211_BA_NOT_ESTABLISHED;
seqlock_init(&ni->ni_ba_tx[i].state_lock);
}
IEEE80211_NODE_LOCK_IRQ(nt);
ni->ni_table = nt;
TAILQ_INSERT_TAIL(&nt->nt_node, ni, ni_list);
LIST_INSERT_HEAD(&nt->nt_hash[hash], ni, ni_hash);
ni->ni_rxfrag = NULL;
ni->ni_challenge = NULL;
ni->ni_implicit_ba_size = IEEE80211_DEFAULT_BA_WINSIZE;
ni->ni_tx_md_ie = NULL;
ni->ni_rx_md_ie = NULL;
ni->ni_tx_ft_ie = NULL;
ni->ni_rx_ft_ie = NULL;
ni->ni_rsn_ie = NULL;
ni->ni_tx_rsn_ie = NULL;
IEEE80211_NODE_UNLOCK_IRQ(nt);
WME_UAPSD_NODE_TRIGSEQINIT(ni);
return ni;
}
EXPORT_SYMBOL(ieee80211_alloc_node);
/* Add wds address to the node table */
int
ieee80211_add_wds_addr(struct ieee80211_node_table *nt,
struct ieee80211_node *ni, const u_int8_t *macaddr, u_int8_t wds_static)
{
int hash;
struct ieee80211_wds_addr *wds;
MALLOC(wds, struct ieee80211_wds_addr *, sizeof(struct ieee80211_wds_addr),
M_80211_WDS, M_NOWAIT | M_ZERO);
if (wds == NULL) {
/* XXX msg */
return 1;
}
if (wds_static)
wds->wds_agingcount = WDS_AGING_STATIC;
else
wds->wds_agingcount = WDS_AGING_COUNT;
hash = IEEE80211_NODE_HASH(macaddr);
IEEE80211_ADDR_COPY(wds->wds_macaddr, macaddr);
wds->wds_ni = ni;
IEEE80211_NODE_LOCK_IRQ(nt);
LIST_INSERT_HEAD(&nt->nt_wds_hash[hash], wds, wds_hash);
IEEE80211_NODE_UNLOCK_IRQ(nt);
return 0;
}
EXPORT_SYMBOL(ieee80211_add_wds_addr);
/* remove wds address from the wds hash table */
void
ieee80211_remove_wds_addr(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
{
int hash;
struct ieee80211_wds_addr *wds;
hash = IEEE80211_NODE_HASH(macaddr);
IEEE80211_NODE_LOCK_IRQ(nt);
LIST_FOREACH(wds, &nt->nt_wds_hash[hash], wds_hash) {
if (IEEE80211_ADDR_EQ(wds->wds_macaddr, macaddr)) {
LIST_REMOVE(wds, wds_hash);
FREE(wds, M_80211_WDS);
break;
}
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
}
EXPORT_SYMBOL(ieee80211_remove_wds_addr);
/* Remove node references from wds table */
void
ieee80211_del_wds_node(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
{
int hash;
struct ieee80211_wds_addr *wds;
IEEE80211_NODE_LOCK_IRQ(nt);
for (hash = 0; hash < IEEE80211_NODE_HASHSIZE; hash++) {
LIST_FOREACH(wds, &nt->nt_wds_hash[hash], wds_hash) {
if (wds->wds_ni == ni) {
LIST_REMOVE(wds, wds_hash);
FREE(wds, M_80211_WDS);
}
}
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
}
EXPORT_SYMBOL(ieee80211_del_wds_node);
static void
ieee80211_node_wds_ageout(unsigned long data)
{
struct ieee80211_node_table *nt = (struct ieee80211_node_table *)data;
int hash;
struct ieee80211_wds_addr *wds;
IEEE80211_NODE_LOCK_IRQ(nt);
for (hash = 0; hash < IEEE80211_NODE_HASHSIZE; hash++) {
LIST_FOREACH(wds, &nt->nt_wds_hash[hash], wds_hash) {
if (wds->wds_agingcount != WDS_AGING_STATIC) {
if (!wds->wds_agingcount) {
LIST_REMOVE(wds, wds_hash);
FREE(wds, M_80211_WDS);
} else
wds->wds_agingcount--;
}
}
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
mod_timer(&nt->nt_wds_aging_timer, jiffies + HZ * WDS_AGING_TIMER_VAL);
}
/*
* Craft a temporary node suitable for sending a management frame
* to the specified station. We craft only as much state as we
* need to do the work since the node will be immediately reclaimed
* once the send completes.
*/
struct ieee80211_node *
_ieee80211_tmp_node(struct ieee80211vap *vap, const u_int8_t *macaddr,
const u_int8_t *bssid)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *ni;
struct ieee80211_node *bss_ni = vap->iv_bss;
if (!bss_ni) {
bss_ni = TAILQ_FIRST(&ic->ic_vaps)->iv_bss;
if (!bss_ni)
return NULL;
}
ni = ic->ic_node_alloc(&ic->ic_sta, vap, macaddr, 1);
if (ni == NULL) {
vap->iv_stats.is_rx_nodealloc++;
return NULL;
}
#ifdef IEEE80211_DEBUG_REFCNT
ni->ni_refdebug_info_p = NULL;
#endif
IEEE80211_ADDR_COPY(ni->ni_macaddr, macaddr);
IEEE80211_ADDR_COPY(ni->ni_bssid, bssid);
ni->ni_txpower = bss_ni->ni_txpower;
ni->ni_vap = vap;
ni->ni_node_idx = vap->iv_vapnode_idx;
ieee80211_node_initref(ni);
/* NB: required by ieee80211_fix_rate */
if (vap->iv_opmode == IEEE80211_M_STA) {
ni->ni_rates = ic->ic_sup_rates[ic->ic_curmode];
} else {
ieee80211_node_set_chan(ic, ni);
}
ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
IEEE80211_KEYIX_NONE);
/* XXX optimize away */
IEEE80211_NODE_SAVEQ_INIT(ni, "unknown");
ni->ni_table = NULL;
ni->ni_ic = ic;
ni->ni_rxfrag = NULL;
ni->ni_challenge = NULL;
return ni;
}
EXPORT_SYMBOL(_ieee80211_tmp_node);
struct ieee80211_node *
ieee80211_tmp_node(struct ieee80211vap *vap, const u_int8_t *macaddr)
{
return _ieee80211_tmp_node(vap, macaddr, vap->iv_bss->ni_bssid);
}
EXPORT_SYMBOL(ieee80211_tmp_node);
/*
* Add the specified station to the station table.
* The node is locked and must be freed by the caller.
*/
struct ieee80211_node *
ieee80211_dup_bss(struct ieee80211vap *vap, const u_int8_t *macaddr)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *ni;
if (NULL == vap->iv_bss)
return NULL;
ni = ieee80211_alloc_node(&ic->ic_sta, vap, macaddr, "bss dup");
if (ni != NULL) {
/*
* Inherit from iv_bss.
*/
ni->ni_authmode = vap->iv_bss->ni_authmode;
ni->ni_txpower = vap->iv_bss->ni_txpower;
ni->ni_vlan = vap->iv_bss->ni_vlan; /* XXX?? */
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_bss->ni_bssid);
ieee80211_node_set_chan(ic, ni);
ni->ni_rsn = vap->iv_bss->ni_rsn;
ni->ni_rxfrag = NULL;
ni->ni_associd = vap->iv_bss->ni_associd;
ni->ni_node_idx = vap->iv_bss->ni_node_idx;
}
return ni;
}
static struct ieee80211_node *
_ieee80211_find_wds_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
{
struct ieee80211_node *ni;
struct ieee80211_wds_addr *wds;
int hash;
IEEE80211_NODE_LOCK_ASSERT(nt);
hash = IEEE80211_NODE_HASH(macaddr);
LIST_FOREACH(wds, &nt->nt_wds_hash[hash], wds_hash) {
if (IEEE80211_ADDR_EQ(wds->wds_macaddr, macaddr)) {
ni = wds->wds_ni;
if (wds->wds_agingcount != WDS_AGING_STATIC)
wds->wds_agingcount = WDS_AGING_COUNT; /* reset the aging count */
ieee80211_ref_node(ni);
return ni;
}
}
return NULL;
}
static struct ieee80211_node *
#ifdef IEEE80211_DEBUG_REFCNT
_ieee80211_find_node_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr,
const char *filename,
int line)
#else
_ieee80211_find_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
#endif
{
struct ieee80211_node *ni;
int hash;
struct ieee80211_wds_addr *wds;
IEEE80211_NODE_LOCK_ASSERT(nt);
hash = IEEE80211_NODE_HASH(macaddr);
LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
ieee80211_ref_node_debug(ni, filename, line);
return ni;
}
}
/* Now, we look for the desired mac address in the 4 address nodes */
LIST_FOREACH(wds, &nt->nt_wds_hash[hash], wds_hash) {
if (IEEE80211_ADDR_EQ(wds->wds_macaddr, macaddr)) {
ni = wds->wds_ni;
ieee80211_ref_node_debug(ni, filename, line);
return ni;
}
}
return NULL;
}
#ifdef IEEE80211_DEBUG_REFCNT
#define _ieee80211_find_node(nt, mac) \
_ieee80211_find_node_debug(nt, mac, filename, line)
#endif
struct ieee80211_node *
ieee80211_find_wds_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
{
struct ieee80211_node *ni;
IEEE80211_NODE_LOCK_IRQ(nt);
ni = _ieee80211_find_wds_node(nt, macaddr);
IEEE80211_NODE_UNLOCK_IRQ(nt);
return ni;
}
EXPORT_SYMBOL(ieee80211_find_wds_node);
struct ieee80211_node * __sram_text
#ifdef IEEE80211_DEBUG_REFCNT
ieee80211_find_node_debug(struct ieee80211_node_table *nt, const u_int8_t *macaddr,
const char *filename, int line)
#else
ieee80211_find_node(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
#endif
{
struct ieee80211_node *ni;
IEEE80211_NODE_LOCK_IRQ(nt);
ni = _ieee80211_find_node(nt, macaddr);
IEEE80211_NODE_UNLOCK_IRQ(nt);
return ni;
}
#ifdef IEEE80211_DEBUG_REFCNT
EXPORT_SYMBOL(ieee80211_find_node_debug);
#else
EXPORT_SYMBOL(ieee80211_find_node);
#endif
#ifdef IEEE80211_DEBUG_REFCNT
#define ieee80211_find_node_by_ip_addr \
ieee80211_find_node_by_ip_addr_debug
#endif
struct ieee80211_node * __sram_text
#ifdef IEEE80211_DEBUG_REFCNT
ieee80211_find_node_by_ip_addr_debug(struct ieee80211_node_table *nt, uint32_t ip_addr,
const char *filename,
int line)
#else
ieee80211_find_node_by_ip_addr(struct ieee80211vap *vap, uint32_t ip_addr)
#endif
{
struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
struct ieee80211_node *ni = NULL;
IEEE80211_NODE_LOCK(nt);
TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
if (ni->ni_vap->iv_dev != vap->iv_dev) {
continue;
}
if (ni->ni_ip_addr && (ip_addr == ni->ni_ip_addr)) {
ieee80211_ref_node_debug(ni, filename, line);
break;
}
}
IEEE80211_NODE_UNLOCK(nt);
return ni;
}
#ifdef IEEE80211_DEBUG_REFCNT
EXPORT_SYMBOL(ieee80211_find_node_by_ip_addr_debug);
#else
EXPORT_SYMBOL(ieee80211_find_node_by_ip_addr);
#endif
#ifdef CONFIG_IPV6
#ifdef IEEE80211_DEBUG_REFCNT
#define ieee80211_find_node_by_ipv6_addr \
ieee80211_find_node_by_ipv6_addr_debug
#endif
struct ieee80211_node *
#ifdef IEEE80211_DEBUG_REFCNT
ieee80211_find_node_by_ipv6_addr_debug(struct ieee80211_node_table *nt, struct in6_addr *ipv6_addr,
const char *filename,
int line)
#else
ieee80211_find_node_by_ipv6_addr(struct ieee80211vap *vap, struct in6_addr *ipv6_addr)
#endif
{
struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
struct ieee80211_node *ni = NULL;
IEEE80211_NODE_LOCK(nt);
TAILQ_FOREACH(ni, &nt->nt_node, ni_list) {
if (ni->ni_vap->iv_dev != vap->iv_dev) {
continue;
}
if (!memcmp(ni->ipv6_llocal.s6_addr, ipv6_addr, sizeof(struct in6_addr))) {
ieee80211_ref_node_debug(ni, filename, line);
break;
}
}
IEEE80211_NODE_UNLOCK(nt);
return ni;
}
#ifdef IEEE80211_DEBUG_REFCNT
EXPORT_SYMBOL(ieee80211_find_node_by_ipv6_addr_debug);
#else
EXPORT_SYMBOL(ieee80211_find_node_by_ipv6_addr);
#endif
#endif
/**
* Look up the AID by MAC address.
* refcnt is not incremented.
*/
u_int16_t /*__sram_text*/
ieee80211_find_aid_by_mac_addr(struct ieee80211_node_table *nt, const u_int8_t *macaddr)
{
struct ieee80211_node *ni;
int hash;
u_int16_t aid = 0;
IEEE80211_NODE_LOCK_IRQ(nt);
IEEE80211_NODE_LOCK_ASSERT(nt);
hash = IEEE80211_NODE_HASH(macaddr);
LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
aid = IEEE80211_AID(ni->ni_associd);
break;
}
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
return aid;
}
EXPORT_SYMBOL(ieee80211_find_aid_by_mac_addr);
struct ieee80211_node * __sram_text
#ifdef IEEE80211_DEBUG_REFCNT
ieee80211_find_node_by_node_idx_debug(struct ieee80211vap *vap, uint16_t node_idx,
const char *filename,
int line)
#else
ieee80211_find_node_by_node_idx(struct ieee80211vap *vap, uint16_t node_idx)
#endif
{
struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
struct ieee80211_node *ni;
IEEE80211_NODE_LOCK_IRQ(nt);
ni = vap->iv_ic->ic_node_idx_ni[IEEE80211_NODE_IDX_UNMAP(node_idx)];
if (ni) {
ieee80211_ref_node_debug(ni, filename, line);
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
return ni;
}
#ifdef IEEE80211_DEBUG_REFCNT
EXPORT_SYMBOL(ieee80211_find_node_by_node_idx_debug);
#else
EXPORT_SYMBOL(ieee80211_find_node_by_node_idx);
#endif
struct ieee80211_node * __sram_text
#ifdef IEEE80211_DEBUG_REFCNT
ieee80211_find_node_by_idx_debug(struct ieee80211com *ic,
struct ieee80211vap *vap,
uint16_t node_idx,
const char *filename,
int line)
#else
ieee80211_find_node_by_idx(struct ieee80211com *ic, struct ieee80211vap *vap, uint16_t node_idx)
#endif
{
struct ieee80211_node_table *nt = &ic->ic_sta;
struct ieee80211_node *ni = NULL;
if (IEEE80211_NODE_IDX_UNMAP(node_idx) < QTN_NCIDX_MAX) {
IEEE80211_NODE_LOCK_IRQ(nt);
ni = ic->ic_node_idx_ni[IEEE80211_NODE_IDX_UNMAP(node_idx)];
if (ni) {
if (!vap || (ni->ni_vap == vap)) {
ieee80211_ref_node_debug(ni, filename, line);
} else {
ni = NULL;
}
}
IEEE80211_NODE_UNLOCK_IRQ(nt);
}
return ni;
}
#ifdef IEEE80211_DEBUG_REFCNT
EXPORT_SYMBOL(ieee80211_find_node_by_idx_debug);
#else
EXPORT_SYMBOL(ieee80211_find_node_by_idx);
#endif
/*
* Fake up a node; this handles node discovery in adhoc mode.
* Note that for the driver's benefit we treat this like an association so the driver has an
* opportunity to set up its private state.
* The node is locked and must be freed by the caller.
*/
struct ieee80211_node *
ieee80211_fakeup_adhoc_node(struct ieee80211vap *vap, const u_int8_t *macaddr)
{
struct ieee80211_node *ni;
if (NULL == vap->iv_bss)
return NULL;
ni = ieee80211_dup_bss(vap, macaddr);
if (ni != NULL) {
/* XXX no rate negotiation; just dup */
ni->ni_rates = vap->iv_bss->ni_rates;
if (vap->iv_ic->ic_newassoc != NULL)
vap->iv_ic->ic_newassoc(ni, 1);
/* XXX not right for 802.1x/WPA */
ieee80211_node_authorize(ni);
}
return ni;
}
/*
* Do node discovery in adhoc mode on receipt of a beacon or probe response frame.
* Note that for the driver's benefit we treat this like an association so the driver has an
* opportunity to set up its private state.
* The node is locked and must be freed by the caller.
*/
struct ieee80211_node *
ieee80211_add_neighbor(struct ieee80211vap *vap, const struct ieee80211_frame *wh,
const struct ieee80211_scanparams *sp)
{
struct ieee80211com *ic = vap->iv_ic;
struct ieee80211_node *ni;
ni = ieee80211_dup_bss(vap, wh->i_addr2); /* XXX alloc_node? */
/* TODO: not really putting itself in a table */
if (ni != NULL) {
ni->ni_esslen = sp->ssid[1];
memcpy(ni->ni_essid, sp->ssid + 2, sp->ssid[1]);
IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
memcpy(ni->ni_tstamp.data, sp->tstamp, sizeof(ni->ni_tstamp));
ni->ni_intval = IEEE80211_BINTVAL_SANITISE(sp->bintval);
ni->ni_capinfo = sp->capinfo;
ni->ni_chan = ic->ic_curchan;
ni->ni_fhdwell = sp->fhdwell;
ni->ni_fhindex = sp->fhindex;
ni->ni_erp = sp->erp;
ni->ni_timoff = sp->timoff;
if (sp->wme != NULL)
ieee80211_saveie(&ni->ni_wme_ie, sp->wme);
if (sp->wpa != NULL)
ieee80211_saveie(&ni->ni_wpa_ie, sp->wpa);
if (sp->rsn != NULL)
ieee80211_saveie(&ni->ni_rsn_ie, sp->rsn);
if (sp->ath != NULL)
ieee80211_saveath(ni, sp->ath);
/* NB: must be after ni_chan is set up */
ieee80211_setup_rates(ni, sp->rates, sp->xrates, IEEE80211_F_DOSORT);
if (ic->ic_newassoc != NULL)
ic->ic_newassoc(ni, 1);
/* XXX not right for 802.1x/WPA */
ieee80211_node_authorize(ni);
if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
/*
* Blindly propagate capabilities based on the
* local configuration. In particular this permits
* us to use QoS to disable ACK's and to use short
* preamble on 2.4G channels.
*/
if (vap->iv_flags & IEEE80211_F_WME)
ni->ni_flags |= IEEE80211_NODE_QOS;
if (vap->iv_flags & IEEE80211_F_SHPREAMBLE)
ni->ni_capinfo |= IEEE80211_CAPINFO_SHORT_PREAMBLE<