libspandsp 0.0.4
|
00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * at_interpreter.h - AT command interpreter to V.251, V.252, V.253, T.31 and the 3GPP specs. 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004, 2005, 2006 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: at_interpreter.h,v 1.18 2008/06/11 17:52:30 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_AT_INTERPRETER_H_) 00031 #define _SPANDSP_AT_INTERPRETER_H_ 00032 00033 /*! \page at_page AT command interpreter 00034 \section at_page_sec_1 What does it do? 00035 The AT interpreter module implements V.251, V.252, V.253, T.31 and various 3GPP 00036 modem control commands. 00037 00038 \section at_page_sec_2 How does it work? 00039 */ 00040 00041 typedef struct at_state_s at_state_t; 00042 00043 typedef int (at_modem_control_handler_t)(at_state_t *s, void *user_data, int op, const char *num); 00044 typedef int (at_tx_handler_t)(at_state_t *s, void *user_data, const uint8_t *buf, size_t len); 00045 typedef int (at_class1_handler_t)(at_state_t *s, void *user_data, int direction, int operation, int val); 00046 00047 enum at_rx_mode_e 00048 { 00049 AT_MODE_ONHOOK_COMMAND, 00050 AT_MODE_OFFHOOK_COMMAND, 00051 AT_MODE_CONNECTED, 00052 AT_MODE_DELIVERY, 00053 AT_MODE_HDLC, 00054 AT_MODE_STUFFED 00055 }; 00056 00057 enum at_call_event_e 00058 { 00059 AT_CALL_EVENT_ALERTING = 1, 00060 AT_CALL_EVENT_CONNECTED, 00061 AT_CALL_EVENT_ANSWERED, 00062 AT_CALL_EVENT_BUSY, 00063 AT_CALL_EVENT_NO_DIALTONE, 00064 AT_CALL_EVENT_NO_ANSWER, 00065 AT_CALL_EVENT_HANGUP 00066 }; 00067 00068 enum at_modem_control_operation_e 00069 { 00070 /*! Start an outgoing call. */ 00071 AT_MODEM_CONTROL_CALL, 00072 /*! Answer an incoming call. */ 00073 AT_MODEM_CONTROL_ANSWER, 00074 /*! Hangup a call. */ 00075 AT_MODEM_CONTROL_HANGUP, 00076 /*! Take the line off hook. */ 00077 AT_MODEM_CONTROL_OFFHOOK, 00078 /*! Put the line on hook. */ 00079 AT_MODEM_CONTROL_ONHOOK, 00080 /*! Control V.24 Circuit 108, "data terminal ready". */ 00081 AT_MODEM_CONTROL_DTR, 00082 /*! Control V.24 Circuit 105, "request to send". */ 00083 AT_MODEM_CONTROL_RTS, 00084 /*! Control V.24 Circuit 106, "clear to send". */ 00085 AT_MODEM_CONTROL_CTS, 00086 /*! Control V.24 Circuit 109, "receive line signal detector" (i.e. carrier detect). */ 00087 AT_MODEM_CONTROL_CAR, 00088 /*! Control V.24 Circuit 125, "ring indicator". */ 00089 AT_MODEM_CONTROL_RNG, 00090 /*! Control V.24 Circuit 107, "data set ready". */ 00091 AT_MODEM_CONTROL_DSR, 00092 /*! Set the caller ID for outgoing calls. */ 00093 AT_MODEM_CONTROL_SETID, 00094 /* The remainder of the control functions should not get past the modem, to the 00095 application. */ 00096 AT_MODEM_CONTROL_RESTART, 00097 AT_MODEM_CONTROL_DTE_TIMEOUT 00098 }; 00099 00100 enum 00101 { 00102 AT_RESPONSE_CODE_OK = 0, 00103 AT_RESPONSE_CODE_CONNECT, 00104 AT_RESPONSE_CODE_RING, 00105 AT_RESPONSE_CODE_NO_CARRIER, 00106 AT_RESPONSE_CODE_ERROR, 00107 AT_RESPONSE_CODE_XXX, 00108 AT_RESPONSE_CODE_NO_DIALTONE, 00109 AT_RESPONSE_CODE_BUSY, 00110 AT_RESPONSE_CODE_NO_ANSWER, 00111 AT_RESPONSE_CODE_FCERROR, 00112 AT_RESPONSE_CODE_FRH3 00113 }; 00114 00115 struct at_call_id 00116 { 00117 char *id; 00118 char *value; 00119 struct at_call_id *next; 00120 }; 00121 00122 /*! 00123 AT profile. 00124 */ 00125 typedef struct 00126 { 00127 /*! TRUE if character echo is enabled */ 00128 int echo; 00129 /*! TRUE if verbose reporting is enabled */ 00130 int verbose; 00131 /*! TRUE if result codes are verbose */ 00132 int result_code_format; 00133 /*! TRUE if pulse dialling is the default */ 00134 int pulse_dial; 00135 /*! ??? */ 00136 int double_escape; 00137 /*! ??? */ 00138 int adaptive_receive; 00139 /*! The state of all possible S registers */ 00140 uint8_t s_regs[100]; 00141 } at_profile_t; 00142 00143 /*! 00144 AT descriptor. This defines the working state for a single instance of 00145 the AT interpreter. 00146 */ 00147 struct at_state_s 00148 { 00149 at_profile_t p; 00150 /*! Value set by +GCI */ 00151 int country_of_installation; 00152 /*! Value set by +FIT */ 00153 int dte_inactivity_timeout; 00154 /*! Value set by +FIT */ 00155 int dte_inactivity_action; 00156 /*! Value set by L */ 00157 int speaker_volume; 00158 /*! Value set by M */ 00159 int speaker_mode; 00160 /*! This is no real DTE rate. This variable is for compatibility this serially 00161 connected modems. */ 00162 /*! Value set by +IPR/+FPR */ 00163 int dte_rate; 00164 /*! Value set by +ICF */ 00165 int dte_char_format; 00166 /*! Value set by +ICF */ 00167 int dte_parity; 00168 /*! Value set by &C */ 00169 int rlsd_behaviour; 00170 /*! Value set by &D */ 00171 int dtr_behaviour; 00172 /*! Value set by +FCL */ 00173 int carrier_loss_timeout; 00174 /*! Value set by X */ 00175 int result_code_mode; 00176 /*! Value set by +IDSR */ 00177 int dsr_option; 00178 /*! Value set by +ILSD */ 00179 int long_space_disconnect_option; 00180 /*! Value set by +ICLOK */ 00181 int sync_tx_clock_source; 00182 /*! Value set by +EWIND */ 00183 int rx_window; 00184 /*! Value set by +EWIND */ 00185 int tx_window; 00186 00187 int v8bis_signal; 00188 int v8bis_1st_message; 00189 int v8bis_2nd_message; 00190 int v8bis_sig_en; 00191 int v8bis_msg_en; 00192 int v8bis_supp_delay; 00193 00194 uint8_t rx_data[256]; 00195 int rx_data_bytes; 00196 00197 int display_call_info; 00198 int call_info_displayed; 00199 struct at_call_id *call_id; 00200 char *local_id; 00201 /*! The currently select FAX modem class. 0 = data modem mode. */ 00202 int fclass_mode; 00203 int at_rx_mode; 00204 int rings_indicated; 00205 int do_hangup; 00206 int silent_dial; 00207 int ok_is_pending; 00208 int dte_is_waiting; 00209 /*! \brief TRUE if a carrier is presnt. Otherwise FALSE. */ 00210 int rx_signal_present; 00211 /*! \brief TRUE if a modem has trained, Otherwise FALSE. */ 00212 int rx_trained; 00213 int transmit; 00214 00215 char line[256]; 00216 int line_ptr; 00217 00218 at_modem_control_handler_t *modem_control_handler; 00219 void *modem_control_user_data; 00220 at_tx_handler_t *at_tx_handler; 00221 void *at_tx_user_data; 00222 at_class1_handler_t *class1_handler; 00223 void *class1_user_data; 00224 00225 /*! \brief Error and flow logging control */ 00226 logging_state_t logging; 00227 }; 00228 00229 #if defined(__cplusplus) 00230 extern "C" 00231 { 00232 #endif 00233 00234 void at_set_at_rx_mode(at_state_t *s, int new_mode); 00235 00236 void at_put_response(at_state_t *s, const char *t); 00237 00238 void at_put_numeric_response(at_state_t *s, int val); 00239 00240 void at_put_response_code(at_state_t *s, int code); 00241 00242 void at_reset_call_info(at_state_t *s); 00243 00244 /*! Set the call information for an AT interpreter. 00245 \brief Set the call information for an AT interpreter. 00246 \param s The AT interpreter context. 00247 \param id . 00248 \param value . */ 00249 void at_set_call_info(at_state_t *s, char const *id, char const *value); 00250 00251 void at_display_call_info(at_state_t *s); 00252 00253 int at_modem_control(at_state_t *s, int op, const char *num); 00254 00255 void at_call_event(at_state_t *s, int event); 00256 00257 void at_interpreter(at_state_t *s, const char *cmd, int len); 00258 00259 void at_set_class1_handler(at_state_t *s, at_class1_handler_t handler, void *user_data); 00260 00261 /*! Initialise an AT interpreter context. 00262 \brief Initialise an AT interpreter context. 00263 \param s The AT context. 00264 \param at_tx_handler x. 00265 \param at_tx_user_data x. 00266 \param modem_control_handler x. 00267 \param modem_control_user_data x. 00268 \return A pointer to the AT context, or NULL if there was a problem. */ 00269 at_state_t *at_init(at_state_t *s, 00270 at_tx_handler_t *at_tx_handler, 00271 void *at_tx_user_data, 00272 at_modem_control_handler_t *modem_control_handler, 00273 void *modem_control_user_data); 00274 00275 /*! Free an AT interpreter context. 00276 \brief Free an AT interpreter context. 00277 \param s The AT context. 00278 \return 0 for OK */ 00279 int at_free(at_state_t *s); 00280 00281 #if defined(__cplusplus) 00282 } 00283 #endif 00284 00285 #endif 00286 /*- End of file ------------------------------------------------------------*/