blob: ac2189885d3b05d15e39e2f309284e6893657df3 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +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>
13
14#include "mbtk_info.h"
15#include "mbtk_list.h"
16#include "mbtk_utils.h"
17
18#include "time.h"
19
20#define EPOLL_LISTEN_MAX 100
21#define EPOLL_LISTEN_MAX 100
22
23#if 0
24struct
25{
26 uint8 operator[128];
27 uint8 operator[128];
28 uint8 mcc_mnc[10];
29} operator_mcc_mnc =
30{
31 {"China Mobile","CMCC","46000"},
32 {"China Unicom","CU","46001"},
33 {"China Mobile","CMCC","46002"},
34 {"China Telecom","CT","46003"},
35 {"China Mobile","CMCC","46004"},
36 {"China Telecom","CT","46005"},
37 {"China Unicom","CU","46006"},
38 {"China Mobile","CMCC","46007"},
39 {"China Mobile","CMCC","46008"},
40 {"China Unicom","CU","46009"},
41 {"China Telecom","CT","46011"},
42 {NULL, NULL, NULL}
43};
44#endif
45
46static int pack_process(mbtk_info_handle_t* handle, mbtk_info_pack_t* pack)
47{
48 mbtk_info_type_enum info_type = mbtk_info_type_get(pack->info_id);
49 LOG("Type : %s, ID : %s, Result : %s ,Length : %d", type2str(info_type),
50 id2str(pack->info_id),
51 err2str(pack->info_err),
52 pack->data_len);
53 if(0 && pack->data_len > 0)
54 {
55 log_hex("DATA", pack->data, pack->data_len);
56 }
57 // IND Message.
58 if(info_type == MBTK_INFO_TYPE_IND)
59 {
60 if(pack->data_len > 0 && pack->data != NULL) // IND message.
61 {
62 log_hex(id2str(pack->info_id), pack->data, pack->data_len);
63 switch(pack->info_id)
64 {
65 case MBTK_INFO_ID_IND_NET_STATE_CHANGE:
66 {
67 if(handle->net_state_cb)
68 handle->net_state_cb(pack->data, pack->data_len);
69 break;
70 }
71 case MBTK_INFO_ID_IND_CALL_STATE_CHANGE:
72 {
73 if(handle->call_state_cb)
74 handle->call_state_cb(pack->data, pack->data_len);
75 break;
76 }
77 case MBTK_INFO_ID_IND_SMS_STATE_CHANGE:
78 {
79 if(handle->sms_state_cb)
80 handle->sms_state_cb(pack->data, pack->data_len);
81 break;
82 }
83 case MBTK_INFO_ID_IND_RADIO_STATE_CHANGE:
84 {
85 if(handle->radio_state_cb)
86 handle->radio_state_cb(pack->data, pack->data_len);
87 break;
88 }
89 case MBTK_INFO_ID_IND_SIM_STATE_CHANGE:
90 {
91 if(handle->sim_state_cb)
92 handle->sim_state_cb(pack->data, pack->data_len);
93 break;
94 }
95 case MBTK_INFO_ID_IND_PDP_STATE_CHANGE:
96 {
97 if(handle->pdp_state_cb)
98 handle->pdp_state_cb(pack->data, pack->data_len);
99 break;
100 }
101 //mbtk wyq for server_ready_status add start
102 case MBTK_INFO_ID_IND_SERVER_STATE_CHANGE:
103 {
104 handle->server_ready_status = 1;
105 LOG("handshake message recv ok.");
106 break;
107 }
108 //mbtk wyq for server_ready_status add end
109 default:
110 {
111 LOG("Unknown IND : %d", pack->info_id);
112 break;
113 }
114 }
115 }
116 else // Register IND response.
117 {
118 handle->info_err = pack->info_err;
119 if(pack->info_err == MBTK_INFO_ERR_SUCCESS)
120 {
121 LOG("IND %s register success.", id2str(pack->info_id));
122 }
123 else
124 {
125 LOG("IND %s register fail : %s", id2str(pack->info_id), err2str(pack->info_err));
126 }
127
128 if(handle->is_waitting) {
129 pthread_mutex_lock(&handle->mutex);
130 pthread_cond_signal(&handle->cond);
131 pthread_mutex_unlock(&handle->mutex);
132 }
133 }
134 }
135 else // Response Information.
136 {
137 handle->info_err = pack->info_err;
138
139 // Set data length.
140 // If data change,will change this lenght in mbtk_info_pack_data_get().
141 handle->data_len = pack->data_len;
142 // Copy data buffer,because it will be released.
143 if(handle->data && pack->data && pack->data_len > 0) {
144 memcpy(handle->data, pack->data, handle->data_len);
145 }
146
147 if(handle->is_waitting) {
148 pthread_mutex_lock(&handle->mutex);
149 pthread_cond_signal(&handle->cond);
150 pthread_mutex_unlock(&handle->mutex);
151 }
152
153
154#if 0
155 if(pack->info_err == MBTK_INFO_ERR_SUCCESS)
156 {
157 LOG("REQ %s success.", id2str(pack->info_id));
158#if 0
159 if(pack->data_len > 0)
160 {
161 log_hex("DATA", pack->data, pack->data_len);
162 }
163#endif
164 switch(pack->info_id)
165 {
166 case MBTK_INFO_ID_NET_AVAILABLE_RSP:
167 {
168 mbtk_net_array_info_t* nets = (mbtk_net_array_info_t*)mbtk_info_pack_data_get(pack);
169 if(nets)
170 {
171 mbtk_net_info_t *net = NULL;
172 list_first(nets->net_list);
173 while ((net = (mbtk_net_info_t*) list_next(nets->net_list)))
174 {
175 LOG("NET : %d, %d, %s", net->net_sel_mode, net->net_type, net->plmn);
176 }
177 list_free(nets->net_list);
178 free(nets);
179 }
180 else
181 {
182 LOG("mbtk_info_pack_data_get() fail.");
183 }
184
185 break;
186 }
187 case MBTK_INFO_ID_NET_SEL_MODE_RSP:
188 {
189 mbtk_net_info_t* net = (mbtk_net_info_t*)mbtk_info_pack_data_get(pack);
190 if(net)
191 {
192 LOG("NET : %d, %d, %d", net->net_sel_mode, net->net_type, net->plmn);
193 free(net);
194 }
195 else
196 {
197 LOG("mbtk_info_pack_data_get() fail.");
198 }
199
200 break;
201 }
202 case MBTK_INFO_ID_NET_BAND_RSP:
203 {
204 mbtk_band_info_t* band = (mbtk_band_info_t*)mbtk_info_pack_data_get(pack);
205 if(band) {
206 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref,
207 band->gsm_band,
208 band->umts_band,
209 band->tdlte_band,
210 band->fddlte_band);
211 } else {
212 LOG("mbtk_info_pack_data_get() fail.");
213 }
214
215 break;
216 }
217 default:
218 {
219 break;
220 }
221 }
222 }
223 else
224 {
225 LOG("REQ %s fail : %s", id2str(pack->info_id), err2str(pack->info_err));
226 }
227#endif
228 }
229 return 0;
230}
231
232
233static void* info_read_run(void* arg)
234{
235 int epoll_fd = epoll_create(5);
236 if(epoll_fd < 0)
237 {
238 LOG("epoll_create() fail[%d].", errno);
239 return NULL;
240 }
241 mbtk_info_handle_t* handle = (mbtk_info_handle_t*)arg;
242
243 uint32 event = EPOLLIN | EPOLLET;
244 struct epoll_event ev_cli, ev_exit;
245 ev_cli.data.fd = handle->client_fd;
246 ev_cli.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
247 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->client_fd,&ev_cli);
248
249 ev_exit.data.fd = handle->exit_fd[0];
250 ev_exit.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
251 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->exit_fd[0],&ev_exit);
252
253 int nready = -1;
254 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
255 while(1)
256 {
257 nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
258 if(nready > 0)
259 {
260 int i;
261 for(i = 0; i < nready; i++)
262 {
263 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
264 if(epoll_events[i].events & EPOLLHUP) // Closed by server.
265 {
266
267 }
268 else if(epoll_events[i].events & EPOLLIN)
269 {
270 if(handle->client_fd == epoll_events[i].data.fd) // Server data arrive.
271 {
272 // Read and process every message.
273 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
274 mbtk_info_pack_t **pack = mbtk_info_pack_recv(handle->client_fd, false, &err);
275
276 // Parse packet error,send error response to client.
277 if(pack == NULL)
278 {
279 if(err != MBTK_INFO_ERR_SUCCESS)
280 {
281 LOG("RSP packet error[%s].", err2str(err));
282 }
283 }
284 else
285 {
286 mbtk_info_pack_t** pack_ptr = pack;
287 while(*pack_ptr)
288 {
289 pack_process(handle, *pack_ptr);
290 mbtk_info_pack_free(pack_ptr);
291 pack_ptr++;
292 }
293 free(pack);
294 }
295 }
296 else if(handle->exit_fd[0] == epoll_events[i].data.fd) //
297 {
298 char buff[100] = {0};
299 int len = read(handle->exit_fd[0], buff, 100);
300 if(len > 0) {
301 LOGI("CMD : %s", buff);
302 if(strcmp(buff, "EXIT") == 0) {
303 goto read_thread_exit;
304 } else {
305 LOGD("Unkonw cmd : %s", buff);
306 }
307 } else {
308 LOGE("sock_read() fail.");
309 }
310 }
311 else
312 {
313 LOG("Unknown socket : %d", epoll_events[i].data.fd);
314 }
315 }
316 else
317 {
318 LOG("Unknown event : %x", epoll_events[i].events);
319 }
320 }
321 }
322 else
323 {
324 LOG("epoll_wait() fail[%d].", errno);
325 }
326 }
327
328read_thread_exit:
329 LOGD("info_read thread exit.");
330 return NULL;
331}
332
333#if 0
334static int info_item_get(mbtk_info_handle_t* handle, mbtk_info_id_enum id, void* data)
335{
336 int data_len = 0;
337 if(data == NULL) {
338 LOG("data is null.");
339 return -1;
340 }
341 mbtk_info_pack_t* pack = mbtk_info_pack_creat(id);
342 if(pack == NULL) {
343 LOG("mbtk_info_item_get() fail.");
344 return -1;
345 }
346
347 mbtk_info_pack_send(handle->client_fd, pack);
348 mbtk_info_pack_free(&pack);
349 handle->data = data;
350
351 // Wait for server response.
352 pthread_mutex_lock(&handle->mutex);
353 handle->is_waitting = true;
354 pthread_cond_wait(&handle->cond, &handle->mutex);
355 handle->is_waitting = false;
356 pthread_mutex_unlock(&handle->mutex);
357
358 if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
359 {
360 LOG("REQ %s success.", id2str(id));
361 if(data && handle->data_len > 0) {
362 data_len = handle->data_len;
363 handle->data_len = 0;
364 handle->data = NULL;
365 }
366 return data_len;
367 } else {
368 LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
369 return -1;
370 }
371}
372#endif
373
374/*
375* Return recv data length.
376* -1 : fail.
377*/
378static int info_item_process(mbtk_info_handle_t *handle,
379 mbtk_info_id_enum id,
380 const void *send_buff,
381 int send_buff_len,
382 void *recv_buff)
383{
384 if(handle == NULL/* || ((send_buff == NULL || send_buff_len == 0) && recv_buff == NULL)*/) {
385 LOG("ARG error.");
386 return -1;
387 }
388
389 mbtk_info_pack_t* pack = mbtk_info_pack_creat(id);
390 if(pack == NULL) {
391 return -1;
392 }
393 if(send_buff && send_buff_len > 0) { // Set the data to be sent.
394 // log_hex("data", send_buff, send_buff_len);
395 // mbtk_info_pack_data_set(pack, data, data_len);
396 pack->data_len = (uint16)send_buff_len;
397 pack->data = (const uint8*)send_buff;
398 }
wangyouqiang962740a2023-11-02 19:27:22 +0800399
400 pthread_mutex_lock(&handle->send_mutex);
401 pthread_mutex_lock(&handle->mutex);
402 handle->is_waitting = true;
b.liu27b91e42024-01-17 20:02:30 +0800403
liubin281ac462023-07-19 14:22:54 +0800404 mbtk_info_pack_send(handle->client_fd, pack);
405 mbtk_info_pack_free(&pack);
406
407 if(recv_buff != NULL)
408 handle->data = recv_buff;
409
410 // Wait for server response.
liubin281ac462023-07-19 14:22:54 +0800411 pthread_cond_wait(&handle->cond, &handle->mutex);
412 handle->is_waitting = false;
413 pthread_mutex_unlock(&handle->mutex);
414
415 if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
416 {
417 LOG("REQ %s success.", id2str(id));
418 int recv_len = 0;
419 if(recv_buff && handle->data_len > 0) {
420 recv_len = handle->data_len;
421 handle->data_len = 0;
422 handle->data = NULL;
423 }
wangyouqiang962740a2023-11-02 19:27:22 +0800424 pthread_mutex_unlock(&handle->send_mutex);
liubin281ac462023-07-19 14:22:54 +0800425 return recv_len;
426 } else {
427 LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
wangyouqiang962740a2023-11-02 19:27:22 +0800428 pthread_mutex_unlock(&handle->send_mutex);
liubin281ac462023-07-19 14:22:54 +0800429 return -1;
430 }
431}
432
433
434
435mbtk_info_handle_t* mbtk_info_handle_get()
436{
437 mbtk_info_handle_t* handle = (mbtk_info_handle_t*)malloc(sizeof(mbtk_info_handle_t));
438 if(!handle)
439 {
440 LOG("malloc() error[%d].", errno);
441 return NULL;
442 }
443 memset(handle, 0, sizeof(mbtk_info_handle_t));
444 handle->client_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
445 if(handle->client_fd < 0)
446 {
447 LOG("socket() fail[%d].", errno);
448 goto error;
449 }
450
451 // Set O_NONBLOCK
452 int flags = fcntl(handle->client_fd, F_GETFL, 0);
453 if (flags < 0)
454 {
455 LOG("Get flags error:%d", errno);
456 goto error;
457 }
458 flags |= O_NONBLOCK;
459 if (fcntl(handle->client_fd, F_SETFL, flags) < 0)
460 {
461 LOG("Set flags error:%d", errno);
462 goto error;
463 }
464
465 struct sockaddr_un cli_addr;
466 memset(&cli_addr, 0, sizeof(cli_addr));
467 cli_addr.sun_family = AF_LOCAL;
468 strcpy(cli_addr.sun_path, SOCK_INFO_PATH);
469 if(connect(handle->client_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
470 {
471 LOG("connect() fail[%d].", errno);
472 goto error;
473 }
474
475 if(pipe(handle->exit_fd)) {
476 LOG("pipe() fail[%d].", errno);
477 goto error;
478 }
479#if 0
480 pthread_attr_t thread_attr;
481 pthread_attr_init(&thread_attr);
482 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
483 {
484 LOG("pthread_attr_setdetachstate() fail.");
485 goto error;
486 }
487
488 if(pthread_create(&(handle->read_thread_id), &thread_attr, info_read_run, handle))
489 {
490 LOG("pthread_create() fail.");
491 goto error;
492 }
493 pthread_attr_destroy(&thread_attr);
494#else
495 if(pthread_create(&(handle->read_thread_id), NULL, info_read_run, handle))
496 {
497 LOG("pthread_create() fail.");
498 goto error;
499 }
500#endif
501
502 pthread_mutex_init(&handle->mutex, NULL);
wangyouqiang962740a2023-11-02 19:27:22 +0800503 pthread_mutex_init(&handle->send_mutex, NULL);
liubin281ac462023-07-19 14:22:54 +0800504 pthread_cond_init(&handle->cond, NULL);
505 handle->is_waitting = false;
506
507 //mbtk wyq for server_ready_status add start
508 int timeout = 5;//The wait server timeout by default
509 LOG("wait server handshake message--->.");
510 while(timeout)
511 {
512 if(handle->server_ready_status)
513 {
514 break;
515 }
516 else
517 {
518 sleep(1);
519 timeout--;
520 }
521 }
522
523 if(timeout <= 0)
524 {
525 if(handle->exit_fd[1] > 0)
526 {
527 write(handle->exit_fd[1], "EXIT", 4);
528 }
529 pthread_join(handle->read_thread_id,NULL);
530 LOG("mbtk_info_handle_get() server not ready.");
531 goto error;
532 }
533 else
534 {
535 LOG("mbtk_info_handle_get() server ready ok.");
536 }
537 //mbtk wyq for server_ready_status add end
538 return handle;
539error:
540 if(handle)
541 {
542 if(handle->client_fd > 0)
543 {
544 close(handle->client_fd);
545 }
546 if(handle->exit_fd[0] > 0) {
547 close(handle->exit_fd[0]);
548 }
549 if(handle->exit_fd[1] > 0) {
550 close(handle->exit_fd[1]);
551 }
552 free(handle);
553 handle = NULL;
554 }
555
556 return NULL;
557}
558
559int mbtk_info_handle_free(mbtk_info_handle_t** handle)
560{
561 if(handle == NULL || *handle == NULL)
562 {
563 LOG("Handle is NULL.");
564 return -1;
565 }
566
567 if((*handle)->exit_fd[1] > 0) {
568 write((*handle)->exit_fd[1], "EXIT", 4);
569 }
570
571 // Wait read_thread exit.
572 pthread_join((*handle)->read_thread_id,NULL);
573
574 if((*handle)->exit_fd[0] > 0) {
575 close((*handle)->exit_fd[0]);
576 (*handle)->exit_fd[0] = -1;
577 }
578
579 if((*handle)->exit_fd[1] > 0) {
580 close((*handle)->exit_fd[1]);
581 (*handle)->exit_fd[1] = -1;
582 }
583
584 if((*handle)->client_fd > 0)
585 {
586 close((*handle)->client_fd);
587 (*handle)->client_fd = -1;
588 }
589 free(*handle);
590 *handle = NULL;
591 return 0;
592}
593
594/*
595* Get platform version.
596*/
597int mbtk_version_get(mbtk_info_handle_t* handle, void *version)
598{
599 if(handle == NULL || version == NULL)
600 {
601 LOGE("ARG error.");
602 return -1;
603 }
604
605 if(info_item_process(handle, MBTK_INFO_ID_DEV_VERSION_REQ, NULL, 0, version) > 0) {
606 LOG("Version : %s", version);
607 return 0;
608 } else {
609 return handle->info_err;
610 }
611}
612
613/*
614* Get platform version.
615*/
616int mbtk_model_get(mbtk_info_handle_t* handle, void *model)
617{
618 if(handle == NULL || model == NULL)
619 {
620 LOGE("ARG error.");
621 return -1;
622 }
623
624 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEL_REQ, NULL, 0, model) > 0) {
625 LOG("Version : %s", model);
626 return 0;
627 } else {
628 return handle->info_err;
629 }
630}
631
632/*
633* Get platform IMEI.
634*/
635int mbtk_imei_get(mbtk_info_handle_t* handle, void *imei)
636{
637 if(handle == NULL || imei == NULL)
638 {
639 LOGE("ARG error.");
640 return -1;
641 }
642 if(info_item_process(handle, MBTK_INFO_ID_DEV_IMEI_REQ, NULL, 0, imei) > 0) {
643 LOG("IMEI : %s", imei);
644 return 0;
645 } else {
646 return handle->info_err;
647 }
648}
649
650/*
651* Get platform SN.
652*/
653int mbtk_sn_get(mbtk_info_handle_t* handle, void *sn)
654{
655 if(handle == NULL || sn == NULL)
656 {
657 LOGE("ARG error.");
658 return -1;
659 }
660 if(info_item_process(handle, MBTK_INFO_ID_DEV_SN_REQ, NULL, 0, sn) > 0) {
661 LOG("SN : %s", sn);
662 return 0;
663 } else {
664 return handle->info_err;
665 }
666}
667
668/*
669* Get platform MEID.
670*/
671int mbtk_meid_get(mbtk_info_handle_t* handle, void *meid)
672{
673 if(handle == NULL || meid == NULL)
674 {
675 LOGE("ARG error.");
676 return -1;
677 }
678 if(info_item_process(handle, MBTK_INFO_ID_DEV_MEID_REQ, NULL, 0, meid) > 0) {
679 LOG("MEID : %s", meid);
680 return 0;
681 } else {
682 return handle->info_err;
683 }
684}
685
686/*
687* Return VoLTE state.
688*/
689int mbtk_volte_state_get(mbtk_info_handle_t* handle, int *volte_state)
690{
691 uint8 state;
692 if(handle == NULL || volte_state == NULL)
693 {
694 LOGE("ARG error.");
695 return -1;
696 }
697 if(info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, NULL, 0, &state) > 0) {
698 LOG("VoLTE State : %d", state);
699 *volte_state = state;
700 return 0;
701 } else {
702 return handle->info_err;
703 }
704}
705
706/*
707* Set VoLTE state.
708*
709* volte_state:
710* 0 : Close VoLTE.
711* 1 : Open VoLTE.
712*
713* Restarting takes effect after execution.
714*/
715int mbtk_volte_state_set(mbtk_info_handle_t* handle, int volte_state)
716{
717 if(handle == NULL)
718 {
719 LOGE("ARG error.");
720 return -1;
721 }
722 return info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, (uint8*)&volte_state, sizeof(uint8), NULL) ? handle->info_err : 0;
723}
724
725/*
726* Get platform IMSI.
727*/
728int mbtk_imsi_get(mbtk_info_handle_t* handle, void *imsi)
729{
730 if(handle == NULL || imsi == NULL)
731 {
732 LOGE("ARG error.");
733 return -1;
734 }
735 if(info_item_process(handle, MBTK_INFO_ID_SIM_IMSI_REQ, NULL, 0, imsi) > 0) {
736 LOG("IMSI : %s", imsi);
737 return 0;
738 } else {
739 return handle->info_err;
740 }
741}
742
743/*
744* Get platform ICCID.
745*/
746int mbtk_iccid_get(mbtk_info_handle_t* handle, void *iccid)
747{
748 if(handle == NULL || iccid == NULL)
749 {
750 LOGE("ARG error.");
751 return -1;
752 }
753 if(info_item_process(handle, MBTK_INFO_ID_SIM_ICCID_REQ, NULL, 0, iccid) > 0) {
754 LOG("ICCID : %s", iccid);
755 return 0;
756 } else {
757 return handle->info_err;
758 }
759}
760
761/*
762* Get current phone number.
763*/
764int mbtk_phone_number_get(mbtk_info_handle_t* handle, void *phone_number)
765{
766 if(handle == NULL || phone_number == NULL)
767 {
768 LOGE("ARG error.");
769 return -1;
770 }
771 if(info_item_process(handle, MBTK_INFO_ID_SIM_PN_REQ, NULL, 0, phone_number) > 0) {
772 LOG("Phone Number : %s", phone_number);
773 return 0;
774 } else {
775 return handle->info_err;
776 }
777}
778
779/*
780* Get PIN’s number of remaining retry
781*/
782int mbtk_pin_last_num_get(mbtk_info_handle_t* handle, mbtk_pin_puk_last_times *last_times)
783{
784 if(handle == NULL || last_times == NULL)
785 {
786 LOGE("ARG error.");
787 return -1;
788 }
789 if(info_item_process(handle, MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ, NULL, 0, last_times) > 0) {
790 LOG("Sim sim_pin_puk_last_times : %d, %d, %d, %d", last_times->p1_retry,last_times->p2_retry,last_times->puk1_retry,last_times->puk2_retry);
791 return 0;
792 } else {
793 return handle->info_err;
794 }
795}
796
797/*
798* emable PIN
799*/
800int mbtk_enable_pin(mbtk_info_handle_t* handle, mbtk_enable_pin_info *pin)
801{
802 if(handle == NULL)
803 {
804 LOGE("ARG error.");
805 return -1;
806 }
807 if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, pin, sizeof(mbtk_enable_pin_info), NULL) >= 0) {
808 LOG("pin Number : %s", pin->pin_value);
809 return 0;
810 } else {
811 return handle->info_err;
812 }
813
814}
815
816/*
817* Verify PIN
818*/
819int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin)
820{
821 if(handle == NULL)
822 {
823 LOGE("ARG error.");
824 return -1;
825 }
826 if(info_item_process(handle, MBTK_INFO_ID_SIM_PIN_REQ, pin, strlen(pin), NULL) >= 0) {
827 LOG("pin Number : %s", pin);
828 return 0;
829 } else {
830 return handle->info_err;
831 }
832
833}
834
835/*
836* Verify PIN
837*/
838int mbtk_change_pin(mbtk_info_handle_t* handle, mbtk_change_pin_info *pin)
839{
840 if(handle == NULL)
841 {
842 LOGE("ARG error.");
843 return -1;
844 }
845 if(info_item_process(handle, MBTK_INFO_ID_SIM_CHANGE_PIN_REQ, pin, sizeof(mbtk_change_pin_info), NULL) >= 0) {
846 LOG("Change PIN : %s -> %s", pin->old_pin_value, pin->new_pin_value);
847 return 0;
848 } else {
849 return handle->info_err;
850 }
851}
852
853/*
854* unblock_pin
855*/
856int mbtk_unlock_pin(mbtk_info_handle_t* handle, mbtk_unlock_pin_info *pin)
857{
858 if(handle == NULL)
859 {
860 LOGE("ARG error.");
861 return -1;
862 }
863 if(info_item_process(handle, MBTK_INFO_ID_SIM_PUK_REQ, pin, sizeof(mbtk_unlock_pin_info), NULL) >= 0) {
864 LOG("Unlock : %s , %s", pin->pin_value , pin->puk_value);
865 return 0;
866 } else {
867 return handle->info_err;
868 }
869}
870
871/*
872* Get plmn list
873*/
874int mbtk_get_plmn_list(mbtk_info_handle_t* handle, mbtk_plmn_info *pin)
875{
876 if(handle == NULL)
877 {
878 LOGE("ARG error.");
879 return -1;
880 }
881 if(info_item_process(handle, MBTK_INFO_ID_SIM_PLMN_REQ, NULL, 0, pin) >= 0) {
882 //LOG("pin Number : %s", pin);
883 return 0;
884 } else {
885 return handle->info_err;
886 }
887}
888
889
890/*
891* Get available network.
892*/
893int mbtk_available_net_get(mbtk_info_handle_t* handle, list_node_t **net_list)
894{
895 if(handle == NULL)
896 {
897 LOGE("ARG error.");
898 return -1;
899 }
900 *net_list = list_create(NULL);
901 if(*net_list == NULL)
902 {
903 LOG("list_create() fail.");
904 return MBTK_INFO_ERR_MEMORY;
905 }
906
907 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
908 int buff_len;
909 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_AVAILABLE_REQ, NULL, 0, buff)) > 0) {
910 int i = 0;
911 while (i < buff_len / sizeof(mbtk_net_info_t))
912 {
913 mbtk_net_info_t* net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t));
914 if(net == NULL)
915 {
916 LOG("malloc() fail.");
917 list_free(*net_list);
918 return MBTK_INFO_ERR_MEMORY;
919 }
920 memcpy(net, buff + i * sizeof(mbtk_net_info_t), sizeof(mbtk_net_info_t));
921 list_add(*net_list, net);
922
923 LOG("NET-%d: %d, %d, %d, %d", i + 1, net->net_sel_mode, net->net_type, net->net_state, net->plmn);
924 i++;
925 }
926
927 return 0;
928 } else {
929 list_free(*net_list);
930 return handle->info_err;
931 }
932}
933
934/*
935* Set network select mode. (+COPS=...)
936*/
937int mbtk_net_sel_mode_set(mbtk_info_handle_t* handle, const mbtk_net_info_t *net)
938{
939 if(handle == NULL || net == NULL)
940 {
941 LOGE("ARG error.");
942 return -1;
943 }
944 return info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, net, sizeof(mbtk_net_info_t), NULL) ? handle->info_err : 0;
945}
946
947/*
948* Get network select mode. (+COPS?)
949*/
950int mbtk_net_sel_mode_get(mbtk_info_handle_t* handle, mbtk_net_info_t *net)
951{
952 if(handle == NULL || net == NULL)
953 {
954 LOGE("ARG error.");
955 return -1;
956 }
957 if(info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, NULL, 0, net) > 0) {
958 LOG("NET : %d, %d, %d, %d", net->net_sel_mode, net->net_type, net->net_state, net->plmn);
959 return 0;
960 } else {
961 return handle->info_err;
962 }
963}
964
965/*
966* Get platform support bands.
967*/
968int mbtk_support_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
969{
970 uint8 type = 0; // Get support bands.
971 if(handle == NULL || band == NULL)
972 {
973 LOGE("ARG error.");
974 return -1;
975 }
976 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
977 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
978 return 0;
979 } else {
980 return handle->info_err;
981 }
982}
983
984/*
985* Get platform current bands.
986*/
987int mbtk_current_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
988{
989 uint8 type = 1; // Get current bands.
990 if(handle == NULL || band == NULL)
991 {
992 LOGE("ARG error.");
993 return -1;
994 }
995 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
996 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
997 return 0;
998 } else {
999 return handle->info_err;
1000 }
1001}
1002
1003/*
1004* Set platform current bands.
1005*/
1006int mbtk_current_band_set(mbtk_info_handle_t* handle, const mbtk_band_info_t *band)
1007{
1008 if(handle == NULL || band == NULL)
1009 {
1010 LOGE("ARG error.");
1011 return -1;
1012 }
1013 return info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, band, sizeof(mbtk_band_info_t), NULL) ? handle->info_err : 0;
1014}
1015
1016/*
1017* Get current cell infomation.
1018*/
1019int mbtk_cell_get(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list)
1020{
1021 if(handle == NULL)
1022 {
1023 LOGE("ARG error.");
1024 return -1;
1025 }
1026 *cell_list = list_create(NULL);
1027 if(*cell_list == NULL)
1028 {
1029 LOG("list_create() fail.");
1030 return MBTK_INFO_ERR_MEMORY;
1031 }
1032
1033 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1034 int buff_len;
1035 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, NULL, 0, buff)) > 0) {
1036 int i = 0;
1037 *type = buff[0]; // Set network type.
1038 while (i < (buff_len - sizeof(uint8)) / sizeof(mbtk_cell_info_t))
1039 {
1040 mbtk_cell_info_t* cell = (mbtk_cell_info_t*)malloc(sizeof(mbtk_cell_info_t));
1041 if(cell == NULL)
1042 {
1043 LOG("malloc() fail.");
1044 list_free(*cell_list);
1045 return MBTK_INFO_ERR_MEMORY;
1046 }
1047 memcpy(cell, buff + sizeof(uint8) + i * sizeof(mbtk_cell_info_t), sizeof(mbtk_cell_info_t));
1048 list_add(*cell_list, cell);
1049
1050 // LOG("Cell-%d: %d, %d, %d, %d, %d", i + 1, cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1051 i++;
1052 }
1053
1054 return 0;
1055 } else {
1056 list_free(*cell_list);
1057 return handle->info_err;
1058 }
1059}
1060/*
1061* Set cell info.
1062*
1063* at*CELL=<mode>,<act>,< band>,<freq>,<cellId>
1064* at*cell=2,3,,40936,429 //
1065* at*cell=0 //
1066*
1067* Restarting takes effect after execution.
1068*/
1069int mbtk_cell_set(mbtk_info_handle_t* handle, char * info, char* response)
1070{
1071 printf("mbtk_cell_set() info:%s, len:%d",info, strlen(info));
1072 char req[128] = {0};
1073 if( info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, info, strlen(info), req) > 0){
1074 memcpy(response, req, strlen(req));
1075 return 0;
1076 }
1077 else{
1078 return 0;
1079 // return handle->info_err;
1080 }
1081}
1082
1083/*
1084* Get all APN informations.
1085*/
1086int mbtk_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_apn_info_t apns[])
1087{
1088 int len;
1089 if(handle == NULL || apn_num == NULL || apns == NULL)
1090 {
1091 LOGE("ARG error.");
1092 return -1;
1093 }
1094 uint8 data[SOCK_MSG_LEN_MAX];
1095 if((len = info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, NULL, 0, data)) > 0) {
1096 /*
1097 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
1098 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1099 */
1100 uint8* ptr = data;
1101 if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
1102 *apn_num = 0;
1103 LOGE("APN array size to not enough.");
1104 return -1;
1105 }
1106 *apn_num = *ptr++;
1107 LOG("APN Number : %d", *apn_num);
1108 int i = 0;
1109 while(i < *apn_num) {
1110 memset(&(apns[i]), 0 ,sizeof(mbtk_apn_info_t));
1111 apns[i].cid = *ptr++;
1112 apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
1113
1114 // apn
1115 len = byte_2_uint16(ptr, false);
1116 ptr += sizeof(uint16);
1117 if(len > 0) { // Has APN
1118 memcpy(apns[i].apn, ptr, len);
1119 ptr += len;
1120 }
1121 // user
1122 len = byte_2_uint16(ptr, false);
1123 ptr += sizeof(uint16);
1124 if(len > 0) { // Has APN
1125 memcpy(apns[i].user, ptr, len);
1126 ptr += len;
1127 }
1128
1129 // pass
1130 len = byte_2_uint16(ptr, false);
1131 ptr += sizeof(uint16);
1132 if(len > 0) { // Has APN
1133 memcpy(apns[i].pass, ptr, len);
1134 ptr += len;
1135 }
1136 // auth
1137 len = byte_2_uint16(ptr, false);
1138 ptr += sizeof(uint16);
1139 if(len > 0) { // Has APN
1140 memcpy(apns[i].auth, ptr, len);
1141 ptr += len;
1142 }
1143
1144 i++;
1145 }
1146 return 0;
1147 } else {
1148 return handle->info_err;
1149 }
1150}
1151
1152/*
1153* Set current APN informations.
1154*/
1155int mbtk_apn_set(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name,
1156 const void *user_name, const void *user_pass, const void *auth)
1157{
1158 if(handle == NULL)
1159 {
1160 LOGE("ARG error.");
1161 return -1;
1162 }
1163 uint8 data[SOCK_MSG_LEN_MAX];
1164 memset(data, 0, SOCK_MSG_LEN_MAX);
1165 // cid : 2 - 7
1166 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1167 LOGE("CID error.");
1168 return -1;
1169 }
1170 uint8* ptr = data;
1171 // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1172 *ptr++ = (uint8)cid;
1173 *ptr++ = (uint8)ip_type;
1174 if(str_empty(apn_name)) {
1175 uint16_2_byte((uint16)0, ptr, false);
1176 ptr += sizeof(uint16);
1177 } else {
1178 uint16_2_byte((uint16)strlen(apn_name), ptr, false);
1179 ptr += sizeof(uint16);
1180 memcpy(ptr, apn_name, strlen(apn_name));
1181 ptr += strlen(apn_name);
1182 }
1183 if(str_empty(user_name)) {
1184 uint16_2_byte((uint16)0, ptr, false);
1185 ptr += sizeof(uint16);
1186 } else {
1187 uint16_2_byte((uint16)strlen(user_name), ptr, false);
1188 ptr += sizeof(uint16);
1189 memcpy(ptr, user_name, strlen(user_name));
1190 ptr += strlen(user_name);
1191 }
1192
1193 if(str_empty(user_pass)) {
1194 uint16_2_byte((uint16)0, ptr, false);
1195 ptr += sizeof(uint16);
1196 } else {
1197 uint16_2_byte((uint16)strlen(user_pass), ptr, false);
1198 ptr += sizeof(uint16);
1199 memcpy(ptr, user_pass, strlen(user_pass));
1200 ptr += strlen(user_pass);
1201 }
1202
1203 if(str_empty(auth)) {
1204 uint16_2_byte((uint16)0, ptr, false);
1205 ptr += sizeof(uint16);
1206 } else {
1207 uint16_2_byte((uint16)strlen(auth), ptr, false);
1208 ptr += sizeof(uint16);
1209 memcpy(ptr, auth, strlen(auth));
1210 ptr += strlen(auth);
1211 }
1212
1213 return info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, data, ptr - data, NULL) ? handle->info_err : 0;
1214}
1215
liuyang0e49d9a2024-04-23 21:04:54 +08001216int mbtk_apn_del(mbtk_info_handle_t* handle, unsigned char profile_idx)
1217{
1218 char profile[2];
1219 memset(profile, 0, 2);
1220 sprintf(profile, "%s", profile_idx);
1221 if(handle == NULL)
1222 {
1223 LOGE("ARG error.");
1224 return -1;
1225 }
1226
1227 if(info_item_process(handle, MBTK_INFO_ID_NET_APN_DEL_REQ, profile, strlen(profile), NULL) >= 0)
1228 {
1229 LOG("profile_idx Number : %s", profile);
1230 return 0;
1231 }
1232 else
1233 {
1234 return handle->info_err;
1235 }
1236
1237}
1238
liubin281ac462023-07-19 14:22:54 +08001239/*
1240* Start data call.
1241*/
1242int mbtk_data_call_start(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout)
1243{
1244 uint8 data[10];
1245 if(handle == NULL)
1246 {
1247 LOGE("ARG error.");
1248 return -1;
1249 }
1250 memset(data, 0, 10);
1251 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1252 LOGE("CID error.");
1253 return -1;
1254 }
1255 uint8* ptr = data;
1256 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
1257 call_type : mbtk_data_call_type_enum
1258 cid : 2 - 7
1259 timeout : second
1260 */
1261 *ptr++ = (uint8)MBTK_DATA_CALL_START;
1262 *ptr++ = (uint8)cid;
1263 *ptr++ = (uint8)(auto_conn_interval > 0 ? auto_conn_interval : 0); // 拨号失败后重拨间隔(s)
1264 *ptr++ = (uint8)(boot_conn ? 1 : 0); // 开机自动拨号
1265 if(timeout <= 0) {
1266 *ptr++ = (uint8)MBTK_DATA_CALL_TIMEOUT_DEFAULT;
1267 } else {
1268 *ptr++ = (uint8)timeout;
1269 }
1270
1271 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 5, NULL) ? handle->info_err : 0;
1272}
1273
1274/*
1275* Stop data call.
1276*/
1277int mbtk_data_call_stop(mbtk_info_handle_t* handle, int cid, int timeout)
1278{
1279 uint8 data[10];
1280 if(handle == NULL)
1281 {
1282 LOGE("ARG error.");
1283 return -1;
1284 }
1285 memset(data, 0, 10);
1286 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1287 LOGE("CID error.");
1288 return -1;
1289 }
1290 uint8* ptr = data;
1291 /* <call_type[1]><cid[1]><timeout[1]>
1292 call_type : mbtk_data_call_type_enum
1293 cid : 2 - 7
1294 timeout : second
1295 */
1296 *ptr++ = (uint8)MBTK_DATA_CALL_STOP;
1297 *ptr++ = (uint8)cid;
1298 *ptr++ = (uint8)timeout;
1299
1300 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, NULL) ? handle->info_err : 0;
1301}
1302
1303/*
1304* Get data call state.
1305*/
1306int mbtk_data_call_state_get(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
1307{
1308 uint8 data[10];
1309 if(handle == NULL)
1310 {
1311 LOGE("ARG error.");
1312 return -1;
1313 }
1314 uint8 recv_buff[SOCK_MSG_LEN_MAX]={0};
1315 memset(data, 0, 10);
1316 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1317 LOGE("CID error.");
1318 return -1;
1319 }
1320 uint8* ptr = data;
1321 /* <call_type[1]><cid[1]><timeout[1]>
1322 call_type : mbtk_data_call_type_enum
1323 cid : 2 - 7
1324 timeout : second
1325 */
1326 *ptr++ = (uint8)MBTK_DATA_CALL_STATE;
1327 *ptr++ = (uint8)cid;
1328 *ptr++ = (uint8)0;
1329
1330 if(ipv4) {
1331 memset(ipv4, 0, sizeof(mbtk_ipv4_info_t));
1332 }
1333
1334 if(ipv6) {
1335 memset(ipv6, 0, sizeof(mbtk_ipv6_info_t));
1336 }
1337
1338 if(info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, recv_buff) > 0) {
1339 if(recv_buff[0] == 0) { // IPv4 Only.
1340 if(ipv4) {
1341 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1342 }
1343 } else if(recv_buff[0] == 1) { // IPv6 Only.
1344 if(ipv6) {
1345 memcpy(ipv6, recv_buff + sizeof(uint8), sizeof(mbtk_ipv6_info_t));
1346 }
1347 } else if(recv_buff[0] == 2) { // IPv4 and IPv6.
1348 if(ipv4) {
1349 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1350 }
1351
1352 if(ipv6) {
1353 memcpy(ipv6, recv_buff + sizeof(uint8) + sizeof(mbtk_ipv4_info_t), sizeof(mbtk_ipv6_info_t));
1354 }
1355 } else {
1356 LOGE("Unknown IP type : %d", recv_buff[0]);
1357 return -1;
1358 }
1359 return 0;
1360 } else {
1361 return handle->info_err;
1362 }
1363}
1364
1365
1366
1367/*
1368* Get current network signal.
1369*/
1370int mbtk_net_signal_get(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal)
1371{
1372 if(handle == NULL || signal == NULL)
1373 {
1374 LOGE("ARG error.");
1375 return -1;
1376 }
1377 if(info_item_process(handle, MBTK_INFO_ID_NET_SIGNAL_REQ, NULL, 0, signal) > 0) {
1378 LOG("Signal : %d, %d, %d, %d, %d, %d, %d", signal->rssi, signal->rxlev, signal->ber, signal->rscp, signal->ecno,
1379 signal->rsrq, signal->rsrp);
1380 return 0;
1381 } else {
1382 return handle->info_err;
1383 }
1384}
1385
1386/*
1387* Get current network register information.
1388*/
1389int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg)
1390{
1391 if(handle == NULL || reg == NULL)
1392 {
1393 LOGE("ARG error.");
1394 return -1;
1395 }
1396 if(info_item_process(handle, MBTK_INFO_ID_NET_REG_REQ, NULL, 0, reg) > 0) {
1397 if(reg->call_state || reg->data_state || reg->ims_state) {
1398 LOGD("REG : call_state=%d, data_state=%d, ims_state=%d, net_type=%d, %04x, %08x", reg->call_state, reg->data_state, reg->ims_state, reg->type, reg->lac, reg->ci);
1399 } else {
1400 LOGE("Net not reg.");
1401 }
1402 return 0;
1403 } else {
1404 return handle->info_err;
1405 }
1406}
1407
r.xiao06db9a12024-04-14 18:51:15 -07001408/*
1409* Get current network IMS information.
1410*/
1411int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* reg)
1412{
1413 uint8 state;
1414 if(handle == NULL)
1415 {
1416 LOGE("ARG error.");
1417 return -1;
1418 }
1419 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, NULL, 0, &state) > 0) {
1420 LOG("reg type : %d", state);
1421 *reg = state;
1422 return 0;
1423 } else {
1424 return handle->info_err;
1425 }
1426
1427}
1428
1429/*
1430* Set current network IMS information.
1431*/
1432int mbtk_net_ims_set(mbtk_info_handle_t* handle, int reg)
1433{
1434 if(handle == NULL)
1435 {
1436 LOGE("ARG error.");
1437 return -1;
1438 }
1439
1440 return info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, (uint8*)&reg, sizeof(uint8), NULL) ? handle->info_err : 0;
1441
1442}
1443
liubin281ac462023-07-19 14:22:54 +08001444
1445/*
1446* Get radio state.
1447*/
1448int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state)
1449{
1450 uint8 state;
1451 if(handle == NULL || radio_state == NULL)
1452 {
1453 LOGE("ARG error.");
1454 return -1;
1455 }
1456 if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) {
1457 LOG("Radio state : %d", state);
1458 *radio_state = state;
1459 return 0;
1460 } else {
1461 return handle->info_err;
1462 }
1463}
1464
1465/*
1466* Set radio state.
1467*/
1468int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state)
1469{
1470 if(handle == NULL)
1471 {
1472 LOGE("ARG error.");
1473 return -1;
1474 }
1475 return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0;
1476}
1477
1478/*
1479* Get time type.
1480*/
1481int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type)
1482{
1483 uint8 state;
1484 if(handle == NULL || time_type == NULL)
1485 {
1486 LOGE("ARG error.");
1487 return -1;
1488 }
1489 if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) {
1490 LOG("Time type : %d", state);
1491 *time_type = state;
1492 return 0;
1493 } else {
1494 return handle->info_err;
1495 }
1496}
1497
1498/*
1499*Get Absolute time
1500*"23/05/24 06:09:32 +32 00"
1501*/
1502int mbtk_get_abs_time(char *time_str, time_t *time_out)
1503{
1504 struct tm tm_;
1505
1506 char *ptr = strstr(time_str + 10, " ");
1507 *ptr = '\0';
1508
1509 LOGD("time : \"%s\"", time_str);
1510#if 1
1511 if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) {
1512 LOGE("strptime() fail.");
1513 return -1;
1514 }
1515#else
1516 int year, month, day, hour, minute,second,time_zone;
1517 if(strstr(time_str, "+")) {
1518 sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1519 } else if(strstr(time_str, "-")) {
1520 sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1521 } else {
1522 LOGE("Time format error:%s", time_str);
1523 return -1;
1524 }
1525
1526 // 1970+
1527 if(year < 70) { // 20xx
1528 tm_.tm_year = 2000 + year;
1529 } else { // 19xx
1530 tm_.tm_year = 1900 + year;
1531 }
1532 tm_.tm_mon = month - 1;
1533 tm_.tm_mday = day;
1534 tm_.tm_hour = hour;
1535 tm_.tm_min = minute;
1536 tm_.tm_sec = second;
1537 tm_.tm_isdst = 0;
1538#endif
1539
1540 time_t timeStamp = mktime(&tm_);
1541 LOGD("tm_.tm_year = %d,tm_.tm_mon = %d,tm_.tm_mday = %d,tm_.tm_hour = %d,tm_.tm_min = %d,tm_.tm_sec = %d,tm_.tm_isdst = %d",tm_.tm_year,tm_.tm_mon,tm_.tm_mday,tm_.tm_hour,tm_.tm_min,tm_.tm_sec,tm_.tm_isdst);
1542 LOGD("time = %ld,%x", timeStamp,timeStamp);
1543 *time_out = timeStamp;
1544
1545 return 0;
1546}
1547
1548/*
1549* Get time type.
1550* "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00"
1551*/
1552int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
1553{
1554 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1555 if(handle == NULL || time_str == NULL)
1556 {
1557 LOGE("ARG error.");
1558 return -1;
1559 }
1560 //printf("mbtk_net_time_get begin info_item_process\n");
1561 if(info_item_process(handle, MBTK_INFO_ID_NET_TIME_REQ, NULL, 0, buff) > 0) {
1562 memcpy(time_str,buff,strlen(buff));
1563
1564 uint8 *temp = strstr(time_str, ",");
1565 if(temp) {
1566 *temp = ' '; // ',' -> ' '
1567
1568 temp = strstr(time_str, "+");
1569 if(temp == NULL) {
1570 temp = strstr(time_str, "-");
1571 }
1572
1573 if(temp) {
1574 // Copy +XX or -XX
1575 uint8 *last_ptr = temp + strlen(temp) + 1;
1576 while(last_ptr > temp) {
1577 *last_ptr = *(last_ptr - 1);
1578 last_ptr--;
1579 }
1580
1581 *last_ptr = ' ';
1582
1583 memcpy(temp + strlen(temp), "00", 2);
1584
1585 LOGD("%s -> %s", buff, time_str);
1586 return 0;
1587 } else {
1588 LOGE("Time error:%s",buff);
1589 return MBTK_INFO_ERR_TIME_FORMAT;
1590 }
1591 } else {
1592 LOGE("Time error:%s",buff);
1593 return MBTK_INFO_ERR_TIME_FORMAT;
1594 }
1595 } else {
1596 return handle->info_err;
1597 }
1598}
1599
1600/*
1601* Set time.
1602*
1603* time_type:
1604* 0: Cell time
1605* 1: NTP time
1606* 2: User time
1607* time_str: "YYYY-MM-DD HH:MM:SS"
1608*/
1609int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str)
1610{
1611 if(handle == NULL)
1612 {
1613 LOGE("ARG error.");
1614 return -1;
1615 }
1616 uint8 buffer[100] = {0};
1617 buffer[0] = (uint8)time_type;
1618 if(time_type == MBTK_TIME_TYPE_USER) {
1619 if(!str_empty(time_str)) {
1620 memcpy(buffer + sizeof(uint8), time_str, strlen(time_str));
1621 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1622 buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0;
1623 } else {
1624 return -1;
1625 }
1626 } else {
1627 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1628 buffer, sizeof(uint8), NULL) ? handle->info_err : 0;
1629 }
1630}
1631
1632/*
1633* Return sms cmgf.
1634*/
1635int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state)
1636{
1637 uint8 state;
1638 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) {
1639 LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state);
1640 *volte_state = state;
1641 return 0;
1642 } else {
1643 return handle->info_err;
1644 }
1645}
1646
1647/*
1648* Set sms cmgf.
1649*
1650* volte_state:
1651* 0 : PDU mode.
1652* 1 : text mode.
1653*
1654* Restarting takes effect after execution.
1655*/
1656int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode)
1657{
1658 printf("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8));
1659 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0;
1660}
1661
1662/*
1663* Set sms cmgs.
1664*
1665if PDU mode (+CMGF=0):
1666+CMGS=<length><CR>
1667PDU is given<ctrl-Z/ESC>
1668
1669if text mode (+CMGF=1):
1670+CMGS=<da>[,<toda>]<CR>
1671text is entered<ctrl-Z/ESC>
1672
1673* Restarting takes effect after execution.
1674*/
1675int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp)
1676{
1677 printf("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs));
1678// char req[20] = {0}
1679 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){
1680 printf("resp:%s\n", resp);
1681 return 0;
1682 }else{
1683 return handle->info_err;
1684 }
1685}
1686
1687/*
1688* Set sms cmgw.
1689*
1690if text mode (+CMGF=1):
1691+CMGW=<oa/da>[,<tooa/toda>[,<stat>]]
1692<CR>
1693text is entered<ctrl-Z/ESC>
1694if PDU mode (+CMGF=0):
1695+CMGW=<length>[,<stat>]<CR>PDU is
1696given<ctrl-Z/ESC>
1697
1698*/
1699
1700int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp)
1701{
1702 printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw));
1703 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){
1704 printf("resp:%s\n", resp);
1705 return 0;
1706 }else{
1707 return handle->info_err;
1708 }
1709}
1710
1711/*
1712* Set sms cmgd.
1713*
1714* +CMGD=<index>[,<delflag>]
1715*
1716* Restarting takes effect after execution.
1717*/
1718int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg)
1719{
1720 printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg));
1721 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0;
1722}
1723
1724/*
r.xiaoeb9dba42024-02-07 02:16:13 -08001725* Get sms cmgd.
1726*
1727* +CMGD: (XXX,XXX)(0-4)
1728*
1729* Restarting takes effect after execution.
1730*/
1731int mbtk_sms_cmgd_get(mbtk_info_handle_t* handle, char * cmdg)
1732{
1733 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, NULL, 0, cmdg) ? handle->info_err : 0;
1734}
1735
1736
1737/*
liubin281ac462023-07-19 14:22:54 +08001738* Set sms cmgl.
1739*
1740* AT+CMGL[=<stat>]
1741*
1742* Restarting takes effect after execution.
1743*/
1744int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp)
1745{
1746 printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl));
1747 char reg[5*1024] ={0};
1748 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){
1749 printf("len:%d , reg:%s\n", strlen(reg), reg);
1750 // memcpy(resp, reg, strlen(reg));
1751 return 0;
1752 }else {
1753 return handle->info_err;
1754 }
1755}
1756
1757/*
1758* Return sms csca.
1759*/
1760int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf)
1761{
1762 // char state;
1763 if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) {
1764 LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf);
1765 // *volte_state = state;
1766 return 0;
1767 } else {
1768 return handle->info_err;
1769 }
1770}
1771
1772/*
1773* Set sms csca.
1774*
1775* AT+CSCA=<number> [,<type>]
1776*
1777* Restarting takes effect after execution.
1778*/
1779int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca)
1780{
1781 printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca));
1782 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0;
1783}
1784
1785/*
1786* Set sms csmp.
1787*
1788* AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1789*
1790* Restarting takes effect after execution.
1791*/
1792int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp)
1793{
1794 printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp));
1795 return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0;
1796}
1797
1798/*
1799* Set sms cscb.
1800*
1801* AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1802*
1803* Restarting takes effect after execution.
1804*/
1805int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb)
1806{
1807 printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb));
1808 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0;
1809}
1810
1811/*
1812* Set sms cnmi.
1813*
1814at+cnmi=1,2
1815
1816OK
1817if sending fails:
1818+CMS ERROR: <err>
1819*/
1820int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle)
1821{
1822 printf("mbtk_sms_cnmi_set()------------start\n");
1823
1824 return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0;
1825}
1826
1827/*
1828* Set sms cmss.
1829*
1830+CMSS=<index>[,<da>[,<toda>]]
1831
1832if sending successful:
1833+CMSS: <mr>
1834OK
1835if sending fails:
1836+CMS ERROR: <err>
1837*/
1838int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp)
1839{
1840 printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss));
1841 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){
1842 printf("resp:%s\n", resp);
1843 return 0;
1844 }else{
1845 return handle->info_err;
1846 }
1847}
1848
1849/*
1850* Return sms cmgf.
1851*/
1852int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem)
1853{
1854 char req[128] = {0};
1855 if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) {
1856 LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req));
1857 memcpy(mem, req, strlen(req));
1858 return 0;
1859 } else {
1860 return handle->info_err;
1861 }
1862}
1863
1864
1865/*
1866* Set sms cpms.
1867*
1868* AT+CPMS=<mem1>[,<mem2>[,<mem3>]]
1869*
1870* Restarting takes effect after execution.
1871*/
1872int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response)
1873{
1874 printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem));
1875 char req[128] = {0};
1876 if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){
1877 memcpy(response, req, strlen(req));
1878 return 0;
1879 }
1880 else{
1881 return handle->info_err;
1882 }
1883}
1884
1885/*
1886* Set sms cm.
1887*
1888* +CMGR=<index>
1889
1890if PDU mode (+CMGF=0) ��command successful:
1891+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
1892OK
1893if text mode (+CMGF=1), command successful and SMS-DELIVER:
1894+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs
1895>, <sca>,<tosca>,<length>]<CR><LF><data>
1896OK
1897if text mode (+CMGF=1), command successful and SMS-SUBMIT:
1898+CMGR:
1899<stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>],
1900<sca>,<tosca>,<length>]<CR><LF><data>
1901OK
1902otherwise:
1903+CMS ERROR: <err>
1904*
1905* Restarting takes effect after execution.
1906*/
1907int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp)
1908{
1909 printf("mbtk_sms_cmgr_set() --------------index:%d",index);
1910 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){
1911 printf("resp:%s\n", resp);
1912 return 0;
1913 }else{
1914 return handle->info_err;
1915 }
1916}
1917
1918
1919/*
1920* Get sim state.
1921*/
1922int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state)
1923{
1924 uint8 state;
1925 if(handle == NULL || sim_state == NULL)
1926 {
1927 LOGE("ARG error.");
1928 return -1;
1929 }
1930 if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) {
1931 *sim_state = (mbtk_sim_state_enum)state;
1932 LOG("Sim state : %d", *sim_state);
1933 return 0;
1934 } else {
1935 return handle->info_err;
1936 }
1937}
1938
1939/*
1940* Get sim card type.
1941*/
1942int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type)
1943{
1944 uint8 state;
1945 if(handle == NULL || sim_card_type == NULL)
1946 {
1947 LOGE("ARG error.");
1948 return -1;
1949 }
1950 if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) {
1951 *sim_card_type = (mbtk_sim_card_type_enum)state;
1952 LOG("Sim sim_card_type : %d", *sim_card_type);
1953 return 0;
1954 } else {
1955 return handle->info_err;
1956 }
1957}
1958
1959/*
1960* Get system temperature.
1961*
1962* type[IN]:
1963* 0: Soc temperature.
1964* 1: RF temperature.
1965* temp[OUT]:
1966* temperature in celsius.
1967*/
1968int mbtk_temp_get(mbtk_info_handle_t* handle, int type, int* temp)
1969{
1970 if(handle == NULL)
1971 {
1972 LOGE("ARG error.");
1973 return -1;
1974 }
1975 if(type != 0 && type != 1 || temp == NULL)
1976 {
1977 return -1;
1978 }
1979
1980 uint8 temp_type = (uint8)type;
1981 uint8 temp_ptr;
1982 if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), &temp_ptr) > 0) {
1983 *temp = temp_ptr;
1984 LOG("Temperature : %d", *temp);
1985 return 0;
1986 } else {
1987 return handle->info_err;
1988 }
1989
1990 return 0;
1991}
1992
1993
1994/*
1995* Set sim power state.
1996* power:
1997* 0: Sim power off.
1998* 1: Sim power on.
1999*/
2000int mbtk_sim_power_set(int power)
2001{
2002 if(power != 0 && power != 1)
2003 {
2004 return -1;
2005 }
2006
2007 // /sys/devices/virtual/usim_event/usim0/send_event
2008 char cmd[100] = {0};
2009 sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
2010 system(cmd);
2011
2012 return 0;
2013}
2014
2015/*
2016* System power.
2017* type:
2018* 0: Reboot system.
2019* 1: Poweroff system.
2020* 2: Halt system.
2021*/
2022int mbtk_system_reboot(int type)
2023{
2024 if(type != 0 && type != 1 && type != 2)
2025 {
2026 return -1;
2027 }
2028
2029 switch(type) {
2030 case 0: {
2031 system("reboot");
2032 break;
2033 }
2034 case 1: {
2035 system("poweroff");
2036 break;
2037 }
2038 case 2: {
2039 system("halt");
2040 break;
2041 }
2042 default: {
2043 break;
2044 }
2045 }
2046
2047 return 0;
2048}
2049
2050/*
2051* set modem fun
2052*
2053*/
2054int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info)
2055{
2056 if(handle == NULL)
2057 {
2058 LOGE("ARG error.");
2059 return -1;
2060 }
2061 return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0;
2062}
2063
2064/*
2065* get modem fun
2066*
2067*/
2068int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun)
2069{
2070 uint8 state;
2071 if(handle == NULL || fun == NULL)
2072 {
2073 LOGE("ARG error.");
2074 return -1;
2075 }
2076 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) {
2077 LOG("modem type : %d", state);
2078 *fun = state;
2079 return 0;
2080 } else {
2081 return handle->info_err;
2082 }
2083}
2084
2085/*
2086* call_start
2087*
2088*/
2089int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number)
2090{
2091 if(handle == NULL)
2092 {
2093 LOGE("ARG error.");
2094 return -1;
2095 }
2096 if(str_empty(phone_number))
2097 return -1;
2098
2099 return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ,
2100 phone_number, strlen(phone_number), NULL) ? handle->info_err : 0;
2101}
2102/*
2103* Answer the phone call.
2104*
2105*/
2106int mbtk_call_answer(mbtk_info_handle_t* handle)
2107{
2108 return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2109}
2110
2111/*
2112* Hang up all call.
2113*
2114*/
2115int mbtk_call_hang(mbtk_info_handle_t* handle)
2116{
2117 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2118}
2119
2120/*
2121* Hang up a call.
2122*
2123*/
2124int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id)
2125{
2126 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0;
2127}
2128
2129/*
2130* Hang up waiting or background call.
2131*
2132*/
2133int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle)
2134{
2135 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2136}
2137
2138/*
2139* Hang up foreground resume background call.
2140*
2141*/
2142int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle)
2143{
2144 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2145}
2146
2147/*
2148* Get current call phone number.
2149*/
2150int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg)
2151{
2152 if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) {
2153 LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
2154 return 0;
2155 } else {
2156 return handle->info_err;
2157 }
2158}
2159
2160/*
2161* Return mute state.
2162*/
2163int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state)
2164{
2165 uint8 state;
2166 if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) {
2167 LOG("Mute State : %d", state);
2168 *mute_state = state;
2169 return 0;
2170 } else {
2171 return handle->info_err;
2172 }
2173}
2174
2175/*
2176* Set mute state.
2177*
2178* mute_state:
2179* 0 : of mute.
2180* 1 : on mute.
2181*
2182* Restarting takes effect after execution.
2183*/
2184int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state)
2185{
2186 return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0;
2187}
2188
2189/*
r.xiaoec113d12024-01-12 02:13:28 -08002190* Set wakeup state.
2191*
2192* wakeup_state:(0~31)
2193* 0 : means resume all
2194* 1~31 means suspend
2195* Control the active reporting of some platform modems to reduce wakeup
2196*/
2197
2198int mbtk_wakeup_state_set(mbtk_info_handle_t* handle, uint32 wakeup_state)
2199{
2200 return info_item_process(handle, MBTK_INFO_ID_WAKEUP_STA_REQ, (uint32*)&wakeup_state, sizeof(uint32), NULL) ? handle->info_err : 0;
2201}
2202
2203/*
2204* oos get.
2205*/
2206int mbtk_oos_get(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
2207{
2208 if(info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, NULL, 0, oos_info) > 0) {
2209 return 0;
2210 } else {
2211 return handle->info_err;
2212 }
2213}
2214
2215/*
2216* oos set .
2217*/
r.xiaocfd7c682024-01-22 03:59:46 -08002218int mbtk_oos_set(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
r.xiaoec113d12024-01-12 02:13:28 -08002219{
2220 if(handle == NULL)
2221 {
2222 LOGE("ARG error.");
2223 return -1;
2224 }
r.xiaoec113d12024-01-12 02:13:28 -08002225
r.xiaocfd7c682024-01-22 03:59:46 -08002226 return info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, oos_info, sizeof(mbtk_oos_info), NULL) ? handle->info_err : 0;
r.xiaoec113d12024-01-12 02:13:28 -08002227}
2228
2229
2230/*
liubin281ac462023-07-19 14:22:54 +08002231* Set DTMF character.
2232*
2233*/
2234int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character)
2235{
2236 if(handle == NULL)
2237 {
2238 LOGE("ARG error.");
2239 return -1;
2240 }
2241 return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ,
2242 dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0;
2243}
2244
2245/*
wangyouqiang38e53362024-01-23 10:53:48 +08002246* Set net led.
2247*
2248*/
2249int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status)
2250{
2251 if(handle == NULL)
2252 {
2253 LOGE("ARG error.");
2254 return -1;
2255 }
2256
2257 char buff[3] = {0};
2258 if(type == MBTK_LED_TYPE_NET)
2259 {
2260 buff[0] = 0;
2261 }
2262 else
2263 {
2264 buff[0] = 1;
2265 }
2266
2267 if(status == MBTK_LED_STATUS_CLOSE)
2268 {
2269 buff[1] = 0;
2270 }
2271 else
2272 {
2273 buff[1] = 1;
2274 }
2275 return info_item_process(handle, MBTK_INFO_ID_LED_REQ, buff, 2, NULL) ? handle->info_err : 0;
2276}
2277
2278/*
liubin281ac462023-07-19 14:22:54 +08002279* Set pdp state change callback function.
2280*/
2281int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2282{
2283 if(handle == NULL)
2284 {
2285 LOGE("ARG error.");
2286 return -1;
2287 }
2288 if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) {
2289 return handle->info_err;
2290 } else {
2291 handle->pdp_state_cb = cb;
2292 return 0;
2293 }
2294}
2295
2296/*
2297* Set network state change callback function.
2298*/
2299int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2300{
2301 if(handle == NULL)
2302 {
2303 LOGE("ARG error.");
2304 return -1;
2305 }
b.liu27b91e42024-01-17 20:02:30 +08002306 if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) < 0) {
2307 return handle->info_err;
2308 } else {
liubin281ac462023-07-19 14:22:54 +08002309 handle->net_state_cb = cb;
2310 return 0;
liubin281ac462023-07-19 14:22:54 +08002311 }
2312}
2313
2314/*
2315* Set call state change callback function.
2316*/
2317int mbtk_call_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2318{
2319 if(handle == NULL)
2320 {
2321 LOGE("ARG error.");
2322 return -1;
2323 }
2324 if(info_item_process(handle, MBTK_INFO_ID_IND_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2325 return handle->info_err;
2326 } else {
2327 handle->call_state_cb = cb;
2328 return 0;
2329 }
2330}
2331
2332/*
2333* Set sms state change callback function.
2334*/
2335int mbtk_sms_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2336{
2337 if(handle == NULL)
2338 {
2339 LOGE("ARG error.");
2340 return -1;
2341 }
2342 if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) {
2343 return handle->info_err;
2344 } else {
2345 handle->sms_state_cb = cb;
2346 return 0;
2347 }
2348}
2349
2350/*
2351* Set radio state change callback function.
2352*/
2353int mbtk_radio_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2354{
2355 if(handle == NULL)
2356 {
2357 LOGE("ARG error.");
2358 return -1;
2359 }
2360 if(info_item_process(handle, MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) {
2361 return handle->info_err;
2362 } else {
2363 handle->radio_state_cb = cb;
2364 return 0;
2365 }
2366}
2367
2368/*
2369* Set sim state change callback function.
2370*/
2371int mbtk_sim_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2372{
2373 if(handle == NULL)
2374 {
2375 LOGE("ARG error.");
2376 return -1;
2377 }
2378 if(info_item_process(handle, MBTK_INFO_ID_IND_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) {
2379 return handle->info_err;
2380 } else {
2381 handle->sim_state_cb = cb;
2382 return 0;
2383 }
2384}