Wed Jan 8 2020 09:49:58

Asterisk developer's documentation


callerid.h File Reference

CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata library. More...

Go to the source code of this file.

Macros

#define AST_LIN2X(a)   ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
 
#define AST_PRES_ALLOWED   0x00
 
#define AST_PRES_ALLOWED_NETWORK_NUMBER   (AST_PRES_ALLOWED | AST_PRES_NETWORK_NUMBER)
 
#define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_FAILED_SCREEN)
 
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_UNSCREENED)
 
#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_PASSED_SCREEN)
 
#define AST_PRES_NETWORK_NUMBER   0x03
 
#define AST_PRES_NUMBER_NOT_AVAILABLE   (AST_PRES_UNAVAILABLE | AST_PRES_NETWORK_NUMBER)
 
#define AST_PRES_NUMBER_TYPE   0x03
 
#define AST_PRES_PROHIB_NETWORK_NUMBER   (AST_PRES_RESTRICTED | AST_PRES_NETWORK_NUMBER)
 
#define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_FAILED_SCREEN)
 
#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_UNSCREENED)
 
#define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_PASSED_SCREEN)
 
#define AST_PRES_RESERVED   0x60
 
#define AST_PRES_RESTRICTED   0x20
 
#define AST_PRES_RESTRICTION   0x60
 
#define AST_PRES_UNAVAILABLE   0x40
 
#define AST_PRES_USER_NUMBER_FAILED_SCREEN   0x02
 
#define AST_PRES_USER_NUMBER_PASSED_SCREEN   0x01
 
#define AST_PRES_USER_NUMBER_UNSCREENED   0x00
 
#define AST_XLAW(a)   ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))
 
#define CID_MSGWAITING   (1 << 4)
 
#define CID_MWI_TYPE_MDMF   0x01
 
#define CID_MWI_TYPE_MDMF_FULL   0x02
 
#define CID_MWI_TYPE_SDMF   0x00
 
#define CID_NOMSGWAITING   (1 << 5)
 
#define CID_PRIVATE_NAME   (1 << 0)
 
#define CID_PRIVATE_NUMBER   (1 << 1)
 
#define CID_SIG_BELL   1
 
#define CID_SIG_DTMF   3
 
#define CID_SIG_SMDI   5
 
#define CID_SIG_V23   2
 
#define CID_SIG_V23_JP   4
 
#define CID_START_DTMF_NOALERT   4
 
#define CID_START_POLARITY   2
 
#define CID_START_POLARITY_IN   3
 
#define CID_START_RING   1
 
#define CID_UNKNOWN_NAME   (1 << 2)
 
#define CID_UNKNOWN_NUMBER   (1 << 3)
 
#define MAX_CALLERID_SIZE   32000
 
#define PUT_AUDIO_SAMPLE(y)
 
#define PUT_BYTE(a)
 
#define PUT_CLID(byte)
 
#define PUT_CLID_BAUD(bit)
 
#define PUT_CLID_MARKMS
 

Typedefs

typedef struct callerid_state CIDSTATE
 

Enumerations

enum  AST_CONNECTED_LINE_UPDATE_SOURCE {
  AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN, AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, AST_CONNECTED_LINE_UPDATE_SOURCE_DIVERSION, AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER,
  AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER_ALERTING
}
 Connected line update source code. More...
 
enum  AST_REDIRECTING_REASON {
  AST_REDIRECTING_REASON_UNKNOWN, AST_REDIRECTING_REASON_USER_BUSY, AST_REDIRECTING_REASON_NO_ANSWER, AST_REDIRECTING_REASON_UNAVAILABLE,
  AST_REDIRECTING_REASON_UNCONDITIONAL, AST_REDIRECTING_REASON_TIME_OF_DAY, AST_REDIRECTING_REASON_DO_NOT_DISTURB, AST_REDIRECTING_REASON_DEFLECTION,
  AST_REDIRECTING_REASON_FOLLOW_ME, AST_REDIRECTING_REASON_OUT_OF_ORDER, AST_REDIRECTING_REASON_AWAY, AST_REDIRECTING_REASON_CALL_FWD_DTE
}
 redirecting reason codes. More...
 

Functions

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) More...
 
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) More...
 
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) More...
 
int ast_callerid_split (const char *src, char *name, int namelen, char *num, int numlen)
 
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. More...
 
const char * ast_connected_line_source_describe (int data)
 Convert connected line update source value to explanatory string. More...
 
const char * ast_connected_line_source_name (int data)
 Convert connected line update source value to text code. More...
 
int ast_connected_line_source_parse (const char *data)
 Convert connected line update source text code to value (used in config file parsing) More...
 
const char * ast_describe_caller_presentation (int data)
 Convert caller ID pres value to explanatory string. More...
 
int ast_gen_cas (unsigned char *outbuf, int sas, int len, format_t codec)
 Generate a CAS (CPE Alert Signal) tone for 'n' samples. More...
 
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_shrink_phone_number) More...
 
int ast_isphonenumber (const char *n)
 Check if a string consists only of digits and + #. More...
 
const char * ast_named_caller_presentation (int data)
 Convert caller ID pres value to text code. More...
 
int ast_parse_caller_presentation (const char *data)
 Convert caller ID text code to value (used in config file parsing) More...
 
const char * ast_party_name_charset_describe (int data)
 Convert ast_party_name.char_set value to explanatory string. More...
 
int ast_party_name_charset_parse (const char *data)
 Convert ast_party_name.char_set text code to value (used in config file parsing) More...
 
const char * ast_party_name_charset_str (int data)
 Convert ast_party_name.char_set value to text code. More...
 
const char * ast_redirecting_reason_describe (int data)
 Convert redirecting reason value to explanatory string. More...
 
const char * ast_redirecting_reason_name (int data)
 Convert redirecting reason value to text code. More...
 
int ast_redirecting_reason_parse (const char *data)
 Convert redirecting reason text code to value (used in config file parsing) More...
 
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... More...
 
int callerid_feed (struct callerid_state *cid, unsigned char *ubuf, int samples, format_t codec)
 Read samples into the state machine. More...
 
int callerid_feed_jp (struct callerid_state *cid, unsigned char *ubuf, int samples, format_t codec)
 Read samples into the state machine. More...
 
void callerid_free (struct callerid_state *cid)
 This function frees callerid_state cid. More...
 
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. More...
 
void callerid_get (struct callerid_state *cid, char **number, char **name, int *flags)
 Extract info out of callerID state machine. Flags are listed above. More...
 
void callerid_get_dtmf (char *cidstring, char *number, int *flags)
 Get and parse DTMF-based callerid. More...
 
static float callerid_getcarrier (float *cr, float *ci, int bit)
 
void callerid_init (void)
 CallerID Initialization. More...
 
struct callerid_statecallerid_new (int cid_signalling)
 Create a callerID state machine. More...
 

Variables

float cid_di [4]
 
float cid_dr [4]
 
float clidsb
 

Detailed Description

CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata library.

Caller ID names and numbers

Definition in file callerid.h.

Macro Definition Documentation

#define AST_LIN2X (   a)    ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))

Definition at line 78 of file callerid.h.

Referenced by gen_tone(), and gen_tones().

#define AST_PRES_ALLOWED_NETWORK_NUMBER   (AST_PRES_ALLOWED | AST_PRES_NETWORK_NUMBER)

Definition at line 338 of file callerid.h.

Referenced by add_rpid().

#define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_FAILED_SCREEN)

Definition at line 335 of file callerid.h.

Referenced by add_rpid().

#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_UNSCREENED)
#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_PASSED_SCREEN)

Definition at line 332 of file callerid.h.

Referenced by add_rpid(), check_access(), dial_exec_full(), and get_rpid().

#define AST_PRES_NETWORK_NUMBER   0x03
#define AST_PRES_NUMBER_NOT_AVAILABLE   (AST_PRES_UNAVAILABLE | AST_PRES_NETWORK_NUMBER)
#define AST_PRES_NUMBER_TYPE   0x03

Definition at line 317 of file callerid.h.

Referenced by ast_party_id_presentation(), and ast_to_misdn_screen().

