blob: 23537087afb49ccf596043427b67ca0be7786367 [file] [log] [blame]
Harald Welte77847ad2015-10-06 22:07:04 +02001/* main application for hnb-gw part of osmo-iuh */
2
3/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
Harald Welteb3dae302015-08-30 12:20:09 +020021#include <unistd.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <getopt.h>
26#include <errno.h>
27#include <signal.h>
Harald Weltea2e6a7a2015-08-29 21:47:39 +020028
Harald Welteb3dae302015-08-30 12:20:09 +020029#include <sys/types.h>
30#include <sys/socket.h>
Harald Welte1d2c39d2015-09-11 17:49:37 +020031#include <netinet/in.h>
Harald Welteb3dae302015-08-30 12:20:09 +020032#include <netinet/sctp.h>
Harald Welte1d2c39d2015-09-11 17:49:37 +020033#include <arpa/inet.h>
Harald Welteb3dae302015-08-30 12:20:09 +020034
35#include <osmocom/core/application.h>
36#include <osmocom/core/talloc.h>
Harald Weltea2e6a7a2015-08-29 21:47:39 +020037#include <osmocom/core/select.h>
Harald Welteb3dae302015-08-30 12:20:09 +020038#include <osmocom/core/logging.h>
Harald Weltea2e6a7a2015-08-29 21:47:39 +020039#include <osmocom/core/socket.h>
Harald Welteb3dae302015-08-30 12:20:09 +020040#include <osmocom/core/msgb.h>
Harald Welte3f712562015-09-07 21:53:25 +020041#include <osmocom/core/write_queue.h>
Harald Welteb3dae302015-08-30 12:20:09 +020042
43#include <osmocom/vty/telnet_interface.h>
44#include <osmocom/vty/logging.h>
Daniel Willmann56f62732015-12-02 11:22:53 +010045#include <osmocom/vty/command.h>
Harald Weltea2e6a7a2015-08-29 21:47:39 +020046
Harald Welteffa7c0a2015-12-23 00:03:41 +010047#include <osmocom/netif/stream.h>
48
Harald Welte75a4e652015-12-22 23:59:24 +010049#include <osmocom/sigtran/sua.h>
50#include <osmocom/sigtran/protocol/sua.h>
51#include <osmocom/sigtran/sccp_sap.h>
52
Harald Weltea2e6a7a2015-08-29 21:47:39 +020053#include "hnbgw.h"
Harald Welteb3dae302015-08-30 12:20:09 +020054#include "hnbgw_hnbap.h"
Harald Welte318e4d52015-09-10 18:47:08 +020055#include "hnbgw_rua.h"
Harald Weltec4338de2015-12-24 00:40:52 +010056#include "hnbgw_cn.h"
Harald Welte90256ba2015-12-23 20:16:36 +010057#include "context_map.h"
Harald Welteb3dae302015-08-30 12:20:09 +020058
59static void *tall_hnb_ctx;
Harald Welte08de6382015-08-31 09:54:45 +020060void *talloc_asn1_ctx;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020061
Harald Weltec4338de2015-12-24 00:40:52 +010062static struct hnb_gw *g_hnb_gw;
Harald Weltea2e6a7a2015-08-29 21:47:39 +020063
Harald Weltec4338de2015-12-24 00:40:52 +010064static int listen_fd_cb(struct osmo_fd *fd, unsigned int what);
65
66static struct hnb_gw *hnb_gw_create(void *ctx)
67{
68 struct hnb_gw *gw = talloc_zero(ctx, struct hnb_gw);
69
70 gw->config.iuh_listen_port = IUH_DEFAULT_SCTP_PORT;
71
Harald Weltec4338de2015-12-24 00:40:52 +010072 gw->next_ue_ctx_id = 23;
73 INIT_LLIST_HEAD(&gw->hnb_list);
74 INIT_LLIST_HEAD(&gw->ue_list);
75 INIT_LLIST_HEAD(&gw->cn_list);
76
77 context_map_init(gw);
78
79 return gw;
80}
81
82struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id)
Harald Welteb534e5c2015-09-11 00:15:16 +020083{
84 struct ue_context *ue;
85
Harald Weltec4338de2015-12-24 00:40:52 +010086 llist_for_each_entry(ue, &gw->ue_list, list) {
Harald Welteb534e5c2015-09-11 00:15:16 +020087 if (ue->context_id == id)
88 return ue;
89 }
90 return NULL;
91
92}
93
Harald Weltec4338de2015-12-24 00:40:52 +010094struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi)
Harald Welteb534e5c2015-09-11 00:15:16 +020095{
96 struct ue_context *ue;
97
Harald Weltec4338de2015-12-24 00:40:52 +010098 llist_for_each_entry(ue, &gw->ue_list, list) {
Harald Welteb534e5c2015-09-11 00:15:16 +020099 if (!strcmp(ue->imsi, imsi))
100 return ue;
101 }
102 return NULL;
103}
104
Daniel Willmann1ee089f2016-01-06 18:07:02 +0100105void ue_context_free_by_hnb(struct hnb_gw *gw, const struct hnb_context *hnb)
106{
107 struct ue_context *ue, *tmp;
108
109 llist_for_each_entry_safe(ue, tmp, &gw->ue_list, list) {
110 if (ue->hnb == hnb)
111 ue_context_free(ue);
112 }
113}
114
Harald Weltec4338de2015-12-24 00:40:52 +0100115static uint32_t get_next_ue_ctx_id(struct hnb_gw *gw)
Harald Welteb534e5c2015-09-11 00:15:16 +0200116{
117 uint32_t id;
118
119 do {
Harald Weltec4338de2015-12-24 00:40:52 +0100120 id = gw->next_ue_ctx_id++;
121 } while (ue_context_by_id(gw, id));
Harald Welteb534e5c2015-09-11 00:15:16 +0200122
123 return id;
124}
125
126struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi)
127{
128 struct ue_context *ue;
129
130 ue = talloc_zero(tall_hnb_ctx, struct ue_context);
131 if (!ue)
132 return NULL;
133
134 ue->hnb = hnb;
135 strncpy(ue->imsi, imsi, sizeof(ue->imsi));
Harald Weltec4338de2015-12-24 00:40:52 +0100136 ue->context_id = get_next_ue_ctx_id(hnb->gw);
137 llist_add_tail(&ue->list, &hnb->gw->ue_list);
Harald Welteb534e5c2015-09-11 00:15:16 +0200138
139 return ue;
140}
141
142void ue_context_free(struct ue_context *ue)
143{
144 llist_del(&ue->list);
145 talloc_free(ue);
146}
Daniel Willmann6480cad2016-01-06 18:06:26 +0100147static int hnb_close_cb(struct osmo_stream_srv *conn)
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200148{
Daniel Willmann6480cad2016-01-06 18:06:26 +0100149}
150
151static int hnb_read_cb(struct osmo_stream_srv *conn)
152{
153 struct hnb_context *hnb = osmo_stream_srv_get_data(conn);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200154 struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx");
Harald Welte3f712562015-09-07 21:53:25 +0200155 int flags = 0;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200156 int rc;
157
158 if (!msg)
159 return -ENOMEM;
160
Harald Welte350814a2015-09-10 22:32:15 +0200161 /* we store a reference to the HomeNodeB in the msg->dest for the
162 * benefit of varoius downstream processing functions */
163 msg->dst = hnb;
164
Daniel Willmann6480cad2016-01-06 18:06:26 +0100165 rc = osmo_stream_srv_recv(conn, msg);
166 if (rc == -EAGAIN) {
167 /* Notification received */
168 msgb_free(msg);
169 return 0;
170 } else if (rc < 0) {
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200171 LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n");
Harald Welteee77cff2015-08-30 16:57:53 +0200172 /* FIXME: clean up after disappeared HNB */
Daniel Willmann6480cad2016-01-06 18:06:26 +0100173 hnb_context_release(hnb);
Daniel Willmann269b8ac2015-12-22 16:26:48 +0100174 goto out;
Daniel Willmann4267a292015-12-15 20:29:27 +0100175 } else if (rc == 0) {
Daniel Willmann6480cad2016-01-06 18:06:26 +0100176 hnb_context_release(hnb);
Daniel Willmann269b8ac2015-12-22 16:26:48 +0100177 rc = -1;
Daniel Willmann4267a292015-12-15 20:29:27 +0100178
Daniel Willmann269b8ac2015-12-22 16:26:48 +0100179 goto out;
Daniel Willmann4267a292015-12-15 20:29:27 +0100180 } else {
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200181 msgb_put(msg, rc);
Daniel Willmann4267a292015-12-15 20:29:27 +0100182 }
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200183
Daniel Willmann6480cad2016-01-06 18:06:26 +0100184 switch (msgb_sctp_ppid(msg)) {
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200185 case IUH_PPI_HNBAP:
Daniel Willmann6480cad2016-01-06 18:06:26 +0100186 hnb->hnbap_stream = msgb_sctp_stream(msg);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200187 rc = hnbgw_hnbap_rx(hnb, msg);
188 break;
189 case IUH_PPI_RUA:
Daniel Willmann6480cad2016-01-06 18:06:26 +0100190 hnb->rua_stream = msgb_sctp_stream(msg);
Harald Welte318e4d52015-09-10 18:47:08 +0200191 rc = hnbgw_rua_rx(hnb, msg);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200192 break;
193 case IUH_PPI_SABP:
194 case IUH_PPI_RNA:
195 case IUH_PPI_PUA:
196 LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n",
Daniel Willmann6480cad2016-01-06 18:06:26 +0100197 msgb_sctp_ppid(msg));
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200198 rc = 0;
199 break;
200 default:
201 LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n",
Daniel Willmann6480cad2016-01-06 18:06:26 +0100202 msgb_sctp_ppid(msg));
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200203 rc = 0;
204 break;
205 }
206
Daniel Willmann269b8ac2015-12-22 16:26:48 +0100207out:
Harald Weltef2f30002015-09-08 00:09:23 +0200208 msgb_free(msg);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200209 return rc;
210}
211
Harald Welte3f712562015-09-07 21:53:25 +0200212static int hnb_write_cb(struct osmo_fd *fd, struct msgb *msg)
213{
214 struct hnb_context *ctx = fd->data;
215 struct sctp_sndrcvinfo sinfo = {
Harald Welteffa7c0a2015-12-23 00:03:41 +0100216 .sinfo_ppid = htonl(msgb_sctp_ppid(msg)),
Harald Welte3f712562015-09-07 21:53:25 +0200217 .sinfo_stream = ctx->hnbap_stream,
218 };
219 int rc;
220
221 rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg),
222 &sinfo, 0);
Harald Welte9e270b42015-09-07 22:41:26 +0200223 /* we don't need to msgb_free(), write_queue does this for us */
Harald Welte3f712562015-09-07 21:53:25 +0200224 return rc;
225}
226
Daniel Willmann6480cad2016-01-06 18:06:26 +0100227struct 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 +0100228{
229 struct hnb_context *ctx;
230
231 ctx = talloc_zero(tall_hnb_ctx, struct hnb_context);
232 if (!ctx)
233 return NULL;
Neels Hofmeyr44beab92016-02-18 01:26:59 +0100234 INIT_LLIST_HEAD(&ctx->map_list);
Harald Welte90256ba2015-12-23 20:16:36 +0100235
236 ctx->gw = gw;
Daniel Willmann6480cad2016-01-06 18:06:26 +0100237 ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, hnb_close_cb, ctx);
238 if (!ctx->conn) {
239 LOGP(DMAIN, LOGL_INFO, "error while creating connection\n");
Neels Hofmeyr44beab92016-02-18 01:26:59 +0100240 talloc_free(ctx);
241 return NULL;
Daniel Willmann6480cad2016-01-06 18:06:26 +0100242 }
243
Harald Welte90256ba2015-12-23 20:16:36 +0100244 llist_add_tail(&ctx->list, &gw->hnb_list);
Neels Hofmeyr44beab92016-02-18 01:26:59 +0100245 return ctx;
Harald Welte90256ba2015-12-23 20:16:36 +0100246}
247
248void hnb_context_release(struct hnb_context *ctx)
249{
250 struct hnbgw_context_map *map, *map2;
251
252 /* remove from the list of HNB contexts */
253 llist_del(&ctx->list);
254
255 /* deactivate all context maps */
256 llist_for_each_entry_safe(map, map2, &ctx->map_list, hnb_list) {
257 /* remove it from list, as HNB context will soon be
258 * gone. Let's hope the seccond osmo_llist_del in the
259 * map garbage collector wors fine? */
260 llist_del(&map->hnb_list);
261 context_map_deactivate(map);
262 }
Daniel Willmann1ee089f2016-01-06 18:07:02 +0100263 ue_context_free_by_hnb(ctx->gw, ctx);
Daniel Willmann6480cad2016-01-06 18:06:26 +0100264 osmo_stream_srv_destroy(ctx->conn);
Harald Welte90256ba2015-12-23 20:16:36 +0100265
266 talloc_free(ctx);
267}
268
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200269/*! call-back when the listen FD has something to read */
Daniel Willmann6480cad2016-01-06 18:06:26 +0100270static int accept_cb(struct osmo_stream_srv_link *srv, int fd)
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200271{
Daniel Willmann6480cad2016-01-06 18:06:26 +0100272 struct hnb_gw *gw = osmo_stream_srv_link_get_data(srv);
Harald Welteb3dae302015-08-30 12:20:09 +0200273 struct hnb_context *ctx;
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200274
Daniel Willmann6480cad2016-01-06 18:06:26 +0100275 ctx = hnb_context_alloc(gw, srv, fd);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200276 if (!ctx)
277 return -ENOMEM;
278
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200279 return 0;
280}
281
Harald Welte75a4e652015-12-22 23:59:24 +0100282/* Entry point for primitives coming up from SCCP User SAP */
283static int sccp_sap_up(struct osmo_prim_hdr *oph, void *link)
284{
285 struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph;
286
287 LOGP(DMAIN, LOGL_DEBUG, "sccp_sap_up(%s)\n", osmo_scu_prim_name(oph));
288
289 /* FIXME: Do something */
290
291 msgb_free(oph->msg);
292
293 return 0;
294}
295
Harald Welteb3dae302015-08-30 12:20:09 +0200296static const struct log_info_cat log_cat[] = {
297 [DMAIN] = {
Daniel Willmann7c27f7b2015-12-15 17:41:41 +0100298 .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1,
Harald Welteb3dae302015-08-30 12:20:09 +0200299 .color = "",
300 .description = "Main program",
301 },
Daniel Willmannbded9842015-12-17 11:51:17 +0100302 [DHNBAP] = {
303 .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
304 .color = "",
305 .description = "Home Node B Application Part",
306 },
Harald Welte75a4e652015-12-22 23:59:24 +0100307 [DSUA] = {
308 .name = "DSUA", .loglevel = LOGL_DEBUG, .enabled = 1,
309 .color = "",
310 .description = "SCCP User Adaptation",
311 },
Harald Weltef42317b2015-12-23 15:36:31 +0100312 [DRUA] = {
313 .name = "DRUA", .loglevel = LOGL_DEBUG, .enabled = 1,
314 .color = "",
315 .description = "RANAP User Adaptation",
316 },
317 [DRANAP] = {
318 .name = "DRANAP", .loglevel = LOGL_DEBUG, .enabled = 1,
319 .color = "",
320 .description = "RAN Application Part",
321 },
Harald Welteb3dae302015-08-30 12:20:09 +0200322};
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200323
Harald Welteb3dae302015-08-30 12:20:09 +0200324static const struct log_info hnbgw_log_info = {
325 .cat = log_cat,
326 .num_cat = ARRAY_SIZE(log_cat),
327};
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200328
Harald Welteb3dae302015-08-30 12:20:09 +0200329static struct vty_app_info vty_info = {
330 .name = "OsmoHNBGW",
331 .version = "0",
332};
333
334static int daemonize = 0;
335
Daniel Willmann56f62732015-12-02 11:22:53 +0100336static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb)
337{
Daniel Willmann5f8c7182016-01-14 15:42:07 +0100338 struct hnbgw_context_map *map;
339
Daniel Willmann56f62732015-12-02 11:22:53 +0100340 vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info,
341 hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid,
342 VTY_NEWLINE);
343 vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE);
Daniel Willmann5f8c7182016-01-14 15:42:07 +0100344
345 llist_for_each_entry(map, &hnb->map_list, hnb_list) {
346 vty_out(vty, " Map %u->%u (RUA->SUA) cnlink=%p state=%u%s", map->rua_ctx_id, map->scu_conn_id,
347 map->cn_link, map->state, VTY_NEWLINE);
348
349 }
Daniel Willmann56f62732015-12-02 11:22:53 +0100350}
351
352static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue)
353{
354 vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE);
355}
356
357DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB")
358{
359 struct hnb_context *hnb;
360
Harald Weltec4338de2015-12-24 00:40:52 +0100361 llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) {
Daniel Willmann56f62732015-12-02 11:22:53 +0100362 vty_dump_hnb_info(vty, hnb);
363 }
364
365 return CMD_SUCCESS;
366}
367
368DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE")
369{
370 struct ue_context *ue;
371
Harald Weltec4338de2015-12-24 00:40:52 +0100372 llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) {
Daniel Willmann56f62732015-12-02 11:22:53 +0100373 vty_dump_ue_info(vty, ue);
374 }
375
376 return CMD_SUCCESS;
377}
378
Daniel Willmann28b9ec12015-12-17 18:02:37 +0100379DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info")
380{
381 talloc_report_full(tall_hnb_ctx, stderr);
Daniel Willmann28b9ec12015-12-17 18:02:37 +0100382 talloc_report_full(talloc_asn1_ctx, stderr);
383
384 return CMD_SUCCESS;
385}
386
Daniel Willmann56f62732015-12-02 11:22:53 +0100387static void hnbgw_vty_init(void)
388{
389 install_element_ve(&show_hnb_cmd);
390 install_element_ve(&show_ue_cmd);
Daniel Willmann28b9ec12015-12-17 18:02:37 +0100391 install_element_ve(&show_talloc_cmd);
Neels Hofmeyr110bb5c2016-02-11 17:51:11 +0100392
393 logging_vty_add_cmds(&hnbgw_log_info);
Daniel Willmann56f62732015-12-02 11:22:53 +0100394}
395
Harald Welteb3dae302015-08-30 12:20:09 +0200396int main(int argc, char **argv)
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200397{
Harald Welte75a4e652015-12-22 23:59:24 +0100398 struct osmo_sua_user *sua_user;
399 struct osmo_sua_link *sua_link;
Daniel Willmann6480cad2016-01-06 18:06:26 +0100400 struct osmo_stream_srv_link *srv;
Harald Welteb3dae302015-08-30 12:20:09 +0200401 int rc;
402
403 tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context");
Harald Welte08de6382015-08-31 09:54:45 +0200404 talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context");
Harald Welteb3dae302015-08-30 12:20:09 +0200405
Harald Weltec4338de2015-12-24 00:40:52 +0100406 g_hnb_gw = hnb_gw_create(tall_hnb_ctx);
Harald Welte90256ba2015-12-23 20:16:36 +0100407
Harald Welteb3dae302015-08-30 12:20:09 +0200408 rc = osmo_init_logging(&hnbgw_log_info);
409 if (rc < 0)
410 exit(1);
411
412 vty_init(&vty_info);
Daniel Willmann56f62732015-12-02 11:22:53 +0100413 hnbgw_vty_init();
Harald Welteb3dae302015-08-30 12:20:09 +0200414
Harald Weltec4338de2015-12-24 00:40:52 +0100415 rc = telnet_init(NULL, g_hnb_gw, 2323);
Harald Welteb3dae302015-08-30 12:20:09 +0200416 if (rc < 0) {
417 perror("Error binding VTY port");
418 exit(1);
419 }
420
Harald Welte75a4e652015-12-22 23:59:24 +0100421 osmo_sua_set_log_area(DSUA);
Harald Weltebdf3fd12016-01-03 17:04:09 +0100422 ranap_set_log_area(DRANAP);
Harald Welte75a4e652015-12-22 23:59:24 +0100423
Daniel Willmann4deab942016-01-14 15:35:11 +0100424 g_hnb_gw->cnlink_cs = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.1", SUA_PORT, 0);
425 g_hnb_gw->cnlink_ps = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.2", SUA_PORT, 1);
Harald Weltec4338de2015-12-24 00:40:52 +0100426
Daniel Willmann6480cad2016-01-06 18:06:26 +0100427 srv = osmo_stream_srv_link_create(tall_hnb_ctx);
428 if (!srv) {
429 perror("cannot create server");
Harald Welteb3dae302015-08-30 12:20:09 +0200430 exit(1);
431 }
Daniel Willmann6480cad2016-01-06 18:06:26 +0100432 osmo_stream_srv_link_set_data(srv, g_hnb_gw);
433 osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP);
434 osmo_stream_srv_link_set_addr(srv, "0.0.0.0");
435 osmo_stream_srv_link_set_port(srv, g_hnb_gw->config.iuh_listen_port);
436 osmo_stream_srv_link_set_accept_cb(srv, accept_cb);
437
438 if (osmo_stream_srv_link_open(srv) < 0) {
Neels Hofmeyrde111bc2016-01-13 11:54:40 +0100439 perror("Cannot open server");
Daniel Willmann6480cad2016-01-06 18:06:26 +0100440 exit(1);
441 }
442 g_hnb_gw->iuh = srv;
Harald Welteb3dae302015-08-30 12:20:09 +0200443
444 if (daemonize) {
445 rc = osmo_daemonize();
446 if (rc < 0) {
447 perror("Error during daemonize");
448 exit(1);
449 }
450 }
451
452 while (1) {
453 rc = osmo_select_main(0);
454 if (rc < 0)
455 exit(3);
456 }
457
458 /* not reached */
459 exit(0);
Harald Weltea2e6a7a2015-08-29 21:47:39 +0200460}