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 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 22 | /* 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 Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 32 | #define IUH_MSGB_SIZE 2048 |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 33 | |
| 34 | struct 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 | |
| 43 | struct hnb_gw; |
| 44 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 45 | enum 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 | |
| 58 | struct 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 Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 67 | struct osmo_sccp_user *sua_user; |
| 68 | struct osmo_sccp_link *sua_link; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 69 | 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 Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 77 | struct hnb_context { |
| 78 | /*! Entry in HNB-global list of HNB */ |
| 79 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 80 | /*! HNB-GW we are part of */ |
| 81 | struct hnb_gw *gw; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 82 | /*! SCTP socket + write queue for Iuh to this specific HNB */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 83 | struct osmo_stream_srv *conn; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 84 | /*! copied from HNB-Identity-Info IE */ |
| 85 | char identity_info[256]; |
| 86 | /*! copied from Cell Identity IE */ |
| 87 | struct umts_cell_id id; |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 88 | |
| 89 | /*! SCTP stream ID for HNBAP */ |
| 90 | uint16_t hnbap_stream; |
| 91 | /*! SCTP stream ID for RUA */ |
| 92 | uint16_t rua_stream; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 93 | |
| 94 | /* linked list of hnbgw_context_map */ |
| 95 | struct llist_head map_list; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct ue_context { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 99 | /*! Entry in the HNB-global list of UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 100 | struct llist_head list; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 101 | /*! Unique Context ID for this UE */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 102 | uint32_t context_id; |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 103 | char imsi[16+1]; |
Neels Hofmeyr | 9246cc9 | 2016-04-25 14:47:26 +0200 | [diff] [blame] | 104 | /* TODO: track TMSI, for HNBAP UE Register Request with TMSI, |
| 105 | * seen with ip.access nano3G femto cell */ |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 106 | /*! UE is serviced via this HNB */ |
| 107 | struct hnb_context *hnb; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct hnb_gw { |
| 111 | struct { |
| 112 | /*! SCTP port for Iuh listening */ |
| 113 | uint16_t iuh_listen_port; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 114 | /*! The UDP port where we receive multiplexed CS user |
| 115 | * plane traffic from HNBs */ |
| 116 | uint16_t iuh_cs_mux_port; |
| 117 | uint16_t rnc_id; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 118 | } config; |
| 119 | /*! SCTP listen socket for incoming connections */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 120 | struct osmo_stream_srv_link *iuh; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 121 | /* list of struct hnb_context */ |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 122 | struct llist_head hnb_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 123 | /* list of struct ue_context */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 124 | struct llist_head ue_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 125 | /* list of struct hnbgw_cnlink */ |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 126 | struct llist_head cn_list; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 127 | /* next availble UE Context ID */ |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 128 | uint32_t next_ue_ctx_id; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 129 | |
| 130 | /* currently active CN links for CS and PS */ |
| 131 | struct hnbgw_cnlink *cnlink_cs; |
| 132 | struct hnbgw_cnlink *cnlink_ps; |
Harald Welte | ba43de4 | 2015-08-29 20:33:16 +0200 | [diff] [blame] | 133 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 134 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 135 | struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id); |
| 136 | struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 137 | struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi); |
| 138 | void ue_context_free(struct ue_context *ue); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 139 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 140 | 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] | 141 | void hnb_context_release(struct hnb_context *ctx); |