Asterisk - The Open Source Telephony Project GIT-master-a358458
Data Structures | Macros | Functions | Variables
callerid.c File Reference

CallerID Generation support. More...

#include "asterisk.h"
#include <time.h>
#include <math.h>
#include <ctype.h>
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/callerid.h"
#include "asterisk/fskmodem.h"
#include "asterisk/utils.h"
#include "asterisk/format_cache.h"
Include dependency graph for callerid.c:

Go to the source code of this file.

Data Structures

struct  ast_value_translation
 
struct  callerid_state
 

Macros

#define AST_CALLERID_UNKNOWN   "<unknown>"
 
#define CALLERID_MARK   1200.0
 
#define CALLERID_SPACE   2200.0
 
#define CAS_FREQ1   2130.0
 
#define CAS_FREQ2   2750.0
 
#define SAS_FREQ   440.0
 

Functions

static int __ast_callerid_generate (unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, int callwaiting, struct ast_format *codec, const char *tz)
 
int ast_callerid_callwaiting_full_generate (unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, 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_callwaiting_full_tz_generate (unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, struct ast_format *codec, const char *tz)
 Generate Caller-ID spill but in a format suitable for Call Waiting(tm)'s Caller*ID(tm) More...
 
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_full_generate (unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec)
 Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format) More...
 
int ast_callerid_full_tz_generate (unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, struct ast_format *codec, const char *tz)
 Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format) 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 *input_str, char **name, char **location)
 Destructively parse inbuf into name and location (or number) More...
 
int ast_callerid_split (const char *buf, 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 sendsas, 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...
 
static int ast_is_valid_string (const char *exten, const char *valid)
 Checks if phone number consists of valid characters. 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)
 Clean up phone string. More...
 
static unsigned short calc_crc (unsigned short crc, unsigned char data)
 
int callerid_feed (struct callerid_state *cid, unsigned char *ubuf, int len, struct ast_format *codec)
 Read samples into the state machine. More...
 
int callerid_feed_jp (struct callerid_state *cid, unsigned char *ubuf, int len, 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_full_generate (unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec)
 Generates a CallerID FSK stream in ulaw format suitable for transmission. More...
 
int callerid_full_tz_generate (unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec, const char *tz)
 Generates a CallerID FSK stream in ulaw format suitable for transmission. 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...
 
static int callerid_genmsg (char *msg, int size, const char *number, const char *name, int flags, int format, const char *ddn, int redirecting, const char *tz)
 
void callerid_get (struct callerid_state *cid, char **name, char **number, 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...
 
void callerid_init (void)
 Initialize stuff for inverse FFT. More...
 
struct callerid_statecallerid_new (int cid_signalling)
 Create a callerID state machine. More...
 
static void gen_tone (unsigned char *buf, int len, struct ast_format *codec, float ddr1, float ddi1, float *cr1, float *ci1)
 
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)
 

Variables

float casdi1
 
float casdi2
 
float casdr1
 
float casdr2
 
float cid_di [4]
 
float cid_dr [4]
 
float clidsb = 8000.0 / 1200.0
 
static const struct ast_value_translation connected_line_source_types []
 Translation table for connected line update source settings. More...
 
static const struct ast_value_translation party_name_charset_tbl []
 Translation table for ast_party_name char-set settings. More...
 
static const struct ast_value_translation pres_types []
 Translation table for Caller ID Presentation settings. More...
 
static const struct ast_value_translation redirecting_reason_types []
 Translation table for redirecting reason settings. More...
 
float sasdi
 
float sasdr
 

Detailed Description

CallerID Generation support.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file callerid.c.

Macro Definition Documentation

◆ AST_CALLERID_UNKNOWN

#define AST_CALLERID_UNKNOWN   "<unknown>"

Definition at line 75 of file callerid.c.

◆ CALLERID_MARK

#define CALLERID_MARK   1200.0

1200 hz for "1"

Definition at line 70 of file callerid.c.

◆ CALLERID_SPACE

#define CALLERID_SPACE   2200.0

2200 hz for "0"

Definition at line 69 of file callerid.c.

◆ CAS_FREQ1

#define CAS_FREQ1   2130.0

Definition at line 72 of file callerid.c.

◆ CAS_FREQ2

#define CAS_FREQ2   2750.0

Definition at line 73 of file callerid.c.

◆ SAS_FREQ

#define SAS_FREQ   440.0

Definition at line 71 of file callerid.c.

Function Documentation

◆ __ast_callerid_generate()

static int __ast_callerid_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
const char *  ddn,
int  redirecting,
int  pres,
int  qualifier,
int  format,
int  callwaiting,
struct ast_format codec,
const char *  tz 
)
static

Definition at line 1109 of file callerid.c.

