lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

April 2025

  • 1 participants
  • 1186 discussions
[XS] Change in osmo-hnbgw[master]: hnbap: Make hnbgw_tx_ue_register_acc_tmsi() signature similar to hnbg...
by fixeria 08 Apr '25

08 Apr '25
Attention is currently required from: pespin. fixeria has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39979?usp=email ) Change subject: hnbap: Make hnbgw_tx_ue_register_acc_tmsi() signature similar to hnbgw_tx_ue_register_acc() ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39979?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I9ce01babda7cb7e415cb7514c26f10a1773166fa Gerrit-Change-Number: 39979 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 08 Apr 2025 20:42:19 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[L] Change in osmo-hnbgw[master]: Move DL CL RANAP processing logic to its proper layer file
by pespin 08 Apr '25

08 Apr '25
Hello Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39987?usp=email to look at the new patch set (#2). Change subject: Move DL CL RANAP processing logic to its proper layer file ...................................................................... Move DL CL RANAP processing logic to its proper layer file This way we effectively split lower layers (SCCP and below) related to the link towards CN from the RANAP payload we need to process and forward. Change-Id: Icf18fe66d0483165fe487fe850b25830faf90150 --- M include/osmocom/hnbgw/hnbgw_ranap.h M src/osmo-hnbgw/hnbgw_cn.c M src/osmo-hnbgw/hnbgw_ranap.c 3 files changed, 215 insertions(+), 205 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/87/39987/2 -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39987?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newpatchset Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: Icf18fe66d0483165fe487fe850b25830faf90150 Gerrit-Change-Number: 39987 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder
1 0
0 0
[M] Change in osmo-hnbgw[master]: Move DL CO RANAP processing to its proper layer file
by pespin 08 Apr '25

08 Apr '25
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39988?usp=email ) Change subject: Move DL CO RANAP processing to its proper layer file ...................................................................... Move DL CO RANAP processing to its proper layer file Change-Id: Ifcb8a23becb57ccad6c9aa4769b6f27d31a71c96 --- M include/osmocom/hnbgw/hnbgw_ranap.h M src/osmo-hnbgw/context_map_sccp.c M src/osmo-hnbgw/hnbgw_ranap.c 3 files changed, 100 insertions(+), 87 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/88/39988/1 diff --git a/include/osmocom/hnbgw/hnbgw_ranap.h b/include/osmocom/hnbgw/hnbgw_ranap.h index 4317ece..2e77246 100644 --- a/include/osmocom/hnbgw/hnbgw_ranap.h +++ b/include/osmocom/hnbgw/hnbgw_ranap.h @@ -8,5 +8,6 @@ int hnbgw_ranap_rx_udt_ul(struct msgb *msg, uint8_t *data, size_t len); int hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, const struct osmo_scu_unitdata_param *unitdata, const uint8_t *data, unsigned int len); +int hnbgw_ranap_rx_data_dl(struct hnbgw_context_map *map, struct msgb *ranap_msg); int hnbgw_ranap_init(void); diff --git a/src/osmo-hnbgw/context_map_sccp.c b/src/osmo-hnbgw/context_map_sccp.c index fc82426..42a0e49 100644 --- a/src/osmo-hnbgw/context_map_sccp.c +++ b/src/osmo-hnbgw/context_map_sccp.c @@ -27,18 +27,10 @@ #include <osmocom/sigtran/sccp_helpers.h> -#include <osmocom/ranap/ranap_common_ran.h> - -#if ENABLE_PFCP -#include <osmocom/pfcp/pfcp_cp_peer.h> -#endif - #include <osmocom/hnbgw/hnbgw_cn.h> #include <osmocom/hnbgw/context_map.h> +#include <osmocom/hnbgw/hnbgw_ranap.h> #include <osmocom/hnbgw/tdefs.h> -#include <osmocom/hnbgw/mgw_fsm.h> -#include <osmocom/hnbgw/ps_rab_ass_fsm.h> -#include <osmocom/hnbgw/kpi.h> enum map_sccp_fsm_state { MAP_SCCP_ST_INIT, @@ -187,32 +179,6 @@ return osmo_sccp_tx_disconn(map->cnlink->hnbgw_sccp_user->sccp_user, map->scu_conn_id, NULL, 0); } -static int destruct_ranap_ran_rx_co_ies(ranap_message *ranap_message_p) -{ - ranap_ran_rx_co_free(ranap_message_p); - return 0; -} - -/* Decode DL RANAP message with convenient memory freeing: just talloc_free() the returned pointer.. - * Allocate a ranap_message from OTC_SELECT, decode RANAP msgb into it, attach a talloc destructor that calls - * ranap_cn_rx_co_free() upon talloc_free(), and return the decoded ranap_message. */ -static ranap_message *hnbgw_decode_ranap_ran_co(struct msgb *ranap_msg) -{ - int rc; - ranap_message *message; - - if (!msg_has_l2_data(ranap_msg)) - return NULL; - message = talloc_zero(OTC_SELECT, ranap_message); - rc = ranap_ran_rx_co_decode(NULL, message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); - if (rc != 0) { - talloc_free(message); - return NULL; - } - talloc_set_destructor(message, destruct_ranap_ran_rx_co_ies); - return message; -} - static int handle_rx_sccp(struct osmo_fsm_inst *fi, struct msgb *ranap_msg) { struct hnbgw_context_map *map = fi->priv; @@ -225,58 +191,7 @@ if (!msg_has_l2_data(ranap_msg)) return 0; - /* See if it is a RAB Assignment Request message from SCCP to RUA, where we need to change the user plane - * information, for RTP mapping via MGW, or GTP mapping via UPF. */ - ranap_message *message = hnbgw_decode_ranap_ran_co(ranap_msg); - if (message) { - talloc_set_destructor(message, destruct_ranap_ran_rx_co_ies); - - LOGPFSML(fi, LOGL_DEBUG, "rx from SCCP: RANAP %s\n", - get_value_string(ranap_procedure_code_vals, message->procedureCode)); - - kpi_ranap_process_dl(map, message); - - if (!map->is_ps) { - /* Circuit-Switched. Set up mapping of RTP ports via MGW */ - - switch (message->procedureCode) { - case RANAP_ProcedureCode_id_RAB_Assignment: - /* mgw_fsm_alloc_and_handle_rab_ass_req() takes ownership of (ranap) message */ - return handle_cs_rab_ass_req(map, ranap_msg, message); - case RANAP_ProcedureCode_id_Iu_Release: - /* Any IU Release will terminate the MGW FSM, the message itsself is not passed to the - * FSM code. It is just forwarded normally by map_rua_tx_dt() below. */ - mgw_fsm_release(map); - break; - } -#if ENABLE_PFCP - } else { - switch (message->procedureCode) { - case RANAP_ProcedureCode_id_RAB_Assignment: - /* If a UPF is configured, handle the RAB Assignment via ps_rab_ass_fsm, and replace the - * GTP F-TEIDs in the RAB Assignment message before passing it on to RUA. */ - if (hnb_gw_is_gtp_mapping_enabled()) { - LOGP(DMAIN, LOGL_DEBUG, - "RAB Assignment: setting up GTP tunnel mapping via UPF %s\n", - osmo_sockaddr_to_str_c(OTC_SELECT, osmo_pfcp_cp_peer_get_remote_addr(g_hnbgw->pfcp.cp_peer))); - return hnbgw_gtpmap_rx_rab_ass_req(map, ranap_msg, message); - } - /* If no UPF is configured, directly forward the message as-is (no GTP mapping). */ - LOGP(DMAIN, LOGL_DEBUG, "RAB Assignment: no UPF configured, forwarding as-is\n"); - break; - - case RANAP_ProcedureCode_id_Iu_Release: - /* Any IU Release will terminate the MGW FSM, the message itsself is not passed to the - * FSM code. It is just forwarded normally by map_rua_tx_dt() below. */ - hnbgw_gtpmap_release(map); - break; - } -#endif - } - } - - /* It was not a RAB Assignment Request that needed to be intercepted. Forward as-is to RUA. */ - return map_rua_dispatch(map, MAP_RUA_EV_TX_DIRECT_TRANSFER, ranap_msg); + return hnbgw_ranap_rx_data_dl(map, ranap_msg); } static void map_sccp_init_action(struct osmo_fsm_inst *fi, uint32_t event, void *data) diff --git a/src/osmo-hnbgw/hnbgw_ranap.c b/src/osmo-hnbgw/hnbgw_ranap.c index d795264..666560c 100644 --- a/src/osmo-hnbgw/hnbgw_ranap.c +++ b/src/osmo-hnbgw/hnbgw_ranap.c @@ -18,6 +18,8 @@ * */ +#include "config.h" + #include <unistd.h> #include <errno.h> #include <string.h> @@ -28,12 +30,21 @@ #include <osmocom/core/utils.h> #include <osmocom/ranap/ranap_common.h> +#include <osmocom/ranap/ranap_common_ran.h> #include <osmocom/ranap/ranap_ies_defs.h> #include <osmocom/ranap/ranap_msg_factory.h> +#if ENABLE_PFCP +#include <osmocom/pfcp/pfcp_cp_peer.h> +#endif + #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/hnbgw_rua.h> #include <osmocom/hnbgw/hnbgw_cn.h> +#include <osmocom/hnbgw/context_map.h> +#include <osmocom/hnbgw/mgw_fsm.h> +#include <osmocom/hnbgw/ps_rab_ass_fsm.h> +#include <osmocom/hnbgw/kpi.h> /***************************************************************************** * Processing of RANAP from the endpoint towards RAN (hNodeB), acting as CN @@ -410,6 +421,92 @@ return rc; } +static int destruct_ranap_ran_rx_co_ies(ranap_message *ranap_message_p) +{ + ranap_ran_rx_co_free(ranap_message_p); + return 0; +} + +/* Decode DL RANAP message with convenient memory freeing: just talloc_free() the returned pointer.. + * Allocate a ranap_message from OTC_SELECT, decode RANAP msgb into it, attach a talloc destructor that calls + * ranap_cn_rx_co_free() upon talloc_free(), and return the decoded ranap_message. */ +static ranap_message *hnbgw_decode_ranap_ran_co(struct msgb *ranap_msg) +{ + int rc; + ranap_message *message; + + if (!msg_has_l2_data(ranap_msg)) + return NULL; + message = talloc_zero(OTC_SELECT, ranap_message); + rc = ranap_ran_rx_co_decode(NULL, message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); + if (rc != 0) { + talloc_free(message); + return NULL; + } + talloc_set_destructor(message, destruct_ranap_ran_rx_co_ies); + return message; +} + +/* Process a received RANAP PDU through SCCP DATA.ind coming from CN (MSC/SGSN) + * Takes ownership of ranap_msg? */ +int hnbgw_ranap_rx_data_dl(struct hnbgw_context_map *map, struct msgb *ranap_msg) +{ + OSMO_ASSERT(map); + OSMO_ASSERT(msg_has_l2_data(ranap_msg)); + + /* See if it is a RAB Assignment Request message from SCCP to RUA, where we need to change the user plane + * information, for RTP mapping via MGW, or GTP mapping via UPF. */ + ranap_message *message = hnbgw_decode_ranap_ran_co(ranap_msg); + if (message) { + talloc_set_destructor(message, destruct_ranap_ran_rx_co_ies); + + LOG_MAP(map, DCN, LOGL_DEBUG, "rx from SCCP: RANAP %s\n", + get_value_string(ranap_procedure_code_vals, message->procedureCode)); + + kpi_ranap_process_dl(map, message); + + if (!map->is_ps) { + /* Circuit-Switched. Set up mapping of RTP ports via MGW */ + switch (message->procedureCode) { + case RANAP_ProcedureCode_id_RAB_Assignment: + /* mgw_fsm_alloc_and_handle_rab_ass_req() takes ownership of (ranap) message */ + return handle_cs_rab_ass_req(map, ranap_msg, message); + case RANAP_ProcedureCode_id_Iu_Release: + /* Any IU Release will terminate the MGW FSM, the message itsself is not passed to the + * FSM code. It is just forwarded normally by map_rua_tx_dt() below. */ + mgw_fsm_release(map); + break; + } +#if ENABLE_PFCP + } else { + switch (message->procedureCode) { + case RANAP_ProcedureCode_id_RAB_Assignment: + /* If a UPF is configured, handle the RAB Assignment via ps_rab_ass_fsm, and replace the + * GTP F-TEIDs in the RAB Assignment message before passing it on to RUA. */ + if (hnb_gw_is_gtp_mapping_enabled()) { + LOG_MAP(map, DCN, LOGL_DEBUG, + "RAB Assignment: setting up GTP tunnel mapping via UPF %s\n", + osmo_sockaddr_to_str_c(OTC_SELECT, osmo_pfcp_cp_peer_get_remote_addr(g_hnbgw->pfcp.cp_peer))); + return hnbgw_gtpmap_rx_rab_ass_req(map, ranap_msg, message); + } + /* If no UPF is configured, directly forward the message as-is (no GTP mapping). */ + LOG_MAP(map, DCN, LOGL_DEBUG, "RAB Assignment: no UPF configured, forwarding as-is\n"); + break; + + case RANAP_ProcedureCode_id_Iu_Release: + /* Any IU Release will terminate the MGW FSM, the message itsself is not passed to the + * FSM code. It is just forwarded normally by map_rua_tx_dt() below. */ + hnbgw_gtpmap_release(map); + break; + } +#endif + } + } + + /* It was not a RAB Assignment Request that needed to be intercepted. Forward as-is to RUA. */ + return map_rua_dispatch(map, MAP_RUA_EV_TX_DIRECT_TRANSFER, ranap_msg); +} + int hnbgw_ranap_init(void) { return 0; -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39988?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: Ifcb8a23becb57ccad6c9aa4769b6f27d31a71c96 Gerrit-Change-Number: 39988 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
1 0
0 0
[M] Change in osmo-hnbgw[master]: Move UL CO RANAP processing to its proper layer file
by pespin 08 Apr '25

