tdls.c 39 KB

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