1111{
1112 int flags = 0;
1113
1114 ast_debug(1, "Caller ID Type %s: Number: %s, Name: %s, DDN: %s, Redirecting Reason: %s, Pres: %s, Qualifier: %s, Format: %s\n",
1115 callwaiting ? "II" : "I", number, name, ddn, ast_redirecting_reason_describe(redirecting),
1116 ast_named_caller_presentation(pres), qualifier ? "LDC" : "None", format == CID_TYPE_MDMF ? "MDMF" : "SDMF");
1117
1118 if (ast_strlen_zero(name))
1119 name = NULL;
1121 number = NULL;
1122
1123 if (pres & AST_PRES_RESTRICTED) {
1124 flags |= CID_PRIVATE_NUMBER;
1125 flags |= CID_PRIVATE_NAME;
1126 } else if (pres & AST_PRES_UNAVAILABLE) {
1127 flags |= CID_UNKNOWN_NUMBER;
1128 flags |= CID_UNKNOWN_NAME;
1129 }
1130
1131 if (qualifier) {
1132 flags |= CID_QUALIFIER;
1133 }
1134
1135 return callerid_full_tz_generate(buf, number, name, ddn, redirecting, flags, format, callwaiting, codec, tz);
1136}
const char * ast_redirecting_reason_describe(int data)
Convert redirecting reason value to explanatory string.
Definition: callerid.c:1337
const char * ast_named_caller_presentation(int data)
Convert caller ID pres value to text code.
Definition: callerid.c:1283
int callerid_full_tz_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec, const char *tz)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
Definition: callerid.c:952
#define CID_TYPE_MDMF
Definition: callerid.h:75
#define CID_UNKNOWN_NUMBER
Definition: callerid.h:55
#define AST_PRES_UNAVAILABLE
Definition: callerid.h:420
#define CID_UNKNOWN_NAME
Definition: callerid.h:54
#define AST_PRES_RESTRICTED
Definition: callerid.h:419
#define CID_PRIVATE_NAME
Definition: callerid.h:52
#define CID_PRIVATE_NUMBER
Definition: callerid.h:53
#define CID_QUALIFIER
Definition: callerid.h:58
static char * tz
Definition: cdr_pgsql.c:71
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char name[]
Definition: format_mp3.c:68
#define ast_debug(level,...)
Log a DEBUG message.
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Number structure.
Definition: app_followme.c:154

References ast_debug, ast_named_caller_presentation(), AST_PRES_RESTRICTED, AST_PRES_UNAVAILABLE, ast_redirecting_reason_describe(), ast_strlen_zero(), buf, callerid_full_tz_generate(), CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_QUALIFIER, CID_TYPE_MDMF, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, name, NULL, and tz.

Referenced by ast_callerid_callwaiting_full_generate(), ast_callerid_callwaiting_full_tz_generate(), ast_callerid_callwaiting_generate(), ast_callerid_full_generate(), ast_callerid_full_tz_generate(), and ast_callerid_generate().

◆ ast_callerid_callwaiting_full_generate()

int ast_callerid_callwaiting_full_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
const char *  ddn,
int  redirecting,
int  pres,
int  qualifier,
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 1154 of file callerid.c.

1156{
1157 /* Type II Caller ID (CWCID) only uses MDMF, so format isn't an argument */
1158 return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, CID_TYPE_MDMF, 1, codec, NULL);
1159}
static int __ast_callerid_generate(unsigned char *buf, const char *name, const char *number, const char *ddn, int redirecting, int pres, int qualifier, int format, int callwaiting, struct ast_format *codec, const char *tz)
Definition: callerid.c:1109

References __ast_callerid_generate(), buf, CID_TYPE_MDMF, name, and NULL.

Referenced by my_send_callerid().

◆ ast_callerid_callwaiting_full_tz_generate()

int ast_callerid_callwaiting_full_tz_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
const char *  ddn,
int  redirecting,
int  pres,
int  qualifier,
struct ast_format codec,
const char *  tz 
)

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

Parameters
tzTZ-format time zone for date/time (NULL for system default)
See also
ast_callerid_generate() for other details

Definition at line 1167 of file callerid.c.

1169{
1170 /* Type II Caller ID (CWCID) only uses MDMF, so format isn't an argument */
1171 return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, CID_TYPE_MDMF, 1, codec, tz);
1172}

References __ast_callerid_generate(), buf, CID_TYPE_MDMF, name, and tz.

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

1144{
1145 return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 1, codec, NULL);
1146}

References __ast_callerid_generate(), buf, CID_TYPE_MDMF, name, and NULL.

Referenced by send_cwcidspill().

◆ ast_callerid_full_generate()

int ast_callerid_full_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
const char *  ddn,
int  redirecting,
int  pres,
int  qualifier,
int  format,
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
ddnDialable Directory Number (or NULL)
redirectingRedirecting Reason (-1 if N/A)
presPresentation (0 for default)
qualifierCall Qualifier (0 for no, 1 for yes)
formatMessage Format
codecAsterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)

Like ast_callerid_generate but with additional parameters.

Definition at line 1148 of file callerid.c.

1150{
1151 return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, format, 0, codec, NULL);
1152}

References __ast_callerid_generate(), buf, name, and NULL.

Referenced by my_send_callerid().

◆ ast_callerid_full_tz_generate()

int ast_callerid_full_tz_generate ( unsigned char *  buf,
const char *  name,
const char *  number,
const char *  ddn,
int  redirecting,
int  pres,
int  qualifier,
int  format,
struct ast_format codec,
const char *  tz 
)

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
ddnDialable Directory Number (or NULL)
redirectingRedirecting Reason (-1 if N/A)
presPresentation (0 for default)
qualifierCall Qualifier (0 for no, 1 for yes)
formatMessage Format
codecAsterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)
tzTZ-format time zone name to use for date/time (NULL for system default)

