434 Commits

Author SHA1 Message Date
Pau Espin Pedrol
1fd205f0b8 ranap: Take into account RNC availability during paging
Avoid transmitting a RANAP paging message to an RNC if we already know
it's not currently available over SCCP.
Take into account that information when deciding/printing whether the
paging could be sent or not.

Take the chance to clean up the iu paging function helpers inherited
from osmo-iuh iu_client.c to better fit the data domain in osmo-sgsn
(iu_rnc).

Change-Id: I24e5446bcf4c958028577230b231960acea9e5b9
2025-09-02 18:55:03 +02:00
Pau Espin Pedrol
b062c3647e stats: Introduce stats sgsn.iu_peers.{total,active}
Change-Id: I51b5227d92027f1251dc4debbbf59737e7c1a9ba
2025-09-02 18:55:03 +02:00
Pau Espin Pedrol
d6c29beaf3 Introduce iu_rnc FSM
This FSM is similar to the already existing ran_peer_fsm in osmo-msc,
which already had better logic around SCCP and RANAP state handling.
Similarly, osmo-sgsn's struct ranap_iu_rnc maps to osmo-msc's struct ran_peer.

With this FSM we can currently track the RANAP link state towards a given
RNC peer:
* Reject (RANAP Error Indication) all UE-related messages until a RANAP
  RESET from RNC is received first.
* Tear down all subsriber connections whenever the RANAP peer sends us a
  RESET message.
* Tear down all subscriber connections whenever the SCCP link towards
  RNC becomes unavailable.
* Send a RESET towards RNC peer once the SCCP link towrdards it becomes
  available again.

This commit only implements so far the Rx path of the FSM, ie. when
receiving events/messages from a peer over SCCP and pushing them locally
up the stack (RANAP). The Tx side will be implemented in a follow-up
commit, which will allow discarding messages if the lower layers towards
a given RNC are known to be down.

Related: OS#3403
Change-Id: I18b7803500163e78ff6a684095194174b0fb6ee1
2025-09-02 18:55:03 +02:00
Pau Espin Pedrol
a24ebc7051 iu_rnc: Introduce helper API iu_rnc_discard_all_ue_ctx()
This is a preparation commit to introduce iu_rnc_fsm in follow-up patch.
The helper API will be used whenever the entire RNC is considered reset.

* Code inside handle_notice_ind() is moved to its own function
  iu_rnc_discard_all_ue_ctx().
* Dependent helper ue_ctx_link_invalidated_free() API is properly
  prefixed/renamed to ue_conn_ctx_link_invalidated_free(), where methods
  for ue_conn_ctx object are placed.
* ue_conn_ctx_find() is properly prefixed/renamed to
  sgsn_scu_iups_ue_conn_ctx_find() and made available to functions in
  other files.

Change-Id: Ie3a4732a85a69d115dd5756bfa64b296e9e5edd2
2025-09-02 18:55:02 +02:00
Pau Espin Pedrol
611b32811e Store scu_iups in iu_rnc instead of ue_ctx
All the ue_ctx belong to a given peer RNC, which holds the SCCP User to
talk to it.

Change-Id: I3969af765b7b0d1375b5e6ad8f3f2e9845f939ef
2025-09-02 18:53:17 +02:00
Pau Espin Pedrol
b9c9271a1f ranap: Improve error handling in Rx RESET
* Verify the CN Indicator is set to PS to avoid reacting on content from
  unexpected peers (eg. IuCS). If none is set, be permissive on rx and
  assume PS.

* If GlobalRNC-ID IE is missing, reject the RESET with an Error
  Indication towards the peer to notify about the rejection.
  Same if we couldn't decode properly it.

* Introduce Tx helpers for generic SCCP UNITDATA.req and RANAP Error
  Indication helpers to simplify code and avoid duplication.

Depends: osmo-iuh.git Change-Id I58c75b3e0e0f33f48d077385ffac820a6b2be59e
Change-Id: I2a53e10c3903992a42d081e3ec300fbdb9b3c34c
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
dfcb514076 iu_rnc: Split iu_rnc_register API into 2 steps
Split lookup+allocation from RAI updating.
This will be needed once we start creating iu_rnc objects upon SCCP
rx RANAP RESET messages, which hold Global RNC-ID but no RAI
information.

Change-Id: I3761cc539c63a7ed680b04bb8136a43d397c10aa
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
ecaa198fa0 Apply uniform prefix to remaining APIs in gprs_ranap.h
Change-Id: I4f253f35013085bdebf80e94ab0d2f771e40dba6
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
eb5959f6b9 Split Iu RANAP conn release over different layers
Move and rename functions acting on mmctx to mmctx.{c,h}.
From there, call functions acting on ranap ue_ctx.

Change-Id: I4acdbc857df36b7409c8210d364758192dfdb0bb
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
c1f2de5790 Split Iu RANAP RAB PS act/deact over different layers
Properly separate logic acting on objects vs logic building and
generating RANAP msg on the wire.

Change-Id: I98788468b7e50619cfd99b3aef2311bb601fb6be
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
a0203ce7ff ranap: Clean up RANAP rx path param passing
Use the osmo-iuh ranap_cn_rx_*_decode2() APIs directly. This
allows getting rid of extra "ctx" temporary structs and another level of
cb indirection.

Take the chance to update most pointers consitfying them.

Depends: osmo-iuh.git Change-Id I667dc2ef377c1ceb5b11315458f00b282c143c81
Change-Id: Ib3c00b5105b7ba4bb1a2dad1a14bea233a03c358
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
20d032bdd2 iu_rnc: Constify function params
Change-Id: I288bc21d24aa5abd3d9bd97e796ac9f8590290bd
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
203676d047 sccp: Introduce helper func sgsn_scu_iups_tx_data_req()
This avoid code deduplication plus moving SCCP SAP logic into sccp.c.

Change-Id: Id34f86b4f5e40ddceac4066ec18ebc60529cafab
2025-09-02 18:51:43 +02:00
Pau Espin Pedrol
265bc33b05 Split most of iu_client.{c,h} into sccp.{c,h} and iu_rnc.{c,h}
* iu_rnc is easily spotted as an object class in the data domain which
  can be put into its own file, handling its specific logic and data.

* SCCP code can also be moved into own specific file, which eases
  self-containment of the layer logic and data.

* As a result, lots of RANAP Rx/Tx code in iu_client.{c,h} can also be
  moved to the already existing gprs_ranap.{c,h}.

All these changes improve a lot readibility of code and makes it a lot
easier to improve/extend the different layers/objects in future patches.

Change-Id: I4c792ae665720460b5a954b5c7cbfe5acbc37473
2025-09-02 18:51:08 +02:00
Pau Espin Pedrol
77cf72ea91 Move gsm0408_gprs_rcvmsg_iu to gprs_gmm.{c,h}
It belongs to that layer, same as existing gsm0408_gprs_rcvmsg_gb()
counterpart.

Change-Id: I09c19689fd7016b76ebeee821b551427965b7cf1
2025-08-27 14:44:34 +02:00
Pau Espin Pedrol
ad61ccd07b debug.h: Remove unused log category DIUCS
It's used nowhere, not even defined in the initialization array of
categories, because IuCS has no place in SGSN.

Change-Id: I0f7c6bedaf3b7f909c3e27175ca99967492ab7c3
2025-08-26 17:51:43 +02:00
Alexander Couzens
02fbdb59c2 Re-introduce Iu/UTRAN support
Add support for UTRAN routing areas.

Change-Id: I1b1aedd2a7c358bd388aa3d8a9f3c6a0011b4889
2025-08-21 23:08:52 +02:00
Alexander Couzens
b1444a6c11 [4/4] iu_client: start using adopted iu_client
Use internal headers.
Use renamed event names/types.

Change-Id: I7c99ad0498c6f885361562c54fcf0ebdc086616b
2025-08-21 18:40:49 +02:00
Alexander Couzens
6534fdbf27 [2/4] iu_client: rename symbols to prevent clashes with libosmo-ranap
While moving the iu_client into osmoSGSN, it's not allowed to have
the same global symbols in the library as in osmoSGSN.

Change-Id: I2af29b38f110b80f69ef598c8e2700ff323a9d7c
2025-08-21 18:10:25 +02:00
Alexander Couzens
2d4fe639cc [1/4] Adopt iu_client from osmo-iuh
iu_client was original written to have an abstraction
for Iu. However the MSC stopped using iu_client a long
time ago because the abstraption didn't fit well.
There was never time to rewrite SGSN to direct talk RANAP
using the primitives.
Adopt iu_client for now, but with the plan to rewrite
it in a similar way as osmo-msc is doing IuCS.

Adopted from osmo-iuh:
1631c8ac5a2f ("iu_client: fix linter issues")
Related: OS#5487

Change-Id: I9c0d9667ddcb57b52eae34da942acfc1688c1418
2025-08-21 18:10:21 +02:00
Alexander Couzens
4ba6638840 routing area: prefix GERAN functions with geran
Make it easier to understand the purpose
of the functions.

Change-Id: Ic616bd8f9afe6cd3702cd4af08706b7b36987f42
2025-08-06 15:00:40 +02:00
Alexander Couzens
bae75b9a60 BSSGP: reset cells when receiving a Reset on Signal BVC
When a PCU sends a BVC Reset over BSSGP on the Signal BVC,
all cells which has been set up previously via PtP BVCs
has to be removed.

They might be introduced after the Signal BVC reset procedure
has finished.

Change-Id: I380c8f9ef90d8c7face5c380d923ab5168f5b484
2025-08-06 14:46:34 +02:00
Alexander Couzens
2422c0375b routing area: sgsn_ra_geran_page_ra: make argument rai const
The second argument mmctx can't made const because of the paging info,
which uses non-const fields.

Change-Id: I21d7e66e433f2b891c94bae91697aa46198fb20c
2025-08-01 17:44:33 +02:00
Alexander Couzens
fec2e5884a routing area: add LOGRA() logging macro
Prepend the routing area in the log message.

Change-Id: Ib287b70c34b21ce64bc864f69fcf6af5fa0698b9
2025-08-01 17:44:33 +02:00
Alexander Couzens
4b894f1a85 routing area: introduce sgsn_ra_find_or_create()
If the RA is the same, return the RA, but if the ran type is different,
return NULL instead of allocating a second RA in the other
RAT.

Change-Id: I6955a09d9d8f3ba4dc3a14d7ed5cd9798d929c61
2025-08-01 17:43:57 +02:00
Alexander Couzens
328edfd6f8 routing area: move cell.cell_id behind a geran union
To prepare for Iu support, use the SGSN RA cell for both,
a GERAN Cell and a UTRAN Service Area.

Change-Id: I0c24d98dd699748842dca271b93e58d27cf02285
2025-08-01 14:27:43 +02:00
Alexander Couzens
9eb1f7e006 use variable name rai for struct osmo_routing_area_id
Be consistent with variable naming if a single
`struct osmo_routing_area_id *` area id is used.

Change-Id: I946983d4857035e06c68af378654466b35025014
2025-08-01 14:25:48 +02:00
Alexander Couzens
f34503289e routing area: introduce ran_type on the RA
A Routing Area should be uniquely identified by the RAI.
Following this, it is forbidden to have a RAI which is valid
in both, GERAN and UTRAN.

Change-Id: I59c35f1a4912ff11574bb31e4fe424816993548c
2025-08-01 14:25:16 +02:00
Alexander Couzens
234da0eed4 mmctx: LOGIUP: allow ue to be NULL
In certain cases, the ue can be NULL.
E.g. when receiving a new Iu event without a context.

Change-Id: Ie569fa100abe518cb63c1b918ad7748a7ea3bb99
2025-07-17 11:41:35 +02:00
Alexander Couzens
901ca02e0e Assign MME GroupId/Code to remote MMEs
In preparation to route SGSN Context Req/Resp/Ack the SGSN
need to route GTP messages based on the MME GroupId and MME Code.

Change-Id: I881aeba904fb6ca815842d36e466a2459ad81913
2025-02-17 23:13:42 +01:00
Alexander Couzens
27dd6d84ec gprs_gmm_util: add parsing of GMM Attach Requests
This will be used in the following commit.

Change-Id: I4a82e0c4070da982efd6c2f15fd145393423772b
2025-01-31 16:43:43 +01:00
Alexander Couzens
921af3d428 Refactor mmctx_is_r99 into mmctx.c
It is related to the mmctx and should be in mmctx.c instead
of the GMM message parsing or handling.

Change-Id: I198a3c9d49667c70e8995808b3fcb5ea26e8f17a
2025-01-28 00:17:15 +01:00
Alexander Couzens
5b289e83cf GMM: split parsing of a RA Update Request in a separate file
gprs_gmm.c is huge. Further split the general validation
and parsing of the message into an own function.

Change-Id: I413da1b6b4b7c0c4781393acd8564661bc74ce2d
2024-10-22 10:25:51 +02:00
Alexander Couzens
8a2ed97336 move gsm48_gmm_att_tlvdef into gprs_gmm_util
The gprs_gmm.c is huge. Move message parsing into gprs_gmm_util.c.

