diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/config.c b/wpa_supplicant-2.9_standard/wpa_supplicant/config.c index 2f8e4eddcadda50bcb0994ffcedf6a31f75c0426..8561c74fb6ab7cfa024fbaad30b9195550260568 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/config.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/config.c @@ -2824,6 +2824,9 @@ static const struct parse_data ssid_fields[] = { { FUNC(go_p2p_dev_addr) }, { FUNC(p2p_client_list) }, { FUNC(psk_list) }, +#ifdef CONFIG_OPEN_HARMONY_PATCH + { INT(timestamp) }, +#endif /* CONFIG_OPEN_HARMONY_PATCH */ #endif /* CONFIG_P2P */ #ifdef CONFIG_HT_OVERRIDES { INT_RANGE(disable_ht, 0, 1) }, diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/config_file.c b/wpa_supplicant-2.9_standard/wpa_supplicant/config_file.c index 060f5df560e4da3871917c959db40d636956fe3b..b90b1efa06cde46034d4f5ec9f8383ff938acb6b 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/config_file.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/config_file.c @@ -27,6 +27,9 @@ #ifdef CONFIG_HUKS_ENCRYPTION_SUPPORT #include "common/wpa_common.h" #endif +#ifdef CONFIG_OPEN_HARMONY_PATCH +#define MAX_NETWORK_NUM 12 +#endif /* CONFIG_OPEN_HARMONY_PATCH */ static int wpa_config_validate_network(struct wpa_ssid *ssid, int line) { @@ -397,6 +400,12 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, errors++; continue; } +#ifdef CONFIG_OPEN_HARMONY_PATCH + if ((id >= MAX_NETWORK_NUM + 1) && strstr(name, "p2p_supplicant") != NULL) { + wpa_printf(MSG_ERROR, "wpa_config_read, over max p2p config"); + break; + } +#endif /* CONFIG_OPEN_HARMONY_PATCH */ } else if (os_strcmp(pos, "cred={") == 0) { cred = wpa_config_read_cred(f, &line, cred_id++); if (cred == NULL) { @@ -868,6 +877,9 @@ static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid) write_go_p2p_dev_addr(f, ssid); write_p2p_client_list(f, ssid); write_psk_list(f, ssid); +#ifdef CONFIG_OPEN_HARMONY_PATCH + write_int(f, "timestamp", ssid->timestamp, -1); +#endif /* ONFIG_OPEN_HARMONY_PATCH */ #endif /* CONFIG_P2P */ INT(ap_max_inactivity); INT(dtim_period); diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/config_ssid.h b/wpa_supplicant-2.9_standard/wpa_supplicant/config_ssid.h index 102f97dc12b686b8298b501082330a304a87df29..13321d05be2ec580fb0454fe6acb08de3ec258ed 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/config_ssid.h +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/config_ssid.h @@ -242,6 +242,10 @@ struct wpa_ssid { u8 iv[64]; #endif +#ifdef CONFIG_OPEN_HARMONY_PATCH + u32 timestamp; +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + /** * psk_set - Whether PSK field is configured */ diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c index b6cc3ffc632dedf9db0c15456b9f18187444ab80..efac0906b0e7d600b5f9d619e8291de31ca3b58f 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/ctrl_iface.c @@ -128,6 +128,10 @@ enum { #define DEFAULT_TEMP_ID (-100) #endif /* CONFIG_OPEN_HARMONY_PATCH */ +#ifdef CONFIG_OPEN_HARMONY_PATCH +#define MAX_NETWORK_NUM 12 +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + static int wpa_supplicant_global_iface_list(struct wpa_global *global, char *buf, int len); static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, @@ -2924,6 +2928,89 @@ static int wpa_supplicant_parse_bssid(struct wpa_ssid *ssid, return ret; } +#ifdef CONFIG_OPEN_HARMONY_PATCH +bool is_p2p_connect(struct wpa_global *global) +{ + struct wpa_supplicant *wpa_s; + for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { + if (strncmp(wpa_s->ifname, "p2p", strlen("p2p")) == 0) { + if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { + return true; + } + } + } + return false; +} + +static struct wpa_ssid *get_old_ssid(struct wpa_supplicant *wpa_s) +{ + struct wpa_ssid *oldSsid; + struct wpa_ssid *ssid = NULL; + + oldSsid = wpa_s->conf->ssid; + if (oldSsid) { + ssid = oldSsid->next; + } else { + return NULL; + } + if (!ssid) { + return oldSsid; + } + while (ssid) { + if (ssid->timestamp < oldSsid->timestamp) { + oldSsid = ssid; + } + ssid = ssid->next; + } + return oldSsid; +} + +static void p2p_check_list(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) +{ + int num = 0; + /* When the function returns, the ssid needs to be refreshed to the front of the conf list. */ + if (ssid && strncmp(wpa_s->ifname, "p2p", strlen("p2p")) == 0 && !is_p2p_connect(wpa_s->global)) { + while (ssid) { + ssid = ssid->next; + num++; + } + if (num <= MAX_NETWORK_NUM) { + ssid = wpa_s->conf->ssid; + return; + } + while (num > MAX_NETWORK_NUM) { + struct wpa_ssid *old_ssid = get_old_ssid(wpa_s); + if (!old_ssid) { + break; + } + wpa_printf(MSG_INFO, "p2p_check_list remove id %d", old_ssid->id); + wpa_config_remove_network(wpa_s->conf, old_ssid->id); + num = 0; + ssid = wpa_s->conf->ssid; + while (ssid) { + ssid = ssid->next; + num++; + } + } + wpa_config_write(wpa_s->confname, wpa_s->conf); + ssid = wpa_s->conf->ssid; + } +} +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + +static void skip_over_ssid(char *cmd, struct wpa_ssid *ssid) +{ + /* skip over ssids until we find next one */ + if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { + int last_id = atoi(cmd + 8); + if (last_id != -1) { + while (ssid != NULL && ssid->id <= last_id) { + ssid = ssid->next; + } + } + } +} + int wpa_supplicant_ctrl_iface_list_networks( struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen) { @@ -2940,16 +3027,10 @@ int wpa_supplicant_ctrl_iface_list_networks( pos += ret; ssid = wpa_s->conf->ssid; - - /* skip over ssids until we find next one */ - if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) { - int last_id = atoi(cmd + 8); - if (last_id != -1) { - while (ssid != NULL && ssid->id <= last_id) { - ssid = ssid->next; - } - } - } +#ifdef CONFIG_OPEN_HARMONY_PATCH + p2p_check_list(wpa_s, ssid); +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + skip_over_ssid(cmd, ssid); while (ssid) { prev = pos; diff --git a/wpa_supplicant-2.9_standard/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant-2.9_standard/wpa_supplicant/p2p_supplicant.c index 52f035ee4f8f9c3d310ca19491eb043e90c55691..38a5d3b891fb430154d1ab6c07e90f89753148da 100644 --- a/wpa_supplicant-2.9_standard/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant-2.9_standard/wpa_supplicant/p2p_supplicant.c @@ -148,6 +148,10 @@ #define HISI_FREQ_5G_MIN 5180 #endif +#ifdef CONFIG_OPEN_HARMONY_PATCH +#define P2P_TIMESTAMP_MIN_INTERVAL 10 +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + enum p2p_group_removal_reason { P2P_GROUP_REMOVAL_UNKNOWN, P2P_GROUP_REMOVAL_SILENT, @@ -1330,6 +1334,46 @@ static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s, return !!(group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP); } +static void p2p_set_ssid_info(struct wpa_ssid *s, struct wpa_ssid *ssid, + const u8 *go_dev_addr) +{ + if (s && ssid) { + s->p2p_group = 1; + s->p2p_persistent_group = 1; + s->disabled = 2; + s->bssid_set = 1; + os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); + s->mode = ssid->mode; + s->auth_alg = WPA_AUTH_ALG_OPEN; + s->key_mgmt = WPA_KEY_MGMT_PSK; + s->proto = WPA_PROTO_RSN; + s->pbss = ssid->pbss; + s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; + s->export_keys = 1; +#ifdef CONFIG_OPEN_HARMONY_PATCH + s->timestamp = ssid->timestamp; +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + if (ssid->passphrase) { + os_free(s->passphrase); + s->passphrase = os_strdup(ssid->passphrase); + } + if (ssid->psk_set) { + s->psk_set = 1; + os_memcpy(s->psk, ssid->psk, 32); + } + if (s->passphrase && !s->psk_set) + wpa_config_update_psk(s); + if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { + os_free(s->ssid); + s->ssid = os_malloc(ssid->ssid_len); + } + if (s->ssid) { + s->ssid_len = ssid->ssid_len; + os_memcpy(s->ssid, ssid->ssid, s->ssid_len); + } + } +} + static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, @@ -1337,15 +1381,33 @@ static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, { struct wpa_ssid *s; int changed = 0; +#ifdef CONFIG_OPEN_HARMONY_PATCH + struct os_time now; +#endif /* ONFIG_OPEN_HARMONY_PATCH */ wpa_printf(MSG_INFO, "P2P: Storing credentials for a persistent " "group (GO Dev Addr " MACSTR_SEC ")", MAC2STR_SEC(go_dev_addr)); + +#ifdef CONFIG_OPEN_HARMONY_PATCH + os_get_time(&now); + if (now.sec > ssid->timestamp) { + ssid->timestamp = now.sec; + } +#endif /* ONFIG_OPEN_HARMONY_PATCH */ + for (s = wpa_s->conf->ssid; s; s = s->next) { if (s->disabled == 2 && ether_addr_equal(go_dev_addr, s->bssid) && s->ssid_len == ssid->ssid_len && - os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) + os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0) { +#ifdef CONFIG_OPEN_HARMONY_PATCH + if ((unsigned int)now.sec > s->timestamp + P2P_TIMESTAMP_MIN_INTERVAL) { + s->timestamp = now.sec; + wpa_config_write(wpa_s->confname, wpa_s->conf); + } +#endif /* ONFIG_OPEN_HARMONY_PATCH */ break; + } } if (s) { @@ -1376,36 +1438,7 @@ static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s, wpa_config_set_network_defaults(s); } - s->p2p_group = 1; - s->p2p_persistent_group = 1; - s->disabled = 2; - s->bssid_set = 1; - os_memcpy(s->bssid, go_dev_addr, ETH_ALEN); - s->mode = ssid->mode; - s->auth_alg = WPA_AUTH_ALG_OPEN; - s->key_mgmt = WPA_KEY_MGMT_PSK; - s->proto = WPA_PROTO_RSN; - s->pbss = ssid->pbss; - s->pairwise_cipher = ssid->pbss ? WPA_CIPHER_GCMP : WPA_CIPHER_CCMP; - s->export_keys = 1; - if (ssid->passphrase) { - os_free(s->passphrase); - s->passphrase = os_strdup(ssid->passphrase); - } - if (ssid->psk_set) { - s->psk_set = 1; - os_memcpy(s->psk, ssid->psk, 32); - } - if (s->passphrase && !s->psk_set) - wpa_config_update_psk(s); - if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) { - os_free(s->ssid); - s->ssid = os_malloc(ssid->ssid_len); - } - if (s->ssid) { - s->ssid_len = ssid->ssid_len; - os_memcpy(s->ssid, ssid->ssid, s->ssid_len); - } + p2p_set_ssid_info(s, ssid, go_dev_addr); if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) { dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list); wpa_s->global->add_psk = NULL;