Asterisk - The Open Source Telephony Project  18.5.0
Macros | Typedefs | Enumerations | Functions | Variables
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.

Macros

#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) More...
 
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) More...
 
char * ast_callerid_merge (char *buf, int bufsiz, const char *name, const char *num, const char *unknown)
 
int ast_callerid_parse (char *instr, char **name, char **location)
 Destructively parse inbuf into name and location (or number) More...
 
int ast_callerid_split (const char *src, char *name, int namelen, char *num, int numlen)
 
int ast_callerid_vmwi_generate (unsigned char *buf, int active, int type, struct ast_format *codec, const char *name, const char *number, int flags)
 Generate message waiting indicator. More...
 
const char * ast_connected_line_source_describe (int data)
 Convert connected line update source value to explanatory string. More...
 
const char * ast_connected_line_source_name (int data)
 Convert connected line update source value to text code. More...
 
int ast_connected_line_source_parse (const char *data)
 Convert connected line update source text code to value (used in config file parsing) More...
 
const char * ast_describe_caller_presentation (int data)
 Convert caller ID pres value to explanatory string. More...
 
int ast_gen_cas (unsigned char *outbuf, int sas, int len, struct ast_format *codec)
 Generate a CAS (CPE Alert Signal) tone for 'n' samples. More...
 
int ast_is_shrinkable_phonenumber (const char *exten)
 Check if a string consists only of digits and + # ( ) - . (meaning it can be cleaned with ast_shrink_phone_number) More...
 
int ast_isphonenumber (const char *n)
 Check if a string consists only of digits and + #. More...
 
const char * ast_named_caller_presentation (int data)
 Convert caller ID pres value to text code. More...
 
int ast_parse_caller_presentation (const char *data)
 Convert caller ID text code to value (used in config file parsing) More...
 
const char * ast_party_name_charset_describe (int data)
 Convert ast_party_name.char_set value to explanatory string. More...
 
int ast_party_name_charset_parse (const char *data)
 Convert ast_party_name.char_set text code to value (used in config file parsing) More...
 
const char * ast_party_name_charset_str (int data)
 Convert ast_party_name.char_set value to text code. More...
 
const char * ast_redirecting_reason_describe (int data)
 Convert redirecting reason value to explanatory string. More...
 
const char * ast_redirecting_reason_name (const struct ast_party_redirecting_reason *data)
 Convert redirecting reason value to text code. More...
 
int ast_redirecting_reason_parse (const char *data)
 Convert redirecting reason text code to value (used in config file parsing) More...
 
void ast_shrink_phone_number (char *n)
 Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s... More...
 
int callerid_feed (struct callerid_state *cid, unsigned char *ubuf, int samples, struct ast_format *codec)
 Read samples into the state machine. More...
 
int callerid_feed_jp (struct callerid_state *cid, unsigned char *ubuf, int samples, struct ast_format *codec)
 Read samples into the state machine. More...
 
void callerid_free (struct callerid_state *cid)
 This function frees callerid_state cid. More...
 
int callerid_generate (unsigned char *buf, const char *number, const char *name, int flags, int callwaiting, struct ast_format *codec)
 Generates a CallerID FSK stream in ulaw format suitable for transmission. More...
 
void callerid_get (struct callerid_state *cid, char **number, char **name, int *flags)
 Extract info out of callerID state machine. Flags are listed above. More...
 
void callerid_get_dtmf (char *cidstring, char *number, int *flags)
 Get and parse DTMF-based callerid. More...
 
static float callerid_getcarrier (float *cr, float *ci, int bit)
 
void callerid_init (void)
 CallerID Initialization. More...
 
struct callerid_statecallerid_new (int cid_signalling)
 Create a callerID state machine. More...
 

Variables

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

Detailed Description

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

Caller ID names and numbers

Definition in file callerid.h.

Macro Definition Documentation

◆ AST_LIN2X

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

◆ AST_PRES_ALLOWED

