blob: efd67fc7fd95da72d74f78195daab10b87afe87d [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
228 RIL_URC_MSG_NET_STATE_LOG, // Save Network state into file.
229 RIL_URC_MSG_END,
230
231 RIL_MSG_ID_UNKNOWN = 0xFFFF // Unknown information.
b.liu87afc4c2024-08-14 17:33:45 +0800232} ril_msg_id_enum;
233
234typedef struct {
235 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
236 uint16 msg_len;
237
b.liub171c9a2024-11-12 19:23:29 +0800238 uint8 at_port; // ATPortType_enum
b.liu87afc4c2024-08-14 17:33:45 +0800239 uint16 msg_index; // Message index(Start from 1)
240 // 0 : For unknown msg id
241 uint16 msg_type; // Refor to : ril_msg_type_enum
242 uint16 msg_id; // Refor to : ril_msg_id_enum
243 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
244 uint16 data_len;
245 uint8 *data;
246} __attribute__((packed)) ril_msg_pack_info_t;
247
248typedef struct {
249 pthread_t pid;
250 char name[20];
251 bool is_waitting;
252 pthread_cond_t cond;
253 pthread_mutex_t mutex;
254} ril_cli_thread_info_t;
255
256typedef struct {
257 pthread_t pid;
258 bool is_async;
259 int *rsp_data_len; // Save response data length.
260 char *rsp_data; // Save response date.
261 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
262 ril_msg_pack_info_t *pack;
263} ril_msg_info_t;
264
265/*
266GSM band��
267 1 �C PGSM 900 (standard or primary)
268 2 �C DCS GSM 1800
269 4 �C PCS GSM 1900
270 8 �C EGSM 900 (extended)
271 16 �C GSM 450
272 32 �C GSM 480
273 64 �C GSM 850
274 512 - BAND_LOCK_BIT // used for GSM band setting
275*/
276typedef enum
277{
278 MBTK_GSM_BAND_PGSM_900 = 1,
279 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
280 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
281 MBTK_GSM_BAND_EGSM_900 = 8,
282 MBTK_GSM_BAND_GSM_450 = 16,
283 MBTK_GSM_BAND_GSM_480 = 32,
284 MBTK_GSM_BAND_GSM_850 = 64,
285 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
286} mbtk_gsm_band_enum;
287
288/*
289UMTS band��
290 1 �C UMTS_BAND_1
291 2 �C UMTS_BAND_2
292 4 �C UMTS_BAND_3
293 8 �C UMTS_BAND_4
294 16 �C UMTS_BAND_5
295 32 �C UMTS_BAND_6
296 64 �C UMTS_BAND_7
297 128 �C UMTS_BAND_8
298 256 �C UMTS_BAND_9
299*/
300typedef enum
301{
302 MBTK_UMTS_BAND_1 = 1,
303 MBTK_UMTS_BAND_2 = 2,
304 MBTK_UMTS_BAND_3 = 4,
305 MBTK_UMTS_BAND_4 = 8,
306 MBTK_UMTS_BAND_5 = 16,
307 MBTK_UMTS_BAND_6 = 32,
308 MBTK_UMTS_BAND_7 = 64,
309 MBTK_UMTS_BAND_8 = 128,
310 MBTK_UMTS_BAND_9 = 256
311} mbtk_umts_band_enum;
312
313/*
314LTEbandH(TDD-LTE band)
315 32 �C TDLTE_BAND_38
316 64 �C TDLTE_BAND_39
317 128 �C TDLTE_BAND_40
318 256 �C TDLTE_BAND_41
319*/
320typedef enum
321{
322 MBTK_TDLTE_BAND_38 = 32,
323 MBTK_TDLTE_BAND_39 = 64,
324 MBTK_TDLTE_BAND_40 = 128,
325 MBTK_TDLTE_BAND_41 = 256
326} mbtk_tdlte_band_enum;
327
328/*
329LTEbandL(FDD-LTE band)
330 1 �C FDDLTE_BAND_1
331 4 �C FDDLTE _BAND_3
332 8 �C FDDLTE _BAND_4
333 64 �C FDDLTE _BAND_7
334 65536 �C FDDLTE _BAND_17
335 524288 �C FDDLTE _BAND_20
336*/
337typedef enum
338{
339 MBTK_FDDLTE_BAND_1 = 1,
340 MBTK_FDDLTE_BAND_3 = 4,
341 MBTK_FDDLTE_BAND_4 = 8,
342 MBTK_FDDLTE_BAND_7 = 64,
343 MBTK_FDDLTE_BAND_17 = 65536,
344 MBTK_FDDLTE_BAND_20 = 524288
345} mbtk_fddlte_band_enum;
346
347typedef enum
348{
349 MBTK_LTE_EXT_BAND_65 = 1,
350 MBTK_LTE_EXT_BAND_66 = 2,
351 MBTK_LTE_EXT_BAND_67 = 4,
352 MBTK_LTE_EXT_BAND_68 = 8,
353 MBTK_LTE_EXT_BAND_69 = 16
354} mbtk_lte_ext_band_enum;
355
b.liub4772072024-08-15 14:47:03 +0800356typedef struct
357{
358 uint8 type; // 0: GSM 1: UMTS 2: LTE
359 bool running;
360
361 int cell_num;
362 mbtk_cell_info_t cell[CELL_NUM_MAX];
363} mbtK_cell_pack_info_t;
364
b.liu87afc4c2024-08-14 17:33:45 +0800365#ifdef __cplusplus
366extern "C" {
367#endif
368
369char* type2str(ril_msg_type_enum type);
370
371char* apn2str(mbtk_ip_type_enum type);
372
373/*
374IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
375*/
376int str_2_ipv6(const void *ip_str, void *ipv6);
377
378/*
379IPv6 : uint128 -> fe80::215:1dff:fe81:484c
380*/
381int ipv6_2_str(const void *ipv6, void *ipv6_str);
382
383char* id2str(int id);
384
385char* err2str(mbtk_ril_err_enum err);
386
387void *mbtk_memcpy(const void *src, unsigned int n);
388
389/*
3900 GSM
3911 GSM_COMPACT
3922 UTRAN
3933 GSM_EGPRS
3944 UTRAN_HSDPA
3955 UTRAN_HSUPA
3966 UTRAN_HSDPA_HSUPA
3977 EUTRAN
3988 ECGSM
399*/
400mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
401
402void ril_msg_pack_free(ril_msg_pack_info_t* pack);
403
b.liub171c9a2024-11-12 19:23:29 +0800404ril_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 +0800405
406int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
407
408ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
409
410#ifdef __cplusplus
411}
412#endif
413
414
415#endif /* MBTK_INFO_INCLUDE */
416
417