diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2015-08-18 09:37:48 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-08-21 09:32:09 +0200 |
commit | 1a6b631690481bb195130c44810ca9d55e7da025 (patch) | |
tree | b3d116798a9db61baed6e4758a53b73d59d6a412 | |
parent | 4fe6bdcbb5f489d81c215903c59cc220a66aec32 (diff) | |
download | NetworkManager-1a6b631690481bb195130c44810ca9d55e7da025.tar.gz |
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()
-rw-r--r-- | libnm-core/nm-utils.c | 55 | ||||
-rw-r--r-- | libnm-core/nm-utils.h | 4 | ||||
-rw-r--r-- | libnm/libnm.ver | 2 |
3 files changed, 61 insertions, 0 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 70777ae379..6312423661 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -2841,6 +2841,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.2 + **/ +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.2 + **/ +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 diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h index 64e57e875a..5f9ec10398 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 guint *nm_utils_wifi_2ghz_freqs (void); +NM_AVAILABLE_IN_1_2 +const guint *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; |