#define AST_PRES_ALLOWED   0x00

◆ AST_PRES_ALLOWED_NETWORK_NUMBER

#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_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN

#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_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED

#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED   (AST_PRES_ALLOWED | AST_PRES_USER_NUMBER_UNSCREENED)

◆ AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN

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

◆ AST_PRES_NETWORK_NUMBER

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

◆ AST_PRES_NUMBER_NOT_AVAILABLE

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

◆ AST_PRES_NUMBER_TYPE

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

◆ AST_PRES_PROHIB_NETWORK_NUMBER

#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_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN

#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_PRES_PROHIB_USER_NUMBER_NOT_SCREENED

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

◆ AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN

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

◆ AST_PRES_RESERVED

#define AST_PRES_RESERVED   0x60

Definition at line 327 of file callerid.h.

◆ AST_PRES_RESTRICTED

#define AST_PRES_RESTRICTED   0x20

◆ AST_PRES_RESTRICTION

#define AST_PRES_RESTRICTION   0x60

◆ AST_PRES_UNAVAILABLE

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

◆ AST_PRES_USER_NUMBER_FAILED_SCREEN

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

◆ AST_PRES_USER_NUMBER_PASSED_SCREEN

#define AST_PRES_USER_NUMBER_PASSED_SCREEN   0x01

◆ AST_PRES_USER_NUMBER_UNSCREENED

#define AST_PRES_USER_NUMBER_UNSCREENED   0x00

◆ AST_XLAW

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

◆ CID_MSGWAITING

#define CID_MSGWAITING   (1 << 4)

Definition at line 56 of file callerid.h.

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

◆ CID_MWI_TYPE_MDMF

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

◆ CID_MWI_TYPE_MDMF_FULL

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

◆ CID_MWI_TYPE_SDMF

#define CID_MWI_TYPE_SDMF   0x00

MWI SDMF format

Definition at line 72 of file callerid.h.

◆ CID_NOMSGWAITING

#define CID_NOMSGWAITING   (1 << 5)

Definition at line 57 of file callerid.h.

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

◆ CID_PRIVATE_NAME

#define CID_PRIVATE_NAME   (1 << 0)

Definition at line 52 of file callerid.h.

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

◆ CID_PRIVATE_NUMBER

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

◆ CID_SIG_BELL

#define CID_SIG_BELL   1

Definition at line 59 of file callerid.h.

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

◆ CID_SIG_DTMF

#define CID_SIG_DTMF   3

Definition at line 61 of file callerid.h.

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

◆ CID_SIG_SMDI

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

◆ CID_SIG_V23

#define CID_SIG_V23   2

Definition at line 60 of file callerid.h.

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

◆ CID_SIG_V23_JP

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

◆ CID_START_DTMF_NOALERT

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

◆ CID_START_POLARITY

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

◆ CID_START_POLARITY_IN

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

◆ CID_START_RING

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

◆ CID_UNKNOWN_NAME

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

◆ CID_UNKNOWN_NUMBER

#define CID_UNKNOWN_NUMBER   (1 << 3)

◆ MAX_CALLERID_SIZE

#define MAX_CALLERID_SIZE   32000

Definition at line 50 of file callerid.h.

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

◆ PUT_AUDIO_SAMPLE

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

Definition at line 283 of file callerid.h.

◆ PUT_BYTE

#define PUT_BYTE (   a)
Value:
do { \
*(buf++) = (a); \
bytes++; \
} while(0)
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static struct test_val a

Definition at line 278 of file callerid.h.

Referenced by ast_callerid_vmwi_generate(), and callerid_generate().

◆ PUT_CLID

#define PUT_CLID (   byte)

◆ PUT_CLID_BAUD

#define PUT_CLID_BAUD (   bit)

Definition at line 295 of file callerid.h.

◆ PUT_CLID_MARKMS

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

Definition at line 289 of file callerid.h.

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

Typedef Documentation

