17
17
#include <asterisk/file.h>
18
18
#include <asterisk/logger.h>
19
19
#include <asterisk/channel.h>
20
#include <asterisk/indications.h>
20
21
#include <asterisk/pbx.h>
21
22
#include <asterisk/module.h>
22
23
#include <asterisk/translate.h>
86
static float loudness=4096.0;
88
83
static int firstdigittimeout = 20000; /* 20 seconds first digit timeout */
89
84
static int digittimeout = 10000; /* 10 seconds subsequent digit timeout */
91
static void make_tone_block(unsigned char *data, float f1, float f2, int len, int *x)
96
for(i = 0; i < len; i++)
98
val = loudness * sin((f1 * 2.0 * M_PI * (*x))/8000.0);
99
val += loudness * sin((f2 * 2.0 * M_PI * (*x)++)/8000.0);
100
data[i] = AST_LIN2MU((int)val);
102
/* wrap back around from 8000 */
103
if (*x >= 8000) *x = 0;
107
86
static int ms_diff(struct timeval *tv1, struct timeval *tv2)
95
static void play_dialtone(struct ast_channel *chan)
97
const struct tone_zone_sound *ts = NULL;
98
ts = ast_get_indication_tone(chan->zone, "dial");
100
ast_playtones_start(chan, 0, ts->data, 0);
102
ast_tonepair_start(chan, 350, 440, 0, 0);
116
105
static int disa_exec(struct ast_channel *chan, void *data)
107
int i,j,k,x,did_ignore;
119
108
struct localuser *u;
120
char tmp[256],arg2[256],exten[AST_MAX_EXTENSION],acctcode[20];
122
unsigned char offset[AST_FRIENDLY_OFFSET];
123
unsigned char buf[640];
109
char tmp[256],arg2[256]="",exten[AST_MAX_EXTENSION],acctcode[20]="";
125
110
char *ourcontext,*ourcallerid;
126
struct ast_frame *f,wf;
127
112
struct timeval lastout, now, lastdigittime;
130
116
char *stringp=NULL;
150
136
ourcontext = strsep(&stringp, "|");
151
137
/* if context specified, save 2nd arg and parse third */
152
138
if (ourcontext) {
153
strcpy(arg2,ourcontext);
139
strncpy(arg2,ourcontext, sizeof(arg2) - 1);
154
140
ourcallerid = strsep(&stringp,"|");
156
142
/* if context not specified, use "disa" */
166
152
ast_answer(chan);
168
154
i = k = x = 0; /* k is 0 for pswd entry, 1 for ext entry */
171
158
/* can we access DISA without password? */
160
ast_log(LOG_DEBUG, "Context: %s\n",ourcontext);
172
162
if (!strcasecmp(tmp, "no-password"))
175
165
ast_log(LOG_DEBUG, "DISA no-password login success\n");
177
167
gettimeofday(&lastdigittime,NULL);
180
173
gettimeofday(&now,NULL);
207
200
if (f->frametype == AST_FRAME_VOICE) {
208
if (!i || (ast_ignore_pattern(ourcontext, exten) && k)) {
209
wf.frametype = AST_FRAME_VOICE;
210
wf.subclass = AST_FORMAT_ULAW;
211
wf.offset = AST_FRIENDLY_OFFSET;
213
wf.data = tone_block.buf;
214
wf.datalen = f->datalen;
215
make_tone_block(tone_block.buf, 350, 440, f->datalen, &x);
216
wf.samples = wf.datalen;
218
if (ast_write(chan, &wf))
220
ast_log(LOG_WARNING, "DISA Failed to write frame on %s\n",chan->name);
221
LOCAL_USER_REMOVE(u);
228
204
/* if not DTMF, just do it again */
289
267
/* password good, set to dial state */
290
ast_log(LOG_WARNING,"DISA on chan %s password is good\n",chan->name);
268
ast_log(LOG_DEBUG,"DISA on chan %s password is good\n",chan->name);
292
272
i = 0; /* re-set buffer pointer */
293
273
exten[sizeof(acctcode)] = 0;
294
strcpy(acctcode,exten);
274
strncpy(acctcode,exten, sizeof(acctcode) - 1);
296
276
ast_log(LOG_DEBUG,"Successful DISA log-in on chan %s\n",chan->name);
300
281
exten[i++] = j; /* save digit */
302
283
if (!k) continue; /* if getting password, continue doing it */
303
284
/* if this exists */
286
if (ast_ignore_pattern(ourcontext, exten)) {
291
ast_playtones_stop(chan);
305
295
/* if can do some more, do it */
306
if (!ast_matchmore_extension(chan,ourcontext,exten,1, chan->callerid))
296
if (!ast_matchmore_extension(chan,ourcontext,exten,1, chan->callerid)) {
311
302
if (k && ast_exists_extension(chan,ourcontext,exten,1, chan->callerid))
304
ast_playtones_stop(chan);
313
305
/* We're authenticated and have a valid extension */
314
306
if (ourcallerid && *ourcallerid)
316
308
if (chan->callerid) free(chan->callerid);
317
309
chan->callerid = strdup(ourcallerid);
319
strcpy(chan->exten,exten);
320
strcpy(chan->context,ourcontext);
321
strcpy(chan->accountcode,acctcode);
311
strncpy(chan->exten, exten, sizeof(chan->exten) - 1);
312
strncpy(chan->context, ourcontext, sizeof(chan->context) - 1);
313
strncpy(chan->accountcode, acctcode, sizeof(chan->accountcode) - 1);
322
314
chan->priority = 0;
323
315
ast_cdr_init(chan->cdr,chan);
324
316
LOCAL_USER_REMOVE(u);
330
/* something is invalid, give em reorder forever */
332
k = 0; /* k = 0 means busy tone, k = 1 means silence) */
333
i = 0; /* Number of samples we've done */
322
ast_indicate(chan,AST_CONTROL_CONGESTION);
323
/* something is invalid, give em reorder for several seconds */
325
while(time(NULL) < rstart + 10)
336
327
if (ast_waitfor(chan, -1) < 0)
338
329
f = ast_read(chan);
341
if (f->frametype == AST_FRAME_VOICE) {
342
wf.frametype = AST_FRAME_VOICE;
343
wf.subclass = AST_FORMAT_ULAW;
344
wf.offset = AST_FRIENDLY_OFFSET;
346
wf.data = tone_block.buf;
347
wf.datalen = f->datalen;
348
wf.samples = wf.datalen;
350
memset(tone_block.buf, 0x7f, wf.datalen);
352
make_tone_block(tone_block.buf,480.0, 620.0,wf.datalen, &x);
358
if (ast_write(chan, &wf))
360
ast_log(LOG_WARNING, "DISA Failed to write frame on %s\n",chan->name);
361
LOCAL_USER_REMOVE(u);
334
ast_playtones_stop(chan);
367
335
LOCAL_USER_REMOVE(u);