~ubuntu-branches/ubuntu/feisty/asterisk/feisty-security

« back to all changes in this revision

Viewing changes to channels/chan_misdn.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Porcheron
  • Date: 2007-01-28 01:08:48 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070128010848-fd6k14jk4nw0drs5
Tags: 1:1.2.14~dfsg-4ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/asterisk.init:
    + create /var/run/ directory if necessary and set proper permissions
  - debian/asterisk.default - fix -D/-d typo in PARAMS (Closes LP#68169)
  - debian/patches/ubuntu_safe_asterisk - remove bashism (Closes LP#68742)
* debian/asterisk.init - fixed stopping stop while RUNASTSAFE=yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
 
65
65
char global_tracefile[BUFFERSIZE+1];
66
66
 
 
67
static int g_config_initialized=0;
67
68
 
68
69
struct misdn_jb{
69
70
        int size;
190
191
        int dropped_frame_cnt;
191
192
 
192
193
        int far_alerting;
 
194
 
 
195
        int nttimeout;
 
196
 
193
197
        int other_pid;
194
198
        struct chan_list *other_ch;
195
199
 
706
710
static void reload_config(void)
707
711
{
708
712
        int i, cfg_debug;
 
713
 
 
714
        if (!g_config_initialized) {
 
715
                ast_log(LOG_WARNING, "chan_misdn is not initialized properly, still reloading ?\n");
 
716
                return ;
 
717
        }
709
718
        
710
719
        free_robin_list();
711
720
        misdn_cfg_reload();
787
796
                        print_bc_info(fd, help, bc);
788
797
                } else {
789
798
                        if (help->state == MISDN_HOLDED) {
790
 
                                chan_misdn_log(0, 0, "ITS A HOLDED BC:\n");
791
 
                                chan_misdn_log(0,0," --> l3_id: %x\n"
 
799
                                chan_misdn_log(2, 0, "ITS A HOLDED BC:\n");
 
800
                                chan_misdn_log(2,0," --> l3_id: %x\n"
792
801
                                                " --> dad:%s oad:%s\n"
793
802
                                
794
803
                                                ,help->l3id
1211
1220
        
1212
1221
        int port=bc->port;
1213
1222
        
1214
 
        chan_misdn_log(1,port,"update_config: Getting Config\n");
1215
 
 
 
1223
        chan_misdn_log(7,port,"update_config: Getting Config\n");
1216
1224
 
1217
1225
        int hdlc=0;
1218
1226
        misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int));
1410
1418
        misdn_cfg_get( port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int));
1411
1419
 
1412
1420
        misdn_cfg_get( port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(int));
 
1421
        misdn_cfg_get( port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(int));
1413
1422
        
1414
1423
        misdn_cfg_get( port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(int));
1415
1424
 
1625
1634
        
1626
1635
        chan_misdn_log(1, port, "* CALL: %s\n",dest);
1627
1636
        
1628
 
        chan_misdn_log(1, port, " --> * dad:%s tech:%s ctx:%s\n",ast->exten,ast->name, ast->context);
 
1637
        chan_misdn_log(2, port, " --> * dad:%s tech:%s ctx:%s\n",ast->exten,ast->name, ast->context);
1629
1638
        
1630
1639
        chan_misdn_log(3, port, " --> * adding2newbc ext %s\n",ast->exten);
1631
1640
        if (ast->exten) {
1681
1690
                return -1;
1682
1691
        }
1683
1692
        
1684
 
        chan_misdn_log(1, port, " --> * SEND: State Dialing pid:%d\n",newbc?newbc->pid:1);
 
1693
        chan_misdn_log(2, port, " --> * SEND: State Dialing pid:%d\n",newbc?newbc->pid:1);
1685
1694
 
1686
1695
        ast_setstate(ast, AST_STATE_DIALING);
1687
1696
        ast->hangupcause=16;
1845
1854
                return -1;
1846
1855
        }
1847
1856
        
1848
 
        chan_misdn_log(1, p->bc->port, "* IND : Indication [%d] from %s\n",cond, ast->exten);
 
1857
        chan_misdn_log(5, p->bc->port, "* IND : Indication [%d] from %s\n",cond, ast->exten);
1849
1858
        
1850
1859
        switch (cond) {
1851
1860
        case AST_CONTROL_BUSY:
1852
 
                chan_misdn_log(1, p->bc->port, "* IND :\tbusy\n");
1853
 
                chan_misdn_log(1, p->bc->port, " --> * SEND: State Busy pid:%d\n",p->bc?p->bc->pid:-1);
 
1861
                chan_misdn_log(1, p->bc->port, "* IND :\tbusy pid:%d\n",p->bc?p->bc->pid:-1);
1854
1862
                ast_setstate(ast,AST_STATE_BUSY);
1855
1863
 
1856
1864
                p->bc->out_cause=17;
1863
1871
                return -1;
1864
1872
                break;
1865
1873
        case AST_CONTROL_RING:
1866
 
                chan_misdn_log(1, p->bc->port, " --> * IND :\tring pid:%d\n",p->bc?p->bc->pid:-1);
 
1874
                chan_misdn_log(1, p->bc->port, "* IND :\tring pid:%d\n",p->bc?p->bc->pid:-1);
1867
1875
                return -1;
1868
1876
                break;
1869
1877
                
1870
1878
        case AST_CONTROL_RINGING:
 
1879
                chan_misdn_log(1, p->bc->port, "* IND :\tringing pid:%d\n",p->bc?p->bc->pid:-1);
1871
1880
                switch (p->state) {
1872
1881
                        case MISDN_ALERTING:
1873
 
                                chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d but I was Ringing before, so ignoreing it\n",p->bc?p->bc->pid:-1);
 
1882
                                chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d but I was Ringing before, so ignoreing it\n",p->bc?p->bc->pid:-1);
1874
1883
                                break;
1875
1884
                        case MISDN_CONNECTED:
1876
 
                                chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d but Connected, so just send TONE_ALERTING without state changes \n",p->bc?p->bc->pid:-1);
 
1885
                                chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d but Connected, so just send TONE_ALERTING without state changes \n",p->bc?p->bc->pid:-1);
1877
1886
                                return -1;
1878
1887
                                break;
1879
1888
                        default:
1880
1889
                                p->state=MISDN_ALERTING;
1881
 
                                chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d\n",p->bc?p->bc->pid:-1);
 
1890
                                chan_misdn_log(2, p->bc->port, " --> * IND :\tringing pid:%d\n",p->bc?p->bc->pid:-1);
1882
1891
                                misdn_lib_send_event( p->bc, EVENT_ALERTING);
1883
1892
                        
1884
1893
                                if (p->other_ch && p->other_ch->bc) {
1885
1894
                                        if (misdn_inband_avail(p->other_ch->bc)) {
1886
 
                                                chan_misdn_log(1,p->bc->port, " --> other End is mISDN and has inband info available\n");
 
1895
                                                chan_misdn_log(2,p->bc->port, " --> other End is mISDN and has inband info available\n");
1887
1896
                                                break;
1888
1897
                                        }
1889
1898
 
1890
1899
                                        if (!p->other_ch->bc->nt) {
1891
 
                                                chan_misdn_log(1,p->bc->port, " --> other End is mISDN TE so it has inband info for sure (?)\n");
 
1900
                                                chan_misdn_log(2,p->bc->port, " --> other End is mISDN TE so it has inband info for sure (?)\n");
1892
1901
                                                break;
1893
1902
                                        }
1894
1903
                                }
1895
1904
 
1896
 
                                chan_misdn_log(1, p->bc->port, " --> * SEND: State Ring pid:%d\n",p->bc?p->bc->pid:-1);
 
1905
                                chan_misdn_log(3, p->bc->port, " --> * SEND: State Ring pid:%d\n",p->bc?p->bc->pid:-1);
1897
1906
                                ast_setstate(ast,AST_STATE_RINGING);
1898
1907
                        
1899
1908
                                if ( !p->bc->nt && (p->orginator==ORG_MISDN) && !p->incoming_early_audio ) 
1900
 
                                        chan_misdn_log(1,p->bc->port, " --> incoming_early_audio off\n");
 
1909
                                        chan_misdn_log(2,p->bc->port, " --> incoming_early_audio off\n");
1901
1910
                                else 
1902
1911
                                        return -1;
1903
1912
                }
1957
1966
                chan_misdn_log(1, p->bc->port, " --> *\tUNHOLD pid:%d\n",p->bc?p->bc->pid:-1);
1958
1967
                break;
1959
1968
        default:
1960
 
                ast_log(LOG_NOTICE, " --> * Unknown Indication:%d pid:%d\n",cond,p->bc?p->bc->pid:-1);
 
1969
                chan_misdn_log(1, p->bc->port, " --> * Unknown Indication:%d pid:%d\n",cond,p->bc?p->bc->pid:-1);
1961
1970
        }
1962
1971
  
1963
1972
        return 0;
2034
2043
                }
2035
2044
    
2036
2045
                chan_misdn_log(1, bc->port, "* IND : HANGUP\tpid:%d ctx:%s dad:%s oad:%s State:%s\n",p->bc?p->bc->pid:-1, ast->context, ast->exten, AST_CID_P(ast), misdn_get_ch_state(p));
2037
 
                chan_misdn_log(2, bc->port, " --> l3id:%x\n",p->l3id);
2038
 
                chan_misdn_log(1, bc->port, " --> cause:%d\n",bc->cause);
2039
 
                chan_misdn_log(1, bc->port, " --> out_cause:%d\n",bc->out_cause);
2040
 
                chan_misdn_log(1, bc->port, " --> state:%s\n", misdn_get_ch_state(p));
 
2046
                chan_misdn_log(3, bc->port, " --> l3id:%x\n",p->l3id);
 
2047
                chan_misdn_log(3, bc->port, " --> cause:%d\n",bc->cause);
 
2048
                chan_misdn_log(2, bc->port, " --> out_cause:%d\n",bc->out_cause);
 
2049
                chan_misdn_log(2, bc->port, " --> state:%s\n", misdn_get_ch_state(p));
2041
2050
                
2042
2051
                switch (p->state) {
2043
2052
                case MISDN_CALLING:
2122
2131
        }
2123
2132
        
2124
2133
 
2125
 
        chan_misdn_log(1, bc->port, "Channel: %s hanguped new state:%s\n",ast->name,misdn_get_ch_state(p));
 
2134
        chan_misdn_log(3, bc->port, " --> Channel: %s hanguped new state:%s\n",ast->name,misdn_get_ch_state(p));
2126
2135
        
2127
2136
        return 0;
2128
2137
}
2338
2347
                        /* got hangup .. */
2339
2348
 
2340
2349
                        if (!f) 
2341
 
                                chan_misdn_log(1,ch1->bc->port,"Read Null Frame\n");
 
2350
                                chan_misdn_log(4,ch1->bc->port,"Read Null Frame\n");
2342
2351
                        else
2343
 
                                chan_misdn_log(1,ch1->bc->port,"Read Frame Controll class:%d\n",f->subclass);
 
2352
                                chan_misdn_log(4,ch1->bc->port,"Read Frame Controll class:%d\n",f->subclass);
2344
2353
                        
2345
2354
                        *fo=f;
2346
2355
                        *rc=who;
2355
2364
                        *rc=who;
2356
2365
                        break;
2357
2366
                }
