ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
esphome::api::APINoiseFrameHelper Class Reference

#include <api_frame_helper_noise.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, const ClientInfo *client_info)
 
 ~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 (uint8_t type, ProtoWriteBuffer buffer) override
 
APIError write_protobuf_packets (ProtoWriteBuffer buffer, std::span< const 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, const ClientInfo *client_info)
 
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)
 
bool is_socket_ready () const
 

Protected Member Functions

APIError state_action_ ()
 To be called from read/write methods.
 
APIError try_read_frame_ (std::vector< uint8_t > *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)
 
APIError handle_handshake_frame_error_ (APIError aerr)
 
APIError handle_noise_error_ (int err, const char *func_name, APIError api_err)
 
- Protected Member Functions inherited from esphome::api::APIFrameHelper
APIError write_raw_ (const struct iovec *iov, int iovcnt, uint16_t total_write_len)
 
APIError try_send_tx_buf_ ()
 
void buffer_data_from_iov_ (const struct iovec *iov, int iovcnt, uint16_t total_write_len, uint16_t offset)
 
APIError handle_socket_write_error_ ()
 
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_ ()
 
APIError handle_socket_read_result_ (ssize_t received)
 

Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Definition at line 10 of file api_frame_helper_noise.h.

Constructor & Destructor Documentation

◆ APINoiseFrameHelper()

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

Definition at line 12 of file api_frame_helper_noise.h.

◆ ~APINoiseFrameHelper()

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

Definition at line 556 of file api_frame_helper_noise.cpp.

Member Function Documentation

◆ check_handshake_finished_()

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

Definition at line 531 of file api_frame_helper_noise.cpp.

◆ frame_footer_size()

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

Implements esphome::api::APIFrameHelper.

Definition at line 31 of file api_frame_helper_noise.h.

◆ frame_header_padding()

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

Implements esphome::api::APIFrameHelper.

Definition at line 29 of file api_frame_helper_noise.h.

◆ handle_handshake_frame_error_()

APIError esphome::api::APINoiseFrameHelper::handle_handshake_frame_error_ ( APIError aerr)
protected

Definition at line 84 of file api_frame_helper_noise.cpp.

◆ handle_noise_error_()

APIError esphome::api::APINoiseFrameHelper::handle_noise_error_ ( int err,
const char * func_name,
APIError api_err )
protected

Definition at line 94 of file api_frame_helper_noise.cpp.

◆ init()

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

Initialize the frame helper, returns OK if successful.

Implements esphome::api::APIFrameHelper.

Definition at line 69 of file api_frame_helper_noise.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 493 of file api_frame_helper_noise.cpp.

◆ loop()

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

Run through handshake messages (if in that phase)

Reimplemented from esphome::api::APIFrameHelper.

Definition at line 104 of file api_frame_helper_noise.cpp.

◆ read_packet()

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

Implements esphome::api::APIFrameHelper.

Definition at line 350 of file api_frame_helper_noise.cpp.

◆ send_explicit_handshake_reject_()

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

Definition at line 334 of file api_frame_helper_noise.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 213 of file api_frame_helper_noise.cpp.

◆ try_read_frame_()

APIError esphome::api::APINoiseFrameHelper::try_read_frame_ ( std::vector< uint8_t > * 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 136 of file api_frame_helper_noise.cpp.

◆ write_frame_()

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

Definition at line 471 of file api_frame_helper_noise.cpp.

◆ write_protobuf_packet()

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

Implements esphome::api::APIFrameHelper.

Definition at line 397 of file api_frame_helper_noise.cpp.

◆ write_protobuf_packets()

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

Implements esphome::api::APIFrameHelper.

Definition at line 405 of file api_frame_helper_noise.cpp.

Field Documentation

◆ ctx_

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

Definition at line 49 of file api_frame_helper_noise.h.

◆ handshake_

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

Definition at line 44 of file api_frame_helper_noise.h.

◆ nid_

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

Definition at line 55 of file api_frame_helper_noise.h.

◆ prologue_

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

Definition at line 52 of file api_frame_helper_noise.h.

◆ recv_cipher_

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

Definition at line 46 of file api_frame_helper_noise.h.

◆ rx_header_buf_

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

Definition at line 61 of file api_frame_helper_noise.h.

◆ rx_header_buf_len_

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

Definition at line 62 of file api_frame_helper_noise.h.

◆ send_cipher_

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

Definition at line 45 of file api_frame_helper_noise.h.


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