cfg80211.c 19 KB

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