Fri Aug 17 00:17:26 2018

Asterisk developer's documentation


callerid.h File Reference

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

#include "asterisk/frame_defs.h"

Go to the source code of this file.

Defines

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

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.


Define Documentation

#define AST_LIN2X (  )     ((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   0x00
#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

Definition at line 321 of file callerid.h.

Referenced by ast_to_misdn_screen(), and misdn_to_ast_screen().

#define AST_PRES_NUMBER_NOT_AVAILABLE   (AST_PRES_UNAVAILABLE | AST_PRES_NETWORK_NUMBER)

Definition at line 353 of file callerid.h.

Referenced by add_rpid(), ast_party_id_presentation(), check_access(), and iax2_call().

#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_RESTRICTED   0x20
#define AST_PRES_RESTRICTION   0x60
#define AST_PRES_UNAVAILABLE   0x40

Definition at line 326 of file callerid.h.

Referenced by ast_party_id_presentation(), ast_to_misdn_pres(), and misdn_to_ast_pres().

#define AST_PRES_USER_NUMBER_FAILED_SCREEN   0x02

Definition at line 320 of file callerid.h.

Referenced by ast_to_misdn_screen(), and misdn_to_ast_screen().

#define AST_PRES_USER_NUMBER_PASSED_SCREEN   0x01

Definition at line 319 of file callerid.h.

Referenced by ast_to_misdn_screen(), and misdn_to_ast_screen().

#define AST_PRES_USER_NUMBER_UNSCREENED   0x00
#define AST_XLAW (  )     ((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 (  ) 
Value:
do { \
   int __sample_idx = (short)(rint(8192.0 * (y))); \
   *(buf++) = AST_LIN2X(__sample_idx); \
   bytes++; \
} while(0)

Definition at line 283 of file callerid.h.

Referenced by tdd_gen_holdtone().

#define PUT_BYTE (  ) 
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++) \
      PUT_AUDIO_SAMPLE(callerid_getcarrier(&cr, &ci, 1)); \
} while(0)

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.

00439                                       {
00440    /*! Update for unknown reason (May be interpreted to mean from answer) */
00441    AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN,
00442    /*! Update from normal call answering */
00443    AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER,
00444    /*! Update from call diversion (Deprecated, use REDIRECTING updates instead.) */
00445    AST_CONNECTED_LINE_UPDATE_SOURCE_DIVERSION,
00446    /*! Update from call transfer(active) (Party has already answered) */
00447    AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER,
00448    /*! Update from call transfer(alerting) (Party has not answered yet) */
00449    AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER_ALERTING
00450 };

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().

01070 {
01071    return __ast_callerid_generate(buf, name, number, 1, codec);
01072 }

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:
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)

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().

01065 {
01066    return __ast_callerid_generate(buf, name, number, 0, codec);
01067 }

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().

01075 {
01076    if (!unknown)
01077       unknown = "<unknown>";
01078    if (name && num) {
01079       char name_buf[128];
01080 
01081       ast_escape_quoted(name, name_buf, sizeof(name_buf));
01082       snprintf(buf, bufsiz, "\"%s\" <%s>", name_buf, num);
01083    } else if (name) {
01084       ast_copy_string(buf, name, bufsiz);
01085    } else if (num) {
01086       ast_copy_string(buf, num, bufsiz);
01087    } else {
01088       ast_copy_string(buf, unknown, bufsiz);
01089    }
01090    return buf;
01091 }

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:
instr buffer of callerid stream (in audio form) to be parsed. Warning, data in buffer is changed.
name address of a pointer-to-char for the name value of the stream.
location address 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().

01010 {
01011    char *ls;
01012    char *le;
01013    char *name_start;
01014    char *instr;
01015    int quotes_stripped = 0;
01016 
01017    /* Handle surrounding quotes */
01018    input_str = ast_strip(input_str);
01019    instr = ast_strip_quoted(input_str, "\"", "\"");
01020    if (instr != input_str) {
01021       quotes_stripped = 1;
01022    }
01023 
01024    /* Try "name" <location> format or name <location> format or with a missing > */
01025    if ((ls = strrchr(instr, '<'))) {
01026       if ((le = strrchr(ls, '>'))) {
01027          *le = '\0'; /* location found, trim off the brackets */
01028       }
01029       *ls = '\0';
01030       *location = ls + 1;  /* and this is the result */
01031 
01032       name_start = ast_strip_quoted(instr, "\"", "\"");
01033    } else { /* no valid brackets */
01034       char tmp[256];
01035 
01036       ast_copy_string(tmp, instr, sizeof(tmp));
01037       ast_shrink_phone_number(tmp);
01038       if (!quotes_stripped && ast_isphonenumber(tmp)) {  /* Assume it's just a location */
01039          name_start = NULL;
01040          strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
01041          *location = instr;
01042       } else { /* Assume it's just a name. */
01043          *location = NULL;
01044          name_start = ast_strip_quoted(instr, "\"", "\"");
01045       }
01046    }
01047 
01048    if (name_start) {
01049       ast_unescape_quoted(name_start);
01050    }
01051    *name = name_start;
01052    return 0;
01053 }

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().

