From 909f17e6cac6b1b876169ade5755c1ef9fdc5efb Mon Sep 17 00:00:00 2001 From: markster Date: Fri, 29 Nov 2002 16:43:28 +0000 Subject: Version 0.3.0 from FTP git-svn-id: http://svn.digium.com/svn/asterisk/trunk@558 f38db490-d61c-443f-a65b-d21fe96a405b --- callerid.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 143 insertions(+), 42 deletions(-) (limited to 'callerid.c') diff --git a/callerid.c b/callerid.c index 898396d86..f1827b76b 100755 --- a/callerid.c +++ b/callerid.c @@ -21,12 +21,11 @@ #include #include #include +#include +#include #include #include #include -#include "sas.h" -#include "cas.h" - struct callerid_state { fsk_data fskd; @@ -46,9 +45,51 @@ struct callerid_state { float cid_dr[4], cid_di[4]; float clidsb = 8000.0 / 1200.0; +float sasdr, sasdi; +float casdr1, casdi1, casdr2, casdi2; #define CALLERID_SPACE 2200.0 /* 2200 hz for "0" */ #define CALLERID_MARK 1200.0 /* 1200 hz for "1" */ +#define SAS_FREQ 440.0 +#define CAS_FREQ1 2130.0 +#define CAS_FREQ2 2750.0 + +static inline void gen_tones(unsigned char *buf, int len, int codec, float ddr1, float ddi1, float ddr2, float ddi2, float *cr1, float *ci1, float *cr2, float *ci2) +{ + int x; + float t; + for (x=0;xnumber; } -int ast_gen_cas(unsigned char *outbuf, int sendsas, int len) +int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, int codec) { int pos = 0; - int cnt; int saslen=2400; + float cr1 = 1.0; + float ci1 = 0.0; + float cr2 = 1.0; + float ci2 = 0.0; if (sendsas) { if (len < saslen) return -1; - while(saslen) { - cnt = saslen; - if (cnt > sizeof(sas)) - cnt = sizeof(sas); - memcpy(outbuf + pos, sas, cnt); - pos += cnt; - len -= cnt; - saslen -= cnt; - } - } - while(len) { - cnt = len; - if (cnt > sizeof(cas)) - cnt = sizeof(cas); - memcpy(outbuf + pos, cas, cnt); - pos += cnt; - len -= cnt; + gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1); + len -= saslen; + pos += saslen; + cr2 = cr1; + ci2 = ci1; } + gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2); return 0; } -int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len) +int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, int codec) { int mylen = len; int olen; @@ -145,7 +184,7 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len) memcpy(buf, cid->oldstuff, cid->oldlen); mylen += cid->oldlen/2; for (x=0;xoldlen/2] = AST_MULAW(ubuf[x]); + buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]); while(mylen >= 80) { olen = mylen; res = fsk_serie(&cid->fskd, buf, &mylen, &b); @@ -282,7 +321,7 @@ void callerid_free(struct callerid_state *cid) free(cid); } -static void callerid_genmsg(char *msg, int size, char *number, char *name, int flags) +static int callerid_genmsg(char *msg, int size, char *number, char *name, int flags) { time_t t; struct tm *tm; @@ -311,9 +350,9 @@ static void callerid_genmsg(char *msg, int size, char *number, char *name, int f size -= res; ptr += res; } else { - /* Send up to 10 digits of number MAX */ + /* Send up to 16 digits of number MAX */ i = strlen(number); - if (i > 10) i = 10; + if (i > 16) i = 16; res = snprintf(ptr, size, "\002%c", i); size -= res; ptr += res; @@ -335,7 +374,7 @@ static void callerid_genmsg(char *msg, int size, char *number, char *name, int f size -= res; ptr += res; } else { - /* Send up to 10 digits of number MAX */ + /* Send up to 16 digits of name MAX */ i = strlen(name); if (i > 16) i = 16; res = snprintf(ptr, size, "\007%c", i); @@ -347,19 +386,80 @@ static void callerid_genmsg(char *msg, int size, char *number, char *name, int f ptr += i; size -= i; } + return (ptr - msg); } -int callerid_generate(unsigned char *buf, char *number, char *name, int flags, int callwaiting) +int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec) +{ + unsigned char msg[256]; + int len=0; + int sum; + int x; + int bytes = 0; + float cr = 1.0; + float ci = 0.0; + float scont = 0.0; + if (mdmf) { + /* MDMF Message waiting */ + msg[len++] = 0x82; + /* Length is 3 */ + msg[len++] = 3; + /* IE is "Message Waiting Parameter" */ + msg[len++] = 0xb; + /* Length of IE is one */ + msg[len++] = 1; + /* Active or not */ + if (active) + msg[len++] = 0xff; + else + msg[len++] = 0x00; + } else { + /* SDMF Message waiting */ + msg[len++] = 0x6; + /* Length is 3 */ + msg[len++] = 3; + if (active) { + msg[len++] = 0x42; + msg[len++] = 0x42; + msg[len++] = 0x42; + } else { + msg[len++] = 0x6f; + msg[len++] = 0x6f; + msg[len++] = 0x6f; + } + } + sum = 0; + for (x=0;x