cfg80211.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. /*
  2. * Copyright (c) 2012-2015 Qualcomm Atheros, Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/etherdevice.h>
  17. #include "wil6210.h"
  18. #include "wmi.h"
  19. #define CHAN60G(_channel, _flags) { \
  20. .band = IEEE80211_BAND_60GHZ, \
  21. .center_freq = 56160 + (2160 * (_channel)), \
  22. .hw_value = (_channel), \
  23. .flags = (_flags), \
  24. .max_antenna_gain = 0, \
  25. .max_power = 40, \
  26. }
  27. static struct ieee80211_channel wil_60ghz_channels[] = {
  28. CHAN60G(1, 0),
  29. CHAN60G(2, 0),
  30. CHAN60G(3, 0),
  31. /* channel 4 not supported yet */
  32. };
  33. static struct ieee80211_supported_band wil_band_60ghz = {
  34. .channels = wil_60ghz_channels,
  35. .n_channels = ARRAY_SIZE(wil_60ghz_channels),
  36. .ht_cap = {
  37. .ht_supported = true,
  38. .cap = 0, /* TODO */
  39. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, /* TODO */
  40. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, /* TODO */
  41. .mcs = {
  42. /* MCS 1..12 - SC PHY */
  43. .rx_mask = {0xfe, 0x1f}, /* 1..12 */
  44. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, /* TODO */
  45. },
  46. },
  47. };
  48. static const struct ieee80211_txrx_stypes
  49. wil_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  50. [NL80211_IFTYPE_STATION] = {
  51. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  52. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  53. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  54. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  55. },
  56. [NL80211_IFTYPE_AP] = {
  57. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  58. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  59. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  60. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  61. },
  62. [NL80211_IFTYPE_P2P_CLIENT] = {
  63. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  64. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  65. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  66. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  67. },
  68. [NL80211_IFTYPE_P2P_GO] = {
  69. .tx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  70. BIT(IEEE80211_STYPE_PROBE_RESP >> 4),
  71. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  72. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  73. },
  74. };
  75. static const u32 wil_cipher_suites[] = {
  76. WLAN_CIPHER_SUITE_GCMP,
  77. };
  78. int wil_iftype_nl2wmi(enum nl80211_iftype type)
  79. {
  80. static const struct {
  81. enum nl80211_iftype nl;
  82. enum wmi_network_type wmi;
  83. } __nl2wmi[] = {
  84. {NL80211_IFTYPE_ADHOC, WMI_NETTYPE_ADHOC},
  85. {NL80211_IFTYPE_STATION, WMI_NETTYPE_INFRA},
  86. {NL80211_IFTYPE_AP, WMI_NETTYPE_AP},
  87. {NL80211_IFTYPE_P2P_CLIENT, WMI_NETTYPE_P2P},
  88. {NL80211_IFTYPE_P2P_GO, WMI_NETTYPE_P2P},
  89. {NL80211_IFTYPE_MONITOR, WMI_NETTYPE_ADHOC}, /* FIXME */
  90. };
  91. uint i;
  92. for (i = 0; i < ARRAY_SIZE(__nl2wmi); i++) {
  93. if (__nl2wmi[i].nl == type)
  94. return __nl2wmi[i].wmi;
  95. }
  96. return -EOPNOTSUPP;
  97. }
  98. int wil_cid_fill_sinfo(struct wil6210_priv *wil, int cid,
  99. struct station_info *sinfo)
  100. {
  101. struct wmi_notify_req_cmd cmd = {
  102. .cid = cid,
  103. .interval_usec = 0,
  104. };
  105. struct {
  106. struct wil6210_mbox_hdr_wmi wmi;
  107. struct wmi_notify_req_done_event evt;
  108. } __packed reply;
  109. struct wil_net_stats *stats = &wil->sta[cid].stats;
  110. int rc;
  111. rc = wmi_call(wil, WMI_NOTIFY_REQ_CMDID, &cmd, sizeof(cmd),
  112. WMI_NOTIFY_REQ_DONE_EVENTID, &reply, sizeof(reply), 20);
  113. if (rc)
  114. return rc;
  115. wil_dbg_wmi(wil, "Link status for CID %d: {\n"
  116. " MCS %d TSF 0x%016llx\n"
  117. " BF status 0x%08x SNR 0x%08x SQI %d%%\n"
  118. " Tx Tpt %d goodput %d Rx goodput %d\n"
  119. " Sectors(rx:tx) my %d:%d peer %d:%d\n""}\n",
  120. cid, le16_to_cpu(reply.evt.bf_mcs),
  121. le64_to_cpu(reply.evt.tsf), reply.evt.status,
  122. le32_to_cpu(reply.evt.snr_val),
  123. reply.evt.sqi,
  124. le32_to_cpu(reply.evt.tx_tpt),
  125. le32_to_cpu(reply.evt.tx_goodput),
  126. le32_to_cpu(reply.evt.rx_goodput),
  127. le16_to_cpu(reply.evt.my_rx_sector),
  128. le16_to_cpu(reply.evt.my_tx_sector),
  129. le16_to_cpu(reply.evt.other_rx_sector),
  130. le16_to_cpu(reply.evt.other_tx_sector));
  131. sinfo->generation = wil->sinfo_gen;
  132. sinfo->filled = BIT(NL80211_STA_INFO_RX_BYTES) |
  133. BIT(NL80211_STA_INFO_TX_BYTES) |
  134. BIT(NL80211_STA_INFO_RX_PACKETS) |
  135. BIT(NL80211_STA_INFO_TX_PACKETS) |
  136. BIT(NL80211_STA_INFO_RX_BITRATE) |
  137. BIT(NL80211_STA_INFO_TX_BITRATE) |
  138. BIT(NL80211_STA_INFO_RX_DROP_MISC) |
  139. BIT(NL80211_STA_INFO_TX_FAILED);
  140. sinfo->txrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  141. sinfo->txrate.mcs = le16_to_cpu(reply.evt.bf_mcs);
  142. sinfo->rxrate.flags = RATE_INFO_FLAGS_MCS | RATE_INFO_FLAGS_60G;
  143. sinfo->rxrate.mcs = stats->last_mcs_rx;
  144. sinfo->rx_bytes = stats->rx_bytes;
  145. sinfo->rx_packets = stats->rx_packets;
  146. sinfo->rx_dropped_misc = stats->rx_dropped;
  147. sinfo->tx_bytes = stats->tx_bytes;
  148. sinfo->tx_packets = stats->tx_packets;
  149. sinfo->tx_failed = stats->tx_errors;
  150. if (test_bit(wil_status_fwconnected, wil->status)) {
  151. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  152. sinfo->signal = reply.evt.sqi;
  153. }
  154. return rc;
  155. }
  156. static int wil_cfg80211_get_station(struct wiphy *wiphy,
  157. struct net_device *ndev,
  158. const u8 *mac, struct station_info *sinfo)
  159. {
  160. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  161. int rc;
  162. int cid = wil_find_cid(wil, mac);
  163. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  164. if (cid < 0)
  165. return cid;
  166. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  167. return rc;
  168. }
  169. /*
  170. * Find @idx-th active STA for station dump.
  171. */
  172. static int wil_find_cid_by_idx(struct wil6210_priv *wil, int idx)
  173. {
  174. int i;
  175. for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
  176. if (wil->sta[i].status == wil_sta_unused)
  177. continue;
  178. if (idx == 0)
  179. return i;
  180. idx--;
  181. }
  182. return -ENOENT;
  183. }
  184. static int wil_cfg80211_dump_station(struct wiphy *wiphy,
  185. struct net_device *dev, int idx,
  186. u8 *mac, struct station_info *sinfo)
  187. {
  188. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  189. int rc;
  190. int cid = wil_find_cid_by_idx(wil, idx);
  191. if (cid < 0)
  192. return -ENOENT;
  193. ether_addr_copy(mac, wil->sta[cid].addr);
  194. wil_dbg_misc(wil, "%s(%pM) CID %d\n", __func__, mac, cid);
  195. rc = wil_cid_fill_sinfo(wil, cid, sinfo);
  196. return rc;
  197. }
  198. static int wil_cfg80211_change_iface(struct wiphy *wiphy,
  199. struct net_device *ndev,
  200. enum nl80211_iftype type, u32 *flags,
  201. struct vif_params *params)
  202. {
  203. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  204. struct wireless_dev *wdev = wil->wdev;
  205. switch (type) {
  206. case NL80211_IFTYPE_STATION:
  207. case NL80211_IFTYPE_AP:
  208. case NL80211_IFTYPE_P2P_CLIENT:
  209. case NL80211_IFTYPE_P2P_GO:
  210. break;
  211. case NL80211_IFTYPE_MONITOR:
  212. if (flags)
  213. wil->monitor_flags = *flags;
  214. else
  215. wil->monitor_flags = 0;
  216. break;
  217. default:
  218. return -EOPNOTSUPP;
  219. }
  220. wdev->iftype = type;
  221. return 0;
  222. }
  223. static int wil_cfg80211_scan(struct wiphy *wiphy,
  224. struct cfg80211_scan_request *request)
  225. {
  226. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  227. struct wireless_dev *wdev = wil->wdev;
  228. struct {
  229. struct wmi_start_scan_cmd cmd;
  230. u16 chnl[4];
  231. } __packed cmd;
  232. uint i, n;
  233. int rc;
  234. if (wil->scan_request) {
  235. wil_err(wil, "Already scanning\n");
  236. return -EAGAIN;
  237. }
  238. /* check we are client side */
  239. switch (wdev->iftype) {
  240. case NL80211_IFTYPE_STATION:
  241. case NL80211_IFTYPE_P2P_CLIENT:
  242. break;
  243. default:
  244. return -EOPNOTSUPP;
  245. }
  246. /* FW don't support scan after connection attempt */
  247. if (test_bit(wil_status_dontscan, wil->status)) {
  248. wil_err(wil, "Can't scan now\n");
  249. return -EBUSY;
  250. }
  251. wil_dbg_misc(wil, "Start scan_request 0x%p\n", request);
  252. wil->scan_request = request;
  253. mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
  254. memset(&cmd, 0, sizeof(cmd));
  255. cmd.cmd.num_channels = 0;
  256. n = min(request->n_channels, 4U);
  257. for (i = 0; i < n; i++) {
  258. int ch = request->channels[i]->hw_value;
  259. if (ch == 0) {
  260. wil_err(wil,
  261. "Scan requested for unknown frequency %dMhz\n",
  262. request->channels[i]->center_freq);
  263. continue;
  264. }
  265. /* 0-based channel indexes */
  266. cmd.cmd.channel_list[cmd.cmd.num_channels++].channel = ch - 1;
  267. wil_dbg_misc(wil, "Scan for ch %d : %d MHz\n", ch,
  268. request->channels[i]->center_freq);
  269. }
  270. if (request->ie_len)
  271. print_hex_dump_bytes("Scan IE ", DUMP_PREFIX_OFFSET,
  272. request->ie, request->ie_len);
  273. else
  274. wil_dbg_misc(wil, "Scan has no IE's\n");
  275. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_REQ, request->ie_len,
  276. request->ie);
  277. if (rc) {
  278. wil_err(wil, "Aborting scan, set_ie failed: %d\n", rc);
  279. goto out;
  280. }
  281. rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  282. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  283. out:
  284. if (rc) {
  285. del_timer_sync(&wil->scan_timer);
  286. wil->scan_request = NULL;
  287. }
  288. return rc;
  289. }
  290. static void wil_print_crypto(struct wil6210_priv *wil,
  291. struct cfg80211_crypto_settings *c)
  292. {
  293. int i, n;
  294. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  295. c->wpa_versions, c->cipher_group);
  296. wil_dbg_misc(wil, "Pairwise ciphers [%d] {\n", c->n_ciphers_pairwise);
  297. n = min_t(int, c->n_ciphers_pairwise, ARRAY_SIZE(c->ciphers_pairwise));
  298. for (i = 0; i < n; i++)
  299. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  300. c->ciphers_pairwise[i]);
  301. wil_dbg_misc(wil, "}\n");
  302. wil_dbg_misc(wil, "AKM suites [%d] {\n", c->n_akm_suites);
  303. n = min_t(int, c->n_akm_suites, ARRAY_SIZE(c->akm_suites));
  304. for (i = 0; i < n; i++)
  305. wil_dbg_misc(wil, " [%d] = 0x%08x\n", i,
  306. c->akm_suites[i]);
  307. wil_dbg_misc(wil, "}\n");
  308. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  309. c->control_port, be16_to_cpu(c->control_port_ethertype),
  310. c->control_port_no_encrypt);
  311. }
  312. static void wil_print_connect_params(struct wil6210_priv *wil,
  313. struct cfg80211_connect_params *sme)
  314. {
  315. wil_info(wil, "Connecting to:\n");
  316. if (sme->channel) {
  317. wil_info(wil, " Channel: %d freq %d\n",
  318. sme->channel->hw_value, sme->channel->center_freq);
  319. }
  320. if (sme->bssid)
  321. wil_info(wil, " BSSID: %pM\n", sme->bssid);
  322. if (sme->ssid)
  323. print_hex_dump(KERN_INFO, " SSID: ", DUMP_PREFIX_OFFSET,
  324. 16, 1, sme->ssid, sme->ssid_len, true);
  325. wil_info(wil, " Privacy: %s\n", sme->privacy ? "secure" : "open");
  326. wil_print_crypto(wil, &sme->crypto);
  327. }
  328. static int wil_cfg80211_connect(struct wiphy *wiphy,
  329. struct net_device *ndev,
  330. struct cfg80211_connect_params *sme)
  331. {
  332. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  333. struct cfg80211_bss *bss;
  334. struct wmi_connect_cmd conn;
  335. const u8 *ssid_eid;
  336. const u8 *rsn_eid;
  337. int ch;
  338. int rc = 0;
  339. wil_print_connect_params(wil, sme);
  340. if (test_bit(wil_status_fwconnecting, wil->status) ||
  341. test_bit(wil_status_fwconnected, wil->status))
  342. return -EALREADY;
  343. if (sme->ie_len > WMI_MAX_IE_LEN) {
  344. wil_err(wil, "IE too large (%td bytes)\n", sme->ie_len);
  345. return -ERANGE;
  346. }
  347. rsn_eid = sme->ie ?
  348. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  349. NULL;
  350. if (sme->privacy && !rsn_eid) {
  351. wil_err(wil, "Missing RSN IE for secure connection\n");
  352. return -EINVAL;
  353. }
  354. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  355. sme->ssid, sme->ssid_len,
  356. IEEE80211_BSS_TYPE_ESS, IEEE80211_PRIVACY_ANY);
  357. if (!bss) {
  358. wil_err(wil, "Unable to find BSS\n");
  359. return -ENOENT;
  360. }
  361. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  362. if (!ssid_eid) {
  363. wil_err(wil, "No SSID\n");
  364. rc = -ENOENT;
  365. goto out;
  366. }
  367. wil->privacy = sme->privacy;
  368. if (wil->privacy) {
  369. /* For secure assoc, send WMI_DELETE_CIPHER_KEY_CMD */
  370. rc = wmi_del_cipher_key(wil, 0, bss->bssid);
  371. if (rc) {
  372. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
  373. goto out;
  374. }
  375. }
  376. /* WMI_SET_APPIE_CMD. ie may contain rsn info as well as other info
  377. * elements. Send it also in case it's empty, to erase previously set
  378. * ies in FW.
  379. */
  380. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  381. if (rc) {
  382. wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
  383. goto out;
  384. }
  385. /* WMI_CONNECT_CMD */
  386. memset(&conn, 0, sizeof(conn));
  387. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  388. case WLAN_CAPABILITY_DMG_TYPE_AP:
  389. conn.network_type = WMI_NETTYPE_INFRA;
  390. break;
  391. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  392. conn.network_type = WMI_NETTYPE_P2P;
  393. break;
  394. default:
  395. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  396. bss->capability);
  397. goto out;
  398. }
  399. if (wil->privacy) {
  400. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  401. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  402. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  403. conn.pairwise_crypto_len = 16;
  404. } else {
  405. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  406. conn.auth_mode = WMI_AUTH_NONE;
  407. }
  408. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  409. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  410. ch = bss->channel->hw_value;
  411. if (ch == 0) {
  412. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  413. bss->channel->center_freq);
  414. rc = -EOPNOTSUPP;
  415. goto out;
  416. }
  417. conn.channel = ch - 1;
  418. ether_addr_copy(conn.bssid, bss->bssid);
  419. ether_addr_copy(conn.dst_mac, bss->bssid);
  420. set_bit(wil_status_fwconnecting, wil->status);
  421. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  422. if (rc == 0) {
  423. netif_carrier_on(ndev);
  424. /* Connect can take lots of time */
  425. mod_timer(&wil->connect_timer,
  426. jiffies + msecs_to_jiffies(2000));
  427. } else {
  428. clear_bit(wil_status_fwconnecting, wil->status);
  429. }
  430. out:
  431. cfg80211_put_bss(wiphy, bss);
  432. return rc;
  433. }
  434. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  435. struct net_device *ndev,
  436. u16 reason_code)
  437. {
  438. int rc;
  439. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  440. rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
  441. return rc;
  442. }
  443. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  444. struct cfg80211_mgmt_tx_params *params,
  445. u64 *cookie)
  446. {
  447. const u8 *buf = params->buf;
  448. size_t len = params->len;
  449. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  450. int rc;
  451. bool tx_status = false;
  452. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  453. struct wmi_sw_tx_req_cmd *cmd;
  454. struct {
  455. struct wil6210_mbox_hdr_wmi wmi;
  456. struct wmi_sw_tx_complete_event evt;
  457. } __packed evt;
  458. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  459. if (!cmd) {
  460. rc = -ENOMEM;
  461. goto out;
  462. }
  463. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  464. cmd->len = cpu_to_le16(len);
  465. memcpy(cmd->payload, buf, len);
  466. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  467. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  468. if (rc == 0)
  469. tx_status = !evt.evt.status;
  470. kfree(cmd);
  471. out:
  472. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  473. tx_status, GFP_KERNEL);
  474. return rc;
  475. }
  476. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  477. struct cfg80211_chan_def *chandef)
  478. {
  479. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  480. struct wireless_dev *wdev = wil->wdev;
  481. wdev->preset_chandef = *chandef;
  482. return 0;
  483. }
  484. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  485. struct net_device *ndev,
  486. u8 key_index, bool pairwise,
  487. const u8 *mac_addr,
  488. struct key_params *params)
  489. {
  490. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  491. /* group key is not used */
  492. if (!pairwise)
  493. return 0;
  494. return wmi_add_cipher_key(wil, key_index, mac_addr,
  495. params->key_len, params->key);
  496. }
  497. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  498. struct net_device *ndev,
  499. u8 key_index, bool pairwise,
  500. const u8 *mac_addr)
  501. {
  502. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  503. /* group key is not used */
  504. if (!pairwise)
  505. return 0;
  506. return wmi_del_cipher_key(wil, key_index, mac_addr);
  507. }
  508. /* Need to be present or wiphy_new() will WARN */
  509. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  510. struct net_device *ndev,
  511. u8 key_index, bool unicast,
  512. bool multicast)
  513. {
  514. return 0;
  515. }
  516. static int wil_remain_on_channel(struct wiphy *wiphy,
  517. struct wireless_dev *wdev,
  518. struct ieee80211_channel *chan,
  519. unsigned int duration,
  520. u64 *cookie)
  521. {
  522. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  523. int rc;
  524. /* TODO: handle duration */
  525. wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
  526. rc = wmi_set_channel(wil, chan->hw_value);
  527. if (rc)
  528. return rc;
  529. rc = wmi_rxon(wil, true);
  530. return rc;
  531. }
  532. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  533. struct wireless_dev *wdev,
  534. u64 cookie)
  535. {
  536. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  537. int rc;
  538. wil_info(wil, "%s()\n", __func__);
  539. rc = wmi_rxon(wil, false);
  540. return rc;
  541. }
  542. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  543. {
  544. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  545. b->head, b->head_len);
  546. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  547. b->tail, b->tail_len);
  548. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  549. b->beacon_ies, b->beacon_ies_len);
  550. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  551. b->probe_resp, b->probe_resp_len);
  552. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  553. b->proberesp_ies, b->proberesp_ies_len);
  554. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  555. b->assocresp_ies, b->assocresp_ies_len);
  556. }
  557. static int wil_fix_bcon(struct wil6210_priv *wil,
  558. struct cfg80211_beacon_data *bcon)
  559. {
  560. struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
  561. size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  562. int rc = 0;
  563. if (bcon->probe_resp_len <= hlen)
  564. return 0;
  565. if (!bcon->proberesp_ies) {
  566. bcon->proberesp_ies = f->u.probe_resp.variable;
  567. bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
  568. rc = 1;
  569. }
  570. if (!bcon->assocresp_ies) {
  571. bcon->assocresp_ies = f->u.probe_resp.variable;
  572. bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
  573. rc = 1;
  574. }
  575. return rc;
  576. }
  577. static int wil_cfg80211_change_beacon(struct wiphy *wiphy,
  578. struct net_device *ndev,
  579. struct cfg80211_beacon_data *bcon)
  580. {
  581. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  582. int rc;
  583. wil_dbg_misc(wil, "%s()\n", __func__);
  584. if (wil_fix_bcon(wil, bcon)) {
  585. wil_dbg_misc(wil, "Fixed bcon\n");
  586. wil_print_bcon_data(bcon);
  587. }
  588. /* FW do not form regular beacon, so bcon IE's are not set
  589. * For the DMG bcon, when it will be supported, bcon IE's will
  590. * be reused; add something like:
  591. * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
  592. * bcon->beacon_ies);
  593. */
  594. rc = wmi_set_ie(wil, WMI_FRAME_PROBE_RESP,
  595. bcon->proberesp_ies_len,
  596. bcon->proberesp_ies);
  597. if (rc) {
  598. wil_err(wil, "set_ie(PROBE_RESP) failed\n");
  599. return rc;
  600. }
  601. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP,
  602. bcon->assocresp_ies_len,
  603. bcon->assocresp_ies);
  604. if (rc) {
  605. wil_err(wil, "set_ie(ASSOC_RESP) failed\n");
  606. return rc;
  607. }
  608. return 0;
  609. }
  610. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  611. struct net_device *ndev,
  612. struct cfg80211_ap_settings *info)
  613. {
  614. int rc = 0;
  615. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  616. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  617. struct ieee80211_channel *channel = info->chandef.chan;
  618. struct cfg80211_beacon_data *bcon = &info->beacon;
  619. struct cfg80211_crypto_settings *crypto = &info->crypto;
  620. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  621. wil_dbg_misc(wil, "%s()\n", __func__);
  622. if (!channel) {
  623. wil_err(wil, "AP: No channel???\n");
  624. return -EINVAL;
  625. }
  626. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  627. channel->center_freq, info->privacy ? "secure" : "open");
  628. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  629. info->privacy, info->auth_type);
  630. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  631. info->dtim_period);
  632. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  633. info->ssid, info->ssid_len);
  634. wil_print_bcon_data(bcon);
  635. wil_print_crypto(wil, crypto);
  636. if (wil_fix_bcon(wil, bcon)) {
  637. wil_dbg_misc(wil, "Fixed bcon\n");
  638. wil_print_bcon_data(bcon);
  639. }
  640. wil_set_recovery_state(wil, fw_recovery_idle);
  641. mutex_lock(&wil->mutex);
  642. __wil_down(wil);
  643. rc = __wil_up(wil);
  644. if (rc)
  645. goto out;
  646. rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
  647. if (rc)
  648. goto out;
  649. /* IE's */
  650. /* bcon 'head IE's are not relevant for 60g band */
  651. /*
  652. * FW do not form regular beacon, so bcon IE's are not set
  653. * For the DMG bcon, when it will be supported, bcon IE's will
  654. * be reused; add something like:
  655. * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
  656. * bcon->beacon_ies);
  657. */
  658. wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
  659. bcon->proberesp_ies);
  660. wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
  661. bcon->assocresp_ies);
  662. wil->privacy = info->privacy;
  663. netif_carrier_on(ndev);
  664. rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
  665. channel->hw_value);
  666. if (rc)
  667. goto err_pcp_start;
  668. rc = wil_bcast_init(wil);
  669. if (rc)
  670. goto err_bcast;
  671. goto out; /* success */
  672. err_bcast:
  673. wmi_pcp_stop(wil);
  674. err_pcp_start:
  675. netif_carrier_off(ndev);
  676. out:
  677. mutex_unlock(&wil->mutex);
  678. return rc;
  679. }
  680. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  681. struct net_device *ndev)
  682. {
  683. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  684. wil_dbg_misc(wil, "%s()\n", __func__);
  685. netif_carrier_off(ndev);
  686. wil_set_recovery_state(wil, fw_recovery_idle);
  687. mutex_lock(&wil->mutex);
  688. wmi_pcp_stop(wil);
  689. __wil_down(wil);
  690. __wil_up(wil);
  691. mutex_unlock(&wil->mutex);
  692. /* some functions above might fail (e.g. __wil_up). Nevertheless, we
  693. * return success because AP has stopped
  694. */
  695. return 0;
  696. }
  697. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  698. struct net_device *dev,
  699. struct station_del_parameters *params)
  700. {
  701. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  702. mutex_lock(&wil->mutex);
  703. wil6210_disconnect(wil, params->mac, params->reason_code, false);
  704. mutex_unlock(&wil->mutex);
  705. return 0;
  706. }
  707. /* probe_client handling */
  708. static void wil_probe_client_handle(struct wil6210_priv *wil,
  709. struct wil_probe_client_req *req)
  710. {
  711. struct net_device *ndev = wil_to_ndev(wil);
  712. struct wil_sta_info *sta = &wil->sta[req->cid];
  713. /* assume STA is alive if it is still connected,
  714. * else FW will disconnect it
  715. */
  716. bool alive = (sta->status == wil_sta_connected);
  717. cfg80211_probe_status(ndev, sta->addr, req->cookie, alive, GFP_KERNEL);
  718. }
  719. static struct list_head *next_probe_client(struct wil6210_priv *wil)
  720. {
  721. struct list_head *ret = NULL;
  722. mutex_lock(&wil->probe_client_mutex);
  723. if (!list_empty(&wil->probe_client_pending)) {
  724. ret = wil->probe_client_pending.next;
  725. list_del(ret);
  726. }
  727. mutex_unlock(&wil->probe_client_mutex);
  728. return ret;
  729. }
  730. void wil_probe_client_worker(struct work_struct *work)
  731. {
  732. struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
  733. probe_client_worker);
  734. struct wil_probe_client_req *req;
  735. struct list_head *lh;
  736. while ((lh = next_probe_client(wil)) != NULL) {
  737. req = list_entry(lh, struct wil_probe_client_req, list);
  738. wil_probe_client_handle(wil, req);
  739. kfree(req);
  740. }
  741. }
  742. void wil_probe_client_flush(struct wil6210_priv *wil)
  743. {
  744. struct wil_probe_client_req *req, *t;
  745. wil_dbg_misc(wil, "%s()\n", __func__);
  746. mutex_lock(&wil->probe_client_mutex);
  747. list_for_each_entry_safe(req, t, &wil->probe_client_pending, list) {
  748. list_del(&req->list);
  749. kfree(req);
  750. }
  751. mutex_unlock(&wil->probe_client_mutex);
  752. }
  753. static int wil_cfg80211_probe_client(struct wiphy *wiphy,
  754. struct net_device *dev,
  755. const u8 *peer, u64 *cookie)
  756. {
  757. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  758. struct wil_probe_client_req *req;
  759. int cid = wil_find_cid(wil, peer);
  760. wil_dbg_misc(wil, "%s(%pM => CID %d)\n", __func__, peer, cid);
  761. if (cid < 0)
  762. return -ENOLINK;
  763. req = kzalloc(sizeof(*req), GFP_KERNEL);
  764. if (!req)
  765. return -ENOMEM;
  766. req->cid = cid;
  767. req->cookie = cid;
  768. mutex_lock(&wil->probe_client_mutex);
  769. list_add_tail(&req->list, &wil->probe_client_pending);
  770. mutex_unlock(&wil->probe_client_mutex);
  771. *cookie = req->cookie;
  772. queue_work(wil->wq_service, &wil->probe_client_worker);
  773. return 0;
  774. }
  775. static int wil_cfg80211_change_bss(struct wiphy *wiphy,
  776. struct net_device *dev,
  777. struct bss_parameters *params)
  778. {
  779. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  780. if (params->ap_isolate >= 0) {
  781. wil_dbg_misc(wil, "%s(ap_isolate %d => %d)\n", __func__,
  782. wil->ap_isolate, params->ap_isolate);
  783. wil->ap_isolate = params->ap_isolate;
  784. }
  785. return 0;
  786. }
  787. static struct cfg80211_ops wil_cfg80211_ops = {
  788. .scan = wil_cfg80211_scan,
  789. .connect = wil_cfg80211_connect,
  790. .disconnect = wil_cfg80211_disconnect,
  791. .change_virtual_intf = wil_cfg80211_change_iface,
  792. .get_station = wil_cfg80211_get_station,
  793. .dump_station = wil_cfg80211_dump_station,
  794. .remain_on_channel = wil_remain_on_channel,
  795. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  796. .mgmt_tx = wil_cfg80211_mgmt_tx,
  797. .set_monitor_channel = wil_cfg80211_set_channel,
  798. .add_key = wil_cfg80211_add_key,
  799. .del_key = wil_cfg80211_del_key,
  800. .set_default_key = wil_cfg80211_set_default_key,
  801. /* AP mode */
  802. .change_beacon = wil_cfg80211_change_beacon,
  803. .start_ap = wil_cfg80211_start_ap,
  804. .stop_ap = wil_cfg80211_stop_ap,
  805. .del_station = wil_cfg80211_del_station,
  806. .probe_client = wil_cfg80211_probe_client,
  807. .change_bss = wil_cfg80211_change_bss,
  808. };
  809. static void wil_wiphy_init(struct wiphy *wiphy)
  810. {
  811. /* TODO: set real value */
  812. wiphy->max_scan_ssids = 10;
  813. wiphy->max_scan_ie_len = WMI_MAX_IE_LEN;
  814. wiphy->max_num_pmkids = 0 /* TODO: */;
  815. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  816. BIT(NL80211_IFTYPE_AP) |
  817. BIT(NL80211_IFTYPE_MONITOR);
  818. /* TODO: enable P2P when integrated with supplicant:
  819. * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
  820. */
  821. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  822. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  823. dev_dbg(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  824. __func__, wiphy->flags);
  825. wiphy->probe_resp_offload =
  826. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  827. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  828. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  829. wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
  830. /* TODO: figure this out */
  831. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  832. wiphy->cipher_suites = wil_cipher_suites;
  833. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  834. wiphy->mgmt_stypes = wil_mgmt_stypes;
  835. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS;
  836. }
  837. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  838. {
  839. int rc = 0;
  840. struct wireless_dev *wdev;
  841. dev_dbg(dev, "%s()\n", __func__);
  842. wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
  843. if (!wdev)
  844. return ERR_PTR(-ENOMEM);
  845. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  846. sizeof(struct wil6210_priv));
  847. if (!wdev->wiphy) {
  848. rc = -ENOMEM;
  849. goto out;
  850. }
  851. set_wiphy_dev(wdev->wiphy, dev);
  852. wil_wiphy_init(wdev->wiphy);
  853. rc = wiphy_register(wdev->wiphy);
  854. if (rc < 0)
  855. goto out_failed_reg;
  856. return wdev;
  857. out_failed_reg:
  858. wiphy_free(wdev->wiphy);
  859. out:
  860. kfree(wdev);
  861. return ERR_PTR(rc);
  862. }
  863. void wil_wdev_free(struct wil6210_priv *wil)
  864. {
  865. struct wireless_dev *wdev = wil_to_wdev(wil);
  866. dev_dbg(wil_to_dev(wil), "%s()\n", __func__);
  867. if (!wdev)
  868. return;
  869. wiphy_unregister(wdev->wiphy);
  870. wiphy_free(wdev->wiphy);
  871. kfree(wdev);
  872. }