pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-sgsn/+/40958?usp=email )


Change subject: sccp: Introduce helper func sgsn_sccp_user_iups_tx_data_req()
......................................................................

sccp: Introduce helper func sgsn_sccp_user_iups_tx_data_req()

This avoid code deduplication plus moving SCCP SAP logic into sccp.c.

Change-Id: Id34f86b4f5e40ddceac4066ec18ebc60529cafab
---
M include/osmocom/sgsn/gprs_ranap.h
M include/osmocom/sgsn/sccp.h
M src/sgsn/gprs_ranap.c
M src/sgsn/sccp.c
4 files changed, 34 insertions(+), 52 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/58/40958/1

diff --git a/include/osmocom/sgsn/gprs_ranap.h 
b/include/osmocom/sgsn/gprs_ranap.h
index 52a70b2..8a6c189 100644
--- a/include/osmocom/sgsn/gprs_ranap.h
+++ b/include/osmocom/sgsn/gprs_ranap.h
@@ -16,7 +16,6 @@
 int iu_rab_act_ps(uint8_t rab_id, struct sgsn_pdp_ctx *pdp);

 int ranap_iu_tx(struct msgb *msg, uint8_t sapi);
-int ranap_iu_rab_act(struct ranap_ue_conn_ctx *ue_ctx, struct msgb *msg);
 int ranap_iu_rab_deact(struct ranap_ue_conn_ctx *ue_ctx, uint8_t rab_id);
 int ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct 
osmo_auth_vector *vec,
                             int send_ck, int new_key);
diff --git a/include/osmocom/sgsn/sccp.h b/include/osmocom/sgsn/sccp.h
index a75c6aa..3dcb4f8 100644
--- a/include/osmocom/sgsn/sccp.h
+++ b/include/osmocom/sgsn/sccp.h
@@ -18,6 +18,8 @@
  */
 #pragma once

+#include <stdint.h>
+
 #include <osmocom/sigtran/sccp_sap.h>

 struct sgsn_instance;
@@ -34,6 +36,8 @@
 struct sgsn_sccp_user_iups *sgsn_scu_iups_inst_alloc(struct sgsn_instance 
*sgsn, struct osmo_sccp_instance *sccp);
 void sgsn_scu_iups_free(struct sgsn_sccp_user_iups *scu_iups);

+int sgsn_sccp_user_iups_tx_data_req(struct sgsn_sccp_user_iups *scu_iups, 
uint32_t conn_id, struct msgb *ranap_msg);
+
 int sgsn_sccp_init(struct sgsn_instance *sgsn);
 void sgsn_sccp_release(struct sgsn_instance *sgsn);

diff --git a/src/sgsn/gprs_ranap.c b/src/sgsn/gprs_ranap.c
index 8433765..008063b 100644
--- a/src/sgsn/gprs_ranap.c
+++ b/src/sgsn/gprs_ranap.c
@@ -331,23 +331,7 @@

        msg = ranap_new_msg_rab_assign_data(rab_id, ggsn_ip,
                                            pdp->lib->teid_gn, use_x213_nsap);
-       msg->l2h = msg->data;
-       return ranap_iu_rab_act(uectx, msg);
-}
-
-int ranap_iu_rab_act(struct ranap_ue_conn_ctx *ue_ctx, struct msgb *msg)
-{
-       struct osmo_scu_prim *prim;
-
-       /* wrap RANAP message in SCCP N-DATA.req */
-       prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim));
-       prim->u.data.conn_id = ue_ctx->conn_id;
-       osmo_prim_init(&prim->oph,
-                      SCCP_SAP_USER,
-                      OSMO_SCU_PRIM_N_DATA,
-                      PRIM_OP_REQUEST,
-                      msg);
-       return osmo_sccp_user_sap_down(ue_ctx->scu_iups->scu, &prim->oph);
+       return sgsn_sccp_user_iups_tx_data_req(uectx->scu_iups, uectx->conn_id, 
msg);
 }

 int ranap_iu_rab_deact(struct ranap_ue_conn_ctx *ue_ctx, uint8_t rab_id)
@@ -359,38 +343,23 @@
 int ranap_iu_tx_sec_mode_cmd(struct ranap_ue_conn_ctx *uectx, struct 
osmo_auth_vector *vec,
                             int send_ck, int new_key)
 {
-       struct osmo_scu_prim *prim;
        struct msgb *msg;

        /* create RANAP message */
        msg = ranap_new_msg_sec_mod_cmd(vec->ik, send_ck ? vec->ck : NULL,
                        new_key ? RANAP_KeyStatus_new : RANAP_KeyStatus_old);
-       msg->l2h = msg->data;
-       /* wrap RANAP message in SCCP N-DATA.req */
-       prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim));
-       prim->u.data.conn_id = uectx->conn_id;
-       osmo_prim_init(&prim->oph, SCCP_SAP_USER,
-                       OSMO_SCU_PRIM_N_DATA,
-                       PRIM_OP_REQUEST, msg);
-       return osmo_sccp_user_sap_down(uectx->scu_iups->scu, &prim->oph);
+       return sgsn_sccp_user_iups_tx_data_req(uectx->scu_iups, uectx->conn_id, 
msg);
 }

 int ranap_iu_tx_common_id(struct ranap_ue_conn_ctx *uectx, const char *imsi)
 {
        struct msgb *msg;
-       struct osmo_scu_prim *prim;

        LOGP(DRANAP, LOGL_INFO, "Transmitting RANAP CommonID (SCCP conn_id 
%u)\n",
             uectx->conn_id);

        msg = ranap_new_msg_common_id(imsi);
