drivers/bluetooth/hci_bcsp.c
Source file repositories/reference/linux-study-clean/drivers/bluetooth/hci_bcsp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/bluetooth/hci_bcsp.c- Extension
.c- Size
- 18766 bytes
- Lines
- 791
- Domain
- Driver Families
- Bucket
- drivers/bluetooth
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/kernel.hlinux/init.hlinux/types.hlinux/fcntl.hlinux/interrupt.hlinux/ptrace.hlinux/poll.hlinux/slab.hlinux/tty.hlinux/errno.hlinux/string.hlinux/signal.hlinux/ioctl.hlinux/skbuff.hlinux/bitrev.hlinux/unaligned.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hhci_uart.h
Detected Declarations
struct bcsp_structfunction bcsp_crc_updatefunction bcsp_slip_msgdelimfunction bcsp_slip_one_bytefunction bcsp_enqueuefunction bcsp_flushfunction bcsp_pkt_cullfunction bcsp_handle_le_pktfunction bcsp_unslip_one_bytefunction bcsp_complete_rx_pktfunction bscp_get_crcfunction bcsp_recvfunction bcsp_timed_eventfunction bcsp_openfunction bcsp_closefunction bcsp_initfunction bcsp_deinit
Annotated Snippet
struct bcsp_struct {
struct sk_buff_head unack; /* Unack'ed packets queue */
struct sk_buff_head rel; /* Reliable packets queue */
struct sk_buff_head unrel; /* Unreliable packets queue */
unsigned long rx_count;
struct sk_buff *rx_skb;
u8 rxseq_txack; /* rxseq == txack. */
u8 rxack; /* Last packet sent by us that the peer ack'ed */
struct timer_list tbcsp;
struct hci_uart *hu;
enum {
BCSP_W4_PKT_DELIMITER,
BCSP_W4_PKT_START,
BCSP_W4_BCSP_HDR,
BCSP_W4_DATA,
BCSP_W4_CRC
} rx_state;
enum {
BCSP_ESCSTATE_NOESC,
BCSP_ESCSTATE_ESC
} rx_esc_state;
u8 use_crc;
u16 message_crc;
u8 txack_req; /* Do we need to send ack's to the peer? */
/* Reliable packet sequence number - used to assign seq to each rel pkt. */
u8 msgq_txseq;
};
/* ---- BCSP CRC calculation ---- */
/* Table for calculating CRC for polynomial 0x1021, LSB processed first,
* initial value 0xffff, bits shifted in reverse order.
*/
static const u16 crc_table[] = {
0x0000, 0x1081, 0x2102, 0x3183,
0x4204, 0x5285, 0x6306, 0x7387,
0x8408, 0x9489, 0xa50a, 0xb58b,
0xc60c, 0xd68d, 0xe70e, 0xf78f
};
/* Initialise the crc calculator */
#define BCSP_CRC_INIT(x) x = 0xffff
/* Update crc with next data byte
*
* Implementation note
* The data byte is treated as two nibbles. The crc is generated
* in reverse, i.e., bits are fed into the register from the top.
*/
static void bcsp_crc_update(u16 *crc, u8 d)
{
u16 reg = *crc;
reg = (reg >> 4) ^ crc_table[(reg ^ d) & 0x000f];
reg = (reg >> 4) ^ crc_table[(reg ^ (d >> 4)) & 0x000f];
*crc = reg;
}
/* ---- BCSP core ---- */
static void bcsp_slip_msgdelim(struct sk_buff *skb)
{
const char pkt_delim = 0xc0;
skb_put_data(skb, &pkt_delim, 1);
}
static void bcsp_slip_one_byte(struct sk_buff *skb, u8 c)
{
const char esc_c0[2] = { 0xdb, 0xdc };
const char esc_db[2] = { 0xdb, 0xdd };
switch (c) {
case 0xc0:
skb_put_data(skb, &esc_c0, 2);
break;
case 0xdb:
skb_put_data(skb, &esc_db, 2);
break;
default:
skb_put_data(skb, &c, 1);
}
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/init.h`, `linux/types.h`, `linux/fcntl.h`, `linux/interrupt.h`, `linux/ptrace.h`, `linux/poll.h`.
- Detected declarations: `struct bcsp_struct`, `function bcsp_crc_update`, `function bcsp_slip_msgdelim`, `function bcsp_slip_one_byte`, `function bcsp_enqueue`, `function bcsp_flush`, `function bcsp_pkt_cull`, `function bcsp_handle_le_pkt`, `function bcsp_unslip_one_byte`, `function bcsp_complete_rx_pkt`.
- Atlas domain: Driver Families / drivers/bluetooth.
- 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.