packet

package
v0.0.0-...-8eec0ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assembler

type Assembler struct {
	// contains filtered or unexported fields
}

func NewAssemmbler

func NewAssemmbler(logger *slog.Logger) *Assembler

func (*Assembler) Assembled

func (a *Assembler) Assembled() <-chan []byte

func (*Assembler) Incoming

func (a *Assembler) Incoming() chan<- []byte

func (*Assembler) Stop

func (a *Assembler) Stop()

type CommandType

type CommandType uint16

CommandType represents a command in the Tuya BLE protocol

const (
	FUN_SENDER_DEVICE_INFO   CommandType = 0x0000
	FUN_SENDER_PAIR          CommandType = 0x0001
	FUN_SENDER_DPS           CommandType = 0x0002
	FUN_SENDER_DEVICE_STATUS CommandType = 0x0003

	FUN_RECEIVE_DP        CommandType = 0x8001
	FUN_RECEIVE_TIME1_REQ CommandType = 0x8011
	FUN_RECEIVE_TIME2_REQ CommandType = 0x8012
)

type Packet

type Packet struct {
	SeqNum       uint32
	ResponseTo   uint32
	CommandType  CommandType
	Payload      []byte
	SecurityFlag SecurityFlag
	IV           []byte
	Data         []byte // Encrypted data
}

Packet represents a Tuya BLE packet

func DecryptAndParsePacket

func DecryptAndParsePacket(data []byte, key []byte) (*Packet, error)

DecryptAndParsePacket decrypts and parses a packet from the given data

func NewPacket

func NewPacket(seqNum, responseTo uint32, commandType CommandType, payload []byte, securityFlag SecurityFlag) *Packet

NewPacket creates a new Packet instance

func (*Packet) BuildAndEncryptPacket

func (p *Packet) BuildAndEncryptPacket(key []byte) ([]byte, error)

BuildAndEncryptPacket constructs and encrypts a packet

type SecurityFlag

type SecurityFlag byte

SecurityFlag represents a security flag in the Tuya BLE protocol

const (
	SecurityFlagAuth    SecurityFlag = 0x01
	SecurityFlagLogin   SecurityFlag = 0x04
	SecurityFlagSession SecurityFlag = 0x05
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL