blob: 61ba50c439407d7cc8d3c8f5f178f493b8f24e23 [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.
Jouni Malinen53053692019-02-19 11:48:06 +02004 * Copyright (c) 2019, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
10#include "wpa_helpers.h"
11
12
Jouni Malinen53053692019-02-19 11:48:06 +020013static enum sigma_cmd_result cmd_sta_atheros(struct sigma_dut *dut,
14 struct sigma_conn *conn,
15 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016{
17 char buf[2048], *pos;
18 int i;
19 const char *intf, *c;
20 char resp[200];
21
22 intf = get_param(cmd, "interface");
23 c = get_param(cmd, "cmd");
24 if (c == NULL)
Jouni Malinen53053692019-02-19 11:48:06 +020025 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020026
27 buf[0] = '\0';
28 if (strncmp(c, "ctrl=", 5) == 0) {
29 size_t rlen;
30 c += 5;
31 if (wpa_command_resp(intf, c, buf, sizeof(buf)) < 0)
Jouni Malinen53053692019-02-19 11:48:06 +020032 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020033 rlen = strlen(buf);
34 if (rlen > 0 && buf[rlen - 1] == '\n')
35 buf[rlen - 1] = '\0';
36 } else if (strncmp(c, "timeout=", 8) == 0) {
37 unsigned int timeout;
38 timeout = atoi(c + 8);
39 if (timeout == 0)
Jouni Malinen53053692019-02-19 11:48:06 +020040 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020041 dut->default_timeout = timeout;
42 sigma_dut_print(dut, DUT_MSG_INFO, "Set DUT default timeout "
43 "to %u seconds", dut->default_timeout);
44 snprintf(buf, sizeof(buf), "OK");
45 } else
Jouni Malinen53053692019-02-19 11:48:06 +020046 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020047
48 i = snprintf(resp, sizeof(resp), "resp,");
Ankita Bajaj12366462018-04-04 16:30:49 +053049 if (i < 0)
Jouni Malinen53053692019-02-19 11:48:06 +020050 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020051 pos = buf;
52 while (*pos && i + 1 < (int) sizeof(resp)) {
53 char c = *pos++;
54 if (c == '\n' || c == '\r' || c == ',')
55 c = '^';
56 resp[i++] = c;
57 }
58 resp[i] = '\0';
59
60 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinen53053692019-02-19 11:48:06 +020061 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020062}
63
64
65static int req_intf(struct sigma_cmd *cmd)
66{
67 return get_param(cmd, "interface") == NULL ? -1 : 0;
68}
69
70
Peng Xu291d97d2018-01-31 16:34:03 -080071#ifdef NL80211_SUPPORT
Jouni Malinen53053692019-02-19 11:48:06 +020072static enum sigma_cmd_result cmd_atheros_config_scan(struct sigma_dut *dut,
73 struct sigma_conn *conn,
74 struct sigma_cmd *cmd)
Peng Xu291d97d2018-01-31 16:34:03 -080075{
76 struct nl_msg *msg;
77 int ret;
78 struct nlattr *params;
79 const char *val;
80 int ifindex;
81
82 val = get_param(cmd, "enable");
83 if (!val)
Jouni Malinen53053692019-02-19 11:48:06 +020084 return INVALID_SEND_STATUS;
Peng Xu291d97d2018-01-31 16:34:03 -080085 ifindex = if_nametoindex("wlan0");
86 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
87 NL80211_CMD_VENDOR)) ||
88 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
89 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
90 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
91 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
92 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
93 nla_put_u8(msg,
94 QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_ENABLE,
95 atoi(val))) {
96 sigma_dut_print(dut, DUT_MSG_ERROR,
97 "%s: err in adding vendor_cmd and vendor_data",
98 __func__);
99 nlmsg_free(msg);
Jouni Malinen829f82c2019-02-19 11:49:57 +0200100 return ERROR_SEND_STATUS;
Peng Xu291d97d2018-01-31 16:34:03 -0800101 }
102 nla_nest_end(msg, params);
103
104 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
105 if (ret) {
106 sigma_dut_print(dut, DUT_MSG_ERROR,
107 "%s: err in send_and_recv_msgs, ret=%d",
108 __func__, ret);
Jouni Malinen829f82c2019-02-19 11:49:57 +0200109 return ERROR_SEND_STATUS;
Peng Xu291d97d2018-01-31 16:34:03 -0800110 }
111
Jouni Malinen53053692019-02-19 11:48:06 +0200112 return STATUS_SENT;
Peng Xu291d97d2018-01-31 16:34:03 -0800113}
114#endif /* NL80211_SUPPORT */
115
116
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200117void atheros_register_cmds(void)
118{
119 sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros);
Peng Xu291d97d2018-01-31 16:34:03 -0800120#ifdef NL80211_SUPPORT
121 sigma_dut_reg_cmd("atheros_config_scan", NULL, cmd_atheros_config_scan);
122#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200123}