Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (station/AP/sniffer) |
| 3 | * Copyright (c) 2017, Qualcomm Atheros, Inc. |
Jouni Malinen | c12ea4a | 2018-01-05 21:07:10 +0200 | [diff] [blame] | 4 | * Copyright (c) 2018, The Linux Foundation |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 5 | * All Rights Reserved. |
| 6 | * Licensed under the Clear BSD license. See README for more details. |
| 7 | */ |
| 8 | |
| 9 | #include "sigma_dut.h" |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 10 | #include <sys/wait.h> |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 11 | #include "wpa_ctrl.h" |
| 12 | #include "wpa_helpers.h" |
| 13 | |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 14 | #ifdef ANDROID |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 15 | char *dpp_qrcode_file = "/sdcard/wpadebug_qrdata.txt"; |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 16 | #endif /* ANDROID */ |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 17 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 18 | |
| 19 | static 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 | |
| 27 | static 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 gowthaman | 9149afc | 2018-01-15 13:40:18 -0800 | [diff] [blame] | 35 | if (!dut->ap_oper_chn) |
| 36 | dut->ap_channel = 11; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 37 | dut->ap_is_dual = 0; |
| 38 | dut->ap_mode = AP_11ng; |
| 39 | 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 | |
| 45 | static 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 | |
| 62 | static int dpp_get_local_bootstrap(struct sigma_dut *dut, |
| 63 | struct sigma_conn *conn, |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 64 | struct sigma_cmd *cmd, int send_result, |
| 65 | int *success) |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 66 | { |
| 67 | const char *curve = dpp_get_curve(cmd, "DPPCryptoIdentifier"); |
| 68 | const char *bs = get_param(cmd, "DPPBS"); |
Jouni Malinen | 4161c3f | 2017-11-13 18:36:09 +0200 | [diff] [blame] | 69 | const char *chan_list = get_param(cmd, "DPPChannelList"); |
| 70 | char *pos, mac[50], buf[200], resp[1000], hex[2000]; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 71 | const char *ifname = get_station_ifname(); |
| 72 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 73 | if (success) |
| 74 | *success = 0; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 75 | 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 112 | 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 Malinen | 4161c3f | 2017-11-13 18:36:09 +0200 | [diff] [blame] | 118 | 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 143 | 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 Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 156 | |
| 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | static 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 Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 174 | char uri[1000]; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 175 | int res; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 176 | |
| 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 Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 188 | free(dut->dpp_peer_uri); |
| 189 | dut->dpp_peer_uri = strdup(uri); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 190 | |
| 191 | return 1; |
| 192 | } |
| 193 | |
| 194 | |
| 195 | static 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 Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 201 | const char *conf_data_events[] = { |
| 202 | "DPP-CONNECTOR", |
| 203 | "DPP-CONFOBJ-PASS", |
| 204 | "DPP-CONFOBJ-PSK", |
| 205 | NULL |
| 206 | }; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 207 | |
| 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 Malinen | 0d34723 | 2017-11-01 17:14:00 +0200 | [diff] [blame] | 213 | wpa_command(ifname, "SET ieee80211w 1") < 0 || |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 214 | 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 Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 240 | res = get_wpa_cli_events(dut, ctrl, conf_data_events, buf, sizeof(buf)); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 241 | if (res < 0) { |
| 242 | send_resp(dut, conn, SIGMA_ERROR, |
Jouni Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 243 | "errorCode,No DPP-CONNECTOR/DPP-CONFOBJ-PASS/PSK"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 244 | goto out; |
| 245 | } |
Jouni Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 246 | |
| 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 Malinen | fddb7ea | 2018-01-05 21:02:50 +0200 | [diff] [blame] | 263 | if (pass_len < 0 || (size_t) pass_len >= sizeof(pass)) |
Jouni Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 264 | 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 289 | 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 312 | 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 Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 319 | |
| 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 Malinen | b4c5e3b | 2017-09-15 17:43:20 +0300 | [diff] [blame] | 352 | skip_dpp_akm: |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 353 | |
| 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; |
| 368 | out: |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 373 | struct dpp_test_info { |
| 374 | const char *step; |
| 375 | const char *frame; |
| 376 | const char *attr; |
| 377 | int value; |
| 378 | }; |
| 379 | |
| 380 | static const struct dpp_test_info dpp_tests[] = { |
| 381 | { "InvalidValue", "AuthenticationRequest", "WrappedData", 1 }, |
| 382 | { "InvalidValue", "AuthenticationResponse", "WrappedData", 2 }, |
Jouni Malinen | f96fcee | 2017-11-22 16:08:35 +0200 | [diff] [blame] | 383 | { "InvalidValue", "AuthenticationResponse", "PrimaryWrappedData", 2 }, |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 384 | { "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 Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 390 | { "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 Malinen | f96fcee | 2017-11-22 16:08:35 +0200 | [diff] [blame] | 406 | { "MissingAttribute", "AuthenticationResponse", "PrimaryWrappedData", |
| 407 | 24 }, |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 408 | { "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 Malinen | 53558e0 | 2017-11-06 12:58:28 +0200 | [diff] [blame] | 443 | { "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 Malinen | ae62448 | 2017-11-19 00:13:51 +0200 | [diff] [blame] | 448 | { "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 Malinen | 67795a7 | 2017-11-22 16:24:43 +0200 | [diff] [blame] | 463 | { "InvalidValue", "AuthenticationRequest", "InitNonce", 81 }, |
Jouni Malinen | 188839b | 2017-11-30 22:02:02 +0200 | [diff] [blame] | 464 | { "InvalidValue", "PeerDiscoveryRequest", "TransactionID", 82 }, |
| 465 | { "InvalidValue", "ConfigurationRequest", "EnrolleeNonce", 83 }, |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 466 | { "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 Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 473 | { NULL, NULL, NULL, 0 } |
| 474 | }; |
| 475 | |
| 476 | |
| 477 | static 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 Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 484 | ((!attr && dpp_tests[i].attr == NULL) || |
| 485 | (attr && strcasecmp(attr, dpp_tests[i].attr) == 0))) |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 486 | return dpp_tests[i].value; |
| 487 | } |
| 488 | |
| 489 | return -1; |
| 490 | } |
| 491 | |
| 492 | |
Jouni Malinen | 6792ff4 | 2018-02-13 00:25:56 +0200 | [diff] [blame] | 493 | static 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 Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 512 | static 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 Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 536 | static int dpp_wait_rx(struct sigma_dut *dut, struct wpa_ctrl *ctrl, |
Jouni Malinen | 3e4344e | 2018-01-22 11:47:37 +0200 | [diff] [blame] | 537 | int frame_type, unsigned int max_wait) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 538 | { |
| 539 | char buf[200], tmp[20]; |
| 540 | int res; |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 541 | 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 Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 546 | |
| 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 Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 550 | if (res < 0) { |
| 551 | dut->default_timeout = old_timeout; |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 552 | return -1; |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 553 | } |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 554 | if (strstr(buf, tmp) != NULL) |
| 555 | break; |
| 556 | } |
| 557 | |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 558 | dut->default_timeout = old_timeout; |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | |
| 563 | static int dpp_wait_rx_conf_req(struct sigma_dut *dut, struct wpa_ctrl *ctrl, |
Jouni Malinen | 3e4344e | 2018-01-22 11:47:37 +0200 | [diff] [blame] | 564 | unsigned int max_wait) |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 565 | { |
| 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 Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 590 | static int dpp_scan_peer_qrcode(struct sigma_dut *dut) |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 591 | { |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 592 | #ifdef ANDROID |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 593 | 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), |
| 602 | "am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeScannerActivity"); |
| 603 | if (system(buf) != 0) { |
| 604 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to launch Scanner"); |
| 605 | return -1; |
| 606 | } |
| 607 | |
| 608 | count = 0; |
| 609 | while (!(fp = fopen(dpp_qrcode_file, "r"))) { |
| 610 | if (count > dut->default_timeout) { |
| 611 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 612 | "Failed to open dpp_qrcode_file - QR Code scanning timed out"); |
| 613 | return -1; |
| 614 | } |
| 615 | |
| 616 | sleep(1); |
| 617 | count++; |
| 618 | } |
| 619 | |
| 620 | if (fseek(fp, 0, SEEK_END) < 0 || (length = ftell(fp)) <= 0 || |
| 621 | fseek(fp, 0, SEEK_SET) < 0) { |
| 622 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 623 | "Failed to get QR Code result file length"); |
| 624 | fclose(fp); |
| 625 | return -1; |
| 626 | } |
| 627 | |
| 628 | buf2 = malloc(length + 1); |
| 629 | if (!buf2) { |
| 630 | fclose(fp); |
| 631 | return -1; |
| 632 | } |
| 633 | |
| 634 | if (fread(buf2, 1, length, fp) != length) { |
| 635 | fclose(fp); |
| 636 | free(buf2); |
| 637 | return -1; |
| 638 | } |
| 639 | |
| 640 | fclose(fp); |
| 641 | buf2[length] = '\0'; |
| 642 | |
| 643 | free(dut->dpp_peer_uri); |
| 644 | dut->dpp_peer_uri = strdup(buf2); |
| 645 | free(buf2); |
| 646 | return 0; |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 647 | #else /* ANDROID */ |
| 648 | pid_t pid; |
| 649 | int pid_status; |
| 650 | int pipe_out[2]; |
| 651 | char buf[4000], *pos; |
| 652 | ssize_t len; |
| 653 | int res = -1, ret; |
| 654 | struct timeval tv; |
| 655 | fd_set rfd; |
| 656 | |
| 657 | if (pipe(pipe_out) != 0) { |
| 658 | perror("pipe"); |
| 659 | return -1; |
| 660 | } |
| 661 | |
| 662 | pid = fork(); |
| 663 | if (pid < 0) { |
| 664 | perror("fork"); |
| 665 | close(pipe_out[0]); |
| 666 | close(pipe_out[1]); |
| 667 | return -1; |
| 668 | } |
| 669 | |
| 670 | if (pid == 0) { |
| 671 | char *argv[4] = { "zbarcam", "--raw", "--prescale=320x240", |
| 672 | NULL }; |
| 673 | |
| 674 | dup2(pipe_out[1], STDOUT_FILENO); |
| 675 | close(pipe_out[0]); |
| 676 | close(pipe_out[1]); |
| 677 | execv("/usr/bin/zbarcam", argv); |
| 678 | perror("execv"); |
| 679 | exit(0); |
| 680 | return -1; |
| 681 | } |
| 682 | |
| 683 | close(pipe_out[1]); |
| 684 | |
| 685 | FD_ZERO(&rfd); |
| 686 | FD_SET(pipe_out[0], &rfd); |
| 687 | tv.tv_sec = dut->default_timeout; |
| 688 | tv.tv_usec = 0; |
| 689 | |
| 690 | ret = select(pipe_out[0] + 1, &rfd, NULL, NULL, &tv); |
| 691 | if (ret < 0) { |
| 692 | perror("select"); |
| 693 | goto out; |
| 694 | } |
| 695 | if (ret == 0) { |
| 696 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 697 | "QR Code scanning timed out"); |
| 698 | goto out; |
| 699 | } |
| 700 | |
| 701 | len = read(pipe_out[0], buf, sizeof(buf)); |
| 702 | if (len <= 0) |
| 703 | goto out; |
| 704 | if (len == sizeof(buf)) |
| 705 | len--; |
| 706 | buf[len] = '\0'; |
| 707 | pos = strchr(buf, '\n'); |
| 708 | if (pos) |
| 709 | *pos = '\0'; |
| 710 | sigma_dut_print(dut, DUT_MSG_DEBUG, "URI from QR scanner: %s", buf); |
| 711 | |
| 712 | free(dut->dpp_peer_uri); |
| 713 | dut->dpp_peer_uri = strdup(buf); |
| 714 | res = 0; |
| 715 | out: |
| 716 | close(pipe_out[0]); |
| 717 | kill(pid, SIGTERM); |
| 718 | waitpid(pid, &pid_status, 0); |
| 719 | |
| 720 | return res; |
| 721 | #endif /* ANDROID */ |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
| 725 | static int dpp_display_own_qrcode(struct sigma_dut *dut) |
| 726 | { |
| 727 | char buf[200], resp[2000]; |
| 728 | const char *ifname = get_station_ifname(); |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 729 | #ifdef ANDROID |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 730 | FILE *fp; |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 731 | #else /* ANDROID */ |
| 732 | pid_t pid; |
| 733 | int pid_status; |
| 734 | #endif /* ANDROID */ |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 735 | |
| 736 | snprintf(buf, sizeof(buf), "DPP_BOOTSTRAP_GET_URI %d", |
| 737 | dut->dpp_local_bootstrap); |
| 738 | if (wpa_command_resp(ifname, buf, resp, sizeof(resp)) < 0 || |
| 739 | strncmp(resp, "FAIL", 4) == 0) |
| 740 | return -2; |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 741 | sigma_dut_print(dut, DUT_MSG_DEBUG, "Own bootstrap URI: %s", resp); |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 742 | |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 743 | #ifdef ANDROID |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 744 | unlink(dpp_qrcode_file); |
| 745 | |
| 746 | fp = fopen(dpp_qrcode_file, "w"); |
| 747 | if (!fp) { |
| 748 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open file %s", |
| 749 | dpp_qrcode_file); |
| 750 | return -2; |
| 751 | } |
| 752 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 753 | fwrite(resp, 1, strlen(resp), fp); |
| 754 | fclose(fp); |
| 755 | |
| 756 | snprintf(buf, sizeof(buf), |
| 757 | "am start -n w1.fi.wpadebug/w1.fi.wpadebug.QrCodeDisplayActivity"); |
| 758 | if (system(buf) != 0) { |
| 759 | sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to display QR Code"); |
| 760 | return -1; |
| 761 | } |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 762 | #else /* ANDROID */ |
| 763 | pid = fork(); |
| 764 | if (pid < 0) { |
| 765 | perror("fork"); |
| 766 | return -1; |
| 767 | } |
| 768 | |
| 769 | if (pid == 0) { |
| 770 | char *argv[3] = { "qr", resp, NULL }; |
| 771 | |
| 772 | execv("/usr/bin/qr", argv); |
| 773 | perror("execv"); |
| 774 | exit(0); |
| 775 | return -1; |
| 776 | } |
| 777 | |
| 778 | waitpid(pid, &pid_status, 0); |
| 779 | #endif /* ANDROID */ |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 780 | |
| 781 | return 0; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
| 785 | static int dpp_automatic_dpp(struct sigma_dut *dut, |
| 786 | struct sigma_conn *conn, |
| 787 | struct sigma_cmd *cmd) |
| 788 | { |
| 789 | const char *bs = get_param(cmd, "DPPBS"); |
| 790 | const char *auth_role = get_param(cmd, "DPPAuthRole"); |
| 791 | const char *prov_role = get_param(cmd, "DPPProvisioningRole"); |
| 792 | const char *pkex_code = get_param(cmd, "DPPPKEXCode"); |
| 793 | const char *pkex_code_id = get_param(cmd, "DPPPKEXCodeIdentifier"); |
| 794 | const char *wait_conn = get_param(cmd, "DPPWaitForConnect"); |
| 795 | const char *self_conf = get_param(cmd, "DPPSelfConfigure"); |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 796 | const char *step = get_param(cmd, "DPPStep"); |
| 797 | const char *frametype = get_param(cmd, "DPPFrameType"); |
| 798 | const char *attr = get_param(cmd, "DPPIEAttribute"); |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 799 | const char *action_type = get_param(cmd, "DPPActionType"); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 800 | const char *role; |
| 801 | const char *val; |
| 802 | const char *conf_role; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 803 | int conf_index = -1; |
| 804 | char buf[2000]; |
| 805 | char conf_ssid[100]; |
| 806 | char conf_pass[100]; |
| 807 | char pkex_identifier[200]; |
| 808 | struct wpa_ctrl *ctrl; |
| 809 | int res; |
| 810 | unsigned int old_timeout; |
| 811 | int own_pkex_id = -1; |
| 812 | const char *ifname = get_station_ifname(); |
| 813 | const char *auth_events[] = { |
| 814 | "DPP-AUTH-SUCCESS", |
| 815 | "DPP-NOT-COMPATIBLE", |
| 816 | "DPP-RESPONSE-PENDING", |
| 817 | "DPP-SCAN-PEER-QR-CODE", |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 818 | "DPP-AUTH-DIRECTION", |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 819 | NULL |
| 820 | }; |
| 821 | const char *conf_events[] = { |
| 822 | "DPP-CONF-RECEIVED", |
| 823 | "DPP-CONF-SENT", |
| 824 | "DPP-CONF-FAILED", |
| 825 | NULL |
| 826 | }; |
| 827 | const char *conn_events[] = { |
| 828 | "PMKSA-CACHE-ADDED", |
| 829 | "CTRL-EVENT-CONNECTED", |
| 830 | NULL |
| 831 | }; |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 832 | const char *groups_override = NULL; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 833 | const char *result; |
Jouni Malinen | d1e22f7 | 2017-12-05 21:12:17 +0200 | [diff] [blame] | 834 | int check_mutual = 0; |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 835 | int enrollee_ap; |
Jouni Malinen | f2fa0d0 | 2018-01-11 20:51:31 +0200 | [diff] [blame] | 836 | int force_gas_fragm = 0; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 837 | |
| 838 | if (!wait_conn) |
| 839 | wait_conn = "no"; |
| 840 | if (!self_conf) |
| 841 | self_conf = "no"; |
| 842 | |
| 843 | if (!auth_role) { |
| 844 | send_resp(dut, conn, SIGMA_ERROR, |
| 845 | "errorCode,Missing DPPAuthRole"); |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | if (!prov_role) { |
| 850 | send_resp(dut, conn, SIGMA_ERROR, |
| 851 | "errorCode,Missing DPPProvisioningRole"); |
| 852 | return 0; |
| 853 | } |
| 854 | |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 855 | val = get_param(cmd, "DPPConfEnrolleeRole"); |
| 856 | if (val) |
| 857 | enrollee_ap = strcasecmp(val, "AP") == 0; |
| 858 | else |
| 859 | enrollee_ap = sigma_dut_is_ap(dut); |
| 860 | |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 861 | if ((step || frametype) && (!step || !frametype)) { |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 862 | send_resp(dut, conn, SIGMA_ERROR, |
| 863 | "errorCode,Invalid DPPStep,DPPFrameType,DPPIEAttribute combination"); |
| 864 | return 0; |
| 865 | } |
| 866 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 867 | if (sigma_dut_is_ap(dut)) { |
| 868 | if (!dut->hostapd_ifname) { |
| 869 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 870 | "hostapd ifname not specified (-j)"); |
| 871 | return -2; |
| 872 | } |
| 873 | ifname = dut->hostapd_ifname; |
| 874 | |
| 875 | if (dpp_hostapd_run(dut) < 0) { |
| 876 | send_resp(dut, conn, SIGMA_ERROR, |
| 877 | "errorCode,Failed to start hostapd"); |
| 878 | return 0; |
| 879 | } |
| 880 | } |
| 881 | |
Jouni Malinen | 67acb0c | 2017-11-21 01:01:54 +0200 | [diff] [blame] | 882 | if (strcasecmp(prov_role, "Configurator") == 0 || |
| 883 | strcasecmp(prov_role, "Both") == 0) { |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 884 | if (dut->dpp_conf_id < 0) { |
| 885 | snprintf(buf, sizeof(buf), |
| 886 | "DPP_CONFIGURATOR_ADD curve=%s", |
| 887 | dpp_get_curve(cmd, "DPPSigningKeyECC")); |
| 888 | if (wpa_command_resp(ifname, buf, |
| 889 | buf, sizeof(buf)) < 0) { |
| 890 | send_resp(dut, conn, SIGMA_ERROR, |
| 891 | "errorCode,Failed to set up configurator"); |
| 892 | return 0; |
| 893 | } |
| 894 | dut->dpp_conf_id = atoi(buf); |
| 895 | } |
Jouni Malinen | 67acb0c | 2017-11-21 01:01:54 +0200 | [diff] [blame] | 896 | if (strcasecmp(prov_role, "Configurator") == 0) |
| 897 | role = "configurator"; |
| 898 | else |
| 899 | role = "either"; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 900 | } else if (strcasecmp(prov_role, "Enrollee") == 0) { |
| 901 | role = "enrollee"; |
| 902 | } else { |
| 903 | send_resp(dut, conn, SIGMA_ERROR, |
| 904 | "errorCode,Unknown DPPProvisioningRole"); |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | pkex_identifier[0] = '\0'; |
| 909 | if (strcasecmp(bs, "PKEX") == 0) { |
Jouni Malinen | 4f47a27 | 2017-11-04 12:29:11 +0200 | [diff] [blame] | 910 | if (sigma_dut_is_ap(dut) && dut->ap_channel != 6) { |
| 911 | /* For now, have to make operating channel match DPP |
| 912 | * listen channel. This should be removed once hostapd |
| 913 | * has support for DPP listen on non-operating channel. |
| 914 | */ |
| 915 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 916 | "Update hostapd operating channel to match listen needs"); |
| 917 | dut->ap_channel = 6; |
priyadharshini gowthaman | b4de196 | 2018-01-15 12:21:04 -0800 | [diff] [blame] | 918 | |
| 919 | if (get_driver_type() == DRIVER_OPENWRT) { |
| 920 | snprintf(buf, sizeof(buf), |
| 921 | "iwconfig %s channel %d", |
| 922 | dut->hostapd_ifname, dut->ap_channel); |
| 923 | run_system(dut, buf); |
| 924 | } |
| 925 | |
Jouni Malinen | 4f47a27 | 2017-11-04 12:29:11 +0200 | [diff] [blame] | 926 | if (wpa_command(ifname, "SET channel 6") < 0 || |
| 927 | wpa_command(ifname, "DISABLE") < 0 || |
| 928 | wpa_command(ifname, "ENABLE") < 0) { |
| 929 | send_resp(dut, conn, SIGMA_ERROR, |
| 930 | "errorCode,Failed to update channel"); |
| 931 | return 0; |
| 932 | } |
| 933 | } |
| 934 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 935 | if (!pkex_code) { |
| 936 | send_resp(dut, conn, SIGMA_ERROR, |
| 937 | "errorCode,Missing DPPPKEXCode"); |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | if (pkex_code_id) |
| 942 | snprintf(pkex_identifier, sizeof(pkex_identifier), |
| 943 | "identifier=%s ", pkex_code_id); |
| 944 | |
| 945 | snprintf(buf, sizeof(buf), |
| 946 | "DPP_BOOTSTRAP_GEN type=pkex curve=%s", |
| 947 | dpp_get_curve(cmd, "DPPCryptoIdentifier")); |
| 948 | if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0) { |
| 949 | send_resp(dut, conn, SIGMA_ERROR, |
| 950 | "errorCode,Failed to set up PKEX"); |
| 951 | return 0; |
| 952 | } |
| 953 | own_pkex_id = atoi(buf); |
| 954 | } |
| 955 | |
| 956 | ctrl = open_wpa_mon(ifname); |
| 957 | if (!ctrl) { |
| 958 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 959 | "Failed to open wpa_supplicant monitor connection"); |
| 960 | return -2; |
| 961 | } |
| 962 | |
| 963 | old_timeout = dut->default_timeout; |
| 964 | val = get_param(cmd, "DPPTimeout"); |
| 965 | if (val && atoi(val) > 0) { |
| 966 | dut->default_timeout = atoi(val); |
| 967 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP timeout: %u", |
| 968 | dut->default_timeout); |
| 969 | } |
| 970 | |
| 971 | conf_ssid[0] = '\0'; |
| 972 | conf_pass[0] = '\0'; |
| 973 | val = get_param(cmd, "DPPConfIndex"); |
| 974 | if (val) |
| 975 | conf_index = atoi(val); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 976 | switch (conf_index) { |
Jouni Malinen | 258cc26 | 2017-10-13 00:19:56 +0300 | [diff] [blame] | 977 | case -1: |
| 978 | conf_role = NULL; |
| 979 | break; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 980 | case 1: |
| 981 | ascii2hexstr("DPPNET01", buf); |
| 982 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 983 | if (enrollee_ap) { |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 984 | conf_role = "ap-dpp"; |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 985 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"ap\"}]"; |
| 986 | } else { |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 987 | conf_role = "sta-dpp"; |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 988 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"sta\"}]"; |
| 989 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 990 | break; |
| 991 | case 2: |
| 992 | ascii2hexstr("DPPNET01", buf); |
| 993 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
Jouni Malinen | 8f81cdf | 2017-09-15 18:15:18 +0300 | [diff] [blame] | 994 | snprintf(conf_pass, sizeof(conf_pass), |
| 995 | "psk=10506e102ad1e7f95112f6b127675bb8344dacacea60403f3fa4055aec85b0fc"); |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 996 | if (enrollee_ap) |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 997 | conf_role = "ap-psk"; |
| 998 | else |
| 999 | conf_role = "sta-psk"; |
| 1000 | break; |
| 1001 | case 3: |
| 1002 | ascii2hexstr("DPPNET01", buf); |
| 1003 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
| 1004 | ascii2hexstr("ThisIsDppPassphrase", buf); |
| 1005 | snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf); |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 1006 | if (enrollee_ap) |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1007 | conf_role = "ap-psk"; |
| 1008 | else |
| 1009 | conf_role = "sta-psk"; |
| 1010 | break; |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 1011 | case 4: |
| 1012 | ascii2hexstr("DPPNET01", buf); |
| 1013 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
Jouni Malinen | e89cdbf | 2017-12-11 20:18:24 +0200 | [diff] [blame] | 1014 | if (enrollee_ap) { |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 1015 | conf_role = "ap-dpp"; |
| 1016 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA2\",\"netRole\":\"ap\"}]"; |
| 1017 | } else { |
| 1018 | conf_role = "sta-dpp"; |
| 1019 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA2\",\"netRole\":\"sta\"}]"; |
| 1020 | } |
| 1021 | break; |
Jouni Malinen | 7d031c7 | 2018-01-09 19:39:56 +0200 | [diff] [blame] | 1022 | case 5: |
| 1023 | ascii2hexstr("DPPNET01", buf); |
| 1024 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
| 1025 | ascii2hexstr("ThisIsDppPassphrase", buf); |
| 1026 | snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf); |
| 1027 | if (enrollee_ap) |
| 1028 | conf_role = "ap-sae"; |
| 1029 | else |
| 1030 | conf_role = "sta-sae"; |
| 1031 | break; |
| 1032 | case 6: |
| 1033 | ascii2hexstr("DPPNET01", buf); |
| 1034 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
| 1035 | ascii2hexstr("ThisIsDppPassphrase", buf); |
| 1036 | snprintf(conf_pass, sizeof(conf_pass), "pass=%s", buf); |
| 1037 | if (enrollee_ap) |
| 1038 | conf_role = "ap-psk-sae"; |
| 1039 | else |
| 1040 | conf_role = "sta-psk-sae"; |
| 1041 | break; |
Jouni Malinen | f2fa0d0 | 2018-01-11 20:51:31 +0200 | [diff] [blame] | 1042 | case 7: |
| 1043 | ascii2hexstr("DPPNET01", buf); |
| 1044 | snprintf(conf_ssid, sizeof(conf_ssid), "ssid=%s", buf); |
| 1045 | if (enrollee_ap) { |
| 1046 | conf_role = "ap-dpp"; |
| 1047 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"ap\"}]"; |
| 1048 | } else { |
| 1049 | conf_role = "sta-dpp"; |
| 1050 | groups_override = "[{\"groupId\":\"DPPGROUP_DPP_INFRA\",\"netRole\":\"sta\"}]"; |
| 1051 | } |
| 1052 | force_gas_fragm = 1; |
| 1053 | break; |
Jouni Malinen | f749076 | 2017-10-12 00:34:37 +0300 | [diff] [blame] | 1054 | default: |
| 1055 | send_resp(dut, conn, SIGMA_ERROR, |
| 1056 | "errorCode,Unsupported DPPConfIndex"); |
| 1057 | goto out; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1058 | } |
| 1059 | |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 1060 | if (groups_override) { |
Jouni Malinen | 2b2230f | 2018-02-12 13:05:06 +0200 | [diff] [blame] | 1061 | snprintf(buf, sizeof(buf), "SET dpp_groups_override %s", |
| 1062 | groups_override); |
Jouni Malinen | 3d291f7 | 2017-11-02 11:31:05 +0200 | [diff] [blame] | 1063 | if (wpa_command(ifname, buf) < 0) { |
| 1064 | send_resp(dut, conn, SIGMA_ERROR, |
| 1065 | "errorCode,Failed to set cred:groups"); |
| 1066 | goto out; |
| 1067 | } |
| 1068 | } |
| 1069 | |
Jouni Malinen | 2b2230f | 2018-02-12 13:05:06 +0200 | [diff] [blame] | 1070 | if (force_gas_fragm) { |
| 1071 | char spaces[1500]; |
| 1072 | |
| 1073 | memset(spaces, ' ', sizeof(spaces)); |
| 1074 | spaces[sizeof(spaces) - 1] = '\0'; |
| 1075 | |
| 1076 | snprintf(buf, sizeof(buf), |
| 1077 | "SET dpp_discovery_override {\"ssid\":\"DPPNET01\"}%s", |
| 1078 | spaces); |
| 1079 | if (wpa_command(ifname, buf) < 0) { |
| 1080 | send_resp(dut, conn, SIGMA_ERROR, |
| 1081 | "errorCode,Failed to set discovery override"); |
| 1082 | goto out; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1086 | if (step) { |
| 1087 | int test; |
| 1088 | |
| 1089 | test = dpp_get_test(step, frametype, attr); |
| 1090 | if (test <= 0) { |
| 1091 | send_resp(dut, conn, SIGMA_ERROR, |
| 1092 | "errorCode,Unsupported DPPStep/DPPFrameType/DPPIEAttribute"); |
| 1093 | goto out; |
| 1094 | } |
| 1095 | |
| 1096 | snprintf(buf, sizeof(buf), "SET dpp_test %d", test); |
| 1097 | if (wpa_command(ifname, buf) < 0) { |
| 1098 | send_resp(dut, conn, SIGMA_ERROR, |
| 1099 | "errorCode,Failed to set dpp_test"); |
| 1100 | goto out; |
| 1101 | } |
| 1102 | } else { |
| 1103 | wpa_command(ifname, "SET dpp_test 0"); |
| 1104 | } |
| 1105 | |
Jouni Malinen | fbb268d | 2017-11-17 18:53:49 +0200 | [diff] [blame] | 1106 | if (strcasecmp(self_conf, "Yes") == 0) { |
| 1107 | if (strcasecmp(prov_role, "Configurator") != 0) { |
| 1108 | send_resp(dut, conn, SIGMA_ERROR, |
| 1109 | "errorCode,Invalid DPPSelfConfigure use - only allowed for Configurator role"); |
| 1110 | goto out; |
| 1111 | } |
| 1112 | if (!conf_role) { |
| 1113 | send_resp(dut, conn, SIGMA_ERROR, |
| 1114 | "errorCode,Missing DPPConfIndex"); |
| 1115 | goto out; |
| 1116 | } |
| 1117 | |
| 1118 | snprintf(buf, sizeof(buf), |
| 1119 | "DPP_CONFIGURATOR_SIGN conf=%s %s %s configurator=%d", |
| 1120 | conf_role, conf_ssid, conf_pass, dut->dpp_conf_id); |
| 1121 | if (wpa_command(ifname, buf) < 0) { |
| 1122 | send_resp(dut, conn, SIGMA_ERROR, |
| 1123 | "errorCode,Failed to initiate DPP self-configuration"); |
| 1124 | goto out; |
| 1125 | } |
Jouni Malinen | 174db64 | 2017-11-27 20:16:29 +0200 | [diff] [blame] | 1126 | if (sigma_dut_is_ap(dut)) |
| 1127 | goto update_ap; |
Jouni Malinen | fbb268d | 2017-11-17 18:53:49 +0200 | [diff] [blame] | 1128 | goto wait_connect; |
| 1129 | } else if (strcasecmp(auth_role, "Initiator") == 0) { |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1130 | char own_txt[20]; |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1131 | int dpp_peer_bootstrap = -1; |
Jouni Malinen | b5ab828 | 2017-11-21 01:12:22 +0200 | [diff] [blame] | 1132 | char neg_freq[30]; |
| 1133 | |
Jouni Malinen | d1e22f7 | 2017-12-05 21:12:17 +0200 | [diff] [blame] | 1134 | val = get_param(cmd, "DPPAuthDirection"); |
| 1135 | check_mutual = val && strcasecmp(val, "Mutual") == 0; |
| 1136 | |
Jouni Malinen | b5ab828 | 2017-11-21 01:12:22 +0200 | [diff] [blame] | 1137 | neg_freq[0] = '\0'; |
| 1138 | val = get_param(cmd, "DPPSubsequentChannel"); |
| 1139 | if (val) { |
| 1140 | int opclass, channel, freq; |
| 1141 | |
| 1142 | opclass = atoi(val); |
| 1143 | val = strchr(val, '/'); |
| 1144 | if (opclass == 0 || !val) { |
| 1145 | send_resp(dut, conn, SIGMA_ERROR, |
| 1146 | "errorCode,Invalid DPPSubsequentChannel"); |
| 1147 | goto out; |
| 1148 | } |
| 1149 | val++; |
| 1150 | channel = atoi(val); |
| 1151 | |
| 1152 | /* Ignoring opclass for now; could use it here for more |
| 1153 | * robust frequency determination. */ |
| 1154 | freq = channel_to_freq(channel); |
| 1155 | if (!freq) { |
| 1156 | send_resp(dut, conn, SIGMA_ERROR, |
| 1157 | "errorCode,Unsupported DPPSubsequentChannel channel"); |
| 1158 | goto out; |
| 1159 | } |
| 1160 | snprintf(neg_freq, sizeof(neg_freq), " neg_freq=%d", |
| 1161 | freq); |
| 1162 | } |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1163 | |
| 1164 | if (strcasecmp(bs, "QR") == 0) { |
| 1165 | if (!dut->dpp_peer_uri) { |
| 1166 | send_resp(dut, conn, SIGMA_ERROR, |
| 1167 | "errorCode,Missing peer bootstrapping info"); |
| 1168 | goto out; |
| 1169 | } |
| 1170 | |
| 1171 | snprintf(buf, sizeof(buf), "DPP_QR_CODE %s", |
| 1172 | dut->dpp_peer_uri); |
| 1173 | if (wpa_command_resp(ifname, buf, buf, |
| 1174 | sizeof(buf)) < 0) { |
| 1175 | send_resp(dut, conn, SIGMA_ERROR, |
| 1176 | "errorCode,Failed to parse URI"); |
| 1177 | goto out; |
| 1178 | } |
| 1179 | dpp_peer_bootstrap = atoi(buf); |
| 1180 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1181 | |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 1182 | if (dut->dpp_local_bootstrap >= 0) |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1183 | snprintf(own_txt, sizeof(own_txt), " own=%d", |
| 1184 | dut->dpp_local_bootstrap); |
| 1185 | else |
| 1186 | own_txt[0] = '\0'; |
| 1187 | if (strcasecmp(bs, "QR") == 0 && |
Jouni Malinen | 67acb0c | 2017-11-21 01:01:54 +0200 | [diff] [blame] | 1188 | (strcasecmp(prov_role, "Configurator") == 0 || |
| 1189 | strcasecmp(prov_role, "Both") == 0)) { |
Jouni Malinen | 258cc26 | 2017-10-13 00:19:56 +0300 | [diff] [blame] | 1190 | if (!conf_role) { |
| 1191 | send_resp(dut, conn, SIGMA_ERROR, |
| 1192 | "errorCode,Missing DPPConfIndex"); |
| 1193 | goto out; |
| 1194 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1195 | snprintf(buf, sizeof(buf), |
Jouni Malinen | b5ab828 | 2017-11-21 01:12:22 +0200 | [diff] [blame] | 1196 | "DPP_AUTH_INIT peer=%d%s role=%s conf=%s %s %s configurator=%d%s", |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1197 | dpp_peer_bootstrap, own_txt, role, |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1198 | conf_role, conf_ssid, conf_pass, |
Jouni Malinen | b5ab828 | 2017-11-21 01:12:22 +0200 | [diff] [blame] | 1199 | dut->dpp_conf_id, neg_freq); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1200 | } else if (strcasecmp(bs, "QR") == 0) { |
| 1201 | snprintf(buf, sizeof(buf), |
Jouni Malinen | b5ab828 | 2017-11-21 01:12:22 +0200 | [diff] [blame] | 1202 | "DPP_AUTH_INIT peer=%d%s role=%s%s", |
| 1203 | dpp_peer_bootstrap, own_txt, role, neg_freq); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1204 | } else if (strcasecmp(bs, "PKEX") == 0 && |
Jouni Malinen | 67acb0c | 2017-11-21 01:01:54 +0200 | [diff] [blame] | 1205 | (strcasecmp(prov_role, "Configurator") == 0 || |
| 1206 | strcasecmp(prov_role, "Both") == 0)) { |
Jouni Malinen | 258cc26 | 2017-10-13 00:19:56 +0300 | [diff] [blame] | 1207 | if (!conf_role) { |
| 1208 | send_resp(dut, conn, SIGMA_ERROR, |
| 1209 | "errorCode,Missing DPPConfIndex"); |
| 1210 | goto out; |
| 1211 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1212 | snprintf(buf, sizeof(buf), |
| 1213 | "DPP_PKEX_ADD own=%d init=1 role=%s conf=%s %s %s configurator=%d %scode=%s", |
| 1214 | own_pkex_id, role, conf_role, |
| 1215 | conf_ssid, conf_pass, dut->dpp_conf_id, |
| 1216 | pkex_identifier, pkex_code); |
| 1217 | } else if (strcasecmp(bs, "PKEX") == 0) { |
| 1218 | snprintf(buf, sizeof(buf), |
| 1219 | "DPP_PKEX_ADD own=%d init=1 role=%s %scode=%s", |
| 1220 | own_pkex_id, role, pkex_identifier, pkex_code); |
Jouni Malinen | d551c6f | 2017-10-12 00:32:18 +0300 | [diff] [blame] | 1221 | } else { |
| 1222 | send_resp(dut, conn, SIGMA_ERROR, |
| 1223 | "errorCode,Unsupported DPPBS"); |
| 1224 | goto out; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1225 | } |
| 1226 | if (wpa_command(ifname, buf) < 0) { |
| 1227 | send_resp(dut, conn, SIGMA_ERROR, |
| 1228 | "errorCode,Failed to initiate DPP authentication"); |
| 1229 | goto out; |
| 1230 | } |
| 1231 | } else if (strcasecmp(auth_role, "Responder") == 0) { |
Jouni Malinen | 67f096a | 2017-11-24 11:58:51 +0200 | [diff] [blame] | 1232 | const char *delay_qr_resp; |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 1233 | int mutual; |
Jouni Malinen | d3afc5c | 2017-11-13 18:39:14 +0200 | [diff] [blame] | 1234 | int freq = 2462; /* default: channel 11 */ |
| 1235 | |
Jouni Malinen | 06cfcb3 | 2018-01-11 20:43:50 +0200 | [diff] [blame] | 1236 | if (strcasecmp(bs, "PKEX") == 0) { |
| 1237 | /* default: channel 6 for PKEX */ |
| 1238 | freq = 2437; |
| 1239 | } |
| 1240 | |
Jouni Malinen | 67f096a | 2017-11-24 11:58:51 +0200 | [diff] [blame] | 1241 | delay_qr_resp = get_param(cmd, "DPPDelayQRResponse"); |
| 1242 | |
Jouni Malinen | 63d5041 | 2017-11-24 11:55:38 +0200 | [diff] [blame] | 1243 | val = get_param(cmd, "DPPAuthDirection"); |
| 1244 | mutual = val && strcasecmp(val, "Mutual") == 0; |
| 1245 | |
Jouni Malinen | d3afc5c | 2017-11-13 18:39:14 +0200 | [diff] [blame] | 1246 | val = get_param(cmd, "DPPListenChannel"); |
| 1247 | if (val) { |
| 1248 | freq = channel_to_freq(atoi(val)); |
| 1249 | if (freq == 0) { |
| 1250 | send_resp(dut, conn, SIGMA_ERROR, |
| 1251 | "errorCode,Unsupported DPPListenChannel value"); |
| 1252 | goto out; |
| 1253 | } |
| 1254 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1255 | |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1256 | if (!delay_qr_resp && dut->dpp_peer_uri) { |
| 1257 | snprintf(buf, sizeof(buf), "DPP_QR_CODE %s", |
| 1258 | dut->dpp_peer_uri); |
| 1259 | if (wpa_command_resp(ifname, buf, buf, |
| 1260 | sizeof(buf)) < 0) { |
| 1261 | send_resp(dut, conn, SIGMA_ERROR, |
| 1262 | "errorCode,Failed to parse URI"); |
| 1263 | goto out; |
| 1264 | } |
| 1265 | } |
| 1266 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1267 | if (strcasecmp(prov_role, "Configurator") == 0) { |
Jouni Malinen | 258cc26 | 2017-10-13 00:19:56 +0300 | [diff] [blame] | 1268 | if (!conf_role) { |
| 1269 | send_resp(dut, conn, SIGMA_ERROR, |
| 1270 | "errorCode,Missing DPPConfIndex"); |
| 1271 | goto out; |
| 1272 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1273 | snprintf(buf, sizeof(buf), |
| 1274 | "SET dpp_configurator_params conf=%s %s %s configurator=%d", |
| 1275 | conf_role, conf_ssid, conf_pass, |
| 1276 | dut->dpp_conf_id); |
| 1277 | if (wpa_command(ifname, buf) < 0) { |
| 1278 | send_resp(dut, conn, SIGMA_ERROR, |
| 1279 | "errorCode,Failed to set configurator parameters"); |
| 1280 | goto out; |
| 1281 | } |
| 1282 | } |
| 1283 | if (strcasecmp(bs, "PKEX") == 0) { |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1284 | snprintf(buf, sizeof(buf), |
| 1285 | "DPP_PKEX_ADD own=%d role=%s %scode=%s", |
| 1286 | own_pkex_id, role, pkex_identifier, pkex_code); |
| 1287 | if (wpa_command(ifname, buf) < 0) { |
| 1288 | send_resp(dut, conn, SIGMA_ERROR, |
| 1289 | "errorCode,Failed to configure DPP PKEX"); |
| 1290 | goto out; |
| 1291 | } |
| 1292 | } |
| 1293 | |
Jouni Malinen | bafc193 | 2017-11-04 11:31:16 +0200 | [diff] [blame] | 1294 | snprintf(buf, sizeof(buf), "DPP_LISTEN %d role=%s%s", |
| 1295 | freq, role, |
| 1296 | (strcasecmp(bs, "QR") == 0 && mutual) ? |
| 1297 | " qr=mutual" : ""); |
| 1298 | if (wpa_command(ifname, buf) < 0) { |
| 1299 | send_resp(dut, conn, SIGMA_ERROR, |
| 1300 | "errorCode,Failed to start DPP listen"); |
| 1301 | goto out; |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1302 | } |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1303 | |
priyadharshini gowthaman | b4de196 | 2018-01-15 12:21:04 -0800 | [diff] [blame] | 1304 | if (get_driver_type() == DRIVER_OPENWRT) { |
| 1305 | snprintf(buf, sizeof(buf), "iwconfig %s channel %d", |
| 1306 | dut->hostapd_ifname, freq_to_channel(freq)); |
| 1307 | run_system(dut, buf); |
| 1308 | } |
| 1309 | |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1310 | if (delay_qr_resp && mutual && dut->dpp_peer_uri) { |
| 1311 | int wait_time = atoi(delay_qr_resp); |
| 1312 | |
| 1313 | res = get_wpa_cli_events(dut, ctrl, auth_events, |
| 1314 | buf, sizeof(buf)); |
| 1315 | if (res < 0) { |
| 1316 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1317 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1318 | goto out; |
| 1319 | } |
| 1320 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1321 | "DPP auth result: %s", buf); |
| 1322 | if (strstr(buf, "DPP-SCAN-PEER-QR-CODE") == NULL) { |
| 1323 | send_resp(dut, conn, SIGMA_ERROR, |
| 1324 | "errorCode,No scan request for peer QR Code seen"); |
| 1325 | goto out; |
| 1326 | } |
| 1327 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 1328 | "Waiting %d second(s) before processing peer URI", |
| 1329 | wait_time); |
| 1330 | sleep(wait_time); |
| 1331 | |
| 1332 | snprintf(buf, sizeof(buf), "DPP_QR_CODE %s", |
| 1333 | dut->dpp_peer_uri); |
| 1334 | if (wpa_command_resp(ifname, buf, buf, |
| 1335 | sizeof(buf)) < 0) { |
| 1336 | send_resp(dut, conn, SIGMA_ERROR, |
| 1337 | "errorCode,Failed to parse URI"); |
| 1338 | goto out; |
| 1339 | } |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1340 | } else if (mutual && action_type && |
| 1341 | strcasecmp(action_type, "ManualDPP") == 0) { |
| 1342 | res = get_wpa_cli_events(dut, ctrl, auth_events, |
| 1343 | buf, sizeof(buf)); |
| 1344 | if (res < 0) { |
| 1345 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1346 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1347 | goto out; |
| 1348 | } |
| 1349 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1350 | "DPP auth result: %s", buf); |
| 1351 | if (strstr(buf, "DPP-SCAN-PEER-QR-CODE") == NULL) { |
| 1352 | send_resp(dut, conn, SIGMA_ERROR, |
| 1353 | "errorCode,No scan request for peer QR Code seen"); |
| 1354 | goto out; |
| 1355 | } |
| 1356 | |
| 1357 | if (dpp_scan_peer_qrcode(dut) < 0) { |
| 1358 | send_resp(dut, conn, SIGMA_ERROR, |
| 1359 | "errorCode,Failed to scan peer QR Code"); |
| 1360 | goto out; |
| 1361 | } |
| 1362 | |
| 1363 | snprintf(buf, sizeof(buf), "DPP_QR_CODE %s", |
| 1364 | dut->dpp_peer_uri); |
| 1365 | if (wpa_command_resp(ifname, buf, buf, |
| 1366 | sizeof(buf)) < 0) { |
| 1367 | send_resp(dut, conn, SIGMA_ERROR, |
| 1368 | "errorCode,Failed to parse URI"); |
| 1369 | goto out; |
| 1370 | } |
Jouni Malinen | b1dd21f | 2017-11-13 19:14:29 +0200 | [diff] [blame] | 1371 | } |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1372 | } else { |
| 1373 | send_resp(dut, conn, SIGMA_ERROR, |
| 1374 | "errorCode,Unknown DPPAuthRole"); |
| 1375 | goto out; |
| 1376 | } |
| 1377 | |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1378 | if (step && strcasecmp(step, "Timeout") == 0) { |
| 1379 | result = "errorCode,Unexpected state"; |
| 1380 | |
| 1381 | if (strcasecmp(frametype, "PKEXExchangeResponse") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1382 | if (dpp_wait_rx(dut, ctrl, 8, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1383 | result = "BootstrapResult,Timeout"; |
| 1384 | else |
| 1385 | result = "BootstrapResult,Errorsent"; |
| 1386 | } |
| 1387 | |
| 1388 | if (strcasecmp(frametype, "PKEXCRRequest") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1389 | if (dpp_wait_rx(dut, ctrl, 9, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1390 | result = "BootstrapResult,Timeout"; |
| 1391 | else |
| 1392 | result = "BootstrapResult,Errorsent"; |
| 1393 | } |
| 1394 | |
| 1395 | if (strcasecmp(frametype, "PKEXCRResponse") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1396 | if (dpp_wait_rx(dut, ctrl, 10, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1397 | result = "BootstrapResult,Timeout"; |
| 1398 | else |
| 1399 | result = "BootstrapResult,Errorsent"; |
| 1400 | } |
| 1401 | |
| 1402 | if (strcasecmp(frametype, "AuthenticationRequest") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1403 | if (dpp_wait_rx(dut, ctrl, 0, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1404 | result = "BootstrapResult,OK,AuthResult,Timeout"; |
| 1405 | else |
| 1406 | result = "BootstrapResult,OK,AuthResult,Errorsent"; |
| 1407 | } |
| 1408 | |
| 1409 | if (strcasecmp(frametype, "AuthenticationResponse") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1410 | if (dpp_wait_rx(dut, ctrl, 1, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1411 | result = "BootstrapResult,OK,AuthResult,Timeout"; |
| 1412 | else |
| 1413 | result = "BootstrapResult,OK,AuthResult,Errorsent"; |
| 1414 | } |
| 1415 | |
| 1416 | if (strcasecmp(frametype, "AuthenticationConfirm") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1417 | if (dpp_wait_rx(dut, ctrl, 2, -1) < 0) |
Jouni Malinen | 3a6b92a | 2017-12-05 20:22:43 +0200 | [diff] [blame] | 1418 | result = "BootstrapResult,OK,AuthResult,Timeout"; |
| 1419 | else |
| 1420 | result = "BootstrapResult,OK,AuthResult,Errorsent"; |
| 1421 | } |
| 1422 | |
| 1423 | if (strcasecmp(frametype, "ConfigurationRequest") == 0) { |
| 1424 | if (get_wpa_cli_event(dut, ctrl, "DPP-CONF-FAILED", |
| 1425 | buf, sizeof(buf)) < 0) |
| 1426 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout"; |
| 1427 | else |
| 1428 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent"; |
| 1429 | } |
| 1430 | |
| 1431 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1432 | goto out; |
| 1433 | } |
| 1434 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1435 | if (frametype && strcasecmp(frametype, "PKEXExchangeRequest") == 0) { |
| 1436 | if (dpp_wait_tx_status(dut, ctrl, 7) < 0) |
| 1437 | result = "BootstrapResult,Timeout"; |
| 1438 | else |
| 1439 | result = "BootstrapResult,Errorsent"; |
| 1440 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1441 | goto out; |
| 1442 | } |
| 1443 | |
| 1444 | if (frametype && strcasecmp(frametype, "PKEXExchangeResponse") == 0) { |
| 1445 | if (dpp_wait_tx_status(dut, ctrl, 8) < 0) |
| 1446 | result = "BootstrapResult,Timeout"; |
| 1447 | else |
| 1448 | result = "BootstrapResult,Errorsent"; |
| 1449 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1450 | goto out; |
| 1451 | } |
| 1452 | |
| 1453 | if (frametype && strcasecmp(frametype, "PKEXCRRequest") == 0) { |
| 1454 | if (dpp_wait_tx_status(dut, ctrl, 9) < 0) |
| 1455 | result = "BootstrapResult,Timeout"; |
| 1456 | else |
| 1457 | result = "BootstrapResult,Errorsent"; |
| 1458 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1459 | goto out; |
| 1460 | } |
| 1461 | |
| 1462 | if (frametype && strcasecmp(frametype, "PKEXCRResponse") == 0) { |
| 1463 | if (dpp_wait_tx_status(dut, ctrl, 10) < 0) |
| 1464 | result = "BootstrapResult,Timeout"; |
| 1465 | else |
| 1466 | result = "BootstrapResult,Errorsent"; |
| 1467 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1468 | goto out; |
| 1469 | } |
| 1470 | |
Jouni Malinen | 6792ff4 | 2018-02-13 00:25:56 +0200 | [diff] [blame] | 1471 | if (!frametype && strcasecmp(bs, "PKEX") == 0 && |
| 1472 | strcasecmp(auth_role, "Responder") == 0) { |
| 1473 | if (dpp_wait_tx_status(dut, ctrl, 10) < 0) { |
| 1474 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1475 | "BootstrapResult,Timeout"); |
| 1476 | goto out; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | if (!frametype && strcasecmp(bs, "PKEX") == 0 && |
| 1481 | strcasecmp(auth_role, "Initiator") == 0) { |
| 1482 | if (dpp_wait_tx(dut, ctrl, 0) < 0) { |
| 1483 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1484 | "BootstrapResult,Timeout"); |
| 1485 | goto out; |
| 1486 | } |
| 1487 | } |
| 1488 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1489 | if (frametype && strcasecmp(frametype, "AuthenticationRequest") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1490 | if (dpp_wait_tx_status(dut, ctrl, 0) < 0) { |
| 1491 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1492 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1493 | goto out; |
| 1494 | } |
| 1495 | |
| 1496 | if (dpp_wait_rx(dut, ctrl, 1, 5) < 0) |
| 1497 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,None"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1498 | else |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1499 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationResponse"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1500 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1501 | goto out; |
| 1502 | } |
| 1503 | |
| 1504 | if (frametype && strcasecmp(frametype, "AuthenticationResponse") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1505 | if (dpp_wait_tx_status(dut, ctrl, 1) < 0) { |
| 1506 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1507 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1508 | goto out; |
| 1509 | } |
| 1510 | |
| 1511 | if (dpp_wait_rx(dut, ctrl, 2, 5) < 0) |
| 1512 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationRequest"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1513 | else |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1514 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationConfirm"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1515 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1516 | goto out; |
| 1517 | } |
| 1518 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1519 | res = get_wpa_cli_events(dut, ctrl, auth_events, buf, sizeof(buf)); |
| 1520 | if (res < 0) { |
| 1521 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1522 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1523 | goto out; |
| 1524 | } |
| 1525 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf); |
| 1526 | |
| 1527 | if (strstr(buf, "DPP-RESPONSE-PENDING")) { |
| 1528 | /* Display own QR code in manual mode */ |
| 1529 | if (action_type && strcasecmp(action_type, "ManualDPP") == 0 && |
| 1530 | dpp_display_own_qrcode(dut) < 0) { |
| 1531 | send_resp(dut, conn, SIGMA_ERROR, |
| 1532 | "errorCode,Failed to display own QR code"); |
| 1533 | goto out; |
| 1534 | } |
| 1535 | |
| 1536 | /* Wait for the actual result after the peer has scanned the |
| 1537 | * QR Code. */ |
| 1538 | res = get_wpa_cli_events(dut, ctrl, auth_events, |
| 1539 | buf, sizeof(buf)); |
Jouni Malinen | d1e22f7 | 2017-12-05 21:12:17 +0200 | [diff] [blame] | 1540 | if (res < 0) { |
| 1541 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1542 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1543 | goto out; |
| 1544 | } |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1545 | |
| 1546 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf); |
| 1547 | } |
| 1548 | |
| 1549 | if (check_mutual) { |
Jouni Malinen | a98426a | 2018-02-06 21:18:48 +0200 | [diff] [blame] | 1550 | if (strstr(buf, "DPP-NOT-COMPATIBLE")) { |
| 1551 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1552 | "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE"); |
| 1553 | goto out; |
| 1554 | } |
| 1555 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1556 | if (!strstr(buf, "DPP-AUTH-DIRECTION")) { |
| 1557 | send_resp(dut, conn, SIGMA_ERROR, |
| 1558 | "errorCode,No event for auth direction seen"); |
| 1559 | goto out; |
| 1560 | } |
| 1561 | |
Jouni Malinen | d1e22f7 | 2017-12-05 21:12:17 +0200 | [diff] [blame] | 1562 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth direction: %s", |
| 1563 | buf); |
| 1564 | if (strstr(buf, "mutual=1") == NULL) { |
| 1565 | send_resp(dut, conn, SIGMA_ERROR, |
| 1566 | "errorCode,Peer did not use mutual authentication"); |
| 1567 | goto out; |
| 1568 | } |
| 1569 | } |
| 1570 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1571 | if (frametype && strcasecmp(frametype, "AuthenticationConfirm") == 0) { |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1572 | if (dpp_wait_tx_status(dut, ctrl, 2) < 0) { |
| 1573 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1574 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1575 | goto out; |
| 1576 | } |
| 1577 | |
| 1578 | if (dpp_wait_rx_conf_req(dut, ctrl, 5) < 0) |
| 1579 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,AuthenticationResponse"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1580 | else |
Jouni Malinen | 9a3415c | 2018-01-10 22:12:22 +0200 | [diff] [blame] | 1581 | result = "BootstrapResult,OK,AuthResult,Errorsent,LastFrameReceived,ConfigurationRequest"; |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1582 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1583 | goto out; |
| 1584 | } |
| 1585 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1586 | if (strstr(buf, "DPP-AUTH-DIRECTION")) { |
Jouni Malinen | 2e9c8a4 | 2017-11-19 12:06:18 +0200 | [diff] [blame] | 1587 | res = get_wpa_cli_events(dut, ctrl, auth_events, |
| 1588 | buf, sizeof(buf)); |
| 1589 | if (res < 0) { |
| 1590 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1591 | "BootstrapResult,OK,AuthResult,Timeout"); |
| 1592 | goto out; |
| 1593 | } |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1594 | |
| 1595 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP auth result: %s", buf); |
Jouni Malinen | 2e9c8a4 | 2017-11-19 12:06:18 +0200 | [diff] [blame] | 1596 | } |
| 1597 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1598 | if (strstr(buf, "DPP-NOT-COMPATIBLE")) { |
| 1599 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1600 | "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE"); |
| 1601 | goto out; |
| 1602 | } |
| 1603 | |
| 1604 | if (!strstr(buf, "DPP-AUTH-SUCCESS")) { |
| 1605 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1606 | "BootstrapResult,OK,AuthResult,FAILED"); |
| 1607 | goto out; |
| 1608 | } |
| 1609 | |
Jouni Malinen | 772299f | 2017-11-06 00:36:26 +0200 | [diff] [blame] | 1610 | if (frametype && strcasecmp(frametype, "ConfigurationRequest") == 0) { |
| 1611 | res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", |
| 1612 | buf, sizeof(buf)); |
| 1613 | if (res < 0) |
| 1614 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout"; |
| 1615 | else |
| 1616 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent"; |
| 1617 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1618 | goto out; |
| 1619 | } |
| 1620 | |
| 1621 | if (frametype && strcasecmp(frametype, "ConfigurationResponse") == 0) { |
| 1622 | res = get_wpa_cli_event(dut, ctrl, "DPP-CONF-SENT", |
| 1623 | buf, sizeof(buf)); |
| 1624 | if (res < 0) |
| 1625 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout"; |
| 1626 | else |
| 1627 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent"; |
| 1628 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1629 | goto out; |
| 1630 | } |
| 1631 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1632 | res = get_wpa_cli_events(dut, ctrl, conf_events, buf, sizeof(buf)); |
| 1633 | if (res < 0) { |
| 1634 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1635 | "BootstrapResult,OK,AuthResult,OK,ConfResult,Timeout"); |
| 1636 | goto out; |
| 1637 | } |
| 1638 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP conf result: %s", buf); |
| 1639 | |
| 1640 | if (!strstr(buf, "DPP-CONF-SENT") && |
| 1641 | !strstr(buf, "DPP-CONF-RECEIVED")) { |
| 1642 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1643 | "BootstrapResult,OK,AuthResult,OK,ConfResult,FAILED"); |
| 1644 | goto out; |
| 1645 | } |
| 1646 | |
| 1647 | if (sigma_dut_is_ap(dut) && |
| 1648 | strcasecmp(prov_role, "Enrollee") == 0) { |
Jouni Malinen | 174db64 | 2017-11-27 20:16:29 +0200 | [diff] [blame] | 1649 | update_ap: |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1650 | res = dpp_hostapd_conf_update(dut, conn, ifname, ctrl); |
| 1651 | if (res == 0) |
| 1652 | goto out; |
| 1653 | if (res < 0) { |
| 1654 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 1655 | goto out; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | if (strcasecmp(wait_conn, "Yes") == 0 && |
| 1660 | !sigma_dut_is_ap(dut) && |
| 1661 | strcasecmp(prov_role, "Enrollee") == 0) { |
Jouni Malinen | fbb268d | 2017-11-17 18:53:49 +0200 | [diff] [blame] | 1662 | wait_connect: |
Jouni Malinen | 53558e0 | 2017-11-06 12:58:28 +0200 | [diff] [blame] | 1663 | if (frametype && strcasecmp(frametype, |
| 1664 | "PeerDiscoveryRequest") == 0) { |
| 1665 | if (dpp_wait_tx_status(dut, ctrl, 5) < 0) |
| 1666 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout"; |
| 1667 | else |
| 1668 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent"; |
| 1669 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1670 | goto out; |
| 1671 | } |
| 1672 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1673 | res = get_wpa_cli_events(dut, ctrl, conn_events, |
| 1674 | buf, sizeof(buf)); |
| 1675 | if (res < 0) { |
| 1676 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1677 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout,NetworkConnectResult,Timeout"); |
| 1678 | goto out; |
| 1679 | } |
| 1680 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP connect result: %s", |
| 1681 | buf); |
| 1682 | |
| 1683 | if (strstr(buf, "PMKSA-CACHE-ADDED")) { |
| 1684 | res = get_wpa_cli_events(dut, ctrl, conn_events, |
| 1685 | buf, sizeof(buf)); |
| 1686 | if (res < 0) { |
| 1687 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1688 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,Timeout"); |
| 1689 | goto out; |
| 1690 | } |
| 1691 | sigma_dut_print(dut, DUT_MSG_DEBUG, |
| 1692 | "DPP connect result: %s", buf); |
| 1693 | if (strstr(buf, "CTRL-EVENT-CONNECTED")) |
| 1694 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1695 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK"); |
| 1696 | else |
| 1697 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1698 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,Timeout"); |
| 1699 | goto out; |
| 1700 | } |
| 1701 | |
| 1702 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1703 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK"); |
| 1704 | goto out; |
| 1705 | } |
| 1706 | |
Jouni Malinen | 53558e0 | 2017-11-06 12:58:28 +0200 | [diff] [blame] | 1707 | if (strcasecmp(wait_conn, "Yes") == 0 && |
| 1708 | frametype && strcasecmp(frametype, "PeerDiscoveryResponse") == 0) { |
| 1709 | if (dpp_wait_tx_status(dut, ctrl, 6) < 0) |
| 1710 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Timeout"; |
| 1711 | else |
| 1712 | result = "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent"; |
| 1713 | send_resp(dut, conn, SIGMA_COMPLETE, result); |
| 1714 | goto out; |
| 1715 | } |
| 1716 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1717 | send_resp(dut, conn, SIGMA_COMPLETE, |
| 1718 | "BootstrapResult,OK,AuthResult,OK,ConfResult,OK"); |
| 1719 | out: |
| 1720 | wpa_ctrl_detach(ctrl); |
| 1721 | wpa_ctrl_close(ctrl); |
| 1722 | dut->default_timeout = old_timeout; |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1727 | static int dpp_manual_dpp(struct sigma_dut *dut, |
| 1728 | struct sigma_conn *conn, |
| 1729 | struct sigma_cmd *cmd) |
| 1730 | { |
| 1731 | const char *auth_role = get_param(cmd, "DPPAuthRole"); |
| 1732 | int res = -1, success; |
| 1733 | const char *val; |
| 1734 | unsigned int old_timeout; |
| 1735 | |
| 1736 | if (!auth_role) { |
| 1737 | send_resp(dut, conn, SIGMA_ERROR, |
| 1738 | "errorCode,Missing DPPAuthRole"); |
| 1739 | return 0; |
| 1740 | } |
| 1741 | |
| 1742 | old_timeout = dut->default_timeout; |
| 1743 | val = get_param(cmd, "DPPTimeout"); |
| 1744 | if (val && atoi(val) > 0) { |
| 1745 | dut->default_timeout = atoi(val); |
| 1746 | sigma_dut_print(dut, DUT_MSG_DEBUG, "DPP timeout: %u", |
| 1747 | dut->default_timeout); |
| 1748 | } |
| 1749 | |
| 1750 | res = dpp_get_local_bootstrap(dut, conn, cmd, 0, &success); |
| 1751 | if (res || !success) |
| 1752 | goto out; |
| 1753 | |
| 1754 | if (strcasecmp(auth_role, "Responder") == 0) { |
| 1755 | res = dpp_display_own_qrcode(dut); |
| 1756 | if (res < 0) |
| 1757 | goto out; |
| 1758 | |
| 1759 | res = dpp_automatic_dpp(dut, conn, cmd); |
| 1760 | goto out; |
| 1761 | } |
| 1762 | |
| 1763 | if (strcasecmp(auth_role, "Initiator") == 0) { |
| 1764 | res = dpp_scan_peer_qrcode(dut); |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 1765 | if (res < 0) { |
| 1766 | send_resp(dut, conn, SIGMA_ERROR, |
| 1767 | "errorCode,Failed to scan peer QR Code"); |
| 1768 | res = 0; |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1769 | goto out; |
Jouni Malinen | 1a38cc3 | 2018-01-05 20:59:00 +0200 | [diff] [blame] | 1770 | } |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1771 | |
| 1772 | res = dpp_automatic_dpp(dut, conn, cmd); |
| 1773 | goto out; |
| 1774 | } |
| 1775 | |
| 1776 | send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unknown DPPAuthRole"); |
| 1777 | res = 0; |
| 1778 | out: |
| 1779 | dut->default_timeout = old_timeout; |
| 1780 | return res; |
| 1781 | } |
| 1782 | |
| 1783 | |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1784 | int dpp_dev_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 1785 | struct sigma_cmd *cmd) |
| 1786 | { |
| 1787 | const char *type = get_param(cmd, "DPPActionType"); |
| 1788 | const char *bs = get_param(cmd, "DPPBS"); |
| 1789 | |
| 1790 | if (!bs) { |
| 1791 | send_resp(dut, conn, SIGMA_ERROR, |
| 1792 | "errorCode,Missing DPPBS"); |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
| 1796 | if (!type) { |
| 1797 | send_resp(dut, conn, SIGMA_ERROR, |
| 1798 | "errorCode,Missing DPPActionType"); |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | if (strcasecmp(type, "GetLocalBootstrap") == 0) |
Srinivas Dasari | bc9e055 | 2018-01-04 19:24:28 +0530 | [diff] [blame] | 1803 | return dpp_get_local_bootstrap(dut, conn, cmd, 1, NULL); |
Jouni Malinen | d86e582 | 2017-08-29 03:55:32 +0300 | [diff] [blame] | 1804 | if (strcasecmp(type, "SetPeerBootstrap") == 0) |
| 1805 | return dpp_set_peer_bootstrap(dut, conn, cmd); |
| 1806 | if (strcasecmp(type, "ManualDPP") == 0) |
| 1807 | return dpp_manual_dpp(dut, conn, cmd); |
| 1808 | if (strcasecmp(type, "AutomaticDPP") == 0) |
| 1809 | return dpp_automatic_dpp(dut, conn, cmd); |
| 1810 | |
| 1811 | send_resp(dut, conn, SIGMA_ERROR, |
| 1812 | "errorCode,Unsupported DPPActionType"); |
| 1813 | return 0; |
| 1814 | } |