blob: add0fdcc8c0e4da8073f676be81f8671bfdadb0b [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +08001#ifndef MBTK_INFO_INCLUDE
2#define MBTK_INFO_INCLUDE
3#include <netinet/in.h>
4#include <pthread.h>
5
6#include "mbtk_type.h"
7#include "mbtk_list.h"
8#include "mbtk_log.h"
9#include "mbtk_utils.h"
10#include "mbtk_ril_api.h"
11
12#define RIL_SOCK_PACKET_TAG 0x5F6F7F8F
13#define RIL_SOCK_NAME "/tmp/mbtk_ril_sock"
b.liu10a34102024-08-20 20:36:24 +080014#define RIL_SOCK_MSG_LEN_MAX (1024 * 6)
b.liu87afc4c2024-08-14 17:33:45 +080015
b.liu15f456b2024-10-31 20:16:06 +080016#define IND_REGISTER_MAX 20
17#define PACK_PROCESS_QUEUE_MAX 20
18
19
b.liu87afc4c2024-08-14 17:33:45 +080020// Tag(4) + Packet_Length(2)
21#define RIL_SOCK_PACK_EXTRA_LEN 6
b.liub171c9a2024-11-12 19:23:29 +080022// RIL_SOCK_PACK_EXTRA_LEN + at_port(1) + Index(2) + Type(2) + Id(2) + Error(2) + data_len(2)
23#define RIL_SOCK_PACK_LEN_MIN (RIL_SOCK_PACK_EXTRA_LEN + 11)
b.liu87afc4c2024-08-14 17:33:45 +080024
25#define RIL_MSG_INDEX_AUTO (-1) // automatically , refor to : ril_index
26#define RIL_MSG_INDEX_INVALID (0) // Invalid msg index.
27
28typedef enum
29{
30 RIL_MSG_TYPE_REQ,
31 RIL_MSG_TYPE_RSP,
32 RIL_MSG_TYPE_IND
33} ril_msg_type_enum;
34
35typedef enum
36{
37 // Device Information
b.liu15f456b2024-10-31 20:16:06 +080038 RIL_MSG_ID_DEV_BEGIN = 0x0,
b.liu87afc4c2024-08-14 17:33:45 +080039 // <string> IMEI
40 RIL_MSG_ID_DEV_IMEI,
41 // <string> SN
42 RIL_MSG_ID_DEV_SN,
43 // <string> MEID
44 RIL_MSG_ID_DEV_MEID,
45 // <string> VERSION
46 RIL_MSG_ID_DEV_VERSION,
47 // <string> MODEL
48 RIL_MSG_ID_DEV_MODEL,
49 // <uint8> 0:Close 1:Open
50 RIL_MSG_ID_DEV_VOLTE,
51 // <string> Temperature
52 RIL_MSG_ID_DEV_TEMP, // Temperature
53 // <string> 23/03/20,01:58:00+32
54 RIL_MSG_ID_DEV_CELL_TIME, // Time
55 // <uint8><uint8>
56 RIL_MSG_ID_DEV_MODEM,
57
58 RIL_MSG_ID_DEV_END,
59
60 // Sim Information
b.liu15f456b2024-10-31 20:16:06 +080061 RIL_MSG_ID_SIM_BEGIN = 0x100,
b.liu87afc4c2024-08-14 17:33:45 +080062 // <uint8> 0:NOT_EXIST 1:READY ...
63 RIL_MSG_ID_SIM_STATE,
64 // <uint8> 0: SIM 1: USIM 2: TEST SIM 3: TEST USIM 4: UNKNOWN
65 RIL_MSG_ID_SIM_TYPE,
66 // <string> IMSI
67 RIL_MSG_ID_SIM_IMSI,
68 // <string> ICCID
69 RIL_MSG_ID_SIM_ICCID,
70 // <string> Phone Number
71 RIL_MSG_ID_SIM_PN,
72 // <string> PUK
73 RIL_MSG_ID_SIM_LOCK,
74 // <uint8> <uint8> <uint8> <uint8> PIN PUK LAST TIMES
75 RIL_MSG_ID_SIM_PINPUK_TIMES,
76 // <string> PLMN
77 RIL_MSG_ID_SIM_PLMN,
78
79 RIL_MSG_ID_SIM_END,
80
81 // Network Information
b.liu15f456b2024-10-31 20:16:06 +080082 RIL_MSG_ID_NET_BEGIN = 0x200,
b.liu87afc4c2024-08-14 17:33:45 +080083 // sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
84 RIL_MSG_ID_NET_AVAILABLE,
85 // <uint8> 0: automatic 1: manual
86 // or
87 // sel_mode(uint8)type(uint8)plmn(uint32)
88 RIL_MSG_ID_NET_SEL_MODE,
89 // mbtk_band_info_t
90 RIL_MSG_ID_NET_BAND,
91 // mbtk_signal_info_t
92 RIL_MSG_ID_NET_SIGNAL,
93 // mbtk_net_reg_info_t
94 RIL_MSG_ID_NET_REG,
95 // mbtk_cell_info_t[]
96 RIL_MSG_ID_NET_CELL,
b.liu557c81d2024-11-19 16:52:45 +080097 // mbtk_ril_oos_info_t
98 RIL_MSG_ID_NET_OOS,
b.liu15f456b2024-10-31 20:16:06 +080099
100 RIL_MSG_ID_NET_END,
101
102
103 // Network Information
104 RIL_MSG_ID_DATA_CALL_BEGIN = 0x300,
b.liu87afc4c2024-08-14 17:33:45 +0800105 // mbtk_apn_info_t
b.liu15f456b2024-10-31 20:16:06 +0800106 RIL_MSG_ID_DATA_CALL_APN,
b.liu87afc4c2024-08-14 17:33:45 +0800107 // REQ:
108 // <call_type[1]><cid[1]><timeout[1]>
109 // call_type : mbtk_data_call_type_enum
110 // cid : 1 - 15
111 // timeout : second
112 // RSP:
113 // <type[1]><ipv4><ipv6>
114 // type : 0-IPV4 1-IPV6 2-IPV4V6
115 // ipv4 : mbtk_ipv4_info_t
116 // ipv6 : mbtk_ipv6_info_t
b.liu15f456b2024-10-31 20:16:06 +0800117 RIL_MSG_ID_DATA_CALL_OPT,
b.liu87afc4c2024-08-14 17:33:45 +0800118
b.liu15f456b2024-10-31 20:16:06 +0800119 RIL_MSG_ID_DATA_CALL_END,
b.liu87afc4c2024-08-14 17:33:45 +0800120
121
122 // Call Information
b.liu15f456b2024-10-31 20:16:06 +0800123 RIL_MSG_ID_CALL_BEGIN = 0x400,
b.liu87afc4c2024-08-14 17:33:45 +0800124 RIL_MSG_ID_CALL_STATE,
125
126 // Start call.
127 RIL_MSG_ID_CALL_START,
128 //answer call
129 RIL_MSG_ID_CALL_ANSWER,
130 //hang up all call
131 RIL_MSG_ID_CALL_HANGUP,
132 //hang up a call
133 RIL_MSG_ID_CALL_HANGUP_A,
134 //hang up waiting or background call
135 RIL_MSG_ID_CALL_HANGUP_B,
136 //hang up foreground resume background
137 RIL_MSG_ID_CALL_HANGUP_C,
138 //wait in call
139 RIL_MSG_ID_CALL_WAITIN,
140 //mute call
141 RIL_MSG_ID_CALL_MUTE,
142 //dtmf call
143 RIL_MSG_ID_CALL_DTMF,
144 RIL_MSG_ID_CALL_END,
145
146 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800147 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800148 RIL_MSG_ID_SMS_STATE,
149 RIL_MSG_ID_SMS_CMGF,
150 RIL_MSG_ID_SMS_CPMS,
151 RIL_MSG_ID_SMS_CMGS,
152 RIL_MSG_ID_SMS_CMSS,
153 RIL_MSG_ID_SMS_CMGR,
154 RIL_MSG_ID_SMS_CMGW,
155 RIL_MSG_ID_SMS_CMGD,
156 RIL_MSG_ID_SMS_CMGL,
157 RIL_MSG_ID_SMS_CSCA,
158 RIL_MSG_ID_SMS_CSMP,
159 RIL_MSG_ID_SMS_CSCB,
160 RIL_MSG_ID_SMS_CNMI,
161
162 RIL_MSG_ID_SMS_END,
163
164 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800165 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800166 RIL_MSG_ID_PB_STATE,
167
168 RIL_MSG_ID_PB_END,
169
b.liu15f456b2024-10-31 20:16:06 +0800170 // Ecall Information
171 RIL_MSG_ID_ECALL_BEGIN = 0x700,
172 // mbtk_ecall_msd_cfg_info_t
173 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800174 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800175 RIL_MSG_ID_ECALL_MSDGEN,
176 // uint8[]
177 RIL_MSG_ID_ECALL_MSD,
178 // NULL
179 RIL_MSG_ID_ECALL_PUSH,
180 // mbtk_ecall_only_info_t
181 RIL_MSG_ID_ECALL_ONLY,
182 // reg <uint8>
183 RIL_MSG_ID_ECALL_REG,
184 // mbtk_ecall_dial_type_enum
185 RIL_MSG_ID_ECALL_DIAL,
186 // mbtk_ecall_mode_type_enum
187 RIL_MSG_ID_ECALL_MODE,
188 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
189 RIL_MSG_ID_ECALL_CFG,
190 // uint8[]
191 RIL_MSG_ID_ECALL_SMS_NUM,
192 // uint8
193 RIL_MSG_ID_ECALL_MUTESPK,
194 // mbtk_ecall_gain_info_t
195 RIL_MSG_ID_ECALL_DSP_GAIN,
196
197 RIL_MSG_ID_ECALL_END,
198
199 // IND Information
200 RIL_MSG_ID_IND_BEGIN = 0x1000,
201 // mbtk_ril_ser_state_enum
202 RIL_MSG_ID_IND_SER_STATE_CHANGE,
203 // mbtk_ril_net_reg_state_info_t
204 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800205 // <uint8> State
206 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
207 // <uint8> State
208 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800209 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800210 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800211 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800212 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800213 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800214 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800215 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800216 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800217 // mbtk_ril_ecall_state_info_t
218 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800219
220
221 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800222
223 // URC message
224 RIL_URC_MSG_BEGIN = 0x2000,
225 RIL_URC_MSG_GET_SIM_STATE, //check sim status
226 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
227 RIL_URC_MSG_END,
228
229 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800230} ril_msg_id_enum;
231
232typedef struct {
233 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
234 uint16 msg_len;
235
b.liub171c9a2024-11-12 19:23:29 +0800236 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800237 uint16 msg_index; // Message index(Start from 1)
238 // 0 : For unknown msg id
239 uint16 msg_type; // Refor to : ril_msg_type_enum
240 uint16 msg_id; // Refor to : ril_msg_id_enum
241 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
242 uint16 data_len;
243 uint8 *data;
244} __attribute__((packed)) ril_msg_pack_info_t;
245
246typedef struct {
247 pthread_t pid;
248 char name[20];
249 bool is_waitting;
250 pthread_cond_t cond;
251 pthread_mutex_t mutex;
252} ril_cli_thread_info_t;
253
254typedef struct {
255 pthread_t pid;
256 bool is_async;
257 int *rsp_data_len; // Save response data length.
258 char *rsp_data; // Save response date.
259 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
260 ril_msg_pack_info_t *pack;
261} ril_msg_info_t;
262
263/*
264GSM band��
265 1 �C PGSM 900 (standard or primary)
266 2 �C DCS GSM 1800
267 4 �C PCS GSM 1900
268 8 �C EGSM 900 (extended)
269 16 �C GSM 450
270 32 �C GSM 480
271 64 �C GSM 850
272 512 - BAND_LOCK_BIT // used for GSM band setting
273*/
274typedef enum
275{
276 MBTK_GSM_BAND_PGSM_900 = 1,
277 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
278 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
279 MBTK_GSM_BAND_EGSM_900 = 8,
280 MBTK_GSM_BAND_GSM_450 = 16,
281 MBTK_GSM_BAND_GSM_480 = 32,
282 MBTK_GSM_BAND_GSM_850 = 64,
283 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
284} mbtk_gsm_band_enum;
285
286/*
287UMTS band��
288 1 �C UMTS_BAND_1
289 2 �C UMTS_BAND_2
290 4 �C UMTS_BAND_3
291 8 �C UMTS_BAND_4
292 16 �C UMTS_BAND_5
293 32 �C UMTS_BAND_6
294 64 �C UMTS_BAND_7
295 128 �C UMTS_BAND_8
296 256 �C UMTS_BAND_9
297*/
298typedef enum
299{
300 MBTK_UMTS_BAND_1 = 1,
301 MBTK_UMTS_BAND_2 = 2,
302 MBTK_UMTS_BAND_3 = 4,
303 MBTK_UMTS_BAND_4 = 8,
304 MBTK_UMTS_BAND_5 = 16,
305 MBTK_UMTS_BAND_6 = 32,
306 MBTK_UMTS_BAND_7 = 64,
307 MBTK_UMTS_BAND_8 = 128,
308 MBTK_UMTS_BAND_9 = 256
309} mbtk_umts_band_enum;
310
311/*
312LTEbandH(TDD-LTE band)
313 32 �C TDLTE_BAND_38
314 64 �C TDLTE_BAND_39
315 128 �C TDLTE_BAND_40
316 256 �C TDLTE_BAND_41
317*/
318typedef enum
319{
320 MBTK_TDLTE_BAND_38 = 32,
321 MBTK_TDLTE_BAND_39 = 64,
322 MBTK_TDLTE_BAND_40 = 128,
323 MBTK_TDLTE_BAND_41 = 256
324} mbtk_tdlte_band_enum;
325
326/*
327LTEbandL(FDD-LTE band)
328 1 �C FDDLTE_BAND_1
329 4 �C FDDLTE _BAND_3
330 8 �C FDDLTE _BAND_4
331 64 �C FDDLTE _BAND_7
332 65536 �C FDDLTE _BAND_17
333 524288 �C FDDLTE _BAND_20
334*/
335typedef enum
336{
337 MBTK_FDDLTE_BAND_1 = 1,
338 MBTK_FDDLTE_BAND_3 = 4,
339 MBTK_FDDLTE_BAND_4 = 8,
340 MBTK_FDDLTE_BAND_7 = 64,
341 MBTK_FDDLTE_BAND_17 = 65536,
342 MBTK_FDDLTE_BAND_20 = 524288
343} mbtk_fddlte_band_enum;
344
345typedef enum
346{
347 MBTK_LTE_EXT_BAND_65 = 1,
348 MBTK_LTE_EXT_BAND_66 = 2,
349 MBTK_LTE_EXT_BAND_67 = 4,
350 MBTK_LTE_EXT_BAND_68 = 8,
351 MBTK_LTE_EXT_BAND_69 = 16
352} mbtk_lte_ext_band_enum;
353
b.liub4772072024-08-15 14:47:03 +0800354typedef struct
355{
356 uint8 type; // 0: GSM 1: UMTS 2: LTE
357 bool running;
358
359 int cell_num;
360 mbtk_cell_info_t cell[CELL_NUM_MAX];
361} mbtK_cell_pack_info_t;
362
b.liu87afc4c2024-08-14 17:33:45 +0800363#ifdef __cplusplus
364extern "C" {
365#endif
366
367char* type2str(ril_msg_type_enum type);
368
369char* apn2str(mbtk_ip_type_enum type);
370
371/*
372IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
373*/
374int str_2_ipv6(const void *ip_str, void *ipv6);
375
376/*
377IPv6 : uint128 -> fe80::215:1dff:fe81:484c
378*/
379int ipv6_2_str(const void *ipv6, void *ipv6_str);
380
381char* id2str(int id);
382
383char* err2str(mbtk_ril_err_enum err);
384
385void *mbtk_memcpy(const void *src, unsigned int n);
386
387/*
3880 GSM
3891 GSM_COMPACT
3902 UTRAN
3913 GSM_EGPRS
3924 UTRAN_HSDPA
3935 UTRAN_HSUPA
3946 UTRAN_HSDPA_HSUPA
3957 EUTRAN
3968 ECGSM
397*/
398mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
399
400void ril_msg_pack_free(ril_msg_pack_info_t* pack);
401
b.liub171c9a2024-11-12 19:23:29 +0800402ril_msg_pack_info_t* ril_msg_pack_creat(ATPortType_enum port, int msg_type, int msg_id, int msg_index, const void *data, int data_len);
b.liu87afc4c2024-08-14 17:33:45 +0800403
404int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
405
406ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
407
408#ifdef __cplusplus
409}
410#endif
411
412
413#endif /* MBTK_INFO_INCLUDE */
414
415