08 Apr '25
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39989?usp=email ) Change subject: Move UL CO RANAP processing to its proper layer file ...................................................................... Move UL CO RANAP processing to its proper layer file Change-Id: I0d16f6c1c303aa1275322f12faf332de8d7c3147 --- M include/osmocom/hnbgw/hnbgw_ranap.h M include/osmocom/hnbgw/hnbgw_rua.h M src/osmo-hnbgw/context_map_rua.c M src/osmo-hnbgw/hnbgw_l3.c M src/osmo-hnbgw/hnbgw_ranap.c M src/osmo-hnbgw/hnbgw_rua.c 6 files changed, 75 insertions(+), 70 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/89/39989/1 diff --git a/include/osmocom/hnbgw/hnbgw_ranap.h b/include/osmocom/hnbgw/hnbgw_ranap.h index 2e77246..7129187 100644 --- a/include/osmocom/hnbgw/hnbgw_ranap.h +++ b/include/osmocom/hnbgw/hnbgw_ranap.h @@ -1,11 +1,16 @@ /* RANAP, 3GPP TS 25.413 */ #pragma once +#include <osmocom/ranap/ranap_ies_defs.h> #include <osmocom/hnbgw/hnbgw.h> struct osmo_scu_unitdata_param; +ranap_message *hnbgw_decode_ranap_cn_co(struct msgb *ranap_msg); + int hnbgw_ranap_rx_udt_ul(struct msgb *msg, uint8_t *data, size_t len); +int hnbgw_ranap_rx_data_ul(struct hnbgw_context_map *map, struct msgb *ranap_msg); + int hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, const struct osmo_scu_unitdata_param *unitdata, const uint8_t *data, unsigned int len); int hnbgw_ranap_rx_data_dl(struct hnbgw_context_map *map, struct msgb *ranap_msg); diff --git a/include/osmocom/hnbgw/hnbgw_rua.h b/include/osmocom/hnbgw/hnbgw_rua.h index 55e90c0..2b74be9 100644 --- a/include/osmocom/hnbgw/hnbgw_rua.h +++ b/include/osmocom/hnbgw/hnbgw_rua.h @@ -3,7 +3,6 @@ #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/rua/RUA_Cause.h> -#include <osmocom/ranap/ranap_ies_defs.h> int hnbgw_rua_rx(struct hnb_context *hnb, struct msgb *msg); @@ -13,4 +12,3 @@ int rua_tx_disc(struct hnb_context *hnb, int is_ps, uint32_t context_id, const RUA_Cause_t *cause, const uint8_t *data, unsigned int len); -ranap_message *hnbgw_decode_ranap_cn_co(struct msgb *ranap_msg); diff --git a/src/osmo-hnbgw/context_map_rua.c b/src/osmo-hnbgw/context_map_rua.c index f73b8e2..ca1a6ed 100644 --- a/src/osmo-hnbgw/context_map_rua.c +++ b/src/osmo-hnbgw/context_map_rua.c @@ -24,19 +24,11 @@ #include <osmocom/core/utils.h> #include <osmocom/core/fsm.h> -#include <osmocom/ranap/ranap_common_cn.h> - -#if ENABLE_PFCP -#include <osmocom/pfcp/pfcp_cp_peer.h> -#endif - #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/context_map.h> #include <osmocom/hnbgw/tdefs.h> #include <osmocom/hnbgw/hnbgw_rua.h> -#include <osmocom/hnbgw/mgw_fsm.h> -#include <osmocom/hnbgw/ps_rab_ass_fsm.h> -#include <osmocom/hnbgw/kpi.h> +#include <osmocom/hnbgw/hnbgw_ranap.h> enum map_rua_fsm_state { MAP_RUA_ST_INIT, @@ -128,32 +120,6 @@ } } -static int destruct_ranap_cn_rx_co_ies(ranap_message *ranap_message_p) -{ - ranap_cn_rx_co_free(ranap_message_p); - return 0; -} - -/* Decode UL RANAP message with convenient memory freeing: just talloc_free() the returned pointer.. - * Allocate a ranap_message from OTC_SELECT, decode RANAP msgb into it, attach a talloc destructor that calls - * ranap_cn_rx_co_free() upon talloc_free(), and return the decoded ranap_message. */ -ranap_message *hnbgw_decode_ranap_cn_co(struct msgb *ranap_msg) -{ - int rc; - ranap_message *message; - - if (!msg_has_l2_data(ranap_msg)) - return NULL; - message = talloc_zero(OTC_SELECT, ranap_message); - rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); - if (rc != 0) { - talloc_free(message); - return NULL; - } - talloc_set_destructor(message, destruct_ranap_cn_rx_co_ies); - return message; -} - /* Dispatch RANAP message to SCCP, if any. */ static int handle_rx_rua(struct osmo_fsm_inst *fi, struct msgb *ranap_msg) { @@ -166,37 +132,7 @@ if (!msg_has_l2_data(ranap_msg)) return 0; - ranap_message *message = hnbgw_decode_ranap_cn_co(ranap_msg); - if (message) { - LOGPFSML(fi, LOGL_DEBUG, "rx from RUA: RANAP %s\n", - get_value_string(ranap_procedure_code_vals, message->procedureCode)); - - kpi_ranap_process_ul(map, message); - - if (!map->is_ps) { - /* See if it is a RAB Assignment Response message from RUA to SCCP, where we need to change the user plane - * information, for RTP mapping via MGW, or GTP mapping via UPF. */ - switch (message->procedureCode) { - case RANAP_ProcedureCode_id_RAB_Assignment: - /* mgw_fsm_handle_rab_ass_resp() takes ownership of prim->oph and (ranap) message */ - return mgw_fsm_handle_cs_rab_ass_resp(map, ranap_msg, message); - } - } else { -#if ENABLE_PFCP - if (hnb_gw_is_gtp_mapping_enabled()) { - /* map->is_ps == true and PFCP is enabled in osmo-hnbgw.cfg */ - switch (message->procedureCode) { - case RANAP_ProcedureCode_id_RAB_Assignment: - /* ps_rab_ass_fsm takes ownership of prim->oph and RANAP message */ - return hnbgw_gtpmap_rx_rab_ass_resp(map, ranap_msg, message); - } - } -#endif - } - } - - /* It was not a RAB Assignment Response that needed to be intercepted. Forward as-is to SCCP. */ - return map_sccp_dispatch(map, MAP_SCCP_EV_TX_DATA_REQUEST, ranap_msg); + return hnbgw_ranap_rx_data_ul(map, ranap_msg); } static int forward_ranap_to_rua(struct hnbgw_context_map *map, struct msgb *ranap_msg) diff --git a/src/osmo-hnbgw/hnbgw_l3.c b/src/osmo-hnbgw/hnbgw_l3.c index 65d9eff..88587f4 100644 --- a/src/osmo-hnbgw/hnbgw_l3.c +++ b/src/osmo-hnbgw/hnbgw_l3.c @@ -28,7 +28,7 @@ #include <osmocom/gsm/protocol/gsm_04_08_gprs.h> #include <osmocom/hnbgw/hnbgw.h> -#include <osmocom/hnbgw/hnbgw_rua.h> +#include <osmocom/hnbgw/hnbgw_ranap.h> #include <osmocom/hnbgw/context_map.h> #include <osmocom/ranap/ranap_ies_defs.h> diff --git a/src/osmo-hnbgw/hnbgw_ranap.c b/src/osmo-hnbgw/hnbgw_ranap.c index 666560c..3078b7d 100644 --- a/src/osmo-hnbgw/hnbgw_ranap.c +++ b/src/osmo-hnbgw/hnbgw_ranap.c @@ -31,6 +31,7 @@ #include <osmocom/ranap/ranap_common.h> #include <osmocom/ranap/ranap_common_ran.h> +#include <osmocom/ranap/ranap_common_cn.h> #include <osmocom/ranap/ranap_ies_defs.h> #include <osmocom/ranap/ranap_msg_factory.h> @@ -224,6 +225,72 @@ return rc; } +static int destruct_ranap_cn_rx_co_ies(ranap_message *ranap_message_p) +{ + ranap_cn_rx_co_free(ranap_message_p); + return 0; +} + +/* Decode UL RANAP message with convenient memory freeing: just talloc_free() the returned pointer.. + * Allocate a ranap_message from OTC_SELECT, decode RANAP msgb into it, attach a talloc destructor that calls + * ranap_cn_rx_co_free() upon talloc_free(), and return the decoded ranap_message. */ +ranap_message *hnbgw_decode_ranap_cn_co(struct msgb *ranap_msg) +{ + int rc; + ranap_message *message; + + if (!msg_has_l2_data(ranap_msg)) + return NULL; + message = talloc_zero(OTC_SELECT, ranap_message); + rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); + if (rc != 0) { + talloc_free(message); + return NULL; + } + talloc_set_destructor(message, destruct_ranap_cn_rx_co_ies); + return message; +} + +/* Process a received RANAP PDU through SCCP DATA.ind coming from CN (MSC/SGSN) + * Takes ownership of ranap_msg? */ +int hnbgw_ranap_rx_data_ul(struct hnbgw_context_map *map, struct msgb *ranap_msg) +{ + OSMO_ASSERT(map); + OSMO_ASSERT(msg_has_l2_data(ranap_msg)); + + ranap_message *message = hnbgw_decode_ranap_cn_co(ranap_msg); + if (message) { + LOG_MAP(map, DHNB, LOGL_DEBUG, "rx from RUA: RANAP %s\n", + get_value_string(ranap_procedure_code_vals, message->procedureCode)); + + kpi_ranap_process_ul(map, message); + + if (!map->is_ps) { + /* See if it is a RAB Assignment Response message from RUA to SCCP, where we need to change the user plane + * information, for RTP mapping via MGW, or GTP mapping via UPF. */ + switch (message->procedureCode) { + case RANAP_ProcedureCode_id_RAB_Assignment: + /* mgw_fsm_handle_rab_ass_resp() takes ownership of prim->oph and (ranap) message */ + return mgw_fsm_handle_cs_rab_ass_resp(map, ranap_msg, message); + } + } else { +#if ENABLE_PFCP + if (hnb_gw_is_gtp_mapping_enabled()) { + /* map->is_ps == true and PFCP is enabled in osmo-hnbgw.cfg */ + switch (message->procedureCode) { + case RANAP_ProcedureCode_id_RAB_Assignment: + /* ps_rab_ass_fsm takes ownership of prim->oph and RANAP message */ + return hnbgw_gtpmap_rx_rab_ass_resp(map, ranap_msg, message); + } + } +#endif + } + } + + /* It was not a RAB Assignment Response that needed to be intercepted. Forward as-is to SCCP. */ + return map_sccp_dispatch(map, MAP_SCCP_EV_TX_DATA_REQUEST, ranap_msg); +} + /***************************************************************************** * Processing of RANAP from the endpoint towards CN (MSC/SGSN), acting as RAN *****************************************************************************/ diff --git a/src/osmo-hnbgw/hnbgw_rua.c b/src/osmo-hnbgw/hnbgw_rua.c index b3342f9..7cc1b27 100644 --- a/src/osmo-hnbgw/hnbgw_rua.c +++ b/src/osmo-hnbgw/hnbgw_rua.c @@ -40,7 +40,6 @@ #include <osmocom/hnbgw/context_map.h> #include <osmocom/hnbgw/hnbgw_rua.h> #include <osmocom/hnbap/HNBAP_CN-DomainIndicator.h> -#include <osmocom/ranap/ranap_ies_defs.h> static int hnbgw_rua_tx(struct hnb_context *ctx, struct msgb *msg) { -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39989?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: I0d16f6c1c303aa1275322f12faf332de8d7c3147 Gerrit-Change-Number: 39989 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in osmo-hnbgw[master]: Move CN-side RANAP processing logic to its proper layer file
by pespin 08 Apr '25

