TuyaOS
tuya_svc_lan.h
浏览该文件的文档.
1
11#ifndef __TUYA_SVC_LAN_H__
12#define __TUYA_SVC_LAN_H__
13
14#include <stdint.h>
15#include "tuya_cloud_types.h"
16#include "ty_cJSON.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22// LAN protocol frame type
23#define FRM_TP_CFG_WF 0x01 // only used for ap 3.0 network config
24#define FRM_TP_ACTV 0x02 // discard
25#define FRM_TP_BIND_DEV 0x03 // discard
26#define FRM_TP_UNBIND_DEV 0x06 // discard
27#define FRM_TP_CMD 0x07 //
28#define FRM_TP_STAT_REPORT 0x08 //
29#define FRM_TP_HB 0x09 //
30#define FRM_QUERY_STAT 0x0a //
31#define FRM_SSID_QUERY 0x0b // discard
32#define FRM_USER_BIND_REQ 0x0c // {"token","yyyyyyyyyyyyyy"}
33#define FRM_TP_NEW_CMD 0x0d //
34#define FRM_ADD_SUB_DEV_CMD 0x0e //
35#define FRM_CFG_WIFI_INFO 0x0f // {"ssid":"xxxx","passwd":"yyyyy"}
36#define FRM_QUERY_STAT_NEW 0x10 //
37#define FRM_SCENE_EXEC 0x11 //
38#define FRM_LAN_QUERY_DP 0x12 //
39
40#define FRM_SECURITY_TYPE3 0x03
41#define FRM_SECURITY_TYPE4 0x04
42#define FRM_SECURITY_TYPE5 0x05
43
44#define FR_TYPE_AP_ENCRYPTION 0x11
45#define FR_TYPE_ENCRYPTION 0x13
46#define FR_TYPE_BOARDCAST_LPV34 0x23
47#define FRM_AP_CFG_WF_V40 0x14
48
49#define FRM_AP_CFG_GET_DEV_INFO (0x16)
50#define FRM_AP_CFG_SET_DEV_SCHEMA (0x17)
51#define FRM_AP_CFG_SET_TIME (0x18)
52#define FRM_AP_CFG_SET_ACTIVE_INFO (0x19)
53#define FRM_LAN_OTA_START (0x1A)
54#define FRM_LAN_OTA_DATA (0x1B)
55#define FRM_LAN_OTA_FINISH (0x1C)
56#define FRM_LAN_RESET (0x1D)
57
58#define FRM_TYPE_REG_CENTER 0x24
59#define FRM_TYPE_APP_UDP_BOARDCAST 0x25
60
61#define WIFI_ERR_APP_TO_DEV 0x15 // aka WIFI_ERR_DEV_TO_APP
62#define FRM_LAN_EXT_STREAM 0x40
63#define FRM_LAN_EXT_BEFORE_ACTIVATE 0x42
64
65
66#pragma pack(1)
70typedef struct {
71 UINT_T head; // 0x55aa
72 uint8_t version;/*version:hight 4bit, reserved: low 4bit*/
73 uint8_t reserved;
74 UINT_T fr_num; // frame sequence number
75 UINT_T fr_type; // frame type
76 UINT_T len; // data length
77 BYTE_T data[0]; // the data
79
83typedef struct {
84 UINT_T crc; // CRC of data
85 UINT_T tail; // 0xaa55
87
91typedef struct {
92 UINT_T head; // 0x55aa
93 UINT_T fr_num; // frame sequence number
94 UINT_T fr_type; // frame type
95 UINT_T len; // data length
96 UINT_T ret_code;// return code
97 BYTE_T data[0]; // the data
99#pragma pack()
100
101#define LPV35_FRAME_HEAD_SIZE 4
102#define LPV35_FRAME_VERSION_SIZE 1
103#define LPV35_FRAME_RESERVE_SIZE 1
104#define LPV35_FRAME_SEQUENCE_SIZE 4
105#define LPV35_FRAME_TYPE_SIZE 4
106#define LPV35_FRAME_DATALEN_SIZE 4
107#define LPV35_FRAME_NONCE_SIZE 12
108#define LPV35_FRAME_TAG_SIZE 16
109#define LPV35_FRAME_TAIL_SIZE 4
110
111#define LPV35_FRAME_MINI_SIZE (LPV35_FRAME_HEAD_SIZE + LPV35_FRAME_VERSION_SIZE + LPV35_FRAME_RESERVE_SIZE + \
112 LPV35_FRAME_SEQUENCE_SIZE + LPV35_FRAME_TYPE_SIZE + LPV35_FRAME_DATALEN_SIZE + LPV35_FRAME_NONCE_SIZE + \
113 LPV35_FRAME_TAG_SIZE + LPV35_FRAME_TAIL_SIZE)
114#pragma pack(1)
115typedef struct {
116 uint8_t version: 4;
117 uint8_t reserved: 4;
118 uint8_t reserved2;
119 uint32_t sequence;
120 uint32_t type;
121 uint32_t length;
123
125
126typedef struct {
127 uint32_t ret_code;
128 uint8_t data[0];
130#pragma pack()
131
132typedef struct {
133 uint32_t sequence;
134 uint32_t type;
135 uint8_t* data;
136 uint32_t data_len;
138
142typedef enum {
143 CFG_UDP_DISCOVERY_FORCE, // send upd discovery even if clients exceed(BOOL_T)
144 CFG_UDP_EXT_UPDATE, // add/update new key/value(ty_cJSON)
145 CFG_UDP_EXT_DELETE, // delete key/value(ty_cJSON)
146 CFG_SET_CLT_NUM, // set clinet number(UINT_T)
147 CFG_UDP_DISCOVERY_INTERVAL, // set udp discovery interval(UINT_T, unit:s, default:5)
148 CFG_REV_BUF_SIZE, // receive buffer size(UINT, default:512)
149 CFG_SET_LAN_CLOSED_CB, // set lan can be closed
150 CFG_DEFAULT_LINKAGE, // default lan linkage (netmgr_linkage_t)
151 CFG_HEART_BEAT_TIMEOUT, // set heart beat time out(default 30)
152 CFG_DEBUG_SWITCH, // debug switch(BOOL_T)
153 CFG_SEQ_ERR_THRESHOLD, // sequence error threshold(default 0)
154 CFG_AP_NETCFG, // token bind use wifi
155 CFG_MAX
156} Lan_Cfg_e;
157
163OPERATE_RET tuya_svc_lan_init(VOID);
164
170OPERATE_RET tuya_svc_lan_exit(VOID);
171
177OPERATE_RET tuya_svc_lan_disable(VOID);
178
184OPERATE_RET tuya_svc_lan_enable(VOID);
185
194OPERATE_RET tuya_svc_lan_dp_report(IN VOID *data, IN CONST UINT_T len);
195
206OPERATE_RET tuya_svc_lan_data_report(IN CONST UINT_T fr_type, IN CONST UINT_T ret_code,
207 IN CONST BYTE_T *data, IN CONST UINT_T len);
208
215
222
231OPERATE_RET tuya_svc_lan_cfg(IN CONST Lan_Cfg_e cfg, IN CONST VOID * data);
232
241typedef OPERATE_RET(*lan_cmd_handler_cb)(IN CONST BYTE_T *data, OUT BYTE_T **out);
242
251OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler);
252
260OPERATE_RET tuya_svc_lan_unregister_cb(IN UINT_T frame_type);
261
272OPERATE_RET tuya_svc_lan_decrypt_data(IN BYTE_T *data, IN CONST INT_T len,
273 IN CONST BYTE_T *key, OUT CHAR_T **out_data);
274
281
289typedef OPERATE_RET(*lan_ext_protocol_handler_cb)(IN ty_cJSON *root_json);
290
299OPERATE_RET tuya_svc_lan_ext_proto_reg(CONST CHAR_T *ext_lan_pro, lan_ext_protocol_handler_cb handler);
300
308OPERATE_RET tuya_svc_lan_ext_proto_unreg(CONST CHAR_T *ext_lan_pro);
309
316
322OPERATE_RET tuya_svc_lan_ext_proto_data_report(IN CONST VOID *data, IN CONST UINT_T len);
323
329typedef BOOL_T(*lan_canbe_closed)(VOID);
330
337
338typedef struct {
339 INT_T socket;
340 UINT_T frame_num;
341 UINT_T frame_type;
342 UINT_T frame_len;
344
345OPERATE_RET tuya_svc_lan_pro_cntl_get_ext_cmd_param(LAN_EXT_CMD_PARAM_S *ext_cmd_param);
346
347OPERATE_RET tuya_svc_lan_data_com_send(IN CONST INT_T socket, IN CONST UINT_T fr_num, IN CONST UINT_T fr_type,
348 IN CONST UINT_T ret_code, IN CONST BYTE_T *data, IN CONST UINT_T len);
349
355#define is_lan_connected() (tuya_svc_lan_get_valid_connections() != 0)
356
357#ifdef __cplusplus
358}
359#endif
360#endif //__TUYA_SVC_LAN_H__
361
Definition: tuya_svc_lan.h:338
LAN protocol frame head format (from app)
Definition: tuya_svc_lan.h:70
LAN protocol frame head format (from device)
Definition: tuya_svc_lan.h:91
LAN protocol frame tail format (from device)
Definition: tuya_svc_lan.h:83
Definition: tuya_svc_lan.h:115
Definition: tuya_svc_lan.h:132
Definition: tuya_svc_lan.h:126
Definition: ty_cJSON.h:104
OPERATE_RET tuya_svc_lan_ext_proto_data_report(IN CONST VOID *data, IN CONST UINT_T len)
extend lan protocol data report
OPERATE_RET tuya_svc_lan_init(VOID)
Init and start LAN service
OPERATE_RET tuya_svc_lan_ext_proto_reg(CONST CHAR_T *ext_lan_pro, lan_ext_protocol_handler_cb handler)
Register extend lan protocol
UINT_T tuya_svc_lan_get_client_num(VOID)
get lan client number
OPERATE_RET tuya_svc_lan_data_report(IN CONST UINT_T fr_type, IN CONST UINT_T ret_code, IN CONST BYTE_T *data, IN CONST UINT_T len)
distribute data to all connections
OPERATE_RET tuya_svc_lan_decrypt_data(IN BYTE_T *data, IN CONST INT_T len, IN CONST BYTE_T *key, OUT CHAR_T **out_data)
Decrypt LAN data
OPERATE_RET tuya_svc_lan_cfg(IN CONST Lan_Cfg_e cfg, IN CONST VOID *data)
lan configure
OPERATE_RET tuya_svc_lan_dp_report(IN VOID *data, IN CONST UINT_T len)
LAN dp report
OPERATE_RET tuya_svc_lan_disable(VOID)
Disable LAN service
BOOL_T tuya_svc_lan_canbe_closed(VOID)
check lan can be closed
INT_T tuya_svc_lan_get_valid_connections(VOID)
get count of vaild connections
OPERATE_RET tuya_svc_lan_ext_proto_uninit(VOID)
uninit extend lan protocol
OPERATE_RET tuya_svc_lan_exit(VOID)
Stop and uninit LAN service
OPERATE_RET tuya_svc_lan_ext_proto_unreg(CONST CHAR_T *ext_lan_pro)
Unregister extend lan protocol
OPERATE_RET(* lan_ext_protocol_handler_cb)(IN ty_cJSON *root_json)
Callback to handle lan protocol data
Definition: tuya_svc_lan.h:289
OPERATE_RET tuya_svc_lan_enable(VOID)
Enable LAN service
OPERATE_RET tuya_svc_lan_disconnect_all(VOID)
disconnect all connections
OPERATE_RET(* lan_cmd_handler_cb)(IN CONST BYTE_T *data, OUT BYTE_T **out)
lan cmd extersion
Definition: tuya_svc_lan.h:241
Lan_Cfg_e
Definition of LAN configuration
Definition: tuya_svc_lan.h:142
OPERATE_RET tuya_svc_lan_unregister_cb(IN UINT_T frame_type)
unregister callback
BOOL_T(* lan_canbe_closed)(VOID)
check lan canbe closed
Definition: tuya_svc_lan.h:329
OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler)
register callback