#define AST_PRES_PROHIB_NETWORK_NUMBER   (AST_PRES_RESTRICTED | AST_PRES_NETWORK_NUMBER)

Definition at line 350 of file callerid.h.

Referenced by add_rpid().

#define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_FAILED_SCREEN)

Definition at line 347 of file callerid.h.

Referenced by add_rpid().

#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_UNSCREENED)

Definition at line 341 of file callerid.h.

Referenced by add_rpid(), get_pai(), and get_rpid().

#define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN   (AST_PRES_RESTRICTED | AST_PRES_USER_NUMBER_PASSED_SCREEN)

Definition at line 344 of file callerid.h.

Referenced by add_rpid(), and get_rpid().

#define AST_PRES_RESERVED   0x60

Definition at line 327 of file callerid.h.

#define AST_PRES_RESTRICTION   0x60
#define AST_PRES_UNAVAILABLE   0x40
#define AST_PRES_USER_NUMBER_FAILED_SCREEN   0x02
#define AST_PRES_USER_NUMBER_PASSED_SCREEN   0x01
#define AST_XLAW (   a)    ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))

Definition at line 79 of file callerid.h.

Referenced by callerid_feed(), and callerid_feed_jp().

#define CID_MSGWAITING   (1 << 4)

Definition at line 56 of file callerid.h.

Referenced by callerid_feed(), mwi_thread(), and my_handle_notify_message().

#define CID_MWI_TYPE_MDMF   0x01

MWI MDMF format – generate only MWI field

Definition at line 74 of file callerid.h.

Referenced by ast_callerid_vmwi_generate().

#define CID_MWI_TYPE_MDMF_FULL   0x02

MWI MDMF format – generate name, callerid, date and MWI fields

Definition at line 76 of file callerid.h.

Referenced by ast_callerid_vmwi_generate(), and mwi_send_init().

#define CID_MWI_TYPE_SDMF   0x00

MWI SDMF format

Definition at line 72 of file callerid.h.

#define CID_NOMSGWAITING   (1 << 5)

Definition at line 57 of file callerid.h.

Referenced by callerid_feed(), mwi_thread(), and my_handle_notify_message().

#define CID_PRIVATE_NAME   (1 << 0)

Definition at line 52 of file callerid.h.

Referenced by callerid_feed(), callerid_genmsg(), and callerid_get().

#define CID_PRIVATE_NUMBER   (1 << 1)

Definition at line 53 of file callerid.h.

Referenced by callerid_feed(), callerid_genmsg(), callerid_get(), and callerid_get_dtmf().

#define CID_SIG_BELL   1

Definition at line 59 of file callerid.h.

Referenced by analog_new(), dahdi_chan_conf_default(), and process_dahdi().

#define CID_SIG_DTMF   3

Definition at line 61 of file callerid.h.

Referenced by __analog_ss_thread(), analog_ss_thread(), and process_dahdi().

#define CID_SIG_SMDI   5

Definition at line 63 of file callerid.h.

Referenced by __analog_ss_thread(), analog_ss_thread(), mkintf(), and process_dahdi().

#define CID_SIG_V23   2

Definition at line 60 of file callerid.h.

Referenced by __analog_ss_thread(), analog_ss_thread(), and process_dahdi().

#define CID_SIG_V23_JP   4

Definition at line 62 of file callerid.h.

Referenced by __analog_ss_thread(), analog_ss_thread(), my_get_callerid(), and process_dahdi().

#define CID_START_DTMF_NOALERT   4

Definition at line 68 of file callerid.h.

Referenced by analog_ss_thread(), do_monitor(), mkintf(), and process_dahdi().

#define CID_START_POLARITY   2

Definition at line 66 of file callerid.h.

Referenced by analog_ss_thread(), handle_init_event(), mkintf(), and process_dahdi().

#define CID_START_POLARITY_IN   3

Definition at line 67 of file callerid.h.

Referenced by analog_ss_thread(), handle_init_event(), mkintf(), and process_dahdi().

#define CID_START_RING   1

Definition at line 65 of file callerid.h.

Referenced by analog_ss_thread(), dahdi_chan_conf_default(), and process_dahdi().

#define CID_UNKNOWN_NAME   (1 << 2)

Definition at line 54 of file callerid.h.

Referenced by callerid_feed(), callerid_genmsg(), callerid_get(), and callerid_new().

#define CID_UNKNOWN_NUMBER   (1 << 3)
#define MAX_CALLERID_SIZE   32000

Definition at line 50 of file callerid.h.

Referenced by mwi_send_init(), my_send_callerid(), and send_cwcidspill().

#define PUT_AUDIO_SAMPLE (   y)
Value:
do { \
int __sample_idx = (short)(rint(8192.0 * (y))); \
*(buf++) = AST_LIN2X(__sample_idx); \
bytes++; \
} while(0)
#define AST_LIN2X(a)
Definition: callerid.h:78

Definition at line 283 of file callerid.h.

#define PUT_BYTE (   a)
Value:
do { \
*(buf++) = (a); \
bytes++; \
} while(0)

Definition at line 278 of file callerid.h.

Referenced by ast_callerid_vmwi_generate(), and callerid_generate().

#define PUT_CLID (   byte)
#define PUT_CLID_BAUD (   bit)

Definition at line 295 of file callerid.h.

#define PUT_CLID_MARKMS
Value:
do { \
int __clid_x; \
for (__clid_x=0;__clid_x<8;__clid_x++) \
} while(0)
#define PUT_AUDIO_SAMPLE(y)
Definition: callerid.h:283
for(;;)
Definition: ast_expr2.c:2460
static float callerid_getcarrier(float *cr, float *ci, int bit)
Definition: callerid.h:264

Definition at line 289 of file callerid.h.

Referenced by adsi_generate(), ast_callerid_vmwi_generate(), callerid_generate(), and dahdi_sendtext().

Typedef Documentation

typedef struct callerid_state CIDSTATE

Definition at line 83 of file callerid.h.

Enumeration Type Documentation

Connected line update source code.

Enumerator
AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN 

Update for unknown reason (May be interpreted to mean from answer)

AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER 

Update from normal call answering

AST_CONNECTED_LINE_UPDATE_SOURCE_DIVERSION 

Update from call diversion (Deprecated, use REDIRECTING updates instead.)

AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER 

Update from call transfer(active) (Party has already answered)

AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER_ALERTING 

Update from call transfer(alerting) (Party has not answered yet)

Definition at line 439 of file callerid.h.

439  {
440  /*! Update for unknown reason (May be interpreted to mean from answer) */
442  /*! Update from normal call answering */
444  /*! Update from call diversion (Deprecated, use REDIRECTING updates instead.) */
446  /*! Update from call transfer(active) (Party has already answered) */
448  /*! Update from call transfer(alerting) (Party has not answered yet) */
450 };

redirecting reason codes.

This list attempts to encompass redirecting reasons as defined by several channel technologies.

Enumerator
AST_REDIRECTING_REASON_UNKNOWN 
AST_REDIRECTING_REASON_USER_BUSY 
AST_REDIRECTING_REASON_NO_ANSWER 
AST_REDIRECTING_REASON_UNAVAILABLE 
AST_REDIRECTING_REASON_UNCONDITIONAL 
AST_REDIRECTING_REASON_TIME_OF_DAY 
AST_REDIRECTING_REASON_DO_NOT_DISTURB 
AST_REDIRECTING_REASON_DEFLECTION 
AST_REDIRECTING_REASON_FOLLOW_ME 
AST_REDIRECTING_REASON_OUT_OF_ORDER 
AST_REDIRECTING_REASON_AWAY 
AST_REDIRECTING_REASON_CALL_FWD_DTE 

Definition at line 390 of file callerid.h.

Function Documentation

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)

See Also
ast_callerid_generate() for other details

Definition at line 1069 of file callerid.c.

References __ast_callerid_generate().

Referenced by my_send_callerid(), and send_cwcidspill().

1070 {
1071  return __ast_callerid_generate(buf, name, number, 1, codec);
1072 }
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, format_t codec)
Definition: callerid.c:1055
Number structure.
Definition: app_followme.c:109
static const char name[]
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)

Parameters
bufbuffer for output samples. See callerid_generate() for details regarding buffer.
nameCaller-ID Name
numberCaller-ID Number
codecAsterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)

Acts like callerid_generate except uses an asterisk format callerid string.

Definition at line 1064 of file callerid.c.

References __ast_callerid_generate().

Referenced by my_send_callerid().

1065 {
1066  return __ast_callerid_generate(buf, name, number, 0, codec);
1067 }
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, format_t codec)
Definition: callerid.c:1055
Number structure.
Definition: app_followme.c:109
static const char name[]
char* ast_callerid_merge ( char *  buf,
int  bufsiz,
const char *  name,
const char *  num,
const char *  unknown 
)

Definition at line 1074 of file callerid.c.

References ast_copy_string(), and ast_escape_quoted().

Referenced by _sip_show_peer(), _skinny_show_line(), handle_cli_iax2_show_peer(), leave_voicemail(), prep_email_sub_vars(), set_one_cid(), and sip_show_user().

1075 {
1076  if (!unknown)
1077  unknown = "<unknown>";
1078  if (name && num) {
1079  char name_buf[128];
1080 
1081  ast_escape_quoted(name, name_buf, sizeof(name_buf));
1082  snprintf(buf, bufsiz, "\"%s\" <%s>", name_buf, num);
1083  } else if (name) {
1084  ast_copy_string(buf, name, bufsiz);
1085  } else if (num) {
1086  ast_copy_string(buf, num, bufsiz);
1087  } else {
1088  ast_copy_string(buf, unknown, bufsiz);
1089  }
1090  return buf;
1091 }
static const char name[]
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
Definition: utils.c:431
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
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.

Parameters
instrbuffer of callerid stream (in audio form) to be parsed. Warning, data in buffer is changed.
nameaddress of a pointer-to-char for the name value of the stream.
locationaddress of a pointer-to-char for the phone number value of the stream.
Note
XXX 'name' is not parsed consistently e.g. we have input location name " foo bar " <123> 123 ' foo bar ' (with spaces around) " foo bar " NULL 'foo bar' (without spaces around) The parsing of leading and trailing space/quotes should be more consistent.
Returns
Returns 0 on success, -1 on failure.

Definition at line 1009 of file callerid.c.

References ast_copy_string(), ast_isphonenumber(), ast_shrink_phone_number(), ast_strip(), ast_strip_quoted(), and ast_unescape_quoted().

Referenced by action_originate(), adsi_message(), advanced_options(), ast_callerid_split(), ast_privacy_check(), ast_privacy_set(), dial_exec_full(), handle_setcallerid(), misdn_new(), play_message_callerid(), read_config(), and unistim_new().

1010 {
1011  char *ls;
1012  char *le;
1013  char *name_start;
1014  char *instr;
1015  int quotes_stripped = 0;
1016 
1017  /* Handle surrounding quotes */
1018  input_str = ast_strip(input_str);
1019  instr = ast_strip_quoted(input_str, "\"", "\"");
1020  if (instr != input_str) {
1021  quotes_stripped = 1;
1022  }
1023 
1024  /* Try "name" <location> format or name <location> format or with a missing > */
1025  if ((ls = strrchr(instr, '<'))) {
1026  if ((le = strrchr(ls, '>'))) {
1027  *le = '\0'; /* location found, trim off the brackets */
1028  }
1029  *ls = '\0';
1030  *location = ls + 1; /* and this is the result */
1031 
1032  name_start = ast_strip_quoted(instr, "\"", "\"");
1033  } else { /* no valid brackets */
1034  char tmp[256];
1035 
1036  ast_copy_string(tmp, instr, sizeof(tmp));
1038  if (!quotes_stripped && ast_isphonenumber(tmp)) { /* Assume it's just a location */
1039  name_start = NULL;
1040  strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
1041  *location = instr;
1042  } else { /* Assume it's just a name. */
1043  *location = NULL;
1044  name_start = ast_strip_quoted(instr, "\"", "\"");
1045  }
1046  }
1047 
1048  if (name_start) {
1049  ast_unescape_quoted(name_start);
1050  }
1051  *name = name_start;
1052  return 0;
1053 }
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
Definition: utils.c:1431
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
Definition: utils.c:461
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
static const char name[]
int ast_isphonenumber(const char *n)
Check if a string consists only of digits and + #.
Definition: callerid.c:999
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:948
int ast_callerid_split ( const char *  src,
char *  name,
int  namelen,
char *  num,
int  numlen 
)

Definition at line 1093 of file callerid.c.

References ast_callerid_parse(), ast_copy_string(), ast_shrink_phone_number(), and ast_strdupa.

Referenced by apply_outgoing(), build_gateway(), build_peer(), build_user(), callerid_read(), config_parse_variables(), disa_exec(), load_module(), party_id_write(), prep_email_sub_vars(), process_dahdi(), store_callerid(), and update_common_options().

1094 {
1095  char *tmp;
1096  char *l = NULL, *n = NULL;
1097 
1098  tmp = ast_strdupa(buf);
1099  ast_callerid_parse(tmp, &n, &l);
1100  if (n)
1101  ast_copy_string(name, n, namelen);
1102  else
1103  name[0] = '\0';
1104  if (l) {
1106  ast_copy_string(num, l, numlen);
1107  } else
1108  num[0] = '\0';
1109  return 0;
1110 }
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static const char name[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:948
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1009
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.

Parameters
buf
activeThe message indicator state – either 0 no messages in mailbox or 1 messages in mailbox
typeFormat of message (any of CID_MWI_TYPE_*)
codec
name
number
flags
See Also
callerid_generate() for more info as it uses the same encoding
Version
1.6.1 changed mdmf parameter to type, added name, number and flags for caller id message generation

Definition at line 811 of file callerid.c.

References callerid_genmsg(), CID_MWI_TYPE_MDMF, CID_MWI_TYPE_MDMF_FULL, len(), PUT_BYTE, PUT_CLID, and PUT_CLID_MARKMS.

Referenced by mwi_send_init().

813 {
814  char msg[256];
815  int len = 0;
816  int sum;
817  int x;
818  int bytes = 0;
819  float cr = 1.0;
820  float ci = 0.0;
821  float scont = 0.0;
822 
823  if (type == CID_MWI_TYPE_MDMF_FULL) {
824  /* MDMF Message waiting with date, number, name and MWI parameter */
825  msg[0] = 0x82;
826 
827  /* put date, number info at the right place */
828  len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags);
829 
830  /* length of MDMF CLI plus Message Waiting Structure */
831  msg[1] = len+3;
832 
833  /* Go to the position to write to */
834  len = len+2;
835 
836  /* "Message Waiting Parameter" */
837  msg[len++] = 0x0b;
838  /* Length of IE is one */
839  msg[len++] = 1;
840  /* Active or not */
841  if (active)
842  msg[len++] = 0xff;
843  else
844  msg[len++] = 0x00;
845 
846  } else if (type == CID_MWI_TYPE_MDMF) {
847  /* MDMF Message waiting only */
848  /* same as above except that the we only put MWI parameter */
849  msg[len++] = 0x82;
850  /* Length is 3 */
851  msg[len++] = 3;
852  /* IE is "Message Waiting Parameter" */
853  msg[len++] = 0x0b;
854  /* Length of IE is one */
855  msg[len++] = 1;
856  /* Active or not */
857  if (active)
858  msg[len++] = 0xff;
859  else
860  msg[len++] = 0x00;
861  } else {
862  /* SDMF Message waiting */
863  msg[len++] = 0x6;
864  /* Length is 3 */
865  msg[len++] = 3;
866  if (active) {
867  msg[len++] = 0x42;
868  msg[len++] = 0x42;
869  msg[len++] = 0x42;
870  } else {
871  msg[len++] = 0x6f;
872  msg[len++] = 0x6f;
873  msg[len++] = 0x6f;
874  }
875  }
876  sum = 0;
877  for (x = 0; x < len; x++)
878  sum += msg[x];
879  sum = (256 - (sum & 255));
880  msg[len++] = sum;
881  /* Wait a half a second */
882  for (x = 0; x < 4000; x++)
883  PUT_BYTE(0x7f);
884  /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
885  for (x = 0; x < 30; x++)
886  PUT_CLID(0x55);
887  /* Send 170ms of callerid marks */
888  for (x = 0; x < 170; x++)
890  for (x = 0; x < len; x++) {
891  PUT_CLID(msg[x]);
892  }
893  /* Send 50 more ms of marks */
894  for (x = 0; x < 50; x++)
896  return bytes;
897 }
#define CID_MWI_TYPE_MDMF_FULL
Definition: callerid.h:76
#define PUT_BYTE(a)
Definition: callerid.h:278
Number structure.
Definition: app_followme.c:109
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags)
Definition: callerid.c:740
static const char name[]
static const char type[]
Definition: chan_nbs.c:57
#define PUT_CLID(byte)
Definition: callerid.h:304
#define PUT_CLID_MARKMS
Definition: callerid.h:289
#define CID_MWI_TYPE_MDMF
Definition: callerid.h:74
const char* ast_connected_line_source_describe ( int  data)

