Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP) |
| 3 | * Copyright (c) 2010, Atheros Communications, Inc. |
Jouni Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 4 | * Copyright (c) 2019, The Linux Foundation |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5 | * 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 13 | static enum sigma_cmd_result cmd_sta_atheros(struct sigma_dut *dut, |
| 14 | struct sigma_conn *conn, |
| 15 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 16 | { |
| 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 25 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 26 | |
| 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 32 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 33 | 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 40 | return INVALID_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 41 | 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 46 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 47 | |
| 48 | i = snprintf(resp, sizeof(resp), "resp,"); |
Ankita Bajaj | 1236646 | 2018-04-04 16:30:49 +0530 | [diff] [blame] | 49 | if (i < 0) |
Jouni Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 50 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 51 | 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 61 | return STATUS_SENT; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | static int req_intf(struct sigma_cmd *cmd) |
| 66 | { |
| 67 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 68 | } |
| 69 | |
| 70 | |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 71 | #ifdef NL80211_SUPPORT |
Jouni Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 72 | static enum sigma_cmd_result cmd_atheros_config_scan(struct sigma_dut *dut, |
| 73 | struct sigma_conn *conn, |
| 74 | struct sigma_cmd *cmd) |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 75 | { |
| 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 Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 84 | return INVALID_SEND_STATUS; |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 85 | 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 Malinen | 829f82c | 2019-02-19 11:49:57 +0200 | [diff] [blame] | 100 | return ERROR_SEND_STATUS; |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 101 | } |
| 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 Malinen | 829f82c | 2019-02-19 11:49:57 +0200 | [diff] [blame] | 109 | return ERROR_SEND_STATUS; |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Jouni Malinen | 5305369 | 2019-02-19 11:48:06 +0200 | [diff] [blame] | 112 | return STATUS_SENT; |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 113 | } |
| 114 | #endif /* NL80211_SUPPORT */ |
| 115 | |
| 116 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 117 | void atheros_register_cmds(void) |
| 118 | { |
| 119 | sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros); |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 120 | #ifdef NL80211_SUPPORT |
| 121 | sigma_dut_reg_cmd("atheros_config_scan", NULL, cmd_atheros_config_scan); |
| 122 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 123 | } |