ARM: mm: Recreate kernel mappings in early_paging_init()
[linux/fpc-iii.git] / drivers / net / wireless / mwifiex / uap_event.c
blob718066577c6c531f22c9f4387639237875f04862
1 /*
2 * Marvell Wireless LAN device driver: AP event handling
4 * Copyright (C) 2012, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include "decl.h"
21 #include "main.h"
22 #include "11n.h"
25 * This function will return the pointer to station entry in station list
26 * table which matches specified mac address.
27 * This function should be called after acquiring RA list spinlock.
28 * NULL is returned if station entry is not found in associated STA list.
30 struct mwifiex_sta_node *
31 mwifiex_get_sta_entry(struct mwifiex_private *priv, u8 *mac)
33 struct mwifiex_sta_node *node;
35 if (!mac)
36 return NULL;
38 list_for_each_entry(node, &priv->sta_list, list) {
39 if (!memcmp(node->mac_addr, mac, ETH_ALEN))
40 return node;
43 return NULL;
47 * This function will add a sta_node entry to associated station list
48 * table with the given mac address.
49 * If entry exist already, existing entry is returned.
50 * If received mac address is NULL, NULL is returned.
52 static struct mwifiex_sta_node *
53 mwifiex_add_sta_entry(struct mwifiex_private *priv, u8 *mac)
55 struct mwifiex_sta_node *node;
56 unsigned long flags;
58 if (!mac)
59 return NULL;
61 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
62 node = mwifiex_get_sta_entry(priv, mac);
63 if (node)
64 goto done;
66 node = kzalloc(sizeof(struct mwifiex_sta_node), GFP_ATOMIC);
67 if (!node)
68 goto done;
70 memcpy(node->mac_addr, mac, ETH_ALEN);
71 list_add_tail(&node->list, &priv->sta_list);
73 done:
74 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
75 return node;
79 * This function will search for HT IE in association request IEs
80 * and set station HT parameters accordingly.
82 static void
83 mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
84 int ies_len, struct mwifiex_sta_node *node)
86 const struct ieee80211_ht_cap *ht_cap;
88 if (!ies)
89 return;
91 ht_cap = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
92 if (ht_cap) {
93 node->is_11n_enabled = 1;
94 node->max_amsdu = le16_to_cpu(ht_cap->cap_info) &
95 IEEE80211_HT_CAP_MAX_AMSDU ?
96 MWIFIEX_TX_DATA_BUF_SIZE_8K :
97 MWIFIEX_TX_DATA_BUF_SIZE_4K;
98 } else {
99 node->is_11n_enabled = 0;
102 return;
106 * This function will delete a station entry from station list
108 static void mwifiex_del_sta_entry(struct mwifiex_private *priv, u8 *mac)
110 struct mwifiex_sta_node *node;
111 unsigned long flags;
113 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
115 node = mwifiex_get_sta_entry(priv, mac);
116 if (node) {
117 list_del(&node->list);
118 kfree(node);
121 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
122 return;
126 * This function will delete all stations from associated station list.
128 static void mwifiex_del_all_sta_list(struct mwifiex_private *priv)
130 struct mwifiex_sta_node *node, *tmp;
131 unsigned long flags;
133 spin_lock_irqsave(&priv->sta_list_spinlock, flags);
135 list_for_each_entry_safe(node, tmp, &priv->sta_list, list) {
136 list_del(&node->list);
137 kfree(node);
140 INIT_LIST_HEAD(&priv->sta_list);
141 spin_unlock_irqrestore(&priv->sta_list_spinlock, flags);
142 return;
146 * This function handles AP interface specific events generated by firmware.
148 * Event specific routines are called by this function based
149 * upon the generated event cause.
152 * Events supported for AP -
153 * - EVENT_UAP_STA_ASSOC
154 * - EVENT_UAP_STA_DEAUTH
155 * - EVENT_UAP_BSS_ACTIVE
156 * - EVENT_UAP_BSS_START
157 * - EVENT_UAP_BSS_IDLE
158 * - EVENT_UAP_MIC_COUNTERMEASURES:
160 int mwifiex_process_uap_event(struct mwifiex_private *priv)
162 struct mwifiex_adapter *adapter = priv->adapter;
163 int len, i;
164 u32 eventcause = adapter->event_cause;
165 struct station_info sinfo;
166 struct mwifiex_assoc_event *event;
167 struct mwifiex_sta_node *node;
168 u8 *deauth_mac;
169 struct host_cmd_ds_11n_batimeout *ba_timeout;
170 u16 ctrl;
172 switch (eventcause) {
173 case EVENT_UAP_STA_ASSOC:
174 memset(&sinfo, 0, sizeof(sinfo));
175 event = (struct mwifiex_assoc_event *)
176 (adapter->event_body + MWIFIEX_UAP_EVENT_EXTRA_HEADER);
177 if (le16_to_cpu(event->type) == TLV_TYPE_UAP_MGMT_FRAME) {
178 len = -1;
180 if (ieee80211_is_assoc_req(event->frame_control))
181 len = 0;
182 else if (ieee80211_is_reassoc_req(event->frame_control))
183 /* There will be ETH_ALEN bytes of
184 * current_ap_addr before the re-assoc ies.
186 len = ETH_ALEN;
188 if (len != -1) {
189 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
190 sinfo.assoc_req_ies = &event->data[len];
191 len = (u8 *)sinfo.assoc_req_ies -
192 (u8 *)&event->frame_control;
193 sinfo.assoc_req_ies_len =
194 le16_to_cpu(event->len) - (u16)len;
197 cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo,
198 GFP_KERNEL);
200 node = mwifiex_add_sta_entry(priv, event->sta_addr);
201 if (!node) {
202 dev_warn(adapter->dev,
203 "could not create station entry!\n");
204 return -1;
207 if (!priv->ap_11n_enabled)
208 break;
210 mwifiex_set_sta_ht_cap(priv, sinfo.assoc_req_ies,
211 sinfo.assoc_req_ies_len, node);
213 for (i = 0; i < MAX_NUM_TID; i++) {
214 if (node->is_11n_enabled)
215 node->ampdu_sta[i] =
216 priv->aggr_prio_tbl[i].ampdu_user;
217 else
218 node->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
220 memset(node->rx_seq, 0xff, sizeof(node->rx_seq));
221 break;
222 case EVENT_UAP_STA_DEAUTH:
223 deauth_mac = adapter->event_body +
224 MWIFIEX_UAP_EVENT_EXTRA_HEADER;
225 cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL);
227 if (priv->ap_11n_enabled) {
228 mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, deauth_mac);
229 mwifiex_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
231 mwifiex_del_sta_entry(priv, deauth_mac);
232 break;
233 case EVENT_UAP_BSS_IDLE:
234 priv->media_connected = false;
235 if (netif_carrier_ok(priv->netdev))
236 netif_carrier_off(priv->netdev);
237 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
239 mwifiex_clean_txrx(priv);
240 mwifiex_del_all_sta_list(priv);
241 break;
242 case EVENT_UAP_BSS_ACTIVE:
243 priv->media_connected = true;
244 if (!netif_carrier_ok(priv->netdev))
245 netif_carrier_on(priv->netdev);
246 mwifiex_wake_up_net_dev_queue(priv->netdev, adapter);
247 break;
248 case EVENT_UAP_BSS_START:
249 dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
250 memcpy(priv->netdev->dev_addr, adapter->event_body + 2,
251 ETH_ALEN);
252 break;
253 case EVENT_UAP_MIC_COUNTERMEASURES:
254 /* For future development */
255 dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause);
256 break;
257 case EVENT_AMSDU_AGGR_CTRL:
258 ctrl = le16_to_cpu(*(__le16 *)adapter->event_body);
259 dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", ctrl);
261 if (priv->media_connected) {
262 adapter->tx_buf_size =
263 min_t(u16, adapter->curr_tx_buf_size, ctrl);
264 dev_dbg(adapter->dev, "event: tx_buf_size %d\n",
265 adapter->tx_buf_size);
267 break;
268 case EVENT_ADDBA:
269 dev_dbg(adapter->dev, "event: ADDBA Request\n");
270 if (priv->media_connected)
271 mwifiex_send_cmd_async(priv, HostCmd_CMD_11N_ADDBA_RSP,
272 HostCmd_ACT_GEN_SET, 0,
273 adapter->event_body);
274 break;
275 case EVENT_DELBA:
276 dev_dbg(adapter->dev, "event: DELBA Request\n");
277 if (priv->media_connected)
278 mwifiex_11n_delete_ba_stream(priv, adapter->event_body);
279 break;
280 case EVENT_BA_STREAM_TIEMOUT:
281 dev_dbg(adapter->dev, "event: BA Stream timeout\n");
282 if (priv->media_connected) {
283 ba_timeout = (void *)adapter->event_body;
284 mwifiex_11n_ba_stream_timeout(priv, ba_timeout);
286 break;
287 default:
288 dev_dbg(adapter->dev, "event: unknown event id: %#x\n",
289 eventcause);
290 break;
293 return 0;
296 /* This function deletes station entry from associated station list.
297 * Also if both AP and STA are 11n enabled, RxReorder tables and TxBA stream
298 * tables created for this station are deleted.
300 void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
301 struct mwifiex_sta_node *node)
303 if (priv->ap_11n_enabled && node->is_11n_enabled) {
304 mwifiex_11n_del_rx_reorder_tbl_by_ta(priv, node->mac_addr);
305 mwifiex_del_tx_ba_stream_tbl_by_ra(priv, node->mac_addr);
307 mwifiex_del_sta_entry(priv, node->mac_addr);
309 return;