69 #define CALLERID_SPACE 2200.0 70 #define CALLERID_MARK 1200.0 71 #define SAS_FREQ 440.0 72 #define CAS_FREQ1 2130.0 73 #define CAS_FREQ2 2750.0 75 #define AST_CALLERID_UNKNOWN "<unknown>" 77 static 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)
81 for (x = 0; x <
len; x++) {
82 t = *cr1 * ddr1 - *ci1 * ddi1;
83 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
85 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
89 t = *cr2 * ddr2 - *ci2 * ddi2;
90 *ci2 = *cr2 * ddi2 + *ci2 * ddr2;
92 t = 2.0 - (*cr2 * *cr2 + *ci2 * *ci2);
95 buf[x] =
AST_LIN2X((*cr1 + *cr2) * 2048.0);
99 static inline void gen_tone(
unsigned char *
buf,
int len,
struct ast_format *codec,
float ddr1,
float ddi1,
float *cr1,
float *ci1)
103 for (x = 0; x <
len; x++) {
104 t = *cr1 * ddr1 - *ci1 * ddi1;
105 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
107 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
134 #ifdef INTEGER_CALLERID 147 if (cid_signalling == 2) {
169 if (cid_signalling == 2) {
209 if (strlen(cidstring) < 2) {
216 if (cidstring[0] ==
'B') {
218 code = atoi(&cidstring[1]);
224 ast_debug(1,
"Unknown DTMF code %d\n", code);
225 }
else if (cidstring[0] ==
'D' && cidstring[2] ==
'#') {
227 if (cidstring[1] ==
'1')
229 if (cidstring[1] ==
'2' || cidstring[1] ==
'3')
231 }
else if (cidstring[0] ==
'D' || cidstring[0] ==
'A') {
233 for (i = 1; i < strlen(cidstring); i++) {
234 if (cidstring[i] ==
'C' || cidstring[i] ==
'#')
236 if (isdigit(cidstring[i]))
237 number[i-1] = cidstring[i];
243 }
else if (isdigit(cidstring[0])) {
247 "parsing might be unreliable\n");
248 for (i = 0; i < strlen(cidstring); i++) {
249 if (isdigit(cidstring[i]))
250 number[i] = cidstring[i];
256 ast_debug(1,
"Unknown CID protocol, start digit '%c'\n", cidstring[0]);
279 gen_tones(outbuf + pos, len, codec,
casdr1,
casdi1,
casdr2,
casdi2, &cr1, &ci1, &cr2, &ci2);
283 static unsigned short calc_crc(
unsigned short crc,
unsigned char data)
285 unsigned int i, j,
org, dst;
289 for (i = 0; i < CHAR_BIT; i++) {
295 data = (
unsigned char) dst;
296 crc ^= (
unsigned int) data << (16 - CHAR_BIT);
297 for (j = 0; j < CHAR_BIT; j++) {
299 crc = (crc << 1) ^ 0x1021U ;
321 for (x = 0; x <
len; x++)
324 while (mylen >= 160) {
334 buf += (olen - mylen);
426 for (x = 0; x < cid->
pos;) {
536 memcpy(cid->
oldstuff, buf, mylen * 2);
559 for (x = 0; x <
len; x++)
561 while (mylen >= 160) {
568 buf += (olen - mylen);
596 if ((b == 0x04) || (b == 0x80) || (b == 0x06) || (b == 0x82)) {
610 if (cid->
pos >= 128) {
623 if ((b + cid->
cksum) & 0xff) {
635 if ((cid->
type == 0x80) || (cid->
type == 0x82)) {
638 for (x = 0; x < cid->
pos;) {
667 cid->
name[res] =
'\0';
693 }
else if (cid->
type == 0x6) {
697 }
else if (cid->
rawdata[2] == 0x6f) {
704 if (!strcmp(cid->
number,
"P")) {
711 if (!strcmp(cid->
name,
"P")) {
712 strcpy(cid->
name,
"");
715 strcpy(cid->
name,
"");
726 memcpy(cid->
oldstuff, buf, mylen * 2);
753 res = snprintf(ptr, size,
"\001\010%02d%02d%02d%02d", tm.
tm_mon + 1,
759 res = snprintf(ptr, size,
"\004\001O");
764 res = snprintf(ptr, size,
"\004\001P");
772 res = snprintf(ptr, size,
"\002%c", i);
775 for (x = 0; x < i; x++)
784 res = snprintf(ptr, size,
"\010\001O");
789 res = snprintf(ptr, size,
"\010\001P");
797 res = snprintf(ptr, size,
"\007%c", i);
800 for (x = 0; x < i; x++)
876 for (x = 0; x <
len; x++)
878 sum = (256 - (sum & 255));
881 for (x = 0; x < 4000; x++)
884 for (x = 0; x < 30; x++)
887 for (x = 0; x < 170; x++)
889 for (x = 0; x <
len; x++) {
893 for (x = 0; x < 50; x++)
912 for (x = 0; x < 4000; x++)
915 for (x = 0; x < 30; x++)
919 for (x = 0; x < 150; x++)
925 sum = 0x80 + strlen(msg);
927 for (x = 0; x <
len; x++) {
935 for (x = 0; x < 50; x++)
952 for (x = 0; n[x]; x++) {
972 if (!strchr(
"( )", n[x]))
992 for (x = 0; exten[x]; x++)
993 if (!strchr(valid, exten[x]))
1014 int quotes_stripped = 0;
1019 if (instr != input_str) {
1020 quotes_stripped = 1;
1024 if ((ls = strrchr(instr,
'<'))) {
1025 if ((le = strrchr(ls,
'>'))) {
1076 unknown =
"<unknown>";
1081 snprintf(buf, bufsiz,
"\"%s\" <%s>", name_buf, num);
1150 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1151 if (!strcasecmp(pres_types[index].
name, data)) {
1152 return pres_types[index].
value;
1168 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1169 if (pres_types[index].
value == data) {
1186 for (index = 0; index <
ARRAY_LEN(pres_types); ++index) {
1187 if (pres_types[index].
value == data) {
1188 return pres_types[index].
name;
1227 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1228 if (!strcasecmp(redirecting_reason_types[index].
name, data)) {
1229 return redirecting_reason_types[index].
value;
1240 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1241 if (redirecting_reason_types[index].
value == data) {
1242 return redirecting_reason_types[index].
description ?:
"Redirecting reason alias-bug";
1258 for (index = 0; index <
ARRAY_LEN(redirecting_reason_types); ++index) {
1259 if (redirecting_reason_types[index].
value == data->
code) {
1260 return redirecting_reason_types[index].
name;
1283 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1284 if (!strcasecmp(connected_line_source_types[index].
name, data)) {
1285 return connected_line_source_types[index].
value;
1296 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1297 if (connected_line_source_types[index].
value == data) {
1298 return connected_line_source_types[index].
description;
1309 for (index = 0; index <
ARRAY_LEN(connected_line_source_types); ++index) {
1310 if (connected_line_source_types[index].
value == data) {
1311 return connected_line_source_types[index].
name;
1338 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1339 if (!strcasecmp(party_name_charset_tbl[index].
name, data)) {
1340 return party_name_charset_tbl[index].
value;
1351 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1352 if (party_name_charset_tbl[index].
value == data) {
1364 for (index = 0; index <
ARRAY_LEN(party_name_charset_tbl); ++index) {
1365 if (party_name_charset_tbl[index].
value == data) {
1366 return party_name_charset_tbl[index].
name;
A-Law to Signed linear conversion.
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.
#define CID_UNKNOWN_NUMBER
static char exten[AST_MAX_EXTENSION]
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
static const struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
const char * ast_redirecting_reason_name(const struct ast_party_redirecting_reason *data)
Convert redirecting reason value to text code.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
Time-related functions and macros.
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 int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, struct ast_format *codec)
#define AST_PRES_USER_NUMBER_FAILED_SCREEN
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.
void callerid_get(struct callerid_state *cid, char **name, char **number, int *flags)
Extract info out of callerID state machine. Flags are listed above.
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)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define CID_MWI_TYPE_MDMF_FULL
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.
int fskmodem_init(fsk_data *fskd)
#define AST_PRES_NETWORK_NUMBER
int code
enum AST_REDIRECTING_REASON value for redirection
void callerid_free(struct callerid_state *cid)
This function frees callerid_state cid.
#define AST_PRES_RESTRICTED
#define ast_strlen_zero(foo)
void callerid_init(void)
Initialize stuff for inverse FFT.
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
General Asterisk PBX channel definitions.
#define AST_PRES_USER_NUMBER_UNSCREENED
const char * ast_redirecting_reason_describe(int data)
Convert redirecting reason value to explanatory string.
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_...
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Asterisk internal frame definitions.
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_party_name_charset_parse(const char *data)
Convert ast_party_name.char_set text code to value (used in config file parsing)
#define CID_PRIVATE_NUMBER
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, struct ast_format *codec)
Read samples into the state machine.
Redirecting reason information.
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
static void gen_tone(unsigned char *buf, int len, struct ast_format *codec, float ddr1, float ddi1, float *cr1, float *ci1)
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
int ast_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen)
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags)
int ast_connected_line_source_parse(const char *data)
Convert connected line update source text code to value (used in config file parsing) ...
char * str
a string value for the redirecting reason
void ast_shrink_phone_number(char *n)
Clean up phone string.
#define ast_calloc(num, len)
A wrapper for calloc()
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
static struct ast_codec unknown
const char * ast_connected_line_source_name(int data)
Convert connected line update source value to text code.
int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, struct ast_format *codec)
Read samples into the state machine.
#define AST_PRES_USER_NUMBER_PASSED_SCREEN
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
const char * ast_party_name_charset_describe(int data)
Convert ast_party_name.char_set value to explanatory string.
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) ...
#define CID_MWI_TYPE_MDMF
char * ast_callerid_merge(char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
int ast_isphonenumber(const char *n)
Check if a string consists only of digits and + #.
struct callerid_state * callerid_new(int cid_signalling)
Create a callerID state machine.
#define AST_PRES_UNAVAILABLE
const char * ast_party_name_charset_str(int data)
Convert ast_party_name.char_set value to text code.
static unsigned short calc_crc(unsigned short crc, unsigned char data)
int ast_callerid_parse(char *input_str, char **name, char **location)
Destructively parse inbuf into name and location (or number)
#define DEBUG_ATLEAST(level)
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
int ast_redirecting_reason_parse(const char *data)
Convert redirecting reason text code to value (used in config file parsing)
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) ...
const char * ast_connected_line_source_describe(int data)
Convert connected line update source value to explanatory string.
const char * ast_named_caller_presentation(int data)
Convert caller ID pres value to text code.