2015-10-06 20:07:04 +00:00
|
|
|
/* main application for hnb-gw part of osmo-iuh */
|
|
|
|
|
|
|
|
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
|
2016-08-17 23:03:44 +00:00
|
|
|
* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
2015-10-06 20:07:04 +00:00
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
2016-08-18 01:15:14 +00:00
|
|
|
#include <stdbool.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
2015-09-11 15:49:37 +00:00
|
|
|
#include <netinet/in.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
#include <netinet/sctp.h>
|
2015-09-11 15:49:37 +00:00
|
|
|
#include <arpa/inet.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
|
|
|
|
#include <osmocom/core/application.h>
|
|
|
|
#include <osmocom/core/talloc.h>
|
2015-08-29 19:47:39 +00:00
|
|
|
#include <osmocom/core/select.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
#include <osmocom/core/logging.h>
|
2015-08-29 19:47:39 +00:00
|
|
|
#include <osmocom/core/socket.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
#include <osmocom/core/msgb.h>
|
2015-09-07 19:53:25 +00:00
|
|
|
#include <osmocom/core/write_queue.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
|
|
|
|
#include <osmocom/vty/telnet_interface.h>
|
|
|
|
#include <osmocom/vty/logging.h>
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2015-12-22 23:03:41 +00:00
|
|
|
#include <osmocom/netif/stream.h>
|
|
|
|
|
2015-12-22 22:59:24 +00:00
|
|
|
#include <osmocom/sigtran/sua.h>
|
|
|
|
#include <osmocom/sigtran/protocol/sua.h>
|
|
|
|
#include <osmocom/sigtran/sccp_sap.h>
|
|
|
|
|
2016-08-18 11:13:55 +00:00
|
|
|
#include <osmocom/iuh/hnbgw.h>
|
|
|
|
#include <osmocom/iuh/hnbgw_hnbap.h>
|
|
|
|
#include <osmocom/iuh/hnbgw_rua.h>
|
|
|
|
#include <osmocom/iuh/hnbgw_cn.h>
|
|
|
|
#include <osmocom/iuh/context_map.h>
|
2015-08-30 10:20:09 +00:00
|
|
|
|
2016-08-18 00:10:57 +00:00
|
|
|
static const char * const osmo_hnbgw_copyright =
|
|
|
|
"OsmoHNBGW - Osmocom Home Node B Gateway implementation\r\n"
|
|
|
|
"Copyright (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>\r\n"
|
|
|
|
"Contributions by Daniel Willmann, Harald Welte, Neels Hofmeyr\r\n"
|
|
|
|
"License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
|
|
|
|
"This is free software: you are free to change and redistribute it.\r\n"
|
|
|
|
"There is NO WARRANTY, to the extent permitted by law.\r\n";
|
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
static void *tall_hnb_ctx;
|
2015-08-31 07:54:45 +00:00
|
|
|
void *talloc_asn1_ctx;
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
static struct hnb_gw *g_hnb_gw;
|
|
|
|
|
|
|
|
static int listen_fd_cb(struct osmo_fd *fd, unsigned int what);
|
|
|
|
|
|
|
|
static struct hnb_gw *hnb_gw_create(void *ctx)
|
|
|
|
{
|
|
|
|
struct hnb_gw *gw = talloc_zero(ctx, struct hnb_gw);
|
|
|
|
|
|
|
|
gw->config.iuh_listen_port = IUH_DEFAULT_SCTP_PORT;
|
|
|
|
|
|
|
|
gw->next_ue_ctx_id = 23;
|
|
|
|
INIT_LLIST_HEAD(&gw->hnb_list);
|
|
|
|
INIT_LLIST_HEAD(&gw->ue_list);
|
|
|
|
INIT_LLIST_HEAD(&gw->cn_list);
|
|
|
|
|
|
|
|
context_map_init(gw);
|
|
|
|
|
|
|
|
return gw;
|
|
|
|
}
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
struct ue_context *ue_context_by_id(struct hnb_gw *gw, uint32_t id)
|
2015-09-10 22:15:16 +00:00
|
|
|
{
|
|
|
|
struct ue_context *ue;
|
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
llist_for_each_entry(ue, &gw->ue_list, list) {
|
2015-09-10 22:15:16 +00:00
|
|
|
if (ue->context_id == id)
|
|
|
|
return ue;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
struct ue_context *ue_context_by_imsi(struct hnb_gw *gw, const char *imsi)
|
2015-09-10 22:15:16 +00:00
|
|
|
{
|
|
|
|
struct ue_context *ue;
|
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
llist_for_each_entry(ue, &gw->ue_list, list) {
|
2015-09-10 22:15:16 +00:00
|
|
|
if (!strcmp(ue->imsi, imsi))
|
|
|
|
return ue;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:06:59 +00:00
|
|
|
struct ue_context *ue_context_by_tmsi(struct hnb_gw *gw, uint32_t tmsi)
|
|
|
|
{
|
|
|
|
struct ue_context *ue;
|
|
|
|
|
|
|
|
llist_for_each_entry(ue, &gw->ue_list, list) {
|
|
|
|
if (ue->tmsi == tmsi)
|
|
|
|
return ue;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-06 17:07:02 +00:00
|
|
|
void ue_context_free_by_hnb(struct hnb_gw *gw, const struct hnb_context *hnb)
|
|
|
|
{
|
|
|
|
struct ue_context *ue, *tmp;
|
|
|
|
|
|
|
|
llist_for_each_entry_safe(ue, tmp, &gw->ue_list, list) {
|
|
|
|
if (ue->hnb == hnb)
|
|
|
|
ue_context_free(ue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
static uint32_t get_next_ue_ctx_id(struct hnb_gw *gw)
|
2015-09-10 22:15:16 +00:00
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
do {
|
2015-12-23 23:40:52 +00:00
|
|
|
id = gw->next_ue_ctx_id++;
|
|
|
|
} while (ue_context_by_id(gw, id));
|
2015-09-10 22:15:16 +00:00
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:06:59 +00:00
|
|
|
struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi,
|
|
|
|
uint32_t tmsi)
|
2015-09-10 22:15:16 +00:00
|
|
|
{
|
|
|
|
struct ue_context *ue;
|
|
|
|
|
|
|
|
ue = talloc_zero(tall_hnb_ctx, struct ue_context);
|
|
|
|
if (!ue)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ue->hnb = hnb;
|
2016-09-22 16:06:59 +00:00
|
|
|
if (imsi)
|
|
|
|
strncpy(ue->imsi, imsi, sizeof(ue->imsi));
|
|
|
|
else
|
|
|
|
ue->imsi[0] = '\0';
|
|
|
|
ue->tmsi = tmsi;
|
2015-12-23 23:40:52 +00:00
|
|
|
ue->context_id = get_next_ue_ctx_id(hnb->gw);
|
|
|
|
llist_add_tail(&ue->list, &hnb->gw->ue_list);
|
2015-09-10 22:15:16 +00:00
|
|
|
|
|
|
|
return ue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ue_context_free(struct ue_context *ue)
|
|
|
|
{
|
|
|
|
llist_del(&ue->list);
|
|
|
|
talloc_free(ue);
|
|
|
|
}
|
2016-01-06 17:06:26 +00:00
|
|
|
static int hnb_close_cb(struct osmo_stream_srv *conn)
|
|
|
|
{
|
|
|
|
}
|
2015-09-10 22:15:16 +00:00
|
|
|
|
2016-01-06 17:06:26 +00:00
|
|
|
static int hnb_read_cb(struct osmo_stream_srv *conn)
|
2015-08-29 19:47:39 +00:00
|
|
|
{
|
2016-01-06 17:06:26 +00:00
|
|
|
struct hnb_context *hnb = osmo_stream_srv_get_data(conn);
|
2015-08-29 19:47:39 +00:00
|
|
|
struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx");
|
2015-09-07 19:53:25 +00:00
|
|
|
int flags = 0;
|
2015-08-29 19:47:39 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (!msg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-09-10 20:32:15 +00:00
|
|
|
/* we store a reference to the HomeNodeB in the msg->dest for the
|
|
|
|
* benefit of varoius downstream processing functions */
|
|
|
|
msg->dst = hnb;
|
|
|
|
|
2016-01-06 17:06:26 +00:00
|
|
|
rc = osmo_stream_srv_recv(conn, msg);
|
|
|
|
if (rc == -EAGAIN) {
|
|
|
|
/* Notification received */
|
|
|
|
msgb_free(msg);
|
|
|
|
return 0;
|
|
|
|
} else if (rc < 0) {
|
2015-08-29 19:47:39 +00:00
|
|
|
LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n");
|
2015-08-30 14:57:53 +00:00
|
|
|
/* FIXME: clean up after disappeared HNB */
|
2016-01-06 17:06:26 +00:00
|
|
|
hnb_context_release(hnb);
|
2015-12-22 15:26:48 +00:00
|
|
|
goto out;
|
2015-12-15 19:29:27 +00:00
|
|
|
} else if (rc == 0) {
|
2016-01-06 17:06:26 +00:00
|
|
|
hnb_context_release(hnb);
|
2015-12-22 15:26:48 +00:00
|
|
|
rc = -1;
|
2015-12-15 19:29:27 +00:00
|
|
|
|
2015-12-22 15:26:48 +00:00
|
|
|
goto out;
|
2015-12-15 19:29:27 +00:00
|
|
|
} else {
|
2015-08-29 19:47:39 +00:00
|
|
|
msgb_put(msg, rc);
|
2015-12-15 19:29:27 +00:00
|
|
|
}
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2016-01-06 17:06:26 +00:00
|
|
|
switch (msgb_sctp_ppid(msg)) {
|
2015-08-29 19:47:39 +00:00
|
|
|
case IUH_PPI_HNBAP:
|
2016-01-06 17:06:26 +00:00
|
|
|
hnb->hnbap_stream = msgb_sctp_stream(msg);
|
2015-08-29 19:47:39 +00:00
|
|
|
rc = hnbgw_hnbap_rx(hnb, msg);
|
|
|
|
break;
|
|
|
|
case IUH_PPI_RUA:
|
2016-01-06 17:06:26 +00:00
|
|
|
hnb->rua_stream = msgb_sctp_stream(msg);
|
2015-09-10 16:47:08 +00:00
|
|
|
rc = hnbgw_rua_rx(hnb, msg);
|
2015-08-29 19:47:39 +00:00
|
|
|
break;
|
|
|
|
case IUH_PPI_SABP:
|
|
|
|
case IUH_PPI_RNA:
|
|
|
|
case IUH_PPI_PUA:
|
|
|
|
LOGP(DMAIN, LOGL_ERROR, "Unimplemented SCTP PPID=%u received\n",
|
2016-01-06 17:06:26 +00:00
|
|
|
msgb_sctp_ppid(msg));
|
2015-08-29 19:47:39 +00:00
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n",
|
2016-01-06 17:06:26 +00:00
|
|
|
msgb_sctp_ppid(msg));
|
2015-08-29 19:47:39 +00:00
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-22 15:26:48 +00:00
|
|
|
out:
|
2015-09-07 22:09:23 +00:00
|
|
|
msgb_free(msg);
|
2015-08-29 19:47:39 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2015-09-07 19:53:25 +00:00
|
|
|
static int hnb_write_cb(struct osmo_fd *fd, struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct hnb_context *ctx = fd->data;
|
|
|
|
struct sctp_sndrcvinfo sinfo = {
|
2015-12-22 23:03:41 +00:00
|
|
|
.sinfo_ppid = htonl(msgb_sctp_ppid(msg)),
|
2015-09-07 19:53:25 +00:00
|
|
|
.sinfo_stream = ctx->hnbap_stream,
|
|
|
|
};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = sctp_send(fd->fd, msgb_data(msg), msgb_length(msg),
|
|
|
|
&sinfo, 0);
|
2015-09-07 20:41:26 +00:00
|
|
|
/* we don't need to msgb_free(), write_queue does this for us */
|
2015-09-07 19:53:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-01-06 17:06:26 +00:00
|
|
|
struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd)
|
2015-12-23 19:16:36 +00:00
|
|
|
{
|
|
|
|
struct hnb_context *ctx;
|
|
|
|
|
|
|
|
ctx = talloc_zero(tall_hnb_ctx, struct hnb_context);
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
2016-02-18 00:26:59 +00:00
|
|
|
INIT_LLIST_HEAD(&ctx->map_list);
|
2015-12-23 19:16:36 +00:00
|
|
|
|
|
|
|
ctx->gw = gw;
|
2016-01-06 17:06:26 +00:00
|
|
|
ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, hnb_close_cb, ctx);
|
|
|
|
if (!ctx->conn) {
|
|
|
|
LOGP(DMAIN, LOGL_INFO, "error while creating connection\n");
|
2016-02-18 00:26:59 +00:00
|
|
|
talloc_free(ctx);
|
|
|
|
return NULL;
|
2016-01-06 17:06:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 19:16:36 +00:00
|
|
|
llist_add_tail(&ctx->list, &gw->hnb_list);
|
2016-02-18 00:26:59 +00:00
|
|
|
return ctx;
|
2015-12-23 19:16:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void hnb_context_release(struct hnb_context *ctx)
|
|
|
|
{
|
|
|
|
struct hnbgw_context_map *map, *map2;
|
|
|
|
|
|
|
|
/* remove from the list of HNB contexts */
|
|
|
|
llist_del(&ctx->list);
|
|
|
|
|
|
|
|
/* deactivate all context maps */
|
|
|
|
llist_for_each_entry_safe(map, map2, &ctx->map_list, hnb_list) {
|
|
|
|
/* remove it from list, as HNB context will soon be
|
2016-04-19 15:54:25 +00:00
|
|
|
* gone. Let's hope the second osmo_llist_del in the
|
|
|
|
* map garbage collector works fine? */
|
2015-12-23 19:16:36 +00:00
|
|
|
llist_del(&map->hnb_list);
|
2016-04-23 11:53:28 +00:00
|
|
|
llist_del(&map->cn_list);
|
2015-12-23 19:16:36 +00:00
|
|
|
context_map_deactivate(map);
|
|
|
|
}
|
2016-01-06 17:07:02 +00:00
|
|
|
ue_context_free_by_hnb(ctx->gw, ctx);
|
2016-01-06 17:06:26 +00:00
|
|
|
osmo_stream_srv_destroy(ctx->conn);
|
2015-12-23 19:16:36 +00:00
|
|
|
|
|
|
|
talloc_free(ctx);
|
|
|
|
}
|
|
|
|
|
2015-08-29 19:47:39 +00:00
|
|
|
/*! call-back when the listen FD has something to read */
|
2016-01-06 17:06:26 +00:00
|
|
|
static int accept_cb(struct osmo_stream_srv_link *srv, int fd)
|
2015-08-29 19:47:39 +00:00
|
|
|
{
|
2016-01-06 17:06:26 +00:00
|
|
|
struct hnb_gw *gw = osmo_stream_srv_link_get_data(srv);
|
2015-08-30 10:20:09 +00:00
|
|
|
struct hnb_context *ctx;
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2016-01-06 17:06:26 +00:00
|
|
|
ctx = hnb_context_alloc(gw, srv, fd);
|
2015-08-29 19:47:39 +00:00
|
|
|
if (!ctx)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-18 00:18:00 +00:00
|
|
|
const char *hnbgw_get_iuh_bind_addr(struct hnb_gw *gw)
|
|
|
|
{
|
|
|
|
const char *addr = gw->config.iuh_bind_addr;
|
|
|
|
if (!addr)
|
|
|
|
addr = HNBGW_IUH_BIND_ADDR_DEFAULT;
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
static const struct log_info_cat log_cat[] = {
|
|
|
|
[DMAIN] = {
|
2016-04-04 16:02:49 +00:00
|
|
|
.name = "DMAIN", .loglevel = LOGL_DEBUG, .enabled = 1,
|
2015-08-30 10:20:09 +00:00
|
|
|
.color = "",
|
|
|
|
.description = "Main program",
|
|
|
|
},
|
2015-12-17 10:51:17 +00:00
|
|
|
[DHNBAP] = {
|
|
|
|
.name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1,
|
|
|
|
.color = "",
|
|
|
|
.description = "Home Node B Application Part",
|
|
|
|
},
|
2015-12-22 22:59:24 +00:00
|
|
|
[DSUA] = {
|
|
|
|
.name = "DSUA", .loglevel = LOGL_DEBUG, .enabled = 1,
|
|
|
|
.color = "",
|
|
|
|
.description = "SCCP User Adaptation",
|
|
|
|
},
|
2015-12-23 14:36:31 +00:00
|
|
|
[DRUA] = {
|
|
|
|
.name = "DRUA", .loglevel = LOGL_DEBUG, .enabled = 1,
|
|
|
|
.color = "",
|
|
|
|
.description = "RANAP User Adaptation",
|
|
|
|
},
|
|
|
|
[DRANAP] = {
|
|
|
|
.name = "DRANAP", .loglevel = LOGL_DEBUG, .enabled = 1,
|
|
|
|
.color = "",
|
|
|
|
.description = "RAN Application Part",
|
|
|
|
},
|
2015-08-30 10:20:09 +00:00
|
|
|
};
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
static const struct log_info hnbgw_log_info = {
|
|
|
|
.cat = log_cat,
|
|
|
|
.num_cat = ARRAY_SIZE(log_cat),
|
|
|
|
};
|
2015-08-29 19:47:39 +00:00
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
static struct vty_app_info vty_info = {
|
|
|
|
.name = "OsmoHNBGW",
|
|
|
|
.version = "0",
|
|
|
|
};
|
|
|
|
|
2016-08-17 11:53:18 +00:00
|
|
|
static struct {
|
|
|
|
int daemonize;
|
2016-08-17 11:54:00 +00:00
|
|
|
const char *config_file;
|
2016-08-18 01:15:14 +00:00
|
|
|
bool log_disable_color;
|
|
|
|
bool log_enable_timestamp;
|
|
|
|
int log_level;
|
|
|
|
const char *log_category_mask;
|
2016-08-17 11:53:18 +00:00
|
|
|
} hnbgw_cmdline_config = {
|
2016-08-17 11:54:00 +00:00
|
|
|
0,
|
2016-08-18 01:15:14 +00:00
|
|
|
"osmo-hnbgw.cfg",
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
NULL,
|
2016-08-17 11:53:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void print_usage()
|
|
|
|
{
|
|
|
|
printf("Usage: osmo-hnbgw\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_help()
|
|
|
|
{
|
|
|
|
printf(" -h --help This text.\n");
|
|
|
|
printf(" -d option --debug=DHNBAP:DSUA:DRUA:DRANAP:DMAIN Enable debugging.\n");
|
|
|
|
printf(" -D --daemonize Fork the process into a background daemon.\n");
|
2016-08-17 11:54:00 +00:00
|
|
|
printf(" -c --config-file filename The config file to use.\n");
|
2016-08-17 11:53:18 +00:00
|
|
|
printf(" -s --disable-color\n");
|
|
|
|
printf(" -T --timestamp Prefix every log line with a timestamp.\n");
|
|
|
|
printf(" -V --version Print the version of OsmoHNBGW.\n");
|
|
|
|
printf(" -e --log-level number Set a global loglevel.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_options(int argc, char **argv)
|
|
|
|
{
|
|
|
|
while (1) {
|
|
|
|
int option_index = 0, c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"debug", 1, 0, 'd'},
|
|
|
|
{"daemonize", 0, 0, 'D'},
|
2016-08-17 11:54:00 +00:00
|
|
|
{"config-file", 1, 0, 'c'},
|
2016-08-17 11:53:18 +00:00
|
|
|
{"disable-color", 0, 0, 's'},
|
|
|
|
{"timestamp", 0, 0, 'T'},
|
|
|
|
{"version", 0, 0, 'V' },
|
|
|
|
{"log-level", 1, 0, 'e'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2016-08-17 11:54:00 +00:00
|
|
|
c = getopt_long(argc, argv, "hd:Dc:sTVe:",
|
2016-08-17 11:53:18 +00:00
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
print_usage();
|
|
|
|
print_help();
|
|
|
|
exit(0);
|
|
|
|
case 's':
|
2016-08-18 01:15:14 +00:00
|
|
|
hnbgw_cmdline_config.log_disable_color = true;
|
2016-08-17 11:53:18 +00:00
|
|
|
break;
|
|
|
|
case 'd':
|
2016-08-18 01:15:14 +00:00
|
|
|
hnbgw_cmdline_config.log_category_mask = optarg;
|
2016-08-17 11:53:18 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
hnbgw_cmdline_config.daemonize = 1;
|
|
|
|
break;
|
2016-08-17 11:54:00 +00:00
|
|
|
case 'c':
|
|
|
|
hnbgw_cmdline_config.config_file = optarg;
|
|
|
|
break;
|
2016-08-17 11:53:18 +00:00
|
|
|
case 'T':
|
2016-08-18 01:15:14 +00:00
|
|
|
hnbgw_cmdline_config.log_enable_timestamp = true;
|
2016-08-17 11:53:18 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
2016-08-18 01:15:14 +00:00
|
|
|
hnbgw_cmdline_config.log_level = atoi(optarg);
|
2016-08-17 11:53:18 +00:00
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
print_version(1);
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* catch unknown options *as well as* missing arguments. */
|
|
|
|
fprintf(stderr, "Error in command line options. Exiting.\n");
|
|
|
|
exit(-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
int main(int argc, char **argv)
|
2015-08-29 19:47:39 +00:00
|
|
|
{
|
2016-07-06 13:58:48 +00:00
|
|
|
struct osmo_sccp_user *sua_user;
|
|
|
|
struct osmo_sccp_link *sua_link;
|
2016-01-06 17:06:26 +00:00
|
|
|
struct osmo_stream_srv_link *srv;
|
2015-08-30 10:20:09 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context");
|
2015-08-31 07:54:45 +00:00
|
|
|
talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context");
|
2015-08-30 10:20:09 +00:00
|
|
|
|
2015-12-23 23:40:52 +00:00
|
|
|
g_hnb_gw = hnb_gw_create(tall_hnb_ctx);
|
2016-04-05 12:27:48 +00:00
|
|
|
g_hnb_gw->config.rnc_id = 23;
|
2015-12-23 19:16:36 +00:00
|
|
|
|
2015-08-30 10:20:09 +00:00
|
|
|
rc = osmo_init_logging(&hnbgw_log_info);
|
|
|
|
if (rc < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2016-08-18 00:10:57 +00:00
|
|
|
vty_info.copyright = osmo_hnbgw_copyright;
|
2015-08-30 10:20:09 +00:00
|
|
|
vty_init(&vty_info);
|
2016-08-18 00:10:57 +00:00
|
|
|
|
2016-08-17 23:03:44 +00:00
|
|
|
hnbgw_vty_init(g_hnb_gw, tall_hnb_ctx);
|
|
|
|
logging_vty_add_cmds(&hnbgw_log_info);
|
2015-08-30 10:20:09 +00:00
|
|
|
|
2016-08-17 11:53:18 +00:00
|
|
|
/* Handle options after vty_init(), for --version */
|
|
|
|
handle_options(argc, argv);
|
|
|
|
|
2016-08-17 11:54:00 +00:00
|
|
|
rc = vty_read_config_file(hnbgw_cmdline_config.config_file, NULL);
|
|
|
|
if (rc < 0) {
|
|
|
|
LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n",
|
|
|
|
hnbgw_cmdline_config.config_file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-18 01:15:14 +00:00
|
|
|
/*
|
|
|
|
* cmdline options take precedence over config file, but if no options
|
|
|
|
* were passed we must not override the config file.
|
|
|
|
*/
|
|
|
|
if (hnbgw_cmdline_config.log_disable_color)
|
|
|
|
log_set_use_color(osmo_stderr_target, 0);
|
|
|
|
if (hnbgw_cmdline_config.log_category_mask)
|
|
|
|
log_parse_category_mask(osmo_stderr_target,
|
|
|
|
hnbgw_cmdline_config.log_category_mask);
|
|
|
|
if (hnbgw_cmdline_config.log_enable_timestamp)
|
|
|
|
log_set_print_timestamp(osmo_stderr_target, 1);
|
|
|
|
if (hnbgw_cmdline_config.log_level)
|
|
|
|
log_set_log_level(osmo_stderr_target,
|
|
|
|
hnbgw_cmdline_config.log_level);
|
|
|
|
|
2016-02-24 19:50:31 +00:00
|
|
|
rc = telnet_init_dynif(NULL, g_hnb_gw, vty_get_bind_addr(), 2323);
|
2015-08-30 10:20:09 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error binding VTY port");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2015-12-22 22:59:24 +00:00
|
|
|
osmo_sua_set_log_area(DSUA);
|
2016-01-03 16:04:09 +00:00
|
|
|
ranap_set_log_area(DRANAP);
|
2015-12-22 22:59:24 +00:00
|
|
|
|
2016-01-14 14:35:11 +00:00
|
|
|
g_hnb_gw->cnlink_cs = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.1", SUA_PORT, 0);
|
|
|
|
g_hnb_gw->cnlink_ps = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.2", SUA_PORT, 1);
|
2015-12-23 23:40:52 +00:00
|
|
|
|
2016-08-18 00:18:00 +00:00
|
|
|
LOGP(DMAIN, LOGL_NOTICE, "Listening for Iuh at %s %d\n",
|
|
|
|
hnbgw_get_iuh_bind_addr(g_hnb_gw),
|
|
|
|
g_hnb_gw->config.iuh_listen_port);
|
2016-01-06 17:06:26 +00:00
|
|
|
srv = osmo_stream_srv_link_create(tall_hnb_ctx);
|
|
|
|
if (!srv) {
|
|
|
|
perror("cannot create server");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
osmo_stream_srv_link_set_data(srv, g_hnb_gw);
|
|
|
|
osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP);
|
2016-08-18 00:18:00 +00:00
|
|
|
osmo_stream_srv_link_set_addr(srv, hnbgw_get_iuh_bind_addr(g_hnb_gw));
|
2016-01-06 17:06:26 +00:00
|
|
|
osmo_stream_srv_link_set_port(srv, g_hnb_gw->config.iuh_listen_port);
|
|
|
|
osmo_stream_srv_link_set_accept_cb(srv, accept_cb);
|
|
|
|
|
|
|
|
if (osmo_stream_srv_link_open(srv) < 0) {
|
2016-01-13 10:54:40 +00:00
|
|
|
perror("Cannot open server");
|
2015-08-30 10:20:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-01-06 17:06:26 +00:00
|
|
|
g_hnb_gw->iuh = srv;
|
2015-08-30 10:20:09 +00:00
|
|
|
|
2016-08-17 11:53:18 +00:00
|
|
|
if (hnbgw_cmdline_config.daemonize) {
|
2015-08-30 10:20:09 +00:00
|
|
|
rc = osmo_daemonize();
|
|
|
|
if (rc < 0) {
|
|
|
|
perror("Error during daemonize");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
rc = osmo_select_main(0);
|
|
|
|
if (rc < 0)
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
exit(0);
|
2015-08-29 19:47:39 +00:00
|
|
|
}
|