Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1 | /* OpenBSC interface to quagga VTY */ |
| 2 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <unistd.h> |
| 23 | #include <sys/types.h> |
| 24 | |
| 25 | #include <vty/command.h> |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 26 | #include <vty/buffer.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 27 | #include <vty/vty.h> |
| 28 | |
| 29 | #include <arpa/inet.h> |
| 30 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 31 | #include <openbsc/linuxlist.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 32 | #include <openbsc/gsm_data.h> |
| 33 | #include <openbsc/gsm_subscriber.h> |
Holger Hans Peter Freyther | 34e9749 | 2009-08-10 07:54:02 +0200 | [diff] [blame] | 34 | #include <openbsc/gsm_04_11.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 35 | #include <openbsc/e1_input.h> |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 36 | #include <openbsc/abis_nm.h> |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 37 | #include <openbsc/gsm_utils.h> |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 38 | #include <openbsc/db.h> |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 39 | #include <openbsc/talloc.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 40 | |
| 41 | static struct gsm_network *gsmnet; |
| 42 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 43 | struct cmd_node net_node = { |
| 44 | GSMNET_NODE, |
| 45 | "%s(network)#", |
| 46 | 1, |
| 47 | }; |
| 48 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 49 | struct cmd_node bts_node = { |
| 50 | BTS_NODE, |
| 51 | "%s(bts)#", |
| 52 | 1, |
| 53 | }; |
| 54 | |
| 55 | struct cmd_node trx_node = { |
| 56 | TRX_NODE, |
| 57 | "%s(trx)#", |
| 58 | 1, |
| 59 | }; |
| 60 | |
| 61 | struct cmd_node ts_node = { |
| 62 | TS_NODE, |
| 63 | "%s(ts)#", |
| 64 | 1, |
| 65 | }; |
| 66 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 67 | struct cmd_node subscr_node = { |
| 68 | SUBSCR_NODE, |
| 69 | "%s(subscriber)#", |
| 70 | 1, |
| 71 | }; |
| 72 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 73 | static int dummy_config_write(struct vty *v) |
| 74 | { |
| 75 | return CMD_SUCCESS; |
| 76 | } |
| 77 | |
| 78 | static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms) |
| 79 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 80 | vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s", |
| 81 | nm_opstate_name(nms->operational), nms->administrative, |
| 82 | nm_avail_name(nms->availability), VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static void net_dump_vty(struct vty *vty, struct gsm_network *net) |
| 86 | { |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 87 | vty_out(vty, "BSC is on Country Code %u, Network Code %u " |
| 88 | "and has %u BTS%s", net->country_code, net->network_code, |
| 89 | net->num_bts, VTY_NEWLINE); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 90 | vty_out(vty, " Long network name: '%s'%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 91 | net->name_long, VTY_NEWLINE); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 92 | vty_out(vty, " Short network name: '%s'%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 93 | net->name_short, VTY_NEWLINE); |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame^] | 94 | vty_out(vty, " Authentication policy: %s%s", |
| 95 | gsm_auth_policy_name(net->auth_policy), VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | DEFUN(show_net, show_net_cmd, "show network", |
| 99 | SHOW_STR "Display information about a GSM NETWORK\n") |
| 100 | { |
| 101 | struct gsm_network *net = gsmnet; |
| 102 | net_dump_vty(vty, net); |
| 103 | |
| 104 | return CMD_SUCCESS; |
| 105 | } |
| 106 | |
| 107 | static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l) |
| 108 | { |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 109 | struct e1inp_line *line; |
| 110 | |
| 111 | if (!e1l) { |
| 112 | vty_out(vty, " None%s", VTY_NEWLINE); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | line = e1l->ts->line; |
| 117 | |
| 118 | vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s", |
| 119 | line->num, line->driver->name, e1l->ts->num, |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 120 | e1inp_signtype_name(e1l->type), VTY_NEWLINE); |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 121 | vty_out(vty, " E1 TEI %u, SAPI %u%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 122 | e1l->tei, e1l->sapi, VTY_NEWLINE); |
| 123 | } |
| 124 | |
| 125 | static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts) |
| 126 | { |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 127 | vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, " |
| 128 | "BSIC %u, TSC %u and %u TRX%s", |
| 129 | bts->nr, btstype2str(bts->type), gsm_band_name(bts->band), |
| 130 | bts->location_area_code, bts->bsic, bts->tsc, |
| 131 | bts->num_trx, VTY_NEWLINE); |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 132 | if (is_ipaccess_bts(bts)) |
| 133 | vty_out(vty, " Unit ID: %u/%u/0%s", |
| 134 | bts->ip_access.site_id, bts->ip_access.bts_id, |
| 135 | VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 136 | vty_out(vty, " NM State: "); |
| 137 | net_dump_nmstate(vty, &bts->nm_state); |
| 138 | vty_out(vty, " Site Mgr NM State: "); |
| 139 | net_dump_nmstate(vty, &bts->site_mgr.nm_state); |
| 140 | vty_out(vty, " Paging: FIXME pending requests, %u free slots%s", |
| 141 | bts->paging.available_slots, VTY_NEWLINE); |
| 142 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 143 | e1isl_dump_vty(vty, bts->oml_link); |
| 144 | /* FIXME: oml_link, chan_desc */ |
| 145 | } |
| 146 | |
| 147 | DEFUN(show_bts, show_bts_cmd, "show bts [number]", |
| 148 | SHOW_STR "Display information about a BTS\n" |
| 149 | "BTS number") |
| 150 | { |
| 151 | struct gsm_network *net = gsmnet; |
| 152 | int bts_nr; |
| 153 | |
| 154 | if (argc != 0) { |
| 155 | /* use the BTS number that the user has specified */ |
| 156 | bts_nr = atoi(argv[0]); |
| 157 | if (bts_nr > net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 158 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 159 | VTY_NEWLINE); |
| 160 | return CMD_WARNING; |
| 161 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 162 | bts_dump_vty(vty, gsm_bts_num(net, bts_nr)); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 163 | return CMD_SUCCESS; |
| 164 | } |
| 165 | /* print all BTS's */ |
| 166 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 167 | bts_dump_vty(vty, gsm_bts_num(net, bts_nr)); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 168 | |
| 169 | return CMD_SUCCESS; |
| 170 | } |
| 171 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 172 | /* utility functions */ |
| 173 | static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line, |
| 174 | const char *ts, const char *ss) |
| 175 | { |
| 176 | e1_link->e1_nr = atoi(line); |
| 177 | e1_link->e1_ts = atoi(ts); |
| 178 | if (!strcmp(ss, "full")) |
| 179 | e1_link->e1_ts_ss = 255; |
| 180 | else |
| 181 | e1_link->e1_ts_ss = atoi(ss); |
| 182 | } |
| 183 | |
| 184 | static void config_write_e1_link(struct vty *vty, struct gsm_e1_subslot *e1_link, |
| 185 | const char *prefix) |
| 186 | { |
| 187 | if (!e1_link->e1_ts) |
| 188 | return; |
| 189 | |
| 190 | if (e1_link->e1_ts_ss == 255) |
| 191 | vty_out(vty, "%se1 line %u timeslot %u sub-slot full%s", |
| 192 | prefix, e1_link->e1_nr, e1_link->e1_ts, VTY_NEWLINE); |
| 193 | else |
| 194 | vty_out(vty, "%se1 line %u timeslot %u sub-slot %u%s", |
| 195 | prefix, e1_link->e1_nr, e1_link->e1_ts, |
| 196 | e1_link->e1_ts_ss, VTY_NEWLINE); |
| 197 | } |
| 198 | |
| 199 | |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 200 | static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts) |
| 201 | { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 202 | vty_out(vty, " timeslot %u%s", ts->nr, VTY_NEWLINE); |
| 203 | if (ts->pchan != GSM_PCHAN_NONE) |
| 204 | vty_out(vty, " phys_chan_config %s%s", |
| 205 | gsm_pchan_name(ts->pchan), VTY_NEWLINE); |
| 206 | config_write_e1_link(vty, &ts->e1_link, " "); |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx) |
| 210 | { |
| 211 | int i; |
| 212 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 213 | vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE); |
| 214 | vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE); |
| 215 | vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 216 | config_write_e1_link(vty, &trx->rsl_e1_link, " rsl "); |
| 217 | vty_out(vty, " rsl e1 tei %u%s", trx->rsl_tei, VTY_NEWLINE); |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 218 | |
| 219 | for (i = 0; i < TRX_NR_TS; i++) |
| 220 | config_write_ts_single(vty, &trx->ts[i]); |
| 221 | } |
| 222 | |
| 223 | static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts) |
| 224 | { |
| 225 | struct gsm_bts_trx *trx; |
| 226 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 227 | vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE); |
| 228 | vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE); |
| 229 | vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE); |
| 230 | vty_out(vty, " location_area_code %u%s", bts->location_area_code, |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 231 | VTY_NEWLINE); |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 232 | vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE); |
| 233 | vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE); |
Harald Welte | 7a8fa41 | 2009-08-10 13:48:16 +0200 | [diff] [blame] | 234 | vty_out(vty, " channel allocator %s%s", |
| 235 | bts->chan_alloc_reverse ? "descending" : "ascending", |
| 236 | VTY_NEWLINE); |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 237 | if (is_ipaccess_bts(bts)) |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 238 | vty_out(vty, " ip.access unit_id %u %u%s", |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 239 | bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 240 | else { |
| 241 | config_write_e1_link(vty, &bts->oml_e1_link, " oml "); |
| 242 | vty_out(vty, " oml e1 tei %u%s", bts->oml_tei, VTY_NEWLINE); |
| 243 | } |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 244 | |
| 245 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 246 | config_write_trx_single(vty, trx); |
| 247 | } |
| 248 | |
| 249 | static int config_write_bts(struct vty *v) |
| 250 | { |
| 251 | struct gsm_bts *bts; |
| 252 | |
| 253 | llist_for_each_entry(bts, &gsmnet->bts_list, list) |
| 254 | config_write_bts_single(v, bts); |
| 255 | |
| 256 | return CMD_SUCCESS; |
| 257 | } |
| 258 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 259 | static int config_write_net(struct vty *vty) |
| 260 | { |
| 261 | vty_out(vty, "network%s", VTY_NEWLINE); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 262 | vty_out(vty, " network country code %u%s", gsmnet->country_code, VTY_NEWLINE); |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 263 | vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 264 | vty_out(vty, " short name %s%s", gsmnet->name_short, VTY_NEWLINE); |
| 265 | vty_out(vty, " long name %s%s", gsmnet->name_long, VTY_NEWLINE); |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame^] | 266 | vty_out(vty, " auth policy %s%s", gsm_auth_policy_name(gsmnet->auth_policy), VTY_NEWLINE); |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 267 | |
| 268 | return CMD_SUCCESS; |
| 269 | } |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 270 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 271 | static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx) |
| 272 | { |
| 273 | vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s", |
| 274 | trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE); |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 275 | vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, " |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 276 | "resulting BS power: %d dBm%s", |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 277 | trx->nominal_power, trx->max_power_red, |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 278 | trx->nominal_power - trx->max_power_red, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 279 | vty_out(vty, " NM State: "); |
| 280 | net_dump_nmstate(vty, &trx->nm_state); |
| 281 | vty_out(vty, " Baseband Transceiver NM State: "); |
| 282 | net_dump_nmstate(vty, &trx->bb_transc.nm_state); |
| 283 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 284 | e1isl_dump_vty(vty, trx->rsl_link); |
| 285 | } |
| 286 | |
| 287 | DEFUN(show_trx, |
| 288 | show_trx_cmd, |
| 289 | "show trx [bts_nr] [trx_nr]", |
| 290 | SHOW_STR "Display information about a TRX\n") |
| 291 | { |
| 292 | struct gsm_network *net = gsmnet; |
| 293 | struct gsm_bts *bts = NULL; |
| 294 | struct gsm_bts_trx *trx; |
| 295 | int bts_nr, trx_nr; |
| 296 | |
| 297 | if (argc >= 1) { |
| 298 | /* use the BTS number that the user has specified */ |
| 299 | bts_nr = atoi(argv[0]); |
| 300 | if (bts_nr >= net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 301 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 302 | VTY_NEWLINE); |
| 303 | return CMD_WARNING; |
| 304 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 305 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 306 | } |
| 307 | if (argc >= 2) { |
| 308 | trx_nr = atoi(argv[1]); |
| 309 | if (trx_nr >= bts->num_trx) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 310 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 311 | VTY_NEWLINE); |
| 312 | return CMD_WARNING; |
| 313 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 314 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 315 | trx_dump_vty(vty, trx); |
| 316 | return CMD_SUCCESS; |
| 317 | } |
| 318 | if (bts) { |
| 319 | /* print all TRX in this BTS */ |
| 320 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 321 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 322 | trx_dump_vty(vty, trx); |
| 323 | } |
| 324 | return CMD_SUCCESS; |
| 325 | } |
| 326 | |
| 327 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 328 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 329 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 330 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 331 | trx_dump_vty(vty, trx); |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | return CMD_SUCCESS; |
| 336 | } |
| 337 | |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 338 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 339 | static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts) |
| 340 | { |
| 341 | struct in_addr ia; |
| 342 | |
| 343 | vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s", |
| 344 | ts->nr, ts->trx->nr, ts->trx->bts->nr, |
| 345 | gsm_pchan_name(ts->pchan), VTY_NEWLINE); |
| 346 | vty_out(vty, " NM State: "); |
| 347 | net_dump_nmstate(vty, &ts->nm_state); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 348 | if (is_ipaccess_bts(ts->trx->bts)) { |
| 349 | ia.s_addr = ts->abis_ip.bound_ip; |
Harald Welte | 2085554 | 2009-07-12 09:50:35 +0200 | [diff] [blame] | 350 | vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 351 | inet_ntoa(ia), ts->abis_ip.bound_port, |
Harald Welte | 2085554 | 2009-07-12 09:50:35 +0200 | [diff] [blame] | 352 | ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id, |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 353 | VTY_NEWLINE); |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 354 | } else { |
| 355 | vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s", |
| 356 | ts->e1_link.e1_nr, ts->e1_link.e1_ts, |
| 357 | ts->e1_link.e1_ts_ss, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
| 361 | DEFUN(show_ts, |
| 362 | show_ts_cmd, |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 363 | "show timeslot [bts_nr] [trx_nr] [ts_nr]", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 364 | SHOW_STR "Display information about a TS\n") |
| 365 | { |
| 366 | struct gsm_network *net = gsmnet; |
| 367 | struct gsm_bts *bts; |
| 368 | struct gsm_bts_trx *trx; |
| 369 | struct gsm_bts_trx_ts *ts; |
| 370 | int bts_nr, trx_nr, ts_nr; |
| 371 | |
| 372 | if (argc >= 1) { |
| 373 | /* use the BTS number that the user has specified */ |
| 374 | bts_nr = atoi(argv[0]); |
| 375 | if (bts_nr >= net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 376 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 377 | VTY_NEWLINE); |
| 378 | return CMD_WARNING; |
| 379 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 380 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 381 | } |
| 382 | if (argc >= 2) { |
| 383 | trx_nr = atoi(argv[1]); |
| 384 | if (trx_nr >= bts->num_trx) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 385 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 386 | VTY_NEWLINE); |
| 387 | return CMD_WARNING; |
| 388 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 389 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 390 | } |
| 391 | if (argc >= 3) { |
| 392 | ts_nr = atoi(argv[2]); |
| 393 | if (ts_nr >= TRX_NR_TS) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 394 | vty_out(vty, "%% can't find TS '%s'%s", argv[2], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 395 | VTY_NEWLINE); |
| 396 | return CMD_WARNING; |
| 397 | } |
| 398 | ts = &trx->ts[ts_nr]; |
| 399 | ts_dump_vty(vty, ts); |
| 400 | return CMD_SUCCESS; |
| 401 | } |
| 402 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 403 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 404 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 405 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 406 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 407 | ts = &trx->ts[ts_nr]; |
| 408 | ts_dump_vty(vty, ts); |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | return CMD_SUCCESS; |
| 414 | } |
| 415 | |
| 416 | static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr) |
| 417 | { |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 418 | vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id, |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 419 | subscr->authorized, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 420 | if (subscr->name) |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 421 | vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 422 | if (subscr->extension) |
| 423 | vty_out(vty, " Extension: %s%s", subscr->extension, |
| 424 | VTY_NEWLINE); |
| 425 | if (subscr->imsi) |
| 426 | vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); |
| 427 | if (subscr->tmsi) |
| 428 | vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE); |
| 429 | } |
| 430 | |
| 431 | static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan) |
| 432 | { |
| 433 | vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s", |
| 434 | lchan->nr, lchan->ts->nr, lchan->ts->trx->nr, |
| 435 | lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type), |
| 436 | VTY_NEWLINE); |
| 437 | vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE); |
| 438 | vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power, |
| 439 | lchan->ms_power, VTY_NEWLINE); |
| 440 | if (lchan->subscr) { |
| 441 | vty_out(vty, " Subscriber:%s", VTY_NEWLINE); |
| 442 | subscr_dump_vty(vty, lchan->subscr); |
| 443 | } else |
| 444 | vty_out(vty, " No Subscriber%s", VTY_NEWLINE); |
| 445 | } |
| 446 | |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 447 | #if 0 |
| 448 | TODO: callref and remote callref of call must be resolved to get gsm_trans object |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 449 | static void call_dump_vty(struct vty *vty, struct gsm_call *call) |
| 450 | { |
| 451 | vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s", |
| 452 | call->type, call->state, call->transaction_id, VTY_NEWLINE); |
| 453 | |
| 454 | if (call->local_lchan) { |
| 455 | vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE); |
| 456 | lchan_dump_vty(vty, call->local_lchan); |
| 457 | } else |
| 458 | vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE); |
| 459 | |
| 460 | if (call->remote_lchan) { |
| 461 | vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE); |
| 462 | lchan_dump_vty(vty, call->remote_lchan); |
| 463 | } else |
| 464 | vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE); |
| 465 | |
| 466 | if (call->called_subscr) { |
| 467 | vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE); |
| 468 | subscr_dump_vty(vty, call->called_subscr); |
| 469 | } else |
| 470 | vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE); |
| 471 | } |
Harald Welte | 4bfdfe7 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 472 | #endif |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 473 | |
| 474 | DEFUN(show_lchan, |
| 475 | show_lchan_cmd, |
| 476 | "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]", |
| 477 | SHOW_STR "Display information about a logical channel\n") |
| 478 | { |
| 479 | struct gsm_network *net = gsmnet; |
| 480 | struct gsm_bts *bts; |
| 481 | struct gsm_bts_trx *trx; |
| 482 | struct gsm_bts_trx_ts *ts; |
| 483 | struct gsm_lchan *lchan; |
| 484 | int bts_nr, trx_nr, ts_nr, lchan_nr; |
| 485 | |
| 486 | if (argc >= 1) { |
| 487 | /* use the BTS number that the user has specified */ |
| 488 | bts_nr = atoi(argv[0]); |
| 489 | if (bts_nr >= net->num_bts) { |
| 490 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 491 | VTY_NEWLINE); |
| 492 | return CMD_WARNING; |
| 493 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 494 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 495 | } |
| 496 | if (argc >= 2) { |
| 497 | trx_nr = atoi(argv[1]); |
| 498 | if (trx_nr >= bts->num_trx) { |
| 499 | vty_out(vty, "%% can't find TRX %s%s", argv[1], |
| 500 | VTY_NEWLINE); |
| 501 | return CMD_WARNING; |
| 502 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 503 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 504 | } |
| 505 | if (argc >= 3) { |
| 506 | ts_nr = atoi(argv[2]); |
| 507 | if (ts_nr >= TRX_NR_TS) { |
| 508 | vty_out(vty, "%% can't find TS %s%s", argv[2], |
| 509 | VTY_NEWLINE); |
| 510 | return CMD_WARNING; |
| 511 | } |
| 512 | ts = &trx->ts[ts_nr]; |
| 513 | } |
| 514 | if (argc >= 4) { |
| 515 | lchan_nr = atoi(argv[3]); |
| 516 | if (lchan_nr >= TS_MAX_LCHAN) { |
| 517 | vty_out(vty, "%% can't find LCHAN %s%s", argv[3], |
| 518 | VTY_NEWLINE); |
| 519 | return CMD_WARNING; |
| 520 | } |
| 521 | lchan = &ts->lchan[lchan_nr]; |
| 522 | lchan_dump_vty(vty, lchan); |
| 523 | return CMD_SUCCESS; |
| 524 | } |
| 525 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 526 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 527 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 528 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 529 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 530 | ts = &trx->ts[ts_nr]; |
| 531 | for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; |
| 532 | lchan_nr++) { |
| 533 | lchan = &ts->lchan[lchan_nr]; |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 534 | if (lchan->type == GSM_LCHAN_NONE) |
| 535 | continue; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 536 | lchan_dump_vty(vty, lchan); |
| 537 | } |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | return CMD_SUCCESS; |
| 543 | } |
| 544 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 545 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 546 | { |
| 547 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 548 | } |
| 549 | |
| 550 | DEFUN(show_e1drv, |
| 551 | show_e1drv_cmd, |
| 552 | "show e1_driver", |
| 553 | SHOW_STR "Display information about available E1 drivers\n") |
| 554 | { |
| 555 | struct e1inp_driver *drv; |
| 556 | |
| 557 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 558 | e1drv_dump_vty(vty, drv); |
| 559 | |
| 560 | return CMD_SUCCESS; |
| 561 | } |
| 562 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 563 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line) |
| 564 | { |
| 565 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 566 | line->num, line->name ? line->name : "", |
| 567 | line->driver->name, VTY_NEWLINE); |
| 568 | } |
| 569 | |
| 570 | DEFUN(show_e1line, |
| 571 | show_e1line_cmd, |
| 572 | "show e1_line [line_nr]", |
| 573 | SHOW_STR "Display information about a E1 line\n") |
| 574 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 575 | struct e1inp_line *line; |
| 576 | |
| 577 | if (argc >= 1) { |
| 578 | int num = atoi(argv[0]); |
| 579 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 580 | if (line->num == num) { |
| 581 | e1line_dump_vty(vty, line); |
| 582 | return CMD_SUCCESS; |
| 583 | } |
| 584 | } |
| 585 | return CMD_WARNING; |
| 586 | } |
| 587 | |
| 588 | llist_for_each_entry(line, &e1inp_line_list, list) |
| 589 | e1line_dump_vty(vty, line); |
| 590 | |
| 591 | return CMD_SUCCESS; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 595 | { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 596 | if (ts->type == E1INP_TS_TYPE_NONE) |
| 597 | return; |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 598 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 599 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 600 | VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | DEFUN(show_e1ts, |
| 604 | show_e1ts_cmd, |
| 605 | "show e1_timeslot [line_nr] [ts_nr]", |
| 606 | SHOW_STR "Display information about a E1 timeslot\n") |
| 607 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 608 | struct e1inp_line *line; |
| 609 | struct e1inp_ts *ts; |
| 610 | int ts_nr; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 611 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 612 | if (argc == 0) { |
| 613 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 614 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 615 | ts = &line->ts[ts_nr]; |
| 616 | e1ts_dump_vty(vty, ts); |
| 617 | } |
| 618 | } |
| 619 | return CMD_SUCCESS; |
| 620 | } |
| 621 | if (argc >= 1) { |
| 622 | int num = atoi(argv[0]); |
| 623 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 624 | if (line->num == num) |
| 625 | break; |
| 626 | } |
| 627 | if (!line || line->num != num) { |
| 628 | vty_out(vty, "E1 line %s is invalid%s", |
| 629 | argv[0], VTY_NEWLINE); |
| 630 | return CMD_WARNING; |
| 631 | } |
| 632 | } |
| 633 | if (argc >= 2) { |
| 634 | ts_nr = atoi(argv[1]); |
| 635 | if (ts_nr > NUM_E1_TS) { |
| 636 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 637 | argv[1], VTY_NEWLINE); |
| 638 | return CMD_WARNING; |
| 639 | } |
| 640 | ts = &line->ts[ts_nr]; |
| 641 | e1ts_dump_vty(vty, ts); |
| 642 | return CMD_SUCCESS; |
| 643 | } else { |
| 644 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 645 | ts = &line->ts[ts_nr]; |
| 646 | e1ts_dump_vty(vty, ts); |
| 647 | } |
| 648 | return CMD_SUCCESS; |
| 649 | } |
| 650 | return CMD_SUCCESS; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Harald Welte | be4b730 | 2009-05-23 16:59:33 +0000 | [diff] [blame] | 653 | static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag) |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 654 | { |
| 655 | vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE); |
| 656 | subscr_dump_vty(vty, pag->subscr); |
| 657 | } |
| 658 | |
Harald Welte | be4b730 | 2009-05-23 16:59:33 +0000 | [diff] [blame] | 659 | static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts) |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 660 | { |
| 661 | struct gsm_paging_request *pag; |
| 662 | |
| 663 | llist_for_each_entry(pag, &bts->paging.pending_requests, entry) |
| 664 | paging_dump_vty(vty, pag); |
| 665 | } |
| 666 | |
| 667 | DEFUN(show_paging, |
| 668 | show_paging_cmd, |
| 669 | "show paging [bts_nr]", |
Harald Welte | be4b730 | 2009-05-23 16:59:33 +0000 | [diff] [blame] | 670 | SHOW_STR "Display information about paging reuqests of a BTS\n") |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 671 | { |
| 672 | struct gsm_network *net = gsmnet; |
| 673 | struct gsm_bts *bts; |
| 674 | int bts_nr; |
| 675 | |
| 676 | if (argc >= 1) { |
| 677 | /* use the BTS number that the user has specified */ |
| 678 | bts_nr = atoi(argv[0]); |
| 679 | if (bts_nr >= net->num_bts) { |
| 680 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 681 | VTY_NEWLINE); |
| 682 | return CMD_WARNING; |
| 683 | } |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 684 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 685 | bts_paging_dump_vty(vty, bts); |
| 686 | |
| 687 | return CMD_SUCCESS; |
| 688 | } |
| 689 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 690 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 691 | bts_paging_dump_vty(vty, bts); |
| 692 | } |
| 693 | |
| 694 | return CMD_SUCCESS; |
| 695 | } |
| 696 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 697 | /* per-subscriber configuration */ |
| 698 | DEFUN(cfg_subscr, |
| 699 | cfg_subscr_cmd, |
| 700 | "subscriber IMSI", |
| 701 | "Select a Subscriber to configure\n") |
| 702 | { |
| 703 | const char *imsi = argv[0]; |
| 704 | struct gsm_subscriber *subscr; |
| 705 | |
Harald Welte | 761e944 | 2009-07-23 19:21:02 +0200 | [diff] [blame] | 706 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 707 | if (!subscr) { |
| 708 | vty_out(vty, "%% No subscriber for IMSI %s%s", |
| 709 | imsi, VTY_NEWLINE); |
| 710 | return CMD_WARNING; |
| 711 | } |
| 712 | |
| 713 | vty->index = subscr; |
| 714 | vty->node = SUBSCR_NODE; |
| 715 | |
| 716 | return CMD_SUCCESS; |
| 717 | } |
| 718 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 719 | DEFUN(cfg_net, |
| 720 | cfg_net_cmd, |
| 721 | "network", |
| 722 | "Configure the GSM network") |
| 723 | { |
| 724 | vty->index = gsmnet; |
| 725 | vty->node = GSMNET_NODE; |
| 726 | |
| 727 | return CMD_SUCCESS; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | DEFUN(cfg_net_ncc, |
| 732 | cfg_net_ncc_cmd, |
| 733 | "network country code <1-999>", |
| 734 | "Set the GSM network country code") |
| 735 | { |
| 736 | gsmnet->country_code = atoi(argv[0]); |
| 737 | |
| 738 | return CMD_SUCCESS; |
| 739 | } |
| 740 | |
| 741 | DEFUN(cfg_net_mnc, |
| 742 | cfg_net_mnc_cmd, |
| 743 | "mobile network code <1-999>", |
| 744 | "Set the GSM mobile network code") |
| 745 | { |
| 746 | gsmnet->network_code = atoi(argv[0]); |
| 747 | |
| 748 | return CMD_SUCCESS; |
| 749 | } |
| 750 | |
| 751 | DEFUN(cfg_net_name_short, |
| 752 | cfg_net_name_short_cmd, |
| 753 | "short name NAME", |
| 754 | "Set the short GSM network name") |
| 755 | { |
| 756 | if (gsmnet->name_short) |
| 757 | talloc_free(gsmnet->name_short); |
| 758 | |
| 759 | gsmnet->name_short = talloc_strdup(gsmnet, argv[0]); |
| 760 | |
| 761 | return CMD_SUCCESS; |
| 762 | } |
| 763 | |
| 764 | DEFUN(cfg_net_name_long, |
| 765 | cfg_net_name_long_cmd, |
| 766 | "long name NAME", |
| 767 | "Set the long GSM network name") |
| 768 | { |
| 769 | if (gsmnet->name_long) |
| 770 | talloc_free(gsmnet->name_long); |
| 771 | |
| 772 | gsmnet->name_long = talloc_strdup(gsmnet, argv[0]); |
| 773 | |
| 774 | return CMD_SUCCESS; |
| 775 | } |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 776 | |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame^] | 777 | DEFUN(cfg_net_auth_policy, |
| 778 | cfg_net_auth_policy_cmd, |
| 779 | "auth policy (closed|accept-all|token)", |
| 780 | "Set the GSM network authentication policy\n") |
| 781 | { |
| 782 | enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]); |
| 783 | |
| 784 | gsmnet->auth_policy = policy; |
| 785 | |
| 786 | return CMD_SUCCESS; |
| 787 | } |
| 788 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 789 | /* per-BTS configuration */ |
| 790 | DEFUN(cfg_bts, |
| 791 | cfg_bts_cmd, |
| 792 | "bts BTS_NR", |
| 793 | "Select a BTS to configure\n") |
| 794 | { |
| 795 | int bts_nr = atoi(argv[0]); |
| 796 | struct gsm_bts *bts; |
| 797 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 798 | if (bts_nr > gsmnet->num_bts) { |
| 799 | vty_out(vty, "%% The next unused BTS number is %u%s", |
| 800 | gsmnet->num_bts, VTY_NEWLINE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 801 | return CMD_WARNING; |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 802 | } else if (bts_nr == gsmnet->num_bts) { |
| 803 | /* allocate a new one */ |
| 804 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN, |
| 805 | HARDCODED_TSC, HARDCODED_BSIC); |
| 806 | } else |
| 807 | bts = gsm_bts_num(gsmnet, bts_nr); |
| 808 | |
| 809 | if (!bts) |
| 810 | return CMD_WARNING; |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 811 | |
| 812 | vty->index = bts; |
| 813 | vty->node = BTS_NODE; |
| 814 | |
| 815 | return CMD_SUCCESS; |
| 816 | } |
| 817 | |
| 818 | DEFUN(cfg_bts_type, |
| 819 | cfg_bts_type_cmd, |
| 820 | "type TYPE", |
| 821 | "Set the BTS type\n") |
| 822 | { |
| 823 | struct gsm_bts *bts = vty->index; |
| 824 | |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 825 | bts->type = parse_btstype(argv[0]); |
| 826 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 827 | return CMD_SUCCESS; |
| 828 | } |
| 829 | |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 830 | DEFUN(cfg_bts_band, |
| 831 | cfg_bts_band_cmd, |
| 832 | "band BAND", |
| 833 | "Set the frequency band of this BTS\n") |
| 834 | { |
| 835 | struct gsm_bts *bts = vty->index; |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 836 | int band = gsm_band_parse(argv[0]); |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 837 | |
| 838 | if (band < 0) { |
| 839 | vty_out(vty, "%% BAND %d is not a valid GSM band%s", |
| 840 | band, VTY_NEWLINE); |
| 841 | return CMD_WARNING; |
| 842 | } |
| 843 | |
| 844 | bts->band = band; |
| 845 | |
| 846 | return CMD_SUCCESS; |
| 847 | } |
| 848 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 849 | DEFUN(cfg_bts_lac, |
| 850 | cfg_bts_lac_cmd, |
| 851 | "location_area_code <0-255>", |
| 852 | "Set the Location Area Code (LAC) of this BTS\n") |
| 853 | { |
| 854 | struct gsm_bts *bts = vty->index; |
| 855 | int lac = atoi(argv[0]); |
| 856 | |
| 857 | if (lac < 0 || lac > 0xff) { |
| 858 | vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s", |
| 859 | lac, VTY_NEWLINE); |
| 860 | return CMD_WARNING; |
| 861 | } |
| 862 | bts->location_area_code = lac; |
| 863 | |
| 864 | return CMD_SUCCESS; |
| 865 | } |
| 866 | |
| 867 | DEFUN(cfg_bts_tsc, |
| 868 | cfg_bts_tsc_cmd, |
| 869 | "training_sequence_code <0-255>", |
| 870 | "Set the Training Sequence Code (TSC) of this BTS\n") |
| 871 | { |
| 872 | struct gsm_bts *bts = vty->index; |
| 873 | int tsc = atoi(argv[0]); |
| 874 | |
| 875 | if (tsc < 0 || tsc > 0xff) { |
| 876 | vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s", |
| 877 | tsc, VTY_NEWLINE); |
| 878 | return CMD_WARNING; |
| 879 | } |
| 880 | bts->tsc = tsc; |
| 881 | |
| 882 | return CMD_SUCCESS; |
| 883 | } |
| 884 | |
Harald Welte | 78f2f50 | 2009-05-23 16:56:52 +0000 | [diff] [blame] | 885 | DEFUN(cfg_bts_bsic, |
| 886 | cfg_bts_bsic_cmd, |
| 887 | "base_station_id_code <0-63>", |
| 888 | "Set the Base Station Identity Code (BSIC) of this BTS\n") |
| 889 | { |
| 890 | struct gsm_bts *bts = vty->index; |
| 891 | int bsic = atoi(argv[0]); |
| 892 | |
| 893 | if (bsic < 0 || bsic > 0x3f) { |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 894 | vty_out(vty, "%% BSIC %d is not in the valid range (0-255)%s", |
Harald Welte | 78f2f50 | 2009-05-23 16:56:52 +0000 | [diff] [blame] | 895 | bsic, VTY_NEWLINE); |
| 896 | return CMD_WARNING; |
| 897 | } |
| 898 | bts->bsic = bsic; |
| 899 | |
| 900 | return CMD_SUCCESS; |
| 901 | } |
| 902 | |
| 903 | |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 904 | DEFUN(cfg_bts_unit_id, |
| 905 | cfg_bts_unit_id_cmd, |
Harald Welte | 07dc73d | 2009-08-07 13:27:09 +0200 | [diff] [blame] | 906 | "ip.access unit_id <0-65534> <0-255>", |
| 907 | "Set the ip.access BTS Unit ID of this BTS\n") |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 908 | { |
| 909 | struct gsm_bts *bts = vty->index; |
| 910 | int site_id = atoi(argv[0]); |
| 911 | int bts_id = atoi(argv[1]); |
| 912 | |
Harald Welte | 07dc73d | 2009-08-07 13:27:09 +0200 | [diff] [blame] | 913 | if (!is_ipaccess_bts(bts)) { |
| 914 | vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE); |
| 915 | return CMD_WARNING; |
| 916 | } |
| 917 | |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 918 | bts->ip_access.site_id = site_id; |
| 919 | bts->ip_access.bts_id = bts_id; |
| 920 | |
| 921 | return CMD_SUCCESS; |
| 922 | } |
| 923 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 924 | DEFUN(cfg_bts_oml_e1, |
| 925 | cfg_bts_oml_e1_cmd, |
| 926 | "oml e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)", |
| 927 | "E1 interface to be used for OML\n") |
| 928 | { |
| 929 | struct gsm_bts *bts = vty->index; |
| 930 | |
| 931 | parse_e1_link(&bts->oml_e1_link, argv[0], argv[1], argv[2]); |
| 932 | |
| 933 | return CMD_SUCCESS; |
| 934 | } |
| 935 | |
| 936 | |
| 937 | DEFUN(cfg_bts_oml_e1_tei, |
| 938 | cfg_bts_oml_e1_tei_cmd, |
| 939 | "oml e1 tei <0-63>", |
| 940 | "Set the TEI to be used for OML") |
| 941 | { |
| 942 | struct gsm_bts *bts = vty->index; |
| 943 | |
| 944 | bts->oml_tei = atoi(argv[0]); |
| 945 | |
| 946 | return CMD_SUCCESS; |
| 947 | } |
| 948 | |
Harald Welte | 7a8fa41 | 2009-08-10 13:48:16 +0200 | [diff] [blame] | 949 | DEFUN(cfg_bts_challoc, cfg_bts_challoc_cmd, |
| 950 | "channel allocator (ascending|descending)", |
| 951 | "Should the channel allocator allocate in reverse TRX order?") |
| 952 | { |
| 953 | struct gsm_bts *bts = vty->index; |
| 954 | |
| 955 | if (!strcmp(argv[0], "ascending")) |
| 956 | bts->chan_alloc_reverse = 0; |
| 957 | else |
| 958 | bts->chan_alloc_reverse = 1; |
| 959 | |
| 960 | return CMD_SUCCESS; |
| 961 | } |
| 962 | |
| 963 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 964 | /* per TRX configuration */ |
| 965 | DEFUN(cfg_trx, |
| 966 | cfg_trx_cmd, |
| 967 | "trx TRX_NR", |
| 968 | "Select a TRX to configure") |
| 969 | { |
| 970 | int trx_nr = atoi(argv[0]); |
| 971 | struct gsm_bts *bts = vty->index; |
| 972 | struct gsm_bts_trx *trx; |
| 973 | |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 974 | if (trx_nr > bts->num_trx) { |
| 975 | vty_out(vty, "%% The next unused TRX number in this BTS is %u%s", |
| 976 | bts->num_trx, VTY_NEWLINE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 977 | return CMD_WARNING; |
Harald Welte | e441d9c | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 978 | } else if (trx_nr == bts->num_trx) { |
| 979 | /* we need to allocate a new one */ |
| 980 | trx = gsm_bts_trx_alloc(bts); |
| 981 | } else |
| 982 | trx = gsm_bts_trx_num(bts, trx_nr); |
| 983 | |
| 984 | if (!trx) |
| 985 | return CMD_WARNING; |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 986 | |
| 987 | vty->index = trx; |
| 988 | vty->node = TRX_NODE; |
| 989 | |
| 990 | return CMD_SUCCESS; |
| 991 | } |
| 992 | |
| 993 | DEFUN(cfg_trx_arfcn, |
| 994 | cfg_trx_arfcn_cmd, |
| 995 | "arfcn <1-1024>", |
| 996 | "Set the ARFCN for this TRX\n") |
| 997 | { |
| 998 | int arfcn = atoi(argv[0]); |
| 999 | struct gsm_bts_trx *trx = vty->index; |
| 1000 | |
| 1001 | /* FIXME: check if this ARFCN is supported by this TRX */ |
| 1002 | |
| 1003 | trx->arfcn = arfcn; |
| 1004 | |
| 1005 | /* FIXME: patch ARFCN into SYSTEM INFORMATION */ |
| 1006 | /* FIXME: use OML layer to update the ARFCN */ |
| 1007 | /* FIXME: use RSL layer to update SYSTEM INFORMATION */ |
| 1008 | |
| 1009 | return CMD_SUCCESS; |
| 1010 | } |
| 1011 | |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 1012 | DEFUN(cfg_trx_max_power_red, |
| 1013 | cfg_trx_max_power_red_cmd, |
| 1014 | "max_power_red <0-100>", |
| 1015 | "Reduction of maximum BS RF Power in dB\n") |
| 1016 | { |
| 1017 | int maxpwr_r = atoi(argv[0]); |
| 1018 | struct gsm_bts_trx *trx = vty->index; |
| 1019 | int upper_limit = 12; /* default 12.21 max power red. */ |
| 1020 | |
| 1021 | /* FIXME: check if our BTS type supports more than 12 */ |
| 1022 | if (maxpwr_r < 0 || maxpwr_r > upper_limit) { |
| 1023 | vty_out(vty, "%% Power %d dB is not in the valid range%s", |
| 1024 | maxpwr_r, VTY_NEWLINE); |
| 1025 | return CMD_WARNING; |
| 1026 | } |
| 1027 | if (maxpwr_r & 1) { |
| 1028 | vty_out(vty, "%% Power %d dB is not an even value%s", |
| 1029 | maxpwr_r, VTY_NEWLINE); |
| 1030 | return CMD_WARNING; |
| 1031 | } |
| 1032 | |
| 1033 | trx->max_power_red = maxpwr_r; |
| 1034 | |
| 1035 | /* FIXME: make sure we update this using OML */ |
| 1036 | |
| 1037 | return CMD_SUCCESS; |
| 1038 | } |
| 1039 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1040 | DEFUN(cfg_trx_rsl_e1, |
| 1041 | cfg_trx_rsl_e1_cmd, |
| 1042 | "rsl e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)", |
| 1043 | "E1 interface to be used for RSL\n") |
| 1044 | { |
| 1045 | struct gsm_bts_trx *trx = vty->index; |
| 1046 | |
| 1047 | parse_e1_link(&trx->rsl_e1_link, argv[0], argv[1], argv[2]); |
| 1048 | |
| 1049 | return CMD_SUCCESS; |
| 1050 | } |
| 1051 | |
| 1052 | DEFUN(cfg_trx_rsl_e1_tei, |
| 1053 | cfg_trx_rsl_e1_tei_cmd, |
| 1054 | "rsl e1 tei <0-63>", |
| 1055 | "Set the TEI to be used for RSL") |
| 1056 | { |
| 1057 | struct gsm_bts_trx *trx = vty->index; |
| 1058 | |
| 1059 | trx->rsl_tei = atoi(argv[0]); |
| 1060 | |
| 1061 | return CMD_SUCCESS; |
| 1062 | } |
| 1063 | |
| 1064 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1065 | /* per TS configuration */ |
| 1066 | DEFUN(cfg_ts, |
| 1067 | cfg_ts_cmd, |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1068 | "timeslot <0-7>", |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1069 | "Select a Timeslot to configure") |
| 1070 | { |
| 1071 | int ts_nr = atoi(argv[0]); |
| 1072 | struct gsm_bts_trx *trx = vty->index; |
| 1073 | struct gsm_bts_trx_ts *ts; |
| 1074 | |
| 1075 | if (ts_nr >= TRX_NR_TS) { |
| 1076 | vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s", |
| 1077 | TRX_NR_TS, VTY_NEWLINE); |
| 1078 | return CMD_WARNING; |
| 1079 | } |
| 1080 | |
| 1081 | ts = &trx->ts[ts_nr]; |
| 1082 | |
| 1083 | vty->index = ts; |
| 1084 | vty->node = TS_NODE; |
| 1085 | |
| 1086 | return CMD_SUCCESS; |
| 1087 | } |
| 1088 | |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 1089 | DEFUN(cfg_ts_pchan, |
| 1090 | cfg_ts_pchan_cmd, |
| 1091 | "phys_chan_config PCHAN", |
| 1092 | "Physical Channel configuration (TCH/SDCCH/...)") |
| 1093 | { |
| 1094 | struct gsm_bts_trx_ts *ts = vty->index; |
| 1095 | int pchanc; |
| 1096 | |
| 1097 | pchanc = gsm_pchan_parse(argv[0]); |
| 1098 | if (pchanc < 0) |
| 1099 | return CMD_WARNING; |
| 1100 | |
| 1101 | ts->pchan = pchanc; |
| 1102 | |
| 1103 | return CMD_SUCCESS; |
| 1104 | } |
| 1105 | |
| 1106 | DEFUN(cfg_ts_e1_subslot, |
| 1107 | cfg_ts_e1_subslot_cmd, |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1108 | "e1 line E1_LINE timeslot <1-31> sub-slot (0|1|2|3|full)", |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 1109 | "E1 sub-slot connected to this on-air timeslot") |
| 1110 | { |
| 1111 | struct gsm_bts_trx_ts *ts = vty->index; |
| 1112 | |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1113 | parse_e1_link(&ts->e1_link, argv[0], argv[1], argv[2]); |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 1114 | |
| 1115 | return CMD_SUCCESS; |
| 1116 | } |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1117 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 1118 | /* Subscriber */ |
| 1119 | DEFUN(show_subscr, |
| 1120 | show_subscr_cmd, |
| 1121 | "show subscriber [IMSI]", |
| 1122 | SHOW_STR "Display information about a subscriber\n") |
| 1123 | { |
| 1124 | const char *imsi; |
| 1125 | struct gsm_subscriber *subscr; |
| 1126 | |
| 1127 | if (argc >= 1) { |
| 1128 | imsi = argv[0]; |
Harald Welte | 761e944 | 2009-07-23 19:21:02 +0200 | [diff] [blame] | 1129 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 1130 | if (!subscr) { |
| 1131 | vty_out(vty, "%% unknown subscriber%s", |
| 1132 | VTY_NEWLINE); |
| 1133 | return CMD_WARNING; |
| 1134 | } |
| 1135 | subscr_dump_vty(vty, subscr); |
| 1136 | |
| 1137 | return CMD_SUCCESS; |
| 1138 | } |
| 1139 | |
| 1140 | /* FIXME: iterate over all subscribers ? */ |
| 1141 | return CMD_WARNING; |
| 1142 | |
| 1143 | return CMD_SUCCESS; |
| 1144 | } |
| 1145 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1146 | DEFUN(sms_send_pend, |
| 1147 | sms_send_pend_cmd, |
| 1148 | "sms send pending MIN_ID", |
| 1149 | "Send all pending SMS starting from MIN_ID") |
| 1150 | { |
| 1151 | struct gsm_sms *sms; |
| 1152 | |
| 1153 | sms = db_sms_get_unsent(gsmnet, atoi(argv[0])); |
| 1154 | if (!sms) |
| 1155 | return CMD_WARNING; |
| 1156 | |
| 1157 | if (!sms->receiver) { |
| 1158 | sms_free(sms); |
| 1159 | return CMD_WARNING; |
| 1160 | } |
| 1161 | |
| 1162 | gsm411_send_sms_subscr(sms->receiver, sms); |
| 1163 | |
| 1164 | return CMD_SUCCESS; |
| 1165 | } |
| 1166 | |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1167 | static struct buffer *argv_to_buffer(int argc, const char *argv[], int base) |
| 1168 | { |
| 1169 | struct buffer *b = buffer_new(1024); |
| 1170 | int i; |
| 1171 | |
| 1172 | if (!b) |
| 1173 | return NULL; |
| 1174 | |
| 1175 | for (i = base; i < argc; i++) { |
| 1176 | buffer_putstr(b, argv[i]); |
| 1177 | buffer_putc(b, ' '); |
| 1178 | } |
| 1179 | buffer_putc(b, '\0'); |
| 1180 | |
| 1181 | return b; |
| 1182 | } |
| 1183 | |
| 1184 | static int _send_sms_buffer(struct gsm_subscriber *receiver, |
| 1185 | struct buffer *b) |
| 1186 | { |
| 1187 | struct gsm_sms *sms = sms_alloc(); |
| 1188 | |
| 1189 | if (!sms) |
| 1190 | return CMD_WARNING; |
| 1191 | |
| 1192 | if (!receiver->lac) { |
| 1193 | /* subscriber currently not attached, store in database? */ |
| 1194 | subscr_put(sms->receiver); |
| 1195 | return CMD_WARNING; |
| 1196 | } |
| 1197 | |
| 1198 | sms->receiver = receiver; |
| 1199 | strncpy(sms->text, buffer_getstr(b), sizeof(sms->text)-1); |
| 1200 | |
| 1201 | /* FIXME: don't use ID 1 static */ |
| 1202 | sms->sender = subscr_get_by_id(gsmnet, 1); |
| 1203 | sms->reply_path_req = 0; |
| 1204 | sms->status_rep_req = 0; |
| 1205 | sms->ud_hdr_ind = 0; |
| 1206 | sms->protocol_id = 0; /* implicit */ |
| 1207 | sms->data_coding_scheme = 0; /* default 7bit */ |
| 1208 | strncpy(sms->dest_addr, receiver->extension, sizeof(sms->dest_addr)-1); |
| 1209 | /* Generate user_data */ |
| 1210 | sms->user_data_len = gsm_7bit_encode(sms->user_data, sms->text); |
| 1211 | |
| 1212 | gsm411_send_sms_subscr(sms->receiver, sms); |
| 1213 | |
| 1214 | return CMD_SUCCESS; |
| 1215 | } |
| 1216 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1217 | DEFUN(sms_send_ext, |
| 1218 | sms_send_ext_cmd, |
| 1219 | "sms send extension EXTEN .LINE", |
| 1220 | "Send a message to a subscriber identified by EXTEN") |
| 1221 | { |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1222 | struct gsm_subscriber *receiver; |
| 1223 | struct buffer *b; |
| 1224 | int rc; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1225 | |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1226 | receiver = subscr_get_by_extension(gsmnet, argv[0]); |
| 1227 | if (!receiver) |
| 1228 | return CMD_WARNING; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1229 | |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1230 | b = argv_to_buffer(argc, argv, 1); |
| 1231 | rc = _send_sms_buffer(receiver, b); |
| 1232 | buffer_free(b); |
| 1233 | |
| 1234 | return rc; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | DEFUN(sms_send_imsi, |
| 1238 | sms_send_imsi_cmd, |
| 1239 | "sms send imsi IMSI .LINE", |
| 1240 | "Send a message to a subscriber identified by IMSI") |
| 1241 | { |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1242 | struct gsm_subscriber *receiver; |
| 1243 | struct buffer *b; |
| 1244 | int rc; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1245 | |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1246 | receiver = subscr_get_by_imsi(gsmnet, argv[0]); |
| 1247 | if (!receiver) |
| 1248 | return CMD_WARNING; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1249 | |
Harald Welte | f9daefd | 2009-08-09 15:13:54 +0200 | [diff] [blame] | 1250 | b = argv_to_buffer(argc, argv, 1); |
| 1251 | rc = _send_sms_buffer(receiver, b); |
| 1252 | buffer_free(b); |
| 1253 | |
| 1254 | return rc; |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 1258 | DEFUN(cfg_subscr_name, |
| 1259 | cfg_subscr_name_cmd, |
| 1260 | "name NAME", |
| 1261 | "Set the name of the subscriber") |
| 1262 | { |
| 1263 | const char *name = argv[0]; |
| 1264 | struct gsm_subscriber *subscr = vty->index; |
| 1265 | |
| 1266 | strncpy(subscr->name, name, sizeof(subscr->name)); |
| 1267 | |
| 1268 | db_sync_subscriber(subscr); |
| 1269 | |
| 1270 | return CMD_SUCCESS; |
| 1271 | } |
| 1272 | |
| 1273 | DEFUN(cfg_subscr_extension, |
| 1274 | cfg_subscr_extension_cmd, |
| 1275 | "extension EXTENSION", |
| 1276 | "Set the extension of the subscriber") |
| 1277 | { |
| 1278 | const char *name = argv[0]; |
| 1279 | struct gsm_subscriber *subscr = vty->index; |
| 1280 | |
| 1281 | strncpy(subscr->extension, name, sizeof(subscr->extension)); |
| 1282 | |
| 1283 | db_sync_subscriber(subscr); |
| 1284 | |
| 1285 | return CMD_SUCCESS; |
| 1286 | } |
| 1287 | |
| 1288 | DEFUN(cfg_subscr_authorized, |
| 1289 | cfg_subscr_authorized_cmd, |
| 1290 | "auth <0-1>", |
| 1291 | "Set the authorization status of the subscriber") |
| 1292 | { |
| 1293 | int auth = atoi(argv[0]); |
| 1294 | struct gsm_subscriber *subscr = vty->index; |
| 1295 | |
| 1296 | if (auth) |
| 1297 | subscr->authorized = 1; |
| 1298 | else |
| 1299 | subscr->authorized = 0; |
| 1300 | |
| 1301 | db_sync_subscriber(subscr); |
| 1302 | |
| 1303 | return CMD_SUCCESS; |
| 1304 | } |
| 1305 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1306 | int bsc_vty_init(struct gsm_network *net) |
| 1307 | { |
| 1308 | gsmnet = net; |
| 1309 | |
| 1310 | cmd_init(1); |
| 1311 | vty_init(); |
| 1312 | |
| 1313 | install_element(VIEW_NODE, &show_net_cmd); |
| 1314 | install_element(VIEW_NODE, &show_bts_cmd); |
| 1315 | install_element(VIEW_NODE, &show_trx_cmd); |
| 1316 | install_element(VIEW_NODE, &show_ts_cmd); |
| 1317 | install_element(VIEW_NODE, &show_lchan_cmd); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 1318 | |
| 1319 | install_element(VIEW_NODE, &show_e1drv_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1320 | install_element(VIEW_NODE, &show_e1line_cmd); |
| 1321 | install_element(VIEW_NODE, &show_e1ts_cmd); |
| 1322 | |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 1323 | install_element(VIEW_NODE, &show_paging_cmd); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1324 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 1325 | install_element(VIEW_NODE, &show_subscr_cmd); |
| 1326 | |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1327 | install_element(VIEW_NODE, &sms_send_pend_cmd); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1328 | install_element(VIEW_NODE, &sms_send_ext_cmd); |
| 1329 | install_element(VIEW_NODE, &sms_send_imsi_cmd); |
Harald Welte | 7604218 | 2009-08-08 16:03:15 +0200 | [diff] [blame] | 1330 | |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 1331 | install_element(CONFIG_NODE, &cfg_net_cmd); |
| 1332 | install_node(&net_node, config_write_net); |
| 1333 | install_default(GSMNET_NODE); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1334 | install_element(GSMNET_NODE, &cfg_net_ncc_cmd); |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 1335 | install_element(GSMNET_NODE, &cfg_net_mnc_cmd); |
| 1336 | install_element(GSMNET_NODE, &cfg_net_name_short_cmd); |
| 1337 | install_element(GSMNET_NODE, &cfg_net_name_long_cmd); |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame^] | 1338 | install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd); |
Harald Welte | 5013b2a | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 1339 | |
| 1340 | install_element(GSMNET_NODE, &cfg_bts_cmd); |
Harald Welte | 67ce073 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 1341 | install_node(&bts_node, config_write_bts); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1342 | install_default(BTS_NODE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1343 | install_element(BTS_NODE, &cfg_bts_type_cmd); |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 1344 | install_element(BTS_NODE, &cfg_bts_band_cmd); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1345 | install_element(BTS_NODE, &cfg_bts_lac_cmd); |
| 1346 | install_element(BTS_NODE, &cfg_bts_tsc_cmd); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1347 | install_element(BTS_NODE, &cfg_bts_bsic_cmd); |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 1348 | install_element(BTS_NODE, &cfg_bts_unit_id_cmd); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1349 | install_element(BTS_NODE, &cfg_bts_oml_e1_cmd); |
| 1350 | install_element(BTS_NODE, &cfg_bts_oml_e1_tei_cmd); |
Harald Welte | 7a8fa41 | 2009-08-10 13:48:16 +0200 | [diff] [blame] | 1351 | install_element(BTS_NODE, &cfg_bts_challoc_cmd); |
| 1352 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1353 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1354 | install_element(BTS_NODE, &cfg_trx_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1355 | install_node(&trx_node, dummy_config_write); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1356 | install_default(TRX_NODE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1357 | install_element(TRX_NODE, &cfg_trx_arfcn_cmd); |
Harald Welte | 879dc97 | 2009-06-20 22:36:12 +0200 | [diff] [blame] | 1358 | install_element(TRX_NODE, &cfg_trx_max_power_red_cmd); |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 1359 | install_element(TRX_NODE, &cfg_trx_rsl_e1_cmd); |
| 1360 | install_element(TRX_NODE, &cfg_trx_rsl_e1_tei_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1361 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 1362 | install_element(TRX_NODE, &cfg_ts_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1363 | install_node(&ts_node, dummy_config_write); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1364 | install_default(TS_NODE); |
Harald Welte | a6fd58e | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 1365 | install_element(TS_NODE, &cfg_ts_pchan_cmd); |
| 1366 | install_element(TS_NODE, &cfg_ts_e1_subslot_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1367 | |
Harald Welte | 40f8289 | 2009-05-23 17:31:39 +0000 | [diff] [blame] | 1368 | install_element(CONFIG_NODE, &cfg_subscr_cmd); |
| 1369 | install_node(&subscr_node, dummy_config_write); |
| 1370 | install_default(SUBSCR_NODE); |
| 1371 | install_element(SUBSCR_NODE, &cfg_subscr_name_cmd); |
| 1372 | install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd); |
| 1373 | install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd); |
| 1374 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 1375 | return 0; |
| 1376 | } |