b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 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 | #include "mbtk_type.h" |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 25 | #include "mbtk_ril_api.h" |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 26 | |
| 27 | /* define AT_DEBUG to send AT traffic to /tmp/radio-at.log" */ |
| 28 | #define AT_DEBUG 0 |
| 29 | |
| 30 | #if AT_DEBUG |
| 31 | extern void AT_DUMP(const char* prefix, const char* buff, int len); |
| 32 | #else |
| 33 | #define AT_DUMP(prefix,buff,len) do{}while(0) |
| 34 | #endif |
| 35 | |
| 36 | #define AT_ERROR_GENERIC (-1) |
| 37 | #define AT_ERROR_COMMAND_PENDING (-2) |
| 38 | #define AT_ERROR_CHANNEL_CLOSED (-3) |
| 39 | #define AT_ERROR_TIMEOUT (-4) |
| 40 | #define AT_ERROR_INVALID_THREAD (-5) /* AT commands may not be issued from |
| 41 | reader thread (or unsolicited response |
| 42 | callback */ |
| 43 | #define AT_ERROR_INVALID_RESPONSE (-6) /* eg an at_send_command_singleline that |
| 44 | did not get back an intermediate |
| 45 | response */ |
| 46 | #define AT_ERROR_TIMEOUT_CLOSE (-7) |
| 47 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 48 | typedef enum |
| 49 | { |
| 50 | NO_RESULT, /* no intermediate response expected */ |
| 51 | NUMERIC, /* a single intermediate response starting with a 0-9 */ |
| 52 | SINGLELINE, /* a single intermediate response starting with a prefix */ |
| 53 | MULTILINE /* multiple line intermediate response |
| 54 | starting with a prefix */ |
| 55 | } ATCommandType; |
| 56 | |
| 57 | /** a singly-lined list of intermediate responses */ |
| 58 | typedef struct ATLine |
| 59 | { |
| 60 | struct ATLine *p_next; |
| 61 | char *line; |
| 62 | } ATLine; |
| 63 | |
| 64 | /** Free this with at_response_free() */ |
| 65 | typedef struct |
| 66 | { |
| 67 | int success; /* true if final response indicates |
| 68 | success (eg "OK") */ |
| 69 | char *finalResponse; /* eg OK, ERROR */ |
| 70 | ATLine *p_intermediates; /* any intermediate responses */ |
| 71 | } ATResponse; |
| 72 | |
| 73 | typedef enum |
| 74 | { |
| 75 | RIL_AT_STATE_CLOSED = 0, |
| 76 | RIL_AT_STATE_OPENED, |
| 77 | RIL_AT_STATE_CONNECTED, |
| 78 | RIL_AT_STATE_READY, |
| 79 | RIL_AT_STATE_BUSY |
| 80 | } mbtk_ril_at_state_enum; |
| 81 | |
| 82 | /** |
| 83 | * a user-provided unsolicited response handler function |
| 84 | * this will be called from the reader thread, so do not block |
| 85 | * "s" is the line, and "sms_pdu" is either NULL or the PDU response |
| 86 | * for multi-line TS 27.005 SMS PDU responses (eg +CMT:) |
| 87 | */ |
| 88 | typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu); |
| 89 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 90 | int at_open(ATPortId_enum port, int at_fd, int uart_fd, ATUnsolHandler h); |
| 91 | void at_close(ATPortId_enum port); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 92 | |
| 93 | /* This callback is invoked on the command thread. |
| 94 | You should reset or handshake here to avoid getting out of sync */ |
| 95 | void at_set_on_timeout(void (*onTimeout)(void)); |
| 96 | /* This callback is invoked on the reader thread (like ATUnsolHandler) |
| 97 | when the input stream closes before you call at_close |
| 98 | (not when you call at_close()) |
| 99 | You should still call at_close() |
| 100 | It may also be invoked immediately from the current thread if the read |
| 101 | channel is already closed */ |
| 102 | void at_set_on_reader_closed(void (*onClose)(void)); |
| 103 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 104 | int at_send_command_singleline (ATPortId_enum port, const char *command, |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 105 | const char *responsePrefix, |
| 106 | ATResponse **pp_outResponse); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 107 | int at_send_command_singleline_with_timeout (ATPortId_enum port, const char *command, |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 108 | const char *responsePrefix, |
| 109 | ATResponse **pp_outResponse,long long timeoutMsec); |
| 110 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 111 | int at_send_command_numeric (ATPortId_enum port, const char *command, |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 112 | ATResponse **pp_outResponse); |
| 113 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 114 | int at_send_command_multiline (ATPortId_enum port, const char *command, |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 115 | const char *responsePrefix, |
| 116 | ATResponse **pp_outResponse); |
| 117 | |
| 118 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 119 | int at_handshake(ATPortId_enum port); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 120 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 121 | int at_send_command (ATPortId_enum port, const char *command, ATResponse **pp_outResponse); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 122 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 123 | int at_send_command_sms (ATPortId_enum port, const char *command, const char *pdu, |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 124 | const char *responsePrefix, |
| 125 | ATResponse **pp_outResponse); |
| 126 | |
| 127 | void at_response_free(ATResponse *p_response); |
| 128 | |
| 129 | typedef enum |
| 130 | { |
| 131 | CME_ERROR_NON_CME = -1, |
| 132 | CME_SUCCESS = 0, |
| 133 | CME_SIM_NOT_INSERTED = 10, |
| 134 | CME_ERROR_UNKNOWN |
| 135 | } AT_CME_Error; |
| 136 | |
| 137 | AT_CME_Error at_get_cme_error(const ATResponse *p_response); |
| 138 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 139 | mbtk_ril_at_state_enum at_state_get(ATPortId_enum port); |
| 140 | void at_state_set(ATPortId_enum port, mbtk_ril_at_state_enum state); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 141 | bool at_rsp_check(ATResponse *p_response); |
| 142 | |
| 143 | #ifdef __cplusplus |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #endif /*ATCHANNEL_H*/ |
| 148 | |