summaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/wcn36xx/testmode.c
blob: 1279064a3b716c2ef6cf82d82c27ea664f1496b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <net/netlink.h>
#include <linux/firmware.h>
#include <net/cfg80211.h>
#include "wcn36xx.h"

#include "testmode.h"
#include "testmode_i.h"
#include "hal.h"
#include "smd.h"

static const struct nla_policy wcn36xx_tm_policy[WCN36XX_TM_ATTR_MAX + 1] = {
	[WCN36XX_TM_ATTR_CMD] = { .type = NLA_U16 },
	[WCN36XX_TM_ATTR_DATA] = { .type = NLA_BINARY,
	.len = WCN36XX_TM_DATA_MAX_LEN },
};

struct build_release_number {
	u16 drv_major;
	u16 drv_minor;
	u16 drv_patch;
	u16 drv_build;
	u16 ptt_max;
	u16 ptt_min;
	u16 fw_ver;
} __packed;

static int wcn36xx_tm_cmd_ptt(struct wcn36xx *wcn, struct ieee80211_vif *vif,
			      struct nlattr *tb[])
{
	int ret = 0, buf_len;
	void *buf;
	struct ftm_rsp_msg *msg, *rsp = NULL;
	struct sk_buff *skb;

	if (!tb[WCN36XX_TM_ATTR_DATA])
		return -EINVAL;

	buf = nla_data(tb[WCN36XX_TM_ATTR_DATA]);
	buf_len = nla_len(tb[WCN36XX_TM_ATTR_DATA]);
	msg = (struct ftm_rsp_msg *)buf;

	wcn36xx_dbg(WCN36XX_DBG_TESTMODE,
		    "testmode cmd wmi msg_id 0x%04X msg_len %d buf %pK buf_len %d\n",
		   msg->msg_id, msg->msg_body_length,
		   buf, buf_len);

	wcn36xx_dbg_dump(WCN36XX_DBG_TESTMODE_DUMP, "REQ ", buf, buf_len);

	if (msg->msg_id == MSG_GET_BUILD_RELEASE_NUMBER) {
		struct build_release_number *body =
				(struct build_release_number *)
				msg->msg_response;

		body->drv_major = wcn->fw_major;
		body->drv_minor = wcn->fw_minor;
		body->drv_patch = wcn->fw_version;
		body->drv_build = wcn->fw_revision;
		body->ptt_max = 10;
		body->ptt_min = 0;

		rsp = msg;
		rsp->resp_status = 0;
	} else {
		wcn36xx_dbg(WCN36XX_DBG_TESTMODE,
			    "PPT Request >> HAL size %d\n",
				msg->msg_body_length);

		msg->resp_status = wcn36xx_smd_process_ptt_msg(wcn, vif, msg,
							       msg->msg_body_length, (void *)(&rsp));

		wcn36xx_dbg(WCN36XX_DBG_TESTMODE,
			    "Response status = %d\n",
				msg->resp_status);
		if (rsp)
			wcn36xx_dbg(WCN36XX_DBG_TESTMODE,
				    "PPT Response << HAL size %d\n",
					rsp->msg_body_length);
	}

	if (!rsp) {
		rsp = msg;
		wcn36xx_warn("No response! Echoing request with response status %d\n",
			     rsp->resp_status);
	}
	wcn36xx_dbg_dump(WCN36XX_DBG_TESTMODE_DUMP, "RSP ",
			 rsp, rsp->msg_body_length);

	skb = cfg80211_testmode_alloc_reply_skb(wcn->hw->wiphy,
						nla_total_size(msg->msg_body_length));
	if (!skb) {
		ret = -ENOMEM;
		goto out;
	}

	ret = nla_put(skb, WCN36XX_TM_ATTR_DATA, rsp->msg_body_length, rsp);
	if (ret) {
		kfree_skb(skb);
		goto out;
	}

	ret = cfg80211_testmode_reply(skb);

out:
	if (rsp != msg)
		kfree(rsp);

	return ret;
}

int wcn36xx_tm_cmd(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
		   void *data, int len)
{
	struct wcn36xx *wcn = hw->priv;
	struct nlattr *tb[WCN36XX_TM_ATTR_MAX + 1];
	int ret = 0;
	unsigned short attr;

	wcn36xx_dbg_dump(WCN36XX_DBG_TESTMODE_DUMP, "Data:", data, len);
	ret = nla_parse(tb, WCN36XX_TM_ATTR_MAX, data, len,
			wcn36xx_tm_policy, NULL);
	if (ret)
		return ret;

	if (!tb[WCN36XX_TM_ATTR_CMD])
		return -EINVAL;

	attr = nla_get_u16(tb[WCN36XX_TM_ATTR_CMD]);

	if (attr != WCN36XX_TM_CMD_PTT)
		return -EOPNOTSUPP;

	return wcn36xx_tm_cmd_ptt(wcn, vif, tb);
}