Convert connected line update source value to explanatory string.

Since
1.8
Parameters
dataAST_CONNECTED_LINE_UPDATE_SOURCE from callerid.h
Returns
string for human presentation

Definition at line 1278 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

1279 {
1280  int index;
1281 
1282  for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1283  if (connected_line_source_types[index].value == data) {
1285  }
1286  }
1287 
1288  return "not-known";
1289 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
const char * description
Definition: callerid.c:1115
static struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1254
const char* ast_connected_line_source_name ( int  data)

Convert connected line update source value to text code.

Since
1.8
Parameters
dataAST_CONNECTED_LINE_UPDATE_SOURCE from callerid.h
Returns
string for config file

Definition at line 1291 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by connectedline_read().

1292 {
1293  int index;
1294 
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;
1298  }
1299  }
1300 
1301  return "not-known";
1302 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1254
const char * name
Definition: callerid.c:1114
int ast_connected_line_source_parse ( const char *  data)

Convert connected line update source text code to value (used in config file parsing)

Since
1.8
Parameters
datatext string from config file
Return values
AST_CONNECTED_LINE_UPDATE_SOURCEfrom callerid.h
-1if not in table

Definition at line 1265 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by connectedline_write().

1266 {
1267  int index;
1268 
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;
1272  }
1273  }
1274 
1275  return -1;
1276 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
static struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1254
const char* ast_describe_caller_presentation ( int  data)

Convert caller ID pres value to explanatory string.

Parameters
dataAST_PRES_ value from callerid.h
Returns
string for human presentation

Definition at line 1165 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

Referenced by _sip_show_peer(), peers_data_provider_get(), report_new_callerid(), sig_pri_event_party_id(), and sip_show_user().

1166 {
1167  int index;
1168 
1169  for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1170  if (pres_types[index].value == data) {
1171  return pres_types[index].description;
1172  }
1173  }
1174 
1175  return "unknown";
1176 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
const char * description
Definition: callerid.c:1115
static struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Definition: callerid.c:1119
int ast_gen_cas ( unsigned char *  outbuf,
int  sas,
int  len,
format_t  codec 
)

Generate a CAS (CPE Alert Signal) tone for 'n' samples.

Parameters
outbufAllocated buffer for data. Must be at least 2400 bytes unless no SAS is desired
sasNon-zero if CAS should be preceeded by SAS
lenHow many samples to generate.
codecWhich codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)
Returns
Returns -1 on error (if len is less than 2400), 0 on success.

Definition at line 262 of file callerid.c.

References gen_tone(), gen_tones(), and callerid_state::pos.

Referenced by __adsi_transmit_messages(), dahdi_callwait(), and my_callwait().

263 {
264  int pos = 0;
265  int saslen = 2400;
266  float cr1 = 1.0;
267  float ci1 = 0.0;
268  float cr2 = 1.0;
269  float ci2 = 0.0;
270 
271  if (sendsas) {
272  if (len < saslen)
273  return -1;
274  gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1);
275  len -= saslen;
276  pos += saslen;
277  cr2 = cr1;
278  ci2 = ci1;
279  }
280  gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2);
281  return 0;
282 }
float casdr1
Definition: callerid.c:68
float sasdi
Definition: callerid.c:67
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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)
Definition: callerid.c:78
float sasdr
Definition: callerid.c:67
float casdr2
Definition: callerid.c:68
float casdi2
Definition: callerid.c:68
static void gen_tone(unsigned char *buf, int len, format_t codec, float ddr1, float ddi1, float *cr1, float *ci1)
Definition: callerid.c:100
float casdi1
Definition: callerid.c:68
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_shrink_phone_number)

Parameters
extenThe extension (or URI) to be checked.
Return values
1if string is valid AST shrinkable phone number
0if not

Definition at line 1004 of file callerid.c.

References ast_is_valid_string().

Referenced by check_peer_ok(), check_user_full(), get_pai(), and get_rpid().

1005 {
1006  return ast_is_valid_string(exten, "0123456789*#+()-.");
1007 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
Definition: callerid.c:987
int ast_isphonenumber ( const char *  n)

Check if a string consists only of digits and + #.

Parameters
nnumber to be checked.
Returns
Returns 0 if n is a number, 1 if it's not.

Definition at line 999 of file callerid.c.

References ast_is_valid_string().

Referenced by ast_callerid_parse().

1000 {
1001  return ast_is_valid_string(n, "0123456789*#+");
1002 }
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
Definition: callerid.c:987
const char* ast_named_caller_presentation ( int  data)

Convert caller ID pres value to text code.

Parameters
dataAST_PRES_ value from callerid.h
Returns
string for config file

Definition at line 1183 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by callerpres_read(), party_id_read(), party_name_read(), party_number_read(), and redirecting_read().

1184 {
1185  int index;
1186 
1187  for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1188  if (pres_types[index].value == data) {
1189  return pres_types[index].name;
1190  }
1191  }
1192 
1193  return "unknown";
1194 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Definition: callerid.c:1119
const char * name
Definition: callerid.c:1114
int ast_parse_caller_presentation ( const char *  data)

Convert caller ID text code to value (used in config file parsing)

Parameters
datatext string from config file
Return values
valueAST_PRES_ from callerid.h
-1if not in table

Definition at line 1144 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by build_peer(), callerpres_write(), dial_exec_full(), party_id_write(), party_name_write(), party_number_write(), redirecting_write(), and setcallerid_pres_exec().

1145 {
1146  int index;
1147  if (!data) {
1148  return -1;
1149  }
1150 
1151  for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1152  if (!strcasecmp(pres_types[index].name, data)) {
1153  return pres_types[index].value;
1154  }
1155  }
1156 
1157  return -1;
1158 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Definition: callerid.c:1119
static const char name[]
const char* ast_party_name_charset_describe ( int  data)

Convert ast_party_name.char_set value to explanatory string.

Since
1.8
Parameters
dataAST_PARTY_CHAR_SET from channel.h
Returns
string for human presentation

Definition at line 1333 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

Referenced by sig_pri_event_party_id().

1334 {
1335  int index;
1336 
1337  for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1338  if (party_name_charset_tbl[index].value == data) {
1339  return party_name_charset_tbl[index].description;
1340  }
1341  }
1342 
1343  return "not-known";
1344 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
const char * description
Definition: callerid.c:1115
static struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1305
int ast_party_name_charset_parse ( const char *  data)

Convert ast_party_name.char_set text code to value (used in config file parsing)

Since
1.8
Parameters
datatext string from config file
Return values
AST_PARTY_CHAR_SETfrom channel.h
-1if not in table

Definition at line 1320 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by party_name_write().

1321 {
1322  int index;
1323 
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;
1327  }
1328  }
1329 
1330  return -1;
1331 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
static struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1305
const char* ast_party_name_charset_str ( int  data)

Convert ast_party_name.char_set value to text code.

Since
1.8
Parameters
dataAST_PARTY_CHAR_SET from channel.h
Returns
string for config file

Definition at line 1346 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by party_name_read().

