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