Harald Welte | 55fe055 | 2010-05-01 16:48:27 +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 |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/socket.h> |
| 24 | #include <netinet/in.h> |
| 25 | #include <arpa/inet.h> |
| 26 | |
| 27 | #include <osmocore/talloc.h> |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 28 | #include <osmocore/utils.h> |
Harald Welte | 50d44fe | 2010-05-18 17:20:49 +0200 | [diff] [blame] | 29 | #include <osmocore/rate_ctr.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 30 | |
| 31 | #include <openbsc/debug.h> |
| 32 | #include <openbsc/sgsn.h> |
| 33 | #include <openbsc/gprs_ns.h> |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 34 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 35 | #include <openbsc/vty.h> |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 36 | |
| 37 | #include <vty/command.h> |
| 38 | #include <vty/vty.h> |
| 39 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 40 | #include <pdp.h> |
| 41 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 42 | static struct sgsn_config *g_cfg = NULL; |
| 43 | |
| 44 | static struct cmd_node sgsn_node = { |
| 45 | SGSN_NODE, |
| 46 | "%s(sgsn)#", |
| 47 | 1, |
| 48 | }; |
| 49 | |
| 50 | static int config_write_sgsn(struct vty *vty) |
| 51 | { |
| 52 | struct in_addr ia; |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 53 | struct sgsn_ggsn_ctx *gctx; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 54 | |
| 55 | vty_out(vty, "sgsn%s", VTY_NEWLINE); |
| 56 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 57 | llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) { |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 58 | vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id, |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 59 | inet_ntoa(gctx->remote_addr), VTY_NEWLINE); |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 60 | vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id, |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 61 | gctx->gtp_version, VTY_NEWLINE); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | return CMD_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | DEFUN(cfg_sgsn, |
| 68 | cfg_sgsn_cmd, |
| 69 | "sgsn", |
| 70 | "Configure the SGSN") |
| 71 | { |
| 72 | vty->node = SGSN_NODE; |
| 73 | return CMD_SUCCESS; |
| 74 | } |
| 75 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 76 | DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd, |
| 77 | "ggsn <0-255> remote-ip A.B.C.D", |
| 78 | "") |
| 79 | { |
| 80 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 81 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 82 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 83 | inet_aton(argv[1], &ggc->remote_addr); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 84 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 85 | return CMD_SUCCESS; |
| 86 | } |
| 87 | |
| 88 | #if 0 |
| 89 | DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd, |
| 90 | "ggsn <0-255> remote-port <0-65535>", |
| 91 | "") |
| 92 | { |
| 93 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 94 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 95 | uint16_t port = atoi(argv[1]); |
| 96 | |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd, |
| 101 | "ggsn <0-255> gtp-version (0|1)", |
| 102 | "") |
| 103 | { |
| 104 | uint32_t id = atoi(argv[0]); |
Harald Welte | eb471c9 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 105 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 106 | |
| 107 | if (atoi(argv[1])) |
| 108 | ggc->gtp_version = 1; |
| 109 | else |
| 110 | ggc->gtp_version = 0; |
| 111 | |
| 112 | return CMD_SUCCESS; |
| 113 | } |
| 114 | |
| 115 | #if 0 |
| 116 | DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd, |
| 117 | "apn APNAME ggsn <0-255>", |
| 118 | "") |
| 119 | { |
| 120 | struct apn_ctx ** |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | const struct value_string gprs_mm_st_strs[] = { |
| 125 | { GMM_DEREGISTERED, "DEREGISTERED" }, |
| 126 | { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" }, |
| 127 | { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" }, |
| 128 | { GMM_REGISTERED_SUSPENDED, "REGISTeRED (SUSPENDED)" }, |
| 129 | { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" }, |
| 130 | { 0, NULL } |
| 131 | }; |
| 132 | |
| 133 | static void vty_dump_pdp(struct vty *vty, const char *pfx, |
| 134 | struct sgsn_pdp_ctx *pdp) |
| 135 | { |
| 136 | vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s", |
Harald Welte | 29d838e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 137 | pfx, pdp->mm->imsi, pdp->sapi, pdp->nsapi, VTY_NEWLINE); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 138 | vty_out(vty, "%s APN: %s\n", pfx, pdp->lib->apn_use.v); |
| 139 | /* FIXME: statistics */ |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 140 | //vty_out_rate_ctr_group(vty, " ", pdp->ctrg); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static void vty_dump_mmctx(struct vty *vty, const char *pfx, |
| 144 | struct sgsn_mm_ctx *mm, int pdp) |
| 145 | { |
| 146 | vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s", |
| 147 | pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE); |
| 148 | vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn, |
| 149 | mm->tlli, VTY_NEWLINE); |
| 150 | vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, " |
| 151 | "Cell ID: %u%s", pfx, |
| 152 | get_value_string(gprs_mm_st_strs, mm->mm_state), |
| 153 | mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac, |
| 154 | mm->cell_id, VTY_NEWLINE); |
| 155 | |
Harald Welte | 8a035af | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 156 | vty_out_rate_ctr_group(vty, " ", mm->ctrg); |
| 157 | |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 158 | if (pdp) { |
| 159 | struct sgsn_pdp_ctx *pdp; |
| 160 | |
| 161 | llist_for_each_entry(pdp, &mm->pdp_list, list) |
| 162 | vty_dump_pdp(vty, " ", pdp); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn", |
| 167 | SHOW_STR "Display information about the SGSN") |
| 168 | { |
| 169 | /* FIXME: statistics */ |
| 170 | return CMD_SUCCESS; |
| 171 | } |
| 172 | |
| 173 | #define MMCTX_STR "MM Context\n" |
| 174 | #define INCLUDE_PDP_STR "Include PDP Context Information\n" |
| 175 | |
| 176 | #if 0 |
| 177 | DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd, |
| 178 | "show mm-context tlli HEX [pdp]", |
| 179 | SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR) |
| 180 | { |
| 181 | uint32_t tlli; |
| 182 | struct sgsn_mm_ctx *mm; |
| 183 | |
| 184 | tlli = strtoul(argv[0], NULL, 16); |
| 185 | mm = sgsn_mm_ctx_by_tlli(tlli); |
| 186 | if (!mm) { |
| 187 | vty_out(vty, "No MM context for TLLI %08x%s", |
| 188 | tlli, VTY_NEWLINE); |
| 189 | return CMD_WARNING; |
| 190 | } |
| 191 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 192 | return CMD_SUCCESS; |
| 193 | } |
| 194 | #endif |
| 195 | |
| 196 | DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd, |
| 197 | "show mm-context imsi IMSI [pdp]", |
| 198 | SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n" |
| 199 | INCLUDE_PDP_STR) |
| 200 | { |
| 201 | struct sgsn_mm_ctx *mm; |
| 202 | |
| 203 | mm = sgsn_mm_ctx_by_imsi(argv[0]); |
| 204 | if (!mm) { |
| 205 | vty_out(vty, "No MM context for IMSI %s%s", |
| 206 | argv[0], VTY_NEWLINE); |
| 207 | return CMD_WARNING; |
| 208 | } |
| 209 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 210 | return CMD_SUCCESS; |
| 211 | } |
| 212 | |
| 213 | DEFUN(swow_mmctx_all, show_mmctx_all_cmd, |
| 214 | "show mm-context all [pdp]", |
| 215 | SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR) |
| 216 | { |
| 217 | struct sgsn_mm_ctx *mm; |
| 218 | |
| 219 | llist_for_each_entry(mm, &sgsn_mm_ctxts, list) |
| 220 | vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0); |
| 221 | |
| 222 | return CMD_SUCCESS; |
| 223 | } |
| 224 | |
| 225 | DEFUN(show_ggsn, show_ggsn_cmd, |
| 226 | "show ggsn", |
| 227 | "") |
| 228 | { |
| 229 | |
| 230 | } |
| 231 | |
| 232 | DEFUN(show_pdpctx_all, show_pdpctx_all_cmd, |
| 233 | "show pdp-context all", |
| 234 | SHOW_STR "Display information on PDP Context\n") |
| 235 | { |
| 236 | struct sgsn_pdp_ctx *pdp; |
| 237 | |
| 238 | llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list) |
| 239 | vty_dump_pdp(vty, "", pdp); |
| 240 | |
| 241 | return CMD_SUCCESS; |
| 242 | } |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 243 | |
| 244 | int sgsn_vty_init(void) |
| 245 | { |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 246 | install_element_ve(&show_sgsn_cmd); |
| 247 | //install_element_ve(&show_mmctx_tlli_cmd); |
| 248 | install_element_ve(&show_mmctx_imsi_cmd); |
| 249 | install_element_ve(&show_mmctx_all_cmd); |
| 250 | install_element_ve(&show_pdpctx_all_cmd); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 251 | |
| 252 | install_element(CONFIG_NODE, &cfg_sgsn_cmd); |
| 253 | install_node(&sgsn_node, config_write_sgsn); |
| 254 | install_default(SGSN_NODE); |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 255 | install_element(SGSN_NODE, &ournode_exit_cmd); |
Harald Welte | dc82b9b | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 256 | install_element(SGSN_NODE, &ournode_end_cmd); |
Harald Welte | c1f6bfe | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 257 | install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd); |
| 258 | //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd); |
| 259 | install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg) |
| 265 | { |
| 266 | int rc; |
| 267 | |
| 268 | g_cfg = cfg; |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 269 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 270 | if (rc < 0) { |
| 271 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 272 | return rc; |
| 273 | } |
| 274 | |
| 275 | return 0; |
| 276 | } |