Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 1 | /* GPRS SGSN Implementation */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 5180844 | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <getopt.h> |
| 27 | #include <errno.h> |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 28 | #include <signal.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 31 | #include <sys/socket.h> |
| 32 | #include <netinet/in.h> |
| 33 | #include <arpa/inet.h> |
| 34 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 35 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 36 | #include <osmocom/core/talloc.h> |
| 37 | #include <osmocom/core/select.h> |
| 38 | #include <osmocom/core/rate_ctr.h> |
| 39 | #include <osmocom/core/logging.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 40 | |
Harald Welte | cfb6b28 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 41 | #include <osmocom/gprs/gprs_ns.h> |
| 42 | #include <osmocom/gprs/gprs_bssgp.h> |
| 43 | |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 44 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | f304678 | 2011-03-23 08:49:00 +0100 | [diff] [blame] | 45 | #include <osmocom/vty/logging.h> |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 46 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 47 | #include <openbsc/signal.h> |
| 48 | #include <openbsc/debug.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 49 | #include <openbsc/vty.h> |
| 50 | #include <openbsc/sgsn.h> |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 51 | #include <openbsc/gprs_llc.h> |
Harald Welte | a62e9fe | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 52 | #include <openbsc/gprs_gmm.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 53 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 54 | #include <gtp.h> |
| 55 | |
Harald Welte | 48030cf | 2010-05-04 07:41:59 +0200 | [diff] [blame] | 56 | #include "../../bscconfig.h" |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 57 | |
| 58 | /* this is here for the vty... it will never be called */ |
| 59 | void subscr_put() { abort(); } |
| 60 | |
| 61 | #define _GNU_SOURCE |
| 62 | #include <getopt.h> |
| 63 | |
| 64 | void *tall_bsc_ctx; |
| 65 | |
| 66 | struct gprs_ns_inst *sgsn_nsi; |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 67 | static int daemonize = 0; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 68 | const char *openbsc_copyright = |
Holger Hans Peter Freyther | 260646d | 2010-09-11 13:32:30 +0800 | [diff] [blame] | 69 | "Copyright (C) 2010 Harald Welte and On-Waves\r\n" |
Harald Welte | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 70 | "License AGPLv3+: GNU AGPL version 2 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n" |
Holger Hans Peter Freyther | 260646d | 2010-09-11 13:32:30 +0800 | [diff] [blame] | 71 | "This is free software: you are free to change and redistribute it.\r\n" |
| 72 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 73 | |
Harald Welte | 17072d1 | 2010-05-17 00:53:10 +0200 | [diff] [blame] | 74 | static struct sgsn_instance sgsn_inst = { |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 75 | .config_file = "osmo_sgsn.cfg", |
| 76 | .cfg = { |
| 77 | .gtp_statedir = "./", |
| 78 | }, |
| 79 | }; |
Harald Welte | 17072d1 | 2010-05-17 00:53:10 +0200 | [diff] [blame] | 80 | struct sgsn_instance *sgsn = &sgsn_inst; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 81 | |
| 82 | /* call-back function for the NS protocol */ |
| 83 | static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 84 | struct msgb *msg, uint16_t bvci) |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 85 | { |
| 86 | int rc = 0; |
| 87 | |
| 88 | switch (event) { |
| 89 | case GPRS_NS_EVT_UNIT_DATA: |
| 90 | /* hand the message into the BSSGP implementation */ |
Harald Welte | a084f12 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 91 | rc = bssgp_rcvmsg(msg); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 92 | break; |
| 93 | default: |
| 94 | LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event); |
| 95 | if (msg) |
Holger Hans Peter Freyther | 1bcd637 | 2012-03-01 20:30:32 +0100 | [diff] [blame] | 96 | msgb_free(msg); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 97 | rc = -EIO; |
| 98 | break; |
| 99 | } |
| 100 | return rc; |
| 101 | } |
| 102 | |
Harald Welte | a62e9fe | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 103 | /* call-back function for the BSSGP protocol */ |
| 104 | int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx) |
| 105 | { |
| 106 | struct osmo_bssgp_prim *bp; |
| 107 | bp = container_of(oph, struct osmo_bssgp_prim, oph); |
| 108 | |
| 109 | switch (oph->sap) { |
| 110 | case SAP_BSSGP_LL: |
| 111 | switch (oph->primitive) { |
| 112 | case PRIM_BSSGP_UL_UD: |
| 113 | return gprs_llc_rcvmsg(oph->msg, bp->tp); |
| 114 | } |
| 115 | break; |
| 116 | case SAP_BSSGP_GMM: |
| 117 | switch (oph->primitive) { |
| 118 | case PRIM_BSSGP_GMM_SUSPEND: |
| 119 | return gprs_gmm_rx_suspend(bp->ra_id, bp->tlli); |
| 120 | case PRIM_BSSGP_GMM_RESUME: |
| 121 | return gprs_gmm_rx_resume(bp->ra_id, bp->tlli, |
| 122 | *bp->u.resume.suspend_ref); |
| 123 | } |
| 124 | break; |
| 125 | case SAP_BSSGP_NM: |
| 126 | break; |
| 127 | } |
| 128 | return 0; |
| 129 | } |
| 130 | |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 131 | static void signal_handler(int signal) |
| 132 | { |
| 133 | fprintf(stdout, "signal %u received\n", signal); |
| 134 | |
| 135 | switch (signal) { |
| 136 | case SIGINT: |
Pablo Neira Ayuso | 42e41df | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 137 | osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 138 | sleep(1); |
| 139 | exit(0); |
| 140 | break; |
| 141 | case SIGABRT: |
| 142 | /* in case of abort, we want to obtain a talloc report |
| 143 | * and then return to the caller, who will abort the process */ |
| 144 | case SIGUSR1: |
| 145 | talloc_report(tall_vty_ctx, stderr); |
| 146 | talloc_report_full(tall_bsc_ctx, stderr); |
| 147 | break; |
| 148 | case SIGUSR2: |
| 149 | talloc_report_full(tall_vty_ctx, stderr); |
| 150 | break; |
| 151 | default: |
| 152 | break; |
| 153 | } |
| 154 | } |
| 155 | |
Harald Welte | 29a4b8c | 2010-05-02 21:29:17 +0200 | [diff] [blame] | 156 | /* NSI that BSSGP uses when transmitting on NS */ |
| 157 | extern struct gprs_ns_inst *bssgp_nsi; |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 158 | extern void *tall_msgb_ctx; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 159 | |
Holger Hans Peter Freyther | 3538c77 | 2010-06-08 16:11:06 +0800 | [diff] [blame] | 160 | extern enum node_type bsc_vty_go_parent(struct vty *vty); |
Harald Welte | 778c4b9 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 161 | |
| 162 | static struct vty_app_info vty_info = { |
Harald Welte | 9af42c3 | 2011-02-24 23:57:06 +0100 | [diff] [blame] | 163 | .name = "OsmoSGSN", |
Harald Welte | 778c4b9 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 164 | .version = PACKAGE_VERSION, |
| 165 | .go_parent_cb = bsc_vty_go_parent, |
Holger Hans Peter Freyther | ba289d0 | 2010-09-04 11:00:01 +0800 | [diff] [blame] | 166 | .is_config_node = bsc_vty_is_config_node, |
Harald Welte | 778c4b9 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 169 | static void print_help(void) |
| 170 | { |
| 171 | printf("Some useful help...\n"); |
| 172 | printf(" -h --help\tthis text\n"); |
| 173 | printf(" -D --daemonize\tFork the process into a background daemon\n"); |
| 174 | printf(" -d option --debug\tenable Debugging\n"); |
| 175 | printf(" -s --disable-color\n"); |
| 176 | printf(" -c --config-file\tThe config file to use\n"); |
| 177 | printf(" -e --log-level number\tSet a global log level\n"); |
| 178 | } |
| 179 | |
| 180 | static void handle_options(int argc, char **argv) |
| 181 | { |
| 182 | while (1) { |
| 183 | int option_index = 0, c; |
| 184 | static struct option long_options[] = { |
| 185 | {"help", 0, 0, 'h'}, |
| 186 | {"debug", 1, 0, 'd'}, |
| 187 | {"daemonize", 0, 0, 'D'}, |
| 188 | {"config-file", 1, 0, 'c'}, |
| 189 | {"disable-color", 0, 0, 's'}, |
| 190 | {"timestamp", 0, 0, 'T'}, |
| 191 | {"log-level", 1, 0, 'e'}, |
| 192 | {NULL, 0, 0, 0} |
| 193 | }; |
| 194 | |
| 195 | c = getopt_long(argc, argv, "hd:Dc:sTe:", |
| 196 | long_options, &option_index); |
| 197 | if (c == -1) |
| 198 | break; |
| 199 | |
| 200 | switch (c) { |
| 201 | case 'h': |
| 202 | //print_usage(); |
| 203 | print_help(); |
| 204 | exit(0); |
| 205 | case 's': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 206 | log_set_use_color(osmo_stderr_target, 0); |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 207 | break; |
| 208 | case 'd': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 209 | log_parse_category_mask(osmo_stderr_target, optarg); |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 210 | break; |
| 211 | case 'D': |
| 212 | daemonize = 1; |
| 213 | break; |
| 214 | case 'c': |
| 215 | sgsn_inst.config_file = strdup(optarg); |
| 216 | break; |
| 217 | case 'T': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 218 | log_set_print_timestamp(osmo_stderr_target, 1); |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 219 | break; |
| 220 | case 'e': |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 221 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 222 | break; |
| 223 | default: |
| 224 | /* ignore */ |
| 225 | break; |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Harald Welte | 40b2575 | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 230 | /* default categories */ |
| 231 | static struct log_info_cat gprs_categories[] = { |
| 232 | [DMM] = { |
| 233 | .name = "DMM", |
| 234 | .description = "Layer3 Mobility Management (MM)", |
| 235 | .color = "\033[1;33m", |
| 236 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 237 | }, |
| 238 | [DSMS] = { |
| 239 | .name = "DSMS", |
| 240 | .description = "Layer3 Short Message Service (SMS)", |
| 241 | .color = "\033[1;37m", |
| 242 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 243 | }, |
| 244 | [DPAG] = { |
| 245 | .name = "DPAG", |
| 246 | .description = "Paging Subsystem", |
| 247 | .color = "\033[1;38m", |
| 248 | .enabled = 1, .loglevel = LOGL_NOTICE, |
| 249 | }, |
| 250 | [DMEAS] = { |
| 251 | .name = "DMEAS", |
| 252 | .description = "Radio Measurement Processing", |
| 253 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 254 | }, |
| 255 | [DREF] = { |
| 256 | .name = "DREF", |
| 257 | .description = "Reference Counting", |
| 258 | .enabled = 0, .loglevel = LOGL_NOTICE, |
| 259 | }, |
| 260 | [DGPRS] = { |
| 261 | .name = "DGPRS", |
| 262 | .description = "GPRS Packet Service", |
| 263 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 264 | }, |
| 265 | [DNS] = { |
| 266 | .name = "DNS", |
| 267 | .description = "GPRS Network Service (NS)", |
| 268 | .enabled = 1, .loglevel = LOGL_INFO, |
| 269 | }, |
| 270 | [DBSSGP] = { |
| 271 | .name = "DBSSGP", |
| 272 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 273 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 274 | }, |
| 275 | [DLLC] = { |
| 276 | .name = "DLLC", |
| 277 | .description = "GPRS Logical Link Control Protocol (LLC)", |
| 278 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 279 | }, |
| 280 | [DSNDCP] = { |
| 281 | .name = "DSNDCP", |
| 282 | .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)", |
| 283 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 284 | }, |
| 285 | }; |
| 286 | |
| 287 | static const struct log_info gprs_log_info = { |
| 288 | .filter_fn = gprs_log_filter_fn, |
| 289 | .cat = gprs_categories, |
| 290 | .num_cat = ARRAY_SIZE(gprs_categories), |
| 291 | }; |
| 292 | |
| 293 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 294 | int main(int argc, char **argv) |
| 295 | { |
| 296 | struct gsm_network dummy_network; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 297 | int rc; |
| 298 | |
| 299 | tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 300 | tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb"); |
| 301 | |
| 302 | signal(SIGINT, &signal_handler); |
| 303 | signal(SIGABRT, &signal_handler); |
| 304 | signal(SIGUSR1, &signal_handler); |
| 305 | signal(SIGUSR2, &signal_handler); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 306 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 307 | osmo_init_ignore_signals(); |
Harald Welte | 40b2575 | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 308 | osmo_init_logging(&gprs_log_info); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 309 | |
Harald Welte | 778c4b9 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 310 | vty_info.copyright = openbsc_copyright; |
| 311 | vty_init(&vty_info); |
Harald Welte | 40b2575 | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 312 | logging_vty_add_cmds(&gprs_log_info); |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 313 | sgsn_vty_init(); |
| 314 | |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 315 | handle_options(argc, argv); |
| 316 | |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 317 | rate_ctr_init(tall_bsc_ctx); |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 318 | rc = telnet_init(tall_bsc_ctx, &dummy_network, 4245); |
| 319 | if (rc < 0) |
| 320 | exit(1); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 321 | |
Harald Welte | deb9017 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 322 | gprs_ns_set_log_ss(DNS); |
Harald Welte | a084f12 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 323 | bssgp_set_log_ss(DBSSGP); |
Harald Welte | deb9017 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 324 | |
Harald Welte | 1d12338 | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 325 | sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 326 | if (!sgsn_nsi) { |
| 327 | LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); |
| 328 | exit(1); |
| 329 | } |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 330 | bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi; |
Harald Welte | 81fb358 | 2010-06-30 19:59:55 +0200 | [diff] [blame] | 331 | |
| 332 | gprs_llc_init("/usr/local/lib/osmocom/crypt/"); |
| 333 | |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 334 | gprs_ns_vty_init(bssgp_nsi); |
Harald Welte | a084f12 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 335 | bssgp_vty_init(); |
Harald Welte | 0c938b7 | 2010-05-18 12:20:12 +0200 | [diff] [blame] | 336 | gprs_llc_vty_init(); |
Harald Welte | 9413503 | 2010-06-30 17:21:19 +0200 | [diff] [blame] | 337 | gprs_sndcp_vty_init(); |
Harald Welte | 7ed98e3 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 338 | /* FIXME: register signal handler for SS_L_NS */ |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 339 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 340 | rc = sgsn_parse_config(sgsn_inst.config_file, &sgsn_inst.cfg); |
Harald Welte | fae1fbc | 2010-05-13 11:50:04 +0200 | [diff] [blame] | 341 | if (rc < 0) { |
| 342 | LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); |
| 343 | exit(2); |
| 344 | } |
| 345 | |
Harald Welte | 8f77f19 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 346 | rc = sgsn_gtp_init(&sgsn_inst); |
Harald Welte | 047a688 | 2010-05-19 15:46:31 +0200 | [diff] [blame] | 347 | if (rc) { |
| 348 | LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n"); |
Harald Welte | e59c56e | 2010-05-18 14:44:31 +0200 | [diff] [blame] | 349 | exit(2); |
Harald Welte | 047a688 | 2010-05-19 15:46:31 +0200 | [diff] [blame] | 350 | } |
Harald Welte | e59c56e | 2010-05-18 14:44:31 +0200 | [diff] [blame] | 351 | |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 352 | rc = gprs_ns_nsip_listen(sgsn_nsi); |
Harald Welte | 047a688 | 2010-05-19 15:46:31 +0200 | [diff] [blame] | 353 | if (rc < 0) { |
| 354 | LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 355 | exit(2); |
Harald Welte | 047a688 | 2010-05-19 15:46:31 +0200 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | rc = gprs_ns_frgre_listen(sgsn_nsi); |
| 359 | if (rc < 0) { |
| 360 | LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " |
| 361 | "socket. Do you have CAP_NET_RAW?\n"); |
| 362 | exit(2); |
| 363 | } |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 364 | |
Harald Welte | 599a957 | 2010-08-27 09:26:44 +0200 | [diff] [blame] | 365 | if (daemonize) { |
| 366 | rc = osmo_daemonize(); |
| 367 | if (rc < 0) { |
| 368 | perror("Error during daemonize"); |
| 369 | exit(1); |
| 370 | } |
| 371 | } |
| 372 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 373 | while (1) { |
Pablo Neira Ayuso | 04d24cd | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 374 | rc = osmo_select_main(0); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 375 | if (rc < 0) |
| 376 | exit(3); |
| 377 | } |
| 378 | |
Harald Welte | 5c71db2 | 2011-07-16 13:47:01 +0200 | [diff] [blame] | 379 | /* not reached */ |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 380 | exit(0); |
| 381 | } |