08 Apr '25
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39987?usp=email ) Change subject: Move CN-side RANAP processing logic to its proper layer file ...................................................................... Move CN-side RANAP processing logic to its proper layer file This way we effectively split lower layers (SCCP and below) related to the link towards CN from the RANAP payload we need to process and forward. Change-Id: Icf18fe66d0483165fe487fe850b25830faf90150 --- M include/osmocom/hnbgw/hnbgw_ranap.h M src/osmo-hnbgw/hnbgw_cn.c M src/osmo-hnbgw/hnbgw_ranap.c 3 files changed, 215 insertions(+), 205 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/87/39987/1 diff --git a/include/osmocom/hnbgw/hnbgw_ranap.h b/include/osmocom/hnbgw/hnbgw_ranap.h index 31f2f57..4317ece 100644 --- a/include/osmocom/hnbgw/hnbgw_ranap.h +++ b/include/osmocom/hnbgw/hnbgw_ranap.h @@ -3,5 +3,10 @@ #include <osmocom/hnbgw/hnbgw.h> +struct osmo_scu_unitdata_param; + int hnbgw_ranap_rx_udt_ul(struct msgb *msg, uint8_t *data, size_t len); +int hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, const struct osmo_scu_unitdata_param *unitdata, + const uint8_t *data, unsigned int len); int hnbgw_ranap_init(void); + diff --git a/src/osmo-hnbgw/hnbgw_cn.c b/src/osmo-hnbgw/hnbgw_cn.c index 743d9b4..692196f 100644 --- a/src/osmo-hnbgw/hnbgw_cn.c +++ b/src/osmo-hnbgw/hnbgw_cn.c @@ -38,210 +38,14 @@ #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/hnbgw_rua.h> +#include <osmocom/hnbgw/hnbgw_ranap.h> #include <osmocom/hnbgw/hnbgw_cn.h> -#include <osmocom/ranap/ranap_ies_defs.h> -#include <osmocom/ranap/ranap_msg_factory.h> -#include <osmocom/ranap/iu_helpers.h> #include <osmocom/hnbgw/context_map.h> /*********************************************************************** * Incoming primitives from SCCP User SAP ***********************************************************************/ -static int cn_ranap_rx_reset_cmd(struct hnbgw_cnlink *cnlink, - const struct osmo_scu_unitdata_param *unitdata, - RANAP_InitiatingMessage_t *imsg) -{ - RANAP_CN_DomainIndicator_t domain; - RANAP_ResetIEs_t ies; - int rc; - - rc = ranap_decode_reseties(&ies, &imsg->value); - domain = ies.cN_DomainIndicator; - ranap_free_reseties(&ies); - - if (rc) { - LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET: cannot decode IEs\n"); - return -1; - } - - if (cnlink->pool->domain != domain) { - LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET indicates domain %s, but this is %s on domain %s\n", - ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); - return -1; - } - - cnlink_rx_reset_cmd(cnlink); - return 0; -} - -static int cn_ranap_rx_reset_ack(struct hnbgw_cnlink *cnlink, - RANAP_SuccessfulOutcome_t *omsg) -{ - RANAP_CN_DomainIndicator_t domain; - RANAP_ResetAcknowledgeIEs_t ies; - int rc; - - rc = ranap_decode_resetacknowledgeies(&ies, &omsg->value); - domain = ies.cN_DomainIndicator; - ranap_free_resetacknowledgeies(&ies); - - if (rc) { - LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET ACK: cannot decode IEs\n"); - return -1; - } - - if (cnlink->pool->domain != domain) { - LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET ACK indicates domain %s, but this is %s on domain %s\n", - ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); - return -1; - } - - cnlink_rx_reset_ack(cnlink); - return 0; -} - -static int cn_ranap_rx_paging_cmd(struct hnbgw_cnlink *cnlink, - RANAP_InitiatingMessage_t *imsg, - const uint8_t *data, unsigned int len) -{ - const char *errmsg; - struct hnb_context *hnb; - bool is_ps = cnlink->pool->domain == DOMAIN_PS; - - errmsg = cnlink_paging_add_ranap(cnlink, imsg); - if (errmsg) { - LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx Paging from CN: %s. Dropping paging record." - " Later on, the Paging Response may be forwarded to the wrong CN peer.\n", - errmsg); - return -1; - } - - /* FIXME: determine which HNBs to send this Paging command, - * rather than broadcasting to all HNBs */ - llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { - if (!hnb->hnb_registered) - continue; - if (is_ps) - HNBP_CTR_INC(hnb->persistent, HNB_CTR_PS_PAGING_ATTEMPTED); - else - HNBP_CTR_INC(hnb->persistent, HNB_CTR_CS_PAGING_ATTEMPTED); - rua_tx_udt(hnb, data, len); - } - - return 0; -} - -static int ranap_rx_udt_dl_initiating_msg(struct hnbgw_cnlink *cnlink, - const struct osmo_scu_unitdata_param *unitdata, - RANAP_InitiatingMessage_t *imsg, - const uint8_t *data, unsigned int len) -{ - switch (imsg->procedureCode) { - case RANAP_ProcedureCode_id_Reset: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_RESET); - return cn_ranap_rx_reset_cmd(cnlink, unitdata, imsg); - case RANAP_ProcedureCode_id_Paging: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_PAGING); - return cn_ranap_rx_paging_cmd(cnlink, imsg, data, len); - case RANAP_ProcedureCode_id_OverloadControl: /* Overload ind */ - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_OVERLOAD_IND); - break; - case RANAP_ProcedureCode_id_ErrorIndication: /* Error ind */ - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_ERROR_IND); - break; - case RANAP_ProcedureCode_id_ResetResource: /* request */ - case RANAP_ProcedureCode_id_InformationTransfer: - case RANAP_ProcedureCode_id_DirectInformationTransfer: - case RANAP_ProcedureCode_id_UplinkInformationExchange: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED); - LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " - "Procedure %ld from CN, ignoring\n", imsg->procedureCode); - break; - default: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNKNOWN); - LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " - "Procedure %ld from CN, ignoring\n", imsg->procedureCode); - break; - } - return 0; -} - -static int ranap_rx_udt_dl_successful_msg(struct hnbgw_cnlink *cnlink, - RANAP_SuccessfulOutcome_t *omsg) -{ - switch (omsg->procedureCode) { - case RANAP_ProcedureCode_id_Reset: /* Reset acknowledge */ - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_RESET); - return cn_ranap_rx_reset_ack(cnlink, omsg); - case RANAP_ProcedureCode_id_ResetResource: /* response */ - case RANAP_ProcedureCode_id_InformationTransfer: - case RANAP_ProcedureCode_id_DirectInformationTransfer: - case RANAP_ProcedureCode_id_UplinkInformationExchange: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED); - LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " - "Procedure %ld from CN, ignoring\n", omsg->procedureCode); - break; - default: - CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNKNOWN); - LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " - "Procedure %ld from CN, ignoring\n", omsg->procedureCode); - break; - } - return 0; -} - - -static int hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, - const struct osmo_scu_unitdata_param *unitdata, - RANAP_RANAP_PDU_t *pdu, const uint8_t *data, unsigned int len) -{ - int rc; - - switch (pdu->present) { - case RANAP_RANAP_PDU_PR_initiatingMessage: - rc = ranap_rx_udt_dl_initiating_msg(cnlink, unitdata, &pdu->choice.initiatingMessage, data, len); - break; - case RANAP_RANAP_PDU_PR_successfulOutcome: - rc = ranap_rx_udt_dl_successful_msg(cnlink, &pdu->choice.successfulOutcome); - break; - case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: - LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " - "unsuccessful outcome procedure %ld from CN, ignoring\n", - pdu->choice.unsuccessfulOutcome.procedureCode); - rc = -ENOTSUP; - break; - default: - LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " - "presence %u from CN, ignoring\n", pdu->present); - rc = -EINVAL; - break; - } - - return rc; -} - -static int handle_cn_ranap(struct hnbgw_cnlink *cnlink, const struct osmo_scu_unitdata_param *unitdata, - const uint8_t *data, unsigned int len) -{ - RANAP_RANAP_PDU_t _pdu, *pdu = &_pdu; - asn_dec_rval_t dec_ret; - int rc; - - memset(pdu, 0, sizeof(*pdu)); - dec_ret = aper_decode(NULL, &asn_DEF_RANAP_RANAP_PDU, (void **) &pdu, - data, len, 0, 0); - if (dec_ret.code != RC_OK) { - LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n"); - return -1; - } - - rc = hnbgw_ranap_rx_udt_dl(cnlink, unitdata, pdu, data, len); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, pdu); - - return rc; -} - static struct hnbgw_cnlink *cnlink_from_addr(struct hnbgw_sccp_user *hsu, const struct osmo_sccp_addr *calling_addr, const struct osmo_prim_hdr *oph) { @@ -283,7 +87,7 @@ return -1; } - return handle_cn_ranap(cnlink, param, msgb_l2(oph->msg), msgb_l2len(oph->msg)); + return hnbgw_ranap_rx_udt_dl(cnlink, param, msgb_l2(oph->msg), msgb_l2len(oph->msg)); } static int handle_cn_conn_conf(struct hnbgw_sccp_user *hsu, diff --git a/src/osmo-hnbgw/hnbgw_ranap.c b/src/osmo-hnbgw/hnbgw_ranap.c index 83215f7..d795264 100644 --- a/src/osmo-hnbgw/hnbgw_ranap.c +++ b/src/osmo-hnbgw/hnbgw_ranap.c @@ -18,23 +18,27 @@ * */ - - -#include <osmocom/core/msgb.h> -#include <osmocom/core/utils.h> - #include <unistd.h> #include <errno.h> #include <string.h> #include "asn1helpers.h" -#include <osmocom/hnbgw/hnbgw.h> -#include <osmocom/hnbgw/hnbgw_rua.h> +#include <osmocom/core/msgb.h> +#include <osmocom/core/utils.h> + #include <osmocom/ranap/ranap_common.h> #include <osmocom/ranap/ranap_ies_defs.h> #include <osmocom/ranap/ranap_msg_factory.h> +#include <osmocom/hnbgw/hnbgw.h> +#include <osmocom/hnbgw/hnbgw_rua.h> +#include <osmocom/hnbgw/hnbgw_cn.h> + +/***************************************************************************** + * Processing of RANAP from the endpoint towards RAN (hNodeB), acting as CN + *****************************************************************************/ + static int ranap_tx_udt_dl_reset_ack(struct hnb_context *hnb, RANAP_CN_DomainIndicator_t domain) { struct msgb *msg; @@ -209,6 +213,203 @@ return rc; } +/***************************************************************************** + * Processing of RANAP from the endpoint towards CN (MSC/SGSN), acting as RAN + *****************************************************************************/ + +static int cn_ranap_rx_reset_cmd(struct hnbgw_cnlink *cnlink, + const struct osmo_scu_unitdata_param *unitdata, + RANAP_InitiatingMessage_t *imsg) +{ + RANAP_CN_DomainIndicator_t domain; + RANAP_ResetIEs_t ies; + int rc; + + rc = ranap_decode_reseties(&ies, &imsg->value); + domain = ies.cN_DomainIndicator; + ranap_free_reseties(&ies); + + if (rc) { + LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET: cannot decode IEs\n"); + return -1; + } + + if (cnlink->pool->domain != domain) { + LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET indicates domain %s, but this is %s on domain %s\n", + ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); + return -1; + } + + cnlink_rx_reset_cmd(cnlink); + return 0; +} + +static int cn_ranap_rx_paging_cmd(struct hnbgw_cnlink *cnlink, + RANAP_InitiatingMessage_t *imsg, + const uint8_t *data, unsigned int len) +{ + const char *errmsg; + struct hnb_context *hnb; + bool is_ps = cnlink->pool->domain == DOMAIN_PS; + + errmsg = cnlink_paging_add_ranap(cnlink, imsg); + if (errmsg) { + LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx Paging from CN: %s. Dropping paging record." + " Later on, the Paging Response may be forwarded to the wrong CN peer.\n", + errmsg); + return -1; + } + + /* FIXME: determine which HNBs to send this Paging command, + * rather than broadcasting to all HNBs */ + llist_for_each_entry(hnb, &g_hnbgw->hnb_list, list) { + if (!hnb->hnb_registered) + continue; + if (is_ps) + HNBP_CTR_INC(hnb->persistent, HNB_CTR_PS_PAGING_ATTEMPTED); + else + HNBP_CTR_INC(hnb->persistent, HNB_CTR_CS_PAGING_ATTEMPTED); + rua_tx_udt(hnb, data, len); + } + + return 0; +} + +static int ranap_rx_udt_dl_initiating_msg(struct hnbgw_cnlink *cnlink, + const struct osmo_scu_unitdata_param *unitdata, + RANAP_InitiatingMessage_t *imsg, + const uint8_t *data, unsigned int len) +{ + switch (imsg->procedureCode) { + case RANAP_ProcedureCode_id_Reset: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_RESET); + return cn_ranap_rx_reset_cmd(cnlink, unitdata, imsg); + case RANAP_ProcedureCode_id_Paging: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_PAGING); + return cn_ranap_rx_paging_cmd(cnlink, imsg, data, len); + case RANAP_ProcedureCode_id_OverloadControl: /* Overload ind */ + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_OVERLOAD_IND); + break; + case RANAP_ProcedureCode_id_ErrorIndication: /* Error ind */ + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_ERROR_IND); + break; + case RANAP_ProcedureCode_id_ResetResource: /* request */ + case RANAP_ProcedureCode_id_InformationTransfer: + case RANAP_ProcedureCode_id_DirectInformationTransfer: + case RANAP_ProcedureCode_id_UplinkInformationExchange: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED); + LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " + "Procedure %ld from CN, ignoring\n", imsg->procedureCode); + break; + default: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNKNOWN); + LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " + "Procedure %ld from CN, ignoring\n", imsg->procedureCode); + break; + } + return 0; +} + +static int cn_ranap_rx_reset_ack(struct hnbgw_cnlink *cnlink, + RANAP_SuccessfulOutcome_t *omsg) +{ + RANAP_CN_DomainIndicator_t domain; + RANAP_ResetAcknowledgeIEs_t ies; + int rc; + + rc = ranap_decode_resetacknowledgeies(&ies, &omsg->value); + domain = ies.cN_DomainIndicator; + ranap_free_resetacknowledgeies(&ies); + + if (rc) { + LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET ACK: cannot decode IEs\n"); + return -1; + } + + if (cnlink->pool->domain != domain) { + LOG_CNLINK(cnlink, DCN, LOGL_ERROR, "Rx RESET ACK indicates domain %s, but this is %s on domain %s\n", + ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); + return -1; + } + + cnlink_rx_reset_ack(cnlink); + return 0; +} + +static int ranap_rx_udt_dl_successful_msg(struct hnbgw_cnlink *cnlink, + RANAP_SuccessfulOutcome_t *omsg) +{ + switch (omsg->procedureCode) { + case RANAP_ProcedureCode_id_Reset: /* Reset acknowledge */ + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_RESET); + return cn_ranap_rx_reset_ack(cnlink, omsg); + case RANAP_ProcedureCode_id_ResetResource: /* response */ + case RANAP_ProcedureCode_id_InformationTransfer: + case RANAP_ProcedureCode_id_DirectInformationTransfer: + case RANAP_ProcedureCode_id_UplinkInformationExchange: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNSUPPORTED); + LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " + "Procedure %ld from CN, ignoring\n", omsg->procedureCode); + break; + default: + CNLINK_CTR_INC(cnlink, CNLINK_CTR_RANAP_RX_UDT_UNKNOWN); + LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " + "Procedure %ld from CN, ignoring\n", omsg->procedureCode); + break; + } + return 0; +} + +static int _hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, + const struct osmo_scu_unitdata_param *unitdata, + RANAP_RANAP_PDU_t *pdu, const uint8_t *data, unsigned int len) +{ + int rc; + + switch (pdu->present) { + case RANAP_RANAP_PDU_PR_initiatingMessage: + rc = ranap_rx_udt_dl_initiating_msg(cnlink, unitdata, &pdu->choice.initiatingMessage, data, len); + break; + case RANAP_RANAP_PDU_PR_successfulOutcome: + rc = ranap_rx_udt_dl_successful_msg(cnlink, &pdu->choice.successfulOutcome); + break; + case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: + LOGP(DRANAP, LOGL_NOTICE, "Received unsupported RANAP " + "unsuccessful outcome procedure %ld from CN, ignoring\n", + pdu->choice.unsuccessfulOutcome.procedureCode); + rc = -ENOTSUP; + break; + default: + LOGP(DRANAP, LOGL_NOTICE, "Received suspicious RANAP " + "presence %u from CN, ignoring\n", pdu->present); + rc = -EINVAL; + break; + } + + return rc; +} + +int hnbgw_ranap_rx_udt_dl(struct hnbgw_cnlink *cnlink, const struct osmo_scu_unitdata_param *unitdata, + const uint8_t *data, unsigned int len) +{ + RANAP_RANAP_PDU_t _pdu, *pdu = &_pdu; + asn_dec_rval_t dec_ret; + int rc; + + memset(pdu, 0, sizeof(*pdu)); + dec_ret = aper_decode(NULL, &asn_DEF_RANAP_RANAP_PDU, (void **) &pdu, + data, len, 0, 0); + if (dec_ret.code != RC_OK) { + LOGP(DRANAP, LOGL_ERROR, "Error in RANAP ASN.1 decode\n"); + return -1; + } + + rc = _hnbgw_ranap_rx_udt_dl(cnlink, unitdata, pdu, data, len); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_RANAP_RANAP_PDU, pdu); + + return rc; +} + int hnbgw_ranap_init(void) { return 0; -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39987?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: Icf18fe66d0483165fe487fe850b25830faf90150 Gerrit-Change-Number: 39987 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in osmo-hnbgw[master]: Move paging logic to its own file
by pespin 08 Apr '25

