falconia has uploaded this change for review.
gsm BC-IE: add functions for specific rules in each direction
3GPP TS 24.008 section 10.5.4.5 defines not only the format and
coding of bearer capability IE, but also a number of specific rules
for MS->network and network->MS directions; these rules are often
quite different between the two directions. In addition to BC-IE
encoding and decoding functions implemented in the previous patch,
provide additional functions that apply the specific rules for
each direction.
Change-Id: If3819b29ea9f9702ffc4f1b7f6dedb21e9ec15de
---
M include/osmocom/gsm/gsm48_ie.h
M src/gsm/gsm48_ie.c
M src/gsm/libosmogsm.map
3 files changed, 150 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/93/44193/1
diff --git a/include/osmocom/gsm/gsm48_ie.h b/include/osmocom/gsm/gsm48_ie.h
index df733fe..f6e1d07 100644
--- a/include/osmocom/gsm/gsm48_ie.h
+++ b/include/osmocom/gsm/gsm48_ie.h
@@ -150,6 +150,8 @@
int osmo_gsm48_encode_bcap_hl(struct msgb *msg, bool lv_only,
const struct osmo_bcap_hl *bc,
bool ms_rules_6d_6e);
+int osmo_gsm48_bcap_apply_ms_rules(struct osmo_bcap_hl *bc);
+int osmo_gsm48_bcap_apply_network_rules(struct osmo_bcap_hl *bc);
/* decode 'call control cap' */
int gsm48_decode_cccap(struct gsm_mncc_cccap *ccap, const uint8_t *lv);
/* encode 'call control cap' */
diff --git a/src/gsm/gsm48_ie.c b/src/gsm/gsm48_ie.c
index 4fc5426..665e3c8 100644
--- a/src/gsm/gsm48_ie.c
+++ b/src/gsm/gsm48_ie.c
@@ -808,6 +808,152 @@
return osmo_gsm48_encode_bcap_ll(msg, lv_only, &lld);
}
+/*! Apply rules for MS->network direction to GSM 04.08 bearer capability IE
+ * prior to encoding.
+ * \param[in/out] bc High-level decoded BC-IE to be preened.
+ * \returns 0 on success; negative on error.
+ *
+ * If the information transfer capability is anything other than speech,
+ * this function does nothing. However, if a speech call is to be made,
+ * the MS implementation calling this API needs to fill out the BC-IE
+ * structure as follows:
+ *
+ * - List all supported GSM speech codecs in the usual part of the struct,
+ * in whatever order of preference you wish to indicate, but with FRv1
+ * always included per GSM spec rules;
+ *
+ * - Leave the radio channel requirement field uninitialized.
+ *
+ * This function fills out the radio channel req field based on the indicated
+ * preference-ordered speech version list, and then conditionally deletes
+ * that speech version list if it includes only FRv1 and HRv1, as called for
+ * in 3GPP TS 24.008 section 10.5.4.5.1.
+ */
+int osmo_gsm48_bcap_apply_ms_rules(struct osmo_bcap_hl *bc)
+{
+ int s;
+ int fr_pos = -1, hr_pos = -1;
+ bool newer_codecs = false;
+
+ /* preening is needed only for speech calls */
+ if (bc->itc != GSM48_BCAP_ITCAP_SPEECH)
+ return 0;
+
+ /* find FRv1 and HRv1 in the caller-filled speech version list */
+ for (s = 0; s < bc->speech.num_vers; s++) {
+ switch (bc->speech.vers[s]) {
+ case GSM48_BCAP_SV_FR:
+ if (fr_pos >= 0) /* duplicates invalid */
+ return -EINVAL;
+ fr_pos = s;
+ break;
+ case GSM48_BCAP_SV_HR:
+ if (hr_pos >= 0) /* duplicates invalid */
+ return -EINVAL;
+ hr_pos = s;
+ break;
+ default:
+ newer_codecs = true;
+ break;
+ }
+ }
+ /* FRv1 support is mandatory */
+ if (fr_pos < 0)
+ return -EINVAL;
+
+ /* Radio channel req bits are for ancient GSM networks that predate
+ * the addition of octets 3a etc: they indicate the v1-only subset
+ * of the full speech version list. */
+ if (hr_pos < 0)
+ bc->rrq = GSM48_BCAP_RRQ_FR_ONLY;
+ else if (fr_pos < hr_pos)
+ bc->rrq = GSM48_BCAP_RRQ_DUAL_FR;
+ else
+ bc->rrq = GSM48_BCAP_RRQ_DUAL_HR;
+
+ /* TS 24.008 section 10.5.4.5.1 says that octets 3a etc "shall"
+ * be included only if the MS supports either CTM text telephony
+ * or at least one newer-than-v1 speech codec. Other GSM MS
+ * implementations with available source code don't follow this
+ * stipulation, probably on the reasoning that if the code
+ * implementation is new enough to know about octets 3a etc,
+ * then the product it goes into will support at least EFR
+ * if not AMR - but let's honor the word of the spec
+ * for brownie points. */
+ if (!newer_codecs && !bc->speech.ctm)
+ bc->speech.num_vers = 0; /* empty list => no octet 3a */
+ return 0;
+}
+
+/*! Apply rules for network->MS direction to GSM 04.08 bearer capability IE
+ * prior to encoding.
+ * \param[in/out] bc High-level decoded BC-IE to be preened.
+ * \returns 0 on success; negative on error.
+ */
+int osmo_gsm48_bcap_apply_network_rules(struct osmo_bcap_hl *bc)
+{
+ /* Table 10.5.102/3GPP TS 24.008, stanza at the very beginning
+ * of the table: in the network->MS direction for all calls,
+ * speech or data, the radio channel requirement bits
+ * get a fixed dummy fill. */
+ bc->rrq = GSM48_BCAP_RRQ_SPARE_NETWORK_TO_MS;
+
+ switch (bc->itc) {
+ case GSM48_BCAP_ITCAP_SPEECH:
+ /* TS 24.008 does not explicitly tell network side implementors
+ * to not send octets 3a etc, but sending them in this
+ * direction is clearly a bad idea:
+ *
+ * - MS are explicitly instructed to ignore these bits,
+ * with "shall" language at the end of
+ * Table 10.5.103/3GPP TS 24.008.
+ *
+ * - Attempting to communicate a speech version list in the
+ * network->MS direction is logically meaningless - see
+ * OS#6655.
+ *
+ * - Because such behavior on the part of the network was
+ * totally unexpected, FTA testsuites for GSM MS back in the
+ * day forgot to test the "shall be ignored by the MS"
+ * behavior, and many type-approved MS out in the field
+ * misbehave in this case - see OS#6656.
+ *
+ * On the basis of these considerations, let us never send
+ * a speech version list in the network->MS direction.
+ */
+ bc->speech.num_vers = 0;
+ break;
+ case GSM48_BCAP_ITCAP_UNR_DIG_INF:
+ case GSM48_BCAP_ITCAP_3k1_AUDIO:
+ case GSM48_BCAP_ITCAP_FAX_G3:
+ case GSM48_BCAP_ITCAP_OTHER:
+ /* Clear out those fields which the spec says are reserved
+ * in the network->MS direction. Why is this logic needed?
+ * There are certain scenarios where the MSC receives BC-IE
+ * from an MS and then has to echo it back, perhaps with
+ * modifications for negotiable parameters. If the original
+ * BC-IE from the MS included fields that are defined only
+ * in the MS->network direction, the response BC-IE from
+ * the MSC needs to follow network->MS format rules, i.e.,
+ * _not_ include those fields.
+ */
+ bc->data.accept_tchf144 = 0; /* octet 6e */
+ bc->data.accept_tchf96 = 0;
+ bc->data.accept_tchf48 = 0;
+ bc->data.max_tch_minus1 = 0;
+ bc->data.waiur = 0; /* octet 6f */
+ bc->data.accept_tch288 = 0; /* octet 6g */
+ bc->data.accept_tch320 = 0;
+ bc->data.accept_tch432 = 0;
+ bc->data.asymmetry = 0;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
/*! Decode TS 04.08 Call Control Capabilities IE (10.5.4.5a)
* \param[out] ccap Caller-provided memory for decoded CC capabilities
* \param[in] lv Length-Value of IE
diff --git a/src/gsm/libosmogsm.map b/src/gsm/libosmogsm.map
index 2cb768f..abb7c2d 100644
--- a/src/gsm/libosmogsm.map
+++ b/src/gsm/libosmogsm.map
@@ -436,6 +436,8 @@
gsm48_mi_to_string;
gsm48_chan_mode_to_vamos;
gsm48_chan_mode_to_non_vamos;
+osmo_gsm48_bcap_apply_ms_rules;
+osmo_gsm48_bcap_apply_network_rules;
osmo_gsm48_decode_bcap_hl;
osmo_gsm48_decode_bcap_ll;
osmo_gsm48_encode_bcap_hl;
To view, visit change 44193. To unsubscribe, or for help writing mail filters, visit settings.