merge: branch 'bg/hotspot-fixes'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1578

(cherry picked from commit afd1a7b9a6)
This commit is contained in:
Beniamino Galvani 2023-03-28 10:02:23 +02:00
commit ccf220c71c
11 changed files with 60 additions and 42 deletions

View file

@ -3227,7 +3227,8 @@ ensure_hotspot_frequency(NMDeviceWifi *self, NMSettingWireless *s_wifi, NMWifiAP
freq = nm_platform_wifi_find_frequency(nm_device_get_platform(device),
nm_device_get_ifindex(device),
rnd_freqs);
rnd_freqs,
TRUE);
if (freq == 0)
freq = rnd_freqs[0];

View file

@ -835,7 +835,7 @@ wifi_set_mode(NMPlatform *platform, int ifindex, _NM80211Mode mode)
}
static guint32
wifi_find_frequency(NMPlatform *platform, int ifindex, const guint32 *freqs)
wifi_find_frequency(NMPlatform *platform, int ifindex, const guint32 *freqs, gboolean ap)
{
return freqs[0];
}

View file

@ -9291,11 +9291,11 @@ wifi_set_powersave(NMPlatform *platform, int ifindex, guint32 powersave)
}
static guint32
wifi_find_frequency(NMPlatform *platform, int ifindex, const guint32 *freqs)
wifi_find_frequency(NMPlatform *platform, int ifindex, const guint32 *freqs, gboolean ap)
{
WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, 0);
return nm_wifi_utils_find_freq(wifi_data, freqs);
return nm_wifi_utils_find_freq(wifi_data, freqs, ap);
}
static void

View file

@ -3192,14 +3192,14 @@ nm_platform_wifi_set_powersave(NMPlatform *self, int ifindex, guint32 powersave)
}
guint32
nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs)
nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs, gboolean ap)
{
_CHECK_SELF(self, klass, 0);
g_return_val_if_fail(ifindex > 0, 0);
g_return_val_if_fail(freqs != NULL, 0);
return klass->wifi_find_frequency(self, ifindex, freqs);
return klass->wifi_find_frequency(self, ifindex, freqs, ap);
}
void

View file

@ -1183,7 +1183,10 @@ typedef struct {
_NM80211Mode (*wifi_get_mode)(NMPlatform *self, int ifindex);
void (*wifi_set_mode)(NMPlatform *self, int ifindex, _NM80211Mode mode);
void (*wifi_set_powersave)(NMPlatform *self, int ifindex, guint32 powersave);
guint32 (*wifi_find_frequency)(NMPlatform *self, int ifindex, const guint32 *freqs);
guint32 (*wifi_find_frequency)(NMPlatform *self,
int ifindex,
const guint32 *freqs,
gboolean ap);
void (*wifi_indicate_addressing_running)(NMPlatform *self, int ifindex, gboolean running);
_NMSettingWirelessWakeOnWLan (*wifi_get_wake_on_wlan)(NMPlatform *self, int ifindex);
gboolean (*wifi_set_wake_on_wlan)(NMPlatform *self,
@ -2063,7 +2066,8 @@ gboolean nm_platform_wifi_get_station(NMPlatform *self,
_NM80211Mode nm_platform_wifi_get_mode(NMPlatform *self, int ifindex);
void nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, _NM80211Mode mode);
void nm_platform_wifi_set_powersave(NMPlatform *self, int ifindex, guint32 powersave);
guint32 nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs);
guint32
nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs, gboolean ap);
void nm_platform_wifi_indicate_addressing_running(NMPlatform *self, int ifindex, gboolean running);
_NMSettingWirelessWakeOnWLan nm_platform_wifi_get_wake_on_wlan(NMPlatform *self, int ifindex);
gboolean

View file

@ -41,10 +41,16 @@
} \
G_STMT_END
typedef struct {
guint32 freq;
bool disabled : 1;
bool no_ir : 1;
} Nl80211Freq;
typedef struct {
NMWifiUtils parent;
struct nl_sock *nl_sock;
guint32 *freqs;
Nl80211Freq *freqs;
int num_freqs;
int phy;
guint16 genl_family_id;
@ -379,7 +385,7 @@ wifi_nl80211_get_freq(NMWifiUtils *data)
}
static guint32
wifi_nl80211_find_freq(NMWifiUtils *data, const guint32 *freqs)
wifi_nl80211_find_freq(NMWifiUtils *data, const guint32 *freqs, gboolean ap)
{
NMWifiUtilsNl80211 *self = (NMWifiUtilsNl80211 *) data;
int i;
@ -389,7 +395,11 @@ wifi_nl80211_find_freq(NMWifiUtils *data, const guint32 *freqs)
* 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])
if (self->freqs[i].disabled)
continue;
if (ap && self->freqs[i].no_ir)
continue;
if (self->freqs[i].freq == freqs[j])
return freqs[j];
}
}
@ -555,7 +565,7 @@ nla_put_failure:
struct nl80211_device_info {
NMWifiUtilsNl80211 *self;
int phy;
guint32 *freqs;
Nl80211Freq *freqs;
int num_freqs;
guint32 freq;
guint32 caps;
@ -657,40 +667,45 @@ nl80211_wiphy_info_handler(const struct nl_msg *msg, void *arg)
/* Read supported frequencies */
num_alloc = 32;
info->num_freqs = 0;
info->freqs = g_new(guint32, num_alloc);
info->freqs = g_new(Nl80211Freq, num_alloc);
nla_for_each_nested (nl_band, tb[NL80211_ATTR_WIPHY_BANDS], rem_band) {
if (nla_parse_nested_arr(tb_band, nl_band, NULL) < 0)
return NL_SKIP;
nla_for_each_nested (nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
Nl80211Freq *f;
if (nla_parse_nested_arr(tb_freq, nl_freq, freq_policy) < 0)
continue;
if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
continue;
if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
continue;
if (info->num_freqs >= num_alloc) {
num_alloc *= 2;
info->freqs = g_renew(guint32, info->freqs, num_alloc);
info->freqs = g_renew(Nl80211Freq, info->freqs, num_alloc);
}
info->freqs[info->num_freqs] = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
f = &info->freqs[info->num_freqs];
*f = (Nl80211Freq){
.freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]),
.disabled = !!tb_freq[NL80211_FREQUENCY_ATTR_DISABLED],
.no_ir = !!tb_freq[NL80211_FREQUENCY_ATTR_NO_IR],
};
info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_VALID;
if (info->freqs[info->num_freqs] > 2400 && info->freqs[info->num_freqs] < 2500)
if (f->freq > 2400 && f->freq < 2500)
info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_2GHZ;
if (info->freqs[info->num_freqs] > 4900 && info->freqs[info->num_freqs] < 6000)
if (f->freq > 4900 && f->freq < 6000)
info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_5GHZ;
info->num_freqs++;
}
}
info->freqs = g_renew(guint32, info->freqs, info->num_freqs);
info->freqs = g_renew(Nl80211Freq, info->freqs, info->num_freqs);
/* Read security/encryption support */
if (tb[NL80211_ATTR_CIPHER_SUITES]) {
@ -769,7 +784,7 @@ wifi_nl80211_get_mesh_channel(NMWifiUtils *data)
}
for (i = 0; i < self->num_freqs; i++) {
if (device_info.freq == self->freqs[i])
if (device_info.freq == self->freqs[i].freq)
return i + 1;
}
return 0;
@ -786,7 +801,7 @@ wifi_nl80211_set_mesh_channel(NMWifiUtils *data, guint32 channel)
return FALSE;
msg = nl80211_alloc_msg(self, NL80211_CMD_SET_WIPHY, 0);
NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, self->freqs[channel - 1]);
NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, self->freqs[channel - 1].freq);
err = nl80211_send_and_recv(self, msg, NULL, NULL);
return err >= 0;

View file

@ -28,8 +28,9 @@ typedef struct {
/* Return current frequency in MHz (really associated BSS frequency) */
guint32 (*get_freq)(NMWifiUtils *data);
/* Return first supported frequency in the zero-terminated list */
guint32 (*find_freq)(NMWifiUtils *data, const guint32 *freqs);
/* Return first supported frequency in the zero-terminated list. @ap
* indicates that the frequency must be suited for AP mode. */
guint32 (*find_freq)(NMWifiUtils *data, const guint32 *freqs, gboolean ap);
/*
* @out_bssid: must be NULL or an ETH_ALEN-byte buffer

View file

@ -249,7 +249,7 @@ wifi_wext_get_freq(NMWifiUtils *data)
}
static guint32
wifi_wext_find_freq(NMWifiUtils *data, const guint32 *freqs)
wifi_wext_find_freq(NMWifiUtils *data, const guint32 *freqs, gboolean ap)
{
NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data;
guint i;

View file

@ -124,12 +124,12 @@ nm_wifi_utils_get_freq(NMWifiUtils *data)
}
guint32
nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs)
nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs, gboolean ap)
{
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);
return NM_WIFI_UTILS_GET_CLASS(data)->find_freq(data, freqs, ap);
}
gboolean

View file

@ -39,7 +39,7 @@ guint32 nm_wifi_utils_get_freq(NMWifiUtils *data);
/* Return the first supported frequency in the zero-terminated list.
* Frequencies are specified in MHz. */
guint32 nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs);
guint32 nm_wifi_utils_find_freq(NMWifiUtils *data, const guint32 *freqs, gboolean ap);
/*
* @out_bssid: must be NULL or an ETH_ALEN-byte buffer

View file

@ -4091,7 +4091,7 @@ generate_ssid_for_hotspot(void)
return ssid_bytes;
}
#define WPA_PASSKEY_SIZE 8
#define WPA_PASSKEY_SIZE 12
static void
generate_wpa_key(char *key, size_t len)
{
@ -4100,14 +4100,14 @@ generate_wpa_key(char *key, size_t len)
g_return_if_fail(key);
g_return_if_fail(len > WPA_PASSKEY_SIZE);
/* generate a 8-chars ASCII WPA key */
for (i = 0; i < WPA_PASSKEY_SIZE; i++) {
int c;
do {
c = nm_random_u64_range_full(33, 126, TRUE);
/* too many non alphanumeric characters are hard to remember for humans */
} while (g_ascii_isalnum(c));
c = nm_random_u64_range_full(48, 122, TRUE);
/* skip characters that look similar */
} while (NM_IN_SET(c, '1', 'l', 'I', '0', 'O', 'Q', '8', 'B', '5', 'S')
|| !g_ascii_isalnum(c));
key[i] = (char) c;
}
@ -4141,7 +4141,7 @@ set_wireless_security_for_hotspot(NMSettingWirelessSecurity *s_wsec,
gboolean show_password,
GError **error)
{
char generated_key[11];
char generated_key[20];
const char *key;
const char *key_mgmt;
@ -4267,6 +4267,8 @@ create_hotspot_conn(const GPtrArray *connections,
NMSettingIPConfig *s_ip4, *s_ip6;
NMSettingProxy *s_proxy;
nm_assert(channel_int == -1 || band);
connection = nm_simple_connection_new();
s_con = (NMSettingConnection *) nm_setting_connection_new();
nm_connection_add_setting(connection, NM_SETTING(s_con));
@ -4297,6 +4299,8 @@ create_hotspot_conn(const GPtrArray *connections,
NM_SETTING_WIRELESS_BAND,
band,
NULL);
} else if (band) {
g_object_set(s_wifi, NM_SETTING_WIRELESS_BAND, band, NULL);
}
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
@ -4442,13 +4446,6 @@ do_device_wifi_hotspot(const NMCCommand *cmd, NmCli *nmc, int argc, const char *
if (nmc->complete)
return;
/* Verify band and channel parameters */
if (!channel) {
if (g_strcmp0(band, "bg") == 0)
channel = "1";
if (g_strcmp0(band, "a") == 0)
channel = "7";
}
if (channel) {
unsigned long int value;