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 | 9d7e31d | 2017-12-22 18:55:04 +0200 | [diff] [blame] | 4 | * Copyright (c) 2011-2014, 2016-2017, Qualcomm Atheros, Inc. |
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 | #ifdef __linux__ |
| 11 | #include <sys/stat.h> |
| 12 | #endif /* __linux__ */ |
| 13 | #include "wpa_helpers.h" |
| 14 | |
| 15 | |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 16 | static enum sigma_cmd_result cmd_ca_get_version(struct sigma_dut *dut, |
| 17 | struct sigma_conn *conn, |
| 18 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 19 | { |
| 20 | const char *info; |
| 21 | |
| 22 | info = get_param(cmd, "TestInfo"); |
| 23 | if (info) { |
| 24 | char buf[200]; |
| 25 | snprintf(buf, sizeof(buf), "NOTE CAPI:TestInfo:%s", info); |
| 26 | wpa_command(get_main_ifname(), buf); |
| 27 | } |
| 28 | |
| 29 | send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0"); |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 30 | return STATUS_SENT; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | |
| 34 | #ifdef __linux__ |
| 35 | |
| 36 | static void first_line(char *s) |
| 37 | { |
| 38 | while (*s) { |
| 39 | if (*s == '\r' || *s == '\n') { |
| 40 | *s = '\0'; |
| 41 | return; |
| 42 | } |
| 43 | s++; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | |
Jouni Malinen | c54710d | 2019-01-23 12:34:21 +0200 | [diff] [blame] | 48 | void get_ver(const char *cmd, char *buf, size_t buflen) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 49 | { |
| 50 | FILE *f; |
| 51 | char *pos; |
| 52 | |
| 53 | buf[0] = '\0'; |
| 54 | f = popen(cmd, "r"); |
| 55 | if (f == NULL) |
| 56 | return; |
| 57 | if (fgets(buf, buflen, f)) |
| 58 | first_line(buf); |
| 59 | pclose(f); |
| 60 | |
| 61 | pos = strstr(buf, " v"); |
| 62 | if (pos == NULL) |
| 63 | buf[0] = '\0'; |
| 64 | else |
| 65 | memmove(buf, pos + 1, strlen(pos)); |
| 66 | } |
| 67 | |
| 68 | #endif /* __linux__ */ |
| 69 | |
| 70 | |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 71 | static enum sigma_cmd_result cmd_device_get_info(struct sigma_dut *dut, |
| 72 | struct sigma_conn *conn, |
| 73 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 74 | { |
Jouni Malinen | 5db3b10 | 2016-08-04 12:27:18 +0300 | [diff] [blame] | 75 | const char *vendor = "Qualcomm Atheros"; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 76 | const char *model = "N/A"; |
| 77 | const char *version = "N/A"; |
| 78 | #ifdef __linux__ |
| 79 | char model_buf[128]; |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 80 | char ver_buf[256]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 81 | #endif /* __linux__ */ |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 82 | char resp[512]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 83 | |
| 84 | #ifdef __linux__ |
| 85 | { |
| 86 | char path[128]; |
| 87 | struct stat s; |
| 88 | FILE *f; |
| 89 | char compat_ver[128]; |
| 90 | char wpa_supplicant_ver[128]; |
| 91 | char hostapd_ver[128]; |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 92 | char host_fw_ver[128]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 93 | |
| 94 | snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", |
| 95 | get_main_ifname()); |
| 96 | if (stat(path, &s) == 0) { |
| 97 | ssize_t res; |
| 98 | char *pos; |
| 99 | snprintf(path, sizeof(path), |
| 100 | "/sys/class/net/%s/device/driver", |
| 101 | get_main_ifname()); |
| 102 | res = readlink(path, path, sizeof(path)); |
| 103 | if (res < 0) |
| 104 | model = "Linux/"; |
| 105 | else { |
| 106 | if (res >= (int) sizeof(path)) |
| 107 | res = sizeof(path) - 1; |
| 108 | path[res] = '\0'; |
| 109 | pos = strrchr(path, '/'); |
| 110 | if (pos == NULL) |
| 111 | pos = path; |
| 112 | else |
| 113 | pos++; |
| 114 | snprintf(model_buf, sizeof(model_buf), |
| 115 | "Linux/%s", pos); |
| 116 | model = model_buf; |
| 117 | } |
| 118 | } else |
| 119 | model = "Linux"; |
| 120 | |
| 121 | /* TODO: get version from wpa_supplicant (+ driver via wpa_s) |
| 122 | */ |
| 123 | |
| 124 | f = fopen("/sys/module/compat/parameters/" |
| 125 | "backported_kernel_version", "r"); |
| 126 | if (f == NULL) |
| 127 | f = fopen("/sys/module/compat/parameters/" |
| 128 | "compat_version", "r"); |
| 129 | if (f) { |
| 130 | if (fgets(compat_ver, sizeof(compat_ver), f) == NULL) |
| 131 | compat_ver[0] = '\0'; |
| 132 | else |
| 133 | first_line(compat_ver); |
| 134 | fclose(f); |
| 135 | } else |
| 136 | compat_ver[0] = '\0'; |
| 137 | |
| 138 | get_ver("./hostapd -v 2>&1", hostapd_ver, sizeof(hostapd_ver)); |
| 139 | if (hostapd_ver[0] == '\0') |
| 140 | get_ver("hostapd -v 2>&1", hostapd_ver, |
| 141 | sizeof(hostapd_ver)); |
| 142 | get_ver("./wpa_supplicant -v", wpa_supplicant_ver, |
| 143 | sizeof(wpa_supplicant_ver)); |
| 144 | if (wpa_supplicant_ver[0] == '\0') |
| 145 | get_ver("wpa_supplicant -v", wpa_supplicant_ver, |
| 146 | sizeof(wpa_supplicant_ver)); |
| 147 | |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 148 | if (get_driver_type() == DRIVER_WCN || |
| 149 | get_driver_type() == DRIVER_LINUX_WCN) |
| 150 | get_ver("iwpriv wlan0 version", host_fw_ver, |
| 151 | sizeof(host_fw_ver)); |
| 152 | else |
| 153 | host_fw_ver[0] = '\0'; |
| 154 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 155 | snprintf(ver_buf, sizeof(ver_buf), |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 156 | "drv=%s%s%s%s%s%s%s/sigma=" SIGMA_DUT_VER "%s%s", |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 157 | compat_ver, |
| 158 | wpa_supplicant_ver[0] ? "/wpas=" : "", |
| 159 | wpa_supplicant_ver, |
| 160 | hostapd_ver[0] ? "/hapd=" : "", |
| 161 | hostapd_ver, |
Pradeep Reddy Potteti | 551b986 | 2017-01-24 17:09:44 +0530 | [diff] [blame] | 162 | host_fw_ver[0] ? "/wlan=" : "", |
| 163 | host_fw_ver, |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 164 | dut->version ? "@" : "", |
| 165 | dut->version ? dut->version : ""); |
| 166 | version = ver_buf; |
| 167 | } |
| 168 | #endif /* __linux__ */ |
| 169 | |
Jouni Malinen | 5db3b10 | 2016-08-04 12:27:18 +0300 | [diff] [blame] | 170 | if (dut->vendor_name) |
| 171 | vendor = dut->vendor_name; |
| 172 | if (dut->model_name) |
| 173 | model = dut->model_name; |
| 174 | if (dut->version_name) |
| 175 | version = dut->version_name; |
| 176 | snprintf(resp, sizeof(resp), "vendor,%s,model,%s,version,%s", |
| 177 | vendor, model, version); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 178 | |
| 179 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 180 | return STATUS_SENT; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
| 184 | static int check_device_list_interfaces(struct sigma_cmd *cmd) |
| 185 | { |
| 186 | if (get_param(cmd, "interfaceType") == NULL) |
| 187 | return -1; |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 192 | static enum sigma_cmd_result cmd_device_list_interfaces(struct sigma_dut *dut, |
| 193 | struct sigma_conn *conn, |
| 194 | struct sigma_cmd *cmd) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 195 | { |
| 196 | const char *type; |
| 197 | char resp[200]; |
| 198 | |
| 199 | type = get_param(cmd, "interfaceType"); |
| 200 | if (type == NULL) |
| 201 | return -1; |
| 202 | sigma_dut_print(dut, DUT_MSG_DEBUG, "device_list_interfaces - " |
| 203 | "interfaceType=%s", type); |
| 204 | if (strcmp(type, "802.11") != 0) |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 205 | return ERROR_SEND_STATUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 206 | |
| 207 | snprintf(resp, sizeof(resp), "interfaceType,802.11," |
| 208 | "interfaceID,%s", get_main_ifname()); |
| 209 | send_resp(dut, conn, SIGMA_COMPLETE, resp); |
Jouni Malinen | cd44490 | 2019-02-19 01:20:45 +0200 | [diff] [blame^] | 210 | return STATUS_SENT; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
| 214 | void basic_register_cmds(void) |
| 215 | { |
| 216 | sigma_dut_reg_cmd("ca_get_version", NULL, cmd_ca_get_version); |
| 217 | sigma_dut_reg_cmd("device_get_info", NULL, cmd_device_get_info); |
| 218 | sigma_dut_reg_cmd("device_list_interfaces", |
| 219 | check_device_list_interfaces, |
| 220 | cmd_device_list_interfaces); |
| 221 | } |