|
25 | 25 | #define MAX_BANDS_STR_LEN 64 |
26 | 26 | #define MACSTR "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" |
27 | 27 |
|
| 28 | +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE |
| 29 | +static const char ca_cert_test[] = { |
| 30 | + #include <wifi_enterprise_test_certs/ca.pem.inc> |
| 31 | + '\0' |
| 32 | +}; |
| 33 | + |
| 34 | +static const char client_cert_test[] = { |
| 35 | + #include <wifi_enterprise_test_certs/client.pem.inc> |
| 36 | + '\0' |
| 37 | +}; |
| 38 | + |
| 39 | +static const char client_key_test[] = { |
| 40 | + #include <wifi_enterprise_test_certs/client-key.pem.inc> |
| 41 | + '\0' |
| 42 | +}; |
| 43 | + |
| 44 | +static const char ca_cert2_test[] = { |
| 45 | + #include <wifi_enterprise_test_certs/ca2.pem.inc> |
| 46 | + '\0'}; |
| 47 | + |
| 48 | +static const char client_cert2_test[] = { |
| 49 | + #include <wifi_enterprise_test_certs/client2.pem.inc> |
| 50 | + '\0'}; |
| 51 | + |
| 52 | +static const char client_key2_test[] = { |
| 53 | + #include <wifi_enterprise_test_certs/client-key2.pem.inc> |
| 54 | + '\0'}; |
| 55 | +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE */ |
| 56 | + |
| 57 | +#if defined CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE || \ |
| 58 | + defined CONFIG_WIFI_NM_HOSTAPD_CRYPTO_ENTERPRISE |
| 59 | +static int cmd_wifi_set_enterprise_creds(const struct shell *sh, struct net_if *iface) |
| 60 | +{ |
| 61 | + struct wifi_enterprise_creds_params params = {0}; |
| 62 | + |
| 63 | + params.ca_cert = (uint8_t *)ca_cert_test; |
| 64 | + params.ca_cert_len = ARRAY_SIZE(ca_cert_test); |
| 65 | + params.client_cert = (uint8_t *)client_cert_test; |
| 66 | + params.client_cert_len = ARRAY_SIZE(client_cert_test); |
| 67 | + params.client_key = (uint8_t *)client_key_test; |
| 68 | + params.client_key_len = ARRAY_SIZE(client_key_test); |
| 69 | + params.ca_cert2 = (uint8_t *)ca_cert2_test; |
| 70 | + params.ca_cert2_len = ARRAY_SIZE(ca_cert2_test); |
| 71 | + params.client_cert2 = (uint8_t *)client_cert2_test; |
| 72 | + params.client_cert2_len = ARRAY_SIZE(client_cert2_test); |
| 73 | + params.client_key2 = (uint8_t *)client_key2_test; |
| 74 | + params.client_key2_len = ARRAY_SIZE(client_key2_test); |
| 75 | + |
| 76 | + if (net_mgmt(NET_REQUEST_WIFI_ENTERPRISE_CREDS, iface, ¶ms, sizeof(params))) { |
| 77 | + shell_warn(sh, "Set enterprise credentials failed\n"); |
| 78 | + return -1; |
| 79 | + } |
| 80 | + |
| 81 | + return 0; |
| 82 | +} |
| 83 | +#endif |
| 84 | + |
28 | 85 | static void print_network_info(void *cb_arg, const char *ssid, size_t ssid_len) |
29 | 86 | { |
30 | 87 | int ret = 0; |
@@ -53,6 +110,23 @@ static void print_network_info(void *cb_arg, const char *ssid, size_t ssid_len) |
53 | 110 | creds.password, creds.password_len); |
54 | 111 | } |
55 | 112 |
|
| 113 | +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE |
| 114 | + if (creds.header.type == WIFI_SECURITY_TYPE_EAP_TLS) { |
| 115 | + if (creds.header.key_passwd_length > 0) { |
| 116 | + shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, |
| 117 | + ", key_passwd: \"%.*s\", key_passwd_len: %d", |
| 118 | + creds.header.key_passwd_length, creds.header.key_passwd, |
| 119 | + creds.header.key_passwd_length); |
| 120 | + } |
| 121 | + if (creds.header.aid_length > 0) { |
| 122 | + shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, |
| 123 | + ", anon_id: \"%.*s\", anon_id_len: %d", |
| 124 | + creds.header.aid_length, creds.header.anon_id, |
| 125 | + creds.header.aid_length); |
| 126 | + } |
| 127 | + } |
| 128 | +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE */ |
| 129 | + |
56 | 130 | if (creds.header.flags & WIFI_CREDENTIALS_FLAG_BSSID) { |
57 | 131 | shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, ", bssid: " MACSTR, |
58 | 132 | creds.header.bssid[0], creds.header.bssid[1], creds.header.bssid[2], |
@@ -266,6 +340,19 @@ static int cmd_add_network(const struct shell *sh, size_t argc, char *argv[]) |
266 | 340 | return -EINVAL; |
267 | 341 | } |
268 | 342 |
|
| 343 | +#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE |
| 344 | + struct net_if *iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET)); |
| 345 | + |
| 346 | + /* Load the enterprise credentials if needed */ |
| 347 | + if (creds.header.type == WIFI_SECURITY_TYPE_EAP_TLS || |
| 348 | + creds.header.type == WIFI_SECURITY_TYPE_EAP_PEAP_MSCHAPV2 || |
| 349 | + creds.header.type == WIFI_SECURITY_TYPE_EAP_PEAP_GTC || |
| 350 | + creds.header.type == WIFI_SECURITY_TYPE_EAP_TTLS_MSCHAPV2 || |
| 351 | + creds.header.type == WIFI_SECURITY_TYPE_EAP_PEAP_TLS) { |
| 352 | + cmd_wifi_set_enterprise_creds(sh, iface); |
| 353 | + } |
| 354 | +#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_CRYPTO_ENTERPRISE */ |
| 355 | + |
269 | 356 | return wifi_credentials_set_personal_struct(&creds); |
270 | 357 | } |
271 | 358 |
|
|
0 commit comments