70#define CALLERID_SPACE 2200.0
71#define CALLERID_MARK 1200.0
73#define CAS_FREQ1 2130.0
74#define CAS_FREQ2 2750.0
76#define AST_CALLERID_UNKNOWN "<unknown>"
78static inline void gen_tones(
unsigned char *
buf,
int len,
struct ast_format *codec,
float ddr1,
float ddi1,
float ddr2,
float ddi2,
float *cr1,
float *ci1,
float *cr2,
float *ci2)
82 for (x = 0; x <
len; x++) {
83 t = *cr1 * ddr1 - *ci1 * ddi1;
84 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
86 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
90 t = *cr2 * ddr2 - *ci2 * ddi2;
91 *ci2 = *cr2 * ddi2 + *ci2 * ddr2;
93 t = 2.0 - (*cr2 * *cr2 + *ci2 * *ci2);
104 for (x = 0; x <
len; x++) {
105 t = *cr1 * ddr1 - *ci1 * ddi1;
106 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
108 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
135#ifdef INTEGER_CALLERID
148 if (cid_signalling == 2) {
170 if (cid_signalling == 2) {
219 if (strlen(cidstring) < 2) {
226 if (cidstring[0] ==
'B') {
228 code = atoi(&cidstring[1]);
234 ast_debug(1,
"Unknown DTMF code %d\n", code);
235 }
else if (cidstring[0] ==
'D' && cidstring[2] ==
'#') {
237 if (cidstring[1] ==
'1')
239 if (cidstring[1] ==
'2' || cidstring[1] ==
'3')
241 }
else if (cidstring[0] ==
'D' || cidstring[0] ==
'A') {
243 for (i = 1; i < strlen(cidstring); i++) {
244 if (cidstring[i] ==
'C' || cidstring[i] ==
'#')
246 if (isdigit(cidstring[i]))
247 number[i-1] = cidstring[i];
253 }
else if (isdigit(cidstring[0])) {
257 "parsing might be unreliable\n");
258 for (i = 0; i < strlen(cidstring); i++) {
259 if (isdigit(cidstring[i]))
266 ast_debug(1,
"Unknown CID protocol, start digit '%c'\n", cidstring[0]);
289 gen_tones(outbuf +
pos,
len, codec,
casdr1,
casdi1,
casdr2,
casdi2, &cr1, &ci1, &cr2, &ci2);
293static unsigned short calc_crc(
unsigned short crc,
unsigned char data)
295 unsigned int i, j,
org, dst;
299 for (i = 0; i < CHAR_BIT; i++) {
305 data = (
unsigned char) dst;
306 crc ^= (
unsigned int) data << (16 - CHAR_BIT);
307 for (j = 0; j < CHAR_BIT; j++) {
309 crc = (
crc << 1) ^ 0x1021U ;
331 for (x = 0; x <
len; x++)
334 while (mylen >= 160) {
344 buf += (olen - mylen);
436 for (x = 0; x < cid->
pos;) {
557 case 0x1:
return "Date/Time";
558 case 0x2:
return "Caller Number";
559 case 0x3:
return "DNIS";
560 case 0x4:
return "Reason For Absence of Number";
561 case 0x5:
return "Reason For Redirection";
562 case 0x6:
return "Call Qualifier";
563 case 0x7:
return "Name";
564 case 0x8:
return "Reason For Absence of Name";
565 case 0xB:
return "Message Waiting";
566 default:
return "Unknown";
584 for (x = 0; x <
len; x++)
586 while (mylen >= 160) {
593 buf += (olen - mylen);
621 if ((
b == 0x04) || (
b == 0x80) || (
b == 0x06) || (
b == 0x82)) {
635 if (cid->
pos >= 128) {
648 if ((
b + cid->
cksum) & 0xff) {
661 if ((cid->
type == 0x80) || (cid->
type == 0x82)) {
663 ast_debug(6,
"%s Caller*ID spill received\n", cid->
type == 0x80 ?
"MDMF" :
"MDMF Message Waiting");
665 for (x = 0; x < cid->
pos;) {
711 switch (*(cid->
rawdata + x + 1)) {
734 if (res == 1 && *(cid->
rawdata + x + 1) ==
'L') {
736 }
else if (res >= 1) {
737 ast_debug(2,
"Invalid value (len %d) received for Call Qualifier: '%c'\n", res, *(cid->
rawdata + x + 1));
748 cid->
name[res] =
'\0';
774 }
else if (cid->
type == 0x6) {
776 ast_debug(6,
"VMWI SDMF Caller*ID spill received\n");
779 }
else if (cid->
rawdata[2] == 0x6f) {
784 ast_debug(6,
"SDMF Caller*ID spill received\n");
787 if (!strcmp(cid->
number,
"P")) {
788 ast_debug(6,
"Caller*ID number is private\n");
791 }
else if (!strcmp(cid->
number,
"O")) {
792 ast_debug(6,
"Caller*ID number is out of area\n");
796 ast_debug(6,
"No Caller*ID number provided, and no reason provided for its absence\n");
802 if (!strcmp(cid->
name,
"P")) {
803 ast_debug(6,
"Caller*ID name is private\n");
804 strcpy(cid->
name,
"");
806 }
else if (!strcmp(cid->
name,
"O")) {
807 ast_debug(6,
"Caller*ID name is out of area\n");
808 strcpy(cid->
name,
"");
811 ast_debug(6,
"No Caller*ID name provided, and no reason provided for its absence\n");
812 strcpy(cid->
name,
"");
853 res = snprintf(ptr, size,
"\001\010%02d%02d%02d%02d", tm.
tm_mon + 1,
860 res = snprintf(ptr, size,
"\004\001O");
865 res = snprintf(ptr, size,
"\004\001P");
873 res = snprintf(ptr, size,
"\002%c", i);
876 for (x = 0; x < i; x++)
890 res = snprintf(ptr, size,
"\010\001O");
895 res = snprintf(ptr, size,
"\010\001P");
903 res = snprintf(ptr, size,
"\007%c", i);
906 for (x = 0; x < i; x++)
915 res = snprintf(ptr, size,
"\006\001L");
924 if (redirecting >= 0) {
926 switch (redirecting) {
928 res = snprintf(ptr, size,
"\005\001\001");
931 res = snprintf(ptr, size,
"\005\001\002");
934 res = snprintf(ptr, size,
"\005\001\003");
937 res = snprintf(ptr, size,
"\005\001\004");
940 res = snprintf(ptr, size,
"\005\001\005");
1017 for (x = 0; x <
len; x++)
1019 sum = (256 - (sum & 255));
1022 for (x = 0; x < 4000; x++)
1025 for (x = 0; x < 30; x++)
1028 for (x = 0; x < 170; x++)
1030 for (x = 0; x <
len; x++) {
1034 for (x = 0; x < 50; x++)
1045 int flags,
int format,
int callwaiting,
struct ast_format *codec)
1052 int flags,
int format,
int callwaiting,
struct ast_format *codec,
const char *
tz)
1066 for (x = 0; x < 4000; x++)
1069 for (x = 0; x < 30; x++)
1073 for (x = 0; x < 150; x++)
1079 sum = 0x80 + strlen(msg);
1081 for (x = 0; x <
len; x++) {
1089 for (x = 0; x < 50; x++)
1106 for (x = 0; n[x]; x++) {
1126 if (!strchr(
"( )", n[x]))
1146 for (x = 0; exten[x]; x++)
1147 if (!strchr(valid, exten[x]))
1168 int quotes_stripped = 0;
1173 if (instr != input_str) {
1174 quotes_stripped = 1;
1178 if ((ls = strrchr(instr,
'<'))) {
1179 if ((le = strrchr(ls,
'>'))) {
1209 const char *ddn,
int redirecting,
int pres,
int qualifier,
int format,
int callwaiting,
struct ast_format *codec,
const char *
tz)
1213 ast_debug(1,
"Caller ID Type %s: Number: %s, Name: %s, DDN: %s, Redirecting Reason: %s, Pres: %s, Qualifier: %s, Format: %s\n",
1239 return __ast_callerid_generate(
buf,
name,
number,
"", -1, 0, 0,
CID_TYPE_MDMF, 0, codec,
NULL);
1244 return __ast_callerid_generate(
buf,
name,
number,
"", -1, 0, 0,
CID_TYPE_MDMF, 1, codec,
NULL);
1248 const char *ddn,
int redirecting,
int pres,
int qualifier,
int format,
struct ast_format *codec)
1250 return __ast_callerid_generate(
buf,
name,
number, ddn, redirecting, pres, qualifier, format, 0, codec,
NULL);
1254 const char *ddn,
int redirecting,
int pres,
int qualifier,
struct ast_format *codec)
1257 return __ast_callerid_generate(
buf,
name,
number, ddn, redirecting, pres, qualifier,
CID_TYPE_MDMF, 1, codec,
NULL);
1261 const char *ddn,
int redirecting,
int pres,
int qualifier,
int format,
struct ast_format *codec,
const char *
tz)
1263 return __ast_callerid_generate(
buf,
name,
number, ddn, redirecting, pres, qualifier, format, 0, codec,
tz);
1267 const char *ddn,
int redirecting,
int pres,
int qualifier,
struct ast_format *codec,
const char *
tz)
1270 return __ast_callerid_generate(
buf,
name,
number, ddn, redirecting, pres, qualifier,
CID_TYPE_MDMF, 1, codec,
tz);
1281 snprintf(
buf, bufsiz,
"\"%s\" <%s>", name_buf, num);
A-Law to Signed linear conversion.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_calloc(num, len)
A wrapper for calloc()
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
int ast_callerid_callwaiting_full_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec)
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
const char * ast_connected_line_source_describe(int data)
Convert connected line update source value to explanatory string.
int ast_callerid_parse(char *input_str, char **name, char **location)
Destructively parse inbuf into name and location (or number)
int ast_callerid_full_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec)
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags, int format, const char *ddn, int redirecting, const char *tz)
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
int ast_callerid_vmwi_generate(unsigned char *buf, int active, int type, struct ast_format *codec, const char *name, const char *number, int flags)
Generate message waiting indicator.
static unsigned short calc_crc(unsigned short crc, unsigned char data)
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
int callerid_generate(unsigned char *buf, const char *number, const char *name, int flags, int callwaiting, struct ast_format *codec)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
void callerid_free(struct callerid_state *cid)
This function frees callerid_state cid.
void callerid_get_with_redirecting(struct callerid_state *cid, char **name, char **number, int *flags, int *redirecting)
Extract info out of callerID state machine. Flags are listed above.
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
int ast_gen_cas(unsigned char *outbuf, int sendsas, int len, struct ast_format *codec)
Generate a CAS (CPE Alert Signal) tone for 'n' samples.
const char * ast_party_name_charset_describe(int data)
Convert ast_party_name.char_set value to explanatory string.
static void gen_tone(unsigned char *buf, int len, struct ast_format *codec, float ddr1, float ddi1, float *cr1, float *ci1)
const char * ast_redirecting_reason_name(const struct ast_party_redirecting_reason *data)
Convert redirecting reason value to text code.
int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, struct ast_format *codec)
Read samples into the state machine.
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, int callwaiting, struct ast_format *codec, const char *tz)
void ast_shrink_phone_number(char *n)
Clean up phone string.
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
int ast_callerid_callwaiting_generate(unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
static void gen_tones(unsigned char *buf, int len, struct ast_format *codec, float ddr1, float ddi1, float ddr2, float ddi2, float *cr1, float *ci1, float *cr2, float *ci2)
const char * ast_party_name_charset_str(int data)
Convert ast_party_name.char_set value to text code.
struct callerid_state * callerid_new(int cid_signalling)
Create a callerID state machine.
void callerid_init(void)
Initialize stuff for inverse FFT.
static const char * mdmf_param_name(int param)
int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, struct ast_format *codec)
Read samples into the state machine.
int callerid_full_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
int ast_party_name_charset_parse(const char *data)
Convert ast_party_name.char_set text code to value (used in config file parsing)
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
int ast_isphonenumber(const char *n)
Check if a string consists only of digits and + #.
const char * ast_redirecting_reason_describe(int data)
Convert redirecting reason value to explanatory string.
int ast_redirecting_reason_parse(const char *data)
Convert redirecting reason text code to value (used in config file parsing)
const char * ast_connected_line_source_name(int data)
Convert connected line update source value to text code.
const char * ast_named_caller_presentation(int data)
Convert caller ID pres value to text code.
static const struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
int ast_connected_line_source_parse(const char *data)
Convert connected line update source text code to value (used in config file parsing)
int ast_callerid_full_tz_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec, const char *tz)
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
int callerid_full_tz_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec, const char *tz)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
int ast_is_shrinkable_phonenumber(const char *exten)
Check if a string consists only of digits and + # ( ) - . (meaning it can be cleaned with ast_shrink_...
int ast_callerid_generate(unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
int ast_callerid_callwaiting_full_tz_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec, const char *tz)
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
void callerid_get(struct callerid_state *cid, char **name, char **number, int *flags)
Extract info out of callerID state machine. Flags are listed above.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define CID_UNKNOWN_NUMBER
#define AST_PRES_USER_NUMBER_UNSCREENED
#define AST_PRES_UNAVAILABLE
#define AST_PRES_USER_NUMBER_PASSED_SCREEN
#define AST_PRES_RESTRICTED
#define CID_MWI_TYPE_MDMF
@ AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER
@ AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN
@ AST_CONNECTED_LINE_UPDATE_SOURCE_DIVERSION
@ AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER_ALERTING
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
#define AST_PRES_NETWORK_NUMBER
@ AST_REDIRECTING_REASON_AWAY
@ AST_REDIRECTING_REASON_UNKNOWN
@ AST_REDIRECTING_REASON_SEND_TO_VM
@ AST_REDIRECTING_REASON_NO_ANSWER
@ AST_REDIRECTING_REASON_DO_NOT_DISTURB
@ AST_REDIRECTING_REASON_FOLLOW_ME
@ AST_REDIRECTING_REASON_DEFLECTION
@ AST_REDIRECTING_REASON_UNAVAILABLE
@ AST_REDIRECTING_REASON_UNCONDITIONAL
@ AST_REDIRECTING_REASON_CALL_FWD_DTE
@ AST_REDIRECTING_REASON_OUT_OF_ORDER
@ AST_REDIRECTING_REASON_TIME_OF_DAY
@ AST_REDIRECTING_REASON_USER_BUSY
#define CID_PRIVATE_NUMBER
#define CID_MWI_TYPE_MDMF_FULL
#define AST_PRES_USER_NUMBER_FAILED_SCREEN
General Asterisk PBX channel definitions.
@ AST_PARTY_CHAR_SET_UNKNOWN
@ AST_PARTY_CHAR_SET_ISO8859_4
@ AST_PARTY_CHAR_SET_WITHDRAWN
@ AST_PARTY_CHAR_SET_ISO8859_5
@ AST_PARTY_CHAR_SET_ISO8859_7
@ AST_PARTY_CHAR_SET_ISO8859_2
@ AST_PARTY_CHAR_SET_ISO8859_1
@ AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING
@ AST_PARTY_CHAR_SET_ISO10646_BMPSTRING
@ AST_PARTY_CHAR_SET_ISO8859_3
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
Retrieve a serial byte into outbyte. Buffer is a pointer into a series of shorts and len records the ...
int fskmodem_init(fsk_data *fskd)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Asterisk internal frame definitions.
#define DEBUG_ATLEAST(level)
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
static force_inline int attribute_pure ast_strlen_zero(const char *s)
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Redirecting reason information.
int code
enum AST_REDIRECTING_REASON value for redirection
char * str
a string value for the redirecting reason
static struct ast_codec unknown
Time-related functions and macros.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
u-Law to Signed linear conversion
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.