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