cfg80211.c 23 KB

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