1003353b0SKalle Valo /*
2003353b0SKalle Valo * Copyright (c) 2010-2011 Atheros Communications Inc.
31b2df407SVasanthakumar Thiagarajan * Copyright (c) 2011 Qualcomm Atheros, Inc.
4003353b0SKalle Valo *
5003353b0SKalle Valo * Permission to use, copy, modify, and/or distribute this software for any
6003353b0SKalle Valo * purpose with or without fee is hereby granted, provided that the above
7003353b0SKalle Valo * copyright notice and this permission notice appear in all copies.
8003353b0SKalle Valo *
9003353b0SKalle Valo * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10003353b0SKalle Valo * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11003353b0SKalle Valo * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12003353b0SKalle Valo * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13003353b0SKalle Valo * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14003353b0SKalle Valo * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15003353b0SKalle Valo * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16003353b0SKalle Valo */
17003353b0SKalle Valo
18003353b0SKalle Valo #include "testmode.h"
194f34daceSThomas Pedersen #include "debug.h"
20003353b0SKalle Valo
21003353b0SKalle Valo #include <net/netlink.h>
22003353b0SKalle Valo
23003353b0SKalle Valo enum ath6kl_tm_attr {
24003353b0SKalle Valo __ATH6KL_TM_ATTR_INVALID = 0,
25003353b0SKalle Valo ATH6KL_TM_ATTR_CMD = 1,
26003353b0SKalle Valo ATH6KL_TM_ATTR_DATA = 2,
27003353b0SKalle Valo
28003353b0SKalle Valo /* keep last */
29003353b0SKalle Valo __ATH6KL_TM_ATTR_AFTER_LAST,
30003353b0SKalle Valo ATH6KL_TM_ATTR_MAX = __ATH6KL_TM_ATTR_AFTER_LAST - 1,
31003353b0SKalle Valo };
32003353b0SKalle Valo
33003353b0SKalle Valo enum ath6kl_tm_cmd {
34003353b0SKalle Valo ATH6KL_TM_CMD_TCMD = 0,
354f34daceSThomas Pedersen ATH6KL_TM_CMD_RX_REPORT = 1, /* not used anymore */
36003353b0SKalle Valo };
37003353b0SKalle Valo
38003353b0SKalle Valo #define ATH6KL_TM_DATA_MAX_LEN 5000
39003353b0SKalle Valo
40003353b0SKalle Valo static const struct nla_policy ath6kl_tm_policy[ATH6KL_TM_ATTR_MAX + 1] = {
41003353b0SKalle Valo [ATH6KL_TM_ATTR_CMD] = { .type = NLA_U32 },
42003353b0SKalle Valo [ATH6KL_TM_ATTR_DATA] = { .type = NLA_BINARY,
43003353b0SKalle Valo .len = ATH6KL_TM_DATA_MAX_LEN },
44003353b0SKalle Valo };
45003353b0SKalle Valo
ath6kl_tm_rx_event(struct ath6kl * ar,void * buf,size_t buf_len)464f34daceSThomas Pedersen void ath6kl_tm_rx_event(struct ath6kl *ar, void *buf, size_t buf_len)
47003353b0SKalle Valo {
484f34daceSThomas Pedersen struct sk_buff *skb;
494f34daceSThomas Pedersen
504f34daceSThomas Pedersen if (!buf || buf_len == 0)
51003353b0SKalle Valo return;
52003353b0SKalle Valo
534f34daceSThomas Pedersen skb = cfg80211_testmode_alloc_event_skb(ar->wiphy, buf_len, GFP_KERNEL);
544f34daceSThomas Pedersen if (!skb) {
554f34daceSThomas Pedersen ath6kl_warn("failed to allocate testmode rx skb!\n");
564f34daceSThomas Pedersen return;
57003353b0SKalle Valo }
587b69549aSDavid S. Miller if (nla_put_u32(skb, ATH6KL_TM_ATTR_CMD, ATH6KL_TM_CMD_TCMD) ||
597b69549aSDavid S. Miller nla_put(skb, ATH6KL_TM_ATTR_DATA, buf_len, buf))
607b69549aSDavid S. Miller goto nla_put_failure;
614f34daceSThomas Pedersen cfg80211_testmode_event(skb, GFP_KERNEL);
624f34daceSThomas Pedersen return;
63003353b0SKalle Valo
64003353b0SKalle Valo nla_put_failure:
654f34daceSThomas Pedersen kfree_skb(skb);
664f34daceSThomas Pedersen ath6kl_warn("nla_put failed on testmode rx skb!\n");
67003353b0SKalle Valo }
68003353b0SKalle Valo
ath6kl_tm_cmd(struct wiphy * wiphy,struct wireless_dev * wdev,void * data,int len)69fc73f11fSDavid Spinadel int ath6kl_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
70fc73f11fSDavid Spinadel void *data, int len)
71003353b0SKalle Valo {
72003353b0SKalle Valo struct ath6kl *ar = wiphy_priv(wiphy);
73003353b0SKalle Valo struct nlattr *tb[ATH6KL_TM_ATTR_MAX + 1];
744f34daceSThomas Pedersen int err, buf_len;
75003353b0SKalle Valo void *buf;
76003353b0SKalle Valo
77*8cb08174SJohannes Berg err = nla_parse_deprecated(tb, ATH6KL_TM_ATTR_MAX, data, len,
78*8cb08174SJohannes Berg ath6kl_tm_policy, NULL);
79003353b0SKalle Valo if (err)
80003353b0SKalle Valo return err;
81003353b0SKalle Valo
82003353b0SKalle Valo if (!tb[ATH6KL_TM_ATTR_CMD])
83003353b0SKalle Valo return -EINVAL;
84003353b0SKalle Valo
85003353b0SKalle Valo switch (nla_get_u32(tb[ATH6KL_TM_ATTR_CMD])) {
86003353b0SKalle Valo case ATH6KL_TM_CMD_TCMD:
87003353b0SKalle Valo if (!tb[ATH6KL_TM_ATTR_DATA])
88003353b0SKalle Valo return -EINVAL;
89003353b0SKalle Valo
90003353b0SKalle Valo buf = nla_data(tb[ATH6KL_TM_ATTR_DATA]);
91003353b0SKalle Valo buf_len = nla_len(tb[ATH6KL_TM_ATTR_DATA]);
92003353b0SKalle Valo
93003353b0SKalle Valo ath6kl_wmi_test_cmd(ar->wmi, buf, buf_len);
94003353b0SKalle Valo
95003353b0SKalle Valo return 0;
96003353b0SKalle Valo
97003353b0SKalle Valo case ATH6KL_TM_CMD_RX_REPORT:
98003353b0SKalle Valo default:
99003353b0SKalle Valo return -EOPNOTSUPP;
100003353b0SKalle Valo }
101003353b0SKalle Valo }
102