01094 {
01095    char *tmp;
01096    char *l = NULL, *n = NULL;
01097 
01098    tmp = ast_strdupa(buf);
01099    ast_callerid_parse(tmp, &n, &l);
01100    if (n)
01101       ast_copy_string(name, n, namelen);
01102    else
01103       name[0] = '\0';
01104    if (l) {
01105       ast_shrink_phone_number(l);
01106       ast_copy_string(num, l, numlen);
01107    } else
01108       num[0] = '\0';
01109    return 0;
01110 }

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 
active The message indicator state -- either 0 no messages in mailbox or 1 messages in mailbox
type Format 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().

00813 {
00814    char msg[256];
00815    int len = 0;
00816    int sum;
00817    int x;
00818    int bytes = 0;
00819    float cr = 1.0;
00820    float ci = 0.0;
00821    float scont = 0.0;
00822    
00823    if (type == CID_MWI_TYPE_MDMF_FULL) {
00824       /* MDMF Message waiting with date, number, name and MWI parameter */
00825       msg[0] = 0x82;
00826 
00827       /* put date, number info at the right place */
00828       len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags); 
00829       
00830       /* length of MDMF CLI plus Message Waiting Structure */
00831       msg[1] = len+3;
00832       
00833       /* Go to the position to write to */
00834       len = len+2;
00835       
00836       /* "Message Waiting Parameter" */
00837       msg[len++] = 0x0b;
00838       /* Length of IE is one */
00839       msg[len++] = 1;
00840       /* Active or not */
00841       if (active)
00842          msg[len++] = 0xff;
00843       else
00844          msg[len++] = 0x00;
00845       
00846    } else if (type == CID_MWI_TYPE_MDMF) {
00847       /* MDMF Message waiting only */
00848       /* same as above except that the we only put MWI parameter */
00849       msg[len++] = 0x82;
00850       /* Length is 3 */
00851       msg[len++] = 3;
00852       /* IE is "Message Waiting Parameter" */
00853       msg[len++] = 0x0b;
00854       /* Length of IE is one */
00855       msg[len++] = 1;
00856       /* Active or not */
00857       if (active)
00858          msg[len++] = 0xff;
00859       else
00860          msg[len++] = 0x00;
00861    } else {
00862       /* SDMF Message waiting */
00863       msg[len++] = 0x6;
00864       /* Length is 3 */
00865       msg[len++] = 3;
00866       if (active) {
00867          msg[len++] = 0x42;
00868          msg[len++] = 0x42;
00869          msg[len++] = 0x42;
00870       } else {
00871          msg[len++] = 0x6f;
00872          msg[len++] = 0x6f;
00873          msg[len++] = 0x6f;
00874       }
00875    }
00876    sum = 0;
00877    for (x = 0; x < len; x++)
00878       sum += msg[x];
00879    sum = (256 - (sum & 255));
00880    msg[len++] = sum;
00881    /* Wait a half a second */
00882    for (x = 0; x < 4000; x++)
00883       PUT_BYTE(0x7f);
00884    /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
00885    for (x = 0; x < 30; x++)
00886       PUT_CLID(0x55);
00887    /* Send 170ms of callerid marks */
00888    for (x = 0; x < 170; x++)
00889       PUT_CLID_MARKMS;
00890    for (x = 0; x < len; x++) {
00891       PUT_CLID(msg[x]);
00892    }
00893    /* Send 50 more ms of marks */
00894    for (x = 0; x < 50; x++)
00895       PUT_CLID_MARKMS;
00896    return bytes;
00897 }

const char* ast_connected_line_source_describe ( int  data  ) 

Convert connected line update source value to explanatory string.

Since:
1.8
Parameters:
data AST_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.

01279 {
01280    int index;
01281 
01282    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01283       if (connected_line_source_types[index].value == data) {
01284          return connected_line_source_types[index].description;
01285       }
01286    }
01287 
01288    return "not-known";
01289 }

const char* ast_connected_line_source_name ( int  data  ) 

Convert connected line update source value to text code.

Since:
1.8
Parameters:
data AST_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().

01292 {
01293    int index;
01294 
01295    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01296       if (connected_line_source_types[index].value == data) {
01297          return connected_line_source_types[index].name;
01298       }
01299    }
01300 
01301    return "not-known";
01302 }

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:
data text string from config file
Return values:
AST_CONNECTED_LINE_UPDATE_SOURCE from callerid.h
-1 if not in table

Definition at line 1265 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by connectedline_write().

01266 {
01267    int index;
01268 
01269    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01270       if (!strcasecmp(connected_line_source_types[index].name, data)) {
01271          return connected_line_source_types[index].value;
01272       }
01273    }
01274 
01275    return -1;
01276 }

const char* ast_describe_caller_presentation ( int  data  ) 

Convert caller ID pres value to explanatory string.

