GSM now receives tones during bridge
[lcr.git] / gsm_bs.cpp
index 902065b..29888be 100644 (file)
@@ -65,7 +65,6 @@ Pgsm_bs::~Pgsm_bs()
 /* DTMF INDICATION */
 void Pgsm_bs::start_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
 {
-       struct lcr_msg *message;
        struct gsm_mncc *resp;
 
        gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
@@ -84,10 +83,16 @@ void Pgsm_bs::start_dtmf_ind(unsigned int msg_type, unsigned int callref, struct
        send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
 
        if (p_g_rtp_bridge) {
-               /* send dtmf information, because we bridge RTP directly */
-               message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF);
-               message->param.dtmf = mncc->keypad;
-               message_put(message);
+               class Port *remote = bridge_remote();
+
+               if (remote) {
+                       struct lcr_msg *message;
+
+                       /* send dtmf information, because we bridge RTP directly */
+                       message = message_create(0, remote->p_serial, EPOINT_TO_PORT, MESSAGE_DTMF);
+                       message->param.dtmf = mncc->keypad;
+                       message_put(message);
+               }
        } else {
                /* generate DTMF tones, since we do audio forwarding inside LCR */
                switch (mncc->keypad) {
@@ -207,6 +212,13 @@ void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
        class Endpoint *epoint;
        struct lcr_msg *message;
        struct gsm_mncc *mode, *proceeding, *frame;
+       struct interface *interface;
+
+       interface = getinterfacebyname(p_g_interface_name);
+       if (!interface) {
+               PERROR("Cannot find interface %s.\n", p_g_interface_name);
+               return;
+       }
 
        /* process given callref */
        gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_IN);
@@ -294,8 +306,7 @@ void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
                FATAL("Incoming call but already got an endpoint.\n");
        if (!(epoint = new Endpoint(p_serial, 0)))
                FATAL("No memory for Endpoint instance\n");
-       if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
-               FATAL("No memory for Endpoint Application instance\n");
+       epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
        epointlist_new(epoint->ep_serial);
 
        /* modify lchan to GSM codec V1 */
@@ -361,7 +372,6 @@ void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
  */
 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
 {
-       struct interface *interface = lcr_gsm->interface;
        struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
        unsigned int callref = mncc->callref;
        class Port *port;
@@ -386,7 +396,8 @@ int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
                port = port->next;
        }
 
-       if (msg_type == GSM_TCHF_FRAME) {
+       if (msg_type == GSM_TCHF_FRAME
+        || msg_type == GSM_TCHF_BAD_FRAME) {
                if (port) {
                        /* inject DTMF, if enabled */
                        if (pgsm_bs->p_g_dtmf) {
@@ -403,30 +414,26 @@ int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
                        } else
                                pgsm_bs->frame_receive(arg);
                        /* if we do not bridge we need to inject audio, if available */
-                       if (!pgsm_bs->p_bridge) {
+                       if (!pgsm_bs->p_bridge || pgsm_bs->p_tone_name[0]) {
                                unsigned char data[160];
                                int i;
 
                                i = pgsm_bs->read_audio(data, 160);
                                if (i)
-                                       pgsm_bs->bridge_rx(data, i);
+                                       pgsm_bs->audio_send(data, i);
                        }
                }
                return 0;
        }
 
        if (!port) {
+               struct interface *interface;
+
                if (msg_type != MNCC_SETUP_IND)
                        return(0);
-#if 0
-               /* find gsm port */
-               mISDNport = mISDNport_first;
-               while(mISDNport) {
-                       if (mISDNport->gsm_bs)
-                               break;
-                       mISDNport = mISDNport->next;
-               }
-               if (!mISDNport) {
+
+               interface = getinterfacebyname(lcr_gsm->interface_name);
+               if (!interface) {
                        struct gsm_mncc *rej;
 
                        rej = create_mncc(MNCC_REJ_REQ, callref);
@@ -438,11 +445,11 @@ int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
                        add_trace("cause", "coding", "%d", rej->cause.coding);
                        add_trace("cause", "location", "%d", rej->cause.location);
                        add_trace("cause", "value", "%d", rej->cause.value);
+                       add_trace("reason", NULL, "interface %s not found", lcr_gsm->interface_name);
                        end_trace();
                        send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
                        return 0;
                }
-#endif
                /* creating port object, transparent until setup with hdlc */
                SPRINT(name, "%s-%d-in", interface->name, 0);
                if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, name, NULL, interface)))
@@ -751,7 +758,7 @@ int gsm_bs_init(struct interface *interface)
        /* create gsm instance */
        gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
 
-       gsm_bs->interface = interface;
+       SCPY(gsm_bs->interface_name, interface->name);
        gsm_bs->type = LCR_GSM_TYPE_NETWORK;
        gsm_bs->sun.sun_family = AF_UNIX;
        SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");