blob: f8bedb66679a6dd857b745900709c9eafed54cb8 [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <errno.h>
5#include <sys/socket.h>
6#include <sys/un.h>
7#include <netinet/in.h>
8#include <pthread.h>
9#include <sys/epoll.h>
10#include <string.h>
11#include <fcntl.h>
12#include <signal.h>
b.liu62240ee2024-11-07 17:52:45 +080013#include <arpa/inet.h>
b.liu87afc4c2024-08-14 17:33:45 +080014
15#include "mbtk_ril_api.h"
b.liu62240ee2024-11-07 17:52:45 +080016#include "mbtk_str.h"
b.liu87afc4c2024-08-14 17:33:45 +080017
18#define CLI_THREAD_MAX 3
19
b.liu62240ee2024-11-07 17:52:45 +080020#define RIL_DEBUG_THREAD 0
21
22#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +080023typedef struct {
24 pthread_t pid;
25 bool is_running;
26 char name[20];
27} ril_cli_thread_info_t;
28
29static ril_cli_thread_info_t cli_threads[CLI_THREAD_MAX];
30static int cli_pid_index = 1;
b.liu62240ee2024-11-07 17:52:45 +080031#endif
b.liu87afc4c2024-08-14 17:33:45 +080032
33static void help()
34{
35 printf("version: Get version.\n");
36 printf("imei: Get IMEI.\n");
37 printf("sn: Get SN.\n");
38 printf("meid: Get MEID.\n");
39 printf("volte: Get VoLTE state.\n");
40 printf("volte 0: Close VoLTE.\n");
41 printf("volte 1: Open VoLTE.\n");
42 printf("radio: Get radio state.\n");
43 printf("radio 0 [0/1]: Close radio.\n");
44 printf("radio 1 [0/1]: Open radio.\n");
45 printf("temp <0,1>: Get SOC/RF temperature.\n");
46 printf("cell_time: Get cell time.\n");
47 printf("sim_state: Get sim state.\n");
48 printf("sim_type: Get sim type.\n");
49 printf("imsi: Get IMSI.\n");
50 printf("iccid: Get ICCID.\n");
51 printf("pn: Get Phone Number.\n");
52 printf("pin_state:Get Sim lock state.\n");
53 printf("pin_times:Get PIN/PUK last times.\n");
54 printf("pin_open <PIN>:Enable sim lock.\n");
55 printf("pin_close <PIN>:Disable sim lock.\n");
56 printf("pin_change <old_pin> <new_pin>:Change sim PIN.\n");
57 printf("pin_verify <PIN>:Verify PIN.\n");
58 printf("puk_verify <PUK> <PIN>:Verify PUK.\n");
59 printf("plmn:Get PLMN List.\n");
60 printf("avail_net: Get available network.\n");
61 printf("sel_mode: Get network select mode.\n");
62 printf("sel_mode <sel_mode> <net_type> <plmn>: Set network select mode.\n");
63 printf("band: Get current bands.\n");
b.liubeb61cc2025-02-13 10:38:29 +080064 printf("band_support: Get support bands.\n");
65 printf("band <net_pref> <gsm_band> <umts_band> <tdlte_band> <fddlte_band> <nr_band_3> <nr_band_2> <nr_band_1> <nr_band_0>: Set current bands.\n");
b.liu87afc4c2024-08-14 17:33:45 +080066 printf("signal: Get network signal.\n");
67 printf("reg: Get network registe information.\n");
68 printf("cell: Get current cell information.\n");
69 printf("shutdown <0,1,2>: reboot/poweroff/halt system.\n");
70 printf("power_sim <0,1>: Power off/on sim.\n");
71 printf("time <0,1,2> YYYY-MM-DD HH:MM:SS : Set system time as CELL/NTP/User.\n");
72 printf("apn : Get current apns.\n");
b.liubcf86c92024-08-19 19:48:28 +080073 printf("apn <cid> <ip_type:1/2/3/4> <save:0/1> <auto_call:0/1> <def_route:0/1> <as_dns:0/1> <apn/null> : Set apn.\n");
b.liu87afc4c2024-08-14 17:33:45 +080074 printf("apn_del <cid> <save:0/1> : Delete APN.\n");
b.liubcf86c92024-08-19 19:48:28 +080075 printf("data_call <0/1/2> <cid> <auto_boot_call> <def_route> <as_dns>: Stop/Start/State data call.\n");
b.liu87afc4c2024-08-14 17:33:45 +080076 printf("call: Call the phone number.\n");
77 printf("answer: Answer the phone call.\n");
78 printf("hangup: Hang up all phone call. No id.\n");
79 printf("hangup 0: Hang up waiting or background phone call.\n");
80 printf("hangup 1: Hang up a phone call.\n");
81 printf("hangup 2: Hang up a phone call.\n");
82 printf("hangup 3: Hangup foreground resume background call.\n");
83 printf("waitin: Returns the list of current calls.\n");
84 printf("mute: Get mute state.\n");
85 printf("mute 0: Close mute.\n");
86 printf("mute 1: Open mute.\n");
87 printf("dtmf : Set dtmf character[0, 1, 2, ..., A, B, C, D, *, #], duration [300-600].\n Such as: dtmf 0 300\n");
88 printf("ims_en 0/1 : Close/Open IMS(Restart takes effect).\n");
89 printf("ims_state : Get IMS open or not?\n");
90 printf("ims_reg: Get IMS register state.\n");
91}
92
b.liu62240ee2024-11-07 17:52:45 +080093#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +080094static void thread_exit_with_wait()
95{
96 int i = 0;
97 while(i < CLI_THREAD_MAX) {
98 cli_threads[i].is_running = FALSE;
99 i++;
100 }
101
102 i = 0;
103 while(i < CLI_THREAD_MAX) {
104 if(cli_threads[i].pid) {
105 pthread_join(cli_threads[i].pid, NULL);
106 printf("Thread (%s) exit.\n", cli_threads[i].name);
107 }
108 i++;
109 }
110}
b.liu62240ee2024-11-07 17:52:45 +0800111#endif
b.liu87afc4c2024-08-14 17:33:45 +0800112
b.liu15f456b2024-10-31 20:16:06 +0800113static void ril_ser_state_change_cb(const void* data, int data_len)
114{
115 if(data) {
b.liu62240ee2024-11-07 17:52:45 +0800116 const uint8 *ptr = (const uint8*)data;
b.liu15f456b2024-10-31 20:16:06 +0800117 mbtk_ril_ser_state_enum state = (mbtk_ril_ser_state_enum)ptr[0];
118 printf("ril server state : %d.\n", state);
119 }
120}
121
122static void net_reg_state_change_cb(const void* data, int data_len)
123{
124 if(data) {
125 mbtk_ril_net_reg_state_info_t *state = (mbtk_ril_net_reg_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800126 printf("net reg state change : sim_id - %d, type - %d, tech - %d, reg_state - %d, TAG - %llx, ci - %llx\n",
127 state->sim_id, state->type,
b.liubeb61cc2025-02-13 10:38:29 +0800128 state->tech, state->reg_state, state->tac, state->ci);
b.liu15f456b2024-10-31 20:16:06 +0800129 }
130}
131
132static void call_state_change_cb(const void* data, int data_len)
133{
134 if(data) {
135 mbtk_ril_call_state_info_t *state = (mbtk_ril_call_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800136 printf("call state change : sim_id - %d, call_id-%d, dir-%d, state-%d, num_type-%d, number-%s\n",
137 state->sim_id, state->call_id,
b.liu15f456b2024-10-31 20:16:06 +0800138 state->dir, state->state, state->num_type, state->call_number);
139 }
140}
141
142static void sms_state_change_cb(const void* data, int data_len)
143{
b.liuaced4f92024-12-31 11:14:51 +0800144 if(data) {
145 mbtk_ril_sms_state_info_t *state = (mbtk_ril_sms_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800146 printf("sms state change : sim_id - %d, SMS PDU(%d) : %s\n", state->sim_id, state->pdu_len, state->pdu);
b.liuaced4f92024-12-31 11:14:51 +0800147 }
b.liu15f456b2024-10-31 20:16:06 +0800148}
149
150static void radio_state_change_cb(const void* data, int data_len)
151{
152 if(data) {
153 mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800154 printf("radio state change : sim_id - %d, radio_state - %d\n", state->sim_id, state->radio_state);
b.liu15f456b2024-10-31 20:16:06 +0800155 }
156}
157
158static void sim_state_change_cb(const void* data, int data_len)
159{
160 if(data) {
161 mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800162 printf("sim state change : sim_id - %d, type - %d, state - %d\n", state->sim_id, state->sim_type, state->sim_state);
b.liu15f456b2024-10-31 20:16:06 +0800163 }
164}
165
166static void pdp_state_change_cb(const void* data, int data_len)
167{
168 if(data) {
169 mbtk_ril_pdp_state_info_t *state = (mbtk_ril_pdp_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800170 printf("pdp state change : sim_id - %d, cid - %d, action - %d, reason-%d, auto_change - %d\n",
171 state->sim_id, state->cid, state->action, state->reason, state->auto_change);
b.liufd87baf2024-11-15 15:30:38 +0800172 if(state->ip_info_valid) {
173 if(state->ip_info.ipv4.valid) {
174 // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t));
175 char ip_tmp[20];
176
177 memset(ip_tmp, 0, 20);
178 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.IPAddr), ip_tmp, 20) == NULL) {
179 printf("IP error.\n");
180 } else {
181 printf("IP : %s\n", ip_tmp);
182 }
183
184 memset(ip_tmp, 0, 20);
185 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.PrimaryDNS), ip_tmp, 20) == NULL) {
186 printf("PrimaryDNS error.\n");
187 } else {
188 printf("PrimaryDNS : %s\n", ip_tmp);
189 }
190
191 memset(ip_tmp, 0, 20);
192 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.SecondaryDNS), ip_tmp, 20) == NULL) {
193 printf("SecondaryDNS error.\n");
194 } else {
195 printf("SecondaryDNS : %s\n", ip_tmp);
196 }
197
198 memset(ip_tmp, 0, 20);
199 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.GateWay), ip_tmp, 20) == NULL) {
200 printf("GateWay error.\n");
201 } else {
202 printf("GateWay : %s\n", ip_tmp);
203 }
204
205 memset(ip_tmp, 0, 20);
206 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.NetMask), ip_tmp, 20) == NULL) {
207 printf("NetMask error.\n");
208 } else {
209 printf("NetMask : %s\n", ip_tmp);
210 }
211 }
212
213 if(state->ip_info.ipv6.valid) {
214 // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t));
215 char ip_tmp[50];
216
217 memset(ip_tmp, 0, 50);
218 if(ipv6_2_str(&(state->ip_info.ipv6.IPV6Addr), ip_tmp)) {
219 printf("IP error.\n");
220 } else {
221 printf("IP : %s\n", ip_tmp);
222 }
223
224 memset(ip_tmp, 0, 50);
225 if(ipv6_2_str(&(state->ip_info.ipv6.PrimaryDNS), ip_tmp)) {
226 printf("PrimaryDNS error.\n");
227 } else {
228 printf("PrimaryDNS : %s\n", ip_tmp);
229 }
230
231 memset(ip_tmp, 0, 50);
232 if(ipv6_2_str(&(state->ip_info.ipv6.SecondaryDNS), ip_tmp)) {
233 printf("SecondaryDNS error.\n");
234 } else {
235 printf("SecondaryDNS : %s\n", ip_tmp);
236 }
237
238 memset(ip_tmp, 0, 50);
239 if(ipv6_2_str(&(state->ip_info.ipv6.GateWay), ip_tmp)) {
240 printf("GateWay error.\n");
241 } else {
242 printf("GateWay : %s\n", ip_tmp);
243 }
244
245 memset(ip_tmp, 0, 50);
246 if(ipv6_2_str(&(state->ip_info.ipv6.NetMask), ip_tmp)) {
247 printf("NetMask error.\n");
248 } else {
249 printf("NetMask : %s\n", ip_tmp);
250 }
251 }
252 }
b.liu15f456b2024-10-31 20:16:06 +0800253 }
254}
255
256static void signal_state_change_cb(const void* data, int data_len)
257{
258
259}
260
261static void ecall_state_change_cb(const void* data, int data_len)
262{
263 if(data)
264 {
265 mbtk_ril_ecall_state_info_t *ecall_data = (mbtk_ril_ecall_state_info_t*)data;
b.liu7ca612c2025-04-25 09:23:36 +0800266 printf("ecall state change : sim_id - %d, urc_id - %d, urc_data - %s\n", ecall_data->sim_id, ecall_data->urc_id, ecall_data->urc_data);
b.liu15f456b2024-10-31 20:16:06 +0800267 }
268}
269
270
b.liu87afc4c2024-08-14 17:33:45 +0800271static void sig_process(int sig)
272{
273 LOGI("I got signal %d\n", sig);
274 switch(sig)
275 {
276 case SIGINT: // Ctrl + C
277 {
278 LOGI("Exit by SIGINT.\n");
b.liu62240ee2024-11-07 17:52:45 +0800279#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800280 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800281#endif
b.liub171c9a2024-11-12 19:23:29 +0800282 mbtk_ril_close(MBTK_AT_PORT_DEF);
b.liu7ca612c2025-04-25 09:23:36 +0800283 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liu87afc4c2024-08-14 17:33:45 +0800284 exit(0);
285 }
286 case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件)
287 {
288 LOGI("Exit by SIGQUIT.\n");
b.liu62240ee2024-11-07 17:52:45 +0800289#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800290 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800291#endif
b.liub171c9a2024-11-12 19:23:29 +0800292 mbtk_ril_close(MBTK_AT_PORT_DEF);
b.liu7ca612c2025-04-25 09:23:36 +0800293 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liu87afc4c2024-08-14 17:33:45 +0800294 exit(0);
295 }
296 case SIGTERM:// 默认kill (同 SIGKILL ,但 SIGKILL 不可捕获)
297 {
298 LOGI("Exit by SIGTERM.\n");
b.liu62240ee2024-11-07 17:52:45 +0800299#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800300 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800301#endif
b.liub171c9a2024-11-12 19:23:29 +0800302 mbtk_ril_close(MBTK_AT_PORT_DEF);
b.liu7ca612c2025-04-25 09:23:36 +0800303 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liu87afc4c2024-08-14 17:33:45 +0800304 exit(0);
305 }
306 case SIGTSTP:// Ctrl + Z (同 SIGSTOP ,但 SIGSTOP 不可捕获)
307 {
308 LOGI("Exit by SIGTSTP.\n");
309 exit(0);
310 }
311 case SIGSEGV: // 如空指针
312 {
313 LOGI("Exit by SIGSEGV.\n");
314 exit(0);
315 }
316 default:
317 {
318 LOGI("Unknown sig:%d\n",sig);
319 break;
320 }
321 }
322}
323
b.liu62240ee2024-11-07 17:52:45 +0800324#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800325static char* thread_id2name(pthread_t pid)
326{
327 int i = 0;
328 while(i < CLI_THREAD_MAX) {
329 if(pid == cli_threads[i].pid) {
330 return cli_threads[i].name;
331 }
332 i++;
333 }
334
335 return "UNKNOWN";
336}
337
338static void* sub_thread_run(void *arg)
339{
340 ril_cli_thread_info_t *cli = (ril_cli_thread_info_t*)arg;
341 cli->pid = pthread_self();
342 cli->is_running = TRUE;
343 sprintf(cli->name, "PID-%d", cli_pid_index++);
344
345 printf("[%s] enter.\n", thread_id2name(cli->pid));
346 while(cli->is_running) {
347 srand((int)(time(0) + cli->pid));
348 int time_sec = 1 + (int)(10.0 * rand() / ( RAND_MAX + 1.0));
349 char version[50] = {0};
350 mbtk_ril_err_enum err = mbtk_version_get(version);
351 if(err != MBTK_RIL_ERR_SUCCESS) {
352 printf("[%s : %ds]Error : %d\n", thread_id2name(cli->pid), time_sec, err);
353 } else {
354 printf("[%s : %ds]Version : %s\n", thread_id2name(cli->pid), time_sec, version);
355 }
356
357 sleep(time_sec);
358 }
359 printf("[%s] exit.\n", thread_id2name(cli->pid));
360 return NULL;
361}
b.liu62240ee2024-11-07 17:52:45 +0800362#endif
b.liu87afc4c2024-08-14 17:33:45 +0800363
364int main(int argc, char *argv[])
365{
366 signal(SIGINT, sig_process);
367 signal(SIGQUIT, sig_process);
368 signal(SIGTERM, sig_process);
369 //signal(SIGTSTP, sig_process);
370 //signal(SIGSEGV, sig_process);
371
372 mbtk_log_init("radio","RIL_CLI");
373
374#ifdef MBTK_DUMP_SUPPORT
375 mbtk_debug_open(NULL, TRUE);
376#endif
377
378 //test2(0, "192.168.1.198");
379 //test2(1, "2409:8162:140:cd3c:1:2:1494:72ba");
380 //test2(1, "254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239");
381 //test2(1, "2400:3200::1");
382
b.liub171c9a2024-11-12 19:23:29 +0800383 mbtk_ril_handle* handle_def = mbtk_ril_open(MBTK_AT_PORT_DEF);
384 if(handle_def == NULL) {
385 printf("mbtk_ril_open(MBTK_AT_PORT_DEF/ATPORTTYPE_0) fail.");
386 return -1;
387 }
388
b.liu7ca612c2025-04-25 09:23:36 +0800389 mbtk_ril_handle* handle_1 = mbtk_ril_open(MBTK_AT_PORT_VOICE);
b.liub171c9a2024-11-12 19:23:29 +0800390 if(handle_1 == NULL) {
391 printf("mbtk_ril_open(ATPORTTYPE_1) fail.");
b.liu87afc4c2024-08-14 17:33:45 +0800392 return -1;
393 }
394
b.liu15f456b2024-10-31 20:16:06 +0800395 mbtk_ril_ser_state_change_cb_reg(ril_ser_state_change_cb);
396
397 mbtk_net_reg_state_change_cb_reg(net_reg_state_change_cb);
398
399 mbtk_call_state_change_cb_reg(call_state_change_cb);
400
401 mbtk_sms_state_change_cb_reg(sms_state_change_cb);
402
403 mbtk_radio_state_change_cb_reg(radio_state_change_cb);
404
405 mbtk_sim_state_change_cb_reg(sim_state_change_cb);
406
407 mbtk_pdp_state_change_cb_reg(pdp_state_change_cb);
408
409 mbtk_signal_state_change_cb_reg(signal_state_change_cb);
410
411 mbtk_ecall_state_change_cb_reg(ecall_state_change_cb);
412
b.liu62240ee2024-11-07 17:52:45 +0800413#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800414 memset(cli_threads, 0, sizeof(ril_cli_thread_info_t) * CLI_THREAD_MAX);
415
416 pthread_t pid1, pid2, pid3;
417 if(pthread_create(&pid1, NULL, sub_thread_run, &cli_threads[0]))
418 {
419 printf("pthread_create() fail.");
420 goto exit;
421 }
422
423 if(pthread_create(&pid2, NULL, sub_thread_run, &cli_threads[1]))
424 {
425 printf("pthread_create() fail.");
426 goto exit;
427 }
428
429 if(pthread_create(&pid3, NULL, sub_thread_run, &cli_threads[2]))
430 {
431 printf("pthread_create() fail.");
432 goto exit;
433 }
434#endif
435 printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n");
436 char cmd[100];
437 while(1)
438 {
439 memset(cmd, 0, 100);
440 mbtk_ril_err_enum err;
441 if(fgets(cmd, 100, stdin))
442 {
443 char *ptr = cmd + strlen(cmd) - 1;
444 while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
445 {
446 *ptr-- = '\0';
447 }
448 if(!strncasecmp(cmd, "version", 7))
449 {
450 char version[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800451 err = mbtk_version_get(handle_def, version);
b.liu87afc4c2024-08-14 17:33:45 +0800452 if(err != MBTK_RIL_ERR_SUCCESS) {
453 printf("Error : %d\n", err);
454 } else {
455 printf("Version : %s\n", version);
456 }
457 }
458 else if(!strncasecmp(cmd, "imei", 4)){
459 char imei[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800460 err = mbtk_imei_get(handle_def, imei);
b.liu87afc4c2024-08-14 17:33:45 +0800461 if(err != MBTK_RIL_ERR_SUCCESS) {
462 printf("Error : %d\n", err);
463 } else {
464 printf("IMEI : %s\n", imei);
465 }
466 } else if(!strncasecmp(cmd, "sn", 2)){
467 char sn[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800468 err = mbtk_sn_get(handle_def, sn);
b.liu87afc4c2024-08-14 17:33:45 +0800469 if(err != MBTK_RIL_ERR_SUCCESS) {
470 printf("Error : %d\n", err);
471 } else {
472 printf("SN : %s\n", sn);
473 }
474 } else if(!strncasecmp(cmd, "meid", 4)){
475 char meid[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800476 err = mbtk_meid_get(handle_def, meid);
b.liu87afc4c2024-08-14 17:33:45 +0800477 if(err != MBTK_RIL_ERR_SUCCESS) {
478 printf("Error : %d\n", err);
479 } else {
480 printf("MEID : %s\n", meid);
481 }
482 } else if(!strncasecmp(cmd, "volte", 5)){ // "volte" or "volte 0" or "volte 1"
483 int volte;
484 if(!strcasecmp(cmd, "volte")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800485 err = mbtk_volte_state_get(handle_def, &volte);
b.liu87afc4c2024-08-14 17:33:45 +0800486 if(err != MBTK_RIL_ERR_SUCCESS) {
487 printf("Error : %d\n", err);
488 } else {
489 printf("VoLTE : %d\n", volte);
490 }
491 } else { // Set
492 if(!strcasecmp(cmd, "volte 1")) { // Open VoLTE
493 volte = 1;
494 } else { // Close VoLTE
495 volte = 0;
496 }
b.liub171c9a2024-11-12 19:23:29 +0800497 err = mbtk_volte_state_set(handle_def, volte);
b.liu87afc4c2024-08-14 17:33:45 +0800498 if(err != MBTK_RIL_ERR_SUCCESS) {
499 printf("Error : %d\n", err);
500 } else {
501 printf("VoLTE set success\n");
502 }
503 }
504 } else if(!strncasecmp(cmd, "radio", 5)){ // "radio" or "radio 0" or "radio 1"
505 mbtk_radio_state_enum radio;
506 if(!strcasecmp(cmd, "radio")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800507 err = mbtk_radio_state_get(handle_def, &radio);
b.liu87afc4c2024-08-14 17:33:45 +0800508 if(err != MBTK_RIL_ERR_SUCCESS) {
509 printf("Error : %d\n", err);
510 } else {
511 printf("Radio : %d\n", radio);
512 }
513 } else { // Set
514 int reset;
515 int count = sscanf(cmd, "radio %d %d", &radio, &reset);
516 if(count > 0) {
517 if(count == 1) {
518 reset = 0;
519 }
520
b.liub171c9a2024-11-12 19:23:29 +0800521 err = mbtk_radio_state_set(handle_def, radio, reset);
b.liu87afc4c2024-08-14 17:33:45 +0800522 if(err != MBTK_RIL_ERR_SUCCESS) {
523 printf("Error : %d\n", err);
524 } else {
525 printf("Radio set success\n");
526 }
527 }
528 }
529 } else if(!strncasecmp(cmd, "temp", 4)){
530 int temp;
531 if(!strcasecmp(cmd, "temp 0")) {
b.liub171c9a2024-11-12 19:23:29 +0800532 err = mbtk_temp_get(handle_def, MBTK_TEMP_TYPE_SOC, &temp);
b.liu87afc4c2024-08-14 17:33:45 +0800533 if(err != MBTK_RIL_ERR_SUCCESS) {
534 printf("Error : %d\n", err);
535 } else {
536 printf("SOC : %d\n", temp);
537 }
538 } else if(!strcasecmp(cmd, "temp 1")) {
b.liub171c9a2024-11-12 19:23:29 +0800539 err = mbtk_temp_get(handle_def, MBTK_TEMP_TYPE_RF, &temp);
b.liu87afc4c2024-08-14 17:33:45 +0800540 if(err != MBTK_RIL_ERR_SUCCESS) {
541 printf("Error : %d\n", err);
542 } else {
543 printf("RF : %d\n", temp);
544 }
545 }
546 } else if(!strncasecmp(cmd, "cell_time", 9)){
547 char time[128] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800548 err = mbtk_cell_time_get(handle_def, time);
b.liu87afc4c2024-08-14 17:33:45 +0800549 if(err != MBTK_RIL_ERR_SUCCESS) {
550 printf("Error : %d\n", err);
551 } else {
552 printf("Cell Time : %s\n", time);
553 }
554 } else if(!strncasecmp(cmd, "sim_state", 9)){
555 mbtk_sim_state_enum sim;
b.liub171c9a2024-11-12 19:23:29 +0800556 err = mbtk_sim_state_get(handle_def, &sim);
b.liu87afc4c2024-08-14 17:33:45 +0800557 if(err != MBTK_RIL_ERR_SUCCESS) {
558 printf("Error : %d\n", err);
559 } else {
560 printf("Sim State : %d\n", sim);
561 }
562 } else if(!strncasecmp(cmd, "sim_type", 8)){
563 mbtk_sim_card_type_enum type;
b.liub171c9a2024-11-12 19:23:29 +0800564 err = mbtk_sim_type_get(handle_def, &type);
b.liu87afc4c2024-08-14 17:33:45 +0800565 if(err != MBTK_RIL_ERR_SUCCESS) {
566 printf("Error : %d\n", err);
567 } else {
568 printf("Sim Type : %d\n", type);
569 }
570 } else if(!strncasecmp(cmd, "imsi", 4)){
571 char imsi[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800572 err = mbtk_imsi_get(handle_def, imsi);
b.liu87afc4c2024-08-14 17:33:45 +0800573 if(err != MBTK_RIL_ERR_SUCCESS) {
574 printf("Error : %d\n", err);
575 } else {
576 printf("IMSI : %s\n", imsi);
577 }
578 } else if(!strncasecmp(cmd, "iccid", 5)){
579 char iccid[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800580 err = mbtk_iccid_get(handle_def, iccid);
b.liu87afc4c2024-08-14 17:33:45 +0800581 if(err != MBTK_RIL_ERR_SUCCESS) {
582 printf("Error : %d\n", err);
583 } else {
584 printf("ICCID : %s\n", iccid);
585 }
586 } else if(!strncasecmp(cmd, "pn", 2)){
587 char phone_number[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800588 err = mbtk_phone_number_get(handle_def, phone_number);
b.liu87afc4c2024-08-14 17:33:45 +0800589 if(err != MBTK_RIL_ERR_SUCCESS) {
590 printf("Error : %d\n", err);
591 } else {
592 printf("Phone Number : %s\n", phone_number);
593 }
594 }
595 /*
596 printf("pin_state:Get Sim lock state.\n");
597 printf("pin_times:Get PIN/PUK last times.\n");
598 printf("pin_open <PIN>:Enable sim lock.\n");
599 printf("pin_close <PIN>:Disable sim lock.\n");
600 printf("pin_change <old_pin> <new_pin>:Change sim PIN.\n");
601 printf("pin_verify <PIN>:Verify PIN.\n");
602 printf("puk_verify <PUK> <PIN>:Verify PUK.\n");
603 */
604 else if(!strncasecmp(cmd, "pin_state", 9)){
605 int lock_state;
b.liub171c9a2024-11-12 19:23:29 +0800606 err = mbtk_sim_lock_get(handle_def, &lock_state);
b.liu87afc4c2024-08-14 17:33:45 +0800607 if(err != MBTK_RIL_ERR_SUCCESS) {
608 printf("Error : %d\n", err);
609 } else {
610 printf("PIN state : %d\n", lock_state);
611 }
612 } else if(!strncasecmp(cmd, "pin_times", 9)){
613 mbtk_pin_puk_last_times_t times;
b.liub171c9a2024-11-12 19:23:29 +0800614 err = mbtk_sim_lock_retry_times_get(handle_def, &times);
b.liu87afc4c2024-08-14 17:33:45 +0800615 if(err != MBTK_RIL_ERR_SUCCESS) {
616 printf("Error : %d\n", err);
617 } else {
618 printf("PIN/PUK retry times:%d,%d,%d,%d\n", times.p1_retry, times.p2_retry, times.puk1_retry, times.puk2_retry);
619 }
620 } else if(!strncasecmp(cmd, "pin_open", 8)){
621 mbtk_sim_lock_info_t info;
622 info.type = MBTK_SIM_LOCK_TYPE_ENABLE;
623 int count = sscanf(cmd, "pin_open %s", info.pin1);
624 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800625 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800626 if(err != MBTK_RIL_ERR_SUCCESS) {
627 printf("Error : %d\n", err);
628 } else {
629 printf("Enable sim lock success.\n");
630 }
631 }
632 } else if(!strncasecmp(cmd, "pin_close", 9)){
633 mbtk_sim_lock_info_t info;
634 info.type = MBTK_SIM_LOCK_TYPE_DISABLE;
635 int count = sscanf(cmd, "pin_close %s", info.pin1);
636 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800637 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800638 if(err != MBTK_RIL_ERR_SUCCESS) {
639 printf("Error : %d\n", err);
640 } else {
641 printf("Disable sim lock success.\n");
642 }
643 }
644 } else if(!strncasecmp(cmd, "pin_change", 10)){
645 mbtk_sim_lock_info_t info;
646 info.type = MBTK_SIM_LOCK_TYPE_CHANGE;
647 int count = sscanf(cmd, "pin_change %s %s", info.pin1, info.pin2);
648 if(count == 2) {
b.liub171c9a2024-11-12 19:23:29 +0800649 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800650 if(err != MBTK_RIL_ERR_SUCCESS) {
651 printf("Error : %d\n", err);
652 } else {
653 printf("PIN change success.\n");
654 }
655 }
656 } else if(!strncasecmp(cmd, "pin_verify", 10)){
657 mbtk_sim_lock_info_t info;
658 info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PIN;
659 int count = sscanf(cmd, "pin_verify %s", info.pin1);
660 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800661 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800662 if(err != MBTK_RIL_ERR_SUCCESS) {
663 printf("Error : %d\n", err);
664 } else {
665 printf("PIN verify success.\n");
666 }
667 }
668 } else if(!strncasecmp(cmd, "puk_verify", 10)){
669 mbtk_sim_lock_info_t info;
670 info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PUK;
671 int count = sscanf(cmd, "puk_verify %s %s", info.puk, info.pin1);
672 if(count == 2) {
b.liub171c9a2024-11-12 19:23:29 +0800673 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800674 if(err != MBTK_RIL_ERR_SUCCESS) {
675 printf("Error : %d\n", err);
676 } else {
677 printf("PUK verify success.\n");
678 }
679 }
680 } else if(!strncasecmp(cmd, "plmn", 4)){
681 mbtk_plmn_info info;
b.liub171c9a2024-11-12 19:23:29 +0800682 err = mbtk_plmn_list_get(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800683 if(err != MBTK_RIL_ERR_SUCCESS) {
684 printf("Error : %d\n", err);
685 } else {
686 printf("PLMN number:%d\n", info.count);
687 int i = 0;
688 while(i < info.count) {
689 printf("%d,%d,%s\n", i+1, info.plmn[i].format, info.plmn[i].name);
690 i++;
691 }
692 }
693 }
694 else if(!strncasecmp(cmd, "avail_net", 9)){
695 mbtk_net_info_array_t net_list;
b.liub171c9a2024-11-12 19:23:29 +0800696 err = mbtk_available_net_get(handle_1, &net_list);
b.liu87afc4c2024-08-14 17:33:45 +0800697 if(err != MBTK_RIL_ERR_SUCCESS) {
698 printf("Error : %d\n", err);
699 } else {
700 printf("Available net number:%d\n", net_list.num);
701 int i = 0;
702 while(i < net_list.num) {
703 printf("NET : %d,%d,%d,%d\n", net_list.net_info[i].net_sel_mode,
704 net_list.net_info[i].net_type, net_list.net_info[i].net_state,
705 net_list.net_info[i].plmn);
706 i++;
707 }
708 }
709 } else if(!strncasecmp(cmd, "sel_mode", 8)){ // "sel_mode" or "sel_mode 1 7 46000"
710 mbtk_net_info_t net;
711 memset(&net, 0, sizeof(mbtk_net_info_t));
712 if(!strcasecmp(cmd, "sel_mode")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800713 err = mbtk_net_sel_mode_get(handle_def, &net);
b.liu87afc4c2024-08-14 17:33:45 +0800714 if(err != MBTK_RIL_ERR_SUCCESS) {
715 printf("Error : %d\n", err);
716 } else {
717 printf("Net : %d, %d, %d, %d\n", net.net_sel_mode, net.net_type, net.net_state, net.plmn);
718 }
719 } else { // Set
720 char *ptr = strstr(cmd, " ");
721 if(ptr == NULL)
722 continue;
723 while(*ptr != '\0' && *ptr == ' ')
724 ptr++;
725 net.net_sel_mode = (uint8)atoi(ptr);
726
727 ptr = strstr(ptr, " ");
728 if(ptr == NULL)
729 continue;
730 while(*ptr != '\0' && *ptr == ' ')
731 ptr++;
732 net.net_type = (uint8)atoi(ptr);
733
734 ptr = strstr(ptr, " ");
735 if(ptr == NULL)
736 continue;
737 while(*ptr != '\0' && *ptr == ' ')
738 ptr++;
739 net.plmn = (uint32)atoi(ptr);
740
b.liub171c9a2024-11-12 19:23:29 +0800741 err = mbtk_net_sel_mode_set(handle_def, &net);
b.liu87afc4c2024-08-14 17:33:45 +0800742 if(err != MBTK_RIL_ERR_SUCCESS) {
743 printf("Error : %d\n", err);
744 } else {
745 printf("Net select mode set success\n");
746 }
747 }
748 } else if(!strncasecmp(cmd, "band", 4)){ // "band" or "band support" or "band 0 79 147 482 524503"
749 mbtk_band_info_t band;
750 memset(&band, 0x0, sizeof(mbtk_band_info_t));
751 if(!strcasecmp(cmd, "band")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800752 err = mbtk_current_band_get(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800753 if(err != MBTK_RIL_ERR_SUCCESS) {
754 printf("Error : %d\n", err);
755 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800756 printf("Band : %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band, band.lte_ext_band,
757 band.nr_3_band, band.nr_2_band, band.nr_1_band, band.nr_0_band);
b.liu87afc4c2024-08-14 17:33:45 +0800758 }
b.liubeb61cc2025-02-13 10:38:29 +0800759 } else if(!strcasecmp(cmd, "band_support")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800760 err = mbtk_support_band_get(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800761 if(err != MBTK_RIL_ERR_SUCCESS) {
762 printf("Error : %d\n", err);
763 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800764 printf("Band : %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", band.net_pref, band.gsm_band, band.umts_band, band.tdlte_band, band.fddlte_band, band.lte_ext_band,
765 band.nr_3_band, band.nr_2_band, band.nr_1_band, band.nr_0_band);
b.liu87afc4c2024-08-14 17:33:45 +0800766 }
b.liubeb61cc2025-02-13 10:38:29 +0800767 } else { // "band 0 79 147 482 524503 x x x x"
768#if 0
b.liu87afc4c2024-08-14 17:33:45 +0800769 char *ptr = strstr(cmd, " ");
770 if(ptr == NULL)
771 continue;
772 while(*ptr != '\0' && *ptr == ' ')
773 ptr++;
774 band.net_pref = (uint8)atoi(ptr);
775
776 ptr = strstr(ptr, " ");
777 if(ptr == NULL)
778 continue;
779 while(*ptr != '\0' && *ptr == ' ')
780 ptr++;
781 band.gsm_band = (uint16)atoi(ptr);
782
783 ptr = strstr(ptr, " ");
784 if(ptr == NULL)
785 continue;
786 while(*ptr != '\0' && *ptr == ' ')
787 ptr++;
788 band.umts_band = (uint16)atoi(ptr);
789
790 ptr = strstr(ptr, " ");
791 if(ptr == NULL)
792 continue;
793 while(*ptr != '\0' && *ptr == ' ')
794 ptr++;
795 band.tdlte_band = (uint32)atoi(ptr);
796
797 ptr = strstr(ptr, " ");
798 if(ptr == NULL)
799 continue;
800 while(*ptr != '\0' && *ptr == ' ')
801 ptr++;
802 band.fddlte_band = (uint32)atoi(ptr);
b.liubeb61cc2025-02-13 10:38:29 +0800803#else
804 int count = sscanf(cmd, "band %d %d %d %d %d %d %d %d %d %d", &band.net_pref, &band.gsm_band, &band.umts_band,
805 &band.tdlte_band, &band.fddlte_band, &band.lte_ext_band, &band.nr_3_band, &band.nr_2_band, &band.nr_1_band, &band.nr_0_band);
b.liu87afc4c2024-08-14 17:33:45 +0800806
b.liubeb61cc2025-02-13 10:38:29 +0800807 if(count != 10 && count != 1) {
808 printf("band set error.\n");
809 continue;
810 }
811#endif
b.liub171c9a2024-11-12 19:23:29 +0800812 err = mbtk_current_band_set(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800813 if(err != MBTK_RIL_ERR_SUCCESS) {
814 printf("Error : %d\n", err);
815 } else {
816 printf("Band set success\n");
817 }
818 }
819 } else if(!strncasecmp(cmd, "signal", 6)){
820 mbtk_signal_info_t signal;
b.liub171c9a2024-11-12 19:23:29 +0800821 err = mbtk_net_signal_get(handle_def, &signal);
b.liu87afc4c2024-08-14 17:33:45 +0800822 if(err != MBTK_RIL_ERR_SUCCESS) {
823 printf("Error : %d\n", err);
824 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800825 printf("Signal : %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", signal.type, signal.rssi, signal.rxlev, signal.ber,
826 signal.rscp, signal.ecno, signal.rsrq, signal.rsrp, signal.ss_rsrq, signal.ss_rsrp, signal.ss_sinr);
b.liu87afc4c2024-08-14 17:33:45 +0800827 }
828 } else if(!strncasecmp(cmd, "reg", 3)){
829 mbtk_net_reg_info_t reg;
b.liub171c9a2024-11-12 19:23:29 +0800830 err = mbtk_net_reg_get(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +0800831 if(err != MBTK_RIL_ERR_SUCCESS) {
832 printf("Error : %d\n", err);
833 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800834 printf("REG : call_state=%d, data_state=%d, ims_state=%d, net_type=%d, %08x, %09x\n", reg.call_state, reg.data_state, reg.ims_state, reg.type, reg.lac, reg.ci);
b.liu87afc4c2024-08-14 17:33:45 +0800835 }
836 } else if(!strncasecmp(cmd, "apn_del", 7)) {
837 mbtk_apn_info_t apn;
838 memset(&apn, 0, sizeof(mbtk_apn_info_t));
839 int cid, auto_save;
840 int count = sscanf(cmd, "apn_del %d %d", &cid, &auto_save);
841 if(count == 2) {
842 apn.cid = (mbtk_ril_cid_enum)cid;
843 apn.auto_save = (uint8)auto_save;
844 }
b.liub171c9a2024-11-12 19:23:29 +0800845 err = mbtk_apn_set(handle_def, &apn);
b.liu87afc4c2024-08-14 17:33:45 +0800846 if(err != MBTK_RIL_ERR_SUCCESS) {
847 printf("Error : %d\n", err);
848 } else {
849 printf("APN delete success\n");
850 }
851
852 } else if(!strncasecmp(cmd, "apn", 3)){
853 if(!strcasecmp(cmd, "apn")) { // Get apn
854 mbtk_apn_info_array_t apns;
b.liub171c9a2024-11-12 19:23:29 +0800855 err = mbtk_apn_get(handle_def, &apns);
b.liu87afc4c2024-08-14 17:33:45 +0800856 if(err != MBTK_RIL_ERR_SUCCESS) {
857 printf("Error : %d\n", err);
858 } else {
859 printf("APN Num:%d\n", apns.num);
860 int i = 0;
861 while(i < apns.num) {
b.liu10a34102024-08-20 20:36:24 +0800862 // printf("APN : %d, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type), apns.apns[i].apn);
863 printf("APN : %d, %s, auth-%d, auto_save-%d, auto_boot_call-%d, %s, %s, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type),
864 apns.apns[i].auth, apns.apns[i].auto_save, apns.apns[i].auto_boot_call,
b.liu62240ee2024-11-07 17:52:45 +0800865 str_empty(apns.apns[i].apn) ? "NULL" : (char*)apns.apns[i].apn,
866 str_empty(apns.apns[i].user) ? "NULL" : (char*)apns.apns[i].user,
867 str_empty(apns.apns[i].pass) ? "NULL" : (char*)apns.apns[i].pass,
868 str_empty(apns.apns[i].type) ? "NULL" : (char*)apns.apns[i].type);
b.liu87afc4c2024-08-14 17:33:45 +0800869 i++;
870 }
b.liu10a34102024-08-20 20:36:24 +0800871 printf("Def route : %d, def dns : %d\n", apns.cid_for_def_route, apns.cid_for_def_dns);
b.liu87afc4c2024-08-14 17:33:45 +0800872 }
873 } else { // apn <cid> <0/1/2/3> <0/1> <0/1> <apn>
874 mbtk_apn_info_t apn;
875 memset(&apn, 0, sizeof(mbtk_apn_info_t));
876#if 1
b.liubcf86c92024-08-19 19:48:28 +0800877 int cid, ip_type, auto_save, auto_boot_call, def_route, as_dns;
878 int count = sscanf(cmd, "apn %d %d %d %d %d %d %s",
879 &cid, &ip_type, &auto_save, &auto_boot_call,
880 &def_route, &as_dns, apn.apn);
b.liu87afc4c2024-08-14 17:33:45 +0800881
882 // Delete APN
b.liu62240ee2024-11-07 17:52:45 +0800883 if(strcmp((char*)apn.apn,"null") == 0 || strcmp((char*)apn.apn,"NULL") == 0) {
b.liu87afc4c2024-08-14 17:33:45 +0800884 memset(apn.apn, 0, sizeof(apn.apn));
885 }
b.liubcf86c92024-08-19 19:48:28 +0800886 if(count == 7) {
b.liu87afc4c2024-08-14 17:33:45 +0800887 apn.cid = (mbtk_ril_cid_enum)cid;
888 apn.ip_type = (mbtk_ip_type_enum)ip_type;
889 apn.auto_save = (uint8)auto_save;
890 apn.auto_boot_call = (uint8)auto_boot_call;
b.liubcf86c92024-08-19 19:48:28 +0800891 apn.def_route = (uint8)def_route;
892 apn.as_dns = (uint8)as_dns;
b.liu87afc4c2024-08-14 17:33:45 +0800893 }
894#else
895 char *ptr = strstr(cmd, " ");
896 if(ptr == NULL)
897 continue;
898 while(*ptr != '\0' && *ptr == ' ')
899 ptr++;
900 apn.cid = (mbtk_ril_cid_enum)atoi(ptr);
901
902 ptr = strstr(ptr, " ");
903 if(ptr == NULL)
904 continue;
905 while(*ptr != '\0' && *ptr == ' ')
906 ptr++;
907 apn.ip_type = (mbtk_ip_type_enum)atoi(ptr);
908
909 ptr = strstr(ptr, " ");
910 if(ptr == NULL)
911 continue;
912 while(*ptr != '\0' && *ptr == ' ')
913 ptr++;
914 memcpy(apn.apn, ptr, strlen(ptr));
915#endif
b.liub171c9a2024-11-12 19:23:29 +0800916 err = mbtk_apn_set(handle_def, &apn);
b.liu87afc4c2024-08-14 17:33:45 +0800917 if(err != MBTK_RIL_ERR_SUCCESS) {
918 printf("Error : %d\n", err);
919 } else {
920 printf("APN set success\n");
921 }
922 }
923 }
b.liubcf86c92024-08-19 19:48:28 +0800924 else if(!strncasecmp(cmd, "data_call", 9)){ // data_call <0/1/2> <cid> <timeout>
925 // mbtk_ril_cid_enum cid, bool auto_boot_call, bool def_route, int retry_interval, int timeout, mbtk_ip_info_t *rsp_info
926 // data_call <0/1/2> <cid> <timeout>
927 int type, cid, auto_boot_call, def_route, as_dns;
928 int count = sscanf(cmd, "data_call %d %d %d %d %d", &type, &cid, &auto_boot_call, &def_route, &as_dns);
929 if(count != 5) {
930 count = sscanf(cmd, "data_call %d %d", &type, &cid);
931 }
932
933 if(count == 5 || count == 2) {
934 mbtk_ip_info_t ip;
935 memset(&ip, 0, sizeof(mbtk_ip_info_t));
936 if(type == MBTK_DATA_CALL_START) {
b.liu15f456b2024-10-31 20:16:06 +0800937 int retry_interval[] = {5, 10, 15};
b.liuafdf2c62024-11-12 11:10:44 +0800938 if(count == 5) {
b.liub171c9a2024-11-12 19:23:29 +0800939 err = mbtk_data_call_start(handle_def, (mbtk_ril_cid_enum)cid, (mbtk_data_call_item_state_enum)auto_boot_call,
b.liuafdf2c62024-11-12 11:10:44 +0800940 (mbtk_data_call_item_state_enum)def_route, (mbtk_data_call_item_state_enum)as_dns, retry_interval,
b.liu15f456b2024-10-31 20:16:06 +0800941 3, 0, &ip);
b.liuafdf2c62024-11-12 11:10:44 +0800942 } else {
b.liub171c9a2024-11-12 19:23:29 +0800943 err = mbtk_data_call_start(handle_def, (mbtk_ril_cid_enum)cid, MBTK_DATA_CALL_ITEM_STATE_NON,
b.liuafdf2c62024-11-12 11:10:44 +0800944 MBTK_DATA_CALL_ITEM_STATE_NON, MBTK_DATA_CALL_ITEM_STATE_NON, retry_interval,
945 3, 0, &ip);
946 }
b.liubcf86c92024-08-19 19:48:28 +0800947 } else if(type == MBTK_DATA_CALL_STOP) {
b.liub171c9a2024-11-12 19:23:29 +0800948 err = mbtk_data_call_stop(handle_def, (mbtk_ril_cid_enum)cid, 10);
b.liubcf86c92024-08-19 19:48:28 +0800949 } else {
b.liub171c9a2024-11-12 19:23:29 +0800950 err = mbtk_data_call_state_get(handle_def, (mbtk_ril_cid_enum)cid, &ip);
b.liubcf86c92024-08-19 19:48:28 +0800951 }
952 if(err) {
953 printf("Error : %d\n", err);
954 } else {
955 printf("DATA_CALL success\n");
956 if(type == MBTK_DATA_CALL_START || type == MBTK_DATA_CALL_STATE) {
957 if(ip.ipv4.valid) {
958 // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t));
959 char ip_tmp[20];
960
961 memset(ip_tmp, 0, 20);
962 if(inet_ntop(AF_INET, &(ip.ipv4.IPAddr), ip_tmp, 20) == NULL) {
963 printf("IP error.\n");
964 } else {
965 printf("IP : %s\n", ip_tmp);
966 }
967
968 memset(ip_tmp, 0, 20);
969 if(inet_ntop(AF_INET, &(ip.ipv4.PrimaryDNS), ip_tmp, 20) == NULL) {
970 printf("PrimaryDNS error.\n");
971 } else {
972 printf("PrimaryDNS : %s\n", ip_tmp);
973 }
974
975 memset(ip_tmp, 0, 20);
976 if(inet_ntop(AF_INET, &(ip.ipv4.SecondaryDNS), ip_tmp, 20) == NULL) {
977 printf("SecondaryDNS error.\n");
978 } else {
979 printf("SecondaryDNS : %s\n", ip_tmp);
980 }
981
982 memset(ip_tmp, 0, 20);
983 if(inet_ntop(AF_INET, &(ip.ipv4.GateWay), ip_tmp, 20) == NULL) {
984 printf("GateWay error.\n");
985 } else {
986 printf("GateWay : %s\n", ip_tmp);
987 }
988
989 memset(ip_tmp, 0, 20);
990 if(inet_ntop(AF_INET, &(ip.ipv4.NetMask), ip_tmp, 20) == NULL) {
991 printf("NetMask error.\n");
992 } else {
993 printf("NetMask : %s\n", ip_tmp);
994 }
995 }
996
997 if(ip.ipv6.valid) {
998 // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t));
999 char ip_tmp[50];
1000
1001 memset(ip_tmp, 0, 50);
1002 if(ipv6_2_str(&(ip.ipv6.IPV6Addr), ip_tmp)) {
1003 printf("IP error.\n");
1004 } else {
1005 printf("IP : %s\n", ip_tmp);
1006 }
1007
1008 memset(ip_tmp, 0, 50);
1009 if(ipv6_2_str(&(ip.ipv6.PrimaryDNS), ip_tmp)) {
1010 printf("PrimaryDNS error.\n");
1011 } else {
1012 printf("PrimaryDNS : %s\n", ip_tmp);
1013 }
1014
1015 memset(ip_tmp, 0, 50);
1016 if(ipv6_2_str(&(ip.ipv6.SecondaryDNS), ip_tmp)) {
1017 printf("SecondaryDNS error.\n");
1018 } else {
1019 printf("SecondaryDNS : %s\n", ip_tmp);
1020 }
1021
1022 memset(ip_tmp, 0, 50);
1023 if(ipv6_2_str(&(ip.ipv6.GateWay), ip_tmp)) {
1024 printf("GateWay error.\n");
1025 } else {
1026 printf("GateWay : %s\n", ip_tmp);
1027 }
1028
1029 memset(ip_tmp, 0, 50);
1030 if(ipv6_2_str(&(ip.ipv6.NetMask), ip_tmp)) {
1031 printf("NetMask error.\n");
1032 } else {
1033 printf("NetMask : %s\n", ip_tmp);
1034 }
1035 }
1036 }
1037 }
1038 }
1039 }
b.liu87afc4c2024-08-14 17:33:45 +08001040 else if(!strncasecmp(cmd, "cell", 4)){
1041 char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME
1042 if(ptr == NULL)
1043 {
b.liub4772072024-08-15 14:47:03 +08001044 mbtk_cell_info_array_t cell;
b.liub171c9a2024-11-12 19:23:29 +08001045 err = mbtk_cell_get(handle_def, &cell);
b.liub4772072024-08-15 14:47:03 +08001046 if(err) {
b.liu87afc4c2024-08-14 17:33:45 +08001047 printf("Error : %d\n", err);
b.liub4772072024-08-15 14:47:03 +08001048 } else if(cell.num > 0){
1049 // Current server cell.
1050 switch(cell.type)
b.liu87afc4c2024-08-14 17:33:45 +08001051 {
b.liub4772072024-08-15 14:47:03 +08001052 case MBTK_CELL_TYPE_GSM:
1053 printf("GSM : lac=%d, ci=%d, arfcn=%d, bsic=%d\n", cell.cell[0].value1, cell.cell[0].value2, cell.cell[0].value3, cell.cell[0].value4);
1054 break;
1055 case MBTK_CELL_TYPE_UMTS:
1056 printf("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell.cell[0].value1, cell.cell[0].value2, cell.cell[0].value3);
1057 break;
1058 case MBTK_CELL_TYPE_LTE:
1059 printf("LTE : tac=%d, PCI=%d, dlEuarfcn=%d, ulEuarfcn=%d, band=%d\n", cell.cell[0].value1, cell.cell[0].value2, cell.cell[0].value3, cell.cell[0].value4, cell.cell[0].value5);
1060 break;
b.liubeb61cc2025-02-13 10:38:29 +08001061 // mcc,mnc,tac,PCI,dlNrArfcn,ulNrArfcn,band,rsrp,rsrq,sinr,rssi
1062 // cellID
1063 case MBTK_CELL_TYPE_NR:
1064 printf("NR : mcc=%d, mnc_len=%d, mnc=%d, tac=%d, PCI=%d, dlNrArfcn=%d, ulNrArfcn=%d, band=%d, rsrp=%d, rsrq=%d, sinr=%d, rssi=%d, cellID=%lld\n",
1065 cell.cell[0].value1, cell.cell[0].value2, cell.cell[0].value3, cell.cell[0].value4, cell.cell[0].value5, cell.cell[0].value6, cell.cell[0].value7
1066 , cell.cell[0].value8, cell.cell[0].value9, cell.cell[0].value10, cell.cell[0].value11, cell.cell[0].value12, cell.cell[0].value64_1);
1067 break;
b.liub4772072024-08-15 14:47:03 +08001068 default:
1069 break;
1070 }
1071
1072 int i = 1;
1073 while (i < cell.num)
1074 {
1075 switch(cell.type)
b.liu87afc4c2024-08-14 17:33:45 +08001076 {
b.liub4772072024-08-15 14:47:03 +08001077 case MBTK_CELL_TYPE_GSM:
1078 printf("CELL : %d, %d, %d, %d, %d", cell.cell[i].value1, cell.cell[i].value2, cell.cell[i].value3, cell.cell[i].value4, cell.cell[i].value5);
b.liu87afc4c2024-08-14 17:33:45 +08001079 break;
b.liub4772072024-08-15 14:47:03 +08001080 case MBTK_CELL_TYPE_UMTS:
1081 printf("CELL : lac=%d, ci=%d, arfcn=%d\n", cell.cell[i].value1, cell.cell[i].value2, cell.cell[i].value3);
b.liu87afc4c2024-08-14 17:33:45 +08001082 break;
b.liub4772072024-08-15 14:47:03 +08001083 case MBTK_CELL_TYPE_LTE:
1084 printf("CELL : phyCellId=%d, euArfcn=%d, rsrp=%d, rsrq=%d\n", cell.cell[i].value1, cell.cell[i].value2, cell.cell[i].value3, cell.cell[i].value4);
b.liu87afc4c2024-08-14 17:33:45 +08001085 break;
b.liubeb61cc2025-02-13 10:38:29 +08001086 // phyCellId,nrArfcn,rsrp,rsrq
1087 case MBTK_CELL_TYPE_NR:
1088 printf("CELL : phyCellId=%d, nrArfcn=%d, rsrp=%d, rsrq=%d\n", cell.cell[i].value1, cell.cell[i].value2, cell.cell[i].value3, cell.cell[i].value4);
1089 break;
b.liu87afc4c2024-08-14 17:33:45 +08001090 default:
1091 break;
1092 }
b.liub4772072024-08-15 14:47:03 +08001093 i++;
b.liu87afc4c2024-08-14 17:33:45 +08001094 }
b.liub4772072024-08-15 14:47:03 +08001095 } else {
1096 printf("Cell no found.");
b.liu87afc4c2024-08-14 17:33:45 +08001097 }
b.liu87afc4c2024-08-14 17:33:45 +08001098 }
1099 else{
1100 char *ptr = strstr(cmd, ","); //cell,2,3,,40936,430
1101 char mem[50]={0};
1102 char resp[1024] = {0};
1103 if(ptr != NULL)
1104 {
1105 ptr++;
1106 memset(mem, 0, sizeof(mem));
1107 memcpy(mem, ptr, strlen(ptr));
1108 printf("cell:%s\n", mem);
1109 }
1110 printf("cell_mem: %s \n", mem);
1111
1112 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001113 err = mbtk_cell_set(handle_def, mem, resp);
b.liu87afc4c2024-08-14 17:33:45 +08001114 if(err) {
1115 printf("Error : %d\n", err);
1116 } else {
1117 printf("cell set . resp:%s\n", resp);
1118 }
b.liu87afc4c2024-08-14 17:33:45 +08001119 }
b.liub4772072024-08-15 14:47:03 +08001120 }
1121 else if(!strncasecmp(cmd, "call", 4)){
b.liu87afc4c2024-08-14 17:33:45 +08001122 char phone_number[12];
1123 char *ptr = strstr(cmd, " ");
1124 if(ptr == NULL)
1125 continue;
1126 while(*ptr != '\0' && *ptr == ' ')
1127 ptr++;
1128 memset(phone_number,0,strlen(phone_number));
1129 memcpy(phone_number,ptr,strlen(ptr));
1130 printf("phone number is: %s\n",phone_number);
b.liub171c9a2024-11-12 19:23:29 +08001131 err = mbtk_call_start(handle_def, phone_number);
b.liu87afc4c2024-08-14 17:33:45 +08001132 if(err) {
1133 printf("Error : %d\n", err);
1134 } else {
1135 printf("Call success.\n");
1136 }
1137 } else if(!strncasecmp(cmd, "answer", 6)){
b.liub171c9a2024-11-12 19:23:29 +08001138 err = mbtk_call_answer(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001139 if(err) {
1140 printf("Error : %d\n", err);
1141 } else {
1142 printf("Call success.\n");
1143 }
1144 } else if(!strncasecmp(cmd, "hangup", 6)){
b.liu62240ee2024-11-07 17:52:45 +08001145 int phone_id = 1;
b.liu87afc4c2024-08-14 17:33:45 +08001146 if(!strcasecmp(cmd, "hangup")) { // hang up all
b.liub171c9a2024-11-12 19:23:29 +08001147 err = mbtk_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001148 if(err) {
1149 printf("Error : %d\n", err);
1150 } else {
1151 printf("Call hang up all.\n");
1152 }
1153 } else if(!strcasecmp(cmd, "hangup 0")) {
b.liub171c9a2024-11-12 19:23:29 +08001154 err = mbtk_waiting_or_background_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001155 if(err) {
1156 printf("Error : %d\n", err);
1157 } else {
1158 printf("Call hang up waiting or background.\n");
1159 }
1160 } else if(!strcasecmp(cmd, "hangup 3")) {
b.liub171c9a2024-11-12 19:23:29 +08001161 err = mbtk_foreground_resume_background_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001162 if(err) {
1163 printf("Error : %d\n", err);
1164 } else {
1165 printf("Call hang up foreground resume background.\n");
1166 }
1167 } else {
1168 if(!strcasecmp(cmd, "hangup 1")) { // hang up a call
1169 phone_id = 1;
1170 } else if(!strcasecmp(cmd, "hangup 2")) {
1171 phone_id = 2;
1172 } else {
1173 printf("Error : Invalid input\n");
1174 }
b.liub171c9a2024-11-12 19:23:29 +08001175 err = mbtk_a_call_hang(handle_def, phone_id);
b.liu87afc4c2024-08-14 17:33:45 +08001176 if(err) {
1177 printf("Error : %d\n", err);
1178 } else {
1179 printf("A Call hang up.\n");
1180 }
1181 }
1182 } else if(!strncasecmp(cmd, "waitin", 6)){
1183 mbtk_call_info_t reg;
b.liub171c9a2024-11-12 19:23:29 +08001184 err = mbtk_call_reg_get(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +08001185 if(err) {
1186 printf("Error : %d\n", err);
1187 } else {
1188 if(reg.call_wait == 0) {
1189 printf("No call ring\n");
1190 }
1191 else {
1192 printf("RING : %d, %d, %d, %d, %d, %s, %d\n", reg.dir1, reg.dir, reg.state, reg.mode, reg.mpty, reg.phone_number, reg.type);
1193 }
1194 }
1195 } else if(!strncasecmp(cmd, "mute", 4)){ // "mute" or "mute 0" or "mute 1"
1196 int mute;
1197 if(!strcasecmp(cmd, "mute")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001198 err = mbtk_mute_state_get(handle_def, &mute);
b.liu87afc4c2024-08-14 17:33:45 +08001199 if(err) {
1200 printf("Error : %d\n", err);
1201 } else {
1202 printf("mute : %d\n", mute);
1203 }
1204 } else { // Set
1205 if(!strcasecmp(cmd, "mute 1")) { // on mute
1206 mute = 1;
1207 } else { // off mute
1208 mute = 0;
1209 }
b.liub171c9a2024-11-12 19:23:29 +08001210 err = mbtk_mute_state_set(handle_def, mute);
b.liu87afc4c2024-08-14 17:33:45 +08001211 if(err) {
1212 printf("Error : %d\n", err);
1213 } else {
1214 printf("mute set success\n");
1215 }
1216 }
1217 } else if(!strncasecmp(cmd, "DTMF", 4)){ // valid character: (0, 1, ..., 9, A, B, C, D, *, #)
1218
1219 mbtk_call_dtmf_info_t reg;
1220
1221 char *ptr = strstr(cmd, " ");
1222 if(ptr == NULL)
1223 continue;
1224 while(*ptr != '\0' && *ptr == ' ')
1225 ptr++;
1226 reg.character = *ptr;
1227
1228 ptr = strstr(ptr, " ");
1229 if(ptr == NULL)
1230 continue;
1231 while(*ptr != '\0' && *ptr == ' ')
1232 ptr++;
1233 reg.duration = (uint32)atoi(ptr);
1234 printf("DTMF character is: %c,%d\n",reg.character, reg.duration);
b.liub171c9a2024-11-12 19:23:29 +08001235 err = mbtk_dtmf_send(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +08001236 if(err) {
1237 printf("Error : %d\n", err);
1238 } else {
1239 printf("DTMF success.\n");
1240 }
b.liub4772072024-08-15 14:47:03 +08001241 } else if(!strncasecmp(cmd, "cmgf", 4)){ // set mode 0: pud, 1:text
1242 int mode;
1243 if(!strcasecmp(cmd, "cmgf")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001244 err = mbtk_sms_cmgf_get(handle_def, &mode);
b.liub4772072024-08-15 14:47:03 +08001245 if(err) {
1246 printf("Error : %d\n", err);
1247 } else {
1248 printf("VoLTE : %d\n", mode);
1249 }
1250 } else { // Set
1251 if(!strcasecmp(cmd, "cmgf 1")) { // cmgf 1
1252 mode = 1;
1253 } else { //
1254 mode = 0;
1255 }
1256 printf("mode:%d\n", mode);
1257 sleep(2);
b.liub171c9a2024-11-12 19:23:29 +08001258 err = mbtk_sms_cmgf_set(handle_def, mode);
b.liub4772072024-08-15 14:47:03 +08001259 if(err) {
1260 printf("Error : %d\n", err);
1261 } else {
1262 printf("VoLTE set success\n");
1263 }
1264 }
1265 }else if(!strncasecmp(cmd, "cpms", 4)){ // //CPMS=ME, ME, ME
1266 char mem[100] = {0};
1267 char resp[100] = {0};
1268 if(!strcasecmp(cmd, "cpms")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001269 err = mbtk_sms_cpms_get(handle_def, mem);
b.liub4772072024-08-15 14:47:03 +08001270 if(err) {
1271 printf("Error : %d\n", err);
1272 } else {
1273 printf("cpms : %s\n", mem);
1274 }
1275 } else { // Set
1276
1277 char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME
1278 if(ptr != NULL)
1279 {
1280 ptr++;
1281 memset(mem, 0, sizeof(mem));
1282 memcpy(mem, ptr, strlen(ptr));
1283 printf("cpms:%s\n", mem);
1284 }
1285 printf("cpms 0\n");
1286
1287 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001288 err = mbtk_sms_cpms_set(handle_def, mem, resp);
b.liub4772072024-08-15 14:47:03 +08001289 if(err) {
1290 printf("Error : %d\n", err);
1291 } else {
1292 printf("cpms set success. resp:%s\n", resp);
1293 }
1294 }
1295 }else if(!strncasecmp(cmd, "cmgs", 4)){ // AT+CMGS="10086", CMGS TEST
1296 char cmgs[1024] = {0};
1297 char resp[50] = {0};
1298 if(!strcasecmp(cmd, "cmgs")) { // Get
b.liudeb8e422024-12-14 17:36:56 +08001299 int mode = 0;
1300 err = 0;
b.liub4772072024-08-15 14:47:03 +08001301 // err = mbtk_sms_cmgs_get(info_handle, &mode);
1302 if(err) {
1303 printf("Error : %d\n", err);
1304 } else {
1305 printf("VoLTE : %d\n", mode);
1306 }
1307 } else { // Set
1308
1309 /*
1310 *AT+CMGS="10086", CMGS TEST // Send a SMS
1311 > CMGS TEST
1312 +CMGS: 17
1313 OK
1314 */
1315
1316 char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf
1317 if(ptr != NULL)
1318 {
1319 ptr = strstr(cmd, ",");
1320 ptr++;
1321 memset(cmgs, 0, sizeof(cmgs));
1322 memcpy(cmgs, ptr, strlen(ptr));
1323 printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs));
1324 }
1325
1326 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001327 err = mbtk_sms_cmgs_set(handle_def, cmgs, resp);
b.liub4772072024-08-15 14:47:03 +08001328 if(err) {
1329 printf("Error : %d\n", err);
1330 } else {
1331 printf("cmgs set success . resp:%s\n", resp);
1332 }
1333 }
1334 }else if(!strncasecmp(cmd, "cmss", 4)){ // +CMSS=<index>[,<da>[,<toda>]]
1335 char cmss[20] = {0};
1336 char resp[20] = {0};
1337 if(!strcasecmp(cmd, "cmgs")) { // Get
1338 printf("cmss : OK\n");
1339
1340 } else {
1341 char *ptr = strstr(cmd, "cmss,"); //CMSS=<index>
1342 if(ptr != NULL)
1343 {
1344 ptr = strstr(cmd, ",");
1345 ptr++;
1346 memset(cmss, 0, sizeof(cmss));
1347 memcpy(cmss, ptr, strlen(ptr));
1348 printf("1cmss:%s\n", cmss);
1349 }
1350
1351
b.liub171c9a2024-11-12 19:23:29 +08001352 err = mbtk_sms_cmss_set(handle_def, cmss, resp);
b.liub4772072024-08-15 14:47:03 +08001353 if(err) {
1354 printf("Error : %d\n", err);
1355 } else {
1356 printf("cmss set success. resp:%s\n", resp);
1357 }
1358 }
1359 }
1360 else if(!strncasecmp(cmd, "cmgr", 4)){ // +CMGR=<index
1361 int index = 0;
1362 char resp[1024] = {0};
1363 if(!strcasecmp(cmd, "cmgr")) { // Get
1364 printf("cmgr : OK\n");
1365
1366 } else {
1367 char *ptr = strstr(cmd, "cmgr,"); //+CMGR <index>
1368 if(ptr != NULL)
1369 {
1370 ptr = strstr(cmd, ",");
1371 ptr++;
1372 index = atoi(ptr);
1373 }
1374 printf("1index:%d\n", index);
1375
1376 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001377 err = mbtk_sms_cmgr_set(handle_def, index, resp);
b.liub4772072024-08-15 14:47:03 +08001378 if(err) {
1379 printf("Error : %d\n", err);
1380 } else {
1381 printf("cmgr set success. rep:%s\n", resp);
1382 }
1383 }
1384 }
1385 else if(!strncasecmp(cmd, "cmgw", 4)){ // +CMGW=<oa/da>[,<tooa/toda>[,<stat>]]<CR>
1386 //+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>
1387 char cmgw[128] = {0};
1388 char resp[50] = {0};
1389 if(!strcasecmp(cmd, "cmgw")) { // Get
1390 printf("cmgw : OK\n");
1391
1392 } else {
1393 char *ptr = strstr(cmd, "cmgw,"); //+CMGW, <oa/da>, data
1394 if(ptr != NULL)
1395 {
1396 ptr = strstr(cmd, ",");
1397 ptr++;
1398 memset(cmgw, 0, sizeof(cmgw));
1399 memcpy(cmgw, ptr, strlen(ptr));
1400 printf("cmgw:%s\n", cmgw);
1401 }
1402
1403 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001404 err = mbtk_sms_cmgw_set(handle_def, cmgw, resp);
b.liub4772072024-08-15 14:47:03 +08001405 if(err) {
1406 printf("Error : %d\n", err);
1407 } else {
1408 printf("cmgw set success. resp:%s\n", resp);
1409 }
1410 }
1411 }
1412 else if(!strncasecmp(cmd, "cmgd", 4)){ // +CMGD=<index>[,<delflag>
1413 //
1414 char cmgd[128] = {0};
1415 if(!strcasecmp(cmd, "cmgd")) { // Get
1416 printf("cmgd : OK\n");
1417
1418 } else {
1419 char *ptr = strstr(cmd, ","); //+CMGD=<index>[,<delflag>
1420 if(ptr != NULL)
1421 {
1422 ptr++;
1423 memset(cmgd, 0, sizeof(cmgd));
1424 memcpy(cmgd, ptr, strlen(ptr));
1425 printf("1cmgd:%s\n", cmgd);
1426 }
1427
1428
b.liub171c9a2024-11-12 19:23:29 +08001429 err = mbtk_sms_cmgd_set(handle_def, cmgd);
b.liub4772072024-08-15 14:47:03 +08001430 if(err) {
1431 printf("Error : %d\n", err);
1432 } else {
1433 printf("VoLTE set success\n");
1434 }
1435 }
1436 }
1437 else if(!strncasecmp(cmd, "cmgl", 4)){ // AT+CMGL[=<stat>]
1438 //
1439 char cmgl[128] = {0};
1440 char resp[5*1024] ={0};
1441 if(!strcasecmp(cmd, "cmgl")) { // Get
1442 printf("cmgl : OK\n");
1443
1444 } else {
1445 char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
1446 if(ptr != NULL)
1447 {
1448 ptr = strstr(cmd, ",");
1449 ptr++;
1450 memset(cmgl, 0, sizeof(cmgl));
1451 memcpy(cmgl, ptr, strlen(ptr));
1452 printf("0cmgl:%s\n", cmgl);
1453 }
1454
1455 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001456 err = mbtk_sms_cmgl_set(handle_def, cmgl, resp);
b.liub4772072024-08-15 14:47:03 +08001457 if(err) {
1458 printf("Error : %d\n", err);
1459 } else {
1460 // printf("cmgl set success, reg:%s\n",resp);
1461 }
1462 }
1463 }
1464 else if(!strncasecmp(cmd, "csca", 4)){ // AT+CSCA=<number> [,<type>]
1465 //
1466 char csca[128] = {0};
1467 if(!strcasecmp(cmd, "csca")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001468 err = mbtk_sms_csca_get(handle_def, csca);
b.liub4772072024-08-15 14:47:03 +08001469 if(err) {
1470 printf("mbtk_sms_csca_get Error : %d\n", err);
1471 } else {
1472 printf("mbtk_sms_csca_get success\n");
1473 }
1474
1475 } else {
1476 char *ptr = strstr(cmd, ","); // AT+CSCA=<number> [,<type>]
1477 if(ptr != NULL)
1478 {
1479 ptr++;
1480 memset(csca, 0, sizeof(csca));
1481 memcpy(csca, ptr, strlen(ptr));
1482 printf("csca:%s\n", csca);
1483 }
1484
b.liub171c9a2024-11-12 19:23:29 +08001485 err = mbtk_sms_csca_set(handle_def, csca);
b.liub4772072024-08-15 14:47:03 +08001486 if(err) {
1487 printf("Error : %d\n", err);
1488 } else {
1489 printf("VoLTE set success\n");
1490 }
1491 }
1492 }
1493 else if(!strncasecmp(cmd, "csmp", 4)){ // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1494 //
1495 char csmp[128] = {0};
1496 if(!strcasecmp(cmd, "csmp")) { // Get
1497 printf("cmgl : OK\n");
1498
1499 } else {
1500 char *ptr = strstr(cmd, ","); // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1501 if(ptr != NULL)
1502 {
1503 ptr++;
1504 memset(csmp, 0, sizeof(csmp));
1505 memcpy(csmp, ptr, strlen(ptr));
1506 printf("csmp:%s\n", csmp);
1507 }
1508
b.liub171c9a2024-11-12 19:23:29 +08001509 err = mbtk_sms_csmp_set(handle_def, csmp);
b.liub4772072024-08-15 14:47:03 +08001510 if(err) {
1511 printf("Error : %d\n", err);
1512 } else {
1513 printf("VoLTE set success\n");
1514 }
1515 }
1516 }
1517 else if(!strncasecmp(cmd, "cscb", 4)){ // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1518 //
1519 char cscb[128] = {0};
1520 if(!strcasecmp(cmd, "cscb")) { // Get
1521 printf("cmgl : OK\n");
1522
1523 } else {
1524 char *ptr = strstr(cmd, ","); // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1525 if(ptr != NULL)
1526 {
1527 ptr++;
1528 memset(cscb, 0, sizeof(cscb));
1529 memcpy(cscb, ptr, strlen(ptr));
1530 printf("cscb:%s\n", cscb);
1531 }
1532
b.liub171c9a2024-11-12 19:23:29 +08001533 err = mbtk_sms_cscb_set(handle_def, cscb);
b.liub4772072024-08-15 14:47:03 +08001534 if(err) {
1535 printf("Error : %d\n", err);
1536 } else {
1537 printf("VoLTE set success\n");
1538 }
1539 }
1540 }
1541#if 0
1542 else if(!strncasecmp(cmd, "shutdown", 8)){
b.liu87afc4c2024-08-14 17:33:45 +08001543 if(!strcasecmp(cmd, "shutdown 0")) {
1544 err = mbtk_system_reboot(0);
1545 if(err) {
1546 printf("Error : %d\n", err);
1547 } else {
1548 printf("Success.\n");
1549 }
1550 } else if(!strcasecmp(cmd, "shutdown 1")) {
1551 err = mbtk_system_reboot(1);
1552 if(err) {
1553 printf("Error : %d\n", err);
1554 } else {
1555 printf("Success.\n");
1556 }
1557 } else if(!strcasecmp(cmd, "shutdown 2")) {
1558 err = mbtk_system_reboot(2);
1559 if(err) {
1560 printf("Error : %d\n", err);
1561 } else {
1562 printf("Success.\n");
1563 }
1564 } else {
1565 printf("Error.");
1566 }
1567 } else if(!strncasecmp(cmd, "power_sim", 9)){
1568 if(!strcasecmp(cmd, "power_sim 0")) {
1569 err = mbtk_sim_power_set(0);
1570 if(err) {
1571 printf("Error : %d\n", err);
1572 } else {
1573 printf("Success.\n");
1574 }
1575 } else if(!strcasecmp(cmd, "power_sim 1")) {
1576 err = mbtk_sim_power_set(1);
1577 if(err) {
1578 printf("Error : %d\n", err);
1579 } else {
1580 printf("Success.\n");
1581 }
1582 } else {
1583 printf("Error.");
1584 }
1585 } else if(!strncasecmp(cmd, "time", 4)){
1586 if(!strcasecmp(cmd, "time 0")) {
1587 err = mbtk_time_set(info_handle, 0, NULL);
1588 if(err) {
1589 printf("Error : %d\n", err);
1590 } else {
1591 printf("Success.\n");
1592 }
1593 } else if(!strcasecmp(cmd, "time 1")) {
1594 err = mbtk_time_set(info_handle, 1, NULL);
1595 if(err) {
1596 printf("Error : %d\n", err);
1597 } else {
1598 printf("Success.\n");
1599 }
1600 } else if(!strncasecmp(cmd, "time 2 ", 7)) {
1601 err = mbtk_time_set(info_handle, 2, cmd + 7);
1602 if(err) {
1603 printf("Error : %d\n", err);
1604 } else {
1605 printf("Success.\n");
1606 }
1607 } else { // Get time type.
1608 int time_type;
1609 err = mbtk_time_get(info_handle, &time_type);
1610 if(err) {
1611 printf("Error : %d\n", err);
1612 } else {
1613 printf("Time type:%d.\n", time_type);
1614 }
1615 }
b.liu87afc4c2024-08-14 17:33:45 +08001616 }
1617#endif
1618 else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) {
1619 help();
1620 } else if(!strcasecmp(cmd, "q")) {
b.liubeb61cc2025-02-13 10:38:29 +08001621 //mbtk_ril_close(MBTK_AT_PORT_DEF);
1622 //mbtk_ril_close(ATPORTTYPE_1);
b.liu87afc4c2024-08-14 17:33:45 +08001623 break;
1624 } else {
1625 printf("\n");
1626 }
1627 }
1628 }
1629
b.liu62240ee2024-11-07 17:52:45 +08001630#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +08001631 thread_exit_with_wait();
b.liu87afc4c2024-08-14 17:33:45 +08001632exit:
b.liu62240ee2024-11-07 17:52:45 +08001633#endif
b.liu7ca612c2025-04-25 09:23:36 +08001634 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liubeb61cc2025-02-13 10:38:29 +08001635 mbtk_ril_close(MBTK_AT_PORT_DEF);
b.liu87afc4c2024-08-14 17:33:45 +08001636
1637 LOG("Client exec complete.");
1638
1639 return 0;
1640}