Parameters:
data AST_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(), and sip_show_user().

01166 {
01167    int index;
01168 
01169    for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
01170       if (pres_types[index].value == data) {
01171          return pres_types[index].description;
01172       }
01173    }
01174 
01175    return "unknown";
01176 }

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:
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)
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().

00263 {
00264    int pos = 0;
00265    int saslen = 2400;
00266    float cr1 = 1.0;
00267    float ci1 = 0.0;
00268    float cr2 = 1.0;
00269    float ci2 = 0.0;
00270 
00271    if (sendsas) {
00272       if (len < saslen)
00273          return -1;
00274       gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1);
00275       len -= saslen;
00276       pos += saslen;
00277       cr2 = cr1;
00278       ci2 = ci1;
00279    }
00280    gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2);
00281    return 0;
00282 }

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:
exten The extension (or URI) to be checked.
Return values:
1 if string is valid AST shrinkable phone number
0 if 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().

01005 {
01006    return ast_is_valid_string(exten, "0123456789*#+()-.");
01007 }

int ast_isphonenumber ( const char *  n  ) 

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

Parameters:
n number 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().

01000 {
01001    return ast_is_valid_string(n, "0123456789*#+");
01002 }

const char* ast_named_caller_presentation ( int  data  ) 

Convert caller ID pres value to text code.

Parameters:
data AST_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().

01184 {
01185    int index;
01186 
01187    for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
01188       if (pres_types[index].value == data) {
01189          return pres_types[index].name;
01190       }
01191    }
01192 
01193    return "unknown";
01194 }

int ast_parse_caller_presentation ( const char *  data  ) 

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

Parameters:
data text string from config file
Return values:
value AST_PRES_ from callerid.h
-1 if 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().

01145 {
01146    int index;
01147    if (!data) {
01148       return -1;
01149    }
01150 
01151    for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
01152       if (!strcasecmp(pres_types[index].name, data)) {
01153          return pres_types[index].value;
01154       }
01155    }
01156 
01157    return -1;
01158 }

const char* ast_party_name_charset_describe ( int  data  ) 

Convert ast_party_name.char_set value to explanatory string.

Since:
1.8
Parameters:
data AST_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.

01334 {
01335    int index;
01336 
01337    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01338       if (party_name_charset_tbl[index].value == data) {
01339          return party_name_charset_tbl[index].description;
01340       }
01341    }
01342 
01343    return "not-known";
01344 }

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:
data text string from config file
Return values:
AST_PARTY_CHAR_SET from channel.h
-1 if 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().

01321 {
01322    int index;
01323 
01324    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01325       if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
01326          return party_name_charset_tbl[index].value;
01327       }
01328    }
01329 
01330    return -1;
01331 }

const char* ast_party_name_charset_str ( int  data  ) 

Convert ast_party_name.char_set value to text code.

Since:
1.8
Parameters:
data AST_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().

01347 {
01348    int index;
01349 
01350    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01351       if (party_name_charset_tbl[index].value == data) {
01352          return party_name_charset_tbl[index].name;
01353       }
01354    }
01355 
01356    return "not-known";
01357 }

const char* ast_redirecting_reason_describe ( int  data  ) 

Convert redirecting reason value to explanatory string.

Since:
1.8
Parameters:
data Q931_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.

01228 {
01229    int index;
01230 
01231    for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
01232       if (redirecting_reason_types[index].value == data) {
01233          return redirecting_reason_types[index].description;
01234       }
01235    }
01236 
01237    return "not-known";
01238 }

const char* ast_redirecting_reason_name ( int  data  ) 

Convert redirecting reason value to text code.

Since:
1.8
Parameters:
data Q931_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().

01241 {
01242    int index;
01243 
01244    for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
01245       if (redirecting_reason_types[index].value == data) {
01246          return redirecting_reason_types[index].name;
01247       }
01248    }
01249 
01250    return "not-known";
01251 }

int ast_redirecting_reason_parse ( const char *  data  ) 

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

Since:
1.8
Parameters:
data text string from config file
Return values:
Q931_REDIRECTING_REASON from callerid.h
-1 if not in table

Definition at line 1214 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by redirecting_write().

01215 {
01216    int index;
01217 
01218    for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
01219       if (!strcasecmp(redirecting_reason_types[index].name, data)) {
01220          return redirecting_reason_types[index].value;
01221       }
01222    }
01223 
01224    return -1;
01225 }

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:
n The 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(), setup_privacy_args(), and write_metadata().

00949 {
00950    int x, y = 0;
00951    int bracketed = 0;
00952 
00953    for (x = 0; n[x]; x++) {
00954       switch (n[x]) {
00955       case '[':
00956          bracketed++;
00957          n[y++] = n[x];
00958          break;
00959       case ']':
00960          bracketed--;
00961          n[y++] = n[x];
00962          break;
00963       case '-':
00964          if (bracketed)
00965             n[y++] = n[x];
00966          break;
00967       case '.':
00968          if (!n[x+1])
00969             n[y++] = n[x];
00970          break;
00971       default:
00972          /* ignore parenthesis and whitespace */
00973          if (!strchr("( )", n[x]))
00974             n[y++] = n[x];
00975       }
00976    }
00977    n[y] = '\0';
00978 }

int callerid_feed ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
format_t  codec 
)

Read samples into the state machine.

Parameters:
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)

Send received audio to the Caller*ID demodulator.

Return values:
-1 on error
0 for "needs more samples"
1 if 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, 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().

00547 {
00548    int mylen = len;
00549    int olen;
00550    int b = 'X';
00551    int res;
00552    int x;
00553    short *buf;
00554 
00555    buf = ast_alloca(2 * len + cid->oldlen);
00556 
00557    memcpy(buf, cid->oldstuff, cid->oldlen);
00558    mylen += cid->oldlen/2;
00559 
00560    for (x = 0; x < len; x++) 
00561       buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
00562    while (mylen >= 160) {
00563       olen = mylen;
00564       res = fsk_serial(&cid->fskd, buf, &mylen, &b);
00565       if (mylen < 0) {
00566          ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
00567          return -1;
00568       }
00569       buf += (olen - mylen);
00570       if (res < 0) {
00571          ast_log(LOG_NOTICE, "fsk_serial failed\n");
00572          return -1;
00573       }
00574       if (res == 1) {
00575          if (b > 0xff) {
00576             if (cid->sawflag != 5) {
00577                /* Ignore invalid bytes */
00578                continue;
00579             }
00580             /*
00581              * We can tollerate an error on the checksum character since the
00582              * checksum character is the last character in the message and
00583              * it validates the message.
00584              *
00585              * Remove character error flags.
00586              * Bit 8 : Parity error
00587              * Bit 9 : Framing error
00588              */
00589             b &= 0xff;
00590          }
00591          switch (cid->sawflag) {
00592          case 0: /* Look for flag */
00593             if (b == 'U')
00594                cid->sawflag = 2;
00595             break;
00596          case 2: /* Get lead-in */
00597             if ((b == 0x04) || (b == 0x80) || (b == 0x06) || (b == 0x82)) {
00598                cid->type = b;
00599                cid->sawflag = 3;
00600                cid->cksum = b;
00601             }
00602             break;
00603          case 3:  /* Get length */
00604             /* Not a lead in.  We're ready  */
00605             cid->sawflag = 4;
00606             cid->len = b;
00607             cid->pos = 0;
00608             cid->cksum += b;
00609             break;
00610          case 4: /* Retrieve message */
00611             if (cid->pos >= 128) {
00612                ast_log(LOG_WARNING, "Caller ID too long???\n");
00613                return -1;
00614             }
00615             cid->rawdata[cid->pos++] = b;
00616             cid->len--;
00617             cid->cksum += b;
00618             if (!cid->len) {
00619                cid->rawdata[cid->pos] = '\0';
00620                cid->sawflag = 5;
00621             }
00622             break;
00623          case 5: /* Check checksum */
00624             if ((b + cid->cksum) & 0xff) {
00625                ast_log(LOG_NOTICE, "Caller*ID failed checksum\n");
00626                /* Try again */
00627                cid->sawflag = 0;
00628                break;
00629             }
00630       
00631             cid->number[0] = '\0';
00632             cid->name[0] = '\0';
00633             /* Update flags */
00634             cid->flags = 0;
00635             /* If we get this far we're fine.  */
00636             if ((cid->type == 0x80) || (cid->type == 0x82)) {
00637                /* MDMF */
00638                /* Go through each element and process */
00639                for (x = 0; x < cid->pos;) {
00640                   switch (cid->rawdata[x++]) {
00641                   case 1:
00642                      /* Date */
00643                      break;
00644                   case 2: /* Number */
00645                   case 3: /* Number (for Zebble) */
00646                   case 4: /* Number */
00647                      res = cid->rawdata[x];
00648                      if (res > 32) {
00649                         ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]);
00650                         res = 32; 
00651                      }
00652                      if (ast_strlen_zero(cid->number)) {
00653                         memcpy(cid->number, cid->rawdata + x + 1, res);
00654                         /* Null terminate */
00655                         cid->number[res] = '\0';
00656                      }
00657                      break;
00658                   case 6: /* Stentor Call Qualifier (ie. Long Distance call) */
00659                      break;
00660                   case 7: /* Name */
00661                   case 8: /* Name */
00662                      res = cid->rawdata[x];
00663                      if (res > 32) {
00664                         ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]);
00665                         res = 32; 
00666                      }
00667                      memcpy(cid->name, cid->rawdata + x + 1, res);
00668                      cid->name[res] = '\0';
00669                      break;
00670                   case 11: /* Message Waiting */
00671                      res = cid->rawdata[x + 1];
00672                      if (res)
00673                         cid->flags |= CID_MSGWAITING;
00674                      else
00675                         cid->flags |= CID_NOMSGWAITING;
00676                      break;
00677                   case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting  */
00678                   case 19: /* UK: Network message system status (Number of messages waiting) */
00679                   case 22: /* Something French */
00680                      break;
00681                   default:
00682                      ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x - 1]);
00683                   }
00684                   res = cid->rawdata[x];
00685                   if (0 > res){  /* Negative offset in the CID Spill */
00686                      ast_log(LOG_NOTICE, "IE %d has bad field length of %d at offset %d\n", cid->rawdata[x-1], cid->rawdata[x], x);
00687                      /* Try again */
00688                      cid->sawflag = 0;
00689                      break;   /* Exit the loop */
00690                   }
00691                   x += cid->rawdata[x];
00692                   x++;
00693                }
00694             } else if (cid->type == 0x6) {
00695                /* VMWI SDMF */
00696                if (cid->rawdata[2] == 0x42) {
00697                   cid->flags |= CID_MSGWAITING;
00698                } else if (cid->rawdata[2] == 0x6f) {
00699                   cid->flags |= CID_NOMSGWAITING;
00700                }
00701             } else {
00702                /* SDMF */
00703                ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number));
00704             }
00705             if (!strcmp(cid->number, "P")) {
00706                strcpy(cid->number, "");
00707                cid->flags |= CID_PRIVATE_NUMBER;
00708             } else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) {
00709                strcpy(cid->number, "");
00710                cid->flags |= CID_UNKNOWN_NUMBER;
00711             }
00712             if (!strcmp(cid->name, "P")) {
00713                strcpy(cid->name, "");
00714                cid->flags |= CID_PRIVATE_NAME;
00715             } else if (!strcmp(cid->name, "O") || ast_strlen_zero(cid->name)) {
00716                strcpy(cid->name, "");
00717                cid->flags |= CID_UNKNOWN_NAME;
00718             }
00719             return 1;
00720             break;
00721          default:
00722             ast_log(LOG_ERROR, "Dunno what to do with a digit in sawflag %d\n", cid->sawflag);
00723          }
00724       }
00725    }
00726    if (mylen) {
00727       memcpy(cid->oldstuff, buf, mylen * 2);
00728       cid->oldlen = mylen * 2;
00729    } else
00730       cid->oldlen = 0;
00731 
00732    return 0;
00733 }

