~davewalker/ubuntu/maverick/asterisk/lp_705014

« back to all changes in this revision

Viewing changes to channels/misdn/isdn_lib.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2007-01-28 01:08:48 UTC
  • mto: (1.2.1 upstream) (8.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20070128010848-2a556wel288emdbp
Tags: upstream-1.2.14~dfsg
ImportĀ upstreamĀ versionĀ 1.2.14~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
420
420
{
421
421
        int i;
422
422
 
423
 
        cb_log(1,stack->port,"find_free_chan: req_chan:%d\n",channel);
 
423
        cb_log(5,stack->port,"find_free_chan: req_chan:%d\n",channel);
424
424
 
425
425
        if (channel < 0 || channel > MAX_BCHANS) {
426
 
                cb_log(4, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
 
426
                cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
427
427
                return 0;
428
428
        }
429
429
        
432
432
        for (i = 0; i < stack->b_num; i++) {
433
433
                if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
434
434
                        if (!stack->channels[i]) {
435
 
                                cb_log (1, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
 
435
                                cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
436
436
                                stack->channels[i] = 1;
437
437
                                return i+1;
438
438
                        }
439
439
                }
440
440
        }
441
441
 
442
 
        cb_log (4, stack->port, " !! NO FREE CHAN IN STACK\n");
 
442
        cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
443
443
        dump_chan_list(stack);
444
444
  
445
445
        return 0;
633
633
        
634
634
        cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid);
635
635
        
 
636
        manager_ec_disable(bc);
 
637
 
636
638
        manager_bchannel_deactivate(bc);
637
639
 
638
 
 
639
 
        manager_ec_disable(bc);
640
 
 
641
 
 
642
640
        mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
643
641
        
644
 
        /*mISDN_clear_stack(stack->midev, bc->b_stid);*/
645
 
 
646
 
        
647
642
        bc->b_stid = 0;
648
643
        bc_state_change(bc, BCHAN_CLEANED);
649
644
        
1014
1009
                mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1015
1010
                
1016
1011
                bc_state_change(bc,BCHAN_ERROR);
 
1012
                cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
1017
1013
                return(-EINVAL);
1018
1014
        }
1019
1015
 
1024
1020
                mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1025
1021
                
1026
1022
                bc_state_change(bc,BCHAN_ERROR);
 
1023
                cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
1027
1024
                return(-EINVAL);
1028
1025
        }
1029
1026
 
1036
1033
                mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
1037
1034
                
1038
1035
                bc_state_change(bc,BCHAN_ERROR);
 
1036
                cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data);
 
1037
                return (-EINVAL);
1039
1038
        }
1040
1039
 
1041
1040
        manager_bchannel_activate(bc);
1467
1466
                case EVENT_SETUP_ACKNOWLEDGE:
1468
1467
 
1469
1468
                setup_bc(bc);
1470
 
                
 
1469
 
1471
1470
                case EVENT_SETUP:
1472
1471
                        
1473
1472
                {
1511
1510
        return 0;
1512
1511
}
1513
1512
 
1514
 
int handle_new_process(struct misdn_stack *stack, iframe_t *frm)
1515
 
{
1516
 
  
1517
 
        struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
1518
 
        
1519
 
        
1520
 
        if (!bc) {
1521
 
                cb_log(0, stack->port, " --> !! lib: No free channel!\n");
1522
 
                return -1;
1523
 
        }
1524
 
  
1525
 
        cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
1526
 
        bc->l3_id=frm->dinfo;
1527
 
        return 0;
1528
 
}
1529
1513
 
