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 | |
Sylvain Munaut | dcf8c4c | 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 | 1dd0a1b | 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 | |
Sylvain Munaut | 48858d2 | 2010-06-09 11:32:51 +0200 | [diff] [blame] | 94 | rc = db_get_authinfo_for_subscr(&ainfo, subscr); |
Holger Hans Peter Freyther | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 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 | 48858d2 | 2010-06-09 11:32:51 +0200 | [diff] [blame] | 103 | rc = db_get_lastauthtuple_for_subscr(&atuple, subscr); |
Holger Hans Peter Freyther | 1dd0a1b | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 124 | /* Subscriber */ |
Holger Hans Peter Freyther | bdae6f9 | 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 | 1dd0a1b | 2010-01-06 06:00:40 +0100 | [diff] [blame] | 134 | subscr_dump_full_vty(vty, subscr); |
Holger Hans Peter Freyther | bdae6f9 | 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 | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 142 | "sms send pending", |
| 143 | "Send all pending SMS") |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 144 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 145 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 146 | struct gsm_sms *sms; |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 147 | int id = 0; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 148 | |
| 149 | while (1) { |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 150 | sms = db_sms_get_unsent_by_subscr(gsmnet, id); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 151 | if (!sms) |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 152 | break; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 153 | |
| 154 | gsm411_send_sms_subscr(sms->receiver, sms); |
Sylvain Munaut | c2e0a44 | 2009-12-22 13:22:29 +0100 | [diff] [blame] | 155 | |
| 156 | id = sms->receiver->id + 1; |
Holger Hans Peter Freyther | bdae6f9 | 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 | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 178 | sms->sender = subscr_get_by_id(receiver->net, 1); |
Holger Hans Peter Freyther | bdae6f9 | 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 | 3699e20 | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 193 | { |
| 194 | struct gsm_sms *sms; |
| 195 | |
Harald Welte | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 196 | sms = sms_from_text(receiver, str); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 197 | sms->protocol_id = tp_pid; |
Holger Hans Peter Freyther | bdae6f9 | 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 | 4015287 | 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 | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 205 | const char *id) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 206 | { |
Harald Welte | 194ef7b | 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 | 18ce31c | 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 | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 225 | |
Harald Welte | a8ca70f | 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 | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 248 | DEFUN(subscriber_send_sms, |
| 249 | subscriber_send_sms_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 250 | "subscriber " SUBSCR_TYPES " ID sms send .LINE", |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 251 | SUBSCR_HELP "SMS Operations\n" "Send SMS\n" "Actual SMS Text") |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 252 | { |
Harald Welte | 4015287 | 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 | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 255 | char *str; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 256 | int rc; |
| 257 | |
Harald Welte | 81cf198 | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 261 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 262 | } |
Harald Welte | 3699e20 | 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 | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 266 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 267 | subscr_put(subscr); |
| 268 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 269 | return rc; |
| 270 | } |
| 271 | |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 272 | DEFUN(subscriber_silent_sms, |
| 273 | subscriber_silent_sms_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 274 | "subscriber " SUBSCR_TYPES " ID silent-sms send .LINE", |
Harald Welte | 18ce31c | 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 | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 277 | { |
Harald Welte | 4015287 | 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 | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 280 | char *str; |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 281 | int rc; |
| 282 | |
Harald Welte | 81cf198 | 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 | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 286 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 287 | } |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 288 | |
Harald Welte | 3699e20 | 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 | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 292 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 293 | subscr_put(subscr); |
| 294 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 295 | return rc; |
| 296 | } |
| 297 | |
Harald Welte | 18ce31c | 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 | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 305 | DEFUN(subscriber_silent_call_start, |
| 306 | subscriber_silent_call_start_cmd, |
Harald Welte | a8ca70f | 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 | 18ce31c | 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 | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 310 | { |
Harald Welte | 4015287 | 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 | 1c378a7 | 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 | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 345 | "subscriber " SUBSCR_TYPES " ID silent-call stop", |
Harald Welte | 18ce31c | 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 | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 348 | { |
Harald Welte | 4015287 | 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 | b8678a7 | 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 | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 355 | argv[0], argv[1], VTY_NEWLINE); |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 356 | return CMD_WARNING; |
| 357 | } |
| 358 | |
Sylvain Munaut | 1c378a7 | 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 | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | subscr_put(subscr); |
| 366 | |
| 367 | return CMD_SUCCESS; |
| 368 | } |
| 369 | |
Harald Welte | a8ca70f | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 376 | { |
Harald Welte | a8ca70f | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 411 | |
| 412 | strncpy(subscr->name, name, sizeof(subscr->name)); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 413 | db_sync_subscriber(subscr); |
| 414 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 415 | subscr_put(subscr); |
| 416 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 417 | return CMD_SUCCESS; |
| 418 | } |
| 419 | |
Harald Welte | a8ca70f | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 425 | { |
Harald Welte | a8ca70f | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 430 | |
Harald Welte | a8ca70f | 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 | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 436 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 437 | strncpy(subscr->extension, name, sizeof(subscr->name)); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 438 | db_sync_subscriber(subscr); |
| 439 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 440 | subscr_put(subscr); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 441 | |
| 442 | return CMD_SUCCESS; |
| 443 | } |
| 444 | |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 445 | #define A3A8_ALG_TYPES "(none|xor|comp128v1)" |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 446 | #define A3A8_ALG_HELP \ |
| 447 | "Use No A3A8 algorithm\n" \ |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 448 | "Use XOR algorithm\n" \ |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 449 | "Use COMP128v1 algorithm\n" |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 450 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 451 | DEFUN(ena_subscr_a3a8, |
| 452 | ena_subscr_a3a8_cmd, |
| 453 | "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " [KI]", |
Harald Welte | c4bf319 | 2010-05-27 10:48:11 +0200 | [diff] [blame] | 454 | SUBSCR_HELP "Set a3a8 parameters for the subscriber\n" |
| 455 | A3A8_ALG_HELP "Encryption Key Ki\n") |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 456 | { |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 457 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 458 | struct gsm_subscriber *subscr = |
| 459 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
| 460 | const char *alg_str = argv[2]; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 461 | const char *ki_str = argc == 4 ? argv[3] : NULL; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 462 | struct gsm_auth_info ainfo; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 463 | int rc, minlen, maxlen; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 464 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 465 | if (!subscr) { |
| 466 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 467 | argv[0], argv[1], VTY_NEWLINE); |
| 468 | return CMD_WARNING; |
| 469 | } |
| 470 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 471 | if (!strcasecmp(alg_str, "none")) { |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 472 | ainfo.auth_algo = AUTH_ALGO_NONE; |
| 473 | minlen = maxlen = 0; |
| 474 | } else if (!strcasecmp(alg_str, "xor")) { |
| 475 | ainfo.auth_algo = AUTH_ALGO_XOR; |
| 476 | minlen = A38_XOR_MIN_KEY_LEN; |
| 477 | maxlen = A38_XOR_MAX_KEY_LEN; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 478 | } else if (!strcasecmp(alg_str, "comp128v1")) { |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 479 | ainfo.auth_algo = AUTH_ALGO_COMP128v1; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 480 | minlen = maxlen = A38_COMP128_KEY_LEN; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 481 | } else { |
| 482 | /* Unknown method */ |
| 483 | return CMD_WARNING; |
| 484 | } |
| 485 | |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 486 | if (ki_str) { |
| 487 | rc = hexparse(ki_str, ainfo.a3a8_ki, sizeof(ainfo.a3a8_ki)); |
| 488 | if ((rc > maxlen) || (rc < minlen)) |
| 489 | return CMD_WARNING; |
| 490 | ainfo.a3a8_ki_len = rc; |
| 491 | } else { |
| 492 | ainfo.a3a8_ki_len = 0; |
| 493 | if (minlen) |
| 494 | return CMD_WARNING; |
| 495 | } |
| 496 | |
| 497 | rc = db_sync_authinfo_for_subscr( |
| 498 | ainfo.auth_algo == AUTH_ALGO_NONE ? NULL : &ainfo, |
| 499 | subscr); |
| 500 | |
Sylvain Munaut | 0d7d991 | 2010-06-10 22:00:48 +0200 | [diff] [blame] | 501 | /* the last tuple probably invalid with the new auth settings */ |
| 502 | db_sync_lastauthtuple_for_subscr(NULL, subscr); |
| 503 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 504 | return rc ? CMD_WARNING : CMD_SUCCESS; |
| 505 | } |
| 506 | |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 507 | static int scall_cbfn(unsigned int subsys, unsigned int signal, |
| 508 | void *handler_data, void *signal_data) |
| 509 | { |
| 510 | struct scall_signal_data *sigdata = signal_data; |
| 511 | struct vty *vty = sigdata->data; |
| 512 | |
| 513 | switch (signal) { |
| 514 | case S_SCALL_SUCCESS: |
| 515 | vty_out(vty, "%% silent call on ARFCN %u timeslot %u%s", |
| 516 | sigdata->lchan->ts->trx->arfcn, sigdata->lchan->ts->nr, |
| 517 | VTY_NEWLINE); |
| 518 | break; |
| 519 | case S_SCALL_EXPIRED: |
| 520 | vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE); |
| 521 | break; |
| 522 | } |
| 523 | return 0; |
| 524 | } |
| 525 | |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 526 | DEFUN(show_stats, |
| 527 | show_stats_cmd, |
| 528 | "show statistics", |
| 529 | SHOW_STR "Display network statistics\n") |
| 530 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 531 | struct gsm_network *net = gsmnet_from_vty(vty); |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 532 | |
| 533 | openbsc_vty_print_statistics(vty, net); |
| 534 | vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s", |
| 535 | counter_get(net->stats.loc_upd_type.attach), |
| 536 | counter_get(net->stats.loc_upd_type.normal), |
| 537 | counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE); |
| 538 | vty_out(vty, "IMSI Detach Indications : %lu%s", |
| 539 | counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE); |
| 540 | vty_out(vty, "Location Update Response: %lu accept, %lu reject%s", |
| 541 | counter_get(net->stats.loc_upd_resp.accept), |
| 542 | counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE); |
| 543 | vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, " |
| 544 | "%lu completed, %lu failed%s", |
| 545 | counter_get(net->stats.handover.attempted), |
| 546 | counter_get(net->stats.handover.no_channel), |
| 547 | counter_get(net->stats.handover.timeout), |
| 548 | counter_get(net->stats.handover.completed), |
| 549 | counter_get(net->stats.handover.failed), VTY_NEWLINE); |
| 550 | vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s", |
| 551 | counter_get(net->stats.sms.submitted), |
| 552 | counter_get(net->stats.sms.no_receiver), VTY_NEWLINE); |
| 553 | vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s", |
| 554 | counter_get(net->stats.sms.delivered), |
| 555 | counter_get(net->stats.sms.rp_err_mem), |
| 556 | counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE); |
| 557 | return CMD_SUCCESS; |
| 558 | } |
| 559 | |
| 560 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 561 | int bsc_vty_init_extra(void) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 562 | { |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 563 | register_signal_handler(SS_SCALL, scall_cbfn, NULL); |
| 564 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 565 | install_element_ve(&show_subscr_cmd); |
| 566 | install_element_ve(&show_subscr_cache_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 567 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 568 | install_element_ve(&sms_send_pend_cmd); |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 569 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 570 | install_element_ve(&subscriber_send_sms_cmd); |
| 571 | install_element_ve(&subscriber_silent_sms_cmd); |
| 572 | install_element_ve(&subscriber_silent_call_start_cmd); |
| 573 | install_element_ve(&subscriber_silent_call_stop_cmd); |
| 574 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 575 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 576 | install_element(ENABLE_NODE, &ena_subscr_name_cmd); |
| 577 | install_element(ENABLE_NODE, &ena_subscr_extension_cmd); |
| 578 | install_element(ENABLE_NODE, &ena_subscr_authorized_cmd); |
| 579 | install_element(ENABLE_NODE, &ena_subscr_a3a8_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 580 | |
| 581 | return 0; |
| 582 | } |