Make random MAC address style parameters use common enum values
This makes the implementation more readable by sharing the same set of enum values for all the parameters related to what kind of random MAC addresses are used. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
681856c355
commit
1d4027fdbe
5 changed files with 28 additions and 18 deletions
|
@ -2372,7 +2372,7 @@ static char * wpa_config_write_mac_value(const struct parse_data *data,
|
||||||
char *value;
|
char *value;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (ssid->mac_addr != 3)
|
if (ssid->mac_addr != WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
value = os_malloc(size);
|
value = os_malloc(size);
|
||||||
|
@ -3226,7 +3226,7 @@ void wpa_config_set_network_defaults(struct wpa_ssid *ssid)
|
||||||
#ifdef CONFIG_MACSEC
|
#ifdef CONFIG_MACSEC
|
||||||
ssid->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
|
ssid->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
|
||||||
#endif /* CONFIG_MACSEC */
|
#endif /* CONFIG_MACSEC */
|
||||||
ssid->mac_addr = -1;
|
ssid->mac_addr = WPAS_MAC_ADDR_STYLE_NOT_SET;
|
||||||
ssid->max_oper_chwidth = DEFAULT_MAX_OPER_CHWIDTH;
|
ssid->max_oper_chwidth = DEFAULT_MAX_OPER_CHWIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5437,9 +5437,9 @@ static const struct global_parse_data global_fields[] = {
|
||||||
{ STR(osu_dir), 0 },
|
{ STR(osu_dir), 0 },
|
||||||
{ STR(wowlan_triggers), CFG_CHANGED_WOWLAN_TRIGGERS },
|
{ STR(wowlan_triggers), CFG_CHANGED_WOWLAN_TRIGGERS },
|
||||||
{ INT(p2p_search_delay), 0},
|
{ INT(p2p_search_delay), 0},
|
||||||
{ INT(mac_addr), 0 },
|
{ INT_RANGE(mac_addr, 0, 2), 0 },
|
||||||
{ INT(rand_addr_lifetime), 0 },
|
{ INT(rand_addr_lifetime), 0 },
|
||||||
{ INT(preassoc_mac_addr), 0 },
|
{ INT_RANGE(preassoc_mac_addr, 0, 2), 0 },
|
||||||
{ INT(key_mgmt_offload), 0},
|
{ INT(key_mgmt_offload), 0},
|
||||||
{ INT(passive_scan), 0 },
|
{ INT(passive_scan), 0 },
|
||||||
{ INT(reassoc_same_bss_optim), 0 },
|
{ INT(reassoc_same_bss_optim), 0 },
|
||||||
|
|
|
@ -1407,7 +1407,7 @@ struct wpa_config {
|
||||||
* the per-network mac_addr parameter. Global mac_addr=1 can be used to
|
* the per-network mac_addr parameter. Global mac_addr=1 can be used to
|
||||||
* change this default behavior.
|
* change this default behavior.
|
||||||
*/
|
*/
|
||||||
int mac_addr;
|
enum wpas_mac_addr_style mac_addr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rand_addr_lifetime - Lifetime of random MAC address in seconds
|
* rand_addr_lifetime - Lifetime of random MAC address in seconds
|
||||||
|
@ -1421,7 +1421,7 @@ struct wpa_config {
|
||||||
* 1 = use random MAC address
|
* 1 = use random MAC address
|
||||||
* 2 = like 1, but maintain OUI (with local admin bit set)
|
* 2 = like 1, but maintain OUI (with local admin bit set)
|
||||||
*/
|
*/
|
||||||
int preassoc_mac_addr;
|
enum wpas_mac_addr_style preassoc_mac_addr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* key_mgmt_offload - Use key management offload
|
* key_mgmt_offload - Use key management offload
|
||||||
|
@ -1623,7 +1623,7 @@ struct wpa_config {
|
||||||
* 1 = use random MAC address
|
* 1 = use random MAC address
|
||||||
* 2 = like 1, but maintain OUI (with local admin bit set)
|
* 2 = like 1, but maintain OUI (with local admin bit set)
|
||||||
*/
|
*/
|
||||||
int gas_rand_mac_addr;
|
enum wpas_mac_addr_style gas_rand_mac_addr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dpp_config_processing - How to process DPP configuration
|
* dpp_config_processing - How to process DPP configuration
|
||||||
|
|
|
@ -71,6 +71,14 @@ enum sae_pk_mode {
|
||||||
SAE_PK_MODE_DISABLED = 2,
|
SAE_PK_MODE_DISABLED = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum wpas_mac_addr_style {
|
||||||
|
WPAS_MAC_ADDR_STYLE_NOT_SET = -1,
|
||||||
|
WPAS_MAC_ADDR_STYLE_PERMANENT = 0,
|
||||||
|
WPAS_MAC_ADDR_STYLE_RANDOM = 1,
|
||||||
|
WPAS_MAC_ADDR_STYLE_RANDOM_SAME_OUI = 2,
|
||||||
|
WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS = 3,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct wpa_ssid - Network configuration data
|
* struct wpa_ssid - Network configuration data
|
||||||
*
|
*
|
||||||
|
@ -995,7 +1003,7 @@ struct wpa_ssid {
|
||||||
* was not specified in the configuration (i.e., default behavior is
|
* was not specified in the configuration (i.e., default behavior is
|
||||||
* followed).
|
* followed).
|
||||||
*/
|
*/
|
||||||
int mac_addr;
|
enum wpas_mac_addr_style mac_addr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mac_value - Specific MAC address to be used
|
* mac_value - Specific MAC address to be used
|
||||||
|
|
|
@ -2230,7 +2230,8 @@ void wpas_connect_work_done(struct wpa_supplicant *wpa_s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style,
|
int wpas_update_random_addr(struct wpa_supplicant *wpa_s,
|
||||||
|
enum wpas_mac_addr_style style,
|
||||||
struct wpa_ssid *ssid)
|
struct wpa_ssid *ssid)
|
||||||
{
|
{
|
||||||
struct os_reltime now;
|
struct os_reltime now;
|
||||||
|
@ -2240,7 +2241,7 @@ int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style,
|
||||||
/* Random addresses are valid within a given ESS so check
|
/* Random addresses are valid within a given ESS so check
|
||||||
* expiration/value only when continuing to use the same ESS. */
|
* expiration/value only when continuing to use the same ESS. */
|
||||||
if (wpa_s->last_mac_addr_style == style && wpa_s->reassoc_same_ess) {
|
if (wpa_s->last_mac_addr_style == style && wpa_s->reassoc_same_ess) {
|
||||||
if (style == 3) {
|
if (style == WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS) {
|
||||||
/* Pregenerated addresses do not expire but their value
|
/* Pregenerated addresses do not expire but their value
|
||||||
* might have changed, so let's check that. */
|
* might have changed, so let's check that. */
|
||||||
if (os_memcmp(wpa_s->own_addr, ssid->mac_value,
|
if (os_memcmp(wpa_s->own_addr, ssid->mac_value,
|
||||||
|
@ -2259,16 +2260,16 @@ int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (style) {
|
switch (style) {
|
||||||
case 1:
|
case WPAS_MAC_ADDR_STYLE_RANDOM:
|
||||||
if (random_mac_addr(addr) < 0)
|
if (random_mac_addr(addr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case WPAS_MAC_ADDR_STYLE_RANDOM_SAME_OUI:
|
||||||
os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN);
|
os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN);
|
||||||
if (random_mac_addr_keep_oui(addr) < 0)
|
if (random_mac_addr_keep_oui(addr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case WPAS_MAC_ADDR_STYLE_DEDICATED_PER_ESS:
|
||||||
if (!ssid) {
|
if (!ssid) {
|
||||||
wpa_msg(wpa_s, MSG_INFO,
|
wpa_msg(wpa_s, MSG_INFO,
|
||||||
"Invalid 'ssid' for address policy 3");
|
"Invalid 'ssid' for address policy 3");
|
||||||
|
@ -2402,7 +2403,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
|
||||||
struct wpa_bss *bss, struct wpa_ssid *ssid)
|
struct wpa_bss *bss, struct wpa_ssid *ssid)
|
||||||
{
|
{
|
||||||
struct wpa_connect_work *cwork;
|
struct wpa_connect_work *cwork;
|
||||||
int rand_style;
|
enum wpas_mac_addr_style rand_style;
|
||||||
|
|
||||||
wpa_s->own_disconnect_req = 0;
|
wpa_s->own_disconnect_req = 0;
|
||||||
wpa_s->own_reconnect_req = 0;
|
wpa_s->own_reconnect_req = 0;
|
||||||
|
@ -2414,7 +2415,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
|
||||||
wpabuf_free(wpa_s->pending_eapol_rx);
|
wpabuf_free(wpa_s->pending_eapol_rx);
|
||||||
wpa_s->pending_eapol_rx = NULL;
|
wpa_s->pending_eapol_rx = NULL;
|
||||||
|
|
||||||
if (ssid->mac_addr == -1)
|
if (ssid->mac_addr == WPAS_MAC_ADDR_STYLE_NOT_SET)
|
||||||
rand_style = wpa_s->conf->mac_addr;
|
rand_style = wpa_s->conf->mac_addr;
|
||||||
else
|
else
|
||||||
rand_style = ssid->mac_addr;
|
rand_style = ssid->mac_addr;
|
||||||
|
@ -2446,14 +2447,15 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
|
||||||
wpa_s_setup_sae_pt(wpa_s->conf, ssid);
|
wpa_s_setup_sae_pt(wpa_s->conf, ssid);
|
||||||
#endif /* CONFIG_SAE */
|
#endif /* CONFIG_SAE */
|
||||||
|
|
||||||
if (rand_style > 0) {
|
if (rand_style > WPAS_MAC_ADDR_STYLE_PERMANENT) {
|
||||||
int status = wpas_update_random_addr(wpa_s, rand_style, ssid);
|
int status = wpas_update_random_addr(wpa_s, rand_style, ssid);
|
||||||
|
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return;
|
return;
|
||||||
if (status > 0) /* MAC changed */
|
if (status > 0) /* MAC changed */
|
||||||
wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
|
wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
|
||||||
} else if (rand_style == 0 && wpa_s->mac_addr_changed) {
|
} else if (rand_style == WPAS_MAC_ADDR_STYLE_PERMANENT &&
|
||||||
|
wpa_s->mac_addr_changed) {
|
||||||
if (wpas_restore_permanent_mac_addr(wpa_s) < 0)
|
if (wpas_restore_permanent_mac_addr(wpa_s) < 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -928,7 +928,7 @@ struct wpa_supplicant {
|
||||||
unsigned int disable_mbo_oce:1;
|
unsigned int disable_mbo_oce:1;
|
||||||
|
|
||||||
struct os_reltime last_mac_addr_change;
|
struct os_reltime last_mac_addr_change;
|
||||||
int last_mac_addr_style;
|
enum wpas_mac_addr_style last_mac_addr_style;
|
||||||
|
|
||||||
struct ibss_rsn *ibss_rsn;
|
struct ibss_rsn *ibss_rsn;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue