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
53typedef enum {
54 CFG_UDP_DISCOVERY_FORCE, // send upd discovery even if clients exceed(BOOL_T)
55 CFG_UDP_EXT_UPDATE, // add/update new key/value(ty_cJSON)
56 CFG_UDP_EXT_DELETE, // delete key/value(ty_cJSON)
57 CFG_SET_CLT_NUM, // set clinet number(UINT_T)
58 CFG_UDP_DISCOVERY_INTERVAL, // set udp discovery interval(UINT_T, unit:s, default:5)
59 CFG_REV_BUF_SIZE, // receive buffer size(UINT, default:512)
60 CFG_SET_LAN_CLOSED_CB, // set lan can be closed
61 CFG_DEFAULT_LINKAGE, // default lan linkage (netmgr_linkage_t)
62 CFG_HEART_BEAT_TIMEOUT, // set heart beat time out(default 30)
63 CFG_DEBUG_SWITCH, // debug switch(BOOL_T)
64 CFG_SEQ_ERR_THRESHOLD, // sequence error threshold(default 0)
65 CFG_WIFI_NETCFG, // token bind use wifi
66 CFG_MAX
67} Lan_Cfg_e;
68
74OPERATE_RET tuya_svc_lan_init(VOID);
75
81OPERATE_RET tuya_svc_lan_exit(VOID);
82
88OPERATE_RET tuya_svc_lan_disable(VOID);
89
95OPERATE_RET tuya_svc_lan_enable(VOID);
96
105OPERATE_RET tuya_svc_lan_dp_report(IN VOID *data, IN CONST UINT_T len);
106
117OPERATE_RET tuya_svc_lan_data_report(IN CONST UINT_T fr_type, IN CONST UINT_T ret_code,
118 IN CONST BYTE_T *data, IN CONST UINT_T len);
119
126
133
142OPERATE_RET tuya_svc_lan_cfg(IN CONST Lan_Cfg_e cfg, IN CONST VOID * data);
143
152typedef OPERATE_RET(*lan_cmd_handler_cb)(IN CONST BYTE_T *data, OUT BYTE_T **out);
153
162OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler);
163
171OPERATE_RET tuya_svc_lan_unregister_cb(IN UINT_T frame_type);
172
179
187typedef OPERATE_RET(*lan_ext_protocol_handler_cb)(IN ty_cJSON *root_json);
188
197OPERATE_RET tuya_svc_lan_ext_proto_reg(CONST CHAR_T *ext_lan_pro, lan_ext_protocol_handler_cb handler);
198
206OPERATE_RET tuya_svc_lan_ext_proto_unreg(CONST CHAR_T *ext_lan_pro);
207
214
220OPERATE_RET tuya_svc_lan_ext_proto_data_report(IN CONST VOID *data, IN CONST UINT_T len);
221
227typedef BOOL_T(*lan_canbe_closed)(VOID);
228
235
236typedef struct {
237 INT_T socket;
238 UINT_T frame_num;
239 UINT_T frame_type;
240 UINT_T frame_len;
242
243OPERATE_RET tuya_svc_lan_pro_cntl_get_ext_cmd_param(LAN_EXT_CMD_PARAM_S *ext_cmd_param);
244
245OPERATE_RET tuya_svc_lan_data_com_send(IN CONST INT_T socket, IN CONST UINT_T fr_num, IN CONST UINT_T fr_type,
246 IN CONST UINT_T ret_code, IN CONST BYTE_T *data, IN CONST UINT_T len);
247
253#define is_lan_connected() (tuya_svc_lan_get_valid_connections() != 0)
254
255#ifdef __cplusplus
256}
257#endif
258#endif //__TUYA_SVC_LAN_H__
259
Definition: tuya_svc_lan.h:236
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:187
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:152
Lan_Cfg_e
Definition of LAN configuration
Definition: tuya_svc_lan.h:53
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:227
OPERATE_RET tuya_svc_lan_register_cb(IN UINT_T frame_type, IN lan_cmd_handler_cb handler)
register callback