Change in libosmocore[master]: Update 3GPP TS 08.08 Cause handling

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Nov 18 20:14:06 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11577 )

Change subject: Update 3GPP TS 08.08 Cause handling
......................................................................

Update 3GPP TS 08.08 Cause handling

* add Class definitions
* add helper to check for extended bit
* add helper to get Cause's Class
* use enum in gsm0808_cause_name() and gsm0808_create_cipher_reject() to
  avoid confusion between class and cause
* update gsm0808_create_cipher_reject() comments

Change-Id: I31b31dfc22eb4b6b07089e1255246ac458125340
Related: OS#3187
---
M TODO-RELEASE
M include/osmocom/gsm/gsm0808.h
M include/osmocom/gsm/gsm0808_utils.h
M include/osmocom/gsm/protocol/gsm_08_08.h
M src/gsm/gsm0808.c
M src/gsm/libosmogsm.map
6 files changed, 59 insertions(+), 9 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/TODO-RELEASE b/TODO-RELEASE
index 5222ec9..00720f6 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -11,3 +11,8 @@
 libosmogsm	gsm48_push_l3hdr()	(re)introduced in gsm/gsm48.h (GSM 04.08 API)
 libosmogsm	gsm48_push_l3hdr_tid()	a wrapper around gsm48_push_l3hdr()
 libosmocore	msgb_l4len		new symbol (exposed as 'static inline' in msgb.h)
+libosmogsm     gsm0808_cause_class_name()      getter for class description
+libosmogsm     gsm0808_cause_class()   getter for cause class
+libosmogsm     gsm0808_cause_ext()     check for cause extended bit
+libosmogsm     gsm0808_cause_name()    use enum as parameter
+libosmogsm     gsm0808_create_cipher_reject()          use enum as parameter
diff --git a/include/osmocom/gsm/gsm0808.h b/include/osmocom/gsm/gsm0808.h
index 652aae9..66f7c27 100644
--- a/include/osmocom/gsm/gsm0808.h
+++ b/include/osmocom/gsm/gsm0808.h
@@ -50,7 +50,7 @@
 struct msgb *gsm0808_create_cipher(const struct gsm0808_encrypt_info *ei,
 				   const uint8_t *cipher_response_mode);
 struct msgb *gsm0808_create_cipher_complete(struct msgb *layer3, uint8_t alg_id);
-struct msgb *gsm0808_create_cipher_reject(uint8_t cause);
+struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause);
 struct msgb *gsm0808_create_classmark_request();
 struct msgb *gsm0808_create_classmark_update(const uint8_t *cm2, uint8_t cm2_len,
 					     const uint8_t *cm3, uint8_t cm3_len);
@@ -178,7 +178,8 @@
 
 const char *gsm0808_bssmap_name(uint8_t msg_type);
 const char *gsm0808_bssap_name(uint8_t msg_type);
-const char *gsm0808_cause_name(uint8_t cause);
+const char *gsm0808_cause_name(enum gsm0808_cause cause);
+const char *gsm0808_cause_class_name(enum gsm0808_cause_class class);
 
 extern const struct value_string gsm0808_lcls_config_names[];
 extern const struct value_string gsm0808_lcls_control_names[];
diff --git a/include/osmocom/gsm/gsm0808_utils.h b/include/osmocom/gsm/gsm0808_utils.h
index f70dbdb..b56e263 100644
--- a/include/osmocom/gsm/gsm0808_utils.h
+++ b/include/osmocom/gsm/gsm0808_utils.h
@@ -107,7 +107,20 @@
 uint16_t gsm0808_sc_cfg_from_gsm48_mr_cfg(const struct gsm48_multi_rate_conf *cfg, bool fr);
 void gsm48_mr_cfg_from_gsm0808_sc_cfg(struct gsm48_multi_rate_conf *cfg, uint16_t s15_s0);
 
