Change in libosmocore[master]: Fix struct bitfields on big endian systems

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Feb 8 17:23:25 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/22679 )

Change subject: Fix struct bitfields on big endian systems
......................................................................

Fix struct bitfields on big endian systems

Changes done by contrib/struct_endianess.py.

Change-Id: Ia9cb1ef2ba2bfff9ef713c7d1cf388931dae1c46
---
M include/osmocom/gprs/protocol/gsm_08_18.h
M include/osmocom/gsm/protocol/gsm_23_032.h
M src/gb/frame_relay.c
3 files changed, 88 insertions(+), 0 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gprs/protocol/gsm_08_18.h b/include/osmocom/gprs/protocol/gsm_08_18.h
index c10c244..0d002b5 100644
--- a/include/osmocom/gprs/protocol/gsm_08_18.h
+++ b/include/osmocom/gprs/protocol/gsm_08_18.h
@@ -4,6 +4,7 @@
 #pragma once
 
 #include <stdint.h>
+#include <osmocom/core/endian.h>
 
 /*! Fixed BVCI definitions (Section 5.4.1) */
 #define BVCI_SIGNALLING	0x0000
diff --git a/include/osmocom/gsm/protocol/gsm_23_032.h b/include/osmocom/gsm/protocol/gsm_23_032.h
index 5be98a2..a4c0506 100644
--- a/include/osmocom/gsm/protocol/gsm_23_032.h
+++ b/include/osmocom/gsm/protocol/gsm_23_032.h
@@ -50,8 +50,13 @@
 };
 
 struct gad_raw_head {
+#if OSMO_IS_LITTLE_ENDIAN
 	uint8_t spare:4,
 		type:4;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	uint8_t type:4, spare:4;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_ell_point {
@@ -61,14 +66,23 @@
 } __attribute__ ((packed));
 
 struct gad_raw_ell_point_unc_circle {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_ELL_POINT_UNC_CIRCLE */
 	uint8_t lat[3];
 	uint8_t lon[3];
 	uint8_t unc:7,
 		spare2:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[3];
+	uint8_t lon[3];
+	uint8_t spare2:1, unc:7;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_ell_point_unc_ellipse {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_ELL_POINT_UNC_ELLIPSE */
 	uint8_t lat[3];
 	uint8_t lon[3];
@@ -79,12 +93,27 @@
 	uint8_t major_ori;
 	uint8_t confidence:7,
 		spare3:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[3];
+	uint8_t lon[3];
+	uint8_t spare1:1, unc_semi_major:7;
+	uint8_t spare2:1, unc_semi_minor:7;
+	uint8_t major_ori;
+	uint8_t spare3:1, confidence:7;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_polygon {
 	struct {
+#if OSMO_IS_LITTLE_ENDIAN
 		uint8_t num_points:4;
 		uint8_t type:4; /*!< type = GAD_TYPE_POLYGON */
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+		uint8_t type:4, num_points:4;
+#endif
 	} h;
 	struct {
 		uint8_t lat[3];
@@ -100,6 +129,7 @@
 } __attribute__ ((packed));
 
 struct gad_raw_ell_point_alt_unc_ell {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_ELL_POINT_ALT_UNC_ELL */
 	uint8_t lat[3];
 	uint8_t lon[3];
@@ -113,9 +143,22 @@
 		spare3:1;
 	uint8_t confidence:7,
 		spare4:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[3];
+	uint8_t lon[3];
+	uint8_t alt[2];
+	uint8_t spare1:1, unc_semi_major:7;
+	uint8_t spare2:1, unc_semi_minor:7;
+	uint8_t major_ori;
+	uint8_t spare3:1, unc_alt:7;
+	uint8_t spare4:1, confidence:7;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_ell_arc {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_ELL_ARC */
 	uint8_t lat[3];
 	uint8_t lon[3];
@@ -126,9 +169,21 @@
 	uint8_t incl_angle;
 	uint8_t confidence:7,
 		spare2:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[3];
+	uint8_t lon[3];
+	uint8_t inner_r[2];
+	uint8_t spare1:1, unc_r:7;
+	uint8_t ofs_angle;
+	uint8_t incl_angle;
+	uint8_t spare2:1, confidence:7;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_ha_ell_point_unc_ell {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_HA_ELL_POINT_UNC_ELLIPSE */
 	uint8_t lat[4];
 	uint8_t lon[4];
@@ -138,9 +193,21 @@
 	uint8_t major_ori;
 	uint8_t confidence:7,
 		spare1:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[4];
+	uint8_t lon[4];
+	uint8_t alt[3];
+	uint8_t unc_semi_major;
+	uint8_t unc_semi_minor;
+	uint8_t major_ori;
+	uint8_t spare1:1, confidence:7;
+#endif
 } __attribute__ ((packed));
 
 struct gad_raw_ha_ell_point_alt_unc_ell {
+#if OSMO_IS_LITTLE_ENDIAN
 	struct gad_raw_head h; /*!< type = GAD_TYPE_HA_ELL_POINT_ALT_UNC_ELL */
 	uint8_t lat[4];
 	uint8_t lon[4];
@@ -153,6 +220,19 @@
 	uint8_t unc_alt;
 	uint8_t v_confidence:7,
 		spare2:1;
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	struct gad_raw_head h;
+	uint8_t lat[4];
+	uint8_t lon[4];
+	uint8_t alt[3];
+	uint8_t unc_semi_major;
+	uint8_t unc_semi_minor;
+	uint8_t major_ori;
+	uint8_t spare1:1, h_confidence:7;
+	uint8_t unc_alt;
+	uint8_t spare2:1, v_confidence:7;
+#endif
 } __attribute__ ((packed));
 
 /*! GAD PDU in network-byte-order according to 3GPP TS 23.032 GAD: Universal Geographical Area Description. */
diff --git a/src/gb/frame_relay.c b/src/gb/frame_relay.c
index c54384e..84cd17f 100644
--- a/src/gb/frame_relay.c
+++ b/src/gb/frame_relay.c
@@ -123,6 +123,7 @@
 
 /* Value part of the Q.933 Annex A.3.3 IE */
 struct q933_a_pvc_sts {
+#if OSMO_IS_LITTLE_ENDIAN
 	uint8_t dlci_msb:6,
 		spare:1,
 		ext0:1;
@@ -136,6 +137,12 @@
 		spare2:3,
 		ext2:1;
 
+#elif OSMO_IS_BIG_ENDIAN
+/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianess.py) */
+	uint8_t ext0:1, spare:1, dlci_msb:6;
+	uint8_t ext1:1, dlci_lsb:4, space1:3;
+	uint8_t ext2:1, spare2:3, new:1, delete:1, active:1, reserved:1;
+#endif
 } __attribute__((packed));
 
 /* RX Message: 14 [ 00 01 03 08 00 75  95 01 01 00 03 02 01 00 ] */

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/22679
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia9cb1ef2ba2bfff9ef713c7d1cf388931dae1c46
Gerrit-Change-Number: 22679
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Assignee: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-CC: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210208/aff6fca9/attachment.htm>


More information about the gerrit-log mailing list