blob: fc70b70080cca5c592363a208b799ac7951ed9ca [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.liub171c9a2024-11-12 19:23:29 +080020void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
b.liu87afc4c2024-08-14 17:33:45 +080021
22/*
23AT+CGSN
24864788050901201
25
26OK
27*/
b.liub171c9a2024-11-12 19:23:29 +080028static int req_imei_get(ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080029{
30 ATResponse *response = NULL;
b.liub171c9a2024-11-12 19:23:29 +080031 int err = at_send_command_numeric(port, "AT+CGSN", &response);
b.liu87afc4c2024-08-14 17:33:45 +080032
33 if (err < 0 || response->success == 0 || !response->p_intermediates) {
34 *cme_err = at_get_cme_error(response);
35 goto exit;
36 }
37
38 memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line));
39exit:
40 at_response_free(response);
41 return err;
42}
43
44/*
45AT+MRD_SN=R
46+MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006
47
48OK
49
50*/
b.liub171c9a2024-11-12 19:23:29 +080051static int req_sn_get(ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080052{
53 ATResponse *response = NULL;
54 char *tmp_ptr = NULL;
b.liub171c9a2024-11-12 19:23:29 +080055 int err = at_send_command_singleline(port, "AT+MRD_SN=R", "+MRD_SN:", &response);
b.liu87afc4c2024-08-14 17:33:45 +080056
57 if (err < 0 || response->success == 0 || !response->p_intermediates){
58 *cme_err = at_get_cme_error(response);
59 goto exit;
60 }
61
62 char *line = response->p_intermediates->line;
63 err = at_tok_start(&line);
64 if (err < 0)
65 {
66 goto exit;
67 }
68
69 err = at_tok_nextstr(&line, &tmp_ptr);
70 if (err < 0)
71 {
72 goto exit;
73 }
74
75 err = at_tok_nextstr(&line, &tmp_ptr);
76 if (err < 0)
77 {
78 goto exit;
79 }
80
81 err = at_tok_nextstr(&line, &tmp_ptr);
82 if (err < 0)
83 {
84 goto exit;
85 }
86
87 memcpy(data, tmp_ptr, strlen(tmp_ptr));
88
89 goto exit;
90exit:
91 at_response_free(response);
92 return err;
93}
94
95/*
96ATI
97Manufacturer:"LYNQ"
98Model:"LYNQ_L508TLC"
99Revision:L508TLCv02.01b01.00
100IMEI:864788050901201
101
102OK
103
104*/
b.liub171c9a2024-11-12 19:23:29 +0800105static int req_version_get(ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800106{
107 ATResponse *response = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800108 int err = at_send_command_multiline(port, "ATI", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800109
110 if (err < 0 || response->success == 0 || !response->p_intermediates){
111 *cme_err = at_get_cme_error(response);
112 goto exit;
113 }
114
115 ATLine* lines_ptr = response->p_intermediates;
116 char *line = NULL;
117 while(lines_ptr)
118 {
119 line = lines_ptr->line;
120 if(strStartsWith(line, "Revision"))
121 {
122 err = at_tok_start(&line);
123 if (err < 0)
124 {
125 goto exit;
126 }
127 memcpy(data, line, strlen(line));
128 break;
129 }
130 lines_ptr = lines_ptr->p_next;
131 }
132
133 goto exit;
134exit:
135 at_response_free(response);
136 return err;
137}
138
139/*
140ATI
141Manufacturer:"LYNQ"
142Model:"LYNQ_L508TLC"
143Revision:L508TLCv02.01b01.00
144IMEI:864788050901201
145
146OK
147
148*/
b.liub171c9a2024-11-12 19:23:29 +0800149static int req_model_get(ATPortType_enum port, void *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800150{
151 ATResponse *response = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800152 int err = at_send_command_multiline(port, "ATI", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800153
154 if (err < 0 || response->success == 0 || !response->p_intermediates){
155 *cme_err = at_get_cme_error(response);
156 goto exit;
157 }
158
159 ATLine* lines_ptr = response->p_intermediates;
160 char *line = NULL;
161 while(lines_ptr)
162 {
163 line = lines_ptr->line;
164 if(strStartsWith(line, "Model"))
165 {
166 err = at_tok_start(&line);
167 if (err < 0)
168 {
169 goto exit;
170 }
171 memcpy(data, line, strlen(line));
172 break;
173 }
174 lines_ptr = lines_ptr->p_next;
175 }
176
177 goto exit;
178exit:
179 at_response_free(response);
180 return err;
181}
182
183/*
184AT+ACONFIG="IMSD=1"
185or
186AT+ACONFIG="IMSD=0"
187
188OK
189*/
b.liub171c9a2024-11-12 19:23:29 +0800190static int req_volte_set(ATPortType_enum port, int state, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800191{
192 ATResponse *response = NULL;
193 char cmd[30] = {0};
194 if(state)
195 {
196 strcpy(cmd, "AT+ACONFIG=\"IMSD=1\"");
197 }
198 else
199 {
200 strcpy(cmd, "AT+ACONFIG=\"IMSD=0\"");
201 }
b.liub171c9a2024-11-12 19:23:29 +0800202 int err = at_send_command(port, cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800203
204 if (err < 0 || response->success == 0) {
205 *cme_err = at_get_cme_error(response);
206 goto exit;
207 }
208
209 err = 0;
210exit:
211 at_response_free(response);
212 return err;
213}
214
215/*
216AT+ACONFIG?
217PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617
218
219OK
220*/
b.liub171c9a2024-11-12 19:23:29 +0800221static int req_volte_get(ATPortType_enum port, int *state, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800222{
223 ATResponse *response = NULL;
b.liu62240ee2024-11-07 17:52:45 +0800224// char *tmp_ptr = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800225 int err = at_send_command_singleline(port, "AT+ACONFIG?", "", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800226
227 if (err < 0 || response->success == 0 || !response->p_intermediates){
228 *cme_err = at_get_cme_error(response);
229 goto exit;
230 }
231
232 char *line = response->p_intermediates->line;
233 char* ptr = strstr(line, "IMSD=");
234 if(ptr)
235 {
236 *state = atoi(ptr + strlen("IMSD="));
237 }
238 else
239 {
240 err = -1;
241 }
242exit:
243 at_response_free(response);
244 return err;
245}
246
247
248/*
249* Get system temperature.
250*
251* type[IN]:
252* 0: Soc temperature.
253* 1: RF temperature.
254* temp[OUT]:
255* temperature in celsius.
256*
257
258AT*RFTEMP
259*RFTEMP:0,28
260OK
261
262AT*SOCTEMP
263*SOCTEMP:24000
264OK
265
266*/
b.liub171c9a2024-11-12 19:23:29 +0800267static int req_temp_get(ATPortType_enum port, mbtk_temp_type_enum type, int16 *temp, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800268{
269 ATResponse *response = NULL;
270 int err = -1;
271 int tmp_int;
272 if(type == MBTK_TEMP_TYPE_SOC) { // Soc
b.liub171c9a2024-11-12 19:23:29 +0800273 err = at_send_command_singleline(port, "AT*SOCTEMP", "*SOCTEMP:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800274 } else { // RF
b.liub171c9a2024-11-12 19:23:29 +0800275 err = at_send_command_singleline(port, "AT*RFTEMP", "*RFTEMP:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800276 }
277
278 if (err < 0 || response->success == 0 || !response->p_intermediates){
279 *cme_err = at_get_cme_error(response);
280 goto exit;
281 }
282
283 char *line = response->p_intermediates->line;
284 err = at_tok_start(&line);
285 if (err < 0)
286 {
287 goto exit;
288 }
289 err = at_tok_nextint(&line, &tmp_int);
290 if (err < 0)
291 {
292 goto exit;
293 }
294
295 if(type == MBTK_TEMP_TYPE_RF) { // RF
296 err = at_tok_nextint(&line, &tmp_int);
297 if (err < 0)
298 {
299 goto exit;
300 }
301 *temp = (int16)tmp_int;
302 } else {
303 tmp_int = tmp_int / 1000;
304 *temp = (int16)tmp_int;
305 }
306
307exit:
308 at_response_free(response);
309 return err;
310}
311
312/*
313AT+CCLK?
314+CCLK: "23/03/20,01:58:00+32"
315
316OK
317
318*/
b.liub171c9a2024-11-12 19:23:29 +0800319static int req_cell_time_get(ATPortType_enum port, char *data, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800320{
321 ATResponse *response = NULL;
322 char *tmp_ptr = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800323 int err = at_send_command_singleline(port, "AT+CCLK?", "+CCLK:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800324
325 if (err < 0 || response->success == 0 || !response->p_intermediates){
326 *cme_err = at_get_cme_error(response);
327 goto exit;
328 }
329
330 char *line = response->p_intermediates->line;
331 err = at_tok_start(&line);
332 if (err < 0)
333 {
334 goto exit;
335 }
336 err = at_tok_nextstr(&line, &tmp_ptr);
337 if (err < 0)
338 {
339 goto exit;
340 }
341 memcpy(data, tmp_ptr, strlen(tmp_ptr));
342
343exit:
344 at_response_free(response);
345 return err;
346}
347
348/*
3490: minimum functionality
3501: full functionality
3513: disable phone receive RF circuits.
3524: disable phone both transmit and receive RF circuits
3535: disable SIM
3546: turn off full secondary receive.
355-1: fail
356*/
b.liub171c9a2024-11-12 19:23:29 +0800357mbtk_radio_state_enum ril_radio_state_get(ATPortType_enum port)
b.liu87afc4c2024-08-14 17:33:45 +0800358{
359 ATResponse *p_response = NULL;
360 int err;
361 char *line;
362 int ret;
363
b.liub171c9a2024-11-12 19:23:29 +0800364 err = at_send_command_singleline(port, "AT+CFUN?", "+CFUN:", &p_response);
b.liu87afc4c2024-08-14 17:33:45 +0800365
366 if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
367 {
368 // assume radio is off
369 goto done;
370 }
371
372 line = p_response->p_intermediates->line;
373
374 err = at_tok_start(&line);
375 if (err < 0) goto done;
376
377 err = at_tok_nextint(&line, &ret);
378 if (err < 0) goto done;
379
380 at_response_free(p_response);
381
382 ril_info.radio_state = (mbtk_radio_state_enum)ret;
383
384 return ril_info.radio_state;
385done:
386 at_response_free(p_response);
387 return MBTK_RADIO_STATE_UNKNOWN;
388}
389
b.liub171c9a2024-11-12 19:23:29 +0800390mbtk_ril_err_enum ril_radio_state_set(ATPortType_enum port, mbtk_radio_state_enum state, bool reset)
b.liu87afc4c2024-08-14 17:33:45 +0800391{
392 int err;
393 ATResponse *p_response = NULL;
394 mbtk_ril_err_enum ret = MBTK_RIL_ERR_UNKNOWN;
395
396 if(state == ril_info.radio_state) {
397 LOGE("Radio state is same.");
398 //return MBTK_RIL_ERR_PARAMETER;
399 return MBTK_RIL_ERR_SUCCESS;
400 }
401
402 LOGI("Set radio state - %d", state);
403
404 char cmd[64] = {0};
405 if(reset) {
406 snprintf(cmd, sizeof(cmd), "AT+CFUN=%d,1", state);
407 } else {
408 snprintf(cmd, sizeof(cmd), "AT+CFUN=%d", state);
409 }
b.liub171c9a2024-11-12 19:23:29 +0800410 err = at_send_command(port, cmd, &p_response);
b.liu87afc4c2024-08-14 17:33:45 +0800411 if (err || !p_response->success) {
412 goto done;
413 }
414
415 if(state == MBTK_RADIO_STATE_FULL_FUNC) { // +CFUN=1
b.liub171c9a2024-11-12 19:23:29 +0800416 if(ril_radio_state_get(port) == MBTK_RADIO_STATE_FULL_FUNC) { // success
b.liu87afc4c2024-08-14 17:33:45 +0800417 ril_info.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
418 ret = MBTK_RIL_ERR_SUCCESS;
419 LOGD("Radio open success.");
420 } else {
421 LOGW("Radio open fail.");
422 }
423 } else {
424 ril_info.radio_state = state;
425 ret = MBTK_RIL_ERR_SUCCESS;
426 LOGD("Set radio state to %d success.", state);
427 }
428
429done:
430 at_response_free(p_response);
431 return ret;
432}
433
b.liu9c19cc62024-11-28 09:43:02 +0800434/*
435AT*POWERIND=0"
436or
437AT*POWERIND=1~31"
438
439OK
440
441AT*POWERIND=31£¬¾ÍÏ൱ÓÚÉèÖÃNETWORK¡¢SIM¡¢SMS¡¢CS CALL¡¢PS DATA±ä»¯Ê±¶¼²»Ö÷¶¯Éϱ¨£¬
442ÆäÖÐPS DATAĿǰÔÝʱ²»Ö§³Ö£¬Ö»ÊDZ£ÁôÁËÕâ¸ö±ê־λ,0 means resume all.
443
444AP power state: 1~31 means suspend,
445bitmap:
446bit0 - NETWORK;
447bit1 - SIM;
448bit2 - SMS;
449bit3 - CS CALL
450bit4 - PS DATA
451
452*/
453static int req_powerind_set(ATPortType_enum port, uint8 state, int *cme_err)
454{
455 ATResponse *response = NULL;
456 int err = -1;
457
458 if (state >= 0 && state < 32)
459 {
460 char cmd[100] = {0};
461 sprintf(cmd, "AT*POWERIND=%d", state);
462 LOG("Set the powerind command is = [%s]\n", cmd);
463 int err = at_send_command(port, cmd, &response);
464 if (err < 0 || response->success == 0){
465 *cme_err = at_get_cme_error(response);
466 goto exit;
467 }
468 }
469
470exit:
471 at_response_free(response);
472 return err;
473}
474
b.liu87afc4c2024-08-14 17:33:45 +0800475
476//void net_list_free(void *data);
477// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
478// Otherwise, do not call pack_error_send().
479mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
480{
481 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
482 int cme_err = MBTK_RIL_ERR_CME_NON;
483 switch(pack->msg_id)
484 {
485 case RIL_MSG_ID_DEV_IMEI:
486 {
487 if(pack->data_len == 0 || pack->data == NULL) // Get IMEI
488 {
489 char imei[20] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800490 if(req_imei_get(cli_info->port, imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800491 {
492 if(cme_err != MBTK_RIL_ERR_CME_NON) {
493 err = MBTK_RIL_ERR_CME + cme_err;
494 } else {
495 err = MBTK_RIL_ERR_UNKNOWN;
496 }
497 LOG("Get IMEI fail.");
498 }
499 else
500 {
b.liub171c9a2024-11-12 19:23:29 +0800501 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imei, strlen(imei));
b.liu87afc4c2024-08-14 17:33:45 +0800502 }
503 }
504 else // Set IMEI(Unsupport).
505 {
506 err = MBTK_RIL_ERR_UNSUPPORTED;
507 LOG("Unsupport set IMEI.");
508 }
509 break;
510 }
511 case RIL_MSG_ID_DEV_SN:
512 {
513 if(pack->data_len == 0 || pack->data == NULL)
514 {
515 char sn[20] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800516 if(req_sn_get(cli_info->port, sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800517 {
518 if(cme_err != MBTK_RIL_ERR_CME_NON) {
519 err = MBTK_RIL_ERR_CME + cme_err;
520 } else {
521 err = MBTK_RIL_ERR_UNKNOWN;
522 }
523 LOG("Get SN fail.");
524 }
525 else
526 {
b.liub171c9a2024-11-12 19:23:29 +0800527 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, sn, strlen(sn));
b.liu87afc4c2024-08-14 17:33:45 +0800528 }
529 }
530 else // Set
531 {
532 err = MBTK_RIL_ERR_UNSUPPORTED;
533 LOG("Unsupport set SN.");
534 }
535 break;
536 }
537 case RIL_MSG_ID_DEV_MEID:
538 {
539 if(pack->data_len == 0 || pack->data == NULL)
540 {
541 err = MBTK_RIL_ERR_UNSUPPORTED;
542 LOG("Support only for CDMA.");
543 }
544 else // Set
545 {
546 err = MBTK_RIL_ERR_UNSUPPORTED;
547 LOG("Unsupport set MEID.");
548 }
549 break;
550 }
551 case RIL_MSG_ID_DEV_VERSION:
552 {
553 if(pack->data_len == 0 || pack->data == NULL)
554 {
555 char version[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800556 if(req_version_get(cli_info->port, version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800557 {
558 if(cme_err != MBTK_RIL_ERR_CME_NON) {
559 err = MBTK_RIL_ERR_CME + cme_err;
560 } else {
561 err = MBTK_RIL_ERR_UNKNOWN;
562 }
563 LOG("Get Version fail.");
564 }
565 else
566 {
b.liub171c9a2024-11-12 19:23:29 +0800567 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen(version));
b.liu87afc4c2024-08-14 17:33:45 +0800568 }
569 }
570 else // Set
571 {
572 err = MBTK_RIL_ERR_UNSUPPORTED;
573 LOG("Unsupport set Version.");
574 }
575 break;
576 }
577 case RIL_MSG_ID_DEV_MODEL:
578 {
579 if(pack->data_len == 0 || pack->data == NULL)
580 {
581 char model[50] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800582 if(req_model_get(cli_info->port, model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800583 {
584 if(cme_err != MBTK_RIL_ERR_CME_NON) {
585 err = MBTK_RIL_ERR_CME + cme_err;
586 } else {
587 err = MBTK_RIL_ERR_UNKNOWN;
588 }
589 LOG("Get Version fail.");
590 }
591 else
592 {
b.liub171c9a2024-11-12 19:23:29 +0800593 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, model, strlen(model));
b.liu87afc4c2024-08-14 17:33:45 +0800594 }
595 }
596 else // Set
597 {
598 err = MBTK_RIL_ERR_UNSUPPORTED;
599 LOG("Unsupport set Model.");
600 }
601 break;
602 }
603 case RIL_MSG_ID_DEV_VOLTE: // <uint8> 0:Close 1:Open
604 {
605 if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state.
606 {
607 int state;
b.liub171c9a2024-11-12 19:23:29 +0800608 if(req_volte_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800609 {
610 if(cme_err != MBTK_RIL_ERR_CME_NON) {
611 err = MBTK_RIL_ERR_CME + cme_err;
612 } else {
613 err = MBTK_RIL_ERR_UNKNOWN;
614 }
615 LOG("Get VoLTE state fail.");
616 }
617 else
618 {
b.liub171c9a2024-11-12 19:23:29 +0800619 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8));
b.liu87afc4c2024-08-14 17:33:45 +0800620 }
621 }
622 else // Set VoLTE state.
623 {
624 if(pack->data == NULL || pack->data_len != sizeof(uint8)
625 || (*(pack->data) != 0 && *(pack->data) != 1))
626 {
627 err = MBTK_RIL_ERR_REQ_PARAMETER;
628 LOG("Set VOLTE parameter error.");
629 break;
630 }
631
632 uint8 on = *(pack->data);
b.liub171c9a2024-11-12 19:23:29 +0800633 if(req_volte_set(cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800634 {
635 if(cme_err != MBTK_RIL_ERR_CME_NON) {
636 err = MBTK_RIL_ERR_CME + cme_err;
637 } else {
638 err = MBTK_RIL_ERR_UNKNOWN;
639 }
640 LOG("Set VoLTE state fail.");
641 }
642 else
643 {
b.liub171c9a2024-11-12 19:23:29 +0800644 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +0800645
646 // Restart is required to take effect.
647 // LOG("Will reboot system...");
648 }
649 }
650 break;
651 }
652 case RIL_MSG_ID_DEV_TEMP:
653 {
654 if(pack->data && pack->data_len == sizeof(uint8)) {
655 int16 temp;
656 mbtk_temp_type_enum type = (mbtk_temp_type_enum)(*(pack->data));
b.liub171c9a2024-11-12 19:23:29 +0800657 if(req_temp_get(cli_info->port, type, &temp, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800658 {
659 if(cme_err != MBTK_RIL_ERR_CME_NON) {
660 err = MBTK_RIL_ERR_CME + cme_err;
661 } else {
662 err = MBTK_RIL_ERR_UNKNOWN;
663 }
664 LOG("Get temperature fail.");
665 }
666 else
667 {
b.liub171c9a2024-11-12 19:23:29 +0800668 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &temp, sizeof(int16));
b.liu87afc4c2024-08-14 17:33:45 +0800669 }
670 } else {
671 err = MBTK_RIL_ERR_UNSUPPORTED;
672 LOG("Unsupport set Temperature.");
673 }
674 break;
675 }
676 case RIL_MSG_ID_DEV_CELL_TIME:
677 {
678 if(pack->data_len == 0 || pack->data == NULL) // Get Time
679 {
680 char time[100] = {0};
b.liub171c9a2024-11-12 19:23:29 +0800681 if(req_cell_time_get(cli_info->port, time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +0800682 {
683 if(cme_err != MBTK_RIL_ERR_CME_NON) {
684 err = MBTK_RIL_ERR_CME + cme_err;
685 } else {
686 err = MBTK_RIL_ERR_UNKNOWN;
687 }
688 LOG("Get cell time fail.");
689 }
690 else
691 {
b.liub171c9a2024-11-12 19:23:29 +0800692 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, time, strlen(time));
b.liu87afc4c2024-08-14 17:33:45 +0800693 }
694 }
695 else // Set Time
696 {
697 err = MBTK_RIL_ERR_UNSUPPORTED;
698 LOG("Unsupport set cell time.");
699 }
700 break;
701 }
702 case RIL_MSG_ID_DEV_MODEM:
703 {
704 if(pack->data_len == 0 || pack->data == NULL)
705 {
b.liub171c9a2024-11-12 19:23:29 +0800706 mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->port);
b.liu87afc4c2024-08-14 17:33:45 +0800707 if(radio_state == MBTK_RADIO_STATE_UNKNOWN)
708 {
709 err = MBTK_RIL_ERR_UNKNOWN;
710 LOG("Get Version fail.");
711 }
712 else
713 {
b.liub171c9a2024-11-12 19:23:29 +0800714 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &radio_state, sizeof(uint8));
b.liu87afc4c2024-08-14 17:33:45 +0800715 }
716 }
717 else // Set
718 {
719 // <func><reset>
720 if(pack->data && pack->data_len == 2) {
721 mbtk_radio_state_enum radio_state = (mbtk_radio_state_enum)(*(pack->data));
722 bool reset = *(pack->data + 1);
b.liub171c9a2024-11-12 19:23:29 +0800723 err = ril_radio_state_set(cli_info->port, radio_state, reset);
b.liu87afc4c2024-08-14 17:33:45 +0800724 if(MBTK_RIL_ERR_SUCCESS == err) {
b.liub171c9a2024-11-12 19:23:29 +0800725 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +0800726 }
727 } else {
728 err = MBTK_RIL_ERR_FORMAT;
729 }
730 }
731 break;
732 }
b.liu9c19cc62024-11-28 09:43:02 +0800733 case RIL_MSG_ID_DEV_POWERIND:
734 {
735 if(pack->data_len == 0 || pack->data == NULL)
736 {
737 err = MBTK_RIL_ERR_UNSUPPORTED;
738 LOG("Get POWERIND state UNSUPPORTED.");
739 }
740 else // Set powerind state.
741 {
742 uint8 state = *(pack->data);
743 if(req_powerind_set(cli_info->port, state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
744 {
745 if(cme_err != MBTK_RIL_ERR_CME_NON) {
746 err = MBTK_RIL_ERR_CME + cme_err;
747 } else {
748 err = MBTK_RIL_ERR_UNKNOWN;
749 }
750 LOG("Set POWERIND state fail.");
751 }
752 else
753 {
754 // pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0);
755 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
756 }
757 }
758 break;
759 }
b.liu87afc4c2024-08-14 17:33:45 +0800760 default:
761 {
762 err = MBTK_RIL_ERR_REQ_UNKNOWN;
763 LOG("Unknown request : %s", id2str(pack->msg_id));
764 break;
765 }
766 }
767
768 return err;
769}
770
771
772
773