blob: 97f31b2221a9b1b337dea6cb06703f718f243dd9 [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,
146 RIL_MSG_ID_CALL_END,
147
148 // SMS Information
b.liu15f456b2024-10-31 20:16:06 +0800149 RIL_MSG_ID_SMS_BEGIN = 0x500,
b.liu87afc4c2024-08-14 17:33:45 +0800150 RIL_MSG_ID_SMS_STATE,
151 RIL_MSG_ID_SMS_CMGF,
152 RIL_MSG_ID_SMS_CPMS,
153 RIL_MSG_ID_SMS_CMGS,
154 RIL_MSG_ID_SMS_CMSS,
155 RIL_MSG_ID_SMS_CMGR,
156 RIL_MSG_ID_SMS_CMGW,
157 RIL_MSG_ID_SMS_CMGD,
158 RIL_MSG_ID_SMS_CMGL,
159 RIL_MSG_ID_SMS_CSCA,
160 RIL_MSG_ID_SMS_CSMP,
161 RIL_MSG_ID_SMS_CSCB,
162 RIL_MSG_ID_SMS_CNMI,
163
164 RIL_MSG_ID_SMS_END,
165
166 // PhoneBook Information
b.liu15f456b2024-10-31 20:16:06 +0800167 RIL_MSG_ID_PB_BEGIN = 0x600,
b.liu87afc4c2024-08-14 17:33:45 +0800168 RIL_MSG_ID_PB_STATE,
169
170 RIL_MSG_ID_PB_END,
171
b.liu15f456b2024-10-31 20:16:06 +0800172 // Ecall Information
173 RIL_MSG_ID_ECALL_BEGIN = 0x700,
174 // mbtk_ecall_msd_cfg_info_t
175 RIL_MSG_ID_ECALL_MSDCFG,
b.liu87afc4c2024-08-14 17:33:45 +0800176 // NULL
b.liu15f456b2024-10-31 20:16:06 +0800177 RIL_MSG_ID_ECALL_MSDGEN,
178 // uint8[]
179 RIL_MSG_ID_ECALL_MSD,
180 // NULL
181 RIL_MSG_ID_ECALL_PUSH,
182 // mbtk_ecall_only_info_t
183 RIL_MSG_ID_ECALL_ONLY,
184 // reg <uint8>
185 RIL_MSG_ID_ECALL_REG,
186 // mbtk_ecall_dial_type_enum
187 RIL_MSG_ID_ECALL_DIAL,
188 // mbtk_ecall_mode_type_enum
189 RIL_MSG_ID_ECALL_MODE,
190 // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
191 RIL_MSG_ID_ECALL_CFG,
192 // uint8[]
193 RIL_MSG_ID_ECALL_SMS_NUM,
194 // uint8
195 RIL_MSG_ID_ECALL_MUTESPK,
196 // mbtk_ecall_gain_info_t
197 RIL_MSG_ID_ECALL_DSP_GAIN,
198
199 RIL_MSG_ID_ECALL_END,
200
201 // IND Information
202 RIL_MSG_ID_IND_BEGIN = 0x1000,
203 // mbtk_ril_ser_state_enum
204 RIL_MSG_ID_IND_SER_STATE_CHANGE,
205 // mbtk_ril_net_reg_state_info_t
206 RIL_MSG_ID_IND_NET_REG_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800207 // <uint8> State
208 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
209 // <uint8> State
210 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800211 // mbtk_ril_radio_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800212 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800213 // mbtk_ril_sim_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800214 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800215 // mbtk_ril_pdp_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800216 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800217 // mbtk_ril_signal_state_info_t
b.liu87afc4c2024-08-14 17:33:45 +0800218 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
b.liu15f456b2024-10-31 20:16:06 +0800219 // mbtk_ril_ecall_state_info_t
220 RIL_MSG_ID_IND_ECALL_STATE_CHANGE,
b.liu87afc4c2024-08-14 17:33:45 +0800221
222
223 RIL_MSG_ID_IND_END,
b.liu15f456b2024-10-31 20:16:06 +0800224
225 // URC message
226 RIL_URC_MSG_BEGIN = 0x2000,
227 RIL_URC_MSG_GET_SIM_STATE, //check sim status
b.liu472cfaf2024-12-19 19:08:19 +0800228 RIL_URC_MSG_BAND_SET, // Band set message
b.liu15f456b2024-10-31 20:16:06 +0800229 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
230 RIL_URC_MSG_END,
231
232 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800233} ril_msg_id_enum;
234
235typedef struct {
236 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
237 uint16 msg_len;
238
b.liub171c9a2024-11-12 19:23:29 +0800239 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800240 uint16 msg_index; // Message index(Start from 1)
241 // 0 : For unknown msg id
242 uint16 msg_type; // Refor to : ril_msg_type_enum
243 uint16 msg_id; // Refor to : ril_msg_id_enum
244 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
245 uint16 data_len;
246 uint8 *data;
247} __attribute__((packed)) ril_msg_pack_info_t;
248
249typedef struct {
250 pthread_t pid;
251 char name[20];
252 bool is_waitting;
253 pthread_cond_t cond;
254 pthread_mutex_t mutex;
255} ril_cli_thread_info_t;
256
257typedef struct {
258 pthread_t pid;
259 bool is_async;
260 int *rsp_data_len; // Save response data length.
261 char *rsp_data; // Save response date.
262 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
263 ril_msg_pack_info_t *pack;
264} ril_msg_info_t;
265
266/*
267GSM band��
268 1 �C PGSM 900 (standard or primary)
269 2 �C DCS GSM 1800
270 4 �C PCS GSM 1900
271 8 �C EGSM 900 (extended)
272 16 �C GSM 450
273 32 �C GSM 480
274 64 �C GSM 850
275 512 - BAND_LOCK_BIT // used for GSM band setting
276*/
277typedef enum
278{
279 MBTK_GSM_BAND_PGSM_900 = 1,
280 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
281 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
282 MBTK_GSM_BAND_EGSM_900 = 8,
283 MBTK_GSM_BAND_GSM_450 = 16,
284 MBTK_GSM_BAND_GSM_480 = 32,
285 MBTK_GSM_BAND_GSM_850 = 64,
286 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
287} mbtk_gsm_band_enum;
288
289/*
290UMTS band��
291 1 �C UMTS_BAND_1
292 2 �C UMTS_BAND_2
293 4 �C UMTS_BAND_3
294 8 �C UMTS_BAND_4
295 16 �C UMTS_BAND_5
296 32 �C UMTS_BAND_6
297 64 �C UMTS_BAND_7
298 128 �C UMTS_BAND_8
299 256 �C UMTS_BAND_9
300*/
301typedef enum
302{
303 MBTK_UMTS_BAND_1 = 1,
304 MBTK_UMTS_BAND_2 = 2,
305 MBTK_UMTS_BAND_3 = 4,
306 MBTK_UMTS_BAND_4 = 8,
307 MBTK_UMTS_BAND_5 = 16,
308 MBTK_UMTS_BAND_6 = 32,
309 MBTK_UMTS_BAND_7 = 64,
310 MBTK_UMTS_BAND_8 = 128,
311 MBTK_UMTS_BAND_9 = 256
312} mbtk_umts_band_enum;
313
314/*
315LTEbandH(TDD-LTE band)
316 32 �C TDLTE_BAND_38
317 64 �C TDLTE_BAND_39
318 128 �C TDLTE_BAND_40
319 256 �C TDLTE_BAND_41
320*/
321typedef enum
322{
323 MBTK_TDLTE_BAND_38 = 32,
324 MBTK_TDLTE_BAND_39 = 64,
325 MBTK_TDLTE_BAND_40 = 128,
326 MBTK_TDLTE_BAND_41 = 256
327} mbtk_tdlte_band_enum;
328
329/*
330LTEbandL(FDD-LTE band)
331 1 �C FDDLTE_BAND_1
332 4 �C FDDLTE _BAND_3
333 8 �C FDDLTE _BAND_4
334 64 �C FDDLTE _BAND_7
335 65536 �C FDDLTE _BAND_17
336 524288 �C FDDLTE _BAND_20
337*/
338typedef enum
339{
340 MBTK_FDDLTE_BAND_1 = 1,
341 MBTK_FDDLTE_BAND_3 = 4,
342 MBTK_FDDLTE_BAND_4 = 8,
343 MBTK_FDDLTE_BAND_7 = 64,
344 MBTK_FDDLTE_BAND_17 = 65536,
345 MBTK_FDDLTE_BAND_20 = 524288
346} mbtk_fddlte_band_enum;
347
348typedef enum
349{
350 MBTK_LTE_EXT_BAND_65 = 1,
351 MBTK_LTE_EXT_BAND_66 = 2,
352 MBTK_LTE_EXT_BAND_67 = 4,
353 MBTK_LTE_EXT_BAND_68 = 8,
354 MBTK_LTE_EXT_BAND_69 = 16
355} mbtk_lte_ext_band_enum;
356
b.liub4772072024-08-15 14:47:03 +0800357typedef struct
358{
359 uint8 type; // 0: GSM 1: UMTS 2: LTE
360 bool running;
361
362 int cell_num;
363 mbtk_cell_info_t cell[CELL_NUM_MAX];
364} mbtK_cell_pack_info_t;
365
b.liu87afc4c2024-08-14 17:33:45 +0800366#ifdef __cplusplus
367extern "C" {
368#endif
369
370char* type2str(ril_msg_type_enum type);
371
372char* apn2str(mbtk_ip_type_enum type);
373
374/*
375IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
376*/
377int str_2_ipv6(const void *ip_str, void *ipv6);
378
379/*
380IPv6 : uint128 -> fe80::215:1dff:fe81:484c
381*/
382int ipv6_2_str(const void *ipv6, void *ipv6_str);
383
384char* id2str(int id);
385
386char* err2str(mbtk_ril_err_enum err);
387
388void *mbtk_memcpy(const void *src, unsigned int n);
389
390/*
3910 GSM
3921 GSM_COMPACT
3932 UTRAN
3943 GSM_EGPRS
3954 UTRAN_HSDPA
3965 UTRAN_HSUPA
3976 UTRAN_HSDPA_HSUPA
3987 EUTRAN
3998 ECGSM
400*/
401mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
402
403void ril_msg_pack_free(ril_msg_pack_info_t* pack);
404
b.liub171c9a2024-11-12 19:23:29 +0800405ril_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 +0800406
407int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
408
409ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
410
411#ifdef __cplusplus
412}
413#endif
414
415
416#endif /* MBTK_INFO_INCLUDE */
417
418