b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1 | #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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 20 | void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 21 | |
| 22 | /* |
| 23 | AT+CGSN |
| 24 | 864788050901201 |
| 25 | |
| 26 | OK |
| 27 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 28 | static int req_imei_get(ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 29 | { |
| 30 | ATResponse *response = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 31 | int err = at_send_command_numeric(port, "AT+CGSN", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 32 | |
| 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)); |
| 39 | exit: |
| 40 | at_response_free(response); |
| 41 | return err; |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | AT+MRD_SN=R |
| 46 | +MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006 |
| 47 | |
| 48 | OK |
| 49 | |
| 50 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 51 | static int req_sn_get(ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 52 | { |
| 53 | ATResponse *response = NULL; |
| 54 | char *tmp_ptr = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 55 | int err = at_send_command_singleline(port, "AT+MRD_SN=R", "+MRD_SN:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 56 | |
| 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; |
| 90 | exit: |
| 91 | at_response_free(response); |
| 92 | return err; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | ATI |
| 97 | Manufacturer:"LYNQ" |
| 98 | Model:"LYNQ_L508TLC" |
| 99 | Revision:L508TLCv02.01b01.00 |
| 100 | IMEI:864788050901201 |
| 101 | |
| 102 | OK |
| 103 | |
| 104 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 105 | static int req_version_get(ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 106 | { |
| 107 | ATResponse *response = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 108 | int err = at_send_command_multiline(port, "ATI", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 109 | |
| 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; |
| 134 | exit: |
| 135 | at_response_free(response); |
| 136 | return err; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | ATI |
| 141 | Manufacturer:"LYNQ" |
| 142 | Model:"LYNQ_L508TLC" |
| 143 | Revision:L508TLCv02.01b01.00 |
| 144 | IMEI:864788050901201 |
| 145 | |
| 146 | OK |
| 147 | |
| 148 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 149 | static int req_model_get(ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 150 | { |
| 151 | ATResponse *response = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 152 | int err = at_send_command_multiline(port, "ATI", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 153 | |
| 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; |
| 178 | exit: |
| 179 | at_response_free(response); |
| 180 | return err; |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | AT+ACONFIG="IMSD=1" |
| 185 | or |
| 186 | AT+ACONFIG="IMSD=0" |
| 187 | |
| 188 | OK |
| 189 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 190 | static int req_volte_set(ATPortType_enum port, int state, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 191 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 202 | int err = at_send_command(port, cmd, &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 203 | |
| 204 | if (err < 0 || response->success == 0) { |
| 205 | *cme_err = at_get_cme_error(response); |
| 206 | goto exit; |
| 207 | } |
| 208 | |
| 209 | err = 0; |
| 210 | exit: |
| 211 | at_response_free(response); |
| 212 | return err; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | AT+ACONFIG? |
| 217 | PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617 |
| 218 | |
| 219 | OK |
| 220 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 221 | static int req_volte_get(ATPortType_enum port, int *state, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 222 | { |
| 223 | ATResponse *response = NULL; |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 224 | // char *tmp_ptr = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 225 | int err = at_send_command_singleline(port, "AT+ACONFIG?", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 226 | |
| 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 | } |
| 242 | exit: |
| 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 | |
| 258 | AT*RFTEMP |
| 259 | *RFTEMP:0,28 |
| 260 | OK |
| 261 | |
| 262 | AT*SOCTEMP |
| 263 | *SOCTEMP:24000 |
| 264 | OK |
| 265 | |
| 266 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 267 | static int req_temp_get(ATPortType_enum port, mbtk_temp_type_enum type, int16 *temp, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 268 | { |
| 269 | ATResponse *response = NULL; |
| 270 | int err = -1; |
| 271 | int tmp_int; |
| 272 | if(type == MBTK_TEMP_TYPE_SOC) { // Soc |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 273 | err = at_send_command_singleline(port, "AT*SOCTEMP", "*SOCTEMP:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 274 | } else { // RF |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 275 | err = at_send_command_singleline(port, "AT*RFTEMP", "*RFTEMP:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 276 | } |
| 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 | |
| 307 | exit: |
| 308 | at_response_free(response); |
| 309 | return err; |
| 310 | } |
| 311 | |
| 312 | /* |
| 313 | AT+CCLK? |
| 314 | +CCLK: "23/03/20,01:58:00+32" |
| 315 | |
| 316 | OK |
| 317 | |
| 318 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 319 | static int req_cell_time_get(ATPortType_enum port, char *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 320 | { |
| 321 | ATResponse *response = NULL; |
| 322 | char *tmp_ptr = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 323 | int err = at_send_command_singleline(port, "AT+CCLK?", "+CCLK:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 324 | |
| 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 | |
| 343 | exit: |
| 344 | at_response_free(response); |
| 345 | return err; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | 0: minimum functionality |
| 350 | 1: full functionality |
| 351 | 3: disable phone receive RF circuits. |
| 352 | 4: disable phone both transmit and receive RF circuits |
| 353 | 5: disable SIM |
| 354 | 6: turn off full secondary receive. |
| 355 | -1: fail |
| 356 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 357 | mbtk_radio_state_enum ril_radio_state_get(ATPortType_enum port) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 358 | { |
| 359 | ATResponse *p_response = NULL; |
| 360 | int err; |
| 361 | char *line; |
| 362 | int ret; |
| 363 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 364 | err = at_send_command_singleline(port, "AT+CFUN?", "+CFUN:", &p_response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 365 | |
| 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; |
| 385 | done: |
| 386 | at_response_free(p_response); |
| 387 | return MBTK_RADIO_STATE_UNKNOWN; |
| 388 | } |
| 389 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 390 | mbtk_ril_err_enum ril_radio_state_set(ATPortType_enum port, mbtk_radio_state_enum state, bool reset) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 391 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 410 | err = at_send_command(port, cmd, &p_response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 411 | if (err || !p_response->success) { |
| 412 | goto done; |
| 413 | } |
| 414 | |
| 415 | if(state == MBTK_RADIO_STATE_FULL_FUNC) { // +CFUN=1 |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 416 | if(ril_radio_state_get(port) == MBTK_RADIO_STATE_FULL_FUNC) { // success |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 417 | 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 | |
| 429 | done: |
| 430 | at_response_free(p_response); |
| 431 | return ret; |
| 432 | } |
| 433 | |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame^] | 434 | /* |
| 435 | AT*POWERIND=0" |
| 436 | or |
| 437 | AT*POWERIND=1~31" |
| 438 | |
| 439 | OK |
| 440 | |
| 441 | AT*POWERIND=31£¬¾ÍÏ൱ÓÚÉèÖÃNETWORK¡¢SIM¡¢SMS¡¢CS CALL¡¢PS DATA±ä»¯Ê±¶¼²»Ö÷¶¯Éϱ¨£¬ |
| 442 | ÆäÖÐPS DATAĿǰÔÝʱ²»Ö§³Ö£¬Ö»ÊDZ£ÁôÁËÕâ¸ö±ê־λ,0 means resume all. |
| 443 | |
| 444 | AP power state: 1~31 means suspend, |
| 445 | bitmap: |
| 446 | bit0 - NETWORK; |
| 447 | bit1 - SIM; |
| 448 | bit2 - SMS; |
| 449 | bit3 - CS CALL |
| 450 | bit4 - PS DATA |
| 451 | |
| 452 | */ |
| 453 | static 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 | |
| 470 | exit: |
| 471 | at_response_free(response); |
| 472 | return err; |
| 473 | } |
| 474 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 475 | |
| 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(). |
| 479 | mbtk_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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 490 | if(req_imei_get(cli_info->port, imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 491 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 501 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, imei, strlen(imei)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 502 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 516 | if(req_sn_get(cli_info->port, sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 517 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 527 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, sn, strlen(sn)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 528 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 556 | if(req_version_get(cli_info->port, version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 557 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 567 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, version, strlen(version)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 568 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 582 | if(req_model_get(cli_info->port, model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 583 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 593 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, model, strlen(model)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 594 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 608 | if(req_volte_get(cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 609 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 619 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(uint8)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 620 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 633 | if(req_volte_set(cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 634 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 644 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 645 | |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 657 | if(req_temp_get(cli_info->port, type, &temp, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 658 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 668 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &temp, sizeof(int16)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 669 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 681 | if(req_cell_time_get(cli_info->port, time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 682 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 692 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, time, strlen(time)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 693 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 706 | mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->port); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 707 | if(radio_state == MBTK_RADIO_STATE_UNKNOWN) |
| 708 | { |
| 709 | err = MBTK_RIL_ERR_UNKNOWN; |
| 710 | LOG("Get Version fail."); |
| 711 | } |
| 712 | else |
| 713 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 714 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &radio_state, sizeof(uint8)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 715 | } |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 723 | err = ril_radio_state_set(cli_info->port, radio_state, reset); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 724 | if(MBTK_RIL_ERR_SUCCESS == err) { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 725 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 726 | } |
| 727 | } else { |
| 728 | err = MBTK_RIL_ERR_FORMAT; |
| 729 | } |
| 730 | } |
| 731 | break; |
| 732 | } |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame^] | 733 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 760 | 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 | |