1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2018 The Linux Foundation. All rights reserved.
3*5113495bSYour Name *
4*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
5*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
6*5113495bSYour Name * above copyright notice and this permission notice appear in all
7*5113495bSYour Name * copies.
8*5113495bSYour Name *
9*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
17*5113495bSYour Name */
18*5113495bSYour Name
19*5113495bSYour Name /**
20*5113495bSYour Name * DOC: implementation of the driver FTM functions interfacing with linux kernel
21*5113495bSYour Name */
22*5113495bSYour Name
23*5113495bSYour Name #include <net/cfg80211.h>
24*5113495bSYour Name #include <qdf_util.h>
25*5113495bSYour Name #include <wlan_objmgr_pdev_obj.h>
26*5113495bSYour Name #include <wlan_cfg80211.h>
27*5113495bSYour Name #include <wlan_cfg80211_ftm.h>
28*5113495bSYour Name #include <wlan_ftm_ucfg_api.h>
29*5113495bSYour Name #include <wlan_osif_priv.h>
30*5113495bSYour Name #include <qdf_types.h>
31*5113495bSYour Name #include <qdf_module.h>
32*5113495bSYour Name
33*5113495bSYour Name static const struct nla_policy
34*5113495bSYour Name wlan_cfg80211_ftm_policy[WLAN_CFG80211_FTM_ATTR_MAX + 1] = {
35*5113495bSYour Name [WLAN_CFG80211_FTM_ATTR_CMD] = {.type = NLA_U32},
36*5113495bSYour Name [WLAN_CFG80211_FTM_ATTR_DATA] = {.type = NLA_BINARY,
37*5113495bSYour Name .len = WLAN_FTM_DATA_MAX_LEN},
38*5113495bSYour Name };
39*5113495bSYour Name
40*5113495bSYour Name static int
wlan_cfg80211_process_ftm_cmd(struct wlan_objmgr_pdev * pdev,struct nlattr * tb[])41*5113495bSYour Name wlan_cfg80211_process_ftm_cmd(struct wlan_objmgr_pdev *pdev,
42*5113495bSYour Name struct nlattr *tb[])
43*5113495bSYour Name {
44*5113495bSYour Name int buf_len;
45*5113495bSYour Name void *buf;
46*5113495bSYour Name QDF_STATUS status;
47*5113495bSYour Name
48*5113495bSYour Name if (!tb[WLAN_CFG80211_FTM_ATTR_DATA]) {
49*5113495bSYour Name ftm_err("WLAN_CFG80211_FTM_ATTR_DATA attribute is invalid");
50*5113495bSYour Name return -EINVAL;
51*5113495bSYour Name }
52*5113495bSYour Name
53*5113495bSYour Name buf = nla_data(tb[WLAN_CFG80211_FTM_ATTR_DATA]);
54*5113495bSYour Name buf_len = nla_len(tb[WLAN_CFG80211_FTM_ATTR_DATA]);
55*5113495bSYour Name
56*5113495bSYour Name if (buf_len > WLAN_FTM_DATA_MAX_LEN)
57*5113495bSYour Name return -EINVAL;
58*5113495bSYour Name
59*5113495bSYour Name ftm_debug("****FTM Tx cmd len = %d*****", buf_len);
60*5113495bSYour Name
61*5113495bSYour Name status = ucfg_wlan_ftm_testmode_cmd(pdev, buf, buf_len);
62*5113495bSYour Name
63*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status))
64*5113495bSYour Name status = QDF_STATUS_E_BUSY;
65*5113495bSYour Name
66*5113495bSYour Name return qdf_status_to_os_return(status);
67*5113495bSYour Name }
68*5113495bSYour Name
69*5113495bSYour Name int
wlan_cfg80211_ftm_testmode_cmd(struct wlan_objmgr_pdev * pdev,void * data,uint32_t len)70*5113495bSYour Name wlan_cfg80211_ftm_testmode_cmd(struct wlan_objmgr_pdev *pdev,
71*5113495bSYour Name void *data, uint32_t len)
72*5113495bSYour Name {
73*5113495bSYour Name struct nlattr *tb[WLAN_CFG80211_FTM_ATTR_MAX + 1];
74*5113495bSYour Name int err = 0, cmd;
75*5113495bSYour Name struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
76*5113495bSYour Name
77*5113495bSYour Name ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
78*5113495bSYour Name WLAN_UMAC_COMP_FTM);
79*5113495bSYour Name if (!ftm_pdev_obj) {
80*5113495bSYour Name ftm_err("Failed to get ftm pdev component");
81*5113495bSYour Name return -EINVAL;
82*5113495bSYour Name }
83*5113495bSYour Name
84*5113495bSYour Name ftm_pdev_obj->cmd_type = WIFI_FTM_CMD_NL80211;
85*5113495bSYour Name
86*5113495bSYour Name err = wlan_cfg80211_nla_parse(tb, WLAN_CFG80211_FTM_ATTR_MAX - 1, data,
87*5113495bSYour Name len, wlan_cfg80211_ftm_policy);
88*5113495bSYour Name if (err) {
89*5113495bSYour Name ftm_err("Testmode INV ATTR");
90*5113495bSYour Name return err;
91*5113495bSYour Name }
92*5113495bSYour Name
93*5113495bSYour Name if (!tb[WLAN_CFG80211_FTM_ATTR_CMD]) {
94*5113495bSYour Name ftm_err("Testmode INV CMD");
95*5113495bSYour Name return -EINVAL;
96*5113495bSYour Name }
97*5113495bSYour Name cmd = nla_get_u32(tb[WLAN_CFG80211_FTM_ATTR_CMD]);
98*5113495bSYour Name
99*5113495bSYour Name switch (cmd) {
100*5113495bSYour Name case WLAN_CFG80211_FTM_CMD_WLAN_FTM:
101*5113495bSYour Name err = wlan_cfg80211_process_ftm_cmd(pdev, tb);
102*5113495bSYour Name break;
103*5113495bSYour Name
104*5113495bSYour Name default:
105*5113495bSYour Name ftm_err("unknown command: %d", cmd);
106*5113495bSYour Name return -ENOENT;
107*5113495bSYour Name }
108*5113495bSYour Name
109*5113495bSYour Name return err;
110*5113495bSYour Name }
111*5113495bSYour Name
112*5113495bSYour Name qdf_export_symbol(wlan_cfg80211_ftm_testmode_cmd);
113*5113495bSYour Name
114*5113495bSYour Name QDF_STATUS
wlan_cfg80211_ftm_rx_event(struct wlan_objmgr_pdev * pdev,uint8_t * data,uint32_t len)115*5113495bSYour Name wlan_cfg80211_ftm_rx_event(struct wlan_objmgr_pdev *pdev,
116*5113495bSYour Name uint8_t *data, uint32_t len)
117*5113495bSYour Name {
118*5113495bSYour Name struct pdev_osif_priv *pdev_ospriv;
119*5113495bSYour Name qdf_nbuf_t skb = NULL;
120*5113495bSYour Name
121*5113495bSYour Name if (!data || !len) {
122*5113495bSYour Name ftm_err("Null data or invalid length");
123*5113495bSYour Name return QDF_STATUS_E_INVAL;
124*5113495bSYour Name }
125*5113495bSYour Name
126*5113495bSYour Name pdev_ospriv = wlan_pdev_get_ospriv(pdev);
127*5113495bSYour Name if (!pdev_ospriv) {
128*5113495bSYour Name ftm_err("pdev_ospriv is NULL");
129*5113495bSYour Name return QDF_STATUS_E_INVAL;
130*5113495bSYour Name }
131*5113495bSYour Name
132*5113495bSYour Name ftm_debug("Testmode response event generated");
133*5113495bSYour Name skb = cfg80211_testmode_alloc_event_skb(pdev_ospriv->wiphy,
134*5113495bSYour Name len, GFP_ATOMIC);
135*5113495bSYour Name if (!skb)
136*5113495bSYour Name return QDF_STATUS_E_NOMEM;
137*5113495bSYour Name
138*5113495bSYour Name if (nla_put_u32(skb, WLAN_CFG80211_FTM_ATTR_CMD,
139*5113495bSYour Name WLAN_CFG80211_FTM_CMD_WLAN_FTM) ||
140*5113495bSYour Name nla_put(skb, WLAN_CFG80211_FTM_ATTR_DATA, len, data)) {
141*5113495bSYour Name goto nla_put_failure;
142*5113495bSYour Name }
143*5113495bSYour Name cfg80211_testmode_event(skb, GFP_ATOMIC);
144*5113495bSYour Name
145*5113495bSYour Name return QDF_STATUS_SUCCESS;
146*5113495bSYour Name
147*5113495bSYour Name nla_put_failure:
148*5113495bSYour Name qdf_nbuf_free(skb);
149*5113495bSYour Name ftm_err("nla_put failed on testmode rx skb!");
150*5113495bSYour Name
151*5113495bSYour Name return QDF_STATUS_E_INVAL;
152*5113495bSYour Name }
153