scan: move scan_freq_set* into util
James Prestwood
PATCH v3 1/3 scan: move scan_freq_set* into util
This will allow scan_freq_set utilities to be used in any modules requiring unit testing
--- src/scan.c | 160 ---------------------------------------------------- src/scan.h | 14 ----- src/util.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 15 +++++ 4 files changed, 176 insertions(+), 174 deletions(-)
src/scan.c +0 -160
@@ -2017,166 +2017,6 @@ bool scan_get_firmware_scan(uint64_t wdev_id, scan_notify_func_t notify,return true; } -struct scan_freq_set { -uint16_t channels_2ghz; -struct l_uintset *channels_5ghz; -}; - -struct scan_freq_set *scan_freq_set_new (void ) -{ - struct scan_freq_set *ret = l_new(struct scan_freq_set, 1); - -/* 802.11-2012, 8.4.2.10 hints that 200 is the largest channel number */ - ret->channels_5ghz =l_uintset_new_from_range (1 ,200 ); - -return ret; -} - -void scan_freq_set_free (struct scan_freq_set *freqs) -{ -l_uintset_free (freqs->channels_5ghz); -l_free (freqs); -} - -bool scan_freq_set_add (struct scan_freq_set *freqs,uint32_t freq) -{ -enum band_freq band; -uint8_t channel; - - channel =band_freq_to_channel (freq, &band); -if (!channel) -return false; - -switch (band) { -case BAND_FREQ_2_4_GHZ : - freqs->channels_2ghz |=1 << (channel -1 ); -return true; -case BAND_FREQ_5_GHZ : -return l_uintset_put (freqs->channels_5ghz, channel); - } - -return false; -} - -bool scan_freq_set_contains (const struct scan_freq_set *freqs,uint32_t freq) -{ -enum band_freq band; -uint8_t channel; - - channel =band_freq_to_channel (freq, &band); -if (!channel) -return false; - -switch (band) { -case BAND_FREQ_2_4_GHZ : -return freqs->channels_2ghz & (1 << (channel -1 )); -case BAND_FREQ_5_GHZ : -return l_uintset_contains (freqs->channels_5ghz, channel); - } - -return false; -} - -uint32_t scan_freq_set_get_bands (struct scan_freq_set *freqs) -{ -uint32_t bands =0 ; -uint32_t max; - -if (freqs->channels_2ghz) - bands |=BAND_FREQ_2_4_GHZ ; - - max =l_uintset_get_max (freqs->channels_5ghz); - -if (l_uintset_find_min (freqs->channels_5ghz) <= max) - bands |=BAND_FREQ_5_GHZ ; - -return bands; -} - -static void scan_channels_5ghz_add (uint32_t channel,void *user_data) -{ -struct l_uintset *to = user_data; - -l_uintset_put (to, channel); -} - -void scan_freq_set_merge (struct scan_freq_set *to, -const struct scan_freq_set *from) -{ - to->channels_2ghz |= from->channels_2ghz; - -l_uintset_foreach (from->channels_5ghz, scan_channels_5ghz_add, - to->channels_5ghz); -} - -bool scan_freq_set_isempty (const struct scan_freq_set *set) -{ -if (set->channels_2ghz ==0 &&l_uintset_isempty (set->channels_5ghz)) -return true; - -return false; -} - -struct channels_5ghz_foreach_data { -scan_freq_set_func_t func; -void *user_data; -}; - -static void scan_channels_5ghz_frequency (uint32_t channel,void *user_data) -{ -const struct channels_5ghz_foreach_data *channels_5ghz_data = user_data; -uint32_t freq; - - freq =band_channel_to_freq (channel,BAND_FREQ_5_GHZ ); - - channels_5ghz_data->func (freq, channels_5ghz_data->user_data); -} - -void scan_freq_set_foreach (const struct scan_freq_set *freqs, -scan_freq_set_func_t func,void *user_data) -{ -struct channels_5ghz_foreach_data data = { }; -uint8_t channel; -uint32_t freq; - -if (unlikely (!freqs || !func)) -return ; - - data.func = func; - data.user_data = user_data; - -l_uintset_foreach (freqs->channels_5ghz, scan_channels_5ghz_frequency, - &data); - -if (!freqs->channels_2ghz) -return ; - -for (channel =1 ; channel <=14 ; channel++) { -if (freqs->channels_2ghz & (1 << (channel -1 ))) { - freq =band_channel_to_freq (channel,BAND_FREQ_2_4_GHZ ); - -func (freq, user_data); - } - } -} - -void scan_freq_set_constrain (struct scan_freq_set *set, -const struct scan_freq_set *constraint) -{ -struct l_uintset *intersection; - - intersection =l_uintset_intersect (constraint->channels_5ghz, - set->channels_5ghz); -if (!intersection) -/* This shouldn't ever be the case. */ -return ; - -l_uintset_free (set->channels_5ghz); - set->channels_5ghz = intersection; - - set->channels_2ghz &= constraint->channels_2ghz; -} -bool scan_wdev_add (uint64_t wdev_id) {struct scan_context *sc;
src/scan.h +0 -14
@@ -108,7 +108,6 @@ typedef bool (*scan_notify_func_t)(int err, struct l_queue *bss_list,const struct scan_freq_set *freqs, void *userdata);typedef void (*scan_destroy_func_t )(void *userdata); -typedef void (*scan_freq_set_func_t )(uint32_t freq,void *userdata);static inline int scan_bss_addr_cmp (const struct scan_bss *a1,const struct scan_bss *a2)
@@ -168,18 +167,5 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu,size_t body_len, uint32_t frequency, int rssi); -struct scan_freq_set *scan_freq_set_new (void ); -void scan_freq_set_free (struct scan_freq_set *freqs); -bool scan_freq_set_add (struct scan_freq_set *freqs,uint32_t freq); -bool scan_freq_set_contains (const struct scan_freq_set *freqs,uint32_t freq); -uint32_t scan_freq_set_get_bands (struct scan_freq_set *freqs); -void scan_freq_set_foreach (const struct scan_freq_set *freqs, -scan_freq_set_func_t func,void *user_data); -void scan_freq_set_merge (struct scan_freq_set *to, -const struct scan_freq_set *from); -void scan_freq_set_constrain (struct scan_freq_set *set, -const struct scan_freq_set *constraint); -bool scan_freq_set_isempty (const struct scan_freq_set *set); -bool scan_wdev_add (uint64_t wdev_id);bool scan_wdev_remove (uint64_t wdev_id);
src/util.c +161 -0
170 lines not on this page · raw message
src/util.h +15 -0
@@ -101,4 +101,19 @@ static inline bool util_ip_subnet_match(uint8_t prefix_len, ~((1u << (8 - (prefix_len % 8))) - 1)); } +typedef void (*scan_freq_set_func_t )(uint32_t freq,void *userdata); + +struct scan_freq_set *scan_freq_set_new (void ); +void scan_freq_set_free (struct scan_freq_set *freqs); +bool scan_freq_set_add (struct scan_freq_set *freqs,uint32_t freq); +bool scan_freq_set_contains (const struct scan_freq_set *freqs,uint32_t freq); +uint32_t scan_freq_set_get_bands (struct scan_freq_set *freqs); +void scan_freq_set_foreach (const struct scan_freq_set *freqs, +scan_freq_set_func_t func,void *user_data); +void scan_freq_set_merge (struct scan_freq_set *to, +const struct scan_freq_set *from); +void scan_freq_set_constrain (struct scan_freq_set *set, +const struct scan_freq_set *constraint); +bool scan_freq_set_isempty (const struct scan_freq_set *set); +#endif /* __UTIL_H */
Signature · 1 line
2.31.1
James Prestwood
PATCH v3 2/3 scan: add scan_freq_set_to_fixed_array
This serializes a scan_freq_set into a uint32_t array.
--- src/util.c | 33 +++++++++++++++++++++++++++++++++ src/util.h | 2 ++ 2 files changed, 35 insertions(+)
src/util.c +33 -0
@@ -470,3 +470,36 @@ void scan_freq_set_constrain(struct scan_freq_set *set, set->channels_2ghz &= constraint->channels_2ghz; } + +static void add_foreach (uint32_t freq,void *user_data) +{ +uint32_t **list = user_data; + + **list = freq; + + *list = *list +1 ; +} + +uint32_t *scan_freq_set_to_fixed_array (const struct scan_freq_set *set, +size_t *len_out) +{ +uint8_t count =0 ; +uint32_t *freqs; + + count =__builtin_popcount (set->channels_2ghz) + +l_uintset_size (set->channels_5ghz); + +if (!count) +return NULL ; + + freqs =l_new (uint32_t, count); + +scan_freq_set_foreach (set, add_foreach, &freqs); + +/* Move pointer back to start of list */ + freqs -= count; + + *len_out = count; + +return freqs; +}
src/util.h +2 -0
@@ -115,5 +115,7 @@ void scan_freq_set_merge(struct scan_freq_set *to,void scan_freq_set_constrain (struct scan_freq_set *set,const struct scan_freq_set *constraint);bool scan_freq_set_isempty (const struct scan_freq_set *set); +uint32_t *scan_freq_set_to_fixed_array (const struct scan_freq_set *set, +size_t *len_out);#endif /* __UTIL_H */
Signature · 1 line
2.31.1
James Prestwood
PATCH v3 3/3 build: update unit tests with util.c/band.c dependency
In reply to James Prestwood--- Makefile.am | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Makefile.am +10 -5
@@ -320,7 +320,8 @@ monitor_iwmon_SOURCES = monitor/main.c linux/nl80211.h \ src/eapolutil.h src/eapolutil.c \ src/nl80211cmd.h src/nl80211cmd.c \ src/p2putil.c src/p2putil.h \ - src/anqputil.h src/anqputil.c + src/anqputil.h src/anqputil.c \ + src/band.h src/band.c monitor_iwmon_LDADD = $(ell_ldadd) if MANUAL_PAGES
@@ -335,6 +336,7 @@ wired_ead_SOURCES = wired/main.c wired/ethdev.h wired/ethdev.c \ wired/network.h wired/network.c \ wired/dbus.h wired/dbus.c \ src/module.h src/module.c \ + src/band.h src/band.c \ $(eap_sources) wired_ead_LDADD = $(ell_ldadd) wired_ead_DEPENDENCIES = $(ell_dependencies)
@@ -361,7 +363,8 @@ tools_probe_req_SOURCES = tools/probe-req.c src/mpdu.h src/mpdu.c \ src/ie.h src/ie.c \ src/nl80211util.h src/nl80211util.c \ src/util.h src/util.c \ - src/common.h src/common.c + src/common.h src/common.c \ + src/band.h src/band.c tools_probe_req_LDADD = $(ell_ldadd) if HWSIM
@@ -370,7 +373,8 @@ bin_PROGRAMS += tools/hwsim tools_hwsim_SOURCES = tools/hwsim.c src/mpdu.h \ src/util.h src/util.c \ src/storage.h src/storage.c \ - src/common.h src/common.c + src/common.h src/common.c \ + src/band.h src/band.c tools_hwsim_LDADD = $(ell_ldadd) if DBUS_POLICY
@@ -480,7 +484,7 @@ unit_test_eapol_DEPENDENCIES = $(ell_dependencies) \ unit/cert-client-key-pkcs8.pem \ unit/tls-settings.8021x -unit_test_util_SOURCES = src/util.h src/util.c \ +unit_test_util_SOURCES = src/util.h src/util.c src/band.c src/band.h \ unit/test-util.c unit_test_util_LDADD = $(ell_ldadd)
@@ -537,7 +541,8 @@ unit_test_p2p_SOURCES = unit/test-p2p.c src/wscutil.h src/wscutil.c \ src/crypto.h src/crypto.c \ src/ie.h src/ie.c \ src/util.h src/util.c \ - src/p2putil.h src/p2putil.c + src/p2putil.h src/p2putil.c \ + src/band.h src/band.c unit_test_p2p_LDADD = $(ell_ldadd) TESTS = $(unit_tests)
Signature · 1 line
2.31.1
Denis Kenzior
Hi James,
Quoted 9 lines · James Prestwood
This will allow
scan_freq_setutilities to be used in any modules requiring unit testing--- src/scan.c | 160 ---------------------------------------------------- src/scan.h | 14 ----- src/util.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/util.h | 15 +++++ 4 files changed, 176 insertions(+), 174 deletions(-)
All applied, thanks.
Regards,
-Denis