BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio > Class Template Reference

ring buffers for ingoing and outgoing LL Data PDUs More...

#include <bluetoe/link_layer/include/bluetoe/ll_data_pdu_buffer.hpp>

Public Types

using layout = typename pdu_layout_by_radio< Radio >::pdu_layout
 layout to be applied to each PDU.
 

Public Member Functions

 ll_data_pdu_buffer ()
 
buffer sizes
constexpr std::size_t max_max_rx_size () const
 returns the maximum value that can be used as maximum receive size.
 
std::size_t max_rx_size () const
 the current maximum receive size
 
void max_rx_size (std::size_t max_size)
 set the maximum receive size
 
constexpr std::size_t max_max_tx_size () const
 returns the maximum value that can be used as maximum receive size.
 
std::size_t max_tx_size () const
 the current maximum transmit size
 
void max_tx_size (std::size_t max_size)
 set the maximum transmit size
 
buffer modes
std::uint8_t * raw_pdu_buffer ()
 returns the underlying raw buffer with a size of at least ll_data_pdu_buffer::size
 
void stop_pdu_buffer ()
 places the buffer in stopped mode.
 
void reset_pdu_buffer ()
 places the buffer in running mode.
 
Interface to access the transmit buffers from the link layer
read_buffer allocate_transmit_buffer (std::size_t size)
 allocates a certain amount of memory to place a PDU to be transmitted .
 
read_buffer allocate_transmit_buffer ()
 calls allocate_transmit_buffer( max_tx_size() + layout_overhead );
 
void commit_transmit_buffer (read_buffer)
 indicates that prior allocated memory is now ready for transmission
 
bool pending_outgoing_data_available () const
 returns true, if there is pending, outgoing data
 
Interface to access the receive buffer from the link layer
write_buffer next_received () const
 returns the oldest PDU out of the receive buffer.
 
void free_received ()
 removes the oldest PDU from the receive buffer.
 

Static Public Attributes

static constexpr std::size_t size = TransmitSize + ReceiveSize
 the size of memory in bytes that are return by raw()
 
static constexpr std::size_t min_buffer_size = 29
 the minimum size an element in the buffer can have (header size + payload size).
 
static constexpr std::size_t max_buffer_size = 251
 the maximum size an element in the buffer can have (header size + payload size).
 
static constexpr std::size_t header_size = 2u
 16 bit header size of a link layer PDU
 
static constexpr std::size_t layout_overhead = layout::data_channel_pdu_memory_size( 0 ) - header_size
 addition layout overhead introduced by the applied layout
 

Protected Member Functions

Interface to the radio hardware
read_buffer allocate_receive_buffer () const
 allocates a buffer for the next PDU to be received.
 
write_buffer received (read_buffer)
 This function will be called by the scheduled radio when a PDU was received without error.
 
write_buffer acknowledge (read_buffer)
 This function will be called, instead of received(), when the CRC of a received PDU is ok, but the MIC is not ok.
 
write_buffer next_transmit ()
 returns the next PDU to be transmitted
 

Detailed Description

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio>
class bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >

ring buffers for ingoing and outgoing LL Data PDUs

The buffer has two modes:

The buffer has three interfaces:

This type is intendet to be inherited by the scheduled radio so that the ll_data_pdu_buffer can access the nessary radio interface by casting this to Radio* and to allow Radio to access the protected interface.

TransmitSize and ReceiveSize are the total size of memory for the receiving and transmitting buffer. Depending on the layout of the used Radio, there might be an overhead per PDU.

Member Typedef Documentation

◆ layout

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
using bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::layout = typename pdu_layout_by_radio< Radio >::pdu_layout

layout to be applied to each PDU.

Basecally, this defined the overhead per PDU (layout_overhead).

Constructor & Destructor Documentation

◆ ll_data_pdu_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::ll_data_pdu_buffer
Postcondition
buffer is in stopped mode

Member Function Documentation

◆ acknowledge()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
write_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::acknowledge ( read_buffer  pdu)
protected

This function will be called, instead of received(), when the CRC of a received PDU is ok, but the MIC is not ok.

In this case, the MIC might not be ok, due to a PDU beeing resent. In this case, the the last send message can be acknowlaged, but the received PDU should not be queued in the buffer.

◆ allocate_receive_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
read_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::allocate_receive_buffer
protected

allocates a buffer for the next PDU to be received.

Once a buffer was allocated to the radio hardware is will be released by the hardware by calling received().

This function can return an empty buffer if the receive buffers are all still allocated. The radio is than required to ignore all incoming trafic.