◆ CIDSTATE

typedef struct callerid_state CIDSTATE

Definition at line 83 of file callerid.h.

Enumeration Type Documentation

◆ AST_CONNECTED_LINE_UPDATE_SOURCE

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.

442  {
443  /*! Update for unknown reason (May be interpreted to mean from answer) */
445  /*! Update from normal call answering */
447  /*! Update from call diversion (Deprecated, use REDIRECTING updates instead.) */
449  /*! Update from call transfer(active) (Party has already answered) */
451  /*! Update from call transfer(alerting) (Party has not answered yet) */
453 };

◆ AST_REDIRECTING_REASON

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

◆ ast_callerid_callwaiting_generate()

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

References __ast_callerid_generate().

Referenced by my_send_callerid(), and send_cwcidspill().

1069 {
1070  return __ast_callerid_generate(buf, name, number, 1, codec);
1071 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, struct ast_format *codec)
Definition: callerid.c:1054
Number structure.
Definition: app_followme.c:154
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_callerid_generate()

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
bufbuffer for output samples. See callerid_generate() for details regarding buffer.
nameCaller-ID Name
numberCaller-ID Number
codecAsterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)

Acts like callerid_generate except uses an asterisk format callerid string.

Definition at line 1063 of file callerid.c.

References __ast_callerid_generate().

Referenced by my_send_callerid().

1064 {
1065  return __ast_callerid_generate(buf, name, number, 0, codec);
1066 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, int callwaiting, struct ast_format *codec)
Definition: callerid.c:1054
Number structure.
Definition: app_followme.c:154
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_callerid_merge()

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(), ast_escape_quoted(), and buf.

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

