Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (Revision 8080) +++ channels/chan_zap.c (Arbeitskopie) @@ -557,6 +557,7 @@ unsigned int dialednone:1; unsigned int dialing:1; unsigned int digital:1; + unsigned int hdlc:1; unsigned int dnd:1; unsigned int echobreak:1; unsigned int echocanbridged:1; @@ -2266,6 +2267,37 @@ return 0; } +static char *zap_set_hdlc_app = "ZapSetHDLC"; + +static char *zap_set_hdlc_synopsis = "Sets channel into HDLC mode"; + +static char *zap_set_hdlc_descrip = +" ZapSetHDLC(): This application will set the current channel in hdlc mode\n" +; + +static int zap_set_hdlc_exec(struct ast_channel *chan, void *data) +{ + /* Data will be our digit string */ + struct zt_pvt *p = (struct zt_pvt *)chan->tech_pvt; + int x=1; + + if (!p) { + ast_log(LOG_WARNING, "Unable to find technology private\n"); + return -1; + } + + ast_mutex_lock(&p->lock); + + if (ioctl(p->subs[SUB_REAL].zfd, ZT_HDLCFCSMODE, &x) == -1) + ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d\n", p->channel, x); + + p->hdlc=1; + + ast_mutex_unlock(&p->lock); + + return 0; +} + int pri_is_up(struct zt_pri *pri) { int x; @@ -2509,7 +2541,15 @@ ast_dsp_free(p->dsp); p->dsp = NULL; } - + + if (p->hdlc) { + int x=1; + res = ioctl(p->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &x); + if (res < 0) + ast_log(LOG_WARNING, "Unable to set Audiomode on channel %d to default\n", p->channel); + p->hdlc = 0; + } + law = ZT_LAW_DEFAULT; res = ioctl(p->subs[SUB_REAL].zfd, ZT_SETLAW, &law); if (res < 0) @@ -4567,11 +4607,22 @@ ast_mutex_unlock(&p->lock); return f; } - if (res != (p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE)) { - ast_log(LOG_DEBUG, "Short read (%d/%d), must be an event...\n", res, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE); - f = __zt_exception(ast); - ast_mutex_unlock(&p->lock); - return f; + + if (p->digital && p->hdlc ) { + /*FIXME:why*/ + res-=2; +#if 0 + ast_log(LOG_NOTICE,"READ: %d\n",res); +#endif + } else { + + if (res != (p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE)) { + ast_log(LOG_DEBUG, "Short read (%d/%d), must be an event...\n", res, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE); + f = __zt_exception(ast); + ast_mutex_unlock(&p->lock); + return f; + } + } if (p->tdd) { /* if in TDD mode, see if we receive that */ int c; @@ -4609,11 +4660,16 @@ ast_verbose(VERBOSE_PREFIX_3 "CPE does not support Call Waiting Caller*ID.\n"); restore_conference(p); } - if (p->subs[index].linear) { - p->subs[index].f.datalen = READ_SIZE * 2; - } else - p->subs[index].f.datalen = READ_SIZE; - + + if (p->digital && p->hdlc) { + p->subs[index].f.datalen = res; + } else { + if (p->subs[index].linear) { + p->subs[index].f.datalen = READ_SIZE * 2; + } else + p->subs[index].f.datalen = READ_SIZE; + } + /* Handle CallerID Transmission */ if ((p->owner == ast) && p->cidspill &&((ast->_state == AST_STATE_UP) || (ast->rings == p->cidrings))) { send_callerid(p); @@ -4621,7 +4677,10 @@ p->subs[index].f.frametype = AST_FRAME_VOICE; p->subs[index].f.subclass = ast->rawreadformat; - p->subs[index].f.samples = READ_SIZE; + if (p->digital && p->hdlc ) + p->subs[index].f.samples = res; + else + p->subs[index].f.samples = READ_SIZE; p->subs[index].f.mallocd = 0; p->subs[index].f.offset = AST_FRIENDLY_OFFSET; p->subs[index].f.data = p->subs[index].buffer + AST_FRIENDLY_OFFSET/2; @@ -4642,7 +4701,7 @@ p->subs[index].f.data = NULL; p->subs[index].f.datalen= 0; } - if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress) && !index) { + if (p->dsp && (!p->ignoredtmf || p->callwaitcas || p->busydetect || p->callprogress) && !index && !p->digital) { /* Perform busy detection. etc on the zap line */ f = ast_dsp_process(ast, p->dsp, &p->subs[index].f); if (f) { @@ -4744,6 +4803,18 @@ int res; int fd; fd = p->subs[index].zfd; + + if (p->digital && p->hdlc) { + /*FIXME: why*/ + char mybuf[len+2]; + memcpy(mybuf,buf,len); +#if 0 + ast_log(LOG_NOTICE, "Writing on zap channel len:%d\n",len); +#endif + write(fd,mybuf,len+2); + return 0; + } + while(len) { size = len; if (size > (linear ? READ_SIZE * 2 : READ_SIZE)) @@ -7746,6 +7817,15 @@ p->digital = 1; if (tmp) tmp->transfercapability = AST_TRANS_CAP_DIGITAL; + } else if (opt == 'h') { + /* If this is an ISDN call, make it digital + hdlc */ + ast_log(LOG_NOTICE,"Setting Digital mode with hdlc encryption\n"); + + p->digital = 1; + p->hdlc = 1; + + if (tmp) + tmp->transfercapability = AST_TRANS_CAP_DIGITAL; } else { ast_log(LOG_WARNING, "Unknown option '%c' in '%s'\n", opt, (char *)data); } @@ -8899,6 +8979,11 @@ if (!ast_strlen_zero(e->answer.useruserinfo)) { pbx_builtin_setvar_helper(pri->pvts[chanpos]->owner, "USERUSERINFO", e->answer.useruserinfo); } + + if (pri->pvts[chanpos]->digital && pri->pvts[chanpos]->hdlc) { + + zap_set_hdlc_exec(pri->pvts[chanpos]->owner,NULL); + } ast_mutex_unlock(&pri->pvts[chanpos]->lock); } } @@ -10123,6 +10208,7 @@ } ast_cli_unregister_multiple(zap_pri_cli, sizeof(zap_pri_cli) / sizeof(zap_pri_cli[0])); ast_unregister_application(zap_send_keypad_facility_app); + ast_unregister_application(zap_set_hdlc_app); #endif #ifdef ZAPATA_R2 ast_cli_unregister_multiple(zap_r2_cli, sizeof(zap_r2_cli) / sizeof(zap_r2_cli[0])); @@ -11026,6 +11112,9 @@ pri_set_message(zt_pri_message); ast_register_application(zap_send_keypad_facility_app, zap_send_keypad_facility_exec, zap_send_keypad_facility_synopsis, zap_send_keypad_facility_descrip); + + ast_register_application(zap_set_hdlc_app, zap_set_hdlc_exec, + zap_set_hdlc_synopsis, zap_set_hdlc_descrip); #endif res = setup_zap(0); /* Make sure we can register our Zap channel type */