hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 1 | #include <stdbool.h> |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdint.h> |
| 5 | #include <dlfcn.h> |
| 6 | #include <time.h> |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 7 | #include "gsw_nw_interface.h" |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 8 | #include "gsw_log_interface.h" |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 9 | typedef unsigned short uint16_t; |
| 10 | typedef unsigned int uint32_t; |
| 11 | typedef unsigned char uint8_t; |
| 12 | typedef unsigned short uint16; |
| 13 | typedef uint32_t sms_client_handle_type; |
| 14 | typedef int kal_int32; |
| 15 | |
| 16 | |
| 17 | //qser include |
| 18 | |
| 19 | |
| 20 | |
| 21 | //mbtk include |
| 22 | typedef void (*mbtk_info_callback_func)(const void* data, int data_len); |
| 23 | typedef unsigned char uint8; |
| 24 | |
| 25 | typedef struct |
| 26 | { |
| 27 | int client_fd; |
| 28 | pthread_t read_thread_id; |
| 29 | int exit_fd[2]; |
| 30 | bool is_waitting; |
| 31 | pthread_cond_t cond; |
| 32 | pthread_mutex_t mutex; |
| 33 | |
| 34 | pthread_mutex_t send_mutex; |
| 35 | |
| 36 | // Temp response data. |
| 37 | uint16 info_err; |
| 38 | uint16 data_len; |
| 39 | void *data; |
| 40 | |
| 41 | //mbtk wyq for server_ready_status add start |
| 42 | char server_ready_status; |
| 43 | //mbtk wyq for server_ready_status add end |
| 44 | |
| 45 | mbtk_info_callback_func net_state_cb; |
| 46 | mbtk_info_callback_func call_state_cb; |
| 47 | mbtk_info_callback_func sms_state_cb; |
| 48 | mbtk_info_callback_func radio_state_cb; |
| 49 | mbtk_info_callback_func sim_state_cb; |
| 50 | mbtk_info_callback_func pdp_state_cb; |
| 51 | //add signal by xr |
| 52 | mbtk_info_callback_func signal_state_cb; |
| 53 | } mbtk_info_handle_t; |
| 54 | |
| 55 | // PDU include |
| 56 | enum EnumDCS { |
| 57 | BIT7 = 0, // GSM 字符集 |
| 58 | BIT8 = 1, // ASCII字符集 |
| 59 | UCS2 = 2 // Unicode 字符集 |
| 60 | }; |
| 61 | |
| 62 | struct SMS_Struct { |
| 63 | char *SCA; // 服务中心地址 |
| 64 | char *OA; // 发送方地址 |
| 65 | char *SCTS; // 服务中心时间戳 |
| 66 | struct UDHS *UDH; // 用户数据头 |
| 67 | char *UD; // 用户数据 |
| 68 | |
| 69 | bool RP; // 应答路径 |
| 70 | bool UDHI; // 用户数据头标识 |
| 71 | bool SRI; // 状态报告指示 |
| 72 | bool MMS; // 更多信息发送 |
| 73 | int MTI; // 信息类型指示 |
| 74 | |
| 75 | char PID; // PID 协议标识 |
| 76 | |
| 77 | enum EnumDCS DCS; // 数据编码方案 |
| 78 | bool TC; // 文本压缩指示 0: 未压缩 1:压缩 |
| 79 | int MC; // 消息类型 -1: 无 1:移动设备特定类型 2:SIM特定类型 3:终端设备特定类型 |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | struct PDUS { |
| 84 | unsigned int count; |
| 85 | char **PDU; |
| 86 | }; |
| 87 | |
| 88 | enum MDAPI_RET_e { |
| 89 | MDAPI_RET_SUCCESS = 0, |
| 90 | MDAPI_RET_ERROR = 1, |
| 91 | MDAPI_RET_TIMEOUT = 2, |
| 92 | MDAPI_RET_NOT_SUPPORT = 3, |
| 93 | }; |
| 94 | |
| 95 | #define MDAPI_TIME_STR_SIZE 22 |
| 96 | #define MDAPI_PHONE_NUMBER_SIZE 32 |
| 97 | #define MDAPI_MAX_PDU_SIZE 512 |
| 98 | #define MSM_NUMBER_MAX 2048+1 |
| 99 | #define RES_NUM_MIN 128 |
| 100 | #define MIN_MSM_PARAM_NUM 4 |
| 101 | #define MIN_IMS_MSM_PARAM_NUM 6 |
| 102 | #define MIN_WRITMSM_PARAM_NUM 5 |
| 103 | #define MSG_MAX_LEN 1024 |
| 104 | #define TELEPHONNUM_LEN 64 |
| 105 | #define STORAGSMS_MAX_SIZE 128 |
lichengzhang | 46a546c | 2025-06-17 16:24:55 +0800 | [diff] [blame] | 106 | #define SMSC_MAX_LEN 100 |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 107 | #define SMS_NUM_MAX 255 |
| 108 | #define MAX_OUT_SIZE 512 |
| 109 | #define MAX_PDU_SIZE 512 |
| 110 | #define MAX_DATE_SIZE 32 |
| 111 | |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 112 | GSW_SMS_Callback_fun gsw_sms_callback = NULL; |
| 113 | |
| 114 | #define lib_mbtk_path "/lib/libmbtk_lib.so" |
| 115 | #define lib_qser_sms_path "/lib/liblynq-qser-sms.so" |
| 116 | |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 117 | |
| 118 | static mbtk_info_handle_t* (*mbtk_info_handle_get)(void); |
| 119 | int (*mbtk_sms_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb); |
| 120 | static int (*mbtk_info_handle_free)(mbtk_info_handle_t** handle); |
| 121 | struct SMS_Struct (*PDUDecoding)(const char *data); |
| 122 | char *(*SCADecoding)(const char *data, int *EndIndex); |
| 123 | char *(*SCAEncoding)(char *SCA); |
| 124 | struct PDUS *(*PDUEncoding)(char *SCA, char *DA, char *UDC, struct UDHS *udhs); |
| 125 | int (*mbtk_sms_cmgf_set)(mbtk_info_handle_t* handle, int mode); |
| 126 | int (*mbtk_sms_cmgs_set)(mbtk_info_handle_t* handle, char * cmgs, char *resp); |
| 127 | int (*mbtk_sms_csca_set)(mbtk_info_handle_t* handle, char * csca); |
| 128 | int (*mbtk_sms_csca_get)(mbtk_info_handle_t* handle, char *buf); |
| 129 | int (*mbtk_sms_cnmi_set)(mbtk_info_handle_t* handle); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 130 | // static void (*mbtk_log)(int level, const char *format, ...); |
| 131 | // static void (*mbtk_log_init)(char *path, char *tag); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 132 | int (*smsPduEncode)(const char *smsc, const char *da_num, const char *msg, int charset, char *smsc_pdu, char **pdu); |
| 133 | int (*smsPduDecode)(const char *pdu_str, int pdu_len, char *da_num, char *smsc, char *msg, int *charset, int *curr_pack, int *total_pack, char *date); |
| 134 | kal_int32 (*_mdapi_sms_get_msg_num)(const char *msg, int charset, kal_int32 *msg_num, kal_int32 *msg_len); |
| 135 | |
l.yang | 6a42e4d | 2025-05-28 01:04:20 -0700 | [diff] [blame] | 136 | #define GSW_SMS "[HAL][GSW_SMS]" |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 137 | |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 138 | static mbtk_info_handle_t* sms_info_handle = NULL; |
| 139 | static sms_client_handle_type handle; |
| 140 | static char sms_center_address[SMSC_MAX_LEN] = {0}; |
| 141 | static void *dlHandle_mbtk; |
| 142 | static int init_flag = 0; |
| 143 | |
| 144 | static int mbtk_sms_import() |
| 145 | { |
| 146 | dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW); |
| 147 | if (dlHandle_mbtk == NULL) |
| 148 | { |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 149 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 150 | } |
| 151 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 152 | // mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init"); |
| 153 | // if (mbtk_log_init == NULL) |
| 154 | // { |
| 155 | // return GSW_HAL_NORMAL_FAIL; |
| 156 | // } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 157 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 158 | // mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log"); |
| 159 | // if (mbtk_log == NULL) |
| 160 | // { |
| 161 | // return GSW_HAL_NORMAL_FAIL; |
| 162 | // } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 163 | |
| 164 | mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get"); |
| 165 | if (mbtk_info_handle_get == NULL) |
| 166 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 167 | LOGE(GSW_SMS,"mbtk_info_handle_get dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 168 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | mbtk_sms_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_sms_state_change_cb_reg"); |
| 172 | if (mbtk_sms_state_change_cb_reg == NULL) |
| 173 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 174 | LOGE(GSW_SMS,"mbtk_sms_state_change_cb_reg dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 175 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | mbtk_info_handle_free = (int (*)(mbtk_info_handle_t** handle))dlsym(dlHandle_mbtk, "mbtk_info_handle_free"); |
| 179 | if (mbtk_info_handle_free == NULL) |
| 180 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 181 | LOGE(GSW_SMS,"mbtk_info_handle_free dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 182 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | PDUDecoding = (struct SMS_Struct (*)(const char *data))dlsym(dlHandle_mbtk, "PDUDecoding"); |
| 186 | if (PDUDecoding == NULL) |
| 187 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 188 | LOGE(GSW_SMS,"PDUDecoding dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 189 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | SCADecoding = (char *(*)(const char *data, int *EndIndex))dlsym(dlHandle_mbtk, "SCADecoding"); |
| 193 | if (SCADecoding == NULL) |
| 194 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 195 | LOGE(GSW_SMS,"SCADecoding dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 196 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | SCAEncoding = (char *(*)(char *SCA))dlsym(dlHandle_mbtk, "SCAEncoding"); |
| 200 | if (SCAEncoding == NULL) |
| 201 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 202 | LOGE(GSW_SMS,"SCAEncoding dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 203 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | PDUEncoding = (struct PDUS *(*)(char *SCA, char *DA, char *UDC, struct UDHS *udhs))dlsym(dlHandle_mbtk, "PDUEncoding"); |
| 207 | if (PDUEncoding == NULL) |
| 208 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 209 | LOGE(GSW_SMS,"PDUEncoding dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 210 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | mbtk_sms_cmgf_set = (int (*)(mbtk_info_handle_t* handle, int mode))dlsym(dlHandle_mbtk, "mbtk_sms_cmgf_set"); |
| 214 | if (mbtk_sms_cmgf_set == NULL) |
| 215 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 216 | LOGE(GSW_SMS,"mbtk_sms_cmgf_set dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 217 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | mbtk_sms_cmgs_set = (int (*)(mbtk_info_handle_t* handle, char * cmgs, char *resp))dlsym(dlHandle_mbtk, "mbtk_sms_cmgs_set"); |
| 221 | if (mbtk_sms_cmgs_set == NULL) |
| 222 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 223 | LOGE(GSW_SMS,"mbtk_sms_cmgs_set dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 224 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | mbtk_sms_csca_set = (int (*)(mbtk_info_handle_t* handle, char * csca))dlsym(dlHandle_mbtk, "mbtk_sms_csca_set"); |
| 228 | if (mbtk_sms_csca_set == NULL) |
| 229 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 230 | LOGE(GSW_SMS,"mbtk_sms_csca_set dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 231 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | mbtk_sms_csca_get = (int (*)(mbtk_info_handle_t* handle, char *buf))dlsym(dlHandle_mbtk, "mbtk_sms_csca_get"); |
| 235 | if (mbtk_sms_csca_get == NULL) |
| 236 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 237 | LOGE(GSW_SMS,"mbtk_sms_csca_get dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 238 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | mbtk_sms_cnmi_set = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_sms_cnmi_set"); |
| 242 | if (mbtk_sms_cnmi_set == NULL) |
| 243 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 244 | LOGE(GSW_SMS,"mbtk_sms_cnmi_set dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 245 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | smsPduEncode = (int (*)(const char *smsc, const char *da_num, const char *msg, int charset, char *smsc_pdu, char **pdu))dlsym(dlHandle_mbtk, "smsPduEncode"); |
| 249 | if (smsPduEncode == NULL) |
| 250 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 251 | LOGE(GSW_SMS,"smsPduEncode dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 252 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | |
| 256 | smsPduDecode = (int (*)(const char *pdu_str, int pdu_len, char *da_num, char *smsc, char *msg, int *charset, int *curr_pack, int *total_pack, char *date))dlsym(dlHandle_mbtk,"smsPduDecode"); |
| 257 | if (smsPduDecode == NULL) |
| 258 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 259 | LOGE(GSW_SMS,"smsPduDecode dlsym fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 260 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | _mdapi_sms_get_msg_num = (kal_int32 (*)(const char *msg, int charset, kal_int32 *msg_num, kal_int32 *msg_len))dlsym(dlHandle_mbtk,"_mdapi_sms_get_msg_num"); |
| 264 | if (_mdapi_sms_get_msg_num == NULL) |
| 265 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 266 | LOGE(GSW_SMS,"_mdapi_sms_get_msg_num dlsym fail"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 267 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | return GSW_HAL_SUCCESS; |
| 271 | |
| 272 | } |
| 273 | |
| 274 | void ArrayToStr(unsigned char *Buff, unsigned int BuffLen, char *OutputStr) |
| 275 | { |
| 276 | int i = 0; |
| 277 | char TempBuff[MSG_MAX_LEN * 2 +1] = {0}; |
| 278 | char strBuff[MSG_MAX_LEN * 2 +1] = {0}; |
| 279 | |
| 280 | for(i = 0; i<BuffLen;i++) |
| 281 | { |
| 282 | sprintf(TempBuff,"%02x",(unsigned char)Buff[i]); |
lichengzhang | dab5ee7 | 2025-07-21 18:03:00 +0800 | [diff] [blame^] | 283 | strncat(strBuff,TempBuff,2); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 284 | } |
| 285 | strncpy(OutputStr, strBuff, BuffLen*2); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | void gsw_sms_state_change_cb(const void* data, int data_len) { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 290 | LOGD(GSW_SMS,"gsw_sms_state_change_cb -------start\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 291 | |
| 292 | uint8 *ptr = (uint8*)data; |
| 293 | |
| 294 | if (!strncmp("+CMT:", (const char *)ptr, 5))//丢弃无用消息 |
| 295 | return ; |
| 296 | |
| 297 | gsw_sms_msg_type_t gsw_sms_msg; |
| 298 | gsw_sms_date_t gsw_sms_date; |
| 299 | |
| 300 | memset(&gsw_sms_msg, 0, sizeof(gsw_sms_msg_type_t)); |
| 301 | memset(&gsw_sms_date, 0, sizeof(gsw_sms_date_t)); |
| 302 | |
| 303 | char smsc[MDAPI_MAX_PDU_SIZE] = {0}; |
| 304 | char received_pdu[MDAPI_MAX_PDU_SIZE] = {0}; |
| 305 | char msg[MDAPI_MAX_PDU_SIZE] = {0}; |
| 306 | char num[MDAPI_MAX_PDU_SIZE] = {0}; |
| 307 | char date[MAX_DATE_SIZE] = {0}; |
| 308 | int charset = 0; |
| 309 | int ret = -1; |
| 310 | int curr_pack = 1; |
| 311 | int total_pack = 1; |
| 312 | if(ptr == NULL) |
| 313 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 314 | LOGE(GSW_SMS,"ptr is null"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 315 | } |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 316 | LOGE(GSW_SMS,"ptr: %s\n,data_len = %d\n", (char *)ptr, data_len); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 317 | if(data_len > MDAPI_MAX_PDU_SIZE) |
| 318 | { |
| 319 | strncpy(received_pdu, (const char *)ptr, MDAPI_MAX_PDU_SIZE-1); |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | strncpy(received_pdu, (const char *)ptr, data_len); |
| 324 | } |
| 325 | ret = smsPduDecode((const char *)received_pdu, data_len, num, smsc, msg, &charset, &curr_pack, &total_pack,date); |
| 326 | if(ret != 0) |
| 327 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 328 | LOGE(GSW_SMS,"smsPduDecode fail\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 329 | return ; |
| 330 | } |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 331 | LOGE(GSW_SMS,"smsPduDecode ret: %d\n", ret); |
| 332 | LOGE(GSW_SMS,"SMS :%s, %s, %d\n", __FILE__, __FUNCTION__, __LINE__); |
| 333 | LOGE(GSW_SMS,"[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); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 334 | |
| 335 | gsw_sms_msg.content_encode = charset; |
| 336 | memcpy(gsw_sms_msg.src_num, num, strlen(num)); |
| 337 | gsw_sms_msg.content_len = strlen(msg); |
| 338 | memcpy(gsw_sms_msg.content, msg, strlen(msg)); |
| 339 | |
| 340 | if(sscanf(date, "%4[^-]-%2[^-]-%2[^ ] %2[^:]:%2[^:]:%2s", (char*)gsw_sms_date.year, (char*)gsw_sms_date.month, (char*)gsw_sms_date.day, (char*)gsw_sms_date.hour, (char*)gsw_sms_date.minutes, (char*)gsw_sms_date.seconds)<=0) |
| 341 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 342 | LOGE(GSW_SMS,"sscanf failed\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | snprintf((char *)gsw_sms_date.timezone, sizeof(gsw_sms_date.timezone), "%s","+8"); |
| 346 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 347 | LOGE(GSW_SMS,"Year: %s\n", (char*)gsw_sms_date.year); |
| 348 | LOGE(GSW_SMS,"Month: %s\n", (char*)gsw_sms_date.month); |
| 349 | LOGE(GSW_SMS,"Day: %s\n", (char*)gsw_sms_date.day); |
| 350 | LOGE(GSW_SMS,"Hour: %s\n", (char*)gsw_sms_date.hour); |
| 351 | LOGE(GSW_SMS,"Minute: %s\n", (char*)gsw_sms_date.minutes); |
| 352 | LOGE(GSW_SMS,"Second: %s\n", (char*)gsw_sms_date.seconds); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 353 | |
| 354 | gsw_sms_msg.date = gsw_sms_date; |
| 355 | |
| 356 | if(gsw_sms_callback) |
| 357 | { |
lichengzhang | 7704687 | 2025-07-07 11:45:51 +0800 | [diff] [blame] | 358 | // if(total_pack > 1 && curr_pack < total_pack) |
| 359 | // { |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 360 | gsw_sms_callback(GSW_SMS_RECEIVED_FLG, &gsw_sms_msg); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 361 | LOGD(GSW_SMS,"the gsw_sms_state_e is %d\n",GSW_SMS_RECEIVED_FLG); |
lichengzhang | 7704687 | 2025-07-07 11:45:51 +0800 | [diff] [blame] | 362 | // } |
| 363 | // else |
| 364 | // { |
| 365 | // gsw_sms_callback(GSW_SMS_FULL_FLG, &gsw_sms_msg); |
| 366 | // } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 367 | |
| 368 | } |
| 369 | |
| 370 | } |
| 371 | |
| 372 | |
| 373 | /** |
| 374 | * @brief SDK interface to call back sms messages |
| 375 | * @param [in] handle_ptr |
| 376 | * @retval 0: success |
| 377 | * @retval other: fail |
| 378 | */ |
| 379 | int gsw_sms_reg_callback(GSW_SMS_Callback_fun handle_ptr) |
| 380 | { |
| 381 | if(init_flag == 0) |
| 382 | { |
| 383 | return -1; |
| 384 | } |
| 385 | |
| 386 | if(handle_ptr == NULL) |
| 387 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 388 | LOGE(GSW_SMS,"gsw_sms_reg_callback fail,handle_ptr is null\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 389 | return -1; |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | gsw_sms_callback = handle_ptr; |
| 394 | } |
| 395 | return GSW_HAL_SUCCESS; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * @brief sms sdk init |
| 400 | * @param [in] token |
| 401 | * @retval 0: success |
| 402 | * @retval other: fail |
| 403 | */ |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 404 | int gsw_sms_sdk_init(int32_t token) |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 405 | { |
| 406 | handle = token; |
| 407 | int ret = -1; |
| 408 | |
| 409 | if(init_flag == 1) |
| 410 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 411 | LOGE(GSW_SMS,"has init sms sdk,return\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 412 | return GSW_HAL_SUCCESS; |
| 413 | } |
| 414 | |
| 415 | ret = mbtk_sms_import(); |
| 416 | if(ret != 0) |
| 417 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 418 | // if(mbtk_log != NULL) |
| 419 | // { |
| 420 | // LOGE(GSW_SMS,"[gsw_sms_sdk_init]mbtk_sms_import fail\n"); |
| 421 | // } |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 422 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 423 | } |
| 424 | |
lichengzhang | 7704687 | 2025-07-07 11:45:51 +0800 | [diff] [blame] | 425 | //mbtk_log_init("syslog", "MBTK_RIL"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 426 | |
| 427 | sms_info_handle = mbtk_info_handle_get(); |
| 428 | if(sms_info_handle == NULL) |
| 429 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 430 | LOGE(GSW_SMS,"[gsw_sms_sdk_init] mbtk handle init fail\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 431 | dlclose(dlHandle_mbtk); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 432 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | ret = mbtk_sms_cnmi_set(sms_info_handle); |
| 436 | if(ret != 0) |
| 437 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 438 | LOGE(GSW_SMS,"mbtk_sms_cnmi_set fail.[%d]\n", ret); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 439 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | ret = mbtk_sms_state_change_cb_reg(sms_info_handle, gsw_sms_state_change_cb); |
| 443 | if(ret != 0) |
| 444 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 445 | LOGE(GSW_SMS,"mbtk_sms_state_change_cb_reg fail.[%d]\n", ret); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 446 | if(sms_info_handle) |
| 447 | { |
| 448 | mbtk_info_handle_free(&sms_info_handle); |
| 449 | sms_info_handle = NULL; |
| 450 | } |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 451 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 452 | } |
| 453 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 454 | LOGD(GSW_SMS,"[gsw_sms_sdk_init]gsw_sms_sdk_init success\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 455 | init_flag = 1; |
| 456 | return GSW_HAL_SUCCESS; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * @brief sms sdk deinit |
| 461 | * @param |
| 462 | * @retval 0: success |
| 463 | * @retval other: fail |
| 464 | */ |
| 465 | int gsw_sms_sdk_deinit(void) |
| 466 | { |
| 467 | int ret = -1; |
| 468 | |
| 469 | if(init_flag == 0) |
| 470 | { |
| 471 | return -1; |
| 472 | } |
| 473 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 474 | LOGD(GSW_SMS,"callback clear\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 475 | gsw_sms_callback = NULL; |
| 476 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 477 | LOGD(GSW_SMS,"handle_free\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 478 | if(sms_info_handle != NULL) |
| 479 | { |
| 480 | ret = mbtk_info_handle_free(&sms_info_handle); |
| 481 | if(ret != 0) |
| 482 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 483 | LOGE(GSW_SMS,"[gsw_sms_sdk_deinit]mbtk_info_handle_free fail\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 484 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 485 | } |
| 486 | sms_info_handle = NULL; |
| 487 | } |
| 488 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 489 | LOGD(GSW_SMS,"dlclose start\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 490 | if(dlHandle_mbtk == NULL) |
| 491 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 492 | LOGE(GSW_SMS,"[gsw_sms_sdk_deinit]dlHandle_sms is null\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 493 | } |
| 494 | else |
| 495 | { |
| 496 | dlclose(dlHandle_mbtk); |
| 497 | } |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 498 | LOGD(GSW_SMS,"dlclose end\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 499 | init_flag = 0; |
| 500 | return GSW_HAL_SUCCESS; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * @brief send sms fuction * |
| 505 | * @param [in] phone_num dest phone num send sms |
| 506 | * @param [in] char_set encode format for sms 0 7bit 1 binary 2 usc2 |
| 507 | * @param [in] msg sms content |
| 508 | * @param [in] msg_len send sms length,max is 1024 |
| 509 | * @retval 0: success |
| 510 | * @retval other: fail |
| 511 | */ |
| 512 | int gsw_send_sms(char *phone_num, int char_set, char *msg, int msg_len) |
| 513 | { |
| 514 | |
| 515 | if(init_flag == 0) |
| 516 | { |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 517 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | if(phone_num == NULL || msg == NULL) |
| 521 | { |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 522 | return GSW_HAL_ARG_INVALID; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 523 | } |
| 524 | |
lichengzhang | dab5ee7 | 2025-07-21 18:03:00 +0800 | [diff] [blame^] | 525 | if(strlen((char *)msg) == 0 || strlen((char *)phone_num) == 0) |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 526 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 527 | LOGE(GSW_SMS,"strlen(telephony_num):%d", strlen((char *)phone_num)); |
| 528 | LOGE(GSW_SMS,"strlen(msg):%d", strlen((char *)msg)); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 529 | return GSW_HAL_ARG_INVALID; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 530 | } |
lichengzhang | dab5ee7 | 2025-07-21 18:03:00 +0800 | [diff] [blame^] | 531 | if(strlen((char *)msg) > MSG_MAX_LEN || msg_len > MSG_MAX_LEN || strlen((char *)msg) != msg_len) |
| 532 | { |
| 533 | LOGE(GSW_SMS,"stelen is %d\n",strlen((char *)msg)); |
| 534 | LOGE(GSW_SMS,"the lenth is error\n"); |
| 535 | return GSW_HAL_NORMAL_FAIL; |
| 536 | } |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 537 | |
| 538 | int err = -1; |
| 539 | |
| 540 | char smscPDU[30] = {0}; |
| 541 | char **pdu = NULL; |
| 542 | char smsc[4] = {0}; |
| 543 | char cmgs[MSM_NUMBER_MAX] = {0}; |
| 544 | char resp[RES_NUM_MIN] = {0}; |
| 545 | char msg_e_b[GSW_SMS_RECV_CONT_MAX+1] = {0};// +1 for end of string.*2:A char array contains two elements of a string for each value |
| 546 | |
| 547 | kal_int32 msg_num = 0; |
| 548 | kal_int32 pdu_msg_len = 0; |
| 549 | kal_int32 status = MDAPI_RET_ERROR; |
| 550 | kal_int32 index = 0; |
| 551 | |
| 552 | if(char_set == 1) //8bit |
| 553 | { |
| 554 | ArrayToStr((unsigned char *)msg, (unsigned int)msg_len, msg_e_b); |
| 555 | status = _mdapi_sms_get_msg_num(msg_e_b, char_set, &msg_num, &pdu_msg_len); |
| 556 | } |
| 557 | |
| 558 | else //7bit usc2 |
| 559 | { |
| 560 | status = _mdapi_sms_get_msg_num((char *)msg, char_set, &msg_num, &pdu_msg_len); |
| 561 | } |
| 562 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 563 | LOGE(GSW_SMS,"%s, %s, %d, msg_len = [%d] ,msg_num=[%d]\n", __FILE__, __FUNCTION__, __LINE__, msg_len, msg_num); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 564 | if(status == MDAPI_RET_ERROR) |
| 565 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 566 | LOGE(GSW_SMS,"get message number failed\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 567 | //return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 568 | } |
| 569 | else |
| 570 | { |
| 571 | //allocate memery for **pdu |
| 572 | pdu = (char **)malloc(sizeof(char *) * msg_num); |
| 573 | if(pdu == NULL) |
| 574 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 575 | LOGE(GSW_SMS,"%s, %s, %d, allocate memory for pdu failed\n", __FILE__, __FUNCTION__, __LINE__); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 576 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | else |
| 580 | { |
| 581 | for(index = 0; index < msg_num; index++) |
| 582 | { |
| 583 | pdu[index] = (char *)malloc(sizeof(char)*MAX_PDU_SIZE); |
| 584 | if(pdu[index] == NULL) |
| 585 | { |
| 586 | for(int i = 0; i < index; i++) |
| 587 | { |
| 588 | free(pdu[i]); |
| 589 | pdu[i] = NULL; |
| 590 | } |
| 591 | free(pdu); |
| 592 | pdu = NULL; |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 593 | LOGE(GSW_SMS,"%s, %s, %d, allocate memory for pdu[%d] failed\n", __FILE__, __FUNCTION__, __LINE__,index); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 594 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 595 | } |
| 596 | else |
| 597 | { |
| 598 | memset(pdu[index], 0, MAX_PDU_SIZE); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 599 | LOGE(GSW_SMS,"%s, %s, %d, pdu[%d} init value is: %s \n", __FILE__, __FUNCTION__, __LINE__, index, pdu[index]); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | //allocate memory for **pdu success |
| 606 | if(index == msg_num) |
| 607 | { |
| 608 | if(char_set == 1)//8bit |
| 609 | { |
| 610 | smsPduEncode(smsc, (char *)phone_num, msg_e_b, char_set, smscPDU, pdu); |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | smsPduEncode(smsc, (char *)phone_num, (char *)msg, char_set, smscPDU, pdu); |
| 615 | } |
| 616 | for(index = 0; index < msg_num; index++) |
| 617 | { |
| 618 | char pdu_data[MAX_PDU_SIZE] = {0}; |
| 619 | char *p = pdu_data; |
| 620 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 621 | LOGE(GSW_SMS,"index:%d\n",index); |
| 622 | LOGE(GSW_SMS,"%s, %s, %d, smscPDU: %s, pdu: %s",__FILE__, __FUNCTION__, __LINE__, smscPDU, pdu[index]); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 623 | sprintf(p, "%s",smscPDU); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 624 | LOGE(GSW_SMS,"pdu_data:%s\n", pdu_data); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 625 | int sc = strlen(pdu_data); |
| 626 | sprintf(p+strlen(p), "%s", pdu[index]); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 627 | LOGE(GSW_SMS,"pdu_data:%s\n", pdu_data); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 628 | |
| 629 | int t = strlen(pdu_data); |
| 630 | sprintf(cmgs, "%d,%s", (t-sc)/2, pdu_data); |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 631 | LOGE(GSW_SMS,"cmgs:%s\n", cmgs); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 632 | memset(resp, 0, sizeof(resp)); |
| 633 | |
| 634 | err = mbtk_sms_cmgf_set(sms_info_handle, 0); |
| 635 | if(err) |
| 636 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 637 | LOGE(GSW_SMS,"cmgf set error : %d\n", err); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 638 | for(index = 0; index < msg_num; index++){ |
| 639 | free(pdu[index]); |
| 640 | pdu[index] = NULL; |
| 641 | } |
| 642 | free(pdu); |
| 643 | pdu = NULL; |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 644 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 645 | } |
| 646 | else |
| 647 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 648 | LOGD(GSW_SMS,"cmgf set success\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp); |
| 652 | if(err) |
| 653 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 654 | LOGE(GSW_SMS,"cmgs send fail\n"); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 655 | for(index = 0; index < msg_num; index++){ |
| 656 | free(pdu[index]); |
| 657 | pdu[index] = NULL; |
| 658 | } |
| 659 | free(pdu); |
| 660 | pdu = NULL; |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 661 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 662 | } |
| 663 | else |
| 664 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 665 | LOGD(GSW_SMS,"cmgs send success, resp:%s\n", resp); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | for(index = 0; index < msg_num; index++){ |
| 672 | free(pdu[index]); |
| 673 | pdu[index] = NULL; |
| 674 | } |
| 675 | free(pdu); |
| 676 | pdu = NULL; |
| 677 | |
| 678 | return GSW_HAL_SUCCESS; |
| 679 | } |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * @brief get smsc fuction * |
| 684 | * @param [in] len input buf len for smsc,max is 32 |
| 685 | * @param [out] smsc address for smsc get from this func * |
| 686 | * @retval 0: success |
| 687 | * @retval other: fail |
| 688 | */ |
| 689 | int gsw_get_smsc_address(int len, char *smsc) |
| 690 | { |
| 691 | int ret = -1; |
| 692 | int len_t = 0; |
| 693 | char smsc_temp[SMSC_MAX_LEN] = {0}; |
| 694 | char *p1, *p2 ,*substr; |
| 695 | |
| 696 | if(init_flag == 0) |
| 697 | { |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 698 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | if(smsc == NULL || len <= 0) |
| 702 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 703 | LOGE(GSW_SMS,"smsc is null or len = %d\n",len); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 704 | return GSW_HAL_ARG_INVALID; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | ret = mbtk_sms_csca_get(sms_info_handle, smsc_temp); |
| 708 | if(smsc_temp[0] == '\0') |
| 709 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 710 | LOGE(GSW_SMS,"gsw_get_smsc_address Error : %d\n", ret); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 711 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | else |
| 715 | { |
| 716 | p1 = strchr(smsc_temp, '\"'); |
| 717 | p2 = strrchr(smsc_temp, '\"'); |
| 718 | if (p1 && p2 && p2 > p1) |
| 719 | { |
| 720 | len_t = p2 - p1 - 1; |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 721 | substr = malloc(len_t + 1); |
| 722 | if (NULL == substr) |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 723 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 724 | LOGE(GSW_SMS,"substr = NULL, malloc faill!!!\n"); |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 725 | return GSW_HAL_NO_MEMORY; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 726 | } |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 727 | strncpy(substr, p1 + 1, len_t); |
| 728 | substr[len_t] = '\0'; |
lichengzhang | 12647e5 | 2025-07-21 17:23:10 +0800 | [diff] [blame] | 729 | strncpy(smsc, substr, len); |
| 730 | strncpy(sms_center_address, substr, len); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 731 | |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 732 | LOGE(GSW_SMS,"qser_sms_getsmscenteraddress success, smsc = %s\n", sms_center_address); |
hong.liu | d241707 | 2025-06-27 07:10:37 -0700 | [diff] [blame] | 733 | free(substr); |
| 734 | substr = NULL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 735 | } |
| 736 | else |
| 737 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 738 | LOGE(GSW_SMS,"String inside double quotes not found\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 739 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | return GSW_HAL_SUCCESS; |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * @brief set smsc fuction |
| 749 | * @param [out] smsc string value for smsc,max length is 32 * |
| 750 | * @retval 0: success |
| 751 | * @retval other: fail |
| 752 | */ |
| 753 | int gsw_set_smsc_address(const char *smsc) |
| 754 | { |
| 755 | int ret = -1; |
| 756 | |
| 757 | if(init_flag == 0) |
| 758 | { |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 759 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | if(smsc == NULL || strlen((char *)smsc) == 0) |
| 763 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 764 | LOGE(GSW_SMS,"smsc is null or empty\n"); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 765 | return GSW_HAL_ARG_INVALID; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | ret = mbtk_sms_csca_set(sms_info_handle, (char *)smsc); |
| 769 | |
| 770 | if(ret == 0) |
| 771 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 772 | LOGE(GSW_SMS,"set smsc success,smsc = %s\n",smsc); |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 773 | } |
| 774 | else |
| 775 | { |
lichengzhang | 7715b2f | 2025-07-19 10:18:21 +0800 | [diff] [blame] | 776 | LOGE(GSW_SMS,"set smsc fail,ret = %d\n", ret); |
xy.he | b41615b | 2025-05-28 16:33:20 +0800 | [diff] [blame] | 777 | return GSW_HAL_NORMAL_FAIL; |
b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | return GSW_HAL_SUCCESS; |
| 781 | } |