Pegasus Pairing

Last Updated on : 2022-11-24 09:20:27download

This topic describes the APIs used to implement the functionality of Pegasus pairing.

Structs

TUYA_PEGASUS_CBS_S

typedef struct {
    TY_PEGASUS_EVENT_CB event_cb;
    TY_PEGASUS_SEND_FRAME_CB send_frame_cb;
    TY_PEGASUS_GET_SSID_PWD_CB get_ssid_pwd_cb;
    TY_PEGASUS_GET_MAC_CB get_mac_cb;
    TY_PEGASUS_SET_OUI_CB set_oui_cb;
} TUYA_PEGASUS_CBS_S;

Functional specification

Registers Pegasus pairing callbacks.

Member description

Member Description
event_cb For more information, see TY_PEGASUS_EVENT_CB.
send_frame_cb For more information, see TY_PEGASUS_SEND_FRAME_CB.
get_ssid_pwd_cb For more information, see TY_PEGASUS_GET_SSID_PWD_CB.
get_mac_cb For more information, see TY_PEGASUS_GET_MAC_CB.
set_oui_cb For more information, see TY_PEGASUS_SET_OUI_CB.

API reference

tuya_thing_config_init

OPERATE_RET tuya_thing_config_init(CONST CHAR_T *ifname, CONST TY_THING_CONFIG_GET_INFO_CB cb);

Functional description

Initializes the one-click pairing feature.

Parameter description

Parameter name Description
ifname Specify the network interface through which you send the packet for the one-click pairing, such as eth0.
cb Register the callback where users enter the SSID and password of the wireless network for use.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_thing_config_start

OPERATE_RET tuya_thing_config_start(UINT_T timeout);

Functional description

Enables the one-click pairing feature.

Parameter description

Parameter name Description
timeout The specified pairing timeout period, in seconds.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_thing_config_stop

OPERATE_RET tuya_thing_config_stop(VOID);

Functional description

Disables the one-click pairing feature.

Parameter description

Parameter name Description
VOID /

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

tuya_pegasus_svc_init

OPERATE_RET tuya_pegasus_svc_init(TUYA_PEGASUS_CBS_S *p_cbs, UINT_T probe_intr_ms);

Functional description

Initializes the Pegasus pairing feature and registers callbacks.

Parameter description

Parameter name Description
p_cbs The pointer to the Pegasus pairing callbacks.
get_probe_intr_ms The probe polling frequency.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

Callback functions

TY_PEGASUS_EVENT_CB

VOID (*TY_PEGASUS_EVENT_CB)(IN CONST TY_PEGASUS_EVENT_E event);

Functional description

Reports the Pegasus pairing events, such as a probe request from a device to be paired. This callback is registered by you.

To report the Tuya-specific organizationally unique identifier (OUI) probe request in the event of TY_PEGASUS_GET_PROBE_START, take the following considerations into account:

  • A device to be paired sends five probe requests consecutively every 250 milliseconds, with a timeout period of five seconds.

  • You can use the cyclic redundancy check (CRC) to detect the identical data and filter out the duplicate to report the unique data only.

  • You can report data in an asynchronous manner to reduce the energy used for request processing by the router. In this case, the data reporting API is blocked generally unless TY_PEGASUS_GET_PROBE_START is received and there is unique data to report.

Parameter description

Parameter name Description
event
  • TY_PEGASUS_START: Start Pegasus pairing.
  • TY_PEGASUS_STOP: Stop Pegasus pairing.
  • TY_PEGASUS_GET_PROBE_START: Report a probe request.
  • TY_PEGASUS_EVENT_INVALD: Invalid event.

Return value

Return value Description
VOID /

TY_PEGASUS_SEND_FRAME_CB

OPERATE_RET (*TY_PEGASUS_SEND_FRAME_CB)(IN CONST TY_FRAME_TYPE_E type,
						  IN CONST UINT8_T *vsie,
						  IN CONST UINT_T vsie_len,
                          IN NW_MAC_S *srcmac,
                          IN NW_MAC_S *dstmac);

Functional description

Sends the probe response and beacon packets. This callback is registered by you.

When the router sends probe response or beacon packets, you only need to implement the data forwarding and broadcasting without taking care of the specific data format.

Parameter description

Parameter name Description
type The types of frame:
  • TY_FRAME_TP_BEACON
  • TY_FRAME_TP_PROBE_REQ
  • TY_FRAME_TP_PROBE_RESP
vsie The memory address of VSIE.
vsie_len The length of VSIE.
srcmac The MAC address of the router.
dstmac The MAC address of the device to be paired.

Return value

Return value Description
VOID /

TY_PEGASUS_GET_SSID_PWD_CB

OPERATE_RET (*TY_PEGASUS_GET_SSID_PWD_CB)(OUT UINT8_T *ssid,
                                          IN INT_T slen,
                                          OUT UINT8_T *pwd,
                                          IN INT_T plen);

Functional description

Gets the SSID and password of the 2.4 GHz wireless network. This callback is registered by you.

Parameter description

Parameter name Description
ssid The SSID of the AP of the router.
slen The length of the SSID.
pwd The password of the AP of the router.
plen The length of the password.

Return value

Return value Description
OPRT_OK Operation succeeded.

TY_PEGASUS_GET_MAC_CB

OPERATE_RET (*TY_PEGASUS_GET_MAC_CB)(OUT NW_MAC_S *mac);

Functional description

Gets the MAC address of the access point (AP). This callback is registered by you.

Parameter description

Parameter name Description
mac The MAC address of the router.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.

TY_PEGASUS_SET_OUI_CB

OPERATE_RET (*TY_PEGASUS_SET_OUI_CB)(IN BYTE_T *oui, IN BYTE_T oui_len);

Functional description

Sets the Tuya-specific OUI. This callback is registered by you.

The Pegasus pairing feature only processes the probe request with the Tuya-specific OUI that includes 0x68, 0x57, and 0x2d.

Parameter description

Parameter name Description
oui The Tuya-specific OUI.
oui_len The length of the OUI.

Return value

Return value Description
OPRT_OK Operation succeeded.
Error code For more information about the error code, see tuya_error_code.h.