mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 04:50:30 +01:00
wifi: merge branch 'th/wifi-random-hotspot-channel'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1099
This commit is contained in:
commit
aaf952cbc4
6 changed files with 97 additions and 27 deletions
3
NEWS
3
NEWS
|
|
@ -8,6 +8,9 @@ subject to change and not guaranteed to be compatible with
|
|||
the later release.
|
||||
USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
|
||||
|
||||
* Wi-Fi hotspots will use a (stable) random channel number unless one is
|
||||
chosen manually.
|
||||
|
||||
=============================================
|
||||
NetworkManager-1.36
|
||||
Overview of changes since NetworkManager-1.34
|
||||
|
|
|
|||
|
|
@ -3103,28 +3103,75 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|||
static void
|
||||
ensure_hotspot_frequency(NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP *ap)
|
||||
{
|
||||
NMDevice *device = NM_DEVICE(self);
|
||||
const char *band = nm_setting_wireless_get_band(s_wifi);
|
||||
const guint32 a_freqs[] = {5180, 5200, 5220, 5745, 5765, 5785, 5805, 0};
|
||||
const guint32 bg_freqs[] = {2412, 2437, 2462, 2472, 0};
|
||||
guint32 freq = 0;
|
||||
guint32 a_freqs[] = {5180, 5200, 5220, 5745, 5765, 5785, 5805, 0};
|
||||
guint32 bg_freqs[] = {2412, 2437, 2462, 2472, 0};
|
||||
guint32 *rnd_freqs;
|
||||
guint rnd_freqs_len;
|
||||
NMDevice *device = NM_DEVICE(self);
|
||||
const char *band = nm_setting_wireless_get_band(s_wifi);
|
||||
guint32 freq;
|
||||
guint64 rnd;
|
||||
guint i;
|
||||
guint l;
|
||||
|
||||
g_assert(ap);
|
||||
nm_assert(ap);
|
||||
nm_assert(NM_IN_STRSET(band, NULL, "a", "bg"));
|
||||
|
||||
if (nm_wifi_ap_get_freq(ap))
|
||||
return;
|
||||
|
||||
if (g_strcmp0(band, "a") == 0)
|
||||
freq = nm_platform_wifi_find_frequency(nm_device_get_platform(device),
|
||||
nm_device_get_ifindex(device),
|
||||
a_freqs);
|
||||
else
|
||||
freq = nm_platform_wifi_find_frequency(nm_device_get_platform(device),
|
||||
nm_device_get_ifindex(device),
|
||||
bg_freqs);
|
||||
{
|
||||
GBytes *ssid;
|
||||
gsize ssid_len;
|
||||
const guint8 *ssid_data;
|
||||
const guint8 random_seed[16] = {0x9a,
|
||||
0xdc,
|
||||
0x86,
|
||||
0x9a,
|
||||
0xa8,
|
||||
0xa2,
|
||||
0x07,
|
||||
0x97,
|
||||
0xbe,
|
||||
0x6d,
|
||||
0xe6,
|
||||
0x99,
|
||||
0x9f,
|
||||
0xa8,
|
||||
0x09,
|
||||
0x2b};
|
||||
|
||||
if (!freq)
|
||||
freq = (g_strcmp0(band, "a") == 0) ? 5180 : 2462;
|
||||
/* Calculate a stable "random" number based on the SSID. */
|
||||
ssid = nm_setting_wireless_get_ssid(s_wifi);
|
||||
ssid_data = g_bytes_get_data(ssid, &ssid_len);
|
||||
rnd = c_siphash_hash(random_seed, ssid_data, ssid_len);
|
||||
}
|
||||
|
||||
if (nm_streq0(band, "a")) {
|
||||
rnd_freqs = a_freqs;
|
||||
rnd_freqs_len = G_N_ELEMENTS(a_freqs) - 1;
|
||||
} else {
|
||||
rnd_freqs = bg_freqs;
|
||||
rnd_freqs_len = G_N_ELEMENTS(bg_freqs) - 1;
|
||||
}
|
||||
|
||||
/* shuffle the frequencies (inplace). The idea is to choose
|
||||
* a different frequency depending on the SSID. */
|
||||
for (i = 0, l = rnd_freqs_len; l > 1; i++, l--) {
|
||||
/* Add an arbitrary chosen (prime) number to rnd, to get more "random"
|
||||
* numbers. Since we only shuffle a handful of elements, that's good
|
||||
* enough (and stable). */
|
||||
rnd += 5630246189u;
|
||||
NM_SWAP(&rnd_freqs[i], &rnd_freqs[i + (rnd % l)]);
|
||||
}
|
||||
|
||||
freq = nm_platform_wifi_find_frequency(nm_device_get_platform(device),
|
||||
nm_device_get_ifindex(device),
|
||||
rnd_freqs);
|
||||
if (freq == 0)
|
||||
freq = rnd_freqs[0];
|
||||
|
||||
_LOGD(LOGD_WIFI, "set frequency for hotspot AP to %u", freq);
|
||||
|
||||
if (nm_wifi_ap_set_freq(ap, freq))
|
||||
_ap_dump(self, LOGL_DEBUG, ap, "updated", 0);
|
||||
|
|
|
|||
|
|
@ -8451,6 +8451,7 @@ static gboolean
|
|||
wifi_get_capabilities(NMPlatform *platform, int ifindex, _NMDeviceWifiCapabilities *caps)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
if (caps)
|
||||
*caps = nm_wifi_utils_get_caps(wifi_data);
|
||||
return TRUE;
|
||||
|
|
@ -8460,6 +8461,7 @@ static guint32
|
|||
wifi_get_frequency(NMPlatform *platform, int ifindex)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, 0);
|
||||
|
||||
return nm_wifi_utils_get_freq(wifi_data);
|
||||
}
|
||||
|
||||
|
|
@ -8471,6 +8473,7 @@ wifi_get_station(NMPlatform *platform,
|
|||
guint32 *out_rate)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
return nm_wifi_utils_get_station(wifi_data, out_bssid, out_quality, out_rate);
|
||||
}
|
||||
|
||||
|
|
@ -8478,6 +8481,7 @@ static _NM80211Mode
|
|||
wifi_get_mode(NMPlatform *platform, int ifindex)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, _NM_802_11_MODE_UNKNOWN);
|
||||
|
||||
return nm_wifi_utils_get_mode(wifi_data);
|
||||
}
|
||||
|
||||
|
|
@ -8485,6 +8489,7 @@ static void
|
|||
wifi_set_mode(NMPlatform *platform, int ifindex, _NM80211Mode mode)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, );
|
||||
|
||||
nm_wifi_utils_set_mode(wifi_data, mode);
|
||||
}
|
||||
|
||||
|
|
@ -8492,6 +8497,7 @@ static void
|
|||
wifi_set_powersave(NMPlatform *platform, int ifindex, guint32 powersave)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, );
|
||||
|
||||
nm_wifi_utils_set_powersave(wifi_data, powersave);
|
||||
}
|
||||
|
||||
|
|
@ -8499,6 +8505,7 @@ static guint32
|
|||
wifi_find_frequency(NMPlatform *platform, int ifindex, const guint32 *freqs)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, 0);
|
||||
|
||||
return nm_wifi_utils_find_freq(wifi_data, freqs);
|
||||
}
|
||||
|
||||
|
|
@ -8506,6 +8513,7 @@ static void
|
|||
wifi_indicate_addressing_running(NMPlatform *platform, int ifindex, gboolean running)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, );
|
||||
|
||||
nm_wifi_utils_indicate_addressing_running(wifi_data, running);
|
||||
}
|
||||
|
||||
|
|
@ -8513,6 +8521,7 @@ static _NMSettingWirelessWakeOnWLan
|
|||
wifi_get_wake_on_wlan(NMPlatform *platform, int ifindex)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
return nm_wifi_utils_get_wake_on_wlan(wifi_data);
|
||||
}
|
||||
|
||||
|
|
@ -8520,6 +8529,7 @@ static gboolean
|
|||
wifi_set_wake_on_wlan(NMPlatform *platform, int ifindex, _NMSettingWirelessWakeOnWLan wowl)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
return nm_wifi_utils_set_wake_on_wlan(wifi_data, wowl);
|
||||
}
|
||||
|
||||
|
|
@ -8565,6 +8575,7 @@ static guint32
|
|||
mesh_get_channel(NMPlatform *platform, int ifindex)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, 0);
|
||||
|
||||
return nm_wifi_utils_get_mesh_channel(wifi_data);
|
||||
}
|
||||
|
||||
|
|
@ -8572,6 +8583,7 @@ static gboolean
|
|||
mesh_set_channel(NMPlatform *platform, int ifindex, guint32 channel)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
return nm_wifi_utils_set_mesh_channel(wifi_data, channel);
|
||||
}
|
||||
|
||||
|
|
@ -8579,6 +8591,7 @@ static gboolean
|
|||
mesh_set_ssid(NMPlatform *platform, int ifindex, const guint8 *ssid, gsize len)
|
||||
{
|
||||
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE);
|
||||
|
||||
return nm_wifi_utils_set_mesh_ssid(wifi_data, ssid, len);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -382,12 +382,14 @@ wifi_nl80211_find_freq(NMWifiUtils *data, const guint32 *freqs)
|
|||
{
|
||||
NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < self->num_freqs; i++) {
|
||||
while (*freqs) {
|
||||
if (self->freqs[i] == *freqs)
|
||||
return *freqs;
|
||||
freqs++;
|
||||
/* It's important to check the values in the order of @freqs, because
|
||||
* that array might be sorted to contain preferred frequencies first. */
|
||||
for (j = 0; freqs[j] != 0; j++) {
|
||||
for (i = 0; i < self->num_freqs; i++) {
|
||||
if (self->freqs[i] == freqs[j])
|
||||
return freqs[j];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -252,13 +252,15 @@ static guint32
|
|||
wifi_wext_find_freq(NMWifiUtils *data, const guint32 *freqs)
|
||||
{
|
||||
NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data;
|
||||
int i;
|
||||
guint i;
|
||||
guint j;
|
||||
|
||||
for (i = 0; i < wext->num_freqs; i++) {
|
||||
while (*freqs) {
|
||||
if (wext->freqs[i] == *freqs)
|
||||
return *freqs;
|
||||
freqs++;
|
||||
/* It's important to check the values in the order of @freqs, because
|
||||
* that array might be sorted to contain preferred frequencies first. */
|
||||
for (j = 0; freqs[j] != 0; j++) {
|
||||
for (i = 0; i < wext->num_freqs; i++) {
|
||||
if (wext->freqs[i] == freqs[j])
|
||||
return freqs[j];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ _NM80211Mode
|
|||
nm_wifi_utils_get_mode(NMWifiUtils *data)
|
||||
{
|
||||
g_return_val_if_fail(data != NULL, _NM_802_11_MODE_UNKNOWN);
|
||||
|
||||
return NM_WIFI_UTILS_GET_CLASS(data)->get_mode(data);
|
||||
}
|
||||
|
||||
|
|
@ -118,6 +119,7 @@ guint32
|
|||
nm_wifi_utils_get_freq(NMWifiUtils *data)
|
||||
{
|
||||
g_return_val_if_fail(data != NULL, 0);
|
||||
|
||||
return NM_WIFI_UTILS_GET_CLASS(data)->get_freq(data);
|
||||
}
|
||||
|
||||
|
|
@ -126,6 +128,7 @@ nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs)
|
|||
{
|
||||
g_return_val_if_fail(data != NULL, 0);
|
||||
g_return_val_if_fail(freqs != NULL, 0);
|
||||
|
||||
return NM_WIFI_UTILS_GET_CLASS(data)->find_freq(data, freqs);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue