blob: 636742732c5e629b9ab6b3720139cd9b7b55109a [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010, Atheros Communications, Inc.
4 * All Rights Reserved.
5 * Licensed under the Clear BSD license. See README for more details.
6 */
7
8#include "sigma_dut.h"
9#include "wpa_helpers.h"
10
11
12static int cmd_sta_atheros(struct sigma_dut *dut, struct sigma_conn *conn,
13 struct sigma_cmd *cmd)
14{
15 char buf[2048], *pos;
16 int i;
17 const char *intf, *c;
18 char resp[200];
19
20 intf = get_param(cmd, "interface");
21 c = get_param(cmd, "cmd");
22 if (c == NULL)
23 return -1;
24
25 buf[0] = '\0';
26 if (strncmp(c, "ctrl=", 5) == 0) {
27 size_t rlen;
28 c += 5;
29 if (wpa_command_resp(intf, c, buf, sizeof(buf)) < 0)
30 return -2;
31 rlen = strlen(buf);
32 if (rlen > 0 && buf[rlen - 1] == '\n')
33 buf[rlen - 1] = '\0';
34 } else if (strncmp(c, "timeout=", 8) == 0) {
35 unsigned int timeout;
36 timeout = atoi(c + 8);
37 if (timeout == 0)
38 return -1;
39 dut->default_timeout = timeout;
40 sigma_dut_print(dut, DUT_MSG_INFO, "Set DUT default timeout "
41 "to %u seconds", dut->default_timeout);
42 snprintf(buf, sizeof(buf), "OK");
43 } else
44 return -2;
45
46 i = snprintf(resp, sizeof(resp), "resp,");
47 pos = buf;
48 while (*pos && i + 1 < (int) sizeof(resp)) {
49 char c = *pos++;
50 if (c == '\n' || c == '\r' || c == ',')
51 c = '^';
52 resp[i++] = c;
53 }
54 resp[i] = '\0';
55
56 send_resp(dut, conn, SIGMA_COMPLETE, resp);
57 return 0;
58}
59
60
61static int req_intf(struct sigma_cmd *cmd)
62{
63 return get_param(cmd, "interface") == NULL ? -1 : 0;
64}
65
66
Peng Xu291d97d2018-01-31 16:34:03 -080067#ifdef NL80211_SUPPORT
68static int cmd_atheros_config_scan(struct sigma_dut *dut,
69 struct sigma_conn *conn,
70 struct sigma_cmd *cmd)
71{
72 struct nl_msg *msg;
73 int ret;
74 struct nlattr *params;
75 const char *val;
76 int ifindex;
77
78 val = get_param(cmd, "enable");
79 if (!val)
80 return -1;
81 ifindex = if_nametoindex("wlan0");
82 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
83 NL80211_CMD_VENDOR)) ||
84 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
85 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
86 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
87 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
88 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
89 nla_put_u8(msg,
90 QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_ENABLE,
91 atoi(val))) {
92 sigma_dut_print(dut, DUT_MSG_ERROR,
93 "%s: err in adding vendor_cmd and vendor_data",
94 __func__);
95 nlmsg_free(msg);
96 return -1;
97 }
98 nla_nest_end(msg, params);
99
100 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
101 if (ret) {
102 sigma_dut_print(dut, DUT_MSG_ERROR,
103 "%s: err in send_and_recv_msgs, ret=%d",
104 __func__, ret);
105 return ret;
106 }
107
108 return 0;
109}
110#endif /* NL80211_SUPPORT */
111
112
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200113void atheros_register_cmds(void)
114{
115 sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros);
Peng Xu291d97d2018-01-31 16:34:03 -0800116#ifdef NL80211_SUPPORT
117 sigma_dut_reg_cmd("atheros_config_scan", NULL, cmd_atheros_config_scan);
118#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200119}