Like ast_callerid_generate but with additional parameters.

Definition at line 1161 of file callerid.c.

1163{
1164 return __ast_callerid_generate(buf, name, number, ddn, redirecting, pres, qualifier, format, 0, codec, tz);
1165}

References __ast_callerid_generate(), buf, name, and tz.

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

1139{
1140 return __ast_callerid_generate(buf, name, number, "", -1, 0, 0, CID_TYPE_MDMF, 0, codec, NULL);
1141}

References __ast_callerid_generate(), buf, CID_TYPE_MDMF, name, and NULL.

◆ ast_callerid_merge()

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

Definition at line 1174 of file callerid.c.

1175{
1176 if (!unknown)
1177 unknown = "<unknown>";
1178 if (name && num) {
1179 char name_buf[128];
1180
1181 ast_escape_quoted(name, name_buf, sizeof(name_buf));
1182 snprintf(buf, bufsiz, "\"%s\" <%s>", name_buf, num);
1183 } else if (name) {
1184 ast_copy_string(buf, name, bufsiz);
1185 } else if (num) {
1186 ast_copy_string(buf, num, bufsiz);
1187 } else {
1188 ast_copy_string(buf, unknown, bufsiz);
1189 }
1190 return buf;
1191}
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
static struct ast_codec unknown
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
Definition: utils.c:781

References ast_copy_string(), ast_escape_quoted(), buf, name, and unknown.

Referenced by 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(), and sip_subscription_to_ami().

◆ 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, outputted 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.
Return values
0on success
-1on failure

Definition at line 1063 of file callerid.c.

1064{
1065 char *ls;
1066 char *le;
1067 char *name_start;
1068 char *instr;
1069 int quotes_stripped = 0;
1070
1071 /* Handle surrounding quotes */
1072 input_str = ast_strip(input_str);
1073 instr = ast_strip_quoted(input_str, "\"", "\"");
1074 if (instr != input_str) {
1075 quotes_stripped = 1;
1076 }
1077
1078 /* Try "name" <location> format or name <location> format or with a missing > */
1079 if ((ls = strrchr(instr, '<'))) {
1080 if ((le = strrchr(ls, '>'))) {
1081 *le = '\0'; /* location found, trim off the brackets */
1082 }
1083 *ls = '\0';
1084 *location = ls + 1; /* and this is the result */
1085
1086 name_start = ast_strip_quoted(instr, "\"", "\"");
1087 } else { /* no valid brackets */
1088 char tmp[256];
1089
1090 ast_copy_string(tmp, instr, sizeof(tmp));
1092 if (!quotes_stripped && ast_isphonenumber(tmp)) { /* Assume it's just a location */
1093 name_start = NULL;
1094 strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
1095 *location = instr;
1096 } else { /* Assume it's just a name. */
1097 *location = NULL;
1098 name_start = ast_strip_quoted(instr, "\"", "\"");
1099 }
1100 }
1101
1102 if (name_start) {
1103 ast_unescape_quoted(name_start);
1104 }
1105 *name = name_start;
1106 return 0;
1107}
static int tmp()
Definition: bt_open.c:389
void ast_shrink_phone_number(char *n)
Clean up phone string.
Definition: callerid.c:1002
int ast_isphonenumber(const char *n)
Check if a string consists only of digits and + #.
Definition: callerid.c:1053
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
Definition: utils.c:1818
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
Definition: utils.c:842

References ast_copy_string(), ast_isphonenumber(), ast_shrink_phone_number(), ast_strip(), ast_strip_quoted(), ast_unescape_quoted(), name, 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(), play_message_callerid(), and unistim_new().

◆ ast_callerid_split()

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

Definition at line 1193 of file callerid.c.

