Skip to content

BL602 and psk / pbkdf2_sha1 calculation issueΒ #1867

@maquowicz

Description

@maquowicz

I've got 1M Bl602 in Cozylife Hygrometer BC148-WT (aliexpress).

Disabled bunch of drivers so firmware will fit:

diff --git a/src/obk_config.h b/src/obk_config.h
index 3e559ed1..64e956cf 100644
--- a/src/obk_config.h
+++ b/src/obk_config.h
@@ -195,26 +195,27 @@
 #define ENABLE_LITTLEFS                                                        1
 #define ENABLE_NTP                                                             1
 // #define ENABLE_NTP_DST                                              1
-#define ENABLE_CALENDAR_EVENTS                                 1
+#define ENABLE_CALENDAR_EVENTS                                 0
 #define ENABLE_DRIVER_LED                                              1
 #define ENABLE_DRIVER_BL0937                                   1
-#define ENABLE_DRIVER_BL0942                                   1
-#define ENABLE_DRIVER_CSE7766                                  1
-#define ENABLE_DRIVER_WEMO                                             1
+#define ENABLE_DRIVER_BL0942                                   0
+#define ENABLE_DRIVER_BL0942SPI                                        0 
+#define ENABLE_DRIVER_CSE7766                                  0
+#define ENABLE_DRIVER_WEMO                                             0
 #define ENABLE_DRIVER_FREEZE                                   0
-#define ENABLE_DRIVER_DHT                                              1
+#define ENABLE_DRIVER_DHT                                              0
 // parse things like $CH1 or $hour etc
 #define ENABLE_EXPAND_CONSTANT                                 1
 #define ENABLE_TASMOTA_JSON                                            1
-#define ENABLE_DRIVER_DDP                                              1
-#define ENABLE_DRIVER_SSDP                                             1
+#define ENABLE_DRIVER_DDP                                              0
+#define ENABLE_DRIVER_SSDP                                             0
 #define ENABLE_DRIVER_CHT83XX                                  1
-#define ENABLE_DRIVER_DS1820                                   1
+#define ENABLE_DRIVER_DS1820                                   0
 #define ENABLE_OBK_SCRIPTING                                   1
-// #define ENABLE_I2C                                                  1
+#define ENABLE_I2C                                                             1
 #define ENABLE_ADVANCED_CHANNELTYPES_DISCOVERY 1
-#define ENABLE_DRIVER_SM16703P                                 1
-#define ENABLE_DRIVER_PIXELANIM                                        1
+#define ENABLE_DRIVER_SM16703P                                 0
+#define ENABLE_DRIVER_PIXELANIM                                        0
 
 #if (OBK_VARIANT == OBK_VARIANT_BERRY)
 #define ENABLE_OBK_BERRY                                               1
@@ -226,7 +227,7 @@
 //#undef ENABLE_DRIVER_CSE7766
 //#undef ENABLE_DRIVER_BL0937
 //#undef ENABLE_DRIVER_BL0942
-#define ENABLE_DRIVER_IRREMOTEESP                              1
+#define ENABLE_DRIVER_IRREMOTEESP                              0
 //#endif
 
 #elif PLATFORM_BEKEN

Spent 2 days debugging and trying to get it working, but it always crashes around

hmac_sha1_vector exit: success, call_id=189
hmac_sha1_vector enter: call_id=190, key_len=14, num_elem=1
hmac inner before sha1_vector, stack: 698 words
hmac inner after sha1_vector, stack: 698 words
hmac outer before sha1_vector, stack: 698 words
hmac outer after sha1_vector, stack: 698 words
hmac_sha1_vector exit: success, call_id=190
hmac_sha1_vector enter: call_id=191, key_len=14, num_elem=1
hmac inner before sha1_vector, stack: 698 words
hmac inner after sha1_vector, stack: 698 words
hmac outer before sha1_vector, stack: 698 words
hmac outer after sha1_vector, stack: 698 words
hmac_sha1_vector exit: success, call_id=191
hmac_sha1_vector enter: call_id=192, key_len=14, num_elem=1
hmac inner before sha1_vector, stack:
[14:17:32.255] - Starting bl602 now....
Booting BL602 Chip...

If anybody runs into this a dirty workaround is to modify OpenBL602 sdk:

diff --git a/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c b/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c
index 7f3019375..350395be4 100644
--- a/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c
+++ b/components/network/wifi_manager/bl60x_wifi_driver/wifi_mgmr_ext.c
@@ -206,6 +206,13 @@ int wifi_mgmr_psk_cal(char *password, char *ssid, int ssid_len, char *output)
     int ret;
     char psk[32];
 
+    if (strlen(password) == 64) {
+        // Bypass: assume password is precomputed hex PSK
+        bl_os_printf("PSK bypass activated\r\n");
+        strcpy(output, password);
+        return 0;
+    }
+
     ret = pbkdf2_sha1(password, ssid, ssid_len, 4096, (uint8_t *)psk, sizeof(psk));
     if (0 == ret) {
         utils_bin2hex(output, psk, 32);
@@ -343,7 +350,7 @@ int wifi_mgmr_sta_connect_ext(wifi_interface_t *wifi_interface, char *ssid, char
     int ssid_len = ssid ? strlen(ssid) : 0;
     int passphr_len = passphr ? strlen(passphr) : 0;
 
-    if (!ssid || ssid_len > 32 || (passphr && ((passphr_len < 8 && passphr_len != 5) || passphr_len > 63))) {
+    if (!ssid || ssid_len > 32 || (passphr && ((passphr_len < 8 && passphr_len != 5) || passphr_len > 64))) {
         return -1;
     }

And use pre-generated psk hex in password field while configurig wifi.
Attached simple script to get that string.
generate_psk_hex.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions