blob: 3631b6767c2d1ead73d0670a4d022048084703a9 [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,
b.liu9c19cc62024-11-28 09:43:02 +080057 // <uint8>
58 RIL_MSG_ID_DEV_POWERIND,
b.liu87afc4c2024-08-14 17:33:45 +080059
60 RIL_MSG_ID_DEV_END,
61
62 // Sim Information
b.liu15f456b2024-10-31 20:16:06 +080063 RIL_MSG_ID_SIM_BEGIN = 0x100,
b.liu87afc4c2024-08-14 17:33:45 +080064 // <uint8> 0:NOT_EXIST 1:READY ...
65 RIL_MSG_ID_SIM_STATE,
66 // <uint8> 0: SIM 1: USIM 2: TEST SIM 3: TEST USIM 4: UNKNOWN
67 RIL_MSG_ID_SIM_TYPE,
68 // <string> IMSI
69 RIL_MSG_ID_SIM_IMSI,
70 // <string> ICCID
71 RIL_MSG_ID_SIM_ICCID,
72 // <string> Phone Number
73 RIL_MSG_ID_SIM_PN,
74 // <string> PUK
75 RIL_MSG_ID_SIM_LOCK,
76 // <uint8> <uint8> <uint8> <uint8> PIN PUK LAST TIMES
77 RIL_MSG_ID_SIM_PINPUK_TIMES,
78 // <string> PLMN
79 RIL_MSG_ID_SIM_PLMN,
80
81 RIL_MSG_ID_SIM_END,
82
83 // Network Information
b.liu15f456b2024-10-31 20:16:06 +080084 RIL_MSG_ID_NET_BEGIN = 0x200,
b.liu87afc4c2024-08-14 17:33:45 +080085 // sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
86 RIL_MSG_ID_NET_AVAILABLE,
87 // <uint8> 0: automatic 1: manual
88 // or
89 // sel_mode(uint8)type(uint8)plmn(uint32)
90 RIL_MSG_ID_NET_SEL_MODE,
91 // mbtk_band_info_t
92 RIL_MSG_ID_NET_BAND,
93 // mbtk_signal_info_t
94 RIL_MSG_ID_NET_SIGNAL,
95 // mbtk_net_reg_info_t
96 RIL_MSG_ID_NET_REG,
97 // mbtk_cell_info_t[]
98 RIL_MSG_ID_NET_CELL,
b.liu557c81d2024-11-19 16:52:45 +080099 // mbtk_ril_oos_info_t
100 RIL_MSG_ID_NET_OOS,
b.liu15f456b2024-10-31 20:16:06 +0800101
102 RIL_MSG_ID_NET_END,
103
104
105 // Network Information
106 RIL_MSG_ID_DATA_CALL_BEGIN = 0x300,
b.liu87afc4c2024-08-14 17:33:45 +0800107 // mbtk_apn_info_t
b.liu15f456b2024-10-31 20:16:06 +0800108 RIL_MSG_ID_DATA_CALL_APN,
b.liu87afc4c2024-08-14 17:33:45 +0800109 // REQ:
110 // <call_type[1]><cid[1]><timeout[1]>
111 // call_type : mbtk_data_call_type_enum
112 // cid : 1 - 15
113 // timeout : second
114 // RSP:
115 // <type[1]><ipv4><ipv6>
116 // type : 0-IPV4 1-IPV6 2-IPV4V6
117 // ipv4 : mbtk_ipv4_info_t
118 // ipv6 : mbtk_ipv6_info_t
b.liu15f456b2024-10-31 20:16:06 +0800119 RIL_MSG_ID_DATA_CALL_OPT,
b.liu87afc4c2024-08-14 17:33:45 +0800120
b.liu15f456b2024-10-31 20:16:06 +0800121 RIL_MSG_ID_DATA_CALL_END,
b.liu87afc4c2024-08-14 17:33:45 +0800122
123
124 // Call Information
b.liu15f456b2024-10-31 20:16:06 +0800125 RIL_MSG_ID_CALL_BEGIN = 0x400,
b.liu87afc4c2024-08-14 17:33:45 +0800126 RIL_MSG_ID_CALL_STATE,
127
128 // Start call.
129 RIL_MSG_ID_CALL_START,
130 //answer call
131 RIL_MSG_ID_CALL_ANSWER,
132 //hang up all call
133 RIL_MSG_ID_CALL_HANGUP,
134 //hang up a call
135 RIL_MSG_ID_CALL_HANGUP_A,
136 //hang up waiting or background call
137 RIL_MSG_ID_CALL_HANGUP_B,
138 //hang up foreground resume background
139 RIL_MSG_ID_CALL_HANGUP_C,
140 //wait in call
141 RIL_MSG_ID_CALL_WAITIN,
142 //mute call
143 RIL_MSG_ID_CALL_MUTE,
144 //dtmf call
145 RIL_MSG_ID_CALL_DTMF,
liuyang3c60be92024-12-19 16:42:32 +0800146 //centric
147 RIL_MSG_ID_CALL_CENTRIC,
b.liu87afc4c2024-08-14 17:33:45 +0800148 RIL_MSG_ID_CALL_END,
149
150 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800151 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800152 RIL_MSG_ID_SMS_STATE,
153 RIL_MSG_ID_SMS_CMGF,
154 RIL_MSG_ID_SMS_CPMS,
155 RIL_MSG_ID_SMS_CMGS,
156 RIL_MSG_ID_SMS_CMSS,
157 RIL_MSG_ID_SMS_CMGR,
158 RIL_MSG_ID_SMS_CMGW,
159 RIL_MSG_ID_SMS_CMGD,
160 RIL_MSG_ID_SMS_CMGL,
161 RIL_MSG_ID_SMS_CSCA,
162 RIL_MSG_ID_SMS_CSMP,
163 RIL_MSG_ID_SMS_CSCB,
164 RIL_MSG_ID_SMS_CNMI,
165
166 RIL_MSG_ID_SMS_END,
167
168 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800169 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800170 RIL_MSG_ID_PB_STATE,
171
172 RIL_MSG_ID_PB_END,
173
b.liu15f456b2024-10-31 20:16:06 +0800174 // Ecall Information
175 RIL_MSG_ID_ECALL_BEGIN = 0x700,
176 // mbtk_ecall_msd_cfg_info_t
177 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800178 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800179 RIL_MSG_ID_ECALL_MSDGEN,
180 // uint8[]
181 RIL_MSG_ID_ECALL_MSD,
182 // NULL
183 RIL_MSG_ID_ECALL_PUSH,
184 // mbtk_ecall_only_info_t
185 RIL_MSG_ID_ECALL_ONLY,
186 // reg <uint8>
187 RIL_MSG_ID_ECALL_REG,
188 // mbtk_ecall_dial_type_enum
189 RIL_MSG_ID_ECALL_DIAL,
190 // mbtk_ecall_mode_type_enum
191 RIL_MSG_ID_ECALL_MODE,
192 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
193 RIL_MSG_ID_ECALL_CFG,
194 // uint8[]
195 RIL_MSG_ID_ECALL_SMS_NUM,
196 // uint8
197 RIL_MSG_ID_ECALL_MUTESPK,
198 // mbtk_ecall_gain_info_t
199 RIL_MSG_ID_ECALL_DSP_GAIN,
200
201 RIL_MSG_ID_ECALL_END,
202
203 // IND Information
204 RIL_MSG_ID_IND_BEGIN = 0x1000,
205 // mbtk_ril_ser_state_enum
206 RIL_MSG_ID_IND_SER_STATE_CHANGE,
207 // mbtk_ril_net_reg_state_info_t
208 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800209 // <uint8> State
210 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
b.liuaced4f92024-12-31 11:14:51 +0800211 // mbtk_ril_sms_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800212 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800213 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800214 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800215 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800216 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800217 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800218 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800219 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800220 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800221 // mbtk_ril_ecall_state_info_t
222 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800223
224
225 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800226
227 // URC message
228 RIL_URC_MSG_BEGIN = 0x2000,
229 RIL_URC_MSG_GET_SIM_STATE, //check sim status
b.liu472cfaf2024-12-19 19:08:19 +0800230 RIL_URC_MSG_BAND_SET, // Band set message
b.liu15f456b2024-10-31 20:16:06 +0800231 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
232 RIL_URC_MSG_END,
233
234 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800235} ril_msg_id_enum;
236
237typedef struct {
238 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
239 uint16 msg_len;
240
b.liub171c9a2024-11-12 19:23:29 +0800241 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800242 uint16 msg_index; // Message index(Start from 1)
243 // 0 : For unknown msg id
244 uint16 msg_type; // Refor to : ril_msg_type_enum
245 uint16 msg_id; // Refor to : ril_msg_id_enum
246 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
247 uint16 data_len;
248 uint8 *data;
249} __attribute__((packed)) ril_msg_pack_info_t;
250
251typedef struct {
252 pthread_t pid;
253 char name[20];
254 bool is_waitting;
255 pthread_cond_t cond;
256 pthread_mutex_t mutex;
257} ril_cli_thread_info_t;
258
259typedef struct {
260 pthread_t pid;
261 bool is_async;
262 int *rsp_data_len; // Save response data length.
263 char *rsp_data; // Save response date.
264 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
265 ril_msg_pack_info_t *pack;
266} ril_msg_info_t;
267
268/*
269GSM band��
270 1 �C PGSM 900 (standard or primary)
271 2 �C DCS GSM 1800
272 4 �C PCS GSM 1900
273 8 �C EGSM 900 (extended)
274 16 �C GSM 450
275 32 �C GSM 480
276 64 �C GSM 850
277 512 - BAND_LOCK_BIT // used for GSM band setting
278*/
279typedef enum
280{
281 MBTK_GSM_BAND_PGSM_900 = 1,
282 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
283 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
284 MBTK_GSM_BAND_EGSM_900 = 8,
285 MBTK_GSM_BAND_GSM_450 = 16,
286 MBTK_GSM_BAND_GSM_480 = 32,
287 MBTK_GSM_BAND_GSM_850 = 64,
288 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
289} mbtk_gsm_band_enum;
290
291/*
292UMTS band��
293 1 �C UMTS_BAND_1
294 2 �C UMTS_BAND_2
295 4 �C UMTS_BAND_3
296 8 �C UMTS_BAND_4
297 16 �C UMTS_BAND_5
298 32 �C UMTS_BAND_6
299 64 �C UMTS_BAND_7
300 128 �C UMTS_BAND_8
301 256 �C UMTS_BAND_9
302*/
303typedef enum
304{
305 MBTK_UMTS_BAND_1 = 1,
306 MBTK_UMTS_BAND_2 = 2,
307 MBTK_UMTS_BAND_3 = 4,
308 MBTK_UMTS_BAND_4 = 8,
309 MBTK_UMTS_BAND_5 = 16,
310 MBTK_UMTS_BAND_6 = 32,
311 MBTK_UMTS_BAND_7 = 64,
312 MBTK_UMTS_BAND_8 = 128,
313 MBTK_UMTS_BAND_9 = 256
314} mbtk_umts_band_enum;
315
316/*
317LTEbandH(TDD-LTE band)
318 32 �C TDLTE_BAND_38
319 64 �C TDLTE_BAND_39
320 128 �C TDLTE_BAND_40
321 256 �C TDLTE_BAND_41
322*/
323typedef enum
324{
325 MBTK_TDLTE_BAND_38 = 32,
326 MBTK_TDLTE_BAND_39 = 64,
327 MBTK_TDLTE_BAND_40 = 128,
328 MBTK_TDLTE_BAND_41 = 256
329} mbtk_tdlte_band_enum;
330
331/*
332LTEbandL(FDD-LTE band)
333 1 �C FDDLTE_BAND_1
334 4 �C FDDLTE _BAND_3
335 8 �C FDDLTE _BAND_4
336 64 �C FDDLTE _BAND_7
337 65536 �C FDDLTE _BAND_17
338 524288 �C FDDLTE _BAND_20
339*/
340typedef enum
341{
342 MBTK_FDDLTE_BAND_1 = 1,
343 MBTK_FDDLTE_BAND_3 = 4,
344 MBTK_FDDLTE_BAND_4 = 8,
345 MBTK_FDDLTE_BAND_7 = 64,
346 MBTK_FDDLTE_BAND_17 = 65536,
347 MBTK_FDDLTE_BAND_20 = 524288
348} mbtk_fddlte_band_enum;
349
350typedef enum
351{
352 MBTK_LTE_EXT_BAND_65 = 1,
353 MBTK_LTE_EXT_BAND_66 = 2,
354 MBTK_LTE_EXT_BAND_67 = 4,
355 MBTK_LTE_EXT_BAND_68 = 8,
356 MBTK_LTE_EXT_BAND_69 = 16
357} mbtk_lte_ext_band_enum;
358
b.liub4772072024-08-15 14:47:03 +0800359typedef struct
360{
361 uint8 type; // 0: GSM 1: UMTS 2: LTE
362 bool running;
363
364 int cell_num;
365 mbtk_cell_info_t cell[CELL_NUM_MAX];
366} mbtK_cell_pack_info_t;
367
b.liu87afc4c2024-08-14 17:33:45 +0800368#ifdef __cplusplus
369extern "C" {
370#endif
371
372char* type2str(ril_msg_type_enum type);
373
374char* apn2str(mbtk_ip_type_enum type);
375
376/*
377IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
378*/
379int str_2_ipv6(const void *ip_str, void *ipv6);
380
381/*
382IPv6 : uint128 -> fe80::215:1dff:fe81:484c
383*/
384int ipv6_2_str(const void *ipv6, void *ipv6_str);
385
386char* id2str(int id);
387
388char* err2str(mbtk_ril_err_enum err);
389
390void *mbtk_memcpy(const void *src, unsigned int n);
391
392/*
3930 GSM
3941 GSM_COMPACT
3952 UTRAN
3963 GSM_EGPRS
3974 UTRAN_HSDPA
3985 UTRAN_HSUPA
3996 UTRAN_HSDPA_HSUPA
4007 EUTRAN
4018 ECGSM
402*/
403mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
404
405void ril_msg_pack_free(ril_msg_pack_info_t* pack);
406
b.liub171c9a2024-11-12 19:23:29 +0800407ril_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 +0800408
409int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
410
411ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
412
413#ifdef __cplusplus
414}
415#endif
416
417
418#endif /* MBTK_INFO_INCLUDE */
419
420