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> |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 8 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 9 | #define DEBUG |
| 10 | #include <osmocom/core/logging.h> |
| 11 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 12 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 13 | enum { |
| 14 | DMAIN, |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 15 | DHNBAP, |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 16 | DSUA, |
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 | |
| 21 | |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 22 | #define HNBGW_LOCAL_IP_DEFAULT "0.0.0.0" |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame^] | 23 | #define HNBGW_IUCS_REMOTE_IP_DEFAULT "127.0.0.1" |
| 24 | #define HNBGW_IUPS_REMOTE_IP_DEFAULT "127.0.0.2" |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 25 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 26 | /* 25.467 Section 7.1 */ |
| 27 | #define IUH_DEFAULT_SCTP_PORT 29169 |
| 28 | #define RNA_DEFAULT_SCTP_PORT 25471 |
| 29 | |
| 30 | #define IUH_PPI_RUA 19 |
| 31 | #define IUH_PPI_HNBAP 20 |
| 32 | #define IUH_PPI_SABP 31 |
| 33 | #define IUH_PPI_RNA 42 |
| 34 | #define IUH_PPI_PUA 55 |
| 35 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 36 | #define IUH_MSGB_SIZE 2048 |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 37 | |
| 38 | struct umts_cell_id { |
| 39 | uint16_t mcc; /*!< Mobile Country Code */ |
| 40 | uint16_t mnc; /*!< Mobile Network Code */ |
| 41 | uint16_t lac; /*!< Locaton Area Code */ |
| 42 | uint16_t rac; /*!< Routing Area Code */ |
| 43 | uint16_t sac; /*!< Service Area Code */ |
| 44 | uint32_t cid; /*!< Cell ID */ |
| 45 | }; |
| 46 | |
| 47 | struct hnb_gw; |
| 48 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 49 | enum hnbgw_cnlink_state { |
| 50 | /* we have just been initialized or were disconnected */ |
| 51 | CNLINK_S_NULL, |
| 52 | /* establishment of the SUA/SCCP link is pending */ |
| 53 | CNLINK_S_EST_PEND, |
| 54 | /* establishment of the SUA/SCCP link was confirmed */ |
| 55 | CNLINK_S_EST_CONF, |
| 56 | /* we have esnt the RANAP RESET and wait for the ACK */ |
| 57 | CNLINK_S_EST_RST_TX_WAIT_ACK, |
| 58 | /* we have received the RANAP RESET ACK and are active */ |
| 59 | CNLINK_S_EST_ACTIVE, |
| 60 | }; |
| 61 | |
| 62 | struct hnbgw_cnlink { |
| 63 | struct llist_head list; |
| 64 | enum hnbgw_cnlink_state state; |
| 65 | struct hnb_gw *gw; |
| 66 | /* are we a PS connection (1) or CS (0) */ |
| 67 | int is_ps; |
| 68 | /* timer for re-transmitting the RANAP Reset */ |
| 69 | struct osmo_timer_list T_RafC; |
| 70 | /* reference to the SCCP User SAP by which we communicate */ |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 71 | struct osmo_sccp_user *sua_user; |
| 72 | struct osmo_sccp_link *sua_link; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 73 | struct osmo_sccp_addr local_addr; |
| 74 | struct osmo_sccp_addr remote_addr; |
| 75 | uint32_t next_conn_id; |
| 76 | |
| 77 | /* linked list of hnbgw_context_map */ |
| 78 | struct llist_head map_list; |
| 79 | }; |
| 80 | |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 81 | struct hnb_context { |
| 82 | /*! Entry in HNB-global list of HNB */ |
| 83 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 84 | /*! HNB-GW we are part of */ |
| 85 | struct hnb_gw *gw; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 86 | /*! SCTP socket + write queue for Iuh to this specific HNB */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 87 | struct osmo_stream_srv *conn; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 88 | /*! copied from HNB-Identity-Info IE */ |
| 89 | char identity_info[256]; |
| 90 | /*! copied from Cell Identity IE */ |
| 91 | struct umts_cell_id id; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 92 | |
| 93 | /*! SCTP stream ID for HNBAP */ |
| 94 | uint16_t hnbap_stream; |
| 95 | /*! SCTP stream ID for RUA */ |
| 96 | uint16_t rua_stream; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 97 | |
| 98 | /* linked list of hnbgw_context_map */ |
| 99 | struct llist_head map_list; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | struct ue_context { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 103 | /*! Entry in the HNB-global list of UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 104 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 105 | /*! Unique Context ID for this UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 106 | uint32_t context_id; |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 107 | char imsi[16+1]; |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 108 | uint32_t tmsi; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 109 | /*! UE is serviced via this HNB */ |
| 110 | struct hnb_context *hnb; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | struct hnb_gw { |
| 114 | struct { |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 115 | const char *iuh_local_ip; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 116 | /*! SCTP port for Iuh listening */ |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 117 | uint16_t iuh_local_port; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 118 | /*! The UDP port where we receive multiplexed CS user |
| 119 | * plane traffic from HNBs */ |
| 120 | uint16_t iuh_cs_mux_port; |
Neels Hofmeyr | 5ee050c | 2016-10-13 15:12:18 +0200 | [diff] [blame^] | 121 | const char *iucs_remote_ip; |
| 122 | uint16_t iucs_remote_port; |
| 123 | const char *iups_remote_ip; |
| 124 | uint16_t iups_remote_port; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 125 | uint16_t rnc_id; |
Neels Hofmeyr | 12181a9 | 2016-04-25 15:05:32 +0200 | [diff] [blame] | 126 | bool hnbap_allow_tmsi; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 127 | } config; |
| 128 | /*! SCTP listen socket for incoming connections */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 129 | struct osmo_stream_srv_link *iuh; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 130 | /* list of struct hnb_context */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 131 | struct llist_head hnb_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 132 | /* list of struct ue_context */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 133 | struct llist_head ue_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 134 | /* list of struct hnbgw_cnlink */ |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 135 | struct llist_head cn_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 136 | /* next availble UE Context ID */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 137 | uint32_t next_ue_ctx_id; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 138 | |
| 139 | /* currently active CN links for CS and PS */ |
| 140 | struct hnbgw_cnlink *cnlink_cs; |
| 141 | struct hnbgw_cnlink *cnlink_ps; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 142 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 143 | |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 144 | extern void *talloc_asn1_ctx; |
| 145 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 146 | struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id); |
| 147 | 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] | 148 | struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi); |
| 149 | struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi, |
| 150 | uint32_t tmsi); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 151 | void ue_context_free(struct ue_context *ue); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 152 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 153 | struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 154 | void hnb_context_release(struct hnb_context *ctx); |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 155 | |
| 156 | void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx); |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 157 | int hnbgw_vty_go_parent(struct vty *vty); |