luat_mobile.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #ifndef __LUAT_MOBILE_H__
  22. #define __LUAT_MOBILE_H__
  23. #include "luat_base.h"
  24. /**
  25. * @defgroup luatos_mobile 移动网络相关接口
  26. * @{
  27. */
  28. /**
  29. * @brief 获取IMEI
  30. *
  31. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  32. * @param buff[OUT] IMEI数据
  33. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  34. * @return int <= 0错误 >0实际传出的大小
  35. */
  36. int luat_mobile_get_imei(int sim_id, char* buff, size_t buf_len);
  37. /**
  38. * @brief 获取SN,如果用户没有调用luat_mobile_set_sn接口写过SN,默认值为空
  39. *
  40. * @param buff[OUT] SN数据
  41. * @param buf_len 用户传入缓存的大小,EC618平台底层支持的最大长度为32字节,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  42. * @return int <= 0错误 >0实际传出的大小
  43. */
  44. int luat_mobile_get_sn(char* buff, size_t buf_len);
  45. /**
  46. * @brief 设置SN
  47. *
  48. * @param buff SN数据,必须是ascii值大于等于0x21小于等于0x7e的可见ascii字符
  49. * @param buf_len SN数据长度;EC618平台底层支持的最大长度为32字节,如果buf_len大于32,只会保存前32字节的数据
  50. * @return int = 0成功, = -1失败
  51. */
  52. int luat_mobile_set_sn(char* buff, uint8_t buf_len);
  53. /**
  54. * @brief 获取MUID,并不一定存在
  55. *
  56. * @param buff[OUT] MUID数据
  57. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  58. * @return int <= 0错误 >0实际传出的大小
  59. */
  60. int luat_mobile_get_muid(char* buff, size_t buf_len);
  61. /**
  62. * @brief 获取SIM卡的ICCID
  63. *
  64. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  65. * @param buff[OUT] ICCID数据
  66. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  67. * @return int <= 0错误 >0实际传出的大小
  68. */
  69. int luat_mobile_get_iccid(int sim_id, char* buff, size_t buf_len);
  70. /**
  71. * @brief 获取SIM卡的IMSI
  72. *
  73. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  74. * @param buff[OUT] IMSI数据
  75. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  76. * @return int <= 0错误 >0实际传出的大小
  77. */
  78. int luat_mobile_get_imsi(int sim_id, char* buff, size_t buf_len);
  79. /**
  80. * @brief 当前使用的SIM卡的手机号,注意,只有写入了手机号才能读出,因此有可能读出来是空的
  81. *
  82. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  83. * @param buff[OUT] sim_number数据
  84. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  85. * @return int <= 0错误 >0实际传出的大小
  86. */
  87. int luat_mobile_get_sim_number(int sim_id, char* buff, size_t buf_len);
  88. /**
  89. * @brief 当前使用的SIM卡的位置,并不一定支持
  90. *
  91. * @param id[OUT] sim位置,对于双卡双待的设备,输出0或者1,其他设备输出0
  92. * @return int =0成功,其他失败
  93. */
  94. int luat_mobile_get_sim_id(int *id);
  95. /**
  96. * @brief 改变使用的SIM卡的位置,并不一定支持
  97. *
  98. * @param id sim位置,对于双卡的设备,选0或者1,其他为自动选择模式。非双卡的设备不支持
  99. * @return int =0成功,其他失败
  100. */
  101. int luat_mobile_set_sim_id(int id);
  102. typedef enum LUAT_MOBILE_SIM_PIN_OP
  103. {
  104. LUAT_SIM_PIN_VERIFY = 0, /* verify pin code */
  105. LUAT_SIM_PIN_CHANGE, /* change pin code */
  106. LUAT_SIM_PIN_ENABLE, /* enable the pin1 state for verification */
  107. LUAT_SIM_PIN_DISABLE, /* disable the pin1 state */
  108. LUAT_SIM_PIN_UNBLOCK, /* unblock pin code */
  109. // LUAT_SIM_PIN_QUERY, /* query pin1 state, enable or disable */
  110. }LUAT_MOBILE_SIM_PIN_OP_E;
  111. /**
  112. * @brief 对SIM卡的pin码做操作
  113. *
  114. * @param id sim位置,对于双卡的设备,选0或者1,其他为自动选择模式,但是0和1的优先级是一致的。非双卡的设备不支持
  115. * @param operation 操作码,见LUAT_MOBILE_SIM_PIN_OP_E
  116. * @param pin1 旧的pin码,或者验证的pin码,解锁pin码时的PUK,参考手机操作
  117. * @param pin2 更换pin码操作时的新的pin码,解锁pin码时的新PIN,参考手机操作
  118. * @return int =0成功,其他失败
  119. */
  120. int luat_mobile_set_sim_pin(int id, uint8_t operation, char pin1[9], char pin2[9]);
  121. /**
  122. * @brief 检查SIM卡是否准备好
  123. *
  124. * @param id sim位置,对于双卡的设备,选0或者1,其他为自动选择模式,但是0和1的优先级是一致的。非双卡的设备不支持
  125. * @return =1准备好,其他未准备好,或者SIM卡不在位
  126. */
  127. uint8_t luat_mobile_get_sim_ready(int id);
  128. /**
  129. * @brief 在自动选择模式时,开机后优先用sim0
  130. *
  131. */
  132. void luat_mobile_set_sim_detect_sim0_first(void);
  133. /**
  134. * @brief 设置默认PDN激活时是否要IPV6网络,现在默认情况下不开
  135. * @param onoff 1开 0关
  136. * @return uint8_t 1开 0关
  137. */
  138. void luat_mobile_set_default_pdn_ipv6(uint8_t onoff);
  139. /**
  140. * @brief 返回默认PDN激活时是否要IPV6网络
  141. * @return uint8_t 1开 0关
  142. */
  143. uint8_t luat_mobile_get_default_pdn_ipv6(void);
  144. /**
  145. * @brief 获取配置的apn name,并不一定支持
  146. *
  147. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  148. * @param cid cid位置 1~6
  149. * @param buff[OUT] apn name
  150. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  151. * @return int <= 0错误 >0实际传出的大小
  152. */
  153. int luat_mobile_get_apn(int sim_id, int cid, char* buff, size_t buf_len);
  154. /**
  155. * @brief 用户控制APN激活过程。只有使用了本函数后,才能通过手动激活用户的APN并加装网卡
  156. */
  157. void luat_mobile_user_ctrl_apn(void);
  158. /**
  159. * @brief 手动设置APN激活所需的最小信息,如果需要更详细的设置,可以自行修改本函数
  160. *
  161. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  162. * @param cid cid位置 2~6
  163. * @param type 激活类型 1 IPV4 2 IPV6 3 IPV4V6
  164. * @param apn_name apn name
  165. * @param name_len apn name 长度
  166. * @return int <= 0错误 >0实际传出的大小
  167. */
  168. int luat_mobile_set_apn_base_info(int sim_id, int cid, uint8_t type, uint8_t* apn_name, uint8_t name_len);
  169. /**
  170. * @brief 手动设置APN激活所需的加密信息,如果需要更详细的设置,可以自行修改本函数。大部分情况下不需要加密信息,定向卡可能需要
  171. *
  172. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  173. * @param cid cid位置 2~6
  174. * @param protocol 加密协议 1~3,0和0xff表示不需要
  175. * @param user_name 用户名
  176. * @param user_name_len 用户名长度
  177. * @param password 密码
  178. * @param password_len 密码长度
  179. * @return int <= 0错误 >0实际传出的大小
  180. */
  181. int luat_mobile_set_apn_auth_info(int sim_id, int cid, uint8_t protocol, uint8_t *user_name, uint8_t user_name_len, uint8_t *password, uint8_t password_len);
  182. /**
  183. * @brief 手动激活/去激活APN
  184. *
  185. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  186. * @param cid cid位置 2~6
  187. * @param state 1激活 0去激活
  188. * @return int <= 0错误 >0实际传出的大小
  189. */
  190. int luat_mobile_active_apn(int sim_id, int cid, uint8_t state);
  191. /**
  192. * @brief 手动激活网卡
  193. *
  194. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  195. * @param cid cid位置 2~6
  196. * @return int <= 0错误 >0实际传出的大小
  197. */
  198. int luat_mobile_active_netif(int sim_id, int cid);
  199. /**
  200. * @brief 用户设置APN的基本信息,并且自动激活,注意不能和上述手动操作APN的API共用,专网卡如果不能用公网apn激活默认承载的必须用这个
  201. *
  202. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  203. * @param cid cid位置 1~6
  204. * @param ip_type 激活类型 1 IPV4 2 IPV6 3 IPV4V6
  205. * @param protocol_type 加密协议 0~2,0xff表示不需要
  206. * @param apn_name apn name,如果留空则使用默认APN
  207. * @param apn_name_len apn name 长度
  208. * @param user_name 用户名
  209. * @param user_name_len 用户名长度
  210. * @param password 密码
  211. * @param password_len 密码长度
  212. * @return 无
  213. */
  214. void luat_mobile_user_apn_auto_active(int sim_id, uint8_t cid,
  215. uint8_t ip_type,
  216. uint8_t protocol_type,
  217. uint8_t *apn_name, uint8_t apn_name_len,
  218. uint8_t *user, uint8_t user_len,
  219. uint8_t *password, uint8_t password_len);
  220. /**
  221. * @brief 获取默认CID的apn name,并不一定支持
  222. *
  223. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  224. * @param buff[OUT] apn name
  225. * @param buf_len 用户传入缓存的大小,如果底层数据量大于buf_len,只会传出buf_len大小的数据
  226. * @return int <= 0错误 >0实际传出的大小
  227. */
  228. int luat_mobile_get_default_apn(int sim_id, char* buff, size_t buf_len);
  229. /**
  230. * @brief 删除定义好的apn
  231. *
  232. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  233. * @param cid cid位置 1~6
  234. * @param is_dedicated 是否是专用的,不清楚的写0
  235. * @return int =0成功,其他失败
  236. */
  237. int luat_mobile_del_apn(int sim_id, uint8_t cid, uint8_t is_dedicated);
  238. /**
  239. * @brief 进出飞行模式
  240. *
  241. * @param index sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  242. * @param mode 飞行模式,1进入,0退出
  243. * @return int =0成功,其他失败
  244. */
  245. int luat_mobile_set_flymode(int index, int mode);
  246. /**
  247. * @brief 飞行模式当前状态
  248. *
  249. * @param index sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  250. * @return int <0 异常 =0飞行模式 =1正常工作 =4射频关闭
  251. */
  252. int luat_mobile_get_flymode(int index);
  253. #if (!defined __LUATOS__) || ((defined __LUATOS__) && (defined LUAT_USE_LWIP))
  254. #include "lwip/opt.h"
  255. #include "lwip/netif.h"
  256. #include "lwip/inet.h"
  257. /**
  258. * @brief 获取已激活承载分配的本地ip地址
  259. *
  260. * @param sim_id sim位置,对于双卡双待的设备,选0或者1,其他设备随意
  261. * @param cid cid位置 1~6,没有使用专网APN的话,就是用1
  262. * @param ip_v4, ipv4的IP地址
  263. * @param ip_v6, ipv6的IP地址
  264. * @return int =0成功,其他失败
  265. */
  266. int luat_mobile_get_local_ip(int sim_id, int cid, ip_addr_t *ip_v4, ip_addr_t *ip_v6);
  267. #endif
  268. /* -------------------------------------------------- cell info begin -------------------------------------------------- */
  269. #define LUAT_MOBILE_CELL_MAX_NUM 9
  270. typedef struct luat_mobile_gsm_service_cell_info
  271. {
  272. int cid; /**< Cell ID, (0 indicates information is not represent).*/
  273. int mcc; /**< This field should be ignored when cid is not present*/
  274. int mnc; /**< This field should be ignored when cid is not present*/
  275. int lac; /**< Location area code.(This field should be ignord when cid is not present). */
  276. int arfcn; /**< Absolute RF channel number. */
  277. int bsic; /**< Base station identity code. (0 indicates information is not present). */
  278. int rssi; /**< Receive signal strength, Value range: rxlev-111 for dbm format */
  279. }luat_mobile_gsm_service_cell_info_t;
  280. typedef struct luat_mobile_gsm_cell_info
  281. {
  282. int cid; /**Cell ID, (0 indicates information is not represent).*/
  283. int mcc; /**This field should be ignored when cid is not present*/
  284. int mnc; /**This field should be ignored when cid is not present*/
  285. int lac; /**Location area code.(This field should be ignord when cid is not present). */
  286. int arfcn; /**Absolute RF channel number. */
  287. int bsic; /**Base station identity code. (0 indicates information is not present). */
  288. int rssi; /**< Receive signal strength, Value range: rxlev-111 for dbm format */
  289. }luat_mobile_gsm_cell_info_t;
  290. typedef struct luat_mobile_lte_service_cell_info
  291. {
  292. uint32_t cid; /**<Cell ID, (0 indicates information is not represent).*/
  293. uint16_t mcc; /**This field should be ignored when cid is not present*/
  294. uint16_t mnc; /**This field should be ignored when cid is not present*/
  295. uint16_t tac; /**Tracing area code (This field should be ignored when cid is not present). */
  296. uint16_t pci; /**Physical cell ID. Range: 0 to 503. */
  297. uint32_t earfcn; /**E-UTRA absolute radio frequency channel number of the cell. RANGE: 0 TO 65535. */
  298. int16_t rssi; /**< Receive signal strength, Value range: rsrp-140 for dbm format */
  299. int16_t rsrp;
  300. int16_t rsrq;
  301. int16_t snr;
  302. uint8_t is_tdd;
  303. uint8_t band;
  304. uint8_t ulbandwidth;
  305. uint8_t dlbandwidth;
  306. }luat_mobile_lte_service_cell_info_t;
  307. typedef struct luat_mobile_lte_cell_info
  308. {
  309. uint32_t cid; /**<Cell ID, (0 indicates information is not represent).*/
  310. uint16_t mcc; /**This field should be ignored when cid is not present*/
  311. uint16_t mnc; /**This field should be ignored when cid is not present*/
  312. uint16_t tac; /**Tracing area code (This field should be ignored when cid is not present). */
  313. uint16_t pci; /**Physical cell ID. Range: 0 to 503. */
  314. uint32_t earfcn; /**E-UTRA absolute radio frequency channel number of the cell. RANGE: 0 TO 65535. */
  315. int16_t rsrp;
  316. int16_t rsrq;
  317. int16_t snr;
  318. }luat_mobile_lte_cell_info_t;
  319. typedef struct luat_mobile_cell_info
  320. {
  321. luat_mobile_gsm_service_cell_info_t gsm_service_info;
  322. luat_mobile_gsm_cell_info_t gsm_info[LUAT_MOBILE_CELL_MAX_NUM]; /**< GSM cell information (Serving and neighbor. */
  323. luat_mobile_lte_service_cell_info_t lte_service_info;
  324. luat_mobile_lte_cell_info_t lte_info[LUAT_MOBILE_CELL_MAX_NUM]; /**< LTE cell information (Serving and neighbor). */
  325. uint8_t gsm_info_valid; /**< Must be set to TRUE if gsm_info is being passed. */
  326. uint8_t gsm_neighbor_info_num; /**< Must be set to the number of elements in entry*/
  327. uint8_t lte_info_valid; /**< Must be set to TRUE if lte_info is being passed. */
  328. uint8_t lte_neighbor_info_num; /**< Must be set to the number of elements in entry*/
  329. }luat_mobile_cell_info_t;
  330. /**
  331. * @brief 立刻搜索一次周围小区基站信息,并同步返回结果
  332. *
  333. * @param info 当前移动网络信号状态详细信息
  334. * @return int =0成功,其他失败
  335. */
  336. int luat_mobile_get_cell_info(luat_mobile_cell_info_t *info);
  337. /**
  338. * @brief 立刻搜索一次周围小区基站信息,通过LUAT_MOBILE_CELL_INFO_UPDATE返回搜索完成消息,luat_mobile_get_last_notify_cell_info获取详细信息
  339. *
  340. * @param max_time 搜索的最大时间,单位秒
  341. * @return int =0成功,其他失败
  342. */
  343. int luat_mobile_get_cell_info_async(uint8_t max_time);
  344. /**
  345. * @brief 获取上一次异步搜索周围小区基站信息,包括周期性搜索和异步搜索,在LUAT_MOBILE_CELL_INFO_UPDATE到来后用本函数获取信息
  346. *
  347. * @param info 当前移动网络信号状态详细信息
  348. * @param max_time 搜索的最大时间
  349. * @return int =0成功,其他失败
  350. */
  351. int luat_mobile_get_last_notify_cell_info(luat_mobile_cell_info_t *info);
  352. typedef struct luat_mobile_gw_signal_strength_info
  353. {
  354. int rssi;
  355. int bitErrorRate;
  356. int rscp;
  357. int ecno;
  358. }luat_mobile_gw_signal_strength_info_t;
  359. typedef struct luat_mobile_lte_signal_strength_info
  360. {
  361. int16_t rssi; /**< Receive signal strength, Value range: rsrp-140 for dbm format */
  362. int16_t rsrp;
  363. int16_t rsrq;
  364. int16_t snr;
  365. }luat_mobile_lte_signal_strength_info_t;
  366. typedef struct luat_mobile_signal_strength_info
  367. {
  368. luat_mobile_gw_signal_strength_info_t gw_signal_strength;
  369. luat_mobile_lte_signal_strength_info_t lte_signal_strength;
  370. uint8_t luat_mobile_gw_signal_strength_vaild;
  371. uint8_t luat_mobile_lte_signal_strength_vaild;
  372. }luat_mobile_signal_strength_info_t;
  373. /**
  374. * @brief 从RSSI转换到CSQ,RSSI只能作为天线口状态的一个参考,而不能作为LTE网络信号状态的参考
  375. *
  376. * @param rssi RSSI值
  377. * @return uint8_t CSQ值
  378. */
  379. uint8_t luat_mobile_rssi_to_csq(int8_t rssi);
  380. /**
  381. * @brief 获取当前移动网络信号状态详细信息
  382. *
  383. * @param info 当前移动网络信号状态详细信息
  384. * @return int =0成功,其他失败
  385. */
  386. int luat_mobile_get_signal_strength_info(luat_mobile_signal_strength_info_t *info);
  387. /**
  388. * @brief 获取CSQ值 CSQ从RSSI转换而来,只能作为天线口状态的一个参考,而不能作为LTE网络信号状态的参考
  389. *
  390. * @param csq CSQ值
  391. * @return int =0成功,其他失败
  392. */
  393. int luat_mobile_get_signal_strength(uint8_t *csq);
  394. /**
  395. * @brief 获取最近一次网络信号状态更新通知后的网络信号状态详细信息
  396. *
  397. * @param info 网络信号状态详细信息
  398. * @return int =0成功,其他失败
  399. */
  400. int luat_mobile_get_last_notify_signal_strength_info(luat_mobile_signal_strength_info_t *info);
  401. /**
  402. * @brief 获取最近一次网络信号状态更新通知后的CSQ值
  403. *
  404. * @param info CSQ值
  405. * @return int =0成功,其他失败
  406. */
  407. int luat_mobile_get_last_notify_signal_strength(uint8_t *csq);
  408. /**
  409. * @brief 获取当前服务小区的ECI
  410. *
  411. * @param eci
  412. * @return int =0成功,其他失败
  413. */
  414. int luat_mobile_get_service_cell_identifier(uint32_t *eci);
  415. /**
  416. * @brief 获取当前服务小区的TAC或LAC
  417. *
  418. * @param tac
  419. * @return int =0成功,其他失败
  420. */
  421. int luat_mobile_get_service_tac_or_lac(uint16_t *tac);
  422. /* --------------------------------------------------- cell info end --------------------------------------------------- */
  423. /* ------------------------------------------------ mobile status begin ----------------------------------------------- */
  424. /**
  425. * @brief 网络状态及相关功能状态发生更换的消息
  426. *
  427. */
  428. typedef enum LUAT_MOBILE_EVENT
  429. {
  430. LUAT_MOBILE_EVENT_CFUN = 0, /**< CFUN消息 */
  431. LUAT_MOBILE_EVENT_SIM, /**< SIM卡消息*/
  432. LUAT_MOBILE_EVENT_REGISTER_STATUS, /**< 移动网络注册消息*/
  433. LUAT_MOBILE_EVENT_CELL_INFO, /**< 小区基站信息和网络信号变更消息*/
  434. LUAT_MOBILE_EVENT_PDP, /**< PDP状态消息*/
  435. LUAT_MOBILE_EVENT_NETIF, /**< internet状态*/
  436. LUAT_MOBILE_EVENT_TIME_SYNC, /**< 通过基站同步时间完成*/
  437. LUAT_MOBILE_EVENT_CSCON, /**< RRC状态,0 idle 1 active*/
  438. LUAT_MOBILE_EVENT_BEARER,/**< PDP承载状态*/
  439. LUAT_MOBILE_EVENT_FATAL_ERROR,/**< 网络遇到严重故障*/
  440. }LUAT_MOBILE_EVENT_E;
  441. typedef enum LUAT_MOBILE_CFUN_STATUS
  442. {
  443. LUAT_MOBILE_CFUN_OFF = 0,
  444. LUAT_MOBILE_CFUN_ON,
  445. LUAT_MOBILE_CFUN_NO_RF = 4,
  446. }LUAT_MOBILE_CFUN_STATUS_E;
  447. typedef enum LUAT_MOBILE_SIM_STATUS
  448. {
  449. LUAT_MOBILE_SIM_READY = 0,
  450. LUAT_MOBILE_NO_SIM,
  451. LUAT_MOBILE_SIM_NEED_PIN,
  452. LUAT_MOBILE_SIM_ENTER_PIN_RESULT,
  453. LUAT_MOBILE_SIM_NUMBER,
  454. }LUAT_MOBILE_SIM_STATUS_E;
  455. typedef enum LUAT_MOBILE_REGISTER_STATUS
  456. {
  457. LUAT_MOBILE_STATUS_UNREGISTER, /**< 网络未注册*/
  458. LUAT_MOBILE_STATUS_REGISTERED, /**< 网络已注册*/
  459. LUAT_MOBILE_STATUS_SEARCHING, /**< 网络搜索中*/
  460. LUAT_MOBILE_STATUS_DENIED, /**< 网络注册被拒绝*/
  461. LUAT_MOBILE_STATUS_UNKNOW, /**< 网络状态未知*/
  462. LUAT_MOBILE_STATUS_REGISTERED_ROAMING, /**< 网络已注册,漫游*/
  463. LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED,
  464. LUAT_MOBILE_STATUS_SMS_ONLY_REGISTERED_ROAMING,
  465. LUAT_MOBILE_STATUS_EMERGENCY_REGISTERED,
  466. LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED,
  467. LUAT_MOBILE_STATUS_CSFB_NOT_PREFERRED_REGISTERED_ROAMING,
  468. }LUAT_MOBILE_REGISTER_STATUS_E;
  469. typedef enum LUAT_MOBILE_CELL_INFO_STATUS
  470. {
  471. LUAT_MOBILE_CELL_INFO_UPDATE = 0, /**< 小区基站信息变更,只有设置了周期性搜索小区基站时才会有*/
  472. LUAT_MOBILE_SIGNAL_UPDATE, /**< 网络信号状态变更,但是不一定是有变化*/
  473. }LUAT_MOBILE_CELL_INFO_STATUS_E;
  474. typedef enum LUAT_MOBILE_PDP_STATUS
  475. {
  476. LUAT_MOBILE_PDP_ACTIVED = 0,
  477. LUAT_MOBILE_PDP_DEACTIVING,
  478. LUAT_MOBILE_PDP_DEACTIVED,
  479. }LUAT_MOBILE_PDP_STATUS_E;
  480. typedef enum LUAT_MOBILE_NETIF_STATUS
  481. {
  482. LUAT_MOBILE_NETIF_LINK_ON = 0, /**< 已联网*/
  483. LUAT_MOBILE_NETIF_LINK_OFF, /**< 断网*/
  484. LUAT_MOBILE_NETIF_LINK_OOS, /**< 失去网络连接,尝试恢复中,等同于LUAT_MOBILE_NETIF_LINK_OFF*/
  485. }LUAT_MOBILE_NETIF_STATUS_E;
  486. typedef enum LUAT_MOBILE_BEARER_STATUS
  487. {
  488. LUAT_MOBILE_BEARER_GET_DEFAULT_APN = 0,/**< 获取到默认APN*/
  489. LUAT_MOBILE_BEARER_APN_SET_DONE,/**< 设置APN信息完成*/
  490. LUAT_MOBILE_BEARER_AUTH_SET_DONE,/**< 设置APN加密状态完成*/
  491. LUAT_MOBILE_BEARER_DEL_DONE,/**< 删除APN信息完成*/
  492. LUAT_MOBILE_BEARER_SET_ACT_STATE_DONE,/**< APN激活/去激活完成*/
  493. }LUAT_MOBILE_BEARER_STATUS_E;
  494. /**
  495. * @brief 获取当前移动网络注册状态
  496. *
  497. * @return 见@enum LUAT_MOBILE_REGISTER_STATUS_E
  498. */
  499. LUAT_MOBILE_REGISTER_STATUS_E luat_mobile_get_register_status(void);
  500. /**
  501. * @brief 网络状态及相关功能状态发生更换时的回调函数,event是消息,index是CID,SIM卡号之类的序号,status是变更后的状态或者更具体的ENUM
  502. *
  503. */
  504. typedef void (*luat_mobile_event_callback_t)(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status);
  505. /**
  506. * @brief 底层短信消息回调函数,event是消息,param是具体数据指针,暂时不同的平台需要独自处理
  507. *
  508. */
  509. typedef void (*luat_mobile_sms_event_callback_t)(uint32_t event, void *param);
  510. /**
  511. * @brief 注册网络状态及相关功能状态发生更换时的回调函数
  512. *
  513. * @param callback_fun 网络状态及相关功能状态发生更换时的回调函数
  514. * @return int =0成功,其他失败
  515. */
  516. int luat_mobile_event_register_handler(luat_mobile_event_callback_t callback_fun);
  517. /**
  518. * @brief 注销网络状态及相关功能状态发生更换时的回调函数
  519. *
  520. * @return int =0成功,其他失败
  521. */
  522. int luat_mobile_event_deregister_handler(void);
  523. /**
  524. * @brief 注册底层短信消息回调函数,后续改为统一消息处理
  525. *
  526. * @param callback_fun 短信消息回调函数,如果为NULL,则是注销
  527. * @return int =0成功,其他失败
  528. */
  529. int luat_mobile_sms_sdk_event_register_handler(luat_mobile_sms_event_callback_t callback_fun);
  530. /* ------------------------------------------------- mobile status end ------------------------------------------------ */
  531. /**
  532. * @brief 设置RRC自动释放时间,在RRC active(见LUAT_MOBILE_EVENT_CSCON)后经过一段时间在适当的时机释放RRC
  533. *
  534. * @param s 超时时间,单位秒,如果为0则是关闭功能
  535. * @note 没有在Air724上使用过AT*RTIME的,或者不明白RRC的含义,请不要使用RRC相关API
  536. */
  537. void luat_mobile_set_rrc_auto_release_time(uint8_t s);
  538. /**
  539. * @brief RRC自动释放暂停/恢复
  540. *
  541. * @param onoff 1暂停 0恢复
  542. * @note 没有在Air724上使用过AT*RTIME的,或者不明白RRC的含义,请不要使用RRC相关API
  543. */
  544. void luat_mobile_rrc_auto_release_pause(uint8_t onoff);
  545. /**
  546. * @brief RRC立刻释放一次,不能在luat_mobile_event_callback里使用
  547. * @note 没有在Air724上使用过AT*RTIME的,或者不明白RRC的含义,请不要使用RRC相关API
  548. */
  549. void luat_mobile_rrc_release_once(void);
  550. /**
  551. * @brief 重新底层网络协议栈,本质是快速的进出飞行模式,注意和设置飞行模式是冲突的,一定时间内只能用一个。
  552. *
  553. * @return int =0成功,其他失败
  554. */
  555. int luat_mobile_reset_stack(void);
  556. /**
  557. * @brief 遇到网络严重错误时允许自动重启协议栈
  558. * @param onoff 0关闭 其他开启
  559. * @return void
  560. */
  561. void luat_mobile_fatal_error_auto_reset_stack(uint8_t onoff);
  562. /**
  563. * @brief 设置周期性辅助工作,包括周期性搜索小区基站,SIM卡短时间脱离卡槽后周期性尝试恢复,这个功能和luat_mobile_reset_stack是有可能冲突的。所有功能默认都是关闭的
  564. *
  565. * @param get_cell_period 周期性搜索小区基站的时间间隔,单位ms,这个会增加低功耗,尽量的长,或者写0关闭这个功能,用上面的手段搜索
  566. * @param check_sim_period SIM卡短时间脱离卡槽后尝试恢复的时间间隔,单位ms,建议在5000~10000,或者写0,当SIM卡移除的消息上来后手动重启协议栈
  567. * @param search_cell_time 启动周期性搜索小区基站后,每次搜索的最大时间,单位s,1~8
  568. * @return int
  569. */
  570. int luat_mobile_set_period_work(uint32_t get_cell_period, uint32_t check_sim_period, uint8_t search_cell_time);
  571. /**
  572. * @brief 设置定时检测网络是否正常并且在检测到长时间无网时通过重启协议栈来恢复,但是不能保证一定成功,这个功能和luat_mobile_reset_stack是有可能冲突的。所有功能默认都是关闭的
  573. *
  574. * @param period 无网时长,单位ms,不可以太短,建议60000以上,为网络搜索网络保留足够的时间
  575. * @return void
  576. */
  577. void luat_mobile_set_check_network_period(uint32_t period);
  578. /**
  579. * @brief 获取累计的IP流量数据
  580. * @param uplink 上行流量
  581. * @param downlink 下行流量
  582. * @return 无
  583. */
  584. void luat_mobile_get_ip_data_traffic(uint64_t *uplink, uint64_t *downlink);
  585. /**
  586. * @brief 清除IP流量数据
  587. * @param clear_uplink 清除上行流量
  588. * @param clear_downlink 清除下行流量
  589. * @return 无
  590. */
  591. void luat_mobile_clear_ip_data_traffic(uint8_t clear_uplink, uint8_t clear_downlink);
  592. /**
  593. * @brief 获取模块能支持的频段
  594. * @param band 存放输出频段值的缓存,至少需要CMI_DEV_SUPPORT_MAX_BAND_NUM字节的空间
  595. * @param total_num 频段数量
  596. * @return 成功返回0,其他失败
  597. */
  598. int luat_mobile_get_support_band(uint8_t *band, uint8_t *total_num);
  599. /**
  600. * @brief 获取模块当前设置使用的频段
  601. * @param band 存放输出频段值的缓存,至少需要CMI_DEV_SUPPORT_MAX_BAND_NUM字节的空间
  602. * @param total_num 频段数量
  603. * @return 成功返回0,其他失败
  604. */
  605. int luat_mobile_get_band(uint8_t *band, uint8_t *total_num);
  606. /**
  607. * @brief 设置模块使用的频段
  608. * @param band 设置的频段,需要至少total_num数量的空间
  609. * @param total_num 频段数量
  610. * @return 成功返回0,其他失败
  611. */
  612. int luat_mobile_set_band(uint8_t *band, uint8_t total_num);
  613. /**
  614. * @brief LTE协议栈功能特殊配置
  615. * @param item 见MOBILE_CONF_XXX
  616. * @param value 配置值
  617. * @return 成功返回0,其他失败
  618. */
  619. int luat_mobile_config(uint8_t item, uint32_t value);
  620. /**
  621. * @brief RF测试模式
  622. * @param uart_id 测试结果输出的串口ID
  623. * @param on_off 进出测试模式,0退出 其他进入
  624. * @return 无
  625. */
  626. void luat_mobile_rf_test_mode(uint8_t uart_id, uint8_t on_off);
  627. /**
  628. * @brief RF测试的指令或者数据输入
  629. * @param data 数据,可以为空,只有为空的时候才会真正开始处理指令
  630. * @param data_len 数据长度,可以为0,只有为0的时候才会真正开始处理指令
  631. * @return 无
  632. */
  633. void luat_mobile_rf_test_input(char *data, uint32_t data_len);
  634. /** @}*/
  635. enum
  636. {
  637. MOBILE_CONF_RESELTOWEAKNCELL = 1,
  638. MOBILE_CONF_STATICCONFIG,
  639. MOBILE_CONF_QUALITYFIRST,
  640. MOBILE_CONF_USERDRXCYCLE,
  641. MOBILE_CONF_T3324MAXVALUE,
  642. MOBILE_CONF_PSM_MODE,
  643. MOBILE_CONF_CE_MODE,
  644. };
  645. #endif