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 | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 20 | void 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); |
| 21 | ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | AT+CGSN |
| 25 | 864788050901201 |
| 26 | |
| 27 | OK |
| 28 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 29 | static int req_imei_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 30 | { |
| 31 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 32 | int err = at_send_command_numeric(portType_2_portId(sim_id, port), "AT+CGSN", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 33 | |
| 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)); |
| 40 | exit: |
| 41 | at_response_free(response); |
| 42 | return err; |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | AT+MRD_SN=R |
| 47 | +MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006 |
| 48 | |
| 49 | OK |
| 50 | |
| 51 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 52 | static int req_sn_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 53 | { |
| 54 | ATResponse *response = NULL; |
| 55 | char *tmp_ptr = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 56 | int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+MRD_SN=R", "+MRD_SN:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 57 | |
| 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; |
| 91 | exit: |
| 92 | at_response_free(response); |
| 93 | return err; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | ATI |
| 98 | Manufacturer:"LYNQ" |
| 99 | Model:"LYNQ_L508TLC" |
| 100 | Revision:L508TLCv02.01b01.00 |
| 101 | IMEI:864788050901201 |
| 102 | |
| 103 | OK |
| 104 | |
| 105 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 106 | static int req_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 107 | { |
| 108 | ATResponse *response = NULL; |
b.liu | 6917e9b | 2025-03-26 17:23:11 +0800 | [diff] [blame] | 109 | |
| 110 | // sleep(3); |
| 111 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 112 | int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 113 | |
| 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; |
| 138 | exit: |
| 139 | at_response_free(response); |
| 140 | return err; |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | ATI |
| 145 | Manufacturer:"LYNQ" |
| 146 | Model:"LYNQ_L508TLC" |
| 147 | Revision:L508TLCv02.01b01.00 |
| 148 | IMEI:864788050901201 |
| 149 | |
| 150 | OK |
| 151 | |
| 152 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 153 | static int req_model_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, void *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 154 | { |
| 155 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 156 | int err = at_send_command_multiline(portType_2_portId(sim_id, port), "ATI", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 157 | |
| 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; |
| 182 | exit: |
| 183 | at_response_free(response); |
| 184 | return err; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | AT+ACONFIG="IMSD=1" |
| 189 | or |
| 190 | AT+ACONFIG="IMSD=0" |
| 191 | |
| 192 | OK |
| 193 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 194 | static int req_volte_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 195 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 206 | int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 207 | |
| 208 | if (err < 0 || response->success == 0) { |
| 209 | *cme_err = at_get_cme_error(response); |
| 210 | goto exit; |
| 211 | } |
| 212 | |
| 213 | err = 0; |
| 214 | exit: |
| 215 | at_response_free(response); |
| 216 | return err; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | AT+ACONFIG? |
| 221 | PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617 |
| 222 | |
| 223 | OK |
| 224 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 225 | static int req_volte_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 226 | { |
| 227 | ATResponse *response = NULL; |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 228 | // char *tmp_ptr = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 229 | int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+ACONFIG?", "", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 230 | |
| 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 | } |
| 246 | exit: |
| 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 | |
| 262 | AT*RFTEMP |
| 263 | *RFTEMP:0,28 |
| 264 | OK |
| 265 | |
| 266 | AT*SOCTEMP |
| 267 | *SOCTEMP:24000 |
| 268 | OK |
| 269 | |
| 270 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 271 | static int req_temp_get(mbtk_sim_type_enum sim_id, 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] | 272 | { |
| 273 | ATResponse *response = NULL; |
| 274 | int err = -1; |
| 275 | int tmp_int; |
| 276 | if(type == MBTK_TEMP_TYPE_SOC) { // Soc |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 277 | err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*SOCTEMP", "*SOCTEMP:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 278 | } else { // RF |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 279 | err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*RFTEMP", "*RFTEMP:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 280 | } |
| 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 | |
| 311 | exit: |
| 312 | at_response_free(response); |
| 313 | return err; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | AT+CCLK? |
| 318 | +CCLK: "23/03/20,01:58:00+32" |
| 319 | |
| 320 | OK |
| 321 | |
| 322 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 323 | static int req_cell_time_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *data, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 324 | { |
| 325 | ATResponse *response = NULL; |
| 326 | char *tmp_ptr = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 327 | int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CCLK?", "+CCLK:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 328 | |
| 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 | |
| 347 | exit: |
| 348 | at_response_free(response); |
| 349 | return err; |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | 0: minimum functionality |
| 354 | 1: full functionality |
| 355 | 3: disable phone receive RF circuits. |
| 356 | 4: disable phone both transmit and receive RF circuits |
| 357 | 5: disable SIM |
| 358 | 6: turn off full secondary receive. |
| 359 | -1: fail |
| 360 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 361 | mbtk_radio_state_enum ril_radio_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 362 | { |
| 363 | ATResponse *p_response = NULL; |
| 364 | int err; |
| 365 | char *line; |
| 366 | int ret; |
| 367 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 368 | err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CFUN?", "+CFUN:", &p_response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 369 | |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 386 | ril_info.radio_state[sim_id] = (mbtk_radio_state_enum)ret; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 387 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 388 | return ril_info.radio_state[sim_id]; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 389 | done: |
| 390 | at_response_free(p_response); |
| 391 | return MBTK_RADIO_STATE_UNKNOWN; |
| 392 | } |
| 393 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 394 | mbtk_ril_err_enum ril_radio_state_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_radio_state_enum state, bool reset) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 395 | { |
| 396 | int err; |
| 397 | ATResponse *p_response = NULL; |
| 398 | mbtk_ril_err_enum ret = MBTK_RIL_ERR_UNKNOWN; |
| 399 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 400 | if(state == ril_info.radio_state[sim_id]) { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 401 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 414 | err = at_send_command(portType_2_portId(sim_id, port), cmd, &p_response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 415 | if (err || !p_response->success) { |
| 416 | goto done; |
| 417 | } |
| 418 | |
| 419 | if(state == MBTK_RADIO_STATE_FULL_FUNC) { // +CFUN=1 |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 420 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 422 | ret = MBTK_RIL_ERR_SUCCESS; |
| 423 | LOGD("Radio open success."); |
| 424 | } else { |
| 425 | LOGW("Radio open fail."); |
| 426 | } |
| 427 | } else { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 428 | ril_info.radio_state[sim_id] = state; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 429 | ret = MBTK_RIL_ERR_SUCCESS; |
| 430 | LOGD("Set radio state to %d success.", state); |
| 431 | } |
| 432 | |
| 433 | done: |
| 434 | at_response_free(p_response); |
| 435 | return ret; |
| 436 | } |
| 437 | |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 438 | /* |
| 439 | AT*POWERIND=0" |
| 440 | or |
| 441 | AT*POWERIND=1~31" |
| 442 | |
| 443 | OK |
| 444 | |
b.liu | 2d7a5e4 | 2024-11-28 09:46:03 +0800 | [diff] [blame] | 445 | AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报, |
| 446 | 其中PS DATA目前暂时不支持,只是保留了这个标志位,0 means resume all. |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 447 | |
| 448 | AP power state: 1~31 means suspend, |
| 449 | bitmap: |
| 450 | bit0 - NETWORK; |
| 451 | bit1 - SIM; |
| 452 | bit2 - SMS; |
| 453 | bit3 - CS CALL |
| 454 | bit4 - PS DATA |
| 455 | |
| 456 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 457 | static int req_powerind_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 state, int *cme_err) |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 458 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 466 | err = at_send_command(portType_2_portId(sim_id, port), cmd, &response); |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 467 | if (err < 0 || response->success == 0){ |
| 468 | *cme_err = at_get_cme_error(response); |
| 469 | goto exit; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | exit: |
| 474 | at_response_free(response); |
| 475 | return err; |
| 476 | } |
| 477 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 478 | static int req_md_version_get(mbtk_sim_type_enum sim_id, ATPortType_enum port,void *data, int *cme_err) |
b.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 479 | { |
| 480 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 481 | int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT*CGMR", "", &response); |
b.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 482 | |
| 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.yang | e533239 | 2025-05-13 03:16:04 -0700 | [diff] [blame^] | 494 | char *start = strstr(line, "FALCON_CP"); |
b.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 495 | 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; |
| 525 | exit: |
| 526 | at_response_free(response); |
| 527 | return err; |
| 528 | } |
| 529 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 530 | |
| 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(). |
| 534 | mbtk_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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 545 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 546 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 556 | ril_rsp_pack_send(cli_info->sim_id, 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] | 557 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 571 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 572 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 582 | ril_rsp_pack_send(cli_info->sim_id, 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] | 583 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 611 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 612 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 622 | ril_rsp_pack_send(cli_info->sim_id, 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] | 623 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 637 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 638 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 648 | ril_rsp_pack_send(cli_info->sim_id, 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] | 649 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 663 | if(req_volte_get(cli_info->sim_id, 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] | 664 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 674 | ril_rsp_pack_send(cli_info->sim_id, 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] | 675 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 688 | if(req_volte_set(cli_info->sim_id, 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] | 689 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 699 | ril_rsp_pack_send(cli_info->sim_id, 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] | 700 | |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 712 | if(req_temp_get(cli_info->sim_id, 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] | 713 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 723 | ril_rsp_pack_send(cli_info->sim_id, 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] | 724 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 736 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 737 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 747 | ril_rsp_pack_send(cli_info->sim_id, 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] | 748 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 761 | mbtk_radio_state_enum radio_state = ril_radio_state_get(cli_info->sim_id, cli_info->port); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 762 | if(radio_state == MBTK_RADIO_STATE_UNKNOWN) |
| 763 | { |
| 764 | err = MBTK_RIL_ERR_UNKNOWN; |
| 765 | LOG("Get Version fail."); |
| 766 | } |
| 767 | else |
| 768 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 769 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 770 | } |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 778 | err = ril_radio_state_set(cli_info->sim_id, cli_info->port, radio_state, reset); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 779 | if(MBTK_RIL_ERR_SUCCESS == err) { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 780 | ril_rsp_pack_send(cli_info->sim_id, 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] | 781 | } |
| 782 | } else { |
| 783 | err = MBTK_RIL_ERR_FORMAT; |
| 784 | } |
| 785 | } |
| 786 | break; |
| 787 | } |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 788 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 798 | if(req_powerind_set(cli_info->sim_id, cli_info->port, state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 799 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 810 | ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
b.liu | 9c19cc6 | 2024-11-28 09:43:02 +0800 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | break; |
| 814 | } |
b.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 815 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 820 | 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.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 821 | { |
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 831 | 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.liu | 7d102f8 | 2025-03-26 18:30:21 +0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | break; |
| 835 | |
| 836 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 837 | 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 | |