net/bluetooth/l2cap_core.c
Source file repositories/reference/linux-study-clean/net/bluetooth/l2cap_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/l2cap_core.c- Extension
.c- Size
- 191370 bytes
- Lines
- 7915
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/debugfs.hlinux/crc16.hlinux/filter.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/l2cap.hsmp.h
Detected Declarations
struct l2cap_ecred_conn_datastruct l2cap_ecred_rsp_datastruct l2cap_chan_datafunction bdaddr_typefunction bdaddr_src_typefunction bdaddr_dst_typefunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction l2cap_add_psmfunction l2cap_add_scidfunction l2cap_alloc_cidfunction l2cap_state_changefunction l2cap_state_change_and_errorfunction l2cap_chan_set_errfunction __set_retrans_timerfunction __set_monitor_timerfunction skb_queue_walkfunction l2cap_seq_list_initfunction l2cap_seq_list_freefunction l2cap_seq_list_containsfunction l2cap_seq_list_popfunction l2cap_seq_list_clearfunction l2cap_seq_list_appendfunction l2cap_chan_timeoutfunction l2cap_chan_destroyfunction l2cap_chan_holdfunction l2cap_chan_putfunction l2cap_chan_set_defaultsfunction l2cap_le_rx_creditsfunction l2cap_le_flowctl_initfunction l2cap_ecred_initfunction __l2cap_chan_addfunction l2cap_chan_addfunction l2cap_chan_delfunction __l2cap_chan_list_idfunction list_for_each_entry_safefunction __l2cap_chan_listfunction list_for_each_entryfunction l2cap_chan_listfunction l2cap_conn_update_id_addrfunction list_for_each_entryfunction l2cap_chan_le_connect_rejectfunction l2cap_chan_ecred_connect_rejectfunction l2cap_chan_connect_rejectfunction l2cap_chan_closefunction l2cap_get_auth_type
Annotated Snippet
struct l2cap_ecred_conn_data {
struct {
struct l2cap_ecred_conn_req_hdr req;
__le16 scid[5];
} __packed pdu;
struct l2cap_chan *chan;
struct pid *pid;
int count;
};
static void l2cap_ecred_defer_connect(struct l2cap_chan *chan, void *data)
{
struct l2cap_ecred_conn_data *conn = data;
struct pid *pid;
if (chan == conn->chan)
return;
if (!test_and_clear_bit(FLAG_DEFER_SETUP, &chan->flags))
return;
pid = chan->ops->get_peer_pid(chan);
/* Only add deferred channels with the same PID/PSM */
if (conn->pid != pid || chan->psm != conn->chan->psm || chan->ident ||
chan->mode != L2CAP_MODE_EXT_FLOWCTL || chan->state != BT_CONNECT)
return;
if (test_and_set_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags))
return;
l2cap_ecred_init(chan, 0);
/* Set the same ident so we can match on the rsp */
chan->ident = conn->chan->ident;
/* Include all channels deferred */
conn->pdu.scid[conn->count] = cpu_to_le16(chan->scid);
conn->count++;
}
static void l2cap_ecred_connect(struct l2cap_chan *chan)
{
struct l2cap_conn *conn = chan->conn;
struct l2cap_ecred_conn_data data;
if (test_bit(FLAG_DEFER_SETUP, &chan->flags))
return;
if (test_and_set_bit(FLAG_ECRED_CONN_REQ_SENT, &chan->flags))
return;
l2cap_ecred_init(chan, 0);
memset(&data, 0, sizeof(data));
data.pdu.req.psm = chan->psm;
data.pdu.req.mtu = cpu_to_le16(chan->imtu);
data.pdu.req.mps = cpu_to_le16(chan->mps);
data.pdu.req.credits = cpu_to_le16(chan->rx_credits);
data.pdu.scid[0] = cpu_to_le16(chan->scid);
chan->ident = l2cap_get_ident(conn);
data.count = 1;
data.chan = chan;
data.pid = chan->ops->get_peer_pid(chan);
__l2cap_chan_list(conn, l2cap_ecred_defer_connect, &data);
l2cap_send_cmd(conn, chan->ident, L2CAP_ECRED_CONN_REQ,
sizeof(data.pdu.req) + data.count * sizeof(__le16),
&data.pdu);
}
static void l2cap_le_start(struct l2cap_chan *chan)
{
struct l2cap_conn *conn = chan->conn;
if (!smp_conn_security(conn->hcon, chan->sec_level))
return;
if (!chan->psm) {
l2cap_chan_ready(chan);
return;
}
if (chan->state == BT_CONNECT) {
if (chan->mode == L2CAP_MODE_EXT_FLOWCTL)
l2cap_ecred_connect(chan);
Annotation
- Immediate include surface: `linux/module.h`, `linux/debugfs.h`, `linux/crc16.h`, `linux/filter.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`, `net/bluetooth/l2cap.h`, `smp.h`.
- Detected declarations: `struct l2cap_ecred_conn_data`, `struct l2cap_ecred_rsp_data`, `struct l2cap_chan_data`, `function bdaddr_type`, `function bdaddr_src_type`, `function bdaddr_dst_type`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.