1#ifndef BLUETOE_LINK_LAYER_L2CAP_SIGNALING_CHANNEL_HPP
2#define BLUETOE_LINK_LAYER_L2CAP_SIGNALING_CHANNEL_HPP
4#include <bluetoe/ll_meta_types.hpp>
5#include <bluetoe/codes.hpp>
6#include <bluetoe/l2cap_channels.hpp>
14 struct signaling_channel_meta_type {};
24 template <
typename ... Options >
33 template <
typename ConnectionData >
34 void l2cap_input(
const std::uint8_t* input, std::size_t in_size, std::uint8_t* output, std::size_t& out_size, ConnectionData& );
39 template <
typename ConnectionData >
40 void l2cap_output( std::uint8_t* output, std::size_t& out_size, ConnectionData& );
56 static constexpr std::uint16_t channel_id = l2cap_channel_ids::signaling;
57 static constexpr std::size_t minimum_channel_mtu_size = bluetoe::details::default_att_mtu_size;
58 static constexpr std::size_t maximum_channel_mtu_size = bluetoe::details::default_att_mtu_size;
60 template <
class PreviousData >
61 using channel_data_t = PreviousData;
64 bluetoe::details::signaling_channel_meta_type,
65 bluetoe::link_layer::details::valid_link_layer_option_meta_type {};
68 void reject_command(
const std::uint8_t* input, std::size_t in_size, std::uint8_t* output, std::size_t& out_size );
70 static constexpr std::uint8_t command_reject_code = 0x01;
71 static constexpr std::uint8_t connection_parameter_update_request_code = 0x12;
72 static constexpr std::uint8_t connection_parameter_update_response_code = 0x13;
74 std::uint16_t interval_min_;
75 std::uint16_t interval_max_;
76 std::uint16_t latency_;
77 std::uint16_t timeout_;
85 static constexpr std::uint8_t invalid_identifier = 0x00;
86 std::uint8_t identifier_;
98 template <
typename ConnectionData >
99 void l2cap_input(
const std::uint8_t*, std::size_t, std::uint8_t*, std::size_t& out_size, ConnectionData& )
107 template <
typename ConnectionData >
108 void l2cap_output( std::uint8_t*, std::size_t& out_size, ConnectionData& )
126 return bluetoe::details::default_att_mtu_size;
130 static constexpr std::uint16_t channel_id = l2cap_channel_ids::signaling;
131 static constexpr std::size_t minimum_channel_mtu_size = 0;
132 static constexpr std::size_t maximum_channel_mtu_size = 0;
134 template <
class PreviousData >
135 using channel_data_t = PreviousData;
137 typedef bluetoe::details::signaling_channel_meta_type meta_type;
141 template <
typename ... Options >
142 signaling_channel< Options... >::signaling_channel()
143 : pending_status_( idle )
144 , identifier_( 0x01 )
148 template <
typename ... Options >
149 template <
typename ConnectionData >
152 const std::uint8_t code = in_size > 0 ? input[ 0 ] : 0;
154 if ( code == connection_parameter_update_response_code && pending_status_ == transmitted )
156 pending_status_ = idle;
157 identifier_ =
static_cast< std::uint8_t
>( identifier_ + 1 );
159 if ( identifier_ == invalid_identifier )
160 identifier_ =
static_cast< std::uint8_t
>( identifier_ + 1 );
166 reject_command( input, in_size, output, out_size );
170 template <
typename ... Options >
171 template <
typename ConnectionData >
174 static constexpr std::size_t pdu_size = 8 + 4;
175 assert( out_size >= pdu_size );
177 if ( pending_status_ == queued )
179 pending_status_ = transmitted;
182 output[ 0 ] = connection_parameter_update_request_code;
183 output[ 1 ] = identifier_;
184 output[ 2 ] = pdu_size - 4;
186 output[ 4 ] =
static_cast< std::uint8_t
>( interval_min_ );
187 output[ 5 ] =
static_cast< std::uint8_t
>( interval_min_ >> 8 );
188 output[ 6 ] =
static_cast< std::uint8_t
>( interval_max_ );
189 output[ 7 ] =
static_cast< std::uint8_t
>( interval_max_ >> 8 );
190 output[ 8 ] =
static_cast< std::uint8_t
>( latency_ );
191 output[ 9 ] =
static_cast< std::uint8_t
>( latency_ >> 8 );
192 output[ 10 ] =
static_cast< std::uint8_t
>( timeout_ );
193 output[ 11 ] =
static_cast< std::uint8_t
>( timeout_ >> 8 );
201 template <
typename ... Options >
204 if ( pending_status_ == idle )
206 interval_min_ = interval_min;
207 interval_max_ = interval_max;
211 pending_status_ = queued;
218 template <
typename ... Options >
221 return bluetoe::details::default_att_mtu_size;
224 template <
typename ... Options >
227 static constexpr std::size_t pdu_size = 6;
228 static constexpr std::uint16_t command_not_understood = 0;
229 assert( out_size >= pdu_size );
235 const std::uint8_t identifier = input[ 1 ];
237 if ( identifier == invalid_identifier )
241 output[ 0 ] = command_reject_code;
242 output[ 1 ] = identifier;
245 output[ 4 ] =
static_cast< std::uint8_t
>( command_not_understood );
246 output[ 5 ] =
static_cast< std::uint8_t
>( command_not_understood >> 8 );
signaling channel implementations that does simply nothing
Definition: l2cap_signaling_channel.hpp:93
bool connection_parameter_update_request(std::uint16_t, std::uint16_t, std::uint16_t, std::uint16_t)
queues a connection parameter update request.
Definition: l2cap_signaling_channel.hpp:116
void l2cap_output(std::uint8_t *, std::size_t &out_size, ConnectionData &)
output to the l2cap layer
Definition: l2cap_signaling_channel.hpp:108
constexpr std::size_t channel_mtu_size() const
supported MTU size
Definition: l2cap_signaling_channel.hpp:124
void l2cap_input(const std::uint8_t *, std::size_t, std::uint8_t *, std::size_t &out_size, ConnectionData &)
input from the l2cap layer
Definition: l2cap_signaling_channel.hpp:99
very basic l2cap signaling channel implementation
Definition: l2cap_signaling_channel.hpp:26
constexpr std::size_t channel_mtu_size() const
supported MTU size
Definition: l2cap_signaling_channel.hpp:219
void l2cap_input(const std::uint8_t *input, std::size_t in_size, std::uint8_t *output, std::size_t &out_size, ConnectionData &)
input from the l2cap layer
Definition: l2cap_signaling_channel.hpp:150
void l2cap_output(std::uint8_t *output, std::size_t &out_size, ConnectionData &)
output to the l2cap layer
Definition: l2cap_signaling_channel.hpp:172
bool connection_parameter_update_request(std::uint16_t interval_min, std::uint16_t interval_max, std::uint16_t latency, std::uint16_t timeout)
queues a connection parameter update request.
Definition: l2cap_signaling_channel.hpp:202