at_interpreter.h

Go to the documentation of this file.
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 General Public License version 2, as
00014  * 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 General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * 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.13 2007/04/08 08:16:17 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     AT_MODEM_CONTROL_CALL,
00071     AT_MODEM_CONTROL_ANSWER,
00072     AT_MODEM_CONTROL_HANGUP,
00073     AT_MODEM_CONTROL_OFFHOOK,
00074     AT_MODEM_CONTROL_ONHOOK,
00075     AT_MODEM_CONTROL_DTR,
00076     AT_MODEM_CONTROL_RTS,
00077     AT_MODEM_CONTROL_CTS,
00078     AT_MODEM_CONTROL_CAR,
00079     AT_MODEM_CONTROL_RNG,
00080     AT_MODEM_CONTROL_DSR,
00081     AT_MODEM_CONTROL_SETID,
00082     /* The remainder of the control functions should not get past the modem, to the
00083        application. */
00084     AT_MODEM_CONTROL_RESTART,
00085     AT_MODEM_CONTROL_DTE_TIMEOUT
00086 };
00087 
00088 enum
00089 {
00090     AT_RESPONSE_CODE_OK = 0,
00091     AT_RESPONSE_CODE_CONNECT,
00092     AT_RESPONSE_CODE_RING,
00093     AT_RESPONSE_CODE_NO_CARRIER,
00094     AT_RESPONSE_CODE_ERROR,
00095     AT_RESPONSE_CODE_XXX,
00096     AT_RESPONSE_CODE_NO_DIALTONE,
00097     AT_RESPONSE_CODE_BUSY,
00098     AT_RESPONSE_CODE_NO_ANSWER,
00099     AT_RESPONSE_CODE_FCERROR,
00100     AT_RESPONSE_CODE_FRH3
00101 };
00102 
00103 /*!
00104     AT profile.
00105 */
00106 typedef struct
00107 {
00108     /*! TRUE if character echo is enabled */
00109     int echo;
00110     /*! TRUE if verbose reporting is enabled */
00111     int verbose;
00112     /*! TRUE if result codes are verbose */
00113     int result_code_format;
00114     /*! TRUE if pulse dialling is the default */
00115     int pulse_dial;
00116     /*! ??? */
00117     int double_escape;
00118     /*! ??? */
00119     int adaptive_receive;
00120     /*! The state of all possible S registers */
00121     uint8_t s_regs[100];
00122 } at_profile_t;
00123 
00124 /*!
00125     AT descriptor. This defines the working state for a single instance of
00126     the AT interpreter.
00127 */
00128 struct at_state_s
00129 {
00130     at_profile_t p;
00131     /*! Value set by +GCI */
00132     int country_of_installation;
00133     /*! Value set by +FIT */
00134     int dte_inactivity_timeout;
00135     /*! Value set by +FIT */
00136     int dte_inactivity_action;
00137     /*! Value set by L */
00138     int speaker_volume;
00139     /*! Value set by M */
00140     int speaker_mode;
00141     /*! This is no real DTE rate. This variable is for compatibility this serially
00142         connected modems. */
00143     /*! Value set by +IPR/+FPR */
00144     int dte_rate;
00145     /*! Value set by +ICF */
00146     int dte_char_format;
00147     /*! Value set by +ICF */
00148     int dte_parity;
00149     /*! Value set by &C */
00150     int rlsd_behaviour;
00151     /*! Value set by &D */
00152     int dtr_behaviour;
00153     /*! Value set by +FCL */
00154     int carrier_loss_timeout;
00155     /*! Value set by X */
00156     int result_code_mode;
00157     /*! Value set by +IDSR */
00158     int dsr_option;
00159     /*! Value set by +ILSD */
00160     int long_space_disconnect_option;
00161     /*! Value set by +ICLOK */
00162     int sync_tx_clock_source;
00163     /*! Value set by +EWIND */
00164     int rx_window;
00165     /*! Value set by +EWIND */
00166     int tx_window;
00167     
00168     int v8bis_signal;
00169     int v8bis_1st_message;
00170     int v8bis_2nd_message;
00171     int v8bis_sig_en;
00172     int v8bis_msg_en;
00173     int v8bis_supp_delay;
00174 
00175     uint8_t rx_data[256];
00176     int rx_data_bytes;
00177 
00178     int display_call_info;
00179     int call_info_displayed;
00180     char *call_date;
00181     char *call_time;
00182     char *originating_name;
00183     char *originating_number;
00184     char *originating_ani;
00185     char *destination_number;
00186     char *local_id;
00187     /*! The currently select FAX modem class. 0 = data modem mode. */
00188     int fclass_mode;
00189     int at_rx_mode;
00190     int rings_indicated;
00191     int do_hangup;
00192     int silent_dial;
00193     int ok_is_pending;
00194     int dte_is_waiting;
00195     /*! \brief TRUE if a carrier is presnt. Otherwise FALSE. */
00196     int rx_signal_present;
00197     /*! \brief TRUE if a modem has trained, Otherwise FALSE. */
00198     int rx_trained;
00199     int transmit;
00200 
00201     char line[256];
00202     int line_ptr;
00203 
00204     at_modem_control_handler_t *modem_control_handler;
00205     void *modem_control_user_data;
00206     at_tx_handler_t *at_tx_handler;
00207     void *at_tx_user_data;
00208     at_class1_handler_t *class1_handler;
00209     void *class1_user_data;
00210 
00211     /*! \brief Error and flow logging control */
00212     logging_state_t logging;
00213 };
00214 
00215 #if defined(__cplusplus)
00216 extern "C"
00217 {
00218 #endif
00219 
00220 void at_set_at_rx_mode(at_state_t *s, int new_mode);
00221 
00222 void at_put_response(at_state_t *s, const char *t);
00223 
00224 void at_put_numeric_response(at_state_t *s, int val);
00225 
00226 void at_put_response_code(at_state_t *s, int code);
00227 
00228 void at_reset_call_info(at_state_t *s);
00229 
00230 /*! Set the call information for an AT interpreter.
00231     \brief Set the call information for an AT interpreter.
00232     \param s The AT interpreter context.
00233     \param call_date .
00234     \param call_time .
00235     \param originating_name .
00236     \param originating_number .
00237     \param originating_ani .
00238     \param destination_number . */
00239 void at_set_call_info(at_state_t *s,
00240                       char const *call_date,
00241                       char const *call_time,
00242                       char const *originating_name,
00243                       char const *originating_number,
00244                       char const *originating_ani,
00245                       char const *destination_number);
00246 
00247 void at_display_call_info(at_state_t *s);
00248 
00249 int at_modem_control(at_state_t *s, int op, const char *num);
00250 
00251 void at_call_event(at_state_t *s, int event);
00252 
00253 void at_interpreter(at_state_t *s, const char *cmd, int len);
00254 
00255 void at_set_class1_handler(at_state_t *s, at_class1_handler_t handler, void *user_data);
00256 
00257 at_state_t *at_init(at_state_t *s,
00258                     at_tx_handler_t *at_tx_handler,
00259                     void *at_tx_user_data,
00260                     at_modem_control_handler_t *modem_control_handler,
00261                     void *modem_control_user_data);
00262 
00263 #if defined(__cplusplus)
00264 }
00265 #endif
00266 
00267 #endif
00268 /*- End of file ------------------------------------------------------------*/

Generated on Mon May 14 04:36:39 2007 for libspandsp by  doxygen 1.5.1