blob: b5fc96dadb37376024ee022ec57eef9f57146492 [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
l.yang5b0ff422024-10-29 19:33:35 -070020
21
liubin281ac462023-07-19 14:22:54 +080022#define EPOLL_LISTEN_MAX 100
23#define EPOLL_LISTEN_MAX 100
24
b.liuc41882f2024-10-23 17:54:44 +080025static mbtk_info_callback_func ril_server_state_cb = NULL;
26
l.yang5b0ff422024-10-29 19:33:35 -070027
liubin281ac462023-07-19 14:22:54 +080028#if 0
29struct
30{
31 uint8 operator[128];
32 uint8 operator[128];
33 uint8 mcc_mnc[10];
34} operator_mcc_mnc =
35{
36 {"China Mobile","CMCC","46000"},
37 {"China Unicom","CU","46001"},
38 {"China Mobile","CMCC","46002"},
39 {"China Telecom","CT","46003"},
40 {"China Mobile","CMCC","46004"},
41 {"China Telecom","CT","46005"},
42 {"China Unicom","CU","46006"},
43 {"China Mobile","CMCC","46007"},
44 {"China Mobile","CMCC","46008"},
45 {"China Unicom","CU","46009"},
46 {"China Telecom","CT","46011"},
47 {NULL, NULL, NULL}
48};
49#endif
50
51static int pack_process(mbtk_info_handle_t* handle, mbtk_info_pack_t* pack)
52{
53 mbtk_info_type_enum info_type = mbtk_info_type_get(pack->info_id);
54 LOG("Type : %s, ID : %s, Result : %s ,Length : %d", type2str(info_type),
55 id2str(pack->info_id),
56 err2str(pack->info_err),
57 pack->data_len);
58 if(0 && pack->data_len > 0)
59 {
60 log_hex("DATA", pack->data, pack->data_len);
61 }
62 // IND Message.
63 if(info_type == MBTK_INFO_TYPE_IND)
64 {
65 if(pack->data_len > 0 && pack->data != NULL) // IND message.
66 {
67 log_hex(id2str(pack->info_id), pack->data, pack->data_len);
68 switch(pack->info_id)
69 {
70 case MBTK_INFO_ID_IND_NET_STATE_CHANGE:
71 {
72 if(handle->net_state_cb)
73 handle->net_state_cb(pack->data, pack->data_len);
74 break;
75 }
76 case MBTK_INFO_ID_IND_CALL_STATE_CHANGE:
77 {
78 if(handle->call_state_cb)
79 handle->call_state_cb(pack->data, pack->data_len);
80 break;
81 }
82 case MBTK_INFO_ID_IND_SMS_STATE_CHANGE:
83 {
84 if(handle->sms_state_cb)
85 handle->sms_state_cb(pack->data, pack->data_len);
86 break;
87 }
88 case MBTK_INFO_ID_IND_RADIO_STATE_CHANGE:
89 {
90 if(handle->radio_state_cb)
91 handle->radio_state_cb(pack->data, pack->data_len);
92 break;
93 }
94 case MBTK_INFO_ID_IND_SIM_STATE_CHANGE:
95 {
96 if(handle->sim_state_cb)
97 handle->sim_state_cb(pack->data, pack->data_len);
98 break;
99 }
100 case MBTK_INFO_ID_IND_PDP_STATE_CHANGE:
101 {
102 if(handle->pdp_state_cb)
103 handle->pdp_state_cb(pack->data, pack->data_len);
104 break;
105 }
106 //mbtk wyq for server_ready_status add start
107 case MBTK_INFO_ID_IND_SERVER_STATE_CHANGE:
108 {
109 handle->server_ready_status = 1;
110 LOG("handshake message recv ok.");
111 break;
112 }
r.xiaofca7c472024-04-24 01:00:23 -0700113 //mbtk xr for signal_status add start
114 case MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE:
115 {
116 if(handle->signal_state_cb)
117 handle->signal_state_cb(pack->data, pack->data_len);
118 break;
119 }
120
liubin281ac462023-07-19 14:22:54 +0800121 //mbtk wyq for server_ready_status add end
122 default:
123 {
124 LOG("Unknown IND : %d", pack->info_id);
125 break;
126 }
127 }
128 }
129 else // Register IND response.
130 {
131 handle->info_err = pack->info_err;
132 if(pack->info_err == MBTK_INFO_ERR_SUCCESS)
133 {
134 LOG("IND %s register success.", id2str(pack->info_id));
135 }
136 else
137 {
138 LOG("IND %s register fail : %s", id2str(pack->info_id), err2str(pack->info_err));
139 }
140
141 if(handle->is_waitting) {
142 pthread_mutex_lock(&handle->mutex);
143 pthread_cond_signal(&handle->cond);
144 pthread_mutex_unlock(&handle->mutex);
145 }
146 }
147 }
148 else // Response Information.
149 {
150 handle->info_err = pack->info_err;
151
152 // Set data length.
153 // If data change,will change this lenght in mbtk_info_pack_data_get().
154 handle->data_len = pack->data_len;
155 // Copy data buffer,because it will be released.
156 if(handle->data && pack->data && pack->data_len > 0) {
157 memcpy(handle->data, pack->data, handle->data_len);
158 }
159
160 if(handle->is_waitting) {
161 pthread_mutex_lock(&handle->mutex);
162 pthread_cond_signal(&handle->cond);
163 pthread_mutex_unlock(&handle->mutex);
164 }
165
166
167#if 0
168 if(pack->info_err == MBTK_INFO_ERR_SUCCESS)
169 {
170 LOG("REQ %s success.", id2str(pack->info_id));
171#if 0
172 if(pack->data_len > 0)
173 {
174 log_hex("DATA", pack->data, pack->data_len);
175 }
176#endif
177 switch(pack->info_id)
178 {
179 case MBTK_INFO_ID_NET_AVAILABLE_RSP:
180 {
181 mbtk_net_array_info_t* nets = (mbtk_net_array_info_t*)mbtk_info_pack_data_get(pack);
182 if(nets)
183 {
184 mbtk_net_info_t *net = NULL;
185 list_first(nets->net_list);
186 while ((net = (mbtk_net_info_t*) list_next(nets->net_list)))
187 {
188 LOG("NET : %d, %d, %s", net->net_sel_mode, net->net_type, net->plmn);
189 }
190 list_free(nets->net_list);
191 free(nets);
192 }
193 else
194 {
195 LOG("mbtk_info_pack_data_get() fail.");
196 }
197
198 break;
199 }
200 case MBTK_INFO_ID_NET_SEL_MODE_RSP:
201 {
202 mbtk_net_info_t* net = (mbtk_net_info_t*)mbtk_info_pack_data_get(pack);
203 if(net)
204 {
205 LOG("NET : %d, %d, %d", net->net_sel_mode, net->net_type, net->plmn);
206 free(net);
207 }
208 else
209 {
210 LOG("mbtk_info_pack_data_get() fail.");
211 }
212
213 break;
214 }
215 case MBTK_INFO_ID_NET_BAND_RSP:
216 {
217 mbtk_band_info_t* band = (mbtk_band_info_t*)mbtk_info_pack_data_get(pack);
218 if(band) {
219 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref,
220 band->gsm_band,
221 band->umts_band,
222 band->tdlte_band,
223 band->fddlte_band);
224 } else {
225 LOG("mbtk_info_pack_data_get() fail.");
226 }
227
228 break;
229 }
230 default:
231 {
232 break;
233 }
234 }
235 }
236 else
237 {
238 LOG("REQ %s fail : %s", id2str(pack->info_id), err2str(pack->info_err));
239 }
240#endif
241 }
242 return 0;
243}
244
245
246static void* info_read_run(void* arg)
247{
248 int epoll_fd = epoll_create(5);
249 if(epoll_fd < 0)
250 {
251 LOG("epoll_create() fail[%d].", errno);
252 return NULL;
253 }
254 mbtk_info_handle_t* handle = (mbtk_info_handle_t*)arg;
255
256 uint32 event = EPOLLIN | EPOLLET;
257 struct epoll_event ev_cli, ev_exit;
258 ev_cli.data.fd = handle->client_fd;
259 ev_cli.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
260 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->client_fd,&ev_cli);
261
262 ev_exit.data.fd = handle->exit_fd[0];
263 ev_exit.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
264 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,handle->exit_fd[0],&ev_exit);
265
266 int nready = -1;
267 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
268 while(1)
269 {
270 nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
271 if(nready > 0)
272 {
273 int i;
274 for(i = 0; i < nready; i++)
275 {
b.liuc41882f2024-10-23 17:54:44 +0800276 LOGD("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
liubin281ac462023-07-19 14:22:54 +0800277 if(epoll_events[i].events & EPOLLHUP) // Closed by server.
278 {
b.liuc41882f2024-10-23 17:54:44 +0800279 LOGD("Closed by server.");
280 if(ril_server_state_cb) {
281 int state = 1;
282 ril_server_state_cb(&state, sizeof(int));
283 }
liubin281ac462023-07-19 14:22:54 +0800284 }
285 else if(epoll_events[i].events & EPOLLIN)
286 {
287 if(handle->client_fd == epoll_events[i].data.fd) // Server data arrive.
288 {
289 // Read and process every message.
290 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
291 mbtk_info_pack_t **pack = mbtk_info_pack_recv(handle->client_fd, false, &err);
292
293 // Parse packet error,send error response to client.
294 if(pack == NULL)
295 {
296 if(err != MBTK_INFO_ERR_SUCCESS)
297 {
298 LOG("RSP packet error[%s].", err2str(err));
299 }
300 }
301 else
302 {
303 mbtk_info_pack_t** pack_ptr = pack;
304 while(*pack_ptr)
305 {
306 pack_process(handle, *pack_ptr);
307 mbtk_info_pack_free(pack_ptr);
308 pack_ptr++;
309 }
310 free(pack);
311 }
312 }
313 else if(handle->exit_fd[0] == epoll_events[i].data.fd) //
314 {
315 char buff[100] = {0};
316 int len = read(handle->exit_fd[0], buff, 100);
317 if(len > 0) {
318 LOGI("CMD : %s", buff);
319 if(strcmp(buff, "EXIT") == 0) {
320 goto read_thread_exit;
321 } else {
322 LOGD("Unkonw cmd : %s", buff);
323 }
324 } else {
325 LOGE("sock_read() fail.");
326 }
327 }
328 else
329 {
330 LOG("Unknown socket : %d", epoll_events[i].data.fd);
331 }
332 }
333 else
334 {
335 LOG("Unknown event : %x", epoll_events[i].events);
336 }
337 }
338 }
339 else
340 {
341 LOG("epoll_wait() fail[%d].", errno);
342 }
343 }
344
345read_thread_exit:
346 LOGD("info_read thread exit.");
347 return NULL;
348}
349
350#if 0
351static int info_item_get(mbtk_info_handle_t* handle, mbtk_info_id_enum id, void* data)
352{
353 int data_len = 0;
354 if(data == NULL) {
355 LOG("data is null.");
356 return -1;
357 }
358 mbtk_info_pack_t* pack = mbtk_info_pack_creat(id);
359 if(pack == NULL) {
360 LOG("mbtk_info_item_get() fail.");
361 return -1;
362 }
363
364 mbtk_info_pack_send(handle->client_fd, pack);
365 mbtk_info_pack_free(&pack);
366 handle->data = data;
367
368 // Wait for server response.
369 pthread_mutex_lock(&handle->mutex);
370 handle->is_waitting = true;
371 pthread_cond_wait(&handle->cond, &handle->mutex);
372 handle->is_waitting = false;
373 pthread_mutex_unlock(&handle->mutex);
374
375 if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
376 {
377 LOG("REQ %s success.", id2str(id));
378 if(data && handle->data_len > 0) {
379 data_len = handle->data_len;
380 handle->data_len = 0;
381 handle->data = NULL;
382 }
383 return data_len;
384 } else {
385 LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
386 return -1;
387 }
388}
389#endif
390
391/*
392* Return recv data length.
393* -1 : fail.
394*/
395static int info_item_process(mbtk_info_handle_t *handle,
396 mbtk_info_id_enum id,
397 const void *send_buff,
398 int send_buff_len,
399 void *recv_buff)
400{
401 if(handle == NULL/* || ((send_buff == NULL || send_buff_len == 0) && recv_buff == NULL)*/) {
402 LOG("ARG error.");
403 return -1;
404 }
405
406 mbtk_info_pack_t* pack = mbtk_info_pack_creat(id);
407 if(pack == NULL) {
408 return -1;
409 }
410 if(send_buff && send_buff_len > 0) { // Set the data to be sent.
411 // log_hex("data", send_buff, send_buff_len);
412 // mbtk_info_pack_data_set(pack, data, data_len);
413 pack->data_len = (uint16)send_buff_len;
414 pack->data = (const uint8*)send_buff;
415 }
wangyouqiang962740a2023-11-02 19:27:22 +0800416
417 pthread_mutex_lock(&handle->send_mutex);
418 pthread_mutex_lock(&handle->mutex);
419 handle->is_waitting = true;
b.liu27b91e42024-01-17 20:02:30 +0800420
liubin281ac462023-07-19 14:22:54 +0800421 mbtk_info_pack_send(handle->client_fd, pack);
422 mbtk_info_pack_free(&pack);
423
424 if(recv_buff != NULL)
425 handle->data = recv_buff;
liubin281ac462023-07-19 14:22:54 +0800426 // Wait for server response.
liubin281ac462023-07-19 14:22:54 +0800427 pthread_cond_wait(&handle->cond, &handle->mutex);
428 handle->is_waitting = false;
429 pthread_mutex_unlock(&handle->mutex);
liubin281ac462023-07-19 14:22:54 +0800430 if(handle->info_err == MBTK_INFO_ERR_SUCCESS)
431 {
432 LOG("REQ %s success.", id2str(id));
433 int recv_len = 0;
434 if(recv_buff && handle->data_len > 0) {
435 recv_len = handle->data_len;
436 handle->data_len = 0;
437 handle->data = NULL;
438 }
wangyouqiang962740a2023-11-02 19:27:22 +0800439 pthread_mutex_unlock(&handle->send_mutex);
b.liubcf86c92024-08-19 19:48:28 +0800440
liubin281ac462023-07-19 14:22:54 +0800441 return recv_len;
442 } else {
443 LOG("REQ %s fail : %s", id2str(id), err2str(handle->info_err));
yq.wangb783cc32024-08-13 23:23:06 -0700444 pthread_mutex_unlock(&handle->send_mutex);
wangyouqiang80487e42024-05-24 15:06:20 +0800445
liubin281ac462023-07-19 14:22:54 +0800446 return -1;
447 }
448}
449
b.liubcf86c92024-08-19 19:48:28 +0800450void mbtk_ril_lib_info_print()
451{
452 MBTK_SOURCE_INFO_PRINT("mbtk_ril_lib");
453}
liubin281ac462023-07-19 14:22:54 +0800454
455mbtk_info_handle_t* mbtk_info_handle_get()
456{
457 mbtk_info_handle_t* handle = (mbtk_info_handle_t*)malloc(sizeof(mbtk_info_handle_t));
458 if(!handle)
459 {
460 LOG("malloc() error[%d].", errno);
461 return NULL;
462 }
463 memset(handle, 0, sizeof(mbtk_info_handle_t));
464 handle->client_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
465 if(handle->client_fd < 0)
466 {
467 LOG("socket() fail[%d].", errno);
468 goto error;
469 }
470
471 // Set O_NONBLOCK
472 int flags = fcntl(handle->client_fd, F_GETFL, 0);
473 if (flags < 0)
474 {
475 LOG("Get flags error:%d", errno);
476 goto error;
477 }
478 flags |= O_NONBLOCK;
479 if (fcntl(handle->client_fd, F_SETFL, flags) < 0)
480 {
481 LOG("Set flags error:%d", errno);
482 goto error;
483 }
484
485 struct sockaddr_un cli_addr;
486 memset(&cli_addr, 0, sizeof(cli_addr));
487 cli_addr.sun_family = AF_LOCAL;
488 strcpy(cli_addr.sun_path, SOCK_INFO_PATH);
489 if(connect(handle->client_fd, (struct sockaddr *)&cli_addr, sizeof(cli_addr)))
490 {
491 LOG("connect() fail[%d].", errno);
492 goto error;
493 }
494
495 if(pipe(handle->exit_fd)) {
496 LOG("pipe() fail[%d].", errno);
497 goto error;
498 }
499#if 0
500 pthread_attr_t thread_attr;
501 pthread_attr_init(&thread_attr);
502 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
503 {
504 LOG("pthread_attr_setdetachstate() fail.");
505 goto error;
506 }
507
508 if(pthread_create(&(handle->read_thread_id), &thread_attr, info_read_run, handle))
509 {
510 LOG("pthread_create() fail.");
511 goto error;
512 }
513 pthread_attr_destroy(&thread_attr);
514#else
515 if(pthread_create(&(handle->read_thread_id), NULL, info_read_run, handle))
516 {
517 LOG("pthread_create() fail.");
518 goto error;
519 }
520#endif
521
522 pthread_mutex_init(&handle->mutex, NULL);
wangyouqiang80487e42024-05-24 15:06:20 +0800523#ifndef MBTK_SG_SUPPORT
wangyouqiang962740a2023-11-02 19:27:22 +0800524 pthread_mutex_init(&handle->send_mutex, NULL);
wangyouqiang80487e42024-05-24 15:06:20 +0800525#endif
liubin281ac462023-07-19 14:22:54 +0800526 pthread_cond_init(&handle->cond, NULL);
527 handle->is_waitting = false;
528
529 //mbtk wyq for server_ready_status add start
530 int timeout = 5;//The wait server timeout by default
531 LOG("wait server handshake message--->.");
532 while(timeout)
533 {
534 if(handle->server_ready_status)
535 {
536 break;
537 }
538 else
539 {
540 sleep(1);
541 timeout--;
542 }
543 }
544
545 if(timeout <= 0)
546 {
547 if(handle->exit_fd[1] > 0)
548 {
549 write(handle->exit_fd[1], "EXIT", 4);
550 }
551 pthread_join(handle->read_thread_id,NULL);
552 LOG("mbtk_info_handle_get() server not ready.");
553 goto error;
554 }
555 else
556 {
557 LOG("mbtk_info_handle_get() server ready ok.");
558 }
559 //mbtk wyq for server_ready_status add end
560 return handle;
561error:
562 if(handle)
563 {
564 if(handle->client_fd > 0)
565 {
566 close(handle->client_fd);
567 }
568 if(handle->exit_fd[0] > 0) {
569 close(handle->exit_fd[0]);
570 }
571 if(handle->exit_fd[1] > 0) {
572 close(handle->exit_fd[1]);
573 }
574 free(handle);
575 handle = NULL;
576 }
577
578 return NULL;
579}
580
581int mbtk_info_handle_free(mbtk_info_handle_t** handle)
582{
583 if(handle == NULL || *handle == NULL)
584 {
585 LOG("Handle is NULL.");
586 return -1;
587 }
588
589 if((*handle)->exit_fd[1] > 0) {
590 write((*handle)->exit_fd[1], "EXIT", 4);
591 }
592
593 // Wait read_thread exit.
594 pthread_join((*handle)->read_thread_id,NULL);
595
596 if((*handle)->exit_fd[0] > 0) {
597 close((*handle)->exit_fd[0]);
598 (*handle)->exit_fd[0] = -1;
599 }
600
601 if((*handle)->exit_fd[1] > 0) {
602 close((*handle)->exit_fd[1]);
603 (*handle)->exit_fd[1] = -1;
604 }
605
606 if((*handle)->client_fd > 0)
607 {
608 close((*handle)->client_fd);
609 (*handle)->client_fd = -1;
610 }
611 free(*handle);
612 *handle = NULL;
613 return 0;
614}
615
616/*
617* Get platform version.
618*/
619int mbtk_version_get(mbtk_info_handle_t* handle, void *version)
620{
621 if(handle == NULL || version == NULL)
622 {
623 LOGE("ARG error.");
624 return -1;
625 }
626
627 if(info_item_process(handle, MBTK_INFO_ID_DEV_VERSION_REQ, NULL, 0, version) > 0) {
628 LOG("Version : %s", version);
629 return 0;
630 } else {
631 return handle->info_err;
632 }
633}
634
635/*
636* Get platform version.
637*/
638int mbtk_model_get(mbtk_info_handle_t* handle, void *model)
639{
640 if(handle == NULL || model == NULL)
641 {
642 LOGE("ARG error.");
643 return -1;
644 }
645
646 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEL_REQ, NULL, 0, model) > 0) {
647 LOG("Version : %s", model);
648 return 0;
649 } else {
650 return handle->info_err;
651 }
652}
653
654/*
655* Get platform IMEI.
656*/
657int mbtk_imei_get(mbtk_info_handle_t* handle, void *imei)
658{
659 if(handle == NULL || imei == NULL)
660 {
661 LOGE("ARG error.");
662 return -1;
663 }
664 if(info_item_process(handle, MBTK_INFO_ID_DEV_IMEI_REQ, NULL, 0, imei) > 0) {
665 LOG("IMEI : %s", imei);
666 return 0;
667 } else {
668 return handle->info_err;
669 }
670}
671
672/*
673* Get platform SN.
674*/
675int mbtk_sn_get(mbtk_info_handle_t* handle, void *sn)
676{
677 if(handle == NULL || sn == NULL)
678 {
679 LOGE("ARG error.");
680 return -1;
681 }
682 if(info_item_process(handle, MBTK_INFO_ID_DEV_SN_REQ, NULL, 0, sn) > 0) {
683 LOG("SN : %s", sn);
684 return 0;
685 } else {
686 return handle->info_err;
687 }
688}
689
690/*
691* Get platform MEID.
692*/
693int mbtk_meid_get(mbtk_info_handle_t* handle, void *meid)
694{
695 if(handle == NULL || meid == NULL)
696 {
697 LOGE("ARG error.");
698 return -1;
699 }
700 if(info_item_process(handle, MBTK_INFO_ID_DEV_MEID_REQ, NULL, 0, meid) > 0) {
701 LOG("MEID : %s", meid);
702 return 0;
703 } else {
704 return handle->info_err;
705 }
706}
707
708/*
709* Return VoLTE state.
710*/
711int mbtk_volte_state_get(mbtk_info_handle_t* handle, int *volte_state)
712{
713 uint8 state;
714 if(handle == NULL || volte_state == NULL)
715 {
716 LOGE("ARG error.");
717 return -1;
718 }
719 if(info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, NULL, 0, &state) > 0) {
720 LOG("VoLTE State : %d", state);
721 *volte_state = state;
722 return 0;
723 } else {
724 return handle->info_err;
725 }
726}
727
728/*
729* Set VoLTE state.
730*
731* volte_state:
732* 0 : Close VoLTE.
733* 1 : Open VoLTE.
734*
735* Restarting takes effect after execution.
736*/
737int mbtk_volte_state_set(mbtk_info_handle_t* handle, int volte_state)
738{
739 if(handle == NULL)
740 {
741 LOGE("ARG error.");
742 return -1;
743 }
744 return info_item_process(handle, MBTK_INFO_ID_DEV_VOLTE_REQ, (uint8*)&volte_state, sizeof(uint8), NULL) ? handle->info_err : 0;
745}
746
747/*
748* Get platform IMSI.
749*/
750int mbtk_imsi_get(mbtk_info_handle_t* handle, void *imsi)
751{
752 if(handle == NULL || imsi == NULL)
753 {
754 LOGE("ARG error.");
755 return -1;
756 }
757 if(info_item_process(handle, MBTK_INFO_ID_SIM_IMSI_REQ, NULL, 0, imsi) > 0) {
758 LOG("IMSI : %s", imsi);
759 return 0;
760 } else {
761 return handle->info_err;
762 }
763}
764
765/*
766* Get platform ICCID.
767*/
768int mbtk_iccid_get(mbtk_info_handle_t* handle, void *iccid)
769{
770 if(handle == NULL || iccid == NULL)
771 {
772 LOGE("ARG error.");
773 return -1;
774 }
775 if(info_item_process(handle, MBTK_INFO_ID_SIM_ICCID_REQ, NULL, 0, iccid) > 0) {
776 LOG("ICCID : %s", iccid);
777 return 0;
778 } else {
779 return handle->info_err;
780 }
781}
782
783/*
784* Get current phone number.
785*/
786int mbtk_phone_number_get(mbtk_info_handle_t* handle, void *phone_number)
787{
788 if(handle == NULL || phone_number == NULL)
789 {
790 LOGE("ARG error.");
791 return -1;
792 }
793 if(info_item_process(handle, MBTK_INFO_ID_SIM_PN_REQ, NULL, 0, phone_number) > 0) {
794 LOG("Phone Number : %s", phone_number);
795 return 0;
796 } else {
797 return handle->info_err;
798 }
799}
800
801/*
802* Get PIN’s number of remaining retry
803*/
804int mbtk_pin_last_num_get(mbtk_info_handle_t* handle, mbtk_pin_puk_last_times *last_times)
805{
806 if(handle == NULL || last_times == NULL)
807 {
808 LOGE("ARG error.");
809 return -1;
810 }
811 if(info_item_process(handle, MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ, NULL, 0, last_times) > 0) {
812 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);
813 return 0;
814 } else {
815 return handle->info_err;
816 }
817}
818
819/*
820* emable PIN
821*/
822int mbtk_enable_pin(mbtk_info_handle_t* handle, mbtk_enable_pin_info *pin)
823{
824 if(handle == NULL)
825 {
826 LOGE("ARG error.");
827 return -1;
828 }
829 if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, pin, sizeof(mbtk_enable_pin_info), NULL) >= 0) {
830 LOG("pin Number : %s", pin->pin_value);
831 return 0;
832 } else {
833 return handle->info_err;
834 }
835
836}
837
838/*
yq.wang586a0df2024-10-24 20:10:37 -0700839* GET PIN STATE
840*/
841int mbtk_get_pin_state(mbtk_info_handle_t* handle, mbtk_pin_state_enum *pin_state)
842{
843 if(handle == NULL)
844 {
845 LOGE("ARG error.");
846 return -1;
847 }
848 if(info_item_process(handle, MBTK_INFO_ID_SIM_ENABLE_PIN_REQ, NULL, 0, pin_state) >= 0) {
849 LOGD("pin state: %d", *pin_state);
850 return 0;
851 } else {
852 return handle->info_err;
853 }
854
855}
856
857
858/*
liubin281ac462023-07-19 14:22:54 +0800859* Verify PIN
860*/
861int mbtk_verify_pin(mbtk_info_handle_t* handle, char *pin)
862{
863 if(handle == NULL)
864 {
865 LOGE("ARG error.");
866 return -1;
867 }
868 if(info_item_process(handle, MBTK_INFO_ID_SIM_PIN_REQ, pin, strlen(pin), NULL) >= 0) {
869 LOG("pin Number : %s", pin);
870 return 0;
871 } else {
872 return handle->info_err;
873 }
874
875}
876
877/*
878* Verify PIN
879*/
880int mbtk_change_pin(mbtk_info_handle_t* handle, mbtk_change_pin_info *pin)
881{
882 if(handle == NULL)
883 {
884 LOGE("ARG error.");
885 return -1;
886 }
887 if(info_item_process(handle, MBTK_INFO_ID_SIM_CHANGE_PIN_REQ, pin, sizeof(mbtk_change_pin_info), NULL) >= 0) {
888 LOG("Change PIN : %s -> %s", pin->old_pin_value, pin->new_pin_value);
889 return 0;
890 } else {
891 return handle->info_err;
892 }
893}
894
895/*
896* unblock_pin
897*/
898int mbtk_unlock_pin(mbtk_info_handle_t* handle, mbtk_unlock_pin_info *pin)
899{
900 if(handle == NULL)
901 {
902 LOGE("ARG error.");
903 return -1;
904 }
905 if(info_item_process(handle, MBTK_INFO_ID_SIM_PUK_REQ, pin, sizeof(mbtk_unlock_pin_info), NULL) >= 0) {
906 LOG("Unlock : %s , %s", pin->pin_value , pin->puk_value);
907 return 0;
908 } else {
909 return handle->info_err;
910 }
911}
912
913/*
914* Get plmn list
915*/
916int mbtk_get_plmn_list(mbtk_info_handle_t* handle, mbtk_plmn_info *pin)
917{
918 if(handle == NULL)
919 {
920 LOGE("ARG error.");
921 return -1;
922 }
923 if(info_item_process(handle, MBTK_INFO_ID_SIM_PLMN_REQ, NULL, 0, pin) >= 0) {
924 //LOG("pin Number : %s", pin);
925 return 0;
926 } else {
927 return handle->info_err;
928 }
929}
930
931
932/*
933* Get available network.
934*/
935int mbtk_available_net_get(mbtk_info_handle_t* handle, list_node_t **net_list)
936{
937 if(handle == NULL)
938 {
939 LOGE("ARG error.");
940 return -1;
941 }
942 *net_list = list_create(NULL);
943 if(*net_list == NULL)
944 {
945 LOG("list_create() fail.");
946 return MBTK_INFO_ERR_MEMORY;
947 }
948
949 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
950 int buff_len;
951 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_AVAILABLE_REQ, NULL, 0, buff)) > 0) {
952 int i = 0;
953 while (i < buff_len / sizeof(mbtk_net_info_t))
954 {
955 mbtk_net_info_t* net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t));
956 if(net == NULL)
957 {
958 LOG("malloc() fail.");
959 list_free(*net_list);
960 return MBTK_INFO_ERR_MEMORY;
961 }
962 memcpy(net, buff + i * sizeof(mbtk_net_info_t), sizeof(mbtk_net_info_t));
963 list_add(*net_list, net);
964
965 LOG("NET-%d: %d, %d, %d, %d", i + 1, net->net_sel_mode, net->net_type, net->net_state, net->plmn);
966 i++;
967 }
968
969 return 0;
970 } else {
971 list_free(*net_list);
972 return handle->info_err;
973 }
974}
975
976/*
977* Set network select mode. (+COPS=...)
978*/
979int mbtk_net_sel_mode_set(mbtk_info_handle_t* handle, const mbtk_net_info_t *net)
980{
981 if(handle == NULL || net == NULL)
982 {
983 LOGE("ARG error.");
984 return -1;
985 }
986 return info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, net, sizeof(mbtk_net_info_t), NULL) ? handle->info_err : 0;
987}
988
989/*
990* Get network select mode. (+COPS?)
991*/
992int mbtk_net_sel_mode_get(mbtk_info_handle_t* handle, mbtk_net_info_t *net)
993{
994 if(handle == NULL || net == NULL)
995 {
996 LOGE("ARG error.");
997 return -1;
998 }
999 if(info_item_process(handle, MBTK_INFO_ID_NET_SEL_MODE_REQ, NULL, 0, net) > 0) {
1000 LOG("NET : %d, %d, %d, %d", net->net_sel_mode, net->net_type, net->net_state, net->plmn);
1001 return 0;
1002 } else {
1003 return handle->info_err;
1004 }
1005}
1006
1007/*
1008* Get platform support bands.
1009*/
1010int mbtk_support_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
1011{
1012 uint8 type = 0; // Get support bands.
1013 if(handle == NULL || band == NULL)
1014 {
1015 LOGE("ARG error.");
1016 return -1;
1017 }
1018 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
1019 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
1020 return 0;
1021 } else {
1022 return handle->info_err;
1023 }
1024}
1025
1026/*
1027* Get platform current bands.
1028*/
1029int mbtk_current_band_get(mbtk_info_handle_t* handle, mbtk_band_info_t *band)
1030{
1031 uint8 type = 1; // Get current bands.
1032 if(handle == NULL || band == NULL)
1033 {
1034 LOGE("ARG error.");
1035 return -1;
1036 }
1037 if(info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, &type, sizeof(uint8), band) > 0) {
1038 LOG("BAND : %d, %d, %d, %d, %d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
1039 return 0;
1040 } else {
1041 return handle->info_err;
1042 }
1043}
1044
1045/*
1046* Set platform current bands.
1047*/
1048int mbtk_current_band_set(mbtk_info_handle_t* handle, const mbtk_band_info_t *band)
1049{
1050 if(handle == NULL || band == NULL)
1051 {
1052 LOGE("ARG error.");
1053 return -1;
1054 }
1055 return info_item_process(handle, MBTK_INFO_ID_NET_BAND_REQ, band, sizeof(mbtk_band_info_t), NULL) ? handle->info_err : 0;
1056}
1057
1058/*
1059* Get current cell infomation.
1060*/
1061int mbtk_cell_get(mbtk_info_handle_t* handle, mbtk_cell_type_enum *type, list_node_t **cell_list)
1062{
1063 if(handle == NULL)
1064 {
1065 LOGE("ARG error.");
1066 return -1;
1067 }
1068 *cell_list = list_create(NULL);
1069 if(*cell_list == NULL)
1070 {
1071 LOG("list_create() fail.");
1072 return MBTK_INFO_ERR_MEMORY;
1073 }
1074
1075 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1076 int buff_len;
1077 if((buff_len = info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, NULL, 0, buff)) > 0) {
1078 int i = 0;
1079 *type = buff[0]; // Set network type.
1080 while (i < (buff_len - sizeof(uint8)) / sizeof(mbtk_cell_info_t))
1081 {
1082 mbtk_cell_info_t* cell = (mbtk_cell_info_t*)malloc(sizeof(mbtk_cell_info_t));
1083 if(cell == NULL)
1084 {
1085 LOG("malloc() fail.");
1086 list_free(*cell_list);
1087 return MBTK_INFO_ERR_MEMORY;
1088 }
1089 memcpy(cell, buff + sizeof(uint8) + i * sizeof(mbtk_cell_info_t), sizeof(mbtk_cell_info_t));
1090 list_add(*cell_list, cell);
1091
1092 // LOG("Cell-%d: %d, %d, %d, %d, %d", i + 1, cell->value1, cell->value2, cell->value3, cell->value4, cell->value5);
1093 i++;
1094 }
1095
1096 return 0;
1097 } else {
1098 list_free(*cell_list);
1099 return handle->info_err;
1100 }
1101}
1102/*
1103* Set cell info.
1104*
1105* at*CELL=<mode>,<act>,< band>,<freq>,<cellId>
1106* at*cell=2,3,,40936,429 //
1107* at*cell=0 //
1108*
1109* Restarting takes effect after execution.
1110*/
1111int mbtk_cell_set(mbtk_info_handle_t* handle, char * info, char* response)
1112{
1113 printf("mbtk_cell_set() info:%s, len:%d",info, strlen(info));
1114 char req[128] = {0};
1115 if( info_item_process(handle, MBTK_INFO_ID_NET_CELL_REQ, info, strlen(info), req) > 0){
1116 memcpy(response, req, strlen(req));
1117 return 0;
1118 }
1119 else{
1120 return 0;
1121 // return handle->info_err;
1122 }
1123}
1124
1125/*
1126* Get all APN informations.
1127*/
1128int mbtk_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_apn_info_t apns[])
1129{
1130 int len;
1131 if(handle == NULL || apn_num == NULL || apns == NULL)
1132 {
1133 LOGE("ARG error.");
1134 return -1;
1135 }
1136 uint8 data[SOCK_MSG_LEN_MAX];
1137 if((len = info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, NULL, 0, data)) > 0) {
1138 /*
1139 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
1140 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1141 */
1142 uint8* ptr = data;
1143 if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
1144 *apn_num = 0;
1145 LOGE("APN array size to not enough.");
1146 return -1;
1147 }
1148 *apn_num = *ptr++;
1149 LOG("APN Number : %d", *apn_num);
1150 int i = 0;
1151 while(i < *apn_num) {
1152 memset(&(apns[i]), 0 ,sizeof(mbtk_apn_info_t));
1153 apns[i].cid = *ptr++;
1154 apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
1155
1156 // apn
1157 len = byte_2_uint16(ptr, false);
1158 ptr += sizeof(uint16);
1159 if(len > 0) { // Has APN
1160 memcpy(apns[i].apn, ptr, len);
1161 ptr += len;
1162 }
1163 // user
1164 len = byte_2_uint16(ptr, false);
1165 ptr += sizeof(uint16);
1166 if(len > 0) { // Has APN
1167 memcpy(apns[i].user, ptr, len);
1168 ptr += len;
1169 }
1170
1171 // pass
1172 len = byte_2_uint16(ptr, false);
1173 ptr += sizeof(uint16);
1174 if(len > 0) { // Has APN
1175 memcpy(apns[i].pass, ptr, len);
1176 ptr += len;
1177 }
1178 // auth
1179 len = byte_2_uint16(ptr, false);
1180 ptr += sizeof(uint16);
1181 if(len > 0) { // Has APN
1182 memcpy(apns[i].auth, ptr, len);
1183 ptr += len;
1184 }
1185
1186 i++;
1187 }
1188 return 0;
1189 } else {
1190 return handle->info_err;
1191 }
1192}
1193
1194/*
wangyouqiang80487e42024-05-24 15:06:20 +08001195* Get all APN informations.
1196*/
1197int mbtk_qser_apn_get(mbtk_info_handle_t* handle, int *apn_num, mbtk_qser_apn_info_s apns[])
1198{
1199 int len;
1200 if(handle == NULL || apn_num == NULL || apns == NULL)
1201 {
1202 LOGE("ARG error.");
1203 return -1;
1204 }
1205 uint8 data[SOCK_MSG_LEN_MAX];
1206 if((len = info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, NULL, 0, data)) > 0) {
1207 /*
1208 <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>...
1209 <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>
1210 */
1211 uint8* ptr = data;
1212 if(apn_num == NULL || apns == NULL || *apn_num < *ptr) {
1213 *apn_num = 0;
1214 LOGE("APN array size to not enough.");
1215 return -1;
1216 }
1217 *apn_num = *ptr++;
1218 LOGD("APN Number : %d", *apn_num);
1219 int i = 0;
1220 while(i < *apn_num) {
1221 memset(&(apns[i]), 0x0 ,sizeof(mbtk_qser_apn_info_s));
1222 apns[i].cid = *ptr++;
1223 apns[i].ip_type = (mbtk_ip_type_enum)(*ptr++);
1224
1225 // apn
1226 len = byte_2_uint16(ptr, false);
1227 ptr += sizeof(uint16);
1228 if(len > 0) { // Has APN
1229 memcpy(apns[i].apn_name, ptr, len);
1230 ptr += len;
1231 }
1232 // user
1233 len = byte_2_uint16(ptr, false);
1234 ptr += sizeof(uint16);
1235 if(len > 0) { // Has APN
1236 memcpy(apns[i].user_name, ptr, len);
1237 ptr += len;
1238 }
1239
1240 // pass
1241 len = byte_2_uint16(ptr, false);
1242 ptr += sizeof(uint16);
1243 if(len > 0) { // Has APN
1244 memcpy(apns[i].user_pass, ptr, len);
1245 ptr += len;
1246 }
1247 // auth
1248 apns[i].auth_proto = (mbtk_apn_auth_proto_enum)(*ptr++);
1249
1250 //apn_type
1251 len = byte_2_uint16(ptr, false);
1252 ptr += sizeof(uint16);
1253 if(len > 0) { // Has APN
1254 memcpy(apns[i].apn_type, ptr, len);
1255 ptr += len;
1256 }
1257
1258 i++;
1259 }
b.liubcf86c92024-08-19 19:48:28 +08001260 }
wangyouqiang80487e42024-05-24 15:06:20 +08001261 else if(len == 0)
1262 {
1263 LOGD("get data len : 0.");
1264 *apn_num = 0;
1265 return 0;
1266 }
1267 else
1268 {
1269 return handle->info_err;
1270 }
1271
1272 return 0;
1273}
1274
1275/*
1276* qser Set current APN informations.
1277*/
1278int mbtk_qser_apn_set(mbtk_info_handle_t* handle, mbtk_qser_apn_info_s *apninfo, unsigned char *cid)
1279{
1280 if(handle == NULL)
1281 {
1282 LOGE("ARG error.");
1283 return -1;
1284 }
b.liubcf86c92024-08-19 19:48:28 +08001285
wangyouqiang80487e42024-05-24 15:06:20 +08001286 uint8 data[SOCK_MSG_LEN_MAX];
1287 memset(data, 0, SOCK_MSG_LEN_MAX);
1288 // cid : 2 - 7
1289 if(apninfo->req_type != MBTK_APN_REQ_TYPE_ADD && (apninfo->cid < MBTK_APN_CID_MIN || apninfo->cid > MBTK_APN_CID_MAX)) {
1290 LOGE("CID error.");
1291 return -1;
1292 }
1293
1294 uint8* ptr = data;
1295 // <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]>
1296 *ptr++ = (uint8)apninfo->cid;
1297 *ptr++ = (uint8)apninfo->ip_type;
1298 *ptr++ = (uint8)apninfo->req_type;
1299 *ptr++ = (uint8)apninfo->auth_proto;
1300 if(str_empty(apninfo->apn_name)) {
1301 uint16_2_byte((uint16)0, ptr, false);
1302 ptr += sizeof(uint16);
1303 } else {
1304 uint16_2_byte((uint16)strlen((char *)apninfo->apn_name), ptr, false);
1305 ptr += sizeof(uint16);
1306 memcpy(ptr, apninfo->apn_name, strlen((char *)apninfo->apn_name));
1307 ptr += strlen((char *)apninfo->apn_name);
1308 }
1309 if(str_empty(apninfo->user_name)) {
1310 uint16_2_byte((uint16)0, ptr, false);
1311 ptr += sizeof(uint16);
1312 } else {
1313 uint16_2_byte((uint16)strlen((char *)apninfo->user_name), ptr, false);
1314 ptr += sizeof(uint16);
1315 memcpy(ptr, apninfo->user_name, strlen((char *)apninfo->user_name));
1316 ptr += strlen((char *)apninfo->user_name);
1317 }
1318
1319 if(str_empty(apninfo->user_pass)) {
1320 uint16_2_byte((uint16)0, ptr, false);
1321 ptr += sizeof(uint16);
1322 } else {
1323 uint16_2_byte((uint16)strlen((char *)apninfo->user_pass), ptr, false);
1324 ptr += sizeof(uint16);
1325 memcpy(ptr, apninfo->user_pass, strlen((char *)apninfo->user_pass));
1326 ptr += strlen((char *)apninfo->user_pass);
1327 }
1328
1329 if(str_empty(apninfo->apn_type)) {
1330 uint16_2_byte((uint16)0, ptr, false);
1331 ptr += sizeof(uint16);
1332 }
1333 else
1334 {
1335 uint16_2_byte((uint16)strlen((char *)apninfo->apn_type), ptr, false);
1336 ptr += sizeof(uint16);
1337 memcpy(ptr, apninfo->apn_type, strlen((char *)apninfo->apn_type));
1338 ptr += strlen((char *)apninfo->apn_type);
1339 }
1340
1341 if(info_item_process(handle, MBTK_INFO_ID_NET_QSER_APN_REQ, data, ptr - data, (void *)cid) < 0)
1342 {
1343 return handle->info_err;
1344 }
1345
1346 return 0;
1347}
1348
1349/*
liubin281ac462023-07-19 14:22:54 +08001350* Set current APN informations.
1351*/
1352int mbtk_apn_set(mbtk_info_handle_t* handle, int cid, mbtk_ip_type_enum ip_type, const void* apn_name,
1353 const void *user_name, const void *user_pass, const void *auth)
1354{
1355 if(handle == NULL)
1356 {
1357 LOGE("ARG error.");
1358 return -1;
1359 }
1360 uint8 data[SOCK_MSG_LEN_MAX];
1361 memset(data, 0, SOCK_MSG_LEN_MAX);
1362 // cid : 2 - 7
1363 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1364 LOGE("CID error.");
1365 return -1;
1366 }
1367 uint8* ptr = data;
1368 // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1369 *ptr++ = (uint8)cid;
1370 *ptr++ = (uint8)ip_type;
1371 if(str_empty(apn_name)) {
1372 uint16_2_byte((uint16)0, ptr, false);
1373 ptr += sizeof(uint16);
1374 } else {
1375 uint16_2_byte((uint16)strlen(apn_name), ptr, false);
1376 ptr += sizeof(uint16);
1377 memcpy(ptr, apn_name, strlen(apn_name));
1378 ptr += strlen(apn_name);
1379 }
1380 if(str_empty(user_name)) {
1381 uint16_2_byte((uint16)0, ptr, false);
1382 ptr += sizeof(uint16);
1383 } else {
1384 uint16_2_byte((uint16)strlen(user_name), ptr, false);
1385 ptr += sizeof(uint16);
1386 memcpy(ptr, user_name, strlen(user_name));
1387 ptr += strlen(user_name);
1388 }
1389
1390 if(str_empty(user_pass)) {
1391 uint16_2_byte((uint16)0, ptr, false);
1392 ptr += sizeof(uint16);
1393 } else {
1394 uint16_2_byte((uint16)strlen(user_pass), ptr, false);
1395 ptr += sizeof(uint16);
1396 memcpy(ptr, user_pass, strlen(user_pass));
1397 ptr += strlen(user_pass);
1398 }
1399
1400 if(str_empty(auth)) {
1401 uint16_2_byte((uint16)0, ptr, false);
1402 ptr += sizeof(uint16);
1403 } else {
1404 uint16_2_byte((uint16)strlen(auth), ptr, false);
1405 ptr += sizeof(uint16);
1406 memcpy(ptr, auth, strlen(auth));
1407 ptr += strlen(auth);
1408 }
1409
1410 return info_item_process(handle, MBTK_INFO_ID_NET_APN_REQ, data, ptr - data, NULL) ? handle->info_err : 0;
1411}
1412
liuyang0e49d9a2024-04-23 21:04:54 +08001413int mbtk_apn_del(mbtk_info_handle_t* handle, unsigned char profile_idx)
1414{
liuyang0e49d9a2024-04-23 21:04:54 +08001415 if(handle == NULL)
1416 {
1417 LOGE("ARG error.");
1418 return -1;
1419 }
liuyang1cefd852024-04-24 18:30:53 +08001420
1421 profile_idx++;
b.liubcf86c92024-08-19 19:48:28 +08001422 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 +08001423 {
liuyang1cefd852024-04-24 18:30:53 +08001424 LOG("profile_idx Number : %d", profile_idx);
liuyang0e49d9a2024-04-23 21:04:54 +08001425 return 0;
b.liubcf86c92024-08-19 19:48:28 +08001426 }
1427 else
liuyang0e49d9a2024-04-23 21:04:54 +08001428 {
1429 return handle->info_err;
1430 }
1431
1432}
1433
liubin281ac462023-07-19 14:22:54 +08001434/*
1435* Start data call.
1436*/
1437int mbtk_data_call_start(mbtk_info_handle_t* handle, int cid, int auto_conn_interval, bool boot_conn, int timeout)
1438{
1439 uint8 data[10];
1440 if(handle == NULL)
1441 {
1442 LOGE("ARG error.");
1443 return -1;
1444 }
1445 memset(data, 0, 10);
1446 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1447 LOGE("CID error.");
1448 return -1;
1449 }
1450 uint8* ptr = data;
1451 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
1452 call_type : mbtk_data_call_type_enum
1453 cid : 2 - 7
1454 timeout : second
1455 */
1456 *ptr++ = (uint8)MBTK_DATA_CALL_START;
1457 *ptr++ = (uint8)cid;
1458 *ptr++ = (uint8)(auto_conn_interval > 0 ? auto_conn_interval : 0); // 拨号失败后重拨间隔(s)
1459 *ptr++ = (uint8)(boot_conn ? 1 : 0); // 开机自动拨号
1460 if(timeout <= 0) {
1461 *ptr++ = (uint8)MBTK_DATA_CALL_TIMEOUT_DEFAULT;
1462 } else {
1463 *ptr++ = (uint8)timeout;
1464 }
1465
1466 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 5, NULL) ? handle->info_err : 0;
1467}
1468
1469/*
1470* Stop data call.
1471*/
1472int mbtk_data_call_stop(mbtk_info_handle_t* handle, int cid, int timeout)
1473{
1474 uint8 data[10];
1475 if(handle == NULL)
1476 {
1477 LOGE("ARG error.");
1478 return -1;
1479 }
1480 memset(data, 0, 10);
1481 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1482 LOGE("CID error.");
1483 return -1;
1484 }
1485 uint8* ptr = data;
1486 /* <call_type[1]><cid[1]><timeout[1]>
1487 call_type : mbtk_data_call_type_enum
1488 cid : 2 - 7
1489 timeout : second
1490 */
1491 *ptr++ = (uint8)MBTK_DATA_CALL_STOP;
1492 *ptr++ = (uint8)cid;
1493 *ptr++ = (uint8)timeout;
1494
1495 return info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, NULL) ? handle->info_err : 0;
1496}
1497
1498/*
1499* Get data call state.
1500*/
1501int mbtk_data_call_state_get(mbtk_info_handle_t* handle, int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6)
1502{
1503 uint8 data[10];
1504 if(handle == NULL)
1505 {
1506 LOGE("ARG error.");
1507 return -1;
1508 }
1509 uint8 recv_buff[SOCK_MSG_LEN_MAX]={0};
1510 memset(data, 0, 10);
1511 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
1512 LOGE("CID error.");
1513 return -1;
1514 }
1515 uint8* ptr = data;
1516 /* <call_type[1]><cid[1]><timeout[1]>
1517 call_type : mbtk_data_call_type_enum
1518 cid : 2 - 7
1519 timeout : second
1520 */
1521 *ptr++ = (uint8)MBTK_DATA_CALL_STATE;
1522 *ptr++ = (uint8)cid;
1523 *ptr++ = (uint8)0;
1524
1525 if(ipv4) {
1526 memset(ipv4, 0, sizeof(mbtk_ipv4_info_t));
1527 }
1528
1529 if(ipv6) {
1530 memset(ipv6, 0, sizeof(mbtk_ipv6_info_t));
1531 }
1532
1533 if(info_item_process(handle, MBTK_INFO_ID_NET_DATA_CALL_REQ, data, 3, recv_buff) > 0) {
1534 if(recv_buff[0] == 0) { // IPv4 Only.
1535 if(ipv4) {
1536 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1537 }
1538 } else if(recv_buff[0] == 1) { // IPv6 Only.
1539 if(ipv6) {
1540 memcpy(ipv6, recv_buff + sizeof(uint8), sizeof(mbtk_ipv6_info_t));
1541 }
1542 } else if(recv_buff[0] == 2) { // IPv4 and IPv6.
1543 if(ipv4) {
1544 memcpy(ipv4, recv_buff + sizeof(uint8), sizeof(mbtk_ipv4_info_t));
1545 }
1546
1547 if(ipv6) {
1548 memcpy(ipv6, recv_buff + sizeof(uint8) + sizeof(mbtk_ipv4_info_t), sizeof(mbtk_ipv6_info_t));
1549 }
1550 } else {
1551 LOGE("Unknown IP type : %d", recv_buff[0]);
1552 return -1;
1553 }
1554 return 0;
1555 } else {
1556 return handle->info_err;
1557 }
1558}
1559
1560
1561
1562/*
1563* Get current network signal.
1564*/
1565int mbtk_net_signal_get(mbtk_info_handle_t* handle, mbtk_signal_info_t *signal)
1566{
1567 if(handle == NULL || signal == NULL)
1568 {
1569 LOGE("ARG error.");
1570 return -1;
1571 }
1572 if(info_item_process(handle, MBTK_INFO_ID_NET_SIGNAL_REQ, NULL, 0, signal) > 0) {
1573 LOG("Signal : %d, %d, %d, %d, %d, %d, %d", signal->rssi, signal->rxlev, signal->ber, signal->rscp, signal->ecno,
1574 signal->rsrq, signal->rsrp);
1575 return 0;
1576 } else {
1577 return handle->info_err;
1578 }
1579}
1580
1581/*
1582* Get current network register information.
1583*/
1584int mbtk_net_reg_get(mbtk_info_handle_t* handle, mbtk_net_reg_info_t *reg)
1585{
1586 if(handle == NULL || reg == NULL)
1587 {
1588 LOGE("ARG error.");
1589 return -1;
1590 }
1591 if(info_item_process(handle, MBTK_INFO_ID_NET_REG_REQ, NULL, 0, reg) > 0) {
1592 if(reg->call_state || reg->data_state || reg->ims_state) {
1593 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);
1594 } else {
1595 LOGE("Net not reg.");
1596 }
1597 return 0;
1598 } else {
1599 return handle->info_err;
1600 }
1601}
1602
r.xiao06db9a12024-04-14 18:51:15 -07001603/*
b.liufdf03172024-06-07 15:01:29 +08001604* Get current IMS enable or not.
r.xiao06db9a12024-04-14 18:51:15 -07001605*/
b.liufdf03172024-06-07 15:01:29 +08001606int mbtk_net_ims_get(mbtk_info_handle_t* handle, int* enable)
r.xiao06db9a12024-04-14 18:51:15 -07001607{
1608 uint8 state;
1609 if(handle == NULL)
1610 {
1611 LOGE("ARG error.");
1612 return -1;
1613 }
1614 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REQ, NULL, 0, &state) > 0) {
b.liufdf03172024-06-07 15:01:29 +08001615 LOG("IMS enable : %d", state);
1616 *enable = state;
r.xiao06db9a12024-04-14 18:51:15 -07001617 return 0;
1618 } else {
1619 return handle->info_err;
1620 }
1621
1622}
1623
1624/*
b.liufdf03172024-06-07 15:01:29 +08001625* Set IMS enable or not. This function takes effect after starting the device.
r.xiao06db9a12024-04-14 18:51:15 -07001626*/
b.liufdf03172024-06-07 15:01:29 +08001627int mbtk_net_ims_set(mbtk_info_handle_t* handle, int enable)
r.xiao06db9a12024-04-14 18:51:15 -07001628{
1629 if(handle == NULL)
1630 {
1631 LOGE("ARG error.");
1632 return -1;
1633 }
1634
b.liufdf03172024-06-07 15:01:29 +08001635 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 -07001636
1637}
1638
b.liufdf03172024-06-07 15:01:29 +08001639/*
1640* Get current network IMS register state.
1641*/
1642int mbtk_net_ims_reg_state_get(mbtk_info_handle_t* handle, int* reg)
1643{
1644 uint8 state;
1645 if(handle == NULL)
1646 {
1647 LOGE("ARG error.");
1648 return -1;
1649 }
1650 if(info_item_process(handle, MBTK_INFO_ID_NET_IMS_REG_STATE_REQ, NULL, 0, &state) > 0) {
1651 LOG("reg type : %d", state);
1652 *reg = state;
1653 return 0;
1654 } else {
1655 return handle->info_err;
1656 }
1657}
1658
liubin281ac462023-07-19 14:22:54 +08001659
1660/*
1661* Get radio state.
1662*/
1663int mbtk_radio_state_get(mbtk_info_handle_t* handle, int *radio_state)
1664{
1665 uint8 state;
1666 if(handle == NULL || radio_state == NULL)
1667 {
1668 LOGE("ARG error.");
1669 return -1;
1670 }
1671 if(info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, NULL, 0, &state) > 0) {
1672 LOG("Radio state : %d", state);
1673 *radio_state = state;
1674 return 0;
1675 } else {
1676 return handle->info_err;
1677 }
1678}
1679
1680/*
1681* Set radio state.
1682*/
1683int mbtk_radio_state_set(mbtk_info_handle_t* handle, int radio_state)
1684{
1685 if(handle == NULL)
1686 {
1687 LOGE("ARG error.");
1688 return -1;
1689 }
1690 return info_item_process(handle, MBTK_INFO_ID_NET_RADIO_REQ, (uint8*)&radio_state, sizeof(uint8), NULL) ? handle->info_err : 0;
1691}
1692
1693/*
1694* Get time type.
1695*/
1696int mbtk_time_get(mbtk_info_handle_t* handle, int *time_type)
1697{
1698 uint8 state;
1699 if(handle == NULL || time_type == NULL)
1700 {
1701 LOGE("ARG error.");
1702 return -1;
1703 }
1704 if(info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ, NULL, 0, &state) > 0) {
1705 LOG("Time type : %d", state);
1706 *time_type = state;
1707 return 0;
1708 } else {
1709 return handle->info_err;
1710 }
1711}
1712
1713/*
1714*Get Absolute time
1715*"23/05/24 06:09:32 +32 00"
1716*/
1717int mbtk_get_abs_time(char *time_str, time_t *time_out)
1718{
1719 struct tm tm_;
1720
1721 char *ptr = strstr(time_str + 10, " ");
1722 *ptr = '\0';
1723
1724 LOGD("time : \"%s\"", time_str);
1725#if 1
1726 if(strptime(time_str, "%y/%m/%d %T", &tm_) == NULL) {
1727 LOGE("strptime() fail.");
1728 return -1;
1729 }
1730#else
1731 int year, month, day, hour, minute,second,time_zone;
1732 if(strstr(time_str, "+")) {
1733 sscanf(time_str, "%d/%d/%d %d:%d:%d +%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1734 } else if(strstr(time_str, "-")) {
1735 sscanf(time_str, "%d/%d/%d %d:%d:%d -%d",&year,&month,&day,&hour,&minute,&second,&time_zone);
1736 } else {
1737 LOGE("Time format error:%s", time_str);
1738 return -1;
1739 }
1740
1741 // 1970+
1742 if(year < 70) { // 20xx
1743 tm_.tm_year = 2000 + year;
1744 } else { // 19xx
1745 tm_.tm_year = 1900 + year;
1746 }
1747 tm_.tm_mon = month - 1;
1748 tm_.tm_mday = day;
1749 tm_.tm_hour = hour;
1750 tm_.tm_min = minute;
1751 tm_.tm_sec = second;
1752 tm_.tm_isdst = 0;
1753#endif
1754
1755 time_t timeStamp = mktime(&tm_);
1756 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);
1757 LOGD("time = %ld,%x", timeStamp,timeStamp);
1758 *time_out = timeStamp;
1759
1760 return 0;
1761}
1762
1763/*
1764* Get time type.
1765* "23/05/24,06:09:32+32" -> "23/05/24 06:09:32 +32 00"
1766*/
1767int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
1768{
1769 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
1770 if(handle == NULL || time_str == NULL)
1771 {
1772 LOGE("ARG error.");
1773 return -1;
1774 }
1775 //printf("mbtk_net_time_get begin info_item_process\n");
b.liubaa41e12024-07-19 15:07:24 +08001776 if(info_item_process(handle, MBTK_INFO_ID_DEV_CELL_TIME_REQ, NULL, 0, buff) > 0) {
liubin281ac462023-07-19 14:22:54 +08001777 memcpy(time_str,buff,strlen(buff));
1778
1779 uint8 *temp = strstr(time_str, ",");
1780 if(temp) {
1781 *temp = ' '; // ',' -> ' '
1782
1783 temp = strstr(time_str, "+");
1784 if(temp == NULL) {
1785 temp = strstr(time_str, "-");
1786 }
1787
1788 if(temp) {
1789 // Copy +XX or -XX
1790 uint8 *last_ptr = temp + strlen(temp) + 1;
1791 while(last_ptr > temp) {
1792 *last_ptr = *(last_ptr - 1);
1793 last_ptr--;
1794 }
1795
1796 *last_ptr = ' ';
1797
1798 memcpy(temp + strlen(temp), "00", 2);
1799
1800 LOGD("%s -> %s", buff, time_str);
1801 return 0;
1802 } else {
1803 LOGE("Time error:%s",buff);
1804 return MBTK_INFO_ERR_TIME_FORMAT;
1805 }
1806 } else {
1807 LOGE("Time error:%s",buff);
1808 return MBTK_INFO_ERR_TIME_FORMAT;
1809 }
1810 } else {
1811 return handle->info_err;
1812 }
1813}
1814
1815/*
1816* Set time.
1817*
1818* time_type:
1819* 0: Cell time
1820* 1: NTP time
1821* 2: User time
1822* time_str: "YYYY-MM-DD HH:MM:SS"
1823*/
1824int mbtk_time_set(mbtk_info_handle_t* handle, mbtk_time_type_enum time_type, char* time_str)
1825{
1826 if(handle == NULL)
1827 {
1828 LOGE("ARG error.");
1829 return -1;
1830 }
1831 uint8 buffer[100] = {0};
1832 buffer[0] = (uint8)time_type;
1833 if(time_type == MBTK_TIME_TYPE_USER) {
1834 if(!str_empty(time_str)) {
1835 memcpy(buffer + sizeof(uint8), time_str, strlen(time_str));
1836 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1837 buffer, sizeof(uint8) + strlen(time_str), NULL) ? handle->info_err : 0;
1838 } else {
1839 return -1;
1840 }
1841 } else {
1842 return info_item_process(handle, MBTK_INFO_ID_DEV_TIME_REQ,
1843 buffer, sizeof(uint8), NULL) ? handle->info_err : 0;
1844 }
1845}
1846
1847/*
1848* Return sms cmgf.
1849*/
1850int mbtk_sms_cmgf_get(mbtk_info_handle_t* handle, int *volte_state)
1851{
1852 uint8 state;
1853 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, NULL, 0, &state) > 0) {
1854 LOG("mbtk_sms_cmgf_get()-----------sms cmgf : %d", state);
1855 *volte_state = state;
1856 return 0;
1857 } else {
1858 return handle->info_err;
1859 }
1860}
1861
1862/*
1863* Set sms cmgf.
1864*
1865* volte_state:
1866* 0 : PDU mode.
1867* 1 : text mode.
1868*
1869* Restarting takes effect after execution.
1870*/
1871int mbtk_sms_cmgf_set(mbtk_info_handle_t* handle, int mode)
1872{
yq.wanga9b5dd02024-10-16 00:25:14 -07001873 LOGD("mbtk_sms_cmgf_set()--------mode=:%d, len:%d", mode, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +08001874 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGF_REQ, (uint8*)&mode, sizeof(uint8), NULL) ? handle->info_err : 0;
1875}
1876
1877/*
1878* Set sms cmgs.
1879*
1880if PDU mode (+CMGF=0):
1881+CMGS=<length><CR>
1882PDU is given<ctrl-Z/ESC>
1883
1884if text mode (+CMGF=1):
1885+CMGS=<da>[,<toda>]<CR>
1886text is entered<ctrl-Z/ESC>
1887
1888* Restarting takes effect after execution.
1889*/
1890int mbtk_sms_cmgs_set(mbtk_info_handle_t* handle, char * cmgs, char *resp)
1891{
yq.wanga9b5dd02024-10-16 00:25:14 -07001892 LOGD("mbtk_sms_cmgs_set(1)--------cmgs=:%s, len:%d", cmgs, strlen(cmgs));
liubin281ac462023-07-19 14:22:54 +08001893// char req[20] = {0}
1894 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGS_REQ, cmgs, strlen(cmgs), resp) > 0){
yq.wanga9b5dd02024-10-16 00:25:14 -07001895 LOGD("resp:%s", resp);
liubin281ac462023-07-19 14:22:54 +08001896 return 0;
1897 }else{
1898 return handle->info_err;
1899 }
1900}
1901
1902/*
1903* Set sms cmgw.
1904*
1905if text mode (+CMGF=1):
1906+CMGW=<oa/da>[,<tooa/toda>[,<stat>]]
1907<CR>
1908text is entered<ctrl-Z/ESC>
1909if PDU mode (+CMGF=0):
1910+CMGW=<length>[,<stat>]<CR>PDU is
1911given<ctrl-Z/ESC>
1912
1913*/
1914
1915int mbtk_sms_cmgw_set(mbtk_info_handle_t* handle, char * cmgw, char *resp)
1916{
1917 printf("mbtk_sms_cmgw_set() ----------cmgw:%s, len:%d", cmgw, strlen(cmgw));
1918 if(info_item_process(handle, MBTK_INFO_ID_SMS_CMGW_REQ, cmgw, strlen(cmgw), resp) > 0){
1919 printf("resp:%s\n", resp);
1920 return 0;
1921 }else{
1922 return handle->info_err;
1923 }
1924}
1925
1926/*
1927* Set sms cmgd.
1928*
1929* +CMGD=<index>[,<delflag>]
1930*
1931* Restarting takes effect after execution.
1932*/
1933int mbtk_sms_cmgd_set(mbtk_info_handle_t* handle, char * cmdg)
1934{
1935 printf("mbtk_sms_cmgd_set() cmdg:%s, len:%d",cmdg, strlen(cmdg));
1936 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, cmdg, strlen(cmdg), NULL) ? handle->info_err : 0;
1937}
1938
1939/*
r.xiaoeb9dba42024-02-07 02:16:13 -08001940* Get sms cmgd.
1941*
1942* +CMGD: (XXX,XXX)(0-4)
1943*
1944* Restarting takes effect after execution.
1945*/
1946int mbtk_sms_cmgd_get(mbtk_info_handle_t* handle, char * cmdg)
1947{
1948 return info_item_process(handle, MBTK_INFO_ID_SMS_CMGD_REQ, NULL, 0, cmdg) ? handle->info_err : 0;
1949}
1950
1951
1952/*
liubin281ac462023-07-19 14:22:54 +08001953* Set sms cmgl.
1954*
1955* AT+CMGL[=<stat>]
1956*
1957* Restarting takes effect after execution.
1958*/
1959int mbtk_sms_cmgl_set(mbtk_info_handle_t* handle, char * cmgl, char *resp)
1960{
1961 printf("0mbtk_sms_cmgl_set() cmgl:%s, len:%d\n",cmgl, strlen(cmgl));
1962 char reg[5*1024] ={0};
1963 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGL_REQ, cmgl, strlen(cmgl), reg) > 0){
1964 printf("len:%d , reg:%s\n", strlen(reg), reg);
1965 // memcpy(resp, reg, strlen(reg));
1966 return 0;
1967 }else {
1968 return handle->info_err;
1969 }
1970}
1971
1972/*
1973* Return sms csca.
1974*/
1975int mbtk_sms_csca_get(mbtk_info_handle_t* handle, char *buf)
1976{
1977 // char state;
1978 if(info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, NULL, 0, buf) > 0) {
1979 LOG("mbtk_sms_csca_get()-----------sms csca : %s", buf);
1980 // *volte_state = state;
1981 return 0;
1982 } else {
1983 return handle->info_err;
1984 }
1985}
1986
1987/*
1988* Set sms csca.
1989*
1990* AT+CSCA=<number> [,<type>]
1991*
1992* Restarting takes effect after execution.
1993*/
1994int mbtk_sms_csca_set(mbtk_info_handle_t* handle, char * csca)
1995{
1996 printf("mbtk_sms_csca_set() csca:%s, len:%d",csca, strlen(csca));
1997 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCA_REQ, csca, strlen(csca), NULL) ? handle->info_err : 0;
1998}
1999
2000/*
2001* Set sms csmp.
2002*
2003* AT+CSMP=[<fo>[,<vp>[,<pid>[,<dcs>]]]]
2004*
2005* Restarting takes effect after execution.
2006*/
2007int mbtk_sms_csmp_set(mbtk_info_handle_t* handle, char * csmp)
2008{
2009 printf("mbtk_sms_csmp_set() csmp:%s, len:%d",csmp, strlen(csmp));
2010 return info_item_process(handle, MBTK_INFO_ID_SMS_CSMP_REQ, csmp, strlen(csmp), NULL) ? handle->info_err : 0;
2011}
2012
2013/*
2014* Set sms cscb.
2015*
2016* AT+CSCB=<[<mode>[,<mids>[,<dcss>]]]>
2017*
2018* Restarting takes effect after execution.
2019*/
2020int mbtk_sms_cscb_set(mbtk_info_handle_t* handle, char * cscb)
2021{
2022 printf("mbtk_sms_cscb_set() cscb:%s, len:%d",cscb, strlen(cscb));
2023 return info_item_process(handle, MBTK_INFO_ID_SMS_CSCB_REQ, cscb, strlen(cscb), NULL) ? handle->info_err : 0;
2024}
2025
2026/*
2027* Set sms cnmi.
2028*
2029at+cnmi=1,2
2030
2031OK
2032if sending fails:
2033+CMS ERROR: <err>
2034*/
2035int mbtk_sms_cnmi_set(mbtk_info_handle_t* handle)
2036{
2037 printf("mbtk_sms_cnmi_set()------------start\n");
2038
2039 return info_item_process(handle, MBTK_INFO_ID_SMS_CNMI_REQ, NULL, 0, NULL)? handle->info_err : 0;
2040}
2041
2042/*
2043* Set sms cmss.
2044*
2045+CMSS=<index>[,<da>[,<toda>]]
2046
2047if sending successful:
2048+CMSS: <mr>
2049OK
2050if sending fails:
2051+CMS ERROR: <err>
2052*/
2053int mbtk_sms_cmss_set(mbtk_info_handle_t* handle, char * cmss, char *resp)
2054{
2055 printf("mbtk_sms_cmss_set()------------cmss:%s, len:%d", cmss, strlen(cmss));
2056 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMSS_REQ, cmss, strlen(cmss), resp) > 0){
2057 printf("resp:%s\n", resp);
2058 return 0;
2059 }else{
2060 return handle->info_err;
2061 }
2062}
2063
2064/*
2065* Return sms cmgf.
2066*/
2067int mbtk_sms_cpms_get(mbtk_info_handle_t* handle, char * mem)
2068{
2069 char req[128] = {0};
2070 if(info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, NULL, 0, &req) > 0) {
2071 LOG("mbtk_sms_cpms_get() req : %s, strlen(mem_ptr):%d\n", req, strlen(req));
2072 memcpy(mem, req, strlen(req));
2073 return 0;
2074 } else {
2075 return handle->info_err;
2076 }
2077}
2078
2079
2080/*
2081* Set sms cpms.
2082*
2083* AT+CPMS=<mem1>[,<mem2>[,<mem3>]]
2084*
2085* Restarting takes effect after execution.
2086*/
2087int mbtk_sms_cpms_set(mbtk_info_handle_t* handle, char * mem, char* response)
2088{
2089 printf("mbtk_sms_cpms_set() mem:%s, len:%d",mem, strlen(mem));
2090 char req[128] = {0};
2091 if( info_item_process(handle, MBTK_INFO_ID_SMS_CPMS_REQ, mem, strlen(mem), req) > 0){
2092 memcpy(response, req, strlen(req));
2093 return 0;
2094 }
2095 else{
2096 return handle->info_err;
2097 }
2098}
2099
2100/*
2101* Set sms cm.
2102*
2103* +CMGR=<index>
2104
2105if PDU mode (+CMGF=0) ��command successful:
2106+CMGR: <stat>,[<alpha>],<length><CR><LF><pdu>
2107OK
2108if text mode (+CMGF=1), command successful and SMS-DELIVER:
2109+CMGR:<stat>,<oa>,[<alpha>],<scts>[,<tooa>,<fo>,<pid>,<dcs
2110>, <sca>,<tosca>,<length>]<CR><LF><data>
2111OK
2112if text mode (+CMGF=1), command successful and SMS-SUBMIT:
2113+CMGR:
2114<stat>,<da>,[<alpha>][,<toda>,<fo>,<pid>,<dcs>,[<vp>],
2115<sca>,<tosca>,<length>]<CR><LF><data>
2116OK
2117otherwise:
2118+CMS ERROR: <err>
2119*
2120* Restarting takes effect after execution.
2121*/
2122int mbtk_sms_cmgr_set(mbtk_info_handle_t* handle, int index, char *resp)
2123{
2124 printf("mbtk_sms_cmgr_set() --------------index:%d",index);
2125 if( info_item_process(handle, MBTK_INFO_ID_SMS_CMGR_REQ, (uint8*)&index, sizeof(uint8), resp) > 0){
2126 printf("resp:%s\n", resp);
2127 return 0;
2128 }else{
2129 return handle->info_err;
2130 }
2131}
2132
2133
2134/*
2135* Get sim state.
2136*/
2137int mbtk_sim_state_get(mbtk_info_handle_t* handle, mbtk_sim_state_enum *sim_state)
2138{
2139 uint8 state;
2140 if(handle == NULL || sim_state == NULL)
2141 {
2142 LOGE("ARG error.");
2143 return -1;
2144 }
2145 if(info_item_process(handle, MBTK_INFO_ID_SIM_STATE_REQ, NULL, 0, &state) > 0) {
2146 *sim_state = (mbtk_sim_state_enum)state;
2147 LOG("Sim state : %d", *sim_state);
2148 return 0;
2149 } else {
2150 return handle->info_err;
2151 }
2152}
2153
2154/*
2155* Get sim card type.
2156*/
2157int mbtk_sim_card_type_get(mbtk_info_handle_t* handle, mbtk_sim_card_type_enum *sim_card_type)
2158{
2159 uint8 state;
2160 if(handle == NULL || sim_card_type == NULL)
2161 {
2162 LOGE("ARG error.");
2163 return -1;
2164 }
2165 if(info_item_process(handle, MBTK_INFO_ID_SIM_STYPE_REQ, NULL, 0, &state) > 0) {
2166 *sim_card_type = (mbtk_sim_card_type_enum)state;
2167 LOG("Sim sim_card_type : %d", *sim_card_type);
2168 return 0;
2169 } else {
2170 return handle->info_err;
2171 }
2172}
2173
2174/*
2175* Get system temperature.
2176*
2177* type[IN]:
2178* 0: Soc temperature.
2179* 1: RF temperature.
2180* temp[OUT]:
2181* temperature in celsius.
2182*/
r.xiao2102d762024-06-07 03:10:38 -07002183int mbtk_temp_get(mbtk_info_handle_t* handle, int type, mbtk_thermal_info_t* temp)
liubin281ac462023-07-19 14:22:54 +08002184{
2185 if(handle == NULL)
2186 {
2187 LOGE("ARG error.");
2188 return -1;
2189 }
r.xiao2102d762024-06-07 03:10:38 -07002190 if(type != 0 && type != 1)
liubin281ac462023-07-19 14:22:54 +08002191 {
2192 return -1;
2193 }
2194
2195 uint8 temp_type = (uint8)type;
r.xiao2102d762024-06-07 03:10:38 -07002196
2197 if(info_item_process(handle, MBTK_INFO_ID_DEV_TEMP_REQ, &temp_type, sizeof(uint8), temp) > 0) {
2198
2199 LOG("Temperature : %d", temp->ther);
liubin281ac462023-07-19 14:22:54 +08002200 return 0;
2201 } else {
2202 return handle->info_err;
2203 }
2204
2205 return 0;
2206}
2207
2208
2209/*
2210* Set sim power state.
2211* power:
2212* 0: Sim power off.
2213* 1: Sim power on.
2214*/
2215int mbtk_sim_power_set(int power)
2216{
2217 if(power != 0 && power != 1)
2218 {
2219 return -1;
2220 }
2221
2222 // /sys/devices/virtual/usim_event/usim0/send_event
2223 char cmd[100] = {0};
2224 sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
2225 system(cmd);
2226
2227 return 0;
2228}
2229
2230/*
2231* System power.
2232* type:
2233* 0: Reboot system.
2234* 1: Poweroff system.
2235* 2: Halt system.
2236*/
2237int mbtk_system_reboot(int type)
2238{
2239 if(type != 0 && type != 1 && type != 2)
2240 {
2241 return -1;
2242 }
2243
2244 switch(type) {
2245 case 0: {
2246 system("reboot");
2247 break;
2248 }
2249 case 1: {
2250 system("poweroff");
2251 break;
2252 }
2253 case 2: {
2254 system("halt");
2255 break;
2256 }
2257 default: {
2258 break;
2259 }
2260 }
2261
2262 return 0;
2263}
2264
2265/*
2266* set modem fun
2267*
2268*/
2269int mbtk_set_modem_fun(mbtk_info_handle_t* handle, mbtk_modem_info_t *info)
2270{
2271 if(handle == NULL)
2272 {
2273 LOGE("ARG error.");
2274 return -1;
2275 }
2276 return info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, info, sizeof(mbtk_modem_info_t), NULL) ? handle->info_err : 0;
2277}
2278
2279/*
2280* get modem fun
2281*
2282*/
2283int mbtk_get_modem_fun(mbtk_info_handle_t* handle, int* fun)
2284{
2285 uint8 state;
2286 if(handle == NULL || fun == NULL)
2287 {
2288 LOGE("ARG error.");
2289 return -1;
2290 }
2291 if(info_item_process(handle, MBTK_INFO_ID_DEV_MODEM_REQ, NULL, 0, &state) > 0) {
2292 LOG("modem type : %d", state);
2293 *fun = state;
2294 return 0;
2295 } else {
2296 return handle->info_err;
2297 }
2298}
2299
2300/*
2301* call_start
2302*
2303*/
2304int mbtk_call_start(mbtk_info_handle_t* handle, char* phone_number)
2305{
2306 if(handle == NULL)
2307 {
2308 LOGE("ARG error.");
2309 return -1;
2310 }
2311 if(str_empty(phone_number))
2312 return -1;
2313
2314 return info_item_process(handle, MBTK_INFO_ID_CALL_START_REQ,
2315 phone_number, strlen(phone_number), NULL) ? handle->info_err : 0;
2316}
2317/*
2318* Answer the phone call.
2319*
2320*/
2321int mbtk_call_answer(mbtk_info_handle_t* handle)
2322{
2323 return info_item_process(handle, MBTK_INFO_ID_CALL_ANSWER_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2324}
2325
2326/*
2327* Hang up all call.
2328*
2329*/
2330int mbtk_call_hang(mbtk_info_handle_t* handle)
2331{
2332 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2333}
2334
2335/*
2336* Hang up a call.
2337*
2338*/
2339int mbtk_a_call_hang(mbtk_info_handle_t* handle, int phone_id)
2340{
2341 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_A_REQ, (uint8*)&phone_id, sizeof(uint8), NULL) ? handle->info_err : 0;
2342}
2343
2344/*
2345* Hang up waiting or background call.
2346*
2347*/
2348int mbtk_waiting_or_background_call_hang(mbtk_info_handle_t* handle)
2349{
2350 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_B_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2351}
2352
2353/*
2354* Hang up foreground resume background call.
2355*
2356*/
2357int mbtk_foreground_resume_background_call_hang(mbtk_info_handle_t* handle)
2358{
2359 return info_item_process(handle, MBTK_INFO_ID_CALL_HANGUP_C_REQ, NULL, 0, NULL) ? handle->info_err : 0;
2360}
2361
2362/*
2363* Get current call phone number.
2364*/
2365int mbtk_call_reg_get(mbtk_info_handle_t* handle, mbtk_call_info_t *reg)
2366{
2367 if(info_item_process(handle, MBTK_INFO_ID_CALL_WAITIN_REQ, NULL, 0, reg) > 0) {
2368 LOG("CLCC : %d, %d, %d, %d, %d, %s, %d", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type);
2369 return 0;
2370 } else {
2371 return handle->info_err;
2372 }
2373}
2374
2375/*
2376* Return mute state.
2377*/
2378int mbtk_mute_state_get(mbtk_info_handle_t* handle, int *mute_state)
2379{
2380 uint8 state;
2381 if(info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, NULL, 0, &state) > 0) {
2382 LOG("Mute State : %d", state);
2383 *mute_state = state;
2384 return 0;
2385 } else {
2386 return handle->info_err;
2387 }
2388}
2389
2390/*
2391* Set mute state.
2392*
2393* mute_state:
2394* 0 : of mute.
2395* 1 : on mute.
2396*
2397* Restarting takes effect after execution.
2398*/
2399int mbtk_mute_state_set(mbtk_info_handle_t* handle, int mute_state)
2400{
2401 return info_item_process(handle, MBTK_INFO_ID_CALL_MUTE_REQ, (uint8*)&mute_state, sizeof(uint8), NULL) ? handle->info_err : 0;
2402}
2403
2404/*
r.xiaoec113d12024-01-12 02:13:28 -08002405* Set wakeup state.
2406*
2407* wakeup_state:(0~31)
2408* 0 : means resume all
2409* 1~31 means suspend
2410* Control the active reporting of some platform modems to reduce wakeup
2411*/
2412
2413int mbtk_wakeup_state_set(mbtk_info_handle_t* handle, uint32 wakeup_state)
2414{
2415 return info_item_process(handle, MBTK_INFO_ID_WAKEUP_STA_REQ, (uint32*)&wakeup_state, sizeof(uint32), NULL) ? handle->info_err : 0;
2416}
2417
2418/*
2419* oos get.
2420*/
2421int mbtk_oos_get(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
2422{
2423 if(info_item_process(handle, MBTK_INFO_ID_OOS_STA_REQ, NULL, 0, oos_info) > 0) {
2424 return 0;
2425 } else {
2426 return handle->info_err;
2427 }
2428}
2429
2430/*
2431* oos set .
2432*/
r.xiaocfd7c682024-01-22 03:59:46 -08002433int mbtk_oos_set(mbtk_info_handle_t* handle, mbtk_oos_info *oos_info)
r.xiaoec113d12024-01-12 02:13:28 -08002434{
2435 if(handle == NULL)
2436 {
2437 LOGE("ARG error.");
2438 return -1;
2439 }
r.xiaoec113d12024-01-12 02:13:28 -08002440
r.xiaocfd7c682024-01-22 03:59:46 -08002441 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 -08002442}
2443
2444
2445/*
liubin281ac462023-07-19 14:22:54 +08002446* Set DTMF character.
2447*
2448*/
2449int mbtk_dtmf_send(mbtk_info_handle_t* handle, mbtk_call_dtmf_info_t *dtmf_character)
2450{
2451 if(handle == NULL)
2452 {
2453 LOGE("ARG error.");
2454 return -1;
2455 }
2456 return info_item_process(handle, MBTK_INFO_ID_CALL_DTMF_REQ,
2457 dtmf_character, sizeof(mbtk_call_dtmf_info_t), NULL) ? handle->info_err : 0;
2458}
2459
2460/*
wangyouqiang38e53362024-01-23 10:53:48 +08002461* Set net led.
2462*
2463*/
2464int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status)
2465{
2466 if(handle == NULL)
2467 {
2468 LOGE("ARG error.");
2469 return -1;
2470 }
2471
2472 char buff[3] = {0};
2473 if(type == MBTK_LED_TYPE_NET)
2474 {
2475 buff[0] = 0;
2476 }
2477 else
2478 {
2479 buff[0] = 1;
2480 }
2481
2482 if(status == MBTK_LED_STATUS_CLOSE)
2483 {
2484 buff[1] = 0;
2485 }
2486 else
2487 {
2488 buff[1] = 1;
2489 }
2490 return info_item_process(handle, MBTK_INFO_ID_LED_REQ, buff, 2, NULL) ? handle->info_err : 0;
2491}
2492
b.liu06559f62024-11-01 18:48:22 +08002493
2494/*
2495* Set msd item.
2496*
2497*/
2498int mbtk_ecall_msd_item_set(mbtk_info_handle_t* handle, const mbtk_ecall_msd_cfg_info_t *msd_cfg)
2499{
2500 if(handle == NULL)
2501 {
2502 return -1;
2503 }
2504
2505 if(msd_cfg == NULL)
2506 {
2507 LOGE("ARG error.");
2508 return -1;
2509 }
2510
2511 if(info_item_process(handle, RIL_MSG_ID_ECALL_MSDCFG_REQ, msd_cfg, sizeof(mbtk_ecall_msd_cfg_info_t), NULL) >= 0) {
2512 return 0;
2513 } else {
2514 return handle->info_err;
2515 }
2516}
2517
2518/*
2519* Generate msd after msd item set.
2520*
2521*/
2522int mbtk_ecall_msd_gen(mbtk_info_handle_t* handle)
2523{
2524 if(handle == NULL)
2525 {
2526 return -1;
2527 }
2528
2529 if(info_item_process(handle, RIL_MSG_ID_ECALL_MSDGEN_REQ, NULL, 0, NULL) >= 0) {
2530 return 0;
2531 } else {
2532 return handle->info_err;
2533 }
2534}
2535
2536/*
2537* Set ecall msd.
2538*
2539*/
2540int mbtk_ecall_msd_set(mbtk_info_handle_t* handle, const void* msd)
2541{
2542 if(handle == NULL || str_empty(msd))
2543 {
2544 LOGE("ARG error.");
2545 return -1;
2546 }
2547
2548 if(info_item_process(handle, RIL_MSG_ID_ECALL_MSD_REQ, msd, strlen(msd), NULL) >= 0) {
2549 return 0;
2550 } else {
2551 return handle->info_err;
2552 }
2553}
2554
2555/*
2556* Get ecall msd.
2557*
2558*/
2559int mbtk_ecall_msd_get(mbtk_info_handle_t* handle, void* msd)
2560{
2561 if(!handle)
2562 {
2563 return -1;
2564 }
2565
2566 if(msd == NULL)
2567 {
2568 LOGE("ARG error.");
2569 return -1;
2570 }
2571
2572 if(info_item_process(handle, RIL_MSG_ID_ECALL_MSD_REQ, NULL, 0, msd) >= 0) {
2573 return 0;
2574 } else {
2575 return handle->info_err;
2576 }
2577}
2578
2579
2580/*
2581* Set ecall msd item.
2582*
2583*/
2584int mbtk_ecall_push(mbtk_info_handle_t* handle)
2585{
2586 if(!handle)
2587 {
2588 return -1;
2589 }
2590
2591 if(info_item_process(handle, RIL_MSG_ID_ECALL_PUSH_REQ, NULL, 0, NULL) >= 0) {
2592 return 0;
2593 } else {
2594 return handle->info_err;
2595 }
2596}
2597
2598/*
2599* Set ecall only configs.
2600*
2601*/
2602int mbtk_ecall_only_set(mbtk_info_handle_t* handle, const mbtk_ecall_only_info_t* info)
2603{
2604 if(!handle)
2605 {
2606 return -1;
2607 }
2608
2609 if(info == NULL)
2610 {
2611 LOGE("ARG error.");
2612 return -1;
2613 }
2614
2615 if(info_item_process(handle, RIL_MSG_ID_ECALL_ONLY_REQ, info, sizeof(mbtk_ecall_only_info_t), NULL) >= 0) {
2616 return 0;
2617 } else {
2618 return handle->info_err;
2619 }
2620}
2621
2622/*
2623* Get ecall only configs.
2624*
2625*/
2626int mbtk_ecall_only_get(mbtk_info_handle_t* handle, mbtk_ecall_only_info_t* info)
2627{
2628 if(!handle)
2629 {
2630 return -1;
2631 }
2632
2633 if(info == NULL)
2634 {
2635 LOGE("ARG error.");
2636 return -1;
2637 }
2638
2639 if(info_item_process(handle, RIL_MSG_ID_ECALL_ONLY_REQ, NULL, 0, info) >= 0) {
2640 return 0;
2641 } else {
2642 return handle->info_err;
2643 }
2644}
2645
2646/*
2647* Set ecall network reg.
2648*
2649*/
2650int mbtk_ecall_reg_set(mbtk_info_handle_t* handle, int reg)
2651{
2652 if(!handle)
2653 {
2654 return -1;
2655 }
2656
2657 if(reg != 0 && reg != 1)
2658 {
2659 LOGE("ARG error.");
2660 return -1;
2661 }
2662
2663 if(info_item_process(handle, RIL_MSG_ID_ECALL_REG_REQ, &reg, 1, NULL) >= 0) {
2664 return 0;
2665 } else {
2666 return handle->info_err;
2667 }
2668}
2669
2670/*
2671* Start ecall dial start.
2672*
2673*/
2674int mbtk_ecall_dial_start(mbtk_info_handle_t* handle, mbtk_ecall_dial_type_enum type)
2675{
2676 if(!handle)
2677 {
2678 return -1;
2679 }
2680
2681 if(info_item_process(handle, RIL_MSG_ID_ECALL_DIAL_REQ, &type, 1, NULL) >= 0) {
2682 return 0;
2683 } else {
2684 return handle->info_err;
2685 }
2686}
2687
2688/*
2689* Get ecall dial state.
2690*
2691*/
2692int mbtk_ecall_dial_state_get(mbtk_info_handle_t* handle, mbtk_ecall_dial_type_enum* type)
2693{
2694 if(!handle)
2695 {
2696 return -1;
2697 }
2698
2699 if(type == NULL)
2700 {
2701 LOGE("ARG error.");
2702 return -1;
2703 }
2704 memset(type, 0, sizeof(mbtk_ecall_dial_type_enum));
2705
2706 if(info_item_process(handle, RIL_MSG_ID_ECALL_DIAL_REQ, NULL, 0, type) >= 0) {
2707 return 0;
2708 } else {
2709 return handle->info_err;
2710 }
2711}
2712
2713/*
2714* Set ecall mode.
2715*
2716*/
2717int mbtk_ecall_mode_set(mbtk_info_handle_t* handle, mbtk_ecall_mode_type_enum mode)
2718{
2719 if(handle == NULL)
2720 {
2721 return -1;
2722 }
2723
2724 if(info_item_process(handle, RIL_MSG_ID_ECALL_MODE_REQ, &mode, 1, NULL) >= 0) {
2725 return 0;
2726 } else {
2727 return handle->info_err;
2728 }
2729}
2730
2731/*
2732* Get ecall mode.
2733*
2734*/
2735int mbtk_ecall_mode_get(mbtk_info_handle_t* handle, mbtk_ecall_mode_type_enum *mode)
2736{
2737 if(handle == NULL)
2738 {
2739 return -1;
2740 }
2741
2742 if(mode == NULL)
2743 {
2744 LOGE("ARG error.");
2745 return -1;
2746 }
2747 memset(mode, 0, sizeof(mbtk_ecall_mode_type_enum));
2748
2749 if(info_item_process(handle, RIL_MSG_ID_ECALL_MODE_REQ, NULL, 0, mode) >= 0) {
2750 return 0;
2751 } else {
2752 return handle->info_err;
2753 }
2754}
2755
2756/*
2757* Set ecall configs.
2758*
2759*/
2760int mbtk_ecall_cfg_set(mbtk_info_handle_t* handle, const mbtk_ecall_cfg_info_t *cfg)
2761{
2762 if(handle == NULL)
2763 {
2764 return -1;
2765 }
2766
b.liueea595d2024-11-05 19:52:10 +08002767 if(cfg == NULL || cfg->type == 0)
b.liu06559f62024-11-01 18:48:22 +08002768 {
2769 LOGE("ARG error.");
2770 return -1;
2771 }
2772
2773 if(info_item_process(handle, RIL_MSG_ID_ECALL_CFG_REQ, cfg, sizeof(mbtk_ecall_cfg_info_t), NULL) >= 0) {
2774 return 0;
2775 } else {
2776 return handle->info_err;
2777 }
2778}
2779
2780/*
2781* Get ecall configs.
2782*
2783*/
2784int mbtk_ecall_cfg_get(mbtk_info_handle_t* handle, mbtk_ecall_cfg_info_t* cfg)
2785{
2786 if(handle == NULL)
2787 {
2788 return -1;
2789 }
2790
b.liueea595d2024-11-05 19:52:10 +08002791 if(cfg == NULL || cfg->type == 0)
b.liu06559f62024-11-01 18:48:22 +08002792 {
2793 LOGE("ARG error.");
2794 return -1;
2795 }
b.liueea595d2024-11-05 19:52:10 +08002796 uint32 type = cfg->type;
b.liu06559f62024-11-01 18:48:22 +08002797
b.liueea595d2024-11-05 19:52:10 +08002798 if(info_item_process(handle, RIL_MSG_ID_ECALL_CFG_REQ, &type, sizeof(uint32), cfg) >= 0) {
b.liu06559f62024-11-01 18:48:22 +08002799 return 0;
2800 } else {
2801 return handle->info_err;
2802 }
2803}
2804
2805/*
2806* Set ecall sms number.
2807*
2808*/
2809int mbtk_ecall_sms_number_set(mbtk_info_handle_t* handle, const void *number)
2810{
2811 if(handle == NULL)
2812 {
2813 return -1;
2814 }
2815
2816 if(str_empty(number))
2817 {
2818 LOGE("ARG error.");
2819 return -1;
2820 }
2821
2822 if(info_item_process(handle, RIL_MSG_ID_ECALL_SMS_NUM_REQ, number, strlen(number), NULL) >= 0) {
2823 return 0;
2824 } else {
2825 return handle->info_err;
2826 }
2827}
2828
2829/*
2830* Get ecall sms number.
2831*
2832*/
2833int mbtk_ecall_sms_number_get(mbtk_info_handle_t* handle, void *number)
2834{
2835 if(handle == NULL)
2836 {
2837 return -1;
2838 }
2839
2840 if(number == NULL)
2841 {
2842 LOGE("ARG error.");
2843 return -1;
2844 }
2845
2846 if(info_item_process(handle, RIL_MSG_ID_ECALL_SMS_NUM_REQ, NULL, 0, number) >= 0) {
2847 return 0;
2848 } else {
2849 return handle->info_err;
2850 }
2851}
2852
2853/*
2854* Set ecall mute speaker.
2855*
2856*/
2857int mbtk_ecall_mute_spk_set(mbtk_info_handle_t* handle, int mute)
2858{
2859 if(handle == NULL)
2860 {
2861 return -1;
2862 }
2863
2864 if(mute != 0 && mute != 1)
2865 {
2866 LOGE("ARG error.");
2867 return -1;
2868 }
2869
2870 if(info_item_process(handle, RIL_MSG_ID_ECALL_MUTESPK_REQ, &mute, 1, NULL) >= 0) {
2871 return 0;
2872 } else {
2873 return handle->info_err;
2874 }
2875}
2876
2877/*
2878* Set ecall dsp gain.
2879*
2880*/
2881int mbtk_ecall_dsp_gain_set(mbtk_info_handle_t* handle, const mbtk_ecall_gain_info_t *gain_info)
2882{
2883 if(handle == NULL)
2884 {
2885 return -1;
2886 }
2887
2888 if(gain_info == NULL)
2889 {
2890 LOGE("ARG error.");
2891 return -1;
2892 }
2893
2894 if(info_item_process(handle, RIL_MSG_ID_ECALL_DSP_GAIN_REQ, gain_info, sizeof(mbtk_ecall_gain_info_t), NULL) >= 0) {
2895 return 0;
2896 } else {
2897 return handle->info_err;
2898 }
2899}
2900
2901
wangyouqiang38e53362024-01-23 10:53:48 +08002902/*
liubin281ac462023-07-19 14:22:54 +08002903* Set pdp state change callback function.
2904*/
2905int mbtk_pdp_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2906{
2907 if(handle == NULL)
2908 {
2909 LOGE("ARG error.");
2910 return -1;
2911 }
2912 if(info_item_process(handle, MBTK_INFO_ID_IND_PDP_STATE_CHANGE, NULL, 0, NULL) < 0) {
2913 return handle->info_err;
2914 } else {
2915 handle->pdp_state_cb = cb;
2916 return 0;
2917 }
2918}
2919
2920/*
2921* Set network state change callback function.
2922*/
2923int mbtk_net_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2924{
2925 if(handle == NULL)
2926 {
2927 LOGE("ARG error.");
2928 return -1;
2929 }
b.liu27b91e42024-01-17 20:02:30 +08002930 if(info_item_process(handle, MBTK_INFO_ID_IND_NET_STATE_CHANGE, NULL, 0, NULL) < 0) {
2931 return handle->info_err;
2932 } else {
liubin281ac462023-07-19 14:22:54 +08002933 handle->net_state_cb = cb;
2934 return 0;
liubin281ac462023-07-19 14:22:54 +08002935 }
2936}
2937
2938/*
2939* Set call state change callback function.
2940*/
2941int mbtk_call_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2942{
2943 if(handle == NULL)
2944 {
2945 LOGE("ARG error.");
2946 return -1;
2947 }
2948 if(info_item_process(handle, MBTK_INFO_ID_IND_CALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
2949 return handle->info_err;
2950 } else {
2951 handle->call_state_cb = cb;
2952 return 0;
2953 }
2954}
2955
2956/*
2957* Set sms state change callback function.
2958*/
2959int mbtk_sms_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2960{
2961 if(handle == NULL)
2962 {
2963 LOGE("ARG error.");
2964 return -1;
2965 }
2966 if(info_item_process(handle, MBTK_INFO_ID_IND_SMS_STATE_CHANGE, NULL, 0, NULL) < 0) {
2967 return handle->info_err;
2968 } else {
2969 handle->sms_state_cb = cb;
2970 return 0;
2971 }
2972}
2973
2974/*
2975* Set radio state change callback function.
2976*/
2977int mbtk_radio_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2978{
2979 if(handle == NULL)
2980 {
2981 LOGE("ARG error.");
2982 return -1;
2983 }
2984 if(info_item_process(handle, MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, NULL, 0, NULL) < 0) {
2985 return handle->info_err;
2986 } else {
2987 handle->radio_state_cb = cb;
2988 return 0;
2989 }
2990}
2991
2992/*
2993* Set sim state change callback function.
2994*/
2995int mbtk_sim_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
2996{
2997 if(handle == NULL)
2998 {
2999 LOGE("ARG error.");
3000 return -1;
3001 }
3002 if(info_item_process(handle, MBTK_INFO_ID_IND_SIM_STATE_CHANGE, NULL, 0, NULL) < 0) {
3003 return handle->info_err;
3004 } else {
3005 handle->sim_state_cb = cb;
3006 return 0;
3007 }
3008}
r.xiaofca7c472024-04-24 01:00:23 -07003009
3010/*
3011* Set signal state change callback function.
3012*/
3013int mbtk_signal_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
3014{
3015 if(handle == NULL)
3016 {
3017 LOGE("ARG error.");
3018 return -1;
3019 }
3020 if(info_item_process(handle, MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE, NULL, 0, NULL) < 0) {
3021 return handle->info_err;
3022 } else {
3023 handle->signal_state_cb = cb;
3024 return 0;
3025 }
3026}
3027
b.liuc41882f2024-10-23 17:54:44 +08003028/*
3029* Set ril server state change callback function.
3030*/
3031int mbtk_ril_server_state_change_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
3032{
3033 if(handle == NULL)
3034 {
3035 LOGE("ARG error.");
3036 return -1;
3037 }
3038
3039 ril_server_state_cb = cb;
3040 return 0;
3041}
3042
b.liu76e353a2024-11-01 14:49:31 +08003043int mbtk_ecall_state_change_cb_reg(mbtk_info_handle_t* handle, mbtk_info_callback_func cb)
3044{
3045 if(handle == NULL)
3046 {
3047 LOGE("ARG error.");
3048 return -1;
3049 }
3050 if(info_item_process(handle, MBTK_INFO_ID_IND_ECALL_STATE_CHANGE, NULL, 0, NULL) < 0) {
3051 return handle->info_err;
3052 } else {
3053 handle->ecall_state_cb = cb;
3054 return 0;
3055 }
3056}
3057
b.liuc41882f2024-10-23 17:54:44 +08003058
l.yang5b0ff422024-10-29 19:33:35 -07003059int mbtk_get_modem_version(mbtk_info_handle_t* handle, void *modem_version)
3060{
3061 if(handle == NULL || modem_version == NULL)
3062 {
3063 LOGE("ARG error.");
3064 return -1;
3065 }
3066
3067 if(info_item_process(handle, MBTK_INFO_ID_DEV_MD_VERSION_REQ, NULL, 0, modem_version) > 0) {
3068 LOG("Version : %s", modem_version);
3069 return 0;
3070 } else {
3071 return handle->info_err;
3072 }
3073}
3074
b.liu76e353a2024-11-01 14:49:31 +08003075