1194{
1195 char *tmp;
1196 char *l = NULL, *n = NULL;
1197
1198 tmp = ast_strdupa(buf);
1199 ast_callerid_parse(tmp, &n, &l);
1200 if (n)
1201 ast_copy_string(name, n, namelen);
1202 else
1203 name[0] = '\0';
1204 if (l) {
1206 ast_copy_string(num, l, numlen);
1207 } else
1208 num[0] = '\0';
1209 return 0;
1210}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_callerid_parse(char *input_str, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1063

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

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

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

854{
855 char msg[256];
856 int len = 0;
857 int sum;
858 int x;
859 int bytes = 0;
860 float cr = 1.0;
861 float ci = 0.0;
862 float scont = 0.0;
863
865 /* MDMF Message waiting with date, number, name and MWI parameter */
866 msg[0] = 0x82;
867
868 /* put date, number info at the right place */
869 len = callerid_genmsg(msg+2, sizeof(msg)-2, number, name, flags, CID_TYPE_MDMF, "", -1, NULL);
870
871 /* length of MDMF CLI plus Message Waiting Structure */
872 msg[1] = len+3;
873
874 /* Go to the position to write to */
875 len = len+2;
876
877 /* "Message Waiting Parameter" */
878 msg[len++] = 0x0b;
879 /* Length of IE is one */
880 msg[len++] = 1;
881 /* Active or not */
882 if (active)
883 msg[len++] = 0xff;
884 else
885 msg[len++] = 0x00;
886
887 } else if (type == CID_MWI_TYPE_MDMF) {
888 /* MDMF Message waiting only */
889 /* same as above except that the we only put MWI parameter */
890 msg[len++] = 0x82;
891 /* Length is 3 */
892 msg[len++] = 3;
893 /* IE is "Message Waiting Parameter" */
894 msg[len++] = 0x0b;
895 /* Length of IE is one */
896 msg[len++] = 1;
897 /* Active or not */
898 if (active)
899 msg[len++] = 0xff;
900 else
901 msg[len++] = 0x00;
902 } else {
903 /* SDMF Message waiting */
904 msg[len++] = 0x6;
905 /* Length is 3 */
906 msg[len++] = 3;
907 if (active) {
908 msg[len++] = 0x42;
909 msg[len++] = 0x42;
910 msg[len++] = 0x42;
911 } else {
912 msg[len++] = 0x6f;
913 msg[len++] = 0x6f;
914 msg[len++] = 0x6f;
915 }
916 }
917 sum = 0;
918 for (x = 0; x < len; x++)
919 sum += msg[x];
920 sum = (256 - (sum & 255));
921 msg[len++] = sum;
922 /* Wait a half a second */
923 for (x = 0; x < 4000; x++)
924 PUT_BYTE(0x7f);
925 /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
926 for (x = 0; x < 30; x++)
927 PUT_CLID(0x55);
928 /* Send 170ms of callerid marks */
929 for (x = 0; x < 170; x++)
931 for (x = 0; x < len; x++) {
932 PUT_CLID(msg[x]);
933 }
934 /* Send 50 more ms of marks */
935 for (x = 0; x < 50; x++)
937 return bytes;
938}
static int callerid_genmsg(char *msg, int size, const char *number, const char *name, int flags, int format, const char *ddn, int redirecting, const char *tz)
Definition: callerid.c:739
#define PUT_CLID(byte)
Definition: callerid.h:398
#define PUT_BYTE(a)
Definition: callerid.h:372
#define CID_MWI_TYPE_MDMF
Definition: callerid.h:81
#define PUT_CLID_MARKMS
Definition: callerid.h:383
#define CID_MWI_TYPE_MDMF_FULL
Definition: callerid.h:83
static const char type[]
Definition: chan_ooh323.c:109
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

References callerid_genmsg(), CID_MWI_TYPE_MDMF, CID_MWI_TYPE_MDMF_FULL, CID_TYPE_MDMF, len(), name, NULL, PUT_BYTE, PUT_CLID, PUT_CLID_MARKMS, and type.

Referenced by mwi_send_init().

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

1394{
1395 int index;
1396
1397 for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1398 if (connected_line_source_types[index].value == data) {
1400 }
1401 }
1402
1403 return "not-known";
1404}
static const struct ast_value_translation connected_line_source_types[]
Translation table for connected line update source settings.
Definition: callerid.c:1369
const char * description
Definition: callerid.c:1215
int value
Definition: syslog.c:37
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, connected_line_source_types, ast_value_translation::description, and value.

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

1407{
1408 int index;
1409
1410 for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1411 if (connected_line_source_types[index].value == data) {
1412 return connected_line_source_types[index].name;
1413 }
1414 }
1415
1416 return "not-known";
1417}
const char * name
Definition: callerid.c:1214

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

Referenced by connectedline_read().

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

1381{
1382 int index;
1383
1384 for (index = 0; index < ARRAY_LEN(connected_line_source_types); ++index) {
1385 if (!strcasecmp(connected_line_source_types[index].name, data)) {
1386 return connected_line_source_types[index].value;
1387 }
1388 }
1389
1390 return -1;
1391}

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

Referenced by connectedline_write().

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

1266{
1267 int index;
1268
1269 for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1270 if (pres_types[index].value == data) {
1271 return pres_types[index].description;
1272 }
1273 }
1274
1275 return "unknown";
1276}
static const struct ast_value_translation pres_types[]
Translation table for Caller ID Presentation settings.
Definition: callerid.c:1219

References ARRAY_LEN, ast_value_translation::description, pres_types, and value.

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

◆ 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)
Return values
-1on error (if len is less than 2400)
0on success

Definition at line 261 of file callerid.c.

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}
float casdi1
Definition: callerid.c:67
float sasdr
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 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 casdi2
Definition: callerid.c:67
float casdr2
Definition: callerid.c:67
float casdr1
Definition: callerid.c:67
float sasdi
Definition: callerid.c:66

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

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

◆ 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 exten is valid AST shrinkable phone number
0if not

Definition at line 1058 of file callerid.c.

1059{
1060 return ast_is_valid_string(exten, "0123456789*#+()-.");
1061}
static int ast_is_valid_string(const char *exten, const char *valid)
Checks if phone number consists of valid characters.
Definition: callerid.c:1041

References ast_is_valid_string().

Referenced by ari_channels_handle_originate_with_id().

◆ ast_is_valid_string()

static int ast_is_valid_string ( const char *  exten,
const char *  valid 
)
static

Checks if phone number consists of valid characters.