1347 {
1348  int index;
1349 
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;
1353  }
1354  }
1355 
1356  return "not-known";
1357 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1305
const char * name
Definition: callerid.c:1114
const char* ast_redirecting_reason_describe ( int  data)

Convert redirecting reason value to explanatory string.

Since
1.8
Parameters
dataQ931_REDIRECTING_REASON from callerid.h
Returns
string for human presentation

Definition at line 1227 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

1228 {
1229  int index;
1230 
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;
1234  }
1235  }
1236 
1237  return "not-known";
1238 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
const char * description
Definition: callerid.c:1115
static struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1197
const char* ast_redirecting_reason_name ( int  data)

Convert redirecting reason value to text code.

Since
1.8
Parameters
dataQ931_REDIRECTING_REASON from callerid.h
Returns
string for config file

Definition at line 1240 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by redirecting_read().

1241 {
1242  int index;
1243 
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;
1247  }
1248  }
1249 
1250  return "not-known";
1251 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1197
const char * name
Definition: callerid.c:1114
int ast_redirecting_reason_parse ( const char *  data)

Convert redirecting reason text code to value (used in config file parsing)

Since
1.8
Parameters
datatext string from config file
Return values
Q931_REDIRECTING_REASONfrom callerid.h
-1if not in table

Definition at line 1214 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by redirecting_write().

1215 {
1216  int index;
1217 
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;
1221  }
1222  }
1223 
1224  return -1;
1225 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
static struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1197
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...

Parameters
nThe number to be stripped/shrunk
Returns
Returns nothing important

Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...

Remove '(', ' ', ')', non-trailing '.', and '-' not in square brackets. Basically, remove anything that could be invalid in a pattern.

Definition at line 948 of file callerid.c.

Referenced by __analog_ss_thread(), action_originate(), analog_ss_thread(), ast_callerid_parse(), ast_callerid_split(), ast_privacy_check(), ast_privacy_set(), check_access(), check_peer_ok(), check_user_full(), get_pai(), get_rpid(), handle_setcallerid(), pbx_load_config(), pri_dchannel(), setup_privacy_args(), and write_metadata().

949 {
950  int x, y = 0;
951  int bracketed = 0;
952 
953  for (x = 0; n[x]; x++) {
954  switch (n[x]) {
955  case '[':
956  bracketed++;
957  n[y++] = n[x];
958  break;
959  case ']':
960  bracketed--;
961  n[y++] = n[x];
962  break;
963  case '-':
964  if (bracketed)
965  n[y++] = n[x];
966  break;
967  case '.':
968  if (!n[x+1])
969  n[y++] = n[x];
970  break;
971  default:
972  /* ignore parenthesis and whitespace */
973  if (!strchr("( )", n[x]))
974  n[y++] = n[x];
975  }
976  }
977  n[y] = '\0';
978 }
int callerid_feed ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
format_t  codec 
)

Read samples into the state machine.

Parameters
cidWhich state machine to act upon
ubufcontaining your samples
samplesnumber of samples contained within the buffer.
codecwhich codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)

Send received audio to the Caller*ID demodulator.

Return values
-1on error
0for "needs more samples"
1if the CallerID spill reception is complete.

Definition at line 546 of file callerid.c.

References ast_alloca, ast_copy_string(), ast_log(), ast_strlen_zero(), AST_XLAW, CID_MSGWAITING, CID_NOMSGWAITING, CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, callerid_state::cksum, callerid_state::flags, fsk_serial(), callerid_state::fskd, callerid_state::len, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, 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 analog_ss_thread(), mwi_thread(), and my_get_callerid().

547 {
548  int mylen = len;
549  int olen;
550  int b = 'X';
551  int res;
552  int x;
553  short *buf;
554 
555  buf = ast_alloca(2 * len + cid->oldlen);
556 
557  memcpy(buf, cid->oldstuff, cid->oldlen);
558  mylen += cid->oldlen/2;
559 
560  for (x = 0; x < len; x++)
561  buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
562  while (mylen >= 160) {
563  olen = mylen;
564  res = fsk_serial(&cid->fskd, buf, &mylen, &b);
565  if (mylen < 0) {
566  ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
567  return -1;
568  }
569  buf += (olen - mylen);
570  if (res < 0) {
571  ast_log(LOG_NOTICE, "fsk_serial failed\n");
572  return -1;
573  }
574  if (res == 1) {
575  if (b > 0xff) {
576  if (cid->sawflag != 5) {
577  /* Ignore invalid bytes */
578  continue;
579  }
580  /*
581  * We can tollerate an error on the checksum character since the
582  * checksum character is the last character in the message and
583  * it validates the message.
584  *
585  * Remove character error flags.
586  * Bit 8 : Parity error
587  * Bit 9 : Framing error
588  */
589  b &= 0xff;
590  }
591  switch (cid->sawflag) {
592  case 0: /* Look for flag */
593  if (b == 'U')
594  cid->sawflag = 2;
595  break;
596  case 2: /* Get lead-in */
597  if ((b == 0x04) || (b == 0x80) || (b == 0x06) || (b == 0x82)) {
598  cid->type = b;
599  cid->sawflag = 3;
600  cid->cksum = b;
601  }
602  break;
603  case 3: /* Get length */
604  /* Not a lead in. We're ready */
605  cid->sawflag = 4;
606  cid->len = b;
607  cid->pos = 0;
608  cid->cksum += b;
609  break;
610  case 4: /* Retrieve message */
611  if (cid->pos >= 128) {
612  ast_log(LOG_WARNING, "Caller ID too long???\n");
613  return -1;
614  }
615  cid->rawdata[cid->pos++] = b;
616  cid->len--;
617  cid->cksum += b;
618  if (!cid->len) {
619  cid->rawdata[cid->pos] = '\0';
620  cid->sawflag = 5;
621  }
622  break;
623  case 5: /* Check checksum */
624  if ((b + cid->cksum) & 0xff) {
625  ast_log(LOG_NOTICE, "Caller*ID failed checksum\n");
626  /* Try again */
627  cid->sawflag = 0;
628  break;
629  }
630 
631  cid->number[0] = '\0';
632  cid->name[0] = '\0';
633  /* Update flags */
634  cid->flags = 0;
635  /* If we get this far we're fine. */
636  if ((cid->type == 0x80) || (cid->type == 0x82)) {
637  /* MDMF */
638  /* Go through each element and process */
639  for (x = 0; x < cid->pos;) {
640  switch (cid->rawdata[x++]) {
641  case 1:
642  /* Date */
643  break;
644  case 2: /* Number */
645  case 3: /* Number (for Zebble) */
646  case 4: /* Number */
647  res = cid->rawdata[x];
648  if (res > 32) {
649  ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]);
650  res = 32;
651  }
652  if (ast_strlen_zero(cid->number)) {
653  memcpy(cid->number, cid->rawdata + x + 1, res);
654  /* Null terminate */
655  cid->number[res] = '\0';
656  }
657  break;
658  case 6: /* Stentor Call Qualifier (ie. Long Distance call) */
659  break;
660  case 7: /* Name */
661  case 8: /* Name */
662  res = cid->rawdata[x];
663  if (res > 32) {
664  ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]);
665  res = 32;
666  }
667  memcpy(cid->name, cid->rawdata + x + 1, res);
668  cid->name[res] = '\0';
669  break;
670  case 11: /* Message Waiting */
671  res = cid->rawdata[x + 1];
672  if (res)
673  cid->flags |= CID_MSGWAITING;
674  else
675  cid->flags |= CID_NOMSGWAITING;
676  break;
677  case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting */
678  case 19: /* UK: Network message system status (Number of messages waiting) */
679  case 22: /* Something French */
680  break;
681  default:
682  ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x - 1]);
683  }
684  res = cid->rawdata[x];
685  if (0 > res){ /* Negative offset in the CID Spill */
686  ast_log(LOG_NOTICE, "IE %d has bad field length of %d at offset %d\n", cid->rawdata[x-1], cid->rawdata[x], x);
687  /* Try again */
688  cid->sawflag = 0;
689  break; /* Exit the loop */
690  }
691  x += cid->rawdata[x];
692  x++;
693  }
694  } else if (cid->type == 0x6) {
695  /* VMWI SDMF */
696  if (cid->rawdata[2] == 0x42) {
697  cid->flags |= CID_MSGWAITING;
698  } else if (cid->rawdata[2] == 0x6f) {
699  cid->flags |= CID_NOMSGWAITING;
700  }
701  } else {
702  /* SDMF */
703  ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number));
704  }
705  if (!strcmp(cid->number, "P")) {
706  strcpy(cid->number, "");
707  cid->flags |= CID_PRIVATE_NUMBER;
708  } else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) {
709  strcpy(cid->number, "");
710  cid->flags |= CID_UNKNOWN_NUMBER;
711  }
712  if (!strcmp(cid->name, "P")) {
713  strcpy(cid->name, "");
714  cid->flags |= CID_PRIVATE_NAME;
715  } else if (!strcmp(cid->name, "O") || ast_strlen_zero(cid->name)) {
716  strcpy(cid->name, "");
717  cid->flags |= CID_UNKNOWN_NAME;
718  }
719  return 1;
720  break;
721  default:
722  ast_log(LOG_ERROR, "Dunno what to do with a digit in sawflag %d\n", cid->sawflag);
723  }
724  }
725  }
726  if (mylen) {
727  memcpy(cid->oldstuff, buf, mylen * 2);
728  cid->oldlen = mylen * 2;
729  } else
730  cid->oldlen = 0;
731 
732  return 0;
733 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
#define CID_MSGWAITING
Definition: callerid.h:56
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
#define AST_XLAW(a)
Definition: callerid.h:79
#define LOG_WARNING
Definition: logger.h:144
#define CID_NOMSGWAITING
Definition: callerid.h:57
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define CID_PRIVATE_NAME
Definition: callerid.h:52
#define CID_PRIVATE_NUMBER
Definition: callerid.h:53
#define LOG_ERROR
Definition: logger.h:155
char name[64]
Definition: callerid.c:54
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...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
short oldstuff[160]
Definition: callerid.c:49
#define CID_UNKNOWN_NAME
Definition: callerid.h:54
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
char rawdata[256]
Definition: callerid.c:48
char number[64]
Definition: callerid.c:55
fsk_data fskd
Definition: callerid.c:47
int callerid_feed_jp ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
format_t  codec 
)

