Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 1 | /* main application for hnb-gw part of osmo-iuh */ |
| 2 | |
| 3 | /* (C) 2015 by Harald Welte <laforge@gnumonks.org> |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 4 | * (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
Harald Welte | 77847ad | 2015-10-06 22:07:04 +0200 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <getopt.h> |
| 27 | #include <errno.h> |
| 28 | #include <signal.h> |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 29 | #include <stdbool.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 30 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 31 | #include <sys/types.h> |
| 32 | #include <sys/socket.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 33 | #include <netinet/in.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 34 | #include <netinet/sctp.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 35 | #include <arpa/inet.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 36 | |
| 37 | #include <osmocom/core/application.h> |
| 38 | #include <osmocom/core/talloc.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 39 | #include <osmocom/core/select.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 40 | #include <osmocom/core/logging.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 41 | #include <osmocom/core/socket.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 42 | #include <osmocom/core/msgb.h> |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 43 | #include <osmocom/core/write_queue.h> |
Max | ef72741 | 2017-12-26 19:27:43 +0100 | [diff] [blame] | 44 | #include <osmocom/ctrl/control_if.h> |
| 45 | #include <osmocom/ctrl/control_cmd.h> |
| 46 | #include <osmocom/ctrl/control_vty.h> |
| 47 | #include <osmocom/ctrl/ports.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 48 | #include <osmocom/vty/telnet_interface.h> |
| 49 | #include <osmocom/vty/logging.h> |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 50 | #include <osmocom/vty/command.h> |
Neels Hofmeyr | 2c56f6d | 2017-12-20 02:31:49 +0100 | [diff] [blame] | 51 | #include <osmocom/vty/ports.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 52 | |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 53 | #include <osmocom/netif/stream.h> |
| 54 | |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 55 | #include <osmocom/ranap/ranap_common.h> |
| 56 | |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 57 | #include <osmocom/sigtran/protocol/m3ua.h> |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 58 | #include <osmocom/sigtran/sccp_sap.h> |
| 59 | |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 60 | #include <osmocom/iuh/hnbgw.h> |
| 61 | #include <osmocom/iuh/hnbgw_hnbap.h> |
| 62 | #include <osmocom/iuh/hnbgw_rua.h> |
| 63 | #include <osmocom/iuh/hnbgw_cn.h> |
| 64 | #include <osmocom/iuh/context_map.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 65 | |
Neels Hofmeyr | 4c45d2b | 2016-08-18 02:10:57 +0200 | [diff] [blame] | 66 | static const char * const osmo_hnbgw_copyright = |
| 67 | "OsmoHNBGW - Osmocom Home Node B Gateway implementation\r\n" |
| 68 | "Copyright (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>\r\n" |
| 69 | "Contributions by Daniel Willmann, Harald Welte, Neels Hofmeyr\r\n" |
| 70 | "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n" |
| 71 | "This is free software: you are free to change and redistribute it.\r\n" |
| 72 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
| 73 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 74 | static void *tall_hnb_ctx; |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 75 | void *talloc_asn1_ctx; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 76 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 77 | static struct hnb_gw *g_hnb_gw; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 78 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 79 | static struct hnb_gw *hnb_gw_create(void *ctx) |
| 80 | { |
| 81 | struct hnb_gw *gw = talloc_zero(ctx, struct hnb_gw); |
| 82 | |
Neels Hofmeyr | 6e3e594 | 2016-10-27 13:13:50 +0200 | [diff] [blame] | 83 | /* strdup so we can easily talloc_free in the VTY code */ |
| 84 | gw->config.iuh_local_ip = talloc_strdup(gw, HNBGW_LOCAL_IP_DEFAULT); |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 85 | gw->config.iuh_local_port = IUH_DEFAULT_SCTP_PORT; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 86 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 87 | gw->next_ue_ctx_id = 23; |
| 88 | INIT_LLIST_HEAD(&gw->hnb_list); |
| 89 | INIT_LLIST_HEAD(&gw->ue_list); |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 90 | |
| 91 | context_map_init(gw); |
| 92 | |
| 93 | return gw; |
| 94 | } |
| 95 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 96 | struct hnb_context *hnb_context_by_id(struct hnb_gw *gw, uint32_t cid) |
| 97 | { |
| 98 | struct hnb_context *hnb; |
| 99 | |
| 100 | llist_for_each_entry(hnb, &gw->hnb_list, list) { |
| 101 | if (hnb->id.cid == cid) |
| 102 | return hnb; |
| 103 | } |
| 104 | |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Stefan Sperling | 319c285 | 2018-10-29 18:19:14 +0100 | [diff] [blame] | 108 | struct hnb_context *hnb_context_by_identity_info(struct hnb_gw *gw, const char *identity_info) |
| 109 | { |
| 110 | struct hnb_context *hnb; |
| 111 | |
| 112 | llist_for_each_entry(hnb, &gw->hnb_list, list) { |
| 113 | if (strcmp(identity_info, hnb->identity_info) == 0) |
| 114 | return hnb; |
| 115 | } |
| 116 | |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 121 | unsigned hnb_contexts(const struct hnb_gw *gw) |
| 122 | { |
| 123 | unsigned num_ctx = 0; |
| 124 | struct hnb_context *hnb; |
| 125 | |
| 126 | llist_for_each_entry(hnb, &gw->hnb_list, list) { |
| 127 | num_ctx++; |
| 128 | } |
| 129 | |
| 130 | return num_ctx; |
| 131 | } |
| 132 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 133 | struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id) |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 134 | { |
| 135 | struct ue_context *ue; |
| 136 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 137 | llist_for_each_entry(ue, &gw->ue_list, list) { |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 138 | if (ue->context_id == id) |
| 139 | return ue; |
| 140 | } |
| 141 | return NULL; |
| 142 | |
| 143 | } |
| 144 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 145 | 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] | 146 | { |
| 147 | struct ue_context *ue; |
| 148 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 149 | llist_for_each_entry(ue, &gw->ue_list, list) { |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 150 | if (!strcmp(ue->imsi, imsi)) |
| 151 | return ue; |
| 152 | } |
| 153 | return NULL; |
| 154 | } |
| 155 | |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 156 | struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi) |
| 157 | { |
| 158 | struct ue_context *ue; |
| 159 | |
| 160 | llist_for_each_entry(ue, &gw->ue_list, list) { |
| 161 | if (ue->tmsi == tmsi) |
| 162 | return ue; |
| 163 | } |
| 164 | return NULL; |
| 165 | } |
| 166 | |
Daniel Willmann | 1ee089f | 2016-01-06 18:07:02 +0100 | [diff] [blame] | 167 | void ue_context_free_by_hnb(struct hnb_gw *gw, const struct hnb_context *hnb) |
| 168 | { |
| 169 | struct ue_context *ue, *tmp; |
| 170 | |
| 171 | llist_for_each_entry_safe(ue, tmp, &gw->ue_list, list) { |
| 172 | if (ue->hnb == hnb) |
| 173 | ue_context_free(ue); |
| 174 | } |
| 175 | } |
| 176 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 177 | static uint32_t get_next_ue_ctx_id(struct hnb_gw *gw) |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 178 | { |
| 179 | uint32_t id; |
| 180 | |
| 181 | do { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 182 | id = gw->next_ue_ctx_id++; |
| 183 | } while (ue_context_by_id(gw, id)); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 184 | |
| 185 | return id; |
| 186 | } |
| 187 | |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 188 | struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi, |
| 189 | uint32_t tmsi) |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 190 | { |
| 191 | struct ue_context *ue; |
| 192 | |
| 193 | ue = talloc_zero(tall_hnb_ctx, struct ue_context); |
| 194 | if (!ue) |
| 195 | return NULL; |
| 196 | |
| 197 | ue->hnb = hnb; |
Harald Welte | e08cdd9 | 2016-11-26 00:01:53 +0100 | [diff] [blame] | 198 | if (imsi) { |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 199 | strncpy(ue->imsi, imsi, sizeof(ue->imsi)); |
Harald Welte | e08cdd9 | 2016-11-26 00:01:53 +0100 | [diff] [blame] | 200 | ue->imsi[sizeof(ue->imsi)-1] = '\0'; |
| 201 | } else |
Neels Hofmeyr | f33e835 | 2016-09-22 18:06:59 +0200 | [diff] [blame] | 202 | ue->imsi[0] = '\0'; |
| 203 | ue->tmsi = tmsi; |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 204 | ue->context_id = get_next_ue_ctx_id(hnb->gw); |
| 205 | llist_add_tail(&ue->list, &hnb->gw->ue_list); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 206 | |
Neels Hofmeyr | 0476e28 | 2016-09-22 19:37:29 +0200 | [diff] [blame] | 207 | LOGP(DHNBAP, LOGL_INFO, "created UE context: id 0x%x, imsi %s, tmsi 0x%x\n", |
| 208 | ue->context_id, imsi? imsi : "-", tmsi); |
| 209 | |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 210 | return ue; |
| 211 | } |
| 212 | |
| 213 | void ue_context_free(struct ue_context *ue) |
| 214 | { |
| 215 | llist_del(&ue->list); |
| 216 | talloc_free(ue); |
| 217 | } |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 218 | |
| 219 | static int hnb_read_cb(struct osmo_stream_srv *conn) |
| 220 | { |
| 221 | struct hnb_context *hnb = osmo_stream_srv_get_data(conn); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 222 | struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 223 | int rc; |
| 224 | |
| 225 | if (!msg) |
| 226 | return -ENOMEM; |
| 227 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 228 | /* we store a reference to the HomeNodeB in the msg->dest for the |
| 229 | * benefit of varoius downstream processing functions */ |
| 230 | msg->dst = hnb; |
| 231 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 232 | rc = osmo_stream_srv_recv(conn, msg); |
| 233 | if (rc == -EAGAIN) { |
| 234 | /* Notification received */ |
| 235 | msgb_free(msg); |
| 236 | return 0; |
| 237 | } else if (rc < 0) { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 238 | LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 239 | /* FIXME: clean up after disappeared HNB */ |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 240 | hnb_context_release(hnb); |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 241 | goto out; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 242 | } else if (rc == 0) { |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 243 | hnb_context_release(hnb); |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 244 | rc = -1; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 245 | |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 246 | goto out; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 247 | } else { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 248 | msgb_put(msg, rc); |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 249 | } |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 250 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 251 | switch (msgb_sctp_ppid(msg)) { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 252 | case IUH_PPI_HNBAP: |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 253 | hnb->hnbap_stream = msgb_sctp_stream(msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 254 | rc = hnbgw_hnbap_rx(hnb, msg); |
| 255 | break; |
| 256 | case IUH_PPI_RUA: |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 257 | hnb->rua_stream = msgb_sctp_stream(msg); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 258 | rc = hnbgw_rua_rx(hnb, msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 259 | break; |
| 260 | case IUH_PPI_SABP: |
| 261 | case IUH_PPI_RNA: |
| 262 | case IUH_PPI_PUA: |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 263 | LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%lu received\n", |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 264 | msgb_sctp_ppid(msg)); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 265 | rc = 0; |
| 266 | break; |
| 267 | default: |
Harald Welte | da86fe5 | 2017-11-21 08:14:37 +0100 | [diff] [blame] | 268 | LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%lu received\n", |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 269 | msgb_sctp_ppid(msg)); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 270 | rc = 0; |
| 271 | break; |
| 272 | } |
| 273 | |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 274 | out: |
Harald Welte | f2f3000 | 2015-09-08 00:09:23 +0200 | [diff] [blame] | 275 | msgb_free(msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 276 | return rc; |
| 277 | } |
| 278 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 279 | 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] | 280 | { |
| 281 | struct hnb_context *ctx; |
| 282 | |
| 283 | ctx = talloc_zero(tall_hnb_ctx, struct hnb_context); |
| 284 | if (!ctx) |
| 285 | return NULL; |
Neels Hofmeyr | 44beab9 | 2016-02-18 01:26:59 +0100 | [diff] [blame] | 286 | INIT_LLIST_HEAD(&ctx->map_list); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 287 | |
| 288 | ctx->gw = gw; |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 289 | ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, NULL, ctx); |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 290 | if (!ctx->conn) { |
| 291 | LOGP(DMAIN, LOGL_INFO, "error while creating connection\n"); |
Neels Hofmeyr | 44beab9 | 2016-02-18 01:26:59 +0100 | [diff] [blame] | 292 | talloc_free(ctx); |
| 293 | return NULL; |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 294 | } |
| 295 | |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 296 | llist_add_tail(&ctx->list, &gw->hnb_list); |
Neels Hofmeyr | 44beab9 | 2016-02-18 01:26:59 +0100 | [diff] [blame] | 297 | return ctx; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 300 | void hnb_context_release(struct hnb_context *ctx) |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 301 | { |
| 302 | struct hnbgw_context_map *map, *map2; |
| 303 | |
| 304 | /* remove from the list of HNB contexts */ |
| 305 | llist_del(&ctx->list); |
| 306 | |
| 307 | /* deactivate all context maps */ |
| 308 | llist_for_each_entry_safe(map, map2, &ctx->map_list, hnb_list) { |
| 309 | /* remove it from list, as HNB context will soon be |
Neels Hofmeyr | 525a69e | 2016-04-19 17:54:25 +0200 | [diff] [blame] | 310 | * gone. Let's hope the second osmo_llist_del in the |
| 311 | * map garbage collector works fine? */ |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 312 | llist_del(&map->hnb_list); |
Neels Hofmeyr | 0a46156 | 2016-04-23 13:53:28 +0200 | [diff] [blame] | 313 | llist_del(&map->cn_list); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 314 | context_map_deactivate(map); |
| 315 | } |
Daniel Willmann | 1ee089f | 2016-01-06 18:07:02 +0100 | [diff] [blame] | 316 | ue_context_free_by_hnb(ctx->gw, ctx); |
Stefan Sperling | c964a2c | 2018-02-19 17:02:12 +0100 | [diff] [blame] | 317 | |
Alexander Couzens | ad4ea3b | 2018-07-24 19:04:47 +0200 | [diff] [blame] | 318 | osmo_stream_srv_destroy(ctx->conn); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 319 | |
| 320 | talloc_free(ctx); |
| 321 | } |
| 322 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 323 | /*! call-back when the listen FD has something to read */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 324 | static int accept_cb(struct osmo_stream_srv_link *srv, int fd) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 325 | { |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 326 | struct hnb_gw *gw = osmo_stream_srv_link_get_data(srv); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 327 | struct hnb_context *ctx; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 328 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 329 | ctx = hnb_context_alloc(gw, srv, fd); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 330 | if (!ctx) |
| 331 | return -ENOMEM; |
| 332 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 336 | static const struct log_info_cat log_cat[] = { |
| 337 | [DMAIN] = { |
Neels Hofmeyr | 6341f4d | 2016-04-04 18:02:49 +0200 | [diff] [blame] | 338 | .name = "DMAIN", .loglevel = LOGL_DEBUG, .enabled = 1, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 339 | .color = "", |
| 340 | .description = "Main program", |
| 341 | }, |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 342 | [DHNBAP] = { |
| 343 | .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 344 | .color = "", |
| 345 | .description = "Home Node B Application Part", |
| 346 | }, |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 347 | [DRUA] = { |
| 348 | .name = "DRUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 349 | .color = "", |
| 350 | .description = "RANAP User Adaptation", |
| 351 | }, |
| 352 | [DRANAP] = { |
| 353 | .name = "DRANAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 354 | .color = "", |
| 355 | .description = "RAN Application Part", |
| 356 | }, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 357 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 358 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 359 | static const struct log_info hnbgw_log_info = { |
| 360 | .cat = log_cat, |
| 361 | .num_cat = ARRAY_SIZE(log_cat), |
| 362 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 363 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 364 | static struct vty_app_info vty_info = { |
| 365 | .name = "OsmoHNBGW", |
Max | 1e57ba5 | 2017-12-28 12:27:41 +0100 | [diff] [blame] | 366 | .version = PACKAGE_VERSION, |
Neels Hofmeyr | c510fc2 | 2016-10-13 16:58:04 +0200 | [diff] [blame] | 367 | .go_parent_cb = hnbgw_vty_go_parent, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 368 | }; |
| 369 | |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 370 | static struct { |
| 371 | int daemonize; |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 372 | const char *config_file; |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 373 | bool log_disable_color; |
| 374 | bool log_enable_timestamp; |
| 375 | int log_level; |
| 376 | const char *log_category_mask; |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 377 | } hnbgw_cmdline_config = { |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 378 | 0, |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 379 | "osmo-hnbgw.cfg", |
Neels Hofmeyr | 3c83996 | 2019-03-04 22:30:01 +0100 | [diff] [blame] | 380 | false, |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 381 | false, |
| 382 | 0, |
| 383 | NULL, |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | static void print_usage() |
| 387 | { |
| 388 | printf("Usage: osmo-hnbgw\n"); |
| 389 | } |
| 390 | |
| 391 | static void print_help() |
| 392 | { |
| 393 | printf(" -h --help This text.\n"); |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 394 | printf(" -d option --debug=DHNBAP:DRUA:DRANAP:DMAIN Enable debugging.\n"); |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 395 | printf(" -D --daemonize Fork the process into a background daemon.\n"); |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 396 | printf(" -c --config-file filename The config file to use.\n"); |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 397 | printf(" -s --disable-color\n"); |
| 398 | printf(" -T --timestamp Prefix every log line with a timestamp.\n"); |
| 399 | printf(" -V --version Print the version of OsmoHNBGW.\n"); |
| 400 | printf(" -e --log-level number Set a global loglevel.\n"); |
| 401 | } |
| 402 | |
| 403 | static void handle_options(int argc, char **argv) |
| 404 | { |
| 405 | while (1) { |
| 406 | int option_index = 0, c; |
| 407 | static struct option long_options[] = { |
| 408 | {"help", 0, 0, 'h'}, |
| 409 | {"debug", 1, 0, 'd'}, |
| 410 | {"daemonize", 0, 0, 'D'}, |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 411 | {"config-file", 1, 0, 'c'}, |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 412 | {"disable-color", 0, 0, 's'}, |
| 413 | {"timestamp", 0, 0, 'T'}, |
| 414 | {"version", 0, 0, 'V' }, |
| 415 | {"log-level", 1, 0, 'e'}, |
| 416 | {0, 0, 0, 0} |
| 417 | }; |
| 418 | |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 419 | c = getopt_long(argc, argv, "hd:Dc:sTVe:", |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 420 | long_options, &option_index); |
| 421 | if (c == -1) |
| 422 | break; |
| 423 | |
| 424 | switch (c) { |
| 425 | case 'h': |
| 426 | print_usage(); |
| 427 | print_help(); |
| 428 | exit(0); |
| 429 | case 's': |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 430 | hnbgw_cmdline_config.log_disable_color = true; |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 431 | break; |
| 432 | case 'd': |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 433 | hnbgw_cmdline_config.log_category_mask = optarg; |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 434 | break; |
| 435 | case 'D': |
| 436 | hnbgw_cmdline_config.daemonize = 1; |
| 437 | break; |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 438 | case 'c': |
| 439 | hnbgw_cmdline_config.config_file = optarg; |
| 440 | break; |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 441 | case 'T': |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 442 | hnbgw_cmdline_config.log_enable_timestamp = true; |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 443 | break; |
| 444 | case 'e': |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 445 | hnbgw_cmdline_config.log_level = atoi(optarg); |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 446 | break; |
| 447 | case 'V': |
| 448 | print_version(1); |
| 449 | exit(0); |
| 450 | break; |
| 451 | default: |
| 452 | /* catch unknown options *as well as* missing arguments. */ |
| 453 | fprintf(stderr, "Error in command line options. Exiting.\n"); |
| 454 | exit(-1); |
| 455 | break; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 460 | CTRL_CMD_DEFINE_RO(hnb_info, "info"); |
| 461 | static int get_hnb_info(struct ctrl_cmd *cmd, void *data) |
| 462 | { |
| 463 | struct hnb_context *hnb = data; |
| 464 | |
| 465 | cmd->reply = talloc_strdup(cmd, hnb->identity_info); |
| 466 | |
| 467 | return CTRL_CMD_REPLY; |
| 468 | } |
| 469 | |
| 470 | CTRL_CMD_DEFINE_RO(hnbs, "num-hnb"); |
| 471 | static int get_hnbs(struct ctrl_cmd *cmd, void *data) |
| 472 | { |
| 473 | cmd->reply = talloc_asprintf(cmd, "%u", hnb_contexts(data)); |
| 474 | |
| 475 | return CTRL_CMD_REPLY; |
| 476 | } |
| 477 | |
| 478 | int hnb_ctrl_cmds_install() |
| 479 | { |
| 480 | int rc = 0; |
| 481 | |
| 482 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_hnbs); |
| 483 | rc |= ctrl_cmd_install(CTRL_NODE_HNB, &cmd_hnb_info); |
| 484 | |
| 485 | return rc; |
| 486 | } |
| 487 | |
| 488 | static int hnb_ctrl_node_lookup(void *data, vector vline, int *node_type, void **node_data, int *i) |
| 489 | { |
| 490 | const char *token = vector_slot(vline, *i); |
| 491 | struct hnb_context *hnb; |
| 492 | long num; |
| 493 | |
| 494 | switch (*node_type) { |
| 495 | case CTRL_NODE_ROOT: |
| 496 | if (strcmp(token, "hnb") != 0) |
| 497 | return 0; |
| 498 | |
| 499 | (*i)++; |
| 500 | |
| 501 | if (!ctrl_parse_get_num(vline, *i, &num)) |
| 502 | return -ERANGE; |
| 503 | |
| 504 | hnb = hnb_context_by_id(data, num); |
| 505 | if (!hnb) |
| 506 | return -ENODEV; |
| 507 | |
| 508 | *node_data = hnb; |
| 509 | *node_type = CTRL_NODE_HNB; |
| 510 | break; |
| 511 | default: |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | return 1; |
| 516 | } |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 517 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 518 | int main(int argc, char **argv) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 519 | { |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 520 | struct osmo_stream_srv_link *srv; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 521 | int rc; |
| 522 | |
| 523 | tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 524 | talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context"); |
Neels Hofmeyr | 4ff1a5a | 2016-09-16 01:38:46 +0200 | [diff] [blame] | 525 | msgb_talloc_ctx_init(tall_hnb_ctx, 0); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 526 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 527 | g_hnb_gw = hnb_gw_create(tall_hnb_ctx); |
Neels Hofmeyr | a4540be | 2016-04-05 14:27:48 +0200 | [diff] [blame] | 528 | g_hnb_gw->config.rnc_id = 23; |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 529 | |
Neels Hofmeyr | f8d5f37 | 2019-03-04 22:30:20 +0100 | [diff] [blame] | 530 | rc = osmo_init_logging2(tall_hnb_ctx, &hnbgw_log_info); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 531 | if (rc < 0) |
| 532 | exit(1); |
| 533 | |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 534 | osmo_ss7_init(); |
| 535 | |
Neels Hofmeyr | 4c45d2b | 2016-08-18 02:10:57 +0200 | [diff] [blame] | 536 | vty_info.copyright = osmo_hnbgw_copyright; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 537 | vty_init(&vty_info); |
Neels Hofmeyr | 4c45d2b | 2016-08-18 02:10:57 +0200 | [diff] [blame] | 538 | |
Neels Hofmeyr | ecbdc5c | 2017-07-31 13:13:24 +0200 | [diff] [blame] | 539 | osmo_ss7_vty_init_asp(tall_hnb_ctx); |
Neels Hofmeyr | b876b42 | 2018-09-27 01:54:58 +0200 | [diff] [blame] | 540 | osmo_sccp_vty_init(); |
Neels Hofmeyr | 4d8eb4c | 2016-08-18 01:03:44 +0200 | [diff] [blame] | 541 | hnbgw_vty_init(g_hnb_gw, tall_hnb_ctx); |
Pau Espin Pedrol | 92ea15a | 2019-08-05 14:49:35 +0200 | [diff] [blame] | 542 | logging_vty_add_cmds(); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 543 | |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 544 | /* Handle options after vty_init(), for --version */ |
| 545 | handle_options(argc, argv); |
| 546 | |
Neels Hofmeyr | 085cd67 | 2016-08-17 13:54:00 +0200 | [diff] [blame] | 547 | rc = vty_read_config_file(hnbgw_cmdline_config.config_file, NULL); |
| 548 | if (rc < 0) { |
| 549 | LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n", |
| 550 | hnbgw_cmdline_config.config_file); |
| 551 | return 1; |
| 552 | } |
| 553 | |
Neels Hofmeyr | 1d03f19 | 2016-08-18 03:15:14 +0200 | [diff] [blame] | 554 | /* |
| 555 | * cmdline options take precedence over config file, but if no options |
| 556 | * were passed we must not override the config file. |
| 557 | */ |
| 558 | if (hnbgw_cmdline_config.log_disable_color) |
| 559 | log_set_use_color(osmo_stderr_target, 0); |
| 560 | if (hnbgw_cmdline_config.log_category_mask) |
| 561 | log_parse_category_mask(osmo_stderr_target, |
| 562 | hnbgw_cmdline_config.log_category_mask); |
| 563 | if (hnbgw_cmdline_config.log_enable_timestamp) |
| 564 | log_set_print_timestamp(osmo_stderr_target, 1); |
| 565 | if (hnbgw_cmdline_config.log_level) |
| 566 | log_set_log_level(osmo_stderr_target, |
| 567 | hnbgw_cmdline_config.log_level); |
| 568 | |
Neels Hofmeyr | ade7e8b | 2017-12-20 02:33:44 +0100 | [diff] [blame] | 569 | rc = telnet_init_dynif(tall_hnb_ctx, g_hnb_gw, vty_get_bind_addr(), OSMO_VTY_PORT_HNBGW); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 570 | if (rc < 0) { |
| 571 | perror("Error binding VTY port"); |
| 572 | exit(1); |
| 573 | } |
| 574 | |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 575 | g_hnb_gw->ctrl = ctrl_interface_setup_dynip2(g_hnb_gw, ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_HNBGW, |
| 576 | hnb_ctrl_node_lookup, _LAST_CTRL_NODE_HNB); |
Max | ef72741 | 2017-12-26 19:27:43 +0100 | [diff] [blame] | 577 | if (!g_hnb_gw->ctrl) { |
| 578 | LOGP(DMAIN, LOGL_ERROR, "Failed to create CTRL interface on %s:%u\n", |
| 579 | ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_HNBGW); |
| 580 | exit(1); |
Max | bfeea67 | 2017-12-27 22:53:36 +0100 | [diff] [blame] | 581 | } else { |
| 582 | rc = hnb_ctrl_cmds_install(); |
| 583 | if (rc) { |
| 584 | LOGP(DMAIN, LOGL_ERROR, "Failed to install CTRL interface commands\n"); |
| 585 | return 2; |
| 586 | } |
Max | ef72741 | 2017-12-26 19:27:43 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 589 | ranap_set_log_area(DRANAP); |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 590 | |
Neels Hofmeyr | accb780 | 2017-12-04 15:24:32 +0100 | [diff] [blame] | 591 | rc = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.1", M3UA_PORT, NULL); |
Neels Hofmeyr | 0f88c11 | 2017-07-03 16:49:43 +0200 | [diff] [blame] | 592 | if (rc < 0) { |
| 593 | LOGP(DMAIN, LOGL_ERROR, "Failed to initialize SCCP link to CN\n"); |
| 594 | exit(1); |
| 595 | } |
| 596 | |
Neels Hofmeyr | 4e2681d | 2017-12-24 23:54:07 +0100 | [diff] [blame] | 597 | LOGP(DHNBAP, LOGL_NOTICE, "Using RNC-Id %u\n", g_hnb_gw->config.rnc_id); |
| 598 | |
Neels Hofmeyr | 6e3e594 | 2016-10-27 13:13:50 +0200 | [diff] [blame] | 599 | OSMO_ASSERT(g_hnb_gw->config.iuh_local_ip); |
Neels Hofmeyr | f495b23 | 2016-08-18 02:18:00 +0200 | [diff] [blame] | 600 | LOGP(DMAIN, LOGL_NOTICE, "Listening for Iuh at %s %d\n", |
Neels Hofmeyr | 6e3e594 | 2016-10-27 13:13:50 +0200 | [diff] [blame] | 601 | g_hnb_gw->config.iuh_local_ip, |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 602 | g_hnb_gw->config.iuh_local_port); |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 603 | srv = osmo_stream_srv_link_create(tall_hnb_ctx); |
| 604 | if (!srv) { |
| 605 | perror("cannot create server"); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 606 | exit(1); |
| 607 | } |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 608 | osmo_stream_srv_link_set_data(srv, g_hnb_gw); |
| 609 | osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP); |
Neels Hofmeyr | 6e3e594 | 2016-10-27 13:13:50 +0200 | [diff] [blame] | 610 | osmo_stream_srv_link_set_addr(srv, g_hnb_gw->config.iuh_local_ip); |
Neels Hofmeyr | c7ccdd4 | 2016-10-13 14:43:49 +0200 | [diff] [blame] | 611 | osmo_stream_srv_link_set_port(srv, g_hnb_gw->config.iuh_local_port); |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 612 | osmo_stream_srv_link_set_accept_cb(srv, accept_cb); |
| 613 | |
| 614 | if (osmo_stream_srv_link_open(srv) < 0) { |
Neels Hofmeyr | de111bc | 2016-01-13 11:54:40 +0100 | [diff] [blame] | 615 | perror("Cannot open server"); |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 616 | exit(1); |
| 617 | } |
| 618 | g_hnb_gw->iuh = srv; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 619 | |
Neels Hofmeyr | 4d675a7 | 2016-08-17 13:53:18 +0200 | [diff] [blame] | 620 | if (hnbgw_cmdline_config.daemonize) { |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 621 | rc = osmo_daemonize(); |
| 622 | if (rc < 0) { |
| 623 | perror("Error during daemonize"); |
| 624 | exit(1); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | while (1) { |
| 629 | rc = osmo_select_main(0); |
| 630 | if (rc < 0) |
| 631 | exit(3); |
| 632 | } |
| 633 | |
| 634 | /* not reached */ |
| 635 | exit(0); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 636 | } |