Skip to content

Commit

Permalink
Adding security in the wifi connectionInfo
Browse files Browse the repository at this point in the history
 - #607
 - Set defalt value to make it optional
 - Use storage if security is not set
 - Fix strcmp bug for wifi security
  • Loading branch information
communix committed Sep 3, 2023
1 parent 4c8ccff commit 9045148
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/modules/pico_cyw43/module_pico_cyw43.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ JERRYXX_FUN(pico_cyw43_wifi_connect) {
uint8_t *pw_str = NULL;
jerry_value_t security =
jerryxx_get_property(connect_info, MSTR_PICO_CYW43_SCANINFO_SECURITY);
uint32_t auth = -1;
uint32_t auth = CYW43_AUTH_OPEN; // Default is OPEN
if (jerry_value_is_string(ssid)) {
jerry_size_t len = jerryxx_get_ascii_string_size(ssid);
if (len > 32) {
Expand Down Expand Up @@ -420,22 +420,25 @@ JERRYXX_FUN(pico_cyw43_wifi_connect) {
jerry_size_t len = jerryxx_get_ascii_string_size(pw);
pw_str = (uint8_t *)malloc(len + 1);
jerryxx_string_to_ascii_char_buffer(pw, pw_str, len);
if (len >= 8) { // Min lenght of the WPA is 8.
auth = CYW43_AUTH_WPA2_MIXED_PSK; // Default auth is changed.
}
pw_str[len] = '\0';
}
if (jerry_value_is_string(security)) {
jerry_size_t len = jerryxx_get_ascii_string_size(security);
uint8_t *security_str = (uint8_t *)malloc(len + 1);
jerryxx_string_to_ascii_char_buffer(security, security_str, len);
security_str[len] = '\0';
if (strcmp((const char *)security_str, "WPA2_WPA_PSK")) {
if (!strcmp((const char *)security_str, "WPA2_WPA_PSK")) {
auth = CYW43_AUTH_WPA2_MIXED_PSK;
} else if (strcmp((const char *)security_str, "WPA2_PSK")) {
} else if (!strcmp((const char *)security_str, "WPA2_PSK")) {
auth = CYW43_AUTH_WPA2_AES_PSK;
} else if (strcmp((const char *)security_str, "WPA_PSK")) {
} else if (!strcmp((const char *)security_str, "WPA_PSK")) {
auth = CYW43_WIFI_AUTH_WPA;
} else if (strcmp((const char *)security_str, "WEP_PSK")) {
} else if (!strcmp((const char *)security_str, "WEP_PSK")) {
auth = 0x00100001; // no idea if this works
} else if (strcmp((const char *)security_str, "OPEN")) {
} else if (!strcmp((const char *)security_str, "OPEN")) {
auth = CYW43_AUTH_OPEN;
}
free(security_str);
Expand Down
3 changes: 3 additions & 0 deletions src/modules/wifi/wifi.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class WiFi extends EventEmitter {
if (!connectInfo.password) {
connectInfo.password = storage ? storage.getItem('WIFI_PASSWORD') : null
}
if (!connectInfo.security) {
connectInfo.security = storage ? storage.getItem('WIFI_SECURITY') : null
}
if (connectInfo.enforce) {
this._dev.connect(connectInfo, err => {
if (err) {
Expand Down

0 comments on commit 9045148

Please sign in to comment.