usbfs_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5pub mod types {
6    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
7}
8
9pub mod ioctl {
10    use nix::*;
11    use crate::types::*;
12
13    // see
14    //  - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/core/devio.c
15    //  - https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/usb.h
16    //  - https://kernel.readthedocs.io/en/sphinx-samples/usb.html#the-ioctl-requests
17    //  - https://stackoverflow.com/questions/11574418/how-to-get-usbs-urb-info-in-linux
18
19    // TODO: 32bit compat versions - but don't know what .h defines the structs
20
21    ioctl_read!(control, 'U', 0, ctrltransfer);
22    //ioctl_readwrite!(control32, 'U', 0, ctrltransfer32);
23    ioctl_read!(bulk, 'U', 2, bulktransfer);
24    //ioctl_readwrite!(bulk32, 'U', 2, bulktransfer32);
25    ioctl_read!(resetep, 'U', 3, ::std::os::raw::c_uint);
26    ioctl_read!(setinterface, 'U', 4, setinterface);
27    ioctl_read!(setconfiguration, 'U', 5, ::std::os::raw::c_uint);
28    ioctl_write_ptr!(getdriver, 'U', 8, getdriver);
29    ioctl_read!(submiturb, 'U', 10, urb);
30    //ioctl_read!(submiturb32, 'U', 10, urb32);
31    ioctl_none!(discardurb, 'U', 11);
32    ioctl_write_ptr!(reapurb, 'U', 12, *mut ::std::os::raw::c_void);
33    //ioctl_write_ptr!(reapurb32, 'U', 12, __u32);
34    ioctl_write_ptr!(reapurbndelay, 'U', 13, *mut ::std::os::raw::c_void);
35    //ioctl_write_ptr!(reapurbndelay32, 'U', 13, __u32);
36    ioctl_read!(discsignal, 'U', 14, disconnectsignal);
37    //ioctl_read!(discsignal32, 'U', 14, disconnectsignal32);
38    ioctl_read!(
39        /// Claim the interface with the given number for use via the given file descriptor.
40        ///
41        /// Will fail with `EBUSY` if some other claim is already in place (e.g. there is a kernel
42        /// driver already attached).
43        claiminterface, 'U', 15, ::std::os::raw::c_uint
44    );
45    ioctl_read!(
46        /// Release an interface previously claimed with `claiminterface()`.
47        releaseinterface, 'U', 16, ::std::os::raw::c_uint
48    );
49    ioctl_write_ptr!(connectinfo, 'U', 17, connectinfo);
50    ioctl_readwrite!(ioctl, 'U', 18, ioctl);
51    //ioctl_readwrite!(ioctl32, 'U', 18, ioctl32);
52    ioctl_read!(hub_portinfo, 'U', 19, hub_portinfo);
53    ioctl_none!(reset, 'U', 20);
54    ioctl_read!(clear_halt, 'U', 21, ::std::os::raw::c_uint);
55    // USBDEVFS_CONNECT and USBDEVFS_DISCONNECT are only used via USBDEVFS_IOCTL
56    pub unsafe fn disconnect(fd: ::std::os::raw::c_int, ifno: ::std::os::raw::c_int) -> Result<i32> {
57        let mut req = crate::types::ioctl {
58            ifno,
59            ioctl_code: request_code_none!('U', 22) as i32,
60            data: std::ptr::null_mut(),
61        };
62        ioctl(fd, &mut req)
63    }
64    pub unsafe fn connect(fd: ::std::os::raw::c_int, ifno: ::std::os::raw::c_int) -> Result<i32>{
65        let mut req = crate::types::ioctl {
66            ifno,
67            ioctl_code: request_code_none!('U', 23) as i32,
68            data: std::ptr::null_mut(),
69        };
70        ioctl(fd, &mut req)
71    }
72    ioctl_read!(claim_port, 'U', 24, ::std::os::raw::c_uint);
73    ioctl_read!(release_port, 'U', 25, ::std::os::raw::c_uint);
74    ioctl_read!(
75        /// returns a 32 bit mask describing the capabilities of this _usbdevfs_ device, as
76        /// described by the `CAP_*` constants.
77        get_capabilities, 'U', 26, __u32
78    );
79    ioctl_read!(disconnect_claim, 'U', 27, disconnect_claim);
80    ioctl_read!(alloc_streams, 'U', 28, streams);
81    ioctl_read!(free_streams, 'U', 29, streams);
82    ioctl_write_ptr!(drop_privileges, 'U', 30, __u32);
83}
84
85#[cfg(test)]
86mod tests {
87
88}