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> |
| 4 | * (C) 2010 by On Waves |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <getopt.h> |
| 28 | #include <errno.h> |
| 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/types.h> |
| 32 | #include <sys/socket.h> |
| 33 | #include <netinet/in.h> |
| 34 | #include <arpa/inet.h> |
| 35 | |
| 36 | #include <osmocore/talloc.h> |
| 37 | #include <osmocore/select.h> |
| 38 | |
| 39 | #include <openbsc/signal.h> |
| 40 | #include <openbsc/debug.h> |
| 41 | #include <openbsc/telnet_interface.h> |
| 42 | #include <openbsc/vty.h> |
| 43 | #include <openbsc/sgsn.h> |
| 44 | #include <openbsc/gprs_ns.h> |
| 45 | #include <openbsc/gprs_bssgp.h> |
| 46 | |
| 47 | #include "../bscconfig.h" |
| 48 | |
| 49 | /* this is here for the vty... it will never be called */ |
| 50 | void subscr_put() { abort(); } |
| 51 | |
| 52 | #define _GNU_SOURCE |
| 53 | #include <getopt.h> |
| 54 | |
| 55 | void *tall_bsc_ctx; |
| 56 | |
| 57 | struct gprs_ns_inst *sgsn_nsi; |
| 58 | |
| 59 | const char *openbsc_version = "Osmocom NSIP Proxy " PACKAGE_VERSION; |
| 60 | const char *openbsc_copyright = |
| 61 | "Copyright (C) 2010 Harald Welte and On-Waves\n" |
| 62 | "Contributions by Daniel Willmann, Jan Lübbe, Stefan Schmidt\n" |
| 63 | "Dieter Spaar, Andreas Eversberg, Holger Freyther\n\n" |
| 64 | "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n" |
| 65 | "This is free software: you are free to change and redistribute it.\n" |
| 66 | "There is NO WARRANTY, to the extent permitted by law.\n"; |
| 67 | |
| 68 | static char *config_file = "osmo_sgsn.cfg"; |
| 69 | static struct sgsn_config sgcfg; |
| 70 | |
| 71 | /* call-back function for the NS protocol */ |
| 72 | static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, |
| 73 | struct msgb *msg, u_int16_t bvci) |
| 74 | { |
| 75 | int rc = 0; |
| 76 | |
| 77 | switch (event) { |
| 78 | case GPRS_NS_EVT_UNIT_DATA: |
| 79 | /* hand the message into the BSSGP implementation */ |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 80 | rc = gprs_bssgp_rcvmsg(msg); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 81 | break; |
| 82 | default: |
| 83 | LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event); |
| 84 | if (msg) |
| 85 | talloc_free(msg); |
| 86 | rc = -EIO; |
| 87 | break; |
| 88 | } |
| 89 | return rc; |
| 90 | } |
| 91 | |
Harald Welte | 29a4b8c | 2010-05-02 21:29:17 +0200 | [diff] [blame] | 92 | /* NSI that BSSGP uses when transmitting on NS */ |
| 93 | extern struct gprs_ns_inst *bssgp_nsi; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 94 | |
| 95 | int main(int argc, char **argv) |
| 96 | { |
| 97 | struct gsm_network dummy_network; |
| 98 | struct log_target *stderr_target; |
| 99 | struct sockaddr_in sin; |
| 100 | int rc; |
| 101 | |
| 102 | tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn"); |
| 103 | |
| 104 | log_init(&log_info); |
| 105 | stderr_target = log_target_create_stderr(); |
| 106 | log_add_target(stderr_target); |
| 107 | log_set_all_filter(stderr_target, 1); |
| 108 | |
| 109 | telnet_init(&dummy_network, 4245); |
| 110 | rc = sgsn_parse_config(config_file, &sgcfg); |
| 111 | if (rc < 0) { |
| 112 | LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n"); |
| 113 | exit(2); |
| 114 | } |
| 115 | |
| 116 | sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb); |
| 117 | if (!sgsn_nsi) { |
| 118 | LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); |
| 119 | exit(1); |
| 120 | } |
Harald Welte | 29a4b8c | 2010-05-02 21:29:17 +0200 | [diff] [blame] | 121 | bssgp_nsi = sgcfg.nsi = sgsn_nsi; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 122 | nsip_listen(sgsn_nsi, sgcfg.nsip_listen_port); |
| 123 | |
| 124 | while (1) { |
| 125 | rc = bsc_select_main(0); |
| 126 | if (rc < 0) |
| 127 | exit(3); |
| 128 | } |
| 129 | |
| 130 | exit(0); |
| 131 | } |
| 132 | |
| 133 | struct gsm_network; |
| 134 | int bsc_vty_init(struct gsm_network *dummy) |
| 135 | { |
| 136 | cmd_init(1); |
| 137 | vty_init(); |
| 138 | |
| 139 | openbsc_vty_add_cmds(); |
| 140 | sgsn_vty_init(); |
| 141 | return 0; |
| 142 | } |
| 143 | |