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