Bluetooth: L2CAP: Make use of Z_STRUCT_SECTION_ITERABLE

This makes use of Z_STRUCT_SECTION_ITERABLE to define fixed channel
sections.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2019-07-01 18:06:04 +03:00 committed by Johan Hedberg
commit 4e8ddfd640
4 changed files with 20 additions and 24 deletions

View file

@ -78,17 +78,17 @@
SECTION_DATA_PROLOGUE(_bt_channels_area,,SUBALIGN(4))
{
_bt_channels_start = .;
KEEP(*(SORT_BY_NAME("._bt_channels.static.*")))
_bt_channels_end = .;
_bt_l2cap_fixed_chan_list_start = .;
KEEP(*(SORT_BY_NAME("._bt_l2cap_fixed_chan.static.*")))
_bt_l2cap_fixed_chan_list_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
#if defined(CONFIG_BT_BREDR)
SECTION_DATA_PROLOGUE(_bt_br_channels_area,,SUBALIGN(4))
{
_bt_br_channels_start = .;
KEEP(*(SORT_BY_NAME("._bt_br_channels.static.*")))
_bt_br_channels_end = .;
_bt_l2cap_br_fixed_chan_list_start = .;
KEEP(*(SORT_BY_NAME("._bt_l2cap_br_fixed_chan.static.*")))
_bt_l2cap_br_fixed_chan_list_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
#endif

View file

@ -50,10 +50,6 @@
#define L2CAP_CONN_TIMEOUT K_SECONDS(40)
#define L2CAP_DISC_TIMEOUT K_SECONDS(2)
/* Linker-defined symbols bound to the bt_l2cap_fixed_chan structs */
extern const struct bt_l2cap_fixed_chan _bt_channels_start[];
extern const struct bt_l2cap_fixed_chan _bt_channels_end[];
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
/* Size of MTU is based on the maximum amount of data the buffer can hold
* excluding ACL and driver headers.
@ -323,7 +319,6 @@ static bool l2cap_chan_add(struct bt_conn *conn, struct bt_l2cap_chan *chan,
void bt_l2cap_connected(struct bt_conn *conn)
{
const struct bt_l2cap_fixed_chan *fchan;
struct bt_l2cap_chan *chan;
if (IS_ENABLED(CONFIG_BT_BREDR) &&
@ -332,7 +327,7 @@ void bt_l2cap_connected(struct bt_conn *conn)
return;
}
for (fchan = _bt_channels_start; fchan < _bt_channels_end; fchan++) {
Z_STRUCT_SECTION_FOREACH(bt_l2cap_fixed_chan, fchan) {
struct bt_l2cap_le_chan *ch;
if (fchan->accept(conn, &chan) < 0) {

View file

@ -79,9 +79,6 @@ enum {
static sys_slist_t br_servers;
/* Linker-defined symbols bound to the bt_l2cap_fixed_chan structs */
extern const struct bt_l2cap_fixed_chan _bt_br_channels_start[];
extern const struct bt_l2cap_fixed_chan _bt_br_channels_end[];
/* Pool for outgoing BR/EDR signaling packets, min MTU is 48 */
NET_BUF_POOL_DEFINE(br_sig_pool, CONFIG_BT_MAX_CONN,
@ -386,12 +383,10 @@ done:
static u8_t get_fixed_channels_mask(void)
{
const struct bt_l2cap_fixed_chan *fchan;
u8_t mask = 0U;
/* this needs to be enhanced if AMP Test Manager support is added */
for (fchan = _bt_br_channels_start; fchan < _bt_br_channels_end;
fchan++) {
Z_STRUCT_SECTION_FOREACH(bt_l2cap_br_fixed_chan, fchan) {
mask |= BIT(fchan->cid);
}
@ -454,11 +449,9 @@ static int l2cap_br_info_req(struct bt_l2cap_br *l2cap, u8_t ident,
void bt_l2cap_br_connected(struct bt_conn *conn)
{
const struct bt_l2cap_fixed_chan *fchan;
struct bt_l2cap_chan *chan;
for (fchan = _bt_br_channels_start; fchan < _bt_br_channels_end;
fchan++) {
Z_STRUCT_SECTION_FOREACH(bt_l2cap_br_fixed_chan, fchan) {
struct bt_l2cap_br_chan *ch;
if (!fchan->accept) {
@ -1550,7 +1543,7 @@ static int l2cap_br_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
return -ENOMEM;
}
BT_L2CAP_CHANNEL_DEFINE(br_fixed_chan, BT_L2CAP_CID_BR_SIG, l2cap_br_accept);
BT_L2CAP_BR_CHANNEL_DEFINE(br_fixed_chan, BT_L2CAP_CID_BR_SIG, l2cap_br_accept);
void bt_l2cap_br_init(void)
{

View file

@ -205,8 +205,16 @@ struct bt_l2cap_fixed_chan {
};
#define BT_L2CAP_CHANNEL_DEFINE(_name, _cid, _accept) \
const struct bt_l2cap_fixed_chan _name __aligned(4) \
__in_section(_bt_channels, static, _name) = { \
const Z_STRUCT_SECTION_ITERABLE(bt_l2cap_fixed_chan, _name) = { \
.cid = _cid, \
.accept = _accept, \
}
/* Need a different name for the sections not to conflict */
#define bt_l2cap_br_fixed_chan bt_l2cap_fixed_chan
#define BT_L2CAP_BR_CHANNEL_DEFINE(_name, _cid, _accept) \
const Z_STRUCT_SECTION_ITERABLE(bt_l2cap_br_fixed_chan, _name) = { \
.cid = _cid, \
.accept = _accept, \
}