Commit | Line | Data |
---|---|---|
3d99d987 AP |
1 | /* |
2 | * Marvell Wireless LAN device driver: AP event handling | |
3 | * | |
4 | * Copyright (C) 2012, Marvell International Ltd. | |
5 | * | |
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. | |
13 | * | |
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. | |
18 | */ | |
19 | ||
20 | #include "decl.h" | |
21 | #include "main.h" | |
22 | ||
017a92a1 AP |
23 | /* |
24 | * This function will return the pointer to station entry in station list | |
25 | * table which matches specified mac address. | |
26 | * This function should be called after acquiring RA list spinlock. | |
27 | * NULL is returned if station entry is not found in associated STA list. | |
28 | */ | |
29 | struct mwifiex_sta_node * | |
30 | mwifiex_get_sta_entry(struct mwifiex_private *priv, u8 *mac) | |
31 | { | |
32 | struct mwifiex_sta_node *node; | |
33 | ||
34 | if (!mac) | |
35 | return NULL; | |
36 | ||
37 | list_for_each_entry(node, &priv->sta_list, list) { | |
38 | if (!memcmp(node->mac_addr, mac, ETH_ALEN)) | |
39 | return node; | |
40 | } | |
41 | ||
42 | return NULL; | |
43 | } | |
44 | ||
45 | /* | |
46 | * This function will add a sta_node entry to associated station list | |
47 | * table with the given mac address. | |
48 | * If entry exist already, existing entry is returned. | |
49 | * If received mac address is NULL, NULL is returned. | |
50 | */ | |
51 | static struct mwifiex_sta_node * | |
52 | mwifiex_add_sta_entry(struct mwifiex_private *priv, u8 *mac) | |
53 | { | |
54 | struct mwifiex_sta_node *node; | |
55 | unsigned long flags; | |
56 | ||
57 | if (!mac) | |
58 | return NULL; | |
59 | ||
60 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
61 | node = mwifiex_get_sta_entry(priv, mac); | |
62 | if (node) | |
63 | goto done; | |
64 | ||
65 | node = kzalloc(sizeof(struct mwifiex_sta_node), GFP_KERNEL); | |
66 | if (!node) | |
67 | goto done; | |
68 | ||
69 | memcpy(node->mac_addr, mac, ETH_ALEN); | |
70 | list_add_tail(&node->list, &priv->sta_list); | |
71 | ||
72 | done: | |
73 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
74 | return node; | |
75 | } | |
76 | ||
77 | /* | |
78 | * This function will search for HT IE in association request IEs | |
79 | * and set station HT parameters accordingly. | |
80 | */ | |
81 | static void | |
82 | mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies, | |
83 | int ies_len, struct mwifiex_sta_node *node) | |
84 | { | |
85 | const struct ieee80211_ht_cap *ht_cap; | |
86 | ||
87 | if (!ies) | |
88 | return; | |
89 | ||
90 | ht_cap = (void *)cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); | |
91 | if (ht_cap) { | |
92 | node->is_11n_enabled = 1; | |
93 | node->max_amsdu = le16_to_cpu(ht_cap->cap_info) & | |
94 | IEEE80211_HT_CAP_MAX_AMSDU ? | |
95 | MWIFIEX_TX_DATA_BUF_SIZE_8K : | |
96 | MWIFIEX_TX_DATA_BUF_SIZE_4K; | |
97 | } else { | |
98 | node->is_11n_enabled = 0; | |
99 | } | |
100 | ||
101 | return; | |
102 | } | |
103 | ||
104 | /* | |
105 | * This function will delete a station entry from station list | |
106 | */ | |
107 | static void mwifiex_del_sta_entry(struct mwifiex_private *priv, u8 *mac) | |
108 | { | |
109 | struct mwifiex_sta_node *node, *tmp; | |
110 | unsigned long flags; | |
111 | ||
112 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
113 | ||
114 | node = mwifiex_get_sta_entry(priv, mac); | |
115 | if (node) { | |
116 | list_for_each_entry_safe(node, tmp, &priv->sta_list, | |
117 | list) { | |
118 | list_del(&node->list); | |
119 | kfree(node); | |
120 | } | |
121 | } | |
122 | ||
123 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
124 | return; | |
125 | } | |
126 | ||
127 | /* | |
128 | * This function will delete all stations from associated station list. | |
129 | */ | |
130 | static void mwifiex_del_all_sta_list(struct mwifiex_private *priv) | |
131 | { | |
132 | struct mwifiex_sta_node *node, *tmp; | |
133 | unsigned long flags; | |
134 | ||
135 | spin_lock_irqsave(&priv->sta_list_spinlock, flags); | |
136 | ||
137 | list_for_each_entry_safe(node, tmp, &priv->sta_list, list) { | |
138 | list_del(&node->list); | |
139 | kfree(node); | |
140 | } | |
141 | ||
142 | INIT_LIST_HEAD(&priv->sta_list); | |
143 | spin_unlock_irqrestore(&priv->sta_list_spinlock, flags); | |
144 | return; | |
145 | } | |
146 | ||
3d99d987 AP |
147 | /* |
148 | * This function handles AP interface specific events generated by firmware. | |
149 | * | |
150 | * Event specific routines are called by this function based | |
151 | * upon the generated event cause. | |
152 | * | |
153 | * | |
154 | * Events supported for AP - | |
155 | * - EVENT_UAP_STA_ASSOC | |
156 | * - EVENT_UAP_STA_DEAUTH | |
157 | * - EVENT_UAP_BSS_ACTIVE | |
158 | * - EVENT_UAP_BSS_START | |
159 | * - EVENT_UAP_BSS_IDLE | |
160 | * - EVENT_UAP_MIC_COUNTERMEASURES: | |
161 | */ | |
162 | int mwifiex_process_uap_event(struct mwifiex_private *priv) | |
163 | { | |
164 | struct mwifiex_adapter *adapter = priv->adapter; | |
017a92a1 | 165 | int len, i; |
3d99d987 AP |
166 | u32 eventcause = adapter->event_cause; |
167 | struct station_info sinfo; | |
168 | struct mwifiex_assoc_event *event; | |
017a92a1 AP |
169 | struct mwifiex_sta_node *node; |
170 | u8 *deauth_mac; | |
3d99d987 AP |
171 | |
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; | |
179 | ||
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. | |
185 | */ | |
186 | len = ETH_ALEN; | |
187 | ||
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; | |
195 | } | |
196 | } | |
197 | cfg80211_new_sta(priv->netdev, event->sta_addr, &sinfo, | |
198 | GFP_KERNEL); | |
017a92a1 AP |
199 | |
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; | |
205 | } | |
206 | ||
207 | if (!priv->ap_11n_enabled) | |
208 | break; | |
209 | ||
210 | mwifiex_set_sta_ht_cap(priv, sinfo.assoc_req_ies, | |
211 | sinfo.assoc_req_ies_len, node); | |
212 | ||
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; | |
219 | } | |
220 | memset(node->rx_seq, 0xff, sizeof(node->rx_seq)); | |
3d99d987 AP |
221 | break; |
222 | case EVENT_UAP_STA_DEAUTH: | |
017a92a1 AP |
223 | deauth_mac = adapter->event_body + |
224 | MWIFIEX_UAP_EVENT_EXTRA_HEADER; | |
225 | cfg80211_del_sta(priv->netdev, deauth_mac, GFP_KERNEL); | |
226 | ||
227 | mwifiex_del_sta_entry(priv, deauth_mac); | |
3d99d987 AP |
228 | break; |
229 | case EVENT_UAP_BSS_IDLE: | |
230 | priv->media_connected = false; | |
017a92a1 | 231 | mwifiex_del_all_sta_list(priv); |
3d99d987 AP |
232 | break; |
233 | case EVENT_UAP_BSS_ACTIVE: | |
234 | priv->media_connected = true; | |
235 | break; | |
236 | case EVENT_UAP_BSS_START: | |
237 | dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause); | |
238 | memcpy(priv->netdev->dev_addr, adapter->event_body + 2, | |
239 | ETH_ALEN); | |
240 | break; | |
241 | case EVENT_UAP_MIC_COUNTERMEASURES: | |
242 | /* For future development */ | |
243 | dev_dbg(adapter->dev, "AP EVENT: event id: %#x\n", eventcause); | |
244 | break; | |
d1cf3b95 AP |
245 | case EVENT_AMSDU_AGGR_CTRL: |
246 | dev_dbg(adapter->dev, "event: AMSDU_AGGR_CTRL %d\n", | |
247 | *(u16 *)adapter->event_body); | |
248 | ||
249 | if (priv->media_connected) { | |
250 | adapter->tx_buf_size = | |
251 | min(adapter->curr_tx_buf_size, | |
252 | le16_to_cpu(*(__le16 *)adapter->event_body)); | |
253 | ||
254 | dev_dbg(adapter->dev, "event: tx_buf_size %d\n", | |
255 | adapter->tx_buf_size); | |
256 | } | |
257 | break; | |
3d99d987 AP |
258 | default: |
259 | dev_dbg(adapter->dev, "event: unknown event id: %#x\n", | |
260 | eventcause); | |
261 | break; | |
262 | } | |
263 | ||
264 | return 0; | |
265 | } |