mncc: Add code to manage the mncc connection for CC
Connect, re-connect and read messages from the MNCC socket. Dispatch the event in case the system got disconnected. Move the app definition to app.h and use it everywhere. Begin with a new call for mncc.
This commit is contained in:
parent
80095748f9
commit
9d12a7c34c
|
@ -2,7 +2,11 @@ bin_PROGRAMS = osmo-sip-connector
|
||||||
|
|
||||||
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(SOFIASIP_CFLAGS)
|
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(SOFIASIP_CFLAGS)
|
||||||
|
|
||||||
|
noinst_HEADERS = \
|
||||||
|
evpoll.h vty.h mncc_protocol.h app.h mncc.h
|
||||||
|
|
||||||
osmo_sip_connector_SOURCES = \
|
osmo_sip_connector_SOURCES = \
|
||||||
|
mncc.c \
|
||||||
evpoll.c \
|
evpoll.c \
|
||||||
vty.c \
|
vty.c \
|
||||||
main.c
|
main.c
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mncc.h"
|
||||||
|
|
||||||
|
struct app_config {
|
||||||
|
struct {
|
||||||
|
const char *local_addr;
|
||||||
|
int local_port;
|
||||||
|
|
||||||
|
const char *remote_addr;
|
||||||
|
int remote_port;
|
||||||
|
} sip;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
const char *path;
|
||||||
|
struct mncc_connection conn;
|
||||||
|
} mncc;
|
||||||
|
|
||||||
|
//int use_imsi_as_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct app_config g_app;
|
|
@ -23,6 +23,8 @@
|
||||||
#include "evpoll.h"
|
#include "evpoll.h"
|
||||||
#include "vty.h"
|
#include "vty.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
#include "mncc.h"
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
#include <osmocom/core/application.h>
|
#include <osmocom/core/application.h>
|
||||||
#include <osmocom/core/utils.h>
|
#include <osmocom/core/utils.h>
|
||||||
|
@ -139,7 +141,8 @@ int main(int argc, char **argv)
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
|
mncc_connection_init(&g_app.mncc.conn, &g_app);
|
||||||
|
mncc_connection_start(&g_app.mncc.conn);
|
||||||
|
|
||||||
/* marry sofia-sip to glib and glib to libosmocore */
|
/* marry sofia-sip to glib and glib to libosmocore */
|
||||||
loop = g_main_loop_new(NULL, FALSE);
|
loop = g_main_loop_new(NULL, FALSE);
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* (C) 2016 by Holger Hans Peter Freyther
|
||||||
|
*
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mncc.h"
|
||||||
|
#include "app.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
|
#include <osmocom/core/socket.h>
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
static void mncc_reconnect(void *data)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
struct mncc_connection *conn = data;
|
||||||
|
|
||||||
|
rc = osmo_sock_unix_init_ofd(&conn->fd, SOCK_SEQPACKET, 0,
|
||||||
|
conn->app->mncc.path, OSMO_SOCK_F_CONNECT);
|
||||||
|
if (rc < 0) {
|
||||||
|
LOGP(DMNCC, LOGL_ERROR, "Failed to connect(%s). Retrying\n",
|
||||||
|
conn->app->mncc.path);
|
||||||
|
osmo_timer_schedule(&conn->reconnect, 5, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGP(DMNCC, LOGL_NOTICE, "Reconnected to %s\n", conn->app->mncc.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int mncc_data(struct osmo_fd *fd, unsigned int what)
|
||||||
|
{
|
||||||
|
char buf[4096];
|
||||||
|
int rc;
|
||||||
|
struct mncc_connection *conn = fd->data;
|
||||||
|
|
||||||
|
rc = read(fd->fd, buf, sizeof(buf));
|
||||||
|
if (rc <= 0) {
|
||||||
|
LOGP(DMNCC, LOGL_ERROR, "Failed to read %d/%s. Re-connecting.\n",
|
||||||
|
rc, strerror(errno));
|
||||||
|
osmo_fd_unregister(fd);
|
||||||
|
close(fd->fd);
|
||||||
|
osmo_timer_schedule(&conn->reconnect, 5, 0);
|
||||||
|
if (conn->on_disconnect)
|
||||||
|
conn->on_disconnect(conn);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mncc_connection_init(struct mncc_connection *conn, struct app_config *cfg)
|
||||||
|
{
|
||||||
|
conn->reconnect.cb = mncc_reconnect;
|
||||||
|
conn->reconnect.data = conn;
|
||||||
|
conn->fd.cb = mncc_data;
|
||||||
|
conn->fd.data = conn;
|
||||||
|
conn->app = cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mncc_connection_start(struct mncc_connection *conn)
|
||||||
|
{
|
||||||
|
LOGP(DMNCC, LOGL_NOTICE, "Scheduling MNCC connect\n");
|
||||||
|
osmo_timer_schedule(&conn->reconnect, 0, 0);
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <osmocom/core/select.h>
|
||||||
|
#include <osmocom/core/timer.h>
|
||||||
|
|
||||||
|
struct app_config;
|
||||||
|
|
||||||
|
struct mncc_connection {
|
||||||
|
struct app_config *app;
|
||||||
|
struct osmo_fd fd;
|
||||||
|
|
||||||
|
struct osmo_timer_list reconnect;
|
||||||
|
|
||||||
|
|
||||||
|
/* callback for application logic */
|
||||||
|
void (*on_disconnect)(struct mncc_connection *);
|
||||||
|
};
|
||||||
|
|
||||||
|
void mncc_connection_init(struct mncc_connection *conn, struct app_config *cfg);
|
||||||
|
void mncc_connection_start(struct mncc_connection *conn);
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "vty.h"
|
#include "vty.h"
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
#include <talloc.h>
|
#include <talloc.h>
|
||||||
|
|
||||||
|
|
16
src/vty.h
16
src/vty.h
|
@ -9,20 +9,4 @@ enum {
|
||||||
APP_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();
|
void mncc_sip_vty_init();
|
||||||
|
|
Loading…
Reference in New Issue