summaryrefslogtreecommitdiffstats
path: root/openbsc/src
diff options
context:
space:
mode:
authorIvan Kluchnikov <kluchnikovi@gmail.com>2016-04-08 10:44:28 +0300
committerIvan Kluchnikov <kluchnikovi@gmail.com>2016-04-19 14:29:09 +0300
commit67fd3b1a0281c87f4f83e2771b0d851930d1fdaa (patch)
treea10b332e0594d096bb21caa81300476f87bc2dc9 /openbsc/src
parente85e7910d22374ba33a347839aa17289f4b9a077 (diff)
Add support of virtual networks for sending network name to ms depending on imsifairwaves/master
Before sending mm info message to ms: - try to find virtual network with the imsi prefix which matches subscriber's imsi - if virtual network was found, use long and short network names of this virtual network for subscriber - if virtual network was not found, use long and short network names of main network for subscriber
Diffstat (limited to 'openbsc/src')
-rw-r--r--openbsc/src/libbsc/bsc_vty.c137
-rw-r--r--openbsc/src/libbsc/net_init.c1
-rw-r--r--openbsc/src/libcommon/common_vty.c19
-rw-r--r--openbsc/src/libcommon/gsm_data.c40
-rw-r--r--openbsc/src/libmsc/gsm_04_08.c42
-rw-r--r--openbsc/src/libmsc/smpp_vty.c10
6 files changed, 231 insertions, 18 deletions
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index d5f7394..c51b360 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -112,6 +112,12 @@ struct cmd_node net_node = {
1,
};
+struct cmd_node virt_net_node = {
+ VIRT_NET_NODE,
+ "%s(config-net-virt)# ",
+ 1,
+};
+
struct cmd_node bts_node = {
BTS_NODE,
"%s(config-net-bts)# ",
@@ -342,6 +348,43 @@ DEFUN(show_bts, show_bts_cmd, "show bts [<0-255>]",
return CMD_SUCCESS;
}
+static void virt_net_dump_vty(struct vty *vty, struct gsm_virt_network *virt_net)
+{
+ vty_out(vty, "Virtual network %u%s", virt_net->nr, VTY_NEWLINE);
+ if (strlen(virt_net->imsi_prefix)) {
+ vty_out(vty, " imsi-prefix %s%s", virt_net->imsi_prefix, VTY_NEWLINE);
+ }
+ vty_out(vty, " Long network name: '%s'%s",
+ virt_net->name_long, VTY_NEWLINE);
+ vty_out(vty, " Short network name: '%s'%s",
+ virt_net->name_short, VTY_NEWLINE);
+}
+
+DEFUN(show_virt_net, show_virt_net_cmd, "show virtual-network [<0-255>]",
+ SHOW_STR "Display information about a virtual network\n"
+ "Virtual network number")
+{
+ struct gsm_network *net = gsmnet_from_vty(vty);
+ int virt_net_nr;
+
+ if (argc != 0) {
+ /* use the virtual network number that the user has specified */
+ virt_net_nr = atoi(argv[0]);
+ if (virt_net_nr >= net->num_virt_net) {
+ vty_out(vty, "%% can't find virtual network '%s'%s", argv[0],
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ virt_net_dump_vty(vty, gsm_virt_net_num(net, virt_net_nr));
+ return CMD_SUCCESS;
+ }
+ /* print all virtual networks */
+ for (virt_net_nr = 0; virt_net_nr < net->num_virt_net; virt_net_nr++)
+ virt_net_dump_vty(vty, gsm_virt_net_num(net, virt_net_nr));
+
+ return CMD_SUCCESS;
+}
+
/* utility functions */
static void parse_e1_link(struct gsm_e1_subslot *e1_link, const char *line,
const char *ts, const char *ss)
@@ -748,6 +791,27 @@ static int config_write_bts(struct vty *v)
return CMD_SUCCESS;
}
+static void config_write_virt_net_single(struct vty *vty, struct gsm_virt_network *virt_net)
+{
+ vty_out(vty, " virtual-network %u%s", virt_net->nr, VTY_NEWLINE);
+ if (strlen(virt_net->imsi_prefix)) {
+ vty_out(vty, " imsi-prefix %s%s", virt_net->imsi_prefix, VTY_NEWLINE);
+ }
+ vty_out(vty, " name short %s%s", virt_net->name_short, VTY_NEWLINE);
+ vty_out(vty, " name long %s%s", virt_net->name_long, VTY_NEWLINE);
+}
+
+static int config_write_virt_net(struct vty *v)
+{
+ struct gsm_network *gsmnet = gsmnet_from_vty(v);
+ struct gsm_virt_network *virt_net;
+
+ llist_for_each_entry(virt_net, &gsmnet->virt_net_list, list)
+ config_write_virt_net_single(v, virt_net);
+
+ return CMD_SUCCESS;
+}
+
static int config_write_net(struct vty *vty)
{
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
@@ -1614,6 +1678,72 @@ DEFUN(cfg_net_exten_prefix,
return CMD_SUCCESS;
}
+DEFUN(cfg_virt_net,
+ cfg_virt_net_cmd,
+ "virtual-network <0-255>",
+ "Select a virtual network to configure\n"
+ "Virtual-network Number\n")
+{
+ struct gsm_network *gsmnet = gsmnet_from_vty(vty);
+ int virt_net_nr = atoi(argv[0]);
+ struct gsm_virt_network *virt_net;
+
+ if (virt_net_nr > gsmnet->num_virt_net) {
+ vty_out(vty, "%% The next unused Virtual-network number is %u%s",
+ gsmnet->num_virt_net, VTY_NEWLINE);
+ return CMD_WARNING;
+ } else if (virt_net_nr == gsmnet->num_virt_net) {
+ /* allocate a new one */
+ virt_net = gsm_virt_net_alloc_register(gsmnet);
+ } else
+ virt_net = gsm_virt_net_num(gsmnet, virt_net_nr);
+
+ if (!virt_net) {
+ vty_out(vty, "%% Unable to allocate Virtual-network %u%s",
+ gsmnet->num_virt_net, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ vty->index = virt_net;
+ vty->index_sub = NULL;
+ vty->node = VIRT_NET_NODE;
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_virt_net_imsi_prefix,
+ cfg_virt_net_imsi_prefix_cmd,
+ "imsi-prefix PREFIX",
+ "Set the IMSI prefix\n"
+ "Prefix\n")
+{
+ struct gsm_virt_network *virt_net = vty->index;
+ if (!osmo_is_digits(argv[0])) {
+ vty_out(vty, "%% PREFIX has to be numeric%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ snprintf(virt_net->imsi_prefix, sizeof(virt_net->imsi_prefix), "%s", argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_virt_net_name,
+ cfg_virt_net_name_cmd,
+ "name (short|long) NAME",
+ "Set the GSM network name\n"
+ "Short network name\n"
+ "Long network name\n"
+ NAME_CMD_STR NAME_STR)
+{
+ struct gsm_virt_network *virt_net = vty->index;
+
+ if (!strcmp(argv[0], "short"))
+ bsc_replace_string(virt_net->network, &virt_net->name_short, argv[1]);
+ else
+ bsc_replace_string(virt_net->network, &virt_net->name_long, argv[1]);
+
+ return CMD_SUCCESS;
+}
+
/* per-BTS configuration */
DEFUN(cfg_bts,
cfg_bts_cmd,
@@ -3772,6 +3902,7 @@ int bsc_vty_init(const struct log_info *cat)
install_element_ve(&show_net_cmd);
+ install_element_ve(&show_virt_net_cmd);
install_element_ve(&show_bts_cmd);
install_element_ve(&show_trx_cmd);
install_element_ve(&show_ts_cmd);
@@ -3820,6 +3951,12 @@ int bsc_vty_init(const struct log_info *cat)
install_element(GSMNET_NODE, &cfg_net_pag_any_tch_cmd);
install_element(GSMNET_NODE, &cfg_net_exten_prefix_cmd);
+ install_element(GSMNET_NODE, &cfg_virt_net_cmd);
+ install_node(&virt_net_node, config_write_virt_net);
+ vty_install_default(VIRT_NET_NODE);
+ install_element(VIRT_NET_NODE, &cfg_virt_net_imsi_prefix_cmd);
+ install_element(VIRT_NET_NODE, &cfg_virt_net_name_cmd);
+
install_element(GSMNET_NODE, &cfg_bts_cmd);
install_node(&bts_node, config_write_bts);
vty_install_default(BTS_NODE);
diff --git a/openbsc/src/libbsc/net_init.c b/openbsc/src/libbsc/net_init.c
index 16e8146..8564315 100644
--- a/openbsc/src/libbsc/net_init.c
+++ b/openbsc/src/libbsc/net_init.c
@@ -72,6 +72,7 @@ struct gsm_network *gsm_network_init(uint16_t country_code, uint16_t network_cod
INIT_LLIST_HEAD(&net->trans_list);
INIT_LLIST_HEAD(&net->upqueue);
INIT_LLIST_HEAD(&net->bts_list);
+ INIT_LLIST_HEAD(&net->virt_net_list);
net->stats.chreq.total = osmo_counter_alloc("net.chreq.total");
net->stats.chreq.no_channel = osmo_counter_alloc("net.chreq.no_channel");
diff --git a/openbsc/src/libcommon/common_vty.c b/openbsc/src/libcommon/common_vty.c
index 186fbe0..7bfbdbe 100644
--- a/openbsc/src/libcommon/common_vty.c
+++ b/openbsc/src/libcommon/common_vty.c
@@ -42,6 +42,15 @@ enum node_type bsc_vty_go_parent(struct vty *vty)
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
+ case VIRT_NET_NODE:
+ vty->node = GSMNET_NODE;
+ {
+ /* set vty->index correctly ! */
+ struct gsm_virt_network *virt_net = vty->index;
+ vty->index = virt_net->network;
+ vty->index_sub = NULL;
+ }
+ break;
case BTS_NODE:
vty->node = GSMNET_NODE;
{
@@ -141,3 +150,13 @@ void bsc_replace_string(void *ctx, char **dst, const char *newstr)
talloc_free(*dst);
*dst = talloc_strdup(ctx, newstr);
}
+
+int osmo_is_digits(const char *str)
+{
+ int i;
+ for (i = 0; i < strlen(str); i++) {
+ if (!isdigit(str[i]))
+ return 0;
+ }
+ return 1;
+}
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c
index 4ce4eca..f3503aa 100644
--- a/openbsc/src/libcommon/gsm_data.c
+++ b/openbsc/src/libcommon/gsm_data.c
@@ -192,6 +192,46 @@ const char *rrlp_mode_name(enum rrlp_mode mode)
return get_value_string(rrlp_mode_names, mode);
}
+struct gsm_virt_network *gsm_virt_net_alloc(void *ctx)
+{
+ struct gsm_virt_network *virt_net = talloc_zero(ctx, struct gsm_virt_network);
+ if (!virt_net)
+ return NULL;
+ return virt_net;
+}
+
+struct gsm_virt_network *gsm_virt_net_alloc_register(struct gsm_network *net)
+{
+ struct gsm_virt_network *virt_net;
+
+ virt_net = gsm_virt_net_alloc(net);
+ if (!virt_net)
+ return NULL;
+
+ virt_net->nr = net->num_virt_net++;
+ virt_net->network = net;
+ virt_net->name_short = talloc_strdup(net, "OpenBSC");
+ virt_net->name_long = talloc_strdup(net, "OpenBSC");
+
+ llist_add_tail(&virt_net->list, &net->virt_net_list);
+ return virt_net;
+}
+
+struct gsm_virt_network *gsm_virt_net_num(struct gsm_network *net, int num)
+{
+ struct gsm_virt_network *virt_net;
+
+ if (num >= net->num_virt_net)
+ return NULL;
+
+ llist_for_each_entry(virt_net, &net->virt_net_list, list) {
+ if (virt_net->nr == num)
+ return virt_net;
+ }
+
+ return NULL;
+}
+
static const struct value_string bts_gprs_mode_names[] = {
{ BTS_GPRS_NONE, "none" },
{ BTS_GPRS_GPRS, "gprs" },
diff --git a/openbsc/src/libmsc/gsm_04_08.c b/openbsc/src/libmsc/gsm_04_08.c
index 5a9e1ec..5f13661 100644
--- a/openbsc/src/libmsc/gsm_04_08.c
+++ b/openbsc/src/libmsc/gsm_04_08.c
@@ -681,6 +681,16 @@ static uint8_t bcdify(uint8_t value)
return ret;
}
+int is_prefix_match_imsi(char *imsi_prefix, char *imsi)
+{
+ size_t prefix_len = strlen(imsi_prefix);
+ size_t imsi_len = strlen(imsi);
+ if ((prefix_len <= imsi_len) &&
+ (strncmp(imsi, imsi_prefix, prefix_len) == 0)) {
+ return 1;
+ }
+ return 0;
+}
/* Section 9.2.15a */
int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
@@ -698,13 +708,29 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
int tzunits;
int dst = 0;
+ char *name_long = net->name_long;
+ char *name_short = net->name_short;
+ int virt_net_nr;
+
msg->lchan = conn->lchan;
gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
gh->proto_discr = GSM48_PDISC_MM;
gh->msg_type = GSM48_MT_MM_INFO;
- if (net->name_long) {
+ if (net->num_virt_net) {
+ for (virt_net_nr = 0; virt_net_nr < net->num_virt_net; virt_net_nr++) {
+ struct gsm_virt_network* virt_net = gsm_virt_net_num(net, virt_net_nr);
+ if (virt_net && strlen(virt_net->imsi_prefix) &&
+ is_prefix_match_imsi(virt_net->imsi_prefix, conn->subscr->imsi)) {
+ name_long = virt_net->name_long;
+ name_short = virt_net->name_short;
+ break;
+ }
+ }
+ }
+
+ if (name_long) {
#if 0
name_len = strlen(net->name_long);
/* 10.5.3.5a */
@@ -720,8 +746,8 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
/* FIXME: Use Cell Broadcast, not UCS-2, since
* UCS-2 is only supported by later revisions of the spec */
#endif
- name_len = (strlen(net->name_long)*7)/8;
- name_pad = (8 - strlen(net->name_long)*7)%8;
+ name_len = (strlen(name_long)*7)/8;
+ name_pad = (8 - strlen(name_long)*7)%8;
if (name_pad > 0)
name_len++;
/* 10.5.3.5a */
@@ -731,11 +757,11 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
ptr8 = msgb_put(msg, name_len);
- gsm_7bit_encode_n(ptr8, name_len, net->name_long, NULL);
+ gsm_7bit_encode_n(ptr8, name_len, name_long, NULL);
}
- if (net->name_short) {
+ if (name_short) {
#if 0
name_len = strlen(net->name_short);
/* 10.5.3.5a */
@@ -748,8 +774,8 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
for (i = 0; i < name_len; i++)
ptr16[i] = htons(net->name_short[i]);
#endif
- name_len = (strlen(net->name_short)*7)/8;
- name_pad = (8 - strlen(net->name_short)*7)%8;
+ name_len = (strlen(name_short)*7)/8;
+ name_pad = (8 - strlen(name_short)*7)%8;
if (name_pad > 0)
name_len++;
/* 10.5.3.5a */
@@ -759,7 +785,7 @@ int gsm48_tx_mm_info(struct gsm_subscriber_connection *conn)
ptr8[2] = 0x80 | name_pad; /* Cell Broadcast DCS, no CI */
ptr8 = msgb_put(msg, name_len);
- gsm_7bit_encode_n(ptr8, name_len, net->name_short, NULL);
+ gsm_7bit_encode_n(ptr8, name_len, name_short, NULL);
}
diff --git a/openbsc/src/libmsc/smpp_vty.c b/openbsc/src/libmsc/smpp_vty.c
index c0695fe..db67677 100644
--- a/openbsc/src/libmsc/smpp_vty.c
+++ b/openbsc/src/libmsc/smpp_vty.c
@@ -227,16 +227,6 @@ DEFUN(cfg_esme_no_passwd, cfg_esme_no_passwd_cmd,
return CMD_SUCCESS;
}
-static int osmo_is_digits(const char *str)
-{
- int i;
- for (i = 0; i < strlen(str); i++) {
- if (!isdigit(str[i]))
- return 0;
- }
- return 1;
-}
-
static const struct value_string route_errstr[] = {
{ -EEXIST, "Route already exists" },
{ -ENODEV, "Route does not exist" },