blob: 6dda440981d7a5387821e002a72600eeb4a48aa1 [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;
liubin281ac462023-07-19 14:22:54 +0800417 // Wait for server response.
liubin281ac462023-07-19 14:22:54 +0800418 pthread_cond_wait(&handle->cond, &handle->mutex);
419 handle->is_waitting = false;
420 pthread_mutex_unlock(&handle->mutex);
liubin281ac462023-07-19 14:22:54 +0800421 if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
422 {
423 LOG("REQ %s success.", id2str(id));
424 int recv_len = 0;
425 if(recv_buff && handle->data_len > 0) {
426 recv_len = handle->data_len;
427 handle->data_len = 0;
428 handle->data = NULL;
429 }
wangyouqiang962740a2023-11-02 19:27:22 +0800430 pthread_mutex_unlock(&handle->send_mutex);
wangyouqiang80487e42024-05-24 15:06:20 +0800431
liubin281ac462023-07-19 14:22:54 +0800432 return recv_len;
433 } else {
434 LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
yq.wangb783cc32024-08-13 23:23:06 -0700435 pthread_mutex_unlock(&handle->send_mutex);
wangyouqiang80487e42024-05-24 15:06:20 +0800436
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);
wangyouqiang80487e42024-05-24 15:06:20 +0800511#ifndef MBTK_SG_SUPPORT
wangyouqiang962740a2023-11-02 19:27:22 +0800512 pthread_mutex_init(&handle->send_mutex, NULL);
wangyouqiang80487e42024-05-24 15:06:20 +0800513#endif
liubin281ac462023-07-19 14:22:54 +0800514 pthread_cond_init(&handle->cond, NULL);
515 handle->is_waitting = false;
516
517 //mbtk wyq for server_ready_status add start
518 int timeout = 5;//The wait server timeout by default
519 LOG("wait server handshake message--->.");
520 while(timeout)
521 {
522 if(handle->server_ready_status)
523 {
524 break;
525 }
526 else
527 {
528 sleep(1);
529 timeout--;
530 }
531 }
532
533 if(timeout <= 0)
534 {
535 if(handle->exit_fd[1] > 0)
536 {
537 write(handle->exit_fd[1], "EXIT", 4);
538 }
539 pthread_join(handle->read_thread_id,NULL);
540 LOG("mbtk_info_handle_get() server not ready.");
541 goto error;
542 }
543 else
544 {
545 LOG("mbtk_info_handle_get() server ready ok.");
546 }
547 //mbtk wyq for server_ready_status add end
548 return handle;
549error:
550 if(handle)
551 {
552 if(handle->client_fd > 0)
553 {
554 close(handle->client_fd);
555 }
556 if(handle->exit_fd[0] > 0) {
557 close(handle->exit_fd[0]);
558 }
559 if(handle->exit_fd[1] > 0) {
560 close(handle->exit_fd[1]);
561 }
562 free(handle);
563 handle = NULL;
564 }
565
566 return NULL;
567}
568
569int mbtk_info_handle_free(mbtk_info_handle_t** handle)
570{
571 if(handle == NULL || *handle == NULL)
572 {
573 LOG("Handle is NULL.");
574 return -1;
575 }
576
577 if((*handle)->exit_fd[1] > 0) {
578 write((*handle)->exit_fd[1], "EXIT", 4);
579 }
580
581 // Wait read_thread exit.
582 pthread_join((*handle)->read_thread_id,NULL);
583
584 if((*handle)->exit_fd[0] > 0) {
585 close((*handle)->exit_fd[0]);
586 (*handle)->exit_fd[0] = -1;
587 }
588
589 if((*handle)->exit_fd[1] > 0) {
590 close((*handle)->exit_fd[1]);
591 (*handle)->exit_fd[1] = -1;
592 }
593
594 if((*handle)->client_fd > 0)
595 {
596 close((*handle)->client_fd);
597 (*handle)->client_fd = -1;
598 }
599 free(*handle);
600 *handle = NULL;
601 return 0;
602}
603
604/*
605* Get platform version.
606*/
607int mbtk_version_get(mbtk_info_handle_t* handle, void *version)
608{
609 if(handle == NULL || version == NULL)
610 {
611 LOGE("ARG error.");
612 return -1;
613 }
614
615 if(info_item_process(handle, MBTK_INFO_ID_DEV_VERSION_REQ, NULL, 0, version) > 0) {
616 LOG("Version : %s", version);
617 return 0;
618 } else {
619 return handle->info_err;
620 }
621}
622
623/*
624* Get platform version.
625*/
626int mbtk_model_get(mbtk_info_handle_t* handle, void *model)
627{
628 if(handle == NULL || model == NULL)
629 {
630 LOGE("ARG error.");
631 return -1;
632 }
633
634 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEL_REQ, NULL, 0, model) > 0) {
635 LOG("Version : %s", model);
636 return 0;
637 } else {
638 return handle->info_err;
639 }
640}
641
642/*
643* Get platform IMEI.
644*/
645int mbtk_imei_get(mbtk_info_handle_t* handle, void *imei)
646{
647 if(handle == NULL || imei == NULL)
648 {
649 LOGE("ARG error.");
650 return -1;
651 }
652 if(info_item_process(handle, MBTK_INFO_ID_DEV_IMEI_REQ, NULL, 0, imei) > 0) {
653 LOG("IMEI : %s", imei);
654 return 0;
655 } else {
656 return handle->info_err;
657 }
658}
659
660/*
661* Get platform SN.
662*/
663int mbtk_sn_get(mbtk_info_handle_t* handle, void *sn)
664{
665 if(handle == NULL || sn == NULL)
666 {
667 LOGE("ARG error.");
668 return -1;
669 }
670 if(info_item_process(handle, MBTK_INFO_ID_DEV_SN_REQ, NULL, 0, sn) > 0) {
671 LOG("SN : %s", sn);
672 return 0;
673 } else {
674 return handle->info_err;
675 }
676}
677
678/*
679* Get platform MEID.
680*/
681int mbtk_meid_get(mbtk_info_handle_t* handle, void *meid)
682{
683 if(handle == NULL || meid == NULL)
684 {
685 LOGE("ARG error.");
686 return -1;
687 }
688 if(info_item_process(handle, MBTK_INFO_ID_DEV_MEID_REQ, NULL, 0, meid) > 0) {
689 LOG("MEID : %s", meid);
690 return 0;
691 } else {
692 return handle->info_err;
693 }
694}
695
696/*
697* Return VoLTE state.
698*/
699int mbtk_volte_state_get(mbtk_info_handle_t* handle, int *volte_state)
700{
701 uint8 state;
702 if(handle == NULL || volte_state == NULL)
703 {
704 LOGE("ARG error.");
705 return -1;
706 }
707 if(info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, NULL, 0, &state) > 0) {
708 LOG("VoLTE State : %d", state);
709 *volte_state = state;
710 return 0;
711 } else {
712 return handle->info_err;
713 }
714}
715
716/*
717* Set VoLTE state.
718*
719* volte_state:
720* 0 : Close VoLTE.
721* 1 : Open VoLTE.
722*
723* Restarting takes effect after execution.
724*/
725int mbtk_volte_state_set(mbtk_info_handle_t* handle, int volte_state)
726{
727 if(handle == NULL)
728 {
729 LOGE("ARG error.");
730 return -1;
731 }
732 return info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, (uint8*)&volte_state, sizeof(uint8), NULL) ? handle->info_err : 0;
733}
734
735/*
736* Get platform IMSI.
737*/
738int mbtk_imsi_get(mbtk_info_handle_t* handle, void *imsi)
739{
740 if(handle == NULL || imsi == NULL)
741 {
742 LOGE("ARG error.");
743 return -1;
744 }
745 if(info_item_process(handle, MBTK_INFO_ID_SIM_IMSI_REQ, NULL, 0, imsi) > 0) {
746 LOG("IMSI : %s", imsi);
747 return 0;
748 } else {
749 return handle->info_err;
750 }
751}
752
753/*
754* Get platform ICCID.
755*/
756int mbtk_iccid_get(mbtk_info_handle_t* handle, void *iccid)
757{
758 if(handle == NULL || iccid == NULL)
759 {
760 LOGE("ARG error.");
761 return -1;
762 }
763 if(info_item_process(handle, MBTK_INFO_ID_SIM_ICCID_REQ, NULL, 0, iccid) > 0) {
764 LOG("ICCID : %s", iccid);
765 return 0;
766 } else {
767 return handle->info_err;
768 }
769}
770
771/*
772* Get current phone number.
773*/
774int mbtk_phone_number_get(mbtk_info_handle_t* handle, void *phone_number)
775{
776 if(handle == NULL || phone_number == NULL)
777 {
778 LOGE("ARG error.");
779 return -1;
780 }
781 if(info_item_process(handle, MBTK_INFO_ID_SIM_PN_REQ, NULL, 0, phone_number) > 0) {
782 LOG("Phone Number : %s", phone_number);
783 return 0;
784 } else {
785 return handle->info_err;
786 }
787}
788
789/*
790* Get PIN’s number of remaining retry
791*/
792int mbtk_pin_last_num_get(mbtk_info_handle_t* handle, mbtk_pin_puk_last_times *last_times)
793{
794 if(handle == NULL || last_times == NULL)
795 {
796 LOGE("ARG error.");
797 return -1;
798 }
799 if(info_item_process(handle, MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ, NULL, 0, last_times) > 0) {
800 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);
801 return 0;
802 } else {
803 return handle->info_err;
804 }
805}
806
807/*
808* emable PIN
809*/
810int mbtk_enable_pin(mbtk_info_handle_t* handle, mbtk_enable_pin_info *pin)
811{
812 if(handle == NULL)
813 {
814 LOGE("ARG error.");
815 return -1;
816 }
817 if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, pin, sizeof(mbtk_enable_pin_info), NULL) >= 0) {
818 LOG("pin Number : %s", pin->pin_value);
819 return 0;
820 } else {
821 return handle->info_err;
822 }
823
824}
825
826/*
827* Verify PIN
828*/
829int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin)
830{
831 if(handle == NULL)
832 {
833 LOGE("ARG error.");
834 return -1;
835 }
836 if(info_item_process(handle, MBTK_INFO_ID_SIM_PIN_REQ, pin, strlen(pin), NULL) >= 0) {
837 LOG("pin Number : %s", pin);
838 return 0;
839 } else {
840 return handle->info_err;
841 }
842
843}
844
845/*
846* Verify PIN
847*/
848int mbtk_change_pin(mbtk_info_handle_t* handle, mbtk_change_pin_info *pin)
849{
850 if(handle == NULL)
851 {
852 LOGE("ARG error.");
853 return -1;
854 }
855 if(info_item_process(handle, MBTK_INFO_ID_SIM_CHANGE_PIN_REQ, pin, sizeof(mbtk_change_pin_info), NULL) >= 0) {
856 LOG("Change PIN : %s -> %s", pin->old_pin_value, pin->new_pin_value);
857 return 0;
858 } else {
859 return handle->info_err;
860 }
861}
862
863/*
864* unblock_pin
865*/
866int mbtk_unlock_pin(mbtk_info_handle_t* handle, mbtk_unlock_pin_info *pin)
867{
868 if(handle == NULL)
869 {
870 LOGE("ARG error.");
871 return -1;
872 }
873 if(info_item_process(handle, MBTK_INFO_ID_SIM_PUK_REQ, pin, sizeof(mbtk_unlock_pin_info), NULL) >= 0) {
874 LOG("Unlock : %s , %s", pin->pin_value , pin->puk_value);
875 return 0;
876 } else {
877 return handle->info_err;
878 }
879}
880
881/*
882* Get plmn list
883*/
884int mbtk_get_plmn_list(mbtk_info_handle_t* handle, mbtk_plmn_info *pin)
885{
886 if(handle == NULL)
887 {
888 LOGE("ARG error.");
889 return -1;
890 }
891 if(info_item_process(handle, MBTK_INFO_ID_SIM_PLMN_REQ, NULL, 0, pin) >= 0) {
892 //LOG("pin Number : %s", pin);
893 return 0;
894 } else {
895 return handle->info_err;
896 }
897}
898
899
900/*
901* Get available network.
902*/
903int mbtk_available_net_get(mbtk_info_handle_t* handle, list_node_t **net_list)
904{
905 if(handle == NULL)
906 {
907 LOGE("ARG error.");
908 return -1;
909 }
910 *net_list = list_create(NULL);
911 if(*net_list == NULL)
912 {
913 LOG("list_create() fail.");
914 return MBTK_INFO_ERR_MEMORY;
915 }
916
917 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
918 int buff_len;
919 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_AVAILABLE_REQ, NULL, 0, buff)) > 0) {
920 int i = 0;
921 while (i < buff_len / sizeof(mbtk_net_info_t))
922 {
923 mbtk_net_info_t* net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t));
924 if(net == NULL)
925 {
926 LOG("malloc() fail.");
927 list_free(*net_list);
928 return MBTK_INFO_ERR_MEMORY;
929 }
930 memcpy(net, buff + i * sizeof(mbtk_net_info_t), sizeof(mbtk_net_info_t));
931 list_add(*net_list, net);
932
933 LOG("NET-%d: %d, %d, %d, %d", i + 1, net->net_sel_mode, net->net_type, net->net_state, net->plmn);
934 i++;
935 }
936
937 return 0;
938 } else {
939 list_free(*net_list);
940 return handle->info_err;
941 }
942}
943
944/*
945* Set network select mode. (+COPS=...)
946*/
947int mbtk_net_sel_mode_set(mbtk_info_handle_t* handle, const mbtk_net_info_t *net)
948{
949 if(handle == NULL || net == NULL)
950 {
951 LOGE("ARG error.");
952 return -1;
953 }
954 return info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, net, sizeof(mbtk_net_info_t), NULL) ? handle->info_err : 0;
955}
956
957/*
958* Get network select mode. (+COPS?)
959*/
960int mbtk_net_sel_mode_get(mbtk_info_handle_t* handle, mbtk_net_info_t *net)
961{
962 if(handle == NULL || net == NULL)
963 {
964 LOGE("ARG error.");
965 return -1;
966 }
967 if(info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, NULL, 0, net) > 0) {
968 LOG("NET : %d, %d, %d, %d", net->net_sel_mode, net->net_type, net->net_state, net->plmn);
969 return 0;
970 } else {
971 return handle->info_err;
972 }
973}
974
975/*
976* Get platform support bands.
977*/
978int mbtk_support_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
979{
980 uint8 type = 0; // Get support bands.
981 if(handle == NULL || band == NULL)
982 {
983 LOGE("ARG error.");
984 return -1;
985 }
986 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
987 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
988 return 0;
989 } else {
990 return handle->info_err;
991 }
992}
993
994/*
995* Get platform current bands.
996*/
997int mbtk_current_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
998{
999 uint8 type = 1; // Get current bands.
1000 if(handle == NULL || band == NULL)
1001 {
1002 LOGE("ARG error.");
1003 return -1;
1004 }
1005 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
1006 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
1007 return 0;
1008 } else {
1009 return handle->info_err;
1010 }
1011}
1012
1013/*
1014* Set platform current bands.
1015*/
1016int mbtk_current_band_set(mbtk_info_handle_t* handle, const mbtk_band_info_t *band)
1017{
1018 if(handle == NULL || band == NULL)
1019 {
1020 LOGE("ARG error.");
1021 return -1;
1022 }
1023 return info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, band, sizeof(mbtk_band_info_t), NULL) ? handle->info_err : 0;
1024}
1025
1026/*
1027* Get current cell infomation.
1028*/
1029int mbtk_cell_get(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list)
1030{
1031 if(handle == NULL)
1032 {
1033 LOGE("ARG error.");
1034 return -1;
1035 }
1036 *cell_list = list_create(NULL);
1037 if(*cell_list == NULL)
1038 {
1039 LOG("list_create() fail.");
1040 return MBTK_INFO_ERR_MEMORY;
1041 }
1042
1043 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1044 int buff_len;
1045 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, NULL, 0, buff)) > 0) {
1046 int i = 0;
1047 *type = buff[0]; // Set network type.
1048 while (i < (buff_len - sizeof(uint8)) / sizeof(mbtk_cell_info_t))
1049 {
1050 mbtk_cell_info_t* cell = (mbtk_cell_info_t*)malloc(sizeof(mbtk_cell_info_t));
1051 if(cell == NULL)
1052 {
1053 LOG("malloc() fail.");
1054 list_free(*cell_list);
1055 return MBTK_INFO_ERR_MEMORY;
1056 }
1057 memcpy(cell, buff + sizeof(uint8) + i * sizeof(mbtk_cell_info_t), sizeof(mbtk_cell_info_t));
1058 list_add(*cell_list, cell);
1059
1060 // LOG("Cell-%d: %d, %d, %d, %d, %d", i + 1, cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1061 i++;
1062 }
1063
1064 return 0;
1065 } else {
1066 list_free(*cell_list);
1067 return handle->info_err;
1068 }
1069}
1070/*
1071* Set cell info.
1072*
1073* at*CELL=<mode>,<act>,< band>,<freq>,<cellId>
1074* at*cell=2,3,,40936,429 //
1075* at*cell=0 //
1076*
1077* Restarting takes effect after execution.
1078*/
1079int mbtk_cell_set(mbtk_info_handle_t* handle, char * info, char* response)
1080{
1081 printf("mbtk_cell_set() info:%s, len:%d",info, strlen(info));
1082 char req[128] = {0};
1083 if( info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, info, strlen(info), req) > 0){
1084 memcpy(response, req, strlen(req));
1085 return 0;
1086 }
1087 else{
1088 return 0;
1089 // return handle->info_err;
1090 }
1091}
1092
1093/*
1094* Get all APN informations.
1095*/
1096int mbtk_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_apn_info_t apns[])
1097{
1098 int len;
1099 if(handle == NULL || apn_num == NULL || apns == NULL)
1100 {
1101 LOGE("ARG error.");
1102 return -1;
1103 }
1104 uint8 data[SOCK_MSG_LEN_MAX];
1105 if((len = info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, NULL, 0, data)) > 0) {
1106 /*
1107 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
1108 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1109 */
1110 uint8* ptr = data;
1111 if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
1112 *apn_num = 0;
1113 LOGE("APN array size to not enough.");
1114 return -1;
1115 }
1116 *apn_num = *ptr++;
1117 LOG("APN Number : %d", *apn_num);
1118 int i = 0;
1119 while(i < *apn_num) {
1120 memset(&(apns[i]), 0 ,sizeof(mbtk_apn_info_t));
1121 apns[i].cid = *ptr++;
1122 apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
1123
1124 // apn
1125 len = byte_2_uint16(ptr, false);
1126 ptr += sizeof(uint16);
1127 if(len > 0) { // Has APN
1128 memcpy(apns[i].apn, ptr, len);
1129 ptr += len;
1130 }
1131 // user
1132 len = byte_2_uint16(ptr, false);
1133 ptr += sizeof(uint16);
1134 if(len > 0) { // Has APN
1135 memcpy(apns[i].user, ptr, len);
1136 ptr += len;
1137 }
1138
1139 // pass
1140 len = byte_2_uint16(ptr, false);
1141 ptr += sizeof(uint16);
1142 if(len > 0) { // Has APN
1143 memcpy(apns[i].pass, ptr, len);
1144 ptr += len;
1145 }
1146 // auth
1147 len = byte_2_uint16(ptr, false);
1148 ptr += sizeof(uint16);
1149 if(len > 0) { // Has APN
1150 memcpy(apns[i].auth, ptr, len);
1151 ptr += len;
1152 }
1153
1154 i++;
1155 }
1156 return 0;
1157 } else {
1158 return handle->info_err;
1159 }
1160}
1161
1162/*
wangyouqiang80487e42024-05-24 15:06:20 +08001163* Get all APN informations.
1164*/
1165int mbtk_qser_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_qser_apn_info_s apns[])
1166{
1167 int len;
1168 if(handle == NULL || apn_num == NULL || apns == NULL)
1169 {
1170 LOGE("ARG error.");
1171 return -1;
1172 }
1173 uint8 data[SOCK_MSG_LEN_MAX];
1174 if((len = info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, NULL, 0, data)) > 0) {
1175 /*
1176 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth[1]><apn_type_len[2]><apn_type_len>...
1177 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth[1]><apn_type_len[2]><apn_type_len>
1178 */
1179 uint8* ptr = data;
1180 if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
1181 *apn_num = 0;
1182 LOGE("APN array size to not enough.");
1183 return -1;
1184 }
1185 *apn_num = *ptr++;
1186 LOGD("APN Number : %d", *apn_num);
1187 int i = 0;
1188 while(i < *apn_num) {
1189 memset(&(apns[i]), 0x0 ,sizeof(mbtk_qser_apn_info_s));
1190 apns[i].cid = *ptr++;
1191 apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
1192
1193 // apn
1194 len = byte_2_uint16(ptr, false);
1195 ptr += sizeof(uint16);
1196 if(len > 0) { // Has APN
1197 memcpy(apns[i].apn_name, ptr, len);
1198 ptr += len;
1199 }
1200 // user
1201 len = byte_2_uint16(ptr, false);
1202 ptr += sizeof(uint16);
1203 if(len > 0) { // Has APN
1204 memcpy(apns[i].user_name, ptr, len);
1205 ptr += len;
1206 }
1207
1208 // pass
1209 len = byte_2_uint16(ptr, false);
1210 ptr += sizeof(uint16);
1211 if(len > 0) { // Has APN
1212 memcpy(apns[i].user_pass, ptr, len);
1213 ptr += len;
1214 }
1215 // auth
1216 apns[i].auth_proto = (mbtk_apn_auth_proto_enum)(*ptr++);
1217
1218 //apn_type
1219 len = byte_2_uint16(ptr, false);
1220 ptr += sizeof(uint16);
1221 if(len > 0) { // Has APN
1222 memcpy(apns[i].apn_type, ptr, len);
1223 ptr += len;
1224 }
1225
1226 i++;
1227 }
1228 }
1229 else if(len == 0)
1230 {
1231 LOGD("get data len : 0.");
1232 *apn_num = 0;
1233 return 0;
1234 }
1235 else
1236 {
1237 return handle->info_err;
1238 }
1239
1240 return 0;
1241}
1242
1243/*
1244* qser Set current APN informations.
1245*/
1246int mbtk_qser_apn_set(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid)
1247{
1248 if(handle == NULL)
1249 {
1250 LOGE("ARG error.");
1251 return -1;
1252 }
1253
1254 uint8 data[SOCK_MSG_LEN_MAX];
1255 memset(data, 0, SOCK_MSG_LEN_MAX);
1256 // cid : 2 - 7
1257 if(apninfo->req_type != MBTK_APN_REQ_TYPE_ADD && (apninfo->cid < MBTK_APN_CID_MIN || apninfo->cid > MBTK_APN_CID_MAX)) {
1258 LOGE("CID error.");
1259 return -1;
1260 }
1261
1262 uint8* ptr = data;
1263 // <cid[1]><ip_type[1]><req_type[1]><auth[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><apn_type[2]>
1264 *ptr++ = (uint8)apninfo->cid;
1265 *ptr++ = (uint8)apninfo->ip_type;
1266 *ptr++ = (uint8)apninfo->req_type;
1267 *ptr++ = (uint8)apninfo->auth_proto;
1268 if(str_empty(apninfo->apn_name)) {
1269 uint16_2_byte((uint16)0, ptr, false);
1270 ptr += sizeof(uint16);
1271 } else {
1272 uint16_2_byte((uint16)strlen((char *)apninfo->apn_name), ptr, false);
1273 ptr += sizeof(uint16);
1274 memcpy(ptr, apninfo->apn_name, strlen((char *)apninfo->apn_name));
1275 ptr += strlen((char *)apninfo->apn_name);
1276 }
1277 if(str_empty(apninfo->user_name)) {
1278 uint16_2_byte((uint16)0, ptr, false);
1279 ptr += sizeof(uint16);
1280 } else {
1281 uint16_2_byte((uint16)strlen((char *)apninfo->user_name), ptr, false);
1282 ptr += sizeof(uint16);
1283 memcpy(ptr, apninfo->user_name, strlen((char *)apninfo->user_name));
1284 ptr += strlen((char *)apninfo->user_name);
1285 }
1286
1287 if(str_empty(apninfo->user_pass)) {
1288 uint16_2_byte((uint16)0, ptr, false);
1289 ptr += sizeof(uint16);
1290 } else {
1291 uint16_2_byte((uint16)strlen((char *)apninfo->user_pass), ptr, false);
1292 ptr += sizeof(uint16);
1293 memcpy(ptr, apninfo->user_pass, strlen((char *)apninfo->user_pass));
1294 ptr += strlen((char *)apninfo->user_pass);
1295 }
1296
1297 if(str_empty(apninfo->apn_type)) {
1298 uint16_2_byte((uint16)0, ptr, false);
1299 ptr += sizeof(uint16);
1300 }
1301 else
1302 {
1303 uint16_2_byte((uint16)strlen((char *)apninfo->apn_type), ptr, false);
1304 ptr += sizeof(uint16);
1305 memcpy(ptr, apninfo->apn_type, strlen((char *)apninfo->apn_type));
1306 ptr += strlen((char *)apninfo->apn_type);
1307 }
1308
1309 if(info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, data, ptr - data, (void *)cid) < 0)
1310 {
1311 return handle->info_err;
1312 }
1313
1314 return 0;
1315}
1316
1317/*
liubin281ac462023-07-19 14:22:54 +08001318* Set current APN informations.
1319*/
1320int mbtk_apn_set(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name,
1321 const void *user_name, const void *user_pass, const void *auth)
1322{
1323 if(handle == NULL)
1324 {
1325 LOGE("ARG error.");
1326 return -1;
1327 }
1328 uint8 data[SOCK_MSG_LEN_MAX];
1329 memset(data, 0, SOCK_MSG_LEN_MAX);
1330 // cid : 2 - 7
1331 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1332 LOGE("CID error.");
1333 return -1;
1334 }
1335 uint8* ptr = data;
1336 // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1337 *ptr++ = (uint8)cid;
1338 *ptr++ = (uint8)ip_type;
1339 if(str_empty(apn_name)) {
1340 uint16_2_byte((uint16)0, ptr, false);
1341 ptr += sizeof(uint16);
1342 } else {
1343 uint16_2_byte((uint16)strlen(apn_name), ptr, false);
1344 ptr += sizeof(uint16);
1345 memcpy(ptr, apn_name, strlen(apn_name));
1346 ptr += strlen(apn_name);
1347 }
1348 if(str_empty(user_name)) {
1349 uint16_2_byte((uint16)0, ptr, false);
1350 ptr += sizeof(uint16);
1351 } else {
1352 uint16_2_byte((uint16)strlen(user_name), ptr, false);
1353 ptr += sizeof(uint16);
1354 memcpy(ptr, user_name, strlen(user_name));
1355 ptr += strlen(user_name);
1356 }
1357
1358 if(str_empty(user_pass)) {
1359 uint16_2_byte((uint16)0, ptr, false);
1360 ptr += sizeof(uint16);
1361 } else {
1362 uint16_2_byte((uint16)strlen(user_pass), ptr, false);
1363 ptr += sizeof(uint16);
1364 memcpy(ptr, user_pass, strlen(user_pass));
1365 ptr += strlen(user_pass);
1366 }
1367
1368 if(str_empty(auth)) {
1369 uint16_2_byte((uint16)0, ptr, false);
1370 ptr += sizeof(uint16);
1371 } else {
1372 uint16_2_byte((uint16)strlen(auth), ptr, false);
1373 ptr += sizeof(uint16);
1374 memcpy(ptr, auth, strlen(auth));
1375 ptr += strlen(auth);
1376 }
1377
1378 return info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, data, ptr - data, NULL) ? handle->info_err : 0;
1379}
1380
liuyang0e49d9a2024-04-23 21:04:54 +08001381int mbtk_apn_del(mbtk_info_handle_t* handle, unsigned char profile_idx)
1382{
liuyang0e49d9a2024-04-23 21:04:54 +08001383 if(handle == NULL)
1384 {
1385 LOGE("ARG error.");
1386 return -1;
1387 }
liuyang1cefd852024-04-24 18:30:53 +08001388
1389 profile_idx++;
1390 if(info_item_process(handle, MBTK_INFO_ID_NET_APN_DEL_REQ, &profile_idx, sizeof(profile_idx), NULL) >= 0)
liuyang0e49d9a2024-04-23 21:04:54 +08001391 {
liuyang1cefd852024-04-24 18:30:53 +08001392 LOG("profile_idx Number : %d", profile_idx);
liuyang0e49d9a2024-04-23 21:04:54 +08001393 return 0;
1394 }
1395 else
1396 {
1397 return handle->info_err;
1398 }
1399
1400}
1401
liubin281ac462023-07-19 14:22:54 +08001402/*
1403* Start data call.
1404*/
1405int mbtk_data_call_start(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout)
1406{
1407 uint8 data[10];
1408 if(handle == NULL)
1409 {
1410 LOGE("ARG error.");
1411 return -1;
1412 }
1413 memset(data, 0, 10);
1414 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1415 LOGE("CID error.");
1416 return -1;
1417 }
1418 uint8* ptr = data;
1419 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
1420 call_type : mbtk_data_call_type_enum
1421 cid : 2 - 7
1422 timeout : second
1423 */
1424 *ptr++ = (uint8)MBTK_DATA_CALL_START;
1425 *ptr++ = (uint8)cid;
1426 *ptr++ = (uint8)(auto_conn_interval > 0 ? auto_conn_interval : 0); // 拨号失败后重拨间隔(s)
1427 *ptr++ = (uint8)(boot_conn ? 1 : 0); // 开机自动拨号
1428 if(timeout <= 0) {
1429 *ptr++ = (uint8)MBTK_DATA_CALL_TIMEOUT_DEFAULT;
1430 } else {
1431 *ptr++ = (uint8)timeout;
1432 }
1433
1434 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 5, NULL) ? handle->info_err : 0;
1435}
1436
1437/*
1438* Stop data call.
1439*/
1440int mbtk_data_call_stop(mbtk_info_handle_t* handle, int cid, int timeout)
1441{
1442 uint8 data[10];
1443 if(handle == NULL)
1444 {
1445 LOGE("ARG error.");
1446 return -1;
1447 }
1448 memset(data, 0, 10);
1449 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1450 LOGE("CID error.");
1451 return -1;
1452 }
1453 uint8* ptr = data;
1454 /* <call_type[1]><cid[1]><timeout[1]>
1455 call_type : mbtk_data_call_type_enum
1456 cid : 2 - 7
1457 timeout : second
1458 */
1459 *ptr++ = (uint8)MBTK_DATA_CALL_STOP;
1460 *ptr++ = (uint8)cid;
1461 *ptr++ = (uint8)timeout;
1462
1463 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, NULL) ? handle->info_err : 0;
1464}
1465
1466/*
1467* Get data call state.
1468*/
1469int mbtk_data_call_state_get(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
1470{
1471 uint8 data[10];
1472 if(handle == NULL)
1473 {
1474 LOGE("ARG error.");
1475 return -1;
1476 }
1477 uint8 recv_buff[SOCK_MSG_LEN_MAX]={0};
1478 memset(data, 0, 10);
1479 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1480 LOGE("CID error.");
1481 return -1;
1482 }
1483 uint8* ptr = data;
1484 /* <call_type[1]><cid[1]><timeout[1]>
1485 call_type : mbtk_data_call_type_enum
1486 cid : 2 - 7
1487 timeout : second
1488 */
1489 *ptr++ = (uint8)MBTK_DATA_CALL_STATE;
1490 *ptr++ = (uint8)cid;
1491 *ptr++ = (uint8)0;
1492
1493 if(ipv4) {
1494 memset(ipv4, 0, sizeof(mbtk_ipv4_info_t));
1495 }
1496
1497 if(ipv6) {
1498 memset(ipv6, 0, sizeof(mbtk_ipv6_info_t));
1499 }
1500
1501 if(info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, recv_buff) > 0) {
1502 if(recv_buff[0] == 0) { // IPv4 Only.
1503 if(ipv4) {
1504 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1505 }
1506 } else if(recv_buff[0] == 1) { // IPv6 Only.
1507 if(ipv6) {
1508 memcpy(ipv6, recv_buff + sizeof(uint8), sizeof(mbtk_ipv6_info_t));
1509 }
1510 } else if(recv_buff[0] == 2) { // IPv4 and IPv6.
1511 if(ipv4) {
1512 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1513 }
1514
1515 if(ipv6) {
1516 memcpy(ipv6, recv_buff + sizeof(uint8) + sizeof(mbtk_ipv4_info_t), sizeof(mbtk_ipv6_info_t));
1517 }
1518 } else {
1519 LOGE("Unknown IP type : %d", recv_buff[0]);
1520 return -1;
1521 }
1522 return 0;
1523 } else {
1524 return handle->info_err;
1525 }
1526}
1527
1528
1529
1530/*
1531* Get current network signal.
1532*/
1533int mbtk_net_signal_get(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal)
1534{
1535 if(handle == NULL || signal == NULL)
1536 {
1537 LOGE("ARG error.");
1538 return -1;
1539 }
1540 if(info_item_process(handle, MBTK_INFO_ID_NET_SIGNAL_REQ, NULL, 0, signal) > 0) {
1541 LOG("Signal : %d, %d, %d, %d, %d, %d, %d", signal->rssi, signal->rxlev, signal->ber, signal->rscp, signal->ecno,
1542 signal->rsrq, signal->rsrp);
1543 return 0;
1544 } else {
1545 return handle->info_err;
1546 }
1547}
1548
1549/*
1550* Get current network register information.
1551*/
1552int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg)
1553{
1554 if(handle == NULL || reg == NULL)
1555 {
1556 LOGE("ARG error.");
1557 return -1;
1558 }
1559 if(info_item_process(handle, MBTK_INFO_ID_NET_REG_REQ, NULL, 0, reg) > 0) {
1560 if(reg->call_state || reg->data_state || reg->ims_state) {
1561 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);
1562 } else {
1563 LOGE("Net not reg.");
1564 }
1565 return 0;
1566 } else {
1567 return handle->info_err;
1568 }
1569}
1570
r.xiao06db9a12024-04-14 18:51:15 -07001571/*
b.liufdf03172024-06-07 15:01:29 +08001572* Get current IMS enable or not.
r.xiao06db9a12024-04-14 18:51:15 -07001573*/
b.liufdf03172024-06-07 15:01:29 +08001574int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* enable)
r.xiao06db9a12024-04-14 18:51:15 -07001575{
1576 uint8 state;
1577 if(handle == NULL)
1578 {
1579 LOGE("ARG error.");
1580 return -1;
1581 }
1582 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, NULL, 0, &state) > 0) {
b.liufdf03172024-06-07 15:01:29 +08001583 LOG("IMS enable : %d", state);
1584 *enable = state;
r.xiao06db9a12024-04-14 18:51:15 -07001585 return 0;
1586 } else {
1587 return handle->info_err;
1588 }
1589
1590}
1591
1592/*
b.liufdf03172024-06-07 15:01:29 +08001593* Set IMS enable or not. This function takes effect after starting the device.
r.xiao06db9a12024-04-14 18:51:15 -07001594*/
b.liufdf03172024-06-07 15:01:29 +08001595int mbtk_net_ims_set(mbtk_info_handle_t* handle, int enable)
r.xiao06db9a12024-04-14 18:51:15 -07001596{
1597 if(handle == NULL)
1598 {
1599 LOGE("ARG error.");
1600 return -1;
1601 }
1602
b.liufdf03172024-06-07 15:01:29 +08001603 return info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, (uint8*)&enable, sizeof(uint8), NULL) ? handle->info_err : 0;
r.xiao06db9a12024-04-14 18:51:15 -07001604
1605}
1606
b.liufdf03172024-06-07 15:01:29 +08001607/*
1608* Get current network IMS register state.
1609*/
1610int mbtk_net_ims_reg_state_get(mbtk_info_handle_t* handle, int* reg)
1611{
1612 uint8 state;
1613 if(handle == NULL)
1614 {
1615 LOGE("ARG error.");
1616 return -1;
1617 }
1618 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REG_STATE_REQ, NULL, 0, &state) > 0) {
1619 LOG("reg type : %d", state);
1620 *reg = state;
1621 return 0;
1622 } else {
1623 return handle->info_err;
1624 }
1625}
1626
liubin281ac462023-07-19 14:22:54 +08001627
1628/*
1629* Get radio state.
1630*/
1631int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state)
1632{
1633 uint8 state;
1634 if(handle == NULL || radio_state == NULL)
1635 {
1636 LOGE("ARG error.");
1637 return -1;
1638 }
1639 if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) {
1640 LOG("Radio state : %d", state);
1641 *radio_state = state;
1642 return 0;
1643 } else {
1644 return handle->info_err;
1645 }
1646}
1647
1648/*
1649* Set radio state.
1650*/
1651int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state)
1652{
1653 if(handle == NULL)
1654 {
1655 LOGE("ARG error.");
1656 return -1;
1657 }
1658 return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0;
1659}
1660
1661/*
1662* Get time type.
1663*/
1664int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type)
1665{
1666 uint8 state;
1667 if(handle == NULL || time_type == NULL)
1668 {
1669 LOGE("ARG error.");
1670 return -1;
1671 }
1672 if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) {
1673 LOG("Time type : %d", state);
1674 *time_type = state;
1675 return 0;
1676 } else {
1677 return handle->info_err;
1678 }
1679}
1680
1681/*
1682*Get Absolute time
1683*"23/05/24 06:09:32 +32 00"
1684*/
1685int mbtk_get_abs_time(char *time_str, time_t *time_out)
1686{
1687 struct tm tm_;
1688
1689 char *ptr = strstr(time_str + 10, " ");
1690 *ptr = '\0';
1691
1692 LOGD("time : \"%s\"", time_str);
1693#if 1
1694 if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) {
1695 LOGE("strptime() fail.");
1696 return -1;
1697 }
1698#else
1699 int year, month, day, hour, minute,second,time_zone;
1700 if(strstr(time_str, "+")) {
1701 sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1702 } else if(strstr(time_str, "-")) {
1703 sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1704 } else {
1705 LOGE("Time format error:%s", time_str);
1706 return -1;
1707 }
1708
1709 // 1970+
1710 if(year < 70) { // 20xx
1711 tm_.tm_year = 2000 + year;
1712 } else { // 19xx
1713 tm_.tm_year = 1900 + year;
1714 }
1715 tm_.tm_mon = month - 1;
1716 tm_.tm_mday = day;
1717 tm_.tm_hour = hour;
1718 tm_.tm_min = minute;
1719 tm_.tm_sec = second;
1720 tm_.tm_isdst = 0;
1721#endif
1722
1723 time_t timeStamp = mktime(&tm_);
1724 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);
1725 LOGD("time = %ld,%x", timeStamp,timeStamp);
1726 *time_out = timeStamp;
1727
1728 return 0;
1729}
1730
1731/*
1732* Get time type.
1733* "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00"
1734*/
1735int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
1736{
1737 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1738 if(handle == NULL || time_str == NULL)
1739 {
1740 LOGE("ARG error.");
1741 return -1;
1742 }
1743 //printf("mbtk_net_time_get begin info_item_process\n");
b.liubaa41e12024-07-19 15:07:24 +08001744 if(info_item_process(handle, MBTK_INFO_ID_DEV_CELL_TIME_REQ, NULL, 0, buff) > 0) {
liubin281ac462023-07-19 14:22:54 +08001745 memcpy(time_str,buff,strlen(buff));
1746
1747 uint8 *temp = strstr(time_str, ",");
1748 if(temp) {
1749 *temp = ' '; // ',' -> ' '
1750
1751 temp = strstr(time_str, "+");
1752 if(temp == NULL) {
1753 temp = strstr(time_str, "-");
1754 }
1755
1756 if(temp) {
1757 // Copy +XX or -XX
1758 uint8 *last_ptr = temp + strlen(temp) + 1;
1759 while(last_ptr > temp) {
1760 *last_ptr = *(last_ptr - 1);
1761 last_ptr--;
1762 }
1763
1764 *last_ptr = ' ';
1765
1766 memcpy(temp + strlen(temp), "00", 2);
1767
1768 LOGD("%s -> %s", buff, time_str);
1769 return 0;
1770 } else {
1771 LOGE("Time error:%s",buff);
1772 return MBTK_INFO_ERR_TIME_FORMAT;
1773 }
1774 } else {
1775 LOGE("Time error:%s",buff);
1776 return MBTK_INFO_ERR_TIME_FORMAT;
1777 }
1778 } else {
1779 return handle->info_err;
1780 }
1781}
1782
1783/*
1784* Set time.
1785*
1786* time_type:
1787* 0: Cell time
1788* 1: NTP time
1789* 2: User time
1790* time_str: "YYYY-MM-DD HH:MM:SS"
1791*/
1792int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str)
1793{
1794 if(handle == NULL)
1795 {
1796 LOGE("ARG error.");
1797 return -1;
1798 }
1799 uint8 buffer[100] = {0};
1800 buffer[0] = (uint8)time_type;
1801 if(time_type == MBTK_TIME_TYPE_USER) {
1802 if(!str_empty(time_str)) {
1803 memcpy(buffer + sizeof(uint8), time_str, strlen(time_str));
1804 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1805 buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0;
1806 } else {
1807 return -1;
1808 }
1809 } else {
1810 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1811 buffer, sizeof(uint8), NULL) ? handle->info_err : 0;
1812 }
1813}
1814
1815/*
1816* Return sms cmgf.
1817*/
1818int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state)
1819{
1820 uint8 state;
1821 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) {
1822 LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state);
1823 *volte_state = state;
1824 return 0;
1825 } else {
1826 return handle->info_err;
1827 }
1828}
1829
1830/*
1831* Set sms cmgf.
1832*
1833* volte_state:
1834* 0 : PDU mode.
1835* 1 : text mode.
1836*
1837* Restarting takes effect after execution.
1838*/
1839int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode)
1840{
1841 printf("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8));
1842 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0;
1843}
1844
1845/*
1846* Set sms cmgs.
1847*
1848if PDU mode (+CMGF=0):
1849+CMGS=<length><CR>
1850PDU is given<ctrl-Z/ESC>
1851
1852if text mode (+CMGF=1):
1853+CMGS=<da>[,<toda>]<CR>
1854text is entered<ctrl-Z/ESC>
1855
1856* Restarting takes effect after execution.
1857*/
1858int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp)
1859{
1860 printf("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs));
1861// char req[20] = {0}
1862 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){
1863 printf("resp:%s\n", resp);
1864 return 0;
1865 }else{
1866 return handle->info_err;
1867 }
1868}
1869
1870/*
1871* Set sms cmgw.
1872*
1873if text mode (+CMGF=1):
1874+CMGW=<oa/da>[,<tooa/toda>[,<stat>]]
1875<CR>
1876text is entered<ctrl-Z/ESC>
1877if PDU mode (+CMGF=0):
1878+CMGW=<length>[,<stat>]<CR>PDU is
1879given<ctrl-Z/ESC>
1880
1881*/
1882
1883int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp)
1884{
1885 printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw));
1886 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){
1887 printf("resp:%s\n", resp);
1888 return 0;
1889 }else{
1890 return handle->info_err;
1891 }
1892}
1893
1894/*
1895* Set sms cmgd.
1896*
1897* +CMGD=<index>[,<delflag>]
1898*
1899* Restarting takes effect after execution.
1900*/
1901int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg)
1902{
1903 printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg));
1904 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0;
1905}
1906
1907/*
r.xiaoeb9dba42024-02-07 02:16:13 -08001908* Get sms cmgd.
1909*
1910* +CMGD: (XXX,XXX)(0-4)
1911*
1912* Restarting takes effect after execution.
1913*/
1914int mbtk_sms_cmgd_get(mbtk_info_handle_t* handle, char * cmdg)
1915{
1916 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, NULL, 0, cmdg) ? handle->info_err : 0;
1917}
1918
1919
1920/*
liubin281ac462023-07-19 14:22:54 +08001921* Set sms cmgl.
1922*
1923* AT+CMGL[=<stat>]
1924*
1925* Restarting takes effect after execution.
1926*/
1927int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp)
1928{
1929 printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl));
1930 char reg[5*1024] ={0};
1931 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){
1932 printf("len:%d , reg:%s\n", strlen(reg), reg);
1933 // memcpy(resp, reg, strlen(reg));
1934 return 0;
1935 }else {
1936 return handle->info_err;
1937 }
1938}
1939
1940/*
1941* Return sms csca.
1942*/
1943int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf)
1944{
1945 // char state;
1946 if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) {
1947 LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf);
1948 // *volte_state = state;
1949 return 0;
1950 } else {
1951 return handle->info_err;
1952 }
1953}
1954
1955/*
1956* Set sms csca.
1957*
1958* AT+CSCA=<number> [,<type>]
1959*
1960* Restarting takes effect after execution.
1961*/
1962int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca)
1963{
1964 printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca));
1965 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0;
1966}
1967
1968/*
1969* Set sms csmp.
1970*
1971* AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
1972*
1973* Restarting takes effect after execution.
1974*/
1975int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp)
1976{
1977 printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp));
1978 return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0;
1979}
1980
1981/*
1982* Set sms cscb.
1983*
1984* AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
1985*
1986* Restarting takes effect after execution.
1987*/
1988int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb)
1989{
1990 printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb));
1991 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0;
1992}
1993
1994/*
1995* Set sms cnmi.
1996*
1997at+cnmi=1,2
1998
1999OK
2000if sending fails:
2001+CMS ERROR: <err>
2002*/
2003int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle)
2004{
2005 printf("mbtk_sms_cnmi_set()------------start\n");
2006
2007 return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0;
2008}
2009
2010/*
2011* Set sms cmss.
2012*
2013+CMSS=<index>[,<da>[,<toda>]]
2014
2015if sending successful:
2016+CMSS: <mr>
2017OK
2018if sending fails:
2019+CMS ERROR: <err>
2020*/
2021int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp)
2022{
2023 printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss));
2024 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){
2025 printf("resp:%s\n", resp);
2026 return 0;
2027 }else{
2028 return handle->info_err;
2029 }
2030}
2031
2032/*
2033* Return sms cmgf.
2034*/
2035int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem)
2036{
2037 char req[128] = {0};
2038 if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) {
2039 LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req));
2040 memcpy(mem, req, strlen(req));
2041 return 0;
2042 } else {
2043 return handle->info_err;
2044 }
2045}
2046
2047
2048/*
2049* Set sms cpms.
2050*
2051* AT+CPMS=<mem1>[,<mem2>[,<mem3>]]
2052*
2053* Restarting takes effect after execution.
2054*/
2055int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response)
2056{
2057 printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem));
2058 char req[128] = {0};
2059 if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){
2060 memcpy(response, req, strlen(req));
2061 return 0;
2062 }
2063 else{
2064 return handle->info_err;
2065 }
2066}
2067
2068/*
2069* Set sms cm.
2070*
2071* +CMGR=<index>
2072
2073if PDU mode (+CMGF=0) ��command successful:
2074+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
2075OK
2076if text mode (+CMGF=1), command successful and SMS-DELIVER:
2077+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs
2078>, <sca>,<tosca>,<length>]<CR><LF><data>
2079OK
2080if text mode (+CMGF=1), command successful and SMS-SUBMIT:
2081+CMGR:
2082<stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>],
2083<sca>,<tosca>,<length>]<CR><LF><data>
2084OK
2085otherwise:
2086+CMS ERROR: <err>
2087*
2088* Restarting takes effect after execution.
2089*/
2090int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp)
2091{
2092 printf("mbtk_sms_cmgr_set() --------------index:%d",index);
2093 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){
2094 printf("resp:%s\n", resp);
2095 return 0;
2096 }else{
2097 return handle->info_err;
2098 }
2099}
2100
2101
2102/*
2103* Get sim state.
2104*/
2105int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state)
2106{
2107 uint8 state;
2108 if(handle == NULL || sim_state == NULL)
2109 {
2110 LOGE("ARG error.");
2111 return -1;
2112 }
2113 if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) {
2114 *sim_state = (mbtk_sim_state_enum)state;
2115 LOG("Sim state : %d", *sim_state);
2116 return 0;
2117 } else {
2118 return handle->info_err;
2119 }
2120}
2121
2122/*
2123* Get sim card type.
2124*/
2125int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type)
2126{
2127 uint8 state;
2128 if(handle == NULL || sim_card_type == NULL)
2129 {
2130 LOGE("ARG error.");
2131 return -1;
2132 }
2133 if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) {
2134 *sim_card_type = (mbtk_sim_card_type_enum)state;
2135 LOG("Sim sim_card_type : %d", *sim_card_type);
2136 return 0;
2137 } else {
2138 return handle->info_err;
2139 }
2140}
2141
2142/*
2143* Get system temperature.
2144*
2145* type[IN]:
2146* 0: Soc temperature.
2147* 1: RF temperature.
2148* temp[OUT]:
2149* temperature in celsius.
2150*/
r.xiao2102d762024-06-07 03:10:38 -07002151int mbtk_temp_get(mbtk_info_handle_t* handle, int type, mbtk_thermal_info_t* temp)
liubin281ac462023-07-19 14:22:54 +08002152{
2153 if(handle == NULL)
2154 {
2155 LOGE("ARG error.");
2156 return -1;
2157 }
r.xiao2102d762024-06-07 03:10:38 -07002158 if(type != 0 && type != 1)
liubin281ac462023-07-19 14:22:54 +08002159 {
2160 return -1;
2161 }
2162
2163 uint8 temp_type = (uint8)type;
r.xiao2102d762024-06-07 03:10:38 -07002164
2165 if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), temp) > 0) {
2166
2167 LOG("Temperature : %d", temp->ther);
liubin281ac462023-07-19 14:22:54 +08002168 return 0;
2169 } else {
2170 return handle->info_err;
2171 }
2172
2173 return 0;
2174}
2175
2176
2177/*
2178* Set sim power state.
2179* power:
2180* 0: Sim power off.
2181* 1: Sim power on.
2182*/
2183int mbtk_sim_power_set(int power)
2184{
2185 if(power != 0 && power != 1)
2186 {
2187 return -1;
2188 }
2189
2190 // /sys/devices/virtual/usim_event/usim0/send_event
2191 char cmd[100] = {0};
2192 sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
2193 system(cmd);
2194
2195 return 0;
2196}
2197
2198/*
2199* System power.
2200* type:
2201* 0: Reboot system.
2202* 1: Poweroff system.
2203* 2: Halt system.
2204*/
2205int mbtk_system_reboot(int type)
2206{
2207 if(type != 0 && type != 1 && type != 2)
2208 {
2209 return -1;
2210 }
2211
2212 switch(type) {
2213 case 0: {
2214 system("reboot");
2215 break;
2216 }
2217 case 1: {
2218 system("poweroff");
2219 break;
2220 }
2221 case 2: {
2222 system("halt");
2223 break;
2224 }
2225 default: {
2226 break;
2227 }
2228 }
2229
2230 return 0;
2231}
2232
2233/*
2234* set modem fun
2235*
2236*/
2237int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info)
2238{
2239 if(handle == NULL)
2240 {
2241 LOGE("ARG error.");
2242 return -1;
2243 }
2244 return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0;
2245}
2246
2247/*
2248* get modem fun
2249*
2250*/
2251int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun)
2252{
2253 uint8 state;
2254 if(handle == NULL || fun == NULL)
2255 {
2256 LOGE("ARG error.");
2257 return -1;
2258 }
2259 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) {
2260 LOG("modem type : %d", state);
2261 *fun = state;
2262 return 0;
2263 } else {
2264 return handle->info_err;
2265 }
2266}
2267
2268/*
2269* call_start
2270*
2271*/
2272int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number)
2273{
2274 if(handle == NULL)
2275 {
2276 LOGE("ARG error.");
2277 return -1;
2278 }
2279 if(str_empty(phone_number))
2280 return -1;
2281
2282 return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ,
2283 phone_number, strlen(phone_number), NULL) ? handle->info_err : 0;
2284}
2285/*
2286* Answer the phone call.
2287*
2288*/
2289int mbtk_call_answer(mbtk_info_handle_t* handle)
2290{
2291 return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2292}
2293
2294/*
2295* Hang up all call.
2296*
2297*/
2298int mbtk_call_hang(mbtk_info_handle_t* handle)
2299{
2300 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2301}
2302
2303/*
2304* Hang up a call.
2305*
2306*/
2307int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id)
2308{
2309 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0;
2310}
2311
2312/*
2313* Hang up waiting or background call.
2314*
2315*/
2316int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle)
2317{
2318 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2319}
2320
2321/*
2322* Hang up foreground resume background call.
2323*
2324*/
2325int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle)
2326{
2327 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2328}
2329
2330/*
2331* Get current call phone number.
2332*/
2333int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg)
2334{
2335 if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) {
2336 LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
2337 return 0;
2338 } else {
2339 return handle->info_err;
2340 }
2341}
2342
2343/*
2344* Return mute state.
2345*/
2346int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state)
2347{
2348 uint8 state;
2349 if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) {
2350 LOG("Mute State : %d", state);
2351 *mute_state = state;
2352 return 0;
2353 } else {
2354 return handle->info_err;
2355 }
2356}
2357
2358/*
2359* Set mute state.
2360*
2361* mute_state:
2362* 0 : of mute.
2363* 1 : on mute.
2364*
2365* Restarting takes effect after execution.
2366*/
2367int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state)
2368{
2369 return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0;
2370}
2371
2372/*
r.xiaoec113d12024-01-12 02:13:28 -08002373* Set wakeup state.
2374*
2375* wakeup_state:(0~31)
2376* 0 : means resume all
2377* 1~31 means suspend
2378* Control the active reporting of some platform modems to reduce wakeup
2379*/
2380
2381int mbtk_wakeup_state_set(mbtk_info_handle_t* handle, uint32 wakeup_state)
2382{
2383 return info_item_process(handle, MBTK_INFO_ID_WAKEUP_STA_REQ, (uint32*)&wakeup_state, sizeof(uint32), NULL) ? handle->info_err : 0;
2384}
2385
2386/*
2387* oos get.
2388*/
2389int mbtk_oos_get(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
2390{
2391 if(info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, NULL, 0, oos_info) > 0) {
2392 return 0;
2393 } else {
2394 return handle->info_err;
2395 }
2396}
2397
2398/*
2399* oos set .
2400*/
r.xiaocfd7c682024-01-22 03:59:46 -08002401int mbtk_oos_set(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
r.xiaoec113d12024-01-12 02:13:28 -08002402{
2403 if(handle == NULL)
2404 {
2405 LOGE("ARG error.");
2406 return -1;
2407 }
r.xiaoec113d12024-01-12 02:13:28 -08002408
r.xiaocfd7c682024-01-22 03:59:46 -08002409 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 -08002410}
2411
2412
2413/*
liubin281ac462023-07-19 14:22:54 +08002414* Set DTMF character.
2415*
2416*/
2417int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character)
2418{
2419 if(handle == NULL)
2420 {
2421 LOGE("ARG error.");
2422 return -1;
2423 }
2424 return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ,
2425 dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0;
2426}
2427
2428/*
wangyouqiang38e53362024-01-23 10:53:48 +08002429* Set net led.
2430*
2431*/
2432int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status)
2433{
2434 if(handle == NULL)
2435 {
2436 LOGE("ARG error.");
2437 return -1;
2438 }
2439
2440 char buff[3] = {0};
2441 if(type == MBTK_LED_TYPE_NET)
2442 {
2443 buff[0] = 0;
2444 }
2445 else
2446 {
2447 buff[0] = 1;
2448 }
2449
2450 if(status == MBTK_LED_STATUS_CLOSE)
2451 {
2452 buff[1] = 0;
2453 }
2454 else
2455 {
2456 buff[1] = 1;
2457 }
2458 return info_item_process(handle, MBTK_INFO_ID_LED_REQ, buff, 2, NULL) ? handle->info_err : 0;
2459}
2460
2461/*
liubin281ac462023-07-19 14:22:54 +08002462* Set pdp state change callback function.
2463*/
2464int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2465{
2466 if(handle == NULL)
2467 {
2468 LOGE("ARG error.");
2469 return -1;
2470 }
2471 if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) {
2472 return handle->info_err;
2473 } else {
2474 handle->pdp_state_cb = cb;
2475 return 0;
2476 }
2477}
2478
2479/*
2480* Set network state change callback function.
2481*/
2482int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2483{
2484 if(handle == NULL)
2485 {
2486 LOGE("ARG error.");
2487 return -1;
2488 }
b.liu27b91e42024-01-17 20:02:30 +08002489 if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) < 0) {
2490 return handle->info_err;
2491 } else {
liubin281ac462023-07-19 14:22:54 +08002492 handle->net_state_cb = cb;
2493 return 0;
liubin281ac462023-07-19 14:22:54 +08002494 }
2495}
2496
2497/*
2498* Set call state change callback function.
2499*/
2500int mbtk_call_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2501{
2502 if(handle == NULL)
2503 {
2504 LOGE("ARG error.");
2505 return -1;
2506 }
2507 if(info_item_process(handle, MBTK_INFO_ID_IND_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2508 return handle->info_err;
2509 } else {
2510 handle->call_state_cb = cb;
2511 return 0;
2512 }
2513}
2514
2515/*
2516* Set sms state change callback function.
2517*/
2518int mbtk_sms_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2519{
2520 if(handle == NULL)
2521 {
2522 LOGE("ARG error.");
2523 return -1;
2524 }
2525 if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) {
2526 return handle->info_err;
2527 } else {
2528 handle->sms_state_cb = cb;
2529 return 0;
2530 }
2531}
2532
2533/*
2534* Set radio state change callback function.
2535*/
2536int mbtk_radio_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2537{
2538 if(handle == NULL)
2539 {
2540 LOGE("ARG error.");
2541 return -1;
2542 }
2543 if(info_item_process(handle, MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) {
2544 return handle->info_err;
2545 } else {
2546 handle->radio_state_cb = cb;
2547 return 0;
2548 }
2549}
2550
2551/*
2552* Set sim state change callback function.
2553*/
2554int mbtk_sim_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2555{
2556 if(handle == NULL)
2557 {
2558 LOGE("ARG error.");
2559 return -1;
2560 }
2561 if(info_item_process(handle, MBTK_INFO_ID_IND_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) {
2562 return handle->info_err;
2563 } else {
2564 handle->sim_state_cb = cb;
2565 return 0;
2566 }
2567}
r.xiaofca7c472024-04-24 01:00:23 -07002568
2569/*
2570* Set signal state change callback function.
2571*/
2572int mbtk_signal_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2573{
2574 if(handle == NULL)
2575 {
2576 LOGE("ARG error.");
2577 return -1;
2578 }
2579 if(info_item_process(handle, MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2580 return handle->info_err;
2581 } else {
2582 handle->signal_state_cb = cb;
2583 return 0;
2584 }
2585}
2586