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 <stdint.h> |
| 29 | |
| 30 | #define QL_SMS_MAX_SEND_MSG_LENGTH 1440 /**< Maximum length of an sending SMS (9*160). */ |
| 31 | #define QL_SMS_MAX_SEND_PDU_LENGTH 255 /**< Maximum length of an sms PDU. */ |
| 32 | #define QL_SMS_MAX_RECV_MSG_LENGTH 160 /**< Maximum length of an recv SMS. */ |
| 33 | #define QL_SMS_MAX_ADDR_LENGTH 252 /**< Maximum length of SCA addr. */ |
| 34 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 35 | typedef enum |
| 36 | { |
| 37 | QL_SIM_SLOT_INVALID = 0x000, /**< Invalid slot. */ |
| 38 | QL_SIM_SLOT_1 = 0xB01, /**< Identify card in slot 1. */ |
| 39 | QL_SIM_SLOT_2 = 0xB02, /**< Identify card in slot 2. */ |
| 40 | } QL_SIM_SLOT_E; |
| 41 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 42 | /** The SMS message format. */ |
| 43 | typedef enum |
| 44 | { |
| 45 | QL_SMS_MSG_FORMAT_GSM_7BIT = 0, |
| 46 | QL_SMS_MSG_FORMAT_BINARY_DATA = 1, |
| 47 | QL_SMS_MSG_FORMAT_UCS2 = 2, |
| 48 | } QL_SMS_MSG_FORMAT_E; |
| 49 | |
| 50 | /** */ |
| 51 | typedef enum { |
| 52 | QL_SMS_PRIMARY_SUBSCRIPTION = 0, |
| 53 | QL_SMS_SECONDARY_SUBSCRIPTION = 1, |
| 54 | } QL_SMS_SUBSCRIPTION_E; |
| 55 | |
| 56 | |
| 57 | /** The SMS message structure. */ |
| 58 | typedef struct |
| 59 | { |
| 60 | QL_SMS_MSG_FORMAT_E format; |
| 61 | char addr[QL_SMS_MAX_ADDR_LENGTH + 1]; /**< Source or destinamtion address. */ |
| 62 | int content_size; |
| 63 | char content[QL_SMS_MAX_SEND_MSG_LENGTH]; |
| 64 | } ql_sms_msg_t; |
| 65 | |
| 66 | typedef struct |
| 67 | { |
| 68 | uint8_t year; /**< Year. since 2000. e.g. 19 means 2019 */ |
| 69 | uint8_t month; /**< Month.*/ |
| 70 | uint8_t day; /**< Day.*/ |
| 71 | uint8_t hours; /**< Hour. 00 ~ 23 */ |
| 72 | uint8_t minutes; /**< Minutes.*/ |
| 73 | uint8_t seconds; /**< Seconds.*/ |
| 74 | /** |
| 75 | * The Time Zone indicates the difference, expressed in quarters of an hour, |
| 76 | * between the local time and GMT. |
| 77 | * */ |
| 78 | uint8_t timezone; |
| 79 | } ql_sms_timestamp_t; |
| 80 | |
| 81 | typedef struct |
| 82 | { |
| 83 | |
| 84 | uint8_t valid; /**< Indicate whether following is valid, 1 - valid; 0 - invalid; */ |
| 85 | uint8_t total_seg; /**< The number of long message segment*/ |
| 86 | uint8_t cur_seg_num; /**< Current number.*/ |
| 87 | uint8_t ref_num; /**< reference number.*/ |
| 88 | } ql_sms_user_data_head_t; |
| 89 | |
| 90 | typedef void (*ql_sms_msg_async_cb_f)(int id, int result); |
| 91 | typedef void (*ql_sms_msg_recv_cb_f)(ql_sms_msg_t *p_msg, ql_sms_timestamp_t *timestamp, |
| 92 | ql_sms_user_data_head_t *head); |
| 93 | |
| 94 | /** The SMS PDU format. */ |
| 95 | typedef enum |
| 96 | { |
| 97 | QL_SMS_PDU_FORMAT_CDMA = 0, |
| 98 | QL_SMS_PDU_FORMAT_GW_PP = 6, |
| 99 | } QL_SMS_PDU_FORMAT_E; |
| 100 | |
| 101 | /** The SMS PDU structure. */ |
| 102 | typedef struct |
| 103 | { |
| 104 | QL_SMS_PDU_FORMAT_E format; |
| 105 | int content_size; |
| 106 | char content[QL_SMS_MAX_SEND_PDU_LENGTH]; |
| 107 | } ql_sms_pdu_t; |
| 108 | |
| 109 | |
| 110 | typedef void (*ql_sms_pdu_async_cb_f)(int id, int result); |
| 111 | typedef void (*ql_sms_pdu_recv_cb_f)(ql_sms_pdu_t *p_pdu); |
| 112 | typedef void (*ql_sms_service_error_cb_f)(int error); |
| 113 | |
| 114 | |
| 115 | /*-----------------------------------------------------------------------------------------------*/ |
| 116 | /** |
| 117 | @brief Initializes SMS service. |
| 118 | @return Whether the SMS service was initialized successfully. |
| 119 | @retval QL_ERR_OK successful. |
| 120 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 121 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 122 | @retval Other error code defined by ql_type.h. |
| 123 | */ |
| 124 | /*-----------------------------------------------------------------------------------------------*/ |
| 125 | int ql_sms_init(void); |
| 126 | |
| 127 | /*-----------------------------------------------------------------------------------------------*/ |
| 128 | /** |
| 129 | @brief Deinitializes SMS service. |
| 130 | @return Whether the SMS service was deinitialized successfully. |
| 131 | @retval QL_ERR_OK successful. |
| 132 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 133 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 134 | @retval Other error code defined by ql_type.h. |
| 135 | */ |
| 136 | /*-----------------------------------------------------------------------------------------------*/ |
| 137 | int ql_sms_deinit(void); |
| 138 | |
| 139 | /*-----------------------------------------------------------------------------------------------*/ |
| 140 | /** |
| 141 | @brief Sets the service center address. |
| 142 | @param[in] addr service center address. |
| 143 | @param[in] len service center address length. |
| 144 | @return Whether the service center address was set successfully. |
| 145 | @retval QL_ERR_OK successful. |
| 146 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 147 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 148 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 149 | @retval Other error code defined by ql_type.h. |
| 150 | */ |
| 151 | /*-----------------------------------------------------------------------------------------------*/ |
| 152 | int ql_sms_set_service_center_addr(char *addr, int len); |
| 153 | |
| 154 | /*-----------------------------------------------------------------------------------------------*/ |
| 155 | /** |
| 156 | @brief Gets the service center address. |
| 157 | @param[out] addr service center address. |
| 158 | @param[in] len service center address length. |
| 159 | @return Whether the service center address was successfully obtained. |
| 160 | @retval QL_ERR_OK successful. |
| 161 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 162 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 163 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 164 | @retval Other error code defined by ql_type.h. |
| 165 | */ |
| 166 | /*-----------------------------------------------------------------------------------------------*/ |
| 167 | int ql_sms_get_service_center_addr(char *addr, int len); |
| 168 | |
| 169 | /*-----------------------------------------------------------------------------------------------*/ |
| 170 | /** |
| 171 | @brief Sends message synchronously. |
| 172 | @param[in] p_msg pointer to ql_sms_msg_t. |
| 173 | @return Whether the message was successfully sent synchronously. |
| 174 | @retval QL_ERR_OK successful. |
| 175 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 176 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 177 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 178 | @retval Other error code defined by ql_type.h. |
| 179 | */ |
| 180 | /*-----------------------------------------------------------------------------------------------*/ |
| 181 | int ql_sms_send_msg(ql_sms_msg_t *p_msg); |
| 182 | |
| 183 | /*-----------------------------------------------------------------------------------------------*/ |
| 184 | /** |
| 185 | @brief Sends message asynchronously. |
| 186 | @param[in] p_msg pointer to ql_sms_msg_t |
| 187 | @param[out] id id for this async operation |
| 188 | @param[in] cb async callback |
| 189 | @return Whether the message was successfully sent asynchronously. |
| 190 | @retval QL_ERR_OK successful. |
| 191 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 192 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 193 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 194 | @retval Other error code defined by ql_type.h. |
| 195 | */ |
| 196 | /*-----------------------------------------------------------------------------------------------*/ |
| 197 | int ql_sms_send_msg_async(ql_sms_msg_t *p_msg, int *id, ql_sms_msg_async_cb_f cb); |
| 198 | |
| 199 | /*-----------------------------------------------------------------------------------------------*/ |
| 200 | /** |
| 201 | @brief Sets SMS message reception callback hanlder. |
| 202 | @param[in] cb message reception callback handler. |
| 203 | @return Whether the message reception callback hanlder was set successfully. |
| 204 | @retval QL_ERR_OK successful. |
| 205 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 206 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 207 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 208 | @retval Other error code defined by ql_type.h. |
| 209 | */ |
| 210 | /*-----------------------------------------------------------------------------------------------*/ |
| 211 | int ql_sms_set_msg_recv_cb(ql_sms_msg_recv_cb_f cb); |
| 212 | |
| 213 | /*-----------------------------------------------------------------------------------------------*/ |
| 214 | /** |
| 215 | @brief Sends PDU synchronously. |
| 216 | @param[in] p_pdu SMS PDU. |
| 217 | @return Whether the PDU was successfully sent synchronously. |
| 218 | @retval QL_ERR_OK successful. |
| 219 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 220 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 221 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 222 | @retval Other error code defined by ql_type.h. |
| 223 | */ |
| 224 | /*-----------------------------------------------------------------------------------------------*/ |
| 225 | int ql_sms_send_pdu(ql_sms_pdu_t *p_pdu); |
| 226 | |
| 227 | /*-----------------------------------------------------------------------------------------------*/ |
| 228 | /** |
| 229 | @brief Sends PDU asynchronously. |
| 230 | @param[in] p_pdu sms pdu. |
| 231 | @param[out] id id for this async operation. |
| 232 | @param[in] cb async callback. |
| 233 | @return Whether the PDU was successfully sent asynchronously. |
| 234 | @retval QL_ERR_OK successful. |
| 235 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 236 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 237 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 238 | @retval Other error code defined by ql_type.h. |
| 239 | */ |
| 240 | /*-----------------------------------------------------------------------------------------------*/ |
| 241 | int ql_sms_send_pdu_async(ql_sms_pdu_t *p_pdu, int *id, ql_sms_pdu_async_cb_f cb); |
| 242 | |
| 243 | /*-----------------------------------------------------------------------------------------------*/ |
| 244 | /** |
| 245 | @brief Sets SMS PDU reception callback hanlder. |
| 246 | @param[in] cb PDU reception callback handler. |
| 247 | @return Whether the PDU reception callback hanlder was set successfully. |
| 248 | @retval QL_ERR_OK successful. |
| 249 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 250 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 251 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 252 | @retval Other error code defined by ql_type.h. |
| 253 | */ |
| 254 | /*-----------------------------------------------------------------------------------------------*/ |
| 255 | int ql_sms_set_pdu_recv_cb(ql_sms_pdu_recv_cb_f cb); |
| 256 | |
| 257 | /*-----------------------------------------------------------------------------------------------*/ |
| 258 | /** |
| 259 | @brief Registration server error callback. Currently, only if the server exits abnormally, |
| 260 | the callback function will be executed, and the error code is QL_ERR_ABORTED; |
| 261 | @param[in] cb Callback function |
| 262 | @return |
| 263 | QL_ERR_OK - successful |
| 264 | Other - error code defined by ql_type.h |
| 265 | */ |
| 266 | /*-----------------------------------------------------------------------------------------------*/ |
| 267 | int ql_sms_set_service_error_cb(ql_sms_service_error_cb_f cb); |
| 268 | |
| 269 | /*-----------------------------------------------------------------------------------------------*/ |
| 270 | /** |
| 271 | @brief Binds the current control point to a specific subscription. |
| 272 | @param[in] sub Subscription type. |
| 273 | @return Whether the subscription was successfully bound. |
| 274 | @retval QL_ERR_OK successful. |
| 275 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 276 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 277 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 278 | @retval Other error code defined by ql_type.h. |
| 279 | */ |
| 280 | /*-----------------------------------------------------------------------------------------------*/ |
| 281 | int ql_sms_bind_subscription(QL_SMS_SUBSCRIPTION_E sub); |
| 282 | |
l.yang | e4f94f4 | 2025-04-29 18:08:39 -0700 | [diff] [blame^] | 283 | /*-----------------------------------------------------------------------------------------------*/ |
| 284 | /** |
| 285 | @brief chose sim card to send sms |
| 286 | @param[in] sub Subscription type. |
| 287 | @return Whether the subscription was successfully bound. |
| 288 | @retval QL_ERR_OK successful. |
| 289 | @retval QL_ERR_INVALID_ARG invalid argument. |
| 290 | @retval QL_ERR_UNKNOWN unknown error, failed to connect to service. |
| 291 | @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry. |
| 292 | @retval Other error code defined by ql_type.h. |
| 293 | */ |
| 294 | /*-----------------------------------------------------------------------------------------------*/ |
| 295 | int ql_set_sms_slot(QL_SIM_SLOT_E log_slot); |
| 296 | |
b.liu | d440f9f | 2025-04-18 10:44:31 +0800 | [diff] [blame] | 297 | |