[3/3] 04.08: add inline funcs for transaction id bits
diff mbox

Message ID 1457968008-15769-4-git-send-email-nhofmeyr@sysmocom.de
State New
Headers show

Commit Message

Neels Hofmeyr March 14, 2016, 3:06 p.m. UTC
Various users of gsm48_hdr apply the same hardcoded shifts/bitmasks to obtain
the transaction ID encoded in the upper nibble of the protocol discriminator.
Centralize. Patch for openbsc.git will follow.
---
 include/osmocom/gsm/protocol/gsm_04_08.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Patch
diff mbox

diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h b/include/osmocom/gsm/protocol/gsm_04_08.h
index 08f32b7..af9c2e9 100644
--- a/include/osmocom/gsm/protocol/gsm_04_08.h
+++ b/include/osmocom/gsm/protocol/gsm_04_08.h
@@ -763,6 +763,33 @@  static inline uint8_t gsm48_hdr_pdisc(struct gsm48_hdr *hdr)
 	return pdisc;
 }
 
+static inline uint8_t gsm48_hdr_trans_id(struct gsm48_hdr *hdr)
+{
+	/*
+	 * 3GPP TS 24.007 version 12.0.0 Release 12,
+	 * 11.2.3.1.3 Transaction identifier
+	 */
+	return (hdr->proto_discr & 0xf0) >> 4;
+}
+
+static inline uint8_t gsm48_hdr_trans_id_flip_ti(struct gsm48_hdr *hdr)
+{
+	/*
+	 * 3GPP TS 24.007 version 12.0.0 Release 12,
+	 * 11.2.3.1.3 Transaction identifier
+	 */
+	return gsm48_hdr_trans_id(hdr) ^ 0x08;
+}
+
+static inline uint8_t gsm48_hdr_trans_id_no_ti(struct gsm48_hdr *hdr)
+{
+	/*
+	 * 3GPP TS 24.007 version 12.0.0 Release 12,
+	 * 11.2.3.1.3 Transaction identifier
+	 */
+	return gsm48_hdr_trans_id(hdr) & 0x07;
+}
+
 static inline uint8_t gsm48_hdr_msg_type_r98(struct gsm48_hdr *hdr)
 {
 	/*