ql_api_aliotsmartcard.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Copyright (c) 2019 Alibaba Group. All rights reserved.
  3. * License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. * not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * Description:
  18. * aliyun_iot_smartcard_export.h: official export file
  19. *
  20. */
  21. #ifndef __ALIYUN_IOT_SMARTCARD_EXPORT_H__
  22. #define __ALIYUN_IOT_SMARTCARD_EXPORT_H__
  23. #include <stdint.h>
  24. #include <stdbool.h>
  25. typedef enum {
  26. POLICY_RSSI = 0,
  27. POLICY_DELAY,
  28. POLICY_MIX,
  29. POLICY_MAX
  30. } aliyun_iot_smartcard_policy_t;
  31. typedef enum {
  32. CARRIER_NULL = 0,
  33. CHINA_MOBILE = 1,
  34. CHINA_UNICOM,
  35. CHINA_TELECOM,
  36. CARRIER_UNKNOWN
  37. } aliyun_iot_smartcard_carrier_type_t;
  38. /* Do NOT modify */
  39. typedef enum {
  40. SIM_NULL = 0,
  41. SMARTCARD_SIM1 = 1, /* SMARTCARD_SIM1 means CHINA_MOBILE */
  42. SMARTCARD_SIM2, /* SMARTCARD_SIM2 means CHINA_UNICOM */
  43. SMARTCARD_SIM3, /* SMARTCARD_SIM3 means CHINA_TELECOM */
  44. SMARTCARD_SIMEXT /* SMARTCARD_SIMEXT means external slot sim */
  45. } aliyun_iot_smartcard_slot_num_t;
  46. typedef enum {
  47. ACT_NULL = 0,
  48. ACT_2G,
  49. ACT_3G,
  50. ACT_4G
  51. } aliyun_iot_smartcard_act_t;
  52. typedef struct {
  53. aliyun_iot_smartcard_slot_num_t slot_num; /**< slot type: SIM1 / SIM2 / SIM3 */
  54. char iccid[32 + 1]; /**< carrier iccid */
  55. char car_name[8 + 1]; /**< carrier name */
  56. aliyun_iot_smartcard_carrier_type_t car_type; /**< carrier type derived from iccid --> plmn*/
  57. bool active; /**< current carrier is active or not */
  58. aliyun_iot_smartcard_act_t act; /**< access technology selected */
  59. int32_t rssi; /**< rssi val */
  60. uint16_t delay; /**< delay in ms */
  61. uint8_t score; /**< score calculated by rssi and delay, lossrate */
  62. } aliyun_iot_smartcard_sim_t;
  63. /* smartcard error code definitions */
  64. #define MN_SUCCESS 0 /* success */
  65. #define MN_ERROR_GENERIC -1 /* generic error */
  66. #define MN_ERROR_INIT -2 /* init error */
  67. #define MN_ERROR_COMMON_PARAMETER -3 /* Invalid parameter */
  68. #define MN_ERROR_NO_SIM -4 /* no sim card detected */
  69. #define MN_ERROR_SAME_CARD -5 /* iccid is same after switch */
  70. #define MN_ERROR_TIMEOUT -6 /* timeout */
  71. #define MN_ERROR_NOT_SMARTCARD -7 /* not alibaba iot smart card */
  72. #define MN_ERROR_SERIAL -8 /* serial init error */
  73. #define MN_ERROR_CHECK -9 /* fail to parse alibaba iot smard card info */
  74. #define MN_ERROR_DIAL_UP_FAIL -10 /* dial up fail */
  75. #define MN_ERROR_REG_FAIL -11 /* network reg fail */
  76. #define MN_ERROR_SDK_ENABLE -12 /* SDK is disabled */
  77. #define MN_ERROR_SCAN -13 /* fail to scan carrier and select best carrier */
  78. #define MN_ERROR_SWITCHING -14 /* carrier switching is undergoing */
  79. #define MN_ERROR_CARRIER_DISABLED -15 /* carrier is disabled */
  80. #define MN_ERROR_PARSE_CONFIG -16 /* parse config file fail, default config is used */
  81. #define MN_ERROR_SCAN_DISABLED -17 /* scan is disabled */
  82. #define MN_ERROR_SWITCH_DISABLED -18 /* switch is disabled */
  83. #define MN_ERROR_MSWITCH_DISABLED -19 /* manu switch is disabled */
  84. /* value MUST be same as aliyun_iot_smartcard_slot_num_t(logic slot) */
  85. typedef enum {
  86. SWITCH_TO_SIM1 = 1, /* CHINA_MOBILE */
  87. SWITCH_TO_SIM2, /* CHINA_UNICOM */
  88. SWITCH_TO_SIM3, /* CHINA_TELECOM */
  89. SWITCH_TO_SIMEXT, /* switch to external sim */
  90. SWITCH_TO_NEXT, /* switch sequence: SIM1 -> SIM2 -> SIM3 -> SIM1 */
  91. SWITCH_MAX
  92. } aliyun_iot_smartcard_type_t;
  93. typedef enum {
  94. ALI_MN_STATE_NONE = 0,
  95. ALI_MN_STATE_IDLE,
  96. ALI_MN_STATE_INITING,
  97. ALI_MN_STATE_SWITCHING,
  98. ALI_MN_STATE_SCANNING,
  99. ALI_MN_STATE_CHECKING,
  100. ALI_MN_STATE_DATA_UPDATING,
  101. ALI_MN_STATE_DATA_SENDING,
  102. ALI_MN_STATE_MAX
  103. } ali_mn_state_et;
  104. typedef struct {
  105. int cnt;
  106. char ping_addr[3][256];
  107. } ali_mn_ping_addr_t;
  108. /*!
  109. * \brief aliyun smart card initialization
  110. *
  111. * \retval Possible returns are:
  112. * 0: init success
  113. * -1: init fail
  114. * -2: already inited
  115. * -3: parameter error
  116. * -4: sim card not detected
  117. * -6: timeout
  118. * -8: serial init error
  119. * -9: fail to parse smartcard info
  120. */
  121. int aliyun_iot_smartcard_init(void);
  122. /*!
  123. * \brief aliyun smart card deinitialization
  124. *
  125. * \retval Possible returns are:
  126. * 0: deinit success
  127. * -1: deinit fail
  128. * -2: not inited
  129. */
  130. int aliyun_iot_smartcard_deinit(void);
  131. /*!
  132. * \brief check if aliyun smart card or not
  133. *
  134. * \param [OUT] : support: true is smartcard, false is not smartcard
  135. *
  136. * \retval Possible returns are:
  137. * 0: success
  138. * -1: fail
  139. */
  140. int aliyun_iot_is_smartcard(bool *support);
  141. /*!
  142. * \brief start aliyun smart card monitor task
  143. *
  144. * \retval Possible returns are:
  145. * -1: fail to start task
  146. * -2: sdk not inited
  147. * -12: sdk is disabled
  148. * -18: smart switch is disabled
  149. * 0: success
  150. * \attention This function should be called after aliyun_iot_smartcard_init
  151. */
  152. int aliyun_iot_smartcard_start_monitor(void);
  153. /*!
  154. * \brief stop aliyun smart card monitor task
  155. *
  156. * \retval Possible returns are:
  157. * -1: fail to stop task
  158. * -12: sdk is disabled
  159. * -18: smart switch is disabled
  160. * 0: success
  161. * \attention This function should be called before aliyun_iot_smartcard_deinit
  162. */
  163. int aliyun_iot_smartcard_stop_monitor(void);
  164. /*!
  165. * \brief aliyun smart card scan carrier
  166. *
  167. * \retval Possible returns are:
  168. * -12: sdk is disabled
  169. * -13: scan fail
  170. * -14: carrier switching is undergoing
  171. * -17: scan is disabled
  172. * 0: success
  173. */
  174. int aliyun_iot_smartcard_scan_carrier(void);
  175. /*!
  176. * \brief switch to specified operator
  177. *
  178. * \param [IN] type: switch type
  179. *
  180. * \retval Possible returns are:
  181. * 0: switch success
  182. * -1: switch fail
  183. * -2: not inited
  184. * -3: parameter error
  185. * -5: iccid is same after switch
  186. * -6: timeout
  187. * -7: not alibaba iot smart card
  188. * -12: sdk is disabled
  189. * -14: carrier switching is undergoing
  190. * -19: manu switch is disabled
  191. */
  192. int aliyun_iot_smartcard_manual_switch(aliyun_iot_smartcard_type_t type);
  193. /*!
  194. * \brief parse json config file
  195. *
  196. * \param [IN] config file path
  197. *
  198. * \retval Possible returns are:
  199. * -1: fail to create default config
  200. * -16: parse config file fail, default config is used
  201. * 0: success
  202. */
  203. int aliyun_iot_smartcard_parse_configs(const char *config_file);
  204. /*!
  205. * \brief update json config file
  206. *
  207. * \retval Possible returns are:
  208. * -1: fail
  209. * 0: success
  210. */
  211. int aliyun_iot_smartcard_update_configs(void);
  212. /*!
  213. * \brief aliyun smart card get sdk version
  214. *
  215. * \param [OUT] major: major version
  216. * \param [OUT] minor: minor version
  217. *
  218. * \retval Possible returns are:
  219. * -3: parameter error
  220. * 0: success
  221. */
  222. int aliyun_iot_smartcard_get_version(int *major, int *minor);
  223. /*!
  224. * \brief get all sim status info
  225. *
  226. * \param [INOUT] slot_cnt as input param, it stores max sim card number sim_info can hold
  227. * As output param, it receives the actual sim card number this API returns
  228. * \param [OUT] sim_info sim_info array to hold the found sim card
  229. *
  230. * \retval Possible returns are:
  231. * -3: parameter error
  232. * 0: success
  233. */
  234. int aliyun_iot_smartcard_get_all_sim_info(uint8_t *slot_cnt, aliyun_iot_smartcard_sim_t *sim_info);
  235. /*!
  236. * \brief get aliyun smart card smart switch policy
  237. *
  238. * \param [IN] policy: pointer to policy val
  239. *
  240. * \retval Possible returns are:
  241. * -3: parameter error
  242. * 0: success
  243. */
  244. int aliyun_iot_smartcard_get_switch_policy(aliyun_iot_smartcard_policy_t *policy);
  245. /*!
  246. * \brief set aliyun smart card smart switch policy
  247. *
  248. * \param [IN] policy: policy val
  249. *
  250. * \retval Possible returns are:
  251. * -3: parameter error
  252. * 0: success
  253. */
  254. int aliyun_iot_smartcard_set_switch_policy(aliyun_iot_smartcard_policy_t policy);
  255. /*!
  256. * \brief get rssi threshold
  257. *
  258. * \param [OUT] rssi: current rssi
  259. *
  260. * \retval Possible returns are:
  261. * -3: parameter error
  262. * 0: success
  263. * \attention This function only used for smart switch
  264. */
  265. int aliyun_iot_smartcard_get_rssi_threshold(int32_t *rssi);
  266. /*!
  267. * \brief set rssi threshold
  268. *
  269. * \param [IN] rssi: rssi to be set
  270. *
  271. * \retval Possible returns are:
  272. * 0: success
  273. * \attention This function only used for smart switch
  274. */
  275. int aliyun_iot_smartcard_set_rssi_threshold(int32_t rssi);
  276. /*!
  277. * \brief get delay threshold
  278. *
  279. * \param [OUT] delay: current delay
  280. *
  281. * \retval Possible returns are:
  282. * -3: parameter error
  283. * 0: success
  284. *
  285. * \attention This function only used for smart switch
  286. */
  287. int aliyun_iot_smartcard_get_delay_threshold(uint16_t *delay);
  288. /*!
  289. * \brief set delay threshold
  290. *
  291. * \param [IN] delay: delay to be set
  292. *
  293. * \retval Possible returns are:
  294. * 0: success
  295. *
  296. * \attention This function only used for smart switch
  297. */
  298. int aliyun_iot_smartcard_set_delay_threshold(uint16_t delay);
  299. /*!
  300. * \brief get check cycle
  301. *
  302. * \param [OUT] cycle: current check cycle
  303. *
  304. * \retval Possible returns are:
  305. * -3: parameter error
  306. * 0: success
  307. * \attention This function only used for smart switch
  308. */
  309. int aliyun_iot_smartcard_get_check_cycle(uint32_t *cycle);
  310. /*!
  311. * \brief set check cycle
  312. *
  313. * \param [IN] cycle: check cycle to be set
  314. *
  315. * \retval Possible returns are:
  316. * -3: parameter error
  317. * 0: success
  318. * \attention This function only used for smart switch
  319. */
  320. int aliyun_iot_smartcard_set_check_cycle(uint32_t cycle);
  321. /*!
  322. * \brief get ping web site
  323. *
  324. * \retval pointer to web
  325. */
  326. const char *aliyun_iot_smartcard_get_ping_addr(void);
  327. /*!
  328. * \brief get ping web site parse result
  329. *
  330. * \retval pointer to ali_mn_ping_addr_t
  331. */
  332. const ali_mn_ping_addr_t *aliyun_iot_smartcard_get_ping_addr_info(void);
  333. /*!
  334. * \brief set ping addr
  335. *
  336. * \param [IN] addr: ping addr to be set
  337. *
  338. * \retval Possible returns are:
  339. * -3: parameter error
  340. * -1: parse error
  341. * 0: success
  342. */
  343. int aliyun_iot_smartcard_set_ping_addr(const char *addr);
  344. /*!
  345. * \brief get disabled carrier string
  346. *
  347. * \retval pointer to disabled carrier string
  348. */
  349. const char *aliyun_iot_smartcard_get_disable_carrier(void);
  350. /*!
  351. * \brief set carrier to be disabled forcely
  352. *
  353. * \param [IN] carrier: carrier to be set
  354. *
  355. * \retval Possible returns are:
  356. * -3: parameter error
  357. * 0: success
  358. */
  359. int aliyun_iot_smartcard_set_disable_carrier(const char *carrier);
  360. /*!
  361. * \brief get sdk enabled or not
  362. *
  363. * \param [OUT] enable
  364. *
  365. * \retval Possible returns are:
  366. * -3: parameter error
  367. * 0: success
  368. */
  369. int aliyun_iot_smartcard_get_enable(bool *enable);
  370. /*!
  371. * \brief set sdk enabled or not
  372. *
  373. * \param [IN] enable: enable or disable sdk support
  374. *
  375. * \retval Possible returns are:
  376. * 0: success
  377. */
  378. int aliyun_iot_smartcard_set_enable(bool enable);
  379. /*!
  380. * \brief get carrier scanning flag
  381. *
  382. * \param [OUT] enable
  383. *
  384. * \retval Possible returns are:
  385. * -3: parameter error
  386. * 0: success
  387. */
  388. int aliyun_iot_smartcard_get_scan_flag(bool *enable);
  389. /*!
  390. * \brief set carrier scanning flag
  391. *
  392. * \param [IN] enable: enable or disable scanning
  393. *
  394. * \retval Possible returns are:
  395. * 0: success
  396. */
  397. int aliyun_iot_smartcard_set_scan_flag(bool enable);
  398. /*!
  399. * \brief get smart switch flag
  400. *
  401. * \param [OUT] enable
  402. *
  403. * \retval Possible returns are:
  404. * -3: parameter error
  405. * 0: success
  406. */
  407. int aliyun_iot_smartcard_get_switch_flag(bool *enable);
  408. /*!
  409. * \brief set smart switch flag
  410. *
  411. * \param [IN] enable: enable or disable auto-switch
  412. *
  413. * \retval Possible returns are:
  414. * 0: success
  415. */
  416. int aliyun_iot_smartcard_set_switch_flag(bool enable);
  417. /*!
  418. * \brief get carrier manu switch flag
  419. *
  420. * \param [OUT] enable
  421. *
  422. * \retval Possible returns are:
  423. * -3: parameter error
  424. * 0: success
  425. */
  426. int aliyun_iot_smartcard_get_manu_switch_flag(bool *enable);
  427. /*!
  428. * \brief set carrier manu switch flag
  429. *
  430. * \param [IN] enable: enable or disable manu switch
  431. *
  432. * \retval Possible returns are:
  433. * 0: success
  434. */
  435. int aliyun_iot_smartcard_set_manu_switch_flag(bool enable);
  436. /*!
  437. * \brief get check retry cnt
  438. *
  439. * \param [OUT] cnt
  440. *
  441. * \retval Possible returns are:
  442. * -3: parameter error
  443. * 0: success
  444. */
  445. int aliyun_iot_smartcard_get_check_retry_cnt(uint32_t *cnt);
  446. /*!
  447. * \brief set check retry cnt
  448. *
  449. * \param [IN] cnt: retry cnt
  450. *
  451. * \retval Possible returns are:
  452. * 0: success
  453. */
  454. int aliyun_iot_smartcard_set_check_retry_cnt(uint32_t cnt);
  455. /*!
  456. * \brief get ping cnt
  457. *
  458. * \param [OUT] cnt
  459. *
  460. * \retval Possible returns are:
  461. * -3: parameter error
  462. * 0: success
  463. */
  464. int aliyun_iot_smartcard_get_ping_cnt(uint32_t *cnt);
  465. /*!
  466. * \brief set ping cnt
  467. *
  468. * \param [IN] cnt: ping cnt
  469. *
  470. * \retval Possible returns are:
  471. * -3: parameter error
  472. * 0: success
  473. */
  474. int aliyun_iot_smartcard_set_ping_cnt(uint32_t cnt);
  475. /*!
  476. * \brief get silent time
  477. *
  478. * \param [OUT] sec
  479. *
  480. * \retval Possible returns are:
  481. * -3: parameter error
  482. * 0: success
  483. */
  484. int aliyun_iot_smartcard_get_silent_time(uint16_t *sec);
  485. /*!
  486. * \brief set silent time
  487. *
  488. * \param [IN] sec: silent time
  489. *
  490. * \retval Possible returns are:
  491. * 0: success
  492. */
  493. int aliyun_iot_smartcard_set_silent_time(uint16_t sec);
  494. /*!
  495. * \brief get conf file
  496. *
  497. * \retval pointer to conf file
  498. */
  499. const char *aliyun_iot_smartcard_get_conf_file(void);
  500. /*!
  501. * \brief set conf file
  502. *
  503. * \param [IN] conf_file
  504. *
  505. * \retval Possible returns are:
  506. * -3: parameter error
  507. * 0: success
  508. */
  509. int aliyun_iot_smartcard_set_conf_file(const char *conf_file);
  510. /*!
  511. * \brief get aliyun smart card sdk current state
  512. *
  513. * \param [OUT] state
  514. *
  515. * \retval Possible returns are:
  516. * -3: parameter error
  517. * 0: success
  518. */
  519. int aliyun_iot_smartcard_get_state(ali_mn_state_et *state);
  520. /*!
  521. * \brief get current selected card slot number
  522. *
  523. * \param [OUT] slot_num: current card slot number, 1 is SIM1, 2 is SIM2, 3 is SIM3, 4 is SIMEXT
  524. *
  525. * \retval Possible returns are:
  526. * -1: fail
  527. * -3: parameter error
  528. * 0: success
  529. */
  530. int aliyun_iot_smartcard_get_card_slot(aliyun_iot_smartcard_slot_num_t *slot_num);
  531. /**
  532. * \brief get aliiccid by reading pbk directly
  533. *
  534. * \param [out] aliiccid: pointer to aliiccid str
  535. * \param [in] len: aliiccid str len
  536. *
  537. * \retval Possible returns are:
  538. * -1: fail
  539. * -3: parameter error
  540. * 0: success
  541. *
  542. * \attention This function can be called before aliyun_iot_smartcard_init
  543. */
  544. int aliyun_iot_smartcard_get_aliiccid(char *iccid, uint8_t len);
  545. /**
  546. * \brief get cached aliiccid without reading pbk
  547. *
  548. * \param [out] aliiccid: pointer to aliiccid str
  549. * \param [in] len: aliiccid str len
  550. *
  551. * \retval Possible returns are:
  552. * -1: fail
  553. * -3: parameter error
  554. * 0: success
  555. *
  556. * \attention This function should be called after aliyun_iot_smartcard_init
  557. */
  558. int aliyun_iot_smartcard_get_cached_aliiccid(char *iccid, uint8_t len);
  559. /*!
  560. * \brief get if average value checking is supported or not
  561. *
  562. * \param [OUT] enable: if enabled, support average value checking
  563. *
  564. * \retval Possible returns are:
  565. * -3: parameter error
  566. * 0: success
  567. */
  568. int aliyun_iot_smartcard_get_average_check_flag(bool *enable);
  569. /*!
  570. * \brief set average value checking support flag
  571. *
  572. * \param [IN] enable: enable or disable flag
  573. *
  574. * \retval Possible returns are:
  575. * 0: success
  576. */
  577. int aliyun_iot_smartcard_set_average_check_flag(bool enable);
  578. /*!
  579. * \brief smart card wait pbk initialization
  580. *
  581. * \param [IN] timeout: wait timeout, uint ms
  582. *
  583. * \retval Possible returns are:
  584. * 0: success
  585. */
  586. int aliyun_iot_smartcard_hal_pbk_wait(uint32 timeout);
  587. #endif /* __ALIYUN_IOT_SMARTCARD_EXPORT_H__ */