]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
BSS: Use wrapper function for getting a pointer to the IE buffer
authorJouni Malinen <jouni@codeaurora.org>
Mon, 16 Nov 2020 14:21:56 +0000 (16:21 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 16 Nov 2020 14:21:56 +0000 (16:21 +0200)
This makes it easier to change the internal struct wpa_bss design for
storing the variable length IE buffers.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
wpa_supplicant/bss.c
wpa_supplicant/bss.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/events.c
wpa_supplicant/op_classes.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/rrm.c
wpa_supplicant/wpa_supplicant.c

index c64ddbcedd7c2bf6195e59b8dc2c7ee00673be26..93ef6fe145296139e7e83185e95f1f8112e9b5bd 100644 (file)
@@ -361,8 +361,7 @@ static bool is_p2p_pending_bss(struct wpa_supplicant *wpa_s,
                      ETH_ALEN) == 0)
                return true;
        if (!is_zero_ether_addr(wpa_s->pending_join_dev_addr) &&
-           p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
-                              addr) == 0 &&
+           p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len, addr) == 0 &&
            os_memcmp(addr, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0)
                return true;
 #endif /* CONFIG_P2P */
@@ -568,7 +567,7 @@ static u32 wpa_bss_compare_res(const struct wpa_bss *old,
                changes |= WPA_BSS_MODE_CHANGED_FLAG;
 
        if (old->ie_len == new_res->ie_len &&
-           os_memcmp(old + 1, new_res + 1, old->ie_len) == 0)
+           os_memcmp(wpa_bss_ie_ptr(old), new_res + 1, old->ie_len) == 0)
                return changes;
        changes |= WPA_BSS_IES_CHANGED_FLAG;
 
@@ -1075,7 +1074,7 @@ struct wpa_bss * wpa_bss_get_p2p_dev_addr(struct wpa_supplicant *wpa_s,
        struct wpa_bss *bss, *found = NULL;
        dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss, list) {
                u8 addr[ETH_ALEN];
-               if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
+               if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len,
                                       addr) != 0 ||
                    os_memcmp(addr, dev_addr, ETH_ALEN) != 0)
                        continue;
@@ -1139,7 +1138,7 @@ struct wpa_bss * wpa_bss_get_id_range(struct wpa_supplicant *wpa_s,
  */
 const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
 {
-       return get_ie((const u8 *) (bss + 1), bss->ie_len, ie);
+       return get_ie(wpa_bss_ie_ptr(bss), bss->ie_len, ie);
 }
 
 
@@ -1154,7 +1153,7 @@ const u8 * wpa_bss_get_ie(const struct wpa_bss *bss, u8 ie)
  */
 const u8 * wpa_bss_get_ie_ext(const struct wpa_bss *bss, u8 ext)
 {
-       return get_ie_ext((const u8 *) (bss + 1), bss->ie_len, ext);
+       return get_ie_ext(wpa_bss_ie_ptr(bss), bss->ie_len, ext);
 }
 
 
@@ -1172,7 +1171,7 @@ const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type)
        const u8 *ies;
        const struct element *elem;
 
