blob: 11cf8ec78dd71c1c09ee3820f979f9e71d168257 [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.liu7ca612c2025-04-25 09:23:36 +080023// RIL_SOCK_PACK_EXTRA_LEN + at_port(1) + sim_id(1) + Index(2) + Type(2) + Id(2) + Error(2) + data_len(2)
24#define RIL_SOCK_PACK_LEN_MIN (RIL_SOCK_PACK_EXTRA_LEN + 12)
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,
b.liu7ca612c2025-04-25 09:23:36 +080081 // <uint8>
82 RIL_MSG_ID_SIM_SWITCH,
b.liu87afc4c2024-08-14 17:33:45 +080083
84 RIL_MSG_ID_SIM_END,
85
86 // Network Information
b.liu15f456b2024-10-31 20:16:06 +080087 RIL_MSG_ID_NET_BEGIN = 0x200,
b.liu87afc4c2024-08-14 17:33:45 +080088 // sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
89 RIL_MSG_ID_NET_AVAILABLE,
90 // <uint8> 0: automatic 1: manual
91 // or
92 // sel_mode(uint8)type(uint8)plmn(uint32)
93 RIL_MSG_ID_NET_SEL_MODE,
94 // mbtk_band_info_t
95 RIL_MSG_ID_NET_BAND,
96 // mbtk_signal_info_t
97 RIL_MSG_ID_NET_SIGNAL,
98 // mbtk_net_reg_info_t
99 RIL_MSG_ID_NET_REG,
100 // mbtk_cell_info_t[]
101 RIL_MSG_ID_NET_CELL,
b.liu557c81d2024-11-19 16:52:45 +0800102 // mbtk_ril_oos_info_t
103 RIL_MSG_ID_NET_OOS,
b.liu15f456b2024-10-31 20:16:06 +0800104
105 RIL_MSG_ID_NET_END,
106
107
108 // Network Information
109 RIL_MSG_ID_DATA_CALL_BEGIN = 0x300,
b.liu87afc4c2024-08-14 17:33:45 +0800110 // mbtk_apn_info_t
b.liu15f456b2024-10-31 20:16:06 +0800111 RIL_MSG_ID_DATA_CALL_APN,
b.liu87afc4c2024-08-14 17:33:45 +0800112 // REQ:
113 // <call_type[1]><cid[1]><timeout[1]>
114 // call_type : mbtk_data_call_type_enum
115 // cid : 1 - 15
116 // timeout : second
117 // RSP:
118 // <type[1]><ipv4><ipv6>
119 // type : 0-IPV4 1-IPV6 2-IPV4V6
120 // ipv4 : mbtk_ipv4_info_t
121 // ipv6 : mbtk_ipv6_info_t
b.liu15f456b2024-10-31 20:16:06 +0800122 RIL_MSG_ID_DATA_CALL_OPT,
b.liu87afc4c2024-08-14 17:33:45 +0800123
b.liu15f456b2024-10-31 20:16:06 +0800124 RIL_MSG_ID_DATA_CALL_END,
b.liu87afc4c2024-08-14 17:33:45 +0800125
126
127 // Call Information
b.liu15f456b2024-10-31 20:16:06 +0800128 RIL_MSG_ID_CALL_BEGIN = 0x400,
b.liu87afc4c2024-08-14 17:33:45 +0800129 RIL_MSG_ID_CALL_STATE,
130
131 // Start call.
132 RIL_MSG_ID_CALL_START,
133 //answer call
134 RIL_MSG_ID_CALL_ANSWER,
135 //hang up all call
136 RIL_MSG_ID_CALL_HANGUP,
137 //hang up a call
138 RIL_MSG_ID_CALL_HANGUP_A,
139 //hang up waiting or background call
140 RIL_MSG_ID_CALL_HANGUP_B,
141 //hang up foreground resume background
142 RIL_MSG_ID_CALL_HANGUP_C,
143 //wait in call
144 RIL_MSG_ID_CALL_WAITIN,
145 //mute call
146 RIL_MSG_ID_CALL_MUTE,
147 //dtmf call
148 RIL_MSG_ID_CALL_DTMF,
liuyang3c60be92024-12-19 16:42:32 +0800149 //centric
150 RIL_MSG_ID_CALL_CENTRIC,
b.liu87afc4c2024-08-14 17:33:45 +0800151 RIL_MSG_ID_CALL_END,
152
153 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800154 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800155 RIL_MSG_ID_SMS_STATE,
156 RIL_MSG_ID_SMS_CMGF,
157 RIL_MSG_ID_SMS_CPMS,
158 RIL_MSG_ID_SMS_CMGS,
159 RIL_MSG_ID_SMS_CMSS,
160 RIL_MSG_ID_SMS_CMGR,
161 RIL_MSG_ID_SMS_CMGW,
162 RIL_MSG_ID_SMS_CMGD,
163 RIL_MSG_ID_SMS_CMGL,
164 RIL_MSG_ID_SMS_CSCA,
165 RIL_MSG_ID_SMS_CSMP,
166 RIL_MSG_ID_SMS_CSCB,
167 RIL_MSG_ID_SMS_CNMI,
168
169 RIL_MSG_ID_SMS_END,
170
171 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800172 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800173 RIL_MSG_ID_PB_STATE,
174
175 RIL_MSG_ID_PB_END,
176
b.liu15f456b2024-10-31 20:16:06 +0800177 // Ecall Information
178 RIL_MSG_ID_ECALL_BEGIN = 0x700,
179 // mbtk_ecall_msd_cfg_info_t
180 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800181 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800182 RIL_MSG_ID_ECALL_MSDGEN,
183 // uint8[]
184 RIL_MSG_ID_ECALL_MSD,
185 // NULL
186 RIL_MSG_ID_ECALL_PUSH,
187 // mbtk_ecall_only_info_t
188 RIL_MSG_ID_ECALL_ONLY,
189 // reg <uint8>
190 RIL_MSG_ID_ECALL_REG,
191 // mbtk_ecall_dial_type_enum
192 RIL_MSG_ID_ECALL_DIAL,
193 // mbtk_ecall_mode_type_enum
194 RIL_MSG_ID_ECALL_MODE,
195 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
196 RIL_MSG_ID_ECALL_CFG,
197 // uint8[]
198 RIL_MSG_ID_ECALL_SMS_NUM,
199 // uint8
200 RIL_MSG_ID_ECALL_MUTESPK,
201 // mbtk_ecall_gain_info_t
202 RIL_MSG_ID_ECALL_DSP_GAIN,
203
204 RIL_MSG_ID_ECALL_END,
205
206 // IND Information
207 RIL_MSG_ID_IND_BEGIN = 0x1000,
208 // mbtk_ril_ser_state_enum
209 RIL_MSG_ID_IND_SER_STATE_CHANGE,
210 // mbtk_ril_net_reg_state_info_t
211 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800212 // <uint8> State
213 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
b.liuaced4f92024-12-31 11:14:51 +0800214 // mbtk_ril_sms_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800215 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800216 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800217 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800218 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800219 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800220 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800221 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800222 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800223 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800224 // mbtk_ril_ecall_state_info_t
225 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800226
227
228 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800229
230 // URC message
231 RIL_URC_MSG_BEGIN = 0x2000,
232 RIL_URC_MSG_GET_SIM_STATE, //check sim status
b.liu472cfaf2024-12-19 19:08:19 +0800233 RIL_URC_MSG_BAND_SET, // Band set message
b.liu15f456b2024-10-31 20:16:06 +0800234 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
235 RIL_URC_MSG_END,
236
237 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800238} ril_msg_id_enum;
239
240typedef struct {
241 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
242 uint16 msg_len;
243
b.liub171c9a2024-11-12 19:23:29 +0800244 uint8 at_port; // ATPortType_enum
b.liu7ca612c2025-04-25 09:23:36 +0800245 uint8 sim_id; // mbtk_sim_type_enum
b.liu87afc4c2024-08-14 17:33:45 +0800246 uint16 msg_index; // Message index(Start from 1)
247 // 0 : For unknown msg id
248 uint16 msg_type; // Refor to : ril_msg_type_enum
249 uint16 msg_id; // Refor to : ril_msg_id_enum
250 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
251 uint16 data_len;
252 uint8 *data;
253} __attribute__((packed)) ril_msg_pack_info_t;
254
255typedef struct {
256 pthread_t pid;
257 char name[20];
258 bool is_waitting;
259 pthread_cond_t cond;
260 pthread_mutex_t mutex;
b.liu6917e9b2025-03-26 17:23:11 +0800261 timer_t timer_id;
262 uint16 msg_index;
b.liu87afc4c2024-08-14 17:33:45 +0800263} ril_cli_thread_info_t;
264
265typedef struct {
266 pthread_t pid;
267 bool is_async;
268 int *rsp_data_len; // Save response data length.
269 char *rsp_data; // Save response date.
270 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
271 ril_msg_pack_info_t *pack;
272} ril_msg_info_t;
273
274/*
275GSM band��
276 1 �C PGSM 900 (standard or primary)
277 2 �C DCS GSM 1800
278 4 �C PCS GSM 1900
279 8 �C EGSM 900 (extended)
280 16 �C GSM 450
281 32 �C GSM 480
282 64 �C GSM 850
283 512 - BAND_LOCK_BIT // used for GSM band setting
284*/
285typedef enum
286{
287 MBTK_GSM_BAND_PGSM_900 = 1,
288 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
289 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
290 MBTK_GSM_BAND_EGSM_900 = 8,
291 MBTK_GSM_BAND_GSM_450 = 16,
292 MBTK_GSM_BAND_GSM_480 = 32,
293 MBTK_GSM_BAND_GSM_850 = 64,
294 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
295} mbtk_gsm_band_enum;
296
297/*
298UMTS band��
299 1 �C UMTS_BAND_1
300 2 �C UMTS_BAND_2
301 4 �C UMTS_BAND_3
302 8 �C UMTS_BAND_4
303 16 �C UMTS_BAND_5
304 32 �C UMTS_BAND_6
305 64 �C UMTS_BAND_7
306 128 �C UMTS_BAND_8
307 256 �C UMTS_BAND_9
308*/
309typedef enum
310{
311 MBTK_UMTS_BAND_1 = 1,
312 MBTK_UMTS_BAND_2 = 2,
313 MBTK_UMTS_BAND_3 = 4,
314 MBTK_UMTS_BAND_4 = 8,
315 MBTK_UMTS_BAND_5 = 16,
316 MBTK_UMTS_BAND_6 = 32,
317 MBTK_UMTS_BAND_7 = 64,
318 MBTK_UMTS_BAND_8 = 128,
319 MBTK_UMTS_BAND_9 = 256
320} mbtk_umts_band_enum;
321
322/*
323LTEbandH(TDD-LTE band)
324 32 �C TDLTE_BAND_38
325 64 �C TDLTE_BAND_39
326 128 �C TDLTE_BAND_40
327 256 �C TDLTE_BAND_41
328*/
329typedef enum
330{
331 MBTK_TDLTE_BAND_38 = 32,
332 MBTK_TDLTE_BAND_39 = 64,
333 MBTK_TDLTE_BAND_40 = 128,
334 MBTK_TDLTE_BAND_41 = 256
335} mbtk_tdlte_band_enum;
336
337/*
338LTEbandL(FDD-LTE band)
339 1 �C FDDLTE_BAND_1
340 4 �C FDDLTE _BAND_3
341 8 �C FDDLTE _BAND_4
342 64 �C FDDLTE _BAND_7
343 65536 �C FDDLTE _BAND_17
344 524288 �C FDDLTE _BAND_20
345*/
346typedef enum
347{
348 MBTK_FDDLTE_BAND_1 = 1,
349 MBTK_FDDLTE_BAND_3 = 4,
350 MBTK_FDDLTE_BAND_4 = 8,
351 MBTK_FDDLTE_BAND_7 = 64,
352 MBTK_FDDLTE_BAND_17 = 65536,
353 MBTK_FDDLTE_BAND_20 = 524288
354} mbtk_fddlte_band_enum;
355
356typedef enum
357{
358 MBTK_LTE_EXT_BAND_65 = 1,
359 MBTK_LTE_EXT_BAND_66 = 2,
360 MBTK_LTE_EXT_BAND_67 = 4,
361 MBTK_LTE_EXT_BAND_68 = 8,
362 MBTK_LTE_EXT_BAND_69 = 16
363} mbtk_lte_ext_band_enum;
364
b.liub4772072024-08-15 14:47:03 +0800365typedef struct
366{
367 uint8 type; // 0: GSM 1: UMTS 2: LTE
368 bool running;
369
370 int cell_num;
371 mbtk_cell_info_t cell[CELL_NUM_MAX];
372} mbtK_cell_pack_info_t;
373
b.liu87afc4c2024-08-14 17:33:45 +0800374#ifdef __cplusplus
375extern "C" {
376#endif
377
378char* type2str(ril_msg_type_enum type);
379
380char* apn2str(mbtk_ip_type_enum type);
381
382/*
383IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
384*/
385int str_2_ipv6(const void *ip_str, void *ipv6);
386
387/*
388IPv6 : uint128 -> fe80::215:1dff:fe81:484c
389*/
390int ipv6_2_str(const void *ipv6, void *ipv6_str);
391
392char* id2str(int id);
393
394char* err2str(mbtk_ril_err_enum err);
395
396void *mbtk_memcpy(const void *src, unsigned int n);
397
398/*
3990 GSM
4001 GSM_COMPACT
4012 UTRAN
4023 GSM_EGPRS
4034 UTRAN_HSDPA
4045 UTRAN_HSUPA
4056 UTRAN_HSDPA_HSUPA
4067 EUTRAN
4078 ECGSM
408*/
409mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
410
411void ril_msg_pack_free(ril_msg_pack_info_t* pack);
412
b.liu7ca612c2025-04-25 09:23:36 +0800413ril_msg_pack_info_t* ril_msg_pack_creat(mbtk_sim_type_enum sim_id, 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 +0800414
415int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
416
417ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
418
419#ifdef __cplusplus
420}
421#endif
422
423
424#endif /* MBTK_INFO_INCLUDE */
425
426