1074 {
1075  if (!unknown)
1076  unknown = "<unknown>";
1077  if (name && num) {
1078  char name_buf[128];
1079 
1080  ast_escape_quoted(name, name_buf, sizeof(name_buf));
1081  snprintf(buf, bufsiz, "\"%s\" <%s>", name_buf, num);
1082  } else if (name) {
1083  ast_copy_string(buf, name, bufsiz);
1084  } else if (num) {
1085  ast_copy_string(buf, num, bufsiz);
1086  } else {
1087  ast_copy_string(buf, unknown, bufsiz);
1088  }
1089  return buf;
1090 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: cdr_mysql.c:74
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
Definition: main/utils.c:635
static struct ast_codec unknown
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ ast_callerid_parse()

int ast_callerid_parse ( char *  instr,
char **  name,
char **  location 
)

Destructively parse inbuf into name and location (or number)

Parses callerid stream from inbuf and changes into useable form, outputed in name and location.

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

Definition at line 1008 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(), unistim_new(), and vm_allocate_dh().

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

◆ ast_callerid_split()

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

Definition at line 1092 of file callerid.c.

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

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

1093 {
1094  char *tmp;
1095  char *l = NULL, *n = NULL;
1096 
1097  tmp = ast_strdupa(buf);
1098  ast_callerid_parse(tmp, &n, &l);
1099  if (n)
1100  ast_copy_string(name, n, namelen);
1101  else
1102  name[0] = '\0';
1103  if (l) {
1105  ast_copy_string(num, l, numlen);
1106  } else
1107  num[0] = '\0';
1108  return 0;
1109 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static int tmp()
Definition: bt_open.c:389
#define NULL
Definition: resample.c:96
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
void ast_shrink_phone_number(char *n)
Clean up phone string.
Definition: callerid.c:947
static const char name[]
Definition: cdr_mysql.c:74
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
int ast_callerid_parse(char *input_str, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008

◆ ast_callerid_vmwi_generate()

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

Definition at line 810 of file callerid.c.

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

Referenced by mwi_send_init().

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

◆ ast_connected_line_source_describe()

const char* ast_connected_line_source_describe ( int  data)

Convert connected line update source value to explanatory string.

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

Definition at line 1292 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

1293 {
1294  int index;
1295 
1296  for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1297  if (connected_line_source_types[index].value == data) {
1299  }
1300  }
1301 
1302  return "not-known";
1303 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
const char * description
Definition: callerid.c:1114
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1268

◆ ast_connected_line_source_name()

const char* ast_connected_line_source_name ( int  data)

Convert connected line update source value to text code.

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

Definition at line 1305 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by connectedline_read().

1306 {
1307  int index;
1308 
1309  for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1310  if (connected_line_source_types[index].value == data) {
1311  return connected_line_source_types[index].name;
1312  }
1313  }
1314 
1315  return "not-known";
1316 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1268
const char * name
Definition: callerid.c:1113

◆ ast_connected_line_source_parse()

int ast_connected_line_source_parse ( const char *  data)

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

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

Definition at line 1279 of file callerid.c.

References ARRAY_LEN, callerid_state::name, and ast_value_translation::value.

Referenced by connectedline_write().

1280 {
1281  int index;
1282 
1283  for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1284  if (!strcasecmp(connected_line_source_types[index].name, data)) {
1285  return connected_line_source_types[index].value;
1286  }
1287  }
1288 
1289  return -1;
1290 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1268
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_describe_caller_presentation()

const char* ast_describe_caller_presentation ( int  data)

Convert caller ID pres value to explanatory string.

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

Definition at line 1164 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(), and sip_show_user().

1165 {
1166  int index;
1167 
1168  for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1169  if (pres_types[index].value == data) {
1170  return pres_types[index].description;
1171  }
1172  }
1173 
1174  return "unknown";
1175 }
static const struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Definition: callerid.c:1118
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
const char * description
Definition: callerid.c:1114

◆ ast_gen_cas()

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

Definition at line 261 of file callerid.c.

References casdi1, casdi2, casdr1, casdr2, gen_tone(), gen_tones(), callerid_state::pos, sasdi, and sasdr.

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

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

◆ ast_is_shrinkable_phonenumber()

int ast_is_shrinkable_phonenumber ( const char *  exten)

Check if a string consists only of digits and + # ( ) - . (meaning it can be cleaned with ast_shrink_phone_number)

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

Definition at line 1003 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().

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

◆ ast_isphonenumber()

int ast_isphonenumber ( const char *  n)

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

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

Definition at line 998 of file callerid.c.

References ast_is_valid_string().

Referenced by ast_callerid_parse(), and hfp_parse_clip().

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

◆ ast_named_caller_presentation()

const char* ast_named_caller_presentation ( int  data)

Convert caller ID pres value to text code.

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

Definition at line 1182 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

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

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

◆ ast_parse_caller_presentation()

int ast_parse_caller_presentation ( const char *  data)

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

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

Definition at line 1143 of file callerid.c.

References ARRAY_LEN, callerid_state::name, and ast_value_translation::value.

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

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

◆ ast_party_name_charset_describe()

const char* ast_party_name_charset_describe ( int  data)

Convert ast_party_name.char_set value to explanatory string.

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

Definition at line 1347 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

Referenced by json_party_name().

1348 {
1349  int index;
1350 
1351  for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1352  if (party_name_charset_tbl[index].value == data) {
1353  return party_name_charset_tbl[index].description;
1354  }
1355  }
1356 
1357  return "not-known";
1358 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
const char * description
Definition: callerid.c:1114
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1319

◆ ast_party_name_charset_parse()

int ast_party_name_charset_parse ( const char *  data)

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

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

Definition at line 1334 of file callerid.c.

References ARRAY_LEN, callerid_state::name, and ast_value_translation::value.

Referenced by party_name_write().

1335 {
1336  int index;
1337 
1338  for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1339  if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
1340  return party_name_charset_tbl[index].value;
1341  }
1342  }
1343 
1344  return -1;
1345 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1319
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_party_name_charset_str()

const char* ast_party_name_charset_str ( int  data)

Convert ast_party_name.char_set value to text code.

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

Definition at line 1360 of file callerid.c.

References ARRAY_LEN, ast_value_translation::name, and value.

Referenced by party_name_read().

1361 {
1362  int index;
1363 
1364  for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1365  if (party_name_charset_tbl[index].value == data) {
1366  return party_name_charset_tbl[index].name;
1367  }
1368  }
1369 
1370  return "not-known";
1371 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1319
const char * name
Definition: callerid.c:1113

◆ ast_redirecting_reason_describe()

const char* ast_redirecting_reason_describe ( int  data)

Convert redirecting reason value to explanatory string.

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

Definition at line 1236 of file callerid.c.

References ARRAY_LEN, ast_value_translation::description, and value.

1237 {
1238  int index;
1239 
1240  for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1241  if (redirecting_reason_types[index].value == data) {
1242  return redirecting_reason_types[index].description ?: "Redirecting reason alias-bug";
1243  }
1244  }
1245 
1246  return "not-known";
1247 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
const char * description
Definition: callerid.c:1114
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1196

◆ ast_redirecting_reason_name()

const char* ast_redirecting_reason_name ( const struct ast_party_redirecting_reason data)

Convert redirecting reason value to text code.

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

Definition at line 1249 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().

1250 {
1251  int index;
1252 
1253  if (!ast_strlen_zero(data->str)) {
1254  /* Use this string if it has been set. Otherwise, use the table. */
1255  return data->str;
1256  }
1257 
1258  for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1259  if (redirecting_reason_types[index].value == data->code) {
1260  return redirecting_reason_types[index].name;
1261  }
1262  }
1263 
1264  return "not-known";
1265 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:37
int code
enum AST_REDIRECTING_REASON value for redirection
Definition: channel.h:511
#define ast_strlen_zero(foo)
Definition: strings.h:52
char * str
a string value for the redirecting reason
Definition: channel.h:508
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1196
const char * name
Definition: callerid.c:1113

◆ ast_redirecting_reason_parse()

int ast_redirecting_reason_parse ( const char *  data)

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

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

Definition at line 1223 of file callerid.c.

References ARRAY_LEN, callerid_state::name, and ast_value_translation::value.

Referenced by get_rdnis(), handle_response_invite(), redirecting_write(), and set_redirecting_reason().

1224 {
1225  int index;
1226 
1227  for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1228  if (!strcasecmp(redirecting_reason_types[index].name, data)) {
1229  return redirecting_reason_types[index].value;
1230  }
1231  }
1232 
1233  return -1;
1234 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
Definition: cdr_mysql.c:74
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1196

◆ ast_shrink_phone_number()

void ast_shrink_phone_number ( char *  n)

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

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

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

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

Definition at line 947 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().

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

◆ callerid_feed()

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

Read samples into the state machine.

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

Send received audio to the Caller*ID demodulator.

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

Definition at line 545 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().

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

◆ callerid_feed_jp()

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

Read samples into the state machine.

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

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

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

Definition at line 306 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, DEBUG_ATLEAST, 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::skipflag.

Referenced by analog_ss_thread(), and my_get_callerid().

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

◆ callerid_free()

void callerid_free ( struct callerid_state cid)

This function frees callerid_state cid.

Parameters
cidThis is the callerid_state state machine to free

Definition at line 734 of file callerid.c.

References ast_free.

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

735 {
736  ast_free(cid);
737 }
#define ast_free(a)
Definition: astmm.h:182

◆ callerid_generate()

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
bufBuffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own. "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun.
numberUse NULL for no number or "P" for "private"
namename to be used
flagspassed flags
callwaitingcallwaiting flag
codec– either AST_FORMAT_ULAW or AST_FORMAT_ALAW

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

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

Definition at line 898 of file callerid.c.

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

Referenced by __ast_callerid_generate().

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

◆ callerid_get()

void callerid_get ( struct callerid_state cid,
char **  number,
char **  name,
int *  flags 
)

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

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

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

Returns
Returns nothing.

Definition at line 188 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().

189 {
190  *flags = cid->flags;
191  if (cid->flags & (CID_UNKNOWN_NAME | CID_PRIVATE_NAME))
192  *name = NULL;
193  else
194  *name = cid->name;
196  *number = NULL;
197  else
198  *number = cid->number;
199 }
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
#define NULL
Definition: resample.c:96
Number structure.
Definition: app_followme.c:154
#define CID_PRIVATE_NAME
Definition: callerid.h:52
#define CID_PRIVATE_NUMBER
Definition: callerid.h:53
char name[64]
Definition: callerid.c:53
static const char name[]
Definition: cdr_mysql.c:74
#define CID_UNKNOWN_NAME
Definition: callerid.h:54
char number[64]
Definition: callerid.c:54

◆ callerid_get_dtmf()

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

Get and parse DTMF-based callerid.

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

Definition at line 201 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().

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

◆ callerid_getcarrier()

static float callerid_getcarrier ( float *  cr,
float *  ci,
int  bit 
)
inlinestatic

Definition at line 264 of file callerid.h.

References cid_di, and cid_dr.

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

◆ callerid_init()

void callerid_init ( void  )

CallerID Initialization.

Initializes the callerid system. Mostly stuff for inverse FFT

CallerID Initialization.

Definition at line 115 of file callerid.c.

References CALLERID_MARK, CALLERID_SPACE, CAS_FREQ1, CAS_FREQ2, casdi1, casdi2, casdr1, casdr2, cid_di, cid_dr, cos, M_PI, SAS_FREQ, sasdi, and sasdr.

Referenced by asterisk_daemon().

116 {
117  cid_dr[0] = cos(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
118  cid_di[0] = sin(CALLERID_SPACE * 2.0 * M_PI / 8000.0);
119  cid_dr[1] = cos(CALLERID_MARK * 2.0 * M_PI / 8000.0);
120  cid_di[1] = sin(CALLERID_MARK * 2.0 * M_PI / 8000.0);
121  sasdr = cos(SAS_FREQ * 2.0 * M_PI / 8000.0);
122  sasdi = sin(SAS_FREQ * 2.0 * M_PI / 8000.0);
123  casdr1 = cos(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
124  casdi1 = sin(CAS_FREQ1 * 2.0 * M_PI / 8000.0);
125  casdr2 = cos(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
126  casdi2 = sin(CAS_FREQ2 * 2.0 * M_PI / 8000.0);
127 }
#define CALLERID_MARK
Definition: callerid.c:70
unsigned int cos
Definition: chan_iax2.c:352
#define CAS_FREQ1
Definition: callerid.c:72
float cid_di[4]
Definition: callerid.c:64
#define CAS_FREQ2
Definition: callerid.c:73
float casdr1
Definition: callerid.c:67
float sasdi
Definition: callerid.c:66
#define SAS_FREQ
Definition: callerid.c:71
#define M_PI
Definition: resample.c:83
#define CALLERID_SPACE
Definition: callerid.c:69
float sasdr
Definition: callerid.c:66
float casdr2
Definition: callerid.c:67
float casdi2
Definition: callerid.c:67
float casdi1
Definition: callerid.c:67
float cid_dr[4]
Definition: callerid.c:64

◆ callerid_new()

struct callerid_state* callerid_new ( int  cid_signalling)

Create a callerID state machine.

Parameters
cid_signallingType of signalling in use

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

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

Definition at line 129 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().

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

Variable Documentation

◆ cid_di

float cid_di[4]

Definition at line 64 of file callerid.c.

Referenced by callerid_getcarrier(), and callerid_init().

◆ cid_dr

float cid_dr[4]

Definition at line 64 of file callerid.c.

Referenced by callerid_getcarrier(), and callerid_init().

◆ clidsb

float clidsb

Definition at line 65 of file callerid.c.