ie: add DPP configurator connectivity element
James Prestwood
PATCH 1/6 ie: add DPP configurator connectivity element
--- src/ie.h | 1 + 1 file changed, 1 insertion(+)
src/ie.h +1 -0
@@ -292,6 +292,7 @@ enum ie_vendor_wfa_oi_type {IE_WFA_OI_OSEN =0x12 ,IE_WFA_OI_OWE_TRANSITION =0x1c ,IE_WFA_OI_ROAMING_SELECTION =0x1d , + IE_WFA_OI_CONFIGURATOR_CONNECTIVITY = 0x1e, }; enum ie_advertisement_id {
Signature · 1 line
2.31.1
James Prestwood
PATCH 2/6 scan: parse configurator connectivity element
This element has no data and indicates the AP supports configuring stations via DPP while also serving current stations.
--- src/scan.c | 3 +++ src/scan.h | 1 + 2 files changed, 4 insertions(+)
src/scan.c +3 -0
@@ -1097,6 +1097,9 @@ static void scan_parse_vendor_specific(struct scan_bss *bss, const void *data,return ; } +if (is_ie_wfa_ie (data, len,IE_WFA_OI_CONFIGURATOR_CONNECTIVITY )) + bss->dpp_configurator = true; +if (!ie_parse_network_cost (data, len, &cost_level, &cost_flags)) { bss->cost_level = cost_level; bss->cost_flags = cost_flags;
src/scan.h +1 -0
@@ -90,6 +90,7 @@ struct scan_bss { bool hs20_dgaf_disable : 1; uint8_t cost_level : 3; uint8_t cost_flags : 4; + bool dpp_configurator : 1; };struct scan_parameters {
Signature · 1 line
2.31.1
James Prestwood
PATCH 3/6 scan: add scan_freq_set_serialize
In reply to James PrestwoodThis serializes a scan_freq_set into a uint32_t array.
--- src/scan.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/scan.h | 3 +++ 2 files changed, 48 insertions(+)
src/scan.c +45 -0
@@ -2370,6 +2370,51 @@ void scan_freq_set_constrain(struct scan_freq_set *set, set->channels_2ghz &= constraint->channels_2ghz; } +struct scan_freq_get_index_data { +unsigned int target; +unsigned int current; +uint32_t found; +}; + +static void count_foreach (uint32_t freq,void *user_data) +{ +uint8_t *count = user_data; + +l_put_u8 (*count +1 , count); +} + +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_serialize (const struct scan_freq_set *set, +size_t *len_out) +{ +uint8_t count =0 ; +uint32_t *freqs; + +scan_freq_set_foreach (set, count_foreach, &count); + +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; +} +bool scan_wdev_add (uint64_t wdev_id) {struct scan_context *sc;
src/scan.h +3 -0
@@ -191,5 +191,8 @@ 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_serialize (const struct scan_freq_set *set, +size_t *len_out); +bool scan_wdev_add (uint64_t wdev_id);bool scan_wdev_remove (uint64_t wdev_id);
Signature · 1 line
2.31.1
Denis Kenzior
Re: [PATCH 3/6] scan: add scan_freq_set_serialize
Hi James,
Quoted 11 lines · James Prestwood
This serializes a
scan_freq_setinto auint32_tarray.--- src/scan.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/scan.h | 3 +++ 2 files changed, 48 insertions(+)src/scan.c +0
-0
src/scan.c void scan_freq_set_constrain(struct scan_freq_set *set, · line 2377
Quoted 8 lines
src/scan.c +5
-0@@ -2370,6 +2370,51 @@ void scan_freq_set_constrain(struct scan_freq_set *set, set->channels_2ghz &= constraint->channels_2ghz; } +struct scan_freq_get_index_data { +unsigned int target; +unsigned int current; +uint32_t found; +};
Whats this for?
src/scan.c void scan_freq_set_constrain(struct scan_freq_set *set, · line 2384
Quoted 7 lines
src/scan.c +7
-0+ +static void count_foreach (uint32_t freq,void *user_data) +{ +uint8_t *count = user_data; + +l_put_u8 (*count +1 , count); +}
Hmm, I wonder if you can either calculate this directly or book-keep the count in scan_freq_set itself. In theory the 2g freqs (if not zero) are just __builtin_popcount(). For the uintset it is essentially the same.
Quoted 41 lines
src/scan.c +33
-0+ +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_serialize (const struct scan_freq_set *set, +size_t *len_out) +{ +uint8_t count =0 ; +uint32_t *freqs; + +scan_freq_set_foreach (set, count_foreach, &count); + +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; +} +bool scan_wdev_add (uint64_t wdev_id) {struct scan_context *sc;src/scan.h +0
-0
src/scan.h void scan_freq_set_constrain(struct scan_freq_set *set, · line 196
Quoted 6 lines
src/scan.h +3
-0@@ -191,5 +191,8 @@ 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_serialize (const struct scan_freq_set *set, +size_t *len_out); +
Can we call this scan_freq_set_to_fixed_array, similar to how l_dbus_message names this.
src/scan.h void scan_freq_set_constrain(struct scan_freq_set *set, · line 198
Quoted 3 lines
src/scan.h +0
-0bool scan_wdev_add (uint64_t wdev_id);bool scan_wdev_remove (uint64_t wdev_id);
Regards,
-Denis
James Prestwood
PATCH 4/6 band: move several scan utilities into band
In reply to James PrestwoodThis will allow unit testing modules which depend on these APIs:
scan_channel_to_freqscan_freq_to_channelscan_oper_class_to_band
--- src/band.c | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/band.h | 10 +++ 2 files changed, 203 insertions(+)
src/band.c +193 -0
@@ -923,3 +923,196 @@ int oci_from_chandef(const struct band_chandef *own, uint8_t oci[static 3])return -ENOENT ; } + +uint8_t band_freq_to_channel (uint32_t freq,enum band_freq *out_band) +{ +uint32_t channel =0 ; + +if (freq >=2412 && freq <=2484 ) { +if (freq ==2484 ) + channel =14 ; +else { + channel = freq -2407 ; + +if (channel %5 ) +return 0 ; + + channel /=5 ; + } + +if (out_band) + *out_band =BAND_FREQ_2_4_GHZ ; + +return channel; + } + +if (freq >=5005 && freq <5900 ) { +if (freq %5 ) +return 0 ; + + channel = (freq -5000 ) /5 ; + +if (out_band) + *out_band =BAND_FREQ_5_GHZ ; + +return channel; + } + +if (freq >=4905 && freq <5000 ) { +if (freq %5 ) +return 0 ; + + channel = (freq -4000 ) /5 ; + +if (out_band) + *out_band =BAND_FREQ_5_GHZ ; + +return channel; + } + +return 0 ; +} + +uint32_t band_channel_to_freq (uint8_t channel,enum band_freq band) +{ +if (band ==BAND_FREQ_2_4_GHZ ) { +if (channel >=1 && channel <=13 ) +return 2407 +5 * channel; + +if (channel ==14 ) +return 2484 ; + } + +if (band ==BAND_FREQ_5_GHZ ) { +if (channel >=1 && channel <=179 ) +return 5000 +5 * channel; + +if (channel >=181 && channel <=199 ) +return 4000 +5 * channel; + } + +return 0 ; +} + +static const char *const oper_class_us_codes[] = { +"US" ,"CA" +}; + +static const char *const oper_class_eu_codes[] = { +"AL" ,"AM" ,"AT" ,"AZ" ,"BA" ,"BE" ,"BG" ,"BY" ,"CH" ,"CY" ,"CZ" ,"DE" , +"DK" ,"EE" ,"EL" ,"ES" ,"FI" ,"FR" ,"GE" ,"HR" ,"HU" ,"IE" ,"IS" ,"IT" , +"LI" ,"LT" ,"LU" ,"LV" ,"MD" ,"ME" ,"MK" ,"MT" ,"NL" ,"NO" ,"PL" ,"PT" , +"RO" ,"RS" ,"RU" ,"SE" ,"SI" ,"SK" ,"TR" ,"UA" ,"UK" +}; + +/* Annex E, table E-1 */ +static const uint8_t oper_class_us_to_global[] = { + [1 ] =115 , [2 ] =118 , [3 ] =124 , [4 ] =121 , + [5 ] =125 , [6 ] =103 , [7 ] =103 , [8 ] =102 , + [9 ] =102 , [10 ] =101 , [11 ] =101 , [12 ] =81 , + [13 ] =94 , [14 ] =95 , [15 ] =96 , [22 ] =116 , + [23 ] =119 , [24 ] =122 , [25 ] =126 , [26 ] =126 , + [27 ] =117 , [28 ] =120 , [29 ] =123 , [30 ] =127 , + [31 ] =127 , [32 ] =83 , [33 ] =84 , [34 ] =180 , +/* 128 - 130 is a 1 to 1 mapping */ +}; + +/* Annex E, table E-2 */ +static const uint8_t oper_class_eu_to_global[] = { + [1 ] =115 , [2 ] =118 , [3 ] =121 , [4 ] =81 , + [5 ] =116 , [6 ] =119 , [7 ] =122 , [8 ] =117 , + [9 ] =120 , [10 ] =123 , [11 ] =83 , [12 ] =84 , + [17 ] =125 , [18 ] =130 , +/* 128 - 130 is a 1 to 1 mapping */ +}; + +/* Annex E, table E-3 */ +static const uint8_t oper_class_jp_to_global[] = { + [1 ] =115 , [2 ] =112 , [3 ] =112 , [4 ] =112 , + [5 ] =112 , [6 ] =112 , [7 ] =109 , [8 ] =109 , + [9 ] =109 , [10 ] =109 , [11 ] =109 , [12 ] =113 , + [13 ] =113 , [14 ] =113 , [15 ] =113 , [16 ] =110 , + [17 ] =110 , [18 ] =110 , [19 ] =110 , [20 ] =110 , + [21 ] =114 , [22 ] =114 , [23 ] =114 , [24 ] =114 , + [25 ] =111 , [26 ] =111 , [27 ] =111 , [28 ] =111 , + [29 ] =111 , [30 ] =81 , [31 ] =82 , [32 ] =118 , + [33 ] =118 , [34 ] =121 , [35 ] =121 , [36 ] =116 , + [37 ] =119 , [38 ] =119 , [39 ] =122 , [40 ] =122 , + [41 ] =117 , [42 ] =120 , [43 ] =120 , [44 ] =123 , + [45 ] =123 , [46 ] =104 , [47 ] =104 , [48 ] =104 , + [49 ] =104 , [50 ] =104 , [51 ] =105 , [52 ] =105 , + [53 ] =105 , [54 ] =105 , [55 ] =105 , [56 ] =83 , + [57 ] =84 , [58 ] =121 , [59 ] =180 , +/* 128 - 130 is a 1 to 1 mapping */ +}; + +/* Annex E, table E-4 (only 2.4GHz and 4.9 / 5GHz bands) */ +static const enum band_freq oper_class_to_band_global[] = { + [81 ...84 ] =BAND_FREQ_2_4_GHZ , + [104 ...130 ] =BAND_FREQ_5_GHZ , +}; + +/* Annex E, table E-5 */ +static const uint8_t oper_class_cn_to_global[] = { + [1 ] =115 , [2 ] =118 , [3 ] =125 , [4 ] =116 , + [5 ] =119 , [6 ] =126 , [7 ] =81 , [8 ] =83 , + [9 ] =84 , +/* 128 - 130 is a 1 to 1 mapping */ +}; + +enum band_freq band_oper_class_to_band (const uint8_t *country, +uint8_t oper_class) +{ +unsigned int i; +int table =0 ; + +if (country && country[2 ] >=1 && country[2 ] <=5 ) + table = country[2 ]; +else if (country) { +for (i =0 ; i <L_ARRAY_SIZE (oper_class_us_codes); i++) +if (!memcmp (oper_class_us_codes[i], country,2 )) { +/* Use table E-1 */ + table =1 ; +break ; + } + +for (i =0 ; i <L_ARRAY_SIZE (oper_class_eu_codes); i++) +if (!memcmp (oper_class_eu_codes[i], country,2 )) { +/* Use table E-2 */ + table =2 ; +break ; + } + +if (!memcmp ("JP" , country,2 )) +/* Use table E-3 */ + table =3 ; + +if (!memcmp ("CN" , country,2 )) +/* Use table E-5 */ + table =5 ; + } + +switch (table) { +case 1 : +if (oper_class <L_ARRAY_SIZE (oper_class_us_to_global)) + oper_class = oper_class_us_to_global[oper_class]; +break ; +case 2 : +if (oper_class <L_ARRAY_SIZE (oper_class_eu_to_global)) + oper_class = oper_class_eu_to_global[oper_class]; +break ; +case 3 : +if (oper_class <L_ARRAY_SIZE (oper_class_jp_to_global)) + oper_class = oper_class_jp_to_global[oper_class]; +break ; +case 5 : +if (oper_class <L_ARRAY_SIZE (oper_class_cn_to_global)) + oper_class = oper_class_cn_to_global[oper_class]; +break ; + } + +if (oper_class <L_ARRAY_SIZE (oper_class_to_band_global)) +return oper_class_to_band_global[oper_class]; +else +return 0 ; +}
src/band.h +10 -0
@@ -36,6 +36,11 @@ enum band_chandef_width { BAND_CHANDEF_WIDTH_160, }; +enum band_freq { +BAND_FREQ_2_4_GHZ =0x1 , +BAND_FREQ_5_GHZ =0x2 , +}; +struct band_chandef {uint32_t frequency;uint32_t channel_width;
@@ -76,3 +81,8 @@ int oci_to_frequency(uint32_t operating_class, uint32_t channel);int oci_verify (const uint8_t oci[static 3 ],const struct band_chandef *own);int oci_from_chandef (const struct band_chandef *own,uint8_t oci[static 3 ]); + +uint8_t band_freq_to_channel (uint32_t freq,enum band_freq *out_band); +uint32_t band_channel_to_freq (uint8_t channel,enum band_freq band); +enum band_freq band_oper_class_to_band (const uint8_t *country, +uint8_t oper_class);
Signature · 1 line
2.31.1
James Prestwood
PATCH 5/6 treewide: update scan utility usage to use band_*
In reply to James Prestwood--- src/ap.c | 9 +++++---- src/netdev.c | 2 +- src/p2p.c | 35 ++++++++++++++++++----------------- src/rrm.c | 11 ++++++----- src/scan.c | 24 ++++++++++++------------ src/station.c | 15 ++++++++------- src/wiphy.c | 12 ++++++------ src/wsc.c | 21 +++++++++++---------- 8 files changed, 67 insertions(+), 62 deletions(-)
src/ap.c +5 -4
@@ -57,6 +57,7 @@#include "src/ap.h" #include "src/storage.h" #include "src/diagnostic.h" +#include "src/band.h" struct ap_state {struct netdev *netdev;
@@ -895,7 +896,7 @@ static uint32_t ap_send_mgmt_frame(struct ap_state *ap,frame_xchg_cb_t callback, void *user_data) { - uint32_t ch_freq = scan_channel_to_freq(ap->channel, SCAN_BAND_2_4_GHZ); + uint32_t ch_freq = band_channel_to_freq(ap->channel, BAND_FREQ_2_4_GHZ);uint64_t wdev_id =netdev_get_wdev_id (ap->netdev);struct iovec iov[2 ];
@@ -2318,7 +2319,7 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)uint32_t nl_akm =CRYPTO_AKM_PSK ;uint32_t wpa_version =NL80211_WPA_VERSION_2 ;uint32_t auth_type =NL80211_AUTHTYPE_OPEN_SYSTEM ; -uint32_t ch_freq =scan_channel_to_freq (ap->channel,SCAN_BAND_2_4_GHZ ); +uint32_t ch_freq =band_channel_to_freq (ap->channel,BAND_FREQ_2_4_GHZ );uint32_t ch_width =NL80211_CHAN_WIDTH_20 ;unsigned int i;
@@ -3066,8 +3067,8 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,if (!l_settings_get_uint (config,"General" ,"Channel" , &uintval) || - !scan_channel_to_freq (uintval, -SCAN_BAND_2_4_GHZ )) { + !band_channel_to_freq (uintval, +BAND_FREQ_2_4_GHZ )) {l_error ("AP Channel value unsupported" );return -EINVAL ; }
src/netdev.c +1 -1
@@ -4188,7 +4188,7 @@ int netdev_join_adhoc(struct netdev *netdev, const char *ssid, {struct l_genl_msg *cmd;uint32_t ifindex = netdev->index; -uint32_t ch_freq =scan_channel_to_freq (6 ,SCAN_BAND_2_4_GHZ ); +uint32_t ch_freq =band_channel_to_freq (6 ,BAND_FREQ_2_4_GHZ );uint32_t ch_type =NL80211_CHAN_HT20 ;if (netdev->type !=NL80211_IFTYPE_ADHOC ) {
src/p2p.c +18 -17
@@ -61,6 +61,7 @@#include "src/netconfig.h" #include "src/ap.h" #include "src/p2p.h" +#include "src/band.h" struct p2p_device {uint64_t wdev_id;
@@ -804,7 +805,7 @@ static void p2p_peer_frame_xchg(struct p2p_peer *peer, struct iovec *tx_body,memcpy (frame +1 , tx_body,sizeof (struct iovec ) * iov_cnt); freq = own_channel ? -scan_channel_to_freq (dev->listen_channel,SCAN_BAND_2_4_GHZ ) : +band_channel_to_freq (dev->listen_channel,BAND_FREQ_2_4_GHZ ) : peer->bss->frequency;va_start (args, cb);
@@ -2094,14 +2095,14 @@ static void p2p_add_freq_func(uint32_t freq, void *user_data) {struct p2p_channel_entries *channel_entry = user_data;uint8_t channel; -enum scan_band band; +enum band_freq band;if (channel_entry->n_channels >=MAX_CHANNELS )return ; - channel =scan_freq_to_channel (freq, &band); + channel =band_freq_to_channel (freq, &band); -if (band !=scan_oper_class_to_band ((const uint8_t *)"XX\x4" , +if (band !=band_oper_class_to_band ((const uint8_t *)"XX\x4" , channel_entry->oper_class))return ;
@@ -2221,10 +2222,10 @@ static bool p2p_go_negotiation_confirm_cb(const struct mmpdu_header *mpdu,*/ p2p_device_interface_create (dev); }else { -enum scan_band band =scan_oper_class_to_band ( +enum band_freq band =band_oper_class_to_band ( (const uint8_t *) info.operating_channel.country, info.operating_channel.oper_class); -uint32_t frequency =scan_channel_to_freq ( +uint32_t frequency =band_channel_to_freq ( info.operating_channel.channel_num, band);
@@ -2590,7 +2591,7 @@ static bool p2p_go_negotiation_resp_cb(const struct mmpdu_header *mpdu,int r;struct iovec iov[16 ];int iov_len =0 ; -enum scan_band band; +enum band_freq band;uint32_t frequency;l_debug ("" );
@@ -2743,10 +2744,10 @@ static bool p2p_go_negotiation_resp_cb(const struct mmpdu_header *mpdu,memcpy (&confirm_info.group_id, &dev->go_group_id,sizeof (struct p2p_group_id_attr )); }else { - band =scan_oper_class_to_band ( + band =band_oper_class_to_band ( (const uint8_t *) resp_info.operating_channel.country, resp_info.operating_channel.oper_class); - frequency =scan_channel_to_freq ( + frequency =band_channel_to_freq ( resp_info.operating_channel.channel_num, band);if (!frequency) {
@@ -3444,8 +3445,8 @@ static void p2p_device_roc_start(struct p2p_device *dev)* channel than on any other channel and then we listen for a * potential GO Negotiation restart on our listen channel. */ - listen_freq =scan_channel_to_freq (dev->listen_channel, -SCAN_BAND_2_4_GHZ ); + listen_freq =band_channel_to_freq (dev->listen_channel, +BAND_FREQ_2_4_GHZ ); msg =l_genl_msg_new_sized (NL80211_CMD_REMAIN_ON_CHANNEL ,64 );l_genl_msg_append_attr (msg,NL80211_ATTR_WDEV ,8 , &dev->wdev_id);
@@ -3809,7 +3810,7 @@ static bool p2p_device_scan_start(struct p2p_device *dev)for (i =0 ; i <L_ARRAY_SIZE (channels_social); i++) {int chan = channels_social[i]; -uint32_t freq =scan_channel_to_freq (chan,SCAN_BAND_2_4_GHZ ); +uint32_t freq =band_channel_to_freq (chan,BAND_FREQ_2_4_GHZ );scan_freq_set_add (params.freqs, freq); }
@@ -3826,7 +3827,7 @@ static bool p2p_device_scan_start(struct p2p_device *dev)for (i =0 ; i < dev->chans_per_scan; i++) {int idx = dev->scan_chan_idx++;int chan = channels_scan_2_4_other[idx]; -uint32_t freq =scan_channel_to_freq (chan,SCAN_BAND_2_4_GHZ ); +uint32_t freq =band_channel_to_freq (chan,BAND_FREQ_2_4_GHZ );if (dev->scan_chan_idx >=L_ARRAY_SIZE (channels_scan_2_4_other)) {
@@ -3997,7 +3998,7 @@ static void p2p_device_send_probe_resp(struct p2p_device *dev, iov[iov_len].iov_base =NULL ; - freq =scan_channel_to_freq (dev->listen_channel,SCAN_BAND_2_4_GHZ ); + freq =band_channel_to_freq (dev->listen_channel,BAND_FREQ_2_4_GHZ );frame_xchg_start (dev->wdev_id, iov, freq,0 ,0 , false,0 , p2p_probe_resp_done, dev,NULL ,NULL );l_debug ("Probe Response tx queued" );
@@ -4019,7 +4020,7 @@ static void p2p_device_probe_cb(const struct mmpdu_header *mpdu,ssize_t wsc_len;struct scan_bss *bss;struct p2p_channel_attr *channel; -enum scan_band band; +enum band_freq band;uint32_t frequency;bool from_conn_peer;
@@ -4082,9 +4083,9 @@ static void p2p_device_probe_cb(const struct mmpdu_header *mpdu,else goto p2p_free; - band =scan_oper_class_to_band ((const uint8_t *) channel->country, + band =band_oper_class_to_band ((const uint8_t *) channel->country, channel->oper_class); - frequency =scan_channel_to_freq (channel->channel_num, band); + frequency =band_channel_to_freq (channel->channel_num, band);if (!frequency) goto p2p_free;
src/rrm.c +6 -5
@@ -41,6 +41,7 @@#include "src/nl80211util.h" #include "src/wiphy.h" #include "src/frame-xchg.h" +#include "src/band.h" #include "linux/nl80211.h"
@@ -278,7 +279,7 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,struct rrm_beacon_report *report = (struct rrm_beacon_report *) to; report->oper_class = beacon->oper_class; - report->channel =scan_freq_to_channel (bss->frequency,NULL ); + report->channel =band_freq_to_channel (bss->frequency,NULL ); report->scan_start_time =L_CPU_TO_LE64 (beacon->scan_start_time); report->duration =L_CPU_TO_LE16 (beacon->duration); report->frame_info =rrm_phy_type (bss);
@@ -310,7 +311,7 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,static bool bss_in_request_range (struct rrm_beacon_req_info *beacon,struct scan_bss *bss) { -uint8_t channel =scan_freq_to_channel (bss->frequency,NULL ); +uint8_t channel =band_freq_to_channel (bss->frequency,NULL );/* Must be a table measurement */ if (beacon->channel ==0 || beacon->channel ==255 )
@@ -436,10 +437,10 @@ static void rrm_handle_beacon_scan(struct rrm_state *rrm, .duration = beacon->duration, .duration_mandatory = test_bit(&beacon->info.mode, 4), }; -enum scan_band band =scan_oper_class_to_band (NULL , beacon->oper_class); +enum band_freq band =band_oper_class_to_band (NULL , beacon->oper_class);uint32_t freq; - freq =scan_channel_to_freq (beacon->channel, band); + freq =band_channel_to_freq (beacon->channel, band);scan_freq_set_add (freqs, freq);if (passive)
@@ -485,7 +486,7 @@ static bool rrm_verify_beacon_request(const uint8_t *request, size_t len) }/* Check this is a valid operating class */ -if (!scan_oper_class_to_band (NULL , request[0 ])) +if (!band_oper_class_to_band (NULL , request[0 ]))return false;return true;
src/scan.c +12 -12
@@ -2233,18 +2233,18 @@ void scan_freq_set_free(struct scan_freq_set *freqs)bool scan_freq_set_add (struct scan_freq_set *freqs,uint32_t freq) { -enum scan_band band; +enum band_freq band;uint8_t channel; - channel =scan_freq_to_channel (freq, &band); + channel =band_freq_to_channel (freq, &band);if (!channel)return false;switch (band) { -case SCAN_BAND_2_4_GHZ : +case BAND_FREQ_2_4_GHZ : freqs->channels_2ghz |=1 << (channel -1 );return true; -case SCAN_BAND_5_GHZ : +case BAND_FREQ_5_GHZ :return l_uintset_put (freqs->channels_5ghz, channel); }
@@ -2253,17 +2253,17 @@ 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) { -enum scan_band band; +enum band_freq band;uint8_t channel; - channel =scan_freq_to_channel (freq, &band); + channel =band_freq_to_channel (freq, &band);if (!channel)return false;switch (band) { -case SCAN_BAND_2_4_GHZ : +case BAND_FREQ_2_4_GHZ :return freqs->channels_2ghz & (1 << (channel -1 )); -case SCAN_BAND_5_GHZ : +case BAND_FREQ_5_GHZ :return l_uintset_contains (freqs->channels_5ghz, channel); }
@@ -2276,12 +2276,12 @@ uint32_t scan_freq_set_get_bands(struct scan_freq_set *freqs)uint32_t max;if (freqs->channels_2ghz) - bands |=SCAN_BAND_2_4_GHZ ; + bands |=BAND_FREQ_2_4_GHZ ; max =l_uintset_get_max (freqs->channels_5ghz);if (l_uintset_find_min (freqs->channels_5ghz) <= max) - bands |=SCAN_BAND_5_GHZ ; + bands |=BAND_FREQ_5_GHZ ;return bands; }
@@ -2320,7 +2320,7 @@ 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 =scan_channel_to_freq (channel,SCAN_BAND_5_GHZ ); + freq =band_channel_to_freq (channel,BAND_FREQ_5_GHZ ); channels_5ghz_data->func (freq, channels_5ghz_data->user_data); }
@@ -2346,7 +2346,7 @@ void scan_freq_set_foreach(const struct scan_freq_set *freqs,for (channel =1 ; channel <=14 ; channel++) {if (freqs->channels_2ghz & (1 << (channel -1 ))) { - freq =scan_channel_to_freq (channel,SCAN_BAND_2_4_GHZ ); + freq =band_channel_to_freq (channel,BAND_FREQ_2_4_GHZ );func (freq, user_data); }
src/station.c +8 -7
@@ -58,6 +58,7 @@#include "src/diagnostic.h" #include "src/frame-xchg.h" #include "src/sysfs.h" +#include "src/band.h" static struct l_queue *station_list;static uint32_t netdev_watch;
@@ -1646,9 +1647,9 @@ static int station_roam_scan(struct station *station, struct scan_freq_set *freq_set);static uint32_t station_freq_from_neighbor_report (const uint8_t *country, -struct ie_neighbor_report_info *info,enum scan_band *out_band) +struct ie_neighbor_report_info *info,enum band_freq *out_band) { -enum scan_band band; +enum band_freq band;uint32_t freq;if (info->oper_class ==0 ) {
@@ -1660,9 +1661,9 @@ static uint32_t station_freq_from_neighbor_report(const uint8_t *country,* use channels in two disjoint ranges. */ if (info->channel_num >=1 && info->channel_num <=14 ) - band =SCAN_BAND_2_4_GHZ ; + band =BAND_FREQ_2_4_GHZ ;else if (info->channel_num >=36 && info->channel_num <=169 ) - band =SCAN_BAND_5_GHZ ; + band =BAND_FREQ_5_GHZ ;else {l_debug ("Ignored: 0 oper class with an unusual " "channel number" );
@@ -1670,7 +1671,7 @@ static uint32_t station_freq_from_neighbor_report(const uint8_t *country,return 0 ; } }else { - band =scan_oper_class_to_band (country, info->oper_class); + band =band_oper_class_to_band (country, info->oper_class);if (!band) {l_debug ("Ignored: unsupported oper class" );
@@ -1678,7 +1679,7 @@ static uint32_t station_freq_from_neighbor_report(const uint8_t *country, } } - freq =scan_channel_to_freq (info->channel_num, band); + freq =band_channel_to_freq (info->channel_num, band);if (!freq) {l_debug ("Ignored: unsupported channel" );
@@ -1711,7 +1712,7 @@ static void parse_neighbor_report(struct station *station,while (ie_tlv_iter_next (&iter)) {struct ie_neighbor_report_info info;uint32_t freq; -enum scan_band band; +enum band_freq band;const uint8_t *cc =NULL ;if (ie_tlv_iter_get_tag (&iter) !=IE_TYPE_NEIGHBOR_REPORT )
src/wiphy.c +6 -6
@@ -431,10 +431,10 @@ uint32_t wiphy_get_supported_bands(struct wiphy *wiphy)uint32_t bands =0 ;if (wiphy->band_2g) - bands |=SCAN_BAND_2_4_GHZ ; + bands |=BAND_FREQ_2_4_GHZ ;if (wiphy->band_5g) - bands |=SCAN_BAND_5_GHZ ; + bands |=BAND_FREQ_5_GHZ ;return bands; }
@@ -777,16 +777,16 @@ int wiphy_estimate_data_rate(struct wiphy *wiphy,const void *ht_capabilities =NULL ;const void *ht_operation =NULL ;const struct band *bandp; -enum scan_band band; +enum band_freq band; -if (scan_freq_to_channel (bss->frequency, &band) ==0 ) +if (band_freq_to_channel (bss->frequency, &band) ==0 )return -ENOTSUP ;switch (band) { -case SCAN_BAND_2_4_GHZ : +case BAND_FREQ_2_4_GHZ : bandp = wiphy->band_2g;break ; -case SCAN_BAND_5_GHZ : +case BAND_FREQ_5_GHZ : bandp = wiphy->band_5g;break ;default :
src/wsc.c +11 -10
@@ -46,6 +46,7 @@#include "src/iwd.h" #include "src/network.h" #include "src/wsc.h" +#include "src/band.h" #define WALK_TIME 120
@@ -299,14 +300,14 @@ static void wsc_enrollee_handshake_event(struct handshake_state *hs,static inline enum wsc_rf_band freq_to_rf_band (uint32_t freq) { -enum scan_band band; +enum band_freq band; -scan_freq_to_channel (freq, &band); +band_freq_to_channel (freq, &band);switch (band) { -case SCAN_BAND_2_4_GHZ : +case BAND_FREQ_2_4_GHZ :return WSC_RF_BAND_2_4_GHZ ; -case SCAN_BAND_5_GHZ : +case BAND_FREQ_5_GHZ :return WSC_RF_BAND_5_0_GHZ ; }
@@ -731,7 +732,7 @@ static bool push_button_scan_results(int err, struct l_queue *bss_list,for (bss_entry =l_queue_get_entries (bss_list); bss_entry; bss_entry = bss_entry->next) {struct scan_bss *bss = bss_entry->data; -enum scan_band band; +enum band_freq band;int err; l_debug("bss '%s' with SSID: %s, freq: %u",
@@ -762,10 +763,10 @@ static bool push_button_scan_results(int err, struct l_queue *bss_list, WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON)continue ; -scan_freq_to_channel (bss->frequency, &band); +band_freq_to_channel (bss->frequency, &band);switch (band) { -case SCAN_BAND_2_4_GHZ : +case BAND_FREQ_2_4_GHZ :if (bss_2g) {l_debug ("2G Session overlap error" ); goto session_overlap;
@@ -775,7 +776,7 @@ static bool push_button_scan_results(int err, struct l_queue *bss_list,memcpy (uuid_2g, probe_response.uuid_e,16 );break ; -case SCAN_BAND_5_GHZ : +case BAND_FREQ_5_GHZ :if (bss_5g) {l_debug ("5G Session overlap error" ); goto session_overlap;
@@ -994,9 +995,9 @@ static bool wsc_initiate_scan(struct wsc_station_dbus *wsc, req.primary_device_type.subcategory =0 ; bands =wiphy_get_supported_bands (wiphy); -if (bands &SCAN_BAND_2_4_GHZ ) +if (bands &BAND_FREQ_2_4_GHZ ) req.rf_bands |=WSC_RF_BAND_2_4_GHZ ; -if (bands &SCAN_BAND_5_GHZ ) +if (bands &BAND_FREQ_5_GHZ ) req.rf_bands |=WSC_RF_BAND_5_0_GHZ ; req.association_state =WSC_ASSOCIATION_STATE_NOT_ASSOCIATED ;
Signature · 1 line
2.31.1
James Prestwood
PATCH 6/6 scan: remove scan APIs refactored into band.c
In reply to James Prestwood--- src/scan.c | 193 ----------------------------------------------------- src/scan.h | 10 --- 2 files changed, 203 deletions(-)
src/scan.c +0 -193
@@ -2017,199 +2017,6 @@ bool scan_get_firmware_scan(uint64_t wdev_id, scan_notify_func_t notify,return true; } -uint8_t scan_freq_to_channel (uint32_t freq,enum scan_band *out_band) -{ -uint32_t channel =0 ; - -if (freq >=2412 && freq <=2484 ) { -if (freq ==2484 ) - channel =14 ; -else { - channel = freq -2407 ; - -if (channel %5 ) -return 0 ; - - channel /=5 ; - } - -if (out_band) - *out_band =SCAN_BAND_2_4_GHZ ; - -return channel; - } - -if (freq >=5005 && freq <5900 ) { -if (freq %5 ) -return 0 ; - - channel = (freq -5000 ) /5 ; - -if (out_band) - *out_band =SCAN_BAND_5_GHZ ; - -return channel; - } - -if (freq >=4905 && freq <5000 ) { -if (freq %5 ) -return 0 ; - - channel = (freq -4000 ) /5 ; - -if (out_band) - *out_band =SCAN_BAND_5_GHZ ; - -return channel; - } - -return 0 ; -} - -uint32_t scan_channel_to_freq (uint8_t channel,enum scan_band band) -{ -if (band ==SCAN_BAND_2_4_GHZ ) { -if (channel >=1 && channel <=13 ) -return 2407 +5 * channel; - -if (channel ==14 ) -return 2484 ; - } - -if (band ==SCAN_BAND_5_GHZ ) { -if (channel >=1 && channel <=179 ) -return 5000 +5 * channel; - -if (channel >=181 && channel <=199 ) -return 4000 +5 * channel; - } - -return 0 ; -} - -static const char *const oper_class_us_codes[] = { -"US" ,"CA" -}; - -static const char *const oper_class_eu_codes[] = { -"AL" ,"AM" ,"AT" ,"AZ" ,"BA" ,"BE" ,"BG" ,"BY" ,"CH" ,"CY" ,"CZ" ,"DE" , -"DK" ,"EE" ,"EL" ,"ES" ,"FI" ,"FR" ,"GE" ,"HR" ,"HU" ,"IE" ,"IS" ,"IT" , -"LI" ,"LT" ,"LU" ,"LV" ,"MD" ,"ME" ,"MK" ,"MT" ,"NL" ,"NO" ,"PL" ,"PT" , -"RO" ,"RS" ,"RU" ,"SE" ,"SI" ,"SK" ,"TR" ,"UA" ,"UK" -}; - -/* Annex E, table E-1 */ -static const uint8_t oper_class_us_to_global[] = { - [1 ] =115 , [2 ] =118 , [3 ] =124 , [4 ] =121 , - [5 ] =125 , [6 ] =103 , [7 ] =103 , [8 ] =102 , - [9 ] =102 , [10 ] =101 , [11 ] =101 , [12 ] =81 , - [13 ] =94 , [14 ] =95 , [15 ] =96 , [22 ] =116 , - [23 ] =119 , [24 ] =122 , [25 ] =126 , [26 ] =126 , - [27 ] =117 , [28 ] =120 , [29 ] =123 , [30 ] =127 , - [31 ] =127 , [32 ] =83 , [33 ] =84 , [34 ] =180 , -/* 128 - 130 is a 1 to 1 mapping */ -}; - -/* Annex E, table E-2 */ -static const uint8_t oper_class_eu_to_global[] = { - [1 ] =115 , [2 ] =118 , [3 ] =121 , [4 ] =81 , - [5 ] =116 , [6 ] =119 , [7 ] =122 , [8 ] =117 , - [9 ] =120 , [10 ] =123 , [11 ] =83 , [12 ] =84 , - [17 ] =125 , [18 ] =130 , -/* 128 - 130 is a 1 to 1 mapping */ -}; - -/* Annex E, table E-3 */ -static const uint8_t oper_class_jp_to_global[] = { - [1 ] =115 , [2 ] =112 , [3 ] =112 , [4 ] =112 , - [5 ] =112 , [6 ] =112 , [7 ] =109 , [8 ] =109 , - [9 ] =109 , [10 ] =109 , [11 ] =109 , [12 ] =113 , - [13 ] =113 , [14 ] =113 , [15 ] =113 , [16 ] =110 , - [17 ] =110 , [18 ] =110 , [19 ] =110 , [20 ] =110 , - [21 ] =114 , [22 ] =114 , [23 ] =114 , [24 ] =114 , - [25 ] =111 , [26 ] =111 , [27 ] =111 , [28 ] =111 , - [29 ] =111 , [30 ] =81 , [31 ] =82 , [32 ] =118 , - [33 ] =118 , [34 ] =121 , [35 ] =121 , [36 ] =116 , - [37 ] =119 , [38 ] =119 , [39 ] =122 , [40 ] =122 , - [41 ] =117 , [42 ] =120 , [43 ] =120 , [44 ] =123 , - [45 ] =123 , [46 ] =104 , [47 ] =104 , [48 ] =104 , - [49 ] =104 , [50 ] =104 , [51 ] =105 , [52 ] =105 , - [53 ] =105 , [54 ] =105 , [55 ] =105 , [56 ] =83 , - [57 ] =84 , [58 ] =121 , [59 ] =180 , -/* 128 - 130 is a 1 to 1 mapping */ -}; - -/* Annex E, table E-4 (only 2.4GHz and 4.9 / 5GHz bands) */ -static const enum scan_band oper_class_to_band_global[] = { - [81 ...84 ] =SCAN_BAND_2_4_GHZ , - [104 ...130 ] =SCAN_BAND_5_GHZ , -}; - -/* Annex E, table E-5 */ -static const uint8_t oper_class_cn_to_global[] = { - [1 ] =115 , [2 ] =118 , [3 ] =125 , [4 ] =116 , - [5 ] =119 , [6 ] =126 , [7 ] =81 , [8 ] =83 , - [9 ] =84 , -/* 128 - 130 is a 1 to 1 mapping */ -}; - -enum scan_band scan_oper_class_to_band (const uint8_t *country, -uint8_t oper_class) -{ -unsigned int i; -int table =0 ; - -if (country && country[2 ] >=1 && country[2 ] <=5 ) - table = country[2 ]; -else if (country) { -for (i =0 ; i <L_ARRAY_SIZE (oper_class_us_codes); i++) -if (!memcmp (oper_class_us_codes[i], country,2 )) { -/* Use table E-1 */ - table =1 ; -break ; - } - -for (i =0 ; i <L_ARRAY_SIZE (oper_class_eu_codes); i++) -if (!memcmp (oper_class_eu_codes[i], country,2 )) { -/* Use table E-2 */ - table =2 ; -break ; - } - -if (!memcmp ("JP" , country,2 )) -/* Use table E-3 */ - table =3 ; - -if (!memcmp ("CN" , country,2 )) -/* Use table E-5 */ - table =5 ; - } - -switch (table) { -case 1 : -if (oper_class <L_ARRAY_SIZE (oper_class_us_to_global)) - oper_class = oper_class_us_to_global[oper_class]; -break ; -case 2 : -if (oper_class <L_ARRAY_SIZE (oper_class_eu_to_global)) - oper_class = oper_class_eu_to_global[oper_class]; -break ; -case 3 : -if (oper_class <L_ARRAY_SIZE (oper_class_jp_to_global)) - oper_class = oper_class_jp_to_global[oper_class]; -break ; -case 5 : -if (oper_class <L_ARRAY_SIZE (oper_class_cn_to_global)) - oper_class = oper_class_cn_to_global[oper_class]; -break ; - } - -if (oper_class <L_ARRAY_SIZE (oper_class_to_band_global)) -return oper_class_to_band_global[oper_class]; -else -return 0 ; -} -struct scan_freq_set {uint16_t channels_2ghz;struct l_uintset *channels_5ghz;
src/scan.h +0 -10
@@ -29,11 +29,6 @@ struct p2p_beacon;struct mmpdu_header ;struct wiphy ; -enum scan_band { -SCAN_BAND_2_4_GHZ =0x1 , -SCAN_BAND_5_GHZ =0x2 , -}; -enum scan_state {SCAN_STATE_NOT_RUNNING ,SCAN_STATE_PASSIVE ,
@@ -173,11 +168,6 @@ struct scan_bss *scan_bss_new_from_probe_req(const struct mmpdu_header *mpdu,size_t body_len, uint32_t frequency, int rssi); -uint8_t scan_freq_to_channel (uint32_t freq,enum scan_band *out_band); -uint32_t scan_channel_to_freq (uint8_t channel,enum scan_band band); -enum scan_band scan_oper_class_to_band (const uint8_t *country, -uint8_t oper_class); -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);
Signature · 1 line
2.31.1
Denis Kenzior
Hi James,
Quoted 4 lines · James Prestwood
--- src/ie.h | 1 + 1 file changed, 1 insertion(+)
Patches 1,2,4,5, and 6 applied. Thanks!
Regards,
-Denis