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') |
Harald Welte | c7ebb77 | 2010-06-30 09:00:46 +0200 | [diff] [blame] | 66 | v = 10 + (c - 'A'); |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 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 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 169 | sms->receiver = subscr_get(receiver); |
| 170 | strncpy(sms->text, text, sizeof(sms->text)-1); |
| 171 | |
| 172 | /* FIXME: don't use ID 1 static */ |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 173 | sms->sender = subscr_get_by_id(receiver->net, 1); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 174 | sms->reply_path_req = 0; |
| 175 | sms->status_rep_req = 0; |
| 176 | sms->ud_hdr_ind = 0; |
| 177 | sms->protocol_id = 0; /* implicit */ |
| 178 | sms->data_coding_scheme = 0; /* default 7bit */ |
| 179 | strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1); |
| 180 | /* Generate user_data */ |
| 181 | sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text); |
| 182 | |
| 183 | return sms; |
| 184 | } |
| 185 | |
Harald Welte | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 186 | static int _send_sms_str(struct gsm_subscriber *receiver, char *str, |
| 187 | u_int8_t tp_pid) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 188 | { |
| 189 | struct gsm_sms *sms; |
| 190 | |
Harald Welte | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 191 | sms = sms_from_text(receiver, str); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 192 | sms->protocol_id = tp_pid; |
Nico Golde | 2e6bc80 | 2010-06-29 20:13:06 +0200 | [diff] [blame] | 193 | |
| 194 | if(!receiver->lac){ |
| 195 | /* subscriber currently not attached, store in database */ |
| 196 | if (db_sms_store(sms) != 0) { |
| 197 | LOGP(DSMS, LOGL_ERROR, "Failed to store SMS in Database\n"); |
| 198 | return CMD_WARNING; |
| 199 | } |
| 200 | } else { |
| 201 | gsm411_send_sms_subscr(receiver, sms); |
| 202 | } |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 203 | |
| 204 | return CMD_SUCCESS; |
| 205 | } |
| 206 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 207 | static struct gsm_subscriber *get_subscr_by_argv(struct gsm_network *gsmnet, |
| 208 | const char *type, |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 209 | const char *id) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 210 | { |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 211 | if (!strcmp(type, "extension")) |
| 212 | return subscr_get_by_extension(gsmnet, id); |
| 213 | else if (!strcmp(type, "imsi")) |
| 214 | return subscr_get_by_imsi(gsmnet, id); |
| 215 | else if (!strcmp(type, "tmsi")) |
| 216 | return subscr_get_by_tmsi(gsmnet, atoi(id)); |
| 217 | else if (!strcmp(type, "id")) |
| 218 | return subscr_get_by_id(gsmnet, atoi(id)); |
| 219 | |
| 220 | return NULL; |
| 221 | } |
| 222 | #define SUBSCR_TYPES "(extension|imsi|tmsi|id)" |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 223 | #define SUBSCR_HELP "Operations on a Subscriber\n" \ |
| 224 | "Identify subscriber by his extension (phone number)\n" \ |
| 225 | "Identify subscriber by his IMSI\n" \ |
| 226 | "Identify subscriber by his TMSI\n" \ |
| 227 | "Identify subscriber by his database ID\n" \ |
| 228 | "Identifier for the subscriber\n" |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 229 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 230 | DEFUN(show_subscr, |
| 231 | show_subscr_cmd, |
| 232 | "show subscriber " SUBSCR_TYPES " ID", |
| 233 | SHOW_STR SUBSCR_HELP) |
| 234 | { |
| 235 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 236 | struct gsm_subscriber *subscr = |
| 237 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
| 238 | |
| 239 | if (!subscr) { |
| 240 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 241 | argv[0], argv[1], VTY_NEWLINE); |
| 242 | return CMD_WARNING; |
| 243 | } |
| 244 | |
| 245 | subscr_dump_full_vty(vty, subscr); |
| 246 | |
| 247 | subscr_put(subscr); |
| 248 | |
| 249 | return CMD_SUCCESS; |
| 250 | } |
| 251 | |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 252 | DEFUN(subscriber_send_sms, |
| 253 | subscriber_send_sms_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 254 | "subscriber " SUBSCR_TYPES " ID sms send .LINE", |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 255 | SUBSCR_HELP "SMS Operations\n" "Send SMS\n" "Actual SMS Text") |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 256 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 257 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 258 | 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] | 259 | char *str; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 260 | int rc; |
| 261 | |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 262 | if (!subscr) { |
| 263 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 264 | argv[0], argv[1], VTY_NEWLINE); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 265 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 266 | } |
Harald Welte | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 267 | str = argv_concat(argv, argc, 2); |
| 268 | rc = _send_sms_str(subscr, str, 0); |
| 269 | talloc_free(str); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 270 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 271 | subscr_put(subscr); |
| 272 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 273 | return rc; |
| 274 | } |
| 275 | |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 276 | DEFUN(subscriber_silent_sms, |
| 277 | subscriber_silent_sms_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 278 | "subscriber " SUBSCR_TYPES " ID silent-sms send .LINE", |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 279 | SUBSCR_HELP |
| 280 | "Silent SMS Operation\n" "Send Silent SMS\n" "Actual SMS text\n") |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 281 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 282 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 283 | 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] | 284 | char *str; |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 285 | int rc; |
| 286 | |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 287 | if (!subscr) { |
| 288 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 289 | argv[0], argv[1], VTY_NEWLINE); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 290 | return CMD_WARNING; |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 291 | } |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 292 | |
Harald Welte | 3699e20 | 2010-05-16 19:28:32 +0200 | [diff] [blame] | 293 | str = argv_concat(argv, argc, 2); |
| 294 | rc = _send_sms_str(subscr, str, 0); |
| 295 | talloc_free(str); |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 296 | |
Harald Welte | bbe3172 | 2009-11-14 10:10:54 +0100 | [diff] [blame] | 297 | subscr_put(subscr); |
| 298 | |
Harald Welte | 9ee8ee9 | 2009-11-05 15:51:17 +0900 | [diff] [blame] | 299 | return rc; |
| 300 | } |
| 301 | |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 302 | #define CHAN_TYPES "(any|tch/f|tch/any|sdcch)" |
| 303 | #define CHAN_TYPE_HELP \ |
| 304 | "Any channel\n" \ |
| 305 | "TCH/F channel\n" \ |
| 306 | "Any TCH channel\n" \ |
| 307 | "SDCCH channel\n" |
| 308 | |
Sylvain Munaut | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 309 | DEFUN(subscriber_silent_call_start, |
| 310 | subscriber_silent_call_start_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 311 | "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] | 312 | SUBSCR_HELP "Silent call operation\n" "Start silent call\n" |
| 313 | CHAN_TYPE_HELP) |
Sylvain Munaut | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 314 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 315 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 316 | 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] | 317 | int rc, type; |
| 318 | |
| 319 | if (!subscr) { |
| 320 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 321 | argv[0], argv[1], VTY_NEWLINE); |
| 322 | return CMD_WARNING; |
| 323 | } |
| 324 | |
| 325 | if (!strcmp(argv[2], "tch/f")) |
| 326 | type = RSL_CHANNEED_TCH_F; |
| 327 | else if (!strcmp(argv[2], "tch/any")) |
| 328 | type = RSL_CHANNEED_TCH_ForH; |
| 329 | else if (!strcmp(argv[2], "sdcch")) |
| 330 | type = RSL_CHANNEED_SDCCH; |
| 331 | else |
| 332 | type = RSL_CHANNEED_ANY; /* Defaults to ANY */ |
| 333 | |
| 334 | rc = gsm_silent_call_start(subscr, vty, type); |
| 335 | if (rc <= 0) { |
| 336 | vty_out(vty, "%% Subscriber not attached%s", |
| 337 | VTY_NEWLINE); |
| 338 | subscr_put(subscr); |
| 339 | return CMD_WARNING; |
| 340 | } |
| 341 | |
| 342 | subscr_put(subscr); |
| 343 | |
| 344 | return CMD_SUCCESS; |
| 345 | } |
| 346 | |
| 347 | DEFUN(subscriber_silent_call_stop, |
| 348 | subscriber_silent_call_stop_cmd, |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 349 | "subscriber " SUBSCR_TYPES " ID silent-call stop", |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 350 | SUBSCR_HELP "Silent call operation\n" "Stop silent call\n" |
| 351 | CHAN_TYPE_HELP) |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 352 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 353 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 354 | 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] | 355 | int rc; |
| 356 | |
| 357 | if (!subscr) { |
| 358 | vty_out(vty, "%% No subscriber found for %s %s%s", |
Harald Welte | 81cf198 | 2009-11-14 10:11:45 +0100 | [diff] [blame] | 359 | argv[0], argv[1], VTY_NEWLINE); |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 360 | return CMD_WARNING; |
| 361 | } |
| 362 | |
Sylvain Munaut | 1c378a7 | 2010-01-02 14:29:43 +0100 | [diff] [blame] | 363 | rc = gsm_silent_call_stop(subscr); |
| 364 | if (rc < 0) { |
| 365 | subscr_put(subscr); |
| 366 | return CMD_WARNING; |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | subscr_put(subscr); |
| 370 | |
| 371 | return CMD_SUCCESS; |
| 372 | } |
| 373 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 374 | DEFUN(ena_subscr_authorizde, |
| 375 | ena_subscr_authorized_cmd, |
| 376 | "subscriber " SUBSCR_TYPES " ID authorized (0|1)", |
| 377 | SUBSCR_HELP "(De-)Authorize subscriber in HLR\n" |
| 378 | "Subscriber should NOT be authorized\n" |
| 379 | "Subscriber should be authorized\n") |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 380 | { |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 381 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 382 | struct gsm_subscriber *subscr = |
| 383 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
| 384 | |
| 385 | if (!subscr) { |
| 386 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 387 | argv[0], argv[1], VTY_NEWLINE); |
| 388 | return CMD_WARNING; |
| 389 | } |
| 390 | |
| 391 | subscr->authorized = atoi(argv[2]); |
| 392 | db_sync_subscriber(subscr); |
| 393 | |
| 394 | subscr_put(subscr); |
| 395 | |
| 396 | return CMD_SUCCESS; |
| 397 | } |
| 398 | |
| 399 | DEFUN(ena_subscr_name, |
| 400 | ena_subscr_name_cmd, |
Harald Welte | 3368e36 | 2010-06-24 08:06:38 +0200 | [diff] [blame] | 401 | "subscriber " SUBSCR_TYPES " ID name .NAME", |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 402 | SUBSCR_HELP "Set the name of the subscriber\n" |
| 403 | "Name of the Subscriber\n") |
| 404 | { |
| 405 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 406 | struct gsm_subscriber *subscr = |
| 407 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
Harald Welte | 3368e36 | 2010-06-24 08:06:38 +0200 | [diff] [blame] | 408 | char *name; |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 409 | |
| 410 | if (!subscr) { |
| 411 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 412 | argv[0], argv[1], VTY_NEWLINE); |
| 413 | return CMD_WARNING; |
| 414 | } |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 415 | |
Harald Welte | 3368e36 | 2010-06-24 08:06:38 +0200 | [diff] [blame] | 416 | name = argv_concat(argv, argc, 2); |
| 417 | if (!name) |
| 418 | return CMD_WARNING; |
| 419 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 420 | strncpy(subscr->name, name, sizeof(subscr->name)); |
Harald Welte | 3368e36 | 2010-06-24 08:06:38 +0200 | [diff] [blame] | 421 | talloc_free(name); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 422 | db_sync_subscriber(subscr); |
| 423 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 424 | subscr_put(subscr); |
| 425 | |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 426 | return CMD_SUCCESS; |
| 427 | } |
| 428 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 429 | DEFUN(ena_subscr_extension, |
| 430 | ena_subscr_extension_cmd, |
| 431 | "subscriber " SUBSCR_TYPES " ID extension EXTENSION", |
| 432 | SUBSCR_HELP "Set the extension (phone number) of the subscriber\n" |
| 433 | "Extension (phone number)\n") |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 434 | { |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 435 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 436 | struct gsm_subscriber *subscr = |
| 437 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
| 438 | const char *name = argv[2]; |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 439 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 440 | if (!subscr) { |
| 441 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 442 | argv[0], argv[1], VTY_NEWLINE); |
| 443 | return CMD_WARNING; |
| 444 | } |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 445 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 446 | strncpy(subscr->extension, name, sizeof(subscr->name)); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 447 | db_sync_subscriber(subscr); |
| 448 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 449 | subscr_put(subscr); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 450 | |
| 451 | return CMD_SUCCESS; |
| 452 | } |
| 453 | |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 454 | #define A3A8_ALG_TYPES "(none|xor|comp128v1)" |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 455 | #define A3A8_ALG_HELP \ |
| 456 | "Use No A3A8 algorithm\n" \ |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 457 | "Use XOR algorithm\n" \ |
Harald Welte | 18ce31c | 2010-05-14 20:05:17 +0200 | [diff] [blame] | 458 | "Use COMP128v1 algorithm\n" |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 459 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 460 | DEFUN(ena_subscr_a3a8, |
| 461 | ena_subscr_a3a8_cmd, |
| 462 | "subscriber " SUBSCR_TYPES " ID a3a8 " A3A8_ALG_TYPES " [KI]", |
Harald Welte | c4bf319 | 2010-05-27 10:48:11 +0200 | [diff] [blame] | 463 | SUBSCR_HELP "Set a3a8 parameters for the subscriber\n" |
| 464 | A3A8_ALG_HELP "Encryption Key Ki\n") |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 465 | { |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 466 | struct gsm_network *gsmnet = gsmnet_from_vty(vty); |
| 467 | struct gsm_subscriber *subscr = |
| 468 | get_subscr_by_argv(gsmnet, argv[0], argv[1]); |
| 469 | const char *alg_str = argv[2]; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 470 | const char *ki_str = argc == 4 ? argv[3] : NULL; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 471 | struct gsm_auth_info ainfo; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 472 | int rc, minlen, maxlen; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 473 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 474 | if (!subscr) { |
| 475 | vty_out(vty, "%% No subscriber found for %s %s%s", |
| 476 | argv[0], argv[1], VTY_NEWLINE); |
| 477 | return CMD_WARNING; |
| 478 | } |
| 479 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 480 | if (!strcasecmp(alg_str, "none")) { |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 481 | ainfo.auth_algo = AUTH_ALGO_NONE; |
| 482 | minlen = maxlen = 0; |
| 483 | } else if (!strcasecmp(alg_str, "xor")) { |
| 484 | ainfo.auth_algo = AUTH_ALGO_XOR; |
| 485 | minlen = A38_XOR_MIN_KEY_LEN; |
| 486 | maxlen = A38_XOR_MAX_KEY_LEN; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 487 | } else if (!strcasecmp(alg_str, "comp128v1")) { |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 488 | ainfo.auth_algo = AUTH_ALGO_COMP128v1; |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 489 | minlen = maxlen = A38_COMP128_KEY_LEN; |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 490 | } else { |
| 491 | /* Unknown method */ |
| 492 | return CMD_WARNING; |
| 493 | } |
| 494 | |
Sylvain Munaut | 4887644 | 2010-06-11 00:19:42 +0200 | [diff] [blame] | 495 | if (ki_str) { |
| 496 | rc = hexparse(ki_str, ainfo.a3a8_ki, sizeof(ainfo.a3a8_ki)); |
| 497 | if ((rc > maxlen) || (rc < minlen)) |
| 498 | return CMD_WARNING; |
| 499 | ainfo.a3a8_ki_len = rc; |
| 500 | } else { |
| 501 | ainfo.a3a8_ki_len = 0; |
| 502 | if (minlen) |
| 503 | return CMD_WARNING; |
| 504 | } |
| 505 | |
| 506 | rc = db_sync_authinfo_for_subscr( |
| 507 | ainfo.auth_algo == AUTH_ALGO_NONE ? NULL : &ainfo, |
| 508 | subscr); |
| 509 | |
Sylvain Munaut | 0d7d991 | 2010-06-10 22:00:48 +0200 | [diff] [blame] | 510 | /* the last tuple probably invalid with the new auth settings */ |
| 511 | db_sync_lastauthtuple_for_subscr(NULL, subscr); |
| 512 | |
Sylvain Munaut | dcf8c4c | 2009-12-27 19:30:46 +0100 | [diff] [blame] | 513 | return rc ? CMD_WARNING : CMD_SUCCESS; |
| 514 | } |
| 515 | |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 516 | static int scall_cbfn(unsigned int subsys, unsigned int signal, |
| 517 | void *handler_data, void *signal_data) |
| 518 | { |
| 519 | struct scall_signal_data *sigdata = signal_data; |
| 520 | struct vty *vty = sigdata->data; |
| 521 | |
| 522 | switch (signal) { |
| 523 | case S_SCALL_SUCCESS: |
| 524 | vty_out(vty, "%% silent call on ARFCN %u timeslot %u%s", |
Holger Hans Peter Freyther | d3aaf66 | 2010-06-17 15:05:57 +0800 | [diff] [blame] | 525 | sigdata->conn->lchan->ts->trx->arfcn, sigdata->conn->lchan->ts->nr, |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 526 | VTY_NEWLINE); |
| 527 | break; |
| 528 | case S_SCALL_EXPIRED: |
| 529 | vty_out(vty, "%% silent call expired paging%s", VTY_NEWLINE); |
| 530 | break; |
| 531 | } |
| 532 | return 0; |
| 533 | } |
| 534 | |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 535 | DEFUN(show_stats, |
| 536 | show_stats_cmd, |
| 537 | "show statistics", |
| 538 | SHOW_STR "Display network statistics\n") |
| 539 | { |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 540 | struct gsm_network *net = gsmnet_from_vty(vty); |
Holger Hans Peter Freyther | e789b21 | 2010-04-15 11:28:14 +0200 | [diff] [blame] | 541 | |
| 542 | openbsc_vty_print_statistics(vty, net); |
| 543 | vty_out(vty, "Location Update : %lu attach, %lu normal, %lu periodic%s", |
| 544 | counter_get(net->stats.loc_upd_type.attach), |
| 545 | counter_get(net->stats.loc_upd_type.normal), |
| 546 | counter_get(net->stats.loc_upd_type.periodic), VTY_NEWLINE); |
| 547 | vty_out(vty, "IMSI Detach Indications : %lu%s", |
| 548 | counter_get(net->stats.loc_upd_type.detach), VTY_NEWLINE); |
| 549 | vty_out(vty, "Location Update Response: %lu accept, %lu reject%s", |
| 550 | counter_get(net->stats.loc_upd_resp.accept), |
| 551 | counter_get(net->stats.loc_upd_resp.reject), VTY_NEWLINE); |
| 552 | vty_out(vty, "Handover : %lu attempted, %lu no_channel, %lu timeout, " |
| 553 | "%lu completed, %lu failed%s", |
| 554 | counter_get(net->stats.handover.attempted), |
| 555 | counter_get(net->stats.handover.no_channel), |
| 556 | counter_get(net->stats.handover.timeout), |
| 557 | counter_get(net->stats.handover.completed), |
| 558 | counter_get(net->stats.handover.failed), VTY_NEWLINE); |
| 559 | vty_out(vty, "SMS MO : %lu submitted, %lu no receiver%s", |
| 560 | counter_get(net->stats.sms.submitted), |
| 561 | counter_get(net->stats.sms.no_receiver), VTY_NEWLINE); |
| 562 | vty_out(vty, "SMS MT : %lu delivered, %lu no memory, %lu other error%s", |
| 563 | counter_get(net->stats.sms.delivered), |
| 564 | counter_get(net->stats.sms.rp_err_mem), |
| 565 | counter_get(net->stats.sms.rp_err_other), VTY_NEWLINE); |
| 566 | return CMD_SUCCESS; |
| 567 | } |
| 568 | |
| 569 | |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 570 | int bsc_vty_init_extra(void) |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 571 | { |
Harald Welte | b8678a7 | 2009-11-14 10:08:40 +0100 | [diff] [blame] | 572 | register_signal_handler(SS_SCALL, scall_cbfn, NULL); |
| 573 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 574 | install_element_ve(&show_subscr_cmd); |
| 575 | install_element_ve(&show_subscr_cache_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 576 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 577 | install_element_ve(&sms_send_pend_cmd); |
Harald Welte | 194ef7b | 2009-11-14 08:00:53 +0100 | [diff] [blame] | 578 | |
Harald Welte | 7bc28f6 | 2010-05-12 16:10:35 +0000 | [diff] [blame] | 579 | install_element_ve(&subscriber_send_sms_cmd); |
| 580 | install_element_ve(&subscriber_silent_sms_cmd); |
| 581 | install_element_ve(&subscriber_silent_call_start_cmd); |
| 582 | install_element_ve(&subscriber_silent_call_stop_cmd); |
| 583 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 584 | |
Harald Welte | a8ca70f | 2010-05-27 10:44:58 +0200 | [diff] [blame] | 585 | install_element(ENABLE_NODE, &ena_subscr_name_cmd); |
| 586 | install_element(ENABLE_NODE, &ena_subscr_extension_cmd); |
| 587 | install_element(ENABLE_NODE, &ena_subscr_authorized_cmd); |
| 588 | install_element(ENABLE_NODE, &ena_subscr_a3a8_cmd); |
Holger Hans Peter Freyther | bdae6f9 | 2009-08-10 10:17:50 +0200 | [diff] [blame] | 589 | |
| 590 | return 0; |
| 591 | } |