1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Transport abstractions for ADB connections.
//!
//! A transport is any type implementing `embedded_io_async::{Read, Write}`.
//! This module ships built-in TCP and USB transports and the [`Splittable`]
//! trait that powers [`Connection::split`](crate::Connection::split) for
//! concurrent read and write tasks on the same connection.
//!
//! # Submodules
//!
//! * [`tcp`] — `TokioTcp` / `SmolTcp` aliases (features `tokio` / `smol`)
//! and `BlockingTcp`, the socket `Inline` dials (feature `split`).
//! * `runtime` — the [`Runtime`](runtime::Runtime) trait, its `Tokio` /
//! `Smol` markers, so both runtimes can be compiled in at once, and
//! `Inline` for a build with neither.
//! * `nusb` — `UsbTransport` and the [`UsbBackend`] marker `Nusb`
//! (feature `nusb`, also enabled by the `usb` convenience alias).
//! * `rusb` — the same via libusb (feature `rusb`). Both backends can be
//! compiled in at once; pick one per call site through [`UsbBackend`].
//! * [`common`] — [`common::Transport`], a TCP-or-USB enum parameterised
//! over both halves, and [`common::NoUsb`] for builds with no backend.
//! * [`any`] — [`any::AnyTransport`] and [`any::connect`] for URI-based
//! dispatch between `tcp://` and `usb://` (feature `split`).
//! * [`split`] — the [`Splittable`] trait itself.
//! * [`uri`] — the parser for `tcp://` and `usb://` addresses; a `usb://`
//! one names the [`uri::UsbSelector`] a [`UsbBackend`] opens.
//! * `tls` — `MaybeTls`, a TCP transport that can start TLS when the
//! device sends `STLS`, and its split halves (feature `tls`).
pub use Splittable;
/// Whether a read can be left pending and dropped at no cost.
///
/// A socket read that is dropped leaves its bytes in the kernel buffer,
/// so the next read picks them up. A USB bulk transfer is handed to the
/// device: cancelling it discards whatever the device already wrote
/// into it, which takes the middle out of a packet and leaves every
/// frame boundary after it wrong. And a read that blocks the thread
/// cannot be raced at all, whatever becomes of its bytes: nothing else
/// gets polled until it returns, and by then there is nothing to drop.
///
/// [`Connection::select_channel`](crate::Connection::select_channel)
/// asks before it lets `interrupt` race a read in flight: a transport
/// that answers `false` gets the interrupt checked between reads
/// instead, which is slower to react but never loses a byte. So does
/// a [`Reader`](crate::Reader) that finds the connection cannot go on,
/// which is why a split read half has to say.
/// A USB backend: the way to obtain a USB transport from a
/// [`UsbSelector`](uri::UsbSelector).
///
/// Implemented by the zero-sized markers `nusb::Nusb` and `rusb::Rusb`,
/// and by [`common::NoUsb`] for builds without USB. Choosing a backend
/// is a type argument rather than a feature, so enabling both features
/// compiles and each call site says which one it wants.
/// `R` is the runtime the resulting transport will run its blocking
/// work on. A backend that has none — `nusb` does its own async IO —
/// simply ignores it, while `rusb` uses it for every transfer. Because
/// the runtime comes from the same place as the one dialling TCP, the
/// two cannot drift apart.
/// ADB USB interface class (vendor-specific).
pub const ADB_CLASS: u8 = 0xFF;
/// ADB USB interface subclass.
pub const ADB_SUBCLASS: u8 = 0x42;
/// ADB USB interface protocol.
pub const ADB_PROTOCOL: u8 = 0x01;