08 Apr '25
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39986?usp=email ) Change subject: Move paging logic to its own file ...................................................................... Move paging logic to its own file Paging logic contains quite a lot of logic which is really specific to paging topic and which can be put together and encapsulated easily. Furthermore, this logic will mostly grow in the future since right now we only offer minimal paging features by broadcasting to all HNBs. Finally, this also simplifies hnbgw_cn.c Change-Id: I402fdcdc261626798904e7ee2eb5db80d30c4c34 --- M include/osmocom/hnbgw/hnbgw_cn.h M src/osmo-hnbgw/Makefile.am A src/osmo-hnbgw/cnlink_paging.c M src/osmo-hnbgw/hnbgw_cn.c 4 files changed, 245 insertions(+), 187 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/86/39986/1 diff --git a/include/osmocom/hnbgw/hnbgw_cn.h b/include/osmocom/hnbgw/hnbgw_cn.h index 9b26e6e..0c99b26 100644 --- a/include/osmocom/hnbgw/hnbgw_cn.h +++ b/include/osmocom/hnbgw/hnbgw_cn.h @@ -1,6 +1,10 @@ #pragma once #include <osmocom/core/rate_ctr.h> +#include <osmocom/gsm/gsm48.h> + +#include <osmocom/ranap/ranap_ies_defs.h> + #include <osmocom/hnbgw/hnbgw.h> struct hnbgw_cnlink *cnlink_alloc(struct hnbgw_cnpool *cnpool, int nr); @@ -21,6 +25,9 @@ void cnlink_resend_reset(struct hnbgw_cnlink *cnlink); void cnlink_set_disconnected(struct hnbgw_cnlink *cnlink); +const char *cnlink_paging_add_ranap(struct hnbgw_cnlink *cnlink, RANAP_InitiatingMessage_t *imsg); +struct hnbgw_cnlink *cnlink_find_by_paging_mi(struct hnbgw_cnpool *cnpool, const struct osmo_mobile_identity *mi); + enum hnbgw_cnpool_ctr { /* TODO: basic counters completely missing * ... diff --git a/src/osmo-hnbgw/Makefile.am b/src/osmo-hnbgw/Makefile.am index dc6a9a4..e108906 100644 --- a/src/osmo-hnbgw/Makefile.am +++ b/src/osmo-hnbgw/Makefile.am @@ -43,6 +43,7 @@ context_map_sccp.c \ hnbgw_cn.c \ cnlink.c \ + cnlink_paging.c \ ranap_rab_ass.c \ mgw_fsm.c \ kpi_dtap.c \ diff --git a/src/osmo-hnbgw/cnlink_paging.c b/src/osmo-hnbgw/cnlink_paging.c new file mode 100644 index 0000000..e5ef2c2 --- /dev/null +++ b/src/osmo-hnbgw/cnlink_paging.c @@ -0,0 +1,237 @@ +/* RANAP Paging of HNB-GW */ +/* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> + * (C) 2025 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de> + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include "config.h" + +#include <errno.h> +#include <sys/types.h> + +#include <asn1c/asn1helpers.h> + +#include <osmocom/core/logging.h> +#include <osmocom/core/timer.h> +#include <osmocom/core/utils.h> +#include <osmocom/core/linuxlist.h> +#include <osmocom/gsm/gsm48.h> + +#include <osmocom/ranap/ranap_ies_defs.h> +#include <osmocom/ranap/iu_helpers.h> + +#include <osmocom/hnbgw/hnbgw.h> +#include <osmocom/hnbgw/hnbgw_cn.h> +#include <osmocom/hnbgw/context_map.h> +#include <osmocom/hnbgw/tdefs.h> + +/*************** + * This module manages the list of "struct cnlink_paging" items in (struct + * hnbgw_cnlink *)->paging. + * Every time a new RANAP Paging Cmd arrives from some cnlink, + * cnlink_paging_add_ranap() is called to potentially store the paging command + * for a while. + * When a paging response is received from HNB, cnlink_find_by_paging_mi() is + * called to obtain the cnlink it should be routed back to. + */ + +struct cnlink_paging { + struct llist_head entry; + + struct osmo_mobile_identity mi; + struct osmo_mobile_identity mi2; + time_t timestamp; +}; + +static int cnlink_paging_destructor(struct cnlink_paging *p) +{ + llist_del(&p->entry); + return 0; +} + + +/* Return current timestamp in *timestamp, and the oldest still valid timestamp according to T3113 timeout. */ +static const char *cnlink_paging_gettime(time_t *timestamp_p, time_t *timeout_p) +{ + struct timespec now; + time_t timestamp; + + /* get timestamp */ + if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0) + return "cannot get timestamp"; + timestamp = now.tv_sec; + + if (timestamp_p) + *timestamp_p = timestamp; + if (timeout_p) + *timeout_p = timestamp - osmo_tdef_get(hnbgw_T_defs, 3113, OSMO_TDEF_S, 15); + return NULL; +} + +static const char *cnlink_paging_add(struct hnbgw_cnlink *cnlink, const struct osmo_mobile_identity *mi, + const struct osmo_mobile_identity *mi2) +{ + struct cnlink_paging *p, *p2; + time_t timestamp; + time_t timeout; + const char *errmsg; + + errmsg = cnlink_paging_gettime(&timestamp, &timeout); + if (errmsg) + return errmsg; + + /* Prune all paging records that are older than the configured timeout. */ + llist_for_each_entry_safe(p, p2, &cnlink->paging, entry) { + if (p->timestamp >= timeout) + continue; + talloc_free(p); + } + + /* Add new entry */ + p = talloc_zero(cnlink, struct cnlink_paging); + *p = (struct cnlink_paging){ + .timestamp = timestamp, + .mi = *mi, + .mi2 = *mi2, + }; + llist_add_tail(&p->entry, &cnlink->paging); + talloc_set_destructor(p, cnlink_paging_destructor); + + LOG_CNLINK(cnlink, DCN, LOGL_INFO, "Rx Paging from CN for %s %s\n", + osmo_mobile_identity_to_str_c(OTC_SELECT, mi), + osmo_mobile_identity_to_str_c(OTC_SELECT, mi2)); + return NULL; +} + +static const char *omi_from_ranap_ue_id(struct osmo_mobile_identity *mi, const RANAP_PermanentNAS_UE_ID_t *ranap_mi) +{ + if (!ranap_mi) + return "null UE ID"; + + if (ranap_mi->present != RANAP_PermanentNAS_UE_ID_PR_iMSI) + return talloc_asprintf(OTC_SELECT, "unsupported UE ID type %u in RANAP Paging", ranap_mi->present); + + if (ranap_mi->choice.iMSI.size > sizeof(mi->imsi)) + return talloc_asprintf(OTC_SELECT, "invalid IMSI size %d > %zu", + ranap_mi->choice.iMSI.size, sizeof(mi->imsi)); + + *mi = (struct osmo_mobile_identity){ + .type = GSM_MI_TYPE_IMSI, + }; + ranap_bcd_decode(mi->imsi, sizeof(mi->imsi), ranap_mi->choice.iMSI.buf, ranap_mi->choice.iMSI.size); + LOGP(DCN, LOGL_DEBUG, "ranap MI %s = %s\n", osmo_hexdump(ranap_mi->choice.iMSI.buf, ranap_mi->choice.iMSI.size), + mi->imsi); + return NULL; +} + +static const char *omi_from_ranap_temp_ue_id(struct osmo_mobile_identity *mi, const RANAP_TemporaryUE_ID_t *ranap_tmsi) +{ + const OCTET_STRING_t *tmsi_str; + + if (!ranap_tmsi) + return "null UE ID"; + + switch (ranap_tmsi->present) { + case RANAP_TemporaryUE_ID_PR_tMSI: + tmsi_str = &ranap_tmsi->choice.tMSI; + break; + case RANAP_TemporaryUE_ID_PR_p_TMSI: + tmsi_str = &ranap_tmsi->choice.p_TMSI; + break; + default: + return talloc_asprintf(OTC_SELECT, "unsupported Temporary UE ID type %u in RANAP Paging", ranap_tmsi->present); + } + + *mi = (struct osmo_mobile_identity){ + .type = GSM_MI_TYPE_TMSI, + .tmsi = asn1str_to_u32(tmsi_str), + }; + LOGP(DCN, LOGL_DEBUG, "ranap temp UE ID = %s\n", osmo_mobile_identity_to_str_c(OTC_SELECT, mi)); + return NULL; +} + +const char *cnlink_paging_add_ranap(struct hnbgw_cnlink *cnlink, RANAP_InitiatingMessage_t *imsg) +{ + RANAP_PagingIEs_t ies; + struct osmo_mobile_identity mi = {}; + struct osmo_mobile_identity mi2 = {}; + RANAP_CN_DomainIndicator_t domain; + const char *errmsg; + + if (ranap_decode_pagingies(&ies, &imsg->value) < 0) + return "decoding RANAP IEs failed"; + + domain = ies.cN_DomainIndicator; + errmsg = omi_from_ranap_ue_id(&mi, &ies.permanentNAS_UE_ID); + + if (!errmsg && (ies.presenceMask & PAGINGIES_RANAP_TEMPORARYUE_ID_PRESENT)) + errmsg = omi_from_ranap_temp_ue_id(&mi2, &ies.temporaryUE_ID); + + ranap_free_pagingies(&ies); + LOG_CNLINK(cnlink, DCN, LOGL_DEBUG, "Decoded Paging: %s %s %s%s%s\n", + ranap_domain_name(domain), osmo_mobile_identity_to_str_c(OTC_SELECT, &mi), + mi2.type ? osmo_mobile_identity_to_str_c(OTC_SELECT, &mi2) : "-", + errmsg ? " -- MI error: " : "", + errmsg ? : ""); + + if (cnlink->pool->domain != domain) + return talloc_asprintf(OTC_SELECT, "message indicates domain %s, but this is %s on domain %s\n", + ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); + + if (errmsg) + return errmsg; + + return cnlink_paging_add(cnlink, &mi, &mi2); +} + +/* If this cnlink has a recent Paging for the given MI, return true and drop the Paging record. + * Else return false. */ +static bool cnlink_match_paging_mi(struct hnbgw_cnlink *cnlink, const struct osmo_mobile_identity *mi, time_t timeout) +{ + struct cnlink_paging *p, *p2; + llist_for_each_entry_safe(p, p2, &cnlink->paging, entry) { + if (p->timestamp < timeout) { + talloc_free(p); + continue; + } + if (osmo_mobile_identity_cmp(&p->mi, mi) + && osmo_mobile_identity_cmp(&p->mi2, mi)) + continue; + talloc_free(p); + return true; + } + return false; +} + +struct hnbgw_cnlink *cnlink_find_by_paging_mi(struct hnbgw_cnpool *cnpool, const struct osmo_mobile_identity *mi) +{ + struct hnbgw_cnlink *cnlink; + time_t timeout = 0; + const char *errmsg; + + errmsg = cnlink_paging_gettime(NULL, &timeout); + if (errmsg) + LOGP(DCN, LOGL_ERROR, "%s\n", errmsg); + + llist_for_each_entry(cnlink, &cnpool->cnlinks, entry) { + if (!cnlink_match_paging_mi(cnlink, mi, timeout)) + continue; + return cnlink; + } + return NULL; +} + diff --git a/src/osmo-hnbgw/hnbgw_cn.c b/src/osmo-hnbgw/hnbgw_cn.c index e7df788..743d9b4 100644 --- a/src/osmo-hnbgw/hnbgw_cn.c +++ b/src/osmo-hnbgw/hnbgw_cn.c @@ -27,7 +27,6 @@ #include <osmocom/core/msgb.h> #include <osmocom/core/utils.h> -#include <osmocom/core/timer.h> #include <osmocom/core/stats.h> #include <osmocom/gsm/gsm23236.h> @@ -40,7 +39,6 @@ #include <osmocom/hnbgw/hnbgw.h> #include <osmocom/hnbgw/hnbgw_rua.h> #include <osmocom/hnbgw/hnbgw_cn.h> -#include <osmocom/hnbgw/tdefs.h> #include <osmocom/ranap/ranap_ies_defs.h> #include <osmocom/ranap/ranap_msg_factory.h> #include <osmocom/ranap/iu_helpers.h> @@ -103,191 +101,6 @@ return 0; } -struct cnlink_paging { - struct llist_head entry; - - struct osmo_mobile_identity mi; - struct osmo_mobile_identity mi2; - time_t timestamp; -}; - -static int cnlink_paging_destructor(struct cnlink_paging *p) -{ - llist_del(&p->entry); - return 0; -} - -/* Return current timestamp in *timestamp, and the oldest still valid timestamp according to T3113 timeout. */ -static const char *cnlink_paging_gettime(time_t *timestamp_p, time_t *timeout_p) -{ - struct timespec now; - time_t timestamp; - - /* get timestamp */ - if (osmo_clock_gettime(CLOCK_MONOTONIC, &now) != 0) - return "cannot get timestamp"; - timestamp = now.tv_sec; - - if (timestamp_p) - *timestamp_p = timestamp; - if (timeout_p) - *timeout_p = timestamp - osmo_tdef_get(hnbgw_T_defs, 3113, OSMO_TDEF_S, 15); - return NULL; -} - -static const char *cnlink_paging_add(struct hnbgw_cnlink *cnlink, const struct osmo_mobile_identity *mi, - const struct osmo_mobile_identity *mi2) -{ - struct cnlink_paging *p, *p2; - time_t timestamp; - time_t timeout; - const char *errmsg; - - errmsg = cnlink_paging_gettime(&timestamp, &timeout); - if (errmsg) - return errmsg; - - /* Prune all paging records that are older than the configured timeout. */ - llist_for_each_entry_safe(p, p2, &cnlink->paging, entry) { - if (p->timestamp >= timeout) - continue; - talloc_free(p); - } - - /* Add new entry */ - p = talloc_zero(cnlink, struct cnlink_paging); - *p = (struct cnlink_paging){ - .timestamp = timestamp, - .mi = *mi, - .mi2 = *mi2, - }; - llist_add_tail(&p->entry, &cnlink->paging); - talloc_set_destructor(p, cnlink_paging_destructor); - - LOG_CNLINK(cnlink, DCN, LOGL_INFO, "Rx Paging from CN for %s %s\n", - osmo_mobile_identity_to_str_c(OTC_SELECT, mi), - osmo_mobile_identity_to_str_c(OTC_SELECT, mi2)); - return NULL; -} - -static const char *omi_from_ranap_ue_id(struct osmo_mobile_identity *mi, const RANAP_PermanentNAS_UE_ID_t *ranap_mi) -{ - if (!ranap_mi) - return "null UE ID"; - - if (ranap_mi->present != RANAP_PermanentNAS_UE_ID_PR_iMSI) - return talloc_asprintf(OTC_SELECT, "unsupported UE ID type %u in RANAP Paging", ranap_mi->present); - - if (ranap_mi->choice.iMSI.size > sizeof(mi->imsi)) - return talloc_asprintf(OTC_SELECT, "invalid IMSI size %d > %zu", - ranap_mi->choice.iMSI.size, sizeof(mi->imsi)); - - *mi = (struct osmo_mobile_identity){ - .type = GSM_MI_TYPE_IMSI, - }; - ranap_bcd_decode(mi->imsi, sizeof(mi->imsi), ranap_mi->choice.iMSI.buf, ranap_mi->choice.iMSI.size); - LOGP(DCN, LOGL_DEBUG, "ranap MI %s = %s\n", osmo_hexdump(ranap_mi->choice.iMSI.buf, ranap_mi->choice.iMSI.size), - mi->imsi); - return NULL; -} - -static const char *omi_from_ranap_temp_ue_id(struct osmo_mobile_identity *mi, const RANAP_TemporaryUE_ID_t *ranap_tmsi) -{ - const OCTET_STRING_t *tmsi_str; - - if (!ranap_tmsi) - return "null UE ID"; - - switch (ranap_tmsi->present) { - case RANAP_TemporaryUE_ID_PR_tMSI: - tmsi_str = &ranap_tmsi->choice.tMSI; - break; - case RANAP_TemporaryUE_ID_PR_p_TMSI: - tmsi_str = &ranap_tmsi->choice.p_TMSI; - break; - default: - return talloc_asprintf(OTC_SELECT, "unsupported Temporary UE ID type %u in RANAP Paging", ranap_tmsi->present); - } - - *mi = (struct osmo_mobile_identity){ - .type = GSM_MI_TYPE_TMSI, - .tmsi = asn1str_to_u32(tmsi_str), - }; - LOGP(DCN, LOGL_DEBUG, "ranap temp UE ID = %s\n", osmo_mobile_identity_to_str_c(OTC_SELECT, mi)); - return NULL; -} - -static const char *cnlink_paging_add_ranap(struct hnbgw_cnlink *cnlink, RANAP_InitiatingMessage_t *imsg) -{ - RANAP_PagingIEs_t ies; - struct osmo_mobile_identity mi = {}; - struct osmo_mobile_identity mi2 = {}; - RANAP_CN_DomainIndicator_t domain; - const char *errmsg; - - if (ranap_decode_pagingies(&ies, &imsg->value) < 0) - return "decoding RANAP IEs failed"; - - domain = ies.cN_DomainIndicator; - errmsg = omi_from_ranap_ue_id(&mi, &ies.permanentNAS_UE_ID); - - if (!errmsg && (ies.presenceMask & PAGINGIES_RANAP_TEMPORARYUE_ID_PRESENT)) - errmsg = omi_from_ranap_temp_ue_id(&mi2, &ies.temporaryUE_ID); - - ranap_free_pagingies(&ies); - LOG_CNLINK(cnlink, DCN, LOGL_DEBUG, "Decoded Paging: %s %s %s%s%s\n", - ranap_domain_name(domain), osmo_mobile_identity_to_str_c(OTC_SELECT, &mi), - mi2.type ? osmo_mobile_identity_to_str_c(OTC_SELECT, &mi2) : "-", - errmsg ? " -- MI error: " : "", - errmsg ? : ""); - - if (cnlink->pool->domain != domain) - return talloc_asprintf(OTC_SELECT, "message indicates domain %s, but this is %s on domain %s\n", - ranap_domain_name(domain), cnlink->name, ranap_domain_name(cnlink->pool->domain)); - - if (errmsg) - return errmsg; - - return cnlink_paging_add(cnlink, &mi, &mi2); -} - -/* If this cnlink has a recent Paging for the given MI, return true and drop the Paging record. - * Else return false. */ -static bool cnlink_match_paging_mi(struct hnbgw_cnlink *cnlink, const struct osmo_mobile_identity *mi, time_t timeout) -{ - struct cnlink_paging *p, *p2; - llist_for_each_entry_safe(p, p2, &cnlink->paging, entry) { - if (p->timestamp < timeout) { - talloc_free(p); - continue; - } - if (osmo_mobile_identity_cmp(&p->mi, mi) - && osmo_mobile_identity_cmp(&p->mi2, mi)) - continue; - talloc_free(p); - return true; - } - return false; -} - -static struct hnbgw_cnlink *cnlink_find_by_paging_mi(struct hnbgw_cnpool *cnpool, const struct osmo_mobile_identity *mi) -{ - struct hnbgw_cnlink *cnlink; - time_t timeout = 0; - const char *errmsg; - - errmsg = cnlink_paging_gettime(NULL, &timeout); - if (errmsg) - LOGP(DCN, LOGL_ERROR, "%s\n", errmsg); - - llist_for_each_entry(cnlink, &cnpool->cnlinks, entry) { - if (!cnlink_match_paging_mi(cnlink, mi, timeout)) - continue; - return cnlink; - } - return NULL; -} - static int cn_ranap_rx_paging_cmd(struct hnbgw_cnlink *cnlink, RANAP_InitiatingMessage_t *imsg, const uint8_t *data, unsigned int len) -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39986?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: I402fdcdc261626798904e7ee2eb5db80d30c4c34 Gerrit-Change-Number: 39986 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-hnbgw[master]: cosmetic: Add spec references for RUA, RANAP, HNBAP
by pespin 08 Apr '25

