ql_api_sms.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /**
  2. @file
  3. ql_sms.h
  4. @brief
  5. This file provides the definitions for sms API functions.
  6. */
  7. /*============================================================================
  8. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  9. Quectel Wireless Solution Proprietary and Confidential.
  10. =============================================================================*/
  11. /*===========================================================================
  12. EDIT HISTORY FOR MODULE
  13. This section contains comments describing changes made to the module.
  14. Notice that changes are listed in reverse chronological order.
  15. WHEN WHO WHAT, WHERE, WHY
  16. ---------- ------------ ----------------------------------------------------
  17. marvin create
  18. =============================================================================*/
  19. #ifndef QL_API_SMS_H
  20. #define QL_API_SMS_H
  21. #include <stdint.h>
  22. #include <stdbool.h>
  23. #include "sockets.h"
  24. #include "ql_api_common.h"
  25. #include "ql_api_osi.h"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /*========================================================================
  30. * Marco Definition
  31. *========================================================================*/
  32. #define QL_SMS_LOG_LEVEL QL_LOG_LEVEL_INFO
  33. #define QL_SMS_LOG(msg, ...) QL_LOG_TAG(QL_LOG_LEVEL_INFO, QL_LOG_TAG_SMS, "ql_sms", msg, ##__VA_ARGS__)
  34. #define QL_SMS_MIN_LEN 1
  35. #define MAX_LONGSMS_SEGMENT 8
  36. #define MAX_SMS_LENGTH (160*4)
  37. #define SMS_BUF_LEN (MAX_SMS_LENGTH + 32)
  38. #define MAX_LONGSMS_LENGTH (160*4*MAX_LONGSMS_SEGMENT)
  39. #define QL_TEL_MAX_LEN 21
  40. #define QL_SMS_PDU_MAX_LEN 176
  41. /*========================================================================
  42. * Enumeration Definition
  43. *========================================================================*/
  44. typedef enum
  45. {
  46. QL_SMS_SUCCESS = 0,
  47. QL_SMS_ERROR = 1 | (QL_COMPONENT_SMS << 16),
  48. QL_SMS_NOT_INIT_ERR,
  49. QL_SMS_PARA_ERR,
  50. QL_SMS_NO_MEMORY_ERR,
  51. QL_SMS_SEM_CREATE_ERR,
  52. QL_SMS_SEM_TIMEOUT_ERR,
  53. QL_SMS_NO_MSG_ERR,
  54. }ql_sms_errcode_e;
  55. typedef enum
  56. {
  57. QL_SMS_INIT_OK_IND = 1| (QL_COMPONENT_SMS << 16),
  58. QL_SMS_NEW_MSG_IND,
  59. QL_SMS_LIST_IND,
  60. QL_SMS_LIST_END_IND,
  61. QL_SMS_LIST_EX_IND,
  62. QL_SMS_MEM_FULL_IND,
  63. QL_SMS_REPORT_IND,
  64. }ql_sms_event_id_e;
  65. typedef enum
  66. {
  67. ME = 1, //Mobile Equipment message storage
  68. SM = 2,//SIM message storage
  69. }ql_sms_stor_e;
  70. typedef enum
  71. {
  72. GSM = 0,
  73. UCS2 = 1,
  74. }ql_sms_code_e;
  75. typedef enum
  76. {
  77. PDU = 0,
  78. TEXT = 1
  79. }ql_sms_format_e;
  80. typedef enum
  81. {
  82. QL_SMS_UNREAD = 0,
  83. QL_SMS_READ = 1,
  84. QL_SMS_UNSENT = 2,
  85. QL_SMS_SENT = 3,
  86. QL_SMS_ALL,
  87. }ql_sms_status_e;
  88. typedef enum {
  89. QL_SMS_DEL_INDEX = 0, /* Delete the message specified in <index> */
  90. QL_SMS_DEL_RECV_READ, /* Delete all read messages from <mem1> storage */
  91. QL_SMS_DEL_RECV_READ_SENT, /* Delete all read messages from <mem1> storage and sent mobile originated messages */
  92. QL_SMS_DEL_RECV_READ_MO, /* Delete all read messages from <mem1> storage, sent and unsent mobile originated messages */
  93. QL_SMS_DEL_ALL, /* Delete all messages from <mem1> storage */
  94. QL_SMS_DEL_MODES_NUMS
  95. }QL_SMS_DELETE_MODE;
  96. typedef enum
  97. {
  98. QL_CS_GSM,
  99. QL_CS_IRA,
  100. QL_CS_UCS2,
  101. QL_CS_ALL,
  102. } ql_sms_cscs_e;
  103. /*========================================================================
  104. * Struct Definition
  105. *========================================================================*/
  106. typedef struct{
  107. uint8_t status;
  108. uint8_t index;
  109. char* buf;
  110. uint16_t buf_len;
  111. }ql_sms_msg_s;
  112. typedef struct{
  113. uint8_t index;
  114. uint8_t mem;
  115. }ql_sms_new_s;
  116. typedef struct
  117. {
  118. uint16_t usedSlotSM;
  119. uint16_t totalSlotSM;
  120. uint16_t unReadRecordsSM;
  121. uint16_t usedSlotME;
  122. uint16_t totalSlotME;
  123. uint16_t unReadRecordsME;
  124. ql_sms_stor_e newSmsStorId;
  125. }ql_sms_stor_info_s;
  126. typedef struct
  127. {
  128. ql_sms_stor_e mem1; //messages to be read and deleted from this memory storage.
  129. ql_sms_stor_e mem2; //messages will be written and sent to this memory storage.
  130. ql_sms_stor_e mem3; //received messages will be placed in this memory storage if routing to PC is not set.
  131. }ql_sms_mem_info_t;
  132. typedef struct
  133. {
  134. uint16_t uYear; //Only the last two digits
  135. uint8_t uMonth;
  136. uint8_t uDay;
  137. uint8_t uHour;
  138. uint8_t uMinute;
  139. uint8_t uSecond;
  140. int8_t iZone;
  141. }ql_sms_time_stamp_s;
  142. typedef struct
  143. {
  144. uint8_t index; //Index in storage
  145. char oa[QL_TEL_MAX_LEN*4+1];//Originating Address
  146. uint8_t tooa; //Type of originating Address
  147. ql_sms_time_stamp_s scts; //Service Centre Time Stamp
  148. ql_sms_status_e status;
  149. uint8_t fo; //First octet of PDU
  150. uint8_t dcs; //Data Coding Scheme
  151. uint16_t uid; //Message identification of a concatenated message
  152. uint8_t msg_seg; //Sequence number of a concatenated message
  153. uint8_t msg_total; //The total number of the segments of one concatenated message.
  154. uint16_t dataLen; //number of bytes
  155. uint8_t data[QL_SMS_PDU_MAX_LEN*2+1];
  156. }ql_sms_recv_s;
  157. typedef struct
  158. {
  159. bool srr; //Status Report Request
  160. uint8_t vp; //Validiy Period
  161. ql_sms_code_e code;
  162. uint8_t mr; //[out] Message Reference
  163. }ql_sms_cfg_s;
  164. typedef struct
  165. {
  166. uint8_t ra[TEL_NUMBER_MAX_LEN];
  167. uint8_t ra_size;
  168. uint8_t tora;
  169. uint8_t fo;
  170. uint8_t mr;
  171. uint8_t st;
  172. ql_sms_time_stamp_s scts;
  173. ql_sms_time_stamp_s dt;
  174. } ql_sms_report_s;
  175. /*========================================================================
  176. * Callback Definition
  177. *========================================================================*/
  178. typedef void (*ql_sms_event_handler_t)(uint8_t sim_id, int event_id, void *ctx);
  179. extern ql_sms_event_handler_t ql_sms_callback;
  180. /*========================================================================
  181. * function Definition
  182. *========================================================================*/
  183. /*****************************************************************
  184. * Function: ql_sms_send_msg
  185. *
  186. * Description:
  187. * 发送文本格式的短消息
  188. *
  189. * Parameters:
  190. * nSim [in] SIM卡索引,取值0-1。
  191. * phone_num [in] 目的手机号码。
  192. * data [in] 短消息数据。
  193. * code [in] 短消息发送时采用的格式,可取值GSM或者UCS2
  194. *
  195. * Return:ql_sms_errcode_e
  196. *
  197. *****************************************************************/
  198. ql_sms_errcode_e ql_sms_send_msg(uint8_t nSim, char *phone_num, char *data, ql_sms_code_e code);
  199. /*****************************************************************
  200. * Function: ql_sms_send_msg_ex
  201. *
  202. * Description:
  203. * 发送文本格式的短消息,可配置短信报告请求
  204. *
  205. * Parameters:
  206. * nSim [in] SIM卡索引,取值0-1。
  207. * phone_num [in] 目的手机号码。
  208. * data [in] 短消息数据。
  209. * cfg [in/out] 短消息发送时的配置,其中mr为[out]参数
  210. *
  211. * Return:ql_sms_errcode_e
  212. *
  213. *****************************************************************/
  214. ql_sms_errcode_e ql_sms_send_msg_ex(uint8_t nSim, char *phone_num, char *data, ql_sms_cfg_s *cfg);
  215. /*****************************************************************
  216. * Function: ql_sms_send_pdu
  217. *
  218. * Description:
  219. * 发送PDU格式的短消息
  220. *
  221. * Parameters:
  222. * nSim [in] SIM卡索引,取值0-1。
  223. * pdu [in] 短消息数据。
  224. *
  225. * Return:ql_sms_errcode_e
  226. *
  227. *****************************************************************/
  228. ql_sms_errcode_e ql_sms_send_pdu(uint8_t nSim, char *pdu);
  229. /*****************************************************************
  230. * Function: ql_sms_get_msg_list
  231. *
  232. * Description:
  233. * 获取短消息列表
  234. *
  235. * Parameters:
  236. * nSim [in] SIM卡索引,取值0-1。
  237. * format [in] PDU或者TEXT格式
  238. * Return:ql_sms_errcode_e
  239. *
  240. *****************************************************************/
  241. ql_sms_errcode_e ql_sms_read_msg_list(uint8_t nSim, ql_sms_format_e format);
  242. /*****************************************************************
  243. * Function: ql_sms_read_msg
  244. *
  245. * Description:
  246. * 文本方式读取单条短消息
  247. *
  248. * Parameters:
  249. * nSim [in] SIM卡索引,取值0-1。
  250. * index [in] 短信索引号。
  251. * buf [out] 用于接收短信内容,其基本组成形式为"<oa>,<scts>,<data>"。
  252. * buf_len [out] 数组长度。
  253. * format [in] 短信格式。文本或者PDU格式。
  254. *
  255. * Return:ql_sms_errcode_e
  256. *
  257. *****************************************************************/
  258. ql_sms_errcode_e ql_sms_read_msg(uint8_t nSim, uint8_t index, char *buf, uint16_t buf_len, ql_sms_format_e format);
  259. /*****************************************************************
  260. * Function: ql_sms_read_msg_ex
  261. *
  262. * Description:
  263. * 读取单条短消息
  264. *
  265. * Parameters:
  266. * nSim [in] SIM卡索引,取值0-1。
  267. * index [in] 短信索引号。
  268. * format [in] 短信格式。文本或者PDU格式。
  269. * msg [out] 参考ql_sms_recv_s结构体。
  270. * Return:ql_sms_errcode_e
  271. *
  272. *****************************************************************/
  273. ql_sms_errcode_e ql_sms_read_msg_ex(uint8_t nSim, uint8_t index, ql_sms_format_e format, ql_sms_recv_s *msg);
  274. /*****************************************************************
  275. * Function: ql_sms_delete_msg
  276. *
  277. * Description:
  278. * 删除单条消息
  279. *
  280. * Parameters:
  281. * nSim [in] SIM卡索引,取值0-1。
  282. * index [in] 短消息序列号。
  283. * Return:ql_sms_errcode_e
  284. *
  285. *****************************************************************/
  286. ql_sms_errcode_e ql_sms_delete_msg(uint8_t nSim, uint8_t index);
  287. /*****************************************************************
  288. * Function: ql_sms_delete_msg_ex
  289. *
  290. * Description:
  291. * 删除单条消息
  292. *
  293. * Parameters:
  294. * nSim [in] SIM卡索引,取值0-1。
  295. * index [in] 短消息序列号。
  296. * del_mode [in] QL_SMS_DELETE_MODE类型数据.
  297. * Return:ql_sms_errcode_e
  298. *
  299. *****************************************************************/
  300. ql_sms_errcode_e ql_sms_delete_msg_ex(uint8_t nSim, uint8_t index, QL_SMS_DELETE_MODE del_mode);
  301. /*****************************************************************
  302. * Function: ql_sms_get_center_address
  303. *
  304. * Description:
  305. * 获取短消息中心号码
  306. *
  307. * Parameters:
  308. * nSim [in] SIM卡索引,取值0-1。
  309. * address [out] 短消息中心号码。
  310. * len [in] 接收短消息中心号码的数组长度.
  311. *
  312. * Return:ql_sms_errcode_e
  313. *
  314. *****************************************************************/
  315. ql_sms_errcode_e ql_sms_get_center_address(uint8_t nSim, char* address, uint8_t len);
  316. /*****************************************************************
  317. * Function: ql_sms_set_center_address
  318. *
  319. * Description:
  320. * 设置短消息中心号码
  321. *
  322. * Parameters:
  323. * nSim [in] SIM卡索引,取值0-1。
  324. * address [in] 短消息中心号码。
  325. *
  326. * Return:ql_sms_errcode_e
  327. *
  328. *****************************************************************/
  329. ql_sms_errcode_e ql_sms_set_center_address(uint8_t nSim, char* address);
  330. /*****************************************************************
  331. * Function: ql_sms_get_storage_info
  332. *
  333. * Description:
  334. * 获取SM与ME的存储信息
  335. *
  336. * Parameters:
  337. * nSim [in] SIM卡索引,取值0-1。
  338. * stor_info [out] 用于保存短信存储信息的结构体。
  339. *
  340. * Return:ql_sms_errcode_e
  341. *
  342. *****************************************************************/
  343. ql_sms_errcode_e ql_sms_get_storage_info(uint8_t nSim, ql_sms_stor_info_s *stor_info);
  344. /*****************************************************************
  345. * Function: ql_sms_set_storage
  346. *
  347. * Description:
  348. * 设置短信存储位置
  349. *
  350. * Parameters:
  351. * nSim [in] SIM卡索引,取值0-1。
  352. * mem1 [in] 读取和删除消息所在内存空间。
  353. * mem2 [in] 写入和发送消息的内存空间。
  354. * mem3 [in] 接收消息的存储位置。
  355. *
  356. * Return:ql_sms_errcode_e
  357. *
  358. *****************************************************************/
  359. ql_sms_errcode_e ql_sms_set_storage(uint8_t nSim, ql_sms_stor_e mem1,ql_sms_stor_e mem2, ql_sms_stor_e mem3);
  360. /*****************************************************************
  361. * Function: ql_sms_get_storage
  362. *
  363. * Description:
  364. * 获取短信存储位置
  365. *
  366. * Parameters:
  367. * nSim [in] SIM卡索引,取值0-1。
  368. * mem_info [in] 见ql_sms_mem_info_t结构体。
  369. *
  370. * Return:ql_sms_errcode_e
  371. *
  372. *****************************************************************/
  373. ql_sms_errcode_e ql_sms_get_storage(uint8_t nSim, ql_sms_mem_info_t *mem_info);
  374. /*****************************************************************
  375. * Function: ql_sms_set_code_mode
  376. *
  377. * Description:
  378. * 设置字符编码
  379. *
  380. * Parameters:
  381. * cscs [in] 字符编码,参考ql_sms_cscs_e联合体。
  382. * Return:ql_sms_errcode_e
  383. *
  384. *****************************************************************/
  385. ql_sms_errcode_e ql_sms_set_code_mode(ql_sms_cscs_e cscs);
  386. /*****************************************************************
  387. * Function: ql_sms_get_code_mode
  388. *
  389. * Description:
  390. * 获取字符编码
  391. *
  392. * Parameters:
  393. * cscs [out] 返回当前字符编码。
  394. * Return:ql_sms_errcode_e
  395. *
  396. *****************************************************************/
  397. ql_sms_errcode_e ql_sms_get_code_mode(ql_sms_cscs_e* cscs);
  398. /*****************************************************************
  399. * Function: ql_sms_set_retry_count
  400. *
  401. * Description:
  402. * 用于设置smc层与smr层短消息发送失败后的重试次数
  403. *
  404. * Parameters:
  405. * nSim [in] SIM卡索引,取值0-1。
  406. * smc_count [in] smc层重试次数,取值0-2。
  407. * smr_count [in] smr层重试次数,取值0-2。
  408. *
  409. * Return:ql_sms_errcode_e
  410. *
  411. *****************************************************************/
  412. ql_sms_errcode_e ql_sms_set_retry_count(uint8_t nSim, uint8_t smc_count, uint8_t smr_count);
  413. /*****************************************************************
  414. * Function: ql_sms_get_ignore_cscs
  415. *
  416. * Description:
  417. * 用于获取在读取短信时, 当短信的编码为8bit或者16bit时,是否忽略CSCS值。
  418. *
  419. * Parameters:
  420. * nSim [in] SIM卡索引,取值0-1。
  421. * enable [out] 是否忽略cscs值。
  422. *
  423. * Return:ql_sms_errcode_e
  424. *
  425. *****************************************************************/
  426. ql_sms_errcode_e ql_sms_get_ignore_cscs(uint8_t nSim, bool *enable);
  427. /*****************************************************************
  428. * Function: ql_sms_set_ignore_cscs
  429. *
  430. * Description:
  431. * 用于设置在读取短信时, 当短信的编码为8bit或者16bit时,是否忽略CSCS值。
  432. *
  433. * Parameters:
  434. * nSim [in] SIM卡索引,取值0-1。
  435. * enable [in] 是否忽略cscs值。
  436. *
  437. * Return:ql_sms_errcode_e
  438. *
  439. *****************************************************************/
  440. ql_sms_errcode_e ql_sms_set_ignore_cscs(uint8_t nSim, bool enable);
  441. /*****************************************************************
  442. * Function: ql_sms_get_storage_info
  443. *
  444. * Description:
  445. * 获取短信模块初始化状态
  446. *
  447. * Parameters:
  448. * nSim [in] SIM卡索引,取值0-1。
  449. * status [out] 短信初始化状态
  450. *
  451. * Return:ql_sms_errcode_e
  452. *
  453. *****************************************************************/
  454. ql_sms_errcode_e ql_sms_get_init_status(uint8_t nSim, uint8_t *status);
  455. /*****************************************************************
  456. * Function: ql_sms_get_storage_info
  457. *
  458. * Description:
  459. * 注册短信回调函数
  460. *
  461. * Parameters:
  462. * cb [in] 回调函数
  463. *
  464. * Return:ql_sms_errcode_e
  465. *
  466. *****************************************************************/
  467. void ql_sms_callback_register(ql_sms_event_handler_t cb);
  468. #ifdef __cplusplus
  469. }/*"C" */
  470. #endif
  471. #endif /*QL_API_SMS_H*/