net/bluetooth/hci_sock.c
Source file repositories/reference/linux-study-clean/net/bluetooth/hci_sock.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/hci_sock.c- Extension
.c- Size
- 50494 bytes
- Lines
- 2270
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/utsname.hlinux/sched.hlinux/uio.hlinux/unaligned.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/hci_mon.hnet/bluetooth/mgmt.hmgmt_util.h
Detected Declarations
struct hci_pinfostruct hci_sec_filterfunction hci_sock_set_flagfunction hci_sock_clear_flagfunction hci_sock_test_flagfunction hci_sock_get_channelfunction hci_sock_get_cookiefunction hci_sock_gen_cookiefunction hci_sock_free_cookiefunction hci_test_bitfunction is_filtered_packetfunction hci_send_to_sockfunction sk_for_eachfunction hci_sock_copy_credsfunction __hci_send_to_channelfunction sk_for_eachfunction hci_send_to_channelfunction hci_send_to_monitorfunction hci_send_monitor_ctrl_eventfunction sk_for_eachfunction __printffunction send_monitor_replayfunction list_for_each_entryfunction send_monitor_control_replayfunction sk_for_eachfunction hci_si_eventfunction hci_sock_dev_eventfunction sk_for_eachfunction list_for_each_entryfunction hci_mgmt_chan_registerfunction hci_mgmt_chan_unregisterfunction hci_sock_releasefunction hci_sock_reject_list_addfunction hci_sock_reject_list_delfunction hci_sock_bound_ioctlfunction hci_sock_ioctlfunction hci_sock_compat_ioctlfunction hci_sock_bindfunction hci_sock_getnamefunction hci_sock_cmsgfunction hci_sock_recvmsgfunction hci_mgmt_cmdfunction hci_logging_framefunction hci_sock_sendmsgfunction hci_sock_setsockopt_oldfunction hci_sock_setsockoptfunction hci_sock_getsockopt_oldfunction hci_sock_getsockopt
Annotated Snippet
static const struct proto_ops hci_sock_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.release = hci_sock_release,
.bind = hci_sock_bind,
.getname = hci_sock_getname,
.sendmsg = hci_sock_sendmsg,
.recvmsg = hci_sock_recvmsg,
.ioctl = hci_sock_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = hci_sock_compat_ioctl,
#endif
.poll = datagram_poll,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = hci_sock_setsockopt,
.getsockopt_iter = hci_sock_getsockopt,
.connect = sock_no_connect,
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.mmap = sock_no_mmap
};
static struct proto hci_sk_proto = {
.name = "HCI",
.owner = THIS_MODULE,
.obj_size = sizeof(struct hci_pinfo)
};
static int hci_sock_create(struct net *net, struct socket *sock, int protocol,
int kern)
{
struct sock *sk;
BT_DBG("sock %p", sock);
if (sock->type != SOCK_RAW)
return -ESOCKTNOSUPPORT;
sock->ops = &hci_sock_ops;
sk = bt_sock_alloc(net, sock, &hci_sk_proto, protocol, GFP_ATOMIC,
kern);
if (!sk)
return -ENOMEM;
sock->state = SS_UNCONNECTED;
sk->sk_destruct = hci_sock_destruct;
bt_sock_link(&hci_sk_list, sk);
return 0;
}
static const struct net_proto_family hci_sock_family_ops = {
.family = PF_BLUETOOTH,
.owner = THIS_MODULE,
.create = hci_sock_create,
};
int __init hci_sock_init(void)
{
int err;
BUILD_BUG_ON(sizeof(struct sockaddr_hci) > sizeof(struct sockaddr));
err = proto_register(&hci_sk_proto, 0);
if (err < 0)
return err;
err = bt_sock_register(BTPROTO_HCI, &hci_sock_family_ops);
if (err < 0) {
BT_ERR("HCI socket registration failed");
goto error;
}
err = bt_procfs_init(&init_net, "hci", &hci_sk_list, NULL);
if (err < 0) {
BT_ERR("Failed to create HCI proc file");
bt_sock_unregister(BTPROTO_HCI);
goto error;
}
BT_INFO("HCI socket layer initialized");
return 0;
error:
proto_unregister(&hci_sk_proto);
return err;
}
Annotation
- Immediate include surface: `linux/compat.h`, `linux/export.h`, `linux/utsname.h`, `linux/sched.h`, `linux/uio.h`, `linux/unaligned.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`.
- Detected declarations: `struct hci_pinfo`, `struct hci_sec_filter`, `function hci_sock_set_flag`, `function hci_sock_clear_flag`, `function hci_sock_test_flag`, `function hci_sock_get_channel`, `function hci_sock_get_cookie`, `function hci_sock_gen_cookie`, `function hci_sock_free_cookie`, `function hci_test_bit`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.