net/bluetooth/rfcomm/tty.c
Source file repositories/reference/linux-study-clean/net/bluetooth/rfcomm/tty.c
File Facts
- System
- Linux kernel
- Corpus path
net/bluetooth/rfcomm/tty.c- Extension
.c- Size
- 26344 bytes
- Lines
- 1149
- 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.
- 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/module.hlinux/tty.hlinux/tty_driver.hlinux/tty_flip.hnet/bluetooth/bluetooth.hnet/bluetooth/hci_core.hnet/bluetooth/rfcomm.h
Detected Declarations
struct rfcomm_devfunction rfcomm_dev_destructfunction rfcomm_dev_activatefunction rfcomm_dev_carrier_raisedfunction rfcomm_dev_shutdownfunction rfcomm_reparent_devicefunction address_showfunction channel_showfunction list_for_each_entryfunction list_for_each_entryfunction rfcomm_dev_addfunction rfcomm_roomfunction rfcomm_wfreefunction rfcomm_set_owner_wfunction __rfcomm_create_devfunction __rfcomm_release_devfunction rfcomm_create_devfunction rfcomm_release_devfunction rfcomm_get_dev_listfunction list_for_each_entryfunction rfcomm_get_dev_infofunction rfcomm_dev_ioctlfunction rfcomm_dev_data_readyfunction rfcomm_dev_state_changefunction rfcomm_dev_modem_statusfunction rfcomm_tty_copy_pendingfunction rfcomm_tty_cleanupfunction rfcomm_tty_installfunction rfcomm_tty_openfunction rfcomm_tty_closefunction rfcomm_tty_writefunction rfcomm_tty_write_roomfunction rfcomm_tty_ioctlfunction rfcomm_tty_set_termiosfunction rfcomm_tty_throttlefunction rfcomm_tty_unthrottlefunction rfcomm_tty_chars_in_bufferfunction rfcomm_tty_flush_bufferfunction rfcomm_tty_send_xcharfunction rfcomm_tty_wait_until_sentfunction rfcomm_tty_hangupfunction rfcomm_tty_tiocmgetfunction rfcomm_tty_tiocmsetfunction rfcomm_init_ttysfunction rfcomm_cleanup_ttys
Annotated Snippet
struct rfcomm_dev {
struct tty_port port;
struct list_head list;
char name[12];
int id;
unsigned long flags;
int err;
unsigned long status; /* don't export to userspace */
bdaddr_t src;
bdaddr_t dst;
u8 channel;
uint modem_status;
struct rfcomm_dlc *dlc;
struct device *tty_dev;
atomic_t wmem_alloc;
struct sk_buff_head pending;
};
static LIST_HEAD(rfcomm_dev_list);
static DEFINE_MUTEX(rfcomm_dev_lock);
static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
static void rfcomm_dev_modem_status(struct rfcomm_dlc *dlc, u8 v24_sig);
/* ---- Device functions ---- */
static void rfcomm_dev_destruct(struct tty_port *port)
{
struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
struct rfcomm_dlc *dlc = dev->dlc;
BT_DBG("dev %p dlc %p", dev, dlc);
rfcomm_dlc_lock(dlc);
/* Detach DLC if it's owned by this dev */
if (dlc->owner == dev)
dlc->owner = NULL;
rfcomm_dlc_unlock(dlc);
rfcomm_dlc_put(dlc);
if (dev->tty_dev)
tty_unregister_device(rfcomm_tty_driver, dev->id);
mutex_lock(&rfcomm_dev_lock);
list_del(&dev->list);
mutex_unlock(&rfcomm_dev_lock);
kfree(dev);
/* It's safe to call module_put() here because socket still
holds reference to this module. */
module_put(THIS_MODULE);
}
/* device-specific initialization: open the dlc */
static int rfcomm_dev_activate(struct tty_port *port, struct tty_struct *tty)
{
struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
int err;
err = rfcomm_dlc_open(dev->dlc, &dev->src, &dev->dst, dev->channel);
if (err)
set_bit(TTY_IO_ERROR, &tty->flags);
return err;
}
/* we block the open until the dlc->state becomes BT_CONNECTED */
static bool rfcomm_dev_carrier_raised(struct tty_port *port)
{
struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
return (dev->dlc->state == BT_CONNECTED);
}
/* device-specific cleanup: close the dlc */
static void rfcomm_dev_shutdown(struct tty_port *port)
{
struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
if (dev->tty_dev->parent)
Annotation
- Immediate include surface: `linux/module.h`, `linux/tty.h`, `linux/tty_driver.h`, `linux/tty_flip.h`, `net/bluetooth/bluetooth.h`, `net/bluetooth/hci_core.h`, `net/bluetooth/rfcomm.h`.
- Detected declarations: `struct rfcomm_dev`, `function rfcomm_dev_destruct`, `function rfcomm_dev_activate`, `function rfcomm_dev_carrier_raised`, `function rfcomm_dev_shutdown`, `function rfcomm_reparent_device`, `function address_show`, `function channel_show`, `function list_for_each_entry`, `function list_for_each_entry`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.