ESPHome 2025.6.3
Loading...
Searching...
No Matches
esphome::api::APINoiseFrameHelper Class Reference

#include <api_frame_helper.h>

Inheritance diagram for esphome::api::APINoiseFrameHelper:
esphome::api::APIFrameHelper

Public Member Functions

 APINoiseFrameHelper (std::unique_ptr< socket::Socket > socket, std::shared_ptr< APINoiseContext > ctx)
 
 ~APINoiseFrameHelper () override
 
APIError init () override
 Initialize the frame helper, returns OK if successful.
 
APIError loop () override
 Run through handshake messages (if in that phase)
 
APIError read_packet (ReadPacketBuffer *buffer) override
 
APIError write_protobuf_packet (uint16_t type, ProtoWriteBuffer buffer) override
 
APIError write_protobuf_packets (ProtoWriteBuffer buffer, const std::vector< PacketInfo > &packets) override
 
uint8_t frame_header_padding () override
 
uint8_t frame_footer_size () override
 
- Public Member Functions inherited from esphome::api::APIFrameHelper
 APIFrameHelper ()=default
 
 APIFrameHelper (std::unique_ptr< socket::Socket > socket)
 
virtual ~APIFrameHelper ()=default
 
bool can_write_without_blocking ()
 
std::string getpeername ()
 
int getpeername (struct sockaddr *addr, socklen_t *addrlen)
 
APIError close ()
 
APIError shutdown (int how)
 
void set_log_info (std::string info)
 
bool is_socket_ready () const
 

Protected Member Functions

APIError state_action_ ()
 To be called from read/write methods.
 
APIError try_read_frame_ (ParsedFrame *frame)
 Read a packet into the rx_buf_.
 
APIError write_frame_ (const uint8_t *data, uint16_t len)
 
APIError init_handshake_ ()
 Initiate the data structures for the handshake.
 
APIError check_handshake_finished_ ()
 
void send_explicit_handshake_reject_ (const std::string &reason)
 
- Protected Member Functions inherited from esphome::api::APIFrameHelper
APIError write_raw_ (const struct iovec *iov, int iovcnt)
 
APIError try_send_tx_buf_ ()
 
void buffer_data_from_iov_ (const struct iovec *iov, int iovcnt, uint16_t total_write_len)
 
template<typename StateEnum >
APIError write_raw_ (const struct iovec *iov, int iovcnt, socket::Socket *socket, std::vector< uint8_t > &tx_buf, const std::string &info, StateEnum &state, StateEnum failed_state)
 
APIError init_common_ ()
 

Protected Attributes

uint8_t rx_header_buf_ [3]
 
uint8_t rx_header_buf_len_ = 0
 
std::vector< uint8_t > prologue_
 
std::shared_ptr< APINoiseContextctx_
 
NoiseHandshakeState * handshake_ {nullptr}
 
NoiseCipherState * send_cipher_ {nullptr}
 
NoiseCipherState * recv_cipher_ {nullptr}
 
NoiseProtocolId nid_
 
- Protected Attributes inherited from esphome::api::APIFrameHelper
std::deque< SendBuffertx_buf_
 
State state_ {State::INITIALIZE}
 
std::string info_
 
socket::Socketsocket_ {nullptr}
 
std::unique_ptr< socket::Socketsocket_owned_
 
uint8_t frame_header_padding_ {0}
 
uint8_t frame_footer_size_ {0}
 
std::vector< struct iovecreusable_iovs_
 
std::vector< uint8_t > rx_buf_
 
uint16_t rx_buf_len_ = 0
 

Additional Inherited Members

- Protected Types inherited from esphome::api::APIFrameHelper
enum class  State {
  INITIALIZE = 1 , CLIENT_HELLO = 2 , SERVER_HELLO = 3 , HANDSHAKE = 4 ,
  DATA = 5 , CLOSED = 6 , FAILED = 7 , EXPLICIT_REJECT = 8
}
 

Detailed Description

Definition at line 187 of file api_frame_helper.h.

Constructor & Destructor Documentation

◆ APINoiseFrameHelper()

esphome::api::APINoiseFrameHelper::APINoiseFrameHelper ( std::unique_ptr< socket::Socket > socket,
std::shared_ptr< APINoiseContext > ctx )
inline

Definition at line 189 of file api_frame_helper.h.

◆ ~APINoiseFrameHelper()

esphome::api::APINoiseFrameHelper::~APINoiseFrameHelper ( )
override

Definition at line 786 of file api_frame_helper.cpp.

Member Function Documentation

◆ check_handshake_finished_()

APIError esphome::api::APINoiseFrameHelper::check_handshake_finished_ ( )
protected

Definition at line 759 of file api_frame_helper.cpp.

◆ frame_footer_size()

uint8_t esphome::api::APINoiseFrameHelper::frame_footer_size ( )
inlineoverridevirtual

Implements esphome::api::APIFrameHelper.

Definition at line 207 of file api_frame_helper.h.

◆ frame_header_padding()

