blob: bee7fb67beda3c5aa3739fe00fd6864447269cdc [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>
Harald Welteba43de42015-08-29 20:33:16 +02008
Harald Welteb3dae302015-08-30 12:20:09 +02009#define DEBUG
10#include <osmocom/core/logging.h>
11
Harald Welte90256ba2015-12-23 20:16:36 +010012
Harald Welteb3dae302015-08-30 12:20:09 +020013enum {
14 DMAIN,
Daniel Willmannbded9842015-12-17 11:51:17 +010015 DHNBAP,
Harald Welte75a4e652015-12-22 23:59:24 +010016 DSUA,
Harald Weltef42317b2015-12-23 15:36:31 +010017 DRUA,
18 DRANAP,
Harald Welteb3dae302015-08-30 12:20:09 +020019};
20
21
Harald Weltea2e6a7a2015-08-29 21:47:39 +020022/* 25.467 Section 7.1 */
23#define IUH_DEFAULT_SCTP_PORT 29169
24#define RNA_DEFAULT_SCTP_PORT 25471
25
26#define IUH_PPI_RUA 19
27#define IUH_PPI_HNBAP 20
28#define IUH_PPI_SABP 31
29#define IUH_PPI_RNA 42
30#define IUH_PPI_PUA 55
31
Harald Welteb3dae302015-08-30 12:20:09 +020032#define IUH_MSGB_SIZE 2048
Harald Weltea2e6a7a2015-08-29 21:47:39 +020033
34struct umts_cell_id {
35 uint16_t mcc; /*!< Mobile Country Code */
36 uint16_t mnc; /*!< Mobile Network Code */
37 uint16_t lac; /*!< Locaton Area Code */
38 uint16_t rac; /*!< Routing Area Code */
39 uint16_t sac; /*!< Service Area Code */
40 uint32_t cid; /*!< Cell ID */
41};
42
43struct hnb_gw;
44
Harald Welte90256ba2015-12-23 20:16:36 +010045enum hnbgw_cnlink_state {
46 /* we have just been initialized or were disconnected */
47 CNLINK_S_NULL,
48 /* establishment of the SUA/SCCP link is pending */
49 CNLINK_S_EST_PEND,
50 /* establishment of the SUA/SCCP link was confirmed */
51 CNLINK_S_EST_CONF,
52 /* we have esnt the RANAP RESET and wait for the ACK */
53 CNLINK_S_EST_RST_TX_WAIT_ACK,
54 /* we have received the RANAP RESET ACK and are active */
55 CNLINK_S_EST_ACTIVE,
56};
57
58struct hnbgw_cnlink {
59 struct llist_head list;
60 enum hnbgw_cnlink_state state;
61 struct hnb_gw *gw;
62 /* are we a PS connection (1) or CS (0) */
63 int is_ps;
64 /* timer for re-transmitting the RANAP Reset */
65 struct osmo_timer_list T_RafC;
66 /* reference to the SCCP User SAP by which we communicate */
Neels Hofmeyr0a437222016-07-06 15:58:48 +020067 struct osmo_sccp_user *sua_user;
68 struct osmo_sccp_link *sua_link;
Harald Welte90256ba2015-12-23 20:16:36 +010069 struct osmo_sccp_addr local_addr;
70 struct osmo_sccp_addr remote_addr;
71 uint32_t next_conn_id;
72
73 /* linked list of hnbgw_context_map */
74 struct llist_head map_list;
75};
76
Harald Welteba43de42015-08-29 20:33:16 +020077struct hnb_context {
78 /*! Entry in HNB-global list of HNB */
79 struct llist_head list;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020080 /*! HNB-GW we are part of */
81 struct hnb_gw *gw;
Harald Welte3f712562015-09-07 21:53:25 +020082 /*! SCTP socket + write queue for Iuh to this specific HNB */
Daniel Willmann6480cad2016-01-06 18:06:26 +010083 struct osmo_stream_srv *conn;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020084 /*! copied from HNB-Identity-Info IE */
85 char identity_info[256];
86 /*! copied from Cell Identity IE */
87 struct umts_cell_id id;
Harald Welte3f712562015-09-07 21:53:25 +020088
89 /*! SCTP stream ID for HNBAP */
90 uint16_t hnbap_stream;
91 /*! SCTP stream ID for RUA */
92 uint16_t rua_stream;
Harald Welte90256ba2015-12-23 20:16:36 +010093
94 /* linked list of hnbgw_context_map */
95 struct llist_head map_list;
Harald Welteba43de42015-08-29 20:33:16 +020096};
97
98struct ue_context {
Harald Weltea2e6a7a2015-08-29 21:47:39 +020099 /*! Entry in the HNB-global list of UE */
Harald Welteba43de42015-08-29 20:33:16 +0200100 struct llist_head list;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200101 /*! Unique Context ID for this UE */
Harald Welteba43de42015-08-29 20:33:16 +0200102 uint32_t context_id;
Harald Welteb534e5c2015-09-11 00:15:16 +0200103 char imsi[16+1];
Neels Hofmeyrf33e8352016-09-22 18:06:59 +0200104 uint32_t tmsi;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200105 /*! UE is serviced via this HNB */
106 struct hnb_context *hnb;
Harald Welteba43de42015-08-29 20:33:16 +0200107};
108
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200109#define HNBGW_IUH_BIND_ADDR_DEFAULT "0.0.0.0"
110
Harald Welteba43de42015-08-29 20:33:16 +0200111struct hnb_gw {
112 struct {
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200113 const char *iuh_bind_addr;
Harald Welteba43de42015-08-29 20:33:16 +0200114 /*! SCTP port for Iuh listening */
115 uint16_t iuh_listen_port;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200116 /*! The UDP port where we receive multiplexed CS user
117 * plane traffic from HNBs */
118 uint16_t iuh_cs_mux_port;
119 uint16_t rnc_id;
Harald Welteba43de42015-08-29 20:33:16 +0200120 } config;
121 /*! SCTP listen socket for incoming connections */
Daniel Willmann6480cad2016-01-06 18:06:26 +0100122 struct osmo_stream_srv_link *iuh;
Harald Weltec4338de2015-12-24 00:40:52 +0100123 /* list of struct hnb_context */
Harald Welteba43de42015-08-29 20:33:16 +0200124 struct llist_head hnb_list;
Harald Weltec4338de2015-12-24 00:40:52 +0100125 /* list of struct ue_context */
Harald Welteb534e5c2015-09-11 00:15:16 +0200126 struct llist_head ue_list;
Harald Weltec4338de2015-12-24 00:40:52 +0100127 /* list of struct hnbgw_cnlink */
Harald Welte90256ba2015-12-23 20:16:36 +0100128 struct llist_head cn_list;
Harald Weltec4338de2015-12-24 00:40:52 +0100129 /* next availble UE Context ID */
Harald Welteb534e5c2015-09-11 00:15:16 +0200130 uint32_t next_ue_ctx_id;
Harald Weltec4338de2015-12-24 00:40:52 +0100131
132 /* currently active CN links for CS and PS */
133 struct hnbgw_cnlink *cnlink_cs;
134 struct hnbgw_cnlink *cnlink_ps;
Harald Welteba43de42015-08-29 20:33:16 +0200135};
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200136
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200137extern void *talloc_asn1_ctx;
138
Harald Weltec4338de2015-12-24 00:40:52 +0100139struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id);
140struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi);
Neels Hofmeyrf33e8352016-09-22 18:06:59 +0200141struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi);
142struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi,
143 uint32_t tmsi);
Harald Welteb534e5c2015-09-11 00:15:16 +0200144void ue_context_free(struct ue_context *ue);
Harald Welte90256ba2015-12-23 20:16:36 +0100145
Daniel Willmann6480cad2016-01-06 18:06:26 +0100146struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd);
Harald Welte90256ba2015-12-23 20:16:36 +0100147void hnb_context_release(struct hnb_context *ctx);
Neels Hofmeyr4d8eb4c2016-08-18 01:03:44 +0200148
149void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx);
Neels Hofmeyrf495b232016-08-18 02:18:00 +0200150
151/*
152 * Return IP address passed to the hnbgw/iuh/bind command, or
153 * IUH_BIND_ADDR_DEFAULT
154 */
155const char *hnbgw_get_iuh_bind_addr(struct hnb_gw *gw);