1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007 - 2012 Realtek Corporation. */
4 #define _RTW_MLME_EXT_C_
6 #include "../include/osdep_service.h"
7 #include "../include/drv_types.h"
8 #include "../include/wifi.h"
9 #include "../include/rtw_mlme_ext.h"
10 #include "../include/wlan_bssdef.h"
11 #include "../include/mlme_osdep.h"
12 #include "../include/recv_osdep.h"
14 static struct mlme_handler mlme_sta_tbl[] = {
15 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
16 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
17 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
18 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
19 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
20 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
22 /*----------------------------------------------------------
24 -----------------------------------------------------------*/
25 {0, "DoReserved", &DoReserved},
26 {0, "DoReserved", &DoReserved},
27 {WIFI_BEACON, "OnBeacon", &OnBeacon},
28 {WIFI_ATIM, "OnATIM", &OnAtim},
29 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
30 {WIFI_AUTH, "OnAuth", &OnAuthClient},
31 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
32 {WIFI_ACTION, "OnAction", &OnAction},
35 static struct action_handler OnAction_tbl[] = {
36 {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
37 {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
38 {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
39 {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
40 {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
41 {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
42 {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved},
43 {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
44 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
45 {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
46 {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
49 static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
51 /**************************************************
52 OUI definitions for the vendor specific IE
53 ***************************************************/
54 unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
55 unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
56 unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
57 unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
58 unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
60 unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
61 unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
63 unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
64 unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
66 extern unsigned char REALTEK_96B_IE[];
68 /********************************************************
70 *********************************************************/
71 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
72 unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
74 /********************************************************
75 ChannelPlan definitions
76 *********************************************************/
77 static struct rt_channel_plan_2g RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = {
78 {{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 */
79 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1 */
80 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* 0x02, RT_CHANNEL_DOMAIN_2G_FCC1 */
81 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1 */
82 {{10, 11, 12, 13}, 4}, /* 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2 */
83 {{}, 0}, /* 0x05, RT_CHANNEL_DOMAIN_2G_NULL */
86 static struct rt_channel_plan_map RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = {
87 /* 0x00 ~ 0x1F , Old Define ===== */
88 {0x02}, /* 0x00, RT_CHANNEL_DOMAIN_FCC */
89 {0x02}, /* 0x01, RT_CHANNEL_DOMAIN_IC */
90 {0x01}, /* 0x02, RT_CHANNEL_DOMAIN_ETSI */
91 {0x01}, /* 0x03, RT_CHANNEL_DOMAIN_SPAIN */
92 {0x01}, /* 0x04, RT_CHANNEL_DOMAIN_FRANCE */
93 {0x03}, /* 0x05, RT_CHANNEL_DOMAIN_MKK */
94 {0x03}, /* 0x06, RT_CHANNEL_DOMAIN_MKK1 */
95 {0x01}, /* 0x07, RT_CHANNEL_DOMAIN_ISRAEL */
96 {0x03}, /* 0x08, RT_CHANNEL_DOMAIN_TELEC */
97 {0x03}, /* 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN */
98 {0x00}, /* 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13 */
99 {0x02}, /* 0x0B, RT_CHANNEL_DOMAIN_TAIWAN */
100 {0x01}, /* 0x0C, RT_CHANNEL_DOMAIN_CHINA */
101 {0x02}, /* 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO */
102 {0x02}, /* 0x0E, RT_CHANNEL_DOMAIN_KOREA */
103 {0x02}, /* 0x0F, RT_CHANNEL_DOMAIN_TURKEY */
104 {0x01}, /* 0x10, RT_CHANNEL_DOMAIN_JAPAN */
105 {0x02}, /* 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS */
106 {0x01}, /* 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
107 {0x00}, /* 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G */
108 {0x02}, /* 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS */
109 {0x00}, /* 0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS */
110 {0x00}, /* 0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS */
111 {0x03}, /* 0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
112 {0x05}, /* 0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS */
113 {0x02}, /* 0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS */
119 {0x05}, /* 0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G */
120 /* 0x20 ~ 0x7F , New Define ===== */
121 {0x00}, /* 0x20, RT_CHANNEL_DOMAIN_WORLD_NULL */
122 {0x01}, /* 0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL */
123 {0x02}, /* 0x22, RT_CHANNEL_DOMAIN_FCC1_NULL */
124 {0x03}, /* 0x23, RT_CHANNEL_DOMAIN_MKK1_NULL */
125 {0x04}, /* 0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL */
126 {0x02}, /* 0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1 */
127 {0x00}, /* 0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1 */
128 {0x03}, /* 0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1 */
129 {0x00}, /* 0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1 */
130 {0x00}, /* 0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2 */
137 {0x00}, /* 0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3 */
138 {0x00}, /* 0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4 */
139 {0x00}, /* 0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5 */
140 {0x00}, /* 0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6 */
141 {0x02}, /* 0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7 */
142 {0x00}, /* 0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2 */
143 {0x00}, /* 0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3 */
144 {0x03}, /* 0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2 */
145 {0x03}, /* 0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3 */
146 {0x02}, /* 0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1 */
153 {0x02}, /* 0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2 */
154 {0x03}, /* 0x41, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G */
157 static struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03}; /* use the conbination for max channel numbers */
160 * Search the @param channel_num in given @param channel_set
161 * @ch_set: the given channel set
162 * @ch: the given channel number
164 * return the index of channel_num in channel_set, -1 if not found
166 int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch)
169 for (i = 0; ch_set[i].ChannelNum != 0; i++) {
170 if (ch == ch_set[i].ChannelNum)
174 if (i >= ch_set[i].ChannelNum)
179 /****************************************************************************
181 Following are the initialization functions for WiFi MLME
183 *****************************************************************************/
185 int init_hw_mlme_ext(struct adapter *padapter)
187 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
189 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
193 static void init_mlme_ext_priv_value(struct adapter *padapter)
195 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
196 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
197 unsigned char mixed_datarate[NumRates] = {
198 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
199 _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_,
200 _48M_RATE_, _54M_RATE_, 0xff
202 unsigned char mixed_basicrate[NumRates] = {
203 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
204 _12M_RATE_, _24M_RATE_, 0xff,
207 atomic_set(&pmlmeext->event_seq, 0);
208 pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
210 pmlmeext->cur_channel = padapter->registrypriv.channel;
211 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
212 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
215 pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
217 memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
218 memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
220 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
222 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
223 pmlmeext->sitesurvey_res.channel_idx = 0;
224 pmlmeext->sitesurvey_res.bss_cnt = 0;
225 pmlmeext->scan_abort = false;
227 pmlmeinfo->state = WIFI_FW_NULL_STATE;
228 pmlmeinfo->reauth_count = 0;
229 pmlmeinfo->reassoc_count = 0;
230 pmlmeinfo->link_count = 0;
231 pmlmeinfo->auth_seq = 0;
232 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
233 pmlmeinfo->key_index = 0;
236 pmlmeinfo->enc_algo = _NO_PRIVACY_;
237 pmlmeinfo->authModeToggle = 0;
239 memset(pmlmeinfo->chg_txt, 0, 128);
241 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
242 pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
244 pmlmeinfo->dialogToken = 0;
246 pmlmeext->action_public_rxseq = 0xffff;
247 pmlmeext->action_public_dialog_token = 0xff;
250 static int has_channel(struct rt_channel_info *channel_set,
255 for (i = 0; i < chanset_size; i++) {
256 if (channel_set[i].ChannelNum == chan)
262 static void init_channel_list(struct adapter *padapter, struct rt_channel_info *channel_set,
264 struct p2p_channels *channel_list) {
265 struct p2p_oper_class_map op_class[] = {
266 { IEEE80211G, 81, 1, 13, 1, BW20 },
267 { IEEE80211G, 82, 14, 14, 1, BW20 },
268 { -1, 0, 0, 0, 0, BW20 }
275 for (op = 0; op_class[op].op_class; op++) {
277 struct p2p_oper_class_map *o = &op_class[op];
278 struct p2p_reg_class *reg = NULL;
280 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
281 if (!has_channel(channel_set, chanset_size, ch)) {
285 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
288 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) &&
289 ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
293 reg = &channel_list->reg_class[cla];
295 reg->reg_class = o->op_class;
298 reg->channel[reg->channels] = ch;
302 channel_list->reg_classes = cla;
305 static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_channel_info *channel_set)
307 u8 index, chanset_size = 0;
308 u8 b2_4GBand = false;
311 memset(channel_set, 0, sizeof(struct rt_channel_info) * MAX_CHANNEL_NUM);
313 if (ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE) {
314 DBG_88E("ChannelPlan ID %x error !!!!!\n", ChannelPlan);
318 if (padapter->registrypriv.wireless_mode & WIRELESS_11G) {
320 if (RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
321 Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
323 Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
327 for (index = 0; index < RTW_ChannelPlan2G[Index2G].Len; index++) {
328 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan2G[Index2G].Channel[index];
330 if ((RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN == ChannelPlan) ||/* Channel 1~11 is active, and 12~14 is passive */
331 (RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G == ChannelPlan)) {
332 if (channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
333 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
334 else if ((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
335 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
336 } else if (RT_CHANNEL_DOMAIN_WORLD_WIDE_13 == ChannelPlan ||
337 RT_CHANNEL_DOMAIN_2G_WORLD == Index2G) {/* channel 12~13, passive scan */
338 if (channel_set[chanset_size].ChannelNum <= 11)
339 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
341 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
343 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
352 int init_mlme_ext_priv(struct adapter *padapter)
355 struct registry_priv *pregistrypriv = &padapter->registrypriv;
356 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
357 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
358 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
360 pmlmeext->padapter = padapter;
362 init_mlme_ext_priv_value(padapter);
363 pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
365 init_mlme_ext_timer(padapter);
367 #ifdef CONFIG_88EU_AP_MODE
368 init_mlme_ap_info(padapter);
371 pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set);
372 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
374 pmlmeext->chan_scan_time = SURVEY_TO;
375 pmlmeext->mlmeext_init = true;
377 pmlmeext->active_keep_alive_check = true;
382 void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
384 struct adapter *padapter = pmlmeext->padapter;
389 if (padapter->bDriverStopped) {
390 _cancel_timer_ex(&pmlmeext->survey_timer);
391 _cancel_timer_ex(&pmlmeext->link_timer);
392 /* _cancel_timer_ex(&pmlmeext->ADDBA_timer); */
396 static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame)
398 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
399 u8 *pframe = precv_frame->rx_data;
402 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
403 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
404 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
406 ptable->func(padapter, precv_frame);
410 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
413 struct mlme_handler *ptable;
414 #ifdef CONFIG_88EU_AP_MODE
415 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
416 #endif /* CONFIG_88EU_AP_MODE */
417 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
418 u8 *pframe = precv_frame->rx_data;
419 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
421 if (GetFrameType(pframe) != WIFI_MGT_TYPE)
424 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
425 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
426 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
429 ptable = mlme_sta_tbl;
431 index = GetFrameSubType(pframe) >> 4;
438 if (GetRetry(pframe)) {
439 if (precv_frame->attrib.seq_num == psta->RxMgmtFrameSeqNum) {
440 /* drop the duplicate management frame */
441 DBG_88E("Drop duplicate management frame with seq_num=%d.\n", precv_frame->attrib.seq_num);
445 psta->RxMgmtFrameSeqNum = precv_frame->attrib.seq_num;
448 #ifdef CONFIG_88EU_AP_MODE
449 switch (GetFrameSubType(pframe)) {
451 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
452 ptable->func = &OnAuth;
454 ptable->func = &OnAuthClient;
457 case WIFI_REASSOCREQ:
458 _mgt_dispatcher(padapter, ptable, precv_frame);
461 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
462 _mgt_dispatcher(padapter, ptable, precv_frame);
464 _mgt_dispatcher(padapter, ptable, precv_frame);
467 _mgt_dispatcher(padapter, ptable, precv_frame);
470 _mgt_dispatcher(padapter, ptable, precv_frame);
473 _mgt_dispatcher(padapter, ptable, precv_frame);
474 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
475 rtw_hostapd_mlme_rx(padapter, precv_frame);
479 _mgt_dispatcher(padapter, ptable, precv_frame);
483 #ifdef CONFIG_88EU_P2P
484 static u32 p2p_listen_state_process(struct adapter *padapter, unsigned char *da)
486 bool response = true;
488 /* do nothing if the device name is empty */
489 if (!padapter->wdinfo.device_name_len)
493 issue_probersp_p2p(padapter, da);
497 #endif /* CONFIG_88EU_P2P */
499 /****************************************************************************
501 Following are the callback functions for each subtype of the management frames
503 *****************************************************************************/
505 unsigned int OnProbeReq(struct adapter *padapter, struct recv_frame *precv_frame)
509 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
510 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
511 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
512 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
513 u8 *pframe = precv_frame->rx_data;
514 uint len = precv_frame->len;
515 u8 is_valid_p2p_probereq = false;
517 #ifdef CONFIG_88EU_P2P
518 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
519 u8 wifi_test_chk_rate = 1;
521 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
522 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE) &&
523 !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
524 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH) &&
525 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)) {
526 /* mcs_rate = 0 -> CCK 1M rate */
527 /* mcs_rate = 1 -> CCK 2M rate */
528 /* mcs_rate = 2 -> CCK 5.5M rate */
529 /* mcs_rate = 3 -> CCK 11M rate */
530 /* In the P2P mode, the driver should not support the CCK rate */
532 /* Commented by Kurt 2012/10/16 */
533 /* IOT issue: Google Nexus7 use 1M rate to send p2p_probe_req after GO nego completed and Nexus7 is client */
534 if (wifi_test_chk_rate == 1) {
535 is_valid_p2p_probereq = process_probe_req_p2p_ie(pwdinfo, pframe, len);
536 if (is_valid_p2p_probereq) {
537 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
539 report_survey_event(padapter, precv_frame);
540 p2p_listen_state_process(padapter, get_sa(pframe));
545 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
552 #endif /* CONFIG_88EU_P2P */
554 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
557 if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
558 !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
561 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
562 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
564 /* check (wildcard) SSID */
566 if (is_valid_p2p_probereq)
567 goto _issue_probersp;
569 if ((ielen != 0 && memcmp((void *)(p+2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength)) ||
570 (ielen == 0 && pmlmeinfo->hidden_ssid_mode))
575 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
576 (pmlmepriv->cur_network.join_res ||
577 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
578 issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
583 unsigned int OnProbeRsp(struct adapter *padapter, struct recv_frame *precv_frame)
585 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
586 #ifdef CONFIG_88EU_P2P
587 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
588 u8 *pframe = precv_frame->rx_data;
591 #ifdef CONFIG_88EU_P2P
592 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
593 if (pwdinfo->tx_prov_disc_info.benable) {
594 if (!memcmp(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
595 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
596 pwdinfo->tx_prov_disc_info.benable = false;
597 issue_p2p_provision_request(padapter,
598 pwdinfo->tx_prov_disc_info.ssid.Ssid,
599 pwdinfo->tx_prov_disc_info.ssid.SsidLength,
600 pwdinfo->tx_prov_disc_info.peerDevAddr);
601 } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
602 pwdinfo->tx_prov_disc_info.benable = false;
603 issue_p2p_provision_request(padapter, NULL, 0,
604 pwdinfo->tx_prov_disc_info.peerDevAddr);
609 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
610 if (pwdinfo->nego_req_info.benable) {
611 DBG_88E("[%s] P2P State is GONEGO ING!\n", __func__);
612 if (!memcmp(pwdinfo->nego_req_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
613 pwdinfo->nego_req_info.benable = false;
614 issue_p2p_GO_request(padapter, pwdinfo->nego_req_info.peerDevAddr);
617 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ)) {
618 if (pwdinfo->invitereq_info.benable) {
619 DBG_88E("[%s] P2P_STATE_TX_INVITE_REQ!\n", __func__);
620 if (!memcmp(pwdinfo->invitereq_info.peer_macaddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
621 pwdinfo->invitereq_info.benable = false;
622 issue_p2p_invitation_request(padapter, pwdinfo->invitereq_info.peer_macaddr);
628 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
629 report_survey_event(padapter, precv_frame);
636 unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
639 struct sta_info *psta;
640 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
641 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
642 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
643 struct sta_priv *pstapriv = &padapter->stapriv;
644 u8 *pframe = precv_frame->rx_data;
645 uint len = precv_frame->len;
646 struct wlan_bssid_ex *pbss;
649 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
650 report_survey_event(padapter, precv_frame);
654 if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
655 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
656 /* we should update current network before auth, or some IE is wrong */
657 pbss = kmalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
659 if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
660 update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true);
661 rtw_get_bcn_info(&(pmlmepriv->cur_network));
666 /* check the vendor of the assoc AP */
667 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe+sizeof(struct rtw_ieee80211_hdr_3addr), len-sizeof(struct rtw_ieee80211_hdr_3addr));
669 /* update TSF Value */
670 update_TSF(pmlmeext, pframe, len);
673 start_clnt_auth(padapter);
678 if (((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
679 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
681 ret = rtw_check_bcn_info(padapter, pframe, len);
683 DBG_88E_LEVEL(_drv_info_, "ap has changed, disconnect now\n ");
684 receive_disconnect(padapter, pmlmeinfo->network.MacAddress, 0);
687 /* update WMM, ERP in the beacon */
688 /* todo: the timer is used instead of the number of the beacon received */
689 if ((sta_rx_pkts(psta) & 0xf) == 0)
690 update_beacon_info(padapter, pframe, len, psta);
691 process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
693 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
694 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
696 /* update WMM, ERP in the beacon */
697 /* todo: the timer is used instead of the number of the beacon received */
698 if ((sta_rx_pkts(psta) & 0xf) == 0)
699 update_beacon_info(padapter, pframe, len, psta);
701 /* allocate a new CAM entry for IBSS station */
702 cam_idx = allocate_fw_sta_entry(padapter);
703 if (cam_idx == NUM_STA)
706 /* get supported rate */
707 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) {
708 pmlmeinfo->FW_sta_info[cam_idx].status = 0;
712 /* update TSF Value */
713 update_TSF(pmlmeext, pframe, len);
715 /* report sta add event */
716 report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
726 unsigned int OnAuth(struct adapter *padapter, struct recv_frame *precv_frame)
728 #ifdef CONFIG_88EU_AP_MODE
729 unsigned int auth_mode, ie_len;
731 unsigned char *sa, *p;
734 static struct sta_info stat;
735 struct sta_info *pstat = NULL;
736 struct sta_priv *pstapriv = &padapter->stapriv;
737 struct security_priv *psecuritypriv = &padapter->securitypriv;
738 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
739 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
740 u8 *pframe = precv_frame->rx_data;
741 uint len = precv_frame->len;
743 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
746 DBG_88E("+OnAuth\n");
748 sa = GetAddr2Ptr(pframe);
750 auth_mode = psecuritypriv->dot11AuthAlgrthm;
751 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + 2));
752 algorithm = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN));
754 DBG_88E("auth alg=%x, seq=%X\n", algorithm, seq);
756 if (auth_mode == 2 && psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
757 psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
760 if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */
761 (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */
762 DBG_88E("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
763 algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
765 status = _STATS_NO_SUPP_ALG_;
770 if (!rtw_access_ctrl(padapter, sa)) {
771 status = _STATS_UNABLE_HANDLE_STA_;
775 pstat = rtw_get_stainfo(pstapriv, sa);
777 /* allocate a new one */
778 DBG_88E("going to alloc stainfo for sa=%pM\n", sa);
779 pstat = rtw_alloc_stainfo(pstapriv, sa);
781 DBG_88E(" Exceed the upper limit of supported clients...\n");
782 status = _STATS_UNABLE_HANDLE_STA_;
786 pstat->state = WIFI_FW_AUTH_NULL;
789 spin_lock_bh(&pstapriv->asoc_list_lock);
790 if (!list_empty(&pstat->asoc_list)) {
791 list_del_init(&pstat->asoc_list);
792 pstapriv->asoc_list_cnt--;
794 spin_unlock_bh(&pstapriv->asoc_list_lock);
797 /* TODO: STA re_auth and auth timeout */
801 spin_lock_bh(&pstapriv->auth_list_lock);
802 if (list_empty(&pstat->auth_list)) {
803 list_add_tail(&pstat->auth_list, &pstapriv->auth_list);
804 pstapriv->auth_list_cnt++;
806 spin_unlock_bh(&pstapriv->auth_list_lock);
808 if (pstat->auth_seq == 0)
809 pstat->expire_to = pstapriv->auth_to;
811 if ((pstat->auth_seq + 1) != seq) {
812 DBG_88E("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
813 seq, pstat->auth_seq+1);
814 status = _STATS_OUT_OF_AUTH_SEQ_;
818 if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2)) {
820 pstat->state &= ~WIFI_FW_AUTH_NULL;
821 pstat->state |= WIFI_FW_AUTH_SUCCESS;
822 pstat->expire_to = pstapriv->assoc_to;
823 pstat->authalg = algorithm;
825 DBG_88E("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
826 seq, pstat->auth_seq+1);
827 status = _STATS_OUT_OF_AUTH_SEQ_;
830 } else { /* shared system or auto authentication */
832 /* prepare for the challenging txt... */
834 pstat->state &= ~WIFI_FW_AUTH_NULL;
835 pstat->state |= WIFI_FW_AUTH_STATE;
836 pstat->authalg = algorithm;
838 } else if (seq == 3) {
839 /* checking for challenging txt... */
840 DBG_88E("checking for challenging txt...\n");
842 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&ie_len,
843 len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
845 if (!p || ie_len <= 0) {
846 DBG_88E("auth rejected because challenge failure!(1)\n");
847 status = _STATS_CHALLENGE_FAIL_;
851 if (!memcmp((void *)(p + 2), pstat->chg_txt, 128)) {
852 pstat->state &= (~WIFI_FW_AUTH_STATE);
853 pstat->state |= WIFI_FW_AUTH_SUCCESS;
854 /* challenging txt is correct... */
855 pstat->expire_to = pstapriv->assoc_to;
857 DBG_88E("auth rejected because challenge failure!\n");
858 status = _STATS_CHALLENGE_FAIL_;
862 DBG_88E("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
863 seq, pstat->auth_seq+1);
864 status = _STATS_OUT_OF_AUTH_SEQ_;
869 /* Now, we are going to issue_auth... */
870 pstat->auth_seq = seq + 1;
872 #ifdef CONFIG_88EU_AP_MODE
873 issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
876 if (pstat->state & WIFI_FW_AUTH_SUCCESS)
884 rtw_free_stainfo(padapter, pstat);
887 memset((char *)pstat, '\0', sizeof(stat));
889 memcpy(pstat->hwaddr, sa, 6);
891 #ifdef CONFIG_88EU_AP_MODE
892 issue_auth(padapter, pstat, (unsigned short)status);
899 unsigned int OnAuthClient(struct adapter *padapter, struct recv_frame *precv_frame)
901 unsigned int seq, len, status, offset;
903 unsigned int go2asoc = 0;
904 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
905 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
906 u8 *pframe = precv_frame->rx_data;
907 uint pkt_len = precv_frame->len;
909 DBG_88E("%s\n", __func__);
911 /* check A1 matches or not */
912 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
915 if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
918 offset = (GetPrivacy(pframe)) ? 4 : 0;
920 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 2));
921 status = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 4));
924 DBG_88E("clnt auth fail, status: %d\n", status);
925 if (status == 13) { /* pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto) */
926 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
927 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
929 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
932 set_link_timer(pmlmeext, 1);
937 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
938 /* legendary shared system */
939 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
940 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
945 memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
946 pmlmeinfo->auth_seq = 3;
947 issue_auth(padapter, NULL, 0);
948 set_link_timer(pmlmeext, REAUTH_TO);
955 } else if (seq == 4) {
956 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
961 /* this is also illegal */
966 DBG_88E_LEVEL(_drv_info_, "auth success, start assoc\n");
967 start_clnt_assoc(padapter);
974 unsigned int OnAssocReq(struct adapter *padapter, struct recv_frame *precv_frame)
976 #ifdef CONFIG_88EU_AP_MODE
978 struct rtw_ieee802_11_elems elems;
979 struct sta_info *pstat;
980 unsigned char reassoc, *p, *pos, *wpa_ie;
981 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
982 int i, ie_len, wpa_ie_len, left;
983 unsigned char supportRate[16];
985 unsigned short status = _STATS_SUCCESSFUL_;
986 unsigned short frame_type, ie_offset = 0;
987 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
988 struct security_priv *psecuritypriv = &padapter->securitypriv;
989 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
990 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
991 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
992 struct sta_priv *pstapriv = &padapter->stapriv;
993 u8 *pframe = precv_frame->rx_data;
994 uint pkt_len = precv_frame->len;
995 #ifdef CONFIG_88EU_P2P
996 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
997 u8 p2p_status_code = P2P_STATUS_SUCCESS;
1000 #endif /* CONFIG_88EU_P2P */
1002 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1005 frame_type = GetFrameSubType(pframe);
1006 if (frame_type == WIFI_ASSOCREQ) {
1008 ie_offset = _ASOCREQ_IE_OFFSET_;
1009 } else { /* WIFI_REASSOCREQ */
1011 ie_offset = _REASOCREQ_IE_OFFSET_;
1014 if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
1015 DBG_88E("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1016 "\n", reassoc, (unsigned long)pkt_len);
1020 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1021 if (pstat == (struct sta_info *)NULL) {
1022 status = _RSON_CLS2_;
1023 goto asoc_class2_error;
1026 capab_info = get_unaligned_le16(pframe + WLAN_HDR_A3_LEN);
1028 left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
1029 pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
1031 DBG_88E("%s\n", __func__);
1033 /* check if this stat has been successfully authenticated/assocated */
1034 if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) {
1035 if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) {
1036 status = _RSON_CLS2_;
1037 goto asoc_class2_error;
1039 pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
1040 pstat->state |= WIFI_FW_ASSOC_STATE;
1043 pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
1044 pstat->state |= WIFI_FW_ASSOC_STATE;
1046 pstat->capability = capab_info;
1047 /* now parse all ieee802_11 ie to point to elems */
1048 if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
1050 DBG_88E("STA %pM sent invalid association request\n",
1052 status = _STATS_FAILURE_;
1053 goto OnAssocReqFail;
1056 /* now we should check all the fields... */
1058 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
1059 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1061 status = _STATS_FAILURE_;
1063 if (ie_len == 0) { /* broadcast ssid, however it is not allowed in assocreq */
1064 status = _STATS_FAILURE_;
1066 /* check if ssid match */
1067 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
1068 status = _STATS_FAILURE_;
1070 if (ie_len != cur->Ssid.SsidLength)
1071 status = _STATS_FAILURE_;
1074 if (_STATS_SUCCESSFUL_ != status)
1075 goto OnAssocReqFail;
1077 /* check if the supported rate is ok */
1078 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SUPPORTEDRATES_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1080 DBG_88E("Rx a sta assoc-req which supported rate is empty!\n");
1081 /* use our own rate set as statoin used */
1082 /* memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN); */
1083 /* supportRateNum = AP_BSSRATE_LEN; */
1085 status = _STATS_FAILURE_;
1086 goto OnAssocReqFail;
1088 memcpy(supportRate, p+2, ie_len);
1089 supportRateNum = ie_len;
1091 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _EXT_SUPPORTEDRATES_IE_, &ie_len,
1092 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1094 if (supportRateNum <= sizeof(supportRate)) {
1095 memcpy(supportRate+supportRateNum, p+2, ie_len);
1096 supportRateNum += ie_len;
1101 /* todo: mask supportRate between AP & STA -> move to update raid */
1102 /* get_matched_rate(pmlmeext, supportRate, &supportRateNum, 0); */
1104 /* update station supportRate */
1105 pstat->bssratelen = supportRateNum;
1106 memcpy(pstat->bssrateset, supportRate, supportRateNum);
1107 UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
1109 /* check RSN/WPA/WPS */
1110 pstat->dot8021xalg = 0;
1112 pstat->wpa_group_cipher = 0;
1113 pstat->wpa2_group_cipher = 0;
1114 pstat->wpa_pairwise_cipher = 0;
1115 pstat->wpa2_pairwise_cipher = 0;
1116 memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
1117 if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
1118 int group_cipher = 0, pairwise_cipher = 0;
1120 wpa_ie = elems.rsn_ie;
1121 wpa_ie_len = elems.rsn_ie_len;
1123 if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1124 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1125 pstat->wpa_psk |= BIT(1);
1127 pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
1128 pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
1130 if (!pstat->wpa2_group_cipher)
1131 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1133 if (!pstat->wpa2_pairwise_cipher)
1134 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1136 status = WLAN_STATUS_INVALID_IE;
1138 } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
1139 int group_cipher = 0, pairwise_cipher = 0;
1141 wpa_ie = elems.wpa_ie;
1142 wpa_ie_len = elems.wpa_ie_len;
1144 if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1145 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1146 pstat->wpa_psk |= BIT(0);
1148 pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
1149 pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
1151 if (!pstat->wpa_group_cipher)
1152 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1154 if (!pstat->wpa_pairwise_cipher)
1155 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1157 status = WLAN_STATUS_INVALID_IE;
1164 if (_STATS_SUCCESSFUL_ != status)
1165 goto OnAssocReqFail;
1167 pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
1170 DBG_88E("STA included WPS IE in "
1171 "(Re)Association Request - assume WPS is "
1173 pstat->flags |= WLAN_STA_WPS;
1174 /* wpabuf_free(sta->wps_ie); */
1175 /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
1176 /* elems.wps_ie_len - 4); */
1178 DBG_88E("STA did not include WPA/RSN IE "
1179 "in (Re)Association Request - possible WPS "
1181 pstat->flags |= WLAN_STA_MAYBE_WPS;
1184 /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
1185 /* that the selected registrar of AP is _FLASE */
1186 if ((psecuritypriv->wpa_psk > 0) && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
1187 if (pmlmepriv->wps_beacon_ie) {
1188 u8 selected_registrar = 0;
1190 rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR, &selected_registrar, NULL);
1192 if (!selected_registrar) {
1193 DBG_88E("selected_registrar is false , or AP is not ready to do WPS\n");
1195 status = _STATS_UNABLE_HANDLE_STA_;
1197 goto OnAssocReqFail;
1204 if (psecuritypriv->wpa_psk == 0) {
1205 DBG_88E("STA %pM: WPA/RSN IE in association "
1206 "request, but AP don't support WPA/RSN\n", pstat->hwaddr);
1208 status = WLAN_STATUS_INVALID_IE;
1210 goto OnAssocReqFail;
1214 DBG_88E("STA included WPS IE in "
1215 "(Re)Association Request - WPS is "
1217 pstat->flags |= WLAN_STA_WPS;
1220 copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len+2);
1223 memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
1225 /* check if there is WMM IE & support WWM-PS */
1226 pstat->flags &= ~WLAN_STA_WME;
1227 pstat->qos_option = 0;
1228 pstat->qos_info = 0;
1229 pstat->has_legacy_ac = true;
1230 pstat->uapsd_vo = 0;
1231 pstat->uapsd_vi = 0;
1232 pstat->uapsd_be = 0;
1233 pstat->uapsd_bk = 0;
1234 if (pmlmepriv->qospriv.qos_option) {
1235 p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
1237 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1239 if (!memcmp(p+2, WMM_IE, 6)) {
1240 pstat->flags |= WLAN_STA_WME;
1242 pstat->qos_option = 1;
1243 pstat->qos_info = *(p+8);
1245 pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
1247 if ((pstat->qos_info&0xf) != 0xf)
1248 pstat->has_legacy_ac = true;
1250 pstat->has_legacy_ac = false;
1252 if (pstat->qos_info&0xf) {
1253 if (pstat->qos_info&BIT(0))
1254 pstat->uapsd_vo = BIT(0)|BIT(1);
1256 pstat->uapsd_vo = 0;
1258 if (pstat->qos_info&BIT(1))
1259 pstat->uapsd_vi = BIT(0)|BIT(1);
1261 pstat->uapsd_vi = 0;
1263 if (pstat->qos_info&BIT(2))
1264 pstat->uapsd_bk = BIT(0)|BIT(1);
1266 pstat->uapsd_bk = 0;
1268 if (pstat->qos_info&BIT(3))
1269 pstat->uapsd_be = BIT(0)|BIT(1);
1271 pstat->uapsd_be = 0;
1282 /* save HT capabilities in the sta object */
1283 memset(&pstat->htpriv.ht_cap, 0, sizeof(struct ieee80211_ht_cap));
1284 if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_cap)) {
1285 pstat->flags |= WLAN_STA_HT;
1287 pstat->flags |= WLAN_STA_WME;
1289 memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct ieee80211_ht_cap));
1291 pstat->flags &= ~WLAN_STA_HT;
1293 if ((!pmlmepriv->htpriv.ht_option) && (pstat->flags&WLAN_STA_HT)) {
1294 status = _STATS_FAILURE_;
1295 goto OnAssocReqFail;
1298 if ((pstat->flags & WLAN_STA_HT) &&
1299 ((pstat->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
1300 (pstat->wpa_pairwise_cipher&WPA_CIPHER_TKIP))) {
1301 DBG_88E("HT: %pM tried to "
1302 "use TKIP with HT association\n", pstat->hwaddr);
1304 /* status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; */
1305 /* goto OnAssocReqFail; */
1308 pstat->flags |= WLAN_STA_NONERP;
1309 for (i = 0; i < pstat->bssratelen; i++) {
1310 if ((pstat->bssrateset[i] & 0x7f) > 22) {
1311 pstat->flags &= ~WLAN_STA_NONERP;
1316 if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1317 pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
1319 pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1321 if (status != _STATS_SUCCESSFUL_)
1322 goto OnAssocReqFail;
1324 #ifdef CONFIG_88EU_P2P
1325 pstat->is_p2p_device = false;
1326 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
1327 p2pie = rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, pkt_len - WLAN_HDR_A3_LEN - ie_offset, NULL, &p2pielen);
1329 pstat->is_p2p_device = true;
1330 p2p_status_code = (u8)process_assoc_req_p2p_ie(pwdinfo, pframe, pkt_len, pstat);
1331 if (p2p_status_code > 0) {
1332 pstat->p2p_status_code = p2p_status_code;
1333 status = _STATS_CAP_FAIL_;
1334 goto OnAssocReqFail;
1338 pstat->p2p_status_code = p2p_status_code;
1339 #endif /* CONFIG_88EU_P2P */
1341 /* TODO: identify_proprietary_vendor_ie(); */
1342 /* Realtek proprietary IE */
1343 /* identify if this is Broadcom sta */
1344 /* identify if this is ralink sta */
1345 /* Customer proprietary IE */
1347 /* get a unique AID */
1348 if (pstat->aid > 0) {
1349 DBG_88E(" old AID %d\n", pstat->aid);
1351 for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++)
1352 if (!pstapriv->sta_aid[pstat->aid - 1])
1355 /* if (pstat->aid > NUM_STA) { */
1356 if (pstat->aid > pstapriv->max_num_sta) {
1359 DBG_88E(" no room for more AIDs\n");
1361 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1363 goto OnAssocReqFail;
1365 pstapriv->sta_aid[pstat->aid - 1] = pstat;
1366 DBG_88E("allocate new AID=(%d)\n", pstat->aid);
1370 pstat->state &= (~WIFI_FW_ASSOC_STATE);
1371 pstat->state |= WIFI_FW_ASSOC_SUCCESS;
1373 spin_lock_bh(&pstapriv->auth_list_lock);
1374 if (!list_empty(&pstat->auth_list)) {
1375 list_del_init(&pstat->auth_list);
1376 pstapriv->auth_list_cnt--;
1378 spin_unlock_bh(&pstapriv->auth_list_lock);
1380 spin_lock_bh(&pstapriv->asoc_list_lock);
1381 if (list_empty(&pstat->asoc_list)) {
1382 pstat->expire_to = pstapriv->expire_to;
1383 list_add_tail(&pstat->asoc_list, &pstapriv->asoc_list);
1384 pstapriv->asoc_list_cnt++;
1386 spin_unlock_bh(&pstapriv->asoc_list_lock);
1388 /* now the station is qualified to join our BSS... */
1389 if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
1390 #ifdef CONFIG_88EU_AP_MODE
1391 /* 1 bss_cap_update & sta_info_update */
1392 bss_cap_update_on_sta_join(padapter, pstat);
1393 sta_info_update(padapter, pstat);
1395 /* issue assoc rsp before notify station join event. */
1396 if (frame_type == WIFI_ASSOCREQ)
1397 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1399 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1401 /* 2 - report to upper layer */
1402 DBG_88E("indicate_sta_join_event to upper layer - hostapd\n");
1403 rtw_indicate_sta_assoc_event(padapter, pstat);
1405 /* 3-(1) report sta add event */
1406 report_add_sta_event(padapter, pstat->hwaddr, pstat->aid);
1414 #ifdef CONFIG_88EU_AP_MODE
1415 issue_deauth(padapter, (void *)GetAddr2Ptr(pframe), status);
1422 #ifdef CONFIG_88EU_AP_MODE
1424 if (frame_type == WIFI_ASSOCREQ)
1425 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1427 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1430 #endif /* CONFIG_88EU_AP_MODE */
1435 unsigned int OnAssocRsp(struct adapter *padapter, struct recv_frame *precv_frame)
1439 unsigned short status;
1440 struct ndis_802_11_var_ie *pIE;
1441 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1442 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1443 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1444 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */
1445 u8 *pframe = precv_frame->rx_data;
1446 uint pkt_len = precv_frame->len;
1448 DBG_88E("%s\n", __func__);
1450 /* check A1 matches or not */
1451 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
1454 if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
1457 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
1460 _cancel_timer_ex(&pmlmeext->link_timer);
1463 status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2));
1465 DBG_88E("assoc reject, status code: %d\n", status);
1466 pmlmeinfo->state = WIFI_FW_NULL_STATE;
1468 goto report_assoc_result;
1471 /* get capabilities */
1472 pmlmeinfo->capability = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1475 pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20;
1478 pmlmeinfo->aid = (int)(le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 4))&0x3fff);
1479 res = pmlmeinfo->aid;
1481 /* following are moved to join event callback function */
1482 /* to handle HT, WMM, rate adaptive, update MAC reg */
1483 /* for not to handle the synchronous IO in the tasklet */
1484 for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
1485 pIE = (struct ndis_802_11_var_ie *)(pframe + i);
1487 switch (pIE->ElementID) {
1488 case _VENDOR_SPECIFIC_IE_:
1489 if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
1490 WMM_param_handler(padapter, pIE);
1492 case _HT_CAPABILITY_IE_: /* HT caps */
1493 HT_caps_handler(padapter, pIE);
1495 case _HT_EXTRA_INFO_IE_: /* HT info */
1496 HT_info_handler(padapter, pIE);
1499 ERP_IE_handler(padapter, pIE);
1504 i += (pIE->Length + 2);
1507 pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
1508 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
1510 /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
1511 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
1513 report_assoc_result:
1515 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
1517 kfree(pmlmepriv->assoc_rsp);
1519 report_join_res(padapter, res);
1524 unsigned int OnDeAuth(struct adapter *padapter, struct recv_frame *precv_frame)
1526 unsigned short reason;
1527 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1528 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1529 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1530 u8 *pframe = precv_frame->rx_data;
1531 #ifdef CONFIG_88EU_P2P
1532 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1533 #endif /* CONFIG_88EU_P2P */
1536 if (!(!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
1539 #ifdef CONFIG_88EU_P2P
1540 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1541 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1542 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1544 #endif /* CONFIG_88EU_P2P */
1546 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1548 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1550 #ifdef CONFIG_88EU_AP_MODE
1551 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1552 struct sta_info *psta;
1553 struct sta_priv *pstapriv = &padapter->stapriv;
1555 DBG_88E_LEVEL(_drv_always_, "ap recv deauth reason code(%d) sta:%pM\n",
1556 reason, GetAddr2Ptr(pframe));
1558 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1562 spin_lock_bh(&pstapriv->asoc_list_lock);
1563 if (!list_empty(&psta->asoc_list)) {
1564 list_del_init(&psta->asoc_list);
1565 pstapriv->asoc_list_cnt--;
1566 updated = ap_free_sta(padapter, psta, false, reason);
1568 spin_unlock_bh(&pstapriv->asoc_list_lock);
1570 associated_clients_update(padapter, updated);
1577 int ignore_received_deauth = 0;
1579 /* Before sending the auth frame to start the STA/GC mode connection with AP/GO,
1580 * we will send the deauth first.
1581 * However, the Win8.1 with BRCM Wi-Fi will send the deauth with reason code 6 to us after receieving our deauth.
1582 * Added the following code to avoid this case.
1584 if ((pmlmeinfo->state & WIFI_FW_AUTH_STATE) ||
1585 (pmlmeinfo->state & WIFI_FW_ASSOC_STATE)) {
1586 if (reason == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA) {
1587 ignore_received_deauth = 1;
1588 } else if (WLAN_REASON_PREV_AUTH_NOT_VALID == reason) {
1590 ignore_received_deauth = 1;
1594 DBG_88E_LEVEL(_drv_always_, "sta recv deauth reason code(%d) sta:%pM, ignore = %d\n",
1595 reason, GetAddr3Ptr(pframe), ignore_received_deauth);
1597 if (!ignore_received_deauth)
1598 receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
1600 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1604 unsigned int OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
1607 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1608 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1609 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1610 u8 *pframe = precv_frame->rx_data;
1611 #ifdef CONFIG_88EU_P2P
1612 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1613 #endif /* CONFIG_88EU_P2P */
1616 if (!(!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
1619 #ifdef CONFIG_88EU_P2P
1620 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1621 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1622 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1624 #endif /* CONFIG_88EU_P2P */
1626 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1628 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1630 #ifdef CONFIG_88EU_AP_MODE
1631 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1632 struct sta_info *psta;
1633 struct sta_priv *pstapriv = &padapter->stapriv;
1635 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1636 reason, GetAddr2Ptr(pframe));
1638 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1642 spin_lock_bh(&pstapriv->asoc_list_lock);
1643 if (!list_empty(&psta->asoc_list)) {
1644 list_del_init(&psta->asoc_list);
1645 pstapriv->asoc_list_cnt--;
1646 updated = ap_free_sta(padapter, psta, false, reason);
1648 spin_unlock_bh(&pstapriv->asoc_list_lock);
1650 associated_clients_update(padapter, updated);
1657 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1658 reason, GetAddr3Ptr(pframe));
1660 receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
1662 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1666 unsigned int OnAtim(struct adapter *padapter, struct recv_frame *precv_frame)
1668 DBG_88E("%s\n", __func__);
1672 unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame)
1674 unsigned int ret = _FAIL;
1675 struct sta_info *psta = NULL;
1676 struct sta_priv *pstapriv = &padapter->stapriv;
1677 u8 *pframe = precv_frame->rx_data;
1678 u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1682 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1684 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1689 category = frame_body[0];
1690 if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
1693 action = frame_body[1];
1695 case RTW_WLAN_ACTION_SPCT_MSR_REQ:
1696 case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
1697 case RTW_WLAN_ACTION_SPCT_TPC_REQ:
1698 case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
1700 case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
1710 unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame)
1715 unsigned int OnAction_dls(struct adapter *padapter, struct recv_frame *precv_frame)
1720 unsigned int OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
1723 struct sta_info *psta = NULL;
1724 struct recv_reorder_ctrl *preorder_ctrl;
1725 unsigned char *frame_body;
1726 unsigned char category, action;
1727 unsigned short tid, status, reason_code = 0;
1728 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1729 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1730 u8 *pframe = precv_frame->rx_data;
1731 struct sta_priv *pstapriv = &padapter->stapriv;
1732 /* check RA matches or not */
1733 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))/* for if1, sta/ap mode */
1736 DBG_88E("%s\n", __func__);
1738 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1739 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
1742 addr = GetAddr2Ptr(pframe);
1743 psta = rtw_get_stainfo(pstapriv, addr);
1748 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1750 category = frame_body[0];
1751 if (category == RTW_WLAN_CATEGORY_BACK) { /* representing Block Ack */
1752 if (!pmlmeinfo->HT_enable)
1754 action = frame_body[1];
1755 DBG_88E("%s, action=%d\n", __func__, action);
1757 case RTW_WLAN_ACTION_ADDBA_REQ: /* ADDBA request */
1758 memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
1759 process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr);
1761 if (pmlmeinfo->bAcceptAddbaReq)
1762 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 0);
1764 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 37);/* reject ADDBA Req */
1766 case RTW_WLAN_ACTION_ADDBA_RESP: /* ADDBA response */
1767 status = get_unaligned_le16(&frame_body[3]);
1768 tid = ((frame_body[5] >> 2) & 0x7);
1769 if (status == 0) { /* successful */
1770 DBG_88E("agg_enable for TID=%d\n", tid);
1771 psta->htpriv.agg_enable_bitmap |= 1 << tid;
1772 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
1774 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
1777 case RTW_WLAN_ACTION_DELBA: /* DELBA */
1778 if ((frame_body[3] & BIT(3)) == 0) {
1779 psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1780 psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1781 reason_code = get_unaligned_le16(&frame_body[4]);
1782 } else if ((frame_body[3] & BIT(3)) == BIT(3)) {
1783 tid = (frame_body[3] >> 4) & 0x0F;
1784 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1785 preorder_ctrl->enable = false;
1786 preorder_ctrl->indicate_seq = 0xffff;
1788 DBG_88E("%s(): DELBA: %x(%x)\n", __func__, pmlmeinfo->agg_enable_bitmap, reason_code);
1789 /* todo: how to notify the host while receiving DELETE BA */
1798 #ifdef CONFIG_88EU_P2P
1800 static int get_reg_classes_full_count(struct p2p_channels *channel_list)
1805 for (i = 0; i < channel_list->reg_classes; i++) {
1806 cnt += channel_list->reg_class[i].channels;
1812 void issue_p2p_GO_request(struct adapter *padapter, u8 *raddr)
1814 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
1815 u8 action = P2P_PUB_ACTION_ACTION;
1816 __be32 p2poui = cpu_to_be32(P2POUI);
1817 u8 oui_subtype = P2P_GO_NEGO_REQ;
1818 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
1819 u8 wpsielen = 0, p2pielen = 0;
1820 u16 len_channellist_attr = 0;
1821 struct xmit_frame *pmgntframe;
1822 struct pkt_attrib *pattrib;
1823 unsigned char *pframe;
1824 struct rtw_ieee80211_hdr *pwlanhdr;
1826 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1827 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1828 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1830 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1834 DBG_88E("[%s] In\n", __func__);
1835 /* update attribute */
1836 pattrib = &pmgntframe->attrib;
1837 update_mgntframe_attrib(padapter, pattrib);
1839 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
1841 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
1842 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
1844 fctrl = &(pwlanhdr->frame_ctl);
1847 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
1848 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
1849 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
1851 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
1852 pmlmeext->mgnt_seq++;
1853 SetFrameSubType(pframe, WIFI_ACTION);
1855 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
1856 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
1858 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
1859 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
1860 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
1861 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
1862 pwdinfo->negotiation_dialog_token = 1; /* Initialize the dialog value */
1863 pframe = rtw_set_fixed_ie(pframe, 1, &pwdinfo->negotiation_dialog_token, &(pattrib->pktlen));
1868 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
1873 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
1877 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
1881 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
1883 /* Device Password ID */
1885 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
1889 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
1894 if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN)
1895 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
1896 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN)
1897 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
1898 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC)
1899 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
1903 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
1905 /* P2P IE Section. */
1909 p2pie[p2pielen++] = 0x50;
1910 p2pie[p2pielen++] = 0x6F;
1911 p2pie[p2pielen++] = 0x9A;
1912 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
1914 /* Commented by Albert 20110306 */
1915 /* According to the P2P Specification, the group negoitation request frame should contain 9 P2P attributes */
1916 /* 1. P2P Capability */
1917 /* 2. Group Owner Intent */
1918 /* 3. Configuration Timeout */
1919 /* 4. Listen Channel */
1920 /* 5. Extended Listen Timing */
1921 /* 6. Intended P2P Interface Address */
1922 /* 7. Channel List */
1923 /* 8. P2P Device Info */
1924 /* 9. Operating Channel */
1926 /* P2P Capability */
1928 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
1931 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1935 /* Device Capability Bitmap, 1 byte */
1936 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
1938 /* Group Capability Bitmap, 1 byte */
1939 if (pwdinfo->persistent_supported)
1940 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
1942 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
1944 /* Group Owner Intent */
1946 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
1949 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
1953 /* Todo the tie breaker bit. */
1954 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
1956 /* Configuration Timeout */
1958 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
1961 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1965 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
1966 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
1968 /* Listen Channel */
1970 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
1973 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
1977 /* Country String */
1978 p2pie[p2pielen++] = 'X';
1979 p2pie[p2pielen++] = 'X';
1981 /* The third byte should be set to 0x04. */
1982 /* Described in the "Operating Channel Attribute" section. */
1983 p2pie[p2pielen++] = 0x04;
1985 /* Operating Class */
1986 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
1988 /* Channel Number */
1989 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listening channel number */
1991 /* Extended Listen Timing ATTR */
1993 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
1996 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
2000 /* Availability Period */
2001 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2004 /* Availability Interval */
2005 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2008 /* Intended P2P Interface Address */
2010 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2013 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2017 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2018 p2pielen += ETH_ALEN;
2022 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2025 /* Country String(3) */
2026 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2027 /* + number of channels in all classes */
2028 len_channellist_attr = 3
2029 + (1 + 1) * (u16)(pmlmeext->channel_list.reg_classes)
2030 + get_reg_classes_full_count(&pmlmeext->channel_list);
2032 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2036 /* Country String */
2037 p2pie[p2pielen++] = 'X';
2038 p2pie[p2pielen++] = 'X';
2040 /* The third byte should be set to 0x04. */
2041 /* Described in the "Operating Channel Attribute" section. */
2042 p2pie[p2pielen++] = 0x04;
2044 /* Channel Entry List */
2048 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2049 /* Operating Class */
2050 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2052 /* Number of Channels */
2053 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2056 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2057 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2064 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2067 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2068 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2069 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2073 /* P2P Device Address */
2074 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2075 p2pielen += ETH_ALEN;
2078 /* This field should be big endian. Noted by P2P specification. */
2080 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2084 /* Primary Device Type */
2086 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2090 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2093 /* Sub Category ID */
2094 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2097 /* Number of Secondary Device Types */
2098 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2102 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2106 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2110 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
2111 p2pielen += pwdinfo->device_name_len;
2113 /* Operating Channel */
2115 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2118 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2122 /* Country String */
2123 p2pie[p2pielen++] = 'X';
2124 p2pie[p2pielen++] = 'X';
2126 /* The third byte should be set to 0x04. */
2127 /* Described in the "Operating Channel Attribute" section. */
2128 p2pie[p2pielen++] = 0x04;
2130 /* Operating Class */
2131 p2pie[p2pielen++] = 0x51;
2133 /* Channel Number */
2134 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2136 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2138 pattrib->last_txcmdsz = pattrib->pktlen;
2140 dump_mgntframe(padapter, pmgntframe);
2143 static void issue_p2p_GO_response(struct adapter *padapter, u8 *raddr, u8 *frame_body, uint len, u8 result)
2145 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2146 u8 action = P2P_PUB_ACTION_ACTION;
2147 __be32 p2poui = cpu_to_be32(P2POUI);
2148 u8 oui_subtype = P2P_GO_NEGO_RESP;
2149 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
2152 u16 wps_devicepassword_id = 0x0000;
2154 uint wps_devicepassword_id_len = 0;
2155 u16 len_channellist_attr = 0;
2157 struct xmit_frame *pmgntframe;
2158 struct pkt_attrib *pattrib;
2159 unsigned char *pframe;
2160 struct rtw_ieee80211_hdr *pwlanhdr;
2162 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2163 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2164 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2166 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2170 DBG_88E("[%s] In, result=%d\n", __func__, result);
2171 /* update attribute */
2172 pattrib = &pmgntframe->attrib;
2173 update_mgntframe_attrib(padapter, pattrib);
2175 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2177 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2178 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2180 fctrl = &(pwlanhdr->frame_ctl);
2183 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2184 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2185 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2187 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2188 pmlmeext->mgnt_seq++;
2189 SetFrameSubType(pframe, WIFI_ACTION);
2191 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2192 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2194 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2195 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2196 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2197 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2198 pwdinfo->negotiation_dialog_token = frame_body[7]; /* The Dialog Token of provisioning discovery request frame. */
2199 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2201 /* Commented by Albert 20110328 */
2202 /* Try to get the device password ID from the WPS IE of group negotiation request frame */
2203 /* WiFi Direct test plan 5.1.15 */
2204 rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
2205 rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *)&be_tmp, &wps_devicepassword_id_len);
2206 wps_devicepassword_id = be16_to_cpu(be_tmp);
2208 memset(wpsie, 0x00, 255);
2214 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
2219 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
2223 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
2227 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
2229 /* Device Password ID */
2231 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
2235 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
2239 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2240 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
2241 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2242 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
2244 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
2247 /* Commented by Kurt 20120113 */
2248 /* If some device wants to do p2p handshake without sending prov_disc_req */
2249 /* We have to get peer_req_cm from here. */
2250 if (!memcmp(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3)) {
2251 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2252 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
2253 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2254 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
2256 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
2259 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
2261 /* P2P IE Section. */
2265 p2pie[p2pielen++] = 0x50;
2266 p2pie[p2pielen++] = 0x6F;
2267 p2pie[p2pielen++] = 0x9A;
2268 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2270 /* Commented by Albert 20100908 */
2271 /* According to the P2P Specification, the group negoitation response frame should contain 9 P2P attributes */
2273 /* 2. P2P Capability */
2274 /* 3. Group Owner Intent */
2275 /* 4. Configuration Timeout */
2276 /* 5. Operating Channel */
2277 /* 6. Intended P2P Interface Address */
2278 /* 7. Channel List */
2279 /* 8. Device Info */
2280 /* 9. Group ID (Only GO) */
2286 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2289 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2293 p2pie[p2pielen++] = result;
2295 /* P2P Capability */
2297 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2300 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2304 /* Device Capability Bitmap, 1 byte */
2306 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2307 /* Commented by Albert 2011/03/08 */
2308 /* According to the P2P specification */
2309 /* if the sending device will be client, the P2P Capability should be reserved of group negotiation response frame */
2310 p2pie[p2pielen++] = 0;
2312 /* Be group owner or meet the error case */
2313 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2316 /* Group Capability Bitmap, 1 byte */
2317 if (pwdinfo->persistent_supported) {
2318 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2320 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2323 /* Group Owner Intent */
2325 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
2328 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2332 if (pwdinfo->peer_intent & 0x01) {
2333 /* Peer's tie breaker bit is 1, our tie breaker bit should be 0 */
2334 p2pie[p2pielen++] = (pwdinfo->intent << 1);
2336 /* Peer's tie breaker bit is 0, our tie breaker bit should be 1 */
2337 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
2340 /* Configuration Timeout */
2342 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2345 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2349 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2350 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2352 /* Operating Channel */
2354 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2357 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2361 /* Country String */
2362 p2pie[p2pielen++] = 'X';
2363 p2pie[p2pielen++] = 'X';
2365 /* The third byte should be set to 0x04. */
2366 /* Described in the "Operating Channel Attribute" section. */
2367 p2pie[p2pielen++] = 0x04;
2369 /* Operating Class */
2370 p2pie[p2pielen++] = 0x51;
2372 /* Channel Number */
2373 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2375 /* Intended P2P Interface Address */
2377 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2380 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2384 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2385 p2pielen += ETH_ALEN;
2389 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2391 /* Country String(3) */
2392 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2393 /* + number of channels in all classes */
2394 len_channellist_attr = 3
2395 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2396 + get_reg_classes_full_count(&pmlmeext->channel_list);
2398 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2403 /* Country String */
2404 p2pie[p2pielen++] = 'X';
2405 p2pie[p2pielen++] = 'X';
2407 /* The third byte should be set to 0x04. */
2408 /* Described in the "Operating Channel Attribute" section. */
2409 p2pie[p2pielen++] = 0x04;
2411 /* Channel Entry List */
2415 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2416 /* Operating Class */
2417 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2419 /* Number of Channels */
2420 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2423 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2424 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2431 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2434 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2435 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2436 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2440 /* P2P Device Address */
2441 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2442 p2pielen += ETH_ALEN;
2445 /* This field should be big endian. Noted by P2P specification. */
2447 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2451 /* Primary Device Type */
2453 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2457 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2460 /* Sub Category ID */
2461 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2464 /* Number of Secondary Device Types */
2465 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2469 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2473 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2477 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
2478 p2pielen += pwdinfo->device_name_len;
2480 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2481 /* Group ID Attribute */
2483 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2486 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2490 /* p2P Device Address */
2491 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN);
2492 p2pielen += ETH_ALEN;
2495 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2496 p2pielen += pwdinfo->nego_ssidlen;
2499 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2501 pattrib->last_txcmdsz = pattrib->pktlen;
2503 dump_mgntframe(padapter, pmgntframe);
2506 static void issue_p2p_GO_confirm(struct adapter *padapter, u8 *raddr, u8 result)
2508 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2509 u8 action = P2P_PUB_ACTION_ACTION;
2510 __be32 p2poui = cpu_to_be32(P2POUI);
2511 u8 oui_subtype = P2P_GO_NEGO_CONF;
2512 u8 p2pie[255] = { 0x00 };
2515 struct xmit_frame *pmgntframe;
2516 struct pkt_attrib *pattrib;
2517 unsigned char *pframe;
2518 struct rtw_ieee80211_hdr *pwlanhdr;
2520 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2521 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2522 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2524 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2528 DBG_88E("[%s] In\n", __func__);
2529 /* update attribute */
2530 pattrib = &pmgntframe->attrib;
2531 update_mgntframe_attrib(padapter, pattrib);
2533 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2535 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2536 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2538 fctrl = &(pwlanhdr->frame_ctl);
2541 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2542 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2543 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2545 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2546 pmlmeext->mgnt_seq++;
2547 SetFrameSubType(pframe, WIFI_ACTION);
2549 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2550 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2552 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2553 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2554 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2555 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2556 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2558 /* P2P IE Section. */
2562 p2pie[p2pielen++] = 0x50;
2563 p2pie[p2pielen++] = 0x6F;
2564 p2pie[p2pielen++] = 0x9A;
2565 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2567 /* Commented by Albert 20110306 */
2568 /* According to the P2P Specification, the group negoitation request frame should contain 5 P2P attributes */
2570 /* 2. P2P Capability */
2571 /* 3. Operating Channel */
2572 /* 4. Channel List */
2573 /* 5. Group ID (if this WiFi is GO) */
2577 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2580 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2584 p2pie[p2pielen++] = result;
2586 /* P2P Capability */
2588 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2591 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2595 /* Device Capability Bitmap, 1 byte */
2596 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2598 /* Group Capability Bitmap, 1 byte */
2599 if (pwdinfo->persistent_supported)
2600 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2602 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2604 /* Operating Channel */
2606 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2609 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2613 /* Country String */
2614 p2pie[p2pielen++] = 'X';
2615 p2pie[p2pielen++] = 'X';
2617 /* The third byte should be set to 0x04. */
2618 /* Described in the "Operating Channel Attribute" section. */
2619 p2pie[p2pielen++] = 0x04;
2621 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2622 /* Operating Class */
2623 p2pie[p2pielen++] = 0x51;
2624 p2pie[p2pielen++] = pwdinfo->peer_operating_ch;
2626 /* Operating Class */
2627 p2pie[p2pielen++] = 0x51;
2629 /* Channel Number */
2630 p2pie[p2pielen++] = pwdinfo->operating_channel; /* Use the listen channel as the operating channel */
2635 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2638 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(pwdinfo->channel_list_attr_len);
2642 memcpy(p2pie + p2pielen, pwdinfo->channel_list_attr, pwdinfo->channel_list_attr_len);
2643 p2pielen += pwdinfo->channel_list_attr_len;
2645 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2646 /* Group ID Attribute */
2648 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2651 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2655 /* p2P Device Address */
2656 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN);
2657 p2pielen += ETH_ALEN;
2660 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2661 p2pielen += pwdinfo->nego_ssidlen;
2663 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2664 pattrib->last_txcmdsz = pattrib->pktlen;
2665 dump_mgntframe(padapter, pmgntframe);
2668 void issue_p2p_invitation_request(struct adapter *padapter, u8 *raddr)
2670 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2671 u8 action = P2P_PUB_ACTION_ACTION;
2672 __be32 p2poui = cpu_to_be32(P2POUI);
2673 u8 oui_subtype = P2P_INVIT_REQ;
2674 u8 p2pie[255] = { 0x00 };
2677 u16 len_channellist_attr = 0;
2678 struct xmit_frame *pmgntframe;
2679 struct pkt_attrib *pattrib;
2680 unsigned char *pframe;
2681 struct rtw_ieee80211_hdr *pwlanhdr;
2683 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2684 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2685 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2687 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2691 /* update attribute */
2692 pattrib = &pmgntframe->attrib;
2693 update_mgntframe_attrib(padapter, pattrib);
2695 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2697 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2698 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2700 fctrl = &(pwlanhdr->frame_ctl);
2703 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2704 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2705 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
2707 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2708 pmlmeext->mgnt_seq++;
2709 SetFrameSubType(pframe, WIFI_ACTION);
2711 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2712 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2714 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2715 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2716 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2717 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2718 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
2720 /* P2P IE Section. */
2724 p2pie[p2pielen++] = 0x50;
2725 p2pie[p2pielen++] = 0x6F;
2726 p2pie[p2pielen++] = 0x9A;
2727 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2729 /* Commented by Albert 20101011 */
2730 /* According to the P2P Specification, the P2P Invitation request frame should contain 7 P2P attributes */
2731 /* 1. Configuration Timeout */
2732 /* 2. Invitation Flags */
2733 /* 3. Operating Channel (Only GO) */
2734 /* 4. P2P Group BSSID (Should be included if I am the GO) */
2735 /* 5. Channel List */
2736 /* 6. P2P Group ID */
2737 /* 7. P2P Device Info */
2739 /* Configuration Timeout */
2741 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2744 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2748 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2749 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2751 /* Invitation Flags */
2753 p2pie[p2pielen++] = P2P_ATTR_INVITATION_FLAGS;
2756 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2760 p2pie[p2pielen++] = P2P_INVITATION_FLAGS_PERSISTENT;
2762 /* Operating Channel */
2764 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2767 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2771 /* Country String */
2772 p2pie[p2pielen++] = 'X';
2773 p2pie[p2pielen++] = 'X';
2775 /* The third byte should be set to 0x04. */
2776 /* Described in the "Operating Channel Attribute" section. */
2777 p2pie[p2pielen++] = 0x04;
2779 /* Operating Class */
2780 p2pie[p2pielen++] = 0x51;
2782 /* Channel Number */
2783 p2pie[p2pielen++] = pwdinfo->invitereq_info.operating_ch; /* operating channel number */
2785 if (!memcmp(myid(&padapter->eeprompriv), pwdinfo->invitereq_info.go_bssid, ETH_ALEN)) {
2786 /* P2P Group BSSID */
2788 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
2791 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2795 /* P2P Device Address for GO */
2796 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2797 p2pielen += ETH_ALEN;
2802 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2805 /* Country String(3) */
2806 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2807 /* + number of channels in all classes */
2808 len_channellist_attr = 3
2809 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2810 + get_reg_classes_full_count(&pmlmeext->channel_list);
2812 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2817 /* Country String */
2818 p2pie[p2pielen++] = 'X';
2819 p2pie[p2pielen++] = 'X';
2821 /* The third byte should be set to 0x04. */
2822 /* Described in the "Operating Channel Attribute" section. */
2823 p2pie[p2pielen++] = 0x04;
2825 /* Channel Entry List */
2828 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2829 /* Operating Class */
2830 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2832 /* Number of Channels */
2833 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2836 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2837 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2844 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2847 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(6 + pwdinfo->invitereq_info.ssidlen);
2851 /* P2P Device Address for GO */
2852 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2853 p2pielen += ETH_ALEN;
2856 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_ssid, pwdinfo->invitereq_info.ssidlen);
2857 p2pielen += pwdinfo->invitereq_info.ssidlen;
2861 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2864 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2865 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2866 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2870 /* P2P Device Address */
2871 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2872 p2pielen += ETH_ALEN;
2875 /* This field should be big endian. Noted by P2P specification. */
2876 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
2879 /* Primary Device Type */
2881 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2885 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2888 /* Sub Category ID */
2889 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2892 /* Number of Secondary Device Types */
2893 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2897 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2901 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2905 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
2906 p2pielen += pwdinfo->device_name_len;
2908 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2910 pattrib->last_txcmdsz = pattrib->pktlen;
2912 dump_mgntframe(padapter, pmgntframe);
2915 void issue_p2p_invitation_response(struct adapter *padapter, u8 *raddr, u8 dialogToken, u8 status_code)
2917 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2918 u8 action = P2P_PUB_ACTION_ACTION;
2919 __be32 p2poui = cpu_to_be32(P2POUI);
2920 u8 oui_subtype = P2P_INVIT_RESP;
2921 u8 p2pie[255] = { 0x00 };
2923 u16 len_channellist_attr = 0;
2924 struct xmit_frame *pmgntframe;
2925 struct pkt_attrib *pattrib;
2926 unsigned char *pframe;
2927 struct rtw_ieee80211_hdr *pwlanhdr;
2929 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2930 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2931 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2933 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2937 /* update attribute */
2938 pattrib = &pmgntframe->attrib;
2939 update_mgntframe_attrib(padapter, pattrib);
2941 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2943 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2944 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2946 fctrl = &(pwlanhdr->frame_ctl);
2949 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2950 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2951 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
2953 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2954 pmlmeext->mgnt_seq++;
2955 SetFrameSubType(pframe, WIFI_ACTION);
2957 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2958 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2960 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2961 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2962 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2963 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2964 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
2966 /* P2P IE Section. */
2970 p2pie[p2pielen++] = 0x50;
2971 p2pie[p2pielen++] = 0x6F;
2972 p2pie[p2pielen++] = 0x9A;
2973 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2975 /* Commented by Albert 20101005 */
2976 /* According to the P2P Specification, the P2P Invitation response frame should contain 5 P2P attributes */
2978 /* 2. Configuration Timeout */
2979 /* 3. Operating Channel (Only GO) */
2980 /* 4. P2P Group BSSID (Only GO) */
2981 /* 5. Channel List */
2985 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2988 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2992 /* When status code is P2P_STATUS_FAIL_INFO_UNAVAILABLE. */
2993 /* Sent the event receiving the P2P Invitation Req frame to DMP UI. */
2994 /* DMP had to compare the MAC address to find out the profile. */
2995 /* So, the WiFi driver will send the P2P_STATUS_FAIL_INFO_UNAVAILABLE to NB. */
2996 /* If the UI found the corresponding profile, the WiFi driver sends the P2P Invitation Req */
2997 /* to NB to rebuild the persistent group. */
2998 p2pie[p2pielen++] = status_code;
3000 /* Configuration Timeout */
3002 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
3005 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3009 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
3010 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
3012 if (status_code == P2P_STATUS_SUCCESS) {
3013 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3014 /* The P2P Invitation request frame asks this Wi-Fi device to be the P2P GO */
3015 /* In this case, the P2P Invitation response frame should carry the two more P2P attributes. */
3016 /* First one is operating channel attribute. */
3017 /* Second one is P2P Group BSSID attribute. */
3019 /* Operating Channel */
3021 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3024 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3028 /* Country String */
3029 p2pie[p2pielen++] = 'X';
3030 p2pie[p2pielen++] = 'X';
3032 /* The third byte should be set to 0x04. */
3033 /* Described in the "Operating Channel Attribute" section. */
3034 p2pie[p2pielen++] = 0x04;
3036 /* Operating Class */
3037 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3039 /* Channel Number */
3040 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3042 /* P2P Group BSSID */
3044 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
3047 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
3051 /* P2P Device Address for GO */
3052 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
3053 p2pielen += ETH_ALEN;
3058 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
3061 /* Country String(3) */
3062 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
3063 /* + number of channels in all classes */
3064 len_channellist_attr = 3
3065 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
3066 + get_reg_classes_full_count(&pmlmeext->channel_list);
3068 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
3072 /* Country String */
3073 p2pie[p2pielen++] = 'X';
3074 p2pie[p2pielen++] = 'X';
3076 /* The third byte should be set to 0x04. */
3077 /* Described in the "Operating Channel Attribute" section. */
3078 p2pie[p2pielen++] = 0x04;
3080 /* Channel Entry List */
3083 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3084 /* Operating Class */
3085 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3087 /* Number of Channels */
3088 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3091 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3092 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3098 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3100 pattrib->last_txcmdsz = pattrib->pktlen;
3102 dump_mgntframe(padapter, pmgntframe);
3105 void issue_p2p_provision_request(struct adapter *padapter, u8 *pssid, u8 ussidlen, u8 *pdev_raddr)
3107 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3108 u8 action = P2P_PUB_ACTION_ACTION;
3110 u8 oui_subtype = P2P_PROVISION_DISC_REQ;
3111 u8 wpsie[100] = { 0x00 };
3113 __be32 p2poui = cpu_to_be32(P2POUI);
3115 struct xmit_frame *pmgntframe;
3116 struct pkt_attrib *pattrib;
3117 unsigned char *pframe;
3118 struct rtw_ieee80211_hdr *pwlanhdr;
3120 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3121 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3122 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3124 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3128 DBG_88E("[%s] In\n", __func__);
3129 /* update attribute */
3130 pattrib = &pmgntframe->attrib;
3131 update_mgntframe_attrib(padapter, pattrib);
3133 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3135 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3136 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3138 fctrl = &(pwlanhdr->frame_ctl);
3141 memcpy(pwlanhdr->addr1, pdev_raddr, ETH_ALEN);
3142 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3143 memcpy(pwlanhdr->addr3, pdev_raddr, ETH_ALEN);
3145 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3146 pmlmeext->mgnt_seq++;
3147 SetFrameSubType(pframe, WIFI_ACTION);
3149 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3150 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3152 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3153 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3154 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
3155 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3156 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
3158 p2pielen = build_prov_disc_request_p2p_ie(pwdinfo, pframe, pssid, ussidlen, pdev_raddr);
3161 pattrib->pktlen += p2pielen;
3165 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3170 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3174 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3178 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3182 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3186 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3190 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
3193 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3195 pattrib->last_txcmdsz = pattrib->pktlen;
3197 dump_mgntframe(padapter, pmgntframe);
3200 static u8 is_matched_in_profilelist(u8 *peermacaddr, struct profile_info *profileinfo)
3202 u8 i, match_result = 0;
3204 DBG_88E("[%s] peermac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3205 peermacaddr[0], peermacaddr[1], peermacaddr[2], peermacaddr[3], peermacaddr[4], peermacaddr[5]);
3207 for (i = 0; i < P2P_MAX_PERSISTENT_GROUP_NUM; i++, profileinfo++) {
3208 DBG_88E("[%s] profileinfo_mac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3209 profileinfo->peermac[0], profileinfo->peermac[1], profileinfo->peermac[2], profileinfo->peermac[3], profileinfo->peermac[4], profileinfo->peermac[5]);
3210 if (!memcmp(peermacaddr, profileinfo->peermac, ETH_ALEN)) {
3212 DBG_88E("[%s] Match!\n", __func__);
3216 return match_result;
3219 void issue_probersp_p2p(struct adapter *padapter, unsigned char *da)
3221 struct xmit_frame *pmgntframe;
3222 struct pkt_attrib *pattrib;
3223 unsigned char *pframe;
3224 struct rtw_ieee80211_hdr *pwlanhdr;
3227 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3228 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3229 u16 beacon_interval = 100;
3231 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3232 u8 wpsie[255] = { 0x00 };
3233 u32 wpsielen = 0, p2pielen = 0;
3235 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3239 /* update attribute */
3240 pattrib = &pmgntframe->attrib;
3241 update_mgntframe_attrib(padapter, pattrib);
3243 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3245 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3246 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3248 mac = myid(&(padapter->eeprompriv));
3250 fctrl = &(pwlanhdr->frame_ctl);
3252 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3253 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3255 /* Use the device address for BSSID field. */
3256 memcpy(pwlanhdr->addr3, mac, ETH_ALEN);
3258 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3259 pmlmeext->mgnt_seq++;
3260 SetFrameSubType(fctrl, WIFI_PROBERSP);
3262 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3263 pattrib->pktlen = pattrib->hdrlen;
3264 pframe += pattrib->hdrlen;
3266 /* timestamp will be inserted by hardware */
3268 pattrib->pktlen += 8;
3270 /* beacon interval: 2 bytes */
3271 memcpy(pframe, (unsigned char *)&beacon_interval, 2);
3273 pattrib->pktlen += 2;
3275 /* capability info: 2 bytes */
3276 /* ESS and IBSS bits must be 0 (defined in the 3.1.2.1.1 of WiFi Direct Spec) */
3277 capInfo |= cap_ShortPremble;
3278 capInfo |= cap_ShortSlot;
3280 memcpy(pframe, (unsigned char *)&capInfo, 2);
3282 pattrib->pktlen += 2;
3285 pframe = rtw_set_ie(pframe, _SSID_IE_, 7, pwdinfo->p2p_wildcard_ssid, &pattrib->pktlen);
3287 /* supported rates... */
3288 /* Use the OFDM rate in the P2P probe response frame. (6(B), 9(B), 12, 18, 24, 36, 48, 54) */
3289 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3291 /* DS parameter set */
3292 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&pwdinfo->listen_channel, &pattrib->pktlen);
3295 /* Noted by Albert 20100907 */
3296 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3300 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3305 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3309 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3313 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3315 /* WiFi Simple Config State */
3317 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SIMPLE_CONF_STATE);
3321 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3325 wpsie[wpsielen++] = WPS_WSC_STATE_NOT_CONFIG; /* Not Configured. */
3329 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_RESP_TYPE);
3333 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3337 wpsie[wpsielen++] = WPS_RESPONSE_TYPE_8021X;
3341 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3345 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3349 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3354 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MANUFACTURER);
3358 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0007);
3362 memcpy(wpsie + wpsielen, "Realtek", 7);
3367 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NAME);
3371 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0006);
3375 memcpy(wpsie + wpsielen, "8188EU", 6);
3380 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NUMBER);
3384 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3388 wpsie[wpsielen++] = 0x31; /* character 1 */
3392 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SERIAL_NUMBER);
3396 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(ETH_ALEN);
3400 memcpy(wpsie + wpsielen, "123456", ETH_ALEN);
3401 wpsielen += ETH_ALEN;
3403 /* Primary Device Type */
3405 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3409 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3414 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
3418 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3421 /* Sub Category ID */
3422 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
3427 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3431 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3435 if (pwdinfo->device_name_len) {
3436 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3437 wpsielen += pwdinfo->device_name_len;
3442 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3446 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3450 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3453 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3455 p2pielen = build_probe_resp_p2p_ie(pwdinfo, pframe);
3457 pattrib->pktlen += p2pielen;
3459 pattrib->last_txcmdsz = pattrib->pktlen;
3461 dump_mgntframe(padapter, pmgntframe);
3464 static int _issue_probereq_p2p(struct adapter *padapter, u8 *da, int wait_ack)
3467 struct xmit_frame *pmgntframe;
3468 struct pkt_attrib *pattrib;
3469 unsigned char *pframe;
3470 struct rtw_ieee80211_hdr *pwlanhdr;
3473 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3474 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3475 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3476 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3477 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
3478 u16 wpsielen = 0, p2pielen = 0;
3479 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3481 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3485 /* update attribute */
3486 pattrib = &pmgntframe->attrib;
3487 update_mgntframe_attrib(padapter, pattrib);
3489 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3491 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3492 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3494 mac = myid(&(padapter->eeprompriv));
3496 fctrl = &(pwlanhdr->frame_ctl);
3500 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3501 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
3503 if ((pwdinfo->p2p_info.scan_op_ch_only) || (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
3504 /* This two flags will be set when this is only the P2P client mode. */
3505 memcpy(pwlanhdr->addr1, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3506 memcpy(pwlanhdr->addr3, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3508 /* broadcast probe request frame */
3509 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
3510 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
3513 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3515 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3516 pmlmeext->mgnt_seq++;
3517 SetFrameSubType(pframe, WIFI_PROBEREQ);
3519 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
3520 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
3522 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
3523 pframe = rtw_set_ie(pframe, _SSID_IE_, pwdinfo->tx_prov_disc_info.ssid.SsidLength, pwdinfo->tx_prov_disc_info.ssid.Ssid, &(pattrib->pktlen));
3525 pframe = rtw_set_ie(pframe, _SSID_IE_, P2P_WILDCARD_SSID_LEN, pwdinfo->p2p_wildcard_ssid, &(pattrib->pktlen));
3527 /* Use the OFDM rate in the P2P probe request frame. (6(B), 9(B), 12(B), 24(B), 36, 48, 54) */
3528 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3531 /* Noted by Albert 20110221 */
3532 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3536 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3541 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3545 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3549 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3551 if (!pmlmepriv->wps_probe_req_ie) {
3554 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3558 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3562 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3567 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3571 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3575 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3581 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3585 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3589 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3590 wpsielen += pwdinfo->device_name_len;
3592 /* Primary Device Type */
3594 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3598 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3603 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_RTK_WIDI);
3607 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3610 /* Sub Category ID */
3611 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_RTK_DMP);
3614 /* Device Password ID */
3616 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
3620 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3624 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC); /* Registrar-specified */
3627 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3631 p2pie[p2pielen++] = 0x50;
3632 p2pie[p2pielen++] = 0x6F;
3633 p2pie[p2pielen++] = 0x9A;
3634 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
3636 /* Commented by Albert 20110221 */
3637 /* According to the P2P Specification, the probe request frame should contain 5 P2P attributes */
3638 /* 1. P2P Capability */
3639 /* 2. P2P Device ID if this probe request wants to find the specific P2P device */
3640 /* 3. Listen Channel */
3641 /* 4. Extended Listen Timing */
3642 /* 5. Operating Channel if this WiFi is working as the group owner now */
3644 /* P2P Capability */
3646 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
3649 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3653 /* Device Capability Bitmap, 1 byte */
3654 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
3656 /* Group Capability Bitmap, 1 byte */
3657 if (pwdinfo->persistent_supported)
3658 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
3660 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
3662 /* Listen Channel */
3664 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
3667 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3671 /* Country String */
3672 p2pie[p2pielen++] = 'X';
3673 p2pie[p2pielen++] = 'X';
3675 /* The third byte should be set to 0x04. */
3676 /* Described in the "Operating Channel Attribute" section. */
3677 p2pie[p2pielen++] = 0x04;
3679 /* Operating Class */
3680 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3682 /* Channel Number */
3683 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listen channel */
3685 /* Extended Listen Timing */
3687 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
3690 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
3694 /* Availability Period */
3695 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3698 /* Availability Interval */
3699 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3702 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3703 /* Operating Channel (if this WiFi is working as the group owner now) */
3705 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3708 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3712 /* Country String */
3713 p2pie[p2pielen++] = 'X';
3714 p2pie[p2pielen++] = 'X';
3716 /* The third byte should be set to 0x04. */
3717 /* Described in the "Operating Channel Attribute" section. */
3718 p2pie[p2pielen++] = 0x04;
3720 /* Operating Class */
3721 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3723 /* Channel Number */
3724 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3727 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3729 if (pmlmepriv->wps_probe_req_ie) {
3731 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
3732 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
3733 pframe += pmlmepriv->wps_probe_req_ie_len;
3736 pattrib->last_txcmdsz = pattrib->pktlen;
3739 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
3741 dump_mgntframe(padapter, pmgntframe);
3749 inline void issue_probereq_p2p(struct adapter *adapter, u8 *da)
3751 _issue_probereq_p2p(adapter, da, false);
3754 int issue_probereq_p2p_ex(struct adapter *adapter, u8 *da, int try_cnt, int wait_ms)
3758 u32 start = jiffies;
3761 ret = _issue_probereq_p2p(adapter, da, wait_ms > 0 ? true : false);
3765 if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
3768 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3770 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3777 if (try_cnt && wait_ms) {
3779 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
3780 FUNC_ADPT_ARG(adapter), da, rtw_get_oper_ch(adapter),
3781 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3783 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
3784 FUNC_ADPT_ARG(adapter), rtw_get_oper_ch(adapter),
3785 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3791 #endif /* CONFIG_88EU_P2P */
3793 static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
3795 struct adapter *adapter = recv_frame->adapter;
3796 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3797 u8 *frame = recv_frame->rx_data;
3798 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) |
3799 (recv_frame->attrib.frag_num & 0xf);
3801 if (GetRetry(frame)) {
3803 if ((seq_ctrl == mlmeext->action_public_rxseq) && (token == mlmeext->action_public_dialog_token)) {
3804 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x, token:%d\n",
3805 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
3809 if (seq_ctrl == mlmeext->action_public_rxseq) {
3810 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x\n",
3811 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq);
3817 mlmeext->action_public_rxseq = seq_ctrl;
3820 mlmeext->action_public_dialog_token = token;
3825 static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
3827 u8 *pframe = precv_frame->rx_data;
3830 #ifdef CONFIG_88EU_P2P
3831 struct adapter *padapter = precv_frame->adapter;
3832 uint len = precv_frame->len;
3835 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3836 u8 result = P2P_STATUS_SUCCESS;
3837 u8 empty_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3838 #endif /* CONFIG_88EU_P2P */
3840 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
3842 dialogToken = frame_body[7];
3844 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
3847 #ifdef CONFIG_88EU_P2P
3848 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
3849 /* Do nothing if the driver doesn't enable the P2P function. */
3850 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
3853 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
3855 switch (frame_body[6]) { /* OUI Subtype */
3856 case P2P_GO_NEGO_REQ:
3857 DBG_88E("[%s] Got GO Nego Req Frame\n", __func__);
3858 memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
3860 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
3861 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3863 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL)) {
3864 /* Commented by Albert 20110526 */
3865 /* In this case, this means the previous nego fail doesn't be reset yet. */
3866 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3867 /* Restore the previous p2p state */
3868 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3869 DBG_88E("[%s] Restore the previous p2p state to %d\n", __func__, rtw_p2p_state(pwdinfo));
3872 /* Commented by Kurt 20110902 */
3873 /* Add if statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
3874 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
3875 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3877 /* Commented by Kurt 20120113 */
3878 /* Get peer_dev_addr here if peer doesn't issue prov_disc frame. */
3879 if (!memcmp(pwdinfo->rx_prov_disc_info.peerDevAddr, empty_addr, ETH_ALEN))
3880 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
3882 result = process_p2p_group_negotation_req(pwdinfo, frame_body, len);
3883 issue_p2p_GO_response(padapter, GetAddr2Ptr(pframe), frame_body, len, result);
3885 /* Commented by Albert 20110718 */
3886 /* No matter negotiating or negotiation failure, the driver should set up the restore P2P state timer. */
3887 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3889 case P2P_GO_NEGO_RESP:
3890 DBG_88E("[%s] Got GO Nego Resp Frame\n", __func__);
3892 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
3893 /* Commented by Albert 20110425 */
3894 /* The restore timer is enabled when issuing the nego request frame of rtw_p2p_connect function. */
3895 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3896 pwdinfo->nego_req_info.benable = false;
3897 result = process_p2p_group_negotation_resp(pwdinfo, frame_body, len);
3898 issue_p2p_GO_confirm(pwdinfo->padapter, GetAddr2Ptr(pframe), result);
3899 if (P2P_STATUS_SUCCESS == result) {
3900 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3901 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3902 pwdinfo->p2p_info.scan_op_ch_only = 1;
3903 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3906 /* Reset the dialog token for group negotiation frames. */
3907 pwdinfo->negotiation_dialog_token = 1;
3908 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
3909 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3911 DBG_88E("[%s] Skipped GO Nego Resp Frame (p2p_state != P2P_STATE_GONEGO_ING)\n", __func__);
3914 case P2P_GO_NEGO_CONF:
3915 DBG_88E("[%s] Got GO Nego Confirm Frame\n", __func__);
3916 result = process_p2p_group_negotation_confirm(pwdinfo, frame_body, len);
3917 if (P2P_STATUS_SUCCESS == result) {
3918 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3919 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3920 pwdinfo->p2p_info.scan_op_ch_only = 1;
3921 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3926 /* Added by Albert 2010/10/05 */
3927 /* Received the P2P Invite Request frame. */
3929 DBG_88E("[%s] Got invite request frame!\n", __func__);
3930 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
3932 /* Parse the necessary information from the P2P Invitation Request frame. */
3933 /* For example: The MAC address of sending this P2P Invitation Request frame. */
3934 u32 attr_contentlen = 0;
3935 u8 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
3936 struct group_id_info group_id;
3937 u8 invitation_flag = 0;
3939 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INVITATION_FLAGS, &invitation_flag, &attr_contentlen);
3940 if (attr_contentlen) {
3941 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_BSSID, pwdinfo->p2p_peer_interface_addr, &attr_contentlen);
3942 /* Commented by Albert 20120510 */
3943 /* Copy to the pwdinfo->p2p_peer_interface_addr. */
3944 /* So that the WFD UI (or Sigma) can get the peer interface address by using the following command. */
3945 /* #> iwpriv wlan0 p2p_get peer_ifa */
3946 /* After having the peer interface address, the sigma can find the correct conf file for wpa_supplicant. */
3948 if (attr_contentlen) {
3949 DBG_88E("[%s] GO's BSSID = %.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3950 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1],
3951 pwdinfo->p2p_peer_interface_addr[2], pwdinfo->p2p_peer_interface_addr[3],
3952 pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
3955 if (invitation_flag & P2P_INVITATION_FLAGS_PERSISTENT) {
3956 /* Re-invoke the persistent group. */
3958 memset(&group_id, 0x00, sizeof(struct group_id_info));
3959 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
3960 if (attr_contentlen) {
3961 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
3962 /* The p2p device sending this p2p invitation request wants this Wi-Fi device to be the persistent GO. */
3963 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_GO);
3964 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
3965 status_code = P2P_STATUS_SUCCESS;
3967 /* The p2p device sending this p2p invitation request wants to be the persistent GO. */
3968 if (is_matched_in_profilelist(pwdinfo->p2p_peer_interface_addr, &pwdinfo->profileinfo[0])) {
3969 u8 operatingch_info[5] = { 0x00 };
3970 if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen)) {
3971 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, (u32)operatingch_info[4])) {
3972 /* The operating channel is acceptable for this device. */
3973 pwdinfo->rx_invitereq_info.operation_ch[0] = operatingch_info[4];
3974 pwdinfo->rx_invitereq_info.scan_op_ch_only = 1;
3975 _set_timer(&pwdinfo->reset_ch_sitesurvey, P2P_RESET_SCAN_CH);
3976 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
3977 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
3978 status_code = P2P_STATUS_SUCCESS;
3980 /* The operating channel isn't supported by this device. */
3981 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
3982 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
3983 status_code = P2P_STATUS_FAIL_NO_COMMON_CH;
3984 _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
3987 /* Commented by Albert 20121130 */
3988 /* Intel will use the different P2P IE to store the operating channel information */
3989 /* Workaround for Intel WiDi 3.5 */
3990 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
3991 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
3992 status_code = P2P_STATUS_SUCCESS;
3995 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
3996 status_code = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
4000 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4001 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4004 /* Received the invitation to join a P2P group. */
4006 memset(&group_id, 0x00, sizeof(struct group_id_info));
4007 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
4008 if (attr_contentlen) {
4009 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
4010 /* In this case, the GO can't be myself. */
4011 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4012 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4014 /* The p2p device sending this p2p invitation request wants to join an existing P2P group */
4015 /* Commented by Albert 2012/06/28 */
4016 /* In this case, this Wi-Fi device should use the iwpriv command to get the peer device address. */
4017 /* The peer device address should be the destination address for the provisioning discovery request. */
4018 /* Then, this Wi-Fi device should use the iwpriv command to get the peer interface address. */
4019 /* The peer interface address should be the address for WPS mac address */
4020 memcpy(pwdinfo->p2p_peer_device_addr, group_id.go_device_addr, ETH_ALEN);
4021 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4022 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_JOIN);
4023 status_code = P2P_STATUS_SUCCESS;
4026 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4027 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4031 DBG_88E("[%s] P2P Invitation Flags Attribute NOT FOUND!\n", __func__);
4032 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4035 DBG_88E("[%s] status_code = %d\n", __func__, status_code);
4037 pwdinfo->inviteresp_info.token = frame_body[7];
4038 issue_p2p_invitation_response(padapter, GetAddr2Ptr(pframe), pwdinfo->inviteresp_info.token, status_code);
4041 case P2P_INVIT_RESP: {
4042 u8 attr_content = 0x00;
4043 u32 attr_contentlen = 0;
4045 DBG_88E("[%s] Got invite response frame!\n", __func__);
4046 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4047 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
4049 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
4051 if (attr_contentlen == 1) {
4052 DBG_88E("[%s] Status = %d\n", __func__, attr_content);
4053 pwdinfo->invitereq_info.benable = false;
4055 if (attr_content == P2P_STATUS_SUCCESS) {
4056 if (!memcmp(pwdinfo->invitereq_info.go_bssid, myid(&padapter->eeprompriv), ETH_ALEN)) {
4057 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
4059 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4061 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_OK);
4063 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4064 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4067 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4068 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4071 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4072 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4075 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL))
4076 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
4079 case P2P_DEVDISC_REQ:
4080 process_p2p_devdisc_req(pwdinfo, pframe, len);
4082 case P2P_DEVDISC_RESP:
4083 process_p2p_devdisc_resp(pwdinfo, pframe, len);
4085 case P2P_PROVISION_DISC_REQ:
4086 DBG_88E("[%s] Got Provisioning Discovery Request Frame\n", __func__);
4087 process_p2p_provdisc_req(pwdinfo, pframe, len);
4088 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
4091 /* Add the following statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
4092 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
4093 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
4095 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ);
4096 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4098 case P2P_PROVISION_DISC_RESP:
4099 /* Commented by Albert 20110707 */
4100 /* Should we check the pwdinfo->tx_prov_disc_info.bsent flag here?? */
4101 DBG_88E("[%s] Got Provisioning Discovery Response Frame\n", __func__);
4102 /* Commented by Albert 20110426 */
4103 /* The restore timer is enabled when issuing the provisioing request frame in rtw_p2p_prov_disc function. */
4104 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4105 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP);
4106 process_p2p_provdisc_resp(pwdinfo, pframe);
4107 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4110 #endif /* CONFIG_88EU_P2P */
4115 static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
4117 unsigned int ret = _FAIL;
4118 u8 *pframe = precv_frame->rx_data;
4119 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4121 if (!memcmp(frame_body + 2, P2P_OUI, 4)) {
4122 ret = on_action_public_p2p(precv_frame);
4128 static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action)
4130 unsigned int ret = _FAIL;
4131 u8 *pframe = precv_frame->rx_data;
4132 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4135 token = frame_body[2];
4137 if (rtw_action_public_decache(precv_frame, token) == _FAIL)
4146 unsigned int on_action_public(struct adapter *padapter, struct recv_frame *precv_frame)
4148 unsigned int ret = _FAIL;
4149 u8 *pframe = precv_frame->rx_data;
4150 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4151 u8 category, action;
4153 /* check RA matches or not */
4154 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
4157 category = frame_body[0];
4158 if (category != RTW_WLAN_CATEGORY_PUBLIC)
4161 action = frame_body[1];
4163 case ACT_PUBLIC_VENDOR:
4164 ret = on_action_public_vendor(precv_frame);
4167 ret = on_action_public_default(precv_frame, action);
4175 unsigned int OnAction_ht(struct adapter *padapter, struct recv_frame *precv_frame)
4180 unsigned int OnAction_wmm(struct adapter *padapter, struct recv_frame *precv_frame)
4185 unsigned int OnAction_p2p(struct adapter *padapter, struct recv_frame *precv_frame)
4187 #ifdef CONFIG_88EU_P2P
4189 u8 category, OUI_Subtype;
4190 u8 *pframe = precv_frame->rx_data;
4191 uint len = precv_frame->len;
4192 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4194 DBG_88E("%s\n", __func__);
4196 /* check RA matches or not */
4197 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))/* for if1, sta/ap mode */
4200 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4202 category = frame_body[0];
4203 if (category != RTW_WLAN_CATEGORY_P2P)
4206 if (be32_to_cpu(*((__be32 *)(frame_body + 1))) != P2POUI)
4209 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
4210 OUI_Subtype = frame_body[5];
4212 switch (OUI_Subtype) {
4213 case P2P_NOTICE_OF_ABSENCE:
4215 case P2P_PRESENCE_REQUEST:
4216 process_p2p_presence_req(pwdinfo, pframe, len);
4218 case P2P_PRESENCE_RESPONSE:
4220 case P2P_GO_DISC_REQUEST:
4225 #endif /* CONFIG_88EU_P2P */
4229 unsigned int OnAction(struct adapter *padapter, struct recv_frame *precv_frame)
4232 unsigned char category;
4233 struct action_handler *ptable;
4234 unsigned char *frame_body;
4235 u8 *pframe = precv_frame->rx_data;
4237 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4239 category = frame_body[0];
4241 for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
4242 ptable = &OnAction_tbl[i];
4243 if (category == ptable->num)
4244 ptable->func(padapter, precv_frame);
4249 unsigned int DoReserved(struct adapter *padapter, struct recv_frame *precv_frame)
4254 struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
4256 struct xmit_frame *pmgntframe;
4257 struct xmit_buf *pxmitbuf;
4259 pmgntframe = rtw_alloc_xmitframe(pxmitpriv);
4261 DBG_88E("%s, alloc xmitframe fail\n", __func__);
4265 pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv);
4267 DBG_88E("%s, alloc xmitbuf fail\n", __func__);
4268 rtw_free_xmitframe(pxmitpriv, pmgntframe);
4271 pmgntframe->frame_tag = MGNT_FRAMETAG;
4272 pmgntframe->pxmitbuf = pxmitbuf;
4273 pmgntframe->buf_addr = pxmitbuf->pbuf;
4274 pxmitbuf->priv_data = pmgntframe;
4278 /****************************************************************************
4280 Following are some TX fuctions for WiFi MLME
4282 *****************************************************************************/
4284 void update_mgnt_tx_rate(struct adapter *padapter, u8 rate)
4286 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4288 pmlmeext->tx_rate = rate;
4289 DBG_88E("%s(): rate = %x\n", __func__, rate);
4292 void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib)
4294 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4296 memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib));
4298 pattrib->hdrlen = 24;
4299 pattrib->nr_frags = 1;
4300 pattrib->priority = 7;
4301 pattrib->mac_id = 0;
4302 pattrib->qsel = 0x12;
4304 pattrib->pktlen = 0;
4306 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
4307 pattrib->raid = 6;/* b mode */
4309 pattrib->raid = 5;/* a/g mode */
4311 pattrib->encrypt = _NO_PRIVACY_;
4312 pattrib->bswenc = false;
4314 pattrib->qos_en = false;
4315 pattrib->ht_en = false;
4316 pattrib->bwmode = HT_CHANNEL_WIDTH_20;
4317 pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
4318 pattrib->sgi = false;
4320 pattrib->seqnum = pmlmeext->mgnt_seq;
4322 pattrib->retry_ctrl = true;
4325 void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe)
4327 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4330 rtw_hal_mgnt_xmit(padapter, pmgntframe);
4333 s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
4336 struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
4337 struct submit_ctx sctx;
4339 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4342 rtw_sctx_init(&sctx, timeout_ms);
4343 pxmitbuf->sctx = &sctx;
4345 ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
4347 if (ret == _SUCCESS)
4348 ret = rtw_sctx_wait(&sctx);
4353 s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe)
4356 u32 timeout_ms = 500;/* 500ms */
4357 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
4359 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4362 _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
4363 pxmitpriv->ack_tx = true;
4365 pmgntframe->ack_report = 1;
4366 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
4367 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
4370 pxmitpriv->ack_tx = false;
4371 _exit_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
4376 static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
4382 ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
4384 if (ssid_ie && ssid_len_ori > 0) {
4385 switch (hidden_ssid_mode) {
4387 u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
4390 remain_len = ies_len - (next_ie - ies);
4393 memcpy(ssid_ie+2, next_ie, remain_len);
4394 len_diff -= ssid_len_ori;
4399 memset(&ssid_ie[2], 0, ssid_len_ori);
4409 void issue_beacon(struct adapter *padapter, int timeout_ms)
4411 struct xmit_frame *pmgntframe;
4412 struct pkt_attrib *pattrib;
4413 unsigned char *pframe;
4414 struct rtw_ieee80211_hdr *pwlanhdr;
4416 unsigned int rate_len;
4417 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4418 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4419 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4420 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4421 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4422 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4423 #ifdef CONFIG_88EU_P2P
4424 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4425 #endif /* CONFIG_88EU_P2P */
4427 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4429 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4432 #if defined (CONFIG_88EU_AP_MODE)
4433 spin_lock_bh(&pmlmepriv->bcn_update_lock);
4434 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4436 /* update attribute */
4437 pattrib = &pmgntframe->attrib;
4438 update_mgntframe_attrib(padapter, pattrib);
4439 pattrib->qsel = 0x10;
4441 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4443 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4444 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4446 fctrl = &(pwlanhdr->frame_ctl);
4449 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4450 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4451 memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
4453 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
4454 /* pmlmeext->mgnt_seq++; */
4455 SetFrameSubType(pframe, WIFI_BEACON);
4457 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4458 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4460 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4461 #ifdef CONFIG_88EU_P2P
4462 /* for P2P : Primary Device Type & Device Name */
4463 u32 wpsielen = 0, insert_len = 0;
4465 wpsie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen);
4467 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && wpsie && wpsielen > 0) {
4468 uint wps_offset, remainder_ielen;
4469 u8 *premainder_ie, *pframe_wscie;
4471 wps_offset = (uint)(wpsie - cur_network->IEs);
4472 premainder_ie = wpsie + wpsielen;
4473 remainder_ielen = cur_network->IELength - wps_offset - wpsielen;
4474 pframe_wscie = pframe + wps_offset;
4475 memcpy(pframe, cur_network->IEs, wps_offset+wpsielen);
4476 pframe += (wps_offset + wpsielen);
4477 pattrib->pktlen += (wps_offset + wpsielen);
4479 /* now pframe is end of wsc ie, insert Primary Device Type & Device Name */
4480 /* Primary Device Type */
4482 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
4486 *(__be16 *)(pframe + insert_len) = cpu_to_be16(0x0008);
4491 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
4495 *(__be32 *)(pframe + insert_len) = cpu_to_be32(WPSOUI);
4498 /* Sub Category ID */
4499 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
4504 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
4508 *(__be16 *)(pframe + insert_len) = cpu_to_be16(pwdinfo->device_name_len);
4512 memcpy(pframe + insert_len, pwdinfo->device_name, pwdinfo->device_name_len);
4513 insert_len += pwdinfo->device_name_len;
4515 /* update wsc ie length */
4516 *(pframe_wscie+1) = (wpsielen-2) + insert_len;
4518 /* pframe move to end */
4519 pframe += insert_len;
4520 pattrib->pktlen += insert_len;
4522 /* copy remainder_ie to pframe */
4523 memcpy(pframe, premainder_ie, remainder_ielen);
4524 pframe += remainder_ielen;
4525 pattrib->pktlen += remainder_ielen;
4527 #endif /* CONFIG_88EU_P2P */
4530 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4531 len_diff = update_hidden_ssid(
4532 pframe+_BEACON_IE_OFFSET_
4533 , cur_network->IELength-_BEACON_IE_OFFSET_
4534 , pmlmeinfo->hidden_ssid_mode
4536 pframe += (cur_network->IELength+len_diff);
4537 pattrib->pktlen += (cur_network->IELength+len_diff);
4544 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
4545 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
4546 if (wps_ie && wps_ielen > 0)
4547 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
4549 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
4551 _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
4554 #ifdef CONFIG_88EU_P2P
4555 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
4557 len = build_beacon_p2p_ie(pwdinfo, pframe);
4560 pattrib->pktlen += len;
4562 #endif /* CONFIG_88EU_P2P */
4567 /* below for ad-hoc mode */
4569 /* timestamp will be inserted by hardware */
4571 pattrib->pktlen += 8;
4573 /* beacon interval: 2 bytes */
4575 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4578 pattrib->pktlen += 2;
4580 /* capability info: 2 bytes */
4582 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4585 pattrib->pktlen += 2;
4588 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4590 /* supported rates... */
4591 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4592 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4594 /* DS parameter set */
4595 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4600 /* IBSS Parameter Set... */
4602 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4605 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4608 /* EXTERNDED SUPPORTED RATE */
4610 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4611 /* todo:HT for adhoc */
4614 #if defined (CONFIG_88EU_AP_MODE)
4615 pmlmepriv->update_bcn = false;
4617 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
4618 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4620 if ((pattrib->pktlen + TXDESC_SIZE) > 512) {
4621 DBG_88E("beacon frame too large\n");
4625 pattrib->last_txcmdsz = pattrib->pktlen;
4627 /* DBG_88E("issue bcn_sz=%d\n", pattrib->last_txcmdsz); */
4629 dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
4631 dump_mgntframe(padapter, pmgntframe);
4634 void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
4636 struct xmit_frame *pmgntframe;
4637 struct pkt_attrib *pattrib;
4638 unsigned char *pframe;
4639 struct rtw_ieee80211_hdr *pwlanhdr;
4641 unsigned char *mac, *bssid;
4642 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4643 #if defined (CONFIG_88EU_AP_MODE)
4646 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4647 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4648 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4649 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4650 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4651 unsigned int rate_len;
4652 #ifdef CONFIG_88EU_P2P
4653 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4654 #endif /* CONFIG_88EU_P2P */
4656 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4658 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4662 /* update attribute */
4663 pattrib = &pmgntframe->attrib;
4664 update_mgntframe_attrib(padapter, pattrib);
4666 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4668 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4669 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4671 mac = myid(&(padapter->eeprompriv));
4672 bssid = cur_network->MacAddress;
4674 fctrl = &(pwlanhdr->frame_ctl);
4676 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4677 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4678 memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
4680 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4681 pmlmeext->mgnt_seq++;
4682 SetFrameSubType(fctrl, WIFI_PROBERSP);
4684 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4685 pattrib->pktlen = pattrib->hdrlen;
4686 pframe += pattrib->hdrlen;
4688 if (cur_network->IELength > MAX_IE_SZ)
4691 #if defined(CONFIG_88EU_AP_MODE)
4692 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4693 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
4695 /* inerset & update wps_probe_resp_ie */
4696 if (pmlmepriv->wps_probe_resp_ie && pwps_ie && wps_ielen > 0) {
4697 uint wps_offset, remainder_ielen;
4700 wps_offset = (uint)(pwps_ie - cur_network->IEs);
4702 premainder_ie = pwps_ie + wps_ielen;
4704 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
4706 memcpy(pframe, cur_network->IEs, wps_offset);
4707 pframe += wps_offset;
4708 pattrib->pktlen += wps_offset;
4710 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
4711 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
4712 memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
4713 pframe += wps_ielen+2;
4714 pattrib->pktlen += wps_ielen+2;
4717 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
4718 memcpy(pframe, premainder_ie, remainder_ielen);
4719 pframe += remainder_ielen;
4720 pattrib->pktlen += remainder_ielen;
4723 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4724 pframe += cur_network->IELength;
4725 pattrib->pktlen += cur_network->IELength;
4730 /* timestamp will be inserted by hardware */
4732 pattrib->pktlen += 8;
4734 /* beacon interval: 2 bytes */
4736 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4739 pattrib->pktlen += 2;
4741 /* capability info: 2 bytes */
4743 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4746 pattrib->pktlen += 2;
4748 /* below for ad-hoc mode */
4751 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4753 /* supported rates... */
4754 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4755 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4757 /* DS parameter set */
4758 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4760 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
4763 /* IBSS Parameter Set... */
4764 /* ATIMWindow = cur->Configuration.ATIMWindow; */
4766 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4769 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4772 /* EXTERNDED SUPPORTED RATE */
4774 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4775 /* todo:HT for adhoc */
4778 #ifdef CONFIG_88EU_P2P
4779 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && is_valid_p2p_probereq) {
4781 len = build_probe_resp_p2p_ie(pwdinfo, pframe);
4784 pattrib->pktlen += len;
4786 #endif /* CONFIG_88EU_P2P */
4788 pattrib->last_txcmdsz = pattrib->pktlen;
4790 dump_mgntframe(padapter, pmgntframe);
4793 static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int wait_ack)
4796 struct xmit_frame *pmgntframe;
4797 struct pkt_attrib *pattrib;
4798 unsigned char *pframe;
4799 struct rtw_ieee80211_hdr *pwlanhdr;
4802 unsigned char bssrate[NumRates];
4803 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4804 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4805 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4806 int bssrate_len = 0;
4807 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4809 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4813 /* update attribute */
4814 pattrib = &pmgntframe->attrib;
4815 update_mgntframe_attrib(padapter, pattrib);
4817 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4819 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4820 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4822 mac = myid(&(padapter->eeprompriv));
4824 fctrl = &(pwlanhdr->frame_ctl);
4828 /* unicast probe request frame */
4829 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4830 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
4832 /* broadcast probe request frame */
4833 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4834 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
4837 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4839 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4840 pmlmeext->mgnt_seq++;
4841 SetFrameSubType(pframe, WIFI_PROBEREQ);
4843 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
4844 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4847 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
4849 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
4851 get_rate_set(padapter, bssrate, &bssrate_len);
4853 if (bssrate_len > 8) {
4854 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, bssrate, &(pattrib->pktlen));
4855 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
4857 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, bssrate_len, bssrate, &(pattrib->pktlen));
4860 /* add wps_ie for wps2.0 */
4861 if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) {
4862 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
4863 pframe += pmlmepriv->wps_probe_req_ie_len;
4864 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
4867 pattrib->last_txcmdsz = pattrib->pktlen;
4870 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
4872 dump_mgntframe(padapter, pmgntframe);
4880 inline void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da)
4882 _issue_probereq(padapter, pssid, da, false);
4885 int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da,
4886 int try_cnt, int wait_ms)
4890 u32 start = jiffies;
4893 ret = _issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false);
4897 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
4900 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
4903 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
4910 if (try_cnt && wait_ms) {
4912 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
4913 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
4914 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
4916 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
4917 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
4918 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
4924 /* if psta == NULL, indiate we are station(client) now... */
4925 void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status)
4927 struct xmit_frame *pmgntframe;
4928 struct pkt_attrib *pattrib;
4929 unsigned char *pframe;
4930 struct rtw_ieee80211_hdr *pwlanhdr;
4934 #ifdef CONFIG_88EU_AP_MODE
4937 int use_shared_key = 0;
4938 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4939 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4940 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4942 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4946 /* update attribute */
4947 pattrib = &pmgntframe->attrib;
4948 update_mgntframe_attrib(padapter, pattrib);
4950 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4952 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4953 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4955 fctrl = &(pwlanhdr->frame_ctl);
4958 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4959 pmlmeext->mgnt_seq++;
4960 SetFrameSubType(pframe, WIFI_AUTH);
4962 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4963 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4965 if (psta) {/* for AP mode */
4966 #ifdef CONFIG_88EU_AP_MODE
4968 memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
4969 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4970 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
4972 /* setting auth algo number */
4973 val16 = (u16)psta->authalg;
4975 if (status != _STATS_SUCCESSFUL_)
4979 le_val16 = cpu_to_le16(val16);
4985 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
4987 /* setting auth seq number */
4988 val16 = (u16)psta->auth_seq;
4989 le_val16 = cpu_to_le16(val16);
4990 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
4992 /* setting status code... */
4994 le_val16 = cpu_to_le16(val16);
4995 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_val16, &(pattrib->pktlen));
4997 /* added challenging text... */
4998 if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
4999 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
5004 memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5005 memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
5006 memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5008 /* setting auth algo number */
5009 val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) ? 1 : 0;/* 0:OPEN System, 1:Shared key */
5013 /* setting IV for auth seq #3 */
5014 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5015 val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
5016 le_tmp32 = cpu_to_le32(val32);
5017 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen));
5019 pattrib->iv_len = 4;
5022 le_tmp16 = cpu_to_le16(val16);
5023 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5025 /* setting auth seq number */
5026 val16 = pmlmeinfo->auth_seq;
5027 le_tmp16 = cpu_to_le16(val16);
5028 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5030 /* setting status code... */
5031 le_tmp16 = cpu_to_le16(status);
5032 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5034 /* then checking to see if sending challenging text... */
5035 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5036 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
5040 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5042 pattrib->encrypt = _WEP40_;
5044 pattrib->icv_len = 4;
5046 pattrib->pktlen += pattrib->icv_len;
5050 pattrib->last_txcmdsz = pattrib->pktlen;
5052 rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
5053 DBG_88E("%s\n", __func__);
5054 dump_mgntframe(padapter, pmgntframe);
5057 void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
5059 #ifdef CONFIG_88EU_AP_MODE
5060 struct xmit_frame *pmgntframe;
5061 struct rtw_ieee80211_hdr *pwlanhdr;
5062 struct pkt_attrib *pattrib;
5063 unsigned char *pbuf, *pframe;
5066 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5067 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5068 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5069 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5070 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
5071 u8 *ie = pnetwork->IEs;
5072 __le16 lestatus, leval;
5073 #ifdef CONFIG_88EU_P2P
5074 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5075 #endif /* CONFIG_88EU_P2P */
5077 DBG_88E("%s\n", __func__);
5079 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5083 /* update attribute */
5084 pattrib = &pmgntframe->attrib;
5085 update_mgntframe_attrib(padapter, pattrib);
5087 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5089 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5090 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5092 fctrl = &(pwlanhdr->frame_ctl);
5095 memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
5096 memcpy((void *)GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN);
5097 memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5099 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5100 pmlmeext->mgnt_seq++;
5101 if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
5102 SetFrameSubType(pwlanhdr, pkt_type);
5106 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5107 pattrib->pktlen += pattrib->hdrlen;
5108 pframe += pattrib->hdrlen;
5111 val = *(unsigned short *)rtw_get_capability_from_ie(ie);
5113 pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_, (unsigned char *)&val, &(pattrib->pktlen));
5115 lestatus = cpu_to_le16(status);
5116 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&lestatus, &(pattrib->pktlen));
5118 leval = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
5119 pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_, (unsigned char *)&leval, &(pattrib->pktlen));
5121 if (pstat->bssratelen <= 8) {
5122 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
5124 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
5125 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen-8), pstat->bssrateset+8, &(pattrib->pktlen));
5128 if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) {
5131 /* FILL HT CAP INFO IE */
5132 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5133 if (pbuf && ie_len > 0) {
5134 memcpy(pframe, pbuf, ie_len+2);
5135 pframe += (ie_len+2);
5136 pattrib->pktlen += (ie_len+2);
5139 /* FILL HT ADD INFO IE */
5140 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5141 if (pbuf && ie_len > 0) {
5142 memcpy(pframe, pbuf, ie_len+2);
5143 pframe += (ie_len+2);
5144 pattrib->pktlen += (ie_len+2);
5149 if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) {
5151 unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
5153 for (pbuf = ie + _BEACON_IE_OFFSET_;; pbuf += (ie_len + 2)) {
5154 pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
5155 if (pbuf && !memcmp(pbuf+2, WMM_PARA_IE, 6)) {
5156 memcpy(pframe, pbuf, ie_len+2);
5157 pframe += (ie_len+2);
5158 pattrib->pktlen += (ie_len+2);
5162 if (!pbuf || ie_len == 0)
5167 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5168 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6, REALTEK_96B_IE, &(pattrib->pktlen));
5170 /* add WPS IE ie for wps 2.0 */
5171 if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) {
5172 memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
5174 pframe += pmlmepriv->wps_assoc_resp_ie_len;
5175 pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
5178 #ifdef CONFIG_88EU_P2P
5179 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && (pstat->is_p2p_device)) {
5182 len = build_assoc_resp_p2p_ie(pwdinfo, pframe, pstat->p2p_status_code);
5185 pattrib->pktlen += len;
5187 #endif /* CONFIG_88EU_P2P */
5188 pattrib->last_txcmdsz = pattrib->pktlen;
5189 dump_mgntframe(padapter, pmgntframe);
5193 void issue_assocreq(struct adapter *padapter)
5196 struct xmit_frame *pmgntframe;
5197 struct pkt_attrib *pattrib;
5198 unsigned char *pframe, *p;
5199 struct rtw_ieee80211_hdr *pwlanhdr;
5202 unsigned int i, j, ie_len, index = 0;
5203 unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
5204 struct ndis_802_11_var_ie *pIE;
5205 struct registry_priv *pregpriv = &padapter->registrypriv;
5206 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5207 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5208 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5209 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5210 int bssrate_len = 0, sta_bssrate_len = 0;
5211 #ifdef CONFIG_88EU_P2P
5212 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5213 u8 p2pie[255] = { 0x00 };
5215 #endif /* CONFIG_88EU_P2P */
5217 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5221 /* update attribute */
5222 pattrib = &pmgntframe->attrib;
5223 update_mgntframe_attrib(padapter, pattrib);
5225 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5226 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5227 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5229 fctrl = &(pwlanhdr->frame_ctl);
5231 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5232 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5233 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5235 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5236 pmlmeext->mgnt_seq++;
5237 SetFrameSubType(pframe, WIFI_ASSOCREQ);
5239 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5240 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5244 memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
5247 pattrib->pktlen += 2;
5249 /* listen interval */
5250 /* todo: listen interval for power saving */
5251 le_tmp = cpu_to_le16(3);
5252 memcpy(pframe, (unsigned char *)&le_tmp, 2);
5254 pattrib->pktlen += 2;
5257 pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
5259 /* supported rate & extended supported rate */
5261 /* Check if the AP's supported rates are also supported by STA. */
5262 get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
5264 if (pmlmeext->cur_channel == 14)/* for JAPAN, channel 14 can only uses B Mode(CCK) */
5265 sta_bssrate_len = 4;
5267 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5268 if (pmlmeinfo->network.SupportedRates[i] == 0)
5270 DBG_88E("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
5273 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5274 if (pmlmeinfo->network.SupportedRates[i] == 0)
5277 /* Check if the AP's supported rates are also supported by STA. */
5278 for (j = 0; j < sta_bssrate_len; j++) {
5279 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
5280 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
5281 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK))
5285 if (j == sta_bssrate_len) {
5286 /* the rate is not supported by STA */
5287 DBG_88E("%s(): the rate[%d]=%02X is not supported by STA!\n", __func__, i, pmlmeinfo->network.SupportedRates[i]);
5289 /* the rate is supported by STA */
5290 bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
5294 bssrate_len = index;
5295 DBG_88E("bssrate_len=%d\n", bssrate_len);
5297 if (bssrate_len == 0) {
5298 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
5299 rtw_free_xmitframe(pxmitpriv, pmgntframe);
5300 goto exit; /* don't connect to AP if no joint supported rate */
5303 if (bssrate_len > 8) {
5304 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, bssrate, &(pattrib->pktlen));
5305 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
5307 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, bssrate_len, bssrate, &(pattrib->pktlen));
5311 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)));
5313 pframe = rtw_set_ie(pframe, _RSN_IE_2_, ie_len, (p + 2), &(pattrib->pktlen));
5316 if (padapter->mlmepriv.htpriv.ht_option) {
5317 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)));
5318 if (p && !is_ap_in_tkip(padapter)) {
5319 memcpy(&(pmlmeinfo->HT_caps), (p + 2), sizeof(struct HT_caps_element));
5321 /* to disable 40M Hz support while gd_bw_40MHz_en = 0 */
5322 if (pregpriv->cbw40_enable == 0)
5323 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info &= cpu_to_le16(~(BIT(6) | BIT(1)));
5325 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(BIT(1));
5327 /* todo: disable SM power save mode */
5328 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x000c);
5330 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
5333 if (pregpriv->rx_stbc)
5334 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0100);/* RX STBC One spatial stream */
5335 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_1R, 16);
5340 if ((pregpriv->rx_stbc == 0x3) ||/* enable for 2.4/5 GHz */
5341 ((pmlmeext->cur_wireless_mode & WIRELESS_11_24N) && (pregpriv->rx_stbc == 0x1)) || /* enable for 2.4GHz */
5342 (pregpriv->wifi_spec == 1)) {
5343 DBG_88E("declare supporting RX STBC\n");
5344 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0200);/* RX STBC two spatial stream */
5346 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_2R, 16);
5349 pframe = rtw_set_ie(pframe, _HT_CAPABILITY_IE_, ie_len, (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
5353 /* vendor specific IE, such as WPA, WMM, WPS */
5354 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
5355 pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
5357 switch (pIE->ElementID) {
5358 case _VENDOR_SPECIFIC_IE_:
5359 if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
5360 (!memcmp(pIE->data, WMM_OUI, 4)) ||
5361 (!memcmp(pIE->data, WPS_OUI, 4))) {
5362 if (!padapter->registrypriv.wifi_spec) {
5363 /* Commented by Kurt 20110629 */
5364 /* In some older APs, WPS handshake */
5365 /* would be fail if we append vender extensions informations to AP */
5366 if (!memcmp(pIE->data, WPS_OUI, 4))
5369 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, pIE->Length, pIE->data, &(pattrib->pktlen));
5375 i += (pIE->Length + 2);
5378 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5379 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6, REALTEK_96B_IE, &(pattrib->pktlen));
5381 #ifdef CONFIG_88EU_P2P
5383 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
5384 /* Should add the P2P IE in the association request frame. */
5388 p2pie[p2pielen++] = 0x50;
5389 p2pie[p2pielen++] = 0x6F;
5390 p2pie[p2pielen++] = 0x9A;
5391 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
5393 /* Commented by Albert 20101109 */
5394 /* According to the P2P Specification, the association request frame should contain 3 P2P attributes */
5395 /* 1. P2P Capability */
5396 /* 2. Extended Listen Timing */
5397 /* 3. Device Info */
5398 /* Commented by Albert 20110516 */
5399 /* 4. P2P Interface */
5401 /* P2P Capability */
5403 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
5406 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
5410 /* Device Capability Bitmap, 1 byte */
5411 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
5413 /* Group Capability Bitmap, 1 byte */
5414 if (pwdinfo->persistent_supported)
5415 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
5417 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
5419 /* Extended Listen Timing */
5421 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
5424 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
5428 /* Availability Period */
5429 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5432 /* Availability Interval */
5433 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5438 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
5441 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
5442 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
5443 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
5447 /* P2P Device Address */
5448 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
5449 p2pielen += ETH_ALEN;
5452 /* This field should be big endian. Noted by P2P specification. */
5453 if ((pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN) ||
5454 (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN))
5455 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
5457 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_PBC);
5461 /* Primary Device Type */
5463 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
5467 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
5470 /* Sub Category ID */
5471 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
5474 /* Number of Secondary Device Types */
5475 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
5479 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
5483 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
5487 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
5488 p2pielen += pwdinfo->device_name_len;
5492 p2pie[p2pielen++] = P2P_ATTR_INTERFACE;
5495 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x000D);
5499 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Device Address */
5500 p2pielen += ETH_ALEN;
5502 p2pie[p2pielen++] = 1; /* P2P Interface Address Count */
5504 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Interface Address List */
5505 p2pielen += ETH_ALEN;
5507 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
5510 #endif /* CONFIG_88EU_P2P */
5512 pattrib->last_txcmdsz = pattrib->pktlen;
5513 dump_mgntframe(padapter, pmgntframe);
5518 if (ret == _SUCCESS)
5519 rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
5521 kfree(pmlmepriv->assoc_req);
5524 /* when wait_ack is ture, this function shoule be called at process context */
5525 static int _issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
5528 struct xmit_frame *pmgntframe;
5529 struct pkt_attrib *pattrib;
5530 unsigned char *pframe;
5531 struct rtw_ieee80211_hdr *pwlanhdr;
5533 struct xmit_priv *pxmitpriv;
5534 struct mlme_ext_priv *pmlmeext;
5535 struct mlme_ext_info *pmlmeinfo;
5540 pxmitpriv = &(padapter->xmitpriv);
5541 pmlmeext = &(padapter->mlmeextpriv);
5542 pmlmeinfo = &(pmlmeext->mlmext_info);
5544 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5548 /* update attribute */
5549 pattrib = &pmgntframe->attrib;
5550 update_mgntframe_attrib(padapter, pattrib);
5551 pattrib->retry_ctrl = false;
5553 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5555 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5556 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5558 fctrl = &(pwlanhdr->frame_ctl);
5561 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5563 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5569 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5570 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5571 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5573 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5574 pmlmeext->mgnt_seq++;
5575 SetFrameSubType(pframe, WIFI_DATA_NULL);
5577 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5578 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5580 pattrib->last_txcmdsz = pattrib->pktlen;
5583 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5585 dump_mgntframe(padapter, pmgntframe);
5593 /* when wait_ms > 0 , this function shoule be called at process context */
5594 /* da == NULL for station mode */
5595 int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
5599 u32 start = jiffies;
5600 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5601 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5603 /* da == NULL, assum it's null data for sta to ap*/
5605 da = get_my_bssid(&(pmlmeinfo->network));
5608 ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0 ? true : false);
5612 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5615 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5617 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5624 if (try_cnt && wait_ms) {
5626 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5627 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5628 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5630 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5631 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5632 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5638 /* when wait_ack is ture, this function shoule be called at process context */
5639 static int _issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
5642 struct xmit_frame *pmgntframe;
5643 struct pkt_attrib *pattrib;
5644 unsigned char *pframe;
5645 struct rtw_ieee80211_hdr *pwlanhdr;
5648 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5649 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5650 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5652 DBG_88E("%s\n", __func__);
5654 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5658 /* update attribute */
5659 pattrib = &pmgntframe->attrib;
5660 update_mgntframe_attrib(padapter, pattrib);
5662 pattrib->hdrlen += 2;
5663 pattrib->qos_en = true;
5665 pattrib->ack_policy = 0;
5668 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5670 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5671 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5673 fctrl = &(pwlanhdr->frame_ctl);
5676 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5678 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5684 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
5686 SetPriority(qc, tid);
5688 SetEOSP(qc, pattrib->eosp);
5690 SetAckpolicy(qc, pattrib->ack_policy);
5692 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5693 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5694 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5696 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5697 pmlmeext->mgnt_seq++;
5698 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
5700 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5701 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5703 pattrib->last_txcmdsz = pattrib->pktlen;
5706 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5708 dump_mgntframe(padapter, pmgntframe);
5716 /* when wait_ms > 0 , this function shoule be called at process context */
5717 /* da == NULL for station mode */
5718 int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
5722 u32 start = jiffies;
5723 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5724 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5726 /* da == NULL, assum it's null data for sta to ap*/
5728 da = get_my_bssid(&(pmlmeinfo->network));
5731 ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0 ? true : false);
5735 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5738 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5740 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5747 if (try_cnt && wait_ms) {
5749 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5750 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5751 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5753 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5754 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5755 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5761 static int _issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack)
5763 struct xmit_frame *pmgntframe;
5764 struct pkt_attrib *pattrib;
5765 unsigned char *pframe;
5766 struct rtw_ieee80211_hdr *pwlanhdr;
5768 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5769 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5770 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5773 #ifdef CONFIG_88EU_P2P
5774 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5775 #endif /* CONFIG_88EU_P2P */
5777 #ifdef CONFIG_88EU_P2P
5778 if (!(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) && (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
5779 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
5780 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
5782 #endif /* CONFIG_88EU_P2P */
5784 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5788 /* update attribute */
5789 pattrib = &pmgntframe->attrib;
5790 update_mgntframe_attrib(padapter, pattrib);
5791 pattrib->retry_ctrl = false;
5793 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5795 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5796 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5798 fctrl = &(pwlanhdr->frame_ctl);
5801 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5802 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5803 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5805 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5806 pmlmeext->mgnt_seq++;
5807 SetFrameSubType(pframe, WIFI_DEAUTH);
5809 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5810 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5812 le_tmp = cpu_to_le16(reason);
5813 pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_, (unsigned char *)&le_tmp, &(pattrib->pktlen));
5815 pattrib->last_txcmdsz = pattrib->pktlen;
5818 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5820 dump_mgntframe(padapter, pmgntframe);
5828 int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason)
5830 DBG_88E("%s to %pM\n", __func__, da);
5831 return _issue_deauth(padapter, da, reason, false);
5834 int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
5839 u32 start = jiffies;
5842 ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? true : false);
5846 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5849 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5851 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5858 if (try_cnt && wait_ms) {
5860 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5861 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5862 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5864 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5865 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5866 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5872 void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
5874 struct xmit_frame *pmgntframe;
5875 struct pkt_attrib *pattrib;
5876 unsigned char *pframe;
5877 struct rtw_ieee80211_hdr *pwlanhdr;
5879 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5880 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5882 DBG_88E(FUNC_NDEV_FMT" ra =%pM, ch:%u, offset:%u\n",
5883 FUNC_NDEV_ARG(padapter->pnetdev), ra, new_ch, ch_offset);
5885 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5889 /* update attribute */
5890 pattrib = &pmgntframe->attrib;
5891 update_mgntframe_attrib(padapter, pattrib);
5893 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5895 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5896 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5898 fctrl = &(pwlanhdr->frame_ctl);
5901 memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
5902 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); /* TA */
5903 memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
5905 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5906 pmlmeext->mgnt_seq++;
5907 SetFrameSubType(pframe, WIFI_ACTION);
5909 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5910 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5912 /* category, action */
5914 u8 category, action;
5915 category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
5916 action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
5918 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
5919 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
5922 pframe = rtw_set_ie_ch_switch (pframe, &(pattrib->pktlen), 0, new_ch, 0);
5923 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
5924 hal_ch_offset_to_secondary_ch_offset(ch_offset));
5926 pattrib->last_txcmdsz = pattrib->pktlen;
5928 dump_mgntframe(padapter, pmgntframe);
5931 void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status)
5933 u8 category = RTW_WLAN_CATEGORY_BACK;
5937 u16 BA_timeout_value;
5939 u16 BA_starting_seqctrl = 0;
5940 enum ht_cap_ampdu_factor max_rx_ampdu_factor;
5941 struct xmit_frame *pmgntframe;
5942 struct pkt_attrib *pattrib;
5944 struct rtw_ieee80211_hdr *pwlanhdr;
5946 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5947 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5948 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5949 struct sta_info *psta;
5950 struct sta_priv *pstapriv = &padapter->stapriv;
5951 struct registry_priv *pregpriv = &padapter->registrypriv;
5953 DBG_88E("%s, category=%d, action=%d, status=%d\n", __func__, category, action, status);
5955 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5959 /* update attribute */
5960 pattrib = &pmgntframe->attrib;
5961 update_mgntframe_attrib(padapter, pattrib);
5963 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5965 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5966 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5968 fctrl = &(pwlanhdr->frame_ctl);
5971 /* memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */
5972 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
5973 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5974 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5976 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5977 pmlmeext->mgnt_seq++;
5978 SetFrameSubType(pframe, WIFI_ACTION);
5980 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5981 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5983 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
5984 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
5986 if (category == 3) {
5988 case 0: /* ADDBA req */
5990 pmlmeinfo->dialogToken++;
5991 } while (pmlmeinfo->dialogToken == 0);
5992 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
5994 BA_para_set = (0x1002 | ((status & 0xf) << 2)); /* immediate ack & 64 buffer size */
5995 le_tmp = cpu_to_le16(BA_para_set);
5996 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
5998 BA_timeout_value = 5000;/* 5ms */
5999 le_tmp = cpu_to_le16(BA_timeout_value);
6000 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6002 psta = rtw_get_stainfo(pstapriv, raddr);
6004 start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07]&0xfff) + 1;
6006 DBG_88E("BA_starting_seqctrl=%d for TID=%d\n", start_seq, status & 0x07);
6008 psta->BA_starting_seqctrl[status & 0x07] = start_seq;
6010 BA_starting_seqctrl = start_seq << 4;
6012 le_tmp = cpu_to_le16(BA_starting_seqctrl);
6013 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6015 case 1: /* ADDBA rsp */
6016 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
6017 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
6018 BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f;
6019 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
6020 switch (max_rx_ampdu_factor) {
6021 case MAX_AMPDU_FACTOR_64K:
6022 BA_para_set |= 0x1000; /* 64 buffer size */
6024 case MAX_AMPDU_FACTOR_32K:
6025 BA_para_set |= 0x0800; /* 32 buffer size */
6027 case MAX_AMPDU_FACTOR_16K:
6028 BA_para_set |= 0x0400; /* 16 buffer size */
6030 case MAX_AMPDU_FACTOR_8K:
6031 BA_para_set |= 0x0200; /* 8 buffer size */
6034 BA_para_set |= 0x1000; /* 64 buffer size */
6038 if (pregpriv->ampdu_amsdu == 0)/* disabled */
6039 BA_para_set = BA_para_set & ~BIT(0);
6040 else if (pregpriv->ampdu_amsdu == 1)/* enabled */
6041 BA_para_set = BA_para_set | BIT(0);
6042 le_tmp = cpu_to_le16(BA_para_set);
6044 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6045 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
6048 BA_para_set = (status & 0x1F) << 3;
6049 le_tmp = cpu_to_le16(BA_para_set);
6050 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6052 reason_code = 37;/* Requested from peer STA as it does not want to use the mechanism */
6053 le_tmp = cpu_to_le16(reason_code);
6054 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6061 pattrib->last_txcmdsz = pattrib->pktlen;
6063 dump_mgntframe(padapter, pmgntframe);
6066 static void issue_action_BSSCoexistPacket(struct adapter *padapter)
6068 struct list_head *plist, *phead;
6069 unsigned char category, action;
6070 struct xmit_frame *pmgntframe;
6071 struct pkt_attrib *pattrib;
6072 unsigned char *pframe;
6073 struct rtw_ieee80211_hdr *pwlanhdr;
6075 struct wlan_network *pnetwork = NULL;
6076 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6077 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6078 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6079 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6080 struct __queue *queue = &(pmlmepriv->scanned_queue);
6081 u8 InfoContent[16] = {0};
6083 if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
6086 if (pmlmeinfo->bwmode_updated)
6089 DBG_88E("%s\n", __func__);
6091 category = RTW_WLAN_CATEGORY_PUBLIC;
6092 action = ACT_PUBLIC_BSSCOEXIST;
6094 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
6098 /* update attribute */
6099 pattrib = &pmgntframe->attrib;
6100 update_mgntframe_attrib(padapter, pattrib);
6102 memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6104 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6105 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6107 fctrl = &(pwlanhdr->frame_ctl);
6110 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6111 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6112 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6114 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
6115 pmlmeext->mgnt_seq++;
6116 SetFrameSubType(pframe, WIFI_ACTION);
6118 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6119 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6121 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6122 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6125 if (pmlmepriv->num_FortyMHzIntolerant > 0) {
6128 iedata |= BIT(2);/* 20 MHz BSS Width Request */
6130 pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
6134 memset(ICS, 0, sizeof(ICS));
6135 if (pmlmepriv->num_sta_no_ht > 0) {
6138 spin_lock_bh(&pmlmepriv->scanned_queue.lock);
6140 phead = get_list_head(queue);
6141 plist = phead->next;
6143 while (phead != plist) {
6146 struct wlan_bssid_ex *pbss_network;
6148 pnetwork = container_of(plist, struct wlan_network, list);
6150 plist = plist->next;
6152 pbss_network = (struct wlan_bssid_ex *)&pnetwork->network;
6154 p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
6155 if (!p || len == 0) { /* non-HT */
6156 if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14))
6159 ICS[0][pbss_network->Configuration.DSConfig] = 1;
6165 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
6167 for (i = 0; i < 8; i++) {
6168 if (ICS[i][0] == 1) {
6172 /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */
6175 for (j = 1; j <= 14; j++) {
6176 if (ICS[i][j] == 1) {
6178 InfoContent[k] = j; /* channel number */
6179 /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
6185 pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
6190 pattrib->last_txcmdsz = pattrib->pktlen;
6192 dump_mgntframe(padapter, pmgntframe);
6195 unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr)
6197 struct sta_priv *pstapriv = &padapter->stapriv;
6198 struct sta_info *psta = NULL;
6199 /* struct recv_reorder_ctrl *preorder_ctrl; */
6200 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6201 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6204 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
6205 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
6208 psta = rtw_get_stainfo(pstapriv, addr);
6212 if (initiator == 0) { /* recipient */
6213 for (tid = 0; tid < MAXTID; tid++) {
6214 if (psta->recvreorder_ctrl[tid].enable) {
6215 DBG_88E("rx agg disable tid(%d)\n", tid);
6216 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6217 psta->recvreorder_ctrl[tid].enable = false;
6218 psta->recvreorder_ctrl[tid].indicate_seq = 0xffff;
6221 } else if (initiator == 1) { /* originator */
6222 for (tid = 0; tid < MAXTID; tid++) {
6223 if (psta->htpriv.agg_enable_bitmap & BIT(tid)) {
6224 DBG_88E("tx agg disable tid(%d)\n", tid);
6225 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6226 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
6227 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
6235 unsigned int send_beacon(struct adapter *padapter)
6241 u32 start = jiffies;
6243 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
6245 issue_beacon(padapter, 100);
6249 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
6251 } while ((poll%10) != 0 && !bxmitok && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6252 } while (!bxmitok && issue < 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6254 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
6257 DBG_88E("%s fail! %u ms\n", __func__, rtw_get_passing_time_ms(start));
6260 u32 passing_time = rtw_get_passing_time_ms(start);
6262 if (passing_time > 100 || issue > 3)
6263 DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", __func__, issue, poll, rtw_get_passing_time_ms(start));
6268 /****************************************************************************
6270 Following are some utitity fuctions for WiFi MLME
6272 *****************************************************************************/
6274 void site_survey(struct adapter *padapter)
6276 unsigned char survey_channel = 0, val8;
6277 enum rt_scan_type ScanType = SCAN_PASSIVE;
6278 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6279 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6280 u32 initialgain = 0;
6282 #ifdef CONFIG_88EU_P2P
6283 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
6285 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6286 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
6287 survey_channel = pwdinfo->rx_invitereq_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6289 survey_channel = pwdinfo->p2p_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6291 ScanType = SCAN_ACTIVE;
6292 } else if (rtw_p2p_findphase_ex_is_social(pwdinfo)) {
6293 /* Commented by Albert 2011/06/03 */
6294 /* The driver is in the find phase, it should go through the social channel. */
6296 survey_channel = pwdinfo->social_chan[pmlmeext->sitesurvey_res.channel_idx];
6297 ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, survey_channel);
6298 if (ch_set_idx >= 0)
6299 ScanType = pmlmeext->channel_set[ch_set_idx].ScanType;
6301 ScanType = SCAN_ACTIVE;
6303 #endif /* CONFIG_88EU_P2P */
6305 struct rtw_ieee80211_channel *ch;
6306 if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) {
6307 ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx];
6308 survey_channel = ch->hw_value;
6309 ScanType = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
6313 if (survey_channel != 0) {
6314 /* PAUSE 4-AC Queue when site_survey */
6315 /* rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6317 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6318 if (pmlmeext->sitesurvey_res.channel_idx == 0)
6319 set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6321 SelectChannel(padapter, survey_channel);
6323 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */
6324 #ifdef CONFIG_88EU_P2P
6325 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) ||
6326 rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6327 issue_probereq_p2p(padapter, NULL);
6328 issue_probereq_p2p(padapter, NULL);
6329 issue_probereq_p2p(padapter, NULL);
6331 #endif /* CONFIG_88EU_P2P */
6334 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
6335 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
6336 /* todo: to issue two probe req??? */
6337 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6338 /* msleep(SURVEY_TO>>1); */
6339 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6343 if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
6344 /* todo: to issue two probe req??? */
6345 issue_probereq(padapter, NULL, NULL);
6346 /* msleep(SURVEY_TO>>1); */
6347 issue_probereq(padapter, NULL, NULL);
6352 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6354 /* channel number is 0 or this channel is not valid. */
6356 #ifdef CONFIG_88EU_P2P
6357 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6358 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6359 /* Set the find_phase_state_exchange_cnt to P2P_FINDPHASE_EX_CNT. */
6360 /* This will let the following flow to run the scanning end. */
6361 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
6365 if (rtw_p2p_findphase_ex_is_needed(pwdinfo)) {
6366 /* Set the P2P State to the listen state of find phase and set the current channel to the listen channel */
6367 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6368 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_LISTEN);
6369 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6371 initialgain = 0xff; /* restore RX GAIN */
6372 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6373 /* turn on dynamic functions */
6374 Restore_DM_Func_Flag(padapter);
6375 /* Switch_DM_Func(padapter, DYNAMIC_FUNC_DIG|DYNAMIC_FUNC_HP|DYNAMIC_FUNC_SS, true); */
6377 _set_timer(&pwdinfo->find_phase_timer, (u32)((u32)(pwdinfo->listen_dwell) * 100));
6379 #endif /* CONFIG_88EU_P2P */
6381 /* 20100721:Interrupt scan operation here. */
6382 /* For SW antenna diversity before link, it needs to switch to another antenna and scan again. */
6383 /* It compares the scan result and select beter one to do connection. */
6384 if (rtw_hal_antdiv_before_linked(padapter)) {
6385 pmlmeext->sitesurvey_res.bss_cnt = 0;
6386 pmlmeext->sitesurvey_res.channel_idx = -1;
6387 pmlmeext->chan_scan_time = SURVEY_TO / 2;
6388 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6391 #ifdef CONFIG_88EU_P2P
6392 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
6393 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
6394 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
6395 #endif /* CONFIG_88EU_P2P */
6397 pmlmeext->sitesurvey_res.state = SCAN_COMPLETE;
6399 /* switch back to the original channel */
6401 #ifdef CONFIG_88EU_P2P
6402 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN))
6403 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6405 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6406 #endif /* CONFIG_88EU_P2P */
6408 /* flush 4-AC Queue after site_survey */
6410 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6413 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6415 initialgain = 0xff; /* restore RX GAIN */
6416 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6417 /* turn on dynamic functions */
6418 Restore_DM_Func_Flag(padapter);
6419 /* Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); */
6421 if (is_client_associated_to_ap(padapter))
6422 issue_nulldata(padapter, NULL, 0, 3, 500);
6424 val8 = 0; /* survey done */
6425 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
6427 report_surveydone_event(padapter);
6429 pmlmeext->chan_scan_time = SURVEY_TO;
6430 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6432 issue_action_BSSCoexistPacket(padapter);
6433 issue_action_BSSCoexistPacket(padapter);
6434 issue_action_BSSCoexistPacket(padapter);
6439 /* collect bss info from Beacon and Probe request/response frames. */
6440 u8 collect_bss_info(struct adapter *padapter, struct recv_frame *precv_frame, struct wlan_bssid_ex *bssid)
6446 u8 *pframe = precv_frame->rx_data;
6447 u32 packet_len = precv_frame->len;
6449 struct registry_priv *pregistrypriv = &padapter->registrypriv;
6450 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6451 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6454 len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
6456 if (len > MAX_IE_SZ)
6459 memset(bssid, 0, sizeof(struct wlan_bssid_ex));
6461 subtype = GetFrameSubType(pframe);
6463 if (subtype == WIFI_BEACON) {
6464 bssid->Reserved[0] = 1;
6465 ie_offset = _BEACON_IE_OFFSET_;
6467 /* FIXME : more type */
6468 if (subtype == WIFI_PROBEREQ) {
6469 ie_offset = _PROBEREQ_IE_OFFSET_;
6470 bssid->Reserved[0] = 2;
6471 } else if (subtype == WIFI_PROBERSP) {
6472 ie_offset = _PROBERSP_IE_OFFSET_;
6473 bssid->Reserved[0] = 3;
6475 bssid->Reserved[0] = 0;
6476 ie_offset = _FIXED_IE_LENGTH_;
6480 bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
6482 /* below is to copy the information element */
6483 bssid->IELength = len;
6484 memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
6486 /* get the signal strength */
6487 bssid->Rssi = precv_frame->attrib.phy_info.recvpower; /* in dBM.raw data */
6488 bssid->PhyInfo.SignalQuality = precv_frame->attrib.phy_info.SignalQuality;/* in percentage */
6489 bssid->PhyInfo.SignalStrength = precv_frame->attrib.phy_info.SignalStrength;/* in percentage */
6490 rtw_hal_get_def_var(padapter, HAL_DEF_CURRENT_ANTENNA, &bssid->PhyInfo.Optimum_antenna);
6493 p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset);
6495 DBG_88E("marc: cannot find SSID for survey event\n");
6500 if (len > NDIS_802_11_LENGTH_SSID) {
6501 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6504 memcpy(bssid->Ssid.Ssid, (p + 2), *(p + 1));
6505 bssid->Ssid.SsidLength = *(p + 1);
6507 bssid->Ssid.SsidLength = 0;
6510 memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
6512 /* checking rate info... */
6514 p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6516 if (len > NDIS_802_11_LENGTH_RATES_EX) {
6517 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6520 memcpy(bssid->SupportedRates, (p + 2), len);
6524 p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6526 if (len > (NDIS_802_11_LENGTH_RATES_EX-i)) {
6527 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6530 memcpy(bssid->SupportedRates + i, (p + 2), len);
6534 bssid->NetworkTypeInUse = Ndis802_11OFDM24;
6536 if (bssid->IELength < 12)
6539 /* Checking for DSConfig */
6540 p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
6542 bssid->Configuration.DSConfig = 0;
6543 bssid->Configuration.Length = 0;
6546 bssid->Configuration.DSConfig = *(p + 2);
6547 } else {/* In 5G, some ap do not have DSSET IE */
6548 /* checking HT info for channel */
6549 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
6551 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
6552 bssid->Configuration.DSConfig = HT_info->primary_channel;
6553 } else { /* use current channel */
6554 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
6558 memcpy(&le32_tmp, rtw_get_beacon_interval_from_ie(bssid->IEs), 2);
6559 bssid->Configuration.BeaconPeriod = le32_to_cpu(le32_tmp);
6561 val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
6563 if (val16 & BIT(0)) {
6564 bssid->InfrastructureMode = Ndis802_11Infrastructure;
6565 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
6567 bssid->InfrastructureMode = Ndis802_11IBSS;
6568 memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
6576 bssid->Configuration.ATIMWindow = 0;
6578 /* 20/40 BSS Coexistence check */
6579 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) {
6580 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6581 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
6583 struct HT_caps_element *pHT_caps;
6584 pHT_caps = (struct HT_caps_element *)(p + 2);
6586 if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info)&BIT(14))
6587 pmlmepriv->num_FortyMHzIntolerant++;
6589 pmlmepriv->num_sta_no_ht++;
6593 /* mark bss info receiving from nearby channel as SignalQuality 101 */
6594 if (bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
6595 bssid->PhyInfo.SignalQuality = 101;
6599 void start_create_ibss(struct adapter *padapter)
6601 unsigned short caps;
6604 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6605 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6606 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6607 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6608 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6610 /* update wireless mode */
6611 update_wireless_mode(padapter);
6613 /* udpate capability */
6614 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6615 update_capinfo(padapter, caps);
6616 if (caps&cap_IBSS) {/* adhoc master */
6618 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6620 /* switch channel */
6621 /* SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE); */
6622 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6624 beacon_timing_control(padapter);
6626 /* set msr to WIFI_FW_ADHOC_STATE */
6627 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6628 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6631 if (send_beacon(padapter) == _FAIL) {
6632 report_join_res(padapter, -1);
6633 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6635 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
6637 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
6639 report_join_res(padapter, 1);
6640 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
6641 rtw_indicate_connect(padapter);
6644 DBG_88E("start_create_ibss, invalid cap:%x\n", caps);
6647 /* update bc/mc sta_info */
6648 update_bmc_sta(padapter);
6651 void start_clnt_join(struct adapter *padapter)
6653 unsigned short caps;
6655 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6656 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6657 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6660 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6661 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6663 /* update wireless mode */
6664 update_wireless_mode(padapter);
6666 /* udpate capability */
6667 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6668 update_capinfo(padapter, caps);
6670 Set_MSR(padapter, WIFI_FW_STATION_STATE);
6672 val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
6674 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6676 /* switch channel */
6677 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6679 /* here wait for receiving the beacon to start auth */
6680 /* and enable a timer */
6681 beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
6682 set_link_timer(pmlmeext, beacon_timeout);
6683 _set_timer(&padapter->mlmepriv.assoc_timer,
6684 (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO*REASSOC_LIMIT) + beacon_timeout);
6686 pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
6687 } else if (caps&cap_IBSS) { /* adhoc client */
6688 Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
6691 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6693 /* switch channel */
6694 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6696 beacon_timing_control(padapter);
6698 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6700 report_join_res(padapter, 1);
6706 void start_clnt_auth(struct adapter *padapter)
6708 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6709 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6711 _cancel_timer_ex(&pmlmeext->link_timer);
6713 pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
6714 pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
6716 pmlmeinfo->auth_seq = 1;
6717 pmlmeinfo->reauth_count = 0;
6718 pmlmeinfo->reassoc_count = 0;
6719 pmlmeinfo->link_count = 0;
6720 pmlmeext->retry = 0;
6722 /* Because of AP's not receiving deauth before */
6723 /* AP may: 1)not response auth or 2)deauth us after link is complete */
6724 /* issue deauth before issuing auth to deal with the situation */
6725 /* Commented by Albert 2012/07/21 */
6726 /* For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. */
6727 issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
6729 DBG_88E_LEVEL(_drv_info_, "start auth\n");
6730 issue_auth(padapter, NULL, 0);
6732 set_link_timer(pmlmeext, REAUTH_TO);
6735 void start_clnt_assoc(struct adapter *padapter)
6737 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6738 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6740 _cancel_timer_ex(&pmlmeext->link_timer);
6742 pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
6743 pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
6745 issue_assocreq(padapter);
6747 set_link_timer(pmlmeext, REASSOC_TO);
6750 unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
6752 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6753 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6756 if (!(!memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN)))
6759 DBG_88E("%s\n", __func__);
6761 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
6762 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
6763 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6764 report_del_sta_event(padapter, MacAddr, reason);
6765 } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
6766 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6767 report_join_res(padapter, -2);
6773 static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid)
6775 struct registry_priv *pregistrypriv;
6776 struct mlme_ext_priv *pmlmeext;
6777 struct rt_channel_info *chplan_new;
6781 pregistrypriv = &padapter->registrypriv;
6782 pmlmeext = &padapter->mlmeextpriv;
6784 /* Adjust channel plan by AP Country IE */
6785 if (pregistrypriv->enable80211d &&
6786 (!pmlmeext->update_channel_plan_by_ap_done)) {
6789 struct rt_channel_plan chplan_ap;
6790 struct rt_channel_info chplan_sta[MAX_CHANNEL_NUM];
6792 u8 fcn; /* first channel number */
6793 u8 noc; /* number of channel */
6796 ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
6805 memset(country, 0, 4);
6806 memcpy(country, p, 3);
6810 while ((ie - p) >= 3) {
6815 for (j = 0; j < noc; j++) {
6817 channel = fcn + j; /* 2.4 GHz */
6819 channel = fcn + j*4; /* 5 GHz */
6821 chplan_ap.Channel[i++] = channel;
6826 memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
6828 memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
6829 chplan_new = pmlmeext->channel_set;
6834 if (pregistrypriv->wireless_mode & WIRELESS_11G) {
6836 if ((i == MAX_CHANNEL_NUM) ||
6837 (chplan_sta[i].ChannelNum == 0) ||
6838 (chplan_sta[i].ChannelNum > 14))
6841 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
6844 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
6845 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6846 chplan_new[k].ScanType = SCAN_ACTIVE;
6850 } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
6851 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6852 chplan_new[k].ScanType = SCAN_PASSIVE;
6855 } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
6856 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6857 chplan_new[k].ScanType = SCAN_ACTIVE;
6863 /* change AP not support channel to Passive scan */
6864 while ((i < MAX_CHANNEL_NUM) &&
6865 (chplan_sta[i].ChannelNum != 0) &&
6866 (chplan_sta[i].ChannelNum <= 14)) {
6867 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6868 chplan_new[k].ScanType = SCAN_PASSIVE;
6873 /* add channel AP supported */
6874 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) {
6875 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6876 chplan_new[k].ScanType = SCAN_ACTIVE;
6881 /* keep original STA 2.4G channel plan */
6882 while ((i < MAX_CHANNEL_NUM) &&
6883 (chplan_sta[i].ChannelNum != 0) &&
6884 (chplan_sta[i].ChannelNum <= 14)) {
6885 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6886 chplan_new[k].ScanType = chplan_sta[i].ScanType;
6891 /* skip AP 2.4G channel plan */
6892 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
6896 /* keep original STA 5G channel plan */
6897 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
6898 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6899 chplan_new[k].ScanType = chplan_sta[i].ScanType;
6904 pmlmeext->update_channel_plan_by_ap_done = 1;
6907 /* If channel is used by AP, set channel scan type to active */
6908 channel = bssid->Configuration.DSConfig;
6909 chplan_new = pmlmeext->channel_set;
6911 while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].ChannelNum != 0)) {
6912 if (chplan_new[i].ChannelNum == channel) {
6913 if (chplan_new[i].ScanType == SCAN_PASSIVE)
6914 chplan_new[i].ScanType = SCAN_ACTIVE;
6921 /****************************************************************************
6923 Following are the functions to report events
6925 *****************************************************************************/
6927 void report_survey_event(struct adapter *padapter, struct recv_frame *precv_frame)
6929 struct cmd_obj *pcmd_obj;
6932 struct survey_event *psurvey_evt;
6933 struct C2HEvent_Header *pc2h_evt_hdr;
6934 struct mlme_ext_priv *pmlmeext;
6935 struct cmd_priv *pcmdpriv;
6936 /* u8 *pframe = precv_frame->rx_data; */
6937 /* uint len = precv_frame->len; */
6942 pmlmeext = &padapter->mlmeextpriv;
6943 pcmdpriv = &padapter->cmdpriv;
6945 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
6949 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
6950 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
6956 INIT_LIST_HEAD(&pcmd_obj->list);
6958 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
6959 pcmd_obj->cmdsz = cmdsz;
6960 pcmd_obj->parmbuf = pevtcmd;
6962 pcmd_obj->rsp = NULL;
6963 pcmd_obj->rspsz = 0;
6965 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
6966 pc2h_evt_hdr->len = sizeof(struct survey_event);
6967 pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
6968 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
6970 psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
6972 if (collect_bss_info(padapter, precv_frame, (struct wlan_bssid_ex *)&psurvey_evt->bss) == _FAIL) {
6978 process_80211d(padapter, &psurvey_evt->bss);
6980 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
6982 pmlmeext->sitesurvey_res.bss_cnt++;
6985 void report_surveydone_event(struct adapter *padapter)
6987 struct cmd_obj *pcmd_obj;
6990 struct surveydone_event *psurveydone_evt;
6991 struct C2HEvent_Header *pc2h_evt_hdr;
6992 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6993 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
6995 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
6999 cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
7000 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7006 INIT_LIST_HEAD(&pcmd_obj->list);
7008 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7009 pcmd_obj->cmdsz = cmdsz;
7010 pcmd_obj->parmbuf = pevtcmd;
7012 pcmd_obj->rsp = NULL;
7013 pcmd_obj->rspsz = 0;
7015 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7016 pc2h_evt_hdr->len = sizeof(struct surveydone_event);
7017 pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
7018 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7020 psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7021 psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
7023 DBG_88E("survey done event(%x)\n", psurveydone_evt->bss_cnt);
7025 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7028 void report_join_res(struct adapter *padapter, int res)
7030 struct cmd_obj *pcmd_obj;
7033 struct joinbss_event *pjoinbss_evt;
7034 struct C2HEvent_Header *pc2h_evt_hdr;
7035 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7036 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7037 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7039 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
7043 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
7044 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
7050 INIT_LIST_HEAD(&pcmd_obj->list);
7052 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7053 pcmd_obj->cmdsz = cmdsz;
7054 pcmd_obj->parmbuf = pevtcmd;
7056 pcmd_obj->rsp = NULL;
7057 pcmd_obj->rspsz = 0;
7059 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7060 pc2h_evt_hdr->len = sizeof(struct joinbss_event);
7061 pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
7062 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7064 pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7065 memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
7066 pjoinbss_evt->network.join_res = res;
7067 pjoinbss_evt->network.aid = res;
7069 DBG_88E("report_join_res(%d)\n", res);
7071 rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
7073 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7076 void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
7078 struct cmd_obj *pcmd_obj;
7081 struct sta_info *psta;
7083 struct stadel_event *pdel_sta_evt;
7084 struct C2HEvent_Header *pc2h_evt_hdr;
7085 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7086 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7088 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7092 cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
7093 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7099 INIT_LIST_HEAD(&pcmd_obj->list);
7101 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7102 pcmd_obj->cmdsz = cmdsz;
7103 pcmd_obj->parmbuf = pevtcmd;
7105 pcmd_obj->rsp = NULL;
7106 pcmd_obj->rspsz = 0;
7108 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7109 pc2h_evt_hdr->len = sizeof(struct stadel_event);
7110 pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
7111 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7113 pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7114 memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7115 memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
7117 psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
7119 mac_id = (int)psta->mac_id;
7123 pdel_sta_evt->mac_id = mac_id;
7125 DBG_88E("report_del_sta_event: delete STA, mac_id =%d\n", mac_id);
7127 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7130 void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx)
7132 struct cmd_obj *pcmd_obj;
7135 struct stassoc_event *padd_sta_evt;
7136 struct C2HEvent_Header *pc2h_evt_hdr;
7137 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7138 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7140 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
7144 cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
7145 pevtcmd = kzalloc(cmdsz, GFP_KERNEL);
7151 INIT_LIST_HEAD(&pcmd_obj->list);
7153 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7154 pcmd_obj->cmdsz = cmdsz;
7155 pcmd_obj->parmbuf = pevtcmd;
7157 pcmd_obj->rsp = NULL;
7158 pcmd_obj->rspsz = 0;
7160 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7161 pc2h_evt_hdr->len = sizeof(struct stassoc_event);
7162 pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
7163 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7165 padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7166 memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7167 padd_sta_evt->cam_id = cam_idx;
7169 DBG_88E("report_add_sta_event: add STA\n");
7171 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7174 /****************************************************************************
7176 Following are the event callback functions
7178 *****************************************************************************/
7180 /* for sta/adhoc mode */
7181 void update_sta_info(struct adapter *padapter, struct sta_info *psta)
7183 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7184 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7185 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7188 VCS_update(padapter, psta);
7191 if (pmlmepriv->htpriv.ht_option) {
7192 psta->htpriv.ht_option = true;
7194 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
7196 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps)))
7197 psta->htpriv.sgi = true;
7199 psta->qos_option = true;
7201 psta->htpriv.ht_option = false;
7203 psta->htpriv.ampdu_enable = false;
7205 psta->htpriv.sgi = false;
7206 psta->qos_option = false;
7208 psta->htpriv.bwmode = pmlmeext->cur_bwmode;
7209 psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
7211 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
7212 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
7215 if (pmlmepriv->qospriv.qos_option)
7216 psta->qos_option = true;
7218 psta->state = _FW_LINKED;
7221 void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res)
7223 struct sta_info *psta, *psta_bmc;
7224 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7225 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7226 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
7227 struct sta_priv *pstapriv = &padapter->stapriv;
7233 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7234 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7236 /* restore to initial setting. */
7237 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7239 goto exit_mlmeext_joinbss_event_callback;
7242 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7244 psta_bmc = rtw_get_bcmc_stainfo(padapter);
7246 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc;
7247 update_bmc_sta_support_rate(padapter, psta_bmc->mac_id);
7248 Update_RA_Entry(padapter, psta_bmc->mac_id);
7252 /* turn on dynamic functions */
7253 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
7255 /* update IOT-releated issue */
7256 update_IOT_info(padapter);
7258 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
7261 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
7263 /* udpate capability */
7264 update_capinfo(padapter, pmlmeinfo->capability);
7266 /* WMM, Update EDCA param */
7267 WMMOnAssocRsp(padapter);
7270 HTOnAssocRsp(padapter);
7272 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7274 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
7275 if (psta) { /* only for infra. mode */
7276 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7278 psta->wireless_mode = pmlmeext->cur_wireless_mode;
7280 /* set per sta rate after updating HT cap. */
7281 set_sta_rate(padapter, psta);
7282 rtw_hal_set_hwreg(padapter, HW_VAR_TX_RPT_MAX_MACID, (u8 *)&psta->mac_id);
7283 media_status = (psta->mac_id<<8)|1; /* MACID|OPMODE: 1 means connect */
7284 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
7288 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7290 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
7291 /* correcting TSF */
7292 correct_TSF(padapter, pmlmeext);
7294 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
7296 exit_mlmeext_joinbss_event_callback:
7298 DBG_88E("=>%s\n", __func__);
7301 void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta)
7303 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7304 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7307 DBG_88E("%s\n", __func__);
7309 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7310 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {/* adhoc master or sta_count>1 */
7312 } else { /* adhoc client */
7313 /* correcting TSF */
7314 correct_TSF(padapter, pmlmeext);
7317 if (send_beacon(padapter) == _FAIL) {
7318 pmlmeinfo->FW_sta_info[psta->mac_id].status = 0;
7319 pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE;
7322 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
7326 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7329 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7331 /* rate radaptive */
7332 Update_RA_Entry(padapter, psta->mac_id);
7334 /* update adhoc sta_info */
7335 update_sta_info(padapter, psta);
7338 void mlmeext_sta_del_event_callback(struct adapter *padapter)
7340 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7341 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7343 if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter)) {
7344 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7345 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7347 /* restore to initial setting. */
7348 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7350 /* switch to the 20M Hz mode after disconnect */
7351 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7352 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7354 /* SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset); */
7355 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7357 flush_all_cam_entry(padapter);
7359 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7361 /* set MSR to no link state -> infra. mode */
7362 Set_MSR(padapter, _HW_STATE_STATION_);
7364 _cancel_timer_ex(&pmlmeext->link_timer);
7368 /****************************************************************************
7370 Following are the functions for the timer handlers
7372 *****************************************************************************/
7373 void _linked_rx_signal_strehgth_display(struct adapter *padapter);
7374 void _linked_rx_signal_strehgth_display(struct adapter *padapter)
7376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7377 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7379 int UndecoratedSmoothedPWDB;
7380 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
7382 else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
7385 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &mac_id);
7387 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
7388 DBG_88E("UndecoratedSmoothedPWDB:%d\n", UndecoratedSmoothedPWDB);
7391 static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta)
7395 if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)) &&
7396 sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta) &&
7397 sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta))
7402 sta_update_last_rx_pkts(psta);
7407 void linked_status_chk(struct adapter *padapter)
7410 struct sta_info *psta;
7411 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7412 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7413 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7414 struct sta_priv *pstapriv = &padapter->stapriv;
7416 if (padapter->bRxRSSIDisplay)
7417 _linked_rx_signal_strehgth_display(padapter);
7419 rtw_hal_sreset_linked_status_check(padapter);
7421 if (is_client_associated_to_ap(padapter)) {
7422 /* linked infrastructure client mode */
7424 int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
7428 psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
7430 bool is_p2p_enable = false;
7431 #ifdef CONFIG_88EU_P2P
7432 is_p2p_enable = !rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE);
7435 if (!chk_ap_is_alive(padapter, psta))
7438 if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
7441 if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)) {
7442 u8 backup_oper_channel = 0;
7444 /* switch to correct channel of current network before issue keep-alive frames */
7445 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
7446 backup_oper_channel = rtw_get_oper_ch(padapter);
7447 SelectChannel(padapter, pmlmeext->cur_channel);
7450 if (rx_chk != _SUCCESS)
7451 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 3, 1);
7453 if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) || rx_chk != _SUCCESS) {
7454 tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
7455 /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
7456 if (tx_chk == _SUCCESS && !is_p2p_enable)
7460 /* back to the original operation channel */
7461 if (backup_oper_channel > 0)
7462 SelectChannel(padapter, backup_oper_channel);
7464 if (rx_chk != _SUCCESS) {
7465 if (pmlmeext->retry == 0) {
7466 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7467 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7468 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7472 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) {
7473 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0);
7477 if (rx_chk == _FAIL) {
7479 if (pmlmeext->retry > rx_chk_limit) {
7480 DBG_88E_LEVEL(_drv_always_, FUNC_ADPT_FMT" disconnect or roaming\n",
7481 FUNC_ADPT_ARG(padapter));
7482 receive_disconnect(padapter, pmlmeinfo->network.MacAddress,
7483 WLAN_REASON_EXPIRATION_CHK);
7487 pmlmeext->retry = 0;
7490 if (tx_chk == _FAIL) {
7491 pmlmeinfo->link_count &= 0xf;
7493 pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
7494 pmlmeinfo->link_count = 0;
7496 } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL) */
7497 } else if (is_client_associated_to_ibss(padapter)) {
7498 /* linked IBSS mode */
7499 /* for each assoc list entry to check the rx pkt counter */
7500 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
7501 if (pmlmeinfo->FW_sta_info[i].status == 1) {
7502 psta = pmlmeinfo->FW_sta_info[i].psta;
7506 if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta)) {
7507 if (pmlmeinfo->FW_sta_info[i].retry < 3) {
7508 pmlmeinfo->FW_sta_info[i].retry++;
7510 pmlmeinfo->FW_sta_info[i].retry = 0;
7511 pmlmeinfo->FW_sta_info[i].status = 0;
7512 report_del_sta_event(padapter, psta->hwaddr
7513 , 65535/* indicate disconnect caused by no rx */
7517 pmlmeinfo->FW_sta_info[i].retry = 0;
7518 pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta);
7525 void survey_timer_hdl(struct adapter *padapter)
7527 struct cmd_obj *ph2c;
7528 struct sitesurvey_parm *psurveyPara;
7529 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7530 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7531 #ifdef CONFIG_88EU_P2P
7532 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7535 /* issue rtw_sitesurvey_cmd */
7536 if (pmlmeext->sitesurvey_res.state > SCAN_START) {
7537 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
7538 pmlmeext->sitesurvey_res.channel_idx++;
7540 if (pmlmeext->scan_abort) {
7541 #ifdef CONFIG_88EU_P2P
7542 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE)) {
7543 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
7544 pmlmeext->sitesurvey_res.channel_idx = 3;
7545 DBG_88E("%s idx:%d, cnt:%u\n", __func__
7546 , pmlmeext->sitesurvey_res.channel_idx
7547 , pwdinfo->find_phase_state_exchange_cnt
7552 pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num;
7553 DBG_88E("%s idx:%d\n", __func__
7554 , pmlmeext->sitesurvey_res.channel_idx
7558 pmlmeext->scan_abort = false;/* reset */
7561 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
7563 goto exit_survey_timer_hdl;
7565 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
7568 goto exit_survey_timer_hdl;
7571 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
7572 rtw_enqueue_cmd(pcmdpriv, ph2c);
7575 exit_survey_timer_hdl:
7579 void link_timer_hdl(struct adapter *padapter)
7581 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7582 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7584 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
7585 DBG_88E("link_timer_hdl:no beacon while connecting\n");
7586 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7587 report_join_res(padapter, -3);
7588 } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) {
7590 if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) {
7591 pmlmeinfo->state = 0;
7592 report_join_res(padapter, -1);
7596 DBG_88E("link_timer_hdl: auth timeout and try again\n");
7597 pmlmeinfo->auth_seq = 1;
7598 issue_auth(padapter, NULL, 0);
7599 set_link_timer(pmlmeext, REAUTH_TO);
7600 } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) {
7601 /* re-assoc timer */
7602 if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) {
7603 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7604 report_join_res(padapter, -2);
7608 DBG_88E("link_timer_hdl: assoc timeout and try again\n");
7609 issue_assocreq(padapter);
7610 set_link_timer(pmlmeext, REASSOC_TO);
7614 void addba_timer_hdl(struct sta_info *psta)
7616 struct ht_priv *phtpriv;
7621 phtpriv = &psta->htpriv;
7623 if ((phtpriv->ht_option) && (phtpriv->ampdu_enable)) {
7624 if (phtpriv->candidate_tid_bitmap)
7625 phtpriv->candidate_tid_bitmap = 0x0;
7629 u8 NULL_hdl(struct adapter *padapter, u8 *pbuf)
7634 u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
7637 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7638 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7639 struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
7641 if (psetop->mode == Ndis802_11APMode) {
7642 pmlmeinfo->state = WIFI_FW_AP_STATE;
7643 type = _HW_STATE_AP_;
7644 } else if (psetop->mode == Ndis802_11Infrastructure) {
7645 pmlmeinfo->state &= ~(BIT(0)|BIT(1));/* clear state */
7646 pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */
7647 type = _HW_STATE_STATION_;
7648 } else if (psetop->mode == Ndis802_11IBSS) {
7649 type = _HW_STATE_ADHOC_;
7651 type = _HW_STATE_NOLINK_;
7654 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
7655 /* Set_NETYPE0_MSR(padapter, type); */
7660 u8 createbss_hdl(struct adapter *padapter, u8 *pbuf)
7662 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7663 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7664 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7665 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7666 /* u32 initialgain; */
7668 if (pparm->network.InfrastructureMode == Ndis802_11APMode) {
7669 #ifdef CONFIG_88EU_AP_MODE
7671 if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
7678 /* below is for ad-hoc master */
7679 if (pparm->network.InfrastructureMode == Ndis802_11IBSS) {
7680 rtw_joinbss_reset(padapter);
7682 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7683 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7684 pmlmeinfo->ERP_enable = 0;
7685 pmlmeinfo->WMM_enable = 0;
7686 pmlmeinfo->HT_enable = 0;
7687 pmlmeinfo->HT_caps_enable = 0;
7688 pmlmeinfo->HT_info_enable = 0;
7689 pmlmeinfo->agg_enable_bitmap = 0;
7690 pmlmeinfo->candidate_tid_bitmap = 0;
7692 /* disable dynamic functions, such as high power, DIG */
7693 Save_DM_Func_Flag(padapter);
7694 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
7696 /* config the initial gain under linking, need to write the BB registers */
7697 /* initialgain = 0x1E; */
7698 /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */
7700 /* cancel link timer */
7701 _cancel_timer_ex(&pmlmeext->link_timer);
7704 flush_all_cam_entry(padapter);
7706 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7707 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7709 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7710 return H2C_PARAMETERS_ERROR;
7712 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7714 start_create_ibss(padapter);
7720 u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf)
7723 struct ndis_802_11_var_ie *pIE;
7724 struct registry_priv *pregpriv = &padapter->registrypriv;
7725 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7726 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7727 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7728 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7731 /* check already connecting to AP or not */
7732 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
7733 if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
7734 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 5, 100);
7736 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7739 flush_all_cam_entry(padapter);
7741 _cancel_timer_ex(&pmlmeext->link_timer);
7743 /* set MSR to nolink -> infra. mode */
7744 Set_MSR(padapter, _HW_STATE_STATION_);
7746 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7749 rtw_antenna_select_cmd(padapter, pparm->network.PhyInfo.Optimum_antenna, false);
7751 rtw_joinbss_reset(padapter);
7753 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7754 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7755 pmlmeinfo->ERP_enable = 0;
7756 pmlmeinfo->WMM_enable = 0;
7757 pmlmeinfo->HT_enable = 0;
7758 pmlmeinfo->HT_caps_enable = 0;
7759 pmlmeinfo->HT_info_enable = 0;
7760 pmlmeinfo->agg_enable_bitmap = 0;
7761 pmlmeinfo->candidate_tid_bitmap = 0;
7762 pmlmeinfo->bwmode_updated = false;
7764 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7765 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7767 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7768 return H2C_PARAMETERS_ERROR;
7770 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7772 /* Check AP vendor to move rtw_joinbss_cmd() */
7774 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pnetwork->IELength;) {
7775 pIE = (struct ndis_802_11_var_ie *)(pnetwork->IEs + i);
7777 switch (pIE->ElementID) {
7778 case _VENDOR_SPECIFIC_IE_:/* Get WMM IE. */
7779 if (!memcmp(pIE->data, WMM_OUI, 4))
7780 pmlmeinfo->WMM_enable = 1;
7782 case _HT_CAPABILITY_IE_: /* Get HT Cap IE. */
7783 pmlmeinfo->HT_caps_enable = 1;
7785 case _HT_EXTRA_INFO_IE_: /* Get HT Info IE. */
7786 pmlmeinfo->HT_info_enable = 1;
7788 /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */
7790 struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data);
7792 if ((pregpriv->cbw40_enable) && (pht_info->infos[0] & BIT(2))) {
7793 /* switch to the 40M Hz mode according to the AP */
7794 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_40;
7795 switch (pht_info->infos[0] & 0x3) {
7797 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
7800 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
7803 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7807 DBG_88E("set ch/bw before connected\n");
7815 i += (pIE->Length + 2);
7817 /* disable dynamic functions, such as high power, DIG */
7819 /* config the initial gain under linking, need to write the BB registers */
7821 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
7823 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7825 /* cancel link timer */
7826 _cancel_timer_ex(&pmlmeext->link_timer);
7828 start_clnt_join(padapter);
7833 u8 disconnect_hdl(struct adapter *padapter, unsigned char *pbuf)
7835 struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
7836 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7837 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7838 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7841 if (is_client_associated_to_ap(padapter))
7842 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms/100, 100);
7844 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7845 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7847 /* restore to initial setting. */
7848 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7850 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
7853 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
7856 /* set MSR to no link state -> infra. mode */
7857 Set_MSR(padapter, _HW_STATE_STATION_);
7859 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7861 /* switch to the 20M Hz mode after disconnect */
7862 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7863 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7865 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7867 flush_all_cam_entry(padapter);
7869 _cancel_timer_ex(&pmlmeext->link_timer);
7871 rtw_free_uc_swdec_pending_queue(padapter);
7876 static int rtw_scan_ch_decision(struct adapter *padapter, struct rtw_ieee80211_channel *out,
7877 u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
7881 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7883 /* clear out first */
7884 memset(out, 0, sizeof(struct rtw_ieee80211_channel)*out_num);
7886 /* acquire channels from in */
7888 for (i = 0; i < in_num; i++) {
7889 set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value);
7890 if (in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED) &&
7892 memcpy(&out[j], &in[i], sizeof(struct rtw_ieee80211_channel));
7894 if (pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
7895 out[j].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
7903 /* if out is empty, use channel_set as default */
7905 for (i = 0; i < pmlmeext->max_chan_nums; i++) {
7906 out[i].hw_value = pmlmeext->channel_set[i].ChannelNum;
7908 if (pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
7909 out[i].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
7918 u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf)
7920 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7921 struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
7922 u8 bdelayscan = false;
7927 #ifdef CONFIG_88EU_P2P
7928 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
7931 if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE) {
7932 /* for first time sitesurvey_cmd */
7933 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, NULL);
7935 pmlmeext->sitesurvey_res.state = SCAN_START;
7936 pmlmeext->sitesurvey_res.bss_cnt = 0;
7937 pmlmeext->sitesurvey_res.channel_idx = 0;
7939 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
7940 if (pparm->ssid[i].SsidLength) {
7941 memcpy(pmlmeext->sitesurvey_res.ssid[i].Ssid, pparm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
7942 pmlmeext->sitesurvey_res.ssid[i].SsidLength = pparm->ssid[i].SsidLength;
7944 pmlmeext->sitesurvey_res.ssid[i].SsidLength = 0;
7948 pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter
7949 , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT
7950 , pparm->ch, pparm->ch_num
7953 pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode;
7955 /* issue null data if associating to the AP */
7956 if (is_client_associated_to_ap(padapter)) {
7957 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
7959 issue_nulldata(padapter, NULL, 1, 3, 500);
7964 /* delay 50ms to protect nulldata(1). */
7965 set_survey_timer(pmlmeext, 50);
7970 if ((pmlmeext->sitesurvey_res.state == SCAN_START) || (pmlmeext->sitesurvey_res.state == SCAN_TXNULL)) {
7971 /* disable dynamic functions, such as high power, DIG */
7972 Save_DM_Func_Flag(padapter);
7973 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
7975 /* config the initial gain under scanning, need to write the BB registers */
7976 #ifdef CONFIG_88EU_P2P
7977 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
7981 #else /* CONFIG_88EU_P2P */
7983 #endif /* CONFIG_88EU_P2P */
7985 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
7987 /* set MSR to no link state */
7988 Set_MSR(padapter, _HW_STATE_NOLINK_);
7990 val8 = 1; /* under site survey */
7991 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
7993 pmlmeext->sitesurvey_res.state = SCAN_PROCESS;
7996 site_survey(padapter);
8001 u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf)
8003 struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
8004 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8005 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8007 if (pparm->mode < 4)
8008 pmlmeinfo->auth_algo = pparm->mode;
8012 u8 setkey_hdl(struct adapter *padapter, u8 *pbuf)
8014 unsigned short ctrl;
8015 struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
8016 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8017 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8018 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8020 /* main tx key for wep. */
8022 pmlmeinfo->key_index = pparm->keyid;
8025 ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
8027 DBG_88E_LEVEL(_drv_info_, "set group key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) "
8028 "keyid:%d\n", pparm->algorithm, pparm->keyid);
8029 write_cam(padapter, pparm->keyid, ctrl, null_sta, pparm->key);
8034 u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf)
8037 u8 cam_id;/* cam_entry */
8038 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8039 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8040 struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
8043 /* 0~3 for default key */
8045 /* for concurrent mode (ap+sta): */
8046 /* default key is disable, using sw encrypt/decrypt */
8047 /* cam_entry = 4 for sta mode (macid = 0) */
8048 /* cam_entry(macid+3) = 5 ~ N for ap mode (aid = 1~N, macid = 2 ~N) */
8050 /* for concurrent mode (sta+sta): */
8051 /* default key is disable, using sw encrypt/decrypt */
8052 /* cam_entry = 4 mapping to macid = 0 */
8053 /* cam_entry = 5 mapping to macid = 2 */
8057 DBG_88E_LEVEL(_drv_info_, "set pairwise key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) camid:%d\n",
8058 pparm->algorithm, cam_id);
8059 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
8060 struct sta_info *psta;
8061 struct sta_priv *pstapriv = &padapter->stapriv;
8063 if (pparm->algorithm == _NO_PRIVACY_) /* clear cam entry */ {
8064 clear_cam_entry(padapter, pparm->id);
8065 return H2C_SUCCESS_RSP;
8068 psta = rtw_get_stainfo(pstapriv, pparm->addr);
8070 ctrl = (BIT(15) | ((pparm->algorithm) << 2));
8072 DBG_88E("r871x_set_stakey_hdl(): enc_algorithm=%d\n", pparm->algorithm);
8074 if ((psta->mac_id < 1) || (psta->mac_id > (NUM_STA-4))) {
8075 DBG_88E("r871x_set_stakey_hdl():set_stakey failed, mac_id(aid)=%d\n", psta->mac_id);
8076 return H2C_REJECTED;
8079 cam_id = (psta->mac_id + 3);/* 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
8081 DBG_88E("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, cam_entry=%d\n", pparm->addr[0],
8082 pparm->addr[1], pparm->addr[2], pparm->addr[3], pparm->addr[4],
8083 pparm->addr[5], cam_id);
8085 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8087 return H2C_SUCCESS_RSP;
8089 DBG_88E("r871x_set_stakey_hdl(): sta has been free\n");
8090 return H2C_REJECTED;
8094 /* below for sta mode */
8096 if (pparm->algorithm == _NO_PRIVACY_) { /* clear cam entry */
8097 clear_cam_entry(padapter, pparm->id);
8100 ctrl = BIT(15) | ((pparm->algorithm) << 2);
8101 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8102 pmlmeinfo->enc_algo = pparm->algorithm;
8106 u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf)
8108 struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
8109 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8110 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8112 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
8117 if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
8118 ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
8119 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
8120 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
8122 psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
8127 u8 set_tx_beacon_cmd(struct adapter *padapter)
8129 struct cmd_obj *ph2c;
8130 struct Tx_Beacon_param *ptxBeacon_parm;
8131 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
8132 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8133 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8137 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL);
8143 ptxBeacon_parm = kzalloc(sizeof(struct Tx_Beacon_param), GFP_KERNEL);
8144 if (!ptxBeacon_parm) {
8150 memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
8152 len_diff = update_hidden_ssid(ptxBeacon_parm->network.IEs+_BEACON_IE_OFFSET_,
8153 ptxBeacon_parm->network.IELength-_BEACON_IE_OFFSET_,
8154 pmlmeinfo->hidden_ssid_mode);
8155 ptxBeacon_parm->network.IELength += len_diff;
8157 init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
8159 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
8166 u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf)
8171 void (*event_callback)(struct adapter *dev, u8 *pbuf);
8172 struct evt_priv *pevt_priv = &(padapter->evtpriv);
8174 peventbuf = (uint *)pbuf;
8175 evt_sz = (u16)(*peventbuf&0xffff);
8176 evt_code = (u8)((*peventbuf>>16)&0xff);
8178 /* checking if event code is valid */
8179 if (evt_code >= MAX_C2HEVT)
8182 /* checking if event size match the event parm size */
8183 if ((wlanevents[evt_code].parmsize != 0) &&
8184 (wlanevents[evt_code].parmsize != evt_sz))
8187 atomic_inc(&pevt_priv->event_seq);
8192 event_callback = wlanevents[evt_code].event_callback;
8193 event_callback(padapter, (u8 *)peventbuf);
8195 pevt_priv->evt_done_cnt++;
8202 u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf)
8205 return H2C_PARAMETERS_ERROR;
8210 u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf)
8212 if (send_beacon(padapter) == _FAIL) {
8213 DBG_88E("issue_beacon, fail!\n");
8214 return H2C_PARAMETERS_ERROR;
8216 #ifdef CONFIG_88EU_AP_MODE
8217 else { /* tx bc/mc frames after update TIM */
8218 struct sta_info *psta_bmc;
8219 struct list_head *xmitframe_plist, *xmitframe_phead;
8220 struct xmit_frame *pxmitframe = NULL;
8221 struct sta_priv *pstapriv = &padapter->stapriv;
8223 /* for BC/MC Frames */
8224 psta_bmc = rtw_get_bcmc_stainfo(padapter);
8228 if ((pstapriv->tim_bitmap&BIT(0)) && (psta_bmc->sleepq_len > 0)) {
8229 msleep(10);/* 10ms, ATIM(HIQ) Windows */
8230 spin_lock_bh(&psta_bmc->sleep_q.lock);
8232 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
8233 xmitframe_plist = xmitframe_phead->next;
8235 while (xmitframe_phead != xmitframe_plist) {
8236 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
8238 xmitframe_plist = xmitframe_plist->next;
8240 list_del_init(&pxmitframe->list);
8242 psta_bmc->sleepq_len--;
8243 if (psta_bmc->sleepq_len > 0)
8244 pxmitframe->attrib.mdata = 1;
8246 pxmitframe->attrib.mdata = 0;
8248 pxmitframe->attrib.triggered = 1;
8250 pxmitframe->attrib.qsel = 0x11;/* HIQ */
8252 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8253 if (rtw_hal_xmit(padapter, pxmitframe))
8254 rtw_os_xmit_complete(padapter, pxmitframe);
8255 spin_lock_bh(&psta_bmc->sleep_q.lock);
8257 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8264 u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf)
8266 struct set_ch_parm *set_ch_parm;
8267 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8270 return H2C_PARAMETERS_ERROR;
8272 set_ch_parm = (struct set_ch_parm *)pbuf;
8274 DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
8275 FUNC_NDEV_ARG(padapter->pnetdev),
8276 set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
8278 pmlmeext->cur_channel = set_ch_parm->ch;
8279 pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
8280 pmlmeext->cur_bwmode = set_ch_parm->bw;
8282 set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
8287 u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)
8289 struct SetChannelPlan_param *setChannelPlan_param;
8290 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8293 return H2C_PARAMETERS_ERROR;
8295 setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
8297 pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
8298 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
8303 u8 led_blink_hdl(struct adapter *padapter, unsigned char *pbuf)
8306 return H2C_PARAMETERS_ERROR;
8310 u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf)
8312 return H2C_REJECTED;
8315 /* TDLS_WRCR : write RCR DATA BIT */
8316 /* TDLS_SD_PTI : issue peer traffic indication */
8317 /* TDLS_CS_OFF : go back to the channel linked with AP, terminating channel switch procedure */
8318 /* TDLS_INIT_CH_SEN : init channel sensing, receive all data and mgnt frame */
8319 /* TDLS_DONE_CH_SEN: channel sensing and report candidate channel */
8320 /* TDLS_OFF_CH : first time set channel to off channel */
8321 /* TDLS_BASE_CH : go back tp the channel linked with AP when set base channel as target channel */
8322 /* TDLS_P_OFF_CH : periodically go to off channel */
8323 /* TDLS_P_BASE_CH : periodically go back to base channel */
8324 /* TDLS_RS_RCR : restore RCR */
8325 /* TDLS_CKALV_PH1 : check alive timer phase1 */
8326 /* TDLS_CKALV_PH2 : check alive timer phase2 */
8327 /* TDLS_FREE_STA : free tdls sta */
8328 u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf)
8330 return H2C_REJECTED;