blob: dda46a0142624349e9acecce1e96f996ccacf697 [file] [log] [blame]
Abhinav Kumardbbfd2c2019-05-07 12:22:06 +05301/*
2 * Copyright (c) 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/**
20 * DOC: wlan_hdd_bcn_recv.c
21 * Feature for receiving beacons of connected AP and sending select
22 * params to upper layer via vendor event
23 */
24
25#include <wlan_hdd_includes.h>
26#include <net/cfg80211.h>
27#include "wlan_osif_priv.h"
28#include "qdf_trace.h"
29#include "wlan_hdd_main.h"
30#include "osif_sync.h"
31#include "wlan_hdd_bcn_recv.h"
32
33static const struct nla_policy
34beacon_reporting_params[QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_MAX + 1] = {
35 [QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_OP_TYPE] = {.type = NLA_U8},
36 [QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_ACTIVE_REPORTING] = {.type =
37 NLA_FLAG},
38 [QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_PERIOD] = {.type = NLA_U8},
39};
40
41/**
42 * __wlan_hdd_cfg80211_bcn_rcv_start() - enable/disable beacon reporting
43 * indication
44 * @wiphy: Pointer to wireless phy
45 * @wdev: Pointer to wireless device
46 * @data: Pointer to data
47 * @data_len: Length of @data
48 *
49 * This function is used to enable/disable asynchronous beacon
50 * reporting feature using vendor commands.
51 *
52 * Return: 0 on success, negative errno on failure
53 */
54static int __wlan_hdd_cfg80211_bcn_rcv_start(struct wiphy *wiphy,
55 struct wireless_dev *wdev,
56 const void *data, int data_len)
57{
58 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
59 struct net_device *dev = wdev->netdev;
60 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
61 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_MAX + 1];
62 uint32_t bcn_report;
63 int errno;
64 QDF_STATUS qdf_status = QDF_STATUS_SUCCESS;
65
66 hdd_enter_dev(dev);
67
68 errno = hdd_validate_adapter(adapter);
69 if (errno)
70 return errno;
71
72 if (adapter->device_mode != QDF_STA_MODE) {
73 hdd_err("Command not allowed as device not in STA mode");
74 return -EINVAL;
75 }
76
77 errno =
78 wlan_cfg80211_nla_parse(tb,
79 QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_MAX,
80 data, data_len, beacon_reporting_params);
81 if (errno) {
82 hdd_err("Invalid ATTR");
83 return -EINVAL;
84 }
85
86 /* Parse and fetch OP Type */
87 if (!tb[QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_OP_TYPE]) {
88 hdd_err("attr beacon report OP type failed");
89 return -EINVAL;
90 }
91
92 bcn_report =
93 nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_BEACON_REPORTING_OP_TYPE]);
94 hdd_debug("Bcn Report: OP type:%d", bcn_report);
95
96 if (bcn_report == QCA_WLAN_VENDOR_BEACON_REPORTING_OP_START) {
97 /* Vendor event is intended for Start*/
98 qdf_status =
99 sme_handle_bcn_recv_start(hdd_ctx->mac_handle,
100 adapter->vdev_id);
101 if (QDF_IS_STATUS_ERROR(qdf_status))
102 hdd_err("beacon receive start failed with status=%d",
103 qdf_status);
104 }
105
106 errno = qdf_status_to_os_return(qdf_status);
107 return errno;
108}
109
110int wlan_hdd_cfg80211_bcn_rcv_start(struct wiphy *wiphy,
111 struct wireless_dev *wdev,
112 const void *data, int data_len)
113{
114 int errno;
115 struct osif_vdev_sync *vdev_sync;
116
117 errno = osif_vdev_sync_op_start(wdev->netdev, &vdev_sync);
118 if (errno)
119 return errno;
120
121 errno = __wlan_hdd_cfg80211_bcn_rcv_start(wiphy, wdev,
122 data, data_len);
123
124 osif_vdev_sync_op_stop(vdev_sync);
125
126 return errno;
127}