2358
 
                
 
2367
        
 
2368
#if 0
2359
2369
                if (f->frametype == AST_FRAME_VOICE) {
2360
 
                        chan_misdn_log(1,0,"Got Voice frame in Bridged state..\n");
 
2370
                        chan_misdn_log(1, ch1->bc->port, "I SEND: Splitting conference with Number:%d\n", ch1->bc->pid +1);
 
2371
        
2361
2372
                        continue;
2362
2373
                }
 
2374
#endif
2363
2375
 
2364
2376
                if (who == c0) {
2365
2377
                        ast_write(c1,f);
2942
2954
                return;
2943
2955
        }
2944
2956
 
2945
 
        cb_log(1,port,"hangup_chan\n");
 
2957
        cb_log(5,port,"hangup_chan called\n");
2946
2958
 
2947
2959
        if (ch->need_hangup) 
2948
2960
        {
2949
 
                cb_log(1,port,"-> hangup\n");
 
2961
                cb_log(2,port," --> hangup\n");
2950
2962
                send_cause2ast(ch->ast,ch->bc,ch);
2951
2963
                ch->need_hangup=0;
2952
2964
                ch->need_queue_hangup=0;
2956
2968
        }
2957
2969
 
2958
2970
        if (!ch->need_queue_hangup) {
2959
 
                cb_log(1,port,"No need to queue hangup\n");
 
2971
                cb_log(2,port," --> No need to queue hangup\n");
2960
2972
        }