-       ies = (const u8 *) (bss + 1);
+       ies = wpa_bss_ie_ptr(bss);
 
        for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, bss->ie_len) {
                if (elem->datalen >= 4 &&
@@ -1205,7 +1204,7 @@ const u8 * wpa_bss_get_vendor_ie_beacon(const struct wpa_bss *bss,
        if (bss->beacon_ie_len == 0)
                return NULL;
 
-       ies = (const u8 *) (bss + 1);
+       ies = wpa_bss_ie_ptr(bss);
        ies += bss->ie_len;
 
        for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies,
@@ -1239,7 +1238,7 @@ struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
        if (buf == NULL)
                return NULL;
 
-       pos = (const u8 *) (bss + 1);
+       pos = wpa_bss_ie_ptr(bss);
        end = pos + bss->ie_len;
 
        while (end - pos > 1) {
@@ -1288,7 +1287,7 @@ struct wpabuf * wpa_bss_get_vendor_ie_multi_beacon(const struct wpa_bss *bss,
        if (buf == NULL)
                return NULL;
 
-       pos = (const u8 *) (bss + 1);
+       pos = wpa_bss_ie_ptr(bss);
        pos += bss->ie_len;
        end = pos + bss->beacon_ie_len;
 
index b3d574eeecd84e4265cf5ab07a04d632d92816f1..a918bc35633fd6d1769630256d555ce9cb6a5b0b 100644 (file)
@@ -113,6 +113,11 @@ struct wpa_bss {
        /* followed by beacon_ie_len octets of IEs */
 };
 
+static inline const u8 * wpa_bss_ie_ptr(const struct wpa_bss *bss)
+{
+       return (const u8 *) (bss + 1);
+}
+
 void wpa_bss_update_start(struct wpa_supplicant *wpa_s);
 void wpa_bss_update_scan_res(struct wpa_supplicant *wpa_s,
                             struct wpa_scan_res *res,
index fcae260b9bedd238ac874a29575c72433a402e57..1f91723321eb0a88261e7ed42649896a43c8853a 100644 (file)
@@ -5022,7 +5022,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
                        return 0;
                pos += ret;
 
-               ie = (const u8 *) (bss + 1);
+               ie = wpa_bss_ie_ptr(bss);
                for (i = 0; i < bss->ie_len; i++) {
                        ret = os_snprintf(pos, end - pos, "%02x", *ie++);
                        if (os_snprintf_error(end - pos, ret))
@@ -5189,7 +5189,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
 
 #ifdef CONFIG_WPS
        if (mask & WPA_BSS_MASK_WPS_SCAN) {
-               ie = (const u8 *) (bss + 1);
+               ie = wpa_bss_ie_ptr(bss);
                ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
                if (ret >= end - pos)
                        return 0;
@@ -5200,7 +5200,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
 
 #ifdef CONFIG_P2P
        if (mask & WPA_BSS_MASK_P2P_SCAN) {
-               ie = (const u8 *) (bss + 1);
+               ie = wpa_bss_ie_ptr(bss);
                ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
                if (ret >= end - pos)
                        return 0;
@@ -5212,7 +5212,8 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
 #ifdef CONFIG_WIFI_DISPLAY
        if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
                struct wpabuf *wfd;
-               ie = (const u8 *) (bss + 1);
+
+               ie = wpa_bss_ie_ptr(bss);
                wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
                                                  WFD_IE_VENDOR_TYPE);
                if (wfd) {
@@ -5290,7 +5291,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
 
 #ifdef CONFIG_MESH
        if (mask & WPA_BSS_MASK_MESH_SCAN) {
-               ie = (const u8 *) (bss + 1);
+               ie = wpa_bss_ie_ptr(bss);
                ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
                if (ret >= end - pos)
                        return 0;
@@ -5337,7 +5338,7 @@ static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
                        return 0;
                pos += ret;
 
-               ie = (const u8 *) (bss + 1);
+               ie = wpa_bss_ie_ptr(bss);
                ie += bss->ie_len;
                for (i = 0; i < bss->beacon_ie_len; i++) {
                        ret = os_snprintf(pos, end - pos, "%02x", *ie++);
index b53746b70fd59ae5c002e41ab5a24a2c31a21949..89e6e73069bf0095615a0678bd192891f2e80409 100644 (file)
@@ -1852,7 +1852,7 @@ wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s,
                                     const struct wpa_bss *bss, int snr)
 {
        int rate = wpa_bss_get_max_rate(bss);
-       const u8 *ies = (const void *) (bss + 1);
+       const u8 *ies = wpa_bss_ie_ptr(bss);
        size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
 
        return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr);
@@ -3029,7 +3029,7 @@ static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
        if (!bss)
                return;
 
-       ieprb = (const u8 *) (bss + 1);
+       ieprb = wpa_bss_ie_ptr(bss);
        iebcn = ieprb + bss->ie_len;
 
        if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
index 461ae545838905dbface8c8257f4a5d7ad1e05f7..b4c0c8a0b0d8207f8964863b1bb42f424d5b9702 100644 (file)
@@ -424,12 +424,13 @@ static int wpas_sta_secondary_channel_offset(struct wpa_bss *bss, u8 *current,
                                             u8 *channel)
 {
 
-       u8 *ies, phy_type;
+       const u8 *ies;
+       u8 phy_type;
        size_t ies_len;
 
        if (!bss)
                return -1;
-       ies = (u8 *) (bss + 1);
+       ies = wpa_bss_ie_ptr(bss);
        ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
        return wpas_get_op_chan_phy(bss->freq, ies, ies_len, current,
                                    channel, &phy_type);
index 75e62a9e99b2a68cb29c95a9db768d68ce1e38a5..9bcce8c6c22160bdbb11766aa5d231f5e0fcef3c 100644 (file)
@@ -1107,9 +1107,9 @@ static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
                           "group is persistent - BSS " MACSTR
                           " did not include P2P IE", MAC2STR(bssid));
                wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
-                           (u8 *) (bss + 1), bss->ie_len);
+                           wpa_bss_ie_ptr(bss), bss->ie_len);
                wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
-                           ((u8 *) bss + 1) + bss->ie_len,
+                           wpa_bss_ie_ptr(bss) + bss->ie_len,
                            bss->beacon_ie_len);
                return 0;
        }
@@ -5200,7 +5200,7 @@ static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
                wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
                           "from BSS table: %d MHz (SSID %s)", freq,
                           wpa_ssid_txt(bss->ssid, bss->ssid_len));
-               if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
+               if (p2p_parse_dev_addr(wpa_bss_ie_ptr(bss), bss->ie_len,
                                       dev_addr) == 0 &&
                    os_memcmp(wpa_s->pending_join_dev_addr,
                              wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 &&
index f0872663617819f03db171fa33f93a254975ad85..a9c7b90fdc93bc372f9bb80add9a82697d2edcff 100644 (file)
@@ -775,10 +775,10 @@ int wpas_get_op_chan_phy(int freq, const u8 *ies, size_t ies_len,
 static int wpas_beacon_rep_add_frame_body(struct bitfield *eids,
                                          enum beacon_report_detail detail,
                                          struct wpa_bss *bss, u8 *buf,
-                                         size_t buf_len, u8 **ies_buf,
+                                         size_t buf_len, const u8 **ies_buf,
                                          size_t *ie_len, int add_fixed)
 {
-       u8 *ies = *ies_buf;
+       const u8 *ies = *ies_buf;
        size_t ies_len = *ie_len;
        u8 *pos = buf;
        int rem_len;
@@ -860,7 +860,7 @@ static int wpas_add_beacon_rep_elem(struct beacon_rep_data *data,
                                    struct wpa_bss *bss,
                                    struct wpabuf **wpa_buf,
                                    struct rrm_measurement_beacon_report *rep,
-                                   u8 **ie, size_t *ie_len, u8 idx)
+                                   const u8 **ie, size_t *ie_len, u8 idx)
 {
        int ret;
        u8 *buf, *pos;
@@ -927,8 +927,8 @@ static int wpas_add_beacon_rep(struct wpa_supplicant *wpa_s,
                               u64 start, u64 parent_tsf)
 {
        struct beacon_rep_data *data = &wpa_s->beacon_rep_data;
-       u8 *ies = (u8 *) (bss + 1);
-       u8 *pos = ies;
+       const u8 *ies = wpa_bss_ie_ptr(bss);
+       const u8 *pos = ies;
        size_t ies_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len;
        struct rrm_measurement_beacon_report rep;
        u8 idx = 0;
index b51e31785745676337ac2c64b2637050504fe67e..5cf45b4ffacaf642a625b620d994734cd783cc6e 100644 (file)
@@ -2276,8 +2276,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
 
 #ifdef CONFIG_TDLS
        if (bss)
-               wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1),
-                               bss->ie_len);
+               wpa_tdls_ap_ies(wpa_s->wpa, wpa_bss_ie_ptr(bss), bss->ie_len);
 #endif /* CONFIG_TDLS */
 
 #ifdef CONFIG_MBO