Parameters
extenString that needs to be checked
validValid characters in string
Return values
1if valid string
0if string contains invalid characters

Definition at line 1041 of file callerid.c.

1042{
1043 int x;
1044
1045 if (ast_strlen_zero(exten))
1046 return 0;
1047 for (x = 0; exten[x]; x++)
1048 if (!strchr(valid, exten[x]))
1049 return 0;
1050 return 1;
1051}

References ast_strlen_zero().

Referenced by ast_is_shrinkable_phonenumber(), and ast_isphonenumber().

◆ ast_isphonenumber()

int ast_isphonenumber ( const char *  n)

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

Parameters
nnumber to be checked.
Return values
0if n is a number
1if not

Definition at line 1053 of file callerid.c.

1054{
1055 return ast_is_valid_string(n, "0123456789*#+");
1056}

References ast_is_valid_string().

Referenced by ast_callerid_parse(), and hfp_parse_clip().

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

1284{
1285 int index;
1286
1287 for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1288 if (pres_types[index].value == data) {
1289 return pres_types[index].name;
1290 }
1291 }
1292
1293 return "unknown";
1294}

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

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

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

1245{
1246 int index;
1247 if (!data) {
1248 return -1;
1249 }
1250
1251 for (index = 0; index < ARRAY_LEN(pres_types); ++index) {
1252 if (!strcasecmp(pres_types[index].name, data)) {
1253 return pres_types[index].value;
1254 }
1255 }
1256
1257 return -1;
1258}

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

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

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

1449{
1450 int index;
1451
1452 for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1453 if (party_name_charset_tbl[index].value == data) {
1454 return party_name_charset_tbl[index].description;
1455 }
1456 }
1457
1458 return "not-known";
1459}
static const struct ast_value_translation party_name_charset_tbl[]
Translation table for ast_party_name char-set settings.
Definition: callerid.c:1420

References ARRAY_LEN, ast_value_translation::description, party_name_charset_tbl, and value.

Referenced by json_party_name().

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

1436{
1437 int index;
1438
1439 for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1440 if (!strcasecmp(party_name_charset_tbl[index].name, data)) {
1441 return party_name_charset_tbl[index].value;
1442 }
1443 }
1444
1445 return -1;
1446}

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

Referenced by party_name_write().

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

1462{
1463 int index;
1464
1465 for (index = 0; index < ARRAY_LEN(party_name_charset_tbl); ++index) {
1466 if (party_name_charset_tbl[index].value == data) {
1467 return party_name_charset_tbl[index].name;
1468 }
1469 }
1470
1471 return "not-known";
1472}

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

Referenced by party_name_read().

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

1338{
1339 int index;
1340
1341 for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1342 if (redirecting_reason_types[index].value == data) {
1343 return redirecting_reason_types[index].description ?: "Redirecting reason alias-bug";
1344 }
1345 }
1346
1347 return "not-known";
1348}
static const struct ast_value_translation redirecting_reason_types[]
Translation table for redirecting reason settings.
Definition: callerid.c:1297

References ARRAY_LEN, ast_value_translation::description, redirecting_reason_types, and value.

Referenced by __ast_callerid_generate().

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

1351{
1352 int index;
1353
1354 if (!ast_strlen_zero(data->str)) {
1355 /* Use this string if it has been set. Otherwise, use the table. */
1356 return data->str;
1357 }
1358
1359 for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1360 if (redirecting_reason_types[index].value == data->code) {
1361 return redirecting_reason_types[index].name;
1362 }
1363 }
1364
1365 return "not-known";
1366}
int code
enum AST_REDIRECTING_REASON value for redirection
Definition: channel.h:510
char * str
a string value for the redirecting reason
Definition: channel.h:507

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

Referenced by redirecting_read().

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

1325{
1326 int index;
1327
1328 for (index = 0; index < ARRAY_LEN(redirecting_reason_types); ++index) {
1329 if (!strcasecmp(redirecting_reason_types[index].name, data)) {
1330 return redirecting_reason_types[index].value;
1331 }
1332 }
1333
1334 return -1;
1335}

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

Referenced by redirecting_write(), and set_redirecting_reason().

◆ ast_shrink_phone_number()

void ast_shrink_phone_number ( char *  n)

Clean up phone string.

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

1003{
1004 int x, y = 0;
1005 int bracketed = 0;
1006
1007 for (x = 0; n[x]; x++) {
1008 switch (n[x]) {
1009 case '[':
1010 bracketed++;
1011 n[y++] = n[x];
1012 break;
1013 case ']':
1014 bracketed--;
1015 n[y++] = n[x];
1016 break;
1017 case '-':
1018 if (bracketed)
1019 n[y++] = n[x];
1020 break;
1021 case '.':
1022 if (!n[x+1])
1023 n[y++] = n[x];
1024 break;
1025 default:
1026 /* ignore parenthesis and whitespace */
1027 if (!strchr("( )", n[x]))
1028 n[y++] = n[x];
1029 }
1030 }
1031 n[y] = '\0';
1032}

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(), handle_setcallerid(), pbx_load_config(), setup_privacy_args(), and write_metadata().

◆ calc_crc()

static unsigned short calc_crc ( unsigned short  crc,
unsigned char  data 
)
static

