<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/9523">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">libmsc/ussd.c: FIX: properly indicate errors<br><br>There are error and problem codes defined by GSM TS 04.80:<br><br>  - Error codes are used when a message is structured correctly,<br>    but something is wrong in context of the current operation.<br>    Usually they are carried by 'Return Error' component.<br><br>  - Problem codes are used when something is wrong with the<br>    message structure, or with carried values. They are<br>    carried by 'Reject' component.<br><br>    There are three groups of them (see table 3.13):<br><br>      - General Problem Codes (table 3.14),<br>      - Invoke Problem Codes (table 3.15),<br>      - Return Result Problem Codes (table 3.16),<br>      - Return Error Problem Codes (table 3.17).<br><br>    The first group is general purpose, and can be sent in<br>    response to any kind of message, excluding 'Reject' itself.<br>    Other ones are bound to specific component types, such as<br>    'Invoke', 'Return Result' and 'Return Error'.<br><br>For some reason, a 'Reject' component with the general problem<br>code 'GSM_0480_GEN_PROB_CODE_UNRECOGNISED' was always used in<br>OsmoMSC. Even when the message structure is correct.<br><br>Let's properly indicate errors in the following way:<br><br>  - 'Reject' with GSM_0480_GEN_PROB_CODE_UNRECOGNISED<br>    when the gsm0480_decode_ss_request() fails to decode<br>    a message. It can only return 0 or 1, so it's hard to<br>    guess which exact part of message caused the error.<br><br>  - 'Return Error' with GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION<br>    when the operation code is not related to USSD.<br><br>  - 'Return Error' with GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE<br>    when the requested USSD code is unhandled (not supported).<br><br>There is a TTCN-3 testcase for this:<br><br>https://gerrit.osmocom.org/9470/<br><br>Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14<br>---<br>M include/osmocom/msc/gsm_04_80.h<br>M src/libmsc/gsm_04_80.c<br>M src/libmsc/ussd.c<br>3 files changed, 41 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/msc/gsm_04_80.h b/include/osmocom/msc/gsm_04_80.h</span><br><span>index dedf243..fb057c8 100644</span><br><span>--- a/include/osmocom/msc/gsm_04_80.h</span><br><span>+++ b/include/osmocom/msc/gsm_04_80.h</span><br><span>@@ -9,8 +9,12 @@</span><br><span> int gsm0480_send_ussd_response(struct gsm_subscriber_connection *conn,</span><br><span>                          const char* response_text,</span><br><span>                           const struct ss_request *req);</span><br><span style="color: hsl(120, 100%, 40%);">+int gsm0480_send_ussd_return_error(struct gsm_subscriber_connection *conn,</span><br><span style="color: hsl(120, 100%, 40%);">+                                const struct ss_request *req,</span><br><span style="color: hsl(120, 100%, 40%);">+                                 uint8_t error_code);</span><br><span> int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn,</span><br><span style="color: hsl(0, 100%, 40%);">-                      const struct ss_request *request);</span><br><span style="color: hsl(120, 100%, 40%);">+                            const struct ss_request *req,</span><br><span style="color: hsl(120, 100%, 40%);">+                         uint8_t error_tag, uint8_t error_code);</span><br><span> </span><br><span> int msc_send_ussd_notify(struct gsm_subscriber_connection *conn, int level,</span><br><span>                       const char *text);</span><br><span>diff --git a/src/libmsc/gsm_04_80.c b/src/libmsc/gsm_04_80.c</span><br><span>index 12b41a1..8799fcb 100644</span><br><span>--- a/src/libmsc/gsm_04_80.c</span><br><span>+++ b/src/libmsc/gsm_04_80.c</span><br><span>@@ -108,15 +108,42 @@</span><br><span>     return msc_tx_dtap(conn, msg);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int gsm0480_send_ussd_return_error(struct gsm_subscriber_connection *conn,</span><br><span style="color: hsl(120, 100%, 40%);">+   const struct ss_request *req, uint8_t error_code)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USSD ERR");</span><br><span style="color: hsl(120, 100%, 40%);">+     struct gsm48_hdr *gh;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       /* First insert the problem code */</span><br><span style="color: hsl(120, 100%, 40%);">+   msgb_push_TLV1(msg, GSM_0480_ERROR_CODE_TAG, error_code);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* Before it insert the invoke ID */</span><br><span style="color: hsl(120, 100%, 40%);">+  msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* Wrap this up as a Reject component */</span><br><span style="color: hsl(120, 100%, 40%);">+      msgb_wrap_with_TL(msg, GSM0480_CTYPE_RETURN_ERROR);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Wrap the component in a Facility message */</span><br><span style="color: hsl(120, 100%, 40%);">+        msgb_wrap_with_TL(msg, GSM0480_IE_FACILITY);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        /* And finally pre-pend the L3 header */</span><br><span style="color: hsl(120, 100%, 40%);">+      gh = (struct gsm48_hdr *) msgb_push(msg, sizeof(*gh));</span><br><span style="color: hsl(120, 100%, 40%);">+        gh->proto_discr = GSM48_PDISC_NC_SS;</span><br><span style="color: hsl(120, 100%, 40%);">+       gh->proto_discr |= req->transaction_id | (1<<7);  /* TI direction = 1 */</span><br><span style="color: hsl(120, 100%, 40%);">+  gh->msg_type = GSM0480_MTYPE_RELEASE_COMPLETE;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return msc_tx_dtap(conn, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int gsm0480_send_ussd_reject(struct gsm_subscriber_connection *conn,</span><br><span style="color: hsl(0, 100%, 40%);">-                          const struct ss_request *req)</span><br><span style="color: hsl(120, 100%, 40%);">+                         const struct ss_request *req,</span><br><span style="color: hsl(120, 100%, 40%);">+                         uint8_t error_tag, uint8_t error_code)</span><br><span> {</span><br><span>     struct msgb *msg = gsm48_msgb_alloc_name("GSM 04.08 USSD REJ");</span><br><span>    struct gsm48_hdr *gh;</span><br><span> </span><br><span>    /* First insert the problem code */</span><br><span style="color: hsl(0, 100%, 40%);">-     msgb_push_TLV1(msg, GSM_0480_PROBLEM_CODE_TAG_GENERAL,</span><br><span style="color: hsl(0, 100%, 40%);">-                  GSM_0480_GEN_PROB_CODE_UNRECOGNISED);</span><br><span style="color: hsl(120, 100%, 40%);">+ msgb_push_TLV1(msg, error_tag, error_code);</span><br><span> </span><br><span>      /* Before it insert the invoke ID */</span><br><span>         msgb_push_TLV1(msg, GSM0480_COMPIDTAG_INVOKE_ID, req->invoke_id);</span><br><span>diff --git a/src/libmsc/ussd.c b/src/libmsc/ussd.c</span><br><span>index fe1610f..f285fcf 100644</span><br><span>--- a/src/libmsc/ussd.c</span><br><span>+++ b/src/libmsc/ussd.c</span><br><span>@@ -74,7 +74,8 @@</span><br><span>    if (!rc) {</span><br><span>           LOGP(DMM, LOGL_ERROR, "SS/USSD message parsing error, "</span><br><span>                    "rejecting request...\n");</span><br><span style="color: hsl(0, 100%, 40%);">-            gsm0480_send_ussd_reject(conn, &req);</span><br><span style="color: hsl(120, 100%, 40%);">+             gsm0480_send_ussd_reject(conn, &req, GSM_0480_PROBLEM_CODE_TAG_GENERAL,</span><br><span style="color: hsl(120, 100%, 40%);">+                   GSM_0480_GEN_PROB_CODE_UNRECOGNISED);</span><br><span>                /* The GSM 04.80 API uses inverted codes (0 means error) */</span><br><span>          return -EPROTO;</span><br><span>      }</span><br><span>@@ -83,8 +84,8 @@</span><br><span>        if (req.ussd_text[0] == '\0' || req.ussd_text[0] == 0xFF) {</span><br><span>          if (req.ss_code > 0) {</span><br><span>                    /* Assume interrogateSS or modification of it and reject */</span><br><span style="color: hsl(0, 100%, 40%);">-                     rc = gsm0480_send_ussd_reject(conn, &req);</span><br><span style="color: hsl(0, 100%, 40%);">-                  return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+                    return gsm0480_send_ussd_return_error(conn, &req,</span><br><span style="color: hsl(120, 100%, 40%);">+                         GSM0480_ERR_CODE_ILLEGAL_SS_OPERATION);</span><br><span>              }</span><br><span>            /* Still assuming a Release-Complete and returning */</span><br><span>                return 0;</span><br><span>@@ -96,7 +97,8 @@</span><br><span>                rc = send_own_number(conn, &req);</span><br><span>        } else {</span><br><span>             DEBUGP(DMM, "Unhandled USSD %s\n", req.ussd_text);</span><br><span style="color: hsl(0, 100%, 40%);">-            rc = gsm0480_send_ussd_reject(conn, &req);</span><br><span style="color: hsl(120, 100%, 40%);">+                rc = gsm0480_send_ussd_return_error(conn, &req,</span><br><span style="color: hsl(120, 100%, 40%);">+                   GSM0480_ERR_CODE_UNEXPECTED_DATA_VALUE);</span><br><span>     }</span><br><span> </span><br><span>        return rc;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/9523">change 9523</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/9523"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-msc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I800e7ec98dc9d0bca2d45a8b8255d60253d63e14 </div>
<div style="display:none"> Gerrit-Change-Number: 9523 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>