1/* //device/system/reference-ril/atchannel.h
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ATCHANNEL_H
19#define ATCHANNEL_H 1
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/* define AT_DEBUG to send AT traffic to /tmp/radio-at.log" */
26#define AT_DEBUG  0
27
28#if AT_DEBUG
29extern void  AT_DUMP(const char* prefix, const char*  buff, int  len);
30#else
31#define  AT_DUMP(prefix,buff,len)  do{}while(0)
32#endif
33
34#define AT_ERROR_GENERIC -1
35#define AT_ERROR_COMMAND_PENDING -2
36#define AT_ERROR_CHANNEL_CLOSED -3
37#define AT_ERROR_TIMEOUT -4
38#define AT_ERROR_INVALID_THREAD -5 /* AT commands may not be issued from
39                                       reader thread (or unsolicited response
40                                       callback */
41#define AT_ERROR_INVALID_RESPONSE -6 /* eg an at_send_command_singleline that
42                                        did not get back an intermediate
43                                        response */
44
45
46typedef enum {
47    NO_RESULT,   /* no intermediate response expected */
48    NUMERIC,     /* a single intermediate response starting with a 0-9 */
49    SINGLELINE,  /* a single intermediate response starting with a prefix */
50    MULTILINE    /* multiple line intermediate response
51                    starting with a prefix */
52} ATCommandType;
53
54/** a singly-lined list of intermediate responses */
55typedef struct ATLine  {
56    struct ATLine *p_next;
57    char *line;
58} ATLine;
59
60/** Free this with at_response_free() */
61typedef struct {
62    int success;              /* true if final response indicates
63                                    success (eg "OK") */
64    char *finalResponse;      /* eg OK, ERROR */
65    ATLine  *p_intermediates; /* any intermediate responses */
66} ATResponse;
67
68/**
69 * a user-provided unsolicited response handler function
70 * this will be called from the reader thread, so do not block
71 * "s" is the line, and "sms_pdu" is either NULL or the PDU response
72 * for multi-line TS 27.005 SMS PDU responses (eg +CMT:)
73 */
74typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu);
75
76int at_open(int fd, ATUnsolHandler h);
77void at_close();
78
79/* This callback is invoked on the command thread.
80   You should reset or handshake here to avoid getting out of sync */
81void at_set_on_timeout(void (*onTimeout)(void));
82/* This callback is invoked on the reader thread (like ATUnsolHandler)
83   when the input stream closes before you call at_close
84   (not when you call at_close())
85   You should still call at_close()
86   It may also be invoked immediately from the current thread if the read
87   channel is already closed */
88void at_set_on_reader_closed(void (*onClose)(void));
89
90int at_send_command_singleline (const char *command,
91                                const char *responsePrefix,
92                                 ATResponse **pp_outResponse);
93
94int at_send_command_numeric (const char *command,
95                                 ATResponse **pp_outResponse);
96
97int at_send_command_multiline (const char *command,
98                                const char *responsePrefix,
99                                 ATResponse **pp_outResponse);
100
101
102int at_handshake();
103
104int at_send_command (const char *command, ATResponse **pp_outResponse);
105
106int at_send_command_sms (const char *command, const char *pdu,
107                            const char *responsePrefix,
108                            ATResponse **pp_outResponse);
109
110void at_response_free(ATResponse *p_response);
111
112typedef enum {
113    CME_ERROR_NON_CME = -1,
114    CME_SUCCESS = 0,
115    CME_SIM_NOT_INSERTED = 10
116} AT_CME_Error;
117
118AT_CME_Error at_get_cme_error(const ATResponse *p_response);
119
120#ifdef __cplusplus
121}
122#endif
123
124#endif /*ATCHANNEL_H*/
125