ctrl: Introduce cmd SET subscriber.create <imsi>
Create a new subscriber from CTRL, similar to VTY command "imsi IDENT create". On success SET_REPLY contains the ID of the newly created subscriber. Related: SYS#5993 Change-Id: Id1b760cd07712245a0eeabaac7891bce93c1fe8echanges/18/28318/4
parent
e427bb299f
commit
d63ec88dba
|
@ -11,6 +11,7 @@ enum {
|
|||
DMSLOOKUP,
|
||||
DLU,
|
||||
DDGSM,
|
||||
DCTRL,
|
||||
};
|
||||
|
||||
extern const struct log_info hlr_log_info;
|
||||
|
|
39
src/ctrl.c
39
src/ctrl.c
|
@ -197,6 +197,43 @@ static void print_subscr_info_aud3g(struct ctrl_cmd *cmd, struct osmo_sub_auth_d
|
|||
aud->u.umts.sqn);
|
||||
}
|
||||
|
||||
CTRL_CMD_DEFINE_WO_NOVRF(subscr_create, "create");
|
||||
static int set_subscr_create(struct ctrl_cmd *cmd, void *data)
|
||||
{
|
||||
struct hlr_subscriber subscr;
|
||||
struct hlr *hlr = data;
|
||||
const char *imsi = cmd->value;
|
||||
int rc;
|
||||
|
||||
if (!osmo_imsi_str_valid(imsi)) {
|
||||
cmd->reply = "Invalid IMSI value.";
|
||||
return CTRL_CMD_ERROR;
|
||||
}
|
||||
|
||||
/* Create the subscriber in the DB */
|
||||
rc = db_subscr_create(g_hlr->dbc, imsi, DB_SUBSCR_FLAG_NAM_CS | DB_SUBSCR_FLAG_NAM_PS);
|
||||
if (rc) {
|
||||
if (rc == -EEXIST)
|
||||
cmd->reply = "Subscriber already exists.";
|
||||
else
|
||||
cmd->reply = "Cannot create subscriber.";
|
||||
return CTRL_CMD_ERROR;
|
||||
}
|
||||
|
||||
LOGP(DCTRL, LOGL_INFO, "Created subscriber IMSI='%s'\n",
|
||||
imsi);
|
||||
|
||||
/* Retrieve data of newly created subscriber: */
|
||||
rc = db_subscr_get_by_imsi(hlr->dbc, imsi, &subscr);
|
||||
if (rc < 0) {
|
||||
cmd->reply = "Failed retrieving ID of newly created subscriber.";
|
||||
return CTRL_CMD_ERROR;
|
||||
}
|
||||
|
||||
cmd->reply = talloc_asprintf(cmd, "%" PRIu64, subscr.id);
|
||||
return CTRL_CMD_REPLY;
|
||||
}
|
||||
|
||||
CTRL_CMD_DEFINE_RO(subscr_info, "info");
|
||||
static int get_subscr_info(struct ctrl_cmd *cmd, void *data)
|
||||
{
|
||||
|
@ -380,6 +417,8 @@ static int hlr_ctrl_cmds_install()
|
|||
{
|
||||
int rc = 0;
|
||||
|
||||
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR, &cmd_subscr_create);
|
||||
|
||||
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info);
|
||||
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_aud);
|
||||
rc |= ctrl_cmd_install(CTRL_NODE_SUBSCR_BY, &cmd_subscr_info_all);
|
||||
|
|
|
@ -43,6 +43,12 @@ const struct log_info_cat hlr_log_info_cat[] = {
|
|||
.color = "\033[1;35m",
|
||||
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
[DCTRL] = {
|
||||
.name = "DCTRL",
|
||||
.description = "Osmocom CTRL interface",
|
||||
.color = "\033[1;30m",
|
||||
.enabled = 1, .loglevel = LOGL_NOTICE,
|
||||
},
|
||||
};
|
||||
|
||||
const struct log_info hlr_log_info = {
|
||||
|
|
|
@ -610,3 +610,17 @@ periodic_lu_timer 0
|
|||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
||||
SET 101 subscriber.create 901991234567891
|
||||
SET_REPLY 101 subscriber.create 124
|
||||
|
||||
GET 102 subscriber.by-id-124.info
|
||||
GET_REPLY 102 subscriber.by-id-124.info
|
||||
id 124
|
||||
imsi 901991234567891
|
||||
nam_cs 1
|
||||
nam_ps 1
|
||||
ms_purged_cs 0
|
||||
ms_purged_ps 0
|
||||
periodic_lu_timer 0
|
||||
periodic_rau_tau_timer 0
|
||||
lmsi 00000000
|
||||
|
|
|
@ -108,3 +108,9 @@ ERROR 47 Invalid value part of 'by-xxx-value' selector.
|
|||
|
||||
GET 48 subscriber.by-id-0x0123.info
|
||||
ERROR 48 Invalid value part of 'by-xxx-value' selector.
|
||||
|
||||
SET 49 subscriber.create zzz
|
||||
ERROR 49 Invalid IMSI value.
|
||||
|
||||
SET 50 subscriber.create 901990000000001
|
||||
ERROR 50 Subscriber already exists.
|
||||
|
|
Loading…
Reference in New Issue