Added display of current active TEI values (L2) at lcradmin.
[lcr.git] / bchannel.c
index c5dcc4b..187409f 100644 (file)
 #include <sys/socket.h>
 #include <mISDNif.h>
 
+#define AF_COMPATIBILITY_FUNC 1
+#define MISDN_OLD_AF_COMPATIBILITY 1
+#include <compat_af_isdn.h>
+
+#define HAVE_ATTRIBUTE_always_inline 1
+#define HAVE_ARPA_INET_H 1
+#define HAVE_TIMERSUB 1
+
+#include <asterisk/compiler.h>
 #include <asterisk/frame.h>
 
+/* Choose if you want to have chan_lcr for Asterisk 1.4.x or CallWeaver 1.2.x */
+/* #define LCR_FOR_CALLWEAVER */
+
+#ifdef LCR_FOR_CALLWEAVER
+#include <asterisk/phone_no_utils.h>
+#include <asterisk/logger.h>
+#include <asterisk/module.h>
+#include <asterisk/channel.h>
+#endif
 
 #include "extension.h"
 #include "message.h"
@@ -53,6 +71,8 @@ enum {
 
 int bchannel_initialize(void)
 {
+       init_af_isdn();
+
        return(0);
 }
 
@@ -142,7 +162,7 @@ int bchannel_create(struct bchannel *bchannel, int mode)
        }
        if (bchannel->b_sock < 0)
        {
-               CERROR(bchannel->call, NULL, "Failed to open bchannel-socket for handle 0x%x with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", bchannel->handle);
+               CERROR(bchannel->call, NULL, "Failed to open bchannel-socket for handle 0x%x with mISDN-DSP layer. Did you load mISDN_dsp.ko?\n", bchannel->handle);
                return(0);
        }
        
@@ -158,12 +178,12 @@ int bchannel_create(struct bchannel *bchannel, int mode)
 
        /* bind socket to bchannel */
        addr.family = AF_ISDN;
-       addr.dev = (bchannel->handle>>8)-1;
+       addr.dev = (bchannel->handle>>8);
        addr.channel = bchannel->handle & 0xff;
        ret = bind(bchannel->b_sock, (struct sockaddr *)&addr, sizeof(addr));
        if (ret < 0)
        {
-               CERROR(bchannel->call, NULL, "Failed to bind bchannel-socket for handle 0x%x with mISDN-DSP layer. (port %d, channel %d) Did you load mISDNdsp.ko?\n", bchannel->handle, addr.dev + 1, addr.channel);
+               CERROR(bchannel->call, NULL, "Failed to bind bchannel-socket for handle 0x%x with mISDN-DSP layer. (port %d, channel %d) Did you load mISDN_dsp.ko?\n", bchannel->handle, addr.dev, addr.channel);
                close(bchannel->b_sock);
                bchannel->b_sock = -1;
                return(0);
@@ -199,7 +219,6 @@ void bchannel_activate(struct bchannel *bchannel, int activate)
                CERROR(bchannel->call, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
 
        bchannel->b_state = (activate)?BSTATE_ACTIVATING:BSTATE_DEACTIVATING;
-       bchannel->rebuffer_usage = 0;
 }
 
 
@@ -254,7 +273,6 @@ void bchannel_destroy(struct bchannel *bchannel)
        {
                close(bchannel->b_sock);
                bchannel->b_sock = -1;
-               bchannel->rebuffer_usage = 0;
        }
        bchannel->b_state = BSTATE_IDLE;
 }
@@ -379,52 +397,15 @@ static void bchannel_receive(struct bchannel *bchannel, unsigned char *buffer, i
                }
        }
 
-       /* no hdlc and rebuffer */
-       if (bchannel->call->rebuffer && !bchannel->call->hdlc) {
-               int u = bchannel->rebuffer_usage;
-               unsigned char * b = bchannel->rebuffer;
-               int l = len;
-               int fd = bchannel->call->pipe[1];
-
-               d = data;
-
-               if (u > 0) {
-                       if (u + l >= 160) {
-                               memcpy(b + u, d, 160 - u);
-                               d += 160 - u;
-                               l -= 160 - u;
-                               u = 0;
-                               if (write(fd, b, 160) < 0)
-                                       goto errout;
-                       } else {
-                               memcpy(b + u, d, l);
-                               u += l;
-                               l = 0;
-                       }
-               }
-
-               while (l >= 160) {
-                       if (write(fd, d, 160) < 0)
-                               goto errout;
-                       d += 160;
-                       l -= 160;
-               }
-
-               if (l > 0) {
-                       memcpy(b, d, l);
-               } 
-               bchannel->rebuffer_usage = u + l;
-       } else {
-               len = write(bchannel->call->pipe[1], data, len);
-               if (len < 0)
-                       goto errout;
-       }
+       
+       len = write(bchannel->call->pipe[1], data, len);
+       if (len < 0)
+               goto errout;
 
        return;
  errout:
        close(bchannel->call->pipe[1]);
        bchannel->call->pipe[1] = -1;
-       bchannel->rebuffer_usage = 0;
        CDEBUG(bchannel->call, NULL, "broken pipe on bchannel pipe\n");
 }
 
@@ -445,20 +426,22 @@ void bchannel_transmit(struct bchannel *bchannel, unsigned char *data, int len)
                return;
        switch(bchannel->b_mode)
        {
-               case 0:
+       case 0:
                for (i = 0; i < len; i++)
                        *p++ = flip_bits[*data++];
                frm->prim = DL_DATA_REQ;
                break;
-               case 1:
+       case 1:
                for (i = 0; i < len; i++)
                        *p++ = flip_bits[*data++];
                frm->prim = PH_DATA_REQ;
                break;
-               case 2:
+       case 2:
+               memcpy(p, data, len);
                frm->prim = DL_DATA_REQ;
                break;
-               case 3:
+       case 3:
+               memcpy(p, data, len);
                frm->prim = PH_DATA_REQ;
                break;
        }