callerid.h File Reference

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

#include "asterisk/format.h"

Include dependency graph for callerid.h:

Go to the source code of this file.

Defines

#define AST_LIN2X(a)   ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (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)   ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (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,
  AST_REDIRECTING_REASON_SEND_TO_VM
}
 redirecting reason codes. More...

Functions

int ast_callerid_callwaiting_generate (unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
 Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm).
int ast_callerid_generate (unsigned char *buf, const char *name, const char *number, struct ast_format *codec)
 Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format).
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, struct ast_format *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, struct ast_format *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 (const struct ast_party_redirecting_reason *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, struct ast_format *codec)
 Read samples into the state machine.
int callerid_feed_jp (struct callerid_state *cid, unsigned char *ubuf, int samples, struct ast_format *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, struct ast_format *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 ( a   )     ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (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 add_privacy_params(), 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(), get_rpid(), and set_id_from_pai().

#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

#define AST_PRES_USER_NUMBER_UNSCREENED   0x00

#define AST_XLAW ( a   )     ((ast_format_cmp(codec, ast_format_alaw) == AST_FORMAT_CMP_EQUAL) ? (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 ( 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++) \
      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 442 of file callerid.h.

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

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 
AST_REDIRECTING_REASON_SEND_TO_VM 

Definition at line 390 of file callerid.h.


Function Documentation

int ast_callerid_callwaiting_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
struct ast_format codec 
)

Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm).

See also:
ast_callerid_generate() for other details

Definition at line 1070 of file callerid.c.

References __ast_callerid_generate().

Referenced by my_send_callerid(), and send_cwcidspill().

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

int ast_callerid_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
struct ast_format codec 
)

Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format).

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 1065 of file callerid.c.

References __ast_callerid_generate().

Referenced by my_send_callerid().

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

char* ast_callerid_merge ( char *  buf,
int  bufsiz,
const char *  name,
const char *  num,
const char *  unknown 
)

Definition at line 1075 of file callerid.c.

References ast_copy_string(), and ast_escape_quoted().

Referenced by _sip_show_peer(), _skinny_show_line(), caller_id_to_str(), cdr_object_create_public_records(), cdr_object_format_property(), cli_show_channel(), handle_cli_iax2_show_peer(), launch_monitor_thread(), leave_voicemail(), prep_email_sub_vars(), sip_show_user(), and sip_subscription_to_ami().

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

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 1010 of file callerid.c.

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

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

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

int ast_callerid_split ( const char *  src,
char *  name,
int  namelen,
char *  num,
int  numlen 
)

Definition at line 1094 of file callerid.c.

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

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

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

int ast_callerid_vmwi_generate ( unsigned char *  buf,
int  active,
int  type,
struct ast_format codec,
const char *  name,
const char *  number,
int  flags 
)

Generate message waiting indicator.

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

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

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 1285 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

01286 {
01287    int index;
01288 
01289    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01290       if (connected_line_source_types[index].value == data) {
01291          return connected_line_source_types[index].description;
01292       }
01293    }
01294 
01295    return "not-known";
01296 }

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 1298 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by connectedline_read().

01299 {
01300    int index;
01301 
01302    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01303       if (connected_line_source_types[index].value == data) {
01304          return connected_line_source_types[index].name;
01305       }
01306    }
01307 
01308    return "not-known";
01309 }

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 1272 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by connectedline_write().

01273 {
01274    int index;
01275 
01276    for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
01277       if (!strcasecmp(connected_line_source_types[index].name, data)) {
01278          return connected_line_source_types[index].value;
01279       }
01280    }
01281 
01282    return -1;
01283 }

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 1166 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

Referenced by _sip_show_peer(), ast_json_party_id(), channel_callerid(), channel_new_callerid(), json_party_name(), json_party_number(), peers_data_provider_get(), and sip_show_user().

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

int ast_gen_cas ( unsigned char *  outbuf,
int  sas,
int  len,
struct ast_format 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 263 of file callerid.c.

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

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

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

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 1005 of file callerid.c.

References ast_is_valid_string().

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

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

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 1000 of file callerid.c.

References ast_is_valid_string().

Referenced by ast_callerid_parse().

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

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 1184 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

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

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

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 1145 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

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

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

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 1340 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

Referenced by json_party_name().

01341 {
01342    int index;
01343 
01344    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01345       if (party_name_charset_tbl[index].value == data) {
01346          return party_name_charset_tbl[index].description;
01347       }
01348    }
01349 
01350    return "not-known";
01351 }

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 1327 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by party_name_write().

01328 {
01329    int index;
01330 
01331    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01332       if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
01333          return party_name_charset_tbl[index].value;
01334       }
01335    }
01336 
01337    return -1;
01338 }

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 1353 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by party_name_read().

01354 {
01355    int index;
01356 
01357    for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
01358       if (party_name_charset_tbl[index].value == data) {
01359          return party_name_charset_tbl[index].name;
01360       }
01361    }
01362 
01363    return "not-known";
01364 }

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 1229 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

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

const char* ast_redirecting_reason_name ( const struct ast_party_redirecting_reason data  ) 

Convert redirecting reason value to text code.

Since:
1.8
Parameters:
data ast_party_redirecting_reason structure from channel.h
Returns:
string for config file

Definition at line 1242 of file callerid.c.

References ARRAY_LEN, ast_strlen_zero, ast_party_redirecting_reason::code, ast_value_translation::name, ast_party_redirecting_reason::str, and value.

Referenced by redirecting_read().

01243 {
01244    int index;
01245 
01246    if (!ast_strlen_zero(data->str)) {
01247       /* Use this string if it has been set. Otherwise, use the table. */
01248       return data->str;
01249    }
01250 
01251    for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
01252       if (redirecting_reason_types[index].value == data->code) {
01253          return redirecting_reason_types[index].name;
01254       }
01255    }
01256 
01257    return "not-known";
01258 }

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 1216 of file callerid.c.

References ARRAY_LEN, name, and ast_value_translation::value.

Referenced by redirecting_write().

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

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 949 of file callerid.c.

Referenced by __analog_ss_thread(), action_originate(), analog_ss_thread(), ari_channels_handle_originate_with_id(), 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().

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

int callerid_feed ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
struct ast_format 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 547 of file callerid.c.

References ast_alloca, ast_copy_string(), ast_log, ast_strlen_zero, AST_XLAW, b, buf, 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().

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

int callerid_feed_jp ( struct callerid_state cid,
unsigned char *  ubuf,
int  samples,
struct ast_format 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 308 of file callerid.c.

References ast_alloca, ast_copy_string(), ast_debug, ast_log, AST_XLAW, b, buf, 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().

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

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 736 of file callerid.c.

References ast_free.

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

00737 {
00738    ast_free(cid);
00739 }

int callerid_generate ( unsigned char *  buf,
const char *  number,
const char *  name,
int  flags,
int  callwaiting,
struct ast_format codec 
)

Generates a CallerID FSK stream in ulaw format suitable for transmission.

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 900 of file callerid.c.

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

Referenced by __ast_callerid_generate().

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

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 190 of file callerid.c.

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

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

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

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

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

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 117 of file callerid.c.

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

Referenced by main().

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

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

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


Variable Documentation

float cid_di[4]

Definition at line 66 of file callerid.c.

Referenced by callerid_getcarrier().

float cid_dr[4]

Definition at line 66 of file callerid.c.

Referenced by callerid_getcarrier().

float clidsb

Definition at line 67 of file callerid.c.


Generated on Thu Apr 16 06:29:18 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6