wlan_cfg80211_p2p.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /*
  2. * Copyright (c) 2017-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /**
  19. * DOC: defines driver functions interfacing with linux kernel
  20. */
  21. #include <qdf_util.h>
  22. #include <wlan_objmgr_psoc_obj.h>
  23. #include <wlan_objmgr_global_obj.h>
  24. #include <wlan_objmgr_pdev_obj.h>
  25. #include <wlan_objmgr_vdev_obj.h>
  26. #include <wlan_objmgr_peer_obj.h>
  27. #include <wlan_p2p_public_struct.h>
  28. #include <wlan_p2p_ucfg_api.h>
  29. #include <wlan_policy_mgr_api.h>
  30. #include <wlan_utility.h>
  31. #include <wlan_osif_priv.h>
  32. #include "wlan_cfg80211.h"
  33. #include "wlan_cfg80211_p2p.h"
  34. #define MAX_NO_OF_2_4_CHANNELS 14
  35. #define MAX_OFFCHAN_TIME_FOR_DNBS 150
  36. /**
  37. * wlan_p2p_rx_callback() - Callback for rx mgmt frame
  38. * @user_data: pointer to soc object
  39. * @rx_frame: RX mgmt frame information
  40. *
  41. * This callback will be used to rx frames in os interface.
  42. *
  43. * Return: None
  44. */
  45. static void wlan_p2p_rx_callback(void *user_data,
  46. struct p2p_rx_mgmt_frame *rx_frame)
  47. {
  48. struct wlan_objmgr_psoc *psoc;
  49. struct wlan_objmgr_vdev *vdev;
  50. struct vdev_osif_priv *osif_priv;
  51. struct wireless_dev *wdev;
  52. psoc = user_data;
  53. if (!psoc) {
  54. osif_err("psoc is null");
  55. return;
  56. }
  57. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  58. rx_frame->vdev_id, WLAN_P2P_ID);
  59. if (!vdev) {
  60. osif_err("vdev is null");
  61. return;
  62. }
  63. osif_priv = wlan_vdev_get_ospriv(vdev);
  64. if (!osif_priv) {
  65. osif_err("osif_priv is null");
  66. goto fail;
  67. }
  68. wdev = osif_priv->wdev;
  69. if (!wdev) {
  70. osif_err("wdev is null");
  71. goto fail;
  72. }
  73. osif_debug("Indicate frame over nl80211, idx:%d",
  74. wdev->netdev->ifindex);
  75. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
  76. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  77. rx_frame->buf, rx_frame->frame_len,
  78. NL80211_RXMGMT_FLAG_ANSWERED);
  79. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0))
  80. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  81. rx_frame->buf, rx_frame->frame_len,
  82. NL80211_RXMGMT_FLAG_ANSWERED, GFP_ATOMIC);
  83. #else
  84. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  85. rx_frame->buf, rx_frame->frame_len, GFP_ATOMIC);
  86. #endif /* LINUX_VERSION_CODE */
  87. fail:
  88. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  89. }
  90. /**
  91. * wlan_p2p_action_tx_cnf_callback() - Callback for tx confirmation
  92. * @user_data: pointer to soc object
  93. * @tx_cnf: tx confirmation information
  94. *
  95. * This callback will be used to give tx mgmt frame confirmation to
  96. * os interface.
  97. *
  98. * Return: None
  99. */
  100. static void wlan_p2p_action_tx_cnf_callback(void *user_data,
  101. struct p2p_tx_cnf *tx_cnf)
  102. {
  103. struct wlan_objmgr_psoc *psoc;
  104. struct wlan_objmgr_vdev *vdev;
  105. struct vdev_osif_priv *osif_priv;
  106. struct wireless_dev *wdev;
  107. bool is_success;
  108. psoc = user_data;
  109. if (!psoc) {
  110. osif_err("psoc is null");
  111. return;
  112. }
  113. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  114. tx_cnf->vdev_id, WLAN_P2P_ID);
  115. if (!vdev) {
  116. osif_err("vdev is null");
  117. return;
  118. }
  119. osif_priv = wlan_vdev_get_ospriv(vdev);
  120. if (!osif_priv) {
  121. osif_err("osif_priv is null");
  122. goto fail;
  123. }
  124. wdev = osif_priv->wdev;
  125. if (!wdev) {
  126. osif_err("wireless dev is null");
  127. goto fail;
  128. }
  129. is_success = tx_cnf->status ? false : true;
  130. cfg80211_mgmt_tx_status(
  131. wdev,
  132. tx_cnf->action_cookie,
  133. tx_cnf->buf, tx_cnf->buf_len,
  134. is_success, GFP_KERNEL);
  135. fail:
  136. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  137. }
  138. #ifdef FEATURE_P2P_LISTEN_OFFLOAD
  139. /**
  140. * wlan_p2p_lo_event_callback() - Callback for listen offload event
  141. * @user_data: pointer to soc object
  142. * @p2p_lo_event: listen offload event information
  143. *
  144. * This callback will be used to give listen offload event to os interface.
  145. *
  146. * Return: None
  147. */
  148. static void wlan_p2p_lo_event_callback(void *user_data,
  149. struct p2p_lo_event *p2p_lo_event)
  150. {
  151. struct wlan_objmgr_psoc *psoc;
  152. struct wlan_objmgr_vdev *vdev;
  153. struct vdev_osif_priv *osif_priv;
  154. struct wireless_dev *wdev;
  155. struct sk_buff *vendor_event;
  156. osif_debug("user data:%pK, vdev id:%d, reason code:%d",
  157. user_data, p2p_lo_event->vdev_id,
  158. p2p_lo_event->reason_code);
  159. psoc = user_data;
  160. if (!psoc) {
  161. osif_err("psoc is null");
  162. return;
  163. }
  164. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  165. p2p_lo_event->vdev_id, WLAN_P2P_ID);
  166. if (!vdev) {
  167. osif_err("vdev is null");
  168. return;
  169. }
  170. osif_priv = wlan_vdev_get_ospriv(vdev);
  171. if (!osif_priv) {
  172. osif_err("osif_priv is null");
  173. goto fail;
  174. }
  175. wdev = osif_priv->wdev;
  176. if (!wdev) {
  177. osif_err("wireless dev is null");
  178. goto fail;
  179. }
  180. vendor_event = cfg80211_vendor_event_alloc(wdev->wiphy, NULL,
  181. sizeof(uint32_t) + NLMSG_HDRLEN,
  182. QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
  183. GFP_KERNEL);
  184. if (!vendor_event) {
  185. osif_err("cfg80211_vendor_event_alloc failed");
  186. goto fail;
  187. }
  188. if (nla_put_u32(vendor_event,
  189. QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
  190. p2p_lo_event->reason_code)) {
  191. osif_err("nla put failed");
  192. kfree_skb(vendor_event);
  193. goto fail;
  194. }
  195. cfg80211_vendor_event(vendor_event, GFP_KERNEL);
  196. fail:
  197. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  198. }
  199. static inline void wlan_p2p_init_lo_event(struct p2p_start_param *start_param,
  200. struct wlan_objmgr_psoc *psoc)
  201. {
  202. start_param->lo_event_cb = wlan_p2p_lo_event_callback;
  203. start_param->lo_event_cb_data = psoc;
  204. }
  205. #else
  206. static inline void wlan_p2p_init_lo_event(struct p2p_start_param *start_param,
  207. struct wlan_objmgr_psoc *psoc)
  208. {
  209. }
  210. #endif /* FEATURE_P2P_LISTEN_OFFLOAD */
  211. /**
  212. * wlan_p2p_event_callback() - Callback for P2P event
  213. * @user_data: pointer to soc object
  214. * @p2p_event: p2p event information
  215. *
  216. * This callback will be used to give p2p event to os interface.
  217. *
  218. * Return: None
  219. */
  220. static void wlan_p2p_event_callback(void *user_data,
  221. struct p2p_event *p2p_event)
  222. {
  223. struct wlan_objmgr_psoc *psoc;
  224. struct wlan_objmgr_vdev *vdev;
  225. struct ieee80211_channel *chan;
  226. struct vdev_osif_priv *osif_priv;
  227. struct wireless_dev *wdev;
  228. struct wlan_objmgr_pdev *pdev;
  229. osif_debug("user data:%pK, vdev id:%d, event type:%d",
  230. user_data, p2p_event->vdev_id, p2p_event->roc_event);
  231. psoc = user_data;
  232. if (!psoc) {
  233. osif_err("psoc is null");
  234. return;
  235. }
  236. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  237. p2p_event->vdev_id, WLAN_P2P_ID);
  238. if (!vdev) {
  239. osif_err("vdev is null");
  240. return;
  241. }
  242. osif_priv = wlan_vdev_get_ospriv(vdev);
  243. if (!osif_priv) {
  244. osif_err("osif_priv is null");
  245. goto fail;
  246. }
  247. wdev = osif_priv->wdev;
  248. if (!wdev) {
  249. osif_err("wireless dev is null");
  250. goto fail;
  251. }
  252. pdev = wlan_vdev_get_pdev(vdev);
  253. chan = ieee80211_get_channel(wdev->wiphy,
  254. wlan_reg_legacy_chan_to_freq(
  255. pdev,
  256. p2p_event->chan));
  257. if (!chan) {
  258. osif_err("channel conversion failed");
  259. goto fail;
  260. }
  261. if (p2p_event->roc_event == ROC_EVENT_READY_ON_CHAN) {
  262. cfg80211_ready_on_channel(wdev,
  263. p2p_event->cookie, chan,
  264. p2p_event->duration, GFP_KERNEL);
  265. } else if (p2p_event->roc_event == ROC_EVENT_COMPLETED) {
  266. cfg80211_remain_on_channel_expired(wdev,
  267. p2p_event->cookie, chan, GFP_KERNEL);
  268. } else {
  269. osif_err("Invalid p2p event");
  270. }
  271. fail:
  272. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  273. }
  274. QDF_STATUS p2p_psoc_enable(struct wlan_objmgr_psoc *psoc)
  275. {
  276. struct p2p_start_param start_param;
  277. if (!psoc) {
  278. osif_err("psoc null");
  279. return QDF_STATUS_E_INVAL;
  280. }
  281. start_param.rx_cb = wlan_p2p_rx_callback;
  282. start_param.rx_cb_data = psoc;
  283. start_param.event_cb = wlan_p2p_event_callback;
  284. start_param.event_cb_data = psoc;
  285. start_param.tx_cnf_cb = wlan_p2p_action_tx_cnf_callback;
  286. start_param.tx_cnf_cb_data = psoc;
  287. wlan_p2p_init_lo_event(&start_param, psoc);
  288. return ucfg_p2p_psoc_start(psoc, &start_param);
  289. }
  290. QDF_STATUS p2p_psoc_disable(struct wlan_objmgr_psoc *psoc)
  291. {
  292. if (!psoc) {
  293. osif_err("psoc null");
  294. return QDF_STATUS_E_INVAL;
  295. }
  296. return ucfg_p2p_psoc_stop(psoc);
  297. }
  298. int wlan_cfg80211_roc(struct wlan_objmgr_vdev *vdev,
  299. struct ieee80211_channel *chan, uint32_t duration,
  300. uint64_t *cookie)
  301. {
  302. struct p2p_roc_req roc_req = {0};
  303. struct wlan_objmgr_psoc *psoc;
  304. uint8_t vdev_id;
  305. bool ok;
  306. int ret;
  307. struct wlan_objmgr_pdev *pdev = NULL;
  308. if (!vdev) {
  309. osif_err("invalid vdev object");
  310. return -EINVAL;
  311. }
  312. if (!chan) {
  313. osif_err("invalid channel");
  314. return -EINVAL;
  315. }
  316. psoc = wlan_vdev_get_psoc(vdev);
  317. vdev_id = wlan_vdev_get_id(vdev);
  318. pdev = wlan_vdev_get_pdev(vdev);
  319. if (!psoc) {
  320. osif_err("psoc handle is NULL");
  321. return -EINVAL;
  322. }
  323. roc_req.chan = (uint32_t)wlan_reg_freq_to_chan(pdev, chan->center_freq);
  324. roc_req.duration = duration;
  325. roc_req.vdev_id = (uint32_t)vdev_id;
  326. ret = policy_mgr_is_chan_ok_for_dnbs(psoc, chan->center_freq, &ok);
  327. if (QDF_IS_STATUS_ERROR(ret)) {
  328. osif_err("policy_mgr_is_chan_ok_for_dnbs():ret:%d",
  329. ret);
  330. return -EINVAL;
  331. }
  332. if (!ok) {
  333. osif_err("channel%d not OK for DNBS", roc_req.chan);
  334. return -EINVAL;
  335. }
  336. return qdf_status_to_os_return(
  337. ucfg_p2p_roc_req(psoc, &roc_req, cookie));
  338. }
  339. int wlan_cfg80211_cancel_roc(struct wlan_objmgr_vdev *vdev,
  340. uint64_t cookie)
  341. {
  342. struct wlan_objmgr_psoc *psoc;
  343. if (!vdev) {
  344. osif_err("invalid vdev object");
  345. return -EINVAL;
  346. }
  347. psoc = wlan_vdev_get_psoc(vdev);
  348. if (!psoc) {
  349. osif_err("psoc handle is NULL");
  350. return -EINVAL;
  351. }
  352. return qdf_status_to_os_return(
  353. ucfg_p2p_roc_cancel_req(psoc, cookie));
  354. }
  355. int wlan_cfg80211_mgmt_tx(struct wlan_objmgr_vdev *vdev,
  356. struct ieee80211_channel *chan, bool offchan,
  357. unsigned int wait,
  358. const uint8_t *buf, uint32_t len, bool no_cck,
  359. bool dont_wait_for_ack, uint64_t *cookie)
  360. {
  361. struct p2p_mgmt_tx mgmt_tx = {0};
  362. struct wlan_objmgr_psoc *psoc;
  363. uint8_t vdev_id;
  364. uint32_t channel = 0;
  365. struct wlan_objmgr_pdev *pdev = NULL;
  366. if (!vdev) {
  367. osif_err("invalid vdev object");
  368. return -EINVAL;
  369. }
  370. pdev = wlan_vdev_get_pdev(vdev);
  371. if (chan)
  372. channel = (uint32_t)wlan_reg_freq_to_chan(pdev,
  373. chan->center_freq);
  374. else
  375. osif_debug("NULL chan, set channel to 0");
  376. psoc = wlan_vdev_get_psoc(vdev);
  377. vdev_id = wlan_vdev_get_id(vdev);
  378. if (!psoc) {
  379. osif_err("psoc handle is NULL");
  380. return -EINVAL;
  381. }
  382. /**
  383. * When offchannel time is more than MAX_OFFCHAN_TIME_FOR_DNBS,
  384. * allow offchannel only if Do_Not_Switch_Channel is not set.
  385. */
  386. if (wait > MAX_OFFCHAN_TIME_FOR_DNBS) {
  387. int ret;
  388. bool ok;
  389. ret = policy_mgr_is_chan_ok_for_dnbs(
  390. psoc, wlan_reg_legacy_chan_to_freq(pdev,
  391. channel),
  392. &ok);
  393. if (QDF_IS_STATUS_ERROR(ret)) {
  394. osif_err("policy_mgr_is_chan_ok_for_dnbs():ret:%d",
  395. ret);
  396. return -EINVAL;
  397. }
  398. if (!ok) {
  399. osif_err("Rejecting mgmt_tx for channel:%d as DNSC is set",
  400. channel);
  401. return -EINVAL;
  402. }
  403. }
  404. mgmt_tx.vdev_id = (uint32_t)vdev_id;
  405. mgmt_tx.chan = channel;
  406. mgmt_tx.wait = wait;
  407. mgmt_tx.len = len;
  408. mgmt_tx.no_cck = (uint32_t)no_cck;
  409. mgmt_tx.dont_wait_for_ack = (uint32_t)dont_wait_for_ack;
  410. mgmt_tx.off_chan = (uint32_t)offchan;
  411. mgmt_tx.buf = buf;
  412. return qdf_status_to_os_return(
  413. ucfg_p2p_mgmt_tx(psoc, &mgmt_tx, cookie, pdev));
  414. }
  415. int wlan_cfg80211_mgmt_tx_cancel(struct wlan_objmgr_vdev *vdev,
  416. uint64_t cookie)
  417. {
  418. struct wlan_objmgr_psoc *psoc;
  419. if (!vdev) {
  420. osif_err("invalid vdev object");
  421. return -EINVAL;
  422. }
  423. psoc = wlan_vdev_get_psoc(vdev);
  424. if (!psoc) {
  425. osif_err("psoc handle is NULL");
  426. return -EINVAL;
  427. }
  428. return qdf_status_to_os_return(
  429. ucfg_p2p_mgmt_tx_cancel(psoc, vdev, cookie));
  430. }