blob: e32b1dd6465b7bd78a7c9168ac575fa153e0c0be [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"
14#define RIL_SOCK_MSG_LEN_MAX 2048
15
16// Tag(4) + Packet_Length(2)
17#define RIL_SOCK_PACK_EXTRA_LEN 6
18// RIL_SOCK_PACK_EXTRA_LEN + Index(2) + Type(2) + Id(2) + Error(2) + data_len(2)
19#define RIL_SOCK_PACK_LEN_MIN (RIL_SOCK_PACK_EXTRA_LEN + 10)
20
21#define RIL_MSG_INDEX_AUTO (-1) // automatically , refor to : ril_index
22#define RIL_MSG_INDEX_INVALID (0) // Invalid msg index.
23
24typedef enum
25{
26 RIL_MSG_TYPE_REQ,
27 RIL_MSG_TYPE_RSP,
28 RIL_MSG_TYPE_IND
29} ril_msg_type_enum;
30
31typedef enum
32{
33 // Device Information
34 RIL_MSG_ID_DEV_BEGIN = 0,
35 // <string> IMEI
36 RIL_MSG_ID_DEV_IMEI,
37 // <string> SN
38 RIL_MSG_ID_DEV_SN,
39 // <string> MEID
40 RIL_MSG_ID_DEV_MEID,
41 // <string> VERSION
42 RIL_MSG_ID_DEV_VERSION,
43 // <string> MODEL
44 RIL_MSG_ID_DEV_MODEL,
45 // <uint8> 0:Close 1:Open
46 RIL_MSG_ID_DEV_VOLTE,
47 // <string> Temperature
48 RIL_MSG_ID_DEV_TEMP, // Temperature
49 // <string> 23/03/20,01:58:00+32
50 RIL_MSG_ID_DEV_CELL_TIME, // Time
51 // <uint8><uint8>
52 RIL_MSG_ID_DEV_MODEM,
53
54 RIL_MSG_ID_DEV_END,
55
56 // Sim Information
57 RIL_MSG_ID_SIM_BEGIN = 1000,
58 // <uint8> 0:NOT_EXIST 1:READY ...
59 RIL_MSG_ID_SIM_STATE,
60 // <uint8> 0: SIM 1: USIM 2: TEST SIM 3: TEST USIM 4: UNKNOWN
61 RIL_MSG_ID_SIM_TYPE,
62 // <string> IMSI
63 RIL_MSG_ID_SIM_IMSI,
64 // <string> ICCID
65 RIL_MSG_ID_SIM_ICCID,
66 // <string> Phone Number
67 RIL_MSG_ID_SIM_PN,
68 // <string> PUK
69 RIL_MSG_ID_SIM_LOCK,
70 // <uint8> <uint8> <uint8> <uint8> PIN PUK LAST TIMES
71 RIL_MSG_ID_SIM_PINPUK_TIMES,
72 // <string> PLMN
73 RIL_MSG_ID_SIM_PLMN,
74
75 RIL_MSG_ID_SIM_END,
76
77 // Network Information
78 RIL_MSG_ID_NET_BEGIN = 2000,
79 // sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
80 RIL_MSG_ID_NET_AVAILABLE,
81 // <uint8> 0: automatic 1: manual
82 // or
83 // sel_mode(uint8)type(uint8)plmn(uint32)
84 RIL_MSG_ID_NET_SEL_MODE,
85 // mbtk_band_info_t
86 RIL_MSG_ID_NET_BAND,
87 // mbtk_signal_info_t
88 RIL_MSG_ID_NET_SIGNAL,
89 // mbtk_net_reg_info_t
90 RIL_MSG_ID_NET_REG,
91 // mbtk_cell_info_t[]
92 RIL_MSG_ID_NET_CELL,
93 // mbtk_apn_info_t
94 RIL_MSG_ID_NET_APN,
95 // REQ:
96 // <call_type[1]><cid[1]><timeout[1]>
97 // call_type : mbtk_data_call_type_enum
98 // cid : 1 - 15
99 // timeout : second
100 // RSP:
101 // <type[1]><ipv4><ipv6>
102 // type : 0-IPV4 1-IPV6 2-IPV4V6
103 // ipv4 : mbtk_ipv4_info_t
104 // ipv6 : mbtk_ipv6_info_t
105 RIL_MSG_ID_NET_DATA_CALL,
106
107 RIL_MSG_ID_NET_END,
108
109
110 // Call Information
111 RIL_MSG_ID_CALL_BEGIN = 3000,
112 RIL_MSG_ID_CALL_STATE,
113
114 // Start call.
115 RIL_MSG_ID_CALL_START,
116 //answer call
117 RIL_MSG_ID_CALL_ANSWER,
118 //hang up all call
119 RIL_MSG_ID_CALL_HANGUP,
120 //hang up a call
121 RIL_MSG_ID_CALL_HANGUP_A,
122 //hang up waiting or background call
123 RIL_MSG_ID_CALL_HANGUP_B,
124 //hang up foreground resume background
125 RIL_MSG_ID_CALL_HANGUP_C,
126 //wait in call
127 RIL_MSG_ID_CALL_WAITIN,
128 //mute call
129 RIL_MSG_ID_CALL_MUTE,
130 //dtmf call
131 RIL_MSG_ID_CALL_DTMF,
132 RIL_MSG_ID_CALL_END,
133
134 // SMS Information
135 RIL_MSG_ID_SMS_BEGIN = 4000,
136 RIL_MSG_ID_SMS_STATE,
137 RIL_MSG_ID_SMS_CMGF,
138 RIL_MSG_ID_SMS_CPMS,
139 RIL_MSG_ID_SMS_CMGS,
140 RIL_MSG_ID_SMS_CMSS,
141 RIL_MSG_ID_SMS_CMGR,
142 RIL_MSG_ID_SMS_CMGW,
143 RIL_MSG_ID_SMS_CMGD,
144 RIL_MSG_ID_SMS_CMGL,
145 RIL_MSG_ID_SMS_CSCA,
146 RIL_MSG_ID_SMS_CSMP,
147 RIL_MSG_ID_SMS_CSCB,
148 RIL_MSG_ID_SMS_CNMI,
149
150 RIL_MSG_ID_SMS_END,
151
152 // PhoneBook Information
153 RIL_MSG_ID_PB_BEGIN = 5000,
154 RIL_MSG_ID_PB_STATE,
155
156 RIL_MSG_ID_PB_END,
157
158 // IND Information
159 RIL_MSG_ID_IND_BEGIN = 10000,
160 // NULL
161 RIL_MSG_ID_IND_SER_READY,
162 // <uint8> State
163 RIL_MSG_ID_IND_NET_STATE_CHANGE,
164 // <uint8> State
165 RIL_MSG_ID_IND_CALL_STATE_CHANGE,
166 // <uint8> State
167 RIL_MSG_ID_IND_SMS_STATE_CHANGE,
168 // <uint8> State
169 RIL_MSG_ID_IND_RADIO_STATE_CHANGE,
170 // <uint8> State
171 RIL_MSG_ID_IND_SIM_STATE_CHANGE,
172 // <uint8> State
173 RIL_MSG_ID_IND_PDP_STATE_CHANGE,
174 // <uint8> State
175 RIL_MSG_ID_IND_SIGNAL_STATE_CHANGE,
176
177
178 RIL_MSG_ID_IND_END,
179 RIL_MSG_ID_UNKNOWN // Unknown information.
180} ril_msg_id_enum;
181
182typedef struct {
183 uint32 tag; // Refor to : RIL_SOCK_PACKET_TAG
184 uint16 msg_len;
185
186 uint16 msg_index; // Message index(Start from 1)
187 // 0 : For unknown msg id
188 uint16 msg_type; // Refor to : ril_msg_type_enum
189 uint16 msg_id; // Refor to : ril_msg_id_enum
190 uint16 err; // Only for RSP(Refor to : mbtk_ril_err_enum)
191 uint16 data_len;
192 uint8 *data;
193} __attribute__((packed)) ril_msg_pack_info_t;
194
195typedef struct {
196 pthread_t pid;
197 char name[20];
198 bool is_waitting;
199 pthread_cond_t cond;
200 pthread_mutex_t mutex;
201} ril_cli_thread_info_t;
202
203typedef struct {
204 pthread_t pid;
205 bool is_async;
206 int *rsp_data_len; // Save response data length.
207 char *rsp_data; // Save response date.
208 int *rsp_err; // Save response error, refor to mbtk_ril_err_enum .
209 ril_msg_pack_info_t *pack;
210} ril_msg_info_t;
211
212/*
213GSM band��
214 1 �C PGSM 900 (standard or primary)
215 2 �C DCS GSM 1800
216 4 �C PCS GSM 1900
217 8 �C EGSM 900 (extended)
218 16 �C GSM 450
219 32 �C GSM 480
220 64 �C GSM 850
221 512 - BAND_LOCK_BIT // used for GSM band setting
222*/
223typedef enum
224{
225 MBTK_GSM_BAND_PGSM_900 = 1,
226 MBTK_GSM_BAND_DCS_GSM_1800 = 2,
227 MBTK_GSM_BAND_PCS_GSM_1900 = 4,
228 MBTK_GSM_BAND_EGSM_900 = 8,
229 MBTK_GSM_BAND_GSM_450 = 16,
230 MBTK_GSM_BAND_GSM_480 = 32,
231 MBTK_GSM_BAND_GSM_850 = 64,
232 MBTK_GSM_BAND_BAND_LOCK_BIT = 512
233} mbtk_gsm_band_enum;
234
235/*
236UMTS band��
237 1 �C UMTS_BAND_1
238 2 �C UMTS_BAND_2
239 4 �C UMTS_BAND_3
240 8 �C UMTS_BAND_4
241 16 �C UMTS_BAND_5
242 32 �C UMTS_BAND_6
243 64 �C UMTS_BAND_7
244 128 �C UMTS_BAND_8
245 256 �C UMTS_BAND_9
246*/
247typedef enum
248{
249 MBTK_UMTS_BAND_1 = 1,
250 MBTK_UMTS_BAND_2 = 2,
251 MBTK_UMTS_BAND_3 = 4,
252 MBTK_UMTS_BAND_4 = 8,
253 MBTK_UMTS_BAND_5 = 16,
254 MBTK_UMTS_BAND_6 = 32,
255 MBTK_UMTS_BAND_7 = 64,
256 MBTK_UMTS_BAND_8 = 128,
257 MBTK_UMTS_BAND_9 = 256
258} mbtk_umts_band_enum;
259
260/*
261LTEbandH(TDD-LTE band)
262 32 �C TDLTE_BAND_38
263 64 �C TDLTE_BAND_39
264 128 �C TDLTE_BAND_40
265 256 �C TDLTE_BAND_41
266*/
267typedef enum
268{
269 MBTK_TDLTE_BAND_38 = 32,
270 MBTK_TDLTE_BAND_39 = 64,
271 MBTK_TDLTE_BAND_40 = 128,
272 MBTK_TDLTE_BAND_41 = 256
273} mbtk_tdlte_band_enum;
274
275/*
276LTEbandL(FDD-LTE band)
277 1 �C FDDLTE_BAND_1
278 4 �C FDDLTE _BAND_3
279 8 �C FDDLTE _BAND_4
280 64 �C FDDLTE _BAND_7
281 65536 �C FDDLTE _BAND_17
282 524288 �C FDDLTE _BAND_20
283*/
284typedef enum
285{
286 MBTK_FDDLTE_BAND_1 = 1,
287 MBTK_FDDLTE_BAND_3 = 4,
288 MBTK_FDDLTE_BAND_4 = 8,
289 MBTK_FDDLTE_BAND_7 = 64,
290 MBTK_FDDLTE_BAND_17 = 65536,
291 MBTK_FDDLTE_BAND_20 = 524288
292} mbtk_fddlte_band_enum;
293
294typedef enum
295{
296 MBTK_LTE_EXT_BAND_65 = 1,
297 MBTK_LTE_EXT_BAND_66 = 2,
298 MBTK_LTE_EXT_BAND_67 = 4,
299 MBTK_LTE_EXT_BAND_68 = 8,
300 MBTK_LTE_EXT_BAND_69 = 16
301} mbtk_lte_ext_band_enum;
302
b.liub4772072024-08-15 14:47:03 +0800303typedef struct
304{
305 uint8 type; // 0: GSM 1: UMTS 2: LTE
306 bool running;
307
308 int cell_num;
309 mbtk_cell_info_t cell[CELL_NUM_MAX];
310} mbtK_cell_pack_info_t;
311
b.liu87afc4c2024-08-14 17:33:45 +0800312#ifdef __cplusplus
313extern "C" {
314#endif
315
316char* type2str(ril_msg_type_enum type);
317
318char* apn2str(mbtk_ip_type_enum type);
319
320/*
321IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239 -> uint128
322*/
323int str_2_ipv6(const void *ip_str, void *ipv6);
324
325/*
326IPv6 : uint128 -> fe80::215:1dff:fe81:484c
327*/
328int ipv6_2_str(const void *ipv6, void *ipv6_str);
329
330char* id2str(int id);
331
332char* err2str(mbtk_ril_err_enum err);
333
334void *mbtk_memcpy(const void *src, unsigned int n);
335
336/*
3370 GSM
3381 GSM_COMPACT
3392 UTRAN
3403 GSM_EGPRS
3414 UTRAN_HSDPA
3425 UTRAN_HSUPA
3436 UTRAN_HSDPA_HSUPA
3447 EUTRAN
3458 ECGSM
346*/
347mbtk_net_type_enum mbtk_net_type_get(mbtk_radio_technology_enum radio_tech);
348
349void ril_msg_pack_free(ril_msg_pack_info_t* pack);
350
351ril_msg_pack_info_t* ril_msg_pack_creat(int msg_type, int msg_id, int msg_index, const void *data, int data_len);
352
353int ril_pack_send(int fd, ril_msg_pack_info_t *pack);
354
355ril_msg_pack_info_t** ril_pack_recv(int fd, bool is_server, mbtk_ril_err_enum *err);
356
357#ifdef __cplusplus
358}
359#endif
360
361
362#endif /* MBTK_INFO_INCLUDE */
363
364