diff options
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/include/vty/command.h | 1 | ||||
-rw-r--r-- | openbsc/include/vty/vty.h | 4 | ||||
-rw-r--r-- | openbsc/src/vty/command.c | 17 | ||||
-rw-r--r-- | openbsc/src/vty/vty.c | 49 | ||||
-rw-r--r-- | openbsc/src/vty_interface.c | 119 |
5 files changed, 165 insertions, 25 deletions
diff --git a/openbsc/include/vty/command.h b/openbsc/include/vty/command.h index f536f2e02..1be05aa8e 100644 --- a/openbsc/include/vty/command.h +++ b/openbsc/include/vty/command.h @@ -61,6 +61,7 @@ struct host { /* There are some command levels which called from command node. */ enum node_type { + GSMNET_NODE, BTS_NODE, TRX_NODE, TS_NODE, diff --git a/openbsc/include/vty/vty.h b/openbsc/include/vty/vty.h index ab34cd3b7..4a1a6ff08 100644 --- a/openbsc/include/vty/vty.h +++ b/openbsc/include/vty/vty.h @@ -129,6 +129,7 @@ static inline char *vty_newline(struct vty *vty) /* Prototypes. */ void vty_init (void); +int vty_read_config_file(const char *file_name); void vty_init_vtysh (void); void vty_reset (void); struct vty *vty_new (void); @@ -136,8 +137,7 @@ struct vty *vty_create (int vty_sock, void *priv); int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); int vty_out_newline(struct vty *); int vty_read(struct vty *vty); -void vty_read_config (char *, char *); -void vty_time_print (struct vty *, int); +//void vty_time_print (struct vty *, int); void vty_close (struct vty *); char *vty_get_cwd (void); void vty_log (const char *level, const char *proto, const char *fmt, va_list); diff --git a/openbsc/src/vty/command.c b/openbsc/src/vty/command.c index 6173292a0..16e0dfb36 100644 --- a/openbsc/src/vty/command.c +++ b/openbsc/src/vty/command.c @@ -507,7 +507,6 @@ static char *zencrypt(const char *passwd) /* This function write configuration of this host. */ static int config_write_host(struct vty *vty) { -#if 0 if (host.name) vty_out(vty, "hostname %s%s", host.name, VTY_NEWLINE); @@ -527,6 +526,7 @@ static int config_write_host(struct vty *vty) VTY_NEWLINE); } +#if 0 if (zlog_default->default_lvl != LOG_DEBUG) { vty_out(vty, "! N.B. The 'log trap' command is deprecated.%s", VTY_NEWLINE); @@ -579,7 +579,7 @@ static int config_write_host(struct vty *vty) if (zlog_default->record_priority == 1) vty_out(vty, "log record-priority%s", VTY_NEWLINE); - +#endif if (host.advanced) vty_out(vty, "service advanced-vty%s", VTY_NEWLINE); @@ -596,7 +596,6 @@ static int config_write_host(struct vty *vty) else if (!host.motd) vty_out(vty, "no banner motd%s", VTY_NEWLINE); -#endif return 1; } @@ -2289,10 +2288,18 @@ DEFUN(config_exit, config_exit_cmd, "exit", "Exit current mode and down to previous mode\n") { switch (vty->node) { - case BTS_NODE: - vty->node = VIEW_NODE; + case GSMNET_NODE: + vty->node = CONFIG_NODE; vty->index = NULL; break; + case BTS_NODE: + vty->node = GSMNET_NODE; + { + /* set vty->index correctly ! */ + struct gsm_bts *bts = vty->index; + vty->index = bts->network; + } + break; case TRX_NODE: vty->node = BTS_NODE; { diff --git a/openbsc/src/vty/vty.c b/openbsc/src/vty/vty.c index 9962474c8..5472fa05a 100644 --- a/openbsc/src/vty/vty.c +++ b/openbsc/src/vty/vty.c @@ -1373,6 +1373,39 @@ int vty_read(struct vty *vty) return 0; } +/* Read up configuration file */ +static int +vty_read_file(FILE *confp) +{ + int ret; + struct vty *vty; + + vty = vty_new(); + vty->fd = 0; + vty->type = VTY_FILE; + vty->node = CONFIG_NODE; + + ret = config_from_file(vty, confp); + + if (ret != CMD_SUCCESS) { + switch (ret) { + case CMD_ERR_AMBIGUOUS: + fprintf(stderr, "Ambiguous command.\n"); + break; + case CMD_ERR_NO_MATCH: + fprintf(stderr, "Ther is no such command.\n"); + break; + } + fprintf(stderr, "Error occurred during reading below " + "line:\n%s\n", vty->buf); + vty_close(vty); + return -EINVAL; + } + + vty_close(vty); + return 0; +} + /* Create new vty structure. */ struct vty * vty_create (int vty_sock, void *priv) @@ -1648,7 +1681,19 @@ void vty_init() #endif } -static __attribute__((constructor)) void on_dso_load_vty(void) +int vty_read_config_file(const char *file_name) { - tall_vty_ctx = talloc_named_const(NULL, 1, "vty"); + FILE *cfile; + int rc; + + cfile = fopen(file_name, "r"); + if (!cfile) + return -ENOENT; + + rc = vty_read_file(cfile); + fclose(cfile); + + host_config_set(file_name); + + return rc; } diff --git a/openbsc/src/vty_interface.c b/openbsc/src/vty_interface.c index 6d1ec96d1..50da4a053 100644 --- a/openbsc/src/vty_interface.c +++ b/openbsc/src/vty_interface.c @@ -35,9 +35,16 @@ #include <openbsc/abis_nm.h> #include <openbsc/gsm_utils.h> #include <openbsc/db.h> +#include <openbsc/talloc.h> static struct gsm_network *gsmnet; +struct cmd_node net_node = { + GSMNET_NODE, + "%s(network)#", + 1, +}; + struct cmd_node bts_node = { BTS_NODE, "%s(bts)#", @@ -161,10 +168,10 @@ DEFUN(show_bts, show_bts_cmd, "show bts [number]", static void config_write_ts_single(struct vty *vty, struct gsm_bts_trx_ts *ts) { - vty_out(vty, "\t\tts %u%s", ts->nr, VTY_NEWLINE); - vty_out(vty, "\t\t\tphys_chan_config %s%s", gsm_pchan_name(ts->pchan), + vty_out(vty, " ts %u%s", ts->nr, VTY_NEWLINE); + vty_out(vty, " phys_chan_config %s%s", gsm_pchan_name(ts->pchan), VTY_NEWLINE); - vty_out(vty, "\t\t\te1_subslot %u %u %u%s", ts->e1_link.e1_nr, + vty_out(vty, " e1_subslot %u %u %u%s", ts->e1_link.e1_nr, ts->e1_link.e1_ts, ts->e1_link.e1_ts_ss, VTY_NEWLINE); } @@ -172,9 +179,9 @@ static void config_write_trx_single(struct vty *vty, struct gsm_bts_trx *trx) { int i; - vty_out(vty, "\ttrx %u%s", trx->nr, VTY_NEWLINE); - vty_out(vty, "\t\tarfcn %u%s", trx->arfcn, VTY_NEWLINE); - vty_out(vty, "\t\tmax_power_red %u%s", trx->max_power_red, VTY_NEWLINE); + vty_out(vty, " trx %u%s", trx->nr, VTY_NEWLINE); + vty_out(vty, " arfcn %u%s", trx->arfcn, VTY_NEWLINE); + vty_out(vty, " max_power_red %u%s", trx->max_power_red, VTY_NEWLINE); for (i = 0; i < TRX_NR_TS; i++) config_write_ts_single(vty, &trx->ts[i]); @@ -184,15 +191,15 @@ static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts) { struct gsm_bts_trx *trx; - vty_out(vty, "bts %u%s", bts->nr, VTY_NEWLINE); - vty_out(vty, "\ttype %s%s", btstype2str(bts->type), VTY_NEWLINE); - vty_out(vty, "\tband %s%s", gsm_band_name(bts->band), VTY_NEWLINE); - vty_out(vty, "\tlocation_area_code %u%s", bts->location_area_code, + vty_out(vty, " bts %u%s", bts->nr, VTY_NEWLINE); + vty_out(vty, " type %s%s", btstype2str(bts->type), VTY_NEWLINE); + vty_out(vty, " band %s%s", gsm_band_name(bts->band), VTY_NEWLINE); + vty_out(vty, " location_area_code %u%s", bts->location_area_code, VTY_NEWLINE); - vty_out(vty, "\ttraining_sequence_code %u%s", bts->tsc, VTY_NEWLINE); - vty_out(vty, "\tbase_station_id_code %u%s", bts->bsic, VTY_NEWLINE); + vty_out(vty, " training_sequence_code %u%s", bts->tsc, VTY_NEWLINE); + vty_out(vty, " base_station_id_code %u%s", bts->bsic, VTY_NEWLINE); if (is_ipaccess_bts(bts)) - vty_out(vty, "\tunit_id %u %u%s", + vty_out(vty, " ip.access unit_id %u %u%s", bts->ip_access.site_id, bts->ip_access.bts_id, VTY_NEWLINE); llist_for_each_entry(trx, &bts->trx_list, list) @@ -209,6 +216,16 @@ static int config_write_bts(struct vty *v) return CMD_SUCCESS; } +static int config_write_net(struct vty *vty) +{ + vty_out(vty, "network%s", VTY_NEWLINE); + vty_out(vty, " country code %u%s", gsmnet->country_code, VTY_NEWLINE); + vty_out(vty, " mobile network code %u%s", gsmnet->network_code, VTY_NEWLINE); + vty_out(vty, " short name '%s'%s", gsmnet->name_short, VTY_NEWLINE); + vty_out(vty, " long name '%s'%s", gsmnet->name_long, VTY_NEWLINE); + + return CMD_SUCCESS; +} static void trx_dump_vty(struct vty *vty, struct gsm_bts_trx *trx) { @@ -656,6 +673,63 @@ DEFUN(cfg_subscr, return CMD_SUCCESS; } +DEFUN(cfg_net, + cfg_net_cmd, + "network", + "Configure the GSM network") +{ + vty->index = gsmnet; + vty->node = GSMNET_NODE; + + return CMD_SUCCESS; +} + + +DEFUN(cfg_net_ncc, + cfg_net_ncc_cmd, + "network country code <1-999>", + "Set the GSM network country code") +{ + gsmnet->country_code = atoi(argv[0]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_net_mnc, + cfg_net_mnc_cmd, + "mobile network code <1-999>", + "Set the GSM mobile network code") +{ + gsmnet->network_code = atoi(argv[0]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_net_name_short, + cfg_net_name_short_cmd, + "short name NAME", + "Set the short GSM network name") +{ + if (gsmnet->name_short) + talloc_free(gsmnet->name_short); + + gsmnet->name_short = talloc_strdup(gsmnet, argv[0]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_net_name_long, + cfg_net_name_long_cmd, + "long name NAME", + "Set the long GSM network name") +{ + if (gsmnet->name_long) + talloc_free(gsmnet->name_long); + + gsmnet->name_long = talloc_strdup(gsmnet, argv[0]); + + return CMD_SUCCESS; +} /* per-BTS configuration */ DEFUN(cfg_bts, @@ -774,8 +848,8 @@ DEFUN(cfg_bts_bsic, DEFUN(cfg_bts_unit_id, cfg_bts_unit_id_cmd, - "unit_id <0-65534> <0-255>", - "Set the BTS Unit ID of this BTS\n") + "ip.access unit_id <0-65534> <0-255>", + "Set the ip.access BTS Unit ID of this BTS\n") { struct gsm_bts *bts = vty->index; int site_id = atoi(argv[0]); @@ -791,6 +865,12 @@ DEFUN(cfg_bts_unit_id, bts_id, VTY_NEWLINE); return CMD_WARNING; } + + if (!is_ipaccess_bts(bts)) { + vty_out(vty, "%% BTS is not of ip.access type%s", VTY_NEWLINE); + return CMD_WARNING; + } + bts->ip_access.site_id = site_id; bts->ip_access.bts_id = bts_id; @@ -1141,7 +1221,14 @@ int bsc_vty_init(struct gsm_network *net) install_element(VIEW_NODE, &sms_send_ext_cmd); install_element(VIEW_NODE, &sms_send_imsi_cmd); - install_element(CONFIG_NODE, &cfg_bts_cmd); + install_element(CONFIG_NODE, &cfg_net_cmd); + install_node(&net_node, config_write_net); + install_default(GSMNET_NODE); + install_element(GSMNET_NODE, &cfg_net_mnc_cmd); + install_element(GSMNET_NODE, &cfg_net_name_short_cmd); + install_element(GSMNET_NODE, &cfg_net_name_long_cmd); + + install_element(GSMNET_NODE, &cfg_bts_cmd); install_node(&bts_node, config_write_bts); install_default(BTS_NODE); install_element(BTS_NODE, &cfg_bts_type_cmd); |