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 | ATDXXXXXXX; |
| 25 | OK |
| 26 | |
| 27 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 28 | static int req_call_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, char *phont_number, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 29 | { |
| 30 | ATResponse *response = NULL; |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 31 | // int tmp_int; |
| 32 | // char *tmp_str = NULL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 33 | char cmd[100] = {0}; |
| 34 | sprintf(cmd, "ATD%s;", phont_number); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 35 | 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] | 36 | if (err < 0 || response->success == 0){ |
| 37 | *cme_err = at_get_cme_error(response); |
| 38 | goto exit; |
| 39 | } |
| 40 | |
| 41 | exit: |
| 42 | at_response_free(response); |
| 43 | return err; |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | |
| 48 | AT+CHLD=2 |
| 49 | OK |
| 50 | |
| 51 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 52 | static int req_answer_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 53 | { |
| 54 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 55 | int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=2", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 56 | if (err < 0 || response->success == 0){ |
| 57 | *cme_err = at_get_cme_error(response); |
| 58 | goto exit; |
| 59 | } |
| 60 | |
| 61 | exit: |
| 62 | at_response_free(response); |
| 63 | return err; |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | ATH |
| 68 | OK |
| 69 | |
| 70 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 71 | static int req_hangup_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 72 | { |
| 73 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 74 | int err = at_send_command(portType_2_portId(sim_id, port), "ATH", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 75 | if (err < 0 || response->success == 0){ |
| 76 | *cme_err = at_get_cme_error(response); |
| 77 | goto exit; |
| 78 | } |
| 79 | |
| 80 | exit: |
| 81 | at_response_free(response); |
| 82 | return err; |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | AT+CHLD=1x |
| 87 | OK |
| 88 | |
| 89 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 90 | static int req_hangup_a_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int phone_id, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 91 | { |
| 92 | ATResponse *response = NULL; |
| 93 | char cmd[100] = {0}; |
| 94 | sprintf(cmd, "AT+CHLD=1%d", phone_id); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 95 | 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] | 96 | if (err < 0 || response->success == 0){ |
| 97 | *cme_err = at_get_cme_error(response); |
| 98 | goto exit; |
| 99 | } |
| 100 | |
| 101 | exit: |
| 102 | at_response_free(response); |
| 103 | return err; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | AT+CHLD=0 |
| 108 | OK |
| 109 | |
| 110 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 111 | static int req_hangup_waiting_or_background_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 112 | { |
| 113 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 114 | int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=0", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 115 | if (err < 0 || response->success == 0){ |
| 116 | *cme_err = at_get_cme_error(response); |
| 117 | goto exit; |
| 118 | } |
| 119 | |
| 120 | exit: |
| 121 | at_response_free(response); |
| 122 | return err; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | AT+CHLD=1 |
| 127 | OK |
| 128 | |
| 129 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 130 | static int req_hangup_foreground_resume_background_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 131 | { |
| 132 | ATResponse *response = NULL; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 133 | int err = at_send_command(portType_2_portId(sim_id, port), "AT+CHLD=1", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 134 | if (err < 0 || response->success == 0){ |
| 135 | *cme_err = at_get_cme_error(response); |
| 136 | goto exit; |
| 137 | } |
| 138 | |
| 139 | exit: |
| 140 | at_response_free(response); |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | AT+CLCC |
| 146 | OK |
| 147 | |
| 148 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 149 | static int req_waitin_call(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_call_info_t *reg, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 150 | { |
| 151 | ATResponse *response = NULL; |
| 152 | int tmp_int; |
| 153 | char *tmp_str = NULL; |
| 154 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 155 | int err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CLCC", "+CLCC:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 156 | if (err < 0 || response->success == 0){ |
| 157 | *cme_err = at_get_cme_error(response); |
| 158 | goto exit; |
| 159 | } |
| 160 | |
| 161 | if(response->success == 1 && !response->p_intermediates) |
| 162 | { |
| 163 | reg->call_wait = 0; |
| 164 | goto exit; |
| 165 | } |
| 166 | |
| 167 | reg->call_wait = 1; |
| 168 | char *line = response->p_intermediates->line; |
| 169 | err = at_tok_start(&line); |
| 170 | if (err < 0) |
| 171 | { |
| 172 | goto exit; |
| 173 | } |
| 174 | err = at_tok_nextint(&line, &tmp_int); // dir1 |
| 175 | if (err < 0) |
| 176 | { |
| 177 | goto exit; |
| 178 | } |
| 179 | reg->dir1 = (uint8)tmp_int; |
| 180 | err = at_tok_nextint(&line, &tmp_int);// dir |
| 181 | if (err < 0) |
| 182 | { |
| 183 | goto exit; |
| 184 | } |
| 185 | reg->dir = (uint8)tmp_int; |
| 186 | err = at_tok_nextint(&line, &tmp_int);// state |
| 187 | if (err < 0) |
| 188 | { |
| 189 | goto exit; |
| 190 | } |
| 191 | reg->state = (uint8)tmp_int; |
| 192 | err = at_tok_nextint(&line, &tmp_int);// mode |
| 193 | if (err < 0) |
| 194 | { |
| 195 | goto exit; |
| 196 | } |
| 197 | reg->mode = (uint8)tmp_int; |
| 198 | err = at_tok_nextint(&line, &tmp_int);// mpty |
| 199 | if (err < 0) |
| 200 | { |
| 201 | goto exit; |
| 202 | } |
| 203 | reg->mpty = (uint8)tmp_int; |
| 204 | err = at_tok_nextstr(&line, &tmp_str); // phone_number |
| 205 | if (err < 0) |
| 206 | { |
| 207 | goto exit; |
| 208 | } |
| 209 | memcpy(reg->phone_number, tmp_str, strlen(tmp_str)); |
| 210 | err = at_tok_nextint(&line, &tmp_int);// tpye |
| 211 | if (err < 0) |
| 212 | { |
| 213 | goto exit; |
| 214 | } |
| 215 | reg->type = (uint8)tmp_int; |
| 216 | |
| 217 | exit: |
| 218 | at_response_free(response); |
| 219 | return err; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | AT+CMUT? |
| 224 | +CMUT: 0 |
| 225 | |
| 226 | OK |
| 227 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 228 | static int req_mute_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] | 229 | { |
| 230 | ATResponse *response = NULL; |
| 231 | int tmp_int; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 232 | int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CMUT?", "+CMUT:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 233 | |
| 234 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 235 | *cme_err = at_get_cme_error(response); |
| 236 | goto exit; |
| 237 | } |
| 238 | |
| 239 | char *line = response->p_intermediates->line; |
| 240 | err = at_tok_start(&line); |
| 241 | if (err < 0) |
| 242 | { |
| 243 | goto exit; |
| 244 | } |
| 245 | err = at_tok_nextint(&line, &tmp_int); |
| 246 | if (err < 0) |
| 247 | { |
| 248 | goto exit; |
| 249 | } |
| 250 | *state = tmp_int; |
| 251 | |
| 252 | exit: |
| 253 | at_response_free(response); |
| 254 | return err; |
| 255 | } |
| 256 | |
| 257 | /* |
| 258 | AT+CMUT=0; |
| 259 | OK |
| 260 | |
| 261 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 262 | static int req_mute_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] | 263 | { |
| 264 | ATResponse *response = NULL; |
| 265 | char cmd[100] = {0}; |
| 266 | sprintf(cmd, "AT+CMUT=%d", state); |
| 267 | LOG("Set the mute command is = %s.\n", cmd); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 268 | 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] | 269 | if (err < 0 || response->success == 0){ |
| 270 | *cme_err = at_get_cme_error(response); |
| 271 | goto exit; |
| 272 | } |
| 273 | |
| 274 | exit: |
| 275 | at_response_free(response); |
| 276 | return err; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | AT+VTS=0; //0, 1, ..., 9, A, B, C, D, *, # |
| 281 | OK |
| 282 | |
| 283 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 284 | static int req_dtmf_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_call_dtmf_info_t *state, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 285 | { |
| 286 | ATResponse *response = NULL; |
| 287 | char cmd[100] = {0}; |
| 288 | sprintf(cmd, "AT+VTS=%c,%d", state->character, state->duration); |
| 289 | LOG("Set the DTMF command is = %s.\n", cmd); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 290 | 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] | 291 | if (err < 0 || response->success == 0){ |
| 292 | *cme_err = at_get_cme_error(response); |
| 293 | goto exit; |
| 294 | } |
| 295 | |
| 296 | exit: |
| 297 | at_response_free(response); |
| 298 | return err; |
| 299 | } |
| 300 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 301 | static int req_centric_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *state, int *cme_err) |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 302 | { |
| 303 | ATResponse *response = NULL; |
| 304 | int tmp_int = 0; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 305 | int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CEUS?", "+CEUS:", &response); |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 306 | |
| 307 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 308 | *cme_err = at_get_cme_error(response); |
| 309 | goto exit; |
| 310 | } |
| 311 | |
| 312 | char *line = response->p_intermediates->line; |
| 313 | err = at_tok_start(&line); |
| 314 | if (err < 0) |
| 315 | { |
| 316 | goto exit; |
| 317 | } |
| 318 | err = at_tok_nextint(&line, &tmp_int); |
| 319 | if (err < 0) |
| 320 | { |
| 321 | goto exit; |
| 322 | } |
| 323 | *state = tmp_int; |
| 324 | |
| 325 | exit: |
| 326 | at_response_free(response); |
| 327 | return err; |
| 328 | } |
| 329 | |
| 330 | /* |
| 331 | AT+CMUT=0; |
| 332 | OK |
| 333 | |
| 334 | */ |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 335 | static int req_centric_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int state, int *cme_err) |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 336 | { |
| 337 | ATResponse *response = NULL; |
| 338 | char cmd[100] = {0}; |
| 339 | sprintf(cmd, "AT+CEUS=%d", state); |
| 340 | LOG("Set the centric command is = %s.\n", cmd); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 341 | int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response); |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 342 | if (err < 0 || response->success == 0){ |
| 343 | *cme_err = at_get_cme_error(response); |
| 344 | goto exit; |
| 345 | } |
| 346 | |
| 347 | exit: |
| 348 | at_response_free(response); |
| 349 | return err; |
| 350 | } |
| 351 | |
| 352 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 353 | //void net_list_free(void *data); |
| 354 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 355 | // Otherwise, do not call pack_error_send(). |
| 356 | mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack) |
| 357 | { |
| 358 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS; |
| 359 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 360 | switch(pack->msg_id) |
| 361 | { |
| 362 | case RIL_MSG_ID_CALL_START: // <string> phone number |
| 363 | { |
| 364 | if(pack->data_len == 0 || pack->data == NULL) |
| 365 | { |
| 366 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 367 | } |
| 368 | else // Set |
| 369 | { |
| 370 | char *pn = (char*)(pack->data); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 371 | if(req_call_start(cli_info->sim_id, cli_info->port, pn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 372 | { |
| 373 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 374 | err = MBTK_RIL_ERR_CME + cme_err; |
| 375 | } else { |
| 376 | err = MBTK_RIL_ERR_UNKNOWN; |
| 377 | } |
| 378 | LOG("ATD fail."); |
| 379 | } |
| 380 | else |
| 381 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 382 | 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] | 383 | } |
| 384 | } |
| 385 | break; |
| 386 | } |
| 387 | case RIL_MSG_ID_CALL_ANSWER: |
| 388 | { |
| 389 | if(pack->data_len == 0 || pack->data == NULL) |
| 390 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 391 | if(req_answer_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 392 | { |
| 393 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 394 | err = MBTK_RIL_ERR_CME + cme_err; |
| 395 | } else { |
| 396 | err = MBTK_RIL_ERR_UNKNOWN; |
| 397 | } |
| 398 | LOG("Answer call fail."); |
| 399 | } |
| 400 | else |
| 401 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 402 | 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] | 403 | } |
| 404 | } |
| 405 | else // Set |
| 406 | { |
| 407 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 408 | LOG("Answer call fail. NO DATA\n"); |
| 409 | } |
| 410 | break; |
| 411 | } |
| 412 | case RIL_MSG_ID_CALL_HANGUP: |
| 413 | { |
| 414 | if(pack->data_len == 0 || pack->data == NULL) |
| 415 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 416 | if(req_hangup_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 417 | { |
| 418 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 419 | err = MBTK_RIL_ERR_CME + cme_err; |
| 420 | } else { |
| 421 | err = MBTK_RIL_ERR_UNKNOWN; |
| 422 | } |
| 423 | LOG("Hang up call fail."); |
| 424 | } |
| 425 | else |
| 426 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 427 | 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] | 428 | } |
| 429 | } |
| 430 | else // Set |
| 431 | { |
| 432 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 433 | LOG("Hang up call fail."); |
| 434 | } |
| 435 | break; |
| 436 | } |
| 437 | case RIL_MSG_ID_CALL_HANGUP_A: |
| 438 | { |
| 439 | if(pack->data_len == 0 || pack->data == NULL) |
| 440 | { |
| 441 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 442 | LOG("Hang up a call fail."); |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | uint8 phone_id = *(pack->data); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 447 | if(req_hangup_a_call(cli_info->sim_id, cli_info->port, phone_id, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 448 | { |
| 449 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 450 | err = MBTK_RIL_ERR_CME + cme_err; |
| 451 | } else { |
| 452 | err = MBTK_RIL_ERR_UNKNOWN; |
| 453 | } |
| 454 | LOG("Hang up a call fail."); |
| 455 | } |
| 456 | else |
| 457 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 458 | 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] | 459 | } |
| 460 | } |
| 461 | break; |
| 462 | } |
| 463 | case RIL_MSG_ID_CALL_HANGUP_B: |
| 464 | { |
| 465 | if(pack->data_len == 0 || pack->data == NULL) |
| 466 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 467 | if(req_hangup_waiting_or_background_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 468 | { |
| 469 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 470 | err = MBTK_RIL_ERR_CME + cme_err; |
| 471 | } else { |
| 472 | err = MBTK_RIL_ERR_UNKNOWN; |
| 473 | } |
| 474 | LOG("Hang up waiting_or_background call fail."); |
| 475 | } |
| 476 | else |
| 477 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 478 | 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] | 479 | } |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 484 | LOG("Hang up waiting_or_background call fail."); |
| 485 | } |
| 486 | break; |
| 487 | } |
| 488 | case RIL_MSG_ID_CALL_HANGUP_C: |
| 489 | { |
| 490 | if(pack->data_len == 0 || pack->data == NULL) |
| 491 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 492 | if(req_hangup_foreground_resume_background_call(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 493 | { |
| 494 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 495 | err = MBTK_RIL_ERR_CME + cme_err; |
| 496 | } else { |
| 497 | err = MBTK_RIL_ERR_UNKNOWN; |
| 498 | } |
| 499 | LOG("Hang up waiting_or_background call fail."); |
| 500 | } |
| 501 | else |
| 502 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 503 | 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] | 504 | } |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 509 | LOG("Hang up waiting_or_background call fail."); |
| 510 | } |
| 511 | break; |
| 512 | } |
| 513 | case RIL_MSG_ID_CALL_WAITIN: |
| 514 | { |
| 515 | if(pack->data_len == 0 || pack->data == NULL) |
| 516 | { |
| 517 | mbtk_call_info_t reg; |
| 518 | memset(®, 0, sizeof(mbtk_call_info_t)); |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 519 | if(req_waitin_call(cli_info->sim_id, cli_info->port, ®, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 520 | { |
| 521 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 522 | err = MBTK_RIL_ERR_CME + cme_err; |
| 523 | } else { |
| 524 | err = MBTK_RIL_ERR_UNKNOWN; |
| 525 | } |
| 526 | LOG("Wait incoing call fail."); |
| 527 | } |
| 528 | else |
| 529 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 530 | ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, ®, sizeof(mbtk_call_info_t)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | else // Set |
| 534 | { |
| 535 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 536 | LOG("Wait incoing call fail."); |
| 537 | } |
| 538 | break; |
| 539 | } |
| 540 | case RIL_MSG_ID_CALL_MUTE: |
| 541 | { |
| 542 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 543 | { |
| 544 | int state; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 545 | if(req_mute_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] | 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 mute state 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, &state, sizeof(uint8)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | else // Set mute state. |
| 560 | { |
| 561 | uint8 on = *(pack->data); |
| 562 | if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1)) |
| 563 | { |
| 564 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 565 | LOG("Set mute parameter error."); |
| 566 | break; |
| 567 | } |
| 568 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 569 | if(req_mute_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] | 570 | { |
| 571 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 572 | err = MBTK_RIL_ERR_CME + cme_err; |
| 573 | } else { |
| 574 | err = MBTK_RIL_ERR_UNKNOWN; |
| 575 | } |
| 576 | LOG("Set mute state fail."); |
| 577 | } |
| 578 | else |
| 579 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 580 | 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] | 581 | } |
| 582 | } |
| 583 | break; |
| 584 | } |
| 585 | case RIL_MSG_ID_CALL_DTMF: |
| 586 | { |
| 587 | if(pack->data_len == 0 || pack->data == NULL) |
| 588 | { |
| 589 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 590 | LOG("Wait incoing call fail."); |
| 591 | } |
| 592 | else // Set |
| 593 | { |
| 594 | mbtk_call_dtmf_info_t *reg = (mbtk_call_dtmf_info_t *)pack->data; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 595 | if(req_dtmf_set(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 596 | { |
| 597 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 598 | err = MBTK_RIL_ERR_CME + cme_err; |
| 599 | } else { |
| 600 | err = MBTK_RIL_ERR_UNKNOWN; |
| 601 | } |
| 602 | LOG("Wait incoing call fail."); |
| 603 | } |
| 604 | else |
| 605 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 606 | 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] | 607 | } |
| 608 | } |
| 609 | break; |
| 610 | } |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 611 | case RIL_MSG_ID_CALL_CENTRIC: |
| 612 | { |
| 613 | if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state. |
| 614 | { |
| 615 | int state; |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 616 | if(req_centric_get(cli_info->sim_id, cli_info->port, &state, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 617 | { |
| 618 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 619 | err = MBTK_RIL_ERR_CME + cme_err; |
| 620 | } else { |
| 621 | err = MBTK_RIL_ERR_UNKNOWN; |
| 622 | } |
| 623 | LOG("Get mute state fail."); |
| 624 | } |
| 625 | else |
| 626 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 627 | ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &state, sizeof(int)); |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | else // Set mute state. |
| 631 | { |
| 632 | uint8 on = *(pack->data); |
| 633 | if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1)) |
| 634 | { |
| 635 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 636 | LOG("Set mute parameter error."); |
| 637 | break; |
| 638 | } |
| 639 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 640 | if(req_centric_set(cli_info->sim_id, cli_info->port, on, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 641 | { |
| 642 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 643 | err = MBTK_RIL_ERR_CME + cme_err; |
| 644 | } else { |
| 645 | err = MBTK_RIL_ERR_UNKNOWN; |
| 646 | } |
| 647 | LOG("Set mute state fail."); |
| 648 | } |
| 649 | else |
| 650 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 651 | ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
liuyang | 3c60be9 | 2024-12-19 16:42:32 +0800 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | break; |
| 655 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 656 | default: |
| 657 | { |
| 658 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 659 | LOG("Unknown request : %s", id2str(pack->msg_id)); |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | return err; |
| 665 | } |
| 666 | |
| 667 | |
| 668 | |