blob: db7fff2bb93f2a7faf3f5ddb028b53e1ef35d3d7 [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.liubeb61cc2025-02-13 10:38:29 +0800126 printf("net reg state change : type - %d, tech - %d, reg_state - %d, TAG - %llx, ci - %llx\n", state->type,
127 state->tech, state->reg_state, state->tac, state->ci);
b.liu15f456b2024-10-31 20:16:06 +0800128 }
129}
130
131static void call_state_change_cb(const void* data, int data_len)
132{
133 if(data) {
134 mbtk_ril_call_state_info_t *state = (mbtk_ril_call_state_info_t*)data;
135 printf("call state change : call_id-%d, dir-%d, state-%d, num_type-%d,number-%s\n", state->call_id,
136 state->dir, state->state, state->num_type, state->call_number);
137 }
138}
139
140static void sms_state_change_cb(const void* data, int data_len)
141{
b.liuaced4f92024-12-31 11:14:51 +0800142 if(data) {
143 mbtk_ril_sms_state_info_t *state = (mbtk_ril_sms_state_info_t*)data;
144 printf("SMS PDU(%d) : %s\n", state->pdu_len, state->pdu);
145 }
b.liu15f456b2024-10-31 20:16:06 +0800146}
147
148static void radio_state_change_cb(const void* data, int data_len)
149{
150 if(data) {
151 mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)data;
152 printf("radio state change : %d\n", state->radio_state);
153 }
154}
155
156static void sim_state_change_cb(const void* data, int data_len)
157{
158 if(data) {
159 mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)data;
160 printf("sim state change : type - %d, state - %d\n", state->sim_type, state->sim_state);
161 }
162}
163
164static void pdp_state_change_cb(const void* data, int data_len)
165{
166 if(data) {
167 mbtk_ril_pdp_state_info_t *state = (mbtk_ril_pdp_state_info_t*)data;
168 printf("pdp state change : cid - %d, action - %d, reason-%d, auto_change - %d\n",
169 state->cid, state->action, state->reason, state->auto_change);
b.liufd87baf2024-11-15 15:30:38 +0800170 if(state->ip_info_valid) {
171 if(state->ip_info.ipv4.valid) {
172 // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t));
173 char ip_tmp[20];
174
175 memset(ip_tmp, 0, 20);
176 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.IPAddr), ip_tmp, 20) == NULL) {
177 printf("IP error.\n");
178 } else {
179 printf("IP : %s\n", ip_tmp);
180 }
181
182 memset(ip_tmp, 0, 20);
183 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.PrimaryDNS), ip_tmp, 20) == NULL) {
184 printf("PrimaryDNS error.\n");
185 } else {
186 printf("PrimaryDNS : %s\n", ip_tmp);
187 }
188
189 memset(ip_tmp, 0, 20);
190 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.SecondaryDNS), ip_tmp, 20) == NULL) {
191 printf("SecondaryDNS error.\n");
192 } else {
193 printf("SecondaryDNS : %s\n", ip_tmp);
194 }
195
196 memset(ip_tmp, 0, 20);
197 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.GateWay), ip_tmp, 20) == NULL) {
198 printf("GateWay error.\n");
199 } else {
200 printf("GateWay : %s\n", ip_tmp);
201 }
202
203 memset(ip_tmp, 0, 20);
204 if(inet_ntop(AF_INET, &(state->ip_info.ipv4.NetMask), ip_tmp, 20) == NULL) {
205 printf("NetMask error.\n");
206 } else {
207 printf("NetMask : %s\n", ip_tmp);
208 }
209 }
210
211 if(state->ip_info.ipv6.valid) {
212 // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t));
213 char ip_tmp[50];
214
215 memset(ip_tmp, 0, 50);
216 if(ipv6_2_str(&(state->ip_info.ipv6.IPV6Addr), ip_tmp)) {
217 printf("IP error.\n");
218 } else {
219 printf("IP : %s\n", ip_tmp);
220 }
221
222 memset(ip_tmp, 0, 50);
223 if(ipv6_2_str(&(state->ip_info.ipv6.PrimaryDNS), ip_tmp)) {
224 printf("PrimaryDNS error.\n");
225 } else {
226 printf("PrimaryDNS : %s\n", ip_tmp);
227 }
228
229 memset(ip_tmp, 0, 50);
230 if(ipv6_2_str(&(state->ip_info.ipv6.SecondaryDNS), ip_tmp)) {
231 printf("SecondaryDNS error.\n");
232 } else {
233 printf("SecondaryDNS : %s\n", ip_tmp);
234 }
235
236 memset(ip_tmp, 0, 50);
237 if(ipv6_2_str(&(state->ip_info.ipv6.GateWay), ip_tmp)) {
238 printf("GateWay error.\n");
239 } else {
240 printf("GateWay : %s\n", ip_tmp);
241 }
242
243 memset(ip_tmp, 0, 50);
244 if(ipv6_2_str(&(state->ip_info.ipv6.NetMask), ip_tmp)) {
245 printf("NetMask error.\n");
246 } else {
247 printf("NetMask : %s\n", ip_tmp);
248 }
249 }
250 }
b.liu15f456b2024-10-31 20:16:06 +0800251 }
252}
253
254static void signal_state_change_cb(const void* data, int data_len)
255{
256
257}
258
259static void ecall_state_change_cb(const void* data, int data_len)
260{
261 if(data)
262 {
263 mbtk_ril_ecall_state_info_t *ecall_data = (mbtk_ril_ecall_state_info_t*)data;
264 printf("ecall state change : urc_id - %d, urc_data - %s\n", ecall_data->urc_id, ecall_data->urc_data);
265 }
266}
267
268
b.liu87afc4c2024-08-14 17:33:45 +0800269static void sig_process(int sig)
270{
271 LOGI("I got signal %d\n", sig);
272 switch(sig)
273 {
274 case SIGINT: // Ctrl + C
275 {
276 LOGI("Exit by SIGINT.\n");
b.liu62240ee2024-11-07 17:52:45 +0800277#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800278 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800279#endif
b.liub171c9a2024-11-12 19:23:29 +0800280 mbtk_ril_close(MBTK_AT_PORT_DEF);
281 mbtk_ril_close(ATPORTTYPE_1);
b.liu87afc4c2024-08-14 17:33:45 +0800282 exit(0);
283 }
284 case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件)
285 {
286 LOGI("Exit by SIGQUIT.\n");
b.liu62240ee2024-11-07 17:52:45 +0800287#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800288 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800289#endif
b.liub171c9a2024-11-12 19:23:29 +0800290 mbtk_ril_close(MBTK_AT_PORT_DEF);
291 mbtk_ril_close(ATPORTTYPE_1);
b.liu87afc4c2024-08-14 17:33:45 +0800292 exit(0);
293 }
294 case SIGTERM:// 默认kill (同 SIGKILL ,但 SIGKILL 不可捕获)
295 {
296 LOGI("Exit by SIGTERM.\n");
b.liu62240ee2024-11-07 17:52:45 +0800297#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800298 thread_exit_with_wait();
b.liu62240ee2024-11-07 17:52:45 +0800299#endif
b.liub171c9a2024-11-12 19:23:29 +0800300 mbtk_ril_close(MBTK_AT_PORT_DEF);
301 mbtk_ril_close(ATPORTTYPE_1);
b.liu87afc4c2024-08-14 17:33:45 +0800302 exit(0);
303 }
304 case SIGTSTP:// Ctrl + Z (同 SIGSTOP ,但 SIGSTOP 不可捕获)
305 {
306 LOGI("Exit by SIGTSTP.\n");
307 exit(0);
308 }
309 case SIGSEGV: // 如空指针
310 {
311 LOGI("Exit by SIGSEGV.\n");
312 exit(0);
313 }
314 default:
315 {
316 LOGI("Unknown sig:%d\n",sig);
317 break;
318 }
319 }
320}
321
b.liu62240ee2024-11-07 17:52:45 +0800322#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800323static char* thread_id2name(pthread_t pid)
324{
325 int i = 0;
326 while(i < CLI_THREAD_MAX) {
327 if(pid == cli_threads[i].pid) {
328 return cli_threads[i].name;
329 }
330 i++;
331 }
332
333 return "UNKNOWN";
334}
335
336static void* sub_thread_run(void *arg)
337{
338 ril_cli_thread_info_t *cli = (ril_cli_thread_info_t*)arg;
339 cli->pid = pthread_self();
340 cli->is_running = TRUE;
341 sprintf(cli->name, "PID-%d", cli_pid_index++);
342
343 printf("[%s] enter.\n", thread_id2name(cli->pid));
344 while(cli->is_running) {
345 srand((int)(time(0) + cli->pid));
346 int time_sec = 1 + (int)(10.0 * rand() / ( RAND_MAX + 1.0));
347 char version[50] = {0};
348 mbtk_ril_err_enum err = mbtk_version_get(version);
349 if(err != MBTK_RIL_ERR_SUCCESS) {
350 printf("[%s : %ds]Error : %d\n", thread_id2name(cli->pid), time_sec, err);
351 } else {
352 printf("[%s : %ds]Version : %s\n", thread_id2name(cli->pid), time_sec, version);
353 }
354
355 sleep(time_sec);
356 }
357 printf("[%s] exit.\n", thread_id2name(cli->pid));
358 return NULL;
359}
b.liu62240ee2024-11-07 17:52:45 +0800360#endif
b.liu87afc4c2024-08-14 17:33:45 +0800361
362int main(int argc, char *argv[])
363{
364 signal(SIGINT, sig_process);
365 signal(SIGQUIT, sig_process);
366 signal(SIGTERM, sig_process);
367 //signal(SIGTSTP, sig_process);
368 //signal(SIGSEGV, sig_process);
369
370 mbtk_log_init("radio","RIL_CLI");
371
372#ifdef MBTK_DUMP_SUPPORT
373 mbtk_debug_open(NULL, TRUE);
374#endif
375
376 //test2(0, "192.168.1.198");
377 //test2(1, "2409:8162:140:cd3c:1:2:1494:72ba");
378 //test2(1, "254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239");
379 //test2(1, "2400:3200::1");
380
b.liub171c9a2024-11-12 19:23:29 +0800381 mbtk_ril_handle* handle_def = mbtk_ril_open(MBTK_AT_PORT_DEF);
382 if(handle_def == NULL) {
383 printf("mbtk_ril_open(MBTK_AT_PORT_DEF/ATPORTTYPE_0) fail.");
384 return -1;
385 }
386
387 mbtk_ril_handle* handle_1 = mbtk_ril_open(ATPORTTYPE_1);
388 if(handle_1 == NULL) {
389 printf("mbtk_ril_open(ATPORTTYPE_1) fail.");
b.liu87afc4c2024-08-14 17:33:45 +0800390 return -1;
391 }
392
b.liu15f456b2024-10-31 20:16:06 +0800393 mbtk_ril_ser_state_change_cb_reg(ril_ser_state_change_cb);
394
395 mbtk_net_reg_state_change_cb_reg(net_reg_state_change_cb);
396
397 mbtk_call_state_change_cb_reg(call_state_change_cb);
398
399 mbtk_sms_state_change_cb_reg(sms_state_change_cb);
400
401 mbtk_radio_state_change_cb_reg(radio_state_change_cb);
402
403 mbtk_sim_state_change_cb_reg(sim_state_change_cb);
404
405 mbtk_pdp_state_change_cb_reg(pdp_state_change_cb);
406
407 mbtk_signal_state_change_cb_reg(signal_state_change_cb);
408
409 mbtk_ecall_state_change_cb_reg(ecall_state_change_cb);
410
b.liu62240ee2024-11-07 17:52:45 +0800411#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +0800412 memset(cli_threads, 0, sizeof(ril_cli_thread_info_t) * CLI_THREAD_MAX);
413
414 pthread_t pid1, pid2, pid3;
415 if(pthread_create(&pid1, NULL, sub_thread_run, &cli_threads[0]))
416 {
417 printf("pthread_create() fail.");
418 goto exit;
419 }
420
421 if(pthread_create(&pid2, NULL, sub_thread_run, &cli_threads[1]))
422 {
423 printf("pthread_create() fail.");
424 goto exit;
425 }
426
427 if(pthread_create(&pid3, NULL, sub_thread_run, &cli_threads[2]))
428 {
429 printf("pthread_create() fail.");
430 goto exit;
431 }
432#endif
433 printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n");
434 char cmd[100];
435 while(1)
436 {
437 memset(cmd, 0, 100);
438 mbtk_ril_err_enum err;
439 if(fgets(cmd, 100, stdin))
440 {
441 char *ptr = cmd + strlen(cmd) - 1;
442 while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
443 {
444 *ptr-- = '\0';
445 }
446 if(!strncasecmp(cmd, "version", 7))
447 {
448 char version[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800449 err = mbtk_version_get(handle_def, version);
b.liu87afc4c2024-08-14 17:33:45 +0800450 if(err != MBTK_RIL_ERR_SUCCESS) {
451 printf("Error : %d\n", err);
452 } else {
453 printf("Version : %s\n", version);
454 }
455 }
456 else if(!strncasecmp(cmd, "imei", 4)){
457 char imei[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800458 err = mbtk_imei_get(handle_def, imei);
b.liu87afc4c2024-08-14 17:33:45 +0800459 if(err != MBTK_RIL_ERR_SUCCESS) {
460 printf("Error : %d\n", err);
461 } else {
462 printf("IMEI : %s\n", imei);
463 }
464 } else if(!strncasecmp(cmd, "sn", 2)){
465 char sn[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800466 err = mbtk_sn_get(handle_def, sn);
b.liu87afc4c2024-08-14 17:33:45 +0800467 if(err != MBTK_RIL_ERR_SUCCESS) {
468 printf("Error : %d\n", err);
469 } else {
470 printf("SN : %s\n", sn);
471 }
472 } else if(!strncasecmp(cmd, "meid", 4)){
473 char meid[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800474 err = mbtk_meid_get(handle_def, meid);
b.liu87afc4c2024-08-14 17:33:45 +0800475 if(err != MBTK_RIL_ERR_SUCCESS) {
476 printf("Error : %d\n", err);
477 } else {
478 printf("MEID : %s\n", meid);
479 }
480 } else if(!strncasecmp(cmd, "volte", 5)){ // "volte" or "volte 0" or "volte 1"
481 int volte;
482 if(!strcasecmp(cmd, "volte")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800483 err = mbtk_volte_state_get(handle_def, &volte);
b.liu87afc4c2024-08-14 17:33:45 +0800484 if(err != MBTK_RIL_ERR_SUCCESS) {
485 printf("Error : %d\n", err);
486 } else {
487 printf("VoLTE : %d\n", volte);
488 }
489 } else { // Set
490 if(!strcasecmp(cmd, "volte 1")) { // Open VoLTE
491 volte = 1;
492 } else { // Close VoLTE
493 volte = 0;
494 }
b.liub171c9a2024-11-12 19:23:29 +0800495 err = mbtk_volte_state_set(handle_def, volte);
b.liu87afc4c2024-08-14 17:33:45 +0800496 if(err != MBTK_RIL_ERR_SUCCESS) {
497 printf("Error : %d\n", err);
498 } else {
499 printf("VoLTE set success\n");
500 }
501 }
502 } else if(!strncasecmp(cmd, "radio", 5)){ // "radio" or "radio 0" or "radio 1"
503 mbtk_radio_state_enum radio;
504 if(!strcasecmp(cmd, "radio")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800505 err = mbtk_radio_state_get(handle_def, &radio);
b.liu87afc4c2024-08-14 17:33:45 +0800506 if(err != MBTK_RIL_ERR_SUCCESS) {
507 printf("Error : %d\n", err);
508 } else {
509 printf("Radio : %d\n", radio);
510 }
511 } else { // Set
512 int reset;
513 int count = sscanf(cmd, "radio %d %d", &radio, &reset);
514 if(count > 0) {
515 if(count == 1) {
516 reset = 0;
517 }
518
b.liub171c9a2024-11-12 19:23:29 +0800519 err = mbtk_radio_state_set(handle_def, radio, reset);
b.liu87afc4c2024-08-14 17:33:45 +0800520 if(err != MBTK_RIL_ERR_SUCCESS) {
521 printf("Error : %d\n", err);
522 } else {
523 printf("Radio set success\n");
524 }
525 }
526 }
527 } else if(!strncasecmp(cmd, "temp", 4)){
528 int temp;
529 if(!strcasecmp(cmd, "temp 0")) {
b.liub171c9a2024-11-12 19:23:29 +0800530 err = mbtk_temp_get(handle_def, MBTK_TEMP_TYPE_SOC, &temp);
b.liu87afc4c2024-08-14 17:33:45 +0800531 if(err != MBTK_RIL_ERR_SUCCESS) {
532 printf("Error : %d\n", err);
533 } else {
534 printf("SOC : %d\n", temp);
535 }
536 } else if(!strcasecmp(cmd, "temp 1")) {
b.liub171c9a2024-11-12 19:23:29 +0800537 err = mbtk_temp_get(handle_def, MBTK_TEMP_TYPE_RF, &temp);
b.liu87afc4c2024-08-14 17:33:45 +0800538 if(err != MBTK_RIL_ERR_SUCCESS) {
539 printf("Error : %d\n", err);
540 } else {
541 printf("RF : %d\n", temp);
542 }
543 }
544 } else if(!strncasecmp(cmd, "cell_time", 9)){
545 char time[128] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800546 err = mbtk_cell_time_get(handle_def, time);
b.liu87afc4c2024-08-14 17:33:45 +0800547 if(err != MBTK_RIL_ERR_SUCCESS) {
548 printf("Error : %d\n", err);
549 } else {
550 printf("Cell Time : %s\n", time);
551 }
552 } else if(!strncasecmp(cmd, "sim_state", 9)){
553 mbtk_sim_state_enum sim;
b.liub171c9a2024-11-12 19:23:29 +0800554 err = mbtk_sim_state_get(handle_def, &sim);
b.liu87afc4c2024-08-14 17:33:45 +0800555 if(err != MBTK_RIL_ERR_SUCCESS) {
556 printf("Error : %d\n", err);
557 } else {
558 printf("Sim State : %d\n", sim);
559 }
560 } else if(!strncasecmp(cmd, "sim_type", 8)){
561 mbtk_sim_card_type_enum type;
b.liub171c9a2024-11-12 19:23:29 +0800562 err = mbtk_sim_type_get(handle_def, &type);
b.liu87afc4c2024-08-14 17:33:45 +0800563 if(err != MBTK_RIL_ERR_SUCCESS) {
564 printf("Error : %d\n", err);
565 } else {
566 printf("Sim Type : %d\n", type);
567 }
568 } else if(!strncasecmp(cmd, "imsi", 4)){
569 char imsi[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800570 err = mbtk_imsi_get(handle_def, imsi);
b.liu87afc4c2024-08-14 17:33:45 +0800571 if(err != MBTK_RIL_ERR_SUCCESS) {
572 printf("Error : %d\n", err);
573 } else {
574 printf("IMSI : %s\n", imsi);
575 }
576 } else if(!strncasecmp(cmd, "iccid", 5)){
577 char iccid[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800578 err = mbtk_iccid_get(handle_def, iccid);
b.liu87afc4c2024-08-14 17:33:45 +0800579 if(err != MBTK_RIL_ERR_SUCCESS) {
580 printf("Error : %d\n", err);
581 } else {
582 printf("ICCID : %s\n", iccid);
583 }
584 } else if(!strncasecmp(cmd, "pn", 2)){
585 char phone_number[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800586 err = mbtk_phone_number_get(handle_def, phone_number);
b.liu87afc4c2024-08-14 17:33:45 +0800587 if(err != MBTK_RIL_ERR_SUCCESS) {
588 printf("Error : %d\n", err);
589 } else {
590 printf("Phone Number : %s\n", phone_number);
591 }
592 }
593 /*
594 printf("pin_state:Get Sim lock state.\n");
595 printf("pin_times:Get PIN/PUK last times.\n");
596 printf("pin_open <PIN>:Enable sim lock.\n");
597 printf("pin_close <PIN>:Disable sim lock.\n");
598 printf("pin_change <old_pin> <new_pin>:Change sim PIN.\n");
599 printf("pin_verify <PIN>:Verify PIN.\n");
600 printf("puk_verify <PUK> <PIN>:Verify PUK.\n");
601 */
602 else if(!strncasecmp(cmd, "pin_state", 9)){
603 int lock_state;
b.liub171c9a2024-11-12 19:23:29 +0800604 err = mbtk_sim_lock_get(handle_def, &lock_state);
b.liu87afc4c2024-08-14 17:33:45 +0800605 if(err != MBTK_RIL_ERR_SUCCESS) {
606 printf("Error : %d\n", err);
607 } else {
608 printf("PIN state : %d\n", lock_state);
609 }
610 } else if(!strncasecmp(cmd, "pin_times", 9)){
611 mbtk_pin_puk_last_times_t times;
b.liub171c9a2024-11-12 19:23:29 +0800612 err = mbtk_sim_lock_retry_times_get(handle_def, &times);
b.liu87afc4c2024-08-14 17:33:45 +0800613 if(err != MBTK_RIL_ERR_SUCCESS) {
614 printf("Error : %d\n", err);
615 } else {
616 printf("PIN/PUK retry times:%d,%d,%d,%d\n", times.p1_retry, times.p2_retry, times.puk1_retry, times.puk2_retry);
617 }
618 } else if(!strncasecmp(cmd, "pin_open", 8)){
619 mbtk_sim_lock_info_t info;
620 info.type = MBTK_SIM_LOCK_TYPE_ENABLE;
621 int count = sscanf(cmd, "pin_open %s", info.pin1);
622 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800623 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800624 if(err != MBTK_RIL_ERR_SUCCESS) {
625 printf("Error : %d\n", err);
626 } else {
627 printf("Enable sim lock success.\n");
628 }
629 }
630 } else if(!strncasecmp(cmd, "pin_close", 9)){
631 mbtk_sim_lock_info_t info;
632 info.type = MBTK_SIM_LOCK_TYPE_DISABLE;
633 int count = sscanf(cmd, "pin_close %s", info.pin1);
634 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800635 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800636 if(err != MBTK_RIL_ERR_SUCCESS) {
637 printf("Error : %d\n", err);
638 } else {
639 printf("Disable sim lock success.\n");
640 }
641 }
642 } else if(!strncasecmp(cmd, "pin_change", 10)){
643 mbtk_sim_lock_info_t info;
644 info.type = MBTK_SIM_LOCK_TYPE_CHANGE;
645 int count = sscanf(cmd, "pin_change %s %s", info.pin1, info.pin2);
646 if(count == 2) {
b.liub171c9a2024-11-12 19:23:29 +0800647 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800648 if(err != MBTK_RIL_ERR_SUCCESS) {
649 printf("Error : %d\n", err);
650 } else {
651 printf("PIN change success.\n");
652 }
653 }
654 } else if(!strncasecmp(cmd, "pin_verify", 10)){
655 mbtk_sim_lock_info_t info;
656 info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PIN;
657 int count = sscanf(cmd, "pin_verify %s", info.pin1);
658 if(count == 1) {
b.liub171c9a2024-11-12 19:23:29 +0800659 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800660 if(err != MBTK_RIL_ERR_SUCCESS) {
661 printf("Error : %d\n", err);
662 } else {
663 printf("PIN verify success.\n");
664 }
665 }
666 } else if(!strncasecmp(cmd, "puk_verify", 10)){
667 mbtk_sim_lock_info_t info;
668 info.type = MBTK_SIM_LOCK_TYPE_VERIFY_PUK;
669 int count = sscanf(cmd, "puk_verify %s %s", info.puk, info.pin1);
670 if(count == 2) {
b.liub171c9a2024-11-12 19:23:29 +0800671 err = mbtk_sim_lock_set(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800672 if(err != MBTK_RIL_ERR_SUCCESS) {
673 printf("Error : %d\n", err);
674 } else {
675 printf("PUK verify success.\n");
676 }
677 }
678 } else if(!strncasecmp(cmd, "plmn", 4)){
679 mbtk_plmn_info info;
b.liub171c9a2024-11-12 19:23:29 +0800680 err = mbtk_plmn_list_get(handle_def, &info);
b.liu87afc4c2024-08-14 17:33:45 +0800681 if(err != MBTK_RIL_ERR_SUCCESS) {
682 printf("Error : %d\n", err);
683 } else {
684 printf("PLMN number:%d\n", info.count);
685 int i = 0;
686 while(i < info.count) {
687 printf("%d,%d,%s\n", i+1, info.plmn[i].format, info.plmn[i].name);
688 i++;
689 }
690 }
691 }
692 else if(!strncasecmp(cmd, "avail_net", 9)){
693 mbtk_net_info_array_t net_list;
b.liub171c9a2024-11-12 19:23:29 +0800694 err = mbtk_available_net_get(handle_1, &net_list);
b.liu87afc4c2024-08-14 17:33:45 +0800695 if(err != MBTK_RIL_ERR_SUCCESS) {
696 printf("Error : %d\n", err);
697 } else {
698 printf("Available net number:%d\n", net_list.num);
699 int i = 0;
700 while(i < net_list.num) {
701 printf("NET : %d,%d,%d,%d\n", net_list.net_info[i].net_sel_mode,
702 net_list.net_info[i].net_type, net_list.net_info[i].net_state,
703 net_list.net_info[i].plmn);
704 i++;
705 }
706 }
707 } else if(!strncasecmp(cmd, "sel_mode", 8)){ // "sel_mode" or "sel_mode 1 7 46000"
708 mbtk_net_info_t net;
709 memset(&net, 0, sizeof(mbtk_net_info_t));
710 if(!strcasecmp(cmd, "sel_mode")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800711 err = mbtk_net_sel_mode_get(handle_def, &net);
b.liu87afc4c2024-08-14 17:33:45 +0800712 if(err != MBTK_RIL_ERR_SUCCESS) {
713 printf("Error : %d\n", err);
714 } else {
715 printf("Net : %d, %d, %d, %d\n", net.net_sel_mode, net.net_type, net.net_state, net.plmn);
716 }
717 } else { // Set
718 char *ptr = strstr(cmd, " ");
719 if(ptr == NULL)
720 continue;
721 while(*ptr != '\0' && *ptr == ' ')
722 ptr++;
723 net.net_sel_mode = (uint8)atoi(ptr);
724
725 ptr = strstr(ptr, " ");
726 if(ptr == NULL)
727 continue;
728 while(*ptr != '\0' && *ptr == ' ')
729 ptr++;
730 net.net_type = (uint8)atoi(ptr);
731
732 ptr = strstr(ptr, " ");
733 if(ptr == NULL)
734 continue;
735 while(*ptr != '\0' && *ptr == ' ')
736 ptr++;
737 net.plmn = (uint32)atoi(ptr);
738
b.liub171c9a2024-11-12 19:23:29 +0800739 err = mbtk_net_sel_mode_set(handle_def, &net);
b.liu87afc4c2024-08-14 17:33:45 +0800740 if(err != MBTK_RIL_ERR_SUCCESS) {
741 printf("Error : %d\n", err);
742 } else {
743 printf("Net select mode set success\n");
744 }
745 }
746 } else if(!strncasecmp(cmd, "band", 4)){ // "band" or "band support" or "band 0 79 147 482 524503"
747 mbtk_band_info_t band;
748 memset(&band, 0x0, sizeof(mbtk_band_info_t));
749 if(!strcasecmp(cmd, "band")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800750 err = mbtk_current_band_get(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800751 if(err != MBTK_RIL_ERR_SUCCESS) {
752 printf("Error : %d\n", err);
753 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800754 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,
755 band.nr_3_band, band.nr_2_band, band.nr_1_band, band.nr_0_band);
b.liu87afc4c2024-08-14 17:33:45 +0800756 }
b.liubeb61cc2025-02-13 10:38:29 +0800757 } else if(!strcasecmp(cmd, "band_support")) { // Get
b.liub171c9a2024-11-12 19:23:29 +0800758 err = mbtk_support_band_get(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800759 if(err != MBTK_RIL_ERR_SUCCESS) {
760 printf("Error : %d\n", err);
761 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800762 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,
763 band.nr_3_band, band.nr_2_band, band.nr_1_band, band.nr_0_band);
b.liu87afc4c2024-08-14 17:33:45 +0800764 }
b.liubeb61cc2025-02-13 10:38:29 +0800765 } else { // "band 0 79 147 482 524503 x x x x"
766#if 0
b.liu87afc4c2024-08-14 17:33:45 +0800767 char *ptr = strstr(cmd, " ");
768 if(ptr == NULL)
769 continue;
770 while(*ptr != '\0' && *ptr == ' ')
771 ptr++;
772 band.net_pref = (uint8)atoi(ptr);
773
774 ptr = strstr(ptr, " ");
775 if(ptr == NULL)
776 continue;
777 while(*ptr != '\0' && *ptr == ' ')
778 ptr++;
779 band.gsm_band = (uint16)atoi(ptr);
780
781 ptr = strstr(ptr, " ");
782 if(ptr == NULL)
783 continue;
784 while(*ptr != '\0' && *ptr == ' ')
785 ptr++;
786 band.umts_band = (uint16)atoi(ptr);
787
788 ptr = strstr(ptr, " ");
789 if(ptr == NULL)
790 continue;
791 while(*ptr != '\0' && *ptr == ' ')
792 ptr++;
793 band.tdlte_band = (uint32)atoi(ptr);
794
795 ptr = strstr(ptr, " ");
796 if(ptr == NULL)
797 continue;
798 while(*ptr != '\0' && *ptr == ' ')
799 ptr++;
800 band.fddlte_band = (uint32)atoi(ptr);
b.liubeb61cc2025-02-13 10:38:29 +0800801#else
802 int count = sscanf(cmd, "band %d %d %d %d %d %d %d %d %d %d", &band.net_pref, &band.gsm_band, &band.umts_band,
803 &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 +0800804
b.liubeb61cc2025-02-13 10:38:29 +0800805 if(count != 10 && count != 1) {
806 printf("band set error.\n");
807 continue;
808 }
809#endif
b.liub171c9a2024-11-12 19:23:29 +0800810 err = mbtk_current_band_set(handle_def, &band);
b.liu87afc4c2024-08-14 17:33:45 +0800811 if(err != MBTK_RIL_ERR_SUCCESS) {
812 printf("Error : %d\n", err);
813 } else {
814 printf("Band set success\n");
815 }
816 }
817 } else if(!strncasecmp(cmd, "signal", 6)){
818 mbtk_signal_info_t signal;
b.liub171c9a2024-11-12 19:23:29 +0800819 err = mbtk_net_signal_get(handle_def, &signal);
b.liu87afc4c2024-08-14 17:33:45 +0800820 if(err != MBTK_RIL_ERR_SUCCESS) {
821 printf("Error : %d\n", err);
822 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800823 printf("Signal : %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n", signal.type, signal.rssi, signal.rxlev, signal.ber,
824 signal.rscp, signal.ecno, signal.rsrq, signal.rsrp, signal.ss_rsrq, signal.ss_rsrp, signal.ss_sinr);
b.liu87afc4c2024-08-14 17:33:45 +0800825 }
826 } else if(!strncasecmp(cmd, "reg", 3)){
827 mbtk_net_reg_info_t reg;
b.liub171c9a2024-11-12 19:23:29 +0800828 err = mbtk_net_reg_get(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +0800829 if(err != MBTK_RIL_ERR_SUCCESS) {
830 printf("Error : %d\n", err);
831 } else {
b.liubeb61cc2025-02-13 10:38:29 +0800832 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 +0800833 }
834 } else if(!strncasecmp(cmd, "apn_del", 7)) {
835 mbtk_apn_info_t apn;
836 memset(&apn, 0, sizeof(mbtk_apn_info_t));
837 int cid, auto_save;
838 int count = sscanf(cmd, "apn_del %d %d", &cid, &auto_save);
839 if(count == 2) {
840 apn.cid = (mbtk_ril_cid_enum)cid;
841 apn.auto_save = (uint8)auto_save;
842 }
b.liub171c9a2024-11-12 19:23:29 +0800843 err = mbtk_apn_set(handle_def, &apn);
b.liu87afc4c2024-08-14 17:33:45 +0800844 if(err != MBTK_RIL_ERR_SUCCESS) {
845 printf("Error : %d\n", err);
846 } else {
847 printf("APN delete success\n");
848 }
849
850 } else if(!strncasecmp(cmd, "apn", 3)){
851 if(!strcasecmp(cmd, "apn")) { // Get apn
852 mbtk_apn_info_array_t apns;
b.liub171c9a2024-11-12 19:23:29 +0800853 err = mbtk_apn_get(handle_def, &apns);
b.liu87afc4c2024-08-14 17:33:45 +0800854 if(err != MBTK_RIL_ERR_SUCCESS) {
855 printf("Error : %d\n", err);
856 } else {
857 printf("APN Num:%d\n", apns.num);
858 int i = 0;
859 while(i < apns.num) {
b.liu10a34102024-08-20 20:36:24 +0800860 // printf("APN : %d, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type), apns.apns[i].apn);
861 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),
862 apns.apns[i].auth, apns.apns[i].auto_save, apns.apns[i].auto_boot_call,
b.liu62240ee2024-11-07 17:52:45 +0800863 str_empty(apns.apns[i].apn) ? "NULL" : (char*)apns.apns[i].apn,
864 str_empty(apns.apns[i].user) ? "NULL" : (char*)apns.apns[i].user,
865 str_empty(apns.apns[i].pass) ? "NULL" : (char*)apns.apns[i].pass,
866 str_empty(apns.apns[i].type) ? "NULL" : (char*)apns.apns[i].type);
b.liu87afc4c2024-08-14 17:33:45 +0800867 i++;
868 }
b.liu10a34102024-08-20 20:36:24 +0800869 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 +0800870 }
871 } else { // apn <cid> <0/1/2/3> <0/1> <0/1> <apn>
872 mbtk_apn_info_t apn;
873 memset(&apn, 0, sizeof(mbtk_apn_info_t));
874#if 1
b.liubcf86c92024-08-19 19:48:28 +0800875 int cid, ip_type, auto_save, auto_boot_call, def_route, as_dns;
876 int count = sscanf(cmd, "apn %d %d %d %d %d %d %s",
877 &cid, &ip_type, &auto_save, &auto_boot_call,
878 &def_route, &as_dns, apn.apn);
b.liu87afc4c2024-08-14 17:33:45 +0800879
880 // Delete APN
b.liu62240ee2024-11-07 17:52:45 +0800881 if(strcmp((char*)apn.apn,"null") == 0 || strcmp((char*)apn.apn,"NULL") == 0) {
b.liu87afc4c2024-08-14 17:33:45 +0800882 memset(apn.apn, 0, sizeof(apn.apn));
883 }
b.liubcf86c92024-08-19 19:48:28 +0800884 if(count == 7) {
b.liu87afc4c2024-08-14 17:33:45 +0800885 apn.cid = (mbtk_ril_cid_enum)cid;
886 apn.ip_type = (mbtk_ip_type_enum)ip_type;
887 apn.auto_save = (uint8)auto_save;
888 apn.auto_boot_call = (uint8)auto_boot_call;
b.liubcf86c92024-08-19 19:48:28 +0800889 apn.def_route = (uint8)def_route;
890 apn.as_dns = (uint8)as_dns;
b.liu87afc4c2024-08-14 17:33:45 +0800891 }
892#else
893 char *ptr = strstr(cmd, " ");
894 if(ptr == NULL)
895 continue;
896 while(*ptr != '\0' && *ptr == ' ')
897 ptr++;
898 apn.cid = (mbtk_ril_cid_enum)atoi(ptr);
899
900 ptr = strstr(ptr, " ");
901 if(ptr == NULL)
902 continue;
903 while(*ptr != '\0' && *ptr == ' ')
904 ptr++;
905 apn.ip_type = (mbtk_ip_type_enum)atoi(ptr);
906
907 ptr = strstr(ptr, " ");
908 if(ptr == NULL)
909 continue;
910 while(*ptr != '\0' && *ptr == ' ')
911 ptr++;
912 memcpy(apn.apn, ptr, strlen(ptr));
913#endif
b.liub171c9a2024-11-12 19:23:29 +0800914 err = mbtk_apn_set(handle_def, &apn);
b.liu87afc4c2024-08-14 17:33:45 +0800915 if(err != MBTK_RIL_ERR_SUCCESS) {
916 printf("Error : %d\n", err);
917 } else {
918 printf("APN set success\n");
919 }
920 }
921 }
b.liubcf86c92024-08-19 19:48:28 +0800922 else if(!strncasecmp(cmd, "data_call", 9)){ // data_call <0/1/2> <cid> <timeout>
923 // mbtk_ril_cid_enum cid, bool auto_boot_call, bool def_route, int retry_interval, int timeout, mbtk_ip_info_t *rsp_info
924 // data_call <0/1/2> <cid> <timeout>
925 int type, cid, auto_boot_call, def_route, as_dns;
926 int count = sscanf(cmd, "data_call %d %d %d %d %d", &type, &cid, &auto_boot_call, &def_route, &as_dns);
927 if(count != 5) {
928 count = sscanf(cmd, "data_call %d %d", &type, &cid);
929 }
930
931 if(count == 5 || count == 2) {
932 mbtk_ip_info_t ip;
933 memset(&ip, 0, sizeof(mbtk_ip_info_t));
934 if(type == MBTK_DATA_CALL_START) {
b.liu15f456b2024-10-31 20:16:06 +0800935 int retry_interval[] = {5, 10, 15};
b.liuafdf2c62024-11-12 11:10:44 +0800936 if(count == 5) {
b.liub171c9a2024-11-12 19:23:29 +0800937 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 +0800938 (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 +0800939 3, 0, &ip);
b.liuafdf2c62024-11-12 11:10:44 +0800940 } else {
b.liub171c9a2024-11-12 19:23:29 +0800941 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 +0800942 MBTK_DATA_CALL_ITEM_STATE_NON, MBTK_DATA_CALL_ITEM_STATE_NON, retry_interval,
943 3, 0, &ip);
944 }
b.liubcf86c92024-08-19 19:48:28 +0800945 } else if(type == MBTK_DATA_CALL_STOP) {
b.liub171c9a2024-11-12 19:23:29 +0800946 err = mbtk_data_call_stop(handle_def, (mbtk_ril_cid_enum)cid, 10);
b.liubcf86c92024-08-19 19:48:28 +0800947 } else {
b.liub171c9a2024-11-12 19:23:29 +0800948 err = mbtk_data_call_state_get(handle_def, (mbtk_ril_cid_enum)cid, &ip);
b.liubcf86c92024-08-19 19:48:28 +0800949 }
950 if(err) {
951 printf("Error : %d\n", err);
952 } else {
953 printf("DATA_CALL success\n");
954 if(type == MBTK_DATA_CALL_START || type == MBTK_DATA_CALL_STATE) {
955 if(ip.ipv4.valid) {
956 // log_hex("IPv4", &ipv4, sizeof(mbtk_ipv4_info_t));
957 char ip_tmp[20];
958
959 memset(ip_tmp, 0, 20);
960 if(inet_ntop(AF_INET, &(ip.ipv4.IPAddr), ip_tmp, 20) == NULL) {
961 printf("IP error.\n");
962 } else {
963 printf("IP : %s\n", ip_tmp);
964 }
965
966 memset(ip_tmp, 0, 20);
967 if(inet_ntop(AF_INET, &(ip.ipv4.PrimaryDNS), ip_tmp, 20) == NULL) {
968 printf("PrimaryDNS error.\n");
969 } else {
970 printf("PrimaryDNS : %s\n", ip_tmp);
971 }
972
973 memset(ip_tmp, 0, 20);
974 if(inet_ntop(AF_INET, &(ip.ipv4.SecondaryDNS), ip_tmp, 20) == NULL) {
975 printf("SecondaryDNS error.\n");
976 } else {
977 printf("SecondaryDNS : %s\n", ip_tmp);
978 }
979
980 memset(ip_tmp, 0, 20);
981 if(inet_ntop(AF_INET, &(ip.ipv4.GateWay), ip_tmp, 20) == NULL) {
982 printf("GateWay error.\n");
983 } else {
984 printf("GateWay : %s\n", ip_tmp);
985 }
986
987 memset(ip_tmp, 0, 20);
988 if(inet_ntop(AF_INET, &(ip.ipv4.NetMask), ip_tmp, 20) == NULL) {
989 printf("NetMask error.\n");
990 } else {
991 printf("NetMask : %s\n", ip_tmp);
992 }
993 }
994
995 if(ip.ipv6.valid) {
996 // log_hex("IPv6", &ipv6, sizeof(mbtk_ipv6_info_t));
997 char ip_tmp[50];
998
999 memset(ip_tmp, 0, 50);
1000 if(ipv6_2_str(&(ip.ipv6.IPV6Addr), ip_tmp)) {
1001 printf("IP error.\n");
1002 } else {
1003 printf("IP : %s\n", ip_tmp);
1004 }
1005
1006 memset(ip_tmp, 0, 50);
1007 if(ipv6_2_str(&(ip.ipv6.PrimaryDNS), ip_tmp)) {
1008 printf("PrimaryDNS error.\n");
1009 } else {
1010 printf("PrimaryDNS : %s\n", ip_tmp);
1011 }
1012
1013 memset(ip_tmp, 0, 50);
1014 if(ipv6_2_str(&(ip.ipv6.SecondaryDNS), ip_tmp)) {
1015 printf("SecondaryDNS error.\n");
1016 } else {
1017 printf("SecondaryDNS : %s\n", ip_tmp);
1018 }
1019
1020 memset(ip_tmp, 0, 50);
1021 if(ipv6_2_str(&(ip.ipv6.GateWay), ip_tmp)) {
1022 printf("GateWay error.\n");
1023 } else {
1024 printf("GateWay : %s\n", ip_tmp);
1025 }
1026
1027 memset(ip_tmp, 0, 50);
1028 if(ipv6_2_str(&(ip.ipv6.NetMask), ip_tmp)) {
1029 printf("NetMask error.\n");
1030 } else {
1031 printf("NetMask : %s\n", ip_tmp);
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
b.liu87afc4c2024-08-14 17:33:45 +08001038 else if(!strncasecmp(cmd, "cell", 4)){
1039 char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME
1040 if(ptr == NULL)
1041 {
b.liub4772072024-08-15 14:47:03 +08001042 mbtk_cell_info_array_t cell;
b.liub171c9a2024-11-12 19:23:29 +08001043 err = mbtk_cell_get(handle_def, &cell);
b.liub4772072024-08-15 14:47:03 +08001044 if(err) {
b.liu87afc4c2024-08-14 17:33:45 +08001045 printf("Error : %d\n", err);
b.liub4772072024-08-15 14:47:03 +08001046 } else if(cell.num > 0){
1047 // Current server cell.
1048 switch(cell.type)
b.liu87afc4c2024-08-14 17:33:45 +08001049 {
b.liub4772072024-08-15 14:47:03 +08001050 case MBTK_CELL_TYPE_GSM:
1051 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);
1052 break;
1053 case MBTK_CELL_TYPE_UMTS:
1054 printf("UMTS : lac=%d, ci=%d, arfcn=%d\n", cell.cell[0].value1, cell.cell[0].value2, cell.cell[0].value3);
1055 break;
1056 case MBTK_CELL_TYPE_LTE:
1057 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);
1058 break;
b.liubeb61cc2025-02-13 10:38:29 +08001059 // mcc,mnc,tac,PCI,dlNrArfcn,ulNrArfcn,band,rsrp,rsrq,sinr,rssi
1060 // cellID
1061 case MBTK_CELL_TYPE_NR:
1062 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",
1063 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
1064 , 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);
1065 break;
b.liub4772072024-08-15 14:47:03 +08001066 default:
1067 break;
1068 }
1069
1070 int i = 1;
1071 while (i < cell.num)
1072 {
1073 switch(cell.type)
b.liu87afc4c2024-08-14 17:33:45 +08001074 {
b.liub4772072024-08-15 14:47:03 +08001075 case MBTK_CELL_TYPE_GSM:
1076 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 +08001077 break;
b.liub4772072024-08-15 14:47:03 +08001078 case MBTK_CELL_TYPE_UMTS:
1079 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 +08001080 break;
b.liub4772072024-08-15 14:47:03 +08001081 case MBTK_CELL_TYPE_LTE:
1082 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 +08001083 break;
b.liubeb61cc2025-02-13 10:38:29 +08001084 // phyCellId,nrArfcn,rsrp,rsrq
1085 case MBTK_CELL_TYPE_NR:
1086 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);
1087 break;
b.liu87afc4c2024-08-14 17:33:45 +08001088 default:
1089 break;
1090 }
b.liub4772072024-08-15 14:47:03 +08001091 i++;
b.liu87afc4c2024-08-14 17:33:45 +08001092 }
b.liub4772072024-08-15 14:47:03 +08001093 } else {
1094 printf("Cell no found.");
b.liu87afc4c2024-08-14 17:33:45 +08001095 }
b.liu87afc4c2024-08-14 17:33:45 +08001096 }
1097 else{
1098 char *ptr = strstr(cmd, ","); //cell,2,3,,40936,430
1099 char mem[50]={0};
1100 char resp[1024] = {0};
1101 if(ptr != NULL)
1102 {
1103 ptr++;
1104 memset(mem, 0, sizeof(mem));
1105 memcpy(mem, ptr, strlen(ptr));
1106 printf("cell:%s\n", mem);
1107 }
1108 printf("cell_mem: %s \n", mem);
1109
1110 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001111 err = mbtk_cell_set(handle_def, mem, resp);
b.liu87afc4c2024-08-14 17:33:45 +08001112 if(err) {
1113 printf("Error : %d\n", err);
1114 } else {
1115 printf("cell set . resp:%s\n", resp);
1116 }
b.liu87afc4c2024-08-14 17:33:45 +08001117 }
b.liub4772072024-08-15 14:47:03 +08001118 }
1119 else if(!strncasecmp(cmd, "call", 4)){
b.liu87afc4c2024-08-14 17:33:45 +08001120 char phone_number[12];
1121 char *ptr = strstr(cmd, " ");
1122 if(ptr == NULL)
1123 continue;
1124 while(*ptr != '\0' && *ptr == ' ')
1125 ptr++;
1126 memset(phone_number,0,strlen(phone_number));
1127 memcpy(phone_number,ptr,strlen(ptr));
1128 printf("phone number is: %s\n",phone_number);
b.liub171c9a2024-11-12 19:23:29 +08001129 err = mbtk_call_start(handle_def, phone_number);
b.liu87afc4c2024-08-14 17:33:45 +08001130 if(err) {
1131 printf("Error : %d\n", err);
1132 } else {
1133 printf("Call success.\n");
1134 }
1135 } else if(!strncasecmp(cmd, "answer", 6)){
b.liub171c9a2024-11-12 19:23:29 +08001136 err = mbtk_call_answer(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001137 if(err) {
1138 printf("Error : %d\n", err);
1139 } else {
1140 printf("Call success.\n");
1141 }
1142 } else if(!strncasecmp(cmd, "hangup", 6)){
b.liu62240ee2024-11-07 17:52:45 +08001143 int phone_id = 1;
b.liu87afc4c2024-08-14 17:33:45 +08001144 if(!strcasecmp(cmd, "hangup")) { // hang up all
b.liub171c9a2024-11-12 19:23:29 +08001145 err = mbtk_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001146 if(err) {
1147 printf("Error : %d\n", err);
1148 } else {
1149 printf("Call hang up all.\n");
1150 }
1151 } else if(!strcasecmp(cmd, "hangup 0")) {
b.liub171c9a2024-11-12 19:23:29 +08001152 err = mbtk_waiting_or_background_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001153 if(err) {
1154 printf("Error : %d\n", err);
1155 } else {
1156 printf("Call hang up waiting or background.\n");
1157 }
1158 } else if(!strcasecmp(cmd, "hangup 3")) {
b.liub171c9a2024-11-12 19:23:29 +08001159 err = mbtk_foreground_resume_background_call_hang(handle_def);
b.liu87afc4c2024-08-14 17:33:45 +08001160 if(err) {
1161 printf("Error : %d\n", err);
1162 } else {
1163 printf("Call hang up foreground resume background.\n");
1164 }
1165 } else {
1166 if(!strcasecmp(cmd, "hangup 1")) { // hang up a call
1167 phone_id = 1;
1168 } else if(!strcasecmp(cmd, "hangup 2")) {
1169 phone_id = 2;
1170 } else {
1171 printf("Error : Invalid input\n");
1172 }
b.liub171c9a2024-11-12 19:23:29 +08001173 err = mbtk_a_call_hang(handle_def, phone_id);
b.liu87afc4c2024-08-14 17:33:45 +08001174 if(err) {
1175 printf("Error : %d\n", err);
1176 } else {
1177 printf("A Call hang up.\n");
1178 }
1179 }
1180 } else if(!strncasecmp(cmd, "waitin", 6)){
1181 mbtk_call_info_t reg;
b.liub171c9a2024-11-12 19:23:29 +08001182 err = mbtk_call_reg_get(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +08001183 if(err) {
1184 printf("Error : %d\n", err);
1185 } else {
1186 if(reg.call_wait == 0) {
1187 printf("No call ring\n");
1188 }
1189 else {
1190 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);
1191 }
1192 }
1193 } else if(!strncasecmp(cmd, "mute", 4)){ // "mute" or "mute 0" or "mute 1"
1194 int mute;
1195 if(!strcasecmp(cmd, "mute")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001196 err = mbtk_mute_state_get(handle_def, &mute);
b.liu87afc4c2024-08-14 17:33:45 +08001197 if(err) {
1198 printf("Error : %d\n", err);
1199 } else {
1200 printf("mute : %d\n", mute);
1201 }
1202 } else { // Set
1203 if(!strcasecmp(cmd, "mute 1")) { // on mute
1204 mute = 1;
1205 } else { // off mute
1206 mute = 0;
1207 }
b.liub171c9a2024-11-12 19:23:29 +08001208 err = mbtk_mute_state_set(handle_def, mute);
b.liu87afc4c2024-08-14 17:33:45 +08001209 if(err) {
1210 printf("Error : %d\n", err);
1211 } else {
1212 printf("mute set success\n");
1213 }
1214 }
1215 } else if(!strncasecmp(cmd, "DTMF", 4)){ // valid character: (0, 1, ..., 9, A, B, C, D, *, #)
1216
1217 mbtk_call_dtmf_info_t reg;
1218
1219 char *ptr = strstr(cmd, " ");
1220 if(ptr == NULL)
1221 continue;
1222 while(*ptr != '\0' && *ptr == ' ')
1223 ptr++;
1224 reg.character = *ptr;
1225
1226 ptr = strstr(ptr, " ");
1227 if(ptr == NULL)
1228 continue;
1229 while(*ptr != '\0' && *ptr == ' ')
1230 ptr++;
1231 reg.duration = (uint32)atoi(ptr);
1232 printf("DTMF character is: %c,%d\n",reg.character, reg.duration);
b.liub171c9a2024-11-12 19:23:29 +08001233 err = mbtk_dtmf_send(handle_def, &reg);
b.liu87afc4c2024-08-14 17:33:45 +08001234 if(err) {
1235 printf("Error : %d\n", err);
1236 } else {
1237 printf("DTMF success.\n");
1238 }
b.liub4772072024-08-15 14:47:03 +08001239 } else if(!strncasecmp(cmd, "cmgf", 4)){ // set mode 0: pud, 1:text
1240 int mode;
1241 if(!strcasecmp(cmd, "cmgf")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001242 err = mbtk_sms_cmgf_get(handle_def, &mode);
b.liub4772072024-08-15 14:47:03 +08001243 if(err) {
1244 printf("Error : %d\n", err);
1245 } else {
1246 printf("VoLTE : %d\n", mode);
1247 }
1248 } else { // Set
1249 if(!strcasecmp(cmd, "cmgf 1")) { // cmgf 1
1250 mode = 1;
1251 } else { //
1252 mode = 0;
1253 }
1254 printf("mode:%d\n", mode);
1255 sleep(2);
b.liub171c9a2024-11-12 19:23:29 +08001256 err = mbtk_sms_cmgf_set(handle_def, mode);
b.liub4772072024-08-15 14:47:03 +08001257 if(err) {
1258 printf("Error : %d\n", err);
1259 } else {
1260 printf("VoLTE set success\n");
1261 }
1262 }
1263 }else if(!strncasecmp(cmd, "cpms", 4)){ // //CPMS=ME, ME, ME
1264 char mem[100] = {0};
1265 char resp[100] = {0};
1266 if(!strcasecmp(cmd, "cpms")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001267 err = mbtk_sms_cpms_get(handle_def, mem);
b.liub4772072024-08-15 14:47:03 +08001268 if(err) {
1269 printf("Error : %d\n", err);
1270 } else {
1271 printf("cpms : %s\n", mem);
1272 }
1273 } else { // Set
1274
1275 char *ptr = strstr(cmd, ","); //CPMS,ME,ME,ME
1276 if(ptr != NULL)
1277 {
1278 ptr++;
1279 memset(mem, 0, sizeof(mem));
1280 memcpy(mem, ptr, strlen(ptr));
1281 printf("cpms:%s\n", mem);
1282 }
1283 printf("cpms 0\n");
1284
1285 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001286 err = mbtk_sms_cpms_set(handle_def, mem, resp);
b.liub4772072024-08-15 14:47:03 +08001287 if(err) {
1288 printf("Error : %d\n", err);
1289 } else {
1290 printf("cpms set success. resp:%s\n", resp);
1291 }
1292 }
1293 }else if(!strncasecmp(cmd, "cmgs", 4)){ // AT+CMGS="10086", CMGS TEST
1294 char cmgs[1024] = {0};
1295 char resp[50] = {0};
1296 if(!strcasecmp(cmd, "cmgs")) { // Get
b.liudeb8e422024-12-14 17:36:56 +08001297 int mode = 0;
1298 err = 0;
b.liub4772072024-08-15 14:47:03 +08001299 // err = mbtk_sms_cmgs_get(info_handle, &mode);
1300 if(err) {
1301 printf("Error : %d\n", err);
1302 } else {
1303 printf("VoLTE : %d\n", mode);
1304 }
1305 } else { // Set
1306
1307 /*
1308 *AT+CMGS="10086", CMGS TEST // Send a SMS
1309 > CMGS TEST
1310 +CMGS: 17
1311 OK
1312 */
1313
1314 char *ptr = strstr(cmd, "cmgs,"); //CMGS="10086",hf
1315 if(ptr != NULL)
1316 {
1317 ptr = strstr(cmd, ",");
1318 ptr++;
1319 memset(cmgs, 0, sizeof(cmgs));
1320 memcpy(cmgs, ptr, strlen(ptr));
1321 printf("1cmgs:%s, strlen(cmgs):%d\n", cmgs, strlen(cmgs));
1322 }
1323
1324 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001325 err = mbtk_sms_cmgs_set(handle_def, cmgs, resp);
b.liub4772072024-08-15 14:47:03 +08001326 if(err) {
1327 printf("Error : %d\n", err);
1328 } else {
1329 printf("cmgs set success . resp:%s\n", resp);
1330 }
1331 }
1332 }else if(!strncasecmp(cmd, "cmss", 4)){ // +CMSS=<index>[,<da>[,<toda>]]
1333 char cmss[20] = {0};
1334 char resp[20] = {0};
1335 if(!strcasecmp(cmd, "cmgs")) { // Get
1336 printf("cmss : OK\n");
1337
1338 } else {
1339 char *ptr = strstr(cmd, "cmss,"); //CMSS=<index>
1340 if(ptr != NULL)
1341 {
1342 ptr = strstr(cmd, ",");
1343 ptr++;
1344 memset(cmss, 0, sizeof(cmss));
1345 memcpy(cmss, ptr, strlen(ptr));
1346 printf("1cmss:%s\n", cmss);
1347 }
1348
1349
b.liub171c9a2024-11-12 19:23:29 +08001350 err = mbtk_sms_cmss_set(handle_def, cmss, resp);
b.liub4772072024-08-15 14:47:03 +08001351 if(err) {
1352 printf("Error : %d\n", err);
1353 } else {
1354 printf("cmss set success. resp:%s\n", resp);
1355 }
1356 }
1357 }
1358 else if(!strncasecmp(cmd, "cmgr", 4)){ // +CMGR=<index
1359 int index = 0;
1360 char resp[1024] = {0};
1361 if(!strcasecmp(cmd, "cmgr")) { // Get
1362 printf("cmgr : OK\n");
1363
1364 } else {
1365 char *ptr = strstr(cmd, "cmgr,"); //+CMGR <index>
1366 if(ptr != NULL)
1367 {
1368 ptr = strstr(cmd, ",");
1369 ptr++;
1370 index = atoi(ptr);
1371 }
1372 printf("1index:%d\n", index);
1373
1374 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001375 err = mbtk_sms_cmgr_set(handle_def, index, resp);
b.liub4772072024-08-15 14:47:03 +08001376 if(err) {
1377 printf("Error : %d\n", err);
1378 } else {
1379 printf("cmgr set success. rep:%s\n", resp);
1380 }
1381 }
1382 }
1383 else if(!strncasecmp(cmd, "cmgw", 4)){ // +CMGW=<oa/da>[,<tooa/toda>[,<stat>]]<CR>
1384 //+CMGW=<length>[,<stat>]<CR>PDU is given<ctrl-Z/ESC>
1385 char cmgw[128] = {0};
1386 char resp[50] = {0};
1387 if(!strcasecmp(cmd, "cmgw")) { // Get
1388 printf("cmgw : OK\n");
1389
1390 } else {
1391 char *ptr = strstr(cmd, "cmgw,"); //+CMGW, <oa/da>, data
1392 if(ptr != NULL)
1393 {
1394 ptr = strstr(cmd, ",");
1395 ptr++;
1396 memset(cmgw, 0, sizeof(cmgw));
1397 memcpy(cmgw, ptr, strlen(ptr));
1398 printf("cmgw:%s\n", cmgw);
1399 }
1400
1401 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001402 err = mbtk_sms_cmgw_set(handle_def, cmgw, resp);
b.liub4772072024-08-15 14:47:03 +08001403 if(err) {
1404 printf("Error : %d\n", err);
1405 } else {
1406 printf("cmgw set success. resp:%s\n", resp);
1407 }
1408 }
1409 }
1410 else if(!strncasecmp(cmd, "cmgd", 4)){ // +CMGD=<index>[,<delflag>
1411 //
1412 char cmgd[128] = {0};
1413 if(!strcasecmp(cmd, "cmgd")) { // Get
1414 printf("cmgd : OK\n");
1415
1416 } else {
1417 char *ptr = strstr(cmd, ","); //+CMGD=<index>[,<delflag>
1418 if(ptr != NULL)
1419 {
1420 ptr++;
1421 memset(cmgd, 0, sizeof(cmgd));
1422 memcpy(cmgd, ptr, strlen(ptr));
1423 printf("1cmgd:%s\n", cmgd);
1424 }
1425
1426
b.liub171c9a2024-11-12 19:23:29 +08001427 err = mbtk_sms_cmgd_set(handle_def, cmgd);
b.liub4772072024-08-15 14:47:03 +08001428 if(err) {
1429 printf("Error : %d\n", err);
1430 } else {
1431 printf("VoLTE set success\n");
1432 }
1433 }
1434 }
1435 else if(!strncasecmp(cmd, "cmgl", 4)){ // AT+CMGL[=<stat>]
1436 //
1437 char cmgl[128] = {0};
1438 char resp[5*1024] ={0};
1439 if(!strcasecmp(cmd, "cmgl")) { // Get
1440 printf("cmgl : OK\n");
1441
1442 } else {
1443 char *ptr = strstr(cmd, "cmgl,"); // AT+CMGL[=<stat>]
1444 if(ptr != NULL)
1445 {
1446 ptr = strstr(cmd, ",");
1447 ptr++;
1448 memset(cmgl, 0, sizeof(cmgl));
1449 memcpy(cmgl, ptr, strlen(ptr));
1450 printf("0cmgl:%s\n", cmgl);
1451 }
1452
1453 memset(resp, 0, sizeof(resp));
b.liub171c9a2024-11-12 19:23:29 +08001454 err = mbtk_sms_cmgl_set(handle_def, cmgl, resp);
b.liub4772072024-08-15 14:47:03 +08001455 if(err) {
1456 printf("Error : %d\n", err);
1457 } else {
1458 // printf("cmgl set success, reg:%s\n",resp);
1459 }
1460 }
1461 }
1462 else if(!strncasecmp(cmd, "csca", 4)){ // AT+CSCA=<number> [,<type>]
1463 //
1464 char csca[128] = {0};
1465 if(!strcasecmp(cmd, "csca")) { // Get
b.liub171c9a2024-11-12 19:23:29 +08001466 err = mbtk_sms_csca_get(handle_def, csca);
b.liub4772072024-08-15 14:47:03 +08001467 if(err) {
1468 printf("mbtk_sms_csca_get Error : %d\n", err);
1469 } else {
1470 printf("mbtk_sms_csca_get success\n");
1471 }
1472
1473 } else {
1474 char *ptr = strstr(cmd, ","); // AT+CSCA=<number> [,<type>]
1475 if(ptr != NULL)
1476 {
1477 ptr++;
1478 memset(csca, 0, sizeof(csca));
1479 memcpy(csca, ptr, strlen(ptr));
1480 printf("csca:%s\n", csca);
1481 }
1482
b.liub171c9a2024-11-12 19:23:29 +08001483 err = mbtk_sms_csca_set(handle_def, csca);
b.liub4772072024-08-15 14:47:03 +08001484 if(err) {
1485 printf("Error : %d\n", err);
1486 } else {
1487 printf("VoLTE set success\n");
1488 }
1489 }
1490 }
1491 else if(!strncasecmp(cmd, "csmp", 4)){ // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1492 //
1493 char csmp[128] = {0};
1494 if(!strcasecmp(cmd, "csmp")) { // Get
1495 printf("cmgl : OK\n");
1496
1497 } else {
1498 char *ptr = strstr(cmd, ","); // AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1499 if(ptr != NULL)
1500 {
1501 ptr++;
1502 memset(csmp, 0, sizeof(csmp));
1503 memcpy(csmp, ptr, strlen(ptr));
1504 printf("csmp:%s\n", csmp);
1505 }
1506
b.liub171c9a2024-11-12 19:23:29 +08001507 err = mbtk_sms_csmp_set(handle_def, csmp);
b.liub4772072024-08-15 14:47:03 +08001508 if(err) {
1509 printf("Error : %d\n", err);
1510 } else {
1511 printf("VoLTE set success\n");
1512 }
1513 }
1514 }
1515 else if(!strncasecmp(cmd, "cscb", 4)){ // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1516 //
1517 char cscb[128] = {0};
1518 if(!strcasecmp(cmd, "cscb")) { // Get
1519 printf("cmgl : OK\n");
1520
1521 } else {
1522 char *ptr = strstr(cmd, ","); // AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1523 if(ptr != NULL)
1524 {
1525 ptr++;
1526 memset(cscb, 0, sizeof(cscb));
1527 memcpy(cscb, ptr, strlen(ptr));
1528 printf("cscb:%s\n", cscb);
1529 }
1530
b.liub171c9a2024-11-12 19:23:29 +08001531 err = mbtk_sms_cscb_set(handle_def, cscb);
b.liub4772072024-08-15 14:47:03 +08001532 if(err) {
1533 printf("Error : %d\n", err);
1534 } else {
1535 printf("VoLTE set success\n");
1536 }
1537 }
1538 }
1539#if 0
1540 else if(!strncasecmp(cmd, "shutdown", 8)){
b.liu87afc4c2024-08-14 17:33:45 +08001541 if(!strcasecmp(cmd, "shutdown 0")) {
1542 err = mbtk_system_reboot(0);
1543 if(err) {
1544 printf("Error : %d\n", err);
1545 } else {
1546 printf("Success.\n");
1547 }
1548 } else if(!strcasecmp(cmd, "shutdown 1")) {
1549 err = mbtk_system_reboot(1);
1550 if(err) {
1551 printf("Error : %d\n", err);
1552 } else {
1553 printf("Success.\n");
1554 }
1555 } else if(!strcasecmp(cmd, "shutdown 2")) {
1556 err = mbtk_system_reboot(2);
1557 if(err) {
1558 printf("Error : %d\n", err);
1559 } else {
1560 printf("Success.\n");
1561 }
1562 } else {
1563 printf("Error.");
1564 }
1565 } else if(!strncasecmp(cmd, "power_sim", 9)){
1566 if(!strcasecmp(cmd, "power_sim 0")) {
1567 err = mbtk_sim_power_set(0);
1568 if(err) {
1569 printf("Error : %d\n", err);
1570 } else {
1571 printf("Success.\n");
1572 }
1573 } else if(!strcasecmp(cmd, "power_sim 1")) {
1574 err = mbtk_sim_power_set(1);
1575 if(err) {
1576 printf("Error : %d\n", err);
1577 } else {
1578 printf("Success.\n");
1579 }
1580 } else {
1581 printf("Error.");
1582 }
1583 } else if(!strncasecmp(cmd, "time", 4)){
1584 if(!strcasecmp(cmd, "time 0")) {
1585 err = mbtk_time_set(info_handle, 0, NULL);
1586 if(err) {
1587 printf("Error : %d\n", err);
1588 } else {
1589 printf("Success.\n");
1590 }
1591 } else if(!strcasecmp(cmd, "time 1")) {
1592 err = mbtk_time_set(info_handle, 1, NULL);
1593 if(err) {
1594 printf("Error : %d\n", err);
1595 } else {
1596 printf("Success.\n");
1597 }
1598 } else if(!strncasecmp(cmd, "time 2 ", 7)) {
1599 err = mbtk_time_set(info_handle, 2, cmd + 7);
1600 if(err) {
1601 printf("Error : %d\n", err);
1602 } else {
1603 printf("Success.\n");
1604 }
1605 } else { // Get time type.
1606 int time_type;
1607 err = mbtk_time_get(info_handle, &time_type);
1608 if(err) {
1609 printf("Error : %d\n", err);
1610 } else {
1611 printf("Time type:%d.\n", time_type);
1612 }
1613 }
b.liu87afc4c2024-08-14 17:33:45 +08001614 }
1615#endif
1616 else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help")) {
1617 help();
1618 } else if(!strcasecmp(cmd, "q")) {
b.liubeb61cc2025-02-13 10:38:29 +08001619 //mbtk_ril_close(MBTK_AT_PORT_DEF);
1620 //mbtk_ril_close(ATPORTTYPE_1);
b.liu87afc4c2024-08-14 17:33:45 +08001621 break;
1622 } else {
1623 printf("\n");
1624 }
1625 }
1626 }
1627
b.liu62240ee2024-11-07 17:52:45 +08001628#if RIL_DEBUG_THREAD
b.liu87afc4c2024-08-14 17:33:45 +08001629 thread_exit_with_wait();
b.liu87afc4c2024-08-14 17:33:45 +08001630exit:
b.liu62240ee2024-11-07 17:52:45 +08001631#endif
b.liu571445f2025-02-13 10:22:55 +08001632 mbtk_ril_close(ATPORTTYPE_1);
b.liubeb61cc2025-02-13 10:38:29 +08001633 mbtk_ril_close(MBTK_AT_PORT_DEF);
b.liu87afc4c2024-08-14 17:33:45 +08001634
1635 LOG("Client exec complete.");
1636
1637 return 0;
1638}