Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

callerid.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- A telephony toolkit for Linux.
00003  *
00004  * CallerID (and other GR30) Generation support 
00005  * 
00006  * Copyright (C) 1999, Mark Spencer
00007  *
00008  * Mark Spencer <markster@linux-support.net>
00009  *
00010  * This program is free software, distributed under the terms of
00011  * the GNU General Public License.
00012  *
00013  * Includes code and algorithms from the Zapata library.
00014  *
00015  */
00016 
00017 #ifndef _CALLERID_H
00018 #define _CALLERID_H
00019 
00020 #define MAX_CALLERID_SIZE 32000
00021 
00022 #define CID_PRIVATE_NAME      (1 << 0)
00023 #define CID_PRIVATE_NUMBER    (1 << 1)
00024 #define CID_UNKNOWN_NAME      (1 << 2)
00025 #define CID_UNKNOWN_NUMBER    (1 << 3)
00026 
00027 #define CID_SIG_BELL 1
00028 #define CID_SIG_V23  2
00029 #define CID_SIG_DTMF 3
00030 
00031 #define CID_START_RING  1
00032 #define CID_START_POLARITY 2
00033 
00034 
00035 #define AST_LIN2X(a) ((codec == AST_FORMAT_ALAW) ? (AST_LIN2A(a)) : (AST_LIN2MU(a)))
00036 #define AST_XLAW(a) ((codec == AST_FORMAT_ALAW) ? (AST_ALAW(a)) : (AST_MULAW(a)))
00037 
00038 
00039 struct callerid_state;
00040 typedef struct callerid_state CIDSTATE;
00041 
00042 //! CallerID Initialization
00043 /*!
00044  * Initializes the callerid system.  Mostly stuff for inverse FFT
00045  */
00046 extern void callerid_init(void);
00047 
00048 //! Generates a CallerID FSK stream in ulaw format suitable for transmission.
00049 /*!
00050  * \param buf Buffer to use. If "buf" is supplied, it will use that buffer instead of allocating its own.  "buf" must be at least 32000 bytes in size of you want to be sure you don't have an overrun.
00051  * \param number Use NULL for no number or "P" for "private"
00052  * \param name name to be used
00053  * \param callwaiting callwaiting flag
00054  * \param codec -- either AST_FORMAT_ULAW or AST_FORMAT_ALAW
00055  * This function creates a stream of callerid (a callerid spill) data in ulaw format. It returns the size
00056  * (in bytes) of the data (if it returns a size of 0, there is probably an error)
00057 */
00058 extern int callerid_generate(unsigned char *buf, char *number, char *name, int flags, int callwaiting, int codec);
00059 
00060 //! Create a callerID state machine
00061 /*!
00062  * \param cid_signalling Type of signalling in use
00063  *
00064  * This function returns a malloc'd instance of the callerid_state data structure.
00065  * Returns a pointer to a malloc'd callerid_state structure, or NULL on error.
00066  */
00067 extern struct callerid_state *callerid_new(int cid_signalling);
00068 
00069 //! Read samples into the state machine.
00070 /*!
00071  * \param cid Which state machine to act upon
00072  * \param buffer containing your samples
00073  * \param samples number of samples contained within the buffer.
00074  * \param codec which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)
00075  *
00076  * Send received audio to the Caller*ID demodulator.
00077  * Returns -1 on error, 0 for "needs more samples", 
00078  * and 1 if the CallerID spill reception is complete.
00079  */
00080 extern int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int samples, int codec);
00081 
00082 //! Extract info out of callerID state machine.  Flags are listed above
00083 /*!
00084  * \param cid Callerid state machine to act upon
00085  * \param number Pass the address of a pointer-to-char (will contain the phone number)
00086  * \param name Pass the address of a pointer-to-char (will contain the name)
00087  * \param flags Pass the address of an int variable(will contain the various callerid flags)
00088  *
00089  * This function extracts a callerid string out of a callerid_state state machine.
00090  * If no number is found, *number will be set to NULL.  Likewise for the name.
00091  * Flags can contain any of the following:
00092  * 
00093  * Returns nothing.
00094  */
00095 void callerid_get(struct callerid_state *cid, char **number, char **name, int *flags);
00096 
00097 //! Get and parse DTMF-based callerid 
00098 /*!
00099  * \param cidstring The actual transmitted string.
00100  * \param number The cid number is returned here.
00101  * \param flags The cid flags are returned here.
00102  * This function parses DTMF callerid.
00103  */
00104 void callerid_get_dtmf(char *cidstring, char *number, int *flags);
00105 
00106 //! Free a callerID state
00107 /*!
00108  * \param cid This is the callerid_state state machine to free
00109  * This function frees callerid_state cid.
00110  */
00111 extern void callerid_free(struct callerid_state *cid);
00112 
00113 //! Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format)
00114 /*!
00115  * \param buf buffer for output samples. See callerid_generate() for details regarding buffer.
00116  * \param astcid Asterisk format callerid string, taken from the callerid field of asterisk.
00117  * \param codec Asterisk codec (either AST_FORMAT_ALAW or AST_FORMAT_ULAW)
00118  *
00119  * Acts like callerid_generate except uses an asterisk format callerid string.
00120  */
00121 extern int ast_callerid_generate(unsigned char *buf, char *astcid, int codec);
00122 
00123 //! Generate message waiting indicator 
00124 extern int vmwi_generate(unsigned char *buf, int active, int mdmf, int codec);
00125 
00126 //! Generate Caller-ID spill from the "callerid" field of asterisk (in e-mail address like format) but in a format suitable for Call Waiting(tm)'s Caller*ID(tm)
00127 /*!
00128  * See ast_callerid_generate for other details
00129  */
00130 extern int ast_callerid_callwaiting_generate(unsigned char *buf, char *astcid, int codec);
00131 
00132 //! Destructively parse inbuf into name and location (or number)
00133 /*!
00134  * \param inbuf buffer of callerid stream (in audio form) to be parsed. Warning, data in buffer is changed.
00135  * \param name address of a pointer-to-char for the name value of the stream.
00136  * \param location address of a pointer-to-char for the phone number value of the stream.
00137  * Parses callerid stream from inbuf and changes into useable form, outputed in name and location.
00138  * Returns 0 on success, -1 on failure.
00139  */
00140 extern int ast_callerid_parse(char *instr, char **name, char **location);
00141 
00142 //! Generate a CAS (CPE Alert Signal) tone for 'n' samples
00143 /*!
00144  * \param outbuf Allocated buffer for data.  Must be at least 2400 bytes unless no SAS is desired
00145  * \param sas Non-zero if CAS should be preceeded by SAS
00146  * \param len How many samples to generate.
00147  * \param codec Which codec (AST_FORMAT_ALAW or AST_FORMAT_ULAW)
00148  * Returns -1 on error (if len is less than 2400), 0 on success.
00149  */
00150 extern int ast_gen_cas(unsigned char *outbuf, int sas, int len, int codec);
00151 
00152 //! Shrink a phone number in place to just digits (more accurately it just removes ()'s, .'s, and -'s...
00153 /*!
00154  * \param n The number to be stripped/shrunk
00155  * Returns nothing important
00156  */
00157 extern void ast_shrink_phone_number(char *n);
00158 
00159 //! Check if a string consists only of digits.  Returns non-zero if so
00160 /*!
00161  * \param n number to be checked.
00162  * Returns 0 if n is a number, 1 if it's not.
00163  */
00164 extern int ast_isphonenumber(char *n);
00165 
00166 
00167 /*
00168  * Caller*ID and other GR-30 compatible generation
00169  * routines (used by ADSI for example)
00170  */
00171 
00172 extern float cid_dr[4];
00173 extern float cid_di[4];
00174 extern float clidsb;
00175 
00176 static inline float callerid_getcarrier(float *cr, float *ci, int bit)
00177 {
00178    /* Move along.  There's nothing to see here... */
00179    float t;
00180    t = *cr * cid_dr[bit] - *ci * cid_di[bit];
00181    *ci = *cr * cid_di[bit] + *ci * cid_dr[bit];
00182    *cr = t;
00183    
00184    t = 2.0 - (*cr * *cr + *ci * *ci);
00185    *cr *= t;
00186    *ci *= t;
00187    return *cr;
00188 }  
00189 
00190 #define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED  0x00
00191 #define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN 0x01
00192 #define AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN 0x02
00193 #define AST_PRES_ALLOWED_NETWORK_NUMBER            0x03
00194 #define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED   0x20
00195 #define AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN  0x21
00196 #define AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN  0x22
00197 #define AST_PRES_PROHIB_NETWORK_NUMBER          0x23
00198 #define AST_PRES_NUMBER_NOT_AVAILABLE           0x43
00199 
00200 #define PUT_BYTE(a) do { \
00201    *(buf++) = (a); \
00202    bytes++; \
00203 } while(0)
00204 
00205 #define PUT_AUDIO_SAMPLE(y) do { \
00206    int index = (short)(rint(8192.0 * (y))); \
00207    *(buf++) = AST_LIN2X(index); \
00208    bytes++; \
00209 } while(0)
00210    
00211 #define PUT_CLID_MARKMS do { \
00212    int x; \
00213    for (x=0;x<8;x++) \
00214       PUT_AUDIO_SAMPLE(callerid_getcarrier(&cr, &ci, 1)); \
00215 } while(0)
00216 
00217 #define PUT_CLID_BAUD(bit) do { \
00218    while(scont < clidsb) { \
00219       PUT_AUDIO_SAMPLE(callerid_getcarrier(&cr, &ci, bit)); \
00220       scont += 1.0; \
00221    } \
00222    scont -= clidsb; \
00223 } while(0)
00224 
00225 
00226 #define PUT_CLID(byte) do { \
00227    int z; \
00228    unsigned char b = (byte); \
00229    PUT_CLID_BAUD(0);    /* Start bit */ \
00230    for (z=0;z<8;z++) { \
00231       PUT_CLID_BAUD(b & 1); \
00232       b >>= 1; \
00233    } \
00234    PUT_CLID_BAUD(1); /* Stop bit */ \
00235 } while(0); 
00236 
00237 
00238 #endif

Generated on Sat Nov 25 19:09:32 2006 for Asterisk by  doxygen 1.4.2