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


Change subject: sccp: Unify path submitting N-*.req
......................................................................

sccp: Unify path submitting N-*.req

This allows having clearer code paths and adding rate counters.

Change-Id: I37b414cf769a16b7c7f596df3bb91a6a91a06298
---
M include/osmocom/hnbgw/hnbgw_sccp.h
M src/osmo-hnbgw/cnlink.c
M src/osmo-hnbgw/context_map_sccp.c
M src/osmo-hnbgw/hnbgw_sccp.c
4 files changed, 113 insertions(+), 35 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/51/40251/1

diff --git a/include/osmocom/hnbgw/hnbgw_sccp.h 
b/include/osmocom/hnbgw/hnbgw_sccp.h
index fbb84f4..d207348 100644
--- a/include/osmocom/hnbgw/hnbgw_sccp.h
+++ b/include/osmocom/hnbgw/hnbgw_sccp.h
@@ -1,9 +1,12 @@
 /* SCCP, ITU Q.711 - Q.714 */
 #pragma once

+#include <stdint.h>
+
 #include <osmocom/core/hashtable.h>
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/prim.h>
+#include <osmocom/core/msgb.h>
 #include <osmocom/core/use_count.h>

 #include <osmocom/sigtran/sccp_sap.h>
@@ -46,3 +49,11 @@
        OSMO_ASSERT(osmo_use_count_get_put(&(hsu)->use_count, use, -1) == 0)

 struct hnbgw_sccp_user *hnbgw_sccp_user_alloc(int ss7_inst_id);
+
+int hnbgw_sccp_user_tx_unitdata_req(struct hnbgw_sccp_user *hsu, const struct 
osmo_sccp_addr *called_addr,
+                                   struct msgb *ranap_msg);
+int hnbgw_sccp_user_tx_connect_req(struct hnbgw_sccp_user *hsu, const struct 
osmo_sccp_addr *called_addr,
+                                  uint32_t scu_conn_id, struct msgb 
*ranap_msg);
+int hnbgw_sccp_user_tx_data_req(struct hnbgw_sccp_user *hsu, uint32_t 
scu_conn_id,
+                               struct msgb *ranap_msg);
+int hnbgw_sccp_user_tx_disconnect_req(struct hnbgw_sccp_user *hsu, uint32_t 
scu_conn_id);
diff --git a/src/osmo-hnbgw/cnlink.c b/src/osmo-hnbgw/cnlink.c
index 137012a..477bd68 100644
--- a/src/osmo-hnbgw/cnlink.c
+++ b/src/osmo-hnbgw/cnlink.c
@@ -138,6 +138,13 @@
                context_map_cnlink_lost(map);
 }

+static int hnbgw_cnlink_tx_sccp_unitdata_req(struct hnbgw_cnlink *cnlink, 
struct msgb *msg)
+{
+       return hnbgw_sccp_user_tx_unitdata_req(cnlink->hnbgw_sccp_user,
+                                              &cnlink->remote_addr,
+                                              msg);
+}
+
 static void tx_reset(struct hnbgw_cnlink *cnlink)
 {
        struct msgb *msg;
@@ -192,10 +199,7 @@

        msg = ranap_new_msg_reset2(cnlink->pool->domain, &cause, use_grnc_id);
        CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_TX_UDT_RESET);
-       osmo_sccp_tx_unitdata_msg(cnlink->hnbgw_sccp_user->sccp_user,
-                                 &cnlink->hnbgw_sccp_user->local_addr,
-                                 &cnlink->remote_addr,
-                                 msg);
+       hnbgw_cnlink_tx_sccp_unitdata_req(cnlink, msg);
 }

 static void tx_reset_ack(struct hnbgw_cnlink *cnlink)
@@ -243,10 +247,7 @@

        msg = ranap_new_msg_reset_ack(cnlink->pool->domain, use_grnc_id);
        CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_TX_UDT_RESET_ACK);
-       osmo_sccp_tx_unitdata_msg(cnlink->hnbgw_sccp_user->sccp_user,
-                                 &cnlink->hnbgw_sccp_user->local_addr,
-                                 &cnlink->remote_addr,
-                                 msg);
+       hnbgw_cnlink_tx_sccp_unitdata_req(cnlink, msg);
 }

 static void cnlink_disc_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
