mal_api.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _MAL_API_H_
  13. #define _MAL_API_H_
  14. #include "osi_api.h"
  15. #include "cfw.h"
  16. #include "osi_event_hub.h"
  17. #include "time.h"
  18. OSI_EXTERN_C_BEGIN
  19. /**
  20. * @brief SIM authentication state
  21. */
  22. typedef enum
  23. {
  24. MAL_SIM_AUTH_READY = 0, ///< Phone is not waiting for any password.
  25. MAL_SIM_AUTH_PIN1_READY = 1, ///< Phone is not waiting for PIN1 password.
  26. MAL_SIM_AUTH_SIMPIN = 2, ///< Phone is waiting for the SIM Personal Identification Number (PIN)
  27. MAL_SIM_AUTH_SIMPUK = 3, ///< Phone is waiting for the SIM Personal Unlocking Key (PUK).
  28. MAL_SIM_AUTH_PHONE_TO_SIMPIN = 4, ///< Phone is waiting for the phone-to-SIM card password.
  29. MAL_SIM_AUTH_PHONE_TO_FIRST_SIMPIN = 5, ///< Phone is waiting for the phone-to-first-SIM card PIN.
  30. MAL_SIM_AUTH_PHONE_TO_FIRST_SIMPUK = 6, ///< Phone is waiting for the phone-to-first-SIM card PUK.
  31. MAL_SIM_AUTH_SIMPIN2 = 7, ///< Phone is waiting for the SIM PIN2.
  32. MAL_SIM_AUTH_SIMPUK2 = 8, ///< Phone is waiting for the SIM PUK2.
  33. MAL_SIM_AUTH_NETWORKPIN = 9, ///< Phone is waiting for the network personalization PIN.
  34. MAL_SIM_AUTH_NETWORKPUK = 10, ///< Phone is waiting for the network personalization PUK.
  35. MAL_SIM_AUTH_NETWORK_SUBSETPIN = 11, ///< Phone is waiting for the network subset personalization PIN.
  36. MAL_SIM_AUTH_NETWORK_SUBSETPUK = 12, ///< Phone is waiting for the network subset personalization PUK.
  37. MAL_SIM_AUTH_PROVIDERPIN = 13, ///< Phone is waiting for the service provider personalization PIN.
  38. MAL_SIM_AUTH_PROVIDERPUK = 14, ///< Phone is waiting for the service provider personalization PUK.
  39. MAL_SIM_AUTH_CORPORATEPIN = 15, ///< Phone is waiting for the corporate personalization PIN.
  40. MAL_SIM_AUTH_CORPORATEPUK = 16, ///< Phone is waiting for the corporate personalization PUK.
  41. MAL_SIM_AUTH_NOSIM = 17, ///< No SIM inserted.
  42. MAL_SIM_AUTH_PIN1BLOCK = 18,
  43. MAL_SIM_AUTH_PIN2BLOCK = 19,
  44. MAL_SIM_AUTH_PIN1_DISABLE = 20,
  45. MAL_SIM_AUTH_SIM_PRESENT = 21,
  46. MAL_SIM_AUTH_SIM_PHASE = 22,
  47. MAL_SIM_AUTH_SIM_END = 23,
  48. MAL_SIM_AUTH_PIN2_DISABLE = 24,
  49. } malSimState_t;
  50. /**
  51. * @brief initialize modem abstraction layer excution engine
  52. */
  53. void malInit(void);
  54. /**
  55. * @brief (+CPIN?)
  56. *
  57. * @param sim SIM index, ignored in single SIM version
  58. * @param state SIM state
  59. * @param remaintries remaining retry count
  60. * @return
  61. * - 0 on success
  62. * - error code on fail
  63. */
  64. unsigned malSimGetState(int sim, malSimState_t *state, unsigned *remaintries);
  65. #define IS_NORMAL_CALL 0
  66. #define IS_EMC_CALL 1
  67. #define IS_NWEMC_CALL 2
  68. /**
  69. * @brief (hanld call type for ATD Command)
  70. *
  71. * Description:this api is used to handle the types of calls
  72. * is normal call,emc call or nw emc call.
  73. *
  74. * @param dnum PhoneNumber
  75. * @param nSim SIM index, ignored in single SIM version
  76. * @return
  77. * - 0 is normal call
  78. * - 1 is emc call
  79. * - 2 is nw emc call
  80. * - error code on fail
  81. */
  82. unsigned _toVoiceDail(CFW_DIALNUMBER_V2 *dnum, CFW_SIM_ID nSim);
  83. /**
  84. * @brief (ATD Command)
  85. *
  86. * Description:this api is used to make calls.
  87. *
  88. * @param dnum PhoneNumber
  89. * @param nSim SIM index, ignored in single SIM version
  90. * @return
  91. * - 0 is normal call success
  92. * - 1 is emc call success
  93. * - 2 is nw emc call success
  94. * - error code on fail
  95. */
  96. unsigned malCcMakeCall(CFW_DIALNUMBER_V2 *dnum, uint8_t nSim);
  97. /**
  98. * @brief (ATH Command)
  99. *
  100. * Description:this api is used to Release calls.
  101. *
  102. * @param nSim SIM index, ignored in single SIM version
  103. * @return
  104. * - 0 Release call success
  105. * - error code on fail
  106. */
  107. unsigned malDisconnectCall(uint8_t nSim);
  108. /**
  109. * @brief (CGATT SetCommand)
  110. *
  111. * Description:this api is used to Attached or Detached network.
  112. *
  113. * @param actattflag 1:for active to Attach 0:for attached or detach
  114. * @param nState Set attached or detached state
  115. * @param AttDetactType Set attach or detach
  116. * @param nSim SIM index, ignored in single SIM version
  117. * @return
  118. * - 0 on success
  119. * - error code on fail
  120. */
  121. unsigned malPsAttach(uint8_t actattflag, uint8_t nState, uint8_t AttDetactType, uint8_t nSim);
  122. /**
  123. * @brief (CGACT SetCommand)
  124. *
  125. * Description:this api is used to Active or Deactive network.
  126. *
  127. * @param nState Set cgact state
  128. * @param nCid Cid flag
  129. * @param nSim SIM index, ignored in single SIM version
  130. * @param nPCid Second cid flag
  131. * @return
  132. * - 0 or 1 on success
  133. * - error code on fail
  134. */
  135. unsigned malPsActivatePdn(uint8_t nState, uint8_t nCid, uint8_t nSim, uint8_t nPCid);
  136. /**
  137. * @brief (COPS SetCommand)
  138. *
  139. * Description:this api is used to register or unregister network operator.
  140. *
  141. * @param nOperatorId Set Operator Id
  142. * @param nMode Network mode
  143. * @param nAct Wireless access techhologt
  144. * @param nSim SIM index, ignored in single SIM version
  145. * @return
  146. * - 0 on success
  147. * - 1 on Register Network again,Network mode is auto.
  148. * - error code on fail
  149. */
  150. unsigned setNetworkOperator(uint8_t nOperatorId[6], uint8_t nMode, uint8_t nAct, uint8_t nSim);
  151. /**
  152. * @brief (COPS TestCommand)
  153. *
  154. * Description:this api is used to get Available network operator.
  155. *
  156. * @param operatorInfo operator information, operatorInfo need to be free after use
  157. * @param operatorCount operator count
  158. * @param nSim SIM index, ignored in single SIM version
  159. * @return
  160. * - 0 on success
  161. * - error code on fail
  162. */
  163. unsigned getAvailableNwOperator(CFW_NW_OPERATOR_INFO *operatorInfo, uint16_t *operatorCount, uint8_t nSim);
  164. /**
  165. * @brief (*****Command COPS_V2)
  166. *
  167. * Description:this api is used to get Available network operator.
  168. *
  169. * @param operatorInfo_v2 operator information,operatorInfo_v2 need to be free after use
  170. * @param operatorCount operator number
  171. * @param nSim SIM index, ignored in single SIM version
  172. * @return
  173. * - 0 on success
  174. * - error code on fail
  175. */
  176. unsigned simVsimGetEO(CFW_NW_OPERATOR_INFO_V2 **operatorInfo_v2, uint16_t *operatorCount, uint8_t nSim);
  177. /**
  178. * @brief (CPOL SetCommand)
  179. *
  180. * Description:this api is used to Write Sim Prefer PLMN.
  181. *
  182. * @param nIndex PLMN number
  183. * @param nOperator PLMN set by user
  184. * @param nSize PLMN length
  185. * @param nSim SIM index, ignored in single SIM version
  186. * @return
  187. * - 0 on success
  188. * - error code on fail
  189. */
  190. unsigned setPreferPLMN(uint16_t nIndex, uint8_t *nOperator, uint8_t nSize, uint8_t nSim);
  191. /**
  192. * @brief (CPOL TestCommand)
  193. *
  194. * Description:this api is used to PLMN Count.
  195. *
  196. * @param nOperNum Get PLMN count to user
  197. * @param nSim SIM index, ignored in single SIM version
  198. * @return
  199. * - 0 on success
  200. * - error code on fail
  201. */
  202. unsigned getPreferOperatorCount(uint32_t *nOperNum, uint8_t nSim);
  203. /**
  204. * @brief (CPOL ReadCommand)
  205. *
  206. * Description:this api is used to PLMN Count.
  207. *
  208. * @param nReadData Read the PLMN name list to the user
  209. * @param nCount Read the number of plmn to the user
  210. * @param nSim SIM index, ignored in single SIM version
  211. * @return
  212. * - 0 on success
  213. * - error code on fail
  214. */
  215. unsigned getPreferPlmnList(uint32_t *nReadData, uint16_t *nCount, uint8_t nSim);
  216. typedef struct
  217. {
  218. uint8_t nStatus; // The status of message in memory
  219. uint16_t nIndex; // Physical storage index
  220. } MAL_SMS_INDEX_T;
  221. typedef struct _MAL_SMS_INDEX_NODE_T
  222. {
  223. uint8_t nDcs; // The data coding scheme of the TP UD field, and may indicate a message class
  224. uint8_t nStatus; // The status of message in memory
  225. uint8_t nTotal; // The total number of concatenated short message
  226. uint16_t nRefNum; // The reference number of concatenated short message
  227. uint8_t nStorage; // The storage location
  228. time_t nTime;
  229. uint8_t nSimId;
  230. osiTimer_t *pTimer;
  231. struct _MAL_SMS_INDEX_NODE_T *pNext;
  232. MAL_SMS_INDEX_T pPhyIndex[0];
  233. } MAL_SMS_INDEX_NODE_T;
  234. typedef struct
  235. {
  236. uint8_t nSimId;
  237. uint8_t nTotal; // The total number of concatenated short message
  238. uint16_t nRefNum; // The reference number of concatenated short message
  239. uint8_t nDcs; // The data coding scheme of the TP UD field, and may indicate a message class
  240. uint8_t nStorage; // The storage location
  241. MAL_SMS_INDEX_T pPhyIndex[0]; // The storage information of concatenated short message
  242. } MAL_SMS_MSG_INFO_T;
  243. typedef struct
  244. {
  245. CFW_SMS_LIST *pListInfo;
  246. } MAL_LISTMESSAGES_CTX;
  247. #define SMS_INDEX_NODE_SIZE(n) (sizeof(MAL_SMS_INDEX_NODE_T) + sizeof(MAL_SMS_INDEX_T) * (n))
  248. typedef struct
  249. {
  250. uint8_t nCurrent;
  251. MAL_SMS_INDEX_NODE_T *pMap;
  252. uint32_t nResult;
  253. } MAL_SMS_DELETE_CTX_T;
  254. typedef struct
  255. {
  256. uint8_t bFirst;
  257. uint8_t nCurrent;
  258. MAL_SMS_INDEX_NODE_T *pMap;
  259. CFW_SMS_NODE_EX *pNode;
  260. } MAL_SMS_READ_CTX_T;
  261. typedef struct
  262. {
  263. uint8_t bFirst;
  264. uint8_t nStorage;
  265. uint8_t nStatus;
  266. CFW_EVENT sEvent;
  267. } MAL_SMS_WRITE_CTX_T;
  268. typedef struct
  269. {
  270. uint8_t nCurrent;
  271. MAL_SMS_INDEX_NODE_T *pMap;
  272. uint32_t nResult;
  273. } MAL_SMS_UNSENT_TO_SENT_CTX_T;
  274. void mal_SmsInitMsgMap(uint8_t nSim);
  275. uint32_t mal_SmsAddSmsNode(CFW_SMS_NODE_EX *pNode, uint8_t nSim);
  276. uint32_t mal_SmsAddNewSmsNode(CFW_NEW_SMS_NODE_EX *pNode, CFW_EMS_INFO *pConcatInfo, uint8_t nSim);
  277. uint32_t mal_SmsListMessages(CFW_SMS_LIST *pListInfo, CFW_SIM_ID nSimId);
  278. /**
  279. * @brief (Exe Command CVSIMRESET)
  280. *
  281. * Description: Getting the concatenated short message according index.
  282. *
  283. * @param nIndex The index of the list of concatenated short message
  284. * @return
  285. * - NULL fail
  286. * - SUCCESS
  287. */
  288. MAL_SMS_MSG_INFO_T *mal_SmsGetMsgInfo(uint16_t nIndex);
  289. uint32_t mal_SmsReadMessage(uint8_t nStorage, uint8_t nType, uint16_t nIndex, void *cb_ctx, osiEventCallback_t cb, CFW_SIM_ID nSimId);
  290. uint32_t mal_SmsDeleteMessage(uint16_t nIndex, uint8_t nStatus, uint8_t nStorage, uint8_t nType, void *cb_ctx, osiEventCallback_t cb, CFW_SIM_ID nSimId);
  291. uint32_t mal_SmsWriteMessage(CFW_DIALNUMBER_V2 *pNumber, uint8_t *pData, uint16_t nDataSize, uint16_t nIndex, uint8_t nStorage, uint8_t nType, uint8_t nStatus, void *cb_ctx, osiEventCallback_t cb, CFW_SIM_ID nSimID);
  292. void mal_SmsChangeStatus(uint8_t nIndex, uint8_t nStorage, uint16_t nRefNum, uint8_t nStatus, uint8_t nSimId);
  293. bool mal_SmsIsRecordExist(uint16_t nIndex, uint8_t nStorage, CFW_SIM_ID nSimId, MAL_SMS_INDEX_NODE_T **map);
  294. bool mal_SmsIsSingleRecordExist(uint16_t nIndex, uint8_t nStorage, CFW_SIM_ID nSimId, uint8_t *current, MAL_SMS_INDEX_NODE_T **map);
  295. void mal_SmsDeleteSingleMessage(uint16_t nIndex, uint8_t nStatus, uint8_t nStorage, CFW_SIM_ID nSimId);
  296. void mal_SmsSetUnSent2Sent(uint8_t nStorage, uint8_t nType, uint16_t nIndex, uint8_t nSendStatus,
  297. void *cb_ctx, osiEventCallback_t cb, CFW_SIM_ID nSimId);
  298. uint32_t mal_SmsWriteLongInfo(uint8_t nStorage, uint8_t nStatus, uint32_t nParam1, uint32_t nParam2, uint8_t nSim);
  299. /**
  300. * @brief (Set Command GWIFISCAN)
  301. *
  302. * Description: This command is used to wifiscan.
  303. *
  304. * @param wifiscanReq: input parameters
  305. * @param atWifiApRes: get wifiscan result information
  306. * @param wifiApNum: get get scan ap node number
  307. * @param maxApNum: get wifiscan max ap number
  308. * @param nSim: SIM index, ignored in single SIM version
  309. * @return
  310. * - 1 on success
  311. * - error code on fail
  312. */
  313. unsigned malWifiScanHSLToCfw(CFW_WIFISCAN_REQ wifiscanReq, CFW_WIFISCAN_AP_RESULT **atWifiApRes, uint16_t *wifiApNum, uint16_t *maxApNum, uint8_t nSim);
  314. OSI_EXTERN_C_END
  315. #endif