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 22 extern "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 29 extern 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 46 typedef 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 */ 55 typedef struct ATLine { 56 struct ATLine *p_next; 57 char *line; 58 } ATLine; 59 60 /** Free this with at_response_free() */ 61 typedef 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 */ 74 typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu); 75 76 int at_open(int fd, ATUnsolHandler h); 77 void 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 */ 81 void 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 */ 88 void at_set_on_reader_closed(void (*onClose)(void)); 89 90 int at_send_command_singleline (const char *command, 91 const char *responsePrefix, 92 ATResponse **pp_outResponse); 93 94 int at_send_command_numeric (const char *command, 95 ATResponse **pp_outResponse); 96 97 int at_send_command_multiline (const char *command, 98 const char *responsePrefix, 99 ATResponse **pp_outResponse); 100 101 int at_send_command_raw (const char *command, 102 const char *raw_data, unsigned int raw_len, 103 const char *responsePrefix, 104 ATResponse **pp_outResponse); 105 106 int at_handshake(); 107 108 int at_send_command (const char *command, ATResponse **pp_outResponse); 109 110 int at_send_command_sms (const char *command, const char *pdu, 111 const char *responsePrefix, 112 ATResponse **pp_outResponse); 113 114 void at_response_free(ATResponse *p_response); 115 116 int strStartsWith(const char *line, const char *prefix); 117 118 typedef enum { 119 CME_ERROR_NON_CME = -1, 120 CME_SUCCESS = 0, 121 122 CME_OPERATION_NOT_ALLOWED = 3, 123 CME_OPERATION_NOT_SUPPORTED = 4, 124 CME_PH_SIM_PIN= 5, 125 CME_PH_FSIM_PIN = 6, 126 CME_PH_FSIM_PUK = 7, 127 CME_SIM_NOT_INSERTED =10, 128 CME_SIM_PIN_REQUIRED = 11, 129 CME_SIM_PUK_REQUIRED = 12, 130 CME_FAILURE = 13, 131 CME_SIM_BUSY = 14, 132 CME_SIM_WRONG = 15, 133 CME_INCORRECT_PASSWORD = 16, 134 CME_SIM_PIN2_REQUIRED = 17, 135 CME_SIM_PUK2_REQUIRED = 18, 136 CME_MEMORY_FULL = 20, 137 CME_INVALID_INDEX = 21, 138 CME_NOT_FOUND = 22, 139 CME_MEMORY_FAILURE = 23, 140 CME_STRING_TO_LONG = 24, 141 CME_INVALID_CHAR = 25, 142 CME_DIALSTR_TO_LONG = 26, 143 CME_INVALID_DIALCHAR = 27, 144 } AT_CME_Error; 145 146 AT_CME_Error at_get_cme_error(const ATResponse *p_response); 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif /*ATCHANNEL_H*/ 153