Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <osmocom/core/select.h> |
| 4 | #include <osmocom/core/linuxlist.h> |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 5 | #include <osmocom/core/write_queue.h> |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 6 | #include <osmocom/core/timer.h> |
| 7 | #include <osmocom/sigtran/sccp_sap.h> |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 8 | #include <osmocom/sigtran/osmo_ss7.h> |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 9 | #include <osmocom/ctrl/control_if.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 10 | #define DEBUG |
| 11 | #include <osmocom/core/logging.h> |
| 12 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 13 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 14 | enum { |
| 15 | DMAIN, |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 16 | DHNBAP, |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 17 | DRUA, |
| 18 | DRANAP, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 19 | }; |
| 20 | |
Harald Welte | c6d9345 | 2020-12-30 13:36:20 +0100 | [diff] [blame] | 21 | #define LOGHNB(x, ss, lvl, fmt, args ...) \ |
| 22 | LOGP(ss, lvl, "%s " fmt, hnb_context_name(x), ## args) |
| 23 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 24 | enum hnb_ctrl_node { |
| 25 | CTRL_NODE_HNB = _LAST_CTRL_NODE, |
| 26 | _LAST_CTRL_NODE_HNB |
| 27 | }; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 28 | |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 29 | #define HNBGW_LOCAL_IP_DEFAULT "0.0.0.0" |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 30 | /* TODO: CS and PS now both connect to OsmoSTP, i.e. that's always going to be the same address. Drop the |
| 31 | * duplicity. */ |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame] | 32 | #define HNBGW_IUCS_REMOTE_IP_DEFAULT "127.0.0.1" |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 33 | #define HNBGW_IUPS_REMOTE_IP_DEFAULT "127.0.0.1" |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 34 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 35 | /* 25.467 Section 7.1 */ |
| 36 | #define IUH_DEFAULT_SCTP_PORT 29169 |
| 37 | #define RNA_DEFAULT_SCTP_PORT 25471 |
| 38 | |
| 39 | #define IUH_PPI_RUA 19 |
| 40 | #define IUH_PPI_HNBAP 20 |
| 41 | #define IUH_PPI_SABP 31 |
| 42 | #define IUH_PPI_RNA 42 |
| 43 | #define IUH_PPI_PUA 55 |
| 44 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 45 | #define IUH_MSGB_SIZE 2048 |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 46 | |
| 47 | struct umts_cell_id { |
| 48 | uint16_t mcc; /*!< Mobile Country Code */ |
| 49 | uint16_t mnc; /*!< Mobile Network Code */ |
| 50 | uint16_t lac; /*!< Locaton Area Code */ |
| 51 | uint16_t rac; /*!< Routing Area Code */ |
| 52 | uint16_t sac; /*!< Service Area Code */ |
| 53 | uint32_t cid; /*!< Cell ID */ |
| 54 | }; |
| 55 | |
| 56 | struct hnb_gw; |
| 57 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 58 | enum hnbgw_cnlink_state { |
| 59 | /* we have just been initialized or were disconnected */ |
| 60 | CNLINK_S_NULL, |
| 61 | /* establishment of the SUA/SCCP link is pending */ |
| 62 | CNLINK_S_EST_PEND, |
| 63 | /* establishment of the SUA/SCCP link was confirmed */ |
| 64 | CNLINK_S_EST_CONF, |
| 65 | /* we have esnt the RANAP RESET and wait for the ACK */ |
| 66 | CNLINK_S_EST_RST_TX_WAIT_ACK, |
| 67 | /* we have received the RANAP RESET ACK and are active */ |
| 68 | CNLINK_S_EST_ACTIVE, |
| 69 | }; |
| 70 | |
| 71 | struct hnbgw_cnlink { |
| 72 | struct llist_head list; |
| 73 | enum hnbgw_cnlink_state state; |
| 74 | struct hnb_gw *gw; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 75 | /* timer for re-transmitting the RANAP Reset */ |
| 76 | struct osmo_timer_list T_RafC; |
| 77 | /* reference to the SCCP User SAP by which we communicate */ |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 78 | struct osmo_sccp_instance *sccp; |
| 79 | struct osmo_sccp_user *sccp_user; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 80 | uint32_t next_conn_id; |
| 81 | |
| 82 | /* linked list of hnbgw_context_map */ |
| 83 | struct llist_head map_list; |
| 84 | }; |
| 85 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 86 | struct hnb_context { |
| 87 | /*! Entry in HNB-global list of HNB */ |
| 88 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 89 | /*! HNB-GW we are part of */ |
| 90 | struct hnb_gw *gw; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 91 | /*! SCTP socket + write queue for Iuh to this specific HNB */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 92 | struct osmo_stream_srv *conn; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 93 | /*! copied from HNB-Identity-Info IE */ |
| 94 | char identity_info[256]; |
| 95 | /*! copied from Cell Identity IE */ |
| 96 | struct umts_cell_id id; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 97 | |
| 98 | /*! SCTP stream ID for HNBAP */ |
| 99 | uint16_t hnbap_stream; |
| 100 | /*! SCTP stream ID for RUA */ |
| 101 | uint16_t rua_stream; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 102 | |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 103 | /*! True if a HNB-REGISTER-REQ from this HNB has been accepted. Note that |
| 104 | * this entire data structure is freed if the HNB sends HNB-DE-REGISTER-REQ. */ |
| 105 | bool hnb_registered; |
| 106 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 107 | /* linked list of hnbgw_context_map */ |
| 108 | struct llist_head map_list; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct ue_context { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 112 | /*! Entry in the HNB-global list of UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 113 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 114 | /*! Unique Context ID for this UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 115 | uint32_t context_id; |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 116 | char imsi[16+1]; |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 117 | uint32_t tmsi; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 118 | /*! UE is serviced via this HNB */ |
| 119 | struct hnb_context *hnb; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | struct hnb_gw { |
| 123 | struct { |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 124 | const char *iuh_local_ip; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 125 | /*! SCTP port for Iuh listening */ |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 126 | uint16_t iuh_local_port; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 127 | /*! The UDP port where we receive multiplexed CS user |
| 128 | * plane traffic from HNBs */ |
| 129 | uint16_t iuh_cs_mux_port; |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 130 | const char *iucs_remote_addr_name; |
| 131 | const char *iups_remote_addr_name; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 132 | uint16_t rnc_id; |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 133 | bool hnbap_allow_tmsi; |
Harald Welte | c6d9345 | 2020-12-30 13:36:20 +0100 | [diff] [blame] | 134 | /*! print hnb-id (true) or MCC-MNC-LAC-RAC-SAC (false) in logs */ |
| 135 | bool log_prefix_hnb_id; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 136 | } config; |
| 137 | /*! SCTP listen socket for incoming connections */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 138 | struct osmo_stream_srv_link *iuh; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 139 | /* list of struct hnb_context */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 140 | struct llist_head hnb_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 141 | /* list of struct ue_context */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 142 | struct llist_head ue_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 143 | /* next availble UE Context ID */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 144 | uint32_t next_ue_ctx_id; |
Max | ef72741 | 2017-12-26 19:27:43 +0100 | [diff] [blame] | 145 | struct ctrl_handle *ctrl; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 146 | /* currently active CN links for CS and PS */ |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 147 | struct { |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 148 | struct osmo_sccp_instance *client; |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 149 | struct hnbgw_cnlink *cnlink; |
| 150 | struct osmo_sccp_addr local_addr; |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 151 | struct osmo_sccp_addr iucs_remote_addr; |
| 152 | struct osmo_sccp_addr iups_remote_addr; |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 153 | } sccp; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 154 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 155 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 156 | extern void *talloc_asn1_ctx; |
| 157 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 158 | struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid); |
Stefan Sperling | 319c285 | 2018-10-29 18:19:14 +0100 | [diff] [blame] | 159 | struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info); |
Harald Welte | c6d9345 | 2020-12-30 13:36:20 +0100 | [diff] [blame] | 160 | const char *hnb_context_name(struct hnb_context *ctx); |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 161 | unsigned hnb_contexts(const struct hnb_gw *gw); |
| 162 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 163 | struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id); |
| 164 | struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi); |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 165 | struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi); |
| 166 | struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi, |
| 167 | uint32_t tmsi); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 168 | void ue_context_free(struct ue_context *ue); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 169 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 170 | struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd); |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 171 | void hnb_context_release(struct hnb_context *ctx); |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 172 | |
| 173 | void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx); |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 174 | int hnbgw_vty_go_parent(struct vty *vty); |