[asterisk-commits] branch crichter/0.3.0 r10763 - in
/team/crichter/0.3.0/channels: ./ misdn/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Feb 22 12:08:50 MST 2006
Author: crichter
Date: Wed Feb 22 13:08:45 2006
New Revision: 10763
URL: http://svn.digium.com/view/asterisk?rev=10763&view=rev
Log:
* changed some strncpys to ast_copy_str
* added copying of some IEs (user,rate,urate) with channel vars
* added #6251
Modified:
team/crichter/0.3.0/channels/chan_misdn.c
team/crichter/0.3.0/channels/chan_zap.c
team/crichter/0.3.0/channels/misdn/isdn_lib.c
team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c
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=10763&r1=10762&r2=10763&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Wed Feb 22 13:08:45 2006
@@ -68,7 +68,7 @@
#define release_unlock ast_mutex_unlock(&release_lock_mutex)
-char global_tracefile[BUFFERSIZE];
+char global_tracefile[BUFFERSIZE+1];
struct misdn_jb{
@@ -82,6 +82,10 @@
int bytes_wrote;
ast_mutex_t mutexjb;
};
+
+void export_ies(struct ast_channel *chan, struct misdn_bchannel *bc);
+void import_ies(struct ast_channel *chan, struct misdn_bchannel *bc);
+
/* allocates the jb-structure and initialise the elements*/
struct misdn_jb *misdn_jb_init(int size, int upper_threshold);
@@ -241,14 +245,13 @@
#define MISDN_ASTERISK_TECH_PVT(ast) ast->tech_pvt
#define MISDN_ASTERISK_PVT(ast) 1
-#define MISDN_ASTERISK_TYPE(ast) ast->tech->type
#include <asterisk/strings.h>
/* #define MISDN_DEBUG 1 */
static char *desc = "Channel driver for mISDN Support (Bri/Pri)";
-static char *misdn_type = "mISDN";
+static const char misdn_type[] = "mISDN";
static int tracing = 0 ;
@@ -881,9 +884,7 @@
tmp=get_chan_by_ast_name(channame);
if (tmp && tmp->bc) {
- int l = sizeof(tmp->bc->display);
- strncpy(tmp->bc->display, msg, l);
- tmp->bc->display[l-1] = 0;
+ ast_copy_string(tmp->bc->display, msg, sizeof(tmp->bc->display));
misdn_lib_send_event(tmp->bc, EVENT_INFORMATION);
} else {
ast_cli(fd,"No such channel %s\n",channame);
@@ -1195,21 +1196,16 @@
int port=bc->port;
chan_misdn_log(1,port,"read_config: Getting Config\n");
-
- char lang[BUFFERSIZE];
-
+
+ char lang[BUFFERSIZE+1];
misdn_cfg_get( port, MISDN_CFG_LANGUAGE, lang, BUFFERSIZE);
ast_copy_string(ast->language, lang, sizeof(ast->language));
- ast->language[sizeof(ast->language)]=0;
-
-
- char musicclass[BUFFERSIZE];
+
+ char musicclass[BUFFERSIZE+1];
misdn_cfg_get( port, MISDN_CFG_MUSICCLASS, musicclass, BUFFERSIZE);
ast_copy_string(ast->musicclass, musicclass, sizeof(ast->musicclass));
- ast->musicclass[sizeof(ast->musicclass)]=0;
-
misdn_cfg_get( port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int));
misdn_cfg_get( port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int));
@@ -1231,7 +1227,7 @@
misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
- strncpy(ast->context,ch->context,sizeof(ast->context)-1);
+ ast_copy_string (ast->context,ch->context,sizeof(ast->context));
{
int ec, ectr;
@@ -1280,7 +1276,7 @@
{
- char callerid[BUFFERSIZE];
+ char callerid[BUFFERSIZE+1];
misdn_cfg_get( port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);
if ( ! ast_strlen_zero(callerid) ) {
chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
@@ -1340,7 +1336,7 @@
} else { /** ORIGINATOR MISDN **/
- char prefix[BUFFERSIZE]="";
+ char prefix[BUFFERSIZE+1]="";
switch( bc->onumplan ) {
case NUMPLAN_INTERNATIONAL:
misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
@@ -1371,13 +1367,11 @@
if (!ast_strlen_zero(bc->dad)) {
- strncpy(bc->orig_dad,bc->dad, sizeof(bc->orig_dad));
- bc->orig_dad[sizeof(bc->orig_dad)-1] = 0;
+ ast_copy_string(bc->orig_dad,bc->dad, sizeof(bc->orig_dad));
}
if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
- strncpy(bc->dad,bc->keypad, sizeof(bc->dad));
- bc->dad[sizeof(bc->dad)-1] = 0;
+ ast_copy_string(bc->dad,bc->keypad, sizeof(bc->dad));
}
prefix[0] = 0;
@@ -1420,10 +1414,9 @@
if ( !ast->cid.cid_num) {
ast->cid.cid_num=strdup(bc->oad);
}
-
+
pbx_builtin_setvar_helper(ch->ast,"REDIRECTING_NUMBER",bc->rad);
}
-
return 0;
}
@@ -1531,7 +1524,10 @@
/* update screening and presentation */
update_config(ch,ORG_AST);
-
+
+ /* fill in some ies from channel vary*/
+ import_ies(ast, newbc);
+
/* Finally The Options Override Everything */
if (opts)
misdn_set_opt_exec(ast,opts);
@@ -2229,7 +2225,7 @@
{
struct ast_channel *tmp = NULL;
- char group[BUFFERSIZE]="";
+ char group[BUFFERSIZE+1]="";
char buf[128];
char buf2[128], *ext=NULL, *port_str;
char *tokb=NULL, *p=NULL;
@@ -2239,20 +2235,12 @@
struct chan_list *cl=init_chan_list();
sprintf(buf,"%s/%s",misdn_type,(char*)data);
- strncpy(buf2,data, 128);
- buf2[127] = 0;
+ ast_copy_string(buf2,data, 128);
+
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 (port_str) {
if (port_str[0]=='g' && port_str[1]==':' ) {
/* We make a group call lets checkout which ports are in my group */
@@ -2280,7 +2268,7 @@
if (!ast_strlen_zero(group)) {
- char cfg_group[BUFFERSIZE];
+ char cfg_group[BUFFERSIZE+1];
struct robin_list *rr = NULL;
if (misdn_cfg_is_group_method(group, METHOD_ROUND_ROBIN)) {
@@ -2938,6 +2926,43 @@
}
}
+
+void import_ies(struct ast_channel *chan, struct misdn_bchannel *bc)
+{
+ char *tmp;
+
+ tmp=pbx_builtin_getvar_helper(chan,"PRI_MODE");
+ if (tmp) bc->mode=atoi(tmp);
+
+ tmp=pbx_builtin_getvar_helper(chan,"PRI_URATE");
+ if (tmp) bc->urate=atoi(tmp);
+
+ tmp=pbx_builtin_getvar_helper(chan,"PRI_RATE");
+ if (tmp) bc->rate=atoi(tmp);
+
+ tmp=pbx_builtin_getvar_helper(chan,"PRI_USER1");
+ if (tmp) bc->user1=atoi(tmp);
+}
+
+void export_ies(struct ast_channel *chan, struct misdn_bchannel *bc)
+{
+ char tmp[32];
+
+ sprintf(tmp,"%d",bc->mode);
+ pbx_builtin_setvar_helper(chan,"PRI_MODE",tmp);
+
+ sprintf(tmp,"%d",bc->urate);
+ pbx_builtin_setvar_helper(chan,"PRI_URATE",tmp);
+
+ sprintf(tmp,"%d",bc->rate);
+ pbx_builtin_setvar_helper(chan,"PRI_RATE",tmp);
+
+ sprintf(tmp,"%d",bc->user1);
+ pbx_builtin_setvar_helper(chan,"PRI_USER1",tmp);
+}
+
+
+
/************************************************************/
/* Receive Events from isdn_lib here */
/************************************************************/
@@ -3146,11 +3171,13 @@
ch->l3id=bc->l3_id;
ch->addr=bc->addr;
ch->orginator = ORG_MISDN;
-
+
chan=misdn_new(ch, AST_STATE_RESERVED,bc->dad, bc->oad, AST_FORMAT_ALAW, bc->port, bc->channel);
- ch->ast = chan;
-
+ ch->ast = chan;
+
read_config(ch, ORG_MISDN);
+
+ export_ies(chan, bc);
ch->ast->rings=1;
ast_setstate(ch->ast, AST_STATE_RINGING);
@@ -3261,7 +3288,7 @@
tone_indicate(ch,TONE_NONE);
else
tone_indicate(ch,TONE_DIAL);
-
+
ch->state=MISDN_WAITING4DIGS;
}
@@ -3649,7 +3676,7 @@
{
- char tempbuf[BUFFERSIZE];
+ char tempbuf[BUFFERSIZE+1];
misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, tempbuf, BUFFERSIZE);
if (strlen(tempbuf))
tracing = 1;
@@ -3879,7 +3906,7 @@
switch(tok[0]) {
case 'd' :
- strncpy(ch->bc->display,++tok,84);
+ ast_copy_string(ch->bc->display,++tok,84);
chan_misdn_log(1, ch->bc->port, "SETOPT: Display:%s\n",ch->bc->display);
break;
@@ -3947,10 +3974,9 @@
}
{
- int l = sizeof(ch->bc->crypt_key);
- strncpy(ch->bc->crypt_key, misdn_key_vector[keyidx], l);
- ch->bc->crypt_key[l-1] = 0;
+ ast_copy_string(ch->bc->crypt_key, misdn_key_vector[keyidx], sizeof(ch->bc->crypt_key));
}
+
chan_misdn_log(0, ch->bc->port, "SETOPT: crypt with key:%s\n",misdn_key_vector[keyidx]);
break;
Modified: team/crichter/0.3.0/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_zap.c?rev=10763&r1=10762&r2=10763&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_zap.c (original)
+++ team/crichter/0.3.0/channels/chan_zap.c Wed Feb 22 13:08:45 2006
@@ -377,6 +377,7 @@
/*! Chunk size to read -- we use 20ms chunks to make things happy. */
#define READ_SIZE 160
+#define HDLC_READ_SIZE 2051
#define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
#define MASK_INUSE (1 << 1) /*!< Channel currently in use */
@@ -502,7 +503,8 @@
int zfd;
struct ast_channel *owner;
int chan;
- short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
+ /* in hdlc mode our buffer must be bigger..*/
+ short buffer[AST_FRIENDLY_OFFSET/2 + HDLC_READ_SIZE];
struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
unsigned int needringing:1;
unsigned int needbusy:1;
@@ -556,6 +558,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;
@@ -702,6 +705,9 @@
static int zt_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int zt_setoption(struct ast_channel *chan, int option, void *data, int datalen);
+
+static int zap_set_hdlc_exec(struct ast_channel *chan, void *data);
+
static const struct ast_channel_tech zap_tech = {
.type = type,
.description = tdesc,
@@ -2462,7 +2468,20 @@
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;
+
+ int bs=READ_SIZE;
+ if (ioctl(p->subs[SUB_REAL].zfd, ZT_SET_BLOCKSIZE, &bs) == -1)
+ ast_log(LOG_WARNING, "Unable to change the blocksize on channel %d to :%d\n", p->channel, bs);
+
+ }
+
law = ZT_LAW_DEFAULT;
res = ioctl(p->subs[SUB_REAL].zfd, ZT_SETLAW, &law);
if (res < 0)
@@ -4507,7 +4526,10 @@
}
readbuf = ((unsigned char *)p->subs[index].buffer) + AST_FRIENDLY_OFFSET;
CHECK_BLOCKING(ast);
- res = read(p->subs[index].zfd, readbuf, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE);
+ if (p->hdlc)
+ res = read(p->subs[index].zfd, readbuf, HDLC_READ_SIZE);
+ else
+ res = read(p->subs[index].zfd, readbuf, p->subs[index].linear ? READ_SIZE * 2 : READ_SIZE);
ast_clear_flag(ast, AST_FLAG_BLOCKING);
/* Check for hangup */
if (res < 0) {
@@ -4525,11 +4547,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->hdlc ) {
+ /*FIXME: last 2 bytes are the Frame check*/
+ 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;
@@ -4567,11 +4600,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->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);
@@ -4579,7 +4617,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->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;
@@ -4600,7 +4641,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) {
@@ -4702,6 +4743,18 @@
int res;
int fd;
fd = p->subs[index].zfd;
+
+ if ( p->hdlc ) {
+ /*FIXME: 2 bytes for the framecheck*/
+ 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))
@@ -7636,6 +7689,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);
}
@@ -8367,6 +8429,11 @@
}
}
}
+
+ 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);
}
}
@@ -9231,6 +9298,45 @@
return RESULT_SUCCESS;
}
+
+
+
+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;
+ int bs=HDLC_READ_SIZE; /* how large can hdlc frames be on the bchannel ? */
+
+ 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);
+
+ if (ioctl(p->subs[SUB_REAL].zfd, ZT_SET_BLOCKSIZE, &bs) == -1)
+ ast_log(LOG_WARNING, "Unable to change the blocksize on channel %d to :%d\n", p->channel, bs);
+
+ p->hdlc=1;
+
+ ast_mutex_unlock(&p->lock);
+
+ return 0;
+}
+
+
static int handle_pri_debug(int fd, int argc, char *argv[])
{
int span;
@@ -10045,6 +10151,9 @@
ast_cli_unregister_multiple(zap_r2_cli, sizeof(zap_r2_cli) / sizeof(zap_r2_cli[0]));
#endif
ast_cli_unregister_multiple(zap_cli, sizeof(zap_cli) / sizeof(zap_cli[0]));
+
+ ast_unregister_application(zap_set_hdlc_app);
+
ast_manager_unregister( "ZapDialOffhook" );
ast_manager_unregister( "ZapHangup" );
ast_manager_unregister( "ZapTransfer" );
@@ -10956,6 +11065,9 @@
ast_manager_register( "ZapDNDoff", 0, action_zapdndoff, "Toggle Zap channel Do Not Disturb status OFF" );
ast_manager_register("ZapShowChannels", 0, action_zapshowchannels, "Show status zapata channels");
+
+ ast_register_application(zap_set_hdlc_app, zap_set_hdlc_exec, zap_set_hdlc_synopsis, zap_set_hdlc_descrip);
+
return res;
}
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=10763&r1=10762&r2=10763&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Wed Feb 22 13:08:45 2006
@@ -491,7 +491,7 @@
bc->capability=INFO_CAPABILITY_SPEECH;
bc->law=INFO_CODEC_ALAW;
bc->mode=0;
- bc->rate=0;
+ bc->rate=0x10;
bc->user1=0;
bc->urate=0;
@@ -503,6 +503,7 @@
bc->infos_pending[0] = 0;
bc->oad[0] = 0;
bc->dad[0] = 0;
+ bc->rad[0] = 0;
bc->orig_dad[0] = 0;
bc->fac_type=FACILITY_NONE;
Modified: team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c?rev=10763&r1=10762&r2=10763&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c Wed Feb 22 13:08:45 2006
@@ -300,6 +300,8 @@
break;
case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
user=-1;
+ mode=bc->mode;
+ rate=bc->rate;
break;
case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
user=-1;
More information about the asterisk-commits
mailing list