2961
2973
 
2962
2974
        ch->need_queue_hangup=0;
2965
2977
 
2966
2978
                if (ch->ast)
2967
2979
                        ast_queue_hangup(ch->ast);
2968
 
                cb_log(1,port,"-> queue_hangup\n");
 
2980
                cb_log(2,port," --> queue_hangup\n");
2969
2981
        } else {
2970
2982
                cb_log(1,port,"Cannot hangup chan, no ast\n");
2971
2983
        }
2985
2997
                        ast=ch->ast;
2986
2998
                } 
2987
2999
                
2988
 
                chan_misdn_log(1, bc->port, "release_chan: bc with l3id: %x\n",bc->l3_id);
 
3000
                chan_misdn_log(5, bc->port, "release_chan: bc with l3id: %x\n",bc->l3_id);
2989
3001
                
2990
3002
                /*releaseing jitterbuffer*/
2991
3003
                if (ch->jb ) {
3164
3176
        tmp=pbx_builtin_getvar_helper(chan,"MISDN_PID");
3165
3177
        if (tmp) {
3166
3178
                ch->other_pid=atoi(tmp);
3167
 
                chan_misdn_log(1,bc->port,"IMPORT_PID: importing pid:%s\n",tmp);
 
3179
                chan_misdn_log(3,bc->port," --> IMPORT_PID: importing pid:%s\n",tmp);
3168
3180
 
3169
3181
                if (ch->other_pid >0) {
3170
3182
                        ch->other_ch=find_chan_by_pid(cl_te,ch->other_pid);
3171
3183
                        if (ch->other_ch) ch->other_ch->other_ch=ch;
3172
3184
                }
3173
3185
        }
 
3186
 
 
3187
        tmp=pbx_builtin_getvar_helper(chan,"MISDN_ADDRESS_COMPLETE");
 
3188
        if (tmp && (atoi(tmp) == 1)) {
 
3189
                bc->sending_complete=1;
 
3190
        }
3174
3191
}
3175
3192
 
