Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 1 | /* OpenBSC interface to quagga VTY */ |
| 2 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 02bd8f4 | 2009-10-27 12:47:06 +0100 | [diff] [blame] | 3 | * (C) 2009 by Holger Hans Peter Freyther |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 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 <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <sys/types.h> |
| 25 | |
| 26 | #include <vty/command.h> |
| 27 | #include <vty/buffer.h> |
| 28 | #include <vty/vty.h> |
| 29 | |
| 30 | #include <arpa/inet.h> |
| 31 | |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 32 | #include <osmocore/linuxlist.h> |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 33 | #include <openbsc/gsm_data.h> |
| 34 | #include <openbsc/gsm_subscriber.h> |
Harald Welte | 0101b81 | 2009-11-17 06:00:23 +0100 | [diff] [blame] | 35 | #include <openbsc/silent_call.h> |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 36 | #include <openbsc/gsm_04_11.h> |
| 37 | #include <openbsc/e1_input.h> |
| 38 | #include <openbsc/abis_nm.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 39 | #include <osmocore/gsm_utils.h> |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 40 | #include <openbsc/db.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 41 | #include <osmocore/talloc.h> |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 42 | #include <openbsc/signal.h> |
Holger Hans Peter Freyther | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 43 | #include <openbsc/debug.h> |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 44 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 45 | |
| 46 | static struct gsm_network *gsmnet; |
| 47 | |
| 48 | struct cmd_node subscr_node = { |
| 49 | SUBSCR_NODE, |
| 50 | "%s(subscriber)#", |
| 51 | 1, |
| 52 | }; |
| 53 | |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame^] | 54 | /* Down vty node level. */ |
| 55 | DEFUN(subscr_node_exit, |
| 56 | subscr_node_exit_cmd, "exit", "Exit current mode and down to previous mode\n") |
| 57 | { |
| 58 | switch (vty->node) { |
| 59 | case SUBSCR_NODE: |
| 60 | vty->node = VIEW_NODE; |
| 61 | subscr_put(vty->index); |
| 62 | vty->index = NULL; |
| 63 | break; |
| 64 | } |
| 65 | return CMD_SUCCESS; |
| 66 | } |
| 67 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 68 | static int dummy_config_write(struct vty *v) |
| 69 | { |
| 70 | return CMD_SUCCESS; |
| 71 | } |
| 72 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 73 | static int hexparse(const char *str, u_int8_t *b, int max_len) |
| 74 | |
| 75 | { |
| 76 | int i, l, v; |
| 77 | |
| 78 | l = strlen(str); |
| 79 | if ((l&1) || ((l>>1) > max_len)) |
| 80 | return -1; |
| 81 | |
| 82 | memset(b, 0x00, max_len); |
| 83 | |
| 84 | for (i=0; i<l; i++) { |
| 85 | char c = str[i]; |
| 86 | if (c >= '0' && c <= '9') |
| 87 | v = c - '0'; |
| 88 | else if (c >= 'a' && c <= 'f') |
| 89 | v = 10 + (c - 'a'); |
| 90 | else if (c >= 'A' && c <= 'F') |
| 91 | v = 10 + (c - 'a'); |
| 92 | else |
| 93 | return -1; |
| 94 | b[i>>1] |= v << (i&1 ? 0 : 4); |
| 95 | } |
| 96 | |
| 97 | return i>>1; |
| 98 | } |
| 99 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 100 | /* per-subscriber configuration */ |
| 101 | DEFUN(cfg_subscr, |
| 102 | cfg_subscr_cmd, |
| 103 | "subscriber IMSI", |
| 104 | "Select a Subscriber to configure\n") |
| 105 | { |
| 106 | const char *imsi = argv[0]; |
| 107 | struct gsm_subscriber *subscr; |
| 108 | |
| 109 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
| 110 | if (!subscr) { |
| 111 | vty_out(vty, "%% No subscriber for IMSI %s%s", |
| 112 | imsi, VTY_NEWLINE); |
| 113 | return CMD_WARNING; |
| 114 | } |
| 115 | |
Holger Hans Peter Freyther | 02bd8f4 | 2009-10-27 12:47:06 +0100 | [diff] [blame] | 116 | /* vty_go_parent should put this subscriber */ |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 117 | vty->index = subscr; |
| 118 | vty->node = SUBSCR_NODE; |
| 119 | |
| 120 | return CMD_SUCCESS; |
| 121 | } |
| 122 | |
Holger Hans Peter Freyther | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 123 | static void subscr_dump_full_vty(struct vty *vty, struct gsm_subscriber *subscr) |
| 124 | { |
| 125 | int rc; |
| 126 | struct gsm_auth_info ainfo; |
| 127 | struct gsm_auth_tuple atuple; |
| 128 | |
| 129 | vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id, |
| 130 | subscr->authorized, VTY_NEWLINE); |
| 131 | if (subscr->name) |
| 132 | vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); |
| 133 | if (subscr->extension) |
| 134 | vty_out(vty, " Extension: %s%s", subscr->extension, |
| 135 | VTY_NEWLINE); |
| 136 | if (subscr->imsi) |
| 137 | vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); |
| 138 | if (subscr->tmsi != GSM_RESERVED_TMSI) |
| 139 | vty_out(vty, " TMSI: %08X%s", subscr->tmsi, |
| 140 | VTY_NEWLINE); |
| 141 | |
| 142 | rc = get_authinfo_by_subscr(&ainfo, subscr); |
| 143 | if (!rc) { |
| 144 | vty_out(vty, " A3A8 algorithm id: %d%s", |
| 145 | ainfo.auth_algo, VTY_NEWLINE); |
| 146 | vty_out(vty, " A3A8 Ki: %s%s", |
| 147 | hexdump(ainfo.a3a8_ki, ainfo.a3a8_ki_len), |
| 148 | VTY_NEWLINE); |
| 149 | } |
| 150 | |
| 151 | rc = get_authtuple_by_subscr(&atuple, subscr); |
| 152 | if (!rc) { |
| 153 | vty_out(vty, " A3A8 last tuple (used %d times):%s", |
| 154 | atuple.use_count, VTY_NEWLINE); |
| 155 | vty_out(vty, " seq # : %d%s", |
| 156 | atuple.key_seq, VTY_NEWLINE); |
| 157 | vty_out(vty, " RAND : %s%s", |
| 158 | hexdump(atuple.rand, sizeof(atuple.rand)), |
| 159 | VTY_NEWLINE); |
| 160 | vty_out(vty, " SRES : %s%s", |
| 161 | hexdump(atuple.sres, sizeof(atuple.sres)), |
| 162 | VTY_NEWLINE); |
| 163 | vty_out(vty, " Kc : %s%s", |
| 164 | hexdump(atuple.kc, sizeof(atuple.kc)), |
| 165 | VTY_NEWLINE); |
| 166 | } |
| 167 | |
| 168 | vty_out(vty, " Use count: %u%s", subscr->use_count, VTY_NEWLINE); |
| 169 | } |
| 170 | |
| 171 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 172 | /* Subscriber */ |
| 173 | DEFUN(show_subscr, |
| 174 | show_subscr_cmd, |
| 175 | "show subscriber [IMSI]", |
| 176 | SHOW_STR "Display information about a subscriber\n") |
| 177 | { |
| 178 | const char *imsi; |
| 179 | struct gsm_subscriber *subscr; |
| 180 | |
| 181 | if (argc >= 1) { |
| 182 | imsi = argv[0]; |
| 183 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
| 184 | if (!subscr) { |
| 185 | vty_out(vty, "%% unknown subscriber%s", |
| 186 | VTY_NEWLINE); |
| 187 | return CMD_WARNING; |
| 188 | } |
Holger Hans Peter Freyther | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 189 | subscr_dump_full_vty(vty, subscr); |
Holger Hans Peter Freyther | 02bd8f4 | 2009-10-27 12:47:06 +0100 | [diff] [blame] | 190 | subscr_put(subscr); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 191 | |
| 192 | return CMD_SUCCESS; |
| 193 | } |
| 194 | |
| 195 | /* FIXME: iterate over all subscribers ? */ |
| 196 | return CMD_WARNING; |
| 197 | |
| 198 | return CMD_SUCCESS; |
| 199 | } |
| 200 | |
| 201 | DEFUN(show_subscr_cache, |
| 202 | show_subscr_cache_cmd, |
| 203 | "show subscriber cache", |
| 204 | SHOW_STR "Display contents of subscriber cache\n") |
| 205 | { |
| 206 | struct gsm_subscriber *subscr; |
| 207 | |
| 208 | llist_for_each_entry(subscr, &active_subscribers, entry) { |
| 209 | vty_out(vty, " Subscriber:%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 210 | subscr_dump_full_vty(vty, subscr); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | return CMD_SUCCESS; |
| 214 | } |
| 215 | |
| 216 | DEFUN(sms_send_pend, |
| 217 | sms_send_pend_cmd, |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 218 | "sms send pending", |
| 219 | "Send all pending SMS") |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 220 | { |
| 221 | struct gsm_sms *sms; |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 222 | int id = 0; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 223 | |
| 224 | while (1) { |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 225 | sms = db_sms_get_unsent_by_subscr(gsmnet, id); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 226 | if (!sms) |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 227 | break; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 228 | |
| 229 | gsm411_send_sms_subscr(sms->receiver, sms); |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 230 | |
| 231 | id = sms->receiver->id + 1; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | return CMD_SUCCESS; |
| 235 | } |
| 236 | |
| 237 | struct gsm_sms *sms_from_text(struct gsm_subscriber *receiver, const char *text) |
| 238 | { |
| 239 | struct gsm_sms *sms = sms_alloc(); |
| 240 | |
| 241 | if (!sms) |
| 242 | return NULL; |
| 243 | |
| 244 | if (!receiver->lac) { |
| 245 | /* subscriber currently not attached, store in database? */ |
| 246 | return NULL; |
| 247 | } |
| 248 | |
| 249 | sms->receiver = subscr_get(receiver); |
| 250 | strncpy(sms->text, text, sizeof(sms->text)-1); |
| 251 | |
| 252 | /* FIXME: don't use ID 1 static */ |
| 253 | sms->sender = subscr_get_by_id(gsmnet, 1); |
| 254 | sms->reply_path_req = 0; |
| 255 | sms->status_rep_req = 0; |
| 256 | sms->ud_hdr_ind = 0; |
| 257 | sms->protocol_id = 0; /* implicit */ |
| 258 | sms->data_coding_scheme = 0; /* default 7bit */ |
| 259 | strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1); |
| 260 | /* Generate user_data */ |
| 261 | sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text); |
| 262 | |
| 263 | return sms; |
| 264 | } |
| 265 | |
| 266 | static int _send_sms_buffer(struct gsm_subscriber *receiver, |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 267 | struct buffer *b, u_int8_t tp_pid) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 268 | { |
| 269 | struct gsm_sms *sms; |
| 270 | |
| 271 | sms = sms_from_text(receiver, buffer_getstr(b)); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 272 | sms->protocol_id = tp_pid; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 273 | gsm411_send_sms_subscr(receiver, sms); |
| 274 | |
| 275 | return CMD_SUCCESS; |
| 276 | } |
| 277 | |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 278 | static struct gsm_subscriber *get_subscr_by_argv(const char *type, |
| 279 | const char *id) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 280 | { |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 281 | if (!strcmp(type, "extension")) |
| 282 | return subscr_get_by_extension(gsmnet, id); |
| 283 | else if (!strcmp(type, "imsi")) |
| 284 | return subscr_get_by_imsi(gsmnet, id); |
| 285 | else if (!strcmp(type, "tmsi")) |
| 286 | return subscr_get_by_tmsi(gsmnet, atoi(id)); |
| 287 | else if (!strcmp(type, "id")) |
| 288 | return subscr_get_by_id(gsmnet, atoi(id)); |
| 289 | |
| 290 | return NULL; |
| 291 | } |
| 292 | #define SUBSCR_TYPES "(extension|imsi|tmsi|id)" |
| 293 | |
| 294 | DEFUN(subscriber_send_sms, |
| 295 | subscriber_send_sms_cmd, |
| 296 | "subscriber " SUBSCR_TYPES " EXTEN sms send .LINE", |
| 297 | "Select subscriber based on extension") |
| 298 | { |
| 299 | struct gsm_subscriber *subscr = get_subscr_by_argv(argv[0], argv[1]); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 300 | struct buffer *b; |
| 301 | int rc; |
| 302 | |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 303 | if (!subscr) { |
| 304 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 305 | argv[0], argv[1], VTY_NEWLINE); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 306 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 307 | } |
Harald Welte | 8791dac | 2010-05-14 17:59:53 +0200 | [diff] [blame] | 308 | b = vty_argv_to_buffer(argc, argv, 2); |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 309 | rc = _send_sms_buffer(subscr, b, 0); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 310 | buffer_free(b); |
| 311 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 312 | subscr_put(subscr); |
| 313 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 314 | return rc; |
| 315 | } |
| 316 | |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 317 | DEFUN(subscriber_silent_sms, |
| 318 | subscriber_silent_sms_cmd, |
| 319 | "subscriber " SUBSCR_TYPES " EXTEN silent sms send .LINE", |
| 320 | "Select subscriber based on extension") |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 321 | { |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 322 | struct gsm_subscriber *subscr = get_subscr_by_argv(argv[0], argv[1]); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 323 | struct buffer *b; |
| 324 | int rc; |
| 325 | |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 326 | if (!subscr) { |
| 327 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 328 | argv[0], argv[1], VTY_NEWLINE); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 329 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 330 | } |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 331 | |
Harald Welte | 8791dac | 2010-05-14 17:59:53 +0200 | [diff] [blame] | 332 | b = vty_argv_to_buffer(argc, argv, 2); |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 333 | rc = _send_sms_buffer(subscr, b, 64); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 334 | buffer_free(b); |
| 335 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 336 | subscr_put(subscr); |
| 337 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 338 | return rc; |
| 339 | } |
| 340 | |
Sylvain Munaut | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 341 | DEFUN(subscriber_silent_call_start, |
| 342 | subscriber_silent_call_start_cmd, |
| 343 | "subscriber " SUBSCR_TYPES " EXTEN silent call start (any|tch/f|tch/any|sdcch)", |
| 344 | "Start a silent call to a subscriber") |
| 345 | { |
| 346 | struct gsm_subscriber *subscr = get_subscr_by_argv(argv[0], argv[1]); |
| 347 | int rc, type; |
| 348 | |
| 349 | if (!subscr) { |
| 350 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 351 | argv[0], argv[1], VTY_NEWLINE); |
| 352 | return CMD_WARNING; |
| 353 | } |
| 354 | |
| 355 | if (!strcmp(argv[2], "tch/f")) |
| 356 | type = RSL_CHANNEED_TCH_F; |
| 357 | else if (!strcmp(argv[2], "tch/any")) |
| 358 | type = RSL_CHANNEED_TCH_ForH; |
| 359 | else if (!strcmp(argv[2], "sdcch")) |
| 360 | type = RSL_CHANNEED_SDCCH; |
| 361 | else |
| 362 | type = RSL_CHANNEED_ANY; /* Defaults to ANY */ |
| 363 | |
| 364 | rc = gsm_silent_call_start(subscr, vty, type); |
| 365 | if (rc <= 0) { |
| 366 | vty_out(vty, "%% Subscriber not attached%s", |
| 367 | VTY_NEWLINE); |
| 368 | subscr_put(subscr); |
| 369 | return CMD_WARNING; |
| 370 | } |
| 371 | |
| 372 | subscr_put(subscr); |
| 373 | |
| 374 | return CMD_SUCCESS; |
| 375 | } |
| 376 | |
| 377 | DEFUN(subscriber_silent_call_stop, |
| 378 | subscriber_silent_call_stop_cmd, |
| 379 | "subscriber " SUBSCR_TYPES " EXTEN silent call stop", |
| 380 | "Stop a silent call to a subscriber") |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 381 | { |
| 382 | struct gsm_subscriber *subscr = get_subscr_by_argv(argv[0], argv[1]); |
| 383 | int rc; |
| 384 | |
| 385 | if (!subscr) { |
| 386 | vty_out(vty, "%% No subscriber found for %s %s%s", |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 387 | argv[0], argv[1], VTY_NEWLINE); |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 388 | return CMD_WARNING; |
| 389 | } |
| 390 | |
Sylvain Munaut | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 391 | rc = gsm_silent_call_stop(subscr); |
| 392 | if (rc < 0) { |
| 393 | subscr_put(subscr); |
| 394 | return CMD_WARNING; |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | subscr_put(subscr); |
| 398 | |
| 399 | return CMD_SUCCESS; |
| 400 | } |
| 401 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 402 | DEFUN(cfg_subscr_name, |
| 403 | cfg_subscr_name_cmd, |
| 404 | "name NAME", |
| 405 | "Set the name of the subscriber") |
| 406 | { |
| 407 | const char *name = argv[0]; |
| 408 | struct gsm_subscriber *subscr = vty->index; |
| 409 | |
| 410 | strncpy(subscr->name, name, sizeof(subscr->name)); |
| 411 | |
| 412 | db_sync_subscriber(subscr); |
| 413 | |
| 414 | return CMD_SUCCESS; |
| 415 | } |
| 416 | |
| 417 | DEFUN(cfg_subscr_extension, |
| 418 | cfg_subscr_extension_cmd, |
| 419 | "extension EXTENSION", |
| 420 | "Set the extension of the subscriber") |
| 421 | { |
| 422 | const char *name = argv[0]; |
| 423 | struct gsm_subscriber *subscr = vty->index; |
| 424 | |
| 425 | strncpy(subscr->extension, name, sizeof(subscr->extension)); |
| 426 | |
| 427 | db_sync_subscriber(subscr); |
| 428 | |
| 429 | return CMD_SUCCESS; |
| 430 | } |
| 431 | |
| 432 | DEFUN(cfg_subscr_authorized, |
| 433 | cfg_subscr_authorized_cmd, |
| 434 | "auth <0-1>", |
| 435 | "Set the authorization status of the subscriber") |
| 436 | { |
| 437 | int auth = atoi(argv[0]); |
| 438 | struct gsm_subscriber *subscr = vty->index; |
| 439 | |
| 440 | if (auth) |
| 441 | subscr->authorized = 1; |
| 442 | else |
| 443 | subscr->authorized = 0; |
| 444 | |
| 445 | db_sync_subscriber(subscr); |
| 446 | |
| 447 | return CMD_SUCCESS; |
| 448 | } |
| 449 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 450 | #define A3A8_ALG_TYPES "(none|comp128v1)" |
| 451 | |
| 452 | DEFUN(cfg_subscr_a3a8, |
| 453 | cfg_subscr_a3a8_cmd, |
| 454 | "a3a8 " A3A8_ALG_TYPES " [KI]", |
| 455 | "Set a3a8 parameters for the subscriber") |
| 456 | { |
| 457 | struct gsm_subscriber *subscr = vty->index; |
| 458 | const char *alg_str = argv[0]; |
| 459 | const char *ki_str = argv[1]; |
| 460 | struct gsm_auth_info ainfo; |
| 461 | int rc; |
| 462 | |
| 463 | if (!strcasecmp(alg_str, "none")) { |
| 464 | /* Just erase */ |
| 465 | rc = set_authinfo_for_subscr(NULL, subscr); |
| 466 | } else if (!strcasecmp(alg_str, "comp128v1")) { |
| 467 | /* Parse hex string Ki */ |
| 468 | rc = hexparse(ki_str, ainfo.a3a8_ki, sizeof(ainfo.a3a8_ki)); |
| 469 | if (rc != 16) |
| 470 | return CMD_WARNING; |
| 471 | |
| 472 | /* Set the infos */ |
| 473 | ainfo.auth_algo = AUTH_ALGO_COMP128v1; |
| 474 | ainfo.a3a8_ki_len = rc; |
| 475 | rc = set_authinfo_for_subscr(&ainfo, subscr); |
| 476 | } else { |
| 477 | /* Unknown method */ |
| 478 | return CMD_WARNING; |
| 479 | } |
| 480 | |
| 481 | return rc ? CMD_WARNING : CMD_SUCCESS; |
| 482 | } |
| 483 | |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 484 | static int scall_cbfn(unsigned int subsys, unsigned int signal, |
| 485 | void *handler_data, void *signal_data) |
| 486 | { |
| 487 | struct scall_signal_data *sigdata = signal_data; |
| 488 | struct vty *vty = sigdata->data; |
| 489 | |
| 490 | switch (signal) { |
| 491 | case S_SCALL_SUCCESS: |
| 492 | vty_out(vty, "%% silent call on ARFCN %u timeslot %u%s", |
| 493 | sigdata->lchan->ts->trx->arfcn, sigdata->lchan->ts->nr, |
| 494 | VTY_NEWLINE); |
| 495 | break; |
| 496 | case S_SCALL_EXPIRED: |
| 497 | vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE); |
| 498 | break; |
| 499 | } |
| 500 | return 0; |
| 501 | } |
| 502 | |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 503 | DEFUN(show_stats, |
| 504 | show_stats_cmd, |
| 505 | "show statistics", |
| 506 | SHOW_STR "Display network statistics\n") |
| 507 | { |
| 508 | struct gsm_network *net = gsmnet; |
| 509 | |
| 510 | openbsc_vty_print_statistics(vty, net); |
| 511 | vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s", |
| 512 | counter_get(net->stats.loc_upd_type.attach), |
| 513 | counter_get(net->stats.loc_upd_type.normal), |
| 514 | counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE); |
| 515 | vty_out(vty, "IMSI Detach Indications : %lu%s", |
| 516 | counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE); |
| 517 | vty_out(vty, "Location Update Response: %lu accept, %lu reject%s", |
| 518 | counter_get(net->stats.loc_upd_resp.accept), |
| 519 | counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE); |
| 520 | vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, " |
| 521 | "%lu completed, %lu failed%s", |
| 522 | counter_get(net->stats.handover.attempted), |
| 523 | counter_get(net->stats.handover.no_channel), |
| 524 | counter_get(net->stats.handover.timeout), |
| 525 | counter_get(net->stats.handover.completed), |
| 526 | counter_get(net->stats.handover.failed), VTY_NEWLINE); |
| 527 | vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s", |
| 528 | counter_get(net->stats.sms.submitted), |
| 529 | counter_get(net->stats.sms.no_receiver), VTY_NEWLINE); |
| 530 | vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s", |
| 531 | counter_get(net->stats.sms.delivered), |
| 532 | counter_get(net->stats.sms.rp_err_mem), |
| 533 | counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE); |
| 534 | return CMD_SUCCESS; |
| 535 | } |
| 536 | |
| 537 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 538 | int bsc_vty_init_extra(struct gsm_network *net) |
| 539 | { |
| 540 | gsmnet = net; |
| 541 | |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 542 | register_signal_handler(SS_SCALL, scall_cbfn, NULL); |
| 543 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 544 | install_element_ve(&show_subscr_cmd); |
| 545 | install_element_ve(&show_subscr_cache_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 546 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 547 | install_element_ve(&sms_send_pend_cmd); |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 548 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 549 | install_element_ve(&subscriber_send_sms_cmd); |
| 550 | install_element_ve(&subscriber_silent_sms_cmd); |
| 551 | install_element_ve(&subscriber_silent_call_start_cmd); |
| 552 | install_element_ve(&subscriber_silent_call_stop_cmd); |
| 553 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 554 | |
| 555 | install_element(CONFIG_NODE, &cfg_subscr_cmd); |
| 556 | install_node(&subscr_node, dummy_config_write); |
| 557 | |
| 558 | install_default(SUBSCR_NODE); |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame^] | 559 | install_element(SUBSCR_NODE, &subscr_node_exit_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 560 | install_element(SUBSCR_NODE, &cfg_subscr_name_cmd); |
| 561 | install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd); |
| 562 | install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd); |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 563 | install_element(SUBSCR_NODE, &cfg_subscr_a3a8_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | } |