00001 /* 00002 * Asterisk -- A telephony toolkit for Linux. 00003 * 00004 * ADSI Support (built upon Caller*ID) 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 _ADSI_H 00018 #define _ADSI_H 00019 #include <asterisk/callerid.h> 00020 00021 /* ADSI Message types */ 00022 #define ADSI_MSG_DISPLAY 132 00023 #define ADSI_MSG_DOWNLOAD 133 00024 00025 /* ADSI Parameters (display) */ 00026 #define ADSI_LOAD_SOFTKEY 128 00027 #define ADSI_INIT_SOFTKEY_LINE 129 00028 #define ADSI_LOAD_VIRTUAL_DISP 130 00029 #define ADSI_LINE_CONTROL 131 00030 #define ADSI_INFORMATION 132 00031 #define ADSI_DISC_SESSION 133 00032 #define ADSI_SWITCH_TO_DATA 134 00033 #define ADSI_SWITCH_TO_VOICE 135 00034 #define ADSI_CLEAR_SOFTKEY 136 00035 #define ADSI_INPUT_CONTROL 137 00036 #define ADSI_INPUT_FORMAT 138 00037 #define ADSI_SWITCH_TO_PERIPH 139 00038 #define ADSI_MOVE_DATA 140 00039 #define ADSI_LOAD_DEFAULT 141 00040 #define ADSI_CONNECT_SESSION 142 00041 #define ADSI_CLEAR_TYPE_AHEAD 143 00042 #define ADSI_DISPLAY_CALL_BUF 144 00043 #define ADSI_CLEAR_CALL_BUF 145 00044 #define ADSI_SWITCH_TO_ALT 146 00045 #define ADSI_SWITCH_TO_GRAPHICS 147 00046 #define ADSI_CLEAR_SCREEN 148 00047 #define ADSI_QUERY_CONFIG 149 00048 #define ADSI_QUERY_CPEID 150 00049 #define ADSI_SWITCH_TO_APP 151 00050 00051 /* Feature download messages */ 00052 #define ADSI_LOAD_SOFTKEY_TABLE 128 /* Conveniently identical to the soft version */ 00053 #define ADSI_LOAD_PREDEF_DISP 129 /* Load predefined display */ 00054 #define ADSI_LOAD_SCRIPT 130 00055 #define ADSI_DOWNLOAD_CONNECT 131 00056 #define ADSI_DOWNLOAD_DISC 132 00057 00058 /* Special return string codes */ 00059 #define ADSI_ENCODED_DTMF 0x80 /* Transmit following chars with encoded dtmf */ 00060 #define ADSI_ON_HOOK 0x81 /* Open switch-hook */ 00061 #define ADSI_OFF_HOOK 0x82 /* Close switch-hook */ 00062 #define ADSI_FLASH 0x83 /* Flash switch-hook */ 00063 #define ADSI_DIAL_TONE_DETECT 0x84 /* Wait for dialtone */ 00064 #define ADSI_LINE_NUMBER 0x85 /* Send current line number using DTMF/encoded DTMF */ 00065 #define ADSI_BLANK 0x86 /* Blank (does nothing) */ 00066 #define ADSI_SEND_CHARS 0x87 /* Send collected digits/characters */ 00067 #define ADSI_CLEAR_CHARS 0x88 /* Clear characters/digits collected */ 00068 #define ADSI_BACKSPACE 0x89 /* Erase last collected digit */ 00069 #define ADSI_TAB_COLUMN 0x8A /* Display specified display column of current line */ 00070 #define ADSI_GOTO_LINE 0x8B /* Go to given page and line number */ 00071 #define ADSI_GOTO_LINE_REL 0x8C /* Go to given line (relative to current) */ 00072 #define ADSI_PAGE_UP 0x8D /* Go up one page */ 00073 #define ADSI_PAGE_DOWN 0x8E /* Go down one page */ 00074 #define ADSI_EXTENDED_DTMF 0x8F /* Send DTMF tones for 250ms instead of 60 ms */ 00075 #define ADSI_DELAY 0x90 /* Delay for given # (times 10) of ms */ 00076 #define ADSI_DIAL_PULSE_ONE 0x91 /* Send a dial pulse "1" */ 00077 #define ADSI_SWITCH_TO_DATA2 0x92 /* Switch CPE to data mode */ 00078 #define ADSI_SWITCH_TO_VOICE2 0x93 /* Switch CPE to voice mode */ 00079 #define ADSI_DISP_CALL_BUF 0x94 /* Display specified call buffer */ 00080 #define ADSI_CLEAR_CALL_B 0x95 /* Clear specified call buffer */ 00081 00082 #ifdef __ADSI_CPE 00083 /* These messages are reserved for the ADSI CPE only */ 00084 #define ADSI_DISPLAY_CONTROL 0x98 /* Store predefined display identified next / Display status display page */ 00085 #define ADSI_DISPLAY_SOFT_KEYS 0x99 /* Display the script soft keys identified next */ 00086 #define ADSI_CHANGE_STATE 0x9A /* Change state of service script */ 00087 #define ADSI_START_CLEAR_TIMER 0x9B /* Start / Clear timer */ 00088 #define ADSI_SET_SCRIPT_FLAG 0x9C /* Set / clear a script flag */ 00089 #define ADSI_JUMP_TO_SUBSCRIPT 0x9D /* Jump to specified subscript */ 00090 #define ADSI_EVENT_22_TRIGGER 0x9E /* Trigger an occurance of event 22 */ 00091 #define ADSI_EVENT_23_TRIGGER 0x9f /* Trigger an occurance of event 23 */ 00092 #define ADSI_EXIT 0xA0 /* Exit the service script interpreter */ 00093 #endif 00094 00095 /* Display pages */ 00096 #define ADSI_INFO_PAGE 0x0 00097 #define ADSI_COMM_PAGE 0x1 00098 00099 #define ADSI_KEY_APPS 20 /* 16 to 33 reserved for applications */ 00100 /* Changed to 20 by MDH */ 00101 /* Justification */ 00102 #define ADSI_JUST_LEFT 0x2 00103 #define ADSI_JUST_RIGHT 0x1 00104 #define ADSI_JUST_CENT 0x0 /* Center */ 00105 #define ADSI_JUST_IND 0x3 /* Indent */ 00106 00107 #define ADSI_KEY_SKT 0x80 /* Load from SKT */ 00108 #define ADSI_KEY_HILITE 0x40 /* Highlight key */ 00109 00110 #define ADSI_DIR_FROM_LEFT (0) 00111 #define ADSI_DIR_FROM_RIGHT (1) 00112 00113 //! Perform Asterisk ADSI initialization (for channel drivers that want 00114 // to support ADSI when the handset is first lifted) */ 00115 /*! 00116 * \param chan Channel to initialize for ADSI (if supported) 00117 * 00118 * Returns 0 on success (or adsi unavailable) and -1 on hangup 00119 * 00120 */ 00121 extern int adsi_channel_init(struct ast_channel *chan); 00122 00123 extern int adsi_begin_download(struct ast_channel *chan, char *service, char *fdn, char *sec, int version); 00124 00125 extern int adsi_end_download(struct ast_channel *chan); 00126 00127 //! Restore ADSI initialization (for applications that play with ADSI 00128 // and want to restore it to normal. If you touch "INFO" then you 00129 // have to use the adsi_channel_init again instead. 00130 /*! 00131 * \param chan Channel to restore 00132 * 00133 * Returns 0 on success (or adsi unavailable) and -1 on hangup 00134 * 00135 */ 00136 extern int adsi_channel_restore(struct ast_channel *chan); 00137 00138 //! Display some stuff on the screen 00139 /*! 00140 * \param chan Channel to display on 00141 * \param lines NULL-terminated list of things to print (no more than 4 recommended) 00142 * \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..) 00143 * \param voice whether to jump into voice mode when finished 00144 * 00145 * Return 0 on success (or adsi unavailable) and -1 on hangup 00146 * 00147 */ 00148 extern int adsi_print(struct ast_channel *chan, char **lines, int *align, int voice); 00149 00150 //! Check if scripts for a given app are already loaded. Version may be -1 00151 // if any version is okay, or 0-255 for a specific version. 00152 /*! 00153 * \param chan Channel to test for loaded app 00154 * \param app Four character app name (must be unique to your application) 00155 * \param ver optional version number 00156 * \param data Non-zero if you want to be put in data mode 00157 * 00158 * Returns 0 if scripts is not loaded or not an ADSI CPE. Returns -1 00159 * on hangup. Returns 1 if script already loaded. 00160 */ 00161 extern int adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data); 00162 extern int adsi_unload_session(struct ast_channel *chan); 00163 00164 /* ADSI Layer 2 transmission functions */ 00165 extern int adsi_transmit_messages(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype); 00166 extern int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype); 00167 00168 //! Read some encoded DTMF data. 00169 /*! 00170 * Returns number of bytes received 00171 */ 00172 extern int adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen); 00173 00174 /* ADSI Layer 3 creation functions */ 00175 00176 //! Connects an ADSI Display Session */ 00177 /*! 00178 * \param buf Character buffer to create parameter in (must have at least 256 free) 00179 * \param fdn Optional 4 byte Feature Download Number (for loading soft keys) 00180 * \param ver Optional version number (0-255, or -1 to omit) 00181 * 00182 * Returns number of bytes added to buffer or -1 on error. 00183 * 00184 */ 00185 00186 extern int adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver); 00187 00188 //! Build Query CPE ID of equipment */ 00189 /*! 00190 * Returns number of bytes added to message 00191 */ 00192 extern int adsi_query_cpeid(unsigned char *buf); 00193 extern int adsi_query_cpeinfo(unsigned char *buf); 00194 00195 //! Get CPE ID from an attached ADSI compatible CPE. 00196 /*! 00197 * Returns 1 on success, storing 4 bytes of CPE ID at buf 00198 * or -1 on hangup, or 0 if there was no hangup but it failed to find the 00199 * device ID. Returns to voice mode if "voice" is non-zero. 00200 */ 00201 extern int adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice); 00202 00203 extern int adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice); 00204 00205 //! Begin an ADSI script download */ 00206 /*! 00207 * \param buf Character buffer to create parameter in (must have at least 256 free) 00208 * \param service, a 1-18 byte name of the feature 00209 * \param fdn 4 byte Feature Download Number (for loading soft keys) 00210 * \param sec 4 byte vendor security code 00211 * \param ver version number (0-255, or -1 to omit) 00212 * 00213 * Returns number of bytes added to buffer or -1 on error. 00214 * 00215 */ 00216 00217 extern int adsi_download_connect(unsigned char *buf, unsigned char *service, unsigned char *fdn, unsigned char *sec, int ver); 00218 00219 //! Disconnects a running session 00220 /*! 00221 * \param buf Character buffer to create parameter in (must have at least 256 free) 00222 * 00223 * Returns number of bytes added to buffer or -1 on error. 00224 * 00225 */ 00226 extern int adsi_disconnect_session(unsigned char *buf); 00227 00228 //! Disconnects (and hopefully saves) a downloaded script 00229 /*! 00230 * \param buf Character buffer to create parameter in (must have at least 256 free) 00231 * 00232 * Returns number of bytes added to buffer or -1 on error. 00233 * 00234 */ 00235 extern int adsi_download_disconnect(unsigned char *buf); 00236 00237 //! Puts CPE in data mode... 00238 /*! 00239 * \param buf Character buffer to create parameter in (must have at least 256 free) 00240 * 00241 * Returns number of bytes added to buffer or -1 on error. 00242 * 00243 */ 00244 extern int adsi_data_mode(unsigned char *buf); 00245 extern int adsi_clear_soft_keys(unsigned char *buf); 00246 extern int adsi_clear_screen(unsigned char *buf); 00247 00248 //! Puts CPE in voice mode... 00249 /*! 00250 * \param buf Character buffer to create parameter in (must have at least 256 free) 00251 * \param when (a time in seconds) to make the switch 00252 * 00253 * Returns number of bytes added to buffer or -1 on error. 00254 * 00255 */ 00256 extern int adsi_voice_mode(unsigned char *buf, int when); 00257 00258 //! Returns non-zero if Channel does or might support ADSI 00259 /*! 00260 * \param chan Channel to check 00261 * 00262 */ 00263 extern int adsi_available(struct ast_channel *chan); 00264 00265 //! Loads a line of info into the display */ 00266 /*! 00267 * \param buf Character buffer to create parameter in (must have at least 256 free) 00268 * \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE) 00269 * \param line Line number to load (1-4 for Comm page, 1-33 for info page) 00270 * \param just Line justification (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CENT, ADSI_JUST_IND) 00271 * \param wrap Wrap (1 = yes, 0 = no) 00272 * \param col1 Text to place in first column 00273 * \param col2 Text to place in second column 00274 * 00275 * Returns number of bytes added to buffer or -1 on error. 00276 * 00277 */ 00278 00279 extern int adsi_display(unsigned char *buf, int page, int line, int just, int wrap, unsigned char *col1, unsigned char *col2); 00280 00281 //! Sets the current line and page */ 00282 /*! 00283 * \param buf Character buffer to create parameter in (must have at least 256 free) 00284 * \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE) 00285 * \param line Line number (1-33 for info page, 1-4 for comm page) 00286 * 00287 * Returns number of bytes added to buffer or -1 on error. 00288 * 00289 */ 00290 00291 extern int adsi_set_line(unsigned char *buf, int page, int line); 00292 00293 //! Creates "load soft key" parameters 00294 /*! 00295 * \param buf Character buffer to create parameter in (must have at least 256 free) 00296 * \param key Key code from 2 to 33, for which key we are loading 00297 * \param llabel Long label for key (1-18 bytes) 00298 * \param slabel Short label for key (1-7 bytes) 00299 * \param ret Optional return sequence (NULL for none) 00300 * \param data whether to put CPE in data mode before sending digits 00301 * 00302 * Returns number of bytes added to buffer or -1 on error. 00303 * 00304 */ 00305 extern int adsi_load_soft_key(unsigned char *buf, int key, unsigned char *llabel, unsigned char *slabel, unsigned char *ret, int data); 00306 00307 //! Set which soft keys should be displayed 00308 /*! 00309 * \param buf Character buffer to create parameter in (must have at least 256 free) 00310 * \param keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE 00311 * But remember, the last two keys aren't real keys, they're for scrolling 00312 * 00313 * Returns number of bytes added to buffer or -1 on error. 00314 * 00315 */ 00316 extern int adsi_set_keys(unsigned char *buf, unsigned char *keys); 00317 00318 //! Set input information 00319 /*! 00320 * \param buf Character buffer to create parameter in (must have at least 256 free) 00321 * \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE) 00322 * \param line Line number to input on 00323 * \param display Set to zero to obscure input, or 1 to leave visible 00324 * \param format Format number to use (0-7) 00325 * \param just Justification (left, right center, indent) 00326 * 00327 * Returns number of bytes added to buffer or -1 on error. 00328 * 00329 */ 00330 extern int adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just); 00331 00332 //! Set input format 00333 /*! 00334 * \param buf Character buffer to create parameter in (must have at least 256 free) 00335 * \param num Which format we are setting 00336 * \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT) 00337 * \param wrap Set to 1 to permit line wrap, or 0 if not 00338 * \param format1 Format for column 1 00339 * \param format2 Format for column 2 00340 * 00341 * Returns number of bytes added to buffer or -1 on error. 00342 * 00343 */ 00344 extern int adsi_input_format(unsigned char *buf, int num, int dir, int wrap, unsigned char *format1, unsigned char *format2); 00345 #endif