Changing version number to 1.9
[lcr.git] / bchannel.c
index 51423a1..5793795 100644 (file)
 #include <netinet/in.h>
 #include <netdb.h>
 #include <sys/socket.h>
-#include <mISDNif.h>
+#include <mISDN/mISDNif.h>
 
-#define AF_COMPATIBILITY_FUNC 1
-#define MISDN_OLD_AF_COMPATIBILITY 1
-#include <compat_af_isdn.h>
+#include <mISDN/mISDNcompat.h>
+int __af_isdn = MISDN_AF_ISDN;
+#include <mISDN/q931.h>
 
 #define HAVE_ATTRIBUTE_always_inline 1
 #define HAVE_ARPA_INET_H 1
@@ -74,8 +74,6 @@ static void bchannel_send_queue(struct bchannel *bchannel);
 
 int bchannel_initialize(void)
 {
-       init_af_isdn();
-
        return 0;
 }
 
@@ -420,26 +418,29 @@ void bchannel_transmit(struct bchannel *bchannel, unsigned char *data, int len)
                return;
        if (len > 1024 || len < 1)
                return;
-       switch(bchannel->b_mode) {
-       case 0:
-               for (i = 0; i < len; i++)
-                       *p++ = flip_bits[*data++];
-               frm->prim = DL_DATA_REQ;
-               break;
-       case 1:
-               for (i = 0; i < len; i++)
-                       *p++ = flip_bits[*data++];
-               frm->prim = PH_DATA_REQ;
-               break;
-       case 2:
-               memcpy(p, data, len);
-               frm->prim = DL_DATA_REQ;
-               break;
-       case 3:
-               memcpy(p, data, len);
-               frm->prim = PH_DATA_REQ;
-               break;
-       }
+       if (data) {
+               switch(bchannel->b_mode) {
+               case 0:
+                       for (i = 0; i < len; i++)
+                               *p++ = flip_bits[*data++];
+                       frm->prim = DL_DATA_REQ;
+                       break;
+               case 1:
+                       for (i = 0; i < len; i++)
+                               *p++ = flip_bits[*data++];
+                       frm->prim = PH_DATA_REQ;
+                       break;
+               case 2:
+                       memcpy(p, data, len);
+                       frm->prim = DL_DATA_REQ;
+                       break;
+               case 3:
+                       memcpy(p, data, len);
+                       frm->prim = PH_DATA_REQ;
+                       break;
+               }
+       } else
+               memset(p, flip_bits[(options.law=='a')?0x2a:0xff], len);
        frm->id = 0;
 #ifdef SEAMLESS_TEST
        unsigned char test_tone[8] = {0x2a, 0x24, 0xb4, 0x24, 0x2a, 0x25, 0xb5, 0x25};
@@ -449,9 +450,9 @@ void bchannel_transmit(struct bchannel *bchannel, unsigned char *data, int len)
        bchannel->test = (bchannel->test + len) & 7;
 #endif
        if (bchannel->nodsp_queue) {
-               space = (bchannel->nodsp_queue_out - bchannel->nodsp_queue_in) & (QUEUE_BUFFER_SIZE - 1);
+               space = (bchannel->nodsp_queue_out - bchannel->nodsp_queue_in - 1) & (QUEUE_BUFFER_SIZE - 1);
                if (len > space) {
-                       CERROR(bchannel->call, NULL, "Queue buffer overflow.\n");
+                       CERROR(bchannel->call, NULL, "Queue buffer overflow, space is %d, len is %d.\n", space, len);
                        return;
                }
                p = buff + MISDN_HEADER_LEN;
@@ -485,6 +486,11 @@ static void bchannel_send_queue(struct bchannel *bchannel)
        len = (bchannel->nodsp_queue_in - bchannel->nodsp_queue_out) & (QUEUE_BUFFER_SIZE - 1);
        if (len == 0)
                return; /* mISDN driver received all load */
+#if 0
+       printf("%4d:(%s|%s)\n", bchannel->nodsp_queue_out,
+               "----------------------------------------------------------------"+64-len/(8192/64),
+               "                                                                "+len/(8192/64));
+#endif
        if (len > 1024)
                len = 1024;
        frm->prim = PH_DATA_REQ;