BlueToe
an alternative GATT/BLE implementation
|
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 | |
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.
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).
bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::ll_data_pdu_buffer |
|
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.
|
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.
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.
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.
void bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, Radio >::free_received |
removes the oldest PDU from the receive buffer.
|
inlineconstexpr |
returns the maximum value that can be used as maximum receive size.
The result is equal to ReceiveSize.
|
inlineconstexpr |
returns the maximum value that can be used as maximum receive size.
The result is equal to TransmitSize.
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.
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.
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.
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.
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.
|
protected |
returns the next PDU to be transmitted
If the transmit buffer is empty, the function will return an empty PDU.
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.
|
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.
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
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.