1 /******************************************************************************
2 *
3 * Copyright(c) 2007 - 2017 Realtek Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 *****************************************************************************/
15 #define _RTW_TDLS_C_
16
17 #include <drv_types.h>
18 #include <hal_data.h>
19
20 #ifdef CONFIG_TDLS
21 #define ONE_SEC 1000 /* 1000 ms */
22
23 extern unsigned char MCS_rate_2R[16];
24 extern unsigned char MCS_rate_1R[16];
25
rtw_tdls_set_link_established(_adapter * adapter,bool en)26 inline void rtw_tdls_set_link_established(_adapter *adapter, bool en)
27 {
28 adapter->tdlsinfo.link_established = en;
29 rtw_mi_update_iface_status(&(adapter->mlmepriv), 0);
30 }
31
rtw_reset_tdls_info(_adapter * padapter)32 void rtw_reset_tdls_info(_adapter *padapter)
33 {
34 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
35
36 ptdlsinfo->ap_prohibited = _FALSE;
37
38 /* For TDLS channel switch, currently we only allow it to work in wifi logo test mode */
39 if (padapter->registrypriv.wifi_spec == 1)
40 ptdlsinfo->ch_switch_prohibited = _FALSE;
41 else
42 ptdlsinfo->ch_switch_prohibited = _TRUE;
43
44 rtw_tdls_set_link_established(padapter, _FALSE);
45 ptdlsinfo->sta_cnt = 0;
46 ptdlsinfo->sta_maximum = _FALSE;
47
48 #ifdef CONFIG_TDLS_CH_SW
49 ptdlsinfo->chsw_info.ch_sw_state = TDLS_STATE_NONE;
50 ATOMIC_SET(&ptdlsinfo->chsw_info.chsw_on, _FALSE);
51 ptdlsinfo->chsw_info.off_ch_num = 0;
52 ptdlsinfo->chsw_info.ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
53 ptdlsinfo->chsw_info.cur_time = 0;
54 ptdlsinfo->chsw_info.delay_switch_back = _FALSE;
55 ptdlsinfo->chsw_info.dump_stack = _FALSE;
56 #endif
57
58 ptdlsinfo->ch_sensing = 0;
59 ptdlsinfo->watchdog_count = 0;
60 ptdlsinfo->dev_discovered = _FALSE;
61
62 #ifdef CONFIG_WFD
63 ptdlsinfo->wfd_info = &padapter->wfd_info;
64 #endif
65
66 ptdlsinfo->tdls_sctx = NULL;
67 }
68
rtw_init_tdls_info(_adapter * padapter)69 int rtw_init_tdls_info(_adapter *padapter)
70 {
71 int res = _SUCCESS;
72 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
73
74 rtw_reset_tdls_info(padapter);
75
76 #ifdef CONFIG_TDLS_DRIVER_SETUP
77 ptdlsinfo->driver_setup = _TRUE;
78 #else
79 ptdlsinfo->driver_setup = _FALSE;
80 #endif /* CONFIG_TDLS_DRIVER_SETUP */
81
82 _rtw_spinlock_init(&ptdlsinfo->cmd_lock);
83 _rtw_spinlock_init(&ptdlsinfo->hdl_lock);
84
85 return res;
86
87 }
88
rtw_free_tdls_info(struct tdls_info * ptdlsinfo)89 void rtw_free_tdls_info(struct tdls_info *ptdlsinfo)
90 {
91 _rtw_spinlock_free(&ptdlsinfo->cmd_lock);
92 _rtw_spinlock_free(&ptdlsinfo->hdl_lock);
93
94 _rtw_memset(ptdlsinfo, 0, sizeof(struct tdls_info));
95
96 }
97
rtw_free_all_tdls_sta(_adapter * padapter,u8 enqueue_cmd)98 void rtw_free_all_tdls_sta(_adapter *padapter, u8 enqueue_cmd)
99 {
100 struct sta_priv *pstapriv = &padapter->stapriv;
101 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
102 _irqL irqL;
103 _list *plist, *phead;
104 s32 index;
105 struct sta_info *psta = NULL;
106 struct sta_info *ptdls_sta[NUM_STA];
107 u8 empty_hwaddr[ETH_ALEN] = { 0x00 };
108
109 _rtw_memset(ptdls_sta, 0x00, sizeof(ptdls_sta));
110
111 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
112 for (index = 0; index < NUM_STA; index++) {
113 phead = &(pstapriv->sta_hash[index]);
114 plist = get_next(phead);
115
116 while (rtw_end_of_queue_search(phead, plist) == _FALSE) {
117 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
118
119 plist = get_next(plist);
120
121 if (psta->tdls_sta_state != TDLS_STATE_NONE)
122 ptdls_sta[index] = psta;
123 }
124 }
125 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
126
127 for (index = 0; index < NUM_STA; index++) {
128 if (ptdls_sta[index]) {
129 struct TDLSoption_param tdls_param;
130
131 psta = ptdls_sta[index];
132
133 RTW_INFO("Do tear down to "MAC_FMT" by enqueue_cmd = %d\n", MAC_ARG(psta->cmn.mac_addr), enqueue_cmd);
134
135 _rtw_memcpy(&(tdls_param.addr), psta->cmn.mac_addr, ETH_ALEN);
136 tdls_param.option = TDLS_TEARDOWN_STA_NO_WAIT;
137 tdls_hdl(padapter, (unsigned char *)&(tdls_param));
138
139 rtw_tdls_teardown_pre_hdl(padapter, psta);
140
141 if (enqueue_cmd == _TRUE)
142 rtw_tdls_cmd(padapter, psta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
143 else
144 {
145 tdls_param.option = TDLS_TEARDOWN_STA_LOCALLY_POST;
146 tdls_hdl(padapter, (unsigned char *)&(tdls_param));
147 }
148 }
149 }
150 }
151
check_ap_tdls_prohibited(u8 * pframe,u8 pkt_len)152 int check_ap_tdls_prohibited(u8 *pframe, u8 pkt_len)
153 {
154 u8 tdls_prohibited_bit = 0x40; /* bit(38); TDLS_prohibited */
155
156 if (pkt_len < 5)
157 return _FALSE;
158
159 pframe += 4;
160 if ((*pframe) & tdls_prohibited_bit)
161 return _TRUE;
162
163 return _FALSE;
164 }
165
check_ap_tdls_ch_switching_prohibited(u8 * pframe,u8 pkt_len)166 int check_ap_tdls_ch_switching_prohibited(u8 *pframe, u8 pkt_len)
167 {
168 u8 tdls_ch_swithcing_prohibited_bit = 0x80; /* bit(39); TDLS_channel_switching prohibited */
169
170 if (pkt_len < 5)
171 return _FALSE;
172
173 pframe += 4;
174 if ((*pframe) & tdls_ch_swithcing_prohibited_bit)
175 return _TRUE;
176
177 return _FALSE;
178 }
179
rtw_is_tdls_enabled(_adapter * padapter)180 u8 rtw_is_tdls_enabled(_adapter *padapter)
181 {
182 return padapter->registrypriv.en_tdls;
183 }
184
rtw_set_tdls_enable(_adapter * padapter,u8 enable)185 void rtw_set_tdls_enable(_adapter *padapter, u8 enable)
186 {
187 padapter->registrypriv.en_tdls = enable;
188 RTW_INFO("%s: en_tdls = %d\n", __func__, rtw_is_tdls_enabled(padapter));
189 }
190
rtw_enable_tdls_func(_adapter * padapter)191 void rtw_enable_tdls_func(_adapter *padapter)
192 {
193 if (rtw_is_tdls_enabled(padapter) == _TRUE)
194 return;
195
196 #if 0
197 #ifdef CONFIG_MCC_MODE
198 if (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC) == _TRUE) {
199 RTW_INFO("[TDLS] MCC is running, can't enable TDLS !\n");
200 return;
201 }
202 #endif
203 #endif
204 rtw_set_tdls_enable(padapter, _TRUE);
205 }
206
rtw_disable_tdls_func(_adapter * padapter,u8 enqueue_cmd)207 void rtw_disable_tdls_func(_adapter *padapter, u8 enqueue_cmd)
208 {
209 if (rtw_is_tdls_enabled(padapter) == _FALSE)
210 return;
211
212 rtw_free_all_tdls_sta(padapter, enqueue_cmd);
213 rtw_tdls_cmd(padapter, NULL, TDLS_RS_RCR);
214 rtw_reset_tdls_info(padapter);
215
216 rtw_set_tdls_enable(padapter, _FALSE);
217 }
218
rtw_is_tdls_sta_existed(_adapter * padapter)219 u8 rtw_is_tdls_sta_existed(_adapter *padapter)
220 {
221 struct sta_priv *pstapriv = &padapter->stapriv;
222 struct sta_info *psta;
223 int i = 0;
224 _irqL irqL;
225 _list *plist, *phead;
226 u8 ret = _FALSE;
227
228 if (rtw_is_tdls_enabled(padapter) == _FALSE)
229 return _FALSE;
230
231 _enter_critical_bh(&pstapriv->sta_hash_lock, &irqL);
232
233 for (i = 0; i < NUM_STA; i++) {
234 phead = &(pstapriv->sta_hash[i]);
235 plist = get_next(phead);
236 while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
237 psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
238 plist = get_next(plist);
239 if (psta->tdls_sta_state != TDLS_STATE_NONE) {
240 ret = _TRUE;
241 goto Exit;
242 }
243 }
244 }
245
246 Exit:
247
248 _exit_critical_bh(&pstapriv->sta_hash_lock, &irqL);
249
250 return ret;
251 }
252
rtw_tdls_is_setup_allowed(_adapter * padapter)253 u8 rtw_tdls_is_setup_allowed(_adapter *padapter)
254 {
255 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
256
257 if (is_client_associated_to_ap(padapter) == _FALSE)
258 return _FALSE;
259
260 if (ptdlsinfo->ap_prohibited == _TRUE)
261 return _FALSE;
262
263 return _TRUE;
264 }
265
266 #ifdef CONFIG_TDLS_CH_SW
rtw_tdls_is_chsw_allowed(_adapter * padapter)267 u8 rtw_tdls_is_chsw_allowed(_adapter *padapter)
268 {
269 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
270
271 if (ptdlsinfo->ch_switch_prohibited == _TRUE)
272 return _FALSE;
273
274 if (padapter->registrypriv.wifi_spec == 0)
275 return _FALSE;
276
277 return _TRUE;
278 }
279 #endif
280
_issue_nulldata_to_TDLS_peer_STA(_adapter * padapter,unsigned char * da,unsigned int power_mode,int wait_ms)281 int _issue_nulldata_to_TDLS_peer_STA(_adapter *padapter, unsigned char *da, unsigned int power_mode, int wait_ms)
282 {
283 int ret = _FAIL;
284 struct xmit_frame *pmgntframe;
285 struct pkt_attrib *pattrib;
286 unsigned char *pframe;
287 struct rtw_ieee80211_hdr *pwlanhdr;
288 unsigned short *fctrl, *qc;
289 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
290 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
291 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
292
293 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
294 if (pmgntframe == NULL)
295 goto exit;
296
297 pattrib = &pmgntframe->attrib;
298 update_mgntframe_attrib(padapter, pattrib);
299
300 pattrib->hdrlen += 2;
301 pattrib->qos_en = _TRUE;
302 pattrib->eosp = 1;
303 pattrib->ack_policy = 0;
304 pattrib->mdata = 0;
305 pattrib->retry_ctrl = _FALSE;
306
307 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
308
309 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
310 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
311
312 fctrl = &(pwlanhdr->frame_ctl);
313 *(fctrl) = 0;
314
315 if (power_mode)
316 SetPwrMgt(fctrl);
317
318 qc = (unsigned short *)(pframe + pattrib->hdrlen - 2);
319
320 SetPriority(qc, 7); /* Set priority to VO */
321
322 SetEOSP(qc, pattrib->eosp);
323
324 SetAckpolicy(qc, pattrib->ack_policy);
325
326 _rtw_memcpy(pwlanhdr->addr1, da, ETH_ALEN);
327 _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
328 _rtw_memcpy(pwlanhdr->addr3, get_my_bssid(&(pmlmeinfo->network)), ETH_ALEN);
329
330 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
331 pmlmeext->mgnt_seq++;
332 set_frame_sub_type(pframe, WIFI_QOS_DATA_NULL);
333
334 pframe += sizeof(struct rtw_ieee80211_hdr_3addr_qos);
335 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr_qos);
336
337 pattrib->last_txcmdsz = pattrib->pktlen;
338
339 if (wait_ms)
340 ret = dump_mgntframe_and_wait_ack_timeout(padapter, pmgntframe, wait_ms);
341 else {
342 dump_mgntframe(padapter, pmgntframe);
343 ret = _SUCCESS;
344 }
345
346 exit:
347 return ret;
348
349 }
350
351 /*
352 *wait_ms == 0 means that there is no need to wait ack through C2H_CCX_TX_RPT
353 *wait_ms > 0 means you want to wait ack through C2H_CCX_TX_RPT, and the value of wait_ms means the interval between each TX
354 *try_cnt means the maximal TX count to try
355 */
issue_nulldata_to_TDLS_peer_STA(_adapter * padapter,unsigned char * da,unsigned int power_mode,int try_cnt,int wait_ms)356 int issue_nulldata_to_TDLS_peer_STA(_adapter *padapter, unsigned char *da, unsigned int power_mode, int try_cnt, int wait_ms)
357 {
358 int ret;
359 int i = 0;
360 systime start = rtw_get_current_time();
361 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
362 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
363
364 #if 0
365 psta = rtw_get_stainfo(&padapter->stapriv, da);
366 if (psta) {
367 if (power_mode)
368 rtw_hal_macid_sleep(padapter, psta->cmn.mac_id);
369 else
370 rtw_hal_macid_wakeup(padapter, psta->cmn.mac_id);
371 } else {
372 RTW_INFO(FUNC_ADPT_FMT ": Can't find sta info for " MAC_FMT ", skip macid %s!!\n",
373 FUNC_ADPT_ARG(padapter), MAC_ARG(da), power_mode ? "sleep" : "wakeup");
374 rtw_warn_on(1);
375 }
376 #endif
377
378 do {
379 ret = _issue_nulldata_to_TDLS_peer_STA(padapter, da, power_mode, wait_ms);
380
381 i++;
382
383 if (RTW_CANNOT_RUN(padapter))
384 break;
385
386 if (i < try_cnt && wait_ms > 0 && ret == _FAIL)
387 rtw_msleep_os(wait_ms);
388
389 } while ((i < try_cnt) && (ret == _FAIL || wait_ms == 0));
390
391 if (ret != _FAIL) {
392 ret = _SUCCESS;
393 #ifndef DBG_XMIT_ACK
394 goto exit;
395 #endif
396 }
397
398 if (try_cnt && wait_ms) {
399 if (da)
400 RTW_INFO(FUNC_ADPT_FMT" to "MAC_FMT", ch:%u%s, %d/%d in %u ms\n",
401 FUNC_ADPT_ARG(padapter), MAC_ARG(da), rtw_get_oper_ch(padapter),
402 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
403 else
404 RTW_INFO(FUNC_ADPT_FMT", ch:%u%s, %d/%d in %u ms\n",
405 FUNC_ADPT_ARG(padapter), rtw_get_oper_ch(padapter),
406 ret == _SUCCESS ? ", acked" : "", i, try_cnt, rtw_get_passing_time_ms(start));
407 }
408 exit:
409 return ret;
410 }
411
412 /* TDLS encryption(if needed) will always be CCMP */
rtw_tdls_set_key(_adapter * padapter,struct sta_info * ptdls_sta)413 void rtw_tdls_set_key(_adapter *padapter, struct sta_info *ptdls_sta)
414 {
415 ptdls_sta->dot118021XPrivacy = _AES_;
416 rtw_setstakey_cmd(padapter, ptdls_sta, TDLS_KEY, _TRUE);
417 }
418
419 #ifdef CONFIG_80211N_HT
rtw_tdls_process_ht_cap(_adapter * padapter,struct sta_info * ptdls_sta,u8 * data,u8 Length)420 void rtw_tdls_process_ht_cap(_adapter *padapter, struct sta_info *ptdls_sta, u8 *data, u8 Length)
421 {
422 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
423 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
424 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
425 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
426 u8 max_AMPDU_len, min_MPDU_spacing;
427 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, cur_beamform_cap = 0;
428
429 /* Save HT capabilities in the sta object */
430 _rtw_memset(&ptdls_sta->htpriv.ht_cap, 0, sizeof(struct rtw_ieee80211_ht_cap));
431 if (data && Length >= sizeof(struct rtw_ieee80211_ht_cap)) {
432 ptdls_sta->flags |= WLAN_STA_HT;
433 ptdls_sta->flags |= WLAN_STA_WME;
434
435 _rtw_memcpy(&ptdls_sta->htpriv.ht_cap, data, sizeof(struct rtw_ieee80211_ht_cap));
436 } else {
437 ptdls_sta->flags &= ~WLAN_STA_HT;
438 return;
439 }
440
441 if (ptdls_sta->flags & WLAN_STA_HT) {
442 if (padapter->registrypriv.ht_enable == _TRUE && is_supported_ht(padapter->registrypriv.wireless_mode) ) {
443 ptdls_sta->htpriv.ht_option = _TRUE;
444 ptdls_sta->qos_option = _TRUE;
445 } else {
446 ptdls_sta->htpriv.ht_option = _FALSE;
447 ptdls_sta->qos_option = _FALSE;
448 }
449 }
450
451 /* HT related cap */
452 if (ptdls_sta->htpriv.ht_option) {
453 /* Check if sta supports rx ampdu */
454 if (padapter->registrypriv.ampdu_enable == 1)
455 ptdls_sta->htpriv.ampdu_enable = _TRUE;
456
457 /* AMPDU Parameters field */
458 /* Get MIN of MAX AMPDU Length Exp */
459 if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3) > (data[2] & 0x3))
460 max_AMPDU_len = (data[2] & 0x3);
461 else
462 max_AMPDU_len = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x3);
463 /* Get MAX of MIN MPDU Start Spacing */
464 if ((pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c) > (data[2] & 0x1c))
465 min_MPDU_spacing = (pmlmeinfo->HT_caps.u.HT_cap_element.AMPDU_para & 0x1c);
466 else
467 min_MPDU_spacing = (data[2] & 0x1c);
468 ptdls_sta->htpriv.rx_ampdu_min_spacing = max_AMPDU_len | min_MPDU_spacing;
469
470 /* Check if sta support s Short GI 20M */
471 if ((phtpriv->sgi_20m == _TRUE) && (ptdls_sta->htpriv.ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SGI_20)))
472 ptdls_sta->htpriv.sgi_20m = _TRUE;
473
474 /* Check if sta support s Short GI 40M */
475 if ((phtpriv->sgi_40m == _TRUE) && (ptdls_sta->htpriv.ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SGI_40)))
476 ptdls_sta->htpriv.sgi_40m = _TRUE;
477
478 /* Bwmode would still followed AP's setting */
479 if (ptdls_sta->htpriv.ht_cap.cap_info & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH)) {
480 if (padapter->mlmeextpriv.cur_bwmode >= CHANNEL_WIDTH_40)
481 ptdls_sta->cmn.bw_mode = CHANNEL_WIDTH_40;
482 ptdls_sta->htpriv.ch_offset = padapter->mlmeextpriv.cur_ch_offset;
483 }
484
485 /* Config LDPC Coding Capability */
486 if (TEST_FLAG(phtpriv->ldpc_cap, LDPC_HT_ENABLE_TX) && GET_HT_CAP_ELE_LDPC_CAP(data)) {
487 SET_FLAG(cur_ldpc_cap, (LDPC_HT_ENABLE_TX | LDPC_HT_CAP_TX));
488 RTW_INFO("Enable HT Tx LDPC!\n");
489 }
490 ptdls_sta->htpriv.ldpc_cap = cur_ldpc_cap;
491
492 /* Config STBC setting */
493 if (TEST_FLAG(phtpriv->stbc_cap, STBC_HT_ENABLE_TX) && GET_HT_CAP_ELE_RX_STBC(data)) {
494 SET_FLAG(cur_stbc_cap, (STBC_HT_ENABLE_TX | STBC_HT_CAP_TX));
495 RTW_INFO("Enable HT Tx STBC!\n");
496 }
497 ptdls_sta->htpriv.stbc_cap = cur_stbc_cap;
498
499 #ifdef CONFIG_BEAMFORMING
500 /* Config Tx beamforming setting */
501 if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE) &&
502 GET_HT_CAP_TXBF_EXPLICIT_COMP_STEERING_CAP(data))
503 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE);
504
505 if (TEST_FLAG(phtpriv->beamform_cap, BEAMFORMING_HT_BEAMFORMER_ENABLE) &&
506 GET_HT_CAP_TXBF_EXPLICIT_COMP_FEEDBACK_CAP(data))
507 SET_FLAG(cur_beamform_cap, BEAMFORMING_HT_BEAMFORMEE_ENABLE);
508 ptdls_sta->htpriv.beamform_cap = cur_beamform_cap;
509 if (cur_beamform_cap)
510 RTW_INFO("Client HT Beamforming Cap = 0x%02X\n", cur_beamform_cap);
511 #endif /* CONFIG_BEAMFORMING */
512 }
513
514 }
515
rtw_tdls_set_ht_cap(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)516 u8 *rtw_tdls_set_ht_cap(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
517 {
518 rtw_ht_use_default_setting(padapter);
519
520 if (padapter->registrypriv.wifi_spec == 1) {
521 padapter->mlmepriv.htpriv.sgi_20m = _FALSE;
522 padapter->mlmepriv.htpriv.sgi_40m = _FALSE;
523 }
524
525 rtw_restructure_ht_ie(padapter, NULL, pframe, 0, &(pattrib->pktlen), padapter->mlmeextpriv.cur_channel, NULL);
526
527 return pframe + pattrib->pktlen;
528 }
529 #endif
530
531 #ifdef CONFIG_80211AC_VHT
rtw_tdls_process_vht_cap(_adapter * padapter,struct sta_info * ptdls_sta,u8 * data,u8 Length)532 void rtw_tdls_process_vht_cap(_adapter *padapter, struct sta_info *ptdls_sta, u8 *data, u8 Length)
533 {
534 struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
535 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
536 struct vht_priv *pvhtpriv = &pmlmepriv->vhtpriv;
537 u8 cur_ldpc_cap = 0, cur_stbc_cap = 0, tx_nss = 0;
538 u16 cur_beamform_cap = 0;
539 u8 *pcap_mcs;
540
541 _rtw_memset(&ptdls_sta->vhtpriv, 0, sizeof(struct vht_priv));
542 if (data && Length == 12) {
543 ptdls_sta->flags |= WLAN_STA_VHT;
544
545 _rtw_memcpy(ptdls_sta->vhtpriv.vht_cap, data, 12);
546
547 #if 0
548 if (elems.vht_op_mode_notify && elems.vht_op_mode_notify_len == 1)
549 _rtw_memcpy(&pstat->vhtpriv.vht_op_mode_notify, elems.vht_op_mode_notify, 1);
550 else /* for Frame without Operating Mode notify ie; default: 80M */
551 pstat->vhtpriv.vht_op_mode_notify = CHANNEL_WIDTH_80;
552 #else
553 ptdls_sta->vhtpriv.vht_op_mode_notify = CHANNEL_WIDTH_80;
554 #endif
555 } else {
556 ptdls_sta->flags &= ~WLAN_STA_VHT;
557 return;
558 }
559
560 if (ptdls_sta->flags & WLAN_STA_VHT) {
561 if (REGSTY_IS_11AC_ENABLE(&padapter->registrypriv)
562 && is_supported_vht(padapter->registrypriv.wireless_mode)
563 && RFCTL_REG_EN_11AC(rfctl)
564 ) {
565 ptdls_sta->vhtpriv.vht_option = _TRUE;
566 ptdls_sta->cmn.ra_info.is_vht_enable = _TRUE;
567 }
568 else
569 ptdls_sta->vhtpriv.vht_option = _FALSE;
570 }
571
572 /* B4 Rx LDPC */
573 if (TEST_FLAG(pvhtpriv->ldpc_cap, LDPC_VHT_ENABLE_TX) &&
574 GET_VHT_CAPABILITY_ELE_RX_LDPC(data)) {
575 SET_FLAG(cur_ldpc_cap, (LDPC_VHT_ENABLE_TX | LDPC_VHT_CAP_TX));
576 RTW_INFO("Current VHT LDPC Setting = %02X\n", cur_ldpc_cap);
577 }
578 ptdls_sta->vhtpriv.ldpc_cap = cur_ldpc_cap;
579
580 /* B5 Short GI for 80 MHz */
581 ptdls_sta->vhtpriv.sgi_80m = (GET_VHT_CAPABILITY_ELE_SHORT_GI80M(data) & pvhtpriv->sgi_80m) ? _TRUE : _FALSE;
582
583 /* B8 B9 B10 Rx STBC */
584 if (TEST_FLAG(pvhtpriv->stbc_cap, STBC_VHT_ENABLE_TX) &&
585 GET_VHT_CAPABILITY_ELE_RX_STBC(data)) {
586 SET_FLAG(cur_stbc_cap, (STBC_VHT_ENABLE_TX | STBC_VHT_CAP_TX));
587 RTW_INFO("Current VHT STBC Setting = %02X\n", cur_stbc_cap);
588 }
589 ptdls_sta->vhtpriv.stbc_cap = cur_stbc_cap;
590
591 #ifdef CONFIG_BEAMFORMING
592 /* B11 SU Beamformer Capable, the target supports Beamformer and we are Beamformee */
593 if (TEST_FLAG(pvhtpriv->beamform_cap, BEAMFORMING_VHT_BEAMFORMER_ENABLE) &&
594 GET_VHT_CAPABILITY_ELE_SU_BFEE(data))
595 SET_FLAG(cur_beamform_cap, BEAMFORMING_VHT_BEAMFORMEE_ENABLE);
596
597 /* B12 SU Beamformee Capable, the target supports Beamformee and we are Beamformer */
598 if (TEST_FLAG(pvhtpriv->beamform_cap, BEAMFORMING_VHT_BEAMFORMEE_ENABLE) &&
599 GET_VHT_CAPABILITY_ELE_SU_BFER(data))
600 SET_FLAG(cur_beamform_cap, BEAMFORMING_VHT_BEAMFORMER_ENABLE);
601 ptdls_sta->vhtpriv.beamform_cap = cur_beamform_cap;
602 ptdls_sta->cmn.bf_info.vht_beamform_cap = cur_beamform_cap;
603 if (cur_beamform_cap)
604 RTW_INFO("Current VHT Beamforming Setting = %02X\n", cur_beamform_cap);
605 #endif /*CONFIG_BEAMFORMING*/
606
607 /* B23 B24 B25 Maximum A-MPDU Length Exponent */
608 ptdls_sta->vhtpriv.ampdu_len = GET_VHT_CAPABILITY_ELE_MAX_RXAMPDU_FACTOR(data);
609
610 pcap_mcs = GET_VHT_CAPABILITY_ELE_RX_MCS(data);
611 tx_nss = GET_HAL_TX_NSS(padapter);
612 rtw_vht_nss_to_mcsmap(tx_nss, ptdls_sta->vhtpriv.vht_mcs_map, pcap_mcs);
613 ptdls_sta->vhtpriv.vht_highest_rate = rtw_get_vht_highest_rate(ptdls_sta->vhtpriv.vht_mcs_map);
614 }
615
rtw_tdls_process_vht_operation(_adapter * padapter,struct sta_info * ptdls_sta,u8 * data,u8 Length)616 void rtw_tdls_process_vht_operation(_adapter *padapter, struct sta_info *ptdls_sta, u8 *data, u8 Length)
617 {
618 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
619 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
620 struct registry_priv *regsty = adapter_to_regsty(padapter);
621 u8 operation_bw = 0;
622
623 if (GET_VHT_OPERATION_ELE_CHL_WIDTH(data) >= 1) {
624
625 operation_bw = CHANNEL_WIDTH_80;
626
627 if (hal_is_bw_support(padapter, operation_bw) && REGSTY_IS_BW_5G_SUPPORT(regsty, operation_bw)
628 && (operation_bw <= pmlmeext->cur_bwmode))
629 ptdls_sta->cmn.bw_mode = operation_bw;
630 else
631 ptdls_sta->cmn.bw_mode = pmlmeext->cur_bwmode;
632 } else
633 ptdls_sta->cmn.bw_mode = pmlmeext->cur_bwmode;
634 }
635
rtw_tdls_process_vht_op_mode_notify(_adapter * padapter,struct sta_info * ptdls_sta,u8 * data,u8 Length)636 void rtw_tdls_process_vht_op_mode_notify(_adapter *padapter, struct sta_info *ptdls_sta, u8 *data, u8 Length)
637 {
638 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
639 struct vht_priv *pvhtpriv = &pmlmepriv->vhtpriv;
640 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
641 struct registry_priv *regsty = adapter_to_regsty(padapter);
642 u8 target_bw;
643 u8 target_rxss, current_rxss;
644
645 if (pvhtpriv->vht_option == _FALSE)
646 return;
647
648 target_bw = GET_VHT_OPERATING_MODE_FIELD_CHNL_WIDTH(data);
649 target_rxss = (GET_VHT_OPERATING_MODE_FIELD_RX_NSS(data) + 1);
650
651 if (hal_is_bw_support(padapter, target_bw) && REGSTY_IS_BW_5G_SUPPORT(regsty, target_bw)
652 && (target_bw <= pmlmeext->cur_bwmode))
653 ptdls_sta->cmn.bw_mode = target_bw;
654 else
655 ptdls_sta->cmn.bw_mode = pmlmeext->cur_bwmode;
656
657 current_rxss = rtw_vht_mcsmap_to_nss(ptdls_sta->vhtpriv.vht_mcs_map);
658 if (target_rxss != current_rxss) {
659 u8 vht_mcs_map[2] = {};
660
661 rtw_vht_nss_to_mcsmap(target_rxss, vht_mcs_map, ptdls_sta->vhtpriv.vht_mcs_map);
662 _rtw_memcpy(ptdls_sta->vhtpriv.vht_mcs_map, vht_mcs_map, 2);
663 }
664 }
665
rtw_tdls_set_aid(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)666 u8 *rtw_tdls_set_aid(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
667 {
668 return rtw_set_ie(pframe, EID_AID, 2, (u8 *)&(padapter->mlmepriv.cur_network.aid), &(pattrib->pktlen));
669 }
670
rtw_tdls_set_vht_cap(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)671 u8 *rtw_tdls_set_vht_cap(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
672 {
673 u32 ie_len = 0;
674
675 rtw_vht_use_default_setting(padapter);
676
677 ie_len = rtw_build_vht_cap_ie(padapter, pframe);
678 pattrib->pktlen += ie_len;
679
680 return pframe + ie_len;
681 }
682
rtw_tdls_set_vht_operation(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib,u8 channel)683 u8 *rtw_tdls_set_vht_operation(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib, u8 channel)
684 {
685 u32 ie_len = 0;
686
687 ie_len = rtw_build_vht_operation_ie(padapter, pframe, channel);
688 pattrib->pktlen += ie_len;
689
690 return pframe + ie_len;
691 }
692
rtw_tdls_set_vht_op_mode_notify(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib,u8 bw)693 u8 *rtw_tdls_set_vht_op_mode_notify(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib, u8 bw)
694 {
695 u32 ie_len = 0;
696
697 ie_len = rtw_build_vht_op_mode_notify_ie(padapter, pframe, bw);
698 pattrib->pktlen += ie_len;
699
700 return pframe + ie_len;
701 }
702 #endif
703
704
rtw_tdls_set_sup_ch(_adapter * adapter,u8 * pframe,struct pkt_attrib * pattrib)705 u8 *rtw_tdls_set_sup_ch(_adapter *adapter, u8 *pframe, struct pkt_attrib *pattrib)
706 {
707 struct rf_ctl_t *rfctl = adapter_to_rfctl(adapter);
708 u8 sup_ch[30 * 2] = {0x00}, ch_set_idx = 0, sup_ch_idx = 2;
709
710 while (ch_set_idx < rfctl->max_chan_nums && rfctl->channel_set[ch_set_idx].ChannelNum != 0) {
711 if (rfctl->channel_set[ch_set_idx].ChannelNum <= 14) {
712 /* TODO: fix 2.4G supported channel when channel doesn't start from 1 and continuous */
713 sup_ch[0] = 1; /* First channel number */
714 sup_ch[1] = rfctl->channel_set[ch_set_idx].ChannelNum; /* Number of channel */
715 } else {
716 sup_ch[sup_ch_idx++] = rfctl->channel_set[ch_set_idx].ChannelNum;
717 sup_ch[sup_ch_idx++] = 1;
718 }
719 ch_set_idx++;
720 }
721
722 return rtw_set_ie(pframe, _SUPPORTED_CH_IE_, sup_ch_idx, sup_ch, &(pattrib->pktlen));
723 }
724
rtw_tdls_set_rsnie(struct tdls_txmgmt * ptxmgmt,u8 * pframe,struct pkt_attrib * pattrib,int init,struct sta_info * ptdls_sta)725 u8 *rtw_tdls_set_rsnie(struct tdls_txmgmt *ptxmgmt, u8 *pframe, struct pkt_attrib *pattrib, int init, struct sta_info *ptdls_sta)
726 {
727 u8 *p = NULL;
728 int len = 0;
729
730 if (ptxmgmt->len > 0)
731 p = rtw_get_ie(ptxmgmt->buf, _RSN_IE_2_, &len, ptxmgmt->len);
732
733 if (p != NULL)
734 return rtw_set_ie(pframe, _RSN_IE_2_, len, p + 2, &(pattrib->pktlen));
735 else if (init == _TRUE)
736 return rtw_set_ie(pframe, _RSN_IE_2_, sizeof(TDLS_RSNIE), TDLS_RSNIE, &(pattrib->pktlen));
737 else
738 return rtw_set_ie(pframe, _RSN_IE_2_, sizeof(ptdls_sta->TDLS_RSNIE), ptdls_sta->TDLS_RSNIE, &(pattrib->pktlen));
739 }
740
rtw_tdls_set_ext_cap(u8 * pframe,struct pkt_attrib * pattrib)741 u8 *rtw_tdls_set_ext_cap(u8 *pframe, struct pkt_attrib *pattrib)
742 {
743 return rtw_set_ie(pframe, WLAN_EID_EXT_CAP , sizeof(TDLS_EXT_CAPIE), TDLS_EXT_CAPIE, &(pattrib->pktlen));
744 }
745
rtw_tdls_set_qos_cap(u8 * pframe,struct pkt_attrib * pattrib)746 u8 *rtw_tdls_set_qos_cap(u8 *pframe, struct pkt_attrib *pattrib)
747 {
748 return rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, sizeof(TDLS_WMMIE), TDLS_WMMIE, &(pattrib->pktlen));
749 }
750
rtw_tdls_set_ftie(struct tdls_txmgmt * ptxmgmt,u8 * pframe,struct pkt_attrib * pattrib,u8 * ANonce,u8 * SNonce)751 u8 *rtw_tdls_set_ftie(struct tdls_txmgmt *ptxmgmt, u8 *pframe, struct pkt_attrib *pattrib, u8 *ANonce, u8 *SNonce)
752 {
753 struct wpa_tdls_ftie FTIE = {0};
754 u8 *p = NULL;
755 int len = 0;
756
757 if (ptxmgmt->len > 0)
758 p = rtw_get_ie(ptxmgmt->buf, _FTIE_, &len, ptxmgmt->len);
759
760 if (p != NULL)
761 return rtw_set_ie(pframe, _FTIE_, len, p + 2, &(pattrib->pktlen));
762 else {
763 if (ANonce != NULL)
764 _rtw_memcpy(FTIE.Anonce, ANonce, WPA_NONCE_LEN);
765 if (SNonce != NULL)
766 _rtw_memcpy(FTIE.Snonce, SNonce, WPA_NONCE_LEN);
767
768 return rtw_set_ie(pframe, _FTIE_, TDLS_FTIE_DATA_LEN,
769 (u8 *)FTIE.data, &(pattrib->pktlen));
770 }
771 }
772
rtw_tdls_set_timeout_interval(struct tdls_txmgmt * ptxmgmt,u8 * pframe,struct pkt_attrib * pattrib,int init,struct sta_info * ptdls_sta)773 u8 *rtw_tdls_set_timeout_interval(struct tdls_txmgmt *ptxmgmt, u8 *pframe, struct pkt_attrib *pattrib, int init, struct sta_info *ptdls_sta)
774 {
775 u8 timeout_itvl[5]; /* set timeout interval to maximum value */
776 u32 timeout_interval = TDLS_TPK_RESEND_COUNT;
777 u8 *p = NULL;
778 int len = 0;
779
780 if (ptxmgmt->len > 0)
781 p = rtw_get_ie(ptxmgmt->buf, _TIMEOUT_ITVL_IE_, &len, ptxmgmt->len);
782
783 if (p != NULL)
784 return rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, len, p + 2, &(pattrib->pktlen));
785 else {
786 /* Timeout interval */
787 timeout_itvl[0] = 0x02;
788 if (init == _TRUE)
789 _rtw_memcpy(timeout_itvl + 1, &timeout_interval, 4);
790 else
791 _rtw_memcpy(timeout_itvl + 1, (u8 *)(&ptdls_sta->TDLS_PeerKey_Lifetime), 4);
792
793 return rtw_set_ie(pframe, _TIMEOUT_ITVL_IE_, 5, timeout_itvl, &(pattrib->pktlen));
794 }
795 }
796
rtw_tdls_set_bss_coexist(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)797 u8 *rtw_tdls_set_bss_coexist(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
798 {
799 u8 iedata = 0;
800
801 if (padapter->mlmepriv.num_FortyMHzIntolerant > 0)
802 iedata |= BIT(2); /* 20 MHz BSS Width Request */
803
804 /* Information Bit should be set by TDLS test plan 5.9 */
805 iedata |= BIT(0);
806 return rtw_set_ie(pframe, EID_BSSCoexistence, 1, &iedata, &(pattrib->pktlen));
807 }
808
rtw_tdls_set_payload_type(u8 * pframe,struct pkt_attrib * pattrib)809 u8 *rtw_tdls_set_payload_type(u8 *pframe, struct pkt_attrib *pattrib)
810 {
811 u8 payload_type = 0x02;
812 return rtw_set_fixed_ie(pframe, 1, &(payload_type), &(pattrib->pktlen));
813 }
814
rtw_tdls_set_category(u8 * pframe,struct pkt_attrib * pattrib,u8 category)815 u8 *rtw_tdls_set_category(u8 *pframe, struct pkt_attrib *pattrib, u8 category)
816 {
817 return rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
818 }
819
rtw_tdls_set_action(u8 * pframe,struct pkt_attrib * pattrib,struct tdls_txmgmt * ptxmgmt)820 u8 *rtw_tdls_set_action(u8 *pframe, struct pkt_attrib *pattrib, struct tdls_txmgmt *ptxmgmt)
821 {
822 return rtw_set_fixed_ie(pframe, 1, &(ptxmgmt->action_code), &(pattrib->pktlen));
823 }
824
rtw_tdls_set_status_code(u8 * pframe,struct pkt_attrib * pattrib,struct tdls_txmgmt * ptxmgmt)825 u8 *rtw_tdls_set_status_code(u8 *pframe, struct pkt_attrib *pattrib, struct tdls_txmgmt *ptxmgmt)
826 {
827 return rtw_set_fixed_ie(pframe, 2, (u8 *)&(ptxmgmt->status_code), &(pattrib->pktlen));
828 }
829
rtw_tdls_set_dialog(u8 * pframe,struct pkt_attrib * pattrib,struct tdls_txmgmt * ptxmgmt)830 u8 *rtw_tdls_set_dialog(u8 *pframe, struct pkt_attrib *pattrib, struct tdls_txmgmt *ptxmgmt)
831 {
832 u8 dialogtoken = 1;
833 if (ptxmgmt->dialog_token)
834 return rtw_set_fixed_ie(pframe, 1, &(ptxmgmt->dialog_token), &(pattrib->pktlen));
835 else
836 return rtw_set_fixed_ie(pframe, 1, &(dialogtoken), &(pattrib->pktlen));
837 }
838
rtw_tdls_set_reg_class(u8 * pframe,struct pkt_attrib * pattrib,struct sta_info * ptdls_sta)839 u8 *rtw_tdls_set_reg_class(u8 *pframe, struct pkt_attrib *pattrib, struct sta_info *ptdls_sta)
840 {
841 u8 reg_class = 22;
842 return rtw_set_fixed_ie(pframe, 1, &(reg_class), &(pattrib->pktlen));
843 }
844
rtw_tdls_set_second_channel_offset(u8 * pframe,struct pkt_attrib * pattrib,u8 ch_offset)845 u8 *rtw_tdls_set_second_channel_offset(u8 *pframe, struct pkt_attrib *pattrib, u8 ch_offset)
846 {
847 return rtw_set_ie(pframe, EID_SecondaryChnlOffset , 1, &ch_offset, &(pattrib->pktlen));
848 }
849
rtw_tdls_set_capability(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)850 u8 *rtw_tdls_set_capability(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
851 {
852 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
853 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
854 u8 cap_from_ie[2] = {0};
855
856 _rtw_memcpy(cap_from_ie, rtw_get_capability_from_ie(pmlmeinfo->network.IEs), 2);
857
858 return rtw_set_fixed_ie(pframe, 2, cap_from_ie, &(pattrib->pktlen));
859 }
860
rtw_tdls_set_supported_rate(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)861 u8 *rtw_tdls_set_supported_rate(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
862 {
863 u8 bssrate[NDIS_802_11_LENGTH_RATES_EX];
864 int bssrate_len = 0;
865 u8 more_supportedrates = 0;
866
867 rtw_set_supported_rate(bssrate, (padapter->registrypriv.wireless_mode == WIRELESS_MODE_MAX) ? padapter->mlmeextpriv.cur_wireless_mode : padapter->registrypriv.wireless_mode);
868 bssrate_len = rtw_get_rateset_len(bssrate);
869
870 if (bssrate_len > 8) {
871 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , 8, bssrate, &(pattrib->pktlen));
872 more_supportedrates = 1;
873 } else
874 pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_ , bssrate_len , bssrate, &(pattrib->pktlen));
875
876 /* extended supported rates */
877 if (more_supportedrates == 1)
878 pframe = rtw_set_ie(pframe, _EXT_SUPPORTEDRATES_IE_ , (bssrate_len - 8), (bssrate + 8), &(pattrib->pktlen));
879
880 return pframe;
881 }
882
rtw_tdls_set_sup_reg_class(u8 * pframe,struct pkt_attrib * pattrib)883 u8 *rtw_tdls_set_sup_reg_class(u8 *pframe, struct pkt_attrib *pattrib)
884 {
885 return rtw_set_ie(pframe, _SRC_IE_ , sizeof(TDLS_SRC), TDLS_SRC, &(pattrib->pktlen));
886 }
887
rtw_tdls_set_linkid(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib,u8 init)888 u8 *rtw_tdls_set_linkid(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib, u8 init)
889 {
890 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
891 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
892
893 u8 link_id_addr[18] = {0};
894
895 _rtw_memcpy(link_id_addr, get_my_bssid(&(pmlmeinfo->network)), 6);
896
897 if (init == _TRUE) {
898 _rtw_memcpy((link_id_addr + 6), pattrib->src, 6);
899 _rtw_memcpy((link_id_addr + 12), pattrib->dst, 6);
900 } else {
901 _rtw_memcpy((link_id_addr + 6), pattrib->dst, 6);
902 _rtw_memcpy((link_id_addr + 12), pattrib->src, 6);
903 }
904 return rtw_set_ie(pframe, _LINK_ID_IE_, 18, link_id_addr, &(pattrib->pktlen));
905 }
906
907 #ifdef CONFIG_TDLS_CH_SW
rtw_tdls_set_target_ch(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)908 u8 *rtw_tdls_set_target_ch(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
909 {
910 u8 target_ch = 1;
911 if (padapter->tdlsinfo.chsw_info.off_ch_num)
912 return rtw_set_fixed_ie(pframe, 1, &(padapter->tdlsinfo.chsw_info.off_ch_num), &(pattrib->pktlen));
913 else
914 return rtw_set_fixed_ie(pframe, 1, &(target_ch), &(pattrib->pktlen));
915 }
916
rtw_tdls_set_ch_sw(u8 * pframe,struct pkt_attrib * pattrib,struct sta_info * ptdls_sta)917 u8 *rtw_tdls_set_ch_sw(u8 *pframe, struct pkt_attrib *pattrib, struct sta_info *ptdls_sta)
918 {
919 u8 ch_switch_timing[4] = {0};
920 u16 switch_time = (ptdls_sta->ch_switch_time >= TDLS_CH_SWITCH_TIME * 1000) ?
921 ptdls_sta->ch_switch_time : TDLS_CH_SWITCH_TIME;
922 u16 switch_timeout = (ptdls_sta->ch_switch_timeout >= TDLS_CH_SWITCH_TIMEOUT * 1000) ?
923 ptdls_sta->ch_switch_timeout : TDLS_CH_SWITCH_TIMEOUT;
924
925 _rtw_memcpy(ch_switch_timing, &switch_time, 2);
926 _rtw_memcpy(ch_switch_timing + 2, &switch_timeout, 2);
927
928 return rtw_set_ie(pframe, _CH_SWITCH_TIMING_, 4, ch_switch_timing, &(pattrib->pktlen));
929 }
930
rtw_tdls_set_ch_sw_oper_control(_adapter * padapter,u8 enable)931 void rtw_tdls_set_ch_sw_oper_control(_adapter *padapter, u8 enable)
932 {
933 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
934 u8 bcn_early_case;
935
936 if (enable == _TRUE) {
937 #ifdef CONFIG_TDLS_CH_SW_V2
938 pHalData->ch_switch_offload = _TRUE;
939 #endif
940
941 #ifdef CONFIG_TDLS_CH_SW_BY_DRV
942 pHalData->ch_switch_offload = _FALSE;
943 #endif
944 bcn_early_case = TDLS_BCN_ERLY_ON;
945 }
946 else {
947 pHalData->ch_switch_offload = _FALSE;
948 bcn_early_case = TDLS_BCN_ERLY_OFF;
949 }
950
951 if (ATOMIC_READ(&padapter->tdlsinfo.chsw_info.chsw_on) != enable)
952 ATOMIC_SET(&padapter->tdlsinfo.chsw_info.chsw_on, enable);
953
954 rtw_hal_set_hwreg(padapter, HW_VAR_BCN_EARLY_C2H_RPT, &enable);
955 rtw_hal_set_hwreg(padapter, HW_VAR_SET_DRV_ERLY_INT, &bcn_early_case);
956 RTW_INFO("[TDLS] %s Bcn Early C2H Report\n", (enable == _TRUE) ? "Start" : "Stop");
957 }
958
rtw_tdls_ch_sw_back_to_base_chnl(_adapter * padapter)959 void rtw_tdls_ch_sw_back_to_base_chnl(_adapter *padapter)
960 {
961 struct mlme_priv *pmlmepriv;
962 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
963
964 pmlmepriv = &padapter->mlmepriv;
965
966 if ((ATOMIC_READ(&pchsw_info->chsw_on) == _TRUE) &&
967 (padapter->mlmeextpriv.cur_channel != rtw_get_oper_ch(padapter)))
968 rtw_tdls_cmd(padapter, pchsw_info->addr, TDLS_CH_SW_TO_BASE_CHNL_UNSOLICITED);
969 }
970
971 #ifndef CONFIG_TDLS_CH_SW_V2
rtw_tdls_chsw_oper_init(_adapter * padapter,u32 timeout_ms)972 static void rtw_tdls_chsw_oper_init(_adapter *padapter, u32 timeout_ms)
973 {
974 struct submit_ctx *chsw_sctx = &padapter->tdlsinfo.chsw_info.chsw_sctx;
975
976 rtw_sctx_init(chsw_sctx, timeout_ms);
977 }
978
rtw_tdls_chsw_oper_wait(_adapter * padapter)979 static int rtw_tdls_chsw_oper_wait(_adapter *padapter)
980 {
981 struct submit_ctx *chsw_sctx = &padapter->tdlsinfo.chsw_info.chsw_sctx;
982
983 return rtw_sctx_wait(chsw_sctx, __func__);
984 }
985
rtw_tdls_chsw_oper_done(_adapter * padapter)986 void rtw_tdls_chsw_oper_done(_adapter *padapter)
987 {
988 struct submit_ctx *chsw_sctx = &padapter->tdlsinfo.chsw_info.chsw_sctx;
989
990 rtw_sctx_done(&chsw_sctx);
991 }
992 #endif
993
rtw_tdls_do_ch_sw(_adapter * padapter,struct sta_info * ptdls_sta,u8 chnl_type,u8 channel,u8 channel_offset,u16 bwmode,u16 ch_switch_time)994 s32 rtw_tdls_do_ch_sw(_adapter *padapter, struct sta_info *ptdls_sta, u8 chnl_type, u8 channel, u8 channel_offset, u16 bwmode, u16 ch_switch_time)
995 {
996 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
997 u8 center_ch, chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
998 u32 ch_sw_time_start, ch_sw_time_spent, wait_time;
999 u8 take_care_iqk;
1000 s32 ret = _FAIL;
1001
1002 ch_sw_time_start = rtw_systime_to_ms(rtw_get_current_time());
1003
1004 /* set mac_id sleep before channel switch */
1005 rtw_hal_macid_sleep(padapter, ptdls_sta->cmn.mac_id);
1006
1007 #if defined(CONFIG_TDLS_CH_SW_BY_DRV) || defined(CONFIG_TDLS_CH_SW_V2)
1008 set_channel_bwmode(padapter, channel, channel_offset, bwmode);
1009 ret = _SUCCESS;
1010 #else
1011 rtw_tdls_chsw_oper_init(padapter, TDLS_CH_SWITCH_OPER_OFFLOAD_TIMEOUT);
1012
1013 /* channel switch IOs offload to FW */
1014 if (rtw_hal_ch_sw_oper_offload(padapter, channel, channel_offset, bwmode) == _SUCCESS) {
1015 if (rtw_tdls_chsw_oper_wait(padapter) == _SUCCESS) {
1016 /* set channel and bw related variables in driver */
1017 _enter_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
1018
1019 rtw_set_oper_ch(padapter, channel);
1020 rtw_set_oper_choffset(padapter, channel_offset);
1021 rtw_set_oper_bw(padapter, bwmode);
1022
1023 center_ch = rtw_get_center_ch(channel, bwmode, channel_offset);
1024 pHalData->current_channel = center_ch;
1025 pHalData->CurrentCenterFrequencyIndex1 = center_ch;
1026 pHalData->current_channel_bw = bwmode;
1027 pHalData->nCur40MhzPrimeSC = channel_offset;
1028
1029 if (bwmode == CHANNEL_WIDTH_80) {
1030 if (center_ch > channel)
1031 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_LOWER;
1032 else if (center_ch < channel)
1033 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_UPPER;
1034 else
1035 chnl_offset80 = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
1036 }
1037 pHalData->nCur80MhzPrimeSC = chnl_offset80;
1038
1039 pHalData->CurrentCenterFrequencyIndex1 = center_ch;
1040
1041 _exit_critical_mutex(&(adapter_to_dvobj(padapter)->setch_mutex), NULL);
1042
1043 rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
1044 if (take_care_iqk == _TRUE)
1045 rtw_hal_ch_sw_iqk_info_restore(padapter, CH_SW_USE_CASE_TDLS);
1046
1047 ret = _SUCCESS;
1048 } else
1049 RTW_INFO("[TDLS] chsw oper wait fail !!\n");
1050 }
1051 #endif
1052
1053 if (ret == _SUCCESS) {
1054 ch_sw_time_spent = rtw_systime_to_ms(rtw_get_current_time()) - ch_sw_time_start;
1055 if (chnl_type == TDLS_CH_SW_OFF_CHNL) {
1056 if ((u32)ch_switch_time / 1000 > ch_sw_time_spent)
1057 wait_time = (u32)ch_switch_time / 1000 - ch_sw_time_spent;
1058 else
1059 wait_time = 0;
1060
1061 if (wait_time > 0)
1062 rtw_msleep_os(wait_time);
1063 }
1064 }
1065
1066 /* set mac_id wakeup after channel switch */
1067 rtw_hal_macid_wakeup(padapter, ptdls_sta->cmn.mac_id);
1068
1069 return ret;
1070 }
1071 #endif
1072
rtw_tdls_set_wmm_params(_adapter * padapter,u8 * pframe,struct pkt_attrib * pattrib)1073 u8 *rtw_tdls_set_wmm_params(_adapter *padapter, u8 *pframe, struct pkt_attrib *pattrib)
1074 {
1075 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1076 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1077 u8 wmm_param_ele[24] = {0};
1078
1079 if (&pmlmeinfo->WMM_param) {
1080 _rtw_memcpy(wmm_param_ele, WMM_PARA_OUI, 6);
1081 if (_rtw_memcmp(&pmlmeinfo->WMM_param, &wmm_param_ele[6], 18) == _TRUE)
1082 /* Use default WMM Param */
1083 _rtw_memcpy(wmm_param_ele + 6, (u8 *)&TDLS_WMM_PARAM_IE, sizeof(TDLS_WMM_PARAM_IE));
1084 else
1085 _rtw_memcpy(wmm_param_ele + 6, (u8 *)&pmlmeinfo->WMM_param, sizeof(pmlmeinfo->WMM_param));
1086 return rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, 24, wmm_param_ele, &(pattrib->pktlen));
1087 } else
1088 return pframe;
1089 }
1090
1091 #ifdef CONFIG_WFD
rtw_tdls_process_wfd_ie(struct tdls_info * ptdlsinfo,u8 * ptr,u8 length)1092 void rtw_tdls_process_wfd_ie(struct tdls_info *ptdlsinfo, u8 *ptr, u8 length)
1093 {
1094 u8 *wfd_ie;
1095 u32 wfd_ielen = 0;
1096
1097 if (!hal_chk_wl_func(tdls_info_to_adapter(ptdlsinfo), WL_FUNC_MIRACAST))
1098 return;
1099
1100 /* Try to get the TCP port information when receiving the negotiation response. */
1101
1102 wfd_ie = rtw_get_wfd_ie(ptr, length, NULL, &wfd_ielen);
1103 while (wfd_ie) {
1104 u8 *attr_content;
1105 u32 attr_contentlen = 0;
1106 int i;
1107
1108 RTW_INFO("[%s] WFD IE Found!!\n", __FUNCTION__);
1109 attr_content = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_DEVICE_INFO, NULL, &attr_contentlen);
1110 if (attr_content && attr_contentlen) {
1111 ptdlsinfo->wfd_info->peer_rtsp_ctrlport = RTW_GET_BE16(attr_content + 2);
1112 RTW_INFO("[%s] Peer PORT NUM = %d\n", __FUNCTION__, ptdlsinfo->wfd_info->peer_rtsp_ctrlport);
1113 }
1114
1115 attr_content = rtw_get_wfd_attr_content(wfd_ie, wfd_ielen, WFD_ATTR_LOCAL_IP_ADDR, NULL, &attr_contentlen);
1116 if (attr_content && attr_contentlen) {
1117 _rtw_memcpy(ptdlsinfo->wfd_info->peer_ip_address, (attr_content + 1), 4);
1118 RTW_INFO("[%s] Peer IP = %02u.%02u.%02u.%02u\n", __FUNCTION__,
1119 ptdlsinfo->wfd_info->peer_ip_address[0], ptdlsinfo->wfd_info->peer_ip_address[1],
1120 ptdlsinfo->wfd_info->peer_ip_address[2], ptdlsinfo->wfd_info->peer_ip_address[3]);
1121 }
1122
1123 wfd_ie = rtw_get_wfd_ie(wfd_ie + wfd_ielen, (ptr + length) - (wfd_ie + wfd_ielen), NULL, &wfd_ielen);
1124 }
1125 }
1126
issue_tunneled_probe_req(_adapter * padapter)1127 int issue_tunneled_probe_req(_adapter *padapter)
1128 {
1129 struct xmit_frame *pmgntframe;
1130 struct pkt_attrib *pattrib;
1131 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1132 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1133 u8 baddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1134 struct tdls_txmgmt txmgmt;
1135 int ret = _FAIL;
1136
1137 RTW_INFO("[%s]\n", __FUNCTION__);
1138
1139 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1140 txmgmt.action_code = TUNNELED_PROBE_REQ;
1141
1142 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1143 if (pmgntframe == NULL)
1144 goto exit;
1145
1146 pattrib = &pmgntframe->attrib;
1147
1148 pmgntframe->frame_tag = DATA_FRAMETAG;
1149 pattrib->ether_type = 0x890d;
1150
1151 _rtw_memcpy(pattrib->dst, baddr, ETH_ALEN);
1152 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1153 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1154 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1155
1156 update_tdls_attrib(padapter, pattrib);
1157 pattrib->qsel = pattrib->priority;
1158 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, &txmgmt) != _SUCCESS) {
1159 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1160 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1161 goto exit;
1162 }
1163 dump_mgntframe(padapter, pmgntframe);
1164 ret = _SUCCESS;
1165 exit:
1166
1167 return ret;
1168 }
1169
issue_tunneled_probe_rsp(_adapter * padapter,union recv_frame * precv_frame)1170 int issue_tunneled_probe_rsp(_adapter *padapter, union recv_frame *precv_frame)
1171 {
1172 struct xmit_frame *pmgntframe;
1173 struct pkt_attrib *pattrib;
1174 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1175 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1176 struct tdls_txmgmt txmgmt;
1177 int ret = _FAIL;
1178
1179 RTW_INFO("[%s]\n", __FUNCTION__);
1180
1181 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1182 txmgmt.action_code = TUNNELED_PROBE_RSP;
1183
1184 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1185 if (pmgntframe == NULL)
1186 goto exit;
1187
1188 pattrib = &pmgntframe->attrib;
1189
1190 pmgntframe->frame_tag = DATA_FRAMETAG;
1191 pattrib->ether_type = 0x890d;
1192
1193 _rtw_memcpy(pattrib->dst, precv_frame->u.hdr.attrib.src, ETH_ALEN);
1194 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1195 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1196 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1197
1198 update_tdls_attrib(padapter, pattrib);
1199 pattrib->qsel = pattrib->priority;
1200 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, &txmgmt) != _SUCCESS) {
1201 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1202 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1203 goto exit;
1204 }
1205 dump_mgntframe(padapter, pmgntframe);
1206 ret = _SUCCESS;
1207 exit:
1208
1209 return ret;
1210 }
1211 #endif /* CONFIG_WFD */
1212
issue_tdls_setup_req(_adapter * padapter,struct tdls_txmgmt * ptxmgmt,int wait_ack)1213 int issue_tdls_setup_req(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, int wait_ack)
1214 {
1215 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
1216 struct xmit_frame *pmgntframe;
1217 struct pkt_attrib *pattrib;
1218 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1219 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1220 struct sta_priv *pstapriv = &padapter->stapriv;
1221 struct sta_info *ptdls_sta = NULL;
1222 _irqL irqL;
1223 int ret = _FAIL;
1224 /* Retry timer should be set at least 301 sec, using TPK_count counting 301 times. */
1225 u32 timeout_interval = TDLS_TPK_RESEND_COUNT;
1226
1227 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1228
1229 if (rtw_tdls_is_setup_allowed(padapter) == _FALSE)
1230 goto exit;
1231
1232 if (IS_MCAST(ptxmgmt->peer))
1233 goto exit;
1234
1235 ptdls_sta = rtw_get_stainfo(pstapriv, ptxmgmt->peer);
1236 if (ptdlsinfo->sta_maximum == _TRUE) {
1237 if (ptdls_sta == NULL)
1238 goto exit;
1239 else if (!(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE))
1240 goto exit;
1241 }
1242
1243 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1244 if (pmgntframe == NULL)
1245 goto exit;
1246
1247 if (ptdls_sta == NULL) {
1248 ptdls_sta = rtw_alloc_stainfo(pstapriv, ptxmgmt->peer);
1249 if (ptdls_sta == NULL) {
1250 RTW_INFO("[%s] rtw_alloc_stainfo fail\n", __FUNCTION__);
1251 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1252 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1253 goto exit;
1254 }
1255 ptdlsinfo->sta_cnt++;
1256 }
1257
1258 ptxmgmt->action_code = TDLS_SETUP_REQUEST;
1259
1260 pattrib = &pmgntframe->attrib;
1261 pmgntframe->frame_tag = DATA_FRAMETAG;
1262 pattrib->ether_type = 0x890d;
1263
1264 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1265 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1266 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1267 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1268
1269 update_tdls_attrib(padapter, pattrib);
1270
1271 if (ptdlsinfo->sta_cnt == MAX_ALLOWED_TDLS_STA_NUM)
1272 ptdlsinfo->sta_maximum = _TRUE;
1273
1274 ptdls_sta->tdls_sta_state |= TDLS_RESPONDER_STATE;
1275
1276 if (rtw_tdls_is_driver_setup(padapter) == _TRUE) {
1277 ptdls_sta->TDLS_PeerKey_Lifetime = timeout_interval;
1278 _set_timer(&ptdls_sta->handshake_timer, TDLS_HANDSHAKE_TIME);
1279 }
1280
1281 pattrib->qsel = pattrib->priority;
1282
1283 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1284 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1285 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1286 goto exit;
1287 }
1288
1289 if (wait_ack)
1290 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
1291 else {
1292 dump_mgntframe(padapter, pmgntframe);
1293 ret = _SUCCESS;
1294 }
1295
1296 exit:
1297
1298 return ret;
1299 }
1300
_issue_tdls_teardown(_adapter * padapter,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta,u8 wait_ack)1301 int _issue_tdls_teardown(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta, u8 wait_ack)
1302 {
1303 struct xmit_frame *pmgntframe;
1304 struct pkt_attrib *pattrib;
1305 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1306 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1307 struct sta_priv *pstapriv = &padapter->stapriv;
1308 _irqL irqL;
1309 int ret = _FAIL;
1310
1311 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1312
1313 ptxmgmt->action_code = TDLS_TEARDOWN;
1314
1315 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1316 if (pmgntframe == NULL)
1317 goto exit;
1318
1319 rtw_mi_set_scan_deny(padapter, 550);
1320 rtw_mi_scan_abort(padapter, _TRUE);
1321
1322 pattrib = &pmgntframe->attrib;
1323
1324 pmgntframe->frame_tag = DATA_FRAMETAG;
1325 pattrib->ether_type = 0x890d;
1326
1327 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1328 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1329
1330 if (ptxmgmt->status_code == _RSON_TDLS_TEAR_UN_RSN_)
1331 _rtw_memcpy(pattrib->ra, ptxmgmt->peer, ETH_ALEN);
1332 else
1333 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1334
1335 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1336
1337 update_tdls_attrib(padapter, pattrib);
1338 pattrib->qsel = pattrib->priority;
1339 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1340 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1341 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1342 goto exit;
1343 }
1344
1345 if (rtw_tdls_is_driver_setup(padapter) == _TRUE)
1346 if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE)
1347 if (pattrib->encrypt)
1348 _cancel_timer_ex(&ptdls_sta->TPK_timer);
1349
1350 if (wait_ack)
1351 ret = dump_mgntframe_and_wait_ack(padapter, pmgntframe);
1352 else {
1353 dump_mgntframe(padapter, pmgntframe);
1354 ret = _SUCCESS;
1355 }
1356
1357 exit:
1358
1359 return ret;
1360 }
1361
issue_tdls_teardown(_adapter * padapter,struct tdls_txmgmt * ptxmgmt,u8 wait_ack)1362 int issue_tdls_teardown(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, u8 wait_ack)
1363 {
1364 struct sta_info *ptdls_sta = NULL;
1365 int ret = _FAIL;
1366
1367 ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), ptxmgmt->peer);
1368 if (ptdls_sta == NULL) {
1369 RTW_INFO("No tdls_sta for tearing down\n");
1370 goto exit;
1371 }
1372
1373 ret = _issue_tdls_teardown(padapter, ptxmgmt, ptdls_sta, wait_ack);
1374 if ((ptxmgmt->status_code == _RSON_TDLS_TEAR_UN_RSN_) && (ret == _FAIL)) {
1375 /* Change status code and send teardown again via AP */
1376 ptxmgmt->status_code = _RSON_TDLS_TEAR_TOOFAR_;
1377 ret = _issue_tdls_teardown(padapter, ptxmgmt, ptdls_sta, wait_ack);
1378 }
1379
1380 if (rtw_tdls_is_driver_setup(padapter)) {
1381 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
1382 rtw_tdls_cmd(padapter, ptxmgmt->peer, TDLS_TEARDOWN_STA_LOCALLY_POST);
1383 }
1384
1385 exit:
1386 return ret;
1387 }
1388
issue_tdls_dis_req(_adapter * padapter,struct tdls_txmgmt * ptxmgmt)1389 int issue_tdls_dis_req(_adapter *padapter, struct tdls_txmgmt *ptxmgmt)
1390 {
1391 struct xmit_frame *pmgntframe;
1392 struct pkt_attrib *pattrib;
1393 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1394 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1395 int ret = _FAIL;
1396
1397 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1398
1399 ptxmgmt->action_code = TDLS_DISCOVERY_REQUEST;
1400 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1401 if (pmgntframe == NULL)
1402 goto exit;
1403
1404 pattrib = &pmgntframe->attrib;
1405 pmgntframe->frame_tag = DATA_FRAMETAG;
1406 pattrib->ether_type = 0x890d;
1407
1408 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1409 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1410 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1411 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1412
1413 update_tdls_attrib(padapter, pattrib);
1414 pattrib->qsel = pattrib->priority;
1415 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1416 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1417 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1418 goto exit;
1419 }
1420 dump_mgntframe(padapter, pmgntframe);
1421 RTW_INFO("issue tdls dis req\n");
1422
1423 ret = _SUCCESS;
1424 exit:
1425
1426 return ret;
1427 }
1428
issue_tdls_setup_rsp(_adapter * padapter,struct tdls_txmgmt * ptxmgmt)1429 int issue_tdls_setup_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt)
1430 {
1431 struct xmit_frame *pmgntframe;
1432 struct pkt_attrib *pattrib;
1433 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1434 int ret = _FAIL;
1435
1436 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1437
1438 ptxmgmt->action_code = TDLS_SETUP_RESPONSE;
1439 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1440 if (pmgntframe == NULL)
1441 goto exit;
1442
1443 pattrib = &pmgntframe->attrib;
1444 pmgntframe->frame_tag = DATA_FRAMETAG;
1445 pattrib->ether_type = 0x890d;
1446
1447 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1448 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1449 _rtw_memcpy(pattrib->ra, get_bssid(&(padapter->mlmepriv)), ETH_ALEN);
1450 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1451
1452 update_tdls_attrib(padapter, pattrib);
1453 pattrib->qsel = pattrib->priority;
1454 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1455 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1456 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1457 goto exit;
1458 }
1459
1460 dump_mgntframe(padapter, pmgntframe);
1461
1462 ret = _SUCCESS;
1463 exit:
1464
1465 return ret;
1466
1467 }
1468
issue_tdls_setup_cfm(_adapter * padapter,struct tdls_txmgmt * ptxmgmt)1469 int issue_tdls_setup_cfm(_adapter *padapter, struct tdls_txmgmt *ptxmgmt)
1470 {
1471 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
1472 struct xmit_frame *pmgntframe;
1473 struct pkt_attrib *pattrib;
1474 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1475 int ret = _FAIL;
1476
1477 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1478
1479 ptxmgmt->action_code = TDLS_SETUP_CONFIRM;
1480 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1481 if (pmgntframe == NULL)
1482 goto exit;
1483
1484 pattrib = &pmgntframe->attrib;
1485 pmgntframe->frame_tag = DATA_FRAMETAG;
1486 pattrib->ether_type = 0x890d;
1487
1488 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1489 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1490 _rtw_memcpy(pattrib->ra, get_bssid(&padapter->mlmepriv), ETH_ALEN);
1491 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1492
1493 update_tdls_attrib(padapter, pattrib);
1494 pattrib->qsel = pattrib->priority;
1495 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1496 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1497 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1498 goto exit;
1499 }
1500
1501 dump_mgntframe(padapter, pmgntframe);
1502
1503 ret = _SUCCESS;
1504 exit:
1505
1506 return ret;
1507
1508 }
1509
1510 /* TDLS Discovery Response frame is a management action frame */
issue_tdls_dis_rsp(_adapter * padapter,struct tdls_txmgmt * ptxmgmt,u8 privacy)1511 int issue_tdls_dis_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, u8 privacy)
1512 {
1513 struct xmit_frame *pmgntframe;
1514 struct pkt_attrib *pattrib;
1515 unsigned char *pframe;
1516 struct rtw_ieee80211_hdr *pwlanhdr;
1517 unsigned short *fctrl;
1518 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1519 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1520 int ret = _FAIL;
1521
1522 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1523
1524 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1525 if (pmgntframe == NULL)
1526 goto exit;
1527
1528 pattrib = &pmgntframe->attrib;
1529 update_mgntframe_attrib(padapter, pattrib);
1530
1531 _rtw_memset(pmgntframe->buf_addr, 0, WLANHDR_OFFSET + TXDESC_OFFSET);
1532
1533 pframe = (u8 *)(pmgntframe->buf_addr) + TXDESC_OFFSET;
1534 pwlanhdr = (struct rtw_ieee80211_hdr *)pframe;
1535
1536 fctrl = &(pwlanhdr->frame_ctl);
1537 *(fctrl) = 0;
1538
1539 /* unicast probe request frame */
1540 _rtw_memcpy(pwlanhdr->addr1, ptxmgmt->peer, ETH_ALEN);
1541 _rtw_memcpy(pattrib->dst, pwlanhdr->addr1, ETH_ALEN);
1542 _rtw_memcpy(pwlanhdr->addr2, adapter_mac_addr(padapter), ETH_ALEN);
1543 _rtw_memcpy(pattrib->src, pwlanhdr->addr2, ETH_ALEN);
1544 _rtw_memcpy(pwlanhdr->addr3, get_bssid(&padapter->mlmepriv), ETH_ALEN);
1545 _rtw_memcpy(pattrib->ra, pwlanhdr->addr3, ETH_ALEN);
1546
1547 SetSeqNum(pwlanhdr, pmlmeext->mgnt_seq);
1548 pmlmeext->mgnt_seq++;
1549 set_frame_sub_type(pframe, WIFI_ACTION);
1550
1551 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
1552 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
1553
1554 rtw_build_tdls_dis_rsp_ies(padapter, pmgntframe, pframe, ptxmgmt, privacy);
1555
1556 pattrib->nr_frags = 1;
1557 pattrib->last_txcmdsz = pattrib->pktlen;
1558
1559 dump_mgntframe(padapter, pmgntframe);
1560 ret = _SUCCESS;
1561
1562 exit:
1563 return ret;
1564 }
1565
issue_tdls_peer_traffic_rsp(_adapter * padapter,struct sta_info * ptdls_sta,struct tdls_txmgmt * ptxmgmt)1566 int issue_tdls_peer_traffic_rsp(_adapter *padapter, struct sta_info *ptdls_sta, struct tdls_txmgmt *ptxmgmt)
1567 {
1568 struct xmit_frame *pmgntframe;
1569 struct pkt_attrib *pattrib;
1570 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1571 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1572 int ret = _FAIL;
1573
1574 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1575
1576 ptxmgmt->action_code = TDLS_PEER_TRAFFIC_RESPONSE;
1577
1578 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1579 if (pmgntframe == NULL)
1580 goto exit;
1581
1582 pattrib = &pmgntframe->attrib;
1583
1584 pmgntframe->frame_tag = DATA_FRAMETAG;
1585 pattrib->ether_type = 0x890d;
1586
1587 _rtw_memcpy(pattrib->dst, ptdls_sta->cmn.mac_addr, ETH_ALEN);
1588 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1589 _rtw_memcpy(pattrib->ra, ptdls_sta->cmn.mac_addr, ETH_ALEN);
1590 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1591
1592 update_tdls_attrib(padapter, pattrib);
1593 pattrib->qsel = pattrib->priority;
1594
1595 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1596 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1597 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1598 goto exit;
1599 }
1600
1601 dump_mgntframe(padapter, pmgntframe);
1602 ret = _SUCCESS;
1603
1604 exit:
1605
1606 return ret;
1607 }
1608
issue_tdls_peer_traffic_indication(_adapter * padapter,struct sta_info * ptdls_sta)1609 int issue_tdls_peer_traffic_indication(_adapter *padapter, struct sta_info *ptdls_sta)
1610 {
1611 struct xmit_frame *pmgntframe;
1612 struct pkt_attrib *pattrib;
1613 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1614 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1615 struct tdls_txmgmt txmgmt;
1616 int ret = _FAIL;
1617
1618 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1619
1620 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1621 txmgmt.action_code = TDLS_PEER_TRAFFIC_INDICATION;
1622
1623 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1624 if (pmgntframe == NULL)
1625 goto exit;
1626
1627 pattrib = &pmgntframe->attrib;
1628
1629 pmgntframe->frame_tag = DATA_FRAMETAG;
1630 pattrib->ether_type = 0x890d;
1631
1632 _rtw_memcpy(pattrib->dst, ptdls_sta->cmn.mac_addr, ETH_ALEN);
1633 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1634 _rtw_memcpy(pattrib->ra, get_bssid(pmlmepriv), ETH_ALEN);
1635 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1636
1637 /* PTI frame's priority should be AC_VO */
1638 pattrib->priority = 7;
1639
1640 update_tdls_attrib(padapter, pattrib);
1641 pattrib->qsel = pattrib->priority;
1642 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, &txmgmt) != _SUCCESS) {
1643 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1644 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1645 goto exit;
1646 }
1647
1648 dump_mgntframe(padapter, pmgntframe);
1649 ret = _SUCCESS;
1650
1651 exit:
1652
1653 return ret;
1654 }
1655
1656 #ifdef CONFIG_TDLS_CH_SW
issue_tdls_ch_switch_req(_adapter * padapter,struct sta_info * ptdls_sta)1657 int issue_tdls_ch_switch_req(_adapter *padapter, struct sta_info *ptdls_sta)
1658 {
1659 struct xmit_frame *pmgntframe;
1660 struct pkt_attrib *pattrib;
1661 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1662 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1663 struct tdls_txmgmt txmgmt;
1664 int ret = _FAIL;
1665
1666 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1667
1668 if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
1669 RTW_INFO("[TDLS] Ignore %s since channel switch is not allowed\n", __func__);
1670 goto exit;
1671 }
1672
1673 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1674 txmgmt.action_code = TDLS_CHANNEL_SWITCH_REQUEST;
1675
1676 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1677 if (pmgntframe == NULL)
1678 goto exit;
1679
1680 pattrib = &pmgntframe->attrib;
1681
1682 pmgntframe->frame_tag = DATA_FRAMETAG;
1683 pattrib->ether_type = 0x890d;
1684
1685 _rtw_memcpy(pattrib->dst, ptdls_sta->cmn.mac_addr, ETH_ALEN);
1686 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1687 _rtw_memcpy(pattrib->ra, ptdls_sta->cmn.mac_addr, ETH_ALEN);
1688 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1689
1690 update_tdls_attrib(padapter, pattrib);
1691 pattrib->qsel = pattrib->priority;
1692 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, &txmgmt) != _SUCCESS) {
1693 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1694 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1695 goto exit;
1696 }
1697
1698 dump_mgntframe(padapter, pmgntframe);
1699 ret = _SUCCESS;
1700 exit:
1701
1702 return ret;
1703 }
1704
issue_tdls_ch_switch_rsp(_adapter * padapter,struct tdls_txmgmt * ptxmgmt,int wait_ack)1705 int issue_tdls_ch_switch_rsp(_adapter *padapter, struct tdls_txmgmt *ptxmgmt, int wait_ack)
1706 {
1707 struct xmit_frame *pmgntframe;
1708 struct pkt_attrib *pattrib;
1709 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1710 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
1711 int ret = _FAIL;
1712
1713 RTW_INFO("[TDLS] %s\n", __FUNCTION__);
1714
1715 if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
1716 RTW_INFO("[TDLS] Ignore %s since channel switch is not allowed\n", __func__);
1717 goto exit;
1718 }
1719
1720 ptxmgmt->action_code = TDLS_CHANNEL_SWITCH_RESPONSE;
1721
1722 pmgntframe = alloc_mgtxmitframe(pxmitpriv);
1723 if (pmgntframe == NULL)
1724 goto exit;
1725
1726 pattrib = &pmgntframe->attrib;
1727
1728 pmgntframe->frame_tag = DATA_FRAMETAG;
1729 pattrib->ether_type = 0x890d;
1730
1731 _rtw_memcpy(pattrib->dst, ptxmgmt->peer, ETH_ALEN);
1732 _rtw_memcpy(pattrib->src, adapter_mac_addr(padapter), ETH_ALEN);
1733 _rtw_memcpy(pattrib->ra, ptxmgmt->peer, ETH_ALEN);
1734 _rtw_memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
1735
1736 update_tdls_attrib(padapter, pattrib);
1737 pattrib->qsel = pattrib->priority;
1738 /*
1739 _enter_critical_bh(&pxmitpriv->lock, &irqL);
1740 if(xmitframe_enqueue_for_tdls_sleeping_sta(padapter, pmgntframe)==_TRUE){
1741 _exit_critical_bh(&pxmitpriv->lock, &irqL);
1742 return _FALSE;
1743 }
1744 */
1745 if (rtw_xmit_tdls_coalesce(padapter, pmgntframe, ptxmgmt) != _SUCCESS) {
1746 rtw_free_xmitbuf(pxmitpriv, pmgntframe->pxmitbuf);
1747 rtw_free_xmitframe(pxmitpriv, pmgntframe);
1748 goto exit;
1749 }
1750
1751 if (wait_ack)
1752 ret = dump_mgntframe_and_wait_ack_timeout(padapter, pmgntframe, 10);
1753 else {
1754 dump_mgntframe(padapter, pmgntframe);
1755 ret = _SUCCESS;
1756 }
1757 exit:
1758
1759 return ret;
1760 }
1761 #endif
1762
On_TDLS_Dis_Rsp(_adapter * padapter,union recv_frame * precv_frame)1763 int On_TDLS_Dis_Rsp(_adapter *padapter, union recv_frame *precv_frame)
1764 {
1765 struct sta_info *ptdls_sta = NULL, *psta = rtw_get_stainfo(&(padapter->stapriv), get_bssid(&(padapter->mlmepriv)));
1766 struct recv_priv *precvpriv = &(padapter->recvpriv);
1767 u8 *ptr = precv_frame->u.hdr.rx_data, *psa;
1768 struct rx_pkt_attrib *pattrib = &(precv_frame->u.hdr.attrib);
1769 struct tdls_info *ptdlsinfo = &(padapter->tdlsinfo);
1770 u8 empty_addr[ETH_ALEN] = { 0x00 };
1771 int rssi = 0;
1772 struct tdls_txmgmt txmgmt;
1773 int ret = _SUCCESS;
1774
1775 if (psta)
1776 rssi = psta->cmn.rssi_stat.rssi;
1777
1778 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1779 /* WFDTDLS: for sigma test, not to setup direct link automatically */
1780 ptdlsinfo->dev_discovered = _TRUE;
1781
1782 psa = get_sa(ptr);
1783 ptdls_sta = rtw_get_stainfo(&(padapter->stapriv), psa);
1784 if (ptdls_sta != NULL)
1785 ptdls_sta->sta_stats.rx_tdls_disc_rsp_pkts++;
1786
1787 #ifdef CONFIG_TDLS_AUTOSETUP
1788 if (ptdls_sta != NULL) {
1789 /* Record the tdls sta with lowest signal strength */
1790 if (ptdlsinfo->sta_maximum == _TRUE && ptdls_sta->alive_count >= 1) {
1791 if (_rtw_memcmp(ptdlsinfo->ss_record.macaddr, empty_addr, ETH_ALEN)) {
1792 _rtw_memcpy(ptdlsinfo->ss_record.macaddr, psa, ETH_ALEN);
1793 ptdlsinfo->ss_record.RxPWDBAll = pattrib->phy_info.rx_pwdb_all;
1794 } else {
1795 if (ptdlsinfo->ss_record.RxPWDBAll < pattrib->phy_info.rx_pwdb_all) {
1796 _rtw_memcpy(ptdlsinfo->ss_record.macaddr, psa, ETH_ALEN);
1797 ptdlsinfo->ss_record.RxPWDBAll = pattrib->phy_info.rx_pwdb_all;
1798 }
1799 }
1800 }
1801 } else {
1802 if (ptdlsinfo->sta_maximum == _TRUE) {
1803 if (_rtw_memcmp(ptdlsinfo->ss_record.macaddr, empty_addr, ETH_ALEN)) {
1804 /* All traffics are busy, do not set up another direct link. */
1805 ret = _FAIL;
1806 goto exit;
1807 } else {
1808 if (pattrib->phy_info.rx_pwdb_all > ptdlsinfo->ss_record.RxPWDBAll) {
1809 _rtw_memcpy(txmgmt.peer, ptdlsinfo->ss_record.macaddr, ETH_ALEN);
1810 /* issue_tdls_teardown(padapter, ptdlsinfo->ss_record.macaddr, _FALSE); */
1811 } else {
1812 ret = _FAIL;
1813 goto exit;
1814 }
1815 }
1816 }
1817
1818
1819 if (pattrib->phy_info.rx_pwdb_all + TDLS_SIGNAL_THRESH >= rssi) {
1820 RTW_INFO("pattrib->RxPWDBAll=%d, pdmpriv->undecorated_smoothed_pwdb=%d\n", pattrib->phy_info.rx_pwdb_all, rssi);
1821 _rtw_memcpy(txmgmt.peer, psa, ETH_ALEN);
1822 issue_tdls_setup_req(padapter, &txmgmt, _FALSE);
1823 }
1824 }
1825 exit:
1826 #endif /* CONFIG_TDLS_AUTOSETUP */
1827
1828 return ret;
1829
1830 }
1831
On_TDLS_Setup_Req(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)1832 sint On_TDLS_Setup_Req(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
1833 {
1834 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
1835 u8 *psa, *pmyid;
1836 struct sta_priv *pstapriv = &padapter->stapriv;
1837 u8 *ptr = precv_frame->u.hdr.rx_data;
1838 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
1839 struct security_priv *psecuritypriv = &padapter->securitypriv;
1840 _irqL irqL;
1841 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
1842 u8 *prsnie, *ppairwise_cipher;
1843 u8 i, k;
1844 u8 ccmp_included = 0, rsnie_included = 0;
1845 u16 j, pairwise_count;
1846 u8 SNonce[32];
1847 u32 timeout_interval = TDLS_TPK_RESEND_COUNT;
1848 sint parsing_length; /* Frame body length, without icv_len */
1849 PNDIS_802_11_VARIABLE_IEs pIE;
1850 u8 FIXED_IE = 5;
1851 unsigned char supportRate[16];
1852 int supportRateNum = 0;
1853 struct tdls_txmgmt txmgmt;
1854
1855 if (rtw_tdls_is_setup_allowed(padapter) == _FALSE)
1856 goto exit;
1857
1858 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
1859 psa = get_sa(ptr);
1860
1861 if (ptdlsinfo->sta_maximum == _TRUE) {
1862 if (ptdls_sta == NULL)
1863 goto exit;
1864 else if (!(ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE))
1865 goto exit;
1866 }
1867
1868 pmyid = adapter_mac_addr(padapter);
1869 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
1870 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
1871 - prx_pkt_attrib->hdrlen
1872 - prx_pkt_attrib->iv_len
1873 - prx_pkt_attrib->icv_len
1874 - LLC_HEADER_SIZE
1875 - ETH_TYPE_LEN
1876 - PAYLOAD_TYPE_LEN;
1877
1878 if (ptdls_sta == NULL) {
1879 ptdls_sta = rtw_alloc_stainfo(pstapriv, psa);
1880 if (ptdls_sta == NULL)
1881 goto exit;
1882
1883 ptdlsinfo->sta_cnt++;
1884 }
1885 else {
1886 if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE) {
1887 /* If the direct link is already set up */
1888 /* Process as re-setup after tear down */
1889 RTW_INFO("re-setup a direct link\n");
1890 }
1891 /* Already receiving TDLS setup request */
1892 else if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE) {
1893 RTW_INFO("receive duplicated TDLS setup request frame in handshaking\n");
1894 goto exit;
1895 }
1896 /* When receiving and sending setup_req to the same link at the same time */
1897 /* STA with higher MAC_addr would be initiator */
1898 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE) {
1899 RTW_INFO("receive setup_req after sending setup_req\n");
1900 for (i = 0; i < 6; i++) {
1901 if (*(pmyid + i) == *(psa + i)) {
1902 } else if (*(pmyid + i) > *(psa + i)) {
1903 ptdls_sta->tdls_sta_state = TDLS_INITIATOR_STATE;
1904 break;
1905 } else if (*(pmyid + i) < *(psa + i))
1906 goto exit;
1907 }
1908 }
1909 }
1910
1911 if (ptdls_sta) {
1912 txmgmt.dialog_token = *(ptr + 2); /* Copy dialog token */
1913 txmgmt.status_code = _STATS_SUCCESSFUL_;
1914
1915 /* Parsing information element */
1916 for (j = FIXED_IE; j < parsing_length;) {
1917
1918 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
1919
1920 switch (pIE->ElementID) {
1921 case _SUPPORTEDRATES_IE_:
1922 if (pIE->Length <= sizeof(supportRate)) {
1923 _rtw_memcpy(supportRate, pIE->data, pIE->Length);
1924 supportRateNum = pIE->Length;
1925 }
1926 break;
1927 case WLAN_EID_COUNTRY:
1928 break;
1929 case _EXT_SUPPORTEDRATES_IE_:
1930 if ((supportRateNum + pIE->Length) <= sizeof(supportRate)) {
1931 _rtw_memcpy(supportRate + supportRateNum, pIE->data, pIE->Length);
1932 supportRateNum += pIE->Length;
1933 }
1934 break;
1935 case _SUPPORTED_CH_IE_:
1936 break;
1937 case _RSN_IE_2_:
1938 rsnie_included = 1;
1939 if (prx_pkt_attrib->encrypt) {
1940 prsnie = (u8 *)pIE;
1941 if (pIE->Length <= sizeof(ptdls_sta->TDLS_RSNIE)) {
1942 /* Check CCMP pairwise_cipher presence. */
1943 ppairwise_cipher = prsnie + 10;
1944 _rtw_memcpy(ptdls_sta->TDLS_RSNIE, pIE->data, pIE->Length);
1945 pairwise_count = *(u16 *)(ppairwise_cipher - 2);
1946 for (k = 0; k < pairwise_count; k++) {
1947 if (_rtw_memcmp(ppairwise_cipher + 4 * k, RSN_CIPHER_SUITE_CCMP, 4) == _TRUE)
1948 ccmp_included = 1;
1949 }
1950
1951 if (ccmp_included == 0)
1952 txmgmt.status_code = _STATS_INVALID_RSNIE_;
1953 }
1954 }
1955 break;
1956 case WLAN_EID_EXT_CAP:
1957 break;
1958 case _VENDOR_SPECIFIC_IE_:
1959 break;
1960 case _FTIE_:
1961 if (prx_pkt_attrib->encrypt)
1962 _rtw_memcpy(SNonce, (ptr + j + 52), 32);
1963 break;
1964 case _TIMEOUT_ITVL_IE_:
1965 if (prx_pkt_attrib->encrypt)
1966 timeout_interval = cpu_to_le32(*(u32 *)(ptr + j + 3));
1967 break;
1968 case _RIC_Descriptor_IE_:
1969 break;
1970 #ifdef CONFIG_80211N_HT
1971 case _HT_CAPABILITY_IE_:
1972 rtw_tdls_process_ht_cap(padapter, ptdls_sta, pIE->data, pIE->Length);
1973 break;
1974 #endif
1975 #ifdef CONFIG_80211AC_VHT
1976 case EID_AID:
1977 break;
1978 case EID_VHTCapability:
1979 rtw_tdls_process_vht_cap(padapter, ptdls_sta, pIE->data, pIE->Length);
1980 break;
1981 #endif
1982 case EID_BSSCoexistence:
1983 break;
1984 case _LINK_ID_IE_:
1985 if (_rtw_memcmp(get_bssid(pmlmepriv), pIE->data, 6) == _FALSE)
1986 txmgmt.status_code = _STATS_NOT_IN_SAME_BSS_;
1987 break;
1988 default:
1989 break;
1990 }
1991
1992 j += (pIE->Length + 2);
1993
1994 }
1995
1996 /* Check status code */
1997 /* If responder STA has/hasn't security on AP, but request hasn't/has RSNIE, it should reject */
1998 if (txmgmt.status_code == _STATS_SUCCESSFUL_) {
1999 if (rsnie_included && prx_pkt_attrib->encrypt == 0)
2000 txmgmt.status_code = _STATS_SEC_DISABLED_;
2001 else if (rsnie_included == 0 && prx_pkt_attrib->encrypt)
2002 txmgmt.status_code = _STATS_INVALID_PARAMETERS_;
2003
2004 #ifdef CONFIG_WFD
2005 /* WFD test plan version 0.18.2 test item 5.1.5 */
2006 /* SoUT does not use TDLS if AP uses weak security */
2007 if (padapter->wdinfo.wfd_tdls_enable && (rsnie_included && prx_pkt_attrib->encrypt != _AES_))
2008 txmgmt.status_code = _STATS_SEC_DISABLED_;
2009 #endif /* CONFIG_WFD */
2010 }
2011
2012 ptdls_sta->tdls_sta_state |= TDLS_INITIATOR_STATE;
2013 if (prx_pkt_attrib->encrypt) {
2014 _rtw_memcpy(ptdls_sta->SNonce, SNonce, 32);
2015
2016 if (timeout_interval <= 300)
2017 ptdls_sta->TDLS_PeerKey_Lifetime = TDLS_TPK_RESEND_COUNT;
2018 else
2019 ptdls_sta->TDLS_PeerKey_Lifetime = timeout_interval;
2020 }
2021
2022 /* Update station supportRate */
2023 ptdls_sta->bssratelen = supportRateNum;
2024 _rtw_memcpy(ptdls_sta->bssrateset, supportRate, supportRateNum);
2025
2026 /* -2: AP + BC/MC sta, -4: default key */
2027 if (ptdlsinfo->sta_cnt == MAX_ALLOWED_TDLS_STA_NUM)
2028 ptdlsinfo->sta_maximum = _TRUE;
2029
2030 #ifdef CONFIG_WFD
2031 rtw_tdls_process_wfd_ie(ptdlsinfo, ptr + FIXED_IE, parsing_length);
2032 #endif
2033
2034 } else
2035 goto exit;
2036
2037 _rtw_memcpy(txmgmt.peer, prx_pkt_attrib->src, ETH_ALEN);
2038
2039 if (rtw_tdls_is_driver_setup(padapter)) {
2040 issue_tdls_setup_rsp(padapter, &txmgmt);
2041
2042 if (txmgmt.status_code == _STATS_SUCCESSFUL_)
2043 _set_timer(&ptdls_sta->handshake_timer, TDLS_HANDSHAKE_TIME);
2044 else {
2045 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2046 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2047 }
2048 }
2049
2050 exit:
2051
2052 return _SUCCESS;
2053 }
2054
On_TDLS_Setup_Rsp(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2055 int On_TDLS_Setup_Rsp(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2056 {
2057 struct registry_priv *pregistrypriv = &padapter->registrypriv;
2058 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
2059 struct sta_priv *pstapriv = &padapter->stapriv;
2060 u8 *ptr = precv_frame->u.hdr.rx_data;
2061 _irqL irqL;
2062 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2063 u8 *psa;
2064 u16 status_code = 0;
2065 sint parsing_length; /* Frame body length, without icv_len */
2066 PNDIS_802_11_VARIABLE_IEs pIE;
2067 u8 FIXED_IE = 7;
2068 u8 ANonce[32];
2069 u8 *pftie = NULL, *ptimeout_ie = NULL, *plinkid_ie = NULL, *prsnie = NULL, *pftie_mic = NULL, *ppairwise_cipher = NULL;
2070 u16 pairwise_count, j, k;
2071 u8 verify_ccmp = 0;
2072 unsigned char supportRate[16];
2073 int supportRateNum = 0;
2074 struct tdls_txmgmt txmgmt;
2075 int ret = _SUCCESS;
2076 u32 timeout_interval = TDLS_TPK_RESEND_COUNT;
2077
2078 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
2079 psa = get_sa(ptr);
2080
2081 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2082 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
2083 - prx_pkt_attrib->hdrlen
2084 - prx_pkt_attrib->iv_len
2085 - prx_pkt_attrib->icv_len
2086 - LLC_HEADER_SIZE
2087 - ETH_TYPE_LEN
2088 - PAYLOAD_TYPE_LEN;
2089
2090 _rtw_memcpy(&status_code, ptr + 2, 2);
2091
2092 if (status_code != 0) {
2093 RTW_INFO("[TDLS] %s status_code = %d, free_tdls_sta\n", __FUNCTION__, status_code);
2094 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2095 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2096 ret = _FAIL;
2097 goto exit;
2098 }
2099
2100 status_code = 0;
2101
2102 /* parsing information element */
2103 for (j = FIXED_IE; j < parsing_length;) {
2104 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
2105
2106 switch (pIE->ElementID) {
2107 case _SUPPORTEDRATES_IE_:
2108 if (pIE->Length <= sizeof(supportRate)) {
2109 _rtw_memcpy(supportRate, pIE->data, pIE->Length);
2110 supportRateNum = pIE->Length;
2111 }
2112 break;
2113 case WLAN_EID_COUNTRY:
2114 break;
2115 case _EXT_SUPPORTEDRATES_IE_:
2116 if ((supportRateNum + pIE->Length) <= sizeof(supportRate)) {
2117 _rtw_memcpy(supportRate + supportRateNum, pIE->data, pIE->Length);
2118 supportRateNum += pIE->Length;
2119 }
2120 break;
2121 case _SUPPORTED_CH_IE_:
2122 break;
2123 case _RSN_IE_2_:
2124 prsnie = (u8 *)pIE;
2125 /* Check CCMP pairwise_cipher presence. */
2126 ppairwise_cipher = prsnie + 10;
2127 _rtw_memcpy(&pairwise_count, (u16 *)(ppairwise_cipher - 2), 2);
2128 for (k = 0; k < pairwise_count; k++) {
2129 if (_rtw_memcmp(ppairwise_cipher + 4 * k, RSN_CIPHER_SUITE_CCMP, 4) == _TRUE)
2130 verify_ccmp = 1;
2131 }
2132 case WLAN_EID_EXT_CAP:
2133 break;
2134 case _VENDOR_SPECIFIC_IE_:
2135 if (_rtw_memcmp((u8 *)pIE + 2, WMM_INFO_OUI, 6) == _TRUE) {
2136 /* WMM Info ID and OUI */
2137 if ((pregistrypriv->wmm_enable == _TRUE) || (padapter->mlmepriv.htpriv.ht_option == _TRUE))
2138 ptdls_sta->qos_option = _TRUE;
2139 }
2140 break;
2141 case _FTIE_:
2142 pftie = (u8 *)pIE;
2143 _rtw_memcpy(ANonce, (ptr + j + 20), 32);
2144 break;
2145 case _TIMEOUT_ITVL_IE_:
2146 ptimeout_ie = (u8 *)pIE;
2147 timeout_interval = cpu_to_le32(*(u32 *)(ptimeout_ie + 3));
2148 break;
2149 case _RIC_Descriptor_IE_:
2150 break;
2151 #ifdef CONFIG_80211N_HT
2152 case _HT_CAPABILITY_IE_:
2153 rtw_tdls_process_ht_cap(padapter, ptdls_sta, pIE->data, pIE->Length);
2154 break;
2155 #endif
2156 #ifdef CONFIG_80211AC_VHT
2157 case EID_AID:
2158 /* todo in the future if necessary */
2159 break;
2160 case EID_VHTCapability:
2161 rtw_tdls_process_vht_cap(padapter, ptdls_sta, pIE->data, pIE->Length);
2162 break;
2163 case EID_OpModeNotification:
2164 rtw_tdls_process_vht_op_mode_notify(padapter, ptdls_sta, pIE->data, pIE->Length);
2165 break;
2166 #endif
2167 case EID_BSSCoexistence:
2168 break;
2169 case _LINK_ID_IE_:
2170 plinkid_ie = (u8 *)pIE;
2171 break;
2172 default:
2173 break;
2174 }
2175
2176 j += (pIE->Length + 2);
2177
2178 }
2179
2180 ptdls_sta->bssratelen = supportRateNum;
2181 _rtw_memcpy(ptdls_sta->bssrateset, supportRate, supportRateNum);
2182 _rtw_memcpy(ptdls_sta->ANonce, ANonce, 32);
2183
2184 #ifdef CONFIG_WFD
2185 rtw_tdls_process_wfd_ie(ptdlsinfo, ptr + FIXED_IE, parsing_length);
2186 #endif
2187
2188 if (prx_pkt_attrib->encrypt) {
2189 if (verify_ccmp == 1) {
2190 txmgmt.status_code = _STATS_SUCCESSFUL_;
2191 if (rtw_tdls_is_driver_setup(padapter) == _TRUE) {
2192 wpa_tdls_generate_tpk(padapter, ptdls_sta);
2193 if (tdls_verify_mic(ptdls_sta->tpk.kck, 2, plinkid_ie, prsnie, ptimeout_ie, pftie) == _FAIL) {
2194 RTW_INFO("[TDLS] %s tdls_verify_mic fail, free_tdls_sta\n", __FUNCTION__);
2195 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2196 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2197 ret = _FAIL;
2198 goto exit;
2199 }
2200 ptdls_sta->TDLS_PeerKey_Lifetime = timeout_interval;
2201 }
2202 } else
2203 txmgmt.status_code = _STATS_INVALID_RSNIE_;
2204 } else
2205 txmgmt.status_code = _STATS_SUCCESSFUL_;
2206
2207 if (rtw_tdls_is_driver_setup(padapter) == _TRUE) {
2208 _rtw_memcpy(txmgmt.peer, prx_pkt_attrib->src, ETH_ALEN);
2209 issue_tdls_setup_cfm(padapter, &txmgmt);
2210
2211 if (txmgmt.status_code == _STATS_SUCCESSFUL_) {
2212 rtw_tdls_set_link_established(padapter, _TRUE);
2213
2214 if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE) {
2215 ptdls_sta->tdls_sta_state |= TDLS_LINKED_STATE;
2216 ptdls_sta->state |= WIFI_ASOC_STATE;
2217 _cancel_timer_ex(&ptdls_sta->handshake_timer);
2218 }
2219
2220 if (prx_pkt_attrib->encrypt)
2221 rtw_tdls_set_key(padapter, ptdls_sta);
2222
2223 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_ESTABLISHED);
2224
2225 }
2226 }
2227
2228 exit:
2229 if (rtw_tdls_is_driver_setup(padapter) == _TRUE)
2230 return ret;
2231 else
2232 return _SUCCESS;
2233
2234 }
2235
On_TDLS_Setup_Cfm(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2236 int On_TDLS_Setup_Cfm(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2237 {
2238 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
2239 struct sta_priv *pstapriv = &padapter->stapriv;
2240 u8 *ptr = precv_frame->u.hdr.rx_data;
2241 _irqL irqL;
2242 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2243 u8 *psa;
2244 u16 status_code = 0;
2245 sint parsing_length;
2246 PNDIS_802_11_VARIABLE_IEs pIE;
2247 u8 FIXED_IE = 5;
2248 u8 *pftie = NULL, *ptimeout_ie = NULL, *plinkid_ie = NULL, *prsnie = NULL, *pftie_mic = NULL, *ppairwise_cipher = NULL;
2249 u16 j, pairwise_count;
2250 int ret = _SUCCESS;
2251
2252 psa = get_sa(ptr);
2253
2254 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2255 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
2256 - prx_pkt_attrib->hdrlen
2257 - prx_pkt_attrib->iv_len
2258 - prx_pkt_attrib->icv_len
2259 - LLC_HEADER_SIZE
2260 - ETH_TYPE_LEN
2261 - PAYLOAD_TYPE_LEN;
2262
2263 _rtw_memcpy(&status_code, ptr + 2, 2);
2264
2265 if (status_code != 0) {
2266 RTW_INFO("[%s] status_code = %d\n, free_tdls_sta", __FUNCTION__, status_code);
2267 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2268 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2269 ret = _FAIL;
2270 goto exit;
2271 }
2272
2273 /* Parsing information element */
2274 for (j = FIXED_IE; j < parsing_length;) {
2275
2276 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
2277
2278 switch (pIE->ElementID) {
2279 case _RSN_IE_2_:
2280 prsnie = (u8 *)pIE;
2281 break;
2282 case _VENDOR_SPECIFIC_IE_:
2283 if (_rtw_memcmp((u8 *)pIE + 2, WMM_PARA_OUI, 6) == _TRUE) {
2284 /* WMM Parameter ID and OUI */
2285 ptdls_sta->qos_option = _TRUE;
2286 }
2287 break;
2288 case _FTIE_:
2289 pftie = (u8 *)pIE;
2290 break;
2291 case _TIMEOUT_ITVL_IE_:
2292 ptimeout_ie = (u8 *)pIE;
2293 break;
2294 #ifdef CONFIG_80211N_HT
2295 case _HT_EXTRA_INFO_IE_:
2296 break;
2297 #endif
2298 #ifdef CONFIG_80211AC_VHT
2299 case EID_VHTOperation:
2300 rtw_tdls_process_vht_operation(padapter, ptdls_sta, pIE->data, pIE->Length);
2301 break;
2302 case EID_OpModeNotification:
2303 rtw_tdls_process_vht_op_mode_notify(padapter, ptdls_sta, pIE->data, pIE->Length);
2304 break;
2305 #endif
2306 case _LINK_ID_IE_:
2307 plinkid_ie = (u8 *)pIE;
2308 break;
2309 default:
2310 break;
2311 }
2312
2313 j += (pIE->Length + 2);
2314
2315 }
2316
2317 if (prx_pkt_attrib->encrypt) {
2318 /* Verify mic in FTIE MIC field */
2319 if (rtw_tdls_is_driver_setup(padapter) &&
2320 (tdls_verify_mic(ptdls_sta->tpk.kck, 3, plinkid_ie, prsnie, ptimeout_ie, pftie) == _FAIL)) {
2321 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2322 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2323 ret = _FAIL;
2324 goto exit;
2325 }
2326 }
2327
2328 if (rtw_tdls_is_driver_setup(padapter)) {
2329 rtw_tdls_set_link_established(padapter, _TRUE);
2330
2331 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE) {
2332 ptdls_sta->tdls_sta_state |= TDLS_LINKED_STATE;
2333 ptdls_sta->state |= WIFI_ASOC_STATE;
2334 _cancel_timer_ex(&ptdls_sta->handshake_timer);
2335 }
2336
2337 if (prx_pkt_attrib->encrypt) {
2338 rtw_tdls_set_key(padapter, ptdls_sta);
2339
2340 /* Start TPK timer */
2341 ptdls_sta->TPK_count = 0;
2342 _set_timer(&ptdls_sta->TPK_timer, ONE_SEC);
2343 }
2344
2345 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_ESTABLISHED);
2346 }
2347
2348 exit:
2349 return ret;
2350
2351 }
2352
On_TDLS_Dis_Req(_adapter * padapter,union recv_frame * precv_frame)2353 int On_TDLS_Dis_Req(_adapter *padapter, union recv_frame *precv_frame)
2354 {
2355 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2356 struct sta_priv *pstapriv = &padapter->stapriv;
2357 struct sta_info *psta_ap;
2358 u8 *ptr = precv_frame->u.hdr.rx_data;
2359 sint parsing_length; /* Frame body length, without icv_len */
2360 PNDIS_802_11_VARIABLE_IEs pIE;
2361 u8 FIXED_IE = 3, *dst;
2362 u16 j;
2363 struct tdls_txmgmt txmgmt;
2364 int ret = _SUCCESS;
2365
2366 if (rtw_tdls_is_driver_setup(padapter) == _FALSE)
2367 goto exit;
2368
2369 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
2370 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2371 txmgmt.dialog_token = *(ptr + 2);
2372 _rtw_memcpy(&txmgmt.peer, precv_frame->u.hdr.attrib.src, ETH_ALEN);
2373 txmgmt.action_code = TDLS_DISCOVERY_RESPONSE;
2374 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
2375 - prx_pkt_attrib->hdrlen
2376 - prx_pkt_attrib->iv_len
2377 - prx_pkt_attrib->icv_len
2378 - LLC_HEADER_SIZE
2379 - ETH_TYPE_LEN
2380 - PAYLOAD_TYPE_LEN;
2381
2382 /* Parsing information element */
2383 for (j = FIXED_IE; j < parsing_length;) {
2384
2385 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
2386
2387 switch (pIE->ElementID) {
2388 case _LINK_ID_IE_:
2389 psta_ap = rtw_get_stainfo(pstapriv, pIE->data);
2390 if (psta_ap == NULL)
2391 goto exit;
2392 dst = pIE->data + 12;
2393 if (MacAddr_isBcst(dst) == _FALSE && (_rtw_memcmp(adapter_mac_addr(padapter), dst, ETH_ALEN) == _FALSE))
2394 goto exit;
2395 break;
2396 default:
2397 break;
2398 }
2399
2400 j += (pIE->Length + 2);
2401
2402 }
2403
2404 issue_tdls_dis_rsp(padapter, &txmgmt, prx_pkt_attrib->privacy);
2405
2406 exit:
2407 return ret;
2408
2409 }
2410
On_TDLS_Teardown(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2411 int On_TDLS_Teardown(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2412 {
2413 u8 *ptr = precv_frame->u.hdr.rx_data;
2414 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2415 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2416 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2417 struct sta_priv *pstapriv = &padapter->stapriv;
2418 _irqL irqL;
2419 u8 reason;
2420
2421 reason = *(ptr + prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN + 2);
2422 RTW_INFO("[TDLS] %s Reason code(%d)\n", __FUNCTION__, reason);
2423
2424 if (rtw_tdls_is_driver_setup(padapter)) {
2425 rtw_tdls_teardown_pre_hdl(padapter, ptdls_sta);
2426 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY_POST);
2427 }
2428
2429 return _SUCCESS;
2430
2431 }
2432
2433 #if 0
2434 u8 TDLS_check_ch_state(uint state)
2435 {
2436 if (state & TDLS_CH_SWITCH_ON_STATE &&
2437 state & TDLS_PEER_AT_OFF_STATE) {
2438 if (state & TDLS_PEER_SLEEP_STATE)
2439 return 2; /* U-APSD + ch. switch */
2440 else
2441 return 1; /* ch. switch */
2442 } else
2443 return 0;
2444 }
2445 #endif
2446
On_TDLS_Peer_Traffic_Indication(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2447 int On_TDLS_Peer_Traffic_Indication(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2448 {
2449 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
2450 u8 *ptr = precv_frame->u.hdr.rx_data;
2451 struct tdls_txmgmt txmgmt;
2452
2453 ptr += pattrib->hdrlen + pattrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2454 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
2455
2456 txmgmt.dialog_token = *(ptr + 2);
2457 issue_tdls_peer_traffic_rsp(padapter, ptdls_sta, &txmgmt);
2458 /* issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 0, 0, 0); */
2459
2460 return _SUCCESS;
2461 }
2462
2463 /* We process buffered data for 1. U-APSD, 2. ch. switch, 3. U-APSD + ch. switch here */
On_TDLS_Peer_Traffic_Rsp(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2464 int On_TDLS_Peer_Traffic_Rsp(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2465 {
2466 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
2467 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2468 struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib;
2469 struct sta_priv *pstapriv = &padapter->stapriv;
2470 u8 wmmps_ac = 0;
2471 /* u8 state=TDLS_check_ch_state(ptdls_sta->tdls_sta_state); */
2472 int i;
2473
2474 ptdls_sta->sta_stats.rx_data_pkts++;
2475
2476 ptdls_sta->tdls_sta_state &= ~(TDLS_WAIT_PTR_STATE);
2477
2478 /* Check 4-AC queue bit */
2479 if (ptdls_sta->uapsd_vo || ptdls_sta->uapsd_vi || ptdls_sta->uapsd_be || ptdls_sta->uapsd_bk)
2480 wmmps_ac = 1;
2481
2482 /* If it's a direct link and have buffered frame */
2483 if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE) {
2484 if (wmmps_ac) {
2485 _irqL irqL;
2486 _list *xmitframe_plist, *xmitframe_phead;
2487 struct xmit_frame *pxmitframe = NULL;
2488
2489 _enter_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
2490
2491 xmitframe_phead = get_list_head(&ptdls_sta->sleep_q);
2492 xmitframe_plist = get_next(xmitframe_phead);
2493
2494 /* transmit buffered frames */
2495 while (rtw_end_of_queue_search(xmitframe_phead, xmitframe_plist) == _FALSE) {
2496 pxmitframe = LIST_CONTAINOR(xmitframe_plist, struct xmit_frame, list);
2497 xmitframe_plist = get_next(xmitframe_plist);
2498 rtw_list_delete(&pxmitframe->list);
2499
2500 ptdls_sta->sleepq_len--;
2501 ptdls_sta->sleepq_ac_len--;
2502 if (ptdls_sta->sleepq_len > 0) {
2503 pxmitframe->attrib.mdata = 1;
2504 pxmitframe->attrib.eosp = 0;
2505 } else {
2506 pxmitframe->attrib.mdata = 0;
2507 pxmitframe->attrib.eosp = 1;
2508 }
2509 pxmitframe->attrib.triggered = 1;
2510
2511 rtw_hal_xmitframe_enqueue(padapter, pxmitframe);
2512 }
2513
2514 if (ptdls_sta->sleepq_len == 0)
2515 RTW_INFO("no buffered packets for tdls to xmit\n");
2516 else {
2517 RTW_INFO("error!psta->sleepq_len=%d\n", ptdls_sta->sleepq_len);
2518 ptdls_sta->sleepq_len = 0;
2519 }
2520
2521 _exit_critical_bh(&ptdls_sta->sleep_q.lock, &irqL);
2522
2523 }
2524
2525 }
2526
2527 return _SUCCESS;
2528 }
2529
2530 #ifdef CONFIG_TDLS_CH_SW
On_TDLS_Ch_Switch_Req(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2531 sint On_TDLS_Ch_Switch_Req(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2532 {
2533 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
2534 struct sta_priv *pstapriv = &padapter->stapriv;
2535 u8 *ptr = precv_frame->u.hdr.rx_data;
2536 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2537 sint parsing_length;
2538 PNDIS_802_11_VARIABLE_IEs pIE;
2539 u8 FIXED_IE = 4;
2540 u16 j;
2541 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2542 u8 zaddr[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
2543 u16 switch_time = TDLS_CH_SWITCH_TIME * 1000, switch_timeout = TDLS_CH_SWITCH_TIMEOUT * 1000;
2544 u8 take_care_iqk;
2545
2546 if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
2547 RTW_INFO("[TDLS] Ignore %s since channel switch is not allowed\n", __func__);
2548 return _FAIL;
2549 }
2550
2551 ptdls_sta->ch_switch_time = switch_time;
2552 ptdls_sta->ch_switch_timeout = switch_timeout;
2553
2554 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2555 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
2556 - prx_pkt_attrib->hdrlen
2557 - prx_pkt_attrib->iv_len
2558 - prx_pkt_attrib->icv_len
2559 - LLC_HEADER_SIZE
2560 - ETH_TYPE_LEN
2561 - PAYLOAD_TYPE_LEN;
2562
2563 pchsw_info->off_ch_num = *(ptr + 2);
2564
2565 if ((*(ptr + 2) == 2) && (hal_is_band_support(padapter, BAND_ON_5G)))
2566 pchsw_info->off_ch_num = 44;
2567
2568 if (pchsw_info->off_ch_num != pmlmeext->cur_channel)
2569 pchsw_info->delay_switch_back = _FALSE;
2570
2571 /* Parsing information element */
2572 for (j = FIXED_IE; j < parsing_length;) {
2573 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
2574
2575 switch (pIE->ElementID) {
2576 case EID_SecondaryChnlOffset:
2577 switch (*(pIE->data)) {
2578 case EXTCHNL_OFFSET_UPPER:
2579 pchsw_info->ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
2580 break;
2581
2582 case EXTCHNL_OFFSET_LOWER:
2583 pchsw_info->ch_offset = HAL_PRIME_CHNL_OFFSET_UPPER;
2584 break;
2585
2586 default:
2587 pchsw_info->ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
2588 break;
2589 }
2590 break;
2591 case _LINK_ID_IE_:
2592 break;
2593 case _CH_SWITCH_TIMING_:
2594 ptdls_sta->ch_switch_time = (RTW_GET_LE16(pIE->data) >= TDLS_CH_SWITCH_TIME * 1000) ?
2595 RTW_GET_LE16(pIE->data) : TDLS_CH_SWITCH_TIME * 1000;
2596 ptdls_sta->ch_switch_timeout = (RTW_GET_LE16(pIE->data + 2) >= TDLS_CH_SWITCH_TIMEOUT * 1000) ?
2597 RTW_GET_LE16(pIE->data + 2) : TDLS_CH_SWITCH_TIMEOUT * 1000;
2598 RTW_INFO("[TDLS] %s ch_switch_time:%d, ch_switch_timeout:%d\n"
2599 , __FUNCTION__, RTW_GET_LE16(pIE->data), RTW_GET_LE16(pIE->data + 2));
2600 default:
2601 break;
2602 }
2603
2604 j += (pIE->Length + 2);
2605 }
2606
2607 #ifndef CONFIG_TDLS_CH_SW_V2
2608 rtw_hal_get_hwreg(padapter, HW_VAR_CH_SW_NEED_TO_TAKE_CARE_IQK_INFO, &take_care_iqk);
2609 if (take_care_iqk == _TRUE) {
2610 u8 central_chnl;
2611 u8 bw_mode;
2612
2613 bw_mode = (pchsw_info->ch_offset) ? CHANNEL_WIDTH_40 : CHANNEL_WIDTH_20;
2614 central_chnl = rtw_get_center_ch(pchsw_info->off_ch_num, bw_mode, pchsw_info->ch_offset);
2615 if (rtw_hal_ch_sw_iqk_info_search(padapter, central_chnl, bw_mode) < 0) {
2616 if (!(pchsw_info->ch_sw_state & TDLS_CH_SWITCH_PREPARE_STATE))
2617 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_PREPARE);
2618
2619 return _FAIL;
2620 }
2621 }
2622 #endif
2623
2624 /* cancel ch sw monitor timer for responder */
2625 if (!(pchsw_info->ch_sw_state & TDLS_CH_SW_INITIATOR_STATE))
2626 _cancel_timer_ex(&ptdls_sta->ch_sw_monitor_timer);
2627
2628 if (_rtw_memcmp(pchsw_info->addr, zaddr, ETH_ALEN) == _TRUE)
2629 _rtw_memcpy(pchsw_info->addr, ptdls_sta->cmn.mac_addr, ETH_ALEN);
2630
2631 if (ATOMIC_READ(&pchsw_info->chsw_on) == _FALSE)
2632 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_START);
2633
2634 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_RESP);
2635
2636 return _SUCCESS;
2637 }
2638
On_TDLS_Ch_Switch_Rsp(_adapter * padapter,union recv_frame * precv_frame,struct sta_info * ptdls_sta)2639 sint On_TDLS_Ch_Switch_Rsp(_adapter *padapter, union recv_frame *precv_frame, struct sta_info *ptdls_sta)
2640 {
2641 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
2642 struct sta_priv *pstapriv = &padapter->stapriv;
2643 u8 *ptr = precv_frame->u.hdr.rx_data;
2644 struct rx_pkt_attrib *prx_pkt_attrib = &precv_frame->u.hdr.attrib;
2645 sint parsing_length;
2646 PNDIS_802_11_VARIABLE_IEs pIE;
2647 u8 FIXED_IE = 4;
2648 u16 status_code, j, switch_time, switch_timeout;
2649 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2650 int ret = _SUCCESS;
2651
2652 if (rtw_tdls_is_chsw_allowed(padapter) == _FALSE) {
2653 RTW_INFO("[TDLS] Ignore %s since channel switch is not allowed\n", __func__);
2654 return _SUCCESS;
2655 }
2656
2657 /* If we receive Unsolicited TDLS Channel Switch Response when channel switch is running, */
2658 /* we will go back to base channel and terminate this channel switch procedure */
2659 if (ATOMIC_READ(&pchsw_info->chsw_on) == _TRUE) {
2660 if (pmlmeext->cur_channel != rtw_get_oper_ch(padapter)) {
2661 RTW_INFO("[TDLS] Rx unsolicited channel switch response\n");
2662 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_TO_BASE_CHNL);
2663 goto exit;
2664 }
2665 }
2666
2667 ptr += prx_pkt_attrib->hdrlen + prx_pkt_attrib->iv_len + LLC_HEADER_SIZE + ETH_TYPE_LEN + PAYLOAD_TYPE_LEN;
2668 parsing_length = ((union recv_frame *)precv_frame)->u.hdr.len
2669 - prx_pkt_attrib->hdrlen
2670 - prx_pkt_attrib->iv_len
2671 - prx_pkt_attrib->icv_len
2672 - LLC_HEADER_SIZE
2673 - ETH_TYPE_LEN
2674 - PAYLOAD_TYPE_LEN;
2675
2676 _rtw_memcpy(&status_code, ptr + 2, 2);
2677
2678 if (status_code != 0) {
2679 RTW_INFO("[TDLS] %s status_code:%d\n", __func__, status_code);
2680 pchsw_info->ch_sw_state &= ~(TDLS_CH_SW_INITIATOR_STATE);
2681 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END);
2682 ret = _FAIL;
2683 goto exit;
2684 }
2685
2686 /* Parsing information element */
2687 for (j = FIXED_IE; j < parsing_length;) {
2688 pIE = (PNDIS_802_11_VARIABLE_IEs)(ptr + j);
2689
2690 switch (pIE->ElementID) {
2691 case _LINK_ID_IE_:
2692 break;
2693 case _CH_SWITCH_TIMING_:
2694 _rtw_memcpy(&switch_time, pIE->data, 2);
2695 if (switch_time > ptdls_sta->ch_switch_time)
2696 _rtw_memcpy(&ptdls_sta->ch_switch_time, &switch_time, 2);
2697
2698 _rtw_memcpy(&switch_timeout, pIE->data + 2, 2);
2699 if (switch_timeout > ptdls_sta->ch_switch_timeout)
2700 _rtw_memcpy(&ptdls_sta->ch_switch_timeout, &switch_timeout, 2);
2701 break;
2702 default:
2703 break;
2704 }
2705
2706 j += (pIE->Length + 2);
2707 }
2708
2709 if ((pmlmeext->cur_channel == rtw_get_oper_ch(padapter)) &&
2710 (pchsw_info->ch_sw_state & TDLS_WAIT_CH_RSP_STATE)) {
2711 if (ATOMIC_READ(&pchsw_info->chsw_on) == _TRUE)
2712 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_TO_OFF_CHNL);
2713 }
2714
2715 exit:
2716 return ret;
2717 }
2718 #endif /* CONFIG_TDLS_CH_SW */
2719
2720 #ifdef CONFIG_WFD
wfd_ie_tdls(_adapter * padapter,u8 * pframe,u32 * pktlen)2721 void wfd_ie_tdls(_adapter *padapter, u8 *pframe, u32 *pktlen)
2722 {
2723 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2724 struct wifi_display_info *pwfd_info = padapter->tdlsinfo.wfd_info;
2725 u8 wfdie[MAX_WFD_IE_LEN] = { 0x00 };
2726 u32 wfdielen = 0;
2727 u16 v16 = 0;
2728
2729 if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST))
2730 return;
2731
2732 /* WFD OUI */
2733 wfdielen = 0;
2734 wfdie[wfdielen++] = 0x50;
2735 wfdie[wfdielen++] = 0x6F;
2736 wfdie[wfdielen++] = 0x9A;
2737 wfdie[wfdielen++] = 0x0A; /* WFA WFD v1.0 */
2738
2739 /*
2740 * Commented by Albert 20110825
2741 * According to the WFD Specification, the negotiation request frame should contain 3 WFD attributes
2742 * 1. WFD Device Information
2743 * 2. Associated BSSID ( Optional )
2744 * 3. Local IP Adress ( Optional )
2745 */
2746
2747 /* WFD Device Information ATTR */
2748 /* Type: */
2749 wfdie[wfdielen++] = WFD_ATTR_DEVICE_INFO;
2750
2751 /* Length: */
2752 /* Note: In the WFD specification, the size of length field is 2. */
2753 RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
2754 wfdielen += 2;
2755
2756 /* Value1: */
2757 /* WFD device information */
2758 /* available for WFD session + Preferred TDLS + WSD ( WFD Service Discovery ) */
2759 v16 = pwfd_info->wfd_device_type | WFD_DEVINFO_SESSION_AVAIL
2760 | WFD_DEVINFO_PC_TDLS | WFD_DEVINFO_WSD;
2761 RTW_PUT_BE16(wfdie + wfdielen, v16);
2762 wfdielen += 2;
2763
2764 /* Value2: */
2765 /* Session Management Control Port */
2766 /* Default TCP port for RTSP messages is 554 */
2767 RTW_PUT_BE16(wfdie + wfdielen, pwfd_info->tdls_rtsp_ctrlport);
2768 wfdielen += 2;
2769
2770 /* Value3: */
2771 /* WFD Device Maximum Throughput */
2772 /* 300Mbps is the maximum throughput */
2773 RTW_PUT_BE16(wfdie + wfdielen, 300);
2774 wfdielen += 2;
2775
2776 /* Associated BSSID ATTR */
2777 /* Type: */
2778 wfdie[wfdielen++] = WFD_ATTR_ASSOC_BSSID;
2779
2780 /* Length: */
2781 /* Note: In the WFD specification, the size of length field is 2. */
2782 RTW_PUT_BE16(wfdie + wfdielen, 0x0006);
2783 wfdielen += 2;
2784
2785 /* Value: */
2786 /* Associated BSSID */
2787 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
2788 _rtw_memcpy(wfdie + wfdielen, &pmlmepriv->assoc_bssid[0], ETH_ALEN);
2789 else
2790 _rtw_memset(wfdie + wfdielen, 0x00, ETH_ALEN);
2791
2792 /* Local IP Address ATTR */
2793 wfdie[wfdielen++] = WFD_ATTR_LOCAL_IP_ADDR;
2794
2795 /* Length: */
2796 /* Note: In the WFD specification, the size of length field is 2. */
2797 RTW_PUT_BE16(wfdie + wfdielen, 0x0005);
2798 wfdielen += 2;
2799
2800 /* Version: */
2801 /* 0x01: Version1;IPv4 */
2802 wfdie[wfdielen++] = 0x01;
2803
2804 /* IPv4 Address */
2805 _rtw_memcpy(wfdie + wfdielen, pwfd_info->ip_address, 4);
2806 wfdielen += 4;
2807
2808 pframe = rtw_set_ie(pframe, _VENDOR_SPECIFIC_IE_, wfdielen, (unsigned char *) wfdie, pktlen);
2809
2810 }
2811 #endif /* CONFIG_WFD */
2812
rtw_build_tdls_setup_req_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)2813 void rtw_build_tdls_setup_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
2814 {
2815 struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
2816 struct registry_priv *pregistrypriv = &padapter->registrypriv;
2817 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2818 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2819 int i = 0 ;
2820 u32 time;
2821 u8 *pframe_head;
2822
2823 /* SNonce */
2824 if (pattrib->encrypt) {
2825 for (i = 0; i < 8; i++) {
2826 time = rtw_get_current_time();
2827 _rtw_memcpy(&ptdls_sta->SNonce[4 * i], (u8 *)&time, 4);
2828 }
2829 }
2830
2831 pframe_head = pframe; /* For rtw_tdls_set_ht_cap() */
2832
2833 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
2834 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
2835 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
2836 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
2837
2838 pframe = rtw_tdls_set_capability(padapter, pframe, pattrib);
2839 pframe = rtw_tdls_set_supported_rate(padapter, pframe, pattrib);
2840 pframe = rtw_tdls_set_sup_ch(padapter, pframe, pattrib);
2841 pframe = rtw_tdls_set_sup_reg_class(pframe, pattrib);
2842
2843 if (pattrib->encrypt)
2844 pframe = rtw_tdls_set_rsnie(ptxmgmt, pframe, pattrib, _TRUE, ptdls_sta);
2845
2846 pframe = rtw_tdls_set_ext_cap(pframe, pattrib);
2847
2848 if (pattrib->encrypt) {
2849 pframe = rtw_tdls_set_ftie(ptxmgmt
2850 , pframe
2851 , pattrib
2852 , NULL
2853 , ptdls_sta->SNonce);
2854
2855 pframe = rtw_tdls_set_timeout_interval(ptxmgmt, pframe, pattrib, _TRUE, ptdls_sta);
2856 }
2857
2858 #ifdef CONFIG_80211N_HT
2859 /* Sup_reg_classes(optional) */
2860 if (pregistrypriv->ht_enable == _TRUE)
2861 pframe = rtw_tdls_set_ht_cap(padapter, pframe_head, pattrib);
2862 #endif
2863
2864 pframe = rtw_tdls_set_bss_coexist(padapter, pframe, pattrib);
2865
2866 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
2867
2868 if ((pregistrypriv->wmm_enable == _TRUE) || (padapter->mlmepriv.htpriv.ht_option == _TRUE))
2869 pframe = rtw_tdls_set_qos_cap(pframe, pattrib);
2870
2871 #ifdef CONFIG_80211AC_VHT
2872 if ((padapter->mlmepriv.htpriv.ht_option == _TRUE) && (pmlmeext->cur_channel > 14)
2873 && REGSTY_IS_11AC_ENABLE(pregistrypriv)
2874 && is_supported_vht(pregistrypriv->wireless_mode)
2875 && RFCTL_REG_EN_11AC(rfctl)
2876 ) {
2877 pframe = rtw_tdls_set_aid(padapter, pframe, pattrib);
2878 pframe = rtw_tdls_set_vht_cap(padapter, pframe, pattrib);
2879 }
2880 #endif
2881
2882 #ifdef CONFIG_WFD
2883 if (padapter->wdinfo.wfd_tdls_enable == 1)
2884 wfd_ie_tdls(padapter, pframe, &(pattrib->pktlen));
2885 #endif
2886
2887 }
2888
rtw_build_tdls_setup_rsp_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)2889 void rtw_build_tdls_setup_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
2890 {
2891 struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
2892 struct registry_priv *pregistrypriv = &padapter->registrypriv;
2893 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2894 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2895 u8 k; /* for random ANonce */
2896 u8 *pftie = NULL, *ptimeout_ie = NULL, *plinkid_ie = NULL, *prsnie = NULL, *pftie_mic = NULL;
2897 u32 time;
2898 u8 *pframe_head;
2899
2900 if (pattrib->encrypt) {
2901 for (k = 0; k < 8; k++) {
2902 time = rtw_get_current_time();
2903 _rtw_memcpy(&ptdls_sta->ANonce[4 * k], (u8 *)&time, 4);
2904 }
2905 }
2906
2907 pframe_head = pframe;
2908
2909 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
2910 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
2911 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
2912 pframe = rtw_tdls_set_status_code(pframe, pattrib, ptxmgmt);
2913
2914 if (ptxmgmt->status_code != 0) {
2915 RTW_INFO("[%s] status_code:%04x\n", __FUNCTION__, ptxmgmt->status_code);
2916 return;
2917 }
2918
2919 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
2920 pframe = rtw_tdls_set_capability(padapter, pframe, pattrib);
2921 pframe = rtw_tdls_set_supported_rate(padapter, pframe, pattrib);
2922 pframe = rtw_tdls_set_sup_ch(padapter, pframe, pattrib);
2923 pframe = rtw_tdls_set_sup_reg_class(pframe, pattrib);
2924
2925 if (pattrib->encrypt) {
2926 prsnie = pframe;
2927 pframe = rtw_tdls_set_rsnie(ptxmgmt, pframe, pattrib, _FALSE, ptdls_sta);
2928 }
2929
2930 pframe = rtw_tdls_set_ext_cap(pframe, pattrib);
2931
2932 if (pattrib->encrypt) {
2933 if (rtw_tdls_is_driver_setup(padapter) == _TRUE)
2934 wpa_tdls_generate_tpk(padapter, ptdls_sta);
2935
2936 pftie = pframe;
2937 pftie_mic = pframe + 4;
2938 pframe = rtw_tdls_set_ftie(ptxmgmt
2939 , pframe
2940 , pattrib
2941 , ptdls_sta->ANonce
2942 , ptdls_sta->SNonce);
2943
2944 ptimeout_ie = pframe;
2945 pframe = rtw_tdls_set_timeout_interval(ptxmgmt, pframe, pattrib, _FALSE, ptdls_sta);
2946 }
2947
2948 #ifdef CONFIG_80211N_HT
2949 /* Sup_reg_classes(optional) */
2950 if (pregistrypriv->ht_enable == _TRUE)
2951 pframe = rtw_tdls_set_ht_cap(padapter, pframe_head, pattrib);
2952 #endif
2953
2954 pframe = rtw_tdls_set_bss_coexist(padapter, pframe, pattrib);
2955
2956 plinkid_ie = pframe;
2957 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
2958
2959 /* Fill FTIE mic */
2960 if (pattrib->encrypt && rtw_tdls_is_driver_setup(padapter) == _TRUE)
2961 wpa_tdls_ftie_mic(ptdls_sta->tpk.kck, 2, plinkid_ie, prsnie, ptimeout_ie, pftie, pftie_mic);
2962
2963 if ((pregistrypriv->wmm_enable == _TRUE) || (padapter->mlmepriv.htpriv.ht_option == _TRUE))
2964 pframe = rtw_tdls_set_qos_cap(pframe, pattrib);
2965
2966 #ifdef CONFIG_80211AC_VHT
2967 if ((padapter->mlmepriv.htpriv.ht_option == _TRUE) && (pmlmeext->cur_channel > 14)
2968 && REGSTY_IS_11AC_ENABLE(pregistrypriv)
2969 && is_supported_vht(pregistrypriv->wireless_mode)
2970 && RFCTL_REG_EN_11AC(rfctl)
2971 ) {
2972 pframe = rtw_tdls_set_aid(padapter, pframe, pattrib);
2973 pframe = rtw_tdls_set_vht_cap(padapter, pframe, pattrib);
2974 pframe = rtw_tdls_set_vht_op_mode_notify(padapter, pframe, pattrib, pmlmeext->cur_bwmode);
2975 }
2976 #endif
2977
2978 #ifdef CONFIG_WFD
2979 if (padapter->wdinfo.wfd_tdls_enable)
2980 wfd_ie_tdls(padapter, pframe, &(pattrib->pktlen));
2981 #endif
2982
2983 }
2984
rtw_build_tdls_setup_cfm_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)2985 void rtw_build_tdls_setup_cfm_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
2986 {
2987 struct rf_ctl_t *rfctl = adapter_to_rfctl(padapter);
2988 struct registry_priv *pregistrypriv = &padapter->registrypriv;
2989 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
2990 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2991 struct pkt_attrib *pattrib = &pxmitframe->attrib;
2992
2993 unsigned int ie_len;
2994 unsigned char *p;
2995 u8 wmm_param_ele[24] = {0};
2996 u8 *pftie = NULL, *ptimeout_ie = NULL, *plinkid_ie = NULL, *prsnie = NULL, *pftie_mic = NULL;
2997
2998 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
2999 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3000 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3001 pframe = rtw_tdls_set_status_code(pframe, pattrib, ptxmgmt);
3002 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
3003
3004 if (ptxmgmt->status_code != 0)
3005 return;
3006
3007 if (pattrib->encrypt) {
3008 prsnie = pframe;
3009 pframe = rtw_tdls_set_rsnie(ptxmgmt, pframe, pattrib, _TRUE, ptdls_sta);
3010 }
3011
3012 if (pattrib->encrypt) {
3013 pftie = pframe;
3014 pftie_mic = pframe + 4;
3015 pframe = rtw_tdls_set_ftie(ptxmgmt
3016 , pframe
3017 , pattrib
3018 , ptdls_sta->ANonce
3019 , ptdls_sta->SNonce);
3020
3021 ptimeout_ie = pframe;
3022 pframe = rtw_tdls_set_timeout_interval(ptxmgmt, pframe, pattrib, _TRUE, ptdls_sta);
3023
3024 if (rtw_tdls_is_driver_setup(padapter) == _TRUE) {
3025 /* Start TPK timer */
3026 ptdls_sta->TPK_count = 0;
3027 _set_timer(&ptdls_sta->TPK_timer, ONE_SEC);
3028 }
3029 }
3030
3031 /* HT operation; todo */
3032
3033 plinkid_ie = pframe;
3034 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3035
3036 if (pattrib->encrypt && (rtw_tdls_is_driver_setup(padapter) == _TRUE))
3037 wpa_tdls_ftie_mic(ptdls_sta->tpk.kck, 3, plinkid_ie, prsnie, ptimeout_ie, pftie, pftie_mic);
3038
3039 if (ptdls_sta->qos_option == _TRUE)
3040 pframe = rtw_tdls_set_wmm_params(padapter, pframe, pattrib);
3041
3042 #ifdef CONFIG_80211AC_VHT
3043 if ((padapter->mlmepriv.htpriv.ht_option == _TRUE)
3044 && (ptdls_sta->vhtpriv.vht_option == _TRUE) && (pmlmeext->cur_channel > 14)
3045 && REGSTY_IS_11AC_ENABLE(pregistrypriv)
3046 && is_supported_vht(pregistrypriv->wireless_mode)
3047 && RFCTL_REG_EN_11AC(rfctl)
3048 ) {
3049 pframe = rtw_tdls_set_vht_operation(padapter, pframe, pattrib, pmlmeext->cur_channel);
3050 pframe = rtw_tdls_set_vht_op_mode_notify(padapter, pframe, pattrib, pmlmeext->cur_bwmode);
3051 }
3052 #endif
3053 }
3054
rtw_build_tdls_teardown_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)3055 void rtw_build_tdls_teardown_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
3056 {
3057 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3058 u8 *pftie = NULL, *pftie_mic = NULL, *plinkid_ie = NULL;
3059
3060 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3061 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3062 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3063 pframe = rtw_tdls_set_status_code(pframe, pattrib, ptxmgmt);
3064
3065 if (pattrib->encrypt) {
3066 pftie = pframe;
3067 pftie_mic = pframe + 4;
3068 pframe = rtw_tdls_set_ftie(ptxmgmt
3069 , pframe
3070 , pattrib
3071 , ptdls_sta->ANonce
3072 , ptdls_sta->SNonce);
3073 }
3074
3075 plinkid_ie = pframe;
3076 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE)
3077 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3078 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE)
3079 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3080
3081 if (pattrib->encrypt && (rtw_tdls_is_driver_setup(padapter) == _TRUE))
3082 wpa_tdls_teardown_ftie_mic(ptdls_sta->tpk.kck, plinkid_ie, ptxmgmt->status_code, 1, 4, pftie, pftie_mic);
3083 }
3084
rtw_build_tdls_dis_req_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt)3085 void rtw_build_tdls_dis_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt)
3086 {
3087 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3088
3089 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3090 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3091 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3092 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
3093 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3094
3095 }
3096
rtw_build_tdls_dis_rsp_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,u8 privacy)3097 void rtw_build_tdls_dis_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, u8 privacy)
3098 {
3099 struct registry_priv *pregistrypriv = &padapter->registrypriv;
3100 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3101 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3102 u8 *pframe_head, pktlen_index;
3103
3104 pktlen_index = pattrib->pktlen;
3105 pframe_head = pframe;
3106
3107 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_PUBLIC);
3108 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3109 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
3110 pframe = rtw_tdls_set_capability(padapter, pframe, pattrib);
3111
3112 pframe = rtw_tdls_set_supported_rate(padapter, pframe, pattrib);
3113
3114 pframe = rtw_tdls_set_sup_ch(padapter, pframe, pattrib);
3115
3116 if (privacy)
3117 pframe = rtw_tdls_set_rsnie(ptxmgmt, pframe, pattrib, _TRUE, NULL);
3118
3119 pframe = rtw_tdls_set_ext_cap(pframe, pattrib);
3120
3121 if (privacy) {
3122 pframe = rtw_tdls_set_ftie(ptxmgmt, pframe, pattrib, NULL, NULL);
3123 pframe = rtw_tdls_set_timeout_interval(ptxmgmt, pframe, pattrib, _TRUE, NULL);
3124 }
3125
3126 #ifdef CONFIG_80211N_HT
3127 if (pregistrypriv->ht_enable == _TRUE)
3128 pframe = rtw_tdls_set_ht_cap(padapter, pframe_head - pktlen_index, pattrib);
3129 #endif
3130
3131 pframe = rtw_tdls_set_bss_coexist(padapter, pframe, pattrib);
3132 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3133
3134 }
3135
3136
rtw_build_tdls_peer_traffic_indication_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)3137 void rtw_build_tdls_peer_traffic_indication_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
3138 {
3139
3140 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3141 u8 AC_queue = 0;
3142
3143 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3144 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3145 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3146 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
3147
3148 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE)
3149 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3150 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE)
3151 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3152
3153 /* PTI control */
3154 /* PU buffer status */
3155 if (ptdls_sta->uapsd_bk & BIT(1))
3156 AC_queue = BIT(0);
3157 if (ptdls_sta->uapsd_be & BIT(1))
3158 AC_queue = BIT(1);
3159 if (ptdls_sta->uapsd_vi & BIT(1))
3160 AC_queue = BIT(2);
3161 if (ptdls_sta->uapsd_vo & BIT(1))
3162 AC_queue = BIT(3);
3163 pframe = rtw_set_ie(pframe, _PTI_BUFFER_STATUS_, 1, &AC_queue, &(pattrib->pktlen));
3164
3165 }
3166
rtw_build_tdls_peer_traffic_rsp_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)3167 void rtw_build_tdls_peer_traffic_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
3168 {
3169
3170 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3171
3172 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3173 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3174 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3175 pframe = rtw_tdls_set_dialog(pframe, pattrib, ptxmgmt);
3176
3177 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE)
3178 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3179 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE)
3180 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3181 }
3182
3183 #ifdef CONFIG_TDLS_CH_SW
rtw_build_tdls_ch_switch_req_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)3184 void rtw_build_tdls_ch_switch_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
3185 {
3186 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
3187 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3188 struct sta_priv *pstapriv = &padapter->stapriv;
3189 u16 switch_time = TDLS_CH_SWITCH_TIME * 1000, switch_timeout = TDLS_CH_SWITCH_TIMEOUT * 1000;
3190
3191 ptdls_sta->ch_switch_time = switch_time;
3192 ptdls_sta->ch_switch_timeout = switch_timeout;
3193
3194 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3195 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3196 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3197 pframe = rtw_tdls_set_target_ch(padapter, pframe, pattrib);
3198 pframe = rtw_tdls_set_reg_class(pframe, pattrib, ptdls_sta);
3199
3200 if (ptdlsinfo->chsw_info.ch_offset != HAL_PRIME_CHNL_OFFSET_DONT_CARE) {
3201 switch (ptdlsinfo->chsw_info.ch_offset) {
3202 case HAL_PRIME_CHNL_OFFSET_LOWER:
3203 pframe = rtw_tdls_set_second_channel_offset(pframe, pattrib, SCA);
3204 break;
3205 case HAL_PRIME_CHNL_OFFSET_UPPER:
3206 pframe = rtw_tdls_set_second_channel_offset(pframe, pattrib, SCB);
3207 break;
3208 }
3209 }
3210
3211 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE)
3212 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3213 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE)
3214 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3215
3216 pframe = rtw_tdls_set_ch_sw(pframe, pattrib, ptdls_sta);
3217
3218 }
3219
rtw_build_tdls_ch_switch_rsp_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe,struct tdls_txmgmt * ptxmgmt,struct sta_info * ptdls_sta)3220 void rtw_build_tdls_ch_switch_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe, struct tdls_txmgmt *ptxmgmt, struct sta_info *ptdls_sta)
3221 {
3222
3223 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3224 struct sta_priv *pstapriv = &padapter->stapriv;
3225
3226 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3227 pframe = rtw_tdls_set_category(pframe, pattrib, RTW_WLAN_CATEGORY_TDLS);
3228 pframe = rtw_tdls_set_action(pframe, pattrib, ptxmgmt);
3229 pframe = rtw_tdls_set_status_code(pframe, pattrib, ptxmgmt);
3230
3231 if (ptdls_sta->tdls_sta_state & TDLS_INITIATOR_STATE)
3232 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _FALSE);
3233 else if (ptdls_sta->tdls_sta_state & TDLS_RESPONDER_STATE)
3234 pframe = rtw_tdls_set_linkid(padapter, pframe, pattrib, _TRUE);
3235
3236 pframe = rtw_tdls_set_ch_sw(pframe, pattrib, ptdls_sta);
3237 }
3238 #endif
3239
3240 #ifdef CONFIG_WFD
rtw_build_tunneled_probe_req_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe)3241 void rtw_build_tunneled_probe_req_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe)
3242 {
3243 u8 i;
3244 _adapter *iface = NULL;
3245 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
3246 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3247 struct wifidirect_info *pwdinfo;
3248
3249 u8 category = RTW_WLAN_CATEGORY_P2P;
3250 u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a};
3251 u8 probe_req = 4;
3252 u8 wfdielen = 0;
3253
3254 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3255 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3256 pframe = rtw_set_fixed_ie(pframe, 3, WFA_OUI, &(pattrib->pktlen));
3257 pframe = rtw_set_fixed_ie(pframe, 1, &(probe_req), &(pattrib->pktlen));
3258
3259 for (i = 0; i < dvobj->iface_nums; i++) {
3260 iface = dvobj->padapters[i];
3261 if ((iface) && rtw_is_adapter_up(iface)) {
3262 pwdinfo = &iface->wdinfo;
3263 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
3264 wfdielen = build_probe_req_wfd_ie(pwdinfo, pframe);
3265 pframe += wfdielen;
3266 pattrib->pktlen += wfdielen;
3267 }
3268 }
3269 }
3270 }
3271
rtw_build_tunneled_probe_rsp_ies(_adapter * padapter,struct xmit_frame * pxmitframe,u8 * pframe)3272 void rtw_build_tunneled_probe_rsp_ies(_adapter *padapter, struct xmit_frame *pxmitframe, u8 *pframe)
3273 {
3274 u8 i;
3275 _adapter *iface = NULL;
3276 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
3277 struct pkt_attrib *pattrib = &pxmitframe->attrib;
3278 struct wifidirect_info *pwdinfo;
3279 u8 category = RTW_WLAN_CATEGORY_P2P;
3280 u8 WFA_OUI[3] = { 0x50, 0x6f, 0x9a};
3281 u8 probe_rsp = 5;
3282 u8 wfdielen = 0;
3283
3284 pframe = rtw_tdls_set_payload_type(pframe, pattrib);
3285 pframe = rtw_set_fixed_ie(pframe, 1, &(category), &(pattrib->pktlen));
3286 pframe = rtw_set_fixed_ie(pframe, 3, WFA_OUI, &(pattrib->pktlen));
3287 pframe = rtw_set_fixed_ie(pframe, 1, &(probe_rsp), &(pattrib->pktlen));
3288
3289 for (i = 0; i < dvobj->iface_nums; i++) {
3290 iface = dvobj->padapters[i];
3291 if ((iface) && rtw_is_adapter_up(iface)) {
3292 pwdinfo = &iface->wdinfo;
3293 if (!rtw_p2p_chk_state(pwdinfo, P2P_STATE_NONE)) {
3294 wfdielen = build_probe_resp_wfd_ie(pwdinfo, pframe, 1);
3295 pframe += wfdielen;
3296 pattrib->pktlen += wfdielen;
3297 }
3298 }
3299 }
3300 }
3301 #endif /* CONFIG_WFD */
3302
_tdls_tpk_timer_hdl(void * FunctionContext)3303 void _tdls_tpk_timer_hdl(void *FunctionContext)
3304 {
3305 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3306 struct tdls_txmgmt txmgmt;
3307
3308 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
3309 ptdls_sta->TPK_count++;
3310 /* TPK_timer expired in a second */
3311 /* Retry timer should set at least 301 sec. */
3312 if (ptdls_sta->TPK_count >= (ptdls_sta->TDLS_PeerKey_Lifetime - 3)) {
3313 RTW_INFO("[TDLS] %s, Re-Setup TDLS link with "MAC_FMT" since TPK lifetime expires!\n",
3314 __FUNCTION__, MAC_ARG(ptdls_sta->cmn.mac_addr));
3315 ptdls_sta->TPK_count = 0;
3316 _rtw_memcpy(txmgmt.peer, ptdls_sta->cmn.mac_addr, ETH_ALEN);
3317 issue_tdls_setup_req(ptdls_sta->padapter, &txmgmt, _FALSE);
3318 }
3319
3320 _set_timer(&ptdls_sta->TPK_timer, ONE_SEC);
3321 }
3322
3323 #ifdef CONFIG_TDLS_CH_SW
_tdls_ch_switch_timer_hdl(void * FunctionContext)3324 void _tdls_ch_switch_timer_hdl(void *FunctionContext)
3325 {
3326 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3327 _adapter *padapter = ptdls_sta->padapter;
3328 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
3329
3330 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END_TO_BASE_CHNL);
3331 RTW_INFO("[TDLS] %s, can't get traffic from op_ch:%d\n", __func__, rtw_get_oper_ch(padapter));
3332 }
3333
_tdls_delay_timer_hdl(void * FunctionContext)3334 void _tdls_delay_timer_hdl(void *FunctionContext)
3335 {
3336 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3337 _adapter *padapter = ptdls_sta->padapter;
3338 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
3339
3340 RTW_INFO("[TDLS] %s, op_ch:%d, tdls_state:0x%08x\n", __func__, rtw_get_oper_ch(padapter), ptdls_sta->tdls_sta_state);
3341 pchsw_info->delay_switch_back = _TRUE;
3342 }
3343
_tdls_stay_on_base_chnl_timer_hdl(void * FunctionContext)3344 void _tdls_stay_on_base_chnl_timer_hdl(void *FunctionContext)
3345 {
3346 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3347 _adapter *padapter = ptdls_sta->padapter;
3348 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
3349
3350 if (ptdls_sta != NULL) {
3351 issue_tdls_ch_switch_req(padapter, ptdls_sta);
3352 pchsw_info->ch_sw_state |= TDLS_WAIT_CH_RSP_STATE;
3353 }
3354 }
3355
_tdls_ch_switch_monitor_timer_hdl(void * FunctionContext)3356 void _tdls_ch_switch_monitor_timer_hdl(void *FunctionContext)
3357 {
3358 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3359 _adapter *padapter = ptdls_sta->padapter;
3360 struct tdls_ch_switch *pchsw_info = &padapter->tdlsinfo.chsw_info;
3361
3362 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_CH_SW_END);
3363 RTW_INFO("[TDLS] %s, does not receive ch sw req\n", __func__);
3364 }
3365
3366 #endif
3367
_tdls_handshake_timer_hdl(void * FunctionContext)3368 void _tdls_handshake_timer_hdl(void *FunctionContext)
3369 {
3370 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3371 _adapter *padapter = NULL;
3372 struct tdls_txmgmt txmgmt;
3373
3374 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
3375 _rtw_memcpy(txmgmt.peer, ptdls_sta->cmn.mac_addr, ETH_ALEN);
3376 txmgmt.status_code = _RSON_TDLS_TEAR_UN_RSN_;
3377
3378 if (ptdls_sta != NULL) {
3379 padapter = ptdls_sta->padapter;
3380
3381 RTW_INFO("[TDLS] Handshake time out\n");
3382 if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE)
3383 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA);
3384 else
3385 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA_LOCALLY);
3386 }
3387 }
3388
_tdls_pti_timer_hdl(void * FunctionContext)3389 void _tdls_pti_timer_hdl(void *FunctionContext)
3390 {
3391 struct sta_info *ptdls_sta = (struct sta_info *)FunctionContext;
3392 _adapter *padapter = NULL;
3393 struct tdls_txmgmt txmgmt;
3394
3395 _rtw_memset(&txmgmt, 0x00, sizeof(struct tdls_txmgmt));
3396 _rtw_memcpy(txmgmt.peer, ptdls_sta->cmn.mac_addr, ETH_ALEN);
3397 txmgmt.status_code = _RSON_TDLS_TEAR_TOOFAR_;
3398
3399 if (ptdls_sta != NULL) {
3400 padapter = ptdls_sta->padapter;
3401
3402 if (ptdls_sta->tdls_sta_state & TDLS_WAIT_PTR_STATE) {
3403 RTW_INFO("[TDLS] Doesn't receive PTR from peer dev:"MAC_FMT"; "
3404 "Send TDLS Tear Down\n", MAC_ARG(ptdls_sta->cmn.mac_addr));
3405 rtw_tdls_cmd(padapter, ptdls_sta->cmn.mac_addr, TDLS_TEARDOWN_STA);
3406 }
3407 }
3408 }
3409
rtw_init_tdls_timer(_adapter * padapter,struct sta_info * psta)3410 void rtw_init_tdls_timer(_adapter *padapter, struct sta_info *psta)
3411 {
3412 psta->padapter = padapter;
3413 rtw_init_timer(&psta->TPK_timer, padapter, _tdls_tpk_timer_hdl, psta);
3414 #ifdef CONFIG_TDLS_CH_SW
3415 rtw_init_timer(&psta->ch_sw_timer, padapter, _tdls_ch_switch_timer_hdl, psta);
3416 rtw_init_timer(&psta->delay_timer, padapter, _tdls_delay_timer_hdl, psta);
3417 rtw_init_timer(&psta->stay_on_base_chnl_timer, padapter, _tdls_stay_on_base_chnl_timer_hdl, psta);
3418 rtw_init_timer(&psta->ch_sw_monitor_timer, padapter, _tdls_ch_switch_monitor_timer_hdl, psta);
3419 #endif
3420 rtw_init_timer(&psta->handshake_timer, padapter, _tdls_handshake_timer_hdl, psta);
3421 rtw_init_timer(&psta->pti_timer, padapter, _tdls_pti_timer_hdl, psta);
3422 }
3423
rtw_cancel_tdls_timer(struct sta_info * psta)3424 void rtw_cancel_tdls_timer(struct sta_info *psta)
3425 {
3426 _cancel_timer_ex(&psta->TPK_timer);
3427 #ifdef CONFIG_TDLS_CH_SW
3428 _cancel_timer_ex(&psta->ch_sw_timer);
3429 _cancel_timer_ex(&psta->delay_timer);
3430 _cancel_timer_ex(&psta->stay_on_base_chnl_timer);
3431 _cancel_timer_ex(&psta->ch_sw_monitor_timer);
3432 #endif
3433 _cancel_timer_ex(&psta->handshake_timer);
3434 _cancel_timer_ex(&psta->pti_timer);
3435 }
3436
rtw_tdls_teardown_pre_hdl(_adapter * padapter,struct sta_info * psta)3437 void rtw_tdls_teardown_pre_hdl(_adapter *padapter, struct sta_info *psta)
3438 {
3439 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
3440 struct sta_priv *pstapriv = &padapter->stapriv;
3441 _irqL irqL;
3442
3443 rtw_cancel_tdls_timer(psta);
3444
3445 _enter_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
3446 if (ptdlsinfo->sta_cnt != 0)
3447 ptdlsinfo->sta_cnt--;
3448 _exit_critical_bh(&(pstapriv->sta_hash_lock), &irqL);
3449
3450 if (ptdlsinfo->sta_cnt < MAX_ALLOWED_TDLS_STA_NUM) {
3451 ptdlsinfo->sta_maximum = _FALSE;
3452 _rtw_memset(&ptdlsinfo->ss_record, 0x00, sizeof(struct tdls_ss_record));
3453 }
3454
3455 if (ptdlsinfo->sta_cnt == 0)
3456 rtw_tdls_set_link_established(padapter, _FALSE);
3457 else
3458 RTW_INFO("Remain tdls sta:%02x\n", ptdlsinfo->sta_cnt);
3459 }
3460
rtw_tdls_teardown_post_hdl(_adapter * padapter,struct sta_info * psta,u8 enqueue_cmd)3461 void rtw_tdls_teardown_post_hdl(_adapter *padapter, struct sta_info *psta, u8 enqueue_cmd)
3462 {
3463 struct tdls_info *ptdlsinfo = &padapter->tdlsinfo;
3464
3465 /* Clear cam */
3466 rtw_clearstakey_cmd(padapter, psta, enqueue_cmd);
3467
3468 /* Update sta media status */
3469 if (enqueue_cmd)
3470 rtw_sta_media_status_rpt_cmd(padapter, psta, 0);
3471 else
3472 rtw_sta_media_status_rpt(padapter, psta, 0);
3473
3474 /* Set RCR if necessary */
3475 if (ptdlsinfo->sta_cnt == 0) {
3476 if (enqueue_cmd)
3477 rtw_tdls_cmd(padapter, NULL, TDLS_RS_RCR);
3478 else
3479 rtw_hal_rcr_set_chk_bssid(padapter, MLME_TDLS_NOLINK);
3480 }
3481
3482 /* Free tdls sta info */
3483 rtw_free_stainfo(padapter, psta);
3484 }
3485
rtw_tdls_is_driver_setup(_adapter * padapter)3486 int rtw_tdls_is_driver_setup(_adapter *padapter)
3487 {
3488 return padapter->tdlsinfo.driver_setup;
3489 }
3490
rtw_tdls_action_txt(enum TDLS_ACTION_FIELD action)3491 const char *rtw_tdls_action_txt(enum TDLS_ACTION_FIELD action)
3492 {
3493 switch (action) {
3494 case TDLS_SETUP_REQUEST:
3495 return "TDLS_SETUP_REQUEST";
3496 case TDLS_SETUP_RESPONSE:
3497 return "TDLS_SETUP_RESPONSE";
3498 case TDLS_SETUP_CONFIRM:
3499 return "TDLS_SETUP_CONFIRM";
3500 case TDLS_TEARDOWN:
3501 return "TDLS_TEARDOWN";
3502 case TDLS_PEER_TRAFFIC_INDICATION:
3503 return "TDLS_PEER_TRAFFIC_INDICATION";
3504 case TDLS_CHANNEL_SWITCH_REQUEST:
3505 return "TDLS_CHANNEL_SWITCH_REQUEST";
3506 case TDLS_CHANNEL_SWITCH_RESPONSE:
3507 return "TDLS_CHANNEL_SWITCH_RESPONSE";
3508 case TDLS_PEER_PSM_REQUEST:
3509 return "TDLS_PEER_PSM_REQUEST";
3510 case TDLS_PEER_PSM_RESPONSE:
3511 return "TDLS_PEER_PSM_RESPONSE";
3512 case TDLS_PEER_TRAFFIC_RESPONSE:
3513 return "TDLS_PEER_TRAFFIC_RESPONSE";
3514 case TDLS_DISCOVERY_REQUEST:
3515 return "TDLS_DISCOVERY_REQUEST";
3516 case TDLS_DISCOVERY_RESPONSE:
3517 return "TDLS_DISCOVERY_RESPONSE";
3518 default:
3519 return "UNKNOWN";
3520 }
3521 }
3522
3523 #endif /* CONFIG_TDLS */
3524