08 Apr '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39977?usp=email ) Change subject: cosmetic: Add spec references for RUA, RANAP, HNBAP ...................................................................... cosmetic: Add spec references for RUA, RANAP, HNBAP Change-Id: I0e638befaa1e5093dc0c95e77414bfd9d9179a66 --- M include/osmocom/hnbgw/hnbgw_hnbap.h M include/osmocom/hnbgw/hnbgw_ranap.h M include/osmocom/hnbgw/hnbgw_rua.h M src/osmo-hnbgw/hnbgw_hnbap.c M src/osmo-hnbgw/hnbgw_ranap.c M src/osmo-hnbgw/hnbgw_rua.c 6 files changed, 6 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/include/osmocom/hnbgw/hnbgw_hnbap.h b/include/osmocom/hnbgw/hnbgw_hnbap.h index d0af955..2f0c5b4 100644 --- a/include/osmocom/hnbgw/hnbgw_hnbap.h +++ b/include/osmocom/hnbgw/hnbgw_hnbap.h @@ -1,3 +1,4 @@ +/* HNBAP, 3GPP TS 25.469 */ #pragma once #include <osmocom/hnbgw/hnbgw.h> diff --git a/include/osmocom/hnbgw/hnbgw_ranap.h b/include/osmocom/hnbgw/hnbgw_ranap.h index 50504e6..31f2f57 100644 --- a/include/osmocom/hnbgw/hnbgw_ranap.h +++ b/include/osmocom/hnbgw/hnbgw_ranap.h @@ -1,3 +1,4 @@ +/* RANAP, 3GPP TS 25.413 */ #pragma once #include <osmocom/hnbgw/hnbgw.h> diff --git a/include/osmocom/hnbgw/hnbgw_rua.h b/include/osmocom/hnbgw/hnbgw_rua.h index 0bf2de8..b7e7ee6 100644 --- a/include/osmocom/hnbgw/hnbgw_rua.h +++ b/include/osmocom/hnbgw/hnbgw_rua.h @@ -1,3 +1,4 @@ +/* RUA, 3GPP TS 25.468 */ #pragma once #include <osmocom/hnbgw/hnbgw.h> diff --git a/src/osmo-hnbgw/hnbgw_hnbap.c b/src/osmo-hnbgw/hnbgw_hnbap.c index e373600..99a27f5 100644 --- a/src/osmo-hnbgw/hnbgw_hnbap.c +++ b/src/osmo-hnbgw/hnbgw_hnbap.c @@ -1,4 +1,4 @@ -/* hnb-gw specific code for HNBAP */ +/* hnb-gw specific code for HNBAP, 3GPP TS 25.469 */ /* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> * All Rights Reserved diff --git a/src/osmo-hnbgw/hnbgw_ranap.c b/src/osmo-hnbgw/hnbgw_ranap.c index 7fb7dcb..83215f7 100644 --- a/src/osmo-hnbgw/hnbgw_ranap.c +++ b/src/osmo-hnbgw/hnbgw_ranap.c @@ -1,4 +1,4 @@ -/* hnb-gw specific code for RANAP */ +/* hnb-gw specific code for RANAP, 3GPP TS 25.413 */ /* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> * All Rights Reserved diff --git a/src/osmo-hnbgw/hnbgw_rua.c b/src/osmo-hnbgw/hnbgw_rua.c index b804b46..b3342f9 100644 --- a/src/osmo-hnbgw/hnbgw_rua.c +++ b/src/osmo-hnbgw/hnbgw_rua.c @@ -1,4 +1,4 @@ -/* hnb-gw specific code for RUA (Ranap User Adaption) */ +/* hnb-gw specific code for RUA (Ranap User Adaption), 3GPP TS 25.468 */ /* (C) 2015 by Harald Welte <laforge(a)gnumonks.org> * All Rights Reserved -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39977?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: I0e638befaa1e5093dc0c95e77414bfd9d9179a66 Gerrit-Change-Number: 39977 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmo-hnbgw[master]: Add function helper hnbgw_decode_ranap_ran_co()
by pespin 08 Apr '25

