1#ifndef BLUETOE_LINK_LAYER_WHITE_LIST_HPP
2#define BLUETOE_LINK_LAYER_WHITE_LIST_HPP
4#include <bluetoe/address.hpp>
5#include <bluetoe/ll_meta_types.hpp>
14 struct white_list_meta_type {};
16 template < std::
size_t RequiredSize,
bool SoftwareRequired,
typename Radio,
typename LinkLayer >
17 class white_list_implementation;
29 template < std::
size_t Size = 8 >
126 details::white_list_meta_type,
127 details::valid_link_layer_option_meta_type {};
129 template <
class Radio,
class LinkLayer >
131 details::white_list_implementation<
133 ( Size > Radio::radio_maximum_white_list_entries ),
149 template <
class Radio,
class LinkLayer >
151 bool is_connection_request_in_filter(
const device_address& )
const
163 details::white_list_meta_type,
164 details::valid_link_layer_option_meta_type {};
173 template < std::
size_t Size,
typename Radio,
typename LinkLayer >
174 class white_list_implementation< Size, true, Radio, LinkLayer >
177 static constexpr std::size_t maximum_white_list_entries = Size;
179 white_list_implementation()
182 , connection_filter_( false )
183 , scan_filter_( false )
187 std::size_t white_list_free_size()
const
192 void clear_white_list()
197 bool add_to_white_list(
const device_address& addr )
199 if ( is_in_white_list( addr ) )
202 if ( free_size_ == 0 )
205 addresses_[ Size - free_size_ ] = addr;
210 bool is_in_white_list(
const device_address& addr )
const
212 const auto end = std::begin( addresses_ ) + ( Size - free_size_ );
213 return std::find( std::begin( addresses_ ), end, addr ) != end;
216 bool remove_from_white_list(
const device_address& addr )
218 const auto end = std::begin( addresses_ ) + ( Size - free_size_ );
219 const auto pos = std::find( std::begin( addresses_ ), end, addr );
230 void connection_request_filter(
bool b )
232 connection_filter_ = b;
235 bool connection_request_filter()
const
237 return connection_filter_;
240 void scan_request_filter(
bool b )
245 bool scan_request_filter()
const
250 bool is_connection_request_in_filter(
const device_address& addr )
const
252 return !connection_filter_ || is_in_white_list( addr );
255 bool is_scan_request_in_filter(
const device_address& addr )
const
257 return !scan_filter_ || is_in_white_list( addr );
262 std::size_t free_size_;
263 device_address addresses_[ Size ];
264 bool connection_filter_;
271 template < std::
size_t Size,
typename Radio,
typename LinkLayer >
272 class white_list_implementation< Size, false, Radio, LinkLayer >
275 static constexpr std::size_t maximum_white_list_entries = Size;
277 std::size_t white_list_free_size()
const
279 return this_to_radio().radio_white_list_free_size();
282 void clear_white_list()
284 this_to_radio().radio_clear_white_list();
287 bool add_to_white_list(
const device_address& addr )
289 return this_to_radio().radio_add_to_white_list( addr );
292 bool is_in_white_list(
const device_address& addr )
const
294 return this_to_radio().radio_is_in_white_list( addr );
297 bool remove_from_white_list(
const device_address& addr )
299 return this_to_radio().radio_remove_from_white_list( addr );
302 void connection_request_filter(
bool b )
304 this_to_radio().radio_connection_request_filter( b );
307 bool connection_request_filter()
const
309 return this_to_radio().radio_connection_request_filter();
312 void scan_request_filter(
bool b )
314 this_to_radio().radio_scan_request_filter( b );
317 bool scan_request_filter()
const
319 return this_to_radio().radio_scan_request_filter();
322 bool is_connection_request_in_filter(
const device_address& addr )
const
324 return this_to_radio().radio_is_connection_request_in_filter( addr );
327 bool is_scan_request_in_filter(
const device_address& addr )
const
329 return this_to_radio().radio_is_scan_request_in_filter( addr );
332 Radio& this_to_radio()
334 return static_cast< Radio&
>(
static_cast< LinkLayer&
>( *this ) );
337 const Radio& this_to_radio()
const
339 return static_cast< const Radio&
>(
static_cast< const LinkLayer&
>( *this ) );
data type containing a device address and the address type (public or random).
Definition: address.hpp:107
adds a white list to the link layer with white list related functions.
Definition: white_list.hpp:31
std::size_t white_list_free_size() const
returns the number of addresses that could be added to the white list before add_to_white_list() woul...
bool connection_request_filter() const
current value of the property.
void scan_request_filter(bool b)
Accept scan requests only from devices within the white list.
void clear_white_list()
remove all entries from the white list
static constexpr std::size_t maximum_white_list_entries
The maximum number of device addresses, the white list can contain.
Definition: white_list.hpp:40
bool scan_request_filter() const
current value of the property.
bool is_in_white_list(const device_address &addr) const
returns true, if the given address in within the white list
bool add_to_white_list(const device_address &addr)
add the given address to the white list.
bool is_scan_request_in_filter(const device_address &addr) const
returns true, if a scan request from the given address should be answered.
bool remove_from_white_list(const device_address &addr)
remove the given address from the white list
bool is_connection_request_in_filter(const device_address &addr) const
returns true, if a connection request from the given address should be answered.
void connection_request_filter(bool b)
Accept connection requests only from devices within the white list.
no white list in the link layer
Definition: white_list.hpp:147