commit 0c0d9e5696d9b72ea3b6228ff964bdc614b3c7b2
parent ea3dedffd96808c7b91d3623aa1aeb173a561681
Author: Denis Kenzior <denkenz@gmail.com>
Date: Fri, 12 Mar 2021 13:49:23 -0600
iwd: Use test_bit from ell
Diffstat:
9 files changed, 42 insertions(+), 47 deletions(-)
diff --git a/src/anqputil.c b/src/anqputil.c
@@ -26,6 +26,7 @@
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/anqputil.h"
#include "src/ie.h"
#include "src/util.h"
@@ -178,7 +179,7 @@ char **anqp_parse_nai_realms(const unsigned char *anqp, unsigned int len)
* action frames it could have been spoofed, but ultimately if
* its bogus the AP won't allow us to connect.
*/
- if (!util_is_bit_set(encoding, 0))
+ if (!test_bit(&encoding, 0))
l_warn("Not verifying NAI encoding");
else if (!l_utf8_validate(nai_realm, nai_len, NULL)) {
l_warn("NAI is not UTF-8");
diff --git a/src/eap-pwd.c b/src/eap-pwd.c
@@ -656,9 +656,9 @@ static void eap_pwd_handle_request(struct eap_state *eap,
}
/* set if Total-Length parameter is include (i.e. first fragment) */
- len_bit = util_is_bit_set(pkt[0], 7);
+ len_bit = test_bit(pkt, 7);
/* set on all but the last fragment */
- more_bit = util_is_bit_set(pkt[0], 6);
+ more_bit = test_bit(pkt, 6);
/* first rx fragment */
if (len_bit) {
diff --git a/src/erp.c b/src/erp.c
@@ -434,7 +434,7 @@ int erp_rx_packet(struct erp_state *erp, const uint8_t *pkt, size_t len)
if (type != ERP_TYPE_REAUTH)
goto eap_failed;
- r = util_is_bit_set(pkt[5], 0);
+ r = test_bit(pkt + 5, 0);
if (r)
goto eap_failed;
diff --git a/src/ie.c b/src/ie.c
@@ -727,17 +727,17 @@ static int parse_ciphers(const uint8_t *data, size_t len,
if (len < 2)
return -EBADMSG;
- out_info->preauthentication = util_is_bit_set(data[0], 0);
- out_info->no_pairwise = util_is_bit_set(data[0], 1);
+ out_info->preauthentication = test_bit(data, 0);
+ out_info->no_pairwise = test_bit(data, 1);
out_info->ptksa_replay_counter = bit_field(data[0], 2, 2);
out_info->gtksa_replay_counter = bit_field(data[0], 4, 2);
- out_info->mfpr = util_is_bit_set(data[0], 6);
- out_info->mfpc = util_is_bit_set(data[0], 7);
- out_info->peerkey_enabled = util_is_bit_set(data[1], 1);
- out_info->spp_a_msdu_capable = util_is_bit_set(data[1], 2);
- out_info->spp_a_msdu_required = util_is_bit_set(data[1], 3);
- out_info->pbac = util_is_bit_set(data[1], 4);
- out_info->extended_key_id = util_is_bit_set(data[1], 5);
+ out_info->mfpr = test_bit(data, 6);
+ out_info->mfpc = test_bit(data, 7);
+ out_info->peerkey_enabled = test_bit(data + 1, 1);
+ out_info->spp_a_msdu_capable = test_bit(data + 1, 2);
+ out_info->spp_a_msdu_required = test_bit(data + 1, 3);
+ out_info->pbac = test_bit(data + 1, 4);
+ out_info->extended_key_id = test_bit(data + 1, 5);
/*
* BIP—default group management cipher suite in an RSNA with
@@ -1450,8 +1450,8 @@ int ie_parse_wpa(struct ie_tlv_iter *iter, struct ie_rsn_info *out_info)
if (len < 2)
return -EBADMSG;
- out_info->preauthentication = util_is_bit_set(data[0], 0);
- out_info->no_pairwise = util_is_bit_set(data[0], 1);
+ out_info->preauthentication = test_bit(data, 0);
+ out_info->no_pairwise = test_bit(data, 1);
out_info->ptksa_replay_counter = bit_field(data[0], 2, 2);
out_info->gtksa_replay_counter = bit_field(data[0], 4, 2);
@@ -1851,9 +1851,9 @@ static int ie_parse_ht_capability(struct ie_tlv_iter *iter, int32_t rssi,
/* Parse out channel width set and short GI */
ht_cap = l_get_u8(data++);
- support_40mhz = util_is_bit_set(ht_cap, 1);
- short_gi_20mhz = util_is_bit_set(ht_cap, 5);
- short_gi_40mhz = util_is_bit_set(ht_cap, 6);
+ support_40mhz = test_bit(&ht_cap, 1);
+ short_gi_20mhz = test_bit(&ht_cap, 5);
+ short_gi_40mhz = test_bit(&ht_cap, 6);
data += 2;
@@ -1868,10 +1868,8 @@ static int ie_parse_ht_capability(struct ie_tlv_iter *iter, int32_t rssi,
*/
for (i = 31; i >= 0; i--) {
uint64_t drate;
- uint8_t byte = i / 8;
- uint8_t bit = i % 8;
- if (!util_is_bit_set(data[byte], bit))
+ if (!test_bit(data, i))
continue;
if (!support_40mhz)
@@ -1979,8 +1977,8 @@ static int ie_parse_vht_capability(struct ie_tlv_iter *vht_iter,
ht_cap = l_get_u8(data);
- short_gi_20mhz = util_is_bit_set(ht_cap, 5);
- short_gi_40mhz = util_is_bit_set(ht_cap, 6);
+ short_gi_20mhz = test_bit(&ht_cap, 5);
+ short_gi_40mhz = test_bit(&ht_cap, 6);
/* now move onto VHT */
len = ie_tlv_iter_get_length(vht_iter);
@@ -2418,16 +2416,16 @@ int ie_parse_neighbor_report(struct ie_tlv_iter *iter,
memcpy(info->addr, data + 0, 6);
- info->ht = util_is_bit_set(data[8], 3);
- info->md = util_is_bit_set(data[8], 2);
- info->immediate_block_ack = util_is_bit_set(data[8], 1);
- info->delayed_block_ack = util_is_bit_set(data[8], 0);
- info->rm = util_is_bit_set(data[9], 7);
- info->apsd = util_is_bit_set(data[9], 6);
- info->qos = util_is_bit_set(data[9], 5);
- info->spectrum_mgmt = util_is_bit_set(data[9], 4);
- info->key_scope = util_is_bit_set(data[9], 3);
- info->security = util_is_bit_set(data[9], 2);
+ info->ht = test_bit(data + 8, 3);
+ info->md = test_bit(data + 8, 2);
+ info->immediate_block_ack = test_bit(data + 8, 1);
+ info->delayed_block_ack = test_bit(data + 8, 0);
+ info->rm = test_bit(data + 9, 7);
+ info->apsd = test_bit(data + 9, 6);
+ info->qos = test_bit(data + 9, 5);
+ info->spectrum_mgmt = test_bit(data + 9, 4);
+ info->key_scope = test_bit(data + 9, 3);
+ info->security = test_bit(data + 9, 2);
info->reachable = bit_field(data[9], 0, 2);
info->oper_class = data[10];
@@ -2561,8 +2559,8 @@ int ie_parse_hs20_indication(struct ie_tlv_iter *iter, uint8_t *version_out,
hs20_config = l_get_u8(data + 4);
- pps_mo_present = util_is_bit_set(hs20_config, 1);
- domain_id_present = util_is_bit_set(hs20_config, 2);
+ pps_mo_present = test_bit(&hs20_config, 1);
+ domain_id_present = test_bit(&hs20_config, 2);
/*
* Hotspot 2.0 Spec - Section 3.1.1
diff --git a/src/rrm.c b/src/rrm.c
@@ -29,6 +29,7 @@
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/module.h"
#include "src/mpdu.h"
#include "src/netdev.h"
@@ -432,7 +433,7 @@ static void rrm_handle_beacon_scan(struct rrm_state *rrm,
.freqs = freqs,
.flush = true,
.duration = beacon->duration,
- .duration_mandatory = util_is_bit_set(beacon->info.mode, 4),
+ .duration_mandatory = test_bit(&beacon->info.mode, 4),
};
enum scan_band band = scan_oper_class_to_band(NULL, beacon->oper_class);
uint32_t freq;
@@ -522,7 +523,7 @@ static void rrm_handle_beacon_request(struct rrm_state *rrm,
* At least for the time being, we will not support autonomous
* reporting, so decline any request to do so.
*/
- if (util_is_bit_set(beacon->info.mode, 1))
+ if (test_bit(&beacon->info.mode, 1))
goto reject_refused;
/*
@@ -532,7 +533,7 @@ static void rrm_handle_beacon_request(struct rrm_state *rrm,
* must reject this request.
*/
if (!wiphy_has_ext_feature(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL)
- && util_is_bit_set(beacon->info.mode, 4))
+ && test_bit(&beacon->info.mode, 4))
goto reject_incapable;
/* advance to beacon request */
diff --git a/src/scan.c b/src/scan.c
@@ -300,7 +300,7 @@ static void scan_build_attr_ie(struct l_genl_msg *msg,
iov[iov_elems].iov_len = ext_capa[1] + 2;
iov_elems++;
- if (util_is_bit_set(ext_capa[2 + 3], 7)) {
+ if (test_bit(&ext_capa[2 + 3], 7)) {
/* Order 12 - Interworking */
interworking[0] = IE_TYPE_INTERWORKING;
interworking[1] = 1;
diff --git a/src/util.c b/src/util.c
@@ -33,6 +33,7 @@
#include <ell/ell.h>
+#include "ell/useful.h"
#include "src/util.h"
const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid)
@@ -155,7 +156,7 @@ bool util_string_to_address(const char *str, uint8_t *out_addr)
bool util_is_group_address(const uint8_t *addr)
{
/* 802.11-2016 section 9.2.2 */
- return util_is_bit_set(addr[0], 0);
+ return test_bit(addr, 0);
}
bool util_is_broadcast_address(const uint8_t *addr)
diff --git a/src/util.h b/src/util.h
@@ -43,12 +43,6 @@ bool util_is_valid_sta_address(const uint8_t *addr);
const char *util_get_domain(const char *identity);
const char *util_get_username(const char *identity);
-static inline bool util_is_bit_set(const uint8_t oct, int bit)
-{
- int mask = 1 << bit;
- return oct & mask ? true : false;
-}
-
/*
* Returns either true_value or false_value (depending if mask is 0xFF or 0x00
* respectively).
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -429,7 +429,7 @@ bool wiphy_rrm_capable(struct wiphy *wiphy)
bool wiphy_has_ext_feature(struct wiphy *wiphy, uint32_t feature)
{
return feature < sizeof(wiphy->ext_features) * 8 &&
- util_is_bit_set(wiphy->ext_features[feature >> 3], feature & 7);
+ test_bit(wiphy->ext_features, feature);
}
uint8_t wiphy_get_max_num_ssids_per_scan(struct wiphy *wiphy)