tdls.c 40 KB

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