X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=gsm.cpp;h=50a8b1d8bd365902cee9af23b1d73af0330d99bf;hp=a26426c2d1f0a01bea85f80f53939c5694d194f4;hb=2188efe2cc9dfb473bf41540960382d7c43b892e;hpb=4ec1520c572c4099b478897e4a6ee3a28622ca44 diff --git a/gsm.cpp b/gsm.cpp index a26426c..50a8b1d 100644 --- a/gsm.cpp +++ b/gsm.cpp @@ -10,14 +10,29 @@ \*****************************************************************************/ #include "main.h" + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif extern "C" { -#include "openbsc/gsm_data.h" -#include "openbsc/mncc.h" -#include "openbsc/trau_frame.h" -#include "openbsc/select.h" -#include "openbsc/debug.h" -#include "openbsc/e1_input.h" -#include "bootstrap.h" +#include + +#include +#include +#include +#include +#include +#include +#include +struct gsm_network *bsc_gsmnet = 0; +extern int ipacc_rtp_direct; +extern int bsc_bootstrap_network(int (*mmc_rev)(struct gsm_network *, int, void *), + const char *cfg_file); +extern int bsc_shutdown_net(struct gsm_network *net); +void talloc_ctx_init(void); +void on_dso_load_token(void); +void on_dso_load_rrlp(void); + #include "gsm_audio.h" #undef AF_ISDN @@ -26,6 +41,7 @@ extern int AF_ISDN; #define PF_ISDN AF_ISDN } + struct lcr_gsm *gsm = NULL; static unsigned int new_callref = 1; @@ -864,7 +880,7 @@ void Pgsm::retr_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc /* * BSC sends message to port */ -static int message_bcs(struct gsm_network *net, int msg_type, void *arg) +static int message_bsc(struct gsm_network *net, int msg_type, void *arg) { struct gsm_mncc *mncc = (struct gsm_mncc *)arg; unsigned int callref = mncc->callref; @@ -1201,7 +1217,7 @@ void Pgsm::message_notify(unsigned int epoint_id, int message_id, union paramete struct gsm_mncc *mncc; int notify; - printf("if = %d\n", param->notifyinfo.notify); +// printf("if = %d\n", param->notifyinfo.notify); if (param->notifyinfo.notify>INFO_NOTIFY_NONE) { notify = param->notifyinfo.notify & 0x7f; if (p_state!=PORT_STATE_CONNECT /*&& p_state!=PORT_STATE_IN_PROCEEDING*/ && p_state!=PORT_STATE_IN_ALERTING) { @@ -1607,11 +1623,11 @@ int gsm_exit(int rc) gsm_sock_close(); /* shutdown network */ if (gsm->network) - shutdown_net((struct gsm_network *)gsm->network); + bsc_shutdown_net((struct gsm_network *)gsm->network); /* free network */ - if (gsm->network) { - free((struct gsm_network *)gsm->network); /* TBD */ - } +// if (gsm->network) { +// free((struct gsm_network *)gsm->network); /* TBD */ +// } free(gsm); gsm = NULL; } @@ -1621,9 +1637,17 @@ int gsm_exit(int rc) int gsm_init(void) { - char hlr[128], filename[128]; + char hlr[128], cfg[128], filename[128]; mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - int pcapfd; + int pcapfd, rc; + + tall_bsc_ctx = talloc_named_const(NULL, 1, "openbsc"); + talloc_ctx_init(); + on_dso_load_token(); + on_dso_load_rrlp(); + + /* seed the PRNG */ + srand(time(NULL)); /* create gsm instance */ gsm = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm)); @@ -1636,46 +1660,64 @@ int gsm_init(void) } /* set debug */ - debug_parse_category_mask(gsm->conf.debug); + if (gsm->conf.debug[0]) + debug_parse_category_mask(gsm->conf.debug); + + /* open pcap file */ + if (gsm->conf.pcapfile[0]) { + if (gsm->conf.pcapfile[0] == '/') + SCPY(filename, gsm->conf.pcapfile); + else + SPRINT(filename, "%s/%s", CONFIG_DATA, gsm->conf.pcapfile); + pcapfd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, mode); + if (pcapfd < 0) { + PERROR("Failed to open file for pcap\n"); + return gsm_exit(-1); + } + e1_set_pcap_fd(pcapfd); + } + + /* set reject cause */ + if (gsm->conf.reject_cause) + gsm0408_set_reject_cause(gsm->conf.reject_cause); + + /* use RTP proxy for audio streaming */ + if (gsm->conf.rtp_proxy) + ipacc_rtp_direct = 0; /* init database */ if (gsm->conf.hlr[0] == '/') SCPY(hlr, gsm->conf.hlr); else SPRINT(hlr, "%s/%s", CONFIG_DATA, gsm->conf.hlr); - - // TODO multiple base stations - if (gsm->conf.numbts < 1 || gsm->conf.numbts > 1) { - PERROR("Expecting exactly one BTS. You defined %d.\n", gsm->conf.numbts); + if (db_init(hlr)) { + PERROR("GSM DB: Failed to init database '%s'. Please check the option settings.\n", hlr); + return gsm_exit(-1); + } + printf("DB: Database initialized.\n"); + if (db_prepare()) { + PERROR("GSM DB: Failed to prepare database.\n"); return gsm_exit(-1); } + printf("DB: Database prepared.\n"); /* bootstrap network */ - gsm->network = bootstrap_network(&message_bcs, gsm->conf.bts[0].type, gsm->conf.mcc, gsm->conf.mnc, gsm->conf.lac, gsm->conf.bts[0].frequency[0], gsm->conf.bts[0].card, !gsm->conf.keep_l2, gsm->conf.short_name, gsm->conf.long_name, hlr, gsm->conf.allow_all); - if (!gsm->network) { + if (gsm->conf.openbsc_cfg[0] == '/') + SCPY(cfg, gsm->conf.openbsc_cfg); + else + SPRINT(cfg, "%s/%s", CONFIG_DATA, gsm->conf.openbsc_cfg); + rc = bsc_bootstrap_network(&message_bsc, cfg); + if (rc < 0) { PERROR("Failed to bootstrap GSM network.\n"); return gsm_exit(-1); } + gsm->network = bsc_gsmnet; /* open gsm loop interface */ if (gsm_sock_open(gsm->conf.interface_bsc)) { return gsm_exit(-1); } - /* open pcap file */ - if (gsm->conf.pcapfile[0]) { - if (gsm->conf.pcapfile[0] == '/') - SCPY(filename, gsm->conf.pcapfile); - else - SPRINT(filename, "%s/%s", CONFIG_DATA, gsm->conf.pcapfile); - pcapfd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, mode); - if (pcapfd < 0) { - PERROR("Failed to open file for pcap\n"); - return gsm_exit(-1); - } - e1_set_pcap_fd(pcapfd); - } - return 0; }