3176
3193
void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch)
3177
3194
{
3178
3195
        char tmp[32];
3179
3196
 
3180
 
        chan_misdn_log(1,bc->port,"EXPORT_PID: pid:%d\n",bc->pid);
 
3197
        chan_misdn_log(3,bc->port," --> EXPORT_PID: pid:%d\n",bc->pid);
3181
3198
        sprintf(tmp,"%d",bc->pid);
3182
3199
        pbx_builtin_setvar_helper(chan,"_MISDN_PID",tmp);
 
3200
 
 
3201
        if (bc->sending_complete) {
 
3202
                sprintf(tmp,"%d",bc->sending_complete);
 
3203
                pbx_builtin_setvar_helper(chan,"MISDN_ADDRESS_COMPLETE",tmp);
 
3204
        }
3183
3205
}
3184
3206
 
3185
3207
 
3717
3739
                ast_queue_control(ch->ast, AST_CONTROL_RINGING);
3718
3740
                ast_setstate(ch->ast, AST_STATE_RINGING);
3719
3741
                
3720
 
                cb_log(1,bc->port,"Set State Ringing\n");
 
3742
                cb_log(7,bc->port," --> Set State Ringing\n");
3721
3743
                
3722
3744
                if ( misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) {
3723
3745
                        cb_log(1,bc->port,"Starting Tones, we have inband Data\n");
3724
3746
                        start_bc_tones(ch);
3725
3747
                } else {
3726
 
                        cb_log(1,bc->port,"We have no inband Data, the other end must create ringing\n");
 
3748
                        cb_log(3,bc->port," --> We have no inband Data, the other end must create ringing\n");
3727
3749
                        if (ch->far_alerting) {
3728
 
                                cb_log(1,bc->port,"The other end can not do ringing eh ?.. we must do all ourself..");
 
3750
                                cb_log(1,bc->port," --> The other end can not do ringing eh ?.. we must do all ourself..");
3729
3751
                                start_bc_tones(ch);
3730
3752
                                /*tone_indicate(ch, TONE_FAR_ALERTING);*/
3731
3753
                        }
3826
3848
                        ch->state=MISDN_CLEANING;
3827
3849
        }
