some fixes, check README
[lcr.git] / mISDN.cpp
index 2507209..3c4c23d 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -28,7 +28,7 @@
 #include <mlayer3.h>
 #else
 extern "C" {
-#include <net_l2.h>
+#include <mISDNuser/net_l2.h>
 }
 #endif
 
@@ -1173,15 +1173,14 @@ seize:
  */
 void PmISDN::drop_bchannel(void)
 {
-       if (p_m_b_index < 0)
-               return;
-
        /* unreserve channel */
        if (p_m_b_reserve)
                p_m_mISDNport->b_reserved--;
        p_m_b_reserve = 0;
 
        /* if not in use */
+       if (p_m_b_index < 0)
+               return;
        if (!p_m_b_channel)
                return;
 
@@ -1265,7 +1264,7 @@ void message_bchannel_from_join(class JoinRemote *joinremote, int type, unsigned
 #ifdef SOCKET_MISDN
                                if (mISDNport->b_socket[i] == handle)
 #else
-                               if ((mISDNport->portnum<<8)+i+1+(i>=15) == handle)
+                               if ((unsigned long)(mISDNport->portnum<<8)+i+1+(i>=15) == handle)
 #endif
                                        break;
                                i++;
@@ -1383,7 +1382,9 @@ int PmISDN::handler(void)
                        p_m_load = 0;
 
                /* to send data, tone must be active OR crypt messages must be on */
-               if ((p_tone_name[0] || p_m_crypt_msg_loops) && p_m_load < ISDN_LOAD)
+               if ((p_tone_name[0] || p_m_crypt_msg_loops)
+                && (p_m_load < ISDN_LOAD)
+                && (p_state==PORT_STATE_CONNECT || p_m_mISDNport->tones))
                {
                        int tosend = ISDN_LOAD - p_m_load, length; 
 #ifdef SOCKET_MISDN
@@ -1416,6 +1417,7 @@ int PmISDN::handler(void)
                                        /* next loop */
                                        p_m_crypt_msg_current = 0;
                                        p_m_crypt_msg_loops--;
+//                                     puts("eine loop weniger");
                                }
 
                                /* new length */
@@ -1532,6 +1534,21 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                        message_put(message);
                        break;
 
+                       default:
+                       chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
+                       add_trace("unknown", NULL, "0x%x", cont);
+                       end_trace();
+               }
+               return;
+       }
+#ifdef SOCKET_MISDN
+       if (hh->prim == PH_SIGNAL_IND)
+#else
+       if (frm->prim == (PH_SIGNAL | INDICATION))
+#endif
+       {
+               switch(frm->dinfo)
+               {
                        case CMX_TX_DATA:
                        if (!p_m_txdata)
                        {
@@ -1539,13 +1556,18 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                                PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring tx data, because 'txdata' is turned off\n", p_name);
                                return;
                        }
+                       /* see below (same condition) */
+                       if (p_state!=PORT_STATE_CONNECT
+                                && !p_m_mISDNport->tones)
+                               break;
+//                     printf(".");fflush(stdout);return;
                        if (p_record)
-                               record((unsigned char *)(cont+1), len - 4, 1); // from up
+                               record(data, len, 1); // from up
                        break;
 
                        default:
-                       chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
-                       add_trace("unknown", NULL, "0x%x", cont);
+                       chan_trace_header(p_m_mISDNport, this, "BCHANNEL signal", DIRECTION_IN);
+                       add_trace("unknown", NULL, "0x%x", frm->dinfo);
                        end_trace();
                }
                return;
@@ -1561,14 +1583,13 @@ void PmISDN::bchannel_receive(iframe_t *frm)
 #endif
                return;
        }
-
        /* calls will not process any audio data unless
         * the call is connected OR interface features audio during call setup.
         */
 //printf("%d -> %d prim=%x joindata=%d tones=%d\n", p_serial, ACTIVE_EPOINT(p_epointlist), frm->prim, p_m_joindata, p_m_mISDNport->earlyb);    
 #ifndef DEBUG_COREBRIDGE
        if (p_state!=PORT_STATE_CONNECT
-        && !p_m_mISDNport->earlyb)
+        && !p_m_mISDNport->tones)
                return;
 #endif
 
@@ -1896,7 +1917,7 @@ void PmISDN::message_crypt(unsigned long epoint_id, int message_id, union parame
                        break;
                }
                p_m_crypt_msg_current = 0; /* reset */
-               p_m_crypt_msg_loops = 3; /* enable */
+               p_m_crypt_msg_loops = 6; /* enable */
 #if 0
                /* disable txmix, or we get corrupt data due to audio process */
                if (p_m_txmix && p_m_b_index>=0)
@@ -1952,7 +1973,7 @@ int PmISDN::message_epoint(unsigned long epoint_id, int message_id, union parame
 #ifdef SOCKET_MISDN
 int mISDN_handler(void)
 {
-       int ret;
+       int ret, work = 0;
        struct mISDNport *mISDNport;
        class PmISDN *isdnport;
        int i;
@@ -2031,6 +2052,7 @@ int mISDN_handler(void)
                                ret = recv(mISDNport->b_stack[i], buffer, sizeof(buffer), 0);
                                if (ret >= MISDN_HEADER_LEN)
                                {
+                                       work = 1;
                                        switch(hh->prim)
                                        {
                                                /* we don't care about confirms, we use rx data to sync tx */
@@ -2041,6 +2063,7 @@ int mISDN_handler(void)
                                                /* we receive audio data, we respond to it AND we send tones */
                                                case PH_DATA_IND:
                                                case DL_DATA_IND:
+                                               case PH_SIGNAL_IND:
                                                case PH_CONTROL_IND:
                                                if (mISDNport->b_port[i])
                                                        mISDNport->b_port[i]->bchannel_receive(hh, buffer+MISDN_HEADER_LEN, ret-MISDN_HEADER_LEN);
@@ -2101,6 +2124,8 @@ int mISDN_handler(void)
                mISDNport = mISDNport->next;
        }
 
+       /* if we received at least one b-frame, we will return 1 */
+       return(work);
 }
 #else
 int mISDN_handler(void)
@@ -2460,6 +2485,7 @@ int mISDN_handler(void)
                        case PH_DATA | INDICATION:
                        case DL_DATA | INDICATION:
                        case PH_CONTROL | INDICATION:
+                       case PH_SIGNAL | INDICATION:
                        i = 0;
                        while(i < mISDNport->b_num)
                        {