-/*! Return 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t. */
+/*! \returns 3GPP TS 08.08 §3.2.2.5 Class of a given Cause */
+static inline enum gsm0808_cause_class gsm0808_cause_class(enum gsm0808_cause cause)
+{
+	return (cause << 1) >> 4;
+}
+
+/*! \returns true if 3GPP TS 08.08 §3.2.2.5 Class has extended bit set */
+static inline bool gsm0808_cause_ext(enum gsm0808_cause cause)
+{
+	/* check that cause looks like 1XXX0000 where XXX represent class */
+	return (cause & 0x80) && !(cause & 0x0F);
+}
+
+/*! \returns 3GPP TS 48.008 3.2.2.49 Current Channel Type 1 from enum gsm_chan_t. */
 static inline uint8_t gsm0808_current_channel_type_1(enum gsm_chan_t type)
 {
 	switch (type) {
diff --git a/include/osmocom/gsm/protocol/gsm_08_08.h b/include/osmocom/gsm/protocol/gsm_08_08.h
index 8431ace..2317e78 100644
--- a/include/osmocom/gsm/protocol/gsm_08_08.h
+++ b/include/osmocom/gsm/protocol/gsm_08_08.h
@@ -384,6 +384,18 @@
 	GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY				= 0x62,
 };
 
+/* 3GPP TS 08.08 §3.2.2.5 Cause Class */
+enum gsm0808_cause_class {
+	GSM0808_CAUSE_CLASS_NORM0		= 0,
+	GSM0808_CAUSE_CLASS_NORM1		= 1,
+	GSM0808_CAUSE_CLASS_RES_UNAVAIL		= 2,
+	GSM0808_CAUSE_CLASS_SRV_OPT_NA		= 3,
+	GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL	= 4,
+	GSM0808_CAUSE_CLASS_INVAL		= 5,
+	GSM0808_CAUSE_CLASS_PERR		= 6,
+	GSM0808_CAUSE_CLASS_INTW		= 7,
+};
+
 /* GSM 08.08 3.2.2.11 Channel Type */
 enum gsm0808_chan_indicator {
 	GSM0808_CHAN_SPEECH = 1,
diff --git a/src/gsm/gsm0808.c b/src/gsm/gsm0808.c
index e5c3e30..791ebc2 100644
--- a/src/gsm/gsm0808.c
+++ b/src/gsm/gsm0808.c
@@ -265,18 +265,18 @@
 }
 
 /*! Create BSSMAP Cipher Mode Reject message
- *  \param[in] cause TS 08.08 cause value
+ *  \param[in] cause 3GPP TS 08.08 §3.2.2.5 cause value
  *  \returns callee-allocated msgb with BSSMAP Cipher Mode Reject message */
-struct msgb *gsm0808_create_cipher_reject(uint8_t cause)
+struct msgb *gsm0808_create_cipher_reject(enum gsm0808_cause cause)
 {
 	struct msgb *msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
-					       "bssmap: clear complete");
+					       "bssmap: cipher mode reject");
 	if (!msg)
 		return NULL;
 
 	msgb_v_put(msg, BSS_MAP_MSG_CIPHER_MODE_REJECT);
-	/* FIXME: support 2-byte cause value as per 3GPP TS 08.08 §3.2.2.5 */
-	msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, &cause);
+
+	msgb_tlv_put(msg, GSM0808_IE_CAUSE, 1, (const uint8_t *)&cause);
 
 	msg->l3h = msgb_tv_push(msg, BSSAP_MSG_BSS_MANAGEMENT, msgb_length(msg));
 
@@ -1271,8 +1271,26 @@
 	{ 0, NULL }
 };
 
+static const struct value_string gsm0808_cause_class_names[] = {
+	{ GSM0808_CAUSE_CLASS_NORM0,		"Normal event" },
+	{ GSM0808_CAUSE_CLASS_NORM1,		"Normal event" },
+	{ GSM0808_CAUSE_CLASS_RES_UNAVAIL,	"Resource unavailable" },
+	{ GSM0808_CAUSE_CLASS_SRV_OPT_NA,	"Service or option not available" },
+	{ GSM0808_CAUSE_CLASS_SRV_OPT_NIMPL,	"Service or option not implemented" },
+	{ GSM0808_CAUSE_CLASS_INVAL,		"Invalid message" },
+	{ GSM0808_CAUSE_CLASS_PERR,		"Protocol error" },
+	{ GSM0808_CAUSE_CLASS_INTW,		"Interworking" },
+	{ 0, NULL }
+};
+
+/*! Return string name of BSSMAP Cause Class name */
+const char *gsm0808_cause_class_name(enum gsm0808_cause_class class)
+{
+	return get_value_string(gsm0808_cause_class_names, class);
+}
+
 /*! Return string name of BSSMAP Cause name */
-const char *gsm0808_cause_name(uint8_t cause)
+const char *gsm0808_cause_name(enum gsm0808_cause cause)
 {
 	return get_value_string(gsm0808_cause_names, cause);
 }
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 6234d94..32e4ce9 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -148,6 +148,7 @@
 gsm0808_bssap_name;
 gsm0808_bssmap_name;
 gsm0808_cause_name;
+gsm0808_cause_class_name;
 gsm0808_create_ass;
 gsm0808_create_assignment_completed;
 gsm0808_create_ass_compl;

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I31b31dfc22eb4b6b07089e1255246ac458125340
Gerrit-Change-Number: 11577
Gerrit-PatchSet: 9
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181118/67e737ea/attachment.htm>


More information about the gerrit-log mailing list