rebuffer option for chan_lcr (160 bytes per frame)
[lcr.git] / bchannel.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** mISDN channel handlin for remote application                              **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <poll.h>
17 #include <errno.h>
18 #include <sys/ioctl.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <netinet/udp.h>
23 #include <netinet/in.h>
24 #include <netdb.h>
25 #include <sys/socket.h>
26 #include <mISDNif.h>
27
28 #include <asterisk/frame.h>
29
30
31 #include "extension.h"
32 #include "message.h"
33 #include "lcrsocket.h"
34 #include "cause.h"
35 #include "bchannel.h"
36 #include "chan_lcr.h"
37 #include "callerid.h"
38
39
40 #ifndef ISDN_PID_L4_B_USER
41 #define ISDN_PID_L4_B_USER 0x440000ff
42 #endif
43
44 pid_t   bchannel_pid;
45
46 enum {
47         BSTATE_IDLE,
48         BSTATE_ACTIVATING,
49         BSTATE_ACTIVE,
50         BSTATE_DEACTIVATING,
51 };
52
53
54 int bchannel_initialize(void)
55 {
56         return(0);
57 }
58
59 void bchannel_deinitialize(void)
60 {
61 }
62
63 /*
64  * send control information to the channel (dsp-module)
65  */
66 static void ph_control(int sock, unsigned int c1, unsigned int c2, char *trace_name, int trace_value, int b_mode)
67 {
68         unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)];
69         struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
70         unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
71         int ret;
72
73         if (b_mode != 0 && b_mode != 2)
74                 return;
75
76         CDEBUG(NULL, NULL, "Sending PH_CONTROL %s %x,%x\n", trace_name, c1, c2);
77         ctrl->prim = PH_CONTROL_REQ;
78         ctrl->id = 0;
79         *d++ = c1;
80         *d++ = c2;
81         ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)*2, 0, NULL, 0);
82         if (ret < 0)
83                 CERROR(NULL, NULL, "Failed to send to socket %d\n", sock);
84 }
85
86 static void ph_control_block(int sock, unsigned int c1, void *c2, int c2_len, char *trace_name, int trace_value, int b_mode)
87 {
88         unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+c2_len];
89         struct mISDNhead *ctrl = (struct mISDNhead *)buffer;
90         unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN);
91         int ret;
92
93         if (b_mode != 0 && b_mode != 2)
94                 return;
95
96         CDEBUG(NULL, NULL, "Sending PH_CONTROL (block) %s %x\n", trace_name, c1);
97         ctrl->prim = PH_CONTROL_REQ;
98         ctrl->id = 0;
99         *d++ = c1;
100         memcpy(d, c2, c2_len);
101         ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)+c2_len, 0, NULL, 0);
102         if (ret < 0)
103                 CERROR(NULL, NULL, "Failed to send to socket %d\n", sock);
104 }
105
106
107 /*
108  * create stack
109  */
110 int bchannel_create(struct bchannel *bchannel, int mode)
111 {
112         int ret;
113         unsigned int on = 1;
114         struct sockaddr_mISDN addr;
115
116         if (bchannel->b_sock > -1)
117         {
118                 CERROR(NULL, NULL, "Socket already created for handle 0x%x\n", bchannel->handle);
119                 return(0);
120         }
121
122         /* open socket */
123         bchannel->b_mode = mode;
124         switch(bchannel->b_mode)
125         {
126                 case 0:
127                 bchannel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_L2DSP);
128                 break;
129                 case 1:
130                 bchannel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW);
131                 break;
132                 case 2:
133                 bchannel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_L2DSPHDLC);
134                 break;
135                 case 3:
136                 bchannel->b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_HDLC);
137                 break;
138         }
139         if (bchannel->b_sock < 0)
140         {
141                 CERROR(NULL, NULL, "Failed to open bchannel-socket for handle 0x%x with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", bchannel->handle);
142                 return(0);
143         }
144         
145         /* set nonblocking io */
146         ret = ioctl(bchannel->b_sock, FIONBIO, &on);
147         if (ret < 0)
148         {
149                 CERROR(NULL, NULL, "Failed to set bchannel-socket handle 0x%x into nonblocking IO\n", bchannel->handle);
150                 close(bchannel->b_sock);
151                 bchannel->b_sock = -1;
152                 return(0);
153         }
154
155         /* bind socket to bchannel */
156         addr.family = AF_ISDN;
157         addr.dev = (bchannel->handle>>8)-1;
158         addr.channel = bchannel->handle & 0xff;
159         ret = bind(bchannel->b_sock, (struct sockaddr *)&addr, sizeof(addr));
160         if (ret < 0)
161         {
162                 CERROR(NULL, 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);
163                 close(bchannel->b_sock);
164                 bchannel->b_sock = -1;
165                 return(0);
166         }
167         return(1);
168 }
169
170
171 /*
172  * activate / deactivate request
173  */
174 void bchannel_activate(struct bchannel *bchannel, int activate)
175 {
176         struct mISDNhead act;
177         int ret;
178
179         /* activate bchannel */
180         CDEBUG(NULL, NULL, "%sActivating B-channel.\n", activate?"":"De-");
181         switch(bchannel->b_mode)
182         {
183                 case 0:
184                 case 2:
185                 act.prim = (activate)?DL_ESTABLISH_REQ:DL_RELEASE_REQ; 
186                 break;
187                 case 1:
188                 case 3:
189                 act.prim = (activate)?PH_ACTIVATE_REQ:PH_DEACTIVATE_REQ; 
190                 break;
191         }
192         act.id = 0;
193         ret = sendto(bchannel->b_sock, &act, MISDN_HEADER_LEN, 0, NULL, 0);
194         if (ret < 0)
195                 CERROR(NULL, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
196
197         bchannel->b_state = (activate)?BSTATE_ACTIVATING:BSTATE_DEACTIVATING;
198         bchannel->rebuffer_usage = 0;
199 }
200
201
202 /*
203  * set features
204  */
205 static void bchannel_activated(struct bchannel *bchannel)
206 {
207         int sock;
208
209         sock = bchannel->b_sock;
210
211         /* set dsp features */
212         if (bchannel->b_txdata)
213                 ph_control(sock, (bchannel->b_txdata)?DSP_TXDATA_ON:DSP_TXDATA_OFF, 0, "DSP-TXDATA", bchannel->b_txdata, bchannel->b_mode);
214         if (bchannel->b_delay)
215                 ph_control(sock, DSP_DELAY, bchannel->b_delay, "DSP-DELAY", bchannel->b_delay, bchannel->b_mode);
216         if (bchannel->b_tx_dejitter)
217                 ph_control(sock, (bchannel->b_tx_dejitter)?DSP_TX_DEJITTER:DSP_TX_DEJ_OFF, 0, "DSP-TX_DEJITTER", bchannel->b_tx_dejitter, bchannel->b_mode);
218         if (bchannel->b_tx_gain)
219                 ph_control(sock, DSP_VOL_CHANGE_TX, bchannel->b_tx_gain, "DSP-TX_GAIN", bchannel->b_tx_gain, bchannel->b_mode);
220         if (bchannel->b_rx_gain)
221                 ph_control(sock, DSP_VOL_CHANGE_RX, bchannel->b_rx_gain, "DSP-RX_GAIN", bchannel->b_rx_gain, bchannel->b_mode);
222         if (bchannel->b_pipeline[0])
223                 ph_control_block(sock, DSP_PIPELINE_CFG, bchannel->b_pipeline, strlen(bchannel->b_pipeline)+1, "DSP-PIPELINE", 0, bchannel->b_mode);
224         if (bchannel->b_conf)
225                 ph_control(sock, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf, bchannel->b_mode);
226         if (bchannel->b_echo)
227                 ph_control(sock, DSP_ECHO_ON, 0, "DSP-ECHO", 1, bchannel->b_mode);
228         if (bchannel->b_tone)
229                 ph_control(sock, DSP_TONE_PATT_ON, bchannel->b_tone, "DSP-TONE", bchannel->b_tone, bchannel->b_mode);
230         if (bchannel->b_rxoff)
231                 ph_control(sock, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1, bchannel->b_mode);
232 //      if (bchannel->b_txmix)
233 //              ph_control(sock, DSP_MIX_ON, 0, "DSP-MIX", 1, bchannel->b_mode);
234         if (bchannel->b_dtmf)
235                 ph_control(sock, DTMF_TONE_START, 0, "DSP-DTMF", 1, bchannel->b_mode);
236         if (bchannel->b_bf_len)
237                 ph_control_block(sock, DSP_BF_ENABLE_KEY, bchannel->b_bf_key, bchannel->b_bf_len, "DSP-CRYPT", bchannel->b_bf_len, bchannel->b_mode);
238         if (bchannel->b_conf)
239                 ph_control(sock, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf, bchannel->b_mode);
240
241         bchannel->b_state = BSTATE_ACTIVE;
242 }
243
244 /*
245  * destroy stack
246  */
247 void bchannel_destroy(struct bchannel *bchannel)
248 {
249         if (bchannel->b_sock > -1)
250         {
251                 close(bchannel->b_sock);
252                 bchannel->b_sock = -1;
253                 bchannel->rebuffer_usage = 0;
254         }
255         bchannel->b_state = BSTATE_IDLE;
256 }
257
258
259 /*
260  * whenever we get audio data from bchannel, we process it here
261  */
262 static void bchannel_receive(struct bchannel *bchannel, unsigned char *buffer, int len)
263 {
264         struct mISDNhead *hh = (struct mISDNhead *)buffer;
265         unsigned char *data = buffer + MISDN_HEADER_LEN;
266         unsigned int cont = *((unsigned int *)data);
267         struct bchannel *remote_bchannel;
268         int ret;
269
270         if (hh->prim == PH_CONTROL_IND)
271         {
272                 if (len < 4)
273                 {
274                         CERROR(NULL, NULL, "SHORT READ OF PH_CONTROL INDICATION\n");
275                         return;
276                 }
277                 if ((cont&(~DTMF_TONE_MASK)) == DTMF_TONE_VAL)
278                 {
279                         if (bchannel->call)
280                                 lcr_in_dtmf(bchannel->call, cont & DTMF_TONE_MASK);
281                         return;
282                 }
283                 switch(cont)
284                 {
285                         case DSP_BF_REJECT:
286                         CERROR(NULL, NULL, "Blowfish crypt rejected.\n");
287                         break;
288
289                         case DSP_BF_ACCEPT:
290                         CDEBUG(NULL, NULL, "Blowfish crypt enabled.\n");
291                         break;
292
293                         default:
294                         CDEBUG(NULL, NULL, "Unhandled bchannel control 0x%x.\n", cont);
295                 }
296                 return;
297         }
298         if (hh->prim == PH_DATA_REQ)
299         {
300                 if (!bchannel->b_txdata)
301                 {
302                         /* if tx is off, it may happen that fifos send us pending informations, we just ignore them */
303                         CDEBUG(NULL, NULL, "ignoring tx data, because 'txdata' is turned off\n");
304                         return;
305                 }
306                 return;
307         }
308         if (hh->prim != PH_DATA_IND && hh->prim != DL_DATA_IND)
309         {
310                 CERROR(NULL, NULL, "Bchannel received unknown primitve: 0x%lx\n", hh->prim);
311                 return;
312         }
313         /* if call is bridged and in non-dsp mode */
314         if (bchannel->b_conf
315          && (bchannel->b_mode == 1 || bchannel->b_mode == 3)
316          && bchannel->call
317          && bchannel->call->bridge_call
318          && bchannel->call->bridge_call->bchannel)
319         {
320                 remote_bchannel = bchannel->call->bridge_call->bchannel;
321                 if (remote_bchannel->b_mode == 1 || remote_bchannel->b_mode == 3)
322                 {
323                         hh->prim = PH_DATA_REQ;
324                         ret = sendto(remote_bchannel->b_sock, buffer, MISDN_HEADER_LEN+len, 0, NULL, 0);
325                         if (ret < 0)
326                                 CERROR(NULL, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
327                         return;
328                 }
329         }
330         /* calls will not process any audio data unless
331          * the call is connected OR interface features audio during call setup.
332          */
333
334         /* if rx is off, it may happen that fifos send us pending informations, we just ignore them */
335         if (bchannel->b_rxoff)
336         {
337                 CDEBUG(NULL, NULL, "ignoring data, because rx is turned off\n");
338                 return;
339         }
340
341         if (!bchannel->call)
342         {
343                 CDEBUG(NULL, NULL, "ignoring data, because no call associated with bchannel\n");
344                 return;
345         }
346         if (!bchannel->call->audiopath)
347         {
348                 /* return, because we have no audio from port */
349                 return;
350         }
351
352         if (bchannel->call->pipe[1] < 0)
353         {
354                 /* nobody there */
355                 return;
356         }
357
358
359         if (bchannel->call->rebuffer) {
360                 int u = bchannel->rebuffer_usage;
361                 unsigned char * b = bchannel->rebuffer;
362                 unsigned char * d = data;
363                 int l = len;
364                 int fd = bchannel->call->pipe[1];
365
366                 if (u > 0) {
367                         if (u + l >= 160) {
368                                 memcpy(b + u, d, 160 - u);
369                                 d += 160 - u;
370                                 l -= 160 - u;
371                                 u = 0;
372                                 if (write(fd, b, 160) < 0) {
373                                         goto errout;
374                                 }
375                         } else {
376                                 memcpy(b + u, d, l);
377                                 u += l;
378                                 l = 0;
379                         }
380                 }
381
382                 while (l >= 160) {
383                         if (write(fd, d, 160) < 0) {
384                                 goto errout;
385                         }
386                         d += 160;
387                         l -= 160;
388                 }
389
390                 if (l > 0) {
391                         memcpy(b, d, l);
392                 } 
393                 bchannel->rebuffer_usage = u + l;
394         } else {
395                 len = write(bchannel->call->pipe[1], data, len);
396                 if (len < 0)
397                 {
398                         goto errout;
399                 }
400         }
401
402         return;
403  errout:
404         close(bchannel->call->pipe[1]);
405         bchannel->call->pipe[1] = -1;
406         bchannel->rebuffer_usage = 0;
407         CDEBUG(NULL, NULL, "broken pipe on bchannel pipe\n");
408 }
409
410
411 /*
412  * transmit data to bchannel
413  */
414 void bchannel_transmit(struct bchannel *bchannel, unsigned char *data, int len)
415 {
416         unsigned char buff[1024 + MISDN_HEADER_LEN], *p = buff + MISDN_HEADER_LEN;
417         struct mISDNhead *frm = (struct mISDNhead *)buff;
418         int ret;
419         int i;
420
421         if (bchannel->b_state != BSTATE_ACTIVE)
422                 return;
423         if (len > 1024 || len < 1)
424                 return;
425         for (i = 0; i < len; i++)
426                 *p++ = flip_bits[*data++];
427         switch(bchannel->b_mode)
428         {
429                 case 0:
430                 case 2:
431                 frm->prim = DL_DATA_REQ;
432                 break;
433                 case 1:
434                 case 3:
435                 frm->prim = PH_DATA_REQ;
436                 break;
437         }
438         frm->id = 0;
439         ret = sendto(bchannel->b_sock, buff, MISDN_HEADER_LEN+len, 0, NULL, 0);
440         if (ret < 0)
441                 CERROR(NULL, NULL, "Failed to send to socket %d\n", bchannel->b_sock);
442 }
443
444
445 /*
446  * join bchannel
447  */
448 void bchannel_join(struct bchannel *bchannel, unsigned short id)
449 {
450         int sock;
451
452         sock = bchannel->b_sock;
453         if (id) {
454                 bchannel->b_conf = (id<<16) + bchannel_pid;
455                 bchannel->b_rxoff = 1;
456         } else {
457                 bchannel->b_conf = 0;
458                 bchannel->b_rxoff = 0;
459         }
460         if (bchannel->b_state == BSTATE_ACTIVE)
461         {
462                 ph_control(sock, DSP_RECEIVE_OFF, bchannel->b_rxoff, "DSP-RX_OFF", bchannel->b_conf, bchannel->b_mode);
463                 ph_control(sock, DSP_CONF_JOIN, bchannel->b_conf, "DSP-CONF", bchannel->b_conf, bchannel->b_mode);
464         }
465 }
466
467
468 /*
469  * dtmf bchannel
470  */
471 void bchannel_dtmf(struct bchannel *bchannel, int on)
472 {
473         int sock;
474
475         sock = bchannel->b_sock;
476         bchannel->b_dtmf = 1;
477         if (bchannel->b_state == BSTATE_ACTIVE)
478                 ph_control(sock, on?DTMF_TONE_START:DTMF_TONE_STOP, 0, "DSP-DTMF", 1, bchannel->b_mode);
479 }
480
481
482 /*
483  * blowfish bchannel
484  */
485 void bchannel_blowfish(struct bchannel *bchannel, unsigned char *key, int len)
486 {
487         int sock;
488
489         sock = bchannel->b_sock;
490         memcpy(bchannel->b_bf_key, key, len);
491         bchannel->b_bf_len = len;
492         if (bchannel->b_state == BSTATE_ACTIVE)
493                 ph_control_block(sock, DSP_BF_ENABLE_KEY, bchannel->b_bf_key, bchannel->b_bf_len, "DSP-CRYPT", bchannel->b_bf_len, bchannel->b_mode);
494 }
495
496
497 /*
498  * pipeline bchannel
499  */
500 void bchannel_pipeline(struct bchannel *bchannel, char *pipeline)
501 {
502         int sock;
503
504         sock = bchannel->b_sock;
505         strncpy(bchannel->b_pipeline, pipeline, sizeof(bchannel->b_pipeline)-1);
506         if (bchannel->b_state == BSTATE_ACTIVE)
507                 ph_control_block(sock, DSP_PIPELINE_CFG, bchannel->b_pipeline, strlen(bchannel->b_pipeline)+1, "DSP-PIPELINE", 0, bchannel->b_mode);
508 }
509
510
511 /*
512  * gain bchannel
513  */
514 void bchannel_gain(struct bchannel *bchannel, int gain, int tx)
515 {
516         int sock;
517
518         sock = bchannel->b_sock;
519         if (tx)
520                 bchannel->b_tx_gain = gain;
521         else
522                 bchannel->b_rx_gain = gain;
523         if (bchannel->b_state == BSTATE_ACTIVE)
524                 ph_control(sock, (tx)?DSP_VOL_CHANGE_TX:DSP_VOL_CHANGE_RX, gain, (tx)?"DSP-TX_GAIN":"DSP-RX_GAIN", gain, bchannel->b_mode);
525 }
526
527
528 /*
529  * main loop for processing messages from mISDN
530  */
531 int bchannel_handle(void)
532 {
533         int ret, work = 0;
534         struct bchannel *bchannel;
535         char buffer[2048+MISDN_HEADER_LEN];
536         struct mISDNhead *hh = (struct mISDNhead *)buffer;
537
538         /* process all bchannels */
539         bchannel = bchannel_first;
540         while(bchannel)
541         {
542                 /* handle message from bchannel */
543                 if (bchannel->b_sock > -1)
544                 {
545                         ret = recv(bchannel->b_sock, buffer, sizeof(buffer), 0);
546                         if (ret >= (int)MISDN_HEADER_LEN)
547                         {
548                                 work = 1;
549                                 switch(hh->prim)
550                                 {
551                                         /* we don't care about confirms, we use rx data to sync tx */
552                                         case PH_DATA_CNF:
553                                         break;
554
555                                         /* we receive audio data, we respond to it AND we send tones */
556                                         case PH_DATA_IND:
557                                         case PH_DATA_REQ:
558                                         case DL_DATA_IND:
559                                         case PH_CONTROL_IND:
560                                         bchannel_receive(bchannel, buffer, ret-MISDN_HEADER_LEN);
561                                         break;
562
563                                         case PH_ACTIVATE_IND:
564                                         case DL_ESTABLISH_IND:
565                                         case PH_ACTIVATE_CNF:
566                                         case DL_ESTABLISH_CNF:
567                                         CDEBUG(NULL, NULL, "DL_ESTABLISH confirm: bchannel is now activated (socket %d).\n", bchannel->b_sock);
568                                         bchannel_activated(bchannel);
569                                         break;
570
571                                         case PH_DEACTIVATE_IND:
572                                         case DL_RELEASE_IND:
573                                         case PH_DEACTIVATE_CNF:
574                                         case DL_RELEASE_CNF:
575                                         CDEBUG(NULL, NULL, "DL_RELEASE confirm: bchannel is now de-activated (socket %d).\n", bchannel->b_sock);
576 //                                      bchannel_deactivated(bchannel);
577                                         break;
578
579                                         default:
580                                         CERROR(NULL, NULL, "child message not handled: prim(0x%x) socket(%d) data len(%d)\n", hh->prim, bchannel->b_sock, ret - MISDN_HEADER_LEN);
581                                 }
582                         } else
583                         {
584                                 if (ret < 0 && errno != EWOULDBLOCK)
585                                         CERROR(NULL, NULL, "Read from socket %d failed with return code %d\n", bchannel->b_sock, ret);
586                         }
587                 }
588                 bchannel = bchannel->next;
589         }
590
591         /* if we received at least one b-frame, we will return 1 */
592         return(work);
593 }
594
595
596 /*
597  * bchannel channel handling
598  */
599 struct bchannel *bchannel_first = NULL;
600 struct bchannel *find_bchannel_handle(unsigned int handle)
601 {
602         struct bchannel *bchannel = bchannel_first;
603
604         while(bchannel)
605         {
606                 if (bchannel->handle == handle)
607                         break;
608                 bchannel = bchannel->next;
609         }
610         return(bchannel);
611 }
612
613 #if 0
614 struct bchannel *find_bchannel_ref(unsigned int ref)
615 {
616         struct bchannel *bchannel = bchannel_first;
617
618         while(bchannel)
619         {
620                 if (bchannel->ref == ref)
621                         break;
622                 bchannel = bchannel->next;
623         }
624         return(bchannel);
625 }
626 #endif
627
628 struct bchannel *alloc_bchannel(unsigned int handle)
629 {
630         struct bchannel **bchannelp = &bchannel_first;
631
632         while(*bchannelp)
633                 bchannelp = &((*bchannelp)->next);
634
635         *bchannelp = (struct bchannel *)calloc(1, sizeof(struct bchannel));
636         if (!*bchannelp)
637                 return(NULL);
638         (*bchannelp)->handle = handle;
639         (*bchannelp)->b_state = BSTATE_IDLE;
640         (*bchannelp)->b_sock = -1;
641                 
642         return(*bchannelp);
643 }
644
645 void free_bchannel(struct bchannel *bchannel)
646 {
647         struct bchannel **temp = &bchannel_first;
648
649         while(*temp)
650         {
651                 if (*temp == bchannel)
652                 {
653                         *temp = (*temp)->next;
654                         if (bchannel->b_sock > -1)
655                                 bchannel_destroy(bchannel);
656                         if (bchannel->call)
657                         {
658                                 if (bchannel->call->bchannel)
659                                         bchannel->call->bchannel = NULL;
660                         }
661                         free(bchannel);
662                         return;
663                 }
664                 temp = &((*temp)->next);
665         }
666 }
667
668