blob: 678a3165ceffc7d4c97d82c9424f9551bec6551d [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.liu15f456b2024-10-31 20:16:06 +080097
98 RIL_MSG_ID_NET_END,
99
100
101 // Network Information
102 RIL_MSG_ID_DATA_CALL_BEGIN = 0x300,
b.liu87afc4c2024-08-14 17:33:45 +0800103 // mbtk_apn_info_t
b.liu15f456b2024-10-31 20:16:06 +0800104 RIL_MSG_ID_DATA_CALL_APN,
b.liu87afc4c2024-08-14 17:33:45 +0800105 // REQ:
106 // <call_type[1]><cid[1]><timeout[1]>
107 // call_type : mbtk_data_call_type_enum
108 // cid : 1 - 15
109 // timeout : second
110 // RSP:
111 // <type[1]><ipv4><ipv6>
112 // type : 0-IPV4 1-IPV6 2-IPV4V6
113 // ipv4 : mbtk_ipv4_info_t
114 // ipv6 : mbtk_ipv6_info_t
b.liu15f456b2024-10-31 20:16:06 +0800115 RIL_MSG_ID_DATA_CALL_OPT,
b.liu87afc4c2024-08-14 17:33:45 +0800116
b.liu15f456b2024-10-31 20:16:06 +0800117 RIL_MSG_ID_DATA_CALL_END,
b.liu87afc4c2024-08-14 17:33:45 +0800118
119
120 // Call Information
b.liu15f456b2024-10-31 20:16:06 +0800121 RIL_MSG_ID_CALL_BEGIN = 0x400,
b.liu87afc4c2024-08-14 17:33:45 +0800122 RIL_MSG_ID_CALL_STATE,
123
124 // Start call.
125 RIL_MSG_ID_CALL_START,
126 //answer call
127 RIL_MSG_ID_CALL_ANSWER,
128 //hang up all call
129 RIL_MSG_ID_CALL_HANGUP,
130 //hang up a call
131 RIL_MSG_ID_CALL_HANGUP_A,
132 //hang up waiting or background call
133 RIL_MSG_ID_CALL_HANGUP_B,
134 //hang up foreground resume background
135 RIL_MSG_ID_CALL_HANGUP_C,
136 //wait in call
137 RIL_MSG_ID_CALL_WAITIN,
138 //mute call
139 RIL_MSG_ID_CALL_MUTE,
140 //dtmf call
141 RIL_MSG_ID_CALL_DTMF,
142 RIL_MSG_ID_CALL_END,
143
144 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800145 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800146 RIL_MSG_ID_SMS_STATE,
147 RIL_MSG_ID_SMS_CMGF,
148 RIL_MSG_ID_SMS_CPMS,
149 RIL_MSG_ID_SMS_CMGS,
150 RIL_MSG_ID_SMS_CMSS,
151 RIL_MSG_ID_SMS_CMGR,
152 RIL_MSG_ID_SMS_CMGW,
153 RIL_MSG_ID_SMS_CMGD,
154 RIL_MSG_ID_SMS_CMGL,
155 RIL_MSG_ID_SMS_CSCA,
156 RIL_MSG_ID_SMS_CSMP,
157 RIL_MSG_ID_SMS_CSCB,
158 RIL_MSG_ID_SMS_CNMI,
159
160 RIL_MSG_ID_SMS_END,
161
162 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800163 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800164 RIL_MSG_ID_PB_STATE,
165
166 RIL_MSG_ID_PB_END,
167
b.liu15f456b2024-10-31 20:16:06 +0800168 // Ecall Information
169 RIL_MSG_ID_ECALL_BEGIN = 0x700,
170 // mbtk_ecall_msd_cfg_info_t
171 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800172 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800173 RIL_MSG_ID_ECALL_MSDGEN,
174 // uint8[]
175 RIL_MSG_ID_ECALL_MSD,
176 // NULL
177 RIL_MSG_ID_ECALL_PUSH,
178 // mbtk_ecall_only_info_t
179 RIL_MSG_ID_ECALL_ONLY,
180 // reg <uint8>
181 RIL_MSG_ID_ECALL_REG,
182 // mbtk_ecall_dial_type_enum
183 RIL_MSG_ID_ECALL_DIAL,
184 // mbtk_ecall_mode_type_enum
185 RIL_MSG_ID_ECALL_MODE,
186 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
187 RIL_MSG_ID_ECALL_CFG,
188 // uint8[]
189 RIL_MSG_ID_ECALL_SMS_NUM,
190 // uint8
191 RIL_MSG_ID_ECALL_MUTESPK,
192 // mbtk_ecall_gain_info_t
193 RIL_MSG_ID_ECALL_DSP_GAIN,
194
195 RIL_MSG_ID_ECALL_END,
196
197 // IND Information
198 RIL_MSG_ID_IND_BEGIN = 0x1000,
199 // mbtk_ril_ser_state_enum
200 RIL_MSG_ID_IND_SER_STATE_CHANGE,
201 // mbtk_ril_net_reg_state_info_t
202 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800203 // <uint8> State
204 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
205 // <uint8> State
206 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800207 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800208 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800209 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800210 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800211 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800212 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800213 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800214 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800215 // mbtk_ril_ecall_state_info_t
216 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800217
218
219 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800220
221 // URC message
222 RIL_URC_MSG_BEGIN = 0x2000,
223 RIL_URC_MSG_GET_SIM_STATE, //check sim status
224 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
225 RIL_URC_MSG_END,
226
227 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800228} ril_msg_id_enum;
229
230typedef struct {
231 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
232 uint16 msg_len;
233
b.liub171c9a2024-11-12 19:23:29 +0800234 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800235 uint16 msg_index; // Message index(Start from 1)
236 // 0 : For unknown msg id
237 uint16 msg_type; // Refor to : ril_msg_type_enum
238 uint16 msg_id; // Refor to : ril_msg_id_enum
239 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
240 uint16 data_len;
241 uint8 *data;
242} __attribute__((packed)) ril_msg_pack_info_t;
243
244typedef struct {
245 pthread_t pid;
246 char name[20];
247 bool is_waitting;
248 pthread_cond_t cond;
249 pthread_mutex_t mutex;
250} ril_cli_thread_info_t;
251
252typedef struct {
253 pthread_t pid;
254 bool is_async;
255 int *rsp_data_len; // Save response data length.
256 char *rsp_data; // Save response date.
257 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
258 ril_msg_pack_info_t *pack;
259} ril_msg_info_t;
260
261/*
262GSM band��
263 1 �C PGSM 900 (standard or primary)
264 2 �C DCS GSM 1800
265 4 �C PCS GSM 1900
266 8 �C EGSM 900 (extended)
267 16 �C GSM 450
268 32 �C GSM 480
269 64 �C GSM 850
270 512 - BAND_LOCK_BIT // used for GSM band setting
271*/
272typedef enum
273{
274 MBTK_GSM_BAND_PGSM_900 = 1,
275 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
276 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
277 MBTK_GSM_BAND_EGSM_900 = 8,
278 MBTK_GSM_BAND_GSM_450 = 16,
279 MBTK_GSM_BAND_GSM_480 = 32,
280 MBTK_GSM_BAND_GSM_850 = 64,
281 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
282} mbtk_gsm_band_enum;
283
284/*
285UMTS band��
286 1 �C UMTS_BAND_1
287 2 �C UMTS_BAND_2
288 4 �C UMTS_BAND_3
289 8 �C UMTS_BAND_4
290 16 �C UMTS_BAND_5
291 32 �C UMTS_BAND_6
292 64 �C UMTS_BAND_7
293 128 �C UMTS_BAND_8
294 256 �C UMTS_BAND_9
295*/
296typedef enum
297{
298 MBTK_UMTS_BAND_1 = 1,
299 MBTK_UMTS_BAND_2 = 2,
300 MBTK_UMTS_BAND_3 = 4,
301 MBTK_UMTS_BAND_4 = 8,
302 MBTK_UMTS_BAND_5 = 16,
303 MBTK_UMTS_BAND_6 = 32,
304 MBTK_UMTS_BAND_7 = 64,
305 MBTK_UMTS_BAND_8 = 128,
306 MBTK_UMTS_BAND_9 = 256
307} mbtk_umts_band_enum;
308
309/*
310LTEbandH(TDD-LTE band)
311 32 �C TDLTE_BAND_38
312 64 �C TDLTE_BAND_39
313 128 �C TDLTE_BAND_40
314 256 �C TDLTE_BAND_41
315*/
316typedef enum
317{
318 MBTK_TDLTE_BAND_38 = 32,
319 MBTK_TDLTE_BAND_39 = 64,
320 MBTK_TDLTE_BAND_40 = 128,
321 MBTK_TDLTE_BAND_41 = 256
322} mbtk_tdlte_band_enum;
323
324/*
325LTEbandL(FDD-LTE band)
326 1 �C FDDLTE_BAND_1
327 4 �C FDDLTE _BAND_3
328 8 �C FDDLTE _BAND_4
329 64 �C FDDLTE _BAND_7
330 65536 �C FDDLTE _BAND_17
331 524288 �C FDDLTE _BAND_20
332*/
333typedef enum
334{
335 MBTK_FDDLTE_BAND_1 = 1,
336 MBTK_FDDLTE_BAND_3 = 4,
337 MBTK_FDDLTE_BAND_4 = 8,
338 MBTK_FDDLTE_BAND_7 = 64,
339 MBTK_FDDLTE_BAND_17 = 65536,
340 MBTK_FDDLTE_BAND_20 = 524288
341} mbtk_fddlte_band_enum;
342
343typedef enum
344{
345 MBTK_LTE_EXT_BAND_65 = 1,
346 MBTK_LTE_EXT_BAND_66 = 2,
347 MBTK_LTE_EXT_BAND_67 = 4,
348 MBTK_LTE_EXT_BAND_68 = 8,
349 MBTK_LTE_EXT_BAND_69 = 16
350} mbtk_lte_ext_band_enum;
351
b.liub4772072024-08-15 14:47:03 +0800352typedef struct
353{
354 uint8 type; // 0: GSM 1: UMTS 2: LTE
355 bool running;
356
357 int cell_num;
358 mbtk_cell_info_t cell[CELL_NUM_MAX];
359} mbtK_cell_pack_info_t;
360
b.liu87afc4c2024-08-14 17:33:45 +0800361#ifdef __cplusplus
362extern "C" {
363#endif
364
365char* type2str(ril_msg_type_enum type);
366
367char* apn2str(mbtk_ip_type_enum type);
368
369/*
370IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
371*/
372int str_2_ipv6(const void *ip_str, void *ipv6);
373
374/*
375IPv6 : uint128 -> fe80::215:1dff:fe81:484c
376*/
377int ipv6_2_str(const void *ipv6, void *ipv6_str);
378
379char* id2str(int id);
380
381char* err2str(mbtk_ril_err_enum err);
382
383void *mbtk_memcpy(const void *src, unsigned int n);
384
385/*
3860 GSM
3871 GSM_COMPACT
3882 UTRAN
3893 GSM_EGPRS
3904 UTRAN_HSDPA
3915 UTRAN_HSUPA
3926 UTRAN_HSDPA_HSUPA
3937 EUTRAN
3948 ECGSM
395*/
396mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
397
398void ril_msg_pack_free(ril_msg_pack_info_t* pack);
399
b.liub171c9a2024-11-12 19:23:29 +0800400ril_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 +0800401
402int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
403
404ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
405
406#ifdef __cplusplus
407}
408#endif
409
410
411#endif /* MBTK_INFO_INCLUDE */
412
413