mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-23 06:02:37 +01:00
wiphy: add _generate_address_from_ssid
This API is being added to support per-network MAC address generation. The MAC is generated based on the network SSID and the adapters permanent address using HMAC-SHA256. The SHA digest is then constrained to make it MAC address compliant. Generating the MAC address like this will ensure that the MAC remains the same each time a given SSID is connected to.
This commit is contained in:
parent
60bb42087a
commit
1f14782857
34
src/wiphy.c
34
src/wiphy.c
@ -435,12 +435,10 @@ const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy)
|
|||||||
return wiphy->rm_enabled_capabilities;
|
return wiphy->rm_enabled_capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6])
|
static void wiphy_address_constrain(struct wiphy *wiphy, uint8_t addr[static 6])
|
||||||
{
|
{
|
||||||
switch (mac_randomize_bytes) {
|
switch (mac_randomize_bytes) {
|
||||||
case 6:
|
case 6:
|
||||||
l_getrandom(addr, 6);
|
|
||||||
|
|
||||||
/* Set the locally administered bit */
|
/* Set the locally administered bit */
|
||||||
addr[0] |= 0x2;
|
addr[0] |= 0x2;
|
||||||
|
|
||||||
@ -448,7 +446,6 @@ void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6])
|
|||||||
addr[0] &= 0xfe;
|
addr[0] &= 0xfe;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
l_getrandom(addr + 3, 3);
|
|
||||||
memcpy(addr, wiphy->permanent_addr, 3);
|
memcpy(addr, wiphy->permanent_addr, 3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -464,6 +461,35 @@ void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6])
|
|||||||
addr[5] = 0x01;
|
addr[5] = 0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6])
|
||||||
|
{
|
||||||
|
switch (mac_randomize_bytes) {
|
||||||
|
case 6:
|
||||||
|
l_getrandom(addr, 6);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
l_getrandom(addr + 3, 3);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wiphy_address_constrain(wiphy, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid,
|
||||||
|
uint8_t addr[static 6])
|
||||||
|
{
|
||||||
|
struct l_checksum *sha = l_checksum_new(L_CHECKSUM_SHA256);
|
||||||
|
|
||||||
|
l_checksum_update(sha, ssid, strlen(ssid));
|
||||||
|
l_checksum_update(sha, wiphy->permanent_addr,
|
||||||
|
sizeof(wiphy->permanent_addr));
|
||||||
|
l_checksum_get_digest(sha, addr, mac_randomize_bytes);
|
||||||
|
|
||||||
|
l_checksum_free(sha);
|
||||||
|
|
||||||
|
wiphy_address_constrain(wiphy, addr);
|
||||||
|
}
|
||||||
|
|
||||||
bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
|
bool wiphy_constrain_freq_set(const struct wiphy *wiphy,
|
||||||
struct scan_freq_set *set)
|
struct scan_freq_set *set)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +82,8 @@ const uint8_t *wiphy_get_extended_capabilities(struct wiphy *wiphy,
|
|||||||
const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy);
|
const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy);
|
||||||
|
|
||||||
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
|
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
|
||||||
|
void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid,
|
||||||
|
uint8_t addr[static 6]);
|
||||||
|
|
||||||
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
|
uint32_t wiphy_state_watch_add(struct wiphy *wiphy,
|
||||||
wiphy_state_watch_func_t func, void *user_data,
|
wiphy_state_watch_func_t func, void *user_data,
|
||||||
|
Loading…
Reference in New Issue
Block a user