tdls.c 44 KB

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