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> |
| 26 | #include <vty/vty.h> |
| 27 | |
| 28 | #include <arpa/inet.h> |
| 29 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 30 | #include <openbsc/linuxlist.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 31 | #include <openbsc/gsm_data.h> |
| 32 | #include <openbsc/gsm_subscriber.h> |
| 33 | #include <openbsc/e1_input.h> |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 34 | #include <openbsc/abis_nm.h> |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 35 | |
| 36 | static struct gsm_network *gsmnet; |
| 37 | |
| 38 | struct cmd_node bts_node = { |
| 39 | BTS_NODE, |
| 40 | "%s(bts)#", |
| 41 | 1, |
| 42 | }; |
| 43 | |
| 44 | struct cmd_node trx_node = { |
| 45 | TRX_NODE, |
| 46 | "%s(trx)#", |
| 47 | 1, |
| 48 | }; |
| 49 | |
| 50 | struct cmd_node ts_node = { |
| 51 | TS_NODE, |
| 52 | "%s(ts)#", |
| 53 | 1, |
| 54 | }; |
| 55 | |
| 56 | static int dummy_config_write(struct vty *v) |
| 57 | { |
| 58 | return CMD_SUCCESS; |
| 59 | } |
| 60 | |
| 61 | static void net_dump_nmstate(struct vty *vty, struct gsm_nm_state *nms) |
| 62 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 63 | vty_out(vty,"Oper '%s', Admin %u, Avail '%s'%s", |
| 64 | nm_opstate_name(nms->operational), nms->administrative, |
| 65 | nm_avail_name(nms->availability), VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void net_dump_vty(struct vty *vty, struct gsm_network *net) |
| 69 | { |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 70 | vty_out(vty, "BSC is on Country Code %u, Network Code %u " |
| 71 | "and has %u BTS%s", net->country_code, net->network_code, |
| 72 | net->num_bts, VTY_NEWLINE); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 73 | vty_out(vty, " Long network name: '%s'%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 74 | net->name_long, VTY_NEWLINE); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 75 | vty_out(vty, " Short network name: '%s'%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 76 | net->name_short, VTY_NEWLINE); |
| 77 | } |
| 78 | |
| 79 | DEFUN(show_net, show_net_cmd, "show network", |
| 80 | SHOW_STR "Display information about a GSM NETWORK\n") |
| 81 | { |
| 82 | struct gsm_network *net = gsmnet; |
| 83 | net_dump_vty(vty, net); |
| 84 | |
| 85 | return CMD_SUCCESS; |
| 86 | } |
| 87 | |
| 88 | static void e1isl_dump_vty(struct vty *vty, struct e1inp_sign_link *e1l) |
| 89 | { |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 90 | struct e1inp_line *line; |
| 91 | |
| 92 | if (!e1l) { |
| 93 | vty_out(vty, " None%s", VTY_NEWLINE); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | line = e1l->ts->line; |
| 98 | |
| 99 | vty_out(vty, " E1 Line %u, Type %s: Timeslot %u, Mode %s%s", |
| 100 | line->num, line->driver->name, e1l->ts->num, |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 101 | e1inp_signtype_name(e1l->type), VTY_NEWLINE); |
Harald Welte | edb3778 | 2009-05-01 14:59:07 +0000 | [diff] [blame] | 102 | vty_out(vty, " E1 TEI %u, SAPI %u%s", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 103 | e1l->tei, e1l->sapi, VTY_NEWLINE); |
| 104 | } |
| 105 | |
| 106 | static void bts_dump_vty(struct vty *vty, struct gsm_bts *bts) |
| 107 | { |
| 108 | vty_out(vty, "BTS %u is of %s type, has LAC %u, TSC %u and %u TRX%s", |
| 109 | bts->nr, btstype2str(bts->type), bts->location_area_code, |
| 110 | bts->tsc, bts->num_trx, VTY_NEWLINE); |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 111 | if (is_ipaccess_bts(bts)) |
| 112 | vty_out(vty, " Unit ID: %u/%u/0%s", |
| 113 | bts->ip_access.site_id, bts->ip_access.bts_id, |
| 114 | VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 115 | vty_out(vty, " NM State: "); |
| 116 | net_dump_nmstate(vty, &bts->nm_state); |
| 117 | vty_out(vty, " Site Mgr NM State: "); |
| 118 | net_dump_nmstate(vty, &bts->site_mgr.nm_state); |
| 119 | vty_out(vty, " Paging: FIXME pending requests, %u free slots%s", |
| 120 | bts->paging.available_slots, VTY_NEWLINE); |
| 121 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 122 | e1isl_dump_vty(vty, bts->oml_link); |
| 123 | /* FIXME: oml_link, chan_desc */ |
| 124 | } |
| 125 | |
| 126 | DEFUN(show_bts, show_bts_cmd, "show bts [number]", |
| 127 | SHOW_STR "Display information about a BTS\n" |
| 128 | "BTS number") |
| 129 | { |
| 130 | struct gsm_network *net = gsmnet; |
| 131 | int bts_nr; |
| 132 | |
| 133 | if (argc != 0) { |
| 134 | /* use the BTS number that the user has specified */ |
| 135 | bts_nr = atoi(argv[0]); |
| 136 | if (bts_nr > net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 137 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 138 | VTY_NEWLINE); |
| 139 | return CMD_WARNING; |
| 140 | } |
| 141 | bts_dump_vty(vty, &net->bts[bts_nr]); |
| 142 | return CMD_SUCCESS; |
| 143 | } |
| 144 | /* print all BTS's */ |
| 145 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) |
| 146 | bts_dump_vty(vty, &net->bts[bts_nr]); |
| 147 | |
| 148 | return CMD_SUCCESS; |
| 149 | } |
| 150 | |
| 151 | static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx) |
| 152 | { |
| 153 | vty_out(vty, "TRX %u of BTS %u is on ARFCN %u%s", |
| 154 | trx->nr, trx->bts->nr, trx->arfcn, VTY_NEWLINE); |
| 155 | vty_out(vty, " NM State: "); |
| 156 | net_dump_nmstate(vty, &trx->nm_state); |
| 157 | vty_out(vty, " Baseband Transceiver NM State: "); |
| 158 | net_dump_nmstate(vty, &trx->bb_transc.nm_state); |
| 159 | vty_out(vty, " E1 Signalling Link:%s", VTY_NEWLINE); |
| 160 | e1isl_dump_vty(vty, trx->rsl_link); |
| 161 | } |
| 162 | |
| 163 | DEFUN(show_trx, |
| 164 | show_trx_cmd, |
| 165 | "show trx [bts_nr] [trx_nr]", |
| 166 | SHOW_STR "Display information about a TRX\n") |
| 167 | { |
| 168 | struct gsm_network *net = gsmnet; |
| 169 | struct gsm_bts *bts = NULL; |
| 170 | struct gsm_bts_trx *trx; |
| 171 | int bts_nr, trx_nr; |
| 172 | |
| 173 | if (argc >= 1) { |
| 174 | /* use the BTS number that the user has specified */ |
| 175 | bts_nr = atoi(argv[0]); |
| 176 | if (bts_nr >= net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 177 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 178 | VTY_NEWLINE); |
| 179 | return CMD_WARNING; |
| 180 | } |
| 181 | bts = &net->bts[bts_nr]; |
| 182 | } |
| 183 | if (argc >= 2) { |
| 184 | trx_nr = atoi(argv[1]); |
| 185 | if (trx_nr >= bts->num_trx) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 186 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 187 | VTY_NEWLINE); |
| 188 | return CMD_WARNING; |
| 189 | } |
| 190 | trx = &bts->trx[trx_nr]; |
| 191 | trx_dump_vty(vty, trx); |
| 192 | return CMD_SUCCESS; |
| 193 | } |
| 194 | if (bts) { |
| 195 | /* print all TRX in this BTS */ |
| 196 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
| 197 | trx = &bts->trx[trx_nr]; |
| 198 | trx_dump_vty(vty, trx); |
| 199 | } |
| 200 | return CMD_SUCCESS; |
| 201 | } |
| 202 | |
| 203 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
| 204 | bts = &net->bts[bts_nr]; |
| 205 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
| 206 | trx = &bts->trx[trx_nr]; |
| 207 | trx_dump_vty(vty, trx); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | return CMD_SUCCESS; |
| 212 | } |
| 213 | |
| 214 | static void ts_dump_vty(struct vty *vty, struct gsm_bts_trx_ts *ts) |
| 215 | { |
| 216 | struct in_addr ia; |
| 217 | |
| 218 | vty_out(vty, "Timeslot %u of TRX %u in BTS %u, phys cfg %s%s", |
| 219 | ts->nr, ts->trx->nr, ts->trx->bts->nr, |
| 220 | gsm_pchan_name(ts->pchan), VTY_NEWLINE); |
| 221 | vty_out(vty, " NM State: "); |
| 222 | net_dump_nmstate(vty, &ts->nm_state); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 223 | if (is_ipaccess_bts(ts->trx->bts)) { |
| 224 | ia.s_addr = ts->abis_ip.bound_ip; |
| 225 | vty_out(vty, " Bound IP: %s Port %u FC=%u F8=%u%s", |
| 226 | inet_ntoa(ia), ts->abis_ip.bound_port, |
| 227 | ts->abis_ip.attr_fc, ts->abis_ip.attr_f8, |
| 228 | VTY_NEWLINE); |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 229 | } else { |
| 230 | vty_out(vty, " E1 Line %u, Timeslot %u, Subslot %u%s", |
| 231 | ts->e1_link.e1_nr, ts->e1_link.e1_ts, |
| 232 | ts->e1_link.e1_ts_ss, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | DEFUN(show_ts, |
| 237 | show_ts_cmd, |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 238 | "show timeslot [bts_nr] [trx_nr] [ts_nr]", |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 239 | SHOW_STR "Display information about a TS\n") |
| 240 | { |
| 241 | struct gsm_network *net = gsmnet; |
| 242 | struct gsm_bts *bts; |
| 243 | struct gsm_bts_trx *trx; |
| 244 | struct gsm_bts_trx_ts *ts; |
| 245 | int bts_nr, trx_nr, ts_nr; |
| 246 | |
| 247 | if (argc >= 1) { |
| 248 | /* use the BTS number that the user has specified */ |
| 249 | bts_nr = atoi(argv[0]); |
| 250 | if (bts_nr >= net->num_bts) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 251 | vty_out(vty, "%% can't find BTS '%s'%s", argv[0], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 252 | VTY_NEWLINE); |
| 253 | return CMD_WARNING; |
| 254 | } |
| 255 | bts = &net->bts[bts_nr]; |
| 256 | } |
| 257 | if (argc >= 2) { |
| 258 | trx_nr = atoi(argv[1]); |
| 259 | if (trx_nr >= bts->num_trx) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 260 | vty_out(vty, "%% can't find TRX '%s'%s", argv[1], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 261 | VTY_NEWLINE); |
| 262 | return CMD_WARNING; |
| 263 | } |
| 264 | trx = &bts->trx[trx_nr]; |
| 265 | } |
| 266 | if (argc >= 3) { |
| 267 | ts_nr = atoi(argv[2]); |
| 268 | if (ts_nr >= TRX_NR_TS) { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 269 | vty_out(vty, "%% can't find TS '%s'%s", argv[2], |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 270 | VTY_NEWLINE); |
| 271 | return CMD_WARNING; |
| 272 | } |
| 273 | ts = &trx->ts[ts_nr]; |
| 274 | ts_dump_vty(vty, ts); |
| 275 | return CMD_SUCCESS; |
| 276 | } |
| 277 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
| 278 | bts = &net->bts[bts_nr]; |
| 279 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
| 280 | trx = &bts->trx[trx_nr]; |
| 281 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 282 | ts = &trx->ts[ts_nr]; |
| 283 | ts_dump_vty(vty, ts); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return CMD_SUCCESS; |
| 289 | } |
| 290 | |
| 291 | static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr) |
| 292 | { |
| 293 | if (subscr->name) |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 294 | vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 295 | if (subscr->extension) |
| 296 | vty_out(vty, " Extension: %s%s", subscr->extension, |
| 297 | VTY_NEWLINE); |
| 298 | if (subscr->imsi) |
| 299 | vty_out(vty, " IMSI: %s%s", subscr->imsi, VTY_NEWLINE); |
| 300 | if (subscr->tmsi) |
| 301 | vty_out(vty, " TMSI: %s%s", subscr->tmsi, VTY_NEWLINE); |
| 302 | } |
| 303 | |
| 304 | static void lchan_dump_vty(struct vty *vty, struct gsm_lchan *lchan) |
| 305 | { |
| 306 | vty_out(vty, "Lchan %u in Timeslot %u of TRX %u in BTS %u, Type %s%s", |
| 307 | lchan->nr, lchan->ts->nr, lchan->ts->trx->nr, |
| 308 | lchan->ts->trx->bts->nr, gsm_lchan_name(lchan->type), |
| 309 | VTY_NEWLINE); |
| 310 | vty_out(vty, " Use Count: %u%s", lchan->use_count, VTY_NEWLINE); |
| 311 | vty_out(vty, " BS Power %u, MS Power %u%s", lchan->bs_power, |
| 312 | lchan->ms_power, VTY_NEWLINE); |
| 313 | if (lchan->subscr) { |
| 314 | vty_out(vty, " Subscriber:%s", VTY_NEWLINE); |
| 315 | subscr_dump_vty(vty, lchan->subscr); |
| 316 | } else |
| 317 | vty_out(vty, " No Subscriber%s", VTY_NEWLINE); |
| 318 | } |
| 319 | |
| 320 | static void call_dump_vty(struct vty *vty, struct gsm_call *call) |
| 321 | { |
| 322 | vty_out(vty, "Call Type %u, State %u, Transaction ID %u%s", |
| 323 | call->type, call->state, call->transaction_id, VTY_NEWLINE); |
| 324 | |
| 325 | if (call->local_lchan) { |
| 326 | vty_out(vty, "Call Local Channel:%s", VTY_NEWLINE); |
| 327 | lchan_dump_vty(vty, call->local_lchan); |
| 328 | } else |
| 329 | vty_out(vty, "Call has no Local Channel%s", VTY_NEWLINE); |
| 330 | |
| 331 | if (call->remote_lchan) { |
| 332 | vty_out(vty, "Call Remote Channel:%s", VTY_NEWLINE); |
| 333 | lchan_dump_vty(vty, call->remote_lchan); |
| 334 | } else |
| 335 | vty_out(vty, "Call has no Remote Channel%s", VTY_NEWLINE); |
| 336 | |
| 337 | if (call->called_subscr) { |
| 338 | vty_out(vty, "Called Subscriber:%s", VTY_NEWLINE); |
| 339 | subscr_dump_vty(vty, call->called_subscr); |
| 340 | } else |
| 341 | vty_out(vty, "Call has no Called Subscriber%s", VTY_NEWLINE); |
| 342 | } |
| 343 | |
| 344 | DEFUN(show_lchan, |
| 345 | show_lchan_cmd, |
| 346 | "show lchan [bts_nr] [trx_nr] [ts_nr] [lchan_nr]", |
| 347 | SHOW_STR "Display information about a logical channel\n") |
| 348 | { |
| 349 | struct gsm_network *net = gsmnet; |
| 350 | struct gsm_bts *bts; |
| 351 | struct gsm_bts_trx *trx; |
| 352 | struct gsm_bts_trx_ts *ts; |
| 353 | struct gsm_lchan *lchan; |
| 354 | int bts_nr, trx_nr, ts_nr, lchan_nr; |
| 355 | |
| 356 | if (argc >= 1) { |
| 357 | /* use the BTS number that the user has specified */ |
| 358 | bts_nr = atoi(argv[0]); |
| 359 | if (bts_nr >= net->num_bts) { |
| 360 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 361 | VTY_NEWLINE); |
| 362 | return CMD_WARNING; |
| 363 | } |
| 364 | bts = &net->bts[bts_nr]; |
| 365 | } |
| 366 | if (argc >= 2) { |
| 367 | trx_nr = atoi(argv[1]); |
| 368 | if (trx_nr >= bts->num_trx) { |
| 369 | vty_out(vty, "%% can't find TRX %s%s", argv[1], |
| 370 | VTY_NEWLINE); |
| 371 | return CMD_WARNING; |
| 372 | } |
| 373 | trx = &bts->trx[trx_nr]; |
| 374 | } |
| 375 | if (argc >= 3) { |
| 376 | ts_nr = atoi(argv[2]); |
| 377 | if (ts_nr >= TRX_NR_TS) { |
| 378 | vty_out(vty, "%% can't find TS %s%s", argv[2], |
| 379 | VTY_NEWLINE); |
| 380 | return CMD_WARNING; |
| 381 | } |
| 382 | ts = &trx->ts[ts_nr]; |
| 383 | } |
| 384 | if (argc >= 4) { |
| 385 | lchan_nr = atoi(argv[3]); |
| 386 | if (lchan_nr >= TS_MAX_LCHAN) { |
| 387 | vty_out(vty, "%% can't find LCHAN %s%s", argv[3], |
| 388 | VTY_NEWLINE); |
| 389 | return CMD_WARNING; |
| 390 | } |
| 391 | lchan = &ts->lchan[lchan_nr]; |
| 392 | lchan_dump_vty(vty, lchan); |
| 393 | return CMD_SUCCESS; |
| 394 | } |
| 395 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
| 396 | bts = &net->bts[bts_nr]; |
| 397 | for (trx_nr = 0; trx_nr < bts->num_trx; trx_nr++) { |
| 398 | trx = &bts->trx[trx_nr]; |
| 399 | for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) { |
| 400 | ts = &trx->ts[ts_nr]; |
| 401 | for (lchan_nr = 0; lchan_nr < TS_MAX_LCHAN; |
| 402 | lchan_nr++) { |
| 403 | lchan = &ts->lchan[lchan_nr]; |
Harald Welte | ef235b5 | 2009-03-10 12:34:02 +0000 | [diff] [blame] | 404 | if (lchan->type == GSM_LCHAN_NONE) |
| 405 | continue; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 406 | lchan_dump_vty(vty, lchan); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | return CMD_SUCCESS; |
| 413 | } |
| 414 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 415 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 416 | { |
| 417 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 418 | } |
| 419 | |
| 420 | DEFUN(show_e1drv, |
| 421 | show_e1drv_cmd, |
| 422 | "show e1_driver", |
| 423 | SHOW_STR "Display information about available E1 drivers\n") |
| 424 | { |
| 425 | struct e1inp_driver *drv; |
| 426 | |
| 427 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 428 | e1drv_dump_vty(vty, drv); |
| 429 | |
| 430 | return CMD_SUCCESS; |
| 431 | } |
| 432 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 433 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line) |
| 434 | { |
| 435 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 436 | line->num, line->name ? line->name : "", |
| 437 | line->driver->name, VTY_NEWLINE); |
| 438 | } |
| 439 | |
| 440 | DEFUN(show_e1line, |
| 441 | show_e1line_cmd, |
| 442 | "show e1_line [line_nr]", |
| 443 | SHOW_STR "Display information about a E1 line\n") |
| 444 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 445 | struct e1inp_line *line; |
| 446 | |
| 447 | if (argc >= 1) { |
| 448 | int num = atoi(argv[0]); |
| 449 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 450 | if (line->num == num) { |
| 451 | e1line_dump_vty(vty, line); |
| 452 | return CMD_SUCCESS; |
| 453 | } |
| 454 | } |
| 455 | return CMD_WARNING; |
| 456 | } |
| 457 | |
| 458 | llist_for_each_entry(line, &e1inp_line_list, list) |
| 459 | e1line_dump_vty(vty, line); |
| 460 | |
| 461 | return CMD_SUCCESS; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 465 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 466 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 467 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 468 | VTY_NEWLINE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | DEFUN(show_e1ts, |
| 472 | show_e1ts_cmd, |
| 473 | "show e1_timeslot [line_nr] [ts_nr]", |
| 474 | SHOW_STR "Display information about a E1 timeslot\n") |
| 475 | { |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 476 | struct e1inp_line *line; |
| 477 | struct e1inp_ts *ts; |
| 478 | int ts_nr; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 479 | |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 480 | if (argc == 0) { |
| 481 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 482 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 483 | ts = &line->ts[ts_nr]; |
| 484 | e1ts_dump_vty(vty, ts); |
| 485 | } |
| 486 | } |
| 487 | return CMD_SUCCESS; |
| 488 | } |
| 489 | if (argc >= 1) { |
| 490 | int num = atoi(argv[0]); |
| 491 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 492 | if (line->num == num) |
| 493 | break; |
| 494 | } |
| 495 | if (!line || line->num != num) { |
| 496 | vty_out(vty, "E1 line %s is invalid%s", |
| 497 | argv[0], VTY_NEWLINE); |
| 498 | return CMD_WARNING; |
| 499 | } |
| 500 | } |
| 501 | if (argc >= 2) { |
| 502 | ts_nr = atoi(argv[1]); |
| 503 | if (ts_nr > NUM_E1_TS) { |
| 504 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 505 | argv[1], VTY_NEWLINE); |
| 506 | return CMD_WARNING; |
| 507 | } |
| 508 | ts = &line->ts[ts_nr]; |
| 509 | e1ts_dump_vty(vty, ts); |
| 510 | return CMD_SUCCESS; |
| 511 | } else { |
| 512 | for (ts_nr = 0; ts_nr < NUM_E1_TS; ts_nr++) { |
| 513 | ts = &line->ts[ts_nr]; |
| 514 | e1ts_dump_vty(vty, ts); |
| 515 | } |
| 516 | return CMD_SUCCESS; |
| 517 | } |
| 518 | return CMD_SUCCESS; |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 521 | void paging_dump_vty(struct vty *vty, struct gsm_paging_request *pag) |
| 522 | { |
| 523 | vty_out(vty, "Paging on BTS %u%s", pag->bts->nr, VTY_NEWLINE); |
| 524 | subscr_dump_vty(vty, pag->subscr); |
| 525 | } |
| 526 | |
| 527 | void bts_paging_dump_vty(struct vty *vty, struct gsm_bts *bts) |
| 528 | { |
| 529 | struct gsm_paging_request *pag; |
| 530 | |
| 531 | llist_for_each_entry(pag, &bts->paging.pending_requests, entry) |
| 532 | paging_dump_vty(vty, pag); |
| 533 | } |
| 534 | |
| 535 | DEFUN(show_paging, |
| 536 | show_paging_cmd, |
| 537 | "show paging [bts_nr]", |
| 538 | SHOW_STR "Display information about pating reuqests of a BTS\n") |
| 539 | { |
| 540 | struct gsm_network *net = gsmnet; |
| 541 | struct gsm_bts *bts; |
| 542 | int bts_nr; |
| 543 | |
| 544 | if (argc >= 1) { |
| 545 | /* use the BTS number that the user has specified */ |
| 546 | bts_nr = atoi(argv[0]); |
| 547 | if (bts_nr >= net->num_bts) { |
| 548 | vty_out(vty, "%% can't find BTS %s%s", argv[0], |
| 549 | VTY_NEWLINE); |
| 550 | return CMD_WARNING; |
| 551 | } |
| 552 | bts = &net->bts[bts_nr]; |
| 553 | bts_paging_dump_vty(vty, bts); |
| 554 | |
| 555 | return CMD_SUCCESS; |
| 556 | } |
| 557 | for (bts_nr = 0; bts_nr < net->num_bts; bts_nr++) { |
| 558 | bts = &net->bts[bts_nr]; |
| 559 | bts_paging_dump_vty(vty, bts); |
| 560 | } |
| 561 | |
| 562 | return CMD_SUCCESS; |
| 563 | } |
| 564 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 565 | /* per-BTS configuration */ |
| 566 | DEFUN(cfg_bts, |
| 567 | cfg_bts_cmd, |
| 568 | "bts BTS_NR", |
| 569 | "Select a BTS to configure\n") |
| 570 | { |
| 571 | int bts_nr = atoi(argv[0]); |
| 572 | struct gsm_bts *bts; |
| 573 | |
| 574 | if (bts_nr >= GSM_MAX_BTS) { |
| 575 | vty_out(vty, "%% This Version of OpenBSC only supports %u BTS%s", |
| 576 | GSM_MAX_BTS, VTY_NEWLINE); |
| 577 | return CMD_WARNING; |
| 578 | } |
| 579 | bts = &gsmnet->bts[bts_nr]; |
| 580 | if (bts_nr >= gsmnet->num_bts) |
| 581 | gsmnet->num_bts = bts_nr + 1; |
| 582 | |
| 583 | vty->index = bts; |
| 584 | vty->node = BTS_NODE; |
| 585 | |
| 586 | return CMD_SUCCESS; |
| 587 | } |
| 588 | |
| 589 | DEFUN(cfg_bts_type, |
| 590 | cfg_bts_type_cmd, |
| 591 | "type TYPE", |
| 592 | "Set the BTS type\n") |
| 593 | { |
| 594 | struct gsm_bts *bts = vty->index; |
| 595 | |
| 596 | //bts->type = |
| 597 | return CMD_SUCCESS; |
| 598 | } |
| 599 | |
| 600 | DEFUN(cfg_bts_lac, |
| 601 | cfg_bts_lac_cmd, |
| 602 | "location_area_code <0-255>", |
| 603 | "Set the Location Area Code (LAC) of this BTS\n") |
| 604 | { |
| 605 | struct gsm_bts *bts = vty->index; |
| 606 | int lac = atoi(argv[0]); |
| 607 | |
| 608 | if (lac < 0 || lac > 0xff) { |
| 609 | vty_out(vty, "%% LAC %d is not in the valid range (0-255)%s", |
| 610 | lac, VTY_NEWLINE); |
| 611 | return CMD_WARNING; |
| 612 | } |
| 613 | bts->location_area_code = lac; |
| 614 | |
| 615 | return CMD_SUCCESS; |
| 616 | } |
| 617 | |
| 618 | DEFUN(cfg_bts_tsc, |
| 619 | cfg_bts_tsc_cmd, |
| 620 | "training_sequence_code <0-255>", |
| 621 | "Set the Training Sequence Code (TSC) of this BTS\n") |
| 622 | { |
| 623 | struct gsm_bts *bts = vty->index; |
| 624 | int tsc = atoi(argv[0]); |
| 625 | |
| 626 | if (tsc < 0 || tsc > 0xff) { |
| 627 | vty_out(vty, "%% TSC %d is not in the valid range (0-255)%s", |
| 628 | tsc, VTY_NEWLINE); |
| 629 | return CMD_WARNING; |
| 630 | } |
| 631 | bts->tsc = tsc; |
| 632 | |
| 633 | return CMD_SUCCESS; |
| 634 | } |
| 635 | |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 636 | DEFUN(cfg_bts_unit_id, |
| 637 | cfg_bts_unit_id_cmd, |
| 638 | "unit_id <0-65534> <0-255>", |
| 639 | "Set the BTS Unit ID of this BTS\n") |
| 640 | { |
| 641 | struct gsm_bts *bts = vty->index; |
| 642 | int site_id = atoi(argv[0]); |
| 643 | int bts_id = atoi(argv[1]); |
| 644 | |
| 645 | if (site_id < 0 || site_id > 65534) { |
| 646 | vty_out(vty, "%% Site ID %d is not in the valid range%s", |
| 647 | site_id, VTY_NEWLINE); |
| 648 | return CMD_WARNING; |
| 649 | } |
| 650 | if (site_id < 0 || site_id > 255) { |
| 651 | vty_out(vty, "%% BTS ID %d is not in the valid range%s", |
| 652 | bts_id, VTY_NEWLINE); |
| 653 | return CMD_WARNING; |
| 654 | } |
| 655 | bts->ip_access.site_id = site_id; |
| 656 | bts->ip_access.bts_id = bts_id; |
| 657 | |
| 658 | return CMD_SUCCESS; |
| 659 | } |
| 660 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 661 | /* per TRX configuration */ |
| 662 | DEFUN(cfg_trx, |
| 663 | cfg_trx_cmd, |
| 664 | "trx TRX_NR", |
| 665 | "Select a TRX to configure") |
| 666 | { |
| 667 | int trx_nr = atoi(argv[0]); |
| 668 | struct gsm_bts *bts = vty->index; |
| 669 | struct gsm_bts_trx *trx; |
| 670 | |
| 671 | if (trx_nr > BTS_MAX_TRX) { |
| 672 | vty_out(vty, "%% This version of OpenBSC only supports %u TRX%s", |
| 673 | BTS_MAX_TRX+1, VTY_NEWLINE); |
| 674 | return CMD_WARNING; |
| 675 | } |
| 676 | |
| 677 | if (trx_nr >= bts->num_trx) |
| 678 | bts->num_trx = trx_nr+1; |
| 679 | |
| 680 | trx = &bts->trx[trx_nr]; |
| 681 | |
| 682 | vty->index = trx; |
| 683 | vty->node = TRX_NODE; |
| 684 | |
| 685 | return CMD_SUCCESS; |
| 686 | } |
| 687 | |
| 688 | DEFUN(cfg_trx_arfcn, |
| 689 | cfg_trx_arfcn_cmd, |
| 690 | "arfcn <1-1024>", |
| 691 | "Set the ARFCN for this TRX\n") |
| 692 | { |
| 693 | int arfcn = atoi(argv[0]); |
| 694 | struct gsm_bts_trx *trx = vty->index; |
| 695 | |
| 696 | /* FIXME: check if this ARFCN is supported by this TRX */ |
| 697 | |
| 698 | trx->arfcn = arfcn; |
| 699 | |
| 700 | /* FIXME: patch ARFCN into SYSTEM INFORMATION */ |
| 701 | /* FIXME: use OML layer to update the ARFCN */ |
| 702 | /* FIXME: use RSL layer to update SYSTEM INFORMATION */ |
| 703 | |
| 704 | return CMD_SUCCESS; |
| 705 | } |
| 706 | |
| 707 | /* per TS configuration */ |
| 708 | DEFUN(cfg_ts, |
| 709 | cfg_ts_cmd, |
| 710 | "timeslot TS_NR", |
| 711 | "Select a Timeslot to configure") |
| 712 | { |
| 713 | int ts_nr = atoi(argv[0]); |
| 714 | struct gsm_bts_trx *trx = vty->index; |
| 715 | struct gsm_bts_trx_ts *ts; |
| 716 | |
| 717 | if (ts_nr >= TRX_NR_TS) { |
| 718 | vty_out(vty, "%% A GSM TRX only has %u Timeslots per TRX%s", |
| 719 | TRX_NR_TS, VTY_NEWLINE); |
| 720 | return CMD_WARNING; |
| 721 | } |
| 722 | |
| 723 | ts = &trx->ts[ts_nr]; |
| 724 | |
| 725 | vty->index = ts; |
| 726 | vty->node = TS_NODE; |
| 727 | |
| 728 | return CMD_SUCCESS; |
| 729 | } |
| 730 | |
| 731 | |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 732 | int bsc_vty_init(struct gsm_network *net) |
| 733 | { |
| 734 | gsmnet = net; |
| 735 | |
| 736 | cmd_init(1); |
| 737 | vty_init(); |
| 738 | |
| 739 | install_element(VIEW_NODE, &show_net_cmd); |
| 740 | install_element(VIEW_NODE, &show_bts_cmd); |
| 741 | install_element(VIEW_NODE, &show_trx_cmd); |
| 742 | install_element(VIEW_NODE, &show_ts_cmd); |
| 743 | install_element(VIEW_NODE, &show_lchan_cmd); |
Harald Welte | 1bc7735 | 2009-03-10 19:47:51 +0000 | [diff] [blame] | 744 | |
| 745 | install_element(VIEW_NODE, &show_e1drv_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 746 | install_element(VIEW_NODE, &show_e1line_cmd); |
| 747 | install_element(VIEW_NODE, &show_e1ts_cmd); |
| 748 | |
Harald Welte | f5025b6 | 2009-03-28 16:55:11 +0000 | [diff] [blame] | 749 | install_element(VIEW_NODE, &show_paging_cmd); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 750 | |
| 751 | install_element(CONFIG_NODE, &cfg_bts_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 752 | install_node(&bts_node, dummy_config_write); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 753 | install_default(BTS_NODE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 754 | install_element(BTS_NODE, &cfg_bts_type_cmd); |
| 755 | install_element(BTS_NODE, &cfg_bts_lac_cmd); |
| 756 | install_element(BTS_NODE, &cfg_bts_tsc_cmd); |
Harald Welte | 4cc3422 | 2009-05-01 15:12:31 +0000 | [diff] [blame] | 757 | install_element(BTS_NODE, &cfg_bts_unit_id_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 758 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 759 | install_element(BTS_NODE, &cfg_trx_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 760 | install_node(&trx_node, dummy_config_write); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 761 | install_default(TRX_NODE); |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 762 | install_element(TRX_NODE, &cfg_trx_arfcn_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 763 | |
Harald Welte | 5258fc4 | 2009-03-28 19:07:53 +0000 | [diff] [blame] | 764 | install_element(TRX_NODE, &cfg_ts_cmd); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 765 | install_node(&ts_node, dummy_config_write); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 766 | install_default(TS_NODE); |
Harald Welte | 68628e8 | 2009-03-10 12:17:57 +0000 | [diff] [blame] | 767 | |
| 768 | return 0; |
| 769 | } |