3828
3850
        break;
 
3851
        case EVENT_BCHAN_ERROR:
3829
3852
        case EVENT_CLEANUP:
3830
3853
        {
3831
3854
                stop_bc_tones(ch);
3923
3946
                                int ret=write(ch->pipe[1], bc->bframe, bc->bframe_len);
3924
3947
                                
3925
3948
                                if (ret<=0) {
3926
 
                                        chan_misdn_log(-1, bc->port, "Write returned <=0 (err=%s)\n",strerror(errno));
 
3949
                                        chan_misdn_log(-1, bc->port, "Write returned <=0 (err=%s) --> hanging up channel\n",strerror(errno));
 
3950
 
 
3951
                                        stop_bc_tones(ch);
 
3952
                                        hangup_chan(ch);
 
3953
                                        release_chan(bc);
3927
3954
                                }
3928
3955
                        } else {
3929
3956
                                chan_misdn_log(1, bc->port, "Wripe Pipe full!\n");
3937
3964
                        chan_misdn_log(1,bc->port,"--> state: %s\n",misdn_get_ch_state(ch));
3938
3965
 
3939
3966
                switch (ch->state) {
3940
 
                        case MISDN_CALLING:
3941
3967
                        case MISDN_DIALING:
3942
3968
                        case MISDN_PROGRESS:
 
3969
                                if (bc->nt && !ch->nttimeout) break;
 
3970
                        
 
3971
                        case MISDN_CALLING:
3943
3972
                        case MISDN_ALERTING:
3944
3973
                        case MISDN_PROCEEDING:
3945
3974
                        case MISDN_CALLING_ACKNOWLEDGE:
3993
4022
                ch->bc=bc;
3994
4023
                ch->state = MISDN_CONNECTED;
3995
4024
 
 
4025
                ch->hold_info.port=0;
 
4026
                ch->hold_info.channel=0;
 
4027
                
3996
4028
                struct ast_channel *hold_ast=AST_BRIDGED_P(ch->ast);
3997
4029
                
3998
4030
                if (hold_ast) {
4074
4106
                break;
4075
4107
                                
4076
4108
        default:
4077
 
                ast_log(LOG_NOTICE, "Got Unknown Event\n");
 
4109
                chan_misdn_log(1,0, "Got Unknown Event\n");
4078
4110
                break;
4079
4111
        }
4080
4112
        
4091
4123
 *******************************************/
4092
4124
 
4093
4125
 
4094
 
static int g_config_initialized=0;
4095
4126
 
4096
4127
int load_module(void)
4097
4128
{
4106
4137
                return 0;
4107
4138
        }
4108
4139
        
4109
 
        
4110
 
        misdn_cfg_init(max_ports);
 
4140
        if (misdn_cfg_init(max_ports)<0) {
 
4141
                ast_log(LOG_ERROR, "Unable to initialize mISDN Config System\n");
 
4142
                return 0;
 
4143
        }
 
4144
 
4111
4145
        g_config_initialized=1;
4112
4146
        
4113
4147
        misdn_debug = (int *)malloc(sizeof(int) * (max_ports+1));
4330
4364
                misdn_lib_send_facility(ch->bc, FACILITY_CALLDEFLECT, tok);
4331
4365
                
4332
4366
        } else {
4333
 
                ast_log(LOG_WARNING, "Unknown Facility: %s\n",tok);
 
4367
                chan_misdn_log(1, ch->bc->port, "Unknown Facility: %s\n",tok);
4334
4368
        }
4335
4369
        
4336
4370
        return 0;