wlan_cfg80211_p2p.c 12 KB

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