blob: 3ad1dd436f24b343b3bf1546f0439f40da383a38 [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>
b.liu6917e9b2025-03-26 17:23:11 +08005#include <time.h>
b.liu87afc4c2024-08-14 17:33:45 +08006
7#include "mbtk_type.h"
8#include "mbtk_list.h"
9#include "mbtk_log.h"
10#include "mbtk_utils.h"
11#include "mbtk_ril_api.h"
12
13#define RIL_SOCK_PACKET_TAG 0x5F6F7F8F
14#define RIL_SOCK_NAME "/tmp/mbtk_ril_sock"
b.liu10a34102024-08-20 20:36:24 +080015#define RIL_SOCK_MSG_LEN_MAX (1024 * 6)
b.liu87afc4c2024-08-14 17:33:45 +080016
b.liu15f456b2024-10-31 20:16:06 +080017#define IND_REGISTER_MAX 20
18#define PACK_PROCESS_QUEUE_MAX 20
19
20
b.liu87afc4c2024-08-14 17:33:45 +080021// Tag(4) + Packet_Length(2)
22#define RIL_SOCK_PACK_EXTRA_LEN 6
b.liub171c9a2024-11-12 19:23:29 +080023// RIL_SOCK_PACK_EXTRA_LEN + at_port(1) + Index(2) + Type(2) + Id(2) + Error(2) + data_len(2)
24#define RIL_SOCK_PACK_LEN_MIN (RIL_SOCK_PACK_EXTRA_LEN + 11)
b.liu87afc4c2024-08-14 17:33:45 +080025
26#define RIL_MSG_INDEX_AUTO (-1) // automatically , refor to : ril_index
27#define RIL_MSG_INDEX_INVALID (0) // Invalid msg index.
28
29typedef enum
30{
31 RIL_MSG_TYPE_REQ,
32 RIL_MSG_TYPE_RSP,
33 RIL_MSG_TYPE_IND
34} ril_msg_type_enum;
35
36typedef enum
37{
38 // Device Information
b.liu15f456b2024-10-31 20:16:06 +080039 RIL_MSG_ID_DEV_BEGIN = 0x0,
b.liu87afc4c2024-08-14 17:33:45 +080040 // <string> IMEI
41 RIL_MSG_ID_DEV_IMEI,
42 // <string> SN
43 RIL_MSG_ID_DEV_SN,
44 // <string> MEID
45 RIL_MSG_ID_DEV_MEID,
46 // <string> VERSION
47 RIL_MSG_ID_DEV_VERSION,
48 // <string> MODEL
49 RIL_MSG_ID_DEV_MODEL,
50 // <uint8> 0:Close 1:Open
51 RIL_MSG_ID_DEV_VOLTE,
52 // <string> Temperature
53 RIL_MSG_ID_DEV_TEMP, // Temperature
54 // <string> 23/03/20,01:58:00+32
55 RIL_MSG_ID_DEV_CELL_TIME, // Time
56 // <uint8><uint8>
57 RIL_MSG_ID_DEV_MODEM,
b.liu9c19cc62024-11-28 09:43:02 +080058 // <uint8>
59 RIL_MSG_ID_DEV_POWERIND,
b.liu7d102f82025-03-26 18:30:21 +080060 RIL_MSG_ID_DEV_MD_VERSION_REQ,
b.liu87afc4c2024-08-14 17:33:45 +080061 RIL_MSG_ID_DEV_END,
62
63 // Sim Information
b.liu15f456b2024-10-31 20:16:06 +080064 RIL_MSG_ID_SIM_BEGIN = 0x100,
b.liu87afc4c2024-08-14 17:33:45 +080065 // <uint8> 0:NOT_EXIST 1:READY ...
66 RIL_MSG_ID_SIM_STATE,
67 // <uint8> 0: SIM 1: USIM 2: TEST SIM 3: TEST USIM 4: UNKNOWN
68 RIL_MSG_ID_SIM_TYPE,
69 // <string> IMSI
70 RIL_MSG_ID_SIM_IMSI,
71 // <string> ICCID
72 RIL_MSG_ID_SIM_ICCID,
73 // <string> Phone Number
74 RIL_MSG_ID_SIM_PN,
75 // <string> PUK
76 RIL_MSG_ID_SIM_LOCK,
77 // <uint8> <uint8> <uint8> <uint8> PIN PUK LAST TIMES
78 RIL_MSG_ID_SIM_PINPUK_TIMES,
79 // <string> PLMN
80 RIL_MSG_ID_SIM_PLMN,
81
82 RIL_MSG_ID_SIM_END,
83
84 // Network Information
b.liu15f456b2024-10-31 20:16:06 +080085 RIL_MSG_ID_NET_BEGIN = 0x200,
b.liu87afc4c2024-08-14 17:33:45 +080086 // sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
87 RIL_MSG_ID_NET_AVAILABLE,
88 // <uint8> 0: automatic 1: manual
89 // or
90 // sel_mode(uint8)type(uint8)plmn(uint32)
91 RIL_MSG_ID_NET_SEL_MODE,
92 // mbtk_band_info_t
93 RIL_MSG_ID_NET_BAND,
94 // mbtk_signal_info_t
95 RIL_MSG_ID_NET_SIGNAL,
96 // mbtk_net_reg_info_t
97 RIL_MSG_ID_NET_REG,
98 // mbtk_cell_info_t[]
99 RIL_MSG_ID_NET_CELL,
b.liu557c81d2024-11-19 16:52:45 +0800100 // mbtk_ril_oos_info_t
101 RIL_MSG_ID_NET_OOS,
b.liu15f456b2024-10-31 20:16:06 +0800102
103 RIL_MSG_ID_NET_END,
104
105
106 // Network Information
107 RIL_MSG_ID_DATA_CALL_BEGIN = 0x300,
b.liu87afc4c2024-08-14 17:33:45 +0800108 // mbtk_apn_info_t
b.liu15f456b2024-10-31 20:16:06 +0800109 RIL_MSG_ID_DATA_CALL_APN,
b.liu87afc4c2024-08-14 17:33:45 +0800110 // REQ:
111 // <call_type[1]><cid[1]><timeout[1]>
112 // call_type : mbtk_data_call_type_enum
113 // cid : 1 - 15
114 // timeout : second
115 // RSP:
116 // <type[1]><ipv4><ipv6>
117 // type : 0-IPV4 1-IPV6 2-IPV4V6
118 // ipv4 : mbtk_ipv4_info_t
119 // ipv6 : mbtk_ipv6_info_t
b.liu15f456b2024-10-31 20:16:06 +0800120 RIL_MSG_ID_DATA_CALL_OPT,
b.liu87afc4c2024-08-14 17:33:45 +0800121
b.liu15f456b2024-10-31 20:16:06 +0800122 RIL_MSG_ID_DATA_CALL_END,
b.liu87afc4c2024-08-14 17:33:45 +0800123
124
125 // Call Information
b.liu15f456b2024-10-31 20:16:06 +0800126 RIL_MSG_ID_CALL_BEGIN = 0x400,
b.liu87afc4c2024-08-14 17:33:45 +0800127 RIL_MSG_ID_CALL_STATE,
128
129 // Start call.
130 RIL_MSG_ID_CALL_START,
131 //answer call
132 RIL_MSG_ID_CALL_ANSWER,
133 //hang up all call
134 RIL_MSG_ID_CALL_HANGUP,
135 //hang up a call
136 RIL_MSG_ID_CALL_HANGUP_A,
137 //hang up waiting or background call
138 RIL_MSG_ID_CALL_HANGUP_B,
139 //hang up foreground resume background
140 RIL_MSG_ID_CALL_HANGUP_C,
141 //wait in call
142 RIL_MSG_ID_CALL_WAITIN,
143 //mute call
144 RIL_MSG_ID_CALL_MUTE,
145 //dtmf call
146 RIL_MSG_ID_CALL_DTMF,
liuyang3c60be92024-12-19 16:42:32 +0800147 //centric
148 RIL_MSG_ID_CALL_CENTRIC,
b.liu87afc4c2024-08-14 17:33:45 +0800149 RIL_MSG_ID_CALL_END,
150
151 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800152 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800153 RIL_MSG_ID_SMS_STATE,
154 RIL_MSG_ID_SMS_CMGF,
155 RIL_MSG_ID_SMS_CPMS,
156 RIL_MSG_ID_SMS_CMGS,
157 RIL_MSG_ID_SMS_CMSS,
158 RIL_MSG_ID_SMS_CMGR,
159 RIL_MSG_ID_SMS_CMGW,
160 RIL_MSG_ID_SMS_CMGD,
161 RIL_MSG_ID_SMS_CMGL,
162 RIL_MSG_ID_SMS_CSCA,
163 RIL_MSG_ID_SMS_CSMP,
164 RIL_MSG_ID_SMS_CSCB,
165 RIL_MSG_ID_SMS_CNMI,
166
167 RIL_MSG_ID_SMS_END,
168
169 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800170 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800171 RIL_MSG_ID_PB_STATE,
172
173 RIL_MSG_ID_PB_END,
174
b.liu15f456b2024-10-31 20:16:06 +0800175 // Ecall Information
176 RIL_MSG_ID_ECALL_BEGIN = 0x700,
177 // mbtk_ecall_msd_cfg_info_t
178 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800179 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800180 RIL_MSG_ID_ECALL_MSDGEN,
181 // uint8[]
182 RIL_MSG_ID_ECALL_MSD,
183 // NULL
184 RIL_MSG_ID_ECALL_PUSH,
185 // mbtk_ecall_only_info_t
186 RIL_MSG_ID_ECALL_ONLY,
187 // reg <uint8>
188 RIL_MSG_ID_ECALL_REG,
189 // mbtk_ecall_dial_type_enum
190 RIL_MSG_ID_ECALL_DIAL,
191 // mbtk_ecall_mode_type_enum
192 RIL_MSG_ID_ECALL_MODE,
193 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
194 RIL_MSG_ID_ECALL_CFG,
195 // uint8[]
196 RIL_MSG_ID_ECALL_SMS_NUM,
197 // uint8
198 RIL_MSG_ID_ECALL_MUTESPK,
199 // mbtk_ecall_gain_info_t
200 RIL_MSG_ID_ECALL_DSP_GAIN,
201
202 RIL_MSG_ID_ECALL_END,
203
204 // IND Information
205 RIL_MSG_ID_IND_BEGIN = 0x1000,
206 // mbtk_ril_ser_state_enum
207 RIL_MSG_ID_IND_SER_STATE_CHANGE,
208 // mbtk_ril_net_reg_state_info_t
209 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800210 // <uint8> State
211 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
b.liuaced4f92024-12-31 11:14:51 +0800212 // mbtk_ril_sms_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800213 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800214 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800215 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800216 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800217 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800218 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800219 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800220 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800221 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800222 // mbtk_ril_ecall_state_info_t
223 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800224
225
226 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800227
228 // URC message
229 RIL_URC_MSG_BEGIN = 0x2000,
230 RIL_URC_MSG_GET_SIM_STATE, //check sim status
b.liu472cfaf2024-12-19 19:08:19 +0800231 RIL_URC_MSG_BAND_SET, // Band set message
b.liu15f456b2024-10-31 20:16:06 +0800232 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
233 RIL_URC_MSG_END,
234
235 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800236} ril_msg_id_enum;
237
238typedef struct {
239 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
240 uint16 msg_len;
241
b.liub171c9a2024-11-12 19:23:29 +0800242 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800243 uint16 msg_index; // Message index(Start from 1)
244 // 0 : For unknown msg id
245 uint16 msg_type; // Refor to : ril_msg_type_enum
246 uint16 msg_id; // Refor to : ril_msg_id_enum
247 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
248 uint16 data_len;
249 uint8 *data;
250} __attribute__((packed)) ril_msg_pack_info_t;
251
252typedef struct {
253 pthread_t pid;
254 char name[20];
255 bool is_waitting;
256 pthread_cond_t cond;
257 pthread_mutex_t mutex;
b.liu6917e9b2025-03-26 17:23:11 +0800258 timer_t timer_id;
259 uint16 msg_index;
b.liu87afc4c2024-08-14 17:33:45 +0800260} ril_cli_thread_info_t;
261
262typedef struct {
263 pthread_t pid;
264 bool is_async;
265 int *rsp_data_len; // Save response data length.
266 char *rsp_data; // Save response date.
267 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
268 ril_msg_pack_info_t *pack;
269} ril_msg_info_t;
270
271/*
272GSM band��
273 1 �C PGSM 900 (standard or primary)
274 2 �C DCS GSM 1800
275 4 �C PCS GSM 1900
276 8 �C EGSM 900 (extended)
277 16 �C GSM 450
278 32 �C GSM 480
279 64 �C GSM 850
280 512 - BAND_LOCK_BIT // used for GSM band setting
281*/
282typedef enum
283{
284 MBTK_GSM_BAND_PGSM_900 = 1,
285 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
286 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
287 MBTK_GSM_BAND_EGSM_900 = 8,
288 MBTK_GSM_BAND_GSM_450 = 16,
289 MBTK_GSM_BAND_GSM_480 = 32,
290 MBTK_GSM_BAND_GSM_850 = 64,
291 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
292} mbtk_gsm_band_enum;
293
294/*
295UMTS band��
296 1 �C UMTS_BAND_1
297 2 �C UMTS_BAND_2
298 4 �C UMTS_BAND_3
299 8 �C UMTS_BAND_4
300 16 �C UMTS_BAND_5
301 32 �C UMTS_BAND_6
302 64 �C UMTS_BAND_7
303 128 �C UMTS_BAND_8
304 256 �C UMTS_BAND_9
305*/
306typedef enum
307{
308 MBTK_UMTS_BAND_1 = 1,
309 MBTK_UMTS_BAND_2 = 2,
310 MBTK_UMTS_BAND_3 = 4,
311 MBTK_UMTS_BAND_4 = 8,
312 MBTK_UMTS_BAND_5 = 16,
313 MBTK_UMTS_BAND_6 = 32,
314 MBTK_UMTS_BAND_7 = 64,
315 MBTK_UMTS_BAND_8 = 128,
316 MBTK_UMTS_BAND_9 = 256
317} mbtk_umts_band_enum;
318
319/*
320LTEbandH(TDD-LTE band)
321 32 �C TDLTE_BAND_38
322 64 �C TDLTE_BAND_39
323 128 �C TDLTE_BAND_40
324 256 �C TDLTE_BAND_41
325*/
326typedef enum
327{
328 MBTK_TDLTE_BAND_38 = 32,
329 MBTK_TDLTE_BAND_39 = 64,
330 MBTK_TDLTE_BAND_40 = 128,
331 MBTK_TDLTE_BAND_41 = 256
332} mbtk_tdlte_band_enum;
333
334/*
335LTEbandL(FDD-LTE band)
336 1 �C FDDLTE_BAND_1
337 4 �C FDDLTE _BAND_3
338 8 �C FDDLTE _BAND_4
339 64 �C FDDLTE _BAND_7
340 65536 �C FDDLTE _BAND_17
341 524288 �C FDDLTE _BAND_20
342*/
343typedef enum
344{
345 MBTK_FDDLTE_BAND_1 = 1,
346 MBTK_FDDLTE_BAND_3 = 4,
347 MBTK_FDDLTE_BAND_4 = 8,
348 MBTK_FDDLTE_BAND_7 = 64,
349 MBTK_FDDLTE_BAND_17 = 65536,
350 MBTK_FDDLTE_BAND_20 = 524288
351} mbtk_fddlte_band_enum;
352
353typedef enum
354{
355 MBTK_LTE_EXT_BAND_65 = 1,
356 MBTK_LTE_EXT_BAND_66 = 2,
357 MBTK_LTE_EXT_BAND_67 = 4,
358 MBTK_LTE_EXT_BAND_68 = 8,
359 MBTK_LTE_EXT_BAND_69 = 16
360} mbtk_lte_ext_band_enum;
361
b.liub4772072024-08-15 14:47:03 +0800362typedef struct
363{
364 uint8 type; // 0: GSM 1: UMTS 2: LTE
365 bool running;
366
367 int cell_num;
368 mbtk_cell_info_t cell[CELL_NUM_MAX];
369} mbtK_cell_pack_info_t;
370
b.liu87afc4c2024-08-14 17:33:45 +0800371#ifdef __cplusplus
372extern "C" {
373#endif
374
375char* type2str(ril_msg_type_enum type);
376
377char* apn2str(mbtk_ip_type_enum type);
378
379/*
380IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
381*/
382int str_2_ipv6(const void *ip_str, void *ipv6);
383
384/*
385IPv6 : uint128 -> fe80::215:1dff:fe81:484c
386*/
387int ipv6_2_str(const void *ipv6, void *ipv6_str);
388
389char* id2str(int id);
390
391char* err2str(mbtk_ril_err_enum err);
392
393void *mbtk_memcpy(const void *src, unsigned int n);
394
395/*
3960 GSM
3971 GSM_COMPACT
3982 UTRAN
3993 GSM_EGPRS
4004 UTRAN_HSDPA
4015 UTRAN_HSUPA
4026 UTRAN_HSDPA_HSUPA
4037 EUTRAN
4048 ECGSM
405*/
406mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
407
408void ril_msg_pack_free(ril_msg_pack_info_t* pack);
409
b.liub171c9a2024-11-12 19:23:29 +0800410ril_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 +0800411
412int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
413
414ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
415
416#ifdef __cplusplus
417}
418#endif
419
420
421#endif /* MBTK_INFO_INCLUDE */
422
423