net/bluetooth/sco.c
Source file repositories/reference/linux-study-clean/net/bluetooth/sco.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/sco.c- Extension
.c- Size
- 33053 bytes
- Lines
- 1661
- 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.
- 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/seq_file.hlinux/sched/signal.hlinux/uio.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/sco.h
Detected Declarations
struct sco_connstruct sco_pinfofunction sco_conn_freefunction sco_conn_putfunction sco_sock_timeoutfunction sco_sock_set_timerfunction sco_sock_clear_timerfunction sco_chan_delfunction sco_conn_delfunction __sco_chan_addfunction sco_chan_addfunction sco_connectfunction itfunction sco_send_framefunction sco_recv_framefunction sk_for_eachfunction sk_for_eachfunction sco_sock_destructfunction sco_sock_cleanup_listenfunction sco_sock_killfunction __sco_sock_closefunction sco_sock_closefunction sco_sock_initfunction sco_sock_createfunction sco_sock_bindfunction sco_sock_connectfunction sco_sock_listenfunction sco_sock_acceptfunction sco_sock_getnamefunction sco_sock_sendmsgfunction sco_conn_defer_acceptfunction sco_sock_recvmsgfunction sco_sock_setsockoptfunction sco_sock_getsockopt_oldfunction sco_sock_getsockoptfunction list_for_each_entryfunction list_for_each_entryfunction sco_sock_shutdownfunction sco_sock_releasefunction sco_conn_readyfunction sco_connect_indfunction sco_connect_cfmfunction sco_disconn_cfmfunction sco_recv_scodatafunction sco_debugfs_showfunction sk_for_eachfunction sco_initfunction sco_exit
Annotated Snippet
static const struct proto_ops sco_sock_ops;
static struct bt_sock_list sco_sk_list = {
.lock = __RW_LOCK_UNLOCKED(sco_sk_list.lock)
};
/* ---- SCO connections ---- */
struct sco_conn {
struct hci_conn *hcon;
spinlock_t lock;
struct sock *sk;
struct delayed_work timeout_work;
unsigned int mtu;
struct kref ref;
};
#define sco_conn_lock(c) spin_lock(&c->lock)
#define sco_conn_unlock(c) spin_unlock(&c->lock)
static void sco_sock_close(struct sock *sk);
static void sco_sock_kill(struct sock *sk);
/* ----- SCO socket info ----- */
#define sco_pi(sk) ((struct sco_pinfo *) sk)
struct sco_pinfo {
struct bt_sock bt;
bdaddr_t src;
bdaddr_t dst;
__u32 flags;
__u16 setting;
struct bt_codec codec;
struct sco_conn *conn;
};
/* ---- SCO timers ---- */
#define SCO_CONN_TIMEOUT (HZ * 40)
#define SCO_DISCONN_TIMEOUT (HZ * 2)
static void sco_conn_free(struct kref *ref)
{
struct sco_conn *conn = container_of(ref, struct sco_conn, ref);
BT_DBG("conn %p", conn);
if (conn->sk)
sco_pi(conn->sk)->conn = NULL;
if (conn->hcon) {
conn->hcon->sco_data = NULL;
hci_conn_drop(conn->hcon);
}
/* Ensure no more work items will run since hci_conn has been dropped */
disable_delayed_work_sync(&conn->timeout_work);
kfree(conn);
}
static void sco_conn_put(struct sco_conn *conn)
{
if (!conn)
return;
BT_DBG("conn %p refcnt %d", conn, kref_read(&conn->ref));
kref_put(&conn->ref, sco_conn_free);
}
static struct sco_conn *sco_conn_hold(struct sco_conn *conn)
{
BT_DBG("conn %p refcnt %u", conn, kref_read(&conn->ref));
kref_get(&conn->ref);
return conn;
}
static struct sco_conn *sco_conn_hold_unless_zero(struct sco_conn *conn)
{
if (!conn)
return NULL;
BT_DBG("conn %p refcnt %u", conn, kref_read(&conn->ref));
if (!kref_get_unless_zero(&conn->ref))
return NULL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/debugfs.h`, `linux/seq_file.h`, `linux/sched/signal.h`, `linux/uio.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`, `net/bluetooth/sco.h`.
- Detected declarations: `struct sco_conn`, `struct sco_pinfo`, `function sco_conn_free`, `function sco_conn_put`, `function sco_sock_timeout`, `function sco_sock_set_timer`, `function sco_sock_clear_timer`, `function sco_chan_del`, `function sco_conn_del`, `function __sco_chan_add`.
- 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.