int callerid_feed_jp ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
format_t  codec 
)

Read samples into the state machine.

Parameters:
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)

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

Return values:
-1 on error
0 for "needs more samples"
1 if 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, callerid_state::crc, callerid_state::flags, fsk_serial(), callerid_state::fskd, callerid_state::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().

00308 {
00309    int mylen = len;
00310    int olen;
00311    int b = 'X';
00312    int b2;
00313    int res;
00314    int x;
00315    short *buf;
00316 
00317    buf = ast_alloca(2 * len + cid->oldlen);
00318 
00319    memcpy(buf, cid->oldstuff, cid->oldlen);
00320    mylen += cid->oldlen / 2;
00321 
00322    for (x = 0; x < len; x++) 
00323       buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
00324 
00325    while (mylen >= 160) {
00326       b = b2 = 0;
00327       olen = mylen;
00328       res = fsk_serial(&cid->fskd, buf, &mylen, &b);
00329 
00330       if (mylen < 0) {
00331          ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
00332          return -1;
00333       }
00334 
00335       buf += (olen - mylen);
00336 
00337       if (res < 0) {
00338          ast_log(LOG_NOTICE, "fsk_serial failed\n");
00339          return -1;
00340       }
00341 
00342       if (res == 1) {
00343          b2 = b;
00344          b  &= 0x7f;
00345 
00346          /* crc checksum calculation */
00347          if (cid->sawflag > 1)
00348             cid->crc = calc_crc(cid->crc, (unsigned char) b2);
00349 
00350          /* Ignore invalid bytes */
00351          if (b > 0xff)
00352             continue;
00353 
00354          /* skip DLE if needed */
00355          if (cid->sawflag > 0) {
00356             if (cid->sawflag != 5 && cid->skipflag == 0 && b == 0x10) {
00357                cid->skipflag = 1 ;
00358                continue ;
00359             }
00360          }
00361          if (cid->skipflag == 1)
00362             cid->skipflag = 0 ;
00363 
00364          /* caller id retrieval */
00365          switch (cid->sawflag) {
00366          case 0: /* DLE */
00367             if (b == 0x10) {
00368                cid->sawflag = 1;
00369                cid->skipflag = 0;
00370                cid->crc = 0;
00371             }
00372             break;
00373          case 1: /* SOH */
00374             if (b == 0x01) 
00375                cid->sawflag = 2;
00376             break ;
00377          case 2: /* HEADER */
00378             if (b == 0x07) 
00379                cid->sawflag = 3;
00380             break;
00381          case 3: /* STX */
00382             if (b == 0x02) 
00383                cid->sawflag = 4;
00384             break;
00385          case 4: /* SERVICE TYPE */
00386             if (b == 0x40) 
00387                cid->sawflag = 5;
00388             break;
00389          case 5: /* Frame Length */
00390             cid->sawflag = 6;
00391             break;   
00392          case 6: /* NUMBER TYPE */
00393             cid->sawflag = 7;
00394             cid->pos = 0;
00395             cid->rawdata[cid->pos++] = b;
00396             break;
00397          case 7:  /* NUMBER LENGTH */
00398             cid->sawflag = 8;
00399             cid->len = b;
00400             if ((cid->len+2) >= sizeof(cid->rawdata)) {
00401                ast_log(LOG_WARNING, "too long caller id string\n") ;
00402                return -1;
00403             }
00404             cid->rawdata[cid->pos++] = b;
00405             break;
00406          case 8:  /* Retrieve message */
00407             cid->rawdata[cid->pos++] = b;
00408             cid->len--;
00409             if (cid->len<=0) {
00410                cid->rawdata[cid->pos] = '\0';
00411                cid->sawflag = 9;
00412             }
00413             break;
00414          case 9:  /* ETX */
00415             cid->sawflag = 10;
00416             break;
00417          case 10: /* CRC Checksum 1 */
00418             cid->sawflag = 11;
00419             break;
00420          case 11: /* CRC Checksum 2 */
00421             cid->sawflag = 12;
00422             if (cid->crc != 0) {
00423                ast_log(LOG_WARNING, "crc checksum error\n") ;
00424                return -1;
00425             } 
00426             /* extract caller id data */
00427             for (x = 0; x < cid->pos;) {
00428                switch (cid->rawdata[x++]) {
00429                case 0x02: /* caller id  number */
00430                   cid->number[0] = '\0';
00431                   cid->name[0] = '\0';
00432                   cid->flags = 0;
00433                   res = cid->rawdata[x++];
00434                   ast_copy_string(cid->number, &cid->rawdata[x], res+1);
00435                   x += res;
00436                   break;
00437                case 0x21: /* additional information */
00438                   /* length */
00439                   x++; 
00440                   /* number type */
00441                   switch (cid->rawdata[x]) { 
00442                   case 0x00: /* unknown */
00443                   case 0x01: /* international number */
00444                   case 0x02: /* domestic number */
00445                   case 0x03: /* network */
00446                   case 0x04: /* local call */
00447                   case 0x06: /* short dial number */
00448                   case 0x07: /* reserved */
00449                   default:   /* reserved */
00450                      ast_debug(2, "cid info:#1=%X\n", (unsigned)cid->rawdata[x]);
00451                      break ;
00452                   }
00453                   x++; 
00454                   /* numbering plan octed 4 */
00455                   x++; 
00456                   /* numbering plan octed 5 */
00457                   switch (cid->rawdata[x]) { 
00458                   case 0x00: /* unknown */
00459                   case 0x01: /* recommendation E.164 ISDN */
00460                   case 0x03: /* recommendation X.121 */
00461                   case 0x04: /* telex dial plan */
00462                   case 0x08: /* domestic dial plan */
00463                   case 0x09: /* private dial plan */
00464                   case 0x05: /* reserved */
00465                   default:   /* reserved */
00466                      ast_debug(2, "cid info:#2=%X\n", (unsigned)cid->rawdata[x]);
00467                      break ;
00468                   }
00469                   x++; 
00470                   break ;
00471                case 0x04: /* no callerid reason */
00472                   /* length */
00473                   x++; 
00474                   /* no callerid reason code */
00475                   switch (cid->rawdata[x]) {
00476                   case 'P': /* caller id denied by user */
00477                   case 'O': /* service not available */
00478                   case 'C': /* pay phone */
00479                   case 'S': /* service congested */
00480                      cid->flags |= CID_UNKNOWN_NUMBER;
00481                      ast_debug(2, "no cid reason:%c\n", cid->rawdata[x]);
00482                      break ;
00483                   }
00484                   x++; 
00485                   break ;
00486                case 0x09: /* dialed number */
00487                   /* length */
00488                   res = cid->rawdata[x++];
00489                   /* dialed number */
00490                   x += res;
00491                   break ;
00492                case 0x22: /* dialed number additional information */
00493                   /* length */
00494                   x++;
00495                   /* number type */
00496                   switch (cid->rawdata[x]) {
00497                   case 0x00: /* unknown */
00498                   case 0x01: /* international number */
00499                   case 0x02: /* domestic number */
00500                   case 0x03: /* network */
00501                   case 0x04: /* local call */
00502                   case 0x06: /* short dial number */
00503                   case 0x07: /* reserved */
00504                   default:   /* reserved */
00505                      if (option_debug > 1)
00506                         ast_log(LOG_NOTICE, "did info:#1=%X\n", (unsigned)cid->rawdata[x]);
00507                      break ;
00508                   }
00509                   x++;
00510                   /* numbering plan octed 4 */
00511                   x++;
00512                   /* numbering plan octed 5 */
00513                   switch (cid->rawdata[x]) {
00514                   case 0x00: /* unknown */
00515                   case 0x01: /* recommendation E.164 ISDN */
00516                   case 0x03: /* recommendation X.121 */
00517                   case 0x04: /* telex dial plan */
00518                   case 0x08: /* domestic dial plan */
00519                   case 0x09: /* private dial plan */
00520                   case 0x05: /* reserved */
00521                   default:   /* reserved */
00522                      ast_debug(2, "did info:#2=%X\n", (unsigned)cid->rawdata[x]);
00523                      break ;
00524                   }
00525                   x++;
00526                   break ;
00527                }
00528             }
00529             return 1;
00530             break;
00531          default:
00532             ast_log(LOG_ERROR, "invalid value in sawflag %d\n", cid->sawflag);
00533          }
00534       }
00535    }
00536    if (mylen) {
00537       memcpy(cid->oldstuff, buf, mylen * 2);
00538       cid->oldlen = mylen * 2;
00539    } else
00540       cid->oldlen = 0;
00541    
00542    return 0;
00543 }

