blob: ef7ee1c98a1f4f1daf34a48f50459a0f4d22bfad [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
1385
1386/*
1387* Get radio state.
1388*/
1389int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state)
1390{
1391 uint8 state;
1392 if(handle == NULL || radio_state == NULL)
1393 {
1394 LOGE("ARG error.");
1395 return -1;
1396 }
1397 if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) {
1398 LOG("Radio state : %d", state);
1399 *radio_state = state;
1400 return 0;
1401 } else {
1402 return handle->info_err;
1403 }
1404}
1405
1406/*
1407* Set radio state.
1408*/
1409int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state)
1410{
1411 if(handle == NULL)
1412 {
1413 LOGE("ARG error.");
1414 return -1;
1415 }
1416 return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0;
1417}
1418
1419/*
1420* Get time type.
1421*/
1422int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type)
1423{
1424 uint8 state;
1425 if(handle == NULL || time_type == NULL)
1426 {
1427 LOGE("ARG error.");
1428 return -1;
1429 }
1430 if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) {
1431 LOG("Time type : %d", state);
1432 *time_type = state;
1433 return 0;
1434 } else {
1435 return handle->info_err;
1436 }
1437}
1438
1439/*
1440*Get Absolute time
1441*"23/05/24 06:09:32 +32 00"
1442*/
1443int mbtk_get_abs_time(char *time_str, time_t *time_out)
1444{
1445 struct tm tm_;
1446
1447 char *ptr = strstr(time_str + 10, " ");
1448 *ptr = '\0';
1449
1450 LOGD("time : \"%s\"", time_str);
1451#if 1
1452 if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) {
1453 LOGE("strptime() fail.");
1454 return -1;
1455 }
1456#else
1457 int year, month, day, hour, minute,second,time_zone;
1458 if(strstr(time_str, "+")) {
1459 sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1460 } else if(strstr(time_str, "-")) {
1461 sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1462 } else {
1463 LOGE("Time format error:%s", time_str);
1464 return -1;
1465 }
1466
1467 // 1970+
1468 if(year < 70) { // 20xx
1469 tm_.tm_year = 2000 + year;
1470 } else { // 19xx
1471 tm_.tm_year = 1900 + year;
1472 }
1473 tm_.tm_mon = month - 1;
1474 tm_.tm_mday = day;
1475 tm_.tm_hour = hour;
1476 tm_.tm_min = minute;
1477 tm_.tm_sec = second;
1478 tm_.tm_isdst = 0;
1479#endif
1480
1481 time_t timeStamp = mktime(&tm_);
1482 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);
1483 LOGD("time = %ld,%x", timeStamp,timeStamp);
1484 *time_out = timeStamp;
1485
1486 return 0;
1487}
1488
1489/*
1490* Get time type.
1491* "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00"
1492*/
1493int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
1494{
1495 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1496 if(handle == NULL || time_str == NULL)
1497 {
1498 LOGE("ARG error.");
1499 return -1;
1500 }
1501 //printf("mbtk_net_time_get begin info_item_process\n");
1502 if(info_item_process(handle, MBTK_INFO_ID_NET_TIME_REQ, NULL, 0, buff) > 0) {
1503 memcpy(time_str,buff,strlen(buff));
1504
1505 uint8 *temp = strstr(time_str, ",");
1506 if(temp) {
1507 *temp = ' '; // ',' -> ' '
1508
1509 temp = strstr(time_str, "+");
1510 if(temp == NULL) {
1511 temp = strstr(time_str, "-");
1512 }
1513
1514 if(temp) {
1515 // Copy +XX or -XX
1516 uint8 *last_ptr = temp + strlen(temp) + 1;
1517 while(last_ptr > temp) {
1518 *last_ptr = *(last_ptr - 1);
1519 last_ptr--;
1520 }
1521
1522 *last_ptr = ' ';
1523
1524 memcpy(temp + strlen(temp), "00", 2);
1525
1526 LOGD("%s -> %s", buff, time_str);
1527 return 0;
1528 } else {
1529 LOGE("Time error:%s",buff);
1530 return MBTK_INFO_ERR_TIME_FORMAT;
1531 }
1532 } else {
1533 LOGE("Time error:%s",buff);
1534 return MBTK_INFO_ERR_TIME_FORMAT;
1535 }
1536 } else {
1537 return handle->info_err;
1538 }
1539}
1540
1541/*
1542* Set time.
1543*
1544* time_type:
1545* 0: Cell time
1546* 1: NTP time
1547* 2: User time
1548* time_str: "YYYY-MM-DD HH:MM:SS"
1549*/
1550int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str)
1551{
1552 if(handle == NULL)
1553 {
1554 LOGE("ARG error.");
1555 return -1;
1556 }
1557 uint8 buffer[100] = {0};
1558 buffer[0] = (uint8)time_type;
1559 if(time_type == MBTK_TIME_TYPE_USER) {
1560 if(!str_empty(time_str)) {
1561 memcpy(buffer + sizeof(uint8), time_str, strlen(time_str));
1562 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1563 buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0;
1564 } else {
1565 return -1;
1566 }
1567 } else {
1568 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1569 buffer, sizeof(uint8), NULL) ? handle->info_err : 0;
1570 }
1571}
1572
1573/*
1574* Return sms cmgf.
1575*/
1576int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state)
1577{
1578 uint8 state;
1579 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) {
1580 LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state);
1581 *volte_state = state;
1582 return 0;
1583 } else {
1584 return handle->info_err;
1585 }
1586}
1587
1588/*
1589* Set sms cmgf.
1590*
1591* volte_state:
1592* 0 : PDU mode.
1593* 1 : text mode.
1594*
1595* Restarting takes effect after execution.
1596*/
1597int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode)
1598{
1599 printf("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8));
1600 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0;
1601}
1602
1603/*
1604* Set sms cmgs.
1605*
1606if PDU mode (+CMGF=0):
1607+CMGS=<length><CR>
1608PDU is given<ctrl-Z/ESC>
1609
1610if text mode (+CMGF=1):
1611+CMGS=<da>[,<toda>]<CR>
1612text is entered<ctrl-Z/ESC>
1613
1614* Restarting takes effect after execution.
1615*/
1616int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp)
1617{
1618 printf("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs));
1619// char req[20] = {0}
1620 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){
1621 printf("resp:%s\n", resp);
1622 return 0;
1623 }else{
1624 return handle->info_err;
1625 }
1626}
1627
1628/*
1629* Set sms cmgw.
1630*
1631if text mode (+CMGF=1):
1632+CMGW=<oa/da>[,<tooa/toda>[,<stat>]]
1633<CR>
1634text is entered<ctrl-Z/ESC>
1635if PDU mode (+CMGF=0):
1636+CMGW=<length>[,<stat>]<CR>PDU is
1637given<ctrl-Z/ESC>
1638
1639*/
1640
1641int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp)
1642{
1643 printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw));
1644 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){
1645 printf("resp:%s\n", resp);
1646 return 0;
1647 }else{
1648 return handle->info_err;
1649 }
1650}
1651
1652/*
1653* Set sms cmgd.
1654*
1655* +CMGD=<index>[,<delflag>]
1656*
1657* Restarting takes effect after execution.
1658*/
1659int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg)
1660{
1661 printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg));
1662 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0;
1663}
1664
1665/*
r.xiaoeb9dba42024-02-07 02:16:13 -08001666* Get sms cmgd.
1667*
1668* +CMGD: (XXX,XXX)(0-4)
1669*
1670* Restarting takes effect after execution.
1671*/
1672int mbtk_sms_cmgd_get(mbtk_info_handle_t* handle, char * cmdg)
1673{
1674 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, NULL, 0, cmdg) ? handle->info_err : 0;
1675}
1676
1677
1678/*
liubin281ac462023-07-19 14:22:54 +08001679* Set sms cmgl.
1680*
1681* AT+CMGL[=<stat>]
1682*
1683* Restarting takes effect after execution.
1684*/
1685int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp)
1686{
1687 printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl));
1688 char reg[5*1024] ={0};
1689 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){
1690 printf("len:%d , reg:%s\n", strlen(reg), reg);
1691 // memcpy(resp, reg, strlen(reg));
1692 return 0;
1693 }else {
1694 return handle->info_err;
1695 }
1696}
1697
1698/*
1699* Return sms csca.
1700*/
1701int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf)
1702{
1703 // char state;
1704 if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) {
1705 LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf);
1706 // *volte_state = state;
1707 return 0;
1708 } else {
1709 return handle->info_err;
1710 }
1711}
1712
1713/*
1714* Set sms csca.
1715*
1716* AT+CSCA=<number> [,<type>]
1717*
1718* Restarting takes effect after execution.
1719*/
1720int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca)
1721{
1722 printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca));
1723 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0;
1724}
1725
1726/*
1727* Set sms csmp.
1728*
1729* AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1730*
1731* Restarting takes effect after execution.
1732*/
1733int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp)
1734{
1735 printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp));
1736 return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0;
1737}
1738
1739/*
1740* Set sms cscb.
1741*
1742* AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1743*
1744* Restarting takes effect after execution.
1745*/
1746int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb)
1747{
1748 printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb));
1749 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0;
1750}
1751
1752/*
1753* Set sms cnmi.
1754*
1755at+cnmi=1,2
1756
1757OK
1758if sending fails:
1759+CMS ERROR: <err>
1760*/
1761int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle)
1762{
1763 printf("mbtk_sms_cnmi_set()------------start\n");
1764
1765 return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0;
1766}
1767
1768/*
1769* Set sms cmss.
1770*
1771+CMSS=<index>[,<da>[,<toda>]]
1772
1773if sending successful:
1774+CMSS: <mr>
1775OK
1776if sending fails:
1777+CMS ERROR: <err>
1778*/
1779int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp)
1780{
1781 printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss));
1782 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){
1783 printf("resp:%s\n", resp);
1784 return 0;
1785 }else{
1786 return handle->info_err;
1787 }
1788}
1789
1790/*
1791* Return sms cmgf.
1792*/
1793int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem)
1794{
1795 char req[128] = {0};
1796 if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) {
1797 LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req));
1798 memcpy(mem, req, strlen(req));
1799 return 0;
1800 } else {
1801 return handle->info_err;
1802 }
1803}
1804
1805
1806/*
1807* Set sms cpms.
1808*
1809* AT+CPMS=<mem1>[,<mem2>[,<mem3>]]
1810*
1811* Restarting takes effect after execution.
1812*/
1813int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response)
1814{
1815 printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem));
1816 char req[128] = {0};
1817 if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){
1818 memcpy(response, req, strlen(req));
1819 return 0;
1820 }
1821 else{
1822 return handle->info_err;
1823 }
1824}
1825
1826/*
1827* Set sms cm.
1828*
1829* +CMGR=<index>
1830
1831if PDU mode (+CMGF=0) ��command successful:
1832+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
1833OK
1834if text mode (+CMGF=1), command successful and SMS-DELIVER:
1835+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs
1836>, <sca>,<tosca>,<length>]<CR><LF><data>
1837OK
1838if text mode (+CMGF=1), command successful and SMS-SUBMIT:
1839+CMGR:
1840<stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>],
1841<sca>,<tosca>,<length>]<CR><LF><data>
1842OK
1843otherwise:
1844+CMS ERROR: <err>
1845*
1846* Restarting takes effect after execution.
1847*/
1848int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp)
1849{
1850 printf("mbtk_sms_cmgr_set() --------------index:%d",index);
1851 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){
1852 printf("resp:%s\n", resp);
1853 return 0;
1854 }else{
1855 return handle->info_err;
1856 }
1857}
1858
1859
1860/*
1861* Get sim state.
1862*/
1863int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state)
1864{
1865 uint8 state;
1866 if(handle == NULL || sim_state == NULL)
1867 {
1868 LOGE("ARG error.");
1869 return -1;
1870 }
1871 if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) {
1872 *sim_state = (mbtk_sim_state_enum)state;
1873 LOG("Sim state : %d", *sim_state);
1874 return 0;
1875 } else {
1876 return handle->info_err;
1877 }
1878}
1879
1880/*
1881* Get sim card type.
1882*/
1883int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type)
1884{
1885 uint8 state;
1886 if(handle == NULL || sim_card_type == NULL)
1887 {
1888 LOGE("ARG error.");
1889 return -1;
1890 }
1891 if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) {
1892 *sim_card_type = (mbtk_sim_card_type_enum)state;
1893 LOG("Sim sim_card_type : %d", *sim_card_type);
1894 return 0;
1895 } else {
1896 return handle->info_err;
1897 }
1898}
1899
1900/*
1901* Get system temperature.
1902*
1903* type[IN]:
1904* 0: Soc temperature.
1905* 1: RF temperature.
1906* temp[OUT]:
1907* temperature in celsius.
1908*/
1909int mbtk_temp_get(mbtk_info_handle_t* handle, int type, int* temp)
1910{
1911 if(handle == NULL)
1912 {
1913 LOGE("ARG error.");
1914 return -1;
1915 }
1916 if(type != 0 && type != 1 || temp == NULL)
1917 {
1918 return -1;
1919 }
1920
1921 uint8 temp_type = (uint8)type;
1922 uint8 temp_ptr;
1923 if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), &temp_ptr) > 0) {
1924 *temp = temp_ptr;
1925 LOG("Temperature : %d", *temp);
1926 return 0;
1927 } else {
1928 return handle->info_err;
1929 }
1930
1931 return 0;
1932}
1933
1934
1935/*
1936* Set sim power state.
1937* power:
1938* 0: Sim power off.
1939* 1: Sim power on.
1940*/
1941int mbtk_sim_power_set(int power)
1942{
1943 if(power != 0 && power != 1)
1944 {
1945 return -1;
1946 }
1947
1948 // /sys/devices/virtual/usim_event/usim0/send_event
1949 char cmd[100] = {0};
1950 sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
1951 system(cmd);
1952
1953 return 0;
1954}
1955
1956/*
1957* System power.
1958* type:
1959* 0: Reboot system.
1960* 1: Poweroff system.
1961* 2: Halt system.
1962*/
1963int mbtk_system_reboot(int type)
1964{
1965 if(type != 0 && type != 1 && type != 2)
1966 {
1967 return -1;
1968 }
1969
1970 switch(type) {
1971 case 0: {
1972 system("reboot");
1973 break;
1974 }
1975 case 1: {
1976 system("poweroff");
1977 break;
1978 }
1979 case 2: {
1980 system("halt");
1981 break;
1982 }
1983 default: {
1984 break;
1985 }
1986 }
1987
1988 return 0;
1989}
1990
1991/*
1992* set modem fun
1993*
1994*/
1995int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info)
1996{
1997 if(handle == NULL)
1998 {
1999 LOGE("ARG error.");
2000 return -1;
2001 }
2002 return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0;
2003}
2004
2005/*
2006* get modem fun
2007*
2008*/
2009int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun)
2010{
2011 uint8 state;
2012 if(handle == NULL || fun == NULL)
2013 {
2014 LOGE("ARG error.");
2015 return -1;
2016 }
2017 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) {
2018 LOG("modem type : %d", state);
2019 *fun = state;
2020 return 0;
2021 } else {
2022 return handle->info_err;
2023 }
2024}
2025
2026/*
2027* call_start
2028*
2029*/
2030int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number)
2031{
2032 if(handle == NULL)
2033 {
2034 LOGE("ARG error.");
2035 return -1;
2036 }
2037 if(str_empty(phone_number))
2038 return -1;
2039
2040 return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ,
2041 phone_number, strlen(phone_number), NULL) ? handle->info_err : 0;
2042}
2043/*
2044* Answer the phone call.
2045*
2046*/
2047int mbtk_call_answer(mbtk_info_handle_t* handle)
2048{
2049 return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2050}
2051
2052/*
2053* Hang up all call.
2054*
2055*/
2056int mbtk_call_hang(mbtk_info_handle_t* handle)
2057{
2058 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2059}
2060
2061/*
2062* Hang up a call.
2063*
2064*/
2065int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id)
2066{
2067 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0;
2068}
2069
2070/*
2071* Hang up waiting or background call.
2072*
2073*/
2074int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle)
2075{
2076 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2077}
2078
2079/*
2080* Hang up foreground resume background call.
2081*
2082*/
2083int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle)
2084{
2085 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2086}
2087
2088/*
2089* Get current call phone number.
2090*/
2091int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg)
2092{
2093 if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) {
2094 LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
2095 return 0;
2096 } else {
2097 return handle->info_err;
2098 }
2099}
2100
2101/*
2102* Return mute state.
2103*/
2104int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state)
2105{
2106 uint8 state;
2107 if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) {
2108 LOG("Mute State : %d", state);
2109 *mute_state = state;
2110 return 0;
2111 } else {
2112 return handle->info_err;
2113 }
2114}
2115
2116/*
2117* Set mute state.
2118*
2119* mute_state:
2120* 0 : of mute.
2121* 1 : on mute.
2122*
2123* Restarting takes effect after execution.
2124*/
2125int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state)
2126{
2127 return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0;
2128}
2129
2130/*
r.xiaoec113d12024-01-12 02:13:28 -08002131* Set wakeup state.
2132*
2133* wakeup_state:(0~31)
2134* 0 : means resume all
2135* 1~31 means suspend
2136* Control the active reporting of some platform modems to reduce wakeup
2137*/
2138
2139int mbtk_wakeup_state_set(mbtk_info_handle_t* handle, uint32 wakeup_state)
2140{
2141 return info_item_process(handle, MBTK_INFO_ID_WAKEUP_STA_REQ, (uint32*)&wakeup_state, sizeof(uint32), NULL) ? handle->info_err : 0;
2142}
2143
2144/*
2145* oos get.
2146*/
2147int mbtk_oos_get(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
2148{
2149 if(info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, NULL, 0, oos_info) > 0) {
2150 return 0;
2151 } else {
2152 return handle->info_err;
2153 }
2154}
2155
2156/*
2157* oos set .
2158*/
r.xiaocfd7c682024-01-22 03:59:46 -08002159int mbtk_oos_set(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
r.xiaoec113d12024-01-12 02:13:28 -08002160{
2161 if(handle == NULL)
2162 {
2163 LOGE("ARG error.");
2164 return -1;
2165 }
r.xiaoec113d12024-01-12 02:13:28 -08002166
r.xiaocfd7c682024-01-22 03:59:46 -08002167 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 -08002168}
2169
2170
2171/*
liubin281ac462023-07-19 14:22:54 +08002172* Set DTMF character.
2173*
2174*/
2175int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character)
2176{
2177 if(handle == NULL)
2178 {
2179 LOGE("ARG error.");
2180 return -1;
2181 }
2182 return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ,
2183 dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0;
2184}
2185
2186/*
wangyouqiang38e53362024-01-23 10:53:48 +08002187* Set net led.
2188*
2189*/
2190int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status)
2191{
2192 if(handle == NULL)
2193 {
2194 LOGE("ARG error.");
2195 return -1;
2196 }
2197
2198 char buff[3] = {0};
2199 if(type == MBTK_LED_TYPE_NET)
2200 {
2201 buff[0] = 0;
2202 }
2203 else
2204 {
2205 buff[0] = 1;
2206 }
2207
2208 if(status == MBTK_LED_STATUS_CLOSE)
2209 {
2210 buff[1] = 0;
2211 }
2212 else
2213 {
2214 buff[1] = 1;
2215 }
2216 return info_item_process(handle, MBTK_INFO_ID_LED_REQ, buff, 2, NULL) ? handle->info_err : 0;
2217}
2218
2219/*
liubin281ac462023-07-19 14:22:54 +08002220* Set pdp state change callback function.
2221*/
2222int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2223{
2224 if(handle == NULL)
2225 {
2226 LOGE("ARG error.");
2227 return -1;
2228 }
2229 if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) {
2230 return handle->info_err;
2231 } else {
2232 handle->pdp_state_cb = cb;
2233 return 0;
2234 }
2235}
2236
2237/*
2238* Set network state change callback function.
2239*/
2240int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2241{
2242 if(handle == NULL)
2243 {
2244 LOGE("ARG error.");
2245 return -1;
2246 }
b.liu27b91e42024-01-17 20:02:30 +08002247 if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) < 0) {
2248 return handle->info_err;
2249 } else {
liubin281ac462023-07-19 14:22:54 +08002250 handle->net_state_cb = cb;
2251 return 0;
liubin281ac462023-07-19 14:22:54 +08002252 }
2253}
2254
2255/*
2256* Set call state change callback function.
2257*/
2258int mbtk_call_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_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2266 return handle->info_err;
2267 } else {
2268 handle->call_state_cb = cb;
2269 return 0;
2270 }
2271}
2272
2273/*
2274* Set sms state change callback function.
2275*/
2276int mbtk_sms_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 }
2283 if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) {
2284 return handle->info_err;
2285 } else {
2286 handle->sms_state_cb = cb;
2287 return 0;
2288 }
2289}
2290
2291/*
2292* Set radio state change callback function.
2293*/
2294int mbtk_radio_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_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) {
2302 return handle->info_err;
2303 } else {
2304 handle->radio_state_cb = cb;
2305 return 0;
2306 }
2307}
2308
2309/*
2310* Set sim state change callback function.
2311*/
2312int mbtk_sim_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_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) {
2320 return handle->info_err;
2321 } else {
2322 handle->sim_state_cb = cb;
2323 return 0;
2324 }
2325}