Definition at line 283 of file callerid.c.

284{
285 unsigned int i, j, org, dst;
286 org = data;
287 dst = 0;
288
289 for (i = 0; i < CHAR_BIT; i++) {
290 org <<= 1;
291 dst >>= 1;
292 if (org & 0x100)
293 dst |= 0x80;
294 }
295 data = (unsigned char) dst;
296 crc ^= (unsigned int) data << (16 - CHAR_BIT);
297 for (j = 0; j < CHAR_BIT; j++) {
298 if (crc & 0x8000U)
299 crc = (crc << 1) ^ 0x1021U ;
300 else
301 crc <<= 1 ;
302 }
303 return crc;
304}
static char org[80]
Definition: pbx_dundi.c:202

References callerid_state::crc, and org.

Referenced by callerid_feed_jp().

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

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 tolerate 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, "");
707 } else if (!strcmp(cid->number, "O") || ast_strlen_zero(cid->number)) {
708 strcpy(cid->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 ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_log
Definition: astobj2.c:42
#define CID_NOMSGWAITING
Definition: callerid.h:57
#define CID_MSGWAITING
Definition: callerid.h:56
#define AST_XLAW(a)
Definition: callerid.h:86
int fsk_serial(fsk_data *fskd, short *buffer, int *len, int *outbyte)
Retrieve a serial byte into outbyte. Buffer is a pointer into a series of shorts and len records the ...
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
char rawdata[256]
Definition: callerid.c:47
char number[64]
Definition: callerid.c:54
fsk_data fskd
Definition: callerid.c:46
short oldstuff[160]
Definition: callerid.c:48
char name[64]
Definition: callerid.c:53
static struct test_val b

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

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

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 */
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}
static unsigned short calc_crc(unsigned short crc, unsigned char data)
Definition: callerid.c:283
#define DEBUG_ATLEAST(level)
unsigned short crc
Definition: callerid.c:60

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

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

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

References ast_free.

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

◆ callerid_full_generate()

int callerid_full_generate ( unsigned char *  buf,
const char *  number,
const char *  name,
const char *  ddn,
int  redirecting,
int  flags,
int  format,
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
ddnDialable Directory Number (or NULL)
redirectingRedirecting reason
flagspassed flags
formatMessage format
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 945 of file callerid.c.

947{
948 /* Default time zone is NULL (system time zone) */
949 return callerid_full_tz_generate(buf, number, name, ddn, redirecting, flags, format, callwaiting, codec, NULL);
950}

References buf, callerid_full_tz_generate(), name, and NULL.

Referenced by callerid_generate().

◆ callerid_full_tz_generate()

int callerid_full_tz_generate ( unsigned char *  buf,
const char *  number,
const char *  name,
const char *  ddn,
int  redirecting,
int  flags,
int  format,
int  callwaiting,
struct ast_format codec,
const char *  tz 
)

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
ddnDialable Directory Number (or NULL)
redirectingRedirecting reason
flagspassed flags
formatMessage format
callwaitingcallwaiting flag
codec– either AST_FORMAT_ULAW or AST_FORMAT_ALAW
tzTZ-format time zone to use for date/time (NULL for system default)

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

954{
955 int bytes = 0;
956 int x, sum;
957 int len;
958
959 /* Initial carriers (real/imaginary) */
960 float cr = 1.0;
961 float ci = 0.0;
962 float scont = 0.0;
963 char msg[256];
964 len = callerid_genmsg(msg, sizeof(msg), number, name, flags, format, ddn, redirecting, tz);
965 if (!callwaiting) {
966 /* Wait a half a second */
967 for (x = 0; x < 4000; x++)
968 PUT_BYTE(0x7f);
969 /* Transmit 30 0x55's (looks like a square wave) for channel seizure */
970 for (x = 0; x < 30; x++)
971 PUT_CLID(0x55);
972 }
973 /* Send 150ms of callerid marks */
974 for (x = 0; x < 150; x++)
976 /* Send 0x80 indicating MDMF format */
977 PUT_CLID(0x80);
978 /* Put length of whole message */
979 PUT_CLID(len);
980 sum = 0x80 + strlen(msg);
981 /* Put each character of message and update checksum */
982 for (x = 0; x < len; x++) {
983 PUT_CLID(msg[x]);
984 sum += msg[x];
985 }
986 /* Send 2's compliment of sum */
987 PUT_CLID(256 - (sum & 255));
988
989 /* Send 50 more ms of marks */
990 for (x = 0; x < 50; x++)
992
993 return bytes;
994}

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

Referenced by __ast_callerid_generate(), and callerid_full_generate().

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

941{
942 return callerid_full_generate(buf, number, name, NULL, -1, flags, CID_TYPE_MDMF, callwaiting, codec);
943}
int callerid_full_generate(unsigned char *buf, const char *number, const char *name, const char *ddn, int redirecting, int flags, int format, int callwaiting, struct ast_format *codec)
Generates a CallerID FSK stream in ulaw format suitable for transmission.
Definition: callerid.c:945

References buf, callerid_full_generate(), CID_TYPE_MDMF, name, and NULL.

◆ callerid_genmsg()

static int callerid_genmsg ( char *  msg,
int  size,
const char *  number,
const char *  name,
int  flags,
int  format,
const char *  ddn,
int  redirecting,
const char *  tz 
)
static

Definition at line 739 of file callerid.c.

741{
742 struct timeval now = ast_tvnow();
743 struct ast_tm tm;
744 char *ptr;
745 int res;
746 int i, x;
747
748 /* Get the time */
749 ast_localtime(&now, &tm, tz);
750
751 ptr = msg;
752
753 /* Format time and message header */
754 res = snprintf(ptr, size, "\001\010%02d%02d%02d%02d", tm.tm_mon + 1,
755 tm.tm_mday, tm.tm_hour, tm.tm_min);
756 size -= res;
757 ptr += res;
758
759 if (ast_strlen_zero(number) || (flags & CID_UNKNOWN_NUMBER)) {
760 /* Indicate number not known */
761 res = snprintf(ptr, size, "\004\001O");
762 size -= res;
763 ptr += res;
764 } else if (flags & CID_PRIVATE_NUMBER) {
765 /* Indicate number is private */
766 res = snprintf(ptr, size, "\004\001P");
767 size -= res;
768 ptr += res;
769 } else {
770 /* Send up to 16 digits of number MAX */
771 i = strlen(number);
772 if (i > 16)
773 i = 16;
774 res = snprintf(ptr, size, "\002%c", i);
775 size -= res;
776 ptr += res;
777 for (x = 0; x < i; x++)
778 ptr[x] = number[x];
779 ptr[i] = '\0';
780 ptr += i;
781 size -= i;
782 }
783
784 if (format == CID_TYPE_SDMF) { /* If Simple Data Message Format, we're done. */
785 /* (some older Caller ID units only support SDMF. If they get an MDMF spill, it's useless.) */
786 return (ptr - msg);
787 }
788
789 if (ast_strlen_zero(name) || (flags & CID_UNKNOWN_NAME)) {
790 /* Indicate name not known */
791 res = snprintf(ptr, size, "\010\001O");
792 size -= res;
793 ptr += res;
794 } else if (flags & CID_PRIVATE_NAME) {
795 /* Indicate name is private */
796 res = snprintf(ptr, size, "\010\001P");
797 size -= res;
798 ptr += res;
799 } else {
800 /* Send up to 16 digits of name MAX */
801 i = strlen(name);
802 if (i > 16)
803 i = 16;
804 res = snprintf(ptr, size, "\007%c", i);
805 size -= res;
806 ptr += res;
807 for (x = 0; x < i; x++)
808 ptr[x] = name[x];
809 ptr[i] = '\0';
810 ptr += i;
811 size -= i;
812 }
813
814 /* Call Qualifier */
815 if (flags & CID_QUALIFIER) {
816 res = snprintf(ptr, size, "\006\001L"); /* LDC (Long Distance Call) is the only valid option */
817 size -= res;
818 ptr += res;
819 }
820
821 /* DDN (Dialable Directory Number) - 11 digits MAX, parameter 003 */
822 /* some CPE seem to display the DDN instead of the CLID, if sent */
823
824 /* Redirecting Reason */
825 if (redirecting >= 0) {
826 res = 0;
827 switch (redirecting) {
829 res = snprintf(ptr, size, "\005\001\001");
830 break;
832 res = snprintf(ptr, size, "\005\001\002");
833 break;
835 res = snprintf(ptr, size, "\005\001\003");
836 break;
838 res = snprintf(ptr, size, "\005\001\004");
839 break;
841 res = snprintf(ptr, size, "\005\001\005");
842 break;
843 default:
844 break;
845 }
846 ptr += res;
847 size -= res;
848 }
849
850 return (ptr - msg);
851}
#define CID_TYPE_SDMF
Definition: callerid.h:73
@ AST_REDIRECTING_REASON_NO_ANSWER
Definition: callerid.h:487
@ AST_REDIRECTING_REASON_DEFLECTION
Definition: callerid.h:492
@ AST_REDIRECTING_REASON_UNCONDITIONAL
Definition: callerid.h:489
@ AST_REDIRECTING_REASON_CALL_FWD_DTE
Definition: callerid.h:496
@ AST_REDIRECTING_REASON_USER_BUSY
Definition: callerid.h:486
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159

References ast_localtime(), AST_REDIRECTING_REASON_CALL_FWD_DTE, AST_REDIRECTING_REASON_DEFLECTION, AST_REDIRECTING_REASON_NO_ANSWER, AST_REDIRECTING_REASON_UNCONDITIONAL, AST_REDIRECTING_REASON_USER_BUSY, ast_strlen_zero(), ast_tvnow(), CID_PRIVATE_NAME, CID_PRIVATE_NUMBER, CID_QUALIFIER, CID_TYPE_SDMF, CID_UNKNOWN_NAME, CID_UNKNOWN_NUMBER, name, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and tz.

Referenced by ast_callerid_vmwi_generate(), and callerid_full_tz_generate().

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

Definition at line 188 of file callerid.c.

189{
190 *flags = cid->flags;
192 *name = NULL;
193 else
194 *name = cid->name;
196 *number = NULL;
197 else
198 *number = cid->number;
199}

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

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

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

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");
211 *flags = CID_UNKNOWN_NUMBER;
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)
220 *flags = CID_UNKNOWN_NUMBER;
221 else if (code == 10)
222 *flags = CID_PRIVATE_NUMBER;
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')
228 *flags = CID_PRIVATE_NUMBER;
229 if (cidstring[1] == '2' || cidstring[1] == '3')
230 *flags = CID_UNKNOWN_NUMBER;
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]);
257 *flags = CID_UNKNOWN_NUMBER;
258 }
259}

