From 2aa32d08e7e5a4657c195e85265a4213f187738c Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Wed, 12 Mar 2025 17:25:07 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=83=AD=E7=82=B9=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E4=B8=8D=E6=98=8E=E6=96=87=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TeamCorePro --- wpa_supplicant-2.9_standard/hostapd/ap_config_file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index 7398715..1cc3ee2 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5283,6 +5283,12 @@ struct hostapd_config * hostapd_config_read(const char *fname) int errors = 0; size_t i; +#ifdef CONFIG_OPEN_HARMONY_PATCH + char *configfile = NULL; + char *pass = NULL; + char *pass_len = NULL; +#endif + f = fopen(fname, "r"); if (f == NULL) { wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " -- Gitee From 424f1ece0dce2e6bfd6e63e172f219f95962fa45 Mon Sep 17 00:00:00 2001 From: lx9512 <352753852@qq.com> Date: Fri, 14 Mar 2025 10:46:24 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E7=83=AD=E7=82=B9=E6=98=8E=E6=96=87?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lx9512 <352753852@qq.com> --- .../hostapd/ap_config_file.c | 84 ++++++++++++++++++- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index 1cc3ee2..20c9671 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5269,6 +5269,78 @@ static void CheckApBand(struct hostapd_config *conf) } #endif +#ifdef CONFIG_OPEN_HARMONY_PATCH +int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, char **pass_len) +{ + if (fname == NULL) { + wpa_printf(MSG_ERROR, "fname is null"); + return 1; + } + char *pass_with_len = NULL; + char *ptr = os_strchr(fname, ' '); + if (ptr == NULL) { + wpa_printf(MSG_ERROR, "wpa_passphrase is null"); + return 1; + } + *ptr++ = '\0'; + *configfile = os_strdup(fname); + pass_with_len = os_strdup(ptr); + if (pass_with_len == NULL) { + wpa_printf(MSG_ERROR, "pass_with_len is null"); + return 1; + } + ptr = os_strchr(pass_with_len, ' '); + if (ptr == NULL) { + wpa_printf(MSG_ERROR, "pass_length is null"); + return 1; + } + *ptr++ = '\0'; + *pass = os_strdup(pass_with_len); + pass_len = os_strdup(ptr); + if (os_strncmp(*pass, "wpa_passphrase=", strlen("wpa_passphrase=")) != 0) { + wpa_printf(MSG_ERROR, "pass has no wpa_passphrase"); + return 1; + } + int pass_len_real = (int)strlen(*pass) - (int)strlen("wpa_passphrase="); + char *endptr; + int base = 10; + int pass_len_value = (int)strtol(*pass_len + strlen("pass_length="), &endptr, base); + if (pass_len_real != pass_len_value) { + wpa_printf(MSG_ERROR, "pass_length is error %d, %d", pass_len_real, pass_len_value); + return 1; + } + return 0; +} + +int hostapd_passphrase_config_fill(struct hostapd_config *conf, const char *pass) +{ + if (conf == NULL || pass == NULL) { + wpa_printf(MSG_ERROR, "conf or wpa_passphrase is null"); + return 1; + } + + struct hostapd_bss_config *bss; + bss = conf->last_bss; + +#define PASS_MIN_LENGTH 8 +#define PASS_MAX_LENGTH 63 + + int len = os_strlen(pass + strlen("wpa_passphrase=")); + if (len < PASS_MIN_LENGTH || len > PASS_MAX_LENGTH) { + wpa_printf(MSG_ERROR, "%s: invalid WPA passphrase length %d (expected 8..63)", + __func__, len); + return 1; + } + os_free(bss->ssid.wpa_passphrase); + bss->ssid.wpa_passphrase = os_strdup(pass + strlen("wpa_passphrase=")); + if (bss->ssid.wpa_passphrase) { + hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk); + bss->ssid.wpa_passphrase_set = 1; + } + return 0; +} +#endif + /** * hostapd_config_read - Read and parse a configuration file * @fname: Configuration file name (including path, if needed) @@ -5287,12 +5359,13 @@ struct hostapd_config * hostapd_config_read(const char *fname) char *configfile = NULL; char *pass = NULL; char *pass_len = NULL; + char *pass = hostapd_passphrase_split(fname); + errors += hostapd_passphrase_split(fname, &configfile, &pass, &pass_len); #endif - - f = fopen(fname, "r"); + f = fopen(configfile, "r"); if (f == NULL) { wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " - "for reading.", fname); + "for reading.", configfile); return NULL; } @@ -5343,6 +5416,9 @@ struct hostapd_config * hostapd_config_read(const char *fname) pos++; errors += hostapd_config_fill(conf, bss, buf, pos, line); } +#ifdef CONFIG_OPEN_HARMONY_PATCH + errors += hostapd_passphrase_config_fill(conf, pass); +#endif fclose(f); #ifdef CONFIG_OPEN_HARMONY_PATCH @@ -5381,7 +5457,7 @@ struct hostapd_config * hostapd_config_read(const char *fname) #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { wpa_printf(MSG_ERROR, "%d errors found in configuration file " - "'%s'", errors, fname); + "'%s'", errors, configfile); hostapd_config_free(conf); conf = NULL; } -- Gitee From 4e93a579ce938284320adab85b8f727dd8fd5668 Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Thu, 27 Mar 2025 14:56:31 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E7=83=AD=E7=82=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: TeamCorePro --- wpa_supplicant-2.9_standard/hostapd/ap_config_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index 20c9671..e427be1 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5296,7 +5296,7 @@ int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, } *ptr++ = '\0'; *pass = os_strdup(pass_with_len); - pass_len = os_strdup(ptr); + *pass_len = os_strdup(ptr); if (os_strncmp(*pass, "wpa_passphrase=", strlen("wpa_passphrase=")) != 0) { wpa_printf(MSG_ERROR, "pass has no wpa_passphrase"); return 1; -- Gitee From 3139453d4d33ca107654c946b3535515d7558cae Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Thu, 27 Mar 2025 17:04:06 +0800 Subject: [PATCH 4/7] hostapd Signed-off-by: TeamCorePro --- wpa_supplicant-2.9_standard/hostapd/ap_config_file.c | 1 - 1 file changed, 1 deletion(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index e427be1..2044f54 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5359,7 +5359,6 @@ struct hostapd_config * hostapd_config_read(const char *fname) char *configfile = NULL; char *pass = NULL; char *pass_len = NULL; - char *pass = hostapd_passphrase_split(fname); errors += hostapd_passphrase_split(fname, &configfile, &pass, &pass_len); #endif f = fopen(configfile, "r"); -- Gitee From e8e60fb6e693f8c0cc29755ca8eb38e32830acbd Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Fri, 28 Mar 2025 19:41:24 +0800 Subject: [PATCH 5/7] hostapd pass Signed-off-by: TeamCorePro --- .../hostapd/ap_config_file.c | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index 2044f54..b94c4c2 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5296,7 +5296,9 @@ int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, } *ptr++ = '\0'; *pass = os_strdup(pass_with_len); + os_free(pass_with_len); *pass_len = os_strdup(ptr); + os_free(ptr); if (os_strncmp(*pass, "wpa_passphrase=", strlen("wpa_passphrase=")) != 0) { wpa_printf(MSG_ERROR, "pass has no wpa_passphrase"); return 1; @@ -5305,6 +5307,12 @@ int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, char *endptr; int base = 10; int pass_len_value = (int)strtol(*pass_len + strlen("pass_length="), &endptr, base); + if (*endptr != '\0') { + wpa_printf(MSG_ERROR, "strtol pass_len_value failed"); + os_free(endptr); + return 1; + } + os_free(endptr); if (pass_len_real != pass_len_value) { wpa_printf(MSG_ERROR, "pass_length is error %d, %d", pass_len_real, pass_len_value); return 1; @@ -5314,7 +5322,7 @@ int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, int hostapd_passphrase_config_fill(struct hostapd_config *conf, const char *pass) { - if (conf == NULL || pass == NULL) { + if (conf == NULL || pass == NULL || conf->last_bss == NULL) { wpa_printf(MSG_ERROR, "conf or wpa_passphrase is null"); return 1; } @@ -5360,13 +5368,18 @@ struct hostapd_config * hostapd_config_read(const char *fname) char *pass = NULL; char *pass_len = NULL; errors += hostapd_passphrase_split(fname, &configfile, &pass, &pass_len); -#endif f = fopen(configfile, "r"); if (f == NULL) { - wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " - "for reading.", configfile); + wpa_printf(MSG_ERROR, "Could not open configuration file '%s' for reading.", configfile); return NULL; } +#else + f = fopen(fname, "r"); + if (f == NULL) { + wpa_printf(MSG_ERROR, "Could not open configuration file '%s' for reading.", fname); + return NULL; + } +#endif conf = hostapd_config_defaults(); if (conf == NULL) { @@ -5455,13 +5468,22 @@ struct hostapd_config * hostapd_config_read(const char *fname) #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { - wpa_printf(MSG_ERROR, "%d errors found in configuration file " - "'%s'", errors, configfile); - hostapd_config_free(conf); +#ifdef CONFIG_OPEN_HARMONY_PATCH + wpa_printf(MSG_ERROR, "%d errors found in configuration file '%s'", errors, configfile); +#else + wpa_printf(MSG_ERROR, "%d errors found in configuration file '%s'", errors, fname); +#endif + hostapd_config_free(conf); conf = NULL; } #endif /* WPA_IGNORE_CONFIG_ERRORS */ +#ifdef CONFIG_OPEN_HARMONY_PATCH + os_free(configfile); + os_free(pass); + os_free(pass_len); +#endif + return conf; } -- Gitee From d244aa97b323bcc17268c93e9a8a461d3a55a75b Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Sat, 12 Apr 2025 14:39:27 +0800 Subject: [PATCH 6/7] passwd new Signed-off-by: TeamCorePro --- .../hostapd/ap_config_file.c | 91 +++---------------- .../hostapd/ap_ctrl_iface.c | 15 +++ .../hostapd/config_file.h | 3 + 3 files changed, 32 insertions(+), 77 deletions(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index b94c4c2..a668244 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -28,6 +28,9 @@ #ifdef CONFIG_OPEN_HARMONY_PATCH #define HT40_OFFSET_DOWN 5 #define HT40_OFFSET_UP 13 +#define PASS_MIN_LENGTH 8 +#define PASS_MAX_LENGTH 65 +static char g_hostapdPassphrase[PASS_MAX_LENGTH]; #endif #ifndef CONFIG_NO_VLAN @@ -5270,56 +5273,6 @@ static void CheckApBand(struct hostapd_config *conf) #endif #ifdef CONFIG_OPEN_HARMONY_PATCH -int hostapd_passphrase_split(const char *fname, char **configfile, char **pass, char **pass_len) -{ - if (fname == NULL) { - wpa_printf(MSG_ERROR, "fname is null"); - return 1; - } - char *pass_with_len = NULL; - char *ptr = os_strchr(fname, ' '); - if (ptr == NULL) { - wpa_printf(MSG_ERROR, "wpa_passphrase is null"); - return 1; - } - *ptr++ = '\0'; - *configfile = os_strdup(fname); - pass_with_len = os_strdup(ptr); - if (pass_with_len == NULL) { - wpa_printf(MSG_ERROR, "pass_with_len is null"); - return 1; - } - ptr = os_strchr(pass_with_len, ' '); - if (ptr == NULL) { - wpa_printf(MSG_ERROR, "pass_length is null"); - return 1; - } - *ptr++ = '\0'; - *pass = os_strdup(pass_with_len); - os_free(pass_with_len); - *pass_len = os_strdup(ptr); - os_free(ptr); - if (os_strncmp(*pass, "wpa_passphrase=", strlen("wpa_passphrase=")) != 0) { - wpa_printf(MSG_ERROR, "pass has no wpa_passphrase"); - return 1; - } - int pass_len_real = (int)strlen(*pass) - (int)strlen("wpa_passphrase="); - char *endptr; - int base = 10; - int pass_len_value = (int)strtol(*pass_len + strlen("pass_length="), &endptr, base); - if (*endptr != '\0') { - wpa_printf(MSG_ERROR, "strtol pass_len_value failed"); - os_free(endptr); - return 1; - } - os_free(endptr); - if (pass_len_real != pass_len_value) { - wpa_printf(MSG_ERROR, "pass_length is error %d, %d", pass_len_real, pass_len_value); - return 1; - } - return 0; -} - int hostapd_passphrase_config_fill(struct hostapd_config *conf, const char *pass) { if (conf == NULL || pass == NULL || conf->last_bss == NULL) { @@ -5330,23 +5283,23 @@ int hostapd_passphrase_config_fill(struct hostapd_config *conf, const char *pass struct hostapd_bss_config *bss; bss = conf->last_bss; -#define PASS_MIN_LENGTH 8 -#define PASS_MAX_LENGTH 63 - - int len = os_strlen(pass + strlen("wpa_passphrase=")); - if (len < PASS_MIN_LENGTH || len > PASS_MAX_LENGTH) { - wpa_printf(MSG_ERROR, "%s: invalid WPA passphrase length %d (expected 8..63)", - __func__, len); - return 1; - } os_free(bss->ssid.wpa_passphrase); - bss->ssid.wpa_passphrase = os_strdup(pass + strlen("wpa_passphrase=")); + bss->ssid.wpa_passphrase = os_strdup(pass); if (bss->ssid.wpa_passphrase) { hostapd_config_clear_wpa_psk(&bss->ssid.wpa_psk); bss->ssid.wpa_passphrase_set = 1; } return 0; } + +int set_global_hostapd_passphrase(const char *pass) { + if (strlen(pass) > PASS_MAX_LENGTH) { + return -1; + } + os_memset(g_hostapdPassphrase, 0, strlen(g_hostapdPassphrase)); + os_memcpy(g_hostapdPassphrase, pass, strlen(pass)); + return 0; +} #endif /** @@ -5363,23 +5316,11 @@ struct hostapd_config * hostapd_config_read(const char *fname) int errors = 0; size_t i; -#ifdef CONFIG_OPEN_HARMONY_PATCH - char *configfile = NULL; - char *pass = NULL; - char *pass_len = NULL; - errors += hostapd_passphrase_split(fname, &configfile, &pass, &pass_len); - f = fopen(configfile, "r"); - if (f == NULL) { - wpa_printf(MSG_ERROR, "Could not open configuration file '%s' for reading.", configfile); - return NULL; - } -#else f = fopen(fname, "r"); if (f == NULL) { wpa_printf(MSG_ERROR, "Could not open configuration file '%s' for reading.", fname); return NULL; } -#endif conf = hostapd_config_defaults(); if (conf == NULL) { @@ -5429,7 +5370,7 @@ struct hostapd_config * hostapd_config_read(const char *fname) errors += hostapd_config_fill(conf, bss, buf, pos, line); } #ifdef CONFIG_OPEN_HARMONY_PATCH - errors += hostapd_passphrase_config_fill(conf, pass); + errors += hostapd_passphrase_config_fill(conf, g_hostapdPassphrase); #endif fclose(f); @@ -5468,11 +5409,7 @@ struct hostapd_config * hostapd_config_read(const char *fname) #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { -#ifdef CONFIG_OPEN_HARMONY_PATCH - wpa_printf(MSG_ERROR, "%d errors found in configuration file '%s'", errors, configfile); -#else wpa_printf(MSG_ERROR, "%d errors found in configuration file '%s'", errors, fname); -#endif hostapd_config_free(conf); conf = NULL; } diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_ctrl_iface.c b/wpa_supplicant-2.9_standard/hostapd/ap_ctrl_iface.c index c67d226..806cb39 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_ctrl_iface.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_ctrl_iface.c @@ -5026,6 +5026,16 @@ static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces, return 0; } +#ifdef CONFIG_OPEN_HARMONY_PATCH +static int hostapd_ctrl_iface_set_wpa_passphrase(char *buf) +{ + if (set_global_hostapd_passphrase(buf) < 0) { + wpa_printf(MSG_ERROR, "Setting wpa passphrase failed"); + return -1; + } + return 0; +} +#endif static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces, char *buf) @@ -5455,6 +5465,11 @@ static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx, } else if (os_strncmp(buf, "ADD ", 4) == 0) { if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0) reply_len = -1; +#ifdef CONFIG_OPEN_HARMONY_PATCH + } else if (os_strncmp(buf, "SET_WPA_PASS ", 13) == 0) { + if (hostapd_ctrl_iface_set_wpa_passphrase(buf + 13) < 0) + reply_len = -1; +#endif } else if (os_strncmp(buf, "REMOVE ", 7) == 0) { if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0) reply_len = -1; diff --git a/wpa_supplicant-2.9_standard/hostapd/config_file.h b/wpa_supplicant-2.9_standard/hostapd/config_file.h index 9ef6ac8..bb93e49 100644 --- a/wpa_supplicant-2.9_standard/hostapd/config_file.h +++ b/wpa_supplicant-2.9_standard/hostapd/config_file.h @@ -15,5 +15,8 @@ int hostapd_config_read_rxkh_file(struct hostapd_bss_config *conf, int hostapd_set_iface(struct hostapd_config *conf, struct hostapd_bss_config *bss, const char *field, char *value); +#ifdef CONFIG_OPEN_HARMONY_PATCH +int set_global_hostapd_passphrase(const char *pass); +#endif #endif /* CONFIG_FILE_H */ -- Gitee From e8e5a8d3529b8ecc39363a0e1a8e4692e53e24a1 Mon Sep 17 00:00:00 2001 From: TeamCorePro Date: Sat, 12 Apr 2025 14:41:35 +0800 Subject: [PATCH 7/7] passwd new 1 Signed-off-by: TeamCorePro --- wpa_supplicant-2.9_standard/hostapd/ap_config_file.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c index a668244..c9256a5 100755 --- a/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c +++ b/wpa_supplicant-2.9_standard/hostapd/ap_config_file.c @@ -5415,12 +5415,6 @@ struct hostapd_config * hostapd_config_read(const char *fname) } #endif /* WPA_IGNORE_CONFIG_ERRORS */ -#ifdef CONFIG_OPEN_HARMONY_PATCH - os_free(configfile); - os_free(pass); - os_free(pass_len); -#endif - return conf; } -- Gitee