Configure PLMN over VTY and use it in HnbRegisterRequest

Change-Id: I6d67aa547d5496fe1407744e1dde07d2a41df500
This commit is contained in:
Pau Espin Pedrol
2021-10-28 18:55:31 +02:00
parent b4cc30ae1d
commit 3423fada07
4 changed files with 62 additions and 4 deletions

View File

@@ -25,6 +25,7 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/write_queue.h>
#include <osmocom/core/logging.h>
#include <osmocom/gsm/gsm23003.h>
enum {
DMAIN,
@@ -54,6 +55,7 @@ struct hnb_chan {
};
struct hnb {
struct osmo_plmn_id plmn;
struct {
char *local_addr;
uint16_t local_port;

View File

@@ -116,6 +116,11 @@ struct hnb *hnb_alloc(void *tall_ctx)
if (!hnb)
return NULL;
hnb->plmn = (struct osmo_plmn_id){
.mcc = 1,
.mnc = 1,
};
hnb->iuh.local_addr = talloc_strdup(hnb, "0.0.0.0");
hnb->iuh.local_port = 0;
hnb->iuh.remote_addr = talloc_strdup(hnb, "127.0.0.1");

View File

@@ -156,7 +156,7 @@ void hnb_send_register_req(struct hnb *hnb)
uint16_t lac, sac;
uint8_t rac;
uint32_t cid;
uint8_t plmn[] = {0x09, 0xf1, 0x99};
uint8_t plmn[3];
char identity[50] = "ATestHNB@";
HNBAP_HNBRegisterRequestIEs_t request;
@@ -175,10 +175,9 @@ void hnb_send_register_req(struct hnb *hnb)
request.hnB_Identity.hNB_Identity_Info.buf = (uint8_t*) identity;
request.hnB_Identity.hNB_Identity_Info.size = strlen(identity);
osmo_plmn_to_bcd(plmn, &hnb->plmn);
request.plmNidentity.buf = plmn;
request.plmNidentity.size = 3;
request.plmNidentity.size = sizeof(plmn);
memset(&request_out, 0, sizeof(request_out));
rc = hnbap_encode_hnbregisterrequesties(&request_out, &request);

View File

@@ -68,6 +68,7 @@ static struct cmd_node hnodeb_node = {
};
#define HNODEB_STR "Configure the HNodeB\n"
#define CODE_CMD_STR "Code commands\n"
DEFUN(cfg_hnodeb,
cfg_hnodeb_cmd,
@@ -80,6 +81,52 @@ DEFUN(cfg_hnodeb,
return CMD_SUCCESS;
}
DEFUN_USRATTR(cfg_hnodeb_ncc,
cfg_hnodeb_ncc_cmd,
0,
"network country code <1-999>",
"Set the GSM network country code\n"
"Country commands\n"
CODE_CMD_STR
"Network Country Code to use\n")
{
struct hnb *hnb = (struct hnb *)vty->index;
uint16_t mcc;
if (osmo_mcc_from_str(argv[0], &mcc)) {
vty_out(vty, "%% Error decoding MCC: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
hnb->plmn.mcc = mcc;
return CMD_SUCCESS;
}
DEFUN_USRATTR(cfg_hnodeb_mnc,
cfg_hnodeb_mnc_cmd,
0,
"mobile network code <0-999>",
"Set the GSM mobile network code\n"
"Network Commands\n"
CODE_CMD_STR
"Mobile Network Code to use\n")
{
struct hnb *hnb = (struct hnb *)vty->index;
uint16_t mnc;
bool mnc_3_digits;
if (osmo_mnc_from_str(argv[0], &mnc, &mnc_3_digits)) {
vty_out(vty, "%% Error decoding MNC: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
hnb->plmn.mnc = mnc;
hnb->plmn.mnc_3_digits = mnc_3_digits;
return CMD_SUCCESS;
}
static struct cmd_node iuh_node = {
IUH_NODE,
"%s(config-iuh)# ",
@@ -139,6 +186,9 @@ DEFUN(cfg_hnodeb_iuh_remote_port, cfg_hnodeb_iuh_remote_port_cmd,
static int config_write_hnodeb(struct vty *vty)
{
vty_out(vty, "hnodeb%s", VTY_NEWLINE);
vty_out(vty, " network country code %s%s", osmo_mcc_name(g_hnb->plmn.mcc), VTY_NEWLINE);
vty_out(vty, " mobile network code %s%s",
osmo_mnc_name(g_hnb->plmn.mnc, g_hnb->plmn.mnc_3_digits), VTY_NEWLINE);
vty_out(vty, " iuh%s", VTY_NEWLINE);
if (g_hnb->iuh.local_addr)
vty_out(vty, " local-ip %s%s", g_hnb->iuh.local_addr, VTY_NEWLINE);
@@ -254,6 +304,8 @@ void hnb_vty_init(void)
{
install_element(CONFIG_NODE, &cfg_hnodeb_cmd);
install_node(&hnodeb_node, config_write_hnodeb);
install_element(HNODEB_NODE, &cfg_hnodeb_ncc_cmd);
install_element(HNODEB_NODE, &cfg_hnodeb_mnc_cmd);
install_element(HNODEB_NODE, &cfg_hnodeb_iuh_cmd);
install_node(&iuh_node, NULL);
install_element(IUH_NODE, &cfg_hnodeb_iuh_local_ip_cmd);