Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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/>. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
| 24 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 25 | #include <osmocom/core/talloc.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 26 | |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 27 | #include <osmocom/gprs/gprs_ns.h> |
| 28 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 29 | #include <openbsc/debug.h> |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 30 | #include <openbsc/gb_proxy.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 31 | #include <openbsc/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 32 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/command.h> |
| 34 | #include <osmocom/vty/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 35 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 36 | static struct gbproxy_config *g_cfg = NULL; |
| 37 | |
| 38 | /* |
| 39 | * vty code for mgcp below |
| 40 | */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 41 | static struct cmd_node gbproxy_node = { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 42 | GBPROXY_NODE, |
Harald Welte | 570ce24 | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 43 | "%s(config-gbproxy)# ", |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 44 | 1, |
| 45 | }; |
| 46 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame^] | 47 | static const struct value_string patch_modes[] = { |
| 48 | {GBPROX_PATCH_DEFAULT, "default"}, |
| 49 | {GBPROX_PATCH_BSSGP, "bssgp"}, |
| 50 | {GBPROX_PATCH_LLC_ATTACH_REQ, "llc-attach-req"}, |
| 51 | {GBPROX_PATCH_LLC_ATTACH, "llc-attach"}, |
| 52 | {GBPROX_PATCH_LLC_GMM, "llc-gmm"}, |
| 53 | {GBPROX_PATCH_LLC, "llc"}, |
| 54 | {0, NULL} |
| 55 | }; |
| 56 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 57 | static int config_write_gbproxy(struct vty *vty) |
| 58 | { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 59 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 60 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 61 | vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 62 | VTY_NEWLINE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 63 | |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 64 | if (g_cfg->core_mcc > 0) |
| 65 | vty_out(vty, " core-mobile-country-code %d%s", |
| 66 | g_cfg->core_mcc, VTY_NEWLINE); |
| 67 | if (g_cfg->core_mnc > 0) |
| 68 | vty_out(vty, " core-mobile-network-code %d%s", |
| 69 | g_cfg->core_mnc, VTY_NEWLINE); |
| 70 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame^] | 71 | if (g_cfg->patch_mode != GBPROX_PATCH_DEFAULT) |
| 72 | vty_out(vty, " patch-mode %s%s", |
| 73 | get_value_string(patch_modes, g_cfg->patch_mode), |
| 74 | VTY_NEWLINE); |
| 75 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 76 | return CMD_SUCCESS; |
| 77 | } |
| 78 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 79 | DEFUN(cfg_gbproxy, |
| 80 | cfg_gbproxy_cmd, |
| 81 | "gbproxy", |
| 82 | "Configure the Gb proxy") |
| 83 | { |
| 84 | vty->node = GBPROXY_NODE; |
| 85 | return CMD_SUCCESS; |
| 86 | } |
| 87 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 88 | DEFUN(cfg_nsip_sgsn_nsei, |
| 89 | cfg_nsip_sgsn_nsei_cmd, |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 90 | "sgsn nsei <0-65534>", |
Holger Hans Peter Freyther | 2eb6e2c | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 91 | "SGSN information\n" |
| 92 | "NSEI to be used in the connection with the SGSN\n" |
| 93 | "The NSEI\n") |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 94 | { |
| 95 | unsigned int port = atoi(argv[0]); |
| 96 | |
| 97 | g_cfg->nsip_sgsn_nsei = port; |
| 98 | return CMD_SUCCESS; |
| 99 | } |
| 100 | |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 101 | #define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n" |
| 102 | |
| 103 | DEFUN(cfg_gbproxy_core_mnc, |
| 104 | cfg_gbproxy_core_mnc_cmd, |
| 105 | "core-mobile-network-code <1-999>", |
| 106 | GBPROXY_CORE_MNC_STR "NCC value\n") |
| 107 | { |
| 108 | g_cfg->core_mnc = atoi(argv[0]); |
| 109 | return CMD_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | DEFUN(cfg_gbproxy_no_core_mnc, |
| 113 | cfg_gbproxy_no_core_mnc_cmd, |
| 114 | "no core-mobile-network-code", |
| 115 | NO_STR GBPROXY_CORE_MNC_STR) |
| 116 | { |
| 117 | g_cfg->core_mnc = 0; |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | #define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n" |
| 122 | |
| 123 | DEFUN(cfg_gbproxy_core_mcc, |
| 124 | cfg_gbproxy_core_mcc_cmd, |
| 125 | "core-mobile-country-code <1-999>", |
| 126 | GBPROXY_CORE_MCC_STR "MCC value\n") |
| 127 | { |
| 128 | g_cfg->core_mcc = atoi(argv[0]); |
| 129 | return CMD_SUCCESS; |
| 130 | } |
| 131 | |
| 132 | DEFUN(cfg_gbproxy_no_core_mcc, |
| 133 | cfg_gbproxy_no_core_mcc_cmd, |
| 134 | "no core-mobile-country-code", |
| 135 | NO_STR GBPROXY_CORE_MCC_STR) |
| 136 | { |
| 137 | g_cfg->core_mcc = 0; |
| 138 | return CMD_SUCCESS; |
| 139 | } |
| 140 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame^] | 141 | DEFUN(cfg_gbproxy_patch_mode, |
| 142 | cfg_gbproxy_patch_mode_cmd, |
| 143 | "patch-mode (default|bssgp|llc-attach-req|llc-attach|llc)", |
| 144 | "Set patch mode\n" |
| 145 | "Use build-in default (at least llc-attach-req)\n" |
| 146 | "Only patch BSSGP headers\n" |
| 147 | "Patch BSSGP headers and LLC Attach Request messages\n" |
| 148 | "Patch BSSGP headers and LLC Attach Request/Accept messages\n" |
| 149 | "Patch BSSGP headers and all supported GMM LLC messages\n" |
| 150 | ) |
| 151 | { |
| 152 | int val = get_string_value(patch_modes, argv[0]); |
| 153 | OSMO_ASSERT(val >= 0); |
| 154 | g_cfg->patch_mode = val; |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
| 158 | |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 159 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 160 | int gbproxy_vty_init(void) |
| 161 | { |
Harald Welte | 995a2d3 | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 162 | install_element_ve(&show_gbproxy_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 163 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 164 | install_element(ENABLE_NODE, &delete_gb_bvci_cmd); |
| 165 | install_element(ENABLE_NODE, &delete_gb_nsei_cmd); |
Holger Hans Peter Freyther | 90267a9 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 166 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 167 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 168 | install_node(&gbproxy_node, config_write_gbproxy); |
Jacob Erlbeck | 36722e1 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 169 | vty_install_default(GBPROXY_NODE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 170 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 171 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd); |
| 172 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd); |
| 173 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd); |
| 174 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd); |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame^] | 175 | install_element(GBPROXY_NODE, &cfg_gbproxy_patch_mode_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 181 | { |
| 182 | int rc; |
| 183 | |
| 184 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 185 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 186 | if (rc < 0) { |
| 187 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 188 | return rc; |
| 189 | } |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |