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