diff --git a/include/linker/common-rom.ld b/include/linker/common-rom.ld index 914a079a7ec..e97a61f113c 100644 --- a/include/linker/common-rom.ld +++ b/include/linker/common-rom.ld @@ -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 diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 80462fef620..6d2461796c4 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -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) { diff --git a/subsys/bluetooth/host/l2cap_br.c b/subsys/bluetooth/host/l2cap_br.c index f71fb5a9e7c..ef7640c0a62 100644 --- a/subsys/bluetooth/host/l2cap_br.c +++ b/subsys/bluetooth/host/l2cap_br.c @@ -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) { diff --git a/subsys/bluetooth/host/l2cap_internal.h b/subsys/bluetooth/host/l2cap_internal.h index 72f3f1d6aa5..e4f1d1b3060 100644 --- a/subsys/bluetooth/host/l2cap_internal.h +++ b/subsys/bluetooth/host/l2cap_internal.h @@ -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, \ }