Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [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> |
| 26 | #include <vty/vty.h> |
| 27 | |
| 28 | #include <arpa/inet.h> |
| 29 | |
| 30 | #include <openbsc/linuxlist.h> |
| 31 | #include <openbsc/gsm_data.h> |
| 32 | #include <openbsc/gsm_subscriber.h> |
| 33 | #include <openbsc/e1_input.h> |
| 34 | #include <openbsc/abis_nm.h> |
| 35 | #include <openbsc/db.h> |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 36 | #include <openbsc/talloc.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 37 | |
| 38 | static struct gsm_network *gsmnet; |
| 39 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 40 | struct cmd_node net_node = { |
| 41 | GSMNET_NODE, |
| 42 | "%s(network)#", |
| 43 | 1, |
| 44 | }; |
| 45 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 46 | struct cmd_node bts_node = { |
| 47 | BTS_NODE, |
| 48 | "%s(bts)#", |
| 49 | 1, |
| 50 | }; |
| 51 | |
| 52 | struct cmd_node trx_node = { |
| 53 | TRX_NODE, |
| 54 | "%s(trx)#", |
| 55 | 1, |
| 56 | }; |
| 57 | |
| 58 | struct cmd_node ts_node = { |
| 59 | TS_NODE, |
| 60 | "%s(ts)#", |
| 61 | 1, |
| 62 | }; |
| 63 | |
| 64 | struct cmd_node subscr_node = { |
| 65 | SUBSCR_NODE, |
| 66 | "%s(subscriber)#", |
| 67 | 1, |
| 68 | }; |
| 69 | |
| 70 | static int dummy_config_write(struct vty *v) |
| 71 | { |
| 72 | return CMD_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms) |
| 76 | { |
| 77 | vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s", |
| 78 | nm_opstate_name(nms->operational), nms->administrative, |
| 79 | nm_avail_name(nms->availability), VTY_NEWLINE); |
| 80 | } |
| 81 | |
| 82 | static void net_dump_vty(struct vty *vty, struct gsm_network *net) |
| 83 | { |
| 84 | vty_out(vty, "BSC is on Country Code %u, Network Code %u " |
| 85 | "and has %u BTS%s", net->country_code, net->network_code, |
| 86 | net->num_bts, VTY_NEWLINE); |
| 87 | vty_out(vty, " Long network name: '%s'%s", |
| 88 | net->name_long, VTY_NEWLINE); |
| 89 | vty_out(vty, " Short network name: '%s'%s", |
| 90 | net->name_short, VTY_NEWLINE); |
| 91 | } |
| 92 | |
| 93 | DEFUN(show_net, show_net_cmd, "show network", |
| 94 | SHOW_STR "Display information about a GSM NETWORK\n") |
| 95 | { |
| 96 | struct gsm_network *net = gsmnet; |
| 97 | net_dump_vty(vty, net); |
| 98 | |
| 99 | return CMD_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l) |
| 103 | { |
| 104 | struct e1inp_line *line; |
| 105 | |
| 106 | if (!e1l) { |
| 107 | vty_out(vty, " None%s", VTY_NEWLINE); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | line = e1l->ts->line; |
| 112 | |
| 113 | vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s", |
| 114 | line->num, line->driver->name, e1l->ts->num, |
| 115 | e1inp_signtype_name(e1l->type), VTY_NEWLINE); |
| 116 | vty_out(vty, " E1 TEI %u, SAPI %u%s", |
| 117 | e1l->tei, e1l->sapi, VTY_NEWLINE); |
| 118 | } |
| 119 | |
| 120 | static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts) |
| 121 | { |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 122 | vty_out(vty, "BTS %u is of %s type in band %s, has LAC %u, " |
| 123 | "BSIC %u, TSC %u and %u TRX%s", |
| 124 | bts->nr, btstype2str(bts->type), gsm_band_name(bts->band), |
| 125 | bts->location_area_code, bts->bsic, bts->tsc, |
| 126 | bts->num_trx, VTY_NEWLINE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 127 | if (is_ipaccess_bts(bts)) |
| 128 | vty_out(vty, " Unit ID: %u/%u/0%s", |
| 129 | bts->ip_access.site_id, bts->ip_access.bts_id, |
| 130 | VTY_NEWLINE); |
| 131 | vty_out(vty, " NM State: "); |
| 132 | net_dump_nmstate(vty, &bts->nm_state); |
| 133 | vty_out(vty, " Site Mgr NM State: "); |
| 134 | net_dump_nmstate(vty, &bts->site_mgr.nm_state); |
| 135 | vty_out(vty, " Paging: FIXME pending requests, %u free slots%s", |
| 136 | bts->paging.available_slots, VTY_NEWLINE); |
| 137 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 138 | e1isl_dump_vty(vty, bts->oml_link); |
| 139 | /* FIXME: oml_link, chan_desc */ |
| 140 | } |
| 141 | |
| 142 | DEFUN(show_bts, show_bts_cmd, "show bts [number]", |
| 143 | SHOW_STR "Display information about a BTS\n" |
| 144 | "BTS number") |
| 145 | { |
| 146 | struct gsm_network *net = gsmnet; |
| 147 | int bts_nr; |
| 148 | |
| 149 | if (argc != 0) { |
| 150 | /* use the BTS number that the user has specified */ |
| 151 | bts_nr = atoi(argv[0]); |
| 152 | if (bts_nr > net->num_bts) { |
| 153 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
| 154 | VTY_NEWLINE); |
| 155 | return CMD_WARNING; |
| 156 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 157 | bts_dump_vty(vty, gsm_bts_num(net, bts_nr)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 158 | return CMD_SUCCESS; |
| 159 | } |
| 160 | /* print all BTS's */ |
| 161 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 162 | bts_dump_vty(vty, gsm_bts_num(net, bts_nr)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 163 | |
| 164 | return CMD_SUCCESS; |
| 165 | } |
| 166 | |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 167 | static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts) |
| 168 | { |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 169 | vty_out(vty, " ts %u%s", ts->nr, VTY_NEWLINE); |
| 170 | vty_out(vty, " phys_chan_config %s%s", gsm_pchan_name(ts->pchan), |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 171 | VTY_NEWLINE); |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 172 | vty_out(vty, " e1_subslot %u %u %u%s", ts->e1_link.e1_nr, |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 173 | ts->e1_link.e1_ts, ts->e1_link.e1_ts_ss, VTY_NEWLINE); |
| 174 | } |
| 175 | |
| 176 | static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx) |
| 177 | { |
| 178 | int i; |
| 179 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 180 | vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE); |
| 181 | vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE); |
| 182 | vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE); |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 183 | |
| 184 | for (i = 0; i < TRX_NR_TS; i++) |
| 185 | config_write_ts_single(vty, &trx->ts[i]); |
| 186 | } |
| 187 | |
| 188 | static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts) |
| 189 | { |
| 190 | struct gsm_bts_trx *trx; |
| 191 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 192 | vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE); |
| 193 | vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE); |
| 194 | vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE); |
| 195 | vty_out(vty, " location_area_code %u%s", bts->location_area_code, |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 196 | VTY_NEWLINE); |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 197 | vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE); |
| 198 | vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE); |
Harald Welte | 3ffe1b3 | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 199 | if (is_ipaccess_bts(bts)) |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 200 | vty_out(vty, " ip.access unit_id %u %u%s", |
Harald Welte | 3ffe1b3 | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 201 | bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE); |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 202 | |
| 203 | llist_for_each_entry(trx, &bts->trx_list, list) |
| 204 | config_write_trx_single(vty, trx); |
| 205 | } |
| 206 | |
| 207 | static int config_write_bts(struct vty *v) |
| 208 | { |
| 209 | struct gsm_bts *bts; |
| 210 | |
| 211 | llist_for_each_entry(bts, &gsmnet->bts_list, list) |
| 212 | config_write_bts_single(v, bts); |
| 213 | |
| 214 | return CMD_SUCCESS; |
| 215 | } |
| 216 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 217 | static int config_write_net(struct vty *vty) |
| 218 | { |
| 219 | vty_out(vty, "network%s", VTY_NEWLINE); |
| 220 | vty_out(vty, " country code %u%s", gsmnet->country_code, VTY_NEWLINE); |
| 221 | vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE); |
| 222 | vty_out(vty, " short name '%s'%s", gsmnet->name_short, VTY_NEWLINE); |
| 223 | vty_out(vty, " long name '%s'%s", gsmnet->name_long, VTY_NEWLINE); |
| 224 | |
| 225 | return CMD_SUCCESS; |
| 226 | } |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 227 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 228 | static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx) |
| 229 | { |
| 230 | vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s", |
| 231 | trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE); |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 232 | vty_out(vty, " RF Nominal Power: %d dBm, reduced by %u dB, " |
| 233 | "resulting BS power: %d dBm\n", |
| 234 | trx->nominal_power, trx->max_power_red, |
| 235 | trx->nominal_power - trx->max_power_red); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 236 | vty_out(vty, " NM State: "); |
| 237 | net_dump_nmstate(vty, &trx->nm_state); |
| 238 | vty_out(vty, " Baseband Transceiver NM State: "); |
| 239 | net_dump_nmstate(vty, &trx->bb_transc.nm_state); |
| 240 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 241 | e1isl_dump_vty(vty, trx->rsl_link); |
| 242 | } |
| 243 | |
| 244 | DEFUN(show_trx, |
| 245 | show_trx_cmd, |
| 246 | "show trx [bts_nr] [trx_nr]", |
| 247 | SHOW_STR "Display information about a TRX\n") |
| 248 | { |
| 249 | struct gsm_network *net = gsmnet; |
| 250 | struct gsm_bts *bts = NULL; |
| 251 | struct gsm_bts_trx *trx; |
| 252 | int bts_nr, trx_nr; |
| 253 | |
| 254 | if (argc >= 1) { |
| 255 | /* use the BTS number that the user has specified */ |
| 256 | bts_nr = atoi(argv[0]); |
| 257 | if (bts_nr >= net->num_bts) { |
| 258 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
| 259 | VTY_NEWLINE); |
| 260 | return CMD_WARNING; |
| 261 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 262 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 263 | } |
| 264 | if (argc >= 2) { |
| 265 | trx_nr = atoi(argv[1]); |
| 266 | if (trx_nr >= bts->num_trx) { |
| 267 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
| 268 | VTY_NEWLINE); |
| 269 | return CMD_WARNING; |
| 270 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 271 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 272 | trx_dump_vty(vty, trx); |
| 273 | return CMD_SUCCESS; |
| 274 | } |
| 275 | if (bts) { |
| 276 | /* print all TRX in this BTS */ |
| 277 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 278 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 279 | trx_dump_vty(vty, trx); |
| 280 | } |
| 281 | return CMD_SUCCESS; |
| 282 | } |
| 283 | |
| 284 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 285 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 286 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 287 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 288 | trx_dump_vty(vty, trx); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return CMD_SUCCESS; |
| 293 | } |
| 294 | |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 295 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 296 | static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts) |
| 297 | { |
| 298 | struct in_addr ia; |
| 299 | |
| 300 | vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s", |
| 301 | ts->nr, ts->trx->nr, ts->trx->bts->nr, |
| 302 | gsm_pchan_name(ts->pchan), VTY_NEWLINE); |
| 303 | vty_out(vty, " NM State: "); |
| 304 | net_dump_nmstate(vty, &ts->nm_state); |
| 305 | if (is_ipaccess_bts(ts->trx->bts)) { |
| 306 | ia.s_addr = ts->abis_ip.bound_ip; |
Harald Welte | 8cdeaad | 2009-07-12 09:50:35 +0200 | [diff] [blame] | 307 | vty_out(vty, " Bound IP: %s Port %u RTP_TYPE2=%u CONN_ID=%u%s", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 308 | inet_ntoa(ia), ts->abis_ip.bound_port, |
Harald Welte | 8cdeaad | 2009-07-12 09:50:35 +0200 | [diff] [blame] | 309 | ts->abis_ip.rtp_payload2, ts->abis_ip.conn_id, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 310 | VTY_NEWLINE); |
| 311 | } else { |
| 312 | vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s", |
| 313 | ts->e1_link.e1_nr, ts->e1_link.e1_ts, |
| 314 | ts->e1_link.e1_ts_ss, VTY_NEWLINE); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | DEFUN(show_ts, |
| 319 | show_ts_cmd, |
| 320 | "show timeslot [bts_nr] [trx_nr] [ts_nr]", |
| 321 | SHOW_STR "Display information about a TS\n") |
| 322 | { |
| 323 | struct gsm_network *net = gsmnet; |
| 324 | struct gsm_bts *bts; |
| 325 | struct gsm_bts_trx *trx; |
| 326 | struct gsm_bts_trx_ts *ts; |
| 327 | int bts_nr, trx_nr, ts_nr; |
| 328 | |
| 329 | if (argc >= 1) { |
| 330 | /* use the BTS number that the user has specified */ |
| 331 | bts_nr = atoi(argv[0]); |
| 332 | if (bts_nr >= net->num_bts) { |
| 333 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
| 334 | VTY_NEWLINE); |
| 335 | return CMD_WARNING; |
| 336 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 337 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 338 | } |
| 339 | if (argc >= 2) { |
| 340 | trx_nr = atoi(argv[1]); |
| 341 | if (trx_nr >= bts->num_trx) { |
| 342 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
| 343 | VTY_NEWLINE); |
| 344 | return CMD_WARNING; |
| 345 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 346 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 347 | } |
| 348 | if (argc >= 3) { |
| 349 | ts_nr = atoi(argv[2]); |
| 350 | if (ts_nr >= TRX_NR_TS) { |
| 351 | vty_out(vty, "%% can't find TS '%s'%s", argv[2], |
| 352 | VTY_NEWLINE); |
| 353 | return CMD_WARNING; |
| 354 | } |
| 355 | ts = &trx->ts[ts_nr]; |
| 356 | ts_dump_vty(vty, ts); |
| 357 | return CMD_SUCCESS; |
| 358 | } |
| 359 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 360 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 361 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 362 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 363 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 364 | ts = &trx->ts[ts_nr]; |
| 365 | ts_dump_vty(vty, ts); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | return CMD_SUCCESS; |
| 371 | } |
| 372 | |
| 373 | static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr) |
| 374 | { |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 375 | vty_out(vty, " ID: %llu, Authorized: %d%s", subscr->id, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 376 | subscr->authorized, VTY_NEWLINE); |
| 377 | if (subscr->name) |
| 378 | vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); |
| 379 | if (subscr->extension) |
| 380 | vty_out(vty, " Extension: %s%s", subscr->extension, |
| 381 | VTY_NEWLINE); |
| 382 | if (subscr->imsi) |
| 383 | vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); |
| 384 | if (subscr->tmsi) |
| 385 | vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE); |
| 386 | } |
| 387 | |
| 388 | static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan) |
| 389 | { |
| 390 | vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s", |
| 391 | lchan->nr, lchan->ts->nr, lchan->ts->trx->nr, |
| 392 | lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type), |
| 393 | VTY_NEWLINE); |
| 394 | vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE); |
| 395 | vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power, |
| 396 | lchan->ms_power, VTY_NEWLINE); |
| 397 | if (lchan->subscr) { |
| 398 | vty_out(vty, " Subscriber:%s", VTY_NEWLINE); |
| 399 | subscr_dump_vty(vty, lchan->subscr); |
| 400 | } else |
| 401 | vty_out(vty, " No Subscriber%s", VTY_NEWLINE); |
| 402 | } |
| 403 | |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 404 | #if 0 |
| 405 | TODO: callref and remote callref of call must be resolved to get gsm_trans object |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 406 | static void call_dump_vty(struct vty *vty, struct gsm_call *call) |
| 407 | { |
| 408 | vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s", |
| 409 | call->type, call->state, call->transaction_id, VTY_NEWLINE); |
| 410 | |
| 411 | if (call->local_lchan) { |
| 412 | vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE); |
| 413 | lchan_dump_vty(vty, call->local_lchan); |
| 414 | } else |
| 415 | vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE); |
| 416 | |
| 417 | if (call->remote_lchan) { |
| 418 | vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE); |
| 419 | lchan_dump_vty(vty, call->remote_lchan); |
| 420 | } else |
| 421 | vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE); |
| 422 | |
| 423 | if (call->called_subscr) { |
| 424 | vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE); |
| 425 | subscr_dump_vty(vty, call->called_subscr); |
| 426 | } else |
| 427 | vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE); |
| 428 | } |
Harald Welte | 0374084 | 2009-06-10 23:11:52 +0800 | [diff] [blame] | 429 | #endif |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 430 | |
| 431 | DEFUN(show_lchan, |
| 432 | show_lchan_cmd, |
| 433 | "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]", |
| 434 | SHOW_STR "Display information about a logical channel\n") |
| 435 | { |
| 436 | struct gsm_network *net = gsmnet; |
| 437 | struct gsm_bts *bts; |
| 438 | struct gsm_bts_trx *trx; |
| 439 | struct gsm_bts_trx_ts *ts; |
| 440 | struct gsm_lchan *lchan; |
| 441 | int bts_nr, trx_nr, ts_nr, lchan_nr; |
| 442 | |
| 443 | if (argc >= 1) { |
| 444 | /* use the BTS number that the user has specified */ |
| 445 | bts_nr = atoi(argv[0]); |
| 446 | if (bts_nr >= net->num_bts) { |
| 447 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 448 | VTY_NEWLINE); |
| 449 | return CMD_WARNING; |
| 450 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 451 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 452 | } |
| 453 | if (argc >= 2) { |
| 454 | trx_nr = atoi(argv[1]); |
| 455 | if (trx_nr >= bts->num_trx) { |
| 456 | vty_out(vty, "%% can't find TRX %s%s", argv[1], |
| 457 | VTY_NEWLINE); |
| 458 | return CMD_WARNING; |
| 459 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 460 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 461 | } |
| 462 | if (argc >= 3) { |
| 463 | ts_nr = atoi(argv[2]); |
| 464 | if (ts_nr >= TRX_NR_TS) { |
| 465 | vty_out(vty, "%% can't find TS %s%s", argv[2], |
| 466 | VTY_NEWLINE); |
| 467 | return CMD_WARNING; |
| 468 | } |
| 469 | ts = &trx->ts[ts_nr]; |
| 470 | } |
| 471 | if (argc >= 4) { |
| 472 | lchan_nr = atoi(argv[3]); |
| 473 | if (lchan_nr >= TS_MAX_LCHAN) { |
| 474 | vty_out(vty, "%% can't find LCHAN %s%s", argv[3], |
| 475 | VTY_NEWLINE); |
| 476 | return CMD_WARNING; |
| 477 | } |
| 478 | lchan = &ts->lchan[lchan_nr]; |
| 479 | lchan_dump_vty(vty, lchan); |
| 480 | return CMD_SUCCESS; |
| 481 | } |
| 482 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 483 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 484 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 485 | trx = gsm_bts_trx_num(bts, trx_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 486 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 487 | ts = &trx->ts[ts_nr]; |
| 488 | for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; |
| 489 | lchan_nr++) { |
| 490 | lchan = &ts->lchan[lchan_nr]; |
| 491 | if (lchan->type == GSM_LCHAN_NONE) |
| 492 | continue; |
| 493 | lchan_dump_vty(vty, lchan); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return CMD_SUCCESS; |
| 500 | } |
| 501 | |
| 502 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 503 | { |
| 504 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 505 | } |
| 506 | |
| 507 | DEFUN(show_e1drv, |
| 508 | show_e1drv_cmd, |
| 509 | "show e1_driver", |
| 510 | SHOW_STR "Display information about available E1 drivers\n") |
| 511 | { |
| 512 | struct e1inp_driver *drv; |
| 513 | |
| 514 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 515 | e1drv_dump_vty(vty, drv); |
| 516 | |
| 517 | return CMD_SUCCESS; |
| 518 | } |
| 519 | |
| 520 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line) |
| 521 | { |
| 522 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 523 | line->num, line->name ? line->name : "", |
| 524 | line->driver->name, VTY_NEWLINE); |
| 525 | } |
| 526 | |
| 527 | DEFUN(show_e1line, |
| 528 | show_e1line_cmd, |
| 529 | "show e1_line [line_nr]", |
| 530 | SHOW_STR "Display information about a E1 line\n") |
| 531 | { |
| 532 | struct e1inp_line *line; |
| 533 | |
| 534 | if (argc >= 1) { |
| 535 | int num = atoi(argv[0]); |
| 536 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 537 | if (line->num == num) { |
| 538 | e1line_dump_vty(vty, line); |
| 539 | return CMD_SUCCESS; |
| 540 | } |
| 541 | } |
| 542 | return CMD_WARNING; |
| 543 | } |
| 544 | |
| 545 | llist_for_each_entry(line, &e1inp_line_list, list) |
| 546 | e1line_dump_vty(vty, line); |
| 547 | |
| 548 | return CMD_SUCCESS; |
| 549 | } |
| 550 | |
| 551 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 552 | { |
| 553 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 554 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 555 | VTY_NEWLINE); |
| 556 | } |
| 557 | |
| 558 | DEFUN(show_e1ts, |
| 559 | show_e1ts_cmd, |
| 560 | "show e1_timeslot [line_nr] [ts_nr]", |
| 561 | SHOW_STR "Display information about a E1 timeslot\n") |
| 562 | { |
| 563 | struct e1inp_line *line; |
| 564 | struct e1inp_ts *ts; |
| 565 | int ts_nr; |
| 566 | |
| 567 | if (argc == 0) { |
| 568 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 569 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 570 | ts = &line->ts[ts_nr]; |
| 571 | e1ts_dump_vty(vty, ts); |
| 572 | } |
| 573 | } |
| 574 | return CMD_SUCCESS; |
| 575 | } |
| 576 | if (argc >= 1) { |
| 577 | int num = atoi(argv[0]); |
| 578 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 579 | if (line->num == num) |
| 580 | break; |
| 581 | } |
| 582 | if (!line || line->num != num) { |
| 583 | vty_out(vty, "E1 line %s is invalid%s", |
| 584 | argv[0], VTY_NEWLINE); |
| 585 | return CMD_WARNING; |
| 586 | } |
| 587 | } |
| 588 | if (argc >= 2) { |
| 589 | ts_nr = atoi(argv[1]); |
| 590 | if (ts_nr > NUM_E1_TS) { |
| 591 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 592 | argv[1], VTY_NEWLINE); |
| 593 | return CMD_WARNING; |
| 594 | } |
| 595 | ts = &line->ts[ts_nr]; |
| 596 | e1ts_dump_vty(vty, ts); |
| 597 | return CMD_SUCCESS; |
| 598 | } else { |
| 599 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 600 | ts = &line->ts[ts_nr]; |
| 601 | e1ts_dump_vty(vty, ts); |
| 602 | } |
| 603 | return CMD_SUCCESS; |
| 604 | } |
| 605 | return CMD_SUCCESS; |
| 606 | } |
| 607 | |
| 608 | static void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag) |
| 609 | { |
| 610 | vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE); |
| 611 | subscr_dump_vty(vty, pag->subscr); |
| 612 | } |
| 613 | |
| 614 | static void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts) |
| 615 | { |
| 616 | struct gsm_paging_request *pag; |
| 617 | |
| 618 | llist_for_each_entry(pag, &bts->paging.pending_requests, entry) |
| 619 | paging_dump_vty(vty, pag); |
| 620 | } |
| 621 | |
| 622 | DEFUN(show_paging, |
| 623 | show_paging_cmd, |
| 624 | "show paging [bts_nr]", |
| 625 | SHOW_STR "Display information about paging reuqests of a BTS\n") |
| 626 | { |
| 627 | struct gsm_network *net = gsmnet; |
| 628 | struct gsm_bts *bts; |
| 629 | int bts_nr; |
| 630 | |
| 631 | if (argc >= 1) { |
| 632 | /* use the BTS number that the user has specified */ |
| 633 | bts_nr = atoi(argv[0]); |
| 634 | if (bts_nr >= net->num_bts) { |
| 635 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 636 | VTY_NEWLINE); |
| 637 | return CMD_WARNING; |
| 638 | } |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 639 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 640 | bts_paging_dump_vty(vty, bts); |
| 641 | |
| 642 | return CMD_SUCCESS; |
| 643 | } |
| 644 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 645 | bts = gsm_bts_num(net, bts_nr); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 646 | bts_paging_dump_vty(vty, bts); |
| 647 | } |
| 648 | |
| 649 | return CMD_SUCCESS; |
| 650 | } |
| 651 | |
| 652 | /* per-subscriber configuration */ |
| 653 | DEFUN(cfg_subscr, |
| 654 | cfg_subscr_cmd, |
| 655 | "subscriber IMSI", |
| 656 | "Select a Subscriber to configure\n") |
| 657 | { |
| 658 | const char *imsi = argv[0]; |
| 659 | struct gsm_subscriber *subscr; |
| 660 | |
Harald Welte | aae7a52 | 2009-07-23 19:21:02 +0200 | [diff] [blame] | 661 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 662 | if (!subscr) { |
| 663 | vty_out(vty, "%% No subscriber for IMSI %s%s", |
| 664 | imsi, VTY_NEWLINE); |
| 665 | return CMD_WARNING; |
| 666 | } |
| 667 | |
| 668 | vty->index = subscr; |
| 669 | vty->node = SUBSCR_NODE; |
| 670 | |
| 671 | return CMD_SUCCESS; |
| 672 | } |
| 673 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 674 | DEFUN(cfg_net, |
| 675 | cfg_net_cmd, |
| 676 | "network", |
| 677 | "Configure the GSM network") |
| 678 | { |
| 679 | vty->index = gsmnet; |
| 680 | vty->node = GSMNET_NODE; |
| 681 | |
| 682 | return CMD_SUCCESS; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | DEFUN(cfg_net_ncc, |
| 687 | cfg_net_ncc_cmd, |
| 688 | "network country code <1-999>", |
| 689 | "Set the GSM network country code") |
| 690 | { |
| 691 | gsmnet->country_code = atoi(argv[0]); |
| 692 | |
| 693 | return CMD_SUCCESS; |
| 694 | } |
| 695 | |
| 696 | DEFUN(cfg_net_mnc, |
| 697 | cfg_net_mnc_cmd, |
| 698 | "mobile network code <1-999>", |
| 699 | "Set the GSM mobile network code") |
| 700 | { |
| 701 | gsmnet->network_code = atoi(argv[0]); |
| 702 | |
| 703 | return CMD_SUCCESS; |
| 704 | } |
| 705 | |
| 706 | DEFUN(cfg_net_name_short, |
| 707 | cfg_net_name_short_cmd, |
| 708 | "short name NAME", |
| 709 | "Set the short GSM network name") |
| 710 | { |
| 711 | if (gsmnet->name_short) |
| 712 | talloc_free(gsmnet->name_short); |
| 713 | |
| 714 | gsmnet->name_short = talloc_strdup(gsmnet, argv[0]); |
| 715 | |
| 716 | return CMD_SUCCESS; |
| 717 | } |
| 718 | |
| 719 | DEFUN(cfg_net_name_long, |
| 720 | cfg_net_name_long_cmd, |
| 721 | "long name NAME", |
| 722 | "Set the long GSM network name") |
| 723 | { |
| 724 | if (gsmnet->name_long) |
| 725 | talloc_free(gsmnet->name_long); |
| 726 | |
| 727 | gsmnet->name_long = talloc_strdup(gsmnet, argv[0]); |
| 728 | |
| 729 | return CMD_SUCCESS; |
| 730 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 731 | |
| 732 | /* per-BTS configuration */ |
| 733 | DEFUN(cfg_bts, |
| 734 | cfg_bts_cmd, |
| 735 | "bts BTS_NR", |
| 736 | "Select a BTS to configure\n") |
| 737 | { |
| 738 | int bts_nr = atoi(argv[0]); |
| 739 | struct gsm_bts *bts; |
| 740 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 741 | if (bts_nr > gsmnet->num_bts) { |
| 742 | vty_out(vty, "%% The next unused BTS number is %u%s", |
| 743 | gsmnet->num_bts, VTY_NEWLINE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 744 | return CMD_WARNING; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 745 | } else if (bts_nr == gsmnet->num_bts) { |
| 746 | /* allocate a new one */ |
| 747 | bts = gsm_bts_alloc(gsmnet, GSM_BTS_TYPE_UNKNOWN, |
| 748 | HARDCODED_TSC, HARDCODED_BSIC); |
| 749 | } else |
| 750 | bts = gsm_bts_num(gsmnet, bts_nr); |
| 751 | |
| 752 | if (!bts) |
| 753 | return CMD_WARNING; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 754 | |
| 755 | vty->index = bts; |
| 756 | vty->node = BTS_NODE; |
| 757 | |
| 758 | return CMD_SUCCESS; |
| 759 | } |
| 760 | |
| 761 | DEFUN(cfg_bts_type, |
| 762 | cfg_bts_type_cmd, |
| 763 | "type TYPE", |
| 764 | "Set the BTS type\n") |
| 765 | { |
| 766 | struct gsm_bts *bts = vty->index; |
| 767 | |
Harald Welte | 3ffe1b3 | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 768 | bts->type = parse_btstype(argv[0]); |
| 769 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 770 | return CMD_SUCCESS; |
| 771 | } |
| 772 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 773 | DEFUN(cfg_bts_band, |
| 774 | cfg_bts_band_cmd, |
| 775 | "band BAND", |
| 776 | "Set the frequency band of this BTS\n") |
| 777 | { |
| 778 | struct gsm_bts *bts = vty->index; |
| 779 | int band = gsm_band_parse(atoi(argv[0])); |
| 780 | |
| 781 | if (band < 0) { |
| 782 | vty_out(vty, "%% BAND %d is not a valid GSM band%s", |
| 783 | band, VTY_NEWLINE); |
| 784 | return CMD_WARNING; |
| 785 | } |
| 786 | |
| 787 | bts->band = band; |
| 788 | |
| 789 | return CMD_SUCCESS; |
| 790 | } |
| 791 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 792 | DEFUN(cfg_bts_lac, |
| 793 | cfg_bts_lac_cmd, |
| 794 | "location_area_code <0-255>", |
| 795 | "Set the Location Area Code (LAC) of this BTS\n") |
| 796 | { |
| 797 | struct gsm_bts *bts = vty->index; |
| 798 | int lac = atoi(argv[0]); |
| 799 | |
| 800 | if (lac < 0 || lac > 0xff) { |
| 801 | vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s", |
| 802 | lac, VTY_NEWLINE); |
| 803 | return CMD_WARNING; |
| 804 | } |
| 805 | bts->location_area_code = lac; |
| 806 | |
| 807 | return CMD_SUCCESS; |
| 808 | } |
| 809 | |
| 810 | DEFUN(cfg_bts_tsc, |
| 811 | cfg_bts_tsc_cmd, |
| 812 | "training_sequence_code <0-255>", |
| 813 | "Set the Training Sequence Code (TSC) of this BTS\n") |
| 814 | { |
| 815 | struct gsm_bts *bts = vty->index; |
| 816 | int tsc = atoi(argv[0]); |
| 817 | |
| 818 | if (tsc < 0 || tsc > 0xff) { |
| 819 | vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s", |
| 820 | tsc, VTY_NEWLINE); |
| 821 | return CMD_WARNING; |
| 822 | } |
| 823 | bts->tsc = tsc; |
| 824 | |
| 825 | return CMD_SUCCESS; |
| 826 | } |
| 827 | |
| 828 | DEFUN(cfg_bts_bsic, |
| 829 | cfg_bts_bsic_cmd, |
| 830 | "base_station_id_code <0-63>", |
| 831 | "Set the Base Station Identity Code (BSIC) of this BTS\n") |
| 832 | { |
| 833 | struct gsm_bts *bts = vty->index; |
| 834 | int bsic = atoi(argv[0]); |
| 835 | |
| 836 | if (bsic < 0 || bsic > 0x3f) { |
| 837 | vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s", |
| 838 | bsic, VTY_NEWLINE); |
| 839 | return CMD_WARNING; |
| 840 | } |
| 841 | bts->bsic = bsic; |
| 842 | |
| 843 | return CMD_SUCCESS; |
| 844 | } |
| 845 | |
| 846 | |
| 847 | DEFUN(cfg_bts_unit_id, |
| 848 | cfg_bts_unit_id_cmd, |
Harald Welte | f515aa0 | 2009-08-07 13:27:09 +0200 | [diff] [blame] | 849 | "ip.access unit_id <0-65534> <0-255>", |
| 850 | "Set the ip.access BTS Unit ID of this BTS\n") |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 851 | { |
| 852 | struct gsm_bts *bts = vty->index; |
| 853 | int site_id = atoi(argv[0]); |
| 854 | int bts_id = atoi(argv[1]); |
| 855 | |
| 856 | if (site_id < 0 || site_id > 65534) { |
| 857 | vty_out(vty, "%% Site ID %d is not in the valid range%s", |
| 858 | site_id, VTY_NEWLINE); |
| 859 | return CMD_WARNING; |
| 860 | } |
| 861 | if (site_id < 0 || site_id > 255) { |
| 862 | vty_out(vty, "%% BTS ID %d is not in the valid range%s", |
| 863 | bts_id, VTY_NEWLINE); |
| 864 | return CMD_WARNING; |
| 865 | } |
Harald Welte | f515aa0 | 2009-08-07 13:27:09 +0200 | [diff] [blame] | 866 | |
| 867 | if (!is_ipaccess_bts(bts)) { |
| 868 | vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE); |
| 869 | return CMD_WARNING; |
| 870 | } |
| 871 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 872 | bts->ip_access.site_id = site_id; |
| 873 | bts->ip_access.bts_id = bts_id; |
| 874 | |
| 875 | return CMD_SUCCESS; |
| 876 | } |
| 877 | |
| 878 | /* per TRX configuration */ |
| 879 | DEFUN(cfg_trx, |
| 880 | cfg_trx_cmd, |
| 881 | "trx TRX_NR", |
| 882 | "Select a TRX to configure") |
| 883 | { |
| 884 | int trx_nr = atoi(argv[0]); |
| 885 | struct gsm_bts *bts = vty->index; |
| 886 | struct gsm_bts_trx *trx; |
| 887 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 888 | if (trx_nr > bts->num_trx) { |
| 889 | vty_out(vty, "%% The next unused TRX number in this BTS is %u%s", |
| 890 | bts->num_trx, VTY_NEWLINE); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 891 | return CMD_WARNING; |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 892 | } else if (trx_nr == bts->num_trx) { |
| 893 | /* we need to allocate a new one */ |
| 894 | trx = gsm_bts_trx_alloc(bts); |
| 895 | } else |
| 896 | trx = gsm_bts_trx_num(bts, trx_nr); |
| 897 | |
| 898 | if (!trx) |
| 899 | return CMD_WARNING; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 900 | |
| 901 | vty->index = trx; |
| 902 | vty->node = TRX_NODE; |
| 903 | |
| 904 | return CMD_SUCCESS; |
| 905 | } |
| 906 | |
| 907 | DEFUN(cfg_trx_arfcn, |
| 908 | cfg_trx_arfcn_cmd, |
| 909 | "arfcn <1-1024>", |
| 910 | "Set the ARFCN for this TRX\n") |
| 911 | { |
| 912 | int arfcn = atoi(argv[0]); |
| 913 | struct gsm_bts_trx *trx = vty->index; |
| 914 | |
| 915 | /* FIXME: check if this ARFCN is supported by this TRX */ |
| 916 | |
| 917 | trx->arfcn = arfcn; |
| 918 | |
| 919 | /* FIXME: patch ARFCN into SYSTEM INFORMATION */ |
| 920 | /* FIXME: use OML layer to update the ARFCN */ |
| 921 | /* FIXME: use RSL layer to update SYSTEM INFORMATION */ |
| 922 | |
| 923 | return CMD_SUCCESS; |
| 924 | } |
| 925 | |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 926 | DEFUN(cfg_trx_max_power_red, |
| 927 | cfg_trx_max_power_red_cmd, |
| 928 | "max_power_red <0-100>", |
| 929 | "Reduction of maximum BS RF Power in dB\n") |
| 930 | { |
| 931 | int maxpwr_r = atoi(argv[0]); |
| 932 | struct gsm_bts_trx *trx = vty->index; |
| 933 | int upper_limit = 12; /* default 12.21 max power red. */ |
| 934 | |
| 935 | /* FIXME: check if our BTS type supports more than 12 */ |
| 936 | if (maxpwr_r < 0 || maxpwr_r > upper_limit) { |
| 937 | vty_out(vty, "%% Power %d dB is not in the valid range%s", |
| 938 | maxpwr_r, VTY_NEWLINE); |
| 939 | return CMD_WARNING; |
| 940 | } |
| 941 | if (maxpwr_r & 1) { |
| 942 | vty_out(vty, "%% Power %d dB is not an even value%s", |
| 943 | maxpwr_r, VTY_NEWLINE); |
| 944 | return CMD_WARNING; |
| 945 | } |
| 946 | |
| 947 | trx->max_power_red = maxpwr_r; |
| 948 | |
| 949 | /* FIXME: make sure we update this using OML */ |
| 950 | |
| 951 | return CMD_SUCCESS; |
| 952 | } |
| 953 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 954 | /* per TS configuration */ |
| 955 | DEFUN(cfg_ts, |
| 956 | cfg_ts_cmd, |
| 957 | "timeslot TS_NR", |
| 958 | "Select a Timeslot to configure") |
| 959 | { |
| 960 | int ts_nr = atoi(argv[0]); |
| 961 | struct gsm_bts_trx *trx = vty->index; |
| 962 | struct gsm_bts_trx_ts *ts; |
| 963 | |
| 964 | if (ts_nr >= TRX_NR_TS) { |
| 965 | vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s", |
| 966 | TRX_NR_TS, VTY_NEWLINE); |
| 967 | return CMD_WARNING; |
| 968 | } |
| 969 | |
| 970 | ts = &trx->ts[ts_nr]; |
| 971 | |
| 972 | vty->index = ts; |
| 973 | vty->node = TS_NODE; |
| 974 | |
| 975 | return CMD_SUCCESS; |
| 976 | } |
| 977 | |
Harald Welte | 3ffe1b3 | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 978 | DEFUN(cfg_ts_pchan, |
| 979 | cfg_ts_pchan_cmd, |
| 980 | "phys_chan_config PCHAN", |
| 981 | "Physical Channel configuration (TCH/SDCCH/...)") |
| 982 | { |
| 983 | struct gsm_bts_trx_ts *ts = vty->index; |
| 984 | int pchanc; |
| 985 | |
| 986 | pchanc = gsm_pchan_parse(argv[0]); |
| 987 | if (pchanc < 0) |
| 988 | return CMD_WARNING; |
| 989 | |
| 990 | ts->pchan = pchanc; |
| 991 | |
| 992 | return CMD_SUCCESS; |
| 993 | } |
| 994 | |
| 995 | DEFUN(cfg_ts_e1_subslot, |
| 996 | cfg_ts_e1_subslot_cmd, |
| 997 | "e1_subslot E1_IF <1-31> <0-4>", |
| 998 | "E1 sub-slot connected to this on-air timeslot") |
| 999 | { |
| 1000 | struct gsm_bts_trx_ts *ts = vty->index; |
| 1001 | |
| 1002 | ts->e1_link.e1_nr = atoi(argv[0]); |
| 1003 | ts->e1_link.e1_ts = atoi(argv[1]); |
| 1004 | ts->e1_link.e1_ts_ss = atoi(argv[2]); |
| 1005 | |
| 1006 | return CMD_SUCCESS; |
| 1007 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1008 | |
| 1009 | /* Subscriber */ |
| 1010 | DEFUN(show_subscr, |
| 1011 | show_subscr_cmd, |
| 1012 | "show subscriber [IMSI]", |
| 1013 | SHOW_STR "Display information about a subscriber\n") |
| 1014 | { |
| 1015 | const char *imsi; |
| 1016 | struct gsm_subscriber *subscr; |
| 1017 | |
| 1018 | if (argc >= 1) { |
| 1019 | imsi = argv[0]; |
Harald Welte | aae7a52 | 2009-07-23 19:21:02 +0200 | [diff] [blame] | 1020 | subscr = subscr_get_by_imsi(gsmnet, imsi); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1021 | if (!subscr) { |
| 1022 | vty_out(vty, "%% unknown subscriber%s", |
| 1023 | VTY_NEWLINE); |
| 1024 | return CMD_WARNING; |
| 1025 | } |
| 1026 | subscr_dump_vty(vty, subscr); |
| 1027 | |
| 1028 | return CMD_SUCCESS; |
| 1029 | } |
| 1030 | |
| 1031 | /* FIXME: iterate over all subscribers ? */ |
| 1032 | return CMD_WARNING; |
| 1033 | |
| 1034 | return CMD_SUCCESS; |
| 1035 | } |
| 1036 | |
| 1037 | DEFUN(cfg_subscr_name, |
| 1038 | cfg_subscr_name_cmd, |
| 1039 | "name NAME", |
| 1040 | "Set the name of the subscriber") |
| 1041 | { |
| 1042 | const char *name = argv[0]; |
| 1043 | struct gsm_subscriber *subscr = vty->index; |
| 1044 | |
| 1045 | strncpy(subscr->name, name, sizeof(subscr->name)); |
| 1046 | |
| 1047 | db_sync_subscriber(subscr); |
| 1048 | |
| 1049 | return CMD_SUCCESS; |
| 1050 | } |
| 1051 | |
| 1052 | DEFUN(cfg_subscr_extension, |
| 1053 | cfg_subscr_extension_cmd, |
| 1054 | "extension EXTENSION", |
| 1055 | "Set the extension of the subscriber") |
| 1056 | { |
| 1057 | const char *name = argv[0]; |
| 1058 | struct gsm_subscriber *subscr = vty->index; |
| 1059 | |
| 1060 | strncpy(subscr->extension, name, sizeof(subscr->extension)); |
| 1061 | |
| 1062 | db_sync_subscriber(subscr); |
| 1063 | |
| 1064 | return CMD_SUCCESS; |
| 1065 | } |
| 1066 | |
| 1067 | DEFUN(cfg_subscr_authorized, |
| 1068 | cfg_subscr_authorized_cmd, |
| 1069 | "auth <0-1>", |
| 1070 | "Set the authorization status of the subscriber") |
| 1071 | { |
| 1072 | int auth = atoi(argv[0]); |
| 1073 | struct gsm_subscriber *subscr = vty->index; |
| 1074 | |
| 1075 | if (auth) |
| 1076 | subscr->authorized = 1; |
| 1077 | else |
| 1078 | subscr->authorized = 0; |
| 1079 | |
| 1080 | db_sync_subscriber(subscr); |
| 1081 | |
| 1082 | return CMD_SUCCESS; |
| 1083 | } |
| 1084 | |
| 1085 | int bsc_vty_init(struct gsm_network *net) |
| 1086 | { |
| 1087 | gsmnet = net; |
| 1088 | |
| 1089 | cmd_init(1); |
| 1090 | vty_init(); |
| 1091 | |
| 1092 | install_element(VIEW_NODE, &show_net_cmd); |
| 1093 | install_element(VIEW_NODE, &show_bts_cmd); |
| 1094 | install_element(VIEW_NODE, &show_trx_cmd); |
| 1095 | install_element(VIEW_NODE, &show_ts_cmd); |
| 1096 | install_element(VIEW_NODE, &show_lchan_cmd); |
| 1097 | |
| 1098 | install_element(VIEW_NODE, &show_e1drv_cmd); |
| 1099 | install_element(VIEW_NODE, &show_e1line_cmd); |
| 1100 | install_element(VIEW_NODE, &show_e1ts_cmd); |
| 1101 | |
| 1102 | install_element(VIEW_NODE, &show_paging_cmd); |
| 1103 | |
| 1104 | install_element(VIEW_NODE, &show_subscr_cmd); |
| 1105 | |
Harald Welte | e87eb46 | 2009-08-07 13:29:14 +0200 | [diff] [blame] | 1106 | install_element(CONFIG_NODE, &cfg_net_cmd); |
| 1107 | install_node(&net_node, config_write_net); |
| 1108 | install_default(GSMNET_NODE); |
| 1109 | install_element(GSMNET_NODE, &cfg_net_mnc_cmd); |
| 1110 | install_element(GSMNET_NODE, &cfg_net_name_short_cmd); |
| 1111 | install_element(GSMNET_NODE, &cfg_net_name_long_cmd); |
| 1112 | |
| 1113 | install_element(GSMNET_NODE, &cfg_bts_cmd); |
Harald Welte | 97ceef9 | 2009-08-06 19:06:46 +0200 | [diff] [blame] | 1114 | install_node(&bts_node, config_write_bts); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1115 | install_default(BTS_NODE); |
| 1116 | install_element(BTS_NODE, &cfg_bts_type_cmd); |
Harald Welte | 91afe4c | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 1117 | install_element(BTS_NODE, &cfg_bts_band_cmd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1118 | install_element(BTS_NODE, &cfg_bts_lac_cmd); |
| 1119 | install_element(BTS_NODE, &cfg_bts_tsc_cmd); |
| 1120 | install_element(BTS_NODE, &cfg_bts_unit_id_cmd); |
| 1121 | |
| 1122 | install_element(BTS_NODE, &cfg_trx_cmd); |
| 1123 | install_node(&trx_node, dummy_config_write); |
| 1124 | install_default(TRX_NODE); |
| 1125 | install_element(TRX_NODE, &cfg_trx_arfcn_cmd); |
Harald Welte | 7f597bc | 2009-06-20 22:36:12 +0200 | [diff] [blame] | 1126 | install_element(TRX_NODE, &cfg_trx_max_power_red_cmd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1127 | |
| 1128 | install_element(TRX_NODE, &cfg_ts_cmd); |
| 1129 | install_node(&ts_node, dummy_config_write); |
| 1130 | install_default(TS_NODE); |
Harald Welte | 3ffe1b3 | 2009-08-07 00:25:23 +0200 | [diff] [blame] | 1131 | install_element(TS_NODE, &cfg_ts_pchan_cmd); |
| 1132 | install_element(TS_NODE, &cfg_ts_e1_subslot_cmd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1133 | |
| 1134 | install_element(CONFIG_NODE, &cfg_subscr_cmd); |
| 1135 | install_node(&subscr_node, dummy_config_write); |
| 1136 | install_default(SUBSCR_NODE); |
| 1137 | install_element(SUBSCR_NODE, &cfg_subscr_name_cmd); |
| 1138 | install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd); |
| 1139 | install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |