blob: 997ef33e518eb4943de0a9a64838bd40b2052c5a [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +08001/* //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#include "mbtk_type.h"
b.liub171c9a2024-11-12 19:23:29 +080025#include "mbtk_ril_api.h"
b.liu87afc4c2024-08-14 17:33:45 +080026
27/* define AT_DEBUG to send AT traffic to /tmp/radio-at.log" */
28#define AT_DEBUG 0
29
30#if AT_DEBUG
31extern 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.liu87afc4c2024-08-14 17:33:45 +080048typedef 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 */
58typedef struct ATLine
59{
60 struct ATLine *p_next;
61 char *line;
62} ATLine;
63
64/** Free this with at_response_free() */
65typedef 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
73typedef 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 */
88typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu);
89
b.liu7ca612c2025-04-25 09:23:36 +080090int at_open(ATPortId_enum port, int at_fd, int uart_fd, ATUnsolHandler h);
91void at_close(ATPortId_enum port);
b.liu87afc4c2024-08-14 17:33:45 +080092
93/* This callback is invoked on the command thread.
94 You should reset or handshake here to avoid getting out of sync */
95void 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 */
102void at_set_on_reader_closed(void (*onClose)(void));
103
b.liu7ca612c2025-04-25 09:23:36 +0800104int at_send_command_singleline (ATPortId_enum port, const char *command,
b.liu87afc4c2024-08-14 17:33:45 +0800105 const char *responsePrefix,
106 ATResponse **pp_outResponse);
b.liu7ca612c2025-04-25 09:23:36 +0800107int at_send_command_singleline_with_timeout (ATPortId_enum port, const char *command,
b.liu87afc4c2024-08-14 17:33:45 +0800108 const char *responsePrefix,
109 ATResponse **pp_outResponse,long long timeoutMsec);
110
b.liu7ca612c2025-04-25 09:23:36 +0800111int at_send_command_numeric (ATPortId_enum port, const char *command,
b.liu87afc4c2024-08-14 17:33:45 +0800112 ATResponse **pp_outResponse);
113
b.liu7ca612c2025-04-25 09:23:36 +0800114int at_send_command_multiline (ATPortId_enum port, const char *command,
b.liu87afc4c2024-08-14 17:33:45 +0800115 const char *responsePrefix,
116 ATResponse **pp_outResponse);
117
118
b.liu7ca612c2025-04-25 09:23:36 +0800119int at_handshake(ATPortId_enum port);
b.liu87afc4c2024-08-14 17:33:45 +0800120
b.liu7ca612c2025-04-25 09:23:36 +0800121int at_send_command (ATPortId_enum port, const char *command, ATResponse **pp_outResponse);
b.liu87afc4c2024-08-14 17:33:45 +0800122
b.liu7ca612c2025-04-25 09:23:36 +0800123int at_send_command_sms (ATPortId_enum port, const char *command, const char *pdu,
b.liu87afc4c2024-08-14 17:33:45 +0800124 const char *responsePrefix,
125 ATResponse **pp_outResponse);
126
127void at_response_free(ATResponse *p_response);
128
129typedef 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
137AT_CME_Error at_get_cme_error(const ATResponse *p_response);
138
b.liu7ca612c2025-04-25 09:23:36 +0800139mbtk_ril_at_state_enum at_state_get(ATPortId_enum port);
140void at_state_set(ATPortId_enum port, mbtk_ril_at_state_enum state);
b.liu87afc4c2024-08-14 17:33:45 +0800141bool at_rsp_check(ATResponse *p_response);
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /*ATCHANNEL_H*/
148