Added bridgin support for GSM and SIP
[lcr.git] / gsm_ms.cpp
index b966ad8..dbd3351 100644 (file)
@@ -26,28 +26,28 @@ static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index);
 /*
  * constructor
  */
-Pgsm_ms::Pgsm_ms(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive, int mode) : Pgsm(type, mISDNport, portname, settings, channel, exclusive, mode)
+Pgsm_ms::Pgsm_ms(int type, char *portname, struct port_settings *settings, struct interface *interface) : Pgsm(type, portname, settings, interface)
 {
        struct lcr_gsm *gsm_ms = gsm_ms_first;
-       char *ms_name = mISDNport->ifport->gsm_ms_name;
 
-       p_m_g_lcr_gsm = NULL;
+       p_g_lcr_gsm = NULL;
+       SCPY(p_g_ms_name, interface->gsm_ms_name);
 
        while (gsm_ms) {
-               if (gsm_ms->type == LCR_GSM_TYPE_MS && !strcmp(gsm_ms->name, ms_name)) {
-                       p_m_g_lcr_gsm = gsm_ms;
+               if (gsm_ms->type == LCR_GSM_TYPE_MS && !strcmp(gsm_ms->name, p_g_ms_name)) {
+                       p_g_lcr_gsm = gsm_ms;
                        break;
                }
                gsm_ms = gsm_ms->gsm_ms_next;
        }
 
-       p_m_g_dtmf_state = DTMF_ST_IDLE;
-       p_m_g_dtmf_index = 0;
-       p_m_g_dtmf[0] = '\0';
-       memset(&p_m_g_dtmf_timer, 0, sizeof(p_m_g_dtmf_timer));
-       add_timer(&p_m_g_dtmf_timer, dtmf_timeout, this, 0);
+       p_g_dtmf_state = DTMF_ST_IDLE;
+       p_g_dtmf_index = 0;
+       p_g_dtmf[0] = '\0';
+       memset(&p_g_dtmf_timer, 0, sizeof(p_g_dtmf_timer));
+       add_timer(&p_g_dtmf_timer, dtmf_timeout, this, 0);
 
-       PDEBUG(DEBUG_GSM, "Created new GSMMSPort(%s %s).\n", portname, ms_name);
+       PDEBUG(DEBUG_GSM, "Created new GSMMSPort(%s %s).\n", portname, p_g_ms_name);
 }
 
 /*
@@ -56,7 +56,7 @@ Pgsm_ms::Pgsm_ms(int type, struct mISDNport *mISDNport, char *portname, struct p
 Pgsm_ms::~Pgsm_ms()
 {
        PDEBUG(DEBUG_GSM, "Destroyed GSM MS process(%s).\n", p_name);
-       del_timer(&p_m_g_dtmf_timer);
+       del_timer(&p_g_dtmf_timer);
 }
 
 /*
@@ -65,21 +65,19 @@ Pgsm_ms::~Pgsm_ms()
 /* SETUP INDICATION */
 void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
 {
-       int ret;
        class Endpoint *epoint;
        struct lcr_msg *message;
-       int channel;
        struct gsm_mncc *mode, *proceeding, *frame;
 
        /* process given callref */
-       l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
+       gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_IN);
        add_trace("callref", "new", "0x%x", callref);
-       if (p_m_g_callref) {
+       if (p_g_callref) {
                /* release in case the ID is already in use */
                add_trace("error", NULL, "callref already in use");
                end_trace();
                mncc = create_mncc(MNCC_REJ_REQ, callref);
-               gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
+               gsm_trace_header(p_g_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
                mncc->fields |= MNCC_F_CAUSE;
                mncc->cause.coding = 3;
                mncc->cause.location = 1;
@@ -89,34 +87,15 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
                add_trace("cause", "value", "%d", mncc->cause.value);
                add_trace("reason", NULL, "callref already in use");
                end_trace();
-               send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
+               send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
                new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
+               trigger_work(&p_g_delete);
                return;
        }
-       p_m_g_callref = callref;
+       p_g_callref = callref;
        end_trace();
 
-       /* if blocked, release call with MT_RELEASE_COMPLETE */
-       if (p_m_mISDNport->ifport->block) {
-               mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
-               gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
-               mncc->fields |= MNCC_F_CAUSE;
-               mncc->cause.coding = 3;
-               mncc->cause.location = 1;
-               mncc->cause.value = 27;
-               add_trace("cause", "coding", "%d", mncc->cause.coding);
-               add_trace("cause", "location", "%d", mncc->cause.location);
-               add_trace("cause", "value", "%d", mncc->cause.value);
-               add_trace("reason", NULL, "port is blocked");
-               end_trace();
-               send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
-               new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
-               return;
-       }
-
-       gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_IND, DIRECTION_IN);
+       gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_IND, DIRECTION_IN);
        /* caller information */
        p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
        if (mncc->fields & MNCC_F_CALLING) {
@@ -169,8 +148,7 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
                add_trace("calling", "screen", "%d", mncc->calling.screen);
                add_trace("calling", "number", "%s", mncc->calling.number);
        }
-       p_callerinfo.isdn_port = p_m_portnum;
-       SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
+       SCPY(p_callerinfo.interface, p_g_interface_name);
        /* dialing information */
        if (mncc->fields & MNCC_F_CALLED) {
                SCAT(p_dialinginfo.id, mncc->called.number);
@@ -244,7 +222,6 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
                add_trace("redir", "present", "%d", mncc->redirecting.present);
                add_trace("redir", "screen", "%d", mncc->redirecting.screen);
                add_trace("redir", "number", "%s", mncc->redirecting.number);
-               p_redirinfo.isdn_port = p_m_portnum;
        }
        /* bearer capability */
        if (mncc->fields & MNCC_F_BEARER_CAP) {
@@ -282,35 +259,6 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
 
        end_trace();
 
-       /* hunt channel */
-       ret = channel = hunt_bchannel();
-       if (ret < 0)
-               goto no_channel;
-
-       /* open channel */
-       ret = seize_bchannel(channel, 1);
-       if (ret < 0) {
-               no_channel:
-               mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
-               gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
-               mncc->fields |= MNCC_F_CAUSE;
-               mncc->cause.coding = 3;
-               mncc->cause.location = 1;
-               mncc->cause.value = 34;
-               add_trace("cause", "coding", "%d", mncc->cause.coding);
-               add_trace("cause", "location", "%d", mncc->cause.location);
-               add_trace("cause", "value", "%d", mncc->cause.value);
-               add_trace("reason", NULL, "no channel");
-               end_trace();
-               send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
-               new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
-               return;
-       }
-       bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
-       if (bchannel_open(p_m_b_index))
-               goto no_channel;
-
        /* create endpoint */
        if (p_epointlist)
                FATAL("Incoming call but already got an endpoint.\n");
@@ -321,37 +269,36 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
        epointlist_new(epoint->ep_serial);
 
        /* modify lchan to GSM codec V1 */
-       gsm_trace_header(p_m_mISDNport, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
-       mode = create_mncc(MNCC_LCHAN_MODIFY, p_m_g_callref);
+       gsm_trace_header(p_g_interface_name, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
+       mode = create_mncc(MNCC_LCHAN_MODIFY, p_g_callref);
        mode->lchan_mode = 0x01; /* GSM V1 */
        mode->lchan_type = 0x02;
        add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
        end_trace();
-       send_and_free_mncc(p_m_g_lcr_gsm, mode->msg_type, mode);
+       send_and_free_mncc(p_g_lcr_gsm, mode->msg_type, mode);
 
        /* send call proceeding */
-       gsm_trace_header(p_m_mISDNport, this, MNCC_CALL_CONF_REQ, DIRECTION_OUT);
-       proceeding = create_mncc(MNCC_CALL_CONF_REQ, p_m_g_callref);
+       gsm_trace_header(p_g_interface_name, this, MNCC_CALL_CONF_REQ, DIRECTION_OUT);
+       proceeding = create_mncc(MNCC_CALL_CONF_REQ, p_g_callref);
        // FIXME: bearer
        /* DTMF supported */
        proceeding->fields |= MNCC_F_CCCAP;
        proceeding->cccap.dtmf = 1;
        end_trace();
-       send_and_free_mncc(p_m_g_lcr_gsm, proceeding->msg_type, proceeding);
+       send_and_free_mncc(p_g_lcr_gsm, proceeding->msg_type, proceeding);
 
        new_state(PORT_STATE_IN_PROCEEDING);
 
-       if (p_m_mISDNport->tones && !p_m_g_tch_connected) { /* only if ... */
-               gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
+       if (p_g_tones && !p_g_tch_connected) { /* only if ... */
+               gsm_trace_header(p_g_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
                end_trace();
-               frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
-               send_and_free_mncc(p_m_g_lcr_gsm, frame->msg_type, frame);
-               p_m_g_tch_connected = 1;
+               frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
+               send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
+               p_g_tch_connected = 1;
        }
 
        /* send setup message to endpoit */
        message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
-       message->param.setup.isdn_port = p_m_portnum;
        message->param.setup.port_type = p_type;
 //     message->param.setup.dtmf = 0;
        memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
@@ -368,12 +315,13 @@ void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_
  */
 int message_ms(struct lcr_gsm *gsm_ms, int msg_type, void *arg)
 {
+       struct interface *interface = gsm_ms->interface;
        struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
        unsigned int callref = mncc->callref;
        class Port *port;
        class Pgsm_ms *pgsm_ms = NULL;
        char name[64];
-       struct mISDNport *mISDNport;
+//     struct mISDNport *mISDNport;
 
        /* Special messages */
        switch (msg_type) {
@@ -385,7 +333,7 @@ int message_ms(struct lcr_gsm *gsm_ms, int msg_type, void *arg)
        while(port) {
                if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
                        pgsm_ms = (class Pgsm_ms *)port;
-                       if (pgsm_ms->p_m_g_callref == callref) {
+                       if (pgsm_ms->p_g_callref == callref) {
                                break;
                        }
                }
@@ -401,6 +349,7 @@ int message_ms(struct lcr_gsm *gsm_ms, int msg_type, void *arg)
        if (!port) {
                if (msg_type != MNCC_SETUP_IND)
                        return(0);
+#if 0
                /* find gsm ms port */
                mISDNport = mISDNport_first;
                while(mISDNport) {
@@ -424,10 +373,10 @@ int message_ms(struct lcr_gsm *gsm_ms, int msg_type, void *arg)
                        send_and_free_mncc(gsm_ms, rej->msg_type, rej);
                        return 0;
                }
+#endif
                /* creating port object, transparent until setup with hdlc */
-               SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
-               if (!(pgsm_ms = new Pgsm_ms(PORT_TYPE_GSM_MS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
-
+               SPRINT(name, "%s-%d-in", interface->name, 0);
+               if (!(pgsm_ms = new Pgsm_ms(PORT_TYPE_GSM_MS_IN, name, NULL, interface)))
                        FATAL("Cannot create Port instance.\n");
        }
 
@@ -482,10 +431,8 @@ int message_ms(struct lcr_gsm *gsm_ms, int msg_type, void *arg)
 void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
 {
        struct lcr_msg *message;
-       int ret;
        struct epoint_list *epointlist;
        struct gsm_mncc *mncc;
-       int channel;
 
        /* copy setup infos to port */
        memcpy(&p_callerinfo, &param->setup.callerinfo, sizeof(p_callerinfo));
@@ -494,22 +441,22 @@ void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parame
        memcpy(&p_redirinfo, &param->setup.redirinfo, sizeof(p_redirinfo));
 
        /* no instance */
-       if (!p_m_g_lcr_gsm || p_m_g_lcr_gsm->mncc_lfd.fd < 0) {
-               gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
-               add_trace("failure", NULL, "MS %s instance is unavailable", p_m_mISDNport->ifport->gsm_ms_name);
+       if (!p_g_lcr_gsm || p_g_lcr_gsm->mncc_lfd.fd < 0) {
+               gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
+               add_trace("failure", NULL, "MS %s instance is unavailable", p_g_ms_name);
                end_trace();
                message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
                message->param.disconnectinfo.cause = 41;
                message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
                message_put(message);
                new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
+               trigger_work(&p_g_delete);
                return;
        }
        
        /* no number */
        if (!p_dialinginfo.id[0]) {
-               gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
+               gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
                add_trace("failure", NULL, "No dialed subscriber given.");
                end_trace();
                message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
@@ -517,46 +464,9 @@ void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parame
                message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
                message_put(message);
                new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
+               trigger_work(&p_g_delete);
                return;
        }
-       
-       /* release if port is blocked */
-       if (p_m_mISDNport->ifport->block) {
-               gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
-               add_trace("failure", NULL, "Port blocked.");
-               end_trace();
-               message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
-               message->param.disconnectinfo.cause = 27; // temp. unavail.
-               message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
-               message_put(message);
-               new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
-               return;
-       }
-
-       /* hunt channel */
-       ret = channel = hunt_bchannel();
-       if (ret < 0)
-               goto no_channel;
-       /* open channel */
-       ret = seize_bchannel(channel, 1);
-       if (ret < 0) {
-               no_channel:
-               gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
-               add_trace("failure", NULL, "No internal audio channel available.");
-               end_trace();
-               message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
-               message->param.disconnectinfo.cause = 34;
-               message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
-               message_put(message);
-               new_state(PORT_STATE_RELEASE);
-               trigger_work(&p_m_g_delete);
-               return;
-       }
-       bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
-       if (bchannel_open(p_m_b_index))
-               goto no_channel;
 
        /* attach only if not already */
        epointlist = p_epointlist;
@@ -569,13 +479,13 @@ void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parame
                epointlist_new(epoint_id);
 
        /* creating l3id */
-       l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
-       p_m_g_callref = new_callref++;
-       add_trace("callref", "new", "0x%x", p_m_g_callref);
+       gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_OUT);
+       p_g_callref = new_callref++;
+       add_trace("callref", "new", "0x%x", p_g_callref);
        end_trace();
 
-       gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
-       mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
+       gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
+       mncc = create_mncc(MNCC_SETUP_REQ, p_g_callref);
        if (!strncasecmp(p_dialinginfo.id, "emerg", 5)) {
                mncc->emergency = 1;
        } else {
@@ -631,7 +541,7 @@ void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parame
        }
 
        end_trace();
-       send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
+       send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
 
        new_state(PORT_STATE_OUT_SETUP);
 
@@ -639,49 +549,51 @@ void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parame
        message_put(message);
 
        new_state(PORT_STATE_OUT_PROCEEDING);
+
+       p_g_rtp_bridge = 0;
 }
 
 void Pgsm_ms::dtmf_statemachine(struct gsm_mncc *mncc)
 {
        struct gsm_mncc *dtmf;
 
-       switch (p_m_g_dtmf_state) {
+       switch (p_g_dtmf_state) {
        case DTMF_ST_SPACE:
        case DTMF_ST_IDLE:
                /* end of string */
-               if (!p_m_g_dtmf[p_m_g_dtmf_index]) {
+               if (!p_g_dtmf[p_g_dtmf_index]) {
                        PDEBUG(DEBUG_GSM, "done with DTMF\n");
-                       p_m_g_dtmf_state = DTMF_ST_IDLE;
+                       p_g_dtmf_state = DTMF_ST_IDLE;
                        return;
                }
-               gsm_trace_header(p_m_mISDNport, this, MNCC_START_DTMF_REQ, DIRECTION_OUT);
-               dtmf = create_mncc(MNCC_START_DTMF_REQ, p_m_g_callref);
-               dtmf->keypad = p_m_g_dtmf[p_m_g_dtmf_index++];
-               p_m_g_dtmf_state = DTMF_ST_START;
+               gsm_trace_header(p_g_interface_name, this, MNCC_START_DTMF_REQ, DIRECTION_OUT);
+               dtmf = create_mncc(MNCC_START_DTMF_REQ, p_g_callref);
+               dtmf->keypad = p_g_dtmf[p_g_dtmf_index++];
+               p_g_dtmf_state = DTMF_ST_START;
                PDEBUG(DEBUG_GSM, "start DTMF (keypad %c)\n",
                        dtmf->keypad);
                end_trace();
-               send_and_free_mncc(p_m_g_lcr_gsm, dtmf->msg_type, dtmf);
+               send_and_free_mncc(p_g_lcr_gsm, dtmf->msg_type, dtmf);
                return;
        case DTMF_ST_START:
                if (mncc->msg_type != MNCC_START_DTMF_RSP) {
                        PDEBUG(DEBUG_GSM, "DTMF was rejected\n");
                        return;
                }
-               schedule_timer(&p_m_g_dtmf_timer, 0, 70 * 1000);
-               p_m_g_dtmf_state = DTMF_ST_MARK;
+               schedule_timer(&p_g_dtmf_timer, 0, 70 * 1000);
+               p_g_dtmf_state = DTMF_ST_MARK;
                PDEBUG(DEBUG_GSM, "DTMF is on\n");
                break;
        case DTMF_ST_MARK:
-               gsm_trace_header(p_m_mISDNport, this, MNCC_STOP_DTMF_REQ, DIRECTION_OUT);
-               dtmf = create_mncc(MNCC_STOP_DTMF_REQ, p_m_g_callref);
-               p_m_g_dtmf_state = DTMF_ST_STOP;
+               gsm_trace_header(p_g_interface_name, this, MNCC_STOP_DTMF_REQ, DIRECTION_OUT);
+               dtmf = create_mncc(MNCC_STOP_DTMF_REQ, p_g_callref);
+               p_g_dtmf_state = DTMF_ST_STOP;
                end_trace();
-               send_and_free_mncc(p_m_g_lcr_gsm, dtmf->msg_type, dtmf);
+               send_and_free_mncc(p_g_lcr_gsm, dtmf->msg_type, dtmf);
                return;
        case DTMF_ST_STOP:
-               schedule_timer(&p_m_g_dtmf_timer, 0, 120 * 1000);
-               p_m_g_dtmf_state = DTMF_ST_SPACE;
+               schedule_timer(&p_g_dtmf_timer, 0, 120 * 1000);
+               p_g_dtmf_state = DTMF_ST_SPACE;
                PDEBUG(DEBUG_GSM, "DTMF is off\n");
                break;
        }
@@ -708,12 +620,12 @@ void Pgsm_ms::message_dtmf(unsigned int epoint_id, int message_id, union paramet
                return;
 
        /* schedule */
-       if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
-               p_m_g_dtmf_index = 0;
-               p_m_g_dtmf[0] = '\0';
+       if (p_g_dtmf_state == DTMF_ST_IDLE) {
+               p_g_dtmf_index = 0;
+               p_g_dtmf[0] = '\0';
        }
-       SCCAT(p_m_g_dtmf, digit);
-       if (p_m_g_dtmf_state == DTMF_ST_IDLE)
+       SCCAT(p_g_dtmf, digit);
+       if (p_g_dtmf_state == DTMF_ST_IDLE)
                dtmf_statemachine(NULL);
 }
 
@@ -731,12 +643,12 @@ void Pgsm_ms::message_information(unsigned int epoint_id, int message_id, union
                        continue;
 
                /* schedule */
-               if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
-                       p_m_g_dtmf_index = 0;
-                       p_m_g_dtmf[0] = '\0';
+               if (p_g_dtmf_state == DTMF_ST_IDLE) {
+                       p_g_dtmf_index = 0;
+                       p_g_dtmf[0] = '\0';
                }
-               SCCAT(p_m_g_dtmf, digit);
-               if (p_m_g_dtmf_state == DTMF_ST_IDLE)
+               SCCAT(p_g_dtmf, digit);
+               if (p_g_dtmf_state == DTMF_ST_IDLE)
                        dtmf_statemachine(NULL);
        }
 }
@@ -794,7 +706,7 @@ int gsm_ms_init(void)
 }
 
 /* add a new GSM mobile instance */
-int gsm_ms_new(const char *name)
+int gsm_ms_new(struct interface *interface)
 {
        struct lcr_gsm *gsm_ms = gsm_ms_first, **gsm_ms_p = &gsm_ms_first;
 
@@ -803,15 +715,16 @@ int gsm_ms_new(const char *name)
                gsm_ms = gsm_ms->gsm_ms_next;
        }
 
-       PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is created\n", name);
+       PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is created\n", interface->gsm_ms_name);
 
        /* create gsm instance */
        gsm_ms = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
 
+       gsm_ms->interface = interface;
        gsm_ms->type = LCR_GSM_TYPE_MS;
-       SCPY(gsm_ms->name, name);
+       SCPY(gsm_ms->name, interface->gsm_ms_name);
        gsm_ms->sun.sun_family = AF_UNIX;
-       SPRINT(gsm_ms->sun.sun_path, "/tmp/ms_mncc_%s", name);
+       SPRINT(gsm_ms->sun.sun_path, "/tmp/ms_mncc_%s", gsm_ms->name);
 
        memset(&gsm_ms->socket_retry, 0, sizeof(gsm_ms->socket_retry));
        add_timer(&gsm_ms->socket_retry, mncc_socket_retry_cb, gsm_ms, 0);
@@ -851,10 +764,10 @@ int gsm_ms_delete(const char *name)
        while(port) {
                if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
                        pgsm_ms = (class Pgsm_ms *)port;
-                       if (pgsm_ms->p_m_g_lcr_gsm == gsm_ms && pgsm_ms->p_m_g_callref) {
+                       if (pgsm_ms->p_g_lcr_gsm == gsm_ms && pgsm_ms->p_g_callref) {
                                struct gsm_mncc *rej;
 
-                               rej = create_mncc(MNCC_REL_REQ, pgsm_ms->p_m_g_callref);
+                               rej = create_mncc(MNCC_REL_REQ, pgsm_ms->p_g_callref);
                                rej->fields |= MNCC_F_CAUSE;
                                rej->cause.coding = 3;
                                rej->cause.location = 1;
@@ -866,7 +779,7 @@ int gsm_ms_delete(const char *name)
                                end_trace();
                                send_and_free_mncc(gsm_ms, rej->msg_type, rej);
                                pgsm_ms->new_state(PORT_STATE_RELEASE);
-                               trigger_work(&pgsm_ms->p_m_g_delete);
+                               trigger_work(&pgsm_ms->p_g_delete);
                        }
                }
        }