1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define _RTW_MLME_EXT_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <wifi.h>
25 #include <rtw_mlme_ext.h>
26 #include <wlan_bssdef.h>
27 #include <mlme_osdep.h>
28 #include <recv_osdep.h>
29
30 static struct mlme_handler mlme_sta_tbl[] = {
31 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
32 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
33 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
34 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
35 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
36 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
37
38 /*----------------------------------------------------------
39 below 2 are reserved
40 -----------------------------------------------------------*/
41 {0, "DoReserved", &DoReserved},
42 {0, "DoReserved", &DoReserved},
43 {WIFI_BEACON, "OnBeacon", &OnBeacon},
44 {WIFI_ATIM, "OnATIM", &OnAtim},
45 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
46 {WIFI_AUTH, "OnAuth", &OnAuthClient},
47 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
48 {WIFI_ACTION, "OnAction", &OnAction},
49 };
50
51 static struct action_handler OnAction_tbl[] = {
52 {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
53 {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
54 {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
55 {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
56 {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
57 {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
58 {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved},
59 {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
60 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
61 {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
62 {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
63 };
64
65
66 static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
67
68 /**************************************************
69 OUI definitions for the vendor specific IE
70 ***************************************************/
71 unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
72 unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
73 unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
74 unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
75 unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
76
77 unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
78 unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
79
80 unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
81 unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
82
83 extern unsigned char REALTEK_96B_IE[];
84
85 /********************************************************
86 MCS rate definitions
87 *********************************************************/
88 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
89 unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
90
91 /********************************************************
92 ChannelPlan definitions
93 *********************************************************/
94 static struct rt_channel_plan_2g RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = {
95 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x00, RT_CHANNEL_DOMAIN_2G_WORLD , Passive scan CH 12, 13 */
96 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1 */
97 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* 0x02, RT_CHANNEL_DOMAIN_2G_FCC1 */
98 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1 */
99 {{10, 11, 12, 13}, 4}, /* 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2 */
100 {{}, 0}, /* 0x05, RT_CHANNEL_DOMAIN_2G_NULL */
101 };
102
103 static struct rt_channel_plan_map RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = {
104 /* 0x00 ~ 0x1F , Old Define ===== */
105 {0x02}, /* 0x00, RT_CHANNEL_DOMAIN_FCC */
106 {0x02}, /* 0x01, RT_CHANNEL_DOMAIN_IC */
107 {0x01}, /* 0x02, RT_CHANNEL_DOMAIN_ETSI */
108 {0x01}, /* 0x03, RT_CHANNEL_DOMAIN_SPAIN */
109 {0x01}, /* 0x04, RT_CHANNEL_DOMAIN_FRANCE */
110 {0x03}, /* 0x05, RT_CHANNEL_DOMAIN_MKK */
111 {0x03}, /* 0x06, RT_CHANNEL_DOMAIN_MKK1 */
112 {0x01}, /* 0x07, RT_CHANNEL_DOMAIN_ISRAEL */
113 {0x03}, /* 0x08, RT_CHANNEL_DOMAIN_TELEC */
114 {0x03}, /* 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN */
115 {0x00}, /* 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13 */
116 {0x02}, /* 0x0B, RT_CHANNEL_DOMAIN_TAIWAN */
117 {0x01}, /* 0x0C, RT_CHANNEL_DOMAIN_CHINA */
118 {0x02}, /* 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO */
119 {0x02}, /* 0x0E, RT_CHANNEL_DOMAIN_KOREA */
120 {0x02}, /* 0x0F, RT_CHANNEL_DOMAIN_TURKEY */
121 {0x01}, /* 0x10, RT_CHANNEL_DOMAIN_JAPAN */
122 {0x02}, /* 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS */
123 {0x01}, /* 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
124 {0x00}, /* 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G */
125 {0x02}, /* 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS */
126 {0x00}, /* 0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS */
127 {0x00}, /* 0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS */
128 {0x03}, /* 0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
129 {0x05}, /* 0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS */
130 {0x02}, /* 0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS */
131 {0x00}, /* 0x1A, */
132 {0x00}, /* 0x1B, */
133 {0x00}, /* 0x1C, */
134 {0x00}, /* 0x1D, */
135 {0x00}, /* 0x1E, */
136 {0x05}, /* 0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G */
137 /* 0x20 ~ 0x7F , New Define ===== */
138 {0x00}, /* 0x20, RT_CHANNEL_DOMAIN_WORLD_NULL */
139 {0x01}, /* 0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL */
140 {0x02}, /* 0x22, RT_CHANNEL_DOMAIN_FCC1_NULL */
141 {0x03}, /* 0x23, RT_CHANNEL_DOMAIN_MKK1_NULL */
142 {0x04}, /* 0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL */
143 {0x02}, /* 0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1 */
144 {0x00}, /* 0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1 */
145 {0x03}, /* 0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1 */
146 {0x00}, /* 0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1 */
147 {0x00}, /* 0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2 */
148 {0x00}, /* 0x2A, */
149 {0x00}, /* 0x2B, */
150 {0x00}, /* 0x2C, */
151 {0x00}, /* 0x2D, */
152 {0x00}, /* 0x2E, */
153 {0x00}, /* 0x2F, */
154 {0x00}, /* 0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3 */
155 {0x00}, /* 0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4 */
156 {0x00}, /* 0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5 */
157 {0x00}, /* 0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6 */
158 {0x02}, /* 0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7 */
159 {0x00}, /* 0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2 */
160 {0x00}, /* 0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3 */
161 {0x03}, /* 0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2 */
162 {0x03}, /* 0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3 */
163 {0x02}, /* 0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1 */
164 {0x00}, /* 0x3A, */
165 {0x00}, /* 0x3B, */
166 {0x00}, /* 0x3C, */
167 {0x00}, /* 0x3D, */
168 {0x00}, /* 0x3E, */
169 {0x00}, /* 0x3F, */
170 {0x02}, /* 0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2 */
171 {0x03}, /* 0x41, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G */
172 };
173
174 static struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03}; /* use the combination for max channel numbers */
175
176 /*
177 * Search the @param channel_num in given @param channel_set
178 * @ch_set: the given channel set
179 * @ch: the given channel number
180 *
181 * return the index of channel_num in channel_set, -1 if not found
182 */
rtw_ch_set_search_ch(struct rt_channel_info * ch_set,const u32 ch)183 int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch)
184 {
185 int i;
186 for (i = 0; ch_set[i].ChannelNum != 0; i++) {
187 if (ch == ch_set[i].ChannelNum)
188 break;
189 }
190
191 if (i >= ch_set[i].ChannelNum)
192 return -1;
193 return i;
194 }
195
196 /****************************************************************************
197
198 Following are the initialization functions for WiFi MLME
199
200 *****************************************************************************/
201
init_hw_mlme_ext(struct adapter * padapter)202 int init_hw_mlme_ext(struct adapter *padapter)
203 {
204 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
205
206 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
207 return _SUCCESS;
208 }
209
init_mlme_ext_priv_value(struct adapter * padapter)210 static void init_mlme_ext_priv_value(struct adapter *padapter)
211 {
212 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
213 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
214 unsigned char mixed_datarate[NumRates] = {
215 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
216 _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_,
217 _48M_RATE_, _54M_RATE_, 0xff
218 };
219 unsigned char mixed_basicrate[NumRates] = {
220 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
221 _12M_RATE_, _24M_RATE_, 0xff,
222 };
223
224 atomic_set(&pmlmeext->event_seq, 0);
225 pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
226
227 pmlmeext->cur_channel = padapter->registrypriv.channel;
228 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
229 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
230 pmlmeext->oper_channel = pmlmeext->cur_channel ;
231 pmlmeext->oper_bwmode = pmlmeext->cur_bwmode;
232 pmlmeext->oper_ch_offset = pmlmeext->cur_ch_offset;
233 pmlmeext->retry = 0;
234
235 pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
236
237 memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
238 memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
239
240 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
241
242 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
243 pmlmeext->sitesurvey_res.channel_idx = 0;
244 pmlmeext->sitesurvey_res.bss_cnt = 0;
245 pmlmeext->scan_abort = false;
246
247 pmlmeinfo->state = WIFI_FW_NULL_STATE;
248 pmlmeinfo->reauth_count = 0;
249 pmlmeinfo->reassoc_count = 0;
250 pmlmeinfo->link_count = 0;
251 pmlmeinfo->auth_seq = 0;
252 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
253 pmlmeinfo->key_index = 0;
254 pmlmeinfo->iv = 0;
255
256 pmlmeinfo->enc_algo = _NO_PRIVACY_;
257 pmlmeinfo->authModeToggle = 0;
258
259 memset(pmlmeinfo->chg_txt, 0, 128);
260
261 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
262 pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
263
264 pmlmeinfo->dialogToken = 0;
265
266 pmlmeext->action_public_rxseq = 0xffff;
267 pmlmeext->action_public_dialog_token = 0xff;
268 }
269
has_channel(struct rt_channel_info * channel_set,u8 chanset_size,u8 chan)270 static int has_channel(struct rt_channel_info *channel_set,
271 u8 chanset_size,
272 u8 chan) {
273 int i;
274
275 for (i = 0; i < chanset_size; i++) {
276 if (channel_set[i].ChannelNum == chan)
277 return 1;
278 }
279 return 0;
280 }
281
init_channel_list(struct adapter * padapter,struct rt_channel_info * channel_set,u8 chanset_size,struct p2p_channels * channel_list)282 static void init_channel_list(struct adapter *padapter, struct rt_channel_info *channel_set,
283 u8 chanset_size,
284 struct p2p_channels *channel_list) {
285 struct p2p_oper_class_map op_class[] = {
286 { IEEE80211G, 81, 1, 13, 1, BW20 },
287 { IEEE80211G, 82, 14, 14, 1, BW20 },
288 { -1, 0, 0, 0, 0, BW20 }
289 };
290
291 int cla, op;
292
293 cla = 0;
294
295 for (op = 0; op_class[op].op_class; op++) {
296 u8 ch;
297 struct p2p_oper_class_map *o = &op_class[op];
298 struct p2p_reg_class *reg = NULL;
299
300 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
301 if (!has_channel(channel_set, chanset_size, ch)) {
302 continue;
303 }
304
305 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
306 continue;
307
308 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) &&
309 ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
310 continue;
311
312 if (reg == NULL) {
313 reg = &channel_list->reg_class[cla];
314 cla++;
315 reg->reg_class = o->op_class;
316 reg->channels = 0;
317 }
318 reg->channel[reg->channels] = ch;
319 reg->channels++;
320 }
321 }
322 channel_list->reg_classes = cla;
323 }
324
init_channel_set(struct adapter * padapter,u8 ChannelPlan,struct rt_channel_info * channel_set)325 static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_channel_info *channel_set)
326 {
327 u8 index, chanset_size = 0;
328 u8 b2_4GBand = false;
329 u8 Index2G = 0;
330
331 memset(channel_set, 0, sizeof(struct rt_channel_info) * MAX_CHANNEL_NUM);
332
333 if (ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE) {
334 DBG_88E("ChannelPlan ID %x error !!!!!\n", ChannelPlan);
335 return chanset_size;
336 }
337
338 if (padapter->registrypriv.wireless_mode & WIRELESS_11G) {
339 b2_4GBand = true;
340 if (RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
341 Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
342 else
343 Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
344 }
345
346 if (b2_4GBand) {
347 for (index = 0; index < RTW_ChannelPlan2G[Index2G].Len; index++) {
348 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan2G[Index2G].Channel[index];
349
350 if ((RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN == ChannelPlan) ||/* Channel 1~11 is active, and 12~14 is passive */
351 (RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G == ChannelPlan)) {
352 if (channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
353 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
354 else if ((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
355 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
356 } else if (RT_CHANNEL_DOMAIN_WORLD_WIDE_13 == ChannelPlan ||
357 RT_CHANNEL_DOMAIN_2G_WORLD == Index2G) {/* channel 12~13, passive scan */
358 if (channel_set[chanset_size].ChannelNum <= 11)
359 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
360 else
361 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
362 } else {
363 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
364 }
365
366 chanset_size++;
367 }
368 }
369 return chanset_size;
370 }
371
init_mlme_ext_priv(struct adapter * padapter)372 int init_mlme_ext_priv(struct adapter *padapter)
373 {
374 int res = _SUCCESS;
375 struct registry_priv *pregistrypriv = &padapter->registrypriv;
376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
377 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
378 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
379
380 pmlmeext->padapter = padapter;
381
382 init_mlme_ext_priv_value(padapter);
383 pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
384
385 init_mlme_ext_timer(padapter);
386
387 #ifdef CONFIG_88EU_AP_MODE
388 init_mlme_ap_info(padapter);
389 #endif
390
391 pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set);
392 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
393
394 pmlmeext->chan_scan_time = SURVEY_TO;
395 pmlmeext->mlmeext_init = true;
396
397
398 pmlmeext->active_keep_alive_check = true;
399
400 return res;
401 }
402
free_mlme_ext_priv(struct mlme_ext_priv * pmlmeext)403 void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
404 {
405 struct adapter *padapter = pmlmeext->padapter;
406
407 if (!padapter)
408 return;
409
410 if (padapter->bDriverStopped) {
411 del_timer_sync(&pmlmeext->survey_timer);
412 del_timer_sync(&pmlmeext->link_timer);
413 }
414 }
415
_mgt_dispatcher(struct adapter * padapter,struct mlme_handler * ptable,struct recv_frame * precv_frame)416 static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame)
417 {
418 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
419 u8 *pframe = precv_frame->rx_data;
420
421 if (ptable->func) {
422 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
423 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
424 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
425 return;
426 ptable->func(padapter, precv_frame);
427 }
428 }
429
mgt_dispatcher(struct adapter * padapter,struct recv_frame * precv_frame)430 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
431 {
432 int index;
433 struct mlme_handler *ptable;
434 #ifdef CONFIG_88EU_AP_MODE
435 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
436 #endif /* CONFIG_88EU_AP_MODE */
437 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
438 u8 *pframe = precv_frame->rx_data;
439 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
440
441 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
442 ("+mgt_dispatcher: type(0x%x) subtype(0x%x)\n",
443 GetFrameType(pframe), GetFrameSubType(pframe)));
444
445 if (GetFrameType(pframe) != WIFI_MGT_TYPE) {
446 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("mgt_dispatcher: type(0x%x) error!\n", GetFrameType(pframe)));
447 return;
448 }
449
450 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
451 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
452 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
453 return;
454
455 ptable = mlme_sta_tbl;
456
457 index = GetFrameSubType(pframe) >> 4;
458
459 if (index > 13) {
460 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type=%d\n", index));
461 return;
462 }
463 ptable += index;
464
465 if (psta != NULL) {
466 if (GetRetry(pframe)) {
467 if (precv_frame->attrib.seq_num ==
468 psta->RxMgmtFrameSeqNum) {
469 /* drop the duplicate management frame */
470 DBG_88E("Drop duplicate management frame with seq_num=%d.\n",
471 precv_frame->attrib.seq_num);
472 return;
473 }
474 }
475 psta->RxMgmtFrameSeqNum = precv_frame->attrib.seq_num;
476 }
477
478 #ifdef CONFIG_88EU_AP_MODE
479 switch (GetFrameSubType(pframe)) {
480 case WIFI_AUTH:
481 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
482 ptable->func = &OnAuth;
483 else
484 ptable->func = &OnAuthClient;
485 /* fall through */
486 case WIFI_ASSOCREQ:
487 case WIFI_REASSOCREQ:
488 _mgt_dispatcher(padapter, ptable, precv_frame);
489 break;
490 case WIFI_PROBEREQ:
491 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
492 _mgt_dispatcher(padapter, ptable, precv_frame);
493 else
494 _mgt_dispatcher(padapter, ptable, precv_frame);
495 break;
496 case WIFI_BEACON:
497 _mgt_dispatcher(padapter, ptable, precv_frame);
498 break;
499 case WIFI_ACTION:
500 _mgt_dispatcher(padapter, ptable, precv_frame);
501 break;
502 default:
503 _mgt_dispatcher(padapter, ptable, precv_frame);
504 break;
505 }
506 #else
507 _mgt_dispatcher(padapter, ptable, precv_frame);
508 #endif
509 }
510
511 /****************************************************************************
512
513 Following are the callback functions for each subtype of the management frames
514
515 *****************************************************************************/
516
OnProbeReq(struct adapter * padapter,struct recv_frame * precv_frame)517 unsigned int OnProbeReq(struct adapter *padapter, struct recv_frame *precv_frame)
518 {
519 unsigned int ielen;
520 unsigned char *p;
521 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
522 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
523 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
524 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
525 u8 *pframe = precv_frame->rx_data;
526 uint len = precv_frame->len;
527 u8 is_valid_p2p_probereq = false;
528
529 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
530 return _SUCCESS;
531
532 if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
533 !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
534 return _SUCCESS;
535
536 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
537 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
538
539 /* check (wildcard) SSID */
540 if (p != NULL) {
541 if (is_valid_p2p_probereq)
542 goto _issue_probersp;
543
544 if ((ielen != 0 && memcmp((void *)(p+2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength)) ||
545 (ielen == 0 && pmlmeinfo->hidden_ssid_mode))
546 return _SUCCESS;
547
548 _issue_probersp:
549
550 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
551 pmlmepriv->cur_network.join_res)
552 issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
553 }
554 return _SUCCESS;
555 }
556
OnProbeRsp(struct adapter * padapter,struct recv_frame * precv_frame)557 unsigned int OnProbeRsp(struct adapter *padapter, struct recv_frame *precv_frame)
558 {
559 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
560
561 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
562 report_survey_event(padapter, precv_frame);
563 return _SUCCESS;
564 }
565
566 return _SUCCESS;
567 }
568
OnBeacon(struct adapter * padapter,struct recv_frame * precv_frame)569 unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
570 {
571 int cam_idx;
572 struct sta_info *psta;
573 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
574 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
575 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
576 struct sta_priv *pstapriv = &padapter->stapriv;
577 u8 *pframe = precv_frame->rx_data;
578 uint len = precv_frame->len;
579 struct wlan_bssid_ex *pbss;
580 int ret = _SUCCESS;
581
582 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
583 report_survey_event(padapter, precv_frame);
584 return _SUCCESS;
585 }
586
587 if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
588 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
589 /* we should update current network before auth, or some IE is wrong */
590 pbss = (struct wlan_bssid_ex *)rtw_malloc(sizeof(struct wlan_bssid_ex));
591 if (pbss) {
592 if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
593 update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true);
594 rtw_get_bcn_info(&(pmlmepriv->cur_network));
595 }
596 kfree(pbss);
597 }
598
599 /* check the vendor of the assoc AP */
600 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe+sizeof(struct rtw_ieee80211_hdr_3addr), len-sizeof(struct rtw_ieee80211_hdr_3addr));
601
602 /* update TSF Value */
603 update_TSF(pmlmeext, pframe, len);
604
605 /* start auth */
606 start_clnt_auth(padapter);
607
608 return _SUCCESS;
609 }
610
611 if (((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
612 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
613 if (psta != NULL) {
614 ret = rtw_check_bcn_info(padapter, pframe, len);
615 if (!ret) {
616 DBG_88E_LEVEL(_drv_info_, "ap has changed, disconnect now\n ");
617 receive_disconnect(padapter, pmlmeinfo->network.MacAddress , 65535);
618 return _SUCCESS;
619 }
620 /* update WMM, ERP in the beacon */
621 /* todo: the timer is used instead of the number of the beacon received */
622 if ((sta_rx_pkts(psta) & 0xf) == 0)
623 update_beacon_info(padapter, pframe, len, psta);
624 }
625 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
626 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
627 if (psta != NULL) {
628 /* update WMM, ERP in the beacon */
629 /* todo: the timer is used instead of the number of the beacon received */
630 if ((sta_rx_pkts(psta) & 0xf) == 0)
631 update_beacon_info(padapter, pframe, len, psta);
632 } else {
633 /* allocate a new CAM entry for IBSS station */
634 cam_idx = allocate_fw_sta_entry(padapter);
635 if (cam_idx == NUM_STA)
636 goto _END_ONBEACON_;
637
638 /* get supported rate */
639 if (update_sta_support_rate(padapter, (pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_), (len - WLAN_HDR_A3_LEN - _BEACON_IE_OFFSET_), cam_idx) == _FAIL) {
640 pmlmeinfo->FW_sta_info[cam_idx].status = 0;
641 goto _END_ONBEACON_;
642 }
643
644 /* update TSF Value */
645 update_TSF(pmlmeext, pframe, len);
646
647 /* report sta add event */
648 report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
649 }
650 }
651 }
652
653 _END_ONBEACON_:
654
655 return _SUCCESS;
656 }
657
OnAuth(struct adapter * padapter,struct recv_frame * precv_frame)658 unsigned int OnAuth(struct adapter *padapter, struct recv_frame *precv_frame)
659 {
660 #ifdef CONFIG_88EU_AP_MODE
661 unsigned int auth_mode, ie_len;
662 u16 seq;
663 unsigned char *sa, *p;
664 u16 algorithm;
665 int status;
666 static struct sta_info stat;
667 struct sta_info *pstat = NULL;
668 struct sta_priv *pstapriv = &padapter->stapriv;
669 struct security_priv *psecuritypriv = &padapter->securitypriv;
670 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
671 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
672 u8 *pframe = precv_frame->rx_data;
673 uint len = precv_frame->len;
674
675 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
676 return _FAIL;
677
678 DBG_88E("+OnAuth\n");
679
680 sa = GetAddr2Ptr(pframe);
681
682 auth_mode = psecuritypriv->dot11AuthAlgrthm;
683 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + 2));
684 algorithm = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN));
685
686 DBG_88E("auth alg=%x, seq=%X\n", algorithm, seq);
687
688 if (auth_mode == 2 && psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
689 psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
690 auth_mode = 0;
691
692 if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */
693 (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */
694 DBG_88E("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
695 algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
696
697 status = _STATS_NO_SUPP_ALG_;
698
699 goto auth_fail;
700 }
701
702 if (!rtw_access_ctrl(padapter, sa)) {
703 status = _STATS_UNABLE_HANDLE_STA_;
704 goto auth_fail;
705 }
706
707 pstat = rtw_get_stainfo(pstapriv, sa);
708 if (pstat == NULL) {
709 /* allocate a new one */
710 DBG_88E("going to alloc stainfo for sa=%pM\n", sa);
711 pstat = rtw_alloc_stainfo(pstapriv, sa);
712 if (pstat == NULL) {
713 DBG_88E(" Exceed the upper limit of supported clients...\n");
714 status = _STATS_UNABLE_HANDLE_STA_;
715 goto auth_fail;
716 }
717
718 pstat->state = WIFI_FW_AUTH_NULL;
719 pstat->auth_seq = 0;
720 } else {
721 spin_lock_bh(&pstapriv->asoc_list_lock);
722 if (!list_empty(&pstat->asoc_list)) {
723 list_del_init(&pstat->asoc_list);
724 pstapriv->asoc_list_cnt--;
725 }
726 spin_unlock_bh(&pstapriv->asoc_list_lock);
727
728 if (seq == 1) {
729 /* TODO: STA re_auth and auth timeout */
730 }
731 }
732
733 spin_lock_bh(&pstapriv->auth_list_lock);
734 if (list_empty(&pstat->auth_list)) {
735 list_add_tail(&pstat->auth_list, &pstapriv->auth_list);
736 pstapriv->auth_list_cnt++;
737 }
738 spin_unlock_bh(&pstapriv->auth_list_lock);
739
740 if (pstat->auth_seq == 0)
741 pstat->expire_to = pstapriv->auth_to;
742
743 if ((pstat->auth_seq + 1) != seq) {
744 DBG_88E("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
745 seq, pstat->auth_seq+1);
746 status = _STATS_OUT_OF_AUTH_SEQ_;
747 goto auth_fail;
748 }
749
750 if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2)) {
751 if (seq == 1) {
752 pstat->state &= ~WIFI_FW_AUTH_NULL;
753 pstat->state |= WIFI_FW_AUTH_SUCCESS;
754 pstat->expire_to = pstapriv->assoc_to;
755 pstat->authalg = algorithm;
756 } else {
757 DBG_88E("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
758 seq, pstat->auth_seq+1);
759 status = _STATS_OUT_OF_AUTH_SEQ_;
760 goto auth_fail;
761 }
762 } else { /* shared system or auto authentication */
763 if (seq == 1) {
764 /* prepare for the challenging txt... */
765
766 pstat->state &= ~WIFI_FW_AUTH_NULL;
767 pstat->state |= WIFI_FW_AUTH_STATE;
768 pstat->authalg = algorithm;
769 pstat->auth_seq = 2;
770 } else if (seq == 3) {
771 /* checking for challenging txt... */
772 DBG_88E("checking for challenging txt...\n");
773
774 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_ , _CHLGETXT_IE_, (int *)&ie_len,
775 len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
776
777 if ((p == NULL) || (ie_len <= 0)) {
778 DBG_88E("auth rejected because challenge failure!(1)\n");
779 status = _STATS_CHALLENGE_FAIL_;
780 goto auth_fail;
781 }
782
783 if (!memcmp((void *)(p + 2), pstat->chg_txt, 128)) {
784 pstat->state &= (~WIFI_FW_AUTH_STATE);
785 pstat->state |= WIFI_FW_AUTH_SUCCESS;
786 /* challenging txt is correct... */
787 pstat->expire_to = pstapriv->assoc_to;
788 } else {
789 DBG_88E("auth rejected because challenge failure!\n");
790 status = _STATS_CHALLENGE_FAIL_;
791 goto auth_fail;
792 }
793 } else {
794 DBG_88E("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
795 seq, pstat->auth_seq+1);
796 status = _STATS_OUT_OF_AUTH_SEQ_;
797 goto auth_fail;
798 }
799 }
800
801 /* Now, we are going to issue_auth... */
802 pstat->auth_seq = seq + 1;
803
804 #ifdef CONFIG_88EU_AP_MODE
805 issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
806 #endif
807
808 if (pstat->state & WIFI_FW_AUTH_SUCCESS)
809 pstat->auth_seq = 0;
810
811 return _SUCCESS;
812
813 auth_fail:
814
815 if (pstat)
816 rtw_free_stainfo(padapter , pstat);
817
818 pstat = &stat;
819 memset((char *)pstat, '\0', sizeof(stat));
820 pstat->auth_seq = 2;
821 memcpy(pstat->hwaddr, sa, 6);
822
823 #ifdef CONFIG_88EU_AP_MODE
824 issue_auth(padapter, pstat, (unsigned short)status);
825 #endif
826
827 #endif
828 return _FAIL;
829 }
830
OnAuthClient(struct adapter * padapter,struct recv_frame * precv_frame)831 unsigned int OnAuthClient(struct adapter *padapter, struct recv_frame *precv_frame)
832 {
833 unsigned int seq, len, status, offset;
834 unsigned char *p;
835 unsigned int go2asoc = 0;
836 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
837 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
838 u8 *pframe = precv_frame->rx_data;
839 uint pkt_len = precv_frame->len;
840
841 DBG_88E("%s\n", __func__);
842
843 /* check A1 matches or not */
844 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
845 return _SUCCESS;
846
847 if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
848 return _SUCCESS;
849
850 offset = (GetPrivacy(pframe)) ? 4 : 0;
851
852 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 2));
853 status = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 4));
854
855 if (status != 0) {
856 DBG_88E("clnt auth fail, status: %d\n", status);
857 if (status == 13) { /* pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto) */
858 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
859 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
860 else
861 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
862 }
863
864 set_link_timer(pmlmeext, 1);
865 goto authclnt_fail;
866 }
867
868 if (seq == 2) {
869 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
870 /* legendary shared system */
871 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
872 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
873
874 if (p == NULL)
875 goto authclnt_fail;
876
877 memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
878 pmlmeinfo->auth_seq = 3;
879 issue_auth(padapter, NULL, 0);
880 set_link_timer(pmlmeext, REAUTH_TO);
881
882 return _SUCCESS;
883 } else {
884 /* open system */
885 go2asoc = 1;
886 }
887 } else if (seq == 4) {
888 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
889 go2asoc = 1;
890 else
891 goto authclnt_fail;
892 } else {
893 /* this is also illegal */
894 goto authclnt_fail;
895 }
896
897 if (go2asoc) {
898 DBG_88E_LEVEL(_drv_info_, "auth success, start assoc\n");
899 start_clnt_assoc(padapter);
900 return _SUCCESS;
901 }
902 authclnt_fail:
903 return _FAIL;
904 }
905
OnAssocReq(struct adapter * padapter,struct recv_frame * precv_frame)906 unsigned int OnAssocReq(struct adapter *padapter, struct recv_frame *precv_frame)
907 {
908 #ifdef CONFIG_88EU_AP_MODE
909 u16 capab_info;
910 struct rtw_ieee802_11_elems elems;
911 struct sta_info *pstat;
912 unsigned char reassoc, *p, *pos, *wpa_ie;
913 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
914 int i, ie_len, wpa_ie_len, left;
915 unsigned char supportRate[16];
916 int supportRateNum;
917 unsigned short status = _STATS_SUCCESSFUL_;
918 unsigned short frame_type, ie_offset = 0;
919 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
920 struct security_priv *psecuritypriv = &padapter->securitypriv;
921 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
922 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
923 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
924 struct sta_priv *pstapriv = &padapter->stapriv;
925 u8 *pframe = precv_frame->rx_data;
926 uint pkt_len = precv_frame->len;
927
928 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
929 return _FAIL;
930
931 frame_type = GetFrameSubType(pframe);
932 if (frame_type == WIFI_ASSOCREQ) {
933 reassoc = 0;
934 ie_offset = _ASOCREQ_IE_OFFSET_;
935 } else { /* WIFI_REASSOCREQ */
936 reassoc = 1;
937 ie_offset = _REASOCREQ_IE_OFFSET_;
938 }
939
940
941 if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
942 DBG_88E("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
943 "\n", reassoc, (unsigned long)pkt_len);
944 return _FAIL;
945 }
946
947 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
948 if (pstat == (struct sta_info *)NULL) {
949 status = _RSON_CLS2_;
950 goto asoc_class2_error;
951 }
952
953 capab_info = get_unaligned_le16(pframe + WLAN_HDR_A3_LEN);
954
955 left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
956 pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
957
958
959 DBG_88E("%s\n", __func__);
960
961 /* check if this stat has been successfully authenticated/assocated */
962 if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) {
963 if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) {
964 status = _RSON_CLS2_;
965 goto asoc_class2_error;
966 } else {
967 pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
968 pstat->state |= WIFI_FW_ASSOC_STATE;
969 }
970 } else {
971 pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
972 pstat->state |= WIFI_FW_ASSOC_STATE;
973 }
974 pstat->capability = capab_info;
975 /* now parse all ieee802_11 ie to point to elems */
976 if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
977 !elems.ssid) {
978 DBG_88E("STA %pM sent invalid association request\n",
979 pstat->hwaddr);
980 status = _STATS_FAILURE_;
981 goto OnAssocReqFail;
982 }
983
984
985 /* now we should check all the fields... */
986 /* checking SSID */
987 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
988 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
989 if (p == NULL)
990 status = _STATS_FAILURE_;
991
992 if (ie_len == 0) { /* broadcast ssid, however it is not allowed in assocreq */
993 status = _STATS_FAILURE_;
994 } else {
995 /* check if ssid match */
996 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
997 status = _STATS_FAILURE_;
998
999 if (ie_len != cur->Ssid.SsidLength)
1000 status = _STATS_FAILURE_;
1001 }
1002
1003 if (_STATS_SUCCESSFUL_ != status)
1004 goto OnAssocReqFail;
1005
1006 /* check if the supported rate is ok */
1007 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SUPPORTEDRATES_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1008 if (p == NULL) {
1009 DBG_88E("Rx a sta assoc-req which supported rate is empty!\n");
1010 /* use our own rate set as statoin used */
1011 /* memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN); */
1012 /* supportRateNum = AP_BSSRATE_LEN; */
1013
1014 status = _STATS_FAILURE_;
1015 goto OnAssocReqFail;
1016 } else {
1017 memcpy(supportRate, p+2, ie_len);
1018 supportRateNum = ie_len;
1019
1020 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _EXT_SUPPORTEDRATES_IE_ , &ie_len,
1021 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1022 if (p != NULL) {
1023 if (supportRateNum <= sizeof(supportRate)) {
1024 memcpy(supportRate+supportRateNum, p+2, ie_len);
1025 supportRateNum += ie_len;
1026 }
1027 }
1028 }
1029
1030 /* todo: mask supportRate between AP & STA -> move to update raid */
1031 /* get_matched_rate(pmlmeext, supportRate, &supportRateNum, 0); */
1032
1033 /* update station supportRate */
1034 pstat->bssratelen = supportRateNum;
1035 memcpy(pstat->bssrateset, supportRate, supportRateNum);
1036 UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
1037
1038 /* check RSN/WPA/WPS */
1039 pstat->dot8021xalg = 0;
1040 pstat->wpa_psk = 0;
1041 pstat->wpa_group_cipher = 0;
1042 pstat->wpa2_group_cipher = 0;
1043 pstat->wpa_pairwise_cipher = 0;
1044 pstat->wpa2_pairwise_cipher = 0;
1045 memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
1046 if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
1047 int group_cipher = 0, pairwise_cipher = 0;
1048
1049 wpa_ie = elems.rsn_ie;
1050 wpa_ie_len = elems.rsn_ie_len;
1051
1052 if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1053 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1054 pstat->wpa_psk |= BIT(1);
1055
1056 pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
1057 pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
1058
1059 if (!pstat->wpa2_group_cipher)
1060 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1061
1062 if (!pstat->wpa2_pairwise_cipher)
1063 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1064 } else {
1065 status = WLAN_STATUS_INVALID_IE;
1066 }
1067 } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
1068 int group_cipher = 0, pairwise_cipher = 0;
1069
1070 wpa_ie = elems.wpa_ie;
1071 wpa_ie_len = elems.wpa_ie_len;
1072
1073 if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1074 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1075 pstat->wpa_psk |= BIT(0);
1076
1077 pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
1078 pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
1079
1080 if (!pstat->wpa_group_cipher)
1081 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1082
1083 if (!pstat->wpa_pairwise_cipher)
1084 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1085 } else {
1086 status = WLAN_STATUS_INVALID_IE;
1087 }
1088 } else {
1089 wpa_ie = NULL;
1090 wpa_ie_len = 0;
1091 }
1092
1093 if (_STATS_SUCCESSFUL_ != status)
1094 goto OnAssocReqFail;
1095
1096 pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
1097 if (wpa_ie == NULL) {
1098 if (elems.wps_ie) {
1099 DBG_88E("STA included WPS IE in "
1100 "(Re)Association Request - assume WPS is "
1101 "used\n");
1102 pstat->flags |= WLAN_STA_WPS;
1103 /* wpabuf_free(sta->wps_ie); */
1104 /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
1105 /* elems.wps_ie_len - 4); */
1106 } else {
1107 DBG_88E("STA did not include WPA/RSN IE "
1108 "in (Re)Association Request - possible WPS "
1109 "use\n");
1110 pstat->flags |= WLAN_STA_MAYBE_WPS;
1111 }
1112
1113
1114 /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
1115 /* that the selected registrar of AP is _FLASE */
1116 if ((psecuritypriv->wpa_psk > 0) && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
1117 if (pmlmepriv->wps_beacon_ie) {
1118 u8 selected_registrar = 0;
1119
1120 rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR , &selected_registrar, NULL);
1121
1122 if (!selected_registrar) {
1123 DBG_88E("selected_registrar is false , or AP is not ready to do WPS\n");
1124
1125 status = _STATS_UNABLE_HANDLE_STA_;
1126
1127 goto OnAssocReqFail;
1128 }
1129 }
1130 }
1131 } else {
1132 int copy_len;
1133
1134 if (psecuritypriv->wpa_psk == 0) {
1135 DBG_88E("STA %pM: WPA/RSN IE in association "
1136 "request, but AP don't support WPA/RSN\n", pstat->hwaddr);
1137
1138 status = WLAN_STATUS_INVALID_IE;
1139
1140 goto OnAssocReqFail;
1141 }
1142
1143 if (elems.wps_ie) {
1144 DBG_88E("STA included WPS IE in "
1145 "(Re)Association Request - WPS is "
1146 "used\n");
1147 pstat->flags |= WLAN_STA_WPS;
1148 copy_len = 0;
1149 } else {
1150 copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len+2);
1151 }
1152 if (copy_len > 0)
1153 memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
1154 }
1155 /* check if there is WMM IE & support WWM-PS */
1156 pstat->flags &= ~WLAN_STA_WME;
1157 pstat->qos_option = 0;
1158 pstat->qos_info = 0;
1159 pstat->has_legacy_ac = true;
1160 pstat->uapsd_vo = 0;
1161 pstat->uapsd_vi = 0;
1162 pstat->uapsd_be = 0;
1163 pstat->uapsd_bk = 0;
1164 if (pmlmepriv->qospriv.qos_option) {
1165 p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
1166 for (;;) {
1167 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1168 if (p != NULL) {
1169 if (!memcmp(p+2, WMM_IE, 6)) {
1170 pstat->flags |= WLAN_STA_WME;
1171
1172 pstat->qos_option = 1;
1173 pstat->qos_info = *(p+8);
1174
1175 pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
1176
1177 if ((pstat->qos_info&0xf) != 0xf)
1178 pstat->has_legacy_ac = true;
1179 else
1180 pstat->has_legacy_ac = false;
1181
1182 if (pstat->qos_info&0xf) {
1183 if (pstat->qos_info&BIT(0))
1184 pstat->uapsd_vo = BIT(0)|BIT(1);
1185 else
1186 pstat->uapsd_vo = 0;
1187
1188 if (pstat->qos_info&BIT(1))
1189 pstat->uapsd_vi = BIT(0)|BIT(1);
1190 else
1191 pstat->uapsd_vi = 0;
1192
1193 if (pstat->qos_info&BIT(2))
1194 pstat->uapsd_bk = BIT(0)|BIT(1);
1195 else
1196 pstat->uapsd_bk = 0;
1197
1198 if (pstat->qos_info&BIT(3))
1199 pstat->uapsd_be = BIT(0)|BIT(1);
1200 else
1201 pstat->uapsd_be = 0;
1202 }
1203 break;
1204 }
1205 } else {
1206 break;
1207 }
1208 p = p + ie_len + 2;
1209 }
1210 }
1211
1212 /* save HT capabilities in the sta object */
1213 memset(&pstat->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
1214 if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
1215 pstat->flags |= WLAN_STA_HT;
1216
1217 pstat->flags |= WLAN_STA_WME;
1218
1219 memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
1220 } else {
1221 pstat->flags &= ~WLAN_STA_HT;
1222 }
1223 if ((!pmlmepriv->htpriv.ht_option) && (pstat->flags&WLAN_STA_HT)) {
1224 status = _STATS_FAILURE_;
1225 goto OnAssocReqFail;
1226 }
1227
1228 if ((pstat->flags & WLAN_STA_HT) &&
1229 ((pstat->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
1230 (pstat->wpa_pairwise_cipher&WPA_CIPHER_TKIP))) {
1231 DBG_88E("HT: %pM tried to "
1232 "use TKIP with HT association\n", pstat->hwaddr);
1233
1234 /* status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; */
1235 /* goto OnAssocReqFail; */
1236 }
1237
1238 pstat->flags |= WLAN_STA_NONERP;
1239 for (i = 0; i < pstat->bssratelen; i++) {
1240 if ((pstat->bssrateset[i] & 0x7f) > 22) {
1241 pstat->flags &= ~WLAN_STA_NONERP;
1242 break;
1243 }
1244 }
1245
1246 if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1247 pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
1248 else
1249 pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1250
1251
1252
1253 if (status != _STATS_SUCCESSFUL_)
1254 goto OnAssocReqFail;
1255
1256 /* TODO: identify_proprietary_vendor_ie(); */
1257 /* Realtek proprietary IE */
1258 /* identify if this is Broadcom sta */
1259 /* identify if this is ralink sta */
1260 /* Customer proprietary IE */
1261
1262 /* get a unique AID */
1263 if (pstat->aid > 0) {
1264 DBG_88E(" old AID %d\n", pstat->aid);
1265 } else {
1266 for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++)
1267 if (pstapriv->sta_aid[pstat->aid - 1] == NULL)
1268 break;
1269
1270 /* if (pstat->aid > NUM_STA) { */
1271 if (pstat->aid > pstapriv->max_num_sta) {
1272 pstat->aid = 0;
1273
1274 DBG_88E(" no room for more AIDs\n");
1275
1276 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1277
1278 goto OnAssocReqFail;
1279 } else {
1280 pstapriv->sta_aid[pstat->aid - 1] = pstat;
1281 DBG_88E("allocate new AID=(%d)\n", pstat->aid);
1282 }
1283 }
1284
1285 pstat->state &= (~WIFI_FW_ASSOC_STATE);
1286 pstat->state |= WIFI_FW_ASSOC_SUCCESS;
1287
1288 spin_lock_bh(&pstapriv->auth_list_lock);
1289 if (!list_empty(&pstat->auth_list)) {
1290 list_del_init(&pstat->auth_list);
1291 pstapriv->auth_list_cnt--;
1292 }
1293 spin_unlock_bh(&pstapriv->auth_list_lock);
1294
1295 spin_lock_bh(&pstapriv->asoc_list_lock);
1296 if (list_empty(&pstat->asoc_list)) {
1297 pstat->expire_to = pstapriv->expire_to;
1298 list_add_tail(&pstat->asoc_list, &pstapriv->asoc_list);
1299 pstapriv->asoc_list_cnt++;
1300 }
1301 spin_unlock_bh(&pstapriv->asoc_list_lock);
1302
1303 /* now the station is qualified to join our BSS... */
1304 if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
1305 #ifdef CONFIG_88EU_AP_MODE
1306 /* 1 bss_cap_update & sta_info_update */
1307 bss_cap_update_on_sta_join(padapter, pstat);
1308 sta_info_update(padapter, pstat);
1309
1310 /* issue assoc rsp before notify station join event. */
1311 if (frame_type == WIFI_ASSOCREQ)
1312 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1313 else
1314 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1315
1316 /* 2 - report to upper layer */
1317 DBG_88E("indicate_sta_join_event to upper layer - hostapd\n");
1318 rtw_indicate_sta_assoc_event(padapter, pstat);
1319
1320 /* 3-(1) report sta add event */
1321 report_add_sta_event(padapter, pstat->hwaddr, pstat->aid);
1322 #endif
1323 }
1324
1325 return _SUCCESS;
1326
1327 asoc_class2_error:
1328
1329 #ifdef CONFIG_88EU_AP_MODE
1330 issue_deauth(padapter, (void *)GetAddr2Ptr(pframe), status);
1331 #endif
1332
1333 return _FAIL;
1334
1335 OnAssocReqFail:
1336
1337
1338 #ifdef CONFIG_88EU_AP_MODE
1339 pstat->aid = 0;
1340 if (frame_type == WIFI_ASSOCREQ)
1341 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1342 else
1343 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1344 #endif
1345
1346
1347 #endif /* CONFIG_88EU_AP_MODE */
1348
1349 return _FAIL;
1350 }
1351
OnAssocRsp(struct adapter * padapter,struct recv_frame * precv_frame)1352 unsigned int OnAssocRsp(struct adapter *padapter, struct recv_frame *precv_frame)
1353 {
1354 uint i;
1355 int res;
1356 unsigned short status;
1357 struct ndis_802_11_var_ie *pIE;
1358 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1359 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1360 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1361 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */
1362 u8 *pframe = precv_frame->rx_data;
1363 uint pkt_len = precv_frame->len;
1364
1365 DBG_88E("%s\n", __func__);
1366
1367 /* check A1 matches or not */
1368 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
1369 return _SUCCESS;
1370
1371 if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
1372 return _SUCCESS;
1373
1374 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
1375 return _SUCCESS;
1376
1377 del_timer_sync(&pmlmeext->link_timer);
1378
1379 /* status */
1380 status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2));
1381 if (status > 0) {
1382 DBG_88E("assoc reject, status code: %d\n", status);
1383 pmlmeinfo->state = WIFI_FW_NULL_STATE;
1384 res = -4;
1385 goto report_assoc_result;
1386 }
1387
1388 /* get capabilities */
1389 pmlmeinfo->capability = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1390
1391 /* set slot time */
1392 pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20;
1393
1394 /* AID */
1395 pmlmeinfo->aid = (int)(le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 4))&0x3fff);
1396 res = pmlmeinfo->aid;
1397
1398 /* following are moved to join event callback function */
1399 /* to handle HT, WMM, rate adaptive, update MAC reg */
1400 /* for not to handle the synchronous IO in the tasklet */
1401 for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
1402 pIE = (struct ndis_802_11_var_ie *)(pframe + i);
1403
1404 switch (pIE->ElementID) {
1405 case _VENDOR_SPECIFIC_IE_:
1406 if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
1407 WMM_param_handler(padapter, pIE);
1408 break;
1409 case _HT_CAPABILITY_IE_: /* HT caps */
1410 HT_caps_handler(padapter, pIE);
1411 break;
1412 case _HT_EXTRA_INFO_IE_: /* HT info */
1413 HT_info_handler(padapter, pIE);
1414 break;
1415 case _ERPINFO_IE_:
1416 ERP_IE_handler(padapter, pIE);
1417 default:
1418 break;
1419 }
1420
1421 i += (pIE->Length + 2);
1422 }
1423
1424 pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
1425 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
1426
1427 /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
1428 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
1429
1430 report_assoc_result:
1431 if (res > 0) {
1432 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
1433 } else {
1434 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
1435 }
1436
1437 report_join_res(padapter, res);
1438
1439 return _SUCCESS;
1440 }
1441
OnDeAuth(struct adapter * padapter,struct recv_frame * precv_frame)1442 unsigned int OnDeAuth(struct adapter *padapter, struct recv_frame *precv_frame)
1443 {
1444 unsigned short reason;
1445 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1446 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1447 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1448 u8 *pframe = precv_frame->rx_data;
1449
1450 /* check A3 */
1451 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1452 ETH_ALEN))
1453 return _SUCCESS;
1454
1455 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1456
1457 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1458
1459 #ifdef CONFIG_88EU_AP_MODE
1460 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1461 struct sta_info *psta;
1462 struct sta_priv *pstapriv = &padapter->stapriv;
1463
1464 DBG_88E_LEVEL(_drv_always_, "ap recv deauth reason code(%d) sta:%pM\n",
1465 reason, GetAddr2Ptr(pframe));
1466
1467 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1468 if (psta) {
1469 u8 updated = 0;
1470
1471 spin_lock_bh(&pstapriv->asoc_list_lock);
1472 if (!list_empty(&psta->asoc_list)) {
1473 list_del_init(&psta->asoc_list);
1474 pstapriv->asoc_list_cnt--;
1475 updated = ap_free_sta(padapter, psta, false, reason);
1476 }
1477 spin_unlock_bh(&pstapriv->asoc_list_lock);
1478
1479 associated_clients_update(padapter, updated);
1480 }
1481
1482
1483 return _SUCCESS;
1484 } else
1485 #endif
1486 {
1487 DBG_88E_LEVEL(_drv_always_, "sta recv deauth reason code(%d) sta:%pM\n",
1488 reason, GetAddr3Ptr(pframe));
1489
1490 receive_disconnect(padapter, GetAddr3Ptr(pframe) , reason);
1491 }
1492 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1493 return _SUCCESS;
1494 }
1495
OnDisassoc(struct adapter * padapter,struct recv_frame * precv_frame)1496 unsigned int OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
1497 {
1498 u16 reason;
1499 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1500 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1501 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1502 u8 *pframe = precv_frame->rx_data;
1503
1504 /* check A3 */
1505 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1506 ETH_ALEN))
1507 return _SUCCESS;
1508
1509 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1510
1511 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1512
1513 #ifdef CONFIG_88EU_AP_MODE
1514 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1515 struct sta_info *psta;
1516 struct sta_priv *pstapriv = &padapter->stapriv;
1517
1518 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1519 reason, GetAddr2Ptr(pframe));
1520
1521 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1522 if (psta) {
1523 u8 updated = 0;
1524
1525 spin_lock_bh(&pstapriv->asoc_list_lock);
1526 if (!list_empty(&psta->asoc_list)) {
1527 list_del_init(&psta->asoc_list);
1528 pstapriv->asoc_list_cnt--;
1529 updated = ap_free_sta(padapter, psta, false, reason);
1530 }
1531 spin_unlock_bh(&pstapriv->asoc_list_lock);
1532
1533 associated_clients_update(padapter, updated);
1534 }
1535
1536 return _SUCCESS;
1537 } else
1538 #endif
1539 {
1540 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1541 reason, GetAddr3Ptr(pframe));
1542
1543 receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
1544 }
1545 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1546 return _SUCCESS;
1547 }
1548
OnAtim(struct adapter * padapter,struct recv_frame * precv_frame)1549 unsigned int OnAtim(struct adapter *padapter, struct recv_frame *precv_frame)
1550 {
1551 DBG_88E("%s\n", __func__);
1552 return _SUCCESS;
1553 }
1554
on_action_spct(struct adapter * padapter,struct recv_frame * precv_frame)1555 unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame)
1556 {
1557 unsigned int ret = _FAIL;
1558 struct sta_info *psta = NULL;
1559 struct sta_priv *pstapriv = &padapter->stapriv;
1560 u8 *pframe = precv_frame->rx_data;
1561 u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1562 u8 category;
1563 u8 action;
1564
1565 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1566
1567 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1568
1569 if (!psta)
1570 goto exit;
1571
1572 category = frame_body[0];
1573 if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
1574 goto exit;
1575
1576 action = frame_body[1];
1577 switch (action) {
1578 case RTW_WLAN_ACTION_SPCT_MSR_REQ:
1579 case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
1580 case RTW_WLAN_ACTION_SPCT_TPC_REQ:
1581 case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
1582 break;
1583 case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
1584 break;
1585 default:
1586 break;
1587 }
1588
1589 exit:
1590 return ret;
1591 }
1592
OnAction_qos(struct adapter * padapter,struct recv_frame * precv_frame)1593 unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame)
1594 {
1595 return _SUCCESS;
1596 }
1597
OnAction_dls(struct adapter * padapter,struct recv_frame * precv_frame)1598 unsigned int OnAction_dls(struct adapter *padapter, struct recv_frame *precv_frame)
1599 {
1600 return _SUCCESS;
1601 }
1602
OnAction_back(struct adapter * padapter,struct recv_frame * precv_frame)1603 unsigned int OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
1604 {
1605 u8 *addr;
1606 struct sta_info *psta = NULL;
1607 struct recv_reorder_ctrl *preorder_ctrl;
1608 unsigned char *frame_body;
1609 unsigned char category, action;
1610 unsigned short tid, status, reason_code = 0;
1611 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1612 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1613 u8 *pframe = precv_frame->rx_data;
1614 struct sta_priv *pstapriv = &padapter->stapriv;
1615 /* check RA matches or not */
1616 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe),
1617 ETH_ALEN))/* for if1, sta/ap mode */
1618 return _SUCCESS;
1619
1620 DBG_88E("%s\n", __func__);
1621
1622 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1623 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
1624 return _SUCCESS;
1625
1626 addr = GetAddr2Ptr(pframe);
1627 psta = rtw_get_stainfo(pstapriv, addr);
1628
1629 if (psta == NULL)
1630 return _SUCCESS;
1631
1632 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1633
1634 category = frame_body[0];
1635 if (category == RTW_WLAN_CATEGORY_BACK) { /* representing Block Ack */
1636 if (!pmlmeinfo->HT_enable)
1637 return _SUCCESS;
1638 action = frame_body[1];
1639 DBG_88E("%s, action=%d\n", __func__, action);
1640 switch (action) {
1641 case RTW_WLAN_ACTION_ADDBA_REQ: /* ADDBA request */
1642 memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
1643 process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr);
1644
1645 if (pmlmeinfo->bAcceptAddbaReq)
1646 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 0);
1647 else
1648 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 37);/* reject ADDBA Req */
1649 break;
1650 case RTW_WLAN_ACTION_ADDBA_RESP: /* ADDBA response */
1651 status = get_unaligned_le16(&frame_body[3]);
1652 tid = ((frame_body[5] >> 2) & 0x7);
1653 if (status == 0) { /* successful */
1654 DBG_88E("agg_enable for TID=%d\n", tid);
1655 psta->htpriv.agg_enable_bitmap |= 1 << tid;
1656 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
1657 } else {
1658 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
1659 }
1660 break;
1661 case RTW_WLAN_ACTION_DELBA: /* DELBA */
1662 if ((frame_body[3] & BIT(3)) == 0) {
1663 psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1664 psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1665 reason_code = get_unaligned_le16(&frame_body[4]);
1666 } else if ((frame_body[3] & BIT(3)) == BIT(3)) {
1667 tid = (frame_body[3] >> 4) & 0x0F;
1668 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1669 preorder_ctrl->enable = false;
1670 preorder_ctrl->indicate_seq = 0xffff;
1671 }
1672 DBG_88E("%s(): DELBA: %x(%x)\n", __func__, pmlmeinfo->agg_enable_bitmap, reason_code);
1673 /* todo: how to notify the host while receiving DELETE BA */
1674 break;
1675 default:
1676 break;
1677 }
1678 }
1679 return _SUCCESS;
1680 }
1681
rtw_action_public_decache(struct recv_frame * recv_frame,s32 token)1682 static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
1683 {
1684 struct adapter *adapter = recv_frame->adapter;
1685 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
1686 u8 *frame = recv_frame->rx_data;
1687 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) |
1688 (recv_frame->attrib.frag_num & 0xf);
1689
1690 if (GetRetry(frame)) {
1691 if (token >= 0) {
1692 if ((seq_ctrl == mlmeext->action_public_rxseq) && (token == mlmeext->action_public_dialog_token)) {
1693 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x, token:%d\n",
1694 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
1695 return _FAIL;
1696 }
1697 } else {
1698 if (seq_ctrl == mlmeext->action_public_rxseq) {
1699 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x\n",
1700 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq);
1701 return _FAIL;
1702 }
1703 }
1704 }
1705
1706 mlmeext->action_public_rxseq = seq_ctrl;
1707
1708 if (token >= 0)
1709 mlmeext->action_public_dialog_token = token;
1710
1711 return _SUCCESS;
1712 }
1713
on_action_public_p2p(struct recv_frame * precv_frame)1714 static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
1715 {
1716 u8 *pframe = precv_frame->rx_data;
1717 u8 *frame_body;
1718 u8 dialogToken = 0;
1719 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1720
1721 dialogToken = frame_body[7];
1722
1723 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
1724 return _FAIL;
1725
1726 return _SUCCESS;
1727 }
1728
on_action_public_vendor(struct recv_frame * precv_frame)1729 static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
1730 {
1731 unsigned int ret = _FAIL;
1732 u8 *pframe = precv_frame->rx_data;
1733 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
1734
1735 if (!memcmp(frame_body + 2, P2P_OUI, 4))
1736 ret = on_action_public_p2p(precv_frame);
1737
1738 return ret;
1739 }
1740
on_action_public_default(struct recv_frame * precv_frame,u8 action)1741 static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action)
1742 {
1743 unsigned int ret = _FAIL;
1744 u8 *pframe = precv_frame->rx_data;
1745 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
1746 u8 token;
1747
1748 token = frame_body[2];
1749
1750 if (rtw_action_public_decache(precv_frame, token) == _FAIL)
1751 goto exit;
1752
1753 ret = _SUCCESS;
1754
1755 exit:
1756 return ret;
1757 }
1758
on_action_public(struct adapter * padapter,struct recv_frame * precv_frame)1759 unsigned int on_action_public(struct adapter *padapter, struct recv_frame *precv_frame)
1760 {
1761 unsigned int ret = _FAIL;
1762 u8 *pframe = precv_frame->rx_data;
1763 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
1764 u8 category, action;
1765
1766 /* check RA matches or not */
1767 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
1768 goto exit;
1769
1770 category = frame_body[0];
1771 if (category != RTW_WLAN_CATEGORY_PUBLIC)
1772 goto exit;
1773
1774 action = frame_body[1];
1775 switch (action) {
1776 case ACT_PUBLIC_VENDOR:
1777 ret = on_action_public_vendor(precv_frame);
1778 break;
1779 default:
1780 ret = on_action_public_default(precv_frame, action);
1781 break;
1782 }
1783
1784 exit:
1785 return ret;
1786 }
1787
OnAction_ht(struct adapter * padapter,struct recv_frame * precv_frame)1788 unsigned int OnAction_ht(struct adapter *padapter, struct recv_frame *precv_frame)
1789 {
1790 return _SUCCESS;
1791 }
1792
OnAction_wmm(struct adapter * padapter,struct recv_frame * precv_frame)1793 unsigned int OnAction_wmm(struct adapter *padapter, struct recv_frame *precv_frame)
1794 {
1795 return _SUCCESS;
1796 }
1797
OnAction_p2p(struct adapter * padapter,struct recv_frame * precv_frame)1798 unsigned int OnAction_p2p(struct adapter *padapter, struct recv_frame *precv_frame)
1799 {
1800 return _SUCCESS;
1801 }
1802
OnAction(struct adapter * padapter,struct recv_frame * precv_frame)1803 unsigned int OnAction(struct adapter *padapter, struct recv_frame *precv_frame)
1804 {
1805 int i;
1806 unsigned char category;
1807 struct action_handler *ptable;
1808 unsigned char *frame_body;
1809 u8 *pframe = precv_frame->rx_data;
1810
1811 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1812
1813 category = frame_body[0];
1814
1815 for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
1816 ptable = &OnAction_tbl[i];
1817 if (category == ptable->num)
1818 ptable->func(padapter, precv_frame);
1819 }
1820 return _SUCCESS;
1821 }
1822
DoReserved(struct adapter * padapter,struct recv_frame * precv_frame)1823 unsigned int DoReserved(struct adapter *padapter, struct recv_frame *precv_frame)
1824 {
1825 return _SUCCESS;
1826 }
1827
alloc_mgtxmitframe(struct xmit_priv * pxmitpriv)1828 struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
1829 {
1830 struct xmit_frame *pmgntframe;
1831 struct xmit_buf *pxmitbuf;
1832
1833 pmgntframe = rtw_alloc_xmitframe(pxmitpriv);
1834 if (pmgntframe == NULL) {
1835 DBG_88E("%s, alloc xmitframe fail\n", __func__);
1836 return NULL;
1837 }
1838
1839 pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv);
1840 if (pxmitbuf == NULL) {
1841 DBG_88E("%s, alloc xmitbuf fail\n", __func__);
1842 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1843 return NULL;
1844 }
1845 pmgntframe->frame_tag = MGNT_FRAMETAG;
1846 pmgntframe->pxmitbuf = pxmitbuf;
1847 pmgntframe->buf_addr = pxmitbuf->pbuf;
1848 pxmitbuf->priv_data = pmgntframe;
1849 return pmgntframe;
1850 }
1851
1852 /****************************************************************************
1853
1854 Following are some TX functions for WiFi MLME
1855
1856 *****************************************************************************/
1857
update_mgnt_tx_rate(struct adapter * padapter,u8 rate)1858 void update_mgnt_tx_rate(struct adapter *padapter, u8 rate)
1859 {
1860 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1861
1862 pmlmeext->tx_rate = rate;
1863 DBG_88E("%s(): rate = %x\n", __func__, rate);
1864 }
1865
update_mgntframe_attrib(struct adapter * padapter,struct pkt_attrib * pattrib)1866 void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib)
1867 {
1868 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1869
1870 memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib));
1871
1872 pattrib->hdrlen = 24;
1873 pattrib->nr_frags = 1;
1874 pattrib->priority = 7;
1875 pattrib->mac_id = 0;
1876 pattrib->qsel = 0x12;
1877
1878 pattrib->pktlen = 0;
1879
1880 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1881 pattrib->raid = 6;/* b mode */
1882 else
1883 pattrib->raid = 5;/* a/g mode */
1884
1885 pattrib->encrypt = _NO_PRIVACY_;
1886 pattrib->bswenc = false;
1887
1888 pattrib->qos_en = false;
1889 pattrib->ht_en = false;
1890 pattrib->bwmode = HT_CHANNEL_WIDTH_20;
1891 pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1892 pattrib->sgi = false;
1893
1894 pattrib->seqnum = pmlmeext->mgnt_seq;
1895
1896 pattrib->retry_ctrl = true;
1897 }
1898
dump_mgntframe(struct adapter * padapter,struct xmit_frame * pmgntframe)1899 void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe)
1900 {
1901 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
1902 return;
1903
1904 rtw_hal_mgnt_xmit(padapter, pmgntframe);
1905 }
1906
dump_mgntframe_and_wait(struct adapter * padapter,struct xmit_frame * pmgntframe,int timeout_ms)1907 s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
1908 {
1909 s32 ret = _FAIL;
1910 struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
1911 struct submit_ctx sctx;
1912
1913 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
1914 return ret;
1915
1916 rtw_sctx_init(&sctx, timeout_ms);
1917 pxmitbuf->sctx = &sctx;
1918
1919 ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
1920
1921 if (ret == _SUCCESS)
1922 ret = rtw_sctx_wait(&sctx);
1923
1924 return ret;
1925 }
1926
dump_mgntframe_and_wait_ack(struct adapter * padapter,struct xmit_frame * pmgntframe)1927 s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe)
1928 {
1929 s32 ret = _FAIL;
1930 u32 timeout_ms = 500;/* 500ms */
1931 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1932
1933 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
1934 return -1;
1935
1936 _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
1937 pxmitpriv->ack_tx = true;
1938
1939 pmgntframe->ack_report = 1;
1940 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
1941 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
1942 }
1943
1944 pxmitpriv->ack_tx = false;
1945 mutex_unlock(&pxmitpriv->ack_tx_mutex);
1946
1947 return ret;
1948 }
1949
update_hidden_ssid(u8 * ies,u32 ies_len,u8 hidden_ssid_mode)1950 static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
1951 {
1952 u8 *ssid_ie;
1953 int ssid_len_ori;
1954 int len_diff = 0;
1955
1956 ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
1957
1958 if (ssid_ie && ssid_len_ori > 0) {
1959 switch (hidden_ssid_mode) {
1960 case 1: {
1961 u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
1962 u32 remain_len = 0;
1963
1964 remain_len = ies_len - (next_ie - ies);
1965
1966 ssid_ie[1] = 0;
1967 memcpy(ssid_ie+2, next_ie, remain_len);
1968 len_diff -= ssid_len_ori;
1969
1970 break;
1971 }
1972 case 2:
1973 memset(&ssid_ie[2], 0, ssid_len_ori);
1974 break;
1975 default:
1976 break;
1977 }
1978 }
1979
1980 return len_diff;
1981 }
1982
issue_beacon(struct adapter * padapter,int timeout_ms)1983 void issue_beacon(struct adapter *padapter, int timeout_ms)
1984 {
1985 struct xmit_frame *pmgntframe;
1986 struct pkt_attrib *pattrib;
1987 unsigned char *pframe;
1988 struct rtw_ieee80211_hdr *pwlanhdr;
1989 __le16 *fctrl;
1990 unsigned int rate_len;
1991 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1992 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1993 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1994 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1995 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
1996 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1997
1998 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1999 if (pmgntframe == NULL) {
2000 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
2001 return;
2002 }
2003 #if defined (CONFIG_88EU_AP_MODE)
2004 spin_lock_bh(&pmlmepriv->bcn_update_lock);
2005 #endif /* if defined (CONFIG_88EU_AP_MODE) */
2006
2007 /* update attribute */
2008 pattrib = &pmgntframe->attrib;
2009 update_mgntframe_attrib(padapter, pattrib);
2010 pattrib->qsel = 0x10;
2011
2012 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2013
2014 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2015 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2016
2017
2018 fctrl = &(pwlanhdr->frame_ctl);
2019 *(fctrl) = 0;
2020
2021 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
2022 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2023 memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
2024
2025 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
2026 /* pmlmeext->mgnt_seq++; */
2027 SetFrameSubType(pframe, WIFI_BEACON);
2028
2029 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2030 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
2031
2032 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
2033 int len_diff;
2034 u8 *wps_ie;
2035 uint wps_ielen;
2036 u8 sr = 0;
2037 memcpy(pframe, cur_network->IEs, cur_network->IELength);
2038 len_diff = update_hidden_ssid(
2039 pframe+_BEACON_IE_OFFSET_
2040 , cur_network->IELength-_BEACON_IE_OFFSET_
2041 , pmlmeinfo->hidden_ssid_mode
2042 );
2043 pframe += (cur_network->IELength+len_diff);
2044 pattrib->pktlen += (cur_network->IELength+len_diff);
2045 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
2046 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
2047 if (wps_ie && wps_ielen > 0)
2048 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
2049 if (sr != 0)
2050 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
2051 else
2052 _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
2053
2054 goto _issue_bcn;
2055 }
2056
2057 /* below for ad-hoc mode */
2058
2059 /* timestamp will be inserted by hardware */
2060 pframe += 8;
2061 pattrib->pktlen += 8;
2062
2063 /* beacon interval: 2 bytes */
2064
2065 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
2066
2067 pframe += 2;
2068 pattrib->pktlen += 2;
2069
2070 /* capability info: 2 bytes */
2071
2072 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
2073
2074 pframe += 2;
2075 pattrib->pktlen += 2;
2076
2077 /* SSID */
2078 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
2079
2080 /* supported rates... */
2081 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
2082 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
2083
2084 /* DS parameter set */
2085 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
2086
2087 {
2088 u8 erpinfo = 0;
2089 u32 ATIMWindow;
2090 /* IBSS Parameter Set... */
2091 ATIMWindow = 0;
2092 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
2093
2094 /* ERP IE */
2095 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
2096 }
2097
2098 /* EXTERNDED SUPPORTED RATE */
2099 if (rate_len > 8)
2100 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
2101 /* todo:HT for adhoc */
2102 _issue_bcn:
2103
2104 #if defined (CONFIG_88EU_AP_MODE)
2105 pmlmepriv->update_bcn = false;
2106
2107 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
2108 #endif /* if defined (CONFIG_88EU_AP_MODE) */
2109
2110 if ((pattrib->pktlen + TXDESC_SIZE) > 512) {
2111 DBG_88E("beacon frame too large\n");
2112 return;
2113 }
2114
2115 pattrib->last_txcmdsz = pattrib->pktlen;
2116
2117 /* DBG_88E("issue bcn_sz=%d\n", pattrib->last_txcmdsz); */
2118 if (timeout_ms > 0)
2119 dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
2120 else
2121 dump_mgntframe(padapter, pmgntframe);
2122 }
2123
issue_probersp(struct adapter * padapter,unsigned char * da,u8 is_valid_p2p_probereq)2124 void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
2125 {
2126 struct xmit_frame *pmgntframe;
2127 struct pkt_attrib *pattrib;
2128 unsigned char *pframe;
2129 struct rtw_ieee80211_hdr *pwlanhdr;
2130 __le16 *fctrl;
2131 unsigned char *mac, *bssid;
2132 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2133 #if defined (CONFIG_88EU_AP_MODE)
2134 u8 *pwps_ie;
2135 uint wps_ielen;
2136 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2137 #endif /* if defined (CONFIG_88EU_AP_MODE) */
2138 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2139 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2140 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
2141 unsigned int rate_len;
2142
2143 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2144 if (pmgntframe == NULL) {
2145 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
2146 return;
2147 }
2148
2149 /* update attribute */
2150 pattrib = &pmgntframe->attrib;
2151 update_mgntframe_attrib(padapter, pattrib);
2152
2153 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2154
2155 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2156 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2157
2158 mac = myid(&(padapter->eeprompriv));
2159 bssid = cur_network->MacAddress;
2160
2161 fctrl = &(pwlanhdr->frame_ctl);
2162 *(fctrl) = 0;
2163 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
2164 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
2165 memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
2166
2167 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2168 pmlmeext->mgnt_seq++;
2169 SetFrameSubType(fctrl, WIFI_PROBERSP);
2170
2171 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2172 pattrib->pktlen = pattrib->hdrlen;
2173 pframe += pattrib->hdrlen;
2174
2175 if (cur_network->IELength > MAX_IE_SZ)
2176 return;
2177
2178 #if defined(CONFIG_88EU_AP_MODE)
2179 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
2180 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
2181
2182 /* inerset & update wps_probe_resp_ie */
2183 if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
2184 uint wps_offset, remainder_ielen;
2185 u8 *premainder_ie;
2186
2187 wps_offset = (uint)(pwps_ie - cur_network->IEs);
2188
2189 premainder_ie = pwps_ie + wps_ielen;
2190
2191 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
2192
2193 memcpy(pframe, cur_network->IEs, wps_offset);
2194 pframe += wps_offset;
2195 pattrib->pktlen += wps_offset;
2196
2197 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
2198 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
2199 memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
2200 pframe += wps_ielen+2;
2201 pattrib->pktlen += wps_ielen+2;
2202 }
2203
2204 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
2205 memcpy(pframe, premainder_ie, remainder_ielen);
2206 pframe += remainder_ielen;
2207 pattrib->pktlen += remainder_ielen;
2208 }
2209 } else {
2210 memcpy(pframe, cur_network->IEs, cur_network->IELength);
2211 pframe += cur_network->IELength;
2212 pattrib->pktlen += cur_network->IELength;
2213 }
2214 } else
2215 #endif
2216 {
2217 /* timestamp will be inserted by hardware */
2218 pframe += 8;
2219 pattrib->pktlen += 8;
2220
2221 /* beacon interval: 2 bytes */
2222
2223 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
2224
2225 pframe += 2;
2226 pattrib->pktlen += 2;
2227
2228 /* capability info: 2 bytes */
2229
2230 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
2231
2232 pframe += 2;
2233 pattrib->pktlen += 2;
2234
2235 /* below for ad-hoc mode */
2236
2237 /* SSID */
2238 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
2239
2240 /* supported rates... */
2241 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
2242 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
2243
2244 /* DS parameter set */
2245 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
2246
2247 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
2248 u8 erpinfo = 0;
2249 u32 ATIMWindow;
2250 /* IBSS Parameter Set... */
2251 /* ATIMWindow = cur->Configuration.ATIMWindow; */
2252 ATIMWindow = 0;
2253 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
2254
2255 /* ERP IE */
2256 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
2257 }
2258
2259
2260 /* EXTERNDED SUPPORTED RATE */
2261 if (rate_len > 8)
2262 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
2263 /* todo:HT for adhoc */
2264 }
2265
2266 pattrib->last_txcmdsz = pattrib->pktlen;
2267
2268 dump_mgntframe(padapter, pmgntframe);
2269
2270 return;
2271 }
2272
_issue_probereq(struct adapter * padapter,struct ndis_802_11_ssid * pssid,u8 * da,int wait_ack)2273 static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int wait_ack)
2274 {
2275 int ret = _FAIL;
2276 struct xmit_frame *pmgntframe;
2277 struct pkt_attrib *pattrib;
2278 unsigned char *pframe;
2279 struct rtw_ieee80211_hdr *pwlanhdr;
2280 __le16 *fctrl;
2281 unsigned char *mac;
2282 unsigned char bssrate[NumRates];
2283 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2284 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2285 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2286 int bssrate_len = 0;
2287 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2288
2289 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+issue_probereq\n"));
2290
2291 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2292 if (pmgntframe == NULL)
2293 goto exit;
2294
2295 /* update attribute */
2296 pattrib = &pmgntframe->attrib;
2297 update_mgntframe_attrib(padapter, pattrib);
2298
2299
2300 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2301
2302 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2303 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2304
2305 mac = myid(&(padapter->eeprompriv));
2306
2307 fctrl = &(pwlanhdr->frame_ctl);
2308 *(fctrl) = 0;
2309
2310 if (da) {
2311 /* unicast probe request frame */
2312 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
2313 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
2314 } else {
2315 /* broadcast probe request frame */
2316 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
2317 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
2318 }
2319
2320 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
2321
2322 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2323 pmlmeext->mgnt_seq++;
2324 SetFrameSubType(pframe, WIFI_PROBEREQ);
2325
2326 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
2327 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
2328
2329 if (pssid)
2330 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
2331 else
2332 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
2333
2334 get_rate_set(padapter, bssrate, &bssrate_len);
2335
2336 if (bssrate_len > 8) {
2337 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
2338 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
2339 } else {
2340 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
2341 }
2342
2343 /* add wps_ie for wps2.0 */
2344 if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) {
2345 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
2346 pframe += pmlmepriv->wps_probe_req_ie_len;
2347 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
2348 }
2349
2350 pattrib->last_txcmdsz = pattrib->pktlen;
2351
2352 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
2353 ("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
2354
2355 if (wait_ack) {
2356 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
2357 } else {
2358 dump_mgntframe(padapter, pmgntframe);
2359 ret = _SUCCESS;
2360 }
2361
2362 exit:
2363 return ret;
2364 }
2365
issue_probereq(struct adapter * padapter,struct ndis_802_11_ssid * pssid,u8 * da)2366 inline void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da)
2367 {
2368 _issue_probereq(padapter, pssid, da, false);
2369 }
2370
issue_probereq_ex(struct adapter * padapter,struct ndis_802_11_ssid * pssid,u8 * da,int try_cnt,int wait_ms)2371 int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da,
2372 int try_cnt, int wait_ms)
2373 {
2374 int ret;
2375 int i = 0;
2376 u32 start = jiffies;
2377
2378 do {
2379 ret = _issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false);
2380
2381 i++;
2382
2383 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
2384 break;
2385
2386 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
2387 msleep(wait_ms);
2388
2389 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
2390
2391 if (ret != _FAIL) {
2392 ret = _SUCCESS;
2393 goto exit;
2394 }
2395
2396 if (try_cnt && wait_ms) {
2397 if (da)
2398 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
2399 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
2400 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
2401 else
2402 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
2403 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
2404 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
2405 }
2406 exit:
2407 return ret;
2408 }
2409
2410 /* if psta == NULL, indicate we are station(client) now... */
issue_auth(struct adapter * padapter,struct sta_info * psta,unsigned short status)2411 void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status)
2412 {
2413 struct xmit_frame *pmgntframe;
2414 struct pkt_attrib *pattrib;
2415 unsigned char *pframe;
2416 struct rtw_ieee80211_hdr *pwlanhdr;
2417 __le16 *fctrl;
2418 unsigned int val32;
2419 u16 val16;
2420 #ifdef CONFIG_88EU_AP_MODE
2421 __le16 le_val16;
2422 #endif
2423 int use_shared_key = 0;
2424 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2425 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2426 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2427
2428 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2429 if (pmgntframe == NULL)
2430 return;
2431
2432 /* update attribute */
2433 pattrib = &pmgntframe->attrib;
2434 update_mgntframe_attrib(padapter, pattrib);
2435
2436 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2437
2438 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2439 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2440
2441 fctrl = &(pwlanhdr->frame_ctl);
2442 *(fctrl) = 0;
2443
2444 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2445 pmlmeext->mgnt_seq++;
2446 SetFrameSubType(pframe, WIFI_AUTH);
2447
2448 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2449 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2450
2451
2452 if (psta) {/* for AP mode */
2453 #ifdef CONFIG_88EU_AP_MODE
2454
2455 memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
2456 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2457 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2458
2459
2460 /* setting auth algo number */
2461 val16 = (u16)psta->authalg;
2462
2463 if (status != _STATS_SUCCESSFUL_)
2464 val16 = 0;
2465
2466 if (val16) {
2467 le_val16 = cpu_to_le16(val16);
2468 use_shared_key = 1;
2469 } else {
2470 le_val16 = 0;
2471 }
2472
2473 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
2474
2475 /* setting auth seq number */
2476 val16 = (u16)psta->auth_seq;
2477 le_val16 = cpu_to_le16(val16);
2478 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
2479
2480 /* setting status code... */
2481 val16 = status;
2482 le_val16 = cpu_to_le16(val16);
2483 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_val16, &(pattrib->pktlen));
2484
2485 /* added challenging text... */
2486 if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
2487 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
2488 #endif
2489 } else {
2490 __le32 le_tmp32;
2491 __le16 le_tmp16;
2492 memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
2493 memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
2494 memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
2495
2496 /* setting auth algo number */
2497 val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) ? 1 : 0;/* 0:OPEN System, 1:Shared key */
2498 if (val16)
2499 use_shared_key = 1;
2500
2501 /* setting IV for auth seq #3 */
2502 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
2503 val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
2504 le_tmp32 = cpu_to_le32(val32);
2505 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen));
2506
2507 pattrib->iv_len = 4;
2508 }
2509
2510 le_tmp16 = cpu_to_le16(val16);
2511 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
2512
2513 /* setting auth seq number */
2514 val16 = pmlmeinfo->auth_seq;
2515 le_tmp16 = cpu_to_le16(val16);
2516 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
2517
2518
2519 /* setting status code... */
2520 le_tmp16 = cpu_to_le16(status);
2521 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
2522
2523 /* then checking to see if sending challenging text... */
2524 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
2525 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
2526
2527 SetPrivacy(fctrl);
2528
2529 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2530
2531 pattrib->encrypt = _WEP40_;
2532
2533 pattrib->icv_len = 4;
2534
2535 pattrib->pktlen += pattrib->icv_len;
2536 }
2537 }
2538
2539 pattrib->last_txcmdsz = pattrib->pktlen;
2540
2541 rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
2542 DBG_88E("%s\n", __func__);
2543 dump_mgntframe(padapter, pmgntframe);
2544
2545 return;
2546 }
2547
2548
issue_asocrsp(struct adapter * padapter,unsigned short status,struct sta_info * pstat,int pkt_type)2549 void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
2550 {
2551 #ifdef CONFIG_88EU_AP_MODE
2552 struct xmit_frame *pmgntframe;
2553 struct rtw_ieee80211_hdr *pwlanhdr;
2554 struct pkt_attrib *pattrib;
2555 unsigned char *pbuf, *pframe;
2556 unsigned short val;
2557 __le16 *fctrl;
2558 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2559 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2560 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2561 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2562 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
2563 u8 *ie = pnetwork->IEs;
2564 __le16 lestatus, leval;
2565
2566 DBG_88E("%s\n", __func__);
2567
2568 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2569 if (pmgntframe == NULL)
2570 return;
2571
2572 /* update attribute */
2573 pattrib = &pmgntframe->attrib;
2574 update_mgntframe_attrib(padapter, pattrib);
2575
2576
2577 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2578
2579 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2580 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2581
2582 fctrl = &(pwlanhdr->frame_ctl);
2583 *(fctrl) = 0;
2584
2585 memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
2586 memcpy((void *)GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN);
2587 memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
2588
2589
2590 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2591 pmlmeext->mgnt_seq++;
2592 if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
2593 SetFrameSubType(pwlanhdr, pkt_type);
2594 else
2595 return;
2596
2597 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2598 pattrib->pktlen += pattrib->hdrlen;
2599 pframe += pattrib->hdrlen;
2600
2601 /* capability */
2602 val = *(unsigned short *)rtw_get_capability_from_ie(ie);
2603
2604 pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
2605
2606 lestatus = cpu_to_le16(status);
2607 pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&lestatus, &(pattrib->pktlen));
2608
2609 leval = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
2610 pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&leval, &(pattrib->pktlen));
2611
2612 if (pstat->bssratelen <= 8) {
2613 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
2614 } else {
2615 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
2616 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen-8), pstat->bssrateset+8, &(pattrib->pktlen));
2617 }
2618
2619 if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) {
2620 uint ie_len = 0;
2621
2622 /* FILL HT CAP INFO IE */
2623 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2624 if (pbuf && ie_len > 0) {
2625 memcpy(pframe, pbuf, ie_len+2);
2626 pframe += (ie_len+2);
2627 pattrib->pktlen += (ie_len+2);
2628 }
2629
2630 /* FILL HT ADD INFO IE */
2631 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
2632 if (pbuf && ie_len > 0) {
2633 memcpy(pframe, pbuf, ie_len+2);
2634 pframe += (ie_len+2);
2635 pattrib->pktlen += (ie_len+2);
2636 }
2637 }
2638
2639 /* FILL WMM IE */
2640 if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) {
2641 uint ie_len = 0;
2642 unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
2643
2644 for (pbuf = ie + _BEACON_IE_OFFSET_;; pbuf += (ie_len + 2)) {
2645 pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
2646 if (pbuf && !memcmp(pbuf+2, WMM_PARA_IE, 6)) {
2647 memcpy(pframe, pbuf, ie_len+2);
2648 pframe += (ie_len+2);
2649 pattrib->pktlen += (ie_len+2);
2650 break;
2651 }
2652
2653 if ((pbuf == NULL) || (ie_len == 0))
2654 break;
2655 }
2656 }
2657
2658 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
2659 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
2660
2661 /* add WPS IE ie for wps 2.0 */
2662 if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) {
2663 memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
2664
2665 pframe += pmlmepriv->wps_assoc_resp_ie_len;
2666 pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
2667 }
2668
2669 pattrib->last_txcmdsz = pattrib->pktlen;
2670 dump_mgntframe(padapter, pmgntframe);
2671 #endif
2672 }
2673
issue_assocreq(struct adapter * padapter)2674 void issue_assocreq(struct adapter *padapter)
2675 {
2676 int ret = _FAIL;
2677 struct xmit_frame *pmgntframe;
2678 struct pkt_attrib *pattrib;
2679 unsigned char *pframe, *p;
2680 struct rtw_ieee80211_hdr *pwlanhdr;
2681 __le16 *fctrl;
2682 __le16 le_tmp;
2683 unsigned int i, j, ie_len, index = 0;
2684 unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
2685 struct ndis_802_11_var_ie *pIE;
2686 struct registry_priv *pregpriv = &padapter->registrypriv;
2687 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2688 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
2689 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2690 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2691 int bssrate_len = 0, sta_bssrate_len = 0;
2692
2693 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2694 if (pmgntframe == NULL)
2695 goto exit;
2696
2697 /* update attribute */
2698 pattrib = &pmgntframe->attrib;
2699 update_mgntframe_attrib(padapter, pattrib);
2700
2701 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2702 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2703 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2704
2705 fctrl = &(pwlanhdr->frame_ctl);
2706 *(fctrl) = 0;
2707 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
2708 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2709 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
2710
2711 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2712 pmlmeext->mgnt_seq++;
2713 SetFrameSubType(pframe, WIFI_ASSOCREQ);
2714
2715 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2716 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2717
2718 /* caps */
2719
2720 memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
2721
2722 pframe += 2;
2723 pattrib->pktlen += 2;
2724
2725 /* listen interval */
2726 /* todo: listen interval for power saving */
2727 le_tmp = cpu_to_le16(3);
2728 memcpy(pframe , (unsigned char *)&le_tmp, 2);
2729 pframe += 2;
2730 pattrib->pktlen += 2;
2731
2732 /* SSID */
2733 pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
2734
2735 /* supported rate & extended supported rate */
2736
2737 /* Check if the AP's supported rates are also supported by STA. */
2738 get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
2739
2740 if (pmlmeext->cur_channel == 14)/* for JAPAN, channel 14 can only uses B Mode(CCK) */
2741 sta_bssrate_len = 4;
2742
2743 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
2744 if (pmlmeinfo->network.SupportedRates[i] == 0)
2745 break;
2746 DBG_88E("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
2747 }
2748
2749 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
2750 if (pmlmeinfo->network.SupportedRates[i] == 0)
2751 break;
2752
2753 /* Check if the AP's supported rates are also supported by STA. */
2754 for (j = 0; j < sta_bssrate_len; j++) {
2755 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
2756 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
2757 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK))
2758 break;
2759 }
2760
2761 if (j == sta_bssrate_len) {
2762 /* the rate is not supported by STA */
2763 DBG_88E("%s(): the rate[%d]=%02X is not supported by STA!\n", __func__, i, pmlmeinfo->network.SupportedRates[i]);
2764 } else {
2765 /* the rate is supported by STA */
2766 bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
2767 }
2768 }
2769
2770 bssrate_len = index;
2771 DBG_88E("bssrate_len=%d\n", bssrate_len);
2772
2773 if (bssrate_len == 0) {
2774 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
2775 rtw_free_xmitframe(pxmitpriv, pmgntframe);
2776 goto exit; /* don't connect to AP if no joint supported rate */
2777 }
2778
2779
2780 if (bssrate_len > 8) {
2781 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
2782 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
2783 } else {
2784 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
2785 }
2786
2787 /* RSN */
2788 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _RSN_IE_2_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
2789 if (p != NULL)
2790 pframe = rtw_set_ie(pframe, _RSN_IE_2_, ie_len, (p + 2), &(pattrib->pktlen));
2791
2792 /* HT caps */
2793 if (padapter->mlmepriv.htpriv.ht_option) {
2794 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _HT_CAPABILITY_IE_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
2795 if ((p != NULL) && (!(is_ap_in_tkip(padapter)))) {
2796 memcpy(&(pmlmeinfo->HT_caps), (p + 2), sizeof(struct HT_caps_element));
2797
2798 /* to disable 40M Hz support while gd_bw_40MHz_en = 0 */
2799 if (pregpriv->cbw40_enable == 0)
2800 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info &= cpu_to_le16(~(BIT(6) | BIT(1)));
2801 else
2802 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(BIT(1));
2803
2804 /* todo: disable SM power save mode */
2805 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x000c);
2806
2807 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
2808 switch (rf_type) {
2809 case RF_1T1R:
2810 if (pregpriv->rx_stbc)
2811 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0100);/* RX STBC One spatial stream */
2812 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_1R, 16);
2813 break;
2814 case RF_2T2R:
2815 case RF_1T2R:
2816 default:
2817 if ((pregpriv->rx_stbc == 0x3) ||/* enable for 2.4/5 GHz */
2818 ((pmlmeext->cur_wireless_mode & WIRELESS_11_24N) && (pregpriv->rx_stbc == 0x1)) || /* enable for 2.4GHz */
2819 (pregpriv->wifi_spec == 1)) {
2820 DBG_88E("declare supporting RX STBC\n");
2821 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0200);/* RX STBC two spatial stream */
2822 }
2823 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_2R, 16);
2824 break;
2825 }
2826 pframe = rtw_set_ie(pframe, _HT_CAPABILITY_IE_, ie_len , (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
2827 }
2828 }
2829
2830 /* vendor specific IE, such as WPA, WMM, WPS */
2831 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
2832 pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
2833
2834 switch (pIE->ElementID) {
2835 case _VENDOR_SPECIFIC_IE_:
2836 if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
2837 (!memcmp(pIE->data, WMM_OUI, 4)) ||
2838 (!memcmp(pIE->data, WPS_OUI, 4))) {
2839 if (!padapter->registrypriv.wifi_spec) {
2840 /* Commented by Kurt 20110629 */
2841 /* In some older APs, WPS handshake */
2842 /* would be fail if we append vender extensions informations to AP */
2843 if (!memcmp(pIE->data, WPS_OUI, 4))
2844 pIE->Length = 14;
2845 }
2846 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, pIE->Length, pIE->data, &(pattrib->pktlen));
2847 }
2848 break;
2849 default:
2850 break;
2851 }
2852 i += (pIE->Length + 2);
2853 }
2854
2855 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
2856 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
2857
2858 pattrib->last_txcmdsz = pattrib->pktlen;
2859 dump_mgntframe(padapter, pmgntframe);
2860
2861 ret = _SUCCESS;
2862
2863 exit:
2864 if (ret == _SUCCESS)
2865 rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
2866 else
2867 rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
2868
2869 return;
2870 }
2871
2872 /* when wait_ack is true, this function should be called at process context */
_issue_nulldata(struct adapter * padapter,unsigned char * da,unsigned int power_mode,int wait_ack)2873 static int _issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
2874 {
2875 int ret = _FAIL;
2876 struct xmit_frame *pmgntframe;
2877 struct pkt_attrib *pattrib;
2878 unsigned char *pframe;
2879 struct rtw_ieee80211_hdr *pwlanhdr;
2880 __le16 *fctrl;
2881 struct xmit_priv *pxmitpriv;
2882 struct mlme_ext_priv *pmlmeext;
2883 struct mlme_ext_info *pmlmeinfo;
2884
2885 if (!padapter)
2886 goto exit;
2887
2888 pxmitpriv = &(padapter->xmitpriv);
2889 pmlmeext = &(padapter->mlmeextpriv);
2890 pmlmeinfo = &(pmlmeext->mlmext_info);
2891
2892 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2893 if (pmgntframe == NULL)
2894 goto exit;
2895
2896 /* update attribute */
2897 pattrib = &pmgntframe->attrib;
2898 update_mgntframe_attrib(padapter, pattrib);
2899 pattrib->retry_ctrl = false;
2900
2901 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2902
2903 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2904 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2905
2906 fctrl = &(pwlanhdr->frame_ctl);
2907 *(fctrl) = 0;
2908
2909 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
2910 SetFrDs(fctrl);
2911 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
2912 SetToDs(fctrl);
2913
2914 if (power_mode)
2915 SetPwrMgt(fctrl);
2916
2917 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
2918 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2919 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
2920
2921 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2922 pmlmeext->mgnt_seq++;
2923 SetFrameSubType(pframe, WIFI_DATA_NULL);
2924
2925 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2926 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2927
2928 pattrib->last_txcmdsz = pattrib->pktlen;
2929
2930 if (wait_ack) {
2931 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
2932 } else {
2933 dump_mgntframe(padapter, pmgntframe);
2934 ret = _SUCCESS;
2935 }
2936
2937 exit:
2938 return ret;
2939 }
2940
2941
2942 /* when wait_ms > 0 , this function should be called at process context */
2943 /* da == NULL for station mode */
issue_nulldata(struct adapter * padapter,unsigned char * da,unsigned int power_mode,int try_cnt,int wait_ms)2944 int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
2945 {
2946 int ret;
2947 int i = 0;
2948 u32 start = jiffies;
2949 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2950 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2951
2952 /* da == NULL, assume it's null data for sta to ap*/
2953 if (da == NULL)
2954 da = get_my_bssid(&(pmlmeinfo->network));
2955
2956 do {
2957 ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0 ? true : false);
2958
2959 i++;
2960
2961 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
2962 break;
2963
2964 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
2965 msleep(wait_ms);
2966 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
2967
2968 if (ret != _FAIL) {
2969 ret = _SUCCESS;
2970 goto exit;
2971 }
2972
2973 if (try_cnt && wait_ms) {
2974 if (da)
2975 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
2976 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
2977 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
2978 else
2979 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
2980 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
2981 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
2982 }
2983 exit:
2984 return ret;
2985 }
2986
2987 /* when wait_ack is true, this function should be called at process context */
_issue_qos_nulldata(struct adapter * padapter,unsigned char * da,u16 tid,int wait_ack)2988 static int _issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
2989 {
2990 int ret = _FAIL;
2991 struct xmit_frame *pmgntframe;
2992 struct pkt_attrib *pattrib;
2993 unsigned char *pframe;
2994 struct rtw_ieee80211_hdr *pwlanhdr;
2995 __le16 *fctrl;
2996 unsigned short *qc;
2997 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2998 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2999 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3000
3001 DBG_88E("%s\n", __func__);
3002
3003 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3004 if (pmgntframe == NULL)
3005 goto exit;
3006
3007 /* update attribute */
3008 pattrib = &pmgntframe->attrib;
3009 update_mgntframe_attrib(padapter, pattrib);
3010
3011 pattrib->hdrlen += 2;
3012 pattrib->qos_en = true;
3013 pattrib->eosp = 1;
3014 pattrib->ack_policy = 0;
3015 pattrib->mdata = 0;
3016
3017 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3018
3019 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3020 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3021
3022 fctrl = &(pwlanhdr->frame_ctl);
3023 *(fctrl) = 0;
3024
3025 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
3026 SetFrDs(fctrl);
3027 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
3028 SetToDs(fctrl);
3029
3030 if (pattrib->mdata)
3031 SetMData(fctrl);
3032
3033 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
3034
3035 SetPriority(qc, tid);
3036
3037 SetEOSP(qc, pattrib->eosp);
3038
3039 SetAckpolicy(qc, pattrib->ack_policy);
3040
3041 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3042 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3043 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
3044
3045 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3046 pmlmeext->mgnt_seq++;
3047 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
3048
3049 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
3050 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
3051
3052 pattrib->last_txcmdsz = pattrib->pktlen;
3053
3054 if (wait_ack) {
3055 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
3056 } else {
3057 dump_mgntframe(padapter, pmgntframe);
3058 ret = _SUCCESS;
3059 }
3060
3061 exit:
3062 return ret;
3063 }
3064
3065 /* when wait_ms > 0 , this function should be called at process context */
3066 /* da == NULL for station mode */
issue_qos_nulldata(struct adapter * padapter,unsigned char * da,u16 tid,int try_cnt,int wait_ms)3067 int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
3068 {
3069 int ret;
3070 int i = 0;
3071 u32 start = jiffies;
3072 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3073 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3074
3075 /* da == NULL, assume it's null data for sta to ap*/
3076 if (da == NULL)
3077 da = get_my_bssid(&(pmlmeinfo->network));
3078
3079 do {
3080 ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0 ? true : false);
3081
3082 i++;
3083
3084 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
3085 break;
3086
3087 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3088 msleep(wait_ms);
3089 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3090
3091 if (ret != _FAIL) {
3092 ret = _SUCCESS;
3093 goto exit;
3094 }
3095
3096 if (try_cnt && wait_ms) {
3097 if (da)
3098 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
3099 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
3100 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3101 else
3102 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
3103 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
3104 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3105 }
3106 exit:
3107 return ret;
3108 }
3109
_issue_deauth(struct adapter * padapter,unsigned char * da,unsigned short reason,u8 wait_ack)3110 static int _issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack)
3111 {
3112 struct xmit_frame *pmgntframe;
3113 struct pkt_attrib *pattrib;
3114 unsigned char *pframe;
3115 struct rtw_ieee80211_hdr *pwlanhdr;
3116 __le16 *fctrl;
3117 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3118 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3119 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3120 int ret = _FAIL;
3121 __le16 le_tmp;
3122
3123 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3124 if (pmgntframe == NULL)
3125 goto exit;
3126
3127 /* update attribute */
3128 pattrib = &pmgntframe->attrib;
3129 update_mgntframe_attrib(padapter, pattrib);
3130 pattrib->retry_ctrl = false;
3131
3132 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3133
3134 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3135 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3136
3137 fctrl = &(pwlanhdr->frame_ctl);
3138 *(fctrl) = 0;
3139
3140 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3141 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3142 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
3143
3144 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3145 pmlmeext->mgnt_seq++;
3146 SetFrameSubType(pframe, WIFI_DEAUTH);
3147
3148 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3149 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3150
3151 le_tmp = cpu_to_le16(reason);
3152 pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&le_tmp, &(pattrib->pktlen));
3153
3154 pattrib->last_txcmdsz = pattrib->pktlen;
3155
3156
3157 if (wait_ack) {
3158 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
3159 } else {
3160 dump_mgntframe(padapter, pmgntframe);
3161 ret = _SUCCESS;
3162 }
3163
3164 exit:
3165 return ret;
3166 }
3167
issue_deauth(struct adapter * padapter,unsigned char * da,unsigned short reason)3168 int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason)
3169 {
3170 DBG_88E("%s to %pM\n", __func__, da);
3171 return _issue_deauth(padapter, da, reason, false);
3172 }
3173
issue_deauth_ex(struct adapter * padapter,u8 * da,unsigned short reason,int try_cnt,int wait_ms)3174 int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
3175 int wait_ms)
3176 {
3177 int ret;
3178 int i = 0;
3179 u32 start = jiffies;
3180
3181 do {
3182 ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? true : false);
3183
3184 i++;
3185
3186 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
3187 break;
3188
3189 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3190 msleep(wait_ms);
3191 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3192
3193 if (ret != _FAIL) {
3194 ret = _SUCCESS;
3195 goto exit;
3196 }
3197
3198 if (try_cnt && wait_ms) {
3199 if (da)
3200 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
3201 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
3202 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3203 else
3204 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
3205 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
3206 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3207 }
3208 exit:
3209 return ret;
3210 }
3211
issue_action_spct_ch_switch(struct adapter * padapter,u8 * ra,u8 new_ch,u8 ch_offset)3212 void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
3213 {
3214 struct xmit_frame *pmgntframe;
3215 struct pkt_attrib *pattrib;
3216 unsigned char *pframe;
3217 struct rtw_ieee80211_hdr *pwlanhdr;
3218 __le16 *fctrl;
3219 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3220 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3221
3222
3223 DBG_88E(FUNC_NDEV_FMT" ra =%pM, ch:%u, offset:%u\n",
3224 FUNC_NDEV_ARG(padapter->pnetdev), ra, new_ch, ch_offset);
3225
3226 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3227 if (pmgntframe == NULL)
3228 return;
3229
3230 /* update attribute */
3231 pattrib = &pmgntframe->attrib;
3232 update_mgntframe_attrib(padapter, pattrib);
3233
3234 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3235
3236 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3237 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3238
3239 fctrl = &(pwlanhdr->frame_ctl);
3240 *(fctrl) = 0;
3241
3242 memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
3243 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); /* TA */
3244 memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
3245
3246 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3247 pmlmeext->mgnt_seq++;
3248 SetFrameSubType(pframe, WIFI_ACTION);
3249
3250 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3251 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3252
3253 /* category, action */
3254 {
3255 u8 category, action;
3256 category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
3257 action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
3258
3259 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3260 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3261 }
3262
3263 pframe = rtw_set_ie_ch_switch (pframe, &(pattrib->pktlen), 0, new_ch, 0);
3264 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
3265 hal_ch_offset_to_secondary_ch_offset(ch_offset));
3266
3267 pattrib->last_txcmdsz = pattrib->pktlen;
3268
3269 dump_mgntframe(padapter, pmgntframe);
3270 }
3271
issue_action_BA(struct adapter * padapter,unsigned char * raddr,unsigned char action,unsigned short status)3272 void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status)
3273 {
3274 u8 category = RTW_WLAN_CATEGORY_BACK;
3275 u16 start_seq;
3276 u16 BA_para_set;
3277 u16 reason_code;
3278 u16 BA_timeout_value;
3279 __le16 le_tmp;
3280 u16 BA_starting_seqctrl = 0;
3281 enum ht_cap_ampdu_factor max_rx_ampdu_factor;
3282 struct xmit_frame *pmgntframe;
3283 struct pkt_attrib *pattrib;
3284 u8 *pframe;
3285 struct rtw_ieee80211_hdr *pwlanhdr;
3286 __le16 *fctrl;
3287 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3288 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3289 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3290 struct sta_info *psta;
3291 struct sta_priv *pstapriv = &padapter->stapriv;
3292 struct registry_priv *pregpriv = &padapter->registrypriv;
3293
3294 DBG_88E("%s, category=%d, action=%d, status=%d\n", __func__, category, action, status);
3295
3296 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3297 if (pmgntframe == NULL)
3298 return;
3299
3300 /* update attribute */
3301 pattrib = &pmgntframe->attrib;
3302 update_mgntframe_attrib(padapter, pattrib);
3303
3304 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3305
3306 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3307 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3308
3309 fctrl = &(pwlanhdr->frame_ctl);
3310 *(fctrl) = 0;
3311
3312 /* memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */
3313 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3314 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3315 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
3316
3317 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3318 pmlmeext->mgnt_seq++;
3319 SetFrameSubType(pframe, WIFI_ACTION);
3320
3321 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3322 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3323
3324 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3325 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3326
3327 if (category == 3) {
3328 switch (action) {
3329 case 0: /* ADDBA req */
3330 do {
3331 pmlmeinfo->dialogToken++;
3332 } while (pmlmeinfo->dialogToken == 0);
3333 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
3334
3335 BA_para_set = (0x1002 | ((status & 0xf) << 2)); /* immediate ack & 64 buffer size */
3336 le_tmp = cpu_to_le16(BA_para_set);
3337 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3338
3339 BA_timeout_value = 5000;/* 5ms */
3340 le_tmp = cpu_to_le16(BA_timeout_value);
3341 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3342
3343 psta = rtw_get_stainfo(pstapriv, raddr);
3344 if (psta != NULL) {
3345 start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07]&0xfff) + 1;
3346
3347 DBG_88E("BA_starting_seqctrl=%d for TID=%d\n", start_seq, status & 0x07);
3348
3349 psta->BA_starting_seqctrl[status & 0x07] = start_seq;
3350
3351 BA_starting_seqctrl = start_seq << 4;
3352 }
3353 le_tmp = cpu_to_le16(BA_starting_seqctrl);
3354 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3355 break;
3356 case 1: /* ADDBA rsp */
3357 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
3358 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
3359
3360 BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f;
3361 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
3362 switch (max_rx_ampdu_factor) {
3363 case MAX_AMPDU_FACTOR_64K:
3364 BA_para_set |= 0x1000; /* 64 buffer size */
3365 break;
3366 case MAX_AMPDU_FACTOR_32K:
3367 BA_para_set |= 0x0800; /* 32 buffer size */
3368 break;
3369 case MAX_AMPDU_FACTOR_16K:
3370 BA_para_set |= 0x0400; /* 16 buffer size */
3371 break;
3372 case MAX_AMPDU_FACTOR_8K:
3373 BA_para_set |= 0x0200; /* 8 buffer size */
3374 break;
3375 default:
3376 BA_para_set |= 0x1000; /* 64 buffer size */
3377 break;
3378 }
3379
3380 if (pregpriv->ampdu_amsdu == 0)/* disabled */
3381 BA_para_set = BA_para_set & ~BIT(0);
3382 else if (pregpriv->ampdu_amsdu == 1)/* enabled */
3383 BA_para_set = BA_para_set | BIT(0);
3384 le_tmp = cpu_to_le16(BA_para_set);
3385
3386 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3387 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
3388 break;
3389 case 2:/* DELBA */
3390 BA_para_set = (status & 0x1F) << 3;
3391 le_tmp = cpu_to_le16(BA_para_set);
3392 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3393
3394 reason_code = 37;/* Requested from peer STA as it does not want to use the mechanism */
3395 le_tmp = cpu_to_le16(reason_code);
3396 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
3397 break;
3398 default:
3399 break;
3400 }
3401 }
3402
3403 pattrib->last_txcmdsz = pattrib->pktlen;
3404
3405 dump_mgntframe(padapter, pmgntframe);
3406 }
3407
issue_action_BSSCoexistPacket(struct adapter * padapter)3408 static void issue_action_BSSCoexistPacket(struct adapter *padapter)
3409 {
3410 struct list_head *plist, *phead;
3411 unsigned char category, action;
3412 struct xmit_frame *pmgntframe;
3413 struct pkt_attrib *pattrib;
3414 unsigned char *pframe;
3415 struct rtw_ieee80211_hdr *pwlanhdr;
3416 __le16 *fctrl;
3417 struct wlan_network *pnetwork = NULL;
3418 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3419 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3420 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3421 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3422 struct __queue *queue = &(pmlmepriv->scanned_queue);
3423 u8 InfoContent[16] = {0};
3424 u8 ICS[8][15];
3425 if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
3426 return;
3427
3428 if (pmlmeinfo->bwmode_updated)
3429 return;
3430
3431
3432 DBG_88E("%s\n", __func__);
3433
3434
3435 category = RTW_WLAN_CATEGORY_PUBLIC;
3436 action = ACT_PUBLIC_BSSCOEXIST;
3437
3438 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3439 if (pmgntframe == NULL)
3440 return;
3441
3442 /* update attribute */
3443 pattrib = &pmgntframe->attrib;
3444 update_mgntframe_attrib(padapter, pattrib);
3445
3446 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3447
3448 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3449 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3450
3451 fctrl = &(pwlanhdr->frame_ctl);
3452 *(fctrl) = 0;
3453
3454 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
3455 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3456 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
3457
3458 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3459 pmlmeext->mgnt_seq++;
3460 SetFrameSubType(pframe, WIFI_ACTION);
3461
3462 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3463 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3464
3465 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3466 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3467
3468
3469 /* */
3470 if (pmlmepriv->num_FortyMHzIntolerant > 0) {
3471 u8 iedata = 0;
3472
3473 iedata |= BIT(2);/* 20 MHz BSS Width Request */
3474
3475 pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
3476 }
3477
3478
3479 /* */
3480 memset(ICS, 0, sizeof(ICS));
3481 if (pmlmepriv->num_sta_no_ht > 0) {
3482 int i;
3483
3484 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
3485
3486 phead = get_list_head(queue);
3487 plist = phead->next;
3488
3489 while (phead != plist) {
3490 int len;
3491 u8 *p;
3492 struct wlan_bssid_ex *pbss_network;
3493
3494 pnetwork = container_of(plist, struct wlan_network, list);
3495
3496 plist = plist->next;
3497
3498 pbss_network = (struct wlan_bssid_ex *)&pnetwork->network;
3499
3500 p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
3501 if ((p == NULL) || (len == 0)) { /* non-HT */
3502 if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14))
3503 continue;
3504
3505 ICS[0][pbss_network->Configuration.DSConfig] = 1;
3506
3507 if (ICS[0][0] == 0)
3508 ICS[0][0] = 1;
3509 }
3510 }
3511 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
3512
3513 for (i = 0; i < 8; i++) {
3514 if (ICS[i][0] == 1) {
3515 int j, k = 0;
3516
3517 InfoContent[k] = i;
3518 /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */
3519 k++;
3520
3521 for (j = 1; j <= 14; j++) {
3522 if (ICS[i][j] == 1) {
3523 if (k < 16) {
3524 InfoContent[k] = j; /* channel number */
3525 /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
3526 k++;
3527 }
3528 }
3529 }
3530
3531 pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
3532 }
3533 }
3534 }
3535
3536
3537 pattrib->last_txcmdsz = pattrib->pktlen;
3538
3539 dump_mgntframe(padapter, pmgntframe);
3540 }
3541
send_delba(struct adapter * padapter,u8 initiator,u8 * addr)3542 unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr)
3543 {
3544 struct sta_priv *pstapriv = &padapter->stapriv;
3545 struct sta_info *psta = NULL;
3546 /* struct recv_reorder_ctrl *preorder_ctrl; */
3547 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3548 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3549 u16 tid;
3550
3551 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
3552 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
3553 return _SUCCESS;
3554
3555 psta = rtw_get_stainfo(pstapriv, addr);
3556 if (psta == NULL)
3557 return _SUCCESS;
3558
3559 if (initiator == 0) { /* recipient */
3560 for (tid = 0; tid < MAXTID; tid++) {
3561 if (psta->recvreorder_ctrl[tid].enable) {
3562 DBG_88E("rx agg disable tid(%d)\n", tid);
3563 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
3564 psta->recvreorder_ctrl[tid].enable = false;
3565 psta->recvreorder_ctrl[tid].indicate_seq = 0xffff;
3566 }
3567 }
3568 } else if (initiator == 1) { /* originator */
3569 for (tid = 0; tid < MAXTID; tid++) {
3570 if (psta->htpriv.agg_enable_bitmap & BIT(tid)) {
3571 DBG_88E("tx agg disable tid(%d)\n", tid);
3572 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
3573 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
3574 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
3575 }
3576 }
3577 }
3578
3579 return _SUCCESS;
3580 }
3581
send_beacon(struct adapter * padapter)3582 unsigned int send_beacon(struct adapter *padapter)
3583 {
3584 u8 bxmitok = false;
3585 int issue = 0;
3586 int poll = 0;
3587
3588 u32 start = jiffies;
3589
3590 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
3591 do {
3592 issue_beacon(padapter, 100);
3593 issue++;
3594 do {
3595 yield();
3596 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
3597 poll++;
3598 } while ((poll%10) != 0 && !bxmitok && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
3599 } while (!bxmitok && issue < 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
3600
3601 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
3602 return _FAIL;
3603 if (!bxmitok) {
3604 DBG_88E("%s fail! %u ms\n", __func__, rtw_get_passing_time_ms(start));
3605 return _FAIL;
3606 } else {
3607 u32 passing_time = rtw_get_passing_time_ms(start);
3608
3609 if (passing_time > 100 || issue > 3)
3610 DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", __func__, issue, poll, rtw_get_passing_time_ms(start));
3611 return _SUCCESS;
3612 }
3613 }
3614
3615 /****************************************************************************
3616
3617 Following are some utility functions for WiFi MLME
3618
3619 *****************************************************************************/
3620
site_survey(struct adapter * padapter)3621 void site_survey(struct adapter *padapter)
3622 {
3623 unsigned char survey_channel = 0, val8;
3624 enum rt_scan_type ScanType = SCAN_PASSIVE;
3625 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3626 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3627 u32 initialgain = 0;
3628 struct rtw_ieee80211_channel *ch;
3629
3630 if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) {
3631 ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx];
3632 survey_channel = ch->hw_value;
3633 ScanType = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
3634 }
3635
3636
3637 if (survey_channel != 0) {
3638 /* PAUSE 4-AC Queue when site_survey */
3639 /* rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
3640 /* val8 |= 0x0f; */
3641 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
3642 if (pmlmeext->sitesurvey_res.channel_idx == 0)
3643 set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
3644 else
3645 SelectChannel(padapter, survey_channel);
3646
3647 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */
3648 int i;
3649 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
3650 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
3651 /* todo: to issue two probe req??? */
3652 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
3653 /* msleep(SURVEY_TO>>1); */
3654 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
3655 }
3656 }
3657
3658 if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
3659 /* todo: to issue two probe req??? */
3660 issue_probereq(padapter, NULL, NULL);
3661 /* msleep(SURVEY_TO>>1); */
3662 issue_probereq(padapter, NULL, NULL);
3663 }
3664
3665 if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
3666 /* todo: to issue two probe req??? */
3667 issue_probereq(padapter, NULL, NULL);
3668 /* msleep(SURVEY_TO>>1); */
3669 issue_probereq(padapter, NULL, NULL);
3670 }
3671 }
3672
3673 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
3674 } else {
3675
3676 /* 20100721:Interrupt scan operation here. */
3677 /* For SW antenna diversity before link, it needs to switch to another antenna and scan again. */
3678 /* It compares the scan result and select better one to do connection. */
3679 if (rtw_hal_antdiv_before_linked(padapter)) {
3680 pmlmeext->sitesurvey_res.bss_cnt = 0;
3681 pmlmeext->sitesurvey_res.channel_idx = -1;
3682 pmlmeext->chan_scan_time = SURVEY_TO / 2;
3683 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
3684 return;
3685 }
3686
3687 pmlmeext->sitesurvey_res.state = SCAN_COMPLETE;
3688
3689 /* switch back to the original channel */
3690
3691 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
3692
3693 /* flush 4-AC Queue after site_survey */
3694 /* val8 = 0; */
3695 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
3696
3697 /* config MSR */
3698 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
3699
3700 initialgain = 0xff; /* restore RX GAIN */
3701 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
3702 /* turn on dynamic functions */
3703 Restore_DM_Func_Flag(padapter);
3704 /* Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); */
3705
3706 if (is_client_associated_to_ap(padapter))
3707 issue_nulldata(padapter, NULL, 0, 3, 500);
3708
3709 val8 = 0; /* survey done */
3710 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
3711
3712 report_surveydone_event(padapter);
3713
3714 pmlmeext->chan_scan_time = SURVEY_TO;
3715 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
3716
3717 issue_action_BSSCoexistPacket(padapter);
3718 issue_action_BSSCoexistPacket(padapter);
3719 issue_action_BSSCoexistPacket(padapter);
3720 }
3721 return;
3722 }
3723
3724 /* collect bss info from Beacon and Probe request/response frames. */
collect_bss_info(struct adapter * padapter,struct recv_frame * precv_frame,struct wlan_bssid_ex * bssid)3725 u8 collect_bss_info(struct adapter *padapter, struct recv_frame *precv_frame, struct wlan_bssid_ex *bssid)
3726 {
3727 int i;
3728 u32 len;
3729 u8 *p;
3730 u16 val16, subtype;
3731 u8 *pframe = precv_frame->rx_data;
3732 u32 packet_len = precv_frame->len;
3733 u8 ie_offset;
3734 struct registry_priv *pregistrypriv = &padapter->registrypriv;
3735 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3736 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3737
3738 len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
3739
3740 if (len > MAX_IE_SZ)
3741 return _FAIL;
3742
3743 memset(bssid, 0, sizeof(struct wlan_bssid_ex));
3744
3745 subtype = GetFrameSubType(pframe);
3746
3747 if (subtype == WIFI_BEACON) {
3748 bssid->Reserved[0] = 1;
3749 ie_offset = _BEACON_IE_OFFSET_;
3750 } else {
3751 /* FIXME : more type */
3752 if (subtype == WIFI_PROBEREQ) {
3753 ie_offset = _PROBEREQ_IE_OFFSET_;
3754 bssid->Reserved[0] = 2;
3755 } else if (subtype == WIFI_PROBERSP) {
3756 ie_offset = _PROBERSP_IE_OFFSET_;
3757 bssid->Reserved[0] = 3;
3758 } else {
3759 bssid->Reserved[0] = 0;
3760 ie_offset = _FIXED_IE_LENGTH_;
3761 }
3762 }
3763
3764 bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
3765
3766 /* below is to copy the information element */
3767 bssid->IELength = len;
3768 memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
3769
3770 /* get the signal strength in dBM.raw data */
3771 bssid->Rssi = precv_frame->attrib.phy_info.recvpower;
3772 bssid->PhyInfo.SignalQuality = precv_frame->attrib.phy_info.SignalQuality;/* in percentage */
3773 bssid->PhyInfo.SignalStrength = precv_frame->attrib.phy_info.SignalStrength;/* in percentage */
3774 rtw_hal_get_def_var(padapter, HAL_DEF_CURRENT_ANTENNA, &bssid->PhyInfo.Optimum_antenna);
3775
3776 /* checking SSID */
3777 p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset);
3778 if (p == NULL) {
3779 DBG_88E("marc: cannot find SSID for survey event\n");
3780 return _FAIL;
3781 }
3782
3783 if (len) {
3784 if (len > NDIS_802_11_LENGTH_SSID) {
3785 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
3786 return _FAIL;
3787 }
3788 memcpy(bssid->Ssid.Ssid, (p + 2), len);
3789 bssid->Ssid.SsidLength = len;
3790 } else {
3791 bssid->Ssid.SsidLength = 0;
3792 }
3793
3794 memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
3795
3796 /* checking rate info... */
3797 i = 0;
3798 p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
3799 if (p != NULL) {
3800 if (len > NDIS_802_11_LENGTH_RATES_EX) {
3801 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
3802 return _FAIL;
3803 }
3804 memcpy(bssid->SupportedRates, (p + 2), len);
3805 i = len;
3806 }
3807
3808 p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
3809 if (p != NULL) {
3810 if (len > (NDIS_802_11_LENGTH_RATES_EX-i)) {
3811 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
3812 return _FAIL;
3813 }
3814 memcpy(bssid->SupportedRates + i, (p + 2), len);
3815 }
3816
3817 /* todo: */
3818 bssid->NetworkTypeInUse = Ndis802_11OFDM24;
3819
3820 if (bssid->IELength < 12)
3821 return _FAIL;
3822
3823 /* Checking for DSConfig */
3824 p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
3825
3826 bssid->Configuration.DSConfig = 0;
3827 bssid->Configuration.Length = 0;
3828
3829 if (p) {
3830 bssid->Configuration.DSConfig = *(p + 2);
3831 } else {/* In 5G, some ap do not have DSSET IE */
3832 /* checking HT info for channel */
3833 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
3834 if (p) {
3835 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
3836 bssid->Configuration.DSConfig = HT_info->primary_channel;
3837 } else { /* use current channel */
3838 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
3839 }
3840 }
3841
3842 if (subtype == WIFI_PROBEREQ) {
3843 /* FIXME */
3844 bssid->InfrastructureMode = Ndis802_11Infrastructure;
3845 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
3846 bssid->Privacy = 1;
3847 return _SUCCESS;
3848 }
3849
3850 bssid->Configuration.BeaconPeriod =
3851 get_unaligned_le16(rtw_get_beacon_interval_from_ie(bssid->IEs));
3852
3853 val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
3854
3855 if (val16 & BIT(0)) {
3856 bssid->InfrastructureMode = Ndis802_11Infrastructure;
3857 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
3858 } else {
3859 bssid->InfrastructureMode = Ndis802_11IBSS;
3860 memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
3861 }
3862
3863 if (val16 & BIT(4))
3864 bssid->Privacy = 1;
3865 else
3866 bssid->Privacy = 0;
3867
3868 bssid->Configuration.ATIMWindow = 0;
3869
3870 /* 20/40 BSS Coexistence check */
3871 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) {
3872 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3873 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
3874 if (p && len > 0) {
3875 struct HT_caps_element *pHT_caps;
3876 pHT_caps = (struct HT_caps_element *)(p + 2);
3877
3878 if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info)&BIT(14))
3879 pmlmepriv->num_FortyMHzIntolerant++;
3880 } else {
3881 pmlmepriv->num_sta_no_ht++;
3882 }
3883 }
3884
3885 /* mark bss info receiving from nearby channel as SignalQuality 101 */
3886 if (bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
3887 bssid->PhyInfo.SignalQuality = 101;
3888 return _SUCCESS;
3889 }
3890
start_create_ibss(struct adapter * padapter)3891 void start_create_ibss(struct adapter *padapter)
3892 {
3893 unsigned short caps;
3894 u8 val8;
3895 u8 join_type;
3896 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3897 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3898 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
3899 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
3900 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
3901
3902 /* update wireless mode */
3903 update_wireless_mode(padapter);
3904
3905 /* update capability */
3906 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
3907 update_capinfo(padapter, caps);
3908 if (caps&cap_IBSS) {/* adhoc master */
3909 val8 = 0xcf;
3910 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
3911
3912 /* switch channel */
3913 /* SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE); */
3914 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
3915
3916 beacon_timing_control(padapter);
3917
3918 /* set msr to WIFI_FW_ADHOC_STATE */
3919 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
3920 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
3921
3922 /* issue beacon */
3923 if (send_beacon(padapter) == _FAIL) {
3924 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("issuing beacon frame fail....\n"));
3925
3926 report_join_res(padapter, -1);
3927 pmlmeinfo->state = WIFI_FW_NULL_STATE;
3928 } else {
3929 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
3930 join_type = 0;
3931 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
3932
3933 report_join_res(padapter, 1);
3934 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
3935 }
3936 } else {
3937 DBG_88E("start_create_ibss, invalid cap:%x\n", caps);
3938 return;
3939 }
3940 }
3941
start_clnt_join(struct adapter * padapter)3942 void start_clnt_join(struct adapter *padapter)
3943 {
3944 unsigned short caps;
3945 u8 val8;
3946 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3947 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3948 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
3949 int beacon_timeout;
3950
3951 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
3952 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
3953
3954 /* update wireless mode */
3955 update_wireless_mode(padapter);
3956
3957 /* update capability */
3958 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
3959 update_capinfo(padapter, caps);
3960 if (caps&cap_ESS) {
3961 Set_MSR(padapter, WIFI_FW_STATION_STATE);
3962
3963 val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
3964
3965 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
3966
3967 /* switch channel */
3968 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
3969
3970 /* here wait for receiving the beacon to start auth */
3971 /* and enable a timer */
3972 beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
3973 set_link_timer(pmlmeext, beacon_timeout);
3974 _set_timer(&padapter->mlmepriv.assoc_timer,
3975 (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO*REASSOC_LIMIT) + beacon_timeout);
3976
3977 pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
3978 } else if (caps&cap_IBSS) { /* adhoc client */
3979 Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
3980
3981 val8 = 0xcf;
3982 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
3983
3984 /* switch channel */
3985 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
3986
3987 beacon_timing_control(padapter);
3988
3989 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
3990
3991 report_join_res(padapter, 1);
3992 } else {
3993 return;
3994 }
3995 }
3996
start_clnt_auth(struct adapter * padapter)3997 void start_clnt_auth(struct adapter *padapter)
3998 {
3999 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4000 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4001
4002 del_timer_sync(&pmlmeext->link_timer);
4003
4004 pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
4005 pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
4006
4007 pmlmeinfo->auth_seq = 1;
4008 pmlmeinfo->reauth_count = 0;
4009 pmlmeinfo->reassoc_count = 0;
4010 pmlmeinfo->link_count = 0;
4011 pmlmeext->retry = 0;
4012
4013
4014 /* Because of AP's not receiving deauth before */
4015 /* AP may: 1)not response auth or 2)deauth us after link is complete */
4016 /* issue deauth before issuing auth to deal with the situation */
4017 /* Commented by Albert 2012/07/21 */
4018 /* For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. */
4019 issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
4020
4021 DBG_88E_LEVEL(_drv_info_, "start auth\n");
4022 issue_auth(padapter, NULL, 0);
4023
4024 set_link_timer(pmlmeext, REAUTH_TO);
4025 }
4026
4027
start_clnt_assoc(struct adapter * padapter)4028 void start_clnt_assoc(struct adapter *padapter)
4029 {
4030 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4031 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4032
4033 del_timer_sync(&pmlmeext->link_timer);
4034
4035 pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
4036 pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
4037
4038 issue_assocreq(padapter);
4039
4040 set_link_timer(pmlmeext, REASSOC_TO);
4041 }
4042
receive_disconnect(struct adapter * padapter,unsigned char * MacAddr,unsigned short reason)4043 unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
4044 {
4045 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4046 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4047
4048 /* check A3 */
4049 if (memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
4050 return _SUCCESS;
4051
4052 DBG_88E("%s\n", __func__);
4053
4054 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
4055 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
4056 pmlmeinfo->state = WIFI_FW_NULL_STATE;
4057 report_del_sta_event(padapter, MacAddr, reason);
4058 } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
4059 pmlmeinfo->state = WIFI_FW_NULL_STATE;
4060 report_join_res(padapter, -2);
4061 }
4062 }
4063 return _SUCCESS;
4064 }
4065
process_80211d(struct adapter * padapter,struct wlan_bssid_ex * bssid)4066 static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid)
4067 {
4068 struct registry_priv *pregistrypriv;
4069 struct mlme_ext_priv *pmlmeext;
4070 struct rt_channel_info *chplan_new;
4071 u8 channel;
4072 u8 i;
4073
4074 pregistrypriv = &padapter->registrypriv;
4075 pmlmeext = &padapter->mlmeextpriv;
4076
4077 /* Adjust channel plan by AP Country IE */
4078 if (pregistrypriv->enable80211d &&
4079 (!pmlmeext->update_channel_plan_by_ap_done)) {
4080 u8 *ie, *p;
4081 u32 len;
4082 struct rt_channel_plan chplan_ap;
4083 struct rt_channel_info chplan_sta[MAX_CHANNEL_NUM];
4084 u8 country[4];
4085 u8 fcn; /* first channel number */
4086 u8 noc; /* number of channel */
4087 u8 j, k;
4088
4089 ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
4090 if (!ie)
4091 return;
4092 if (len < 6)
4093 return;
4094 ie += 2;
4095 p = ie;
4096 ie += len;
4097
4098 memset(country, 0, 4);
4099 memcpy(country, p, 3);
4100 p += 3;
4101 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
4102 ("%s: 802.11d country =%s\n", __func__, country));
4103
4104 i = 0;
4105 while ((ie - p) >= 3) {
4106 fcn = *(p++);
4107 noc = *(p++);
4108 p++;
4109
4110 for (j = 0; j < noc; j++) {
4111 if (fcn <= 14)
4112 channel = fcn + j; /* 2.4 GHz */
4113 else
4114 channel = fcn + j*4; /* 5 GHz */
4115
4116 chplan_ap.Channel[i++] = channel;
4117 }
4118 }
4119 chplan_ap.Len = i;
4120
4121 memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
4122
4123 memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
4124 chplan_new = pmlmeext->channel_set;
4125
4126 i = 0;
4127 j = 0;
4128 k = 0;
4129 if (pregistrypriv->wireless_mode & WIRELESS_11G) {
4130 do {
4131 if ((i == MAX_CHANNEL_NUM) ||
4132 (chplan_sta[i].ChannelNum == 0) ||
4133 (chplan_sta[i].ChannelNum > 14))
4134 break;
4135
4136 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
4137 break;
4138
4139 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
4140 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
4141 chplan_new[k].ScanType = SCAN_ACTIVE;
4142 i++;
4143 j++;
4144 k++;
4145 } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
4146 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
4147 chplan_new[k].ScanType = SCAN_PASSIVE;
4148 i++;
4149 k++;
4150 } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
4151 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
4152 chplan_new[k].ScanType = SCAN_ACTIVE;
4153 j++;
4154 k++;
4155 }
4156 } while (1);
4157
4158 /* change AP not support channel to Passive scan */
4159 while ((i < MAX_CHANNEL_NUM) &&
4160 (chplan_sta[i].ChannelNum != 0) &&
4161 (chplan_sta[i].ChannelNum <= 14)) {
4162 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
4163 chplan_new[k].ScanType = SCAN_PASSIVE;
4164 i++;
4165 k++;
4166 }
4167
4168 /* add channel AP supported */
4169 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) {
4170 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
4171 chplan_new[k].ScanType = SCAN_ACTIVE;
4172 j++;
4173 k++;
4174 }
4175 } else {
4176 /* keep original STA 2.4G channel plan */
4177 while ((i < MAX_CHANNEL_NUM) &&
4178 (chplan_sta[i].ChannelNum != 0) &&
4179 (chplan_sta[i].ChannelNum <= 14)) {
4180 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
4181 chplan_new[k].ScanType = chplan_sta[i].ScanType;
4182 i++;
4183 k++;
4184 }
4185
4186 /* skip AP 2.4G channel plan */
4187 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
4188 j++;
4189 }
4190
4191 /* keep original STA 5G channel plan */
4192 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
4193 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
4194 chplan_new[k].ScanType = chplan_sta[i].ScanType;
4195 i++;
4196 k++;
4197 }
4198
4199 pmlmeext->update_channel_plan_by_ap_done = 1;
4200 }
4201
4202 /* If channel is used by AP, set channel scan type to active */
4203 channel = bssid->Configuration.DSConfig;
4204 chplan_new = pmlmeext->channel_set;
4205 i = 0;
4206 while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].ChannelNum != 0)) {
4207 if (chplan_new[i].ChannelNum == channel) {
4208 if (chplan_new[i].ScanType == SCAN_PASSIVE) {
4209 chplan_new[i].ScanType = SCAN_ACTIVE;
4210 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
4211 ("%s: change channel %d scan type from passive to active\n",
4212 __func__, channel));
4213 }
4214 break;
4215 }
4216 i++;
4217 }
4218 }
4219
4220 /****************************************************************************
4221
4222 Following are the functions to report events
4223
4224 *****************************************************************************/
4225
report_survey_event(struct adapter * padapter,struct recv_frame * precv_frame)4226 void report_survey_event(struct adapter *padapter,
4227 struct recv_frame *precv_frame)
4228 {
4229 struct cmd_obj *pcmd_obj;
4230 u8 *pevtcmd;
4231 u32 cmdsz;
4232 struct survey_event *psurvey_evt;
4233 struct C2HEvent_Header *pc2h_evt_hdr;
4234 struct mlme_ext_priv *pmlmeext;
4235 struct cmd_priv *pcmdpriv;
4236
4237 if (!padapter)
4238 return;
4239
4240 pmlmeext = &padapter->mlmeextpriv;
4241 pcmdpriv = &padapter->cmdpriv;
4242
4243
4244 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4245 if (pcmd_obj == NULL)
4246 return;
4247
4248 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
4249 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4250 if (pevtcmd == NULL) {
4251 kfree(pcmd_obj);
4252 return;
4253 }
4254
4255 INIT_LIST_HEAD(&pcmd_obj->list);
4256
4257 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
4258 pcmd_obj->cmdsz = cmdsz;
4259 pcmd_obj->parmbuf = pevtcmd;
4260
4261 pcmd_obj->rsp = NULL;
4262 pcmd_obj->rspsz = 0;
4263
4264 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
4265 pc2h_evt_hdr->len = sizeof(struct survey_event);
4266 pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
4267 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
4268
4269 psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
4270
4271 if (collect_bss_info(padapter, precv_frame, (struct wlan_bssid_ex *)&psurvey_evt->bss) == _FAIL) {
4272 kfree(pcmd_obj);
4273 kfree(pevtcmd);
4274 return;
4275 }
4276
4277 process_80211d(padapter, &psurvey_evt->bss);
4278
4279 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
4280
4281 pmlmeext->sitesurvey_res.bss_cnt++;
4282
4283 return;
4284 }
4285
report_surveydone_event(struct adapter * padapter)4286 void report_surveydone_event(struct adapter *padapter)
4287 {
4288 struct cmd_obj *pcmd_obj;
4289 u8 *pevtcmd;
4290 u32 cmdsz;
4291 struct surveydone_event *psurveydone_evt;
4292 struct C2HEvent_Header *pc2h_evt_hdr;
4293 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4294 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4295
4296 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
4297 if (pcmd_obj == NULL)
4298 return;
4299
4300 cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
4301 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
4302 if (pevtcmd == NULL) {
4303 kfree(pcmd_obj);
4304 return;
4305 }
4306
4307 INIT_LIST_HEAD(&pcmd_obj->list);
4308
4309 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
4310 pcmd_obj->cmdsz = cmdsz;
4311 pcmd_obj->parmbuf = pevtcmd;
4312
4313 pcmd_obj->rsp = NULL;
4314 pcmd_obj->rspsz = 0;
4315
4316 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
4317 pc2h_evt_hdr->len = sizeof(struct surveydone_event);
4318 pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
4319 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
4320
4321 psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
4322 psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
4323
4324 DBG_88E("survey done event(%x)\n", psurveydone_evt->bss_cnt);
4325
4326 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
4327
4328 return;
4329 }
4330
report_join_res(struct adapter * padapter,int res)4331 void report_join_res(struct adapter *padapter, int res)
4332 {
4333 struct cmd_obj *pcmd_obj;
4334 u8 *pevtcmd;
4335 u32 cmdsz;
4336 struct joinbss_event *pjoinbss_evt;
4337 struct C2HEvent_Header *pc2h_evt_hdr;
4338 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4339 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4340 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4341
4342 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4343 if (pcmd_obj == NULL)
4344 return;
4345
4346 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
4347 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4348 if (pevtcmd == NULL) {
4349 kfree(pcmd_obj);
4350 return;
4351 }
4352
4353 INIT_LIST_HEAD(&pcmd_obj->list);
4354
4355 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
4356 pcmd_obj->cmdsz = cmdsz;
4357 pcmd_obj->parmbuf = pevtcmd;
4358
4359 pcmd_obj->rsp = NULL;
4360 pcmd_obj->rspsz = 0;
4361
4362 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
4363 pc2h_evt_hdr->len = sizeof(struct joinbss_event);
4364 pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
4365 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
4366
4367 pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
4368 memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
4369 pjoinbss_evt->network.join_res = res;
4370 pjoinbss_evt->network.aid = res;
4371
4372 DBG_88E("report_join_res(%d)\n", res);
4373
4374
4375 rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
4376
4377
4378 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
4379
4380 return;
4381 }
4382
report_del_sta_event(struct adapter * padapter,unsigned char * MacAddr,unsigned short reason)4383 void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
4384 {
4385 struct cmd_obj *pcmd_obj;
4386 u8 *pevtcmd;
4387 u32 cmdsz;
4388 struct sta_info *psta;
4389 int mac_id;
4390 struct stadel_event *pdel_sta_evt;
4391 struct C2HEvent_Header *pc2h_evt_hdr;
4392 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4393 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4394
4395 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
4396 if (pcmd_obj == NULL)
4397 return;
4398
4399 cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
4400 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
4401 if (pevtcmd == NULL) {
4402 kfree(pcmd_obj);
4403 return;
4404 }
4405
4406 INIT_LIST_HEAD(&pcmd_obj->list);
4407
4408 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
4409 pcmd_obj->cmdsz = cmdsz;
4410 pcmd_obj->parmbuf = pevtcmd;
4411
4412 pcmd_obj->rsp = NULL;
4413 pcmd_obj->rspsz = 0;
4414
4415 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
4416 pc2h_evt_hdr->len = sizeof(struct stadel_event);
4417 pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
4418 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
4419
4420 pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
4421 memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
4422 memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
4423
4424
4425 psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
4426 if (psta)
4427 mac_id = (int)psta->mac_id;
4428 else
4429 mac_id = (-1);
4430
4431 pdel_sta_evt->mac_id = mac_id;
4432
4433 DBG_88E("report_del_sta_event: delete STA, mac_id =%d\n", mac_id);
4434
4435 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
4436
4437 return;
4438 }
4439
report_add_sta_event(struct adapter * padapter,unsigned char * MacAddr,int cam_idx)4440 void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx)
4441 {
4442 struct cmd_obj *pcmd_obj;
4443 u8 *pevtcmd;
4444 u32 cmdsz;
4445 struct stassoc_event *padd_sta_evt;
4446 struct C2HEvent_Header *pc2h_evt_hdr;
4447 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4448 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4449
4450 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
4451 if (pcmd_obj == NULL)
4452 return;
4453
4454 cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
4455 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
4456 if (pevtcmd == NULL) {
4457 kfree(pcmd_obj);
4458 return;
4459 }
4460
4461 INIT_LIST_HEAD(&pcmd_obj->list);
4462
4463 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
4464 pcmd_obj->cmdsz = cmdsz;
4465 pcmd_obj->parmbuf = pevtcmd;
4466
4467 pcmd_obj->rsp = NULL;
4468 pcmd_obj->rspsz = 0;
4469
4470 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
4471 pc2h_evt_hdr->len = sizeof(struct stassoc_event);
4472 pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
4473 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
4474
4475 padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
4476 memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
4477 padd_sta_evt->cam_id = cam_idx;
4478
4479 DBG_88E("report_add_sta_event: add STA\n");
4480
4481 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
4482
4483 return;
4484 }
4485
4486
4487 /****************************************************************************
4488
4489 Following are the event callback functions
4490
4491 *****************************************************************************/
4492
4493 /* for sta/adhoc mode */
update_sta_info(struct adapter * padapter,struct sta_info * psta)4494 void update_sta_info(struct adapter *padapter, struct sta_info *psta)
4495 {
4496 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4497 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4498 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4499
4500 /* ERP */
4501 VCS_update(padapter, psta);
4502
4503 /* HT */
4504 if (pmlmepriv->htpriv.ht_option) {
4505 psta->htpriv.ht_option = true;
4506
4507 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
4508
4509 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps)))
4510 psta->htpriv.sgi = true;
4511
4512 psta->qos_option = true;
4513 } else {
4514 psta->htpriv.ht_option = false;
4515
4516 psta->htpriv.ampdu_enable = false;
4517
4518 psta->htpriv.sgi = false;
4519 psta->qos_option = false;
4520 }
4521 psta->htpriv.bwmode = pmlmeext->cur_bwmode;
4522 psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
4523
4524 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
4525 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
4526
4527 /* QoS */
4528 if (pmlmepriv->qospriv.qos_option)
4529 psta->qos_option = true;
4530
4531
4532 psta->state = _FW_LINKED;
4533 }
4534
mlmeext_joinbss_event_callback(struct adapter * padapter,int join_res)4535 void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res)
4536 {
4537 struct sta_info *psta, *psta_bmc;
4538 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4539 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4540 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4541 struct sta_priv *pstapriv = &padapter->stapriv;
4542 u8 join_type;
4543 u16 media_status;
4544
4545 if (join_res < 0) {
4546 join_type = 1;
4547 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
4548 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
4549
4550 /* restore to initial setting. */
4551 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
4552
4553 goto exit_mlmeext_joinbss_event_callback;
4554 }
4555
4556 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
4557 /* for bc/mc */
4558 psta_bmc = rtw_get_bcmc_stainfo(padapter);
4559 if (psta_bmc) {
4560 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc;
4561 update_bmc_sta_support_rate(padapter, psta_bmc->mac_id);
4562 Update_RA_Entry(padapter, psta_bmc->mac_id);
4563 }
4564 }
4565
4566
4567 /* turn on dynamic functions */
4568 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
4569
4570 /* update IOT-related issue */
4571 update_IOT_info(padapter);
4572
4573 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
4574
4575 /* BCN interval */
4576 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
4577
4578 /* update capability */
4579 update_capinfo(padapter, pmlmeinfo->capability);
4580
4581 /* WMM, Update EDCA param */
4582 WMMOnAssocRsp(padapter);
4583
4584 /* HT */
4585 HTOnAssocRsp(padapter);
4586
4587 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
4588
4589 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
4590 if (psta) { /* only for infra. mode */
4591 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
4592
4593 psta->wireless_mode = pmlmeext->cur_wireless_mode;
4594
4595 /* set per sta rate after updating HT cap. */
4596 set_sta_rate(padapter, psta);
4597 rtw_hal_set_hwreg(padapter, HW_VAR_TX_RPT_MAX_MACID, (u8 *)&psta->mac_id);
4598 media_status = (psta->mac_id<<8)|1; /* MACID|OPMODE: 1 means connect */
4599 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
4600 }
4601
4602 join_type = 2;
4603 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
4604
4605 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
4606 /* correcting TSF */
4607 correct_TSF(padapter, pmlmeext);
4608 }
4609 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
4610
4611 exit_mlmeext_joinbss_event_callback:
4612
4613 DBG_88E("=>%s\n", __func__);
4614 }
4615
mlmeext_sta_add_event_callback(struct adapter * padapter,struct sta_info * psta)4616 void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta)
4617 {
4618 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4619 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4620 u8 join_type;
4621
4622 DBG_88E("%s\n", __func__);
4623
4624 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
4625 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {/* adhoc master or sta_count>1 */
4626 /* nothing to do */
4627 } else { /* adhoc client */
4628 /* correcting TSF */
4629 correct_TSF(padapter, pmlmeext);
4630
4631 /* start beacon */
4632 if (send_beacon(padapter) == _FAIL) {
4633 pmlmeinfo->FW_sta_info[psta->mac_id].status = 0;
4634 pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE;
4635 return;
4636 }
4637 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
4638 }
4639
4640 join_type = 2;
4641 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
4642 }
4643
4644 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
4645
4646 /* rate radaptive */
4647 Update_RA_Entry(padapter, psta->mac_id);
4648
4649 /* update adhoc sta_info */
4650 update_sta_info(padapter, psta);
4651 }
4652
mlmeext_sta_del_event_callback(struct adapter * padapter)4653 void mlmeext_sta_del_event_callback(struct adapter *padapter)
4654 {
4655 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4656 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4657
4658 if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter)) {
4659 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
4660 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
4661
4662 /* restore to initial setting. */
4663 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
4664
4665 /* switch to the 20M Hz mode after disconnect */
4666 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
4667 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
4668
4669 /* SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset); */
4670 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
4671
4672
4673 flush_all_cam_entry(padapter);
4674
4675 pmlmeinfo->state = WIFI_FW_NULL_STATE;
4676
4677 /* set MSR to no link state -> infra. mode */
4678 Set_MSR(padapter, _HW_STATE_STATION_);
4679
4680 del_timer_sync(&pmlmeext->link_timer);
4681 }
4682 }
4683
4684 /****************************************************************************
4685
4686 Following are the functions for the timer handlers
4687
4688 *****************************************************************************/
4689 void _linked_rx_signal_strehgth_display(struct adapter *padapter);
_linked_rx_signal_strehgth_display(struct adapter * padapter)4690 void _linked_rx_signal_strehgth_display(struct adapter *padapter)
4691 {
4692 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4693 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4694 u8 mac_id;
4695 int UndecoratedSmoothedPWDB;
4696 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
4697 mac_id = 0;
4698 else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
4699 mac_id = 2;
4700
4701 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &mac_id);
4702
4703 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
4704 DBG_88E("UndecoratedSmoothedPWDB:%d\n", UndecoratedSmoothedPWDB);
4705 }
4706
chk_ap_is_alive(struct adapter * padapter,struct sta_info * psta)4707 static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta)
4708 {
4709 u8 ret = false;
4710
4711 if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)) &&
4712 sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta) &&
4713 sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta))
4714 ret = false;
4715 else
4716 ret = true;
4717
4718 sta_update_last_rx_pkts(psta);
4719
4720 return ret;
4721 }
4722
linked_status_chk(struct adapter * padapter)4723 void linked_status_chk(struct adapter *padapter)
4724 {
4725 u32 i;
4726 struct sta_info *psta;
4727 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4728 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4729 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4730 struct sta_priv *pstapriv = &padapter->stapriv;
4731
4732 if (padapter->bRxRSSIDisplay)
4733 _linked_rx_signal_strehgth_display(padapter);
4734
4735 if (is_client_associated_to_ap(padapter)) {
4736 /* linked infrastructure client mode */
4737
4738 int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
4739 int rx_chk_limit;
4740
4741 rx_chk_limit = 4;
4742 psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
4743 if (psta != NULL) {
4744 bool is_p2p_enable = false;
4745
4746 if (!chk_ap_is_alive(padapter, psta))
4747 rx_chk = _FAIL;
4748
4749 if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
4750 tx_chk = _FAIL;
4751
4752 if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)) {
4753 u8 backup_oper_channel = 0;
4754
4755 /* switch to correct channel of current network before issue keep-alive frames */
4756 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
4757 backup_oper_channel = rtw_get_oper_ch(padapter);
4758 SelectChannel(padapter, pmlmeext->cur_channel);
4759 }
4760
4761 if (rx_chk != _SUCCESS)
4762 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 3, 1);
4763
4764 if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) || rx_chk != _SUCCESS) {
4765 tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
4766 /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
4767 if (tx_chk == _SUCCESS && !is_p2p_enable)
4768 rx_chk = _SUCCESS;
4769 }
4770
4771 /* back to the original operation channel */
4772 if (backup_oper_channel > 0)
4773 SelectChannel(padapter, backup_oper_channel);
4774 } else {
4775 if (rx_chk != _SUCCESS) {
4776 if (pmlmeext->retry == 0) {
4777 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
4778 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
4779 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
4780 }
4781 }
4782
4783 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) {
4784 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0);
4785 }
4786 }
4787
4788 if (rx_chk == _FAIL) {
4789 pmlmeext->retry++;
4790 if (pmlmeext->retry > rx_chk_limit) {
4791 DBG_88E_LEVEL(_drv_always_, FUNC_ADPT_FMT" disconnect or roaming\n",
4792 FUNC_ADPT_ARG(padapter));
4793 receive_disconnect(padapter, pmlmeinfo->network.MacAddress,
4794 WLAN_REASON_EXPIRATION_CHK);
4795 return;
4796 }
4797 } else {
4798 pmlmeext->retry = 0;
4799 }
4800
4801 if (tx_chk == _FAIL) {
4802 pmlmeinfo->link_count &= 0xf;
4803 } else {
4804 pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
4805 pmlmeinfo->link_count = 0;
4806 }
4807 } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL) */
4808 } else if (is_client_associated_to_ibss(padapter)) {
4809 /* linked IBSS mode */
4810 /* for each assoc list entry to check the rx pkt counter */
4811 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
4812 if (pmlmeinfo->FW_sta_info[i].status == 1) {
4813 psta = pmlmeinfo->FW_sta_info[i].psta;
4814
4815 if (NULL == psta)
4816 continue;
4817 if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta)) {
4818 if (pmlmeinfo->FW_sta_info[i].retry < 3) {
4819 pmlmeinfo->FW_sta_info[i].retry++;
4820 } else {
4821 pmlmeinfo->FW_sta_info[i].retry = 0;
4822 pmlmeinfo->FW_sta_info[i].status = 0;
4823 report_del_sta_event(padapter, psta->hwaddr
4824 , 65535/* indicate disconnect caused by no rx */
4825 );
4826 }
4827 } else {
4828 pmlmeinfo->FW_sta_info[i].retry = 0;
4829 pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta);
4830 }
4831 }
4832 }
4833 }
4834 }
4835
survey_timer_hdl(void * function_context)4836 void survey_timer_hdl(void *function_context)
4837 {
4838 struct adapter *padapter = (struct adapter *)function_context;
4839 struct cmd_obj *ph2c;
4840 struct sitesurvey_parm *psurveyPara;
4841 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4842 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4843
4844 /* issue rtw_sitesurvey_cmd */
4845 if (pmlmeext->sitesurvey_res.state > SCAN_START) {
4846 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
4847 pmlmeext->sitesurvey_res.channel_idx++;
4848
4849 if (pmlmeext->scan_abort) {
4850 pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num;
4851 DBG_88E("%s idx:%d\n", __func__
4852 , pmlmeext->sitesurvey_res.channel_idx);
4853
4854 pmlmeext->scan_abort = false;/* reset */
4855 }
4856
4857 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4858 if (ph2c == NULL)
4859 goto exit_survey_timer_hdl;
4860
4861 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
4862 if (psurveyPara == NULL) {
4863 kfree(ph2c);
4864 goto exit_survey_timer_hdl;
4865 }
4866
4867 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
4868 rtw_enqueue_cmd(pcmdpriv, ph2c);
4869 }
4870
4871
4872 exit_survey_timer_hdl:
4873 return;
4874 }
4875
link_timer_hdl(void * function_context)4876 void link_timer_hdl(void *function_context)
4877 {
4878 struct adapter *padapter = (struct adapter *)function_context;
4879 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4880 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4881
4882 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
4883 DBG_88E("link_timer_hdl:no beacon while connecting\n");
4884 pmlmeinfo->state = WIFI_FW_NULL_STATE;
4885 report_join_res(padapter, -3);
4886 } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) {
4887 /* re-auth timer */
4888 if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) {
4889 pmlmeinfo->state = 0;
4890 report_join_res(padapter, -1);
4891 return;
4892 }
4893
4894 DBG_88E("link_timer_hdl: auth timeout and try again\n");
4895 pmlmeinfo->auth_seq = 1;
4896 issue_auth(padapter, NULL, 0);
4897 set_link_timer(pmlmeext, REAUTH_TO);
4898 } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) {
4899 /* re-assoc timer */
4900 if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) {
4901 pmlmeinfo->state = WIFI_FW_NULL_STATE;
4902 report_join_res(padapter, -2);
4903 return;
4904 }
4905
4906 DBG_88E("link_timer_hdl: assoc timeout and try again\n");
4907 issue_assocreq(padapter);
4908 set_link_timer(pmlmeext, REASSOC_TO);
4909 }
4910 return;
4911 }
4912
addba_timer_hdl(void * function_context)4913 void addba_timer_hdl(void *function_context)
4914 {
4915 struct sta_info *psta = (struct sta_info *)function_context;
4916 struct ht_priv *phtpriv;
4917
4918 if (!psta)
4919 return;
4920
4921 phtpriv = &psta->htpriv;
4922
4923 if ((phtpriv->ht_option) && (phtpriv->ampdu_enable)) {
4924 if (phtpriv->candidate_tid_bitmap)
4925 phtpriv->candidate_tid_bitmap = 0x0;
4926 }
4927 }
4928
NULL_hdl(struct adapter * padapter,u8 * pbuf)4929 u8 NULL_hdl(struct adapter *padapter, u8 *pbuf)
4930 {
4931 return H2C_SUCCESS;
4932 }
4933
setopmode_hdl(struct adapter * padapter,u8 * pbuf)4934 u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
4935 {
4936 u8 type;
4937 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4938 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4939 struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
4940
4941 if (psetop->mode == Ndis802_11APMode) {
4942 pmlmeinfo->state = WIFI_FW_AP_STATE;
4943 type = _HW_STATE_AP_;
4944 } else if (psetop->mode == Ndis802_11Infrastructure) {
4945 pmlmeinfo->state &= ~(BIT(0)|BIT(1));/* clear state */
4946 pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */
4947 type = _HW_STATE_STATION_;
4948 } else if (psetop->mode == Ndis802_11IBSS) {
4949 type = _HW_STATE_ADHOC_;
4950 } else {
4951 type = _HW_STATE_NOLINK_;
4952 }
4953
4954 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
4955 /* Set_NETYPE0_MSR(padapter, type); */
4956
4957 return H2C_SUCCESS;
4958 }
4959
createbss_hdl(struct adapter * padapter,u8 * pbuf)4960 u8 createbss_hdl(struct adapter *padapter, u8 *pbuf)
4961 {
4962 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4963 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4964 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
4965 struct wlan_bssid_ex *pparm = (struct wlan_bssid_ex *)pbuf;
4966 /* u32 initialgain; */
4967
4968
4969 if (pparm->InfrastructureMode == Ndis802_11APMode) {
4970 #ifdef CONFIG_88EU_AP_MODE
4971
4972 if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
4973 /* todo: */
4974 return H2C_SUCCESS;
4975 }
4976 #endif
4977 }
4978
4979 /* below is for ad-hoc master */
4980 if (pparm->InfrastructureMode == Ndis802_11IBSS) {
4981 rtw_joinbss_reset(padapter);
4982
4983 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
4984 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
4985 pmlmeinfo->ERP_enable = 0;
4986 pmlmeinfo->WMM_enable = 0;
4987 pmlmeinfo->HT_enable = 0;
4988 pmlmeinfo->HT_caps_enable = 0;
4989 pmlmeinfo->HT_info_enable = 0;
4990 pmlmeinfo->agg_enable_bitmap = 0;
4991 pmlmeinfo->candidate_tid_bitmap = 0;
4992
4993 /* disable dynamic functions, such as high power, DIG */
4994 Save_DM_Func_Flag(padapter);
4995 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
4996
4997 /* config the initial gain under linking, need to write the BB registers */
4998 /* initialgain = 0x1E; */
4999 /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */
5000
5001 /* cancel link timer */
5002 del_timer_sync(&pmlmeext->link_timer);
5003
5004 /* clear CAM */
5005 flush_all_cam_entry(padapter);
5006
5007 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
5008 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
5009
5010 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
5011 return H2C_PARAMETERS_ERROR;
5012
5013 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
5014
5015 start_create_ibss(padapter);
5016 }
5017
5018 return H2C_SUCCESS;
5019 }
5020
join_cmd_hdl(struct adapter * padapter,u8 * pbuf)5021 u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf)
5022 {
5023 u8 join_type;
5024 struct ndis_802_11_var_ie *pIE;
5025 struct registry_priv *pregpriv = &padapter->registrypriv;
5026 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5027 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5028 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
5029 struct wlan_bssid_ex *pparm = (struct wlan_bssid_ex *)pbuf;
5030 u32 i;
5031
5032 /* check already connecting to AP or not */
5033 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
5034 if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
5035 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 5, 100);
5036
5037 pmlmeinfo->state = WIFI_FW_NULL_STATE;
5038
5039 /* clear CAM */
5040 flush_all_cam_entry(padapter);
5041
5042 del_timer_sync(&pmlmeext->link_timer);
5043
5044 /* set MSR to nolink -> infra. mode */
5045 Set_MSR(padapter, _HW_STATE_STATION_);
5046
5047
5048 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
5049 }
5050
5051 rtw_antenna_select_cmd(padapter, pparm->PhyInfo.Optimum_antenna, false);
5052
5053 rtw_joinbss_reset(padapter);
5054
5055 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
5056 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
5057 pmlmeinfo->ERP_enable = 0;
5058 pmlmeinfo->WMM_enable = 0;
5059 pmlmeinfo->HT_enable = 0;
5060 pmlmeinfo->HT_caps_enable = 0;
5061 pmlmeinfo->HT_info_enable = 0;
5062 pmlmeinfo->agg_enable_bitmap = 0;
5063 pmlmeinfo->candidate_tid_bitmap = 0;
5064 pmlmeinfo->bwmode_updated = false;
5065
5066 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
5067 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
5068
5069 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
5070 return H2C_PARAMETERS_ERROR;
5071
5072 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
5073
5074 /* Check AP vendor to move rtw_joinbss_cmd() */
5075
5076 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pnetwork->IELength;) {
5077 pIE = (struct ndis_802_11_var_ie *)(pnetwork->IEs + i);
5078
5079 switch (pIE->ElementID) {
5080 case _VENDOR_SPECIFIC_IE_:/* Get WMM IE. */
5081 if (!memcmp(pIE->data, WMM_OUI, 4))
5082 pmlmeinfo->WMM_enable = 1;
5083 break;
5084 case _HT_CAPABILITY_IE_: /* Get HT Cap IE. */
5085 pmlmeinfo->HT_caps_enable = 1;
5086 break;
5087 case _HT_EXTRA_INFO_IE_: /* Get HT Info IE. */
5088 pmlmeinfo->HT_info_enable = 1;
5089
5090 /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */
5091 {
5092 struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data);
5093
5094 if ((pregpriv->cbw40_enable) && (pht_info->infos[0] & BIT(2))) {
5095 /* switch to the 40M Hz mode according to the AP */
5096 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_40;
5097 switch (pht_info->infos[0] & 0x3) {
5098 case 1:
5099 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
5100 break;
5101 case 3:
5102 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
5103 break;
5104 default:
5105 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
5106 break;
5107 }
5108
5109 DBG_88E("set ch/bw before connected\n");
5110 }
5111 }
5112 break;
5113 default:
5114 break;
5115 }
5116
5117 i += (pIE->Length + 2);
5118 }
5119 /* disable dynamic functions, such as high power, DIG */
5120
5121 /* config the initial gain under linking, need to write the BB registers */
5122
5123 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
5124 join_type = 0;
5125 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
5126
5127 /* cancel link timer */
5128 del_timer_sync(&pmlmeext->link_timer);
5129
5130 start_clnt_join(padapter);
5131
5132 return H2C_SUCCESS;
5133 }
5134
disconnect_hdl(struct adapter * padapter,unsigned char * pbuf)5135 u8 disconnect_hdl(struct adapter *padapter, unsigned char *pbuf)
5136 {
5137 struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
5138 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5139 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5140 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
5141 u8 val8;
5142
5143 if (is_client_associated_to_ap(padapter))
5144 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms/100, 100);
5145
5146 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
5147 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
5148
5149 /* restore to initial setting. */
5150 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
5151
5152 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
5153 /* Stop BCN */
5154 val8 = 0;
5155 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
5156 }
5157
5158
5159 /* set MSR to no link state -> infra. mode */
5160 Set_MSR(padapter, _HW_STATE_STATION_);
5161
5162 pmlmeinfo->state = WIFI_FW_NULL_STATE;
5163
5164 /* switch to the 20M Hz mode after disconnect */
5165 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
5166 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
5167
5168 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
5169
5170 flush_all_cam_entry(padapter);
5171
5172 del_timer_sync(&pmlmeext->link_timer);
5173
5174 rtw_free_uc_swdec_pending_queue(padapter);
5175
5176 return H2C_SUCCESS;
5177 }
5178
rtw_scan_ch_decision(struct adapter * padapter,struct rtw_ieee80211_channel * out,u32 out_num,struct rtw_ieee80211_channel * in,u32 in_num)5179 static int rtw_scan_ch_decision(struct adapter *padapter, struct rtw_ieee80211_channel *out,
5180 u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
5181 {
5182 int i, j;
5183 int set_idx;
5184 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5185
5186 /* clear out first */
5187 memset(out, 0, sizeof(struct rtw_ieee80211_channel)*out_num);
5188
5189 /* acquire channels from in */
5190 j = 0;
5191 for (i = 0; i < in_num; i++) {
5192 set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value);
5193 if (in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED) &&
5194 set_idx >= 0) {
5195 out[j] = in[i];
5196
5197 if (pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
5198 out[j].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
5199
5200 j++;
5201 }
5202 if (j >= out_num)
5203 break;
5204 }
5205
5206 /* if out is empty, use channel_set as default */
5207 if (j == 0) {
5208 for (i = 0; i < pmlmeext->max_chan_nums; i++) {
5209 out[i].hw_value = pmlmeext->channel_set[i].ChannelNum;
5210
5211 if (pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
5212 out[i].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
5213
5214 j++;
5215 }
5216 }
5217
5218 return j;
5219 }
5220
sitesurvey_cmd_hdl(struct adapter * padapter,u8 * pbuf)5221 u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf)
5222 {
5223 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5224 struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
5225 u8 bdelayscan = false;
5226 u8 val8;
5227 u32 initialgain;
5228 u32 i;
5229
5230 if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE) {
5231 /* for first time sitesurvey_cmd */
5232 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, NULL);
5233
5234 pmlmeext->sitesurvey_res.state = SCAN_START;
5235 pmlmeext->sitesurvey_res.bss_cnt = 0;
5236 pmlmeext->sitesurvey_res.channel_idx = 0;
5237
5238 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
5239 if (pparm->ssid[i].SsidLength) {
5240 memcpy(pmlmeext->sitesurvey_res.ssid[i].Ssid, pparm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
5241 pmlmeext->sitesurvey_res.ssid[i].SsidLength = pparm->ssid[i].SsidLength;
5242 } else {
5243 pmlmeext->sitesurvey_res.ssid[i].SsidLength = 0;
5244 }
5245 }
5246
5247 pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter
5248 , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT
5249 , pparm->ch, pparm->ch_num
5250 );
5251
5252 pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode;
5253
5254 /* issue null data if associating to the AP */
5255 if (is_client_associated_to_ap(padapter)) {
5256 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
5257
5258 issue_nulldata(padapter, NULL, 1, 3, 500);
5259
5260 bdelayscan = true;
5261 }
5262 if (bdelayscan) {
5263 /* delay 50ms to protect nulldata(1). */
5264 set_survey_timer(pmlmeext, 50);
5265 return H2C_SUCCESS;
5266 }
5267 }
5268
5269 if ((pmlmeext->sitesurvey_res.state == SCAN_START) || (pmlmeext->sitesurvey_res.state == SCAN_TXNULL)) {
5270 /* disable dynamic functions, such as high power, DIG */
5271 Save_DM_Func_Flag(padapter);
5272 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
5273
5274 /* config the initial gain under scanning, need to write the BB registers */
5275 initialgain = 0x1E;
5276
5277 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
5278
5279 /* set MSR to no link state */
5280 Set_MSR(padapter, _HW_STATE_NOLINK_);
5281
5282 val8 = 1; /* under site survey */
5283 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
5284
5285 pmlmeext->sitesurvey_res.state = SCAN_PROCESS;
5286 }
5287
5288 site_survey(padapter);
5289
5290 return H2C_SUCCESS;
5291 }
5292
setauth_hdl(struct adapter * padapter,unsigned char * pbuf)5293 u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf)
5294 {
5295 struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
5296 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5297 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5298
5299 if (pparm->mode < 4)
5300 pmlmeinfo->auth_algo = pparm->mode;
5301 return H2C_SUCCESS;
5302 }
5303
setkey_hdl(struct adapter * padapter,u8 * pbuf)5304 u8 setkey_hdl(struct adapter *padapter, u8 *pbuf)
5305 {
5306 unsigned short ctrl;
5307 struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
5308 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5309 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5310 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
5311
5312 /* main tx key for wep. */
5313 if (pparm->set_tx)
5314 pmlmeinfo->key_index = pparm->keyid;
5315
5316 /* write cam */
5317 ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
5318
5319 DBG_88E_LEVEL(_drv_info_, "set group key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) "
5320 "keyid:%d\n", pparm->algorithm, pparm->keyid);
5321 write_cam(padapter, pparm->keyid, ctrl, null_sta, pparm->key);
5322
5323 return H2C_SUCCESS;
5324 }
5325
set_stakey_hdl(struct adapter * padapter,u8 * pbuf)5326 u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf)
5327 {
5328 u16 ctrl = 0;
5329 u8 cam_id;/* cam_entry */
5330 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5331 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5332 struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
5333
5334 /* cam_entry: */
5335 /* 0~3 for default key */
5336
5337 /* for concurrent mode (ap+sta): */
5338 /* default key is disable, using sw encrypt/decrypt */
5339 /* cam_entry = 4 for sta mode (macid = 0) */
5340 /* cam_entry(macid+3) = 5 ~ N for ap mode (aid = 1~N, macid = 2 ~N) */
5341
5342 /* for concurrent mode (sta+sta): */
5343 /* default key is disable, using sw encrypt/decrypt */
5344 /* cam_entry = 4 mapping to macid = 0 */
5345 /* cam_entry = 5 mapping to macid = 2 */
5346
5347 cam_id = 4;
5348
5349 DBG_88E_LEVEL(_drv_info_, "set pairwise key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) camid:%d\n",
5350 pparm->algorithm, cam_id);
5351 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
5352 struct sta_info *psta;
5353 struct sta_priv *pstapriv = &padapter->stapriv;
5354
5355 if (pparm->algorithm == _NO_PRIVACY_) /* clear cam entry */ {
5356 clear_cam_entry(padapter, pparm->id);
5357 return H2C_SUCCESS_RSP;
5358 }
5359
5360 psta = rtw_get_stainfo(pstapriv, pparm->addr);
5361 if (psta) {
5362 ctrl = (BIT(15) | ((pparm->algorithm) << 2));
5363
5364 DBG_88E("r871x_set_stakey_hdl(): enc_algorithm=%d\n", pparm->algorithm);
5365
5366 if ((psta->mac_id < 1) || (psta->mac_id > (NUM_STA-4))) {
5367 DBG_88E("r871x_set_stakey_hdl():set_stakey failed, mac_id(aid)=%d\n", psta->mac_id);
5368 return H2C_REJECTED;
5369 }
5370
5371 cam_id = (psta->mac_id + 3);/* 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
5372
5373 DBG_88E("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, cam_entry=%d\n", pparm->addr[0],
5374 pparm->addr[1], pparm->addr[2], pparm->addr[3], pparm->addr[4],
5375 pparm->addr[5], cam_id);
5376
5377 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
5378
5379 return H2C_SUCCESS_RSP;
5380 } else {
5381 DBG_88E("r871x_set_stakey_hdl(): sta has been free\n");
5382 return H2C_REJECTED;
5383 }
5384 }
5385
5386 /* below for sta mode */
5387
5388 if (pparm->algorithm == _NO_PRIVACY_) { /* clear cam entry */
5389 clear_cam_entry(padapter, pparm->id);
5390 return H2C_SUCCESS;
5391 }
5392 ctrl = BIT(15) | ((pparm->algorithm) << 2);
5393 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
5394 pmlmeinfo->enc_algo = pparm->algorithm;
5395 return H2C_SUCCESS;
5396 }
5397
add_ba_hdl(struct adapter * padapter,unsigned char * pbuf)5398 u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf)
5399 {
5400 struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
5401 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5402 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5403
5404 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
5405
5406 if (!psta)
5407 return H2C_SUCCESS;
5408
5409 if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
5410 ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
5411 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
5412 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
5413 } else {
5414 psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
5415 }
5416 return H2C_SUCCESS;
5417 }
5418
set_tx_beacon_cmd(struct adapter * padapter)5419 u8 set_tx_beacon_cmd(struct adapter *padapter)
5420 {
5421 struct cmd_obj *ph2c;
5422 struct wlan_bssid_ex *ptxBeacon_parm;
5423 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
5424 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5425 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5426 u8 res = _SUCCESS;
5427 int len_diff = 0;
5428
5429
5430 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
5431 if (ph2c == NULL) {
5432 res = _FAIL;
5433 goto exit;
5434 }
5435
5436 ptxBeacon_parm = kzalloc(sizeof(struct wlan_bssid_ex), GFP_KERNEL);
5437 if (ptxBeacon_parm == NULL) {
5438 kfree(ph2c);
5439 res = _FAIL;
5440 goto exit;
5441 }
5442
5443 memcpy(ptxBeacon_parm, &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
5444
5445 len_diff = update_hidden_ssid(ptxBeacon_parm->IEs+_BEACON_IE_OFFSET_,
5446 ptxBeacon_parm->IELength-_BEACON_IE_OFFSET_,
5447 pmlmeinfo->hidden_ssid_mode);
5448 ptxBeacon_parm->IELength += len_diff;
5449
5450 init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
5451
5452 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
5453
5454
5455 exit:
5456
5457
5458 return res;
5459 }
5460
mlme_evt_hdl(struct adapter * padapter,unsigned char * pbuf)5461 u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf)
5462 {
5463 u8 evt_code;
5464 u16 evt_sz;
5465 uint *peventbuf;
5466 void (*event_callback)(struct adapter *dev, u8 *pbuf);
5467
5468 peventbuf = (uint *)pbuf;
5469 evt_sz = (u16)(*peventbuf&0xffff);
5470 evt_code = (u8)((*peventbuf>>16)&0xff);
5471
5472 /* checking if event code is valid */
5473 if (evt_code >= MAX_C2HEVT) {
5474 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("\nEvent Code(%d) mismatch!\n", evt_code));
5475 goto _abort_event_;
5476 }
5477
5478 /* checking if event size match the event parm size */
5479 if ((wlanevents[evt_code].parmsize != 0) &&
5480 (wlanevents[evt_code].parmsize != evt_sz)) {
5481 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
5482 ("\nEvent(%d) Parm Size mismatch (%d vs %d)!\n",
5483 evt_code, wlanevents[evt_code].parmsize, evt_sz));
5484 goto _abort_event_;
5485 }
5486
5487 peventbuf += 2;
5488
5489 if (peventbuf) {
5490 event_callback = wlanevents[evt_code].event_callback;
5491 event_callback(padapter, (u8 *)peventbuf);
5492
5493 }
5494
5495 _abort_event_:
5496 return H2C_SUCCESS;
5497 }
5498
tx_beacon_hdl(struct adapter * padapter,unsigned char * pbuf)5499 u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf)
5500 {
5501 if (send_beacon(padapter) == _FAIL) {
5502 DBG_88E("issue_beacon, fail!\n");
5503 return H2C_PARAMETERS_ERROR;
5504 }
5505 #ifdef CONFIG_88EU_AP_MODE
5506 else { /* tx bc/mc frames after update TIM */
5507 struct sta_info *psta_bmc;
5508 struct list_head *xmitframe_plist, *xmitframe_phead;
5509 struct xmit_frame *pxmitframe = NULL;
5510 struct sta_priv *pstapriv = &padapter->stapriv;
5511
5512 /* for BC/MC Frames */
5513 psta_bmc = rtw_get_bcmc_stainfo(padapter);
5514 if (!psta_bmc)
5515 return H2C_SUCCESS;
5516
5517 if ((pstapriv->tim_bitmap&BIT(0)) && (psta_bmc->sleepq_len > 0)) {
5518 msleep(10);/* 10ms, ATIM(HIQ) Windows */
5519 spin_lock_bh(&psta_bmc->sleep_q.lock);
5520
5521 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
5522 xmitframe_plist = xmitframe_phead->next;
5523
5524 while (xmitframe_phead != xmitframe_plist) {
5525 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
5526
5527 xmitframe_plist = xmitframe_plist->next;
5528
5529 list_del_init(&pxmitframe->list);
5530
5531 psta_bmc->sleepq_len--;
5532 if (psta_bmc->sleepq_len > 0)
5533 pxmitframe->attrib.mdata = 1;
5534 else
5535 pxmitframe->attrib.mdata = 0;
5536
5537 pxmitframe->attrib.triggered = 1;
5538
5539 pxmitframe->attrib.qsel = 0x11;/* HIQ */
5540
5541 spin_unlock_bh(&psta_bmc->sleep_q.lock);
5542 if (rtw_hal_xmit(padapter, pxmitframe))
5543 rtw_os_xmit_complete(padapter, pxmitframe);
5544 spin_lock_bh(&psta_bmc->sleep_q.lock);
5545 }
5546 spin_unlock_bh(&psta_bmc->sleep_q.lock);
5547 }
5548 }
5549 #endif
5550 return H2C_SUCCESS;
5551 }
5552
set_ch_hdl(struct adapter * padapter,u8 * pbuf)5553 u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf)
5554 {
5555 struct set_ch_parm *set_ch_parm;
5556 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5557
5558 if (!pbuf)
5559 return H2C_PARAMETERS_ERROR;
5560
5561 set_ch_parm = (struct set_ch_parm *)pbuf;
5562
5563 DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
5564 FUNC_NDEV_ARG(padapter->pnetdev),
5565 set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
5566
5567 pmlmeext->cur_channel = set_ch_parm->ch;
5568 pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
5569 pmlmeext->cur_bwmode = set_ch_parm->bw;
5570
5571 set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
5572
5573 return H2C_SUCCESS;
5574 }
5575
set_chplan_hdl(struct adapter * padapter,unsigned char * pbuf)5576 u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)
5577 {
5578 struct SetChannelPlan_param *setChannelPlan_param;
5579 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5580
5581 if (!pbuf)
5582 return H2C_PARAMETERS_ERROR;
5583
5584 setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
5585
5586 pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
5587 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
5588
5589 return H2C_SUCCESS;
5590 }
5591