net/bluetooth/rfcomm/sock.c
Source file repositories/reference/linux-study-clean/net/bluetooth/rfcomm/sock.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/rfcomm/sock.c- Extension
.c- Size
- 23180 bytes
- Lines
- 1109
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compat.hlinux/export.hlinux/debugfs.hlinux/sched/signal.hlinux/uio.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/l2cap.hnet/bluetooth/rfcomm.h
Detected Declarations
function rfcomm_dlc_lockfunction rfcomm_sk_state_changefunction sk_for_eachfunction sk_for_eachfunction rfcomm_sock_destructfunction rfcomm_sock_cleanup_listenfunction rfcomm_sock_killfunction __rfcomm_sock_closefunction rfcomm_sock_closefunction rfcomm_sock_initfunction rfcomm_sock_createfunction rfcomm_sock_bindfunction rfcomm_sock_connectfunction rfcomm_sock_listenfunction rfcomm_sock_acceptfunction rfcomm_sock_getnamefunction rfcomm_sock_sendmsgfunction rfcomm_sock_recvmsgfunction rfcomm_sock_setsockopt_oldfunction rfcomm_sock_setsockoptfunction rfcomm_sock_getsockopt_oldfunction rfcomm_sock_getsockoptfunction rfcomm_sock_ioctlfunction rfcomm_sock_compat_ioctlfunction rfcomm_sock_shutdownfunction rfcomm_sock_releasefunction rfcomm_lockfunction rfcomm_sock_debugfs_showfunction sk_for_eachfunction rfcomm_init_socketsfunction rfcomm_cleanup_sockets
Annotated Snippet
static const struct proto_ops rfcomm_sock_ops;
static struct bt_sock_list rfcomm_sk_list = {
.lock = __RW_LOCK_UNLOCKED(rfcomm_sk_list.lock)
};
static void rfcomm_sock_close(struct sock *sk);
static void rfcomm_sock_kill(struct sock *sk);
/* ---- DLC callbacks ----
*
* called under rfcomm_dlc_lock()
*/
static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb)
{
struct sock *sk = d->owner;
if (!sk)
return;
atomic_add(skb->len, &sk->sk_rmem_alloc);
skb_queue_tail(&sk->sk_receive_queue, skb);
sk->sk_data_ready(sk);
if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf)
rfcomm_dlc_throttle(d);
}
static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err)
{
struct sock *sk = d->owner, *parent;
if (!sk)
return;
BT_DBG("dlc %p state %ld err %d", d, d->state, err);
lock_sock(sk);
if (err)
sk->sk_err = err;
sk->sk_state = d->state;
parent = bt_sk(sk)->parent;
if (parent) {
if (d->state == BT_CLOSED) {
sock_set_flag(sk, SOCK_ZAPPED);
bt_accept_unlink(sk);
}
parent->sk_data_ready(parent);
} else {
if (d->state == BT_CONNECTED)
rfcomm_session_getaddr(d->session,
&rfcomm_pi(sk)->src, NULL);
sk->sk_state_change(sk);
}
release_sock(sk);
if (parent && sock_flag(sk, SOCK_ZAPPED)) {
/* We have to drop DLC lock here, otherwise
* rfcomm_sock_destruct() will dead lock. */
rfcomm_dlc_unlock(d);
rfcomm_sock_kill(sk);
rfcomm_dlc_lock(d);
}
}
/* ---- Socket functions ---- */
static struct sock *__rfcomm_get_listen_sock_by_addr(u8 channel, bdaddr_t *src)
{
struct sock *sk = NULL;
sk_for_each(sk, &rfcomm_sk_list.head) {
if (rfcomm_pi(sk)->channel != channel)
continue;
if (bacmp(&rfcomm_pi(sk)->src, src))
continue;
if (sk->sk_state == BT_BOUND || sk->sk_state == BT_LISTEN)
break;
}
return sk ? sk : NULL;
}
/* Find socket with channel and source bdaddr.
* Returns closest match with an extra reference held.
*/
Annotation
- Immediate include surface: `linux/compat.h`, `linux/export.h`, `linux/debugfs.h`, `linux/sched/signal.h`, `linux/uio.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`, `net/bluetooth/l2cap.h`.
- Detected declarations: `function rfcomm_dlc_lock`, `function rfcomm_sk_state_change`, `function sk_for_each`, `function sk_for_each`, `function rfcomm_sock_destruct`, `function rfcomm_sock_cleanup_listen`, `function rfcomm_sock_kill`, `function __rfcomm_sock_close`, `function rfcomm_sock_close`, `function rfcomm_sock_init`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.