Read samples into the state machine.

Parameters
cidWhich state machine to act upon
ubufcontaining your samples
samplesnumber of samples contained within the buffer.
codecwhich codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)

Send received audio to the Caller*ID demodulator (for japanese style lines).

Return values
-1on error
0for "needs more samples"
1if the CallerID spill reception is complete.

Definition at line 307 of file callerid.c.

References ast_alloca, ast_copy_string(), ast_debug, ast_log(), AST_XLAW, calc_crc(), CID_UNKNOWN_NUMBER, continue, callerid_state::crc, callerid_state::flags, fsk_serial(), callerid_state::fskd, callerid_state::len, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, callerid_state::name, callerid_state::number, callerid_state::oldlen, callerid_state::oldstuff, option_debug, callerid_state::pos, callerid_state::rawdata, callerid_state::sawflag, and callerid_state::skipflag.

Referenced by analog_ss_thread(), and my_get_callerid().

308 {
309  int mylen = len;
310  int olen;
311  int b = 'X';
312  int b2;
313  int res;
314  int x;
315  short *buf;
316 
317  buf = ast_alloca(2 * len + cid->oldlen);
318 
319  memcpy(buf, cid->oldstuff, cid->oldlen);
320  mylen += cid->oldlen / 2;
321 
322  for (x = 0; x < len; x++)
323  buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
324 
325  while (mylen >= 160) {
326  b = b2 = 0;
327  olen = mylen;
328  res = fsk_serial(&cid->fskd, buf, &mylen, &b);
329 
330  if (mylen < 0) {
331  ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
332  return -1;
333  }
334 
335  buf += (olen - mylen);
336 
337  if (res < 0) {
338  ast_log(LOG_NOTICE, "fsk_serial failed\n");
339  return -1;
340  }
341 
342  if (res == 1) {
343  b2 = b;
344  b &= 0x7f;
345 
346  /* crc checksum calculation */
347  if (cid->sawflag > 1)
348  cid->crc = calc_crc(cid->crc, (unsigned char) b2);
349 
350  /* Ignore invalid bytes */
351  if (b > 0xff)
352  continue;
353 
354  /* skip DLE if needed */
355  if (cid->sawflag > 0) {
356  if (cid->sawflag != 5 && cid->skipflag == 0 && b == 0x10) {
357  cid->skipflag = 1 ;
358  continue ;
359  }
360  }
361  if (cid->skipflag == 1)
362  cid->skipflag = 0 ;
363 
364  /* caller id retrieval */
365  switch (cid->sawflag) {
366  case 0: /* DLE */
367  if (b == 0x10) {
368  cid->sawflag = 1;
369  cid->skipflag = 0;
370  cid->crc = 0;
371  }
372  break;
373  case 1: /* SOH */
374  if (b == 0x01)
375  cid->sawflag = 2;
376  break ;
377  case 2: /* HEADER */
378  if (b == 0x07)
379  cid->sawflag = 3;
380  break;
381  case 3: /* STX */
382  if (b == 0x02)
383  cid->sawflag = 4;
384  break;
385  case 4: /* SERVICE TYPE */
386  if (b == 0x40)
387  cid->sawflag = 5;
388  break;
389  case 5: /* Frame Length */
390  cid->sawflag = 6;
391  break;
392  case 6: /* NUMBER TYPE */
393  cid->sawflag = 7;
394  cid->pos = 0;
395  cid->rawdata[cid->pos++] = b;
396  break;
397  case 7: /* NUMBER LENGTH */
398  cid->sawflag = 8;
399  cid->len = b;
400  if ((cid->len+2) >= sizeof(cid->rawdata)) {
401  ast_log(LOG_WARNING, "too long caller id string\n") ;
402  return -1;
403  }
404  cid->rawdata[cid->pos++] = b;
405  break;
406  case 8: /* Retrieve message */
407  cid->rawdata[cid->pos++] = b;
408  cid->len--;
409  if (cid->len<=0) {
410  cid->rawdata[cid->pos] = '\0';
411  cid->sawflag = 9;
412  }
413  break;
414  case 9: /* ETX */
415  cid->sawflag = 10;
416  break;
417  case 10: /* CRC Checksum 1 */
418  cid->sawflag = 11;
419  break;
420  case 11: /* CRC Checksum 2 */
421  cid->sawflag = 12;
422  if (cid->crc != 0) {
423  ast_log(LOG_WARNING, "crc checksum error\n") ;
424  return -1;
425  }
426  /* extract caller id data */
427  for (x = 0; x < cid->pos;) {
428  switch (cid->rawdata[x++]) {
429  case 0x02: /* caller id number */
430  cid->number[0] = '\0';
431  cid->name[0] = '\0';
432  cid->flags = 0;
433  res = cid->rawdata[x++];
434  ast_copy_string(cid->number, &cid->rawdata[x], res+1);
435  x += res;
436  break;
437  case 0x21: /* additional information */
438  /* length */
439  x++;
440  /* number type */
441  switch (cid->rawdata[x]) {
442  case 0x00: /* unknown */
443  case 0x01: /* international number */
444  case 0x02: /* domestic number */
445  case 0x03: /* network */
446  case 0x04: /* local call */
447  case 0x06: /* short dial number */
448  case 0x07: /* reserved */
449  default: /* reserved */
450  ast_debug(2, "cid info:#1=%X\n", (unsigned)cid->rawdata[x]);
451  break ;
452  }
453  x++;
454  /* numbering plan octed 4 */
455  x++;
456  /* numbering plan octed 5 */
457  switch (cid->rawdata[x]) {
458  case 0x00: /* unknown */
459  case 0x01: /* recommendation E.164 ISDN */
460  case 0x03: /* recommendation X.121 */
461  case 0x04: /* telex dial plan */
462  case 0x08: /* domestic dial plan */
463  case 0x09: /* private dial plan */
464  case 0x05: /* reserved */
465  default: /* reserved */
466  ast_debug(2, "cid info:#2=%X\n", (unsigned)cid->rawdata[x]);
467  break ;
468  }
469  x++;
470  break ;
471  case 0x04: /* no callerid reason */
472  /* length */
473  x++;
474  /* no callerid reason code */
475  switch (cid->rawdata[x]) {
476  case 'P': /* caller id denied by user */
477  case 'O': /* service not available */
478  case 'C': /* pay phone */
479  case 'S': /* service congested */
480  cid->flags |= CID_UNKNOWN_NUMBER;
481  ast_debug(2, "no cid reason:%c\n", cid->rawdata[x]);
482  break ;
483  }
484  x++;
485  break ;
486  case 0x09: /* dialed number */
487  /* length */
488  res = cid->rawdata[x++];
489  /* dialed number */
490  x += res;
491  break ;
492  case 0x22: /* dialed number additional information */
493  /* length */
494  x++;
495  /* number type */
496  switch (cid->rawdata[x]) {
497  case 0x00: /* unknown */
498  case 0x01: /* international number */
499  case 0x02: /* domestic number */
500  case 0x03: /* network */
501  case 0x04: /* local call */
502  case 0x06: /* short dial number */
503  case 0x07: /* reserved */
504  default: /* reserved */
505  if (option_debug > 1)
506  ast_log(LOG_NOTICE, "did info:#1=%X\n", (unsigned)cid->rawdata[x]);
507  break ;
508  }
509  x++;
510  /* numbering plan octed 4 */
511  x++;
512  /* numbering plan octed 5 */
513  switch (cid->rawdata[x]) {
514  case 0x00: /* unknown */
515  case 0x01: /* recommendation E.164 ISDN */
516  case 0x03: /* recommendation X.121 */
517  case 0x04: /* telex dial plan */
518  case 0x08: /* domestic dial plan */
519  case 0x09: /* private dial plan */
520  case 0x05: /* reserved */
521  default: /* reserved */
522  ast_debug(2, "did info:#2=%X\n", (unsigned)cid->rawdata[x]);
523  break ;
524  }
525  x++;
526  break ;
527  }
528  }
529  return 1;
530  break;
531  default:
532  ast_log(LOG_ERROR, "invalid value in sawflag %d\n", cid->sawflag);
533  }
534  }
535  }
536  if (mylen) {
537  memcpy(cid->oldstuff, buf, mylen * 2);
538  cid->oldlen = mylen * 2;
539  } else
540  cid->oldlen = 0;
541 
542  return 0;
543 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
int option_debug
Definition: asterisk.c:182
#define AST_XLAW(a)
Definition: callerid.h:79
unsigned short crc
Definition: callerid.c:61
#define LOG_WARNING
Definition: logger.h:144
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define LOG_ERROR
Definition: logger.h:155
char name[64]
Definition: callerid.c:54
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...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
short oldstuff[160]
Definition: callerid.c:49
continue
Definition: ast_expr2.c:1263
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static unsigned short calc_crc(unsigned short crc, unsigned char data)
Definition: callerid.c:284
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
char rawdata[256]
Definition: callerid.c:48
char number[64]
Definition: callerid.c:55
fsk_data fskd
Definition: callerid.c:47
void callerid_free ( struct callerid_state cid)

This function frees callerid_state cid.

Parameters
cidThis is the callerid_state state machine to free

Definition at line 735 of file callerid.c.

References ast_free.

Referenced by __analog_ss_thread(), analog_ss_thread(), mwi_thread(), and my_stop_cid_detect().

736 {
737  ast_free(cid);
738 }
#define ast_free(a)
Definition: astmm.h:97
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.

Parameters
bufBuffer 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.
numberUse NULL for no number or "P" for "private"
namename to be used
flagspassed flags
callwaitingcallwaiting flag
codec– either AST_FORMAT_ULAW or AST_FORMAT_ALAW

This function creates a stream of callerid (a callerid spill) data in ulaw format.

Returns
It returns the size (in bytes) of the data (if it returns a size of 0, there is probably an error)

Definition at line 899 of file callerid.c.

References callerid_genmsg(), len(), PUT_BYTE, PUT_CLID, and PUT_CLID_MARKMS.

Referenced by __ast_callerid_generate().

900 {
901  int bytes = 0;
902  int x, sum;
903  int len;
904 
905  /* Initial carriers (real/imaginary) */
906  float cr = 1.0;
907  float ci = 0.0;
908  float scont = 0.0;
909  char msg[256];
910  len = callerid_genmsg(msg, sizeof(msg), number, name, flags);
911  if (!callwaiting) {
912  /* Wait a half a second */
913  for (x = 0; x < 4000; x++)
914  PUT_BYTE(0x7f);
915  /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
916  for (x = 0; x < 30; x++)
917  PUT_CLID(0x55);
918  }
919  /* Send 150ms of callerid marks */
920  for (x = 0; x < 150; x++)
922  /* Send 0x80 indicating MDMF format */
923  PUT_CLID(0x80);
924  /* Put length of whole message */
925  PUT_CLID(len);
926  sum = 0x80 + strlen(msg);
927  /* Put each character of message and update checksum */
928  for (x = 0; x < len; x++) {
929  PUT_CLID(msg[x]);
930  sum += msg[x];
931  }
932  /* Send 2's compliment of sum */
933  PUT_CLID(256 - (sum & 255));
934 
935  /* Send 50 more ms of marks */
936  for (x = 0; x < 50; x++)
938 
939  return bytes;
940 }
static int callwaiting
Definition: chan_mgcp.c:178
#define PUT_BYTE(a)
Definition: callerid.h:278
Number structure.
Definition: app_followme.c:109
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags)
Definition: callerid.c:740
static const char name[]
#define PUT_CLID(byte)
Definition: callerid.h:304
#define PUT_CLID_MARKMS
Definition: callerid.h:289
void callerid_get ( struct callerid_state cid,
char **  number,
char **  name,
int *  flags 
)

