[PATCH] libosmocore[master]: GSUP: add USSD encoding / decoding support

2018-04-01 Thread Vadim Yanitskiy
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/7600

to look at the new patch set (#2).

GSUP: add USSD encoding / decoding support

In order to be able to transfer USSD messages via GSUP, this
change introduces the new message types OSMO_GSUP_MSGT_USSD_*,
and a few new information elements:

  - OSMO_GSUP_USSD_SID_IE,
  - OSMO_GSUP_USSD_PAYLOAD_IE.

The 'osmo_gsup_message' structure was extended with a few new
fields, which carry the L3 bytes of USSD payload, its length,
and unique USSD session ID.

Change-Id: Ie17a78043a35fffbdd59e80fd2b2da39cce5e532
Related: OS#1597
---
M include/osmocom/gsm/gsup.h
M src/gsm/gsup.c
M tests/gsup/gsup_test.c
M tests/gsup/gsup_test.err
M tests/gsup/gsup_test.ok
5 files changed, 105 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/00/7600/2

diff --git a/include/osmocom/gsm/gsup.h b/include/osmocom/gsm/gsup.h
index 1a8a3b2..7b7e0ef 100644
--- a/include/osmocom/gsm/gsup.h
+++ b/include/osmocom/gsm/gsup.h
@@ -81,6 +81,9 @@
OSMO_GSUP_AUTS_IE   = 0x26,
OSMO_GSUP_RES_IE= 0x27,
OSMO_GSUP_CN_DOMAIN_IE  = 0x28,
+   /* USSD support */
+   OSMO_GSUP_USSD_SID_IE   = 0x29,
+   OSMO_GSUP_USSD_PAYLOAD_IE   = 0x30,
 };
 
 /*! GSUP message type */
@@ -110,6 +113,10 @@
OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST  = 0b00011100,
OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR= 0b00011101,
OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT   = 0b0000,
+
+   OSMO_GSUP_MSGT_USSD_REQUEST = 0b0010,
+   OSMO_GSUP_MSGT_USSD_ERROR   = 0b0011,
+   OSMO_GSUP_MSGT_USSD_RESULT  = 0b00100010,
 };
 
 #define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b0011) == 0b00)
@@ -175,6 +182,9 @@
enum osmo_gsup_cn_domaincn_domain;
const uint8_t   *pdp_charg_enc;
size_t  pdp_charg_enc_len;
+   const uint8_t   *ussd_payload;
+   size_t  ussd_payload_len;
+   uint32_tussd_sid;
 };
 
 int osmo_gsup_decode(const uint8_t *data, size_t data_len,
diff --git a/src/gsm/gsup.c b/src/gsm/gsup.c
index b6ac56d..d43af9b 100644
--- a/src/gsm/gsup.c
+++ b/src/gsm/gsup.c
@@ -29,6 +29,7 @@
 #include 
 
 #include 
+#include 
 
 /*! \addtogroup gsup
  *  @{
@@ -62,6 +63,10 @@
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST),
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR),
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT),
+
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_REQUEST),
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_ERROR),
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_RESULT),
{ 0, NULL }
 };
 
@@ -261,6 +266,7 @@
 
/* specific parts */
while (data_len > 0) {
+   uint32_t *ussd_sid;
enum osmo_gsup_iei iei;
struct osmo_gsup_pdp_info pdp_info;
struct osmo_auth_vector auth_info;
@@ -385,6 +391,16 @@
gsup_msg->pdp_charg_enc_len = value_len;
break;
 
+   case OSMO_GSUP_USSD_SID_IE:
+   ussd_sid = (uint32_t *) value;
+   gsup_msg->ussd_sid = ntohl(*ussd_sid);
+   break;
+
+   case OSMO_GSUP_USSD_PAYLOAD_IE:
+   gsup_msg->ussd_payload = value;
+   gsup_msg->ussd_payload_len = value_len;
+   break;
+
default:
LOGP(DLGSUP, LOGL_NOTICE,
 "GSUP IE type %d unknown\n", iei);
@@ -483,6 +499,7 @@
int idx;
uint8_t bcd_buf[GSM48_MI_SIZE] = {0};
size_t bcd_len;
+   uint32_t ussd_sid;
 
/* generic part */
if(!gsup_msg->message_type)
@@ -564,6 +581,17 @@
gsup_msg->pdp_charg_enc_len, 
gsup_msg->pdp_charg_enc);
}
 
+   if (gsup_msg->ussd_sid) {
+   ussd_sid = htonl(gsup_msg->ussd_sid);
+   msgb_tlv_put(msg, OSMO_GSUP_USSD_SID_IE,
+   sizeof(gsup_msg->ussd_sid), (uint8_t *) _sid);
+   }
+
+   if (gsup_msg->ussd_payload) {
+   msgb_tlv_put(msg, OSMO_GSUP_USSD_PAYLOAD_IE,
+   gsup_msg->ussd_payload_len, gsup_msg->ussd_payload);
+   }
+
return 0;
 }
 
diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c
index b55f1d9..437b07f 100644
--- a/tests/gsup/gsup_test.c
+++ b/tests/gsup/gsup_test.c
@@ -171,6 +171,56 @@
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
};
 
