1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define _RTW_MLME_EXT_C_
22 #include <osdep_service.h>
23 #include <drv_types.h>
25 #include <rtw_mlme_ext.h>
26 #include <wlan_bssdef.h>
27 #include <mlme_osdep.h>
28 #include <recv_osdep.h>
30 static struct mlme_handler mlme_sta_tbl[] = {
31 {WIFI_ASSOCREQ, "OnAssocReq", &OnAssocReq},
32 {WIFI_ASSOCRSP, "OnAssocRsp", &OnAssocRsp},
33 {WIFI_REASSOCREQ, "OnReAssocReq", &OnAssocReq},
34 {WIFI_REASSOCRSP, "OnReAssocRsp", &OnAssocRsp},
35 {WIFI_PROBEREQ, "OnProbeReq", &OnProbeReq},
36 {WIFI_PROBERSP, "OnProbeRsp", &OnProbeRsp},
38 /*----------------------------------------------------------
40 -----------------------------------------------------------*/
41 {0, "DoReserved", &DoReserved},
42 {0, "DoReserved", &DoReserved},
43 {WIFI_BEACON, "OnBeacon", &OnBeacon},
44 {WIFI_ATIM, "OnATIM", &OnAtim},
45 {WIFI_DISASSOC, "OnDisassoc", &OnDisassoc},
46 {WIFI_AUTH, "OnAuth", &OnAuthClient},
47 {WIFI_DEAUTH, "OnDeAuth", &OnDeAuth},
48 {WIFI_ACTION, "OnAction", &OnAction},
51 static struct action_handler OnAction_tbl[] = {
52 {RTW_WLAN_CATEGORY_SPECTRUM_MGMT, "ACTION_SPECTRUM_MGMT", on_action_spct},
53 {RTW_WLAN_CATEGORY_QOS, "ACTION_QOS", &OnAction_qos},
54 {RTW_WLAN_CATEGORY_DLS, "ACTION_DLS", &OnAction_dls},
55 {RTW_WLAN_CATEGORY_BACK, "ACTION_BACK", &OnAction_back},
56 {RTW_WLAN_CATEGORY_PUBLIC, "ACTION_PUBLIC", on_action_public},
57 {RTW_WLAN_CATEGORY_RADIO_MEASUREMENT, "ACTION_RADIO_MEASUREMENT", &DoReserved},
58 {RTW_WLAN_CATEGORY_FT, "ACTION_FT", &DoReserved},
59 {RTW_WLAN_CATEGORY_HT, "ACTION_HT", &OnAction_ht},
60 {RTW_WLAN_CATEGORY_SA_QUERY, "ACTION_SA_QUERY", &DoReserved},
61 {RTW_WLAN_CATEGORY_WMM, "ACTION_WMM", &OnAction_wmm},
62 {RTW_WLAN_CATEGORY_P2P, "ACTION_P2P", &OnAction_p2p},
66 static u8 null_addr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
68 /**************************************************
69 OUI definitions for the vendor specific IE
70 ***************************************************/
71 unsigned char RTW_WPA_OUI[] = {0x00, 0x50, 0xf2, 0x01};
72 unsigned char WMM_OUI[] = {0x00, 0x50, 0xf2, 0x02};
73 unsigned char WPS_OUI[] = {0x00, 0x50, 0xf2, 0x04};
74 unsigned char P2P_OUI[] = {0x50, 0x6F, 0x9A, 0x09};
75 unsigned char WFD_OUI[] = {0x50, 0x6F, 0x9A, 0x0A};
77 unsigned char WMM_INFO_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
78 unsigned char WMM_PARA_OUI[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
80 unsigned char WPA_TKIP_CIPHER[4] = {0x00, 0x50, 0xf2, 0x02};
81 unsigned char RSN_TKIP_CIPHER[4] = {0x00, 0x0f, 0xac, 0x02};
83 extern unsigned char REALTEK_96B_IE[];
85 /********************************************************
87 *********************************************************/
88 unsigned char MCS_rate_2R[16] = {0xff, 0xff, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
89 unsigned char MCS_rate_1R[16] = {0xff, 0x00, 0x0, 0x0, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
91 /********************************************************
92 ChannelPlan definitions
93 *********************************************************/
94 static struct rt_channel_plan_2g RTW_ChannelPlan2G[RT_CHANNEL_DOMAIN_2G_MAX] = {
95 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x00, RT_CHANNEL_DOMAIN_2G_WORLD , Passive scan CH 12, 13 */
96 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}, /* 0x01, RT_CHANNEL_DOMAIN_2G_ETSI1 */
97 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11}, /* 0x02, RT_CHANNEL_DOMAIN_2G_FCC1 */
98 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}, /* 0x03, RT_CHANNEL_DOMAIN_2G_MIKK1 */
99 {{10, 11, 12, 13}, 4}, /* 0x04, RT_CHANNEL_DOMAIN_2G_ETSI2 */
100 {{}, 0}, /* 0x05, RT_CHANNEL_DOMAIN_2G_NULL */
103 static struct rt_channel_plan_map RTW_ChannelPlanMap[RT_CHANNEL_DOMAIN_MAX] = {
104 /* 0x00 ~ 0x1F , Old Define ===== */
105 {0x02}, /* 0x00, RT_CHANNEL_DOMAIN_FCC */
106 {0x02}, /* 0x01, RT_CHANNEL_DOMAIN_IC */
107 {0x01}, /* 0x02, RT_CHANNEL_DOMAIN_ETSI */
108 {0x01}, /* 0x03, RT_CHANNEL_DOMAIN_SPAIN */
109 {0x01}, /* 0x04, RT_CHANNEL_DOMAIN_FRANCE */
110 {0x03}, /* 0x05, RT_CHANNEL_DOMAIN_MKK */
111 {0x03}, /* 0x06, RT_CHANNEL_DOMAIN_MKK1 */
112 {0x01}, /* 0x07, RT_CHANNEL_DOMAIN_ISRAEL */
113 {0x03}, /* 0x08, RT_CHANNEL_DOMAIN_TELEC */
114 {0x03}, /* 0x09, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN */
115 {0x00}, /* 0x0A, RT_CHANNEL_DOMAIN_WORLD_WIDE_13 */
116 {0x02}, /* 0x0B, RT_CHANNEL_DOMAIN_TAIWAN */
117 {0x01}, /* 0x0C, RT_CHANNEL_DOMAIN_CHINA */
118 {0x02}, /* 0x0D, RT_CHANNEL_DOMAIN_SINGAPORE_INDIA_MEXICO */
119 {0x02}, /* 0x0E, RT_CHANNEL_DOMAIN_KOREA */
120 {0x02}, /* 0x0F, RT_CHANNEL_DOMAIN_TURKEY */
121 {0x01}, /* 0x10, RT_CHANNEL_DOMAIN_JAPAN */
122 {0x02}, /* 0x11, RT_CHANNEL_DOMAIN_FCC_NO_DFS */
123 {0x01}, /* 0x12, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
124 {0x00}, /* 0x13, RT_CHANNEL_DOMAIN_WORLD_WIDE_5G */
125 {0x02}, /* 0x14, RT_CHANNEL_DOMAIN_TAIWAN_NO_DFS */
126 {0x00}, /* 0x15, RT_CHANNEL_DOMAIN_ETSI_NO_DFS */
127 {0x00}, /* 0x16, RT_CHANNEL_DOMAIN_KOREA_NO_DFS */
128 {0x03}, /* 0x17, RT_CHANNEL_DOMAIN_JAPAN_NO_DFS */
129 {0x05}, /* 0x18, RT_CHANNEL_DOMAIN_PAKISTAN_NO_DFS */
130 {0x02}, /* 0x19, RT_CHANNEL_DOMAIN_TAIWAN2_NO_DFS */
136 {0x05}, /* 0x1F, RT_CHANNEL_DOMAIN_WORLD_WIDE_ONLY_5G */
137 /* 0x20 ~ 0x7F , New Define ===== */
138 {0x00}, /* 0x20, RT_CHANNEL_DOMAIN_WORLD_NULL */
139 {0x01}, /* 0x21, RT_CHANNEL_DOMAIN_ETSI1_NULL */
140 {0x02}, /* 0x22, RT_CHANNEL_DOMAIN_FCC1_NULL */
141 {0x03}, /* 0x23, RT_CHANNEL_DOMAIN_MKK1_NULL */
142 {0x04}, /* 0x24, RT_CHANNEL_DOMAIN_ETSI2_NULL */
143 {0x02}, /* 0x25, RT_CHANNEL_DOMAIN_FCC1_FCC1 */
144 {0x00}, /* 0x26, RT_CHANNEL_DOMAIN_WORLD_ETSI1 */
145 {0x03}, /* 0x27, RT_CHANNEL_DOMAIN_MKK1_MKK1 */
146 {0x00}, /* 0x28, RT_CHANNEL_DOMAIN_WORLD_KCC1 */
147 {0x00}, /* 0x29, RT_CHANNEL_DOMAIN_WORLD_FCC2 */
154 {0x00}, /* 0x30, RT_CHANNEL_DOMAIN_WORLD_FCC3 */
155 {0x00}, /* 0x31, RT_CHANNEL_DOMAIN_WORLD_FCC4 */
156 {0x00}, /* 0x32, RT_CHANNEL_DOMAIN_WORLD_FCC5 */
157 {0x00}, /* 0x33, RT_CHANNEL_DOMAIN_WORLD_FCC6 */
158 {0x02}, /* 0x34, RT_CHANNEL_DOMAIN_FCC1_FCC7 */
159 {0x00}, /* 0x35, RT_CHANNEL_DOMAIN_WORLD_ETSI2 */
160 {0x00}, /* 0x36, RT_CHANNEL_DOMAIN_WORLD_ETSI3 */
161 {0x03}, /* 0x37, RT_CHANNEL_DOMAIN_MKK1_MKK2 */
162 {0x03}, /* 0x38, RT_CHANNEL_DOMAIN_MKK1_MKK3 */
163 {0x02}, /* 0x39, RT_CHANNEL_DOMAIN_FCC1_NCC1 */
170 {0x02}, /* 0x40, RT_CHANNEL_DOMAIN_FCC1_NCC2 */
171 {0x03}, /* 0x41, RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G */
174 static struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {0x03}; /* use the combination for max channel numbers */
177 * Search the @param channel_num in given @param channel_set
178 * @ch_set: the given channel set
179 * @ch: the given channel number
181 * return the index of channel_num in channel_set, -1 if not found
183 int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch)
186 for (i = 0; ch_set[i].ChannelNum != 0; i++) {
187 if (ch == ch_set[i].ChannelNum)
191 if (i >= ch_set[i].ChannelNum)
196 /****************************************************************************
198 Following are the initialization functions for WiFi MLME
200 *****************************************************************************/
202 int init_hw_mlme_ext(struct adapter *padapter)
204 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
206 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
210 static void init_mlme_ext_priv_value(struct adapter *padapter)
212 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
213 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
214 unsigned char mixed_datarate[NumRates] = {
215 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
216 _9M_RATE_, _12M_RATE_, _18M_RATE_, _24M_RATE_, _36M_RATE_,
217 _48M_RATE_, _54M_RATE_, 0xff
219 unsigned char mixed_basicrate[NumRates] = {
220 _1M_RATE_, _2M_RATE_, _5M_RATE_, _11M_RATE_, _6M_RATE_,
221 _12M_RATE_, _24M_RATE_, 0xff,
224 atomic_set(&pmlmeext->event_seq, 0);
225 pmlmeext->mgnt_seq = 0;/* reset to zero when disconnect at client mode */
227 pmlmeext->cur_channel = padapter->registrypriv.channel;
228 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
229 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
230 pmlmeext->oper_channel = pmlmeext->cur_channel ;
231 pmlmeext->oper_bwmode = pmlmeext->cur_bwmode;
232 pmlmeext->oper_ch_offset = pmlmeext->cur_ch_offset;
235 pmlmeext->cur_wireless_mode = padapter->registrypriv.wireless_mode;
237 memcpy(pmlmeext->datarate, mixed_datarate, NumRates);
238 memcpy(pmlmeext->basicrate, mixed_basicrate, NumRates);
240 pmlmeext->tx_rate = IEEE80211_CCK_RATE_1MB;
242 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
243 pmlmeext->sitesurvey_res.channel_idx = 0;
244 pmlmeext->sitesurvey_res.bss_cnt = 0;
245 pmlmeext->scan_abort = false;
247 pmlmeinfo->state = WIFI_FW_NULL_STATE;
248 pmlmeinfo->reauth_count = 0;
249 pmlmeinfo->reassoc_count = 0;
250 pmlmeinfo->link_count = 0;
251 pmlmeinfo->auth_seq = 0;
252 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
253 pmlmeinfo->key_index = 0;
256 pmlmeinfo->enc_algo = _NO_PRIVACY_;
257 pmlmeinfo->authModeToggle = 0;
259 _rtw_memset(pmlmeinfo->chg_txt, 0, 128);
261 pmlmeinfo->slotTime = SHORT_SLOT_TIME;
262 pmlmeinfo->preamble_mode = PREAMBLE_AUTO;
264 pmlmeinfo->dialogToken = 0;
266 pmlmeext->action_public_rxseq = 0xffff;
267 pmlmeext->action_public_dialog_token = 0xff;
270 static int has_channel(struct rt_channel_info *channel_set,
275 for (i = 0; i < chanset_size; i++) {
276 if (channel_set[i].ChannelNum == chan)
282 static void init_channel_list(struct adapter *padapter, struct rt_channel_info *channel_set,
284 struct p2p_channels *channel_list) {
285 struct p2p_oper_class_map op_class[] = {
286 { IEEE80211G, 81, 1, 13, 1, BW20 },
287 { IEEE80211G, 82, 14, 14, 1, BW20 },
288 { -1, 0, 0, 0, 0, BW20 }
295 for (op = 0; op_class[op].op_class; op++) {
297 struct p2p_oper_class_map *o = &op_class[op];
298 struct p2p_reg_class *reg = NULL;
300 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
301 if (!has_channel(channel_set, chanset_size, ch)) {
305 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
308 if ((0 == (padapter->registrypriv.cbw40_enable & BIT(1))) &&
309 ((BW40MINUS == o->bw) || (BW40PLUS == o->bw)))
313 reg = &channel_list->reg_class[cla];
315 reg->reg_class = o->op_class;
318 reg->channel[reg->channels] = ch;
322 channel_list->reg_classes = cla;
325 static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_channel_info *channel_set)
327 u8 index, chanset_size = 0;
328 u8 b2_4GBand = false;
331 _rtw_memset(channel_set, 0, sizeof(struct rt_channel_info) * MAX_CHANNEL_NUM);
333 if (ChannelPlan >= RT_CHANNEL_DOMAIN_MAX && ChannelPlan != RT_CHANNEL_DOMAIN_REALTEK_DEFINE) {
334 DBG_88E("ChannelPlan ID %x error !!!!!\n", ChannelPlan);
338 if (padapter->registrypriv.wireless_mode & WIRELESS_11G) {
340 if (RT_CHANNEL_DOMAIN_REALTEK_DEFINE == ChannelPlan)
341 Index2G = RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE.Index2G;
343 Index2G = RTW_ChannelPlanMap[ChannelPlan].Index2G;
347 for (index = 0; index < RTW_ChannelPlan2G[Index2G].Len; index++) {
348 channel_set[chanset_size].ChannelNum = RTW_ChannelPlan2G[Index2G].Channel[index];
350 if ((RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN == ChannelPlan) ||/* Channel 1~11 is active, and 12~14 is passive */
351 (RT_CHANNEL_DOMAIN_GLOBAL_DOAMIN_2G == ChannelPlan)) {
352 if (channel_set[chanset_size].ChannelNum >= 1 && channel_set[chanset_size].ChannelNum <= 11)
353 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
354 else if ((channel_set[chanset_size].ChannelNum >= 12 && channel_set[chanset_size].ChannelNum <= 14))
355 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
356 } else if (RT_CHANNEL_DOMAIN_WORLD_WIDE_13 == ChannelPlan ||
357 RT_CHANNEL_DOMAIN_2G_WORLD == Index2G) {/* channel 12~13, passive scan */
358 if (channel_set[chanset_size].ChannelNum <= 11)
359 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
361 channel_set[chanset_size].ScanType = SCAN_PASSIVE;
363 channel_set[chanset_size].ScanType = SCAN_ACTIVE;
372 int init_mlme_ext_priv(struct adapter *padapter)
375 struct registry_priv *pregistrypriv = &padapter->registrypriv;
376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
377 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
378 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
380 pmlmeext->padapter = padapter;
382 init_mlme_ext_priv_value(padapter);
383 pmlmeinfo->bAcceptAddbaReq = pregistrypriv->bAcceptAddbaReq;
385 init_mlme_ext_timer(padapter);
387 #ifdef CONFIG_88EU_AP_MODE
388 init_mlme_ap_info(padapter);
391 pmlmeext->max_chan_nums = init_channel_set(padapter, pmlmepriv->ChannelPlan, pmlmeext->channel_set);
392 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
394 pmlmeext->chan_scan_time = SURVEY_TO;
395 pmlmeext->mlmeext_init = true;
398 pmlmeext->active_keep_alive_check = true;
403 void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
405 struct adapter *padapter = pmlmeext->padapter;
410 if (padapter->bDriverStopped) {
411 _cancel_timer_ex(&pmlmeext->survey_timer);
412 _cancel_timer_ex(&pmlmeext->link_timer);
413 /* _cancel_timer_ex(&pmlmeext->ADDBA_timer); */
417 static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame)
419 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
420 u8 *pframe = precv_frame->rx_data;
423 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
424 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
425 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
427 ptable->func(padapter, precv_frame);
431 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
434 struct mlme_handler *ptable;
435 #ifdef CONFIG_88EU_AP_MODE
436 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
437 #endif /* CONFIG_88EU_AP_MODE */
438 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
439 u8 *pframe = precv_frame->rx_data;
440 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
442 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
443 ("+mgt_dispatcher: type(0x%x) subtype(0x%x)\n",
444 GetFrameType(pframe), GetFrameSubType(pframe)));
446 if (GetFrameType(pframe) != WIFI_MGT_TYPE) {
447 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("mgt_dispatcher: type(0x%x) error!\n", GetFrameType(pframe)));
451 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
452 if (memcmp(GetAddr1Ptr(pframe), myid(&padapter->eeprompriv), ETH_ALEN) &&
453 memcmp(GetAddr1Ptr(pframe), bc_addr, ETH_ALEN))
456 ptable = mlme_sta_tbl;
458 index = GetFrameSubType(pframe) >> 4;
461 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("Currently we do not support reserved sub-fr-type=%d\n", index));
467 if (GetRetry(pframe)) {
468 if (precv_frame->attrib.seq_num ==
469 psta->RxMgmtFrameSeqNum) {
470 /* drop the duplicate management frame */
471 DBG_88E("Drop duplicate management frame with seq_num=%d.\n",
472 precv_frame->attrib.seq_num);
476 psta->RxMgmtFrameSeqNum = precv_frame->attrib.seq_num;
479 #ifdef CONFIG_88EU_AP_MODE
480 switch (GetFrameSubType(pframe)) {
482 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
483 ptable->func = &OnAuth;
485 ptable->func = &OnAuthClient;
488 case WIFI_REASSOCREQ:
489 _mgt_dispatcher(padapter, ptable, precv_frame);
492 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
493 _mgt_dispatcher(padapter, ptable, precv_frame);
495 _mgt_dispatcher(padapter, ptable, precv_frame);
498 _mgt_dispatcher(padapter, ptable, precv_frame);
501 _mgt_dispatcher(padapter, ptable, precv_frame);
504 _mgt_dispatcher(padapter, ptable, precv_frame);
508 _mgt_dispatcher(padapter, ptable, precv_frame);
512 #ifdef CONFIG_88EU_P2P
513 static u32 p2p_listen_state_process(struct adapter *padapter, unsigned char *da)
515 bool response = true;
517 /* do nothing if the device name is empty */
518 if (!padapter->wdinfo.device_name_len)
522 issue_probersp_p2p(padapter, da);
526 #endif /* CONFIG_88EU_P2P */
529 /****************************************************************************
531 Following are the callback functions for each subtype of the management frames
533 *****************************************************************************/
535 unsigned int OnProbeReq(struct adapter *padapter, struct recv_frame *precv_frame)
539 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
540 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
541 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
542 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
543 u8 *pframe = precv_frame->rx_data;
544 uint len = precv_frame->len;
545 u8 is_valid_p2p_probereq = false;
547 #ifdef CONFIG_88EU_P2P
548 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
549 u8 wifi_test_chk_rate = 1;
551 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) &&
552 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE) &&
553 !rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT) &&
554 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH) &&
555 !rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN)) {
556 /* mcs_rate = 0 -> CCK 1M rate */
557 /* mcs_rate = 1 -> CCK 2M rate */
558 /* mcs_rate = 2 -> CCK 5.5M rate */
559 /* mcs_rate = 3 -> CCK 11M rate */
560 /* In the P2P mode, the driver should not support the CCK rate */
562 /* Commented by Kurt 2012/10/16 */
563 /* IOT issue: Google Nexus7 use 1M rate to send p2p_probe_req after GO nego completed and Nexus7 is client */
564 if (wifi_test_chk_rate == 1) {
565 is_valid_p2p_probereq = process_probe_req_p2p_ie(pwdinfo, pframe, len);
566 if (is_valid_p2p_probereq) {
567 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE)) {
569 report_survey_event(padapter, precv_frame);
570 p2p_listen_state_process(padapter, get_sa(pframe));
575 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO))
582 #endif /* CONFIG_88EU_P2P */
584 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
587 if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
588 !check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
591 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _PROBEREQ_IE_OFFSET_, _SSID_IE_, (int *)&ielen,
592 len - WLAN_HDR_A3_LEN - _PROBEREQ_IE_OFFSET_);
594 /* check (wildcard) SSID */
596 if (is_valid_p2p_probereq)
597 goto _issue_probersp;
599 if ((ielen != 0 && memcmp((void *)(p+2), (void *)cur->Ssid.Ssid, cur->Ssid.SsidLength)) ||
600 (ielen == 0 && pmlmeinfo->hidden_ssid_mode))
605 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
606 pmlmepriv->cur_network.join_res)
607 issue_probersp(padapter, get_sa(pframe), is_valid_p2p_probereq);
612 unsigned int OnProbeRsp(struct adapter *padapter, struct recv_frame *precv_frame)
614 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
615 #ifdef CONFIG_88EU_P2P
616 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
617 u8 *pframe = precv_frame->rx_data;
620 #ifdef CONFIG_88EU_P2P
621 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ)) {
622 if (pwdinfo->tx_prov_disc_info.benable) {
623 if (!memcmp(pwdinfo->tx_prov_disc_info.peerIFAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
624 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
625 pwdinfo->tx_prov_disc_info.benable = false;
626 issue_p2p_provision_request(padapter,
627 pwdinfo->tx_prov_disc_info.ssid.Ssid,
628 pwdinfo->tx_prov_disc_info.ssid.SsidLength,
629 pwdinfo->tx_prov_disc_info.peerDevAddr);
630 } else if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_DEVICE) || rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
631 pwdinfo->tx_prov_disc_info.benable = false;
632 issue_p2p_provision_request(padapter, NULL, 0,
633 pwdinfo->tx_prov_disc_info.peerDevAddr);
638 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
639 if (pwdinfo->nego_req_info.benable) {
640 DBG_88E("[%s] P2P State is GONEGO ING!\n", __func__);
641 if (!memcmp(pwdinfo->nego_req_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
642 pwdinfo->nego_req_info.benable = false;
643 issue_p2p_GO_request(padapter, pwdinfo->nego_req_info.peerDevAddr);
646 } else if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_INVITE_REQ)) {
647 if (pwdinfo->invitereq_info.benable) {
648 DBG_88E("[%s] P2P_STATE_TX_INVITE_REQ!\n", __func__);
649 if (!memcmp(pwdinfo->invitereq_info.peer_macaddr, GetAddr2Ptr(pframe), ETH_ALEN)) {
650 pwdinfo->invitereq_info.benable = false;
651 issue_p2p_invitation_request(padapter, pwdinfo->invitereq_info.peer_macaddr);
658 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
659 report_survey_event(padapter, precv_frame);
666 unsigned int OnBeacon(struct adapter *padapter, struct recv_frame *precv_frame)
669 struct sta_info *psta;
670 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
671 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
672 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
673 struct sta_priv *pstapriv = &padapter->stapriv;
674 u8 *pframe = precv_frame->rx_data;
675 uint len = precv_frame->len;
676 struct wlan_bssid_ex *pbss;
679 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
680 report_survey_event(padapter, precv_frame);
684 if (!memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network), ETH_ALEN)) {
685 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
686 /* we should update current network before auth, or some IE is wrong */
687 pbss = (struct wlan_bssid_ex *)rtw_malloc(sizeof(struct wlan_bssid_ex));
689 if (collect_bss_info(padapter, precv_frame, pbss) == _SUCCESS) {
690 update_network(&(pmlmepriv->cur_network.network), pbss, padapter, true);
691 rtw_get_bcn_info(&(pmlmepriv->cur_network));
696 /* check the vendor of the assoc AP */
697 pmlmeinfo->assoc_AP_vendor = check_assoc_AP(pframe+sizeof(struct rtw_ieee80211_hdr_3addr), len-sizeof(struct rtw_ieee80211_hdr_3addr));
699 /* update TSF Value */
700 update_TSF(pmlmeext, pframe, len);
703 start_clnt_auth(padapter);
708 if (((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) && (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)) {
709 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
711 ret = rtw_check_bcn_info(padapter, pframe, len);
713 DBG_88E_LEVEL(_drv_info_, "ap has changed, disconnect now\n ");
714 receive_disconnect(padapter, pmlmeinfo->network.MacAddress , 65535);
717 /* update WMM, ERP in the beacon */
718 /* todo: the timer is used instead of the number of the beacon received */
719 if ((sta_rx_pkts(psta) & 0xf) == 0)
720 update_beacon_info(padapter, pframe, len, psta);
721 process_p2p_ps_ie(padapter, (pframe + WLAN_HDR_A3_LEN), (len - WLAN_HDR_A3_LEN));
723 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
724 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
726 /* update WMM, ERP in the beacon */
727 /* todo: the timer is used instead of the number of the beacon received */
728 if ((sta_rx_pkts(psta) & 0xf) == 0)
729 update_beacon_info(padapter, pframe, len, psta);
731 /* allocate a new CAM entry for IBSS station */
732 cam_idx = allocate_fw_sta_entry(padapter);
733 if (cam_idx == NUM_STA)
736 /* get supported rate */
737 if (update_sta_support_rate(padapter, (pframe + WLAN_HDR_A3_LEN + _BEACON_IE_OFFSET_), (len - WLAN_HDR_A3_LEN - _BEACON_IE_OFFSET_), cam_idx) == _FAIL) {
738 pmlmeinfo->FW_sta_info[cam_idx].status = 0;
742 /* update TSF Value */
743 update_TSF(pmlmeext, pframe, len);
745 /* report sta add event */
746 report_add_sta_event(padapter, GetAddr2Ptr(pframe), cam_idx);
756 unsigned int OnAuth(struct adapter *padapter, struct recv_frame *precv_frame)
758 #ifdef CONFIG_88EU_AP_MODE
759 unsigned int auth_mode, ie_len;
761 unsigned char *sa, *p;
764 static struct sta_info stat;
765 struct sta_info *pstat = NULL;
766 struct sta_priv *pstapriv = &padapter->stapriv;
767 struct security_priv *psecuritypriv = &padapter->securitypriv;
768 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
769 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
770 u8 *pframe = precv_frame->rx_data;
771 uint len = precv_frame->len;
773 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
776 DBG_88E("+OnAuth\n");
778 sa = GetAddr2Ptr(pframe);
780 auth_mode = psecuritypriv->dot11AuthAlgrthm;
781 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + 2));
782 algorithm = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN));
784 DBG_88E("auth alg=%x, seq=%X\n", algorithm, seq);
786 if (auth_mode == 2 && psecuritypriv->dot11PrivacyAlgrthm != _WEP40_ &&
787 psecuritypriv->dot11PrivacyAlgrthm != _WEP104_)
790 if ((algorithm > 0 && auth_mode == 0) || /* rx a shared-key auth but shared not enabled */
791 (algorithm == 0 && auth_mode == 1)) { /* rx a open-system auth but shared-key is enabled */
792 DBG_88E("auth rejected due to bad alg [alg=%d, auth_mib=%d] %02X%02X%02X%02X%02X%02X\n",
793 algorithm, auth_mode, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
795 status = _STATS_NO_SUPP_ALG_;
800 if (!rtw_access_ctrl(padapter, sa)) {
801 status = _STATS_UNABLE_HANDLE_STA_;
805 pstat = rtw_get_stainfo(pstapriv, sa);
807 /* allocate a new one */
808 DBG_88E("going to alloc stainfo for sa=%pM\n", sa);
809 pstat = rtw_alloc_stainfo(pstapriv, sa);
811 DBG_88E(" Exceed the upper limit of supported clients...\n");
812 status = _STATS_UNABLE_HANDLE_STA_;
816 pstat->state = WIFI_FW_AUTH_NULL;
819 spin_lock_bh(&pstapriv->asoc_list_lock);
820 if (!rtw_is_list_empty(&pstat->asoc_list)) {
821 rtw_list_delete(&pstat->asoc_list);
822 pstapriv->asoc_list_cnt--;
824 spin_unlock_bh(&pstapriv->asoc_list_lock);
827 /* TODO: STA re_auth and auth timeout */
831 spin_lock_bh(&pstapriv->auth_list_lock);
832 if (rtw_is_list_empty(&pstat->auth_list)) {
833 rtw_list_insert_tail(&pstat->auth_list, &pstapriv->auth_list);
834 pstapriv->auth_list_cnt++;
836 spin_unlock_bh(&pstapriv->auth_list_lock);
838 if (pstat->auth_seq == 0)
839 pstat->expire_to = pstapriv->auth_to;
841 if ((pstat->auth_seq + 1) != seq) {
842 DBG_88E("(1)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
843 seq, pstat->auth_seq+1);
844 status = _STATS_OUT_OF_AUTH_SEQ_;
848 if (algorithm == 0 && (auth_mode == 0 || auth_mode == 2)) {
850 pstat->state &= ~WIFI_FW_AUTH_NULL;
851 pstat->state |= WIFI_FW_AUTH_SUCCESS;
852 pstat->expire_to = pstapriv->assoc_to;
853 pstat->authalg = algorithm;
855 DBG_88E("(2)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
856 seq, pstat->auth_seq+1);
857 status = _STATS_OUT_OF_AUTH_SEQ_;
860 } else { /* shared system or auto authentication */
862 /* prepare for the challenging txt... */
864 pstat->state &= ~WIFI_FW_AUTH_NULL;
865 pstat->state |= WIFI_FW_AUTH_STATE;
866 pstat->authalg = algorithm;
868 } else if (seq == 3) {
869 /* checking for challenging txt... */
870 DBG_88E("checking for challenging txt...\n");
872 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + 4 + _AUTH_IE_OFFSET_ , _CHLGETXT_IE_, (int *)&ie_len,
873 len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_ - 4);
875 if ((p == NULL) || (ie_len <= 0)) {
876 DBG_88E("auth rejected because challenge failure!(1)\n");
877 status = _STATS_CHALLENGE_FAIL_;
881 if (!memcmp((void *)(p + 2), pstat->chg_txt, 128)) {
882 pstat->state &= (~WIFI_FW_AUTH_STATE);
883 pstat->state |= WIFI_FW_AUTH_SUCCESS;
884 /* challenging txt is correct... */
885 pstat->expire_to = pstapriv->assoc_to;
887 DBG_88E("auth rejected because challenge failure!\n");
888 status = _STATS_CHALLENGE_FAIL_;
892 DBG_88E("(3)auth rejected because out of seq [rx_seq=%d, exp_seq=%d]!\n",
893 seq, pstat->auth_seq+1);
894 status = _STATS_OUT_OF_AUTH_SEQ_;
899 /* Now, we are going to issue_auth... */
900 pstat->auth_seq = seq + 1;
902 #ifdef CONFIG_88EU_AP_MODE
903 issue_auth(padapter, pstat, (unsigned short)(_STATS_SUCCESSFUL_));
906 if (pstat->state & WIFI_FW_AUTH_SUCCESS)
914 rtw_free_stainfo(padapter , pstat);
917 _rtw_memset((char *)pstat, '\0', sizeof(stat));
919 memcpy(pstat->hwaddr, sa, 6);
921 #ifdef CONFIG_88EU_AP_MODE
922 issue_auth(padapter, pstat, (unsigned short)status);
929 unsigned int OnAuthClient(struct adapter *padapter, struct recv_frame *precv_frame)
931 unsigned int seq, len, status, offset;
933 unsigned int go2asoc = 0;
934 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
935 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
936 u8 *pframe = precv_frame->rx_data;
937 uint pkt_len = precv_frame->len;
939 DBG_88E("%s\n", __func__);
941 /* check A1 matches or not */
942 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
945 if (!(pmlmeinfo->state & WIFI_FW_AUTH_STATE))
948 offset = (GetPrivacy(pframe)) ? 4 : 0;
950 seq = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 2));
951 status = le16_to_cpu(*(__le16 *)((size_t)pframe + WLAN_HDR_A3_LEN + offset + 4));
954 DBG_88E("clnt auth fail, status: %d\n", status);
955 if (status == 13) { /* pmlmeinfo->auth_algo == dot11AuthAlgrthm_Auto) */
956 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
957 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Open;
959 pmlmeinfo->auth_algo = dot11AuthAlgrthm_Shared;
962 set_link_timer(pmlmeext, 1);
967 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) {
968 /* legendary shared system */
969 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + _AUTH_IE_OFFSET_, _CHLGETXT_IE_, (int *)&len,
970 pkt_len - WLAN_HDR_A3_LEN - _AUTH_IE_OFFSET_);
975 memcpy((void *)(pmlmeinfo->chg_txt), (void *)(p + 2), len);
976 pmlmeinfo->auth_seq = 3;
977 issue_auth(padapter, NULL, 0);
978 set_link_timer(pmlmeext, REAUTH_TO);
985 } else if (seq == 4) {
986 if (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared)
991 /* this is also illegal */
996 DBG_88E_LEVEL(_drv_info_, "auth success, start assoc\n");
997 start_clnt_assoc(padapter);
1004 unsigned int OnAssocReq(struct adapter *padapter, struct recv_frame *precv_frame)
1006 #ifdef CONFIG_88EU_AP_MODE
1008 struct rtw_ieee802_11_elems elems;
1009 struct sta_info *pstat;
1010 unsigned char reassoc, *p, *pos, *wpa_ie;
1011 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01};
1012 int i, ie_len, wpa_ie_len, left;
1013 unsigned char supportRate[16];
1015 unsigned short status = _STATS_SUCCESSFUL_;
1016 unsigned short frame_type, ie_offset = 0;
1017 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1018 struct security_priv *psecuritypriv = &padapter->securitypriv;
1019 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1020 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1021 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
1022 struct sta_priv *pstapriv = &padapter->stapriv;
1023 u8 *pframe = precv_frame->rx_data;
1024 uint pkt_len = precv_frame->len;
1025 #ifdef CONFIG_88EU_P2P
1026 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1027 u8 p2p_status_code = P2P_STATUS_SUCCESS;
1030 #endif /* CONFIG_88EU_P2P */
1032 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1035 frame_type = GetFrameSubType(pframe);
1036 if (frame_type == WIFI_ASSOCREQ) {
1038 ie_offset = _ASOCREQ_IE_OFFSET_;
1039 } else { /* WIFI_REASSOCREQ */
1041 ie_offset = _REASOCREQ_IE_OFFSET_;
1045 if (pkt_len < IEEE80211_3ADDR_LEN + ie_offset) {
1046 DBG_88E("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
1047 "\n", reassoc, (unsigned long)pkt_len);
1051 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1052 if (pstat == (struct sta_info *)NULL) {
1053 status = _RSON_CLS2_;
1054 goto asoc_class2_error;
1057 capab_info = RTW_GET_LE16(pframe + WLAN_HDR_A3_LEN);
1059 left = pkt_len - (IEEE80211_3ADDR_LEN + ie_offset);
1060 pos = pframe + (IEEE80211_3ADDR_LEN + ie_offset);
1063 DBG_88E("%s\n", __func__);
1065 /* check if this stat has been successfully authenticated/assocated */
1066 if (!((pstat->state) & WIFI_FW_AUTH_SUCCESS)) {
1067 if (!((pstat->state) & WIFI_FW_ASSOC_SUCCESS)) {
1068 status = _RSON_CLS2_;
1069 goto asoc_class2_error;
1071 pstat->state &= (~WIFI_FW_ASSOC_SUCCESS);
1072 pstat->state |= WIFI_FW_ASSOC_STATE;
1075 pstat->state &= (~WIFI_FW_AUTH_SUCCESS);
1076 pstat->state |= WIFI_FW_ASSOC_STATE;
1078 pstat->capability = capab_info;
1079 /* now parse all ieee802_11 ie to point to elems */
1080 if (rtw_ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
1082 DBG_88E("STA %pM sent invalid association request\n",
1084 status = _STATS_FAILURE_;
1085 goto OnAssocReqFail;
1089 /* now we should check all the fields... */
1091 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SSID_IE_, &ie_len,
1092 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1094 status = _STATS_FAILURE_;
1096 if (ie_len == 0) { /* broadcast ssid, however it is not allowed in assocreq */
1097 status = _STATS_FAILURE_;
1099 /* check if ssid match */
1100 if (memcmp((void *)(p+2), cur->Ssid.Ssid, cur->Ssid.SsidLength))
1101 status = _STATS_FAILURE_;
1103 if (ie_len != cur->Ssid.SsidLength)
1104 status = _STATS_FAILURE_;
1107 if (_STATS_SUCCESSFUL_ != status)
1108 goto OnAssocReqFail;
1110 /* check if the supported rate is ok */
1111 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _SUPPORTEDRATES_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1113 DBG_88E("Rx a sta assoc-req which supported rate is empty!\n");
1114 /* use our own rate set as statoin used */
1115 /* memcpy(supportRate, AP_BSSRATE, AP_BSSRATE_LEN); */
1116 /* supportRateNum = AP_BSSRATE_LEN; */
1118 status = _STATS_FAILURE_;
1119 goto OnAssocReqFail;
1121 memcpy(supportRate, p+2, ie_len);
1122 supportRateNum = ie_len;
1124 p = rtw_get_ie(pframe + WLAN_HDR_A3_LEN + ie_offset, _EXT_SUPPORTEDRATES_IE_ , &ie_len,
1125 pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1127 if (supportRateNum <= sizeof(supportRate)) {
1128 memcpy(supportRate+supportRateNum, p+2, ie_len);
1129 supportRateNum += ie_len;
1134 /* todo: mask supportRate between AP & STA -> move to update raid */
1135 /* get_matched_rate(pmlmeext, supportRate, &supportRateNum, 0); */
1137 /* update station supportRate */
1138 pstat->bssratelen = supportRateNum;
1139 memcpy(pstat->bssrateset, supportRate, supportRateNum);
1140 UpdateBrateTblForSoftAP(pstat->bssrateset, pstat->bssratelen);
1142 /* check RSN/WPA/WPS */
1143 pstat->dot8021xalg = 0;
1145 pstat->wpa_group_cipher = 0;
1146 pstat->wpa2_group_cipher = 0;
1147 pstat->wpa_pairwise_cipher = 0;
1148 pstat->wpa2_pairwise_cipher = 0;
1149 _rtw_memset(pstat->wpa_ie, 0, sizeof(pstat->wpa_ie));
1150 if ((psecuritypriv->wpa_psk & BIT(1)) && elems.rsn_ie) {
1151 int group_cipher = 0, pairwise_cipher = 0;
1153 wpa_ie = elems.rsn_ie;
1154 wpa_ie_len = elems.rsn_ie_len;
1156 if (rtw_parse_wpa2_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1157 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1158 pstat->wpa_psk |= BIT(1);
1160 pstat->wpa2_group_cipher = group_cipher&psecuritypriv->wpa2_group_cipher;
1161 pstat->wpa2_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa2_pairwise_cipher;
1163 if (!pstat->wpa2_group_cipher)
1164 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1166 if (!pstat->wpa2_pairwise_cipher)
1167 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1169 status = WLAN_STATUS_INVALID_IE;
1171 } else if ((psecuritypriv->wpa_psk & BIT(0)) && elems.wpa_ie) {
1172 int group_cipher = 0, pairwise_cipher = 0;
1174 wpa_ie = elems.wpa_ie;
1175 wpa_ie_len = elems.wpa_ie_len;
1177 if (rtw_parse_wpa_ie(wpa_ie-2, wpa_ie_len+2, &group_cipher, &pairwise_cipher, NULL) == _SUCCESS) {
1178 pstat->dot8021xalg = 1;/* psk, todo:802.1x */
1179 pstat->wpa_psk |= BIT(0);
1181 pstat->wpa_group_cipher = group_cipher&psecuritypriv->wpa_group_cipher;
1182 pstat->wpa_pairwise_cipher = pairwise_cipher&psecuritypriv->wpa_pairwise_cipher;
1184 if (!pstat->wpa_group_cipher)
1185 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1187 if (!pstat->wpa_pairwise_cipher)
1188 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1190 status = WLAN_STATUS_INVALID_IE;
1197 if (_STATS_SUCCESSFUL_ != status)
1198 goto OnAssocReqFail;
1200 pstat->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS);
1201 if (wpa_ie == NULL) {
1203 DBG_88E("STA included WPS IE in "
1204 "(Re)Association Request - assume WPS is "
1206 pstat->flags |= WLAN_STA_WPS;
1207 /* wpabuf_free(sta->wps_ie); */
1208 /* sta->wps_ie = wpabuf_alloc_copy(elems.wps_ie + 4, */
1209 /* elems.wps_ie_len - 4); */
1211 DBG_88E("STA did not include WPA/RSN IE "
1212 "in (Re)Association Request - possible WPS "
1214 pstat->flags |= WLAN_STA_MAYBE_WPS;
1218 /* AP support WPA/RSN, and sta is going to do WPS, but AP is not ready */
1219 /* that the selected registrar of AP is _FLASE */
1220 if ((psecuritypriv->wpa_psk > 0) && (pstat->flags & (WLAN_STA_WPS|WLAN_STA_MAYBE_WPS))) {
1221 if (pmlmepriv->wps_beacon_ie) {
1222 u8 selected_registrar = 0;
1224 rtw_get_wps_attr_content(pmlmepriv->wps_beacon_ie, pmlmepriv->wps_beacon_ie_len, WPS_ATTR_SELECTED_REGISTRAR , &selected_registrar, NULL);
1226 if (!selected_registrar) {
1227 DBG_88E("selected_registrar is false , or AP is not ready to do WPS\n");
1229 status = _STATS_UNABLE_HANDLE_STA_;
1231 goto OnAssocReqFail;
1238 if (psecuritypriv->wpa_psk == 0) {
1239 DBG_88E("STA %pM: WPA/RSN IE in association "
1240 "request, but AP don't support WPA/RSN\n", pstat->hwaddr);
1242 status = WLAN_STATUS_INVALID_IE;
1244 goto OnAssocReqFail;
1248 DBG_88E("STA included WPS IE in "
1249 "(Re)Association Request - WPS is "
1251 pstat->flags |= WLAN_STA_WPS;
1254 copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len+2);
1257 memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
1259 /* check if there is WMM IE & support WWM-PS */
1260 pstat->flags &= ~WLAN_STA_WME;
1261 pstat->qos_option = 0;
1262 pstat->qos_info = 0;
1263 pstat->has_legacy_ac = true;
1264 pstat->uapsd_vo = 0;
1265 pstat->uapsd_vi = 0;
1266 pstat->uapsd_be = 0;
1267 pstat->uapsd_bk = 0;
1268 if (pmlmepriv->qospriv.qos_option) {
1269 p = pframe + WLAN_HDR_A3_LEN + ie_offset; ie_len = 0;
1271 p = rtw_get_ie(p, _VENDOR_SPECIFIC_IE_, &ie_len, pkt_len - WLAN_HDR_A3_LEN - ie_offset);
1273 if (!memcmp(p+2, WMM_IE, 6)) {
1274 pstat->flags |= WLAN_STA_WME;
1276 pstat->qos_option = 1;
1277 pstat->qos_info = *(p+8);
1279 pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
1281 if ((pstat->qos_info&0xf) != 0xf)
1282 pstat->has_legacy_ac = true;
1284 pstat->has_legacy_ac = false;
1286 if (pstat->qos_info&0xf) {
1287 if (pstat->qos_info&BIT(0))
1288 pstat->uapsd_vo = BIT(0)|BIT(1);
1290 pstat->uapsd_vo = 0;
1292 if (pstat->qos_info&BIT(1))
1293 pstat->uapsd_vi = BIT(0)|BIT(1);
1295 pstat->uapsd_vi = 0;
1297 if (pstat->qos_info&BIT(2))
1298 pstat->uapsd_bk = BIT(0)|BIT(1);
1300 pstat->uapsd_bk = 0;
1302 if (pstat->qos_info&BIT(3))
1303 pstat->uapsd_be = BIT(0)|BIT(1);
1305 pstat->uapsd_be = 0;
1316 /* save HT capabilities in the sta object */
1317 _rtw_memset(&pstat->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
1318 if (elems.ht_capabilities && elems.ht_capabilities_len >= sizeof(struct rtw_ieee80211_ht_cap)) {
1319 pstat->flags |= WLAN_STA_HT;
1321 pstat->flags |= WLAN_STA_WME;
1323 memcpy(&pstat->htpriv.ht_cap, elems.ht_capabilities, sizeof(struct rtw_ieee80211_ht_cap));
1325 pstat->flags &= ~WLAN_STA_HT;
1327 if ((!pmlmepriv->htpriv.ht_option) && (pstat->flags&WLAN_STA_HT)) {
1328 status = _STATS_FAILURE_;
1329 goto OnAssocReqFail;
1332 if ((pstat->flags & WLAN_STA_HT) &&
1333 ((pstat->wpa2_pairwise_cipher&WPA_CIPHER_TKIP) ||
1334 (pstat->wpa_pairwise_cipher&WPA_CIPHER_TKIP))) {
1335 DBG_88E("HT: %pM tried to "
1336 "use TKIP with HT association\n", pstat->hwaddr);
1338 /* status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; */
1339 /* goto OnAssocReqFail; */
1342 pstat->flags |= WLAN_STA_NONERP;
1343 for (i = 0; i < pstat->bssratelen; i++) {
1344 if ((pstat->bssrateset[i] & 0x7f) > 22) {
1345 pstat->flags &= ~WLAN_STA_NONERP;
1350 if (pstat->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1351 pstat->flags |= WLAN_STA_SHORT_PREAMBLE;
1353 pstat->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1357 if (status != _STATS_SUCCESSFUL_)
1358 goto OnAssocReqFail;
1360 #ifdef CONFIG_88EU_P2P
1361 pstat->is_p2p_device = false;
1362 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
1363 p2pie = rtw_get_p2p_ie(pframe + WLAN_HDR_A3_LEN + ie_offset , pkt_len - WLAN_HDR_A3_LEN - ie_offset , NULL, &p2pielen);
1365 pstat->is_p2p_device = true;
1366 p2p_status_code = (u8)process_assoc_req_p2p_ie(pwdinfo, pframe, pkt_len, pstat);
1367 if (p2p_status_code > 0) {
1368 pstat->p2p_status_code = p2p_status_code;
1369 status = _STATS_CAP_FAIL_;
1370 goto OnAssocReqFail;
1374 pstat->p2p_status_code = p2p_status_code;
1375 #endif /* CONFIG_88EU_P2P */
1377 /* TODO: identify_proprietary_vendor_ie(); */
1378 /* Realtek proprietary IE */
1379 /* identify if this is Broadcom sta */
1380 /* identify if this is ralink sta */
1381 /* Customer proprietary IE */
1383 /* get a unique AID */
1384 if (pstat->aid > 0) {
1385 DBG_88E(" old AID %d\n", pstat->aid);
1387 for (pstat->aid = 1; pstat->aid <= NUM_STA; pstat->aid++)
1388 if (pstapriv->sta_aid[pstat->aid - 1] == NULL)
1391 /* if (pstat->aid > NUM_STA) { */
1392 if (pstat->aid > pstapriv->max_num_sta) {
1395 DBG_88E(" no room for more AIDs\n");
1397 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1399 goto OnAssocReqFail;
1401 pstapriv->sta_aid[pstat->aid - 1] = pstat;
1402 DBG_88E("allocate new AID=(%d)\n", pstat->aid);
1406 pstat->state &= (~WIFI_FW_ASSOC_STATE);
1407 pstat->state |= WIFI_FW_ASSOC_SUCCESS;
1409 spin_lock_bh(&pstapriv->auth_list_lock);
1410 if (!rtw_is_list_empty(&pstat->auth_list)) {
1411 rtw_list_delete(&pstat->auth_list);
1412 pstapriv->auth_list_cnt--;
1414 spin_unlock_bh(&pstapriv->auth_list_lock);
1416 spin_lock_bh(&pstapriv->asoc_list_lock);
1417 if (rtw_is_list_empty(&pstat->asoc_list)) {
1418 pstat->expire_to = pstapriv->expire_to;
1419 rtw_list_insert_tail(&pstat->asoc_list, &pstapriv->asoc_list);
1420 pstapriv->asoc_list_cnt++;
1422 spin_unlock_bh(&pstapriv->asoc_list_lock);
1424 /* now the station is qualified to join our BSS... */
1425 if (pstat && (pstat->state & WIFI_FW_ASSOC_SUCCESS) && (_STATS_SUCCESSFUL_ == status)) {
1426 #ifdef CONFIG_88EU_AP_MODE
1427 /* 1 bss_cap_update & sta_info_update */
1428 bss_cap_update_on_sta_join(padapter, pstat);
1429 sta_info_update(padapter, pstat);
1431 /* issue assoc rsp before notify station join event. */
1432 if (frame_type == WIFI_ASSOCREQ)
1433 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1435 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1437 /* 2 - report to upper layer */
1438 DBG_88E("indicate_sta_join_event to upper layer - hostapd\n");
1439 rtw_indicate_sta_assoc_event(padapter, pstat);
1441 /* 3-(1) report sta add event */
1442 report_add_sta_event(padapter, pstat->hwaddr, pstat->aid);
1450 #ifdef CONFIG_88EU_AP_MODE
1451 issue_deauth(padapter, (void *)GetAddr2Ptr(pframe), status);
1459 #ifdef CONFIG_88EU_AP_MODE
1461 if (frame_type == WIFI_ASSOCREQ)
1462 issue_asocrsp(padapter, status, pstat, WIFI_ASSOCRSP);
1464 issue_asocrsp(padapter, status, pstat, WIFI_REASSOCRSP);
1468 #endif /* CONFIG_88EU_AP_MODE */
1473 unsigned int OnAssocRsp(struct adapter *padapter, struct recv_frame *precv_frame)
1477 unsigned short status;
1478 struct ndis_802_11_var_ie *pIE;
1479 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1480 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1481 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1482 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */
1483 u8 *pframe = precv_frame->rx_data;
1484 uint pkt_len = precv_frame->len;
1486 DBG_88E("%s\n", __func__);
1488 /* check A1 matches or not */
1489 if (memcmp(myid(&(padapter->eeprompriv)), get_da(pframe), ETH_ALEN))
1492 if (!(pmlmeinfo->state & (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE)))
1495 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
1498 _cancel_timer_ex(&pmlmeext->link_timer);
1501 status = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 2));
1503 DBG_88E("assoc reject, status code: %d\n", status);
1504 pmlmeinfo->state = WIFI_FW_NULL_STATE;
1506 goto report_assoc_result;
1509 /* get capabilities */
1510 pmlmeinfo->capability = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1513 pmlmeinfo->slotTime = (pmlmeinfo->capability & BIT(10)) ? 9 : 20;
1516 pmlmeinfo->aid = (int)(le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN + 4))&0x3fff);
1517 res = pmlmeinfo->aid;
1519 /* following are moved to join event callback function */
1520 /* to handle HT, WMM, rate adaptive, update MAC reg */
1521 /* for not to handle the synchronous IO in the tasklet */
1522 for (i = (6 + WLAN_HDR_A3_LEN); i < pkt_len;) {
1523 pIE = (struct ndis_802_11_var_ie *)(pframe + i);
1525 switch (pIE->ElementID) {
1526 case _VENDOR_SPECIFIC_IE_:
1527 if (!memcmp(pIE->data, WMM_PARA_OUI, 6)) /* WMM */
1528 WMM_param_handler(padapter, pIE);
1530 case _HT_CAPABILITY_IE_: /* HT caps */
1531 HT_caps_handler(padapter, pIE);
1533 case _HT_EXTRA_INFO_IE_: /* HT info */
1534 HT_info_handler(padapter, pIE);
1537 ERP_IE_handler(padapter, pIE);
1542 i += (pIE->Length + 2);
1545 pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
1546 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
1548 /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
1549 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
1551 report_assoc_result:
1553 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
1555 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
1558 report_join_res(padapter, res);
1563 unsigned int OnDeAuth(struct adapter *padapter, struct recv_frame *precv_frame)
1565 unsigned short reason;
1566 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1567 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1568 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1569 u8 *pframe = precv_frame->rx_data;
1570 #ifdef CONFIG_88EU_P2P
1571 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1572 #endif /* CONFIG_88EU_P2P */
1575 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1579 #ifdef CONFIG_88EU_P2P
1580 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1581 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1582 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1584 #endif /* CONFIG_88EU_P2P */
1586 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1588 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1590 #ifdef CONFIG_88EU_AP_MODE
1591 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1592 struct sta_info *psta;
1593 struct sta_priv *pstapriv = &padapter->stapriv;
1595 DBG_88E_LEVEL(_drv_always_, "ap recv deauth reason code(%d) sta:%pM\n",
1596 reason, GetAddr2Ptr(pframe));
1598 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1602 spin_lock_bh(&pstapriv->asoc_list_lock);
1603 if (!rtw_is_list_empty(&psta->asoc_list)) {
1604 rtw_list_delete(&psta->asoc_list);
1605 pstapriv->asoc_list_cnt--;
1606 updated = ap_free_sta(padapter, psta, false, reason);
1608 spin_unlock_bh(&pstapriv->asoc_list_lock);
1610 associated_clients_update(padapter, updated);
1618 DBG_88E_LEVEL(_drv_always_, "sta recv deauth reason code(%d) sta:%pM\n",
1619 reason, GetAddr3Ptr(pframe));
1621 receive_disconnect(padapter, GetAddr3Ptr(pframe) , reason);
1623 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1627 unsigned int OnDisassoc(struct adapter *padapter, struct recv_frame *precv_frame)
1630 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1631 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1632 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1633 u8 *pframe = precv_frame->rx_data;
1634 #ifdef CONFIG_88EU_P2P
1635 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1636 #endif /* CONFIG_88EU_P2P */
1639 if (memcmp(GetAddr3Ptr(pframe), get_my_bssid(&pmlmeinfo->network),
1643 #ifdef CONFIG_88EU_P2P
1644 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
1645 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
1646 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
1648 #endif /* CONFIG_88EU_P2P */
1650 reason = le16_to_cpu(*(__le16 *)(pframe + WLAN_HDR_A3_LEN));
1652 DBG_88E("%s Reason code(%d)\n", __func__, reason);
1654 #ifdef CONFIG_88EU_AP_MODE
1655 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1656 struct sta_info *psta;
1657 struct sta_priv *pstapriv = &padapter->stapriv;
1659 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1660 reason, GetAddr2Ptr(pframe));
1662 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1666 spin_lock_bh(&pstapriv->asoc_list_lock);
1667 if (!rtw_is_list_empty(&psta->asoc_list)) {
1668 rtw_list_delete(&psta->asoc_list);
1669 pstapriv->asoc_list_cnt--;
1670 updated = ap_free_sta(padapter, psta, false, reason);
1672 spin_unlock_bh(&pstapriv->asoc_list_lock);
1674 associated_clients_update(padapter, updated);
1681 DBG_88E_LEVEL(_drv_always_, "ap recv disassoc reason code(%d) sta:%pM\n",
1682 reason, GetAddr3Ptr(pframe));
1684 receive_disconnect(padapter, GetAddr3Ptr(pframe), reason);
1686 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
1690 unsigned int OnAtim(struct adapter *padapter, struct recv_frame *precv_frame)
1692 DBG_88E("%s\n", __func__);
1696 unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame)
1698 unsigned int ret = _FAIL;
1699 struct sta_info *psta = NULL;
1700 struct sta_priv *pstapriv = &padapter->stapriv;
1701 u8 *pframe = precv_frame->rx_data;
1702 u8 *frame_body = (u8 *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1706 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1708 psta = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
1713 category = frame_body[0];
1714 if (category != RTW_WLAN_CATEGORY_SPECTRUM_MGMT)
1717 action = frame_body[1];
1719 case RTW_WLAN_ACTION_SPCT_MSR_REQ:
1720 case RTW_WLAN_ACTION_SPCT_MSR_RPRT:
1721 case RTW_WLAN_ACTION_SPCT_TPC_REQ:
1722 case RTW_WLAN_ACTION_SPCT_TPC_RPRT:
1724 case RTW_WLAN_ACTION_SPCT_CHL_SWITCH:
1734 unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame)
1739 unsigned int OnAction_dls(struct adapter *padapter, struct recv_frame *precv_frame)
1744 unsigned int OnAction_back(struct adapter *padapter, struct recv_frame *precv_frame)
1747 struct sta_info *psta = NULL;
1748 struct recv_reorder_ctrl *preorder_ctrl;
1749 unsigned char *frame_body;
1750 unsigned char category, action;
1751 unsigned short tid, status, reason_code = 0;
1752 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1753 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1754 u8 *pframe = precv_frame->rx_data;
1755 struct sta_priv *pstapriv = &padapter->stapriv;
1756 /* check RA matches or not */
1757 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe),
1758 ETH_ALEN))/* for if1, sta/ap mode */
1761 DBG_88E("%s\n", __func__);
1763 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1764 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
1767 addr = GetAddr2Ptr(pframe);
1768 psta = rtw_get_stainfo(pstapriv, addr);
1773 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
1775 category = frame_body[0];
1776 if (category == RTW_WLAN_CATEGORY_BACK) { /* representing Block Ack */
1777 if (!pmlmeinfo->HT_enable)
1779 action = frame_body[1];
1780 DBG_88E("%s, action=%d\n", __func__, action);
1782 case RTW_WLAN_ACTION_ADDBA_REQ: /* ADDBA request */
1783 memcpy(&(pmlmeinfo->ADDBA_req), &(frame_body[2]), sizeof(struct ADDBA_request));
1784 process_addba_req(padapter, (u8 *)&(pmlmeinfo->ADDBA_req), addr);
1786 if (pmlmeinfo->bAcceptAddbaReq)
1787 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 0);
1789 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_ADDBA_RESP, 37);/* reject ADDBA Req */
1791 case RTW_WLAN_ACTION_ADDBA_RESP: /* ADDBA response */
1792 status = RTW_GET_LE16(&frame_body[3]);
1793 tid = ((frame_body[5] >> 2) & 0x7);
1794 if (status == 0) { /* successful */
1795 DBG_88E("agg_enable for TID=%d\n", tid);
1796 psta->htpriv.agg_enable_bitmap |= 1 << tid;
1797 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
1799 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
1802 case RTW_WLAN_ACTION_DELBA: /* DELBA */
1803 if ((frame_body[3] & BIT(3)) == 0) {
1804 psta->htpriv.agg_enable_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1805 psta->htpriv.candidate_tid_bitmap &= ~(1 << ((frame_body[3] >> 4) & 0xf));
1806 reason_code = RTW_GET_LE16(&frame_body[4]);
1807 } else if ((frame_body[3] & BIT(3)) == BIT(3)) {
1808 tid = (frame_body[3] >> 4) & 0x0F;
1809 preorder_ctrl = &psta->recvreorder_ctrl[tid];
1810 preorder_ctrl->enable = false;
1811 preorder_ctrl->indicate_seq = 0xffff;
1813 DBG_88E("%s(): DELBA: %x(%x)\n", __func__, pmlmeinfo->agg_enable_bitmap, reason_code);
1814 /* todo: how to notify the host while receiving DELETE BA */
1823 #ifdef CONFIG_88EU_P2P
1825 static int get_reg_classes_full_count(struct p2p_channels *channel_list)
1830 for (i = 0; i < channel_list->reg_classes; i++) {
1831 cnt += channel_list->reg_class[i].channels;
1837 void issue_p2p_GO_request(struct adapter *padapter, u8 *raddr)
1839 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
1840 u8 action = P2P_PUB_ACTION_ACTION;
1841 __be32 p2poui = cpu_to_be32(P2POUI);
1842 u8 oui_subtype = P2P_GO_NEGO_REQ;
1843 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
1844 u8 wpsielen = 0, p2pielen = 0;
1845 u16 len_channellist_attr = 0;
1846 struct xmit_frame *pmgntframe;
1847 struct pkt_attrib *pattrib;
1848 unsigned char *pframe;
1849 struct rtw_ieee80211_hdr *pwlanhdr;
1851 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1852 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1853 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1855 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1856 if (pmgntframe == NULL)
1859 DBG_88E("[%s] In\n", __func__);
1860 /* update attribute */
1861 pattrib = &pmgntframe->attrib;
1862 update_mgntframe_attrib(padapter, pattrib);
1864 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
1866 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
1867 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
1869 fctrl = &(pwlanhdr->frame_ctl);
1872 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
1873 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
1874 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
1876 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
1877 pmlmeext->mgnt_seq++;
1878 SetFrameSubType(pframe, WIFI_ACTION);
1880 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
1881 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
1883 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
1884 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
1885 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
1886 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
1887 pwdinfo->negotiation_dialog_token = 1; /* Initialize the dialog value */
1888 pframe = rtw_set_fixed_ie(pframe, 1, &pwdinfo->negotiation_dialog_token, &(pattrib->pktlen));
1895 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
1900 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
1904 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
1908 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
1910 /* Device Password ID */
1912 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
1916 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
1921 if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN)
1922 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
1923 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN)
1924 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
1925 else if (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PBC)
1926 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
1930 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
1933 /* P2P IE Section. */
1937 p2pie[p2pielen++] = 0x50;
1938 p2pie[p2pielen++] = 0x6F;
1939 p2pie[p2pielen++] = 0x9A;
1940 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
1942 /* Commented by Albert 20110306 */
1943 /* According to the P2P Specification, the group negotiation request frame should contain 9 P2P attributes */
1944 /* 1. P2P Capability */
1945 /* 2. Group Owner Intent */
1946 /* 3. Configuration Timeout */
1947 /* 4. Listen Channel */
1948 /* 5. Extended Listen Timing */
1949 /* 6. Intended P2P Interface Address */
1950 /* 7. Channel List */
1951 /* 8. P2P Device Info */
1952 /* 9. Operating Channel */
1955 /* P2P Capability */
1957 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
1960 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1964 /* Device Capability Bitmap, 1 byte */
1965 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
1967 /* Group Capability Bitmap, 1 byte */
1968 if (pwdinfo->persistent_supported)
1969 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
1971 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
1973 /* Group Owner Intent */
1975 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
1978 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
1982 /* Todo the tie breaker bit. */
1983 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
1985 /* Configuration Timeout */
1987 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
1990 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
1994 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
1995 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
1998 /* Listen Channel */
2000 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
2003 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2007 /* Country String */
2008 p2pie[p2pielen++] = 'X';
2009 p2pie[p2pielen++] = 'X';
2011 /* The third byte should be set to 0x04. */
2012 /* Described in the "Operating Channel Attribute" section. */
2013 p2pie[p2pielen++] = 0x04;
2015 /* Operating Class */
2016 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
2018 /* Channel Number */
2019 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listening channel number */
2022 /* Extended Listen Timing ATTR */
2024 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
2027 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
2031 /* Availability Period */
2032 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2035 /* Availability Interval */
2036 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
2040 /* Intended P2P Interface Address */
2042 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2045 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2049 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2050 p2pielen += ETH_ALEN;
2055 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2058 /* Country String(3) */
2059 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2060 /* + number of channels in all classes */
2061 len_channellist_attr = 3
2062 + (1 + 1) * (u16)(pmlmeext->channel_list.reg_classes)
2063 + get_reg_classes_full_count(&pmlmeext->channel_list);
2065 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2069 /* Country String */
2070 p2pie[p2pielen++] = 'X';
2071 p2pie[p2pielen++] = 'X';
2073 /* The third byte should be set to 0x04. */
2074 /* Described in the "Operating Channel Attribute" section. */
2075 p2pie[p2pielen++] = 0x04;
2077 /* Channel Entry List */
2081 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2082 /* Operating Class */
2083 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2085 /* Number of Channels */
2086 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2089 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2090 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2097 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2100 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2101 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2102 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2106 /* P2P Device Address */
2107 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2108 p2pielen += ETH_ALEN;
2111 /* This field should be big endian. Noted by P2P specification. */
2113 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2117 /* Primary Device Type */
2119 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2123 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2126 /* Sub Category ID */
2127 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2130 /* Number of Secondary Device Types */
2131 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2135 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2139 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2143 memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
2144 p2pielen += pwdinfo->device_name_len;
2147 /* Operating Channel */
2149 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2152 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2156 /* Country String */
2157 p2pie[p2pielen++] = 'X';
2158 p2pie[p2pielen++] = 'X';
2160 /* The third byte should be set to 0x04. */
2161 /* Described in the "Operating Channel Attribute" section. */
2162 p2pie[p2pielen++] = 0x04;
2164 /* Operating Class */
2165 p2pie[p2pielen++] = 0x51;
2167 /* Channel Number */
2168 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2170 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2172 pattrib->last_txcmdsz = pattrib->pktlen;
2174 dump_mgntframe(padapter, pmgntframe);
2179 static void issue_p2p_GO_response(struct adapter *padapter, u8 *raddr, u8 *frame_body, uint len, u8 result)
2181 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2182 u8 action = P2P_PUB_ACTION_ACTION;
2183 __be32 p2poui = cpu_to_be32(P2POUI);
2184 u8 oui_subtype = P2P_GO_NEGO_RESP;
2185 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
2188 u16 wps_devicepassword_id = 0x0000;
2190 uint wps_devicepassword_id_len = 0;
2191 u16 len_channellist_attr = 0;
2193 struct xmit_frame *pmgntframe;
2194 struct pkt_attrib *pattrib;
2195 unsigned char *pframe;
2196 struct rtw_ieee80211_hdr *pwlanhdr;
2198 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2199 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2200 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2202 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2203 if (pmgntframe == NULL)
2206 DBG_88E("[%s] In, result=%d\n", __func__, result);
2207 /* update attribute */
2208 pattrib = &pmgntframe->attrib;
2209 update_mgntframe_attrib(padapter, pattrib);
2211 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2213 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2214 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2216 fctrl = &(pwlanhdr->frame_ctl);
2219 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2220 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2221 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2223 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2224 pmlmeext->mgnt_seq++;
2225 SetFrameSubType(pframe, WIFI_ACTION);
2227 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2228 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2230 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2231 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2232 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2233 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2234 pwdinfo->negotiation_dialog_token = frame_body[7]; /* The Dialog Token of provisioning discovery request frame. */
2235 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2237 /* Commented by Albert 20110328 */
2238 /* Try to get the device password ID from the WPS IE of group negotiation request frame */
2239 /* WiFi Direct test plan 5.1.15 */
2240 rtw_get_wps_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, wpsie, &wpsielen);
2241 rtw_get_wps_attr_content(wpsie, wpsielen, WPS_ATTR_DEVICE_PWID, (u8 *)&be_tmp, &wps_devicepassword_id_len);
2242 wps_devicepassword_id = be16_to_cpu(be_tmp);
2244 _rtw_memset(wpsie, 0x00, 255);
2250 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
2255 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
2259 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
2263 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
2265 /* Device Password ID */
2267 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
2271 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
2275 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2276 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC);
2277 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2278 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_USER_SPEC);
2280 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_PBC);
2283 /* Commented by Kurt 20120113 */
2284 /* If some device wants to do p2p handshake without sending prov_disc_req */
2285 /* We have to get peer_req_cm from here. */
2286 if (!memcmp(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "000", 3)) {
2287 if (wps_devicepassword_id == WPS_DPID_USER_SPEC)
2288 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "dis", 3);
2289 else if (wps_devicepassword_id == WPS_DPID_REGISTRAR_SPEC)
2290 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pad", 3);
2292 memcpy(pwdinfo->rx_prov_disc_info.strconfig_method_desc_of_prov_disc_req, "pbc", 3);
2295 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
2298 /* P2P IE Section. */
2302 p2pie[p2pielen++] = 0x50;
2303 p2pie[p2pielen++] = 0x6F;
2304 p2pie[p2pielen++] = 0x9A;
2305 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2307 /* Commented by Albert 20100908 */
2308 /* According to the P2P Specification, the group negotiation response frame should contain 9 P2P attributes */
2310 /* 2. P2P Capability */
2311 /* 3. Group Owner Intent */
2312 /* 4. Configuration Timeout */
2313 /* 5. Operating Channel */
2314 /* 6. Intended P2P Interface Address */
2315 /* 7. Channel List */
2316 /* 8. Device Info */
2317 /* 9. Group ID (Only GO) */
2324 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2327 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2331 p2pie[p2pielen++] = result;
2333 /* P2P Capability */
2335 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2338 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2342 /* Device Capability Bitmap, 1 byte */
2344 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2345 /* Commented by Albert 2011/03/08 */
2346 /* According to the P2P specification */
2347 /* if the sending device will be client, the P2P Capability should be reserved of group negotiation response frame */
2348 p2pie[p2pielen++] = 0;
2350 /* Be group owner or meet the error case */
2351 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2354 /* Group Capability Bitmap, 1 byte */
2355 if (pwdinfo->persistent_supported) {
2356 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2358 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2361 /* Group Owner Intent */
2363 p2pie[p2pielen++] = P2P_ATTR_GO_INTENT;
2366 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2370 if (pwdinfo->peer_intent & 0x01) {
2371 /* Peer's tie breaker bit is 1, our tie breaker bit should be 0 */
2372 p2pie[p2pielen++] = (pwdinfo->intent << 1);
2374 /* Peer's tie breaker bit is 0, our tie breaker bit should be 1 */
2375 p2pie[p2pielen++] = ((pwdinfo->intent << 1) | BIT(0));
2379 /* Configuration Timeout */
2381 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2384 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2388 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2389 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2391 /* Operating Channel */
2393 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2396 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2400 /* Country String */
2401 p2pie[p2pielen++] = 'X';
2402 p2pie[p2pielen++] = 'X';
2404 /* The third byte should be set to 0x04. */
2405 /* Described in the "Operating Channel Attribute" section. */
2406 p2pie[p2pielen++] = 0x04;
2408 /* Operating Class */
2409 p2pie[p2pielen++] = 0x51;
2411 /* Channel Number */
2412 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
2414 /* Intended P2P Interface Address */
2416 p2pie[p2pielen++] = P2P_ATTR_INTENTED_IF_ADDR;
2419 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2423 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2424 p2pielen += ETH_ALEN;
2428 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2430 /* Country String(3) */
2431 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2432 /* + number of channels in all classes */
2433 len_channellist_attr = 3
2434 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2435 + get_reg_classes_full_count(&pmlmeext->channel_list);
2437 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2442 /* Country String */
2443 p2pie[p2pielen++] = 'X';
2444 p2pie[p2pielen++] = 'X';
2446 /* The third byte should be set to 0x04. */
2447 /* Described in the "Operating Channel Attribute" section. */
2448 p2pie[p2pielen++] = 0x04;
2450 /* Channel Entry List */
2454 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2455 /* Operating Class */
2456 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2458 /* Number of Channels */
2459 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2462 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2463 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2470 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2473 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2474 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2475 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2479 /* P2P Device Address */
2480 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2481 p2pielen += ETH_ALEN;
2484 /* This field should be big endian. Noted by P2P specification. */
2486 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
2490 /* Primary Device Type */
2492 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2496 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2499 /* Sub Category ID */
2500 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2503 /* Number of Secondary Device Types */
2504 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2508 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2512 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2516 memcpy(p2pie + p2pielen, pwdinfo->device_name , pwdinfo->device_name_len);
2517 p2pielen += pwdinfo->device_name_len;
2519 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2520 /* Group ID Attribute */
2522 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2525 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2529 /* p2P Device Address */
2530 memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
2531 p2pielen += ETH_ALEN;
2534 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2535 p2pielen += pwdinfo->nego_ssidlen;
2538 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2540 pattrib->last_txcmdsz = pattrib->pktlen;
2542 dump_mgntframe(padapter, pmgntframe);
2546 static void issue_p2p_GO_confirm(struct adapter *padapter, u8 *raddr, u8 result)
2548 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2549 u8 action = P2P_PUB_ACTION_ACTION;
2550 __be32 p2poui = cpu_to_be32(P2POUI);
2551 u8 oui_subtype = P2P_GO_NEGO_CONF;
2552 u8 p2pie[255] = { 0x00 };
2555 struct xmit_frame *pmgntframe;
2556 struct pkt_attrib *pattrib;
2557 unsigned char *pframe;
2558 struct rtw_ieee80211_hdr *pwlanhdr;
2560 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2561 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2562 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2564 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2565 if (pmgntframe == NULL)
2568 DBG_88E("[%s] In\n", __func__);
2569 /* update attribute */
2570 pattrib = &pmgntframe->attrib;
2571 update_mgntframe_attrib(padapter, pattrib);
2573 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2575 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2576 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2578 fctrl = &(pwlanhdr->frame_ctl);
2581 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2582 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2583 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
2585 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2586 pmlmeext->mgnt_seq++;
2587 SetFrameSubType(pframe, WIFI_ACTION);
2589 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2590 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2592 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2593 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2594 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2595 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2596 pframe = rtw_set_fixed_ie(pframe, 1, &(pwdinfo->negotiation_dialog_token), &(pattrib->pktlen));
2600 /* P2P IE Section. */
2604 p2pie[p2pielen++] = 0x50;
2605 p2pie[p2pielen++] = 0x6F;
2606 p2pie[p2pielen++] = 0x9A;
2607 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2609 /* Commented by Albert 20110306 */
2610 /* According to the P2P Specification, the group negotiation request frame should contain 5 P2P attributes */
2612 /* 2. P2P Capability */
2613 /* 3. Operating Channel */
2614 /* 4. Channel List */
2615 /* 5. Group ID (if this WiFi is GO) */
2619 p2pie[p2pielen++] = P2P_ATTR_STATUS;
2622 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2626 p2pie[p2pielen++] = result;
2628 /* P2P Capability */
2630 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
2633 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2637 /* Device Capability Bitmap, 1 byte */
2638 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
2640 /* Group Capability Bitmap, 1 byte */
2641 if (pwdinfo->persistent_supported)
2642 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN | P2P_GRPCAP_PERSISTENT_GROUP;
2644 p2pie[p2pielen++] = P2P_GRPCAP_CROSS_CONN;
2646 /* Operating Channel */
2648 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2651 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
2655 /* Country String */
2656 p2pie[p2pielen++] = 'X';
2657 p2pie[p2pielen++] = 'X';
2659 /* The third byte should be set to 0x04. */
2660 /* Described in the "Operating Channel Attribute" section. */
2661 p2pie[p2pielen++] = 0x04;
2664 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_CLIENT)) {
2665 /* Operating Class */
2666 p2pie[p2pielen++] = 0x51;
2667 p2pie[p2pielen++] = pwdinfo->peer_operating_ch;
2669 /* Operating Class */
2670 p2pie[p2pielen++] = 0x51;
2672 /* Channel Number */
2673 p2pie[p2pielen++] = pwdinfo->operating_channel; /* Use the listen channel as the operating channel */
2679 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2682 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(pwdinfo->channel_list_attr_len);
2686 memcpy(p2pie + p2pielen, pwdinfo->channel_list_attr, pwdinfo->channel_list_attr_len);
2687 p2pielen += pwdinfo->channel_list_attr_len;
2689 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
2690 /* Group ID Attribute */
2692 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2695 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN + pwdinfo->nego_ssidlen);
2699 /* p2P Device Address */
2700 memcpy(p2pie + p2pielen , pwdinfo->device_addr, ETH_ALEN);
2701 p2pielen += ETH_ALEN;
2704 memcpy(p2pie + p2pielen, pwdinfo->nego_ssid, pwdinfo->nego_ssidlen);
2705 p2pielen += pwdinfo->nego_ssidlen;
2707 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2708 pattrib->last_txcmdsz = pattrib->pktlen;
2709 dump_mgntframe(padapter, pmgntframe);
2713 void issue_p2p_invitation_request(struct adapter *padapter, u8 *raddr)
2715 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2716 u8 action = P2P_PUB_ACTION_ACTION;
2717 __be32 p2poui = cpu_to_be32(P2POUI);
2718 u8 oui_subtype = P2P_INVIT_REQ;
2719 u8 p2pie[255] = { 0x00 };
2722 u16 len_channellist_attr = 0;
2723 struct xmit_frame *pmgntframe;
2724 struct pkt_attrib *pattrib;
2725 unsigned char *pframe;
2726 struct rtw_ieee80211_hdr *pwlanhdr;
2728 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2729 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2730 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2732 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2733 if (pmgntframe == NULL)
2736 /* update attribute */
2737 pattrib = &pmgntframe->attrib;
2738 update_mgntframe_attrib(padapter, pattrib);
2740 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2742 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2743 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2745 fctrl = &(pwlanhdr->frame_ctl);
2748 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
2749 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
2750 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
2752 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
2753 pmlmeext->mgnt_seq++;
2754 SetFrameSubType(pframe, WIFI_ACTION);
2756 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2757 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2759 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
2760 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
2761 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
2762 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
2763 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
2765 /* P2P IE Section. */
2769 p2pie[p2pielen++] = 0x50;
2770 p2pie[p2pielen++] = 0x6F;
2771 p2pie[p2pielen++] = 0x9A;
2772 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
2774 /* Commented by Albert 20101011 */
2775 /* According to the P2P Specification, the P2P Invitation request frame should contain 7 P2P attributes */
2776 /* 1. Configuration Timeout */
2777 /* 2. Invitation Flags */
2778 /* 3. Operating Channel (Only GO) */
2779 /* 4. P2P Group BSSID (Should be included if I am the GO) */
2780 /* 5. Channel List */
2781 /* 6. P2P Group ID */
2782 /* 7. P2P Device Info */
2784 /* Configuration Timeout */
2786 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
2789 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
2793 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
2794 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
2796 /* Invitation Flags */
2798 p2pie[p2pielen++] = P2P_ATTR_INVITATION_FLAGS;
2801 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
2805 p2pie[p2pielen++] = P2P_INVITATION_FLAGS_PERSISTENT;
2808 /* Operating Channel */
2810 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
2813 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
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 /* Operating Class */
2826 p2pie[p2pielen++] = 0x51;
2828 /* Channel Number */
2829 p2pie[p2pielen++] = pwdinfo->invitereq_info.operating_ch; /* operating channel number */
2831 if (!memcmp(myid(&padapter->eeprompriv),
2832 pwdinfo->invitereq_info.go_bssid, ETH_ALEN)) {
2833 /* P2P Group BSSID */
2835 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
2838 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
2842 /* P2P Device Address for GO */
2843 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2844 p2pielen += ETH_ALEN;
2849 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
2853 /* Country String(3) */
2854 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
2855 /* + number of channels in all classes */
2856 len_channellist_attr = 3
2857 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
2858 + get_reg_classes_full_count(&pmlmeext->channel_list);
2860 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
2865 /* Country String */
2866 p2pie[p2pielen++] = 'X';
2867 p2pie[p2pielen++] = 'X';
2869 /* The third byte should be set to 0x04. */
2870 /* Described in the "Operating Channel Attribute" section. */
2871 p2pie[p2pielen++] = 0x04;
2873 /* Channel Entry List */
2876 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
2877 /* Operating Class */
2878 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
2880 /* Number of Channels */
2881 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
2884 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
2885 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
2893 p2pie[p2pielen++] = P2P_ATTR_GROUP_ID;
2896 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(6 + pwdinfo->invitereq_info.ssidlen);
2900 /* P2P Device Address for GO */
2901 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_bssid, ETH_ALEN);
2902 p2pielen += ETH_ALEN;
2905 memcpy(p2pie + p2pielen, pwdinfo->invitereq_info.go_ssid, pwdinfo->invitereq_info.ssidlen);
2906 p2pielen += pwdinfo->invitereq_info.ssidlen;
2911 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
2914 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
2915 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
2916 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
2920 /* P2P Device Address */
2921 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
2922 p2pielen += ETH_ALEN;
2925 /* This field should be big endian. Noted by P2P specification. */
2926 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
2929 /* Primary Device Type */
2931 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
2935 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
2938 /* Sub Category ID */
2939 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
2942 /* Number of Secondary Device Types */
2943 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
2947 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
2951 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
2955 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
2956 p2pielen += pwdinfo->device_name_len;
2958 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
2960 pattrib->last_txcmdsz = pattrib->pktlen;
2962 dump_mgntframe(padapter, pmgntframe);
2967 void issue_p2p_invitation_response(struct adapter *padapter, u8 *raddr, u8 dialogToken, u8 status_code)
2969 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
2970 u8 action = P2P_PUB_ACTION_ACTION;
2971 __be32 p2poui = cpu_to_be32(P2POUI);
2972 u8 oui_subtype = P2P_INVIT_RESP;
2973 u8 p2pie[255] = { 0x00 };
2975 u16 len_channellist_attr = 0;
2976 struct xmit_frame *pmgntframe;
2977 struct pkt_attrib *pattrib;
2978 unsigned char *pframe;
2979 struct rtw_ieee80211_hdr *pwlanhdr;
2981 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2982 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2983 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
2985 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
2986 if (pmgntframe == NULL)
2989 /* update attribute */
2990 pattrib = &pmgntframe->attrib;
2991 update_mgntframe_attrib(padapter, pattrib);
2993 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
2995 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
2996 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
2998 fctrl = &(pwlanhdr->frame_ctl);
3001 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
3002 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3003 memcpy(pwlanhdr->addr3, raddr, ETH_ALEN);
3005 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3006 pmlmeext->mgnt_seq++;
3007 SetFrameSubType(pframe, WIFI_ACTION);
3009 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3010 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3012 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3013 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3014 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
3015 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3016 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
3018 /* P2P IE Section. */
3022 p2pie[p2pielen++] = 0x50;
3023 p2pie[p2pielen++] = 0x6F;
3024 p2pie[p2pielen++] = 0x9A;
3025 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
3027 /* Commented by Albert 20101005 */
3028 /* According to the P2P Specification, the P2P Invitation response frame should contain 5 P2P attributes */
3030 /* 2. Configuration Timeout */
3031 /* 3. Operating Channel (Only GO) */
3032 /* 4. P2P Group BSSID (Only GO) */
3033 /* 5. Channel List */
3037 p2pie[p2pielen++] = P2P_ATTR_STATUS;
3040 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0001);
3044 /* When status code is P2P_STATUS_FAIL_INFO_UNAVAILABLE. */
3045 /* Sent the event receiving the P2P Invitation Req frame to DMP UI. */
3046 /* DMP had to compare the MAC address to find out the profile. */
3047 /* So, the WiFi driver will send the P2P_STATUS_FAIL_INFO_UNAVAILABLE to NB. */
3048 /* If the UI found the corresponding profile, the WiFi driver sends the P2P Invitation Req */
3049 /* to NB to rebuild the persistent group. */
3050 p2pie[p2pielen++] = status_code;
3052 /* Configuration Timeout */
3054 p2pie[p2pielen++] = P2P_ATTR_CONF_TIMEOUT;
3057 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3061 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P GO */
3062 p2pie[p2pielen++] = 200; /* 2 seconds needed to be the P2P Client */
3064 if (status_code == P2P_STATUS_SUCCESS) {
3065 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3066 /* The P2P Invitation request frame asks this Wi-Fi device to be the P2P GO */
3067 /* In this case, the P2P Invitation response frame should carry the two more P2P attributes. */
3068 /* First one is operating channel attribute. */
3069 /* Second one is P2P Group BSSID attribute. */
3071 /* Operating Channel */
3073 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3076 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3080 /* Country String */
3081 p2pie[p2pielen++] = 'X';
3082 p2pie[p2pielen++] = 'X';
3084 /* The third byte should be set to 0x04. */
3085 /* Described in the "Operating Channel Attribute" section. */
3086 p2pie[p2pielen++] = 0x04;
3088 /* Operating Class */
3089 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3091 /* Channel Number */
3092 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3095 /* P2P Group BSSID */
3097 p2pie[p2pielen++] = P2P_ATTR_GROUP_BSSID;
3100 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(ETH_ALEN);
3104 /* P2P Device Address for GO */
3105 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
3106 p2pielen += ETH_ALEN;
3111 p2pie[p2pielen++] = P2P_ATTR_CH_LIST;
3114 /* Country String(3) */
3115 /* + (Operating Class (1) + Number of Channels(1)) * Operation Classes (?) */
3116 /* + number of channels in all classes */
3117 len_channellist_attr = 3
3118 + (1 + 1) * (u16)pmlmeext->channel_list.reg_classes
3119 + get_reg_classes_full_count(&pmlmeext->channel_list);
3121 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(len_channellist_attr);
3125 /* Country String */
3126 p2pie[p2pielen++] = 'X';
3127 p2pie[p2pielen++] = 'X';
3129 /* The third byte should be set to 0x04. */
3130 /* Described in the "Operating Channel Attribute" section. */
3131 p2pie[p2pielen++] = 0x04;
3133 /* Channel Entry List */
3136 for (j = 0; j < pmlmeext->channel_list.reg_classes; j++) {
3137 /* Operating Class */
3138 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].reg_class;
3140 /* Number of Channels */
3141 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channels;
3144 for (i = 0; i < pmlmeext->channel_list.reg_class[j].channels; i++) {
3145 p2pie[p2pielen++] = pmlmeext->channel_list.reg_class[j].channel[i];
3151 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3153 pattrib->last_txcmdsz = pattrib->pktlen;
3155 dump_mgntframe(padapter, pmgntframe);
3160 void issue_p2p_provision_request(struct adapter *padapter, u8 *pssid, u8 ussidlen, u8 *pdev_raddr)
3162 unsigned char category = RTW_WLAN_CATEGORY_PUBLIC;
3163 u8 action = P2P_PUB_ACTION_ACTION;
3165 u8 oui_subtype = P2P_PROVISION_DISC_REQ;
3166 u8 wpsie[100] = { 0x00 };
3168 __be32 p2poui = cpu_to_be32(P2POUI);
3170 struct xmit_frame *pmgntframe;
3171 struct pkt_attrib *pattrib;
3172 unsigned char *pframe;
3173 struct rtw_ieee80211_hdr *pwlanhdr;
3175 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3176 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3177 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3179 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3180 if (pmgntframe == NULL)
3183 DBG_88E("[%s] In\n", __func__);
3184 /* update attribute */
3185 pattrib = &pmgntframe->attrib;
3186 update_mgntframe_attrib(padapter, pattrib);
3188 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3190 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3191 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3193 fctrl = &(pwlanhdr->frame_ctl);
3196 memcpy(pwlanhdr->addr1, pdev_raddr, ETH_ALEN);
3197 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
3198 memcpy(pwlanhdr->addr3, pdev_raddr, ETH_ALEN);
3200 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3201 pmlmeext->mgnt_seq++;
3202 SetFrameSubType(pframe, WIFI_ACTION);
3204 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
3205 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3207 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3208 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3209 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&(p2poui), &(pattrib->pktlen));
3210 pframe = rtw_set_fixed_ie(pframe, 1, &(oui_subtype), &(pattrib->pktlen));
3211 pframe = rtw_set_fixed_ie(pframe, 1, &(dialogToken), &(pattrib->pktlen));
3213 p2pielen = build_prov_disc_request_p2p_ie(pwdinfo, pframe, pssid, ussidlen, pdev_raddr);
3216 pattrib->pktlen += p2pielen;
3220 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3225 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3229 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3233 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3237 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3241 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3245 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->tx_prov_disc_info.wps_config_method_request);
3248 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3250 pattrib->last_txcmdsz = pattrib->pktlen;
3252 dump_mgntframe(padapter, pmgntframe);
3257 static u8 is_matched_in_profilelist(u8 *peermacaddr, struct profile_info *profileinfo)
3259 u8 i, match_result = 0;
3261 DBG_88E("[%s] peermac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3262 peermacaddr[0], peermacaddr[1], peermacaddr[2], peermacaddr[3], peermacaddr[4], peermacaddr[5]);
3264 for (i = 0; i < P2P_MAX_PERSISTENT_GROUP_NUM; i++, profileinfo++) {
3265 DBG_88E("[%s] profileinfo_mac=%.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
3266 profileinfo->peermac[0], profileinfo->peermac[1], profileinfo->peermac[2], profileinfo->peermac[3], profileinfo->peermac[4], profileinfo->peermac[5]);
3267 if (!memcmp(peermacaddr, profileinfo->peermac, ETH_ALEN)) {
3269 DBG_88E("[%s] Match!\n", __func__);
3273 return match_result;
3276 void issue_probersp_p2p(struct adapter *padapter, unsigned char *da)
3278 struct xmit_frame *pmgntframe;
3279 struct pkt_attrib *pattrib;
3280 unsigned char *pframe;
3281 struct rtw_ieee80211_hdr *pwlanhdr;
3284 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3285 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3286 u16 beacon_interval = 100;
3288 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3289 u8 wpsie[255] = { 0x00 };
3290 u32 wpsielen = 0, p2pielen = 0;
3292 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3293 if (pmgntframe == NULL)
3296 /* update attribute */
3297 pattrib = &pmgntframe->attrib;
3298 update_mgntframe_attrib(padapter, pattrib);
3300 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3302 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3303 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3305 mac = myid(&(padapter->eeprompriv));
3307 fctrl = &(pwlanhdr->frame_ctl);
3309 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3310 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3312 /* Use the device address for BSSID field. */
3313 memcpy(pwlanhdr->addr3, mac, ETH_ALEN);
3315 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3316 pmlmeext->mgnt_seq++;
3317 SetFrameSubType(fctrl, WIFI_PROBERSP);
3319 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
3320 pattrib->pktlen = pattrib->hdrlen;
3321 pframe += pattrib->hdrlen;
3323 /* timestamp will be inserted by hardware */
3325 pattrib->pktlen += 8;
3327 /* beacon interval: 2 bytes */
3328 memcpy(pframe, (unsigned char *)&beacon_interval, 2);
3330 pattrib->pktlen += 2;
3332 /* capability info: 2 bytes */
3333 /* ESS and IBSS bits must be 0 (defined in the 3.1.2.1.1 of WiFi Direct Spec) */
3334 capInfo |= cap_ShortPremble;
3335 capInfo |= cap_ShortSlot;
3337 memcpy(pframe, (unsigned char *)&capInfo, 2);
3339 pattrib->pktlen += 2;
3343 pframe = rtw_set_ie(pframe, _SSID_IE_, 7, pwdinfo->p2p_wildcard_ssid, &pattrib->pktlen);
3345 /* supported rates... */
3346 /* Use the OFDM rate in the P2P probe response frame. (6(B), 9(B), 12, 18, 24, 36, 48, 54) */
3347 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3349 /* DS parameter set */
3350 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&pwdinfo->listen_channel, &pattrib->pktlen);
3353 /* Noted by Albert 20100907 */
3354 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3358 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3363 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3367 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3371 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3373 /* WiFi Simple Config State */
3375 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SIMPLE_CONF_STATE);
3379 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3383 wpsie[wpsielen++] = WPS_WSC_STATE_NOT_CONFIG; /* Not Configured. */
3387 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_RESP_TYPE);
3391 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3395 wpsie[wpsielen++] = WPS_RESPONSE_TYPE_8021X;
3399 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3403 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3407 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3412 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MANUFACTURER);
3416 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0007);
3420 memcpy(wpsie + wpsielen, "Realtek", 7);
3425 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NAME);
3429 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0006);
3433 memcpy(wpsie + wpsielen, "8188EU", 6);
3438 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_MODEL_NUMBER);
3442 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3446 wpsie[wpsielen++] = 0x31; /* character 1 */
3450 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_SERIAL_NUMBER);
3454 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(ETH_ALEN);
3458 memcpy(wpsie + wpsielen, "123456" , ETH_ALEN);
3459 wpsielen += ETH_ALEN;
3461 /* Primary Device Type */
3463 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3467 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3472 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
3476 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3479 /* Sub Category ID */
3480 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
3485 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3489 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3493 if (pwdinfo->device_name_len) {
3494 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3495 wpsielen += pwdinfo->device_name_len;
3500 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3504 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3508 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3512 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3515 p2pielen = build_probe_resp_p2p_ie(pwdinfo, pframe);
3517 pattrib->pktlen += p2pielen;
3519 pattrib->last_txcmdsz = pattrib->pktlen;
3521 dump_mgntframe(padapter, pmgntframe);
3526 static int _issue_probereq_p2p(struct adapter *padapter, u8 *da, int wait_ack)
3529 struct xmit_frame *pmgntframe;
3530 struct pkt_attrib *pattrib;
3531 unsigned char *pframe;
3532 struct rtw_ieee80211_hdr *pwlanhdr;
3535 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
3536 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
3537 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3538 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3539 u8 wpsie[255] = { 0x00 }, p2pie[255] = { 0x00 };
3540 u16 wpsielen = 0, p2pielen = 0;
3541 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
3543 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
3544 if (pmgntframe == NULL)
3547 /* update attribute */
3548 pattrib = &pmgntframe->attrib;
3549 update_mgntframe_attrib(padapter, pattrib);
3552 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
3554 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
3555 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
3557 mac = myid(&(padapter->eeprompriv));
3559 fctrl = &(pwlanhdr->frame_ctl);
3563 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
3564 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
3566 if ((pwdinfo->p2p_info.scan_op_ch_only) || (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
3567 /* This two flags will be set when this is only the P2P client mode. */
3568 memcpy(pwlanhdr->addr1, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3569 memcpy(pwlanhdr->addr3, pwdinfo->p2p_peer_interface_addr, ETH_ALEN);
3571 /* broadcast probe request frame */
3572 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
3573 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
3576 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
3578 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
3579 pmlmeext->mgnt_seq++;
3580 SetFrameSubType(pframe, WIFI_PROBEREQ);
3582 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
3583 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
3585 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_TX_PROVISION_DIS_REQ))
3586 pframe = rtw_set_ie(pframe, _SSID_IE_, pwdinfo->tx_prov_disc_info.ssid.SsidLength, pwdinfo->tx_prov_disc_info.ssid.Ssid, &(pattrib->pktlen));
3588 pframe = rtw_set_ie(pframe, _SSID_IE_, P2P_WILDCARD_SSID_LEN, pwdinfo->p2p_wildcard_ssid, &(pattrib->pktlen));
3590 /* Use the OFDM rate in the P2P probe request frame. (6(B), 9(B), 12(B), 24(B), 36, 48, 54) */
3591 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pwdinfo->support_rate, &pattrib->pktlen);
3595 /* Noted by Albert 20110221 */
3596 /* According to the WPS specification, all the WPS attribute is presented by Big Endian. */
3600 *(__be32 *)(wpsie) = cpu_to_be32(WPSOUI);
3605 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_VER1);
3609 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0001);
3613 wpsie[wpsielen++] = WPS_VERSION_1; /* Version 1.0 */
3615 if (pmlmepriv->wps_probe_req_ie == NULL) {
3618 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_UUID_E);
3622 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0010);
3626 memcpy(wpsie + wpsielen, myid(&padapter->eeprompriv), ETH_ALEN);
3631 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_CONF_METHOD);
3635 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3639 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->supported_wps_cm);
3645 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
3649 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(pwdinfo->device_name_len);
3653 memcpy(wpsie + wpsielen, pwdinfo->device_name, pwdinfo->device_name_len);
3654 wpsielen += pwdinfo->device_name_len;
3656 /* Primary Device Type */
3658 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
3662 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0008);
3667 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_CID_RTK_WIDI);
3671 *(__be32 *)(wpsie + wpsielen) = cpu_to_be32(WPSOUI);
3674 /* Sub Category ID */
3675 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_PDT_SCID_RTK_DMP);
3678 /* Device Password ID */
3680 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_ATTR_DEVICE_PWID);
3684 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(0x0002);
3688 *(__be16 *)(wpsie + wpsielen) = cpu_to_be16(WPS_DPID_REGISTRAR_SPEC); /* Registrar-specified */
3691 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wpsielen, (unsigned char *)wpsie, &pattrib->pktlen);
3695 p2pie[p2pielen++] = 0x50;
3696 p2pie[p2pielen++] = 0x6F;
3697 p2pie[p2pielen++] = 0x9A;
3698 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
3700 /* Commented by Albert 20110221 */
3701 /* According to the P2P Specification, the probe request frame should contain 5 P2P attributes */
3702 /* 1. P2P Capability */
3703 /* 2. P2P Device ID if this probe request wants to find the specific P2P device */
3704 /* 3. Listen Channel */
3705 /* 4. Extended Listen Timing */
3706 /* 5. Operating Channel if this WiFi is working as the group owner now */
3708 /* P2P Capability */
3710 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
3713 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
3717 /* Device Capability Bitmap, 1 byte */
3718 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
3720 /* Group Capability Bitmap, 1 byte */
3721 if (pwdinfo->persistent_supported)
3722 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
3724 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
3726 /* Listen Channel */
3728 p2pie[p2pielen++] = P2P_ATTR_LISTEN_CH;
3731 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3735 /* Country String */
3736 p2pie[p2pielen++] = 'X';
3737 p2pie[p2pielen++] = 'X';
3739 /* The third byte should be set to 0x04. */
3740 /* Described in the "Operating Channel Attribute" section. */
3741 p2pie[p2pielen++] = 0x04;
3743 /* Operating Class */
3744 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3746 /* Channel Number */
3747 p2pie[p2pielen++] = pwdinfo->listen_channel; /* listen channel */
3750 /* Extended Listen Timing */
3752 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
3755 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
3759 /* Availability Period */
3760 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3763 /* Availability Interval */
3764 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
3767 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
3768 /* Operating Channel (if this WiFi is working as the group owner now) */
3770 p2pie[p2pielen++] = P2P_ATTR_OPERATING_CH;
3773 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0005);
3777 /* Country String */
3778 p2pie[p2pielen++] = 'X';
3779 p2pie[p2pielen++] = 'X';
3781 /* The third byte should be set to 0x04. */
3782 /* Described in the "Operating Channel Attribute" section. */
3783 p2pie[p2pielen++] = 0x04;
3785 /* Operating Class */
3786 p2pie[p2pielen++] = 0x51; /* Copy from SD7 */
3788 /* Channel Number */
3789 p2pie[p2pielen++] = pwdinfo->operating_channel; /* operating channel number */
3792 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
3794 if (pmlmepriv->wps_probe_req_ie != NULL) {
3796 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
3797 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
3798 pframe += pmlmepriv->wps_probe_req_ie_len;
3801 pattrib->last_txcmdsz = pattrib->pktlen;
3803 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
3806 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
3808 dump_mgntframe(padapter, pmgntframe);
3816 inline void issue_probereq_p2p(struct adapter *adapter, u8 *da)
3818 _issue_probereq_p2p(adapter, da, false);
3821 int issue_probereq_p2p_ex(struct adapter *adapter, u8 *da, int try_cnt, int wait_ms)
3825 u32 start = jiffies;
3828 ret = _issue_probereq_p2p(adapter, da, wait_ms > 0 ? true : false);
3832 if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
3835 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
3837 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
3844 if (try_cnt && wait_ms) {
3846 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
3847 FUNC_ADPT_ARG(adapter), da, rtw_get_oper_ch(adapter),
3848 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3850 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
3851 FUNC_ADPT_ARG(adapter), rtw_get_oper_ch(adapter),
3852 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
3858 #endif /* CONFIG_88EU_P2P */
3860 static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
3862 struct adapter *adapter = recv_frame->adapter;
3863 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3864 u8 *frame = recv_frame->rx_data;
3865 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) |
3866 (recv_frame->attrib.frag_num & 0xf);
3868 if (GetRetry(frame)) {
3870 if ((seq_ctrl == mlmeext->action_public_rxseq) && (token == mlmeext->action_public_dialog_token)) {
3871 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x, token:%d\n",
3872 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq, token);
3876 if (seq_ctrl == mlmeext->action_public_rxseq) {
3877 DBG_88E(FUNC_ADPT_FMT" seq_ctrl = 0x%x, rxseq = 0x%x\n",
3878 FUNC_ADPT_ARG(adapter), seq_ctrl, mlmeext->action_public_rxseq);
3884 mlmeext->action_public_rxseq = seq_ctrl;
3887 mlmeext->action_public_dialog_token = token;
3892 static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
3894 u8 *pframe = precv_frame->rx_data;
3897 #ifdef CONFIG_88EU_P2P
3898 struct adapter *padapter = precv_frame->adapter;
3899 uint len = precv_frame->len;
3902 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
3903 u8 result = P2P_STATUS_SUCCESS;
3904 u8 empty_addr[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3905 #endif /* CONFIG_88EU_P2P */
3907 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
3909 dialogToken = frame_body[7];
3911 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
3914 #ifdef CONFIG_88EU_P2P
3915 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
3916 /* Do nothing if the driver doesn't enable the P2P function. */
3917 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE))
3920 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
3922 switch (frame_body[6]) { /* OUI Subtype */
3923 case P2P_GO_NEGO_REQ:
3924 DBG_88E("[%s] Got GO Nego Req Frame\n", __func__);
3925 _rtw_memset(&pwdinfo->groupid_info, 0x00, sizeof(struct group_id_info));
3927 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
3928 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3930 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL)) {
3931 /* Commented by Albert 20110526 */
3932 /* In this case, this means the previous nego fail doesn't be reset yet. */
3933 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3934 /* Restore the previous p2p state */
3935 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
3936 DBG_88E("[%s] Restore the previous p2p state to %d\n", __func__, rtw_p2p_state(pwdinfo));
3939 /* Commented by Kurt 20110902 */
3940 /* Add if statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
3941 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING))
3942 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
3944 /* Commented by Kurt 20120113 */
3945 /* Get peer_dev_addr here if peer doesn't issue prov_disc frame. */
3946 if (!memcmp(pwdinfo->rx_prov_disc_info.peerDevAddr, empty_addr,
3948 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
3950 result = process_p2p_group_negotation_req(pwdinfo, frame_body, len);
3951 issue_p2p_GO_response(padapter, GetAddr2Ptr(pframe), frame_body, len, result);
3953 /* Commented by Albert 20110718 */
3954 /* No matter negotiating or negotiation failure, the driver should set up the restore P2P state timer. */
3955 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3957 case P2P_GO_NEGO_RESP:
3958 DBG_88E("[%s] Got GO Nego Resp Frame\n", __func__);
3960 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_ING)) {
3961 /* Commented by Albert 20110425 */
3962 /* The restore timer is enabled when issuing the nego request frame of rtw_p2p_connect function. */
3963 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
3964 pwdinfo->nego_req_info.benable = false;
3965 result = process_p2p_group_negotation_resp(pwdinfo, frame_body, len);
3966 issue_p2p_GO_confirm(pwdinfo->padapter, GetAddr2Ptr(pframe), result);
3967 if (P2P_STATUS_SUCCESS == result) {
3968 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3969 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3970 pwdinfo->p2p_info.scan_op_ch_only = 1;
3971 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3974 /* Reset the dialog token for group negotiation frames. */
3975 pwdinfo->negotiation_dialog_token = 1;
3976 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_GONEGO_FAIL))
3977 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
3979 DBG_88E("[%s] Skipped GO Nego Resp Frame (p2p_state != P2P_STATE_GONEGO_ING)\n", __func__);
3982 case P2P_GO_NEGO_CONF:
3983 DBG_88E("[%s] Got GO Nego Confirm Frame\n", __func__);
3984 result = process_p2p_group_negotation_confirm(pwdinfo, frame_body, len);
3985 if (P2P_STATUS_SUCCESS == result) {
3986 if (rtw_p2p_role(pwdinfo) == P2P_ROLE_CLIENT) {
3987 pwdinfo->p2p_info.operation_ch[0] = pwdinfo->peer_operating_ch;
3988 pwdinfo->p2p_info.scan_op_ch_only = 1;
3989 _set_timer(&pwdinfo->reset_ch_sitesurvey2, P2P_RESET_SCAN_CH);
3994 /* Added by Albert 2010/10/05 */
3995 /* Received the P2P Invite Request frame. */
3997 DBG_88E("[%s] Got invite request frame!\n", __func__);
3998 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
4000 /* Parse the necessary information from the P2P Invitation Request frame. */
4001 /* For example: The MAC address of sending this P2P Invitation Request frame. */
4002 u32 attr_contentlen = 0;
4003 u8 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4004 struct group_id_info group_id;
4005 u8 invitation_flag = 0;
4007 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_INVITATION_FLAGS, &invitation_flag, &attr_contentlen);
4008 if (attr_contentlen) {
4009 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_BSSID, pwdinfo->p2p_peer_interface_addr, &attr_contentlen);
4010 /* Commented by Albert 20120510 */
4011 /* Copy to the pwdinfo->p2p_peer_interface_addr. */
4012 /* So that the WFD UI (or Sigma) can get the peer interface address by using the following command. */
4013 /* #> iwpriv wlan0 p2p_get peer_ifa */
4014 /* After having the peer interface address, the sigma can find the correct conf file for wpa_supplicant. */
4016 if (attr_contentlen) {
4017 DBG_88E("[%s] GO's BSSID = %.2X %.2X %.2X %.2X %.2X %.2X\n", __func__,
4018 pwdinfo->p2p_peer_interface_addr[0], pwdinfo->p2p_peer_interface_addr[1],
4019 pwdinfo->p2p_peer_interface_addr[2], pwdinfo->p2p_peer_interface_addr[3],
4020 pwdinfo->p2p_peer_interface_addr[4], pwdinfo->p2p_peer_interface_addr[5]);
4023 if (invitation_flag & P2P_INVITATION_FLAGS_PERSISTENT) {
4024 /* Re-invoke the persistent group. */
4026 _rtw_memset(&group_id, 0x00, sizeof(struct group_id_info));
4027 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
4028 if (attr_contentlen) {
4029 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
4030 /* The p2p device sending this p2p invitation request wants this Wi-Fi device to be the persistent GO. */
4031 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_GO);
4032 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
4033 status_code = P2P_STATUS_SUCCESS;
4035 /* The p2p device sending this p2p invitation request wants to be the persistent GO. */
4036 if (is_matched_in_profilelist(pwdinfo->p2p_peer_interface_addr, &pwdinfo->profileinfo[0])) {
4037 u8 operatingch_info[5] = { 0x00 };
4038 if (rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_OPERATING_CH, operatingch_info, &attr_contentlen)) {
4039 if (rtw_ch_set_search_ch(padapter->mlmeextpriv.channel_set, (u32)operatingch_info[4])) {
4040 /* The operating channel is acceptable for this device. */
4041 pwdinfo->rx_invitereq_info.operation_ch[0] = operatingch_info[4];
4042 pwdinfo->rx_invitereq_info.scan_op_ch_only = 1;
4043 _set_timer(&pwdinfo->reset_ch_sitesurvey, P2P_RESET_SCAN_CH);
4044 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
4045 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4046 status_code = P2P_STATUS_SUCCESS;
4048 /* The operating channel isn't supported by this device. */
4049 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4050 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4051 status_code = P2P_STATUS_FAIL_NO_COMMON_CH;
4052 _set_timer(&pwdinfo->restore_p2p_state_timer, 3000);
4055 /* Commented by Albert 20121130 */
4056 /* Intel will use the different P2P IE to store the operating channel information */
4057 /* Workaround for Intel WiDi 3.5 */
4058 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_MATCH);
4059 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4060 status_code = P2P_STATUS_SUCCESS;
4063 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4064 status_code = P2P_STATUS_FAIL_UNKNOWN_P2PGROUP;
4068 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4069 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4072 /* Received the invitation to join a P2P group. */
4074 _rtw_memset(&group_id, 0x00, sizeof(struct group_id_info));
4075 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_GROUP_ID, (u8 *)&group_id, &attr_contentlen);
4076 if (attr_contentlen) {
4077 if (!memcmp(group_id.go_device_addr, myid(&padapter->eeprompriv), ETH_ALEN)) {
4078 /* In this case, the GO can't be myself. */
4079 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_DISMATCH);
4080 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4082 /* The p2p device sending this p2p invitation request wants to join an existing P2P group */
4083 /* Commented by Albert 2012/06/28 */
4084 /* In this case, this Wi-Fi device should use the iwpriv command to get the peer device address. */
4085 /* The peer device address should be the destination address for the provisioning discovery request. */
4086 /* Then, this Wi-Fi device should use the iwpriv command to get the peer interface address. */
4087 /* The peer interface address should be the address for WPS mac address */
4088 memcpy(pwdinfo->p2p_peer_device_addr, group_id.go_device_addr , ETH_ALEN);
4089 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4090 rtw_p2p_set_state(pwdinfo, P2P_STATE_RECV_INVITE_REQ_JOIN);
4091 status_code = P2P_STATUS_SUCCESS;
4094 DBG_88E("[%s] P2P Group ID Attribute NOT FOUND!\n", __func__);
4095 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4099 DBG_88E("[%s] P2P Invitation Flags Attribute NOT FOUND!\n", __func__);
4100 status_code = P2P_STATUS_FAIL_INFO_UNAVAILABLE;
4103 DBG_88E("[%s] status_code = %d\n", __func__, status_code);
4105 pwdinfo->inviteresp_info.token = frame_body[7];
4106 issue_p2p_invitation_response(padapter, GetAddr2Ptr(pframe), pwdinfo->inviteresp_info.token, status_code);
4109 case P2P_INVIT_RESP: {
4110 u8 attr_content = 0x00;
4111 u32 attr_contentlen = 0;
4113 DBG_88E("[%s] Got invite response frame!\n", __func__);
4114 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4115 p2p_ie = rtw_get_p2p_ie(frame_body + _PUBLIC_ACTION_IE_OFFSET_, len - _PUBLIC_ACTION_IE_OFFSET_, NULL, &p2p_ielen);
4117 rtw_get_p2p_attr_content(p2p_ie, p2p_ielen, P2P_ATTR_STATUS, &attr_content, &attr_contentlen);
4119 if (attr_contentlen == 1) {
4120 DBG_88E("[%s] Status = %d\n", __func__, attr_content);
4121 pwdinfo->invitereq_info.benable = false;
4123 if (attr_content == P2P_STATUS_SUCCESS) {
4124 if (!memcmp(pwdinfo->invitereq_info.go_bssid, myid(&padapter->eeprompriv), ETH_ALEN)) {
4125 rtw_p2p_set_role(pwdinfo, P2P_ROLE_GO);
4127 rtw_p2p_set_role(pwdinfo, P2P_ROLE_CLIENT);
4129 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_OK);
4131 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4132 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4135 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4136 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4139 rtw_p2p_set_role(pwdinfo, P2P_ROLE_DEVICE);
4140 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL);
4143 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_INVITE_RESP_FAIL))
4144 _set_timer(&pwdinfo->restore_p2p_state_timer, 5000);
4147 case P2P_DEVDISC_REQ:
4148 process_p2p_devdisc_req(pwdinfo, pframe, len);
4150 case P2P_DEVDISC_RESP:
4151 process_p2p_devdisc_resp(pwdinfo, pframe, len);
4153 case P2P_PROVISION_DISC_REQ:
4154 DBG_88E("[%s] Got Provisioning Discovery Request Frame\n", __func__);
4155 process_p2p_provdisc_req(pwdinfo, pframe, len);
4156 memcpy(pwdinfo->rx_prov_disc_info.peerDevAddr, GetAddr2Ptr(pframe), ETH_ALEN);
4159 /* Add the following statement to avoid receiving duplicate prov disc req. such that pre_p2p_state would be covered. */
4160 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ))
4161 rtw_p2p_set_pre_state(pwdinfo, rtw_p2p_state(pwdinfo));
4163 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_REQ);
4164 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4166 case P2P_PROVISION_DISC_RESP:
4167 /* Commented by Albert 20110707 */
4168 /* Should we check the pwdinfo->tx_prov_disc_info.bsent flag here?? */
4169 DBG_88E("[%s] Got Provisioning Discovery Response Frame\n", __func__);
4170 /* Commented by Albert 20110426 */
4171 /* The restore timer is enabled when issuing the provisioing request frame in rtw_p2p_prov_disc function. */
4172 _cancel_timer_ex(&pwdinfo->restore_p2p_state_timer);
4173 rtw_p2p_set_state(pwdinfo, P2P_STATE_RX_PROVISION_DIS_RSP);
4174 process_p2p_provdisc_resp(pwdinfo, pframe);
4175 _set_timer(&pwdinfo->restore_p2p_state_timer, P2P_PROVISION_TIMEOUT);
4178 #endif /* CONFIG_88EU_P2P */
4183 static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
4185 unsigned int ret = _FAIL;
4186 u8 *pframe = precv_frame->rx_data;
4187 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4189 if (!memcmp(frame_body + 2, P2P_OUI, 4))
4190 ret = on_action_public_p2p(precv_frame);
4195 static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action)
4197 unsigned int ret = _FAIL;
4198 u8 *pframe = precv_frame->rx_data;
4199 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4202 token = frame_body[2];
4204 if (rtw_action_public_decache(precv_frame, token) == _FAIL)
4213 unsigned int on_action_public(struct adapter *padapter, struct recv_frame *precv_frame)
4215 unsigned int ret = _FAIL;
4216 u8 *pframe = precv_frame->rx_data;
4217 u8 *frame_body = pframe + sizeof(struct rtw_ieee80211_hdr_3addr);
4218 u8 category, action;
4220 /* check RA matches or not */
4221 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))
4224 category = frame_body[0];
4225 if (category != RTW_WLAN_CATEGORY_PUBLIC)
4228 action = frame_body[1];
4230 case ACT_PUBLIC_VENDOR:
4231 ret = on_action_public_vendor(precv_frame);
4234 ret = on_action_public_default(precv_frame, action);
4242 unsigned int OnAction_ht(struct adapter *padapter, struct recv_frame *precv_frame)
4247 unsigned int OnAction_wmm(struct adapter *padapter, struct recv_frame *precv_frame)
4252 unsigned int OnAction_p2p(struct adapter *padapter, struct recv_frame *precv_frame)
4254 #ifdef CONFIG_88EU_P2P
4256 u8 category, OUI_Subtype;
4257 u8 *pframe = precv_frame->rx_data;
4258 uint len = precv_frame->len;
4259 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4262 DBG_88E("%s\n", __func__);
4264 /* check RA matches or not */
4265 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), ETH_ALEN))/* for if1, sta/ap mode */
4268 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4270 category = frame_body[0];
4271 if (category != RTW_WLAN_CATEGORY_P2P)
4274 if (be32_to_cpu(*((__be32 *)(frame_body + 1))) != P2POUI)
4277 len -= sizeof(struct rtw_ieee80211_hdr_3addr);
4278 OUI_Subtype = frame_body[5];
4280 switch (OUI_Subtype) {
4281 case P2P_NOTICE_OF_ABSENCE:
4283 case P2P_PRESENCE_REQUEST:
4284 process_p2p_presence_req(pwdinfo, pframe, len);
4286 case P2P_PRESENCE_RESPONSE:
4288 case P2P_GO_DISC_REQUEST:
4293 #endif /* CONFIG_88EU_P2P */
4297 unsigned int OnAction(struct adapter *padapter, struct recv_frame *precv_frame)
4300 unsigned char category;
4301 struct action_handler *ptable;
4302 unsigned char *frame_body;
4303 u8 *pframe = precv_frame->rx_data;
4305 frame_body = (unsigned char *)(pframe + sizeof(struct rtw_ieee80211_hdr_3addr));
4307 category = frame_body[0];
4309 for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
4310 ptable = &OnAction_tbl[i];
4311 if (category == ptable->num)
4312 ptable->func(padapter, precv_frame);
4317 unsigned int DoReserved(struct adapter *padapter, struct recv_frame *precv_frame)
4322 struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv)
4324 struct xmit_frame *pmgntframe;
4325 struct xmit_buf *pxmitbuf;
4327 pmgntframe = rtw_alloc_xmitframe(pxmitpriv);
4328 if (pmgntframe == NULL) {
4329 DBG_88E("%s, alloc xmitframe fail\n", __func__);
4333 pxmitbuf = rtw_alloc_xmitbuf_ext(pxmitpriv);
4334 if (pxmitbuf == NULL) {
4335 DBG_88E("%s, alloc xmitbuf fail\n", __func__);
4336 rtw_free_xmitframe(pxmitpriv, pmgntframe);
4339 pmgntframe->frame_tag = MGNT_FRAMETAG;
4340 pmgntframe->pxmitbuf = pxmitbuf;
4341 pmgntframe->buf_addr = pxmitbuf->pbuf;
4342 pxmitbuf->priv_data = pmgntframe;
4346 /****************************************************************************
4348 Following are some TX functions for WiFi MLME
4350 *****************************************************************************/
4352 void update_mgnt_tx_rate(struct adapter *padapter, u8 rate)
4354 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4356 pmlmeext->tx_rate = rate;
4357 DBG_88E("%s(): rate = %x\n", __func__, rate);
4360 void update_mgntframe_attrib(struct adapter *padapter, struct pkt_attrib *pattrib)
4362 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4364 _rtw_memset((u8 *)(pattrib), 0, sizeof(struct pkt_attrib));
4366 pattrib->hdrlen = 24;
4367 pattrib->nr_frags = 1;
4368 pattrib->priority = 7;
4369 pattrib->mac_id = 0;
4370 pattrib->qsel = 0x12;
4372 pattrib->pktlen = 0;
4374 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
4375 pattrib->raid = 6;/* b mode */
4377 pattrib->raid = 5;/* a/g mode */
4379 pattrib->encrypt = _NO_PRIVACY_;
4380 pattrib->bswenc = false;
4382 pattrib->qos_en = false;
4383 pattrib->ht_en = false;
4384 pattrib->bwmode = HT_CHANNEL_WIDTH_20;
4385 pattrib->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
4386 pattrib->sgi = false;
4388 pattrib->seqnum = pmlmeext->mgnt_seq;
4390 pattrib->retry_ctrl = true;
4393 void dump_mgntframe(struct adapter *padapter, struct xmit_frame *pmgntframe)
4395 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4398 rtw_hal_mgnt_xmit(padapter, pmgntframe);
4401 s32 dump_mgntframe_and_wait(struct adapter *padapter, struct xmit_frame *pmgntframe, int timeout_ms)
4404 struct xmit_buf *pxmitbuf = pmgntframe->pxmitbuf;
4405 struct submit_ctx sctx;
4407 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4410 rtw_sctx_init(&sctx, timeout_ms);
4411 pxmitbuf->sctx = &sctx;
4413 ret = rtw_hal_mgnt_xmit(padapter, pmgntframe);
4415 if (ret == _SUCCESS)
4416 ret = rtw_sctx_wait(&sctx);
4421 s32 dump_mgntframe_and_wait_ack(struct adapter *padapter, struct xmit_frame *pmgntframe)
4424 u32 timeout_ms = 500;/* 500ms */
4425 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
4427 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
4430 _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
4431 pxmitpriv->ack_tx = true;
4433 pmgntframe->ack_report = 1;
4434 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) {
4435 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
4438 pxmitpriv->ack_tx = false;
4439 mutex_unlock(&pxmitpriv->ack_tx_mutex);
4444 static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
4450 ssid_ie = rtw_get_ie(ies, WLAN_EID_SSID, &ssid_len_ori, ies_len);
4452 if (ssid_ie && ssid_len_ori > 0) {
4453 switch (hidden_ssid_mode) {
4455 u8 *next_ie = ssid_ie + 2 + ssid_len_ori;
4458 remain_len = ies_len - (next_ie - ies);
4461 memcpy(ssid_ie+2, next_ie, remain_len);
4462 len_diff -= ssid_len_ori;
4467 _rtw_memset(&ssid_ie[2], 0, ssid_len_ori);
4477 void issue_beacon(struct adapter *padapter, int timeout_ms)
4479 struct xmit_frame *pmgntframe;
4480 struct pkt_attrib *pattrib;
4481 unsigned char *pframe;
4482 struct rtw_ieee80211_hdr *pwlanhdr;
4484 unsigned int rate_len;
4485 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4486 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4487 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4488 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4489 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4490 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4491 #ifdef CONFIG_88EU_P2P
4492 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4493 #endif /* CONFIG_88EU_P2P */
4495 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4496 if (pmgntframe == NULL) {
4497 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4500 #if defined (CONFIG_88EU_AP_MODE)
4501 spin_lock_bh(&pmlmepriv->bcn_update_lock);
4502 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4504 /* update attribute */
4505 pattrib = &pmgntframe->attrib;
4506 update_mgntframe_attrib(padapter, pattrib);
4507 pattrib->qsel = 0x10;
4509 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4511 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4512 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4515 fctrl = &(pwlanhdr->frame_ctl);
4518 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4519 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
4520 memcpy(pwlanhdr->addr3, get_my_bssid(cur_network), ETH_ALEN);
4522 SetSeqNum(pwlanhdr, 0/*pmlmeext->mgnt_seq*/);
4523 /* pmlmeext->mgnt_seq++; */
4524 SetFrameSubType(pframe, WIFI_BEACON);
4526 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
4527 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4529 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4530 #ifdef CONFIG_88EU_P2P
4531 /* for P2P : Primary Device Type & Device Name */
4532 u32 wpsielen = 0, insert_len = 0;
4534 wpsie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wpsielen);
4536 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && wpsie && wpsielen > 0) {
4537 uint wps_offset, remainder_ielen;
4538 u8 *premainder_ie, *pframe_wscie;
4540 wps_offset = (uint)(wpsie - cur_network->IEs);
4541 premainder_ie = wpsie + wpsielen;
4542 remainder_ielen = cur_network->IELength - wps_offset - wpsielen;
4543 pframe_wscie = pframe + wps_offset;
4544 memcpy(pframe, cur_network->IEs, wps_offset+wpsielen);
4545 pframe += (wps_offset + wpsielen);
4546 pattrib->pktlen += (wps_offset + wpsielen);
4548 /* now pframe is end of wsc ie, insert Primary Device Type & Device Name */
4549 /* Primary Device Type */
4551 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_PRIMARY_DEV_TYPE);
4555 *(__be16 *)(pframe + insert_len) = cpu_to_be16(0x0008);
4560 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
4564 *(__be32 *)(pframe + insert_len) = cpu_to_be32(WPSOUI);
4567 /* Sub Category ID */
4568 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
4573 *(__be16 *)(pframe + insert_len) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
4577 *(__be16 *)(pframe + insert_len) = cpu_to_be16(pwdinfo->device_name_len);
4581 memcpy(pframe + insert_len, pwdinfo->device_name, pwdinfo->device_name_len);
4582 insert_len += pwdinfo->device_name_len;
4584 /* update wsc ie length */
4585 *(pframe_wscie+1) = (wpsielen-2) + insert_len;
4587 /* pframe move to end */
4588 pframe += insert_len;
4589 pattrib->pktlen += insert_len;
4591 /* copy remainder_ie to pframe */
4592 memcpy(pframe, premainder_ie, remainder_ielen);
4593 pframe += remainder_ielen;
4594 pattrib->pktlen += remainder_ielen;
4596 #endif /* CONFIG_88EU_P2P */
4599 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4600 len_diff = update_hidden_ssid(
4601 pframe+_BEACON_IE_OFFSET_
4602 , cur_network->IELength-_BEACON_IE_OFFSET_
4603 , pmlmeinfo->hidden_ssid_mode
4605 pframe += (cur_network->IELength+len_diff);
4606 pattrib->pktlen += (cur_network->IELength+len_diff);
4613 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
4614 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
4615 if (wps_ie && wps_ielen > 0)
4616 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
4618 set_fwstate(pmlmepriv, WIFI_UNDER_WPS);
4620 _clr_fwstate_(pmlmepriv, WIFI_UNDER_WPS);
4623 #ifdef CONFIG_88EU_P2P
4624 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO)) {
4626 len = build_beacon_p2p_ie(pwdinfo, pframe);
4629 pattrib->pktlen += len;
4631 #endif /* CONFIG_88EU_P2P */
4636 /* below for ad-hoc mode */
4638 /* timestamp will be inserted by hardware */
4640 pattrib->pktlen += 8;
4642 /* beacon interval: 2 bytes */
4644 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4647 pattrib->pktlen += 2;
4649 /* capability info: 2 bytes */
4651 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4654 pattrib->pktlen += 2;
4657 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4659 /* supported rates... */
4660 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4661 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4663 /* DS parameter set */
4664 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4669 /* IBSS Parameter Set... */
4671 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4674 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4677 /* EXTERNDED SUPPORTED RATE */
4679 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4680 /* todo:HT for adhoc */
4683 #if defined (CONFIG_88EU_AP_MODE)
4684 pmlmepriv->update_bcn = false;
4686 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
4687 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4689 if ((pattrib->pktlen + TXDESC_SIZE) > 512) {
4690 DBG_88E("beacon frame too large\n");
4694 pattrib->last_txcmdsz = pattrib->pktlen;
4696 /* DBG_88E("issue bcn_sz=%d\n", pattrib->last_txcmdsz); */
4698 dump_mgntframe_and_wait(padapter, pmgntframe, timeout_ms);
4700 dump_mgntframe(padapter, pmgntframe);
4703 void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p_probereq)
4705 struct xmit_frame *pmgntframe;
4706 struct pkt_attrib *pattrib;
4707 unsigned char *pframe;
4708 struct rtw_ieee80211_hdr *pwlanhdr;
4710 unsigned char *mac, *bssid;
4711 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4712 #if defined (CONFIG_88EU_AP_MODE)
4715 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4716 #endif /* if defined (CONFIG_88EU_AP_MODE) */
4717 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4718 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4719 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
4720 unsigned int rate_len;
4721 #ifdef CONFIG_88EU_P2P
4722 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
4723 #endif /* CONFIG_88EU_P2P */
4725 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4726 if (pmgntframe == NULL) {
4727 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
4731 /* update attribute */
4732 pattrib = &pmgntframe->attrib;
4733 update_mgntframe_attrib(padapter, pattrib);
4735 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4737 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4738 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4740 mac = myid(&(padapter->eeprompriv));
4741 bssid = cur_network->MacAddress;
4743 fctrl = &(pwlanhdr->frame_ctl);
4745 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4746 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4747 memcpy(pwlanhdr->addr3, bssid, ETH_ALEN);
4749 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4750 pmlmeext->mgnt_seq++;
4751 SetFrameSubType(fctrl, WIFI_PROBERSP);
4753 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
4754 pattrib->pktlen = pattrib->hdrlen;
4755 pframe += pattrib->hdrlen;
4757 if (cur_network->IELength > MAX_IE_SZ)
4760 #if defined(CONFIG_88EU_AP_MODE)
4761 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
4762 pwps_ie = rtw_get_wps_ie(cur_network->IEs+_FIXED_IE_LENGTH_, cur_network->IELength-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
4764 /* inerset & update wps_probe_resp_ie */
4765 if ((pmlmepriv->wps_probe_resp_ie != NULL) && pwps_ie && (wps_ielen > 0)) {
4766 uint wps_offset, remainder_ielen;
4769 wps_offset = (uint)(pwps_ie - cur_network->IEs);
4771 premainder_ie = pwps_ie + wps_ielen;
4773 remainder_ielen = cur_network->IELength - wps_offset - wps_ielen;
4775 memcpy(pframe, cur_network->IEs, wps_offset);
4776 pframe += wps_offset;
4777 pattrib->pktlen += wps_offset;
4779 wps_ielen = (uint)pmlmepriv->wps_probe_resp_ie[1];/* to get ie data len */
4780 if ((wps_offset+wps_ielen+2) <= MAX_IE_SZ) {
4781 memcpy(pframe, pmlmepriv->wps_probe_resp_ie, wps_ielen+2);
4782 pframe += wps_ielen+2;
4783 pattrib->pktlen += wps_ielen+2;
4786 if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
4787 memcpy(pframe, premainder_ie, remainder_ielen);
4788 pframe += remainder_ielen;
4789 pattrib->pktlen += remainder_ielen;
4792 memcpy(pframe, cur_network->IEs, cur_network->IELength);
4793 pframe += cur_network->IELength;
4794 pattrib->pktlen += cur_network->IELength;
4799 /* timestamp will be inserted by hardware */
4801 pattrib->pktlen += 8;
4803 /* beacon interval: 2 bytes */
4805 memcpy(pframe, (unsigned char *)(rtw_get_beacon_interval_from_ie(cur_network->IEs)), 2);
4808 pattrib->pktlen += 2;
4810 /* capability info: 2 bytes */
4812 memcpy(pframe, (unsigned char *)(rtw_get_capability_from_ie(cur_network->IEs)), 2);
4815 pattrib->pktlen += 2;
4817 /* below for ad-hoc mode */
4820 pframe = rtw_set_ie(pframe, _SSID_IE_, cur_network->Ssid.SsidLength, cur_network->Ssid.Ssid, &pattrib->pktlen);
4822 /* supported rates... */
4823 rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
4824 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
4826 /* DS parameter set */
4827 pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
4829 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
4832 /* IBSS Parameter Set... */
4833 /* ATIMWindow = cur->Configuration.ATIMWindow; */
4835 pframe = rtw_set_ie(pframe, _IBSS_PARA_IE_, 2, (unsigned char *)(&ATIMWindow), &pattrib->pktlen);
4838 pframe = rtw_set_ie(pframe, _ERPINFO_IE_, 1, &erpinfo, &pattrib->pktlen);
4842 /* EXTERNDED SUPPORTED RATE */
4844 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (rate_len - 8), (cur_network->SupportedRates + 8), &pattrib->pktlen);
4845 /* todo:HT for adhoc */
4848 #ifdef CONFIG_88EU_P2P
4849 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && is_valid_p2p_probereq) {
4851 len = build_probe_resp_p2p_ie(pwdinfo, pframe);
4854 pattrib->pktlen += len;
4856 #endif /* CONFIG_88EU_P2P */
4858 pattrib->last_txcmdsz = pattrib->pktlen;
4860 dump_mgntframe(padapter, pmgntframe);
4865 static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da, int wait_ack)
4868 struct xmit_frame *pmgntframe;
4869 struct pkt_attrib *pattrib;
4870 unsigned char *pframe;
4871 struct rtw_ieee80211_hdr *pwlanhdr;
4874 unsigned char bssrate[NumRates];
4875 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
4876 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
4877 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
4878 int bssrate_len = 0;
4879 u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4881 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_, ("+issue_probereq\n"));
4883 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
4884 if (pmgntframe == NULL)
4887 /* update attribute */
4888 pattrib = &pmgntframe->attrib;
4889 update_mgntframe_attrib(padapter, pattrib);
4892 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
4894 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
4895 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
4897 mac = myid(&(padapter->eeprompriv));
4899 fctrl = &(pwlanhdr->frame_ctl);
4903 /* unicast probe request frame */
4904 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
4905 memcpy(pwlanhdr->addr3, da, ETH_ALEN);
4907 /* broadcast probe request frame */
4908 memcpy(pwlanhdr->addr1, bc_addr, ETH_ALEN);
4909 memcpy(pwlanhdr->addr3, bc_addr, ETH_ALEN);
4912 memcpy(pwlanhdr->addr2, mac, ETH_ALEN);
4914 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
4915 pmlmeext->mgnt_seq++;
4916 SetFrameSubType(pframe, WIFI_PROBEREQ);
4918 pframe += sizeof (struct rtw_ieee80211_hdr_3addr);
4919 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr);
4922 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
4924 pframe = rtw_set_ie(pframe, _SSID_IE_, 0, NULL, &(pattrib->pktlen));
4926 get_rate_set(padapter, bssrate, &bssrate_len);
4928 if (bssrate_len > 8) {
4929 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
4930 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
4932 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
4935 /* add wps_ie for wps2.0 */
4936 if (pmlmepriv->wps_probe_req_ie_len > 0 && pmlmepriv->wps_probe_req_ie) {
4937 memcpy(pframe, pmlmepriv->wps_probe_req_ie, pmlmepriv->wps_probe_req_ie_len);
4938 pframe += pmlmepriv->wps_probe_req_ie_len;
4939 pattrib->pktlen += pmlmepriv->wps_probe_req_ie_len;
4942 pattrib->last_txcmdsz = pattrib->pktlen;
4944 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
4945 ("issuing probe_req, tx_len=%d\n", pattrib->last_txcmdsz));
4948 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
4950 dump_mgntframe(padapter, pmgntframe);
4958 inline void issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da)
4960 _issue_probereq(padapter, pssid, da, false);
4963 int issue_probereq_ex(struct adapter *padapter, struct ndis_802_11_ssid *pssid, u8 *da,
4964 int try_cnt, int wait_ms)
4968 u32 start = jiffies;
4971 ret = _issue_probereq(padapter, pssid, da, wait_ms > 0 ? true : false);
4975 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
4978 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
4981 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
4988 if (try_cnt && wait_ms) {
4990 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
4991 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
4992 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
4994 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
4995 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
4996 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5002 /* if psta == NULL, indicate we are station(client) now... */
5003 void issue_auth(struct adapter *padapter, struct sta_info *psta, unsigned short status)
5005 struct xmit_frame *pmgntframe;
5006 struct pkt_attrib *pattrib;
5007 unsigned char *pframe;
5008 struct rtw_ieee80211_hdr *pwlanhdr;
5012 #ifdef CONFIG_88EU_AP_MODE
5015 int use_shared_key = 0;
5016 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5017 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5018 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5020 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5021 if (pmgntframe == NULL)
5024 /* update attribute */
5025 pattrib = &pmgntframe->attrib;
5026 update_mgntframe_attrib(padapter, pattrib);
5028 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5030 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5031 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5033 fctrl = &(pwlanhdr->frame_ctl);
5036 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5037 pmlmeext->mgnt_seq++;
5038 SetFrameSubType(pframe, WIFI_AUTH);
5040 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5041 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5044 if (psta) {/* for AP mode */
5045 #ifdef CONFIG_88EU_AP_MODE
5047 memcpy(pwlanhdr->addr1, psta->hwaddr, ETH_ALEN);
5048 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5049 memcpy(pwlanhdr->addr3, myid(&(padapter->eeprompriv)), ETH_ALEN);
5052 /* setting auth algo number */
5053 val16 = (u16)psta->authalg;
5055 if (status != _STATS_SUCCESSFUL_)
5059 le_val16 = cpu_to_le16(val16);
5065 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5067 /* setting auth seq number */
5068 val16 = (u16)psta->auth_seq;
5069 le_val16 = cpu_to_le16(val16);
5070 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5072 /* setting status code... */
5074 le_val16 = cpu_to_le16(val16);
5075 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_val16, &(pattrib->pktlen));
5077 /* added challenging text... */
5078 if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
5079 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, psta->chg_txt, &(pattrib->pktlen));
5084 memcpy(pwlanhdr->addr1, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5085 memcpy(pwlanhdr->addr2, myid(&padapter->eeprompriv), ETH_ALEN);
5086 memcpy(pwlanhdr->addr3, get_my_bssid(&pmlmeinfo->network), ETH_ALEN);
5088 /* setting auth algo number */
5089 val16 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_Shared) ? 1 : 0;/* 0:OPEN System, 1:Shared key */
5093 /* setting IV for auth seq #3 */
5094 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5095 val32 = ((pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30));
5096 le_tmp32 = cpu_to_le32(val32);
5097 pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen));
5099 pattrib->iv_len = 4;
5102 le_tmp16 = cpu_to_le16(val16);
5103 pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5105 /* setting auth seq number */
5106 val16 = pmlmeinfo->auth_seq;
5107 le_tmp16 = cpu_to_le16(val16);
5108 pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5111 /* setting status code... */
5112 le_tmp16 = cpu_to_le16(status);
5113 pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
5115 /* then checking to see if sending challenging text... */
5116 if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
5117 pframe = rtw_set_ie(pframe, _CHLGETXT_IE_, 128, pmlmeinfo->chg_txt, &(pattrib->pktlen));
5121 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5123 pattrib->encrypt = _WEP40_;
5125 pattrib->icv_len = 4;
5127 pattrib->pktlen += pattrib->icv_len;
5131 pattrib->last_txcmdsz = pattrib->pktlen;
5133 rtw_wep_encrypt(padapter, (u8 *)pmgntframe);
5134 DBG_88E("%s\n", __func__);
5135 dump_mgntframe(padapter, pmgntframe);
5141 void issue_asocrsp(struct adapter *padapter, unsigned short status, struct sta_info *pstat, int pkt_type)
5143 #ifdef CONFIG_88EU_AP_MODE
5144 struct xmit_frame *pmgntframe;
5145 struct rtw_ieee80211_hdr *pwlanhdr;
5146 struct pkt_attrib *pattrib;
5147 unsigned char *pbuf, *pframe;
5150 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5151 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5152 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
5153 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5154 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
5155 u8 *ie = pnetwork->IEs;
5156 __le16 lestatus, leval;
5157 #ifdef CONFIG_88EU_P2P
5158 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5159 #endif /* CONFIG_88EU_P2P */
5161 DBG_88E("%s\n", __func__);
5163 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5164 if (pmgntframe == NULL)
5167 /* update attribute */
5168 pattrib = &pmgntframe->attrib;
5169 update_mgntframe_attrib(padapter, pattrib);
5172 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5174 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5175 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5177 fctrl = &(pwlanhdr->frame_ctl);
5180 memcpy((void *)GetAddr1Ptr(pwlanhdr), pstat->hwaddr, ETH_ALEN);
5181 memcpy((void *)GetAddr2Ptr(pwlanhdr), myid(&(padapter->eeprompriv)), ETH_ALEN);
5182 memcpy((void *)GetAddr3Ptr(pwlanhdr), get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5185 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5186 pmlmeext->mgnt_seq++;
5187 if ((pkt_type == WIFI_ASSOCRSP) || (pkt_type == WIFI_REASSOCRSP))
5188 SetFrameSubType(pwlanhdr, pkt_type);
5192 pattrib->hdrlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5193 pattrib->pktlen += pattrib->hdrlen;
5194 pframe += pattrib->hdrlen;
5197 val = *(unsigned short *)rtw_get_capability_from_ie(ie);
5199 pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
5201 lestatus = cpu_to_le16(status);
5202 pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&lestatus, &(pattrib->pktlen));
5204 leval = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
5205 pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&leval, &(pattrib->pktlen));
5207 if (pstat->bssratelen <= 8) {
5208 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
5210 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, 8, pstat->bssrateset, &(pattrib->pktlen));
5211 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_, (pstat->bssratelen-8), pstat->bssrateset+8, &(pattrib->pktlen));
5214 if ((pstat->flags & WLAN_STA_HT) && (pmlmepriv->htpriv.ht_option)) {
5217 /* FILL HT CAP INFO IE */
5218 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_CAPABILITY_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5219 if (pbuf && ie_len > 0) {
5220 memcpy(pframe, pbuf, ie_len+2);
5221 pframe += (ie_len+2);
5222 pattrib->pktlen += (ie_len+2);
5225 /* FILL HT ADD INFO IE */
5226 pbuf = rtw_get_ie(ie + _BEACON_IE_OFFSET_, _HT_ADD_INFO_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_));
5227 if (pbuf && ie_len > 0) {
5228 memcpy(pframe, pbuf, ie_len+2);
5229 pframe += (ie_len+2);
5230 pattrib->pktlen += (ie_len+2);
5235 if ((pstat->flags & WLAN_STA_WME) && (pmlmepriv->qospriv.qos_option)) {
5237 unsigned char WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
5239 for (pbuf = ie + _BEACON_IE_OFFSET_;; pbuf += (ie_len + 2)) {
5240 pbuf = rtw_get_ie(pbuf, _VENDOR_SPECIFIC_IE_, &ie_len, (pnetwork->IELength - _BEACON_IE_OFFSET_ - (ie_len + 2)));
5241 if (pbuf && !memcmp(pbuf+2, WMM_PARA_IE, 6)) {
5242 memcpy(pframe, pbuf, ie_len+2);
5243 pframe += (ie_len+2);
5244 pattrib->pktlen += (ie_len+2);
5248 if ((pbuf == NULL) || (ie_len == 0))
5253 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5254 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
5256 /* add WPS IE ie for wps 2.0 */
5257 if (pmlmepriv->wps_assoc_resp_ie && pmlmepriv->wps_assoc_resp_ie_len > 0) {
5258 memcpy(pframe, pmlmepriv->wps_assoc_resp_ie, pmlmepriv->wps_assoc_resp_ie_len);
5260 pframe += pmlmepriv->wps_assoc_resp_ie_len;
5261 pattrib->pktlen += pmlmepriv->wps_assoc_resp_ie_len;
5264 #ifdef CONFIG_88EU_P2P
5265 if (rtw_p2p_chk_role(pwdinfo, P2P_ROLE_GO) && (pstat->is_p2p_device)) {
5268 len = build_assoc_resp_p2p_ie(pwdinfo, pframe, pstat->p2p_status_code);
5271 pattrib->pktlen += len;
5273 #endif /* CONFIG_88EU_P2P */
5274 pattrib->last_txcmdsz = pattrib->pktlen;
5275 dump_mgntframe(padapter, pmgntframe);
5279 void issue_assocreq(struct adapter *padapter)
5282 struct xmit_frame *pmgntframe;
5283 struct pkt_attrib *pattrib;
5284 unsigned char *pframe, *p;
5285 struct rtw_ieee80211_hdr *pwlanhdr;
5288 unsigned int i, j, ie_len, index = 0;
5289 unsigned char rf_type, bssrate[NumRates], sta_bssrate[NumRates];
5290 struct ndis_802_11_var_ie *pIE;
5291 struct registry_priv *pregpriv = &padapter->registrypriv;
5292 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5293 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
5294 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5295 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5296 int bssrate_len = 0, sta_bssrate_len = 0;
5297 #ifdef CONFIG_88EU_P2P
5298 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5299 u8 p2pie[255] = { 0x00 };
5301 #endif /* CONFIG_88EU_P2P */
5303 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5304 if (pmgntframe == NULL)
5307 /* update attribute */
5308 pattrib = &pmgntframe->attrib;
5309 update_mgntframe_attrib(padapter, pattrib);
5311 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5312 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5313 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5315 fctrl = &(pwlanhdr->frame_ctl);
5317 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5318 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5319 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5321 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5322 pmlmeext->mgnt_seq++;
5323 SetFrameSubType(pframe, WIFI_ASSOCREQ);
5325 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5326 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5330 memcpy(pframe, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
5333 pattrib->pktlen += 2;
5335 /* listen interval */
5336 /* todo: listen interval for power saving */
5337 le_tmp = cpu_to_le16(3);
5338 memcpy(pframe , (unsigned char *)&le_tmp, 2);
5340 pattrib->pktlen += 2;
5343 pframe = rtw_set_ie(pframe, _SSID_IE_, pmlmeinfo->network.Ssid.SsidLength, pmlmeinfo->network.Ssid.Ssid, &(pattrib->pktlen));
5345 /* supported rate & extended supported rate */
5347 /* Check if the AP's supported rates are also supported by STA. */
5348 get_rate_set(padapter, sta_bssrate, &sta_bssrate_len);
5350 if (pmlmeext->cur_channel == 14)/* for JAPAN, channel 14 can only uses B Mode(CCK) */
5351 sta_bssrate_len = 4;
5353 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5354 if (pmlmeinfo->network.SupportedRates[i] == 0)
5356 DBG_88E("network.SupportedRates[%d]=%02X\n", i, pmlmeinfo->network.SupportedRates[i]);
5359 for (i = 0; i < NDIS_802_11_LENGTH_RATES_EX; i++) {
5360 if (pmlmeinfo->network.SupportedRates[i] == 0)
5363 /* Check if the AP's supported rates are also supported by STA. */
5364 for (j = 0; j < sta_bssrate_len; j++) {
5365 /* Avoid the proprietary data rate (22Mbps) of Handlink WSG-4000 AP */
5366 if ((pmlmeinfo->network.SupportedRates[i]|IEEE80211_BASIC_RATE_MASK)
5367 == (sta_bssrate[j]|IEEE80211_BASIC_RATE_MASK))
5371 if (j == sta_bssrate_len) {
5372 /* the rate is not supported by STA */
5373 DBG_88E("%s(): the rate[%d]=%02X is not supported by STA!\n", __func__, i, pmlmeinfo->network.SupportedRates[i]);
5375 /* the rate is supported by STA */
5376 bssrate[index++] = pmlmeinfo->network.SupportedRates[i];
5380 bssrate_len = index;
5381 DBG_88E("bssrate_len=%d\n", bssrate_len);
5383 if (bssrate_len == 0) {
5384 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
5385 rtw_free_xmitframe(pxmitpriv, pmgntframe);
5386 goto exit; /* don't connect to AP if no joint supported rate */
5390 if (bssrate_len > 8) {
5391 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
5392 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
5394 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
5398 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _RSN_IE_2_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
5400 pframe = rtw_set_ie(pframe, _RSN_IE_2_, ie_len, (p + 2), &(pattrib->pktlen));
5403 if (padapter->mlmepriv.htpriv.ht_option) {
5404 p = rtw_get_ie((pmlmeinfo->network.IEs + sizeof(struct ndis_802_11_fixed_ie)), _HT_CAPABILITY_IE_, &ie_len, (pmlmeinfo->network.IELength - sizeof(struct ndis_802_11_fixed_ie)));
5405 if ((p != NULL) && (!(is_ap_in_tkip(padapter)))) {
5406 memcpy(&(pmlmeinfo->HT_caps), (p + 2), sizeof(struct HT_caps_element));
5408 /* to disable 40M Hz support while gd_bw_40MHz_en = 0 */
5409 if (pregpriv->cbw40_enable == 0)
5410 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info &= cpu_to_le16(~(BIT(6) | BIT(1)));
5412 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(BIT(1));
5414 /* todo: disable SM power save mode */
5415 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x000c);
5417 rtw_hal_get_hwreg(padapter, HW_VAR_RF_TYPE, (u8 *)(&rf_type));
5420 if (pregpriv->rx_stbc)
5421 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0100);/* RX STBC One spatial stream */
5422 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_1R, 16);
5427 if ((pregpriv->rx_stbc == 0x3) ||/* enable for 2.4/5 GHz */
5428 ((pmlmeext->cur_wireless_mode & WIRELESS_11_24N) && (pregpriv->rx_stbc == 0x1)) || /* enable for 2.4GHz */
5429 (pregpriv->wifi_spec == 1)) {
5430 DBG_88E("declare supporting RX STBC\n");
5431 pmlmeinfo->HT_caps.u.HT_cap_element.HT_caps_info |= cpu_to_le16(0x0200);/* RX STBC two spatial stream */
5433 memcpy(pmlmeinfo->HT_caps.u.HT_cap_element.MCS_rate, MCS_rate_2R, 16);
5436 pframe = rtw_set_ie(pframe, _HT_CAPABILITY_IE_, ie_len , (u8 *)(&(pmlmeinfo->HT_caps)), &(pattrib->pktlen));
5440 /* vendor specific IE, such as WPA, WMM, WPS */
5441 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
5442 pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
5444 switch (pIE->ElementID) {
5445 case _VENDOR_SPECIFIC_IE_:
5446 if ((!memcmp(pIE->data, RTW_WPA_OUI, 4)) ||
5447 (!memcmp(pIE->data, WMM_OUI, 4)) ||
5448 (!memcmp(pIE->data, WPS_OUI, 4))) {
5449 if (!padapter->registrypriv.wifi_spec) {
5450 /* Commented by Kurt 20110629 */
5451 /* In some older APs, WPS handshake */
5452 /* would be fail if we append vender extensions informations to AP */
5453 if (!memcmp(pIE->data, WPS_OUI, 4))
5456 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, pIE->Length, pIE->data, &(pattrib->pktlen));
5462 i += (pIE->Length + 2);
5465 if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
5466 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 6 , REALTEK_96B_IE, &(pattrib->pktlen));
5468 #ifdef CONFIG_88EU_P2P
5470 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE) && !rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)) {
5471 /* Should add the P2P IE in the association request frame. */
5475 p2pie[p2pielen++] = 0x50;
5476 p2pie[p2pielen++] = 0x6F;
5477 p2pie[p2pielen++] = 0x9A;
5478 p2pie[p2pielen++] = 0x09; /* WFA P2P v1.0 */
5480 /* Commented by Albert 20101109 */
5481 /* According to the P2P Specification, the association request frame should contain 3 P2P attributes */
5482 /* 1. P2P Capability */
5483 /* 2. Extended Listen Timing */
5484 /* 3. Device Info */
5485 /* Commented by Albert 20110516 */
5486 /* 4. P2P Interface */
5488 /* P2P Capability */
5490 p2pie[p2pielen++] = P2P_ATTR_CAPABILITY;
5493 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0002);
5497 /* Device Capability Bitmap, 1 byte */
5498 p2pie[p2pielen++] = DMP_P2P_DEVCAP_SUPPORT;
5500 /* Group Capability Bitmap, 1 byte */
5501 if (pwdinfo->persistent_supported)
5502 p2pie[p2pielen++] = P2P_GRPCAP_PERSISTENT_GROUP | DMP_P2P_GRPCAP_SUPPORT;
5504 p2pie[p2pielen++] = DMP_P2P_GRPCAP_SUPPORT;
5506 /* Extended Listen Timing */
5508 p2pie[p2pielen++] = P2P_ATTR_EX_LISTEN_TIMING;
5511 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x0004);
5515 /* Availability Period */
5516 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5519 /* Availability Interval */
5520 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0xFFFF);
5525 p2pie[p2pielen++] = P2P_ATTR_DEVICE_INFO;
5528 /* 21 -> P2P Device Address (6bytes) + Config Methods (2bytes) + Primary Device Type (8bytes) */
5529 /* + NumofSecondDevType (1byte) + WPS Device Name ID field (2bytes) + WPS Device Name Len field (2bytes) */
5530 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(21 + pwdinfo->device_name_len);
5534 /* P2P Device Address */
5535 memcpy(p2pie + p2pielen, myid(&padapter->eeprompriv), ETH_ALEN);
5536 p2pielen += ETH_ALEN;
5539 /* This field should be big endian. Noted by P2P specification. */
5540 if ((pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_PEER_DISPLAY_PIN) ||
5541 (pwdinfo->ui_got_wps_info == P2P_GOT_WPSINFO_SELF_DISPLAY_PIN))
5542 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_DISPLAY);
5544 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_CONFIG_METHOD_PBC);
5548 /* Primary Device Type */
5550 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_CID_MULIT_MEDIA);
5554 *(__be32 *)(p2pie + p2pielen) = cpu_to_be32(WPSOUI);
5557 /* Sub Category ID */
5558 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_PDT_SCID_MEDIA_SERVER);
5561 /* Number of Secondary Device Types */
5562 p2pie[p2pielen++] = 0x00; /* No Secondary Device Type List */
5566 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(WPS_ATTR_DEVICE_NAME);
5570 *(__be16 *)(p2pie + p2pielen) = cpu_to_be16(pwdinfo->device_name_len);
5574 memcpy(p2pie + p2pielen, pwdinfo->device_name, pwdinfo->device_name_len);
5575 p2pielen += pwdinfo->device_name_len;
5579 p2pie[p2pielen++] = P2P_ATTR_INTERFACE;
5582 *(__le16 *)(p2pie + p2pielen) = cpu_to_le16(0x000D);
5586 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Device Address */
5587 p2pielen += ETH_ALEN;
5589 p2pie[p2pielen++] = 1; /* P2P Interface Address Count */
5591 memcpy(p2pie + p2pielen, pwdinfo->device_addr, ETH_ALEN); /* P2P Interface Address List */
5592 p2pielen += ETH_ALEN;
5594 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, p2pielen, (unsigned char *)p2pie, &pattrib->pktlen);
5597 #endif /* CONFIG_88EU_P2P */
5599 pattrib->last_txcmdsz = pattrib->pktlen;
5600 dump_mgntframe(padapter, pmgntframe);
5605 if (ret == _SUCCESS)
5606 rtw_buf_update(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len, (u8 *)pwlanhdr, pattrib->pktlen);
5608 rtw_buf_free(&pmlmepriv->assoc_req, &pmlmepriv->assoc_req_len);
5613 /* when wait_ack is true, this function should be called at process context */
5614 static int _issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ack)
5617 struct xmit_frame *pmgntframe;
5618 struct pkt_attrib *pattrib;
5619 unsigned char *pframe;
5620 struct rtw_ieee80211_hdr *pwlanhdr;
5622 struct xmit_priv *pxmitpriv;
5623 struct mlme_ext_priv *pmlmeext;
5624 struct mlme_ext_info *pmlmeinfo;
5629 pxmitpriv = &(padapter->xmitpriv);
5630 pmlmeext = &(padapter->mlmeextpriv);
5631 pmlmeinfo = &(pmlmeext->mlmext_info);
5633 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5634 if (pmgntframe == NULL)
5637 /* update attribute */
5638 pattrib = &pmgntframe->attrib;
5639 update_mgntframe_attrib(padapter, pattrib);
5640 pattrib->retry_ctrl = false;
5642 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5644 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5645 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5647 fctrl = &(pwlanhdr->frame_ctl);
5650 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5652 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5658 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5659 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5660 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5662 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5663 pmlmeext->mgnt_seq++;
5664 SetFrameSubType(pframe, WIFI_DATA_NULL);
5666 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5667 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5669 pattrib->last_txcmdsz = pattrib->pktlen;
5672 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5674 dump_mgntframe(padapter, pmgntframe);
5683 /* when wait_ms > 0 , this function should be called at process context */
5684 /* da == NULL for station mode */
5685 int issue_nulldata(struct adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
5689 u32 start = jiffies;
5690 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5691 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5693 /* da == NULL, assume it's null data for sta to ap*/
5695 da = get_my_bssid(&(pmlmeinfo->network));
5698 ret = _issue_nulldata(padapter, da, power_mode, wait_ms > 0 ? true : false);
5702 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5705 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5707 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5714 if (try_cnt && wait_ms) {
5716 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5717 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5718 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5720 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5721 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5722 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5728 /* when wait_ack is true, this function should be called at process context */
5729 static int _issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int wait_ack)
5732 struct xmit_frame *pmgntframe;
5733 struct pkt_attrib *pattrib;
5734 unsigned char *pframe;
5735 struct rtw_ieee80211_hdr *pwlanhdr;
5738 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5739 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5740 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5742 DBG_88E("%s\n", __func__);
5744 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5745 if (pmgntframe == NULL)
5748 /* update attribute */
5749 pattrib = &pmgntframe->attrib;
5750 update_mgntframe_attrib(padapter, pattrib);
5752 pattrib->hdrlen += 2;
5753 pattrib->qos_en = true;
5755 pattrib->ack_policy = 0;
5758 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5760 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5761 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5763 fctrl = &(pwlanhdr->frame_ctl);
5766 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)
5768 else if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
5774 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
5776 SetPriority(qc, tid);
5778 SetEOSP(qc, pattrib->eosp);
5780 SetAckpolicy(qc, pattrib->ack_policy);
5782 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5783 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5784 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5786 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5787 pmlmeext->mgnt_seq++;
5788 SetFrameSubType(pframe, WIFI_QOS_DATA_NULL);
5790 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5791 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
5793 pattrib->last_txcmdsz = pattrib->pktlen;
5796 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5798 dump_mgntframe(padapter, pmgntframe);
5806 /* when wait_ms > 0 , this function should be called at process context */
5807 /* da == NULL for station mode */
5808 int issue_qos_nulldata(struct adapter *padapter, unsigned char *da, u16 tid, int try_cnt, int wait_ms)
5812 u32 start = jiffies;
5813 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5814 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5816 /* da == NULL, assume it's null data for sta to ap*/
5818 da = get_my_bssid(&(pmlmeinfo->network));
5821 ret = _issue_qos_nulldata(padapter, da, tid, wait_ms > 0 ? true : false);
5825 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5828 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5830 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5837 if (try_cnt && wait_ms) {
5839 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5840 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5841 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5843 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5844 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5845 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5851 static int _issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason, u8 wait_ack)
5853 struct xmit_frame *pmgntframe;
5854 struct pkt_attrib *pattrib;
5855 unsigned char *pframe;
5856 struct rtw_ieee80211_hdr *pwlanhdr;
5858 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5859 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5860 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
5863 #ifdef CONFIG_88EU_P2P
5864 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
5865 #endif /* CONFIG_88EU_P2P */
5867 #ifdef CONFIG_88EU_P2P
5868 if (!(rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) && (pwdinfo->rx_invitereq_info.scan_op_ch_only)) {
5869 _cancel_timer_ex(&pwdinfo->reset_ch_sitesurvey);
5870 _set_timer(&pwdinfo->reset_ch_sitesurvey, 10);
5872 #endif /* CONFIG_88EU_P2P */
5874 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5875 if (pmgntframe == NULL)
5878 /* update attribute */
5879 pattrib = &pmgntframe->attrib;
5880 update_mgntframe_attrib(padapter, pattrib);
5881 pattrib->retry_ctrl = false;
5883 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5885 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5886 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5888 fctrl = &(pwlanhdr->frame_ctl);
5891 memcpy(pwlanhdr->addr1, da, ETH_ALEN);
5892 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
5893 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
5895 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5896 pmlmeext->mgnt_seq++;
5897 SetFrameSubType(pframe, WIFI_DEAUTH);
5899 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
5900 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
5902 le_tmp = cpu_to_le16(reason);
5903 pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&le_tmp, &(pattrib->pktlen));
5905 pattrib->last_txcmdsz = pattrib->pktlen;
5909 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
5911 dump_mgntframe(padapter, pmgntframe);
5919 int issue_deauth(struct adapter *padapter, unsigned char *da, unsigned short reason)
5921 DBG_88E("%s to %pM\n", __func__, da);
5922 return _issue_deauth(padapter, da, reason, false);
5925 int issue_deauth_ex(struct adapter *padapter, u8 *da, unsigned short reason, int try_cnt,
5930 u32 start = jiffies;
5933 ret = _issue_deauth(padapter, da, reason, wait_ms > 0 ? true : false);
5937 if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
5940 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
5942 } while ((i < try_cnt) && ((ret == _FAIL) || (wait_ms == 0)));
5949 if (try_cnt && wait_ms) {
5951 DBG_88E(FUNC_ADPT_FMT" to %pM, ch:%u%s, %d/%d in %u ms\n",
5952 FUNC_ADPT_ARG(padapter), da, rtw_get_oper_ch(padapter),
5953 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5955 DBG_88E(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
5956 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
5957 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
5963 void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
5965 struct xmit_frame *pmgntframe;
5966 struct pkt_attrib *pattrib;
5967 unsigned char *pframe;
5968 struct rtw_ieee80211_hdr *pwlanhdr;
5970 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
5971 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
5974 DBG_88E(FUNC_NDEV_FMT" ra =%pM, ch:%u, offset:%u\n",
5975 FUNC_NDEV_ARG(padapter->pnetdev), ra, new_ch, ch_offset);
5977 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
5978 if (pmgntframe == NULL)
5981 /* update attribute */
5982 pattrib = &pmgntframe->attrib;
5983 update_mgntframe_attrib(padapter, pattrib);
5985 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
5987 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
5988 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
5990 fctrl = &(pwlanhdr->frame_ctl);
5993 memcpy(pwlanhdr->addr1, ra, ETH_ALEN); /* RA */
5994 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN); /* TA */
5995 memcpy(pwlanhdr->addr3, ra, ETH_ALEN); /* DA = RA */
5997 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
5998 pmlmeext->mgnt_seq++;
5999 SetFrameSubType(pframe, WIFI_ACTION);
6001 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6002 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6004 /* category, action */
6006 u8 category, action;
6007 category = RTW_WLAN_CATEGORY_SPECTRUM_MGMT;
6008 action = RTW_WLAN_ACTION_SPCT_CHL_SWITCH;
6010 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6011 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6014 pframe = rtw_set_ie_ch_switch (pframe, &(pattrib->pktlen), 0, new_ch, 0);
6015 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
6016 hal_ch_offset_to_secondary_ch_offset(ch_offset));
6018 pattrib->last_txcmdsz = pattrib->pktlen;
6020 dump_mgntframe(padapter, pmgntframe);
6023 void issue_action_BA(struct adapter *padapter, unsigned char *raddr, unsigned char action, unsigned short status)
6025 u8 category = RTW_WLAN_CATEGORY_BACK;
6029 u16 BA_timeout_value;
6031 u16 BA_starting_seqctrl = 0;
6032 enum ht_cap_ampdu_factor max_rx_ampdu_factor;
6033 struct xmit_frame *pmgntframe;
6034 struct pkt_attrib *pattrib;
6036 struct rtw_ieee80211_hdr *pwlanhdr;
6038 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6039 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6040 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6041 struct sta_info *psta;
6042 struct sta_priv *pstapriv = &padapter->stapriv;
6043 struct registry_priv *pregpriv = &padapter->registrypriv;
6045 DBG_88E("%s, category=%d, action=%d, status=%d\n", __func__, category, action, status);
6047 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
6048 if (pmgntframe == NULL)
6051 /* update attribute */
6052 pattrib = &pmgntframe->attrib;
6053 update_mgntframe_attrib(padapter, pattrib);
6055 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6057 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6058 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6060 fctrl = &(pwlanhdr->frame_ctl);
6063 /* memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN); */
6064 memcpy(pwlanhdr->addr1, raddr, ETH_ALEN);
6065 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6066 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6068 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
6069 pmlmeext->mgnt_seq++;
6070 SetFrameSubType(pframe, WIFI_ACTION);
6072 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6073 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6075 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6076 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6078 if (category == 3) {
6080 case 0: /* ADDBA req */
6082 pmlmeinfo->dialogToken++;
6083 } while (pmlmeinfo->dialogToken == 0);
6084 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->dialogToken), &(pattrib->pktlen));
6086 BA_para_set = (0x1002 | ((status & 0xf) << 2)); /* immediate ack & 64 buffer size */
6087 le_tmp = cpu_to_le16(BA_para_set);
6088 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6090 BA_timeout_value = 5000;/* 5ms */
6091 le_tmp = cpu_to_le16(BA_timeout_value);
6092 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6094 psta = rtw_get_stainfo(pstapriv, raddr);
6096 start_seq = (psta->sta_xmitpriv.txseq_tid[status & 0x07]&0xfff) + 1;
6098 DBG_88E("BA_starting_seqctrl=%d for TID=%d\n", start_seq, status & 0x07);
6100 psta->BA_starting_seqctrl[status & 0x07] = start_seq;
6102 BA_starting_seqctrl = start_seq << 4;
6104 le_tmp = cpu_to_le16(BA_starting_seqctrl);
6105 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6107 case 1: /* ADDBA rsp */
6108 pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
6109 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
6111 BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f;
6112 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
6113 switch (max_rx_ampdu_factor) {
6114 case MAX_AMPDU_FACTOR_64K:
6115 BA_para_set |= 0x1000; /* 64 buffer size */
6117 case MAX_AMPDU_FACTOR_32K:
6118 BA_para_set |= 0x0800; /* 32 buffer size */
6120 case MAX_AMPDU_FACTOR_16K:
6121 BA_para_set |= 0x0400; /* 16 buffer size */
6123 case MAX_AMPDU_FACTOR_8K:
6124 BA_para_set |= 0x0200; /* 8 buffer size */
6127 BA_para_set |= 0x1000; /* 64 buffer size */
6131 if (pregpriv->ampdu_amsdu == 0)/* disabled */
6132 BA_para_set = BA_para_set & ~BIT(0);
6133 else if (pregpriv->ampdu_amsdu == 1)/* enabled */
6134 BA_para_set = BA_para_set | BIT(0);
6135 le_tmp = cpu_to_le16(BA_para_set);
6137 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6138 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
6141 BA_para_set = (status & 0x1F) << 3;
6142 le_tmp = cpu_to_le16(BA_para_set);
6143 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6145 reason_code = 37;/* Requested from peer STA as it does not want to use the mechanism */
6146 le_tmp = cpu_to_le16(reason_code);
6147 pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
6154 pattrib->last_txcmdsz = pattrib->pktlen;
6156 dump_mgntframe(padapter, pmgntframe);
6159 static void issue_action_BSSCoexistPacket(struct adapter *padapter)
6161 struct list_head *plist, *phead;
6162 unsigned char category, action;
6163 struct xmit_frame *pmgntframe;
6164 struct pkt_attrib *pattrib;
6165 unsigned char *pframe;
6166 struct rtw_ieee80211_hdr *pwlanhdr;
6168 struct wlan_network *pnetwork = NULL;
6169 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
6170 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6171 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
6172 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6173 struct __queue *queue = &(pmlmepriv->scanned_queue);
6174 u8 InfoContent[16] = {0};
6176 if ((pmlmepriv->num_FortyMHzIntolerant == 0) || (pmlmepriv->num_sta_no_ht == 0))
6179 if (pmlmeinfo->bwmode_updated)
6183 DBG_88E("%s\n", __func__);
6186 category = RTW_WLAN_CATEGORY_PUBLIC;
6187 action = ACT_PUBLIC_BSSCOEXIST;
6189 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
6190 if (pmgntframe == NULL)
6193 /* update attribute */
6194 pattrib = &pmgntframe->attrib;
6195 update_mgntframe_attrib(padapter, pattrib);
6197 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
6199 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
6200 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
6202 fctrl = &(pwlanhdr->frame_ctl);
6205 memcpy(pwlanhdr->addr1, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6206 memcpy(pwlanhdr->addr2, myid(&(padapter->eeprompriv)), ETH_ALEN);
6207 memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
6209 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
6210 pmlmeext->mgnt_seq++;
6211 SetFrameSubType(pframe, WIFI_ACTION);
6213 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
6214 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
6216 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
6217 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
6221 if (pmlmepriv->num_FortyMHzIntolerant > 0) {
6224 iedata |= BIT(2);/* 20 MHz BSS Width Request */
6226 pframe = rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
6231 _rtw_memset(ICS, 0, sizeof(ICS));
6232 if (pmlmepriv->num_sta_no_ht > 0) {
6235 spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
6237 phead = get_list_head(queue);
6238 plist = phead->next;
6243 struct wlan_bssid_ex *pbss_network;
6245 if (rtw_end_of_queue_search(phead, plist))
6248 pnetwork = container_of(plist, struct wlan_network, list);
6250 plist = plist->next;
6252 pbss_network = (struct wlan_bssid_ex *)&pnetwork->network;
6254 p = rtw_get_ie(pbss_network->IEs + _FIXED_IE_LENGTH_, _HT_CAPABILITY_IE_, &len, pbss_network->IELength - _FIXED_IE_LENGTH_);
6255 if ((p == NULL) || (len == 0)) { /* non-HT */
6256 if ((pbss_network->Configuration.DSConfig <= 0) || (pbss_network->Configuration.DSConfig > 14))
6259 ICS[0][pbss_network->Configuration.DSConfig] = 1;
6265 spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
6267 for (i = 0; i < 8; i++) {
6268 if (ICS[i][0] == 1) {
6272 /* SET_BSS_INTOLERANT_ELE_REG_CLASS(InfoContent, i); */
6275 for (j = 1; j <= 14; j++) {
6276 if (ICS[i][j] == 1) {
6278 InfoContent[k] = j; /* channel number */
6279 /* SET_BSS_INTOLERANT_ELE_CHANNEL(InfoContent+k, j); */
6285 pframe = rtw_set_ie(pframe, EID_BSSIntolerantChlReport, k, InfoContent, &(pattrib->pktlen));
6291 pattrib->last_txcmdsz = pattrib->pktlen;
6293 dump_mgntframe(padapter, pmgntframe);
6296 unsigned int send_delba(struct adapter *padapter, u8 initiator, u8 *addr)
6298 struct sta_priv *pstapriv = &padapter->stapriv;
6299 struct sta_info *psta = NULL;
6300 /* struct recv_reorder_ctrl *preorder_ctrl; */
6301 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6302 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6305 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
6306 if (!(pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS))
6309 psta = rtw_get_stainfo(pstapriv, addr);
6313 if (initiator == 0) { /* recipient */
6314 for (tid = 0; tid < MAXTID; tid++) {
6315 if (psta->recvreorder_ctrl[tid].enable) {
6316 DBG_88E("rx agg disable tid(%d)\n", tid);
6317 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6318 psta->recvreorder_ctrl[tid].enable = false;
6319 psta->recvreorder_ctrl[tid].indicate_seq = 0xffff;
6322 } else if (initiator == 1) { /* originator */
6323 for (tid = 0; tid < MAXTID; tid++) {
6324 if (psta->htpriv.agg_enable_bitmap & BIT(tid)) {
6325 DBG_88E("tx agg disable tid(%d)\n", tid);
6326 issue_action_BA(padapter, addr, RTW_WLAN_ACTION_DELBA, (((tid << 1) | initiator)&0x1F));
6327 psta->htpriv.agg_enable_bitmap &= ~BIT(tid);
6328 psta->htpriv.candidate_tid_bitmap &= ~BIT(tid);
6336 unsigned int send_beacon(struct adapter *padapter)
6342 u32 start = jiffies;
6344 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_VALID, NULL);
6346 issue_beacon(padapter, 100);
6350 rtw_hal_get_hwreg(padapter, HW_VAR_BCN_VALID, (u8 *)(&bxmitok));
6352 } while ((poll%10) != 0 && !bxmitok && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6353 } while (!bxmitok && issue < 100 && !padapter->bSurpriseRemoved && !padapter->bDriverStopped);
6355 if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
6358 DBG_88E("%s fail! %u ms\n", __func__, rtw_get_passing_time_ms(start));
6361 u32 passing_time = rtw_get_passing_time_ms(start);
6363 if (passing_time > 100 || issue > 3)
6364 DBG_88E("%s success, issue:%d, poll:%d, %u ms\n", __func__, issue, poll, rtw_get_passing_time_ms(start));
6369 /****************************************************************************
6371 Following are some utility functions for WiFi MLME
6373 *****************************************************************************/
6375 void site_survey(struct adapter *padapter)
6377 unsigned char survey_channel = 0, val8;
6378 enum rt_scan_type ScanType = SCAN_PASSIVE;
6379 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6380 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6381 u32 initialgain = 0;
6383 #ifdef CONFIG_88EU_P2P
6384 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
6386 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6387 if (pwdinfo->rx_invitereq_info.scan_op_ch_only) {
6388 survey_channel = pwdinfo->rx_invitereq_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6390 survey_channel = pwdinfo->p2p_info.operation_ch[pmlmeext->sitesurvey_res.channel_idx];
6392 ScanType = SCAN_ACTIVE;
6393 } else if (rtw_p2p_findphase_ex_is_social(pwdinfo)) {
6394 /* Commented by Albert 2011/06/03 */
6395 /* The driver is in the find phase, it should go through the social channel. */
6397 survey_channel = pwdinfo->social_chan[pmlmeext->sitesurvey_res.channel_idx];
6398 ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, survey_channel);
6399 if (ch_set_idx >= 0)
6400 ScanType = pmlmeext->channel_set[ch_set_idx].ScanType;
6402 ScanType = SCAN_ACTIVE;
6404 #endif /* CONFIG_88EU_P2P */
6406 struct rtw_ieee80211_channel *ch;
6407 if (pmlmeext->sitesurvey_res.channel_idx < pmlmeext->sitesurvey_res.ch_num) {
6408 ch = &pmlmeext->sitesurvey_res.ch[pmlmeext->sitesurvey_res.channel_idx];
6409 survey_channel = ch->hw_value;
6410 ScanType = (ch->flags & RTW_IEEE80211_CHAN_PASSIVE_SCAN) ? SCAN_PASSIVE : SCAN_ACTIVE;
6414 if (survey_channel != 0) {
6415 /* PAUSE 4-AC Queue when site_survey */
6416 /* rtw_hal_get_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6418 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6419 if (pmlmeext->sitesurvey_res.channel_idx == 0)
6420 set_channel_bwmode(padapter, survey_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6422 SelectChannel(padapter, survey_channel);
6424 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */
6425 #ifdef CONFIG_88EU_P2P
6426 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) ||
6427 rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6428 issue_probereq_p2p(padapter, NULL);
6429 issue_probereq_p2p(padapter, NULL);
6430 issue_probereq_p2p(padapter, NULL);
6432 #endif /* CONFIG_88EU_P2P */
6435 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
6436 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
6437 /* todo: to issue two probe req??? */
6438 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6439 /* msleep(SURVEY_TO>>1); */
6440 issue_probereq(padapter, &(pmlmeext->sitesurvey_res.ssid[i]), NULL);
6444 if (pmlmeext->sitesurvey_res.scan_mode == SCAN_ACTIVE) {
6445 /* todo: to issue two probe req??? */
6446 issue_probereq(padapter, NULL, NULL);
6447 /* msleep(SURVEY_TO>>1); */
6448 issue_probereq(padapter, NULL, NULL);
6453 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6455 /* channel number is 0 or this channel is not valid. */
6457 #ifdef CONFIG_88EU_P2P
6458 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH)) {
6459 if ((pwdinfo->rx_invitereq_info.scan_op_ch_only) || (pwdinfo->p2p_info.scan_op_ch_only)) {
6460 /* Set the find_phase_state_exchange_cnt to P2P_FINDPHASE_EX_CNT. */
6461 /* This will let the following flow to run the scanning end. */
6462 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
6466 if (rtw_p2p_findphase_ex_is_needed(pwdinfo)) {
6467 /* Set the P2P State to the listen state of find phase and set the current channel to the listen channel */
6468 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6469 rtw_p2p_set_state(pwdinfo, P2P_STATE_FIND_PHASE_LISTEN);
6470 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6472 initialgain = 0xff; /* restore RX GAIN */
6473 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6474 /* turn on dynamic functions */
6475 Restore_DM_Func_Flag(padapter);
6476 /* Switch_DM_Func(padapter, DYNAMIC_FUNC_DIG|DYNAMIC_FUNC_HP|DYNAMIC_FUNC_SS, true); */
6478 _set_timer(&pwdinfo->find_phase_timer, (u32)((u32)(pwdinfo->listen_dwell) * 100));
6480 #endif /* CONFIG_88EU_P2P */
6482 /* 20100721:Interrupt scan operation here. */
6483 /* For SW antenna diversity before link, it needs to switch to another antenna and scan again. */
6484 /* It compares the scan result and select better one to do connection. */
6485 if (rtw_hal_antdiv_before_linked(padapter)) {
6486 pmlmeext->sitesurvey_res.bss_cnt = 0;
6487 pmlmeext->sitesurvey_res.channel_idx = -1;
6488 pmlmeext->chan_scan_time = SURVEY_TO / 2;
6489 set_survey_timer(pmlmeext, pmlmeext->chan_scan_time);
6492 #ifdef CONFIG_88EU_P2P
6493 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_SCAN) || rtw_p2p_chk_state(pwdinfo, P2P_STATE_FIND_PHASE_SEARCH))
6494 rtw_p2p_set_state(pwdinfo, rtw_p2p_pre_state(pwdinfo));
6495 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_NONE);
6496 #endif /* CONFIG_88EU_P2P */
6498 pmlmeext->sitesurvey_res.state = SCAN_COMPLETE;
6500 /* switch back to the original channel */
6502 #ifdef CONFIG_88EU_P2P
6503 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN))
6504 set_channel_bwmode(padapter, pwdinfo->listen_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6506 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6507 #endif /* CONFIG_88EU_P2P */
6509 /* flush 4-AC Queue after site_survey */
6511 /* rtw_hal_set_hwreg(padapter, HW_VAR_TXPAUSE, (u8 *)(&val8)); */
6514 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6516 initialgain = 0xff; /* restore RX GAIN */
6517 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
6518 /* turn on dynamic functions */
6519 Restore_DM_Func_Flag(padapter);
6520 /* Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true); */
6522 if (is_client_associated_to_ap(padapter))
6523 issue_nulldata(padapter, NULL, 0, 3, 500);
6525 val8 = 0; /* survey done */
6526 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
6528 report_surveydone_event(padapter);
6530 pmlmeext->chan_scan_time = SURVEY_TO;
6531 pmlmeext->sitesurvey_res.state = SCAN_DISABLE;
6533 issue_action_BSSCoexistPacket(padapter);
6534 issue_action_BSSCoexistPacket(padapter);
6535 issue_action_BSSCoexistPacket(padapter);
6541 /* collect bss info from Beacon and Probe request/response frames. */
6542 u8 collect_bss_info(struct adapter *padapter, struct recv_frame *precv_frame, struct wlan_bssid_ex *bssid)
6548 u8 *pframe = precv_frame->rx_data;
6549 u32 packet_len = precv_frame->len;
6551 struct registry_priv *pregistrypriv = &padapter->registrypriv;
6552 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6553 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6555 len = packet_len - sizeof(struct rtw_ieee80211_hdr_3addr);
6557 if (len > MAX_IE_SZ)
6560 _rtw_memset(bssid, 0, sizeof(struct wlan_bssid_ex));
6562 subtype = GetFrameSubType(pframe);
6564 if (subtype == WIFI_BEACON) {
6565 bssid->Reserved[0] = 1;
6566 ie_offset = _BEACON_IE_OFFSET_;
6568 /* FIXME : more type */
6569 if (subtype == WIFI_PROBEREQ) {
6570 ie_offset = _PROBEREQ_IE_OFFSET_;
6571 bssid->Reserved[0] = 2;
6572 } else if (subtype == WIFI_PROBERSP) {
6573 ie_offset = _PROBERSP_IE_OFFSET_;
6574 bssid->Reserved[0] = 3;
6576 bssid->Reserved[0] = 0;
6577 ie_offset = _FIXED_IE_LENGTH_;
6581 bssid->Length = sizeof(struct wlan_bssid_ex) - MAX_IE_SZ + len;
6583 /* below is to copy the information element */
6584 bssid->IELength = len;
6585 memcpy(bssid->IEs, (pframe + sizeof(struct rtw_ieee80211_hdr_3addr)), bssid->IELength);
6587 /* get the signal strength in dBM.raw data */
6588 bssid->Rssi = precv_frame->attrib.phy_info.recvpower;
6589 bssid->PhyInfo.SignalQuality = precv_frame->attrib.phy_info.SignalQuality;/* in percentage */
6590 bssid->PhyInfo.SignalStrength = precv_frame->attrib.phy_info.SignalStrength;/* in percentage */
6591 rtw_hal_get_def_var(padapter, HAL_DEF_CURRENT_ANTENNA, &bssid->PhyInfo.Optimum_antenna);
6594 p = rtw_get_ie(bssid->IEs + ie_offset, _SSID_IE_, &len, bssid->IELength - ie_offset);
6596 DBG_88E("marc: cannot find SSID for survey event\n");
6601 if (len > NDIS_802_11_LENGTH_SSID) {
6602 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6605 memcpy(bssid->Ssid.Ssid, (p + 2), len);
6606 bssid->Ssid.SsidLength = len;
6608 bssid->Ssid.SsidLength = 0;
6611 _rtw_memset(bssid->SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
6613 /* checking rate info... */
6615 p = rtw_get_ie(bssid->IEs + ie_offset, _SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6617 if (len > NDIS_802_11_LENGTH_RATES_EX) {
6618 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6621 memcpy(bssid->SupportedRates, (p + 2), len);
6625 p = rtw_get_ie(bssid->IEs + ie_offset, _EXT_SUPPORTEDRATES_IE_, &len, bssid->IELength - ie_offset);
6627 if (len > (NDIS_802_11_LENGTH_RATES_EX-i)) {
6628 DBG_88E("%s()-%d: IE too long (%d) for survey event\n", __func__, __LINE__, len);
6631 memcpy(bssid->SupportedRates + i, (p + 2), len);
6635 bssid->NetworkTypeInUse = Ndis802_11OFDM24;
6637 if (bssid->IELength < 12)
6640 /* Checking for DSConfig */
6641 p = rtw_get_ie(bssid->IEs + ie_offset, _DSSET_IE_, &len, bssid->IELength - ie_offset);
6643 bssid->Configuration.DSConfig = 0;
6644 bssid->Configuration.Length = 0;
6647 bssid->Configuration.DSConfig = *(p + 2);
6648 } else {/* In 5G, some ap do not have DSSET IE */
6649 /* checking HT info for channel */
6650 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
6652 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
6653 bssid->Configuration.DSConfig = HT_info->primary_channel;
6654 } else { /* use current channel */
6655 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
6659 if (subtype == WIFI_PROBEREQ) {
6661 bssid->InfrastructureMode = Ndis802_11Infrastructure;
6662 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
6667 bssid->Configuration.BeaconPeriod =
6668 get_unaligned_le16(rtw_get_beacon_interval_from_ie(bssid->IEs));
6670 val16 = rtw_get_capability((struct wlan_bssid_ex *)bssid);
6672 if (val16 & BIT(0)) {
6673 bssid->InfrastructureMode = Ndis802_11Infrastructure;
6674 memcpy(bssid->MacAddress, GetAddr2Ptr(pframe), ETH_ALEN);
6676 bssid->InfrastructureMode = Ndis802_11IBSS;
6677 memcpy(bssid->MacAddress, GetAddr3Ptr(pframe), ETH_ALEN);
6685 bssid->Configuration.ATIMWindow = 0;
6687 /* 20/40 BSS Coexistence check */
6688 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) {
6689 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
6690 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
6692 struct HT_caps_element *pHT_caps;
6693 pHT_caps = (struct HT_caps_element *)(p + 2);
6695 if (le16_to_cpu(pHT_caps->u.HT_cap_element.HT_caps_info)&BIT(14))
6696 pmlmepriv->num_FortyMHzIntolerant++;
6698 pmlmepriv->num_sta_no_ht++;
6702 /* mark bss info receiving from nearby channel as SignalQuality 101 */
6703 if (bssid->Configuration.DSConfig != rtw_get_oper_ch(padapter))
6704 bssid->PhyInfo.SignalQuality = 101;
6708 void start_create_ibss(struct adapter *padapter)
6710 unsigned short caps;
6713 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6714 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6715 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6716 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6717 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6719 /* update wireless mode */
6720 update_wireless_mode(padapter);
6722 /* update capability */
6723 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6724 update_capinfo(padapter, caps);
6725 if (caps&cap_IBSS) {/* adhoc master */
6727 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6729 /* switch channel */
6730 /* SelectChannel(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE); */
6731 set_channel_bwmode(padapter, pmlmeext->cur_channel, HAL_PRIME_CHNL_OFFSET_DONT_CARE, HT_CHANNEL_WIDTH_20);
6733 beacon_timing_control(padapter);
6735 /* set msr to WIFI_FW_ADHOC_STATE */
6736 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6737 Set_MSR(padapter, (pmlmeinfo->state & 0x3));
6740 if (send_beacon(padapter) == _FAIL) {
6741 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("issuing beacon frame fail....\n"));
6743 report_join_res(padapter, -1);
6744 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6746 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, padapter->registrypriv.dev_network.MacAddress);
6748 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
6750 report_join_res(padapter, 1);
6751 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
6754 DBG_88E("start_create_ibss, invalid cap:%x\n", caps);
6759 void start_clnt_join(struct adapter *padapter)
6761 unsigned short caps;
6763 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6764 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6765 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
6768 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
6769 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
6771 /* update wireless mode */
6772 update_wireless_mode(padapter);
6774 /* update capability */
6775 caps = rtw_get_capability((struct wlan_bssid_ex *)pnetwork);
6776 update_capinfo(padapter, caps);
6778 Set_MSR(padapter, WIFI_FW_STATION_STATE);
6780 val8 = (pmlmeinfo->auth_algo == dot11AuthAlgrthm_8021X) ? 0xcc : 0xcf;
6782 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6784 /* switch channel */
6785 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6787 /* here wait for receiving the beacon to start auth */
6788 /* and enable a timer */
6789 beacon_timeout = decide_wait_for_beacon_timeout(pmlmeinfo->bcn_interval);
6790 set_link_timer(pmlmeext, beacon_timeout);
6791 _set_timer(&padapter->mlmepriv.assoc_timer,
6792 (REAUTH_TO * REAUTH_LIMIT) + (REASSOC_TO*REASSOC_LIMIT) + beacon_timeout);
6794 pmlmeinfo->state = WIFI_FW_AUTH_NULL | WIFI_FW_STATION_STATE;
6795 } else if (caps&cap_IBSS) { /* adhoc client */
6796 Set_MSR(padapter, WIFI_FW_ADHOC_STATE);
6799 rtw_hal_set_hwreg(padapter, HW_VAR_SEC_CFG, (u8 *)(&val8));
6801 /* switch channel */
6802 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
6804 beacon_timing_control(padapter);
6806 pmlmeinfo->state = WIFI_FW_ADHOC_STATE;
6808 report_join_res(padapter, 1);
6814 void start_clnt_auth(struct adapter *padapter)
6816 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6817 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6819 _cancel_timer_ex(&pmlmeext->link_timer);
6821 pmlmeinfo->state &= (~WIFI_FW_AUTH_NULL);
6822 pmlmeinfo->state |= WIFI_FW_AUTH_STATE;
6824 pmlmeinfo->auth_seq = 1;
6825 pmlmeinfo->reauth_count = 0;
6826 pmlmeinfo->reassoc_count = 0;
6827 pmlmeinfo->link_count = 0;
6828 pmlmeext->retry = 0;
6831 /* Because of AP's not receiving deauth before */
6832 /* AP may: 1)not response auth or 2)deauth us after link is complete */
6833 /* issue deauth before issuing auth to deal with the situation */
6834 /* Commented by Albert 2012/07/21 */
6835 /* For the Win8 P2P connection, it will be hard to have a successful connection if this Wi-Fi doesn't connect to it. */
6836 issue_deauth(padapter, (&(pmlmeinfo->network))->MacAddress, WLAN_REASON_DEAUTH_LEAVING);
6838 DBG_88E_LEVEL(_drv_info_, "start auth\n");
6839 issue_auth(padapter, NULL, 0);
6841 set_link_timer(pmlmeext, REAUTH_TO);
6845 void start_clnt_assoc(struct adapter *padapter)
6847 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6848 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6850 _cancel_timer_ex(&pmlmeext->link_timer);
6852 pmlmeinfo->state &= (~(WIFI_FW_AUTH_NULL | WIFI_FW_AUTH_STATE));
6853 pmlmeinfo->state |= (WIFI_FW_AUTH_SUCCESS | WIFI_FW_ASSOC_STATE);
6855 issue_assocreq(padapter);
6857 set_link_timer(pmlmeext, REASSOC_TO);
6860 unsigned int receive_disconnect(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
6862 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
6863 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
6866 if (memcmp(MacAddr, get_my_bssid(&pmlmeinfo->network), ETH_ALEN))
6869 DBG_88E("%s\n", __func__);
6871 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
6872 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
6873 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6874 report_del_sta_event(padapter, MacAddr, reason);
6875 } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
6876 pmlmeinfo->state = WIFI_FW_NULL_STATE;
6877 report_join_res(padapter, -2);
6883 static void process_80211d(struct adapter *padapter, struct wlan_bssid_ex *bssid)
6885 struct registry_priv *pregistrypriv;
6886 struct mlme_ext_priv *pmlmeext;
6887 struct rt_channel_info *chplan_new;
6891 pregistrypriv = &padapter->registrypriv;
6892 pmlmeext = &padapter->mlmeextpriv;
6894 /* Adjust channel plan by AP Country IE */
6895 if (pregistrypriv->enable80211d &&
6896 (!pmlmeext->update_channel_plan_by_ap_done)) {
6899 struct rt_channel_plan chplan_ap;
6900 struct rt_channel_info chplan_sta[MAX_CHANNEL_NUM];
6902 u8 fcn; /* first channel number */
6903 u8 noc; /* number of channel */
6906 ie = rtw_get_ie(bssid->IEs + _FIXED_IE_LENGTH_, _COUNTRY_IE_, &len, bssid->IELength - _FIXED_IE_LENGTH_);
6915 _rtw_memset(country, 0, 4);
6916 memcpy(country, p, 3);
6918 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
6919 ("%s: 802.11d country =%s\n", __func__, country));
6922 while ((ie - p) >= 3) {
6927 for (j = 0; j < noc; j++) {
6929 channel = fcn + j; /* 2.4 GHz */
6931 channel = fcn + j*4; /* 5 GHz */
6933 chplan_ap.Channel[i++] = channel;
6938 memcpy(chplan_sta, pmlmeext->channel_set, sizeof(chplan_sta));
6940 _rtw_memset(pmlmeext->channel_set, 0, sizeof(pmlmeext->channel_set));
6941 chplan_new = pmlmeext->channel_set;
6946 if (pregistrypriv->wireless_mode & WIRELESS_11G) {
6948 if ((i == MAX_CHANNEL_NUM) ||
6949 (chplan_sta[i].ChannelNum == 0) ||
6950 (chplan_sta[i].ChannelNum > 14))
6953 if ((j == chplan_ap.Len) || (chplan_ap.Channel[j] > 14))
6956 if (chplan_sta[i].ChannelNum == chplan_ap.Channel[j]) {
6957 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6958 chplan_new[k].ScanType = SCAN_ACTIVE;
6962 } else if (chplan_sta[i].ChannelNum < chplan_ap.Channel[j]) {
6963 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6964 chplan_new[k].ScanType = SCAN_PASSIVE;
6967 } else if (chplan_sta[i].ChannelNum > chplan_ap.Channel[j]) {
6968 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6969 chplan_new[k].ScanType = SCAN_ACTIVE;
6975 /* change AP not support channel to Passive scan */
6976 while ((i < MAX_CHANNEL_NUM) &&
6977 (chplan_sta[i].ChannelNum != 0) &&
6978 (chplan_sta[i].ChannelNum <= 14)) {
6979 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6980 chplan_new[k].ScanType = SCAN_PASSIVE;
6985 /* add channel AP supported */
6986 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14)) {
6987 chplan_new[k].ChannelNum = chplan_ap.Channel[j];
6988 chplan_new[k].ScanType = SCAN_ACTIVE;
6993 /* keep original STA 2.4G channel plan */
6994 while ((i < MAX_CHANNEL_NUM) &&
6995 (chplan_sta[i].ChannelNum != 0) &&
6996 (chplan_sta[i].ChannelNum <= 14)) {
6997 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
6998 chplan_new[k].ScanType = chplan_sta[i].ScanType;
7003 /* skip AP 2.4G channel plan */
7004 while ((j < chplan_ap.Len) && (chplan_ap.Channel[j] <= 14))
7008 /* keep original STA 5G channel plan */
7009 while ((i < MAX_CHANNEL_NUM) && (chplan_sta[i].ChannelNum != 0)) {
7010 chplan_new[k].ChannelNum = chplan_sta[i].ChannelNum;
7011 chplan_new[k].ScanType = chplan_sta[i].ScanType;
7016 pmlmeext->update_channel_plan_by_ap_done = 1;
7019 /* If channel is used by AP, set channel scan type to active */
7020 channel = bssid->Configuration.DSConfig;
7021 chplan_new = pmlmeext->channel_set;
7023 while ((i < MAX_CHANNEL_NUM) && (chplan_new[i].ChannelNum != 0)) {
7024 if (chplan_new[i].ChannelNum == channel) {
7025 if (chplan_new[i].ScanType == SCAN_PASSIVE) {
7026 chplan_new[i].ScanType = SCAN_ACTIVE;
7027 RT_TRACE(_module_rtl871x_mlme_c_, _drv_notice_,
7028 ("%s: change channel %d scan type from passive to active\n",
7029 __func__, channel));
7037 /****************************************************************************
7039 Following are the functions to report events
7041 *****************************************************************************/
7043 void report_survey_event(struct adapter *padapter,
7044 struct recv_frame *precv_frame)
7046 struct cmd_obj *pcmd_obj;
7049 struct survey_event *psurvey_evt;
7050 struct C2HEvent_Header *pc2h_evt_hdr;
7051 struct mlme_ext_priv *pmlmeext;
7052 struct cmd_priv *pcmdpriv;
7057 pmlmeext = &padapter->mlmeextpriv;
7058 pcmdpriv = &padapter->cmdpriv;
7061 pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7062 if (pcmd_obj == NULL)
7065 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
7066 pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
7067 if (pevtcmd == NULL) {
7072 _rtw_init_listhead(&pcmd_obj->list);
7074 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7075 pcmd_obj->cmdsz = cmdsz;
7076 pcmd_obj->parmbuf = pevtcmd;
7078 pcmd_obj->rsp = NULL;
7079 pcmd_obj->rspsz = 0;
7081 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7082 pc2h_evt_hdr->len = sizeof(struct survey_event);
7083 pc2h_evt_hdr->ID = GEN_EVT_CODE(_Survey);
7084 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7086 psurvey_evt = (struct survey_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7088 if (collect_bss_info(padapter, precv_frame, (struct wlan_bssid_ex *)&psurvey_evt->bss) == _FAIL) {
7094 process_80211d(padapter, &psurvey_evt->bss);
7096 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7098 pmlmeext->sitesurvey_res.bss_cnt++;
7103 void report_surveydone_event(struct adapter *padapter)
7105 struct cmd_obj *pcmd_obj;
7108 struct surveydone_event *psurveydone_evt;
7109 struct C2HEvent_Header *pc2h_evt_hdr;
7110 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7111 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7113 pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7114 if (pcmd_obj == NULL)
7117 cmdsz = (sizeof(struct surveydone_event) + sizeof(struct C2HEvent_Header));
7118 pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
7119 if (pevtcmd == NULL) {
7124 _rtw_init_listhead(&pcmd_obj->list);
7126 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7127 pcmd_obj->cmdsz = cmdsz;
7128 pcmd_obj->parmbuf = pevtcmd;
7130 pcmd_obj->rsp = NULL;
7131 pcmd_obj->rspsz = 0;
7133 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7134 pc2h_evt_hdr->len = sizeof(struct surveydone_event);
7135 pc2h_evt_hdr->ID = GEN_EVT_CODE(_SurveyDone);
7136 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7138 psurveydone_evt = (struct surveydone_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7139 psurveydone_evt->bss_cnt = pmlmeext->sitesurvey_res.bss_cnt;
7141 DBG_88E("survey done event(%x)\n", psurveydone_evt->bss_cnt);
7143 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7148 void report_join_res(struct adapter *padapter, int res)
7150 struct cmd_obj *pcmd_obj;
7153 struct joinbss_event *pjoinbss_evt;
7154 struct C2HEvent_Header *pc2h_evt_hdr;
7155 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7156 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7157 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7159 pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7160 if (pcmd_obj == NULL)
7163 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
7164 pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
7165 if (pevtcmd == NULL) {
7170 _rtw_init_listhead(&pcmd_obj->list);
7172 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7173 pcmd_obj->cmdsz = cmdsz;
7174 pcmd_obj->parmbuf = pevtcmd;
7176 pcmd_obj->rsp = NULL;
7177 pcmd_obj->rspsz = 0;
7179 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7180 pc2h_evt_hdr->len = sizeof(struct joinbss_event);
7181 pc2h_evt_hdr->ID = GEN_EVT_CODE(_JoinBss);
7182 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7184 pjoinbss_evt = (struct joinbss_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7185 memcpy((unsigned char *)(&(pjoinbss_evt->network.network)), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
7186 pjoinbss_evt->network.join_res = res;
7187 pjoinbss_evt->network.aid = res;
7189 DBG_88E("report_join_res(%d)\n", res);
7192 rtw_joinbss_event_prehandle(padapter, (u8 *)&pjoinbss_evt->network);
7195 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7200 void report_del_sta_event(struct adapter *padapter, unsigned char *MacAddr, unsigned short reason)
7202 struct cmd_obj *pcmd_obj;
7205 struct sta_info *psta;
7207 struct stadel_event *pdel_sta_evt;
7208 struct C2HEvent_Header *pc2h_evt_hdr;
7209 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7210 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7212 pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7213 if (pcmd_obj == NULL)
7216 cmdsz = (sizeof(struct stadel_event) + sizeof(struct C2HEvent_Header));
7217 pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
7218 if (pevtcmd == NULL) {
7223 _rtw_init_listhead(&pcmd_obj->list);
7225 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7226 pcmd_obj->cmdsz = cmdsz;
7227 pcmd_obj->parmbuf = pevtcmd;
7229 pcmd_obj->rsp = NULL;
7230 pcmd_obj->rspsz = 0;
7232 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7233 pc2h_evt_hdr->len = sizeof(struct stadel_event);
7234 pc2h_evt_hdr->ID = GEN_EVT_CODE(_DelSTA);
7235 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7237 pdel_sta_evt = (struct stadel_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7238 memcpy((unsigned char *)(&(pdel_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7239 memcpy((unsigned char *)(pdel_sta_evt->rsvd), (unsigned char *)(&reason), 2);
7242 psta = rtw_get_stainfo(&padapter->stapriv, MacAddr);
7244 mac_id = (int)psta->mac_id;
7248 pdel_sta_evt->mac_id = mac_id;
7250 DBG_88E("report_del_sta_event: delete STA, mac_id =%d\n", mac_id);
7252 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7257 void report_add_sta_event(struct adapter *padapter, unsigned char *MacAddr, int cam_idx)
7259 struct cmd_obj *pcmd_obj;
7262 struct stassoc_event *padd_sta_evt;
7263 struct C2HEvent_Header *pc2h_evt_hdr;
7264 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7265 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7267 pcmd_obj = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7268 if (pcmd_obj == NULL)
7271 cmdsz = (sizeof(struct stassoc_event) + sizeof(struct C2HEvent_Header));
7272 pevtcmd = (u8 *)rtw_zmalloc(cmdsz);
7273 if (pevtcmd == NULL) {
7278 _rtw_init_listhead(&pcmd_obj->list);
7280 pcmd_obj->cmdcode = GEN_CMD_CODE(_Set_MLME_EVT);
7281 pcmd_obj->cmdsz = cmdsz;
7282 pcmd_obj->parmbuf = pevtcmd;
7284 pcmd_obj->rsp = NULL;
7285 pcmd_obj->rspsz = 0;
7287 pc2h_evt_hdr = (struct C2HEvent_Header *)(pevtcmd);
7288 pc2h_evt_hdr->len = sizeof(struct stassoc_event);
7289 pc2h_evt_hdr->ID = GEN_EVT_CODE(_AddSTA);
7290 pc2h_evt_hdr->seq = atomic_inc_return(&pmlmeext->event_seq);
7292 padd_sta_evt = (struct stassoc_event *)(pevtcmd + sizeof(struct C2HEvent_Header));
7293 memcpy((unsigned char *)(&(padd_sta_evt->macaddr)), MacAddr, ETH_ALEN);
7294 padd_sta_evt->cam_id = cam_idx;
7296 DBG_88E("report_add_sta_event: add STA\n");
7298 rtw_enqueue_cmd(pcmdpriv, pcmd_obj);
7304 /****************************************************************************
7306 Following are the event callback functions
7308 *****************************************************************************/
7310 /* for sta/adhoc mode */
7311 void update_sta_info(struct adapter *padapter, struct sta_info *psta)
7313 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
7314 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7315 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7318 VCS_update(padapter, psta);
7321 if (pmlmepriv->htpriv.ht_option) {
7322 psta->htpriv.ht_option = true;
7324 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
7326 if (support_short_GI(padapter, &(pmlmeinfo->HT_caps)))
7327 psta->htpriv.sgi = true;
7329 psta->qos_option = true;
7331 psta->htpriv.ht_option = false;
7333 psta->htpriv.ampdu_enable = false;
7335 psta->htpriv.sgi = false;
7336 psta->qos_option = false;
7338 psta->htpriv.bwmode = pmlmeext->cur_bwmode;
7339 psta->htpriv.ch_offset = pmlmeext->cur_ch_offset;
7341 psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
7342 psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
7345 if (pmlmepriv->qospriv.qos_option)
7346 psta->qos_option = true;
7349 psta->state = _FW_LINKED;
7352 void mlmeext_joinbss_event_callback(struct adapter *padapter, int join_res)
7354 struct sta_info *psta, *psta_bmc;
7355 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7356 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7357 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
7358 struct sta_priv *pstapriv = &padapter->stapriv;
7364 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7365 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7367 /* restore to initial setting. */
7368 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7370 goto exit_mlmeext_joinbss_event_callback;
7373 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7375 psta_bmc = rtw_get_bcmc_stainfo(padapter);
7377 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc;
7378 update_bmc_sta_support_rate(padapter, psta_bmc->mac_id);
7379 Update_RA_Entry(padapter, psta_bmc->mac_id);
7384 /* turn on dynamic functions */
7385 Switch_DM_Func(padapter, DYNAMIC_ALL_FUNC_ENABLE, true);
7387 /* update IOT-related issue */
7388 update_IOT_info(padapter);
7390 rtw_hal_set_hwreg(padapter, HW_VAR_BASIC_RATE, cur_network->SupportedRates);
7393 rtw_hal_set_hwreg(padapter, HW_VAR_BEACON_INTERVAL, (u8 *)(&pmlmeinfo->bcn_interval));
7395 /* update capability */
7396 update_capinfo(padapter, pmlmeinfo->capability);
7398 /* WMM, Update EDCA param */
7399 WMMOnAssocRsp(padapter);
7402 HTOnAssocRsp(padapter);
7404 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7406 psta = rtw_get_stainfo(pstapriv, cur_network->MacAddress);
7407 if (psta) { /* only for infra. mode */
7408 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7410 psta->wireless_mode = pmlmeext->cur_wireless_mode;
7412 /* set per sta rate after updating HT cap. */
7413 set_sta_rate(padapter, psta);
7414 rtw_hal_set_hwreg(padapter, HW_VAR_TX_RPT_MAX_MACID, (u8 *)&psta->mac_id);
7415 media_status = (psta->mac_id<<8)|1; /* MACID|OPMODE: 1 means connect */
7416 rtw_hal_set_hwreg(padapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
7420 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7422 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE) {
7423 /* correcting TSF */
7424 correct_TSF(padapter, pmlmeext);
7426 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_CONNECT, 0);
7428 exit_mlmeext_joinbss_event_callback:
7430 DBG_88E("=>%s\n", __func__);
7433 void mlmeext_sta_add_event_callback(struct adapter *padapter, struct sta_info *psta)
7435 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
7436 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7439 DBG_88E("%s\n", __func__);
7441 if ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) {
7442 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {/* adhoc master or sta_count>1 */
7444 } else { /* adhoc client */
7445 /* correcting TSF */
7446 correct_TSF(padapter, pmlmeext);
7449 if (send_beacon(padapter) == _FAIL) {
7450 pmlmeinfo->FW_sta_info[psta->mac_id].status = 0;
7451 pmlmeinfo->state ^= WIFI_FW_ADHOC_STATE;
7454 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
7458 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7461 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
7463 /* rate radaptive */
7464 Update_RA_Entry(padapter, psta->mac_id);
7466 /* update adhoc sta_info */
7467 update_sta_info(padapter, psta);
7470 void mlmeext_sta_del_event_callback(struct adapter *padapter)
7472 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7473 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7475 if (is_client_associated_to_ap(padapter) || is_IBSS_empty(padapter)) {
7476 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7477 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7479 /* restore to initial setting. */
7480 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7482 /* switch to the 20M Hz mode after disconnect */
7483 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7484 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7486 /* SelectChannel(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset); */
7487 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
7490 flush_all_cam_entry(padapter);
7492 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7494 /* set MSR to no link state -> infra. mode */
7495 Set_MSR(padapter, _HW_STATE_STATION_);
7497 _cancel_timer_ex(&pmlmeext->link_timer);
7501 /****************************************************************************
7503 Following are the functions for the timer handlers
7505 *****************************************************************************/
7506 void _linked_rx_signal_strehgth_display(struct adapter *padapter);
7507 void _linked_rx_signal_strehgth_display(struct adapter *padapter)
7509 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7510 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7512 int UndecoratedSmoothedPWDB;
7513 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
7515 else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
7518 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &mac_id);
7520 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
7521 DBG_88E("UndecoratedSmoothedPWDB:%d\n", UndecoratedSmoothedPWDB);
7524 static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta)
7528 if ((sta_rx_data_pkts(psta) == sta_last_rx_data_pkts(psta)) &&
7529 sta_rx_beacon_pkts(psta) == sta_last_rx_beacon_pkts(psta) &&
7530 sta_rx_probersp_pkts(psta) == sta_last_rx_probersp_pkts(psta))
7535 sta_update_last_rx_pkts(psta);
7540 void linked_status_chk(struct adapter *padapter)
7543 struct sta_info *psta;
7544 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
7545 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7546 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7547 struct sta_priv *pstapriv = &padapter->stapriv;
7549 if (padapter->bRxRSSIDisplay)
7550 _linked_rx_signal_strehgth_display(padapter);
7552 rtw_hal_sreset_linked_status_check(padapter);
7554 if (is_client_associated_to_ap(padapter)) {
7555 /* linked infrastructure client mode */
7557 int tx_chk = _SUCCESS, rx_chk = _SUCCESS;
7561 psta = rtw_get_stainfo(pstapriv, pmlmeinfo->network.MacAddress);
7563 bool is_p2p_enable = false;
7564 #ifdef CONFIG_88EU_P2P
7565 is_p2p_enable = !rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE);
7568 if (!chk_ap_is_alive(padapter, psta))
7571 if (pxmitpriv->last_tx_pkts == pxmitpriv->tx_pkts)
7574 if (pmlmeext->active_keep_alive_check && (rx_chk == _FAIL || tx_chk == _FAIL)) {
7575 u8 backup_oper_channel = 0;
7577 /* switch to correct channel of current network before issue keep-alive frames */
7578 if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
7579 backup_oper_channel = rtw_get_oper_ch(padapter);
7580 SelectChannel(padapter, pmlmeext->cur_channel);
7583 if (rx_chk != _SUCCESS)
7584 issue_probereq_ex(padapter, &pmlmeinfo->network.Ssid, psta->hwaddr, 3, 1);
7586 if ((tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) || rx_chk != _SUCCESS) {
7587 tx_chk = issue_nulldata(padapter, psta->hwaddr, 0, 3, 1);
7588 /* if tx acked and p2p disabled, set rx_chk _SUCCESS to reset retry count */
7589 if (tx_chk == _SUCCESS && !is_p2p_enable)
7593 /* back to the original operation channel */
7594 if (backup_oper_channel > 0)
7595 SelectChannel(padapter, backup_oper_channel);
7597 if (rx_chk != _SUCCESS) {
7598 if (pmlmeext->retry == 0) {
7599 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7600 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7601 issue_probereq(padapter, &pmlmeinfo->network.Ssid, pmlmeinfo->network.MacAddress);
7605 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) {
7606 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0);
7610 if (rx_chk == _FAIL) {
7612 if (pmlmeext->retry > rx_chk_limit) {
7613 DBG_88E_LEVEL(_drv_always_, FUNC_ADPT_FMT" disconnect or roaming\n",
7614 FUNC_ADPT_ARG(padapter));
7615 receive_disconnect(padapter, pmlmeinfo->network.MacAddress,
7616 WLAN_REASON_EXPIRATION_CHK);
7620 pmlmeext->retry = 0;
7623 if (tx_chk == _FAIL) {
7624 pmlmeinfo->link_count &= 0xf;
7626 pxmitpriv->last_tx_pkts = pxmitpriv->tx_pkts;
7627 pmlmeinfo->link_count = 0;
7629 } /* end of if ((psta = rtw_get_stainfo(pstapriv, passoc_res->network.MacAddress)) != NULL) */
7630 } else if (is_client_associated_to_ibss(padapter)) {
7631 /* linked IBSS mode */
7632 /* for each assoc list entry to check the rx pkt counter */
7633 for (i = IBSS_START_MAC_ID; i < NUM_STA; i++) {
7634 if (pmlmeinfo->FW_sta_info[i].status == 1) {
7635 psta = pmlmeinfo->FW_sta_info[i].psta;
7639 if (pmlmeinfo->FW_sta_info[i].rx_pkt == sta_rx_pkts(psta)) {
7640 if (pmlmeinfo->FW_sta_info[i].retry < 3) {
7641 pmlmeinfo->FW_sta_info[i].retry++;
7643 pmlmeinfo->FW_sta_info[i].retry = 0;
7644 pmlmeinfo->FW_sta_info[i].status = 0;
7645 report_del_sta_event(padapter, psta->hwaddr
7646 , 65535/* indicate disconnect caused by no rx */
7650 pmlmeinfo->FW_sta_info[i].retry = 0;
7651 pmlmeinfo->FW_sta_info[i].rx_pkt = (u32)sta_rx_pkts(psta);
7658 void survey_timer_hdl(struct adapter *padapter)
7660 struct cmd_obj *ph2c;
7661 struct sitesurvey_parm *psurveyPara;
7662 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
7663 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7664 #ifdef CONFIG_88EU_P2P
7665 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
7668 /* issue rtw_sitesurvey_cmd */
7669 if (pmlmeext->sitesurvey_res.state > SCAN_START) {
7670 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS)
7671 pmlmeext->sitesurvey_res.channel_idx++;
7673 if (pmlmeext->scan_abort) {
7674 #ifdef CONFIG_88EU_P2P
7675 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE)) {
7676 rtw_p2p_findphase_ex_set(pwdinfo, P2P_FINDPHASE_EX_MAX);
7677 pmlmeext->sitesurvey_res.channel_idx = 3;
7678 DBG_88E("%s idx:%d, cnt:%u\n", __func__
7679 , pmlmeext->sitesurvey_res.channel_idx
7680 , pwdinfo->find_phase_state_exchange_cnt
7685 pmlmeext->sitesurvey_res.channel_idx = pmlmeext->sitesurvey_res.ch_num;
7686 DBG_88E("%s idx:%d\n", __func__
7687 , pmlmeext->sitesurvey_res.channel_idx
7691 pmlmeext->scan_abort = false;/* reset */
7694 ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
7696 goto exit_survey_timer_hdl;
7698 psurveyPara = (struct sitesurvey_parm *)rtw_zmalloc(sizeof(struct sitesurvey_parm));
7699 if (psurveyPara == NULL) {
7701 goto exit_survey_timer_hdl;
7704 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, GEN_CMD_CODE(_SiteSurvey));
7705 rtw_enqueue_cmd(pcmdpriv, ph2c);
7709 exit_survey_timer_hdl:
7713 void link_timer_hdl(struct adapter *padapter)
7715 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7716 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7718 if (pmlmeinfo->state & WIFI_FW_AUTH_NULL) {
7719 DBG_88E("link_timer_hdl:no beacon while connecting\n");
7720 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7721 report_join_res(padapter, -3);
7722 } else if (pmlmeinfo->state & WIFI_FW_AUTH_STATE) {
7724 if (++pmlmeinfo->reauth_count > REAUTH_LIMIT) {
7725 pmlmeinfo->state = 0;
7726 report_join_res(padapter, -1);
7730 DBG_88E("link_timer_hdl: auth timeout and try again\n");
7731 pmlmeinfo->auth_seq = 1;
7732 issue_auth(padapter, NULL, 0);
7733 set_link_timer(pmlmeext, REAUTH_TO);
7734 } else if (pmlmeinfo->state & WIFI_FW_ASSOC_STATE) {
7735 /* re-assoc timer */
7736 if (++pmlmeinfo->reassoc_count > REASSOC_LIMIT) {
7737 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7738 report_join_res(padapter, -2);
7742 DBG_88E("link_timer_hdl: assoc timeout and try again\n");
7743 issue_assocreq(padapter);
7744 set_link_timer(pmlmeext, REASSOC_TO);
7749 void addba_timer_hdl(struct sta_info *psta)
7751 struct ht_priv *phtpriv;
7756 phtpriv = &psta->htpriv;
7758 if ((phtpriv->ht_option) && (phtpriv->ampdu_enable)) {
7759 if (phtpriv->candidate_tid_bitmap)
7760 phtpriv->candidate_tid_bitmap = 0x0;
7764 u8 NULL_hdl(struct adapter *padapter, u8 *pbuf)
7769 u8 setopmode_hdl(struct adapter *padapter, u8 *pbuf)
7772 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7773 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7774 struct setopmode_parm *psetop = (struct setopmode_parm *)pbuf;
7776 if (psetop->mode == Ndis802_11APMode) {
7777 pmlmeinfo->state = WIFI_FW_AP_STATE;
7778 type = _HW_STATE_AP_;
7779 } else if (psetop->mode == Ndis802_11Infrastructure) {
7780 pmlmeinfo->state &= ~(BIT(0)|BIT(1));/* clear state */
7781 pmlmeinfo->state |= WIFI_FW_STATION_STATE;/* set to STATION_STATE */
7782 type = _HW_STATE_STATION_;
7783 } else if (psetop->mode == Ndis802_11IBSS) {
7784 type = _HW_STATE_ADHOC_;
7786 type = _HW_STATE_NOLINK_;
7789 rtw_hal_set_hwreg(padapter, HW_VAR_SET_OPMODE, (u8 *)(&type));
7790 /* Set_NETYPE0_MSR(padapter, type); */
7795 u8 createbss_hdl(struct adapter *padapter, u8 *pbuf)
7797 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7798 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7799 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7800 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7801 /* u32 initialgain; */
7804 if (pparm->network.InfrastructureMode == Ndis802_11APMode) {
7805 #ifdef CONFIG_88EU_AP_MODE
7807 if (pmlmeinfo->state == WIFI_FW_AP_STATE) {
7814 /* below is for ad-hoc master */
7815 if (pparm->network.InfrastructureMode == Ndis802_11IBSS) {
7816 rtw_joinbss_reset(padapter);
7818 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7819 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7820 pmlmeinfo->ERP_enable = 0;
7821 pmlmeinfo->WMM_enable = 0;
7822 pmlmeinfo->HT_enable = 0;
7823 pmlmeinfo->HT_caps_enable = 0;
7824 pmlmeinfo->HT_info_enable = 0;
7825 pmlmeinfo->agg_enable_bitmap = 0;
7826 pmlmeinfo->candidate_tid_bitmap = 0;
7828 /* disable dynamic functions, such as high power, DIG */
7829 Save_DM_Func_Flag(padapter);
7830 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
7832 /* config the initial gain under linking, need to write the BB registers */
7833 /* initialgain = 0x1E; */
7834 /* rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain)); */
7836 /* cancel link timer */
7837 _cancel_timer_ex(&pmlmeext->link_timer);
7840 flush_all_cam_entry(padapter);
7842 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7843 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7845 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7846 return H2C_PARAMETERS_ERROR;
7848 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7850 start_create_ibss(padapter);
7856 u8 join_cmd_hdl(struct adapter *padapter, u8 *pbuf)
7859 struct ndis_802_11_var_ie *pIE;
7860 struct registry_priv *pregpriv = &padapter->registrypriv;
7861 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7862 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7863 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7864 struct joinbss_parm *pparm = (struct joinbss_parm *)pbuf;
7867 /* check already connecting to AP or not */
7868 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
7869 if (pmlmeinfo->state & WIFI_FW_STATION_STATE)
7870 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, 5, 100);
7872 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7875 flush_all_cam_entry(padapter);
7877 _cancel_timer_ex(&pmlmeext->link_timer);
7879 /* set MSR to nolink -> infra. mode */
7880 Set_MSR(padapter, _HW_STATE_STATION_);
7883 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7886 rtw_antenna_select_cmd(padapter, pparm->network.PhyInfo.Optimum_antenna, false);
7888 rtw_joinbss_reset(padapter);
7890 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
7891 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7892 pmlmeinfo->ERP_enable = 0;
7893 pmlmeinfo->WMM_enable = 0;
7894 pmlmeinfo->HT_enable = 0;
7895 pmlmeinfo->HT_caps_enable = 0;
7896 pmlmeinfo->HT_info_enable = 0;
7897 pmlmeinfo->agg_enable_bitmap = 0;
7898 pmlmeinfo->candidate_tid_bitmap = 0;
7899 pmlmeinfo->bwmode_updated = false;
7901 memcpy(pnetwork, pbuf, FIELD_OFFSET(struct wlan_bssid_ex, IELength));
7902 pnetwork->IELength = ((struct wlan_bssid_ex *)pbuf)->IELength;
7904 if (pnetwork->IELength > MAX_IE_SZ)/* Check pbuf->IELength */
7905 return H2C_PARAMETERS_ERROR;
7907 memcpy(pnetwork->IEs, ((struct wlan_bssid_ex *)pbuf)->IEs, pnetwork->IELength);
7909 /* Check AP vendor to move rtw_joinbss_cmd() */
7911 for (i = sizeof(struct ndis_802_11_fixed_ie); i < pnetwork->IELength;) {
7912 pIE = (struct ndis_802_11_var_ie *)(pnetwork->IEs + i);
7914 switch (pIE->ElementID) {
7915 case _VENDOR_SPECIFIC_IE_:/* Get WMM IE. */
7916 if (!memcmp(pIE->data, WMM_OUI, 4))
7917 pmlmeinfo->WMM_enable = 1;
7919 case _HT_CAPABILITY_IE_: /* Get HT Cap IE. */
7920 pmlmeinfo->HT_caps_enable = 1;
7922 case _HT_EXTRA_INFO_IE_: /* Get HT Info IE. */
7923 pmlmeinfo->HT_info_enable = 1;
7925 /* spec case only for cisco's ap because cisco's ap issue assoc rsp using mcs rate @40MHz or @20MHz */
7927 struct HT_info_element *pht_info = (struct HT_info_element *)(pIE->data);
7929 if ((pregpriv->cbw40_enable) && (pht_info->infos[0] & BIT(2))) {
7930 /* switch to the 40M Hz mode according to the AP */
7931 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_40;
7932 switch (pht_info->infos[0] & 0x3) {
7934 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
7937 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
7940 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
7944 DBG_88E("set ch/bw before connected\n");
7952 i += (pIE->Length + 2);
7954 /* disable dynamic functions, such as high power, DIG */
7956 /* config the initial gain under linking, need to write the BB registers */
7958 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, pmlmeinfo->network.MacAddress);
7960 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_JOIN, (u8 *)(&join_type));
7962 /* cancel link timer */
7963 _cancel_timer_ex(&pmlmeext->link_timer);
7965 start_clnt_join(padapter);
7970 u8 disconnect_hdl(struct adapter *padapter, unsigned char *pbuf)
7972 struct disconnect_parm *param = (struct disconnect_parm *)pbuf;
7973 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
7974 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
7975 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
7978 if (is_client_associated_to_ap(padapter))
7979 issue_deauth_ex(padapter, pnetwork->MacAddress, WLAN_REASON_DEAUTH_LEAVING, param->deauth_timeout_ms/100, 100);
7981 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_DISCONNECT, NULL);
7982 rtw_hal_set_hwreg(padapter, HW_VAR_BSSID, null_addr);
7984 /* restore to initial setting. */
7985 update_tx_basic_rate(padapter, padapter->registrypriv.wireless_mode);
7987 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
7990 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_FUNC, (u8 *)(&val8));
7994 /* set MSR to no link state -> infra. mode */
7995 Set_MSR(padapter, _HW_STATE_STATION_);
7997 pmlmeinfo->state = WIFI_FW_NULL_STATE;
7999 /* switch to the 20M Hz mode after disconnect */
8000 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
8001 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
8003 set_channel_bwmode(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
8005 flush_all_cam_entry(padapter);
8007 _cancel_timer_ex(&pmlmeext->link_timer);
8009 rtw_free_uc_swdec_pending_queue(padapter);
8014 static int rtw_scan_ch_decision(struct adapter *padapter, struct rtw_ieee80211_channel *out,
8015 u32 out_num, struct rtw_ieee80211_channel *in, u32 in_num)
8019 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8021 /* clear out first */
8022 _rtw_memset(out, 0, sizeof(struct rtw_ieee80211_channel)*out_num);
8024 /* acquire channels from in */
8026 for (i = 0; i < in_num; i++) {
8027 set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, in[i].hw_value);
8028 if (in[i].hw_value && !(in[i].flags & RTW_IEEE80211_CHAN_DISABLED) &&
8032 if (pmlmeext->channel_set[set_idx].ScanType == SCAN_PASSIVE)
8033 out[j].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
8041 /* if out is empty, use channel_set as default */
8043 for (i = 0; i < pmlmeext->max_chan_nums; i++) {
8044 out[i].hw_value = pmlmeext->channel_set[i].ChannelNum;
8046 if (pmlmeext->channel_set[i].ScanType == SCAN_PASSIVE)
8047 out[i].flags &= RTW_IEEE80211_CHAN_PASSIVE_SCAN;
8056 u8 sitesurvey_cmd_hdl(struct adapter *padapter, u8 *pbuf)
8058 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8059 struct sitesurvey_parm *pparm = (struct sitesurvey_parm *)pbuf;
8060 u8 bdelayscan = false;
8065 #ifdef CONFIG_88EU_P2P
8066 struct wifidirect_info *pwdinfo = &padapter->wdinfo;
8069 if (pmlmeext->sitesurvey_res.state == SCAN_DISABLE) {
8070 /* for first time sitesurvey_cmd */
8071 rtw_hal_set_hwreg(padapter, HW_VAR_CHECK_TXBUF, NULL);
8073 pmlmeext->sitesurvey_res.state = SCAN_START;
8074 pmlmeext->sitesurvey_res.bss_cnt = 0;
8075 pmlmeext->sitesurvey_res.channel_idx = 0;
8077 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
8078 if (pparm->ssid[i].SsidLength) {
8079 memcpy(pmlmeext->sitesurvey_res.ssid[i].Ssid, pparm->ssid[i].Ssid, IW_ESSID_MAX_SIZE);
8080 pmlmeext->sitesurvey_res.ssid[i].SsidLength = pparm->ssid[i].SsidLength;
8082 pmlmeext->sitesurvey_res.ssid[i].SsidLength = 0;
8086 pmlmeext->sitesurvey_res.ch_num = rtw_scan_ch_decision(padapter
8087 , pmlmeext->sitesurvey_res.ch, RTW_CHANNEL_SCAN_AMOUNT
8088 , pparm->ch, pparm->ch_num
8091 pmlmeext->sitesurvey_res.scan_mode = pparm->scan_mode;
8093 /* issue null data if associating to the AP */
8094 if (is_client_associated_to_ap(padapter)) {
8095 pmlmeext->sitesurvey_res.state = SCAN_TXNULL;
8097 issue_nulldata(padapter, NULL, 1, 3, 500);
8102 /* delay 50ms to protect nulldata(1). */
8103 set_survey_timer(pmlmeext, 50);
8108 if ((pmlmeext->sitesurvey_res.state == SCAN_START) || (pmlmeext->sitesurvey_res.state == SCAN_TXNULL)) {
8109 /* disable dynamic functions, such as high power, DIG */
8110 Save_DM_Func_Flag(padapter);
8111 Switch_DM_Func(padapter, DYNAMIC_FUNC_DISABLE, false);
8113 /* config the initial gain under scanning, need to write the BB registers */
8114 #ifdef CONFIG_88EU_P2P
8115 if (rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE))
8119 #else /* CONFIG_88EU_P2P */
8121 #endif /* CONFIG_88EU_P2P */
8123 rtw_hal_set_hwreg(padapter, HW_VAR_INITIAL_GAIN, (u8 *)(&initialgain));
8125 /* set MSR to no link state */
8126 Set_MSR(padapter, _HW_STATE_NOLINK_);
8128 val8 = 1; /* under site survey */
8129 rtw_hal_set_hwreg(padapter, HW_VAR_MLME_SITESURVEY, (u8 *)(&val8));
8131 pmlmeext->sitesurvey_res.state = SCAN_PROCESS;
8134 site_survey(padapter);
8139 u8 setauth_hdl(struct adapter *padapter, unsigned char *pbuf)
8141 struct setauth_parm *pparm = (struct setauth_parm *)pbuf;
8142 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8143 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8145 if (pparm->mode < 4)
8146 pmlmeinfo->auth_algo = pparm->mode;
8150 u8 setkey_hdl(struct adapter *padapter, u8 *pbuf)
8152 unsigned short ctrl;
8153 struct setkey_parm *pparm = (struct setkey_parm *)pbuf;
8154 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8155 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8156 unsigned char null_sta[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
8158 /* main tx key for wep. */
8160 pmlmeinfo->key_index = pparm->keyid;
8163 ctrl = BIT(15) | ((pparm->algorithm) << 2) | pparm->keyid;
8165 DBG_88E_LEVEL(_drv_info_, "set group key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) "
8166 "keyid:%d\n", pparm->algorithm, pparm->keyid);
8167 write_cam(padapter, pparm->keyid, ctrl, null_sta, pparm->key);
8172 u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf)
8175 u8 cam_id;/* cam_entry */
8176 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8177 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8178 struct set_stakey_parm *pparm = (struct set_stakey_parm *)pbuf;
8181 /* 0~3 for default key */
8183 /* for concurrent mode (ap+sta): */
8184 /* default key is disable, using sw encrypt/decrypt */
8185 /* cam_entry = 4 for sta mode (macid = 0) */
8186 /* cam_entry(macid+3) = 5 ~ N for ap mode (aid = 1~N, macid = 2 ~N) */
8188 /* for concurrent mode (sta+sta): */
8189 /* default key is disable, using sw encrypt/decrypt */
8190 /* cam_entry = 4 mapping to macid = 0 */
8191 /* cam_entry = 5 mapping to macid = 2 */
8195 DBG_88E_LEVEL(_drv_info_, "set pairwise key to hw: alg:%d(WEP40-1 WEP104-5 TKIP-2 AES-4) camid:%d\n",
8196 pparm->algorithm, cam_id);
8197 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
8198 struct sta_info *psta;
8199 struct sta_priv *pstapriv = &padapter->stapriv;
8201 if (pparm->algorithm == _NO_PRIVACY_) /* clear cam entry */ {
8202 clear_cam_entry(padapter, pparm->id);
8203 return H2C_SUCCESS_RSP;
8206 psta = rtw_get_stainfo(pstapriv, pparm->addr);
8208 ctrl = (BIT(15) | ((pparm->algorithm) << 2));
8210 DBG_88E("r871x_set_stakey_hdl(): enc_algorithm=%d\n", pparm->algorithm);
8212 if ((psta->mac_id < 1) || (psta->mac_id > (NUM_STA-4))) {
8213 DBG_88E("r871x_set_stakey_hdl():set_stakey failed, mac_id(aid)=%d\n", psta->mac_id);
8214 return H2C_REJECTED;
8217 cam_id = (psta->mac_id + 3);/* 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
8219 DBG_88E("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, cam_entry=%d\n", pparm->addr[0],
8220 pparm->addr[1], pparm->addr[2], pparm->addr[3], pparm->addr[4],
8221 pparm->addr[5], cam_id);
8223 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8225 return H2C_SUCCESS_RSP;
8227 DBG_88E("r871x_set_stakey_hdl(): sta has been free\n");
8228 return H2C_REJECTED;
8232 /* below for sta mode */
8234 if (pparm->algorithm == _NO_PRIVACY_) { /* clear cam entry */
8235 clear_cam_entry(padapter, pparm->id);
8238 ctrl = BIT(15) | ((pparm->algorithm) << 2);
8239 write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
8240 pmlmeinfo->enc_algo = pparm->algorithm;
8244 u8 add_ba_hdl(struct adapter *padapter, unsigned char *pbuf)
8246 struct addBaReq_parm *pparm = (struct addBaReq_parm *)pbuf;
8247 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8248 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8250 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, pparm->addr);
8255 if (((pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) && (pmlmeinfo->HT_enable)) ||
8256 ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE)) {
8257 issue_action_BA(padapter, pparm->addr, RTW_WLAN_ACTION_ADDBA_REQ, (u16)pparm->tid);
8258 _set_timer(&psta->addba_retry_timer, ADDBA_TO);
8260 psta->htpriv.candidate_tid_bitmap &= ~BIT(pparm->tid);
8265 u8 set_tx_beacon_cmd(struct adapter *padapter)
8267 struct cmd_obj *ph2c;
8268 struct Tx_Beacon_param *ptxBeacon_parm;
8269 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
8270 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8271 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
8276 ph2c = (struct cmd_obj *)rtw_zmalloc(sizeof(struct cmd_obj));
8282 ptxBeacon_parm = (struct Tx_Beacon_param *)rtw_zmalloc(sizeof(struct Tx_Beacon_param));
8283 if (ptxBeacon_parm == NULL) {
8289 memcpy(&(ptxBeacon_parm->network), &(pmlmeinfo->network), sizeof(struct wlan_bssid_ex));
8291 len_diff = update_hidden_ssid(ptxBeacon_parm->network.IEs+_BEACON_IE_OFFSET_,
8292 ptxBeacon_parm->network.IELength-_BEACON_IE_OFFSET_,
8293 pmlmeinfo->hidden_ssid_mode);
8294 ptxBeacon_parm->network.IELength += len_diff;
8296 init_h2fwcmd_w_parm_no_rsp(ph2c, ptxBeacon_parm, GEN_CMD_CODE(_TX_Beacon));
8298 res = rtw_enqueue_cmd(pcmdpriv, ph2c);
8307 u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf)
8312 void (*event_callback)(struct adapter *dev, u8 *pbuf);
8313 struct evt_priv *pevt_priv = &(padapter->evtpriv);
8315 peventbuf = (uint *)pbuf;
8316 evt_sz = (u16)(*peventbuf&0xffff);
8317 evt_code = (u8)((*peventbuf>>16)&0xff);
8319 /* checking if event code is valid */
8320 if (evt_code >= MAX_C2HEVT) {
8321 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("\nEvent Code(%d) mismatch!\n", evt_code));
8325 /* checking if event size match the event parm size */
8326 if ((wlanevents[evt_code].parmsize != 0) &&
8327 (wlanevents[evt_code].parmsize != evt_sz)) {
8328 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
8329 ("\nEvent(%d) Parm Size mismatch (%d vs %d)!\n",
8330 evt_code, wlanevents[evt_code].parmsize, evt_sz));
8334 atomic_inc(&pevt_priv->event_seq);
8339 event_callback = wlanevents[evt_code].event_callback;
8340 event_callback(padapter, (u8 *)peventbuf);
8342 pevt_priv->evt_done_cnt++;
8349 u8 h2c_msg_hdl(struct adapter *padapter, unsigned char *pbuf)
8352 return H2C_PARAMETERS_ERROR;
8357 u8 tx_beacon_hdl(struct adapter *padapter, unsigned char *pbuf)
8359 if (send_beacon(padapter) == _FAIL) {
8360 DBG_88E("issue_beacon, fail!\n");
8361 return H2C_PARAMETERS_ERROR;
8363 #ifdef CONFIG_88EU_AP_MODE
8364 else { /* tx bc/mc frames after update TIM */
8365 struct sta_info *psta_bmc;
8366 struct list_head *xmitframe_plist, *xmitframe_phead;
8367 struct xmit_frame *pxmitframe = NULL;
8368 struct sta_priv *pstapriv = &padapter->stapriv;
8370 /* for BC/MC Frames */
8371 psta_bmc = rtw_get_bcmc_stainfo(padapter);
8375 if ((pstapriv->tim_bitmap&BIT(0)) && (psta_bmc->sleepq_len > 0)) {
8376 msleep(10);/* 10ms, ATIM(HIQ) Windows */
8377 spin_lock_bh(&psta_bmc->sleep_q.lock);
8379 xmitframe_phead = get_list_head(&psta_bmc->sleep_q);
8380 xmitframe_plist = xmitframe_phead->next;
8382 while (!rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
8383 pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
8385 xmitframe_plist = xmitframe_plist->next;
8387 rtw_list_delete(&pxmitframe->list);
8389 psta_bmc->sleepq_len--;
8390 if (psta_bmc->sleepq_len > 0)
8391 pxmitframe->attrib.mdata = 1;
8393 pxmitframe->attrib.mdata = 0;
8395 pxmitframe->attrib.triggered = 1;
8397 pxmitframe->attrib.qsel = 0x11;/* HIQ */
8399 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8400 if (rtw_hal_xmit(padapter, pxmitframe))
8401 rtw_os_xmit_complete(padapter, pxmitframe);
8402 spin_lock_bh(&psta_bmc->sleep_q.lock);
8404 spin_unlock_bh(&psta_bmc->sleep_q.lock);
8411 u8 set_ch_hdl(struct adapter *padapter, u8 *pbuf)
8413 struct set_ch_parm *set_ch_parm;
8414 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8417 return H2C_PARAMETERS_ERROR;
8419 set_ch_parm = (struct set_ch_parm *)pbuf;
8421 DBG_88E(FUNC_NDEV_FMT" ch:%u, bw:%u, ch_offset:%u\n",
8422 FUNC_NDEV_ARG(padapter->pnetdev),
8423 set_ch_parm->ch, set_ch_parm->bw, set_ch_parm->ch_offset);
8425 pmlmeext->cur_channel = set_ch_parm->ch;
8426 pmlmeext->cur_ch_offset = set_ch_parm->ch_offset;
8427 pmlmeext->cur_bwmode = set_ch_parm->bw;
8429 set_channel_bwmode(padapter, set_ch_parm->ch, set_ch_parm->ch_offset, set_ch_parm->bw);
8434 u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)
8436 struct SetChannelPlan_param *setChannelPlan_param;
8437 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
8440 return H2C_PARAMETERS_ERROR;
8442 setChannelPlan_param = (struct SetChannelPlan_param *)pbuf;
8444 pmlmeext->max_chan_nums = init_channel_set(padapter, setChannelPlan_param->channel_plan, pmlmeext->channel_set);
8445 init_channel_list(padapter, pmlmeext->channel_set, pmlmeext->max_chan_nums, &pmlmeext->channel_list);
8450 u8 led_blink_hdl(struct adapter *padapter, unsigned char *pbuf)
8453 return H2C_PARAMETERS_ERROR;
8457 u8 set_csa_hdl(struct adapter *padapter, unsigned char *pbuf)
8459 return H2C_REJECTED;
8462 /* TDLS_WRCR : write RCR DATA BIT */
8463 /* TDLS_SD_PTI : issue peer traffic indication */
8464 /* TDLS_CS_OFF : go back to the channel linked with AP, terminating channel switch procedure */
8465 /* TDLS_INIT_CH_SEN : init channel sensing, receive all data and mgnt frame */
8466 /* TDLS_DONE_CH_SEN: channel sensing and report candidate channel */
8467 /* TDLS_OFF_CH : first time set channel to off channel */
8468 /* TDLS_BASE_CH : go back tp the channel linked with AP when set base channel as target channel */
8469 /* TDLS_P_OFF_CH : periodically go to off channel */
8470 /* TDLS_P_BASE_CH : periodically go back to base channel */
8471 /* TDLS_RS_RCR : restore RCR */
8472 /* TDLS_CKALV_PH1 : check alive timer phase1 */
8473 /* TDLS_CKALV_PH2 : check alive timer phase2 */
8474 /* TDLS_FREE_STA : free tdls sta */
8475 u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf)
8477 return H2C_REJECTED;