References ast_debug, ast_log, CID_PRIVATE_NUMBER, CID_UNKNOWN_NUMBER, callerid_state::flags, and LOG_WARNING.

Referenced by __analog_ss_thread(), and analog_ss_thread().

◆ callerid_init()

void callerid_init ( void  )

Initialize stuff for inverse FFT.

CallerID Initialization.

Definition at line 115 of file callerid.c.

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 SAS_FREQ
Definition: callerid.c:71
float cid_dr[4]
Definition: callerid.c:64
#define CAS_FREQ2
Definition: callerid.c:73
#define CAS_FREQ1
Definition: callerid.c:72
#define CALLERID_MARK
Definition: callerid.c:70
#define CALLERID_SPACE
Definition: callerid.c:69
float cid_di[4]
Definition: callerid.c:64
unsigned int cos
Definition: chan_iax2.c:356
#define M_PI
Definition: resample.c:83

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

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

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 ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
int fskmodem_init(fsk_data *fskd)
Definition: fskmodem_int.c:195
int f_mark_idx
float nstop
int pllispb2
Definition: fskmodem_int.h:61
int instop
Definition: fskmodem_int.h:46
int pllispb
Definition: fskmodem_int.h:59
int pllids
Definition: fskmodem_int.h:60
int f_space_idx

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

