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
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index 23468c3..9fdf379 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 @@
 
 	/* 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 d9640aa..5c1a931 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -438,8 +438,8 @@
 	      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 @@
 		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 */