#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <ctype.h>
#include "asterisk.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/callerid.h"
#include "asterisk/logger.h"
#include "asterisk/fskmodem.h"
#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
struct | callerid_state |
Defines | |
#define | AST_CALLERID_UNKNOWN "<unknown>" |
#define | CALLERID_MARK 1200.0 |
#define | CALLERID_SPACE 2200.0 |
#define | CAS_FREQ1 2130.0 |
#define | CAS_FREQ2 2750.0 |
#define | SAS_FREQ 440.0 |
Functions | |
static int | __ast_callerid_generate (unsigned char *buf, char *name, char *number, int callwaiting, int codec) |
int | ast_callerid_callwaiting_generate (unsigned char *buf, char *name, char *number, int codec) |
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm) See ast_callerid_generate() for other details. | |
int | ast_callerid_generate (unsigned char *buf, char *name, char *number, int codec) |
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format). | |
char * | ast_callerid_merge (char *buf, int bufsiz, const char *name, const char *num, const char *unknown) |
int | ast_callerid_parse (char *instr, char **name, char **location) |
Destructively parse inbuf into name and location (or number) Parses callerid stream from inbuf and changes into useable form, outputed in name and location. | |
int | ast_callerid_split (const char *buf, char *name, int namelen, char *num, int numlen) |
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, int codec) |
int | ast_isphonenumber (char *n) |
Check if a string consists only of digits. | |
int | ast_parse_caller_presentation (const char *data) |
Convert caller ID text code to value used in config file parsing. | |
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... | |
int | callerid_feed (struct callerid_state *cid, unsigned char *ubuf, int len, int codec) |
Read samples into the state machine. | |
void | callerid_free (struct callerid_state *cid) |
Free a callerID state. | |
int | callerid_generate (unsigned char *buf, char *number, char *name, int flags, int callwaiting, int codec) |
Generates a CallerID FSK stream in ulaw format suitable for transmission. | |
static int | callerid_genmsg (char *msg, int size, char *number, char *name, int flags) |
void | callerid_get (struct callerid_state *cid, char **name, char **number, int *flags) |
Extract info out of callerID state machine. Flags are listed above. | |
void | callerid_get_dtmf (char *cidstring, char *number, int *flags) |
void | callerid_init (void) |
CallerID Initialization. | |
callerid_state * | callerid_new (int cid_signalling) |
Create a callerID state machine. | |
static void | gen_tone (unsigned char *buf, int len, int codec, float ddr1, float ddi1, float *cr1, float *ci1) |
static 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 | vmwi_generate (unsigned char *buf, int active, int mdmf, int codec) |
Generate message waiting indicator (stutter tone). | |
Variables | |
float | casdi1 |
float | casdi2 |
float | casdr1 |
float | casdr2 |
float | cid_di [4] |
float | cid_dr [4] |
float | clidsb = 8000.0 / 1200.0 |
struct { | |
char * description | |
char * name | |
int val | |
} | pres_types [] |
float | sasdi |
float | sasdr |
Definition in file callerid.c.
#define AST_CALLERID_UNKNOWN "<unknown>" |
Definition at line 73 of file callerid.c.
#define CALLERID_MARK 1200.0 |
#define CALLERID_SPACE 2200.0 |
#define CAS_FREQ1 2130.0 |
#define CAS_FREQ2 2750.0 |
#define SAS_FREQ 440.0 |
static int __ast_callerid_generate | ( | unsigned char * | buf, | |
char * | name, | |||
char * | number, | |||
int | callwaiting, | |||
int | codec | |||
) | [static] |
Definition at line 687 of file callerid.c.
References ast_strlen_zero(), and callerid_generate().
Referenced by ast_callerid_callwaiting_generate(), and ast_callerid_generate().
00688 { 00689 if (ast_strlen_zero(name)) 00690 name = NULL; 00691 if (ast_strlen_zero(number)) 00692 number = NULL; 00693 return callerid_generate(buf, number, name, 0, callwaiting, codec); 00694 }
int ast_callerid_callwaiting_generate | ( | unsigned char * | buf, | |
char * | name, | |||
char * | number, | |||
int | codec | |||
) |
Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm) See ast_callerid_generate() for other details.
Definition at line 701 of file callerid.c.
References __ast_callerid_generate().
Referenced by send_cwcidspill().
00702 { 00703 return __ast_callerid_generate(buf, name, number, 1, codec); 00704 }
int ast_callerid_generate | ( | unsigned char * | buf, | |
char * | name, | |||
char * | number, | |||
int | codec | |||
) |
Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format).
buf | buffer for output samples. See callerid_generate() for details regarding buffer. | |
name | Caller-ID Name | |
number | Caller-ID Number | |
codec | Asterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Definition at line 696 of file callerid.c.
References __ast_callerid_generate().
Referenced by zt_call().
00697 { 00698 return __ast_callerid_generate(buf, name, number, 0, codec); 00699 }
char* ast_callerid_merge | ( | char * | buf, | |
int | bufsiz, | |||
const char * | name, | |||
const char * | num, | |||
const char * | unknown | |||
) |
Definition at line 706 of file callerid.c.
Referenced by _sip_show_peer(), iax2_show_peer(), leave_voicemail(), prep_email_sub_vars(), and sip_show_user().
00707 { 00708 if (!unknown) 00709 unknown = "<unknown>"; 00710 if (name && num) 00711 snprintf(buf, bufsiz, "\"%s\" <%s>", name, num); 00712 else if (name) 00713 ast_copy_string(buf, name, bufsiz); 00714 else if (num) 00715 ast_copy_string(buf, num, bufsiz); 00716 else 00717 ast_copy_string(buf, unknown, bufsiz); 00718 return buf; 00719 }
int ast_callerid_parse | ( | char * | instr, | |
char ** | name, | |||
char ** | location | |||
) |
Destructively parse inbuf into name and location (or number) Parses callerid stream from inbuf and changes into useable form, outputed in name and location.
Definition at line 640 of file callerid.c.
References ast_isphonenumber(), ast_shrink_phone_number(), and ast_strlen_zero().
Referenced by action_originate(), advanced_options(), ast_callerid_split(), ast_osp_lookup(), ast_osp_validate(), ast_privacy_check(), ast_privacy_set(), handle_setcallerid(), misdn_new(), play_message_callerid(), rpt_call(), rpt_exec(), setrdnis_exec(), and write_metadata().
00641 { 00642 char *ns, *ne; 00643 char *ls, *le; 00644 char tmp[256]; 00645 /* Try for "name" <location> format or 00646 name <location> format */ 00647 if ((ls = strchr(instr, '<')) && (le = strchr(ls, '>'))) { 00648 /* Found the location */ 00649 *le = '\0'; 00650 *ls = '\0'; 00651 *location = ls + 1; 00652 if ((ns = strchr(instr, '\"')) && (ne = strchr(ns + 1, '\"'))) { 00653 /* Get name out of quotes */ 00654 *ns = '\0'; 00655 *ne = '\0'; 00656 *name = ns + 1; 00657 return 0; 00658 } else { 00659 /* Just trim off any trailing spaces */ 00660 *name = instr; 00661 while(!ast_strlen_zero(instr) && (instr[strlen(instr) - 1] < 33)) 00662 instr[strlen(instr) - 1] = '\0'; 00663 /* And leading spaces */ 00664 *name = ast_skip_blanks(*name); 00665 return 0; 00666 } 00667 } else { 00668 ast_copy_string(tmp, instr, sizeof(tmp)); 00669 ast_shrink_phone_number(tmp); 00670 if (ast_isphonenumber(tmp)) { 00671 /* Assume it's just a location */ 00672 *name = NULL; 00673 *location = instr; 00674 } else { 00675 /* Assume it's just a name. Make sure it's not quoted though */ 00676 *name = instr; 00677 while(*(*name) && ((*(*name) < 33) || (*(*name) == '\"'))) (*name)++; 00678 ne = *name + strlen(*name) - 1; 00679 while((ne > *name) && ((*ne < 33) || (*ne == '\"'))) { *ne = '\0'; ne--; } 00680 *location = NULL; 00681 } 00682 return 0; 00683 } 00684 return -1; 00685 }
int ast_callerid_split | ( | const char * | buf, | |
char * | name, | |||
int | namelen, | |||
char * | num, | |||
int | numlen | |||
) |
Definition at line 721 of file callerid.c.
References ast_callerid_parse(), ast_shrink_phone_number(), ast_strdupa, and n.
Referenced by apply_outgoing(), build_device(), build_gateway(), build_peer(), build_user(), callerid_write(), disa_exec(), load_module(), monitor_handle_notowned(), setcallerid_exec(), setup_zap(), and vpb_new().
00722 { 00723 char *tmp; 00724 char *l = NULL, *n = NULL; 00725 tmp = ast_strdupa(buf); 00726 if (!tmp) { 00727 name[0] = '\0'; 00728 num[0] = '\0'; 00729 return -1; 00730 } 00731 ast_callerid_parse(tmp, &n, &l); 00732 if (n) 00733 ast_copy_string(name, n, namelen); 00734 else 00735 name[0] = '\0'; 00736 if (l) { 00737 ast_shrink_phone_number(l); 00738 ast_copy_string(num, l, numlen); 00739 } else 00740 num[0] = '\0'; 00741 return 0; 00742 }
const char* ast_describe_caller_presentation | ( | int | data | ) |
Convert caller ID pres value to explanatory string.
data | value (see callerid.h AST_PRES_ ) |
Definition at line 781 of file callerid.c.
References pres_types.
Referenced by _sip_show_peer(), ast_set_callerid(), and sip_show_user().
00782 { 00783 int i; 00784 00785 for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { 00786 if (pres_types[i].val == data) 00787 return pres_types[i].description; 00788 } 00789 00790 return "unknown"; 00791 }
int ast_gen_cas | ( | unsigned char * | outbuf, | |
int | sas, | |||
int | len, | |||
int | codec | |||
) |
outbuf | Allocated buffer for data. Must be at least 2400 bytes unless no SAS is desired | |
sas | Non-zero if CAS should be preceeded by SAS | |
len | How many samples to generate. | |
codec | Which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Definition at line 233 of file callerid.c.
References gen_tone(), gen_tones(), and callerid_state::pos.
Referenced by __adsi_transmit_messages(), and zt_callwait().
00234 { 00235 int pos = 0; 00236 int saslen=2400; 00237 float cr1 = 1.0; 00238 float ci1 = 0.0; 00239 float cr2 = 1.0; 00240 float ci2 = 0.0; 00241 if (sendsas) { 00242 if (len < saslen) 00243 return -1; 00244 gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1); 00245 len -= saslen; 00246 pos += saslen; 00247 cr2 = cr1; 00248 ci2 = ci1; 00249 } 00250 gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2); 00251 return 0; 00252 }
int ast_isphonenumber | ( | char * | n | ) |
Check if a string consists only of digits.
0 if not
Definition at line 626 of file callerid.c.
References ast_strlen_zero().
Referenced by ast_callerid_parse(), ast_osp_lookup(), and ast_osp_validate().
00627 { 00628 int x; 00629 if (ast_strlen_zero(n)) 00630 return 0; 00631 for (x=0;n[x];x++) 00632 if (!strchr("0123456789*#+", n[x])) 00633 return 0; 00634 return 1; 00635 }
int ast_parse_caller_presentation | ( | const char * | data | ) |
Convert caller ID text code to value used in config file parsing.
data | text string |
Definition at line 765 of file callerid.c.
References name, and pres_types.
Referenced by build_peer(), build_user(), and setcallerid_pres_exec().
00766 { 00767 int i; 00768 00769 for (i = 0; i < ((sizeof(pres_types) / sizeof(pres_types[0]))); i++) { 00770 if (!strcasecmp(pres_types[i].name, data)) 00771 return pres_types[i].val; 00772 } 00773 00774 return -1; 00775 }
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...
n | The number to be stripped/shrunk |
Definition at line 592 of file callerid.c.
Referenced by action_originate(), ast_callerid_parse(), ast_callerid_split(), ast_osp_lookup(), ast_osp_validate(), ast_privacy_check(), ast_privacy_set(), check_access(), check_user_full(), dial_exec_full(), get_callerid_ast(), handle_setcallerid(), pbx_load_module(), rpt_exec(), setrdnis_exec(), and write_metadata().
00593 { 00594 int x,y=0; 00595 int bracketed=0; 00596 for (x=0;n[x];x++) { 00597 switch(n[x]) { 00598 case '[': 00599 bracketed++; 00600 n[y++] = n[x]; 00601 break; 00602 case ']': 00603 bracketed--; 00604 n[y++] = n[x]; 00605 break; 00606 case '-': 00607 if (bracketed) 00608 n[y++] = n[x]; 00609 break; 00610 case '.': 00611 if (!n[x+1]) 00612 n[y++] = n[x]; 00613 break; 00614 default: 00615 if (!strchr("( )", n[x])) 00616 n[y++] = n[x]; 00617 } 00618 } 00619 n[y] = '\0'; 00620 }
int callerid_feed | ( | struct callerid_state * | cid, | |
unsigned char * | ubuf, | |||
int | samples, | |||
int | codec | |||
) |
Read samples into the state machine.
cid | Which state machine to act upon | |
ubuf | containing your samples | |
samples | number of samples contained within the buffer. | |
codec | which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Definition at line 254 of file callerid.c.
References ast_log(), ast_strlen_zero(), AST_XLAW, CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, callerid_state::cksum, callerid_state::flags, free, fsk_serie(), callerid_state::fskd, callerid_state::len, LOG_ERROR, LOG_NOTICE, LOG_WARNING, malloc, callerid_state::name, callerid_state::number, callerid_state::oldlen, callerid_state::oldstuff, callerid_state::pos, callerid_state::rawdata, callerid_state::sawflag, and callerid_state::type.
Referenced by get_callerid_ast(), and ss_thread().
00255 { 00256 int mylen = len; 00257 int olen; 00258 int b = 'X'; 00259 int res; 00260 int x; 00261 short *buf = malloc(2 * len + cid->oldlen); 00262 short *obuf = buf; 00263 if (!buf) { 00264 ast_log(LOG_WARNING, "Out of memory\n"); 00265 return -1; 00266 } 00267 memset(buf, 0, 2 * len + cid->oldlen); 00268 memcpy(buf, cid->oldstuff, cid->oldlen); 00269 mylen += cid->oldlen/2; 00270 for (x=0;x<len;x++) 00271 buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]); 00272 while(mylen >= 160) { 00273 olen = mylen; 00274 res = fsk_serie(&cid->fskd, buf, &mylen, &b); 00275 if (mylen < 0) { 00276 ast_log(LOG_ERROR, "fsk_serie made mylen < 0 (%d)\n", mylen); 00277 free(obuf); 00278 return -1; 00279 } 00280 buf += (olen - mylen); 00281 if (res < 0) { 00282 ast_log(LOG_NOTICE, "fsk_serie failed\n"); 00283 return -1; 00284 } 00285 if (res == 1) { 00286 /* Ignore invalid bytes */ 00287 if (b > 0xff) 00288 continue; 00289 switch(cid->sawflag) { 00290 case 0: /* Look for flag */ 00291 if (b == 'U') 00292 cid->sawflag = 2; 00293 break; 00294 case 2: /* Get lead-in */ 00295 if ((b == 0x04) || (b == 0x80)) { 00296 cid->type = b; 00297 cid->sawflag = 3; 00298 cid->cksum = b; 00299 } 00300 break; 00301 case 3: /* Get length */ 00302 /* Not a lead in. We're ready */ 00303 cid->sawflag = 4; 00304 cid->len = b; 00305 cid->pos = 0; 00306 cid->cksum += b; 00307 break; 00308 case 4: /* Retrieve message */ 00309 if (cid->pos >= 128) { 00310 ast_log(LOG_WARNING, "Caller ID too long???\n"); 00311 free(obuf); 00312 return -1; 00313 } 00314 cid->rawdata[cid->pos++] = b; 00315 cid->len--; 00316 cid->cksum += b; 00317 if (!cid->len) { 00318 cid->rawdata[cid->pos] = '\0'; 00319 cid->sawflag = 5; 00320 } 00321 break; 00322 case 5: /* Check checksum */ 00323 if (b != (256 - (cid->cksum & 0xff))) { 00324 ast_log(LOG_NOTICE, "Caller*ID failed checksum\n"); 00325 /* Try again */ 00326 cid->sawflag = 0; 00327 break; 00328 } 00329 00330 cid->number[0] = '\0'; 00331 cid->name[0] = '\0'; 00332 /* If we get this far we're fine. */ 00333 if (cid->type == 0x80) { 00334 /* MDMF */ 00335 /* Go through each element and process */ 00336 for (x=0;x< cid->pos;) { 00337 switch(cid->rawdata[x++]) { 00338 case 1: 00339 /* Date */ 00340 break; 00341 case 2: /* Number */ 00342 case 3: /* Number (for Zebble) */ 00343 case 4: /* Number */ 00344 res = cid->rawdata[x]; 00345 if (res > 32) { 00346 ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]); 00347 res = 32; 00348 } 00349 if (ast_strlen_zero(cid->number)) { 00350 memcpy(cid->number, cid->rawdata + x + 1, res); 00351 /* Null terminate */ 00352 cid->number[res] = '\0'; 00353 } 00354 break; 00355 case 6: /* Stentor Call Qualifier (ie. Long Distance call) */ 00356 break; 00357 case 7: /* Name */ 00358 case 8: /* Name */ 00359 res = cid->rawdata[x]; 00360 if (res > 32) { 00361 ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]); 00362 res = 32; 00363 } 00364 memcpy(cid->name, cid->rawdata + x + 1, res); 00365 cid->name[res] = '\0'; 00366 break; 00367 case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting */ 00368 case 19: /* UK: Network message system status (Number of messages waiting) */ 00369 case 22: /* Something French */ 00370 break; 00371 default: 00372 ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x-1]); 00373 } 00374 x += cid->rawdata[x]; 00375 x++; 00376 } 00377 } else { 00378 /* SDMF */ 00379 ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number)); 00380 } 00381 /* Update flags */ 00382 cid->flags = 0; 00383 if (!strcmp(cid->number, "P")) { 00384 strcpy(cid->number, ""); 00385 cid->flags |= CID_PRIVATE_NUMBER; 00386 } else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) { 00387 strcpy(cid->number, ""); 00388 cid->flags |= CID_UNKNOWN_NUMBER; 00389 } 00390 if (!strcmp(cid->name, "P")) { 00391 strcpy(cid->name, ""); 00392 cid->flags |= CID_PRIVATE_NAME; 00393 } else if (!strcmp(cid->name, "O") || ast_strlen_zero(cid->name)) { 00394 strcpy(cid->name, ""); 00395 cid->flags |= CID_UNKNOWN_NAME; 00396 } 00397 free(obuf); 00398 return 1; 00399 break; 00400 default: 00401 ast_log(LOG_ERROR, "Dunno what to do with a digit in sawflag %d\n", cid->sawflag); 00402 } 00403 } 00404 } 00405 if (mylen) { 00406 memcpy(cid->oldstuff, buf, mylen * 2); 00407 cid->oldlen = mylen * 2; 00408 } else 00409 cid->oldlen = 0; 00410 free(obuf); 00411 return 0; 00412 }
void callerid_free | ( | struct callerid_state * | cid | ) |
Free a callerID state.
cid | This is the callerid_state state machine to free This function frees callerid_state cid. |
Definition at line 414 of file callerid.c.
References free.
Referenced by get_callerid_ast(), and ss_thread().
00415 { 00416 free(cid); 00417 }
int callerid_generate | ( | unsigned char * | buf, | |
char * | number, | |||
char * | name, | |||
int | flags, | |||
int | callwaiting, | |||
int | codec | |||
) |
Generates a CallerID FSK stream in ulaw format suitable for transmission.
buf | Buffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own. "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun. | |
number | Use NULL for no number or "P" for "private" | |
name | name to be used | |
flags | passed flags | |
callwaiting | callwaiting flag | |
codec | -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW This function creates a stream of callerid (a callerid spill) data in ulaw format. |
Definition at line 550 of file callerid.c.
References callerid_genmsg(), PUT_BYTE, PUT_CLID, and PUT_CLID_MARKMS.
Referenced by __ast_callerid_generate().
00551 { 00552 int bytes=0; 00553 int x, sum; 00554 int len; 00555 /* Initial carriers (real/imaginary) */ 00556 float cr = 1.0; 00557 float ci = 0.0; 00558 float scont = 0.0; 00559 char msg[256]; 00560 len = callerid_genmsg(msg, sizeof(msg), number, name, flags); 00561 if (!callwaiting) { 00562 /* Wait a half a second */ 00563 for (x=0;x<4000;x++) 00564 PUT_BYTE(0x7f); 00565 /* Transmit 30 0x55's (looks like a square wave) for channel seizure */ 00566 for (x=0;x<30;x++) 00567 PUT_CLID(0x55); 00568 } 00569 /* Send 150ms of callerid marks */ 00570 for (x=0;x<150;x++) 00571 PUT_CLID_MARKMS; 00572 /* Send 0x80 indicating MDMF format */ 00573 PUT_CLID(0x80); 00574 /* Put length of whole message */ 00575 PUT_CLID(len); 00576 sum = 0x80 + strlen(msg); 00577 /* Put each character of message and update checksum */ 00578 for (x=0;x<len; x++) { 00579 PUT_CLID(msg[x]); 00580 sum += msg[x]; 00581 } 00582 /* Send 2's compliment of sum */ 00583 PUT_CLID(256 - (sum & 255)); 00584 00585 /* Send 50 more ms of marks */ 00586 for (x=0;x<50;x++) 00587 PUT_CLID_MARKMS; 00588 00589 return bytes; 00590 }
static int callerid_genmsg | ( | char * | msg, | |
int | size, | |||
char * | number, | |||
char * | name, | |||
int | flags | |||
) | [static] |
Definition at line 419 of file callerid.c.
References ast_strlen_zero(), CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, and t.
Referenced by callerid_generate().
00420 { 00421 time_t t; 00422 struct tm tm; 00423 char *ptr; 00424 int res; 00425 int i,x; 00426 /* Get the time */ 00427 time(&t); 00428 localtime_r(&t,&tm); 00429 00430 ptr = msg; 00431 00432 /* Format time and message header */ 00433 res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm.tm_mon + 1, 00434 tm.tm_mday, tm.tm_hour, tm.tm_min); 00435 size -= res; 00436 ptr += res; 00437 if (ast_strlen_zero(number) || (flags & CID_UNKNOWN_NUMBER)) { 00438 /* Indicate number not known */ 00439 res = snprintf(ptr, size, "\004\001O"); 00440 size -= res; 00441 ptr += res; 00442 } else if (flags & CID_PRIVATE_NUMBER) { 00443 /* Indicate number is private */ 00444 res = snprintf(ptr, size, "\004\001P"); 00445 size -= res; 00446 ptr += res; 00447 } else { 00448 /* Send up to 16 digits of number MAX */ 00449 i = strlen(number); 00450 if (i > 16) i = 16; 00451 res = snprintf(ptr, size, "\002%c", i); 00452 size -= res; 00453 ptr += res; 00454 for (x=0;x<i;x++) 00455 ptr[x] = number[x]; 00456 ptr[i] = '\0'; 00457 ptr += i; 00458 size -= i; 00459 } 00460 00461 if (ast_strlen_zero(name) || (flags & CID_UNKNOWN_NAME)) { 00462 /* Indicate name not known */ 00463 res = snprintf(ptr, size, "\010\001O"); 00464 size -= res; 00465 ptr += res; 00466 } else if (flags & CID_PRIVATE_NAME) { 00467 /* Indicate name is private */ 00468 res = snprintf(ptr, size, "\010\001P"); 00469 size -= res; 00470 ptr += res; 00471 } else { 00472 /* Send up to 16 digits of name MAX */ 00473 i = strlen(name); 00474 if (i > 16) i = 16; 00475 res = snprintf(ptr, size, "\007%c", i); 00476 size -= res; 00477 ptr += res; 00478 for (x=0;x<i;x++) 00479 ptr[x] = name[x]; 00480 ptr[i] = '\0'; 00481 ptr += i; 00482 size -= i; 00483 } 00484 return (ptr - msg); 00485 00486 }
void callerid_get | ( | struct callerid_state * | cid, | |
char ** | number, | |||
char ** | name, | |||
int * | flags | |||
) |
Extract info out of callerID state machine. Flags are listed above.
cid | Callerid state machine to act upon | |
number | Pass the address of a pointer-to-char (will contain the phone number) | |
name | Pass the address of a pointer-to-char (will contain the name) | |
flags | Pass the address of an int variable(will contain the various callerid flags) |
Definition at line 159 of file callerid.c.
References CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, callerid_state::flags, callerid_state::name, and callerid_state::number.
Referenced by get_callerid_ast(), and ss_thread().
00160 { 00161 *flags = cid->flags; 00162 if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NUMBER)) 00163 *name = NULL; 00164 else 00165 *name = cid->name; 00166 if (cid->flags & (CID_UNKNOWN_NUMBER | CID_PRIVATE_NUMBER)) 00167 *number = NULL; 00168 else 00169 *number = cid->number; 00170 }
void callerid_get_dtmf | ( | char * | cidstring, | |
char * | number, | |||
int * | flags | |||
) |
cidstring | The actual transmitted string. | |
number | The cid number is returned here. | |
flags | The cid flags are returned here. This function parses DTMF callerid. |
Definition at line 172 of file callerid.c.
References ast_log(), CID_PRIVATE_NUMBER, CID_UNKNOWN_NUMBER, LOG_DEBUG, and LOG_WARNING.
Referenced by ss_thread().
00173 { 00174 int i; 00175 int code; 00176 00177 /* "Clear" the number-buffer. */ 00178 number[0] = 0; 00179 00180 if (strlen(cidstring) < 2) { 00181 ast_log(LOG_DEBUG, "No cid detected\n"); 00182 *flags = CID_UNKNOWN_NUMBER; 00183 return; 00184 } 00185 00186 /* Detect protocol and special types */ 00187 if (cidstring[0] == 'B') { 00188 /* Handle special codes */ 00189 code = atoi(&cidstring[1]); 00190 if (code == 0) 00191 *flags = CID_UNKNOWN_NUMBER; 00192 else if (code == 10) 00193 *flags = CID_PRIVATE_NUMBER; 00194 else 00195 ast_log(LOG_DEBUG, "Unknown DTMF code %d\n", code); 00196 } else if (cidstring[0] == 'D' && cidstring[2] == '#') { 00197 /* .DK special code */ 00198 if (cidstring[1] == '1') 00199 *flags = CID_PRIVATE_NUMBER; 00200 if (cidstring[1] == '2' || cidstring[1] == '3') 00201 *flags = CID_UNKNOWN_NUMBER; 00202 } else if (cidstring[0] == 'D' || cidstring[0] == 'A') { 00203 /* "Standard" callerid */ 00204 for (i = 1; i < strlen(cidstring); i++ ) { 00205 if (cidstring[i] == 'C' || cidstring[i] == '#') 00206 break; 00207 if (isdigit(cidstring[i])) 00208 number[i-1] = cidstring[i]; 00209 else 00210 ast_log(LOG_DEBUG, "Unknown CID digit '%c'\n", 00211 cidstring[i]); 00212 } 00213 number[i-1] = 0; 00214 } else if (isdigit(cidstring[0])) { 00215 /* It begins with a digit, so we parse it as a number and hope 00216 * for the best */ 00217 ast_log(LOG_WARNING, "Couldn't detect start-character. CID " 00218 "parsing might be unreliable\n"); 00219 for (i = 0; i < strlen(cidstring); i++) { 00220 if (isdigit(cidstring[i])) 00221 number[i] = cidstring[i]; 00222 else 00223 break; 00224 } 00225 number[i] = 0; 00226 } else { 00227 ast_log(LOG_DEBUG, "Unknown CID protocol, start digit '%c'\n", 00228 cidstring[0]); 00229 *flags = CID_UNKNOWN_NUMBER; 00230 } 00231 }
void callerid_init | ( | void | ) |
CallerID Initialization.
Definition at line 113 of file callerid.c.
References CALLERID_MARK, CALLERID_SPACE, CAS_FREQ1, CAS_FREQ2, and SAS_FREQ.
Referenced by main().
00114 { 00115 cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0); 00116 cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0); 00117 cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0); 00118 cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0); 00119 sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0); 00120 sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0); 00121 casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0); 00122 casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0); 00123 casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0); 00124 casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0); 00125 }
struct callerid_state* callerid_new | ( | int | cid_signalling | ) |
Create a callerID state machine.
cid_signalling | Type of signalling in use |
Definition at line 127 of file callerid.c.
References ast_log(), CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, LOG_WARNING, and malloc.
Referenced by get_callerid_ast(), and ss_thread().
00128 { 00129 struct callerid_state *cid; 00130 cid = malloc(sizeof(struct callerid_state)); 00131 if (cid) { 00132 memset(cid, 0, sizeof(struct callerid_state)); 00133 cid->fskd.spb = 7; /* 1200 baud */ 00134 cid->fskd.hdlc = 0; /* Async */ 00135 cid->fskd.nbit = 8; /* 8 bits */ 00136 cid->fskd.nstop = 1; /* 1 stop bit */ 00137 cid->fskd.paridad = 0; /* No parity */ 00138 cid->fskd.bw=1; /* Filter 800 Hz */ 00139 if (cid_signalling == 2) { /* v23 signalling */ 00140 cid->fskd.f_mark_idx = 4; /* 1300 Hz */ 00141 cid->fskd.f_space_idx = 5; /* 2100 Hz */ 00142 } else { /* Bell 202 signalling as default */ 00143 cid->fskd.f_mark_idx = 2; /* 1200 Hz */ 00144 cid->fskd.f_space_idx = 3; /* 2200 Hz */ 00145 } 00146 cid->fskd.pcola = 0; /* No clue */ 00147 cid->fskd.cont = 0; /* Digital PLL reset */ 00148 cid->fskd.x0 = 0.0; 00149 cid->fskd.state = 0; 00150 memset(cid->name, 0, sizeof(cid->name)); 00151 memset(cid->number, 0, sizeof(cid->number)); 00152 cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER; 00153 cid->pos = 0; 00154 } else 00155 ast_log(LOG_WARNING, "Out of memory\n"); 00156 return cid; 00157 }
static void gen_tone | ( | unsigned char * | buf, | |
int | len, | |||
int | codec, | |||
float | ddr1, | |||
float | ddi1, | |||
float * | cr1, | |||
float * | ci1 | |||
) | [inline, static] |
Definition at line 97 of file callerid.c.
Referenced by ast_gen_cas().
00098 { 00099 int x; 00100 float t; 00101 for (x=0;x<len;x++) { 00102 t = *cr1 * ddr1 - *ci1 * ddi1; 00103 *ci1 = *cr1 * ddi1 + *ci1 * ddr1; 00104 *cr1 = t; 00105 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1); 00106 *cr1 *= t; 00107 *ci1 *= t; 00108 buf[x] = AST_LIN2X(*cr1 * 8192.0); 00109 } 00110 }
static 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 | |||
) | [inline, static] |
Definition at line 75 of file callerid.c.
Referenced by ast_gen_cas().
00076 { 00077 int x; 00078 float t; 00079 for (x=0;x<len;x++) { 00080 t = *cr1 * ddr1 - *ci1 * ddi1; 00081 *ci1 = *cr1 * ddi1 + *ci1 * ddr1; 00082 *cr1 = t; 00083 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1); 00084 *cr1 *= t; 00085 *ci1 *= t; 00086 00087 t = *cr2 * ddr2 - *ci2 * ddi2; 00088 *ci2 = *cr2 * ddi2 + *ci2 * ddr2; 00089 *cr2 = t; 00090 t = 2.0 - (*cr2 * *cr2 + *ci2 * *ci2); 00091 *cr2 *= t; 00092 *ci2 *= t; 00093 buf[x] = AST_LIN2X((*cr1 + *cr2) * 2048.0); 00094 } 00095 }
int vmwi_generate | ( | unsigned char * | buf, | |
int | active, | |||
int | mdmf, | |||
int | codec | |||
) |
Generate message waiting indicator (stutter tone).
Definition at line 488 of file callerid.c.
References PUT_BYTE, PUT_CLID, and PUT_CLID_MARKMS.
Referenced by do_monitor().
00489 { 00490 unsigned char msg[256]; 00491 int len=0; 00492 int sum; 00493 int x; 00494 int bytes = 0; 00495 float cr = 1.0; 00496 float ci = 0.0; 00497 float scont = 0.0; 00498 if (mdmf) { 00499 /* MDMF Message waiting */ 00500 msg[len++] = 0x82; 00501 /* Length is 3 */ 00502 msg[len++] = 3; 00503 /* IE is "Message Waiting Parameter" */ 00504 msg[len++] = 0xb; 00505 /* Length of IE is one */ 00506 msg[len++] = 1; 00507 /* Active or not */ 00508 if (active) 00509 msg[len++] = 0xff; 00510 else 00511 msg[len++] = 0x00; 00512 } else { 00513 /* SDMF Message waiting */ 00514 msg[len++] = 0x6; 00515 /* Length is 3 */ 00516 msg[len++] = 3; 00517 if (active) { 00518 msg[len++] = 0x42; 00519 msg[len++] = 0x42; 00520 msg[len++] = 0x42; 00521 } else { 00522 msg[len++] = 0x6f; 00523 msg[len++] = 0x6f; 00524 msg[len++] = 0x6f; 00525 } 00526 } 00527 sum = 0; 00528 for (x=0;x<len;x++) 00529 sum += msg[x]; 00530 sum = (256 - (sum & 255)); 00531 msg[len++] = sum; 00532 /* Wait a half a second */ 00533 for (x=0;x<4000;x++) 00534 PUT_BYTE(0x7f); 00535 /* Transmit 30 0x55's (looks like a square wave) for channel seizure */ 00536 for (x=0;x<30;x++) 00537 PUT_CLID(0x55); 00538 /* Send 170ms of callerid marks */ 00539 for (x=0;x<170;x++) 00540 PUT_CLID_MARKMS; 00541 for (x=0;x<len;x++) { 00542 PUT_CLID(msg[x]); 00543 } 00544 /* Send 50 more ms of marks */ 00545 for (x=0;x<50;x++) 00546 PUT_CLID_MARKMS; 00547 return bytes; 00548 }
float casdi1 |
Definition at line 65 of file callerid.c.
float casdi2 |
Definition at line 65 of file callerid.c.
float casdr1 |
Definition at line 65 of file callerid.c.
float casdr2 |
Definition at line 65 of file callerid.c.
float cid_di[4] |
float cid_dr[4] |
float clidsb = 8000.0 / 1200.0 |
Definition at line 63 of file callerid.c.
char* description |
Definition at line 747 of file callerid.c.
Referenced by handle_show_application(), handle_show_function(), and load_pbx().
char* name |
Definition at line 746 of file callerid.c.
Referenced by __iax2_show_peers(), _sip_show_peers(), action_getvar(), action_hangup(), action_originate(), action_redirect(), action_setvar(), action_status(), action_timeout(), add_agent(), adsi_load(), adsi_message(), advanced_options(), alarm2str(), ast_channel_free(), ast_dsp_set_call_progress_zone(), ast_getformatname(), ast_getformatname_multiple(), ast_monitor_change_fname(), ast_monitor_start(), ast_monitor_stop(), ast_parse_caller_presentation(), ast_rtp_lookup_mime_multiple(), ast_var_name(), bestdata_handle_escape(), callerid_write(), change_monitor_action(), channel_spy(), chanspy_exec(), complete_agent_logoff_cmd(), dlclose(), do_directory(), dump_ies(), dump_prov_ies(), dundi_ie2str(), find_peer(), get_callerid_ast(), get_zap_channel_locked(), handle_context(), handle_macro(), handle_message(), handle_showchan(), iax_ie2str(), iax_provflags2str(), iax_str2flags(), int2strat(), load_pbx(), misdn_cfg_get_config_string(), pbx_builtin_importvar(), pbx_builtin_setglobalvar(), pbx_builtin_setvar(), phone_request(), play_message_callerid(), process_opcode(), process_returncode(), register_verify(), rpt_call(), rpt_exec(), rpt_master(), setcallerid_exec(), settransfercapability_exec(), sip_prune_realtime(), softhangup_exec(), ss_thread(), start_monitor_action(), stop_monitor_action(), strat2int(), unload_module(), update_call_counter(), and vpb_request().
struct { ... } pres_types[] [static] |
Referenced by ast_describe_caller_presentation(), and ast_parse_caller_presentation().
float sasdi |
Definition at line 64 of file callerid.c.
float sasdr |
Definition at line 64 of file callerid.c.
int val |
Definition at line 745 of file callerid.c.