+   static const uint8_t send_ussd_req[] = {
+   0x20,
+   TEST_IMSI_IE,
+   /* USSD_SID_IE */
+   

[PATCH] libosmocore[master]: GSUP: add USSD encoding / decoding support

2018-03-30 Thread Vadim Yanitskiy

Review at  https://gerrit.osmocom.org/7600

GSUP: add USSD encoding / decoding support

In order to be able to transfer USSD messages via GSUP, this
change introduces the new message types OSMO_GSUP_MSGT_USSD_*,
and a new information element OSMO_GSUP_USSD_IE.

The 'osmo_gsup_message' structure was extended with two new
fields, which carry the L3 bytes of USSD payload and its length.

Change-Id: Ie17a78043a35fffbdd59e80fd2b2da39cce5e532
Related: OS#1597
---
M include/osmocom/gsm/gsup.h
M src/gsm/gsup.c
M tests/gsup/gsup_test.c
M tests/gsup/gsup_test.err
M tests/gsup/gsup_test.ok
5 files changed, 83 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/00/7600/1

diff --git a/include/osmocom/gsm/gsup.h b/include/osmocom/gsm/gsup.h
index 1a8a3b2..0ba3272 100644
--- a/include/osmocom/gsm/gsup.h
+++ b/include/osmocom/gsm/gsup.h
@@ -81,6 +81,8 @@
OSMO_GSUP_AUTS_IE   = 0x26,
OSMO_GSUP_RES_IE= 0x27,
OSMO_GSUP_CN_DOMAIN_IE  = 0x28,
+   /* USSD support */
+   OSMO_GSUP_USSD_IE   = 0x29,
 };
 
 /*! GSUP message type */
@@ -110,6 +112,10 @@
OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST  = 0b00011100,
OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR= 0b00011101,
OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT   = 0b0000,
+
+   OSMO_GSUP_MSGT_USSD_REQUEST = 0b0010,
+   OSMO_GSUP_MSGT_USSD_ERROR   = 0b0011,
+   OSMO_GSUP_MSGT_USSD_RESULT  = 0b00100010,
 };
 
 #define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b0011) == 0b00)
@@ -175,6 +181,8 @@
enum osmo_gsup_cn_domaincn_domain;
const uint8_t   *pdp_charg_enc;
size_t  pdp_charg_enc_len;
+   const uint8_t   *ussd_payload;
+   size_t  ussd_payload_len;
 };
 
 int osmo_gsup_decode(const uint8_t *data, size_t data_len,
diff --git a/src/gsm/gsup.c b/src/gsm/gsup.c
index b6ac56d..4bf3964 100644
--- a/src/gsm/gsup.c
+++ b/src/gsm/gsup.c
@@ -62,6 +62,10 @@
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST),
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR),
OSMO_VALUE_STRING(OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT),
+
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_REQUEST),
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_ERROR),
+   OSMO_VALUE_STRING(OSMO_GSUP_MSGT_USSD_RESULT),
{ 0, NULL }
 };
 
@@ -385,6 +389,11 @@
gsup_msg->pdp_charg_enc_len = value_len;
break;
 
+   case OSMO_GSUP_USSD_IE:
+   gsup_msg->ussd_payload = value;
+   gsup_msg->ussd_payload_len = value_len;
+   break;
+
default:
LOGP(DLGSUP, LOGL_NOTICE,
 "GSUP IE type %d unknown\n", iei);
@@ -564,6 +573,11 @@
gsup_msg->pdp_charg_enc_len, 
gsup_msg->pdp_charg_enc);
}
 
+   if (gsup_msg->ussd_payload) {
+   msgb_tlv_put(msg, OSMO_GSUP_USSD_IE,
+   gsup_msg->ussd_payload_len, 
gsup_msg->ussd_payload);
+   }
+
return 0;
 }
 
diff --git a/tests/gsup/gsup_test.c b/tests/gsup/gsup_test.c
index b55f1d9..accc5e8 100644
--- a/tests/gsup/gsup_test.c
+++ b/tests/gsup/gsup_test.c
@@ -171,6 +171,50 @@
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
};
 
+   static const uint8_t send_ussd_req[] = {
+   0x20,
+   TEST_IMSI_IE,
+   0x29, 0x19, /* USSD */
+   /**
+* Protocol Discriminator: Non call related SS messages
+* Message Type: Register (0x3b), SQN: 1
+*/
+   0x0b, 0x7b, 0x1c, 0x15, 0xa1, 0x13, 0x02, 0x01,
+   0x05, 0x02, 0x01, 0x3b,
+   /**
+* Coding: GSM 7 bit default alphabet
+* Language: Language unspecified (15)
+*/
+   0x30, 0x0b, 0x04, 0x01, 0x0f,
+   /**
+* USSD String: *#100#
+*/
+   0x04, 0x06, 0xaa, 0x51, 0x0c, 0x06, 0x1b, 0x01,
+   };
+
+   static const uint8_t send_ussd_res[] = {
+   0x22,
+   TEST_IMSI_IE,
+   0x29, 0x2b, /* USSD */
+   /**
+* Protocol Discriminator: Non call related SS messages
+* Message Type: Release Complete (0x2a), SQN: 0
+*/
+   0x8b, 0x2a, 0x1c, 0x27, 0xa2, 0x25, 0x02, 0x01,
+   0x05, 0x30, 0x20, 0x02, 0x01, 0x3b,
+   /**
+* Coding: GSM 7 bit default alphabet
+* Language: Language unspecified (15)
+*/
+   0x30, 0x1b, 0x04, 0x01, 0x0f,
+   /**