b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 1 | /*-----------------------------------------------------------------------------------------------*/ |
| 2 | /** |
| 3 | @file ql_sms.h |
| 4 | @brief SMS service API. |
| 5 | */ |
| 6 | /*-----------------------------------------------------------------------------------------------*/ |
| 7 | |
| 8 | /*------------------------------------------------------------------------------------------------- |
| 9 | Copyright (c) 2019 Quectel Wireless Solution, Co., Ltd. All Rights Reserved. |
| 10 | Quectel Wireless Solution Proprietary and Confidential. |
| 11 | -------------------------------------------------------------------------------------------------*/ |
| 12 | |
| 13 | /*------------------------------------------------------------------------------------------------- |
| 14 | EDIT HISTORY |
| 15 | This section contains comments describing changes made to the file. |
| 16 | Notice that changes are listed in reverse chronological order. |
| 17 | $Header: $ |
| 18 | when who what, where, why |
| 19 | -------- --- ---------------------------------------------------------- |
| 20 | 20200107 solomon.cui Add GSM-7bit and ISO 8859-1 conversion. |
| 21 | 20191225 solomon.cui Modify fucntion description. |
| 22 | 20191017 solomon.cui Free async reponse not user data. |
| 23 | 20190815 solomon.cui Add service type for sending message. |
| 24 | 20190627 solomon.cui Support asynchronously send msg and pdu |
| 25 | 20190625 solomon.cui Convert timestamp frome hex to dec. |
| 26 | 20190614 solomon.cui Created . |
| 27 | -------------------------------------------------------------------------------------------------*/ |
| 28 | #include "mbtk_type.h" |
| 29 | #include "mbtk_pdu_sms.h" |
| 30 | #include "mbtk_ril_api.h" |
| 31 | #include "mbtk_log.h" |
| 32 | #include "ql_sms.h" |
| 33 | #include "ql_type.h" |
| 34 | |
| 35 | #include <stdint.h> |
| 36 | #include <stdio.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <sys/epoll.h> |
| 39 | #include <unistd.h> |
| 40 | #include <errno.h> |
| 41 | #include <pthread.h> |
| 42 | #include <string.h> |
| 43 | #include <fcntl.h> |
| 44 | #include <time.h> |
| 45 | |
| 46 | #define MBTK_ERR_OK 0 |
| 47 | #define TELEPHONE_NUM_MAX 16 |
| 48 | #define MSM_NUMBER_MAX 2048+1 |
| 49 | #define RES_NUM_MIN 128 |
| 50 | #define TIME_ZONE_CN 32 |
| 51 | #define HAL_SMS_CONTENT_LEN 1024 |
| 52 | |
| 53 | typedef struct { |
| 54 | mbtk_ril_handle* handle; |
| 55 | ql_sms_msg_recv_cb_f recv_cb; |
| 56 | ql_sms_service_error_cb_f server_cb; |
| 57 | }ql_sms_info_handle_t; |
| 58 | |
| 59 | |
| 60 | static ql_sms_info_handle_t* sms_handle = NULL; |
| 61 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 62 | static mbtk_sim_type_enum s_sms_slot = MBTK_SIM_1; |
| 63 | |
| 64 | static bool check_slot_valid(QL_SIM_SLOT_E slot) |
| 65 | { |
| 66 | if (slot !=QL_SIM_SLOT_1 && slot != QL_SIM_SLOT_2) |
| 67 | { |
| 68 | LOGE("bad slot: %d, slot should be 1 or 2", slot); |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | static void ql_slot_convert_to_mbtk(QL_SIM_SLOT_E ql_slot,mbtk_sim_type_enum *mbtk_slot) |
| 76 | { |
| 77 | if(ql_slot == QL_SIM_SLOT_1) |
| 78 | { |
| 79 | *mbtk_slot = MBTK_SIM_1; |
| 80 | } |
| 81 | |
| 82 | if(ql_slot == QL_SIM_SLOT_2) |
| 83 | { |
| 84 | *mbtk_slot = MBTK_SIM_2; |
| 85 | } |
| 86 | return; |
| 87 | |
| 88 | } |
| 89 | |
| 90 | int ql_set_sms_slot(QL_SIM_SLOT_E log_slot) |
| 91 | { |
| 92 | if(!check_slot_valid(log_slot)) |
| 93 | { |
| 94 | LOGE("[%s] check_slot_valid failed.", __func__); |
| 95 | return QL_ERR_INVALID_ARG; |
| 96 | } |
| 97 | ql_slot_convert_to_mbtk(log_slot,&s_sms_slot); |
| 98 | LOGE("s_net_slot is %d",s_sms_slot); |
| 99 | return QL_ERR_OK; |
| 100 | } |
| 101 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 102 | static void ql_sms_state_change_cb(const void* data, int data_len) |
| 103 | { |
| 104 | LOGV("sms_state_change_cb()----------start\n"); |
| 105 | mbtk_ril_sms_state_info_t *ptr = (mbtk_ril_sms_state_info_t *)data; |
| 106 | |
| 107 | ql_sms_msg_t sms_msg; |
| 108 | ql_sms_timestamp_t sms_timestamp; |
| 109 | ql_sms_user_data_head_t sms_user_data_head; |
| 110 | |
| 111 | memset(&sms_msg,0x00, sizeof(ql_sms_msg_t)); |
| 112 | memset(&sms_timestamp,0x00, sizeof(ql_sms_timestamp_t)); |
| 113 | memset(&sms_user_data_head,0x00, sizeof(ql_sms_user_data_head_t)); |
| 114 | |
| 115 | char smsc[MDAPI_MAX_PDU_SIZE] = {0}; |
| 116 | char received_pdu[MDAPI_MAX_PDU_SIZE] = {0}; |
| 117 | char msg[MDAPI_MAX_PDU_SIZE] = {0}; |
| 118 | char num[MDAPI_MAX_PDU_SIZE] = {0}; |
| 119 | uint8 year[8] = {0}; |
| 120 | uint8 month[4] = {0}; |
| 121 | uint8 day[4] = {0}; |
| 122 | uint8 hour[4] = {0}; |
| 123 | uint8 minutes[4]= {0}; |
| 124 | uint8 seconds[4]= {0}; |
| 125 | //char timezone[4] = {0}; |
| 126 | char date[32] = {0}; |
| 127 | int charset = 0; |
| 128 | int ret = -1; |
| 129 | int curr_pack = 1; |
| 130 | int total_pack = 1; |
| 131 | if(ptr == NULL) |
| 132 | { |
| 133 | LOGE("ptr is null"); |
| 134 | } |
| 135 | LOGE("ptr: %s\n,data_len = %d\n", (char *)ptr->pdu, data_len); |
| 136 | if(data_len > MDAPI_MAX_PDU_SIZE) |
| 137 | { |
| 138 | strncpy(received_pdu, (const char *)ptr->pdu, MDAPI_MAX_PDU_SIZE-1); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | strncpy(received_pdu, (const char *)ptr->pdu, data_len); |
| 143 | } |
| 144 | ret = smsPduDecode((const char *)received_pdu, data_len, num, smsc, msg, &charset, &curr_pack, &total_pack,date); |
| 145 | if(ret != 0) |
| 146 | { |
| 147 | LOGE("smsPduDecode fail ret: %d\n",ret); |
| 148 | return ; |
| 149 | } |
| 150 | |
| 151 | LOGE("[EVENT][MT_SMS]PDU decode:smsc: %s\n, phone number: %s\ncharset: %d\n msg_len: %d\n message content: %s\n curr_pack: %d\n total_pack: %d\n date: %s", smsc, num, charset, strlen(msg), msg, curr_pack, total_pack, date); |
| 152 | |
| 153 | sms_msg.format = charset; |
| 154 | memcpy(sms_msg.addr, num, strlen(num)); |
| 155 | sms_msg.content_size = strlen(msg); |
| 156 | memcpy(sms_msg.content, msg, strlen(msg)); |
| 157 | |
| 158 | if(sscanf(date, "%4[^-]-%2[^-]-%2[^ ] %2[^:]:%2[^:]:%2s", year, month, day, hour, minutes, seconds)<=0) |
| 159 | { |
| 160 | LOGE("sscanf failed\n"); |
| 161 | } |
| 162 | |
| 163 | int tmp_year = atoi((char *)year); |
| 164 | |
| 165 | sms_timestamp.year = tmp_year-2000; |
| 166 | sms_timestamp.month = atoi((char *)month); |
| 167 | sms_timestamp.day = atoi((char *)day); |
| 168 | sms_timestamp.hours = atoi((char *)hour); |
| 169 | sms_timestamp.minutes = atoi((char *)minutes); |
| 170 | sms_timestamp.seconds = atoi((char *)seconds); |
| 171 | sms_timestamp.timezone = TIME_ZONE_CN; |
| 172 | |
| 173 | LOGE("Year: %d\n", sms_timestamp.year); |
| 174 | LOGE("Month: %d\n", sms_timestamp.month); |
| 175 | LOGE("Day: %d\n", sms_timestamp.day); |
| 176 | LOGE("Hour: %d\n", sms_timestamp.hours); |
| 177 | LOGE("Minute: %d\n", sms_timestamp.minutes); |
| 178 | LOGE("Second: %d\n", sms_timestamp.seconds); |
| 179 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 180 | if(total_pack > 1 && curr_pack <= total_pack) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 181 | { |
| 182 | sms_user_data_head.valid = TRUE; |
| 183 | sms_user_data_head.total_seg = total_pack; |
| 184 | sms_user_data_head.cur_seg_num = curr_pack; |
| 185 | } |
| 186 | else |
| 187 | { |
| 188 | sms_user_data_head.valid = FALSE; |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 189 | sms_user_data_head.total_seg = 0; |
| 190 | sms_user_data_head.cur_seg_num = 0; |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | if(sms_handle->recv_cb) |
| 194 | { |
| 195 | sms_handle->recv_cb(&sms_msg, &sms_timestamp, &sms_user_data_head); |
| 196 | } |
| 197 | |
| 198 | } |
| 199 | |
| 200 | static void ql_sms_server_change_cb(const void* data, int data_len) |
| 201 | { |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 202 | if(data) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 203 | { |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 204 | mbtk_ril_ser_state_enum server_state = *(mbtk_ril_ser_state_enum *)data; |
| 205 | if(sms_handle->server_cb && server_state == MBTK_RIL_SER_STATE_EXIT) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 206 | { |
| 207 | sms_handle->server_cb(QL_ERR_ABORTED); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /*-----------------------------------------------------------------------------------------------*/ |
| 214 | /** |
| 215 | @brief Initializes SMS service. |
| 216 | @return Whether the SMS service was initialized successfully. |
| 217 | @retval QL_ERR_OK successful. |
| 218 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 219 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 220 | @retval Other error code defined by ql_type.h. |
| 221 | */ |
| 222 | /*-----------------------------------------------------------------------------------------------*/ |
| 223 | int ql_sms_init(void) |
| 224 | { |
| 225 | if(NULL == sms_handle) |
| 226 | { |
| 227 | sms_handle = (ql_sms_info_handle_t*)malloc(sizeof(ql_sms_info_handle_t)); |
| 228 | if(NULL == sms_handle) |
| 229 | { |
| 230 | LOGE("[ql_sms_init] sms handle malloc fail."); |
| 231 | return QL_ERR_FAILED; |
| 232 | } |
| 233 | |
| 234 | sms_handle->handle = mbtk_ril_open(MBTK_AT_PORT_DEF); |
| 235 | if(NULL == sms_handle->handle) |
| 236 | { |
| 237 | LOGE("[ql_sms_init] mbtk handle init fail."); |
| 238 | if(sms_handle) |
| 239 | { |
| 240 | free(sms_handle); |
| 241 | sms_handle = NULL; |
| 242 | return QL_ERR_FAILED; |
| 243 | } |
| 244 | } |
| 245 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 246 | int err = mbtk_ds_sms_cnmi_set(sms_handle->handle,MBTK_SIM_1); |
| 247 | if(err) |
| 248 | { |
| 249 | LOGE("set cnmi fail"); |
| 250 | return QL_ERR_FAILED; |
| 251 | } |
| 252 | err = mbtk_ds_sms_cnmi_set(sms_handle->handle,MBTK_SIM_2); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 253 | if(err) |
| 254 | { |
| 255 | LOGE("set cnmi fail"); |
| 256 | return QL_ERR_FAILED; |
| 257 | } |
| 258 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 259 | int ret = mbtk_ds_sms_state_change_cb_reg(MBTK_SIM_1,ql_sms_state_change_cb); |
| 260 | if(ret != MBTK_ERR_OK) |
| 261 | { |
| 262 | LOGE("[ql_sms_init] set sms state cb fail.[%d]", ret); |
| 263 | if(sms_handle->handle) |
| 264 | { |
| 265 | mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 266 | sms_handle->handle = NULL; |
| 267 | return QL_ERR_FAILED; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | ret = mbtk_ds_sms_state_change_cb_reg(MBTK_SIM_2,ql_sms_state_change_cb); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 272 | if(ret != MBTK_ERR_OK) |
| 273 | { |
| 274 | LOGE("[ql_sms_init] set sms state cb fail.[%d]", ret); |
| 275 | if(sms_handle->handle) |
| 276 | { |
| 277 | mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 278 | sms_handle->handle = NULL; |
| 279 | return QL_ERR_FAILED; |
| 280 | } |
| 281 | } |
| 282 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 283 | ret = mbtk_ril_ser_state_change_cb_reg(ql_sms_server_change_cb); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 284 | if(ret != MBTK_ERR_OK) |
| 285 | { |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 286 | LOGE("[%s] mbtk_ril_ser_state_change_cb_reg fail.[%d]", __func__, ret); |
| 287 | if(sms_handle->handle) |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 288 | { |
| 289 | mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 290 | sms_handle->handle = NULL; |
| 291 | return QL_ERR_FAILED; |
| 292 | } |
| 293 | } |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 294 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 295 | sms_handle->recv_cb = NULL; |
| 296 | sms_handle->server_cb = NULL; |
| 297 | } |
| 298 | |
| 299 | return QL_ERR_OK; |
| 300 | |
| 301 | } |
| 302 | |
| 303 | /*-----------------------------------------------------------------------------------------------*/ |
| 304 | /** |
| 305 | @brief Deinitializes SMS service. |
| 306 | @return Whether the SMS service was deinitialized successfully. |
| 307 | @retval QL_ERR_OK successful. |
| 308 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 309 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 310 | @retval Other error code defined by ql_type.h. |
| 311 | */ |
| 312 | /*-----------------------------------------------------------------------------------------------*/ |
| 313 | int ql_sms_deinit(void) |
| 314 | { |
| 315 | if(NULL == sms_handle) |
| 316 | { |
| 317 | LOGE("[ql_sms_deinit] sms handle not init."); |
| 318 | return QL_ERR_NOT_INIT; |
| 319 | } |
| 320 | |
| 321 | int ret = 0; |
| 322 | sms_handle->server_cb = NULL; |
| 323 | sms_handle->recv_cb = NULL; |
| 324 | |
| 325 | if(NULL != sms_handle->handle) |
| 326 | { |
| 327 | ret = mbtk_ril_close(MBTK_AT_PORT_DEF); |
| 328 | if(ret != MBTK_ERR_OK) |
| 329 | { |
| 330 | LOGE("[ql_sms_deinit] mbtk handle deinit fail.[%d]", ret); |
| 331 | return QL_ERR_FAILED; |
| 332 | } |
| 333 | sms_handle->handle = NULL; |
| 334 | } |
| 335 | |
| 336 | if(ret != QL_ERR_OK) |
| 337 | { |
| 338 | LOGE("[ql_sms_deinit] cb thread free deinit fail."); |
| 339 | return QL_ERR_FAILED; |
| 340 | } |
| 341 | |
| 342 | free(sms_handle); |
| 343 | sms_handle = NULL; |
| 344 | return QL_ERR_OK; |
| 345 | |
| 346 | } |
| 347 | |
| 348 | /*-----------------------------------------------------------------------------------------------*/ |
| 349 | /** |
| 350 | @brief Sets the service center address. |
| 351 | @param[in] addr service center address. |
| 352 | @param[in] len service center address length. |
| 353 | @return Whether the service center address was set successfully. |
| 354 | @retval QL_ERR_OK successful. |
| 355 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 356 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 357 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 358 | @retval Other error code defined by ql_type.h. |
| 359 | */ |
| 360 | /*-----------------------------------------------------------------------------------------------*/ |
| 361 | int ql_sms_set_service_center_addr(char *addr, int len); |
| 362 | |
| 363 | /*-----------------------------------------------------------------------------------------------*/ |
| 364 | /** |
| 365 | @brief Gets the service center address. |
| 366 | @param[out] addr service center address. |
| 367 | @param[in] len service center address length. |
| 368 | @return Whether the service center address was successfully obtained. |
| 369 | @retval QL_ERR_OK successful. |
| 370 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 371 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 372 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 373 | @retval Other error code defined by ql_type.h. |
| 374 | */ |
| 375 | /*-----------------------------------------------------------------------------------------------*/ |
| 376 | int ql_sms_get_service_center_addr(char *addr, int len); |
| 377 | |
| 378 | /*-----------------------------------------------------------------------------------------------*/ |
| 379 | /** |
| 380 | @brief Sends message synchronously. |
| 381 | @param[in] p_msg pointer to ql_sms_msg_t. |
| 382 | @return Whether the message was successfully sent synchronously. |
| 383 | @retval QL_ERR_OK successful. |
| 384 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 385 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 386 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 387 | @retval Other error code defined by ql_type.h. |
| 388 | */ |
| 389 | /*-----------------------------------------------------------------------------------------------*/ |
| 390 | int ql_sms_send_msg(ql_sms_msg_t *p_msg); |
| 391 | |
| 392 | /*-----------------------------------------------------------------------------------------------*/ |
| 393 | /** |
| 394 | @brief Sends message asynchronously. |
| 395 | @param[in] p_msg pointer to ql_sms_msg_t |
| 396 | @param[out] id id for this async operation |
| 397 | @param[in] cb async callback |
| 398 | @return Whether the message was successfully sent asynchronously. |
| 399 | @retval QL_ERR_OK successful. |
| 400 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 401 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 402 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 403 | @retval Other error code defined by ql_type.h. |
| 404 | */ |
| 405 | /*-----------------------------------------------------------------------------------------------*/ |
| 406 | int ql_sms_send_msg_async(ql_sms_msg_t *p_msg, int *id, ql_sms_msg_async_cb_f cb) |
| 407 | { |
| 408 | if (NULL == sms_handle) |
| 409 | { |
| 410 | LOGE("handle NULL"); |
| 411 | return QL_ERR_FAILED; |
| 412 | } |
| 413 | |
| 414 | if (NULL == p_msg) |
| 415 | { |
| 416 | LOGE("p_msgt NULL"); |
| 417 | return QL_ERR_FAILED; |
| 418 | } |
| 419 | |
| 420 | if(NULL == id) |
| 421 | { |
| 422 | LOGE("id NULL"); |
| 423 | return QL_ERR_FAILED; |
| 424 | } |
| 425 | |
| 426 | int8 *phone_num = NULL; |
| 427 | int8 *msg = NULL; |
| 428 | int32 msg_len; |
| 429 | |
| 430 | char cmgs[MSM_NUMBER_MAX] = {0}; |
| 431 | char resp[RES_NUM_MIN] = {0}; |
| 432 | |
| 433 | char smscPDU[30] = {0}; |
| 434 | char **pdu = NULL; |
| 435 | char smsc[4] = {0}; |
| 436 | char msg_e_b[HAL_SMS_CONTENT_LEN] = {0};// +1 for end of string.*2:A char array contains two elements of a string for each value |
| 437 | |
| 438 | int char_set = 0; |
| 439 | //int lsms_flag = 0; |
| 440 | int err = 0; |
| 441 | int i = 0; |
| 442 | |
| 443 | msg = (int8 *)p_msg->content; |
| 444 | |
| 445 | msg_len = strlen(p_msg->content); |
| 446 | |
| 447 | phone_num = (int8 *)p_msg->addr; |
| 448 | |
| 449 | if (p_msg->format == 0)//7 |
| 450 | char_set = 0; |
| 451 | else if (p_msg->format == 1)//8 |
| 452 | char_set = 1; |
| 453 | else if (p_msg->format == 2)//UCS2 |
| 454 | char_set = 2; |
| 455 | else |
| 456 | { |
| 457 | LOGE("ql_sms_send_msg_async format error"); |
| 458 | return QL_ERR_FAILED; |
| 459 | } |
| 460 | |
| 461 | if(strcmp((char*)msg,"") == 0 || msg[0] == '\0') |
| 462 | { |
| 463 | LOGE("ql_sms_send_msg_async msg [%s]",msg); |
| 464 | return QL_ERR_FAILED; |
| 465 | } |
| 466 | |
| 467 | if(strcmp((char*)phone_num,"") == 0 || phone_num[0] == '\0') |
| 468 | { |
| 469 | LOGE("ql_sms_send_msg_async phone_num [%s]",phone_num); |
| 470 | return QL_ERR_FAILED; |
| 471 | } |
| 472 | |
| 473 | kal_int32 msg_num = 0; |
| 474 | kal_int32 pdu_msg_len = 0; |
| 475 | kal_int32 status = MDAPI_RET_ERROR; |
| 476 | kal_int32 index = 0; |
| 477 | |
| 478 | if(char_set == 1) //8bit |
| 479 | { |
| 480 | ArrayToStr((unsigned char *)msg, (unsigned int)msg_len, msg_e_b); |
| 481 | status = _mdapi_sms_get_msg_num(msg_e_b, char_set, &msg_num, &pdu_msg_len); |
| 482 | } |
| 483 | else //7bit usc2 |
| 484 | { |
| 485 | status = _mdapi_sms_get_msg_num((char *)msg, char_set, &msg_num, &pdu_msg_len); |
| 486 | } |
| 487 | |
| 488 | LOGE("msg_len = [%d] ,msg_num=[%d]",msg_len, msg_num); |
| 489 | if(status == MDAPI_RET_ERROR) |
| 490 | { |
| 491 | LOGE("get message number failed"); |
| 492 | return QL_ERR_FAILED; |
| 493 | } |
| 494 | else |
| 495 | { |
| 496 | //allocate memery for **pdu |
| 497 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 498 | if(pdu == NULL) |
| 499 | { |
| 500 | LOGE("allocate memory for pdu failed"); |
| 501 | return QL_ERR_FAILED; |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | for(index = 0; index < msg_num; index++) |
| 506 | { |
| 507 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 508 | if(pdu[index] == NULL) |
| 509 | { |
| 510 | for(i = 0; i < index; i++) |
| 511 | { |
| 512 | free(pdu[i]); |
| 513 | pdu[i] = NULL; |
| 514 | } |
| 515 | free(pdu); |
| 516 | pdu = NULL; |
| 517 | LOGE("allocate memory for pdu[%d] failed",index); |
| 518 | return QL_ERR_FAILED; |
| 519 | } |
| 520 | else |
| 521 | { |
| 522 | memset(pdu[index], 0, MAX_PDU_SIZE); |
| 523 | LOGE("pdu[%d} init value is: %s ",index, pdu[index]); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | //allocate memory for **pdu success |
| 530 | if(index == msg_num) |
| 531 | { |
| 532 | if(char_set == 1)//8bit |
| 533 | { |
| 534 | smsPduEncode(smsc, (char *)phone_num, msg_e_b, char_set, smscPDU, pdu); |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | smsPduEncode(smsc, (char *)phone_num, (char *)msg, char_set, smscPDU, pdu); |
| 539 | } |
| 540 | for(index = 0; index < msg_num; index++) |
| 541 | { |
| 542 | char pdu_data[MAX_PDU_SIZE] = {0}; |
| 543 | char *p = pdu_data; |
| 544 | |
| 545 | LOGE("index:%d",index); |
| 546 | LOGE("smscPDU: %s, pdu: %s",smscPDU, pdu[index]); |
| 547 | sprintf(p, "%s",smscPDU); |
| 548 | LOGE("pdu_data:%s\n", pdu_data); |
| 549 | int sc = strlen(pdu_data); |
| 550 | sprintf(p+strlen(p), "%s", pdu[index]); |
| 551 | LOGE("pdu_data:%s", pdu_data); |
| 552 | |
| 553 | int t = strlen(pdu_data); |
| 554 | sprintf(cmgs, "%d,%s", (t-sc)/2, pdu_data); |
| 555 | LOGE("cmgs:%s\n", cmgs); |
| 556 | memset(resp, 0, sizeof(resp)); |
| 557 | |
| 558 | err = mbtk_sms_cmgf_set(sms_handle->handle, 0); |
| 559 | if(err) |
| 560 | { |
| 561 | LOGE("cmgf set error : %d", err); |
| 562 | for(index = 0; index < msg_num; index++){ |
| 563 | free(pdu[index]); |
| 564 | pdu[index] = NULL; |
| 565 | } |
| 566 | free(pdu); |
| 567 | pdu = NULL; |
| 568 | return QL_ERR_FAILED; |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | LOGD("cmgf set success"); |
| 573 | } |
| 574 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 575 | err = mbtk_ds_sms_cmgs_set(sms_handle->handle,s_sms_slot, cmgs, resp); |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 576 | if(err) |
| 577 | { |
| 578 | LOGE("cmgs send fail (%d)",err); |
| 579 | for(index = 0; index < msg_num; index++){ |
| 580 | free(pdu[index]); |
| 581 | pdu[index] = NULL; |
| 582 | } |
| 583 | free(pdu); |
| 584 | pdu = NULL; |
| 585 | return QL_ERR_FAILED; |
| 586 | } |
| 587 | else |
| 588 | { |
| 589 | LOGD("cmgs send success, resp:%s", resp); |
| 590 | } |
| 591 | |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | for(index = 0; index < msg_num; index++){ |
| 596 | free(pdu[index]); |
| 597 | pdu[index] = NULL; |
| 598 | } |
| 599 | free(pdu); |
| 600 | pdu = NULL; |
| 601 | |
| 602 | *id = 1; |
| 603 | cb(1, 1); |
| 604 | |
| 605 | return QL_ERR_OK; |
| 606 | } |
| 607 | |
| 608 | /*-----------------------------------------------------------------------------------------------*/ |
| 609 | /** |
| 610 | @brief Sets SMS message reception callback hanlder. |
| 611 | @param[in] cb message reception callback handler. |
| 612 | @return Whether the message reception callback hanlder was set successfully. |
| 613 | @retval QL_ERR_OK successful. |
| 614 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 615 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 616 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 617 | @retval Other error code defined by ql_type.h. |
| 618 | */ |
| 619 | /*-----------------------------------------------------------------------------------------------*/ |
| 620 | int ql_sms_set_msg_recv_cb(ql_sms_msg_recv_cb_f cb) |
| 621 | { |
| 622 | if(NULL == sms_handle) |
| 623 | { |
| 624 | LOGE("[ql_sms_set_msg_recv_cb] sms handle not init."); |
| 625 | return QL_ERR_NOT_INIT; |
| 626 | } |
| 627 | |
| 628 | sms_handle->recv_cb = cb; |
| 629 | |
| 630 | return QL_ERR_OK; |
| 631 | |
| 632 | } |
| 633 | |
| 634 | /*-----------------------------------------------------------------------------------------------*/ |
| 635 | /** |
| 636 | @brief Sends PDU synchronously. |
| 637 | @param[in] p_pdu SMS PDU. |
| 638 | @return Whether the PDU was successfully sent synchronously. |
| 639 | @retval QL_ERR_OK successful. |
| 640 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 641 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 642 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 643 | @retval Other error code defined by ql_type.h. |
| 644 | */ |
| 645 | /*-----------------------------------------------------------------------------------------------*/ |
| 646 | int ql_sms_send_pdu(ql_sms_pdu_t *p_pdu); |
| 647 | |
| 648 | /*-----------------------------------------------------------------------------------------------*/ |
| 649 | /** |
| 650 | @brief Sends PDU asynchronously. |
| 651 | @param[in] p_pdu sms pdu. |
| 652 | @param[out] id id for this async operation. |
| 653 | @param[in] cb async callback. |
| 654 | @return Whether the PDU was successfully sent asynchronously. |
| 655 | @retval QL_ERR_OK successful. |
| 656 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 657 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 658 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 659 | @retval Other error code defined by ql_type.h. |
| 660 | */ |
| 661 | /*-----------------------------------------------------------------------------------------------*/ |
| 662 | int ql_sms_send_pdu_async(ql_sms_pdu_t *p_pdu, int *id, ql_sms_pdu_async_cb_f cb); |
| 663 | |
| 664 | /*-----------------------------------------------------------------------------------------------*/ |
| 665 | /** |
| 666 | @brief Sets SMS PDU reception callback hanlder. |
| 667 | @param[in] cb PDU reception callback handler. |
| 668 | @return Whether the PDU reception callback hanlder was set successfully. |
| 669 | @retval QL_ERR_OK successful. |
| 670 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 671 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 672 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 673 | @retval Other error code defined by ql_type.h. |
| 674 | */ |
| 675 | /*-----------------------------------------------------------------------------------------------*/ |
| 676 | int ql_sms_set_pdu_recv_cb(ql_sms_pdu_recv_cb_f cb); |
| 677 | |
| 678 | /*-----------------------------------------------------------------------------------------------*/ |
| 679 | /** |
| 680 | @brief Registration server error callback. Currently, only if the server exits abnormally, |
| 681 | the callback function will be executed, and the error code is QL_ERR_ABORTED; |
| 682 | @param[in] cb Callback function |
| 683 | @return |
| 684 | QL_ERR_OK - successful |
| 685 | Other - error code defined by ql_type.h |
| 686 | */ |
| 687 | /*-----------------------------------------------------------------------------------------------*/ |
| 688 | int ql_sms_set_service_error_cb(ql_sms_service_error_cb_f cb) |
| 689 | { |
| 690 | if(NULL == sms_handle) |
| 691 | { |
| 692 | LOGE("[ql_sms_set_service_error_cb] sms handle not init."); |
| 693 | return QL_ERR_NOT_INIT; |
| 694 | } |
| 695 | |
| 696 | sms_handle->server_cb = cb; |
| 697 | |
| 698 | return QL_ERR_OK; |
| 699 | } |
| 700 | |
| 701 | /*-----------------------------------------------------------------------------------------------*/ |
| 702 | /** |
| 703 | @brief Binds the current control point to a specific subscription. |
| 704 | @param[in] sub Subscription type. |
| 705 | @return Whether the subscription was successfully bound. |
| 706 | @retval QL_ERR_OK successful. |
| 707 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 708 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 709 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 710 | @retval Other error code defined by ql_type.h. |
| 711 | */ |
| 712 | /*-----------------------------------------------------------------------------------------------*/ |
| 713 | int ql_sms_bind_subscription(QL_SMS_SUBSCRIPTION_E sub); |
| 714 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 715 | |
| 716 | |