1 #ifndef _INFRA_COMPAT_H_
2 #define _INFRA_COMPAT_H_
3 
4 #include "linkkit/infra/infra_defs.h"
5 
6 #undef being_deprecated
7 #define being_deprecated
8 
9 typedef enum _IOT_LogLevel {
10     IOT_LOG_NONE = 0,
11     IOT_LOG_CRIT,
12     IOT_LOG_ERROR,
13     IOT_LOG_WARNING,
14     IOT_LOG_INFO,
15     IOT_LOG_DEBUG,
16 } IOT_LogLevel;
17 
18 void IOT_SetLogLevel(IOT_LogLevel level);
19 void IOT_DumpMemoryStats(IOT_LogLevel level);
20 
21 /**
22  * @brief event list used for iotx_regist_event_monitor_cb
23  */
24 enum iotx_event_t {
25     IOTX_AWSS_START =
26         0x1000, /* AWSS start without enbale, just supports device discover */
27     IOTX_AWSS_ENABLE,            /* AWSS enable */
28     IOTX_AWSS_LOCK_CHAN,         /* AWSS lock channel(Got AWSS sync packet) */
29     IOTX_AWSS_CS_ERR,            /* AWSS AWSS checksum is error */
30     IOTX_AWSS_PASSWD_ERR,        /* AWSS decrypt passwd error */
31     IOTX_AWSS_GOT_SSID_PASSWD,   /* AWSS parse ssid and passwd successfully */
32     IOTX_AWSS_CONNECT_ADHA,      /* AWSS try to connnect adha (device discover,
33                                     router solution) */
34     IOTX_AWSS_CONNECT_ADHA_FAIL, /* AWSS fails to connect adha */
35     IOTX_AWSS_CONNECT_AHA,       /* AWSS try to connect aha (AP solution) */
36     IOTX_AWSS_CONNECT_AHA_FAIL,  /* AWSS fails to connect aha */
37     IOTX_AWSS_SETUP_NOTIFY,   /* AWSS sends out device setup information (AP and
38                                  router solution) */
39     IOTX_AWSS_CONNECT_ROUTER, /* AWSS try to connect destination router */
40     IOTX_AWSS_CONNECT_ROUTER_FAIL, /* AWSS fails to connect destination router.
41                                     */
42     IOTX_AWSS_GOT_IP,      /* AWSS connects destination successfully and got ip
43                               address */
44     IOTX_AWSS_SUC_NOTIFY,  /* AWSS sends out success notify (AWSS sucess) */
45     IOTX_AWSS_BIND_NOTIFY, /* AWSS sends out bind notify information to support
46                               bind between user and device */
47     IOTX_AWSS_ENABLE_TIMEOUT, /* AWSS enable timeout(user needs to call
48                                  awss_config_press again to enable awss) */
49     IOTX_CONN_CLOUD = 0x2000, /* Device try to connect cloud */
50     IOTX_CONN_CLOUD_FAIL,     /* Device fails to connect cloud, refer to
51                                  net_sockets.h for error code */
52     IOTX_CONN_CLOUD_SUC,      /* Device connects cloud successfully */
53     IOTX_RESET = 0x3000, /* Linkkit reset success (just got reset response from
54                             cloud without any other operation) */
55 };
56 
57 /**
58  * @brief register callback to monitor all event from system.
59  *
60  * @param callback, when some event occurs, the system will trigger callback to
61  * user. refer to enum iotx_event_t for event list supported.
62  *
63  * @return 0 when success, -1 when fail.
64  * @note: user should make sure that callback is not block and runs to complete
65  * fast.
66  */
67 int iotx_event_regist_cb(void (*monitor_cb)(int event));
68 
69 /**
70  * @brief post event to trigger callback resitered by iotx_event_regist_cb
71  *
72  * @param event, event id, refer to iotx_event_t
73  *
74  * @return 0 when success, -1 when fail.
75  */
76 int iotx_event_post(int event);
77 
78 #ifndef VERSION_NUM_SIZE
79 #define VERSION_NUM_SIZE 4
80 #endif
81 
82 #ifndef RANDOM_NUM_SIZE
83 #define RANDOM_NUM_SIZE 4
84 #endif
85 
86 #ifndef MAC_ADDRESS_SIZE
87 #define MAC_ADDRESS_SIZE 8
88 #endif
89 
90 #ifndef CHIP_CODE_SIZE
91 #define CHIP_CODE_SIZE 4
92 #endif
93 
94 #define AOS_ACTIVE_INFO_LEN (81)
95 unsigned int aos_get_version_info(unsigned char version_num[VERSION_NUM_SIZE],
96                                   unsigned char random_num[RANDOM_NUM_SIZE],
97                                   unsigned char mac_address[MAC_ADDRESS_SIZE],
98                                   unsigned char chip_code[CHIP_CODE_SIZE],
99                                   unsigned char *output_buffer,
100                                   unsigned int output_buffer_size);
101 
102 typedef enum {
103     ITE_AWSS_STATUS,
104     ITE_CONNECT_SUCC,
105     ITE_CONNECT_FAIL,
106     ITE_DISCONNECTED,
107     ITE_RAWDATA_ARRIVED,
108     ITE_SERVICE_REQUEST,
109     ITE_SERVICE_REQUEST_EXT,
110     ITE_PROPERTY_SET,
111     ITE_PROPERTY_GET,
112 #ifdef DEVICE_MODEL_SHADOW
113     ITE_PROPERTY_DESIRED_GET_REPLY,
114 #endif
115     ITE_REPORT_REPLY,
116     ITE_TRIGGER_EVENT_REPLY,
117     ITE_TIMESTAMP_REPLY,
118     ITE_TOPOLIST_REPLY,
119     ITE_PERMIT_JOIN,
120     ITE_INITIALIZE_COMPLETED,
121     ITE_FOTA,
122     ITE_COTA,
123     ITE_MQTT_CONNECT_SUCC,
124     ITE_CLOUD_ERROR,
125 } iotx_ioctl_event_t;
126 
127 #define IOT_RegisterCallback(evt, cb)   iotx_register_for_##evt(cb)
128 #define DECLARE_EVENT_CALLBACK(evt, cb) int iotx_register_for_##evt(cb);
129 #define DEFINE_EVENT_CALLBACK(evt, cb)                                    \
130     int iotx_register_for_##evt(cb)                                       \
131     {                                                                     \
132         if (evt < 0 ||                                                    \
133             evt >= sizeof(g_impl_event_map) / sizeof(impl_event_map_t)) { \
134             return -1;                                                    \
135         }                                                                 \
136         g_impl_event_map[evt].callback = (void *)callback;                \
137         return 0;                                                         \
138     }
139 
140 DECLARE_EVENT_CALLBACK(ITE_AWSS_STATUS, int (*cb)(int))
141 DECLARE_EVENT_CALLBACK(ITE_CONNECT_SUCC, int (*cb)(void))
142 DECLARE_EVENT_CALLBACK(ITE_CONNECT_FAIL, int (*cb)(void))
143 DECLARE_EVENT_CALLBACK(ITE_DISCONNECTED, int (*cb)(void))
144 DECLARE_EVENT_CALLBACK(ITE_RAWDATA_ARRIVED,
145                        int (*cb)(const int, const unsigned char *, const int))
146 DECLARE_EVENT_CALLBACK(ITE_SERVICE_REQUEST,
147                        int (*cb)(const int, const char *, const int,
148                                  const char *, const int, char **, int *))
149 DECLARE_EVENT_CALLBACK(ITE_SERVICE_REQUEST_EXT,
150                        int (*cb)(int, const char *, int, const char *, int,
151                                  const char *, int, void *))
152 DECLARE_EVENT_CALLBACK(ITE_PROPERTY_SET,
153                        int (*cb)(const int, const char *, const int))
154 DECLARE_EVENT_CALLBACK(ITE_PROPERTY_DESIRED_GET_REPLY,
155                        int (*cb)(const char *, const int))
156 DECLARE_EVENT_CALLBACK(ITE_PROPERTY_GET, int (*cb)(const int, const char *,
157                                                    const int, char **, int *))
158 DECLARE_EVENT_CALLBACK(ITE_REPORT_REPLY,
159                        int (*cb)(const int, const int, const int, const char *,
160                                  const int))
161 DECLARE_EVENT_CALLBACK(ITE_TRIGGER_EVENT_REPLY,
162                        int (*cb)(const int, const int, const int, const char *,
163                                  const int, const char *, const int))
164 DECLARE_EVENT_CALLBACK(ITE_TIMESTAMP_REPLY, int (*cb)(const char *))
165 DECLARE_EVENT_CALLBACK(ITE_TOPOLIST_REPLY,
166                        int (*cb)(const int, const int, const int, const char *,
167                                  const int))
168 DECLARE_EVENT_CALLBACK(ITE_PERMIT_JOIN, int (*cb)(const char *, const int))
169 DECLARE_EVENT_CALLBACK(ITE_INITIALIZE_COMPLETED, int (*cb)(const int))
170 DECLARE_EVENT_CALLBACK(ITE_FOTA, int (*cb)(const int, const char *))
171 DECLARE_EVENT_CALLBACK(ITE_COTA,
172                        int (*cb)(const int, const char *, int, const char *,
173                                  const char *, const char *, const char *))
174 DECLARE_EVENT_CALLBACK(ITE_MQTT_CONNECT_SUCC, int (*cb)(void))
175 DECLARE_EVENT_CALLBACK(ITE_CLOUD_ERROR,
176                        int (*callback)(const int, const char *, const char *))
177 
178 void *iotx_event_callback(int evt);
179 
180 typedef struct {
181     uint16_t port;
182     uint8_t init;
183     char *host_name;
184     char *client_id;
185     char *username;
186     char *password;
187     const char *pub_key;
188 } iotx_conn_info_t, *iotx_conn_info_pt;
189 
190 int IOT_SetupConnInfo(const char *product_key, const char *device_name,
191                       const char *device_secret, void **info_ptr);
192 
193 typedef enum {
194     IOTX_IOCTL_SET_REGION,      /* value(int*): iotx_cloud_region_types_t */
195     IOTX_IOCTL_GET_REGION,      /* value(int*) */
196     IOTX_IOCTL_SET_MQTT_DOMAIN, /* value(const char*): point to mqtt domain
197                                    string */
198     IOTX_IOCTL_SET_HTTP_DOMAIN, /* value(const char*): point to http domain
199                                    string */
200     IOTX_IOCTL_SET_DYNAMIC_REGISTER, /* value(int*): 0 - Disable Dynamic
201                                         Register, 1 - Enable Dynamic Register */
202     IOTX_IOCTL_GET_DYNAMIC_REGISTER, /* value(int*) */
203     IOTX_IOCTL_RECV_PROP_REPLY,  /* value(int*): 0 - Disable property post reply
204                                     by cloud; 1 - Enable property post reply by
205                                     cloud */
206     IOTX_IOCTL_RECV_EVENT_REPLY, /* value(int*): 0 - Disable event post reply by
207                                     cloud; 1 - Enable event post reply by cloud
208                                   */
209     IOTX_IOCTL_SEND_PROP_SET_REPLY, /* value(int*): 0 - Disable send post set
210                                        reply by devid; 1 - Enable property set
211                                        reply by devid */
212     IOTX_IOCTL_SET_SUBDEV_SIGN,  /* value(const char*): only for slave device,
213                                     set signature of subdevice */
214     IOTX_IOCTL_GET_SUBDEV_LOGIN, /* value(int*): 0 - SubDev is logout; 1 -
215                                     SubDev is login */
216     IOTX_IOCTL_SET_OTA_DEV_ID,   /* value(int*):     select the device to do OTA
217                                     according to devid */
218     IOTX_IOCTL_FOTA_TIMEOUT_MS,  /* value(int*): set Firmware OTA max retry
219                                     timeout */
220     IOTX_IOCTL_SET_CUSTOMIZE_INFO, /* value(char*): set mqtt clientID customize
221                                       information */
222     IOTX_IOCTL_SET_MQTT_PORT,      /* value(uint16_t *) modify mqtt server port
223                                       number */
224     IOTX_IOCTL_SET_AWSS_ENABLE_INTERVAL, /* value(uint32_t*): - set an interval
225                                             during which wifi-provision is
226                                             enabled, unit is Ms*/
227     IOTX_IOCTL_SET_AWSS_CHANNEL_SCAN_INTERVAL, /* value(uint32_t*): - set an
228                                                   interval during which a
229                                                   channel is scanned, unit is
230                                                   Ms*/
231     IOTX_IOCTL_SET_PROXY_REGISTER, /* value(int*): 0 - Disable proxy product
232                                       register, 1 - Enable proxy product
233                                       register */
234     IOTX_IOCTL_QUERY_DEVID, /* value(iotx_dev_meta_info_t*): device meta info,
235                                only productKey and deviceName is required, ret
236                                value is subdev_id or -1 */
237     IOTX_IOCTL_SUB_USER_TOPIC, /* subscribe a topic according to user topic and
238                                   callback */
239 } iotx_ioctl_option_t;
240 
241 typedef enum {
242     IMPL_LINKKIT_IOCTL_SWITCH_PROPERTY_POST_REPLY, /* only for master device,
243                                                       choose whether you need
244                                                       receive property post
245                                                       reply message */
246     IMPL_LINKKIT_IOCTL_SWITCH_EVENT_POST_REPLY,    /* only for master device,
247                                                       choose whether you need
248                                                       receive event post reply
249                                                       message */
250     IMPL_LINKKIT_IOCTL_SWITCH_PROPERTY_SET_REPLY,  /* only for master device,
251                                                       choose whether you need
252                                                       send property set reply
253                                                       message */
254     IMPL_LINKKIT_IOCTL_MAX
255 } impl_linkkit_ioctl_cmd_t;
256 
257 /**
258  * @brief Setup Demain type, should be called before MQTT connection.
259  *
260  * @param [in] option: see iotx_ioctl_option_t.
261  *
262  * @return None.
263  * @see None.
264  */
265 int IOT_Ioctl(int option, void *data);
266 
267 #ifdef INFRA_MEM_STATS
268 #include "linkkit/infra/infra_mem_stats.h"
269 #endif
270 
271 /* compatible for V2.3.0 */
272 #define IOTX_CLOUD_DOMAIN_SH  IOTX_CLOUD_REGION_SHANGHAI
273 #define IOTX_CLOUD_DOMAIN_SG  IOTX_CLOUD_REGION_SINGAPORE
274 #define IOTX_CLOUD_DOMAIN_JP  IOTX_CLOUD_REGION_JAPAN
275 #define IOTX_CLOUD_DOMAIN_US  IOTX_CLOUD_REGION_USA_WEST
276 #define IOTX_CLOUD_DOMAIN_GER IOTX_CLOUD_REGION_GERMANY
277 #define IOTX_IOCTL_SET_DOMAIN IOTX_IOCTL_SET_REGION
278 #define IOTX_IOCTL_GET_DOMAIN IOTX_IOCTL_GET_REGION
279 
280 #define IOT_OpenLog(arg)
281 #define IOT_CloseLog()   IOT_SetLogLevel(IOT_LOG_NONE)
282 #define IOT_LOG_EMERG    IOT_LOG_NONE
283 
284 #define IOT_Linkkit_Post IOT_Linkkit_Report
285 /* compatible for V2.3.0 end */
286 
287 typedef enum {
288     HAL_AES_ENCRYPTION = 0,
289     HAL_AES_DECRYPTION = 1,
290 } AES_DIR_t;
291 
292 #define AES_DECRYPTION HAL_AES_DECRYPTION
293 #define AES_ENCRYPTION HAL_AES_ENCRYPTION
294 
295 typedef void *p_Aes128_t;
296 
297 #define NETWORK_ADDR_LEN (16)
298 
299 typedef struct _network_addr_t {
300     unsigned char addr[NETWORK_ADDR_LEN];
301     unsigned short port;
302 } NetworkAddr;
303 
304 #endif /* _INFRA_COMPAT_H_ */
305