[asterisk-commits] branch crichter/0.3.0 r37171 - in
/team/crichter/0.3.0: channels/ channels/mi...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Jul 6 08:05:49 MST 2006
Author: crichter
Date: Thu Jul 6 10:05:49 2006
New Revision: 37171
URL: http://svn.digium.com/view/asterisk?rev=37171&view=rev
Log:
* removed tone_indicate, we genrate only the dialtone by ourself (and the hanguptone of course)
* removed the state handling from release_chan, and simplified the ast_hangup/ast_queue_hangup stuff
* added pp_l2_check option, for pp lines where the pbx does not initially gets the L2 up
* simplified and fixed a bug in the pid generation code
* fixed a bug in empty_chan, which might cause segfaults and memorry corruptions
* added prepare_bc function, which is sort of the opposite of empty_bc
Modified:
team/crichter/0.3.0/channels/chan_misdn.c
team/crichter/0.3.0/channels/misdn/chan_misdn_config.h
team/crichter/0.3.0/channels/misdn/isdn_lib.c
team/crichter/0.3.0/channels/misdn/isdn_lib.h
team/crichter/0.3.0/channels/misdn_config.c
team/crichter/0.3.0/configs/misdn.conf.sample
Modified: team/crichter/0.3.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_misdn.c?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Thu Jul 6 10:05:49 2006
@@ -142,6 +142,9 @@
char allowed_bearers[BUFFERSIZE+1];
enum misdn_chan_state state;
+ int need_queue_hangup;
+ int need_hangup;
+
int holded;
int orginator;
@@ -303,8 +306,9 @@
-
-static int tone_indicate( struct chan_list *cl, enum tone_e tone);
+static int dialtone_indicate(struct chan_list *cl);
+static int hanguptone_indicate(struct chan_list *cl);
+static int stop_indicate(struct chan_list *cl);
static int start_bc_tones(struct chan_list *cl);
static int stop_bc_tones(struct chan_list *cl);
@@ -1677,7 +1681,7 @@
p->state = MISDN_CONNECTED;
misdn_lib_echo(p->bc,0);
- tone_indicate(p, TONE_NONE);
+ stop_indicate(p);
if ( ast_strlen_zero(p->bc->cad) ) {
chan_misdn_log(2,p->bc->port," --> empty cad using dad\n");
@@ -1790,15 +1794,18 @@
p->bc->out_cause=17;
if (p->state != MISDN_CONNECTED) {
+ start_bc_tones(p);
misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
- return -1;
} else {
chan_misdn_log(-1, p->bc->port, " --> !! Got Busy in Connected State !?! ast:%s\n", ast->name);
}
+ return -1;
break;
case AST_CONTROL_RING:
chan_misdn_log(1, p->bc->port, " --> * IND :\tring pid:%d\n",p->bc?p->bc->pid:-1);
+ return -1;
break;
+
case AST_CONTROL_RINGING:
switch (p->state) {
case MISDN_ALERTING:
@@ -1823,13 +1830,6 @@
chan_misdn_log(1,p->bc->port, " --> other End is mISDN TE so it has inband info for sure (?)\n");
break;
}
-#if 0
- if (p->other_ch->bc->nt) {
- chan_misdn_log(1,p->bc->port, " --> other End is mISDN NT .. \n");
- break;
- }
-#endif
-
}
chan_misdn_log(1, p->bc->port, " --> * SEND: State Ring pid:%d\n",p->bc?p->bc->pid:-1);
@@ -1847,9 +1847,11 @@
break;
case AST_CONTROL_TAKEOFFHOOK:
chan_misdn_log(1, p->bc->port, " --> *\ttakeoffhook pid:%d\n",p->bc?p->bc->pid:-1);
+ return -1;
break;
case AST_CONTROL_OFFHOOK:
chan_misdn_log(1, p->bc->port, " --> *\toffhook pid:%d\n",p->bc?p->bc->pid:-1);
+ return -1;
break;
case AST_CONTROL_FLASH:
chan_misdn_log(1, p->bc->port, " --> *\tflash pid:%d\n",p->bc?p->bc->pid:-1);
@@ -1874,13 +1876,13 @@
}
if (p->bc->nt) {
- tone_indicate(p, TONE_BUSY);
+ hanguptone_indicate(p);
}
break;
case -1 :
chan_misdn_log(1, p->bc->port, " --> * IND :\t-1! (stop indication) pid:%d\n",p->bc?p->bc->pid:-1);
- tone_indicate(p, TONE_NONE);
+ stop_indicate(p);
if (p->state == MISDN_CONNECTED)
start_bc_tones(p);
@@ -1975,9 +1977,8 @@
break;
case MISDN_HOLDED:
case MISDN_DIALING:
- case MISDN_CALLING_ACKNOWLEDGE:
start_bc_tones(p);
- tone_indicate(p, TONE_HANGUP);
+ hanguptone_indicate(p);
if (bc->nt) {
misdn_lib_send_event( bc, EVENT_DISCONNECT);
@@ -1986,12 +1987,19 @@
p->state=MISDN_CLEANING;
}
break;
+
+ case MISDN_CALLING_ACKNOWLEDGE:
+ start_bc_tones(p);
+ hanguptone_indicate(p);
+
+ misdn_lib_send_event( bc, EVENT_DISCONNECT);
+ break;
case MISDN_ALERTING:
case MISDN_PROGRESS:
case MISDN_PROCEEDING:
if (p->orginator != ORG_AST)
- tone_indicate(p, TONE_HANGUP);
+ hanguptone_indicate(p);
/*p->state=MISDN_CLEANING;*/
misdn_lib_send_event( bc, EVENT_DISCONNECT);
@@ -2000,7 +2008,7 @@
/* Alerting or Disconect */
if (p->bc->nt) {
start_bc_tones(p);
- tone_indicate(p, TONE_HANGUP);
+ hanguptone_indicate(p);
p->bc->progress_indicator=8;
}
misdn_lib_send_event( bc, EVENT_DISCONNECT);
@@ -2054,9 +2062,18 @@
struct chan_list *tmp;
int len;
- if (!ast) return NULL;
- if (! (tmp=MISDN_ASTERISK_TECH_PVT(ast)) ) return NULL;
- if (!tmp->bc) return NULL;
+ if (!ast) {
+ chan_misdn_log(1,0,"misdn_read called without ast\n");
+ return NULL;
+ }
+ if (! (tmp=MISDN_ASTERISK_TECH_PVT(ast)) ) {
+ chan_misdn_log(1,0,"misdn_read called without ast->pvt\n");
+ return NULL;
+ }
+ if (!tmp->bc) {
+ chan_misdn_log(1,0,"misdn_read called without bc\n");
+ return NULL;
+ }
len=read(tmp->pipe[0],tmp->ast_rd_buf,sizeof(tmp->ast_rd_buf));
@@ -2291,51 +2308,12 @@
/** AST INDICATIONS END **/
-static int tone_indicate( struct chan_list *cl, enum tone_e tone)
+static int dialtone_indicate(struct chan_list *cl)
{
const struct tone_zone_sound *ts= NULL;
struct ast_channel *ast=cl->ast;
-
- chan_misdn_log(3,cl->bc->port,"Tone Indicate:\n");
-
- if (!cl->ast) {
- chan_misdn_log(3,cl->bc->port,"Ast Ptr Not existing anymore.. we need to generate tones ourselves now (tbd)\n");
-
- misdn_lib_send_tone(cl->bc,tone);
- misdn_lib_tone_generator_start(cl->bc);
- return 0;
- }
-
- switch (tone) {
- case TONE_DIAL:
- chan_misdn_log(3,cl->bc->port," --> Dial\n");
- ts=ast_get_indication_tone(ast->zone,"dial");
- break;
- case TONE_ALERTING:
- chan_misdn_log(3,cl->bc->port," --> Ring\n");
- ts=ast_get_indication_tone(ast->zone,"ring");
- break;
- case TONE_FAR_ALERTING:
- /* VERY UGLY HACK, BECAUSE CHAN_SIP DOES NOT GENERATE TONES */
- chan_misdn_log(3,cl->bc->port," --> Ring\n");
- ts=ast_get_indication_tone(ast->zone,"ring");
- misdn_lib_echo(cl->bc,1);
- break;
- case TONE_BUSY:
- chan_misdn_log(3,cl->bc->port," --> Busy\n");
- ts=ast_get_indication_tone(ast->zone,"busy");
- break;
- case TONE_FILE:
- break;
- case TONE_NONE:
- chan_misdn_log(3,cl->bc->port," --> None\n");
- misdn_lib_tone_generator_stop(cl->bc);
- ast_playtones_stop(ast);
- break;
- default:
- chan_misdn_log(0,cl->bc->port,"Don't know how to handle tone: %d\n",tone);
- }
-
+ chan_misdn_log(3,cl->bc->port," --> Dial\n");
+ ts=ast_get_indication_tone(ast->zone,"dial");
cl->ts=ts;
if (ts) {
@@ -2345,13 +2323,31 @@
chan_misdn_log(4,cl->bc->port,"Starting Playtones\n");
misdn_lib_tone_generator_start(cl->bc);
}
-
+
return 0;
}
+static int hanguptone_indicate(struct chan_list *cl)
+{
+ misdn_lib_send_tone(cl->bc,TONE_HANGUP);
+ misdn_lib_tone_generator_start(cl->bc);
+ return 0;
+}
+
+static int stop_indicate(struct chan_list *cl)
+{
+ struct ast_channel *ast=cl->ast;
+ chan_misdn_log(3,cl->bc->port," --> None\n");
+ misdn_lib_tone_generator_stop(cl->bc);
+ ast_playtones_stop(ast);
+ /*ast_deactivate_generator(ast);*/
+
+ return 0;
+}
+
+
static int start_bc_tones(struct chan_list* cl)
{
-/* manager_bchannel_activate(cl->bc); */
misdn_lib_tone_generator_stop(cl->bc);
cl->notxtone=0;
cl->norxtone=0;
@@ -2360,10 +2356,8 @@
static int stop_bc_tones(struct chan_list *cl)
{
-/* if (cl->bc) {
- manager_bchannel_deactivate(cl->bc);
- }
-*/
+ if (!cl) return -1;
+
cl->notxtone=1;
cl->norxtone=1;
@@ -2383,6 +2377,8 @@
memset(cl,0,sizeof(struct chan_list));
cl->orginator=orig;
+ cl->need_queue_hangup=1;
+ cl->need_hangup=1;
return cl;
@@ -2471,8 +2467,11 @@
if (!strcasecmp(cfg_group, group)) {
int port_up;
- int check;
+ int check,checkl2;
misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(int));
+ misdn_cfg_get(port, MISDN_CFG_PP_L2_CHECK, &checkl2, sizeof(int));
+ check=checkl2?2:check;
+
port_up = misdn_lib_port_up(port, check);
if (check && !port_up)
@@ -2507,8 +2506,10 @@
chan_misdn_log(3,port, "Group [%s] Port [%d]\n", group, port);
if (!strcasecmp(cfg_group, group)) {
int port_up;
- int check;
+ int check,checkl2;
misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(int));
+ misdn_cfg_get(port, MISDN_CFG_PP_L2_CHECK, &checkl2, sizeof(int));
+ check=checkl2?2:check;
port_up = misdn_lib_port_up(port, check);
chan_misdn_log(4, port, "portup:%d\n", port_up);
@@ -2544,7 +2545,9 @@
/* fill in the config into the objects */
read_config(cl, ORG_AST);
-
+
+ /* important */
+ cl->need_hangup=0;
return tmp;
}
@@ -2832,11 +2835,52 @@
/** Channel Queue End **/
+int pbx_start_chan(struct chan_list *ch)
+{
+ int ret=ast_pbx_start(ch->ast);
+
+ if (ret>=0)
+ ch->need_hangup=0;
+ else
+ ch->need_hangup=1;
+
+ return ret;
+}
+
+static void hangup_chan(struct chan_list *ch)
+{
+ if (!ch) {
+ cb_log(1,0,"Cannot hangup chan, no ch\n");
+ return;
+ }
+
+
+ if (ch->need_hangup)
+ {
+ send_cause2ast(ch->ast,ch->bc,ch);
+ ch->need_hangup=0;
+ ch->need_queue_hangup=0;
+ if (ch->ast)
+ ast_hangup(ch->ast);
+ return;
+ }
+
+ if (!ch->need_queue_hangup) {
+ cb_log(1,ch->bc->port,"No need to queue hangup\n");
+ }
+
+ ch->need_queue_hangup=0;
+ if (ch->ast) {
+ send_cause2ast(ch->ast,ch->bc,ch);
+ ast_queue_hangup(ch->ast);
+ } else {
+ cb_log(1,ch->bc->port,"Cannot hangup chan, no ast\n");
+ }
+}
/** Isdn asks us to release channel, pendant to misdn_hangup **/
static void release_chan(struct misdn_bchannel *bc) {
struct ast_channel *ast=NULL;
-
{
struct chan_list *ch=find_chan_by_bc(cl_te, bc);
if (!ch) ch=find_chan_by_l3id (cl_te, bc->l3_id);
@@ -2871,9 +2915,6 @@
if (ast && MISDN_ASTERISK_TECH_PVT(ast)) {
chan_misdn_log(1, bc->port, "* RELEASING CHANNEL pid:%d ctx:%s dad:%s oad:%s state: %s\n",bc?bc->pid:-1, ast->context, ast->exten,AST_CID_P(ast),misdn_get_ch_state(ch));
chan_misdn_log(3, bc->port, " --> * State Down\n");
- /* copy cause */
- send_cause2ast(ast,bc,ch);
-
MISDN_ASTERISK_TECH_PVT(ast)=NULL;
@@ -2881,55 +2922,8 @@
chan_misdn_log(3, bc->port, " --> Setting AST State to down\n");
ast_setstate(ast, AST_STATE_DOWN);
}
+ }
- switch(ch->state) {
- case MISDN_EXTCANTMATCH:
- case MISDN_WAITING4DIGS:
- {
- chan_misdn_log(3, bc->port, " --> * State Wait4dig | ExtCantMatch\n");
- ast_hangup(ast);
- }
- break;
-
- case MISDN_DIALING:
- case MISDN_CALLING_ACKNOWLEDGE:
- case MISDN_PROGRESS:
- case MISDN_PROCEEDING:
- chan_misdn_log(2, bc->port, "* --> In State Dialin\n");
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
- ast_queue_hangup(ast);
-
- break;
- case MISDN_CALLING:
-
- chan_misdn_log(2, bc->port, "* --> In State Callin\n");
-
- if (!bc->nt) {
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
- ast_queue_hangup(ast);
- } else {
- chan_misdn_log(2, bc->port, "* --> Hangup\n");
- ast_queue_hangup(ast);
- }
- break;
-
- case MISDN_CLEANING:
- /* this state comes out of ast so we mustnt call a ast function ! */
- chan_misdn_log(2, bc->port, "* --> In StateCleaning\n");
- break;
- case MISDN_HOLD_DISCONNECT:
- chan_misdn_log(2, bc->port, "* --> In HOLD_DISC\n");
- break;
- default:
- chan_misdn_log(2, bc->port, "* --> In State Default\n");
- chan_misdn_log(2, bc->port, "* --> Queue Hangup\n");
- if (ast) {
- ast_queue_hangup(ast);
- } else {
- chan_misdn_log (0, bc->port, "!! Not really queued!\n");
- }
- }
- }
ch->state=MISDN_CLEANING;
cl_dequeue_chan(&cl_te, ch);
@@ -2981,16 +2975,17 @@
if ( !bc->nt && (ch->orginator==ORG_MISDN) && !ch->incoming_early_audio )
chan_misdn_log(1,bc->port, " --> incoming_early_audio off\n");
- else
- tone_indicate(ch,TONE_DIAL);
+ else
+ dialtone_indicate(ch);
chan_misdn_log(1, bc->port, "* Starting Ast ctx:%s dad:%s oad:%s with 's' extension\n", ast->context, ast->exten, AST_CID_P(ast));
strncpy(ast->exten,"s", 2);
- if (ast_pbx_start(ast)<0) {
+ if (pbx_start_chan(ch)<0) {
ast=NULL;
- tone_indicate(ch,TONE_BUSY);
+ hangup_chan(ch);
+ hanguptone_indicate(ch);
if (bc->nt)
misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
@@ -3019,6 +3014,18 @@
static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc, struct chan_list *ch) {
+ if (!ast) {
+ chan_misdn_log(1,0,"send_cause2ast: No Ast\n");
+ return;
+ }
+ if (!bc) {
+ chan_misdn_log(1,0,"send_cause2ast: No BC\n");
+ return;
+ }
+ if (!ch) {
+ chan_misdn_log(1,0,"send_cause2ast: No Ch\n");
+ return;
+ }
ast->hangupcause=bc->cause;
@@ -3095,16 +3102,22 @@
chan_misdn_log(2,bc->port," --> bc_state:%s\n",bc_state2str(bc->bc_state));
}
- if (event != EVENT_SETUP) {
- if (!ch) {
- if (event == EVENT_RELEASE_COMPLETE) {
+ if (!ch) {
+ switch(event) {
+ case EVENT_SETUP:
+ case EVENT_DISCONNECT:
+ break;
+ case EVENT_RELEASE_COMPLETE:
chan_misdn_log(1, bc->port, " --> no Ch, so we've already released.\n");
- return 0;
- }
-
- if (event != EVENT_CLEANUP && event != EVENT_TONE_GENERATE && event != EVENT_BCHAN_DATA)
- ast_log(LOG_NOTICE, "Chan not existing at the moment bc->l3id:%x bc:%p event:%s port:%d channel:%d\n",bc->l3_id, bc, manager_isdn_get_info( event), bc->port,bc->channel);
- return -1;
+ break;
+ case EVENT_CLEANUP:
+ case EVENT_TONE_GENERATE:
+ case EVENT_BCHAN_DATA:
+ return -1;
+
+ default:
+ chan_misdn_log(1,bc->port, "Chan not existing at the moment bc->l3id:%x bc:%p event:%s port:%d channel:%d\n",bc->l3_id, bc, manager_isdn_get_info( event), bc->port,bc->channel);
+ return -1;
}
}
@@ -3186,7 +3199,7 @@
int stop_tone;
misdn_cfg_get( 0, MISDN_GEN_STOP_TONE, &stop_tone, sizeof(int));
if ( stop_tone ) {
- tone_indicate(ch,TONE_NONE);
+ stop_indicate(ch);
}
if (ch->state == MISDN_WAITING4DIGS ) {
@@ -3210,13 +3223,13 @@
int ret;/** Sending SETUP_ACK**/
ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
if (ast_pickup_call(ch->ast)) {
- ast_hangup(ch->ast);
+ hangup_chan(ch);
} else {
struct ast_channel *chan=ch->ast;
ch->state = MISDN_CALLING_ACKNOWLEDGE;
+ ast_setstate(chan, AST_STATE_DOWN);
+ hangup_chan(ch);
ch->ast=NULL;
- ast_setstate(chan, AST_STATE_DOWN);
- ast_hangup(chan);
break;
}
}
@@ -3225,7 +3238,7 @@
chan_misdn_log(-1, bc->port, "Extension can never match, so disconnecting\n");
if (bc->nt)
- tone_indicate(ch,TONE_BUSY);
+ hanguptone_indicate(ch);
ch->state=MISDN_EXTCANTMATCH;
bc->out_cause=1;
@@ -3236,12 +3249,13 @@
if (ast_exists_extension(ch->ast, ch->context, bc->dad, 1, bc->oad)) {
ch->state=MISDN_DIALING;
- tone_indicate(ch,TONE_NONE);
+ stop_indicate(ch);
/* chan_misdn_log(1, bc->port, " --> * Starting Ast ctx:%s\n", ch->context);*/
- if (ast_pbx_start(ch->ast)<0) {
+ if (pbx_start_chan(ch)<0) {
+ hangup_chan(ch);
chan_misdn_log(-1, bc->port, "ast_pbx_start returned < 0 in INFO\n");
- if (bc->nt) tone_indicate(ch,TONE_BUSY);
+ if (bc->nt) hanguptone_indicate(ch);
misdn_lib_send_event(bc, EVENT_DISCONNECT );
}
@@ -3361,12 +3375,12 @@
int ret;/** Sending SETUP_ACK**/
ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
if (ast_pickup_call(chan)) {
- ast_hangup(chan);
+ hangup_chan(ch);
} else {
ch->state = MISDN_CALLING_ACKNOWLEDGE;
+ ast_setstate(chan, AST_STATE_DOWN);
+ hangup_chan(ch);
ch->ast=NULL;
- ast_setstate(chan, AST_STATE_DOWN);
- ast_hangup(chan);
break;
}
}
@@ -3404,7 +3418,7 @@
chan_misdn_log(-1, bc->port, "Extension can never match, so disconnecting\n");
if (bc->nt)
- tone_indicate(ch,TONE_BUSY);
+ hanguptone_indicate(ch);
ch->state=MISDN_EXTCANTMATCH;
bc->out_cause=1;
@@ -3427,13 +3441,14 @@
ret= misdn_lib_send_event(bc, EVENT_PROCEEDING );
}
- if (ast_pbx_start(chan)<0) {
+ if (pbx_start_chan(ch)<0) {
+ hangup_chan(ch);
chan_misdn_log(-1, bc->port, "ast_pbx_start returned <0 in SETUP\n");
chan=NULL;
if (bc->nt) {
- tone_indicate(ch,TONE_BUSY);
+ hanguptone_indicate(ch);
misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
} else
misdn_lib_send_event(bc, EVENT_RELEASE);
@@ -3466,9 +3481,10 @@
int stop_tone;
misdn_cfg_get( 0, MISDN_GEN_STOP_TONE, &stop_tone, sizeof(int));
if ( (!ast_strlen_zero(bc->dad)) && stop_tone )
- tone_indicate(ch,TONE_NONE);
- else
- tone_indicate(ch,TONE_DIAL);
+ stop_indicate(ch);
+ else {
+ dialtone_indicate(ch);
+ }
ch->state=MISDN_WAITING4DIGS;
}
@@ -3548,7 +3564,7 @@
if (ch->far_alerting) {
cb_log(1,bc->port,"The other end can not do ringing eh ?.. we must do all ourself..");
start_bc_tones(ch);
- tone_indicate(ch, TONE_FAR_ALERTING);
+ /*tone_indicate(ch, TONE_FAR_ALERTING);*/
}
}
}
@@ -3560,7 +3576,7 @@
struct ast_channel *bridged=AST_BRIDGED_P(ch->ast);
misdn_lib_echo(bc,0);
- tone_indicate(ch, TONE_NONE);
+ stop_indicate(ch);
if (bridged && !strcasecmp(bridged->tech->type,"mISDN")) {
struct chan_list *bridged_ch=MISDN_ASTERISK_TECH_PVT(bridged);
@@ -3595,9 +3611,9 @@
break;
case EVENT_DISCONNECT:
/*we might not have an ch->ast ptr here anymore*/
- {
+ if (ch) {
struct chan_list *holded_ch=find_holded(cl_te, bc);
-
+
if (ch->ast)
send_cause2ast(ch->ast,bc,ch);
@@ -3625,52 +3641,39 @@
}
stop_bc_tones(ch);
- bc->out_cause=-1;
-
- release_chan(bc);
- misdn_lib_send_event(bc,EVENT_RELEASE);
- }
+ hangup_chan(ch);
+ }
+ bc->out_cause=-1;
+ if (bc->need_release) misdn_lib_send_event(bc,EVENT_RELEASE);
break;
case EVENT_RELEASE:
{
-
- switch ( bc->cause) {
-
- case -1:
- /*
- OK, it really sucks, this is a RELEASE from NT-Stack So we take
- it and return easylie, It seems that we've send a DISCONNECT
- before, so we should RELEASE_COMPLETE after that Disconnect
- (looks like ALERTING State at misdn_hangup !!
- */
-
- /*return RESPONSE_OK;*/
- if (!bc->nt) release_chan(bc);
-
- break;
- }
-
-
bc->out_cause=16;
- /*stop_bc_tones(ch);
- release_chan(bc);*/
-
- if (!bc->nt) release_chan(bc);
-
- misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-
+ hangup_chan(ch);
+ release_chan(bc);
+
+ if (bc->cause >= 0 && bc->need_release_complete)
+ misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
}
break;
case EVENT_RELEASE_COMPLETE:
{
stop_bc_tones(ch);
+ hangup_chan(ch);
release_chan(bc);
- ch->state=MISDN_CLEANING;
+ if(ch)
+ ch->state=MISDN_CLEANING;
}
break;
-
+ case EVENT_CLEANUP:
+ {
+ stop_bc_tones(ch);
+ hangup_chan(ch);
+ release_chan(bc);
+ }
+ break;
case EVENT_TONE_GENERATE:
{
@@ -3747,6 +3750,7 @@
}
if (FD_ISSET(ch->pipe[1],&wrfs)) {
+ chan_misdn_log(9, bc->port, "writing %d bytes 2 asterisk\n",bc->bframe_len);
int ret=write(ch->pipe[1], bc->bframe, bc->bframe_len);
if (ret<=0) {
@@ -3764,7 +3768,6 @@
chan_misdn_log(1,bc->port,"--> state: %s\n",misdn_get_ch_state(ch));
switch (ch->state) {
- case MISDN_WAITING4DIGS:
case MISDN_CALLING:
case MISDN_DIALING:
case MISDN_PROGRESS:
@@ -3773,13 +3776,27 @@
case MISDN_CALLING_ACKNOWLEDGE:
if (bc->nt) {
bc->progress_indicator=8;
- tone_indicate(ch, TONE_BUSY);
+ hanguptone_indicate(ch);
}
bc->out_cause=1;
misdn_lib_send_event(bc,EVENT_DISCONNECT);
break;
+ case MISDN_WAITING4DIGS:
+ if (bc->nt) {
+ bc->progress_indicator=8;
+ bc->out_cause=1;
+ hanguptone_indicate(ch);
+ misdn_lib_send_event(bc,EVENT_DISCONNECT);
+ } else {
+ bc->out_cause=16;
+ misdn_lib_send_event(bc,EVENT_RELEASE);
+ }
+
+ break;
+
+
case MISDN_CLEANING:
chan_misdn_log(1,bc->port," --> in state cleaning .. so ingoring, the stack should clean it for us\n");
break;
@@ -3789,12 +3806,7 @@
}
}
break;
- case EVENT_CLEANUP:
- {
- stop_bc_tones(ch);
- release_chan(bc);
- }
- break;
+
/***************************/
/** Suplementary Services **/
Modified: team/crichter/0.3.0/channels/misdn/chan_misdn_config.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/chan_misdn_config.h?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/chan_misdn_config.h (original)
+++ team/crichter/0.3.0/channels/misdn/chan_misdn_config.h Thu Jul 6 10:05:49 2006
@@ -29,6 +29,7 @@
MISDN_CFG_TXGAIN, /* int */
MISDN_CFG_TE_CHOOSE_CHANNEL, /* int (bool) */
MISDN_CFG_PMP_L1_CHECK, /* int (bool) */
+ MISDN_CFG_PP_L2_CHECK, /* int (bool) */
MISDN_CFG_HDLC, /* int (bool) */
MISDN_CFG_CONTEXT, /* char[] */
MISDN_CFG_LANGUAGE, /* char[] */
Modified: team/crichter/0.3.0/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_lib.c?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Thu Jul 6 10:05:49 2006
@@ -412,6 +412,11 @@
int empty_chan_in_stack(struct misdn_stack *stack, int channel)
{
+ if (channel<=0) {
+ cb_log(-1,stack?stack->port:0, "empty_chan_inst_stack: cannot empty channel %d\n",channel);
+ return -1;
+ }
+
cb_log (1, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel);
stack->channels[channel-1] = 0;
dump_chan_list(stack);
@@ -808,9 +813,6 @@
ncr.len = 0;
bc->l3_id = l3_id;
- if (mypid>5000) mypid=1;
- bc->pid=mypid++;
-
cb_log(3, stack->port, " --> new_l3id %x\n",l3_id);
} else {
@@ -841,9 +843,6 @@
/* send message */
bc->l3_id = l3_id;
- if (mypid>5000) mypid=1;
- bc->pid=mypid++;
-
cb_log(3, stack->port, "--> new_l3id %x\n",l3_id);
mISDN_write(midev, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
@@ -1462,7 +1461,8 @@
case EVENT_RELEASE_COMPLETE:
case EVENT_RELEASE:
- empty_chan_in_stack(stack,bc->channel);
+ if (bc->channel>0)
+ empty_chan_in_stack(stack,bc->channel);
empty_bc(bc);
clean_up_bc(bc);
break;
@@ -1488,9 +1488,6 @@
cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
bc->l3_id=frm->dinfo;
-
- if (mypid>5000) mypid=1;
- bc->pid=mypid++;
return 0;
}
@@ -1528,7 +1525,8 @@
if (bc) {
cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n",frm->dinfo);
- empty_chan_in_stack(stack,bc->channel);
+ if (bc->channel>0)
+ empty_chan_in_stack(stack,bc->channel);
empty_bc(bc);
clean_up_bc(bc);
@@ -1566,10 +1564,10 @@
return;
}
- if (bc->channel>=0) {
+ if (bc->channel>0) {
empty_chan_in_stack(stack,bc->channel);
- empty_bc(bc);
- }
+ }
+ empty_bc(bc);
clean_up_bc(bc);
}
@@ -1645,7 +1643,11 @@
if (stack->port == port) {
if (stack->ptp ) {
- if (stack->l1link && stack->l2link) {
+ if (stack->l1link) {
+ if (check==2 && !stack->l2link) {
+ cb_log(-1,port, "Port Down L2 (checked):%d L1:%d\n", stack->l2link, stack->l1link);
+ return 0;
+ }
return 1;
} else {
cb_log(-1,port, "Port Down L2:%d L1:%d\n",
@@ -1992,6 +1994,9 @@
break;
case EVENT_RELEASE:
case EVENT_RELEASE_COMPLETE:
+ if (bc->channel>0)
+ empty_chan_in_stack(stack, bc->channel);
+ empty_bc(bc);
clean_up_bc(bc);
break;
@@ -2521,7 +2526,8 @@
bc->out_cause=16;
misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
- empty_chan_in_stack(stack, bc->channel);
+ if (bc->channel>0)
+ empty_chan_in_stack(stack, bc->channel);
empty_bc(bc);
bc_state_change(bc,BCHAN_CLEANED);
@@ -2920,6 +2926,25 @@
}
+
+void prepare_bc(struct misdn_bchannel*bc, int channel)
+{
+ bc->channel = channel;
+ bc->channel_preselected = channel?1:0;
+ bc->in_use = 1;
+ bc->need_disconnect=1;
+ bc->need_release=1;
+ bc->need_release_complete=1;
+
+ if (++mypid>5000) mypid=1;
+ bc->pid=mypid;
+
+#if 0
+ bc->addr=0;
+ bc->b_stid=0;
+ bc->layer_id=0;
+#endif
+}
struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel)
{
@@ -2949,9 +2974,7 @@
}
for (i = 0; i < stack->b_num; i++) {
if (!stack->bc[i].in_use) {
- stack->bc[i].channel = channel;
- stack->bc[i].channel_preselected = channel?1:0;
- stack->bc[i].in_use = 1;
+ prepare_bc(&stack->bc[i], channel);
return &stack->bc[i];
}
}
@@ -3129,7 +3152,8 @@
misdn_split_conf(bc->holded_bc,bc->holded_bc->conf_id);
}
- empty_chan_in_stack(stack,bc->channel);
+ if (bc->channel>0)
+ empty_chan_in_stack(stack,bc->channel);
empty_bc(bc);
clean_up_bc(bc);
}
@@ -3142,11 +3166,29 @@
cb_event( EVENT_NEW_BC, holded_bc, glob_mgr->user_data);
}
break;
-
+
+ /* finishing the channel eh ? */
+ case EVENT_DISCONNECT:
+ if (!bc->need_disconnect) {
+ cb_log(-1,1," --> we have already send Disconnect\n");
+ return -1;
+ }
+
+ bc->need_disconnect=0;
+ break;
case EVENT_RELEASE:
+ if (!bc->need_release) {
+ cb_log(-1,bc->port," --> we have already send Release\n");
+ return -1;
+ }
+ bc->need_release=0;
+ break;
case EVENT_RELEASE_COMPLETE:
- /*we do the cleanup in EVENT_CLEANUP*/
- /*clean_up_bc(bc);*/
+ if (!bc->need_release_complete) {
+ cb_log(-1,bc->port," --> we have already send Release_complete\n");
+ return -1;
+ }
+ bc->need_release_complete=0;
break;
case EVENT_CONNECT_ACKNOWLEDGE:
@@ -3916,7 +3958,8 @@
{
struct misdn_stack *stack=get_stack_by_bc(bc);
- empty_chan_in_stack(stack, bc->channel);
+ if (bc->channel>0)
+ empty_chan_in_stack(stack, bc->channel);
empty_bc(bc);
misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
Modified: team/crichter/0.3.0/channels/misdn/isdn_lib.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_lib.h?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.h (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.h Thu Jul 6 10:05:49 2006
@@ -190,7 +190,11 @@
int layer;
-
+ /*state stuff*/
+ int need_disconnect;
+ int need_release;
+ int need_release_complete;
+
/** var stuff**/
int l3_id;
int pid;
Modified: team/crichter/0.3.0/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn_config.c?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn_config.c (original)
+++ team/crichter/0.3.0/channels/misdn_config.c Thu Jul 6 10:05:49 2006
@@ -90,6 +90,7 @@
{ "te_choose_channel", MISDN_CFG_TE_CHOOSE_CHANNEL, MISDN_CTYPE_BOOL, "no", NONE },
{ "far_alerting", MISDN_CFG_FAR_ALERTING, MISDN_CTYPE_BOOL, "no", NONE },
{ "pmp_l1_check", MISDN_CFG_PMP_L1_CHECK, MISDN_CTYPE_BOOL, "yes", NONE },
+ { "pp_l2_check", MISDN_CFG_PP_L2_CHECK, MISDN_CTYPE_BOOL, "no", NONE },
{ "hdlc", MISDN_CFG_HDLC, MISDN_CTYPE_BOOL, "no", NONE },
{ "context", MISDN_CFG_CONTEXT, MISDN_CTYPE_STR, "default", NONE },
{ "language", MISDN_CFG_LANGUAGE, MISDN_CTYPE_STR, "en", NONE },
Modified: team/crichter/0.3.0/configs/misdn.conf.sample
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/configs/misdn.conf.sample?rev=37171&r1=37170&r2=37171&view=diff
==============================================================================
--- team/crichter/0.3.0/configs/misdn.conf.sample (original)
+++ team/crichter/0.3.0/configs/misdn.conf.sample Thu Jul 6 10:05:49 2006
@@ -186,6 +186,7 @@
; default: yes
;
pmp_l1_check=yes
+pp_l2_check=no
;
; Send Setup_Acknowledge on incoming calls anyway (instead of PROCEEDING),
More information about the asterisk-commits
mailing list