uint8_t esphome::api::APINoiseFrameHelper::frame_header_padding ( )
inlineoverridevirtual

Implements esphome::api::APIFrameHelper.

Definition at line 205 of file api_frame_helper.h.

◆ init()

APIError esphome::api::APINoiseFrameHelper::init ( )
overridevirtual

Initialize the frame helper, returns OK if successful.

Implements esphome::api::APIFrameHelper.

Definition at line 263 of file api_frame_helper.cpp.

◆ init_handshake_()

APIError esphome::api::APINoiseFrameHelper::init_handshake_ ( )
protected

Initiate the data structures for the handshake.

Returns
0 on success, -1 on error (check errno)

Definition at line 713 of file api_frame_helper.cpp.

◆ loop()

APIError esphome::api::APINoiseFrameHelper::loop ( )
overridevirtual

Run through handshake messages (if in that phase)

Implements esphome::api::APIFrameHelper.

Definition at line 276 of file api_frame_helper.cpp.

◆ read_packet()

APIError esphome::api::APINoiseFrameHelper::read_packet ( ReadPacketBuffer * buffer)
overridevirtual

Implements esphome::api::APIFrameHelper.

Definition at line 554 of file api_frame_helper.cpp.

◆ send_explicit_handshake_reject_()

void esphome::api::APINoiseFrameHelper::send_explicit_handshake_reject_ ( const std::string & reason)
protected

Definition at line 538 of file api_frame_helper.cpp.

◆ state_action_()

APIError esphome::api::APINoiseFrameHelper::state_action_ ( )
protected

To be called from read/write methods.

This method runs through the internal handshake methods, if in that state.

If the handshake is still active when this method returns and a read/write can't take place at the moment, returns WOULD_BLOCK. If an error occurred, returns that error. Only returns OK if the transport is ready for data traffic.

Definition at line 402 of file api_frame_helper.cpp.

◆ try_read_frame_()

APIError esphome::api::APINoiseFrameHelper::try_read_frame_ ( ParsedFrame * frame)
protected

Read a packet into the rx_buf_.

If successful, stores frame data in the frame parameter

Parameters
frameThe struct to hold the frame information in. msg_start: points to the start of the payload - this pointer is only valid until the next try_receive_raw_ call
Returns
0 if a full packet is in rx_buf_
-1 if error, check errno.

errno EWOULDBLOCK: Packet could not be read without blocking. Try again later. errno ENOMEM: Not enough memory for reading packet. errno API_ERROR_BAD_INDICATOR: Bad indicator byte at start of frame. errno API_ERROR_HANDSHAKE_PACKET_LEN: Packet too big for this phase.

Definition at line 304 of file api_frame_helper.cpp.

◆ write_frame_()

APIError esphome::api::APINoiseFrameHelper::write_frame_ ( const uint8_t * data,
uint16_t len )
protected

Definition at line 691 of file api_frame_helper.cpp.

◆ write_protobuf_packet()

APIError esphome::api::APINoiseFrameHelper::write_protobuf_packet ( uint16_t type,
ProtoWriteBuffer buffer )
overridevirtual

Implements esphome::api::APIFrameHelper.

Definition at line 607 of file api_frame_helper.cpp.

◆ write_protobuf_packets()

APIError esphome::api::APINoiseFrameHelper::write_protobuf_packets ( ProtoWriteBuffer buffer,
const std::vector< PacketInfo > & packets )
overridevirtual

Implements esphome::api::APIFrameHelper.

Definition at line 621 of file api_frame_helper.cpp.

Field Documentation

◆ ctx_

std::shared_ptr<APINoiseContext> esphome::api::APINoiseFrameHelper::ctx_
protected

Definition at line 224 of file api_frame_helper.h.

◆ handshake_

NoiseHandshakeState* esphome::api::APINoiseFrameHelper::handshake_ {nullptr}
protected

Definition at line 225 of file api_frame_helper.h.

◆ nid_

NoiseProtocolId esphome::api::APINoiseFrameHelper::nid_
protected

Definition at line 228 of file api_frame_helper.h.

◆ prologue_

std::vector<uint8_t> esphome::api::APINoiseFrameHelper::prologue_
protected

Definition at line 222 of file api_frame_helper.h.

◆ recv_cipher_

NoiseCipherState* esphome::api::APINoiseFrameHelper::recv_cipher_ {nullptr}
protected

Definition at line 227 of file api_frame_helper.h.

◆ rx_header_buf_

uint8_t esphome::api::APINoiseFrameHelper::rx_header_buf_[3]
protected

Definition at line 219 of file api_frame_helper.h.

◆ rx_header_buf_len_

uint8_t esphome::api::APINoiseFrameHelper::rx_header_buf_len_ = 0
protected

Definition at line 220 of file api_frame_helper.h.

◆ send_cipher_

NoiseCipherState* esphome::api::APINoiseFrameHelper::send_cipher_ {nullptr}
protected

Definition at line 226 of file api_frame_helper.h.


The documentation for this class was generated from the following files: