libnm: add utility functions for getting 2.4 GHz and 5 GHz Wi-Fi frequencies

nm_utils_wifi_2ghz_freqs()
nm_utils_wifi_5ghz_freqs()

(cherry picked from commit 1a6b631690)
This commit is contained in:
Jiří Klimeš 2015-08-18 09:37:48 +02:00
parent c8b5b5eb1c
commit 77bf69c3dc
3 changed files with 61 additions and 0 deletions

View file

@ -2692,6 +2692,61 @@ nm_utils_wifi_is_channel_valid (guint32 channel, const char *band)
return FALSE;
}
static const guint *
_wifi_freqs (gboolean bg_band)
{
static guint *freqs_2ghz = NULL;
static guint *freqs_5ghz = NULL;
guint *freqs;
freqs = bg_band ? freqs_2ghz : freqs_5ghz;
if (G_UNLIKELY (freqs == NULL)) {
struct cf_pair *table;
int i;
table = bg_band ? bg_table : a_table;
freqs = g_new0 (guint, bg_band ? G_N_ELEMENTS (bg_table) : G_N_ELEMENTS (a_table));
for (i = 0; table[i].chan; i++)
freqs[i] = table[i].freq;
freqs[i] = 0;
if (bg_band)
freqs_2ghz = freqs;
else
freqs_5ghz = freqs;
}
return freqs;
}
/**
* nm_utils_wifi_2ghz_freqs:
*
* Utility function to return 2.4 GHz Wi-Fi frequencies (802.11bg band).
*
* Returns: zero-terminated array of frequencies numbers (in MHz)
*
* Since: 1.0.6
**/
const guint *
nm_utils_wifi_2ghz_freqs (void)
{
return _wifi_freqs (TRUE);
}
/**
* nm_utils_wifi_5ghz_freqs:
*
* Utility function to return 5 GHz Wi-Fi frequencies (802.11a band).
*
* Returns: zero-terminated array of frequencies numbers (in MHz)
*
* Since: 1.0.6
**/
const guint *
nm_utils_wifi_5ghz_freqs (void)
{
return _wifi_freqs (FALSE);
}
/**
* nm_utils_wifi_strength_bars:
* @strength: the access point strength, from 0 to 100

View file

@ -140,6 +140,10 @@ guint32 nm_utils_wifi_freq_to_channel (guint32 freq);
guint32 nm_utils_wifi_channel_to_freq (guint32 channel, const char *band);
guint32 nm_utils_wifi_find_next_channel (guint32 channel, int direction, char *band);
gboolean nm_utils_wifi_is_channel_valid (guint32 channel, const char *band);
NM_AVAILABLE_IN_1_0_6
const guint *nm_utils_wifi_2ghz_freqs (void);
NM_AVAILABLE_IN_1_0_6
const guint *nm_utils_wifi_5ghz_freqs (void);
const char *nm_utils_wifi_strength_bars (guint8 strength);

View file

@ -859,5 +859,7 @@ global:
nm_device_wifi_request_scan_options_async;
nm_metered_get_type;
nm_setting_connection_get_metered;
nm_utils_wifi_2ghz_freqs;
nm_utils_wifi_5ghz_freqs;
} libnm_1_0_4;