void callerid_free ( struct callerid_state cid  ) 

This function frees callerid_state cid.

Parameters:
cid This 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().

00736 {
00737    ast_free(cid);
00738 }

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:
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.

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().

00900 {
00901    int bytes = 0;
00902    int x, sum;
00903    int len;
00904 
00905    /* Initial carriers (real/imaginary) */
00906    float cr = 1.0;
00907    float ci = 0.0;
00908    float scont = 0.0;
00909    char msg[256];
00910    len = callerid_genmsg(msg, sizeof(msg), number, name, flags);
00911    if (!callwaiting) {
00912       /* Wait a half a second */
00913       for (x = 0; x < 4000; x++)
00914          PUT_BYTE(0x7f);
00915       /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
00916       for (x = 0; x < 30; x++)
00917          PUT_CLID(0x55);
00918    }
00919    /* Send 150ms of callerid marks */
00920    for (x = 0; x < 150; x++)
00921       PUT_CLID_MARKMS;
00922    /* Send 0x80 indicating MDMF format */
00923    PUT_CLID(0x80);
00924    /* Put length of whole message */
00925    PUT_CLID(len);
00926    sum = 0x80 + strlen(msg);
00927    /* Put each character of message and update checksum */
00928    for (x = 0; x < len; x++) {
00929       PUT_CLID(msg[x]);
00930       sum += msg[x];
00931    }
00932    /* Send 2's compliment of sum */
00933    PUT_CLID(256 - (sum & 255));
00934 
00935    /* Send 50 more ms of marks */
00936    for (x = 0; x < 50; x++)
00937       PUT_CLID_MARKMS;
00938    
00939    return bytes;
00940 }

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:
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)

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().

00190 {
00191    *flags = cid->flags;
00192    if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NAME))
00193       *name = NULL;
00194    else
00195       *name = cid->name;
00196    if (cid->flags & (CID_UNKNOWN_NUMBER | CID_PRIVATE_NUMBER))
00197       *number = NULL;
00198    else
00199       *number = cid->number;
00200 }

void callerid_get_dtmf ( char *  cidstring,
char *  number,
int *  flags 
)

Get and parse DTMF-based callerid.

Parameters:
cidstring The actual transmitted string.
number The cid number is returned here.
flags The 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().

00203 {
00204    int i;
00205    int code;
00206 
00207    /* "Clear" the number-buffer. */
00208    number[0] = 0;
00209 
00210    if (strlen(cidstring) < 2) {
00211       ast_debug(1, "No cid detected\n");
00212       *flags = CID_UNKNOWN_NUMBER;
00213       return;
00214    }
00215    
00216    /* Detect protocol and special types */
00217    if (cidstring[0] == 'B') {
00218       /* Handle special codes */
00219       code = atoi(&cidstring[1]);
00220       if (code == 0)
00221          *flags = CID_UNKNOWN_NUMBER;
00222       else if (code == 10) 
00223          *flags = CID_PRIVATE_NUMBER;
00224       else
00225          ast_debug(1, "Unknown DTMF code %d\n", code);
00226    } else if (cidstring[0] == 'D' && cidstring[2] == '#') {
00227       /* .DK special code */
00228       if (cidstring[1] == '1')
00229          *flags = CID_PRIVATE_NUMBER;
00230       if (cidstring[1] == '2' || cidstring[1] == '3')
00231          *flags = CID_UNKNOWN_NUMBER;
00232    } else if (cidstring[0] == 'D' || cidstring[0] == 'A') {
00233       /* "Standard" callerid */
00234       for (i = 1; i < strlen(cidstring); i++) {
00235          if (cidstring[i] == 'C' || cidstring[i] == '#')
00236             break;
00237          if (isdigit(cidstring[i]))
00238             number[i-1] = cidstring[i];
00239          else
00240             ast_debug(1, "Unknown CID digit '%c'\n",
00241                cidstring[i]);
00242       }
00243       number[i-1] = 0;
00244    } else if (isdigit(cidstring[0])) {
00245       /* It begins with a digit, so we parse it as a number and hope
00246        * for the best */
00247       ast_log(LOG_WARNING, "Couldn't detect start-character. CID "
00248          "parsing might be unreliable\n");
00249       for (i = 0; i < strlen(cidstring); i++) {
00250          if (isdigit(cidstring[i]))
00251             number[i] = cidstring[i];
00252          else
00253             break;
00254       }
00255       number[i] = 0;
00256    } else {
00257       ast_debug(1, "Unknown CID protocol, start digit '%c'\n", cidstring[0]);
00258       *flags = CID_UNKNOWN_NUMBER;
00259    }
00260 }

