net/bluetooth/mgmt_util.c
Source file repositories/reference/linux-study-clean/net/bluetooth/mgmt_util.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/mgmt_util.c- Extension
.c- Size
- 9653 bytes
- Lines
- 439
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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/unaligned.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/hci_mon.hnet/bluetooth/mgmt.hmgmt_util.h
Detected Declarations
function Copyrightfunction mgmt_send_event_skbfunction mgmt_send_eventfunction mgmt_cmd_statusfunction mgmt_cmd_completefunction list_for_each_entry_safefunction mgmt_pending_foreachfunction list_for_each_entry_safefunction mgmt_pending_freefunction mgmt_pending_removefunction __mgmt_pending_listedfunction list_for_each_entryfunction mgmt_pending_listedfunction mgmt_pending_validfunction mgmt_mesh_foreachfunction list_for_each_entry_safefunction list_for_each_entryfunction list_for_each_entryfunction mgmt_mesh_remove
Annotated Snippet
if (cmd->opcode == opcode) {
mutex_unlock(&hdev->mgmt_pending_lock);
return cmd;
}
}
mutex_unlock(&hdev->mgmt_pending_lock);
return NULL;
}
void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev, bool remove,
void (*cb)(struct mgmt_pending_cmd *cmd, void *data),
void *data)
{
struct mgmt_pending_cmd *cmd, *tmp;
mutex_lock(&hdev->mgmt_pending_lock);
list_for_each_entry_safe(cmd, tmp, &hdev->mgmt_pending, list) {
if (opcode > 0 && cmd->opcode != opcode)
continue;
if (remove)
list_del(&cmd->list);
cb(cmd, data);
if (remove)
mgmt_pending_free(cmd);
}
mutex_unlock(&hdev->mgmt_pending_lock);
}
struct mgmt_pending_cmd *mgmt_pending_new(struct sock *sk, u16 opcode,
struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_pending_cmd *cmd;
cmd = kzalloc_obj(*cmd);
if (!cmd)
return NULL;
cmd->opcode = opcode;
cmd->hdev = hdev;
cmd->param = kmemdup(data, len, GFP_KERNEL);
if (!cmd->param) {
kfree(cmd);
return NULL;
}
cmd->param_len = len;
cmd->sk = sk;
sock_hold(sk);
return cmd;
}
struct mgmt_pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_pending_cmd *cmd;
cmd = mgmt_pending_new(sk, opcode, hdev, data, len);
if (!cmd)
return NULL;
mutex_lock(&hdev->mgmt_pending_lock);
list_add_tail(&cmd->list, &hdev->mgmt_pending);
mutex_unlock(&hdev->mgmt_pending_lock);
return cmd;
}
void mgmt_pending_free(struct mgmt_pending_cmd *cmd)
{
sock_put(cmd->sk);
kfree(cmd->param);
kfree(cmd);
}
void mgmt_pending_remove(struct mgmt_pending_cmd *cmd)
{
mutex_lock(&cmd->hdev->mgmt_pending_lock);
list_del(&cmd->list);
Annotation
- Immediate include surface: `linux/unaligned.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`, `net/bluetooth/hci_mon.h`, `net/bluetooth/mgmt.h`, `mgmt_util.h`.
- Detected declarations: `function Copyright`, `function mgmt_send_event_skb`, `function mgmt_send_event`, `function mgmt_cmd_status`, `function mgmt_cmd_complete`, `function list_for_each_entry_safe`, `function mgmt_pending_foreach`, `function list_for_each_entry_safe`, `function mgmt_pending_free`, `function mgmt_pending_remove`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.