b.liu | 4e243dc | 2023-11-27 11:20:00 +0800 | [diff] [blame] | 1 | #include "lynq_qser_sms.h" |
| 2 | #include "mbtk_type.h" |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 3 | #include "mbtk_pdu_sms.h" |
| 4 | #include "mbtk_info_api.h" |
| 5 | #include "lynq_sms.h" |
r.xiao | ba8483c | 2024-04-14 18:53:10 -0700 | [diff] [blame] | 6 | #include "mbtk_log.h" |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 7 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | |
| 13 | #define TELEPHONE_NUM_MAX 16 |
| 14 | #define MSM_NUMBER_MAX 1024+1 |
| 15 | #define RES_NUM_MIN 128 |
| 16 | |
| 17 | |
| 18 | #define DSC_to_msg(DSC) (DSC == 0 ? "Bit7" : (DSC == 1 ? "Bit8" : "UCS2")) |
| 19 | |
| 20 | static mbtk_info_handle_t* sms_info_handle = NULL; |
| 21 | static char sms_center_address[128] = {0}; |
| 22 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 23 | typedef struct |
| 24 | { |
| 25 | QSER_SMS_RxMsgHandlerFunc_t handlerPtr; |
| 26 | void* contextPtr; |
| 27 | } lynq_sms_cb_func; |
| 28 | |
| 29 | static lynq_sms_cb_func lynq_sms_func_cb_handle; |
| 30 | |
| 31 | sms_client_handle_type g_sms_val = -1; |
| 32 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 33 | |
| 34 | void lynq_sms_state_change_cb(const void* data, int data_len) |
| 35 | { |
| 36 | LOGV("sms_state_change_cb()----------start\n"); |
| 37 | uint8 *ptr = (uint8*)data; |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 38 | //printf("3sms_state_change_cb() : %s\n", ptr); |
| 39 | |
| 40 | if (!strncmp("+CMT:", ptr, 5))//丢弃无用消息 |
| 41 | return ; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 42 | |
| 43 | struct SMS_Struct s = PDUDecoding(ptr); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 44 | /* |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 45 | printf("服务中心地址: %s\n", s.SCA); |
| 46 | printf("发送方地址: %s\n", s.OA); |
| 47 | printf("服务中心时间戳: %s\n", s.SCTS); |
| 48 | printf("消息内容: %s\n", s.UD); |
| 49 | printf("数据编码方案: %s\n", DSC_to_msg(s.DCS)); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 50 | */ |
| 51 | QSER_SMS_Msg_t* tmp_data = NULL; |
| 52 | |
| 53 | tmp_data = (QSER_SMS_Msg_t*)malloc(sizeof(QSER_SMS_Msg_t)); |
| 54 | memset(tmp_data,0x00, sizeof(QSER_SMS_Msg_t)); |
| 55 | |
| 56 | tmp_data->format = s.DCS; |
| 57 | //printf("t数据编码方案: %d\n", tmp_data->format); |
| 58 | memcpy(tmp_data->src_addr, s.OA, strlen(s.OA)); |
| 59 | //printf("t发送方地址: %s\n", tmp_data->src_addr); |
| 60 | memcpy(tmp_data->timestamp, s.SCTS, strlen(s.SCTS)); |
| 61 | //printf("t服务中心时间戳: %s\n", tmp_data->timestamp); |
| 62 | tmp_data->sms_data_len = strlen(s.UD); |
| 63 | //printf("t消息内容长度: %d\n", tmp_data->sms_data_len); |
| 64 | memcpy(tmp_data->sms_data, s.UD, strlen(s.UD)); |
| 65 | //printf("t消息内容: %s\n", tmp_data->sms_data); |
| 66 | |
| 67 | lynq_sms_func_cb_handle.handlerPtr(tmp_data, NULL); |
| 68 | |
| 69 | free(tmp_data); |
| 70 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
| 74 | int qser_sms_client_init(sms_client_handle_type *ph_sms)//out |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 75 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 76 | //UNUSED(ph_sms); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 77 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 78 | if(sms_info_handle == NULL) |
| 79 | { |
| 80 | sms_info_handle = mbtk_info_handle_get(); |
| 81 | if(sms_info_handle) |
| 82 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 83 | LOGI("creat sms_info_handle is success"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 84 | *ph_sms = sms_info_handle->client_fd; |
| 85 | g_sms_val = sms_info_handle->client_fd; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 86 | } |
| 87 | else |
| 88 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 89 | LOGE("creat sms_info_handle is fail"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 90 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 94 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 95 | } |
| 96 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 97 | int qser_sms_client_deinit(sms_client_handle_type h_sms)//in |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 98 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 99 | //UNUSED(h_sms); |
| 100 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 101 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 102 | LOGE("handle NULL\n"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 103 | return -1; |
| 104 | } |
| 105 | |
r.xiao | fca7c47 | 2024-04-24 01:00:23 -0700 | [diff] [blame] | 106 | mbtk_sms_state_change_cb_reg(sms_info_handle, NULL); |
| 107 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 108 | if(sms_info_handle) |
| 109 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 110 | mbtk_info_handle_free(&sms_info_handle); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 111 | LOGI("deinit sms_info_handle is succuess"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 112 | } |
| 113 | else |
| 114 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 115 | LOGE("deinit sms_info_handle is fail"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 116 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 117 | } |
| 118 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 119 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 120 | } |
| 121 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 122 | int qser_sms_send_sms(sms_client_handle_type h_sms, QSER_sms_info_t *pt_sms_info)//in in 发送短信的内容、目的号码 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 123 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 124 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 125 | //UNUSED(pt_sms_info); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 126 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 127 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 128 | LOGE("handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 129 | return -1; |
| 130 | } |
| 131 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 132 | if (pt_sms_info == NULL) |
| 133 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 134 | LOGE("QSER_sms_info_t NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 135 | return -1; |
| 136 | } |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 137 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 138 | if(sms_info_handle == NULL) |
| 139 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 140 | LOGE("qser_sms_send_sms sms_info_handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 141 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 142 | } |
| 143 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 144 | uint8_t *phone_num = NULL, *data = NULL; |
| 145 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 146 | char cmgs[MSM_NUMBER_MAX] = {0}; |
| 147 | char resp[RES_NUM_MIN] = {0}; |
| 148 | char pdu_data[512] = {0}; |
| 149 | char phone_lenth[10] = {0}; |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 150 | char mem[10] = {0}; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 151 | char *p = pdu_data; |
| 152 | int mode = 0; |
| 153 | int err = 0; |
| 154 | int i = 0; |
| 155 | |
| 156 | data = pt_sms_info->sms_data; |
| 157 | |
| 158 | phone_num = pt_sms_info->src_addr; |
| 159 | |
| 160 | if (pt_sms_info->format == 0)//7 |
| 161 | mode = 1; |
| 162 | else if (pt_sms_info->format == 1)//8 |
| 163 | return SMS_ERR; |
| 164 | else if (pt_sms_info->format == 2)//USC2 |
| 165 | mode = 0; |
| 166 | else |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 167 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 168 | |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 169 | //设置存储器 |
r.xiao | d3256ae | 2024-02-28 23:20:55 -0800 | [diff] [blame] | 170 | /* |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 171 | if (pt_sms_info->storage == 0) |
| 172 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 173 | strcpy(mem, "SM"); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 174 | } |
| 175 | else if (pt_sms_info->storage == 1) |
| 176 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 177 | strcpy(mem, "ME"); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 178 | } |
| 179 | else |
| 180 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 181 | LOGE("qser_sms_deletefromstorage storage is no Support"); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 182 | return -1; |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | memset(resp, 0, sizeof(resp)); |
| 186 | err = mbtk_sms_cpms_set(sms_info_handle, mem, resp); |
| 187 | if(err) { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 188 | LOGE("Error : %d", err); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 189 | } else { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 190 | LOGI("cpms set success. resp:%s", resp); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 191 | } |
r.xiao | d3256ae | 2024-02-28 23:20:55 -0800 | [diff] [blame] | 192 | */ |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 193 | if(data == NULL) |
| 194 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 195 | LOGE("qser_sms_send_sms data NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 196 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | if(phone_num == NULL) |
| 200 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 201 | LOGE("qser_sms_send_sms phone_num NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 202 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 203 | } |
| 204 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 205 | if(strlen(data) > 512 || strlen(data) == 0 || strlen(phone_num) == 0) |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 206 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 207 | LOGE("strlen(telephony_num):%d", strlen(phone_num)); |
| 208 | LOGE("strlen(msg):%d", strlen(data)); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 209 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 210 | } |
| 211 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 212 | if (mode == 0)// PDU |
| 213 | { |
| 214 | #if 1 |
| 215 | if (sms_center_address[0] == '\0') |
| 216 | { |
| 217 | memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 218 | memcpy(sms_center_address, "+8613800280500", strlen("+8613800280500")); |
| 219 | } |
| 220 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 221 | //printf("phone_num:%s\n", phone_num); |
| 222 | //printf("sms_center_address:%s\n", sms_center_address); |
| 223 | //printf("data:%s\n", data); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 224 | |
| 225 | char* pdu = NULL; |
| 226 | char* smsc = SCAEncoding(sms_center_address); |
| 227 | struct PDUS *pdus = PDUEncoding(sms_center_address,phone_num, data, NULL); |
| 228 | |
| 229 | for (i = 0; i < pdus->count; i++) |
| 230 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 231 | LOGI("第 %d 条:", i + 1); |
| 232 | LOGI("%s\n", pdus->PDU[i]); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 233 | pdu = pdus->PDU[i]; |
| 234 | } |
| 235 | |
| 236 | sprintf(p, "%s",smsc); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 237 | LOGI("pdu_data:%s", pdu_data); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 238 | sprintf(p+strlen(p), "%s", pdu); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 239 | LOGI("pdu_data:%s",pdu_data); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 240 | |
| 241 | //sprintf(cmgs,"%d,%s",strlen(pdu_data), pdu_data); |
| 242 | int t = strlen(pdu_data); |
| 243 | sprintf(cmgs,"%d,%s",(t-18)/2, pdu_data); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 244 | LOGI("cmgs:%s", cmgs); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 245 | #else |
| 246 | char *tmp_t = "0891683108200805F011000D91688189914026F3000800044F60597D"; |
| 247 | sprintf(cmgs,"%d,%s",19,tmp_t); |
| 248 | printf("cmgs:%s\n", cmgs); |
| 249 | #endif |
| 250 | |
| 251 | memset(resp, 0, sizeof(resp)); |
| 252 | |
| 253 | err = mbtk_sms_cmgf_set(sms_info_handle, mode); |
| 254 | if(err) |
| 255 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 256 | LOGE("cmgf set error : %d", err); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 257 | } |
| 258 | else |
| 259 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 260 | LOGI("cmgf set success"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp); |
| 264 | if(err) |
| 265 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 266 | LOGE("Error : %d", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 267 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 268 | } |
| 269 | else |
| 270 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 271 | LOGI("cmgs set success . resp:%s", resp); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | else if (mode == 1) // text |
| 275 | { |
| 276 | err = mbtk_sms_cmgf_set(sms_info_handle, mode); |
| 277 | if(err) |
| 278 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 279 | LOGE("cmgf set error : %d", err); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 280 | } |
| 281 | else |
| 282 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 283 | LOGI("cmgf set success"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | sprintf(cmgs,"%s,%s", phone_num, data); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 287 | LOGI("cmgs:%s", cmgs); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 288 | |
| 289 | memset(resp, 0, sizeof(resp)); |
| 290 | |
| 291 | err = mbtk_sms_cmgs_set(sms_info_handle, cmgs, resp); |
| 292 | if(err) |
| 293 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 294 | LOGE("Error : %d", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 295 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 296 | } |
| 297 | else |
| 298 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 299 | LOGI("cmgs set success . resp:%s", resp); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | else |
| 303 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 304 | LOGE("Error : mode"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 305 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 306 | } |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 307 | |
| 308 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 309 | } |
| 310 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 311 | //注册接收新短信 |
| 312 | int qser_sms_addrxmsghandler(QSER_SMS_RxMsgHandlerFunc_t handlerPtr, void* contextPtr)//in sms电话状态回调函数 in 主要是获取 上报 的内容 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 313 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 314 | //UNUSED(handlerPtr); |
| 315 | //UNUSED(contextPtr); |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 316 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 317 | if(sms_info_handle == NULL) |
| 318 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 319 | LOGE("qser_sms_addrxmsghandler sms_info_handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 320 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | int err = mbtk_sms_cnmi_set(sms_info_handle); |
| 324 | if(err) |
| 325 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 326 | LOGE("set cnmi fail"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 327 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 328 | } |
| 329 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 330 | lynq_sms_func_cb_handle.handlerPtr = handlerPtr; |
| 331 | lynq_sms_func_cb_handle.contextPtr = contextPtr; |
| 332 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 333 | mbtk_sms_state_change_cb_reg(sms_info_handle, lynq_sms_state_change_cb); |
| 334 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 335 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 336 | } |
| 337 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 338 | //删除短信 |
| 339 | int qser_sms_deletefromstorage(sms_client_handle_type h_sms, QSER_sms_storage_info_t *pt_sms_storage)//in in 删除短信的信息 |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 340 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 341 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 342 | //UNUSED(pt_sms_storage); |
| 343 | char cmgd[128] = {0}; |
| 344 | int err = 0; |
r.xiao | 26cb069 | 2024-05-22 22:47:08 -0700 | [diff] [blame] | 345 | |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 346 | int t_storage = 0; |
| 347 | char mem[10] = {0}; |
| 348 | char resp[RES_NUM_MIN] = {0}; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 349 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 350 | if (h_sms != g_sms_val || g_sms_val == -1) |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 351 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 352 | LOGE("handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 353 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | if(pt_sms_storage == NULL) |
| 357 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 358 | LOGE("qser_sms_deletefromstorage pt_sms_storage NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 359 | return -1; |
| 360 | } |
| 361 | |
| 362 | if(sms_info_handle == NULL) |
| 363 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 364 | LOGE("qser_sms_deletefromstorage sms_info_handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 365 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 366 | } |
r.xiao | d3256ae | 2024-02-28 23:20:55 -0800 | [diff] [blame] | 367 | /* |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 368 | t_storage = pt_sms_storage->storage; //设置存储器 |
| 369 | |
| 370 | if (t_storage == 0) |
| 371 | { |
| 372 | strncpy(mem, "SM", 2); |
| 373 | } |
| 374 | else if (t_storage == 1) |
| 375 | { |
| 376 | strncpy(mem, "ME", 2); |
| 377 | } |
| 378 | else |
| 379 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 380 | LOGE("qser_sms_deletefromstorage storage is no Support"); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 381 | return -1; |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | memset(resp, 0, sizeof(resp)); |
| 385 | err = mbtk_sms_cpms_set(sms_info_handle, mem, resp); |
| 386 | if(err) { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 387 | LOGE("Error : %d", err); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 388 | } else { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 389 | LOGI("cpms set success. resp:%s", resp); |
r.xiao | e73f870 | 2024-01-06 01:40:03 -0800 | [diff] [blame] | 390 | } |
r.xiao | d3256ae | 2024-02-28 23:20:55 -0800 | [diff] [blame] | 391 | */ |
r.xiao | 26cb069 | 2024-05-22 22:47:08 -0700 | [diff] [blame] | 392 | uint32_t id_x = 0; //若后面其他产品是int类型则用宏控制 |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 393 | id_x = pt_sms_storage->storage_idx;//获取idx的值 |
| 394 | |
| 395 | if(id_x == -1) //delete all |
| 396 | { |
r.xiao | 26cb069 | 2024-05-22 22:47:08 -0700 | [diff] [blame] | 397 | memcpy(cmgd, "0,4", strlen("0,4")); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 398 | } |
| 399 | else |
| 400 | { |
| 401 | sprintf(cmgd,"%d",id_x); |
| 402 | } |
| 403 | |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 404 | LOGI("cmgd:%s", cmgd); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 405 | |
| 406 | err = mbtk_sms_cmgd_set(sms_info_handle, cmgd); |
| 407 | if(err) |
| 408 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 409 | LOGE("qser_sms_deletefromstorage Error : %d", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 410 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 411 | } |
| 412 | else |
| 413 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 414 | LOGI("qser_sms_deletefromstorage set success"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 415 | } |
| 416 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 417 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 418 | } |
| 419 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 420 | //获取短信中心号码 |
| 421 | int qser_sms_getsmscenteraddress( sms_client_handle_type h_sms,QSER_sms_service_center_cfg_t *set_sca_cfg)//in out |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 422 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 423 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 424 | //UNUSED(set_sca_cfg); |
| 425 | char sms_center_addree[254] = {0}; |
| 426 | int len_t; |
| 427 | char *p1, *p2 ,*substr; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 428 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 429 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 430 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 431 | LOGE("handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 432 | return -1; |
| 433 | } |
| 434 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 435 | if (set_sca_cfg == NULL) |
| 436 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 437 | LOGE("QSER_sms_service_center_cfg_t NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 438 | return -1; |
| 439 | } |
| 440 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 441 | if(sms_info_handle == NULL) |
| 442 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 443 | LOGE("qser_sms_getsmscenteraddress sms_info_handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 444 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | int err = mbtk_sms_csca_get(sms_info_handle, sms_center_addree); |
| 448 | if(sms_center_addree[0] == '\0') |
| 449 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 450 | LOGE("qser_sms_getsmscenteraddress Error : %d", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 451 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 452 | } |
| 453 | else |
| 454 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 455 | p1 = strchr(sms_center_addree, '\"'); |
| 456 | p2 = strrchr(sms_center_addree, '\"'); |
| 457 | if (p1 && p2 && p2 > p1) |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 458 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 459 | len_t = p2 - p1 - 1; |
| 460 | char substr_t[len_t + 1]; |
| 461 | strncpy(substr_t, p1 + 1, len_t); |
| 462 | substr_t[len_t] = '\0'; |
| 463 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 464 | substr = substr_t; |
| 465 | |
| 466 | memcpy(set_sca_cfg->service_center_addr, substr, strlen(substr)); |
| 467 | memcpy(sms_center_address, substr, strlen(substr)); |
| 468 | |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 469 | LOGI("qser_sms_getsmscenteraddress success"); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 470 | } |
| 471 | else |
| 472 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 473 | LOGE("String inside double quotes not found"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 474 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 478 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 479 | } |
| 480 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 481 | //设置短信中心号码 |
| 482 | int qser_sms_setsmscenteraddress( sms_client_handle_type h_sms, QSER_sms_service_center_cfg_t *get_sca_cfg)//in in |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 483 | { |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 484 | //UNUSED(h_sms); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 485 | //UNUSED(get_sca_cfg); |
| 486 | char *destNum = NULL; |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 487 | |
| 488 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 489 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 490 | LOGE("handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 491 | return -1; |
| 492 | } |
| 493 | |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 494 | if(sms_info_handle == NULL) |
| 495 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 496 | LOGE("qser_sms_setsmscenteraddress sms_info_handle NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 497 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | if(get_sca_cfg == NULL) |
| 501 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 502 | LOGE("qser_sms_setsmscenteraddress get_sca_cfg NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 503 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | destNum = get_sca_cfg->service_center_addr; |
| 507 | |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 508 | //printf("1destNum:%s\n", destNum); |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 509 | memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 510 | memcpy(sms_center_address, destNum, strlen(destNum)); |
| 511 | |
| 512 | if (destNum == NULL) |
| 513 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 514 | LOGE("qser_sms_setsmscenteraddress destNum NULL"); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 515 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | int err = mbtk_sms_csca_set(sms_info_handle, destNum); |
| 519 | if(err) |
| 520 | { |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 521 | LOGE("Error : %d", err); |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 522 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 523 | } |
| 524 | else |
| 525 | { |
| 526 | // memset(sms_center_address, 0, sizeof(sms_center_address)); |
| 527 | // memcpy(sms_center_address, destNum, strlen(destNum)); |
r.xiao | ec113d1 | 2024-01-12 02:13:28 -0800 | [diff] [blame] | 528 | //printf("destNum:%s\n", destNum); |
r.xiao | eb9dba4 | 2024-02-07 02:16:13 -0800 | [diff] [blame] | 529 | LOGI("qser_sms_setsmscenteraddress success"); |
| 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | |
| 536 | //显示删除列表 |
| 537 | int qser_sms_deletefromstoragelist( sms_client_handle_type h_sms, char* del_list)//in out |
| 538 | { |
| 539 | //UNUSED(h_sms); |
| 540 | //UNUSED(get_sca_cfg); |
| 541 | |
| 542 | if (h_sms != g_sms_val || g_sms_val == -1) |
| 543 | { |
| 544 | LOGE("handle NULL"); |
| 545 | return -1; |
| 546 | } |
| 547 | |
| 548 | if(sms_info_handle == NULL) |
| 549 | { |
| 550 | LOGE("qser_sms_deletefromstoragelist sms_info_handle NULL"); |
| 551 | return -1; |
| 552 | } |
| 553 | |
| 554 | int err = mbtk_sms_cmgd_get(sms_info_handle, del_list); |
| 555 | if(err > 0 && err != 300)//MBTK_INFO_ERR_SUCCESS |
| 556 | { |
| 557 | LOGE("Error : %d", err); |
| 558 | return -1; |
r.xiao | dac8256 | 2023-12-07 18:22:32 -0800 | [diff] [blame] | 559 | } |
| 560 | |
r.xiao | efee006 | 2023-12-29 19:35:43 -0800 | [diff] [blame] | 561 | return 0; |
b.liu | 5fa9e77 | 2023-11-23 18:00:55 +0800 | [diff] [blame] | 562 | } |
| 563 | |