◆ gen_tone()

static void gen_tone ( unsigned char *  buf,
int  len,
struct ast_format codec,
float  ddr1,
float  ddi1,
float *  cr1,
float *  ci1 
)
inlinestatic

Definition at line 99 of file callerid.c.

100{
101 int x;
102 float t;
103 for (x = 0; x < len; x++) {
104 t = *cr1 * ddr1 - *ci1 * ddi1;
105 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
106 *cr1 = t;
107 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
108 *cr1 *= t;
109 *ci1 *= t;
110 buf[x] = AST_LIN2X(*cr1 * 8192.0);
111 }
112}
#define AST_LIN2X(a)
Definition: callerid.h:85

References AST_LIN2X, buf, and len().

Referenced by ast_gen_cas().

◆ gen_tones()

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

Definition at line 77 of file callerid.c.

78{
79 int x;
80 float t;
81 for (x = 0; x < len; x++) {
82 t = *cr1 * ddr1 - *ci1 * ddi1;
83 *ci1 = *cr1 * ddi1 + *ci1 * ddr1;
84 *cr1 = t;
85 t = 2.0 - (*cr1 * *cr1 + *ci1 * *ci1);
86 *cr1 *= t;
87 *ci1 *= t;
88
89 t = *cr2 * ddr2 - *ci2 * ddi2;
90 *ci2 = *cr2 * ddi2 + *ci2 * ddr2;
91 *cr2 = t;
92 t = 2.0 - (*cr2 * *cr2 + *ci2 * *ci2);
93 *cr2 *= t;
94 *ci2 *= t;
95 buf[x] = AST_LIN2X((*cr1 + *cr2) * 2048.0);
96 }
97}

References AST_LIN2X, buf, and len().

Referenced by ast_gen_cas().

Variable Documentation

◆ casdi1

float casdi1

Definition at line 67 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().

◆ casdi2

float casdi2

Definition at line 67 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().

◆ casdr1

float casdr1

Definition at line 67 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().

◆ casdr2

float casdr2

Definition at line 67 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().

◆ 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 = 8000.0 / 1200.0

Definition at line 65 of file callerid.c.

◆ connected_line_source_types

const struct ast_value_translation connected_line_source_types[]
static

Translation table for connected line update source settings.

Definition at line 1369 of file callerid.c.

Referenced by ast_connected_line_source_describe(), ast_connected_line_source_name(), and ast_connected_line_source_parse().

◆ party_name_charset_tbl

const struct ast_value_translation party_name_charset_tbl[]
static

Translation table for ast_party_name char-set settings.

Definition at line 1420 of file callerid.c.

Referenced by ast_party_name_charset_describe(), ast_party_name_charset_parse(), and ast_party_name_charset_str().

◆ pres_types

const struct ast_value_translation pres_types[]
static

Translation table for Caller ID Presentation settings.

Definition at line 1219 of file callerid.c.

Referenced by ast_describe_caller_presentation(), ast_named_caller_presentation(), and ast_parse_caller_presentation().

◆ redirecting_reason_types

const struct ast_value_translation redirecting_reason_types[]
static

Translation table for redirecting reason settings.

Definition at line 1297 of file callerid.c.

Referenced by ast_redirecting_reason_describe(), ast_redirecting_reason_name(), and ast_redirecting_reason_parse().

◆ sasdi

float sasdi

Definition at line 66 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().

◆ sasdr

float sasdr

Definition at line 66 of file callerid.c.

Referenced by ast_gen_cas(), and callerid_init().