? channels/misdn/te_test.c Index: channels/chan_misdn.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_misdn.c,v retrieving revision 1.6 diff -u -r1.6 chan_misdn.c --- channels/chan_misdn.c 11 Nov 2005 00:35:21 -0000 1.6 +++ channels/chan_misdn.c 14 Nov 2005 13:57:20 -0000 @@ -152,6 +152,7 @@ static void free_robin_list ( void ) { free_robin_list_r(robin); + robin = NULL; } struct robin_list* get_robin_position (char *group) @@ -1040,21 +1041,29 @@ int r; struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast); struct misdn_bchannel *newbc; - char *opts=NULL; + char *opts=NULL, *ext=NULL; char dest_cp[256]; + char *tokb; { strncpy(dest_cp,dest,sizeof(dest_cp)-1); dest_cp[sizeof(dest_cp)]=0; - opts=strchr(dest_cp,'/'); - if ( opts && (opts=strchr(++opts,'/')) ) { - if (opts) { - opts++; - if (!*opts) opts=NULL; + + ext=strtok_r(dest_cp,"/",&tokb); + + if (ext) { + ext=strtok_r(NULL,"/",&tokb); + if (ext) { + opts=strtok_r(NULL,"/",&tokb); + } else { + chan_misdn_log(-1,0,"misdn_call: No Extension given!\n"); + return -1; } } + + } - + if (!ast) { ast_log(LOG_WARNING, " --> ! misdn_call called on ast_channel *ast where ast == NULL\n"); return -1; @@ -1085,7 +1094,10 @@ } port=newbc->port; - + + strncpy(newbc->dad,ext,sizeof( newbc->dad)); + strncpy(ast->exten,ext,sizeof(ast->exten)); + chan_misdn_log(1, 0, "* CALL: %s\n",dest); @@ -1148,17 +1160,40 @@ int def_callingpres; misdn_cfg_get( port, MISDN_CFG_USE_CALLINGPRES, &def_callingpres, sizeof(int)); if ( def_callingpres) { - switch (ast->cid.cid_pres){ - case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: + switch (ast->cid.cid_pres & 0x60){ + + case AST_PRES_RESTRICTED: newbc->pres=1; break; - case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: - newbc->pres=0; + case AST_PRES_UNAVAILABLE: + newbc->pres=2; break; + default: newbc->pres=0; } + + switch (ast->cid.cid_pres & 0x3){ + + case AST_PRES_USER_NUMBER_UNSCREENED: + newbc->screen=0; + break; + + case AST_PRES_USER_NUMBER_PASSED_SCREEN: + newbc->screen=1; + break; + case AST_PRES_USER_NUMBER_FAILED_SCREEN: + newbc->screen=2; + break; + + case AST_PRES_NETWORK_NUMBER: + newbc->screen=3; + break; + + default: + newbc->screen=0; + } } @@ -1289,12 +1324,19 @@ } } + + { + char *async=pbx_builtin_getvar_helper(ast, "MISDN_DIGITAL_TRANS"); + if (async) { + chan_misdn_log(1, p->bc->port, " --> Connection is transparent digital\n"); + p->bc->async=1; + } + } p->state = MISDN_CONNECTED; misdn_lib_send_event( p->bc, EVENT_CONNECT); start_bc_tones(p); - return 0; } @@ -1506,6 +1548,13 @@ return 0 ; } + bc=p->bc; + + if (!bc) { + release_unlock; + ast_log(LOG_WARNING,"Hangup with private but no bc ?\n"); + return 0; + } MISDN_ASTERISK_TECH_PVT(ast)=NULL; @@ -1529,12 +1578,9 @@ release_unlock; - bc=p->bc; - if (!bc) { - ast_log(LOG_WARNING,"Hangup with private but no bc ?\n"); - return 0; - } + + { char *varcause=NULL; @@ -1645,7 +1691,6 @@ tmp->frame.data = tmp->ast_rd_buf ; chan_misdn_trace_call(tmp->ast,3,"*->I: EVENT_READ len=%d\n",len); - return &tmp->frame; } @@ -1692,7 +1737,6 @@ } #endif chan_misdn_trace_call(ast,3,"*->I: EVENT_WRITE len=%d\n",frame->samples); - i= manager_tx2misdn_frm(p->bc, frame->data, frame->samples); return 0; @@ -1840,13 +1884,15 @@ port_str=strtok_r(buf2,"/", &tokb); ext=strtok_r(NULL,"/", &tokb); + + /* + if (!ext) { + ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITH WRONG ARGS, check extension.conf\n",ext); + + return NULL; + } + */ - if (!ext) { - ast_log(LOG_WARNING, " --> ! IND : CALL dad:%s WITH WRONG ARGS, check extension.conf\n",ext); - - return NULL; - } - if (port_str) { if (port_str[0]=='g' && port_str[1]==':' ) { /* We make a group call lets checkout which ports are in my group */ @@ -2017,7 +2063,7 @@ { struct ast_channel *tmp; - tmp = ast_channel_alloc(0); + tmp = ast_channel_alloc(1); if (tmp) { chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s ctx:%s\n",exten,callerid, context); @@ -2052,9 +2098,15 @@ tmp->readformat = format; tmp->priority=1; - - strncpy(tmp->context, context, sizeof(tmp->context)-1); - strncpy(tmp->exten, exten, sizeof(tmp->exten) - 1); + + if (context) + strncpy(tmp->context, context, sizeof(tmp->context)-1); + else + chan_misdn_log(1,0,"misdn_new: no context given.\n"); + if (exten) + strncpy(tmp->exten, exten, sizeof(tmp->exten) - 1); + else + chan_misdn_log(1,0,"misdn_new: no exten given.\n"); if (callerid) { char *cid_name, *cid_num; @@ -2208,7 +2260,6 @@ printf ("\n"); #endif chan_misdn_log(9, tmp->bc->port, "Queueing %d bytes 2 Asterisk\n",len); - ast_queue_frame(tmp->ast,&frame); } else { @@ -2812,24 +2863,7 @@ /** queue new chan **/ cl_queue_chan(&cl_te, ch) ; - /* Check for Pickup Request first */ - if (!strcmp(chan->exten, ast_pickup_ext())) { - int ret;/** Sending SETUP_ACK**/ - ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE ); - - if (ast_pickup_call(chan)) { - ast_hangup(chan); - } else { - ch->state = MISDN_CALLING_ACKNOWLEDGE; - - ch->ast=NULL; - - ast_setstate(chan, AST_STATE_DOWN); - ast_hangup(chan); - - break; - } - } + /* added support for s extension hope it will help those poor cretains which haven't overlap dial. @@ -2854,6 +2888,51 @@ } + + { + int ec, ectr; + + misdn_cfg_get( bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int)); + + misdn_cfg_get( bc->port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int)); + if (ec == 1 ) { + bc->ec_enable=1; + } else if ( ec > 1 ) { + bc->ec_enable=1; + bc->ec_deftaps=ec; + } + + if ( !ectr ) { + bc->ec_training=0; + } + } + + + if (bc->urate>0) { + char buf[16]; + snprintf(buf,16,"%d",bc->urate); + pbx_builtin_setvar_helper(chan,"MISDN_URATE",buf); + } + + /* Check for Pickup Request first */ + if (!strcmp(chan->exten, ast_pickup_ext())) { + int ret;/** Sending SETUP_ACK**/ + ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE ); + + if (ast_pickup_call(chan)) { + ast_hangup(chan); + } else { + ch->state = MISDN_CALLING_ACKNOWLEDGE; + + ch->ast=NULL; + + ast_setstate(chan, AST_STATE_DOWN); + ast_hangup(chan); + + break; + } + } + /** Now after we've finished configuring our channel object we'll jump into the dialplan **/ @@ -2966,12 +3045,12 @@ { ch->state = MISDN_ALERTING; - chan_misdn_trace_call(ch->ast,1,"I->*: EVENT_ALERTING\n"); - - ast_queue_control(ch->ast, AST_CONTROL_RINGING); - ast_setstate(ch->ast, AST_STATE_RINGING); - - if ( misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) { + ast_queue_control(ch->ast, AST_CONTROL_RINGING); + ast_setstate(ch->ast, AST_STATE_RINGING); + + cb_log(1,bc->port,"Set State Ringing\n"); + + if ( misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) { start_bc_tones(ch); } } @@ -2998,6 +3077,20 @@ struct chan_list *holded_ch=find_holded(cl_te, bc); + + send_cause2ast(ch->ast,bc); + + if (misdn_inband_avail(bc) && ch->state != MISDN_CONNECTED) { + /* If there's inband information available (e.g. a + recorded message saying what was wrong with the + dialled number, or perhaps even giving an + alternative number, then play it instead of + immediately releasing the call */ + start_bc_tones(ch); + break; + } + + /*Check for holded channel, to implement transfer*/ if (holded_ch ) { if (ch->state == MISDN_CONNECTED ) { misdn_transfer_bc(ch, holded_ch) ; @@ -3005,13 +3098,8 @@ break; } } - - send_cause2ast(ch->ast,bc); - - if (!misdn_inband_avail(bc)) { - /* If Inband Avail. In TE, wait till we get hangup from ast. */ - stop_bc_tones(ch); - } + + stop_bc_tones(ch); bc->out_cause=16; misdn_lib_send_event(bc,EVENT_RELEASE); @@ -3600,9 +3688,13 @@ chan_misdn_log(1, ch->bc->port, "SETOPT: Digital TRANS_DIGITAL\n"); ch->bc->async=1; ch->bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED; + /*ch->bc->state=STATE_CONNECTED; + misdn_lib_setup_bc(ch->bc);*/ } else { ch->bc->async=0; ch->bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED; + /*ch->bc->state=STATE_CONNECTED; + misdn_lib_setup_bc(ch->bc);*/ } break; Index: channels/chan_misdn_config.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_misdn_config.c,v retrieving revision 1.3 diff -u -r1.3 chan_misdn_config.c --- channels/chan_misdn_config.c 11 Nov 2005 00:35:21 -0000 1.3 +++ channels/chan_misdn_config.c 14 Nov 2005 13:57:20 -0000 @@ -27,6 +27,9 @@ */ +#include +#include + #include "chan_misdn_config.h" #include @@ -34,9 +37,6 @@ #include #include #include -#include -#include -#include #include #define AST_LOAD_CFG ast_config_load Index: channels/misdn/isdn_lib.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/misdn/isdn_lib.c,v retrieving revision 1.4 diff -u -r1.4 isdn_lib.c --- channels/misdn/isdn_lib.c 8 Nov 2005 00:02:53 -0000 1.4 +++ channels/misdn/isdn_lib.c 14 Nov 2005 13:57:23 -0000 @@ -50,7 +50,8 @@ struct misdn_stack* get_stack_by_bc(struct misdn_bchannel *bc) { struct misdn_stack *stack=get_misdn_stack(); - + + if (!bc) return NULL; for ( ; stack; stack=stack->next) { int i; @@ -333,7 +334,8 @@ int misdn_cap_is_speech(int cap) /** Poor mans version **/ { - if (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) return 1; + if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) && + (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1; return 0; } @@ -342,6 +344,7 @@ switch (bc->progress_indicator) { case INFO_PI_INBAND_AVAILABLE: case INFO_PI_CALL_NOT_E2E_ISDN: + case INFO_PI_CALLED_NOT_ISDN: return 1; default: return 0; @@ -400,6 +403,8 @@ void empty_bc(struct misdn_bchannel *bc) { + bc->state=STATE_NOTHING; + bc->channel = 0; bc->in_use = 0; @@ -674,6 +679,11 @@ } +void misdn_lib_setup_bc(struct misdn_bchannel *bc) +{ + setup_bc(bc); +} + int setup_bc(struct misdn_bchannel *bc) { @@ -687,15 +697,18 @@ int midev=stack->midev; int channel=bc->channel-1-(bc->channel>16); int b_stid=stack->b_stids[channel>=0?channel:0]; + - if (bc->upset) { - cb_log(5, stack->port, "$$$ bc already upsetted stid :%x\n", b_stid); - return -1; - } - + if (bc->nodsp ) + clean_up_bc(bc); - if (bc->nodsp) { + if ( !misdn_cap_is_speech(bc->capability)) clean_up_bc(bc); + + + if (bc->upset) { + cb_log(4, stack->port, "$$$ bc already upsetted stid :%x\n", b_stid); + return -1; } cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid); @@ -704,7 +717,7 @@ cb_log(0, stack->port," -- Stid <=0 at the moment on port:%d channel:%d\n",stack->port,channel); return 1; } - + bc->b_stid = b_stid; @@ -756,11 +769,12 @@ if (bc->async == 1 || bc->nodsp) { - cb_log(4, stack->port," --> TRANSPARENT Mode (no DSP)\n"); + cb_log(4, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n"); pid.protocol[1] = ISDN_PID_L1_B_64TRANS; pid.protocol[2] = ISDN_PID_L2_B_TRANS; pid.protocol[3] = ISDN_PID_L3_B_USER; pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)); + } else if ( misdn_cap_is_speech(bc->capability)) { cb_log(4, stack->port," --> TRANSPARENT Mode\n"); pid.protocol[1] = ISDN_PID_L1_B_64TRANS; @@ -1201,7 +1215,12 @@ struct misdn_stack *stack=get_stack_by_bc(bc); if (stack->mode == TE_MODE) { switch (event) { + + case EVENT_CONNECT_ACKNOWLEDGE: + manager_bchannel_activate(bc); + break; case EVENT_CONNECT: + if ( *bc->crypt_key ) { cb_log(4, stack->port, "ENABLING BLOWFISH port:%d channel:%d oad%d:%s dad%d:%s\n", stack->port, bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad); @@ -1326,6 +1345,11 @@ void misdn_lib_release(struct misdn_bchannel *bc) { struct misdn_stack *stack=get_stack_by_bc(bc); + + if (!stack) { + cb_log(1,0,"misdn_release: No Stack found\n"); + return; + } if (bc->channel>=0) { empty_chan_in_stack(stack,bc->channel); @@ -1489,13 +1513,14 @@ } break; - + + case CC_CONNECT|INDICATION: case CC_ALERTING|INDICATION: case CC_PROCEEDING|INDICATION: - case CC_CONNECT|INDICATION: + { struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); - + if (!bc) { msg_t *dmsg; cb_log(0, stack->port,"!!!! We didn't found our bc, dinfo:%x port:%d\n",hh->dinfo, stack->port); @@ -1507,6 +1532,7 @@ return 0; } + setup_bc(bc); } break; @@ -1850,8 +1876,9 @@ case DL_ESTABLISH | CONFIRM: cb_log(4, stack->port, "BCHAN: bchan ACT Confirm\n"); free_msg(msg); - return 1; + return 1; + case PH_DEACTIVATE | INDICATION: case DL_RELEASE | INDICATION: cb_log (4, stack->port, "BCHAN: DeACT Ind\n"); @@ -1899,7 +1926,8 @@ bc->bframe_len = frm->len; /** Anyway flip the bufbits **/ - flip_buf_bits(bc->bframe, bc->bframe_len); + if ( misdn_cap_is_speech(bc->capability) ) + flip_buf_bits(bc->bframe, bc->bframe_len); #if MISDN_DEBUG @@ -2417,6 +2445,8 @@ cb_log(2, stack->port, " --> channel:%d caps:%s pi:%x keypad:%s\n", bc->channel, bearer2str(bc->capability),bc->progress_indicator, bc->keypad); + cb_log(3, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); + cb_log(3, stack->port, " --> pid:%d addr:%x l3id:%x\n", bc->pid, bc->addr, bc->l3_id); cb_log(4, stack->port, " --> bc:%x h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); @@ -3030,8 +3060,9 @@ struct misdn_stack *stack=get_stack_by_bc(bc); if (!bc->active) return -1; - - flip_buf_bits(data,len); + + if ( misdn_cap_is_speech(bc->capability) ) + flip_buf_bits(data,len); if ( !bc->nojitter && misdn_cap_is_speech(bc->capability) ) { if (len > ibuf_freecount(bc->misdnbuf)) { Index: channels/misdn/isdn_lib.h =================================================================== RCS file: /usr/cvsroot/asterisk/channels/misdn/isdn_lib.h,v retrieving revision 1.2 diff -u -r1.2 isdn_lib.h --- channels/misdn/isdn_lib.h 1 Nov 2005 22:04:14 -0000 1.2 +++ channels/misdn/isdn_lib.h 14 Nov 2005 13:57:23 -0000 @@ -235,8 +235,7 @@ int stack_holder; int pres; - - int nohdlc; + int screen; int capability; int law; @@ -350,6 +349,7 @@ /** Ibuf interface End **/ +void misdn_lib_setup_bc(struct misdn_bchannel *bc); void misdn_lib_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2); void misdn_lib_split_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2); Index: channels/misdn/isdn_msg_parser.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/misdn/isdn_msg_parser.c,v retrieving revision 1.2 diff -u -r1.2 isdn_msg_parser.c --- channels/misdn/isdn_msg_parser.c 1 Nov 2005 22:04:14 -0000 1.2 +++ channels/misdn/isdn_msg_parser.c 14 Nov 2005 13:57:23 -0000 @@ -267,7 +267,7 @@ enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc); { - int type=bc->onumplan,plan=1,present=bc->pres,screen=0; + int type=bc->onumplan,plan=1,present=bc->pres,screen=bc->screen; enc_ie_calling_pn(&setup->CALLING_PN, msg, type, plan, present, screen, bc->oad, nt, bc); }