Vadim Yanitskiy has uploaded this change for review. ( 
https://gerrit.osmocom.org/11069


Change subject: GSUP/SM: (WIP) introduce MO/MT FORWARD_SM messages
......................................................................

GSUP/SM: (WIP) introduce MO/MT FORWARD_SM messages

According to 3GPP TS 29.002, sections 12.2 and 12.9 the FORWARD_SM
messages (a.k.a MAP-*-FORWARD-SHORT-MESSAGE) are used to forward
MO/MT SMS messages.

Please note that only the 'must-have' fields of of both message
types are introduced by this change, in particular:

  - OSMO_GSUP_MSGT_{MO|MT}_FORWARD_SM_REQUEST (MAP Request)
    - OSMO_GSUP_SM_RP_DA_IE
    - OSMO_GSUP_SM_RP_OA_IE
    - OSMO_GSUP_SM_RP_UI_IE

  - OSMO_GSUP_MSGT_{MO|MT}_FORWARD_SM_RESULT (MAP ACK)
    - OSMO_GSUP_SM_RP_UI_IE

  - OSMO_GSUP_MSGT_{MO|MT}_FORWARD_SM_ERROR (MAP Response)
    - GSUP_CAUSE_IE (MAP User Error, see 7.6.1)

Since there is no TCAP layer in GSUP, the context is emulated
using the session management IEs (see GSUP_SESSION_*_IE).

Change-Id: Ibe325c64ae2d6c626b232533bb4cbc65fc2b5d71
---
M include/osmocom/gsm/gsup.h
M src/gsm/gsup.c
M tests/gsup/gsup_test.err
3 files changed, 96 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/69/11069/1

diff --git a/include/osmocom/gsm/gsup.h b/include/osmocom/gsm/gsup.h
index bed61ae..3f9a3f9 100644
--- a/include/osmocom/gsm/gsup.h
+++ b/include/osmocom/gsm/gsup.h
@@ -93,6 +93,9 @@
        OSMO_GSUP_SMSC_ADDR_IE                  = 0x40,
        OSMO_GSUP_NODE_ADDR_IE                  = 0x41,
        OSMO_GSUP_SM_RP_RPI_IE                  = 0x42,
+       OSMO_GSUP_SM_RP_DA_IE                   = 0x43,
+       OSMO_GSUP_SM_RP_OA_IE                   = 0x44,
+       OSMO_GSUP_SM_RP_UI_IE                   = 0x45,
 };

 /*! GSUP message type */
@@ -131,6 +134,14 @@
        OSMO_GSUP_MSGT_SRI_FOR_SM_REQUEST       = 0b00100100,
        OSMO_GSUP_MSGT_SRI_FOR_SM_ERROR         = 0b00100101,
        OSMO_GSUP_MSGT_SRI_FOR_SM_RESULT        = 0b00100110,
+
+       OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST    = 0b00101000,
+       OSMO_GSUP_MSGT_MO_FORWARD_SM_ERROR      = 0b00101001,
+       OSMO_GSUP_MSGT_MO_FORWARD_SM_RESULT     = 0b00101010,
+
+       OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST    = 0b00110000,
+       OSMO_GSUP_MSGT_MT_FORWARD_SM_ERROR      = 0b00110001,
+       OSMO_GSUP_MSGT_MT_FORWARD_SM_RESULT     = 0b00110010,
 };

 #define OSMO_GSUP_IS_MSGT_REQUEST(msgt) (((msgt) & 0b00000011) == 0b00)
@@ -231,6 +242,25 @@
        size_t                          node_addr_len;
        /*! HACK: SM-RP-RPI is (<0 / 0 / >0) => (false / omited / true) */
        int                             sm_rp_rpi;
+
+       /*! SM Destination Address, see 7.6.8.1. It can be of the following:
+        ** IMSI, LMSI, MSISDN, roaming number, or service centre address.
+        ** The values from 'osmo_gsup_iei' enum are used for 'sm_rp_da_type'.
+        ** NOTE: LMSI, roaming number are not implemented */
+       const uint8_t                   *sm_rp_da;
+       uint8_t                         sm_rp_da_type;
+       size_t                          sm_rp_da_len;
+
+       /*! SM Originating Address, see 7.6.8.2. It can be of the following:
+        ** MSISDN or service centre address. ** The values from 'osmo_gsup_iei'
+        ** enum are used for 'sm_rp_da_type'. */
+       const uint8_t                   *sm_rp_oa;
+       uint8_t                         sm_rp_oa_type;
+       size_t                          sm_rp_oa_len;
+
+       /*! SM TPDU (Transport Protocol Data Unit), see 7.6.8.4 */
+       const uint8_t                   *sm_rp_ui;
+       size_t                          sm_rp_ui_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 22e26f1..752cfca 100644
--- a/src/gsm/gsup.c
+++ b/src/gsm/gsup.c
@@ -71,6 +71,14 @@
        OSMO_VALUE_STRING(OSMO_GSUP_MSGT_SRI_FOR_SM_ERROR),
        OSMO_VALUE_STRING(OSMO_GSUP_MSGT_SRI_FOR_SM_RESULT),