static float callerid_getcarrier ( float *  cr,
float *  ci,
int  bit 
) [inline, static]

Definition at line 264 of file callerid.h.

References cid_di, and cid_dr.

00265 {
00266    /* Move along.  There's nothing to see here... */
00267    float t;
00268    t = *cr * cid_dr[bit] - *ci * cid_di[bit];
00269    *ci = *cr * cid_di[bit] + *ci * cid_dr[bit];
00270    *cr = t;
00271 
00272    t = 2.0 - (*cr * *cr + *ci * *ci);
00273    *cr *= t;
00274    *ci *= t;
00275    return *cr;
00276 }

void callerid_init ( void   ) 

CallerID Initialization.

Initializes the callerid system. Mostly stuff for inverse FFT

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().

00117 {
00118    cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
00119    cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
00120    cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0);
00121    cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0);
00122    sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0);
00123    sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0);
00124    casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
00125    casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
00126    casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
00127    casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
00128 }

struct callerid_state* callerid_new ( int  cid_signalling  )  [read]

Create a callerID state machine.

Parameters:
cid_signalling Type 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().

00131 {
00132    struct callerid_state *cid;
00133 
00134    if ((cid = ast_calloc(1, sizeof(*cid)))) {
00135 #ifdef INTEGER_CALLERID
00136       cid->fskd.ispb = 7;           /* 1200 baud */   
00137       /* Set up for 1200 / 8000 freq *32 to allow ints */
00138       cid->fskd.pllispb  = (int)(8000 * 32  / 1200);
00139       cid->fskd.pllids   = cid->fskd.pllispb/32;
00140       cid->fskd.pllispb2 = cid->fskd.pllispb/2;
00141       
00142       cid->fskd.icont = 0;           /* PLL REset */
00143       /* cid->fskd.hdlc = 0; */        /* Async */
00144       cid->fskd.nbit = 8;              /* 8 bits */
00145       cid->fskd.instop = 1;         /* 1 stop bit */
00146       /* cid->fskd.paridad = 0; */     /* No parity */
00147       cid->fskd.bw = 1;                /* Filter 800 Hz */
00148       if (cid_signalling == 2) {       /* v23 signalling */
00149          cid->fskd.f_mark_idx  = 4; /* 1300 Hz */
00150          cid->fskd.f_space_idx = 5; /* 2100 Hz */
00151       } else {                         /* Bell 202 signalling as default */
00152          cid->fskd.f_mark_idx  = 2; /* 1200 Hz */
00153          cid->fskd.f_space_idx = 3; /* 2200 Hz */
00154       }
00155       /* cid->fskd.pcola = 0; */       /* No clue */
00156       /* cid->fskd.cont = 0.0; */      /* Digital PLL reset */
00157       /* cid->fskd.x0 = 0.0; */
00158       /* cid->fskd.state = 0; */
00159       cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
00160       /* cid->pos = 0; */
00161 
00162       fskmodem_init(&cid->fskd);
00163 #else
00164       cid->fskd.spb = 7.0;             /* 1200 baud */
00165       /* cid->fskd.hdlc = 0; */        /* Async */
00166       cid->fskd.nbit = 8;              /* 8 bits */
00167       cid->fskd.nstop = 1.0;           /* 1 stop bit */
00168       /* cid->fskd.paridad = 0; */     /* No parity */
00169       cid->fskd.bw = 1;                /* Filter 800 Hz */
00170       if (cid_signalling == 2) {       /* v23 signalling */
00171          cid->fskd.f_mark_idx =  4; /* 1300 Hz */
00172          cid->fskd.f_space_idx = 5; /* 2100 Hz */
00173       } else {                         /* Bell 202 signalling as default */
00174          cid->fskd.f_mark_idx =  2; /* 1200 Hz */
00175          cid->fskd.f_space_idx = 3; /* 2200 Hz */
00176       }
00177       /* cid->fskd.pcola = 0; */       /* No clue */
00178       /* cid->fskd.cont = 0.0; */      /* Digital PLL reset */
00179       /* cid->fskd.x0 = 0.0; */
00180       /* cid->fskd.state = 0; */
00181       cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
00182       /* cid->pos = 0; */
00183 #endif
00184    }
00185 
00186    return cid;
00187 }


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.


Generated on 17 Aug 2018 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1