~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): Jean-Michel Dault
  • Date: 2010-02-16 14:08:54 UTC
  • mfrom: (1.2.5 upstream) (8.3.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100216140854-rb2godspb9lduazl
Tags: 1:1.6.2.2-1ubuntu1
* Merge from Debian: security update
  * Changes:
  - debian/control: Change Maintainer
  - debian/control: Removed Uploaders field.
  - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
  - debian/asterisk.init : chown /dev/dahdi
  - debian/backports/hardy : add file
  - debian/backports/asterisk.init.hardy : add file

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
        
525
525
        channel--;
526
526
 
 
527
        pthread_mutex_lock(&stack->st_lock);
527
528
        if (dec) {
528
529
                for (i = bnums; i >=0; i--) {
529
530
                        if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */
547
548
        }
548
549
 
549
550
        if (!chan) {
 
551
                pthread_mutex_unlock(&stack->st_lock);
550
552
                cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
551
553
                dump_chan_list(stack);
552
554
                bc->out_cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
554
556
        }       
555
557
 
556
558
        if (set_chan_in_stack(stack, chan)<0) {
 
559
                pthread_mutex_unlock(&stack->st_lock);
557
560
                cb_log (0, stack->port, "Channel Already in use:%d\n", chan);
558
561
                bc->out_cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
559
562
                return -1;
560
563
        }
 
564
        pthread_mutex_unlock(&stack->st_lock);
561
565
 
562
566
        bc->channel=chan;
563
567
        return 0;
803
807
        for (i=0; i<=stack->b_num; i++) {
804
808
                if (global_state == MISDN_INITIALIZED)  {
805
809
                        cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); 
806
 
                        empty_chan_in_stack(stack,i+1);
807
810
                        empty_bc(&stack->bc[i]);
808
811
                        clean_up_bc(&stack->bc[i]);
 
812
                        empty_chan_in_stack(stack, i + 1);
809
813
                        stack->bc[i].in_use = 0;
810
814
                }
811
815
                
1268
1272
  
1269
1273
        msg_queue_init(&stack->downqueue);
1270
1274
        msg_queue_init(&stack->upqueue);
 
1275
 
 
1276
        pthread_mutex_init(&stack->st_lock, NULL);
1271
1277
  
1272
1278
        /* query port's requirements */
1273
1279
        ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff));
1442
1448
 
1443
1449
        if (stack->upper_id) 
1444
1450
                mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
 
1451
 
 
1452
        pthread_mutex_destroy(&stack->st_lock);
1445
1453
}
1446
1454
 
1447
1455
 
