blob: d6a459654681e65da8f7714a8791a65328c7aeca [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 Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2014, 2016-2017, Qualcomm Atheros, Inc.
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#ifdef __linux__
11#include <sys/stat.h>
12#endif /* __linux__ */
13#include "wpa_helpers.h"
14
15
Jouni Malinencd444902019-02-19 01:20:45 +020016static enum sigma_cmd_result cmd_ca_get_version(struct sigma_dut *dut,
17 struct sigma_conn *conn,
18 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020019{
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 Malinencd444902019-02-19 01:20:45 +020030 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020031}
32
33
34#ifdef __linux__
35
36static 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 Malinenc54710d2019-01-23 12:34:21 +020048void get_ver(const char *cmd, char *buf, size_t buflen)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020049{
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 Malinencd444902019-02-19 01:20:45 +020071static enum sigma_cmd_result cmd_device_get_info(struct sigma_dut *dut,
72 struct sigma_conn *conn,
73 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020074{
Jouni Malinen5db3b102016-08-04 12:27:18 +030075 const char *vendor = "Qualcomm Atheros";
Jouni Malinencd4e3c32015-10-29 12:39:56 +020076 const char *model = "N/A";
77 const char *version = "N/A";
78#ifdef __linux__
79 char model_buf[128];
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +053080 char ver_buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020081#endif /* __linux__ */
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +053082 char resp[512];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020083
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 Potteti551b9862017-01-24 17:09:44 +053092 char host_fw_ver[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020093
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 Potteti551b9862017-01-24 17:09:44 +0530148 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 Malinencd4e3c32015-10-29 12:39:56 +0200155 snprintf(ver_buf, sizeof(ver_buf),
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530156 "drv=%s%s%s%s%s%s%s/sigma=" SIGMA_DUT_VER "%s%s",
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200157 compat_ver,
158 wpa_supplicant_ver[0] ? "/wpas=" : "",
159 wpa_supplicant_ver,
160 hostapd_ver[0] ? "/hapd=" : "",
161 hostapd_ver,
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530162 host_fw_ver[0] ? "/wlan=" : "",
163 host_fw_ver,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200164 dut->version ? "@" : "",
165 dut->version ? dut->version : "");
166 version = ver_buf;
167 }
168#endif /* __linux__ */
169
Jouni Malinen5db3b102016-08-04 12:27:18 +0300170 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 Malinencd4e3c32015-10-29 12:39:56 +0200178
179 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd444902019-02-19 01:20:45 +0200180 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200181}
182
183
184static 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 Malinencd444902019-02-19 01:20:45 +0200192static enum sigma_cmd_result cmd_device_list_interfaces(struct sigma_dut *dut,
193 struct sigma_conn *conn,
194 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200195{
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 Malinencd444902019-02-19 01:20:45 +0200205 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206
207 snprintf(resp, sizeof(resp), "interfaceType,802.11,"
208 "interfaceID,%s", get_main_ifname());
209 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd444902019-02-19 01:20:45 +0200210 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200211}
212
213
214void 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}