staging: rtl8188eu:Remove rtw_zmalloc(), wrapper for kzalloc()
[deliverable/linux.git] / drivers / staging / rtl8188eu / core / rtw_mlme_ext.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 *
19 ******************************************************************************/
20 #define _RTW_MLME_EXT_C_
21
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <wifi.h>
25 #include <rtw_mlme_ext.h>
26 #include <wlan_bssdef.h>
27 #include <mlme_osdep.h>
28 #include <recv_osdep.h>
29
30 static struct mlme_handler mlme_sta_tbl[] = {
31 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
32 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
33 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
34 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
35 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
36 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
37
38 /*----------------------------------------------------------
39 below 2 are reserved
40 -----------------------------------------------------------*/
41 {0, "DoReserved", &DoReserved},
42 {0, "DoReserved", &DoReserved},
43 {WIFI_BEACON, "OnBeacon", &OnBeacon},
44 {WIFI_ATIM, "OnATIM", &OnAtim},
45 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
46 {WIFI_AUTH, "OnAuth", &OnAuthClient},
47 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
48 {WIFI_ACTION, "OnAction", &OnAction},
49 };
50
51 static struct action_handler OnAction_tbl[] = {
52 {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
53 {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
54 {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
55 {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
56 {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
57 {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
58 {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved},
59 {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
60 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
61 {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
62 {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
63 };
64
65
66 static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
67
68 /**************************************************
69 OUI definitions for the vendor specific IE
70 ***************************************************/
71 unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
72 unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
73 unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
74 unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
75 unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
76
77 unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
78 unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
79
80 unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
81 unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
82
83 extern unsigned char REALTEK_96B_IE[];
84
85 /********************************************************
86 MCS rate definitions
87 *********************************************************/
88 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
89 unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
90
91 /********************************************************
92 ChannelPlan definitions
93 *********************************************************/
94 static struct rt_channel_plan_2g RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = {
95 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x00, RT_CHANNEL_DOMAIN_2G_WORLD , Passive scan CH 12, 13 */
96 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1 */
97 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* 0x02, RT_CHANNEL_DOMAIN_2G_FCC1 */
98 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1 */
99 {{10, 11, 12, 13}, 4}, /* 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2 */
100 {{}, 0}, /* 0x05, RT_CHANNEL_DOMAIN_2G_NULL */
101 };
102
103 static struct rt_channel_plan_map RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = {
104 /* 0x00 ~ 0x1F , Old Define ===== */
105 {0x02}, /* 0x00, RT_CHANNEL_DOMAIN_FCC */
106 {0x02}, /* 0x01, RT_CHANNEL_DOMAIN_IC */
107 {0x01}, /* 0x02, RT_CHANNEL_DOMAIN_ETSI */
108 {0x01}, /* 0x03, RT_CHANNEL_DOMAIN_SPAIN */
109 {0x01}, /* 0x04, RT_CHANNEL_DOMAIN_FRANCE */
110 {0x03}, /* 0x05, RT_CHANNEL_DOMAIN_MKK */
111 {0x03}, /* 0x06, RT_CHANNEL_DOMAIN_MKK1 */
112 {0x01}, /* 0x07, RT_CHANNEL_DOMAIN_ISRAEL */
113 {0x03}, /* 0x08, RT_CHANNEL_DOMAIN_TELEC */
114 {0x03}, /* 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN */
115 {0x00}, /* 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13 */
116 {0x02}, /* 0x0B, RT_CHANNEL_DOMAIN_TAIWAN */
117 {0x01}, /* 0x0C, RT_CHANNEL_DOMAIN_CHINA */
118 {0x02}, /* 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO */
119 {0x02}, /* 0x0E, RT_CHANNEL_DOMAIN_KOREA */
120 {0x02}, /* 0x0F, RT_CHANNEL_DOMAIN_TURKEY */
121 {0x01}, /* 0x10, RT_CHANNEL_DOMAIN_JAPAN */
122 {0x02}, /* 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS */
123 {0x01}, /* 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
124 {0x00}, /* 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G */
125 {0x02}, /* 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS */
126 {0x00}, /* 0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS */
127 {0x00}, /* 0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS */
128 {0x03}, /* 0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
129 {0x05}, /* 0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS */
130 {0x02}, /* 0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS */
131 {0x00}, /* 0x1A, */
132 {0x00}, /* 0x1B, */
133 {0x00}, /* 0x1C, */
134 {0x00}, /* 0x1D, */
135 {0x00}, /* 0x1E, */
136 {0x05}, /* 0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G */
137 /* 0x20 ~ 0x7F , New Define ===== */
138 {0x00}, /* 0x20, RT_CHANNEL_DOMAIN_WORLD_NULL */
139 {0x01}, /* 0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL */
140 {0x02}, /* 0x22, RT_CHANNEL_DOMAIN_FCC1_NULL */
141 {0x03}, /* 0x23, RT_CHANNEL_DOMAIN_MKK1_NULL */
142 {0x04}, /* 0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL */
143 {0x02}, /* 0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1 */
144 {0x00}, /* 0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1 */
145 {0x03}, /* 0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1 */
146 {0x00}, /* 0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1 */
147 {0x00}, /* 0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2 */
148 {0x00}, /* 0x2A, */
149 {0x00}, /* 0x2B, */
150 {0x00}, /* 0x2C, */
151 {0x00}, /* 0x2D, */
152 {0x00}, /* 0x2E, */
153 {0x00}, /* 0x2F, */
154 {0x00}, /* 0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3 */
155 {0x00}, /* 0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4 */
156 {0x00}, /* 0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5 */
157 {0x00}, /* 0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6 */
158 {0x02}, /* 0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7 */
159 {0x00}, /* 0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2 */
160 {0x00}, /* 0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3 */
161 {0x03}, /* 0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2 */
162 {0x03}, /* 0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3 */
163 {0x02}, /* 0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1 */
164 {0x00}, /* 0x3A, */
165 {0x00}, /* 0x3B, */
166 {0x00}, /* 0x3C, */
167 {0x00}, /* 0x3D, */
168 {0x00}, /* 0x3E, */
169 {0x00}, /* 0x3F, */
170 {0x02}, /* 0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2 */
171 {0x03}, /* 0x41, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G */
172 };
173
174 static struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03}; /* use the combination for max channel numbers */
175
176 /*
177 * Search the @param channel_num in given @param channel_set
178 * @ch_set: the given channel set
179 * @ch: the given channel number
180 *
181 * return the index of channel_num in channel_set, -1 if not found
182 */
183 int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch)
184 {
185 int i;
186 for (i = 0; ch_set[i].ChannelNum != 0; i++) {
187 if (ch == ch_set[i].ChannelNum)
188 break;
189 }
190
191 if (i >= ch_set[i].ChannelNum)
192 return -1;
193 return i;
194 }
195
196 /****************************************************************************
197
198 Following are the initialization functions for WiFi MLME
199
200 *****************************************************************************/
201
202 int init_hw_mlme_ext(struct adapter *padapter)
203 {
204 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
205
206 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
207 return _SUCCESS;
208 }
209
210 static void init_mlme_ext_priv_value(struct adapter *padapter)
211 {
212 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
213 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
214 unsigned char mixed_datarate[NumRates] = {
215 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
216 _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_,
217 _48M_RATE_, _54M_RATE_, 0xff
218 };
219 unsigned char mixed_basicrate[NumRates] = {
220 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
221 _12M_RATE_, _24M_RATE_, 0xff,
222 };
223
224 atomic_set(&pmlmeext->event_seq, 0);
225 pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
226
227 pmlmeext->cur_channel = padapter->registrypriv.channel;
228 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
229 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
230 pmlmeext->oper_channel = pmlmeext->cur_channel ;
231 pmlmeext->oper_bwmode = pmlmeext->cur_bwmode;
232 pmlmeext->oper_ch_offset = pmlmeext->cur_ch_offset;
233 pmlmeext->retry = 0;
234
235 pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
236
237 memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
238 memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
239
240 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
241
242 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
243 pmlmeext->sitesurvey_res.channel_idx = 0;
244 pmlmeext->sitesurvey_res.bss_cnt = 0;
245 pmlmeext->scan_abort = false;
246
247 pmlmeinfo->state = WIFI_FW_NULL_STATE;
248 pmlmeinfo->reauth_count = 0;
249 pmlmeinfo->reassoc_count = 0;
250 pmlmeinfo->link_count = 0;
251 pmlmeinfo->auth_seq = 0;
252 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
253 pmlmeinfo->key_index = 0;
254 pmlmeinfo->iv = 0;
255
256 pmlmeinfo->enc_algo = _NO_PRIVACY_;
257 pmlmeinfo->authModeToggle = 0;
258
259 memset(pmlmeinfo->chg_txt, 0, 128);
260
261 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
262 pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
263
264 pmlmeinfo->dialogToken = 0;
265
266 pmlmeext->action_public_rxseq = 0xffff;
267 pmlmeext->action_public_dialog_token = 0xff;
268 }
269
270 static int has_channel(struct rt_channel_info *channel_set,
271 u8 chanset_size,
272 u8 chan) {
273 int i;
274
275 for (i = 0; i < chanset_size; i++) {
276 if (channel_set[i].ChannelNum == chan)
277 return 1;
278 }
279 return 0;
280 }
281
282 static void init_channel_list(struct adapter *padapter, struct rt_channel_info *channel_set,
283 u8 chanset_size,
284 struct p2p_channels *channel_list) {
285 struct p2p_oper_class_map op_class[] = {
286 { IEEE80211G, 81, 1, 13, 1, BW20 },
287 { IEEE80211G, 82, 14, 14, 1, BW20 },
288 { -1, 0, 0, 0, 0, BW20 }
289 };
290
291 int cla, op;
292
293 cla = 0;
294
295 for (op = 0; op_class[op].op_class; op++) {
296 u8 ch;
297 struct p2p_oper_class_map *o = &op_class[op];
298 struct p2p_reg_class *reg = NULL;
299
300 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
301 if (!has_channel(channel_set, chanset_size, ch)) {
302 continue;
303 }
304
305 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
306 continue;
307
308 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) &&
309 ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
310 continue;
311
312 if (reg == NULL) {
313 reg = &channel_list->reg_class[cla];
314 cla++;
315 reg->reg_class = o->op_class;
316 reg->channels = 0;
317 }
318 reg->channel[reg->channels] = ch;
319 reg->channels++;
320 }
321 }
322 channel_list->reg_classes = cla;
323 }
324
325 static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_channel_info *channel_set)
326 {
327 u8 index, chanset_size = 0;
328 u8 b2_4GBand = false;
329 u8 Index2G = 0;
330
331 memset(channel_set, 0, sizeof(struct rt_channel_info) * MAX_CHANNEL_NUM);
332
333 if (ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE) {
334 DBG_88E("ChannelPlan ID %x error !!!!!\n", ChannelPlan);
335 return chanset_size;
336 }
337
338 if (padapter->registrypriv.wireless_mode & WIRELESS_11G) {
339 b2_4GBand = true;
340 if (RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
341 Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
342 else
343 Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
344 }
345
346 if (b2_4GBand) {
347 for (index = 0; index < RTW_ChannelPlan2G[Index2G].Len; index++) {
348 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan2G[Index2G].Channel[index];
349
350 if ((RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN == ChannelPlan) ||/* Channel 1~11 is active, and 12~14 is passive */
351 (RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G == ChannelPlan)) {
352 if (channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
353 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
354 else if ((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
355 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
356 } else if (RT_CHANNEL_DOMAIN_WORLD_WIDE_13 == ChannelPlan ||
357 RT_CHANNEL_DOMAIN_2G_WORLD == Index2G) {/* channel 12~13, passive scan */
358 if (channel_set[chanset_size].ChannelNum <= 11)
359 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
360 else
361 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
362 } else {
363 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
364 }
365
366 chanset_size++;
367 }
368 }
369 return chanset_size;
370 }
371
372 int init_mlme_ext_priv(struct adapter *padapter)
373 {
374 int res = _SUCCESS;
375 struct registry_priv *pregistrypriv = &padapter->registrypriv;
376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
377 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
378 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
379
380 pmlmeext->padapter = padapter;
381
382 init_mlme_ext_priv_value(padapter);
383 pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
384
385 init_mlme_ext_timer(padapter);
386
387 #ifdef CONFIG_88EU_AP_MODE
388 init_mlme_ap_info(padapter);
389 #endif
390
391 pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set);
392 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
393
394 pmlmeext->chan_scan_time = SURVEY_TO;
395 pmlmeext->mlmeext_init = true;
396
397
398 pmlmeext->active_keep_alive_check = true;
399
400 return res;
401 }
402
403 void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
404 {
405 struct adapter *padapter = pmlmeext->padapter;
406
407 if (!padapter)
408 return;
409
410 if (padapter->bDriverStopped) {
411 _cancel_timer_ex(&pmlmeext->survey_timer);
412 _cancel_timer_ex(&pmlmeext->link_timer);
413 /* _cancel_timer_ex(&pmlmeext->ADDBA_timer); */
414 }
415 }
416
417 static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame)
418 {
419 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
420 u8 *pframe = precv_frame->rx_data;
421
422 if (ptable->func) {
423 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
424 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
425 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
426 return;
427 ptable->func(padapter, precv_frame);
428 }
429 }
430
431 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
432 {
433 int index;
434 struct mlme_handler *ptable;
435 #ifdef CONFIG_88EU_AP_MODE
436 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
437 #endif /* CONFIG_88EU_AP_MODE */
438 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
439 u8 *pframe = precv_frame->rx_data;
440 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
441
442 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
443 ("+mgt_dispatcher: type(0x%x) subtype(0x%x)\n",
444 GetFrameType(pframe), GetFrameSubType(pframe)));
445
446 if (GetFrameType(pframe) != WIFI_MGT_TYPE) {
447 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("mgt_dispatcher: type(0x%x) error!\n", GetFrameType(pframe)));
448 return;
449 }
450
451 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
452 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
453 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
454 return;
455
456 ptable = mlme_sta_tbl;
457
458 index = GetFrameSubType(pframe) >> 4;
459
460 if (index > 13) {
461 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type=%d\n", index));
462 return;
463 }
464 ptable += index;
465
466 if (psta != NULL) {
467 if (GetRetry(pframe)) {
468 if (precv_frame->attrib.seq_num ==
469 psta->RxMgmtFrameSeqNum) {
470 /* drop the duplicate management frame */
471 DBG_88E("Drop duplicate management frame with seq_num=%d.\n",
472 precv_frame->attrib.seq_num);
473 return;
474 }
475 }
476 psta->RxMgmtFrameSeqNum = precv_frame->attrib.seq_num;
477 }
478
479 #ifdef CONFIG_88EU_AP_MODE
480 switch (GetFrameSubType(pframe)) {
481 case WIFI_AUTH:
482 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
483 ptable->func = &OnAuth;
484 else
485 ptable->func = &OnAuthClient;
486 /* fall through */
487 case WIFI_ASSOCREQ:
488 case WIFI_REASSOCREQ:
489 _mgt_dispatcher(padapter, ptable, precv_frame);
490 break;
491 case WIFI_PROBEREQ:
492 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
493 _mgt_dispatcher(padapter, ptable, precv_frame);
494 else
495 _mgt_dispatcher(padapter, ptable, precv_frame);
496 break;
497 case WIFI_BEACON:
498 _mgt_dispatcher(padapter, ptable, precv_frame);
499 break;
500 case WIFI_ACTION:
501 _mgt_dispatcher(padapter, ptable, precv_frame);
502 break;
503 default:
504 _mgt_dispatcher(padapter, ptable, precv_frame);
505 break;
506 }
507 #else
508 _mgt_dispatcher(padapter, ptable, precv_frame);
509 #endif
510 }
511
512 #ifdef CONFIG_88EU_P2P
513 static u32 p2p_listen_state_process(struct adapter *padapter, unsigned char *da)
514 {
515 bool response = true;
516
517 /* do nothing if the device name is empty */
518 if (!padapter->wdinfo.device_name_len)
519 response = false;
520
521 if (response)
522 issue_probersp_p2p(padapter, da);
523
524 return _SUCCESS;
525 }
526 #endif /* CONFIG_88EU_P2P */
527
528
529 /****************************************************************************
530
531 Following are the callback functions for each subtype of the management frames
532
533 *****************************************************************************/
534
535 unsigned int OnProbeReq(struct adapter *padapter, struct recv_frame *precv_frame)
536 {
537 unsigned int ielen;
538 unsigned char *p;
539 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
540 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
541 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
542 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
543 u8 *pframe = precv_frame->rx_data;
544 uint len = precv_frame->len;
545 u8 is_valid_p2p_probereq = false;
546
547 #ifdef CONFIG_88EU_P2P
548 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
549 u8 wifi_test_chk_rate = 1;
550
551 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
552 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE) &&
553 !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
554 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH) &&
555 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)) {
556 /* mcs_rate = 0 -> CCK 1M rate */
557 /* mcs_rate = 1 -> CCK 2M rate */
558 /* mcs_rate = 2 -> CCK 5.5M rate */
559 /* mcs_rate = 3 -> CCK 11M rate */
560 /* In the P2P mode, the driver should not support the CCK rate */
561
562 /* Commented by Kurt 2012/10/16 */
563 /* IOT issue: Google Nexus7 use 1M rate to send p2p_probe_req after GO nego completed and Nexus7 is client */
564 if (wifi_test_chk_rate == 1) {
565 is_valid_p2p_probereq = process_probe_req_p2p_ie(pwdinfo, pframe, len);
566 if (is_valid_p2p_probereq) {
567 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
568 /* FIXME */
569 report_survey_event(padapter, precv_frame);
570 p2p_listen_state_process(padapter, get_sa(pframe));
571
572 return _SUCCESS;
573 }
574
575 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
576 goto _continue;
577 }
578 }
579 }
580
581 _continue:
582 #endif /* CONFIG_88EU_P2P */
583
584 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
585 return _SUCCESS;
586
587 if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
588 !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
589 return _SUCCESS;
590
591 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
592 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
593
594 /* check (wildcard) SSID */
595 if (p != NULL) {
596 if (is_valid_p2p_probereq)
597 goto _issue_probersp;
598
599 if ((ielen != 0 && memcmp((void *)(p+2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength)) ||
600 (ielen == 0 && pmlmeinfo->hidden_ssid_mode))
601 return _SUCCESS;
602
603 _issue_probersp:
604
605 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
606 pmlmepriv->cur_network.join_res)
607 issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
608 }
609 return _SUCCESS;
610 }
611
612 unsigned int OnProbeRsp(struct adapter *padapter, struct recv_frame *precv_frame)
613 {
614 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
615 #ifdef CONFIG_88EU_P2P
616 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
617 u8 *pframe = precv_frame->rx_data;
618 #endif
619
620 #ifdef CONFIG_88EU_P2P
621 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
622 if (pwdinfo->tx_prov_disc_info.benable) {
623 if (!memcmp(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
624 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
625 pwdinfo->tx_prov_disc_info.benable = false;
626 issue_p2p_provision_request(padapter,
627 pwdinfo->tx_prov_disc_info.ssid.Ssid,
628 pwdinfo->tx_prov_disc_info.ssid.SsidLength,
629 pwdinfo->tx_prov_disc_info.peerDevAddr);
630 } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
631 pwdinfo->tx_prov_disc_info.benable = false;
632 issue_p2p_provision_request(padapter, NULL, 0,
633 pwdinfo->tx_prov_disc_info.peerDevAddr);
634 }
635 }
636 }
637 return _SUCCESS;
638 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
639 if (pwdinfo->nego_req_info.benable) {
640 DBG_88E("[%s] P2P State is GONEGO ING!\n", __func__);
641 if (!memcmp(pwdinfo->nego_req_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
642 pwdinfo->nego_req_info.benable = false;
643 issue_p2p_GO_request(padapter, pwdinfo->nego_req_info.peerDevAddr);
644 }
645 }
646 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ)) {
647 if (pwdinfo->invitereq_info.benable) {
648 DBG_88E("[%s] P2P_STATE_TX_INVITE_REQ!\n", __func__);
649 if (!memcmp(pwdinfo->invitereq_info.peer_macaddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
650 pwdinfo->invitereq_info.benable = false;
651 issue_p2p_invitation_request(padapter, pwdinfo->invitereq_info.peer_macaddr);
652 }
653 }
654 }
655 #endif
656
657
658 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
659 report_survey_event(padapter, precv_frame);
660 return _SUCCESS;
661 }
662
663 return _SUCCESS;
664 }
665
666 unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
667 {
668 int cam_idx;
669 struct sta_info *psta;
670 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
671 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
672 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
673 struct sta_priv *pstapriv = &padapter->stapriv;
674 u8 *pframe = precv_frame->rx_data;
675 uint len = precv_frame->len;
676 struct wlan_bssid_ex *pbss;
677 int ret = _SUCCESS;
678
679 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
680 report_survey_event(padapter, precv_frame);
681 return _SUCCESS;
682 }
683
684 if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
685 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
686 /* we should update current network before auth, or some IE is wrong */
687 pbss = (struct wlan_bssid_ex *)rtw_malloc(sizeof(struct wlan_bssid_ex));
688 if (pbss) {
689 if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
690 update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true);
691 rtw_get_bcn_info(&(pmlmepriv->cur_network));
692 }
693 kfree(pbss);
694 }
695
696 /* check the vendor of the assoc AP */
697 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe+sizeof(struct rtw_ieee80211_hdr_3addr), len-sizeof(struct rtw_ieee80211_hdr_3addr));
698
699 /* update TSF Value */
700 update_TSF(pmlmeext, pframe, len);
701
702 /* start auth */
703 start_clnt_auth(padapter);
704
705 return _SUCCESS;
706 }
707
708 if (((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
709 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
710 if (psta != NULL) {
711 ret = rtw_check_bcn_info(padapter, pframe, len);
712 if (!ret) {
713 DBG_88E_LEVEL(_drv_info_, "ap has changed, disconnect now\n ");
714 receive_disconnect(padapter, pmlmeinfo->network.MacAddress , 65535);
715 return _SUCCESS;
716 }
717 /* update WMM, ERP in the beacon */
718 /* todo: the timer is used instead of the number of the beacon received */
719 if ((sta_rx_pkts(psta) & 0xf) == 0)
720 update_beacon_info(padapter, pframe, len, psta);
721 process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
722 }
723 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
724 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
725 if (psta != NULL) {
726 /* update WMM, ERP in the beacon */
727 /* todo: the timer is used instead of the number of the beacon received */
728 if ((sta_rx_pkts(psta) & 0xf) == 0)
729 update_beacon_info(padapter, pframe, len, psta);
730 } else {
731 /* allocate a new CAM entry for IBSS station */
732 cam_idx = allocate_fw_sta_entry(padapter);
733 if (cam_idx == NUM_STA)
734 goto _END_ONBEACON_;
735
736 /* get supported rate */
737 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) {
738 pmlmeinfo->FW_sta_info[cam_idx].status = 0;
739 goto _END_ONBEACON_;
740 }
741
742 /* update TSF Value */
743 update_TSF(pmlmeext, pframe, len);
744
745 /* report sta add event */
746 report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
747 }
748 }
749 }
750
751 _END_ONBEACON_:
752
753 return _SUCCESS;
754 }
755
756 unsigned int OnAuth(struct adapter *padapter, struct recv_frame *precv_frame)
757 {
758 #ifdef CONFIG_88EU_AP_MODE
759 unsigned int auth_mode, ie_len;
760 u16 seq;
761 unsigned char *sa, *p;
762 u16 algorithm;
763 int status;
764 static struct sta_info stat;
765 struct sta_info *pstat = NULL;
766 struct sta_priv *pstapriv = &padapter->stapriv;
767 struct security_priv *psecuritypriv = &padapter->securitypriv;
768 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
769 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
770 u8 *pframe = precv_frame->rx_data;
771 uint len = precv_frame->len;
772
773 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
774 return _FAIL;
775
776 DBG_88E("+OnAuth\n");
777
778 sa = GetAddr2Ptr(pframe);
779
780 auth_mode = psecuritypriv->dot11AuthAlgrthm;
781 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + 2));
782 algorithm = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN));
783
784 DBG_88E("auth alg=%x, seq=%X\n", algorithm, seq);
785
786 if (auth_mode == 2 && psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
787 psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
788 auth_mode = 0;
789
790 if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */
791 (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */
792 DBG_88E("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
793 algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
794
795 status = _STATS_NO_SUPP_ALG_;
796
797 goto auth_fail;
798 }
799
800 if (!rtw_access_ctrl(padapter, sa)) {
801 status = _STATS_UNABLE_HANDLE_STA_;
802 goto auth_fail;
803 }
804
805 pstat = rtw_get_stainfo(pstapriv, sa);
806 if (pstat == NULL) {
807 /* allocate a new one */
808 DBG_88E("going to alloc stainfo for sa=%pM\n", sa);
809 pstat = rtw_alloc_stainfo(pstapriv, sa);
810 if (pstat == NULL) {
811 DBG_88E(" Exceed the upper limit of supported clients...\n");
812 status = _STATS_UNABLE_HANDLE_STA_;
813 goto auth_fail;
814 }
815
816 pstat->state = WIFI_FW_AUTH_NULL;
817 pstat->auth_seq = 0;
818 } else {
819 spin_lock_bh(&pstapriv->asoc_list_lock);
820 if (!list_empty(&pstat->asoc_list)) {
821 rtw_list_delete(&pstat->asoc_list);
822 pstapriv->asoc_list_cnt--;
823 }
824 spin_unlock_bh(&pstapriv->asoc_list_lock);
825
826 if (seq == 1) {
827 /* TODO: STA re_auth and auth timeout */
828 }
829 }
830
831 spin_lock_bh(&pstapriv->auth_list_lock);
832 if (list_empty(&pstat->auth_list)) {
833 list_add_tail(&pstat->auth_list, &pstapriv->auth_list);
834 pstapriv->auth_list_cnt++;
835 }
836 spin_unlock_bh(&pstapriv->auth_list_lock);
837
838 if (pstat->auth_seq == 0)
839 pstat->expire_to = pstapriv->auth_to;
840
841 if ((pstat->auth_seq + 1) != seq) {
842 DBG_88E("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
843 seq, pstat->auth_seq+1);
844 status = _STATS_OUT_OF_AUTH_SEQ_;
845 goto auth_fail;
846 }
847
848 if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2)) {
849 if (seq == 1) {
850 pstat->state &= ~WIFI_FW_AUTH_NULL;
851 pstat->state |= WIFI_FW_AUTH_SUCCESS;
852 pstat->expire_to = pstapriv->assoc_to;
853 pstat->authalg = algorithm;
854 } else {
855 DBG_88E("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
856 seq, pstat->auth_seq+1);
857 status = _STATS_OUT_OF_AUTH_SEQ_;
858 goto auth_fail;
859 }
860 } else { /* shared system or auto authentication */
861 if (seq == 1) {
862 /* prepare for the challenging txt... */
863
864 pstat->state &= ~WIFI_FW_AUTH_NULL;
865 pstat->state |= WIFI_FW_AUTH_STATE;
866 pstat->authalg = algorithm;
867 pstat->auth_seq = 2;
868 } else if (seq == 3) {
869 /* checking for challenging txt... */
870 DBG_88E("checking for challenging txt...\n");
871
872 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_ , _CHLGETXT_IE_, (int *)&ie_len,
873 len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
874
875 if ((p == NULL) || (ie_len <= 0)) {
876 DBG_88E("auth rejected because challenge failure!(1)\n");
877 status = _STATS_CHALLENGE_FAIL_;
878 goto auth_fail;
879 }
880
881 if (!memcmp((void *)(p + 2), pstat->chg_txt, 128)) {
882 pstat->state &= (~WIFI_FW_AUTH_STATE);
883 pstat->state |= WIFI_FW_AUTH_SUCCESS;
884 /* challenging txt is correct... */
885 pstat->expire_to = pstapriv->assoc_to;
886 } else {
887 DBG_88E("auth rejected because challenge failure!\n");
888 status = _STATS_CHALLENGE_FAIL_;
889 goto auth_fail;
890 }
891 } else {
892 DBG_88E("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
893 seq, pstat->auth_seq+1);
894 status = _STATS_OUT_OF_AUTH_SEQ_;
895 goto auth_fail;
896 }
897 }
898
899 /* Now, we are going to issue_auth... */
900 pstat->auth_seq = seq + 1;
901
902 #ifdef CONFIG_88EU_AP_MODE
903 issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
904 #endif
905
906 if (pstat->state & WIFI_FW_AUTH_SUCCESS)
907 pstat->auth_seq = 0;
908
909 return _SUCCESS;
910
911 auth_fail:
912
913 if (pstat)
914 rtw_free_stainfo(padapter , pstat);
915
916 pstat = &stat;
917 memset((char *)pstat, '\0', sizeof(stat));
918 pstat->auth_seq = 2;
919 memcpy(pstat->hwaddr, sa, 6);
920
921 #ifdef CONFIG_88EU_AP_MODE
922 issue_auth(padapter, pstat, (unsigned short)status);
923 #endif
924
925 #endif
926 return _FAIL;
927 }
928
929 unsigned int OnAuthClient(struct adapter *padapter, struct recv_frame *precv_frame)
930 {
931 unsigned int seq, len, status, offset;
932 unsigned char *p;
933 unsigned int go2asoc = 0;
934 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
935 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
936 u8 *pframe = precv_frame->rx_data;
937 uint pkt_len = precv_frame->len;
938
939 DBG_88E("%s\n", __func__);
940
941 /* check A1 matches or not */
942 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
943 return _SUCCESS;
944
945 if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
946 return _SUCCESS;
947
948 offset = (GetPrivacy(pframe)) ? 4 : 0;
949
950 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 2));
951 status = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 4));
952
953 if (status != 0) {
954 DBG_88E("clnt auth fail, status: %d\n", status);
955 if (status == 13) { /* pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto) */
956 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
957 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
958 else
959 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
960 }
961
962 set_link_timer(pmlmeext, 1);
963 goto authclnt_fail;
964 }
965
966 if (seq == 2) {
967 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
968 /* legendary shared system */
969 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
970 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
971
972 if (p == NULL)
973 goto authclnt_fail;
974
975 memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
976 pmlmeinfo->auth_seq = 3;
977 issue_auth(padapter, NULL, 0);
978 set_link_timer(pmlmeext, REAUTH_TO);
979
980 return _SUCCESS;
981 } else {
982 /* open system */
983 go2asoc = 1;
984 }
985 } else if (seq == 4) {
986 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
987 go2asoc = 1;
988 else
989 goto authclnt_fail;
990 } else {
991 /* this is also illegal */
992 goto authclnt_fail;
993 }
994
995 if (go2asoc) {
996 DBG_88E_LEVEL(_drv_info_, "auth success, start assoc\n");
997 start_clnt_assoc(padapter);
998 return _SUCCESS;
999 }
1000 authclnt_fail:
1001 return _FAIL;
1002 }
1003
1004 unsigned int OnAssocReq(struct adapter *padapter, struct recv_frame *precv_frame)
1005 {
1006 #ifdef CONFIG_88EU_AP_MODE
1007 u16 capab_info;
1008 struct rtw_ieee802_11_elems elems;
1009 struct sta_info *pstat;
1010 unsigned char reassoc, *p, *pos, *wpa_ie;
1011 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
1012 int i, ie_len, wpa_ie_len, left;
1013 unsigned char supportRate[16];
1014 int supportRateNum;
1015 unsigned short status = _STATS_SUCCESSFUL_;
1016 unsigned short frame_type, ie_offset = 0;
1017 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1018 struct security_priv *psecuritypriv = &padapter->securitypriv;
1019 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1020 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1021 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
1022 struct sta_priv *pstapriv = &padapter->stapriv;
1023 u8 *pframe = precv_frame->rx_data;
1024 uint pkt_len = precv_frame->len;
1025 #ifdef CONFIG_88EU_P2P
1026 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1027 u8 p2p_status_code = P2P_STATUS_SUCCESS;
1028 u8 *p2pie;
1029 u32 p2pielen = 0;
1030 #endif /* CONFIG_88EU_P2P */
1031
1032 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1033 return _FAIL;
1034
1035 frame_type = GetFrameSubType(pframe);
1036 if (frame_type == WIFI_ASSOCREQ) {
1037 reassoc = 0;
1038 ie_offset = _ASOCREQ_IE_OFFSET_;
1039 } else { /* WIFI_REASSOCREQ */
1040 reassoc = 1;
1041 ie_offset = _REASOCREQ_IE_OFFSET_;
1042 }
1043
1044
1045 if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
1046 DBG_88E("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1047 "\n", reassoc, (unsigned long)pkt_len);
1048 return _FAIL;
1049 }
1050
1051 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1052 if (pstat == (struct sta_info *)NULL) {
1053 status = _RSON_CLS2_;
1054 goto asoc_class2_error;
1055 }
1056
1057 capab_info = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN);
1058
1059 left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
1060 pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
1061
1062
1063 DBG_88E("%s\n", __func__);
1064
1065 /* check if this stat has been successfully authenticated/assocated */
1066 if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) {
1067 if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) {
1068 status = _RSON_CLS2_;
1069 goto asoc_class2_error;
1070 } else {
1071 pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
1072 pstat->state |= WIFI_FW_ASSOC_STATE;
1073 }
1074 } else {
1075 pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
1076 pstat->state |= WIFI_FW_ASSOC_STATE;
1077 }
1078 pstat->capability = capab_info;
1079 /* now parse all ieee802_11 ie to point to elems */
1080 if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
1081 !elems.ssid) {
1082 DBG_88E("STA %pM sent invalid association request\n",
1083 pstat->hwaddr);
1084 status = _STATS_FAILURE_;
1085 goto OnAssocReqFail;
1086 }
1087
1088
1089 /* now we should check all the fields... */
1090 /* checking SSID */
1091 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
1092 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1093 if (p == NULL)
1094 status = _STATS_FAILURE_;
1095
1096 if (ie_len == 0) { /* broadcast ssid, however it is not allowed in assocreq */
1097 status = _STATS_FAILURE_;
1098 } else {
1099 /* check if ssid match */
1100 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
1101 status = _STATS_FAILURE_;
1102
1103 if (ie_len != cur->Ssid.SsidLength)
1104 status = _STATS_FAILURE_;
1105 }
1106
1107 if (_STATS_SUCCESSFUL_ != status)
1108 goto OnAssocReqFail;
1109
1110 /* check if the supported rate is ok */
1111 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SUPPORTEDRATES_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1112 if (p == NULL) {
1113 DBG_88E("Rx a sta assoc-req which supported rate is empty!\n");
1114 /* use our own rate set as statoin used */
1115 /* memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN); */
1116 /* supportRateNum = AP_BSSRATE_LEN; */
1117
1118 status = _STATS_FAILURE_;
1119 goto OnAssocReqFail;
1120 } else {
1121 memcpy(supportRate, p+2, ie_len);
1122 supportRateNum = ie_len;
1123
1124 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _EXT_SUPPORTEDRATES_IE_ , &ie_len,
1125 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1126 if (p != NULL) {
1127 if (supportRateNum <= sizeof(supportRate)) {
1128 memcpy(supportRate+supportRateNum, p+2, ie_len);
1129 supportRateNum += ie_len;
1130 }
1131 }
1132 }
1133
1134 /* todo: mask supportRate between AP & STA -> move to update raid */
1135 /* get_matched_rate(pmlmeext, supportRate, &supportRateNum, 0); */
1136
1137 /* update station supportRate */
1138 pstat->bssratelen = supportRateNum;
1139 memcpy(pstat->bssrateset, supportRate, supportRateNum);
1140 UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
1141
1142 /* check RSN/WPA/WPS */
1143 pstat->dot8021xalg = 0;
1144 pstat->wpa_psk = 0;
1145 pstat->wpa_group_cipher = 0;
1146 pstat->wpa2_group_cipher = 0;
1147 pstat->wpa_pairwise_cipher = 0;
1148 pstat->wpa2_pairwise_cipher = 0;
1149 memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
1150 if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
1151 int group_cipher = 0, pairwise_cipher = 0;
1152
1153 wpa_ie = elems.rsn_ie;
1154 wpa_ie_len = elems.rsn_ie_len;
1155
1156 if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1157 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1158 pstat->wpa_psk |= BIT(1);
1159
1160 pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
1161 pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
1162
1163 if (!pstat->wpa2_group_cipher)
1164 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1165
1166 if (!pstat->wpa2_pairwise_cipher)
1167 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1168 } else {
1169 status = WLAN_STATUS_INVALID_IE;
1170 }
1171 } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
1172 int group_cipher = 0, pairwise_cipher = 0;
1173
1174 wpa_ie = elems.wpa_ie;
1175 wpa_ie_len = elems.wpa_ie_len;
1176
1177 if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1178 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1179 pstat->wpa_psk |= BIT(0);
1180
1181 pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
1182 pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
1183
1184 if (!pstat->wpa_group_cipher)
1185 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1186
1187 if (!pstat->wpa_pairwise_cipher)
1188 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1189 } else {
1190 status = WLAN_STATUS_INVALID_IE;
1191 }
1192 } else {
1193 wpa_ie = NULL;
1194 wpa_ie_len = 0;
1195 }
1196
1197 if (_STATS_SUCCESSFUL_ != status)
1198 goto OnAssocReqFail;
1199
1200 pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
1201 if (wpa_ie == NULL) {
1202 if (elems.wps_ie) {
1203 DBG_88E("STA included WPS IE in "
1204 "(Re)Association Request - assume WPS is "
1205 "used\n");
1206 pstat->flags |= WLAN_STA_WPS;
1207 /* wpabuf_free(sta->wps_ie); */
1208 /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
1209 /* elems.wps_ie_len - 4); */
1210 } else {
1211 DBG_88E("STA did not include WPA/RSN IE "
1212 "in (Re)Association Request - possible WPS "
1213 "use\n");
1214 pstat->flags |= WLAN_STA_MAYBE_WPS;
1215 }
1216
1217
1218 /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
1219 /* that the selected registrar of AP is _FLASE */
1220 if ((psecuritypriv->wpa_psk > 0) && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
1221 if (pmlmepriv->wps_beacon_ie) {
1222 u8 selected_registrar = 0;
1223
1224 rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR , &selected_registrar, NULL);
1225
1226 if (!selected_registrar) {
1227 DBG_88E("selected_registrar is false , or AP is not ready to do WPS\n");
1228
1229 status = _STATS_UNABLE_HANDLE_STA_;
1230
1231 goto OnAssocReqFail;
1232 }
1233 }
1234 }
1235 } else {
1236 int copy_len;
1237
1238 if (psecuritypriv->wpa_psk == 0) {
1239 DBG_88E("STA %pM: WPA/RSN IE in association "
1240 "request, but AP don't support WPA/RSN\n", pstat->hwaddr);
1241
1242 status = WLAN_STATUS_INVALID_IE;
1243
1244 goto OnAssocReqFail;
1245 }
1246
1247 if (elems.wps_ie) {
1248 DBG_88E("STA included WPS IE in "
1249 "(Re)Association Request - WPS is "
1250 "used\n");
1251 pstat->flags |= WLAN_STA_WPS;
1252 copy_len = 0;
1253 } else {
1254 copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len+2);
1255 }
1256 if (copy_len > 0)
1257 memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
1258 }
1259 /* check if there is WMM IE & support WWM-PS */
1260 pstat->flags &= ~WLAN_STA_WME;
1261 pstat->qos_option = 0;
1262 pstat->qos_info = 0;
1263 pstat->has_legacy_ac = true;
1264 pstat->uapsd_vo = 0;
1265 pstat->uapsd_vi = 0;
1266 pstat->uapsd_be = 0;
1267 pstat->uapsd_bk = 0;
1268 if (pmlmepriv->qospriv.qos_option) {
1269 p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
1270 for (;;) {
1271 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1272 if (p != NULL) {
1273 if (!memcmp(p+2, WMM_IE, 6)) {
1274 pstat->flags |= WLAN_STA_WME;
1275
1276 pstat->qos_option = 1;
1277 pstat->qos_info = *(p+8);
1278
1279 pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
1280
1281 if ((pstat->qos_info&0xf) != 0xf)
1282 pstat->has_legacy_ac = true;
1283 else
1284 pstat->has_legacy_ac = false;
1285
1286 if (pstat->qos_info&0xf) {
1287 if (pstat->qos_info&BIT(0))
1288 pstat->uapsd_vo = BIT(0)|BIT(1);
1289 else
1290 pstat->uapsd_vo = 0;
1291
1292 if (pstat->qos_info&BIT(1))
1293 pstat->uapsd_vi = BIT(0)|BIT(1);
1294 else
1295 pstat->uapsd_vi = 0;
1296
1297 if (pstat->qos_info&BIT(2))
1298 pstat->uapsd_bk = BIT(0)|BIT(1);
1299 else
1300 pstat->uapsd_bk = 0;
1301
1302 if (pstat->qos_info&BIT(3))
1303 pstat->uapsd_be = BIT(0)|BIT(1);
1304 else
1305 pstat->uapsd_be = 0;
1306 }
1307 break;
1308 }
1309 } else {
1310 break;
1311 }
1312 p = p + ie_len + 2;
1313 }
1314 }
1315
1316 /* save HT capabilities in the sta object */
1317 memset(&pstat->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
1318 if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
1319 pstat->flags |= WLAN_STA_HT;
1320
1321 pstat->flags |= WLAN_STA_WME;
1322
1323 memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
1324 } else {
1325 pstat->flags &= ~WLAN_STA_HT;
1326 }
1327 if ((!pmlmepriv->htpriv.ht_option) && (pstat->flags&WLAN_STA_HT)) {
1328 status = _STATS_FAILURE_;
1329 goto OnAssocReqFail;
1330 }
1331
1332 if ((pstat->flags & WLAN_STA_HT) &&
1333 ((pstat->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
1334 (pstat->wpa_pairwise_cipher&WPA_CIPHER_TKIP))) {
1335 DBG_88E("HT: %pM tried to "
1336 "use TKIP with HT association\n", pstat->hwaddr);
1337
1338 /* status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; */
1339 /* goto OnAssocReqFail; */
1340 }
1341
1342 pstat->flags |= WLAN_STA_NONERP;
1343 for (i = 0; i < pstat->bssratelen; i++) {
1344 if ((pstat->bssrateset[i] & 0x7f) > 22) {
1345 pstat->flags &= ~WLAN_STA_NONERP;
1346 break;
1347 }
1348 }
1349
1350 if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1351 pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
1352 else
1353 pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1354
1355
1356
1357 if (status != _STATS_SUCCESSFUL_)
1358 goto OnAssocReqFail;
1359
1360 #ifdef CONFIG_88EU_P2P
1361 pstat->is_p2p_device = false;
1362 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
1363 p2pie = rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + ie_offset , pkt_len - WLAN_HDR_A3_LEN - ie_offset , NULL, &p2pielen);
1364 if (p2pie) {
1365 pstat->is_p2p_device = true;
1366 p2p_status_code = (u8)process_assoc_req_p2p_ie(pwdinfo, pframe, pkt_len, pstat);
1367 if (p2p_status_code > 0) {
1368 pstat->p2p_status_code = p2p_status_code;
1369 status = _STATS_CAP_FAIL_;
1370 goto OnAssocReqFail;
1371 }
1372 }
1373 }
1374 pstat->p2p_status_code = p2p_status_code;
1375 #endif /* CONFIG_88EU_P2P */
1376
1377 /* TODO: identify_proprietary_vendor_ie(); */
1378 /* Realtek proprietary IE */
1379 /* identify if this is Broadcom sta */
1380 /* identify if this is ralink sta */
1381 /* Customer proprietary IE */
1382
1383 /* get a unique AID */
1384 if (pstat->aid > 0) {
1385 DBG_88E(" old AID %d\n", pstat->aid);
1386 } else {
1387 for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++)
1388 if (pstapriv->sta_aid[pstat->aid - 1] == NULL)
1389 break;
1390
1391 /* if (pstat->aid > NUM_STA) { */
1392 if (pstat->aid > pstapriv->max_num_sta) {
1393 pstat->aid = 0;
1394
1395 DBG_88E(" no room for more AIDs\n");
1396
1397 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1398
1399 goto OnAssocReqFail;
1400 } else {
1401 pstapriv->sta_aid[pstat->aid - 1] = pstat;
1402 DBG_88E("allocate new AID=(%d)\n", pstat->aid);
1403 }
1404 }
1405
1406 pstat->state &= (~WIFI_FW_ASSOC_STATE);
1407 pstat->state |= WIFI_FW_ASSOC_SUCCESS;
1408
1409 spin_lock_bh(&pstapriv->auth_list_lock);
1410 if (!list_empty(&pstat->auth_list)) {
1411 rtw_list_delete(&pstat->auth_list);
1412 pstapriv->auth_list_cnt--;
1413 }
1414 spin_unlock_bh(&pstapriv->auth_list_lock);
1415
1416 spin_lock_bh(&pstapriv->asoc_list_lock);
1417 if (list_empty(&pstat->asoc_list)) {
1418 pstat->expire_to = pstapriv->expire_to;
1419 list_add_tail(&pstat->asoc_list, &pstapriv->asoc_list);
1420 pstapriv->asoc_list_cnt++;
1421 }
1422 spin_unlock_bh(&pstapriv->asoc_list_lock);
1423
1424 /* now the station is qualified to join our BSS... */
1425 if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
1426 #ifdef CONFIG_88EU_AP_MODE
1427 /* 1 bss_cap_update & sta_info_update */
1428 bss_cap_update_on_sta_join(padapter, pstat);
1429 sta_info_update(padapter, pstat);
1430
1431 /* issue assoc rsp before notify station join event. */
1432 if (frame_type == WIFI_ASSOCREQ)
1433 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1434 else
1435 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1436
1437 /* 2 - report to upper layer */
1438 DBG_88E("indicate_sta_join_event to upper layer - hostapd\n");
1439 rtw_indicate_sta_assoc_event(padapter, pstat);
1440
1441 /* 3-(1) report sta add event */
1442 report_add_sta_event(padapter, pstat->hwaddr, pstat->aid);
1443 #endif
1444 }
1445
1446 return _SUCCESS;
1447
1448 asoc_class2_error:
1449
1450 #ifdef CONFIG_88EU_AP_MODE
1451 issue_deauth(padapter, (void *)GetAddr2Ptr(pframe), status);
1452 #endif
1453
1454 return _FAIL;
1455
1456 OnAssocReqFail:
1457
1458
1459 #ifdef CONFIG_88EU_AP_MODE
1460 pstat->aid = 0;
1461 if (frame_type == WIFI_ASSOCREQ)
1462 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1463 else
1464 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1465 #endif
1466
1467
1468 #endif /* CONFIG_88EU_AP_MODE */
1469
1470 return _FAIL;
1471 }
1472
1473 unsigned int OnAssocRsp(struct adapter *padapter, struct recv_frame *precv_frame)
1474 {
1475 uint i;
1476 int res;
1477 unsigned short status;
1478 struct ndis_802_11_var_ie *pIE;
1479 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1480 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1481 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1482 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */
1483 u8 *pframe = precv_frame->rx_data;
1484 uint pkt_len = precv_frame->len;
1485
1486 DBG_88E("%s\n", __func__);
1487
1488 /* check A1 matches or not */
1489 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
1490 return _SUCCESS;
1491
1492 if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
1493 return _SUCCESS;
1494
1495 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
1496 return _SUCCESS;
1497
1498 _cancel_timer_ex(&pmlmeext->link_timer);
1499
1500 /* status */
1501 status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2));
1502 if (status > 0) {
1503 DBG_88E("assoc reject, status code: %d\n", status);
1504 pmlmeinfo->state = WIFI_FW_NULL_STATE;
1505 res = -4;
1506 goto report_assoc_result;
1507 }
1508
1509 /* get capabilities */
1510 pmlmeinfo->capability = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1511
1512 /* set slot time */
1513 pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20;
1514
1515 /* AID */
1516 pmlmeinfo->aid = (int)(le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 4))&0x3fff);
1517 res = pmlmeinfo->aid;
1518
1519 /* following are moved to join event callback function */
1520 /* to handle HT, WMM, rate adaptive, update MAC reg */
1521 /* for not to handle the synchronous IO in the tasklet */
1522 for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
1523 pIE = (struct ndis_802_11_var_ie *)(pframe + i);
1524
1525 switch (pIE->ElementID) {
1526 case _VENDOR_SPECIFIC_IE_:
1527 if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
1528 WMM_param_handler(padapter, pIE);
1529 break;
1530 case _HT_CAPABILITY_IE_: /* HT caps */
1531 HT_caps_handler(padapter, pIE);
1532 break;
1533 case _HT_EXTRA_INFO_IE_: /* HT info */
1534 HT_info_handler(padapter, pIE);
1535 break;
1536 case _ERPINFO_IE_:
1537 ERP_IE_handler(padapter, pIE);
1538 default:
1539 break;
1540 }
1541
1542 i += (pIE->Length + 2);
1543 }
1544
1545 pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
1546 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
1547
1548 /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
1549 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
1550
1551 report_assoc_result:
1552 if (res > 0) {
1553 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
1554 } else {
1555 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
1556 }
1557
1558 report_join_res(padapter, res);
1559
1560 return _SUCCESS;
1561 }
1562
1563 unsigned int OnDeAuth(struct adapter *padapter, struct recv_frame *precv_frame)
1564 {
1565 unsigned short reason;
1566 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1567 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1568 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1569 u8 *pframe = precv_frame->rx_data;
1570 #ifdef CONFIG_88EU_P2P
1571 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1572 #endif /* CONFIG_88EU_P2P */
1573
1574 /* check A3 */
1575 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1576 ETH_ALEN))
1577 return _SUCCESS;
1578
1579 #ifdef CONFIG_88EU_P2P
1580 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1581 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1582 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1583 }
1584 #endif /* CONFIG_88EU_P2P */
1585
1586 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1587
1588 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1589
1590 #ifdef CONFIG_88EU_AP_MODE
1591 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1592 struct sta_info *psta;
1593 struct sta_priv *pstapriv = &padapter->stapriv;
1594
1595 DBG_88E_LEVEL(_drv_always_, "ap recv deauth reason code(%d) sta:%pM\n",
1596 reason, GetAddr2Ptr(pframe));
1597
1598 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1599 if (psta) {
1600 u8 updated = 0;
1601
1602 spin_lock_bh(&pstapriv->asoc_list_lock);
1603 if (!list_empty(&psta->asoc_list)) {
1604 rtw_list_delete(&psta->asoc_list);
1605 pstapriv->asoc_list_cnt--;
1606 updated = ap_free_sta(padapter, psta, false, reason);
1607 }
1608 spin_unlock_bh(&pstapriv->asoc_list_lock);
1609
1610 associated_clients_update(padapter, updated);
1611 }
1612
1613
1614 return _SUCCESS;
1615 } else
1616 #endif
1617 {
1618 DBG_88E_LEVEL(_drv_always_, "sta recv deauth reason code(%d) sta:%pM\n",
1619 reason, GetAddr3Ptr(pframe));
1620
1621 receive_disconnect(padapter, GetAddr3Ptr(pframe) , reason);
1622 }
1623 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1624 return _SUCCESS;
1625 }
1626
1627 unsigned int OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
1628 {
1629 u16 reason;
1630 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1631 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1632 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1633 u8 *pframe = precv_frame->rx_data;
1634 #ifdef CONFIG_88EU_P2P
1635 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1636 #endif /* CONFIG_88EU_P2P */
1637
1638 /* check A3 */
1639 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1640 ETH_ALEN))
1641 return _SUCCESS;
1642
1643 #ifdef CONFIG_88EU_P2P
1644 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1645 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1646 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1647 }
1648 #endif /* CONFIG_88EU_P2P */
1649
1650 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1651
1652 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1653
1654 #ifdef CONFIG_88EU_AP_MODE
1655 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1656 struct sta_info *psta;
1657 struct sta_priv *pstapriv = &padapter->stapriv;
1658
1659 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1660 reason, GetAddr2Ptr(pframe));
1661
1662 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1663 if (psta) {
1664 u8 updated = 0;
1665
1666 spin_lock_bh(&pstapriv->asoc_list_lock);
1667 if (!list_empty(&psta->asoc_list)) {
1668 rtw_list_delete(&psta->asoc_list);
1669 pstapriv->asoc_list_cnt--;
1670 updated = ap_free_sta(padapter, psta, false, reason);
1671 }
1672 spin_unlock_bh(&pstapriv->asoc_list_lock);
1673
1674 associated_clients_update(padapter, updated);
1675 }
1676
1677 return _SUCCESS;
1678 } else
1679 #endif
1680 {
1681 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1682 reason, GetAddr3Ptr(pframe));
1683
1684 receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
1685 }
1686 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1687 return _SUCCESS;
1688 }
1689
1690 unsigned int OnAtim(struct adapter *padapter, struct recv_frame *precv_frame)
1691 {
1692 DBG_88E("%s\n", __func__);
1693 return _SUCCESS;
1694 }
1695
1696 unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame)
1697 {
1698 unsigned int ret = _FAIL;
1699 struct sta_info *psta = NULL;
1700 struct sta_priv *pstapriv = &padapter->stapriv;
1701 u8 *pframe = precv_frame->rx_data;
1702 u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1703 u8 category;
1704 u8 action;
1705
1706 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1707
1708 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1709
1710 if (!psta)
1711 goto exit;
1712
1713 category = frame_body[0];
1714 if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
1715 goto exit;
1716
1717 action = frame_body[1];
1718 switch (action) {
1719 case RTW_WLAN_ACTION_SPCT_MSR_REQ:
1720 case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
1721 case RTW_WLAN_ACTION_SPCT_TPC_REQ:
1722 case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
1723 break;
1724 case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
1725 break;
1726 default:
1727 break;
1728 }
1729
1730 exit:
1731 return ret;
1732 }
1733
1734 unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame)
1735 {
1736 return _SUCCESS;
1737 }
1738
1739 unsigned int OnAction_dls(struct adapter *padapter, struct recv_frame *precv_frame)
1740 {
1741 return _SUCCESS;
1742 }
1743
1744 unsigned int OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
1745 {
1746 u8 *addr;
1747 struct sta_info *psta = NULL;
1748 struct recv_reorder_ctrl *preorder_ctrl;
1749 unsigned char *frame_body;
1750 unsigned char category, action;
1751 unsigned short tid, status, reason_code = 0;
1752 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1753 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1754 u8 *pframe = precv_frame->rx_data;
1755 struct sta_priv *pstapriv = &padapter->stapriv;
1756 /* check RA matches or not */
1757 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe),
1758 ETH_ALEN))/* for if1, sta/ap mode */
1759 return _SUCCESS;
1760
1761 DBG_88E("%s\n", __func__);
1762
1763 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1764 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
1765 return _SUCCESS;
1766
1767 addr = GetAddr2Ptr(pframe);
1768 psta = rtw_get_stainfo(pstapriv, addr);
1769
1770 if (psta == NULL)
1771 return _SUCCESS;
1772
1773 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1774
1775 category = frame_body[0];
1776 if (category == RTW_WLAN_CATEGORY_BACK) { /* representing Block Ack */
1777 if (!pmlmeinfo->HT_enable)
1778 return _SUCCESS;
1779 action = frame_body[1];
1780 DBG_88E("%s, action=%d\n", __func__, action);
1781 switch (action) {
1782 case RTW_WLAN_ACTION_ADDBA_REQ: /* ADDBA request */
1783 memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
1784 process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr);
1785
1786 if (pmlmeinfo->bAcceptAddbaReq)
1787 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 0);
1788 else
1789 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 37);/* reject ADDBA Req */
1790 break;
1791 case RTW_WLAN_ACTION_ADDBA_RESP: /* ADDBA response */
1792 status = RTW_GET_LE16(&frame_body[3]);
1793 tid = ((frame_body[5] >> 2) & 0x7);
1794 if (status == 0) { /* successful */
1795 DBG_88E("agg_enable for TID=%d\n", tid);
1796 psta->htpriv.agg_enable_bitmap |= 1 << tid;
1797 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
1798 } else {
1799 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
1800 }
1801 break;
1802 case RTW_WLAN_ACTION_DELBA: /* DELBA */
1803 if ((frame_body[3] & BIT(3)) == 0) {
1804 psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1805 psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1806 reason_code = RTW_GET_LE16(&frame_body[4]);
1807 } else if ((frame_body[3] & BIT(3)) == BIT(3)) {
1808 tid = (frame_body[3] >> 4) & 0x0F;
1809 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1810 preorder_ctrl->enable = false;
1811 preorder_ctrl->indicate_seq = 0xffff;
1812 }
1813 DBG_88E("%s(): DELBA: %x(%x)\n", __func__, pmlmeinfo->agg_enable_bitmap, reason_code);
1814 /* todo: how to notify the host while receiving DELETE BA */
1815 break;
1816 default:
1817 break;
1818 }
1819 }
1820 return _SUCCESS;
1821 }
1822
1823 #ifdef CONFIG_88EU_P2P
1824
1825 static int get_reg_classes_full_count(struct p2p_channels *channel_list)
1826 {
1827 int cnt = 0;
1828 int i;
1829
1830 for (i = 0; i < channel_list->reg_classes; i++) {
1831 cnt += channel_list->reg_class[i].channels;
1832 }
1833
1834 return cnt;
1835 }
1836
1837 void issue_p2p_GO_request(struct adapter *padapter, u8 *raddr)
1838 {
1839 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
1840 u8 action = P2P_PUB_ACTION_ACTION;
1841 __be32 p2poui = cpu_to_be32(P2POUI);
1842 u8 oui_subtype = P2P_GO_NEGO_REQ;
1843 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
1844 u8 wpsielen = 0, p2pielen = 0;
1845 u16 len_channellist_attr = 0;
1846 struct xmit_frame *pmgntframe;
1847 struct pkt_attrib *pattrib;
1848 unsigned char *pframe;
1849 struct rtw_ieee80211_hdr *pwlanhdr;
1850 __le16 *fctrl;
1851 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1852 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1853 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1854
1855 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1856 if (pmgntframe == NULL)
1857 return;
1858
1859 DBG_88E("[%s] In\n", __func__);
1860 /* update attribute */
1861 pattrib = &pmgntframe->attrib;
1862 update_mgntframe_attrib(padapter, pattrib);
1863
1864 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
1865
1866 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
1867 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
1868
1869 fctrl = &(pwlanhdr->frame_ctl);
1870 *(fctrl) = 0;
1871
1872 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
1873 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
1874 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
1875
1876 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
1877 pmlmeext->mgnt_seq++;
1878 SetFrameSubType(pframe, WIFI_ACTION);
1879
1880 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
1881 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
1882
1883 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
1884 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
1885 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
1886 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
1887 pwdinfo->negotiation_dialog_token = 1; /* Initialize the dialog value */
1888 pframe = rtw_set_fixed_ie(pframe, 1, &pwdinfo->negotiation_dialog_token, &(pattrib->pktlen));
1889
1890
1891
1892 /* WPS Section */
1893 wpsielen = 0;
1894 /* WPS OUI */
1895 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
1896 wpsielen += 4;
1897
1898 /* WPS version */
1899 /* Type: */
1900 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
1901 wpsielen += 2;
1902
1903 /* Length: */
1904 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
1905 wpsielen += 2;
1906
1907 /* Value: */
1908 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
1909
1910 /* Device Password ID */
1911 /* Type: */
1912 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
1913 wpsielen += 2;
1914
1915 /* Length: */
1916 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
1917 wpsielen += 2;
1918
1919 /* Value: */
1920
1921 if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN)
1922 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
1923 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN)
1924 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
1925 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC)
1926 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
1927
1928 wpsielen += 2;
1929
1930 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
1931
1932
1933 /* P2P IE Section. */
1934
1935 /* P2P OUI */
1936 p2pielen = 0;
1937 p2pie[p2pielen++] = 0x50;
1938 p2pie[p2pielen++] = 0x6F;
1939 p2pie[p2pielen++] = 0x9A;
1940 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
1941
1942 /* Commented by Albert 20110306 */
1943 /* According to the P2P Specification, the group negotiation request frame should contain 9 P2P attributes */
1944 /* 1. P2P Capability */
1945 /* 2. Group Owner Intent */
1946 /* 3. Configuration Timeout */
1947 /* 4. Listen Channel */
1948 /* 5. Extended Listen Timing */
1949 /* 6. Intended P2P Interface Address */
1950 /* 7. Channel List */
1951 /* 8. P2P Device Info */
1952 /* 9. Operating Channel */
1953
1954
1955 /* P2P Capability */
1956 /* Type: */
1957 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
1958
1959 /* Length: */
1960 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1961 p2pielen += 2;
1962
1963 /* Value: */
1964 /* Device Capability Bitmap, 1 byte */
1965 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
1966
1967 /* Group Capability Bitmap, 1 byte */
1968 if (pwdinfo->persistent_supported)
1969 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
1970 else
1971 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
1972
1973 /* Group Owner Intent */
1974 /* Type: */
1975 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
1976
1977 /* Length: */
1978 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
1979 p2pielen += 2;
1980
1981 /* Value: */
1982 /* Todo the tie breaker bit. */
1983 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
1984
1985 /* Configuration Timeout */
1986 /* Type: */
1987 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
1988
1989 /* Length: */
1990 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1991 p2pielen += 2;
1992
1993 /* Value: */
1994 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
1995 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
1996
1997
1998 /* Listen Channel */
1999 /* Type: */
2000 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
2001
2002 /* Length: */
2003 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2004 p2pielen += 2;
2005
2006 /* Value: */
2007 /* Country String */
2008 p2pie[p2pielen++] = 'X';
2009 p2pie[p2pielen++] = 'X';
2010
2011 /* The third byte should be set to 0x04. */
2012 /* Described in the "Operating Channel Attribute" section. */
2013 p2pie[p2pielen++] = 0x04;
2014
2015 /* Operating Class */
2016 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
2017
2018 /* Channel Number */
2019 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listening channel number */
2020
2021
2022 /* Extended Listen Timing ATTR */
2023 /* Type: */
2024 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
2025
2026 /* Length: */
2027 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
2028 p2pielen += 2;
2029
2030 /* Value: */
2031 /* Availability Period */
2032 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2033 p2pielen += 2;
2034
2035 /* Availability Interval */
2036 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2037 p2pielen += 2;
2038
2039
2040 /* Intended P2P Interface Address */
2041 /* Type: */
2042 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2043
2044 /* Length: */
2045 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2046 p2pielen += 2;
2047
2048 /* Value: */
2049 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2050 p2pielen += ETH_ALEN;
2051
2052
2053 /* Channel List */
2054 /* Type: */
2055 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2056
2057 /* Length: */
2058 /* Country String(3) */
2059 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2060 /* + number of channels in all classes */
2061 len_channellist_attr = 3
2062 + (1 + 1) * (u16)(pmlmeext->channel_list.reg_classes)
2063 + get_reg_classes_full_count(&pmlmeext->channel_list);
2064
2065 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2066 p2pielen += 2;
2067
2068 /* Value: */
2069 /* Country String */
2070 p2pie[p2pielen++] = 'X';
2071 p2pie[p2pielen++] = 'X';
2072
2073 /* The third byte should be set to 0x04. */
2074 /* Described in the "Operating Channel Attribute" section. */
2075 p2pie[p2pielen++] = 0x04;
2076
2077 /* Channel Entry List */
2078
2079 {
2080 int i, j;
2081 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2082 /* Operating Class */
2083 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2084
2085 /* Number of Channels */
2086 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2087
2088 /* Channel List */
2089 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2090 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2091 }
2092 }
2093 }
2094
2095 /* Device Info */
2096 /* Type: */
2097 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2098
2099 /* Length: */
2100 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2101 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2102 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2103 p2pielen += 2;
2104
2105 /* Value: */
2106 /* P2P Device Address */
2107 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2108 p2pielen += ETH_ALEN;
2109
2110 /* Config Method */
2111 /* This field should be big endian. Noted by P2P specification. */
2112
2113 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2114
2115 p2pielen += 2;
2116
2117 /* Primary Device Type */
2118 /* Category ID */
2119 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2120 p2pielen += 2;
2121
2122 /* OUI */
2123 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2124 p2pielen += 4;
2125
2126 /* Sub Category ID */
2127 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2128 p2pielen += 2;
2129
2130 /* Number of Secondary Device Types */
2131 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2132
2133 /* Device Name */
2134 /* Type: */
2135 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2136 p2pielen += 2;
2137
2138 /* Length: */
2139 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2140 p2pielen += 2;
2141
2142 /* Value: */
2143 memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
2144 p2pielen += pwdinfo->device_name_len;
2145
2146
2147 /* Operating Channel */
2148 /* Type: */
2149 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2150
2151 /* Length: */
2152 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2153 p2pielen += 2;
2154
2155 /* Value: */
2156 /* Country String */
2157 p2pie[p2pielen++] = 'X';
2158 p2pie[p2pielen++] = 'X';
2159
2160 /* The third byte should be set to 0x04. */
2161 /* Described in the "Operating Channel Attribute" section. */
2162 p2pie[p2pielen++] = 0x04;
2163
2164 /* Operating Class */
2165 p2pie[p2pielen++] = 0x51;
2166
2167 /* Channel Number */
2168 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2169
2170 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2171
2172 pattrib->last_txcmdsz = pattrib->pktlen;
2173
2174 dump_mgntframe(padapter, pmgntframe);
2175
2176 return;
2177 }
2178
2179 static void issue_p2p_GO_response(struct adapter *padapter, u8 *raddr, u8 *frame_body, uint len, u8 result)
2180 {
2181 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2182 u8 action = P2P_PUB_ACTION_ACTION;
2183 __be32 p2poui = cpu_to_be32(P2POUI);
2184 u8 oui_subtype = P2P_GO_NEGO_RESP;
2185 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
2186 u8 p2pielen = 0;
2187 uint wpsielen = 0;
2188 u16 wps_devicepassword_id = 0x0000;
2189 __be16 be_tmp;
2190 uint wps_devicepassword_id_len = 0;
2191 u16 len_channellist_attr = 0;
2192
2193 struct xmit_frame *pmgntframe;
2194 struct pkt_attrib *pattrib;
2195 unsigned char *pframe;
2196 struct rtw_ieee80211_hdr *pwlanhdr;
2197 __le16 *fctrl;
2198 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2199 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2200 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2201
2202 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2203 if (pmgntframe == NULL)
2204 return;
2205
2206 DBG_88E("[%s] In, result=%d\n", __func__, result);
2207 /* update attribute */
2208 pattrib = &pmgntframe->attrib;
2209 update_mgntframe_attrib(padapter, pattrib);
2210
2211 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2212
2213 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2214 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2215
2216 fctrl = &(pwlanhdr->frame_ctl);
2217 *(fctrl) = 0;
2218
2219 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2220 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2221 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2222
2223 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2224 pmlmeext->mgnt_seq++;
2225 SetFrameSubType(pframe, WIFI_ACTION);
2226
2227 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2228 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2229
2230 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2231 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2232 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2233 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2234 pwdinfo->negotiation_dialog_token = frame_body[7]; /* The Dialog Token of provisioning discovery request frame. */
2235 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2236
2237 /* Commented by Albert 20110328 */
2238 /* Try to get the device password ID from the WPS IE of group negotiation request frame */
2239 /* WiFi Direct test plan 5.1.15 */
2240 rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
2241 rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *)&be_tmp, &wps_devicepassword_id_len);
2242 wps_devicepassword_id = be16_to_cpu(be_tmp);
2243
2244 memset(wpsie, 0x00, 255);
2245 wpsielen = 0;
2246
2247 /* WPS Section */
2248 wpsielen = 0;
2249 /* WPS OUI */
2250 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
2251 wpsielen += 4;
2252
2253 /* WPS version */
2254 /* Type: */
2255 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
2256 wpsielen += 2;
2257
2258 /* Length: */
2259 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
2260 wpsielen += 2;
2261
2262 /* Value: */
2263 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
2264
2265 /* Device Password ID */
2266 /* Type: */
2267 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
2268 wpsielen += 2;
2269
2270 /* Length: */
2271 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
2272 wpsielen += 2;
2273
2274 /* Value: */
2275 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2276 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
2277 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2278 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
2279 else
2280 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
2281 wpsielen += 2;
2282
2283 /* Commented by Kurt 20120113 */
2284 /* If some device wants to do p2p handshake without sending prov_disc_req */
2285 /* We have to get peer_req_cm from here. */
2286 if (!memcmp(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3)) {
2287 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2288 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
2289 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2290 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
2291 else
2292 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
2293 }
2294
2295 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
2296
2297
2298 /* P2P IE Section. */
2299
2300 /* P2P OUI */
2301 p2pielen = 0;
2302 p2pie[p2pielen++] = 0x50;
2303 p2pie[p2pielen++] = 0x6F;
2304 p2pie[p2pielen++] = 0x9A;
2305 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2306
2307 /* Commented by Albert 20100908 */
2308 /* According to the P2P Specification, the group negotiation response frame should contain 9 P2P attributes */
2309 /* 1. Status */
2310 /* 2. P2P Capability */
2311 /* 3. Group Owner Intent */
2312 /* 4. Configuration Timeout */
2313 /* 5. Operating Channel */
2314 /* 6. Intended P2P Interface Address */
2315 /* 7. Channel List */
2316 /* 8. Device Info */
2317 /* 9. Group ID (Only GO) */
2318
2319
2320 /* ToDo: */
2321
2322 /* P2P Status */
2323 /* Type: */
2324 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2325
2326 /* Length: */
2327 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2328 p2pielen += 2;
2329
2330 /* Value: */
2331 p2pie[p2pielen++] = result;
2332
2333 /* P2P Capability */
2334 /* Type: */
2335 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2336
2337 /* Length: */
2338 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2339 p2pielen += 2;
2340
2341 /* Value: */
2342 /* Device Capability Bitmap, 1 byte */
2343
2344 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2345 /* Commented by Albert 2011/03/08 */
2346 /* According to the P2P specification */
2347 /* if the sending device will be client, the P2P Capability should be reserved of group negotiation response frame */
2348 p2pie[p2pielen++] = 0;
2349 } else {
2350 /* Be group owner or meet the error case */
2351 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2352 }
2353
2354 /* Group Capability Bitmap, 1 byte */
2355 if (pwdinfo->persistent_supported) {
2356 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2357 } else {
2358 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2359 }
2360
2361 /* Group Owner Intent */
2362 /* Type: */
2363 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
2364
2365 /* Length: */
2366 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2367 p2pielen += 2;
2368
2369 /* Value: */
2370 if (pwdinfo->peer_intent & 0x01) {
2371 /* Peer's tie breaker bit is 1, our tie breaker bit should be 0 */
2372 p2pie[p2pielen++] = (pwdinfo->intent << 1);
2373 } else {
2374 /* Peer's tie breaker bit is 0, our tie breaker bit should be 1 */
2375 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
2376 }
2377
2378
2379 /* Configuration Timeout */
2380 /* Type: */
2381 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2382
2383 /* Length: */
2384 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2385 p2pielen += 2;
2386
2387 /* Value: */
2388 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2389 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2390
2391 /* Operating Channel */
2392 /* Type: */
2393 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2394
2395 /* Length: */
2396 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2397 p2pielen += 2;
2398
2399 /* Value: */
2400 /* Country String */
2401 p2pie[p2pielen++] = 'X';
2402 p2pie[p2pielen++] = 'X';
2403
2404 /* The third byte should be set to 0x04. */
2405 /* Described in the "Operating Channel Attribute" section. */
2406 p2pie[p2pielen++] = 0x04;
2407
2408 /* Operating Class */
2409 p2pie[p2pielen++] = 0x51;
2410
2411 /* Channel Number */
2412 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2413
2414 /* Intended P2P Interface Address */
2415 /* Type: */
2416 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2417
2418 /* Length: */
2419 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2420 p2pielen += 2;
2421
2422 /* Value: */
2423 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2424 p2pielen += ETH_ALEN;
2425
2426 /* Channel List */
2427 /* Type: */
2428 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2429
2430 /* Country String(3) */
2431 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2432 /* + number of channels in all classes */
2433 len_channellist_attr = 3
2434 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2435 + get_reg_classes_full_count(&pmlmeext->channel_list);
2436
2437 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2438
2439 p2pielen += 2;
2440
2441 /* Value: */
2442 /* Country String */
2443 p2pie[p2pielen++] = 'X';
2444 p2pie[p2pielen++] = 'X';
2445
2446 /* The third byte should be set to 0x04. */
2447 /* Described in the "Operating Channel Attribute" section. */
2448 p2pie[p2pielen++] = 0x04;
2449
2450 /* Channel Entry List */
2451
2452 {
2453 int i, j;
2454 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2455 /* Operating Class */
2456 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2457
2458 /* Number of Channels */
2459 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2460
2461 /* Channel List */
2462 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2463 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2464 }
2465 }
2466 }
2467
2468 /* Device Info */
2469 /* Type: */
2470 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2471
2472 /* Length: */
2473 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2474 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2475 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2476 p2pielen += 2;
2477
2478 /* Value: */
2479 /* P2P Device Address */
2480 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2481 p2pielen += ETH_ALEN;
2482
2483 /* Config Method */
2484 /* This field should be big endian. Noted by P2P specification. */
2485
2486 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2487
2488 p2pielen += 2;
2489
2490 /* Primary Device Type */
2491 /* Category ID */
2492 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2493 p2pielen += 2;
2494
2495 /* OUI */
2496 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2497 p2pielen += 4;
2498
2499 /* Sub Category ID */
2500 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2501 p2pielen += 2;
2502
2503 /* Number of Secondary Device Types */
2504 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2505
2506 /* Device Name */
2507 /* Type: */
2508 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2509 p2pielen += 2;
2510
2511 /* Length: */
2512 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2513 p2pielen += 2;
2514
2515 /* Value: */
2516 memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
2517 p2pielen += pwdinfo->device_name_len;
2518
2519 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2520 /* Group ID Attribute */
2521 /* Type: */
2522 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2523
2524 /* Length: */
2525 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2526 p2pielen += 2;
2527
2528 /* Value: */
2529 /* p2P Device Address */
2530 memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
2531 p2pielen += ETH_ALEN;
2532
2533 /* SSID */
2534 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2535 p2pielen += pwdinfo->nego_ssidlen;
2536 }
2537
2538 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2539
2540 pattrib->last_txcmdsz = pattrib->pktlen;
2541
2542 dump_mgntframe(padapter, pmgntframe);
2543 return;
2544 }
2545
2546 static void issue_p2p_GO_confirm(struct adapter *padapter, u8 *raddr, u8 result)
2547 {
2548 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2549 u8 action = P2P_PUB_ACTION_ACTION;
2550 __be32 p2poui = cpu_to_be32(P2POUI);
2551 u8 oui_subtype = P2P_GO_NEGO_CONF;
2552 u8 p2pie[255] = { 0x00 };
2553 u8 p2pielen = 0;
2554
2555 struct xmit_frame *pmgntframe;
2556 struct pkt_attrib *pattrib;
2557 unsigned char *pframe;
2558 struct rtw_ieee80211_hdr *pwlanhdr;
2559 __le16 *fctrl;
2560 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2561 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2562 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2563
2564 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2565 if (pmgntframe == NULL)
2566 return;
2567
2568 DBG_88E("[%s] In\n", __func__);
2569 /* update attribute */
2570 pattrib = &pmgntframe->attrib;
2571 update_mgntframe_attrib(padapter, pattrib);
2572
2573 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2574
2575 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2576 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2577
2578 fctrl = &(pwlanhdr->frame_ctl);
2579 *(fctrl) = 0;
2580
2581 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2582 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2583 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2584
2585 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2586 pmlmeext->mgnt_seq++;
2587 SetFrameSubType(pframe, WIFI_ACTION);
2588
2589 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2590 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2591
2592 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2593 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2594 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2595 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2596 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2597
2598
2599
2600 /* P2P IE Section. */
2601
2602 /* P2P OUI */
2603 p2pielen = 0;
2604 p2pie[p2pielen++] = 0x50;
2605 p2pie[p2pielen++] = 0x6F;
2606 p2pie[p2pielen++] = 0x9A;
2607 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2608
2609 /* Commented by Albert 20110306 */
2610 /* According to the P2P Specification, the group negotiation request frame should contain 5 P2P attributes */
2611 /* 1. Status */
2612 /* 2. P2P Capability */
2613 /* 3. Operating Channel */
2614 /* 4. Channel List */
2615 /* 5. Group ID (if this WiFi is GO) */
2616
2617 /* P2P Status */
2618 /* Type: */
2619 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2620
2621 /* Length: */
2622 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2623 p2pielen += 2;
2624
2625 /* Value: */
2626 p2pie[p2pielen++] = result;
2627
2628 /* P2P Capability */
2629 /* Type: */
2630 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2631
2632 /* Length: */
2633 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2634 p2pielen += 2;
2635
2636 /* Value: */
2637 /* Device Capability Bitmap, 1 byte */
2638 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2639
2640 /* Group Capability Bitmap, 1 byte */
2641 if (pwdinfo->persistent_supported)
2642 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2643 else
2644 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2645
2646 /* Operating Channel */
2647 /* Type: */
2648 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2649
2650 /* Length: */
2651 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2652 p2pielen += 2;
2653
2654 /* Value: */
2655 /* Country String */
2656 p2pie[p2pielen++] = 'X';
2657 p2pie[p2pielen++] = 'X';
2658
2659 /* The third byte should be set to 0x04. */
2660 /* Described in the "Operating Channel Attribute" section. */
2661 p2pie[p2pielen++] = 0x04;
2662
2663
2664 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2665 /* Operating Class */
2666 p2pie[p2pielen++] = 0x51;
2667 p2pie[p2pielen++] = pwdinfo->peer_operating_ch;
2668 } else {
2669 /* Operating Class */
2670 p2pie[p2pielen++] = 0x51;
2671
2672 /* Channel Number */
2673 p2pie[p2pielen++] = pwdinfo->operating_channel; /* Use the listen channel as the operating channel */
2674 }
2675
2676
2677 /* Channel List */
2678 /* Type: */
2679 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2680
2681 /* Length: */
2682 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(pwdinfo->channel_list_attr_len);
2683 p2pielen += 2;
2684
2685 /* Value: */
2686 memcpy(p2pie + p2pielen, pwdinfo->channel_list_attr, pwdinfo->channel_list_attr_len);
2687 p2pielen += pwdinfo->channel_list_attr_len;
2688
2689 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2690 /* Group ID Attribute */
2691 /* Type: */
2692 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2693
2694 /* Length: */
2695 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2696 p2pielen += 2;
2697
2698 /* Value: */
2699 /* p2P Device Address */
2700 memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
2701 p2pielen += ETH_ALEN;
2702
2703 /* SSID */
2704 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2705 p2pielen += pwdinfo->nego_ssidlen;
2706 }
2707 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2708 pattrib->last_txcmdsz = pattrib->pktlen;
2709 dump_mgntframe(padapter, pmgntframe);
2710 return;
2711 }
2712
2713 void issue_p2p_invitation_request(struct adapter *padapter, u8 *raddr)
2714 {
2715 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2716 u8 action = P2P_PUB_ACTION_ACTION;
2717 __be32 p2poui = cpu_to_be32(P2POUI);
2718 u8 oui_subtype = P2P_INVIT_REQ;
2719 u8 p2pie[255] = { 0x00 };
2720 u8 p2pielen = 0;
2721 u8 dialogToken = 3;
2722 u16 len_channellist_attr = 0;
2723 struct xmit_frame *pmgntframe;
2724 struct pkt_attrib *pattrib;
2725 unsigned char *pframe;
2726 struct rtw_ieee80211_hdr *pwlanhdr;
2727 __le16 *fctrl;
2728 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2729 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2730 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2731
2732 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2733 if (pmgntframe == NULL)
2734 return;
2735
2736 /* update attribute */
2737 pattrib = &pmgntframe->attrib;
2738 update_mgntframe_attrib(padapter, pattrib);
2739
2740 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2741
2742 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2743 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2744
2745 fctrl = &(pwlanhdr->frame_ctl);
2746 *(fctrl) = 0;
2747
2748 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2749 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2750 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
2751
2752 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2753 pmlmeext->mgnt_seq++;
2754 SetFrameSubType(pframe, WIFI_ACTION);
2755
2756 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2757 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2758
2759 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2760 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2761 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2762 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2763 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
2764
2765 /* P2P IE Section. */
2766
2767 /* P2P OUI */
2768 p2pielen = 0;
2769 p2pie[p2pielen++] = 0x50;
2770 p2pie[p2pielen++] = 0x6F;
2771 p2pie[p2pielen++] = 0x9A;
2772 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2773
2774 /* Commented by Albert 20101011 */
2775 /* According to the P2P Specification, the P2P Invitation request frame should contain 7 P2P attributes */
2776 /* 1. Configuration Timeout */
2777 /* 2. Invitation Flags */
2778 /* 3. Operating Channel (Only GO) */
2779 /* 4. P2P Group BSSID (Should be included if I am the GO) */
2780 /* 5. Channel List */
2781 /* 6. P2P Group ID */
2782 /* 7. P2P Device Info */
2783
2784 /* Configuration Timeout */
2785 /* Type: */
2786 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2787
2788 /* Length: */
2789 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2790 p2pielen += 2;
2791
2792 /* Value: */
2793 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2794 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2795
2796 /* Invitation Flags */
2797 /* Type: */
2798 p2pie[p2pielen++] = P2P_ATTR_INVITATION_FLAGS;
2799
2800 /* Length: */
2801 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2802 p2pielen += 2;
2803
2804 /* Value: */
2805 p2pie[p2pielen++] = P2P_INVITATION_FLAGS_PERSISTENT;
2806
2807
2808 /* Operating Channel */
2809 /* Type: */
2810 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2811
2812 /* Length: */
2813 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2814 p2pielen += 2;
2815
2816 /* Value: */
2817 /* Country String */
2818 p2pie[p2pielen++] = 'X';
2819 p2pie[p2pielen++] = 'X';
2820
2821 /* The third byte should be set to 0x04. */
2822 /* Described in the "Operating Channel Attribute" section. */
2823 p2pie[p2pielen++] = 0x04;
2824
2825 /* Operating Class */
2826 p2pie[p2pielen++] = 0x51;
2827
2828 /* Channel Number */
2829 p2pie[p2pielen++] = pwdinfo->invitereq_info.operating_ch; /* operating channel number */
2830
2831 if (!memcmp(myid(&padapter->eeprompriv),
2832 pwdinfo->invitereq_info.go_bssid, ETH_ALEN)) {
2833 /* P2P Group BSSID */
2834 /* Type: */
2835 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
2836
2837 /* Length: */
2838 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2839 p2pielen += 2;
2840
2841 /* Value: */
2842 /* P2P Device Address for GO */
2843 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2844 p2pielen += ETH_ALEN;
2845 }
2846
2847 /* Channel List */
2848 /* Type: */
2849 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2850
2851
2852 /* Length: */
2853 /* Country String(3) */
2854 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2855 /* + number of channels in all classes */
2856 len_channellist_attr = 3
2857 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2858 + get_reg_classes_full_count(&pmlmeext->channel_list);
2859
2860 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2861
2862 p2pielen += 2;
2863
2864 /* Value: */
2865 /* Country String */
2866 p2pie[p2pielen++] = 'X';
2867 p2pie[p2pielen++] = 'X';
2868
2869 /* The third byte should be set to 0x04. */
2870 /* Described in the "Operating Channel Attribute" section. */
2871 p2pie[p2pielen++] = 0x04;
2872
2873 /* Channel Entry List */
2874 {
2875 int i, j;
2876 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2877 /* Operating Class */
2878 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2879
2880 /* Number of Channels */
2881 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2882
2883 /* Channel List */
2884 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2885 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2886 }
2887 }
2888 }
2889
2890
2891 /* P2P Group ID */
2892 /* Type: */
2893 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2894
2895 /* Length: */
2896 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(6 + pwdinfo->invitereq_info.ssidlen);
2897 p2pielen += 2;
2898
2899 /* Value: */
2900 /* P2P Device Address for GO */
2901 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2902 p2pielen += ETH_ALEN;
2903
2904 /* SSID */
2905 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_ssid, pwdinfo->invitereq_info.ssidlen);
2906 p2pielen += pwdinfo->invitereq_info.ssidlen;
2907
2908
2909 /* Device Info */
2910 /* Type: */
2911 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2912
2913 /* Length: */
2914 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2915 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2916 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2917 p2pielen += 2;
2918
2919 /* Value: */
2920 /* P2P Device Address */
2921 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2922 p2pielen += ETH_ALEN;
2923
2924 /* Config Method */
2925 /* This field should be big endian. Noted by P2P specification. */
2926 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
2927 p2pielen += 2;
2928
2929 /* Primary Device Type */
2930 /* Category ID */
2931 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2932 p2pielen += 2;
2933
2934 /* OUI */
2935 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2936 p2pielen += 4;
2937
2938 /* Sub Category ID */
2939 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2940 p2pielen += 2;
2941
2942 /* Number of Secondary Device Types */
2943 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2944
2945 /* Device Name */
2946 /* Type: */
2947 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2948 p2pielen += 2;
2949
2950 /* Length: */
2951 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2952 p2pielen += 2;
2953
2954 /* Value: */
2955 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
2956 p2pielen += pwdinfo->device_name_len;
2957
2958 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2959
2960 pattrib->last_txcmdsz = pattrib->pktlen;
2961
2962 dump_mgntframe(padapter, pmgntframe);
2963
2964 return;
2965 }
2966
2967 void issue_p2p_invitation_response(struct adapter *padapter, u8 *raddr, u8 dialogToken, u8 status_code)
2968 {
2969 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2970 u8 action = P2P_PUB_ACTION_ACTION;
2971 __be32 p2poui = cpu_to_be32(P2POUI);
2972 u8 oui_subtype = P2P_INVIT_RESP;
2973 u8 p2pie[255] = { 0x00 };
2974 u8 p2pielen = 0;
2975 u16 len_channellist_attr = 0;
2976 struct xmit_frame *pmgntframe;
2977 struct pkt_attrib *pattrib;
2978 unsigned char *pframe;
2979 struct rtw_ieee80211_hdr *pwlanhdr;
2980 __le16 *fctrl;
2981 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2982 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2983 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2984
2985 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2986 if (pmgntframe == NULL)
2987 return;
2988
2989 /* update attribute */
2990 pattrib = &pmgntframe->attrib;
2991 update_mgntframe_attrib(padapter, pattrib);
2992
2993 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2994
2995 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2996 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2997
2998 fctrl = &(pwlanhdr->frame_ctl);
2999 *(fctrl) = 0;
3000
3001 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3002 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3003 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
3004
3005 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3006 pmlmeext->mgnt_seq++;
3007 SetFrameSubType(pframe, WIFI_ACTION);
3008
3009 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3010 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3011
3012 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3013 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3014 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
3015 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3016 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
3017
3018 /* P2P IE Section. */
3019
3020 /* P2P OUI */
3021 p2pielen = 0;
3022 p2pie[p2pielen++] = 0x50;
3023 p2pie[p2pielen++] = 0x6F;
3024 p2pie[p2pielen++] = 0x9A;
3025 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
3026
3027 /* Commented by Albert 20101005 */
3028 /* According to the P2P Specification, the P2P Invitation response frame should contain 5 P2P attributes */
3029 /* 1. Status */
3030 /* 2. Configuration Timeout */
3031 /* 3. Operating Channel (Only GO) */
3032 /* 4. P2P Group BSSID (Only GO) */
3033 /* 5. Channel List */
3034
3035 /* P2P Status */
3036 /* Type: */
3037 p2pie[p2pielen++] = P2P_ATTR_STATUS;
3038
3039 /* Length: */
3040 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
3041 p2pielen += 2;
3042
3043 /* Value: */
3044 /* When status code is P2P_STATUS_FAIL_INFO_UNAVAILABLE. */
3045 /* Sent the event receiving the P2P Invitation Req frame to DMP UI. */
3046 /* DMP had to compare the MAC address to find out the profile. */
3047 /* So, the WiFi driver will send the P2P_STATUS_FAIL_INFO_UNAVAILABLE to NB. */
3048 /* If the UI found the corresponding profile, the WiFi driver sends the P2P Invitation Req */
3049 /* to NB to rebuild the persistent group. */
3050 p2pie[p2pielen++] = status_code;
3051
3052 /* Configuration Timeout */
3053 /* Type: */
3054 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
3055
3056 /* Length: */
3057 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3058 p2pielen += 2;
3059
3060 /* Value: */
3061 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
3062 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
3063
3064 if (status_code == P2P_STATUS_SUCCESS) {
3065 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3066 /* The P2P Invitation request frame asks this Wi-Fi device to be the P2P GO */
3067 /* In this case, the P2P Invitation response frame should carry the two more P2P attributes. */
3068 /* First one is operating channel attribute. */
3069 /* Second one is P2P Group BSSID attribute. */
3070
3071 /* Operating Channel */
3072 /* Type: */
3073 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3074
3075 /* Length: */
3076 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3077 p2pielen += 2;
3078
3079 /* Value: */
3080 /* Country String */
3081 p2pie[p2pielen++] = 'X';
3082 p2pie[p2pielen++] = 'X';
3083
3084 /* The third byte should be set to 0x04. */
3085 /* Described in the "Operating Channel Attribute" section. */
3086 p2pie[p2pielen++] = 0x04;
3087
3088 /* Operating Class */
3089 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3090
3091 /* Channel Number */
3092 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3093
3094
3095 /* P2P Group BSSID */
3096 /* Type: */
3097 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
3098
3099 /* Length: */
3100 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
3101 p2pielen += 2;
3102
3103 /* Value: */
3104 /* P2P Device Address for GO */
3105 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
3106 p2pielen += ETH_ALEN;
3107 }
3108
3109 /* Channel List */
3110 /* Type: */
3111 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
3112
3113 /* Length: */
3114 /* Country String(3) */
3115 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
3116 /* + number of channels in all classes */
3117 len_channellist_attr = 3
3118 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
3119 + get_reg_classes_full_count(&pmlmeext->channel_list);
3120
3121 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
3122 p2pielen += 2;
3123
3124 /* Value: */
3125 /* Country String */
3126 p2pie[p2pielen++] = 'X';
3127 p2pie[p2pielen++] = 'X';
3128
3129 /* The third byte should be set to 0x04. */
3130 /* Described in the "Operating Channel Attribute" section. */
3131 p2pie[p2pielen++] = 0x04;
3132
3133 /* Channel Entry List */
3134 {
3135 int i, j;
3136 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3137 /* Operating Class */
3138 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3139
3140 /* Number of Channels */
3141 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3142
3143 /* Channel List */
3144 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3145 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3146 }
3147 }
3148 }
3149 }
3150
3151 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3152
3153 pattrib->last_txcmdsz = pattrib->pktlen;
3154
3155 dump_mgntframe(padapter, pmgntframe);
3156
3157 return;
3158 }
3159
3160 void issue_p2p_provision_request(struct adapter *padapter, u8 *pssid, u8 ussidlen, u8 *pdev_raddr)
3161 {
3162 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3163 u8 action = P2P_PUB_ACTION_ACTION;
3164 u8 dialogToken = 1;
3165 u8 oui_subtype = P2P_PROVISION_DISC_REQ;
3166 u8 wpsie[100] = { 0x00 };
3167 u8 wpsielen = 0;
3168 __be32 p2poui = cpu_to_be32(P2POUI);
3169 u32 p2pielen = 0;
3170 struct xmit_frame *pmgntframe;
3171 struct pkt_attrib *pattrib;
3172 unsigned char *pframe;
3173 struct rtw_ieee80211_hdr *pwlanhdr;
3174 __le16 *fctrl;
3175 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3176 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3177 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3178
3179 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3180 if (pmgntframe == NULL)
3181 return;
3182
3183 DBG_88E("[%s] In\n", __func__);
3184 /* update attribute */
3185 pattrib = &pmgntframe->attrib;
3186 update_mgntframe_attrib(padapter, pattrib);
3187
3188 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3189
3190 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3191 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3192
3193 fctrl = &(pwlanhdr->frame_ctl);
3194 *(fctrl) = 0;
3195
3196 memcpy(pwlanhdr->addr1, pdev_raddr, ETH_ALEN);
3197 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3198 memcpy(pwlanhdr->addr3, pdev_raddr, ETH_ALEN);
3199
3200 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3201 pmlmeext->mgnt_seq++;
3202 SetFrameSubType(pframe, WIFI_ACTION);
3203
3204 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3205 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3206
3207 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3208 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3209 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
3210 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3211 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
3212
3213 p2pielen = build_prov_disc_request_p2p_ie(pwdinfo, pframe, pssid, ussidlen, pdev_raddr);
3214
3215 pframe += p2pielen;
3216 pattrib->pktlen += p2pielen;
3217
3218 wpsielen = 0;
3219 /* WPS OUI */
3220 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3221 wpsielen += 4;
3222
3223 /* WPS version */
3224 /* Type: */
3225 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3226 wpsielen += 2;
3227
3228 /* Length: */
3229 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3230 wpsielen += 2;
3231
3232 /* Value: */
3233 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3234
3235 /* Config Method */
3236 /* Type: */
3237 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3238 wpsielen += 2;
3239
3240 /* Length: */
3241 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3242 wpsielen += 2;
3243
3244 /* Value: */
3245 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
3246 wpsielen += 2;
3247
3248 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3249
3250 pattrib->last_txcmdsz = pattrib->pktlen;
3251
3252 dump_mgntframe(padapter, pmgntframe);
3253
3254 return;
3255 }
3256
3257 static u8 is_matched_in_profilelist(u8 *peermacaddr, struct profile_info *profileinfo)
3258 {
3259 u8 i, match_result = 0;
3260
3261 DBG_88E("[%s] peermac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3262 peermacaddr[0], peermacaddr[1], peermacaddr[2], peermacaddr[3], peermacaddr[4], peermacaddr[5]);
3263
3264 for (i = 0; i < P2P_MAX_PERSISTENT_GROUP_NUM; i++, profileinfo++) {
3265 DBG_88E("[%s] profileinfo_mac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3266 profileinfo->peermac[0], profileinfo->peermac[1], profileinfo->peermac[2], profileinfo->peermac[3], profileinfo->peermac[4], profileinfo->peermac[5]);
3267 if (!memcmp(peermacaddr, profileinfo->peermac, ETH_ALEN)) {
3268 match_result = 1;
3269 DBG_88E("[%s] Match!\n", __func__);
3270 break;
3271 }
3272 }
3273 return match_result;
3274 }
3275
3276 void issue_probersp_p2p(struct adapter *padapter, unsigned char *da)
3277 {
3278 struct xmit_frame *pmgntframe;
3279 struct pkt_attrib *pattrib;
3280 unsigned char *pframe;
3281 struct rtw_ieee80211_hdr *pwlanhdr;
3282 __le16 *fctrl;
3283 unsigned char *mac;
3284 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3285 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3286 u16 beacon_interval = 100;
3287 u16 capInfo = 0;
3288 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3289 u8 wpsie[255] = { 0x00 };
3290 u32 wpsielen = 0, p2pielen = 0;
3291
3292 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3293 if (pmgntframe == NULL)
3294 return;
3295
3296 /* update attribute */
3297 pattrib = &pmgntframe->attrib;
3298 update_mgntframe_attrib(padapter, pattrib);
3299
3300 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3301
3302 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3303 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3304
3305 mac = myid(&(padapter->eeprompriv));
3306
3307 fctrl = &(pwlanhdr->frame_ctl);
3308 *(fctrl) = 0;
3309 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3310 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3311
3312 /* Use the device address for BSSID field. */
3313 memcpy(pwlanhdr->addr3, mac, ETH_ALEN);
3314
3315 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3316 pmlmeext->mgnt_seq++;
3317 SetFrameSubType(fctrl, WIFI_PROBERSP);
3318
3319 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3320 pattrib->pktlen = pattrib->hdrlen;
3321 pframe += pattrib->hdrlen;
3322
3323 /* timestamp will be inserted by hardware */
3324 pframe += 8;
3325 pattrib->pktlen += 8;
3326
3327 /* beacon interval: 2 bytes */
3328 memcpy(pframe, (unsigned char *)&beacon_interval, 2);
3329 pframe += 2;
3330 pattrib->pktlen += 2;
3331
3332 /* capability info: 2 bytes */
3333 /* ESS and IBSS bits must be 0 (defined in the 3.1.2.1.1 of WiFi Direct Spec) */
3334 capInfo |= cap_ShortPremble;
3335 capInfo |= cap_ShortSlot;
3336
3337 memcpy(pframe, (unsigned char *)&capInfo, 2);
3338 pframe += 2;
3339 pattrib->pktlen += 2;
3340
3341
3342 /* SSID */
3343 pframe = rtw_set_ie(pframe, _SSID_IE_, 7, pwdinfo->p2p_wildcard_ssid, &pattrib->pktlen);
3344
3345 /* supported rates... */
3346 /* Use the OFDM rate in the P2P probe response frame. (6(B), 9(B), 12, 18, 24, 36, 48, 54) */
3347 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3348
3349 /* DS parameter set */
3350 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&pwdinfo->listen_channel, &pattrib->pktlen);
3351
3352 /* Todo: WPS IE */
3353 /* Noted by Albert 20100907 */
3354 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3355
3356 wpsielen = 0;
3357 /* WPS OUI */
3358 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3359 wpsielen += 4;
3360
3361 /* WPS version */
3362 /* Type: */
3363 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3364 wpsielen += 2;
3365
3366 /* Length: */
3367 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3368 wpsielen += 2;
3369
3370 /* Value: */
3371 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3372
3373 /* WiFi Simple Config State */
3374 /* Type: */
3375 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SIMPLE_CONF_STATE);
3376 wpsielen += 2;
3377
3378 /* Length: */
3379 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3380 wpsielen += 2;
3381
3382 /* Value: */
3383 wpsie[wpsielen++] = WPS_WSC_STATE_NOT_CONFIG; /* Not Configured. */
3384
3385 /* Response Type */
3386 /* Type: */
3387 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_RESP_TYPE);
3388 wpsielen += 2;
3389
3390 /* Length: */
3391 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3392 wpsielen += 2;
3393
3394 /* Value: */
3395 wpsie[wpsielen++] = WPS_RESPONSE_TYPE_8021X;
3396
3397 /* UUID-E */
3398 /* Type: */
3399 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3400 wpsielen += 2;
3401
3402 /* Length: */
3403 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3404 wpsielen += 2;
3405
3406 /* Value: */
3407 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3408 wpsielen += 0x10;
3409
3410 /* Manufacturer */
3411 /* Type: */
3412 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MANUFACTURER);
3413 wpsielen += 2;
3414
3415 /* Length: */
3416 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0007);
3417 wpsielen += 2;
3418
3419 /* Value: */
3420 memcpy(wpsie + wpsielen, "Realtek", 7);
3421 wpsielen += 7;
3422
3423 /* Model Name */
3424 /* Type: */
3425 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NAME);
3426 wpsielen += 2;
3427
3428 /* Length: */
3429 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0006);
3430 wpsielen += 2;
3431
3432 /* Value: */
3433 memcpy(wpsie + wpsielen, "8188EU", 6);
3434 wpsielen += 6;
3435
3436 /* Model Number */
3437 /* Type: */
3438 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NUMBER);
3439 wpsielen += 2;
3440
3441 /* Length: */
3442 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3443 wpsielen += 2;
3444
3445 /* Value: */
3446 wpsie[wpsielen++] = 0x31; /* character 1 */
3447
3448 /* Serial Number */
3449 /* Type: */
3450 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SERIAL_NUMBER);
3451 wpsielen += 2;
3452
3453 /* Length: */
3454 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(ETH_ALEN);
3455 wpsielen += 2;
3456
3457 /* Value: */
3458 memcpy(wpsie + wpsielen, "123456" , ETH_ALEN);
3459 wpsielen += ETH_ALEN;
3460
3461 /* Primary Device Type */
3462 /* Type: */
3463 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3464 wpsielen += 2;
3465
3466 /* Length: */
3467 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3468 wpsielen += 2;
3469
3470 /* Value: */
3471 /* Category ID */
3472 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
3473 wpsielen += 2;
3474
3475 /* OUI */
3476 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3477 wpsielen += 4;
3478
3479 /* Sub Category ID */
3480 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
3481 wpsielen += 2;
3482
3483 /* Device Name */
3484 /* Type: */
3485 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3486 wpsielen += 2;
3487
3488 /* Length: */
3489 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3490 wpsielen += 2;
3491
3492 /* Value: */
3493 if (pwdinfo->device_name_len) {
3494 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3495 wpsielen += pwdinfo->device_name_len;
3496 }
3497
3498 /* Config Method */
3499 /* Type: */
3500 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3501 wpsielen += 2;
3502
3503 /* Length: */
3504 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3505 wpsielen += 2;
3506
3507 /* Value: */
3508 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3509 wpsielen += 2;
3510
3511
3512 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3513
3514
3515 p2pielen = build_probe_resp_p2p_ie(pwdinfo, pframe);
3516 pframe += p2pielen;
3517 pattrib->pktlen += p2pielen;
3518
3519 pattrib->last_txcmdsz = pattrib->pktlen;
3520
3521 dump_mgntframe(padapter, pmgntframe);
3522
3523 return;
3524 }
3525
3526 static int _issue_probereq_p2p(struct adapter *padapter, u8 *da, int wait_ack)
3527 {
3528 int ret = _FAIL;
3529 struct xmit_frame *pmgntframe;
3530 struct pkt_attrib *pattrib;
3531 unsigned char *pframe;
3532 struct rtw_ieee80211_hdr *pwlanhdr;
3533 __le16 *fctrl;
3534 unsigned char *mac;
3535 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3536 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3537 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3538 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3539 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
3540 u16 wpsielen = 0, p2pielen = 0;
3541 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3542
3543 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3544 if (pmgntframe == NULL)
3545 goto exit;
3546
3547 /* update attribute */
3548 pattrib = &pmgntframe->attrib;
3549 update_mgntframe_attrib(padapter, pattrib);
3550
3551
3552 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3553
3554 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3555 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3556
3557 mac = myid(&(padapter->eeprompriv));
3558
3559 fctrl = &(pwlanhdr->frame_ctl);
3560 *(fctrl) = 0;
3561
3562 if (da) {
3563 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3564 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
3565 } else {
3566 if ((pwdinfo->p2p_info.scan_op_ch_only) || (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
3567 /* This two flags will be set when this is only the P2P client mode. */
3568 memcpy(pwlanhdr->addr1, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3569 memcpy(pwlanhdr->addr3, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3570 } else {
3571 /* broadcast probe request frame */
3572 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
3573 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
3574 }
3575 }
3576 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3577
3578 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3579 pmlmeext->mgnt_seq++;
3580 SetFrameSubType(pframe, WIFI_PROBEREQ);
3581
3582 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
3583 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
3584
3585 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
3586 pframe = rtw_set_ie(pframe, _SSID_IE_, pwdinfo->tx_prov_disc_info.ssid.SsidLength, pwdinfo->tx_prov_disc_info.ssid.Ssid, &(pattrib->pktlen));
3587 else
3588 pframe = rtw_set_ie(pframe, _SSID_IE_, P2P_WILDCARD_SSID_LEN, pwdinfo->p2p_wildcard_ssid, &(pattrib->pktlen));
3589
3590 /* Use the OFDM rate in the P2P probe request frame. (6(B), 9(B), 12(B), 24(B), 36, 48, 54) */
3591 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3592
3593
3594 /* WPS IE */
3595 /* Noted by Albert 20110221 */
3596 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3597
3598 wpsielen = 0;
3599 /* WPS OUI */
3600 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3601 wpsielen += 4;
3602
3603 /* WPS version */
3604 /* Type: */
3605 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3606 wpsielen += 2;
3607
3608 /* Length: */
3609 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3610 wpsielen += 2;
3611
3612 /* Value: */
3613 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3614
3615 if (pmlmepriv->wps_probe_req_ie == NULL) {
3616 /* UUID-E */
3617 /* Type: */
3618 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3619 wpsielen += 2;
3620
3621 /* Length: */
3622 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3623 wpsielen += 2;
3624
3625 /* Value: */
3626 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3627 wpsielen += 0x10;
3628
3629 /* Config Method */
3630 /* Type: */
3631 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3632 wpsielen += 2;
3633
3634 /* Length: */
3635 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3636 wpsielen += 2;
3637
3638 /* Value: */
3639 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3640 wpsielen += 2;
3641 }
3642
3643 /* Device Name */
3644 /* Type: */
3645 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3646 wpsielen += 2;
3647
3648 /* Length: */
3649 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3650 wpsielen += 2;
3651
3652 /* Value: */
3653 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3654 wpsielen += pwdinfo->device_name_len;
3655
3656 /* Primary Device Type */
3657 /* Type: */
3658 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3659 wpsielen += 2;
3660
3661 /* Length: */
3662 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3663 wpsielen += 2;
3664
3665 /* Value: */
3666 /* Category ID */
3667 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_RTK_WIDI);
3668 wpsielen += 2;
3669
3670 /* OUI */
3671 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3672 wpsielen += 4;
3673
3674 /* Sub Category ID */
3675 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_RTK_DMP);
3676 wpsielen += 2;
3677
3678 /* Device Password ID */
3679 /* Type: */
3680 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
3681 wpsielen += 2;
3682
3683 /* Length: */
3684 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3685 wpsielen += 2;
3686
3687 /* Value: */
3688 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC); /* Registrar-specified */
3689 wpsielen += 2;
3690
3691 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3692
3693 /* P2P OUI */
3694 p2pielen = 0;
3695 p2pie[p2pielen++] = 0x50;
3696 p2pie[p2pielen++] = 0x6F;
3697 p2pie[p2pielen++] = 0x9A;
3698 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
3699
3700 /* Commented by Albert 20110221 */
3701 /* According to the P2P Specification, the probe request frame should contain 5 P2P attributes */
3702 /* 1. P2P Capability */
3703 /* 2. P2P Device ID if this probe request wants to find the specific P2P device */
3704 /* 3. Listen Channel */
3705 /* 4. Extended Listen Timing */
3706 /* 5. Operating Channel if this WiFi is working as the group owner now */
3707
3708 /* P2P Capability */
3709 /* Type: */
3710 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
3711
3712 /* Length: */
3713 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3714 p2pielen += 2;
3715
3716 /* Value: */
3717 /* Device Capability Bitmap, 1 byte */
3718 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
3719
3720 /* Group Capability Bitmap, 1 byte */
3721 if (pwdinfo->persistent_supported)
3722 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
3723 else
3724 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
3725
3726 /* Listen Channel */
3727 /* Type: */
3728 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
3729
3730 /* Length: */
3731 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3732 p2pielen += 2;
3733
3734 /* Value: */
3735 /* Country String */
3736 p2pie[p2pielen++] = 'X';
3737 p2pie[p2pielen++] = 'X';
3738
3739 /* The third byte should be set to 0x04. */
3740 /* Described in the "Operating Channel Attribute" section. */
3741 p2pie[p2pielen++] = 0x04;
3742
3743 /* Operating Class */
3744 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3745
3746 /* Channel Number */
3747 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listen channel */
3748
3749
3750 /* Extended Listen Timing */
3751 /* Type: */
3752 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
3753
3754 /* Length: */
3755 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
3756 p2pielen += 2;
3757
3758 /* Value: */
3759 /* Availability Period */
3760 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3761 p2pielen += 2;
3762
3763 /* Availability Interval */
3764 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3765 p2pielen += 2;
3766
3767 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3768 /* Operating Channel (if this WiFi is working as the group owner now) */
3769 /* Type: */
3770 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3771
3772 /* Length: */
3773 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3774 p2pielen += 2;
3775
3776 /* Value: */
3777 /* Country String */
3778 p2pie[p2pielen++] = 'X';
3779 p2pie[p2pielen++] = 'X';
3780
3781 /* The third byte should be set to 0x04. */
3782 /* Described in the "Operating Channel Attribute" section. */
3783 p2pie[p2pielen++] = 0x04;
3784
3785 /* Operating Class */
3786 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3787
3788 /* Channel Number */
3789 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3790 }
3791
3792 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3793
3794 if (pmlmepriv->wps_probe_req_ie != NULL) {
3795 /* WPS IE */
3796 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
3797 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
3798 pframe += pmlmepriv->wps_probe_req_ie_len;
3799 }
3800
3801 pattrib->last_txcmdsz = pattrib->pktlen;
3802
3803 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
3804
3805 if (wait_ack) {
3806 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
3807 } else {
3808 dump_mgntframe(padapter, pmgntframe);
3809 ret = _SUCCESS;
3810 }
3811
3812 exit:
3813 return ret;
3814 }
3815
3816 inline void issue_probereq_p2p(struct adapter *adapter, u8 *da)
3817 {
3818 _issue_probereq_p2p(adapter, da, false);
3819 }
3820
3821 int issue_probereq_p2p_ex(struct adapter *adapter, u8 *da, int try_cnt, int wait_ms)
3822 {
3823 int ret;
3824 int i = 0;
3825 u32 start = jiffies;
3826
3827 do {
3828 ret = _issue_probereq_p2p(adapter, da, wait_ms > 0 ? true : false);
3829
3830 i++;
3831
3832 if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
3833 break;
3834
3835 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3836 msleep(wait_ms);
3837 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3838
3839 if (ret != _FAIL) {
3840 ret = _SUCCESS;
3841 goto exit;
3842 }
3843
3844 if (try_cnt && wait_ms) {
3845 if (da)
3846 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
3847 FUNC_ADPT_ARG(adapter), da, rtw_get_oper_ch(adapter),
3848 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3849 else
3850 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
3851 FUNC_ADPT_ARG(adapter), rtw_get_oper_ch(adapter),
3852 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3853 }
3854 exit:
3855 return ret;
3856 }
3857
3858 #endif /* CONFIG_88EU_P2P */
3859
3860 static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
3861 {
3862 struct adapter *adapter = recv_frame->adapter;
3863 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3864 u8 *frame = recv_frame->rx_data;
3865 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) |
3866 (recv_frame->attrib.frag_num & 0xf);
3867
3868 if (GetRetry(frame)) {
3869 if (token >= 0) {
3870 if ((seq_ctrl == mlmeext->action_public_rxseq) && (token == mlmeext->action_public_dialog_token)) {
3871 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x, token:%d\n",
3872 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
3873 return _FAIL;
3874 }
3875 } else {
3876 if (seq_ctrl == mlmeext->action_public_rxseq) {
3877 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x\n",
3878 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq);
3879 return _FAIL;
3880 }
3881 }
3882 }
3883
3884 mlmeext->action_public_rxseq = seq_ctrl;
3885
3886 if (token >= 0)
3887 mlmeext->action_public_dialog_token = token;
3888
3889 return _SUCCESS;
3890 }
3891
3892 static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
3893 {
3894 u8 *pframe = precv_frame->rx_data;
3895 u8 *frame_body;
3896 u8 dialogToken = 0;
3897 #ifdef CONFIG_88EU_P2P
3898 struct adapter *padapter = precv_frame->adapter;
3899 uint len = precv_frame->len;
3900 u8 *p2p_ie;
3901 u32 p2p_ielen;
3902 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3903 u8 result = P2P_STATUS_SUCCESS;
3904 u8 empty_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3905 #endif /* CONFIG_88EU_P2P */
3906
3907 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
3908
3909 dialogToken = frame_body[7];
3910
3911 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
3912 return _FAIL;
3913
3914 #ifdef CONFIG_88EU_P2P
3915 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
3916 /* Do nothing if the driver doesn't enable the P2P function. */
3917 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
3918 return _SUCCESS;
3919
3920 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
3921
3922 switch (frame_body[6]) { /* OUI Subtype */
3923 case P2P_GO_NEGO_REQ:
3924 DBG_88E("[%s] Got GO Nego Req Frame\n", __func__);
3925 memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
3926
3927 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
3928 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3929
3930 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL)) {
3931 /* Commented by Albert 20110526 */
3932 /* In this case, this means the previous nego fail doesn't be reset yet. */
3933 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3934 /* Restore the previous p2p state */
3935 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3936 DBG_88E("[%s] Restore the previous p2p state to %d\n", __func__, rtw_p2p_state(pwdinfo));
3937 }
3938
3939 /* Commented by Kurt 20110902 */
3940 /* Add if statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
3941 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
3942 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3943
3944 /* Commented by Kurt 20120113 */
3945 /* Get peer_dev_addr here if peer doesn't issue prov_disc frame. */
3946 if (!memcmp(pwdinfo->rx_prov_disc_info.peerDevAddr, empty_addr,
3947 ETH_ALEN))
3948 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
3949
3950 result = process_p2p_group_negotation_req(pwdinfo, frame_body, len);
3951 issue_p2p_GO_response(padapter, GetAddr2Ptr(pframe), frame_body, len, result);
3952
3953 /* Commented by Albert 20110718 */
3954 /* No matter negotiating or negotiation failure, the driver should set up the restore P2P state timer. */
3955 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3956 break;
3957 case P2P_GO_NEGO_RESP:
3958 DBG_88E("[%s] Got GO Nego Resp Frame\n", __func__);
3959
3960 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
3961 /* Commented by Albert 20110425 */
3962 /* The restore timer is enabled when issuing the nego request frame of rtw_p2p_connect function. */
3963 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3964 pwdinfo->nego_req_info.benable = false;
3965 result = process_p2p_group_negotation_resp(pwdinfo, frame_body, len);
3966 issue_p2p_GO_confirm(pwdinfo->padapter, GetAddr2Ptr(pframe), result);
3967 if (P2P_STATUS_SUCCESS == result) {
3968 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3969 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3970 pwdinfo->p2p_info.scan_op_ch_only = 1;
3971 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3972 }
3973 }
3974 /* Reset the dialog token for group negotiation frames. */
3975 pwdinfo->negotiation_dialog_token = 1;
3976 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
3977 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3978 } else {
3979 DBG_88E("[%s] Skipped GO Nego Resp Frame (p2p_state != P2P_STATE_GONEGO_ING)\n", __func__);
3980 }
3981 break;
3982 case P2P_GO_NEGO_CONF:
3983 DBG_88E("[%s] Got GO Nego Confirm Frame\n", __func__);
3984 result = process_p2p_group_negotation_confirm(pwdinfo, frame_body, len);
3985 if (P2P_STATUS_SUCCESS == result) {
3986 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3987 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3988 pwdinfo->p2p_info.scan_op_ch_only = 1;
3989 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3990 }
3991 }
3992 break;
3993 case P2P_INVIT_REQ:
3994 /* Added by Albert 2010/10/05 */
3995 /* Received the P2P Invite Request frame. */
3996
3997 DBG_88E("[%s] Got invite request frame!\n", __func__);
3998 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
3999 if (p2p_ie) {
4000 /* Parse the necessary information from the P2P Invitation Request frame. */
4001 /* For example: The MAC address of sending this P2P Invitation Request frame. */
4002 u32 attr_contentlen = 0;
4003 u8 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4004 struct group_id_info group_id;
4005 u8 invitation_flag = 0;
4006
4007 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INVITATION_FLAGS, &invitation_flag, &attr_contentlen);
4008 if (attr_contentlen) {
4009 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_BSSID, pwdinfo->p2p_peer_interface_addr, &attr_contentlen);
4010 /* Commented by Albert 20120510 */
4011 /* Copy to the pwdinfo->p2p_peer_interface_addr. */
4012 /* So that the WFD UI (or Sigma) can get the peer interface address by using the following command. */
4013 /* #> iwpriv wlan0 p2p_get peer_ifa */
4014 /* After having the peer interface address, the sigma can find the correct conf file for wpa_supplicant. */
4015
4016 if (attr_contentlen) {
4017 DBG_88E("[%s] GO's BSSID = %.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
4018 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1],
4019 pwdinfo->p2p_peer_interface_addr[2], pwdinfo->p2p_peer_interface_addr[3],
4020 pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4021 }
4022
4023 if (invitation_flag & P2P_INVITATION_FLAGS_PERSISTENT) {
4024 /* Re-invoke the persistent group. */
4025
4026 memset(&group_id, 0x00, sizeof(struct group_id_info));
4027 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
4028 if (attr_contentlen) {
4029 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
4030 /* The p2p device sending this p2p invitation request wants this Wi-Fi device to be the persistent GO. */
4031 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_GO);
4032 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
4033 status_code = P2P_STATUS_SUCCESS;
4034 } else {
4035 /* The p2p device sending this p2p invitation request wants to be the persistent GO. */
4036 if (is_matched_in_profilelist(pwdinfo->p2p_peer_interface_addr, &pwdinfo->profileinfo[0])) {
4037 u8 operatingch_info[5] = { 0x00 };
4038 if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen)) {
4039 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, (u32)operatingch_info[4])) {
4040 /* The operating channel is acceptable for this device. */
4041 pwdinfo->rx_invitereq_info.operation_ch[0] = operatingch_info[4];
4042 pwdinfo->rx_invitereq_info.scan_op_ch_only = 1;
4043 _set_timer(&pwdinfo->reset_ch_sitesurvey, P2P_RESET_SCAN_CH);
4044 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
4045 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4046 status_code = P2P_STATUS_SUCCESS;
4047 } else {
4048 /* The operating channel isn't supported by this device. */
4049 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4050 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4051 status_code = P2P_STATUS_FAIL_NO_COMMON_CH;
4052 _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
4053 }
4054 } else {
4055 /* Commented by Albert 20121130 */
4056 /* Intel will use the different P2P IE to store the operating channel information */
4057 /* Workaround for Intel WiDi 3.5 */
4058 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
4059 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4060 status_code = P2P_STATUS_SUCCESS;
4061 }
4062 } else {
4063 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4064 status_code = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
4065 }
4066 }
4067 } else {
4068 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4069 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4070 }
4071 } else {
4072 /* Received the invitation to join a P2P group. */
4073
4074 memset(&group_id, 0x00, sizeof(struct group_id_info));
4075 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
4076 if (attr_contentlen) {
4077 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
4078 /* In this case, the GO can't be myself. */
4079 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4080 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4081 } else {
4082 /* The p2p device sending this p2p invitation request wants to join an existing P2P group */
4083 /* Commented by Albert 2012/06/28 */
4084 /* In this case, this Wi-Fi device should use the iwpriv command to get the peer device address. */
4085 /* The peer device address should be the destination address for the provisioning discovery request. */
4086 /* Then, this Wi-Fi device should use the iwpriv command to get the peer interface address. */
4087 /* The peer interface address should be the address for WPS mac address */
4088 memcpy(pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN);
4089 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4090 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_JOIN);
4091 status_code = P2P_STATUS_SUCCESS;
4092 }
4093 } else {
4094 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4095 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4096 }
4097 }
4098 } else {
4099 DBG_88E("[%s] P2P Invitation Flags Attribute NOT FOUND!\n", __func__);
4100 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4101 }
4102
4103 DBG_88E("[%s] status_code = %d\n", __func__, status_code);
4104
4105 pwdinfo->inviteresp_info.token = frame_body[7];
4106 issue_p2p_invitation_response(padapter, GetAddr2Ptr(pframe), pwdinfo->inviteresp_info.token, status_code);
4107 }
4108 break;
4109 case P2P_INVIT_RESP: {
4110 u8 attr_content = 0x00;
4111 u32 attr_contentlen = 0;
4112
4113 DBG_88E("[%s] Got invite response frame!\n", __func__);
4114 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4115 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
4116 if (p2p_ie) {
4117 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
4118
4119 if (attr_contentlen == 1) {
4120 DBG_88E("[%s] Status = %d\n", __func__, attr_content);
4121 pwdinfo->invitereq_info.benable = false;
4122
4123 if (attr_content == P2P_STATUS_SUCCESS) {
4124 if (!memcmp(pwdinfo->invitereq_info.go_bssid, myid(&padapter->eeprompriv), ETH_ALEN)) {
4125 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
4126 } else {
4127 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4128 }
4129 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_OK);
4130 } else {
4131 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4132 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4133 }
4134 } else {
4135 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4136 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4137 }
4138 } else {
4139 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4140 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4141 }
4142
4143 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL))
4144 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
4145 break;
4146 }
4147 case P2P_DEVDISC_REQ:
4148 process_p2p_devdisc_req(pwdinfo, pframe, len);
4149 break;
4150 case P2P_DEVDISC_RESP:
4151 process_p2p_devdisc_resp(pwdinfo, pframe, len);
4152 break;
4153 case P2P_PROVISION_DISC_REQ:
4154 DBG_88E("[%s] Got Provisioning Discovery Request Frame\n", __func__);
4155 process_p2p_provdisc_req(pwdinfo, pframe, len);
4156 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
4157
4158 /* 20110902 Kurt */
4159 /* Add the following statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
4160 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
4161 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
4162
4163 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ);
4164 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4165 break;
4166 case P2P_PROVISION_DISC_RESP:
4167 /* Commented by Albert 20110707 */
4168 /* Should we check the pwdinfo->tx_prov_disc_info.bsent flag here?? */
4169 DBG_88E("[%s] Got Provisioning Discovery Response Frame\n", __func__);
4170 /* Commented by Albert 20110426 */
4171 /* The restore timer is enabled when issuing the provisioing request frame in rtw_p2p_prov_disc function. */
4172 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4173 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP);
4174 process_p2p_provdisc_resp(pwdinfo, pframe);
4175 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4176 break;
4177 }
4178 #endif /* CONFIG_88EU_P2P */
4179
4180 return _SUCCESS;
4181 }
4182
4183 static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
4184 {
4185 unsigned int ret = _FAIL;
4186 u8 *pframe = precv_frame->rx_data;
4187 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4188
4189 if (!memcmp(frame_body + 2, P2P_OUI, 4))
4190 ret = on_action_public_p2p(precv_frame);
4191
4192 return ret;
4193 }
4194
4195 static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action)
4196 {
4197 unsigned int ret = _FAIL;
4198 u8 *pframe = precv_frame->rx_data;
4199 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4200 u8 token;
4201
4202 token = frame_body[2];
4203
4204 if (rtw_action_public_decache(precv_frame, token) == _FAIL)
4205 goto exit;
4206
4207 ret = _SUCCESS;
4208
4209 exit:
4210 return ret;
4211 }
4212
4213 unsigned int on_action_public(struct adapter *padapter, struct recv_frame *precv_frame)
4214 {
4215 unsigned int ret = _FAIL;
4216 u8 *pframe = precv_frame->rx_data;
4217 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4218 u8 category, action;
4219
4220 /* check RA matches or not */
4221 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
4222 goto exit;
4223
4224 category = frame_body[0];
4225 if (category != RTW_WLAN_CATEGORY_PUBLIC)
4226 goto exit;
4227
4228 action = frame_body[1];
4229 switch (action) {
4230 case ACT_PUBLIC_VENDOR:
4231 ret = on_action_public_vendor(precv_frame);
4232 break;
4233 default:
4234 ret = on_action_public_default(precv_frame, action);
4235 break;
4236 }
4237
4238 exit:
4239 return ret;
4240 }
4241
4242 unsigned int OnAction_ht(struct adapter *padapter, struct recv_frame *precv_frame)
4243 {
4244 return _SUCCESS;
4245 }
4246
4247 unsigned int OnAction_wmm(struct adapter *padapter, struct recv_frame *precv_frame)
4248 {
4249 return _SUCCESS;
4250 }
4251
4252 unsigned int OnAction_p2p(struct adapter *padapter, struct recv_frame *precv_frame)
4253 {
4254 #ifdef CONFIG_88EU_P2P
4255 u8 *frame_body;
4256 u8 category, OUI_Subtype;
4257 u8 *pframe = precv_frame->rx_data;
4258 uint len = precv_frame->len;
4259 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4260
4261
4262 DBG_88E("%s\n", __func__);
4263
4264 /* check RA matches or not */
4265 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))/* for if1, sta/ap mode */
4266 return _SUCCESS;
4267
4268 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4269
4270 category = frame_body[0];
4271 if (category != RTW_WLAN_CATEGORY_P2P)
4272 return _SUCCESS;
4273
4274 if (be32_to_cpu(*((__be32 *)(frame_body + 1))) != P2POUI)
4275 return _SUCCESS;
4276
4277 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
4278 OUI_Subtype = frame_body[5];
4279
4280 switch (OUI_Subtype) {
4281 case P2P_NOTICE_OF_ABSENCE:
4282 break;
4283 case P2P_PRESENCE_REQUEST:
4284 process_p2p_presence_req(pwdinfo, pframe, len);
4285 break;
4286 case P2P_PRESENCE_RESPONSE:
4287 break;
4288 case P2P_GO_DISC_REQUEST:
4289 break;
4290 default:
4291 break;
4292 }
4293 #endif /* CONFIG_88EU_P2P */
4294 return _SUCCESS;
4295 }
4296
4297 unsigned int OnAction(struct adapter *padapter, struct recv_frame *precv_frame)
4298 {
4299 int i;
4300 unsigned char category;
4301 struct action_handler *ptable;
4302 unsigned char *frame_body;
4303 u8 *pframe = precv_frame->rx_data;
4304
4305 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4306
4307 category = frame_body[0];
4308
4309 for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
4310 ptable = &OnAction_tbl[i];
4311 if (category == ptable->num)
4312 ptable->func(padapter, precv_frame);
4313 }
4314 return _SUCCESS;
4315 }
4316
4317 unsigned int DoReserved(struct adapter *padapter, struct recv_frame *precv_frame)
4318 {
4319 return _SUCCESS;
4320 }
4321
4322 struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
4323 {
4324 struct xmit_frame *pmgntframe;
4325 struct xmit_buf *pxmitbuf;
4326
4327 pmgntframe = rtw_alloc_xmitframe(pxmitpriv);
4328 if (pmgntframe == NULL) {
4329 DBG_88E("%s, alloc xmitframe fail\n", __func__);
4330 return NULL;
4331 }
4332
4333 pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv);
4334 if (pxmitbuf == NULL) {
4335 DBG_88E("%s, alloc xmitbuf fail\n", __func__);
4336 rtw_free_xmitframe(pxmitpriv, pmgntframe);
4337 return NULL;
4338 }
4339 pmgntframe->frame_tag = MGNT_FRAMETAG;
4340 pmgntframe->pxmitbuf = pxmitbuf;
4341 pmgntframe->buf_addr = pxmitbuf->pbuf;
4342 pxmitbuf->priv_data = pmgntframe;
4343 return pmgntframe;
4344 }
4345
4346 /****************************************************************************
4347
4348 Following are some TX functions for WiFi MLME
4349
4350 *****************************************************************************/
4351
4352 void update_mgnt_tx_rate(struct adapter *padapter, u8 rate)
4353 {
4354 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4355
4356 pmlmeext->tx_rate = rate;
4357 DBG_88E("%s(): rate = %x\n", __func__, rate);
4358 }
4359
4360 void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib)
4361 {
4362 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4363
4364 memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib));
4365
4366 pattrib->hdrlen = 24;
4367 pattrib->nr_frags = 1;
4368 pattrib->priority = 7;
4369 pattrib->mac_id = 0;
4370 pattrib->qsel = 0x12;
4371
4372 pattrib->pktlen = 0;
4373
4374 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
4375 pattrib->raid = 6;/* b mode */
4376 else
4377 pattrib->raid = 5;/* a/g mode */
4378
4379 pattrib->encrypt = _NO_PRIVACY_;
4380 pattrib->bswenc = false;
4381
4382 pattrib->qos_en = false;
4383 pattrib->ht_en = false;
4384 pattrib->bwmode = HT_CHANNEL_WIDTH_20;
4385 pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
4386 pattrib->sgi = false;
4387
4388 pattrib->seqnum = pmlmeext->mgnt_seq;
4389
4390 pattrib->retry_ctrl = true;
4391 }
4392
4393 void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe)
4394 {
4395 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4396 return;
4397
4398 rtw_hal_mgnt_xmit(padapter, pmgntframe);
4399 }
4400
4401 s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
4402 {
4403 s32 ret = _FAIL;
4404 struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
4405 struct submit_ctx sctx;
4406
4407 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4408 return ret;
4409
4410 rtw_sctx_init(&sctx, timeout_ms);
4411 pxmitbuf->sctx = &sctx;
4412
4413 ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
4414
4415 if (ret == _SUCCESS)
4416 ret = rtw_sctx_wait(&sctx);
4417
4418 return ret;
4419 }
4420
4421 s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe)
4422 {
4423 s32 ret = _FAIL;
4424 u32 timeout_ms = 500;/* 500ms */
4425 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
4426
4427 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4428 return -1;
4429
4430 _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
4431 pxmitpriv->ack_tx = true;
4432
4433 pmgntframe->ack_report = 1;
4434 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
4435 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
4436 }
4437
4438 pxmitpriv->ack_tx = false;
4439 mutex_unlock(&pxmitpriv->ack_tx_mutex);
4440
4441 return ret;
4442 }
4443
4444 static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
4445 {
4446 u8 *ssid_ie;
4447 int ssid_len_ori;
4448 int len_diff = 0;
4449
4450 ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
4451
4452 if (ssid_ie && ssid_len_ori > 0) {
4453 switch (hidden_ssid_mode) {
4454 case 1: {
4455 u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
4456 u32 remain_len = 0;
4457
4458 remain_len = ies_len - (next_ie - ies);
4459
4460 ssid_ie[1] = 0;
4461 memcpy(ssid_ie+2, next_ie, remain_len);
4462 len_diff -= ssid_len_ori;
4463
4464 break;
4465 }
4466 case 2:
4467 memset(&ssid_ie[2], 0, ssid_len_ori);
4468 break;
4469 default:
4470 break;
4471 }
4472 }
4473
4474 return len_diff;
4475 }
4476
4477 void issue_beacon(struct adapter *padapter, int timeout_ms)
4478 {
4479 struct xmit_frame *pmgntframe;
4480 struct pkt_attrib *pattrib;
4481 unsigned char *pframe;
4482 struct rtw_ieee80211_hdr *pwlanhdr;
4483 __le16 *fctrl;
4484 unsigned int rate_len;
4485 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4486 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4487 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4488 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4489 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4490 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4491 #ifdef CONFIG_88EU_P2P
4492 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4493 #endif /* CONFIG_88EU_P2P */
4494
4495 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4496 if (pmgntframe == NULL) {
4497 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4498 return;
4499 }
4500 #if defined (CONFIG_88EU_AP_MODE)
4501 spin_lock_bh(&pmlmepriv->bcn_update_lock);
4502 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4503
4504 /* update attribute */
4505 pattrib = &pmgntframe->attrib;
4506 update_mgntframe_attrib(padapter, pattrib);
4507 pattrib->qsel = 0x10;
4508
4509 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4510
4511 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4512 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4513
4514
4515 fctrl = &(pwlanhdr->frame_ctl);
4516 *(fctrl) = 0;
4517
4518 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4519 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4520 memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
4521
4522 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
4523 /* pmlmeext->mgnt_seq++; */
4524 SetFrameSubType(pframe, WIFI_BEACON);
4525
4526 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4527 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4528
4529 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4530 #ifdef CONFIG_88EU_P2P
4531 /* for P2P : Primary Device Type & Device Name */
4532 u32 wpsielen = 0, insert_len = 0;
4533 u8 *wpsie = NULL;
4534 wpsie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen);
4535
4536 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && wpsie && wpsielen > 0) {
4537 uint wps_offset, remainder_ielen;
4538 u8 *premainder_ie, *pframe_wscie;
4539
4540 wps_offset = (uint)(wpsie - cur_network->IEs);
4541 premainder_ie = wpsie + wpsielen;
4542 remainder_ielen = cur_network->IELength - wps_offset - wpsielen;
4543 pframe_wscie = pframe + wps_offset;
4544 memcpy(pframe, cur_network->IEs, wps_offset+wpsielen);
4545 pframe += (wps_offset + wpsielen);
4546 pattrib->pktlen += (wps_offset + wpsielen);
4547
4548 /* now pframe is end of wsc ie, insert Primary Device Type & Device Name */
4549 /* Primary Device Type */
4550 /* Type: */
4551 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
4552 insert_len += 2;
4553
4554 /* Length: */
4555 *(__be16 *)(pframe + insert_len) = cpu_to_be16(0x0008);
4556 insert_len += 2;
4557
4558 /* Value: */
4559 /* Category ID */
4560 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
4561 insert_len += 2;
4562
4563 /* OUI */
4564 *(__be32 *)(pframe + insert_len) = cpu_to_be32(WPSOUI);
4565 insert_len += 4;
4566
4567 /* Sub Category ID */
4568 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
4569 insert_len += 2;
4570
4571 /* Device Name */
4572 /* Type: */
4573 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
4574 insert_len += 2;
4575
4576 /* Length: */
4577 *(__be16 *)(pframe + insert_len) = cpu_to_be16(pwdinfo->device_name_len);
4578 insert_len += 2;
4579
4580 /* Value: */
4581 memcpy(pframe + insert_len, pwdinfo->device_name, pwdinfo->device_name_len);
4582 insert_len += pwdinfo->device_name_len;
4583
4584 /* update wsc ie length */
4585 *(pframe_wscie+1) = (wpsielen-2) + insert_len;
4586
4587 /* pframe move to end */
4588 pframe += insert_len;
4589 pattrib->pktlen += insert_len;
4590
4591 /* copy remainder_ie to pframe */
4592 memcpy(pframe, premainder_ie, remainder_ielen);
4593 pframe += remainder_ielen;
4594 pattrib->pktlen += remainder_ielen;
4595 } else
4596 #endif /* CONFIG_88EU_P2P */
4597 {
4598 int len_diff;
4599 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4600 len_diff = update_hidden_ssid(
4601 pframe+_BEACON_IE_OFFSET_
4602 , cur_network->IELength-_BEACON_IE_OFFSET_
4603 , pmlmeinfo->hidden_ssid_mode
4604 );
4605 pframe += (cur_network->IELength+len_diff);
4606 pattrib->pktlen += (cur_network->IELength+len_diff);
4607 }
4608
4609 {
4610 u8 *wps_ie;
4611 uint wps_ielen;
4612 u8 sr = 0;
4613 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
4614 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
4615 if (wps_ie && wps_ielen > 0)
4616 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
4617 if (sr != 0)
4618 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
4619 else
4620 _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
4621 }
4622
4623 #ifdef CONFIG_88EU_P2P
4624 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
4625 u32 len;
4626 len = build_beacon_p2p_ie(pwdinfo, pframe);
4627
4628 pframe += len;
4629 pattrib->pktlen += len;
4630 }
4631 #endif /* CONFIG_88EU_P2P */
4632
4633 goto _issue_bcn;
4634 }
4635
4636 /* below for ad-hoc mode */
4637
4638 /* timestamp will be inserted by hardware */
4639 pframe += 8;
4640 pattrib->pktlen += 8;
4641
4642 /* beacon interval: 2 bytes */
4643
4644 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4645
4646 pframe += 2;
4647 pattrib->pktlen += 2;
4648
4649 /* capability info: 2 bytes */
4650
4651 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4652
4653 pframe += 2;
4654 pattrib->pktlen += 2;
4655
4656 /* SSID */
4657 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4658
4659 /* supported rates... */
4660 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4661 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4662
4663 /* DS parameter set */
4664 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4665
4666 {
4667 u8 erpinfo = 0;
4668 u32 ATIMWindow;
4669 /* IBSS Parameter Set... */
4670 ATIMWindow = 0;
4671 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4672
4673 /* ERP IE */
4674 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4675 }
4676
4677 /* EXTERNDED SUPPORTED RATE */
4678 if (rate_len > 8)
4679 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4680 /* todo:HT for adhoc */
4681 _issue_bcn:
4682
4683 #if defined (CONFIG_88EU_AP_MODE)
4684 pmlmepriv->update_bcn = false;
4685
4686 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
4687 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4688
4689 if ((pattrib->pktlen + TXDESC_SIZE) > 512) {
4690 DBG_88E("beacon frame too large\n");
4691 return;
4692 }
4693
4694 pattrib->last_txcmdsz = pattrib->pktlen;
4695
4696 /* DBG_88E("issue bcn_sz=%d\n", pattrib->last_txcmdsz); */
4697 if (timeout_ms > 0)
4698 dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
4699 else
4700 dump_mgntframe(padapter, pmgntframe);
4701 }
4702
4703 void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
4704 {
4705 struct xmit_frame *pmgntframe;
4706 struct pkt_attrib *pattrib;
4707 unsigned char *pframe;
4708 struct rtw_ieee80211_hdr *pwlanhdr;
4709 __le16 *fctrl;
4710 unsigned char *mac, *bssid;
4711 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4712 #if defined (CONFIG_88EU_AP_MODE)
4713 u8 *pwps_ie;
4714 uint wps_ielen;
4715 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4716 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4717 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4718 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4719 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4720 unsigned int rate_len;
4721 #ifdef CONFIG_88EU_P2P
4722 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4723 #endif /* CONFIG_88EU_P2P */
4724
4725 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4726 if (pmgntframe == NULL) {
4727 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4728 return;
4729 }
4730
4731 /* update attribute */
4732 pattrib = &pmgntframe->attrib;
4733 update_mgntframe_attrib(padapter, pattrib);
4734
4735 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4736
4737 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4738 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4739
4740 mac = myid(&(padapter->eeprompriv));
4741 bssid = cur_network->MacAddress;
4742
4743 fctrl = &(pwlanhdr->frame_ctl);
4744 *(fctrl) = 0;
4745 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4746 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4747 memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
4748
4749 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4750 pmlmeext->mgnt_seq++;
4751 SetFrameSubType(fctrl, WIFI_PROBERSP);
4752
4753 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4754 pattrib->pktlen = pattrib->hdrlen;
4755 pframe += pattrib->hdrlen;
4756
4757 if (cur_network->IELength > MAX_IE_SZ)
4758 return;
4759
4760 #if defined(CONFIG_88EU_AP_MODE)
4761 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4762 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
4763
4764 /* inerset & update wps_probe_resp_ie */
4765 if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
4766 uint wps_offset, remainder_ielen;
4767 u8 *premainder_ie;
4768
4769 wps_offset = (uint)(pwps_ie - cur_network->IEs);
4770
4771 premainder_ie = pwps_ie + wps_ielen;
4772
4773 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
4774
4775 memcpy(pframe, cur_network->IEs, wps_offset);
4776 pframe += wps_offset;
4777 pattrib->pktlen += wps_offset;
4778
4779 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
4780 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
4781 memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
4782 pframe += wps_ielen+2;
4783 pattrib->pktlen += wps_ielen+2;
4784 }
4785
4786 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
4787 memcpy(pframe, premainder_ie, remainder_ielen);
4788 pframe += remainder_ielen;
4789 pattrib->pktlen += remainder_ielen;
4790 }
4791 } else {
4792 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4793 pframe += cur_network->IELength;
4794 pattrib->pktlen += cur_network->IELength;
4795 }
4796 } else
4797 #endif
4798 {
4799 /* timestamp will be inserted by hardware */
4800 pframe += 8;
4801 pattrib->pktlen += 8;
4802
4803 /* beacon interval: 2 bytes */
4804
4805 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4806
4807 pframe += 2;
4808 pattrib->pktlen += 2;
4809
4810 /* capability info: 2 bytes */
4811
4812 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4813
4814 pframe += 2;
4815 pattrib->pktlen += 2;
4816
4817 /* below for ad-hoc mode */
4818
4819 /* SSID */
4820 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4821
4822 /* supported rates... */
4823 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4824 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4825
4826 /* DS parameter set */
4827 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4828
4829 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
4830 u8 erpinfo = 0;
4831 u32 ATIMWindow;
4832 /* IBSS Parameter Set... */
4833 /* ATIMWindow = cur->Configuration.ATIMWindow; */
4834 ATIMWindow = 0;
4835 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4836
4837 /* ERP IE */
4838 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4839 }
4840
4841
4842 /* EXTERNDED SUPPORTED RATE */
4843 if (rate_len > 8)
4844 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4845 /* todo:HT for adhoc */
4846 }
4847
4848 #ifdef CONFIG_88EU_P2P
4849 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && is_valid_p2p_probereq) {
4850 u32 len;
4851 len = build_probe_resp_p2p_ie(pwdinfo, pframe);
4852
4853 pframe += len;
4854 pattrib->pktlen += len;
4855 }
4856 #endif /* CONFIG_88EU_P2P */
4857
4858 pattrib->last_txcmdsz = pattrib->pktlen;
4859
4860 dump_mgntframe(padapter, pmgntframe);
4861
4862 return;
4863 }
4864
4865 static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int wait_ack)
4866 {
4867 int ret = _FAIL;
4868 struct xmit_frame *pmgntframe;
4869 struct pkt_attrib *pattrib;
4870 unsigned char *pframe;
4871 struct rtw_ieee80211_hdr *pwlanhdr;
4872 __le16 *fctrl;
4873 unsigned char *mac;
4874 unsigned char bssrate[NumRates];
4875 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4876 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4877 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4878 int bssrate_len = 0;
4879 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4880
4881 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+issue_probereq\n"));
4882
4883 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4884 if (pmgntframe == NULL)
4885 goto exit;
4886
4887 /* update attribute */
4888 pattrib = &pmgntframe->attrib;
4889 update_mgntframe_attrib(padapter, pattrib);
4890
4891
4892 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4893
4894 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4895 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4896
4897 mac = myid(&(padapter->eeprompriv));
4898
4899 fctrl = &(pwlanhdr->frame_ctl);
4900 *(fctrl) = 0;
4901
4902 if (da) {
4903 /* unicast probe request frame */
4904 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4905 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
4906 } else {
4907 /* broadcast probe request frame */
4908 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4909 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
4910 }
4911
4912 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4913
4914 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4915 pmlmeext->mgnt_seq++;
4916 SetFrameSubType(pframe, WIFI_PROBEREQ);
4917
4918 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
4919 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4920
4921 if (pssid)
4922 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
4923 else
4924 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
4925
4926 get_rate_set(padapter, bssrate, &bssrate_len);
4927
4928 if (bssrate_len > 8) {
4929 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
4930 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
4931 } else {
4932 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
4933 }
4934
4935 /* add wps_ie for wps2.0 */
4936 if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) {
4937 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
4938 pframe += pmlmepriv->wps_probe_req_ie_len;
4939 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
4940 }
4941
4942 pattrib->last_txcmdsz = pattrib->pktlen;
4943
4944 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
4945 ("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
4946
4947 if (wait_ack) {
4948 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
4949 } else {
4950 dump_mgntframe(padapter, pmgntframe);
4951 ret = _SUCCESS;
4952 }
4953
4954 exit:
4955 return ret;
4956 }
4957
4958 inline void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da)
4959 {
4960 _issue_probereq(padapter, pssid, da, false);
4961 }
4962
4963 int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da,
4964 int try_cnt, int wait_ms)
4965 {
4966 int ret;
4967 int i = 0;
4968 u32 start = jiffies;
4969
4970 do {
4971 ret = _issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false);
4972
4973 i++;
4974
4975 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
4976 break;
4977
4978 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
4979 msleep(wait_ms);
4980
4981 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
4982
4983 if (ret != _FAIL) {
4984 ret = _SUCCESS;
4985 goto exit;
4986 }
4987
4988 if (try_cnt && wait_ms) {
4989 if (da)
4990 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
4991 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
4992 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
4993 else
4994 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
4995 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
4996 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
4997 }
4998 exit:
4999 return ret;
5000 }
5001
5002 /* if psta == NULL, indicate we are station(client) now... */
5003 void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status)
5004 {
5005 struct xmit_frame *pmgntframe;
5006 struct pkt_attrib *pattrib;
5007 unsigned char *pframe;
5008 struct rtw_ieee80211_hdr *pwlanhdr;
5009 __le16 *fctrl;
5010 unsigned int val32;
5011 u16 val16;
5012 #ifdef CONFIG_88EU_AP_MODE
5013 __le16 le_val16;
5014 #endif
5015 int use_shared_key = 0;
5016 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5017 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5018 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5019
5020 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5021 if (pmgntframe == NULL)
5022 return;
5023
5024 /* update attribute */
5025 pattrib = &pmgntframe->attrib;
5026 update_mgntframe_attrib(padapter, pattrib);
5027
5028 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5029
5030 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5031 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5032
5033 fctrl = &(pwlanhdr->frame_ctl);
5034 *(fctrl) = 0;
5035
5036 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5037 pmlmeext->mgnt_seq++;
5038 SetFrameSubType(pframe, WIFI_AUTH);
5039
5040 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5041 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5042
5043
5044 if (psta) {/* for AP mode */
5045 #ifdef CONFIG_88EU_AP_MODE
5046
5047 memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
5048 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5049 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
5050
5051
5052 /* setting auth algo number */
5053 val16 = (u16)psta->authalg;
5054
5055 if (status != _STATS_SUCCESSFUL_)
5056 val16 = 0;
5057
5058 if (val16) {
5059 le_val16 = cpu_to_le16(val16);
5060 use_shared_key = 1;
5061 } else {
5062 le_val16 = 0;
5063 }
5064
5065 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5066
5067 /* setting auth seq number */
5068 val16 = (u16)psta->auth_seq;
5069 le_val16 = cpu_to_le16(val16);
5070 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5071
5072 /* setting status code... */
5073 val16 = status;
5074 le_val16 = cpu_to_le16(val16);
5075 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5076
5077 /* added challenging text... */
5078 if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
5079 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
5080 #endif
5081 } else {
5082 __le32 le_tmp32;
5083 __le16 le_tmp16;
5084 memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5085 memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
5086 memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5087
5088 /* setting auth algo number */
5089 val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) ? 1 : 0;/* 0:OPEN System, 1:Shared key */
5090 if (val16)
5091 use_shared_key = 1;
5092
5093 /* setting IV for auth seq #3 */
5094 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5095 val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
5096 le_tmp32 = cpu_to_le32(val32);
5097 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen));
5098
5099 pattrib->iv_len = 4;
5100 }
5101
5102 le_tmp16 = cpu_to_le16(val16);
5103 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5104
5105 /* setting auth seq number */
5106 val16 = pmlmeinfo->auth_seq;
5107 le_tmp16 = cpu_to_le16(val16);
5108 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5109
5110
5111 /* setting status code... */
5112 le_tmp16 = cpu_to_le16(status);
5113 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5114
5115 /* then checking to see if sending challenging text... */
5116 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5117 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
5118
5119 SetPrivacy(fctrl);
5120
5121 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5122
5123 pattrib->encrypt = _WEP40_;
5124
5125 pattrib->icv_len = 4;
5126
5127 pattrib->pktlen += pattrib->icv_len;
5128 }
5129 }
5130
5131 pattrib->last_txcmdsz = pattrib->pktlen;
5132
5133 rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
5134 DBG_88E("%s\n", __func__);
5135 dump_mgntframe(padapter, pmgntframe);
5136
5137 return;
5138 }
5139
5140
5141 void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
5142 {
5143 #ifdef CONFIG_88EU_AP_MODE
5144 struct xmit_frame *pmgntframe;
5145 struct rtw_ieee80211_hdr *pwlanhdr;
5146 struct pkt_attrib *pattrib;
5147 unsigned char *pbuf, *pframe;
5148 unsigned short val;
5149 __le16 *fctrl;
5150 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5151 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5152 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5153 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5154 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
5155 u8 *ie = pnetwork->IEs;
5156 __le16 lestatus, leval;
5157 #ifdef CONFIG_88EU_P2P
5158 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5159 #endif /* CONFIG_88EU_P2P */
5160
5161 DBG_88E("%s\n", __func__);
5162
5163 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5164 if (pmgntframe == NULL)
5165 return;
5166
5167 /* update attribute */
5168 pattrib = &pmgntframe->attrib;
5169 update_mgntframe_attrib(padapter, pattrib);
5170
5171
5172 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5173
5174 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5175 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5176
5177 fctrl = &(pwlanhdr->frame_ctl);
5178 *(fctrl) = 0;
5179
5180 memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
5181 memcpy((void *)GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN);
5182 memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5183
5184
5185 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5186 pmlmeext->mgnt_seq++;
5187 if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
5188 SetFrameSubType(pwlanhdr, pkt_type);
5189 else
5190 return;
5191
5192 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5193 pattrib->pktlen += pattrib->hdrlen;
5194 pframe += pattrib->hdrlen;
5195
5196 /* capability */
5197 val = *(unsigned short *)rtw_get_capability_from_ie(ie);
5198
5199 pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
5200
5201 lestatus = cpu_to_le16(status);
5202 pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&lestatus, &(pattrib->pktlen));
5203
5204 leval = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
5205 pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&leval, &(pattrib->pktlen));
5206
5207 if (pstat->bssratelen <= 8) {
5208 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
5209 } else {
5210 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
5211 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen-8), pstat->bssrateset+8, &(pattrib->pktlen));
5212 }
5213
5214 if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) {
5215 uint ie_len = 0;
5216
5217 /* FILL HT CAP INFO IE */
5218 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5219 if (pbuf && ie_len > 0) {
5220 memcpy(pframe, pbuf, ie_len+2);
5221 pframe += (ie_len+2);
5222 pattrib->pktlen += (ie_len+2);
5223 }
5224
5225 /* FILL HT ADD INFO IE */
5226 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5227 if (pbuf && ie_len > 0) {
5228 memcpy(pframe, pbuf, ie_len+2);
5229 pframe += (ie_len+2);
5230 pattrib->pktlen += (ie_len+2);
5231 }
5232 }
5233
5234 /* FILL WMM IE */
5235 if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) {
5236 uint ie_len = 0;
5237 unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
5238
5239 for (pbuf = ie + _BEACON_IE_OFFSET_;; pbuf += (ie_len + 2)) {
5240 pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
5241 if (pbuf && !memcmp(pbuf+2, WMM_PARA_IE, 6)) {
5242 memcpy(pframe, pbuf, ie_len+2);
5243 pframe += (ie_len+2);
5244 pattrib->pktlen += (ie_len+2);
5245 break;
5246 }
5247
5248 if ((pbuf == NULL) || (ie_len == 0))
5249 break;
5250 }
5251 }
5252
5253 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5254 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
5255
5256 /* add WPS IE ie for wps 2.0 */
5257 if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) {
5258 memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
5259
5260 pframe += pmlmepriv->wps_assoc_resp_ie_len;
5261 pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
5262 }
5263
5264 #ifdef CONFIG_88EU_P2P
5265 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && (pstat->is_p2p_device)) {
5266 u32 len;
5267
5268 len = build_assoc_resp_p2p_ie(pwdinfo, pframe, pstat->p2p_status_code);
5269
5270 pframe += len;
5271 pattrib->pktlen += len;
5272 }
5273 #endif /* CONFIG_88EU_P2P */
5274 pattrib->last_txcmdsz = pattrib->pktlen;
5275 dump_mgntframe(padapter, pmgntframe);
5276 #endif
5277 }
5278
5279 void issue_assocreq(struct adapter *padapter)
5280 {
5281 int ret = _FAIL;
5282 struct xmit_frame *pmgntframe;
5283 struct pkt_attrib *pattrib;
5284 unsigned char *pframe, *p;
5285 struct rtw_ieee80211_hdr *pwlanhdr;
5286 __le16 *fctrl;
5287 __le16 le_tmp;
5288 unsigned int i, j, ie_len, index = 0;
5289 unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
5290 struct ndis_802_11_var_ie *pIE;
5291 struct registry_priv *pregpriv = &padapter->registrypriv;
5292 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5293 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5294 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5295 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5296 int bssrate_len = 0, sta_bssrate_len = 0;
5297 #ifdef CONFIG_88EU_P2P
5298 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5299 u8 p2pie[255] = { 0x00 };
5300 u16 p2pielen = 0;
5301 #endif /* CONFIG_88EU_P2P */
5302
5303 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5304 if (pmgntframe == NULL)
5305 goto exit;
5306
5307 /* update attribute */
5308 pattrib = &pmgntframe->attrib;
5309 update_mgntframe_attrib(padapter, pattrib);
5310
5311 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5312 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5313 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5314
5315 fctrl = &(pwlanhdr->frame_ctl);
5316 *(fctrl) = 0;
5317 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5318 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5319 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5320
5321 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5322 pmlmeext->mgnt_seq++;
5323 SetFrameSubType(pframe, WIFI_ASSOCREQ);
5324
5325 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5326 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5327
5328 /* caps */
5329
5330 memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
5331
5332 pframe += 2;
5333 pattrib->pktlen += 2;
5334
5335 /* listen interval */
5336 /* todo: listen interval for power saving */
5337 le_tmp = cpu_to_le16(3);
5338 memcpy(pframe , (unsigned char *)&le_tmp, 2);
5339 pframe += 2;
5340 pattrib->pktlen += 2;
5341
5342 /* SSID */
5343 pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
5344
5345 /* supported rate & extended supported rate */
5346
5347 /* Check if the AP's supported rates are also supported by STA. */
5348 get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
5349
5350 if (pmlmeext->cur_channel == 14)/* for JAPAN, channel 14 can only uses B Mode(CCK) */
5351 sta_bssrate_len = 4;
5352
5353 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5354 if (pmlmeinfo->network.SupportedRates[i] == 0)
5355 break;
5356 DBG_88E("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
5357 }
5358
5359 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5360 if (pmlmeinfo->network.SupportedRates[i] == 0)
5361 break;
5362
5363 /* Check if the AP's supported rates are also supported by STA. */
5364 for (j = 0; j < sta_bssrate_len; j++) {
5365 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
5366 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
5367 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK))
5368 break;
5369 }
5370
5371 if (j == sta_bssrate_len) {
5372 /* the rate is not supported by STA */
5373 DBG_88E("%s(): the rate[%d]=%02X is not supported by STA!\n", __func__, i, pmlmeinfo->network.SupportedRates[i]);
5374 } else {
5375 /* the rate is supported by STA */
5376 bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
5377 }
5378 }
5379
5380 bssrate_len = index;
5381 DBG_88E("bssrate_len=%d\n", bssrate_len);
5382
5383 if (bssrate_len == 0) {
5384 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
5385 rtw_free_xmitframe(pxmitpriv, pmgntframe);
5386 goto exit; /* don't connect to AP if no joint supported rate */
5387 }
5388
5389
5390 if (bssrate_len > 8) {
5391 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
5392 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
5393 } else {
5394 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
5395 }
5396
5397 /* RSN */
5398 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _RSN_IE_2_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
5399 if (p != NULL)
5400 pframe = rtw_set_ie(pframe, _RSN_IE_2_, ie_len, (p + 2), &(pattrib->pktlen));
5401
5402 /* HT caps */
5403 if (padapter->mlmepriv.htpriv.ht_option) {
5404 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _HT_CAPABILITY_IE_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
5405 if ((p != NULL) && (!(is_ap_in_tkip(padapter)))) {
5406 memcpy(&(pmlmeinfo->HT_caps), (p + 2), sizeof(struct HT_caps_element));
5407
5408 /* to disable 40M Hz support while gd_bw_40MHz_en = 0 */
5409 if (pregpriv->cbw40_enable == 0)
5410 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info &= cpu_to_le16(~(BIT(6) | BIT(1)));
5411 else
5412 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(BIT(1));
5413
5414 /* todo: disable SM power save mode */
5415 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x000c);
5416
5417 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
5418 switch (rf_type) {
5419 case RF_1T1R:
5420 if (pregpriv->rx_stbc)
5421 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0100);/* RX STBC One spatial stream */
5422 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_1R, 16);
5423 break;
5424 case RF_2T2R:
5425 case RF_1T2R:
5426 default:
5427 if ((pregpriv->rx_stbc == 0x3) ||/* enable for 2.4/5 GHz */
5428 ((pmlmeext->cur_wireless_mode & WIRELESS_11_24N) && (pregpriv->rx_stbc == 0x1)) || /* enable for 2.4GHz */
5429 (pregpriv->wifi_spec == 1)) {
5430 DBG_88E("declare supporting RX STBC\n");
5431 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0200);/* RX STBC two spatial stream */
5432 }
5433 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_2R, 16);
5434 break;
5435 }
5436 pframe = rtw_set_ie(pframe, _HT_CAPABILITY_IE_, ie_len , (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
5437 }
5438 }
5439
5440 /* vendor specific IE, such as WPA, WMM, WPS */
5441 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
5442 pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
5443
5444 switch (pIE->ElementID) {
5445 case _VENDOR_SPECIFIC_IE_:
5446 if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
5447 (!memcmp(pIE->data, WMM_OUI, 4)) ||
5448 (!memcmp(pIE->data, WPS_OUI, 4))) {
5449 if (!padapter->registrypriv.wifi_spec) {
5450 /* Commented by Kurt 20110629 */
5451 /* In some older APs, WPS handshake */
5452 /* would be fail if we append vender extensions informations to AP */
5453 if (!memcmp(pIE->data, WPS_OUI, 4))
5454 pIE->Length = 14;
5455 }
5456 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, pIE->Length, pIE->data, &(pattrib->pktlen));
5457 }
5458 break;
5459 default:
5460 break;
5461 }
5462 i += (pIE->Length + 2);
5463 }
5464
5465 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5466 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
5467
5468 #ifdef CONFIG_88EU_P2P
5469
5470 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
5471 /* Should add the P2P IE in the association request frame. */
5472 /* P2P OUI */
5473
5474 p2pielen = 0;
5475 p2pie[p2pielen++] = 0x50;
5476 p2pie[p2pielen++] = 0x6F;
5477 p2pie[p2pielen++] = 0x9A;
5478 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
5479
5480 /* Commented by Albert 20101109 */
5481 /* According to the P2P Specification, the association request frame should contain 3 P2P attributes */
5482 /* 1. P2P Capability */
5483 /* 2. Extended Listen Timing */
5484 /* 3. Device Info */
5485 /* Commented by Albert 20110516 */
5486 /* 4. P2P Interface */
5487
5488 /* P2P Capability */
5489 /* Type: */
5490 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
5491
5492 /* Length: */
5493 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
5494 p2pielen += 2;
5495
5496 /* Value: */
5497 /* Device Capability Bitmap, 1 byte */
5498 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
5499
5500 /* Group Capability Bitmap, 1 byte */
5501 if (pwdinfo->persistent_supported)
5502 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
5503 else
5504 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
5505
5506 /* Extended Listen Timing */
5507 /* Type: */
5508 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
5509
5510 /* Length: */
5511 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
5512 p2pielen += 2;
5513
5514 /* Value: */
5515 /* Availability Period */
5516 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5517 p2pielen += 2;
5518
5519 /* Availability Interval */
5520 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5521 p2pielen += 2;
5522
5523 /* Device Info */
5524 /* Type: */
5525 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
5526
5527 /* Length: */
5528 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
5529 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
5530 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
5531 p2pielen += 2;
5532
5533 /* Value: */
5534 /* P2P Device Address */
5535 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
5536 p2pielen += ETH_ALEN;
5537
5538 /* Config Method */
5539 /* This field should be big endian. Noted by P2P specification. */
5540 if ((pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN) ||
5541 (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN))
5542 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
5543 else
5544 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_PBC);
5545
5546 p2pielen += 2;
5547
5548 /* Primary Device Type */
5549 /* Category ID */
5550 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
5551 p2pielen += 2;
5552
5553 /* OUI */
5554 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
5555 p2pielen += 4;
5556
5557 /* Sub Category ID */
5558 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
5559 p2pielen += 2;
5560
5561 /* Number of Secondary Device Types */
5562 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
5563
5564 /* Device Name */
5565 /* Type: */
5566 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
5567 p2pielen += 2;
5568
5569 /* Length: */
5570 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
5571 p2pielen += 2;
5572
5573 /* Value: */
5574 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
5575 p2pielen += pwdinfo->device_name_len;
5576
5577 /* P2P Interface */
5578 /* Type: */
5579 p2pie[p2pielen++] = P2P_ATTR_INTERFACE;
5580
5581 /* Length: */
5582 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x000D);
5583 p2pielen += 2;
5584
5585 /* Value: */
5586 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Device Address */
5587 p2pielen += ETH_ALEN;
5588
5589 p2pie[p2pielen++] = 1; /* P2P Interface Address Count */
5590
5591 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Interface Address List */
5592 p2pielen += ETH_ALEN;
5593
5594 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
5595 }
5596
5597 #endif /* CONFIG_88EU_P2P */
5598
5599 pattrib->last_txcmdsz = pattrib->pktlen;
5600 dump_mgntframe(padapter, pmgntframe);
5601
5602 ret = _SUCCESS;
5603
5604 exit:
5605 if (ret == _SUCCESS)
5606 rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
5607 else
5608 rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
5609
5610 return;
5611 }
5612
5613 /* when wait_ack is true, this function should be called at process context */
5614 static int _issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
5615 {
5616 int ret = _FAIL;
5617 struct xmit_frame *pmgntframe;
5618 struct pkt_attrib *pattrib;
5619 unsigned char *pframe;
5620 struct rtw_ieee80211_hdr *pwlanhdr;
5621 __le16 *fctrl;
5622 struct xmit_priv *pxmitpriv;
5623 struct mlme_ext_priv *pmlmeext;
5624 struct mlme_ext_info *pmlmeinfo;
5625
5626 if (!padapter)
5627 goto exit;
5628
5629 pxmitpriv = &(padapter->xmitpriv);
5630 pmlmeext = &(padapter->mlmeextpriv);
5631 pmlmeinfo = &(pmlmeext->mlmext_info);
5632
5633 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5634 if (pmgntframe == NULL)
5635 goto exit;
5636
5637 /* update attribute */
5638 pattrib = &pmgntframe->attrib;
5639 update_mgntframe_attrib(padapter, pattrib);
5640 pattrib->retry_ctrl = false;
5641
5642 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5643
5644 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5645 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5646
5647 fctrl = &(pwlanhdr->frame_ctl);
5648 *(fctrl) = 0;
5649
5650 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5651 SetFrDs(fctrl);
5652 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5653 SetToDs(fctrl);
5654
5655 if (power_mode)
5656 SetPwrMgt(fctrl);
5657
5658 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5659 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5660 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5661
5662 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5663 pmlmeext->mgnt_seq++;
5664 SetFrameSubType(pframe, WIFI_DATA_NULL);
5665
5666 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5667 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5668
5669 pattrib->last_txcmdsz = pattrib->pktlen;
5670
5671 if (wait_ack) {
5672 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5673 } else {
5674 dump_mgntframe(padapter, pmgntframe);
5675 ret = _SUCCESS;
5676 }
5677
5678 exit:
5679 return ret;
5680 }
5681
5682
5683 /* when wait_ms > 0 , this function should be called at process context */
5684 /* da == NULL for station mode */
5685 int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
5686 {
5687 int ret;
5688 int i = 0;
5689 u32 start = jiffies;
5690 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5691 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5692
5693 /* da == NULL, assume it's null data for sta to ap*/
5694 if (da == NULL)
5695 da = get_my_bssid(&(pmlmeinfo->network));
5696
5697 do {
5698 ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0 ? true : false);
5699
5700 i++;
5701
5702 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5703 break;
5704
5705 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5706 msleep(wait_ms);
5707 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5708
5709 if (ret != _FAIL) {
5710 ret = _SUCCESS;
5711 goto exit;
5712 }
5713
5714 if (try_cnt && wait_ms) {
5715 if (da)
5716 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5717 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5718 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5719 else
5720 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5721 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5722 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5723 }
5724 exit:
5725 return ret;
5726 }
5727
5728 /* when wait_ack is true, this function should be called at process context */
5729 static int _issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
5730 {
5731 int ret = _FAIL;
5732 struct xmit_frame *pmgntframe;
5733 struct pkt_attrib *pattrib;
5734 unsigned char *pframe;
5735 struct rtw_ieee80211_hdr *pwlanhdr;
5736 __le16 *fctrl;
5737 unsigned short *qc;
5738 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5739 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5740 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5741
5742 DBG_88E("%s\n", __func__);
5743
5744 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5745 if (pmgntframe == NULL)
5746 goto exit;
5747
5748 /* update attribute */
5749 pattrib = &pmgntframe->attrib;
5750 update_mgntframe_attrib(padapter, pattrib);
5751
5752 pattrib->hdrlen += 2;
5753 pattrib->qos_en = true;
5754 pattrib->eosp = 1;
5755 pattrib->ack_policy = 0;
5756 pattrib->mdata = 0;
5757
5758 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5759
5760 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5761 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5762
5763 fctrl = &(pwlanhdr->frame_ctl);
5764 *(fctrl) = 0;
5765
5766 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5767 SetFrDs(fctrl);
5768 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5769 SetToDs(fctrl);
5770
5771 if (pattrib->mdata)
5772 SetMData(fctrl);
5773
5774 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
5775
5776 SetPriority(qc, tid);
5777
5778 SetEOSP(qc, pattrib->eosp);
5779
5780 SetAckpolicy(qc, pattrib->ack_policy);
5781
5782 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5783 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5784 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5785
5786 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5787 pmlmeext->mgnt_seq++;
5788 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
5789
5790 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5791 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5792
5793 pattrib->last_txcmdsz = pattrib->pktlen;
5794
5795 if (wait_ack) {
5796 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5797 } else {
5798 dump_mgntframe(padapter, pmgntframe);
5799 ret = _SUCCESS;
5800 }
5801
5802 exit:
5803 return ret;
5804 }
5805
5806 /* when wait_ms > 0 , this function should be called at process context */
5807 /* da == NULL for station mode */
5808 int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
5809 {
5810 int ret;
5811 int i = 0;
5812 u32 start = jiffies;
5813 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5814 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5815
5816 /* da == NULL, assume it's null data for sta to ap*/
5817 if (da == NULL)
5818 da = get_my_bssid(&(pmlmeinfo->network));
5819
5820 do {
5821 ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0 ? true : false);
5822
5823 i++;
5824
5825 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5826 break;
5827
5828 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5829 msleep(wait_ms);
5830 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5831
5832 if (ret != _FAIL) {
5833 ret = _SUCCESS;
5834 goto exit;
5835 }
5836
5837 if (try_cnt && wait_ms) {
5838 if (da)
5839 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5840 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5841 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5842 else
5843 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5844 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5845 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5846 }
5847 exit:
5848 return ret;
5849 }
5850
5851 static int _issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack)
5852 {
5853 struct xmit_frame *pmgntframe;
5854 struct pkt_attrib *pattrib;
5855 unsigned char *pframe;
5856 struct rtw_ieee80211_hdr *pwlanhdr;
5857 __le16 *fctrl;
5858 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5859 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5860 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5861 int ret = _FAIL;
5862 __le16 le_tmp;
5863 #ifdef CONFIG_88EU_P2P
5864 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5865 #endif /* CONFIG_88EU_P2P */
5866
5867 #ifdef CONFIG_88EU_P2P
5868 if (!(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) && (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
5869 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
5870 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
5871 }
5872 #endif /* CONFIG_88EU_P2P */
5873
5874 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5875 if (pmgntframe == NULL)
5876 goto exit;
5877
5878 /* update attribute */
5879 pattrib = &pmgntframe->attrib;
5880 update_mgntframe_attrib(padapter, pattrib);
5881 pattrib->retry_ctrl = false;
5882
5883 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5884
5885 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5886 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5887
5888 fctrl = &(pwlanhdr->frame_ctl);
5889 *(fctrl) = 0;
5890
5891 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5892 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5893 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5894
5895 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5896 pmlmeext->mgnt_seq++;
5897 SetFrameSubType(pframe, WIFI_DEAUTH);
5898
5899 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5900 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5901
5902 le_tmp = cpu_to_le16(reason);
5903 pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&le_tmp, &(pattrib->pktlen));
5904
5905 pattrib->last_txcmdsz = pattrib->pktlen;
5906
5907
5908 if (wait_ack) {
5909 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5910 } else {
5911 dump_mgntframe(padapter, pmgntframe);
5912 ret = _SUCCESS;
5913 }
5914
5915 exit:
5916 return ret;
5917 }
5918
5919 int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason)
5920 {
5921 DBG_88E("%s to %pM\n", __func__, da);
5922 return _issue_deauth(padapter, da, reason, false);
5923 }
5924
5925 int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
5926 int wait_ms)
5927 {
5928 int ret;
5929 int i = 0;
5930 u32 start = jiffies;
5931
5932 do {
5933 ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? true : false);
5934
5935 i++;
5936
5937 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5938 break;
5939
5940 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5941 msleep(wait_ms);
5942 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5943
5944 if (ret != _FAIL) {
5945 ret = _SUCCESS;
5946 goto exit;
5947 }
5948
5949 if (try_cnt && wait_ms) {
5950 if (da)
5951 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5952 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5953 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5954 else
5955 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5956 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5957 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5958 }
5959 exit:
5960 return ret;
5961 }
5962
5963 void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
5964 {
5965 struct xmit_frame *pmgntframe;
5966 struct pkt_attrib *pattrib;
5967 unsigned char *pframe;
5968 struct rtw_ieee80211_hdr *pwlanhdr;
5969 __le16 *fctrl;
5970 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5971 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5972
5973
5974 DBG_88E(FUNC_NDEV_FMT" ra =%pM, ch:%u, offset:%u\n",
5975 FUNC_NDEV_ARG(padapter->pnetdev), ra, new_ch, ch_offset);
5976
5977 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5978 if (pmgntframe == NULL)
5979 return;
5980
5981 /* update attribute */
5982 pattrib = &pmgntframe->attrib;
5983 update_mgntframe_attrib(padapter, pattrib);
5984
5985 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5986
5987 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5988 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5989
5990 fctrl = &(pwlanhdr->frame_ctl);
5991 *(fctrl) = 0;
5992
5993 memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
5994 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); /* TA */
5995 memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
5996
5997 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5998 pmlmeext->mgnt_seq++;
5999 SetFrameSubType(pframe, WIFI_ACTION);
6000
6001 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6002 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6003
6004 /* category, action */
6005 {
6006 u8 category, action;
6007 category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
6008 action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
6009
6010 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6011 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6012 }
6013
6014 pframe = rtw_set_ie_ch_switch (pframe, &(pattrib->pktlen), 0, new_ch, 0);
6015 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
6016 hal_ch_offset_to_secondary_ch_offset(ch_offset));
6017
6018 pattrib->last_txcmdsz = pattrib->pktlen;
6019
6020 dump_mgntframe(padapter, pmgntframe);
6021 }
6022
6023 void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status)
6024 {
6025 u8 category = RTW_WLAN_CATEGORY_BACK;
6026 u16 start_seq;
6027 u16 BA_para_set;
6028 u16 reason_code;
6029 u16 BA_timeout_value;
6030 __le16 le_tmp;
6031 u16 BA_starting_seqctrl = 0;
6032 enum ht_cap_ampdu_factor max_rx_ampdu_factor;
6033 struct xmit_frame *pmgntframe;
6034 struct pkt_attrib *pattrib;
6035 u8 *pframe;
6036 struct rtw_ieee80211_hdr *pwlanhdr;
6037 __le16 *fctrl;
6038 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6039 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6040 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6041 struct sta_info *psta;
6042 struct sta_priv *pstapriv = &padapter->stapriv;
6043 struct registry_priv *pregpriv = &padapter->registrypriv;
6044
6045 DBG_88E("%s, category=%d, action=%d, status=%d\n", __func__, category, action, status);
6046
6047 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
6048 if (pmgntframe == NULL)
6049 return;
6050
6051 /* update attribute */
6052 pattrib = &pmgntframe->attrib;
6053 update_mgntframe_attrib(padapter, pattrib);
6054
6055 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6056
6057 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6058 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6059
6060 fctrl = &(pwlanhdr->frame_ctl);
6061 *(fctrl) = 0;
6062
6063 /* memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */
6064 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
6065 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6066 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6067
6068 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
6069 pmlmeext->mgnt_seq++;
6070 SetFrameSubType(pframe, WIFI_ACTION);
6071
6072 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6073 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6074
6075 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6076 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6077
6078 if (category == 3) {
6079 switch (action) {
6080 case 0: /* ADDBA req */
6081 do {
6082 pmlmeinfo->dialogToken++;
6083 } while (pmlmeinfo->dialogToken == 0);
6084 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
6085
6086 BA_para_set = (0x1002 | ((status & 0xf) << 2)); /* immediate ack & 64 buffer size */
6087 le_tmp = cpu_to_le16(BA_para_set);
6088 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6089
6090 BA_timeout_value = 5000;/* 5ms */
6091 le_tmp = cpu_to_le16(BA_timeout_value);
6092 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6093
6094 psta = rtw_get_stainfo(pstapriv, raddr);
6095 if (psta != NULL) {
6096 start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07]&0xfff) + 1;
6097
6098 DBG_88E("BA_starting_seqctrl=%d for TID=%d\n", start_seq, status & 0x07);
6099
6100 psta->BA_starting_seqctrl[status & 0x07] = start_seq;
6101
6102 BA_starting_seqctrl = start_seq << 4;
6103 }
6104 le_tmp = cpu_to_le16(BA_starting_seqctrl);
6105 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6106 break;
6107 case 1: /* ADDBA rsp */
6108 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
6109 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
6110
6111 BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f;
6112 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
6113 switch (max_rx_ampdu_factor) {
6114 case MAX_AMPDU_FACTOR_64K:
6115 BA_para_set |= 0x1000; /* 64 buffer size */
6116 break;
6117 case MAX_AMPDU_FACTOR_32K:
6118 BA_para_set |= 0x0800; /* 32 buffer size */
6119 break;
6120 case MAX_AMPDU_FACTOR_16K:
6121 BA_para_set |= 0x0400; /* 16 buffer size */
6122 break;
6123 case MAX_AMPDU_FACTOR_8K:
6124 BA_para_set |= 0x0200; /* 8 buffer size */
6125 break;
6126 default:
6127 BA_para_set |= 0x1000; /* 64 buffer size */
6128 break;
6129 }
6130
6131 if (pregpriv->ampdu_amsdu == 0)/* disabled */
6132 BA_para_set = BA_para_set & ~BIT(0);
6133 else if (pregpriv->ampdu_amsdu == 1)/* enabled */
6134 BA_para_set = BA_para_set | BIT(0);
6135 le_tmp = cpu_to_le16(BA_para_set);
6136
6137 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6138 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
6139 break;
6140 case 2:/* DELBA */
6141 BA_para_set = (status & 0x1F) << 3;
6142 le_tmp = cpu_to_le16(BA_para_set);
6143 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6144
6145 reason_code = 37;/* Requested from peer STA as it does not want to use the mechanism */
6146 le_tmp = cpu_to_le16(reason_code);
6147 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6148 break;
6149 default:
6150 break;
6151 }
6152 }
6153
6154 pattrib->last_txcmdsz = pattrib->pktlen;
6155
6156 dump_mgntframe(padapter, pmgntframe);
6157 }
6158
6159 static void issue_action_BSSCoexistPacket(struct adapter *padapter)
6160 {
6161 struct list_head *plist, *phead;
6162 unsigned char category, action;
6163 struct xmit_frame *pmgntframe;
6164 struct pkt_attrib *pattrib;
6165 unsigned char *pframe;
6166 struct rtw_ieee80211_hdr *pwlanhdr;
6167 __le16 *fctrl;
6168 struct wlan_network *pnetwork = NULL;
6169 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6170 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6171 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6172 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6173 struct __queue *queue = &(pmlmepriv->scanned_queue);
6174 u8 InfoContent[16] = {0};
6175 u8 ICS[8][15];
6176 if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
6177 return;
6178
6179 if (pmlmeinfo->bwmode_updated)
6180 return;
6181
6182
6183 DBG_88E("%s\n", __func__);
6184
6185
6186 category = RTW_WLAN_CATEGORY_PUBLIC;
6187 action = ACT_PUBLIC_BSSCOEXIST;
6188
6189 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
6190 if (pmgntframe == NULL)
6191 return;
6192
6193 /* update attribute */
6194 pattrib = &pmgntframe->attrib;
6195 update_mgntframe_attrib(padapter, pattrib);
6196
6197 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6198
6199 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6200 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6201
6202 fctrl = &(pwlanhdr->frame_ctl);
6203 *(fctrl) = 0;
6204
6205 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6206 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6207 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6208
6209 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
6210 pmlmeext->mgnt_seq++;
6211 SetFrameSubType(pframe, WIFI_ACTION);
6212
6213 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6214 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6215
6216 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6217 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6218
6219
6220 /* */
6221 if (pmlmepriv->num_FortyMHzIntolerant > 0) {
6222 u8 iedata = 0;
6223
6224 iedata |= BIT(2);/* 20 MHz BSS Width Request */
6225
6226 pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
6227 }
6228
6229
6230 /* */
6231 memset(ICS, 0, sizeof(ICS));
6232 if (pmlmepriv->num_sta_no_ht > 0) {
6233 int i;
6234
6235 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
6236
6237 phead = get_list_head(queue);
6238 plist = phead->next;
6239
6240 while (phead != plist) {
6241 int len;
6242 u8 *p;
6243 struct wlan_bssid_ex *pbss_network;
6244
6245 pnetwork = container_of(plist, struct wlan_network, list);
6246
6247 plist = plist->next;
6248
6249 pbss_network = (struct wlan_bssid_ex *)&pnetwork->network;
6250
6251 p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
6252 if ((p == NULL) || (len == 0)) { /* non-HT */
6253 if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14))
6254 continue;
6255
6256 ICS[0][pbss_network->Configuration.DSConfig] = 1;
6257
6258 if (ICS[0][0] == 0)
6259 ICS[0][0] = 1;
6260 }
6261 }
6262 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
6263
6264 for (i = 0; i < 8; i++) {
6265 if (ICS[i][0] == 1) {
6266 int j, k = 0;
6267
6268 InfoContent[k] = i;
6269 /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */
6270 k++;
6271
6272 for (j = 1; j <= 14; j++) {
6273 if (ICS[i][j] == 1) {
6274 if (k < 16) {
6275 InfoContent[k] = j; /* channel number */
6276 /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
6277 k++;
6278 }
6279 }
6280 }
6281
6282 pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
6283 }
6284 }
6285 }
6286
6287
6288 pattrib->last_txcmdsz = pattrib->pktlen;
6289
6290 dump_mgntframe(padapter, pmgntframe);
6291 }
6292
6293 unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr)
6294 {
6295 struct sta_priv *pstapriv = &padapter->stapriv;
6296 struct sta_info *psta = NULL;
6297 /* struct recv_reorder_ctrl *preorder_ctrl; */
6298 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6299 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6300 u16 tid;
6301
6302 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
6303 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
6304 return _SUCCESS;
6305
6306 psta = rtw_get_stainfo(pstapriv, addr);
6307 if (psta == NULL)
6308 return _SUCCESS;
6309
6310 if (initiator == 0) { /* recipient */
6311 for (tid = 0; tid < MAXTID; tid++) {
6312 if (psta->recvreorder_ctrl[tid].enable) {
6313 DBG_88E("rx agg disable tid(%d)\n", tid);
6314 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6315 psta->recvreorder_ctrl[tid].enable = false;
6316 psta->recvreorder_ctrl[tid].indicate_seq = 0xffff;
6317 }
6318 }
6319 } else if (initiator == 1) { /* originator */
6320 for (tid = 0; tid < MAXTID; tid++) {
6321 if (psta->htpriv.agg_enable_bitmap & BIT(tid)) {
6322 DBG_88E("tx agg disable tid(%d)\n", tid);
6323 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6324 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
6325 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
6326 }
6327 }
6328 }
6329
6330 return _SUCCESS;
6331 }
6332
6333 unsigned int send_beacon(struct adapter *padapter)
6334 {
6335 u8 bxmitok = false;
6336 int issue = 0;
6337 int poll = 0;
6338
6339 u32 start = jiffies;
6340
6341 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
6342 do {
6343 issue_beacon(padapter, 100);
6344 issue++;
6345 do {
6346 yield();
6347 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
6348 poll++;
6349 } while ((poll%10) != 0 && !bxmitok && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6350 } while (!bxmitok && issue < 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6351
6352 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
6353 return _FAIL;
6354 if (!bxmitok) {
6355 DBG_88E("%s fail! %u ms\n", __func__, rtw_get_passing_time_ms(start));
6356 return _FAIL;
6357 } else {
6358 u32 passing_time = rtw_get_passing_time_ms(start);
6359
6360 if (passing_time > 100 || issue > 3)
6361 DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", __func__, issue, poll, rtw_get_passing_time_ms(start));
6362 return _SUCCESS;
6363 }
6364 }
6365
6366 /****************************************************************************
6367
6368 Following are some utility functions for WiFi MLME
6369
6370 *****************************************************************************/
6371
6372 void site_survey(struct adapter *padapter)
6373 {
6374 unsigned char survey_channel = 0, val8;
6375 enum rt_scan_type ScanType = SCAN_PASSIVE;
6376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6377 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6378 u32 initialgain = 0;
6379
6380 #ifdef CONFIG_88EU_P2P
6381 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
6382
6383 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6384 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
6385 survey_channel = pwdinfo->rx_invitereq_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6386 } else {
6387 survey_channel = pwdinfo->p2p_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6388 }
6389 ScanType = SCAN_ACTIVE;
6390 } else if (rtw_p2p_findphase_ex_is_social(pwdinfo)) {
6391 /* Commented by Albert 2011/06/03 */
6392 /* The driver is in the find phase, it should go through the social channel. */
6393 int ch_set_idx;
6394 survey_channel = pwdinfo->social_chan[pmlmeext->sitesurvey_res.channel_idx];
6395 ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, survey_channel);
6396 if (ch_set_idx >= 0)
6397 ScanType = pmlmeext->channel_set[ch_set_idx].ScanType;
6398 else
6399 ScanType = SCAN_ACTIVE;
6400 } else
6401 #endif /* CONFIG_88EU_P2P */
6402 {
6403 struct rtw_ieee80211_channel *ch;
6404 if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) {
6405 ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx];
6406 survey_channel = ch->hw_value;
6407 ScanType = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
6408 }
6409 }
6410
6411 if (survey_channel != 0) {
6412 /* PAUSE 4-AC Queue when site_survey */
6413 /* rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6414 /* val8 |= 0x0f; */
6415 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6416 if (pmlmeext->sitesurvey_res.channel_idx == 0)
6417 set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6418 else
6419 SelectChannel(padapter, survey_channel);
6420
6421 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */
6422 #ifdef CONFIG_88EU_P2P
6423 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) ||
6424 rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6425 issue_probereq_p2p(padapter, NULL);
6426 issue_probereq_p2p(padapter, NULL);
6427 issue_probereq_p2p(padapter, NULL);
6428 } else
6429 #endif /* CONFIG_88EU_P2P */
6430 {
6431 int i;
6432 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
6433 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
6434 /* todo: to issue two probe req??? */
6435 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6436 /* msleep(SURVEY_TO>>1); */
6437 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6438 }
6439 }
6440
6441 if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
6442 /* todo: to issue two probe req??? */
6443 issue_probereq(padapter, NULL, NULL);
6444 /* msleep(SURVEY_TO>>1); */
6445 issue_probereq(padapter, NULL, NULL);
6446 }
6447 }
6448 }
6449
6450 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6451 } else {
6452 /* channel number is 0 or this channel is not valid. */
6453
6454 #ifdef CONFIG_88EU_P2P
6455 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6456 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6457 /* Set the find_phase_state_exchange_cnt to P2P_FINDPHASE_EX_CNT. */
6458 /* This will let the following flow to run the scanning end. */
6459 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
6460 }
6461 }
6462
6463 if (rtw_p2p_findphase_ex_is_needed(pwdinfo)) {
6464 /* Set the P2P State to the listen state of find phase and set the current channel to the listen channel */
6465 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6466 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_LISTEN);
6467 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6468
6469 initialgain = 0xff; /* restore RX GAIN */
6470 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6471 /* turn on dynamic functions */
6472 Restore_DM_Func_Flag(padapter);
6473 /* Switch_DM_Func(padapter, DYNAMIC_FUNC_DIG|DYNAMIC_FUNC_HP|DYNAMIC_FUNC_SS, true); */
6474
6475 _set_timer(&pwdinfo->find_phase_timer, (u32)((u32)(pwdinfo->listen_dwell) * 100));
6476 } else
6477 #endif /* CONFIG_88EU_P2P */
6478 {
6479 /* 20100721:Interrupt scan operation here. */
6480 /* For SW antenna diversity before link, it needs to switch to another antenna and scan again. */
6481 /* It compares the scan result and select better one to do connection. */
6482 if (rtw_hal_antdiv_before_linked(padapter)) {
6483 pmlmeext->sitesurvey_res.bss_cnt = 0;
6484 pmlmeext->sitesurvey_res.channel_idx = -1;
6485 pmlmeext->chan_scan_time = SURVEY_TO / 2;
6486 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6487 return;
6488 }
6489 #ifdef CONFIG_88EU_P2P
6490 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
6491 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
6492 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
6493 #endif /* CONFIG_88EU_P2P */
6494
6495 pmlmeext->sitesurvey_res.state = SCAN_COMPLETE;
6496
6497 /* switch back to the original channel */
6498
6499 #ifdef CONFIG_88EU_P2P
6500 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN))
6501 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6502 else
6503 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6504 #endif /* CONFIG_88EU_P2P */
6505
6506 /* flush 4-AC Queue after site_survey */
6507 /* val8 = 0; */
6508 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6509
6510 /* config MSR */
6511 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6512
6513 initialgain = 0xff; /* restore RX GAIN */
6514 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6515 /* turn on dynamic functions */
6516 Restore_DM_Func_Flag(padapter);
6517 /* Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); */
6518
6519 if (is_client_associated_to_ap(padapter))
6520 issue_nulldata(padapter, NULL, 0, 3, 500);
6521
6522 val8 = 0; /* survey done */
6523 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
6524
6525 report_surveydone_event(padapter);
6526
6527 pmlmeext->chan_scan_time = SURVEY_TO;
6528 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6529
6530 issue_action_BSSCoexistPacket(padapter);
6531 issue_action_BSSCoexistPacket(padapter);
6532 issue_action_BSSCoexistPacket(padapter);
6533 }
6534 }
6535 return;
6536 }
6537
6538 /* collect bss info from Beacon and Probe request/response frames. */
6539 u8 collect_bss_info(struct adapter *padapter, struct recv_frame *precv_frame, struct wlan_bssid_ex *bssid)
6540 {
6541 int i;
6542 u32 len;
6543 u8 *p;
6544 u16 val16, subtype;
6545 u8 *pframe = precv_frame->rx_data;
6546 u32 packet_len = precv_frame->len;
6547 u8 ie_offset;
6548 struct registry_priv *pregistrypriv = &padapter->registrypriv;
6549 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6550 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6551
6552 len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
6553
6554 if (len > MAX_IE_SZ)
6555 return _FAIL;
6556
6557 memset(bssid, 0, sizeof(struct wlan_bssid_ex));
6558
6559 subtype = GetFrameSubType(pframe);
6560
6561 if (subtype == WIFI_BEACON) {
6562 bssid->Reserved[0] = 1;
6563 ie_offset = _BEACON_IE_OFFSET_;
6564 } else {
6565 /* FIXME : more type */
6566 if (subtype == WIFI_PROBEREQ) {
6567 ie_offset = _PROBEREQ_IE_OFFSET_;
6568 bssid->Reserved[0] = 2;
6569 } else if (subtype == WIFI_PROBERSP) {
6570 ie_offset = _PROBERSP_IE_OFFSET_;
6571 bssid->Reserved[0] = 3;
6572 } else {
6573 bssid->Reserved[0] = 0;
6574 ie_offset = _FIXED_IE_LENGTH_;
6575 }
6576 }
6577
6578 bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
6579
6580 /* below is to copy the information element */
6581 bssid->IELength = len;
6582 memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
6583
6584 /* get the signal strength in dBM.raw data */
6585 bssid->Rssi = precv_frame->attrib.phy_info.recvpower;
6586 bssid->PhyInfo.SignalQuality = precv_frame->attrib.phy_info.SignalQuality;/* in percentage */
6587 bssid->PhyInfo.SignalStrength = precv_frame->attrib.phy_info.SignalStrength;/* in percentage */
6588 rtw_hal_get_def_var(padapter, HAL_DEF_CURRENT_ANTENNA, &bssid->PhyInfo.Optimum_antenna);
6589
6590 /* checking SSID */
6591 p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset);
6592 if (p == NULL) {
6593 DBG_88E("marc: cannot find SSID for survey event\n");
6594 return _FAIL;
6595 }
6596
6597 if (len) {
6598 if (len > NDIS_802_11_LENGTH_SSID) {
6599 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6600 return _FAIL;
6601 }
6602 memcpy(bssid->Ssid.Ssid, (p + 2), len);
6603 bssid->Ssid.SsidLength = len;
6604 } else {
6605 bssid->Ssid.SsidLength = 0;
6606 }
6607
6608 memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
6609
6610 /* checking rate info... */
6611 i = 0;
6612 p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6613 if (p != NULL) {
6614 if (len > NDIS_802_11_LENGTH_RATES_EX) {
6615 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6616 return _FAIL;
6617 }
6618 memcpy(bssid->SupportedRates, (p + 2), len);
6619 i = len;
6620 }
6621
6622 p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6623 if (p != NULL) {
6624 if (len > (NDIS_802_11_LENGTH_RATES_EX-i)) {
6625 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6626 return _FAIL;
6627 }
6628 memcpy(bssid->SupportedRates + i, (p + 2), len);
6629 }
6630
6631 /* todo: */
6632 bssid->NetworkTypeInUse = Ndis802_11OFDM24;
6633
6634 if (bssid->IELength < 12)
6635 return _FAIL;
6636
6637 /* Checking for DSConfig */
6638 p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
6639
6640 bssid->Configuration.DSConfig = 0;
6641 bssid->Configuration.Length = 0;
6642
6643 if (p) {
6644 bssid->Configuration.DSConfig = *(p + 2);
6645 } else {/* In 5G, some ap do not have DSSET IE */
6646 /* checking HT info for channel */
6647 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
6648 if (p) {
6649 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
6650 bssid->Configuration.DSConfig = HT_info->primary_channel;
6651 } else { /* use current channel */
6652 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
6653 }
6654 }
6655
6656 if (subtype == WIFI_PROBEREQ) {
6657 /* FIXME */
6658 bssid->InfrastructureMode = Ndis802_11Infrastructure;
6659 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
6660 bssid->Privacy = 1;
6661 return _SUCCESS;
6662 }
6663
6664 bssid->Configuration.BeaconPeriod =
6665 get_unaligned_le16(rtw_get_beacon_interval_from_ie(bssid->IEs));
6666
6667 val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
6668
6669 if (val16 & BIT(0)) {
6670 bssid->InfrastructureMode = Ndis802_11Infrastructure;
6671 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
6672 } else {
6673 bssid->InfrastructureMode = Ndis802_11IBSS;
6674 memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
6675 }
6676
6677 if (val16 & BIT(4))
6678 bssid->Privacy = 1;
6679 else
6680 bssid->Privacy = 0;
6681
6682 bssid->Configuration.ATIMWindow = 0;
6683
6684 /* 20/40 BSS Coexistence check */
6685 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) {
6686 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6687 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
6688 if (p && len > 0) {
6689 struct HT_caps_element *pHT_caps;
6690 pHT_caps = (struct HT_caps_element *)(p + 2);
6691
6692 if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info)&BIT(14))
6693 pmlmepriv->num_FortyMHzIntolerant++;
6694 } else {
6695 pmlmepriv->num_sta_no_ht++;
6696 }
6697 }
6698
6699 /* mark bss info receiving from nearby channel as SignalQuality 101 */
6700 if (bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
6701 bssid->PhyInfo.SignalQuality = 101;
6702 return _SUCCESS;
6703 }
6704
6705 void start_create_ibss(struct adapter *padapter)
6706 {
6707 unsigned short caps;
6708 u8 val8;
6709 u8 join_type;
6710 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6711 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6712 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6713 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6714 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6715
6716 /* update wireless mode */
6717 update_wireless_mode(padapter);
6718
6719 /* update capability */
6720 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6721 update_capinfo(padapter, caps);
6722 if (caps&cap_IBSS) {/* adhoc master */
6723 val8 = 0xcf;
6724 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6725
6726 /* switch channel */
6727 /* SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE); */
6728 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6729
6730 beacon_timing_control(padapter);
6731
6732 /* set msr to WIFI_FW_ADHOC_STATE */
6733 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6734 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6735
6736 /* issue beacon */
6737 if (send_beacon(padapter) == _FAIL) {
6738 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("issuing beacon frame fail....\n"));
6739
6740 report_join_res(padapter, -1);
6741 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6742 } else {
6743 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
6744 join_type = 0;
6745 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
6746
6747 report_join_res(padapter, 1);
6748 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
6749 }
6750 } else {
6751 DBG_88E("start_create_ibss, invalid cap:%x\n", caps);
6752 return;
6753 }
6754 }
6755
6756 void start_clnt_join(struct adapter *padapter)
6757 {
6758 unsigned short caps;
6759 u8 val8;
6760 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6761 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6762 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6763 int beacon_timeout;
6764
6765 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6766 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6767
6768 /* update wireless mode */
6769 update_wireless_mode(padapter);
6770
6771 /* update capability */
6772 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6773 update_capinfo(padapter, caps);
6774 if (caps&cap_ESS) {
6775 Set_MSR(padapter, WIFI_FW_STATION_STATE);
6776
6777 val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
6778
6779 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6780
6781 /* switch channel */
6782 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6783
6784 /* here wait for receiving the beacon to start auth */
6785 /* and enable a timer */
6786 beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
6787 set_link_timer(pmlmeext, beacon_timeout);
6788 _set_timer(&padapter->mlmepriv.assoc_timer,
6789 (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO*REASSOC_LIMIT) + beacon_timeout);
6790
6791 pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
6792 } else if (caps&cap_IBSS) { /* adhoc client */
6793 Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
6794
6795 val8 = 0xcf;
6796 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6797
6798 /* switch channel */
6799 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6800
6801 beacon_timing_control(padapter);
6802
6803 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6804
6805 report_join_res(padapter, 1);
6806 } else {
6807 return;
6808 }
6809 }
6810
6811 void start_clnt_auth(struct adapter *padapter)
6812 {
6813 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6814 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6815
6816 _cancel_timer_ex(&pmlmeext->link_timer);
6817
6818 pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
6819 pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
6820
6821 pmlmeinfo->auth_seq = 1;
6822 pmlmeinfo->reauth_count = 0;
6823 pmlmeinfo->reassoc_count = 0;
6824 pmlmeinfo->link_count = 0;
6825 pmlmeext->retry = 0;
6826
6827
6828 /* Because of AP's not receiving deauth before */
6829 /* AP may: 1)not response auth or 2)deauth us after link is complete */
6830 /* issue deauth before issuing auth to deal with the situation */
6831 /* Commented by Albert 2012/07/21 */
6832 /* For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. */
6833 issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
6834
6835 DBG_88E_LEVEL(_drv_info_, "start auth\n");
6836 issue_auth(padapter, NULL, 0);
6837
6838 set_link_timer(pmlmeext, REAUTH_TO);
6839 }
6840
6841
6842 void start_clnt_assoc(struct adapter *padapter)
6843 {
6844 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6845 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6846
6847 _cancel_timer_ex(&pmlmeext->link_timer);
6848
6849 pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
6850 pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
6851
6852 issue_assocreq(padapter);
6853
6854 set_link_timer(pmlmeext, REASSOC_TO);
6855 }
6856
6857 unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
6858 {
6859 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6860 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6861
6862 /* check A3 */
6863 if (memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
6864 return _SUCCESS;
6865
6866 DBG_88E("%s\n", __func__);
6867
6868 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
6869 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
6870 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6871 report_del_sta_event(padapter, MacAddr, reason);
6872 } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
6873 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6874 report_join_res(padapter, -2);
6875 }
6876 }
6877 return _SUCCESS;
6878 }
6879
6880 static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid)
6881 {
6882 struct registry_priv *pregistrypriv;
6883 struct mlme_ext_priv *pmlmeext;
6884 struct rt_channel_info *chplan_new;
6885 u8 channel;
6886 u8 i;
6887
6888 pregistrypriv = &padapter->registrypriv;
6889 pmlmeext = &padapter->mlmeextpriv;
6890
6891 /* Adjust channel plan by AP Country IE */
6892 if (pregistrypriv->enable80211d &&
6893 (!pmlmeext->update_channel_plan_by_ap_done)) {
6894 u8 *ie, *p;
6895 u32 len;
6896 struct rt_channel_plan chplan_ap;
6897 struct rt_channel_info chplan_sta[MAX_CHANNEL_NUM];
6898 u8 country[4];
6899 u8 fcn; /* first channel number */
6900 u8 noc; /* number of channel */
6901 u8 j, k;
6902
6903 ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
6904 if (!ie)
6905 return;
6906 if (len < 6)
6907 return;
6908 ie += 2;
6909 p = ie;
6910 ie += len;
6911
6912 memset(country, 0, 4);
6913 memcpy(country, p, 3);
6914 p += 3;
6915 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
6916 ("%s: 802.11d country =%s\n", __func__, country));
6917
6918 i = 0;
6919 while ((ie - p) >= 3) {
6920 fcn = *(p++);
6921 noc = *(p++);
6922 p++;
6923
6924 for (j = 0; j < noc; j++) {
6925 if (fcn <= 14)
6926 channel = fcn + j; /* 2.4 GHz */
6927 else
6928 channel = fcn + j*4; /* 5 GHz */
6929
6930 chplan_ap.Channel[i++] = channel;
6931 }
6932 }
6933 chplan_ap.Len = i;
6934
6935 memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
6936
6937 memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
6938 chplan_new = pmlmeext->channel_set;
6939
6940 i = 0;
6941 j = 0;
6942 k = 0;
6943 if (pregistrypriv->wireless_mode & WIRELESS_11G) {
6944 do {
6945 if ((i == MAX_CHANNEL_NUM) ||
6946 (chplan_sta[i].ChannelNum == 0) ||
6947 (chplan_sta[i].ChannelNum > 14))
6948 break;
6949
6950 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
6951 break;
6952
6953 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
6954 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6955 chplan_new[k].ScanType = SCAN_ACTIVE;
6956 i++;
6957 j++;
6958 k++;
6959 } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
6960 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6961 chplan_new[k].ScanType = SCAN_PASSIVE;
6962 i++;
6963 k++;
6964 } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
6965 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6966 chplan_new[k].ScanType = SCAN_ACTIVE;
6967 j++;
6968 k++;
6969 }
6970 } while (1);
6971
6972 /* change AP not support channel to Passive scan */
6973 while ((i < MAX_CHANNEL_NUM) &&
6974 (chplan_sta[i].ChannelNum != 0) &&
6975 (chplan_sta[i].ChannelNum <= 14)) {
6976 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6977 chplan_new[k].ScanType = SCAN_PASSIVE;
6978 i++;
6979 k++;
6980 }
6981
6982 /* add channel AP supported */
6983 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) {
6984 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6985 chplan_new[k].ScanType = SCAN_ACTIVE;
6986 j++;
6987 k++;
6988 }
6989 } else {
6990 /* keep original STA 2.4G channel plan */
6991 while ((i < MAX_CHANNEL_NUM) &&
6992 (chplan_sta[i].ChannelNum != 0) &&
6993 (chplan_sta[i].ChannelNum <= 14)) {
6994 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6995 chplan_new[k].ScanType = chplan_sta[i].ScanType;
6996 i++;
6997 k++;
6998 }
6999
7000 /* skip AP 2.4G channel plan */
7001 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
7002 j++;
7003 }
7004
7005 /* keep original STA 5G channel plan */
7006 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
7007 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
7008 chplan_new[k].ScanType = chplan_sta[i].ScanType;
7009 i++;
7010 k++;
7011 }
7012
7013 pmlmeext->update_channel_plan_by_ap_done = 1;
7014 }
7015
7016 /* If channel is used by AP, set channel scan type to active */
7017 channel = bssid->Configuration.DSConfig;
7018 chplan_new = pmlmeext->channel_set;
7019 i = 0;
7020 while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].ChannelNum != 0)) {
7021 if (chplan_new[i].ChannelNum == channel) {
7022 if (chplan_new[i].ScanType == SCAN_PASSIVE) {
7023 chplan_new[i].ScanType = SCAN_ACTIVE;
7024 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
7025 ("%s: change channel %d scan type from passive to active\n",
7026 __func__, channel));
7027 }
7028 break;
7029 }
7030 i++;
7031 }
7032 }
7033
7034 /****************************************************************************
7035
7036 Following are the functions to report events
7037
7038 *****************************************************************************/
7039
7040 void report_survey_event(struct adapter *padapter,
7041 struct recv_frame *precv_frame)
7042 {
7043 struct cmd_obj *pcmd_obj;
7044 u8 *pevtcmd;
7045 u32 cmdsz;
7046 struct survey_event *psurvey_evt;
7047 struct C2HEvent_Header *pc2h_evt_hdr;
7048 struct mlme_ext_priv *pmlmeext;
7049 struct cmd_priv *pcmdpriv;
7050
7051 if (!padapter)
7052 return;
7053
7054 pmlmeext = &padapter->mlmeextpriv;
7055 pcmdpriv = &padapter->cmdpriv;
7056
7057
7058 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7059 if (pcmd_obj == NULL)
7060 return;
7061
7062 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
7063 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7064 if (pevtcmd == NULL) {
7065 kfree(pcmd_obj);
7066 return;
7067 }
7068
7069 INIT_LIST_HEAD(&pcmd_obj->list);
7070
7071 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7072 pcmd_obj->cmdsz = cmdsz;
7073 pcmd_obj->parmbuf = pevtcmd;
7074
7075 pcmd_obj->rsp = NULL;
7076 pcmd_obj->rspsz = 0;
7077
7078 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7079 pc2h_evt_hdr->len = sizeof(struct survey_event);
7080 pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
7081 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7082
7083 psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7084
7085 if (collect_bss_info(padapter, precv_frame, (struct wlan_bssid_ex *)&psurvey_evt->bss) == _FAIL) {
7086 kfree(pcmd_obj);
7087 kfree(pevtcmd);
7088 return;
7089 }
7090
7091 process_80211d(padapter, &psurvey_evt->bss);
7092
7093 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7094
7095 pmlmeext->sitesurvey_res.bss_cnt++;
7096
7097 return;
7098 }
7099
7100 void report_surveydone_event(struct adapter *padapter)
7101 {
7102 struct cmd_obj *pcmd_obj;
7103 u8 *pevtcmd;
7104 u32 cmdsz;
7105 struct surveydone_event *psurveydone_evt;
7106 struct C2HEvent_Header *pc2h_evt_hdr;
7107 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7108 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7109
7110 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7111 if (pcmd_obj == NULL)
7112 return;
7113
7114 cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
7115 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7116 if (pevtcmd == NULL) {
7117 kfree(pcmd_obj);
7118 return;
7119 }
7120
7121 INIT_LIST_HEAD(&pcmd_obj->list);
7122
7123 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7124 pcmd_obj->cmdsz = cmdsz;
7125 pcmd_obj->parmbuf = pevtcmd;
7126
7127 pcmd_obj->rsp = NULL;
7128 pcmd_obj->rspsz = 0;
7129
7130 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7131 pc2h_evt_hdr->len = sizeof(struct surveydone_event);
7132 pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
7133 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7134
7135 psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7136 psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
7137
7138 DBG_88E("survey done event(%x)\n", psurveydone_evt->bss_cnt);
7139
7140 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7141
7142 return;
7143 }
7144
7145 void report_join_res(struct adapter *padapter, int res)
7146 {
7147 struct cmd_obj *pcmd_obj;
7148 u8 *pevtcmd;
7149 u32 cmdsz;
7150 struct joinbss_event *pjoinbss_evt;
7151 struct C2HEvent_Header *pc2h_evt_hdr;
7152 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7153 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7154 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7155
7156 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7157 if (pcmd_obj == NULL)
7158 return;
7159
7160 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
7161 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7162 if (pevtcmd == NULL) {
7163 kfree(pcmd_obj);
7164 return;
7165 }
7166
7167 INIT_LIST_HEAD(&pcmd_obj->list);
7168
7169 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7170 pcmd_obj->cmdsz = cmdsz;
7171 pcmd_obj->parmbuf = pevtcmd;
7172
7173 pcmd_obj->rsp = NULL;
7174 pcmd_obj->rspsz = 0;
7175
7176 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7177 pc2h_evt_hdr->len = sizeof(struct joinbss_event);
7178 pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
7179 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7180
7181 pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7182 memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
7183 pjoinbss_evt->network.join_res = res;
7184 pjoinbss_evt->network.aid = res;
7185
7186 DBG_88E("report_join_res(%d)\n", res);
7187
7188
7189 rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
7190
7191
7192 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7193
7194 return;
7195 }
7196
7197 void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
7198 {
7199 struct cmd_obj *pcmd_obj;
7200 u8 *pevtcmd;
7201 u32 cmdsz;
7202 struct sta_info *psta;
7203 int mac_id;
7204 struct stadel_event *pdel_sta_evt;
7205 struct C2HEvent_Header *pc2h_evt_hdr;
7206 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7207 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7208
7209 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7210 if (pcmd_obj == NULL)
7211 return;
7212
7213 cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
7214 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7215 if (pevtcmd == NULL) {
7216 kfree(pcmd_obj);
7217 return;
7218 }
7219
7220 INIT_LIST_HEAD(&pcmd_obj->list);
7221
7222 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7223 pcmd_obj->cmdsz = cmdsz;
7224 pcmd_obj->parmbuf = pevtcmd;
7225
7226 pcmd_obj->rsp = NULL;
7227 pcmd_obj->rspsz = 0;
7228
7229 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7230 pc2h_evt_hdr->len = sizeof(struct stadel_event);
7231 pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
7232 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7233
7234 pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7235 memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7236 memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
7237
7238
7239 psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
7240 if (psta)
7241 mac_id = (int)psta->mac_id;
7242 else
7243 mac_id = (-1);
7244
7245 pdel_sta_evt->mac_id = mac_id;
7246
7247 DBG_88E("report_del_sta_event: delete STA, mac_id =%d\n", mac_id);
7248
7249 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7250
7251 return;
7252 }
7253
7254 void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx)
7255 {
7256 struct cmd_obj *pcmd_obj;
7257 u8 *pevtcmd;
7258 u32 cmdsz;
7259 struct stassoc_event *padd_sta_evt;
7260 struct C2HEvent_Header *pc2h_evt_hdr;
7261 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7262 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7263
7264 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7265 if (pcmd_obj == NULL)
7266 return;
7267
7268 cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
7269 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7270 if (pevtcmd == NULL) {
7271 kfree(pcmd_obj);
7272 return;
7273 }
7274
7275 INIT_LIST_HEAD(&pcmd_obj->list);
7276
7277 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7278 pcmd_obj->cmdsz = cmdsz;
7279 pcmd_obj->parmbuf = pevtcmd;
7280
7281 pcmd_obj->rsp = NULL;
7282 pcmd_obj->rspsz = 0;
7283
7284 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7285 pc2h_evt_hdr->len = sizeof(struct stassoc_event);
7286 pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
7287 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7288
7289 padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7290 memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7291 padd_sta_evt->cam_id = cam_idx;
7292
7293 DBG_88E("report_add_sta_event: add STA\n");
7294
7295 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7296
7297 return;
7298 }
7299
7300
7301 /****************************************************************************
7302
7303 Following are the event callback functions
7304
7305 *****************************************************************************/
7306
7307 /* for sta/adhoc mode */
7308 void update_sta_info(struct adapter *padapter, struct sta_info *psta)
7309 {
7310 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7311 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7312 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7313
7314 /* ERP */
7315 VCS_update(padapter, psta);
7316
7317 /* HT */
7318 if (pmlmepriv->htpriv.ht_option) {
7319 psta->htpriv.ht_option = true;
7320
7321 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
7322
7323 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps)))
7324 psta->htpriv.sgi = true;
7325
7326 psta->qos_option = true;
7327 } else {
7328 psta->htpriv.ht_option = false;
7329
7330 psta->htpriv.ampdu_enable = false;
7331
7332 psta->htpriv.sgi = false;
7333 psta->qos_option = false;
7334 }
7335 psta->htpriv.bwmode = pmlmeext->cur_bwmode;
7336 psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
7337
7338 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
7339 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
7340
7341 /* QoS */
7342 if (pmlmepriv->qospriv.qos_option)
7343 psta->qos_option = true;
7344
7345
7346 psta->state = _FW_LINKED;
7347 }
7348
7349 void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res)
7350 {
7351 struct sta_info *psta, *psta_bmc;
7352 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7353 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7354 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
7355 struct sta_priv *pstapriv = &padapter->stapriv;
7356 u8 join_type;
7357 u16 media_status;
7358
7359 if (join_res < 0) {
7360 join_type = 1;
7361 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7362 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7363
7364 /* restore to initial setting. */
7365 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7366
7367 goto exit_mlmeext_joinbss_event_callback;
7368 }
7369
7370 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7371 /* for bc/mc */
7372 psta_bmc = rtw_get_bcmc_stainfo(padapter);
7373 if (psta_bmc) {
7374 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc;
7375 update_bmc_sta_support_rate(padapter, psta_bmc->mac_id);
7376 Update_RA_Entry(padapter, psta_bmc->mac_id);
7377 }
7378 }
7379
7380
7381 /* turn on dynamic functions */
7382 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
7383
7384 /* update IOT-related issue */
7385 update_IOT_info(padapter);
7386
7387 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
7388
7389 /* BCN interval */
7390 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
7391
7392 /* update capability */
7393 update_capinfo(padapter, pmlmeinfo->capability);
7394
7395 /* WMM, Update EDCA param */
7396 WMMOnAssocRsp(padapter);
7397
7398 /* HT */
7399 HTOnAssocRsp(padapter);
7400
7401 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7402
7403 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
7404 if (psta) { /* only for infra. mode */
7405 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7406
7407 psta->wireless_mode = pmlmeext->cur_wireless_mode;
7408
7409 /* set per sta rate after updating HT cap. */
7410 set_sta_rate(padapter, psta);
7411 rtw_hal_set_hwreg(padapter, HW_VAR_TX_RPT_MAX_MACID, (u8 *)&psta->mac_id);
7412 media_status = (psta->mac_id<<8)|1; /* MACID|OPMODE: 1 means connect */
7413 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
7414 }
7415
7416 join_type = 2;
7417 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7418
7419 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
7420 /* correcting TSF */
7421 correct_TSF(padapter, pmlmeext);
7422 }
7423 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
7424
7425 exit_mlmeext_joinbss_event_callback:
7426
7427 DBG_88E("=>%s\n", __func__);
7428 }
7429
7430 void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta)
7431 {
7432 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7433 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7434 u8 join_type;
7435
7436 DBG_88E("%s\n", __func__);
7437
7438 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7439 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {/* adhoc master or sta_count>1 */
7440 /* nothing to do */
7441 } else { /* adhoc client */
7442 /* correcting TSF */
7443 correct_TSF(padapter, pmlmeext);
7444
7445 /* start beacon */
7446 if (send_beacon(padapter) == _FAIL) {
7447 pmlmeinfo->FW_sta_info[psta->mac_id].status = 0;
7448 pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE;
7449 return;
7450 }
7451 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
7452 }
7453
7454 join_type = 2;
7455 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7456 }
7457
7458 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7459
7460 /* rate radaptive */
7461 Update_RA_Entry(padapter, psta->mac_id);
7462
7463 /* update adhoc sta_info */
7464 update_sta_info(padapter, psta);
7465 }
7466
7467 void mlmeext_sta_del_event_callback(struct adapter *padapter)
7468 {
7469 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7470 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7471
7472 if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter)) {
7473 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7474 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7475
7476 /* restore to initial setting. */
7477 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7478
7479 /* switch to the 20M Hz mode after disconnect */
7480 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7481 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7482
7483 /* SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset); */
7484 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7485
7486
7487 flush_all_cam_entry(padapter);
7488
7489 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7490
7491 /* set MSR to no link state -> infra. mode */
7492 Set_MSR(padapter, _HW_STATE_STATION_);
7493
7494 _cancel_timer_ex(&pmlmeext->link_timer);
7495 }
7496 }
7497
7498 /****************************************************************************
7499
7500 Following are the functions for the timer handlers
7501
7502 *****************************************************************************/
7503 void _linked_rx_signal_strehgth_display(struct adapter *padapter);
7504 void _linked_rx_signal_strehgth_display(struct adapter *padapter)
7505 {
7506 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7507 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7508 u8 mac_id;
7509 int UndecoratedSmoothedPWDB;
7510 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
7511 mac_id = 0;
7512 else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
7513 mac_id = 2;
7514
7515 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &mac_id);
7516
7517 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
7518 DBG_88E("UndecoratedSmoothedPWDB:%d\n", UndecoratedSmoothedPWDB);
7519 }
7520
7521 static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta)
7522 {
7523 u8 ret = false;
7524
7525 if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)) &&
7526 sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta) &&
7527 sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta))
7528 ret = false;
7529 else
7530 ret = true;
7531
7532 sta_update_last_rx_pkts(psta);
7533
7534 return ret;
7535 }
7536
7537 void linked_status_chk(struct adapter *padapter)
7538 {
7539 u32 i;
7540 struct sta_info *psta;
7541 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7542 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7543 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7544 struct sta_priv *pstapriv = &padapter->stapriv;
7545
7546 if (padapter->bRxRSSIDisplay)
7547 _linked_rx_signal_strehgth_display(padapter);
7548
7549 if (is_client_associated_to_ap(padapter)) {
7550 /* linked infrastructure client mode */
7551
7552 int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
7553 int rx_chk_limit;
7554
7555 rx_chk_limit = 4;
7556 psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
7557 if (psta != NULL) {
7558 bool is_p2p_enable = false;
7559 #ifdef CONFIG_88EU_P2P
7560 is_p2p_enable = !rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE);
7561 #endif
7562
7563 if (!chk_ap_is_alive(padapter, psta))
7564 rx_chk = _FAIL;
7565
7566 if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
7567 tx_chk = _FAIL;
7568
7569 if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)) {
7570 u8 backup_oper_channel = 0;
7571
7572 /* switch to correct channel of current network before issue keep-alive frames */
7573 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
7574 backup_oper_channel = rtw_get_oper_ch(padapter);
7575 SelectChannel(padapter, pmlmeext->cur_channel);
7576 }
7577
7578 if (rx_chk != _SUCCESS)
7579 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 3, 1);
7580
7581 if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) || rx_chk != _SUCCESS) {
7582 tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
7583 /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
7584 if (tx_chk == _SUCCESS && !is_p2p_enable)
7585 rx_chk = _SUCCESS;
7586 }
7587
7588 /* back to the original operation channel */
7589 if (backup_oper_channel > 0)
7590 SelectChannel(padapter, backup_oper_channel);
7591 } else {
7592 if (rx_chk != _SUCCESS) {
7593 if (pmlmeext->retry == 0) {
7594 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7595 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7596 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7597 }
7598 }
7599
7600 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) {
7601 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0);
7602 }
7603 }
7604
7605 if (rx_chk == _FAIL) {
7606 pmlmeext->retry++;
7607 if (pmlmeext->retry > rx_chk_limit) {
7608 DBG_88E_LEVEL(_drv_always_, FUNC_ADPT_FMT" disconnect or roaming\n",
7609 FUNC_ADPT_ARG(padapter));
7610 receive_disconnect(padapter, pmlmeinfo->network.MacAddress,
7611 WLAN_REASON_EXPIRATION_CHK);
7612 return;
7613 }
7614 } else {
7615 pmlmeext->retry = 0;
7616 }
7617
7618 if (tx_chk == _FAIL) {
7619 pmlmeinfo->link_count &= 0xf;
7620 } else {
7621 pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
7622 pmlmeinfo->link_count = 0;
7623 }
7624 } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL) */
7625 } else if (is_client_associated_to_ibss(padapter)) {
7626 /* linked IBSS mode */
7627 /* for each assoc list entry to check the rx pkt counter */
7628 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
7629 if (pmlmeinfo->FW_sta_info[i].status == 1) {
7630 psta = pmlmeinfo->FW_sta_info[i].psta;
7631
7632 if (NULL == psta)
7633 continue;
7634 if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta)) {
7635 if (pmlmeinfo->FW_sta_info[i].retry < 3) {
7636 pmlmeinfo->FW_sta_info[i].retry++;
7637 } else {
7638 pmlmeinfo->FW_sta_info[i].retry = 0;
7639 pmlmeinfo->FW_sta_info[i].status = 0;
7640 report_del_sta_event(padapter, psta->hwaddr
7641 , 65535/* indicate disconnect caused by no rx */
7642 );
7643 }
7644 } else {
7645 pmlmeinfo->FW_sta_info[i].retry = 0;
7646 pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta);
7647 }
7648 }
7649 }
7650 }
7651 }
7652
7653 void survey_timer_hdl(struct adapter *padapter)
7654 {
7655 struct cmd_obj *ph2c;
7656 struct sitesurvey_parm *psurveyPara;
7657 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7658 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7659 #ifdef CONFIG_88EU_P2P
7660 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7661 #endif
7662
7663 /* issue rtw_sitesurvey_cmd */
7664 if (pmlmeext->sitesurvey_res.state > SCAN_START) {
7665 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
7666 pmlmeext->sitesurvey_res.channel_idx++;
7667
7668 if (pmlmeext->scan_abort) {
7669 #ifdef CONFIG_88EU_P2P
7670 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE)) {
7671 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
7672 pmlmeext->sitesurvey_res.channel_idx = 3;
7673 DBG_88E("%s idx:%d, cnt:%u\n", __func__
7674 , pmlmeext->sitesurvey_res.channel_idx
7675 , pwdinfo->find_phase_state_exchange_cnt
7676 );
7677 } else
7678 #endif
7679 {
7680 pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num;
7681 DBG_88E("%s idx:%d\n", __func__
7682 , pmlmeext->sitesurvey_res.channel_idx
7683 );
7684 }
7685
7686 pmlmeext->scan_abort = false;/* reset */
7687 }
7688
7689 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7690 if (ph2c == NULL)
7691 goto exit_survey_timer_hdl;
7692
7693 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_KERNEL);
7694 if (psurveyPara == NULL) {
7695 kfree(ph2c);
7696 goto exit_survey_timer_hdl;
7697 }
7698
7699 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
7700 rtw_enqueue_cmd(pcmdpriv, ph2c);
7701 }
7702
7703
7704 exit_survey_timer_hdl:
7705 return;
7706 }
7707
7708 void link_timer_hdl(struct adapter *padapter)
7709 {
7710 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7711 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7712
7713 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
7714 DBG_88E("link_timer_hdl:no beacon while connecting\n");
7715 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7716 report_join_res(padapter, -3);
7717 } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) {
7718 /* re-auth timer */
7719 if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) {
7720 pmlmeinfo->state = 0;
7721 report_join_res(padapter, -1);
7722 return;
7723 }
7724
7725 DBG_88E("link_timer_hdl: auth timeout and try again\n");
7726 pmlmeinfo->auth_seq = 1;
7727 issue_auth(padapter, NULL, 0);
7728 set_link_timer(pmlmeext, REAUTH_TO);
7729 } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) {
7730 /* re-assoc timer */
7731 if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) {
7732 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7733 report_join_res(padapter, -2);
7734 return;
7735 }
7736
7737 DBG_88E("link_timer_hdl: assoc timeout and try again\n");
7738 issue_assocreq(padapter);
7739 set_link_timer(pmlmeext, REASSOC_TO);
7740 }
7741 return;
7742 }
7743
7744 void addba_timer_hdl(struct sta_info *psta)
7745 {
7746 struct ht_priv *phtpriv;
7747
7748 if (!psta)
7749 return;
7750
7751 phtpriv = &psta->htpriv;
7752
7753 if ((phtpriv->ht_option) && (phtpriv->ampdu_enable)) {
7754 if (phtpriv->candidate_tid_bitmap)
7755 phtpriv->candidate_tid_bitmap = 0x0;
7756 }
7757 }
7758
7759 u8 NULL_hdl(struct adapter *padapter, u8 *pbuf)
7760 {
7761 return H2C_SUCCESS;
7762 }
7763
7764 u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
7765 {
7766 u8 type;
7767 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7768 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7769 struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
7770
7771 if (psetop->mode == Ndis802_11APMode) {
7772 pmlmeinfo->state = WIFI_FW_AP_STATE;
7773 type = _HW_STATE_AP_;
7774 } else if (psetop->mode == Ndis802_11Infrastructure) {
7775 pmlmeinfo->state &= ~(BIT(0)|BIT(1));/* clear state */
7776 pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */
7777 type = _HW_STATE_STATION_;
7778 } else if (psetop->mode == Ndis802_11IBSS) {
7779 type = _HW_STATE_ADHOC_;
7780 } else {
7781 type = _HW_STATE_NOLINK_;
7782 }
7783
7784 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
7785 /* Set_NETYPE0_MSR(padapter, type); */
7786
7787 return H2C_SUCCESS;
7788 }
7789
7790 u8 createbss_hdl(struct adapter *padapter, u8 *pbuf)
7791 {
7792 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7793 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7794 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7795 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7796 /* u32 initialgain; */
7797
7798
7799 if (pparm->network.InfrastructureMode == Ndis802_11APMode) {
7800 #ifdef CONFIG_88EU_AP_MODE
7801
7802 if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
7803 /* todo: */
7804 return H2C_SUCCESS;
7805 }
7806 #endif
7807 }
7808
7809 /* below is for ad-hoc master */
7810 if (pparm->network.InfrastructureMode == Ndis802_11IBSS) {
7811 rtw_joinbss_reset(padapter);
7812
7813 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7814 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7815 pmlmeinfo->ERP_enable = 0;
7816 pmlmeinfo->WMM_enable = 0;
7817 pmlmeinfo->HT_enable = 0;
7818 pmlmeinfo->HT_caps_enable = 0;
7819 pmlmeinfo->HT_info_enable = 0;
7820 pmlmeinfo->agg_enable_bitmap = 0;
7821 pmlmeinfo->candidate_tid_bitmap = 0;
7822
7823 /* disable dynamic functions, such as high power, DIG */
7824 Save_DM_Func_Flag(padapter);
7825 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
7826
7827 /* config the initial gain under linking, need to write the BB registers */
7828 /* initialgain = 0x1E; */
7829 /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */
7830
7831 /* cancel link timer */
7832 _cancel_timer_ex(&pmlmeext->link_timer);
7833
7834 /* clear CAM */
7835 flush_all_cam_entry(padapter);
7836
7837 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7838 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7839
7840 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7841 return H2C_PARAMETERS_ERROR;
7842
7843 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7844
7845 start_create_ibss(padapter);
7846 }
7847
7848 return H2C_SUCCESS;
7849 }
7850
7851 u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf)
7852 {
7853 u8 join_type;
7854 struct ndis_802_11_var_ie *pIE;
7855 struct registry_priv *pregpriv = &padapter->registrypriv;
7856 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7857 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7858 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7859 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7860 u32 i;
7861
7862 /* check already connecting to AP or not */
7863 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
7864 if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
7865 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 5, 100);
7866
7867 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7868
7869 /* clear CAM */
7870 flush_all_cam_entry(padapter);
7871
7872 _cancel_timer_ex(&pmlmeext->link_timer);
7873
7874 /* set MSR to nolink -> infra. mode */
7875 Set_MSR(padapter, _HW_STATE_STATION_);
7876
7877
7878 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7879 }
7880
7881 rtw_antenna_select_cmd(padapter, pparm->network.PhyInfo.Optimum_antenna, false);
7882
7883 rtw_joinbss_reset(padapter);
7884
7885 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7886 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7887 pmlmeinfo->ERP_enable = 0;
7888 pmlmeinfo->WMM_enable = 0;
7889 pmlmeinfo->HT_enable = 0;
7890 pmlmeinfo->HT_caps_enable = 0;
7891 pmlmeinfo->HT_info_enable = 0;
7892 pmlmeinfo->agg_enable_bitmap = 0;
7893 pmlmeinfo->candidate_tid_bitmap = 0;
7894 pmlmeinfo->bwmode_updated = false;
7895
7896 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7897 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7898
7899 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7900 return H2C_PARAMETERS_ERROR;
7901
7902 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7903
7904 /* Check AP vendor to move rtw_joinbss_cmd() */
7905
7906 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pnetwork->IELength;) {
7907 pIE = (struct ndis_802_11_var_ie *)(pnetwork->IEs + i);
7908
7909 switch (pIE->ElementID) {
7910 case _VENDOR_SPECIFIC_IE_:/* Get WMM IE. */
7911 if (!memcmp(pIE->data, WMM_OUI, 4))
7912 pmlmeinfo->WMM_enable = 1;
7913 break;
7914 case _HT_CAPABILITY_IE_: /* Get HT Cap IE. */
7915 pmlmeinfo->HT_caps_enable = 1;
7916 break;
7917 case _HT_EXTRA_INFO_IE_: /* Get HT Info IE. */
7918 pmlmeinfo->HT_info_enable = 1;
7919
7920 /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */
7921 {
7922 struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data);
7923
7924 if ((pregpriv->cbw40_enable) && (pht_info->infos[0] & BIT(2))) {
7925 /* switch to the 40M Hz mode according to the AP */
7926 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_40;
7927 switch (pht_info->infos[0] & 0x3) {
7928 case 1:
7929 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
7930 break;
7931 case 3:
7932 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
7933 break;
7934 default:
7935 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7936 break;
7937 }
7938
7939 DBG_88E("set ch/bw before connected\n");
7940 }
7941 }
7942 break;
7943 default:
7944 break;
7945 }
7946
7947 i += (pIE->Length + 2);
7948 }
7949 /* disable dynamic functions, such as high power, DIG */
7950
7951 /* config the initial gain under linking, need to write the BB registers */
7952
7953 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
7954 join_type = 0;
7955 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7956
7957 /* cancel link timer */
7958 _cancel_timer_ex(&pmlmeext->link_timer);
7959
7960 start_clnt_join(padapter);
7961
7962 return H2C_SUCCESS;
7963 }
7964
7965 u8 disconnect_hdl(struct adapter *padapter, unsigned char *pbuf)
7966 {
7967 struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
7968 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7969 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7970 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7971 u8 val8;
7972
7973 if (is_client_associated_to_ap(padapter))
7974 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms/100, 100);
7975
7976 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7977 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7978
7979 /* restore to initial setting. */
7980 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7981
7982 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
7983 /* Stop BCN */
7984 val8 = 0;
7985 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
7986 }
7987
7988
7989 /* set MSR to no link state -> infra. mode */
7990 Set_MSR(padapter, _HW_STATE_STATION_);
7991
7992 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7993
7994 /* switch to the 20M Hz mode after disconnect */
7995 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7996 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7997
7998 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7999
8000 flush_all_cam_entry(padapter);
8001
8002 _cancel_timer_ex(&pmlmeext->link_timer);
8003
8004 rtw_free_uc_swdec_pending_queue(padapter);
8005
8006 return H2C_SUCCESS;
8007 }
8008
8009 static int rtw_scan_ch_decision(struct adapter *padapter, struct rtw_ieee80211_channel *out,
8010 u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
8011 {
8012 int i, j;
8013 int set_idx;
8014 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8015
8016 /* clear out first */
8017 memset(out, 0, sizeof(struct rtw_ieee80211_channel)*out_num);
8018
8019 /* acquire channels from in */
8020 j = 0;
8021 for (i = 0; i < in_num; i++) {
8022 set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value);
8023 if (in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED) &&
8024 set_idx >= 0) {
8025 out[j] = in[i];
8026
8027 if (pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
8028 out[j].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
8029
8030 j++;
8031 }
8032 if (j >= out_num)
8033 break;
8034 }
8035
8036 /* if out is empty, use channel_set as default */
8037 if (j == 0) {
8038 for (i = 0; i < pmlmeext->max_chan_nums; i++) {
8039 out[i].hw_value = pmlmeext->channel_set[i].ChannelNum;
8040
8041 if (pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
8042 out[i].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
8043
8044 j++;
8045 }
8046 }
8047
8048 return j;
8049 }
8050
8051 u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf)
8052 {
8053 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8054 struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
8055 u8 bdelayscan = false;
8056 u8 val8;
8057 u32 initialgain;
8058 u32 i;
8059
8060 #ifdef CONFIG_88EU_P2P
8061 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
8062 #endif
8063
8064 if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE) {
8065 /* for first time sitesurvey_cmd */
8066 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, NULL);
8067
8068 pmlmeext->sitesurvey_res.state = SCAN_START;
8069 pmlmeext->sitesurvey_res.bss_cnt = 0;
8070 pmlmeext->sitesurvey_res.channel_idx = 0;
8071
8072 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
8073 if (pparm->ssid[i].SsidLength) {
8074 memcpy(pmlmeext->sitesurvey_res.ssid[i].Ssid, pparm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
8075 pmlmeext->sitesurvey_res.ssid[i].SsidLength = pparm->ssid[i].SsidLength;
8076 } else {
8077 pmlmeext->sitesurvey_res.ssid[i].SsidLength = 0;
8078 }
8079 }
8080
8081 pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter
8082 , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT
8083 , pparm->ch, pparm->ch_num
8084 );
8085
8086 pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode;
8087
8088 /* issue null data if associating to the AP */
8089 if (is_client_associated_to_ap(padapter)) {
8090 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
8091
8092 issue_nulldata(padapter, NULL, 1, 3, 500);
8093
8094 bdelayscan = true;
8095 }
8096 if (bdelayscan) {
8097 /* delay 50ms to protect nulldata(1). */
8098 set_survey_timer(pmlmeext, 50);
8099 return H2C_SUCCESS;
8100 }
8101 }
8102
8103 if ((pmlmeext->sitesurvey_res.state == SCAN_START) || (pmlmeext->sitesurvey_res.state == SCAN_TXNULL)) {
8104 /* disable dynamic functions, such as high power, DIG */
8105 Save_DM_Func_Flag(padapter);
8106 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
8107
8108 /* config the initial gain under scanning, need to write the BB registers */
8109 #ifdef CONFIG_88EU_P2P
8110 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
8111 initialgain = 0x1E;
8112 else
8113 initialgain = 0x28;
8114 #else /* CONFIG_88EU_P2P */
8115 initialgain = 0x1E;
8116 #endif /* CONFIG_88EU_P2P */
8117
8118 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
8119
8120 /* set MSR to no link state */
8121 Set_MSR(padapter, _HW_STATE_NOLINK_);
8122
8123 val8 = 1; /* under site survey */
8124 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
8125
8126 pmlmeext->sitesurvey_res.state = SCAN_PROCESS;
8127 }
8128
8129 site_survey(padapter);
8130
8131 return H2C_SUCCESS;
8132 }
8133
8134 u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf)
8135 {
8136 struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
8137 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8138 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8139
8140 if (pparm->mode < 4)
8141 pmlmeinfo->auth_algo = pparm->mode;
8142 return H2C_SUCCESS;
8143 }
8144
8145 u8 setkey_hdl(struct adapter *padapter, u8 *pbuf)
8146 {
8147 unsigned short ctrl;
8148 struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
8149 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8150 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8151 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8152
8153 /* main tx key for wep. */
8154 if (pparm->set_tx)
8155 pmlmeinfo->key_index = pparm->keyid;
8156
8157 /* write cam */
8158 ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
8159
8160 DBG_88E_LEVEL(_drv_info_, "set group key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) "
8161 "keyid:%d\n", pparm->algorithm, pparm->keyid);
8162 write_cam(padapter, pparm->keyid, ctrl, null_sta, pparm->key);
8163
8164 return H2C_SUCCESS;
8165 }
8166
8167 u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf)
8168 {
8169 u16 ctrl = 0;
8170 u8 cam_id;/* cam_entry */
8171 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8172 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8173 struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
8174
8175 /* cam_entry: */
8176 /* 0~3 for default key */
8177
8178 /* for concurrent mode (ap+sta): */
8179 /* default key is disable, using sw encrypt/decrypt */
8180 /* cam_entry = 4 for sta mode (macid = 0) */
8181 /* cam_entry(macid+3) = 5 ~ N for ap mode (aid = 1~N, macid = 2 ~N) */
8182
8183 /* for concurrent mode (sta+sta): */
8184 /* default key is disable, using sw encrypt/decrypt */
8185 /* cam_entry = 4 mapping to macid = 0 */
8186 /* cam_entry = 5 mapping to macid = 2 */
8187
8188 cam_id = 4;
8189
8190 DBG_88E_LEVEL(_drv_info_, "set pairwise key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) camid:%d\n",
8191 pparm->algorithm, cam_id);
8192 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
8193 struct sta_info *psta;
8194 struct sta_priv *pstapriv = &padapter->stapriv;
8195
8196 if (pparm->algorithm == _NO_PRIVACY_) /* clear cam entry */ {
8197 clear_cam_entry(padapter, pparm->id);
8198 return H2C_SUCCESS_RSP;
8199 }
8200
8201 psta = rtw_get_stainfo(pstapriv, pparm->addr);
8202 if (psta) {
8203 ctrl = (BIT(15) | ((pparm->algorithm) << 2));
8204
8205 DBG_88E("r871x_set_stakey_hdl(): enc_algorithm=%d\n", pparm->algorithm);
8206
8207 if ((psta->mac_id < 1) || (psta->mac_id > (NUM_STA-4))) {
8208 DBG_88E("r871x_set_stakey_hdl():set_stakey failed, mac_id(aid)=%d\n", psta->mac_id);
8209 return H2C_REJECTED;
8210 }
8211
8212 cam_id = (psta->mac_id + 3);/* 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
8213
8214 DBG_88E("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, cam_entry=%d\n", pparm->addr[0],
8215 pparm->addr[1], pparm->addr[2], pparm->addr[3], pparm->addr[4],
8216 pparm->addr[5], cam_id);
8217
8218 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8219
8220 return H2C_SUCCESS_RSP;
8221 } else {
8222 DBG_88E("r871x_set_stakey_hdl(): sta has been free\n");
8223 return H2C_REJECTED;
8224 }
8225 }
8226
8227 /* below for sta mode */
8228
8229 if (pparm->algorithm == _NO_PRIVACY_) { /* clear cam entry */
8230 clear_cam_entry(padapter, pparm->id);
8231 return H2C_SUCCESS;
8232 }
8233 ctrl = BIT(15) | ((pparm->algorithm) << 2);
8234 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8235 pmlmeinfo->enc_algo = pparm->algorithm;
8236 return H2C_SUCCESS;
8237 }
8238
8239 u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf)
8240 {
8241 struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
8242 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8243 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8244
8245 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
8246
8247 if (!psta)
8248 return H2C_SUCCESS;
8249
8250 if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
8251 ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
8252 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
8253 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
8254 } else {
8255 psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
8256 }
8257 return H2C_SUCCESS;
8258 }
8259
8260 u8 set_tx_beacon_cmd(struct adapter *padapter)
8261 {
8262 struct cmd_obj *ph2c;
8263 struct Tx_Beacon_param *ptxBeacon_parm;
8264 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
8265 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8266 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8267 u8 res = _SUCCESS;
8268 int len_diff = 0;
8269
8270
8271 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
8272 if (ph2c == NULL) {
8273 res = _FAIL;
8274 goto exit;
8275 }
8276
8277 ptxBeacon_parm = kzalloc(sizeof(struct Tx_Beacon_param), GFP_KERNEL);
8278 if (ptxBeacon_parm == NULL) {
8279 kfree(ph2c);
8280 res = _FAIL;
8281 goto exit;
8282 }
8283
8284 memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
8285
8286 len_diff = update_hidden_ssid(ptxBeacon_parm->network.IEs+_BEACON_IE_OFFSET_,
8287 ptxBeacon_parm->network.IELength-_BEACON_IE_OFFSET_,
8288 pmlmeinfo->hidden_ssid_mode);
8289 ptxBeacon_parm->network.IELength += len_diff;
8290
8291 init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
8292
8293 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
8294
8295
8296 exit:
8297
8298
8299 return res;
8300 }
8301
8302 u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf)
8303 {
8304 u8 evt_code;
8305 u16 evt_sz;
8306 uint *peventbuf;
8307 void (*event_callback)(struct adapter *dev, u8 *pbuf);
8308 struct evt_priv *pevt_priv = &(padapter->evtpriv);
8309
8310 peventbuf = (uint *)pbuf;
8311 evt_sz = (u16)(*peventbuf&0xffff);
8312 evt_code = (u8)((*peventbuf>>16)&0xff);
8313
8314 /* checking if event code is valid */
8315 if (evt_code >= MAX_C2HEVT) {
8316 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("\nEvent Code(%d) mismatch!\n", evt_code));
8317 goto _abort_event_;
8318 }
8319
8320 /* checking if event size match the event parm size */
8321 if ((wlanevents[evt_code].parmsize != 0) &&
8322 (wlanevents[evt_code].parmsize != evt_sz)) {
8323 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
8324 ("\nEvent(%d) Parm Size mismatch (%d vs %d)!\n",
8325 evt_code, wlanevents[evt_code].parmsize, evt_sz));
8326 goto _abort_event_;
8327 }
8328
8329 atomic_inc(&pevt_priv->event_seq);
8330
8331 peventbuf += 2;
8332
8333 if (peventbuf) {
8334 event_callback = wlanevents[evt_code].event_callback;
8335 event_callback(padapter, (u8 *)peventbuf);
8336
8337 pevt_priv->evt_done_cnt++;
8338 }
8339
8340 _abort_event_:
8341 return H2C_SUCCESS;
8342 }
8343
8344 u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf)
8345 {
8346 if (!pbuf)
8347 return H2C_PARAMETERS_ERROR;
8348
8349 return H2C_SUCCESS;
8350 }
8351
8352 u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf)
8353 {
8354 if (send_beacon(padapter) == _FAIL) {
8355 DBG_88E("issue_beacon, fail!\n");
8356 return H2C_PARAMETERS_ERROR;
8357 }
8358 #ifdef CONFIG_88EU_AP_MODE
8359 else { /* tx bc/mc frames after update TIM */
8360 struct sta_info *psta_bmc;
8361 struct list_head *xmitframe_plist, *xmitframe_phead;
8362 struct xmit_frame *pxmitframe = NULL;
8363 struct sta_priv *pstapriv = &padapter->stapriv;
8364
8365 /* for BC/MC Frames */
8366 psta_bmc = rtw_get_bcmc_stainfo(padapter);
8367 if (!psta_bmc)
8368 return H2C_SUCCESS;
8369
8370 if ((pstapriv->tim_bitmap&BIT(0)) && (psta_bmc->sleepq_len > 0)) {
8371 msleep(10);/* 10ms, ATIM(HIQ) Windows */
8372 spin_lock_bh(&psta_bmc->sleep_q.lock);
8373
8374 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
8375 xmitframe_plist = xmitframe_phead->next;
8376
8377 while (xmitframe_phead != xmitframe_plist) {
8378 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
8379
8380 xmitframe_plist = xmitframe_plist->next;
8381
8382 rtw_list_delete(&pxmitframe->list);
8383
8384 psta_bmc->sleepq_len--;
8385 if (psta_bmc->sleepq_len > 0)
8386 pxmitframe->attrib.mdata = 1;
8387 else
8388 pxmitframe->attrib.mdata = 0;
8389
8390 pxmitframe->attrib.triggered = 1;
8391
8392 pxmitframe->attrib.qsel = 0x11;/* HIQ */
8393
8394 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8395 if (rtw_hal_xmit(padapter, pxmitframe))
8396 rtw_os_xmit_complete(padapter, pxmitframe);
8397 spin_lock_bh(&psta_bmc->sleep_q.lock);
8398 }
8399 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8400 }
8401 }
8402 #endif
8403 return H2C_SUCCESS;
8404 }
8405
8406 u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf)
8407 {
8408 struct set_ch_parm *set_ch_parm;
8409 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8410
8411 if (!pbuf)
8412 return H2C_PARAMETERS_ERROR;
8413
8414 set_ch_parm = (struct set_ch_parm *)pbuf;
8415
8416 DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
8417 FUNC_NDEV_ARG(padapter->pnetdev),
8418 set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
8419
8420 pmlmeext->cur_channel = set_ch_parm->ch;
8421 pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
8422 pmlmeext->cur_bwmode = set_ch_parm->bw;
8423
8424 set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
8425
8426 return H2C_SUCCESS;
8427 }
8428
8429 u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)
8430 {
8431 struct SetChannelPlan_param *setChannelPlan_param;
8432 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8433
8434 if (!pbuf)
8435 return H2C_PARAMETERS_ERROR;
8436
8437 setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
8438
8439 pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
8440 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
8441
8442 return H2C_SUCCESS;
8443 }
8444
8445 u8 led_blink_hdl(struct adapter *padapter, unsigned char *pbuf)
8446 {
8447 if (!pbuf)
8448 return H2C_PARAMETERS_ERROR;
8449 return H2C_SUCCESS;
8450 }
8451
8452 u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf)
8453 {
8454 return H2C_REJECTED;
8455 }
8456
8457 /* TDLS_WRCR : write RCR DATA BIT */
8458 /* TDLS_SD_PTI : issue peer traffic indication */
8459 /* TDLS_CS_OFF : go back to the channel linked with AP, terminating channel switch procedure */
8460 /* TDLS_INIT_CH_SEN : init channel sensing, receive all data and mgnt frame */
8461 /* TDLS_DONE_CH_SEN: channel sensing and report candidate channel */
8462 /* TDLS_OFF_CH : first time set channel to off channel */
8463 /* TDLS_BASE_CH : go back tp the channel linked with AP when set base channel as target channel */
8464 /* TDLS_P_OFF_CH : periodically go to off channel */
8465 /* TDLS_P_BASE_CH : periodically go back to base channel */
8466 /* TDLS_RS_RCR : restore RCR */
8467 /* TDLS_CKALV_PH1 : check alive timer phase1 */
8468 /* TDLS_CKALV_PH2 : check alive timer phase2 */
8469 /* TDLS_FREE_STA : free tdls sta */
8470 u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf)
8471 {
8472 return H2C_REJECTED;
8473 }
This page took 0.268872 seconds and 5 git commands to generate.