cfg80211.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * Copyright (c) 2012-2012 Quantenna Communications, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/ieee80211.h>
  20. #include <net/cfg80211.h>
  21. #include <net/netlink.h>
  22. #include "cfg80211.h"
  23. #include "commands.h"
  24. #include "core.h"
  25. #include "util.h"
  26. #include "bus.h"
  27. /* Supported rates to be advertised to the cfg80211 */
  28. static struct ieee80211_rate qtnf_rates_2g[] = {
  29. {.bitrate = 10, .hw_value = 2, },
  30. {.bitrate = 20, .hw_value = 4, },
  31. {.bitrate = 55, .hw_value = 11, },
  32. {.bitrate = 110, .hw_value = 22, },
  33. {.bitrate = 60, .hw_value = 12, },
  34. {.bitrate = 90, .hw_value = 18, },
  35. {.bitrate = 120, .hw_value = 24, },
  36. {.bitrate = 180, .hw_value = 36, },
  37. {.bitrate = 240, .hw_value = 48, },
  38. {.bitrate = 360, .hw_value = 72, },
  39. {.bitrate = 480, .hw_value = 96, },
  40. {.bitrate = 540, .hw_value = 108, },
  41. };
  42. /* Supported rates to be advertised to the cfg80211 */
  43. static struct ieee80211_rate qtnf_rates_5g[] = {
  44. {.bitrate = 60, .hw_value = 12, },
  45. {.bitrate = 90, .hw_value = 18, },
  46. {.bitrate = 120, .hw_value = 24, },
  47. {.bitrate = 180, .hw_value = 36, },
  48. {.bitrate = 240, .hw_value = 48, },
  49. {.bitrate = 360, .hw_value = 72, },
  50. {.bitrate = 480, .hw_value = 96, },
  51. {.bitrate = 540, .hw_value = 108, },
  52. };
  53. /* Supported crypto cipher suits to be advertised to cfg80211 */
  54. static const u32 qtnf_cipher_suites[] = {
  55. WLAN_CIPHER_SUITE_TKIP,
  56. WLAN_CIPHER_SUITE_CCMP,
  57. WLAN_CIPHER_SUITE_AES_CMAC,
  58. };
  59. /* Supported mgmt frame types to be advertised to cfg80211 */
  60. static const struct ieee80211_txrx_stypes
  61. qtnf_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  62. [NL80211_IFTYPE_STATION] = {
  63. .tx = BIT(IEEE80211_STYPE_ACTION >> 4),
  64. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  65. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  66. },
  67. [NL80211_IFTYPE_AP] = {
  68. .tx = BIT(IEEE80211_STYPE_ACTION >> 4),
  69. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  70. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  71. BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  72. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  73. BIT(IEEE80211_STYPE_AUTH >> 4),
  74. },
  75. };
  76. static int
  77. qtnf_validate_iface_combinations(struct wiphy *wiphy,
  78. struct qtnf_vif *change_vif,
  79. enum nl80211_iftype new_type)
  80. {
  81. struct qtnf_wmac *mac;
  82. struct qtnf_vif *vif;
  83. int i;
  84. int ret = 0;
  85. struct iface_combination_params params = {
  86. .num_different_channels = 1,
  87. };
  88. mac = wiphy_priv(wiphy);
  89. if (!mac)
  90. return -EFAULT;
  91. for (i = 0; i < QTNF_MAX_INTF; i++) {
  92. vif = &mac->iflist[i];
  93. if (vif->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
  94. params.iftype_num[vif->wdev.iftype]++;
  95. }
  96. if (change_vif) {
  97. params.iftype_num[new_type]++;
  98. params.iftype_num[change_vif->wdev.iftype]--;
  99. } else {
  100. params.iftype_num[new_type]++;
  101. }
  102. ret = cfg80211_check_combinations(wiphy, &params);
  103. return ret;
  104. }
  105. static int
  106. qtnf_change_virtual_intf(struct wiphy *wiphy,
  107. struct net_device *dev,
  108. enum nl80211_iftype type,
  109. struct vif_params *params)
  110. {
  111. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  112. u8 *mac_addr;
  113. int ret;
  114. ret = qtnf_validate_iface_combinations(wiphy, vif, type);
  115. if (ret) {
  116. pr_err("VIF%u.%u combination check: failed to set type %d\n",
  117. vif->mac->macid, vif->vifid, type);
  118. return ret;
  119. }
  120. if (params)
  121. mac_addr = params->macaddr;
  122. else
  123. mac_addr = NULL;
  124. qtnf_scan_done(vif->mac, true);
  125. ret = qtnf_cmd_send_change_intf_type(vif, type, mac_addr);
  126. if (ret) {
  127. pr_err("VIF%u.%u: failed to change VIF type: %d\n",
  128. vif->mac->macid, vif->vifid, ret);
  129. return ret;
  130. }
  131. vif->wdev.iftype = type;
  132. return 0;
  133. }
  134. int qtnf_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
  135. {
  136. struct net_device *netdev = wdev->netdev;
  137. struct qtnf_vif *vif;
  138. if (WARN_ON(!netdev))
  139. return -EFAULT;
  140. vif = qtnf_netdev_get_priv(wdev->netdev);
  141. qtnf_scan_done(vif->mac, true);
  142. /* Stop data */
  143. netif_tx_stop_all_queues(netdev);
  144. if (netif_carrier_ok(netdev))
  145. netif_carrier_off(netdev);
  146. if (netdev->reg_state == NETREG_REGISTERED)
  147. unregister_netdevice(netdev);
  148. if (qtnf_cmd_send_del_intf(vif))
  149. pr_err("VIF%u.%u: failed to delete VIF\n", vif->mac->macid,
  150. vif->vifid);
  151. vif->netdev->ieee80211_ptr = NULL;
  152. vif->netdev = NULL;
  153. vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  154. return 0;
  155. }
  156. static struct wireless_dev *qtnf_add_virtual_intf(struct wiphy *wiphy,
  157. const char *name,
  158. unsigned char name_assign_t,
  159. enum nl80211_iftype type,
  160. struct vif_params *params)
  161. {
  162. struct qtnf_wmac *mac;
  163. struct qtnf_vif *vif;
  164. u8 *mac_addr = NULL;
  165. int ret;
  166. mac = wiphy_priv(wiphy);
  167. if (!mac)
  168. return ERR_PTR(-EFAULT);
  169. ret = qtnf_validate_iface_combinations(wiphy, NULL, type);
  170. if (ret) {
  171. pr_err("MAC%u invalid combination: failed to add type %d\n",
  172. mac->macid, type);
  173. return ERR_PTR(ret);
  174. }
  175. switch (type) {
  176. case NL80211_IFTYPE_STATION:
  177. case NL80211_IFTYPE_AP:
  178. vif = qtnf_mac_get_free_vif(mac);
  179. if (!vif) {
  180. pr_err("MAC%u: no free VIF available\n", mac->macid);
  181. return ERR_PTR(-EFAULT);
  182. }
  183. eth_zero_addr(vif->mac_addr);
  184. eth_zero_addr(vif->bssid);
  185. vif->bss_priority = QTNF_DEF_BSS_PRIORITY;
  186. vif->sta_state = QTNF_STA_DISCONNECTED;
  187. memset(&vif->wdev, 0, sizeof(vif->wdev));
  188. vif->wdev.wiphy = wiphy;
  189. vif->wdev.iftype = type;
  190. break;
  191. default:
  192. pr_err("MAC%u: unsupported IF type %d\n", mac->macid, type);
  193. return ERR_PTR(-ENOTSUPP);
  194. }
  195. if (params)
  196. mac_addr = params->macaddr;
  197. if (qtnf_cmd_send_add_intf(vif, type, mac_addr)) {
  198. pr_err("VIF%u.%u: failed to add VIF\n", mac->macid, vif->vifid);
  199. goto err_cmd;
  200. }
  201. if (!is_valid_ether_addr(vif->mac_addr)) {
  202. pr_err("VIF%u.%u: FW reported bad MAC: %pM\n",
  203. mac->macid, vif->vifid, vif->mac_addr);
  204. goto err_mac;
  205. }
  206. if (qtnf_core_net_attach(mac, vif, name, name_assign_t)) {
  207. pr_err("VIF%u.%u: failed to attach netdev\n", mac->macid,
  208. vif->vifid);
  209. goto err_net;
  210. }
  211. vif->wdev.netdev = vif->netdev;
  212. return &vif->wdev;
  213. err_net:
  214. vif->netdev = NULL;
  215. err_mac:
  216. qtnf_cmd_send_del_intf(vif);
  217. err_cmd:
  218. vif->wdev.iftype = NL80211_IFTYPE_UNSPECIFIED;
  219. return ERR_PTR(-EFAULT);
  220. }
  221. static int qtnf_mgmt_set_appie(struct qtnf_vif *vif,
  222. const struct cfg80211_beacon_data *info)
  223. {
  224. int ret = 0;
  225. if (!info->beacon_ies || !info->beacon_ies_len) {
  226. ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
  227. NULL, 0);
  228. } else {
  229. ret = qtnf_cmd_send_mgmt_set_appie(vif, QLINK_IE_SET_BEACON_IES,
  230. info->beacon_ies,
  231. info->beacon_ies_len);
  232. }
  233. if (ret)
  234. goto out;
  235. if (!info->proberesp_ies || !info->proberesp_ies_len) {
  236. ret = qtnf_cmd_send_mgmt_set_appie(vif,
  237. QLINK_IE_SET_PROBE_RESP_IES,
  238. NULL, 0);
  239. } else {
  240. ret = qtnf_cmd_send_mgmt_set_appie(vif,
  241. QLINK_IE_SET_PROBE_RESP_IES,
  242. info->proberesp_ies,
  243. info->proberesp_ies_len);
  244. }
  245. if (ret)
  246. goto out;
  247. if (!info->assocresp_ies || !info->assocresp_ies_len) {
  248. ret = qtnf_cmd_send_mgmt_set_appie(vif,
  249. QLINK_IE_SET_ASSOC_RESP,
  250. NULL, 0);
  251. } else {
  252. ret = qtnf_cmd_send_mgmt_set_appie(vif,
  253. QLINK_IE_SET_ASSOC_RESP,
  254. info->assocresp_ies,
  255. info->assocresp_ies_len);
  256. }
  257. out:
  258. return ret;
  259. }
  260. static int qtnf_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  261. struct cfg80211_beacon_data *info)
  262. {
  263. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  264. return qtnf_mgmt_set_appie(vif, info);
  265. }
  266. static int qtnf_start_ap(struct wiphy *wiphy, struct net_device *dev,
  267. struct cfg80211_ap_settings *settings)
  268. {
  269. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  270. int ret;
  271. ret = qtnf_cmd_send_start_ap(vif, settings);
  272. if (ret)
  273. pr_err("VIF%u.%u: failed to start AP\n", vif->mac->macid,
  274. vif->vifid);
  275. return ret;
  276. }
  277. static int qtnf_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  278. {
  279. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  280. int ret;
  281. qtnf_scan_done(vif->mac, true);
  282. ret = qtnf_cmd_send_stop_ap(vif);
  283. if (ret) {
  284. pr_err("VIF%u.%u: failed to stop AP operation in FW\n",
  285. vif->mac->macid, vif->vifid);
  286. netif_carrier_off(vif->netdev);
  287. }
  288. return ret;
  289. }
  290. static int qtnf_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  291. {
  292. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  293. struct qtnf_vif *vif;
  294. int ret;
  295. vif = qtnf_mac_get_base_vif(mac);
  296. if (!vif) {
  297. pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
  298. return -EFAULT;
  299. }
  300. if (changed & (WIPHY_PARAM_RETRY_LONG | WIPHY_PARAM_RETRY_SHORT)) {
  301. pr_err("MAC%u: can't modify retry params\n", mac->macid);
  302. return -EOPNOTSUPP;
  303. }
  304. ret = qtnf_cmd_send_update_phy_params(mac, changed);
  305. if (ret)
  306. pr_err("MAC%u: failed to update PHY params\n", mac->macid);
  307. return ret;
  308. }
  309. static void
  310. qtnf_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
  311. u16 frame_type, bool reg)
  312. {
  313. struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
  314. u16 mgmt_type;
  315. u16 new_mask;
  316. u16 qlink_frame_type = 0;
  317. mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
  318. if (reg)
  319. new_mask = vif->mgmt_frames_bitmask | BIT(mgmt_type);
  320. else
  321. new_mask = vif->mgmt_frames_bitmask & ~BIT(mgmt_type);
  322. if (new_mask == vif->mgmt_frames_bitmask)
  323. return;
  324. switch (frame_type & IEEE80211_FCTL_STYPE) {
  325. case IEEE80211_STYPE_REASSOC_REQ:
  326. case IEEE80211_STYPE_ASSOC_REQ:
  327. qlink_frame_type = QLINK_MGMT_FRAME_ASSOC_REQ;
  328. break;
  329. case IEEE80211_STYPE_AUTH:
  330. qlink_frame_type = QLINK_MGMT_FRAME_AUTH;
  331. break;
  332. case IEEE80211_STYPE_PROBE_REQ:
  333. qlink_frame_type = QLINK_MGMT_FRAME_PROBE_REQ;
  334. break;
  335. case IEEE80211_STYPE_ACTION:
  336. qlink_frame_type = QLINK_MGMT_FRAME_ACTION;
  337. break;
  338. default:
  339. pr_warn("VIF%u.%u: unsupported frame type: %X\n",
  340. vif->mac->macid, vif->vifid,
  341. (frame_type & IEEE80211_FCTL_STYPE) >> 4);
  342. return;
  343. }
  344. if (qtnf_cmd_send_register_mgmt(vif, qlink_frame_type, reg)) {
  345. pr_warn("VIF%u.%u: failed to %sregister mgmt frame type 0x%x\n",
  346. vif->mac->macid, vif->vifid, reg ? "" : "un",
  347. frame_type);
  348. return;
  349. }
  350. vif->mgmt_frames_bitmask = new_mask;
  351. pr_debug("VIF%u.%u: %sregistered mgmt frame type 0x%x\n",
  352. vif->mac->macid, vif->vifid, reg ? "" : "un", frame_type);
  353. }
  354. static int
  355. qtnf_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  356. struct cfg80211_mgmt_tx_params *params, u64 *cookie)
  357. {
  358. struct qtnf_vif *vif = qtnf_netdev_get_priv(wdev->netdev);
  359. const struct ieee80211_mgmt *mgmt_frame = (void *)params->buf;
  360. u32 short_cookie = prandom_u32();
  361. u16 flags = 0;
  362. u16 freq;
  363. *cookie = short_cookie;
  364. if (params->offchan)
  365. flags |= QLINK_MGMT_FRAME_TX_FLAG_OFFCHAN;
  366. if (params->no_cck)
  367. flags |= QLINK_MGMT_FRAME_TX_FLAG_NO_CCK;
  368. if (params->dont_wait_for_ack)
  369. flags |= QLINK_MGMT_FRAME_TX_FLAG_ACK_NOWAIT;
  370. /* If channel is not specified, pass "freq = 0" to tell device
  371. * firmware to use current channel.
  372. */
  373. if (params->chan)
  374. freq = params->chan->center_freq;
  375. else
  376. freq = 0;
  377. pr_debug("%s freq:%u; FC:%.4X; DA:%pM; len:%zu; C:%.8X; FL:%.4X\n",
  378. wdev->netdev->name, freq,
  379. le16_to_cpu(mgmt_frame->frame_control), mgmt_frame->da,
  380. params->len, short_cookie, flags);
  381. return qtnf_cmd_send_mgmt_frame(vif, short_cookie, flags,
  382. freq,
  383. params->buf, params->len);
  384. }
  385. static int
  386. qtnf_get_station(struct wiphy *wiphy, struct net_device *dev,
  387. const u8 *mac, struct station_info *sinfo)
  388. {
  389. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  390. sinfo->generation = vif->generation;
  391. return qtnf_cmd_get_sta_info(vif, mac, sinfo);
  392. }
  393. static int
  394. qtnf_dump_station(struct wiphy *wiphy, struct net_device *dev,
  395. int idx, u8 *mac, struct station_info *sinfo)
  396. {
  397. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  398. const struct qtnf_sta_node *sta_node;
  399. int ret;
  400. sta_node = qtnf_sta_list_lookup_index(&vif->sta_list, idx);
  401. if (unlikely(!sta_node))
  402. return -ENOENT;
  403. ether_addr_copy(mac, sta_node->mac_addr);
  404. ret = qtnf_cmd_get_sta_info(vif, sta_node->mac_addr, sinfo);
  405. if (unlikely(ret == -ENOENT)) {
  406. qtnf_sta_list_del(vif, mac);
  407. cfg80211_del_sta(vif->netdev, mac, GFP_KERNEL);
  408. sinfo->filled = 0;
  409. }
  410. sinfo->generation = vif->generation;
  411. return ret;
  412. }
  413. static int qtnf_add_key(struct wiphy *wiphy, struct net_device *dev,
  414. u8 key_index, bool pairwise, const u8 *mac_addr,
  415. struct key_params *params)
  416. {
  417. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  418. int ret;
  419. ret = qtnf_cmd_send_add_key(vif, key_index, pairwise, mac_addr, params);
  420. if (ret)
  421. pr_err("VIF%u.%u: failed to add key: cipher=%x idx=%u pw=%u\n",
  422. vif->mac->macid, vif->vifid, params->cipher, key_index,
  423. pairwise);
  424. return ret;
  425. }
  426. static int qtnf_del_key(struct wiphy *wiphy, struct net_device *dev,
  427. u8 key_index, bool pairwise, const u8 *mac_addr)
  428. {
  429. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  430. int ret;
  431. ret = qtnf_cmd_send_del_key(vif, key_index, pairwise, mac_addr);
  432. if (ret) {
  433. if (ret == -ENOENT) {
  434. pr_debug("VIF%u.%u: key index %d out of bounds\n",
  435. vif->mac->macid, vif->vifid, key_index);
  436. } else {
  437. pr_err("VIF%u.%u: failed to delete key: idx=%u pw=%u\n",
  438. vif->mac->macid, vif->vifid,
  439. key_index, pairwise);
  440. }
  441. }
  442. return ret;
  443. }
  444. static int qtnf_set_default_key(struct wiphy *wiphy, struct net_device *dev,
  445. u8 key_index, bool unicast, bool multicast)
  446. {
  447. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  448. int ret;
  449. ret = qtnf_cmd_send_set_default_key(vif, key_index, unicast, multicast);
  450. if (ret)
  451. pr_err("VIF%u.%u: failed to set dflt key: idx=%u uc=%u mc=%u\n",
  452. vif->mac->macid, vif->vifid, key_index, unicast,
  453. multicast);
  454. return ret;
  455. }
  456. static int
  457. qtnf_set_default_mgmt_key(struct wiphy *wiphy, struct net_device *dev,
  458. u8 key_index)
  459. {
  460. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  461. int ret;
  462. ret = qtnf_cmd_send_set_default_mgmt_key(vif, key_index);
  463. if (ret)
  464. pr_err("VIF%u.%u: failed to set default MGMT key: idx=%u\n",
  465. vif->mac->macid, vif->vifid, key_index);
  466. return ret;
  467. }
  468. static int
  469. qtnf_change_station(struct wiphy *wiphy, struct net_device *dev,
  470. const u8 *mac, struct station_parameters *params)
  471. {
  472. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  473. int ret;
  474. ret = qtnf_cmd_send_change_sta(vif, mac, params);
  475. if (ret)
  476. pr_err("VIF%u.%u: failed to change STA %pM\n",
  477. vif->mac->macid, vif->vifid, mac);
  478. return ret;
  479. }
  480. static int
  481. qtnf_del_station(struct wiphy *wiphy, struct net_device *dev,
  482. struct station_del_parameters *params)
  483. {
  484. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  485. int ret;
  486. if (params->mac &&
  487. (vif->wdev.iftype == NL80211_IFTYPE_AP) &&
  488. !is_broadcast_ether_addr(params->mac) &&
  489. !qtnf_sta_list_lookup(&vif->sta_list, params->mac))
  490. return 0;
  491. ret = qtnf_cmd_send_del_sta(vif, params);
  492. if (ret)
  493. pr_err("VIF%u.%u: failed to delete STA %pM\n",
  494. vif->mac->macid, vif->vifid, params->mac);
  495. return ret;
  496. }
  497. static int
  498. qtnf_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
  499. {
  500. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  501. cancel_delayed_work_sync(&mac->scan_timeout);
  502. mac->scan_req = request;
  503. if (qtnf_cmd_send_scan(mac)) {
  504. pr_err("MAC%u: failed to start scan\n", mac->macid);
  505. mac->scan_req = NULL;
  506. return -EFAULT;
  507. }
  508. queue_delayed_work(mac->bus->workqueue, &mac->scan_timeout,
  509. QTNF_SCAN_TIMEOUT_SEC * HZ);
  510. return 0;
  511. }
  512. static int
  513. qtnf_connect(struct wiphy *wiphy, struct net_device *dev,
  514. struct cfg80211_connect_params *sme)
  515. {
  516. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  517. int ret;
  518. if (vif->wdev.iftype != NL80211_IFTYPE_STATION)
  519. return -EOPNOTSUPP;
  520. if (vif->sta_state != QTNF_STA_DISCONNECTED)
  521. return -EBUSY;
  522. if (sme->bssid)
  523. ether_addr_copy(vif->bssid, sme->bssid);
  524. else
  525. eth_zero_addr(vif->bssid);
  526. ret = qtnf_cmd_send_connect(vif, sme);
  527. if (ret) {
  528. pr_err("VIF%u.%u: failed to connect\n", vif->mac->macid,
  529. vif->vifid);
  530. return ret;
  531. }
  532. vif->sta_state = QTNF_STA_CONNECTING;
  533. return 0;
  534. }
  535. static int
  536. qtnf_disconnect(struct wiphy *wiphy, struct net_device *dev,
  537. u16 reason_code)
  538. {
  539. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  540. struct qtnf_vif *vif;
  541. int ret = 0;
  542. vif = qtnf_mac_get_base_vif(mac);
  543. if (!vif) {
  544. pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
  545. return -EFAULT;
  546. }
  547. if (vif->wdev.iftype != NL80211_IFTYPE_STATION) {
  548. ret = -EOPNOTSUPP;
  549. goto out;
  550. }
  551. qtnf_scan_done(mac, true);
  552. if (vif->sta_state == QTNF_STA_DISCONNECTED)
  553. goto out;
  554. ret = qtnf_cmd_send_disconnect(vif, reason_code);
  555. if (ret) {
  556. pr_err("VIF%u.%u: failed to disconnect\n", mac->macid,
  557. vif->vifid);
  558. goto out;
  559. }
  560. out:
  561. if (vif->sta_state == QTNF_STA_CONNECTING)
  562. vif->sta_state = QTNF_STA_DISCONNECTED;
  563. return ret;
  564. }
  565. static int
  566. qtnf_dump_survey(struct wiphy *wiphy, struct net_device *dev,
  567. int idx, struct survey_info *survey)
  568. {
  569. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  570. struct wireless_dev *wdev = dev->ieee80211_ptr;
  571. struct ieee80211_supported_band *sband;
  572. const struct cfg80211_chan_def *chandef = &wdev->chandef;
  573. struct ieee80211_channel *chan;
  574. struct qtnf_chan_stats stats;
  575. struct qtnf_vif *vif;
  576. int ret;
  577. vif = qtnf_netdev_get_priv(dev);
  578. sband = wiphy->bands[NL80211_BAND_2GHZ];
  579. if (sband && idx >= sband->n_channels) {
  580. idx -= sband->n_channels;
  581. sband = NULL;
  582. }
  583. if (!sband)
  584. sband = wiphy->bands[NL80211_BAND_5GHZ];
  585. if (!sband || idx >= sband->n_channels)
  586. return -ENOENT;
  587. chan = &sband->channels[idx];
  588. memset(&stats, 0, sizeof(stats));
  589. survey->channel = chan;
  590. survey->filled = 0x0;
  591. if (chandef->chan) {
  592. if (chan->hw_value == chandef->chan->hw_value)
  593. survey->filled = SURVEY_INFO_IN_USE;
  594. }
  595. ret = qtnf_cmd_get_chan_stats(mac, chan->hw_value, &stats);
  596. switch (ret) {
  597. case 0:
  598. if (unlikely(stats.chan_num != chan->hw_value)) {
  599. pr_err("received stats for channel %d instead of %d\n",
  600. stats.chan_num, chan->hw_value);
  601. ret = -EINVAL;
  602. break;
  603. }
  604. survey->filled |= SURVEY_INFO_TIME |
  605. SURVEY_INFO_TIME_SCAN |
  606. SURVEY_INFO_TIME_BUSY |
  607. SURVEY_INFO_TIME_RX |
  608. SURVEY_INFO_TIME_TX |
  609. SURVEY_INFO_NOISE_DBM;
  610. survey->time_scan = stats.cca_try;
  611. survey->time = stats.cca_try;
  612. survey->time_tx = stats.cca_tx;
  613. survey->time_rx = stats.cca_rx;
  614. survey->time_busy = stats.cca_busy;
  615. survey->noise = stats.chan_noise;
  616. break;
  617. case -ENOENT:
  618. pr_debug("no stats for channel %u\n", chan->hw_value);
  619. ret = 0;
  620. break;
  621. default:
  622. pr_debug("failed to get chan(%d) stats from card\n",
  623. chan->hw_value);
  624. ret = -EINVAL;
  625. break;
  626. }
  627. return ret;
  628. }
  629. static int
  630. qtnf_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
  631. struct cfg80211_chan_def *chandef)
  632. {
  633. struct net_device *ndev = wdev->netdev;
  634. struct qtnf_vif *vif;
  635. int ret;
  636. if (!ndev)
  637. return -ENODEV;
  638. vif = qtnf_netdev_get_priv(wdev->netdev);
  639. ret = qtnf_cmd_get_channel(vif, chandef);
  640. if (ret) {
  641. pr_err("%s: failed to get channel: %d\n", ndev->name, ret);
  642. goto out;
  643. }
  644. if (!cfg80211_chandef_valid(chandef)) {
  645. pr_err("%s: bad channel freq=%u cf1=%u cf2=%u bw=%u\n",
  646. ndev->name, chandef->chan->center_freq,
  647. chandef->center_freq1, chandef->center_freq2,
  648. chandef->width);
  649. ret = -ENODATA;
  650. }
  651. out:
  652. return ret;
  653. }
  654. static int qtnf_channel_switch(struct wiphy *wiphy, struct net_device *dev,
  655. struct cfg80211_csa_settings *params)
  656. {
  657. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  658. int ret;
  659. pr_debug("%s: chan(%u) count(%u) radar(%u) block_tx(%u)\n", dev->name,
  660. params->chandef.chan->hw_value, params->count,
  661. params->radar_required, params->block_tx);
  662. if (!cfg80211_chandef_valid(&params->chandef)) {
  663. pr_err("%s: invalid channel\n", dev->name);
  664. return -EINVAL;
  665. }
  666. ret = qtnf_cmd_send_chan_switch(vif, params);
  667. if (ret)
  668. pr_warn("%s: failed to switch to channel (%u)\n",
  669. dev->name, params->chandef.chan->hw_value);
  670. return ret;
  671. }
  672. static int qtnf_start_radar_detection(struct wiphy *wiphy,
  673. struct net_device *ndev,
  674. struct cfg80211_chan_def *chandef,
  675. u32 cac_time_ms)
  676. {
  677. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  678. int ret;
  679. if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
  680. return -ENOTSUPP;
  681. ret = qtnf_cmd_start_cac(vif, chandef, cac_time_ms);
  682. if (ret)
  683. pr_err("%s: failed to start CAC ret=%d\n", ndev->name, ret);
  684. return ret;
  685. }
  686. static int qtnf_set_mac_acl(struct wiphy *wiphy,
  687. struct net_device *dev,
  688. const struct cfg80211_acl_data *params)
  689. {
  690. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  691. int ret;
  692. ret = qtnf_cmd_set_mac_acl(vif, params);
  693. if (ret)
  694. pr_err("%s: failed to set mac ACL ret=%d\n", dev->name, ret);
  695. return ret;
  696. }
  697. static int qtnf_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  698. bool enabled, int timeout)
  699. {
  700. struct qtnf_vif *vif = qtnf_netdev_get_priv(dev);
  701. int ret;
  702. ret = qtnf_cmd_send_pm_set(vif, enabled ? QLINK_PM_AUTO_STANDBY :
  703. QLINK_PM_OFF, timeout);
  704. if (ret) {
  705. pr_err("%s: failed to set PM mode ret=%d\n", dev->name, ret);
  706. return ret;
  707. }
  708. return ret;
  709. }
  710. #ifdef CONFIG_PM
  711. static int qtnf_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan)
  712. {
  713. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  714. struct qtnf_vif *vif;
  715. int ret = 0;
  716. vif = qtnf_mac_get_base_vif(mac);
  717. if (!vif) {
  718. pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
  719. ret = -EFAULT;
  720. goto exit;
  721. }
  722. if (!wowlan) {
  723. pr_debug("WoWLAN triggers are not enabled\n");
  724. qtnf_virtual_intf_cleanup(vif->netdev);
  725. goto exit;
  726. }
  727. qtnf_scan_done(vif->mac, true);
  728. ret = qtnf_cmd_send_wowlan_set(vif, wowlan);
  729. if (ret) {
  730. pr_err("MAC%u: failed to set WoWLAN triggers\n",
  731. mac->macid);
  732. goto exit;
  733. }
  734. exit:
  735. return ret;
  736. }
  737. static int qtnf_resume(struct wiphy *wiphy)
  738. {
  739. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  740. struct qtnf_vif *vif;
  741. int ret = 0;
  742. vif = qtnf_mac_get_base_vif(mac);
  743. if (!vif) {
  744. pr_err("MAC%u: primary VIF is not configured\n", mac->macid);
  745. ret = -EFAULT;
  746. goto exit;
  747. }
  748. ret = qtnf_cmd_send_wowlan_set(vif, NULL);
  749. if (ret) {
  750. pr_err("MAC%u: failed to reset WoWLAN triggers\n",
  751. mac->macid);
  752. goto exit;
  753. }
  754. exit:
  755. return ret;
  756. }
  757. static void qtnf_set_wakeup(struct wiphy *wiphy, bool enabled)
  758. {
  759. struct qtnf_wmac *mac = wiphy_priv(wiphy);
  760. struct qtnf_bus *bus = mac->bus;
  761. device_set_wakeup_enable(bus->dev, enabled);
  762. }
  763. #endif
  764. static struct cfg80211_ops qtn_cfg80211_ops = {
  765. .add_virtual_intf = qtnf_add_virtual_intf,
  766. .change_virtual_intf = qtnf_change_virtual_intf,
  767. .del_virtual_intf = qtnf_del_virtual_intf,
  768. .start_ap = qtnf_start_ap,
  769. .change_beacon = qtnf_change_beacon,
  770. .stop_ap = qtnf_stop_ap,
  771. .set_wiphy_params = qtnf_set_wiphy_params,
  772. .mgmt_frame_register = qtnf_mgmt_frame_register,
  773. .mgmt_tx = qtnf_mgmt_tx,
  774. .change_station = qtnf_change_station,
  775. .del_station = qtnf_del_station,
  776. .get_station = qtnf_get_station,
  777. .dump_station = qtnf_dump_station,
  778. .add_key = qtnf_add_key,
  779. .del_key = qtnf_del_key,
  780. .set_default_key = qtnf_set_default_key,
  781. .set_default_mgmt_key = qtnf_set_default_mgmt_key,
  782. .scan = qtnf_scan,
  783. .connect = qtnf_connect,
  784. .disconnect = qtnf_disconnect,
  785. .dump_survey = qtnf_dump_survey,
  786. .get_channel = qtnf_get_channel,
  787. .channel_switch = qtnf_channel_switch,
  788. .start_radar_detection = qtnf_start_radar_detection,
  789. .set_mac_acl = qtnf_set_mac_acl,
  790. .set_power_mgmt = qtnf_set_power_mgmt,
  791. #ifdef CONFIG_PM
  792. .suspend = qtnf_suspend,
  793. .resume = qtnf_resume,
  794. .set_wakeup = qtnf_set_wakeup,
  795. #endif
  796. };
  797. static void qtnf_cfg80211_reg_notifier(struct wiphy *wiphy_in,
  798. struct regulatory_request *req)
  799. {
  800. struct qtnf_wmac *mac = wiphy_priv(wiphy_in);
  801. struct qtnf_bus *bus = mac->bus;
  802. struct wiphy *wiphy;
  803. unsigned int mac_idx;
  804. enum nl80211_band band;
  805. int ret;
  806. pr_debug("MAC%u: initiator=%d alpha=%c%c\n", mac->macid, req->initiator,
  807. req->alpha2[0], req->alpha2[1]);
  808. ret = qtnf_cmd_reg_notify(bus, req);
  809. if (ret) {
  810. if (ret != -EOPNOTSUPP && ret != -EALREADY)
  811. pr_err("failed to update reg domain to %c%c\n",
  812. req->alpha2[0], req->alpha2[1]);
  813. return;
  814. }
  815. for (mac_idx = 0; mac_idx < QTNF_MAX_MAC; ++mac_idx) {
  816. if (!(bus->hw_info.mac_bitmap & (1 << mac_idx)))
  817. continue;
  818. mac = bus->mac[mac_idx];
  819. if (!mac)
  820. continue;
  821. wiphy = priv_to_wiphy(mac);
  822. for (band = 0; band < NUM_NL80211_BANDS; ++band) {
  823. if (!wiphy->bands[band])
  824. continue;
  825. ret = qtnf_cmd_band_info_get(mac, wiphy->bands[band]);
  826. if (ret)
  827. pr_err("failed to get chan info for mac %u band %u\n",
  828. mac_idx, band);
  829. }
  830. }
  831. }
  832. struct wiphy *qtnf_wiphy_allocate(struct qtnf_bus *bus)
  833. {
  834. struct wiphy *wiphy;
  835. if (bus->hw_info.hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
  836. qtn_cfg80211_ops.start_radar_detection = NULL;
  837. if (!(bus->hw_info.hw_capab & QLINK_HW_CAPAB_PWR_MGMT))
  838. qtn_cfg80211_ops.set_power_mgmt = NULL;
  839. wiphy = wiphy_new(&qtn_cfg80211_ops, sizeof(struct qtnf_wmac));
  840. if (!wiphy)
  841. return NULL;
  842. set_wiphy_dev(wiphy, bus->dev);
  843. return wiphy;
  844. }
  845. static int
  846. qtnf_wiphy_setup_if_comb(struct wiphy *wiphy, struct qtnf_mac_info *mac_info)
  847. {
  848. struct ieee80211_iface_combination *if_comb;
  849. size_t n_if_comb;
  850. u16 interface_modes = 0;
  851. size_t i, j;
  852. if_comb = mac_info->if_comb;
  853. n_if_comb = mac_info->n_if_comb;
  854. if (!if_comb || !n_if_comb)
  855. return -ENOENT;
  856. for (i = 0; i < n_if_comb; i++) {
  857. if_comb[i].radar_detect_widths = mac_info->radar_detect_widths;
  858. for (j = 0; j < if_comb[i].n_limits; j++)
  859. interface_modes |= if_comb[i].limits[j].types;
  860. }
  861. wiphy->iface_combinations = if_comb;
  862. wiphy->n_iface_combinations = n_if_comb;
  863. wiphy->interface_modes = interface_modes;
  864. return 0;
  865. }
  866. int qtnf_wiphy_register(struct qtnf_hw_info *hw_info, struct qtnf_wmac *mac)
  867. {
  868. struct wiphy *wiphy = priv_to_wiphy(mac);
  869. struct qtnf_mac_info *macinfo = &mac->macinfo;
  870. int ret;
  871. if (!wiphy) {
  872. pr_err("invalid wiphy pointer\n");
  873. return -EFAULT;
  874. }
  875. wiphy->frag_threshold = macinfo->frag_thr;
  876. wiphy->rts_threshold = macinfo->rts_thr;
  877. wiphy->retry_short = macinfo->sretry_limit;
  878. wiphy->retry_long = macinfo->lretry_limit;
  879. wiphy->coverage_class = macinfo->coverage_class;
  880. wiphy->max_scan_ssids =
  881. (hw_info->max_scan_ssids) ? hw_info->max_scan_ssids : 1;
  882. wiphy->max_scan_ie_len = QTNF_MAX_VSIE_LEN;
  883. wiphy->mgmt_stypes = qtnf_mgmt_stypes;
  884. wiphy->max_remain_on_channel_duration = 5000;
  885. wiphy->max_acl_mac_addrs = macinfo->max_acl_mac_addrs;
  886. wiphy->max_num_csa_counters = 2;
  887. ret = qtnf_wiphy_setup_if_comb(wiphy, macinfo);
  888. if (ret)
  889. goto out;
  890. /* Initialize cipher suits */
  891. wiphy->cipher_suites = qtnf_cipher_suites;
  892. wiphy->n_cipher_suites = ARRAY_SIZE(qtnf_cipher_suites);
  893. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  894. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  895. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD |
  896. WIPHY_FLAG_AP_UAPSD |
  897. WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  898. wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  899. if (hw_info->hw_capab & QLINK_HW_CAPAB_DFS_OFFLOAD)
  900. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD);
  901. wiphy->probe_resp_offload = NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  902. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2;
  903. wiphy->available_antennas_tx = macinfo->num_tx_chain;
  904. wiphy->available_antennas_rx = macinfo->num_rx_chain;
  905. wiphy->max_ap_assoc_sta = macinfo->max_ap_assoc_sta;
  906. wiphy->ht_capa_mod_mask = &macinfo->ht_cap_mod_mask;
  907. wiphy->vht_capa_mod_mask = &macinfo->vht_cap_mod_mask;
  908. ether_addr_copy(wiphy->perm_addr, mac->macaddr);
  909. if (hw_info->hw_capab & QLINK_HW_CAPAB_STA_INACT_TIMEOUT)
  910. wiphy->features |= NL80211_FEATURE_INACTIVITY_TIMER;
  911. if (hw_info->hw_capab & QLINK_HW_CAPAB_SCAN_RANDOM_MAC_ADDR)
  912. wiphy->features |= NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
  913. if (!(hw_info->hw_capab & QLINK_HW_CAPAB_OBSS_SCAN))
  914. wiphy->features |= NL80211_FEATURE_NEED_OBSS_SCAN;
  915. #ifdef CONFIG_PM
  916. if (macinfo->wowlan)
  917. wiphy->wowlan = macinfo->wowlan;
  918. #endif
  919. if (hw_info->hw_capab & QLINK_HW_CAPAB_REG_UPDATE) {
  920. wiphy->regulatory_flags |= REGULATORY_STRICT_REG |
  921. REGULATORY_CUSTOM_REG;
  922. wiphy->reg_notifier = qtnf_cfg80211_reg_notifier;
  923. wiphy_apply_custom_regulatory(wiphy, hw_info->rd);
  924. } else {
  925. wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
  926. }
  927. if (mac->macinfo.extended_capabilities_len) {
  928. wiphy->extended_capabilities =
  929. mac->macinfo.extended_capabilities;
  930. wiphy->extended_capabilities_mask =
  931. mac->macinfo.extended_capabilities_mask;
  932. wiphy->extended_capabilities_len =
  933. mac->macinfo.extended_capabilities_len;
  934. }
  935. strlcpy(wiphy->fw_version, hw_info->fw_version,
  936. sizeof(wiphy->fw_version));
  937. wiphy->hw_version = hw_info->hw_version;
  938. ret = wiphy_register(wiphy);
  939. if (ret < 0)
  940. goto out;
  941. if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED)
  942. ret = regulatory_set_wiphy_regd(wiphy, hw_info->rd);
  943. else if (isalpha(hw_info->rd->alpha2[0]) &&
  944. isalpha(hw_info->rd->alpha2[1]))
  945. ret = regulatory_hint(wiphy, hw_info->rd->alpha2);
  946. out:
  947. return ret;
  948. }
  949. void qtnf_netdev_updown(struct net_device *ndev, bool up)
  950. {
  951. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  952. if (qtnf_cmd_send_updown_intf(vif, up))
  953. pr_err("failed to send up/down command to FW\n");
  954. }
  955. void qtnf_virtual_intf_cleanup(struct net_device *ndev)
  956. {
  957. struct qtnf_vif *vif = qtnf_netdev_get_priv(ndev);
  958. struct qtnf_wmac *mac = wiphy_priv(vif->wdev.wiphy);
  959. if (vif->wdev.iftype == NL80211_IFTYPE_STATION) {
  960. switch (vif->sta_state) {
  961. case QTNF_STA_DISCONNECTED:
  962. break;
  963. case QTNF_STA_CONNECTING:
  964. cfg80211_connect_result(vif->netdev,
  965. vif->bssid, NULL, 0,
  966. NULL, 0,
  967. WLAN_STATUS_UNSPECIFIED_FAILURE,
  968. GFP_KERNEL);
  969. qtnf_disconnect(vif->wdev.wiphy, ndev,
  970. WLAN_REASON_DEAUTH_LEAVING);
  971. break;
  972. case QTNF_STA_CONNECTED:
  973. cfg80211_disconnected(vif->netdev,
  974. WLAN_REASON_DEAUTH_LEAVING,
  975. NULL, 0, 1, GFP_KERNEL);
  976. qtnf_disconnect(vif->wdev.wiphy, ndev,
  977. WLAN_REASON_DEAUTH_LEAVING);
  978. break;
  979. }
  980. vif->sta_state = QTNF_STA_DISCONNECTED;
  981. }
  982. qtnf_scan_done(mac, true);
  983. }
  984. void qtnf_cfg80211_vif_reset(struct qtnf_vif *vif)
  985. {
  986. if (vif->wdev.iftype == NL80211_IFTYPE_STATION) {
  987. switch (vif->sta_state) {
  988. case QTNF_STA_CONNECTING:
  989. cfg80211_connect_result(vif->netdev,
  990. vif->bssid, NULL, 0,
  991. NULL, 0,
  992. WLAN_STATUS_UNSPECIFIED_FAILURE,
  993. GFP_KERNEL);
  994. break;
  995. case QTNF_STA_CONNECTED:
  996. cfg80211_disconnected(vif->netdev,
  997. WLAN_REASON_DEAUTH_LEAVING,
  998. NULL, 0, 1, GFP_KERNEL);
  999. break;
  1000. case QTNF_STA_DISCONNECTED:
  1001. break;
  1002. }
  1003. }
  1004. cfg80211_shutdown_all_interfaces(vif->wdev.wiphy);
  1005. vif->sta_state = QTNF_STA_DISCONNECTED;
  1006. }
  1007. void qtnf_band_init_rates(struct ieee80211_supported_band *band)
  1008. {
  1009. switch (band->band) {
  1010. case NL80211_BAND_2GHZ:
  1011. band->bitrates = qtnf_rates_2g;
  1012. band->n_bitrates = ARRAY_SIZE(qtnf_rates_2g);
  1013. break;
  1014. case NL80211_BAND_5GHZ:
  1015. band->bitrates = qtnf_rates_5g;
  1016. band->n_bitrates = ARRAY_SIZE(qtnf_rates_5g);
  1017. break;
  1018. default:
  1019. band->bitrates = NULL;
  1020. band->n_bitrates = 0;
  1021. break;
  1022. }
  1023. }