mISDN-socket port opens
[lcr.git] / mISDN.cpp
index e8e7692..9bff716 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -286,7 +286,7 @@ PmISDN::PmISDN(int type, mISDNport *mISDNport, char *portname, struct port_setti
  */
 PmISDN::~PmISDN()
 {
-       struct message *message;
+       struct lcr_msg *message;
 
        /* remove bchannel relation */
        drop_bchannel();
@@ -317,7 +317,7 @@ void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, char *ms
        /* init trace with given values */
        start_trace(mISDNport?mISDNport->portnum:0,
                    (mISDNport)?((mISDNport->ifport)?mISDNport->ifport->interface:NULL):NULL,
-                   port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype):NULL,
+                   port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
                    port?port->p_dialinginfo.id:NULL,
                    direction,
                    CATEGORY_CH,
@@ -428,7 +428,7 @@ void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsign
        /* init trace with given values */
        start_trace(mISDNport?mISDNport->portnum:0,
                    mISDNport?mISDNport->ifport->interface:NULL,
-                   port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype):NULL,
+                   port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
                    port?port->p_dialinginfo.id:NULL,
                    direction,
                    CATEGORY_CH,
@@ -532,7 +532,10 @@ static int _bchannel_create(struct mISDNport *mISDNport, int i)
        }
 
        /* open socket */
-       mISDNport->b_socket[i] = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_L2DSP);
+#warning testing without bchannel
+return(0);
+#warning testing without DSP
+       mISDNport->b_socket[i] = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW/*ISDN_P_B_L2DSP*/);
        if (mISDNport->b_socket[i] < 0)
        {
                PERROR("Error: Failed to open bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", i);
@@ -1511,7 +1514,7 @@ on empty load, remote-audio causes the load with the remote audio to be increase
  */
 int PmISDN::handler(void)
 {
-       struct message *message;
+       struct lcr_msg *message;
        int elapsed = 0;
        int ret;
 
@@ -1647,7 +1650,7 @@ void PmISDN::bchannel_receive(iframe_t *frm)
 #endif
        unsigned char *data_temp;
        unsigned long length_temp;
-       struct message *message;
+       struct lcr_msg *message;
        unsigned char *p;
        int l;
 
@@ -1962,7 +1965,7 @@ void PmISDN::set_tone(char *dir, char *tone)
 
 
 /* MESSAGE_mISDNSIGNAL */
-//extern struct message *dddebug;
+//extern struct lcr_msg *dddebug;
 void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union parameter *param)
 {
        switch(param->mISDNsignal.message)
@@ -2052,7 +2055,7 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
 /* MESSAGE_CRYPT */
 void PmISDN::message_crypt(unsigned long epoint_id, int message_id, union parameter *param)
 {
-       struct message *message;
+       struct lcr_msg *message;
 
        switch(param->crypt.type)
        {
@@ -2296,25 +2299,48 @@ int mISDN_handler(void)
                        l3m = &mb->l3;
                        switch(l3m->type)
                        {
-#warning SOCKET TBD: Layer 1 indication
-#if 0
-                               case MT_L1ACTIVATE:
+                               case MPH_ACTIVATE_IND:
                                l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN);
                                end_trace();
                                mISDNport->l1link = 1;
                                break;
        
-                               case MT_L1DEACTIVATE:
+                               case MPH_DEACTIVATE_IND:
                                l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN);
                                end_trace();
                                mISDNport->l1link = 0;
                                break;
 
-                               case MT_L1CONTROL:
-                               PDEBUG(DEBUG_ISDN, "Received PH_CONTROL for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
-                               // special config commands for interface (ip-address/LOS/AIS/RDI/SLIP)
+                               case MPH_INFORMATION_IND:
+                               PDEBUG(DEBUG_ISDN, "Received MPH_INFORMATION_IND for port %d (%s).\n", mISDNport->portnum, mISDNport->ifport->interface->name);
+                               switch (l3m->pid)
+                               {
+                                       case L1_SIGNAL_LOS_ON:
+                                       mISDNport->los = 1;
+                                       break;
+                                       case L1_SIGNAL_LOS_OFF:
+                                       mISDNport->los = 0;
+                                       break;
+                                       case L1_SIGNAL_AIS_ON:
+                                       mISDNport->ais = 1;
+                                       break;
+                                       case L1_SIGNAL_AIS_OFF:
+                                       mISDNport->ais = 0;
+                                       break;
+                                       case L1_SIGNAL_RDI_ON:
+                                       mISDNport->rdi = 1;
+                                       break;
+                                       case L1_SIGNAL_RDI_OFF:
+                                       mISDNport->rdi = 0;
+                                       break;
+                                       case L1_SIGNAL_SLIP_TX:
+                                       mISDNport->slip_tx++;
+                                       break;
+                                       case L1_SIGNAL_SLIP_RX:
+                                       mISDNport->slip_rx++;
+                                       break;
+                               }
                                break;
-#endif
 
                                case MT_L2ESTABLISH:
                                l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
@@ -2944,7 +2970,7 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
 #ifdef SOCKET_MISDN
        devinfo.id = port - 1;
        ret = ioctl(mISDNsocket, IMGETDEVINFO, &devinfo);
-       if (ret <= 0)
+       if (ret < 0)
        {
                PERROR_RUNTIME("Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", i, ret);
                return(NULL);
@@ -3127,7 +3153,7 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
                
        /* allocate ressources of port */
 #ifdef SOCKET_MISDN
-       /* open layer 3 */
+       /* open layer 3 and init upqueue */
        protocol = (nt)?L3_PROTOCOL_DSS1_USER:L3_PROTOCOL_DSS1_NET;
        prop = 0;
        if (ptp) // ptp forced
@@ -3139,9 +3165,11 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
        mISDNport->ml3 = open_layer3(port-1, protocol, prop , do_layer3, mISDNport);
        if (!mISDNport->ml3)
        {
-               PERROR_RUNTIME("Cannot get layer(%d) id of port %d\n", nt?2:4, port);
+               PERROR_RUNTIME("oper_layer3() failed for port %d\n", port);
+               mISDNport_close(mISDNport);
                return(NULL);
        }
+       mqueue_init(&mISDNport->upqueue);
 
 #if 0
        /* if ntmode, establish L1 to send the tei removal during start */
@@ -3326,11 +3354,6 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
        }
 #endif
 
-#ifdef SOCKET_MISDN
-       /* init stack queue */
-       mqueue_init(&mISDNport->upqueue);
-#endif
-       
        /* initially, we assume that the link is down, exept for nt-ptmp */
        mISDNport->l2link = (mISDNport->ntmode && !mISDNport->ptp)?1:0;
 
@@ -3422,8 +3445,12 @@ void mISDNport_close(struct mISDNport *mISDNport)
        }
 
 #ifdef SOCKET_MISDN
-       close_layer3(mISDNport->ml3);
-       mqueue_purge(&mISDNport->upqueue);
+       /* close layer 3, if open and purge upqueue */
+       if (mISDNport->ml3)
+       {
+               close_layer3(mISDNport->ml3);
+               mqueue_purge(&mISDNport->upqueue);
+       }
 #else
        /* free ressources of port */
        msg_queue_purge(&mISDNport->downqueue);
@@ -3537,7 +3564,7 @@ void mISDN_port_info(void)
 #ifdef SOCKET_MISDN
                devinfo.id = i - 1;
                ret = ioctl(sock, IMGETDEVINFO, &devinfo);
-               if (ret <= 0)
+               if (ret < 0)
                {
                        fprintf(stderr, "Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", i, ret);
                        break;
@@ -3582,18 +3609,24 @@ void mISDN_port_info(void)
                if ((te || nt) && (bri || pri || pots))
                        useable = 1;
 
-               if (te && bri)
-                       printf("TE-mode BRI S/T interface line (for phone lines)");
-               if (nt && bri)
-                       printf("NT-mode BRI S/T interface port (for phones)");
-               if (te && pri)
-                       printf("TE-mode PRI E1  interface line (for phone lines)");
-               if (nt && pri)
-                       printf("NT-mode PRI E1  interface port (for E1 terminals)");
-               if (te && pots)
-                       printf("FXS     POTS    interface port (for analog lines)");
-               if (nt && pots)
-                       printf("FXO     POTS    interface port (for analog phones)");
+               if (te && nt && bri)
+                       printf("TE/NT-mode BRI S/T (for phone lines & phones)");
+               if (te && !nt && bri)
+                       printf("TE-mode    BRI S/T (for phone lines)");
+               if (nt && !te && bri)
+                       printf("NT-mode    BRI S/T (for phones)");
+               if (te && nt && pri)
+                       printf("TE/NT-mode PRI E1  (for phone lines & E1 devices)");
+               if (te && !nt && pri)
+                       printf("TE-mode    PRI E1  (for phone lines)");
+               if (nt && !te && pri)
+                       printf("NT-mode    PRI E1  (for E1 devices)");
+               if (te && nt && pots)
+                       printf("FXS/FXO    POTS    (for analog lines & phones)");
+               if (te && !nt && pots)
+                       printf("FXS        POTS    (for analog lines)");
+               if (nt && !te && pots)
+                       printf("FXO        POTS    (for analog phones)");
                if (pots)
                {
                        useable = 0;
@@ -3641,7 +3674,7 @@ void mISDN_port_info(void)
                        useable = 1;
                        nt = 1;
                        pri = 1;
-                       printf("NT-mode PRI E1  interface port (for E1 terminals)");
+                       printf("NT-mode PRI E1  interface port (for E1 devices)");
                        break;
                        default:
                        useable = 0;
@@ -3780,7 +3813,7 @@ void PmISDN::txfromup(unsigned char *data, int length)
 #ifdef SOCKET_MISDN
                hh->prim = DL_DATA_REQ; 
                hh->id = 0;
-               memcpy(buf+MISDN_HEADER_LEN, data, ISDN_LOAD);
+               memset(buf+MISDN_HEADER_LEN, (options.law=='a')?0x2a:0xff, ISDN_LOAD);
                ret = sendto(p_m_mISDNport->b_socket[p_m_b_index], buf, MISDN_HEADER_LEN+ISDN_LOAD, 0, NULL, 0);
                if (!ret)
                        PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_socket[p_m_b_index]);
@@ -3789,7 +3822,7 @@ void PmISDN::txfromup(unsigned char *data, int length)
                frm->addr = p_m_mISDNport->b_addr[p_m_b_index] | FLG_MSG_DOWN;
                frm->dinfo = 0;
                frm->len = ISDN_LOAD;
-               memcpy(buf+mISDN_HEADER_LEN, data, ISDN_LOAD);
+               memset(buf+mISDN_HEADER_LEN, (options.law=='a')?0x2a:0xff, ISDN_LOAD);
                mISDN_write(mISDNdevice, frm, mISDN_HEADER_LEN+ISDN_LOAD, TIMEOUT_1SEC);
 #endif
                p_m_load += ISDN_LOAD;