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