Change-Id: I67dcdb986fd01dc093501d324b5c376246a5d30d
2024-10-22 10:25:49 +02:00
Alexander Couzens
72283a1686 Refactor diffing same GMM messages
gprs_gmm_attach_req_ies() isn't specific for the attach request.
It also did not cover the full message because of a fixed message length
when comparing both messages.

A diff of the old and new GMM message is required to figure out
if the MS/UE is retransmitting an old message or starting
a new procedure.

Change-Id: Ie698d3a6894a5796663c22c8bfd12b47acda57e6
2024-10-21 20:53:52 +02:00
Alexander Couzens
e7303adc8d Implement correct Routing Area based paging
Previous the SGSN would not support multiple BSS within the
same routing area.
Add support paging of a whole routing area.

Change-Id: I181da9f656e394ccfcb8999021a5b7e13ca0419f
2024-10-21 20:53:52 +02:00
Alexander Couzens
e8c82d9cd1 Add Routing Areas
Add a routing area layer which tracks routing area and
cells within a routing area.

Change-Id: I2474b19a7471a1dea3c863ddf8372b16180211aa
2024-10-21 20:53:52 +02:00
Alexander Couzens
12ed86d17a Replace gprs_ra_id with modern osmo_routing_area_id
The new modern osmo_routing_area_id is more flexible
and allow to access PLMN, LAC more convient.

Depends: Iaef54cac541913534af00f40483723e9952a6807 (libosmocore)
Change-Id: Ia41eb8f51d3836b1bc65325ff1ec6bdb16e20c7e
2024-08-20 14:08:14 +02:00
Pau Espin Pedrol
868d818e6e Fix double free during RAU with unexpected Old RAI
If an MS which had an MMCTX at the SGSN sent RAU update with an
unexpected Old RA field, the RAU was rejected and LLME (LLC layer)
unassigned (freed), because no MMCTX was found matching the wrong old
RA.
However, an MMCTX may actually exist pointing to that LLME, and hence
when the LLME is freed, it stayed unnoticed with a dangling pointer to
the freed LLME in ctx->gb.llme.
Let's try to harder to avoid this kind of bugs which make osmo-sgsn
crash.

Once we properly split the code into separate independent layers (LLC,
MMCTX, etc.) each holding their own structs, this kind of bugs shouldn't
happen anymore.

Related: OS#6441
Change-Id: I5a4328c6e945b85dd815215724feecadba59c435
2024-08-19 18:20:53 +02:00
Alexander Couzens
9650961c4b includes: add forward declartion of external types
Change-Id: Ifbf0a045a6391694155f6627967f2d92b930d765
2024-08-04 19:52:35 +02:00
Alexander Couzens
c05dad1035 includes: sgsn.h: use full path include for gtp.h
The gtp header of ggsn have been moved to osmocom/gtp/gtp.h for a while.
Use the full path to prevent clashs with older versions

Change-Id: I764644110c0f332b18117e1e8311ddc55eafd5fa
2024-08-04 17:44:37 +02:00
Pau Espin Pedrol
7d5337fe80 Handle rx UpdatePDPCtxReq with Tunnel Direct Flags EI=1
GGSN informed us that it received an Error Indication when sending DL data to the RNC.
This probably means the RNC lost its state, aka crashed or was rebooted.
Mark the subscriber as PMM-IDLE, release Iu and point GTPU back to SGSN.
Then page the UE so it hopefully re-creates the state at the RNC.

Related: OS#6512
Related: OS#6519
Related: SYS#5435
Depends: osmo-ggsn.git Change-Id Ic80a9a928c55b6ff85be96014920bb42793cb943
Change-Id: I76d4c387730fdbfb9e7e0dd23a5afb9e762228b1
2024-08-01 11:39:00 +02:00
Pau Espin Pedrol
2cd06e28f4 Announce SGSN own TEID during UpdatePDPCtxReq after UE goes PMM-IDLE
When the UE/RNC closes the Iu conn (while keeping the PDP Context
activated), the SGSN updates the GGSN to point the GTPU tunnel to
itself. Unfortunately, only the IP address was being updated while the
TEID was kept the same (the one from the RNC).

As a result, when new MT data arrived at the GGSN, it would forward it
over GTPU to the SGSN using the incorrect RNC TEID, which the libgtp
stack at osmo-sgsn would silently drop due to not being known (because
it was >PDP_MAX=1024).