Extract info out of callerID state machine. Flags are listed above.

Parameters
cidCallerid state machine to act upon
numberPass the address of a pointer-to-char (will contain the phone number)
namePass the address of a pointer-to-char (will contain the name)
flagsPass the address of an int variable(will contain the various callerid flags)

This function extracts a callerid string out of a callerid_state state machine. If no number is found, *number will be set to NULL. Likewise for the name. Flags can contain any of the following:

Returns
Returns nothing.

Definition at line 189 of file callerid.c.

References CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, callerid_state::flags, callerid_state::name, and callerid_state::number.

Referenced by analog_ss_thread(), mwi_thread(), and my_get_callerid().

190 {
191  *flags = cid->flags;
192  if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NAME))
193  *name = NULL;
194  else
195  *name = cid->name;
197  *number = NULL;
198  else
199  *number = cid->number;
200 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
Number structure.
Definition: app_followme.c:109
#define CID_PRIVATE_NAME
Definition: callerid.h:52
#define CID_PRIVATE_NUMBER
Definition: callerid.h:53
char name[64]
Definition: callerid.c:54
static const char name[]
#define CID_UNKNOWN_NAME
Definition: callerid.h:54
char number[64]
Definition: callerid.c:55
void callerid_get_dtmf ( char *  cidstring,
char *  number,
int *  flags 
)

Get and parse DTMF-based callerid.

Parameters
cidstringThe actual transmitted string.
numberThe cid number is returned here.
flagsThe cid flags are returned here.

Definition at line 202 of file callerid.c.

References ast_debug, ast_log(), CID_PRIVATE_NUMBER, CID_UNKNOWN_NUMBER, and LOG_WARNING.

Referenced by __analog_ss_thread(), and analog_ss_thread().

