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