blob: 1cea5ed0dcb591e9b569f0a595f5d716290be51f [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.
4 * Copyright (c) 2011-2014, Qualcomm Atheros, Inc.
5 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
10#include <sys/stat.h>
11#include "wpa_ctrl.h"
12#include "wpa_helpers.h"
13
14
15int run_system(struct sigma_dut *dut, const char *cmd)
16{
17 int res;
18
19 sigma_dut_print(dut, DUT_MSG_DEBUG, "Running '%s'", cmd);
20 res = system(cmd);
21 if (res < 0) {
22 sigma_dut_print(dut, DUT_MSG_DEBUG, "Failed to execute "
23 "command '%s'", cmd);
24 }
25 return res;
26}
27
28
29static int p2p_group_add(struct sigma_dut *dut, const char *ifname,
30 int go, const char *grpid, const char *ssid)
31{
32 struct wfa_cs_p2p_group *grp;
33
34 if (go)
35 dut->go = 1;
36 else
37 dut->p2p_client = 1;
38 grp = malloc(sizeof(*grp));
39 if (grp == NULL)
40 return -1;
41 memset(grp, 0, sizeof(*grp));
42 strncpy(grp->ifname, ifname, IFNAMSIZ);
43 grp->go = go;
44 strncpy(grp->grpid, grpid, P2P_GRP_ID_LEN);
45 strncpy(grp->ssid, ssid, sizeof(grp->ssid));
46
47 grp->next = dut->groups;
48 dut->groups = grp;
49
50 return 0;
51}
52
53
54static int p2p_group_remove(struct sigma_dut *dut, const char *grpid)
55{
56 struct wfa_cs_p2p_group *grp, *prev;
57
58 prev = NULL;
59 grp = dut->groups;
60 while (grp) {
61 if (strcmp(grpid, grp->grpid) == 0) {
62 if (prev)
63 prev->next = grp->next;
64 else
65 dut->groups = grp->next;
66 free(grp);
67 return 0;
68 }
69 prev = grp;
70 grp = grp->next;
71 }
72 return -1;
73}
74
75
76static struct wfa_cs_p2p_group * p2p_group_get(struct sigma_dut *dut,
77 const char *grpid)
78{
79 struct wfa_cs_p2p_group *grp;
80 char buf[1000], buf2[4096], *ifname, *pos;
81 char go_dev_addr[50];
82 char ssid[33];
83
84 for (grp = dut->groups; grp; grp = grp->next) {
85 if (strcmp(grpid, grp->grpid) == 0)
86 return grp;
87 }
88
89 /*
90 * No group found based on group id. As a workaround for GO Negotiation
91 * responder case where we do not store group id, try to find an active
92 * group that matches with the requested group id.
93 */
94
95 pos = strchr(grpid, ' ');
96 if (pos == NULL)
97 return NULL;
98 if (pos - grpid > (int) sizeof(go_dev_addr))
99 return NULL;
100 memcpy(go_dev_addr, grpid, pos - grpid);
101 go_dev_addr[pos - grpid] = '\0';
102 strncpy(ssid, pos + 1, sizeof(ssid));
103 ssid[sizeof(ssid) - 1] = '\0';
104 printf("Trying to find suitable interface for group: go_dev_addr='%s' "
105 "grpid='%s'\n", go_dev_addr, grpid);
106
107 if (wpa_command_resp(get_main_ifname(), "INTERFACES", buf, sizeof(buf))
108 < 0)
109 return NULL;
110 ifname = buf;
111 while (ifname && *ifname) {
112 int add = 0;
113 int go = 0;
114 pos = strchr(ifname, '\n');
115 if (pos)
116 *pos++ = '\0';
117 printf("Considering interface '%s' for group\n", ifname);
118
119 if (wpa_command_resp(ifname, "STATUS", buf2, sizeof(buf2)) ==
120 0) {
121 if (strstr(buf2, ssid)) {
122 printf("Selected interface '%s' based on "
123 "STATUS\n", ifname);
124 add = 1;
125 }
126 if (strstr(buf2, "P2P GO"))
127 go = 1;
128 }
129
130 if (wpa_command_resp(ifname, "LIST_NETWORKS", buf2,
131 sizeof(buf2)) == 0) {
132 char *line, *end;
133 line = buf2;
134 while (line && *line) {
135 end = strchr(line, ' ');
136 if (end)
137 *end++ = '\0';
138 if (strstr(line, ssid) &&
139 strstr(line, "[CURRENT]")) {
140 printf("Selected interface '%s' "
141 "based on LIST_NETWORKS\n",
142 ifname);
143 add = 1;
144 break;
145 }
146 line = end;
147 }
148 }
149
150 if (add) {
151 p2p_group_add(dut, ifname, go, grpid, ssid);
152 return dut->groups;
153 }
154
155 ifname = pos;
156 }
157
158 return NULL;
159}
160
161
162static const char * get_group_ifname(struct sigma_dut *dut, const char *ifname)
163{
164 char buf[1000], *iface, *pos;
165 char state[100];
166
167 if (dut->groups) {
168 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: Use group interface "
169 "%s instead of main interface %s",
170 __func__, dut->groups->ifname, ifname);
171 return dut->groups->ifname;
172 }
173
174 /* Try to find a suitable group interface */
175 if (wpa_command_resp(get_main_ifname(), "INTERFACES",
176 buf, sizeof(buf)) < 0)
177 return ifname;
178
179 iface = buf;
180 while (iface && *iface) {
181 pos = strchr(iface, '\n');
182 if (pos)
183 *pos++ = '\0';
184 sigma_dut_print(dut, DUT_MSG_DEBUG, "Considering interface "
185 "'%s' for IP address", iface);
186 if (get_wpa_status(iface, "wpa_state", state, sizeof(state)) ==
187 0 && strcmp(state, "COMPLETED") == 0)
188 return iface;
189 iface = pos;
190 }
191
192 return ifname;
193}
194
195
196static int p2p_peer_known(const char *ifname, const char *peer, int full)
197{
198 char buf[4096];
199
200 snprintf(buf, sizeof(buf), "P2P_PEER %s", peer);
201 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
202 return 0;
203 if (strncasecmp(buf, peer, strlen(peer)) != 0)
204 return 0;
205 if (!full)
206 return 1;
207 return strstr(buf, "[PROBE_REQ_ONLY]") == NULL ? 1 : 0;
208}
209
210
211static int p2p_discover_peer(struct sigma_dut *dut, const char *ifname,
212 const char *peer, int full)
213{
214 unsigned int count;
215
216 if (p2p_peer_known(ifname, peer, full))
217 return 0;
218 printf("Peer not yet discovered - start discovery\n");
219 if (wpa_command(ifname, "P2P_FIND") < 0) {
220 printf("Failed to start discovery\n");
221 return -1;
222 }
223
224 count = 0;
225 while (count < dut->default_timeout) {
226 count++;
227 sleep(1);
228 if (p2p_peer_known(ifname, peer, full)) {
229 printf("Peer discovered - return to previous state\n");
230 switch (dut->p2p_mode) {
231 case P2P_IDLE:
232 wpa_command(ifname, "P2P_STOP_FIND");
233 break;
234 case P2P_DISCOVER:
235 /* Already running discovery */
236 break;
237 case P2P_LISTEN:
238 wpa_command(ifname, "P2P_LISTEN");
239 break;
240 case P2P_DISABLE:
241 printf("Invalid state - P2P was disabled?!\n");
242 break;
243 }
244 return 0;
245 }
246 }
247
248 printf("Peer discovery timed out - peer not discovered\n");
249 wpa_command(ifname, "P2P_STOP_FIND");
250
251 return -1;
252}
253
254
255static void add_dummy_services(const char *intf)
256{
257 wpa_command(intf, "P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027");
258 wpa_command(intf, "P2P_SERVICE_ADD bonjour 076578616d706c650b5f6166706f766572746370c00c001001 00");
259 wpa_command(intf, "P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027");
260 wpa_command(intf, "P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074");
261
262 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice");
263 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:5566d33e-9774-09ab-4822-333456785632::upnp:rootdevice");
264 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:1122de4e-8574-59ab-9322-333456789044::urn:schemas-upnp-org:service:ContentDirectory:2");
265 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:5566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2");
266 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device:InternetGatewayDevice:1");
267
268 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:1859dede-8574-59ab-9332-123456789012::upnp:rootdevice");
269 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:1566d33e-9774-09ab-4822-333456785632::upnp:rootdevice");
270 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:2122de4e-8574-59ab-9322-333456789044::urn:schemas-upnp-org:service:ContentDirectory:2");
271 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:1566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2");
272 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:1859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device:InternetGatewayDevice:1");
273
274 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:2859dede-8574-59ab-9332-123456789012::upnp:rootdevice");
275 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:2566d33e-9774-09ab-4822-333456785632::upnp:rootdevice");
276 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:3122de4e-8574-59ab-9322-333456789044::urn:schemas-upnp-org:service:ContentDirectory:2");
277 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:2566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2");
278 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:2859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device:InternetGatewayDevice:1");
279
280 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:3859dede-8574-59ab-9332-123456789012::upnp:rootdevice");
281 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:3566d33e-9774-09ab-4822-333456785632::upnp:rootdevice");
282 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:4122de4e-8574-59ab-9322-333456789044::urn:schemas-upnp-org:service:ContentDirectory:2");
283 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:3566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2");
284 wpa_command(intf, "P2P_SERVICE_ADD upnp 10 uuid:3859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device:InternetGatewayDevice:1");
285}
286
287
288void disconnect_station(struct sigma_dut *dut)
289{
290 wpa_command(get_station_ifname(), "DISCONNECT");
291 remove_wpa_networks(get_station_ifname());
292 dut->infra_ssid[0] = '\0';
293#ifdef __linux__
294 {
295 char path[128];
296 char buf[200];
297 struct stat s;
298 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid",
299 get_station_ifname());
300 if (stat(path, &s) == 0) {
301 snprintf(buf, sizeof(buf),
302 "kill `cat %s`", path);
303 sigma_dut_print(dut, DUT_MSG_DEBUG,
304 "Kill previous DHCP client: %s", buf);
305 run_system(dut, buf);
306 unlink(path);
307 }
308 snprintf(buf, sizeof(buf),
309 "ifconfig %s 0.0.0.0", get_station_ifname());
310 sigma_dut_print(dut, DUT_MSG_DEBUG,
311 "Clear infrastructure station IP address: %s",
312 buf);
313 run_system(dut, buf);
314 }
315#endif /* __linux__ */
316}
317
318
319static int cmd_sta_get_p2p_dev_address(struct sigma_dut *dut,
320 struct sigma_conn *conn,
321 struct sigma_cmd *cmd)
322{
323 const char *intf = get_param(cmd, "interface");
324 char buf[100], resp[200];
325
326 start_sta_mode(dut);
327 if (get_wpa_status(intf, "p2p_device_address", buf, sizeof(buf)) < 0) {
328 send_resp(dut, conn, SIGMA_ERROR, NULL);
329 return 0;
330 }
331
332 snprintf(resp, sizeof(resp), "DevID,%s", buf);
333 send_resp(dut, conn, SIGMA_COMPLETE, resp);
334 return 0;
335}
336
337
338static int cmd_sta_set_p2p(struct sigma_dut *dut, struct sigma_conn *conn,
339 struct sigma_cmd *cmd)
340{
341 const char *intf = get_param(cmd, "Interface");
342 char buf[256];
343 const char *val;
344 const char *noa_dur, *noa_int, *noa_count;
345 const char *ext_listen_int, *ext_listen_period;
346
347 val = get_param(cmd, "LISTEN_CHN");
348 if (val) {
349 dut->listen_chn = atoi(val);
350 snprintf(buf, sizeof(buf), "P2P_SET listen_channel %d",
351 dut->listen_chn);
352 if (wpa_command(intf, buf) < 0)
353 return -2;
354 }
355
356 ext_listen_int = get_param(cmd, "Ext_Listen_Time_Interval");
357 ext_listen_period = get_param(cmd, "Ext_Listen_Time_Period");
358
359 if (ext_listen_int || ext_listen_period) {
360 if (!ext_listen_int || !ext_listen_period) {
361 sigma_dut_print(dut, DUT_MSG_INFO, "Only one "
362 "ext_listen_time parameter included; "
363 "both are needed");
364 return -1;
365 }
366 snprintf(buf, sizeof(buf), "P2P_EXT_LISTEN %d %d",
367 atoi(ext_listen_period),
368 atoi(ext_listen_int));
369 if (wpa_command(intf, buf) < 0)
370 return -2;
371 }
372
373 val = get_param(cmd, "P2P_MODE");
374 if (val) {
375 if (strcasecmp(val, "Listen") == 0) {
376 wpa_command(intf, "P2P_SET disabled 0");
377 if (wpa_command(intf, "P2P_LISTEN") < 0)
378 return -2;
379 dut->p2p_mode = P2P_LISTEN;
380 } else if (strcasecmp(val, "Discover") == 0) {
381 wpa_command(intf, "P2P_SET disabled 0");
382 if (wpa_command(intf, "P2P_FIND") < 0)
383 return -2;
384 dut->p2p_mode = P2P_DISCOVER;
385 } else if (strcasecmp(val, "Idle") == 0) {
386 wpa_command(intf, "P2P_SET disabled 0");
387 if (wpa_command(intf, "P2P_STOP_FIND") < 0)
388 return -2;
389 dut->p2p_mode = P2P_IDLE;
390 } else if (strcasecmp(val, "Disable") == 0) {
391 if (wpa_command(intf, "P2P_SET disabled 1") < 0)
392 return -2;
393 dut->p2p_mode = P2P_DISABLE;
394 } else
395 return -1;
396 }
397
398 val = get_param(cmd, "PERSISTENT");
399 if (val) {
400 dut->persistent = atoi(val);
401 }
402
403 val = get_param(cmd, "INTRA_BSS");
404 if (val) {
405 int intra_bss = atoi(val);
406 /* TODO: add support for this */
407 if (!intra_bss) {
408 sigma_dut_print(dut, DUT_MSG_INFO, "Disabling of "
409 "intra-BSS bridging not supported");
410 return -1;
411 }
412 dut->intra_bss = intra_bss;
413 }
414
415 noa_dur = get_param(cmd, "NoA_duration");
416 noa_int = get_param(cmd, "NoA_Interval");
417 noa_count = get_param(cmd, "NoA_Count");
418 if (noa_dur)
419 dut->noa_duration = atoi(noa_dur);
420
421 if (noa_int)
422 dut->noa_interval = atoi(noa_int);
423
424 if (noa_count)
425 dut->noa_count = atoi(noa_count);
426
427 if (noa_dur || noa_int || noa_count) {
428 int start;
429 const char *ifname;
430 if (dut->noa_count == 0 && dut->noa_duration == 0)
431 start = 0;
432 else if (dut->noa_duration > 102) /* likely non-periodic NoA */
433 start = 50;
434 else
435 start = 102 - dut->noa_duration;
436 snprintf(buf, sizeof(buf), "P2P_SET noa %d,%d,%d",
437 dut->noa_count, start,
438 dut->noa_duration);
439 ifname = get_group_ifname(dut, intf);
440 sigma_dut_print(dut, DUT_MSG_INFO,
441 "Set GO NoA for interface %s", ifname);
442 if (wpa_command(ifname, buf) < 0) {
443 send_resp(dut, conn, SIGMA_ERROR,
444 "errorCode,Use of NoA as GO not supported");
445 return 0;
446 }
447 }
448
449 val = get_param(cmd, "Concurrency");
450 if (val) {
451 /* TODO */
452 }
453
454 val = get_param(cmd, "P2PInvitation");
455 if (val) {
456 /* TODO */
457 }
458
459 val = get_param(cmd, "BCN_INT");
460 if (val) {
461 /* TODO */
462 }
463
464 val = get_param(cmd, "Discoverability");
465 if (val) {
466 snprintf(buf, sizeof(buf), "P2P_SET discoverability %d",
467 atoi(val));
468 if (wpa_command(intf, buf) < 0)
469 return -2;
470 }
471
472 val = get_param(cmd, "Service_Discovery");
473 if (val) {
474 int sd = atoi(val);
475 if (sd) {
476 wpa_command(intf, "P2P_SERVICE_FLUSH");
477
478 if (sd == 2)
479 wpa_command(intf, "P2P_SET force_long_sd 1");
480
481 /*
482 * Set up some dummy service to create a large SD
483 * response that requires fragmentation.
484 */
485 add_dummy_services(intf);
486 } else {
487 wpa_command(intf, "P2P_SERVICE_FLUSH");
488 }
489 }
490
491 val = get_param(cmd, "CrossConnection");
492 if (val) {
493 if (atoi(val)) {
494 if (wpa_command(intf, "P2P_SET cross_connect 1") < 0)
495 return -2;
496 } else {
497 if (wpa_command(intf, "P2P_SET cross_connect 0") < 0)
498 return -2;
499 }
500 }
501
502 val = get_param(cmd, "P2PManaged");
503 if (val) {
504 if (atoi(val)) {
505 send_resp(dut, conn, SIGMA_INVALID, "ErrorCode,"
506 "P2P Managed functionality not supported");
507 return 0;
508 }
509 }
510
511 val = get_param(cmd, "GO_APSD");
512 if (val) {
513 if (atoi(val)) {
514 if (wpa_command(intf, "P2P_SET go_apsd 1") < 0)
515 return -2;
516 } else {
517 if (wpa_command(intf, "P2P_SET go_apsd 0") < 0)
518 return -2;
519 }
520 }
521
522 return 1;
523}
524
525
526static int cmd_sta_start_autonomous_go(struct sigma_dut *dut,
527 struct sigma_conn *conn,
528 struct sigma_cmd *cmd)
529{
530 const char *intf = get_param(cmd, "Interface");
531 const char *oper_chn = get_param(cmd, "OPER_CHN");
532 const char *ssid_param = get_param(cmd, "SSID");
533 int freq, chan, res;
534 char buf[256], grpid[100], resp[200];
535 struct wpa_ctrl *ctrl;
536 char *ifname, *gtype, *pos, *ssid, bssid[20];
537 char *go_dev_addr;
538
539 if (oper_chn == NULL)
540 return -1;
541
542 chan = atoi(oper_chn);
543 if (chan >= 1 && chan <= 13)
544 freq = 2407 + chan * 5;
545 else if (chan == 14)
546 freq = 2484;
547 else
548 freq = 5000 + chan * 5;
549
550 if (ssid_param)
551 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix %s",
552 ssid_param);
553 else
554 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix ");
555 if (wpa_command(intf, buf) < 0)
556 return -2;
557
558 /* Stop Listen/Discovery state to avoid issues with GO operations */
559 if (wpa_command(intf, "P2P_STOP_FIND") < 0)
560 return -2;
561
562 ctrl = open_wpa_mon(intf);
563 if (ctrl == NULL) {
564 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
565 "wpa_supplicant monitor connection");
566 return -2;
567 }
568
569 snprintf(buf, sizeof(buf), "P2P_GROUP_ADD %sfreq=%d",
570 dut->persistent ? "persistent " : "", freq);
571 if (wpa_command(intf, buf) < 0) {
572 wpa_ctrl_detach(ctrl);
573 wpa_ctrl_close(ctrl);
574 return -2;
575 }
576
577 res = get_wpa_cli_event(dut, ctrl, "P2P-GROUP-STARTED",
578 buf, sizeof(buf));
579
580 wpa_ctrl_detach(ctrl);
581 wpa_ctrl_close(ctrl);
582
583 if (res < 0) {
584 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,GO starting "
585 "did not complete");
586 return 0;
587 }
588
589 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group started event '%s'", buf);
590 ifname = strchr(buf, ' ');
591 if (ifname == NULL)
592 return -2;
593 ifname++;
594 pos = strchr(ifname, ' ');
595 if (pos == NULL)
596 return -2;
597 *pos++ = '\0';
598 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group interface %s", ifname);
599
600 gtype = pos;
601 pos = strchr(gtype, ' ');
602 if (pos == NULL)
603 return -2;
604 *pos++ = '\0';
605 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group type %s", gtype);
606
607 ssid = strstr(pos, "ssid=\"");
608 if (ssid == NULL)
609 return -2;
610 ssid += 6;
611 pos = strchr(ssid, '"');
612 if (pos == NULL)
613 return -2;
614 *pos++ = '\0';
615 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group SSID %s", ssid);
616
617 go_dev_addr = strstr(pos, "go_dev_addr=");
618 if (go_dev_addr == NULL) {
619 sigma_dut_print(dut, DUT_MSG_ERROR, "No GO P2P Device Address "
620 "found");
621 return -2;
622 }
623 go_dev_addr += 12;
624 if (strlen(go_dev_addr) < 17) {
625 sigma_dut_print(dut, DUT_MSG_ERROR, "Too short GO P2P Device "
626 "Address '%s'", go_dev_addr);
627 return -2;
628 }
629 go_dev_addr[17] = '\0';
630 *pos = '\0';
631 sigma_dut_print(dut, DUT_MSG_DEBUG, "GO P2P Device Address %s",
632 go_dev_addr);
633
634 if (get_wpa_status(ifname, "bssid", bssid, sizeof(bssid)) < 0)
635 return -2;
636 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group BSSID %s", bssid);
637
638 snprintf(grpid, sizeof(grpid), "%s %s", go_dev_addr, ssid);
639 p2p_group_add(dut, ifname, strcmp(gtype, "GO") == 0, grpid, ssid);
640
641 snprintf(resp, sizeof(resp), "GroupID,%s", grpid);
642 send_resp(dut, conn, SIGMA_COMPLETE, resp);
643 return 0;
644}
645
646
647static int cmd_sta_p2p_connect(struct sigma_dut *dut, struct sigma_conn *conn,
648 struct sigma_cmd *cmd)
649{
650 const char *intf = get_param(cmd, "Interface");
651 const char *devid = get_param(cmd, "P2PDevID");
652 /* const char *grpid_param = get_param(cmd, "GroupID"); */
653 int res;
654 char buf[256];
655 struct wpa_ctrl *ctrl;
656 char *ifname, *gtype, *pos, *ssid, bssid[20];
657 char grpid[100];
658
659 /* TODO: handle the new grpid argument */
660
661 if (devid == NULL)
662 return -1;
663
664 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
665 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS parameters "
666 "not yet set");
667 return 0;
668 }
669
670 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trying to discover GO %s", devid);
671 if (p2p_discover_peer(dut, intf, devid, 1) < 0) {
672 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
673 "discover the requested peer");
674 return 0;
675 }
676
677 ctrl = open_wpa_mon(intf);
678 if (ctrl == NULL) {
679 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
680 "wpa_supplicant monitor connection");
681 return -2;
682 }
683
684 switch (dut->wps_method) {
685 case WFA_CS_WPS_PBC:
686 snprintf(buf, sizeof(buf), "P2P_CONNECT %s pbc join",
687 devid);
688 break;
689 case WFA_CS_WPS_PIN_DISPLAY:
690 snprintf(buf, sizeof(buf), "P2P_CONNECT %s %s display join",
691 devid, dut->wps_pin);
692 break;
693 case WFA_CS_WPS_PIN_KEYPAD:
694 snprintf(buf, sizeof(buf), "P2P_CONNECT %s %s keypad join",
695 devid, dut->wps_pin);
696 break;
697 default:
698 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unknown WPS "
699 "method for sta_p2p_connect");
700 wpa_ctrl_detach(ctrl);
701 wpa_ctrl_close(ctrl);
702 return 0;
703 }
704
705 if (wpa_command(intf, buf) < 0) {
706 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to join "
707 "the group");
708 wpa_ctrl_detach(ctrl);
709 wpa_ctrl_close(ctrl);
710 return 0;
711 }
712
713 res = get_wpa_cli_event(dut, ctrl, "P2P-GROUP-STARTED",
714 buf, sizeof(buf));
715
716 wpa_ctrl_detach(ctrl);
717 wpa_ctrl_close(ctrl);
718
719 if (res < 0) {
720 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Group joining "
721 "did not complete");
722 return 0;
723 }
724
725 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group started event '%s'", buf);
726 ifname = strchr(buf, ' ');
727 if (ifname == NULL)
728 return -2;
729 ifname++;
730 pos = strchr(ifname, ' ');
731 if (pos == NULL)
732 return -2;
733 *pos++ = '\0';
734 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group interface %s", ifname);
735
736 gtype = pos;
737 pos = strchr(gtype, ' ');
738 if (pos == NULL)
739 return -2;
740 *pos++ = '\0';
741 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group type %s", gtype);
742
743 ssid = strstr(pos, "ssid=\"");
744 if (ssid == NULL)
745 return -2;
746 ssid += 6;
747 pos = strchr(ssid, '"');
748 if (pos == NULL)
749 return -2;
750 *pos = '\0';
751 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group SSID %s", ssid);
752
753 if (get_wpa_status(ifname, "bssid", bssid, sizeof(bssid)) < 0)
754 return -2;
755 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group BSSID %s", bssid);
756
757 snprintf(grpid, sizeof(grpid), "%s %s", bssid, ssid);
758 p2p_group_add(dut, ifname, strcmp(gtype, "GO") == 0, grpid, ssid);
759
760 return 1;
761}
762
763
764static int p2p_group_formation_event(struct sigma_dut *dut,
765 struct sigma_conn *conn,
766 struct wpa_ctrl *ctrl,
767 const char *intf, const char *peer_role,
768 int nfc);
769
770static int cmd_sta_p2p_start_group_formation(struct sigma_dut *dut,
771 struct sigma_conn *conn,
772 struct sigma_cmd *cmd)
773{
774 const char *intf = get_param(cmd, "Interface");
775 const char *devid = get_param(cmd, "P2PDevID");
776 const char *intent_val = get_param(cmd, "INTENT_VAL");
777 const char *init_go_neg = get_param(cmd, "INIT_GO_NEG");
778 const char *oper_chn = get_param(cmd, "OPER_CHN");
779 const char *ssid_param = get_param(cmd, "SSID");
780 int freq = 0, chan, init;
781 char buf[256];
782 struct wpa_ctrl *ctrl;
783
784 if (devid == NULL || intent_val == NULL)
785 return -1;
786
787 if (init_go_neg)
788 init = atoi(init_go_neg);
789 else
790 init = 0;
791
792 if (oper_chn) {
793 chan = atoi(oper_chn);
794 if (chan >= 1 && chan <= 13)
795 freq = 2407 + chan * 5;
796 else if (chan == 14)
797 freq = 2484;
798 else
799 freq = 5000 + chan * 5;
800 }
801
802 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
803 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS parameters "
804 "not yet set");
805 return 0;
806 }
807
808 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trying to discover peer %s for "
809 "group formation", devid);
810 if (p2p_discover_peer(dut, intf, devid, init) < 0) {
811 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
812 "discover the requested peer");
813 return 0;
814 }
815
816 if (ssid_param)
817 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix %s",
818 ssid_param);
819 else
820 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix ");
821 if (wpa_command(intf, buf) < 0)
822 return -2;
823
824 if (init) {
825 ctrl = open_wpa_mon(intf);
826 if (ctrl == NULL) {
827 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
828 "wpa_supplicant monitor connection");
829 return -2;
830 }
831 } else
832 ctrl = NULL;
833
834 snprintf(buf, sizeof(buf), "P2P_CONNECT %s %s%s%s%s go_intent=%d",
835 devid,
836 dut->wps_method == WFA_CS_WPS_PBC ?
837 "pbc" : dut->wps_pin,
838 dut->wps_method == WFA_CS_WPS_PBC ? "" :
839 (dut->wps_method == WFA_CS_WPS_PIN_DISPLAY ? " display" :
840 (dut->wps_method == WFA_CS_WPS_PIN_LABEL ? " label" :
841 " keypad" )),
842 dut->persistent ? " persistent" : "",
843 init ? "" : " auth",
844 atoi(intent_val));
845 if (freq > 0) {
846 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
847 " freq=%d", freq);
848 }
849 if (wpa_command(intf, buf) < 0) {
850 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to start "
851 "group formation");
852 if (ctrl) {
853 wpa_ctrl_detach(ctrl);
854 wpa_ctrl_close(ctrl);
855 }
856 return 0;
857 }
858
859 if (!init)
860 return 1;
861
862 return p2p_group_formation_event(dut, conn, ctrl, intf, NULL, 0);
863}
864
865
866static int p2p_group_formation_event(struct sigma_dut *dut,
867 struct sigma_conn *conn,
868 struct wpa_ctrl *ctrl,
869 const char *intf, const char *peer_role,
870 int nfc)
871{
872 int res;
873 char buf[256], grpid[50], resp[256];
874 char *ifname, *gtype, *pos, *ssid, bssid[20];
875 char *go_dev_addr;
876 char role[30];
877 const char *events[] = {
878 "P2P-GROUP-STARTED",
879 "P2P-GO-NEG-FAILURE",
880 "P2P-NFC-PEER-CLIENT",
881 "P2P-GROUP-FORMATION-FAILURE",
882 NULL
883 };
884
885 role[0] = '\0';
886 if (peer_role)
887 snprintf(role, sizeof(role), ",PeerRole,%s", peer_role);
888
889 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
890
891 wpa_ctrl_detach(ctrl);
892 wpa_ctrl_close(ctrl);
893
894 if (res < 0) {
895 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Group formation "
896 "did not complete");
897 return 0;
898 }
899
900 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group started event '%s'", buf);
901
902 if (strstr(buf, "P2P-NFC-PEER-CLIENT")) {
903 snprintf(resp, sizeof(resp),
904 "Result,,GroupID,,PeerRole,1,PauseFlag,0");
905 send_resp(dut, conn, SIGMA_COMPLETE, resp);
906 return 0;
907 }
908
909 if (strstr(buf, "P2P-GROUP-FORMATION-FAILURE")) {
910 snprintf(buf, sizeof(buf), "ErrorCode,Group formation failed");
911 send_resp(dut, conn, SIGMA_ERROR, buf);
912 return 0;
913 }
914
915 if (strstr(buf, "P2P-GO-NEG-FAILURE")) {
916 int status = -1;
917 pos = strstr(buf, " status=");
918 if (pos)
919 status = atoi(pos + 8);
920 sigma_dut_print(dut, DUT_MSG_INFO, "GO Negotiation failed "
921 "(status=%d)", status);
922 if (status == 9) {
923 sigma_dut_print(dut, DUT_MSG_INFO, "Both devices "
924 "tried to use GO Intent 15");
925 send_resp(dut, conn, SIGMA_COMPLETE, "result,FAIL");
926 return 0;
927 }
928 snprintf(buf, sizeof(buf), "ErrorCode,GO Negotiation failed "
929 "(status=%d)", status);
930 send_resp(dut, conn, SIGMA_ERROR, buf);
931 return 0;
932 }
933
934 ifname = strchr(buf, ' ');
935 if (ifname == NULL)
936 return -2;
937 ifname++;
938 pos = strchr(ifname, ' ');
939 if (pos == NULL)
940 return -2;
941 *pos++ = '\0';
942 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group interface %s", ifname);
943
944 gtype = pos;
945 pos = strchr(gtype, ' ');
946 if (pos == NULL)
947 return -2;
948 *pos++ = '\0';
949 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group type %s", gtype);
950
951 ssid = strstr(pos, "ssid=\"");
952 if (ssid == NULL)
953 return -2;
954 ssid += 6;
955 pos = strchr(ssid, '"');
956 if (pos == NULL)
957 return -2;
958 *pos++ = '\0';
959 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group SSID %s", ssid);
960
961 go_dev_addr = strstr(pos, "go_dev_addr=");
962 if (go_dev_addr == NULL) {
963 sigma_dut_print(dut, DUT_MSG_ERROR, "No GO P2P Device Address "
964 "found\n");
965 return -2;
966 }
967 go_dev_addr += 12;
968 if (strlen(go_dev_addr) < 17) {
969 sigma_dut_print(dut, DUT_MSG_ERROR, "Too short GO P2P Device "
970 "Address '%s'", go_dev_addr);
971 return -2;
972 }
973 go_dev_addr[17] = '\0';
974 *pos = '\0';
975 sigma_dut_print(dut, DUT_MSG_ERROR, "GO P2P Device Address %s",
976 go_dev_addr);
977
978 if (get_wpa_status(ifname, "bssid", bssid, sizeof(bssid)) < 0)
979 return -2;
980 sigma_dut_print(dut, DUT_MSG_DEBUG, "Group BSSID %s", bssid);
981
982 snprintf(grpid, sizeof(grpid), "%s %s", go_dev_addr, ssid);
983 p2p_group_add(dut, ifname, strcmp(gtype, "GO") == 0, grpid, ssid);
984 snprintf(resp, sizeof(resp), "Result,%s,GroupID,%s%s%s",
985 strcmp(gtype, "GO") == 0 ? "GO" : "CLIENT", grpid, role,
986 nfc ? ",PauseFlag,0" : "");
987 send_resp(dut, conn, SIGMA_COMPLETE, resp);
988
989#ifdef __QNXNTO__
990 /* Start DHCP server if we became the GO */
991 if (strcmp(gtype, "GO") == 0 &&
992 system("dhcpd -cf /etc/dhcpd.conf -pf /var/run/dhcpd qca1 &") == 0)
993 sigma_dut_print(dut, DUT_MSG_ERROR,
994 "Failed to start DHCPD server");
995#endif /* __QNXNTO__ */
996
997 return 0;
998}
999
1000
1001int wps_connection_event(struct sigma_dut *dut, struct sigma_conn *conn,
1002 struct wpa_ctrl *ctrl, const char *intf, int p2p_resp)
1003{
1004 int res;
1005 char buf[256];
1006 const char *events[] = {
1007 "CTRL-EVENT-CONNECTED",
1008 "WPS-FAIL",
1009 "WPS-TIMEOUT",
1010 NULL
1011 };
1012
1013 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
1014
1015 wpa_ctrl_detach(ctrl);
1016 wpa_ctrl_close(ctrl);
1017
1018 if (res < 0) {
1019#ifdef USE_ERROR_RETURNS
1020 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS connection "
1021 "did not complete");
1022#else
1023 send_resp(dut, conn, SIGMA_COMPLETE, "ErrorCode,WPS connection "
1024 "did not complete");
1025#endif
1026 return 0;
1027 }
1028
1029 if (strstr(buf, "WPS-FAIL") || strstr(buf, "WPS-TIMEOUT")) {
1030#ifdef USE_ERROR_RETURNS
1031 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS operation "
1032 "failed");
1033#else
1034 send_resp(dut, conn, SIGMA_COMPLETE, "ErrorCode,WPS operation "
1035 "failed");
1036#endif
1037 return 0;
1038 }
1039
1040 if (!p2p_resp)
1041 return 1;
1042 send_resp(dut, conn, SIGMA_COMPLETE, "Result,,GroupID,,PeerRole,");
1043 return 0;
1044}
1045
1046
1047static int cmd_sta_p2p_dissolve(struct sigma_dut *dut, struct sigma_conn *conn,
1048 struct sigma_cmd *cmd)
1049{
1050 const char *intf = get_param(cmd, "interface");
1051 const char *grpid = get_param(cmd, "GroupID");
1052 struct wfa_cs_p2p_group *grp;
1053 char buf[128];
1054
1055 if (grpid == NULL)
1056 return -1;
1057
1058 grp = p2p_group_get(dut, grpid);
1059 if (grp == NULL) {
1060 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Requested group "
1061 "not found");
1062 return 0;
1063 }
1064
1065 snprintf(buf, sizeof(buf), "P2P_GROUP_REMOVE %s", grp->ifname);
1066 if (wpa_command(intf, buf) < 0) {
1067 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to remove the "
1068 "specified group from wpa_supplicant - assume "
1069 "group has already been removed");
1070 }
1071 sigma_dut_print(dut, DUT_MSG_DEBUG, "Removed group %s", grpid);
1072 if (grp->go)
1073 dut->go = 0;
1074 else
1075 dut->p2p_client = 0;
1076 p2p_group_remove(dut, grpid);
1077 return 1;
1078}
1079
1080
1081static int cmd_sta_send_p2p_invitation_req(struct sigma_dut *dut,
1082 struct sigma_conn *conn,
1083 struct sigma_cmd *cmd)
1084{
1085 const char *intf = get_param(cmd, "interface");
1086 const char *devid = get_param(cmd, "P2PDevID");
1087 const char *grpid = get_param(cmd, "GroupID");
1088 const char *reinvoke = get_param(cmd, "Reinvoke");
1089 char c[256];
1090 char buf[4096];
1091 struct wpa_ctrl *ctrl;
1092 int res;
1093
1094 if (devid == NULL || grpid == NULL)
1095 return -1;
1096
1097 if (reinvoke && atoi(reinvoke)) {
1098 int id = -1;
1099 char *ssid, *pos;
1100
1101 ssid = strchr(grpid, ' ');
1102 if (ssid == NULL) {
1103 sigma_dut_print(dut, DUT_MSG_INFO, "Invalid grpid");
1104 return -1;
1105 }
1106 ssid++;
1107 sigma_dut_print(dut, DUT_MSG_DEBUG, "Search for persistent "
1108 "group credentials based on SSID: '%s'", ssid);
1109 if (wpa_command_resp(intf, "LIST_NETWORKS",
1110 buf, sizeof(buf)) < 0)
1111 return -2;
1112 pos = strstr(buf, ssid);
1113 if (pos == NULL || pos == buf || pos[-1] != '\t' ||
1114 pos[strlen(ssid)] != '\t') {
1115 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
1116 "Persistent group credentials not found");
1117 return 0;
1118 }
1119 while (pos > buf && pos[-1] != '\n')
1120 pos--;
1121 id = atoi(pos);
1122 snprintf(c, sizeof(c), "P2P_INVITE persistent=%d peer=%s",
1123 id, devid);
1124 } else {
1125 struct wfa_cs_p2p_group *grp;
1126 grp = p2p_group_get(dut, grpid);
1127 if (grp == NULL) {
1128 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
1129 "No active P2P group found for invitation");
1130 return 0;
1131 }
1132 snprintf(c, sizeof(c), "P2P_INVITE group=%s peer=%s",
1133 grp->ifname, devid);
1134 }
1135
1136 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trying to discover peer %s for "
1137 "invitation", devid);
1138 if (p2p_discover_peer(dut, intf, devid, 0) < 0) {
1139 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
1140 "discover the requested peer");
1141 return 0;
1142 }
1143
1144 ctrl = open_wpa_mon(intf);
1145 if (ctrl == NULL) {
1146 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
1147 "wpa_supplicant monitor connection");
1148 return -2;
1149 }
1150
1151 if (wpa_command(intf, c) < 0) {
1152 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to send invitation "
1153 "request");
1154 wpa_ctrl_detach(ctrl);
1155 wpa_ctrl_close(ctrl);
1156 return -2;
1157 }
1158
1159 res = get_wpa_cli_event(dut, ctrl, "P2P-INVITATION-RESULT",
1160 buf, sizeof(buf));
1161
1162 wpa_ctrl_detach(ctrl);
1163 wpa_ctrl_close(ctrl);
1164
1165 if (res < 0)
1166 return -2;
1167
1168 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invitation event: '%s'", buf);
1169 return 1;
1170}
1171
1172
1173static int cmd_sta_accept_p2p_invitation_req(struct sigma_dut *dut,
1174 struct sigma_conn *conn,
1175 struct sigma_cmd *cmd)
1176{
1177 const char *intf = get_param(cmd, "Interface");
1178 const char *devid = get_param(cmd, "P2PDevID");
1179 const char *grpid = get_param(cmd, "GroupID");
1180 const char *reinvoke = get_param(cmd, "Reinvoke");
1181 char buf[100];
1182
1183 if (devid == NULL || grpid == NULL)
1184 return -1;
1185
1186 if (reinvoke && atoi(reinvoke)) {
1187 /*
1188 * Assume persistent reconnect is enabled and there is no need
1189 * to do anything here.
1190 */
1191 return 1;
1192 }
1193
1194 /*
1195 * In a client-joining-a-running-group case, we need to separately
1196 * authorize the invitation.
1197 */
1198
1199 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trying to discover GO %s", devid);
1200 if (p2p_discover_peer(dut, intf, devid, 1) < 0) {
1201 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
1202 "discover the requested peer");
1203 return 0;
1204 }
1205
1206 snprintf(buf, sizeof(buf), "P2P_CONNECT %s %s join auth",
1207 devid,
1208 dut->wps_method == WFA_CS_WPS_PBC ?
1209 "pbc" : dut->wps_pin);
1210 if (wpa_command(intf, buf) < 0)
1211 return -2;
1212
1213 return 1;
1214}
1215
1216
1217static int cmd_sta_send_p2p_provision_dis_req(struct sigma_dut *dut,
1218 struct sigma_conn *conn,
1219 struct sigma_cmd *cmd)
1220{
1221 const char *intf = get_param(cmd, "interface");
1222 const char *conf_method = get_param(cmd, "ConfigMethod");
1223 const char *devid = get_param(cmd, "P2PDevID");
1224 char buf[256];
1225 char *method;
1226
1227 if (conf_method == NULL || devid == NULL)
1228 return -1;
1229
1230 if (strcasecmp(conf_method, "Display") == 0)
1231 method = "display";
1232 else if (strcasecmp(conf_method, "Keyboard") == 0 ||
1233 strcasecmp(conf_method, "keypad") == 0)
1234 method = "keypad";
1235 else if (strcasecmp(conf_method, "Label") == 0)
1236 method = "label";
1237 else if (strcasecmp(conf_method, "pbc") == 0 ||
1238 strcasecmp(conf_method, "pushbutton") == 0)
1239 method = "pbc";
1240 else
1241 return -1;
1242
1243 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trying to discover peer %s for "
1244 "provision discovery", devid);
1245 if (p2p_discover_peer(dut, intf, devid, 0) < 0) {
1246 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
1247 "discover the requested peer");
1248 return 0;
1249 }
1250
1251 snprintf(buf, sizeof(buf), "P2P_PROV_DISC %s %s", devid, method);
1252 if (wpa_command(intf, buf) < 0) {
1253 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to send provision "
1254 "discovery request");
1255 return -2;
1256 }
1257
1258 return 1;
1259}
1260
1261
1262static int cmd_sta_set_wps_pbc(struct sigma_dut *dut, struct sigma_conn *conn,
1263 struct sigma_cmd *cmd)
1264{
1265 /* const char *intf = get_param(cmd, "Interface"); */
1266 const char *grpid = get_param(cmd, "GroupID");
1267
1268 if (grpid) {
1269 struct wfa_cs_p2p_group *grp;
1270 grp = p2p_group_get(dut, grpid);
1271 if (grp && grp->go) {
1272 sigma_dut_print(dut, DUT_MSG_DEBUG, "Authorize a "
1273 "client to join with WPS");
1274 wpa_command(grp->ifname, "WPS_PBC");
1275 return 1;
1276 }
1277 }
1278
1279 dut->wps_method = WFA_CS_WPS_PBC;
1280 return 1;
1281}
1282
1283
1284static int cmd_sta_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
1285 struct sigma_cmd *cmd)
1286{
1287 /* const char *intf = get_param(cmd, "Interface"); */
1288 const char *grpid = get_param(cmd, "GroupID");
1289 char *pin = "12345670"; /* TODO: use random PIN */
1290 char resp[100];
1291
1292 if (grpid) {
1293 char buf[100];
1294 struct wfa_cs_p2p_group *grp;
1295 grp = p2p_group_get(dut, grpid);
1296 if (grp && grp->go) {
1297 sigma_dut_print(dut, DUT_MSG_DEBUG, "Authorize a "
1298 "client to join with WPS");
1299 snprintf(buf, sizeof(buf), "WPS_PIN any %s", pin);
1300 if (wpa_command(grp->ifname, buf) < 0)
1301 return -1;
1302 goto done;
1303 }
1304 }
1305
1306 strncpy(dut->wps_pin, pin, sizeof(dut->wps_pin));
1307 dut->wps_method = WFA_CS_WPS_PIN_DISPLAY;
1308done:
1309 snprintf(resp, sizeof(resp), "PIN,%s", pin);
1310 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1311
1312 return 0;
1313}
1314
1315
1316static int cmd_sta_wps_read_label(struct sigma_dut *dut,
1317 struct sigma_conn *conn,
1318 struct sigma_cmd *cmd)
1319{
1320 /* const char *intf = get_param(cmd, "Interface"); */
1321 const char *grpid = get_param(cmd, "GroupID");
1322 char *pin = "12345670";
1323 char resp[100];
1324
1325 if (grpid) {
1326 char buf[100];
1327 struct wfa_cs_p2p_group *grp;
1328 grp = p2p_group_get(dut, grpid);
1329 if (grp && grp->go) {
1330 sigma_dut_print(dut, DUT_MSG_DEBUG, "Authorize a "
1331 "client to join with WPS");
1332 snprintf(buf, sizeof(buf), "WPS_PIN any %s", pin);
1333 wpa_command(grp->ifname, buf);
1334 return 1;
1335 }
1336 }
1337
1338 strncpy(dut->wps_pin, pin, sizeof(dut->wps_pin));
1339 dut->wps_method = WFA_CS_WPS_PIN_LABEL;
1340 snprintf(resp, sizeof(resp), "LABEL,%s", pin);
1341 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1342
1343 return 0;
1344}
1345
1346
1347static int cmd_sta_wps_enter_pin(struct sigma_dut *dut,
1348 struct sigma_conn *conn,
1349 struct sigma_cmd *cmd)
1350{
1351 /* const char *intf = get_param(cmd, "Interface"); */
1352 const char *grpid = get_param(cmd, "GroupID");
1353 const char *pin = get_param(cmd, "PIN");
1354
1355 if (pin == NULL)
1356 return -1;
1357
1358 if (grpid) {
1359 char buf[100];
1360 struct wfa_cs_p2p_group *grp;
1361 grp = p2p_group_get(dut, grpid);
1362 if (grp && grp->go) {
1363 sigma_dut_print(dut, DUT_MSG_DEBUG, "Authorize a "
1364 "client to join with WPS");
1365 snprintf(buf, sizeof(buf), "WPS_PIN any %s", pin);
1366 wpa_command(grp->ifname, buf);
1367 return 1;
1368 }
1369 }
1370
1371 strncpy(dut->wps_pin, pin, sizeof(dut->wps_pin));
1372 dut->wps_pin[sizeof(dut->wps_pin) - 1] = '\0';
1373 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
1374
1375 return 1;
1376}
1377
1378
1379static int cmd_sta_get_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1380 struct sigma_cmd *cmd)
1381{
1382 /* const char *intf = get_param(cmd, "interface"); */
1383 const char *grpid = get_param(cmd, "GroupID");
1384 struct wfa_cs_p2p_group *grp;
1385 char passphrase[64], resp[200];
1386
1387 if (grpid == NULL)
1388 return -1;
1389
1390 grp = p2p_group_get(dut, grpid);
1391 if (grp == NULL) {
1392 send_resp(dut, conn, SIGMA_ERROR,
1393 "errorCode,Requested group not found");
1394 return 0;
1395 }
1396 if (!grp->go) {
1397 send_resp(dut, conn, SIGMA_ERROR,
1398 "errorCode,Local role is not GO in the specified "
1399 "group");
1400 return 0;
1401 }
1402
1403 if (wpa_command_resp(grp->ifname, "P2P_GET_PASSPHRASE",
1404 passphrase, sizeof(passphrase)) < 0)
1405 return -2;
1406
1407 snprintf(resp, sizeof(resp), "passPhrase,%s,ssid,%s",
1408 passphrase, grp->ssid);
1409 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1410
1411 return 0;
1412}
1413
1414
1415int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
1416 struct sigma_cmd *cmd)
1417{
1418 const char *intf = get_param(cmd, "interface");
1419 struct wfa_cs_p2p_group *grp, *prev;
1420 char buf[256];
1421
1422 dut->go = 0;
1423 dut->p2p_client = 0;
1424 dut->wps_method = WFA_CS_WPS_NOT_READY;
1425
1426 grp = dut->groups;
1427 while (grp) {
1428 prev = grp;
1429 grp = grp->next;
1430
1431 snprintf(buf, sizeof(buf), "P2P_GROUP_REMOVE %s",
1432 prev->ifname);
1433 wpa_command(intf, buf);
1434 p2p_group_remove(dut, prev->grpid);
1435 }
1436
1437 wpa_command(intf, "P2P_GROUP_REMOVE *");
1438 wpa_command(intf, "P2P_STOP_FIND");
1439 wpa_command(intf, "P2P_FLUSH");
1440 wpa_command(intf, "P2P_SERVICE_FLUSH");
1441 wpa_command(intf, "P2P_SET disabled 0");
1442 wpa_command(intf, "P2P_SET ssid_postfix ");
1443 wpa_command(intf, "P2P_SET listen_channel 6");
1444 dut->listen_chn = 6;
1445 wpa_command(intf, "P2P_EXT_LISTEN");
1446 wpa_command(intf, "SET p2p_go_intent 7");
1447 wpa_command(intf, "P2P_SET client_apsd disable");
1448 wpa_command(intf, "P2P_SET go_apsd disable");
1449 wpa_command(get_station_ifname(), "P2P_SET ps 98");
1450 wpa_command(get_station_ifname(), "P2P_SET ps 96");
1451 wpa_command(get_station_ifname(), "P2P_SET ps 0");
1452 wpa_command(intf, "SET persistent_reconnect 1");
1453 wpa_command(intf, "SET ampdu 1");
1454 run_system(dut, "iptables -F INPUT");
1455 if (dut->arp_ipaddr[0]) {
1456 snprintf(buf, sizeof(buf), "ip nei del %s dev %s",
1457 dut->arp_ipaddr, dut->arp_ifname);
1458 run_system(dut, buf);
1459 dut->arp_ipaddr[0] = '\0';
1460 }
1461 snprintf(buf, sizeof(buf), "ip nei flush dev %s",
1462 get_station_ifname());
1463 run_system(dut, buf);
1464 dut->p2p_mode = P2P_IDLE;
1465 dut->client_uapsd = 0;
1466 ath6kl_client_uapsd(dut, intf, 0);
1467
1468 remove_wpa_networks(intf);
1469
1470 disconnect_station(dut);
1471
1472 if (dut->iface_down_on_reset)
1473 dut_ifc_reset(dut);
1474
1475 return 1;
1476}
1477
1478
1479static int cmd_sta_get_p2p_ip_config(struct sigma_dut *dut,
1480 struct sigma_conn *conn,
1481 struct sigma_cmd *cmd)
1482{
1483 /* const char *intf = get_param(cmd, "Interface"); */
1484 const char *grpid = get_param(cmd, "GroupID");
1485 struct wfa_cs_p2p_group *grp = NULL;
1486 int count;
1487 char macaddr[20];
1488 char resp[200], info[150];
1489
1490 if (grpid == NULL)
1491 return -1;
1492
1493 if (strcmp(grpid, "$P2P_GROUP_ID") == 0)
1494 return -1;
1495
1496 /*
1497 * If we did not initiate the operation that created the group, we may
1498 * not have the group information available in the DUT code yet and it
1499 * may take some time to get this from wpa_supplicant in case we are
1500 * the P2P client. As such, we better try this multiple times to allow
1501 * some time to complete the operation.
1502 */
1503
1504 sigma_dut_print(dut, DUT_MSG_DEBUG, "Waiting to find the requested "
1505 "group");
1506 count = dut->default_timeout;
1507 while (count > 0) {
1508 grp = p2p_group_get(dut, grpid);
1509 if (grp == NULL) {
1510 sigma_dut_print(dut, DUT_MSG_DEBUG, "Requested group "
1511 "not yet found (count=%d)", count);
1512 sleep(1);
1513 } else
1514 break;
1515 count--;
1516 }
1517 if (grp == NULL) {
1518 send_resp(dut, conn, SIGMA_ERROR,
1519 "errorCode,Requested group not found");
1520 return 0;
1521 }
1522
1523 sigma_dut_print(dut, DUT_MSG_DEBUG, "Waiting for IP address on group "
1524 "interface %s", grp->ifname);
1525 if (wait_ip_addr(dut, grp->ifname, dut->default_timeout) < 0) {
1526 send_resp(dut, conn, SIGMA_ERROR,
1527 "errorCode,No IP address received");
1528 return 0;
1529 }
1530
1531 if (get_ip_config(dut, grp->ifname, info, sizeof(info)) < 0) {
1532 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get IP address "
1533 "for group interface %s",
1534 grp->ifname);
1535 send_resp(dut, conn, SIGMA_ERROR,
1536 "errorCode,Failed to get IP address");
1537 return 0;
1538 }
1539
1540 if (get_wpa_status(grp->ifname, "address",
1541 macaddr, sizeof(macaddr)) < 0) {
1542 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to get interface "
1543 "address for group interface %s",
1544 grp->ifname);
1545 return -2;
1546 }
1547
1548 sigma_dut_print(dut, DUT_MSG_DEBUG, "IP address for group interface "
1549 "%s found", grp->ifname);
1550
1551 snprintf(resp, sizeof(resp), "%s,P2PInterfaceAddress,%s",
1552 info, macaddr);
1553
1554 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1555 return 0;
1556}
1557
1558
1559static int cmd_sta_send_p2p_presence_req(struct sigma_dut *dut,
1560 struct sigma_conn *conn,
1561 struct sigma_cmd *cmd)
1562{
1563 const char *intf = get_param(cmd, "Interface");
1564 const char *dur = get_param(cmd, "Duration");
1565 const char *interv = get_param(cmd, "Interval");
1566 /* const char *grpid = get_param(cmd, "GroupID"); */
1567 const char *ifname;
1568 char buf[100];
1569
1570 if (dur == NULL || interv == NULL)
1571 return -1;
1572
1573 /* TODO: need to add groupid into parameters in CAPI spec; for now,
1574 * pick the first active group */
1575 ifname = get_group_ifname(dut, intf);
1576 snprintf(buf, sizeof(buf), "P2P_PRESENCE_REQ %s %s", dur, interv);
1577 if (wpa_command(ifname, buf) < 0)
1578 return -2;
1579
1580 return 1;
1581}
1582
1583
1584static int cmd_sta_set_sleep(struct sigma_dut *dut, struct sigma_conn *conn,
1585 struct sigma_cmd *cmd)
1586{
1587 /* const char *intf = get_param(cmd, "Interface"); */
1588 struct wfa_cs_p2p_group *grp;
1589 char *ifname;
1590 const char *grpid = get_param(cmd, "GroupID");
1591
1592 if (grpid == NULL)
1593 ifname = get_station_ifname();
1594 else {
1595 grp = p2p_group_get(dut, grpid);
1596 if (grp == NULL) {
1597 send_resp(dut, conn, SIGMA_ERROR,
1598 "errorCode,Requested group not found");
1599 return 0;
1600 }
1601 ifname = grp->ifname;
1602 }
1603
1604 if (dut->client_uapsd) {
1605#ifdef __linux__
1606 /* no special handling for nl80211 yet */
1607 char path[128];
1608 struct stat s;
1609 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211",
1610 ifname);
1611 if (stat(path, &s) == 0) {
1612 if (wpa_command(ifname, "P2P_SET ps 1") < 0) {
1613 send_resp(dut, conn, SIGMA_ERROR,
1614 "errorCode,Going to sleep not supported");
1615 return 0;
1616 }
1617 return 1;
1618 }
1619#endif /* __linux__ */
1620 if (wpa_command(ifname, "P2P_SET ps 99") < 0)
1621 return -2;
1622 } else {
1623 if (wpa_command(ifname, "P2P_SET ps 1") < 0) {
1624 send_resp(dut, conn, SIGMA_ERROR,
1625 "errorCode,Going to sleep not supported");
1626 return 0;
1627 }
1628 }
1629
1630 return 1;
1631}
1632
1633
1634static int cmd_sta_set_opportunistic_ps(struct sigma_dut *dut,
1635 struct sigma_conn *conn,
1636 struct sigma_cmd *cmd)
1637{
1638 /* const char *intf = get_param(cmd, "Interface"); */
1639 struct wfa_cs_p2p_group *grp;
1640 char buf[100];
1641 const char *grpid = get_param(cmd, "GroupID");
1642 const char *ctwindow = get_param(cmd, "CTWindow");
1643
1644 if (grpid == NULL || ctwindow == NULL)
1645 return -1;
1646
1647 grp = p2p_group_get(dut, grpid);
1648 if (grp == NULL) {
1649 send_resp(dut, conn, SIGMA_ERROR,
1650 "errorCode,Requested group not found");
1651 return 0;
1652 }
1653
1654 if (wpa_command(grp->ifname, "P2P_SET oppps 1") < 0) {
1655 send_resp(dut, conn, SIGMA_ERROR,
1656 "errorCode,Use of OppPS as GO not supported");
1657 return 0;
1658 }
1659 snprintf(buf, sizeof(buf), "P2P_SET ctwindow %d", atoi(ctwindow));
1660 if (wpa_command(grp->ifname, buf) < 0) {
1661 send_resp(dut, conn, SIGMA_ERROR,
1662 "errorCode,Use of CTWindow as GO not supported");
1663 return 0;
1664 }
1665
1666 return 1;
1667}
1668
1669
1670static int cmd_sta_send_service_discovery_req(struct sigma_dut *dut,
1671 struct sigma_conn *conn,
1672 struct sigma_cmd *cmd)
1673{
1674 const char *intf = get_param(cmd, "Interface");
1675 const char *devid = get_param(cmd, "P2PDevID");
1676 char buf[128];
1677
1678 if (devid == NULL)
1679 return -1;
1680
1681 snprintf(buf, sizeof(buf), "P2P_SERV_DISC_REQ %s 02000001",
1682 devid);
1683 if (wpa_command(intf, buf) < 0) {
1684 send_resp(dut, conn, SIGMA_ERROR, NULL);
1685 return 0;
1686 }
1687
1688 return 1;
1689}
1690
1691
1692static int cmd_sta_add_arp_table_entry(struct sigma_dut *dut,
1693 struct sigma_conn *conn,
1694 struct sigma_cmd *cmd)
1695{
1696 char buf[256];
1697 char *ifname;
1698 const char *grpid, *ipaddr, *macaddr;
1699
1700 grpid = get_param(cmd, "GroupID");
1701 ipaddr = get_param(cmd, "IPAddress");
1702 macaddr = get_param(cmd, "MACAddress");
1703 if (ipaddr == NULL || macaddr == NULL)
1704 return -1;
1705
1706 if (grpid == NULL)
1707 ifname = get_station_ifname();
1708 else {
1709 struct wfa_cs_p2p_group *grp;
1710 grp = p2p_group_get(dut, grpid);
1711 if (grp == NULL) {
1712 send_resp(dut, conn, SIGMA_ERROR,
1713 "errorCode,Requested group not found");
1714 return 0;
1715 }
1716 ifname = grp->ifname;
1717 }
1718
1719 snprintf(dut->arp_ipaddr, sizeof(dut->arp_ipaddr), "%s",
1720 ipaddr);
1721 snprintf(dut->arp_ifname, sizeof(dut->arp_ifname), "%s",
1722 ifname);
1723
1724 snprintf(buf, sizeof(buf), "ip nei add %s lladdr %s dev %s",
1725 ipaddr, macaddr, ifname);
1726 run_system(dut, buf);
1727
1728 return 1;
1729}
1730
1731
1732static int cmd_sta_block_icmp_response(struct sigma_dut *dut,
1733 struct sigma_conn *conn,
1734 struct sigma_cmd *cmd)
1735{
1736 char buf[256];
1737 struct wfa_cs_p2p_group *grp;
1738 char *ifname;
1739 const char *grpid, *ipaddr;
1740
1741 grpid = get_param(cmd, "GroupID");
1742 ipaddr = get_param(cmd, "IPAddress");
1743 if (ipaddr == NULL)
1744 return -1;
1745
1746 if (grpid == NULL)
1747 ifname = get_station_ifname();
1748 else {
1749 grp = p2p_group_get(dut, grpid);
1750 if (grp == NULL) {
1751 send_resp(dut, conn, SIGMA_ERROR,
1752 "errorCode,Requested group not found");
1753 return 0;
1754 }
1755 ifname = grp->ifname;
1756 }
1757
1758 snprintf(buf, sizeof(buf),
1759 "iptables -I INPUT -s %s -p icmp -i %s -j DROP",
1760 ipaddr, ifname);
1761 run_system(dut, buf);
1762
1763 return 1;
1764}
1765
1766
1767static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
1768 const char *info)
1769{
1770 int res;
1771
1772 sigma_dut_summary(dut, "NFC operation: %s", info);
1773 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
1774 printf("%s\n\n", info);
1775
1776 nfc_status(dut, "START", info);
1777 res = run_system(dut, cmd);
1778 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
1779 if (res) {
1780 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
1781 cmd, res);
1782 return res;
1783 }
1784
1785 return 0;
1786}
1787
1788
1789static int nfc_write_p2p_select(struct sigma_dut *dut, struct sigma_conn *conn,
1790 struct sigma_cmd *cmd)
1791{
1792 int res;
1793 const char *ifname = get_param(cmd, "Interface");
1794 char buf[300];
1795
1796 run_system(dut, "killall wps-nfc.py");
1797 run_system(dut, "killall p2p-nfc.py");
1798
1799 if (wpa_command(ifname, "WPS_NFC_TOKEN NDEF") < 0) {
1800 send_resp(dut, conn, SIGMA_ERROR,
1801 "ErrorCode,Failed to generate NFC password token");
1802 return 0;
1803 }
1804
1805 unlink("nfc-success");
1806 snprintf(buf, sizeof(buf),
1807 "./p2p-nfc.py -1 --no-wait %s%s --success nfc-success write-p2p-sel",
1808 dut->summary_log ? "--summary " : "",
1809 dut->summary_log ? dut->summary_log : "");
1810 res = run_nfc_command(dut, buf,
1811 "Touch NFC Tag to write P2P connection handover select");
1812 if (res || !file_exists("nfc-success")) {
1813 send_resp(dut, conn, SIGMA_ERROR,
1814 "ErrorCode,Failed to write tag");
1815 return 0;
1816 }
1817
1818 if (wpa_command(ifname, "P2P_SET nfc_tag 1") < 0) {
1819 send_resp(dut, conn, SIGMA_ERROR,
1820 "ErrorCode,Failed to enable NFC password token");
1821 return 0;
1822 }
1823
1824 if (!dut->go && wpa_command(ifname, "P2P_LISTEN") < 0) {
1825 send_resp(dut, conn, SIGMA_ERROR,
1826 "ErrorCode,Failed to start listen mode");
1827 return 0;
1828 }
1829
1830 send_resp(dut, conn, SIGMA_COMPLETE,
1831 "Result,,GroupID,,PeerRole,,PauseFlag,0");
1832 return 0;
1833}
1834
1835
1836static int nfc_write_config_token(struct sigma_dut *dut,
1837 struct sigma_conn *conn,
1838 struct sigma_cmd *cmd)
1839{
1840 int res;
1841 const char *bssid = get_param(cmd, "Bssid");
1842 const char *intf = get_param(cmd, "Interface");
1843 char buf[200];
1844
1845 run_system(dut, "killall wps-nfc.py");
1846 run_system(dut, "killall p2p-nfc.py");
1847 unlink("nfc-success");
1848 if (dut->er_oper_performed && bssid) {
1849 char current_bssid[30], id[10];
1850 if (get_wpa_status(intf, "id", id, sizeof(id)) < 0 ||
1851 get_wpa_status(intf, "bssid", current_bssid,
1852 sizeof(current_bssid)) < 0 ||
1853 strncasecmp(bssid, current_bssid, strlen(current_bssid)) !=
1854 0) {
1855 send_resp(dut, conn, SIGMA_ERROR,
1856 "ErrorCode,No configuration known for BSSID");
1857 return 0;
1858 }
1859 snprintf(buf, sizeof(buf),
1860 "./wps-nfc.py --id %s --no-wait %s%s --success nfc-success write-config",
1861 id,
1862 dut->summary_log ? "--summary " : "",
1863 dut->summary_log ? dut->summary_log : "");
1864 res = run_nfc_command(dut, buf,
1865 "Touch NFC Tag to write WPS configuration token");
1866 } else {
1867 snprintf(buf, sizeof(buf),
1868 "./wps-nfc.py --no-wait %s%s --success nfc-success write-config",
1869 dut->summary_log ? "--summary " : "",
1870 dut->summary_log ? dut->summary_log : "");
1871 res = run_nfc_command(dut, buf,
1872 "Touch NFC Tag to write WPS configuration token");
1873 }
1874 if (res || !file_exists("nfc-success")) {
1875 send_resp(dut, conn, SIGMA_ERROR,
1876 "ErrorCode,Failed to write tag");
1877 return 0;
1878 }
1879
1880 send_resp(dut, conn, SIGMA_COMPLETE,
1881 "Result,,GroupID,,PeerRole,,PauseFlag,0");
1882 return 0;
1883}
1884
1885
1886static int nfc_write_password_token(struct sigma_dut *dut,
1887 struct sigma_conn *conn,
1888 struct sigma_cmd *cmd)
1889{
1890 int res;
1891 char buf[300];
1892
1893 run_system(dut, "killall wps-nfc.py");
1894 run_system(dut, "killall p2p-nfc.py");
1895 unlink("nfc-success");
1896 snprintf(buf, sizeof(buf),
1897 "./wps-nfc.py --no-wait %s%s --success nfc-success write-password",
1898 dut->summary_log ? "--summary " : "",
1899 dut->summary_log ? dut->summary_log : "");
1900 res = run_nfc_command(dut, buf,
1901 "Touch NFC Tag to write WPS password token");
1902 if (res || !file_exists("nfc-success")) {
1903 send_resp(dut, conn, SIGMA_ERROR,
1904 "ErrorCode,Failed to write tag");
1905 return 0;
1906 }
1907
1908 send_resp(dut, conn, SIGMA_COMPLETE,
1909 "Result,,GroupID,,PeerRole,,PauseFlag,0");
1910 return 0;
1911}
1912
1913
1914static int nfc_read_tag(struct sigma_dut *dut,
1915 struct sigma_conn *conn,
1916 struct sigma_cmd *cmd)
1917{
1918 int res;
1919 struct wpa_ctrl *ctrl;
1920 const char *intf = get_param(cmd, "Interface");
1921 const char *oper_chn = get_param(cmd, "OPER_CHN");
1922 char buf[1000], freq_str[20];
1923
1924 run_system(dut, "killall wps-nfc.py");
1925 run_system(dut, "killall p2p-nfc.py");
1926
1927 ctrl = open_wpa_mon(intf);
1928 if (ctrl == NULL) {
1929 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
1930 "wpa_supplicant monitor connection");
1931 return -2;
1932 }
1933
1934 freq_str[0] = '\0';
1935 if (oper_chn) {
1936 int chan = atoi(oper_chn);
1937 if (chan >= 1 && chan <= 11)
1938 snprintf(freq_str, sizeof(freq_str), " --freq %d",
1939 2407 + chan * 5);
1940 }
1941
1942 unlink("nfc-success");
1943 snprintf(buf, sizeof(buf),
1944 "./p2p-nfc.py -1 -t %s%s --success nfc-success --no-wait%s",
1945 dut->summary_log ? "--summary " : "",
1946 dut->summary_log ? dut->summary_log : "",
1947 freq_str);
1948 res = run_nfc_command(dut, buf,
1949 "Touch NFC Tag to read it");
1950 if (res || !file_exists("nfc-success")) {
1951 send_resp(dut, conn, SIGMA_ERROR,
1952 "ErrorCode,Failed to read tag");
1953 wpa_ctrl_detach(ctrl);
1954 wpa_ctrl_close(ctrl);
1955 return 0;
1956 }
1957
1958 if (dut->p2p_mode == P2P_DISABLE)
1959 return wps_connection_event(dut, conn, ctrl, intf, 1);
1960
1961 if (dut->go || dut->p2p_client) {
1962 wpa_ctrl_detach(ctrl);
1963 wpa_ctrl_close(ctrl);
1964 send_resp(dut, conn, SIGMA_COMPLETE,
1965 "Result,,GroupID,,PeerRole,,PauseFlag,0");
1966 return 0;
1967 }
1968
1969 /* FIX: PeerRole */
1970 return p2p_group_formation_event(dut, conn, ctrl, intf, "0", 1);
1971}
1972
1973
1974static int nfc_wps_read_tag(struct sigma_dut *dut,
1975 struct sigma_conn *conn,
1976 struct sigma_cmd *cmd)
1977{
1978 int res;
1979 struct wpa_ctrl *ctrl;
1980 const char *intf = get_param(cmd, "Interface");
1981 char buf[300];
1982
1983 run_system(dut, "killall wps-nfc.py");
1984 run_system(dut, "killall p2p-nfc.py");
1985
1986 ctrl = open_wpa_mon(intf);
1987 if (ctrl == NULL) {
1988 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
1989 "wpa_supplicant monitor connection");
1990 return -2;
1991 }
1992
1993 unlink("nfc-success");
1994 snprintf(buf, sizeof(buf),
1995 "./wps-nfc.py -1 --no-wait %s%s --success nfc-success",
1996 dut->summary_log ? "--summary " : "",
1997 dut->summary_log ? dut->summary_log : "");
1998 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
1999 if (res || !file_exists("nfc-success")) {
2000 send_resp(dut, conn, SIGMA_ERROR,
2001 "ErrorCode,Failed to read tag");
2002 wpa_ctrl_detach(ctrl);
2003 wpa_ctrl_close(ctrl);
2004 return 0;
2005 }
2006
2007 return wps_connection_event(dut, conn, ctrl, intf, 1);
2008}
2009
2010
2011static int er_ap_add_match(const char *event, const char *bssid,
2012 const char *req_uuid,
2013 char *ret_uuid, size_t max_uuid_len)
2014{
2015 const char *pos, *uuid;
2016
2017 pos = strchr(event, ' ');
2018 if (pos == NULL)
2019 return 0;
2020 pos++;
2021 uuid = pos;
2022
2023 pos = strchr(pos, ' ');
2024 if (pos == NULL)
2025 return 0;
2026 if (ret_uuid) {
2027 if ((size_t) (pos - uuid + 1) < max_uuid_len) {
2028 memcpy(ret_uuid, uuid, pos - uuid);
2029 ret_uuid[pos - uuid] = '\0';
2030 } else
2031 ret_uuid[0] = '\0';
2032 }
2033
2034 if (req_uuid && strncasecmp(req_uuid, uuid, pos - uuid) == 0)
2035 return 1;
2036
2037 pos++;
2038 /* at BSSID */
2039
2040 return strncasecmp(pos, bssid, strlen(bssid)) == 0;
2041}
2042
2043
2044static int er_start(struct sigma_dut *dut, struct sigma_conn *conn,
2045 struct wpa_ctrl *ctrl, const char *intf, const char *bssid,
2046 const char *uuid, char *ret_uuid, size_t max_uuid_len)
2047{
2048 char id[10];
2049 int res;
2050 char buf[1000];
2051
2052 sigma_dut_print(dut, DUT_MSG_INFO, "Trying to find WPS AP %s over UPnP",
2053 bssid);
2054
2055 if (wpa_command(intf, "WPS_ER_START") < 0) {
2056 send_resp(dut, conn, SIGMA_ERROR,
2057 "ErrorCode,Failed to start ER");
2058 return 0;
2059 }
2060
2061 for (;;) {
2062 res = get_wpa_cli_event(dut, ctrl, "WPS-ER-AP-ADD",
2063 buf, sizeof(buf));
2064 if (res < 0) {
2065#ifdef USE_ERROR_RETURNS
2066 send_resp(dut, conn, SIGMA_ERROR,
2067 "ErrorCode,Could not find the AP over UPnP");
2068#else
2069 send_resp(dut, conn, SIGMA_COMPLETE,
2070 "ErrorCode,Could not find the AP over UPnP");
2071#endif
2072 return 0;
2073 }
2074
2075 if (er_ap_add_match(buf, bssid, uuid, ret_uuid, max_uuid_len)) {
2076 sigma_dut_print(dut, DUT_MSG_INFO,
2077 "Found WPS AP over UPnP: %s", buf);
2078 break;
2079 }
2080 }
2081
2082 if (get_wpa_status(intf, "id", id, sizeof(id)) < 0) {
2083 send_resp(dut, conn, SIGMA_ERROR,
2084 "ErrorCode,Could not find AP configuration");
2085 return 0;
2086 }
2087
2088 if (ret_uuid) {
2089 snprintf(buf, sizeof(buf), "WPS_ER_SET_CONFIG %s %s",
2090 ret_uuid, id);
2091 } else if (uuid) {
2092 snprintf(buf, sizeof(buf), "WPS_ER_SET_CONFIG %s %s",
2093 uuid, id);
2094 } else {
2095 snprintf(buf, sizeof(buf), "WPS_ER_SET_CONFIG %s %s",
2096 bssid, id);
2097 }
2098 if (wpa_command(intf, buf) < 0) {
2099 send_resp(dut, conn, SIGMA_ERROR,
2100 "ErrorCode,Failed to select network configuration for ER");
2101 return 0;
2102 }
2103
2104 return 1;
2105}
2106
2107
2108static int nfc_wps_read_passwd(struct sigma_dut *dut,
2109 struct sigma_conn *conn,
2110 struct sigma_cmd *cmd)
2111{
2112 int res;
2113 struct wpa_ctrl *ctrl;
2114 const char *intf = get_param(cmd, "Interface");
2115 const char *bssid = get_param(cmd, "Bssid");
2116 const char *ssid = get_param(cmd, "SSID");
2117 const char *security = get_param(cmd, "Security");
2118 const char *passphrase = get_param(cmd, "Passphrase");
2119 char ssid_hex[200], passphrase_hex[200];
2120 const char *val;
2121 int sta_action;
2122 char buf[1000];
2123 const char *keymgmt, *cipher;
2124
2125 run_system(dut, "killall wps-nfc.py");
2126 run_system(dut, "killall p2p-nfc.py");
2127
2128 if ((ssid && strlen(ssid) >= 2 * sizeof(ssid_hex)) ||
2129 (passphrase && strlen(passphrase) >= 2 * sizeof(passphrase_hex))) {
2130 send_resp(dut, conn, SIGMA_ERROR,
2131 "ErrorCode,Too long SSID/passphrase");
2132 return 0;
2133 }
2134
2135 val = get_param(cmd, "WpsStaAction");
2136 if (!val) {
2137 send_resp(dut, conn, SIGMA_ERROR,
2138 "ErrorCode,Missing WpsStaAction argument");
2139 return 0;
2140 }
2141
2142 sta_action = atoi(val);
2143 if (sta_action != 1 && sta_action != 2) {
2144 send_resp(dut, conn, SIGMA_ERROR,
2145 "ErrorCode,Unsupported WpsStaAction value");
2146 return 0;
2147 }
2148
2149 if (!bssid) {
2150 send_resp(dut, conn, SIGMA_ERROR,
2151 "ErrorCode,Missing Bssid argument");
2152 return 0;
2153 }
2154
2155 if (sta_action == 2) {
2156 if (!ssid) {
2157 send_resp(dut, conn, SIGMA_ERROR,
2158 "ErrorCode,Missing SSID argument");
2159 return 0;
2160 }
2161
2162 if (!security) {
2163 send_resp(dut, conn, SIGMA_ERROR,
2164 "ErrorCode,Missing Security argument");
2165 return 0;
2166 }
2167
2168 if (!passphrase) {
2169 send_resp(dut, conn, SIGMA_ERROR,
2170 "ErrorCode,Missing Passphrase argument");
2171 return 0;
2172 }
2173 }
2174
2175 ctrl = open_wpa_mon(intf);
2176 if (ctrl == NULL) {
2177 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
2178 "wpa_supplicant monitor connection");
2179 return -2;
2180 }
2181
2182 if (sta_action == 1) {
2183 const char *uuid = get_param(cmd, "UUID");
2184 res = er_start(dut, conn, ctrl, intf, bssid, uuid, NULL, 0);
2185 if (res != 1) {
2186 wpa_ctrl_detach(ctrl);
2187 wpa_ctrl_close(ctrl);
2188 return res;
2189 }
2190 }
2191
2192 unlink("nfc-success");
2193 snprintf(buf, sizeof(buf),
2194 "./wps-nfc.py -1 --no-wait %s%s --success nfc-success",
2195 dut->summary_log ? "--summary " : "",
2196 dut->summary_log ? dut->summary_log : "");
2197 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
2198 if (res || !file_exists("nfc-success")) {
2199 wpa_ctrl_detach(ctrl);
2200 wpa_ctrl_close(ctrl);
2201 send_resp(dut, conn, SIGMA_ERROR,
2202 "ErrorCode,Failed to read tag");
2203 return 0;
2204 }
2205
2206 if (sta_action == 1) {
2207 sigma_dut_print(dut, DUT_MSG_INFO, "Prepared device password for ER to enroll a new station");
2208 wpa_ctrl_detach(ctrl);
2209 wpa_ctrl_close(ctrl);
2210 send_resp(dut, conn, SIGMA_COMPLETE,
2211 "Result,,GroupID,,PeerRole,");
2212 return 0;
2213 }
2214 if (strcasecmp(security, "wpa2-psk") == 0) {
2215 keymgmt = "WPA2PSK";
2216 cipher = "CCMP";
2217 } else {
2218 wpa_ctrl_detach(ctrl);
2219 wpa_ctrl_close(ctrl);
2220 send_resp(dut, conn, SIGMA_ERROR,
2221 "ErrorCode,Unsupported Security value");
2222 return 0;
2223 }
2224
2225 ascii2hexstr(ssid, ssid_hex);
2226 ascii2hexstr(passphrase, passphrase_hex);
2227 snprintf(buf, sizeof(buf), "WPS_REG %s nfc-pw %s %s %s %s",
2228 bssid, ssid_hex, keymgmt, cipher, passphrase_hex);
2229
2230 if (wpa_command(intf, buf) < 0) {
2231 wpa_ctrl_detach(ctrl);
2232 wpa_ctrl_close(ctrl);
2233 send_resp(dut, conn, SIGMA_ERROR,
2234 "ErrorCode,Failed to start registrar");
2235 return 0;
2236 }
2237
2238 return wps_connection_event(dut, conn, ctrl, intf, 1);
2239}
2240
2241
2242static int nfc_wps_read_config(struct sigma_dut *dut,
2243 struct sigma_conn *conn,
2244 struct sigma_cmd *cmd)
2245{
2246 int res;
2247 struct wpa_ctrl *ctrl;
2248 const char *intf = get_param(cmd, "Interface");
2249 char buf[300];
2250
2251 run_system(dut, "killall wps-nfc.py");
2252 run_system(dut, "killall p2p-nfc.py");
2253
2254 ctrl = open_wpa_mon(intf);
2255 if (ctrl == NULL) {
2256 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
2257 "wpa_supplicant monitor connection");
2258 return -2;
2259 }
2260
2261 unlink("nfc-success");
2262 snprintf(buf, sizeof(buf),
2263 "./wps-nfc.py -1 --no-wait %s%s --success nfc-success",
2264 dut->summary_log ? "--summary " : "",
2265 dut->summary_log ? dut->summary_log : "");
2266 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
2267 if (res || !file_exists("nfc-success")) {
2268 send_resp(dut, conn, SIGMA_ERROR,
2269 "ErrorCode,Failed to read tag");
2270 wpa_ctrl_detach(ctrl);
2271 wpa_ctrl_close(ctrl);
2272 return 0;
2273 }
2274
2275 return wps_connection_event(dut, conn, ctrl, intf, 1);
2276}
2277
2278
2279static int nfc_wps_connection_handover(struct sigma_dut *dut,
2280 struct sigma_conn *conn,
2281 struct sigma_cmd *cmd)
2282{
2283 const char *intf = get_param(cmd, "Interface");
2284 int res;
2285 const char *init = get_param(cmd, "Init");
2286 struct wpa_ctrl *ctrl = NULL;
2287 char buf[300];
2288
2289 run_system(dut, "killall wps-nfc.py");
2290 run_system(dut, "killall p2p-nfc.py");
2291
2292 ctrl = open_wpa_mon(intf);
2293 if (ctrl == NULL) {
2294 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
2295 "wpa_supplicant monitor connection");
2296 return -2;
2297 }
2298
2299 unlink("nfc-success");
2300 if ((!init || atoi(init) == 0) && dut->er_oper_performed) {
2301 const char *bssid = get_param(cmd, "Bssid");
2302 const char *req_uuid = get_param(cmd, "UUID");
2303 char uuid[100];
2304
2305 if (bssid == NULL)
2306 bssid = dut->er_oper_bssid;
2307
2308 res = er_start(dut, conn, ctrl, intf, bssid, req_uuid, uuid,
2309 sizeof(uuid));
2310 if (res != 1) {
2311 wpa_ctrl_detach(ctrl);
2312 wpa_ctrl_close(ctrl);
2313 return res;
2314 }
2315
2316 snprintf(buf, sizeof(buf),
2317 "./wps-nfc.py -1 --uuid %s %s%s --success nfc-success",
2318 uuid,
2319 dut->summary_log ? "--summary " : "",
2320 dut->summary_log ? dut->summary_log : "");
2321 res = run_nfc_command(dut, buf,
2322 "Touch NFC Device to respond to WPS connection handover");
2323 } else if (!init || atoi(init)) {
2324 snprintf(buf, sizeof(buf),
2325 "./wps-nfc.py -1 --no-wait %s%s --success nfc-success",
2326 dut->summary_log ? "--summary " : "",
2327 dut->summary_log ? dut->summary_log : "");
2328 res = run_nfc_command(dut, buf,
2329 "Touch NFC Device to initiate WPS connection handover");
2330 } else {
2331 snprintf(buf, sizeof(buf),
2332 "./p2p-nfc.py -1 --no-wait --no-input %s%s --success nfc-success --handover-only",
2333 dut->summary_log ? "--summary " : "",
2334 dut->summary_log ? dut->summary_log : "");
2335 res = run_nfc_command(dut, buf,
2336 "Touch NFC Device to respond to WPS connection handover");
2337 }
2338 if (res) {
2339 wpa_ctrl_detach(ctrl);
2340 wpa_ctrl_close(ctrl);
2341 send_resp(dut, conn, SIGMA_ERROR,
2342 "ErrorCode,Failed to enable NFC for connection "
2343 "handover");
2344 return 0;
2345 }
2346 if (!file_exists("nfc-success")) {
2347 wpa_ctrl_detach(ctrl);
2348 wpa_ctrl_close(ctrl);
2349 send_resp(dut, conn, SIGMA_ERROR,
2350 "ErrorCode,Failed to complete NFC connection handover");
2351 return 0;
2352 }
2353
2354 if (init && atoi(init))
2355 return wps_connection_event(dut, conn, ctrl, intf, 1);
2356
2357 wpa_ctrl_detach(ctrl);
2358 wpa_ctrl_close(ctrl);
2359
2360 send_resp(dut, conn, SIGMA_COMPLETE,
2361 "Result,,GroupID,,PeerRole,,PauseFlag,0");
2362 return 0;
2363}
2364
2365
2366static int nfc_p2p_connection_handover(struct sigma_dut *dut,
2367 struct sigma_conn *conn,
2368 struct sigma_cmd *cmd)
2369{
2370 const char *intf = get_param(cmd, "Interface");
2371 int res;
2372 const char *init = get_param(cmd, "Init");
2373 const char *oper_chn = get_param(cmd, "OPER_CHN");
2374 struct wpa_ctrl *ctrl;
2375 char buf[1000], freq_str[20];
2376
2377 run_system(dut, "killall wps-nfc.py");
2378 run_system(dut, "killall p2p-nfc.py");
2379
2380 ctrl = open_wpa_mon(intf);
2381 if (ctrl == NULL) {
2382 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
2383 "wpa_supplicant monitor connection");
2384 return -2;
2385 }
2386
2387 freq_str[0] = '\0';
2388 if (oper_chn) {
2389 int chan = atoi(oper_chn);
2390 if (chan >= 1 && chan <= 11)
2391 snprintf(freq_str, sizeof(freq_str), " --freq %d",
2392 2407 + chan * 5);
2393 }
2394
2395 unlink("nfc-success");
2396 if (init && atoi(init)) {
2397 snprintf(buf, sizeof(buf),
2398 "./p2p-nfc.py -1 -I -N --no-wait %s%s --success nfc-success --no-input%s --handover-only",
2399 dut->summary_log ? "--summary " : "",
2400 dut->summary_log ? dut->summary_log : "",
2401 freq_str);
2402 res = run_nfc_command(dut, buf,
2403 "Touch NFC Device to initiate P2P connection handover");
2404 } else {
2405 snprintf(buf, sizeof(buf),
2406 "./p2p-nfc.py -1 --no-wait %s%s --success nfc-success --no-input%s --handover-only",
2407 dut->summary_log ? "--summary " : "",
2408 dut->summary_log ? dut->summary_log : "",
2409 freq_str);
2410 res = run_nfc_command(dut, buf,
2411 "Touch NFC Device to respond to P2P connection handover");
2412 }
2413 if (res) {
2414 wpa_ctrl_detach(ctrl);
2415 wpa_ctrl_close(ctrl);
2416 send_resp(dut, conn, SIGMA_ERROR,
2417 "ErrorCode,Failed to enable NFC for connection "
2418 "handover");
2419 return 0;
2420 }
2421 if (!file_exists("nfc-success")) {
2422 wpa_ctrl_detach(ctrl);
2423 wpa_ctrl_close(ctrl);
2424 send_resp(dut, conn, SIGMA_ERROR,
2425 "ErrorCode,Failed to complete NFC connection handover");
2426 return 0;
2427 }
2428
2429 if (dut->go || dut->p2p_client) {
2430 wpa_ctrl_detach(ctrl);
2431 wpa_ctrl_close(ctrl);
2432 send_resp(dut, conn, SIGMA_COMPLETE,
2433 "Result,,GroupID,,PeerRole,,PauseFlag,0");
2434 return 0;
2435 }
2436
2437 /* FIX: peer role from handover message */
2438 return p2p_group_formation_event(dut, conn, ctrl, intf, "0", 1);
2439}
2440
2441
2442static int cmd_sta_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
2443 struct sigma_cmd *cmd)
2444{
2445 const char *intf = get_param(cmd, "Interface");
2446 const char *oper = get_param(cmd, "Operation");
2447 const char *ssid_param = get_param(cmd, "SSID");
2448 const char *intent_val = get_param(cmd, "INTENT_VAL");
2449 const char *oper_chn = get_param(cmd, "OPER_CHN");
2450 char buf[256];
2451
2452 if (oper == NULL)
2453 return -1;
2454
2455 if (ssid_param)
2456 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix %s",
2457 ssid_param);
2458 else
2459 snprintf(buf, sizeof(buf), "P2P_SET ssid_postfix ");
2460 if (wpa_command(intf, buf) < 0)
2461 sigma_dut_print(dut, DUT_MSG_INFO, "Failed P2P ssid_postfix - ignore and assume this is for non-P2P case");
2462
2463 if (intent_val) {
2464 snprintf(buf, sizeof(buf), "SET p2p_go_intent %s", intent_val);
2465 if (wpa_command(intf, buf) < 0)
2466 return -2;
2467 }
2468
2469 if (oper_chn) {
2470 int chan = atoi(oper_chn);
2471 if (chan < 1 || chan > 11) {
2472 send_resp(dut, conn, SIGMA_ERROR,
2473 "ErrorCode,Unsupported operating channel");
2474 return 0;
2475 }
2476 snprintf(buf, sizeof(buf), "SET p2p_oper_channel %d", chan);
2477 if (wpa_command(intf, "SET p2p_oper_reg_class 81") < 0 ||
2478 wpa_command(intf, buf) < 0) {
2479 send_resp(dut, conn, SIGMA_ERROR,
2480 "ErrorCode,Failed to set operating channel");
2481 return 0;
2482 }
2483 }
2484
2485 if (strcasecmp(oper, "WRITE_SELECT") == 0)
2486 return nfc_write_p2p_select(dut, conn, cmd);
2487 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
2488 return nfc_write_config_token(dut, conn, cmd);
2489 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
2490 return nfc_write_password_token(dut, conn, cmd);
2491 if (strcasecmp(oper, "READ_TAG") == 0)
2492 return nfc_read_tag(dut, conn, cmd);
2493 if (strcasecmp(oper, "WPS_READ_TAG") == 0)
2494 return nfc_wps_read_tag(dut, conn, cmd);
2495 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
2496 return nfc_wps_read_passwd(dut, conn, cmd);
2497 if (strcasecmp(oper, "WPS_READ_CONFIG") == 0)
2498 return nfc_wps_read_config(dut, conn, cmd);
2499 if (strcasecmp(oper, "CONN_HNDOVR") == 0)
2500 return nfc_p2p_connection_handover(dut, conn, cmd);
2501 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
2502 return nfc_wps_connection_handover(dut, conn, cmd);
2503
2504 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
2505 return 0;
2506}
2507
2508
2509int p2p_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
2510 struct sigma_cmd *cmd)
2511{
2512 const char *parameter = get_param(cmd, "Parameter");
2513 char buf[100];
2514
2515 if (parameter == NULL)
2516 return -1;
2517 if (strcasecmp(parameter, "ListenChannel") == 0) {
2518 snprintf(buf, sizeof(buf), "ListenChnl,%u", dut->listen_chn);
2519 send_resp(dut, conn, SIGMA_COMPLETE, buf);
2520 return 0;
2521 }
2522
2523 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
2524 return 0;
2525}
2526
2527
2528static int req_intf(struct sigma_cmd *cmd)
2529{
2530 return get_param(cmd, "interface") == NULL ? -1 : 0;
2531}
2532
2533
2534void p2p_register_cmds(void)
2535{
2536 sigma_dut_reg_cmd("sta_get_p2p_dev_address", req_intf,
2537 cmd_sta_get_p2p_dev_address);
2538 sigma_dut_reg_cmd("sta_set_p2p", req_intf, cmd_sta_set_p2p);
2539 sigma_dut_reg_cmd("sta_start_autonomous_go", req_intf,
2540 cmd_sta_start_autonomous_go);
2541 sigma_dut_reg_cmd("sta_p2p_connect", req_intf, cmd_sta_p2p_connect);
2542 sigma_dut_reg_cmd("sta_p2p_start_group_formation", req_intf,
2543 cmd_sta_p2p_start_group_formation);
2544 sigma_dut_reg_cmd("sta_p2p_dissolve", req_intf, cmd_sta_p2p_dissolve);
2545 sigma_dut_reg_cmd("sta_send_p2p_invitation_req", req_intf,
2546 cmd_sta_send_p2p_invitation_req);
2547 sigma_dut_reg_cmd("sta_accept_p2p_invitation_req", req_intf,
2548 cmd_sta_accept_p2p_invitation_req);
2549 sigma_dut_reg_cmd("sta_send_p2p_provision_dis_req", req_intf,
2550 cmd_sta_send_p2p_provision_dis_req);
2551 sigma_dut_reg_cmd("sta_set_wps_pbc", req_intf, cmd_sta_set_wps_pbc);
2552 sigma_dut_reg_cmd("sta_wps_read_pin", req_intf, cmd_sta_wps_read_pin);
2553 sigma_dut_reg_cmd("sta_wps_read_label", req_intf,
2554 cmd_sta_wps_read_label);
2555 sigma_dut_reg_cmd("sta_wps_enter_pin", req_intf,
2556 cmd_sta_wps_enter_pin);
2557 sigma_dut_reg_cmd("sta_get_psk", req_intf, cmd_sta_get_psk);
2558 sigma_dut_reg_cmd("sta_p2p_reset", req_intf, cmd_sta_p2p_reset);
2559 sigma_dut_reg_cmd("sta_get_p2p_ip_config", req_intf,
2560 cmd_sta_get_p2p_ip_config);
2561 sigma_dut_reg_cmd("sta_send_p2p_presence_req", req_intf,
2562 cmd_sta_send_p2p_presence_req);
2563 sigma_dut_reg_cmd("sta_set_sleep", req_intf, cmd_sta_set_sleep);
2564 sigma_dut_reg_cmd("sta_set_opportunistic_ps", req_intf,
2565 cmd_sta_set_opportunistic_ps);
2566 sigma_dut_reg_cmd("sta_send_service_discovery_req", req_intf,
2567 cmd_sta_send_service_discovery_req);
2568 sigma_dut_reg_cmd("sta_add_arp_table_entry", req_intf,
2569 cmd_sta_add_arp_table_entry);
2570 sigma_dut_reg_cmd("sta_block_icmp_response", req_intf,
2571 cmd_sta_block_icmp_response);
2572 sigma_dut_reg_cmd("sta_nfc_action", req_intf, cmd_sta_nfc_action);
2573}