blob: 28d386a36010557260e6086b3455d59517cae15c [file] [log] [blame]
Jouni Malinend86e5822017-08-29 03:55:32 +03001/*
2 * Sigma Control API DUT (station/AP/sniffer)
3 * Copyright (c) 2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02004 * Copyright (c) 2018, The Linux Foundation
Jouni Malinend86e5822017-08-29 03:55:32 +03005 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
Jouni Malinen1a38cc32018-01-05 20:59:00 +020010#include <sys/wait.h>
Jouni Malinend86e5822017-08-29 03:55:32 +030011#include "wpa_ctrl.h"
12#include "wpa_helpers.h"
13
Jouni Malinen1a38cc32018-01-05 20:59:00 +020014#ifdef ANDROID
Srinivas Dasaribc9e0552018-01-04 19:24:28 +053015char *dpp_qrcode_file = "/sdcard/wpadebug_qrdata.txt";
Jouni Malinen1a38cc32018-01-05 20:59:00 +020016#endif /* ANDROID */
Srinivas Dasaribc9e0552018-01-04 19:24:28 +053017
Jouni Malinend86e5822017-08-29 03:55:32 +030018
19static int sigma_dut_is_ap(struct sigma_dut *dut)
20{
21 return dut->device_type == AP_unknown ||
22 dut->device_type == AP_testbed ||
23 dut->device_type == AP_dut;
24}
25
26
27static int dpp_hostapd_run(struct sigma_dut *dut)
28{
29 if (dut->hostapd_running)
30 return 0;
31
32 sigma_dut_print(dut, DUT_MSG_INFO,
33 "Starting hostapd in unconfigured state for DPP");
34 snprintf(dut->ap_ssid, sizeof(dut->ap_ssid), "unconfigured");
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080035 if (!dut->ap_oper_chn)
36 dut->ap_channel = 11;
Jouni Malinend86e5822017-08-29 03:55:32 +030037 dut->ap_is_dual = 0;
priyadharshini gowthamanfa2d7c32018-02-20 13:30:13 -080038 dut->ap_mode = dut->ap_channel <= 14 ? AP_11ng : AP_11na;
Jouni Malinend86e5822017-08-29 03:55:32 +030039 dut->ap_key_mgmt = AP_OPEN;
40 dut->ap_cipher = AP_PLAIN;
41 return cmd_ap_config_commit(dut, NULL, NULL) == 1 ? 0 : -1;
42}
43
44
45static const char * dpp_get_curve(struct sigma_cmd *cmd, const char *arg)
46{
47 const char *val = get_param(cmd, arg);
48
49 if (!val)
50 val = "P-256";
51 else if (strcasecmp(val, "BP-256R1") == 0)
52 val = "BP-256";
53 else if (strcasecmp(val, "BP-384R1") == 0)
54 val = "BP-384";
55 else if (strcasecmp(val, "BP-512R1") == 0)
56 val = "BP-512";
57
58 return val;
59}
60
61
62static int dpp_get_local_bootstrap(struct sigma_dut *dut,
63 struct sigma_conn *conn,
Srinivas Dasaribc9e0552018-01-04 19:24:28 +053064 struct sigma_cmd *cmd, int send_result,
65 int *success)
Jouni Malinend86e5822017-08-29 03:55:32 +030066{
67 const char *curve = dpp_get_curve(cmd, "DPPCryptoIdentifier");
68 const char *bs = get_param(cmd, "DPPBS");
Jouni Malinen4161c3f2017-11-13 18:36:09 +020069 const char *chan_list = get_param(cmd, "DPPChannelList");
70 char *pos, mac[50], buf[200], resp[1000], hex[2000];
Jouni Malinend86e5822017-08-29 03:55:32 +030071 const char *ifname = get_station_ifname();
72
Srinivas Dasaribc9e0552018-01-04 19:24:28 +053073 if (success)
74 *success = 0;
Jouni Malinend86e5822017-08-29 03:55:32 +030075 if (strcasecmp(bs, "QR") != 0) {
76 send_resp(dut, conn, SIGMA_ERROR,
77 "errorCode,Unsupported DPPBS");
78 return 0;
79 }
80
81 if (sigma_dut_is_ap(dut)) {
82 u8 bssid[ETH_ALEN];
83
84 if (!dut->hostapd_ifname) {
85 sigma_dut_print(dut, DUT_MSG_ERROR,
86 "hostapd ifname not specified (-j)");
87 return -2;
88 }
89 ifname = dut->hostapd_ifname;
90 if (get_hwaddr(dut->hostapd_ifname, bssid) < 0) {
91 sigma_dut_print(dut, DUT_MSG_ERROR,
92 "Could not get MAC address for %s",
93 dut->hostapd_ifname);
94 return -2;
95 }
96 snprintf(mac, sizeof(mac), "%02x%02x%02x%02x%02x%02x",
97 bssid[0], bssid[1], bssid[2],
98 bssid[3], bssid[4], bssid[5]);
99 } else {
100 if (get_wpa_status(ifname, "address", mac, sizeof(mac)) < 0)
101 return -2;
102 }
103
104 pos = mac;
105 while (*pos) {
106 if (*pos == ':')
107 memmove(pos, pos + 1, strlen(pos));
108 else
109 pos++;
110 }
111
Jouni Malinend86e5822017-08-29 03:55:32 +0300112 if (sigma_dut_is_ap(dut) && dpp_hostapd_run(dut) < 0) {
113 send_resp(dut, conn, SIGMA_ERROR,
114 "errorCode,Failed to start hostapd");
115 return 0;
116 }
117
Jouni Malinen4161c3f2017-11-13 18:36:09 +0200118 if (chan_list &&
119 (strcmp(chan_list, "0/0") == 0 || chan_list[0] == '\0')) {
120 /* No channel list */
121 snprintf(buf, sizeof(buf),
122 "DPP_BOOTSTRAP_GEN type=qrcode curve=%s mac=%s",
123 curve, mac);
124 } else if (chan_list) {
125 /* Channel list override (CTT case) - space separated tuple(s)
126 * of OperatingClass/Channel; convert to wpa_supplicant/hostapd
127 * format: comma separated tuples */
128 strlcpy(resp, chan_list, sizeof(resp));
129 for (pos = resp; *pos; pos++) {
130 if (*pos == ' ')
131 *pos = ',';
132 }
133 snprintf(buf, sizeof(buf),
134 "DPP_BOOTSTRAP_GEN type=qrcode curve=%s chan=%s mac=%s",
135 curve, resp, mac);
136 } else {
137 /* Default channel list (normal DUT case) */
138 snprintf(buf, sizeof(buf),
139 "DPP_BOOTSTRAP_GEN type=qrcode curve=%s chan=81/11 mac=%s",
140 curve, mac);
141 }
142
Jouni Malinend86e5822017-08-29 03:55:32 +0300143 if (wpa_command_resp(ifname, buf, resp, sizeof(resp)) < 0)
144 return -2;
145 if (strncmp(resp, "FAIL", 4) == 0)
146 return -2;
147 dut->dpp_local_bootstrap = atoi(resp);
148 snprintf(buf, sizeof(buf), "DPP_BOOTSTRAP_GET_URI %d",
149 atoi(resp));
150 if (wpa_command_resp(ifname, buf, resp, sizeof(resp)) < 0)
151 return -2;
152 if (strncmp(resp, "FAIL", 4) == 0)
153 return -2;
154
155 sigma_dut_print(dut, DUT_MSG_DEBUG, "URI: %s", resp);
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530156
157 if (send_result) {
158 ascii2hexstr(resp, hex);
159 snprintf(resp, sizeof(resp), "BootstrappingData,%s", hex);
160 send_resp(dut, conn, SIGMA_COMPLETE, resp);
161 }
162
163 if (success)
164 *success = 1;
Jouni Malinend86e5822017-08-29 03:55:32 +0300165 return 0;
166}
167
168
169static int dpp_set_peer_bootstrap(struct sigma_dut *dut,
170 struct sigma_conn *conn,
171 struct sigma_cmd *cmd)
172{
173 const char *val = get_param(cmd, "DPPBootstrappingdata");
Jouni Malinenb1dd21f2017-11-13 19:14:29 +0200174 char uri[1000];
Jouni Malinend86e5822017-08-29 03:55:32 +0300175 int res;
Jouni Malinend86e5822017-08-29 03:55:32 +0300176
177 if (!val) {
178 send_resp(dut, conn, SIGMA_ERROR,
179 "errorCode,Missing DPPBootstrappingdata");
180 return 0;
181 }
182
183 res = parse_hexstr(val, (unsigned char *) uri, sizeof(uri));
184 if (res < 0 || (size_t) res >= sizeof(uri))
185 return -2;
186 uri[res] = '\0';
187 sigma_dut_print(dut, DUT_MSG_DEBUG, "URI: %s", uri);
Jouni Malinenb1dd21f2017-11-13 19:14:29 +0200188 free(dut->dpp_peer_uri);
189 dut->dpp_peer_uri = strdup(uri);
Jouni Malinend86e5822017-08-29 03:55:32 +0300190
191 return 1;
192}
193
194
195static int dpp_hostapd_conf_update(struct sigma_dut *dut,
196 struct sigma_conn *conn, const char *ifname,
197 struct wpa_ctrl *ctrl)
198{
199 int res;
200 char buf[2000], buf2[2500], *pos, *pos2;
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300201 const char *conf_data_events[] = {
202 "DPP-CONNECTOR",
203 "DPP-CONFOBJ-PASS",
204 "DPP-CONFOBJ-PSK",
205 NULL
206 };
Jouni Malinend86e5822017-08-29 03:55:32 +0300207
208 sigma_dut_print(dut, DUT_MSG_INFO,
209 "Update hostapd configuration based on DPP Config Object");
210
211 if (wpa_command(ifname, "SET wpa 2") < 0 ||
212 wpa_command(ifname, "SET wpa_key_mgmt DPP") < 0 ||
Jouni Malinen0d347232017-11-01 17:14:00 +0200213 wpa_command(ifname, "SET ieee80211w 1") < 0 ||
Jouni Malinend86e5822017-08-29 03:55:32 +0300214 wpa_command(ifname, "SET rsn_pairwise CCMP") < 0) {
215 send_resp(dut, conn, SIGMA_ERROR,
216 "errorCode,Failed to update AP security parameters");
217 goto out;
218 }
219
220 res = get_wpa_cli_event(dut, ctrl, "DPP-CONFOBJ-SSID",
221 buf, sizeof(buf));
222 if (res < 0) {
223 send_resp(dut, conn, SIGMA_ERROR,
224 "errorCode,No DPP-CONFOBJ-SSID");
225 goto out;
226 }
227 pos = strchr(buf, ' ');
228 if (!pos)
229 return -2;
230 pos++;
231 sigma_dut_print(dut, DUT_MSG_INFO,
232 "DPP: Config Object SSID: %s", pos);
233 snprintf(buf2, sizeof(buf2), "SET ssid %s", pos);
234 if (wpa_command(ifname, buf2) < 0) {
235 send_resp(dut, conn, SIGMA_ERROR,
236 "errorCode,Failed to update AP SSID");
237 goto out;
238 }
239
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300240 res = get_wpa_cli_events(dut, ctrl, conf_data_events, buf, sizeof(buf));
Jouni Malinend86e5822017-08-29 03:55:32 +0300241 if (res < 0) {
242 send_resp(dut, conn, SIGMA_ERROR,
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300243 "errorCode,No DPP-CONNECTOR/DPP-CONFOBJ-PASS/PSK");
Jouni Malinend86e5822017-08-29 03:55:32 +0300244 goto out;
245 }
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300246
247 if (!strstr(buf, "DPP-CONNECTOR")) {
248 if (wpa_command(ifname, "SET wpa_key_mgmt WPA-PSK") < 0) {
249 send_resp(dut, conn, SIGMA_ERROR,
250 "errorCode,Failed to update AP security parameters");
251 goto out;
252 }
253
254 pos = strchr(buf, ' ');
255 if (!pos)
256 return -2;
257 pos++;
258 if (strstr(buf, "DPP-CONFOBJ-PASS")) {
259 char pass[64];
260 int pass_len;
261
262 pass_len = parse_hexstr(pos, (u8 *) pass, sizeof(pass));
Jouni Malinenfddb7ea2018-01-05 21:02:50 +0200263 if (pass_len < 0 || (size_t) pass_len >= sizeof(pass))
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300264 return -2;
265 pass[pass_len] = '\0';
266 sigma_dut_print(dut, DUT_MSG_INFO,
267 "DPP: Passphrase: %s", pass);
268 snprintf(buf2, sizeof(buf2), "SET wpa_passphrase %s",
269 pass);
270 if (wpa_command(ifname, buf2) < 0) {
271 send_resp(dut, conn, SIGMA_ERROR,
272 "errorCode,Failed to set passphrase");
273 goto out;
274 }
275 } else if (strstr(buf, "DPP-CONFOBJ-PSK")) {
276 sigma_dut_print(dut, DUT_MSG_INFO,
277 "DPP: PSK: %s", pos);
278 snprintf(buf2, sizeof(buf2), "SET wpa_psk %s", pos);
279 if (wpa_command(ifname, buf2) < 0) {
280 send_resp(dut, conn, SIGMA_ERROR,
281 "errorCode,Failed to set PSK");
282 goto out;
283 }
284 }
285
286 goto skip_dpp_akm;
287 }
288
Jouni Malinend86e5822017-08-29 03:55:32 +0300289 pos = strchr(buf, ' ');
290 if (!pos)
291 return -2;
292 pos++;
293 sigma_dut_print(dut, DUT_MSG_INFO, "DPP: Connector: %s", pos);
294 snprintf(buf2, sizeof(buf2), "SET dpp_connector %s", pos);
295 if (wpa_command(ifname, buf2) < 0) {
296 send_resp(dut, conn, SIGMA_ERROR,
297 "errorCode,Failed to update AP Connector");
298 goto out;
299 }
300
301 res = get_wpa_cli_event(dut, ctrl, "DPP-C-SIGN-KEY",
302 buf, sizeof(buf));
303 if (res < 0) {
304 send_resp(dut, conn, SIGMA_ERROR,
305 "errorCode,No DPP-C-SIGN-KEY");
306 goto out;
307 }
308 pos = strchr(buf, ' ');
309 if (!pos)
310 return -2;
311 pos++;
Jouni Malinend86e5822017-08-29 03:55:32 +0300312 sigma_dut_print(dut, DUT_MSG_INFO, "DPP: C-sign-key: %s", pos);
313 snprintf(buf2, sizeof(buf2), "SET dpp_csign %s", pos);
314 if (wpa_command(ifname, buf2) < 0) {
315 send_resp(dut, conn, SIGMA_ERROR,
316 "errorCode,Failed to update AP C-sign-key");
317 goto out;
318 }
Jouni Malinend86e5822017-08-29 03:55:32 +0300319
320 res = get_wpa_cli_event(dut, ctrl, "DPP-NET-ACCESS-KEY",
321 buf, sizeof(buf));
322 if (res < 0) {
323 send_resp(dut, conn, SIGMA_ERROR,
324 "errorCode,No DPP-NET-ACCESS-KEY");
325 goto out;
326 }
327 pos = strchr(buf, ' ');
328 if (!pos)
329 return -2;
330 pos++;
331 pos2 = strchr(pos, ' ');
332 if (pos2)
333 *pos2++ = '\0';
334 sigma_dut_print(dut, DUT_MSG_INFO, "DPP: netAccessKey: %s", pos);
335 snprintf(buf2, sizeof(buf2), "SET dpp_netaccesskey %s", pos);
336 if (wpa_command(ifname, buf2) < 0) {
337 send_resp(dut, conn, SIGMA_ERROR,
338 "errorCode,Failed to update AP netAccessKey");
339 goto out;
340 }
341 if (pos2) {
342 sigma_dut_print(dut, DUT_MSG_INFO,
343 "DPP: netAccessKey expiry: %s", pos2);
344 snprintf(buf2, sizeof(buf2), "SET dpp_netaccesskey_expiry %s",
345 pos2);
346 if (wpa_command(ifname, buf2) < 0) {
347 send_resp(dut, conn, SIGMA_ERROR,
348 "errorCode,Failed to update AP netAccessKey expiry");
349 goto out;
350 }
351 }
Jouni Malinenb4c5e3b2017-09-15 17:43:20 +0300352skip_dpp_akm:
Jouni Malinend86e5822017-08-29 03:55:32 +0300353
354 if (wpa_command(ifname, "DISABLE") < 0 ||
355 wpa_command(ifname, "ENABLE") < 0) {
356 send_resp(dut, conn, SIGMA_ERROR,
357 "errorCode,Failed to update AP configuration");
358 goto out;
359 }
360
361 res = get_wpa_cli_event(dut, ctrl, "AP-ENABLED", buf, sizeof(buf));
362 if (res < 0) {
363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,No AP-ENABLED");
364 goto out;
365 }
366
367 return 1;
368out:
369 return 0;
370}
371
372
Jouni Malinen772299f2017-11-06 00:36:26 +0200373struct dpp_test_info {
374 const char *step;
375 const char *frame;
376 const char *attr;
377 int value;
378};
379
380static const struct dpp_test_info dpp_tests[] = {
381 { "InvalidValue", "AuthenticationRequest", "WrappedData", 1 },
382 { "InvalidValue", "AuthenticationResponse", "WrappedData", 2 },
Jouni Malinenf96fcee2017-11-22 16:08:35 +0200383 { "InvalidValue", "AuthenticationResponse", "PrimaryWrappedData", 2 },
Jouni Malinen772299f2017-11-06 00:36:26 +0200384 { "InvalidValue", "AuthenticationConfirm", "WrappedData", 3 },
385 { "InvalidValue", "PKEXCRRequest", "WrappedData", 4 },
386 { "InvalidValue", "PKEXCRResponse", "WrappedData", 5 },
387 { "InvalidValue", "ConfigurationRequest", "WrappedData", 6 },
388 { "InvalidValue", "ConfigurationResponse", "WrappedData", 7 },
389 { "InvalidValue", "AuthenticationRequest", "InitCapabilities", 8 },
Jouni Malinen772299f2017-11-06 00:36:26 +0200390 { "MissingAttribute", "AuthenticationRequest", "RespBSKeyHash", 10 },
391 { "MissingAttribute", "AuthenticationRequest", "InitBSKeyHash", 11 },
392 { "MissingAttribute", "AuthenticationRequest", "InitProtocolKey", 12 },
393 { "MissingAttribute", "AuthenticationRequest", "InitNonce", 13 },
394 { "MissingAttribute", "AuthenticationRequest", "InitCapabilities", 14 },
395 { "MissingAttribute", "AuthenticationRequest", "WrappedData", 15 },
396 { "MissingAttribute", "AuthenticationResponse", "DPPStatus", 16 },
397 { "MissingAttribute", "AuthenticationResponse", "RespBSKeyHash", 17 },
398 { "MissingAttribute", "AuthenticationResponse", "InitBSKeyHash", 18 },
399 { "MissingAttribute", "AuthenticationResponse", "RespProtocolKey", 19 },
400 { "MissingAttribute", "AuthenticationResponse", "RespNonce", 20 },
401 { "MissingAttribute", "AuthenticationResponse", "InitNonce", 21 },
402 { "MissingAttribute", "AuthenticationResponse", "RespCapabilities",
403 22 },
404 { "MissingAttribute", "AuthenticationResponse", "RespAuthTag", 23 },
405 { "MissingAttribute", "AuthenticationResponse", "WrappedData", 24 },
Jouni Malinenf96fcee2017-11-22 16:08:35 +0200406 { "MissingAttribute", "AuthenticationResponse", "PrimaryWrappedData",
407 24 },
Jouni Malinen772299f2017-11-06 00:36:26 +0200408 { "MissingAttribute", "AuthenticationConfirm", "DPPStatus", 25 },
409 { "MissingAttribute", "AuthenticationConfirm", "RespBSKeyHash", 26 },
410 { "MissingAttribute", "AuthenticationConfirm", "InitBSKeyHash", 27 },
411 { "MissingAttribute", "AuthenticationConfirm", "InitAuthTag", 28 },
412 { "MissingAttribute", "AuthenticationConfirm", "WrappedData", 29 },
413 { "InvalidValue", "AuthenticationResponse", "InitNonce", 30 },
414 { "InvalidValue", "AuthenticationResponse", "RespCapabilities", 31 },
415 { "InvalidValue", "AuthenticationResponse", "RespAuthTag", 32 },
416 { "InvalidValue", "AuthenticationConfirm", "InitAuthTag", 33 },
417 { "MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup", 34 },
418 { "MissingAttribute", "PKEXExchangeRequest", "EncryptedKey", 35 },
419 { "MissingAttribute", "PKEXExchangeResponse", "DPPStatus", 36 },
420 { "MissingAttribute", "PKEXExchangeResponse", "EncryptedKey", 37 },
421 { "MissingAttribute", "PKEXCRRequest", "BSKey", 38 },
422 { "MissingAttribute", "PKEXCRRequest", "InitAuthTag", 39 },
423 { "MissingAttribute", "PKEXCRRequest", "WrappedData", 40 },
424 { "MissingAttribute", "PKEXCRResponse", "BSKey", 41 },
425 { "MissingAttribute", "PKEXCRResponse", "RespAuthTag", 42 },
426 { "MissingAttribute", "PKEXCRResponse", "WrappedData", 43 },
427 { "InvalidValue", "PKEXExchangeRequest", "EncryptedKey", 44 },
428 { "InvalidValue", "PKEXExchangeResponse", "EncryptedKey", 45 },
429 { "InvalidValue", "PKEXExchangeResponse", "DPPStatus", 46 },
430 { "InvalidValue", "PKEXCRRequest", "BSKey", 47 },
431 { "InvalidValue", "PKEXCRResponse", "BSKey", 48 },
432 { "InvalidValue", "PKEXCRRequest", "InitAuthTag", 49 },
433 { "InvalidValue", "PKEXCRResponse", "RespAuthTag", 50 },
434 { "MissingAttribute", "ConfigurationRequest", "EnrolleeNonce", 51 },
435 { "MissingAttribute", "ConfigurationRequest", "ConfigAttr", 52 },
436 { "MissingAttribute", "ConfigurationRequest", "WrappedData", 53 },
437 { "MissingAttribute", "ConfigurationResponse", "EnrolleeNonce", 54 },
438 { "MissingAttribute", "ConfigurationResponse", "ConfigObj", 55 },
439 { "MissingAttribute", "ConfigurationResponse", "DPPStatus", 56 },
440 { "MissingAttribute", "ConfigurationResponse", "WrappedData", 57 },
441 { "InvalidValue", "ConfigurationResponse", "DPPStatus", 58 },
442 { "InvalidValue", "ConfigurationResponse", "EnrolleeNonce", 59 },
Jouni Malinen53558e02017-11-06 12:58:28 +0200443 { "MissingAttribute", "PeerDiscoveryRequest", "TransactionID", 60 },
444 { "MissingAttribute", "PeerDiscoveryRequest", "Connector", 61 },
445 { "MissingAttribute", "PeerDiscoveryResponse", "TransactionID", 62 },
446 { "MissingAttribute", "PeerDiscoveryResponse", "DPPStatus", 63 },
447 { "MissingAttribute", "PeerDiscoveryResponse", "Connector", 64 },
Jouni Malinenae624482017-11-19 00:13:51 +0200448 { "InvalidValue", "AuthenticationRequest", "InitProtocolKey", 66 },
449 { "InvalidValue", "AuthenticationResponse", "RespProtocolKey", 67 },
450 { "InvalidValue", "AuthenticationRequest", "RespBSKeyHash", 68 },
451 { "InvalidValue", "AuthenticationRequest", "InitBSKeyHash", 69 },
452 { "InvalidValue", "AuthenticationResponse", "RespBSKeyHash", 70 },
453 { "InvalidValue", "AuthenticationResponse", "InitBSKeyHash", 71 },
454 { "InvalidValue", "AuthenticationConfirm", "RespBSKeyHash", 72 },
455 { "InvalidValue", "AuthenticationConfirm", "InitBSKeyHash", 73 },
456 { "InvalidValue", "AuthenticationResponse", "DPPStatus", 74 },
457 { "InvalidValue", "AuthenticationConfirm", "DPPStatus", 75 },
458 { "InvalidValue", "ConfigurationRequest", "ConfigAttr", 76 },
459 { "InvalidValue", "PeerDiscoveryResponse", "TransactionID", 77 },
460 { "InvalidValue", "PeerDiscoveryResponse", "DPPStatus", 78 },
461 { "InvalidValue", "PeerDiscoveryResponse", "Connector", 79 },
462 { "InvalidValue", "PeerDiscoveryRequest", "Connector", 80 },
Jouni Malinen67795a72017-11-22 16:24:43 +0200463 { "InvalidValue", "AuthenticationRequest", "InitNonce", 81 },
Jouni Malinen188839b2017-11-30 22:02:02 +0200464 { "InvalidValue", "PeerDiscoveryRequest", "TransactionID", 82 },
465 { "InvalidValue", "ConfigurationRequest", "EnrolleeNonce", 83 },
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200466 { "Timeout", "PKEXExchangeResponse", NULL, 84 },
467 { "Timeout", "PKEXCRRequest", NULL, 85 },
468 { "Timeout", "PKEXCRResponse", NULL, 86 },
469 { "Timeout", "AuthenticationRequest", NULL, 87 },
470 { "Timeout", "AuthenticationResponse", NULL, 88 },
471 { "Timeout", "AuthenticationConfirm", NULL, 89 },
472 { "Timeout", "ConfigurationRequest", NULL, 90 },
Jouni Malinen772299f2017-11-06 00:36:26 +0200473 { NULL, NULL, NULL, 0 }
474};
475
476
477static int dpp_get_test(const char *step, const char *frame, const char *attr)
478{
479 int i;
480
481 for (i = 0; dpp_tests[i].step; i++) {
482 if (strcasecmp(step, dpp_tests[i].step) == 0 &&
483 strcasecmp(frame, dpp_tests[i].frame) == 0 &&
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200484 ((!attr && dpp_tests[i].attr == NULL) ||
485 (attr && strcasecmp(attr, dpp_tests[i].attr) == 0)))
Jouni Malinen772299f2017-11-06 00:36:26 +0200486 return dpp_tests[i].value;
487 }
488
489 return -1;
490}
491
492
Jouni Malinen6792ff42018-02-13 00:25:56 +0200493static int dpp_wait_tx(struct sigma_dut *dut, struct wpa_ctrl *ctrl,
494 int frame_type)
495{
496 char buf[200], tmp[20];
497 int res;
498
499 snprintf(tmp, sizeof(tmp), "type=%d", frame_type);
500 for (;;) {
501 res = get_wpa_cli_event(dut, ctrl, "DPP-TX", buf, sizeof(buf));
502 if (res < 0)
503 return -1;
504 if (strstr(buf, tmp) != NULL)
505 break;
506 }
507
508 return 0;
509}
510
511
Jouni Malinen772299f2017-11-06 00:36:26 +0200512static int dpp_wait_tx_status(struct sigma_dut *dut, struct wpa_ctrl *ctrl,
513 int frame_type)
514{
515 char buf[200], tmp[20];
516 int res;
517
518 snprintf(tmp, sizeof(tmp), "type=%d", frame_type);
519 for (;;) {
520 res = get_wpa_cli_event(dut, ctrl, "DPP-TX", buf, sizeof(buf));
521 if (res < 0)
522 return -1;
523 if (strstr(buf, tmp) != NULL)
524 break;
525 }
526
527 res = get_wpa_cli_event(dut, ctrl, "DPP-TX-STATUS",
528 buf, sizeof(buf));
529 if (res < 0 || strstr(buf, "result=FAILED") != NULL)
530 return -1;
531
532 return 0;
533}
534
535
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200536static int dpp_wait_rx(struct sigma_dut *dut, struct wpa_ctrl *ctrl,
Jouni Malinen3e4344e2018-01-22 11:47:37 +0200537 int frame_type, unsigned int max_wait)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200538{
539 char buf[200], tmp[20];
540 int res;
Jouni Malinen9a3415c2018-01-10 22:12:22 +0200541 unsigned int old_timeout;
542
543 old_timeout = dut->default_timeout;
544 if (max_wait > 0 && dut->default_timeout > max_wait)
545 dut->default_timeout = max_wait;
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200546
547 snprintf(tmp, sizeof(tmp), "type=%d", frame_type);
548 for (;;) {
549 res = get_wpa_cli_event(dut, ctrl, "DPP-RX", buf, sizeof(buf));
Jouni Malinen9a3415c2018-01-10 22:12:22 +0200550 if (res < 0) {
551 dut->default_timeout = old_timeout;
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200552 return -1;
Jouni Malinen9a3415c2018-01-10 22:12:22 +0200553 }
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200554 if (strstr(buf, tmp) != NULL)
555 break;
556 }
557
Jouni Malinen9a3415c2018-01-10 22:12:22 +0200558 dut->default_timeout = old_timeout;
559 return 0;
560}
561
562
563static int dpp_wait_rx_conf_req(struct sigma_dut *dut, struct wpa_ctrl *ctrl,
Jouni Malinen3e4344e2018-01-22 11:47:37 +0200564 unsigned int max_wait)
Jouni Malinen9a3415c2018-01-10 22:12:22 +0200565{
566 char buf[200];
567 int res;
568 unsigned int old_timeout;
569
570 old_timeout = dut->default_timeout;
571 if (max_wait > 0 && dut->default_timeout > max_wait)
572 dut->default_timeout = max_wait;
573
574 for (;;) {
575 res = get_wpa_cli_event(dut, ctrl, "DPP-CONF-REQ-RX",
576 buf, sizeof(buf));
577 if (res < 0) {
578 dut->default_timeout = old_timeout;
579 return -1;
580 }
581
582 break;
583 }
584
585 dut->default_timeout = old_timeout;
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200586 return 0;
587}
588
589
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530590static int dpp_scan_peer_qrcode(struct sigma_dut *dut)
Jouni Malinend86e5822017-08-29 03:55:32 +0300591{
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200592#ifdef ANDROID
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530593 char buf[100];
594 char *buf2 = NULL;
595 FILE *fp = NULL;
596 uint32_t length;
597 unsigned int count;
598
599 unlink(dpp_qrcode_file);
600
601 snprintf(buf, sizeof(buf),
Jouni Malinen07458342018-02-22 19:23:40 +0200602 "am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeReadActivity");
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530603 if (system(buf) != 0) {
Jouni Malinen07458342018-02-22 19:23:40 +0200604 sigma_dut_print(dut, DUT_MSG_ERROR,
605 "Failed to launch QR Code scanner");
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530606 return -1;
607 }
608
609 count = 0;
610 while (!(fp = fopen(dpp_qrcode_file, "r"))) {
611 if (count > dut->default_timeout) {
612 sigma_dut_print(dut, DUT_MSG_ERROR,
613 "Failed to open dpp_qrcode_file - QR Code scanning timed out");
614 return -1;
615 }
616
617 sleep(1);
618 count++;
619 }
620
621 if (fseek(fp, 0, SEEK_END) < 0 || (length = ftell(fp)) <= 0 ||
622 fseek(fp, 0, SEEK_SET) < 0) {
623 sigma_dut_print(dut, DUT_MSG_ERROR,
624 "Failed to get QR Code result file length");
625 fclose(fp);
626 return -1;
627 }
628
629 buf2 = malloc(length + 1);
630 if (!buf2) {
631 fclose(fp);
632 return -1;
633 }
634
635 if (fread(buf2, 1, length, fp) != length) {
636 fclose(fp);
637 free(buf2);
638 return -1;
639 }
640
641 fclose(fp);
642 buf2[length] = '\0';
643
644 free(dut->dpp_peer_uri);
645 dut->dpp_peer_uri = strdup(buf2);
646 free(buf2);
647 return 0;
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200648#else /* ANDROID */
649 pid_t pid;
650 int pid_status;
651 int pipe_out[2];
652 char buf[4000], *pos;
653 ssize_t len;
654 int res = -1, ret;
655 struct timeval tv;
656 fd_set rfd;
657
658 if (pipe(pipe_out) != 0) {
659 perror("pipe");
660 return -1;
661 }
662
663 pid = fork();
664 if (pid < 0) {
665 perror("fork");
666 close(pipe_out[0]);
667 close(pipe_out[1]);
668 return -1;
669 }
670
671 if (pid == 0) {
672 char *argv[4] = { "zbarcam", "--raw", "--prescale=320x240",
673 NULL };
674
675 dup2(pipe_out[1], STDOUT_FILENO);
676 close(pipe_out[0]);
677 close(pipe_out[1]);
678 execv("/usr/bin/zbarcam", argv);
679 perror("execv");
680 exit(0);
681 return -1;
682 }
683
684 close(pipe_out[1]);
685
686 FD_ZERO(&rfd);
687 FD_SET(pipe_out[0], &rfd);
688 tv.tv_sec = dut->default_timeout;
689 tv.tv_usec = 0;
690
691 ret = select(pipe_out[0] + 1, &rfd, NULL, NULL, &tv);
692 if (ret < 0) {
693 perror("select");
694 goto out;
695 }
696 if (ret == 0) {
697 sigma_dut_print(dut, DUT_MSG_DEBUG,
698 "QR Code scanning timed out");
699 goto out;
700 }
701
702 len = read(pipe_out[0], buf, sizeof(buf));
703 if (len <= 0)
704 goto out;
705 if (len == sizeof(buf))
706 len--;
707 buf[len] = '\0';
708 pos = strchr(buf, '\n');
709 if (pos)
710 *pos = '\0';
711 sigma_dut_print(dut, DUT_MSG_DEBUG, "URI from QR scanner: %s", buf);
712
713 free(dut->dpp_peer_uri);
714 dut->dpp_peer_uri = strdup(buf);
715 res = 0;
716out:
717 close(pipe_out[0]);
718 kill(pid, SIGTERM);
719 waitpid(pid, &pid_status, 0);
720
721 return res;
722#endif /* ANDROID */
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530723}
724
725
726static int dpp_display_own_qrcode(struct sigma_dut *dut)
727{
728 char buf[200], resp[2000];
729 const char *ifname = get_station_ifname();
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200730#ifdef ANDROID
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530731 FILE *fp;
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200732#else /* ANDROID */
733 pid_t pid;
734 int pid_status;
735#endif /* ANDROID */
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530736
737 snprintf(buf, sizeof(buf), "DPP_BOOTSTRAP_GET_URI %d",
738 dut->dpp_local_bootstrap);
739 if (wpa_command_resp(ifname, buf, resp, sizeof(resp)) < 0 ||
740 strncmp(resp, "FAIL", 4) == 0)
741 return -2;
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200742 sigma_dut_print(dut, DUT_MSG_DEBUG, "Own bootstrap URI: %s", resp);
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530743
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200744#ifdef ANDROID
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530745 unlink(dpp_qrcode_file);
746
747 fp = fopen(dpp_qrcode_file, "w");
748 if (!fp) {
749 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open file %s",
750 dpp_qrcode_file);
751 return -2;
752 }
753
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530754 fwrite(resp, 1, strlen(resp), fp);
755 fclose(fp);
756
757 snprintf(buf, sizeof(buf),
758 "am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeDisplayActivity");
759 if (system(buf) != 0) {
760 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to display QR Code");
761 return -1;
762 }
Jouni Malinen1a38cc32018-01-05 20:59:00 +0200763#else /* ANDROID */
764 pid = fork();
765 if (pid < 0) {
766 perror("fork");
767 return -1;
768 }
769
770 if (pid == 0) {
771 char *argv[3] = { "qr", resp, NULL };
772
773 execv("/usr/bin/qr", argv);
774 perror("execv");
775 exit(0);
776 return -1;
777 }
778
779 waitpid(pid, &pid_status, 0);
780#endif /* ANDROID */
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530781
782 return 0;
Jouni Malinend86e5822017-08-29 03:55:32 +0300783}
784
785
786static int dpp_automatic_dpp(struct sigma_dut *dut,
787 struct sigma_conn *conn,
788 struct sigma_cmd *cmd)
789{
790 const char *bs = get_param(cmd, "DPPBS");
791 const char *auth_role = get_param(cmd, "DPPAuthRole");
792 const char *prov_role = get_param(cmd, "DPPProvisioningRole");
793 const char *pkex_code = get_param(cmd, "DPPPKEXCode");
794 const char *pkex_code_id = get_param(cmd, "DPPPKEXCodeIdentifier");
795 const char *wait_conn = get_param(cmd, "DPPWaitForConnect");
796 const char *self_conf = get_param(cmd, "DPPSelfConfigure");
Jouni Malinen772299f2017-11-06 00:36:26 +0200797 const char *step = get_param(cmd, "DPPStep");
798 const char *frametype = get_param(cmd, "DPPFrameType");
799 const char *attr = get_param(cmd, "DPPIEAttribute");
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530800 const char *action_type = get_param(cmd, "DPPActionType");
Jouni Malinend86e5822017-08-29 03:55:32 +0300801 const char *role;
802 const char *val;
803 const char *conf_role;
Jouni Malinend86e5822017-08-29 03:55:32 +0300804 int conf_index = -1;
805 char buf[2000];
806 char conf_ssid[100];
807 char conf_pass[100];
808 char pkex_identifier[200];
809 struct wpa_ctrl *ctrl;
810 int res;
811 unsigned int old_timeout;
812 int own_pkex_id = -1;
813 const char *ifname = get_station_ifname();
814 const char *auth_events[] = {
815 "DPP-AUTH-SUCCESS",
816 "DPP-NOT-COMPATIBLE",
817 "DPP-RESPONSE-PENDING",
818 "DPP-SCAN-PEER-QR-CODE",
Srinivas Dasaribc9e0552018-01-04 19:24:28 +0530819 "DPP-AUTH-DIRECTION",
Jouni Malinend86e5822017-08-29 03:55:32 +0300820 NULL
821 };
822 const char *conf_events[] = {
823 "DPP-CONF-RECEIVED",
824 "DPP-CONF-SENT",
825 "DPP-CONF-FAILED",
826 NULL
827 };
828 const char *conn_events[] = {
829 "PMKSA-CACHE-ADDED",
830 "CTRL-EVENT-CONNECTED",
831 NULL
832 };
Jouni Malinen3d291f72017-11-02 11:31:05 +0200833 const char *groups_override = NULL;
Jouni Malinen772299f2017-11-06 00:36:26 +0200834 const char *result;
Jouni Malinend1e22f72017-12-05 21:12:17 +0200835 int check_mutual = 0;
Jouni Malinene89cdbf2017-12-11 20:18:24 +0200836 int enrollee_ap;
Jouni Malinenf2fa0d02018-01-11 20:51:31 +0200837 int force_gas_fragm = 0;
Jouni Malinend86e5822017-08-29 03:55:32 +0300838
839 if (!wait_conn)
840 wait_conn = "no";
841 if (!self_conf)
842 self_conf = "no";
843
844 if (!auth_role) {
845 send_resp(dut, conn, SIGMA_ERROR,
846 "errorCode,Missing DPPAuthRole");
847 return 0;
848 }
849
850 if (!prov_role) {
851 send_resp(dut, conn, SIGMA_ERROR,
852 "errorCode,Missing DPPProvisioningRole");
853 return 0;
854 }
855
Jouni Malinene89cdbf2017-12-11 20:18:24 +0200856 val = get_param(cmd, "DPPConfEnrolleeRole");
857 if (val)
858 enrollee_ap = strcasecmp(val, "AP") == 0;
859 else
860 enrollee_ap = sigma_dut_is_ap(dut);
861
Jouni Malinen3a6b92a2017-12-05 20:22:43 +0200862 if ((step || frametype) && (!step || !frametype)) {
Jouni Malinen772299f2017-11-06 00:36:26 +0200863 send_resp(dut, conn, SIGMA_ERROR,
864 "errorCode,Invalid DPPStep,DPPFrameType,DPPIEAttribute combination");
865 return 0;
866 }
867
Jouni Malinend86e5822017-08-29 03:55:32 +0300868 if (sigma_dut_is_ap(dut)) {
869 if (!dut->hostapd_ifname) {
870 sigma_dut_print(dut, DUT_MSG_ERROR,
871 "hostapd ifname not specified (-j)");
872 return -2;
873 }
874 ifname = dut->hostapd_ifname;
875
876 if (dpp_hostapd_run(dut) < 0) {
877 send_resp(dut, conn, SIGMA_ERROR,
878 "errorCode,Failed to start hostapd");
879 return 0;
880 }
881 }
882
Jouni Malinen67acb0c2017-11-21 01:01:54 +0200883 if (strcasecmp(prov_role, "Configurator") == 0 ||
884 strcasecmp(prov_role, "Both") == 0) {
Jouni Malinend86e5822017-08-29 03:55:32 +0300885 if (dut->dpp_conf_id < 0) {
886 snprintf(buf, sizeof(buf),
887 "DPP_CONFIGURATOR_ADD curve=%s",
888 dpp_get_curve(cmd, "DPPSigningKeyECC"));
889 if (wpa_command_resp(ifname, buf,
890 buf, sizeof(buf)) < 0) {
891 send_resp(dut, conn, SIGMA_ERROR,
892 "errorCode,Failed to set up configurator");
893 return 0;
894 }
895 dut->dpp_conf_id = atoi(buf);
896 }
Jouni Malinen67acb0c2017-11-21 01:01:54 +0200897 if (strcasecmp(prov_role, "Configurator") == 0)
898 role = "configurator";
899 else
900 role = "either";
Jouni Malinend86e5822017-08-29 03:55:32 +0300901 } else if (strcasecmp(prov_role, "Enrollee") == 0) {
902 role = "enrollee";
903 } else {
904 send_resp(dut, conn, SIGMA_ERROR,
905 "errorCode,Unknown DPPProvisioningRole");
906 return 0;
907 }
908
909 pkex_identifier[0] = '\0';
910 if (strcasecmp(bs, "PKEX") == 0) {
Jouni Malinen4f47a272017-11-04 12:29:11 +0200911 if (sigma_dut_is_ap(dut) && dut->ap_channel != 6) {
912 /* For now, have to make operating channel match DPP
913 * listen channel. This should be removed once hostapd
914 * has support for DPP listen on non-operating channel.
915 */
916 sigma_dut_print(dut, DUT_MSG_INFO,
917 "Update hostapd operating channel to match listen needs");
918 dut->ap_channel = 6;
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -0800919
920 if (get_driver_type() == DRIVER_OPENWRT) {
921 snprintf(buf, sizeof(buf),
922 "iwconfig %s channel %d",
923 dut->hostapd_ifname, dut->ap_channel);
924 run_system(dut, buf);
925 }
926
Jouni Malinen4f47a272017-11-04 12:29:11 +0200927 if (wpa_command(ifname, "SET channel 6") < 0 ||
928 wpa_command(ifname, "DISABLE") < 0 ||
929 wpa_command(ifname, "ENABLE") < 0) {
930 send_resp(dut, conn, SIGMA_ERROR,
931 "errorCode,Failed to update channel");
932 return 0;
933 }
934 }
935
Jouni Malinend86e5822017-08-29 03:55:32 +0300936 if (!pkex_code) {
937 send_resp(dut, conn, SIGMA_ERROR,
938 "errorCode,Missing DPPPKEXCode");
939 return 0;
940 }
941
942 if (pkex_code_id)
943 snprintf(pkex_identifier, sizeof(pkex_identifier),
944 "identifier=%s ", pkex_code_id);
945
946 snprintf(buf, sizeof(buf),
947 "DPP_BOOTSTRAP_GEN type=pkex curve=%s",
948 dpp_get_curve(cmd, "DPPCryptoIdentifier"));
949 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) {
950 send_resp(dut, conn, SIGMA_ERROR,
951 "errorCode,Failed to set up PKEX");
952 return 0;
953 }
954 own_pkex_id = atoi(buf);
955 }
956
957 ctrl = open_wpa_mon(ifname);
958 if (!ctrl) {
959 sigma_dut_print(dut, DUT_MSG_ERROR,
960 "Failed to open wpa_supplicant monitor connection");
961 return -2;
962 }
963
964 old_timeout = dut->default_timeout;
965 val = get_param(cmd, "DPPTimeout");
966 if (val && atoi(val) > 0) {
967 dut->default_timeout = atoi(val);
968 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP timeout: %u",
969 dut->default_timeout);
970 }
971
972 conf_ssid[0] = '\0';
973 conf_pass[0] = '\0';
974 val = get_param(cmd, "DPPConfIndex");
975 if (val)
976 conf_index = atoi(val);
Jouni Malinend86e5822017-08-29 03:55:32 +0300977 switch (conf_index) {
Jouni Malinen258cc262017-10-13 00:19:56 +0300978 case -1:
979 conf_role = NULL;
980 break;
Jouni Malinend86e5822017-08-29 03:55:32 +0300981 case 1:
982 ascii2hexstr("DPPNET01", buf);
983 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
Jouni Malinene89cdbf2017-12-11 20:18:24 +0200984 if (enrollee_ap) {
Jouni Malinend86e5822017-08-29 03:55:32 +0300985 conf_role = "ap-dpp";
Jouni Malinen3d291f72017-11-02 11:31:05 +0200986 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"ap\"}]";
987 } else {
Jouni Malinend86e5822017-08-29 03:55:32 +0300988 conf_role = "sta-dpp";
Jouni Malinen3d291f72017-11-02 11:31:05 +0200989 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"sta\"}]";
990 }
Jouni Malinend86e5822017-08-29 03:55:32 +0300991 break;
992 case 2:
993 ascii2hexstr("DPPNET01", buf);
994 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
Jouni Malinen8f81cdf2017-09-15 18:15:18 +0300995 snprintf(conf_pass, sizeof(conf_pass),
996 "psk=10506e102ad1e7f95112f6b127675bb8344dacacea60403f3fa4055aec85b0fc");
Jouni Malinene89cdbf2017-12-11 20:18:24 +0200997 if (enrollee_ap)
Jouni Malinend86e5822017-08-29 03:55:32 +0300998 conf_role = "ap-psk";
999 else
1000 conf_role = "sta-psk";
1001 break;
1002 case 3:
1003 ascii2hexstr("DPPNET01", buf);
1004 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
1005 ascii2hexstr("ThisIsDppPassphrase", buf);
1006 snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf);
Jouni Malinene89cdbf2017-12-11 20:18:24 +02001007 if (enrollee_ap)
Jouni Malinend86e5822017-08-29 03:55:32 +03001008 conf_role = "ap-psk";
1009 else
1010 conf_role = "sta-psk";
1011 break;
Jouni Malinen3d291f72017-11-02 11:31:05 +02001012 case 4:
1013 ascii2hexstr("DPPNET01", buf);
1014 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
Jouni Malinene89cdbf2017-12-11 20:18:24 +02001015 if (enrollee_ap) {
Jouni Malinen3d291f72017-11-02 11:31:05 +02001016 conf_role = "ap-dpp";
1017 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA2\",\"netRole\":\"ap\"}]";
1018 } else {
1019 conf_role = "sta-dpp";
1020 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA2\",\"netRole\":\"sta\"}]";
1021 }
1022 break;
Jouni Malinen7d031c72018-01-09 19:39:56 +02001023 case 5:
1024 ascii2hexstr("DPPNET01", buf);
1025 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
1026 ascii2hexstr("ThisIsDppPassphrase", buf);
1027 snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf);
1028 if (enrollee_ap)
1029 conf_role = "ap-sae";
1030 else
1031 conf_role = "sta-sae";
1032 break;
1033 case 6:
1034 ascii2hexstr("DPPNET01", buf);
1035 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
1036 ascii2hexstr("ThisIsDppPassphrase", buf);
1037 snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf);
1038 if (enrollee_ap)
1039 conf_role = "ap-psk-sae";
1040 else
1041 conf_role = "sta-psk-sae";
1042 break;
Jouni Malinenf2fa0d02018-01-11 20:51:31 +02001043 case 7:
1044 ascii2hexstr("DPPNET01", buf);
1045 snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf);
1046 if (enrollee_ap) {
1047 conf_role = "ap-dpp";
1048 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"ap\"}]";
1049 } else {
1050 conf_role = "sta-dpp";
1051 groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"sta\"}]";
1052 }
1053 force_gas_fragm = 1;
1054 break;
Jouni Malinenf7490762017-10-12 00:34:37 +03001055 default:
1056 send_resp(dut, conn, SIGMA_ERROR,
1057 "errorCode,Unsupported DPPConfIndex");
1058 goto out;
Jouni Malinend86e5822017-08-29 03:55:32 +03001059 }
1060
Jouni Malinen3d291f72017-11-02 11:31:05 +02001061 if (groups_override) {
Jouni Malinen2b2230f2018-02-12 13:05:06 +02001062 snprintf(buf, sizeof(buf), "SET dpp_groups_override %s",
1063 groups_override);
Jouni Malinen3d291f72017-11-02 11:31:05 +02001064 if (wpa_command(ifname, buf) < 0) {
1065 send_resp(dut, conn, SIGMA_ERROR,
1066 "errorCode,Failed to set cred:groups");
1067 goto out;
1068 }
1069 }
1070
Jouni Malinen2b2230f2018-02-12 13:05:06 +02001071 if (force_gas_fragm) {
1072 char spaces[1500];
1073
1074 memset(spaces, ' ', sizeof(spaces));
1075 spaces[sizeof(spaces) - 1] = '\0';
1076
1077 snprintf(buf, sizeof(buf),
1078 "SET dpp_discovery_override {\"ssid\":\"DPPNET01\"}%s",
1079 spaces);
1080 if (wpa_command(ifname, buf) < 0) {
1081 send_resp(dut, conn, SIGMA_ERROR,
1082 "errorCode,Failed to set discovery override");
1083 goto out;
1084 }
1085 }
1086
Jouni Malinen772299f2017-11-06 00:36:26 +02001087 if (step) {
1088 int test;
1089
1090 test = dpp_get_test(step, frametype, attr);
1091 if (test <= 0) {
1092 send_resp(dut, conn, SIGMA_ERROR,
1093 "errorCode,Unsupported DPPStep/DPPFrameType/DPPIEAttribute");
1094 goto out;
1095 }
1096
1097 snprintf(buf, sizeof(buf), "SET dpp_test %d", test);
1098 if (wpa_command(ifname, buf) < 0) {
1099 send_resp(dut, conn, SIGMA_ERROR,
1100 "errorCode,Failed to set dpp_test");
1101 goto out;
1102 }
1103 } else {
1104 wpa_command(ifname, "SET dpp_test 0");
1105 }
1106
Jouni Malinenfbb268d2017-11-17 18:53:49 +02001107 if (strcasecmp(self_conf, "Yes") == 0) {
1108 if (strcasecmp(prov_role, "Configurator") != 0) {
1109 send_resp(dut, conn, SIGMA_ERROR,
1110 "errorCode,Invalid DPPSelfConfigure use - only allowed for Configurator role");
1111 goto out;
1112 }
1113 if (!conf_role) {
1114 send_resp(dut, conn, SIGMA_ERROR,
1115 "errorCode,Missing DPPConfIndex");
1116 goto out;
1117 }
1118
1119 snprintf(buf, sizeof(buf),
1120 "DPP_CONFIGURATOR_SIGN conf=%s %s %s configurator=%d",
1121 conf_role, conf_ssid, conf_pass, dut->dpp_conf_id);
1122 if (wpa_command(ifname, buf) < 0) {
1123 send_resp(dut, conn, SIGMA_ERROR,
1124 "errorCode,Failed to initiate DPP self-configuration");
1125 goto out;
1126 }
Jouni Malinen174db642017-11-27 20:16:29 +02001127 if (sigma_dut_is_ap(dut))
1128 goto update_ap;
Jouni Malinenfbb268d2017-11-17 18:53:49 +02001129 goto wait_connect;
1130 } else if (strcasecmp(auth_role, "Initiator") == 0) {
Jouni Malinend86e5822017-08-29 03:55:32 +03001131 char own_txt[20];
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001132 int dpp_peer_bootstrap = -1;
Jouni Malinenb5ab8282017-11-21 01:12:22 +02001133 char neg_freq[30];
1134
Jouni Malinend1e22f72017-12-05 21:12:17 +02001135 val = get_param(cmd, "DPPAuthDirection");
1136 check_mutual = val && strcasecmp(val, "Mutual") == 0;
1137
Jouni Malinenb5ab8282017-11-21 01:12:22 +02001138 neg_freq[0] = '\0';
1139 val = get_param(cmd, "DPPSubsequentChannel");
1140 if (val) {
1141 int opclass, channel, freq;
1142
1143 opclass = atoi(val);
1144 val = strchr(val, '/');
1145 if (opclass == 0 || !val) {
1146 send_resp(dut, conn, SIGMA_ERROR,
1147 "errorCode,Invalid DPPSubsequentChannel");
1148 goto out;
1149 }
1150 val++;
1151 channel = atoi(val);
1152
1153 /* Ignoring opclass for now; could use it here for more
1154 * robust frequency determination. */
1155 freq = channel_to_freq(channel);
1156 if (!freq) {
1157 send_resp(dut, conn, SIGMA_ERROR,
1158 "errorCode,Unsupported DPPSubsequentChannel channel");
1159 goto out;
1160 }
1161 snprintf(neg_freq, sizeof(neg_freq), " neg_freq=%d",
1162 freq);
1163 }
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001164
1165 if (strcasecmp(bs, "QR") == 0) {
1166 if (!dut->dpp_peer_uri) {
1167 send_resp(dut, conn, SIGMA_ERROR,
1168 "errorCode,Missing peer bootstrapping info");
1169 goto out;
1170 }
1171
1172 snprintf(buf, sizeof(buf), "DPP_QR_CODE %s",
1173 dut->dpp_peer_uri);
1174 if (wpa_command_resp(ifname, buf, buf,
1175 sizeof(buf)) < 0) {
1176 send_resp(dut, conn, SIGMA_ERROR,
1177 "errorCode,Failed to parse URI");
1178 goto out;
1179 }
1180 dpp_peer_bootstrap = atoi(buf);
1181 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001182
Jouni Malinen63d50412017-11-24 11:55:38 +02001183 if (dut->dpp_local_bootstrap >= 0)
Jouni Malinend86e5822017-08-29 03:55:32 +03001184 snprintf(own_txt, sizeof(own_txt), " own=%d",
1185 dut->dpp_local_bootstrap);
1186 else
1187 own_txt[0] = '\0';
1188 if (strcasecmp(bs, "QR") == 0 &&
Jouni Malinen67acb0c2017-11-21 01:01:54 +02001189 (strcasecmp(prov_role, "Configurator") == 0 ||
1190 strcasecmp(prov_role, "Both") == 0)) {
Jouni Malinen258cc262017-10-13 00:19:56 +03001191 if (!conf_role) {
1192 send_resp(dut, conn, SIGMA_ERROR,
1193 "errorCode,Missing DPPConfIndex");
1194 goto out;
1195 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001196 snprintf(buf, sizeof(buf),
Jouni Malinenb5ab8282017-11-21 01:12:22 +02001197 "DPP_AUTH_INIT peer=%d%s role=%s conf=%s %s %s configurator=%d%s",
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001198 dpp_peer_bootstrap, own_txt, role,
Jouni Malinend86e5822017-08-29 03:55:32 +03001199 conf_role, conf_ssid, conf_pass,
Jouni Malinenb5ab8282017-11-21 01:12:22 +02001200 dut->dpp_conf_id, neg_freq);
Jouni Malinend86e5822017-08-29 03:55:32 +03001201 } else if (strcasecmp(bs, "QR") == 0) {
1202 snprintf(buf, sizeof(buf),
Jouni Malinenb5ab8282017-11-21 01:12:22 +02001203 "DPP_AUTH_INIT peer=%d%s role=%s%s",
1204 dpp_peer_bootstrap, own_txt, role, neg_freq);
Jouni Malinend86e5822017-08-29 03:55:32 +03001205 } else if (strcasecmp(bs, "PKEX") == 0 &&
Jouni Malinen67acb0c2017-11-21 01:01:54 +02001206 (strcasecmp(prov_role, "Configurator") == 0 ||
1207 strcasecmp(prov_role, "Both") == 0)) {
Jouni Malinen258cc262017-10-13 00:19:56 +03001208 if (!conf_role) {
1209 send_resp(dut, conn, SIGMA_ERROR,
1210 "errorCode,Missing DPPConfIndex");
1211 goto out;
1212 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001213 snprintf(buf, sizeof(buf),
1214 "DPP_PKEX_ADD own=%d init=1 role=%s conf=%s %s %s configurator=%d %scode=%s",
1215 own_pkex_id, role, conf_role,
1216 conf_ssid, conf_pass, dut->dpp_conf_id,
1217 pkex_identifier, pkex_code);
1218 } else if (strcasecmp(bs, "PKEX") == 0) {
1219 snprintf(buf, sizeof(buf),
1220 "DPP_PKEX_ADD own=%d init=1 role=%s %scode=%s",
1221 own_pkex_id, role, pkex_identifier, pkex_code);
Jouni Malinend551c6f2017-10-12 00:32:18 +03001222 } else {
1223 send_resp(dut, conn, SIGMA_ERROR,
1224 "errorCode,Unsupported DPPBS");
1225 goto out;
Jouni Malinend86e5822017-08-29 03:55:32 +03001226 }
1227 if (wpa_command(ifname, buf) < 0) {
1228 send_resp(dut, conn, SIGMA_ERROR,
1229 "errorCode,Failed to initiate DPP authentication");
1230 goto out;
1231 }
1232 } else if (strcasecmp(auth_role, "Responder") == 0) {
Jouni Malinen67f096a2017-11-24 11:58:51 +02001233 const char *delay_qr_resp;
Jouni Malinen63d50412017-11-24 11:55:38 +02001234 int mutual;
Jouni Malinend3afc5c2017-11-13 18:39:14 +02001235 int freq = 2462; /* default: channel 11 */
1236
Jouni Malinen06cfcb32018-01-11 20:43:50 +02001237 if (strcasecmp(bs, "PKEX") == 0) {
1238 /* default: channel 6 for PKEX */
1239 freq = 2437;
1240 }
1241
Jouni Malinen67f096a2017-11-24 11:58:51 +02001242 delay_qr_resp = get_param(cmd, "DPPDelayQRResponse");
1243
Jouni Malinen63d50412017-11-24 11:55:38 +02001244 val = get_param(cmd, "DPPAuthDirection");
1245 mutual = val && strcasecmp(val, "Mutual") == 0;
1246
Jouni Malinend3afc5c2017-11-13 18:39:14 +02001247 val = get_param(cmd, "DPPListenChannel");
1248 if (val) {
1249 freq = channel_to_freq(atoi(val));
1250 if (freq == 0) {
1251 send_resp(dut, conn, SIGMA_ERROR,
1252 "errorCode,Unsupported DPPListenChannel value");
1253 goto out;
1254 }
1255 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001256
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001257 if (!delay_qr_resp && dut->dpp_peer_uri) {
1258 snprintf(buf, sizeof(buf), "DPP_QR_CODE %s",
1259 dut->dpp_peer_uri);
1260 if (wpa_command_resp(ifname, buf, buf,
1261 sizeof(buf)) < 0) {
1262 send_resp(dut, conn, SIGMA_ERROR,
1263 "errorCode,Failed to parse URI");
1264 goto out;
1265 }
1266 }
1267
Jouni Malinend86e5822017-08-29 03:55:32 +03001268 if (strcasecmp(prov_role, "Configurator") == 0) {
Jouni Malinen258cc262017-10-13 00:19:56 +03001269 if (!conf_role) {
1270 send_resp(dut, conn, SIGMA_ERROR,
1271 "errorCode,Missing DPPConfIndex");
1272 goto out;
1273 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001274 snprintf(buf, sizeof(buf),
1275 "SET dpp_configurator_params conf=%s %s %s configurator=%d",
1276 conf_role, conf_ssid, conf_pass,
1277 dut->dpp_conf_id);
1278 if (wpa_command(ifname, buf) < 0) {
1279 send_resp(dut, conn, SIGMA_ERROR,
1280 "errorCode,Failed to set configurator parameters");
1281 goto out;
1282 }
1283 }
1284 if (strcasecmp(bs, "PKEX") == 0) {
Jouni Malinend86e5822017-08-29 03:55:32 +03001285 snprintf(buf, sizeof(buf),
1286 "DPP_PKEX_ADD own=%d role=%s %scode=%s",
1287 own_pkex_id, role, pkex_identifier, pkex_code);
1288 if (wpa_command(ifname, buf) < 0) {
1289 send_resp(dut, conn, SIGMA_ERROR,
1290 "errorCode,Failed to configure DPP PKEX");
1291 goto out;
1292 }
1293 }
1294
Jouni Malinenbafc1932017-11-04 11:31:16 +02001295 snprintf(buf, sizeof(buf), "DPP_LISTEN %d role=%s%s",
1296 freq, role,
1297 (strcasecmp(bs, "QR") == 0 && mutual) ?
1298 " qr=mutual" : "");
1299 if (wpa_command(ifname, buf) < 0) {
1300 send_resp(dut, conn, SIGMA_ERROR,
1301 "errorCode,Failed to start DPP listen");
1302 goto out;
Jouni Malinend86e5822017-08-29 03:55:32 +03001303 }
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001304
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08001305 if (get_driver_type() == DRIVER_OPENWRT) {
1306 snprintf(buf, sizeof(buf), "iwconfig %s channel %d",
1307 dut->hostapd_ifname, freq_to_channel(freq));
1308 run_system(dut, buf);
1309 }
1310
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001311 if (delay_qr_resp && mutual && dut->dpp_peer_uri) {
1312 int wait_time = atoi(delay_qr_resp);
1313
1314 res = get_wpa_cli_events(dut, ctrl, auth_events,
1315 buf, sizeof(buf));
1316 if (res < 0) {
1317 send_resp(dut, conn, SIGMA_COMPLETE,
1318 "BootstrapResult,OK,AuthResult,Timeout");
1319 goto out;
1320 }
1321 sigma_dut_print(dut, DUT_MSG_DEBUG,
1322 "DPP auth result: %s", buf);
1323 if (strstr(buf, "DPP-SCAN-PEER-QR-CODE") == NULL) {
1324 send_resp(dut, conn, SIGMA_ERROR,
1325 "errorCode,No scan request for peer QR Code seen");
1326 goto out;
1327 }
1328 sigma_dut_print(dut, DUT_MSG_INFO,
1329 "Waiting %d second(s) before processing peer URI",
1330 wait_time);
1331 sleep(wait_time);
1332
1333 snprintf(buf, sizeof(buf), "DPP_QR_CODE %s",
1334 dut->dpp_peer_uri);
1335 if (wpa_command_resp(ifname, buf, buf,
1336 sizeof(buf)) < 0) {
1337 send_resp(dut, conn, SIGMA_ERROR,
1338 "errorCode,Failed to parse URI");
1339 goto out;
1340 }
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301341 } else if (mutual && action_type &&
1342 strcasecmp(action_type, "ManualDPP") == 0) {
1343 res = get_wpa_cli_events(dut, ctrl, auth_events,
1344 buf, sizeof(buf));
1345 if (res < 0) {
1346 send_resp(dut, conn, SIGMA_COMPLETE,
1347 "BootstrapResult,OK,AuthResult,Timeout");
1348 goto out;
1349 }
1350 sigma_dut_print(dut, DUT_MSG_DEBUG,
1351 "DPP auth result: %s", buf);
1352 if (strstr(buf, "DPP-SCAN-PEER-QR-CODE") == NULL) {
1353 send_resp(dut, conn, SIGMA_ERROR,
1354 "errorCode,No scan request for peer QR Code seen");
1355 goto out;
1356 }
1357
1358 if (dpp_scan_peer_qrcode(dut) < 0) {
1359 send_resp(dut, conn, SIGMA_ERROR,
1360 "errorCode,Failed to scan peer QR Code");
1361 goto out;
1362 }
1363
1364 snprintf(buf, sizeof(buf), "DPP_QR_CODE %s",
1365 dut->dpp_peer_uri);
1366 if (wpa_command_resp(ifname, buf, buf,
1367 sizeof(buf)) < 0) {
1368 send_resp(dut, conn, SIGMA_ERROR,
1369 "errorCode,Failed to parse URI");
1370 goto out;
1371 }
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02001372 }
Jouni Malinend86e5822017-08-29 03:55:32 +03001373 } else {
1374 send_resp(dut, conn, SIGMA_ERROR,
1375 "errorCode,Unknown DPPAuthRole");
1376 goto out;
1377 }
1378
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001379 if (step && strcasecmp(step, "Timeout") == 0) {
1380 result = "errorCode,Unexpected state";
1381
1382 if (strcasecmp(frametype, "PKEXExchangeResponse") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001383 if (dpp_wait_rx(dut, ctrl, 8, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001384 result = "BootstrapResult,Timeout";
1385 else
1386 result = "BootstrapResult,Errorsent";
1387 }
1388
1389 if (strcasecmp(frametype, "PKEXCRRequest") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001390 if (dpp_wait_rx(dut, ctrl, 9, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001391 result = "BootstrapResult,Timeout";
1392 else
1393 result = "BootstrapResult,Errorsent";
1394 }
1395
1396 if (strcasecmp(frametype, "PKEXCRResponse") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001397 if (dpp_wait_rx(dut, ctrl, 10, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001398 result = "BootstrapResult,Timeout";
1399 else
1400 result = "BootstrapResult,Errorsent";
1401 }
1402
1403 if (strcasecmp(frametype, "AuthenticationRequest") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001404 if (dpp_wait_rx(dut, ctrl, 0, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001405 result = "BootstrapResult,OK,AuthResult,Timeout";
1406 else
1407 result = "BootstrapResult,OK,AuthResult,Errorsent";
1408 }
1409
1410 if (strcasecmp(frametype, "AuthenticationResponse") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001411 if (dpp_wait_rx(dut, ctrl, 1, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001412 result = "BootstrapResult,OK,AuthResult,Timeout";
1413 else
1414 result = "BootstrapResult,OK,AuthResult,Errorsent";
1415 }
1416
1417 if (strcasecmp(frametype, "AuthenticationConfirm") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001418 if (dpp_wait_rx(dut, ctrl, 2, -1) < 0)
Jouni Malinen3a6b92a2017-12-05 20:22:43 +02001419 result = "BootstrapResult,OK,AuthResult,Timeout";
1420 else
1421 result = "BootstrapResult,OK,AuthResult,Errorsent";
1422 }
1423
1424 if (strcasecmp(frametype, "ConfigurationRequest") == 0) {
1425 if (get_wpa_cli_event(dut, ctrl, "DPP-CONF-FAILED",
1426 buf, sizeof(buf)) < 0)
1427 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout";
1428 else
1429 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent";
1430 }
1431
1432 send_resp(dut, conn, SIGMA_COMPLETE, result);
1433 goto out;
1434 }
1435
Jouni Malinen772299f2017-11-06 00:36:26 +02001436 if (frametype && strcasecmp(frametype, "PKEXExchangeRequest") == 0) {
1437 if (dpp_wait_tx_status(dut, ctrl, 7) < 0)
1438 result = "BootstrapResult,Timeout";
1439 else
1440 result = "BootstrapResult,Errorsent";
1441 send_resp(dut, conn, SIGMA_COMPLETE, result);
1442 goto out;
1443 }
1444
1445 if (frametype && strcasecmp(frametype, "PKEXExchangeResponse") == 0) {
1446 if (dpp_wait_tx_status(dut, ctrl, 8) < 0)
1447 result = "BootstrapResult,Timeout";
1448 else
1449 result = "BootstrapResult,Errorsent";
1450 send_resp(dut, conn, SIGMA_COMPLETE, result);
1451 goto out;
1452 }
1453
1454 if (frametype && strcasecmp(frametype, "PKEXCRRequest") == 0) {
1455 if (dpp_wait_tx_status(dut, ctrl, 9) < 0)
1456 result = "BootstrapResult,Timeout";
1457 else
1458 result = "BootstrapResult,Errorsent";
1459 send_resp(dut, conn, SIGMA_COMPLETE, result);
1460 goto out;
1461 }
1462
1463 if (frametype && strcasecmp(frametype, "PKEXCRResponse") == 0) {
1464 if (dpp_wait_tx_status(dut, ctrl, 10) < 0)
1465 result = "BootstrapResult,Timeout";
1466 else
1467 result = "BootstrapResult,Errorsent";
1468 send_resp(dut, conn, SIGMA_COMPLETE, result);
1469 goto out;
1470 }
1471
Jouni Malinen6792ff42018-02-13 00:25:56 +02001472 if (!frametype && strcasecmp(bs, "PKEX") == 0 &&
1473 strcasecmp(auth_role, "Responder") == 0) {
1474 if (dpp_wait_tx_status(dut, ctrl, 10) < 0) {
1475 send_resp(dut, conn, SIGMA_COMPLETE,
1476 "BootstrapResult,Timeout");
1477 goto out;
1478 }
1479 }
1480
1481 if (!frametype && strcasecmp(bs, "PKEX") == 0 &&
1482 strcasecmp(auth_role, "Initiator") == 0) {
1483 if (dpp_wait_tx(dut, ctrl, 0) < 0) {
1484 send_resp(dut, conn, SIGMA_COMPLETE,
1485 "BootstrapResult,Timeout");
1486 goto out;
1487 }
1488 }
1489
Jouni Malinen772299f2017-11-06 00:36:26 +02001490 if (frametype && strcasecmp(frametype, "AuthenticationRequest") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001491 if (dpp_wait_tx_status(dut, ctrl, 0) < 0) {
1492 send_resp(dut, conn, SIGMA_COMPLETE,
1493 "BootstrapResult,OK,AuthResult,Timeout");
1494 goto out;
1495 }
1496
1497 if (dpp_wait_rx(dut, ctrl, 1, 5) < 0)
1498 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,None";
Jouni Malinen772299f2017-11-06 00:36:26 +02001499 else
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001500 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationResponse";
Jouni Malinen772299f2017-11-06 00:36:26 +02001501 send_resp(dut, conn, SIGMA_COMPLETE, result);
1502 goto out;
1503 }
1504
1505 if (frametype && strcasecmp(frametype, "AuthenticationResponse") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001506 if (dpp_wait_tx_status(dut, ctrl, 1) < 0) {
1507 send_resp(dut, conn, SIGMA_COMPLETE,
1508 "BootstrapResult,OK,AuthResult,Timeout");
1509 goto out;
1510 }
1511
1512 if (dpp_wait_rx(dut, ctrl, 2, 5) < 0)
1513 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationRequest";
Jouni Malinen772299f2017-11-06 00:36:26 +02001514 else
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001515 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationConfirm";
Jouni Malinen772299f2017-11-06 00:36:26 +02001516 send_resp(dut, conn, SIGMA_COMPLETE, result);
1517 goto out;
1518 }
1519
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301520 res = get_wpa_cli_events(dut, ctrl, auth_events, buf, sizeof(buf));
1521 if (res < 0) {
1522 send_resp(dut, conn, SIGMA_COMPLETE,
1523 "BootstrapResult,OK,AuthResult,Timeout");
1524 goto out;
1525 }
1526 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf);
1527
1528 if (strstr(buf, "DPP-RESPONSE-PENDING")) {
1529 /* Display own QR code in manual mode */
1530 if (action_type && strcasecmp(action_type, "ManualDPP") == 0 &&
1531 dpp_display_own_qrcode(dut) < 0) {
1532 send_resp(dut, conn, SIGMA_ERROR,
1533 "errorCode,Failed to display own QR code");
1534 goto out;
1535 }
1536
1537 /* Wait for the actual result after the peer has scanned the
1538 * QR Code. */
1539 res = get_wpa_cli_events(dut, ctrl, auth_events,
1540 buf, sizeof(buf));
Jouni Malinend1e22f72017-12-05 21:12:17 +02001541 if (res < 0) {
1542 send_resp(dut, conn, SIGMA_COMPLETE,
1543 "BootstrapResult,OK,AuthResult,Timeout");
1544 goto out;
1545 }
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301546
1547 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf);
1548 }
1549
1550 if (check_mutual) {
Jouni Malinena98426a2018-02-06 21:18:48 +02001551 if (strstr(buf, "DPP-NOT-COMPATIBLE")) {
1552 send_resp(dut, conn, SIGMA_COMPLETE,
1553 "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE");
1554 goto out;
1555 }
1556
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301557 if (!strstr(buf, "DPP-AUTH-DIRECTION")) {
1558 send_resp(dut, conn, SIGMA_ERROR,
1559 "errorCode,No event for auth direction seen");
1560 goto out;
1561 }
1562
Jouni Malinend1e22f72017-12-05 21:12:17 +02001563 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth direction: %s",
1564 buf);
1565 if (strstr(buf, "mutual=1") == NULL) {
1566 send_resp(dut, conn, SIGMA_ERROR,
1567 "errorCode,Peer did not use mutual authentication");
1568 goto out;
1569 }
1570 }
1571
Jouni Malinen772299f2017-11-06 00:36:26 +02001572 if (frametype && strcasecmp(frametype, "AuthenticationConfirm") == 0) {
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001573 if (dpp_wait_tx_status(dut, ctrl, 2) < 0) {
1574 send_resp(dut, conn, SIGMA_COMPLETE,
1575 "BootstrapResult,OK,AuthResult,Timeout");
1576 goto out;
1577 }
1578
1579 if (dpp_wait_rx_conf_req(dut, ctrl, 5) < 0)
1580 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationResponse";
Jouni Malinen772299f2017-11-06 00:36:26 +02001581 else
Jouni Malinen9a3415c2018-01-10 22:12:22 +02001582 result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,ConfigurationRequest";
Jouni Malinen772299f2017-11-06 00:36:26 +02001583 send_resp(dut, conn, SIGMA_COMPLETE, result);
1584 goto out;
1585 }
1586
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301587 if (strstr(buf, "DPP-AUTH-DIRECTION")) {
Jouni Malinen2e9c8a42017-11-19 12:06:18 +02001588 res = get_wpa_cli_events(dut, ctrl, auth_events,
1589 buf, sizeof(buf));
1590 if (res < 0) {
1591 send_resp(dut, conn, SIGMA_COMPLETE,
1592 "BootstrapResult,OK,AuthResult,Timeout");
1593 goto out;
1594 }
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301595
1596 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf);
Jouni Malinen2e9c8a42017-11-19 12:06:18 +02001597 }
1598
Jouni Malinend86e5822017-08-29 03:55:32 +03001599 if (strstr(buf, "DPP-NOT-COMPATIBLE")) {
1600 send_resp(dut, conn, SIGMA_COMPLETE,
1601 "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE");
1602 goto out;
1603 }
1604
1605 if (!strstr(buf, "DPP-AUTH-SUCCESS")) {
1606 send_resp(dut, conn, SIGMA_COMPLETE,
1607 "BootstrapResult,OK,AuthResult,FAILED");
1608 goto out;
1609 }
1610
Jouni Malinen772299f2017-11-06 00:36:26 +02001611 if (frametype && strcasecmp(frametype, "ConfigurationRequest") == 0) {
1612 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE",
1613 buf, sizeof(buf));
1614 if (res < 0)
1615 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout";
1616 else
1617 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent";
1618 send_resp(dut, conn, SIGMA_COMPLETE, result);
1619 goto out;
1620 }
1621
1622 if (frametype && strcasecmp(frametype, "ConfigurationResponse") == 0) {
1623 res = get_wpa_cli_event(dut, ctrl, "DPP-CONF-SENT",
1624 buf, sizeof(buf));
1625 if (res < 0)
1626 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout";
1627 else
1628 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent";
1629 send_resp(dut, conn, SIGMA_COMPLETE, result);
1630 goto out;
1631 }
1632
Jouni Malinend86e5822017-08-29 03:55:32 +03001633 res = get_wpa_cli_events(dut, ctrl, conf_events, buf, sizeof(buf));
1634 if (res < 0) {
1635 send_resp(dut, conn, SIGMA_COMPLETE,
1636 "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout");
1637 goto out;
1638 }
1639 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP conf result: %s", buf);
1640
1641 if (!strstr(buf, "DPP-CONF-SENT") &&
1642 !strstr(buf, "DPP-CONF-RECEIVED")) {
1643 send_resp(dut, conn, SIGMA_COMPLETE,
1644 "BootstrapResult,OK,AuthResult,OK,ConfResult,FAILED");
1645 goto out;
1646 }
1647
1648 if (sigma_dut_is_ap(dut) &&
1649 strcasecmp(prov_role, "Enrollee") == 0) {
Jouni Malinen174db642017-11-27 20:16:29 +02001650 update_ap:
Jouni Malinend86e5822017-08-29 03:55:32 +03001651 res = dpp_hostapd_conf_update(dut, conn, ifname, ctrl);
1652 if (res == 0)
1653 goto out;
1654 if (res < 0) {
1655 send_resp(dut, conn, SIGMA_ERROR, NULL);
1656 goto out;
1657 }
1658 }
1659
1660 if (strcasecmp(wait_conn, "Yes") == 0 &&
1661 !sigma_dut_is_ap(dut) &&
1662 strcasecmp(prov_role, "Enrollee") == 0) {
Jouni Malinenfbb268d2017-11-17 18:53:49 +02001663 wait_connect:
Jouni Malinen53558e02017-11-06 12:58:28 +02001664 if (frametype && strcasecmp(frametype,
1665 "PeerDiscoveryRequest") == 0) {
1666 if (dpp_wait_tx_status(dut, ctrl, 5) < 0)
1667 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout";
1668 else
1669 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent";
1670 send_resp(dut, conn, SIGMA_COMPLETE, result);
1671 goto out;
1672 }
1673
Jouni Malinend86e5822017-08-29 03:55:32 +03001674 res = get_wpa_cli_events(dut, ctrl, conn_events,
1675 buf, sizeof(buf));
1676 if (res < 0) {
1677 send_resp(dut, conn, SIGMA_COMPLETE,
1678 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout,NetworkConnectResult,Timeout");
1679 goto out;
1680 }
1681 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP connect result: %s",
1682 buf);
1683
1684 if (strstr(buf, "PMKSA-CACHE-ADDED")) {
1685 res = get_wpa_cli_events(dut, ctrl, conn_events,
1686 buf, sizeof(buf));
1687 if (res < 0) {
1688 send_resp(dut, conn, SIGMA_COMPLETE,
1689 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,Timeout");
1690 goto out;
1691 }
1692 sigma_dut_print(dut, DUT_MSG_DEBUG,
1693 "DPP connect result: %s", buf);
1694 if (strstr(buf, "CTRL-EVENT-CONNECTED"))
1695 send_resp(dut, conn, SIGMA_COMPLETE,
1696 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK");
1697 else
1698 send_resp(dut, conn, SIGMA_COMPLETE,
1699 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,Timeout");
1700 goto out;
1701 }
1702
1703 send_resp(dut, conn, SIGMA_COMPLETE,
1704 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK");
1705 goto out;
1706 }
1707
Jouni Malinen53558e02017-11-06 12:58:28 +02001708 if (strcasecmp(wait_conn, "Yes") == 0 &&
1709 frametype && strcasecmp(frametype, "PeerDiscoveryResponse") == 0) {
1710 if (dpp_wait_tx_status(dut, ctrl, 6) < 0)
1711 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout";
1712 else
1713 result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent";
1714 send_resp(dut, conn, SIGMA_COMPLETE, result);
1715 goto out;
1716 }
1717
Jouni Malinend86e5822017-08-29 03:55:32 +03001718 send_resp(dut, conn, SIGMA_COMPLETE,
1719 "BootstrapResult,OK,AuthResult,OK,ConfResult,OK");
1720out:
1721 wpa_ctrl_detach(ctrl);
1722 wpa_ctrl_close(ctrl);
1723 dut->default_timeout = old_timeout;
1724 return 0;
1725}
1726
1727
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301728static int dpp_manual_dpp(struct sigma_dut *dut,
1729 struct sigma_conn *conn,
1730 struct sigma_cmd *cmd)
1731{
1732 const char *auth_role = get_param(cmd, "DPPAuthRole");
1733 int res = -1, success;
1734 const char *val;
1735 unsigned int old_timeout;
1736
1737 if (!auth_role) {
1738 send_resp(dut, conn, SIGMA_ERROR,
1739 "errorCode,Missing DPPAuthRole");
1740 return 0;
1741 }
1742
1743 old_timeout = dut->default_timeout;
1744 val = get_param(cmd, "DPPTimeout");
1745 if (val && atoi(val) > 0) {
1746 dut->default_timeout = atoi(val);
1747 sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP timeout: %u",
1748 dut->default_timeout);
1749 }
1750
1751 res = dpp_get_local_bootstrap(dut, conn, cmd, 0, &success);
1752 if (res || !success)
1753 goto out;
1754
1755 if (strcasecmp(auth_role, "Responder") == 0) {
1756 res = dpp_display_own_qrcode(dut);
1757 if (res < 0)
1758 goto out;
1759
1760 res = dpp_automatic_dpp(dut, conn, cmd);
1761 goto out;
1762 }
1763
1764 if (strcasecmp(auth_role, "Initiator") == 0) {
1765 res = dpp_scan_peer_qrcode(dut);
Jouni Malinen1a38cc32018-01-05 20:59:00 +02001766 if (res < 0) {
1767 send_resp(dut, conn, SIGMA_ERROR,
1768 "errorCode,Failed to scan peer QR Code");
1769 res = 0;
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301770 goto out;
Jouni Malinen1a38cc32018-01-05 20:59:00 +02001771 }
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301772
1773 res = dpp_automatic_dpp(dut, conn, cmd);
1774 goto out;
1775 }
1776
1777 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unknown DPPAuthRole");
1778 res = 0;
1779out:
1780 dut->default_timeout = old_timeout;
1781 return res;
1782}
1783
1784
Jouni Malinend86e5822017-08-29 03:55:32 +03001785int dpp_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1786 struct sigma_cmd *cmd)
1787{
1788 const char *type = get_param(cmd, "DPPActionType");
1789 const char *bs = get_param(cmd, "DPPBS");
1790
1791 if (!bs) {
1792 send_resp(dut, conn, SIGMA_ERROR,
1793 "errorCode,Missing DPPBS");
1794 return 0;
1795 }
1796
1797 if (!type) {
1798 send_resp(dut, conn, SIGMA_ERROR,
1799 "errorCode,Missing DPPActionType");
1800 return 0;
1801 }
1802
1803 if (strcasecmp(type, "GetLocalBootstrap") == 0)
Srinivas Dasaribc9e0552018-01-04 19:24:28 +05301804 return dpp_get_local_bootstrap(dut, conn, cmd, 1, NULL);
Jouni Malinend86e5822017-08-29 03:55:32 +03001805 if (strcasecmp(type, "SetPeerBootstrap") == 0)
1806 return dpp_set_peer_bootstrap(dut, conn, cmd);
1807 if (strcasecmp(type, "ManualDPP") == 0)
1808 return dpp_manual_dpp(dut, conn, cmd);
1809 if (strcasecmp(type, "AutomaticDPP") == 0)
1810 return dpp_automatic_dpp(dut, conn, cmd);
1811
1812 send_resp(dut, conn, SIGMA_ERROR,
1813 "errorCode,Unsupported DPPActionType");
1814 return 0;
1815}