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 FRM_TYPE_REG_CENTER 0x24
45#define FRM_TYPE_APP_UDP_BOARDCAST 0x25
46
47#define FRM_LAN_EXT_STREAM 0x40
48#define FRM_LAN_EXT_BEFORE_ACTIVATE 0x42
49#define FRM_LAN_UPD_LOG 0x30
50
54typedef enum {
55 CFG_UDP_DISCOVERY_FORCE, // send upd discovery even if clients exceed(BOOL_T)
56 CFG_UDP_EXT_UPDATE, // add/update new key/value(ty_cJSON)
57 CFG_UDP_EXT_DELETE, // delete key/value(ty_cJSON)
58 CFG_SET_CLT_NUM, // set clinet number(UINT_T)
59 CFG_UDP_DISCOVERY_INTERVAL, // set udp discovery interval(UINT_T, unit:s, default:5)
60 CFG_REV_BUF_SIZE, // receive buffer size(UINT, default:512)
61 CFG_SET_LAN_CLOSED_CB, // set lan can be closed
62 CFG_DEFAULT_LINKAGE, // default lan linkage (netmgr_linkage_t)
63 CFG_HEART_BEAT_TIMEOUT, // set heart beat time out(default 30)
64 CFG_DEBUG_SWITCH, // debug switch(BOOL_T)
65 CFG_SEQ_ERR_THRESHOLD, // sequence error threshold(default 0)
66 CFG_WIFI_NETCFG, // token bind use wifi
67 CFG_MAX
68} Lan_Cfg_e;
69
75OPERATE_RET tuya_svc_lan_init(VOID);
76
82OPERATE_RET tuya_svc_lan_exit(VOID);
83
89OPERATE_RET tuya_svc_lan_disable(VOID);
90
96OPERATE_RET tuya_svc_lan_enable(VOID);
97
106OPERATE_RET tuya_svc_lan_dp_report(IN VOID *data, IN CONST UINT_T len);
107
118OPERATE_RET tuya_svc_lan_data_report(IN CONST UINT_T fr_type, IN CONST UINT_T ret_code,
119 IN CONST BYTE_T *data, IN CONST UINT_T len);
120
127
134
143OPERATE_RET tuya_svc_lan_cfg(IN CONST Lan_Cfg_e cfg, IN CONST VOID * data);
144
153typedef OPERATE_RET(*lan_cmd_handler_cb)(IN CONST BYTE_T *data, OUT BYTE_T **out);
154
163OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler);
164
172OPERATE_RET tuya_svc_lan_unregister_cb(IN UINT_T frame_type);
173
180
188typedef OPERATE_RET(*lan_ext_protocol_handler_cb)(IN ty_cJSON *root_json);
189
198OPERATE_RET tuya_svc_lan_ext_proto_reg(CONST CHAR_T *ext_lan_pro, lan_ext_protocol_handler_cb handler);
199
207OPERATE_RET tuya_svc_lan_ext_proto_unreg(CONST CHAR_T *ext_lan_pro);
208
215
221OPERATE_RET tuya_svc_lan_ext_proto_data_report(IN CONST VOID *data, IN CONST UINT_T len);
222
228typedef BOOL_T(*lan_canbe_closed)(VOID);
229
236
237typedef struct {
238 INT_T socket;
239 UINT_T frame_num;
240 UINT_T frame_type;
241 UINT_T frame_len;
243
244OPERATE_RET tuya_svc_lan_pro_cntl_get_ext_cmd_param(LAN_EXT_CMD_PARAM_S *ext_cmd_param);
245
246OPERATE_RET tuya_svc_lan_data_com_send(IN CONST INT_T socket, IN CONST UINT_T fr_num, IN CONST UINT_T fr_type,
247 IN CONST UINT_T ret_code, IN CONST BYTE_T *data, IN CONST UINT_T len);
248
254#define is_lan_connected() (tuya_svc_lan_get_valid_connections() != 0)
255
256#ifdef __cplusplus
257}
258#endif
259#endif //__TUYA_SVC_LAN_H__
260
Definition: tuya_svc_lan.h:237
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_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:188
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:153
Lan_Cfg_e
Definition of LAN configuration
Definition: tuya_svc_lan.h:54
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:228
OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler)
register callback