aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-01-13 07:28:31 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-02-18 21:00:58 +0100
commit2d8d7e62c1fc902a8495610f335c6e65cc1003d4 (patch)
tree2b6b9d6c5de26bd4eab6490c9825fd97eb6fd3ad /src/common
parentbc028cd4d3b24f1e632a04bd0eebcb48b0c27ea2 (diff)
Use global init/cleanup function
Diffstat (limited to 'src/common')
-rw-r--r--src/common/call.c43
-rw-r--r--src/common/call.h2
-rw-r--r--src/common/main.h2
-rw-r--r--src/common/main_common.c42
4 files changed, 63 insertions, 26 deletions
diff --git a/src/common/call.c b/src/common/call.c
index 50370ec..72ff516 100644
--- a/src/common/call.c
+++ b/src/common/call.c
@@ -34,10 +34,6 @@
#define DISC_TIMEOUT 30
-extern int use_mncc_sock;
-extern int send_patterns;
-extern int release_on_disconnect;
-
/* stream patterns/announcements */
int16_t *test_spl = NULL;
int16_t *ringback_spl = NULL;
@@ -175,6 +171,10 @@ typedef struct call {
int test_audio_pos; /* position for test tone toward mobile */
int dial_digits; /* number of digits to be dialed */
int loopback; /* loopback test for echo */
+ int use_mncc_sock;
+ int send_patterns;
+ int release_on_disconnect;
+
} call_t;
static call_t call;
@@ -454,20 +454,23 @@ static void process_timeout(struct timer *timer)
}
}
-int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback)
+int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback, int use_mncc_sock, int send_patterns, int release_on_disconnect)
{
int rc = 0;
init_testton();
- if (use_mncc_sock)
- return 0;
-
memset(&call, 0, sizeof(call));
strncpy(call.station_id, station_id, sizeof(call.station_id) - 1);
call.latspl = latency * samplerate / 1000;
call.dial_digits = dial_digits;
call.loopback = loopback;
+ call.use_mncc_sock = use_mncc_sock;
+ call.send_patterns = send_patterns;
+ call.release_on_disconnect = release_on_disconnect;
+
+ if (call.use_mncc_sock)
+ return 0;
if (!audiodev[0])
return 0;
@@ -502,7 +505,7 @@ error:
void call_cleanup(void)
{
- if (use_mncc_sock)
+ if (call.use_mncc_sock)
return;
/* close sound devoice */
@@ -625,7 +628,7 @@ void print_console_text(void)
* returns 1 on exit (ctrl+c) */
void process_call(int c)
{
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
mncc_handle();
return;
}
@@ -714,7 +717,7 @@ int call_in_setup(int callref, const char *callerid, const char *dialing)
if (!strcmp(dialing, "010"))
PDEBUG(DCALL, DEBUG_INFO, " -> Call to Operator '%s'\n", dialing);
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
uint8_t buf[sizeof(struct gsm_mncc)];
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
int rc;
@@ -777,11 +780,11 @@ void call_in_alerting(int callref)
PDEBUG(DCALL, DEBUG_INFO, "Call is alerting\n");
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
uint8_t buf[sizeof(struct gsm_mncc)];
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
- if (!send_patterns) {
+ if (!call.send_patterns) {
memset(buf, 0, sizeof(buf));
mncc->msg_type = MNCC_ALERT_IND;
mncc->callref = callref;
@@ -830,7 +833,7 @@ void call_in_answer(int callref, const char *connect_id)
PDEBUG(DCALL, DEBUG_INFO, "Call has been answered by '%s'\n", connect_id);
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
_indicate_answer(callref, connect_id);
set_pattern_process(callref, PATTERN_NONE);
set_state_process(callref, CALL_CONNECT);
@@ -857,7 +860,7 @@ void call_in_release(int callref, int cause)
PDEBUG(DCALL, DEBUG_INFO, "Call has been released with cause=%d\n", cause);
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
uint8_t buf[sizeof(struct gsm_mncc)];
struct gsm_mncc *mncc = (struct gsm_mncc *)buf;
@@ -869,7 +872,7 @@ void call_in_release(int callref, int cause)
mncc->cause.value = cause;
if (is_process(callref)) {
- if (!send_patterns
+ if (!call.send_patterns
|| is_process_state(callref) == CALL_DISCONNECTED
|| is_process_state(callref) == CALL_SETUP_MO) {
PDEBUG(DMNCC, DEBUG_INFO, "Releasing MNCC call towards Network\n");
@@ -901,7 +904,7 @@ void call_tx_audio(int callref, int16_t *samples, int count)
if (!callref)
return;
- if (use_mncc_sock) {
+ if (call.use_mncc_sock) {
uint8_t buf[sizeof(struct gsm_data_frame) + count * sizeof(int16_t)];
struct gsm_data_frame *data = (struct gsm_data_frame *)buf;
@@ -1046,7 +1049,7 @@ void call_mncc_recv(uint8_t *buf, int length)
rc = call_out_setup(callref, caller_id, caller_type, number);
if (rc < 0) {
PDEBUG(DCALL, DEBUG_NOTICE, "Call rejected, cause %d\n", -rc);
- if (send_patterns) {
+ if (call.send_patterns) {
PDEBUG(DCALL, DEBUG_DEBUG, "Early connecting after setup\n");
_indicate_answer(callref, number);
disconnect_process(callref, -rc);
@@ -1064,7 +1067,7 @@ void call_mncc_recv(uint8_t *buf, int length)
break;
}
- if (send_patterns) {
+ if (call.send_patterns) {
PDEBUG(DCALL, DEBUG_DEBUG, "Early connecting after setup\n");
_indicate_answer(callref, number);
break;
@@ -1077,7 +1080,7 @@ void call_mncc_recv(uint8_t *buf, int length)
case MNCC_DISC_REQ:
PDEBUG(DMNCC, DEBUG_INFO, "Received MNCC disconnect from Network with cause %d\n", mncc->cause.value);
- if (is_process_state(callref) == CALL_CONNECT && release_on_disconnect) {
+ if (is_process_state(callref) == CALL_CONNECT && call.release_on_disconnect) {
PDEBUG(DCALL, DEBUG_INFO, "Releaseing, because we don't send disconnect tones to mobile phone\n");
PDEBUG(DMNCC, DEBUG_INFO, "Releasing MNCC call towards Network\n");
diff --git a/src/common/call.h b/src/common/call.h
index 996224f..63719f4 100644
--- a/src/common/call.h
+++ b/src/common/call.h
@@ -9,7 +9,7 @@ enum number_type {
TYPE_INTERNATIONAL,
};
-int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback);
+int call_init(const char *station_id, const char *audiodev, int samplerate, int latency, int dial_digits, int loopback, int use_mncc_sock, int send_patterns, int release_on_disconnect);
void call_cleanup(void);
void process_call(int c);
void clear_console_text(void);
diff --git a/src/common/main.h b/src/common/main.h
index 3b680e4..488650d 100644
--- a/src/common/main.h
+++ b/src/common/main.h
@@ -39,7 +39,9 @@ void opt_switch_common(int c, char *arg0, int *skip_args);
extern int quit;
void sighandler(int sigset);
+int init_common(const char *station_id, int station_id_digits);
void main_common(int *quit, int latency, int interval, void (*myhandler)(void));
+void cleanup_common(void);
void dump_info(void);
diff --git a/src/common/main_common.c b/src/common/main_common.c
index 2aa5b40..399a6eb 100644
--- a/src/common/main_common.c
+++ b/src/common/main_common.c
@@ -32,6 +32,7 @@
#include "sender.h"
#include "timer.h"
#include "call.h"
+#include "mncc_sock.h"
#ifdef HAVE_SDR
#include "sdr.h"
#endif
@@ -353,6 +354,35 @@ static int get_char()
return -1;
}
+int init_common(const char *station_id, int station_id_digits)
+{
+ int rc;
+
+ /* init mncc */
+ if (use_mncc_sock) {
+ rc = mncc_init("/tmp/bsc_mncc");
+ if (rc < 0) {
+ fprintf(stderr, "Failed to setup MNCC socket. Quitting!\n");
+ return rc;
+ }
+ }
+
+ /* init call device */
+ rc = call_init(station_id, call_audiodev, samplerate, latency, station_id_digits, loopback, use_mncc_sock, send_patterns, release_on_disconnect);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to create call control instance. Quitting!\n");
+ return rc;
+ }
+
+#ifdef HAVE_SDR
+ rc = sdr_init(sdr_args, sdr_rx_gain, sdr_tx_gain, write_iq_rx_wave, write_iq_tx_wave, read_iq_rx_wave);
+ if (rc < 0)
+ return rc;
+#endif
+
+ return 0;
+}
+
/* Loop through all transceiver instances of one network. */
void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
{
@@ -362,11 +392,6 @@ void main_common(int *quit, int latency, int interval, void (*myhandler)(void))
struct termios term, term_orig;
int c;
-#ifdef HAVE_SDR
- if (sdr_init(sdr_args, sdr_rx_gain, sdr_tx_gain))
- return;
-#endif
-
/* open audio */
if (sender_open_audio())
return;
@@ -477,3 +502,10 @@ next_char:
}
}
+void cleanup_common(void)
+{
+ call_cleanup();
+ if (use_mncc_sock)
+ mncc_exit();
+}
+