1487
1495
static struct misdn_bchannel *find_bc_by_masked_l3id(struct misdn_stack *stack, unsigned long l3id, unsigned long mask)
1488
1496
{
1489
1497
        int i;
1490
 
        for (i=0; i<=stack->b_num; i++) {
1491
 
                if ( (stack->bc[i].l3_id & mask)  ==  (l3id & mask)) return &stack->bc[i] ;
 
1498
 
 
1499
        for (i = 0; i <= stack->b_num; i++) {
 
1500
                if (stack->bc[i].in_use && (stack->bc[i].l3_id & mask) == (l3id & mask)) {
 
1501
                        return &stack->bc[i];
 
1502
                }
1492
1503
        }
1493
1504
        return stack_holder_find(stack,l3id);
1494
1505
}
1497
1508
struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id)
1498
1509
{
1499
1510
        int i;
1500
 
        for (i=0; i<=stack->b_num; i++) {
1501
 
                if (stack->bc[i].l3_id == l3id) return &stack->bc[i] ;
 
1511
 
 
1512
        for (i = 0; i <= stack->b_num; i++) {
 
1513
                if (stack->bc[i].in_use && stack->bc[i].l3_id == l3id) {
 
1514
                        return &stack->bc[i];
 
1515
                }
1502
1516
        }
1503
1517
        return stack_holder_find(stack,l3id);
1504
1518
}
1508
1522
        struct misdn_stack *stack;
1509
1523
        int i;
1510
1524
 
1511
 
        for (stack=glob_mgr->stack_list;
1512
 
             stack;
1513
 
             stack=stack->next) {
1514
 
                for (i=0; i<=stack->b_num; i++) {
1515
 
                        if ( (stack->bc[i].addr&STACK_ID_MASK)==(addr&STACK_ID_MASK) ||  stack->bc[i].layer_id== addr ) {
 
1525
        for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
 
1526
                for (i = 0; i <= stack->b_num; i++) {
 
1527
                        if (stack->bc[i].in_use
 
1528
                                && ((stack->bc[i].addr & STACK_ID_MASK) == (addr & STACK_ID_MASK)
 
1529
                                        || stack->bc[i].layer_id == addr)) {
1516
1530
                                return &stack->bc[i];
1517
1531
                        }
1518
1532
                }
1526
1540
        struct misdn_stack *stack;
1527
1541
        int i;
1528
1542
        
1529
 
        for (stack=glob_mgr->stack_list;
1530
 
             stack;
1531
 
             stack=stack->next) {
1532
 
                for (i=0; i<=stack->b_num; i++) {
1533
 
                        if ( stack->bc[i].conf_id==confid ) {
 
1543
        for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
 
1544
                for (i = 0; i <= stack->b_num; i++) {
 
1545
                        if (stack->bc[i].in_use && stack->bc[i].conf_id == confid) {
1534
1546
                                return &stack->bc[i];
1535
1547
                        }
1536
1548
                }
1544
1556
        struct misdn_stack *stack = find_stack_by_port(port);
1545
1557
        int i;
1546
1558
 
1547
 
        if (!stack) return NULL;        
 
1559
        if (!stack) {
 
1560
                return NULL;
 
1561
        }
1548
1562
        
1549
 
        for (i=0; i<=stack->b_num; i++) {
1550
 
                if ( stack->bc[i].channel== channel ) {
 
1563
        for (i = 0; i <= stack->b_num; i++) {
 
1564
                if (stack->bc[i].in_use && stack->bc[i].channel == channel) {
1551
1565
                        return &stack->bc[i];
1552
1566
                }
1553
1567
        }
1614
1628
                                if (!bc->channel)
1615
1629
                                        cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
1616
1630
                                else 
1617
 
                                        cb_log(0, stack->port, "Requested Channel Already in Use releasing this call with cause 34!!!!\n");
 
1631
                                        cb_log(0, stack->port,
 
1632
                                                "Requested Channel Already in Use releasing this call with cause %d!!!!\n",
 
1633
                                                bc->out_cause);
1618
1634
 
1619
1635
                                /* when the channel is already in use, we can't
1620
1636
                                 * simply clear it, we need to make sure that 
1725
1741
/* Empties bc if it's reserved (no SETUP out yet) */
1726
1742
void misdn_lib_release(struct misdn_bchannel *bc)
1727
1743
{
 
1744
        int channel;
1728
1745
        struct misdn_stack *stack=get_stack_by_bc(bc);
1729
1746
 
1730
1747
        if (!stack) {
1732
1749
                return;
1733
1750
        }
1734
1751
        
1735
 
        if (bc->channel>0) 
1736
 
                empty_chan_in_stack(stack,bc->channel);
1737
 
        
 
1752
        channel = bc->channel;
1738
1753
        empty_bc(bc);
1739
1754
        clean_up_bc(bc);
 
1755
        if (channel > 0) {
 
1756
                empty_chan_in_stack(stack, channel);
 
1757
        }
1740
1758
        bc->in_use=0;
1741
1759
}
1742
1760
 
2782
2800
                                bc->cause=tmpcause;
2783
2801
                                bc->out_cause=tmp_out_cause;
2784
2802
                                clean_up_bc(bc);
 
2803
                                bc->in_use = 0;
2785
2804
                                
2786
2805
                                if (tmpcause == AST_CAUSE_REQUESTED_CHAN_UNAVAIL) {
2787
 
                                        cb_log(0,stack->port,"**** Received CAUSE:%d, so not cleaning up channel %d\n", AST_CAUSE_REQUESTED_CHAN_UNAVAIL, channel);
2788
 
                                        cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n");
2789
 
                                        set_chan_in_stack(stack, channel);
2790
 
                                        bc->channel=channel;
 
2806
                                        cb_log(0, stack->port, "**** Received CAUSE:%d, restarting channel %d\n", AST_CAUSE_REQUESTED_CHAN_UNAVAIL, channel);
2791
2807
                                        misdn_lib_send_restart(stack->port, channel);
2792
 
                                } else {
2793
 
                                        if (channel>0)
2794
 
                                                empty_chan_in_stack(stack, channel);
2795
 
                                }
2796
 
                                bc->in_use=0;
 
2808
                                }
 
2809
                                if (channel > 0) {
 
2810
                                        empty_chan_in_stack(stack, channel);
 
2811
                                }
2797
2812
                        }
2798
2813
 
2799
2814
                        if (event == EVENT_RESTART) {
2800
 
                                cb_log(0, stack->port, "**** Received RESTART_ACK channel:%d\n", bc->restart_channel);
 
2815
                                cb_log(0, stack->port, "**** Received RESTART channel:%d\n", bc->restart_channel);
2801
2816
                                empty_chan_in_stack(stack, bc->restart_channel);
2802
2817
                        }
2803
2818
 
3179
3194
        struct misdn_stack *stack;
3180
3195
        int i;
3181
3196
  
3182
 
        for (stack=glob_mgr->stack_list;
3183
 
             stack;
3184
 
             stack=stack->next) {
3185
 
                for (i=0; i<=stack->b_num; i++)
3186
 
                        if (stack->bc[i].pid == pid) return &stack->bc[i];
 
3197
        for (stack = glob_mgr->stack_list; stack; stack = stack->next) {
 
3198
                for (i = 0; i <= stack->b_num; i++) {
 
3199
                        if (stack->bc[i].in_use && stack->bc[i].pid == pid) {
 
3200
                                return &stack->bc[i];
 
3201
                        }
 
3202
                }
3187
3203
        }
3188
3204
  
3189
3205
        return NULL;
3213
3229
{
3214
3230
        bc->channel = channel;
3215
3231
        bc->channel_preselected = channel?1:0;
3216
 
        bc->in_use = 1;
3217
3232
        bc->need_disconnect=1;
3218
3233
        bc->need_release=1;
3219
3234
        bc->need_release_complete=1;
3227
3242
        bc->b_stid=0;
3228
3243
        bc->layer_id=0;
3229
3244
#endif
 
3245
 
 
3246
        bc->in_use = 1;
3230
3247
}
3231
3248
 
3232
3249
struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
3239
3256
                return NULL;
3240
3257
        }
3241
3258
 
3242
 
        usleep(1000);
3243
 
 
3244
3259
        for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
3245
3260
    
3246
3261
                if (stack->port == port) {
3251
3266
                                return NULL;
3252
3267
                        }
3253
3268
                
 
3269
                        pthread_mutex_lock(&stack->st_lock);
3254
3270
                        if (channel > 0) {
3255
3271
                                if (channel <= stack->b_num) {
3256
3272
                                        for (i = 0; i < stack->b_num; i++) {
3257
3273
                                                if ( stack->bc[i].channel == channel) {
3258
3274
                                                        if (test_inuse(&stack->bc[i])) { 
 
3275
                                                                pthread_mutex_unlock(&stack->st_lock);
3259
3276
                                                                cb_log(0,port,"Requested channel:%d on port:%d is already in use\n",channel, port);
3260
3277
                                                                return NULL;
3261
3278
 
3262
3279
                                                        } else {
3263
3280
                                                                prepare_bc(&stack->bc[i], channel);
 
3281
                                                                pthread_mutex_unlock(&stack->st_lock);
3264
3282
                                                                return &stack->bc[i];
3265
3283
                                                        }
3266
3284
                                                }
3267
3285
                                        }
3268
3286
                                } else {
 
3287
                                        pthread_mutex_unlock(&stack->st_lock);
3269
3288
                                        cb_log(0,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port);
3270
3289
                                        return NULL;
3271
3290
                                }
3282
3301
                                                        
3283
3302
                                                prepare_bc(&stack->bc[i], channel);
3284
3303
                                                stack->bc[i].dec=1;
 
3304
                                                pthread_mutex_unlock(&stack->st_lock);
3285
3305
                                                return &stack->bc[i];
3286
3306
                                        }
3287
3307
                                }
3293
3313
                                                        stack->bc[i].cw=1;
3294
3314
 
3295
3315
                                                prepare_bc(&stack->bc[i], channel);
 
3316
                                                pthread_mutex_unlock(&stack->st_lock);
3296
3317
                                                return &stack->bc[i];
3297
3318
                                        }
3298
3319
                                }
3299
3320
                        }
 
3321
                        pthread_mutex_unlock(&stack->st_lock);
3300
3322
 
3301
3323
                        cb_log(1,port,"There is no free channel on port (%d)\n",port);
3302
3324
                        return NULL;
3875
3897
                /* clean up chan in stack, to be sure we don't think it's
3876
3898
                 * in use anymore */
3877
3899
                for (cnt=0; cnt<=stack->b_num; cnt++) {
3878
 
                        if (stack->bc[cnt].channel == channel) {
 
3900
                        if (stack->bc[cnt].in_use && stack->bc[cnt].channel == channel) {
3879
3901
                                empty_bc(&stack->bc[cnt]);
3880
3902
                                clean_up_bc(&stack->bc[cnt]);
3881
3903
                                stack->bc[cnt].in_use=0;