Version 0.1.10 from FTP
[asterisk/asterisk.git] / include / asterisk / adsi.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * ADSI Support (built upon Caller*ID) 
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License.
12  *
13  * Includes code and algorithms from the Zapata library.
14  *
15  */
16
17 #ifndef _ADSI_H
18 #define _ADSI_H
19 #include <asterisk/callerid.h>
20
21 /* ADSI Message types */
22 #define ADSI_MSG_DISPLAY        132
23 #define ADSI_MSG_DOWNLOAD       133
24
25 /* ADSI Parameters (display) */
26 #define ADSI_LOAD_SOFTKEY       128
27 #define ADSI_INIT_SOFTKEY_LINE  129
28 #define ADSI_LOAD_VIRTUAL_DISP  130
29 #define ADSI_LINE_CONTROL       131
30 #define ADSI_INFORMATION        132
31 #define ADSI_DISC_SESSION       133
32 #define ADSI_SWITCH_TO_DATA     134
33 #define ADSI_SWITCH_TO_VOICE    135
34 #define ADSI_CLEAR_SOFTKEY      136
35 #define ADSI_INPUT_CONTROL      137
36 #define ADSI_INPUT_FORMAT       138
37 #define ADSI_SWITCH_TO_PERIPH   139
38 #define ADSI_MOVE_DATA          140
39 #define ADSI_LOAD_DEFAULT       141
40 #define ADSI_CONNECT_SESSION    142
41 #define ADSI_CLEAR_TYPE_AHEAD   143
42 #define ADSI_DISPLAY_CALL_BUF   144
43 #define ADSI_CLEAR_CALL_BUF     145
44 #define ADSI_SWITCH_TO_ALT      146
45 #define ADSI_SWITCH_TO_GRAPHICS 147
46 #define ADSI_CLEAR_SCREEN       148
47 #define ADSI_QUERY_CONFIG       149
48 #define ADSI_QUERY_CPEID        150
49 #define ADSI_SWITCH_TO_APP      151
50
51 /* Feature download messages */
52 #define ADSI_LOAD_SOFTKEY_TABLE 128     /* Conveniently identical to the soft version */
53 #define ADSI_LOAD_PREDEF_DISP   129     /* Load predefined display */
54 #define ADSI_LOAD_SCRIPT        130
55 #define ADSI_DOWNLOAD_CONNECT   131
56 #define ADSI_DOWNLOAD_DISC      132
57
58 /* Special return string codes */
59 #define ADSI_ENCODED_DTMF       0x80    /* Transmit following chars with encoded dtmf */
60 #define ADSI_ON_HOOK            0x81    /* Open switch-hook */
61 #define ADSI_OFF_HOOK           0x82    /* Close switch-hook */
62 #define ADSI_FLASH              0x83    /* Flash switch-hook */
63 #define ADSI_DIAL_TONE_DETECT   0x84    /* Wait for dialtone */
64 #define ADSI_LINE_NUMBER        0x85    /* Send current line number using DTMF/encoded DTMF */
65 #define ADSI_BLANK              0x86    /* Blank (does nothing) */
66 #define ADSI_SEND_CHARS         0x87    /* Send collected digits/characters */
67 #define ADSI_CLEAR_CHARS        0x88    /* Clear characters/digits collected */
68 #define ADSI_BACKSPACE          0x89    /* Erase last collected digit */
69 #define ADSI_TAB_COLUMN         0x8A    /* Display specified display column of current line */
70 #define ADSI_GOTO_LINE          0x8B    /* Go to given page and line number */
71 #define ADSI_GOTO_LINE_REL      0x8C    /* Go to given line (relative to current) */
72 #define ADSI_PAGE_UP            0x8D    /* Go up one page */
73 #define ADSI_PAGE_DOWN          0x8E    /* Go down one page */
74 #define ADSI_EXTENDED_DTMF      0x8F    /* Send DTMF tones for 250ms instead of 60 ms */
75 #define ADSI_DELAY              0x90    /* Delay for given # (times 10) of ms */
76 #define ADSI_DIAL_PULSE_ONE     0x91    /* Send a dial pulse "1" */
77 #define ADSI_SWITCH_TO_DATA2    0x92    /* Switch CPE to data mode */
78 #define ADSI_SWITCH_TO_VOICE2   0x93    /* Switch CPE to voice mode */
79 #define ADSI_DISP_CALL_BUF      0x94    /* Display specified call buffer */
80 #define ADSI_CLEAR_CALL_BUF     0x95    /* Clear specified call buffer */
81
82 #ifdef __ADSI_CPE
83 /* These messages are reserved for the ADSI CPE only */
84 #define ADSI_DISPLAY_CONTROL    0x98    /* Store predefined display identified next / Display status display page */
85 #define ADSI_DISPLAY_SOFT_KEYS  0x99    /* Display the script soft keys identified next */
86 #define ADSI_CHANGE_STATE       0x9A    /* Change state of service script */
87 #define ADSI_START_CLEAR_TIMER  0x9B    /* Start / Clear timer */
88 #define ADSI_SET_SCRIPT_FLAG    0x9C    /* Set / clear a script flag */
89 #define ADSI_JUMP_TO_SUBSCRIPT  0x9D    /* Jump to specified subscript */
90 #define ADSI_EVENT_22_TRIGGER   0x9E    /* Trigger an occurance of event 22 */
91 #define ADSI_EVENT_23_TRIGGER   0x9f    /* Trigger an occurance of event 23 */
92 #define ADSI_EXIT               0xA0    /* Exit the service script interpreter */
93 #endif
94
95 /* Display pages */
96 #define ADSI_INFO_PAGE  0x0
97 #define ADSI_COMM_PAGE  0x1
98
99 #define ADSI_KEY_APPS   16      /* 16 to 33 reserved for applications */
100
101 /* Justification */
102 #define ADSI_JUST_LEFT  0x2
103 #define ADSI_JUST_RIGHT 0x1
104 #define ADSI_JUST_CENT  0x0     /* Center */
105 #define ADSI_JUST_IND   0x3     /* Indent */
106
107 #define ADSI_KEY_SKT    0x80    /* Load from SKT */
108 #define ADSI_KEY_HILITE 0x40    /* Highlight key */
109
110 #define ADSI_DIR_FROM_LEFT (0)
111 #define ADSI_DIR_FROM_RIGHT (1)
112
113 //! Perform Asterisk ADSI initialization (for channel drivers that want
114 //   to support ADSI when the handset is first lifted) */
115 /*! 
116  * \param chan Channel to initialize for ADSI (if supported)
117  * 
118  * Returns 0 on success (or adsi unavailable) and -1 on hangup
119  * 
120  */
121 extern int adsi_channel_init(struct ast_channel *chan);
122
123 extern int adsi_begin_download(struct ast_channel *chan, char *service, char *fdn, char *sec, int version);
124
125 extern int adsi_end_download(struct ast_channel *chan);
126
127 //! Restore ADSI initialization (for applications that play with ADSI
128 //  and want to restore it to normal.  If you touch "INFO" then you
129 //  have to use the adsi_channel_init again instead.
130 /*!
131  * \param chan Channel to restore
132  * 
133  * Returns 0 on success (or adsi unavailable) and -1 on hangup
134  *
135  */
136 extern int adsi_channel_restore(struct ast_channel *chan);
137
138 //! Display some stuff on the screen
139 /*!
140  * \param chan Channel to display on
141  * \param lines NULL-terminated list of things to print (no more than 4 recommended)
142  * \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..)
143  *
144  * Return 0 on success (or adsi unavailable) and -1 on hangup
145  *
146  */
147 extern int adsi_print(struct ast_channel *chan, char **lines, int *align);
148
149 //! Check if scripts for a given app are already loaded.  Version may be -1
150 //  if any version is okay, or 0-255 for a specific version.
151 /*!
152  * \param chan Channel to test for loaded app
153  * \param app Four character app name (must be unique to your application)
154  * \param ver optional version number
155  * \param data Non-zero if you want to be put in data mode
156  *
157  * Returns 0 if scripts is not loaded or not an ADSI CPE.  Returns -1
158  * on hangup.  Returns 1 if script already loaded.
159  */
160 extern int adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data);
161 extern int adsi_unload_session(struct ast_channel *chan);
162
163 /* ADSI Layer 2 transmission functions */
164 extern int adsi_transmit_messages(struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype);
165 extern int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype);
166
167 /* ADSI Layer 3 creation functions */
168
169 //! Connects an ADSI Display Session */
170 /*!
171  * \param buf Character buffer to create parameter in (must have at least 256 free)
172  * \param fdn Optional 4 byte Feature Download Number (for loading soft keys)
173  * \param ver Optional version number (0-255, or -1 to omit)
174  *
175  * Returns number of bytes added to buffer or -1 on error.
176  *
177  */
178
179 extern int adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver);
180
181 //! Begin an ADSI script download */
182 /*!
183  * \param buf Character buffer to create parameter in (must have at least 256 free)
184  * \param service, a 1-18 byte name of the feature
185  * \param fdn 4 byte Feature Download Number (for loading soft keys)
186  * \param sec 4 byte vendor security code
187  * \param ver version number (0-255, or -1 to omit)
188  *
189  * Returns number of bytes added to buffer or -1 on error.
190  *
191  */
192
193 extern int adsi_download_connect(unsigned char *buf, unsigned char *service, unsigned char *fdn, unsigned char *sec, int ver);
194
195 //! Disconnects a running session
196 /*!
197  * \param buf Character buffer to create parameter in (must have at least 256 free)
198  *
199  * Returns number of bytes added to buffer or -1 on error.
200  *
201  */
202 extern int adsi_disconnect_session(unsigned char *buf);
203
204 //! Disconnects (and hopefully saves) a downloaded script
205 /*!
206  * \param buf Character buffer to create parameter in (must have at least 256 free)
207  *
208  * Returns number of bytes added to buffer or -1 on error.
209  *
210  */
211 extern int adsi_download_disconnect(unsigned char *buf);
212
213 //! Puts CPE in data mode...
214 /*!
215  * \param buf Character buffer to create parameter in (must have at least 256 free)
216  *
217  * Returns number of bytes added to buffer or -1 on error.
218  *
219  */
220 extern int adsi_data_mode(unsigned char *buf);
221
222 //! Puts CPE in voice mode...
223 /*!
224  * \param buf Character buffer to create parameter in (must have at least 256 free)
225  * \param when (a time in seconds) to make the switch
226  *
227  * Returns number of bytes added to buffer or -1 on error.
228  *
229  */
230 extern int adsi_voice_mode(unsigned char *buf, int when);
231
232 //! Returns non-zero if Channel does or might support ADSI
233 /*!
234  * \param chan Channel to check
235  *
236  */
237 extern int adsi_available(struct ast_channel *chan);
238
239 //! Loads a line of info into the display */
240 /*!
241  * \param buf Character buffer to create parameter in (must have at least 256 free)
242  * \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
243  * \param line Line number to load (1-4 for Comm page, 1-33 for info page)
244  * \param just Line justification (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CENT, ADSI_JUST_IND)
245  * \param wrap Wrap (1 = yes, 0 = no)
246  * \param col1 Text to place in first column
247  * \param col2 Text to place in second column
248  *
249  * Returns number of bytes added to buffer or -1 on error.
250  *
251  */
252
253 extern int adsi_display(unsigned char *buf, int page, int line, int just, int wrap, unsigned char *col1, unsigned char *col2);
254
255 //! Sets the current line and page */
256 /*!
257  * \param buf Character buffer to create parameter in (must have at least 256 free)
258  * \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
259  * \param line Line number (1-33 for info page, 1-4 for comm page)
260  *
261  * Returns number of bytes added to buffer or -1 on error.
262  *
263  */
264
265 extern int adsi_set_line(unsigned char *buf, int page, int line);
266
267 //! Creates "load soft key" parameters
268 /*! 
269  * \param buf Character buffer to create parameter in (must have at least 256 free)
270  * \param key Key code from 2 to 33, for which key we are loading
271  * \param llabel Long label for key (1-18 bytes)
272  * \param slabel Short label for key (1-7 bytes)
273  * \param ret Optional return sequence (NULL for none)
274  * \param data whether to put CPE in data mode before sending digits
275  *
276  * Returns number of bytes added to buffer or -1 on error.
277  *
278  */
279 extern int adsi_load_soft_key(unsigned char *buf, int key, unsigned char *llabel, unsigned char *slabel, unsigned char *ret, int data);
280
281 //! Set which soft keys should be displayed
282 /*!
283  * \param buf Character buffer to create parameter in (must have at least 256 free)
284  * \param keys Array of 6 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE
285  *
286  * Returns number of bytes added to buffer or -1 on error.
287  *
288  */
289 extern int adsi_set_keys(unsigned char *buf, unsigned char *keys);
290
291 //! Set input information
292 /*!
293  * \param buf Character buffer to create parameter in (must have at least 256 free)
294  * \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
295  * \param line Line number to input on
296  * \param display Set to zero to obscure input, or 1 to leave visible
297  * \param format Format number to use (0-7)
298  * \param just Justification (left, right center, indent)
299  *
300  * Returns number of bytes added to buffer or -1 on error.
301  *
302  */
303 extern int adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just);
304
305 //! Set input format
306 /*!
307  * \param buf Character buffer to create parameter in (must have at least 256 free)
308  * \param num Which format we are setting
309  * \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT)
310  * \param wrap Set to 1 to permit line wrap, or 0 if not
311  * \param format1 Format for column 1
312  * \param format2 Format for column 2
313  *
314  * Returns number of bytes added to buffer or -1 on error.
315  *
316  */
317 extern int adsi_input_format(unsigned char *buf, int num, int dir, int wrap, unsigned char *format1, unsigned char *format2);
318 #endif