osmo-iuh/include/osmocom/iuh/hnbgw.h

168 lines
4.6 KiB
C
Raw Normal View History

#pragma once
#include <osmocom/core/select.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/write_queue.h>
#include <osmocom/core/timer.h>
#include <osmocom/sigtran/sccp_sap.h>
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
#include <osmocom/sigtran/osmo_ss7.h>
#include <osmocom/ctrl/control_if.h>
2015-08-30 10:20:09 +00:00
#define DEBUG
#include <osmocom/core/logging.h>
2015-08-30 10:20:09 +00:00
enum {
DMAIN,
DHNBAP,
DRUA,
DRANAP,
2015-08-30 10:20:09 +00:00
};
enum hnb_ctrl_node {
CTRL_NODE_HNB = _LAST_CTRL_NODE,
_LAST_CTRL_NODE_HNB
};
2015-08-30 10:20:09 +00:00
#define HNBGW_LOCAL_IP_DEFAULT "0.0.0.0"
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
/* TODO: CS and PS now both connect to OsmoSTP, i.e. that's always going to be the same address. Drop the
* duplicity. */
#define HNBGW_IUCS_REMOTE_IP_DEFAULT "127.0.0.1"
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
#define HNBGW_IUPS_REMOTE_IP_DEFAULT "127.0.0.1"
/* 25.467 Section 7.1 */
#define IUH_DEFAULT_SCTP_PORT 29169
#define RNA_DEFAULT_SCTP_PORT 25471
#define IUH_PPI_RUA 19
#define IUH_PPI_HNBAP 20
#define IUH_PPI_SABP 31
#define IUH_PPI_RNA 42
#define IUH_PPI_PUA 55
2015-08-30 10:20:09 +00:00
#define IUH_MSGB_SIZE 2048
struct umts_cell_id {
uint16_t mcc; /*!< Mobile Country Code */
uint16_t mnc; /*!< Mobile Network Code */
uint16_t lac; /*!< Locaton Area Code */
uint16_t rac; /*!< Routing Area Code */
uint16_t sac; /*!< Service Area Code */
uint32_t cid; /*!< Cell ID */
};
struct hnb_gw;
enum hnbgw_cnlink_state {
/* we have just been initialized or were disconnected */
CNLINK_S_NULL,
/* establishment of the SUA/SCCP link is pending */
CNLINK_S_EST_PEND,
/* establishment of the SUA/SCCP link was confirmed */
CNLINK_S_EST_CONF,
/* we have esnt the RANAP RESET and wait for the ACK */
CNLINK_S_EST_RST_TX_WAIT_ACK,
/* we have received the RANAP RESET ACK and are active */
CNLINK_S_EST_ACTIVE,
};
struct hnbgw_cnlink {
struct llist_head list;
enum hnbgw_cnlink_state state;
struct hnb_gw *gw;
/* timer for re-transmitting the RANAP Reset */
struct osmo_timer_list T_RafC;
/* reference to the SCCP User SAP by which we communicate */
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
struct osmo_sccp_instance *sccp;
struct osmo_sccp_user *sccp_user;
uint32_t next_conn_id;
/* linked list of hnbgw_context_map */
struct llist_head map_list;
};
struct hnb_context {
/*! Entry in HNB-global list of HNB */
struct llist_head list;
/*! HNB-GW we are part of */
struct hnb_gw *gw;
/*! SCTP socket + write queue for Iuh to this specific HNB */
struct osmo_stream_srv *conn;
/*! copied from HNB-Identity-Info IE */
char identity_info[256];
/*! copied from Cell Identity IE */
struct umts_cell_id id;
/*! SCTP stream ID for HNBAP */
uint16_t hnbap_stream;
/*! SCTP stream ID for RUA */
uint16_t rua_stream;
/*! True if a HNB-REGISTER-REQ from this HNB has been accepted. Note that
* this entire data structure is freed if the HNB sends HNB-DE-REGISTER-REQ. */
bool hnb_registered;
/* linked list of hnbgw_context_map */
struct llist_head map_list;
};
struct ue_context {
/*! Entry in the HNB-global list of UE */
struct llist_head list;
/*! Unique Context ID for this UE */
uint32_t context_id;
char imsi[16+1];
uint32_t tmsi;
/*! UE is serviced via this HNB */
struct hnb_context *hnb;
};
struct hnb_gw {
struct {
const char *iuh_local_ip;
/*! SCTP port for Iuh listening */
uint16_t iuh_local_port;
/*! The UDP port where we receive multiplexed CS user
* plane traffic from HNBs */
uint16_t iuh_cs_mux_port;
const char *iucs_remote_addr_name;
const char *iups_remote_addr_name;
uint16_t rnc_id;
hnbap: accept UE Register Requests with TMSI and pTMSI Add the option to allow UE Register Requests with a TMSI identity. Add VTY command to enable this option, 'hnbap-allow-tmsi'. Add hnbgw_tx_ue_register_acc_tmsi(). HNBGW so far keeps track of UEs that have registered, with their IMSI. When a UE registers with only a TMSI, we obviously can't store an IMSI. However, since we're so far never *using* the list of UEs in osmo-hnbgw, we might as well just accept the TMSI registration and carry on as usual. All that is needed for proper operation is a valid UE context. This is aimed at the ip.access nano3G femto cell, as it apparently feeds whichever identification the UE sends through to HNBAP (TMSI+LAI, pTMSI+RAI), instead of an IMSI as expected. So far this caused failures and the need to make the UE clear its TMSI (wait several minutes or attempt to subscribe to a different network), so that UE registration switched back to IMSI. When simply accepting the TMSI in osmo-hngw, no problems are apparent in our current code state. For example, a Samsung Galaxy S4 seems to send a UE_Identity_PR_tMSILAI (CS identity), and a GT-I9100 seems to send a UE_Identity_PR_pTMSIRAI (PS identity) upon first registration to the network. Recording the IMSI in hnbgw: we could use the subscriber list during paging, to page a UE on only its last seen HNB. On the other hand, it doesn't hurt to anyway always page to all HNBs connected to osmo-hnbgw. The paging procedure does include a page-to-all-HNBs in case the first HNB paging fails. But we must be aware that UEs that register by TMSI will simply not have an IMSI recorded in the list of UE contexts, so a lookup based on IMSI may fail. Patch-by: Harald Welte <laforge@gnumonks.org>, me Change-Id: I87bc1aa3e85815ded7ac1dbdca48f1680b468589
2016-04-25 13:05:32 +00:00
bool hnbap_allow_tmsi;
} config;
/*! SCTP listen socket for incoming connections */
struct osmo_stream_srv_link *iuh;
/* list of struct hnb_context */
struct llist_head hnb_list;
/* list of struct ue_context */
struct llist_head ue_list;
/* next availble UE Context ID */
uint32_t next_ue_ctx_id;
struct ctrl_handle *ctrl;
/* currently active CN links for CS and PS */
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
struct {
struct osmo_sccp_instance *client;
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
struct hnbgw_cnlink *cnlink;
struct osmo_sccp_addr local_addr;
struct osmo_sccp_addr iucs_remote_addr;
struct osmo_sccp_addr iups_remote_addr;
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
} sccp;
};
extern void *talloc_asn1_ctx;
struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid);
unsigned hnb_contexts(const struct hnb_gw *gw);
struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id);
struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi);
struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi);
struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi,
uint32_t tmsi);
void ue_context_free(struct ue_context *ue);
struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd);
void hnb_context_release(struct hnb_context *ctx, bool destroy_conn);
void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx);
int hnbgw_vty_go_parent(struct vty *vty);