-       msg->l2h = msg->data;
-       prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim));
-       prim->u.data.conn_id = uectx->conn_id;
-       osmo_prim_init(&prim->oph, SCCP_SAP_USER,
-                       OSMO_SCU_PRIM_N_DATA,
-                       PRIM_OP_REQUEST, msg);
-       return osmo_sccp_user_sap_down(uectx->scu_iups->scu, &prim->oph);
+       return sgsn_sccp_user_iups_tx_data_req(uectx->scu_iups, uectx->conn_id, 
msg);
 }

 /* Send a paging command down a given SCCP User. tmsi and paging_cause are
@@ -413,7 +382,6 @@
 {
        struct ranap_ue_conn_ctx *uectx = msg_nas->dst;
        struct msgb *msg;
-       struct osmo_scu_prim *prim;

        if (!uectx) {
                LOGP(DRANAP, LOGL_ERROR,
@@ -426,22 +394,16 @@

        msg = ranap_new_msg_dt(sapi, msg_nas->data, msgb_length(msg_nas));
        msgb_free(msg_nas);
-       msg->l2h = msg->data;
-       prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim));
-       prim->u.data.conn_id = uectx->conn_id;
-       osmo_prim_init(&prim->oph, SCCP_SAP_USER,
-                       OSMO_SCU_PRIM_N_DATA,
-                       PRIM_OP_REQUEST, msg);
-       return osmo_sccp_user_sap_down(uectx->scu_iups->scu, &prim->oph);
+
+       return sgsn_sccp_user_iups_tx_data_req(uectx->scu_iups, uectx->conn_id, 
msg);
 }

 /* Send Iu Release for the given UE connection.
  * If cause is NULL, Normal Release cause is sent, otherwise
  * the provided cause. */
-int ranap_iu_tx_release(struct ranap_ue_conn_ctx *ctx, const struct 
RANAP_Cause *cause)
+int ranap_iu_tx_release(struct ranap_ue_conn_ctx *uectx, const struct 
RANAP_Cause *cause)
 {
        struct msgb *msg;
-       struct osmo_scu_prim *prim;
        static const struct RANAP_Cause default_cause = {
                .present = RANAP_Cause_PR_nAS,
                .choice.radioNetwork = RANAP_CauseNAS_normal_release,
@@ -451,13 +413,7 @@
                cause = &default_cause;

        msg = ranap_new_msg_iu_rel_cmd(cause);
-       msg->l2h = msg->data;
-       prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim));
-       prim->u.data.conn_id = ctx->conn_id;
-       osmo_prim_init(&prim->oph, SCCP_SAP_USER,
-                       OSMO_SCU_PRIM_N_DATA,
-                       PRIM_OP_REQUEST, msg);
-       return osmo_sccp_user_sap_down(ctx->scu_iups->scu, &prim->oph);
+       return sgsn_sccp_user_iups_tx_data_req(uectx->scu_iups, uectx->conn_id, 
msg);
 }

 void ranap_iu_tx_release_free(struct ranap_ue_conn_ctx *ctx,
diff --git a/src/sgsn/sccp.c b/src/sgsn/sccp.c
index 2f99f6b..4a4d6a1 100644
--- a/src/sgsn/sccp.c
+++ b/src/sgsn/sccp.c
@@ -77,6 +77,29 @@
        talloc_free(scu_iups);
 }

+/* wrap RANAP message in SCCP N-DATA.req
+ * ranap_msg becomes owned by the callee. */
+int sgsn_sccp_user_iups_tx_data_req(struct sgsn_sccp_user_iups *scu_iups, 
uint32_t conn_id, struct msgb *ranap_msg)
+{
+       struct osmo_scu_prim *prim;
+       int rc;
+
+       if (!scu_iups) {
+               LOGP(DSUA, LOGL_ERROR, "Failed to send SCCP N-DATA.req(%u): no 
SCCP User\n", conn_id);
+               return -1;
+       }
+
+       ranap_msg->l2h = ranap_msg->data;
+       prim = (struct osmo_scu_prim *)msgb_push(ranap_msg, sizeof(*prim));
+       osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_DATA, 
PRIM_OP_REQUEST, ranap_msg);
+       prim->u.data.conn_id = conn_id;
+
+       rc = osmo_sccp_user_sap_down(scu_iups->scu, &prim->oph);
+       if (rc)
+               LOGP(DSUA, LOGL_ERROR, "Failed to send SCCP N-DATA.req(%u)\n", 
conn_id);
+       return rc;
+}
+
 static struct ranap_ue_conn_ctx *ue_conn_ctx_find(struct sgsn_sccp_user_iups 
*scu_iups, uint32_t conn_id)
 {
        struct ranap_ue_conn_ctx *ctx;

--
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/40958?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: Id34f86b4f5e40ddceac4066ec18ebc60529cafab
Gerrit-Change-Number: 40958
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>

Reply via email to