08 Apr '25
pespin has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39984?usp=email ) Change subject: Add function helper hnbgw_decode_ranap_ran_co() ...................................................................... Patch Set 1: (2 comments) File src/osmo-hnbgw/context_map_sccp.c: https://gerrit.osmocom.org/c/osmo-hnbgw/+/39984/comment/e5bcf503_35e16300?u… : PS1, Line 207: rc = ranap_ran_rx_co_decode(NULL, message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); THis function is RAN specific. The CN side is using ranap_cn_rx_co_decode(). https://gerrit.osmocom.org/c/osmo-hnbgw/+/39984/comment/1711a4c0_46c0764a?u… : PS1, Line 212: talloc_set_destructor(message, destruct_ranap_ran_rx_co_ies); destruct_ranap_ran_rx_co_ies() too, which calls RAN specific ranap_ran_rx_co_free(). -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39984?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: Ifbb058d5340a6cb3a1703415e49c0de04fa6aec1 Gerrit-Change-Number: 39984 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Tue, 08 Apr 2025 18:16:31 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No
1 0
0 0
[S] Change in osmo-hnbgw[master]: Rename function s/hnbgw_decode_ranap_co/hnbgw_decode_ranap_cn_co/g
by pespin 08 Apr '25

08 Apr '25
Attention is currently required from: laforge. pespin has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-hnbgw/+/39983?usp=email ) Change subject: Rename function s/hnbgw_decode_ranap_co/hnbgw_decode_ranap_cn_co/g ...................................................................... Patch Set 1: (2 comments) File src/osmo-hnbgw/context_map_rua.c: https://gerrit.osmocom.org/c/osmo-hnbgw/+/39983/comment/df1321d5_af5483a7?u… : PS1, Line 140: hnbgw_decode_ranap_cn_co > now I'm confused. _cn_ seems to indicate from the core network. […] That's how all code in osmo-iuh is named. My understanding is that "cn" means "we decode from CN point of view". That means decoding UL traffic and transmitting DL traffic. In the HNBGW case, that means when traffic comes from RUA we are the "CN" and hence we decode UL traffic and transmit DL traffic. https://gerrit.osmocom.org/c/osmo-hnbgw/+/39983/comment/939d6a7a_4ff40868?u… : PS1, Line 148: rc = ranap_cn_rx_co_decode2(message, msgb_l2(ranap_msg), msgb_l2len(ranap_msg)); See how it matches this osmo-iuh naming. "cn". -- To view, visit https://gerrit.osmocom.org/c/osmo-hnbgw/+/39983?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-hnbgw Gerrit-Branch: master Gerrit-Change-Id: Ia4e5a21a9724ebf759b62c13759a776189b09e91 Gerrit-Change-Number: 39983 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-CC: laforge <laforge(a)osmocom.org> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Comment-Date: Tue, 08 Apr 2025 18:15:20 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: laforge <laforge(a)osmocom.org>
1 0
0 0
[L] Change in pysim[master]: pySim-smpp2sim.py: Simulate SMSC+CN+RAN+UE for OTA testing
by laforge 08 Apr '25

