blob: be84651371773cfb35346041b12d04da1221911a [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2014, 2016, Qualcomm Atheros, Inc.
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/stat.h>
12#include "wpa_ctrl.h"
13#include "wpa_helpers.h"
14
15
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +020016#define DEFAULT_HAPD_CTRL_PATH "/var/run/hostapd/"
17
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018extern char *sigma_main_ifname;
19extern char *sigma_station_ifname;
Danny Segalf2af39b2016-04-10 16:23:11 +030020extern char *sigma_p2p_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020021extern char *sigma_wpas_ctrl;
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +053022extern char *client_socket_path;
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +020023extern char *sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020024
25
26char * get_main_ifname(void)
27{
28 enum driver_type drv = get_driver_type();
29 enum openwrt_driver_type openwrt_drv = get_openwrt_driver_type();
30
31 if (sigma_main_ifname)
32 return sigma_main_ifname;
33
Rajesh Babu Sarvepalli96c347d2016-04-18 12:15:32 +053034 if (drv == DRIVER_ATHEROS || openwrt_drv == OPENWRT_DRIVER_ATHEROS) {
35 if (if_nametoindex("ath2") > 0)
36 return "ath2";
37 else if (if_nametoindex("ath1") > 0)
38 return "ath1";
39 else
40 return "ath0";
41 }
42
Rajesh Babu Sarvepalli78d1a882016-04-18 12:15:32 +053043 if (if_nametoindex("p2p0") > 0)
44 return "p2p0";
45 if (if_nametoindex("wlan1") > 0) {
46 struct stat s;
47 if (stat("/sys/module/mac80211", &s) == 0 &&
48 if_nametoindex("wlan0")) {
49 /*
50 * Likely a dual-radio AP device; use wlan0 for STA/P2P
51 * operations.
52 */
53 return "wlan0";
54 }
55 return "wlan1";
56 }
57 if (if_nametoindex("wlan0") > 0)
58 return "wlan0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +020059
Rajesh Babu Sarvepalli78d1a882016-04-18 12:15:32 +053060 return "unknown";
Jouni Malinencd4e3c32015-10-29 12:39:56 +020061}
62
63
64char * get_station_ifname(void)
65{
66 if (sigma_station_ifname)
67 return sigma_station_ifname;
68
69 /*
70 * If we have both wlan0 and wlan1, assume the first one is the station
71 * interface.
72 */
73 if (if_nametoindex("wlan1") > 0 && if_nametoindex("wlan0") > 0)
74 return "wlan0";
75
76 if (if_nametoindex("ath0") > 0)
77 return "ath0";
78
79 /* If nothing else matches, hope for best and guess.. */
80 return "wlan0";
81}
82
83
Danny Segalf2af39b2016-04-10 16:23:11 +030084const char * get_p2p_ifname(const char *primary_ifname)
85{
86 if (strcmp(get_station_ifname(), primary_ifname) != 0)
87 return primary_ifname;
88
89 if (sigma_p2p_ifname)
90 return sigma_p2p_ifname;
91
92 return get_station_ifname();
93}
94
95
Jouni Malinencd4e3c32015-10-29 12:39:56 +020096void dut_ifc_reset(struct sigma_dut *dut)
97{
98 char buf[256];
99 char *ifc = get_station_ifname();
100
101 snprintf(buf, sizeof(buf), "ifconfig %s down", ifc);
102 run_system(dut, buf);
103 snprintf(buf, sizeof(buf), "ifconfig %s up", ifc);
104 run_system(dut, buf);
105}
106
107
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200108int wpa_ctrl_command(const char *path, const char *ifname, const char *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200109{
110 struct wpa_ctrl *ctrl;
111 char buf[128];
112 size_t len;
113
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200114 snprintf(buf, sizeof(buf), "%s%s", path, ifname);
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530115 ctrl = wpa_ctrl_open2(buf, client_socket_path);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200116 if (ctrl == NULL) {
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530117 printf("wpa_command: wpa_ctrl_open2(%s) failed\n", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200118 return -1;
119 }
120 len = sizeof(buf);
121 if (wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len, NULL) < 0) {
122 printf("wpa_command: wpa_ctrl_request failed\n");
123 wpa_ctrl_close(ctrl);
124 return -1;
125 }
126 wpa_ctrl_close(ctrl);
127 buf[len] = '\0';
128 if (strncmp(buf, "FAIL", 4) == 0) {
129 printf("wpa_command: Command failed (FAIL received)\n");
130 return -1;
131 }
132 return 0;
133}
134
135
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200136int wpa_command(const char *ifname, const char *cmd)
137{
138 printf("wpa_command(ifname='%s', cmd='%s')\n", ifname, cmd);
139 return wpa_ctrl_command(sigma_wpas_ctrl, ifname, cmd);
140}
141
142
Alexei Avshalom Lazardc7bf052018-12-23 16:49:49 +0200143int hapd_command(const char *ifname, const char *cmd)
144{
145 const char *path = sigma_hapd_ctrl ? sigma_hapd_ctrl :
146 DEFAULT_HAPD_CTRL_PATH;
147
148 printf("hapd_command(ifname='%s', cmd='%s')\n", ifname, cmd);
149 return wpa_ctrl_command(path, ifname, cmd);
150}
151
152
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200153int wpa_ctrl_command_resp(const char *path, const char *ifname,
154 const char *cmd, char *resp, size_t resp_size)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200155{
156 struct wpa_ctrl *ctrl;
157 char buf[128];
158 size_t len;
159
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200160 snprintf(buf, sizeof(buf), "%s%s", path, ifname);
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530161 ctrl = wpa_ctrl_open2(buf, client_socket_path);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200162 if (ctrl == NULL) {
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530163 printf("wpa_command: wpa_ctrl_open2(%s) failed\n", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200164 return -1;
165 }
166 len = resp_size;
167 if (wpa_ctrl_request(ctrl, cmd, strlen(cmd), resp, &len, NULL) < 0) {
168 printf("wpa_command: wpa_ctrl_request failed\n");
169 wpa_ctrl_close(ctrl);
170 return -1;
171 }
172 wpa_ctrl_close(ctrl);
173 resp[len] = '\0';
174 return 0;
175}
176
177
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200178int wpa_command_resp(const char *ifname, const char *cmd,
179 char *resp, size_t resp_size)
180{
181 printf("wpa_command(ifname='%s', cmd='%s')\n", ifname, cmd);
182 return wpa_ctrl_command_resp(sigma_wpas_ctrl, ifname, cmd,
183 resp, resp_size);
184}
185
186
Alexei Avshalom Lazardc7bf052018-12-23 16:49:49 +0200187int hapd_command_resp(const char *ifname, const char *cmd,
188 char *resp, size_t resp_size)
189{
190 const char *path = sigma_hapd_ctrl ? sigma_hapd_ctrl :
191 DEFAULT_HAPD_CTRL_PATH;
192
193 printf("hapd_command(ifname='%s', cmd='%s')\n", ifname, cmd);
194 return wpa_ctrl_command_resp(path, ifname, cmd, resp, resp_size);
195}
196
197
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200198struct wpa_ctrl * open_wpa_ctrl_mon(const char *ctrl_path, const char *ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200199{
200 struct wpa_ctrl *ctrl;
201 char path[256];
202
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200203 snprintf(path, sizeof(path), "%s%s", ctrl_path, ifname);
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530204 ctrl = wpa_ctrl_open2(path, client_socket_path);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200205 if (ctrl == NULL)
206 return NULL;
207 if (wpa_ctrl_attach(ctrl) < 0) {
208 wpa_ctrl_close(ctrl);
209 return NULL;
210 }
211
212 return ctrl;
213}
214
215
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200216struct wpa_ctrl * open_wpa_mon(const char *ifname)
217{
218 return open_wpa_ctrl_mon(sigma_wpas_ctrl, ifname);
219}
220
221
222struct wpa_ctrl * open_hapd_mon(const char *ifname)
223{
224 const char *path = sigma_hapd_ctrl ?
225 sigma_hapd_ctrl : DEFAULT_HAPD_CTRL_PATH;
226
227 return open_wpa_ctrl_mon(path, ifname);
228}
229
230
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200231int get_wpa_cli_events(struct sigma_dut *dut, struct wpa_ctrl *mon,
232 const char **events, char *buf, size_t buf_size)
233{
234 int fd, ret;
235 fd_set rfd;
236 char *pos;
237 struct timeval tv;
238 time_t start, now;
239 int i;
240
241 for (i = 0; events[i]; i++) {
242 sigma_dut_print(dut, DUT_MSG_DEBUG,
243 "Waiting for wpa_cli event: %s", events[i]);
244 }
245 fd = wpa_ctrl_get_fd(mon);
246 if (fd < 0)
247 return -1;
248
249 time(&start);
250 while (1) {
251 size_t len;
252
253 FD_ZERO(&rfd);
254 FD_SET(fd, &rfd);
255
256 time(&now);
257 if ((unsigned int) (now - start) >= dut->default_timeout)
258 tv.tv_sec = 1;
259 else
260 tv.tv_sec = dut->default_timeout -
261 (unsigned int) (now - start) + 1;
262 tv.tv_usec = 0;
263 ret = select(fd + 1, &rfd, NULL, NULL, &tv);
264 if (ret == 0) {
265 sigma_dut_print(dut, DUT_MSG_INFO, "Timeout on "
266 "waiting for events");
267 return -1;
268 }
269 if (ret < 0) {
270 sigma_dut_print(dut, DUT_MSG_INFO, "select: %s",
271 strerror(errno));
272 return -1;
273 }
274 len = buf_size;
275 if (wpa_ctrl_recv(mon, buf, &len) < 0) {
276 sigma_dut_print(dut, DUT_MSG_ERROR, "Failure while "
277 "waiting for events");
278 return -1;
279 }
280 if (len == buf_size)
281 len--;
282 buf[len] = '\0';
283
284 pos = strchr(buf, '>');
285 if (pos) {
286 for (i = 0; events[i]; i++) {
287 if (strncmp(pos + 1, events[i],
288 strlen(events[i])) == 0)
289 return 0; /* Event found */
290 }
291 }
292
293 time(&now);
294 if ((unsigned int) (now - start) > dut->default_timeout) {
295 sigma_dut_print(dut, DUT_MSG_INFO, "Timeout on "
296 "waiting for event");
297 return -1;
298 }
299 }
300}
301
302
303int get_wpa_cli_event2(struct sigma_dut *dut, struct wpa_ctrl *mon,
304 const char *event, const char *event2,
305 char *buf, size_t buf_size)
306{
307 const char *events[3] = { event, event2, NULL };
308 return get_wpa_cli_events(dut, mon, events, buf, buf_size);
309}
310
311
312int get_wpa_cli_event(struct sigma_dut *dut, struct wpa_ctrl *mon,
313 const char *event, char *buf, size_t buf_size)
314{
315 return get_wpa_cli_event2(dut, mon, event, NULL, buf, buf_size);
316}
317
318
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -0700319/*
320 * signal_poll cmd output sample
321 * RSSI=-51
322 * LINKSPEED=866
323 * NOISE=-101
324 * FREQUENCY=5180
325 * AVG_RSSI=-50
326 */
327int get_wpa_signal_poll(struct sigma_dut *dut, const char *ifname,
328 const char *field, char *obuf, size_t obuf_size)
329{
330 struct wpa_ctrl *ctrl;
331 char buf[4096];
332 char *pos, *end;
333 size_t len, flen;
334
335 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, ifname);
336 ctrl = wpa_ctrl_open2(buf, client_socket_path);
337 if (!ctrl) {
338 sigma_dut_print(dut, DUT_MSG_ERROR,
339 "Failed to connect to wpa_supplicant");
340 return -1;
341 }
342
343 len = sizeof(buf);
344 if (wpa_ctrl_request(ctrl, "SIGNAL_POLL", 11, buf, &len, NULL) < 0) {
345 wpa_ctrl_close(ctrl);
346 sigma_dut_print(dut, DUT_MSG_ERROR, "ctrl request failed");
347 return -1;
348 }
349 buf[len] = '\0';
350
351 wpa_ctrl_close(ctrl);
352
353 flen = strlen(field);
354 pos = buf;
355 while (pos + flen < buf + len) {
356 if (pos > buf) {
357 if (*pos != '\n') {
358 pos++;
359 continue;
360 }
361 pos++;
362 }
363 if (strncmp(pos, field, flen) != 0 || pos[flen] != '=') {
364 pos++;
365 continue;
366 }
367 pos += flen + 1;
368 end = strchr(pos, '\n');
369 if (!end) {
370 sigma_dut_print(dut, DUT_MSG_ERROR,
371 "Could not find signal poll field '%s' - end is NULL",
372 field);
373 return -1;
374 }
375 *end++ = '\0';
376 if (end - pos > (int) obuf_size) {
377 sigma_dut_print(dut, DUT_MSG_ERROR,
378 "signal poll out buffer is too small");
379 return -1;
380 }
381 memcpy(obuf, pos, end - pos);
382 return 0;
383 }
384
385 sigma_dut_print(dut, DUT_MSG_ERROR, "signal poll param not found");
386 return -1;
387}
388
389
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200390static int get_wpa_ctrl_status_field(const char *path, const char *ifname,
391 const char *cmd, const char *field,
392 char *obuf, size_t obuf_size)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200393{
394 struct wpa_ctrl *ctrl;
395 char buf[4096];
396 char *pos, *end;
397 size_t len, flen;
398
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200399 snprintf(buf, sizeof(buf), "%s%s", path, ifname);
Rajiv Ranjan525dbfd2018-04-20 17:42:48 +0530400 ctrl = wpa_ctrl_open2(buf, client_socket_path);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200401 if (ctrl == NULL)
402 return -1;
403 len = sizeof(buf);
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200404 if (wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len, NULL) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405 wpa_ctrl_close(ctrl);
406 return -1;
407 }
408 wpa_ctrl_close(ctrl);
409 buf[len] = '\0';
410
411 flen = strlen(field);
412 pos = buf;
413 while (pos + flen < buf + len) {
414 if (pos > buf) {
415 if (*pos != '\n') {
416 pos++;
417 continue;
418 }
419 pos++;
420 }
421 if (strncmp(pos, field, flen) != 0 || pos[flen] != '=') {
422 pos++;
423 continue;
424 }
425 pos += flen + 1;
426 end = strchr(pos, '\n');
427 if (end == NULL)
428 return -1;
429 *end++ = '\0';
430 if (end - pos > (int) obuf_size)
431 return -1;
432 memcpy(obuf, pos, end - pos);
433 return 0;
434 }
435
436 return -1;
437}
438
439
Alexei Avshalom Lazar52ec2362018-12-18 15:58:31 +0200440int get_wpa_status(const char *ifname, const char *field, char *obuf,
441 size_t obuf_size)
442{
443 return get_wpa_ctrl_status_field(sigma_wpas_ctrl, ifname, "STATUS",
444 field, obuf, obuf_size);
445}
446
447
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +0200448int get_hapd_config(const char *ifname, const char *field, char *obuf,
449 size_t obuf_size)
450{
451 const char *path = sigma_hapd_ctrl ?
452 sigma_hapd_ctrl : DEFAULT_HAPD_CTRL_PATH;
453
454 return get_wpa_ctrl_status_field(path, ifname, "GET_CONFIG",
455 field, obuf, obuf_size);
456}
457
458
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200459int wait_ip_addr(struct sigma_dut *dut, const char *ifname, int timeout)
460{
461 char ip[30];
462 int count = timeout;
463
464 while (count > 0) {
465 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: ifname='%s' - %d "
466 "seconds remaining",
467 __func__, ifname, count);
468 count--;
469 if (get_wpa_status(ifname, "ip_address", ip, sizeof(ip)) == 0
470 && strlen(ip) > 0) {
471 sigma_dut_print(dut, DUT_MSG_INFO, "IP address "
472 "found: '%s'", ip);
473 return 0;
474 }
475 sleep(1);
476 }
477 sigma_dut_print(dut, DUT_MSG_INFO, "%s: Could not get IP address for "
478 "ifname='%s'", __func__, ifname);
479 return -1;
480}
481
482
483void remove_wpa_networks(const char *ifname)
484{
485 char buf[4096];
486 char cmd[256];
487 char *pos;
488
489 if (wpa_command_resp(ifname, "LIST_NETWORKS", buf, sizeof(buf)) < 0)
490 return;
491
492 /* Skip the first line (header) */
493 pos = strchr(buf, '\n');
494 if (pos == NULL)
495 return;
496 pos++;
497 while (pos && pos[0]) {
498 int id = atoi(pos);
499 snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %d", id);
500 wpa_command(ifname, cmd);
501 pos = strchr(pos, '\n');
502 if (pos)
503 pos++;
504 }
505}
506
507
508int add_network(const char *ifname)
509{
510 char res[30];
511
512 if (wpa_command_resp(ifname, "ADD_NETWORK", res, sizeof(res)) < 0)
513 return -1;
514 return atoi(res);
515}
516
517
518int set_network(const char *ifname, int id, const char *field,
519 const char *value)
520{
521 char buf[200];
522 snprintf(buf, sizeof(buf), "SET_NETWORK %d %s %s", id, field, value);
523 return wpa_command(ifname, buf);
524}
525
526
527int set_network_quoted(const char *ifname, int id, const char *field,
528 const char *value)
529{
530 char buf[200];
531 snprintf(buf, sizeof(buf), "SET_NETWORK %d %s \"%s\"",
532 id, field, value);
533 return wpa_command(ifname, buf);
534}
535
536
537int add_cred(const char *ifname)
538{
539 char res[30];
540
541 if (wpa_command_resp(ifname, "ADD_CRED", res, sizeof(res)) < 0)
542 return -1;
543 return atoi(res);
544}
545
546
547int set_cred(const char *ifname, int id, const char *field, const char *value)
548{
549 char buf[200];
550 snprintf(buf, sizeof(buf), "SET_CRED %d %s %s", id, field, value);
551 return wpa_command(ifname, buf);
552}
553
554
555int set_cred_quoted(const char *ifname, int id, const char *field,
556 const char *value)
557{
558 char buf[200];
559 snprintf(buf, sizeof(buf), "SET_CRED %d %s \"%s\"",
560 id, field, value);
561 return wpa_command(ifname, buf);
562}
563
564
565int start_sta_mode(struct sigma_dut *dut)
566{
567 FILE *f;
Alexei Avshalom Lazar3e8267e2018-12-18 15:58:54 +0200568 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200569 char *ifname;
570 char *tmp, *pos;
571
572 if (dut->mode == SIGMA_MODE_STATION)
573 return 0;
574
575 if (dut->mode == SIGMA_MODE_AP) {
576 if (system("killall hostapd") == 0) {
577 int i;
578
579 /* Wait some time to allow hostapd to complete cleanup
580 * before starting a new process */
581 for (i = 0; i < 10; i++) {
582 usleep(500000);
583 if (system("pidof hostapd") != 0)
584 break;
585 }
586 }
587 }
588
589 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
590 snprintf(buf, sizeof(buf), "ifconfig %s down",
591 dut->sniffer_ifname);
592 if (system(buf) != 0) {
593 sigma_dut_print(dut, DUT_MSG_INFO,
594 "Failed to run '%s'", buf);
595 }
596 snprintf(buf, sizeof(buf), "iw dev %s set type station",
597 dut->sniffer_ifname);
598 if (system(buf) != 0) {
599 sigma_dut_print(dut, DUT_MSG_INFO,
600 "Failed to run '%s'", buf);
601 }
602 }
603
604 dut->mode = SIGMA_MODE_STATION;
605
606 ifname = get_main_ifname();
607 if (wpa_command(ifname, "PING") == 0)
608 return 0; /* wpa_supplicant is already running */
609
610 /* Start wpa_supplicant */
611 f = fopen(SIGMA_TMPDIR "/sigma_dut-sta.conf", "w");
612 if (f == NULL)
613 return -1;
614
615 tmp = strdup(sigma_wpas_ctrl);
616 if (tmp == NULL) {
617 fclose(f);
618 return -1;
619 }
620 pos = tmp;
621 while (pos[0] != '\0' && pos[1] != '\0')
622 pos++;
623 if (*pos == '/')
624 *pos = '\0';
625 fprintf(f, "ctrl_interface=%s\n", tmp);
626 free(tmp);
627 fprintf(f, "device_name=Test client\n");
628 fprintf(f, "device_type=1-0050F204-1\n");
Alexei Avshalom Lazar1080c582018-12-20 17:40:55 +0200629 if (is_60g_sigma_dut(dut)) {
630 fprintf(f, "eapol_version=2\n");
631 fprintf(f,
632 "config_methods=display push_button keypad virtual_display physical_display virtual_push_button\n");
633 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200634 fclose(f);
635
636#ifdef __QNXNTO__
Alexei Avshalom Lazar3e8267e2018-12-18 15:58:54 +0200637 snprintf(buf, sizeof(buf), "wpa_supplicant -Dqca -i%s -B %s%s"
638 "-c" SIGMA_TMPDIR "/sigma_dut-sta.conf", ifname,
639 dut->wpa_supplicant_debug_log ? "-K -t -ddd -f " : "",
640 dut->wpa_supplicant_debug_log ?
641 dut->wpa_supplicant_debug_log : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200642#else /*__QNXNTO__*/
Alexei Avshalom Lazar3e8267e2018-12-18 15:58:54 +0200643 snprintf(buf, sizeof(buf), "wpa_supplicant -Dnl80211 -i%s -B %s%s "
644 "-c" SIGMA_TMPDIR "/sigma_dut-sta.conf", ifname,
645 dut->wpa_supplicant_debug_log ? "-K -t -ddd -f " : "",
646 dut->wpa_supplicant_debug_log ?
647 dut->wpa_supplicant_debug_log : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200648#endif /*__QNXNTO__*/
649 if (system(buf) != 0) {
650 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s'", buf);
651 return -1;
652 }
653
654 sleep(1);
655
656 if (wpa_command(ifname, "PING")) {
657 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to communicate "
658 "with wpa_supplicant");
659 return -1;
660 }
661
662 return 0;
663}
664
665
666void stop_sta_mode(struct sigma_dut *dut)
667{
Alexei Avshalom Lazar80566092018-12-18 16:01:50 +0200668 if (is_60g_sigma_dut(dut)) {
669 wpa_command(get_main_ifname(), "TERMINATE");
670 return;
671 }
672
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200673 wpa_command("wlan0", "TERMINATE");
674 wpa_command("wlan1", "TERMINATE");
675 wpa_command("ath0", "TERMINATE");
676 wpa_command("ath1", "TERMINATE");
677}