Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 1 | /* |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 2 | * (C) 2010-2013 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 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 | 288be16 | 2010-05-01 16:48:27 +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 | 288be16 | 2010-05-01 16:48:27 +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 | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 24 | #include <time.h> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 25 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 26 | #include <osmocom/core/talloc.h> |
| 27 | #include <osmocom/core/utils.h> |
| 28 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 29 | |
| 30 | #include <openbsc/debug.h> |
| 31 | #include <openbsc/sgsn.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 32 | #include <osmocom/gprs/gprs_ns.h> |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 33 | #include <openbsc/gprs_sgsn.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 34 | #include <openbsc/vty.h> |
Harald Welte | c5d4a0c | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 35 | #include <openbsc/gsm_04_08_gprs.h> |
Jacob Erlbeck | 8054799 | 2014-12-19 19:19:46 +0100 | [diff] [blame] | 36 | #include <openbsc/gprs_gsup_client.h> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 37 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 38 | #include <osmocom/vty/command.h> |
| 39 | #include <osmocom/vty/vty.h> |
Pablo Neira Ayuso | 6110a3f | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 40 | #include <osmocom/vty/misc.h> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 41 | |
Jacob Erlbeck | 8054799 | 2014-12-19 19:19:46 +0100 | [diff] [blame] | 42 | #include <osmocom/abis/ipa.h> |
| 43 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 44 | #include <pdp.h> |
| 45 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 46 | static struct sgsn_config *g_cfg = NULL; |
| 47 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 48 | const struct value_string sgsn_auth_pol_strs[] = { |
| 49 | { SGSN_AUTH_POLICY_OPEN, "accept-all" }, |
| 50 | { SGSN_AUTH_POLICY_CLOSED, "closed" }, |
| 51 | { SGSN_AUTH_POLICY_ACL_ONLY, "acl-only" }, |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 52 | { SGSN_AUTH_POLICY_REMOTE, "remote" }, |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 53 | { 0, NULL } |
| 54 | }; |
| 55 | |
| 56 | |
Harald Welte | c5d4a0c | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 57 | #define GSM48_MAX_APN_LEN 102 /* 10.5.6.1 */ |
| 58 | static char *gprs_apn2str(uint8_t *apn, unsigned int len) |
| 59 | { |
| 60 | static char apnbuf[GSM48_MAX_APN_LEN+1]; |
Holger Hans Peter Freyther | 80e0365 | 2013-07-04 18:44:16 +0200 | [diff] [blame] | 61 | unsigned int i = 0; |
Harald Welte | c5d4a0c | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 62 | |
| 63 | if (!apn) |
| 64 | return ""; |
| 65 | |
| 66 | if (len > sizeof(apnbuf)-1) |
| 67 | len = sizeof(apnbuf)-1; |
| 68 | |
| 69 | memcpy(apnbuf, apn, len); |
| 70 | apnbuf[len] = '\0'; |
| 71 | |
| 72 | /* replace the domain name step sizes with dots */ |
| 73 | while (i < len) { |
| 74 | unsigned int step = apnbuf[i]; |
| 75 | apnbuf[i] = '.'; |
| 76 | i += step+1; |
| 77 | } |
| 78 | |
| 79 | return apnbuf+1; |
| 80 | } |
| 81 | |
Holger Hans Peter Freyther | a273030 | 2014-03-23 18:08:26 +0100 | [diff] [blame] | 82 | char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len) |
Harald Welte | c5d4a0c | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 83 | { |
| 84 | static char str[INET6_ADDRSTRLEN + 10]; |
| 85 | |
| 86 | if (!pdpa || len < 2) |
| 87 | return "none"; |
| 88 | |
| 89 | switch (pdpa[0] & 0x0f) { |
| 90 | case PDP_TYPE_ORG_IETF: |
| 91 | switch (pdpa[1]) { |
| 92 | case PDP_TYPE_N_IETF_IPv4: |
| 93 | if (len < 2 + 4) |
| 94 | break; |
| 95 | strcpy(str, "IPv4 "); |
| 96 | inet_ntop(AF_INET, pdpa+2, str+5, sizeof(str)-5); |
| 97 | return str; |
| 98 | case PDP_TYPE_N_IETF_IPv6: |
| 99 | if (len < 2 + 8) |
| 100 | break; |
| 101 | strcpy(str, "IPv6 "); |
| 102 | inet_ntop(AF_INET6, pdpa+2, str+5, sizeof(str)-5); |
| 103 | return str; |
| 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | break; |
| 108 | case PDP_TYPE_ORG_ETSI: |
| 109 | if (pdpa[1] == PDP_TYPE_N_ETSI_PPP) |
| 110 | return "PPP"; |
| 111 | break; |
| 112 | default: |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | return "invalid"; |
| 117 | } |
| 118 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 119 | static struct cmd_node sgsn_node = { |
| 120 | SGSN_NODE, |
Harald Welte | 570ce24 | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 121 | "%s(config-sgsn)# ", |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 122 | 1, |
| 123 | }; |
| 124 | |
| 125 | static int config_write_sgsn(struct vty *vty) |
| 126 | { |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 127 | struct sgsn_ggsn_ctx *gctx; |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 128 | struct imsi_acl_entry *acl; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 129 | |
| 130 | vty_out(vty, "sgsn%s", VTY_NEWLINE); |
| 131 | |
Harald Welte | e300d00 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 132 | vty_out(vty, " gtp local-ip %s%s", |
| 133 | inet_ntoa(g_cfg->gtp_listenaddr.sin_addr), VTY_NEWLINE); |
| 134 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 135 | llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) { |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 136 | vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 137 | inet_ntoa(gctx->remote_addr), VTY_NEWLINE); |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 138 | vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 139 | gctx->gtp_version, VTY_NEWLINE); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 142 | vty_out(vty, " auth-policy %s%s", |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 143 | get_value_string(sgsn_auth_pol_strs, g_cfg->auth_policy), |
| 144 | VTY_NEWLINE); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 145 | if (g_cfg->gsup_server_addr.sin_addr.s_addr) |
| 146 | vty_out(vty, " gsup remote-ip %s%s", |
| 147 | inet_ntoa(g_cfg->gsup_server_addr.sin_addr), VTY_NEWLINE); |
| 148 | if (g_cfg->gsup_server_port) |
| 149 | vty_out(vty, " gsup remote-port %d%s", |
| 150 | g_cfg->gsup_server_port, VTY_NEWLINE); |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 151 | llist_for_each_entry(acl, &g_cfg->imsi_acl, list) |
| 152 | vty_out(vty, " imsi-acl add %s%s", acl->imsi, VTY_NEWLINE); |
| 153 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
Holger Hans Peter Freyther | 1491f2e | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 157 | #define SGSN_STR "Configure the SGSN\n" |
| 158 | #define GGSN_STR "Configure the GGSN information\n" |
Harald Welte | e300d00 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 159 | |
| 160 | DEFUN(cfg_sgsn, cfg_sgsn_cmd, |
| 161 | "sgsn", |
| 162 | SGSN_STR) |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 163 | { |
| 164 | vty->node = SGSN_NODE; |
| 165 | return CMD_SUCCESS; |
| 166 | } |
| 167 | |
Harald Welte | e300d00 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 168 | DEFUN(cfg_sgsn_bind_addr, cfg_sgsn_bind_addr_cmd, |
| 169 | "gtp local-ip A.B.C.D", |
| 170 | "GTP Parameters\n" |
Holger Hans Peter Freyther | 1491f2e | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 171 | "Set the IP address for the local GTP bind\n" |
| 172 | "IPv4 Address\n") |
Harald Welte | e300d00 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 173 | { |
| 174 | inet_aton(argv[0], &g_cfg->gtp_listenaddr.sin_addr); |
| 175 | |
| 176 | return CMD_SUCCESS; |
| 177 | } |
| 178 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 179 | DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd, |
| 180 | "ggsn <0-255> remote-ip A.B.C.D", |
Holger Hans Peter Freyther | 1491f2e | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 181 | GGSN_STR "GGSN Number\n" IP_STR "IPv4 Address\n") |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 182 | { |
| 183 | uint32_t id = atoi(argv[0]); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 184 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 185 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 186 | inet_aton(argv[1], &ggc->remote_addr); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 187 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 188 | return CMD_SUCCESS; |
| 189 | } |
| 190 | |
| 191 | #if 0 |
| 192 | DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd, |
| 193 | "ggsn <0-255> remote-port <0-65535>", |
| 194 | "") |
| 195 | { |
| 196 | uint32_t id = atoi(argv[0]); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 197 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 198 | uint16_t port = atoi(argv[1]); |
| 199 | |
| 200 | } |
| 201 | #endif |
| 202 | |
| 203 | DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd, |
| 204 | "ggsn <0-255> gtp-version (0|1)", |
Holger Hans Peter Freyther | 1491f2e | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 205 | GGSN_STR "GGSN Number\n" "GTP Version\n" |
| 206 | "Version 0\n" "Version 1\n") |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 207 | { |
| 208 | uint32_t id = atoi(argv[0]); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 209 | struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 210 | |
| 211 | if (atoi(argv[1])) |
| 212 | ggc->gtp_version = 1; |
| 213 | else |
| 214 | ggc->gtp_version = 0; |
| 215 | |
| 216 | return CMD_SUCCESS; |
| 217 | } |
| 218 | |
| 219 | #if 0 |
| 220 | DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd, |
| 221 | "apn APNAME ggsn <0-255>", |
| 222 | "") |
| 223 | { |
| 224 | struct apn_ctx ** |
| 225 | } |
| 226 | #endif |
| 227 | |
| 228 | const struct value_string gprs_mm_st_strs[] = { |
| 229 | { GMM_DEREGISTERED, "DEREGISTERED" }, |
| 230 | { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" }, |
| 231 | { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" }, |
Harald Welte | bffeff8 | 2010-06-09 15:50:45 +0200 | [diff] [blame] | 232 | { GMM_REGISTERED_SUSPENDED, "REGISTERED (SUSPENDED)" }, |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 233 | { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" }, |
| 234 | { 0, NULL } |
| 235 | }; |
| 236 | |
| 237 | static void vty_dump_pdp(struct vty *vty, const char *pfx, |
| 238 | struct sgsn_pdp_ctx *pdp) |
| 239 | { |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 240 | const char *imsi = pdp->mm ? pdp->mm->imsi : "(detaching)"; |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 241 | vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s", |
Jacob Erlbeck | 99985b5 | 2014-10-13 10:32:00 +0200 | [diff] [blame] | 242 | pfx, imsi, pdp->sapi, pdp->nsapi, VTY_NEWLINE); |
Harald Welte | c5d4a0c | 2010-07-02 22:47:59 +0200 | [diff] [blame] | 243 | vty_out(vty, "%s APN: %s%s", pfx, |
| 244 | gprs_apn2str(pdp->lib->apn_use.v, pdp->lib->apn_use.l), |
| 245 | VTY_NEWLINE); |
| 246 | vty_out(vty, "%s PDP Address: %s%s", pfx, |
| 247 | gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l), |
| 248 | VTY_NEWLINE); |
Harald Welte | efbdee9 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 249 | vty_out_rate_ctr_group(vty, " ", pdp->ctrg); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static void vty_dump_mmctx(struct vty *vty, const char *pfx, |
| 253 | struct sgsn_mm_ctx *mm, int pdp) |
| 254 | { |
| 255 | vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s", |
| 256 | pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE); |
| 257 | vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn, |
| 258 | mm->tlli, VTY_NEWLINE); |
| 259 | vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, " |
| 260 | "Cell ID: %u%s", pfx, |
| 261 | get_value_string(gprs_mm_st_strs, mm->mm_state), |
| 262 | mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac, |
| 263 | mm->cell_id, VTY_NEWLINE); |
| 264 | |
Harald Welte | 8acd88f | 2010-05-18 10:57:45 +0200 | [diff] [blame] | 265 | vty_out_rate_ctr_group(vty, " ", mm->ctrg); |
| 266 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 267 | if (pdp) { |
| 268 | struct sgsn_pdp_ctx *pdp; |
| 269 | |
| 270 | llist_for_each_entry(pdp, &mm->pdp_list, list) |
| 271 | vty_dump_pdp(vty, " ", pdp); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn", |
| 276 | SHOW_STR "Display information about the SGSN") |
| 277 | { |
Jacob Erlbeck | 8054799 | 2014-12-19 19:19:46 +0100 | [diff] [blame] | 278 | if (sgsn->gsup_client) { |
| 279 | struct ipa_client_conn *link = sgsn->gsup_client->link; |
| 280 | vty_out(vty, |
| 281 | " Remote authorization: %sconnected to %s:%d via GSUP%s", |
| 282 | sgsn->gsup_client->is_connected ? "" : "not ", |
| 283 | link->addr, link->port, |
| 284 | VTY_NEWLINE); |
| 285 | } |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 286 | /* FIXME: statistics */ |
| 287 | return CMD_SUCCESS; |
| 288 | } |
| 289 | |
| 290 | #define MMCTX_STR "MM Context\n" |
| 291 | #define INCLUDE_PDP_STR "Include PDP Context Information\n" |
| 292 | |
| 293 | #if 0 |
| 294 | DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd, |
| 295 | "show mm-context tlli HEX [pdp]", |
| 296 | SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR) |
| 297 | { |
| 298 | uint32_t tlli; |
| 299 | struct sgsn_mm_ctx *mm; |
| 300 | |
| 301 | tlli = strtoul(argv[0], NULL, 16); |
| 302 | mm = sgsn_mm_ctx_by_tlli(tlli); |
| 303 | if (!mm) { |
| 304 | vty_out(vty, "No MM context for TLLI %08x%s", |
| 305 | tlli, VTY_NEWLINE); |
| 306 | return CMD_WARNING; |
| 307 | } |
| 308 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 309 | return CMD_SUCCESS; |
| 310 | } |
| 311 | #endif |
| 312 | |
| 313 | DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd, |
| 314 | "show mm-context imsi IMSI [pdp]", |
| 315 | SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n" |
| 316 | INCLUDE_PDP_STR) |
| 317 | { |
| 318 | struct sgsn_mm_ctx *mm; |
| 319 | |
| 320 | mm = sgsn_mm_ctx_by_imsi(argv[0]); |
| 321 | if (!mm) { |
| 322 | vty_out(vty, "No MM context for IMSI %s%s", |
| 323 | argv[0], VTY_NEWLINE); |
| 324 | return CMD_WARNING; |
| 325 | } |
| 326 | vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0); |
| 327 | return CMD_SUCCESS; |
| 328 | } |
| 329 | |
| 330 | DEFUN(swow_mmctx_all, show_mmctx_all_cmd, |
| 331 | "show mm-context all [pdp]", |
| 332 | SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR) |
| 333 | { |
| 334 | struct sgsn_mm_ctx *mm; |
| 335 | |
| 336 | llist_for_each_entry(mm, &sgsn_mm_ctxts, list) |
| 337 | vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0); |
| 338 | |
| 339 | return CMD_SUCCESS; |
| 340 | } |
| 341 | |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 342 | DEFUN(show_pdpctx_all, show_pdpctx_all_cmd, |
| 343 | "show pdp-context all", |
Holger Hans Peter Freyther | 1491f2e | 2011-11-05 15:21:16 +0100 | [diff] [blame] | 344 | SHOW_STR "Display information on PDP Context\n" "Show everything\n") |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 345 | { |
| 346 | struct sgsn_pdp_ctx *pdp; |
| 347 | |
| 348 | llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list) |
| 349 | vty_dump_pdp(vty, "", pdp); |
| 350 | |
| 351 | return CMD_SUCCESS; |
| 352 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 353 | |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 354 | |
| 355 | DEFUN(imsi_acl, cfg_imsi_acl_cmd, |
| 356 | "imsi-acl (add|del) IMSI", |
| 357 | "Access Control List of foreign IMSIs\n" |
| 358 | "Add IMSI to ACL\n" |
| 359 | "Remove IMSI from ACL\n" |
| 360 | "IMSI of subscriber\n") |
| 361 | { |
| 362 | const char *op = argv[0]; |
| 363 | const char *imsi = argv[1]; |
| 364 | int rc; |
| 365 | |
| 366 | if (!strcmp(op, "add")) |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 367 | rc = sgsn_acl_add(imsi, g_cfg); |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 368 | else |
Jacob Erlbeck | 3b5d407 | 2014-10-24 15:11:03 +0200 | [diff] [blame] | 369 | rc = sgsn_acl_del(imsi, g_cfg); |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 370 | |
| 371 | if (rc < 0) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 372 | vty_out(vty, "%% unable to %s ACL%s", op, VTY_NEWLINE); |
| 373 | |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 374 | return CMD_WARNING; |
| 375 | } |
| 376 | |
| 377 | return CMD_SUCCESS; |
| 378 | } |
| 379 | |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 380 | DEFUN(cfg_auth_policy, cfg_auth_policy_cmd, |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 381 | "auth-policy (accept-all|closed|acl-only|remote)", |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 382 | "Autorization Policy of SGSN\n" |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 383 | "Accept all IMSIs (DANGEROUS)\n" |
| 384 | "Accept only home network subscribers or those in the ACL\n" |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 385 | "Accept only subscribers in the ACL\n" |
| 386 | "Use remote subscription data only (HLR)\n") |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 387 | { |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 388 | int val = get_string_value(sgsn_auth_pol_strs, argv[0]); |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 389 | OSMO_ASSERT(val >= SGSN_AUTH_POLICY_OPEN && val <= SGSN_AUTH_POLICY_REMOTE); |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 390 | g_cfg->auth_policy = val; |
Jacob Erlbeck | 9d4f46c | 2014-12-17 13:20:08 +0100 | [diff] [blame] | 391 | g_cfg->require_authentication = (val == SGSN_AUTH_POLICY_REMOTE); |
Jacob Erlbeck | 771573c | 2014-12-19 18:08:48 +0100 | [diff] [blame] | 392 | g_cfg->require_update_location = (val == SGSN_AUTH_POLICY_REMOTE); |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 393 | |
| 394 | return CMD_SUCCESS; |
| 395 | } |
| 396 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 397 | /* Subscriber */ |
| 398 | #include <openbsc/gsm_subscriber.h> |
| 399 | |
| 400 | static void subscr_dump_full_vty(struct vty *vty, struct gsm_subscriber *subscr, int pending) |
| 401 | { |
| 402 | char expire_time[200]; |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 403 | struct gsm_auth_tuple *at; |
| 404 | int at_idx; |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 405 | |
| 406 | vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id, |
| 407 | subscr->authorized, VTY_NEWLINE); |
| 408 | if (strlen(subscr->name)) |
| 409 | vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); |
| 410 | if (strlen(subscr->extension)) |
| 411 | vty_out(vty, " Extension: %s%s", subscr->extension, |
| 412 | VTY_NEWLINE); |
| 413 | vty_out(vty, " LAC: %d/0x%x%s", |
| 414 | subscr->lac, subscr->lac, VTY_NEWLINE); |
| 415 | vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); |
| 416 | if (subscr->tmsi != GSM_RESERVED_TMSI) |
| 417 | vty_out(vty, " TMSI: %08X%s", subscr->tmsi, |
| 418 | VTY_NEWLINE); |
| 419 | |
| 420 | if (strlen(subscr->equipment.imei) > 0) |
| 421 | vty_out(vty, " IMEI: %s%s", subscr->equipment.imei, VTY_NEWLINE); |
| 422 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 423 | for (at_idx = 0; at_idx < ARRAY_SIZE(subscr->sgsn_data->auth_triplets); |
| 424 | at_idx++) { |
| 425 | at = &subscr->sgsn_data->auth_triplets[at_idx]; |
| 426 | if (at->key_seq == GSM_KEY_SEQ_INVAL) |
| 427 | continue; |
| 428 | |
| 429 | vty_out(vty, " A3A8 tuple (used %d times): ", |
| 430 | at->use_count); |
| 431 | vty_out(vty, " seq # : %d, ", |
| 432 | at->key_seq); |
| 433 | vty_out(vty, " RAND : %s, ", |
| 434 | osmo_hexdump(at->rand, sizeof(at->rand))); |
| 435 | vty_out(vty, " SRES : %s, ", |
| 436 | osmo_hexdump(at->sres, sizeof(at->sres))); |
| 437 | vty_out(vty, " Kc : %s%s", |
| 438 | osmo_hexdump(at->kc, sizeof(at->kc)), |
| 439 | VTY_NEWLINE); |
| 440 | } |
| 441 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 442 | /* print the expiration time of a subscriber */ |
| 443 | if (subscr->expire_lu) { |
| 444 | strftime(expire_time, sizeof(expire_time), |
| 445 | "%a, %d %b %Y %T %z", localtime(&subscr->expire_lu)); |
| 446 | expire_time[sizeof(expire_time) - 1] = '\0'; |
| 447 | vty_out(vty, " Expiration Time: %s%s", expire_time, VTY_NEWLINE); |
| 448 | } |
| 449 | |
| 450 | if (subscr->flags) |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 451 | vty_out(vty, " Flags: %s%s%s%s%s%s", |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 452 | subscr->flags & GSM_SUBSCRIBER_FIRST_CONTACT ? |
| 453 | "FIRST_CONTACT " : "", |
| 454 | subscr->flags & GPRS_SUBSCRIBER_CANCELLED ? |
| 455 | "CANCELLED " : "", |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 456 | subscr->flags & GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING ? |
| 457 | "UPDATE_LOCATION_PENDING " : "", |
| 458 | subscr->flags & GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING ? |
| 459 | "AUTH_INFO_PENDING " : "", |
Jacob Erlbeck | 65fa3f7 | 2015-01-06 16:32:41 +0100 | [diff] [blame] | 460 | subscr->flags & GPRS_SUBSCRIBER_ENABLE_PURGE ? |
| 461 | "ENABLE_PURGE " : "", |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 462 | VTY_NEWLINE); |
| 463 | |
| 464 | vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE); |
| 465 | } |
| 466 | |
| 467 | DEFUN(show_subscr_cache, |
| 468 | show_subscr_cache_cmd, |
| 469 | "show subscriber cache", |
| 470 | SHOW_STR "Show information about subscribers\n" |
| 471 | "Display contents of subscriber cache\n") |
| 472 | { |
| 473 | struct gsm_subscriber *subscr; |
| 474 | |
| 475 | llist_for_each_entry(subscr, &active_subscribers, entry) { |
| 476 | vty_out(vty, " Subscriber:%s", VTY_NEWLINE); |
| 477 | subscr_dump_full_vty(vty, subscr, 0); |
| 478 | } |
| 479 | |
| 480 | return CMD_SUCCESS; |
| 481 | } |
| 482 | |
| 483 | #define UPDATE_SUBSCR_STR "update-subscriber imsi IMSI " |
| 484 | #define UPDATE_SUBSCR_HELP "Update subscriber list\n" \ |
| 485 | "Use the IMSI to select the subscriber\n" \ |
| 486 | "The IMSI\n" |
| 487 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 488 | #define UPDATE_SUBSCR_INSERT_HELP "Insert data into the subscriber record\n" |
| 489 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 490 | DEFUN(update_subscr_insert_auth_triplet, update_subscr_insert_auth_triplet_cmd, |
| 491 | UPDATE_SUBSCR_STR "insert auth-triplet <1-5> sres SRES rand RAND kc KC", |
| 492 | UPDATE_SUBSCR_HELP |
| 493 | UPDATE_SUBSCR_INSERT_HELP |
| 494 | "Update authentication triplet\n" |
| 495 | "Triplet index\n" |
| 496 | "Set SRES value\nSRES value (4 byte) in hex\n" |
| 497 | "Set RAND value\nRAND value (16 byte) in hex\n" |
| 498 | "Set Kc value\nKc value (8 byte) in hex\n") |
| 499 | { |
| 500 | const char *imsi = argv[0]; |
| 501 | const int cksn = atoi(argv[1]) - 1; |
| 502 | const char *sres_str = argv[2]; |
| 503 | const char *rand_str = argv[3]; |
| 504 | const char *kc_str = argv[4]; |
| 505 | struct gsm_auth_tuple at = {0,}; |
| 506 | |
| 507 | struct gsm_subscriber *subscr; |
| 508 | |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 509 | subscr = gprs_subscr_get_by_imsi(imsi); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 510 | if (!subscr) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 511 | vty_out(vty, "%% unable get subscriber record for %s%s", |
| 512 | imsi, VTY_NEWLINE); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 513 | return CMD_WARNING; |
| 514 | } |
| 515 | |
| 516 | OSMO_ASSERT(subscr->sgsn_data); |
| 517 | |
Jacob Erlbeck | 17fb3d4 | 2015-01-05 09:43:51 +0100 | [diff] [blame] | 518 | if (osmo_hexparse(sres_str, &at.sres[0], sizeof(at.sres)) < 0) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 519 | vty_out(vty, "%% invalid SRES value '%s'%s", |
| 520 | sres_str, VTY_NEWLINE); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 521 | goto failed; |
| 522 | } |
Jacob Erlbeck | 17fb3d4 | 2015-01-05 09:43:51 +0100 | [diff] [blame] | 523 | if (osmo_hexparse(rand_str, &at.rand[0], sizeof(at.rand)) < 0) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 524 | vty_out(vty, "%% invalid RAND value '%s'%s", |
| 525 | rand_str, VTY_NEWLINE); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 526 | goto failed; |
| 527 | } |
Jacob Erlbeck | 17fb3d4 | 2015-01-05 09:43:51 +0100 | [diff] [blame] | 528 | if (osmo_hexparse(kc_str, &at.kc[0], sizeof(at.kc)) < 0) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 529 | vty_out(vty, "%% invalid Kc value '%s'%s", |
| 530 | kc_str, VTY_NEWLINE); |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 531 | goto failed; |
| 532 | } |
| 533 | at.key_seq = cksn; |
| 534 | |
| 535 | subscr->sgsn_data->auth_triplets[cksn] = at; |
| 536 | subscr->sgsn_data->auth_triplets_updated = 1; |
| 537 | |
| 538 | subscr_put(subscr); |
| 539 | |
| 540 | return CMD_SUCCESS; |
| 541 | |
| 542 | failed: |
| 543 | subscr_put(subscr); |
| 544 | return CMD_SUCCESS; |
| 545 | } |
| 546 | |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 547 | DEFUN(update_subscr_cancel, update_subscr_cancel_cmd, |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 548 | UPDATE_SUBSCR_STR "cancel (update-procedure|subscription-withdraw)", |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 549 | UPDATE_SUBSCR_HELP |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 550 | "Cancel (remove) subscriber record\n" |
| 551 | "The MS moved to another SGSN\n" |
| 552 | "The subscription is no longer valid\n") |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 553 | { |
| 554 | const char *imsi = argv[0]; |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 555 | const char *cancel_type = argv[1]; |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 556 | |
| 557 | struct gsm_subscriber *subscr; |
| 558 | |
| 559 | subscr = gprs_subscr_get_by_imsi(imsi); |
| 560 | if (!subscr) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 561 | vty_out(vty, "%% no subscriber record for %s%s", |
| 562 | imsi, VTY_NEWLINE); |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 563 | return CMD_WARNING; |
| 564 | } |
| 565 | |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 566 | if (strcmp(cancel_type, "update-procedure") == 0) |
| 567 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
| 568 | else |
| 569 | subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED; |
| 570 | |
Jacob Erlbeck | 37139e5 | 2015-01-23 13:52:55 +0100 | [diff] [blame] | 571 | gprs_subscr_cancel(subscr); |
| 572 | subscr_put(subscr); |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 573 | |
| 574 | return CMD_SUCCESS; |
| 575 | } |
| 576 | |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 577 | DEFUN(update_subscr_create, update_subscr_create_cmd, |
| 578 | UPDATE_SUBSCR_STR "create", |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 579 | UPDATE_SUBSCR_HELP |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 580 | "Create a subscriber entry\n") |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 581 | { |
| 582 | const char *imsi = argv[0]; |
| 583 | |
| 584 | struct gsm_subscriber *subscr; |
| 585 | |
| 586 | subscr = gprs_subscr_get_by_imsi(imsi); |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 587 | if (subscr) { |
| 588 | vty_out(vty, "%% subscriber record already exists for %s%s", |
| 589 | imsi, VTY_NEWLINE); |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 590 | return CMD_WARNING; |
| 591 | } |
| 592 | |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 593 | subscr = gprs_subscr_get_or_create(imsi); |
| 594 | subscr->keep_in_ram = 1; |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 595 | subscr_put(subscr); |
| 596 | |
| 597 | return CMD_SUCCESS; |
| 598 | } |
| 599 | |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 600 | DEFUN(update_subscr_destroy, update_subscr_destroy_cmd, |
| 601 | UPDATE_SUBSCR_STR "destroy", |
| 602 | UPDATE_SUBSCR_HELP |
| 603 | "Destroy a subscriber entry\n") |
| 604 | { |
| 605 | const char *imsi = argv[0]; |
| 606 | |
| 607 | struct gsm_subscriber *subscr; |
| 608 | |
| 609 | subscr = gprs_subscr_get_by_imsi(imsi); |
| 610 | if (!subscr) { |
| 611 | vty_out(vty, "%% subscriber record does not exist for %s%s", |
| 612 | imsi, VTY_NEWLINE); |
| 613 | return CMD_WARNING; |
| 614 | } |
| 615 | |
| 616 | subscr->keep_in_ram = 0; |
Jacob Erlbeck | 8000e0e | 2015-01-27 14:56:40 +0100 | [diff] [blame] | 617 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 618 | gprs_subscr_cancel(subscr); |
| 619 | if (subscr->use_count > 1) |
| 620 | vty_out(vty, "%% subscriber is still in use%s", |
| 621 | VTY_NEWLINE); |
| 622 | subscr_put(subscr); |
| 623 | |
| 624 | return CMD_SUCCESS; |
| 625 | } |
| 626 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 627 | #define UL_ERR_STR "system-failure|data-missing|unexpected-data-value|" \ |
| 628 | "unknown-subscriber|roaming-not-allowed" |
| 629 | |
| 630 | #define UL_ERR_HELP \ |
| 631 | "Force error code SystemFailure\n" \ |
| 632 | "Force error code DataMissing\n" \ |
| 633 | "Force error code UnexpectedDataValue\n" \ |
| 634 | "Force error code UnknownSubscriber\n" \ |
| 635 | "Force error code RoamingNotAllowed\n" |
| 636 | |
| 637 | DEFUN(update_subscr_update_location_result, update_subscr_update_location_result_cmd, |
| 638 | UPDATE_SUBSCR_STR "update-location-result (ok|" UL_ERR_STR ")", |
| 639 | UPDATE_SUBSCR_HELP |
| 640 | "Complete the update location procedure\n" |
| 641 | "The update location request succeeded\n" |
| 642 | UL_ERR_HELP) |
| 643 | { |
| 644 | const char *imsi = argv[0]; |
| 645 | const char *ret_code_str = argv[1]; |
| 646 | |
| 647 | struct gsm_subscriber *subscr; |
| 648 | |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 649 | const struct value_string cause_mapping[] = { |
| 650 | { GMM_CAUSE_NET_FAIL, "system-failure" }, |
| 651 | { GMM_CAUSE_INV_MAND_INFO, "data-missing" }, |
| 652 | { GMM_CAUSE_PROTO_ERR_UNSPEC, "unexpected-data-value" }, |
| 653 | { GMM_CAUSE_IMSI_UNKNOWN, "unknown-subscriber" }, |
| 654 | { GMM_CAUSE_GPRS_NOTALLOWED, "roaming-not-allowed" }, |
| 655 | { 0, NULL } |
| 656 | }; |
| 657 | |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 658 | subscr = gprs_subscr_get_by_imsi(imsi); |
| 659 | if (!subscr) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 660 | vty_out(vty, "%% unable to get subscriber record for %s%s", |
| 661 | imsi, VTY_NEWLINE); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 662 | return CMD_WARNING; |
| 663 | } |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 664 | |
| 665 | if (strcmp(ret_code_str, "ok") == 0) { |
| 666 | subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE; |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 667 | subscr->authorized = 1; |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 668 | } else { |
| 669 | subscr->sgsn_data->error_cause = |
| 670 | get_string_value(cause_mapping, ret_code_str); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 671 | subscr->authorized = 0; |
Jacob Erlbeck | d6267d1 | 2015-01-19 11:10:04 +0100 | [diff] [blame] | 672 | } |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 673 | |
| 674 | gprs_subscr_update(subscr); |
| 675 | |
| 676 | subscr_put(subscr); |
| 677 | |
| 678 | return CMD_SUCCESS; |
| 679 | } |
| 680 | |
| 681 | DEFUN(update_subscr_update_auth_info, update_subscr_update_auth_info_cmd, |
| 682 | UPDATE_SUBSCR_STR "update-auth-info", |
| 683 | UPDATE_SUBSCR_HELP |
| 684 | "Complete the send authentication info procedure\n") |
| 685 | { |
| 686 | const char *imsi = argv[0]; |
| 687 | |
| 688 | struct gsm_subscriber *subscr; |
| 689 | |
| 690 | subscr = gprs_subscr_get_by_imsi(imsi); |
| 691 | if (!subscr) { |
Jacob Erlbeck | 15cc8c8 | 2015-01-19 14:29:43 +0100 | [diff] [blame] | 692 | vty_out(vty, "%% unable to get subscriber record for %s%s", |
| 693 | imsi, VTY_NEWLINE); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 694 | return CMD_WARNING; |
| 695 | } |
| 696 | |
| 697 | gprs_subscr_update_auth_info(subscr); |
| 698 | |
| 699 | subscr_put(subscr); |
| 700 | |
| 701 | return CMD_SUCCESS; |
| 702 | } |
| 703 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 704 | DEFUN(cfg_gsup_remote_ip, cfg_gsup_remote_ip_cmd, |
| 705 | "gsup remote-ip A.B.C.D", |
| 706 | "GSUP Parameters\n" |
| 707 | "Set the IP address of the remote GSUP server\n" |
| 708 | "IPv4 Address\n") |
| 709 | { |
| 710 | inet_aton(argv[0], &g_cfg->gsup_server_addr.sin_addr); |
| 711 | |
| 712 | return CMD_SUCCESS; |
| 713 | } |
| 714 | |
| 715 | DEFUN(cfg_gsup_remote_port, cfg_gsup_remote_port_cmd, |
| 716 | "gsup remote-port <0-65535>", |
| 717 | "GSUP Parameters\n" |
| 718 | "Set the TCP port of the remote GSUP server\n" |
| 719 | "Remote TCP port\n") |
| 720 | { |
| 721 | g_cfg->gsup_server_port = atoi(argv[0]); |
| 722 | |
| 723 | return CMD_SUCCESS; |
| 724 | } |
| 725 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 726 | int sgsn_vty_init(void) |
| 727 | { |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 728 | install_element_ve(&show_sgsn_cmd); |
| 729 | //install_element_ve(&show_mmctx_tlli_cmd); |
| 730 | install_element_ve(&show_mmctx_imsi_cmd); |
| 731 | install_element_ve(&show_mmctx_all_cmd); |
| 732 | install_element_ve(&show_pdpctx_all_cmd); |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 733 | install_element_ve(&show_subscr_cache_cmd); |
| 734 | |
Jacob Erlbeck | 7921ab1 | 2014-12-08 15:52:00 +0100 | [diff] [blame] | 735 | install_element(ENABLE_NODE, &update_subscr_insert_auth_triplet_cmd); |
Jacob Erlbeck | d919343 | 2015-01-19 14:11:46 +0100 | [diff] [blame] | 736 | install_element(ENABLE_NODE, &update_subscr_create_cmd); |
Jacob Erlbeck | e988ae4 | 2015-01-27 12:41:19 +0100 | [diff] [blame] | 737 | install_element(ENABLE_NODE, &update_subscr_destroy_cmd); |
Jacob Erlbeck | 207f4a5 | 2014-11-11 14:01:48 +0100 | [diff] [blame] | 738 | install_element(ENABLE_NODE, &update_subscr_cancel_cmd); |
Jacob Erlbeck | 98a95ac | 2014-11-28 14:55:25 +0100 | [diff] [blame] | 739 | install_element(ENABLE_NODE, &update_subscr_update_location_result_cmd); |
| 740 | install_element(ENABLE_NODE, &update_subscr_update_auth_info_cmd); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 741 | |
| 742 | install_element(CONFIG_NODE, &cfg_sgsn_cmd); |
| 743 | install_node(&sgsn_node, config_write_sgsn); |
Jacob Erlbeck | 36722e1 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 744 | vty_install_default(SGSN_NODE); |
Harald Welte | e300d00 | 2010-06-02 12:41:34 +0200 | [diff] [blame] | 745 | install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd); |
Harald Welte | d193cb3 | 2010-05-17 22:58:03 +0200 | [diff] [blame] | 746 | install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd); |
| 747 | //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd); |
| 748 | install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd); |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 749 | install_element(SGSN_NODE, &cfg_imsi_acl_cmd); |
Harald Welte | 3dfb549 | 2013-03-19 11:48:54 +0100 | [diff] [blame] | 750 | install_element(SGSN_NODE, &cfg_auth_policy_cmd); |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 751 | install_element(SGSN_NODE, &cfg_gsup_remote_ip_cmd); |
| 752 | install_element(SGSN_NODE, &cfg_gsup_remote_port_cmd); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg) |
| 758 | { |
| 759 | int rc; |
| 760 | |
| 761 | g_cfg = cfg; |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 762 | |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 763 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 764 | if (rc < 0) { |
| 765 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 766 | return rc; |
| 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |