vty: Work on configuration of the MNCC to SIP gateway

We will add addressing by IMSI but right now let's focus on the
minimum of what needs to be there.
zecke/wip/sip-invite-cancel
Holger Hans Peter Freyther 7 years ago
parent 5b0d4618df
commit 11713d88e4
  1. 6
      doc/examples/osmo-sip-connector.cfg
  2. 48
      src/main.c
  3. 136
      src/vty.c
  4. 23
      src/vty.h

@ -0,0 +1,6 @@
app
mncc
socket-path /tmp/bsc_mncc
sip
local 0.0.0.0 5060
remote pbx 5060

@ -18,6 +18,8 @@
*
*/
#define _GNU_SOURCE
#include "evpoll.h"
#include "vty.h"
#include "logging.h"
@ -36,9 +38,13 @@
#include <sofia-sip/su_glib.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
void *tall_mncc_ctx;
static char *config_file = "osmo-sip-connector.cfg";
static struct log_info_cat mncc_sip_categories[] = {
[DSIP] = {
.name = "DSIP",
@ -62,6 +68,39 @@ static const struct log_info mncc_sip_info = {
.num_cat = ARRAY_SIZE(mncc_sip_categories),
};
static void print_help(void)
{
printf("Osmo MNCC to SIP bridge\n");
printf(" -h --hekp\tthis text\n");
printf(" -c --config-file NAME\tThe config file to use [%s]\n", config_file);
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"config-file", 1, 0, 'c'},
{NULL, 0, 0, 0}
};
c = getopt_long(argc, argv, "hc:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'h':
print_help();
exit(0);
case 'c':
config_file = optarg;
break;
}
}
}
int main(int argc, char **argv)
{
int rc;
@ -84,6 +123,15 @@ int main(int argc, char **argv)
sip_root = su_glib_root_create(NULL);
/* parsing and setup */
handle_options(argc, argv);
rc = vty_read_config_file(config_file, NULL);
if (rc < 0) {
LOGP(DAPP, LOGL_ERROR, "Can not parse config: %s %d\n",
config_file, rc);
exit(1);
}
LOGP(DAPP, LOGL_NOTICE, "VTY at %s %d\n",
vty_get_bind_addr(), OSMO_VTY_PORT_MNCC_SIP);
rc = telnet_init_dynif(tall_mncc_ctx, NULL,

@ -20,9 +20,33 @@
#include "vty.h"
#include <talloc.h>
extern void *tall_mncc_ctx;
struct app_config g_app;
static int mncc_vty_go_parent(struct vty *vty);
static int mncc_vty_is_config_node(struct vty *vty, int node);
static struct cmd_node sip_node = {
SIP_NODE,
"%s(config-sip)# ",
1,
};
static struct cmd_node mncc_node = {
MNCC_NODE,
"%s(config-mncc)# ",
1,
};
static struct cmd_node app_node = {
APP_NODE,
"%s(config-app)# ",
1,
};
static struct vty_app_info vty_info = {
.name = "OsmoMNCC",
.version = PACKAGE_VERSION,
@ -31,18 +55,124 @@ static struct vty_app_info vty_info = {
.copyright = "GNU AGPLv3+\n",
};
static int mncc_vty_go_parent(struct vty *vty)
{
return 0;
switch (vty->node) {
case SIP_NODE:
case MNCC_NODE:
case APP_NODE:
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
default:
if (mncc_vty_is_config_node(vty, vty->node))
vty->node = CONFIG_NODE;
else
vty->node = ENABLE_NODE;
vty->index = NULL;
break;
}
return vty->node;
}
static int mncc_vty_is_config_node(struct vty *vty, int node)
{
return 0;
return node >= SIP_NODE;
}
static int config_write_sip(struct vty *vty)
{
vty_out(vty, "sip%s", VTY_NEWLINE);
vty_out(vty, " local %s %d%s", g_app.sip.local_addr, g_app.sip.local_port, VTY_NEWLINE);
vty_out(vty, " remote %s %d%s", g_app.sip.remote_addr, g_app.sip.remote_port, VTY_NEWLINE);
return CMD_SUCCESS;
}
static int config_write_mncc(struct vty *vty)
{
vty_out(vty, "mncc%s", VTY_NEWLINE);
vty_out(vty, " socket-path %s%s", g_app.mncc.path, VTY_NEWLINE);
return CMD_SUCCESS;
}
static int config_write_app(struct vty *vty)
{
vty_out(vty, "app%s", VTY_NEWLINE);
return CMD_SUCCESS;
}
DEFUN(cfg_sip, cfg_sip_cmd,
"sip", "SIP related commands\n")
{
vty->node = SIP_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_sip_local_addr, cfg_sip_local_addr_cmd,
"local A.B.C.D <1-65534>",
"Local information\nIPv4 bind address\nport\n")
{
talloc_free((char *) g_app.sip.local_addr);
g_app.sip.local_addr = talloc_strdup(tall_mncc_ctx, argv[0]);
g_app.sip.local_port = atoi(argv[1]);
return CMD_SUCCESS;
}
DEFUN(cfg_sip_remote_addr, cfg_sip_remote_addr_cmd,
"remote ADDR <1-65534>",
"Remore information\nSIP hostname\nport\n")
{
talloc_free((char *) g_app.sip.remote_addr);
g_app.sip.remote_addr = talloc_strdup(tall_mncc_ctx, argv[0]);
g_app.sip.remote_port = atoi(argv[1]);
return CMD_SUCCESS;
}
DEFUN(cfg_mncc, cfg_mncc_cmd,
"mncc",
"MNCC\n")
{
vty->node = MNCC_NODE;
return CMD_SUCCESS;
}
DEFUN(cfg_mncc_path, cfg_mncc_path_cmd,
"socket-path NAME",
"MNCC filepath\nFilename\n")
{
talloc_free((char *) g_app.mncc.path);
g_app.mncc.path = talloc_strdup(tall_mncc_ctx, argv[0]);
return CMD_SUCCESS;
}
DEFUN(cfg_app, cfg_app_cmd,
"app", "Application Handling\n")
{
vty->node = APP_NODE;
return CMD_SUCCESS;
}
void mncc_sip_vty_init(void)
{
/* default values */
g_app.mncc.path = talloc_strdup(tall_mncc_ctx, "/tmp/bsc_mncc");
g_app.sip.local_addr = talloc_strdup(tall_mncc_ctx, "127.0.0.1");
g_app.sip.local_port = 5060;
g_app.sip.remote_addr = talloc_strdup(tall_mncc_ctx, "pbx");
g_app.sip.remote_port = 5060;
vty_init(&vty_info);
install_element(CONFIG_NODE, &cfg_sip_cmd);
install_node(&sip_node, config_write_sip);
install_element(SIP_NODE, &cfg_sip_local_addr_cmd);
install_element(SIP_NODE, &cfg_sip_remote_addr_cmd);
install_element(CONFIG_NODE, &cfg_mncc_cmd);
install_node(&mncc_node, config_write_mncc);
install_element(MNCC_NODE, &cfg_mncc_path_cmd);
install_element(CONFIG_NODE, &cfg_app_cmd);
install_node(&app_node, config_write_app);
}

@ -1,5 +1,28 @@
#pragma once
#include <osmocom/vty/command.h>
#include <osmocom/vty/vty.h>
enum {
SIP_NODE = _LAST_OSMOVTY_NODE + 1,
MNCC_NODE,
APP_NODE,
};
struct app_config {
struct {
const char *local_addr;
int local_port;
const char *remote_addr;
int remote_port;
} sip;
struct {
const char *path;
} mncc;
//int use_imsi_as_id;
};
void mncc_sip_vty_init();

Loading…
Cancel
Save