blob: 941f5eb206cccbe75c184d14b06aa012f18e6c69 [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +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 <fcntl.h>
11#include <signal.h>
12
13#include "mbtk_type.h"
14#include "mbtk_ril.h"
15#include "atchannel.h"
16#include "at_tok.h"
17#include "mbtk_utils.h"
18#include "ril_info.h"
19
b.liu7ca612c2025-04-25 09:23:36 +080020void ril_rsp_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
21ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port);
b.liu87afc4c2024-08-14 17:33:45 +080022
23/*
24AT+CGSN
25864788050901201
26
27OK
28*/
b.liu7ca612c2025-04-25 09:23:36 +080029static int req_imei_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080030{
31 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +080032 int err = at_send_command_numeric(portType_2_portId(sim_id, port), "AT+CGSN", &response);
b.liu87afc4c2024-08-14 17:33:45 +080033
34 if (err < 0 || response->success == 0 || !response->p_intermediates) {
35 *cme_err = at_get_cme_error(response);
36 goto exit;
37 }
38
39 memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line));
40exit:
41 at_response_free(response);
42 return err;
43}
44
45/*
46AT+MRD_SN=R
47+MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006
48
49OK
50
51*/
b.liu7ca612c2025-04-25 09:23:36 +080052static int req_sn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080053{
54 ATResponse *response = NULL;
55 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +080056 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+MRD_SN=R", "+MRD_SN:", &response);
b.liu87afc4c2024-08-14 17:33:45 +080057
58 if (err < 0 || response->success == 0 || !response->p_intermediates){
59 *cme_err = at_get_cme_error(response);
60 goto exit;
61 }
62
63 char *line = response->p_intermediates->line;
64 err = at_tok_start(&line);
65 if (err < 0)
66 {
67 goto exit;
68 }
69
70 err = at_tok_nextstr(&line, &tmp_ptr);
71 if (err < 0)
72 {
73 goto exit;
74 }
75
76 err = at_tok_nextstr(&line, &tmp_ptr);
77 if (err < 0)
78 {
79 goto exit;
80 }
81
82 err = at_tok_nextstr(&line, &tmp_ptr);
83 if (err < 0)
84 {
85 goto exit;
86 }
87
88 memcpy(data, tmp_ptr, strlen(tmp_ptr));
89
90 goto exit;
91exit:
92 at_response_free(response);
93 return err;
94}
95
96/*
97ATI
98Manufacturer:"LYNQ"
99Model:"LYNQ_L508TLC"
100Revision:L508TLCv02.01b01.00
101IMEI:864788050901201
102
103OK
104
105*/
b.liu7ca612c2025-04-25 09:23:36 +0800106static int req_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800107{
108 ATResponse *response = NULL;
b.liu6917e9b2025-03-26 17:23:11 +0800109
110// sleep(3);
111
b.liu7ca612c2025-04-25 09:23:36 +0800112 int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800113
114 if (err < 0 || response->success == 0 || !response->p_intermediates){
115 *cme_err = at_get_cme_error(response);
116 goto exit;
117 }
118
119 ATLine* lines_ptr = response->p_intermediates;
120 char *line = NULL;
121 while(lines_ptr)
122 {
123 line = lines_ptr->line;
124 if(strStartsWith(line, "Revision"))
125 {
126 err = at_tok_start(&line);
127 if (err < 0)
128 {
129 goto exit;
130 }
131 memcpy(data, line, strlen(line));
132 break;
133 }
134 lines_ptr = lines_ptr->p_next;
135 }
136
137 goto exit;
138exit:
139 at_response_free(response);
140 return err;
141}
142
143/*
144ATI
145Manufacturer:"LYNQ"
146Model:"LYNQ_L508TLC"
147Revision:L508TLCv02.01b01.00
148IMEI:864788050901201
149
150OK
151
152*/
b.liu7ca612c2025-04-25 09:23:36 +0800153static int req_model_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800154{
155 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800156 int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800157
158 if (err < 0 || response->success == 0 || !response->p_intermediates){
159 *cme_err = at_get_cme_error(response);
160 goto exit;
161 }
162
163 ATLine* lines_ptr = response->p_intermediates;
164 char *line = NULL;
165 while(lines_ptr)
166 {
167 line = lines_ptr->line;
168 if(strStartsWith(line, "Model"))
169 {
170 err = at_tok_start(&line);
171 if (err < 0)
172 {
173 goto exit;
174 }
175 memcpy(data, line, strlen(line));
176 break;
177 }
178 lines_ptr = lines_ptr->p_next;
179 }
180
181 goto exit;
182exit:
183 at_response_free(response);
184 return err;
185}
186
187/*
188AT+ACONFIG="IMSD=1"
189or
190AT+ACONFIG="IMSD=0"
191
192OK
193*/
b.liu7ca612c2025-04-25 09:23:36 +0800194static int req_volte_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800195{
196 ATResponse *response = NULL;
197 char cmd[30] = {0};
198 if(state)
199 {
200 strcpy(cmd, "AT+ACONFIG=\"IMSD=1\"");
201 }
202 else
203 {
204 strcpy(cmd, "AT+ACONFIG=\"IMSD=0\"");
205 }
b.liu7ca612c2025-04-25 09:23:36 +0800206 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800207
208 if (err < 0 || response->success == 0) {
209 *cme_err = at_get_cme_error(response);
210 goto exit;
211 }
212
213 err = 0;
214exit:
215 at_response_free(response);
216 return err;
217}
218
219/*
220AT+ACONFIG?
221PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617
222
223OK
224*/
b.liu7ca612c2025-04-25 09:23:36 +0800225static int req_volte_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800226{
227 ATResponse *response = NULL;
b.liu62240ee2024-11-07 17:52:45 +0800228// char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800229 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+ACONFIG?", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800230
231 if (err < 0 || response->success == 0 || !response->p_intermediates){
232 *cme_err = at_get_cme_error(response);
233 goto exit;
234 }
235
236 char *line = response->p_intermediates->line;
237 char* ptr = strstr(line, "IMSD=");
238 if(ptr)
239 {
240 *state = atoi(ptr + strlen("IMSD="));
241 }
242 else
243 {
244 err = -1;
245 }
246exit:
247 at_response_free(response);
248 return err;
249}
250
251
252/*
253* Get system temperature.
254*
255* type[IN]:
256* 0: Soc temperature.
257* 1: RF temperature.
258* temp[OUT]:
259* temperature in celsius.
260*
261
262AT*RFTEMP
263*RFTEMP:0,28
264OK
265
266AT*SOCTEMP
267*SOCTEMP:24000
268OK
269
270*/
b.liu7ca612c2025-04-25 09:23:36 +0800271static int req_temp_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_temp_type_enum type, int16 *temp, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800272{
273 ATResponse *response = NULL;
274 int err = -1;
275 int tmp_int;
276 if(type == MBTK_TEMP_TYPE_SOC) { // Soc
b.liu7ca612c2025-04-25 09:23:36 +0800277 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*SOCTEMP", "*SOCTEMP:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800278 } else { // RF
b.liu7ca612c2025-04-25 09:23:36 +0800279 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*RFTEMP", "*RFTEMP:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800280 }
281
282 if (err < 0 || response->success == 0 || !response->p_intermediates){
283 *cme_err = at_get_cme_error(response);
284 goto exit;
285 }
286
287 char *line = response->p_intermediates->line;
288 err = at_tok_start(&line);
289 if (err < 0)
290 {
291 goto exit;
292 }
293 err = at_tok_nextint(&line, &tmp_int);
294 if (err < 0)
295 {
296 goto exit;
297 }
298
299 if(type == MBTK_TEMP_TYPE_RF) { // RF
300 err = at_tok_nextint(&line, &tmp_int);
301 if (err < 0)
302 {
303 goto exit;
304 }
305 *temp = (int16)tmp_int;
306 } else {
307 tmp_int = tmp_int / 1000;
308 *temp = (int16)tmp_int;
309 }
310
311exit:
312 at_response_free(response);
313 return err;
314}
315
316/*
317AT+CCLK?
318+CCLK: "23/03/20,01:58:00+32"
319
320OK
321
322*/
b.liu7ca612c2025-04-25 09:23:36 +0800323static int req_cell_time_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800324{
325 ATResponse *response = NULL;
326 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800327 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CCLK?", "+CCLK:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800328
329 if (err < 0 || response->success == 0 || !response->p_intermediates){
330 *cme_err = at_get_cme_error(response);
331 goto exit;
332 }
333
334 char *line = response->p_intermediates->line;
335 err = at_tok_start(&line);
336 if (err < 0)
337 {
338 goto exit;
339 }
340 err = at_tok_nextstr(&line, &tmp_ptr);
341 if (err < 0)
342 {
343 goto exit;
344 }
345 memcpy(data, tmp_ptr, strlen(tmp_ptr));
346
347exit:
348 at_response_free(response);
349 return err;
350}
351
352/*
3530: minimum functionality
3541: full functionality
3553: disable phone receive RF circuits.
3564: disable phone both transmit and receive RF circuits
3575: disable SIM
3586: turn off full secondary receive.
359-1: fail
360*/
b.liu7ca612c2025-04-25 09:23:36 +0800361mbtk_radio_state_enum ril_radio_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port)
b.liu87afc4c2024-08-14 17:33:45 +0800362{
363 ATResponse *p_response = NULL;
364 int err;
365 char *line;
366 int ret;
367
b.liu7ca612c2025-04-25 09:23:36 +0800368 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CFUN?", "+CFUN:", &p_response);
b.liu87afc4c2024-08-14 17:33:45 +0800369
370 if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
371 {
372 // assume radio is off
373 goto done;
374 }
375
376 line = p_response->p_intermediates->line;
377
378 err = at_tok_start(&line);
379 if (err < 0) goto done;
380
381 err = at_tok_nextint(&line, &ret);
382 if (err < 0) goto done;
383
384 at_response_free(p_response);
385
b.liu7ca612c2025-04-25 09:23:36 +0800386 ril_info.radio_state[sim_id] = (mbtk_radio_state_enum)ret;
b.liu87afc4c2024-08-14 17:33:45 +0800387
b.liu7ca612c2025-04-25 09:23:36 +0800388 return ril_info.radio_state[sim_id];
b.liu87afc4c2024-08-14 17:33:45 +0800389done:
390 at_response_free(p_response);
391 return MBTK_RADIO_STATE_UNKNOWN;
392}
393
b.liu7ca612c2025-04-25 09:23:36 +0800394mbtk_ril_err_enum ril_radio_state_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_radio_state_enum state, bool reset)
b.liu87afc4c2024-08-14 17:33:45 +0800395{
396 int err;
397 ATResponse *p_response = NULL;
398 mbtk_ril_err_enum ret = MBTK_RIL_ERR_UNKNOWN;
399
b.liu7ca612c2025-04-25 09:23:36 +0800400 if(state == ril_info.radio_state[sim_id]) {
b.liu87afc4c2024-08-14 17:33:45 +0800401 LOGE("Radio state is same.");
402 //return MBTK_RIL_ERR_PARAMETER;
403 return MBTK_RIL_ERR_SUCCESS;
404 }
405
406 LOGI("Set radio state - %d", state);
407
408 char cmd[64] = {0};
409 if(reset) {
410 snprintf(cmd, sizeof(cmd), "AT+CFUN=%d,1", state);
411 } else {
412 snprintf(cmd, sizeof(cmd), "AT+CFUN=%d", state);
413 }
b.liu7ca612c2025-04-25 09:23:36 +0800414 err = at_send_command(portType_2_portId(sim_id, port), cmd, &p_response);
b.liu87afc4c2024-08-14 17:33:45 +0800415 if (err || !p_response->success) {
416 goto done;
417 }
418
419 if(state == MBTK_RADIO_STATE_FULL_FUNC) { // +CFUN=1
b.liu7ca612c2025-04-25 09:23:36 +0800420 if(ril_radio_state_get(sim_id, port) == MBTK_RADIO_STATE_FULL_FUNC) { // success
421 ril_info.radio_state[sim_id] = MBTK_RADIO_STATE_FULL_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +0800422 ret = MBTK_RIL_ERR_SUCCESS;
423 LOGD("Radio open success.");
424 } else {
425 LOGW("Radio open fail.");
426 }
427 } else {
b.liu7ca612c2025-04-25 09:23:36 +0800428 ril_info.radio_state[sim_id] = state;
b.liu87afc4c2024-08-14 17:33:45 +0800429 ret = MBTK_RIL_ERR_SUCCESS;
430 LOGD("Set radio state to %d success.", state);
431 }
432
433done:
434 at_response_free(p_response);
435 return ret;
436}
437
b.liu9c19cc62024-11-28 09:43:02 +0800438/*
439AT*POWERIND=0"
440or
441AT*POWERIND=1~31"
442
443OK
444
b.liu2d7a5e42024-11-28 09:46:03 +0800445AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报,
446其中PS DATA目前暂时不支持,只是保留了这个标志位,0 means resume all.
b.liu9c19cc62024-11-28 09:43:02 +0800447
448AP power state: 1~31 means suspend,
449bitmap:
450bit0 - NETWORK;
451bit1 - SIM;
452bit2 - SMS;
453bit3 - CS CALL
454bit4 - PS DATA
455
456*/
b.liu7ca612c2025-04-25 09:23:36 +0800457static int req_powerind_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 state, int *cme_err)
b.liu9c19cc62024-11-28 09:43:02 +0800458{
459 ATResponse *response = NULL;
460 int err = -1;
461
462 if (state >= 0 && state < 32)
463 {
464 char cmd[100] = {0};
465 sprintf(cmd, "AT*POWERIND=%d", state);
b.liu7ca612c2025-04-25 09:23:36 +0800466 err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu9c19cc62024-11-28 09:43:02 +0800467 if (err < 0 || response->success == 0){
468 *cme_err = at_get_cme_error(response);
469 goto exit;
470 }
471 }
472
473exit:
474 at_response_free(response);
475 return err;
476}
477
b.liu7ca612c2025-04-25 09:23:36 +0800478static int req_md_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port,void *data, int *cme_err)
b.liu7d102f82025-03-26 18:30:21 +0800479{
480 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800481 int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT*CGMR", "", &response);
b.liu7d102f82025-03-26 18:30:21 +0800482
483 if (err < 0 || response->success == 0 || !response->p_intermediates)
484 {
485 *cme_err = at_get_cme_error(response);
486 goto exit;
487 }
488
489 ATLine* lines_ptr = response->p_intermediates;
490 char *line = NULL;
491 while(lines_ptr)
492 {
493 line = lines_ptr->line;
l.yange5332392025-05-13 03:16:04 -0700494 char *start = strstr(line, "FALCON_CP");
b.liu7d102f82025-03-26 18:30:21 +0800495 if(start)
496 {
497 char *end = strstr(start, "_Linux");
498 if(end)
499 {
500 end += strlen("_Linux");
501 int length = end - start;
502 if (length)
503 {
504 strncpy(data, start, length);
505 ((char*)data)[length] = '\0';
506 break;
507 }
508 else
509 {
510 err = -1;
511 goto exit;
512
513 }
514 }
515 else
516 {
517 err = -1;
518 goto exit;
519 }
520 }
521 lines_ptr = lines_ptr->p_next;
522 }
523
524 goto exit;
525exit:
526 at_response_free(response);
527 return err;
528}
529
b.liu87afc4c2024-08-14 17:33:45 +0800530
531//void net_list_free(void *data);
532// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
533// Otherwise, do not call pack_error_send().
534mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
535{
536 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
537 int cme_err = MBTK_RIL_ERR_CME_NON;
538 switch(pack->msg_id)
539 {
540 case RIL_MSG_ID_DEV_IMEI:
541 {
542 if(pack->data_len == 0 || pack->data == NULL) // Get IMEI
543 {
544 char imei[20] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800545 if(req_imei_get(cli_info->sim_id, cli_info->port, imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800546 {
547 if(cme_err != MBTK_RIL_ERR_CME_NON) {
548 err = MBTK_RIL_ERR_CME + cme_err;
549 } else {
550 err = MBTK_RIL_ERR_UNKNOWN;
551 }
552 LOG("Get IMEI fail.");
553 }
554 else
555 {
b.liu7ca612c2025-04-25 09:23:36 +0800556 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imei, strlen(imei));
b.liu87afc4c2024-08-14 17:33:45 +0800557 }
558 }
559 else // Set IMEI(Unsupport).
560 {
561 err = MBTK_RIL_ERR_UNSUPPORTED;
562 LOG("Unsupport set IMEI.");
563 }
564 break;
565 }
566 case RIL_MSG_ID_DEV_SN:
567 {
568 if(pack->data_len == 0 || pack->data == NULL)
569 {
570 char sn[20] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800571 if(req_sn_get(cli_info->sim_id, cli_info->port, sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800572 {
573 if(cme_err != MBTK_RIL_ERR_CME_NON) {
574 err = MBTK_RIL_ERR_CME + cme_err;
575 } else {
576 err = MBTK_RIL_ERR_UNKNOWN;
577 }
578 LOG("Get SN fail.");
579 }
580 else
581 {
b.liu7ca612c2025-04-25 09:23:36 +0800582 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, sn, strlen(sn));
b.liu87afc4c2024-08-14 17:33:45 +0800583 }
584 }
585 else // Set
586 {
587 err = MBTK_RIL_ERR_UNSUPPORTED;
588 LOG("Unsupport set SN.");
589 }
590 break;
591 }
592 case RIL_MSG_ID_DEV_MEID:
593 {
594 if(pack->data_len == 0 || pack->data == NULL)
595 {
596 err = MBTK_RIL_ERR_UNSUPPORTED;
597 LOG("Support only for CDMA.");
598 }
599 else // Set
600 {
601 err = MBTK_RIL_ERR_UNSUPPORTED;
602 LOG("Unsupport set MEID.");
603 }
604 break;
605 }
606 case RIL_MSG_ID_DEV_VERSION:
607 {
608 if(pack->data_len == 0 || pack->data == NULL)
609 {
610 char version[50] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800611 if(req_version_get(cli_info->sim_id, cli_info->port, version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800612 {
613 if(cme_err != MBTK_RIL_ERR_CME_NON) {
614 err = MBTK_RIL_ERR_CME + cme_err;
615 } else {
616 err = MBTK_RIL_ERR_UNKNOWN;
617 }
618 LOG("Get Version fail.");
619 }
620 else
621 {
b.liu7ca612c2025-04-25 09:23:36 +0800622 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen(version));
b.liu87afc4c2024-08-14 17:33:45 +0800623 }
624 }
625 else // Set
626 {
627 err = MBTK_RIL_ERR_UNSUPPORTED;
628 LOG("Unsupport set Version.");
629 }
630 break;
631 }
632 case RIL_MSG_ID_DEV_MODEL:
633 {
634 if(pack->data_len == 0 || pack->data == NULL)
635 {
636 char model[50] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800637 if(req_model_get(cli_info->sim_id, cli_info->port, model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800638 {
639 if(cme_err != MBTK_RIL_ERR_CME_NON) {
640 err = MBTK_RIL_ERR_CME + cme_err;
641 } else {
642 err = MBTK_RIL_ERR_UNKNOWN;
643 }
644 LOG("Get Version fail.");
645 }
646 else
647 {
b.liu7ca612c2025-04-25 09:23:36 +0800648 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, model, strlen(model));
b.liu87afc4c2024-08-14 17:33:45 +0800649 }
650 }
651 else // Set
652 {
653 err = MBTK_RIL_ERR_UNSUPPORTED;
654 LOG("Unsupport set Model.");
655 }
656 break;
657 }
658 case RIL_MSG_ID_DEV_VOLTE: // <uint8> 0:Close 1:Open
659 {
660 if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state.
661 {
662 int state;
b.liu7ca612c2025-04-25 09:23:36 +0800663 if(req_volte_get(cli_info->sim_id, cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800664 {
665 if(cme_err != MBTK_RIL_ERR_CME_NON) {
666 err = MBTK_RIL_ERR_CME + cme_err;
667 } else {
668 err = MBTK_RIL_ERR_UNKNOWN;
669 }
670 LOG("Get VoLTE state fail.");
671 }
672 else
673 {
b.liu7ca612c2025-04-25 09:23:36 +0800674 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
b.liu87afc4c2024-08-14 17:33:45 +0800675 }
676 }
677 else // Set VoLTE state.
678 {
679 if(pack->data == NULL || pack->data_len != sizeof(uint8)
680 || (*(pack->data) != 0 && *(pack->data) != 1))
681 {
682 err = MBTK_RIL_ERR_REQ_PARAMETER;
683 LOG("Set VOLTE parameter error.");
684 break;
685 }
686
687 uint8 on = *(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +0800688 if(req_volte_set(cli_info->sim_id, cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800689 {
690 if(cme_err != MBTK_RIL_ERR_CME_NON) {
691 err = MBTK_RIL_ERR_CME + cme_err;
692 } else {
693 err = MBTK_RIL_ERR_UNKNOWN;
694 }
695 LOG("Set VoLTE state fail.");
696 }
697 else
698 {
b.liu7ca612c2025-04-25 09:23:36 +0800699 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +0800700
701 // Restart is required to take effect.
702 // LOG("Will reboot system...");
703 }
704 }
705 break;
706 }
707 case RIL_MSG_ID_DEV_TEMP:
708 {
709 if(pack->data && pack->data_len == sizeof(uint8)) {
710 int16 temp;
711 mbtk_temp_type_enum type = (mbtk_temp_type_enum)(*(pack->data));
b.liu7ca612c2025-04-25 09:23:36 +0800712 if(req_temp_get(cli_info->sim_id, cli_info->port, type, &temp, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800713 {
714 if(cme_err != MBTK_RIL_ERR_CME_NON) {
715 err = MBTK_RIL_ERR_CME + cme_err;
716 } else {
717 err = MBTK_RIL_ERR_UNKNOWN;
718 }
719 LOG("Get temperature fail.");
720 }
721 else
722 {
b.liu7ca612c2025-04-25 09:23:36 +0800723 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &temp, sizeof(int16));
b.liu87afc4c2024-08-14 17:33:45 +0800724 }
725 } else {
726 err = MBTK_RIL_ERR_UNSUPPORTED;
727 LOG("Unsupport set Temperature.");
728 }
729 break;
730 }
731 case RIL_MSG_ID_DEV_CELL_TIME:
732 {
733 if(pack->data_len == 0 || pack->data == NULL) // Get Time
734 {
735 char time[100] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800736 if(req_cell_time_get(cli_info->sim_id, cli_info->port, time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800737 {
738 if(cme_err != MBTK_RIL_ERR_CME_NON) {
739 err = MBTK_RIL_ERR_CME + cme_err;
740 } else {
741 err = MBTK_RIL_ERR_UNKNOWN;
742 }
743 LOG("Get cell time fail.");
744 }
745 else
746 {
b.liu7ca612c2025-04-25 09:23:36 +0800747 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, time, strlen(time));
b.liu87afc4c2024-08-14 17:33:45 +0800748 }
749 }
750 else // Set Time
751 {
752 err = MBTK_RIL_ERR_UNSUPPORTED;
753 LOG("Unsupport set cell time.");
754 }
755 break;
756 }
757 case RIL_MSG_ID_DEV_MODEM:
758 {
759 if(pack->data_len == 0 || pack->data == NULL)
760 {
b.liu7ca612c2025-04-25 09:23:36 +0800761 mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->sim_id, cli_info->port);
b.liu87afc4c2024-08-14 17:33:45 +0800762 if(radio_state == MBTK_RADIO_STATE_UNKNOWN)
763 {
764 err = MBTK_RIL_ERR_UNKNOWN;
765 LOG("Get Version fail.");
766 }
767 else
768 {
b.liu7ca612c2025-04-25 09:23:36 +0800769 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &radio_state, sizeof(uint8));
b.liu87afc4c2024-08-14 17:33:45 +0800770 }
771 }
772 else // Set
773 {
774 // <func><reset>
775 if(pack->data && pack->data_len == 2) {
776 mbtk_radio_state_enum radio_state = (mbtk_radio_state_enum)(*(pack->data));
777 bool reset = *(pack->data + 1);
b.liu7ca612c2025-04-25 09:23:36 +0800778 err = ril_radio_state_set(cli_info->sim_id, cli_info->port, radio_state, reset);
b.liu87afc4c2024-08-14 17:33:45 +0800779 if(MBTK_RIL_ERR_SUCCESS == err) {
b.liu7ca612c2025-04-25 09:23:36 +0800780 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +0800781 }
782 } else {
783 err = MBTK_RIL_ERR_FORMAT;
784 }
785 }
786 break;
787 }
b.liu9c19cc62024-11-28 09:43:02 +0800788 case RIL_MSG_ID_DEV_POWERIND:
789 {
790 if(pack->data_len == 0 || pack->data == NULL)
791 {
792 err = MBTK_RIL_ERR_UNSUPPORTED;
793 LOG("Get POWERIND state UNSUPPORTED.");
794 }
795 else // Set powerind state.
796 {
797 uint8 state = *(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +0800798 if(req_powerind_set(cli_info->sim_id, cli_info->port, state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu9c19cc62024-11-28 09:43:02 +0800799 {
800 if(cme_err != MBTK_RIL_ERR_CME_NON) {
801 err = MBTK_RIL_ERR_CME + cme_err;
802 } else {
803 err = MBTK_RIL_ERR_UNKNOWN;
804 }
805 LOG("Set POWERIND state fail.");
806 }
807 else
808 {
809 // pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0);
b.liu7ca612c2025-04-25 09:23:36 +0800810 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu9c19cc62024-11-28 09:43:02 +0800811 }
812 }
813 break;
814 }
b.liu7d102f82025-03-26 18:30:21 +0800815 case RIL_MSG_ID_DEV_MD_VERSION_REQ:
816 {
817 if(pack->data_len == 0 || pack->data == NULL) // Get VERSION
818 {
819 char version[50] = {0};
b.liu7ca612c2025-04-25 09:23:36 +0800820 if(req_md_version_get(cli_info->sim_id, cli_info->port,version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu7d102f82025-03-26 18:30:21 +0800821 {
822 if(cme_err != MBTK_RIL_ERR_CME_NON) {
823 err = MBTK_RIL_ERR_CME + cme_err;
824 } else {
825 err = MBTK_RIL_ERR_UNKNOWN;
826 }
827 LOG("Get MD Version fail.");
828 }
829 else
830 {
b.liu7ca612c2025-04-25 09:23:36 +0800831 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen((char*)version));
b.liu7d102f82025-03-26 18:30:21 +0800832 }
833 }
834 break;
835
836 }
b.liu87afc4c2024-08-14 17:33:45 +0800837 default:
838 {
839 err = MBTK_RIL_ERR_REQ_UNKNOWN;
840 LOG("Unknown request : %s", id2str(pack->msg_id));
841 break;
842 }
843 }
844
845 return err;
846}
847
848
849
850