socket mISDN work
[lcr.git] / bchannel.c
index 6d504bd..dbc11d7 100644 (file)
@@ -49,7 +49,7 @@ enum {
        BSTATE_ACTIVE,
 };
 
-#ifdef MISDN_SOCKET
+#ifdef SOCKET_MISDN
 int bchannel_socket = -1;
 
 int bchannel_initialize(void)
@@ -225,7 +225,7 @@ int bchannel_create(struct bchannel *channel)
 
        if (channel->b_sock)
        {
-               PERROR("Error: Socket already created for handle %d\n", channel->handle);
+               PERROR("Error: Socket already created for handle 0x%x\n", channel->handle);
                return(0);
        }
 
@@ -233,7 +233,7 @@ int bchannel_create(struct bchannel *channel)
        channel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_L2DSP);
        if (channel->b_sock < 0)
        {
-               PERROR("Error: Failed to open bchannel-socket for handle %d with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", channel->handle);
+               PERROR("Error: Failed to open bchannel-socket for handle 0x%x with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", channel->handle);
                return(0);
        }
        
@@ -241,7 +241,7 @@ int bchannel_create(struct bchannel *channel)
        ret = ioctl(channel->b_sock, FIONBIO, &on);
        if (ret < 0)
        {
-               PERROR("Error: Failed to set bchannel-socket handle %d into nonblocking IO\n", channel->handle);
+               PERROR("Error: Failed to set bchannel-socket handle 0x%x into nonblocking IO\n", channel->handle);
                close(channel->b_sock);
                channel->b_sock = -1;
                return(0);
@@ -251,10 +251,10 @@ int bchannel_create(struct bchannel *channel)
        addr.family = AF_ISDN;
        addr.dev = (channel->handle>>8)-1;
        addr.channel = channel->handle && 0xff;
-       ret = bind(di->bchan, (struct sockaddr *)&addr, sizeof(addr));
+       ret = bind(channel->b_sock, (struct sockaddr *)&addr, sizeof(addr));
        if (ret < 0)
        {
-               PERROR("Error: Failed to bind bchannel-socket for handle %d with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", channel->handle);
+               PERROR("Error: Failed to bind bchannel-socket for handle 0x%x with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", channel->handle);
                close(channel->b_sock);
                channel->b_sock = -1;
                return(0);
@@ -424,6 +424,8 @@ static void bchannel_activated(struct bchannel *channel)
                ph_control(handle, DTMF_TONE_START, 0, "DSP-DTMF", 1);
        if (channel->b_crypt_len)
                ph_control_block(handle, BF_ENABLE_KEY, channel->b_crypt_key, channel->b_crypt_len, "DSP-CRYPT", channel->b_crypt_len);
+       if (channel->b_conf)
+               ph_control(handle, CMX_CONF_JOIN, channel->b_conf, "DSP-CONF", channel->b_conf);
 
        channel->b_state = BSTATE_ACTIVE;
 }
@@ -694,38 +696,32 @@ int bchannel_handle(void)
 #else
 int bchannel_handle(void)
 {
-       int ret;
        int i;
        struct bchannel *channel;
-       msg_t *msg;
        iframe_t *frm;
-       msg_t *dmsg;
-       mISDNuser_head_t *hh;
-       net_stack_t *nst;
+       unsigned char buffer[2048];
+       struct mISDNhead *hh = (struct mISDNhead *)buffer;
+       int len;
 
        /* no device, no read */
        if (bchannel_device < 0)
                return(0);
 
        /* get message from kernel */
-       if (!(msg = alloc_msg(MAX_MSG_SIZE)))
-               return(1);
-       ret = mISDN_read(bchannel_device, msg->data, MAX_MSG_SIZE, 0);
-       if (ret < 0)
+       len = mISDN_read(bchannel_device, buffer, sizeof(buffer), 0);
+       if (len < 0)
        {
-               free_msg(msg);
                if (errno == EAGAIN)
                        return(0);
-               FATAL("Failed to do mISDN_read()\n");
+               PERROR("Failed to do mISDN_read()\n");
+               return(0);
        }
-       if (!ret)
+       if (!len)
        {
-               free_msg(msg);
 //             printf("%s: ERROR: mISDN_read() returns nothing\n");
                return(0);
        }
-       msg->len = ret;
-       frm = (iframe_t *)msg->data;
+       frm = (iframe_t *)buffer;
 
        /* global prim */
        switch(frm->prim)
@@ -735,7 +731,6 @@ int bchannel_handle(void)
                case MGR_ADDTIMER | CONFIRM:
                case MGR_DELTIMER | CONFIRM:
                case MGR_REMOVETIMER | CONFIRM:
-               free_msg(msg);
                return(1);
        }
 
@@ -749,7 +744,7 @@ int bchannel_handle(void)
        } 
        if (!channel)
        {
-               PERROR("message belongs to no channel: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
+               PERROR("message belongs to no channel: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, len);
                goto out;
        }
 
@@ -766,7 +761,7 @@ int bchannel_handle(void)
                case DL_DATA | INDICATION:
                case PH_CONTROL | INDICATION:
                case PH_SIGNAL | INDICATION:
-               bchannel_receive(channel, frm->prim, frm->dinfo, frm->data.p, frm->len);
+               bchannel_receive(channel, frm->prim, frm->dinfo, (unsigned char *)frm->data.p, frm->len);
                break;
 
                case PH_ACTIVATE | INDICATION:
@@ -786,11 +781,10 @@ int bchannel_handle(void)
                break;
 
                default:
-               PERROR("message not handled: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
+               PERROR("message not handled: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, len);
        }
 
        out:
-       free_msg(msg);
        return(1);
 }
 #endif
@@ -828,16 +822,16 @@ struct bchannel *find_bchannel_ref(unsigned long ref)
 
 struct bchannel *alloc_bchannel(unsigned long handle)
 {
-       struct chan_bchannel **channelp = &bchannel_first;
+       struct bchannel **channelp = &bchannel_first;
 
        while(*channelp)
                channelp = &((*channelp)->next);
 
-       *channelp = (struct chan_bchannel *)malloc(sizeof(struct chan_bchannel));
+       *channelp = (struct bchannel *)malloc(sizeof(struct bchannel));
        if (!*channelp)
                return(NULL);
-       channel->handle = handle;
-       channel->b_state = BSTATE_IDLE;
+       (*channelp)->handle = handle;
+       (*channelp)->b_state = BSTATE_IDLE;
                
        return(*channelp);
 }