aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2020-06-05 14:16:11 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2020-06-09 12:36:38 +0200
commit2908dbfddd0dd89df34e876d417fe1d8f085408d (patch)
tree441f398595da02377a170680729fd27ae72165c0
parentef5b9b64342510278f795fedb9ec026f212587a8 (diff)
gsm0808: fix endieness of call identifier
The call identifier in the ASSIGNMENT COMMAND is encoded in the wrong endieness. 3GPP TS 48.008, section 3.2.2.105 specifies that the least significant byte should be transmitted first, which means that the endieness here is little endian. Lets make sure that the endieness is correctly transmitted, regardless of the host byte order. Change-Id: I6468e502f552f99ab54aec9d4b1c169fdc0adfb8 Related: OS#4582
-rw-r--r--src/gsm/gsm0808.c12
-rw-r--r--tests/gsm0808/gsm0808_test.c6
2 files changed, 14 insertions, 4 deletions
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 23468c3e..9fdf3794 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <osmocom/core/byteswap.h>
+#include <osmocom/core/endian.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm0808_utils.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
@@ -515,7 +516,16 @@ struct msgb *gsm0808_create_ass2(const struct gsm0808_channel_type *ct,
/* AoIP: Call Identifier 3.2.2.105 */
if (ci) {
- ci_sw = osmo_htonl(*ci);
+ /* NOTE: 3GPP TS 48.008, section 3.2.2.105 specifies that
+ the least significant byte should be transmitted first.
+ On x86, this would mean that the endieness is already
+ correct, however a platform independed implementation
+ is required: */
+#ifndef OSMO_IS_LITTLE_ENDIAN
+ ci_sw = osmo_swab32(*ci);
+#else
+ ci_sw = *ci;
+#endif
msgb_tv_fixed_put(msg, GSM0808_IE_CALL_ID, sizeof(ci_sw),
(uint8_t *) & ci_sw);
}
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index d9640aa3..5c1a9313 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -438,8 +438,8 @@ static void test_create_ass()
0x04, GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17,
0x04, 0xd2, GSM0808_IE_SPEECH_CODEC_LIST, 0x07,
GSM0808_SCT_FR3 | 0x50, 0xef, 0xcd, GSM0808_SCT_FR2 | 0xa0, 0x9f,
- GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xaa, 0xbb,
- 0xcc, 0xdd };
+ GSM0808_SCT_CSD | 0x90, 0xc0, GSM0808_IE_CALL_ID, 0xdd, 0xcc,
+ 0xbb, 0xaa };
struct msgb *msg;
struct gsm0808_channel_type ct;
@@ -499,7 +499,7 @@ static void test_create_ass2()
GSM0808_SCT_CSD | 0x90,
0xc0,
GSM0808_IE_CALL_ID,
- 0xde, 0xad, 0xfa, 0xce, /* CallID */
+ 0xce, 0xfa, 0xad, 0xde, /* CallID */
0x83, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, 0x45, /* Kc */
GSM0808_IE_GLOBAL_CALL_REF, 0x0d, /* GCR, length */
0x03, 0x44, 0x44, 0x44, /* GCR, Net ID */