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