]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
radiotap: Fix compiler issues with packed structures
authorJouni Malinen <j@w1.fi>
Sun, 21 Feb 2021 10:07:38 +0000 (12:07 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 21 Feb 2021 10:40:58 +0000 (12:40 +0200)
Replace the Radiotap parser platform.h file with use of helper functions
from utils/common.h to avoid compiler issues with the updated design and
getting pointers to members of packet structs.

Silence the warning about _next_bitmap assignment. This pointer is
dereferenced only with operations that are safe for unaligned access, so
the compiler warning is not helpful here.

__packed might not be defined in this context, so use STRUCT_PACKED from
utils/common.h.

Fixes: e6ac269433a3 ("radiotap: Update radiotap parser")
Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/platform.h
src/utils/radiotap.c
src/utils/radiotap.h

index 813987eb660648cf17d6d6e1b656648220e5922e..b2ad856b91b1c315a933285d5dfc7286f6480e65 100644 (file)
@@ -1,21 +1,18 @@
+/*
+ * Platform definitions for Radiotap parser
+ * Copyright (c) 2021, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
 #ifndef PLATFORM_H
 #define PLATFORM_H
 
 #include "includes.h"
 #include "common.h"
 
-#define le16_to_cpu            le_to_host16
-#define le32_to_cpu            le_to_host32
-
-#define get_unaligned(p)                                       \
-({                                                             \
-       struct packed_dummy_struct {                            \
-               typeof(*(p)) __val;                             \
-       } __attribute__((packed)) *__ptr = (void *) (p);        \
-                                                               \
-       __ptr->__val;                                           \
-})
-#define get_unaligned_le16(p)  le16_to_cpu(get_unaligned((le16 *)(p)))
-#define get_unaligned_le32(p)  le32_to_cpu(get_unaligned((le32 *)(p)))
+#define get_unaligned_le16(p)  WPA_GET_LE16((void *) (p))
+#define get_unaligned_le32(p)  WPA_GET_LE32((void *) (p))
 
 #endif /* PLATFORM_H */
index 6dfe3053eec1d6f5a792db9cf3aa8cf7c4960421..6dfe298189b5e99fcc9de5c24053e4bc95a48584 100644 (file)
@@ -111,7 +111,7 @@ int ieee80211_radiotap_iterator_init(
        iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header);
        iterator->_next_ns_data = NULL;
        iterator->_reset_on_ext = 0;
-       iterator->_next_bitmap = &radiotap_header->it_present;
+       iterator->_next_bitmap = (le32 *) (((u8 *) radiotap_header) + offsetof(struct ieee80211_radiotap_header, it_present));
        iterator->_next_bitmap++;
        iterator->_vns = vns;
        iterator->current_namespace = &radiotap_ns;
index 17bb6330d6b8e6170ca18b2cb192f883f2d3959b..488d5a3b42c8d7ba03e6ff77871a61982e601bdb 100644 (file)
@@ -39,7 +39,7 @@ struct ieee80211_radiotap_header {
         * @it_present: (first) present word
         */
        le32 it_present;
-} __packed;
+} STRUCT_PACKED;
 
 /* version is always 0 */
 #define PKTHDR_RADIOTAP_VERSION        0