cfg80211.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. /*
  2. * Copyright (c) 2012 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. rc = wmi_send(wil, WMI_START_SCAN_CMDID, &cmd, sizeof(cmd.cmd) +
  270. cmd.cmd.num_channels * sizeof(cmd.cmd.channel_list[0]));
  271. if (rc)
  272. wil->scan_request = NULL;
  273. return rc;
  274. }
  275. static int wil_cfg80211_connect(struct wiphy *wiphy,
  276. struct net_device *ndev,
  277. struct cfg80211_connect_params *sme)
  278. {
  279. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  280. struct cfg80211_bss *bss;
  281. struct wmi_connect_cmd conn;
  282. const u8 *ssid_eid;
  283. const u8 *rsn_eid;
  284. int ch;
  285. int rc = 0;
  286. if (test_bit(wil_status_fwconnecting, &wil->status) ||
  287. test_bit(wil_status_fwconnected, &wil->status))
  288. return -EALREADY;
  289. bss = cfg80211_get_bss(wiphy, sme->channel, sme->bssid,
  290. sme->ssid, sme->ssid_len,
  291. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  292. if (!bss) {
  293. wil_err(wil, "Unable to find BSS\n");
  294. return -ENOENT;
  295. }
  296. ssid_eid = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  297. if (!ssid_eid) {
  298. wil_err(wil, "No SSID\n");
  299. rc = -ENOENT;
  300. goto out;
  301. }
  302. rsn_eid = sme->ie ?
  303. cfg80211_find_ie(WLAN_EID_RSN, sme->ie, sme->ie_len) :
  304. NULL;
  305. if (rsn_eid) {
  306. if (sme->ie_len > WMI_MAX_IE_LEN) {
  307. rc = -ERANGE;
  308. wil_err(wil, "IE too large (%td bytes)\n",
  309. sme->ie_len);
  310. goto out;
  311. }
  312. /*
  313. * For secure assoc, send:
  314. * (1) WMI_DELETE_CIPHER_KEY_CMD
  315. * (2) WMI_SET_APPIE_CMD
  316. */
  317. rc = wmi_del_cipher_key(wil, 0, bss->bssid);
  318. if (rc) {
  319. wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD failed\n");
  320. goto out;
  321. }
  322. /* WMI_SET_APPIE_CMD */
  323. rc = wmi_set_ie(wil, WMI_FRAME_ASSOC_REQ, sme->ie_len, sme->ie);
  324. if (rc) {
  325. wil_err(wil, "WMI_SET_APPIE_CMD failed\n");
  326. goto out;
  327. }
  328. }
  329. /* WMI_CONNECT_CMD */
  330. memset(&conn, 0, sizeof(conn));
  331. switch (bss->capability & WLAN_CAPABILITY_DMG_TYPE_MASK) {
  332. case WLAN_CAPABILITY_DMG_TYPE_AP:
  333. conn.network_type = WMI_NETTYPE_INFRA;
  334. break;
  335. case WLAN_CAPABILITY_DMG_TYPE_PBSS:
  336. conn.network_type = WMI_NETTYPE_P2P;
  337. break;
  338. default:
  339. wil_err(wil, "Unsupported BSS type, capability= 0x%04x\n",
  340. bss->capability);
  341. goto out;
  342. }
  343. if (rsn_eid) {
  344. conn.dot11_auth_mode = WMI_AUTH11_SHARED;
  345. conn.auth_mode = WMI_AUTH_WPA2_PSK;
  346. conn.pairwise_crypto_type = WMI_CRYPT_AES_GCMP;
  347. conn.pairwise_crypto_len = 16;
  348. } else {
  349. conn.dot11_auth_mode = WMI_AUTH11_OPEN;
  350. conn.auth_mode = WMI_AUTH_NONE;
  351. }
  352. conn.ssid_len = min_t(u8, ssid_eid[1], 32);
  353. memcpy(conn.ssid, ssid_eid+2, conn.ssid_len);
  354. ch = bss->channel->hw_value;
  355. if (ch == 0) {
  356. wil_err(wil, "BSS at unknown frequency %dMhz\n",
  357. bss->channel->center_freq);
  358. rc = -EOPNOTSUPP;
  359. goto out;
  360. }
  361. conn.channel = ch - 1;
  362. memcpy(conn.bssid, bss->bssid, ETH_ALEN);
  363. memcpy(conn.dst_mac, bss->bssid, ETH_ALEN);
  364. set_bit(wil_status_fwconnecting, &wil->status);
  365. rc = wmi_send(wil, WMI_CONNECT_CMDID, &conn, sizeof(conn));
  366. if (rc == 0) {
  367. /* Connect can take lots of time */
  368. mod_timer(&wil->connect_timer,
  369. jiffies + msecs_to_jiffies(2000));
  370. } else {
  371. clear_bit(wil_status_fwconnecting, &wil->status);
  372. }
  373. out:
  374. cfg80211_put_bss(wiphy, bss);
  375. return rc;
  376. }
  377. static int wil_cfg80211_disconnect(struct wiphy *wiphy,
  378. struct net_device *ndev,
  379. u16 reason_code)
  380. {
  381. int rc;
  382. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  383. rc = wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
  384. return rc;
  385. }
  386. int wil_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  387. struct cfg80211_mgmt_tx_params *params,
  388. u64 *cookie)
  389. {
  390. const u8 *buf = params->buf;
  391. size_t len = params->len;
  392. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  393. int rc;
  394. bool tx_status = false;
  395. struct ieee80211_mgmt *mgmt_frame = (void *)buf;
  396. struct wmi_sw_tx_req_cmd *cmd;
  397. struct {
  398. struct wil6210_mbox_hdr_wmi wmi;
  399. struct wmi_sw_tx_complete_event evt;
  400. } __packed evt;
  401. cmd = kmalloc(sizeof(*cmd) + len, GFP_KERNEL);
  402. if (!cmd) {
  403. rc = -ENOMEM;
  404. goto out;
  405. }
  406. memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
  407. cmd->len = cpu_to_le16(len);
  408. memcpy(cmd->payload, buf, len);
  409. rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, cmd, sizeof(*cmd) + len,
  410. WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
  411. if (rc == 0)
  412. tx_status = !evt.evt.status;
  413. kfree(cmd);
  414. out:
  415. cfg80211_mgmt_tx_status(wdev, cookie ? *cookie : 0, buf, len,
  416. tx_status, GFP_KERNEL);
  417. return rc;
  418. }
  419. static int wil_cfg80211_set_channel(struct wiphy *wiphy,
  420. struct cfg80211_chan_def *chandef)
  421. {
  422. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  423. struct wireless_dev *wdev = wil->wdev;
  424. wdev->preset_chandef = *chandef;
  425. return 0;
  426. }
  427. static int wil_cfg80211_add_key(struct wiphy *wiphy,
  428. struct net_device *ndev,
  429. u8 key_index, bool pairwise,
  430. const u8 *mac_addr,
  431. struct key_params *params)
  432. {
  433. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  434. /* group key is not used */
  435. if (!pairwise)
  436. return 0;
  437. return wmi_add_cipher_key(wil, key_index, mac_addr,
  438. params->key_len, params->key);
  439. }
  440. static int wil_cfg80211_del_key(struct wiphy *wiphy,
  441. struct net_device *ndev,
  442. u8 key_index, bool pairwise,
  443. const u8 *mac_addr)
  444. {
  445. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  446. /* group key is not used */
  447. if (!pairwise)
  448. return 0;
  449. return wmi_del_cipher_key(wil, key_index, mac_addr);
  450. }
  451. /* Need to be present or wiphy_new() will WARN */
  452. static int wil_cfg80211_set_default_key(struct wiphy *wiphy,
  453. struct net_device *ndev,
  454. u8 key_index, bool unicast,
  455. bool multicast)
  456. {
  457. return 0;
  458. }
  459. static int wil_remain_on_channel(struct wiphy *wiphy,
  460. struct wireless_dev *wdev,
  461. struct ieee80211_channel *chan,
  462. unsigned int duration,
  463. u64 *cookie)
  464. {
  465. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  466. int rc;
  467. /* TODO: handle duration */
  468. wil_info(wil, "%s(%d, %d ms)\n", __func__, chan->center_freq, duration);
  469. rc = wmi_set_channel(wil, chan->hw_value);
  470. if (rc)
  471. return rc;
  472. rc = wmi_rxon(wil, true);
  473. return rc;
  474. }
  475. static int wil_cancel_remain_on_channel(struct wiphy *wiphy,
  476. struct wireless_dev *wdev,
  477. u64 cookie)
  478. {
  479. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  480. int rc;
  481. wil_info(wil, "%s()\n", __func__);
  482. rc = wmi_rxon(wil, false);
  483. return rc;
  484. }
  485. static void wil_print_bcon_data(struct cfg80211_beacon_data *b)
  486. {
  487. print_hex_dump_bytes("head ", DUMP_PREFIX_OFFSET,
  488. b->head, b->head_len);
  489. print_hex_dump_bytes("tail ", DUMP_PREFIX_OFFSET,
  490. b->tail, b->tail_len);
  491. print_hex_dump_bytes("BCON IE ", DUMP_PREFIX_OFFSET,
  492. b->beacon_ies, b->beacon_ies_len);
  493. print_hex_dump_bytes("PROBE ", DUMP_PREFIX_OFFSET,
  494. b->probe_resp, b->probe_resp_len);
  495. print_hex_dump_bytes("PROBE IE ", DUMP_PREFIX_OFFSET,
  496. b->proberesp_ies, b->proberesp_ies_len);
  497. print_hex_dump_bytes("ASSOC IE ", DUMP_PREFIX_OFFSET,
  498. b->assocresp_ies, b->assocresp_ies_len);
  499. }
  500. static void wil_print_crypto(struct wil6210_priv *wil,
  501. struct cfg80211_crypto_settings *c)
  502. {
  503. wil_dbg_misc(wil, "WPA versions: 0x%08x cipher group 0x%08x\n",
  504. c->wpa_versions, c->cipher_group);
  505. wil_dbg_misc(wil, "Pairwise ciphers [%d]\n", c->n_ciphers_pairwise);
  506. wil_dbg_misc(wil, "AKM suites [%d]\n", c->n_akm_suites);
  507. wil_dbg_misc(wil, "Control port : %d, eth_type 0x%04x no_encrypt %d\n",
  508. c->control_port, be16_to_cpu(c->control_port_ethertype),
  509. c->control_port_no_encrypt);
  510. }
  511. static int wil_fix_bcon(struct wil6210_priv *wil,
  512. struct cfg80211_beacon_data *bcon)
  513. {
  514. struct ieee80211_mgmt *f = (struct ieee80211_mgmt *)bcon->probe_resp;
  515. size_t hlen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  516. int rc = 0;
  517. if (bcon->probe_resp_len <= hlen)
  518. return 0;
  519. if (!bcon->proberesp_ies) {
  520. bcon->proberesp_ies = f->u.probe_resp.variable;
  521. bcon->proberesp_ies_len = bcon->probe_resp_len - hlen;
  522. rc = 1;
  523. }
  524. if (!bcon->assocresp_ies) {
  525. bcon->assocresp_ies = f->u.probe_resp.variable;
  526. bcon->assocresp_ies_len = bcon->probe_resp_len - hlen;
  527. rc = 1;
  528. }
  529. return rc;
  530. }
  531. static int wil_cfg80211_start_ap(struct wiphy *wiphy,
  532. struct net_device *ndev,
  533. struct cfg80211_ap_settings *info)
  534. {
  535. int rc = 0;
  536. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  537. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  538. struct ieee80211_channel *channel = info->chandef.chan;
  539. struct cfg80211_beacon_data *bcon = &info->beacon;
  540. struct cfg80211_crypto_settings *crypto = &info->crypto;
  541. u8 wmi_nettype = wil_iftype_nl2wmi(wdev->iftype);
  542. wil_dbg_misc(wil, "%s()\n", __func__);
  543. if (!channel) {
  544. wil_err(wil, "AP: No channel???\n");
  545. return -EINVAL;
  546. }
  547. wil_dbg_misc(wil, "AP on Channel %d %d MHz, %s\n", channel->hw_value,
  548. channel->center_freq, info->privacy ? "secure" : "open");
  549. wil_dbg_misc(wil, "Privacy: %d auth_type %d\n",
  550. info->privacy, info->auth_type);
  551. wil_dbg_misc(wil, "BI %d DTIM %d\n", info->beacon_interval,
  552. info->dtim_period);
  553. print_hex_dump_bytes("SSID ", DUMP_PREFIX_OFFSET,
  554. info->ssid, info->ssid_len);
  555. wil_print_bcon_data(bcon);
  556. wil_print_crypto(wil, crypto);
  557. if (wil_fix_bcon(wil, bcon)) {
  558. wil_dbg_misc(wil, "Fixed bcon\n");
  559. wil_print_bcon_data(bcon);
  560. }
  561. mutex_lock(&wil->mutex);
  562. rc = wil_reset(wil);
  563. if (rc)
  564. goto out;
  565. /* Rx VRING. */
  566. rc = wil_rx_init(wil);
  567. if (rc)
  568. goto out;
  569. rc = wmi_set_ssid(wil, info->ssid_len, info->ssid);
  570. if (rc)
  571. goto out;
  572. /* MAC address - pre-requisite for other commands */
  573. wmi_set_mac_address(wil, ndev->dev_addr);
  574. /* IE's */
  575. /* bcon 'head IE's are not relevant for 60g band */
  576. /*
  577. * FW do not form regular beacon, so bcon IE's are not set
  578. * For the DMG bcon, when it will be supported, bcon IE's will
  579. * be reused; add something like:
  580. * wmi_set_ie(wil, WMI_FRAME_BEACON, bcon->beacon_ies_len,
  581. * bcon->beacon_ies);
  582. */
  583. wmi_set_ie(wil, WMI_FRAME_PROBE_RESP, bcon->proberesp_ies_len,
  584. bcon->proberesp_ies);
  585. wmi_set_ie(wil, WMI_FRAME_ASSOC_RESP, bcon->assocresp_ies_len,
  586. bcon->assocresp_ies);
  587. wil->secure_pcp = info->privacy;
  588. rc = wmi_pcp_start(wil, info->beacon_interval, wmi_nettype,
  589. channel->hw_value);
  590. if (rc)
  591. goto out;
  592. netif_carrier_on(ndev);
  593. out:
  594. mutex_unlock(&wil->mutex);
  595. return rc;
  596. }
  597. static int wil_cfg80211_stop_ap(struct wiphy *wiphy,
  598. struct net_device *ndev)
  599. {
  600. int rc = 0;
  601. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  602. wil_dbg_misc(wil, "%s()\n", __func__);
  603. mutex_lock(&wil->mutex);
  604. rc = wmi_pcp_stop(wil);
  605. mutex_unlock(&wil->mutex);
  606. return rc;
  607. }
  608. static int wil_cfg80211_del_station(struct wiphy *wiphy,
  609. struct net_device *dev, const u8 *mac)
  610. {
  611. struct wil6210_priv *wil = wiphy_to_wil(wiphy);
  612. mutex_lock(&wil->mutex);
  613. wil6210_disconnect(wil, mac);
  614. mutex_unlock(&wil->mutex);
  615. return 0;
  616. }
  617. static struct cfg80211_ops wil_cfg80211_ops = {
  618. .scan = wil_cfg80211_scan,
  619. .connect = wil_cfg80211_connect,
  620. .disconnect = wil_cfg80211_disconnect,
  621. .change_virtual_intf = wil_cfg80211_change_iface,
  622. .get_station = wil_cfg80211_get_station,
  623. .dump_station = wil_cfg80211_dump_station,
  624. .remain_on_channel = wil_remain_on_channel,
  625. .cancel_remain_on_channel = wil_cancel_remain_on_channel,
  626. .mgmt_tx = wil_cfg80211_mgmt_tx,
  627. .set_monitor_channel = wil_cfg80211_set_channel,
  628. .add_key = wil_cfg80211_add_key,
  629. .del_key = wil_cfg80211_del_key,
  630. .set_default_key = wil_cfg80211_set_default_key,
  631. /* AP mode */
  632. .start_ap = wil_cfg80211_start_ap,
  633. .stop_ap = wil_cfg80211_stop_ap,
  634. .del_station = wil_cfg80211_del_station,
  635. };
  636. static void wil_wiphy_init(struct wiphy *wiphy)
  637. {
  638. /* TODO: set real value */
  639. wiphy->max_scan_ssids = 10;
  640. wiphy->max_num_pmkids = 0 /* TODO: */;
  641. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  642. BIT(NL80211_IFTYPE_AP) |
  643. BIT(NL80211_IFTYPE_MONITOR);
  644. /* TODO: enable P2P when integrated with supplicant:
  645. * BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO)
  646. */
  647. wiphy->flags |= WIPHY_FLAG_HAVE_AP_SME |
  648. WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  649. dev_warn(wiphy_dev(wiphy), "%s : flags = 0x%08x\n",
  650. __func__, wiphy->flags);
  651. wiphy->probe_resp_offload =
  652. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
  653. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
  654. NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
  655. wiphy->bands[IEEE80211_BAND_60GHZ] = &wil_band_60ghz;
  656. /* TODO: figure this out */
  657. wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  658. wiphy->cipher_suites = wil_cipher_suites;
  659. wiphy->n_cipher_suites = ARRAY_SIZE(wil_cipher_suites);
  660. wiphy->mgmt_stypes = wil_mgmt_stypes;
  661. }
  662. struct wireless_dev *wil_cfg80211_init(struct device *dev)
  663. {
  664. int rc = 0;
  665. struct wireless_dev *wdev;
  666. wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  667. if (!wdev)
  668. return ERR_PTR(-ENOMEM);
  669. wdev->wiphy = wiphy_new(&wil_cfg80211_ops,
  670. sizeof(struct wil6210_priv));
  671. if (!wdev->wiphy) {
  672. rc = -ENOMEM;
  673. goto out;
  674. }
  675. set_wiphy_dev(wdev->wiphy, dev);
  676. wil_wiphy_init(wdev->wiphy);
  677. rc = wiphy_register(wdev->wiphy);
  678. if (rc < 0)
  679. goto out_failed_reg;
  680. return wdev;
  681. out_failed_reg:
  682. wiphy_free(wdev->wiphy);
  683. out:
  684. kfree(wdev);
  685. return ERR_PTR(rc);
  686. }
  687. void wil_wdev_free(struct wil6210_priv *wil)
  688. {
  689. struct wireless_dev *wdev = wil_to_wdev(wil);
  690. if (!wdev)
  691. return;
  692. wiphy_unregister(wdev->wiphy);
  693. wiphy_free(wdev->wiphy);
  694. kfree(wdev);
  695. }