From 77bf69c3dc6ef6c17741cdf0f81af911378596e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Tue, 18 Aug 2015 09:37:48 +0200 Subject: [PATCH] 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 1a6b631690481bb195130c44810ca9d55e7da025) --- libnm-core/nm-utils.c | 55 +++++++++++++++++++++++++++++++++++++++++++ libnm-core/nm-utils.h | 4 ++++ libnm/libnm.ver | 2 ++ 3 files changed, 61 insertions(+) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 873f9ac18e..70450af11f 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -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 diff --git a/libnm-core/nm-utils.h b/libnm-core/nm-utils.h index 8c22cfd168..45bdf757ea 100644 --- a/libnm-core/nm-utils.h +++ b/libnm-core/nm-utils.h @@ -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); diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 9d20ebb64a..4bf77938ec 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -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;