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