08 Apr '25
laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/37456?usp=email ) Change subject: pySim-smpp2sim.py: Simulate SMSC+CN+RAN+UE for OTA testing ...................................................................... pySim-smpp2sim.py: Simulate SMSC+CN+RAN+UE for OTA testing The pySim-smpp2sim.py program exposes two interfaces: * SMPP server-side port, so external programs can rx/tx SMS * APDU interface towards the SIM card It therefore emulates the SMSC, Core Network, RAND and UE parts that would normally be encountered in an OTA setup. Change-Id: Ie5bae9d823bca6f6c658bd455303f63bace2258c --- M docs/index.rst A docs/smpp2sim.rst A pySim-smpp2sim.py M pySim/cat.py M pySim/sms.py M requirements.txt M setup.py 7 files changed, 533 insertions(+), 1 deletion(-) Approvals: laforge: Looks good to me, approved Jenkins Builder: Verified diff --git a/docs/index.rst b/docs/index.rst index 1dfa624..be48ac8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -41,6 +41,7 @@ shell trace legacy + smpp2sim library osmo-smdpp sim-rest diff --git a/docs/smpp2sim.rst b/docs/smpp2sim.rst new file mode 100644 index 0000000..cd86900 --- /dev/null +++ b/docs/smpp2sim.rst @@ -0,0 +1,57 @@ +pySim-smpp2sim +============== + +This is a program to emulate the entire communication path SMSC-CN-RAN-ME +that is usually between an OTA backend and the SIM card. This allows +to play with SIM OTA technology without using a mobile network or even +a mobile phone. + +An external application can act as SMPP ESME and must encode (and +encrypt/sign) the OTA SMS and submit them via SMPP to this program, just +like it would submit it normally to a SMSC (SMS Service Centre). The +program then re-formats the SMPP-SUBMIT into a SMS DELIVER TPDU and +passes it via an ENVELOPE APDU to the SIM card that is locally inserted +into a smart card reader. + +The path from SIM to external OTA application works the opposite way. + +The default SMPP system_id is `test`. Likewise, the default SMPP +password is `test` + +Running pySim-smpp2sim +---------------------- + +The command accepts the same command line arguments for smart card interface device selection as pySim-shell, +as well as a few SMPP specific arguments: + +.. argparse:: + :module: pySim-smpp2sim + :func: option_parser + :prog: pySim-smpp2sim.py + + +Example execution with sample output +------------------------------------ + +So for a simple system with a single PC/SC device, you would typically use something like +`./pySim-smpp2sim.py -p0` to start the program. You will see output like this at start-up +:: + + Using reader PCSC[HID Global OMNIKEY 3x21 Smart Card Reader [OMNIKEY 3x21 Smart Card Reader] 00 00] + INFO root: Binding Virtual SMSC to TCP Port 2775 at :: + +The application has hence bound to local TCP port 2775 and expects your SMS-sending applications to send their +SMS there. Once you do, you will see log output like below: +:: + + WARNING smpp.twisted.protocol: SMPP connection established from ::ffff:127.0.0.1 to port 2775 + INFO smpp.twisted.server: Added CommandId.bind_transceiver bind for 'test'. Active binds: CommandId.bind_transceiver: 1, CommandId.bind_transmitter: 0, CommandId.bind_receiver: 0. Max binds: 2 + INFO smpp.twisted.protocol: Bind request succeeded for test. 1 active binds + +And once your external program is sending SMS to the simulated SMSC, it will log something like +:: + + INFO root: SMS_DELIVER(MTI=0, MMS=False, LP=False, RP=False, UDHI=True, SRI=False, OA=AddressField(TON=international, NPI=unknown, 12), PID=7f, DCS=f6, SCTS=bytearray(b'"pR\x00\x00\x00\x00'), UDL=45, UD=b"\x02p\x00\x00(\x15\x16\x19\x12\x12\xb0\x00\x01'\xfa(\xa5\xba\xc6\x9d<^\x9d\xf2\xc7\x15]\xfd\xdeD\x9c\x82k#b\x15Ve0x{0\xe8\xbe]") + SMSPPDownload(DeviceIdentities({'source_dev_id': 'network', 'dest_dev_id': 'uicc'}),Address({'ton_npi': 0, 'call_number': '0123456'}),SMS_TPDU({'tpdu': '400290217ff6227052000000002d02700000281516191212b0000127fa28a5bac69d3c5e9df2c7155dfdde449c826b236215566530787b30e8be5d'})) + INFO root: ENVELOPE: d147820283818604001032548b3b400290217ff6227052000000002d02700000281516191212b0000127fa28a5bac69d3c5e9df2c7155dfdde449c826b236215566530787b30e8be5d + INFO root: SW 9000: 027100002412b000019a551bb7c28183652de0ace6170d0e563c5e949a3ba56747fe4c1dbbef16642c diff --git a/pySim-smpp2sim.py b/pySim-smpp2sim.py new file mode 100755 index 0000000..70eb622 --- /dev/null +++ b/pySim-smpp2sim.py @@ -0,0 +1,428 @@ +#!/usr/bin/env python3 +# +# Program to emulate the entire communication path SMSC-MSC-BSC-BTS-ME +# that is usually between an OTA backend and the SIM card. This allows +# to play with SIM OTA technology without using a mobile network or even +# a mobile phone. +# +# An external application must encode (and encrypt/sign) the OTA SMS +# and submit them via SMPP to this program, just like it would submit +# it normally to a SMSC (SMS Service Centre). The program then re-formats +# the SMPP-SUBMIT into a SMS DELIVER TPDU and passes it via an ENVELOPE +# APDU to the SIM card that is locally inserted into a smart card reader. +# +# The path from SIM to external OTA application works the opposite way. + +# (C) 2023-2024 by Harald Welte <laforge(a)osmocom.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import argparse +import logging +import colorlog + +from twisted.protocols import basic +from twisted.internet import defer, endpoints, protocol, reactor, task +from twisted.cred.portal import IRealm +from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse +from twisted.cred.portal import Portal +from zope.interface import implementer + +from smpp.twisted.config import SMPPServerConfig +from smpp.twisted.server import SMPPServerFactory, SMPPBindManager +from smpp.twisted.protocol import SMPPSessionStates, DataHandlerResponse + +from smpp.pdu import pdu_types, operations, pdu_encoding + +from pySim.sms import SMS_DELIVER, SMS_SUBMIT, AddressField + +from pySim.transport import LinkBase, ProactiveHandler, argparse_add_reader_args, init_reader, ApduTracer +from pySim.commands import SimCardCommands +from pySim.cards import UiccCardBase +from pySim.exceptions import * +from pySim.cat import ProactiveCommand, SendShortMessage, SMS_TPDU, SMSPPDownload, BearerDescription +from pySim.cat import DeviceIdentities, Address, OtherAddress, UiccTransportLevel, BufferSize +from pySim.cat import ChannelStatus, ChannelData, ChannelDataLength +from pySim.utils import b2h, h2b + +logger = logging.getLogger(__name__) + +# MSISDNs to use when generating proactive SMS messages +SIM_MSISDN='23' +ESME_MSISDN='12' + +# HACK: we need some kind of mapping table between system_id and card-reader +# or actually route based on MSISDNs +hackish_global_smpp = None + +class MyApduTracer(ApduTracer): + def trace_response(self, cmd, sw, resp): + print("-> %s %s" % (cmd[:10], cmd[10:])) + print("<- %s: %s" % (sw, resp)) + +class TcpProtocol(protocol.Protocol): + def dataReceived(self, data): + pass + + def connectionLost(self, reason): + pass + + +def tcp_connected_callback(p: protocol.Protocol): + """called by twisted TCP client.""" + logger.error("%s: connected!" % p) + +class ProactChannel: + """Representation of a single proective channel.""" + def __init__(self, channels: 'ProactChannels', chan_nr: int): + self.channels = channels + self.chan_nr = chan_nr + self.ep = None + + def close(self): + """Close the channel.""" + if self.ep: + self.ep.disconnect() + self.channels.channel_delete(self.chan_nr) + +class ProactChannels: + """Wrapper class for maintaining state of proactive channels.""" + def __init__(self): + self.channels = {} + + def channel_create(self) -> ProactChannel: + """Create a new proactive channel, allocating its integer number.""" + for i in range(1, 9): + if not i in self.channels: + self.channels[i] = ProactChannel(self, i) + return self.channels[i] + raise ValueError('Cannot allocate another channel: All channels active') + + def channel_delete(self, chan_nr: int): + del self.channels[chan_nr] + +class Proact(ProactiveHandler): + #def __init__(self, smpp_factory): + # self.smpp_factory = smpp_factory + def __init__(self): + self.channels = ProactChannels() + + @staticmethod + def _find_first_element_of_type(instlist, cls): + for i in instlist: + if isinstance(i, cls): + return i + return None + + """Call-back which the pySim transport core calls whenever it receives a + proactive command from the SIM.""" + def handle_SendShortMessage(self, pcmd: ProactiveCommand): + # {'smspp_download': [{'device_identities': {'source_dev_id': 'network', + # 'dest_dev_id': 'uicc'}}, + # {'address': {'ton_npi': {'ext': True, + # 'type_of_number': 'international', + # 'numbering_plan_id': 'isdn_e164'}, + # 'call_number': '79'}}, + # {'sms_tpdu': {'tpdu': '40048111227ff6407070611535004d02700000481516011212000001fe4c0943aea42e45021c078ae06c66afc09303608874b72f58bacadb0dcf665c29349c799fbb522e61709c9baf1890015e8e8e196e36153106c8b92f95153774'}} + # ]} + """Card requests sending a SMS. We need to pass it on to the ESME via SMPP.""" + logger.info("SendShortMessage") + logger.info(pcmd) + # Relevant parts in pcmd: Address, SMS_TPDU + addr_ie = Proact._find_first_element_of_type(pcmd.children, Address) + sms_tpdu_ie = Proact._find_first_element_of_type(pcmd.children, SMS_TPDU) + raw_tpdu = sms_tpdu_ie.decoded['tpdu'] + submit = SMS_SUBMIT.from_bytes(raw_tpdu) + submit.tp_da = AddressField(addr_ie.decoded['call_number'], addr_ie.decoded['ton_npi']['type_of_number'], + addr_ie.decoded['ton_npi']['numbering_plan_id']) + logger.info(submit) + self.send_sms_via_smpp(submit) + + def handle_OpenChannel(self, pcmd: ProactiveCommand): + """Card requests opening a new channel via a UDP/TCP socket.""" + # {'open_channel': [{'command_details': {'command_number': 1, + # 'type_of_command': 'open_channel', + # 'command_qualifier': 3}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'terminal'}}, + # {'bearer_description': {'bearer_type': 'default', + # 'bearer_parameters': ''}}, + # {'buffer_size': 1024}, + # {'uicc_transport_level': {'protocol_type': 'tcp_uicc_client_remote', + # 'port_number': 32768}}, + # {'other_address': {'type_of_address': 'ipv4', + # 'address': '01020304'}} + # ]} + logger.info("OpenChannel") + logger.info(pcmd) + transp_lvl_ie = Proact._find_first_element_of_type(pcmd.children, UiccTransportLevel) + other_addr_ie = Proact._find_first_element_of_type(pcmd.children, OtherAddress) + bearer_desc_ie = Proact._find_first_element_of_type(pcmd.children, BearerDescription) + buffer_size_ie = Proact._find_first_element_of_type(pcmd.children, BufferSize) + if transp_lvl_ie.decoded['protocol_type'] != 'tcp_uicc_client_remote': + raise ValueError('Unsupported protocol_type') + if other_addr_ie.decoded.get('type_of_address', None) != 'ipv4': + raise ValueError('Unsupported type_of_address') + ipv4_bytes = h2b(other_addr_ie.decoded['address']) + ipv4_str = '%u.%u.%u.%u' % (ipv4_bytes[0], ipv4_bytes[1], ipv4_bytes[2], ipv4_bytes[3]) + port_nr = transp_lvl_ie.decoded['port_number'] + print("%s:%u" % (ipv4_str, port_nr)) + channel = self.channels.channel_create() + channel.ep = endpoints.TCP4ClientEndpoint(reactor, ipv4_str, port_nr) + channel.prot = TcpProtocol() + d = endpoints.connectProtocol(channel.ep, channel.prot) + # FIXME: why is this never called despite the client showing the inbound connection? + d.addCallback(tcp_connected_callback) + + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'open_channel', + # 'command_qualifier': 3}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_status': '8100'}, + # {'bearer_description': {'bearer_type': 'default', 'bearer_parameters': ''}}, + # {'buffer_size': 1024} + # ] + return self.prepare_response(pcmd) + [ChannelStatus(decoded='8100'), bearer_desc_ie, buffer_size_ie] + + def handle_CloseChannel(self, pcmd: ProactiveCommand): + """Close a channel.""" + logger.info("CloseChannel") + logger.info(pcmd) + + def handle_ReceiveData(self, pcmd: ProactiveCommand): + """Receive/read data from the socket.""" + # {'receive_data': [{'command_details': {'command_number': 1, + # 'type_of_command': 'receive_data', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'channel_1'}}, + # {'channel_data_length': 9} + # ]} + logger.info("ReceiveData") + logger.info(pcmd) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'receive_data', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_data': '16030100040e000000'}, + # {'channel_data_length': 0} + # ] + return self.prepare_response(pcmd) + [] + + def handle_SendData(self, pcmd: ProactiveCommand): + """Send/write data received from the SIM to the socket.""" + # {'send_data': [{'command_details': {'command_number': 1, + # 'type_of_command': 'send_data', + # 'command_qualifier': 1}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'channel_1'}}, + # {'channel_data': '160301003c010000380303d0f45e12b52ce5bb522750dd037738195334c87a46a847fe2b6886cada9ea6bf00000a00ae008c008b00b0002c010000050001000101'} + # ]} + logger.info("SendData") + logger.info(pcmd) + dev_id_ie = Proact._find_first_element_of_type(pcmd.children, DeviceIdentities) + chan_data_ie = Proact._find_first_element_of_type(pcmd.children, ChannelData) + chan_str = dev_id_ie.decoded['dest_dev_id'] + chan_nr = 1 # FIXME + chan = self.channels.channels.get(chan_nr, None) + # FIXME chan.prot.transport.write(h2b(chan_data_ie.decoded)) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'send_data', + # 'command_qualifier': 1}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}}, + # {'channel_data_length': 255} + # ] + return self.prepare_response(pcmd) + [ChannelDataLength(decoded=255)] + + def handle_SetUpEventList(self, pcmd: ProactiveCommand): + # {'set_up_event_list': [{'command_details': {'command_number': 1, + # 'type_of_command': 'set_up_event_list', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'uicc', + # 'dest_dev_id': 'terminal'}}, + # {'event_list': ['data_available', 'channel_status']} + # ]} + logger.info("SetUpEventList") + logger.info(pcmd) + # Terminal Response example: [ + # {'command_details': {'command_number': 1, + # 'type_of_command': 'set_up_event_list', + # 'command_qualifier': 0}}, + # {'device_identities': {'source_dev_id': 'terminal', 'dest_dev_id': 'uicc'}}, + # {'result': {'general_result': 'performed_successfully', 'additional_information': ''}} + # ] + return self.prepare_response(pcmd) + + def getChannelStatus(self, pcmd: ProactiveCommand): + logger.info("GetChannelStatus") + logger.info(pcmd) + return self.prepare_response(pcmd) + [] + + def send_sms_via_smpp(self, submit: SMS_SUBMIT): + # while in a normal network the phone/ME would *submit* a message to the SMSC, + # we are actually emulating the SMSC itself, so we must *deliver* the message + # to the ESME + deliver = SMS_DELIVER.from_submit(submit) + deliver_smpp = deliver.to_smpp() + + hackish_global_smpp.sendDataRequest(deliver_smpp) +# # obtain the connection/binding of system_id to be used for delivering MO-SMS to the ESME +# connection = smpp_server.getBoundConnections[system_id].getNextBindingForDelivery() +# connection.sendDataRequest(deliver_smpp) + + + +def dcs_is_8bit(dcs): + if dcs == pdu_types.DataCoding(pdu_types.DataCodingScheme.DEFAULT, + pdu_types.DataCodingDefault.OCTET_UNSPECIFIED): + return True + if dcs == pdu_types.DataCoding(pdu_types.DataCodingScheme.DEFAULT, + pdu_types.DataCodingDefault.OCTET_UNSPECIFIED_COMMON): + return True + # pySim-smpp2sim.py:150:21: E1101: Instance of 'DataCodingScheme' has no 'GSM_MESSAGE_CLASS' member (no-member) + # pylint: disable=no-member + if dcs.scheme == pdu_types.DataCodingScheme.GSM_MESSAGE_CLASS and dcs.schemeData['msgCoding'] == pdu_types.DataCodingGsmMsgCoding.DATA_8BIT: + return True + else: + return False + + +class MyServer: + + @implementer(IRealm) + class SmppRealm: + def requestAvatar(self, avatarId, mind, *interfaces): + return ('SMPP', avatarId, lambda: None) + + def __init__(self, tcp_port:int = 2775, bind_ip = '::', system_id:str = 'test', password:str = 'test'): + smpp_config = SMPPServerConfig(msgHandler=self._msgHandler, + systems={system_id: {'max_bindings': 2}}) + portal = Portal(self.SmppRealm()) + credential_checker = InMemoryUsernamePasswordDatabaseDontUse() + credential_checker.addUser(system_id, password) + portal.registerChecker(credential_checker) + self.factory = SMPPServerFactory(smpp_config, auth_portal=portal) + logger.info('Binding Virtual SMSC to TCP Port %u at %s' % (tcp_port, bind_ip)) + smppEndpoint = endpoints.TCP6ServerEndpoint(reactor, tcp_port, interface=bind_ip) + smppEndpoint.listen(self.factory) + self.tp = self.scc = self.card = None + + def connect_to_card(self, tp: LinkBase): + self.tp = tp + self.scc = SimCardCommands(self.tp) + self.card = UiccCardBase(self.scc) + # this should be part of UiccCardBase, but FairewavesSIM breaks with that :/ + self.scc.cla_byte = "00" + self.scc.sel_ctrl = "0004" + self.card.read_aids() + self.card.select_adf_by_aid(adf='usim') + # FIXME: create a more realistic profile than ffffff + self.scc.terminal_profile('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') + + def _msgHandler(self, system_id, smpp, pdu): + """Handler for incoming messages received via SMPP from ESME.""" + # HACK: we need some kind of mapping table between system_id and card-reader + # or actually route based on MSISDNs + global hackish_global_smpp + hackish_global_smpp = smpp + if pdu.id == pdu_types.CommandId.submit_sm: + return self.handle_submit_sm(system_id, smpp, pdu) + else: + logger.warning('Rejecting non-SUBMIT commandID') + return pdu_types.CommandStatus.ESME_RINVCMDID + + def handle_submit_sm(self, system_id, smpp, pdu): + """SUBMIT-SM was received via SMPP from ESME. We need to deliver it to the SIM.""" + # check for valid data coding scheme + PID + if not dcs_is_8bit(pdu.params['data_coding']): + logger.warning('Rejecting non-8bit DCS') + return pdu_types.CommandStatus.ESME_RINVDCS + if pdu.params['protocol_id'] != 0x7f: + logger.warning('Rejecting non-SIM PID') + return pdu_types.CommandStatus.ESME_RINVDCS + + # 1) build a SMS-DELIVER (!) from the SMPP-SUBMIT + tpdu = SMS_DELIVER.from_smpp_submit(pdu) + logger.info(tpdu) + # 2) wrap into the CAT ENVELOPE for SMS-PP-Download + tpdu_ie = SMS_TPDU(decoded={'tpdu': b2h(tpdu.to_bytes())}) + addr_ie = Address(decoded={'ton_npi': {'ext':False, 'type_of_number':'unknown', 'numbering_plan_id':'unknown'}, 'call_number': '0123456'}) + dev_ids = DeviceIdentities(decoded={'source_dev_id': 'network', 'dest_dev_id': 'uicc'}) + sms_dl = SMSPPDownload(children=[dev_ids, addr_ie, tpdu_ie]) + # 3) send to the card + envelope_hex = b2h(sms_dl.to_tlv()) + logger.info("ENVELOPE: %s" % envelope_hex) + (data, sw) = self.scc.envelope(envelope_hex) + logger.info("SW %s: %s" % (sw, data)) + if sw in ['9200', '9300']: + # TODO send back RP-ERROR message with TP-FCS == 'SIM Application Toolkit Busy' + return pdu_types.CommandStatus.ESME_RSUBMITFAIL + elif sw == '9000' or sw[0:2] in ['6f', '62', '63'] and len(data): + # data something like 027100000e0ab000110000000000000001612f or + # 027100001c12b000119660ebdb81be189b5e4389e9e7ab2bc0954f963ad869ed7c + # which is the user-data portion of the SMS starting with the UDH (027100) + # TODO: return the response back to the sender in an RP-ACK; PID/DCS like in CMD + deliver = operations.DeliverSM(service_type=pdu.params['service_type'], + source_addr_ton=pdu.params['dest_addr_ton'], + source_addr_npi=pdu.params['dest_addr_npi'], + source_addr=pdu.params['destination_addr'], + dest_addr_ton=pdu.params['source_addr_ton'], + dest_addr_npi=pdu.params['source_addr_npi'], + destination_addr=pdu.params['source_addr'], + esm_class=pdu.params['esm_class'], + protocol_id=pdu.params['protocol_id'], + priority_flag=pdu.params['priority_flag'], + data_coding=pdu.params['data_coding'], + short_message=h2b(data)) + smpp.sendDataRequest(deliver) + return pdu_types.CommandStatus.ESME_ROK + else: + return pdu_types.CommandStatus.ESME_RSUBMITFAIL + + +option_parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +argparse_add_reader_args(option_parser) +smpp_group = option_parser.add_argument_group('SMPP Options') +smpp_group.add_argument('--smpp-bind-port', type=int, default=2775, + help='TCP Port to bind the SMPP socket to') +smpp_group.add_argument('--smpp-bind-ip', default='::', + help='IPv4/IPv6 address to bind the SMPP socket to') +smpp_group.add_argument('--smpp-system-id', default='test', + help='SMPP System-ID used by ESME to bind') +smpp_group.add_argument('--smpp-password', default='test', + help='SMPP Password used by ESME to bind') + +if __name__ == '__main__': + log_format='%(log_color)s%(levelname)-8s%(reset)s %(name)s: %(message)s' + colorlog.basicConfig(level=logging.INFO, format = log_format) + logger = colorlog.getLogger() + + opts = option_parser.parse_args() + + tp = init_reader(opts, proactive_handler = Proact()) + if tp is None: + exit(1) + tp.connect() + + global g_ms + g_ms = MyServer(opts.smpp_bind_port, opts.smpp_bind_ip, opts.smpp_system_id, opts.smpp_password) + g_ms.connect_to_card(tp) + reactor.run() + diff --git a/pySim/cat.py b/pySim/cat.py index fae5fbf..448d874 100644 --- a/pySim/cat.py +++ b/pySim/cat.py @@ -32,7 +32,7 @@ # TS 102 223 Section 8.1 class Address(COMPR_TLV_IE, tag=0x86): - _construct = Struct('ton_npi'/Int8ub, + _construct = Struct('ton_npi'/TonNpi, 'call_number'/BcdAdapter(GreedyBytes)) # TS 102 223 Section 8.2 diff --git a/pySim/sms.py b/pySim/sms.py index df835e4..7e5acf1 100644 --- a/pySim/sms.py +++ b/pySim/sms.py @@ -253,6 +253,49 @@ } return cls(**d) + @classmethod + def from_submit(cls, submit: 'SMS_SUBMIT') -> 'SMS_DELIVER': + """Construct a SMS_DELIVER instance from a SMS_SUBMIT instance.""" + d = { + # common fields (SMS_TPDU base class) which exist in submit, so we can copy them + 'tp_mti': submit.tp_mti, + 'tp_rp': submit.tp_rp, + 'tp_udhi': submit.tp_udhi, + 'tp_pid': submit.tp_pid, + 'tp_dcs': submit.tp_dcs, + 'tp_udl': submit.tp_udl, + 'tp_ud': submit.tp_ud, + # SMS_DELIVER specific fields + 'tp_lp': False, + 'tp_mms': False, + 'tp_oa': None, + 'tp_scts': h2b('22705200000000'), # FIXME + 'tp_sri': False, + } + return cls(**d) + + def to_smpp(self) -> pdu_types.PDU: + """Translate a SMS_DELIVER instance to a smpp.pdu.operations.DeliverSM instance.""" + # we only deal with binary SMS here: + if self.tp_dcs != 0xF6: + raise ValueError('Unsupported DCS: We only support DCS=0xF6 for now') + dcs = pdu_types.DataCoding(pdu_types.DataCodingScheme.DEFAULT, + pdu_types.DataCodingDefault.OCTET_UNSPECIFIED) + esm_class = pdu_types.EsmClass(pdu_types.EsmClassMode.DEFAULT, pdu_types.EsmClassType.DEFAULT, + gsmFeatures=[pdu_types.EsmClassGsmFeatures.UDHI_INDICATOR_SET]) + if self.tp_oa: + oa_digits, oa_ton, oa_npi = self.tp_oa.to_smpp() + else: + oa_digits, oa_ton, oa_npi = None, None, None + return operations.DeliverSM(source_addr=oa_digits, + source_addr_ton=oa_ton, + source_addr_npi=oa_npi, + #destination_addr=ESME_MSISDN, + esm_class=esm_class, + protocol_id=self.tp_pid, + data_coding=dcs, + short_message=self.tp_ud) + class SMS_SUBMIT(SMS_TPDU): diff --git a/requirements.txt b/requirements.txt index 16fa886..11170da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ git+https://github.com/osmocom/asn1tools packaging git+https://github.com/hologram-io/smpp.pdu +smpp.twisted3 @ git+https://github.com/jookies/smpp.twisted diff --git a/setup.py b/setup.py index c982ce0..bf9299c 100644 --- a/setup.py +++ b/setup.py @@ -33,12 +33,14 @@ "packaging", "smpp.pdu @ git+https://github.com/hologram-io/smpp.pdu", "asn1tools", + "smpp.twisted3 @ git+https://github.com/jookies/smpp.twisted", ], scripts=[ 'pySim-prog.py', 'pySim-read.py', 'pySim-shell.py', 'pySim-trace.py', + 'pySim-smpp2sim.py', ], package_data={ 'pySim.esim': -- To view, visit https://gerrit.osmocom.org/c/pysim/+/37456?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ie5bae9d823bca6f6c658bd455303f63bace2258c Gerrit-Change-Number: 37456 Gerrit-PatchSet: 10 Gerrit-Owner: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de> Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: osmith <osmith(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • ...
  • 119
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.