wlan_cfg80211_p2p.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. /*
  2. * Copyright (c) 2017-2019 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. osif_debug("user data:%pK, vdev id:%d, rssi:%d, buf:%pK, len:%d",
  53. user_data, rx_frame->vdev_id, rx_frame->rx_rssi,
  54. rx_frame->buf, rx_frame->frame_len);
  55. psoc = user_data;
  56. if (!psoc) {
  57. osif_err("psoc is null");
  58. return;
  59. }
  60. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  61. rx_frame->vdev_id, WLAN_P2P_ID);
  62. if (!vdev) {
  63. osif_err("vdev is null");
  64. return;
  65. }
  66. osif_priv = wlan_vdev_get_ospriv(vdev);
  67. if (!osif_priv) {
  68. osif_err("osif_priv is null");
  69. goto fail;
  70. }
  71. wdev = osif_priv->wdev;
  72. if (!wdev) {
  73. osif_err("wdev is null");
  74. goto fail;
  75. }
  76. osif_debug("Indicate frame over nl80211, vdev id:%d, idx:%d",
  77. rx_frame->vdev_id, wdev->netdev->ifindex);
  78. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0))
  79. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  80. rx_frame->buf, rx_frame->frame_len,
  81. NL80211_RXMGMT_FLAG_ANSWERED);
  82. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0))
  83. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  84. rx_frame->buf, rx_frame->frame_len,
  85. NL80211_RXMGMT_FLAG_ANSWERED, GFP_ATOMIC);
  86. #else
  87. cfg80211_rx_mgmt(wdev, rx_frame->rx_freq, rx_frame->rx_rssi * 100,
  88. rx_frame->buf, rx_frame->frame_len, GFP_ATOMIC);
  89. #endif /* LINUX_VERSION_CODE */
  90. fail:
  91. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  92. }
  93. /**
  94. * wlan_p2p_action_tx_cnf_callback() - Callback for tx confirmation
  95. * @user_data: pointer to soc object
  96. * @tx_cnf: tx confirmation information
  97. *
  98. * This callback will be used to give tx mgmt frame confirmation to
  99. * os interface.
  100. *
  101. * Return: None
  102. */
  103. static void wlan_p2p_action_tx_cnf_callback(void *user_data,
  104. struct p2p_tx_cnf *tx_cnf)
  105. {
  106. struct wlan_objmgr_psoc *psoc;
  107. struct wlan_objmgr_vdev *vdev;
  108. struct vdev_osif_priv *osif_priv;
  109. struct wireless_dev *wdev;
  110. bool is_success;
  111. osif_debug("user data:%pK, action cookie:%llx, buf:%pK, len:%d, tx status:%d",
  112. user_data, tx_cnf->action_cookie, tx_cnf->buf,
  113. tx_cnf->buf_len, tx_cnf->status);
  114. psoc = user_data;
  115. if (!psoc) {
  116. osif_err("psoc is null");
  117. return;
  118. }
  119. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  120. tx_cnf->vdev_id, WLAN_P2P_ID);
  121. if (!vdev) {
  122. osif_err("vdev is null");
  123. return;
  124. }
  125. osif_priv = wlan_vdev_get_ospriv(vdev);
  126. if (!osif_priv) {
  127. osif_err("osif_priv is null");
  128. goto fail;
  129. }
  130. wdev = osif_priv->wdev;
  131. if (!wdev) {
  132. osif_err("wireless dev is null");
  133. goto fail;
  134. }
  135. is_success = tx_cnf->status ? false : true;
  136. cfg80211_mgmt_tx_status(
  137. wdev,
  138. tx_cnf->action_cookie,
  139. tx_cnf->buf, tx_cnf->buf_len,
  140. is_success, GFP_KERNEL);
  141. fail:
  142. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  143. }
  144. #ifdef FEATURE_P2P_LISTEN_OFFLOAD
  145. /**
  146. * wlan_p2p_lo_event_callback() - Callback for listen offload event
  147. * @user_data: pointer to soc object
  148. * @p2p_lo_event: listen offload event information
  149. *
  150. * This callback will be used to give listen offload event to os interface.
  151. *
  152. * Return: None
  153. */
  154. static void wlan_p2p_lo_event_callback(void *user_data,
  155. struct p2p_lo_event *p2p_lo_event)
  156. {
  157. struct wlan_objmgr_psoc *psoc;
  158. struct wlan_objmgr_vdev *vdev;
  159. struct vdev_osif_priv *osif_priv;
  160. struct wireless_dev *wdev;
  161. struct sk_buff *vendor_event;
  162. osif_debug("user data:%pK, vdev id:%d, reason code:%d",
  163. user_data, p2p_lo_event->vdev_id,
  164. p2p_lo_event->reason_code);
  165. psoc = user_data;
  166. if (!psoc) {
  167. osif_err("psoc is null");
  168. return;
  169. }
  170. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  171. p2p_lo_event->vdev_id, WLAN_P2P_ID);
  172. if (!vdev) {
  173. osif_err("vdev is null");
  174. return;
  175. }
  176. osif_priv = wlan_vdev_get_ospriv(vdev);
  177. if (!osif_priv) {
  178. osif_err("osif_priv is null");
  179. goto fail;
  180. }
  181. wdev = osif_priv->wdev;
  182. if (!wdev) {
  183. osif_err("wireless dev is null");
  184. goto fail;
  185. }
  186. vendor_event = cfg80211_vendor_event_alloc(wdev->wiphy, NULL,
  187. sizeof(uint32_t) + NLMSG_HDRLEN,
  188. QCA_NL80211_VENDOR_SUBCMD_P2P_LO_EVENT_INDEX,
  189. GFP_KERNEL);
  190. if (!vendor_event) {
  191. osif_err("cfg80211_vendor_event_alloc failed");
  192. goto fail;
  193. }
  194. if (nla_put_u32(vendor_event,
  195. QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_STOP_REASON,
  196. p2p_lo_event->reason_code)) {
  197. osif_err("nla put failed");
  198. kfree_skb(vendor_event);
  199. goto fail;
  200. }
  201. cfg80211_vendor_event(vendor_event, GFP_KERNEL);
  202. fail:
  203. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  204. }
  205. static inline void wlan_p2p_init_lo_event(struct p2p_start_param *start_param,
  206. struct wlan_objmgr_psoc *psoc)
  207. {
  208. start_param->lo_event_cb = wlan_p2p_lo_event_callback;
  209. start_param->lo_event_cb_data = psoc;
  210. }
  211. #else
  212. static inline void wlan_p2p_init_lo_event(struct p2p_start_param *start_param,
  213. struct wlan_objmgr_psoc *psoc)
  214. {
  215. }
  216. #endif /* FEATURE_P2P_LISTEN_OFFLOAD */
  217. /**
  218. * wlan_p2p_event_callback() - Callback for P2P event
  219. * @user_data: pointer to soc object
  220. * @p2p_event: p2p event information
  221. *
  222. * This callback will be used to give p2p event to os interface.
  223. *
  224. * Return: None
  225. */
  226. static void wlan_p2p_event_callback(void *user_data,
  227. struct p2p_event *p2p_event)
  228. {
  229. struct wlan_objmgr_psoc *psoc;
  230. struct wlan_objmgr_vdev *vdev;
  231. struct ieee80211_channel *chan;
  232. struct vdev_osif_priv *osif_priv;
  233. struct wireless_dev *wdev;
  234. osif_debug("user data:%pK, vdev id:%d, event type:%d",
  235. user_data, p2p_event->vdev_id, p2p_event->roc_event);
  236. psoc = user_data;
  237. if (!psoc) {
  238. osif_err("psoc is null");
  239. return;
  240. }
  241. vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc,
  242. p2p_event->vdev_id, WLAN_P2P_ID);
  243. if (!vdev) {
  244. osif_err("vdev is null");
  245. return;
  246. }
  247. osif_priv = wlan_vdev_get_ospriv(vdev);
  248. if (!osif_priv) {
  249. osif_err("osif_priv is null");
  250. goto fail;
  251. }
  252. wdev = osif_priv->wdev;
  253. if (!wdev) {
  254. osif_err("wireless dev is null");
  255. goto fail;
  256. }
  257. chan = ieee80211_get_channel(wdev->wiphy,
  258. wlan_chan_to_freq(p2p_event->chan));
  259. if (!chan) {
  260. osif_err("channel conversion failed");
  261. goto fail;
  262. }
  263. if (p2p_event->roc_event == ROC_EVENT_READY_ON_CHAN) {
  264. cfg80211_ready_on_channel(wdev,
  265. p2p_event->cookie, chan,
  266. p2p_event->duration, GFP_KERNEL);
  267. } else if (p2p_event->roc_event == ROC_EVENT_COMPLETED) {
  268. cfg80211_remain_on_channel_expired(wdev,
  269. p2p_event->cookie, chan, GFP_KERNEL);
  270. } else {
  271. osif_err("Invalid p2p event");
  272. }
  273. fail:
  274. wlan_objmgr_vdev_release_ref(vdev, WLAN_P2P_ID);
  275. }
  276. QDF_STATUS p2p_psoc_enable(struct wlan_objmgr_psoc *psoc)
  277. {
  278. struct p2p_start_param start_param;
  279. if (!psoc) {
  280. osif_err("psoc null");
  281. return QDF_STATUS_E_INVAL;
  282. }
  283. start_param.rx_cb = wlan_p2p_rx_callback;
  284. start_param.rx_cb_data = psoc;
  285. start_param.event_cb = wlan_p2p_event_callback;
  286. start_param.event_cb_data = psoc;
  287. start_param.tx_cnf_cb = wlan_p2p_action_tx_cnf_callback;
  288. start_param.tx_cnf_cb_data = psoc;
  289. wlan_p2p_init_lo_event(&start_param, psoc);
  290. return ucfg_p2p_psoc_start(psoc, &start_param);
  291. }
  292. QDF_STATUS p2p_psoc_disable(struct wlan_objmgr_psoc *psoc)
  293. {
  294. if (!psoc) {
  295. osif_err("psoc null");
  296. return QDF_STATUS_E_INVAL;
  297. }
  298. return ucfg_p2p_psoc_stop(psoc);
  299. }
  300. int wlan_cfg80211_roc(struct wlan_objmgr_vdev *vdev,
  301. struct ieee80211_channel *chan, uint32_t duration,
  302. uint64_t *cookie)
  303. {
  304. struct p2p_roc_req roc_req = {0};
  305. struct wlan_objmgr_psoc *psoc;
  306. uint8_t vdev_id;
  307. bool ok;
  308. int ret;
  309. if (!vdev) {
  310. osif_err("invalid vdev object");
  311. return -EINVAL;
  312. }
  313. if (!chan) {
  314. osif_err("invalid channel");
  315. return -EINVAL;
  316. }
  317. psoc = wlan_vdev_get_psoc(vdev);
  318. vdev_id = wlan_vdev_get_id(vdev);
  319. if (!psoc) {
  320. osif_err("psoc handle is NULL");
  321. return -EINVAL;
  322. }
  323. roc_req.chan = (uint32_t)wlan_freq_to_chan(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, roc_req.chan, &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. if (!vdev) {
  366. osif_err("invalid vdev object");
  367. return -EINVAL;
  368. }
  369. if (chan)
  370. channel = (uint32_t)wlan_freq_to_chan(chan->center_freq);
  371. else
  372. osif_debug("NULL chan, set channel to 0");
  373. psoc = wlan_vdev_get_psoc(vdev);
  374. vdev_id = wlan_vdev_get_id(vdev);
  375. if (!psoc) {
  376. osif_err("psoc handle is NULL");
  377. return -EINVAL;
  378. }
  379. /**
  380. * When offchannel time is more than MAX_OFFCHAN_TIME_FOR_DNBS,
  381. * allow offchannel only if Do_Not_Switch_Channel is not set.
  382. */
  383. if (wait > MAX_OFFCHAN_TIME_FOR_DNBS) {
  384. int ret;
  385. bool ok;
  386. ret = policy_mgr_is_chan_ok_for_dnbs(psoc, channel, &ok);
  387. if (QDF_IS_STATUS_ERROR(ret)) {
  388. osif_err("policy_mgr_is_chan_ok_for_dnbs():ret:%d",
  389. ret);
  390. return -EINVAL;
  391. }
  392. if (!ok) {
  393. osif_err("Rejecting mgmt_tx for channel:%d as DNSC is set",
  394. channel);
  395. return -EINVAL;
  396. }
  397. }
  398. mgmt_tx.vdev_id = (uint32_t)vdev_id;
  399. mgmt_tx.chan = channel;
  400. mgmt_tx.wait = wait;
  401. mgmt_tx.len = len;
  402. mgmt_tx.no_cck = (uint32_t)no_cck;
  403. mgmt_tx.dont_wait_for_ack = (uint32_t)dont_wait_for_ack;
  404. mgmt_tx.off_chan = (uint32_t)offchan;
  405. mgmt_tx.buf = buf;
  406. return qdf_status_to_os_return(
  407. ucfg_p2p_mgmt_tx(psoc, &mgmt_tx, cookie));
  408. }
  409. int wlan_cfg80211_mgmt_tx_cancel(struct wlan_objmgr_vdev *vdev,
  410. uint64_t cookie)
  411. {
  412. struct wlan_objmgr_psoc *psoc;
  413. if (!vdev) {
  414. osif_err("invalid vdev object");
  415. return -EINVAL;
  416. }
  417. psoc = wlan_vdev_get_psoc(vdev);
  418. if (!psoc) {
  419. osif_err("psoc handle is NULL");
  420. return -EINVAL;
  421. }
  422. return qdf_status_to_os_return(
  423. ucfg_p2p_mgmt_tx_cancel(psoc, vdev, cookie));
  424. }