Changes to the patch set:
* Instead of using the bitmask constants, introduce inline functions.
* Apply in src/gsm/gsm0480.c.
* Also add functions for the transaction ID, encoded in the protocol
discriminator octet.
Neels Hofmeyr (3):
04.08: add inline funcs for pdisc + msg type bitmasks
04.08: switch to r99 msg type bitmasks by default
04.08: add inline funcs for transaction id bits
include/osmocom/gsm/protocol/gsm_04_08.h | 83 ++++++++++++++++++++++++++++++++
src/gsm/gsm0480.c | 4 +-
2 files changed, 85 insertions(+), 2 deletions(-)
--
2.1.4
Show replies by date
Add inline functions for both release <= 98 and release >= 99 as well as a
default define. Use the release 98 by default since the current code base uses
the r98 bitmasks.
These inline functions relieve callers of the decision on masking bits of the
protocol discriminator and message type octets.
Also add a define for the protocol discriminator extension to one octet length
(GSM48_PDISC_EXTEND).
Apply new pdisc function in gsm0480.c.
---
include/osmocom/gsm/protocol/gsm_04_08.h | 56 ++++++++++++++++++++++++++++++++
src/gsm/gsm0480.c | 4 +--
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h
b/include/osmocom/gsm/protocol/gsm_04_08.h
index eefaf2b..9930032 100644
--- a/include/osmocom/gsm/protocol/gsm_04_08.h
+++ b/include/osmocom/gsm/protocol/gsm_04_08.h
@@ -747,9 +747,65 @@ struct gsm48_rr_status {
#define GSM48_PDISC_SM_GPRS 0x0a
#define GSM48_PDISC_NC_SS 0x0b
#define GSM48_PDISC_LOC 0x0c
+#define GSM48_PDISC_EXTEND 0x0e
#define GSM48_PDISC_MASK 0x0f
#define GSM48_PDISC_USSD 0x11
+static inline uint8_t gsm48_hdr_pdisc(struct gsm48_hdr *hdr)
+{
+ /*
+ * 3GPP TS 24.007 version 12.0.0 Release 12,
+ * 11.2.3.1.1 Protocol discriminator
+ */
+ uint8_t pdisc = hdr->proto_discr & GSM48_PDISC_MASK;
+ if (pdisc == GSM48_PDISC_EXTEND)
+ return hdr->proto_discr;
+ return pdisc;
+}
+
+static inline uint8_t gsm48_hdr_msg_type_r98(struct gsm48_hdr *hdr)
+{
+ /*
+ * 3GPP TS 24.007 version 12.0.0 Release 12,
+ * 11.2.3.2.1 Message type octet (when accessing Release 98 and older
+ * networks only)
+ */
+ switch (gsm48_hdr_pdisc(hdr)) {
+ case GSM48_PDISC_MM:
+ case GSM48_PDISC_CC:
+ case GSM48_PDISC_NC_SS:
+ case GSM48_PDISC_GROUP_CC:
+ case GSM48_PDISC_BCAST_CC:
+ case GSM48_PDISC_LOC:
+ return hdr->msg_type & 0xbf;
+ default:
+ return hdr->msg_type;
+ }
+}
+
+static inline uint8_t gsm48_hdr_msg_type_r99(struct gsm48_hdr *hdr)
+{
+ /*
+ * 3GPP TS 24.007 version 12.0.0 Release 12,
+ * 11.2.3.2.2 Message type octet (when accessing Release 99 and newer
+ * networks)
+ */
+ switch (gsm48_hdr_pdisc(hdr)) {
+ case GSM48_PDISC_MM:
+ case GSM48_PDISC_CC:
+ return hdr->msg_type & 0x3f;
+ case GSM48_PDISC_NC_SS:
+ case GSM48_PDISC_GROUP_CC:
+ case GSM48_PDISC_BCAST_CC:
+ case GSM48_PDISC_LOC:
+ return hdr->msg_type & 0xbf;
+ default:
+ return hdr->msg_type;
+ }
+}
+
+#define gsm48_hdr_msg_type gsm48_hdr_msg_type_r98
+
/* Section 10.4 */
#define GSM48_MT_RR_INIT_REQ 0x3c
#define GSM48_MT_RR_ADD_ASS 0x3b
diff --git a/src/gsm/gsm0480.c b/src/gsm/gsm0480.c
index 952604b..8963b78 100644
--- a/src/gsm/gsm0480.c
+++ b/src/gsm/gsm0480.c
@@ -220,7 +220,7 @@ int gsm0480_decode_ussd_request(const struct gsm48_hdr *hdr, uint16_t
len,
return 0;
}
- if ((hdr->proto_discr & 0x0f) == GSM48_PDISC_NC_SS) {
+ if (gsm48_hdr_pdisc(hdr) == GSM48_PDISC_NC_SS) {
req->transaction_id = hdr->proto_discr & 0x70;
ss.transaction_id = req->transaction_id;
@@ -254,7 +254,7 @@ int gsm0480_decode_ss_request(const struct gsm48_hdr *hdr, uint16_t
len,
return 0;
}
- if ((hdr->proto_discr & 0x0f) == GSM48_PDISC_NC_SS) {
+ if (gsm48_hdr_pdisc(hdr) == GSM48_PDISC_NC_SS) {
req->transaction_id = hdr->proto_discr & 0x70;
rc = parse_ss(hdr, len, req);
}
--
2.1.4
---
include/osmocom/gsm/protocol/gsm_04_08.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/osmocom/gsm/protocol/gsm_04_08.h
b/include/osmocom/gsm/protocol/gsm_04_08.h
index 9930032..08f32b7 100644
--- a/include/osmocom/gsm/protocol/gsm_04_08.h
+++ b/include/osmocom/gsm/protocol/gsm_04_08.h
@@ -804,7 +804,7 @@ static inline uint8_t gsm48_hdr_msg_type_r99(struct gsm48_hdr *hdr)
}
}
-#define gsm48_hdr_msg_type gsm48_hdr_msg_type_r98
+#define gsm48_hdr_msg_type gsm48_hdr_msg_type_r99
/* Section 10.4 */
#define GSM48_MT_RR_INIT_REQ 0x3c
--
2.1.4
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(+)
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)
{
/*
--
2.1.4