cfg80211.c 32 KB

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