+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MO_FORWARD_SM_REQUEST),
+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MO_FORWARD_SM_ERROR),
+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MO_FORWARD_SM_RESULT),
+
+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MT_FORWARD_SM_REQUEST),
+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MT_FORWARD_SM_ERROR),
+       OSMO_VALUE_STRING(OSMO_GSUP_MSGT_MT_FORWARD_SM_RESULT),
+
        { 0, NULL }
 };

@@ -452,6 +460,37 @@
                        gsup_msg->sm_rp_rpi = (*value) ? 1 : -1;
                        break;

+               case OSMO_GSUP_SM_RP_DA_IE:
+                       /* First octet contains type of address */
+                       if (value_len < 1) {
+                               LOGP(DLGSUP, LOGL_ERROR, "Short read of "
+                                       "SM_RP_DA_IE (missing address type)\n");
+                               return -GMM_CAUSE_COND_IE_ERR;
+                       }
+
+                       gsup_msg->sm_rp_da = value + 1; /* Skip address type */
+                       gsup_msg->sm_rp_da_len = value_len - 1;
+                       gsup_msg->sm_rp_da_type = value[0];
+                       break;
+
+               case OSMO_GSUP_SM_RP_OA_IE:
+                       /* First octet contains type of address */
+                       if (value_len < 1) {
+                               LOGP(DLGSUP, LOGL_ERROR, "Short read of "
+                                       "SM_RP_OA_IE (missing address type)\n");
+                               return -GMM_CAUSE_COND_IE_ERR;
+                       }
+
+                       gsup_msg->sm_rp_oa = value + 1; /* Skip address type */
+                       gsup_msg->sm_rp_oa_len = value_len - 1;
+                       gsup_msg->sm_rp_oa_type = value[0];
+                       break;
+
+               case OSMO_GSUP_SM_RP_UI_IE:
+                       gsup_msg->sm_rp_ui = value;
+                       gsup_msg->sm_rp_ui_len = value_len;
+                       break;
+
                default:
                        LOGP(DLGSUP, LOGL_NOTICE,
                             "GSUP IE type %d unknown\n", iei);
@@ -659,6 +698,31 @@
                msgb_tlv_put(msg, OSMO_GSUP_SM_RP_RPI_IE, sizeof(u8), &u8);
        }

+       if (gsup_msg->sm_rp_da) {
+               /* Compose TLTV manually */
+               uint8_t *buf = msgb_put(msg, 
TLV_GROSS_LEN(gsup_msg->sm_rp_da_len + 1));
+               *buf++ = OSMO_GSUP_SM_RP_DA_IE;
+               *buf++ = gsup_msg->sm_rp_da_len + 1;
+               *buf++ = gsup_msg->sm_rp_da_type;
+               if (gsup_msg->sm_rp_da_len)
+                       memcpy(buf, gsup_msg->sm_rp_da, gsup_msg->sm_rp_da_len);
+       }
+
+       if (gsup_msg->sm_rp_oa) {
+               /* Compose TLTV manually */
+               uint8_t *buf = msgb_put(msg, 
TLV_GROSS_LEN(gsup_msg->sm_rp_oa_len + 1));
+               *buf++ = OSMO_GSUP_SM_RP_OA_IE;
+               *buf++ = gsup_msg->sm_rp_oa_len + 1;
+               *buf++ = gsup_msg->sm_rp_oa_type;
+               if (gsup_msg->sm_rp_oa_len)
+                       memcpy(buf, gsup_msg->sm_rp_oa, gsup_msg->sm_rp_oa_len);
+       }
+
+       if (gsup_msg->sm_rp_ui) {
+               msgb_tlv_put(msg, OSMO_GSUP_SM_RP_UI_IE,
+                               gsup_msg->sm_rp_ui_len, gsup_msg->sm_rp_ui);
+       }
+
        return 0;
 }

diff --git a/tests/gsup/gsup_test.err b/tests/gsup/gsup_test.err
index ac71ac2..389a721 100644
--- a/tests/gsup/gsup_test.err
+++ b/tests/gsup/gsup_test.err
@@ -72,13 +72,13 @@
   message 2: tested 21248 modifications, 2571 parse failures
   message 3: tested 2816 modifications, 510 parse failures
   message 4: tested 3584 modifications, 768 parse failures
-  message 5: tested 20736 modifications, 4010 parse failures
+  message 5: tested 20736 modifications, 4012 parse failures
   message 6: tested 3584 modifications, 769 parse failures
   message 7: tested 3584 modifications, 768 parse failures
   message 8: tested 2816 modifications, 510 parse failures
   message 9: tested 2816 modifications, 510 parse failures
   message 10: tested 3584 modifications, 768 parse failures
-  message 11: tested 3328 modifications, 767 parse failures
+  message 11: tested 3328 modifications, 769 parse failures
   message 12: tested 54016 modifications, 4622 parse failures
   message 13: tested 11520 modifications, 1026 parse failures
   message 14: tested 5120 modifications, 1026 parse failures

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe325c64ae2d6c626b232533bb4cbc65fc2b5d71
Gerrit-Change-Number: 11069
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <[email protected]>

Reply via email to