1530
1514
int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
1531
1515
{
1534
1518
        switch (frm->prim) {
1535
1519
        case CC_NEW_CR|INDICATION:
1536
1520
                cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
1537
 
                if (handle_new_process(stack, frm) <0) {
 
1521
 
 
1522
                struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
 
1523
                if (!bc) {
 
1524
                        cb_log(0, stack->port, " --> !! lib: No free channel!\n");
1538
1525
                        return -1;
1539
1526
                }
 
1527
  
 
1528
                cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
 
1529
                bc->l3_id=frm->dinfo;
1540
1530
                return 1;
1541
1531
        case CC_NEW_CR|CONFIRM:
1542
1532
                return 1;
1681
1671
             stack;
1682
1672
             stack=stack->next) {
1683
1673
                
1684
 
                if ( !stack->ptp && !check) return 1;
1685
 
                
1686
1674
                if (stack->port == port) {
1687
1675
 
1688
1676
                        if (stack->blocked) {
1700
1688
                                        return 0;
1701
1689
                                }
1702
1690
                        } else {
1703
 
                                if ( stack->l1link)
 
1691
                                if ( !check || stack->l1link )
1704
1692
                                        return 1;
1705
1693
                                else {
1706
1694
                                        cb_log(0,port, "Port down PMP\n");
1787
1775
      
1788
1776
                case CC_SETUP|INDICATION:
1789
1777
                {
1790
 
                        iframe_t frm; /* fake te frm to add callref to global callreflist */
1791
 
                        frm.dinfo = hh->dinfo;
1792
 
                        frm.addr=stack->upper_id;
1793
 
                        frm.prim = CC_NEW_CR|INDICATION;
1794
 
                        
1795
 
                        if (handle_cr(stack, &frm)< 0) {
 
1778
                        struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
 
1779
                        if (!bc) 
 
1780
                        ERR_NO_CHANNEL:
 
1781
                        {
1796
1782
                                msg_t *dmsg;
1797
1783
                                cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %x (No free Chan for you..)\n", hh->dinfo);
1798
1784
                                dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
1800
1786
                                free_msg(msg);
1801
1787
                                return 0;
1802
1788
                        }
 
1789
  
 
1790
                        cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo);
 
1791
                        bc->l3_id=hh->dinfo;
 
1792
 
 
1793
                        if (bc->channel<=0) {
 
1794
                                bc->channel=find_free_chan_in_stack(stack,0);
 
1795
 
 
1796
                                if (bc->channel<=0)
 
1797
                                        goto ERR_NO_CHANNEL;
 
1798
                        }
1803
1799
                }
1804
1800
                break;
1805
1801
 
2032
2028
                                                if (stack->ptp) 
2033
2029
                                                        set_chan_in_stack(stack, bc->channel);
2034
2030
                                                else 
2035
 
                                                        cb_log(0,stack->port," --> PTMP but channel requested\n");
 
2031
                                                        cb_log(3,stack->port," --> PTMP but channel requested\n");
2036
2032
 
2037
2033
                                        } else {
2038
2034
 
3175
3171
        }
3176
3172
        
3177
3173
        cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s pid:%d\n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad, bc->pid);
3178
 
        cb_log(1, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state));
 
3174
        cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state));
3179
3175
        misdn_lib_log_ies(bc);
3180
3176
        
3181
3177
        switch (event) {
4184
4180
 
4185
4181
        struct misdn_stack *stack=get_stack_by_bc(bc);
4186
4182
        
4187
 
        cb_log(1, stack?stack->port:0,"ec_enable\n");
 
4183
        cb_log(4, stack?stack->port:0,"ec_enable\n");
4188
4184
 
4189
4185
        if (!misdn_cap_is_speech(bc->capability)) {
4190
4186
                cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n");
4192
4188
        }
4193
4189
 
4194
4190
        if (bc->ec_enable) {
4195
 
                cb_log(1, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d training:%d\n",bc->ec_deftaps, bc->ec_training);
 
4191
                cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d training:%d\n",bc->ec_deftaps, bc->ec_training);
4196
4192
        
4197
4193
                switch (bc->ec_deftaps) {
4198
4194
                case 4:
4224
4220
{
4225
4221
        struct misdn_stack *stack=get_stack_by_bc(bc);
4226
4222
        
4227
 
        cb_log(1, stack?stack->port:0,"ec_disable\n");
 
4223
        cb_log(4, stack?stack->port:0," --> ec_disable\n");
4228
4224
 
4229
4225
        if (!misdn_cap_is_speech(bc->capability)) {
4230
4226
                cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n");
4232
4228
        }
4233
4229
 
4234
4230
        if ( ! bc->ec_enable) {
4235
 
                cb_log(1, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
 
4231
                cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n");
4236
4232
                manager_ph_control(bc,  ECHOCAN_OFF, 0);
4237
4233
        }
4238
4234
}
4249
4245
        manager_ph_control(bc, CMX_RECEIVE_OFF, 0);
4250
4246
        manager_ph_control(bc, CMX_CONF_JOIN, conf_id);
4251
4247
 
4252
 
        cb_log(1,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
 
4248
        cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id);
4253
4249
 
4254
4250
        char data[16];
4255
4251
        int len=15;
4267
4263
        manager_ph_control(bc, CMX_RECEIVE_ON, 0);
4268
4264
        manager_ph_control(bc, CMX_CONF_SPLIT, conf_id);
4269
4265
 
4270
 
        cb_log(1,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
 
4266
        cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id);
4271
4267
}
4272
4268
 
4273
4269
void misdn_lib_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2) {
4274
4270
        int conf_id=bc1->pid +1;
4275
4271
 
4276
 
        cb_log(1, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
 
4272
        cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port);
4277
4273
        
4278
4274
        struct misdn_bchannel *bc_list[]={
4279
4275
                bc1,bc2,NULL
4282
4278
                
4283
4279
        for (bc=bc_list; *bc;  *bc++) { 
4284
4280
                (*bc)->conf_id=conf_id;
4285
 
                cb_log(1, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
 
4281
                cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr);
4286
4282
        
4287
4283
                switch((*bc)->bc_state) {
4288
4284
                        case BCHAN_ACTIVATED:
4317
4313
 
4318
4314
void misdn_lib_echo(struct misdn_bchannel *bc, int onoff)
4319
4315
{
4320
 
        cb_log(1,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
 
4316
        cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF");
4321
4317
        manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0);
4322
4318
}
4323
4319