Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* pcu_main.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 20 | #include <pcu_l1_if.h> |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 21 | #include <gprs_rlcmac.h> |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 22 | #include <gprs_debug.h> |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 23 | #include <unistd.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 24 | #include <stdbool.h> |
| 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
| 28 | #include <errno.h> |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 29 | #include <getopt.h> |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 30 | #include <signal.h> |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 31 | #include <sched.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 32 | #include <bts.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 33 | #include <osmocom/pcu/pcuif_proto.h> |
Alexander Couzens | 5c3783b | 2019-05-25 05:41:18 +0200 | [diff] [blame] | 34 | #include "gprs_bssgp_pcu.h" |
| 35 | |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 36 | extern "C" { |
| 37 | #include "pcu_vty.h" |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 38 | #include "coding_scheme.h" |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 39 | #include <osmocom/gprs/gprs_bssgp.h> |
Alexander Couzens | 290d903 | 2020-09-16 21:52:02 +0200 | [diff] [blame] | 40 | #include <osmocom/gprs/gprs_ns2.h> |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 41 | #include <osmocom/vty/telnet_interface.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 42 | #include <osmocom/vty/command.h> |
| 43 | #include <osmocom/vty/vty.h> |
Neels Hofmeyr | 01826c1 | 2016-08-23 16:31:02 +0200 | [diff] [blame] | 44 | #include <osmocom/vty/ports.h> |
Harald Welte | 398f60e | 2020-12-10 13:39:21 +0100 | [diff] [blame] | 45 | #include <osmocom/vty/logging.h> |
Pau Espin Pedrol | b75c27f | 2020-08-18 13:43:43 +0200 | [diff] [blame] | 46 | #include <osmocom/vty/cpu_sched_vty.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 47 | #include <osmocom/core/rate_ctr.h> |
| 48 | #include <osmocom/core/select.h> |
| 49 | #include <osmocom/core/application.h> |
| 50 | #include <osmocom/core/msgb.h> |
Jacob Erlbeck | 42aba81 | 2015-11-10 15:32:00 +0100 | [diff] [blame] | 51 | #include <osmocom/core/stats.h> |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 52 | #include <osmocom/core/gsmtap.h> |
| 53 | #include <osmocom/core/gsmtap_util.h> |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 54 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 55 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 56 | extern struct gprs_nsvc *nsvc; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 57 | uint16_t spoof_mcc = 0, spoof_mnc = 0; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 58 | bool spoof_mnc_3_digits = false; |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 59 | static int config_given = 0; |
Holger Hans Peter Freyther | 4e8b50c | 2013-11-11 20:12:30 +0100 | [diff] [blame] | 60 | static char *config_file = strdup("osmo-pcu.cfg"); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 61 | extern struct vty_app_info pcu_vty_info; |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 62 | void *tall_pcu_ctx = NULL; |
Andreas Eversberg | 7a5a67a | 2013-01-16 08:43:24 +0100 | [diff] [blame] | 63 | extern void *bv_tall_ctx; |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 64 | static int quit = 0; |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 65 | static int rt_prio = -1; |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 66 | static bool daemonize = false; |
Holger Hans Peter Freyther | 173ef90 | 2016-03-04 17:54:09 +0100 | [diff] [blame] | 67 | static const char *gsmtap_addr = "localhost"; // FIXME: use gengetopt's default value instead |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 68 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 69 | static void print_help() |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 70 | { |
Vadim Yanitskiy | 35668a2 | 2020-10-24 05:10:30 +0700 | [diff] [blame] | 71 | printf( "Some useful options:\n" |
| 72 | " -h --help This text\n" |
| 73 | " -c --config-file Specify the filename of the config file\n" |
| 74 | " -m --mcc MCC Use given MCC instead of value provided by BTS\n" |
| 75 | " -n --mnc MNC Use given MNC instead of value provided by BTS\n" |
| 76 | " -V --version Print version\n" |
| 77 | " -r --realtime PRIO Use SCHED_RR with the specified priority\n" |
| 78 | " -D --daemonize Fork the process into a background daemon\n" |
| 79 | " -i --gsmtap-ip The destination IP used for GSMTAP\n" |
Vadim Yanitskiy | 1136fdb | 2020-10-24 05:14:52 +0700 | [diff] [blame] | 80 | "\nVTY reference generation:\n" |
| 81 | " --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n" |
| 82 | " --vty-ref-xml Generate the VTY reference XML output and exit.\n" |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 83 | ); |
| 84 | } |
| 85 | |
Vadim Yanitskiy | 1136fdb | 2020-10-24 05:14:52 +0700 | [diff] [blame] | 86 | static void handle_long_options(const char *prog_name, const int long_option) |
| 87 | { |
| 88 | static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT; |
| 89 | |
| 90 | switch (long_option) { |
| 91 | case 1: |
| 92 | vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg); |
| 93 | if (vty_ref_mode < 0) { |
| 94 | fprintf(stderr, "%s: Unknown VTY reference generation " |
| 95 | "mode '%s'\n", prog_name, optarg); |
| 96 | exit(2); |
| 97 | } |
| 98 | break; |
| 99 | case 2: |
| 100 | fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n", |
| 101 | get_value_string(vty_ref_gen_mode_names, vty_ref_mode), |
| 102 | get_value_string(vty_ref_gen_mode_desc, vty_ref_mode)); |
| 103 | vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode); |
| 104 | exit(0); |
| 105 | default: |
| 106 | fprintf(stderr, "%s: error parsing cmdline options\n", prog_name); |
| 107 | exit(2); |
| 108 | } |
| 109 | } |
| 110 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 111 | /* FIXME: finally get some option parsing code into libosmocore */ |
| 112 | static void handle_options(int argc, char **argv) |
| 113 | { |
| 114 | while (1) { |
| 115 | int option_idx = 0, c; |
Philipp Maier | 08c5037 | 2020-10-09 20:41:17 +0200 | [diff] [blame] | 116 | static int long_option = 0; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 117 | static const struct option long_options[] = { |
| 118 | { "help", 0, 0, 'h' }, |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 119 | { "config-file", 1, 0, 'c' }, |
Andreas Eversberg | 1944bd5 | 2012-07-06 09:32:39 +0200 | [diff] [blame] | 120 | { "mcc", 1, 0, 'm' }, |
| 121 | { "mnc", 1, 0, 'n' }, |
Harald Welte | e5a0939 | 2013-01-17 12:28:16 +0100 | [diff] [blame] | 122 | { "version", 0, 0, 'V' }, |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 123 | { "realtime", 1, 0, 'r' }, |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 124 | { "daemonize", 0, 0, 'D' }, |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 125 | { "exit", 0, 0, 'e' }, |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 126 | { "gsmtap-ip", 1, 0, 'i' }, |
Vadim Yanitskiy | 1136fdb | 2020-10-24 05:14:52 +0700 | [diff] [blame] | 127 | { "vty-ref-mode", 1, &long_option, 1 }, |
| 128 | { "vty-ref-xml", 0, &long_option, 2 }, |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 129 | { 0, 0, 0, 0 } |
| 130 | }; |
| 131 | |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 132 | c = getopt_long(argc, argv, "hc:m:n:Vr:De:i:", |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 133 | long_options, &option_idx); |
| 134 | if (c == -1) |
| 135 | break; |
| 136 | |
| 137 | switch (c) { |
| 138 | case 'h': |
| 139 | print_help(); |
| 140 | exit(0); |
| 141 | break; |
Philipp Maier | 08c5037 | 2020-10-09 20:41:17 +0200 | [diff] [blame] | 142 | case 0: |
Vadim Yanitskiy | 1136fdb | 2020-10-24 05:14:52 +0700 | [diff] [blame] | 143 | handle_long_options(argv[0], long_option); |
| 144 | break; |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 145 | case 'c': |
Holger Hans Peter Freyther | 4e8b50c | 2013-11-11 20:12:30 +0100 | [diff] [blame] | 146 | free(config_file); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 147 | config_file = strdup(optarg); |
| 148 | config_given = 1; |
| 149 | break; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 150 | case 'm': |
| 151 | spoof_mcc = atoi(optarg); |
| 152 | break; |
| 153 | case 'n': |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 154 | if (osmo_mnc_from_str(optarg, &spoof_mnc, &spoof_mnc_3_digits)) { |
| 155 | fprintf(stderr, "Error decoding MNC '%s'\n", optarg); |
| 156 | exit(1); |
| 157 | } |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 158 | break; |
Harald Welte | e5a0939 | 2013-01-17 12:28:16 +0100 | [diff] [blame] | 159 | case 'V': |
| 160 | print_version(1); |
| 161 | exit(0); |
| 162 | break; |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 163 | case 'i': |
| 164 | gsmtap_addr = optarg; |
| 165 | break; |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 166 | case 'r': |
| 167 | rt_prio = atoi(optarg); |
| 168 | break; |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 169 | case 'D': |
| 170 | daemonize = true; |
| 171 | break; |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 172 | case 'e': |
Daniel Willmann | 6d8884d | 2014-06-04 18:30:59 +0200 | [diff] [blame] | 173 | fprintf(stderr, "Warning: Option '-e' is deprecated!\n"); |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 174 | break; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 175 | default: |
| 176 | fprintf(stderr, "Unknown option '%c'\n", c); |
| 177 | exit(0); |
| 178 | break; |
| 179 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 180 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 181 | } |
| 182 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 183 | void sighandler(int sigset) |
| 184 | { |
Harald Welte | 45143d2 | 2018-05-15 15:24:30 +0200 | [diff] [blame] | 185 | if (sigset == SIGPIPE) |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 186 | return; |
| 187 | |
| 188 | fprintf(stderr, "Signal %d received.\n", sigset); |
| 189 | |
| 190 | switch (sigset) { |
| 191 | case SIGINT: |
Holger Hans Peter Freyther | 72075f0 | 2013-03-19 18:33:06 +0400 | [diff] [blame] | 192 | case SIGTERM: |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 193 | /* If another signal is received afterwards, the program |
| 194 | * is terminated without finishing shutdown process. |
| 195 | */ |
| 196 | signal(SIGINT, SIG_DFL); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 197 | signal(SIGTERM, SIG_DFL); |
| 198 | signal(SIGPIPE, SIG_DFL); |
| 199 | signal(SIGABRT, SIG_DFL); |
| 200 | signal(SIGUSR1, SIG_DFL); |
| 201 | signal(SIGUSR2, SIG_DFL); |
| 202 | |
| 203 | quit = 1; |
| 204 | break; |
| 205 | case SIGABRT: |
Pau Espin Pedrol | 58cd1d2 | 2020-11-25 17:43:32 +0100 | [diff] [blame] | 206 | /* in case of abort, we want to obtain a talloc report and |
| 207 | * then run default SIGABRT handler, who will generate coredump |
| 208 | * and abort the process. abort() should do this for us after we |
| 209 | * return, but program wouldn't exit if an external SIGABRT is |
| 210 | * received. |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 211 | */ |
Pau Espin Pedrol | 58cd1d2 | 2020-11-25 17:43:32 +0100 | [diff] [blame] | 212 | talloc_report_full(tall_pcu_ctx, stderr); |
| 213 | signal(SIGABRT, SIG_DFL); |
| 214 | raise(SIGABRT); |
| 215 | break; |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 216 | case SIGUSR1: |
| 217 | case SIGUSR2: |
| 218 | talloc_report_full(tall_pcu_ctx, stderr); |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 223 | int main(int argc, char *argv[]) |
| 224 | { |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 225 | struct sched_param param; |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 226 | struct gprs_pcu *pcu; |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 227 | int rc; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 228 | |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 229 | /* tall_pcu_ctx may already have been initialized in bts.cpp during early_init(). */ |
| 230 | if (!tall_pcu_ctx) { |
| 231 | tall_pcu_ctx = talloc_named_const(NULL, 1, "Osmo-PCU context"); |
| 232 | if (!tall_pcu_ctx) |
| 233 | return -ENOMEM; |
| 234 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
| 235 | } |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 236 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 237 | pcu = gprs_pcu_alloc(tall_pcu_ctx); |
| 238 | the_pcu = pcu; /* globally avaialable object */ |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 239 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 240 | pcu->pcu_sock_path = talloc_strdup(tall_pcu_ctx, PCU_SOCK_DEFAULT); |
Pau Espin Pedrol | c4178e5 | 2017-08-08 15:03:50 +0200 | [diff] [blame] | 241 | |
Neels Hofmeyr | 78ce591 | 2017-02-08 17:07:31 +0100 | [diff] [blame] | 242 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 243 | |
Jacob Erlbeck | 42aba81 | 2015-11-10 15:32:00 +0100 | [diff] [blame] | 244 | osmo_stats_init(tall_pcu_ctx); |
sivasankari | ee78bf0 | 2016-12-15 17:39:14 +0530 | [diff] [blame] | 245 | rate_ctr_init(tall_pcu_ctx); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 246 | |
Vadim Yanitskiy | d83c8ff | 2020-02-06 16:46:17 +0700 | [diff] [blame] | 247 | pcu_vty_info.tall_ctx = tall_pcu_ctx; |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 248 | vty_init(&pcu_vty_info); |
Pau Espin Pedrol | cd2ac56 | 2019-08-05 14:30:44 +0200 | [diff] [blame] | 249 | pcu_vty_init(); |
Pau Espin Pedrol | b75c27f | 2020-08-18 13:43:43 +0200 | [diff] [blame] | 250 | osmo_cpu_sched_vty_init(tall_pcu_ctx); |
Harald Welte | 398f60e | 2020-12-10 13:39:21 +0100 | [diff] [blame] | 251 | logging_vty_add_deprecated_subsys(tall_pcu_ctx, "bssgp"); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 252 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 253 | handle_options(argc, argv); |
| 254 | if ((!!spoof_mcc) + (!!spoof_mnc) == 1) { |
| 255 | fprintf(stderr, "--mcc and --mnc must be specified " |
| 256 | "together.\n"); |
| 257 | exit(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 258 | } |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 259 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 260 | pcu->gsmtap = gsmtap_source_init(gsmtap_addr, GSMTAP_UDP_PORT, 1); |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 261 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 262 | if (pcu->gsmtap) |
| 263 | gsmtap_source_add_sink(pcu->gsmtap); |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 264 | else |
| 265 | fprintf(stderr, "Failed to initialize GSMTAP for %s\n", gsmtap_addr); |
| 266 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 267 | pcu->nsi = gprs_ns2_instantiate(tall_pcu_ctx, gprs_ns_prim_cb, NULL); |
| 268 | if (!pcu->nsi) { |
Alexander Couzens | 5c3783b | 2019-05-25 05:41:18 +0200 | [diff] [blame] | 269 | LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); |
| 270 | exit(1); |
| 271 | } |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 272 | bssgp_set_bssgp_callback(gprs_gp_send_cb, pcu->nsi); |
Alexander Couzens | 54211b1 | 2021-01-25 20:16:08 +0100 | [diff] [blame] | 273 | gprs_ns2_vty_init(pcu->nsi); |
Alexander Couzens | 5c3783b | 2019-05-25 05:41:18 +0200 | [diff] [blame] | 274 | |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 275 | rc = vty_read_config_file(config_file, NULL); |
| 276 | if (rc < 0 && config_given) { |
| 277 | fprintf(stderr, "Failed to parse the config file: '%s'\n", |
| 278 | config_file); |
| 279 | exit(1); |
| 280 | } |
| 281 | if (rc < 0) |
| 282 | fprintf(stderr, "No config file: '%s' Using default config.\n", |
| 283 | config_file); |
| 284 | |
Neels Hofmeyr | fd9e16c | 2016-08-23 16:43:05 +0200 | [diff] [blame] | 285 | rc = telnet_init_dynif(tall_pcu_ctx, NULL, vty_get_bind_addr(), |
| 286 | OSMO_VTY_PORT_PCU); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 287 | if (rc < 0) { |
| 288 | fprintf(stderr, "Error initializing telnet\n"); |
| 289 | exit(1); |
| 290 | } |
| 291 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 292 | if (!pcu->alloc_algorithm) |
| 293 | pcu->alloc_algorithm = alloc_algorithm_dynamic; |
Andreas Eversberg | f298fa8 | 2012-07-13 14:50:57 +0200 | [diff] [blame] | 294 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 295 | rc = pcu_l1if_open(); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 296 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 297 | if (rc < 0) |
| 298 | return rc; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 299 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 300 | signal(SIGINT, sighandler); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 301 | signal(SIGTERM, sighandler); |
| 302 | signal(SIGPIPE, sighandler); |
| 303 | signal(SIGABRT, sighandler); |
| 304 | signal(SIGUSR1, sighandler); |
| 305 | signal(SIGUSR2, sighandler); |
Harald Welte | 45143d2 | 2018-05-15 15:24:30 +0200 | [diff] [blame] | 306 | osmo_init_ignore_signals(); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 307 | |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 308 | /* enable realtime priority for us */ |
| 309 | if (rt_prio != -1) { |
| 310 | memset(¶m, 0, sizeof(param)); |
| 311 | param.sched_priority = rt_prio; |
| 312 | rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); |
| 313 | if (rc != 0) { |
| 314 | fprintf(stderr, "Setting SCHED_RR priority(%d) failed: %s\n", |
| 315 | param.sched_priority, strerror(errno)); |
| 316 | exit(1); |
| 317 | } |
| 318 | } |
| 319 | |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 320 | if (daemonize) { |
| 321 | rc = osmo_daemonize(); |
| 322 | if (rc < 0) { |
| 323 | perror("Error during daemonize"); |
| 324 | exit(1); |
| 325 | } |
| 326 | } |
| 327 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 328 | while (!quit) { |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 329 | osmo_select_main(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 330 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 331 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 332 | telnet_exit(); |
| 333 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 334 | pcu_l1if_close(); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 335 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 336 | TALLOC_FREE(the_pcu); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 337 | talloc_report_full(tall_pcu_ctx, stderr); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 338 | talloc_free(tall_pcu_ctx); |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 339 | |
| 340 | return 0; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 341 | } |