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 | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 22 | #include <gsm_timer.h> |
Ivan Kluchnikov | a9f1ff2 | 2012-05-24 22:25:06 +0400 | [diff] [blame] | 23 | #include <gprs_debug.h> |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 24 | #include <unistd.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 25 | #include <stdbool.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <errno.h> |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 30 | #include <getopt.h> |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 31 | #include <signal.h> |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 32 | #include <sched.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 33 | #include <bts.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 34 | #include <gprs_coding_scheme.h> |
| 35 | #include <osmocom/pcu/pcuif_proto.h> |
Alexander Couzens | 5c3783b | 2019-05-25 05:41:18 +0200 | [diff] [blame] | 36 | #include "gprs_bssgp_pcu.h" |
| 37 | |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 38 | extern "C" { |
| 39 | #include "pcu_vty.h" |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 40 | #include <osmocom/gprs/gprs_bssgp.h> |
| 41 | #include <osmocom/gprs/gprs_ns.h> |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 42 | #include <osmocom/vty/telnet_interface.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 43 | #include <osmocom/vty/command.h> |
| 44 | #include <osmocom/vty/vty.h> |
Neels Hofmeyr | 01826c1 | 2016-08-23 16:31:02 +0200 | [diff] [blame] | 45 | #include <osmocom/vty/ports.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 46 | #include <osmocom/core/rate_ctr.h> |
| 47 | #include <osmocom/core/select.h> |
| 48 | #include <osmocom/core/application.h> |
| 49 | #include <osmocom/core/msgb.h> |
Jacob Erlbeck | 42aba81 | 2015-11-10 15:32:00 +0100 | [diff] [blame] | 50 | #include <osmocom/core/stats.h> |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 51 | #include <osmocom/core/gsmtap.h> |
| 52 | #include <osmocom/core/gsmtap_util.h> |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 53 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 54 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 55 | extern struct gprs_nsvc *nsvc; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 56 | uint16_t spoof_mcc = 0, spoof_mnc = 0; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 57 | bool spoof_mnc_3_digits = false; |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 58 | static int config_given = 0; |
Holger Hans Peter Freyther | 4e8b50c | 2013-11-11 20:12:30 +0100 | [diff] [blame] | 59 | static char *config_file = strdup("osmo-pcu.cfg"); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 60 | extern struct vty_app_info pcu_vty_info; |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 61 | void *tall_pcu_ctx = NULL; |
Andreas Eversberg | 7a5a67a | 2013-01-16 08:43:24 +0100 | [diff] [blame] | 62 | extern void *bv_tall_ctx; |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 63 | static int quit = 0; |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 64 | static int rt_prio = -1; |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 65 | static bool daemonize = false; |
Holger Hans Peter Freyther | 173ef90 | 2016-03-04 17:54:09 +0100 | [diff] [blame] | 66 | 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] | 67 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 68 | static void print_help() |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 69 | { |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 70 | printf( "Options:\n" |
| 71 | " -h --help This text\n" |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 72 | " -c --config-file Specify the filename of the config " |
| 73 | "file\n" |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 74 | " -m --mcc MCC Use given MCC instead of value " |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 75 | "provided by BTS\n" |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 76 | " -n --mnc MNC Use given MNC instead of value " |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 77 | "provided by BTS\n" |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 78 | " -V --version Print version\n" |
| 79 | " -r --realtime PRIO Use SCHED_RR with the specified " |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 80 | "priority\n" |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 81 | " -D --daemonize Fork the process into a background " |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 82 | "daemon\n" |
Rafael Diniz | 0e6e45a | 2019-04-06 18:21:55 -0300 | [diff] [blame] | 83 | " -i --gsmtap-ip The destination IP used for GSMTAP\n" |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 84 | ); |
| 85 | } |
| 86 | |
| 87 | /* FIXME: finally get some option parsing code into libosmocore */ |
| 88 | static void handle_options(int argc, char **argv) |
| 89 | { |
| 90 | while (1) { |
| 91 | int option_idx = 0, c; |
| 92 | static const struct option long_options[] = { |
| 93 | { "help", 0, 0, 'h' }, |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 94 | { "config-file", 1, 0, 'c' }, |
Andreas Eversberg | 1944bd5 | 2012-07-06 09:32:39 +0200 | [diff] [blame] | 95 | { "mcc", 1, 0, 'm' }, |
| 96 | { "mnc", 1, 0, 'n' }, |
Harald Welte | e5a0939 | 2013-01-17 12:28:16 +0100 | [diff] [blame] | 97 | { "version", 0, 0, 'V' }, |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 98 | { "realtime", 1, 0, 'r' }, |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 99 | { "daemonize", 0, 0, 'D' }, |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 100 | { "exit", 0, 0, 'e' }, |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 101 | { "gsmtap-ip", 1, 0, 'i' }, |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 102 | { 0, 0, 0, 0 } |
| 103 | }; |
| 104 | |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 105 | c = getopt_long(argc, argv, "hc:m:n:Vr:De:i:", |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 106 | long_options, &option_idx); |
| 107 | if (c == -1) |
| 108 | break; |
| 109 | |
| 110 | switch (c) { |
| 111 | case 'h': |
| 112 | print_help(); |
| 113 | exit(0); |
| 114 | break; |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 115 | case 'c': |
Holger Hans Peter Freyther | 4e8b50c | 2013-11-11 20:12:30 +0100 | [diff] [blame] | 116 | free(config_file); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 117 | config_file = strdup(optarg); |
| 118 | config_given = 1; |
| 119 | break; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 120 | case 'm': |
| 121 | spoof_mcc = atoi(optarg); |
| 122 | break; |
| 123 | case 'n': |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 124 | if (osmo_mnc_from_str(optarg, &spoof_mnc, &spoof_mnc_3_digits)) { |
| 125 | fprintf(stderr, "Error decoding MNC '%s'\n", optarg); |
| 126 | exit(1); |
| 127 | } |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 128 | break; |
Harald Welte | e5a0939 | 2013-01-17 12:28:16 +0100 | [diff] [blame] | 129 | case 'V': |
| 130 | print_version(1); |
| 131 | exit(0); |
| 132 | break; |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 133 | case 'i': |
| 134 | gsmtap_addr = optarg; |
| 135 | break; |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 136 | case 'r': |
| 137 | rt_prio = atoi(optarg); |
| 138 | break; |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 139 | case 'D': |
| 140 | daemonize = true; |
| 141 | break; |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 142 | case 'e': |
Daniel Willmann | 6d8884d | 2014-06-04 18:30:59 +0200 | [diff] [blame] | 143 | fprintf(stderr, "Warning: Option '-e' is deprecated!\n"); |
Holger Hans Peter Freyther | a30f476 | 2013-07-11 16:13:38 +0200 | [diff] [blame] | 144 | break; |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 145 | default: |
| 146 | fprintf(stderr, "Unknown option '%c'\n", c); |
| 147 | exit(0); |
| 148 | break; |
| 149 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 150 | } |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 151 | } |
| 152 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 153 | void sighandler(int sigset) |
| 154 | { |
Harald Welte | 45143d2 | 2018-05-15 15:24:30 +0200 | [diff] [blame] | 155 | if (sigset == SIGPIPE) |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 156 | return; |
| 157 | |
| 158 | fprintf(stderr, "Signal %d received.\n", sigset); |
| 159 | |
| 160 | switch (sigset) { |
| 161 | case SIGINT: |
Holger Hans Peter Freyther | 72075f0 | 2013-03-19 18:33:06 +0400 | [diff] [blame] | 162 | case SIGTERM: |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 163 | /* If another signal is received afterwards, the program |
| 164 | * is terminated without finishing shutdown process. |
| 165 | */ |
| 166 | signal(SIGINT, SIG_DFL); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 167 | signal(SIGTERM, SIG_DFL); |
| 168 | signal(SIGPIPE, SIG_DFL); |
| 169 | signal(SIGABRT, SIG_DFL); |
| 170 | signal(SIGUSR1, SIG_DFL); |
| 171 | signal(SIGUSR2, SIG_DFL); |
| 172 | |
| 173 | quit = 1; |
| 174 | break; |
| 175 | case SIGABRT: |
| 176 | /* in case of abort, we want to obtain a talloc report |
| 177 | * and then return to the caller, who will abort the process |
| 178 | */ |
| 179 | case SIGUSR1: |
| 180 | case SIGUSR2: |
| 181 | talloc_report_full(tall_pcu_ctx, stderr); |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 186 | int main(int argc, char *argv[]) |
| 187 | { |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 188 | struct sched_param param; |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 189 | struct gprs_rlcmac_bts *bts; |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 190 | int rc; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 191 | |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 192 | /* tall_pcu_ctx may already have been initialized in bts.cpp during early_init(). */ |
| 193 | if (!tall_pcu_ctx) { |
| 194 | tall_pcu_ctx = talloc_named_const(NULL, 1, "Osmo-PCU context"); |
| 195 | if (!tall_pcu_ctx) |
| 196 | return -ENOMEM; |
| 197 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
| 198 | } |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 199 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 200 | bts = bts_main_data(); |
Andreas Eversberg | cd8a83a | 2012-09-23 06:41:21 +0200 | [diff] [blame] | 201 | bts->fc_interval = 1; |
Andreas Eversberg | 499ff41 | 2012-10-03 14:21:36 +0200 | [diff] [blame] | 202 | bts->initial_cs_dl = bts->initial_cs_ul = 1; |
Jacob Erlbeck | 96ccea8 | 2016-01-07 15:00:43 +0100 | [diff] [blame] | 203 | bts->initial_mcs_dl = bts->initial_mcs_ul = 1; |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 204 | bts->cs1 = 1; |
Andreas Eversberg | dfa563c | 2012-07-06 08:13:59 +0200 | [diff] [blame] | 205 | bts->n3101 = 10; |
| 206 | bts->n3103 = 4; |
| 207 | bts->n3105 = 8; |
Andreas Eversberg | 0b874b6 | 2013-03-16 15:56:01 +0100 | [diff] [blame] | 208 | bts->alpha = 0; /* a = 0.0 */ |
Max | 84bf0fa | 2017-09-01 11:02:40 +0200 | [diff] [blame] | 209 | bts->si13_is_set = false; |
Jacob Erlbeck | 3c91cb8 | 2015-06-04 10:05:48 +0200 | [diff] [blame] | 210 | bts->ms_idle_sec = 60; /* slightly above T3314 (default 44s, 24.008, 11.2.2) */ |
Jacob Erlbeck | 1751c62 | 2015-06-04 12:12:32 +0200 | [diff] [blame] | 211 | bts->cs_adj_enabled = 1; |
| 212 | bts->cs_adj_upper_limit = 33; /* Decrease CS if the error rate is above */ |
| 213 | bts->cs_adj_lower_limit = 10; /* Increase CS if the error rate is below */ |
Max | 8119ecd | 2019-03-06 19:03:01 +0100 | [diff] [blame] | 214 | bts->max_cs_ul = MAX_GPRS_CS; |
| 215 | bts->max_cs_dl = MAX_GPRS_CS; |
| 216 | bts->max_mcs_ul = MAX_EDGE_MCS; |
| 217 | bts->max_mcs_dl = MAX_EDGE_MCS; |
Jacob Erlbeck | 94cde13 | 2015-06-09 09:44:36 +0200 | [diff] [blame] | 218 | /* CS-1 to CS-4 */ |
| 219 | bts->cs_lqual_ranges[0].low = -256; |
| 220 | bts->cs_lqual_ranges[0].high = 6; |
| 221 | bts->cs_lqual_ranges[1].low = 5; |
| 222 | bts->cs_lqual_ranges[1].high = 8; |
| 223 | bts->cs_lqual_ranges[2].low = 7; |
| 224 | bts->cs_lqual_ranges[2].high = 13; |
| 225 | bts->cs_lqual_ranges[3].low = 12; |
| 226 | bts->cs_lqual_ranges[3].high = 256; |
Minh-Quang Nguyen | 1f18909 | 2017-08-16 09:50:06 -0400 | [diff] [blame] | 227 | |
| 228 | /* MCS-1 to MCS-9 */ |
| 229 | /* Default thresholds are referenced from literature */ |
| 230 | /* Fig. 2.3, Chapter 2, Optimizing Wireless Communication Systems, Springer (2009) */ |
| 231 | bts->mcs_lqual_ranges[0].low = -256; |
| 232 | bts->mcs_lqual_ranges[0].high = 6; |
| 233 | bts->mcs_lqual_ranges[1].low = 5; |
| 234 | bts->mcs_lqual_ranges[1].high = 8; |
| 235 | bts->mcs_lqual_ranges[2].low = 7; |
| 236 | bts->mcs_lqual_ranges[2].high = 13; |
| 237 | bts->mcs_lqual_ranges[3].low = 12; |
| 238 | bts->mcs_lqual_ranges[3].high = 15; |
| 239 | bts->mcs_lqual_ranges[4].low = 14; |
| 240 | bts->mcs_lqual_ranges[4].high = 17; |
| 241 | bts->mcs_lqual_ranges[5].low = 16; |
| 242 | bts->mcs_lqual_ranges[5].high = 18; |
| 243 | bts->mcs_lqual_ranges[6].low = 17; |
| 244 | bts->mcs_lqual_ranges[6].high = 20; |
| 245 | bts->mcs_lqual_ranges[7].low = 19; |
| 246 | bts->mcs_lqual_ranges[7].high = 24; |
| 247 | bts->mcs_lqual_ranges[8].low = 23; |
| 248 | bts->mcs_lqual_ranges[8].high = 256; |
Jacob Erlbeck | 70b96aa | 2015-06-12 10:52:34 +0200 | [diff] [blame] | 249 | bts->cs_downgrade_threshold = 200; |
Andreas Eversberg | 5dac2f0 | 2012-06-27 15:52:04 +0200 | [diff] [blame] | 250 | |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 251 | /* TODO: increase them when CRBB decoding is implemented */ |
| 252 | bts->ws_base = 64; |
| 253 | bts->ws_pdch = 0; |
| 254 | |
Jacob Erlbeck | b31f5ef | 2015-07-21 14:00:14 +0200 | [diff] [blame] | 255 | bts->llc_codel_interval_msec = LLC_CODEL_USE_DEFAULT; |
Jacob Erlbeck | eb93f59 | 2015-11-30 11:53:06 +0100 | [diff] [blame] | 256 | bts->dl_tbf_idle_msec = 2000; |
| 257 | bts->llc_idle_ack_csec = 10; |
Jacob Erlbeck | b31f5ef | 2015-07-21 14:00:14 +0200 | [diff] [blame] | 258 | |
Aravind Sirsikar | 50b0970 | 2016-08-22 17:21:10 +0530 | [diff] [blame] | 259 | /* |
| 260 | * By default resegmentation is supported in DL |
| 261 | * can also be configured through VTY |
| 262 | */ |
| 263 | bts->dl_arq_type = EGPRS_ARQ1; |
| 264 | |
Pau Espin Pedrol | c4178e5 | 2017-08-08 15:03:50 +0200 | [diff] [blame] | 265 | bts->pcu_sock_path = talloc_strdup(tall_pcu_ctx, PCU_SOCK_DEFAULT); |
| 266 | |
Neels Hofmeyr | 78ce591 | 2017-02-08 17:07:31 +0100 | [diff] [blame] | 267 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 268 | |
Jacob Erlbeck | 42aba81 | 2015-11-10 15:32:00 +0100 | [diff] [blame] | 269 | osmo_stats_init(tall_pcu_ctx); |
sivasankari | ee78bf0 | 2016-12-15 17:39:14 +0530 | [diff] [blame] | 270 | rate_ctr_init(tall_pcu_ctx); |
Jacob Erlbeck | 56af6d5 | 2015-08-17 14:06:21 +0200 | [diff] [blame] | 271 | gprs_ns_set_log_ss(DNS); |
Jacob Erlbeck | 00fc6b1 | 2015-04-09 19:26:39 +0200 | [diff] [blame] | 272 | bssgp_set_log_ss(DBSSGP); |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 273 | |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 274 | vty_init(&pcu_vty_info); |
Pau Espin Pedrol | cd2ac56 | 2019-08-05 14:30:44 +0200 | [diff] [blame] | 275 | pcu_vty_init(); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 276 | |
Andreas Eversberg | 81e895b | 2012-07-06 08:24:53 +0200 | [diff] [blame] | 277 | handle_options(argc, argv); |
| 278 | if ((!!spoof_mcc) + (!!spoof_mnc) == 1) { |
| 279 | fprintf(stderr, "--mcc and --mnc must be specified " |
| 280 | "together.\n"); |
| 281 | exit(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 282 | } |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 283 | |
Max | 2efdf69 | 2016-02-22 11:39:30 +0100 | [diff] [blame] | 284 | bts->gsmtap = gsmtap_source_init(gsmtap_addr, GSMTAP_UDP_PORT, 1); |
| 285 | |
| 286 | if (bts->gsmtap) |
| 287 | gsmtap_source_add_sink(bts->gsmtap); |
| 288 | else |
| 289 | fprintf(stderr, "Failed to initialize GSMTAP for %s\n", gsmtap_addr); |
| 290 | |
Alexander Couzens | 5c3783b | 2019-05-25 05:41:18 +0200 | [diff] [blame] | 291 | bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx); |
| 292 | if (!bssgp_nsi) { |
| 293 | LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n"); |
| 294 | exit(1); |
| 295 | } |
| 296 | gprs_ns_vty_init(bssgp_nsi); |
| 297 | |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 298 | rc = vty_read_config_file(config_file, NULL); |
| 299 | if (rc < 0 && config_given) { |
| 300 | fprintf(stderr, "Failed to parse the config file: '%s'\n", |
| 301 | config_file); |
| 302 | exit(1); |
| 303 | } |
| 304 | if (rc < 0) |
| 305 | fprintf(stderr, "No config file: '%s' Using default config.\n", |
| 306 | config_file); |
| 307 | |
Neels Hofmeyr | fd9e16c | 2016-08-23 16:43:05 +0200 | [diff] [blame] | 308 | rc = telnet_init_dynif(tall_pcu_ctx, NULL, vty_get_bind_addr(), |
| 309 | OSMO_VTY_PORT_PCU); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 310 | if (rc < 0) { |
| 311 | fprintf(stderr, "Error initializing telnet\n"); |
| 312 | exit(1); |
| 313 | } |
| 314 | |
Andreas Eversberg | f298fa8 | 2012-07-13 14:50:57 +0200 | [diff] [blame] | 315 | if (!bts->alloc_algorithm) |
Jacob Erlbeck | f16a069 | 2015-07-14 14:29:34 +0200 | [diff] [blame] | 316 | bts->alloc_algorithm = alloc_algorithm_dynamic; |
Andreas Eversberg | f298fa8 | 2012-07-13 14:50:57 +0200 | [diff] [blame] | 317 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 318 | rc = pcu_l1if_open(); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 319 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 320 | if (rc < 0) |
| 321 | return rc; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 322 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 323 | signal(SIGINT, sighandler); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 324 | signal(SIGTERM, sighandler); |
| 325 | signal(SIGPIPE, sighandler); |
| 326 | signal(SIGABRT, sighandler); |
| 327 | signal(SIGUSR1, sighandler); |
| 328 | signal(SIGUSR2, sighandler); |
Harald Welte | 45143d2 | 2018-05-15 15:24:30 +0200 | [diff] [blame] | 329 | osmo_init_ignore_signals(); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 330 | |
Andreas Eversberg | 783aa4b | 2013-05-05 09:15:11 +0200 | [diff] [blame] | 331 | /* enable realtime priority for us */ |
| 332 | if (rt_prio != -1) { |
| 333 | memset(¶m, 0, sizeof(param)); |
| 334 | param.sched_priority = rt_prio; |
| 335 | rc = sched_setscheduler(getpid(), SCHED_RR, ¶m); |
| 336 | if (rc != 0) { |
| 337 | fprintf(stderr, "Setting SCHED_RR priority(%d) failed: %s\n", |
| 338 | param.sched_priority, strerror(errno)); |
| 339 | exit(1); |
| 340 | } |
| 341 | } |
| 342 | |
Rafael Diniz | f0af1b0 | 2019-01-28 22:37:46 -0200 | [diff] [blame] | 343 | if (daemonize) { |
| 344 | rc = osmo_daemonize(); |
| 345 | if (rc < 0) { |
| 346 | perror("Error during daemonize"); |
| 347 | exit(1); |
| 348 | } |
| 349 | } |
| 350 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 351 | while (!quit) { |
Ivan Kluchnikov | 61a33f7 | 2012-04-12 15:22:06 +0400 | [diff] [blame] | 352 | osmo_gsm_timers_check(); |
| 353 | osmo_gsm_timers_prepare(); |
| 354 | osmo_gsm_timers_update(); |
| 355 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 356 | osmo_select_main(0); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 357 | } |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 358 | |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 359 | telnet_exit(); |
| 360 | |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 361 | pcu_l1if_close(); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 362 | |
Max | d5ffeb5 | 2019-03-18 15:48:38 +0100 | [diff] [blame] | 363 | bts_cleanup(); |
Andreas Eversberg | e266bd4 | 2012-07-13 14:00:21 +0200 | [diff] [blame] | 364 | talloc_report_full(tall_pcu_ctx, stderr); |
Andreas Eversberg | ebde64f | 2012-07-12 09:18:42 +0200 | [diff] [blame] | 365 | talloc_free(tall_pcu_ctx); |
Andreas Eversberg | 3e372d5 | 2012-07-06 09:28:15 +0200 | [diff] [blame] | 366 | |
| 367 | return 0; |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 368 | } |