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