net/bluetooth/hci_core.c
Source file repositories/reference/linux-study-clean/net/bluetooth/hci_core.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/hci_core.c- Extension
.c- Size
- 96809 bytes
- Lines
- 4129
- 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.
- 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.
- 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/export.hlinux/rfkill.hlinux/debugfs.hlinux/crypto.hlinux/kcov.hlinux/property.hlinux/suspend.hlinux/wait.hlinux/unaligned.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/l2cap.hnet/bluetooth/mgmt.hhci_debugfs.hsmp.hleds.hmsft.haosp.hhci_codec.h
Detected Declarations
function hci_dev_put_srcufunction hci_discovery_activefunction hci_discovery_set_statefunction hci_inquiry_cache_flushfunction list_for_each_entry_safefunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction hci_inquiry_cache_update_resolvefunction list_for_each_entryfunction hci_inquiry_cache_updatefunction inquiry_cache_dumpfunction list_for_each_entryfunction hci_inquiryfunction inquiry_cache_emptyfunction hci_dev_do_openfunction hci_dev_openfunction hci_dev_do_closefunction hci_dev_closefunction hci_dev_do_resetfunction hci_dev_resetfunction hci_dev_reset_statfunction hci_update_passive_scan_statefunction hci_dev_cmdfunction hci_get_dev_listfunction hci_get_dev_infofunction hci_dev_do_powerofffunction hci_rfkill_set_blockfunction hci_power_onfunction hci_dev_test_flagfunction hci_power_offfunction hci_error_resetfunction hci_uuids_clearfunction list_for_each_entry_safefunction hci_link_keys_clearfunction list_for_each_entry_safefunction hci_smp_ltks_clearfunction list_for_each_entry_safefunction hci_smp_irks_clearfunction list_for_each_entry_safefunction hci_blocked_keys_clearfunction list_for_each_entry_safefunction hci_is_blocked_keyfunction hci_persistent_keyfunction ltk_rolefunction list_for_each_entry_rcufunction hci_remove_link_keyfunction hci_remove_ltk
Annotated Snippet
error = device_add(&hdev->dev);
if (error < 0)
goto err_wqueue;
hci_leds_init(hdev);
hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops,
hdev);
if (hdev->rfkill) {
if (rfkill_register(hdev->rfkill) < 0) {
rfkill_destroy(hdev->rfkill);
hdev->rfkill = NULL;
}
}
if (hdev->rfkill && rfkill_blocked(hdev->rfkill))
hci_dev_set_flag(hdev, HCI_RFKILLED);
hci_dev_set_flag(hdev, HCI_SETUP);
hci_dev_set_flag(hdev, HCI_AUTO_OFF);
/* Assume BR/EDR support until proven otherwise (such as
* through reading supported features during init.
*/
hci_dev_set_flag(hdev, HCI_BREDR_ENABLED);
write_lock(&hci_dev_list_lock);
list_add(&hdev->list, &hci_dev_list);
write_unlock(&hci_dev_list_lock);
/* Devices that are marked for raw-only usage are unconfigured
* and should not be included in normal operation.
*/
if (hci_test_quirk(hdev, HCI_QUIRK_RAW_DEVICE))
hci_dev_set_flag(hdev, HCI_UNCONFIGURED);
/* Mark Remote Wakeup connection flag as supported if driver has wakeup
* callback.
*/
if (hdev->wakeup)
hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP;
hci_sock_dev_event(hdev, HCI_DEV_REG);
hci_dev_hold(hdev);
error = hci_register_suspend_notifier(hdev);
if (error)
BT_WARN("register suspend notifier failed error:%d\n", error);
queue_work(hdev->req_workqueue, &hdev->power_on);
idr_init(&hdev->adv_monitors_idr);
msft_register(hdev);
return id;
err_wqueue:
debugfs_remove_recursive(hdev->debugfs);
destroy_workqueue(hdev->workqueue);
destroy_workqueue(hdev->req_workqueue);
err:
ida_free(&hci_index_ida, hdev->id);
return error;
}
EXPORT_SYMBOL(hci_register_dev);
/* Unregister HCI device */
void hci_unregister_dev(struct hci_dev *hdev)
{
BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
mutex_lock(&hdev->unregister_lock);
hci_dev_set_flag(hdev, HCI_UNREGISTER);
mutex_unlock(&hdev->unregister_lock);
write_lock(&hci_dev_list_lock);
list_del(&hdev->list);
write_unlock(&hci_dev_list_lock);
synchronize_srcu(&hdev->srcu);
cleanup_srcu_struct(&hdev->srcu);
disable_work_sync(&hdev->rx_work);
disable_work_sync(&hdev->cmd_work);
disable_work_sync(&hdev->tx_work);
disable_work_sync(&hdev->power_on);
disable_work_sync(&hdev->error_reset);
disable_delayed_work_sync(&hdev->cmd_timer);
Annotation
- Immediate include surface: `linux/export.h`, `linux/rfkill.h`, `linux/debugfs.h`, `linux/crypto.h`, `linux/kcov.h`, `linux/property.h`, `linux/suspend.h`, `linux/wait.h`.
- Detected declarations: `function hci_dev_put_srcu`, `function hci_discovery_active`, `function hci_discovery_set_state`, `function hci_inquiry_cache_flush`, `function list_for_each_entry_safe`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function hci_inquiry_cache_update_resolve`, `function list_for_each_entry`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration 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.