203 {
204  int i;
205  int code;
206 
207  /* "Clear" the number-buffer. */
208  number[0] = 0;
209 
210  if (strlen(cidstring) < 2) {
211  ast_debug(1, "No cid detected\n");
213  return;
214  }
215 
216  /* Detect protocol and special types */
217  if (cidstring[0] == 'B') {
218  /* Handle special codes */
219  code = atoi(&cidstring[1]);
220  if (code == 0)
222  else if (code == 10)
224  else
225  ast_debug(1, "Unknown DTMF code %d\n", code);
226  } else if (cidstring[0] == 'D' && cidstring[2] == '#') {
227  /* .DK special code */
228  if (cidstring[1] == '1')
230  if (cidstring[1] == '2' || cidstring[1] == '3')
232  } else if (cidstring[0] == 'D' || cidstring[0] == 'A') {
233  /* "Standard" callerid */
234  for (i = 1; i < strlen(cidstring); i++) {
235  if (cidstring[i] == 'C' || cidstring[i] == '#')
236  break;
237  if (isdigit(cidstring[i]))
238  number[i-1] = cidstring[i];
239  else
240  ast_debug(1, "Unknown CID digit '%c'\n",
241  cidstring[i]);
242  }
243  number[i-1] = 0;
244  } else if (isdigit(cidstring[0])) {
245  /* It begins with a digit, so we parse it as a number and hope
246  * for the best */
247  ast_log(LOG_WARNING, "Couldn't detect start-character. CID "
248  "parsing might be unreliable\n");
249  for (i = 0; i < strlen(cidstring); i++) {
250  if (isdigit(cidstring[i]))
251  number[i] = cidstring[i];
252  else
253  break;
254  }
255  number[i] = 0;
256  } else {
257  ast_debug(1, "Unknown CID protocol, start digit '%c'\n", cidstring[0]);
259  }
260 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
#define LOG_WARNING
Definition: logger.h:144
Number structure.
Definition: app_followme.c:109
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define CID_PRIVATE_NUMBER
Definition: callerid.h:53
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...
Definition: logger.c:1207
static float callerid_getcarrier ( float *  cr,
float *  ci,
int  bit 
)
inlinestatic

Definition at line 264 of file callerid.h.

References cid_di, and cid_dr.

265 {
266  /* Move along. There's nothing to see here... */
267  float t;
268  t = *cr * cid_dr[bit] - *ci * cid_di[bit];
269  *ci = *cr * cid_di[bit] + *ci * cid_dr[bit];
270  *cr = t;
271 
272  t = 2.0 - (*cr * *cr + *ci * *ci);
273  *cr *= t;
274  *ci *= t;
275  return *cr;
276 }
float cid_di[4]
Definition: callerid.c:65
float cid_dr[4]
Definition: callerid.c:65
void callerid_init ( void  )

CallerID Initialization.

Initializes the callerid system. Mostly stuff for inverse FFT

CallerID Initialization.

Definition at line 116 of file callerid.c.

References CALLERID_MARK, CALLERID_SPACE, CAS_FREQ1, CAS_FREQ2, cos, M_PI, and SAS_FREQ.

Referenced by main().

117 {
118  cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
119  cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
120  cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0);
121  cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0);
122  sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0);
123  sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0);
124  casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
125  casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
126  casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
127  casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
128 }
#define CALLERID_MARK
Definition: callerid.c:71
#define CAS_FREQ1
Definition: callerid.c:73
float cid_di[4]
Definition: callerid.c:65
#define CAS_FREQ2
Definition: callerid.c:74
float casdr1
Definition: callerid.c:68
float sasdi
Definition: callerid.c:67
#define M_PI
#define SAS_FREQ
Definition: callerid.c:72
#define CALLERID_SPACE
Definition: callerid.c:70
float sasdr
Definition: callerid.c:67
float casdr2
Definition: callerid.c:68
float casdi2
Definition: callerid.c:68
float casdi1
Definition: callerid.c:68
static unsigned int cos
Definition: chan_h323.c:147
float cid_dr[4]
Definition: callerid.c:65
struct callerid_state* callerid_new ( int  cid_signalling)

Create a callerID state machine.

Parameters
cid_signallingType of signalling in use

This function returns a malloc'd instance of the callerid_state data structure.

Returns
Returns a pointer to a malloc'd callerid_state structure, or NULL on error.

Definition at line 130 of file callerid.c.

References ast_calloc, fsk_data::bw, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, fsk_data::f_mark_idx, fsk_data::f_space_idx, callerid_state::flags, callerid_state::fskd, fskmodem_init(), fsk_data::icont, fsk_data::instop, fsk_data::ispb, fsk_data::nbit, fsk_data::nstop, fsk_data::pllids, fsk_data::pllispb, fsk_data::pllispb2, and fsk_data::spb.

Referenced by analog_ss_thread(), mwi_thread(), and my_start_cid_detect().

131 {
132  struct callerid_state *cid;
133 
134  if ((cid = ast_calloc(1, sizeof(*cid)))) {
135 #ifdef INTEGER_CALLERID
136  cid->fskd.ispb = 7; /* 1200 baud */
137  /* Set up for 1200 / 8000 freq *32 to allow ints */
138  cid->fskd.pllispb = (int)(8000 * 32 / 1200);
139  cid->fskd.pllids = cid->fskd.pllispb/32;
140  cid->fskd.pllispb2 = cid->fskd.pllispb/2;
141 
142  cid->fskd.icont = 0; /* PLL REset */
143  /* cid->fskd.hdlc = 0; */ /* Async */
144  cid->fskd.nbit = 8; /* 8 bits */
145  cid->fskd.instop = 1; /* 1 stop bit */
146  /* cid->fskd.paridad = 0; */ /* No parity */
147  cid->fskd.bw = 1; /* Filter 800 Hz */
148  if (cid_signalling == 2) { /* v23 signalling */
149  cid->fskd.f_mark_idx = 4; /* 1300 Hz */
150  cid->fskd.f_space_idx = 5; /* 2100 Hz */
151  } else { /* Bell 202 signalling as default */
152  cid->fskd.f_mark_idx = 2; /* 1200 Hz */
153  cid->fskd.f_space_idx = 3; /* 2200 Hz */
154  }
155  /* cid->fskd.pcola = 0; */ /* No clue */
156  /* cid->fskd.cont = 0.0; */ /* Digital PLL reset */
157  /* cid->fskd.x0 = 0.0; */
158  /* cid->fskd.state = 0; */
160  /* cid->pos = 0; */
161 
162  fskmodem_init(&cid->fskd);
163 #else
164  cid->fskd.spb = 7.0; /* 1200 baud */
165  /* cid->fskd.hdlc = 0; */ /* Async */
166  cid->fskd.nbit = 8; /* 8 bits */
167  cid->fskd.nstop = 1.0; /* 1 stop bit */
168  /* cid->fskd.paridad = 0; */ /* No parity */
169  cid->fskd.bw = 1; /* Filter 800 Hz */
170  if (cid_signalling == 2) { /* v23 signalling */
171  cid->fskd.f_mark_idx = 4; /* 1300 Hz */
172  cid->fskd.f_space_idx = 5; /* 2100 Hz */
173  } else { /* Bell 202 signalling as default */
174  cid->fskd.f_mark_idx = 2; /* 1200 Hz */
175  cid->fskd.f_space_idx = 3; /* 2200 Hz */
176  }
177  /* cid->fskd.pcola = 0; */ /* No clue */
178  /* cid->fskd.cont = 0.0; */ /* Digital PLL reset */
179  /* cid->fskd.x0 = 0.0; */
180  /* cid->fskd.state = 0; */
182  /* cid->pos = 0; */
183 #endif
184  }
185 
186  return cid;
187 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
int pllids
Definition: fskmodem_int.h:60
int fskmodem_init(fsk_data *fskd)
Definition: fskmodem_int.c:197
float nstop
int instop
Definition: fskmodem_int.h:46
int pllispb
Definition: fskmodem_int.h:59
int pllispb2
Definition: fskmodem_int.h:61
int f_space_idx
#define CID_UNKNOWN_NAME
Definition: callerid.h:54
#define ast_calloc(a, b)
Definition: astmm.h:82
int f_mark_idx
fsk_data fskd
Definition: callerid.c:47

Variable Documentation

float cid_di[4]

Definition at line 65 of file callerid.c.

Referenced by callerid_getcarrier().

float cid_dr[4]

Definition at line 65 of file callerid.c.

Referenced by callerid_getcarrier().

float clidsb

Definition at line 66 of file callerid.c.