Attention
there should be a maximum of one allocated but jet not released buffer.

◆ allocate_transmit_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
read_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::allocate_transmit_buffer ( std::size_t  size)

allocates a certain amount of memory to place a PDU to be transmitted .

If not enough memory is available, the function will return an empty buffer (size == 0). To indicate that the allocated memory is filled with data to be send, commit_transmit_buffer() must be called. The size parameter is the sum of the payload + header.

Postcondition
r = allocate_transmit_buffer( n ); r.size == 0 || r.size == n
Precondition
buffer is in running mode
size <= max_tx_size()

◆ commit_transmit_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::commit_transmit_buffer ( read_buffer  pdu)

indicates that prior allocated memory is now ready for transmission

To send a PDU, first allocate_transmit_buffer() have to be called, with the maximum size need to assemble the PDU. Then commit_transmit_buffer() have to be called with the size that the PDU is really filled with at the begining of the buffer.

Precondition
a buffer must have been allocated by a call to allocate_transmit_buffer()
size
buffer is in running mode

◆ free_received()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::free_received

removes the oldest PDU from the receive buffer.

Precondition
next_received() was called without free_received() beeing called.
buffer is in running mode

◆ max_max_rx_size()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
constexpr std::size_t bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_max_rx_size ( ) const
inlineconstexpr

returns the maximum value that can be used as maximum receive size.

The result is equal to ReceiveSize.

◆ max_max_tx_size()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
constexpr std::size_t bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_max_tx_size ( ) const
inlineconstexpr

returns the maximum value that can be used as maximum receive size.

The result is equal to TransmitSize.

◆ max_rx_size() [1/2]

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
std::size_t bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_rx_size

the current maximum receive size

No PDU with larger size can be receive. This will always return at least 29 plus the Radio's layout overhead.

◆ max_rx_size() [2/2]

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_rx_size ( std::size_t  max_size)

set the maximum receive size

The used size must be smaller or equal to ReceiveSize - layout_overhead / max_max_rx_size(), smaller than 251 and larger or equal to 29. The memory is best used, when ReceiveSize divided by max_size + layout_overhead results in an integer. That integer is then the number of PDUs that can be buffered on the receivin side.

By default the function will return 29.

Postcondition
max_rx_size() == max_size

◆ max_tx_size() [1/2]

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
std::size_t bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_tx_size

the current maximum transmit size

No PDU with larger size can be transmitted. This will always return at least 29.

◆ max_tx_size() [2/2]

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::max_tx_size ( std::size_t  max_size)

set the maximum transmit size

The used size must be smaller or equal to TransmitSize / max_max_tx_size(), smaller than 251 and larger or equal to 29. The memory is best used, when TransmitSize divided by max_size results in an integer. That integer is then the number of PDUs that can be buffered on the transmitting side.

By default the function will return 29.

Postcondition
max_tx_size() == max_size

◆ next_received()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
write_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::next_received

returns the oldest PDU out of the receive buffer.

If there is no PDU in the receive buffer, an empty PDU will be returned (size == 0 ). The returned PDU is not removed from the buffer. To remove the buffer after it is not used any more, free_received() must be called.

Precondition
buffer is in running mode

◆ next_transmit()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
write_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::next_transmit
protected

returns the next PDU to be transmitted

If the transmit buffer is empty, the function will return an empty PDU.

Postcondition
next_transmit().size != 0 && next_transmit().buffer != nullptr

◆ raw_pdu_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
std::uint8_t * bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::raw_pdu_buffer

returns the underlying raw buffer with a size of at least ll_data_pdu_buffer::size

The underlying memory can be used when it's not used by other means. The size that can saftely be used is ll_data_pdu_buffer::size.

Precondition
buffer is in stopped mode

◆ received()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
write_buffer bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::received ( read_buffer  pdu)
protected

This function will be called by the scheduled radio when a PDU was received without error.

The function returns the next buffer to be transmitted.

This function will call increment_receive_packet_counter() and increment_transmit_packet_counter() on the Radio if the counter part of the encryption IV part have to be incremented.

◆ reset_pdu_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::reset_pdu_buffer

places the buffer in running mode.

Receive and transmit buffers are empty. Sequence numbers are reseted. max_rx_size() is set to default

Postcondition
next_received().empty()
max_rx_size() == 29u

◆ stop_pdu_buffer()

template<std::size_t TransmitSize, std::size_t ReceiveSize, typename Radio >
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::stop_pdu_buffer ( )

places the buffer in stopped mode.

If the buffer is in stopped mode, it's internal memory can be used for other purposes.


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