spandsp  0.0.6
at_interpreter.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * at_interpreter.h - AT command interpreter to V.251, V.252, V.253, T.31 and the 3GPP specs.
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2004, 2005, 2006 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_AT_INTERPRETER_H_)
29 #define _SPANDSP_AT_INTERPRETER_H_
30 
31 /*! \page at_page AT command interpreter
32 \section at_page_sec_1 What does it do?
33 The AT interpreter module implements V.251, V.252, V.253, T.31 and various 3GPP
34 modem control commands.
35 
36 \section at_page_sec_2 How does it work?
37 */
38 
39 enum at_rx_mode_e
40 {
41  AT_MODE_ONHOOK_COMMAND,
42  AT_MODE_OFFHOOK_COMMAND,
43  AT_MODE_CONNECTED,
44  AT_MODE_DELIVERY,
45  AT_MODE_HDLC,
46  AT_MODE_STUFFED
47 };
48 
49 enum at_call_event_e
50 {
51  AT_CALL_EVENT_ALERTING = 1,
52  AT_CALL_EVENT_CONNECTED,
53  AT_CALL_EVENT_ANSWERED,
54  AT_CALL_EVENT_BUSY,
55  AT_CALL_EVENT_NO_DIALTONE,
56  AT_CALL_EVENT_NO_ANSWER,
57  AT_CALL_EVENT_HANGUP
58 };
59 
61 {
62  /*! Start an outgoing call. */
64  /*! Answer an incoming call. */
66  /*! Hangup a call. */
68  /*! Take the line off hook. */
70  /*! Put the line on hook. */
72  /*! Control V.24 Circuit 108, "data terminal ready". */
74  /*! Control V.24 Circuit 105, "request to send". */
76  /*! Control V.24 Circuit 106, "clear to send". */
78  /*! Control V.24 Circuit 109, "receive line signal detector" (i.e. carrier detect). */
80  /*! Control V.24 Circuit 125, "ring indicator". */
82  /*! Control V.24 Circuit 107, "data set ready". */
84  /*! Set the caller ID for outgoing calls. */
86  /* The remainder of the control functions should not get past the modem, to the
87  application. */
88  AT_MODEM_CONTROL_RESTART,
89  AT_MODEM_CONTROL_DTE_TIMEOUT
90 };
91 
92 enum
93 {
94  AT_RESPONSE_CODE_OK = 0,
95  AT_RESPONSE_CODE_CONNECT,
96  AT_RESPONSE_CODE_RING,
97  AT_RESPONSE_CODE_NO_CARRIER,
98  AT_RESPONSE_CODE_ERROR,
99  AT_RESPONSE_CODE_XXX,
100  AT_RESPONSE_CODE_NO_DIALTONE,
101  AT_RESPONSE_CODE_BUSY,
102  AT_RESPONSE_CODE_NO_ANSWER,
103  AT_RESPONSE_CODE_FCERROR,
104  AT_RESPONSE_CODE_FRH3
105 };
106 
107 typedef struct at_state_s at_state_t;
108 
109 typedef int (at_modem_control_handler_t)(at_state_t *s, void *user_data, int op, const char *num);
110 typedef int (at_tx_handler_t)(at_state_t *s, void *user_data, const uint8_t *buf, size_t len);
111 typedef int (at_class1_handler_t)(at_state_t *s, void *user_data, int direction, int operation, int val);
112 
113 /*!
114  AT profile.
115 */
116 typedef struct
117 {
118  /*! TRUE if character echo is enabled */
119  int echo;
120  /*! TRUE if verbose reporting is enabled */
121  int verbose;
122  /*! TRUE if result codes are verbose */
124  /*! TRUE if pulse dialling is the default */
126  /*! ??? */
128  /*! ??? */
130  /*! The state of all possible S registers */
131  uint8_t s_regs[100];
132 } at_profile_t;
133 
134 #if defined(__cplusplus)
135 extern "C"
136 {
137 #endif
138 
139 SPAN_DECLARE(void) at_set_at_rx_mode(at_state_t *s, int new_mode);
140 
141 SPAN_DECLARE(void) at_put_response(at_state_t *s, const char *t);
142 
143 SPAN_DECLARE(void) at_put_numeric_response(at_state_t *s, int val);
144 
145 SPAN_DECLARE(void) at_put_response_code(at_state_t *s, int code);
146 
147 SPAN_DECLARE(void) at_reset_call_info(at_state_t *s);
148 
149 /*! Set the call information for an AT interpreter.
150  \brief Set the call information for an AT interpreter.
151  \param s The AT interpreter context.
152  \param id .
153  \param value . */
154 SPAN_DECLARE(void) at_set_call_info(at_state_t *s, char const *id, char const *value);
155 
156 SPAN_DECLARE(void) at_display_call_info(at_state_t *s);
157 
158 SPAN_DECLARE(int) at_modem_control(at_state_t *s, int op, const char *num);
159 
160 SPAN_DECLARE(void) at_call_event(at_state_t *s, int event);
161 
162 SPAN_DECLARE(void) at_interpreter(at_state_t *s, const char *cmd, int len);
163 
164 SPAN_DECLARE(void) at_set_class1_handler(at_state_t *s, at_class1_handler_t handler, void *user_data);
165 
166 /*! Initialise an AT interpreter context.
167  \brief Initialise an AT interpreter context.
168  \param s The AT context.
169  \param at_tx_handler x.
170  \param at_tx_user_data x.
171  \param modem_control_handler x.
172  \param modem_control_user_data x.
173  \return A pointer to the AT context, or NULL if there was a problem. */
174 SPAN_DECLARE(at_state_t *) at_init(at_state_t *s,
175  at_tx_handler_t *at_tx_handler,
176  void *at_tx_user_data,
177  at_modem_control_handler_t *modem_control_handler,
178  void *modem_control_user_data);
179 
180 /*! Release an AT interpreter context.
181  \brief Release an AT interpreter context.
182  \param s The AT context.
183  \return 0 for OK */
184 SPAN_DECLARE(int) at_release(at_state_t *s);
185 
186 /*! Free an AT interpreter context.
187  \brief Free an AT interpreter context.
188  \param s The AT context.
189  \return 0 for OK */
190 SPAN_DECLARE(int) at_free(at_state_t *s);
191 
192 #if defined(__cplusplus)
193 }
194 #endif
195 
196 #endif
197 /*- End of file ------------------------------------------------------------*/
async_rx_state_s::parity_errors
int parity_errors
Definition: private/async.h:83
at_state_s::dte_inactivity_action
int dte_inactivity_action
Definition: private/at_interpreter.h:52
at_release
int at_release(at_state_t *s)
Release an AT interpreter context.
Definition: at_interpreter.c:5530
tone_generate.h
at_state_s::rx_signal_present
int rx_signal_present
TRUE if a carrier is presnt. Otherwise FALSE.
Definition: private/at_interpreter.h:108
at_profile_t::verbose
int verbose
Definition: at_interpreter.h:121
at_interpreter.h
AT_MODEM_CONTROL_ANSWER
@ AT_MODEM_CONTROL_ANSWER
Definition: at_interpreter.h:65
at_profile_t::pulse_dial
int pulse_dial
Definition: at_interpreter.h:125
at_profile_t
Definition: at_interpreter.h:117
AT_MODEM_CONTROL_CAR
@ AT_MODEM_CONTROL_CAR
Definition: at_interpreter.h:79
AT_MODEM_CONTROL_RNG
@ AT_MODEM_CONTROL_RNG
Definition: at_interpreter.h:81
async_tx_state_s::data_bits
int data_bits
The number of data bits per character.
Definition: private/async.h:37
async.h
hdlc.h
AT_MODEM_CONTROL_SETID
@ AT_MODEM_CONTROL_SETID
Definition: at_interpreter.h:85
at_set_call_info
void at_set_call_info(at_state_t *s, char const *id, char const *value)
Set the call information for an AT interpreter.
Definition: at_interpreter.c:328
at_init
at_state_t * at_init(at_state_t *s, at_tx_handler_t *at_tx_handler, void *at_tx_user_data, at_modem_control_handler_t *modem_control_handler, void *modem_control_user_data)
Initialise an AT interpreter context.
Definition: at_interpreter.c:5503
at_state_s::rlsd_behaviour
int rlsd_behaviour
Definition: private/at_interpreter.h:66
AT_MODEM_CONTROL_OFFHOOK
@ AT_MODEM_CONTROL_OFFHOOK
Definition: at_interpreter.h:69
at_state_s::dtr_behaviour
int dtr_behaviour
Definition: private/at_interpreter.h:68
async_tx_state_s::byte_in_progress
unsigned int byte_in_progress
A current, partially transmitted, character.
Definition: private/async.h:48
AT_MODEM_CONTROL_CALL
@ AT_MODEM_CONTROL_CALL
Definition: at_interpreter.h:63
at_modem_control_operation_e
at_modem_control_operation_e
Definition: at_interpreter.h:61
at_interpreter.h
async_tx_state_s::get_byte
get_byte_func_t get_byte
A pointer to the callback routine used to get characters to be transmitted.
Definition: private/async.h:43
AT_MODEM_CONTROL_RTS
@ AT_MODEM_CONTROL_RTS
Definition: at_interpreter.h:75
async_rx_state_s
Definition: private/async.h:61
complex.h
at_state_s::country_of_installation
int country_of_installation
Definition: private/at_interpreter.h:48
at_free
int at_free(at_state_t *s)
Free an AT interpreter context.
Definition: at_interpreter.c:5539
ASYNC_PARITY_EVEN
@ ASYNC_PARITY_EVEN
Definition: async.h:135
at_init
at_state_t * at_init(at_state_t *s, at_tx_handler_t *at_tx_handler, void *at_tx_user_data, at_modem_control_handler_t *modem_control_handler, void *modem_control_user_data)
Initialise an AT interpreter context.
Definition: at_interpreter.c:5503
async_tx_state_s
Definition: private/async.h:35
AT_MODEM_CONTROL_DTR
@ AT_MODEM_CONTROL_DTR
Definition: at_interpreter.h:73
ASYNC_PARITY_NONE
@ ASYNC_PARITY_NONE
Definition: async.h:133
at_call_id_s
Definition: private/at_interpreter.h:34
at_state_s::speaker_mode
int speaker_mode
Definition: private/at_interpreter.h:56
at_profile_t::double_escape
int double_escape
Definition: at_interpreter.h:127
at_state_s::dsr_option
int dsr_option
Definition: private/at_interpreter.h:74
at_state_s::fclass_mode
int fclass_mode
Definition: private/at_interpreter.h:99
at_state_s::dte_inactivity_timeout
int dte_inactivity_timeout
Definition: private/at_interpreter.h:50
queue.h
async_tx_state_s::parity
int parity
The type of parity.
Definition: private/async.h:39
at_profile_t::adaptive_receive
int adaptive_receive
Definition: at_interpreter.h:129
at_state_s::speaker_volume
int speaker_volume
Definition: private/at_interpreter.h:54
async_rx_init
async_rx_state_t * async_rx_init(async_rx_state_t *s, int data_bits, int parity, int stop_bits, int use_v14, put_byte_func_t put_byte, void *user_data)
Initialise an asynchronous data receiver context.
Definition: async.c:83
span_log
int span_log(logging_state_t *s, int level, const char *format,...)
Generate a log entry.
Definition: logging.c:84
at_set_call_info
void at_set_call_info(at_state_t *s, char const *id, char const *value)
Set the call information for an AT interpreter.
Definition: at_interpreter.c:328
at_release
int at_release(at_state_t *s)
Release an AT interpreter context.
Definition: at_interpreter.c:5530
AT_MODEM_CONTROL_DSR
@ AT_MODEM_CONTROL_DSR
Definition: at_interpreter.h:83
AT_MODEM_CONTROL_ONHOOK
@ AT_MODEM_CONTROL_ONHOOK
Definition: at_interpreter.h:71
at_state_s::logging
logging_state_t logging
Error and flow logging control.
Definition: private/at_interpreter.h:124
async_tx_state_s::user_data
void * user_data
An opaque pointer passed when calling get_byte.
Definition: private/async.h:45
at_profile_t::echo
int echo
Definition: at_interpreter.h:119
AT_MODEM_CONTROL_HANGUP
@ AT_MODEM_CONTROL_HANGUP
Definition: at_interpreter.h:67
async_tx_init
async_tx_state_t * async_tx_init(async_tx_state_t *s, int data_bits, int parity, int stop_bits, int use_v14, get_byte_func_t get_byte, void *user_data)
Initialise an asynchronous data transmit context.
Definition: async.c:208
at_state_s::carrier_loss_timeout
int carrier_loss_timeout
Definition: private/at_interpreter.h:70
at_state_s::tx_window
int tx_window
Definition: private/at_interpreter.h:82
fsk.h
logging.h
at_state_s::dte_rate
int dte_rate
Definition: private/at_interpreter.h:60
at_state_s::dte_parity
int dte_parity
Definition: private/at_interpreter.h:64
ASYNC_PARITY_ODD
@ ASYNC_PARITY_ODD
Definition: async.h:137
at_state_s::long_space_disconnect_option
int long_space_disconnect_option
Definition: private/at_interpreter.h:76
async_tx_state_s::stop_bits
int stop_bits
The number of stop bits per character.
Definition: private/async.h:41
at_free
int at_free(at_state_t *s)
Free an AT interpreter context.
Definition: at_interpreter.c:5539
async_tx_state_s::bitpos
int bitpos
The current bit position within a partially transmitted character.
Definition: private/async.h:50
async_tx_state_s::parity_bit
int parity_bit
Parity bit.
Definition: private/async.h:52
at_profile_t::s_regs
uint8_t s_regs[100]
Definition: at_interpreter.h:131
at_profile_t::result_code_format
int result_code_format
Definition: at_interpreter.h:123
at_state_s::rx_window
int rx_window
Definition: private/at_interpreter.h:80
async_rx_state_s::framing_errors
int framing_errors
Definition: private/async.h:85
at_state_s::result_code_mode
int result_code_mode
Definition: private/at_interpreter.h:72
at_state_s
Definition: private/at_interpreter.h:45
at_state_s::dte_char_format
int dte_char_format
Definition: private/at_interpreter.h:62
at_state_s::sync_tx_clock_source
int sync_tx_clock_source
Definition: private/at_interpreter.h:78
fax_modems.h
AT_MODEM_CONTROL_CTS
@ AT_MODEM_CONTROL_CTS
Definition: at_interpreter.h:77