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_state * | callerid_new (int cid_signalling) |
| Create a callerID state machine. | |
Variables | |
| float | cid_di [4] |
| float | cid_dr [4] |
| float | clidsb |
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata library.
Definition in file callerid.h.
| #define AST_LIN2X | ( | a | ) | ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a))) |
Definition at line 78 of file callerid.h.
Referenced by gen_tone(), and gen_tones().
| #define AST_PRES_ALLOWED 0x00 |
Definition at line 324 of file callerid.h.
Referenced by add_rpid(), ast_party_id_presentation(), ast_to_misdn_pres(), handle_response_invite(), initreqprep(), misdn_facility_ie_handler(), misdn_to_ast_pres(), and sip_call().
| #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(), ast_to_pri_presentation(), and pri_to_ast_presentation().
| #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(), ast_to_pri_presentation(), and pri_to_ast_presentation().
| #define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_UNSCREENED) |
Definition at line 329 of file callerid.h.
Referenced by __ast_request_and_dial(), add_rpid(), ast_party_name_init(), ast_party_number_init(), ast_to_pri_presentation(), get_pai(), get_rpid(), pri_to_ast_presentation(), and privacy_exec().
| #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(), ast_to_pri_presentation(), check_access(), dial_exec_full(), get_rpid(), and pri_to_ast_presentation().
| #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_to_pri_presentation(), check_access(), iax2_call(), and pri_to_ast_presentation().
| #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(), ast_to_pri_presentation(), and pri_to_ast_presentation().
| #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(), ast_to_pri_presentation(), and pri_to_ast_presentation().
| #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(), ast_to_pri_presentation(), get_pai(), get_rpid(), and pri_to_ast_presentation().
| #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(), ast_to_pri_presentation(), get_rpid(), and pri_to_ast_presentation().
| #define AST_PRES_RESERVED 0x60 |
Definition at line 327 of file callerid.h.
| #define AST_PRES_RESTRICTED 0x20 |
Definition at line 325 of file callerid.h.
Referenced by ast_party_id_presentation(), ast_to_misdn_pres(), cb_events(), misdn_facility_ie_handler(), and misdn_to_ast_pres().
| #define AST_PRES_RESTRICTION 0x60 |
Definition at line 323 of file callerid.h.
Referenced by add_rpid(), ast_party_id_presentation(), ast_to_misdn_pres(), handle_response_invite(), initreqprep(), and sip_call().
| #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 |
Definition at line 318 of file callerid.h.
Referenced by ast_party_id_presentation(), ast_to_misdn_screen(), cb_events(), misdn_facility_ie_handler(), and misdn_to_ast_screen().
| #define AST_XLAW | ( | a | ) | ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a))) |
Definition at line 79 of file callerid.h.
Referenced by callerid_feed(), and callerid_feed_jp().
| #define CID_MSGWAITING (1 << 4) |
Definition at line 56 of file callerid.h.
Referenced by callerid_feed(), mwi_thread(), and my_handle_notify_message().
| #define CID_MWI_TYPE_MDMF 0x01 |
MWI MDMF format -- generate only MWI field
Definition at line 74 of file callerid.h.
Referenced by ast_callerid_vmwi_generate().
| #define CID_MWI_TYPE_MDMF_FULL 0x02 |
MWI MDMF format -- generate name, callerid, date and MWI fields
Definition at line 76 of file callerid.h.
Referenced by ast_callerid_vmwi_generate(), and mwi_send_init().
| #define CID_MWI_TYPE_SDMF 0x00 |
MWI SDMF format
Definition at line 72 of file callerid.h.
| #define CID_NOMSGWAITING (1 << 5) |
Definition at line 57 of file callerid.h.
Referenced by callerid_feed(), mwi_thread(), and my_handle_notify_message().
| #define CID_PRIVATE_NAME (1 << 0) |
Definition at line 52 of file callerid.h.
Referenced by callerid_feed(), callerid_genmsg(), and callerid_get().
| #define CID_PRIVATE_NUMBER (1 << 1) |
Definition at line 53 of file callerid.h.
Referenced by callerid_feed(), callerid_genmsg(), callerid_get(), and callerid_get_dtmf().
| #define CID_SIG_BELL 1 |
Definition at line 59 of file callerid.h.
Referenced by analog_new(), dahdi_chan_conf_default(), and process_dahdi().
| #define CID_SIG_DTMF 3 |
Definition at line 61 of file callerid.h.
Referenced by __analog_ss_thread(), analog_ss_thread(), and process_dahdi().
| #define CID_SIG_SMDI 5 |
Definition at line 63 of file callerid.h.
Referenced by __analog_ss_thread(), analog_ss_thread(), mkintf(), and process_dahdi().
| #define CID_SIG_V23 2 |
Definition at line 60 of file callerid.h.
Referenced by __analog_ss_thread(), analog_ss_thread(), and process_dahdi().
| #define CID_SIG_V23_JP 4 |
Definition at line 62 of file callerid.h.
Referenced by __analog_ss_thread(), analog_ss_thread(), my_get_callerid(), and process_dahdi().
| #define CID_START_DTMF_NOALERT 4 |
Definition at line 68 of file callerid.h.
Referenced by analog_ss_thread(), do_monitor(), mkintf(), and process_dahdi().
| #define CID_START_POLARITY 2 |
Definition at line 66 of file callerid.h.
Referenced by analog_ss_thread(), handle_init_event(), mkintf(), and process_dahdi().
| #define CID_START_POLARITY_IN 3 |
Definition at line 67 of file callerid.h.
Referenced by analog_ss_thread(), handle_init_event(), mkintf(), and process_dahdi().
| #define CID_START_RING 1 |
Definition at line 65 of file callerid.h.
Referenced by analog_ss_thread(), dahdi_chan_conf_default(), and process_dahdi().
| #define CID_UNKNOWN_NAME (1 << 2) |
Definition at line 54 of file callerid.h.
Referenced by callerid_feed(), callerid_genmsg(), callerid_get(), and callerid_new().
| #define CID_UNKNOWN_NUMBER (1 << 3) |
Definition at line 55 of file callerid.h.
Referenced by callerid_feed(), callerid_feed_jp(), callerid_genmsg(), callerid_get(), callerid_get_dtmf(), and callerid_new().
| #define MAX_CALLERID_SIZE 32000 |
Definition at line 50 of file callerid.h.
Referenced by mwi_send_init(), my_send_callerid(), and send_cwcidspill().
| #define PUT_AUDIO_SAMPLE | ( | y | ) |
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.
| #define PUT_BYTE | ( | a | ) |
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 | ) |
Definition at line 304 of file callerid.h.
Referenced by adsi_generate(), ast_callerid_vmwi_generate(), callerid_generate(), and dahdi_sendtext().
| #define PUT_CLID_BAUD | ( | bit | ) |
Definition at line 295 of file callerid.h.
| #define PUT_CLID_MARKMS |
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 struct callerid_state CIDSTATE |
Definition at line 83 of file callerid.h.
Connected line update source code.
Definition at line 439 of file callerid.h.
{
/*! Update for unknown reason (May be interpreted to mean from answer) */
AST_CONNECTED_LINE_UPDATE_SOURCE_UNKNOWN,
/*! Update from normal call answering */
AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER,
/*! Update from call diversion (Deprecated, use REDIRECTING updates instead.) */
AST_CONNECTED_LINE_UPDATE_SOURCE_DIVERSION,
/*! Update from call transfer(active) (Party has already answered) */
AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER,
/*! Update from call transfer(alerting) (Party has not answered yet) */
AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER_ALERTING
};
redirecting reason codes.
This list attempts to encompass redirecting reasons as defined by several channel technologies.
Definition at line 390 of file callerid.h.
{
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, /* This is something defined in Q.931, and no I don't know what it means */
};
| 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)
Definition at line 1068 of file callerid.c.
References __ast_callerid_generate().
Referenced by my_send_callerid(), and send_cwcidspill().
{
return __ast_callerid_generate(buf, name, number, 1, codec);
}
| 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)
| 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 1063 of file callerid.c.
References __ast_callerid_generate().
Referenced by my_send_callerid().
{
return __ast_callerid_generate(buf, name, number, 0, codec);
}
| char* ast_callerid_merge | ( | char * | buf, |
| int | bufsiz, | ||
| const char * | name, | ||
| const char * | num, | ||
| const char * | unknown | ||
| ) |
Definition at line 1073 of file callerid.c.
References ast_copy_string().
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().
{
if (!unknown)
unknown = "<unknown>";
if (name && num)
snprintf(buf, bufsiz, "\"%s\" <%s>", name, num);
else if (name)
ast_copy_string(buf, name, bufsiz);
else if (num)
ast_copy_string(buf, num, bufsiz);
else
ast_copy_string(buf, unknown, bufsiz);
return buf;
}
| 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.
| 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. |
Definition at line 1005 of file callerid.c.
References ast_copy_string(), ast_isphonenumber(), ast_shrink_phone_number(), ast_skip_blanks(), and ast_trim_blanks().
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(), rpt_call(), and unistim_new().
{
char *ns, *ne, *ls, *le;
/* Try "name" <location> format or name <location> format */
if ((ls = strrchr(instr, '<')) && (le = strrchr(ls, '>'))) {
*ls = *le = '\0'; /* location found, trim off the brackets */
*location = ls + 1; /* and this is the result */
if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
*ns = *ne = '\0'; /* trim off the quotes */
*name = ns + 1; /* and this is the name */
} else if (ns) {
/* An opening quote was found but no closing quote was. The closing
* quote may actually be after the end of the bracketed number
*/
if (strchr(le + 1, '\"')) {
*ns = '\0';
*name = ns + 1;
ast_trim_blanks(*name);
} else {
*name = NULL;
}
} else { /* no quotes, trim off leading and trailing spaces */
*name = ast_skip_blanks(instr);
ast_trim_blanks(*name);
}
} else { /* no valid brackets */
char tmp[256];
ast_copy_string(tmp, instr, sizeof(tmp));
ast_shrink_phone_number(tmp);
if (ast_isphonenumber(tmp)) { /* Assume it's just a location */
*name = NULL;
strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
*location = instr;
} else { /* Assume it's just a name. */
*location = NULL;
if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
*ns = *ne = '\0'; /* trim off the quotes */
*name = ns + 1; /* and this is the name */
} else { /* no quotes, trim off leading and trailing spaces */
*name = ast_skip_blanks(instr);
ast_trim_blanks(*name);
}
}
}
return 0;
}
| int ast_callerid_split | ( | const char * | src, |
| char * | name, | ||
| int | namelen, | ||
| char * | num, | ||
| int | numlen | ||
| ) |
Definition at line 1088 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().
{
char *tmp;
char *l = NULL, *n = NULL;
tmp = ast_strdupa(buf);
ast_callerid_parse(tmp, &n, &l);
if (n)
ast_copy_string(name, n, namelen);
else
name[0] = '\0';
if (l) {
ast_shrink_phone_number(l);
ast_copy_string(num, l, numlen);
} else
num[0] = '\0';
return 0;
}
| 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.
| 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 |
Definition at line 807 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().
{
char msg[256];
int len = 0;
int sum;
int x;
int bytes = 0;
float cr = 1.0;
float ci = 0.0;
float scont = 0.0;
if (type == CID_MWI_TYPE_MDMF_FULL) {
/* MDMF Message waiting with date, number, name and MWI parameter */
msg[0] = 0x82;
/* put date, number info at the right place */
len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags);
/* length of MDMF CLI plus Message Waiting Structure */
msg[1] = len+3;
/* Go to the position to write to */
len = len+2;
/* "Message Waiting Parameter" */
msg[len++] = 0x0b;
/* Length of IE is one */
msg[len++] = 1;
/* Active or not */
if (active)
msg[len++] = 0xff;
else
msg[len++] = 0x00;
} else if (type == CID_MWI_TYPE_MDMF) {
/* MDMF Message waiting only */
/* same as above except that the we only put MWI parameter */
msg[len++] = 0x82;
/* Length is 3 */
msg[len++] = 3;
/* IE is "Message Waiting Parameter" */
msg[len++] = 0x0b;
/* Length of IE is one */
msg[len++] = 1;
/* Active or not */
if (active)
msg[len++] = 0xff;
else
msg[len++] = 0x00;
} else {
/* SDMF Message waiting */
msg[len++] = 0x6;
/* Length is 3 */
msg[len++] = 3;
if (active) {
msg[len++] = 0x42;
msg[len++] = 0x42;
msg[len++] = 0x42;
} else {
msg[len++] = 0x6f;
msg[len++] = 0x6f;
msg[len++] = 0x6f;
}
}
sum = 0;
for (x = 0; x < len; x++)
sum += msg[x];
sum = (256 - (sum & 255));
msg[len++] = sum;
/* Wait a half a second */
for (x = 0; x < 4000; x++)
PUT_BYTE(0x7f);
/* Transmit 30 0x55's (looks like a square wave) for channel seizure */
for (x = 0; x < 30; x++)
PUT_CLID(0x55);
/* Send 170ms of callerid marks */
for (x = 0; x < 170; x++)
PUT_CLID_MARKMS;
for (x = 0; x < len; x++) {
PUT_CLID(msg[x]);
}
/* Send 50 more ms of marks */
for (x = 0; x < 50; x++)
PUT_CLID_MARKMS;
return bytes;
}
| const char* ast_connected_line_source_describe | ( | int | data | ) |
Convert connected line update source value to explanatory string.
| data | AST_CONNECTED_LINE_UPDATE_SOURCE from callerid.h |
Definition at line 1273 of file callerid.c.
References ARRAY_LEN, ast_value_translation::description, and value.
{
int index;
for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
if (connected_line_source_types[index].value == data) {
return connected_line_source_types[index].description;
}
}
return "not-known";
}
| const char* ast_connected_line_source_name | ( | int | data | ) |
Convert connected line update source value to text code.
| data | AST_CONNECTED_LINE_UPDATE_SOURCE from callerid.h |
Definition at line 1286 of file callerid.c.
References ARRAY_LEN, ast_value_translation::name, and value.
Referenced by connectedline_read().
{
int index;
for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
if (connected_line_source_types[index].value == data) {
return connected_line_source_types[index].name;
}
}
return "not-known";
}
| int ast_connected_line_source_parse | ( | const char * | data | ) |
Convert connected line update source text code to value (used in config file parsing)
| data | text string from config file |
| AST_CONNECTED_LINE_UPDATE_SOURCE | from callerid.h |
| -1 | if not in table |
Definition at line 1260 of file callerid.c.
References ARRAY_LEN, name, and ast_value_translation::value.
Referenced by connectedline_write().
{
int index;
for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
if (!strcasecmp(connected_line_source_types[index].name, data)) {
return connected_line_source_types[index].value;
}
}
return -1;
}
| const char* ast_describe_caller_presentation | ( | int | data | ) |
Convert caller ID pres value to explanatory string.
| data | AST_PRES_ value from callerid.h |
Definition at line 1160 of file callerid.c.
References ARRAY_LEN, ast_value_translation::description, and value.
Referenced by _sip_show_peer(), peers_data_provider_get(), report_new_callerid(), sig_pri_event_party_id(), and sip_show_user().
{
int index;
for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
if (pres_types[index].value == data) {
return pres_types[index].description;
}
}
return "unknown";
}
| int ast_gen_cas | ( | unsigned char * | outbuf, |
| int | sas, | ||
| int | len, | ||
| format_t | codec | ||
| ) |
Generate a CAS (CPE Alert Signal) tone for 'n' samples.
| outbuf | Allocated buffer for data. Must be at least 2400 bytes unless no SAS is desired |
| sas | Non-zero if CAS should be preceeded by SAS |
| len | How many samples to generate. |
| codec | Which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Definition at line 258 of file callerid.c.
References gen_tone(), gen_tones(), and callerid_state::pos.
Referenced by __adsi_transmit_messages(), dahdi_callwait(), and my_callwait().
{
int pos = 0;
int saslen = 2400;
float cr1 = 1.0;
float ci1 = 0.0;
float cr2 = 1.0;
float ci2 = 0.0;
if (sendsas) {
if (len < saslen)
return -1;
gen_tone(outbuf, saslen, codec, sasdr, sasdi, &cr1, &ci1);
len -= saslen;
pos += saslen;
cr2 = cr1;
ci2 = ci1;
}
gen_tones(outbuf + pos, len, codec, casdr1, casdi1, casdr2, casdi2, &cr1, &ci1, &cr2, &ci2);
return 0;
}
| 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)
| exten | The extension (or URI) to be checked. |
| 1 | if string is valid AST shrinkable phone number |
| 0 | if not |
Definition at line 1000 of file callerid.c.
References ast_is_valid_string().
Referenced by check_peer_ok(), check_user_full(), get_pai(), and get_rpid().
{
return ast_is_valid_string(exten, "0123456789*#+()-.");
}
| int ast_isphonenumber | ( | const char * | n | ) |
Check if a string consists only of digits and + #.
| n | number to be checked. |
Definition at line 995 of file callerid.c.
References ast_is_valid_string().
Referenced by ast_callerid_parse().
{
return ast_is_valid_string(n, "0123456789*#+");
}
| const char* ast_named_caller_presentation | ( | int | data | ) |
Convert caller ID pres value to text code.
| data | AST_PRES_ value from callerid.h |
Definition at line 1178 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().
{
int index;
for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
if (pres_types[index].value == data) {
return pres_types[index].name;
}
}
return "unknown";
}
| int ast_parse_caller_presentation | ( | const char * | data | ) |
Convert caller ID text code to value (used in config file parsing)
| data | text string from config file |
| value | AST_PRES_ from callerid.h |
| -1 | if not in table |
Definition at line 1139 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().
{
int index;
if (!data) {
return -1;
}
for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
if (!strcasecmp(pres_types[index].name, data)) {
return pres_types[index].value;
}
}
return -1;
}
| const char* ast_party_name_charset_describe | ( | int | data | ) |
Convert ast_party_name.char_set value to explanatory string.
| data | AST_PARTY_CHAR_SET from channel.h |
Definition at line 1328 of file callerid.c.
References ARRAY_LEN, ast_value_translation::description, and value.
Referenced by sig_pri_event_party_id().
{
int index;
for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
if (party_name_charset_tbl[index].value == data) {
return party_name_charset_tbl[index].description;
}
}
return "not-known";
}
| int ast_party_name_charset_parse | ( | const char * | data | ) |
Convert ast_party_name.char_set text code to value (used in config file parsing)
| data | text string from config file |
| AST_PARTY_CHAR_SET | from channel.h |
| -1 | if not in table |
Definition at line 1315 of file callerid.c.
References ARRAY_LEN, name, and ast_value_translation::value.
Referenced by party_name_write().
{
int index;
for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
return party_name_charset_tbl[index].value;
}
}
return -1;
}
| const char* ast_party_name_charset_str | ( | int | data | ) |
Convert ast_party_name.char_set value to text code.
| data | AST_PARTY_CHAR_SET from channel.h |
Definition at line 1341 of file callerid.c.
References ARRAY_LEN, ast_value_translation::name, and value.
Referenced by party_name_read().
{
int index;
for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
if (party_name_charset_tbl[index].value == data) {
return party_name_charset_tbl[index].name;
}
}
return "not-known";
}
| const char* ast_redirecting_reason_describe | ( | int | data | ) |
Convert redirecting reason value to explanatory string.
| data | Q931_REDIRECTING_REASON from callerid.h |
Definition at line 1222 of file callerid.c.
References ARRAY_LEN, ast_value_translation::description, and value.
{
int index;
for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
if (redirecting_reason_types[index].value == data) {
return redirecting_reason_types[index].description;
}
}
return "not-known";
}
| const char* ast_redirecting_reason_name | ( | int | data | ) |
Convert redirecting reason value to text code.
| data | Q931_REDIRECTING_REASON from callerid.h |
Definition at line 1235 of file callerid.c.
References ARRAY_LEN, ast_value_translation::name, and value.
Referenced by redirecting_read().
{
int index;
for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
if (redirecting_reason_types[index].value == data) {
return redirecting_reason_types[index].name;
}
}
return "not-known";
}
| int ast_redirecting_reason_parse | ( | const char * | data | ) |
Convert redirecting reason text code to value (used in config file parsing)
| data | text string from config file |
| Q931_REDIRECTING_REASON | from callerid.h |
| -1 | if not in table |
Definition at line 1209 of file callerid.c.
References ARRAY_LEN, name, and ast_value_translation::value.
Referenced by redirecting_write().
{
int index;
for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
if (!strcasecmp(redirecting_reason_types[index].name, data)) {
return redirecting_reason_types[index].value;
}
}
return -1;
}
| void ast_shrink_phone_number | ( | char * | n | ) |
Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...
| n | The number to be stripped/shrunk |
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 944 of file callerid.c.
Referenced by __analog_ss_thread(), action_originate(), analog_ss_thread(), ast_callerid_parse(), ast_callerid_split(), ast_privacy_check(), ast_privacy_set(), check_access(), check_peer_ok(), check_user_full(), get_pai(), get_rpid(), handle_setcallerid(), pbx_load_config(), pri_dchannel(), rpt_exec(), setup_privacy_args(), and write_metadata().
{
int x, y = 0;
int bracketed = 0;
for (x = 0; n[x]; x++) {
switch (n[x]) {
case '[':
bracketed++;
n[y++] = n[x];
break;
case ']':
bracketed--;
n[y++] = n[x];
break;
case '-':
if (bracketed)
n[y++] = n[x];
break;
case '.':
if (!n[x+1])
n[y++] = n[x];
break;
default:
/* ignore parenthesis and whitespace */
if (!strchr("( )", n[x]))
n[y++] = n[x];
}
}
n[y] = '\0';
}
| int callerid_feed | ( | struct callerid_state * | cid, |
| unsigned char * | ubuf, | ||
| int | samples, | ||
| format_t | codec | ||
| ) |
Read samples into the state machine.
| cid | Which state machine to act upon |
| ubuf | containing your samples |
| samples | number of samples contained within the buffer. |
| codec | which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Send received audio to the Caller*ID demodulator.
| -1 | on error |
| 0 | for "needs more samples" |
| 1 | if the CallerID spill reception is complete. |
Definition at line 542 of file callerid.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), AST_XLAW, CID_MSGWAITING, CID_NOMSGWAITING, CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, callerid_state::cksum, callerid_state::flags, fsk_serial(), callerid_state::fskd, callerid_state::len, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, callerid_state::name, callerid_state::number, callerid_state::oldlen, callerid_state::oldstuff, callerid_state::pos, callerid_state::rawdata, callerid_state::sawflag, and callerid_state::type.
Referenced by analog_ss_thread(), mwi_thread(), and my_get_callerid().
{
int mylen = len;
int olen;
int b = 'X';
int res;
int x;
short *buf;
buf = alloca(2 * len + cid->oldlen);
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen/2;
for (x = 0; x < len; x++)
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
while (mylen >= 160) {
olen = mylen;
res = fsk_serial(&cid->fskd, buf, &mylen, &b);
if (mylen < 0) {
ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
return -1;
}
buf += (olen - mylen);
if (res < 0) {
ast_log(LOG_NOTICE, "fsk_serial failed\n");
return -1;
}
if (res == 1) {
if (b > 0xff) {
if (cid->sawflag != 5) {
/* Ignore invalid bytes */
continue;
}
/*
* We can tollerate an error on the checksum character since the
* checksum character is the last character in the message and
* it validates the message.
*
* Remove character error flags.
* Bit 8 : Parity error
* Bit 9 : Framing error
*/
b &= 0xff;
}
switch (cid->sawflag) {
case 0: /* Look for flag */
if (b == 'U')
cid->sawflag = 2;
break;
case 2: /* Get lead-in */
if ((b == 0x04) || (b == 0x80) || (b == 0x06) || (b == 0x82)) {
cid->type = b;
cid->sawflag = 3;
cid->cksum = b;
}
break;
case 3: /* Get length */
/* Not a lead in. We're ready */
cid->sawflag = 4;
cid->len = b;
cid->pos = 0;
cid->cksum += b;
break;
case 4: /* Retrieve message */
if (cid->pos >= 128) {
ast_log(LOG_WARNING, "Caller ID too long???\n");
return -1;
}
cid->rawdata[cid->pos++] = b;
cid->len--;
cid->cksum += b;
if (!cid->len) {
cid->rawdata[cid->pos] = '\0';
cid->sawflag = 5;
}
break;
case 5: /* Check checksum */
if (b != (256 - (cid->cksum & 0xff))) {
ast_log(LOG_NOTICE, "Caller*ID failed checksum\n");
/* Try again */
cid->sawflag = 0;
break;
}
cid->number[0] = '\0';
cid->name[0] = '\0';
/* Update flags */
cid->flags = 0;
/* If we get this far we're fine. */
if ((cid->type == 0x80) || (cid->type == 0x82)) {
/* MDMF */
/* Go through each element and process */
for (x = 0; x < cid->pos;) {
switch (cid->rawdata[x++]) {
case 1:
/* Date */
break;
case 2: /* Number */
case 3: /* Number (for Zebble) */
case 4: /* Number */
res = cid->rawdata[x];
if (res > 32) {
ast_log(LOG_NOTICE, "Truncating long caller ID number from %d bytes to 32\n", cid->rawdata[x]);
res = 32;
}
if (ast_strlen_zero(cid->number)) {
memcpy(cid->number, cid->rawdata + x + 1, res);
/* Null terminate */
cid->number[res] = '\0';
}
break;
case 6: /* Stentor Call Qualifier (ie. Long Distance call) */
break;
case 7: /* Name */
case 8: /* Name */
res = cid->rawdata[x];
if (res > 32) {
ast_log(LOG_NOTICE, "Truncating long caller ID name from %d bytes to 32\n", cid->rawdata[x]);
res = 32;
}
memcpy(cid->name, cid->rawdata + x + 1, res);
cid->name[res] = '\0';
break;
case 11: /* Message Waiting */
res = cid->rawdata[x + 1];
if (res)
cid->flags |= CID_MSGWAITING;
else
cid->flags |= CID_NOMSGWAITING;
break;
case 17: /* UK: Call type, 1=Voice Call, 2=Ringback when free, 129=Message waiting */
case 19: /* UK: Network message system status (Number of messages waiting) */
case 22: /* Something French */
break;
default:
ast_log(LOG_NOTICE, "Unknown IE %d\n", cid->rawdata[x - 1]);
}
res = cid->rawdata[x];
if (0 > res){ /* Negative offset in the CID Spill */
ast_log(LOG_NOTICE, "IE %d has bad field length of %d at offset %d\n", cid->rawdata[x-1], cid->rawdata[x], x);
/* Try again */
cid->sawflag = 0;
break; /* Exit the loop */
}
x += cid->rawdata[x];
x++;
}
} else if (cid->type == 0x6) {
/* VMWI SDMF */
if (cid->rawdata[2] == 0x42) {
cid->flags |= CID_MSGWAITING;
} else if (cid->rawdata[2] == 0x6f) {
cid->flags |= CID_NOMSGWAITING;
}
} else {
/* SDMF */
ast_copy_string(cid->number, cid->rawdata + 8, sizeof(cid->number));
}
if (!strcmp(cid->number, "P")) {
strcpy(cid->number, "");
cid->flags |= CID_PRIVATE_NUMBER;
} else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) {
strcpy(cid->number, "");
cid->flags |= CID_UNKNOWN_NUMBER;
}
if (!strcmp(cid->name, "P")) {
strcpy(cid->name, "");
cid->flags |= CID_PRIVATE_NAME;
} else if (!strcmp(cid->name, "O") || ast_strlen_zero(cid->name)) {
strcpy(cid->name, "");
cid->flags |= CID_UNKNOWN_NAME;
}
return 1;
break;
default:
ast_log(LOG_ERROR, "Dunno what to do with a digit in sawflag %d\n", cid->sawflag);
}
}
}
if (mylen) {
memcpy(cid->oldstuff, buf, mylen * 2);
cid->oldlen = mylen * 2;
} else
cid->oldlen = 0;
return 0;
}
| int callerid_feed_jp | ( | struct callerid_state * | cid, |
| unsigned char * | ubuf, | ||
| int | samples, | ||
| format_t | codec | ||
| ) |
Read samples into the state machine.
| cid | Which state machine to act upon |
| ubuf | containing your samples |
| samples | number of samples contained within the buffer. |
| codec | which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW) |
Send received audio to the Caller*ID demodulator (for japanese style lines).
| -1 | on error |
| 0 | for "needs more samples" |
| 1 | if the CallerID spill reception is complete. |
Definition at line 303 of file callerid.c.
References 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, 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().
{
int mylen = len;
int olen;
int b = 'X';
int b2;
int res;
int x;
short *buf;
buf = alloca(2 * len + cid->oldlen);
memcpy(buf, cid->oldstuff, cid->oldlen);
mylen += cid->oldlen / 2;
for (x = 0; x < len; x++)
buf[x+cid->oldlen/2] = AST_XLAW(ubuf[x]);
while (mylen >= 160) {
b = b2 = 0;
olen = mylen;
res = fsk_serial(&cid->fskd, buf, &mylen, &b);
if (mylen < 0) {
ast_log(LOG_ERROR, "No start bit found in fsk data.\n");
return -1;
}
buf += (olen - mylen);
if (res < 0) {
ast_log(LOG_NOTICE, "fsk_serial failed\n");
return -1;
}
if (res == 1) {
b2 = b;
b &= 0x7f;
/* crc checksum calculation */
if (cid->sawflag > 1)
cid->crc = calc_crc(cid->crc, (unsigned char) b2);
/* Ignore invalid bytes */
if (b > 0xff)
continue;
/* skip DLE if needed */
if (cid->sawflag > 0) {
if (cid->sawflag != 5 && cid->skipflag == 0 && b == 0x10) {
cid->skipflag = 1 ;
continue ;
}
}
if (cid->skipflag == 1)
cid->skipflag = 0 ;
/* caller id retrieval */
switch (cid->sawflag) {
case 0: /* DLE */
if (b == 0x10) {
cid->sawflag = 1;
cid->skipflag = 0;
cid->crc = 0;
}
break;
case 1: /* SOH */
if (b == 0x01)
cid->sawflag = 2;
break ;
case 2: /* HEADER */
if (b == 0x07)
cid->sawflag = 3;
break;
case 3: /* STX */
if (b == 0x02)
cid->sawflag = 4;
break;
case 4: /* SERVICE TYPE */
if (b == 0x40)
cid->sawflag = 5;
break;
case 5: /* Frame Length */
cid->sawflag = 6;
break;
case 6: /* NUMBER TYPE */
cid->sawflag = 7;
cid->pos = 0;
cid->rawdata[cid->pos++] = b;
break;
case 7: /* NUMBER LENGTH */
cid->sawflag = 8;
cid->len = b;
if ((cid->len+2) >= sizeof(cid->rawdata)) {
ast_log(LOG_WARNING, "too long caller id string\n") ;
return -1;
}
cid->rawdata[cid->pos++] = b;
break;
case 8: /* Retrieve message */
cid->rawdata[cid->pos++] = b;
cid->len--;
if (cid->len<=0) {
cid->rawdata[cid->pos] = '\0';
cid->sawflag = 9;
}
break;
case 9: /* ETX */
cid->sawflag = 10;
break;
case 10: /* CRC Checksum 1 */
cid->sawflag = 11;
break;
case 11: /* CRC Checksum 2 */
cid->sawflag = 12;
if (cid->crc != 0) {
ast_log(LOG_WARNING, "crc checksum error\n") ;
return -1;
}
/* extract caller id data */
for (x = 0; x < cid->pos;) {
switch (cid->rawdata[x++]) {
case 0x02: /* caller id number */
cid->number[0] = '\0';
cid->name[0] = '\0';
cid->flags = 0;
res = cid->rawdata[x++];
ast_copy_string(cid->number, &cid->rawdata[x], res+1);
x += res;
break;
case 0x21: /* additional information */
/* length */
x++;
/* number type */
switch (cid->rawdata[x]) {
case 0x00: /* unknown */
case 0x01: /* international number */
case 0x02: /* domestic number */
case 0x03: /* network */
case 0x04: /* local call */
case 0x06: /* short dial number */
case 0x07: /* reserved */
default: /* reserved */
ast_debug(2, "cid info:#1=%X\n", cid->rawdata[x]);
break ;
}
x++;
/* numbering plan octed 4 */
x++;
/* numbering plan octed 5 */
switch (cid->rawdata[x]) {
case 0x00: /* unknown */
case 0x01: /* recommendation E.164 ISDN */
case 0x03: /* recommendation X.121 */
case 0x04: /* telex dial plan */
case 0x08: /* domestic dial plan */
case 0x09: /* private dial plan */
case 0x05: /* reserved */
default: /* reserved */
ast_debug(2, "cid info:#2=%X\n", cid->rawdata[x]);
break ;
}
x++;
break ;
case 0x04: /* no callerid reason */
/* length */
x++;
/* no callerid reason code */
switch (cid->rawdata[x]) {
case 'P': /* caller id denied by user */
case 'O': /* service not available */
case 'C': /* pay phone */
case 'S': /* service congested */
cid->flags |= CID_UNKNOWN_NUMBER;
ast_debug(2, "no cid reason:%c\n", cid->rawdata[x]);
break ;
}
x++;
break ;
case 0x09: /* dialed number */
/* length */
res = cid->rawdata[x++];
/* dialed number */
x += res;
break ;
case 0x22: /* dialed number additional information */
/* length */
x++;
/* number type */
switch (cid->rawdata[x]) {
case 0x00: /* unknown */
case 0x01: /* international number */
case 0x02: /* domestic number */
case 0x03: /* network */
case 0x04: /* local call */
case 0x06: /* short dial number */
case 0x07: /* reserved */
default: /* reserved */
if (option_debug > 1)
ast_log(LOG_NOTICE, "did info:#1=%X\n", cid->rawdata[x]);
break ;
}
x++;
/* numbering plan octed 4 */
x++;
/* numbering plan octed 5 */
switch (cid->rawdata[x]) {
case 0x00: /* unknown */
case 0x01: /* recommendation E.164 ISDN */
case 0x03: /* recommendation X.121 */
case 0x04: /* telex dial plan */
case 0x08: /* domestic dial plan */
case 0x09: /* private dial plan */
case 0x05: /* reserved */
default: /* reserved */
ast_debug(2, "did info:#2=%X\n", cid->rawdata[x]);
break ;
}
x++;
break ;
}
}
return 1;
break;
default:
ast_log(LOG_ERROR, "invalid value in sawflag %d\n", cid->sawflag);
}
}
}
if (mylen) {
memcpy(cid->oldstuff, buf, mylen * 2);
cid->oldlen = mylen * 2;
} else
cid->oldlen = 0;
return 0;
}
| void callerid_free | ( | struct callerid_state * | cid | ) |
This function frees callerid_state cid.
| cid | This is the callerid_state state machine to free |
Definition at line 731 of file callerid.c.
References ast_free.
Referenced by __analog_ss_thread(), analog_ss_thread(), mwi_thread(), my_get_callerid(), and my_stop_cid_detect().
{
ast_free(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.
| buf | Buffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own. "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun. |
| number | Use NULL for no number or "P" for "private" |
| name | name to be used |
| flags | passed flags |
| callwaiting | callwaiting flag |
| codec | -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW |
This function creates a stream of callerid (a callerid spill) data in ulaw format.
Definition at line 895 of file callerid.c.
References callerid_genmsg(), len(), PUT_BYTE, PUT_CLID, and PUT_CLID_MARKMS.
Referenced by __ast_callerid_generate().
{
int bytes = 0;
int x, sum;
int len;
/* Initial carriers (real/imaginary) */
float cr = 1.0;
float ci = 0.0;
float scont = 0.0;
char msg[256];
len = callerid_genmsg(msg, sizeof(msg), number, name, flags);
if (!callwaiting) {
/* Wait a half a second */
for (x = 0; x < 4000; x++)
PUT_BYTE(0x7f);
/* Transmit 30 0x55's (looks like a square wave) for channel seizure */
for (x = 0; x < 30; x++)
PUT_CLID(0x55);
}
/* Send 150ms of callerid marks */
for (x = 0; x < 150; x++)
PUT_CLID_MARKMS;
/* Send 0x80 indicating MDMF format */
PUT_CLID(0x80);
/* Put length of whole message */
PUT_CLID(len);
sum = 0x80 + strlen(msg);
/* Put each character of message and update checksum */
for (x = 0; x < len; x++) {
PUT_CLID(msg[x]);
sum += msg[x];
}
/* Send 2's compliment of sum */
PUT_CLID(256 - (sum & 255));
/* Send 50 more ms of marks */
for (x = 0; x < 50; x++)
PUT_CLID_MARKMS;
return bytes;
}
| void callerid_get | ( | struct callerid_state * | cid, |
| char ** | number, | ||
| char ** | name, | ||
| int * | flags | ||
| ) |
Extract info out of callerID state machine. Flags are listed above.
| cid | Callerid state machine to act upon |
| number | Pass the address of a pointer-to-char (will contain the phone number) |
| name | Pass the address of a pointer-to-char (will contain the name) |
| flags | Pass the address of an int variable(will contain the various callerid flags) |
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:
Definition at line 185 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().
{
*flags = cid->flags;
if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NAME))
*name = NULL;
else
*name = cid->name;
if (cid->flags & (CID_UNKNOWN_NUMBER | CID_PRIVATE_NUMBER))
*number = NULL;
else
*number = cid->number;
}
| void callerid_get_dtmf | ( | char * | cidstring, |
| char * | number, | ||
| int * | flags | ||
| ) |
Get and parse DTMF-based callerid.
| cidstring | The actual transmitted string. |
| number | The cid number is returned here. |
| flags | The cid flags are returned here. |
Definition at line 198 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().
{
int i;
int code;
/* "Clear" the number-buffer. */
number[0] = 0;
if (strlen(cidstring) < 2) {
ast_debug(1, "No cid detected\n");
*flags = CID_UNKNOWN_NUMBER;
return;
}
/* Detect protocol and special types */
if (cidstring[0] == 'B') {
/* Handle special codes */
code = atoi(&cidstring[1]);
if (code == 0)
*flags = CID_UNKNOWN_NUMBER;
else if (code == 10)
*flags = CID_PRIVATE_NUMBER;
else
ast_debug(1, "Unknown DTMF code %d\n", code);
} else if (cidstring[0] == 'D' && cidstring[2] == '#') {
/* .DK special code */
if (cidstring[1] == '1')
*flags = CID_PRIVATE_NUMBER;
if (cidstring[1] == '2' || cidstring[1] == '3')
*flags = CID_UNKNOWN_NUMBER;
} else if (cidstring[0] == 'D' || cidstring[0] == 'A') {
/* "Standard" callerid */
for (i = 1; i < strlen(cidstring); i++) {
if (cidstring[i] == 'C' || cidstring[i] == '#')
break;
if (isdigit(cidstring[i]))
number[i-1] = cidstring[i];
else
ast_debug(1, "Unknown CID digit '%c'\n",
cidstring[i]);
}
number[i-1] = 0;
} else if (isdigit(cidstring[0])) {
/* It begins with a digit, so we parse it as a number and hope
* for the best */
ast_log(LOG_WARNING, "Couldn't detect start-character. CID "
"parsing might be unreliable\n");
for (i = 0; i < strlen(cidstring); i++) {
if (isdigit(cidstring[i]))
number[i] = cidstring[i];
else
break;
}
number[i] = 0;
} else {
ast_debug(1, "Unknown CID protocol, start digit '%c'\n", cidstring[0]);
*flags = CID_UNKNOWN_NUMBER;
}
}
| static float callerid_getcarrier | ( | float * | cr, |
| float * | ci, | ||
| int | bit | ||
| ) | [inline, static] |
| void callerid_init | ( | void | ) |
CallerID Initialization.
Definition at line 112 of file callerid.c.
References CALLERID_MARK, CALLERID_SPACE, CAS_FREQ1, CAS_FREQ2, cos, M_PI, and SAS_FREQ.
Referenced by main().
{
cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0);
cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0);
sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0);
sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0);
casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
}
| struct callerid_state* callerid_new | ( | int | cid_signalling | ) | [read] |
Create a callerID state machine.
| cid_signalling | Type of signalling in use |
This function returns a malloc'd instance of the callerid_state data structure.
Definition at line 126 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().
{
struct callerid_state *cid;
if ((cid = ast_calloc(1, sizeof(*cid)))) {
#ifdef INTEGER_CALLERID
cid->fskd.ispb = 7; /* 1200 baud */
/* Set up for 1200 / 8000 freq *32 to allow ints */
cid->fskd.pllispb = (int)(8000 * 32 / 1200);
cid->fskd.pllids = cid->fskd.pllispb/32;
cid->fskd.pllispb2 = cid->fskd.pllispb/2;
cid->fskd.icont = 0; /* PLL REset */
/* cid->fskd.hdlc = 0; */ /* Async */
cid->fskd.nbit = 8; /* 8 bits */
cid->fskd.instop = 1; /* 1 stop bit */
/* cid->fskd.paridad = 0; */ /* No parity */
cid->fskd.bw = 1; /* Filter 800 Hz */
if (cid_signalling == 2) { /* v23 signalling */
cid->fskd.f_mark_idx = 4; /* 1300 Hz */
cid->fskd.f_space_idx = 5; /* 2100 Hz */
} else { /* Bell 202 signalling as default */
cid->fskd.f_mark_idx = 2; /* 1200 Hz */
cid->fskd.f_space_idx = 3; /* 2200 Hz */
}
/* cid->fskd.pcola = 0; */ /* No clue */
/* cid->fskd.cont = 0.0; */ /* Digital PLL reset */
/* cid->fskd.x0 = 0.0; */
/* cid->fskd.state = 0; */
cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
/* cid->pos = 0; */
fskmodem_init(&cid->fskd);
#else
cid->fskd.spb = 7.0; /* 1200 baud */
/* cid->fskd.hdlc = 0; */ /* Async */
cid->fskd.nbit = 8; /* 8 bits */
cid->fskd.nstop = 1.0; /* 1 stop bit */
/* cid->fskd.paridad = 0; */ /* No parity */
cid->fskd.bw = 1; /* Filter 800 Hz */
if (cid_signalling == 2) { /* v23 signalling */
cid->fskd.f_mark_idx = 4; /* 1300 Hz */
cid->fskd.f_space_idx = 5; /* 2100 Hz */
} else { /* Bell 202 signalling as default */
cid->fskd.f_mark_idx = 2; /* 1200 Hz */
cid->fskd.f_space_idx = 3; /* 2200 Hz */
}
/* cid->fskd.pcola = 0; */ /* No clue */
/* cid->fskd.cont = 0.0; */ /* Digital PLL reset */
/* cid->fskd.x0 = 0.0; */
/* cid->fskd.state = 0; */
cid->flags = CID_UNKNOWN_NAME | CID_UNKNOWN_NUMBER;
/* cid->pos = 0; */
#endif
}
return cid;
}
| float cid_di[4] |
Definition at line 61 of file callerid.c.
Referenced by callerid_getcarrier().
| float cid_dr[4] |
Definition at line 61 of file callerid.c.
Referenced by callerid_getcarrier().
| float clidsb |
Definition at line 62 of file callerid.c.