The issue can be triggered in test SGSN_Tests_Iu.TC_pmm_idle_rx_mt_data.

Related: OS#5773
Related: SYS#5435
Change-Id: I782aa43c71569922a945bd44544bb1388bf8c878
2024-07-30 21:38:41 +02:00
Pau Espin Pedrol
4ced617eb6 Fix DeactPDPCtxAcc when UE goes PMM ENABLED but lost its PDP context
Scenario: UE activates a PDP context, then after a while goes PMM IDLE
(Iu conn is destroyed but PDP is kept).
When UE connects through Iu again, it sends eg. RAU or ServiceRequest
with pdp_status bitmask statis the active NSAPIs.
If some NSAPI (PDP context) is enabled at SGSN but doesn't show up in
the bitmask, SGSN will destroy the PDP context with GGSN
(DeletePDPContextReq) towards GGSN prior to re-creating it.
When SGSN receives the DeletePDPContextResp, it would forward a
DeactivatePDPContextReq to the UE for a PDP context which was not known
by the UE anymore, this is wrong.

With this patch, the state of the NSAPI/PDP at the UE side is tracked,
and used to know whether when the PDP gets deleted on the GGSN side then
it needs to also be deleted on the Iu side.

Change-Id: I0ccd9228d71c29248b5f510356dbfdb09565dc30
2024-07-30 21:36:01 +02:00
Pau Espin Pedrol
dc4c294f94 gsup: Use new libosmogsm struct osmo_gsup_pdp_info fields
This also makes sure it doesn't compile against older libosmogsm gsup
versions which would break ABI.

Change-Id: I0d03d368e73ab62ec631420769f6af91f2ff9987
Related: OS#6091
Depends: libosmocore.git Change-Id 70be3560659c58f24b8db529c4fc85da4bb0ec04
2024-01-29 11:07:03 +01:00
Philipp Maier
e746b0bef6 sgsn_rim: forward message based on RIM ROUTING ADDRESS
At the moment we parse the RAN TRANSPARENT CONTAINER to look at the
destination RIM ROUTING INFORMATION. This is not correct. The SGSN
should not decode the RAN TRANSPARENT CONTAINER and use the RIM ROUTING
ADDRESS / RIM ROUTING ADDRESS DISCRIMINATOR IE to make the routing
decision.

Related: OS#6095
Depends: libosmocore.git Ibca1f08906c4ffeecdae80d4e91c6c7b05fe4f8a
Change-Id: Ifd2b915ed2f05130cff8ee77714b82005c17de3d
2023-09-18 21:53:39 +02:00
Philipp Maier
7840375d51 sgsn_rim: get rid of MME check in sgsn_rim_rx_from_gtp:
There is no point in checking the MME any further. When the message has
reached this code path it is about to be forwarded to BSSGP, so the MME
does not play a role in the following code pathes.

The check also relys on the source RIM ROUTING INFORMATION IE inside the
RAN TRANSPARENT CONTAINER, which we are not supposed to decode.

Change-Id: I97c89aeb11537ae54d1fbea48c75619d8a92af61
Related: OS#6095
2023-08-10 10:23:06 +02:00
Pau Espin Pedrol
86b630cfe1 vty: Introduce encryption cipher-plugin-path command
The load of plugins will eventually be moved to libosmo-gprs
implementation, and path will be passed as a parameter. Once it's moved
inside libosmo-gprs, it will be more strict on load failures, which can
cause internally if the path doesn't exist (unless NULL is passed).
Hence, add a VTY config to allow configuring the right path, and have it
disabled by default.

Change-Id: I4f965c7afafa193f4d7486750dd3e43cca22bb65
2023-01-11 12:58:23 +01:00
Pau Espin Pedrol
93bc518b53 Move global mmctx list into struct sgsn_instance
Change-Id: Idf8458902321da03b9b0831dad3ad383a9c7afa1
2023-01-11 12:58:23 +01:00
Pau Espin Pedrol
58101ea587 Split gprs_sgsn.{c,h} -> {auth,mmctx,sgsn}.{c,h}
Some level of split already existed, like sgsn_auth.c, but headers were
entangled together.
Let's clearly separate application centric code (sgsn.c/h), auth related
code (auth.c/h) and mmctx related code (mmctx.c/h).

Change-Id: I048a082851c1275c959649942904205b02acce2a
2023-01-11 12:58:15 +01:00