From 40f828936f733bf12bd5d06a1097043812ea339a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 23 May 2009 17:31:39 +0000 Subject: [PATCH] show and edit subscribers from the vty interface --- include/openbsc/gsm_subscriber.h | 2 +- include/vty/command.h | 1 + src/vty/command.c | 5 ++ src/vty_interface.c | 117 +++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 1 deletion(-) diff --git a/include/openbsc/gsm_subscriber.h b/include/openbsc/gsm_subscriber.h index 7da896e8b..46b674b1f 100644 --- a/include/openbsc/gsm_subscriber.h +++ b/include/openbsc/gsm_subscriber.h @@ -12,7 +12,7 @@ #define GSM_EXTENSION_LENGTH 128 struct gsm_subscriber { - u_int64_t id; + long unsigned int id; char imsi[GSM_IMSI_LENGTH]; char tmsi[GSM_TMSI_LENGTH]; u_int16_t lac; diff --git a/include/vty/command.h b/include/vty/command.h index 26022cb02..f536f2e02 100644 --- a/include/vty/command.h +++ b/include/vty/command.h @@ -64,6 +64,7 @@ enum node_type { BTS_NODE, TRX_NODE, TS_NODE, + SUBSCR_NODE, AUTH_NODE, /* Authentication mode of vty interface. */ VIEW_NODE, /* View node. Default mode of vty interface. */ diff --git a/src/vty/command.c b/src/vty/command.c index f4242626b..94a5c2af2 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -2312,6 +2312,11 @@ DEFUN(config_exit, vty->index = ts->trx; } break; + case SUBSCR_NODE: + vty->node = VIEW_NODE; + subscr_put(vty->index); + vty->index = NULL; + break; case VIEW_NODE: case ENABLE_NODE: if (0) //vty_shell (vty)) diff --git a/src/vty_interface.c b/src/vty_interface.c index a6bfdf23a..44531dd50 100644 --- a/src/vty_interface.c +++ b/src/vty_interface.c @@ -32,6 +32,7 @@ #include #include #include +#include static struct gsm_network *gsmnet; @@ -53,6 +54,12 @@ struct cmd_node ts_node = { 1, }; +struct cmd_node subscr_node = { + SUBSCR_NODE, + "%s(subscriber)#", + 1, +}; + static int dummy_config_write(struct vty *v) { return CMD_SUCCESS; @@ -290,6 +297,8 @@ DEFUN(show_ts, static void subscr_dump_vty(struct vty *vty, struct gsm_subscriber *subscr) { + vty_out(vty, " ID: %lu, Authorized: %d%s", subscr->id, + subscr->authorized, VTY_NEWLINE); if (subscr->name) vty_out(vty, " Name: '%s'%s", subscr->name, VTY_NEWLINE); if (subscr->extension) @@ -562,6 +571,29 @@ DEFUN(show_paging, return CMD_SUCCESS; } +/* per-subscriber configuration */ +DEFUN(cfg_subscr, + cfg_subscr_cmd, + "subscriber IMSI", + "Select a Subscriber to configure\n") +{ + const char *imsi = argv[0]; + struct gsm_subscriber *subscr; + + subscr = subscr_get_by_imsi(imsi); + if (!subscr) { + vty_out(vty, "%% No subscriber for IMSI %s%s", + imsi, VTY_NEWLINE); + return CMD_WARNING; + } + + vty->index = subscr; + vty->node = SUBSCR_NODE; + + return CMD_SUCCESS; +} + + /* per-BTS configuration */ DEFUN(cfg_bts, cfg_bts_cmd, @@ -748,6 +780,82 @@ DEFUN(cfg_ts, } +/* Subscriber */ +DEFUN(show_subscr, + show_subscr_cmd, + "show subscriber [IMSI]", + SHOW_STR "Display information about a subscriber\n") +{ + const char *imsi; + struct gsm_subscriber *subscr; + + if (argc >= 1) { + imsi = argv[0]; + subscr = subscr_get_by_imsi(imsi); + if (!subscr) { + vty_out(vty, "%% unknown subscriber%s", + VTY_NEWLINE); + return CMD_WARNING; + } + subscr_dump_vty(vty, subscr); + + return CMD_SUCCESS; + } + + /* FIXME: iterate over all subscribers ? */ + return CMD_WARNING; + + return CMD_SUCCESS; +} + +DEFUN(cfg_subscr_name, + cfg_subscr_name_cmd, + "name NAME", + "Set the name of the subscriber") +{ + const char *name = argv[0]; + struct gsm_subscriber *subscr = vty->index; + + strncpy(subscr->name, name, sizeof(subscr->name)); + + db_sync_subscriber(subscr); + + return CMD_SUCCESS; +} + +DEFUN(cfg_subscr_extension, + cfg_subscr_extension_cmd, + "extension EXTENSION", + "Set the extension of the subscriber") +{ + const char *name = argv[0]; + struct gsm_subscriber *subscr = vty->index; + + strncpy(subscr->extension, name, sizeof(subscr->extension)); + + db_sync_subscriber(subscr); + + return CMD_SUCCESS; +} + +DEFUN(cfg_subscr_authorized, + cfg_subscr_authorized_cmd, + "auth <0-1>", + "Set the authorization status of the subscriber") +{ + int auth = atoi(argv[0]); + struct gsm_subscriber *subscr = vty->index; + + if (auth) + subscr->authorized = 1; + else + subscr->authorized = 0; + + db_sync_subscriber(subscr); + + return CMD_SUCCESS; +} + int bsc_vty_init(struct gsm_network *net) { gsmnet = net; @@ -767,6 +875,8 @@ int bsc_vty_init(struct gsm_network *net) install_element(VIEW_NODE, &show_paging_cmd); + install_element(VIEW_NODE, &show_subscr_cmd); + install_element(CONFIG_NODE, &cfg_bts_cmd); install_node(&bts_node, dummy_config_write); install_default(BTS_NODE); @@ -784,5 +894,12 @@ int bsc_vty_init(struct gsm_network *net) install_node(&ts_node, dummy_config_write); install_default(TS_NODE); + install_element(CONFIG_NODE, &cfg_subscr_cmd); + install_node(&subscr_node, dummy_config_write); + install_default(SUBSCR_NODE); + install_element(SUBSCR_NODE, &cfg_subscr_name_cmd); + install_element(SUBSCR_NODE, &cfg_subscr_extension_cmd); + install_element(SUBSCR_NODE, &cfg_subscr_authorized_cmd); + return 0; }