tdls.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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. struct timeval tv;
  454. int ret;
  455. u16 skb_len;
  456. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  457. max(sizeof(struct ieee80211_mgmt),
  458. sizeof(struct ieee80211_tdls_data)) +
  459. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  460. MWIFIEX_SUPPORTED_RATES +
  461. 3 + /* Qos Info */
  462. sizeof(struct ieee_types_extcap) +
  463. sizeof(struct ieee80211_ht_cap) +
  464. sizeof(struct ieee_types_bss_co_2040) +
  465. sizeof(struct ieee80211_ht_operation) +
  466. sizeof(struct ieee80211_tdls_lnkie) +
  467. extra_ies_len;
  468. if (priv->adapter->is_hw_11ac_capable)
  469. skb_len += sizeof(struct ieee_types_vht_cap) +
  470. sizeof(struct ieee_types_vht_oper) +
  471. sizeof(struct ieee_types_aid);
  472. skb = dev_alloc_skb(skb_len);
  473. if (!skb) {
  474. dev_err(priv->adapter->dev,
  475. "allocate skb failed for management frame\n");
  476. return -ENOMEM;
  477. }
  478. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  479. switch (action_code) {
  480. case WLAN_TDLS_SETUP_REQUEST:
  481. case WLAN_TDLS_SETUP_CONFIRM:
  482. case WLAN_TDLS_TEARDOWN:
  483. case WLAN_TDLS_DISCOVERY_REQUEST:
  484. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  485. dialog_token, status_code,
  486. skb);
  487. if (ret) {
  488. dev_kfree_skb_any(skb);
  489. return ret;
  490. }
  491. if (extra_ies_len)
  492. memcpy(skb_put(skb, extra_ies_len), extra_ies,
  493. extra_ies_len);
  494. mwifiex_tdls_add_link_ie(skb, priv->curr_addr, peer,
  495. priv->cfg_bssid);
  496. break;
  497. case WLAN_TDLS_SETUP_RESPONSE:
  498. ret = mwifiex_prep_tdls_encap_data(priv, peer, action_code,
  499. dialog_token, status_code,
  500. skb);
  501. if (ret) {
  502. dev_kfree_skb_any(skb);
  503. return ret;
  504. }
  505. if (extra_ies_len)
  506. memcpy(skb_put(skb, extra_ies_len), extra_ies,
  507. extra_ies_len);
  508. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  509. priv->cfg_bssid);
  510. break;
  511. }
  512. switch (action_code) {
  513. case WLAN_TDLS_SETUP_REQUEST:
  514. case WLAN_TDLS_SETUP_RESPONSE:
  515. skb->priority = MWIFIEX_PRIO_BK;
  516. break;
  517. default:
  518. skb->priority = MWIFIEX_PRIO_VI;
  519. break;
  520. }
  521. tx_info = MWIFIEX_SKB_TXCB(skb);
  522. memset(tx_info, 0, sizeof(*tx_info));
  523. tx_info->bss_num = priv->bss_num;
  524. tx_info->bss_type = priv->bss_type;
  525. do_gettimeofday(&tv);
  526. skb->tstamp = timeval_to_ktime(tv);
  527. mwifiex_queue_tx_pkt(priv, skb);
  528. return 0;
  529. }
  530. static int
  531. mwifiex_construct_tdls_action_frame(struct mwifiex_private *priv,
  532. const u8 *peer,
  533. u8 action_code, u8 dialog_token,
  534. u16 status_code, struct sk_buff *skb)
  535. {
  536. struct ieee80211_mgmt *mgmt;
  537. u8 bc_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  538. int ret;
  539. u16 capab;
  540. struct ieee80211_ht_cap *ht_cap;
  541. u8 radio, *pos;
  542. capab = priv->curr_bss_params.bss_descriptor.cap_info_bitmap;
  543. mgmt = (void *)skb_put(skb, offsetof(struct ieee80211_mgmt, u));
  544. memset(mgmt, 0, 24);
  545. memcpy(mgmt->da, peer, ETH_ALEN);
  546. memcpy(mgmt->sa, priv->curr_addr, ETH_ALEN);
  547. memcpy(mgmt->bssid, priv->cfg_bssid, ETH_ALEN);
  548. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  549. IEEE80211_STYPE_ACTION);
  550. /* add address 4 */
  551. pos = skb_put(skb, ETH_ALEN);
  552. switch (action_code) {
  553. case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
  554. skb_put(skb, sizeof(mgmt->u.action.u.tdls_discover_resp) + 1);
  555. mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
  556. mgmt->u.action.u.tdls_discover_resp.action_code =
  557. WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
  558. mgmt->u.action.u.tdls_discover_resp.dialog_token =
  559. dialog_token;
  560. mgmt->u.action.u.tdls_discover_resp.capability =
  561. cpu_to_le16(capab);
  562. /* move back for addr4 */
  563. memmove(pos + ETH_ALEN, &mgmt->u.action.category,
  564. sizeof(mgmt->u.action.u.tdls_discover_resp));
  565. /* init address 4 */
  566. memcpy(pos, bc_addr, ETH_ALEN);
  567. ret = mwifiex_tdls_append_rates_ie(priv, skb);
  568. if (ret) {
  569. dev_kfree_skb_any(skb);
  570. return ret;
  571. }
  572. pos = (void *)skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  573. *pos++ = WLAN_EID_HT_CAPABILITY;
  574. *pos++ = sizeof(struct ieee80211_ht_cap);
  575. ht_cap = (void *)pos;
  576. radio = mwifiex_band_to_radio_type(priv->curr_bss_params.band);
  577. ret = mwifiex_fill_cap_info(priv, radio, ht_cap);
  578. if (ret) {
  579. dev_kfree_skb_any(skb);
  580. return ret;
  581. }
  582. if (priv->adapter->is_hw_11ac_capable) {
  583. ret = mwifiex_tdls_add_vht_capab(priv, skb);
  584. if (ret) {
  585. dev_kfree_skb_any(skb);
  586. return ret;
  587. }
  588. mwifiex_tdls_add_aid(priv, skb);
  589. }
  590. mwifiex_tdls_add_ext_capab(priv, skb);
  591. mwifiex_tdls_add_qos_capab(skb);
  592. break;
  593. default:
  594. dev_err(priv->adapter->dev, "Unknown TDLS action frame type\n");
  595. return -EINVAL;
  596. }
  597. return 0;
  598. }
  599. int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
  600. u8 action_code, u8 dialog_token,
  601. u16 status_code, const u8 *extra_ies,
  602. size_t extra_ies_len)
  603. {
  604. struct sk_buff *skb;
  605. struct mwifiex_txinfo *tx_info;
  606. struct timeval tv;
  607. u8 *pos;
  608. u32 pkt_type, tx_control;
  609. u16 pkt_len, skb_len;
  610. skb_len = MWIFIEX_MIN_DATA_HEADER_LEN +
  611. max(sizeof(struct ieee80211_mgmt),
  612. sizeof(struct ieee80211_tdls_data)) +
  613. MWIFIEX_MGMT_FRAME_HEADER_SIZE +
  614. MWIFIEX_SUPPORTED_RATES +
  615. sizeof(struct ieee_types_extcap) +
  616. sizeof(struct ieee80211_ht_cap) +
  617. sizeof(struct ieee_types_bss_co_2040) +
  618. sizeof(struct ieee80211_ht_operation) +
  619. sizeof(struct ieee80211_tdls_lnkie) +
  620. extra_ies_len +
  621. 3 + /* Qos Info */
  622. ETH_ALEN; /* Address4 */
  623. if (priv->adapter->is_hw_11ac_capable)
  624. skb_len += sizeof(struct ieee_types_vht_cap) +
  625. sizeof(struct ieee_types_vht_oper) +
  626. sizeof(struct ieee_types_aid);
  627. skb = dev_alloc_skb(skb_len);
  628. if (!skb) {
  629. dev_err(priv->adapter->dev,
  630. "allocate skb failed for management frame\n");
  631. return -ENOMEM;
  632. }
  633. skb_reserve(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
  634. pkt_type = PKT_TYPE_MGMT;
  635. tx_control = 0;
  636. pos = skb_put(skb, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  637. memset(pos, 0, MWIFIEX_MGMT_FRAME_HEADER_SIZE + sizeof(pkt_len));
  638. memcpy(pos, &pkt_type, sizeof(pkt_type));
  639. memcpy(pos + sizeof(pkt_type), &tx_control, sizeof(tx_control));
  640. if (mwifiex_construct_tdls_action_frame(priv, peer, action_code,
  641. dialog_token, status_code,
  642. skb)) {
  643. dev_kfree_skb_any(skb);
  644. return -EINVAL;
  645. }
  646. if (extra_ies_len)
  647. memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
  648. /* the TDLS link IE is always added last we are the responder */
  649. mwifiex_tdls_add_link_ie(skb, peer, priv->curr_addr,
  650. priv->cfg_bssid);
  651. skb->priority = MWIFIEX_PRIO_VI;
  652. tx_info = MWIFIEX_SKB_TXCB(skb);
  653. memset(tx_info, 0, sizeof(*tx_info));
  654. tx_info->bss_num = priv->bss_num;
  655. tx_info->bss_type = priv->bss_type;
  656. tx_info->flags |= MWIFIEX_BUF_FLAG_TDLS_PKT;
  657. pkt_len = skb->len - MWIFIEX_MGMT_FRAME_HEADER_SIZE - sizeof(pkt_len);
  658. memcpy(skb->data + MWIFIEX_MGMT_FRAME_HEADER_SIZE, &pkt_len,
  659. sizeof(pkt_len));
  660. do_gettimeofday(&tv);
  661. skb->tstamp = timeval_to_ktime(tv);
  662. mwifiex_queue_tx_pkt(priv, skb);
  663. return 0;
  664. }
  665. /* This function process tdls action frame from peer.
  666. * Peer capabilities are stored into station node structure.
  667. */
  668. void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
  669. u8 *buf, int len)
  670. {
  671. struct mwifiex_sta_node *sta_ptr;
  672. u8 *peer, *pos, *end;
  673. u8 i, action, basic;
  674. int ie_len = 0;
  675. if (len < (sizeof(struct ethhdr) + 3))
  676. return;
  677. if (*(buf + sizeof(struct ethhdr)) != WLAN_TDLS_SNAP_RFTYPE)
  678. return;
  679. if (*(buf + sizeof(struct ethhdr) + 1) != WLAN_CATEGORY_TDLS)
  680. return;
  681. peer = buf + ETH_ALEN;
  682. action = *(buf + sizeof(struct ethhdr) + 2);
  683. /* just handle TDLS setup request/response/confirm */
  684. if (action > WLAN_TDLS_SETUP_CONFIRM)
  685. return;
  686. dev_dbg(priv->adapter->dev,
  687. "rx:tdls action: peer=%pM, action=%d\n", peer, action);
  688. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  689. if (!sta_ptr)
  690. return;
  691. switch (action) {
  692. case WLAN_TDLS_SETUP_REQUEST:
  693. if (len < (sizeof(struct ethhdr) + TDLS_REQ_FIX_LEN))
  694. return;
  695. pos = buf + sizeof(struct ethhdr) + 4;
  696. /* payload 1+ category 1 + action 1 + dialog 1 */
  697. sta_ptr->tdls_cap.capab = cpu_to_le16(*(u16 *)pos);
  698. ie_len = len - sizeof(struct ethhdr) - TDLS_REQ_FIX_LEN;
  699. pos += 2;
  700. break;
  701. case WLAN_TDLS_SETUP_RESPONSE:
  702. if (len < (sizeof(struct ethhdr) + TDLS_RESP_FIX_LEN))
  703. return;
  704. /* payload 1+ category 1 + action 1 + dialog 1 + status code 2*/
  705. pos = buf + sizeof(struct ethhdr) + 6;
  706. sta_ptr->tdls_cap.capab = cpu_to_le16(*(u16 *)pos);
  707. ie_len = len - sizeof(struct ethhdr) - TDLS_RESP_FIX_LEN;
  708. pos += 2;
  709. break;
  710. case WLAN_TDLS_SETUP_CONFIRM:
  711. if (len < (sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN))
  712. return;
  713. pos = buf + sizeof(struct ethhdr) + TDLS_CONFIRM_FIX_LEN;
  714. ie_len = len - sizeof(struct ethhdr) - TDLS_CONFIRM_FIX_LEN;
  715. break;
  716. default:
  717. dev_warn(priv->adapter->dev, "Unknown TDLS frame type.\n");
  718. return;
  719. }
  720. for (end = pos + ie_len; pos + 1 < end; pos += 2 + pos[1]) {
  721. if (pos + 2 + pos[1] > end)
  722. break;
  723. switch (*pos) {
  724. case WLAN_EID_SUPP_RATES:
  725. sta_ptr->tdls_cap.rates_len = pos[1];
  726. for (i = 0; i < pos[1]; i++)
  727. sta_ptr->tdls_cap.rates[i] = pos[i + 2];
  728. break;
  729. case WLAN_EID_EXT_SUPP_RATES:
  730. basic = sta_ptr->tdls_cap.rates_len;
  731. for (i = 0; i < pos[1]; i++)
  732. sta_ptr->tdls_cap.rates[basic + i] = pos[i + 2];
  733. sta_ptr->tdls_cap.rates_len += pos[1];
  734. break;
  735. case WLAN_EID_HT_CAPABILITY:
  736. memcpy((u8 *)&sta_ptr->tdls_cap.ht_capb, pos,
  737. sizeof(struct ieee80211_ht_cap));
  738. sta_ptr->is_11n_enabled = 1;
  739. break;
  740. case WLAN_EID_HT_OPERATION:
  741. memcpy(&sta_ptr->tdls_cap.ht_oper, pos,
  742. sizeof(struct ieee80211_ht_operation));
  743. break;
  744. case WLAN_EID_BSS_COEX_2040:
  745. sta_ptr->tdls_cap.coex_2040 = pos[2];
  746. break;
  747. case WLAN_EID_EXT_CAPABILITY:
  748. memcpy((u8 *)&sta_ptr->tdls_cap.extcap, pos,
  749. sizeof(struct ieee_types_header) +
  750. min_t(u8, pos[1], 8));
  751. break;
  752. case WLAN_EID_RSN:
  753. memcpy((u8 *)&sta_ptr->tdls_cap.rsn_ie, pos,
  754. sizeof(struct ieee_types_header) + pos[1]);
  755. break;
  756. case WLAN_EID_QOS_CAPA:
  757. sta_ptr->tdls_cap.qos_info = pos[2];
  758. break;
  759. case WLAN_EID_VHT_OPERATION:
  760. if (priv->adapter->is_hw_11ac_capable)
  761. memcpy(&sta_ptr->tdls_cap.vhtoper, pos,
  762. sizeof(struct ieee80211_vht_operation));
  763. break;
  764. case WLAN_EID_VHT_CAPABILITY:
  765. if (priv->adapter->is_hw_11ac_capable) {
  766. memcpy((u8 *)&sta_ptr->tdls_cap.vhtcap, pos,
  767. sizeof(struct ieee80211_vht_cap));
  768. sta_ptr->is_11ac_enabled = 1;
  769. }
  770. break;
  771. case WLAN_EID_AID:
  772. if (priv->adapter->is_hw_11ac_capable)
  773. sta_ptr->tdls_cap.aid =
  774. le16_to_cpu(*(__le16 *)(pos + 2));
  775. default:
  776. break;
  777. }
  778. }
  779. return;
  780. }
  781. static int
  782. mwifiex_tdls_process_config_link(struct mwifiex_private *priv, const u8 *peer)
  783. {
  784. struct mwifiex_sta_node *sta_ptr;
  785. struct mwifiex_ds_tdls_oper tdls_oper;
  786. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  787. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  788. if (!sta_ptr || sta_ptr->tdls_status == TDLS_SETUP_FAILURE) {
  789. dev_err(priv->adapter->dev,
  790. "link absent for peer %pM; cannot config\n", peer);
  791. return -EINVAL;
  792. }
  793. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  794. tdls_oper.tdls_action = MWIFIEX_TDLS_CONFIG_LINK;
  795. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  796. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  797. }
  798. static int
  799. mwifiex_tdls_process_create_link(struct mwifiex_private *priv, const u8 *peer)
  800. {
  801. struct mwifiex_sta_node *sta_ptr;
  802. struct mwifiex_ds_tdls_oper tdls_oper;
  803. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  804. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  805. if (sta_ptr && sta_ptr->tdls_status == TDLS_SETUP_INPROGRESS) {
  806. dev_dbg(priv->adapter->dev,
  807. "Setup already in progress for peer %pM\n", peer);
  808. return 0;
  809. }
  810. sta_ptr = mwifiex_add_sta_entry(priv, peer);
  811. if (!sta_ptr)
  812. return -ENOMEM;
  813. sta_ptr->tdls_status = TDLS_SETUP_INPROGRESS;
  814. mwifiex_hold_tdls_packets(priv, peer);
  815. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  816. tdls_oper.tdls_action = MWIFIEX_TDLS_CREATE_LINK;
  817. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  818. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  819. }
  820. static int
  821. mwifiex_tdls_process_disable_link(struct mwifiex_private *priv, const u8 *peer)
  822. {
  823. struct mwifiex_sta_node *sta_ptr;
  824. struct mwifiex_ds_tdls_oper tdls_oper;
  825. unsigned long flags;
  826. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  827. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  828. if (sta_ptr) {
  829. if (sta_ptr->is_11n_enabled) {
  830. mwifiex_11n_cleanup_reorder_tbl(priv);
  831. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  832. flags);
  833. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  834. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  835. flags);
  836. }
  837. mwifiex_del_sta_entry(priv, peer);
  838. }
  839. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  840. memcpy(&tdls_oper.peer_mac, peer, ETH_ALEN);
  841. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  842. return mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  843. HostCmd_ACT_GEN_SET, 0, &tdls_oper, true);
  844. }
  845. static int
  846. mwifiex_tdls_process_enable_link(struct mwifiex_private *priv, const u8 *peer)
  847. {
  848. struct mwifiex_sta_node *sta_ptr;
  849. struct ieee80211_mcs_info mcs;
  850. unsigned long flags;
  851. int i;
  852. sta_ptr = mwifiex_get_sta_entry(priv, peer);
  853. if (sta_ptr && (sta_ptr->tdls_status != TDLS_SETUP_FAILURE)) {
  854. dev_dbg(priv->adapter->dev,
  855. "tdls: enable link %pM success\n", peer);
  856. sta_ptr->tdls_status = TDLS_SETUP_COMPLETE;
  857. mcs = sta_ptr->tdls_cap.ht_capb.mcs;
  858. if (mcs.rx_mask[0] != 0xff)
  859. sta_ptr->is_11n_enabled = true;
  860. if (sta_ptr->is_11n_enabled) {
  861. if (le16_to_cpu(sta_ptr->tdls_cap.ht_capb.cap_info) &
  862. IEEE80211_HT_CAP_MAX_AMSDU)
  863. sta_ptr->max_amsdu =
  864. MWIFIEX_TX_DATA_BUF_SIZE_8K;
  865. else
  866. sta_ptr->max_amsdu =
  867. MWIFIEX_TX_DATA_BUF_SIZE_4K;
  868. for (i = 0; i < MAX_NUM_TID; i++)
  869. sta_ptr->ampdu_sta[i] =
  870. priv->aggr_prio_tbl[i].ampdu_user;
  871. } else {
  872. for (i = 0; i < MAX_NUM_TID; i++)
  873. sta_ptr->ampdu_sta[i] = BA_STREAM_NOT_ALLOWED;
  874. }
  875. memset(sta_ptr->rx_seq, 0xff, sizeof(sta_ptr->rx_seq));
  876. mwifiex_restore_tdls_packets(priv, peer, TDLS_SETUP_COMPLETE);
  877. } else {
  878. dev_dbg(priv->adapter->dev,
  879. "tdls: enable link %pM failed\n", peer);
  880. if (sta_ptr) {
  881. mwifiex_11n_cleanup_reorder_tbl(priv);
  882. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  883. flags);
  884. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  885. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  886. flags);
  887. mwifiex_del_sta_entry(priv, peer);
  888. }
  889. mwifiex_restore_tdls_packets(priv, peer, TDLS_LINK_TEARDOWN);
  890. return -1;
  891. }
  892. return 0;
  893. }
  894. int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action)
  895. {
  896. switch (action) {
  897. case MWIFIEX_TDLS_ENABLE_LINK:
  898. return mwifiex_tdls_process_enable_link(priv, peer);
  899. case MWIFIEX_TDLS_DISABLE_LINK:
  900. return mwifiex_tdls_process_disable_link(priv, peer);
  901. case MWIFIEX_TDLS_CREATE_LINK:
  902. return mwifiex_tdls_process_create_link(priv, peer);
  903. case MWIFIEX_TDLS_CONFIG_LINK:
  904. return mwifiex_tdls_process_config_link(priv, peer);
  905. }
  906. return 0;
  907. }
  908. int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac)
  909. {
  910. struct mwifiex_sta_node *sta_ptr;
  911. sta_ptr = mwifiex_get_sta_entry(priv, mac);
  912. if (sta_ptr)
  913. return sta_ptr->tdls_status;
  914. return TDLS_NOT_SETUP;
  915. }
  916. void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv)
  917. {
  918. struct mwifiex_sta_node *sta_ptr;
  919. struct mwifiex_ds_tdls_oper tdls_oper;
  920. unsigned long flags;
  921. if (list_empty(&priv->sta_list))
  922. return;
  923. list_for_each_entry(sta_ptr, &priv->sta_list, list) {
  924. memset(&tdls_oper, 0, sizeof(struct mwifiex_ds_tdls_oper));
  925. if (sta_ptr->is_11n_enabled) {
  926. mwifiex_11n_cleanup_reorder_tbl(priv);
  927. spin_lock_irqsave(&priv->wmm.ra_list_spinlock,
  928. flags);
  929. mwifiex_11n_delete_all_tx_ba_stream_tbl(priv);
  930. spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock,
  931. flags);
  932. }
  933. mwifiex_restore_tdls_packets(priv, sta_ptr->mac_addr,
  934. TDLS_LINK_TEARDOWN);
  935. memcpy(&tdls_oper.peer_mac, sta_ptr->mac_addr, ETH_ALEN);
  936. tdls_oper.tdls_action = MWIFIEX_TDLS_DISABLE_LINK;
  937. if (mwifiex_send_cmd(priv, HostCmd_CMD_TDLS_OPER,
  938. HostCmd_ACT_GEN_SET, 0, &tdls_oper, false))
  939. dev_warn(priv->adapter->dev,
  940. "Disable link failed for TDLS peer %pM",
  941. sta_ptr->mac_addr);
  942. }
  943. mwifiex_del_all_sta_list(priv);
  944. }