blob: f45a6fc9593a081a69ef831ee76fcca21db38170 [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>
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +020012#include <linux/ethtool.h>
13#include <linux/netlink.h>
14#include <linux/sockios.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#endif /* __linux__ */
16#include "wpa_helpers.h"
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +020017#include <sys/ioctl.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018
19
Jouni Malinencd444902019-02-19 01:20:45 +020020static enum sigma_cmd_result cmd_ca_get_version(struct sigma_dut *dut,
21 struct sigma_conn *conn,
22 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020023{
24 const char *info;
25
26 info = get_param(cmd, "TestInfo");
27 if (info) {
28 char buf[200];
29 snprintf(buf, sizeof(buf), "NOTE CAPI:TestInfo:%s", info);
30 wpa_command(get_main_ifname(), buf);
31 }
32
33 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
Jouni Malinencd444902019-02-19 01:20:45 +020034 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020035}
36
37
38#ifdef __linux__
39
40static void first_line(char *s)
41{
42 while (*s) {
43 if (*s == '\r' || *s == '\n') {
44 *s = '\0';
45 return;
46 }
47 s++;
48 }
49}
50
51
Jouni Malinenc54710d2019-01-23 12:34:21 +020052void get_ver(const char *cmd, char *buf, size_t buflen)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020053{
54 FILE *f;
55 char *pos;
56
57 buf[0] = '\0';
58 f = popen(cmd, "r");
59 if (f == NULL)
60 return;
61 if (fgets(buf, buflen, f))
62 first_line(buf);
63 pclose(f);
64
65 pos = strstr(buf, " v");
66 if (pos == NULL)
67 buf[0] = '\0';
68 else
69 memmove(buf, pos + 1, strlen(pos));
70}
71
72#endif /* __linux__ */
73
74
Jouni Malinencd444902019-02-19 01:20:45 +020075static enum sigma_cmd_result cmd_device_get_info(struct sigma_dut *dut,
76 struct sigma_conn *conn,
77 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020078{
Jouni Malinen5db3b102016-08-04 12:27:18 +030079 const char *vendor = "Qualcomm Atheros";
Jouni Malinencd4e3c32015-10-29 12:39:56 +020080 const char *model = "N/A";
81 const char *version = "N/A";
82#ifdef __linux__
83 char model_buf[128];
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +053084 char ver_buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020085#endif /* __linux__ */
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +053086 char resp[512];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020087
88#ifdef __linux__
89 {
90 char path[128];
91 struct stat s;
92 FILE *f;
93 char compat_ver[128];
94 char wpa_supplicant_ver[128];
95 char hostapd_ver[128];
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +053096 char host_fw_ver[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020097
98 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211",
99 get_main_ifname());
100 if (stat(path, &s) == 0) {
101 ssize_t res;
102 char *pos;
103 snprintf(path, sizeof(path),
104 "/sys/class/net/%s/device/driver",
105 get_main_ifname());
106 res = readlink(path, path, sizeof(path));
107 if (res < 0)
108 model = "Linux/";
109 else {
110 if (res >= (int) sizeof(path))
111 res = sizeof(path) - 1;
112 path[res] = '\0';
113 pos = strrchr(path, '/');
114 if (pos == NULL)
115 pos = path;
116 else
117 pos++;
118 snprintf(model_buf, sizeof(model_buf),
119 "Linux/%s", pos);
120 model = model_buf;
121 }
122 } else
123 model = "Linux";
124
125 /* TODO: get version from wpa_supplicant (+ driver via wpa_s)
126 */
127
128 f = fopen("/sys/module/compat/parameters/"
129 "backported_kernel_version", "r");
130 if (f == NULL)
131 f = fopen("/sys/module/compat/parameters/"
132 "compat_version", "r");
133 if (f) {
134 if (fgets(compat_ver, sizeof(compat_ver), f) == NULL)
135 compat_ver[0] = '\0';
136 else
137 first_line(compat_ver);
138 fclose(f);
139 } else
140 compat_ver[0] = '\0';
141
142 get_ver("./hostapd -v 2>&1", hostapd_ver, sizeof(hostapd_ver));
143 if (hostapd_ver[0] == '\0')
144 get_ver("hostapd -v 2>&1", hostapd_ver,
145 sizeof(hostapd_ver));
146 get_ver("./wpa_supplicant -v", wpa_supplicant_ver,
147 sizeof(wpa_supplicant_ver));
148 if (wpa_supplicant_ver[0] == '\0')
149 get_ver("wpa_supplicant -v", wpa_supplicant_ver,
150 sizeof(wpa_supplicant_ver));
151
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +0200152 host_fw_ver[0] = '\0';
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530153 if (get_driver_type() == DRIVER_WCN ||
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +0200154 get_driver_type() == DRIVER_LINUX_WCN) {
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530155 get_ver("iwpriv wlan0 version", host_fw_ver,
156 sizeof(host_fw_ver));
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +0200157 } else if (get_driver_type() == DRIVER_WIL6210) {
158 struct ethtool_drvinfo drvinfo;
159 struct ifreq ifr; /* ifreq suitable for ethtool ioctl */
160 int fd; /* socket suitable for ethtool ioctl */
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530161
Alexei Avshalom Lazar9b85c412019-01-31 15:20:52 +0200162 memset(&drvinfo, 0, sizeof(drvinfo));
163 drvinfo.cmd = ETHTOOL_GDRVINFO;
164
165 memset(&ifr, 0, sizeof(ifr));
166 strcpy(ifr.ifr_name, get_main_ifname());
167
168 fd = socket(AF_INET, SOCK_DGRAM, 0);
169 if (fd < 0)
170 fd = socket(AF_NETLINK, SOCK_RAW,
171 NETLINK_GENERIC);
172 if (fd >= 0) {
173 ifr.ifr_data = (void *) &drvinfo;
174 if (ioctl(fd, SIOCETHTOOL, &ifr) == 0)
175 strlcpy(host_fw_ver, drvinfo.fw_version,
176 sizeof(host_fw_ver));
177 close(fd);
178 }
179 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200180 snprintf(ver_buf, sizeof(ver_buf),
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530181 "drv=%s%s%s%s%s%s%s/sigma=" SIGMA_DUT_VER "%s%s",
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200182 compat_ver,
183 wpa_supplicant_ver[0] ? "/wpas=" : "",
184 wpa_supplicant_ver,
185 hostapd_ver[0] ? "/hapd=" : "",
186 hostapd_ver,
Pradeep Reddy Potteti551b9862017-01-24 17:09:44 +0530187 host_fw_ver[0] ? "/wlan=" : "",
188 host_fw_ver,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200189 dut->version ? "@" : "",
190 dut->version ? dut->version : "");
191 version = ver_buf;
192 }
193#endif /* __linux__ */
194
Jouni Malinen5db3b102016-08-04 12:27:18 +0300195 if (dut->vendor_name)
196 vendor = dut->vendor_name;
197 if (dut->model_name)
198 model = dut->model_name;
199 if (dut->version_name)
200 version = dut->version_name;
201 snprintf(resp, sizeof(resp), "vendor,%s,model,%s,version,%s",
202 vendor, model, version);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200203
204 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd444902019-02-19 01:20:45 +0200205 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206}
207
208
209static int check_device_list_interfaces(struct sigma_cmd *cmd)
210{
211 if (get_param(cmd, "interfaceType") == NULL)
212 return -1;
213 return 0;
214}
215
216
Jouni Malinencd444902019-02-19 01:20:45 +0200217static enum sigma_cmd_result cmd_device_list_interfaces(struct sigma_dut *dut,
218 struct sigma_conn *conn,
219 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200220{
221 const char *type;
222 char resp[200];
223
224 type = get_param(cmd, "interfaceType");
225 if (type == NULL)
226 return -1;
227 sigma_dut_print(dut, DUT_MSG_DEBUG, "device_list_interfaces - "
228 "interfaceType=%s", type);
229 if (strcmp(type, "802.11") != 0)
Jouni Malinencd444902019-02-19 01:20:45 +0200230 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200231
232 snprintf(resp, sizeof(resp), "interfaceType,802.11,"
233 "interfaceID,%s", get_main_ifname());
234 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd444902019-02-19 01:20:45 +0200235 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200236}
237
238
239void basic_register_cmds(void)
240{
241 sigma_dut_reg_cmd("ca_get_version", NULL, cmd_ca_get_version);
242 sigma_dut_reg_cmd("device_get_info", NULL, cmd_device_get_info);
243 sigma_dut_reg_cmd("device_list_interfaces",
244 check_device_list_interfaces,
245 cmd_device_list_interfaces);
246}