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