tdls.c 44 KB

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