adsi.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief ADSI Support (built upon Caller*ID)
  20. */
  21. #ifndef _ASTERISK_ADSI_H
  22. #define _ASTERISK_ADSI_H
  23. #include "asterisk/callerid.h"
  24. /*! \name ADSI parameters */
  25. /*@{ */
  26. /* ADSI Message types */
  27. #define ADSI_MSG_DISPLAY 132
  28. #define ADSI_MSG_DOWNLOAD 133
  29. /* ADSI Parameters (display) */
  30. #define ADSI_LOAD_SOFTKEY 128
  31. #define ADSI_INIT_SOFTKEY_LINE 129
  32. #define ADSI_LOAD_VIRTUAL_DISP 130
  33. #define ADSI_LINE_CONTROL 131
  34. #define ADSI_INFORMATION 132
  35. #define ADSI_DISC_SESSION 133
  36. #define ADSI_SWITCH_TO_DATA 134
  37. #define ADSI_SWITCH_TO_VOICE 135
  38. #define ADSI_CLEAR_SOFTKEY 136
  39. #define ADSI_INPUT_CONTROL 137
  40. #define ADSI_INPUT_FORMAT 138
  41. #define ADSI_SWITCH_TO_PERIPH 139
  42. #define ADSI_MOVE_DATA 140
  43. #define ADSI_LOAD_DEFAULT 141
  44. #define ADSI_CONNECT_SESSION 142
  45. #define ADSI_CLEAR_TYPE_AHEAD 143
  46. #define ADSI_DISPLAY_CALL_BUF 144
  47. #define ADSI_CLEAR_CALL_BUF 145
  48. #define ADSI_SWITCH_TO_ALT 146
  49. #define ADSI_SWITCH_TO_GRAPHICS 147
  50. #define ADSI_CLEAR_SCREEN 148
  51. #define ADSI_QUERY_CONFIG 149
  52. #define ADSI_QUERY_CPEID 150
  53. #define ADSI_SWITCH_TO_APP 151
  54. /* Feature download messages */
  55. #define ADSI_LOAD_SOFTKEY_TABLE 128 /* Conveniently identical to the soft version */
  56. #define ADSI_LOAD_PREDEF_DISP 129 /* Load predefined display */
  57. #define ADSI_LOAD_SCRIPT 130
  58. #define ADSI_DOWNLOAD_CONNECT 131
  59. #define ADSI_DOWNLOAD_DISC 132
  60. /* Special return string codes */
  61. #define ADSI_ENCODED_DTMF 0x80 /* Transmit following chars with encoded dtmf */
  62. #define ADSI_ON_HOOK 0x81 /* Open switch-hook */
  63. #define ADSI_OFF_HOOK 0x82 /* Close switch-hook */
  64. #define ADSI_FLASH 0x83 /* Flash switch-hook */
  65. #define ADSI_DIAL_TONE_DETECT 0x84 /* Wait for dialtone */
  66. #define ADSI_LINE_NUMBER 0x85 /* Send current line number using DTMF/encoded DTMF */
  67. #define ADSI_BLANK 0x86 /* Blank (does nothing) */
  68. #define ADSI_SEND_CHARS 0x87 /* Send collected digits/characters */
  69. #define ADSI_CLEAR_CHARS 0x88 /* Clear characters/digits collected */
  70. #define ADSI_BACKSPACE 0x89 /* Erase last collected digit */
  71. #define ADSI_TAB_COLUMN 0x8A /* Display specified display column of current line */
  72. #define ADSI_GOTO_LINE 0x8B /* Go to given page and line number */
  73. #define ADSI_GOTO_LINE_REL 0x8C /* Go to given line (relative to current) */
  74. #define ADSI_PAGE_UP 0x8D /* Go up one page */
  75. #define ADSI_PAGE_DOWN 0x8E /* Go down one page */
  76. #define ADSI_EXTENDED_DTMF 0x8F /* Send DTMF tones for 250ms instead of 60 ms */
  77. #define ADSI_DELAY 0x90 /* Delay for given # (times 10) of ms */
  78. #define ADSI_DIAL_PULSE_ONE 0x91 /* Send a dial pulse "1" */
  79. #define ADSI_SWITCH_TO_DATA2 0x92 /* Switch CPE to data mode */
  80. #define ADSI_SWITCH_TO_VOICE2 0x93 /* Switch CPE to voice mode */
  81. #define ADSI_DISP_CALL_BUF 0x94 /* Display specified call buffer */
  82. #define ADSI_CLEAR_CALL_B 0x95 /* Clear specified call buffer */
  83. #ifdef __ADSI_CPE
  84. /* These messages are reserved for the ADSI CPE only */
  85. #define ADSI_DISPLAY_CONTROL 0x98 /* Store predefined display identified next / Display status display page */
  86. #define ADSI_DISPLAY_SOFT_KEYS 0x99 /* Display the script soft keys identified next */
  87. #define ADSI_CHANGE_STATE 0x9A /* Change state of service script */
  88. #define ADSI_START_CLEAR_TIMER 0x9B /* Start / Clear timer */
  89. #define ADSI_SET_SCRIPT_FLAG 0x9C /* Set / clear a script flag */
  90. #define ADSI_JUMP_TO_SUBSCRIPT 0x9D /* Jump to specified subscript */
  91. #define ADSI_EVENT_22_TRIGGER 0x9E /* Trigger an occurance of event 22 */
  92. #define ADSI_EVENT_23_TRIGGER 0x9f /* Trigger an occurance of event 23 */
  93. #define ADSI_EXIT 0xA0 /* Exit the service script interpreter */
  94. #endif
  95. /* Display pages */
  96. #define ADSI_INFO_PAGE 0x0
  97. #define ADSI_COMM_PAGE 0x1
  98. #define ADSI_KEY_APPS 16 /* 16 to 33 reserved for applications */
  99. /* Justification */
  100. #define ADSI_JUST_LEFT 0x2
  101. #define ADSI_JUST_RIGHT 0x1
  102. #define ADSI_JUST_CENT 0x0 /* Center */
  103. #define ADSI_JUST_IND 0x3 /* Indent */
  104. #define ADSI_KEY_SKT 0x80 /* Load from SKT */
  105. #define ADSI_KEY_HILITE 0x40 /* Highlight key */
  106. #define ADSI_DIR_FROM_LEFT (0)
  107. #define ADSI_DIR_FROM_RIGHT (1)
  108. #define AST_ADSI_VERSION 1
  109. /*@} */
  110. int ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version);
  111. int ast_adsi_end_download(struct ast_channel *chan);
  112. /*! Restore ADSI initialization (for applications that play with ADSI
  113. * and want to restore it to normal. If you touch "INFO" then you
  114. * have to use the ast_adsi_channel_init again instead.
  115. * \param chan Channel to restore
  116. *
  117. * \retval 0 on success (or adsi unavailable)
  118. * \retval -1 on hangup
  119. */
  120. int ast_adsi_channel_restore(struct ast_channel *chan);
  121. /*!
  122. * \brief Display some stuff on the screen
  123. * \param chan Channel to display on
  124. * \param lines NULL-terminated list of things to print (no more than 4 recommended)
  125. * \param align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..)
  126. * \param voice whether to jump into voice mode when finished
  127. *
  128. * \retval 0 on success (or adsi unavailable)
  129. * \retval -1 on hangup
  130. */
  131. int ast_adsi_print(struct ast_channel *chan, char **lines, int *align, int voice);
  132. /*!
  133. * \brief Check if scripts for a given app are already loaded.
  134. * Version may be -1, if any version is okay, or 0-255 for a specific version.
  135. * \param chan Channel to test for loaded app
  136. * \param app Four character app name (must be unique to your application)
  137. * \param ver optional version number
  138. * \param data Non-zero if you want to be put in data mode
  139. *
  140. * \retval 0 if scripts is not loaded or not an ADSI CPE
  141. * \retval -1 on hangup
  142. * \retval 1 if script already loaded.
  143. */
  144. int ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data);
  145. int ast_adsi_unload_session(struct ast_channel *chan);
  146. /* ADSI Layer 2 transmission functions */
  147. int ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype);
  148. int ast_adsi_transmit_message_full(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait);
  149. /*! Read some encoded DTMF data.
  150. * Returns number of bytes received
  151. */
  152. int ast_adsi_read_encoded_dtmf(struct ast_channel *chan, unsigned char *buf, int maxlen);
  153. /* ADSI Layer 3 creation functions */
  154. /*!
  155. * \brief Connects an ADSI Display Session
  156. * \param buf Character buffer to create parameter in (must have at least 256 free)
  157. * \param fdn Optional 4 byte Feature Download Number (for loading soft keys)
  158. * \param ver Optional version number (0-255, or -1 to omit)
  159. *
  160. * \retval number of bytes added to buffer
  161. * \retval -1 on error.
  162. */
  163. int ast_adsi_connect_session(unsigned char *buf, unsigned char *fdn, int ver);
  164. /*! Build Query CPE ID of equipment.
  165. * Returns number of bytes added to message
  166. */
  167. int ast_adsi_query_cpeid(unsigned char *buf);
  168. int ast_adsi_query_cpeinfo(unsigned char *buf);
  169. /*! Get CPE ID from an attached ADSI compatible CPE.
  170. * Returns 1 on success, storing 4 bytes of CPE ID at buf
  171. * or -1 on hangup, or 0 if there was no hangup but it failed to find the
  172. * device ID. Returns to voice mode if "voice" is non-zero.
  173. */
  174. int ast_adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice);
  175. int ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice);
  176. /*!
  177. * \brief Begin an ADSI script download
  178. * \param buf Character buffer to create parameter in (must have at least 256 free)
  179. * \param service a 1-18 byte name of the feature
  180. * \param fdn 4 byte Feature Download Number (for loading soft keys)
  181. * \param sec 4 byte vendor security code
  182. * \param ver version number (0-255, or -1 to omit)
  183. *
  184. * \retval number of bytes added to buffer
  185. * \retval -1 on error.
  186. */
  187. int ast_adsi_download_connect(unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver);
  188. /*!
  189. * \brief Disconnects a running session.
  190. * \param buf Character buffer to create parameter in (must have at least 256 free)
  191. *
  192. * \retval number of bytes added to buffer
  193. * \retval -1 on error.
  194. */
  195. int ast_adsi_disconnect_session(unsigned char *buf);
  196. /*!
  197. * \brief Disconnects (and hopefully saves) a downloaded script
  198. * \param buf Character buffer to create parameter in (must have at least 256 free)
  199. *
  200. * \retval number of bytes added to buffer
  201. * \retval -1 on error.
  202. */
  203. int ast_adsi_download_disconnect(unsigned char *buf);
  204. /*!
  205. * \brief Puts CPE in data mode.
  206. * \param buf Character buffer to create parameter in (must have at least 256 free)
  207. *
  208. * \retval number of bytes added to buffer
  209. * \retval -1 on error.
  210. */
  211. int ast_adsi_data_mode(unsigned char *buf);
  212. int ast_adsi_clear_soft_keys(unsigned char *buf);
  213. int ast_adsi_clear_screen(unsigned char *buf);
  214. /*!
  215. * \brief Puts CPE in voice mode.
  216. * \param buf Character buffer to create parameter in (must have at least 256 free)
  217. * \param when (a time in seconds) to make the switch
  218. *
  219. * \retval number of bytes added to buffer
  220. * \retval -1 on error.
  221. */
  222. int ast_adsi_voice_mode(unsigned char *buf, int when);
  223. /*!
  224. * \brief Returns non-zero if Channel does or might support ADSI
  225. * \param chan Channel to check
  226. */
  227. int ast_adsi_available(struct ast_channel *chan);
  228. /*!
  229. * \brief Loads a line of info into the display.
  230. * \param buf Character buffer to create parameter in (must have at least 256 free)
  231. * \param page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
  232. * \param line Line number to load (1-4 for Comm page, 1-33 for info page)
  233. * \param just Line justification (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CENT, ADSI_JUST_IND)
  234. * \param wrap Wrap (1 = yes, 0 = no)
  235. * \param col1 Text to place in first column
  236. * \param col2 Text to place in second column
  237. *
  238. * \retval number of bytes added to buffer
  239. * \retval -1 on error.
  240. */
  241. int ast_adsi_display(unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2);
  242. /*!
  243. * \brief Sets the current line and page.
  244. * \param buf Character buffer to create parameter in (must have at least 256 free)
  245. * \param page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
  246. * \param line Line number (1-33 for info page, 1-4 for comm page)
  247. *
  248. * \retval number of bytes added to buffer
  249. * \retval -1 on error.
  250. */
  251. int ast_adsi_set_line(unsigned char *buf, int page, int line);
  252. /*!
  253. * \brief Creates "load soft key" parameters
  254. * \param buf Character buffer to create parameter in (must have at least 256 free)
  255. * \param key Key code from 2 to 33, for which key we are loading
  256. * \param llabel Long label for key (1-18 bytes)
  257. * \param slabel Short label for key (1-7 bytes)
  258. * \param ret Optional return sequence (NULL for none)
  259. * \param data whether to put CPE in data mode before sending digits
  260. *
  261. * \retval number of bytes added to buffer
  262. * \retval -1 on error.
  263. */
  264. int ast_adsi_load_soft_key(unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data);
  265. /*!
  266. * \brief Set which soft keys should be displayed
  267. * \param buf Character buffer to create parameter in (must have at least 256 free)
  268. * \param keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE
  269. * But remember, the last two keys aren't real keys, they're for scrolling
  270. *
  271. * \retval number of bytes added to buffer
  272. * \retval -1 on error.
  273. */
  274. int ast_adsi_set_keys(unsigned char *buf, unsigned char *keys);
  275. /*!
  276. * \brief Set input information
  277. * \param buf Character buffer to create parameter in (must have at least 256 free)
  278. * \param page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
  279. * \param line Line number to input on
  280. * \param display Set to zero to obscure input, or 1 to leave visible
  281. * \param format Format number to use (0-7)
  282. * \param just Justification (left, right center, indent)
  283. *
  284. * \retval number of bytes added to buffer
  285. * \retval -1 on error.
  286. */
  287. int ast_adsi_input_control(unsigned char *buf, int page, int line, int display, int format, int just);
  288. /*!
  289. * \brief Set input format
  290. * \param buf Character buffer to create parameter in (must have at least 256 free)
  291. * \param num Which format we are setting
  292. * \param dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT)
  293. * \param wrap Set to 1 to permit line wrap, or 0 if not
  294. * \param format1 Format for column 1
  295. * \param format2 Format for column 2
  296. *
  297. * \retval number of bytes added to buffer
  298. * \retval -1 on error.
  299. */
  300. int ast_adsi_input_format(unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2);
  301. struct adsi_funcs {
  302. unsigned int version;
  303. int (*begin_download)(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version);
  304. int (*end_download)(struct ast_channel *chan);
  305. int (*channel_restore) (struct ast_channel *chan);
  306. int (*print) (struct ast_channel *chan, char **lines, int *align, int voice);
  307. int (*load_session) (struct ast_channel *chan, unsigned char *app, int ver, int data);
  308. int (*unload_session) (struct ast_channel *chan);
  309. int (*transmit_message) (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype);
  310. int (*transmit_message_full) (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait);
  311. int (*read_encoded_dtmf) (struct ast_channel *chan, unsigned char *buf, int maxlen);
  312. int (*connect_session) (unsigned char *buf, unsigned char *fdn, int ver);
  313. int (*query_cpeid) (unsigned char *buf);
  314. int (*query_cpeinfo) (unsigned char *buf);
  315. int (*get_cpeid) (struct ast_channel *chan, unsigned char *cpeid, int voice);
  316. int (*get_cpeinfo) (struct ast_channel *chan, int *width, int *height, int *buttons, int voice);
  317. int (*download_connect) (unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver);
  318. int (*disconnect_session) (unsigned char *buf);
  319. int (*download_disconnect) (unsigned char *buf);
  320. int (*data_mode) (unsigned char *buf);
  321. int (*clear_soft_keys) (unsigned char *buf);
  322. int (*clear_screen) (unsigned char *buf);
  323. int (*voice_mode) (unsigned char *buf, int when);
  324. int (*available) (struct ast_channel *chan);
  325. int (*display) (unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2);
  326. int (*set_line) (unsigned char *buf, int page, int line);
  327. int (*load_soft_key) (unsigned char *buf, int key, const char *llabel, const char *slabel, char *ret, int data);
  328. int (*set_keys) (unsigned char *buf, unsigned char *keys);
  329. int (*input_control) (unsigned char *buf, int page, int line, int display, int format, int just);
  330. int (*input_format) (unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2);
  331. };
  332. void ast_adsi_install_funcs(const struct adsi_funcs *funcs);
  333. #endif /* _ASTERISK_ADSI_H */