diff --git a/src/osmo-hnbgw/context_map_sccp.c 
b/src/osmo-hnbgw/context_map_sccp.c
index f0bbe1b..3c97789 100644
--- a/src/osmo-hnbgw/context_map_sccp.c
+++ b/src/osmo-hnbgw/context_map_sccp.c
@@ -117,10 +117,8 @@
 static int tx_sccp_cr(struct osmo_fsm_inst *fi, struct msgb *ranap_msg)
 {
        struct hnbgw_context_map *map = fi->priv;
-       struct osmo_scu_prim *prim;
-       int rc;

-       if (!map->cnlink || !map->cnlink->hnbgw_sccp_user) {
+       if (!map->cnlink) {
                LOGPFSML(fi, LOGL_ERROR, "Failed to send SCCP Connection 
Request: no CN link\n");
                return -1;
        }
@@ -130,53 +128,40 @@
                ranap_msg = hnbgw_ranap_msg_alloc("SCCP-CR-empty");
        }

-       prim = (struct osmo_scu_prim *)msgb_push(ranap_msg, sizeof(*prim));
-       osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_CONNECT, 
PRIM_OP_REQUEST, ranap_msg);
-       prim->u.connect.called_addr = map->cnlink->remote_addr;
-       prim->u.connect.calling_addr = map->cnlink->hnbgw_sccp_user->local_addr;
-       prim->u.connect.sccp_class = 2;
-       prim->u.connect.conn_id = map->scu_conn_id;
-
-       rc = 
osmo_sccp_user_sap_down_nofree(map->cnlink->hnbgw_sccp_user->sccp_user, 
&prim->oph);
-       if (rc)
-               LOGPFSML(fi, LOGL_ERROR, "Failed to send SCCP Connection 
Request to CN\n");
-       return rc;
+       return hnbgw_sccp_user_tx_connect_req(map->cnlink->hnbgw_sccp_user,
+                                             &map->cnlink->remote_addr,
+                                             map->scu_conn_id,
+                                             ranap_msg);
 }

 static int tx_sccp_df1(struct osmo_fsm_inst *fi, struct msgb *ranap_msg)
 {
        struct hnbgw_context_map *map = fi->priv;
-       struct osmo_scu_prim *prim;
-       int rc;

        if (!msg_has_l2_data(ranap_msg))
                return 0;

-       if (!map->cnlink || !map->cnlink->hnbgw_sccp_user) {
+       if (!map->cnlink) {
                LOGPFSML(fi, LOGL_ERROR, "Failed to send SCCP Data Form 1: no 
CN link\n");
                return -1;
        }

-       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 = map->scu_conn_id;
-
-       rc = 
osmo_sccp_user_sap_down_nofree(map->cnlink->hnbgw_sccp_user->sccp_user, 
&prim->oph);
-       if (rc)
-               LOGPFSML(fi, LOGL_ERROR, "Failed to send SCCP Data Form 1 to 
CN\n");
-       return rc;
+       return hnbgw_sccp_user_tx_data_req(map->cnlink->hnbgw_sccp_user,
+                                          map->scu_conn_id,
+                                          ranap_msg);
 }

 static int tx_sccp_rlsd(struct osmo_fsm_inst *fi)
 {
        struct hnbgw_context_map *map = fi->priv;

-       if (!map->cnlink || !map->cnlink->hnbgw_sccp_user) {
+       if (!map->cnlink) {
                LOGPFSML(fi, LOGL_ERROR, "Failed to send SCCP RLSD: no CN 
link\n");
                return -1;
        }

-       return osmo_sccp_tx_disconn(map->cnlink->hnbgw_sccp_user->sccp_user, 
map->scu_conn_id, NULL, 0);
+       return hnbgw_sccp_user_tx_disconnect_req(map->cnlink->hnbgw_sccp_user,
+                                                map->scu_conn_id);
 }

 static int handle_rx_sccp(struct osmo_fsm_inst *fi, struct msgb *ranap_msg)
diff --git a/src/osmo-hnbgw/hnbgw_sccp.c b/src/osmo-hnbgw/hnbgw_sccp.c
index 999ebde..4699b2f 100644
--- a/src/osmo-hnbgw/hnbgw_sccp.c
+++ b/src/osmo-hnbgw/hnbgw_sccp.c
@@ -340,6 +340,87 @@
        return rc;
 }

+/***********************************************************************
+ * Submit primitives to SCCP User SAP
+ ***********************************************************************/
+
+int hnbgw_sccp_user_tx_unitdata_req(struct hnbgw_sccp_user *hsu, const struct 
osmo_sccp_addr *called_addr, struct msgb *ranap_msg)
+{
+       if (!hsu) {
+               LOGP(DCN, LOGL_ERROR, "Failed to send SCCP N-UNITDATA.req: no 
SCCP User\n");
+               return -1;
+       }
+       OSMO_ASSERT(called_addr);
+       return osmo_sccp_tx_unitdata_msg(hsu->sccp_user,
+                                        &hsu->local_addr,
+                                        called_addr,
+                                        ranap_msg);
+}
+
+int hnbgw_sccp_user_tx_connect_req(struct hnbgw_sccp_user *hsu, const struct 
osmo_sccp_addr *called_addr, uint32_t scu_conn_id, struct msgb *ranap_msg)
+{
+       struct osmo_scu_prim *prim;
+       int rc;
+
+       if (!hsu) {
+               LOGP(DCN, LOGL_ERROR, "Failed to send SCCP N-CONNECT.req(%u): 
no SCCP User\n", scu_conn_id);
+               return -1;
+       }
+
+       OSMO_ASSERT(called_addr);
+
+       prim = (struct osmo_scu_prim *)msgb_push(ranap_msg, sizeof(*prim));
+       osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_CONNECT, 
PRIM_OP_REQUEST, ranap_msg);
+       prim->u.connect.called_addr = *called_addr;
+       prim->u.connect.calling_addr = hsu->local_addr;
+       prim->u.connect.sccp_class = 2;
+       prim->u.connect.conn_id = scu_conn_id;
+
+       rc = osmo_sccp_user_sap_down_nofree(hsu->sccp_user, &prim->oph);
+       if (rc)
+               LOG_HSU(hsu, DCN, LOGL_ERROR, "Failed to send SCCP Connection 
Request to CN\n");
+       return rc;
+}
+
+int hnbgw_sccp_user_tx_data_req(struct hnbgw_sccp_user *hsu, uint32_t 
scu_conn_id, struct msgb *ranap_msg)
+{
+       struct osmo_scu_prim *prim;
+       int rc;
+
+       if (!hsu) {
+               LOGP(DCN, LOGL_ERROR, "Failed to send SCCP N-DATA.req(%u): no 
SCCP User\n", scu_conn_id);
+               return -1;
+       }
+
+       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 = scu_conn_id;
+
+       rc = osmo_sccp_user_sap_down_nofree(hsu->sccp_user, &prim->oph);
+       if (rc)
+               LOG_HSU(hsu, DCN, LOGL_ERROR, "Failed to send SCCP 
N-DATA.req(%u)\n", scu_conn_id);
+       return rc;
+}
+
+int hnbgw_sccp_user_tx_disconnect_req(struct hnbgw_sccp_user *hsu, uint32_t 
scu_conn_id)
+{
+       int rc;
+
+       if (!hsu) {
+               LOGP(DCN, LOGL_ERROR, "Failed to send SCCP 
N-DISCONNECT.req(%u): no SCCP User\n", scu_conn_id);
+               return -1;
+       }
+
+       rc = osmo_sccp_tx_disconn(hsu->sccp_user, scu_conn_id, NULL, 0);
+       if (rc)
+               LOG_HSU(hsu, DCN, LOGL_ERROR, "Failed to send SCCP 
N-DISCONNECT.req(%u)\n", scu_conn_id);
+       return rc;
+}
+
+/***********************************************************************
+ * struct hnbgw_sccp_user lifecycle:
+ ***********************************************************************/
+
 static int hnbgw_sccp_user_use_cb(struct osmo_use_count_entry *e, int32_t 
old_use_count, const char *file, int line)
 {
        struct hnbgw_sccp_user *hsu = e->use_count->talloc_object;

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

Gerrit-MessageType: newchange
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I37b414cf769a16b7c7f596df3bb91a6a91a06298
Gerrit-Change-Number: 40251
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pes...@sysmocom.de>

Reply via email to