blob: 4848c2f3d4b37aaa6dd2dbcf88756fabe8b91990 [file] [log] [blame]
Harald Welteba43de42015-08-29 20:33:16 +02001#pragma once
2
3#include <osmocom/core/select.h>
4#include <osmocom/core/linuxlist.h>
Harald Welte3f712562015-09-07 21:53:25 +02005#include <osmocom/core/write_queue.h>
Harald Welte90256ba2015-12-23 20:16:36 +01006#include <osmocom/core/timer.h>
7#include <osmocom/sigtran/sccp_sap.h>
Neels Hofmeyr0f88c112017-07-03 16:49:43 +02008#include <osmocom/sigtran/osmo_ss7.h>
Maxbfeea672017-12-27 22:53:36 +01009#include <osmocom/ctrl/control_if.h>
Harald Welteb3dae302015-08-30 12:20:09 +020010#define DEBUG
11#include <osmocom/core/logging.h>
12
Harald Welte90256ba2015-12-23 20:16:36 +010013
Harald Welteb3dae302015-08-30 12:20:09 +020014enum {
15 DMAIN,
Daniel Willmannbded9842015-12-17 11:51:17 +010016 DHNBAP,
Harald Weltef42317b2015-12-23 15:36:31 +010017 DRUA,
18 DRANAP,
Harald Welteb3dae302015-08-30 12:20:09 +020019};
20
Maxbfeea672017-12-27 22:53:36 +010021enum hnb_ctrl_node {
22 CTRL_NODE_HNB = _LAST_CTRL_NODE,
23 _LAST_CTRL_NODE_HNB
24};
Harald Welteb3dae302015-08-30 12:20:09 +020025
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +020026#define HNBGW_LOCAL_IP_DEFAULT "0.0.0.0"
Neels Hofmeyr0f88c112017-07-03 16:49:43 +020027/* TODO: CS and PS now both connect to OsmoSTP, i.e. that's always going to be the same address. Drop the
28 * duplicity. */
Neels Hofmeyr5ee050c2016-10-13 15:12:18 +020029#define HNBGW_IUCS_REMOTE_IP_DEFAULT "127.0.0.1"
Neels Hofmeyr0f88c112017-07-03 16:49:43 +020030#define HNBGW_IUPS_REMOTE_IP_DEFAULT "127.0.0.1"
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +020031
Harald Weltea2e6a7a2015-08-29 21:47:39 +020032/* 25.467 Section 7.1 */
33#define IUH_DEFAULT_SCTP_PORT 29169
34#define RNA_DEFAULT_SCTP_PORT 25471
35
36#define IUH_PPI_RUA 19
37#define IUH_PPI_HNBAP 20
38#define IUH_PPI_SABP 31
39#define IUH_PPI_RNA 42
40#define IUH_PPI_PUA 55
41
Harald Welteb3dae302015-08-30 12:20:09 +020042#define IUH_MSGB_SIZE 2048
Harald Weltea2e6a7a2015-08-29 21:47:39 +020043
44struct umts_cell_id {
45 uint16_t mcc; /*!< Mobile Country Code */
46 uint16_t mnc; /*!< Mobile Network Code */
47 uint16_t lac; /*!< Locaton Area Code */
48 uint16_t rac; /*!< Routing Area Code */
49 uint16_t sac; /*!< Service Area Code */
50 uint32_t cid; /*!< Cell ID */
51};
52
53struct hnb_gw;
54
Harald Welte90256ba2015-12-23 20:16:36 +010055enum hnbgw_cnlink_state {
56 /* we have just been initialized or were disconnected */
57 CNLINK_S_NULL,
58 /* establishment of the SUA/SCCP link is pending */
59 CNLINK_S_EST_PEND,
60 /* establishment of the SUA/SCCP link was confirmed */
61 CNLINK_S_EST_CONF,
62 /* we have esnt the RANAP RESET and wait for the ACK */
63 CNLINK_S_EST_RST_TX_WAIT_ACK,
64 /* we have received the RANAP RESET ACK and are active */
65 CNLINK_S_EST_ACTIVE,
66};
67
68struct hnbgw_cnlink {
69 struct llist_head list;
70 enum hnbgw_cnlink_state state;
71 struct hnb_gw *gw;
Harald Welte90256ba2015-12-23 20:16:36 +010072 /* timer for re-transmitting the RANAP Reset */
73 struct osmo_timer_list T_RafC;
74 /* reference to the SCCP User SAP by which we communicate */
Neels Hofmeyr0f88c112017-07-03 16:49:43 +020075 struct osmo_sccp_instance *sccp;
76 struct osmo_sccp_user *sccp_user;
Harald Welte90256ba2015-12-23 20:16:36 +010077 uint32_t next_conn_id;
78
79 /* linked list of hnbgw_context_map */
80 struct llist_head map_list;
81};
82
Harald Welteba43de42015-08-29 20:33:16 +020083struct hnb_context {
84 /*! Entry in HNB-global list of HNB */
85 struct llist_head list;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020086 /*! HNB-GW we are part of */
87 struct hnb_gw *gw;
Harald Welte3f712562015-09-07 21:53:25 +020088 /*! SCTP socket + write queue for Iuh to this specific HNB */
Daniel Willmann6480cad2016-01-06 18:06:26 +010089 struct osmo_stream_srv *conn;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020090 /*! copied from HNB-Identity-Info IE */
91 char identity_info[256];
92 /*! copied from Cell Identity IE */
93 struct umts_cell_id id;
Harald Welte3f712562015-09-07 21:53:25 +020094
95 /*! SCTP stream ID for HNBAP */
96 uint16_t hnbap_stream;
97 /*! SCTP stream ID for RUA */
98 uint16_t rua_stream;
Harald Welte90256ba2015-12-23 20:16:36 +010099
Stefan Sperlingc964a2c2018-02-19 17:02:12 +0100100 /*! True if a HNB-REGISTER-REQ from this HNB has been accepted. Note that
101 * this entire data structure is freed if the HNB sends HNB-DE-REGISTER-REQ. */
102 bool hnb_registered;
103
Harald Welte90256ba2015-12-23 20:16:36 +0100104 /* linked list of hnbgw_context_map */
105 struct llist_head map_list;
Harald Welteba43de42015-08-29 20:33:16 +0200106};
107
108struct ue_context {
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200109 /*! Entry in the HNB-global list of UE */
Harald Welteba43de42015-08-29 20:33:16 +0200110 struct llist_head list;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200111 /*! Unique Context ID for this UE */
Harald Welteba43de42015-08-29 20:33:16 +0200112 uint32_t context_id;
Harald Welteb534e5c2015-09-11 00:15:16 +0200113 char imsi[16+1];
Neels Hofmeyrf33e8352016-09-22 18:06:59 +0200114 uint32_t tmsi;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200115 /*! UE is serviced via this HNB */
116 struct hnb_context *hnb;
Harald Welteba43de42015-08-29 20:33:16 +0200117};
118
119struct hnb_gw {
120 struct {
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200121 const char *iuh_local_ip;
Harald Welteba43de42015-08-29 20:33:16 +0200122 /*! SCTP port for Iuh listening */
Neels Hofmeyrc7ccdd42016-10-13 14:43:49 +0200123 uint16_t iuh_local_port;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200124 /*! The UDP port where we receive multiplexed CS user
125 * plane traffic from HNBs */
126 uint16_t iuh_cs_mux_port;
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200127 const char *iucs_remote_addr_name;
128 const char *iups_remote_addr_name;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200129 uint16_t rnc_id;
Neels Hofmeyr12181a92016-04-25 15:05:32 +0200130 bool hnbap_allow_tmsi;
Harald Welteba43de42015-08-29 20:33:16 +0200131 } config;
132 /*! SCTP listen socket for incoming connections */
Daniel Willmann6480cad2016-01-06 18:06:26 +0100133 struct osmo_stream_srv_link *iuh;
Harald Weltec4338de2015-12-24 00:40:52 +0100134 /* list of struct hnb_context */
Harald Welteba43de42015-08-29 20:33:16 +0200135 struct llist_head hnb_list;
Harald Weltec4338de2015-12-24 00:40:52 +0100136 /* list of struct ue_context */
Harald Welteb534e5c2015-09-11 00:15:16 +0200137 struct llist_head ue_list;
Harald Weltec4338de2015-12-24 00:40:52 +0100138 /* next availble UE Context ID */
Harald Welteb534e5c2015-09-11 00:15:16 +0200139 uint32_t next_ue_ctx_id;
Maxef727412017-12-26 19:27:43 +0100140 struct ctrl_handle *ctrl;
Harald Weltec4338de2015-12-24 00:40:52 +0100141 /* currently active CN links for CS and PS */
Neels Hofmeyr0f88c112017-07-03 16:49:43 +0200142 struct {
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200143 struct osmo_sccp_instance *client;
Neels Hofmeyr0f88c112017-07-03 16:49:43 +0200144 struct hnbgw_cnlink *cnlink;
145 struct osmo_sccp_addr local_addr;
Neels Hofmeyrecbdc5c2017-07-31 13:13:24 +0200146 struct osmo_sccp_addr iucs_remote_addr;
147 struct osmo_sccp_addr iups_remote_addr;
Neels Hofmeyr0f88c112017-07-03 16:49:43 +0200148 } sccp;
Harald Welteba43de42015-08-29 20:33:16 +0200149};
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200150
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200151extern void *talloc_asn1_ctx;
152
Maxbfeea672017-12-27 22:53:36 +0100153struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid);
Stefan Sperling319c2852018-10-29 18:19:14 +0100154struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info);
Maxbfeea672017-12-27 22:53:36 +0100155unsigned hnb_contexts(const struct hnb_gw *gw);
156
Harald Weltec4338de2015-12-24 00:40:52 +0100157struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id);
158struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi);
Neels Hofmeyrf33e8352016-09-22 18:06:59 +0200159struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi);
160struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi,
161 uint32_t tmsi);
Harald Welteb534e5c2015-09-11 00:15:16 +0200162void ue_context_free(struct ue_context *ue);
Harald Welte90256ba2015-12-23 20:16:36 +0100163
Daniel Willmann6480cad2016-01-06 18:06:26 +0100164struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd);
Alexander Couzensad4ea3b2018-07-24 19:04:47 +0200165void hnb_context_release(struct hnb_context *ctx);
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200166
167void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx);
Neels Hofmeyrc510fc22016-10-13 16:58:04 +0200168int hnbgw_vty_go_parent(struct vty *vty);