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> |
| 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 Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 21 | #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 Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 28 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | #include <sys/socket.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 31 | #include <netinet/in.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 32 | #include <netinet/sctp.h> |
Harald Welte | 1d2c39d | 2015-09-11 17:49:37 +0200 | [diff] [blame] | 33 | #include <arpa/inet.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 34 | |
| 35 | #include <osmocom/core/application.h> |
| 36 | #include <osmocom/core/talloc.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 37 | #include <osmocom/core/select.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 38 | #include <osmocom/core/logging.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 39 | #include <osmocom/core/socket.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 40 | #include <osmocom/core/msgb.h> |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 41 | #include <osmocom/core/write_queue.h> |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 42 | |
| 43 | #include <osmocom/vty/telnet_interface.h> |
| 44 | #include <osmocom/vty/logging.h> |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 45 | #include <osmocom/vty/command.h> |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 46 | |
Harald Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 47 | #include <osmocom/netif/stream.h> |
| 48 | |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 49 | #include <osmocom/sigtran/sua.h> |
| 50 | #include <osmocom/sigtran/protocol/sua.h> |
| 51 | #include <osmocom/sigtran/sccp_sap.h> |
| 52 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 53 | #include "hnbgw.h" |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 54 | #include "hnbgw_hnbap.h" |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 55 | #include "hnbgw_rua.h" |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 56 | #include "hnbgw_cn.h" |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 57 | #include "context_map.h" |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 58 | |
| 59 | static void *tall_hnb_ctx; |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 60 | void *talloc_asn1_ctx; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 61 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 62 | static struct hnb_gw *g_hnb_gw; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 63 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 64 | static int listen_fd_cb(struct osmo_fd *fd, unsigned int what); |
| 65 | |
| 66 | static 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 Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 72 | 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 | |
| 82 | 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] | 83 | { |
| 84 | struct ue_context *ue; |
| 85 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 86 | llist_for_each_entry(ue, &gw->ue_list, list) { |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 87 | if (ue->context_id == id) |
| 88 | return ue; |
| 89 | } |
| 90 | return NULL; |
| 91 | |
| 92 | } |
| 93 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 94 | 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] | 95 | { |
| 96 | struct ue_context *ue; |
| 97 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 98 | llist_for_each_entry(ue, &gw->ue_list, list) { |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 99 | if (!strcmp(ue->imsi, imsi)) |
| 100 | return ue; |
| 101 | } |
| 102 | return NULL; |
| 103 | } |
| 104 | |
Daniel Willmann | 1ee089f | 2016-01-06 18:07:02 +0100 | [diff] [blame] | 105 | void 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 Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 115 | static uint32_t get_next_ue_ctx_id(struct hnb_gw *gw) |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 116 | { |
| 117 | uint32_t id; |
| 118 | |
| 119 | do { |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 120 | id = gw->next_ue_ctx_id++; |
| 121 | } while (ue_context_by_id(gw, id)); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 122 | |
| 123 | return id; |
| 124 | } |
| 125 | |
| 126 | struct 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 Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 136 | ue->context_id = get_next_ue_ctx_id(hnb->gw); |
| 137 | llist_add_tail(&ue->list, &hnb->gw->ue_list); |
Harald Welte | b534e5c | 2015-09-11 00:15:16 +0200 | [diff] [blame] | 138 | |
| 139 | return ue; |
| 140 | } |
| 141 | |
| 142 | void ue_context_free(struct ue_context *ue) |
| 143 | { |
| 144 | llist_del(&ue->list); |
| 145 | talloc_free(ue); |
| 146 | } |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 147 | static int hnb_close_cb(struct osmo_stream_srv *conn) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 148 | { |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static int hnb_read_cb(struct osmo_stream_srv *conn) |
| 152 | { |
| 153 | struct hnb_context *hnb = osmo_stream_srv_get_data(conn); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 154 | struct msgb *msg = msgb_alloc(IUH_MSGB_SIZE, "Iuh rx"); |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 155 | int flags = 0; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 156 | int rc; |
| 157 | |
| 158 | if (!msg) |
| 159 | return -ENOMEM; |
| 160 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 161 | /* 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 Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 165 | 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 Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 171 | LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); |
Harald Welte | ee77cff | 2015-08-30 16:57:53 +0200 | [diff] [blame] | 172 | /* FIXME: clean up after disappeared HNB */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 173 | hnb_context_release(hnb); |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 174 | goto out; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 175 | } else if (rc == 0) { |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 176 | hnb_context_release(hnb); |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 177 | rc = -1; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 178 | |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 179 | goto out; |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 180 | } else { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 181 | msgb_put(msg, rc); |
Daniel Willmann | 4267a29 | 2015-12-15 20:29:27 +0100 | [diff] [blame] | 182 | } |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 183 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 184 | switch (msgb_sctp_ppid(msg)) { |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 185 | case IUH_PPI_HNBAP: |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 186 | hnb->hnbap_stream = msgb_sctp_stream(msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 187 | rc = hnbgw_hnbap_rx(hnb, msg); |
| 188 | break; |
| 189 | case IUH_PPI_RUA: |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 190 | hnb->rua_stream = msgb_sctp_stream(msg); |
Harald Welte | 318e4d5 | 2015-09-10 18:47:08 +0200 | [diff] [blame] | 191 | rc = hnbgw_rua_rx(hnb, msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 192 | 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 Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 197 | msgb_sctp_ppid(msg)); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 198 | rc = 0; |
| 199 | break; |
| 200 | default: |
| 201 | LOGP(DMAIN, LOGL_ERROR, "Unknown SCTP PPID=%u received\n", |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 202 | msgb_sctp_ppid(msg)); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 203 | rc = 0; |
| 204 | break; |
| 205 | } |
| 206 | |
Daniel Willmann | 269b8ac | 2015-12-22 16:26:48 +0100 | [diff] [blame] | 207 | out: |
Harald Welte | f2f3000 | 2015-09-08 00:09:23 +0200 | [diff] [blame] | 208 | msgb_free(msg); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 209 | return rc; |
| 210 | } |
| 211 | |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 212 | static 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 Welte | ffa7c0a | 2015-12-23 00:03:41 +0100 | [diff] [blame] | 216 | .sinfo_ppid = htonl(msgb_sctp_ppid(msg)), |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 217 | .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 Welte | 9e270b4 | 2015-09-07 22:41:26 +0200 | [diff] [blame] | 223 | /* we don't need to msgb_free(), write_queue does this for us */ |
Harald Welte | 3f71256 | 2015-09-07 21:53:25 +0200 | [diff] [blame] | 224 | return rc; |
| 225 | } |
| 226 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 227 | 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] | 228 | { |
| 229 | struct hnb_context *ctx; |
| 230 | |
| 231 | ctx = talloc_zero(tall_hnb_ctx, struct hnb_context); |
| 232 | if (!ctx) |
| 233 | return NULL; |
| 234 | |
| 235 | ctx->gw = gw; |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 236 | ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, hnb_close_cb, ctx); |
| 237 | if (!ctx->conn) { |
| 238 | LOGP(DMAIN, LOGL_INFO, "error while creating connection\n"); |
| 239 | return -1; |
| 240 | } |
| 241 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 242 | INIT_LLIST_HEAD(&ctx->map_list); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 243 | |
| 244 | llist_add_tail(&ctx->list, &gw->hnb_list); |
| 245 | } |
| 246 | |
| 247 | void hnb_context_release(struct hnb_context *ctx) |
| 248 | { |
| 249 | struct hnbgw_context_map *map, *map2; |
| 250 | |
| 251 | /* remove from the list of HNB contexts */ |
| 252 | llist_del(&ctx->list); |
| 253 | |
| 254 | /* deactivate all context maps */ |
| 255 | llist_for_each_entry_safe(map, map2, &ctx->map_list, hnb_list) { |
| 256 | /* remove it from list, as HNB context will soon be |
| 257 | * gone. Let's hope the seccond osmo_llist_del in the |
| 258 | * map garbage collector wors fine? */ |
| 259 | llist_del(&map->hnb_list); |
| 260 | context_map_deactivate(map); |
| 261 | } |
Daniel Willmann | 1ee089f | 2016-01-06 18:07:02 +0100 | [diff] [blame] | 262 | ue_context_free_by_hnb(ctx->gw, ctx); |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 263 | osmo_stream_srv_destroy(ctx->conn); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 264 | |
| 265 | talloc_free(ctx); |
| 266 | } |
| 267 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 268 | /*! call-back when the listen FD has something to read */ |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 269 | static int accept_cb(struct osmo_stream_srv_link *srv, int fd) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 270 | { |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 271 | struct hnb_gw *gw = osmo_stream_srv_link_get_data(srv); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 272 | struct hnb_context *ctx; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 273 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 274 | ctx = hnb_context_alloc(gw, srv, fd); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 275 | if (!ctx) |
| 276 | return -ENOMEM; |
| 277 | |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 281 | /* Entry point for primitives coming up from SCCP User SAP */ |
| 282 | static int sccp_sap_up(struct osmo_prim_hdr *oph, void *link) |
| 283 | { |
| 284 | struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph; |
| 285 | |
| 286 | LOGP(DMAIN, LOGL_DEBUG, "sccp_sap_up(%s)\n", osmo_scu_prim_name(oph)); |
| 287 | |
| 288 | /* FIXME: Do something */ |
| 289 | |
| 290 | msgb_free(oph->msg); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 295 | static const struct log_info_cat log_cat[] = { |
| 296 | [DMAIN] = { |
Daniel Willmann | 7c27f7b | 2015-12-15 17:41:41 +0100 | [diff] [blame] | 297 | .name = "DMAIN", .loglevel = LOGL_INFO, .enabled = 1, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 298 | .color = "", |
| 299 | .description = "Main program", |
| 300 | }, |
Daniel Willmann | bded984 | 2015-12-17 11:51:17 +0100 | [diff] [blame] | 301 | [DHNBAP] = { |
| 302 | .name = "DHNBAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 303 | .color = "", |
| 304 | .description = "Home Node B Application Part", |
| 305 | }, |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 306 | [DSUA] = { |
| 307 | .name = "DSUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 308 | .color = "", |
| 309 | .description = "SCCP User Adaptation", |
| 310 | }, |
Harald Welte | f42317b | 2015-12-23 15:36:31 +0100 | [diff] [blame] | 311 | [DRUA] = { |
| 312 | .name = "DRUA", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 313 | .color = "", |
| 314 | .description = "RANAP User Adaptation", |
| 315 | }, |
| 316 | [DRANAP] = { |
| 317 | .name = "DRANAP", .loglevel = LOGL_DEBUG, .enabled = 1, |
| 318 | .color = "", |
| 319 | .description = "RAN Application Part", |
| 320 | }, |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 321 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 322 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 323 | static const struct log_info hnbgw_log_info = { |
| 324 | .cat = log_cat, |
| 325 | .num_cat = ARRAY_SIZE(log_cat), |
| 326 | }; |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 327 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 328 | static struct vty_app_info vty_info = { |
| 329 | .name = "OsmoHNBGW", |
| 330 | .version = "0", |
| 331 | }; |
| 332 | |
| 333 | static int daemonize = 0; |
| 334 | |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 335 | static void vty_dump_hnb_info(struct vty *vty, struct hnb_context *hnb) |
| 336 | { |
| 337 | vty_out(vty, "HNB \"%s\" MCC %u MNC %u LAC %u RAC %u SAC %u CID %u%s", hnb->identity_info, |
| 338 | hnb->id.mcc, hnb->id.mnc, hnb->id.lac, hnb->id.rac, hnb->id.sac, hnb->id.cid, |
| 339 | VTY_NEWLINE); |
| 340 | vty_out(vty, " HNBAP ID %u RUA ID %u%s", hnb->hnbap_stream, hnb->rua_stream, VTY_NEWLINE); |
| 341 | } |
| 342 | |
| 343 | static void vty_dump_ue_info(struct vty *vty, struct ue_context *ue) |
| 344 | { |
| 345 | vty_out(vty, "UE IMSI \"%s\" context ID %u%s", ue->imsi, ue->context_id, VTY_NEWLINE); |
| 346 | } |
| 347 | |
| 348 | DEFUN(show_hnb, show_hnb_cmd, "show hnb all", SHOW_STR "Display information about a HNB") |
| 349 | { |
| 350 | struct hnb_context *hnb; |
| 351 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 352 | llist_for_each_entry(hnb, &g_hnb_gw->hnb_list, list) { |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 353 | vty_dump_hnb_info(vty, hnb); |
| 354 | } |
| 355 | |
| 356 | return CMD_SUCCESS; |
| 357 | } |
| 358 | |
| 359 | DEFUN(show_ue, show_ue_cmd, "show ue all", SHOW_STR "Display information about a UE") |
| 360 | { |
| 361 | struct ue_context *ue; |
| 362 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 363 | llist_for_each_entry(ue, &g_hnb_gw->ue_list, list) { |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 364 | vty_dump_ue_info(vty, ue); |
| 365 | } |
| 366 | |
| 367 | return CMD_SUCCESS; |
| 368 | } |
| 369 | |
Daniel Willmann | 28b9ec1 | 2015-12-17 18:02:37 +0100 | [diff] [blame] | 370 | DEFUN(show_talloc, show_talloc_cmd, "show talloc", SHOW_STR "Display talloc info") |
| 371 | { |
| 372 | talloc_report_full(tall_hnb_ctx, stderr); |
Daniel Willmann | 28b9ec1 | 2015-12-17 18:02:37 +0100 | [diff] [blame] | 373 | talloc_report_full(talloc_asn1_ctx, stderr); |
| 374 | |
| 375 | return CMD_SUCCESS; |
| 376 | } |
| 377 | |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 378 | static void hnbgw_vty_init(void) |
| 379 | { |
| 380 | install_element_ve(&show_hnb_cmd); |
| 381 | install_element_ve(&show_ue_cmd); |
Daniel Willmann | 28b9ec1 | 2015-12-17 18:02:37 +0100 | [diff] [blame] | 382 | install_element_ve(&show_talloc_cmd); |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 385 | int main(int argc, char **argv) |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 386 | { |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 387 | struct osmo_sua_user *sua_user; |
| 388 | struct osmo_sua_link *sua_link; |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 389 | struct osmo_stream_srv_link *srv; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 390 | int rc; |
| 391 | |
| 392 | tall_hnb_ctx = talloc_named_const(NULL, 0, "hnb_context"); |
Harald Welte | 08de638 | 2015-08-31 09:54:45 +0200 | [diff] [blame] | 393 | talloc_asn1_ctx = talloc_named_const(NULL, 0, "asn1_context"); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 394 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 395 | g_hnb_gw = hnb_gw_create(tall_hnb_ctx); |
Harald Welte | 90256ba | 2015-12-23 20:16:36 +0100 | [diff] [blame] | 396 | |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 397 | rc = osmo_init_logging(&hnbgw_log_info); |
| 398 | if (rc < 0) |
| 399 | exit(1); |
| 400 | |
| 401 | vty_init(&vty_info); |
Daniel Willmann | 56f6273 | 2015-12-02 11:22:53 +0100 | [diff] [blame] | 402 | hnbgw_vty_init(); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 403 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 404 | rc = telnet_init(NULL, g_hnb_gw, 2323); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 405 | if (rc < 0) { |
| 406 | perror("Error binding VTY port"); |
| 407 | exit(1); |
| 408 | } |
| 409 | |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 410 | osmo_sua_set_log_area(DSUA); |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 411 | ranap_set_log_area(DRANAP); |
Harald Welte | 75a4e65 | 2015-12-22 23:59:24 +0100 | [diff] [blame] | 412 | |
Harald Welte | c4338de | 2015-12-24 00:40:52 +0100 | [diff] [blame] | 413 | g_hnb_gw->cnlink_cs = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.1", SUA_PORT); |
| 414 | g_hnb_gw->cnlink_ps = hnbgw_cnlink_init(g_hnb_gw, "127.0.0.2", SUA_PORT); |
| 415 | |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 416 | srv = osmo_stream_srv_link_create(tall_hnb_ctx); |
| 417 | if (!srv) { |
| 418 | perror("cannot create server"); |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 419 | exit(1); |
| 420 | } |
Daniel Willmann | 6480cad | 2016-01-06 18:06:26 +0100 | [diff] [blame] | 421 | osmo_stream_srv_link_set_data(srv, g_hnb_gw); |
| 422 | osmo_stream_srv_link_set_proto(srv, IPPROTO_SCTP); |
| 423 | osmo_stream_srv_link_set_addr(srv, "0.0.0.0"); |
| 424 | osmo_stream_srv_link_set_port(srv, g_hnb_gw->config.iuh_listen_port); |
| 425 | osmo_stream_srv_link_set_accept_cb(srv, accept_cb); |
| 426 | |
| 427 | if (osmo_stream_srv_link_open(srv) < 0) { |
| 428 | perror("Cannot oper server"); |
| 429 | exit(1); |
| 430 | } |
| 431 | g_hnb_gw->iuh = srv; |
Harald Welte | b3dae30 | 2015-08-30 12:20:09 +0200 | [diff] [blame] | 432 | |
| 433 | if (daemonize) { |
| 434 | rc = osmo_daemonize(); |
| 435 | if (rc < 0) { |
| 436 | perror("Error during daemonize"); |
| 437 | exit(1); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | while (1) { |
| 442 | rc = osmo_select_main(0); |
| 443 | if (rc < 0) |
| 444 | exit(3); |
| 445 | } |
| 446 | |
| 447 | /* not reached */ |
| 448 | exit(0); |
Harald Welte | a2e6a7a | 2015-08-29 21:47:39 +0200 | [diff] [blame] | 449 | } |