at_cmd_sms.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #ifndef __AT_CMD_SMS_H__
  2. #define __AT_CMD_SMS_H__
  3. #include "ats_config.h"
  4. #include "mal_api.h"
  5. #include "quec_proj_config.h"
  6. #include "quec_atcmd_sms.h"
  7. #define AT_SMS_STATUS_UNREAD 0
  8. #define AT_SMS_STATUS_READ 1
  9. #define AT_SMS_STATUS_UNSENT 2
  10. #define AT_SMS_STATUS_SENT 3
  11. #define AT_SMS_STATUS_ALL 4
  12. #define AT_SMS_LONG_MAX_SIZE 420
  13. #ifdef CONFIG_QUEC_PROJECT_FEATURE_SMS
  14. bool atSmsGetPduNum(const uint8_t *pPDUData, uint8_t *pPDUNUM, uint8_t *pType, uint8_t *nPDULen);
  15. bool atSmsIsPduValid(uint8_t *pPDUData, uint8_t *nPDULen, bool bReadOrListMsgFlag);
  16. #else
  17. static bool atSmsGetPduNum(const uint8_t *pPDUData, uint8_t *pPDUNUM, uint8_t *pType, uint8_t *nPDULen);
  18. static bool atSmsIsPduValid(uint8_t *pPDUData, uint8_t *nPDULen, bool bReadOrListMsgFlag);
  19. #endif
  20. /**
  21. * add sca to pdu
  22. */
  23. #ifdef CONFIG_QUEC_PROJECT_FEATURE_SMS
  24. bool atSmsPduAddSca(uint8_t *InPDU, uint8_t *OutPDU, size_t *pSize, uint8_t nSim);
  25. #else
  26. static bool atSmsPduAddSca(uint8_t *InPDU, uint8_t *OutPDU, size_t *pSize, uint8_t nSim);
  27. #endif
  28. #define SMS_CMGS_MAX_SIZE 1024 + 2 // include ctrl+z
  29. #ifndef CONFIG_QUEC_PROJECT_FEATURE_SMS
  30. typedef struct
  31. {
  32. CFW_DIALNUMBER_V2 number;
  33. uint8_t *data;
  34. unsigned pdu_length;
  35. } cmgsAsyncContext_t;
  36. #endif
  37. #ifndef CONFIG_QUEC_PROJECT_FEATURE_SMS
  38. typedef struct
  39. {
  40. CFW_DIALNUMBER_V2 number;
  41. uint8_t data[SMS_MAX_SIZE];
  42. unsigned pdu_length;
  43. } cmgcAsyncContext_t;
  44. typedef struct
  45. {
  46. CFW_DIALNUMBER_V2 number;
  47. uint8_t stat;
  48. uint8_t *data;
  49. uint8_t pdu_data[SMS_MAX_SIZE];
  50. uint32_t pdu_length;
  51. } cmgwAsyncCtx_t;
  52. #endif
  53. typedef struct
  54. {
  55. CFW_DIALNUMBER_V2 number;
  56. unsigned number_strlen;
  57. unsigned nindex;
  58. uint8_t status;
  59. } cmssAsyncContext_t;
  60. typedef struct
  61. {
  62. uint32_t value1;
  63. uint32_t value2;
  64. } smsValueIntegerMap_t;
  65. static const osiValueStrMap_t gSmsState[] = {
  66. {CFW_SMS_STORED_STATUS_UNREAD, "REC UNREAD"},
  67. {CFW_SMS_STORED_STATUS_READ, "REC READ"},
  68. {CFW_SMS_STORED_STATUS_UNSENT, "STO UNSENT"},
  69. {CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ, "STO SENT"},
  70. {CFW_SMS_STORED_STATUS_STORED_ALL, "ALL"},
  71. {0, NULL},
  72. };
  73. static const osiValueStrMap_t gCmgwSmsState[] = {
  74. {CFW_SMS_STORED_STATUS_UNSENT, "STO UNSENT"},
  75. {CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ, "STO SENT"},
  76. {0, NULL},
  77. };
  78. static const osiValueStrMap_t gSmsNumState[] = {
  79. {AT_SMS_STATUS_UNREAD, "REC UNREAD"},
  80. {AT_SMS_STATUS_READ, "REC READ"},
  81. {AT_SMS_STATUS_UNSENT, "STO UNSENT"},
  82. {AT_SMS_STATUS_SENT, "STO SENT"},
  83. {AT_SMS_STATUS_ALL, "ALL"},
  84. {0, NULL},
  85. };
  86. static smsValueIntegerMap_t gSmsStatusCfwToAt[] = {
  87. {CFW_SMS_STORED_STATUS_UNREAD, AT_SMS_STATUS_UNREAD},
  88. {CFW_SMS_STORED_STATUS_READ, AT_SMS_STATUS_READ},
  89. {CFW_SMS_STORED_STATUS_UNSENT, AT_SMS_STATUS_UNSENT},
  90. {CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ, AT_SMS_STATUS_SENT},
  91. {CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_RECV, AT_SMS_STATUS_SENT},
  92. {CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_STORE, AT_SMS_STATUS_SENT},
  93. {CFW_SMS_STORED_STATUS_SENT_SR_REQ_RECV_STORE, AT_SMS_STATUS_SENT},
  94. {CFW_SMS_STORED_STATUS_STORED_ALL, CFW_SMS_STORED_STATUS_STORED_ALL},
  95. {0, 0},
  96. };
  97. static smsValueIntegerMap_t gAtStatusToCfw[] = {
  98. {AT_SMS_STATUS_UNREAD, CFW_SMS_STORED_STATUS_UNREAD},
  99. {AT_SMS_STATUS_READ, CFW_SMS_STORED_STATUS_READ},
  100. {AT_SMS_STATUS_UNSENT, CFW_SMS_STORED_STATUS_UNSENT},
  101. {AT_SMS_STATUS_SENT, CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ |
  102. CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_RECV |
  103. CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_STORE |
  104. CFW_SMS_STORED_STATUS_SENT_SR_REQ_RECV_STORE},
  105. {AT_SMS_STATUS_ALL, CFW_SMS_STORED_STATUS_STORED_ALL},
  106. {5, 0xff},
  107. };
  108. static smsValueIntegerMap_t gAtCmgdStatusToCfw[] = {
  109. {0, 0},
  110. {1, CFW_SMS_STORED_STATUS_READ},
  111. {2, CFW_SMS_STORED_STATUS_READ | CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ |
  112. CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_RECV | CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_STORE |
  113. CFW_SMS_STORED_STATUS_SENT_SR_REQ_RECV_STORE},
  114. {3, CFW_SMS_STORED_STATUS_READ | CFW_SMS_STORED_STATUS_SENT_NOT_SR_REQ |
  115. CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_RECV | CFW_SMS_STORED_STATUS_SENT_SR_REQ_NOT_STORE |
  116. CFW_SMS_STORED_STATUS_SENT_SR_REQ_RECV_STORE | CFW_SMS_STORED_STATUS_UNSENT},
  117. {4, CFW_SMS_STORED_STATUS_STORED_ALL},
  118. {5, 0xff},
  119. };
  120. static const osiValueStrMap_t gStoreList[] = {
  121. {CFW_SMS_STORAGE_ME, "ME"},
  122. {CFW_SMS_STORAGE_MT, "MT"},
  123. {CFW_SMS_STORAGE_SM, "SM"},
  124. {0, NULL},
  125. };
  126. typedef struct
  127. {
  128. uint8_t n;
  129. uint8_t cnma_data[200];
  130. uint16_t cnma_data_length;
  131. } cnmaAsyncContext_t;
  132. #ifdef CONFIG_CONCAT_SMS_SUPPORT
  133. typedef struct
  134. {
  135. uint8_t nCurrent; // the index of the segment of the concatenated short message
  136. uint16_t nRefNum; // The reference number of concatenated short message
  137. uint16_t nPhyIndex; // Physical storage index
  138. uint8_t nStorage;
  139. uint8_t nSimId;
  140. char *pHeadStr; // The string of urc of contain +CMGL
  141. char *pDataStr; // The real sms data
  142. uint16_t pDataStrLen;
  143. } SMS_BUF_NODE_T;
  144. SMS_BUF_NODE_T *pSmsBufNode[32] = {
  145. 0,
  146. };
  147. typedef struct _AT_SMS_INIT_ALL
  148. {
  149. uint8_t nSim;
  150. uint8_t nStorage;
  151. } AT_SMS_INIT_ALL;
  152. typedef struct _CMGL_UNREAD_TO_READ_PARAM_T
  153. {
  154. uint8_t simId;
  155. uint16_t refNum;
  156. } CMGL_UNREAD_TO_READ_PARAM_T;
  157. typedef struct
  158. {
  159. uint8_t delflag;
  160. uint16_t nIndex;
  161. uint8_t nStatus;
  162. uint8_t nStorage;
  163. } cmgdAsyncContext_t;
  164. typedef struct
  165. {
  166. uint8_t current;
  167. uint8_t nIndex;
  168. void *map;
  169. } cmgrAsyncContext_t;
  170. #endif
  171. #ifdef CONFIG_AT_SMS_CB_SUPPORT
  172. /*
  173. the short message class enum
  174. */
  175. typedef enum _AT_SMS_CLASS_E
  176. {
  177. AT_SMS_CLASS_0,
  178. AT_SMS_CLASS_1,
  179. AT_SMS_CLASS_2,
  180. AT_SMS_CLASS_3
  181. } AT_SMS_CLASS_E;
  182. typedef enum
  183. {
  184. AT_SMSCB_GERMAN_ID = 0,
  185. AT_SMSCB_ENGLISH_ID = 1,
  186. AT_SMSCB_ITALIAN_ID = 2,
  187. AT_SMSCB_FRENCH_ID = 3,
  188. AT_SMSCB_SPANISH_ID = 4,
  189. AT_SMSCB_DUTCH_ID = 5,
  190. AT_SMSCB_SWEDISH_ID = 6,
  191. AT_SMSCB_DANISH_ID = 7,
  192. AT_SMSCB_PORTUGUESE_ID = 8,
  193. AT_SMSCB_FINNISH_ID = 9,
  194. AT_SMSCB_NORWEGIAN_ID = 10,
  195. AT_SMSCB_GREEK_ID = 11,
  196. AT_SMSCB_TURKISH_ID = 12,
  197. AT_SMSCB_HUNGARIAN_ID = 13,
  198. AT_SMSCB_POLISH_ID = 14,
  199. AT_SMSCB_LANGUAGE_UNSPECIFIED = 15,
  200. AT_SMSCB_CZECH_ID = 0x20,
  201. AT_SMSCB_HEBREW_ID = 0x21,
  202. AT_SMSCB_ARABIC_ID = 0x22,
  203. AT_SMSCB_RUSSIAN_ID = 0x23,
  204. AT_SMSCB_ICELANDIC_ID = 0x24,
  205. AT_SMSCB_CHINESE_ID = 0x48,
  206. AT_SMSCB_LANGUAGE_NUM = 0x7a7b // max language id = 0x7a7a(zz)
  207. } AT_SMSCB_LANGUAGE_ID_E;
  208. /*
  209. the alphabet type being used
  210. */
  211. typedef enum _AT_SMS_ALPHABET_TYPE_E
  212. {
  213. AT_SMS_DEFAULT_ALPHABET = 0, // default alphabet
  214. AT_SMS_8_BIT_ALPHBET, // 8 bit data
  215. AT_SMS_UCS2_ALPHABET, // UCS2(16bit)
  216. AT_SMS_RESERVED_ALPHABET // reserved
  217. } AT_SMS_ALPHABET_TYPE_E;
  218. typedef struct _AT_SMSCB_DCS_T
  219. {
  220. bool class_is_present; // whether use specified class
  221. AT_SMS_CLASS_E sms_class; // the sms class type
  222. AT_SMS_ALPHABET_TYPE_E alphabet_type; // the alphabet type
  223. bool language_id_present;
  224. AT_SMSCB_LANGUAGE_ID_E language_id;
  225. } AT_SMSCB_DCS_T;
  226. typedef uint16_t AT_CB_MSG_ID_T;
  227. typedef uint8_t AT_CB_UPDATE_T;
  228. typedef uint8_t AT_MESSAGE_CODE_T;
  229. typedef uint16_t AT_MSG_CODE_T;
  230. typedef uint8_t SMSCB_UPDATE_NUM_T;
  231. typedef uint8_t SMSCB_PAGE_TOTAL_NUM_T;
  232. typedef uint8_t SMSCB_PAGE_CURR_NUM_T;
  233. typedef uint8_t SMSCB_GEOGRAPH_SCOPE_T;
  234. typedef uint8_t SMSCB_MSG_CODE_T;
  235. #define SMSCB_INVALID_PAGE_NUM 0
  236. #define AT_CB_MSG_LEN 93
  237. #define GET_MSG_CODE(_msg_value_ptr) \
  238. (((uint16_t)(*(_msg_value_ptr)&0x3F) << 4) | ((uint16_t)(*((_msg_value_ptr) + 1) >> 4)))
  239. #define GET_UPDATE_NUM(_msg_value) \
  240. ((_msg_value)&0x0f)
  241. #define GET_MSG_ID(_msg_value_ptr) \
  242. (((uint16_t)(*(_msg_value_ptr)) << 8) | ((uint16_t) * (((_msg_value_ptr) + 1))))
  243. #define GET_GS_CODE(_msg_value_ptr) \
  244. (((*(_msg_value_ptr)) & 0xc0) >> 6)
  245. typedef enum
  246. {
  247. AT_CB_DISPLAY_IMMEDIATE,
  248. AT_CB_DISPLAY_NORMAL
  249. } AT_CB_DISPLAY_MODE_E;
  250. #define AT_CB_MAX_PAGE_NUM 15
  251. #define SMSCB_PAGE_LENGTH 88
  252. typedef SLIST_ENTRY(SMSCB_PAGE_MSG) atCbPageMsgIter_t;
  253. typedef SLIST_HEAD(atCbPageMsgHead, SMSCB_PAGE_MSG) atCbPageMsgHead_t;
  254. typedef uint8_t AT_CB_PAGE_ARR_T[SMSCB_PAGE_LENGTH];
  255. struct SMSCB_PAGE_MSG
  256. {
  257. atCbPageMsgIter_t iter;
  258. uint16_t msg_id;
  259. uint16_t msg_code;
  260. AT_SMSCB_DCS_T dcs_t;
  261. uint8_t page_total_num;
  262. uint8_t cur_page_len[AT_CB_MAX_PAGE_NUM];
  263. AT_CB_PAGE_ARR_T page_arr[AT_CB_MAX_PAGE_NUM];
  264. };
  265. typedef struct SMSCB_PAGE_MSG SMSCB_PAGE_MSG_T;
  266. atCbPageMsgHead_t gAtCbPageMsgList[CONFIG_NUMBER_OF_SIM] = {NULL};
  267. #endif
  268. #endif