70 #define CALLERID_SPACE 2200.0
71 #define CALLERID_MARK 1200.0
72 #define SAS_FREQ 440.0
73 #define CAS_FREQ1 2130.0
74 #define CAS_FREQ2 2750.0
76 #define AST_CALLERID_UNKNOWN "<unknown>"
78 static inline void gen_tones(
unsigned char *buf,
int len,
format_t 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);
96 buf[x] =
AST_LIN2X((*cr1 + *cr2) * 2048.0);
100 static inline void gen_tone(
unsigned char *buf,
int len,
format_t codec,
float ddr1,
float ddi1,
float *cr1,
float *ci1)
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) {
210 if (strlen(cidstring) < 2) {
217 if (cidstring[0] ==
'B') {
219 code = atoi(&cidstring[1]);
225 ast_debug(1,
"Unknown DTMF code %d\n", code);
226 }
else if (cidstring[0] ==
'D' && cidstring[2] ==
'#') {
228 if (cidstring[1] ==
'1')
230 if (cidstring[1] ==
'2' || cidstring[1] ==
'3')
232 }
else if (cidstring[0] ==
'D' || cidstring[0] ==
'A') {
234 for (i = 1; i < strlen(cidstring); i++) {
235 if (cidstring[i] ==
'C' || cidstring[i] ==
'#')
237 if (isdigit(cidstring[i]))
238 number[i-1] = cidstring[i];
244 }
else if (isdigit(cidstring[0])) {
248 "parsing might be unreliable\n");
249 for (i = 0; i < strlen(cidstring); i++) {
250 if (isdigit(cidstring[i]))
251 number[i] = cidstring[i];
257 ast_debug(1,
"Unknown CID protocol, start digit '%c'\n", cidstring[0]);
274 gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1);
280 gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2);
284 static unsigned short calc_crc(
unsigned short crc,
unsigned char data)
286 unsigned int i, j,
org, dst;
290 for (i = 0; i < CHAR_BIT; i++) {
296 data = (
unsigned char) dst;
297 crc ^= (
unsigned int) data << (16 - CHAR_BIT);
298 for (j = 0; j < CHAR_BIT; j++) {
300 crc = (crc << 1) ^ 0x1021U ;
322 for (x = 0; x <
len; x++)
325 while (mylen >= 160) {
335 buf += (olen - mylen);
427 for (x = 0; x < cid->
pos;) {
537 memcpy(cid->
oldstuff, buf, mylen * 2);
560 for (x = 0; x <
len; x++)
562 while (mylen >= 160) {
569 buf += (olen - mylen);
597 if ((b == 0x04) || (b == 0x80) || (b == 0x06) || (b == 0x82)) {
611 if (cid->
pos >= 128) {
624 if ((b + cid->
cksum) & 0xff) {
636 if ((cid->
type == 0x80) || (cid->
type == 0x82)) {
639 for (x = 0; x < cid->
pos;) {
668 cid->
name[res] =
'\0';
694 }
else if (cid->
type == 0x6) {
698 }
else if (cid->
rawdata[2] == 0x6f) {
705 if (!strcmp(cid->
number,
"P")) {
712 if (!strcmp(cid->
name,
"P")) {
713 strcpy(cid->
name,
"");
716 strcpy(cid->
name,
"");
727 memcpy(cid->
oldstuff, buf, mylen * 2);
754 res = snprintf(ptr, size,
"\001\010%02d%02d%02d%02d", tm.
tm_mon + 1,
760 res = snprintf(ptr, size,
"\004\001O");
765 res = snprintf(ptr, size,
"\004\001P");
773 res = snprintf(ptr, size,
"\002%c", i);
776 for (x = 0; x < i; x++)
785 res = snprintf(ptr, size,
"\010\001O");
790 res = snprintf(ptr, size,
"\010\001P");
798 res = snprintf(ptr, size,
"\007%c", i);
801 for (x = 0; x < i; x++)
812 const char*
name,
const char*
number,
int flags)
877 for (x = 0; x <
len; x++)
879 sum = (256 - (sum & 255));
882 for (x = 0; x < 4000; x++)
885 for (x = 0; x < 30; x++)
888 for (x = 0; x < 170; x++)
890 for (x = 0; x <
len; x++) {
894 for (x = 0; x < 50; x++)
913 for (x = 0; x < 4000; x++)
916 for (x = 0; x < 30; x++)
920 for (x = 0; x < 150; x++)
926 sum = 0x80 + strlen(msg);
928 for (x = 0; x <
len; x++) {
936 for (x = 0; x < 50; x++)
953 for (x = 0; n[x]; x++) {
973 if (!strchr(
"( )", n[x]))
993 for (x = 0; exten[x]; x++)
994 if (!strchr(valid, exten[x]))
1015 int quotes_stripped = 0;
1020 if (instr != input_str) {
1021 quotes_stripped = 1;
1025 if ((ls = strrchr(instr,
'<'))) {
1026 if ((le = strrchr(ls,
'>'))) {
1077 unknown =
"<unknown>";
1082 snprintf(buf, bufsiz,
"\"%s\" <%s>", name_buf, num);
1096 char *l = NULL, *n = NULL;
1151 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1152 if (!strcasecmp(pres_types[index].
name, data)) {
1153 return pres_types[index].
value;
1169 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1170 if (pres_types[index].
value == data) {
1187 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1188 if (pres_types[index].
value == data) {
1189 return pres_types[index].
name;
1218 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1219 if (!strcasecmp(redirecting_reason_types[index].
name, data)) {
1220 return redirecting_reason_types[index].
value;
1231 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1232 if (redirecting_reason_types[index].
value == data) {
1233 return redirecting_reason_types[index].
description;
1244 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1245 if (redirecting_reason_types[index].
value == data) {
1246 return redirecting_reason_types[index].
name;
1269 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1270 if (!strcasecmp(connected_line_source_types[index].
name, data)) {
1271 return connected_line_source_types[index].
value;
1282 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1283 if (connected_line_source_types[index].
value == data) {
1284 return connected_line_source_types[index].
description;
1295 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1296 if (connected_line_source_types[index].
value == data) {
1297 return connected_line_source_types[index].
name;
1324 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1325 if (!strcasecmp(party_name_charset_tbl[index].
name, data)) {
1326 return party_name_charset_tbl[index].
value;
1337 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1338 if (party_name_charset_tbl[index].
value == data) {
1350 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1351 if (party_name_charset_tbl[index].
value == data) {
1352 return party_name_charset_tbl[index].
name;
A-Law to Signed linear conversion.
#define CID_UNKNOWN_NUMBER
static char exten[AST_MAX_EXTENSION]
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
const char * ast_named_caller_presentation(int data)
Convert caller ID pres value to text code.
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, format_t codec)
Asterisk main include file. File version handling, generic pbx functions.
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_split(const char *src, char *name, int namelen, char *num, int numlen)
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
const char * ast_connected_line_source_name(int data)
Convert connected line update source value to text code.
int ast_callerid_vmwi_generate(unsigned char *buf, int active, int type, format_t codec, const char *name, const char *number, int flags)
Generate message waiting indicator.
int ast_redirecting_reason_parse(const char *data)
Convert redirecting reason text code to value (used in config file parsing)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
#define AST_PRES_USER_NUMBER_FAILED_SCREEN
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define CID_MWI_TYPE_MDMF_FULL
int fskmodem_init(fsk_data *fskd)
int ast_is_shrinkable_phonenumber(const char *exten)
Check if a string consists only of digits and and + # ( ) - . (meaning it can be cleaned with ast_shr...
#define AST_PRES_NETWORK_NUMBER
const char * ast_redirecting_reason_name(int data)
Convert redirecting reason value to text code.
void callerid_get(struct callerid_state *cid, char **number, char **name, int *flags)
Extract info out of callerID state machine. Flags are listed above.
int ast_callerid_generate(unsigned char *buf, const char *name, const char *number, format_t codec)
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format) ...
#define AST_PRES_RESTRICTED
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
#define ast_debug(level,...)
Log a DEBUG message.
u-Law to Signed linear conversion
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
void callerid_init(void)
CallerID Initialization.
General Asterisk PBX channel definitions.
#define AST_PRES_USER_NUMBER_UNSCREENED
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Asterisk internal frame definitions.
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
int ast_party_name_charset_parse(const char *data)
Convert ast_party_name.char_set text code to value (used in config file parsing)
int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int samples, format_t codec)
Read samples into the state machine.
int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int samples, format_t codec)
Read samples into the state machine.
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
#define CID_PRIVATE_NUMBER
#define ast_strdupa(s)
duplicate a string in memory from the stack
int callerid_generate(unsigned char *buf, const char *number, const char *name, int flags, int callwaiting, format_t codec)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags)
static void gen_tones(unsigned char *buf, int len, format_t codec, float ddr1, float ddi1, float ddr2, float ddi2, float *cr1, float *ci1, float *cr2, float *ci2)
const char * ast_redirecting_reason_describe(int data)
Convert redirecting reason value to explanatory string.
int ast_gen_cas(unsigned char *outbuf, int sas, int len, format_t codec)
Generate a CAS (CPE Alert Signal) tone for 'n' samples.
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
int ast_callerid_callwaiting_generate(unsigned char *buf, const char *name, const char *number, format_t codec)
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm) ...
int ast_isphonenumber(const char *n)
Check if a string consists only of digits and + #.
static struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
const char * ast_party_name_charset_str(int data)
Convert ast_party_name.char_set value to text code.
#define AST_PRES_USER_NUMBER_PASSED_SCREEN
void callerid_free(struct callerid_state *cid)
This function frees callerid_state cid.
static struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
static void gen_tone(unsigned char *buf, int len, format_t codec, float ddr1, float ddi1, float *cr1, float *ci1)
#define CID_MWI_TYPE_MDMF
const char * ast_connected_line_source_describe(int data)
Convert connected line update source value to explanatory string.
static struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
#define AST_PRES_UNAVAILABLE
static unsigned short calc_crc(unsigned short crc, unsigned char data)
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...
struct callerid_state * callerid_new(int cid_signalling)
Create a callerID state machine.
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
const char * ast_party_name_charset_describe(int data)
Convert ast_party_name.char_set value to explanatory string.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)