blob: d471c3b26303a2b53264008765e979357345cade [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
1216/*
1217* Start data call.
1218*/
1219int mbtk_data_call_start(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout)
1220{
1221 uint8 data[10];
1222 if(handle == NULL)
1223 {
1224 LOGE("ARG error.");
1225 return -1;
1226 }
1227 memset(data, 0, 10);
1228 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1229 LOGE("CID error.");
1230 return -1;
1231 }
1232 uint8* ptr = data;
1233 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
1234 call_type : mbtk_data_call_type_enum
1235 cid : 2 - 7
1236 timeout : second
1237 */
1238 *ptr++ = (uint8)MBTK_DATA_CALL_START;
1239 *ptr++ = (uint8)cid;
1240 *ptr++ = (uint8)(auto_conn_interval > 0 ? auto_conn_interval : 0); // 拨号失败后重拨间隔(s)
1241 *ptr++ = (uint8)(boot_conn ? 1 : 0); // 开机自动拨号
1242 if(timeout <= 0) {
1243 *ptr++ = (uint8)MBTK_DATA_CALL_TIMEOUT_DEFAULT;
1244 } else {
1245 *ptr++ = (uint8)timeout;
1246 }
1247
1248 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 5, NULL) ? handle->info_err : 0;
1249}
1250
1251/*
1252* Stop data call.
1253*/
1254int mbtk_data_call_stop(mbtk_info_handle_t* handle, int cid, int timeout)
1255{
1256 uint8 data[10];
1257 if(handle == NULL)
1258 {
1259 LOGE("ARG error.");
1260 return -1;
1261 }
1262 memset(data, 0, 10);
1263 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1264 LOGE("CID error.");
1265 return -1;
1266 }
1267 uint8* ptr = data;
1268 /* <call_type[1]><cid[1]><timeout[1]>
1269 call_type : mbtk_data_call_type_enum
1270 cid : 2 - 7
1271 timeout : second
1272 */
1273 *ptr++ = (uint8)MBTK_DATA_CALL_STOP;
1274 *ptr++ = (uint8)cid;
1275 *ptr++ = (uint8)timeout;
1276
1277 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, NULL) ? handle->info_err : 0;
1278}
1279
1280/*
1281* Get data call state.
1282*/
1283int mbtk_data_call_state_get(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
1284{
1285 uint8 data[10];
1286 if(handle == NULL)
1287 {
1288 LOGE("ARG error.");
1289 return -1;
1290 }
1291 uint8 recv_buff[SOCK_MSG_LEN_MAX]={0};
1292 memset(data, 0, 10);
1293 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1294 LOGE("CID error.");
1295 return -1;
1296 }
1297 uint8* ptr = data;
1298 /* <call_type[1]><cid[1]><timeout[1]>
1299 call_type : mbtk_data_call_type_enum
1300 cid : 2 - 7
1301 timeout : second
1302 */
1303 *ptr++ = (uint8)MBTK_DATA_CALL_STATE;
1304 *ptr++ = (uint8)cid;
1305 *ptr++ = (uint8)0;
1306
1307 if(ipv4) {
1308 memset(ipv4, 0, sizeof(mbtk_ipv4_info_t));
1309 }
1310
1311 if(ipv6) {
1312 memset(ipv6, 0, sizeof(mbtk_ipv6_info_t));
1313 }
1314
1315 if(info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, recv_buff) > 0) {
1316 if(recv_buff[0] == 0) { // IPv4 Only.
1317 if(ipv4) {
1318 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1319 }
1320 } else if(recv_buff[0] == 1) { // IPv6 Only.
1321 if(ipv6) {
1322 memcpy(ipv6, recv_buff + sizeof(uint8), sizeof(mbtk_ipv6_info_t));
1323 }
1324 } else if(recv_buff[0] == 2) { // IPv4 and IPv6.
1325 if(ipv4) {
1326 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1327 }
1328
1329 if(ipv6) {
1330 memcpy(ipv6, recv_buff + sizeof(uint8) + sizeof(mbtk_ipv4_info_t), sizeof(mbtk_ipv6_info_t));
1331 }
1332 } else {
1333 LOGE("Unknown IP type : %d", recv_buff[0]);
1334 return -1;
1335 }
1336 return 0;
1337 } else {
1338 return handle->info_err;
1339 }
1340}
1341
1342
1343
1344/*
1345* Get current network signal.
1346*/
1347int mbtk_net_signal_get(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal)
1348{
1349 if(handle == NULL || signal == NULL)
1350 {
1351 LOGE("ARG error.");
1352 return -1;
1353 }
1354 if(info_item_process(handle, MBTK_INFO_ID_NET_SIGNAL_REQ, NULL, 0, signal) > 0) {
1355 LOG("Signal : %d, %d, %d, %d, %d, %d, %d", signal->rssi, signal->rxlev, signal->ber, signal->rscp, signal->ecno,
1356 signal->rsrq, signal->rsrp);
1357 return 0;
1358 } else {
1359 return handle->info_err;
1360 }
1361}
1362
1363/*
1364* Get current network register information.
1365*/
1366int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg)
1367{
1368 if(handle == NULL || reg == NULL)
1369 {
1370 LOGE("ARG error.");
1371 return -1;
1372 }
1373 if(info_item_process(handle, MBTK_INFO_ID_NET_REG_REQ, NULL, 0, reg) > 0) {
1374 if(reg->call_state || reg->data_state || reg->ims_state) {
1375 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);
1376 } else {
1377 LOGE("Net not reg.");
1378 }
1379 return 0;
1380 } else {
1381 return handle->info_err;
1382 }
1383}
1384
r.xiao06db9a12024-04-14 18:51:15 -07001385/*
1386* Get current network IMS information.
1387*/
1388int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* reg)
1389{
1390 uint8 state;
1391 if(handle == NULL)
1392 {
1393 LOGE("ARG error.");
1394 return -1;
1395 }
1396 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, NULL, 0, &state) > 0) {
1397 LOG("reg type : %d", state);
1398 *reg = state;
1399 return 0;
1400 } else {
1401 return handle->info_err;
1402 }
1403
1404}
1405
1406/*
1407* Set current network IMS information.
1408*/
1409int mbtk_net_ims_set(mbtk_info_handle_t* handle, int reg)
1410{
1411 if(handle == NULL)
1412 {
1413 LOGE("ARG error.");
1414 return -1;
1415 }
1416
1417 return info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, (uint8*)&reg, sizeof(uint8), NULL) ? handle->info_err : 0;
1418
1419}
1420
liubin281ac462023-07-19 14:22:54 +08001421
1422/*
1423* Get radio state.
1424*/
1425int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state)
1426{
1427 uint8 state;
1428 if(handle == NULL || radio_state == NULL)
1429 {
1430 LOGE("ARG error.");
1431 return -1;
1432 }
1433 if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) {
1434 LOG("Radio state : %d", state);
1435 *radio_state = state;
1436 return 0;
1437 } else {
1438 return handle->info_err;
1439 }
1440}
1441
1442/*
1443* Set radio state.
1444*/
1445int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state)
1446{
1447 if(handle == NULL)
1448 {
1449 LOGE("ARG error.");
1450 return -1;
1451 }
1452 return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0;
1453}
1454
1455/*
1456* Get time type.
1457*/
1458int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type)
1459{
1460 uint8 state;
1461 if(handle == NULL || time_type == NULL)
1462 {
1463 LOGE("ARG error.");
1464 return -1;
1465 }
1466 if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) {
1467 LOG("Time type : %d", state);
1468 *time_type = state;
1469 return 0;
1470 } else {
1471 return handle->info_err;
1472 }
1473}
1474
1475/*
1476*Get Absolute time
1477*"23/05/24 06:09:32 +32 00"
1478*/
1479int mbtk_get_abs_time(char *time_str, time_t *time_out)
1480{
1481 struct tm tm_;
1482
1483 char *ptr = strstr(time_str + 10, " ");
1484 *ptr = '\0';
1485
1486 LOGD("time : \"%s\"", time_str);
1487#if 1
1488 if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) {
1489 LOGE("strptime() fail.");
1490 return -1;
1491 }
1492#else
1493 int year, month, day, hour, minute,second,time_zone;
1494 if(strstr(time_str, "+")) {
1495 sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1496 } else if(strstr(time_str, "-")) {
1497 sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1498 } else {
1499 LOGE("Time format error:%s", time_str);
1500 return -1;
1501 }
1502
1503 // 1970+
1504 if(year < 70) { // 20xx
1505 tm_.tm_year = 2000 + year;
1506 } else { // 19xx
1507 tm_.tm_year = 1900 + year;
1508 }
1509 tm_.tm_mon = month - 1;
1510 tm_.tm_mday = day;
1511 tm_.tm_hour = hour;
1512 tm_.tm_min = minute;
1513 tm_.tm_sec = second;
1514 tm_.tm_isdst = 0;
1515#endif
1516
1517 time_t timeStamp = mktime(&tm_);
1518 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);
1519 LOGD("time = %ld,%x", timeStamp,timeStamp);
1520 *time_out = timeStamp;
1521
1522 return 0;
1523}
1524
1525/*
1526* Get time type.
1527* "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00"
1528*/
1529int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
1530{
1531 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1532 if(handle == NULL || time_str == NULL)
1533 {
1534 LOGE("ARG error.");
1535 return -1;
1536 }
1537 //printf("mbtk_net_time_get begin info_item_process\n");
1538 if(info_item_process(handle, MBTK_INFO_ID_NET_TIME_REQ, NULL, 0, buff) > 0) {
1539 memcpy(time_str,buff,strlen(buff));
1540
1541 uint8 *temp = strstr(time_str, ",");
1542 if(temp) {
1543 *temp = ' '; // ',' -> ' '
1544
1545 temp = strstr(time_str, "+");
1546 if(temp == NULL) {
1547 temp = strstr(time_str, "-");
1548 }
1549
1550 if(temp) {
1551 // Copy +XX or -XX
1552 uint8 *last_ptr = temp + strlen(temp) + 1;
1553 while(last_ptr > temp) {
1554 *last_ptr = *(last_ptr - 1);
1555 last_ptr--;
1556 }
1557
1558 *last_ptr = ' ';
1559
1560 memcpy(temp + strlen(temp), "00", 2);
1561
1562 LOGD("%s -> %s", buff, time_str);
1563 return 0;
1564 } else {
1565 LOGE("Time error:%s",buff);
1566 return MBTK_INFO_ERR_TIME_FORMAT;
1567 }
1568 } else {
1569 LOGE("Time error:%s",buff);
1570 return MBTK_INFO_ERR_TIME_FORMAT;
1571 }
1572 } else {
1573 return handle->info_err;
1574 }
1575}
1576
1577/*
1578* Set time.
1579*
1580* time_type:
1581* 0: Cell time
1582* 1: NTP time
1583* 2: User time
1584* time_str: "YYYY-MM-DD HH:MM:SS"
1585*/
1586int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str)
1587{
1588 if(handle == NULL)
1589 {
1590 LOGE("ARG error.");
1591 return -1;
1592 }
1593 uint8 buffer[100] = {0};
1594 buffer[0] = (uint8)time_type;
1595 if(time_type == MBTK_TIME_TYPE_USER) {
1596 if(!str_empty(time_str)) {
1597 memcpy(buffer + sizeof(uint8), time_str, strlen(time_str));
1598 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1599 buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0;
1600 } else {
1601 return -1;
1602 }
1603 } else {
1604 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1605 buffer, sizeof(uint8), NULL) ? handle->info_err : 0;
1606 }
1607}
1608
1609/*
1610* Return sms cmgf.
1611*/
1612int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state)
1613{
1614 uint8 state;
1615 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) {
1616 LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state);
1617 *volte_state = state;
1618 return 0;
1619 } else {
1620 return handle->info_err;
1621 }
1622}
1623
1624/*
1625* Set sms cmgf.
1626*
1627* volte_state:
1628* 0 : PDU mode.
1629* 1 : text mode.
1630*
1631* Restarting takes effect after execution.
1632*/
1633int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode)
1634{
1635 printf("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8));
1636 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0;
1637}
1638
1639/*
1640* Set sms cmgs.
1641*
1642if PDU mode (+CMGF=0):
1643+CMGS=<length><CR>
1644PDU is given<ctrl-Z/ESC>
1645
1646if text mode (+CMGF=1):
1647+CMGS=<da>[,<toda>]<CR>
1648text is entered<ctrl-Z/ESC>
1649
1650* Restarting takes effect after execution.
1651*/
1652int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp)
1653{
1654 printf("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs));
1655// char req[20] = {0}
1656 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){
1657 printf("resp:%s\n", resp);
1658 return 0;
1659 }else{
1660 return handle->info_err;
1661 }
1662}
1663
1664/*
1665* Set sms cmgw.
1666*
1667if text mode (+CMGF=1):
1668+CMGW=<oa/da>[,<tooa/toda>[,<stat>]]
1669<CR>
1670text is entered<ctrl-Z/ESC>
1671if PDU mode (+CMGF=0):
1672+CMGW=<length>[,<stat>]<CR>PDU is
1673given<ctrl-Z/ESC>
1674
1675*/
1676
1677int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp)
1678{
1679 printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw));
1680 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){
1681 printf("resp:%s\n", resp);
1682 return 0;
1683 }else{
1684 return handle->info_err;
1685 }
1686}
1687
1688/*
1689* Set sms cmgd.
1690*
1691* +CMGD=<index>[,<delflag>]
1692*
1693* Restarting takes effect after execution.
1694*/
1695int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg)
1696{
1697 printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg));
1698 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0;
1699}
1700
1701/*
r.xiaoeb9dba42024-02-07 02:16:13 -08001702* Get sms cmgd.
1703*
1704* +CMGD: (XXX,XXX)(0-4)
1705*
1706* Restarting takes effect after execution.
1707*/
1708int mbtk_sms_cmgd_get(mbtk_info_handle_t* handle, char * cmdg)
1709{
1710 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, NULL, 0, cmdg) ? handle->info_err : 0;
1711}
1712
1713
1714/*
liubin281ac462023-07-19 14:22:54 +08001715* Set sms cmgl.
1716*
1717* AT+CMGL[=<stat>]
1718*
1719* Restarting takes effect after execution.
1720*/
1721int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp)
1722{
1723 printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl));
1724 char reg[5*1024] ={0};
1725 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){
1726 printf("len:%d , reg:%s\n", strlen(reg), reg);
1727 // memcpy(resp, reg, strlen(reg));
1728 return 0;
1729 }else {
1730 return handle->info_err;
1731 }
1732}
1733
1734/*
1735* Return sms csca.
1736*/
1737int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf)
1738{
1739 // char state;
1740 if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) {
1741 LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf);
1742 // *volte_state = state;
1743 return 0;
1744 } else {
1745 return handle->info_err;
1746 }
1747}
1748
1749/*
1750* Set sms csca.
1751*
1752* AT+CSCA=<number> [,<type>]
1753*
1754* Restarting takes effect after execution.
1755*/
1756int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca)
1757{
1758 printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca));
1759 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0;
1760}
1761
1762/*
1763* Set sms csmp.
1764*
1765* AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1766*
1767* Restarting takes effect after execution.
1768*/
1769int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp)
1770{
1771 printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp));
1772 return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0;
1773}
1774
1775/*
1776* Set sms cscb.
1777*
1778* AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1779*
1780* Restarting takes effect after execution.
1781*/
1782int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb)
1783{
1784 printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb));
1785 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0;
1786}
1787
1788/*
1789* Set sms cnmi.
1790*
1791at+cnmi=1,2
1792
1793OK
1794if sending fails:
1795+CMS ERROR: <err>
1796*/
1797int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle)
1798{
1799 printf("mbtk_sms_cnmi_set()------------start\n");
1800
1801 return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0;
1802}
1803
1804/*
1805* Set sms cmss.
1806*
1807+CMSS=<index>[,<da>[,<toda>]]
1808
1809if sending successful:
1810+CMSS: <mr>
1811OK
1812if sending fails:
1813+CMS ERROR: <err>
1814*/
1815int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp)
1816{
1817 printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss));
1818 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){
1819 printf("resp:%s\n", resp);
1820 return 0;
1821 }else{
1822 return handle->info_err;
1823 }
1824}
1825
1826/*
1827* Return sms cmgf.
1828*/
1829int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem)
1830{
1831 char req[128] = {0};
1832 if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) {
1833 LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req));
1834 memcpy(mem, req, strlen(req));
1835 return 0;
1836 } else {
1837 return handle->info_err;
1838 }
1839}
1840
1841
1842/*
1843* Set sms cpms.
1844*
1845* AT+CPMS=<mem1>[,<mem2>[,<mem3>]]
1846*
1847* Restarting takes effect after execution.
1848*/
1849int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response)
1850{
1851 printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem));
1852 char req[128] = {0};
1853 if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){
1854 memcpy(response, req, strlen(req));
1855 return 0;
1856 }
1857 else{
1858 return handle->info_err;
1859 }
1860}
1861
1862/*
1863* Set sms cm.
1864*
1865* +CMGR=<index>
1866
1867if PDU mode (+CMGF=0) ��command successful:
1868+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
1869OK
1870if text mode (+CMGF=1), command successful and SMS-DELIVER:
1871+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs
1872>, <sca>,<tosca>,<length>]<CR><LF><data>
1873OK
1874if text mode (+CMGF=1), command successful and SMS-SUBMIT:
1875+CMGR:
1876<stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>],
1877<sca>,<tosca>,<length>]<CR><LF><data>
1878OK
1879otherwise:
1880+CMS ERROR: <err>
1881*
1882* Restarting takes effect after execution.
1883*/
1884int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp)
1885{
1886 printf("mbtk_sms_cmgr_set() --------------index:%d",index);
1887 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){
1888 printf("resp:%s\n", resp);
1889 return 0;
1890 }else{
1891 return handle->info_err;
1892 }
1893}
1894
1895
1896/*
1897* Get sim state.
1898*/
1899int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state)
1900{
1901 uint8 state;
1902 if(handle == NULL || sim_state == NULL)
1903 {
1904 LOGE("ARG error.");
1905 return -1;
1906 }
1907 if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) {
1908 *sim_state = (mbtk_sim_state_enum)state;
1909 LOG("Sim state : %d", *sim_state);
1910 return 0;
1911 } else {
1912 return handle->info_err;
1913 }
1914}
1915
1916/*
1917* Get sim card type.
1918*/
1919int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type)
1920{
1921 uint8 state;
1922 if(handle == NULL || sim_card_type == NULL)
1923 {
1924 LOGE("ARG error.");
1925 return -1;
1926 }
1927 if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) {
1928 *sim_card_type = (mbtk_sim_card_type_enum)state;
1929 LOG("Sim sim_card_type : %d", *sim_card_type);
1930 return 0;
1931 } else {
1932 return handle->info_err;
1933 }
1934}
1935
1936/*
1937* Get system temperature.
1938*
1939* type[IN]:
1940* 0: Soc temperature.
1941* 1: RF temperature.
1942* temp[OUT]:
1943* temperature in celsius.
1944*/
1945int mbtk_temp_get(mbtk_info_handle_t* handle, int type, int* temp)
1946{
1947 if(handle == NULL)
1948 {
1949 LOGE("ARG error.");
1950 return -1;
1951 }
1952 if(type != 0 && type != 1 || temp == NULL)
1953 {
1954 return -1;
1955 }
1956
1957 uint8 temp_type = (uint8)type;
1958 uint8 temp_ptr;
1959 if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), &temp_ptr) > 0) {
1960 *temp = temp_ptr;
1961 LOG("Temperature : %d", *temp);
1962 return 0;
1963 } else {
1964 return handle->info_err;
1965 }
1966
1967 return 0;
1968}
1969
1970
1971/*
1972* Set sim power state.
1973* power:
1974* 0: Sim power off.
1975* 1: Sim power on.
1976*/
1977int mbtk_sim_power_set(int power)
1978{
1979 if(power != 0 && power != 1)
1980 {
1981 return -1;
1982 }
1983
1984 // /sys/devices/virtual/usim_event/usim0/send_event
1985 char cmd[100] = {0};
1986 sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
1987 system(cmd);
1988
1989 return 0;
1990}
1991
1992/*
1993* System power.
1994* type:
1995* 0: Reboot system.
1996* 1: Poweroff system.
1997* 2: Halt system.
1998*/
1999int mbtk_system_reboot(int type)
2000{
2001 if(type != 0 && type != 1 && type != 2)
2002 {
2003 return -1;
2004 }
2005
2006 switch(type) {
2007 case 0: {
2008 system("reboot");
2009 break;
2010 }
2011 case 1: {
2012 system("poweroff");
2013 break;
2014 }
2015 case 2: {
2016 system("halt");
2017 break;
2018 }
2019 default: {
2020 break;
2021 }
2022 }
2023
2024 return 0;
2025}
2026
2027/*
2028* set modem fun
2029*
2030*/
2031int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info)
2032{
2033 if(handle == NULL)
2034 {
2035 LOGE("ARG error.");
2036 return -1;
2037 }
2038 return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0;
2039}
2040
2041/*
2042* get modem fun
2043*
2044*/
2045int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun)
2046{
2047 uint8 state;
2048 if(handle == NULL || fun == NULL)
2049 {
2050 LOGE("ARG error.");
2051 return -1;
2052 }
2053 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) {
2054 LOG("modem type : %d", state);
2055 *fun = state;
2056 return 0;
2057 } else {
2058 return handle->info_err;
2059 }
2060}
2061
2062/*
2063* call_start
2064*
2065*/
2066int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number)
2067{
2068 if(handle == NULL)
2069 {
2070 LOGE("ARG error.");
2071 return -1;
2072 }
2073 if(str_empty(phone_number))
2074 return -1;
2075
2076 return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ,
2077 phone_number, strlen(phone_number), NULL) ? handle->info_err : 0;
2078}
2079/*
2080* Answer the phone call.
2081*
2082*/
2083int mbtk_call_answer(mbtk_info_handle_t* handle)
2084{
2085 return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2086}
2087
2088/*
2089* Hang up all call.
2090*
2091*/
2092int mbtk_call_hang(mbtk_info_handle_t* handle)
2093{
2094 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2095}
2096
2097/*
2098* Hang up a call.
2099*
2100*/
2101int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id)
2102{
2103 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0;
2104}
2105
2106/*
2107* Hang up waiting or background call.
2108*
2109*/
2110int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle)
2111{
2112 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2113}
2114
2115/*
2116* Hang up foreground resume background call.
2117*
2118*/
2119int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle)
2120{
2121 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2122}
2123
2124/*
2125* Get current call phone number.
2126*/
2127int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg)
2128{
2129 if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) {
2130 LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
2131 return 0;
2132 } else {
2133 return handle->info_err;
2134 }
2135}
2136
2137/*
2138* Return mute state.
2139*/
2140int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state)
2141{
2142 uint8 state;
2143 if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) {
2144 LOG("Mute State : %d", state);
2145 *mute_state = state;
2146 return 0;
2147 } else {
2148 return handle->info_err;
2149 }
2150}
2151
2152/*
2153* Set mute state.
2154*
2155* mute_state:
2156* 0 : of mute.
2157* 1 : on mute.
2158*
2159* Restarting takes effect after execution.
2160*/
2161int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state)
2162{
2163 return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0;
2164}
2165
2166/*
r.xiaoec113d12024-01-12 02:13:28 -08002167* Set wakeup state.
2168*
2169* wakeup_state:(0~31)
2170* 0 : means resume all
2171* 1~31 means suspend
2172* Control the active reporting of some platform modems to reduce wakeup
2173*/
2174
2175int mbtk_wakeup_state_set(mbtk_info_handle_t* handle, uint32 wakeup_state)
2176{
2177 return info_item_process(handle, MBTK_INFO_ID_WAKEUP_STA_REQ, (uint32*)&wakeup_state, sizeof(uint32), NULL) ? handle->info_err : 0;
2178}
2179
2180/*
2181* oos get.
2182*/
2183int mbtk_oos_get(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
2184{
2185 if(info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, NULL, 0, oos_info) > 0) {
2186 return 0;
2187 } else {
2188 return handle->info_err;
2189 }
2190}
2191
2192/*
2193* oos set .
2194*/
r.xiaocfd7c682024-01-22 03:59:46 -08002195int mbtk_oos_set(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
r.xiaoec113d12024-01-12 02:13:28 -08002196{
2197 if(handle == NULL)
2198 {
2199 LOGE("ARG error.");
2200 return -1;
2201 }
r.xiaoec113d12024-01-12 02:13:28 -08002202
r.xiaocfd7c682024-01-22 03:59:46 -08002203 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 -08002204}
2205
2206
2207/*
liubin281ac462023-07-19 14:22:54 +08002208* Set DTMF character.
2209*
2210*/
2211int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character)
2212{
2213 if(handle == NULL)
2214 {
2215 LOGE("ARG error.");
2216 return -1;
2217 }
2218 return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ,
2219 dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0;
2220}
2221
2222/*
wangyouqiang38e53362024-01-23 10:53:48 +08002223* Set net led.
2224*
2225*/
2226int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status)
2227{
2228 if(handle == NULL)
2229 {
2230 LOGE("ARG error.");
2231 return -1;
2232 }
2233
2234 char buff[3] = {0};
2235 if(type == MBTK_LED_TYPE_NET)
2236 {
2237 buff[0] = 0;
2238 }
2239 else
2240 {
2241 buff[0] = 1;
2242 }
2243
2244 if(status == MBTK_LED_STATUS_CLOSE)
2245 {
2246 buff[1] = 0;
2247 }
2248 else
2249 {
2250 buff[1] = 1;
2251 }
2252 return info_item_process(handle, MBTK_INFO_ID_LED_REQ, buff, 2, NULL) ? handle->info_err : 0;
2253}
2254
2255/*
liubin281ac462023-07-19 14:22:54 +08002256* Set pdp state change callback function.
2257*/
2258int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2259{
2260 if(handle == NULL)
2261 {
2262 LOGE("ARG error.");
2263 return -1;
2264 }
2265 if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) {
2266 return handle->info_err;
2267 } else {
2268 handle->pdp_state_cb = cb;
2269 return 0;
2270 }
2271}
2272
2273/*
2274* Set network state change callback function.
2275*/
2276int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2277{
2278 if(handle == NULL)
2279 {
2280 LOGE("ARG error.");
2281 return -1;
2282 }
b.liu27b91e42024-01-17 20:02:30 +08002283 if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) < 0) {
2284 return handle->info_err;
2285 } else {
liubin281ac462023-07-19 14:22:54 +08002286 handle->net_state_cb = cb;
2287 return 0;
liubin281ac462023-07-19 14:22:54 +08002288 }
2289}
2290
2291/*
2292* Set call state change callback function.
2293*/
2294int mbtk_call_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2295{
2296 if(handle == NULL)
2297 {
2298 LOGE("ARG error.");
2299 return -1;
2300 }
2301 if(info_item_process(handle, MBTK_INFO_ID_IND_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2302 return handle->info_err;
2303 } else {
2304 handle->call_state_cb = cb;
2305 return 0;
2306 }
2307}
2308
2309/*
2310* Set sms state change callback function.
2311*/
2312int mbtk_sms_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2313{
2314 if(handle == NULL)
2315 {
2316 LOGE("ARG error.");
2317 return -1;
2318 }
2319 if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) {
2320 return handle->info_err;
2321 } else {
2322 handle->sms_state_cb = cb;
2323 return 0;
2324 }
2325}
2326
2327/*
2328* Set radio state change callback function.
2329*/
2330int mbtk_radio_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2331{
2332 if(handle == NULL)
2333 {
2334 LOGE("ARG error.");
2335 return -1;
2336 }
2337 if(info_item_process(handle, MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) {
2338 return handle->info_err;
2339 } else {
2340 handle->radio_state_cb = cb;
2341 return 0;
2342 }
2343}
2344
2345/*
2346* Set sim state change callback function.
2347*/
2348int mbtk_sim_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2349{
2350 if(handle == NULL)
2351 {
2352 LOGE("ARG error.");
2353 return -1;
2354 }
2355 if(info_item_process(handle, MBTK_INFO_ID_IND_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) {
2356 return handle->info_err;
2357 } else {
2358 handle->sim_state_cb = cb;
2359 return 0;
2360 }
2361}