@ -1227,11 +1227,9 @@ static void *pri_dchannel(void *vpri)
* so other threads can send D channel messages .
* so other threads can send D channel messages .
*/
*/
ast_mutex_unlock ( & pri - > lock ) ;
ast_mutex_unlock ( & pri - > lock ) ;
c = sig_pri_new_ast_channel ( pri - > pvts [ chanpos ] , AST_STATE_RESERVED , 0 , ( e - > ring . layer1 = PRI_LAYER_1_ALAW ) ? SIG_PRI_ALAW : SIG_PRI_ULAW , e - > ring . ctype , pri - > pvts [ chanpos ] - > exten , NULL ) ;
c = sig_pri_new_ast_channel ( pri - > pvts [ chanpos ] , AST_STATE_RESERVED , 0 , ( e - > ring . layer1 = PRI_LAYER_1_ALAW ) ? SIG_PRI_ALAW : SIG_PRI_ULAW , e - > ring . ctype , pri - > pvts [ chanpos ] - > exten , NULL ) ;
ast_mutex_lock ( & pri - > lock ) ;
sig_pri_unlock_private ( pri - > pvts [ chanpos ] ) ;
if ( c ) {
if ( ! ast_strlen_zero ( e - > ring . callingsubaddr ) ) {
if ( ! ast_strlen_zero ( e - > ring . callingsubaddr ) ) {
pbx_builtin_setvar_helper ( c , " CALLINGSUBADDR " , e - > ring . callingsubaddr ) ;
pbx_builtin_setvar_helper ( c , " CALLINGSUBADDR " , e - > ring . callingsubaddr ) ;
}
}
@ -1253,10 +1251,7 @@ static void *pri_dchannel(void *vpri)
# if defined(HAVE_PRI_REVERSE_CHARGE)
# if defined(HAVE_PRI_REVERSE_CHARGE)
pri - > pvts [ chanpos ] - > reverse_charging_indication = e - > ring . reversecharge ;
pri - > pvts [ chanpos ] - > reverse_charging_indication = e - > ring . reversecharge ;
# endif
# endif
}
sig_pri_lock_private ( pri - > pvts [ chanpos ] ) ;
ast_mutex_lock ( & pri - > lock ) ;
pthread_attr_init ( & attr ) ;
pthread_attr_init ( & attr ) ;
pthread_attr_setdetachstate ( & attr , PTHREAD_CREATE_DETACHED ) ;
pthread_attr_setdetachstate ( & attr , PTHREAD_CREATE_DETACHED ) ;
if ( c & & ! ast_pthread_create ( & threadid , & attr , pri_ss_thread , pri - > pvts [ chanpos ] ) ) {
if ( c & & ! ast_pthread_create ( & threadid , & attr , pri_ss_thread , pri - > pvts [ chanpos ] ) ) {
@ -1280,11 +1275,20 @@ static void *pri_dchannel(void *vpri)
* so other threads can send D channel messages .
* so other threads can send D channel messages .
*/
*/
ast_mutex_unlock ( & pri - > lock ) ;
ast_mutex_unlock ( & pri - > lock ) ;
c = sig_pri_new_ast_channel ( pri - > pvts [ chanpos ] , AST_STATE_RING , 1 , ( e - > ring . layer1 = = PRI_LAYER_1_ALAW ) ? SIG_PRI_ALAW : SIG_PRI_ULAW , e - > ring . ctype , pri - > pvts [ chanpos ] - > exten , NULL ) ;
c = sig_pri_new_ast_channel ( pri - > pvts [ chanpos ] , AST_STATE_RING , 0 , ( e - > ring . layer1 = = PRI_LAYER_1_ALAW ) ? SIG_PRI_ALAW : SIG_PRI_ULAW , e - > ring . ctype , pri - > pvts [ chanpos ] - > exten , NULL ) ;
ast_mutex_lock ( & pri - > lock ) ;
if ( c ) {
if ( c ) {
sig_pri_unlock_private ( pri - > pvts [ chanpos ] ) ;
/*
* It is reasonably safe to set the following
* channel variables while the PRI and DAHDI private
* structures are locked . The PBX has not been
* started yet and it is unlikely that any other task
* will do anything with the channel we have just
* created .
*/
if ( ! ast_strlen_zero ( e - > ring . callingsubaddr ) ) {
pbx_builtin_setvar_helper ( c , " CALLINGSUBADDR " , e - > ring . callingsubaddr ) ;
}
if ( e - > ring . ani2 > = 0 ) {
if ( e - > ring . ani2 > = 0 ) {
snprintf ( ani2str , sizeof ( ani2str ) , " %d " , e - > ring . ani2 ) ;
snprintf ( ani2str , sizeof ( ani2str ) , " %d " , e - > ring . ani2 ) ;
pbx_builtin_setvar_helper ( c , " ANI2 " , ani2str ) ;
pbx_builtin_setvar_helper ( c , " ANI2 " , ani2str ) ;
@ -1304,24 +1308,23 @@ static void *pri_dchannel(void *vpri)
snprintf ( calledtonstr , sizeof ( calledtonstr ) , " %d " , e - > ring . calledplan ) ;
snprintf ( calledtonstr , sizeof ( calledtonstr ) , " %d " , e - > ring . calledplan ) ;
pbx_builtin_setvar_helper ( c , " CALLEDTON " , calledtonstr ) ;
pbx_builtin_setvar_helper ( c , " CALLEDTON " , calledtonstr ) ;
}
sig_pri_lock_private ( pri - > pvts [ chanpos ] ) ;
if ( c & & ! ast_pbx_start ( c ) ) {
ast_mutex_lock ( & pri - > lock ) ;
ast_verb ( 3 , " Accepting call from '%s' to '%s' on channel %d/%d, span %d \n " ,
ast_verb ( 3 , " Accepting call from '%s' to '%s' on channel %d/%d, span %d \n " ,
plancallingnum , pri - > pvts [ chanpos ] - > exten ,
plancallingnum , pri - > pvts [ chanpos ] - > exten ,
pri - > pvts [ chanpos ] - > logicalspan , pri - > pvts [ chanpos ] - > prioffset , pri - > span ) ;
pri - > pvts [ chanpos ] - > logicalspan , pri - > pvts [ chanpos ] - > prioffset , pri - > span ) ;
sig_pri_set_echocanceller ( pri - > pvts [ chanpos ] , 1 ) ;
sig_pri_set_echocanceller ( pri - > pvts [ chanpos ] , 1 ) ;
} else {
} else {
ast_mutex_lock ( & pri - > lock ) ;
ast_log ( LOG_WARNING , " Unable to start PBX on channel %d/%d, span %d \n " ,
ast_log ( LOG_WARNING , " Unable to start PBX on channel %d/%d, span %d \n " ,
pri - > pvts [ chanpos ] - > logicalspan , pri - > pvts [ chanpos ] - > prioffset , pri - > span ) ;
pri - > pvts [ chanpos ] - > logicalspan , pri - > pvts [ chanpos ] - > prioffset , pri - > span ) ;
if ( c ) {
ast_hangup ( c ) ;
} else {
pri_hangup ( pri - > pri , e - > ring . call , PRI_CAUSE_SWITCH_CONGESTION ) ;
pri_hangup ( pri - > pri , e - > ring . call , PRI_CAUSE_SWITCH_CONGESTION ) ;
pri - > pvts [ chanpos ] - > call = NULL ;
pri - > pvts [ chanpos ] - > call = NULL ;
}
}
}
}
}
} else {
} else {
ast_verb ( 3 , " Extension '%s' in context '%s' from '%s' does not exist. Rejecting call on channel %d/%d, span %d \n " ,
ast_verb ( 3 , " Extension '%s' in context '%s' from '%s' does not exist. Rejecting call on channel %d/%d, span %d \n " ,
pri - > pvts [ chanpos ] - > exten , pri - > pvts [ chanpos ] - > context , pri - > pvts [ chanpos ] - > cid_num , pri - > pvts [ chanpos ] - > logicalspan ,
pri - > pvts [ chanpos ] - > exten , pri - > pvts [ chanpos ] - > context , pri - > pvts [ chanpos ] - > cid_num , pri - > pvts [ chanpos ] - > logicalspan ,