diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2015-08-18 09:37:48 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-08-20 11:48:02 +0200 |
commit | 91977ee2b4e5e27533c725088213c3b3deb15faf (patch) | |
tree | f0e71c5f80f7c6c8809207f56adf19d005785c3d | |
parent | d98816032075eef6c7920b6ad67394b01e6865f8 (diff) | |
download | NetworkManager-91977ee2b4e5e27533c725088213c3b3deb15faf.tar.gz |
libnm: add utility functions for getting 2.4 GHz and 5 GHz Wi-Fi frequences
nm_utils_wifi_2ghz_freqs()
nm_utils_wifi_5ghz_freqs()
-rw-r--r-- | libnm-core/nm-utils.c | 56 | ||||
-rw-r--r-- | libnm-core/nm-utils.h | 4 | ||||
-rw-r--r-- | libnm/libnm.ver | 2 |
3 files changed, 62 insertions, 0 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 8b44a32bc8..9e59840287 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2828,6 +2828,62 @@ nm_utils_wifi_is_channel_valid (guint32 channel, const char *band) return FALSE; } +static const int const * +_wifi_freqs (gboolean bg_band) +{ + static int *freqs_2ghz = NULL; + static int *freqs_5ghz = NULL; + int *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 (int, 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 list of 2.4 GHz Wi-Fi frequences. + * Utility function to return 2.4 GHz Wi-Fi frequences (802.11bg band). + * + * Returns: zero-terminated array of frequences numbers (in MHz) + * + * Since: 1.2 + **/ +const int const * +nm_utils_wifi_2ghz_freqs (void) +{ + return _wifi_freqs (TRUE); +} + +/** + * nm_utils_wifi_5ghz_freqs: + * + * Utility function to return 5 GHz Wi-Fi frequences (802.11a band). + * + * Returns: zero-terminated array of frequences numbers (in MHz) + * + * Since: 1.2 + **/ +const int const * +nm_utils_wifi_5ghz_freqs (void) +{ + return _wifi_freqs (FALSE); +} + /** * nm_utils_wifi_strength_bars: * @strength: the access point strength, from 0 to 100 diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h index 64e57e875a..7d2387b7a0 100644 --- a/libnm-core/nm-utils.h +++ b/libnm-core/nm-utils.h @@ -144,6 +144,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_2 +const int const *nm_utils_wifi_2ghz_freqs (void); +NM_AVAILABLE_IN_1_2 +const int const *nm_utils_wifi_5ghz_freqs (void); const char *nm_utils_wifi_strength_bars (guint8 strength); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index ee23ad06e2..125aaa51cf 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -876,6 +876,8 @@ global: nm_utils_bond_mode_string_to_int; nm_utils_enum_from_str; nm_utils_enum_to_str; + nm_utils_wifi_2ghz_freqs; + nm_utils_wifi_5ghz_freqs; nm_vpn_editor_plugin_load_from_file; nm_vpn_plugin_info_get_filename; nm_vpn_plugin_info_get_editor_plugin; |