tdls.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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. static void mwifiex_restore_tdls_packets(struct mwifiex_private *priv,
  26. const u8 *mac, u8 status)
  27. {
  28. struct mwifiex_ra_list_tbl *ra_list;
  29. struct list_head *tid_list;
  30. struct sk_buff *skb, *tmp;
  31. struct mwifiex_txinfo *tx_info;
  32. unsigned long flags;
  33. u32 tid;
  34. u8 tid_down;
  35. dev_dbg(priv->adapter->dev, "%s: %pM\n", __func__, mac);
  36. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  37. skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
  38. if (!ether_addr_equal(mac, skb->data))
  39. continue;
  40. __skb_unlink(skb, &priv->tdls_txq);
  41. tx_info = MWIFIEX_SKB_TXCB(skb);
  42. tid = skb->priority;
  43. tid_down = mwifiex_wmm_downgrade_tid(priv, tid);
  44. if (status == TDLS_SETUP_COMPLETE) {
  45. ra_list = mwifiex_wmm_get_queue_raptr(priv, tid, mac);
  46. ra_list->tdls_link = true;
  47. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  48. } else {
  49. tid_list = &priv->wmm.tid_tbl_ptr[tid_down].ra_list;
  50. if (!list_empty(tid_list))
  51. ra_list = list_first_entry(tid_list,
  52. struct mwifiex_ra_list_tbl, list);
  53. else
  54. ra_list = NULL;
  55. tx_info->flags &= ~MWIFIEX_BUF_FLAG_TDLS_PKT;
  56. }
  57. if (!ra_list) {
  58. mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
  59. continue;
  60. }
  61. skb_queue_tail(&ra_list->skb_head, skb);
  62. ra_list->ba_pkt_count++;
  63. ra_list->total_pkt_count++;
  64. if (atomic_read(&priv->wmm.highest_queued_prio) <
  65. tos_to_tid_inv[tid_down])
  66. atomic_set(&priv->wmm.highest_queued_prio,
  67. tos_to_tid_inv[tid_down]);
  68. atomic_inc(&priv->wmm.tx_pkts_queued);
  69. }
  70. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  71. return;
  72. }
  73. static void mwifiex_hold_tdls_packets(struct mwifiex_private *priv,
  74. const u8 *mac)
  75. {
  76. struct mwifiex_ra_list_tbl *ra_list;
  77. struct list_head *ra_list_head;
  78. struct sk_buff *skb, *tmp;
  79. unsigned long flags;
  80. int i;
  81. dev_dbg(priv->adapter->dev, "%s: %pM\n", __func__, mac);
  82. spin_lock_irqsave(&priv->wmm.ra_list_spinlock, flags);
  83. for (i = 0; i < MAX_NUM_TID; i++) {
  84. if (!list_empty(&priv->wmm.tid_tbl_ptr[i].ra_list)) {
  85. ra_list_head = &priv->wmm.tid_tbl_ptr[i].ra_list;
  86. list_for_each_entry(ra_list, ra_list_head, list) {
  87. skb_queue_walk_safe(&ra_list->skb_head, skb,
  88. tmp) {
  89. if (!ether_addr_equal(mac, skb->data))
  90. continue;
  91. __skb_unlink(skb, &ra_list->skb_head);
  92. atomic_dec(&priv->wmm.tx_pkts_queued);
  93. ra_list->total_pkt_count--;
  94. skb_queue_tail(&priv->tdls_txq, skb);
  95. }
  96. }
  97. }
  98. }
  99. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
  100. return;
  101. }
  102. /* This function appends rate TLV to scan config command. */
  103. static int
  104. mwifiex_tdls_append_rates_ie(struct mwifiex_private *priv,
  105. struct sk_buff *skb)
  106. {
  107. u8 rates[MWIFIEX_SUPPORTED_RATES], *pos;
  108. u16 rates_size, supp_rates_size, ext_rates_size;
  109. memset(rates, 0, sizeof(rates));
  110. rates_size = mwifiex_get_supported_rates(priv, rates);
  111. supp_rates_size = min_t(u16, rates_size, MWIFIEX_TDLS_SUPPORTED_RATES);
  112. if (skb_tailroom(skb) < rates_size + 4) {
  113. dev_err(priv->adapter->dev,
  114. "Insuffient space while adding rates\n");
  115. return -ENOMEM;
  116. }
  117. pos = skb_put(skb, supp_rates_size + 2);
  118. *pos++ = WLAN_EID_SUPP_RATES;
  119. *pos++ = supp_rates_size;
  120. memcpy(pos, rates, supp_rates_size);
  121. if (rates_size > MWIFIEX_TDLS_SUPPORTED_RATES) {
  122. ext_rates_size = rates_size - MWIFIEX_TDLS_SUPPORTED_RATES;
  123. pos = skb_put(skb, ext_rates_size + 2);
  124. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  125. *pos++ = ext_rates_size;
  126. memcpy(pos, rates + MWIFIEX_TDLS_SUPPORTED_RATES,
  127. ext_rates_size);
  128. }
  129. return 0;
  130. }
  131. static void mwifiex_tdls_add_aid(struct mwifiex_private *priv,
  132. struct sk_buff *skb)
  133. {
  134. struct ieee_types_assoc_rsp *assoc_rsp;
  135. u8 *pos;
  136. assoc_rsp = (struct ieee_types_assoc_rsp *)&priv->assoc_rsp_buf;
  137. pos = (void *)skb_put(skb, 4);
  138. *pos++ = WLAN_EID_AID;
  139. *pos++ = 2;
  140. *pos++ = le16_to_cpu(assoc_rsp->a_id);
  141. return;
  142. }
  143. static int mwifiex_tdls_add_vht_capab(struct mwifiex_private *priv,
  144. struct sk_buff *skb)
  145. {
  146. struct ieee80211_vht_cap vht_cap;
  147. u8 *pos;
  148. pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  149. *pos++ = WLAN_EID_VHT_CAPABILITY;
  150. *pos++ = sizeof(struct ieee80211_vht_cap);
  151. memset(&vht_cap, 0, sizeof(struct ieee80211_vht_cap));
  152. mwifiex_fill_vht_cap_tlv(priv, &vht_cap, priv->curr_bss_params.band);
  153. memcpy(pos, &vht_cap, sizeof(vht_cap));
  154. return 0;
  155. }
  156. static int
  157. mwifiex_tdls_add_ht_oper(struct mwifiex_private *priv, const u8 *mac,
  158. u8 vht_enabled, struct sk_buff *skb)
  159. {
  160. struct ieee80211_ht_operation *ht_oper;
  161. struct mwifiex_sta_node *sta_ptr;
  162. struct mwifiex_bssdescriptor *bss_desc =
  163. &priv->curr_bss_params.bss_descriptor;
  164. u8 *pos;
  165. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  166. if (unlikely(!sta_ptr)) {
  167. dev_warn(priv->adapter->dev,
  168. "TDLS peer station not found in list\n");
  169. return -1;
  170. }
  171. pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_operation) + 2);
  172. *pos++ = WLAN_EID_HT_OPERATION;
  173. *pos++ = sizeof(struct ieee80211_ht_operation);
  174. ht_oper = (void *)pos;
  175. ht_oper->primary_chan = bss_desc->channel;
  176. /* follow AP's channel bandwidth */
  177. if (ISSUPP_CHANWIDTH40(priv->adapter->hw_dot_11n_dev_cap) &&
  178. bss_desc->bcn_ht_cap &&
  179. ISALLOWED_CHANWIDTH40(bss_desc->bcn_ht_oper->ht_param))
  180. ht_oper->ht_param = bss_desc->bcn_ht_oper->ht_param;
  181. if (vht_enabled) {
  182. ht_oper->ht_param =
  183. mwifiex_get_sec_chan_offset(bss_desc->channel);
  184. ht_oper->ht_param |= BIT(2);
  185. }
  186. memcpy(&sta_ptr->tdls_cap.ht_oper, ht_oper,
  187. sizeof(struct ieee80211_ht_operation));
  188. return 0;
  189. }
  190. static int mwifiex_tdls_add_vht_oper(struct mwifiex_private *priv,
  191. const u8 *mac, struct sk_buff *skb)
  192. {
  193. struct mwifiex_bssdescriptor *bss_desc;
  194. struct ieee80211_vht_operation *vht_oper;
  195. struct ieee80211_vht_cap *vht_cap, *ap_vht_cap = NULL;
  196. struct mwifiex_sta_node *sta_ptr;
  197. struct mwifiex_adapter *adapter = priv->adapter;
  198. u8 supp_chwd_set, peer_supp_chwd_set;
  199. u8 *pos, ap_supp_chwd_set, chan_bw;
  200. u16 mcs_map_user, mcs_map_resp, mcs_map_result;
  201. u16 mcs_user, mcs_resp, nss;
  202. u32 usr_vht_cap_info;
  203. bss_desc = &priv->curr_bss_params.bss_descriptor;
  204. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  205. if (unlikely(!sta_ptr)) {
  206. dev_warn(adapter->dev, "TDLS peer station not found in list\n");
  207. return -1;
  208. }
  209. if (!mwifiex_is_bss_in_11ac_mode(priv)) {
  210. if (sta_ptr->tdls_cap.extcap.ext_capab[7] &
  211. WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
  212. dev_dbg(adapter->dev,
  213. "TDLS peer doesn't support wider bandwitdh\n");
  214. return 0;
  215. }
  216. } else {
  217. ap_vht_cap = bss_desc->bcn_vht_cap;
  218. }
  219. pos = (void *)skb_put(skb, sizeof(struct ieee80211_vht_operation) + 2);
  220. *pos++ = WLAN_EID_VHT_OPERATION;
  221. *pos++ = sizeof(struct ieee80211_vht_operation);
  222. vht_oper = (struct ieee80211_vht_operation *)pos;
  223. if (bss_desc->bss_band & BAND_A)
  224. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_a;
  225. else
  226. usr_vht_cap_info = adapter->usr_dot_11ac_dev_cap_bg;
  227. /* find the minmum bandwith between AP/TDLS peers */
  228. vht_cap = &sta_ptr->tdls_cap.vhtcap;
  229. supp_chwd_set = GET_VHTCAP_CHWDSET(usr_vht_cap_info);
  230. peer_supp_chwd_set =
  231. GET_VHTCAP_CHWDSET(le32_to_cpu(vht_cap->vht_cap_info));
  232. supp_chwd_set = min_t(u8, supp_chwd_set, peer_supp_chwd_set);
  233. /* We need check AP's bandwidth when TDLS_WIDER_BANDWIDTH is off */
  234. if (ap_vht_cap && sta_ptr->tdls_cap.extcap.ext_capab[7] &
  235. WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) {
  236. ap_supp_chwd_set =
  237. GET_VHTCAP_CHWDSET(le32_to_cpu(ap_vht_cap->vht_cap_info));
  238. supp_chwd_set = min_t(u8, supp_chwd_set, ap_supp_chwd_set);
  239. }
  240. switch (supp_chwd_set) {
  241. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  242. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  243. break;
  244. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  245. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_160MHZ;
  246. break;
  247. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  248. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80P80MHZ;
  249. break;
  250. default:
  251. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
  252. break;
  253. }
  254. mcs_map_user = GET_DEVRXMCSMAP(adapter->usr_dot_11ac_mcs_support);
  255. mcs_map_resp = le16_to_cpu(vht_cap->supp_mcs.rx_mcs_map);
  256. mcs_map_result = 0;
  257. for (nss = 1; nss <= 8; nss++) {
  258. mcs_user = GET_VHTNSSMCS(mcs_map_user, nss);
  259. mcs_resp = GET_VHTNSSMCS(mcs_map_resp, nss);
  260. if ((mcs_user == IEEE80211_VHT_MCS_NOT_SUPPORTED) ||
  261. (mcs_resp == IEEE80211_VHT_MCS_NOT_SUPPORTED))
  262. SET_VHTNSSMCS(mcs_map_result, nss,
  263. IEEE80211_VHT_MCS_NOT_SUPPORTED);
  264. else
  265. SET_VHTNSSMCS(mcs_map_result, nss,
  266. min_t(u16, mcs_user, mcs_resp));
  267. }
  268. vht_oper->basic_mcs_set = cpu_to_le16(mcs_map_result);
  269. switch (vht_oper->chan_width) {
  270. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  271. chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
  272. break;
  273. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  274. chan_bw = IEEE80211_VHT_CHANWIDTH_160MHZ;
  275. break;
  276. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  277. chan_bw = IEEE80211_VHT_CHANWIDTH_80MHZ;
  278. break;
  279. default:
  280. chan_bw = IEEE80211_VHT_CHANWIDTH_USE_HT;
  281. break;
  282. }
  283. vht_oper->center_freq_seg1_idx =
  284. mwifiex_get_center_freq_index(priv, BAND_AAC,
  285. bss_desc->channel,
  286. chan_bw);
  287. return 0;
  288. }
  289. static void mwifiex_tdls_add_ext_capab(struct mwifiex_private *priv,
  290. struct sk_buff *skb)
  291. {
  292. struct ieee_types_extcap *extcap;
  293. extcap = (void *)skb_put(skb, sizeof(struct ieee_types_extcap));
  294. extcap->ieee_hdr.element_id = WLAN_EID_EXT_CAPABILITY;
  295. extcap->ieee_hdr.len = 8;
  296. memset(extcap->ext_capab, 0, 8);
  297. extcap->ext_capab[4] |= WLAN_EXT_CAPA5_TDLS_ENABLED;
  298. if (priv->adapter->is_hw_11ac_capable)
  299. extcap->ext_capab[7] |= WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED;
  300. }
  301. static void mwifiex_tdls_add_qos_capab(struct sk_buff *skb)
  302. {
  303. u8 *pos = (void *)skb_put(skb, 3);
  304. *pos++ = WLAN_EID_QOS_CAPA;
  305. *pos++ = 1;
  306. *pos++ = MWIFIEX_TDLS_DEF_QOS_CAPAB;
  307. }
  308. static int mwifiex_prep_tdls_encap_data(struct mwifiex_private *priv,
  309. const u8 *peer, u8 action_code,
  310. u8 dialog_token,
  311. u16 status_code, struct sk_buff *skb)
  312. {
  313. struct ieee80211_tdls_data *tf;
  314. int ret;
  315. u16 capab;
  316. struct ieee80211_ht_cap *ht_cap;
  317. u8 radio, *pos;
  318. capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
  319. tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
  320. memcpy(tf->da, peer, ETH_ALEN);
  321. memcpy(tf->sa, priv->curr_addr, ETH_ALEN);
  322. tf->ether_type = cpu_to_be16(ETH_P_TDLS);
  323. tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
  324. switch (action_code) {
  325. case WLAN_TDLS_SETUP_REQUEST:
  326. tf->category = WLAN_CATEGORY_TDLS;
  327. tf->action_code = WLAN_TDLS_SETUP_REQUEST;
  328. skb_put(skb, sizeof(tf->u.setup_req));
  329. tf->u.setup_req.dialog_token = dialog_token;
  330. tf->u.setup_req.capability = cpu_to_le16(capab);
  331. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  332. if (ret) {
  333. dev_kfree_skb_any(skb);
  334. return ret;
  335. }
  336. pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  337. *pos++ = WLAN_EID_HT_CAPABILITY;
  338. *pos++ = sizeof(struct ieee80211_ht_cap);
  339. ht_cap = (void *)pos;
  340. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  341. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  342. if (ret) {
  343. dev_kfree_skb_any(skb);
  344. return ret;
  345. }
  346. if (priv->adapter->is_hw_11ac_capable) {
  347. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  348. if (ret) {
  349. dev_kfree_skb_any(skb);
  350. return ret;
  351. }
  352. mwifiex_tdls_add_aid(priv, skb);
  353. }
  354. mwifiex_tdls_add_ext_capab(priv, skb);
  355. mwifiex_tdls_add_qos_capab(skb);
  356. break;
  357. case WLAN_TDLS_SETUP_RESPONSE:
  358. tf->category = WLAN_CATEGORY_TDLS;
  359. tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
  360. skb_put(skb, sizeof(tf->u.setup_resp));
  361. tf->u.setup_resp.status_code = cpu_to_le16(status_code);
  362. tf->u.setup_resp.dialog_token = dialog_token;
  363. tf->u.setup_resp.capability = cpu_to_le16(capab);
  364. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  365. if (ret) {
  366. dev_kfree_skb_any(skb);
  367. return ret;
  368. }
  369. pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  370. *pos++ = WLAN_EID_HT_CAPABILITY;
  371. *pos++ = sizeof(struct ieee80211_ht_cap);
  372. ht_cap = (void *)pos;
  373. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  374. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  375. if (ret) {
  376. dev_kfree_skb_any(skb);
  377. return ret;
  378. }
  379. if (priv->adapter->is_hw_11ac_capable) {
  380. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  381. if (ret) {
  382. dev_kfree_skb_any(skb);
  383. return ret;
  384. }
  385. mwifiex_tdls_add_aid(priv, skb);
  386. }
  387. mwifiex_tdls_add_ext_capab(priv, skb);
  388. mwifiex_tdls_add_qos_capab(skb);
  389. break;
  390. case WLAN_TDLS_SETUP_CONFIRM:
  391. tf->category = WLAN_CATEGORY_TDLS;
  392. tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
  393. skb_put(skb, sizeof(tf->u.setup_cfm));
  394. tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
  395. tf->u.setup_cfm.dialog_token = dialog_token;
  396. if (priv->adapter->is_hw_11ac_capable) {
  397. ret = mwifiex_tdls_add_vht_oper(priv, peer, skb);
  398. if (ret) {
  399. dev_kfree_skb_any(skb);
  400. return ret;
  401. }
  402. ret = mwifiex_tdls_add_ht_oper(priv, peer, 1, skb);
  403. if (ret) {
  404. dev_kfree_skb_any(skb);
  405. return ret;
  406. }
  407. } else {
  408. ret = mwifiex_tdls_add_ht_oper(priv, peer, 0, skb);
  409. if (ret) {
  410. dev_kfree_skb_any(skb);
  411. return ret;
  412. }
  413. }
  414. break;
  415. case WLAN_TDLS_TEARDOWN:
  416. tf->category = WLAN_CATEGORY_TDLS;
  417. tf->action_code = WLAN_TDLS_TEARDOWN;
  418. skb_put(skb, sizeof(tf->u.teardown));
  419. tf->u.teardown.reason_code = cpu_to_le16(status_code);
  420. break;
  421. case WLAN_TDLS_DISCOVERY_REQUEST:
  422. tf->category = WLAN_CATEGORY_TDLS;
  423. tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
  424. skb_put(skb, sizeof(tf->u.discover_req));
  425. tf->u.discover_req.dialog_token = dialog_token;
  426. break;
  427. default:
  428. dev_err(priv->adapter->dev, "Unknown TDLS frame type.\n");
  429. return -EINVAL;
  430. }
  431. return 0;
  432. }
  433. static void
  434. mwifiex_tdls_add_link_ie(struct sk_buff *skb, const u8 *src_addr,
  435. const u8 *peer, const u8 *bssid)
  436. {
  437. struct ieee80211_tdls_lnkie *lnkid;
  438. lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
  439. lnkid->ie_type = WLAN_EID_LINK_ID;
  440. lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) -
  441. sizeof(struct ieee_types_header);
  442. memcpy(lnkid->bssid, bssid, ETH_ALEN);
  443. memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
  444. memcpy(lnkid->resp_sta, peer, ETH_ALEN);
  445. }
  446. int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
  447. u8 action_code, u8 dialog_token,
  448. u16 status_code, const u8 *extra_ies,
  449. size_t extra_ies_len)
  450. {
  451. struct sk_buff *skb;
  452. struct mwifiex_txinfo *tx_info;
  453. int ret;
  454. u16 skb_len;
  455. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  456. max(sizeof(struct ieee80211_mgmt),
  457. sizeof(struct ieee80211_tdls_data)) +
  458. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  459. MWIFIEX_SUPPORTED_RATES +
  460. 3 + /* Qos Info */
  461. sizeof(struct ieee_types_extcap) +
  462. sizeof(struct ieee80211_ht_cap) +
  463. sizeof(struct ieee_types_bss_co_2040) +
  464. sizeof(struct ieee80211_ht_operation) +
  465. sizeof(struct ieee80211_tdls_lnkie) +
  466. extra_ies_len;
  467. if (priv->adapter->is_hw_11ac_capable)
  468. skb_len += sizeof(struct ieee_types_vht_cap) +
  469. sizeof(struct ieee_types_vht_oper) +
  470. sizeof(struct ieee_types_aid);
  471. skb = dev_alloc_skb(skb_len);
  472. if (!skb) {
  473. dev_err(priv->adapter->dev,
  474. "allocate skb failed for management frame\n");
  475. return -ENOMEM;
  476. }
  477. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  478. switch (action_code) {
  479. case WLAN_TDLS_SETUP_REQUEST:
  480. case WLAN_TDLS_SETUP_CONFIRM:
  481. case WLAN_TDLS_TEARDOWN:
  482. case WLAN_TDLS_DISCOVERY_REQUEST:
  483. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  484. dialog_token, status_code,
  485. skb);
  486. if (ret) {
  487. dev_kfree_skb_any(skb);
  488. return ret;
  489. }
  490. if (extra_ies_len)
  491. memcpy(skb_put(skb, extra_ies_len), extra_ies,
  492. extra_ies_len);
  493. mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
  494. priv->cfg_bssid);
  495. break;
  496. case WLAN_TDLS_SETUP_RESPONSE:
  497. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  498. dialog_token, status_code,
  499. skb);
  500. if (ret) {
  501. dev_kfree_skb_any(skb);
  502. return ret;
  503. }
  504. if (extra_ies_len)
  505. memcpy(skb_put(skb, extra_ies_len), extra_ies,
  506. extra_ies_len);
  507. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  508. priv->cfg_bssid);
  509. break;
  510. }
  511. switch (action_code) {
  512. case WLAN_TDLS_SETUP_REQUEST:
  513. case WLAN_TDLS_SETUP_RESPONSE:
  514. skb->priority = MWIFIEX_PRIO_BK;
  515. break;
  516. default:
  517. skb->priority = MWIFIEX_PRIO_VI;
  518. break;
  519. }
  520. tx_info = MWIFIEX_SKB_TXCB(skb);
  521. memset(tx_info, 0, sizeof(*tx_info));
  522. tx_info->bss_num = priv->bss_num;
  523. tx_info->bss_type = priv->bss_type;
  524. __net_timestamp(skb);
  525. mwifiex_queue_tx_pkt(priv, skb);
  526. return 0;
  527. }
  528. static int
  529. mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
  530. const u8 *peer,
  531. u8 action_code, u8 dialog_token,
  532. u16 status_code, struct sk_buff *skb)
  533. {
  534. struct ieee80211_mgmt *mgmt;
  535. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  536. int ret;
  537. u16 capab;
  538. struct ieee80211_ht_cap *ht_cap;
  539. u8 radio, *pos;
  540. capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
  541. mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
  542. memset(mgmt, 0, 24);
  543. memcpy(mgmt->da, peer, ETH_ALEN);
  544. memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
  545. memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
  546. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  547. IEEE80211_STYPE_ACTION);
  548. /* add address 4 */
  549. pos = skb_put(skb, ETH_ALEN);
  550. switch (action_code) {
  551. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  552. skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
  553. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  554. mgmt->u.action.u.tdls_discover_resp.action_code =
  555. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  556. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  557. dialog_token;
  558. mgmt->u.action.u.tdls_discover_resp.capability =
  559. cpu_to_le16(capab);
  560. /* move back for addr4 */
  561. memmove(pos + ETH_ALEN, &mgmt->u.action.category,
  562. sizeof(mgmt->u.action.u.tdls_discover_resp));
  563. /* init address 4 */
  564. memcpy(pos, bc_addr, ETH_ALEN);
  565. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  566. if (ret) {
  567. dev_kfree_skb_any(skb);
  568. return ret;
  569. }
  570. pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  571. *pos++ = WLAN_EID_HT_CAPABILITY;
  572. *pos++ = sizeof(struct ieee80211_ht_cap);
  573. ht_cap = (void *)pos;
  574. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  575. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  576. if (ret) {
  577. dev_kfree_skb_any(skb);
  578. return ret;
  579. }
  580. if (priv->adapter->is_hw_11ac_capable) {
  581. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  582. if (ret) {
  583. dev_kfree_skb_any(skb);
  584. return ret;
  585. }
  586. mwifiex_tdls_add_aid(priv, skb);
  587. }
  588. mwifiex_tdls_add_ext_capab(priv, skb);
  589. mwifiex_tdls_add_qos_capab(skb);
  590. break;
  591. default:
  592. dev_err(priv->adapter->dev, "Unknown TDLS action frame type\n");
  593. return -EINVAL;
  594. }
  595. return 0;
  596. }
  597. int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
  598. u8 action_code, u8 dialog_token,
  599. u16 status_code, const u8 *extra_ies,
  600. size_t extra_ies_len)
  601. {
  602. struct sk_buff *skb;
  603. struct mwifiex_txinfo *tx_info;
  604. u8 *pos;
  605. u32 pkt_type, tx_control;
  606. u16 pkt_len, skb_len;
  607. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  608. max(sizeof(struct ieee80211_mgmt),
  609. sizeof(struct ieee80211_tdls_data)) +
  610. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  611. MWIFIEX_SUPPORTED_RATES +
  612. sizeof(struct ieee_types_extcap) +
  613. sizeof(struct ieee80211_ht_cap) +
  614. sizeof(struct ieee_types_bss_co_2040) +
  615. sizeof(struct ieee80211_ht_operation) +
  616. sizeof(struct ieee80211_tdls_lnkie) +
  617. extra_ies_len +
  618. 3 + /* Qos Info */
  619. ETH_ALEN; /* Address4 */
  620. if (priv->adapter->is_hw_11ac_capable)
  621. skb_len += sizeof(struct ieee_types_vht_cap) +
  622. sizeof(struct ieee_types_vht_oper) +
  623. sizeof(struct ieee_types_aid);
  624. skb = dev_alloc_skb(skb_len);
  625. if (!skb) {
  626. dev_err(priv->adapter->dev,
  627. "allocate skb failed for management frame\n");
  628. return -ENOMEM;
  629. }
  630. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  631. pkt_type = PKT_TYPE_MGMT;
  632. tx_control = 0;
  633. pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  634. memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  635. memcpy(pos, &pkt_type, sizeof(pkt_type));
  636. memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
  637. if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
  638. dialog_token, status_code,
  639. skb)) {
  640. dev_kfree_skb_any(skb);
  641. return -EINVAL;
  642. }
  643. if (extra_ies_len)
  644. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  645. /* the TDLS link IE is always added last we are the responder */
  646. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  647. priv->cfg_bssid);
  648. skb->priority = MWIFIEX_PRIO_VI;
  649. tx_info = MWIFIEX_SKB_TXCB(skb);
  650. memset(tx_info, 0, sizeof(*tx_info));
  651. tx_info->bss_num = priv->bss_num;
  652. tx_info->bss_type = priv->bss_type;
  653. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  654. pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
  655. memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
  656. sizeof(pkt_len));
  657. __net_timestamp(skb);
  658. mwifiex_queue_tx_pkt(priv, skb);
  659. return 0;
  660. }
  661. /* This function process tdls action frame from peer.
  662. * Peer capabilities are stored into station node structure.
  663. */
  664. void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
  665. u8 *buf, int len)
  666. {
  667. struct mwifiex_sta_node *sta_ptr;
  668. u8 *peer, *pos, *end;
  669. u8 i, action, basic;
  670. __le16 cap = 0;
  671. int ie_len = 0;
  672. if (len < (sizeof(struct ethhdr) + 3))
  673. return;
  674. if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
  675. return;
  676. if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
  677. return;
  678. peer = buf + ETH_ALEN;
  679. action = *(buf + sizeof(struct ethhdr) + 2);
  680. dev_dbg(priv->adapter->dev,
  681. "rx:tdls action: peer=%pM, action=%d\n", peer, action);
  682. switch (action) {
  683. case WLAN_TDLS_SETUP_REQUEST:
  684. if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
  685. return;
  686. pos = buf + sizeof(struct ethhdr) + 4;
  687. /* payload 1+ category 1 + action 1 + dialog 1 */
  688. cap = cpu_to_le16(*(u16 *)pos);
  689. ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
  690. pos += 2;
  691. break;
  692. case WLAN_TDLS_SETUP_RESPONSE:
  693. if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
  694. return;
  695. /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
  696. pos = buf + sizeof(struct ethhdr) + 6;
  697. cap = cpu_to_le16(*(u16 *)pos);
  698. ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
  699. pos += 2;
  700. break;
  701. case WLAN_TDLS_SETUP_CONFIRM:
  702. if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
  703. return;
  704. pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
  705. ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
  706. break;
  707. default:
  708. dev_dbg(priv->adapter->dev, "Unknown TDLS frame type.\n");
  709. return;
  710. }
  711. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  712. if (!sta_ptr)
  713. return;
  714. sta_ptr->tdls_cap.capab = cap;
  715. for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
  716. if (pos + 2 + pos[1] > end)
  717. break;
  718. switch (*pos) {
  719. case WLAN_EID_SUPP_RATES:
  720. sta_ptr->tdls_cap.rates_len = pos[1];
  721. for (i = 0; i < pos[1]; i++)
  722. sta_ptr->tdls_cap.rates[i] = pos[i + 2];
  723. break;
  724. case WLAN_EID_EXT_SUPP_RATES:
  725. basic = sta_ptr->tdls_cap.rates_len;
  726. for (i = 0; i < pos[1]; i++)
  727. sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
  728. sta_ptr->tdls_cap.rates_len += pos[1];
  729. break;
  730. case WLAN_EID_HT_CAPABILITY:
  731. memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,
  732. sizeof(struct ieee80211_ht_cap));
  733. sta_ptr->is_11n_enabled = 1;
  734. break;
  735. case WLAN_EID_HT_OPERATION:
  736. memcpy(&sta_ptr->tdls_cap.ht_oper, pos,
  737. sizeof(struct ieee80211_ht_operation));
  738. break;
  739. case WLAN_EID_BSS_COEX_2040:
  740. sta_ptr->tdls_cap.coex_2040 = pos[2];
  741. break;
  742. case WLAN_EID_EXT_CAPABILITY:
  743. memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
  744. sizeof(struct ieee_types_header) +
  745. min_t(u8, pos[1], 8));
  746. break;
  747. case WLAN_EID_RSN:
  748. memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
  749. sizeof(struct ieee_types_header) +
  750. min_t(u8, pos[1], IEEE_MAX_IE_SIZE -
  751. sizeof(struct ieee_types_header)));
  752. break;
  753. case WLAN_EID_QOS_CAPA:
  754. sta_ptr->tdls_cap.qos_info = pos[2];
  755. break;
  756. case WLAN_EID_VHT_OPERATION:
  757. if (priv->adapter->is_hw_11ac_capable)
  758. memcpy(&sta_ptr->tdls_cap.vhtoper, pos,
  759. sizeof(struct ieee80211_vht_operation));
  760. break;
  761. case WLAN_EID_VHT_CAPABILITY:
  762. if (priv->adapter->is_hw_11ac_capable) {
  763. memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos,
  764. sizeof(struct ieee80211_vht_cap));
  765. sta_ptr->is_11ac_enabled = 1;
  766. }
  767. break;
  768. case WLAN_EID_AID:
  769. if (priv->adapter->is_hw_11ac_capable)
  770. sta_ptr->tdls_cap.aid =
  771. le16_to_cpu(*(__le16 *)(pos + 2));
  772. default:
  773. break;
  774. }
  775. }
  776. return;
  777. }
  778. static int
  779. mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
  780. {
  781. struct mwifiex_sta_node *sta_ptr;
  782. struct mwifiex_ds_tdls_oper tdls_oper;
  783. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  784. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  785. if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
  786. dev_err(priv->adapter->dev,
  787. "link absent for peer %pM; cannot config\n", peer);
  788. return -EINVAL;
  789. }
  790. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  791. tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
  792. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  793. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  794. }
  795. static int
  796. mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
  797. {
  798. struct mwifiex_sta_node *sta_ptr;
  799. struct mwifiex_ds_tdls_oper tdls_oper;
  800. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  801. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  802. if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
  803. dev_dbg(priv->adapter->dev,
  804. "Setup already in progress for peer %pM\n", peer);
  805. return 0;
  806. }
  807. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  808. if (!sta_ptr)
  809. return -ENOMEM;
  810. sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
  811. mwifiex_hold_tdls_packets(priv, peer);
  812. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  813. tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
  814. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  815. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  816. }
  817. static int
  818. mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
  819. {
  820. struct mwifiex_sta_node *sta_ptr;
  821. struct mwifiex_ds_tdls_oper tdls_oper;
  822. unsigned long flags;
  823. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  824. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  825. if (sta_ptr) {
  826. if (sta_ptr->is_11n_enabled) {
  827. mwifiex_11n_cleanup_reorder_tbl(priv);
  828. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  829. flags);
  830. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  831. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  832. flags);
  833. }
  834. mwifiex_del_sta_entry(priv, peer);
  835. }
  836. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  837. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  838. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  839. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  840. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  841. }
  842. static int
  843. mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
  844. {
  845. struct mwifiex_sta_node *sta_ptr;
  846. struct ieee80211_mcs_info mcs;
  847. unsigned long flags;
  848. int i;
  849. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  850. if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
  851. dev_dbg(priv->adapter->dev,
  852. "tdls: enable link %pM success\n", peer);
  853. sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
  854. mcs = sta_ptr->tdls_cap.ht_capb.mcs;
  855. if (mcs.rx_mask[0] != 0xff)
  856. sta_ptr->is_11n_enabled = true;
  857. if (sta_ptr->is_11n_enabled) {
  858. if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
  859. IEEE80211_HT_CAP_MAX_AMSDU)
  860. sta_ptr->max_amsdu =
  861. MWIFIEX_TX_DATA_BUF_SIZE_8K;
  862. else
  863. sta_ptr->max_amsdu =
  864. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  865. for (i = 0; i < MAX_NUM_TID; i++)
  866. sta_ptr->ampdu_sta[i] =
  867. priv->aggr_prio_tbl[i].ampdu_user;
  868. } else {
  869. for (i = 0; i < MAX_NUM_TID; i++)
  870. sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  871. }
  872. memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
  873. mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
  874. } else {
  875. dev_dbg(priv->adapter->dev,
  876. "tdls: enable link %pM failed\n", peer);
  877. if (sta_ptr) {
  878. mwifiex_11n_cleanup_reorder_tbl(priv);
  879. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  880. flags);
  881. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  882. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  883. flags);
  884. mwifiex_del_sta_entry(priv, peer);
  885. }
  886. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  887. return -1;
  888. }
  889. return 0;
  890. }
  891. int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
  892. {
  893. switch (action) {
  894. case MWIFIEX_TDLS_ENABLE_LINK:
  895. return mwifiex_tdls_process_enable_link(priv, peer);
  896. case MWIFIEX_TDLS_DISABLE_LINK:
  897. return mwifiex_tdls_process_disable_link(priv, peer);
  898. case MWIFIEX_TDLS_CREATE_LINK:
  899. return mwifiex_tdls_process_create_link(priv, peer);
  900. case MWIFIEX_TDLS_CONFIG_LINK:
  901. return mwifiex_tdls_process_config_link(priv, peer);
  902. }
  903. return 0;
  904. }
  905. int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
  906. {
  907. struct mwifiex_sta_node *sta_ptr;
  908. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  909. if (sta_ptr)
  910. return sta_ptr->tdls_status;
  911. return TDLS_NOT_SETUP;
  912. }
  913. void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
  914. {
  915. struct mwifiex_sta_node *sta_ptr;
  916. struct mwifiex_ds_tdls_oper tdls_oper;
  917. unsigned long flags;
  918. if (list_empty(&priv->sta_list))
  919. return;
  920. list_for_each_entry(sta_ptr, &priv->sta_list, list) {
  921. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  922. if (sta_ptr->is_11n_enabled) {
  923. mwifiex_11n_cleanup_reorder_tbl(priv);
  924. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  925. flags);
  926. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  927. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  928. flags);
  929. }
  930. mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
  931. TDLS_LINK_TEARDOWN);
  932. memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
  933. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  934. if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  935. HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
  936. dev_warn(priv->adapter->dev,
  937. "Disable link failed for TDLS peer %pM",
  938. sta_ptr->mac_addr);
  939. }
  940. mwifiex_del_all_sta_list(priv);
  941. }