1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "testmode.h"
19#include "debug.h"
20
21#include <net/netlink.h>
22
23enum ath6kl_tm_attr {
24 __ATH6KL_TM_ATTR_INVALID = 0,
25 ATH6KL_TM_ATTR_CMD = 1,
26 ATH6KL_TM_ATTR_DATA = 2,
27
28
29 __ATH6KL_TM_ATTR_AFTER_LAST,
30 ATH6KL_TM_ATTR_MAX = __ATH6KL_TM_ATTR_AFTER_LAST - 1,
31};
32
33enum ath6kl_tm_cmd {
34 ATH6KL_TM_CMD_TCMD = 0,
35 ATH6KL_TM_CMD_RX_REPORT = 1,
36};
37
38#define ATH6KL_TM_DATA_MAX_LEN 5000
39
40static const struct nla_policy ath6kl_tm_policy[ATH6KL_TM_ATTR_MAX + 1] = {
41 [ATH6KL_TM_ATTR_CMD] = { .type = NLA_U32 },
42 [ATH6KL_TM_ATTR_DATA] = { .type = NLA_BINARY,
43 .len = ATH6KL_TM_DATA_MAX_LEN },
44};
45
46void ath6kl_tm_rx_event(struct ath6kl *ar, void *buf, size_t buf_len)
47{
48 struct sk_buff *skb;
49
50 if (!buf || buf_len == 0)
51 return;
52
53 skb = cfg80211_testmode_alloc_event_skb(ar->wiphy, buf_len, GFP_KERNEL);
54 if (!skb) {
55 ath6kl_warn("failed to allocate testmode rx skb!\n");
56 return;
57 }
58 if (nla_put_u32(skb, ATH6KL_TM_ATTR_CMD, ATH6KL_TM_CMD_TCMD) ||
59 nla_put(skb, ATH6KL_TM_ATTR_DATA, buf_len, buf))
60 goto nla_put_failure;
61 cfg80211_testmode_event(skb, GFP_KERNEL);
62 return;
63
64nla_put_failure:
65 kfree_skb(skb);
66 ath6kl_warn("nla_put failed on testmode rx skb!\n");
67}
68
69int ath6kl_tm_cmd(struct wiphy *wiphy, void *data, int len)
70{
71 struct ath6kl *ar = wiphy_priv(wiphy);
72 struct nlattr *tb[ATH6KL_TM_ATTR_MAX + 1];
73 int err, buf_len;
74 void *buf;
75
76 err = nla_parse(tb, ATH6KL_TM_ATTR_MAX, data, len,
77 ath6kl_tm_policy);
78 if (err)
79 return err;
80
81 if (!tb[ATH6KL_TM_ATTR_CMD])
82 return -EINVAL;
83
84 switch (nla_get_u32(tb[ATH6KL_TM_ATTR_CMD])) {
85 case ATH6KL_TM_CMD_TCMD:
86 if (!tb[ATH6KL_TM_ATTR_DATA])
87 return -EINVAL;
88
89 buf = nla_data(tb[ATH6KL_TM_ATTR_DATA]);
90 buf_len = nla_len(tb[ATH6KL_TM_ATTR_DATA]);
91
92 ath6kl_wmi_test_cmd(ar->wmi, buf, buf_len);
93
94 return 0;
95
96 break;
97 case ATH6KL_TM_CMD_RX_REPORT:
98 default:
99 return -EOPNOTSUPP;
100 }
101}
102