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