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