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. |
| 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 | |
| 12 | static 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,"); |
Ankita Bajaj | 1236646 | 2018-04-04 16:30:49 +0530 | [diff] [blame] | 47 | if (i < 0) |
| 48 | return -2; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 49 | pos = buf; |
| 50 | while (*pos && i + 1 < (int) sizeof(resp)) { |
| 51 | char c = *pos++; |
| 52 | if (c == '\n' || c == '\r' || c == ',') |
| 53 | c = '^'; |
| 54 | resp[i++] = c; |
| 55 | } |
| 56 | resp[i] = '\0'; |
| 57 | |
| 58 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | static int req_intf(struct sigma_cmd *cmd) |
| 64 | { |
| 65 | return get_param(cmd, "interface") == NULL ? -1 : 0; |
| 66 | } |
| 67 | |
| 68 | |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 69 | #ifdef NL80211_SUPPORT |
| 70 | static int cmd_atheros_config_scan(struct sigma_dut *dut, |
| 71 | struct sigma_conn *conn, |
| 72 | struct sigma_cmd *cmd) |
| 73 | { |
| 74 | struct nl_msg *msg; |
| 75 | int ret; |
| 76 | struct nlattr *params; |
| 77 | const char *val; |
| 78 | int ifindex; |
| 79 | |
| 80 | val = get_param(cmd, "enable"); |
| 81 | if (!val) |
| 82 | return -1; |
| 83 | ifindex = if_nametoindex("wlan0"); |
| 84 | if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0, |
| 85 | NL80211_CMD_VENDOR)) || |
| 86 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) || |
| 87 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 88 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 89 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 90 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 91 | nla_put_u8(msg, |
| 92 | QCA_WLAN_VENDOR_ATTR_CONFIG_SCAN_ENABLE, |
| 93 | atoi(val))) { |
| 94 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 95 | "%s: err in adding vendor_cmd and vendor_data", |
| 96 | __func__); |
| 97 | nlmsg_free(msg); |
| 98 | return -1; |
| 99 | } |
| 100 | nla_nest_end(msg, params); |
| 101 | |
| 102 | ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL); |
| 103 | if (ret) { |
| 104 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 105 | "%s: err in send_and_recv_msgs, ret=%d", |
| 106 | __func__, ret); |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | #endif /* NL80211_SUPPORT */ |
| 113 | |
| 114 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 115 | void atheros_register_cmds(void) |
| 116 | { |
| 117 | sigma_dut_reg_cmd("sta_atheros", req_intf, cmd_sta_atheros); |
Peng Xu | 291d97d | 2018-01-31 16:34:03 -0800 | [diff] [blame] | 118 | #ifdef NL80211_SUPPORT |
| 119 | sigma_dut_reg_cmd("atheros_config_scan", NULL, cmd_atheros_config_scan); |
| 120 | #endif /* NL80211_SUPPORT */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 121 | } |