tdls.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. /*
  2. * NXP Wireless LAN device driver: TDLS handling
  3. *
  4. * Copyright 2011-2020 NXP
  5. *
  6. * This software file (the "File") is distributed by NXP
  7. * under the terms of the GNU General Public License Version 2, June 1991
  8. * (the "License"). You may use, redistribute and/or modify this File in
  9. * accordance with the terms and conditions of the License, a copy of which
  10. * is available on the worldwide web at
  11. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  12. *
  13. * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
  14. * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
  15. * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
  16. * this warranty disclaimer.
  17. */
  18. #include "main.h"
  19. #include "wmm.h"
  20. #include "11n.h"
  21. #include "11n_rxreorder.h"
  22. #include "11ac.h"
  23. #define TDLS_REQ_FIX_LEN 6
  24. #define TDLS_RESP_FIX_LEN 8
  25. #define TDLS_CONFIRM_FIX_LEN 6
  26. #define MWIFIEX_TDLS_WMM_INFO_SIZE 7
  27. static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv,
  28. const u8 *mac, u8 status)
  29. {
  30. struct mwifiex_ra_list_tbl *ra_list;
  31. struct list_head *tid_list;
  32. struct sk_buff *skb, *tmp;
  33. struct mwifiex_txinfo *tx_info;
  34. u32 tid;
  35. u8 tid_down;
  36. mwifiex_dbg(priv->adapter, DATA, "%s: %pM\n", __func__, mac);
  37. spin_lock_bh(&priv->wmm.ra_list_spinlock);
  38. skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
  39. if (!ether_addr_equal(mac, skb->data))
  40. continue;
  41. __skb_unlink(skb, &priv->tdls_txq);
  42. tx_info = MWIFIEX_SKB_TXCB(skb);
  43. tid = skb->priority;
  44. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  45. if (mwifiex_is_tdls_link_setup(status)) {
  46. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid, mac);
  47. ra_list->tdls_link = true;
  48. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  49. } else {
  50. tid_list = &priv->wmm.tid_tbl_ptr[tid_down].ra_list;
  51. ra_list = list_first_entry_or_null(tid_list,
  52. struct mwifiex_ra_list_tbl, list);
  53. tx_info->flags &= ~MWIFIEX_BUF_FLAG_TDLS_PKT;
  54. }
  55. if (!ra_list) {
  56. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  57. continue;
  58. }
  59. skb_queue_tail(&ra_list->skb_head, skb);
  60. ra_list->ba_pkt_count++;
  61. ra_list->total_pkt_count++;
  62. if (atomic_read(&priv->wmm.highest_queued_prio) <
  63. tos_to_tid_inv[tid_down])
  64. atomic_set(&priv->wmm.highest_queued_prio,
  65. tos_to_tid_inv[tid_down]);
  66. atomic_inc(&priv->wmm.tx_pkts_queued);
  67. }
  68. spin_unlock_bh(&priv->wmm.ra_list_spinlock);
  69. return;
  70. }
  71. static void mwifiex_hold_tdls_packets(struct mwifiex_private *priv,
  72. const u8 *mac)
  73. {
  74. struct mwifiex_ra_list_tbl *ra_list;
  75. struct list_head *ra_list_head;
  76. struct sk_buff *skb, *tmp;
  77. int i;
  78. mwifiex_dbg(priv->adapter, DATA, "%s: %pM\n", __func__, mac);
  79. spin_lock_bh(&priv->wmm.ra_list_spinlock);
  80. for (i = 0; i < MAX_NUM_TID; i++) {
  81. if (!list_empty(&priv->wmm.tid_tbl_ptr[i].ra_list)) {
  82. ra_list_head = &priv->wmm.tid_tbl_ptr[i].ra_list;
  83. list_for_each_entry(ra_list, ra_list_head, list) {
  84. skb_queue_walk_safe(&ra_list->skb_head, skb,
  85. tmp) {
  86. if (!ether_addr_equal(mac, skb->data))
  87. continue;
  88. __skb_unlink(skb, &ra_list->skb_head);
  89. atomic_dec(&priv->wmm.tx_pkts_queued);
  90. ra_list->total_pkt_count--;
  91. skb_queue_tail(&priv->tdls_txq, skb);
  92. }
  93. }
  94. }
  95. }
  96. spin_unlock_bh(&priv->wmm.ra_list_spinlock);
  97. return;
  98. }
  99. /* This function appends rate TLV to scan config command. */
  100. static int
  101. mwifiex_tdls_append_rates_ie(struct mwifiex_private *priv,
  102. struct sk_buff *skb)
  103. {
  104. u8 rates[MWIFIEX_SUPPORTED_RATES], *pos;
  105. u16 rates_size, supp_rates_size, ext_rates_size;
  106. memset(rates, 0, sizeof(rates));
  107. rates_size = mwifiex_get_supported_rates(priv, rates);
  108. supp_rates_size = min_t(u16, rates_size, MWIFIEX_TDLS_SUPPORTED_RATES);
  109. if (skb_tailroom(skb) < rates_size + 4) {
  110. mwifiex_dbg(priv->adapter, ERROR,
  111. "Insufficient space while adding rates\n");
  112. return -ENOMEM;
  113. }
  114. pos = skb_put(skb, supp_rates_size + 2);
  115. *pos++ = WLAN_EID_SUPP_RATES;
  116. *pos++ = supp_rates_size;
  117. memcpy(pos, rates, supp_rates_size);
  118. if (rates_size > MWIFIEX_TDLS_SUPPORTED_RATES) {
  119. ext_rates_size = rates_size - MWIFIEX_TDLS_SUPPORTED_RATES;
  120. pos = skb_put(skb, ext_rates_size + 2);
  121. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  122. *pos++ = ext_rates_size;
  123. memcpy(pos, rates + MWIFIEX_TDLS_SUPPORTED_RATES,
  124. ext_rates_size);
  125. }
  126. return 0;
  127. }
  128. static void mwifiex_tdls_add_aid(struct mwifiex_private *priv,
  129. struct sk_buff *skb)
  130. {
  131. struct ieee_types_assoc_rsp *assoc_rsp;
  132. u8 *pos;
  133. assoc_rsp = (struct ieee_types_assoc_rsp *)&priv->assoc_rsp_buf;
  134. pos = skb_put(skb, 4);
  135. *pos++ = WLAN_EID_AID;
  136. *pos++ = 2;
  137. memcpy(pos, &assoc_rsp->a_id, sizeof(assoc_rsp->a_id));
  138. return;
  139. }
  140. static int mwifiex_tdls_add_vht_capab(struct mwifiex_private *priv,
  141. struct sk_buff *skb)
  142. {
  143. struct ieee80211_vht_cap vht_cap;
  144. u8 *pos;
  145. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  146. *pos++ = WLAN_EID_VHT_CAPABILITY;
  147. *pos++ = sizeof(struct ieee80211_vht_cap);
  148. memset(&vht_cap, 0, sizeof(struct ieee80211_vht_cap));
  149. mwifiex_fill_vht_cap_tlv(priv, &vht_cap, priv->curr_bss_params.band);
  150. memcpy(pos, &vht_cap, sizeof(vht_cap));
  151. return 0;
  152. }
  153. static int
  154. mwifiex_tdls_add_ht_oper(struct mwifiex_private *priv, const u8 *mac,
  155. u8 vht_enabled, struct sk_buff *skb)
  156. {
  157. struct ieee80211_ht_operation *ht_oper;
  158. struct mwifiex_sta_node *sta_ptr;
  159. struct mwifiex_bssdescriptor *bss_desc =
  160. &priv->curr_bss_params.bss_descriptor;
  161. u8 *pos;
  162. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  163. if (unlikely(!sta_ptr)) {
  164. mwifiex_dbg(priv->adapter, ERROR,
  165. "TDLS peer station not found in list\n");
  166. return -1;
  167. }
  168. if (!(le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info))) {
  169. mwifiex_dbg(priv->adapter, WARN,
  170. "TDLS peer doesn't support ht capabilities\n");
  171. return 0;
  172. }
  173. pos = skb_put(skb, sizeof(struct ieee80211_ht_operation) + 2);
  174. *pos++ = WLAN_EID_HT_OPERATION;
  175. *pos++ = sizeof(struct ieee80211_ht_operation);
  176. ht_oper = (void *)pos;
  177. ht_oper->primary_chan = bss_desc->channel;
  178. /* follow AP's channel bandwidth */
  179. if (ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
  180. bss_desc->bcn_ht_cap &&
  181. ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_oper->ht_param))
  182. ht_oper->ht_param = bss_desc->bcn_ht_oper->ht_param;
  183. if (vht_enabled) {
  184. ht_oper->ht_param =
  185. mwifiex_get_sec_chan_offset(bss_desc->channel);
  186. ht_oper->ht_param |= BIT(2);
  187. }
  188. memcpy(&sta_ptr->tdls_cap.ht_oper, ht_oper,
  189. sizeof(struct ieee80211_ht_operation));
  190. return 0;
  191. }
  192. static int mwifiex_tdls_add_vht_oper(struct mwifiex_private *priv,
  193. const u8 *mac, struct sk_buff *skb)
  194. {
  195. struct mwifiex_bssdescriptor *bss_desc;
  196. struct ieee80211_vht_operation *vht_oper;
  197. struct ieee80211_vht_cap *vht_cap, *ap_vht_cap = NULL;
  198. struct mwifiex_sta_node *sta_ptr;
  199. struct mwifiex_adapter *adapter = priv->adapter;
  200. u8 supp_chwd_set, peer_supp_chwd_set;
  201. u8 *pos, ap_supp_chwd_set, chan_bw;
  202. u16 mcs_map_user, mcs_map_resp, mcs_map_result;
  203. u16 mcs_user, mcs_resp, nss;
  204. u32 usr_vht_cap_info;
  205. bss_desc = &priv->curr_bss_params.bss_descriptor;
  206. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  207. if (unlikely(!sta_ptr)) {
  208. mwifiex_dbg(adapter, ERROR,
  209. "TDLS peer station not found in list\n");
  210. return -1;
  211. }
  212. if (!(le32_to_cpu(sta_ptr->tdls_cap.vhtcap.vht_cap_info))) {
  213. mwifiex_dbg(adapter, WARN,
  214. "TDLS peer doesn't support vht capabilities\n");
  215. return 0;
  216. }
  217. if (!mwifiex_is_bss_in_11ac_mode(priv)) {
  218. if (sta_ptr->tdls_cap.extcap.ext_capab[7] &
  219. WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
  220. mwifiex_dbg(adapter, WARN,
  221. "TDLS peer doesn't support wider bandwidth\n");
  222. return 0;
  223. }
  224. } else {
  225. ap_vht_cap = bss_desc->bcn_vht_cap;
  226. }
  227. pos = skb_put(skb, sizeof(struct ieee80211_vht_operation) + 2);
  228. *pos++ = WLAN_EID_VHT_OPERATION;
  229. *pos++ = sizeof(struct ieee80211_vht_operation);
  230. vht_oper = (struct ieee80211_vht_operation *)pos;
  231. if (bss_desc->bss_band & BAND_A)
  232. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
  233. else
  234. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
  235. /* find the minimum bandwidth between AP/TDLS peers */
  236. vht_cap = &sta_ptr->tdls_cap.vhtcap;
  237. supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
  238. peer_supp_chwd_set =
  239. GET_VHTCAP_CHWDSET(le32_to_cpu(vht_cap->vht_cap_info));
  240. supp_chwd_set = min_t(u8, supp_chwd_set, peer_supp_chwd_set);
  241. /* We need check AP's bandwidth when TDLS_WIDER_BANDWIDTH is off */
  242. if (ap_vht_cap && sta_ptr->tdls_cap.extcap.ext_capab[7] &
  243. WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
  244. ap_supp_chwd_set =
  245. GET_VHTCAP_CHWDSET(le32_to_cpu(ap_vht_cap->vht_cap_info));
  246. supp_chwd_set = min_t(u8, supp_chwd_set, ap_supp_chwd_set);
  247. }
  248. switch (supp_chwd_set) {
  249. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  250. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  251. break;
  252. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  253. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
  254. break;
  255. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  256. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
  257. break;
  258. default:
  259. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
  260. break;
  261. }
  262. mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
  263. mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
  264. mcs_map_result = 0;
  265. for (nss = 1; nss <= 8; nss++) {
  266. mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
  267. mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
  268. if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
  269. (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
  270. SET_VHTNSSMCS(mcs_map_result, nss,
  271. IEEE80211_VHT_MCS_NOT_SUPPORTED);
  272. else
  273. SET_VHTNSSMCS(mcs_map_result, nss,
  274. min_t(u16, mcs_user, mcs_resp));
  275. }
  276. vht_oper->basic_mcs_set = cpu_to_le16(mcs_map_result);
  277. switch (vht_oper->chan_width) {
  278. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  279. chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
  280. break;
  281. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  282. chan_bw = IEEE80211_VHT_CHANWIDTH_160MHZ;
  283. break;
  284. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  285. chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
  286. break;
  287. default:
  288. chan_bw = IEEE80211_VHT_CHANWIDTH_USE_HT;
  289. break;
  290. }
  291. vht_oper->center_freq_seg0_idx =
  292. mwifiex_get_center_freq_index(priv, BAND_AAC,
  293. bss_desc->channel,
  294. chan_bw);
  295. return 0;
  296. }
  297. static void mwifiex_tdls_add_ext_capab(struct mwifiex_private *priv,
  298. struct sk_buff *skb)
  299. {
  300. struct ieee_types_extcap *extcap;
  301. extcap = skb_put(skb, sizeof(struct ieee_types_extcap));
  302. extcap->ieee_hdr.element_id = WLAN_EID_EXT_CAPABILITY;
  303. extcap->ieee_hdr.len = 8;
  304. memset(extcap->ext_capab, 0, 8);
  305. extcap->ext_capab[4] |= WLAN_EXT_CAPA5_TDLS_ENABLED;
  306. extcap->ext_capab[3] |= WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH;
  307. if (priv->adapter->is_hw_11ac_capable)
  308. extcap->ext_capab[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED;
  309. }
  310. static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
  311. {
  312. u8 *pos = skb_put(skb, 3);
  313. *pos++ = WLAN_EID_QOS_CAPA;
  314. *pos++ = 1;
  315. *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
  316. }
  317. static void
  318. mwifiex_tdls_add_wmm_param_ie(struct mwifiex_private *priv, struct sk_buff *skb)
  319. {
  320. struct ieee80211_wmm_param_ie *wmm;
  321. u8 ac_vi[] = {0x42, 0x43, 0x5e, 0x00};
  322. u8 ac_vo[] = {0x62, 0x32, 0x2f, 0x00};
  323. u8 ac_be[] = {0x03, 0xa4, 0x00, 0x00};
  324. u8 ac_bk[] = {0x27, 0xa4, 0x00, 0x00};
  325. wmm = skb_put_zero(skb, sizeof(*wmm));
  326. wmm->element_id = WLAN_EID_VENDOR_SPECIFIC;
  327. wmm->len = sizeof(*wmm) - 2;
  328. wmm->oui[0] = 0x00; /* Microsoft OUI 00:50:F2 */
  329. wmm->oui[1] = 0x50;
  330. wmm->oui[2] = 0xf2;
  331. wmm->oui_type = 2; /* WME */
  332. wmm->oui_subtype = 1; /* WME param */
  333. wmm->version = 1; /* WME ver */
  334. wmm->qos_info = 0; /* U-APSD not in use */
  335. /* use default WMM AC parameters for TDLS link*/
  336. memcpy(&wmm->ac[0], ac_be, sizeof(ac_be));
  337. memcpy(&wmm->ac[1], ac_bk, sizeof(ac_bk));
  338. memcpy(&wmm->ac[2], ac_vi, sizeof(ac_vi));
  339. memcpy(&wmm->ac[3], ac_vo, sizeof(ac_vo));
  340. }
  341. static void
  342. mwifiex_add_wmm_info_ie(struct mwifiex_private *priv, struct sk_buff *skb,
  343. u8 qosinfo)
  344. {
  345. u8 *buf;
  346. buf = skb_put(skb,
  347. MWIFIEX_TDLS_WMM_INFO_SIZE + sizeof(struct ieee_types_header));
  348. *buf++ = WLAN_EID_VENDOR_SPECIFIC;
  349. *buf++ = 7; /* len */
  350. *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
  351. *buf++ = 0x50;
  352. *buf++ = 0xf2;
  353. *buf++ = 2; /* WME */
  354. *buf++ = 0; /* WME info */
  355. *buf++ = 1; /* WME ver */
  356. *buf++ = qosinfo; /* U-APSD no in use */
  357. }
  358. static void mwifiex_tdls_add_bss_co_2040(struct sk_buff *skb)
  359. {
  360. struct ieee_types_bss_co_2040 *bssco;
  361. bssco = skb_put(skb, sizeof(struct ieee_types_bss_co_2040));
  362. bssco->ieee_hdr.element_id = WLAN_EID_BSS_COEX_2040;
  363. bssco->ieee_hdr.len = sizeof(struct ieee_types_bss_co_2040) -
  364. sizeof(struct ieee_types_header);
  365. bssco->bss_2040co = 0x01;
  366. }
  367. static void mwifiex_tdls_add_supported_chan(struct sk_buff *skb)
  368. {
  369. struct ieee_types_generic *supp_chan;
  370. u8 chan_supp[] = {1, 11};
  371. supp_chan = skb_put(skb,
  372. (sizeof(struct ieee_types_header) + sizeof(chan_supp)));
  373. supp_chan->ieee_hdr.element_id = WLAN_EID_SUPPORTED_CHANNELS;
  374. supp_chan->ieee_hdr.len = sizeof(chan_supp);
  375. memcpy(supp_chan->data, chan_supp, sizeof(chan_supp));
  376. }
  377. static void mwifiex_tdls_add_oper_class(struct sk_buff *skb)
  378. {
  379. struct ieee_types_generic *reg_class;
  380. u8 rc_list[] = {1,
  381. 1, 2, 3, 4, 12, 22, 23, 24, 25, 27, 28, 29, 30, 32, 33};
  382. reg_class = skb_put(skb,
  383. (sizeof(struct ieee_types_header) + sizeof(rc_list)));
  384. reg_class->ieee_hdr.element_id = WLAN_EID_SUPPORTED_REGULATORY_CLASSES;
  385. reg_class->ieee_hdr.len = sizeof(rc_list);
  386. memcpy(reg_class->data, rc_list, sizeof(rc_list));
  387. }
  388. static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
  389. const u8 *peer, u8 action_code,
  390. u8 dialog_token,
  391. u16 status_code, struct sk_buff *skb)
  392. {
  393. struct ieee80211_tdls_data *tf;
  394. int ret;
  395. u16 capab;
  396. struct ieee80211_ht_cap *ht_cap;
  397. u8 radio, *pos;
  398. capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
  399. tf = skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  400. memcpy(tf->da, peer, ETH_ALEN);
  401. memcpy(tf->sa, priv->curr_addr, ETH_ALEN);
  402. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  403. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  404. switch (action_code) {
  405. case WLAN_TDLS_SETUP_REQUEST:
  406. tf->category = WLAN_CATEGORY_TDLS;
  407. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  408. skb_put(skb, sizeof(tf->u.setup_req));
  409. tf->u.setup_req.dialog_token = dialog_token;
  410. tf->u.setup_req.capability = cpu_to_le16(capab);
  411. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  412. if (ret) {
  413. dev_kfree_skb_any(skb);
  414. return ret;
  415. }
  416. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  417. *pos++ = WLAN_EID_HT_CAPABILITY;
  418. *pos++ = sizeof(struct ieee80211_ht_cap);
  419. ht_cap = (void *)pos;
  420. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  421. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  422. if (ret) {
  423. dev_kfree_skb_any(skb);
  424. return ret;
  425. }
  426. if (priv->adapter->is_hw_11ac_capable) {
  427. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  428. if (ret) {
  429. dev_kfree_skb_any(skb);
  430. return ret;
  431. }
  432. mwifiex_tdls_add_aid(priv, skb);
  433. }
  434. mwifiex_tdls_add_ext_capab(priv, skb);
  435. mwifiex_tdls_add_bss_co_2040(skb);
  436. mwifiex_tdls_add_supported_chan(skb);
  437. mwifiex_tdls_add_oper_class(skb);
  438. mwifiex_add_wmm_info_ie(priv, skb, 0);
  439. break;
  440. case WLAN_TDLS_SETUP_RESPONSE:
  441. tf->category = WLAN_CATEGORY_TDLS;
  442. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  443. skb_put(skb, sizeof(tf->u.setup_resp));
  444. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  445. tf->u.setup_resp.dialog_token = dialog_token;
  446. tf->u.setup_resp.capability = cpu_to_le16(capab);
  447. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  448. if (ret) {
  449. dev_kfree_skb_any(skb);
  450. return ret;
  451. }
  452. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  453. *pos++ = WLAN_EID_HT_CAPABILITY;
  454. *pos++ = sizeof(struct ieee80211_ht_cap);
  455. ht_cap = (void *)pos;
  456. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  457. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  458. if (ret) {
  459. dev_kfree_skb_any(skb);
  460. return ret;
  461. }
  462. if (priv->adapter->is_hw_11ac_capable) {
  463. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  464. if (ret) {
  465. dev_kfree_skb_any(skb);
  466. return ret;
  467. }
  468. mwifiex_tdls_add_aid(priv, skb);
  469. }
  470. mwifiex_tdls_add_ext_capab(priv, skb);
  471. mwifiex_tdls_add_bss_co_2040(skb);
  472. mwifiex_tdls_add_supported_chan(skb);
  473. mwifiex_tdls_add_oper_class(skb);
  474. mwifiex_add_wmm_info_ie(priv, skb, 0);
  475. break;
  476. case WLAN_TDLS_SETUP_CONFIRM:
  477. tf->category = WLAN_CATEGORY_TDLS;
  478. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  479. skb_put(skb, sizeof(tf->u.setup_cfm));
  480. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  481. tf->u.setup_cfm.dialog_token = dialog_token;
  482. mwifiex_tdls_add_wmm_param_ie(priv, skb);
  483. if (priv->adapter->is_hw_11ac_capable) {
  484. ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
  485. if (ret) {
  486. dev_kfree_skb_any(skb);
  487. return ret;
  488. }
  489. ret = mwifiex_tdls_add_ht_oper(priv, peer, 1, skb);
  490. if (ret) {
  491. dev_kfree_skb_any(skb);
  492. return ret;
  493. }
  494. } else {
  495. ret = mwifiex_tdls_add_ht_oper(priv, peer, 0, skb);
  496. if (ret) {
  497. dev_kfree_skb_any(skb);
  498. return ret;
  499. }
  500. }
  501. break;
  502. case WLAN_TDLS_TEARDOWN:
  503. tf->category = WLAN_CATEGORY_TDLS;
  504. tf->action_code = WLAN_TDLS_TEARDOWN;
  505. skb_put(skb, sizeof(tf->u.teardown));
  506. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  507. break;
  508. case WLAN_TDLS_DISCOVERY_REQUEST:
  509. tf->category = WLAN_CATEGORY_TDLS;
  510. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  511. skb_put(skb, sizeof(tf->u.discover_req));
  512. tf->u.discover_req.dialog_token = dialog_token;
  513. break;
  514. default:
  515. mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
  516. return -EINVAL;
  517. }
  518. return 0;
  519. }
  520. static void
  521. mwifiex_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
  522. const u8 *peer, const u8 *bssid)
  523. {
  524. struct ieee80211_tdls_lnkie *lnkid;
  525. lnkid = skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  526. lnkid->ie_type = WLAN_EID_LINK_ID;
  527. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) -
  528. sizeof(struct ieee_types_header);
  529. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  530. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  531. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  532. }
  533. int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
  534. u8 action_code, u8 dialog_token,
  535. u16 status_code, const u8 *extra_ies,
  536. size_t extra_ies_len)
  537. {
  538. struct sk_buff *skb;
  539. struct mwifiex_txinfo *tx_info;
  540. int ret;
  541. u16 skb_len;
  542. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  543. max(sizeof(struct ieee80211_mgmt),
  544. sizeof(struct ieee80211_tdls_data)) +
  545. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  546. MWIFIEX_SUPPORTED_RATES +
  547. 3 + /* Qos Info */
  548. sizeof(struct ieee_types_extcap) +
  549. sizeof(struct ieee80211_ht_cap) +
  550. sizeof(struct ieee_types_bss_co_2040) +
  551. sizeof(struct ieee80211_ht_operation) +
  552. sizeof(struct ieee80211_tdls_lnkie) +
  553. (2 * (sizeof(struct ieee_types_header))) +
  554. MWIFIEX_SUPPORTED_CHANNELS +
  555. MWIFIEX_OPERATING_CLASSES +
  556. sizeof(struct ieee80211_wmm_param_ie) +
  557. extra_ies_len;
  558. if (priv->adapter->is_hw_11ac_capable)
  559. skb_len += sizeof(struct ieee_types_vht_cap) +
  560. sizeof(struct ieee_types_vht_oper) +
  561. sizeof(struct ieee_types_aid);
  562. skb = dev_alloc_skb(skb_len);
  563. if (!skb) {
  564. mwifiex_dbg(priv->adapter, ERROR,
  565. "allocate skb failed for management frame\n");
  566. return -ENOMEM;
  567. }
  568. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  569. switch (action_code) {
  570. case WLAN_TDLS_SETUP_REQUEST:
  571. case WLAN_TDLS_SETUP_CONFIRM:
  572. case WLAN_TDLS_TEARDOWN:
  573. case WLAN_TDLS_DISCOVERY_REQUEST:
  574. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  575. dialog_token, status_code,
  576. skb);
  577. if (ret) {
  578. dev_kfree_skb_any(skb);
  579. return ret;
  580. }
  581. if (extra_ies_len)
  582. skb_put_data(skb, extra_ies, extra_ies_len);
  583. mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
  584. priv->cfg_bssid);
  585. break;
  586. case WLAN_TDLS_SETUP_RESPONSE:
  587. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  588. dialog_token, status_code,
  589. skb);
  590. if (ret) {
  591. dev_kfree_skb_any(skb);
  592. return ret;
  593. }
  594. if (extra_ies_len)
  595. skb_put_data(skb, extra_ies, extra_ies_len);
  596. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  597. priv->cfg_bssid);
  598. break;
  599. }
  600. switch (action_code) {
  601. case WLAN_TDLS_SETUP_REQUEST:
  602. case WLAN_TDLS_SETUP_RESPONSE:
  603. skb->priority = MWIFIEX_PRIO_BK;
  604. break;
  605. default:
  606. skb->priority = MWIFIEX_PRIO_VI;
  607. break;
  608. }
  609. tx_info = MWIFIEX_SKB_TXCB(skb);
  610. memset(tx_info, 0, sizeof(*tx_info));
  611. tx_info->bss_num = priv->bss_num;
  612. tx_info->bss_type = priv->bss_type;
  613. __net_timestamp(skb);
  614. mwifiex_queue_tx_pkt(priv, skb);
  615. /* Delay 10ms to make sure tdls setup confirm/teardown frame
  616. * is received by peer
  617. */
  618. if (action_code == WLAN_TDLS_SETUP_CONFIRM ||
  619. action_code == WLAN_TDLS_TEARDOWN)
  620. msleep_interruptible(10);
  621. return 0;
  622. }
  623. static int
  624. mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
  625. const u8 *peer,
  626. u8 action_code, u8 dialog_token,
  627. u16 status_code, struct sk_buff *skb)
  628. {
  629. struct ieee80211_mgmt *mgmt;
  630. int ret;
  631. u16 capab;
  632. struct ieee80211_ht_cap *ht_cap;
  633. unsigned int extra;
  634. u8 radio, *pos;
  635. capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
  636. mgmt = skb_put(skb, offsetof(struct ieee80211_mgmt, u));
  637. memset(mgmt, 0, 24);
  638. memcpy(mgmt->da, peer, ETH_ALEN);
  639. memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
  640. memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
  641. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  642. IEEE80211_STYPE_ACTION);
  643. /* add address 4 */
  644. pos = skb_put(skb, ETH_ALEN);
  645. switch (action_code) {
  646. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  647. /* See the layout of 'struct ieee80211_mgmt'. */
  648. extra = sizeof(mgmt->u.action.u.tdls_discover_resp) +
  649. sizeof(mgmt->u.action.category);
  650. skb_put(skb, extra);
  651. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  652. mgmt->u.action.u.tdls_discover_resp.action_code =
  653. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  654. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  655. dialog_token;
  656. mgmt->u.action.u.tdls_discover_resp.capability =
  657. cpu_to_le16(capab);
  658. /* move back for addr4 */
  659. memmove(pos + ETH_ALEN, &mgmt->u.action, extra);
  660. /* init address 4 */
  661. eth_broadcast_addr(pos);
  662. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  663. if (ret) {
  664. dev_kfree_skb_any(skb);
  665. return ret;
  666. }
  667. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  668. *pos++ = WLAN_EID_HT_CAPABILITY;
  669. *pos++ = sizeof(struct ieee80211_ht_cap);
  670. ht_cap = (void *)pos;
  671. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  672. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  673. if (ret) {
  674. dev_kfree_skb_any(skb);
  675. return ret;
  676. }
  677. if (priv->adapter->is_hw_11ac_capable) {
  678. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  679. if (ret) {
  680. dev_kfree_skb_any(skb);
  681. return ret;
  682. }
  683. mwifiex_tdls_add_aid(priv, skb);
  684. }
  685. mwifiex_tdls_add_ext_capab(priv, skb);
  686. mwifiex_tdls_add_bss_co_2040(skb);
  687. mwifiex_tdls_add_supported_chan(skb);
  688. mwifiex_tdls_add_qos_capab(skb);
  689. mwifiex_tdls_add_oper_class(skb);
  690. break;
  691. default:
  692. mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS action frame type\n");
  693. return -EINVAL;
  694. }
  695. return 0;
  696. }
  697. int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
  698. u8 action_code, u8 dialog_token,
  699. u16 status_code, const u8 *extra_ies,
  700. size_t extra_ies_len)
  701. {
  702. struct sk_buff *skb;
  703. struct mwifiex_txinfo *tx_info;
  704. u8 *pos;
  705. u32 pkt_type, tx_control;
  706. u16 pkt_len, skb_len;
  707. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  708. max(sizeof(struct ieee80211_mgmt),
  709. sizeof(struct ieee80211_tdls_data)) +
  710. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  711. MWIFIEX_SUPPORTED_RATES +
  712. sizeof(struct ieee_types_extcap) +
  713. sizeof(struct ieee80211_ht_cap) +
  714. sizeof(struct ieee_types_bss_co_2040) +
  715. sizeof(struct ieee80211_ht_operation) +
  716. sizeof(struct ieee80211_tdls_lnkie) +
  717. extra_ies_len +
  718. 3 + /* Qos Info */
  719. ETH_ALEN; /* Address4 */
  720. if (priv->adapter->is_hw_11ac_capable)
  721. skb_len += sizeof(struct ieee_types_vht_cap) +
  722. sizeof(struct ieee_types_vht_oper) +
  723. sizeof(struct ieee_types_aid);
  724. skb = dev_alloc_skb(skb_len);
  725. if (!skb) {
  726. mwifiex_dbg(priv->adapter, ERROR,
  727. "allocate skb failed for management frame\n");
  728. return -ENOMEM;
  729. }
  730. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  731. pkt_type = PKT_TYPE_MGMT;
  732. tx_control = 0;
  733. pos = skb_put_zero(skb,
  734. MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  735. memcpy(pos, &pkt_type, sizeof(pkt_type));
  736. memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
  737. if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
  738. dialog_token, status_code,
  739. skb)) {
  740. dev_kfree_skb_any(skb);
  741. return -EINVAL;
  742. }
  743. if (extra_ies_len)
  744. skb_put_data(skb, extra_ies, extra_ies_len);
  745. /* the TDLS link IE is always added last we are the responder */
  746. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  747. priv->cfg_bssid);
  748. skb->priority = MWIFIEX_PRIO_VI;
  749. tx_info = MWIFIEX_SKB_TXCB(skb);
  750. memset(tx_info, 0, sizeof(*tx_info));
  751. tx_info->bss_num = priv->bss_num;
  752. tx_info->bss_type = priv->bss_type;
  753. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  754. pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
  755. memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
  756. sizeof(pkt_len));
  757. __net_timestamp(skb);
  758. mwifiex_queue_tx_pkt(priv, skb);
  759. return 0;
  760. }
  761. /* This function process tdls action frame from peer.
  762. * Peer capabilities are stored into station node structure.
  763. */
  764. void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
  765. u8 *buf, int len)
  766. {
  767. struct mwifiex_sta_node *sta_ptr;
  768. u8 *peer, *pos, *end;
  769. u8 i, action, basic;
  770. u16 cap = 0;
  771. int ies_len = 0;
  772. if (len < (sizeof(struct ethhdr) + 3))
  773. return;
  774. if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
  775. return;
  776. if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
  777. return;
  778. peer = buf + ETH_ALEN;
  779. action = *(buf + sizeof(struct ethhdr) + 2);
  780. mwifiex_dbg(priv->adapter, DATA,
  781. "rx:tdls action: peer=%pM, action=%d\n", peer, action);
  782. switch (action) {
  783. case WLAN_TDLS_SETUP_REQUEST:
  784. if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
  785. return;
  786. pos = buf + sizeof(struct ethhdr) + 4;
  787. /* payload 1+ category 1 + action 1 + dialog 1 */
  788. cap = get_unaligned_le16(pos);
  789. ies_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
  790. pos += 2;
  791. break;
  792. case WLAN_TDLS_SETUP_RESPONSE:
  793. if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
  794. return;
  795. /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
  796. pos = buf + sizeof(struct ethhdr) + 6;
  797. cap = get_unaligned_le16(pos);
  798. ies_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
  799. pos += 2;
  800. break;
  801. case WLAN_TDLS_SETUP_CONFIRM:
  802. if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
  803. return;
  804. pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
  805. ies_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
  806. break;
  807. default:
  808. mwifiex_dbg(priv->adapter, ERROR, "Unknown TDLS frame type.\n");
  809. return;
  810. }
  811. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  812. if (!sta_ptr)
  813. return;
  814. sta_ptr->tdls_cap.capab = cpu_to_le16(cap);
  815. for (end = pos + ies_len; pos + 1 < end; pos += 2 + pos[1]) {
  816. u8 ie_len = pos[1];
  817. if (pos + 2 + ie_len > end)
  818. break;
  819. switch (*pos) {
  820. case WLAN_EID_SUPP_RATES:
  821. if (ie_len > sizeof(sta_ptr->tdls_cap.rates))
  822. return;
  823. sta_ptr->tdls_cap.rates_len = ie_len;
  824. for (i = 0; i < ie_len; i++)
  825. sta_ptr->tdls_cap.rates[i] = pos[i + 2];
  826. break;
  827. case WLAN_EID_EXT_SUPP_RATES:
  828. if (ie_len > sizeof(sta_ptr->tdls_cap.rates))
  829. return;
  830. basic = sta_ptr->tdls_cap.rates_len;
  831. if (ie_len > sizeof(sta_ptr->tdls_cap.rates) - basic)
  832. return;
  833. for (i = 0; i < ie_len; i++)
  834. sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
  835. sta_ptr->tdls_cap.rates_len += ie_len;
  836. break;
  837. case WLAN_EID_HT_CAPABILITY:
  838. if (ie_len != sizeof(struct ieee80211_ht_cap))
  839. return;
  840. /* copy the ie's value into ht_capb*/
  841. memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos + 2,
  842. sizeof(struct ieee80211_ht_cap));
  843. sta_ptr->is_11n_enabled = 1;
  844. break;
  845. case WLAN_EID_HT_OPERATION:
  846. if (ie_len != sizeof(struct ieee80211_ht_operation))
  847. return;
  848. /* copy the ie's value into ht_oper*/
  849. memcpy(&sta_ptr->tdls_cap.ht_oper, pos + 2,
  850. sizeof(struct ieee80211_ht_operation));
  851. break;
  852. case WLAN_EID_BSS_COEX_2040:
  853. if (ie_len != sizeof(pos[2]))
  854. return;
  855. sta_ptr->tdls_cap.coex_2040 = pos[2];
  856. break;
  857. case WLAN_EID_EXT_CAPABILITY:
  858. if (ie_len < sizeof(struct ieee_types_header))
  859. return;
  860. if (ie_len > 8)
  861. return;
  862. memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
  863. sizeof(struct ieee_types_header) +
  864. min_t(u8, ie_len, 8));
  865. break;
  866. case WLAN_EID_RSN:
  867. if (ie_len < sizeof(struct ieee_types_header))
  868. return;
  869. if (ie_len > IEEE_MAX_IE_SIZE -
  870. sizeof(struct ieee_types_header))
  871. return;
  872. memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
  873. sizeof(struct ieee_types_header) +
  874. min_t(u8, ie_len, IEEE_MAX_IE_SIZE -
  875. sizeof(struct ieee_types_header)));
  876. break;
  877. case WLAN_EID_QOS_CAPA:
  878. if (ie_len != sizeof(pos[2]))
  879. return;
  880. sta_ptr->tdls_cap.qos_info = pos[2];
  881. break;
  882. case WLAN_EID_VHT_OPERATION:
  883. if (priv->adapter->is_hw_11ac_capable) {
  884. if (ie_len !=
  885. sizeof(struct ieee80211_vht_operation))
  886. return;
  887. /* copy the ie's value into vhtoper*/
  888. memcpy(&sta_ptr->tdls_cap.vhtoper, pos + 2,
  889. sizeof(struct ieee80211_vht_operation));
  890. }
  891. break;
  892. case WLAN_EID_VHT_CAPABILITY:
  893. if (priv->adapter->is_hw_11ac_capable) {
  894. if (ie_len != sizeof(struct ieee80211_vht_cap))
  895. return;
  896. /* copy the ie's value into vhtcap*/
  897. memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos + 2,
  898. sizeof(struct ieee80211_vht_cap));
  899. sta_ptr->is_11ac_enabled = 1;
  900. }
  901. break;
  902. case WLAN_EID_AID:
  903. if (priv->adapter->is_hw_11ac_capable) {
  904. if (ie_len != sizeof(u16))
  905. return;
  906. sta_ptr->tdls_cap.aid =
  907. get_unaligned_le16((pos + 2));
  908. }
  909. break;
  910. default:
  911. break;
  912. }
  913. }
  914. return;
  915. }
  916. static int
  917. mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
  918. {
  919. struct mwifiex_sta_node *sta_ptr;
  920. struct mwifiex_ds_tdls_oper tdls_oper;
  921. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  922. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  923. if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
  924. mwifiex_dbg(priv->adapter, ERROR,
  925. "link absent for peer %pM; cannot config\n", peer);
  926. return -EINVAL;
  927. }
  928. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  929. tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
  930. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  931. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  932. }
  933. static int
  934. mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
  935. {
  936. struct mwifiex_sta_node *sta_ptr;
  937. struct mwifiex_ds_tdls_oper tdls_oper;
  938. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  939. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  940. if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
  941. mwifiex_dbg(priv->adapter, WARN,
  942. "Setup already in progress for peer %pM\n", peer);
  943. return 0;
  944. }
  945. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  946. if (!sta_ptr)
  947. return -ENOMEM;
  948. sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
  949. mwifiex_hold_tdls_packets(priv, peer);
  950. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  951. tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
  952. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  953. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  954. }
  955. static int
  956. mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
  957. {
  958. struct mwifiex_sta_node *sta_ptr;
  959. struct mwifiex_ds_tdls_oper tdls_oper;
  960. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  961. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  962. if (sta_ptr) {
  963. if (sta_ptr->is_11n_enabled) {
  964. mwifiex_11n_cleanup_reorder_tbl(priv);
  965. spin_lock_bh(&priv->wmm.ra_list_spinlock);
  966. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  967. spin_unlock_bh(&priv->wmm.ra_list_spinlock);
  968. }
  969. mwifiex_del_sta_entry(priv, peer);
  970. }
  971. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  972. mwifiex_auto_tdls_update_peer_status(priv, peer, TDLS_NOT_SETUP);
  973. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  974. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  975. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  976. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  977. }
  978. static int
  979. mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
  980. {
  981. struct mwifiex_sta_node *sta_ptr;
  982. struct ieee80211_mcs_info mcs;
  983. int i;
  984. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  985. if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
  986. mwifiex_dbg(priv->adapter, MSG,
  987. "tdls: enable link %pM success\n", peer);
  988. sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
  989. mcs = sta_ptr->tdls_cap.ht_capb.mcs;
  990. if (mcs.rx_mask[0] != 0xff)
  991. sta_ptr->is_11n_enabled = true;
  992. if (sta_ptr->is_11n_enabled) {
  993. if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
  994. IEEE80211_HT_CAP_MAX_AMSDU)
  995. sta_ptr->max_amsdu =
  996. MWIFIEX_TX_DATA_BUF_SIZE_8K;
  997. else
  998. sta_ptr->max_amsdu =
  999. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  1000. for (i = 0; i < MAX_NUM_TID; i++)
  1001. sta_ptr->ampdu_sta[i] =
  1002. priv->aggr_prio_tbl[i].ampdu_user;
  1003. } else {
  1004. for (i = 0; i < MAX_NUM_TID; i++)
  1005. sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  1006. }
  1007. if (sta_ptr->tdls_cap.extcap.ext_capab[3] &
  1008. WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) {
  1009. mwifiex_config_tdls_enable(priv);
  1010. mwifiex_config_tdls_cs_params(priv);
  1011. }
  1012. memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
  1013. mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
  1014. mwifiex_auto_tdls_update_peer_status(priv, peer,
  1015. TDLS_SETUP_COMPLETE);
  1016. } else {
  1017. mwifiex_dbg(priv->adapter, ERROR,
  1018. "tdls: enable link %pM failed\n", peer);
  1019. if (sta_ptr) {
  1020. mwifiex_11n_cleanup_reorder_tbl(priv);
  1021. spin_lock_bh(&priv->wmm.ra_list_spinlock);
  1022. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  1023. spin_unlock_bh(&priv->wmm.ra_list_spinlock);
  1024. mwifiex_del_sta_entry(priv, peer);
  1025. }
  1026. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  1027. mwifiex_auto_tdls_update_peer_status(priv, peer,
  1028. TDLS_NOT_SETUP);
  1029. return -1;
  1030. }
  1031. return 0;
  1032. }
  1033. int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
  1034. {
  1035. switch (action) {
  1036. case MWIFIEX_TDLS_ENABLE_LINK:
  1037. return mwifiex_tdls_process_enable_link(priv, peer);
  1038. case MWIFIEX_TDLS_DISABLE_LINK:
  1039. return mwifiex_tdls_process_disable_link(priv, peer);
  1040. case MWIFIEX_TDLS_CREATE_LINK:
  1041. return mwifiex_tdls_process_create_link(priv, peer);
  1042. case MWIFIEX_TDLS_CONFIG_LINK:
  1043. return mwifiex_tdls_process_config_link(priv, peer);
  1044. }
  1045. return 0;
  1046. }
  1047. int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
  1048. {
  1049. struct mwifiex_sta_node *sta_ptr;
  1050. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  1051. if (sta_ptr)
  1052. return sta_ptr->tdls_status;
  1053. return TDLS_NOT_SETUP;
  1054. }
  1055. int mwifiex_get_tdls_list(struct mwifiex_private *priv,
  1056. struct tdls_peer_info *buf)
  1057. {
  1058. struct mwifiex_sta_node *sta_ptr;
  1059. struct tdls_peer_info *peer = buf;
  1060. int count = 0;
  1061. if (!ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info))
  1062. return 0;
  1063. /* make sure we are in station mode and connected */
  1064. if (!(priv->bss_type == MWIFIEX_BSS_TYPE_STA && priv->media_connected))
  1065. return 0;
  1066. spin_lock_bh(&priv->sta_list_spinlock);
  1067. list_for_each_entry(sta_ptr, &priv->sta_list, list) {
  1068. if (mwifiex_is_tdls_link_setup(sta_ptr->tdls_status)) {
  1069. ether_addr_copy(peer->peer_addr, sta_ptr->mac_addr);
  1070. peer++;
  1071. count++;
  1072. if (count >= MWIFIEX_MAX_TDLS_PEER_SUPPORTED)
  1073. break;
  1074. }
  1075. }
  1076. spin_unlock_bh(&priv->sta_list_spinlock);
  1077. return count;
  1078. }
  1079. void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
  1080. {
  1081. struct mwifiex_sta_node *sta_ptr;
  1082. struct mwifiex_ds_tdls_oper tdls_oper;
  1083. if (list_empty(&priv->sta_list))
  1084. return;
  1085. list_for_each_entry(sta_ptr, &priv->sta_list, list) {
  1086. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  1087. if (sta_ptr->is_11n_enabled) {
  1088. mwifiex_11n_cleanup_reorder_tbl(priv);
  1089. spin_lock_bh(&priv->wmm.ra_list_spinlock);
  1090. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  1091. spin_unlock_bh(&priv->wmm.ra_list_spinlock);
  1092. }
  1093. mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
  1094. TDLS_LINK_TEARDOWN);
  1095. memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
  1096. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  1097. if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  1098. HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
  1099. mwifiex_dbg(priv->adapter, ERROR,
  1100. "Disable link failed for TDLS peer %pM",
  1101. sta_ptr->mac_addr);
  1102. }
  1103. mwifiex_del_all_sta_list(priv);
  1104. }
  1105. int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb)
  1106. {
  1107. struct mwifiex_auto_tdls_peer *peer;
  1108. u8 mac[ETH_ALEN];
  1109. ether_addr_copy(mac, skb->data);
  1110. spin_lock_bh(&priv->auto_tdls_lock);
  1111. list_for_each_entry(peer, &priv->auto_tdls_list, list) {
  1112. if (!memcmp(mac, peer->mac_addr, ETH_ALEN)) {
  1113. if (peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
  1114. peer->tdls_status == TDLS_NOT_SETUP &&
  1115. (peer->failure_count <
  1116. MWIFIEX_TDLS_MAX_FAIL_COUNT)) {
  1117. peer->tdls_status = TDLS_SETUP_INPROGRESS;
  1118. mwifiex_dbg(priv->adapter, INFO,
  1119. "setup TDLS link, peer=%pM rssi=%d\n",
  1120. peer->mac_addr, peer->rssi);
  1121. cfg80211_tdls_oper_request(priv->netdev,
  1122. peer->mac_addr,
  1123. NL80211_TDLS_SETUP,
  1124. 0, GFP_ATOMIC);
  1125. peer->do_setup = false;
  1126. priv->check_tdls_tx = false;
  1127. } else if (peer->failure_count <
  1128. MWIFIEX_TDLS_MAX_FAIL_COUNT &&
  1129. peer->do_discover) {
  1130. mwifiex_send_tdls_data_frame(priv,
  1131. peer->mac_addr,
  1132. WLAN_TDLS_DISCOVERY_REQUEST,
  1133. 1, 0, NULL, 0);
  1134. peer->do_discover = false;
  1135. }
  1136. }
  1137. }
  1138. spin_unlock_bh(&priv->auto_tdls_lock);
  1139. return 0;
  1140. }
  1141. void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv)
  1142. {
  1143. struct mwifiex_auto_tdls_peer *peer, *tmp_node;
  1144. spin_lock_bh(&priv->auto_tdls_lock);
  1145. list_for_each_entry_safe(peer, tmp_node, &priv->auto_tdls_list, list) {
  1146. list_del(&peer->list);
  1147. kfree(peer);
  1148. }
  1149. INIT_LIST_HEAD(&priv->auto_tdls_list);
  1150. spin_unlock_bh(&priv->auto_tdls_lock);
  1151. priv->check_tdls_tx = false;
  1152. }
  1153. void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac)
  1154. {
  1155. struct mwifiex_auto_tdls_peer *tdls_peer;
  1156. if (!priv->adapter->auto_tdls)
  1157. return;
  1158. spin_lock_bh(&priv->auto_tdls_lock);
  1159. list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
  1160. if (!memcmp(tdls_peer->mac_addr, mac, ETH_ALEN)) {
  1161. tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
  1162. tdls_peer->rssi_jiffies = jiffies;
  1163. spin_unlock_bh(&priv->auto_tdls_lock);
  1164. return;
  1165. }
  1166. }
  1167. /* create new TDLS peer */
  1168. tdls_peer = kzalloc(sizeof(*tdls_peer), GFP_ATOMIC);
  1169. if (tdls_peer) {
  1170. ether_addr_copy(tdls_peer->mac_addr, mac);
  1171. tdls_peer->tdls_status = TDLS_SETUP_INPROGRESS;
  1172. tdls_peer->rssi_jiffies = jiffies;
  1173. INIT_LIST_HEAD(&tdls_peer->list);
  1174. list_add_tail(&tdls_peer->list, &priv->auto_tdls_list);
  1175. mwifiex_dbg(priv->adapter, INFO,
  1176. "Add auto TDLS peer= %pM to list\n", mac);
  1177. }
  1178. spin_unlock_bh(&priv->auto_tdls_lock);
  1179. }
  1180. void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
  1181. const u8 *mac, u8 link_status)
  1182. {
  1183. struct mwifiex_auto_tdls_peer *peer;
  1184. if (!priv->adapter->auto_tdls)
  1185. return;
  1186. spin_lock_bh(&priv->auto_tdls_lock);
  1187. list_for_each_entry(peer, &priv->auto_tdls_list, list) {
  1188. if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
  1189. if ((link_status == TDLS_NOT_SETUP) &&
  1190. (peer->tdls_status == TDLS_SETUP_INPROGRESS))
  1191. peer->failure_count++;
  1192. else if (mwifiex_is_tdls_link_setup(link_status))
  1193. peer->failure_count = 0;
  1194. peer->tdls_status = link_status;
  1195. break;
  1196. }
  1197. }
  1198. spin_unlock_bh(&priv->auto_tdls_lock);
  1199. }
  1200. void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
  1201. u8 *mac, s8 snr, s8 nflr)
  1202. {
  1203. struct mwifiex_auto_tdls_peer *peer;
  1204. if (!priv->adapter->auto_tdls)
  1205. return;
  1206. spin_lock_bh(&priv->auto_tdls_lock);
  1207. list_for_each_entry(peer, &priv->auto_tdls_list, list) {
  1208. if (!memcmp(peer->mac_addr, mac, ETH_ALEN)) {
  1209. peer->rssi = nflr - snr;
  1210. peer->rssi_jiffies = jiffies;
  1211. break;
  1212. }
  1213. }
  1214. spin_unlock_bh(&priv->auto_tdls_lock);
  1215. }
  1216. void mwifiex_check_auto_tdls(struct timer_list *t)
  1217. {
  1218. struct mwifiex_private *priv = from_timer(priv, t, auto_tdls_timer);
  1219. struct mwifiex_auto_tdls_peer *tdls_peer;
  1220. u16 reason = WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED;
  1221. if (WARN_ON_ONCE(!priv || !priv->adapter)) {
  1222. pr_err("mwifiex: %s: adapter or private structure is NULL\n",
  1223. __func__);
  1224. return;
  1225. }
  1226. if (unlikely(!priv->adapter->auto_tdls))
  1227. return;
  1228. if (!priv->auto_tdls_timer_active) {
  1229. mwifiex_dbg(priv->adapter, INFO,
  1230. "auto TDLS timer inactive; return");
  1231. return;
  1232. }
  1233. priv->check_tdls_tx = false;
  1234. spin_lock_bh(&priv->auto_tdls_lock);
  1235. list_for_each_entry(tdls_peer, &priv->auto_tdls_list, list) {
  1236. if ((jiffies - tdls_peer->rssi_jiffies) >
  1237. (MWIFIEX_AUTO_TDLS_IDLE_TIME * HZ)) {
  1238. tdls_peer->rssi = 0;
  1239. tdls_peer->do_discover = true;
  1240. priv->check_tdls_tx = true;
  1241. }
  1242. if (((tdls_peer->rssi >= MWIFIEX_TDLS_RSSI_LOW) ||
  1243. !tdls_peer->rssi) &&
  1244. mwifiex_is_tdls_link_setup(tdls_peer->tdls_status)) {
  1245. tdls_peer->tdls_status = TDLS_LINK_TEARDOWN;
  1246. mwifiex_dbg(priv->adapter, MSG,
  1247. "teardown TDLS link,peer=%pM rssi=%d\n",
  1248. tdls_peer->mac_addr, -tdls_peer->rssi);
  1249. tdls_peer->do_discover = true;
  1250. priv->check_tdls_tx = true;
  1251. cfg80211_tdls_oper_request(priv->netdev,
  1252. tdls_peer->mac_addr,
  1253. NL80211_TDLS_TEARDOWN,
  1254. reason, GFP_ATOMIC);
  1255. } else if (tdls_peer->rssi &&
  1256. tdls_peer->rssi <= MWIFIEX_TDLS_RSSI_HIGH &&
  1257. tdls_peer->tdls_status == TDLS_NOT_SETUP &&
  1258. tdls_peer->failure_count <
  1259. MWIFIEX_TDLS_MAX_FAIL_COUNT) {
  1260. priv->check_tdls_tx = true;
  1261. tdls_peer->do_setup = true;
  1262. mwifiex_dbg(priv->adapter, INFO,
  1263. "check TDLS with peer=%pM\t"
  1264. "rssi=%d\n", tdls_peer->mac_addr,
  1265. tdls_peer->rssi);
  1266. }
  1267. }
  1268. spin_unlock_bh(&priv->auto_tdls_lock);
  1269. mod_timer(&priv->auto_tdls_timer,
  1270. jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
  1271. }
  1272. void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv)
  1273. {
  1274. timer_setup(&priv->auto_tdls_timer, mwifiex_check_auto_tdls, 0);
  1275. priv->auto_tdls_timer_active = true;
  1276. mod_timer(&priv->auto_tdls_timer,
  1277. jiffies + msecs_to_jiffies(MWIFIEX_TIMER_10S));
  1278. }
  1279. void mwifiex_clean_auto_tdls(struct mwifiex_private *priv)
  1280. {
  1281. if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
  1282. priv->adapter->auto_tdls &&
  1283. priv->bss_type == MWIFIEX_BSS_TYPE_STA) {
  1284. priv->auto_tdls_timer_active = false;
  1285. del_timer(&priv->auto_tdls_timer);
  1286. mwifiex_flush_auto_tdls_list(priv);
  1287. }
  1288. }
  1289. static int mwifiex_config_tdls(struct mwifiex_private *priv, u8 enable)
  1290. {
  1291. struct mwifiex_tdls_config config;
  1292. config.enable = cpu_to_le16(enable);
  1293. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
  1294. ACT_TDLS_CS_ENABLE_CONFIG, 0, &config, true);
  1295. }
  1296. int mwifiex_config_tdls_enable(struct mwifiex_private *priv)
  1297. {
  1298. return mwifiex_config_tdls(priv, true);
  1299. }
  1300. int mwifiex_config_tdls_disable(struct mwifiex_private *priv)
  1301. {
  1302. return mwifiex_config_tdls(priv, false);
  1303. }
  1304. int mwifiex_config_tdls_cs_params(struct mwifiex_private *priv)
  1305. {
  1306. struct mwifiex_tdls_config_cs_params config_tdls_cs_params;
  1307. config_tdls_cs_params.unit_time = MWIFIEX_DEF_CS_UNIT_TIME;
  1308. config_tdls_cs_params.thr_otherlink = MWIFIEX_DEF_CS_THR_OTHERLINK;
  1309. config_tdls_cs_params.thr_directlink = MWIFIEX_DEF_THR_DIRECTLINK;
  1310. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
  1311. ACT_TDLS_CS_PARAMS, 0,
  1312. &config_tdls_cs_params, true);
  1313. }
  1314. int mwifiex_stop_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac)
  1315. {
  1316. struct mwifiex_tdls_stop_cs_params stop_tdls_cs_params;
  1317. ether_addr_copy(stop_tdls_cs_params.peer_mac, peer_mac);
  1318. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
  1319. ACT_TDLS_CS_STOP, 0,
  1320. &stop_tdls_cs_params, true);
  1321. }
  1322. int mwifiex_start_tdls_cs(struct mwifiex_private *priv, const u8 *peer_mac,
  1323. u8 primary_chan, u8 second_chan_offset, u8 band)
  1324. {
  1325. struct mwifiex_tdls_init_cs_params start_tdls_cs_params;
  1326. ether_addr_copy(start_tdls_cs_params.peer_mac, peer_mac);
  1327. start_tdls_cs_params.primary_chan = primary_chan;
  1328. start_tdls_cs_params.second_chan_offset = second_chan_offset;
  1329. start_tdls_cs_params.band = band;
  1330. start_tdls_cs_params.switch_time = cpu_to_le16(MWIFIEX_DEF_CS_TIME);
  1331. start_tdls_cs_params.switch_timeout =
  1332. cpu_to_le16(MWIFIEX_DEF_CS_TIMEOUT);
  1333. start_tdls_cs_params.reg_class = MWIFIEX_DEF_CS_REG_CLASS;
  1334. start_tdls_cs_params.periodicity = MWIFIEX_DEF_CS_PERIODICITY;
  1335. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_CONFIG,
  1336. ACT_TDLS_CS_INIT, 0,
  1337. &start_tdls_cs_params, true);
  1338. }