├── io-kit ├── LICENSE-MIT ├── LICENSE-APACHE ├── src │ ├── hid │ │ ├── mod.rs │ │ ├── value.rs │ │ ├── element.rs │ │ ├── manager.rs │ │ └── device.rs │ ├── lib.rs │ ├── mach.rs │ └── base.rs └── Cargo.toml ├── io-kit-sys ├── LICENSE-MIT ├── LICENSE-APACHE ├── src │ ├── pwr_mgt │ │ ├── mod.rs │ │ └── pm.rs │ ├── serial │ │ ├── mod.rs │ │ └── keys.rs │ ├── usb │ │ ├── mod.rs │ │ ├── lib.rs │ │ └── usb_spec.rs │ ├── ps │ │ ├── mod.rs │ │ ├── power_sources.rs │ │ └── keys.rs │ ├── hid │ │ ├── mod.rs │ │ ├── value.rs │ │ ├── base.rs │ │ ├── element.rs │ │ ├── manager.rs │ │ ├── device.rs │ │ └── keys.rs │ ├── base.rs │ ├── types.rs │ ├── ret.rs │ ├── keys.rs │ └── lib.rs ├── build.rs └── Cargo.toml ├── .gitignore ├── README.md ├── COPYRIGHT ├── Cargo.toml ├── LICENSE-MIT ├── .github └── workflows │ └── ci.yml ├── .typos.toml └── LICENSE-APACHE /io-kit/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /io-kit-sys/LICENSE-MIT: -------------------------------------------------------------------------------- 1 | ../LICENSE-MIT -------------------------------------------------------------------------------- /io-kit/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /io-kit-sys/LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | ../LICENSE-APACHE -------------------------------------------------------------------------------- /io-kit-sys/src/pwr_mgt/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod pm; 2 | -------------------------------------------------------------------------------- /io-kit-sys/src/serial/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod keys; 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | **/*.rs.bk 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /io-kit-sys/src/usb/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod lib; 2 | pub mod usb_spec; 3 | -------------------------------------------------------------------------------- /io-kit-sys/src/ps/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod keys; 2 | pub mod power_sources; 3 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod base; 2 | pub mod device; 3 | pub mod element; 4 | pub mod keys; 5 | pub mod manager; 6 | pub mod usage_tables; 7 | pub mod value; 8 | -------------------------------------------------------------------------------- /io-kit-sys/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | if std::env::var("TARGET").unwrap().contains("-apple") { 3 | println!("cargo:rustc-link-lib=framework=IOKit"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # io-kit-rs 2 | 3 | [![Build Status](https://github.com/jtakakura/io-kit-rs/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jtakakura/io-kit-rs/actions) 4 | -------------------------------------------------------------------------------- /io-kit/src/hid/mod.rs: -------------------------------------------------------------------------------- 1 | pub use io_kit_sys::hid::keys; 2 | pub use io_kit_sys::hid::usage_tables; 3 | 4 | pub mod device; 5 | pub mod element; 6 | pub mod manager; 7 | pub mod value; 8 | -------------------------------------------------------------------------------- /io-kit/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | #![allow(non_upper_case_globals)] 3 | 4 | #[macro_use(impl_TCFType)] 5 | extern crate core_foundation; 6 | extern crate mach2; 7 | 8 | extern crate io_kit_sys; 9 | 10 | pub use io_kit_sys::ret; 11 | 12 | pub mod base; 13 | pub mod hid; 14 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 or the MIT license 3 | , at your 4 | option. All files in the project carrying such notice may not be 5 | copied, modified, or distributed except according to those terms. 6 | -------------------------------------------------------------------------------- /io-kit-sys/src/usb/lib.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | pub const kIOUSBDeviceClassName: *const ::std::os::raw::c_char = 3 | b"IOUSBDevice\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 4 | pub const kIOUSBInterfaceClassName: *const ::std::os::raw::c_char = 5 | b"kIOUSBInterfaceClassName\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 6 | -------------------------------------------------------------------------------- /io-kit/src/hid/value.rs: -------------------------------------------------------------------------------- 1 | use core_foundation::base::{CFRelease, TCFType}; 2 | 3 | pub use io_kit_sys::hid::base::IOHIDValueRef; 4 | pub use io_kit_sys::hid::value::*; 5 | 6 | pub struct IOHIDValue(IOHIDValueRef); 7 | 8 | impl Drop for IOHIDValue { 9 | fn drop(&mut self) { 10 | unsafe { CFRelease(self.as_CFTypeRef()) } 11 | } 12 | } 13 | 14 | impl_TCFType!(IOHIDValue, IOHIDValueRef, IOHIDValueGetTypeID); 15 | -------------------------------------------------------------------------------- /io-kit-sys/src/base.rs: -------------------------------------------------------------------------------- 1 | use std::os::raw::c_uchar; 2 | 3 | // exports from `MacTypes.h` 4 | pub type Boolean = c_uchar; 5 | 6 | // exports from `libdispatch` 7 | #[repr(C)] 8 | #[derive(Debug, Copy)] 9 | pub struct dispatch_queue_s { 10 | _address: u8, 11 | } 12 | impl Clone for dispatch_queue_s { 13 | fn clone(&self) -> Self { 14 | *self 15 | } 16 | } 17 | pub type dispatch_queue_t = *mut dispatch_queue_s; 18 | -------------------------------------------------------------------------------- /io-kit/src/hid/element.rs: -------------------------------------------------------------------------------- 1 | use core_foundation::base::{CFRelease, TCFType}; 2 | 3 | pub use io_kit_sys::hid::base::IOHIDElementRef; 4 | pub use io_kit_sys::hid::element::*; 5 | 6 | pub struct IOHIDElement(IOHIDElementRef); 7 | 8 | impl Drop for IOHIDElement { 9 | fn drop(&mut self) { 10 | unsafe { CFRelease(self.as_CFTypeRef()) } 11 | } 12 | } 13 | 14 | impl_TCFType!(IOHIDElement, IOHIDElementRef, IOHIDElementGetTypeID); 15 | -------------------------------------------------------------------------------- /io-kit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "io-kit" 3 | version = "0.1.0" 4 | 5 | description.workspace = true 6 | authors.workspace = true 7 | edition.workspace = true 8 | license.workspace = true 9 | homepage.workspace = true 10 | repository.workspace = true 11 | categories.workspace = true 12 | keywords.workspace = true 13 | rust-version.workspace = true 14 | 15 | [dependencies] 16 | core-foundation = "0.10" 17 | io-kit-sys = { workspace = true } 18 | mach2 = { workspace = true } 19 | -------------------------------------------------------------------------------- /io-kit-sys/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "io-kit-sys" 3 | version = "0.5.0" 4 | links = "IOKit" 5 | build = "build.rs" 6 | 7 | description.workspace = true 8 | authors.workspace = true 9 | edition.workspace = true 10 | license.workspace = true 11 | homepage.workspace = true 12 | repository.workspace = true 13 | categories.workspace = true 14 | keywords.workspace = true 15 | rust-version.workspace = true 16 | 17 | [dependencies] 18 | core-foundation-sys = "0.8" 19 | mach2 = { workspace = true } 20 | -------------------------------------------------------------------------------- /io-kit/src/hid/manager.rs: -------------------------------------------------------------------------------- 1 | use core_foundation::base::{kCFAllocatorDefault, CFRelease, TCFType}; 2 | 3 | pub use io_kit_sys::hid::manager::*; 4 | 5 | pub struct IOHIDManager(IOHIDManagerRef); 6 | 7 | impl Drop for IOHIDManager { 8 | fn drop(&mut self) { 9 | unsafe { CFRelease(self.as_CFTypeRef()) } 10 | } 11 | } 12 | 13 | impl IOHIDManager { 14 | pub fn new() -> Option { 15 | let m = unsafe { IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDManagerOptionNone) }; 16 | 17 | if m.is_null() { 18 | None 19 | } else { 20 | Some(IOHIDManager(m)) 21 | } 22 | } 23 | } 24 | 25 | impl_TCFType!(IOHIDManager, IOHIDManagerRef, IOHIDManagerGetTypeID); 26 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["io-kit", "io-kit-sys"] 3 | resolver = "2" 4 | 5 | [workspace.package] 6 | description = "Bindings to IOKit for macOS" 7 | authors = ["Junji Takakura "] 8 | edition = "2021" 9 | license = "MIT OR Apache-2.0" 10 | homepage = "https://github.com/jtakakura/io-kit-rs" 11 | repository = "https://github.com/jtakakura/io-kit-rs" 12 | rust-version = "1.65" 13 | categories = ["api-bindings", "os::macos-apis"] 14 | keywords = ["iokit", "macos", "ffi", "hid", "usb"] 15 | 16 | [workspace.dependencies] 17 | io-kit = { default-features = false, path = "io-kit", version = "0.1" } 18 | io-kit-sys = { default-features = false, path = "io-kit-sys", version = "0.5" } 19 | mach2 = "0.5" 20 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2018 Junji Takakura 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | 2 | name: CI 3 | 4 | on: 5 | push: 6 | branches: [ main ] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | env: 11 | CARGO_TERM_COLOR: always 12 | RUSTFLAGS: "-D warnings" 13 | 14 | jobs: 15 | build: 16 | runs-on: ${{ matrix.os }} 17 | strategy: 18 | matrix: 19 | os: [macos-13, macos-14, macos-15] 20 | toolchain: [stable] 21 | include: 22 | - os: macos-14 23 | toolchain: "1.65.0" 24 | steps: 25 | - uses: actions/checkout@v4 26 | - name: Install toolchain 27 | uses: dtolnay/rust-toolchain@master 28 | with: 29 | toolchain: ${{ matrix.toolchain }} 30 | - name: check typos 31 | uses: crate-ci/typos@v1.29.4 32 | - name: Check semver 33 | continue-on-error: true 34 | uses: obi1kenobi/cargo-semver-checks-action@v2 35 | - name: Build 36 | run: cargo build --verbose 37 | - name: Run tests 38 | run: cargo test --verbose 39 | - name: Run clippy 40 | if: matrix.os == 'macos-14' && matrix.toolchain == 'stable' 41 | run: cargo clippy --all-targets --workspace 42 | -------------------------------------------------------------------------------- /io-kit-sys/src/serial/keys.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use ::std::os::raw::c_char; 4 | 5 | pub const kIOSerialBSDServiceValue: *const c_char = 6 | b"IOSerialBSDClient\0" as *const [u8; 18] as *const c_char; 7 | pub const kIOSerialBSDTypeKey: *const c_char = 8 | b"IOSerialBSDClientType\0" as *const [u8; 22] as *const c_char; 9 | pub const kIOSerialBSDAllTypes: *const c_char = 10 | b"IOSerialStream\0" as *const [u8; 15] as *const c_char; 11 | pub const kIOSerialBSDModemType: *const c_char = 12 | b"IOSerialStream\0" as *const [u8; 15] as *const c_char; 13 | pub const kIOSerialBSDRS232Type: *const c_char = 14 | b"IOSerialStream\0" as *const [u8; 15] as *const c_char; 15 | pub const kIOTTYDeviceKey: *const c_char = b"IOTTYDevice\0" as *const [u8; 12] as *const c_char; 16 | pub const kIOTTYBaseNameKey: *const c_char = b"IOTTYBaseName\0" as *const [u8; 14] as *const c_char; 17 | pub const kIOTTYSuffixKey: *const c_char = b"IOTTYSuffix\0" as *const [u8; 12] as *const c_char; 18 | pub const kIOCalloutDeviceKey: *const c_char = 19 | b"IOCalloutDevice\0" as *const [u8; 16] as *const c_char; 20 | pub const kIODialinDeviceKey: *const c_char = 21 | b"IODialinDevice\0" as *const [u8; 15] as *const c_char; 22 | pub const kIOTTYWaitForIdleKey: *const c_char = 23 | b"IOTTYWaitForIdle\0" as *const [u8; 17] as *const c_char; 24 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/value.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFTypeID}; 4 | 5 | use crate::hid::{ 6 | base::{IOHIDElementRef, IOHIDValueRef}, 7 | keys::IOHIDValueScaleType, 8 | }; 9 | 10 | extern "C" { 11 | pub fn IOHIDValueGetTypeID() -> CFTypeID; 12 | 13 | pub fn IOHIDValueCreateWithIntegerValue( 14 | allocator: CFAllocatorRef, 15 | element: IOHIDElementRef, 16 | timeStamp: u64, 17 | value: CFIndex, 18 | ) -> IOHIDValueRef; 19 | 20 | pub fn IOHIDValueCreateWithBytes( 21 | allocator: CFAllocatorRef, 22 | element: IOHIDElementRef, 23 | timeStamp: u64, 24 | bytes: *const u8, 25 | length: CFIndex, 26 | ) -> IOHIDValueRef; 27 | 28 | pub fn IOHIDValueCreateWithBytesNoCopy( 29 | allocator: CFAllocatorRef, 30 | element: IOHIDElementRef, 31 | timeStamp: u64, 32 | bytes: *const u8, 33 | length: CFIndex, 34 | ) -> IOHIDValueRef; 35 | 36 | pub fn IOHIDValueGetElement(value: IOHIDValueRef) -> IOHIDElementRef; 37 | 38 | pub fn IOHIDValueGetTimeStamp(value: IOHIDValueRef) -> u64; 39 | 40 | pub fn IOHIDValueGetLength(value: IOHIDValueRef) -> CFIndex; 41 | 42 | pub fn IOHIDValueGetBytePtr(value: IOHIDValueRef) -> *const u8; 43 | 44 | pub fn IOHIDValueGetIntegerValue(value: IOHIDValueRef) -> CFIndex; 45 | 46 | pub fn IOHIDValueGetScaledValue(value: IOHIDValueRef, type_: IOHIDValueScaleType) -> f64; 47 | } 48 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/base.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use std::os::raw::c_void; 4 | 5 | use core_foundation_sys::base::CFIndex; 6 | use core_foundation_sys::dictionary::CFDictionaryRef; 7 | 8 | use crate::{hid::keys::IOHIDReportType, ret::IOReturn}; 9 | 10 | #[repr(C)] 11 | #[derive(Debug, Copy, Clone)] 12 | pub struct __IOHIDDevice { 13 | _unused: [u8; 0], 14 | } 15 | pub type IOHIDDeviceRef = *mut __IOHIDDevice; 16 | 17 | #[repr(C)] 18 | #[derive(Debug, Copy, Clone)] 19 | pub struct __IOHIDElement { 20 | _unused: [u8; 0], 21 | } 22 | pub type IOHIDElementRef = *mut __IOHIDElement; 23 | 24 | #[repr(C)] 25 | #[derive(Debug, Copy, Clone)] 26 | pub struct __IOHIDValue { 27 | _unused: [u8; 0], 28 | } 29 | pub type IOHIDValueRef = *mut __IOHIDValue; 30 | 31 | pub const kIOHIDTransactionDirectionTypeInput: u32 = 0; 32 | pub const kIOHIDTransactionDirectionTypeOutput: u32 = 1; 33 | 34 | pub const kIOHIDTransactionOptionDefaultOutputValue: u32 = 0x0001; 35 | 36 | pub type IOHIDCallback = 37 | Option; 38 | 39 | pub type IOHIDReportCallback = Option< 40 | unsafe extern "C" fn( 41 | context: *mut c_void, 42 | result: IOReturn, 43 | sender: *mut c_void, 44 | type_: IOHIDReportType, 45 | reportID: u32, 46 | report: *mut u8, 47 | reportLength: CFIndex, 48 | ), 49 | >; 50 | pub type IOHIDReportWithTimeStampCallback = Option< 51 | unsafe extern "C" fn( 52 | context: *mut c_void, 53 | result: IOReturn, 54 | sender: *mut c_void, 55 | type_: IOHIDReportType, 56 | reportID: u32, 57 | report: *mut u8, 58 | reportLength: CFIndex, 59 | timeStamp: u64, 60 | ), 61 | >; 62 | 63 | pub type IOHIDValueCallback = Option< 64 | unsafe extern "C" fn( 65 | context: *mut c_void, 66 | result: IOReturn, 67 | sender: *mut c_void, 68 | value: IOHIDValueRef, 69 | ), 70 | >; 71 | 72 | pub type IOHIDValueMultipleCallback = Option< 73 | unsafe extern "C" fn( 74 | context: *mut c_void, 75 | result: IOReturn, 76 | sender: *mut c_void, 77 | multiple: CFDictionaryRef, 78 | ), 79 | >; 80 | 81 | pub type IOHIDDeviceCallback = Option< 82 | unsafe extern "C" fn( 83 | context: *mut c_void, 84 | result: IOReturn, 85 | sender: *mut c_void, 86 | device: IOHIDDeviceRef, 87 | ), 88 | >; 89 | -------------------------------------------------------------------------------- /io-kit/src/hid/device.rs: -------------------------------------------------------------------------------- 1 | use std::os::raw::c_char; 2 | 3 | use core_foundation::base::{kCFAllocatorDefault, CFRelease, CFType, CFTypeID, TCFType}; 4 | 5 | pub use io_kit_sys::hid::base::IOHIDDeviceRef; 6 | pub use io_kit_sys::hid::device::*; 7 | use io_kit_sys::hid::keys::kIOHIDOptionsTypeNone; 8 | use io_kit_sys::CFSTR; 9 | 10 | use crate::{ 11 | base::{IOService, TIOObject}, 12 | ret::{kIOReturnSuccess, IOReturn}, 13 | }; 14 | 15 | pub struct IOHIDDevice(IOHIDDeviceRef); 16 | 17 | impl Drop for IOHIDDevice { 18 | fn drop(&mut self) { 19 | unsafe { CFRelease(self.as_CFTypeRef()) } 20 | } 21 | } 22 | 23 | impl IOHIDDevice { 24 | pub fn get_type_id() -> CFTypeID { 25 | unsafe { IOHIDDeviceGetTypeID() } 26 | } 27 | 28 | pub fn create(service: IOService) -> Option { 29 | unsafe { 30 | let result = IOHIDDeviceCreate(kCFAllocatorDefault, service.as_io_object_t()); 31 | 32 | if result.is_null() { 33 | None 34 | } else { 35 | Some(IOHIDDevice(result)) 36 | } 37 | } 38 | } 39 | 40 | pub fn open(&self) -> Result<(), IOReturn> { 41 | unsafe { 42 | let result = IOHIDDeviceOpen(self.0, kIOHIDOptionsTypeNone); 43 | 44 | if result == kIOReturnSuccess { 45 | Ok(()) 46 | } else { 47 | Err(result) 48 | } 49 | } 50 | } 51 | 52 | pub fn close(&self) -> Result<(), IOReturn> { 53 | unsafe { 54 | let result = IOHIDDeviceClose(self.0, kIOHIDOptionsTypeNone); 55 | 56 | if result == kIOReturnSuccess { 57 | Ok(()) 58 | } else { 59 | Err(result) 60 | } 61 | } 62 | } 63 | 64 | pub fn conforms_to(&self, usage_page: u32, usage: u32) -> bool { 65 | unsafe { IOHIDDeviceConformsTo(self.0, usage_page, usage) != 0 } 66 | } 67 | 68 | /// Gets a property from the device for the given key. 69 | /// 70 | /// # Safety 71 | /// 72 | /// The caller must ensure that `key` is a valid, null-terminated C string. 73 | pub unsafe fn get_property(&self, key: *const c_char) -> Option { 74 | let result = IOHIDDeviceGetProperty(self.0, CFSTR(key)); 75 | 76 | if result.is_null() { 77 | None 78 | } else { 79 | Some(TCFType::wrap_under_get_rule(result)) 80 | } 81 | } 82 | } 83 | 84 | impl_TCFType!(IOHIDDevice, IOHIDDeviceRef, IOHIDDeviceGetTypeID); 85 | -------------------------------------------------------------------------------- /io-kit-sys/src/ps/power_sources.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use core_foundation_sys::array::CFArrayRef; 4 | use core_foundation_sys::base::CFTypeRef; 5 | use core_foundation_sys::dictionary::CFDictionaryRef; 6 | use core_foundation_sys::runloop::CFRunLoopSourceRef; 7 | use core_foundation_sys::string::CFStringRef; 8 | 9 | // Low Power Warnings 10 | pub const kIOPSNotifyLowBattery: *const ::std::os::raw::c_char = 11 | b"com.apple.system.powersources.lowbattery\0" as *const [u8; 41usize] 12 | as *const ::std::os::raw::c_char; 13 | 14 | pub type IOPSLowBatteryWarningLevel = u32; 15 | pub const kIOPSLowBatteryWarningNone: IOPSLowBatteryWarningLevel = 1; 16 | pub const kIOPSLowBatteryWarningEarly: IOPSLowBatteryWarningLevel = 2; 17 | pub const kIOPSLowBatteryWarningFinal: IOPSLowBatteryWarningLevel = 3; 18 | 19 | pub const kIOPSNotifyTimeRemaining: *const ::std::os::raw::c_char = 20 | b"com.apple.system.powersources.timeremaining\0" as *const [u8; 44usize] 21 | as *const ::std::os::raw::c_char; 22 | pub const kIOPSTimeRemainingNotificationKey: *const ::std::os::raw::c_char = 23 | kIOPSNotifyTimeRemaining as *const [u8; 44usize] as *const ::std::os::raw::c_char; 24 | pub const kIOPSNotifyPowerSource: *const ::std::os::raw::c_char = 25 | b"com.apple.system.powersources.source\0" as *const [u8; 37usize] 26 | as *const ::std::os::raw::c_char; 27 | pub const kIOPSNotifyAttach: *const ::std::os::raw::c_char = 28 | b"com.apple.system.powersources.attach\0" as *const [u8; 37usize] 29 | as *const ::std::os::raw::c_char; 30 | pub const kIOPSNotifyAnyPowerSource: *const ::std::os::raw::c_char = 31 | b"com.apple.system.powersources\0" as *const [u8; 30usize] as *const ::std::os::raw::c_char; 32 | pub const kIOPMUPSPowerKey: *const ::std::os::raw::c_char = 33 | b"UPS Power\0" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 34 | pub const kIOPMBatteryPowerKey: *const ::std::os::raw::c_char = 35 | b"Battery Power\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 36 | pub const kIOPMACPowerKey: *const ::std::os::raw::c_char = 37 | b"AC Power\0" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 38 | 39 | pub type IOPowerSourceCallbackType = unsafe extern "C" fn(context: *mut ::std::os::raw::c_void); 40 | 41 | extern "C" { 42 | pub fn IOPSGetBatteryWarningLevel() -> IOPSLowBatteryWarningLevel; 43 | pub fn IOPSCopyPowerSourcesInfo() -> CFTypeRef; 44 | pub fn IOPSCopyPowerSourcesList(blob: CFTypeRef) -> CFArrayRef; 45 | pub fn IOPSGetPowerSourceDescription(blob: CFTypeRef, ps: CFTypeRef) -> CFDictionaryRef; 46 | pub fn IOPSGetProvidingPowerSourceType(snapshot: CFTypeRef) -> CFStringRef; 47 | pub fn IOPSNotificationCreateRunLoopSource( 48 | callback: IOPowerSourceCallbackType, 49 | context: *mut ::std::os::raw::c_void, 50 | ) -> CFRunLoopSourceRef; 51 | pub fn IOPSCreateLimitedPowerNotification( 52 | callback: IOPowerSourceCallbackType, 53 | context: *mut ::std::os::raw::c_void, 54 | ) -> CFRunLoopSourceRef; 55 | pub fn IOPSCopyExternalPowerAdapterDetails() -> CFDictionaryRef; 56 | } 57 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/element.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use core_foundation_sys::array::CFArrayRef; 4 | use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFTypeID, CFTypeRef}; 5 | use core_foundation_sys::dictionary::CFDictionaryRef; 6 | use core_foundation_sys::string::CFStringRef; 7 | 8 | use crate::{ 9 | base::Boolean, 10 | hid::{ 11 | base::{IOHIDDeviceRef, IOHIDElementRef}, 12 | keys::{IOHIDElementCollectionType, IOHIDElementCookie, IOHIDElementType}, 13 | }, 14 | }; 15 | 16 | extern "C" { 17 | pub fn IOHIDElementGetTypeID() -> CFTypeID; 18 | 19 | pub fn IOHIDElementCreateWithDictionary( 20 | allocator: CFAllocatorRef, 21 | dictionary: CFDictionaryRef, 22 | ) -> IOHIDElementRef; 23 | 24 | pub fn IOHIDElementGetDevice(element: IOHIDElementRef) -> IOHIDDeviceRef; 25 | 26 | pub fn IOHIDElementGetParent(element: IOHIDElementRef) -> IOHIDElementRef; 27 | 28 | pub fn IOHIDElementGetChildren(element: IOHIDElementRef) -> CFArrayRef; 29 | 30 | pub fn IOHIDElementAttach(element: IOHIDElementRef, toAttach: IOHIDElementRef); 31 | 32 | pub fn IOHIDElementDetach(element: IOHIDElementRef, toDetach: IOHIDElementRef); 33 | 34 | pub fn IOHIDElementCopyAttached(element: IOHIDElementRef) -> CFArrayRef; 35 | 36 | pub fn IOHIDElementGetCookie(element: IOHIDElementRef) -> IOHIDElementCookie; 37 | 38 | pub fn IOHIDElementGetType(element: IOHIDElementRef) -> IOHIDElementType; 39 | 40 | pub fn IOHIDElementGetCollectionType(element: IOHIDElementRef) -> IOHIDElementCollectionType; 41 | 42 | pub fn IOHIDElementGetUsagePage(element: IOHIDElementRef) -> u32; 43 | 44 | pub fn IOHIDElementGetUsage(element: IOHIDElementRef) -> u32; 45 | 46 | pub fn IOHIDElementIsVirtual(element: IOHIDElementRef) -> Boolean; 47 | 48 | pub fn IOHIDElementIsRelative(element: IOHIDElementRef) -> Boolean; 49 | 50 | pub fn IOHIDElementIsWrapping(element: IOHIDElementRef) -> Boolean; 51 | 52 | pub fn IOHIDElementIsArray(element: IOHIDElementRef) -> Boolean; 53 | 54 | pub fn IOHIDElementIsNonLinear(element: IOHIDElementRef) -> Boolean; 55 | 56 | pub fn IOHIDElementHasPreferredState(element: IOHIDElementRef) -> Boolean; 57 | 58 | pub fn IOHIDElementHasNullState(element: IOHIDElementRef) -> Boolean; 59 | 60 | pub fn IOHIDElementGetName(element: IOHIDElementRef) -> CFStringRef; 61 | 62 | pub fn IOHIDElementGetReportID(element: IOHIDElementRef) -> u32; 63 | 64 | pub fn IOHIDElementGetReportSize(element: IOHIDElementRef) -> u32; 65 | 66 | pub fn IOHIDElementGetReportCount(element: IOHIDElementRef) -> u32; 67 | 68 | pub fn IOHIDElementGetUnit(element: IOHIDElementRef) -> u32; 69 | 70 | pub fn IOHIDElementGetUnitExponent(element: IOHIDElementRef) -> u32; 71 | 72 | pub fn IOHIDElementGetLogicalMin(element: IOHIDElementRef) -> CFIndex; 73 | 74 | pub fn IOHIDElementGetLogicalMax(element: IOHIDElementRef) -> CFIndex; 75 | 76 | pub fn IOHIDElementGetPhysicalMin(element: IOHIDElementRef) -> CFIndex; 77 | 78 | pub fn IOHIDElementGetPhysicalMax(element: IOHIDElementRef) -> CFIndex; 79 | 80 | pub fn IOHIDElementGetProperty(element: IOHIDElementRef, key: CFStringRef) -> CFTypeRef; 81 | 82 | pub fn IOHIDElementSetProperty( 83 | element: IOHIDElementRef, 84 | key: CFStringRef, 85 | property: CFTypeRef, 86 | ) -> Boolean; 87 | } 88 | -------------------------------------------------------------------------------- /io-kit-sys/src/usb/usb_spec.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | pub const kUSBDeviceClass: *const ::std::os::raw::c_char = 4 | b"bDeviceClass\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 5 | pub const kUSBDeviceSubClass: *const ::std::os::raw::c_char = 6 | b"bDeviceSubClass\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 7 | pub const kUSBDeviceProtocol: *const ::std::os::raw::c_char = 8 | b"bDeviceProtocol\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 9 | pub const kUSBDeviceMaxPacketSize: *const ::std::os::raw::c_char = 10 | b"bMaxPacketSize0\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 11 | pub const kUSBVendorID: *const ::std::os::raw::c_char = 12 | b"idVendor\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 13 | pub const kUSBVendorName: *const ::std::os::raw::c_char = kUSBVendorID; 14 | pub const kUSBProductID: *const ::std::os::raw::c_char = 15 | b"idProduct\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 16 | pub const kUSBProductName: *const ::std::os::raw::c_char = kUSBProductID; 17 | pub const kUSBDeviceReleaseNumber: *const ::std::os::raw::c_char = 18 | b"bcdDevice\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 19 | pub const kUSBManufacturerStringIndex: *const ::std::os::raw::c_char = 20 | b"iManufacturer\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 21 | pub const kUSBProductStringIndex: *const ::std::os::raw::c_char = 22 | b"iProduct\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 23 | pub const kUSBSerialNumberStringIndex: *const ::std::os::raw::c_char = 24 | b"iSerialNumber\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 25 | pub const kUSBDeviceNumConfigs: *const ::std::os::raw::c_char = 26 | b"bNumConfigurations\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 27 | pub const kUSBInterfaceNumber: *const ::std::os::raw::c_char = 28 | b"bInterfaceNumber\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 29 | pub const kUSBAlternateSetting: *const ::std::os::raw::c_char = 30 | b"bAlternateSetting\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 31 | pub const kUSBNumEndpoints: *const ::std::os::raw::c_char = 32 | b"bNumEndpoints\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 33 | pub const kUSBInterfaceClass: *const ::std::os::raw::c_char = 34 | b"bInterfaceClass\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 35 | pub const kUSBInterfaceSubClass: *const ::std::os::raw::c_char = 36 | b"bInterfaceSubClass\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 37 | pub const kUSBInterfaceProtocol: *const ::std::os::raw::c_char = 38 | b"bInterfaceProtocol\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 39 | pub const kUSBInterfaceStringIndex: *const ::std::os::raw::c_char = 40 | b"iInterface\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 41 | pub const kUSBConfigurationValue: *const ::std::os::raw::c_char = 42 | b"bConfigurationValue\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 43 | pub const kUSBProductString: *const ::std::os::raw::c_char = 44 | b"USB Product Name\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 45 | pub const kUSBVendorString: *const ::std::os::raw::c_char = 46 | b"USB Vendor Name\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 47 | pub const kUSBSerialNumberString: *const ::std::os::raw::c_char = 48 | b"USB Serial Number\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 49 | pub const kUSB1284DeviceID: *const ::std::os::raw::c_char = 50 | b"1284 Device ID\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 51 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/manager.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use std::os::raw::c_void; 4 | 5 | use core_foundation_sys::array::CFArrayRef; 6 | use core_foundation_sys::base::{CFAllocatorRef, CFTypeID, CFTypeRef}; 7 | use core_foundation_sys::dictionary::CFDictionaryRef; 8 | use core_foundation_sys::runloop::CFRunLoopRef; 9 | use core_foundation_sys::set::CFSetRef; 10 | use core_foundation_sys::string::CFStringRef; 11 | 12 | use crate::{ 13 | base::Boolean, 14 | hid::base::{IOHIDDeviceCallback, IOHIDReportCallback, IOHIDValueCallback}, 15 | ret::IOReturn, 16 | types::IOOptionBits, 17 | }; 18 | 19 | pub type IOHIDManagerOptions = IOOptionBits; 20 | pub const kIOHIDManagerOptionNone: IOHIDManagerOptions = 0x0; 21 | pub const kIOHIDManagerOptionUsePersistentProperties: IOHIDManagerOptions = 0x1; 22 | pub const kIOHIDManagerOptionDoNotLoadProperties: IOHIDManagerOptions = 0x2; 23 | pub const kIOHIDManagerOptionDoNotSaveProperties: IOHIDManagerOptions = 0x4; 24 | 25 | #[repr(C)] 26 | #[derive(Debug, Copy, Clone)] 27 | pub struct __IOHIDManager { 28 | _unused: [u8; 0], 29 | } 30 | pub type IOHIDManagerRef = *mut __IOHIDManager; 31 | 32 | extern "C" { 33 | pub fn IOHIDManagerGetTypeID() -> CFTypeID; 34 | 35 | pub fn IOHIDManagerCreate( 36 | allocator: CFAllocatorRef, 37 | options: IOHIDManagerOptions, 38 | ) -> IOHIDManagerRef; 39 | 40 | pub fn IOHIDManagerOpen(manager: IOHIDManagerRef, options: IOHIDManagerOptions) -> IOReturn; 41 | 42 | pub fn IOHIDManagerClose(manager: IOHIDManagerRef, options: IOHIDManagerOptions) -> IOReturn; 43 | 44 | pub fn IOHIDManagerGetProperty(manager: IOHIDManagerRef, key: CFStringRef) -> CFTypeRef; 45 | 46 | pub fn IOHIDManagerSetProperty( 47 | manager: IOHIDManagerRef, 48 | key: CFStringRef, 49 | value: CFTypeRef, 50 | ) -> Boolean; 51 | 52 | pub fn IOHIDManagerScheduleWithRunLoop( 53 | manager: IOHIDManagerRef, 54 | runLoop: CFRunLoopRef, 55 | runLoopMode: CFStringRef, 56 | ); 57 | 58 | pub fn IOHIDManagerUnscheduleFromRunLoop( 59 | manager: IOHIDManagerRef, 60 | runLoop: CFRunLoopRef, 61 | runLoopMode: CFStringRef, 62 | ); 63 | 64 | pub fn IOHIDManagerSetDeviceMatching(manager: IOHIDManagerRef, matching: CFDictionaryRef); 65 | 66 | pub fn IOHIDManagerSetDeviceMatchingMultiple(manager: IOHIDManagerRef, multiple: CFArrayRef); 67 | 68 | pub fn IOHIDManagerCopyDevices(manager: IOHIDManagerRef) -> CFSetRef; 69 | 70 | pub fn IOHIDManagerRegisterDeviceMatchingCallback( 71 | manager: IOHIDManagerRef, 72 | callback: IOHIDDeviceCallback, 73 | context: *mut c_void, 74 | ); 75 | 76 | pub fn IOHIDManagerRegisterDeviceRemovalCallback( 77 | manager: IOHIDManagerRef, 78 | callback: IOHIDDeviceCallback, 79 | context: *mut c_void, 80 | ); 81 | 82 | pub fn IOHIDManagerRegisterInputReportCallback( 83 | manager: IOHIDManagerRef, 84 | callback: IOHIDReportCallback, 85 | context: *mut c_void, 86 | ); 87 | 88 | pub fn IOHIDManagerRegisterInputValueCallback( 89 | manager: IOHIDManagerRef, 90 | callback: IOHIDValueCallback, 91 | context: *mut c_void, 92 | ); 93 | 94 | pub fn IOHIDManagerSetInputValueMatching(manager: IOHIDManagerRef, matching: CFDictionaryRef); 95 | 96 | pub fn IOHIDManagerSetInputValueMatchingMultiple( 97 | manager: IOHIDManagerRef, 98 | multiple: CFArrayRef, 99 | ); 100 | 101 | pub fn IOHIDManagerSaveToPropertyDomain( 102 | manager: IOHIDManagerRef, 103 | applicationID: CFStringRef, 104 | userName: CFStringRef, 105 | hostName: CFStringRef, 106 | options: IOOptionBits, 107 | ); 108 | } 109 | -------------------------------------------------------------------------------- /.typos.toml: -------------------------------------------------------------------------------- 1 | [files] 2 | extend-exclude = [] 3 | ignore-hidden = true 4 | ignore-files = true 5 | ignore-dot = true 6 | ignore-vcs = true 7 | ignore-global = true 8 | ignore-parent = true 9 | 10 | [default] 11 | binary = false 12 | check-filename = true 13 | check-file = true 14 | unicode = true 15 | ignore-hex = true 16 | identifier-leading-digits = false 17 | locale = "en" 18 | extend-ignore-identifiers-re = [] 19 | extend-ignore-words-re = [] 20 | extend-ignore-re = [] 21 | 22 | [default.extend-identifiers] 23 | TIOObject = "TIOObject" 24 | 25 | [default.extend-words] 26 | AFE = "AFE" 27 | Atrribute = "Atrribute" 28 | Browswer = "Browswer" 29 | Disharge = "Disharge" 30 | Grammer = "Grammer" 31 | Rechargable = "Rechargable" 32 | managment = "managment" 33 | 34 | [type.lock] 35 | extend-glob = [] 36 | check-file = false 37 | extend-ignore-identifiers-re = [] 38 | extend-ignore-words-re = [] 39 | extend-ignore-re = [] 40 | 41 | [type.lock.extend-identifiers] 42 | 43 | [type.lock.extend-words] 44 | 45 | [type.jl] 46 | extend-glob = [] 47 | extend-ignore-identifiers-re = [] 48 | extend-ignore-words-re = [] 49 | extend-ignore-re = [] 50 | 51 | [type.jl.extend-identifiers] 52 | 53 | [type.jl.extend-words] 54 | modul = "modul" 55 | egal = "egal" 56 | egals = "egals" 57 | usig = "usig" 58 | 59 | [type.rust] 60 | extend-glob = [] 61 | extend-ignore-identifiers-re = [] 62 | extend-ignore-words-re = [] 63 | extend-ignore-re = [] 64 | 65 | [type.rust.extend-identifiers] 66 | ratatui = "ratatui" 67 | flate2 = "flate2" 68 | 69 | [type.rust.extend-words] 70 | ser = "ser" 71 | 72 | [type.bitbake] 73 | extend-glob = [] 74 | extend-ignore-identifiers-re = [] 75 | extend-ignore-words-re = [] 76 | extend-ignore-re = [] 77 | 78 | [type.bitbake.extend-identifiers] 79 | 80 | [type.bitbake.extend-words] 81 | PN = "PN" 82 | 83 | [type.css] 84 | extend-glob = [] 85 | extend-ignore-identifiers-re = [] 86 | extend-ignore-words-re = [] 87 | extend-ignore-re = [] 88 | 89 | [type.css.extend-identifiers] 90 | nd = "nd" 91 | 92 | [type.css.extend-words] 93 | 94 | [type.py] 95 | extend-glob = [] 96 | extend-ignore-identifiers-re = [] 97 | extend-ignore-words-re = [] 98 | extend-ignore-re = [] 99 | 100 | [type.py.extend-identifiers] 101 | arange = "arange" 102 | EOFError = "EOFError" 103 | NDArray = "NDArray" 104 | 105 | [type.py.extend-words] 106 | 107 | [type.cert] 108 | extend-glob = [] 109 | check-file = false 110 | extend-ignore-identifiers-re = [] 111 | extend-ignore-words-re = [] 112 | extend-ignore-re = [] 113 | 114 | [type.cert.extend-identifiers] 115 | 116 | [type.cert.extend-words] 117 | 118 | [type.man] 119 | extend-glob = [] 120 | extend-ignore-identifiers-re = [] 121 | extend-ignore-words-re = [] 122 | extend-ignore-re = [] 123 | 124 | [type.man.extend-identifiers] 125 | Nd = "Nd" 126 | 127 | [type.man.extend-words] 128 | 129 | [type.go] 130 | extend-glob = [] 131 | extend-ignore-identifiers-re = [] 132 | extend-ignore-words-re = [] 133 | extend-ignore-re = [] 134 | 135 | [type.go.extend-identifiers] 136 | Rela32 = "Rela32" 137 | NewCFBEncrypter = "NewCFBEncrypter" 138 | TLS_RSA_WITH_3DES_EDE_CBC_SHA = "TLS_RSA_WITH_3DES_EDE_CBC_SHA" 139 | NewCBCEncrypter = "NewCBCEncrypter" 140 | flate = "flate" 141 | TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" 142 | O_WRONLY = "O_WRONLY" 143 | Rela64 = "Rela64" 144 | NOTE_FFOR = "NOTE_FFOR" 145 | 146 | [type.go.extend-words] 147 | 148 | [type.sh] 149 | extend-glob = [] 150 | extend-ignore-identifiers-re = [] 151 | extend-ignore-words-re = [] 152 | extend-ignore-re = [] 153 | 154 | [type.sh.extend-identifiers] 155 | ot = "ot" 156 | stap = "stap" 157 | 158 | [type.sh.extend-words] 159 | 160 | [type.vimscript] 161 | extend-glob = [] 162 | extend-ignore-identifiers-re = [] 163 | extend-ignore-words-re = [] 164 | extend-ignore-re = [] 165 | 166 | [type.vimscript.extend-identifiers] 167 | windo = "windo" 168 | 169 | [type.vimscript.extend-words] 170 | 171 | [type.cpp] 172 | extend-glob = [] 173 | extend-ignore-identifiers-re = [] 174 | extend-ignore-words-re = [] 175 | extend-ignore-re = [] 176 | 177 | [type.cpp.extend-identifiers] 178 | countr_one = "countr_one" 179 | 180 | [type.cpp.extend-words] 181 | -------------------------------------------------------------------------------- /io-kit/src/mach.rs: -------------------------------------------------------------------------------- 1 | use io_kit_sys::base::*; 2 | use io_kit_sys::mach_sys::kern_return_t; 3 | 4 | #[derive(Clone, Copy, Debug, PartialEq)] 5 | pub enum KernReturn { 6 | Success, 7 | InvalidAddress, 8 | ProtectionFailure, 9 | NoSpace, 10 | InvalidArgument, 11 | Failure, 12 | ResourceShortage, 13 | NotReceiver, 14 | NoAccess, 15 | MemoryFailure, 16 | MemoryError, 17 | AlreadyInSet, 18 | NotInSet, 19 | NameExists, 20 | Aborted, 21 | InvalidName, 22 | InvalidTask, 23 | InvalidRight, 24 | InvalidValue, 25 | UrefsOverflow, 26 | InvalidCapability, 27 | RightExists, 28 | InvalidHost, 29 | MemoryPresent, 30 | MemoryDataMoved, 31 | MemoryRestartCopy, 32 | InvalidProcessorSet, 33 | PolicyLimit, 34 | InvalidPolicy, 35 | InvalidObject, 36 | AlreadyWaiting, 37 | DefaultSet, 38 | ExceptionProtected, 39 | InvalidLedger, 40 | InvalidMemoryControl, 41 | InvalidSecurity, 42 | NotDepressed, 43 | Terminated, 44 | LockSetDestroyed, 45 | LockUnstable, 46 | LockOwned, 47 | LockOwnedSelf, 48 | SemaphoreDestroyed, 49 | RpcServerTerminated, 50 | RpcTerminateOrphan, 51 | RpcContinueOrphan, 52 | NotSupported, 53 | NodeDown, 54 | NotWaiting, 55 | OperationTimedOut, 56 | ReturnMax, 57 | Unknown(kern_return_t), 58 | } 59 | 60 | impl From for KernReturn { 61 | fn from(code: kern_return_t) -> KernReturn { 62 | match code { 63 | KERN_SUCCESS => KernReturn::Success, 64 | KERN_INVALID_ADDRESS => KernReturn::InvalidAddress, 65 | KERN_PROTECTION_FAILURE => KernReturn::ProtectionFailure, 66 | KERN_NO_SPACE => KernReturn::NoSpace, 67 | KERN_INVALID_ARGUMENT => KernReturn::InvalidArgument, 68 | KERN_FAILURE => KernReturn::Failure, 69 | KERN_RESOURCE_SHORTAGE => KernReturn::ResourceShortage, 70 | KERN_NOT_RECEIVER => KernReturn::NotReceiver, 71 | KERN_NO_ACCESS => KernReturn::NoAccess, 72 | KERN_MEMORY_FAILURE => KernReturn::MemoryFailure, 73 | KERN_MEMORY_ERROR => KernReturn::MemoryError, 74 | KERN_ALREADY_IN_SET => KernReturn::AlreadyInSet, 75 | KERN_NOT_IN_SET => KernReturn::NotInSet, 76 | KERN_NAME_EXISTS => KernReturn::NameExists, 77 | KERN_ABORTED => KernReturn::Aborted, 78 | KERN_INVALID_NAME => KernReturn::InvalidName, 79 | KERN_INVALID_TASK => KernReturn::InvalidTask, 80 | KERN_INVALID_RIGHT => KernReturn::InvalidRight, 81 | KERN_INVALID_VALUE => KernReturn::InvalidValue, 82 | KERN_UREFS_OVERFLOW => KernReturn::UrefsOverflow, 83 | KERN_INVALID_CAPABILITY => KernReturn::InvalidCapability, 84 | KERN_RIGHT_EXISTS => KernReturn::RightExists, 85 | KERN_INVALID_HOST => KernReturn::InvalidHost, 86 | KERN_MEMORY_PRESENT => KernReturn::MemoryPresent, 87 | KERN_MEMORY_DATA_MOVED => KernReturn::MemoryDataMoved, 88 | KERN_MEMORY_RESTART_COPY => KernReturn::MemoryRestartCopy, 89 | KERN_INVALID_PROCESSOR_SET => KernReturn::InvalidProcessorSet, 90 | KERN_POLICY_LIMIT => KernReturn::PolicyLimit, 91 | KERN_INVALID_POLICY => KernReturn::InvalidPolicy, 92 | KERN_INVALID_OBJECT => KernReturn::InvalidObject, 93 | KERN_ALREADY_WAITING => KernReturn::AlreadyWaiting, 94 | KERN_DEFAULT_SET => KernReturn::DefaultSet, 95 | KERN_EXCEPTION_PROTECTED => KernReturn::ExceptionProtected, 96 | KERN_INVALID_LEDGER => KernReturn::InvalidLedger, 97 | KERN_INVALID_MEMORY_CONTROL => KernReturn::InvalidMemoryControl, 98 | KERN_INVALID_SECURITY => KernReturn::InvalidSecurity, 99 | KERN_NOT_DEPRESSED => KernReturn::NotDepressed, 100 | KERN_TERMINATED => KernReturn::Terminated, 101 | KERN_LOCK_SET_DESTROYED => KernReturn::LockSetDestroyed, 102 | KERN_LOCK_UNSTABLE => KernReturn::LockUnstable, 103 | KERN_LOCK_OWNED => KernReturn::LockOwned, 104 | KERN_LOCK_OWNED_SELF => KernReturn::LockOwnedSelf, 105 | KERN_SEMAPHORE_DESTROYED => KernReturn::SemaphoreDestroyed, 106 | KERN_RPC_SERVER_TERMINATED => KernReturn::RpcServerTerminated, 107 | KERN_RPC_TERMINATE_ORPHAN => KernReturn::RpcTerminateOrphan, 108 | KERN_RPC_CONTINUE_ORPHAN => KernReturn::RpcContinueOrphan, 109 | KERN_NOT_SUPPORTED => KernReturn::NotSupported, 110 | KERN_NODE_DOWN => KernReturn::NodeDown, 111 | KERN_NOT_WAITING => KernReturn::NotWaiting, 112 | KERN_OPERATION_TIMED_OUT => KernReturn::OperationTimedOut, 113 | KERN_RETURN_MAX => KernReturn::ReturnMax, 114 | code => KernReturn::Unknown(code), 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /io-kit-sys/src/types.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use std::os::raw::{c_char, c_int, c_uint, c_ulonglong}; 4 | 5 | use mach2::port::mach_port_t; 6 | use mach2::vm_types::mach_vm_address_t; 7 | 8 | pub type IOOptionBits = c_uint; 9 | pub type IOFixed = c_int; 10 | pub type IOVersion = c_uint; 11 | pub type IOItemCount = c_uint; 12 | pub type IOCacheMode = c_uint; 13 | 14 | pub type IOByteCount32 = c_uint; 15 | pub type IOByteCount64 = c_ulonglong; 16 | 17 | pub type IOPhysicalAddress32 = c_uint; 18 | pub type IOPhysicalAddress64 = c_ulonglong; 19 | pub type IOPhysicalLength32 = c_uint; 20 | pub type IOPhysicalLength64 = c_ulonglong; 21 | 22 | #[cfg(all(not(target_arch = "arm"), not(target_arch = "x86")))] 23 | pub type IOVirtualAddress = mach_vm_address_t; 24 | #[cfg(any(target_arch = "arm", target_arch = "x86"))] 25 | pub type IOVirtualAddress = vm_address_t; 26 | 27 | #[cfg(all( 28 | not(target_arch = "arm"), 29 | not(target_arch = "x86"), 30 | not(target_arch = "x86_64") 31 | ))] 32 | pub type IOByteCount = IOByteCount64; 33 | #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] 34 | pub type IOByteCount = IOByteCount32; 35 | 36 | pub type IOLogicalAddress = IOVirtualAddress; 37 | 38 | #[cfg(all( 39 | not(target_arch = "arm"), 40 | not(target_arch = "x86"), 41 | not(target_arch = "x86_64") 42 | ))] 43 | pub type IOPhysicalAddress = IOPhysicalAddress64; 44 | #[cfg(all( 45 | not(target_arch = "arm"), 46 | not(target_arch = "x86"), 47 | not(target_arch = "x86_64") 48 | ))] 49 | pub type IOPhysicalLength = IOPhysicalLength64; 50 | #[cfg(all( 51 | not(target_arch = "arm"), 52 | not(target_arch = "x86"), 53 | not(target_arch = "x86_64") 54 | ))] 55 | pub const IOPhysSize: c_int = 64; 56 | 57 | #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] 58 | pub type IOPhysicalAddress = IOPhysicalAddress32; 59 | #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] 60 | pub type IOPhysicalLength = IOPhysicalAddress32; 61 | #[cfg(any(target_arch = "arm", target_arch = "x86", target_arch = "x86_64"))] 62 | pub const IOPhysSize: c_int = 32; 63 | 64 | #[repr(C)] 65 | #[derive(Debug, Copy)] 66 | pub struct IOPhysicalRange { 67 | address: IOPhysicalAddress, 68 | length: IOByteCount, 69 | } 70 | impl Clone for IOPhysicalRange { 71 | fn clone(&self) -> Self { 72 | *self 73 | } 74 | } 75 | 76 | #[repr(C)] 77 | #[derive(Debug, Copy)] 78 | pub struct IOVirtualRange { 79 | address: IOVirtualAddress, 80 | length: IOByteCount, 81 | } 82 | impl Clone for IOVirtualRange { 83 | fn clone(&self) -> Self { 84 | *self 85 | } 86 | } 87 | 88 | #[cfg(all(not(target_arch = "arm"), not(target_arch = "x86")))] 89 | pub type IOAddressRange = IOVirtualRange; 90 | #[cfg(any(target_arch = "arm", target_arch = "x86"))] 91 | #[repr(C)] 92 | #[derive(Debug, Copy)] 93 | pub struct IOAddressRange { 94 | address: mach_vm_address_t, 95 | length: mach_vm_size_t, 96 | } 97 | #[cfg(any(target_arch = "arm", target_arch = "x86"))] 98 | impl Clone for IOAddressRange { 99 | fn clone(&self) -> Self { 100 | *self 101 | } 102 | } 103 | 104 | // Map between #defined or enum'd constants and text description. 105 | #[repr(C)] 106 | #[derive(Debug, Copy)] 107 | pub struct IONamedValue { 108 | value: c_int, 109 | name: *const c_char, 110 | } 111 | impl Clone for IONamedValue { 112 | fn clone(&self) -> Self { 113 | *self 114 | } 115 | } 116 | 117 | // Memory alignment -- specified as a power of two. 118 | pub type IOAlignment = c_uint; 119 | 120 | pub type io_object_t = mach_port_t; 121 | 122 | pub type io_connect_t = io_object_t; 123 | pub type io_enumerator_t = io_object_t; 124 | pub type io_iterator_t = io_object_t; 125 | pub type io_registry_entry_t = io_object_t; 126 | pub type io_service_t = io_object_t; 127 | 128 | pub const IO_OBJECT_NULL: io_object_t = 0; 129 | 130 | // IOConnectMapMemory memoryTypes 131 | pub const kIODefaultMemoryType: c_int = 0; 132 | 133 | pub const kIODefaultCache: c_int = 0; 134 | pub const kIOInhibitCache: c_int = 1; 135 | pub const kIOWriteThruCache: c_int = 2; 136 | pub const kIOCopybackCache: c_int = 3; 137 | pub const kIOWriteCombineCache: c_int = 4; 138 | pub const kIOCopybackInnerCache: c_int = 5; 139 | 140 | // IOMemory mapping options 141 | pub const kIOMapAnywhere: c_int = 0x00000001; 142 | 143 | pub const kIOMapCacheMask: c_int = 0x00000700; 144 | pub const kIOMapCacheShift: c_int = 8; 145 | pub const kIOMapDefaultCache: c_int = kIODefaultCache << kIOMapCacheShift; 146 | pub const kIOMapInhibitCache: c_int = kIOInhibitCache << kIOMapCacheShift; 147 | pub const kIOMapWriteThruCache: c_int = kIOWriteThruCache << kIOMapCacheShift; 148 | pub const kIOMapCopybackCache: c_int = kIOCopybackCache << kIOMapCacheShift; 149 | pub const kIOMapWriteCombineCache: c_int = kIOWriteCombineCache << kIOMapCacheShift; 150 | pub const kIOMapCopybackInnerCache: c_int = kIOCopybackInnerCache << kIOMapCacheShift; 151 | 152 | pub const kIOMapUserOptionsMask: c_int = 0x00000fff; 153 | 154 | pub const kIOMapReadOnly: c_int = 0x00001000; 155 | 156 | pub const kIOMapStatic: c_int = 0x01000000; 157 | pub const kIOMapReference: c_int = 0x02000000; 158 | pub const kIOMapUnique: c_int = 0x04000000; 159 | pub const kIOMapPrefault: c_int = 0x10000000; 160 | pub const kIOMapOverwrite: c_int = 0x20000000; 161 | 162 | // Scale Factors 163 | pub const kNanosecondScale: c_int = 1; 164 | pub const kMicrosecondScale: c_int = 1000; 165 | pub const kMillisecondScale: c_int = 1000 * 1000; 166 | pub const kSecondScale: c_int = 1000 * 1000 * 1000; 167 | pub const kTickScale: c_int = kSecondScale / 100; 168 | 169 | pub const kIOConnectMethodVarOutputSize: c_int = -3; 170 | 171 | // compatibility types 172 | pub type IODeviceNumber = c_uint; 173 | -------------------------------------------------------------------------------- /io-kit-sys/src/ret.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use std::os::raw::c_int; 4 | 5 | use mach2::kern_return::{kern_return_t, KERN_SUCCESS}; 6 | 7 | // sys_iokit 8 | const SYS_IOKIT: c_int = ((0x38) & 0x3f) << 26; 9 | const SUB_IOKIT_COMMON: c_int = 0; 10 | 11 | // IOReturn 12 | pub type IOReturn = kern_return_t; 13 | // OK 14 | pub const kIOReturnSuccess: IOReturn = KERN_SUCCESS as c_int; 15 | // general error 16 | pub const kIOReturnError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2bc; 17 | // can't allocate memory 18 | pub const kIOReturnNoMemory: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2bd; 19 | // resource shortage 20 | pub const kIOReturnNoResources: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2be; 21 | // error during IPC 22 | pub const kIOReturnIPCError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2bf; 23 | // no such device 24 | pub const kIOReturnNoDevice: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c0; 25 | // privilege violation 26 | pub const kIOReturnNotPrivileged: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c1; 27 | // invalid argument 28 | pub const kIOReturnBadArgument: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c2; 29 | // device read locked 30 | pub const kIOReturnLockedRead: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c3; 31 | // device write locked 32 | pub const kIOReturnLockedWrite: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c4; 33 | // exclusive access and device already open 34 | pub const kIOReturnExclusiveAccess: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c5; 35 | // sent/received messages had different msg_id 36 | pub const kIOReturnBadMessageID: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c6; 37 | // unsupported function 38 | pub const kIOReturnUnsupported: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c7; 39 | // misc. VM failure 40 | pub const kIOReturnVMError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c8; 41 | // internal error 42 | pub const kIOReturnInternalError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2c9; 43 | // General I/O error 44 | pub const kIOReturnIOError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ca; 45 | // ??? 46 | // pub const kIOReturn???Error: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2cb; 47 | // can't acquire lock 48 | pub const kIOReturnCannotLock: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2cc; 49 | // device not open 50 | pub const kIOReturnNotOpen: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2cd; 51 | // read not supported 52 | pub const kIOReturnNotReadable: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ce; 53 | // write not supported 54 | pub const kIOReturnNotWritable: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2cf; 55 | // alignment error 56 | pub const kIOReturnNotAligned: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d0; 57 | // Media Error 58 | pub const kIOReturnBadMedia: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d1; 59 | // device(s) still open 60 | pub const kIOReturnStillOpen: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d2; 61 | // rld failure 62 | pub const kIOReturnRLDError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d3; 63 | // DMA failure 64 | pub const kIOReturnDMAError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d4; 65 | // Device Busy 66 | pub const kIOReturnBusy: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d5; 67 | // I/O Timeout 68 | pub const kIOReturnTimeout: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d6; 69 | // device offline 70 | pub const kIOReturnOffline: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d7; 71 | // not ready 72 | pub const kIOReturnNotReady: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d8; 73 | // device not attached 74 | pub const kIOReturnNotAttached: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2d9; 75 | // no DMA channels left 76 | pub const kIOReturnNoChannels: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2da; 77 | // no space for data 78 | pub const kIOReturnNoSpace: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2db; 79 | // ??? 80 | // pub const kIOReturn???Error: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2dc; 81 | // port already exists 82 | pub const kIOReturnPortExists: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2dd; 83 | // can't wire down physical memory 84 | pub const kIOReturnCannotWire: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2de; 85 | // no interrupt attached 86 | pub const kIOReturnNoInterrupt: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2df; 87 | // no DMA frames enqueued 88 | pub const kIOReturnNoFrames: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e0; 89 | // oversized msg received on interrupt port 90 | pub const kIOReturnMessageTooLarge: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e1; 91 | // not permitted 92 | pub const kIOReturnNotPermitted: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e2; 93 | // no power to device 94 | pub const kIOReturnNoPower: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e3; 95 | // media not present 96 | pub const kIOReturnNoMedia: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e4; 97 | // media not formatted 98 | pub const kIOReturnUnformattedMedia: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e5; 99 | // no such mode 100 | pub const kIOReturnUnsupportedMode: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e6; 101 | // data underrun 102 | pub const kIOReturnUnderrun: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e7; 103 | // data overrun 104 | pub const kIOReturnOverrun: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e8; 105 | // the device is not working properly! 106 | pub const kIOReturnDeviceError: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2e9; 107 | // a completion routine is required 108 | pub const kIOReturnNoCompletion: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ea; 109 | // operation aborted 110 | pub const kIOReturnAborted: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2eb; 111 | // bus bandwidth would be exceeded 112 | pub const kIOReturnNoBandwidth: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ec; 113 | // device not responding 114 | pub const kIOReturnNotResponding: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ed; 115 | // isochronous I/O request for distant past! 116 | pub const kIOReturnIsoTooOld: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ee; 117 | // isochronous I/O request for distant future 118 | pub const kIOReturnIsoTooNew: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2ef; 119 | // data was not found 120 | pub const kIOReturnNotFound: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x2f0; 121 | // should never be seen 122 | pub const kIOReturnInvalid: IOReturn = SYS_IOKIT | SUB_IOKIT_COMMON | 0x1; 123 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/device.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | use std::os::raw::c_void; 4 | 5 | use core_foundation_sys::array::CFArrayRef; 6 | use core_foundation_sys::base::{CFAllocatorRef, CFIndex, CFTypeID, CFTypeRef}; 7 | use core_foundation_sys::date::CFTimeInterval; 8 | use core_foundation_sys::dictionary::CFDictionaryRef; 9 | use core_foundation_sys::runloop::CFRunLoopRef; 10 | use core_foundation_sys::string::CFStringRef; 11 | 12 | use crate::{ 13 | base::Boolean, 14 | hid::{ 15 | base::{ 16 | IOHIDCallback, IOHIDDeviceRef, IOHIDElementRef, IOHIDReportCallback, 17 | IOHIDReportWithTimeStampCallback, IOHIDValueCallback, IOHIDValueMultipleCallback, 18 | IOHIDValueRef, 19 | }, 20 | keys::IOHIDReportType, 21 | }, 22 | ret::IOReturn, 23 | types::{io_service_t, IOOptionBits}, 24 | }; 25 | 26 | extern "C" { 27 | pub fn IOHIDDeviceGetTypeID() -> CFTypeID; 28 | 29 | pub fn IOHIDDeviceCreate(allocator: CFAllocatorRef, service: io_service_t) -> IOHIDDeviceRef; 30 | 31 | pub fn IOHIDDeviceGetService(device: IOHIDDeviceRef) -> io_service_t; 32 | 33 | pub fn IOHIDDeviceOpen(device: IOHIDDeviceRef, options: IOOptionBits) -> IOReturn; 34 | 35 | pub fn IOHIDDeviceClose(device: IOHIDDeviceRef, options: IOOptionBits) -> IOReturn; 36 | 37 | pub fn IOHIDDeviceConformsTo(device: IOHIDDeviceRef, usagePage: u32, usage: u32) -> Boolean; 38 | 39 | pub fn IOHIDDeviceGetProperty(device: IOHIDDeviceRef, key: CFStringRef) -> CFTypeRef; 40 | 41 | pub fn IOHIDDeviceSetProperty( 42 | device: IOHIDDeviceRef, 43 | key: CFStringRef, 44 | property: CFTypeRef, 45 | ) -> Boolean; 46 | 47 | pub fn IOHIDDeviceCopyMatchingElements( 48 | device: IOHIDDeviceRef, 49 | matching: CFDictionaryRef, 50 | options: IOOptionBits, 51 | ) -> CFArrayRef; 52 | 53 | pub fn IOHIDDeviceScheduleWithRunLoop( 54 | device: IOHIDDeviceRef, 55 | runLoop: CFRunLoopRef, 56 | runLoopMode: CFStringRef, 57 | ); 58 | 59 | pub fn IOHIDDeviceUnscheduleFromRunLoop( 60 | device: IOHIDDeviceRef, 61 | runLoop: CFRunLoopRef, 62 | runLoopMode: CFStringRef, 63 | ); 64 | 65 | pub fn IOHIDDeviceRegisterRemovalCallback( 66 | device: IOHIDDeviceRef, 67 | callback: IOHIDCallback, 68 | context: *mut c_void, 69 | ); 70 | 71 | pub fn IOHIDDeviceRegisterInputValueCallback( 72 | device: IOHIDDeviceRef, 73 | callback: IOHIDValueCallback, 74 | context: *mut c_void, 75 | ); 76 | 77 | pub fn IOHIDDeviceRegisterInputReportCallback( 78 | device: IOHIDDeviceRef, 79 | report: *mut u8, 80 | reportLength: CFIndex, 81 | callback: IOHIDReportCallback, 82 | context: *mut c_void, 83 | ); 84 | 85 | pub fn IOHIDDeviceRegisterInputReportWithTimeStampCallback( 86 | device: IOHIDDeviceRef, 87 | report: *mut u8, 88 | reportLength: CFIndex, 89 | callback: IOHIDReportWithTimeStampCallback, 90 | context: *mut c_void, 91 | ); 92 | 93 | pub fn IOHIDDeviceSetInputValueMatching(device: IOHIDDeviceRef, matching: CFDictionaryRef); 94 | 95 | pub fn IOHIDDeviceSetInputValueMatchingMultiple(device: IOHIDDeviceRef, multiple: CFArrayRef); 96 | 97 | pub fn IOHIDDeviceSetValue( 98 | device: IOHIDDeviceRef, 99 | element: IOHIDElementRef, 100 | value: IOHIDValueRef, 101 | ) -> IOReturn; 102 | 103 | pub fn IOHIDDeviceSetValueMultiple( 104 | device: IOHIDDeviceRef, 105 | multiple: CFDictionaryRef, 106 | ) -> IOReturn; 107 | 108 | pub fn IOHIDDeviceSetValueWithCallback( 109 | device: IOHIDDeviceRef, 110 | element: IOHIDElementRef, 111 | value: IOHIDValueRef, 112 | timeout: CFTimeInterval, 113 | callback: IOHIDValueCallback, 114 | context: *mut c_void, 115 | ) -> IOReturn; 116 | 117 | pub fn IOHIDDeviceSetValueMultipleWithCallback( 118 | device: IOHIDDeviceRef, 119 | multiple: CFDictionaryRef, 120 | timeout: CFTimeInterval, 121 | callback: IOHIDValueMultipleCallback, 122 | context: *mut c_void, 123 | ) -> IOReturn; 124 | 125 | pub fn IOHIDDeviceGetValue( 126 | device: IOHIDDeviceRef, 127 | element: IOHIDElementRef, 128 | pValue: *mut IOHIDValueRef, 129 | ) -> IOReturn; 130 | 131 | pub fn IOHIDDeviceCopyValueMultiple( 132 | device: IOHIDDeviceRef, 133 | elements: CFArrayRef, 134 | pMultiple: *mut CFDictionaryRef, 135 | ) -> IOReturn; 136 | 137 | pub fn IOHIDDeviceGetValueWithCallback( 138 | device: IOHIDDeviceRef, 139 | element: IOHIDElementRef, 140 | pValue: *mut IOHIDValueRef, 141 | timeout: CFTimeInterval, 142 | callback: IOHIDValueCallback, 143 | context: *mut c_void, 144 | ) -> IOReturn; 145 | 146 | pub fn IOHIDDeviceCopyValueMultipleWithCallback( 147 | device: IOHIDDeviceRef, 148 | elements: CFArrayRef, 149 | pMultiple: *mut CFDictionaryRef, 150 | timeout: CFTimeInterval, 151 | callback: IOHIDValueMultipleCallback, 152 | context: *mut c_void, 153 | ) -> IOReturn; 154 | 155 | pub fn IOHIDDeviceSetReport( 156 | device: IOHIDDeviceRef, 157 | reportType: IOHIDReportType, 158 | reportID: CFIndex, 159 | report: *const u8, 160 | reportLength: CFIndex, 161 | ) -> IOReturn; 162 | 163 | pub fn IOHIDDeviceSetReportWithCallback( 164 | device: IOHIDDeviceRef, 165 | reportType: IOHIDReportType, 166 | reportID: CFIndex, 167 | report: *const u8, 168 | reportLength: CFIndex, 169 | timeout: CFTimeInterval, 170 | callback: IOHIDReportCallback, 171 | context: *mut c_void, 172 | ) -> IOReturn; 173 | 174 | pub fn IOHIDDeviceGetReport( 175 | device: IOHIDDeviceRef, 176 | reportType: IOHIDReportType, 177 | reportID: CFIndex, 178 | report: *mut u8, 179 | pReportLength: *mut CFIndex, 180 | ) -> IOReturn; 181 | 182 | pub fn IOHIDDeviceGetReportWithCallback( 183 | device: IOHIDDeviceRef, 184 | reportType: IOHIDReportType, 185 | reportID: CFIndex, 186 | report: *mut u8, 187 | pReportLength: *mut CFIndex, 188 | timeout: CFTimeInterval, 189 | callback: IOHIDReportCallback, 190 | context: *mut c_void, 191 | ) -> IOReturn; 192 | } 193 | -------------------------------------------------------------------------------- /io-kit/src/base.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CStr; 2 | use std::mem; 3 | 4 | use std::os::raw::c_char; 5 | 6 | use core_foundation::base::TCFType; 7 | use core_foundation::dictionary::CFDictionary; 8 | use core_foundation::string::CFString; 9 | use io_kit_sys::types::{io_iterator_t, io_object_t, io_registry_entry_t, io_service_t}; 10 | use io_kit_sys::*; 11 | use mach2::kern_return::KERN_SUCCESS; 12 | 13 | pub struct IOObject(io_object_t); 14 | 15 | impl Drop for IOObject { 16 | fn drop(&mut self) { 17 | self.release().unwrap(); 18 | } 19 | } 20 | 21 | impl TIOObject for IOObject { 22 | #[inline] 23 | fn as_concrete_io_object_t(&self) -> io_object_t { 24 | self.0 25 | } 26 | 27 | #[inline] 28 | fn as_io_object_t(&self) -> io_object_t { 29 | self.as_concrete_io_object_t() 30 | } 31 | } 32 | 33 | pub struct IOIterator(io_iterator_t); 34 | 35 | impl Drop for IOIterator { 36 | fn drop(&mut self) { 37 | self.release().unwrap(); 38 | } 39 | } 40 | 41 | impl Iterator for IOIterator { 42 | type Item = IOObject; 43 | 44 | fn next(&mut self) -> Option { 45 | unsafe { 46 | let result = IOIteratorNext(self.as_io_object_t()); 47 | 48 | if result != 0 { 49 | Some(IOObject(result)) 50 | } else { 51 | None 52 | } 53 | } 54 | } 55 | } 56 | 57 | impl IOIterator { 58 | pub fn reset(&self) { 59 | unsafe { IOIteratorReset(self.as_io_object_t()) } 60 | } 61 | 62 | pub fn is_valid(&self) -> bool { 63 | unsafe { IOIteratorIsValid(self.as_io_object_t()) != 0 } 64 | } 65 | } 66 | 67 | impl TIOObject for IOIterator { 68 | #[inline] 69 | fn as_concrete_io_object_t(&self) -> io_iterator_t { 70 | self.0 71 | } 72 | 73 | #[inline] 74 | fn as_io_object_t(&self) -> io_object_t { 75 | self.as_concrete_io_object_t() 76 | } 77 | } 78 | 79 | pub struct IOService(io_service_t); 80 | 81 | impl Drop for IOService { 82 | fn drop(&mut self) { 83 | self.release().unwrap(); 84 | } 85 | } 86 | 87 | impl IOService { 88 | pub fn get_matching_service(matching: CFDictionary) -> Option { 89 | unsafe { 90 | let result = 91 | IOServiceGetMatchingService(kIOMasterPortDefault, matching.as_CFTypeRef() as _); 92 | 93 | if result != 0 { 94 | Some(IOService(result)) 95 | } else { 96 | None 97 | } 98 | } 99 | } 100 | 101 | pub fn get_matching_services(matching: CFDictionary) -> Result, i32> { 102 | unsafe { 103 | let mut io_iterator_t = mem::MaybeUninit::::uninit(); 104 | 105 | let result = IOServiceGetMatchingServices( 106 | kIOMasterPortDefault, 107 | matching.as_CFTypeRef() as _, 108 | io_iterator_t.as_mut_ptr(), 109 | ); 110 | 111 | if result != KERN_SUCCESS { 112 | return Err(result); 113 | } 114 | 115 | let io_iterator_t = io_iterator_t.assume_init(); 116 | 117 | let mut v: Vec = Vec::new(); 118 | 119 | loop { 120 | let result = IOIteratorNext(io_iterator_t); 121 | 122 | if result == 0 { 123 | break; 124 | } 125 | 126 | v.push(IOService(result)) 127 | } 128 | 129 | Ok(v) 130 | } 131 | } 132 | } 133 | 134 | impl TIOObject for IOService { 135 | #[inline] 136 | fn as_concrete_io_object_t(&self) -> io_service_t { 137 | self.0 138 | } 139 | 140 | #[inline] 141 | fn as_io_object_t(&self) -> io_object_t { 142 | self.as_concrete_io_object_t() 143 | } 144 | } 145 | 146 | pub trait TIOObject { 147 | /// Returns the object as its concrete `io_object_t`. 148 | fn as_concrete_io_object_t(&self) -> concrete_io_object_t; 149 | 150 | /// Returns the object as a raw `io_object_t`. 151 | fn as_io_object_t(&self) -> io_object_t; 152 | 153 | fn release(&self) -> Result<(), i32> { 154 | unsafe { 155 | let result = IOObjectRelease(self.as_io_object_t()); 156 | 157 | if result == KERN_SUCCESS { 158 | Ok(()) 159 | } else { 160 | Err(result) 161 | } 162 | } 163 | } 164 | 165 | fn retain(&self) -> Result<(), i32> { 166 | unsafe { 167 | let result = IOObjectRetain(self.as_io_object_t()); 168 | 169 | if result == KERN_SUCCESS { 170 | Ok(()) 171 | } else { 172 | Err(result) 173 | } 174 | } 175 | } 176 | 177 | fn get_class(&self) -> Result { 178 | unsafe { 179 | let mut buf = Vec::::with_capacity(128); 180 | 181 | let result = IOObjectGetClass(self.as_io_object_t(), buf.as_mut_ptr()); 182 | 183 | if result == KERN_SUCCESS { 184 | Ok(CStr::from_ptr(buf.as_ptr()).to_str().unwrap().to_string()) 185 | } else { 186 | Err(result) 187 | } 188 | } 189 | } 190 | 191 | fn copy_class(&self) -> Option { 192 | unsafe { 193 | let result = IOObjectCopyClass(self.as_io_object_t()); 194 | 195 | if result.is_null() { 196 | None 197 | } else { 198 | Some(TCFType::wrap_under_get_rule(result)) 199 | } 200 | } 201 | } 202 | 203 | fn copy_superclass_for_class(&self, class_name: CFString) -> Option { 204 | unsafe { 205 | let result = IOObjectCopySuperclassForClass(class_name.as_CFTypeRef() as _); 206 | 207 | if result.is_null() { 208 | None 209 | } else { 210 | Some(TCFType::wrap_under_get_rule(result)) 211 | } 212 | } 213 | } 214 | 215 | fn copy_bundle_identifier_for_class(&self, class_name: CFString) -> Option { 216 | unsafe { 217 | let result = IOObjectCopyBundleIdentifierForClass(class_name.as_CFTypeRef() as _); 218 | 219 | if result.is_null() { 220 | None 221 | } else { 222 | Some(TCFType::wrap_under_get_rule(result)) 223 | } 224 | } 225 | } 226 | 227 | /// Returns the parent IOService for the given plane. 228 | /// # Safety 229 | /// The caller must ensure that `plane` is a valid, null-terminated C string. 230 | unsafe fn parent(&self, plane: *const c_char) -> Result { 231 | let mut parent = mem::MaybeUninit::::uninit(); 232 | 233 | let result = 234 | IORegistryEntryGetParentEntry(self.as_io_object_t(), plane, parent.as_mut_ptr()); 235 | 236 | if result == KERN_SUCCESS { 237 | Ok(IOService(parent.assume_init())) 238 | } else { 239 | Err(result) 240 | } 241 | } 242 | 243 | /// Returns the child IOIterator for the given plane. 244 | /// # Safety 245 | /// The caller must ensure that `plane` is a valid, null-terminated C string. 246 | unsafe fn children(&self, plane: *const c_char) -> Result { 247 | let mut it = mem::MaybeUninit::::uninit(); 248 | 249 | let result = IORegistryEntryGetChildIterator(self.as_io_object_t(), plane, it.as_mut_ptr()); 250 | 251 | if result == KERN_SUCCESS { 252 | Ok(IOIterator(it.assume_init())) 253 | } else { 254 | Err(result) 255 | } 256 | } 257 | 258 | /// Checks if the object conforms to the given class name. 259 | /// 260 | /// # Safety 261 | /// 262 | /// The caller must ensure that `class_name` is a valid, null-terminated C string. 263 | unsafe fn conforms_to(&self, class_name: *const c_char) -> bool { 264 | IOObjectConformsTo(self.as_io_object_t(), class_name) != 0 265 | } 266 | 267 | fn is_equal_to(&self, object: &impl TIOObject) -> bool { 268 | unsafe { IOObjectIsEqualTo(self.as_io_object_t(), object.as_io_object_t()) != 0 } 269 | } 270 | 271 | fn get_kernel_retain_count(&self) -> u32 { 272 | unsafe { IOObjectGetKernelRetainCount(self.as_io_object_t()) } 273 | } 274 | 275 | fn get_user_retain_count(&self) -> u32 { 276 | unsafe { IOObjectGetUserRetainCount(self.as_io_object_t()) } 277 | } 278 | 279 | fn get_retain_count(&self) -> u32 { 280 | unsafe { IOObjectGetRetainCount(self.as_io_object_t()) } 281 | } 282 | } 283 | 284 | /// Returns a matching IOService dictionary for the given name. 285 | /// 286 | /// # Safety 287 | /// 288 | /// The caller must ensure that `name` is a valid, null-terminated C string. 289 | pub unsafe fn io_service_matching(name: *const c_char) -> Option { 290 | let result = IOServiceMatching(name); 291 | 292 | if result.is_null() { 293 | None 294 | } else { 295 | Some(TCFType::wrap_under_get_rule(result as *const _)) 296 | } 297 | } 298 | -------------------------------------------------------------------------------- /io-kit-sys/src/ps/keys.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | // IOPSPowerAdapter Keys 4 | pub const kIOPSPowerAdapterIDKey: *const ::std::os::raw::c_char = 5 | b"AdapterID\0" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 6 | pub const kIOPSPowerAdapterWattsKey: *const ::std::os::raw::c_char = 7 | b"Watts\0" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 8 | pub const kIOPSPowerAdapterRevisionKey: *const ::std::os::raw::c_char = 9 | b"AdapterRevision\0" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 10 | pub const kIOPSPowerAdapterSerialNumberKey: *const ::std::os::raw::c_char = 11 | b"SerialNumber\0" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 12 | pub const kIOPSPowerAdapterFamilyKey: *const ::std::os::raw::c_char = 13 | b"FamilyCode\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 14 | pub const kIOPSPowerAdapterCurrentKey: *const ::std::os::raw::c_char = 15 | b"Current\0" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 16 | pub const kIOPSPowerAdapterSourceKey: *const ::std::os::raw::c_char = 17 | b"Source\0" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 18 | 19 | // Internal Keys 20 | pub const kIOPSUPSManagementClaimed: *const ::std::os::raw::c_char = 21 | b"/IOKit/UPSPowerManagementClaimed\0" as *const [u8; 33usize] as *const ::std::os::raw::c_char; 22 | pub const kIOPSLowWarnLevelKey: *const ::std::os::raw::c_char = 23 | b"Low Warn Level\0" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 24 | pub const kIOPSDeadWarnLevelKey: *const ::std::os::raw::c_char = 25 | b"Shutdown Level\0" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 26 | pub const kIOPSDynamicStorePath: *const ::std::os::raw::c_char = 27 | b"/IOKit/PowerSources\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 28 | 29 | // Power Source Commands (UPS) 30 | pub const kIOPSCommandDelayedRemovePowerKey: *const ::std::os::raw::c_char = 31 | b"Delayed Remove Power\0" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 32 | pub const kIOPSCommandEnableAudibleAlarmKey: *const ::std::os::raw::c_char = 33 | b"Enable Audible Alarm\0" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 34 | pub const kIOPSCommandStartupDelayKey: *const ::std::os::raw::c_char = 35 | b"Startup Delay\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 36 | pub const kIOPSCommandSetCurrentLimitKey: *const ::std::os::raw::c_char = 37 | b"Set Current Limit\0" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 38 | pub const kIOPSCommandSetRequiredVoltageKey: *const ::std::os::raw::c_char = 39 | b"Set Required Voltage\0" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 40 | pub const kIOPSCommandSendCurrentStateOfCharge: *const ::std::os::raw::c_char = 41 | b"Send Current State of Charge\0" as *const [u8; 29usize] as *const ::std::os::raw::c_char; 42 | pub const kIOPSCommandSendCurrentTemperature: *const ::std::os::raw::c_char = 43 | b"Send Current Temperature\0" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 44 | 45 | // Power Source data keys 46 | pub const kIOPSPowerSourceIDKey: *const ::std::os::raw::c_char = 47 | b"Power Source ID\0" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 48 | pub const kIOPSPowerSourceStateKey: *const ::std::os::raw::c_char = 49 | b"Power Source State\0" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 50 | pub const kIOPSCurrentCapacityKey: *const ::std::os::raw::c_char = 51 | b"Current Capacity\0" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 52 | pub const kIOPSMaxCapacityKey: *const ::std::os::raw::c_char = 53 | b"Max Capacity\0" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 54 | pub const kIOPSDesignCapacityKey: *const ::std::os::raw::c_char = 55 | b"DesignCapacity\0" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 56 | pub const kIOPSNominalCapacityKey: *const ::std::os::raw::c_char = 57 | b"Nominal Capacity\0" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 58 | pub const kIOPSTimeToEmptyKey: *const ::std::os::raw::c_char = 59 | b"Time to Empty\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 60 | pub const kIOPSTimeToFullChargeKey: *const ::std::os::raw::c_char = 61 | b"Time to Full Charge\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 62 | pub const kIOPSIsChargingKey: *const ::std::os::raw::c_char = 63 | b"Is Charging\0" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 64 | pub const kIOPSInternalFailureKey: *const ::std::os::raw::c_char = 65 | b"Internal Failure\0" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 66 | pub const kIOPSIsPresentKey: *const ::std::os::raw::c_char = 67 | b"Is Present\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 68 | pub const kIOPSVoltageKey: *const ::std::os::raw::c_char = 69 | b"Voltage\0" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 70 | pub const kIOPSCurrentKey: *const ::std::os::raw::c_char = 71 | b"Current\0" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 72 | pub const kIOPSTemperatureKey: *const ::std::os::raw::c_char = 73 | b"Temperature\0" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 74 | pub const kIOPSNameKey: *const ::std::os::raw::c_char = 75 | b"Name\0" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 76 | pub const kIOPSTypeKey: *const ::std::os::raw::c_char = 77 | b"Type\0" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 78 | pub const kIOPSTransportTypeKey: *const ::std::os::raw::c_char = 79 | b"Transport Type\0" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 80 | pub const kIOPSVendorIDKey: *const ::std::os::raw::c_char = 81 | b"Vendor ID\0" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 82 | pub const kIOPSProductIDKey: *const ::std::os::raw::c_char = 83 | b"Product ID\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 84 | pub const kIOPSVendorDataKey: *const ::std::os::raw::c_char = 85 | b"Vendor Specific Data\0" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 86 | pub const kIOPSBatteryHealthKey: *const ::std::os::raw::c_char = 87 | b"BatteryHealth\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 88 | pub const kIOPSBatteryHealthConditionKey: *const ::std::os::raw::c_char = 89 | b"BatteryHealthCondition\0" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 90 | pub const kIOPSBatteryFailureModesKey: *const ::std::os::raw::c_char = 91 | b"BatteryFailureModes\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 92 | pub const kIOPSHealthConfidenceKey: *const ::std::os::raw::c_char = 93 | b"HealthConfidence\0" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 94 | pub const kIOPSMaxErrKey: *const ::std::os::raw::c_char = 95 | b"MaxErr\0" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 96 | pub const kIOPSIsChargedKey: *const ::std::os::raw::c_char = 97 | b"Is Charged\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 98 | pub const kIOPSIsFinishingChargeKey: *const ::std::os::raw::c_char = 99 | b"Is Finishing Charge\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 100 | pub const kIOPSHardwareSerialNumberKey: *const ::std::os::raw::c_char = 101 | b"Hardware Serial Number\0" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 102 | 103 | // Transport types 104 | pub const kIOPSSerialTransportType: *const ::std::os::raw::c_char = 105 | b"Serial\0" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 106 | pub const kIOPSUSBTransportType: *const ::std::os::raw::c_char = 107 | b"USB\0" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 108 | pub const kIOPSNetworkTransportType: *const ::std::os::raw::c_char = 109 | b"Ethernet\0" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 110 | pub const kIOPSInternalType: *const ::std::os::raw::c_char = 111 | b"Internal\0" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 112 | 113 | // PowerSource Types 114 | pub const kIOPSInternalBatteryType: *const ::std::os::raw::c_char = 115 | b"InternalBattery\0" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 116 | pub const kIOPSUPSType: *const ::std::os::raw::c_char = 117 | b"UPS\0" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 118 | pub const kIOPSOffLineValue: *const ::std::os::raw::c_char = 119 | b"Off Line\0" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 120 | pub const kIOPSACPowerValue: *const ::std::os::raw::c_char = 121 | b"AC Power\0" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 122 | pub const kIOPSBatteryPowerValue: *const ::std::os::raw::c_char = 123 | b"Battery Power\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 124 | 125 | // Battery Health values 126 | pub const kIOPSPoorValue: *const ::std::os::raw::c_char = 127 | b"Poor\0" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 128 | pub const kIOPSFairValue: *const ::std::os::raw::c_char = 129 | b"Fair\0" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 130 | pub const kIOPSGoodValue: *const ::std::os::raw::c_char = 131 | b"Good\0" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 132 | 133 | // Battery Health Condition values 134 | pub const kIOPSCheckBatteryValue: *const ::std::os::raw::c_char = 135 | b"Check Battery\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 136 | pub const kIOPSPermanentFailureValue: *const ::std::os::raw::c_char = 137 | b"Permanent Battery Failure\0" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 138 | 139 | // Battery Failure Mode values 140 | pub const kIOPSFailureExternalInput: *const ::std::os::raw::c_char = 141 | b"Externally Indicated Failure\0" as *const [u8; 29usize] as *const ::std::os::raw::c_char; 142 | pub const kIOPSFailureSafetyOverVoltage: *const ::std::os::raw::c_char = 143 | b"Safety Over-Voltage\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 144 | pub const kIOPSFailureChargeOverTemp: *const ::std::os::raw::c_char = 145 | b"Charge Over-Temperature\0" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 146 | pub const kIOPSFailureDischargeOverTemp: *const ::std::os::raw::c_char = 147 | b"Discharge Over-Temperature\0" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 148 | pub const kIOPSFailureCellImbalance: *const ::std::os::raw::c_char = 149 | b"Cell Imbalance\0" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 150 | pub const kIOPSFailureChargeFET: *const ::std::os::raw::c_char = 151 | b"Charge FET\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 152 | pub const kIOPSFailureDischargeFET: *const ::std::os::raw::c_char = 153 | b"Discharge FET\0" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 154 | pub const kIOPSFailureDataFlushFault: *const ::std::os::raw::c_char = 155 | b"Data Flush Fault\0" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 156 | pub const kIOPSFailurePermanentAFEComms: *const ::std::os::raw::c_char = 157 | b"Permanent AFE Comms\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 158 | pub const kIOPSFailurePeriodicAFEComms: *const ::std::os::raw::c_char = 159 | b"Periodic AFE Comms\0" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 160 | pub const kIOPSFailureChargeOverCurrent: *const ::std::os::raw::c_char = 161 | b"Charge Over-Current\0" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 162 | pub const kIOPSFailureDischargeOverCurrent: *const ::std::os::raw::c_char = 163 | b"Discharge Over-Current\0" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 164 | pub const kIOPSFailureOpenThermistor: *const ::std::os::raw::c_char = 165 | b"Open Thermistor\0" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 166 | pub const kIOPSFailureFuseBlown: *const ::std::os::raw::c_char = 167 | b"Fuse Blown\0" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 168 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | 191 | Copyright (c) 2017-2018 Junji Takakura 192 | 193 | Licensed under the Apache License, Version 2.0 (the "License"); 194 | you may not use this file except in compliance with the License. 195 | You may obtain a copy of the License at 196 | 197 | http://www.apache.org/licenses/LICENSE-2.0 198 | 199 | Unless required by applicable law or agreed to in writing, software 200 | distributed under the License is distributed on an "AS IS" BASIS, 201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | See the License for the specific language governing permissions and 203 | limitations under the License. 204 | -------------------------------------------------------------------------------- /io-kit-sys/src/keys.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | // properties found in the registry root 4 | pub const kIOKitBuildVersionKey: *const ::std::os::raw::c_char = 5 | b"IOKitBuildVersion\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 6 | pub const kIOKitDiagnosticsKey: *const ::std::os::raw::c_char = 7 | b"IOKitDiagnostics\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 8 | // a dictionary keyed by plane name 9 | pub const kIORegistryPlanesKey: *const ::std::os::raw::c_char = 10 | b"IORegistryPlanes\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 11 | pub const kIOCatalogueKey: *const ::std::os::raw::c_char = 12 | b"IOCatalogue\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 13 | 14 | // registry plane names 15 | pub const kIOServicePlane: *const ::std::os::raw::c_char = 16 | b"IOService\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 17 | pub const kIOPowerPlane: *const ::std::os::raw::c_char = 18 | b"IOPower\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 19 | pub const kIODeviceTreePlane: *const ::std::os::raw::c_char = 20 | b"IODeviceTree\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 21 | pub const kIOAudioPlane: *const ::std::os::raw::c_char = 22 | b"IOAudio\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 23 | pub const kIOFireWirePlane: *const ::std::os::raw::c_char = 24 | b"IOFireWire\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 25 | pub const kIOUSBPlane: *const ::std::os::raw::c_char = 26 | b"IOUSB\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 27 | 28 | // registry ID number 29 | pub const kIORegistryEntryIDKey: *const ::std::os::raw::c_char = 30 | b"IORegistryEntryID\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 31 | 32 | // IOService class name 33 | pub const kIOServiceClass: *const ::std::os::raw::c_char = 34 | b"IOService\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 35 | 36 | // IOResources class name 37 | pub const kIOResourcesClass: *const ::std::os::raw::c_char = 38 | b"IOResources\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 39 | 40 | // IOService driver probing property names 41 | pub const kIOClassKey: *const ::std::os::raw::c_char = 42 | b"IOClass\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 43 | pub const kIOProbeScoreKey: *const ::std::os::raw::c_char = 44 | b"IOProbeScore\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 45 | pub const kIOKitDebugKey: *const ::std::os::raw::c_char = 46 | b"IOKitDebug\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 47 | 48 | // IOService matching property names 49 | pub const kIOProviderClassKey: *const ::std::os::raw::c_char = 50 | b"IOProviderClass\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 51 | pub const kIONameMatchKey: *const ::std::os::raw::c_char = 52 | b"IONameMatch\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 53 | pub const kIOPropertyMatchKey: *const ::std::os::raw::c_char = 54 | b"IOPropertyMatch\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 55 | pub const kIOPathMatchKey: *const ::std::os::raw::c_char = 56 | b"IOPathMatch\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 57 | pub const kIOLocationMatchKey: *const ::std::os::raw::c_char = 58 | b"IOLocationMatch\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 59 | pub const kIOParentMatchKey: *const ::std::os::raw::c_char = 60 | b"IOParentMatch\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 61 | pub const kIOResourceMatchKey: *const ::std::os::raw::c_char = 62 | b"IOResourceMatch\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 63 | pub const kIOMatchedServiceCountKey: *const ::std::os::raw::c_char = 64 | b"IOMatchedServiceCountMatch\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 65 | 66 | pub const kIONameMatchedKey: *const ::std::os::raw::c_char = 67 | b"IONameMatched\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 68 | 69 | pub const kIOMatchCategoryKey: *const ::std::os::raw::c_char = 70 | b"IOMatchCategory\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 71 | pub const kIODefaultMatchCategoryKey: *const ::std::os::raw::c_char = 72 | b"IODefaultMatchCategory\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 73 | 74 | // IOService default user client class, for loadable user clients 75 | pub const kIOUserClientClassKey: *const ::std::os::raw::c_char = 76 | b"IOUserClientClass\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 77 | 78 | // key to find IOMappers 79 | pub const kIOMapperIDKey: *const ::std::os::raw::c_char = 80 | b"IOMapperID\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 81 | 82 | pub const kIOUserClientCrossEndianKey: *const ::std::os::raw::c_char = 83 | b"IOUserClientCrossEndian\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 84 | pub const kIOUserClientCrossEndianCompatibleKey: *const ::std::os::raw::c_char = 85 | b"IOUserClientCrossEndianCompatible\x00" as *const [u8; 34usize] 86 | as *const ::std::os::raw::c_char; 87 | pub const kIOUserClientSharedInstanceKey: *const ::std::os::raw::c_char = 88 | b"IOUserClientSharedInstance\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 89 | // diagnostic string describing the creating task 90 | pub const kIOUserClientCreatorKey: *const ::std::os::raw::c_char = 91 | b"IOUserClientCreator\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 92 | 93 | // IOService notification types 94 | pub const kIOPublishNotification: *const ::std::os::raw::c_char = 95 | b"IOServicePublish\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 96 | pub const kIOFirstPublishNotification: *const ::std::os::raw::c_char = 97 | b"IOServiceFirstPublish\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 98 | pub const kIOMatchedNotification: *const ::std::os::raw::c_char = 99 | b"IOServiceMatched\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 100 | pub const kIOFirstMatchNotification: *const ::std::os::raw::c_char = 101 | b"IOServiceFirstMatch\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 102 | pub const kIOTerminatedNotification: *const ::std::os::raw::c_char = 103 | b"IOServiceTerminate\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 104 | 105 | // IOService interest notification types 106 | pub const kIOGeneralInterest: *const ::std::os::raw::c_char = 107 | b"IOGeneralInterest\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 108 | pub const kIOBusyInterest: *const ::std::os::raw::c_char = 109 | b"IOBusyInterest\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 110 | pub const kIOAppPowerStateInterest: *const ::std::os::raw::c_char = 111 | b"IOAppPowerStateInterest\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 112 | pub const kIOPriorityPowerStateInterest: *const ::std::os::raw::c_char = 113 | b"IOPriorityPowerStateInterest\x00" as *const [u8; 29usize] as *const ::std::os::raw::c_char; 114 | 115 | pub const kIOPlatformDeviceMessageKey: *const ::std::os::raw::c_char = 116 | b"IOPlatformDeviceMessage\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 117 | 118 | // IOService interest notification types 119 | pub const kIOCFPlugInTypesKey: *const ::std::os::raw::c_char = 120 | b"IOCFPlugInTypes\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 121 | 122 | // properties found in services that implement command pooling 123 | pub const kIOCommandPoolSizeKey: *const ::std::os::raw::c_char = 124 | b"IOCommandPoolSize\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 125 | 126 | // properties found in services that implement priority 127 | pub const kIOMaximumPriorityCountKey: *const ::std::os::raw::c_char = 128 | b"IOMaximumPriorityCount\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 129 | 130 | // properties found in services that have transfer constraints 131 | pub const kIOMaximumBlockCountReadKey: *const ::std::os::raw::c_char = 132 | b"IOMaximumBlockCountRead\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 133 | pub const kIOMaximumBlockCountWriteKey: *const ::std::os::raw::c_char = 134 | b"IOMaximumBlockCountWrite\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 135 | pub const kIOMaximumByteCountReadKey: *const ::std::os::raw::c_char = 136 | b"IOMaximumByteCountRead\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 137 | pub const kIOMaximumByteCountWriteKey: *const ::std::os::raw::c_char = 138 | b"IOMaximumByteCountWrite\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 139 | pub const kIOMaximumSegmentCountReadKey: *const ::std::os::raw::c_char = 140 | b"IOMaximumSegmentCountRead\x00" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 141 | pub const kIOMaximumSegmentCountWriteKey: *const ::std::os::raw::c_char = 142 | b"IOMaximumSegmentCountWrite\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 143 | pub const kIOMaximumSegmentByteCountReadKey: *const ::std::os::raw::c_char = 144 | b"IOMaximumSegmentByteCountRead\x00" as *const [u8; 30usize] as *const ::std::os::raw::c_char; 145 | pub const kIOMaximumSegmentByteCountWriteKey: *const ::std::os::raw::c_char = 146 | b"IOMaximumSegmentByteCountWrite\x00" as *const [u8; 31usize] as *const ::std::os::raw::c_char; 147 | pub const kIOMinimumSegmentAlignmentByteCountKey: *const ::std::os::raw::c_char = 148 | b"IOMinimumSegmentAlignmentByteCount\x00" as *const [u8; 35usize] 149 | as *const ::std::os::raw::c_char; 150 | pub const kIOMaximumSegmentAddressableBitCountKey: *const ::std::os::raw::c_char = 151 | b"IOMaximumSegmentAddressableBitCount\x00" as *const [u8; 36usize] 152 | as *const ::std::os::raw::c_char; 153 | 154 | // properties found in services that wish to describe an icon 155 | pub const kIOIconKey: *const ::std::os::raw::c_char = 156 | b"IOIcon\x00" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 157 | pub const kIOBundleResourceFileKey: *const ::std::os::raw::c_char = 158 | b"IOBundleResourceFile\x00" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 159 | pub const kIOBusBadgeKey: *const ::std::os::raw::c_char = 160 | b"IOBusBadge\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 161 | pub const kIODeviceIconKey: *const ::std::os::raw::c_char = 162 | b"IODeviceIcon\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 163 | 164 | // property of root that describes the machine's serial number as a string 165 | pub const kIOPlatformSerialNumberKey: *const ::std::os::raw::c_char = 166 | b"IOPlatformSerialNumber\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 167 | 168 | // property of root that describes the machine's UUID as a string 169 | pub const kIOPlatformUUIDKey: *const ::std::os::raw::c_char = 170 | b"IOPlatformUUID\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 171 | 172 | // IODTNVRAM property keys 173 | pub const kIONVRAMDeletePropertyKey: *const ::std::os::raw::c_char = 174 | b"IONVRAM-DELETE-PROPERTY\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 175 | pub const kIONVRAMSyncNowPropertyKey: *const ::std::os::raw::c_char = 176 | b"IONVRAM-SYNCNOW-PROPERTY\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 177 | pub const kIONVRAMActivateCSRConfigPropertyKey: *const ::std::os::raw::c_char = 178 | b"IONVRAM-ARMCSR-PROPERTY\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 179 | pub const kIODTNVRAMPanicInfoKey: *const ::std::os::raw::c_char = 180 | b"aapl,panic-info\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 181 | 182 | // keys for complex boot information 183 | pub const kIOBootDeviceKey: *const ::std::os::raw::c_char = 184 | b"IOBootDevice\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 185 | pub const kIOBootDevicePathKey: *const ::std::os::raw::c_char = 186 | b"IOBootDevicePath\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 187 | pub const kIOBootDeviceSizeKey: *const ::std::os::raw::c_char = 188 | b"IOBootDeviceSize\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 189 | 190 | // keys for OS Version information 191 | pub const kOSBuildVersionKey: *const ::std::os::raw::c_char = 192 | b"OS Build Version\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 193 | -------------------------------------------------------------------------------- /io-kit-sys/src/hid/keys.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | // This is used to find HID Devices in the IORegistry 4 | pub const kIOHIDDeviceKey: *const ::std::os::raw::c_char = 5 | b"IOHIDDevice\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 6 | 7 | // HID Device Property Keys 8 | pub const kIOHIDTransportKey: *const ::std::os::raw::c_char = 9 | b"Transport\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 10 | pub const kIOHIDVendorIDKey: *const ::std::os::raw::c_char = 11 | b"VendorID\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 12 | pub const kIOHIDVendorIDSourceKey: *const ::std::os::raw::c_char = 13 | b"VendorIDSource\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 14 | pub const kIOHIDProductIDKey: *const ::std::os::raw::c_char = 15 | b"ProductID\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 16 | pub const kIOHIDVersionNumberKey: *const ::std::os::raw::c_char = 17 | b"VersionNumber\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 18 | pub const kIOHIDManufacturerKey: *const ::std::os::raw::c_char = 19 | b"Manufacturer\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 20 | pub const kIOHIDProductKey: *const ::std::os::raw::c_char = 21 | b"Product\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 22 | pub const kIOHIDSerialNumberKey: *const ::std::os::raw::c_char = 23 | b"SerialNumber\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 24 | pub const kIOHIDCountryCodeKey: *const ::std::os::raw::c_char = 25 | b"CountryCode\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 26 | pub const kIOHIDStandardTypeKey: *const ::std::os::raw::c_char = 27 | b"StandardType\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 28 | pub const kIOHIDLocationIDKey: *const ::std::os::raw::c_char = 29 | b"LocationID\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 30 | pub const kIOHIDDeviceUsageKey: *const ::std::os::raw::c_char = 31 | b"DeviceUsage\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 32 | pub const kIOHIDDeviceUsagePageKey: *const ::std::os::raw::c_char = 33 | b"DeviceUsagePage\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 34 | pub const kIOHIDDeviceUsagePairsKey: *const ::std::os::raw::c_char = 35 | b"DeviceUsagePairs\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 36 | pub const kIOHIDPrimaryUsageKey: *const ::std::os::raw::c_char = 37 | b"PrimaryUsage\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 38 | pub const kIOHIDPrimaryUsagePageKey: *const ::std::os::raw::c_char = 39 | b"PrimaryUsagePage\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 40 | pub const kIOHIDMaxInputReportSizeKey: *const ::std::os::raw::c_char = 41 | b"MaxInputReportSize\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 42 | pub const kIOHIDMaxOutputReportSizeKey: *const ::std::os::raw::c_char = 43 | b"MaxOutputReportSize\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 44 | pub const kIOHIDMaxFeatureReportSizeKey: *const ::std::os::raw::c_char = 45 | b"MaxFeatureReportSize\x00" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 46 | pub const kIOHIDReportIntervalKey: *const ::std::os::raw::c_char = 47 | b"ReportInterval\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 48 | pub const kIOHIDSampleIntervalKey: *const ::std::os::raw::c_char = 49 | b"SampleInterval\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 50 | pub const kIOHIDBatchIntervalKey: *const ::std::os::raw::c_char = 51 | b"BatchInterval\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 52 | pub const kIOHIDRequestTimeoutKey: *const ::std::os::raw::c_char = 53 | b"RequestTimeout\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 54 | pub const kIOHIDReportDescriptorKey: *const ::std::os::raw::c_char = 55 | b"ReportDescriptor\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 56 | pub const kIOHIDResetKey: *const ::std::os::raw::c_char = 57 | b"Reset\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 58 | pub const kIOHIDKeyboardLanguageKey: *const ::std::os::raw::c_char = 59 | b"KeyboardLanguage\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 60 | pub const kIOHIDAltHandlerIdKey: *const ::std::os::raw::c_char = 61 | b"alt_handler_id\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 62 | pub const kIOHIDBuiltInKey: *const ::std::os::raw::c_char = 63 | b"Built-In\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 64 | pub const kIOHIDDisplayIntegratedKey: *const ::std::os::raw::c_char = 65 | b"DisplayIntegrated\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 66 | pub const kIOHIDProductIDMaskKey: *const ::std::os::raw::c_char = 67 | b"ProductIDMask\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 68 | pub const kIOHIDProductIDArrayKey: *const ::std::os::raw::c_char = 69 | b"ProductIDArray\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 70 | pub const kIOHIDPowerOnDelayNSKey: *const ::std::os::raw::c_char = 71 | b"HIDPowerOnDelayNS\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 72 | pub const kIOHIDCategoryKey: *const ::std::os::raw::c_char = 73 | b"Category\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 74 | pub const kIOHIDMaxResponseLatencyKey: *const ::std::os::raw::c_char = 75 | b"MaxResponseLatency\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 76 | pub const kIOHIDUniqueIDKey: *const ::std::os::raw::c_char = 77 | b"UniqueID\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 78 | pub const kIOHIDPhysicalDeviceUniqueIDKey: *const ::std::os::raw::c_char = 79 | b"PhysicalDeviceUniqueID\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 80 | 81 | pub const kIOHIDTransportUSBValue: *const ::std::os::raw::c_char = 82 | b"USB\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 83 | pub const kIOHIDTransportBluetoothValue: *const ::std::os::raw::c_char = 84 | b"Bluetooth\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 85 | pub const kIOHIDTransportBluetoothLowEnergyValue: *const ::std::os::raw::c_char = 86 | b"BluetoothLowEnergy\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 87 | pub const kIOHIDTransportAIDBValue: *const ::std::os::raw::c_char = 88 | b"AIDB\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 89 | pub const kIOHIDTransportI2CValue: *const ::std::os::raw::c_char = 90 | b"I2C\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 91 | pub const kIOHIDTransportSPIValue: *const ::std::os::raw::c_char = 92 | b"SPI\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 93 | pub const kIOHIDTransportSerialValue: *const ::std::os::raw::c_char = 94 | b"Serial\x00" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 95 | pub const kIOHIDTransportIAPValue: *const ::std::os::raw::c_char = 96 | b"IAP\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 97 | pub const kIOHIDTransportAirPlayValue: *const ::std::os::raw::c_char = 98 | b"AirPlay\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 99 | pub const kIOHIDTransportSPUValue: *const ::std::os::raw::c_char = 100 | b"SPU\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 101 | 102 | pub const kIOHIDCategoryAutomotiveValue: *const ::std::os::raw::c_char = 103 | b"Automotive\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 104 | 105 | // HID Element Key 106 | pub const kIOHIDElementKey: *const ::std::os::raw::c_char = 107 | b"Elements\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 108 | 109 | // HID Element Dictionary Keys 110 | pub const kIOHIDElementCookieKey: *const ::std::os::raw::c_char = 111 | b"ElementCookie\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 112 | pub const kIOHIDElementTypeKey: *const ::std::os::raw::c_char = 113 | b"Type\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 114 | pub const kIOHIDElementCollectionTypeKey: *const ::std::os::raw::c_char = 115 | b"CollectionType\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 116 | pub const kIOHIDElementUsageKey: *const ::std::os::raw::c_char = 117 | b"Usage\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 118 | pub const kIOHIDElementUsagePageKey: *const ::std::os::raw::c_char = 119 | b"UsagePage\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 120 | pub const kIOHIDElementMinKey: *const ::std::os::raw::c_char = 121 | b"Min\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 122 | pub const kIOHIDElementMaxKey: *const ::std::os::raw::c_char = 123 | b"Max\x00" as *const [u8; 4usize] as *const ::std::os::raw::c_char; 124 | pub const kIOHIDElementScaledMinKey: *const ::std::os::raw::c_char = 125 | b"ScaledMin\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 126 | pub const kIOHIDElementScaledMaxKey: *const ::std::os::raw::c_char = 127 | b"ScaledMax\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 128 | pub const kIOHIDElementSizeKey: *const ::std::os::raw::c_char = 129 | b"Size\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 130 | pub const kIOHIDElementReportSizeKey: *const ::std::os::raw::c_char = 131 | b"ReportSize\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 132 | pub const kIOHIDElementReportCountKey: *const ::std::os::raw::c_char = 133 | b"ReportCount\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 134 | pub const kIOHIDElementReportIDKey: *const ::std::os::raw::c_char = 135 | b"ReportID\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 136 | pub const kIOHIDElementIsArrayKey: *const ::std::os::raw::c_char = 137 | b"IsArray\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 138 | pub const kIOHIDElementIsRelativeKey: *const ::std::os::raw::c_char = 139 | b"IsRelative\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 140 | pub const kIOHIDElementIsWrappingKey: *const ::std::os::raw::c_char = 141 | b"IsWrapping\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 142 | pub const kIOHIDElementIsNonLinearKey: *const ::std::os::raw::c_char = 143 | b"IsNonLinear\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 144 | pub const kIOHIDElementHasPreferredStateKey: *const ::std::os::raw::c_char = 145 | b"HasPreferredState\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 146 | pub const kIOHIDElementHasNullStateKey: *const ::std::os::raw::c_char = 147 | b"HasNullState\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 148 | pub const kIOHIDElementFlagsKey: *const ::std::os::raw::c_char = 149 | b"Flags\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 150 | pub const kIOHIDElementUnitKey: *const ::std::os::raw::c_char = 151 | b"Unit\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 152 | pub const kIOHIDElementUnitExponentKey: *const ::std::os::raw::c_char = 153 | b"UnitExponent\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 154 | pub const kIOHIDElementNameKey: *const ::std::os::raw::c_char = 155 | b"Name\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 156 | pub const kIOHIDElementValueLocationKey: *const ::std::os::raw::c_char = 157 | b"ValueLocation\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 158 | pub const kIOHIDElementDuplicateIndexKey: *const ::std::os::raw::c_char = 159 | b"DuplicateIndex\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 160 | pub const kIOHIDElementParentCollectionKey: *const ::std::os::raw::c_char = 161 | b"ParentCollection\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 162 | pub const kIOHIDElementVendorSpecificKey: *const ::std::os::raw::c_char = 163 | b"VendorSpecific\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 164 | 165 | // HID Element Match Keys 166 | pub const kIOHIDElementCookieMinKey: *const ::std::os::raw::c_char = 167 | b"ElementCookieMin\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 168 | pub const kIOHIDElementCookieMaxKey: *const ::std::os::raw::c_char = 169 | b"ElementCookieMax\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 170 | pub const kIOHIDElementUsageMinKey: *const ::std::os::raw::c_char = 171 | b"UsageMin\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 172 | pub const kIOHIDElementUsageMaxKey: *const ::std::os::raw::c_char = 173 | b"UsageMax\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 174 | 175 | // HID Element Calibration Keys 176 | pub const kIOHIDElementCalibrationMinKey: *const ::std::os::raw::c_char = 177 | b"CalibrationMin\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 178 | pub const kIOHIDElementCalibrationMaxKey: *const ::std::os::raw::c_char = 179 | b"CalibrationMax\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 180 | pub const kIOHIDElementCalibrationSaturationMinKey: *const ::std::os::raw::c_char = 181 | b"CalibrationSaturationMin\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 182 | pub const kIOHIDElementCalibrationSaturationMaxKey: *const ::std::os::raw::c_char = 183 | b"CalibrationSaturationMax\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 184 | pub const kIOHIDElementCalibrationDeadZoneMinKey: *const ::std::os::raw::c_char = 185 | b"CalibrationDeadZoneMin\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 186 | pub const kIOHIDElementCalibrationDeadZoneMaxKey: *const ::std::os::raw::c_char = 187 | b"CalibrationDeadZoneMax\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 188 | pub const kIOHIDElementCalibrationGranularityKey: *const ::std::os::raw::c_char = 189 | b"CalibrationGranularity\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 190 | 191 | pub type IOHIDElementCookie = u32; 192 | 193 | pub type IOHIDElementType = u32; 194 | pub const kIOHIDElementTypeInput_Misc: IOHIDElementType = 1; 195 | pub const kIOHIDElementTypeInput_Button: IOHIDElementType = 2; 196 | pub const kIOHIDElementTypeInput_Axis: IOHIDElementType = 3; 197 | pub const kIOHIDElementTypeInput_ScanCodes: IOHIDElementType = 4; 198 | pub const kIOHIDElementTypeOutput: IOHIDElementType = 129; 199 | pub const kIOHIDElementTypeFeature: IOHIDElementType = 257; 200 | pub const kIOHIDElementTypeCollection: IOHIDElementType = 513; 201 | 202 | pub type IOHIDElementCollectionType = u32; 203 | pub const kIOHIDElementCollectionTypePhysical: IOHIDElementCollectionType = 0x00; 204 | pub const kIOHIDElementCollectionTypeApplication: IOHIDElementCollectionType = 0x01; 205 | pub const kIOHIDElementCollectionTypeLogical: IOHIDElementCollectionType = 0x02; 206 | pub const kIOHIDElementCollectionTypeReport: IOHIDElementCollectionType = 0x03; 207 | pub const kIOHIDElementCollectionTypeNamedArray: IOHIDElementCollectionType = 0x04; 208 | pub const kIOHIDElementCollectionTypeUsageSwitch: IOHIDElementCollectionType = 0x05; 209 | pub const kIOHIDElementCollectionTypeUsageModifier: IOHIDElementCollectionType = 0x06; 210 | 211 | pub type IOHIDReportType = u32; 212 | pub const kIOHIDReportTypeInput: IOHIDReportType = 0; 213 | pub const kIOHIDReportTypeOutput: IOHIDReportType = 1; 214 | pub const kIOHIDReportTypeFeature: IOHIDReportType = 2; 215 | pub const kIOHIDReportTypeCount: IOHIDReportType = 3; 216 | 217 | pub type IOHIDOptionsType = u32; 218 | pub const kIOHIDOptionsTypeNone: IOHIDOptionsType = 0x00; 219 | pub const kIOHIDOptionsTypeSeizeDevice: IOHIDOptionsType = 0x01; 220 | 221 | pub type IOHIDQueueOptionsType = u32; 222 | pub const kIOHIDQueueOptionsTypeNone: IOHIDQueueOptionsType = 0x00; 223 | pub const kIOHIDQueueOptionsTypeEnqueueAll: IOHIDQueueOptionsType = 0x01; 224 | 225 | pub type IOHIDElementFlags = u32; 226 | pub const kIOHIDElementFlagsConstantMask: IOHIDElementFlags = 0x0001; 227 | pub const kIOHIDElementFlagsVariableMask: IOHIDElementFlags = 0x0002; 228 | pub const kIOHIDElementFlagsRelativeMask: IOHIDElementFlags = 0x0004; 229 | pub const kIOHIDElementFlagsWrapMask: IOHIDElementFlags = 0x0008; 230 | pub const kIOHIDElementFlagsNonLinearMask: IOHIDElementFlags = 0x0010; 231 | pub const kIOHIDElementFlagsNoPreferredMask: IOHIDElementFlags = 0x0020; 232 | pub const kIOHIDElementFlagsNullStateMask: IOHIDElementFlags = 0x0040; 233 | pub const kIOHIDElementFlagsVolativeMask: IOHIDElementFlags = 0x0080; 234 | pub const kIOHIDElementFlagsBufferedByteMask: IOHIDElementFlags = 0x0100; 235 | 236 | pub type IOHIDStandardType = u32; 237 | pub const kIOHIDStandardTypeANSI: IOHIDStandardType = 0; 238 | pub const kIOHIDStandardTypeISO: IOHIDStandardType = 1; 239 | pub const kIOHIDStandardTypeJIS: IOHIDStandardType = 2; 240 | 241 | pub type IOHIDValueScaleType = u32; 242 | pub const kIOHIDValueScaleTypeCalibrated: IOHIDValueScaleType = 0; 243 | pub const kIOHIDValueScaleTypePhysical: IOHIDValueScaleType = 1; 244 | 245 | pub type IOHIDValueOptions = u32; 246 | pub const kIOHIDValueOptionsFlagRelativeSimple: IOHIDValueOptions = 1 << 0; 247 | pub const kIOHIDValueOptionsFlagPrevious: IOHIDValueOptions = 1 << 1; 248 | 249 | pub const kIOHIDDigitizerGestureCharacterStateKey: *const ::std::os::raw::c_char = 250 | b"DigitizerCharacterGestureState\x00" as *const [u8; 31usize] as *const ::std::os::raw::c_char; 251 | -------------------------------------------------------------------------------- /io-kit-sys/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![allow(non_camel_case_types)] 2 | #![allow(non_upper_case_globals)] 3 | #![allow(non_snake_case)] 4 | 5 | extern crate core_foundation_sys; 6 | extern crate mach2; 7 | 8 | pub mod base; 9 | pub mod keys; 10 | pub mod ret; 11 | pub mod types; 12 | 13 | pub mod hid; 14 | pub mod ps; 15 | pub mod pwr_mgt; 16 | pub mod serial; 17 | pub mod usb; 18 | 19 | use std::os::raw::{c_char, c_int, c_void}; 20 | 21 | use core_foundation_sys::base::{CFAllocatorRef, CFTypeRef}; 22 | use core_foundation_sys::dictionary::{CFDictionaryRef, CFMutableDictionaryRef}; 23 | use core_foundation_sys::runloop::CFRunLoopSourceRef; 24 | use core_foundation_sys::string::CFStringRef; 25 | use mach2::boolean::boolean_t; 26 | use mach2::clock_types::mach_timespec_t; 27 | use mach2::kern_return::kern_return_t; 28 | use mach2::mach_types::task_port_t; 29 | use mach2::message::mach_msg_header_t; 30 | use mach2::port::mach_port_t; 31 | use mach2::vm_types::{mach_vm_address_t, mach_vm_size_t}; 32 | 33 | use base::dispatch_queue_t; 34 | use ret::IOReturn; 35 | use types::{ 36 | io_connect_t, io_iterator_t, io_object_t, io_registry_entry_t, io_service_t, IOOptionBits, 37 | }; 38 | 39 | // exports from 40 | extern "C" { 41 | fn __CFStringMakeConstantString(cStr: *const c_char) -> CFStringRef; 42 | } 43 | 44 | /// Converts a C string to a constant CFStringRef. 45 | /// 46 | /// # Safety 47 | /// 48 | /// The caller must ensure that `cStr` is a valid, null-terminated C string. 49 | pub unsafe fn CFSTR(cStr: *const c_char) -> CFStringRef { 50 | __CFStringMakeConstantString(cStr) 51 | } 52 | 53 | // exports from 54 | #[repr(C)] 55 | #[derive(Debug, Copy, Clone)] 56 | pub struct IONotificationPort { 57 | _unused: [u8; 0], 58 | } 59 | 60 | pub type IONotificationPortRef = *mut IONotificationPort; 61 | 62 | pub type IOServiceMatchingCallback = 63 | unsafe extern "C" fn(refcon: *mut c_void, iterator: io_iterator_t); 64 | 65 | pub type IOServiceInterestCallback = unsafe extern "C" fn( 66 | refcon: *mut c_void, 67 | service: io_service_t, 68 | messageType: u32, 69 | messageArgument: *mut c_void, 70 | ); 71 | 72 | extern "C" { 73 | #[link_name = "kIOMasterPortDefault"] 74 | pub static kIOMasterPortDefault: mach_port_t; 75 | 76 | pub fn IOMasterPort(bootstrapPort: mach_port_t, masterPort: *mut mach_port_t) -> kern_return_t; 77 | 78 | pub fn IONotificationPortCreate(masterPort: mach_port_t) -> IONotificationPortRef; 79 | 80 | pub fn IONotificationPortDestroy(notify: IONotificationPortRef); 81 | 82 | pub fn IONotificationPortGetRunLoopSource(notify: IONotificationPortRef) -> CFRunLoopSourceRef; 83 | 84 | pub fn IONotificationPortGetMachPort(notify: IONotificationPortRef) -> mach_port_t; 85 | 86 | pub fn IONotificationPortSetDispatchQueue( 87 | notify: IONotificationPortRef, 88 | queue: dispatch_queue_t, 89 | ); 90 | 91 | pub fn IODispatchCalloutFromMessage( 92 | unused: *mut c_void, 93 | msg: *mut mach_msg_header_t, 94 | reference: *mut c_void, 95 | ); 96 | 97 | pub fn IOCreateReceivePort(msgType: u32, recvPort: *mut mach_port_t) -> kern_return_t; 98 | } 99 | 100 | // IOObject 101 | extern "C" { 102 | pub fn IOObjectRelease(object: io_object_t) -> kern_return_t; 103 | 104 | pub fn IOObjectRetain(object: io_object_t) -> kern_return_t; 105 | 106 | pub fn IOObjectGetClass(object: io_object_t, className: *mut c_char) -> kern_return_t; 107 | 108 | pub fn IOObjectCopyClass(object: io_object_t) -> CFStringRef; 109 | 110 | pub fn IOObjectCopySuperclassForClass(classname: CFStringRef) -> CFStringRef; 111 | 112 | pub fn IOObjectCopyBundleIdentifierForClass(classname: CFStringRef) -> CFStringRef; 113 | 114 | pub fn IOObjectConformsTo(object: io_object_t, className: *const c_char) -> boolean_t; 115 | 116 | pub fn IOObjectIsEqualTo(object: io_object_t, anObject: io_object_t) -> boolean_t; 117 | 118 | pub fn IOObjectGetKernelRetainCount(object: io_object_t) -> u32; 119 | 120 | pub fn IOObjectGetUserRetainCount(object: io_object_t) -> u32; 121 | 122 | pub fn IOObjectGetRetainCount(object: io_object_t) -> u32; 123 | } 124 | 125 | // IOIterator, subclass of IOObject 126 | extern "C" { 127 | pub fn IOIteratorNext(iterator: io_iterator_t) -> io_object_t; 128 | 129 | pub fn IOIteratorReset(iterator: io_iterator_t); 130 | 131 | pub fn IOIteratorIsValid(iterator: io_iterator_t) -> boolean_t; 132 | } 133 | 134 | // IOService, subclass of IORegistryEntry 135 | extern "C" { 136 | pub fn IOServiceGetMatchingService( 137 | masterPort: mach_port_t, 138 | matching: CFDictionaryRef, 139 | ) -> io_service_t; 140 | 141 | pub fn IOServiceGetMatchingServices( 142 | masterPort: mach_port_t, 143 | matching: CFDictionaryRef, 144 | existing: *mut io_iterator_t, 145 | ) -> kern_return_t; 146 | 147 | pub fn IOServiceAddNotification( 148 | masterPort: mach_port_t, 149 | notificationType: *const c_char, 150 | matching: CFDictionaryRef, 151 | wakePort: mach_port_t, 152 | reference: usize, 153 | notification: *mut io_iterator_t, 154 | ) -> kern_return_t; 155 | 156 | pub fn IOServiceAddMatchingNotification( 157 | notifyPort: IONotificationPortRef, 158 | notificationType: *const c_char, 159 | matching: CFDictionaryRef, 160 | callback: IOServiceMatchingCallback, 161 | refCon: *mut c_void, 162 | notification: *mut io_iterator_t, 163 | ) -> kern_return_t; 164 | 165 | pub fn IOServiceAddInterestNotification( 166 | notifyPort: IONotificationPortRef, 167 | service: io_service_t, 168 | interestType: *const c_char, 169 | callback: IOServiceInterestCallback, 170 | refCon: *mut c_void, 171 | notification: *mut io_object_t, 172 | ) -> kern_return_t; 173 | 174 | pub fn IOServiceMatchPropertyTable( 175 | service: io_service_t, 176 | matching: CFDictionaryRef, 177 | matches: *mut boolean_t, 178 | ) -> kern_return_t; 179 | 180 | pub fn IOServiceGetBusyState(service: io_service_t, busyState: *mut u32) -> kern_return_t; 181 | 182 | pub fn IOServiceWaitQuiet( 183 | service: io_service_t, 184 | waitTime: *mut mach_timespec_t, 185 | ) -> kern_return_t; 186 | 187 | pub fn IOKitGetBusyState(masterPort: mach_port_t, busyState: *mut u32) -> kern_return_t; 188 | 189 | pub fn IOKitWaitQuiet(masterPort: mach_port_t, waitTime: *mut mach_timespec_t) 190 | -> kern_return_t; 191 | 192 | pub fn IOServiceOpen( 193 | service: io_service_t, 194 | owningTask: task_port_t, 195 | type_: u32, 196 | connect: *mut io_connect_t, 197 | ) -> kern_return_t; 198 | 199 | pub fn IOServiceRequestProbe(service: io_service_t, options: u32) -> kern_return_t; 200 | } 201 | 202 | // options for IOServiceAuthorize() 203 | pub const kIOServiceInteractionAllowed: u32 = 0x00000001; 204 | 205 | extern "C" { 206 | pub fn IOServiceAuthorize(service: io_service_t, options: u32) -> kern_return_t; 207 | 208 | pub fn IOServiceOpenAsFileDescriptor(service: io_service_t, oflag: c_int) -> c_int; 209 | } 210 | 211 | // IOService connection 212 | extern "C" { 213 | pub fn IOServiceClose(connect: io_connect_t) -> kern_return_t; 214 | 215 | pub fn IOConnectAddRef(connect: io_connect_t) -> kern_return_t; 216 | 217 | pub fn IOConnectRelease(connect: io_connect_t) -> kern_return_t; 218 | 219 | pub fn IOConnectGetService(connect: io_connect_t, service: *mut io_service_t) -> kern_return_t; 220 | 221 | pub fn IOConnectSetNotificationPort( 222 | connect: io_connect_t, 223 | type_: u32, 224 | port: mach_port_t, 225 | reference: usize, 226 | ) -> kern_return_t; 227 | 228 | pub fn IOConnectMapMemory( 229 | connect: io_connect_t, 230 | memoryType: u32, 231 | intoTask: task_port_t, 232 | atAddress: *mut mach_vm_address_t, 233 | ofSize: *mut mach_vm_size_t, 234 | options: IOOptionBits, 235 | ) -> kern_return_t; 236 | 237 | pub fn IOConnectMapMemory64( 238 | connect: io_connect_t, 239 | memoryType: u32, 240 | intoTask: task_port_t, 241 | atAddress: *mut mach_vm_address_t, 242 | ofSize: *mut mach_vm_size_t, 243 | options: IOOptionBits, 244 | ) -> kern_return_t; 245 | 246 | pub fn IOConnectUnmapMemory( 247 | connect: io_connect_t, 248 | memoryType: u32, 249 | fromTask: task_port_t, 250 | atAddress: mach_vm_address_t, 251 | ) -> kern_return_t; 252 | 253 | pub fn IOConnectUnmapMemory64( 254 | connect: io_connect_t, 255 | memoryType: u32, 256 | fromTask: task_port_t, 257 | atAddress: mach_vm_address_t, 258 | ) -> kern_return_t; 259 | 260 | pub fn IOConnectSetCFProperties(connect: io_connect_t, properties: CFTypeRef) -> kern_return_t; 261 | 262 | pub fn IOConnectSetCFProperty( 263 | connect: io_connect_t, 264 | propertyName: CFStringRef, 265 | property: CFTypeRef, 266 | ) -> kern_return_t; 267 | } 268 | 269 | // Combined LP64 & ILP32 Extended IOUserClient::externalMethod 270 | extern "C" { 271 | pub fn IOConnectCallMethod( 272 | connection: mach_port_t, 273 | selector: u32, 274 | input: *const u64, 275 | inputCnt: u32, 276 | inputStruct: *const c_void, 277 | inputStructCnt: usize, 278 | output: *mut u64, 279 | outputCnt: *mut u32, 280 | outputStruct: *mut c_void, 281 | outputStructCnt: *mut usize, 282 | ) -> kern_return_t; 283 | 284 | pub fn IOConnectCallAsyncMethod( 285 | connection: mach_port_t, 286 | selector: u32, 287 | wake_port: mach_port_t, 288 | reference: *mut u64, 289 | referenceCnt: u32, 290 | input: *const u64, 291 | inputCnt: u32, 292 | inputStruct: *const c_void, 293 | inputStructCnt: usize, 294 | output: *mut u64, 295 | outputCnt: *mut u32, 296 | outputStruct: *mut c_void, 297 | outputStructCnt: *mut usize, 298 | ) -> kern_return_t; 299 | } 300 | extern "C" { 301 | pub fn IOConnectCallStructMethod( 302 | connection: mach_port_t, 303 | selector: u32, 304 | inputStruct: *const c_void, 305 | inputStructCnt: usize, 306 | outputStruct: *mut c_void, 307 | outputStructCnt: *mut usize, 308 | ) -> kern_return_t; 309 | 310 | pub fn IOConnectCallAsyncStructMethod( 311 | connection: mach_port_t, 312 | selector: u32, 313 | wake_port: mach_port_t, 314 | reference: *mut u64, 315 | referenceCnt: u32, 316 | inputStruct: *const c_void, 317 | inputStructCnt: usize, 318 | outputStruct: *mut c_void, 319 | outputStructCnt: *mut usize, 320 | ) -> kern_return_t; 321 | 322 | pub fn IOConnectCallScalarMethod( 323 | connection: mach_port_t, 324 | selector: u32, 325 | input: *const u64, 326 | inputCnt: u32, 327 | output: *mut u64, 328 | outputCnt: *mut u32, 329 | ) -> kern_return_t; 330 | 331 | pub fn IOConnectCallAsyncScalarMethod( 332 | connection: mach_port_t, 333 | selector: u32, 334 | wake_port: mach_port_t, 335 | reference: *mut u64, 336 | referenceCnt: u32, 337 | input: *const u64, 338 | inputCnt: u32, 339 | output: *mut u64, 340 | outputCnt: *mut u32, 341 | ) -> kern_return_t; 342 | } 343 | 344 | extern "C" { 345 | pub fn IOConnectTrap0(connect: io_connect_t, index: u32) -> kern_return_t; 346 | 347 | pub fn IOConnectTrap1(connect: io_connect_t, index: u32, p1: usize) -> kern_return_t; 348 | 349 | pub fn IOConnectTrap2(connect: io_connect_t, index: u32, p1: usize, p2: usize) 350 | -> kern_return_t; 351 | 352 | pub fn IOConnectTrap3( 353 | connect: io_connect_t, 354 | index: u32, 355 | p1: usize, 356 | p2: usize, 357 | p3: usize, 358 | ) -> kern_return_t; 359 | 360 | pub fn IOConnectTrap4( 361 | connect: io_connect_t, 362 | index: u32, 363 | p1: usize, 364 | p2: usize, 365 | p3: usize, 366 | p4: usize, 367 | ) -> kern_return_t; 368 | 369 | pub fn IOConnectTrap5( 370 | connect: io_connect_t, 371 | index: u32, 372 | p1: usize, 373 | p2: usize, 374 | p3: usize, 375 | p4: usize, 376 | p5: usize, 377 | ) -> kern_return_t; 378 | 379 | pub fn IOConnectTrap6( 380 | connect: io_connect_t, 381 | index: u32, 382 | p1: usize, 383 | p2: usize, 384 | p3: usize, 385 | p4: usize, 386 | p5: usize, 387 | p6: usize, 388 | ) -> kern_return_t; 389 | } 390 | 391 | extern "C" { 392 | pub fn IOConnectAddClient(connect: io_connect_t, client: io_connect_t) -> kern_return_t; 393 | 394 | pub fn IORegistryGetRootEntry(masterPort: mach_port_t) -> io_registry_entry_t; 395 | 396 | pub fn IORegistryEntryFromPath( 397 | masterPort: mach_port_t, 398 | path: *mut c_char, 399 | ) -> io_registry_entry_t; 400 | 401 | pub fn IORegistryEntryCopyFromPath( 402 | masterPort: mach_port_t, 403 | path: CFStringRef, 404 | ) -> io_registry_entry_t; 405 | } 406 | 407 | pub const kIORegistryIterateRecursively: u32 = 0x00000001; 408 | pub const kIORegistryIterateParents: u32 = 0x00000002; 409 | 410 | extern "C" { 411 | pub fn IORegistryCreateIterator( 412 | masterPort: mach_port_t, 413 | plane: *const c_char, 414 | options: IOOptionBits, 415 | iterator: *mut io_iterator_t, 416 | ) -> kern_return_t; 417 | 418 | pub fn IORegistryEntryCreateIterator( 419 | entry: io_registry_entry_t, 420 | plane: *const c_char, 421 | options: IOOptionBits, 422 | iterator: *mut io_iterator_t, 423 | ) -> kern_return_t; 424 | } 425 | 426 | // IORegistryIterator, subclass of IOIterator 427 | extern "C" { 428 | pub fn IORegistryIteratorEnterEntry(iterator: io_iterator_t) -> kern_return_t; 429 | 430 | pub fn IORegistryIteratorExitEntry(iterator: io_iterator_t) -> kern_return_t; 431 | } 432 | 433 | // IORegistryEntry, subclass of IOObject 434 | extern "C" { 435 | pub fn IORegistryEntryGetName(entry: io_registry_entry_t, name: *mut c_char) -> kern_return_t; 436 | 437 | pub fn IORegistryEntryGetNameInPlane( 438 | entry: io_registry_entry_t, 439 | plane: *const c_char, 440 | name: *mut c_char, 441 | ) -> kern_return_t; 442 | 443 | pub fn IORegistryEntryGetLocationInPlane( 444 | entry: io_registry_entry_t, 445 | plane: *const c_char, 446 | location: *mut c_char, 447 | ) -> kern_return_t; 448 | 449 | pub fn IORegistryEntryGetPath( 450 | entry: io_registry_entry_t, 451 | plane: *const c_char, 452 | path: *mut c_char, 453 | ) -> kern_return_t; 454 | 455 | pub fn IORegistryEntryCopyPath(entry: io_registry_entry_t, plane: *const c_char) 456 | -> CFStringRef; 457 | 458 | pub fn IORegistryEntryGetRegistryEntryID( 459 | entry: io_registry_entry_t, 460 | entryID: *mut u64, 461 | ) -> kern_return_t; 462 | 463 | pub fn IORegistryEntryCreateCFProperties( 464 | entry: io_registry_entry_t, 465 | properties: *mut CFMutableDictionaryRef, 466 | allocator: CFAllocatorRef, 467 | options: IOOptionBits, 468 | ) -> kern_return_t; 469 | 470 | pub fn IORegistryEntryCreateCFProperty( 471 | entry: io_registry_entry_t, 472 | key: CFStringRef, 473 | allocator: CFAllocatorRef, 474 | options: IOOptionBits, 475 | ) -> CFTypeRef; 476 | 477 | pub fn IORegistryEntrySearchCFProperty( 478 | entry: io_registry_entry_t, 479 | plane: *const c_char, 480 | key: CFStringRef, 481 | allocator: CFAllocatorRef, 482 | options: IOOptionBits, 483 | ) -> CFTypeRef; 484 | 485 | #[deprecated( 486 | since = "0.1.0", 487 | note = "please use `IORegistryEntryCreateCFProperty` instead" 488 | )] 489 | pub fn IORegistryEntryGetProperty( 490 | entry: io_registry_entry_t, 491 | propertyName: *mut c_char, 492 | buffer: *mut c_char, 493 | size: *mut u32, 494 | ) -> kern_return_t; 495 | 496 | pub fn IORegistryEntrySetCFProperties( 497 | entry: io_registry_entry_t, 498 | properties: CFTypeRef, 499 | ) -> kern_return_t; 500 | 501 | pub fn IORegistryEntrySetCFProperty( 502 | entry: io_registry_entry_t, 503 | propertyName: CFStringRef, 504 | property: CFTypeRef, 505 | ) -> kern_return_t; 506 | 507 | pub fn IORegistryEntryGetChildIterator( 508 | entry: io_registry_entry_t, 509 | plane: *const c_char, 510 | iterator: *mut io_iterator_t, 511 | ) -> kern_return_t; 512 | 513 | pub fn IORegistryEntryGetChildEntry( 514 | entry: io_registry_entry_t, 515 | plane: *const c_char, 516 | child: *mut io_registry_entry_t, 517 | ) -> kern_return_t; 518 | 519 | pub fn IORegistryEntryGetParentIterator( 520 | entry: io_registry_entry_t, 521 | plane: *const c_char, 522 | iterator: *mut io_iterator_t, 523 | ) -> kern_return_t; 524 | 525 | pub fn IORegistryEntryGetParentEntry( 526 | entry: io_registry_entry_t, 527 | plane: *const c_char, 528 | parent: *mut io_registry_entry_t, 529 | ) -> kern_return_t; 530 | 531 | pub fn IORegistryEntryInPlane(entry: io_registry_entry_t, plane: *const c_char) -> boolean_t; 532 | } 533 | 534 | // Matching dictionary creation helpers 535 | extern "C" { 536 | pub fn IOServiceMatching(name: *const c_char) -> CFMutableDictionaryRef; 537 | 538 | pub fn IOServiceNameMatching(name: *const c_char) -> CFMutableDictionaryRef; 539 | 540 | pub fn IOBSDNameMatching( 541 | masterPort: mach_port_t, 542 | options: u32, 543 | bsdName: *const c_char, 544 | ) -> CFMutableDictionaryRef; 545 | 546 | pub fn IOOpenFirmwarePathMatching( 547 | masterPort: mach_port_t, 548 | options: u32, 549 | path: *const c_char, 550 | ) -> CFMutableDictionaryRef; 551 | 552 | pub fn IORegistryEntryIDMatching(entryID: u64) -> CFMutableDictionaryRef; 553 | 554 | pub fn IOServiceOFPathToBSDName( 555 | masterPort: mach_port_t, 556 | openFirmwarePath: *const c_char, 557 | bsdName: *mut c_char, 558 | ) -> kern_return_t; 559 | } 560 | 561 | pub type IOAsyncCallback0 = Option; 562 | 563 | pub type IOAsyncCallback1 = 564 | Option; 565 | 566 | pub type IOAsyncCallback2 = Option< 567 | unsafe extern "C" fn( 568 | refcon: *mut c_void, 569 | result: IOReturn, 570 | arg0: *mut c_void, 571 | arg1: *mut c_void, 572 | ), 573 | >; 574 | 575 | pub type IOAsyncCallback = Option< 576 | unsafe extern "C" fn( 577 | refcon: *mut c_void, 578 | result: IOReturn, 579 | args: *mut *mut c_void, 580 | numArgs: u32, 581 | ), 582 | >; 583 | 584 | #[cfg(test)] 585 | mod tests { 586 | use super::*; 587 | use std::ffi::CString; 588 | 589 | #[test] 590 | fn test_cfstr_creates_nonnull_cfstringref() { 591 | unsafe { 592 | let test_str = CString::new("Test").unwrap(); 593 | let cf_str = CFSTR(test_str.as_ptr()); 594 | assert!(!cf_str.is_null()); 595 | } 596 | } 597 | 598 | #[test] 599 | fn test_io_master_port_function() { 600 | use mach2::kern_return::KERN_SUCCESS; 601 | unsafe { 602 | let mut master_port: mach_port_t = 0; 603 | let result = IOMasterPort(kIOMasterPortDefault, &mut master_port); 604 | // IOMasterPort should succeed 605 | assert_eq!(result, KERN_SUCCESS); 606 | } 607 | } 608 | 609 | #[test] 610 | fn test_io_service_matching_returns_nonnull() { 611 | unsafe { 612 | let name = CString::new("IOHIDDevice").unwrap(); 613 | let matching = IOServiceMatching(name.as_ptr()); 614 | // IOServiceMatching should return a non-null dictionary 615 | assert!(!matching.is_null()); 616 | } 617 | } 618 | 619 | #[test] 620 | fn test_io_iterator_type_size() { 621 | // Ensure the iterator type has the expected size 622 | assert_eq!(std::mem::size_of::(), std::mem::size_of::()); 623 | } 624 | 625 | #[test] 626 | fn test_io_object_type_size() { 627 | // Ensure the object type has the expected size 628 | assert_eq!(std::mem::size_of::(), std::mem::size_of::()); 629 | } 630 | 631 | #[test] 632 | fn test_kern_success_constant() { 633 | use mach2::kern_return::KERN_SUCCESS; 634 | // Verify KERN_SUCCESS is 0 as expected 635 | assert_eq!(KERN_SUCCESS, 0); 636 | } 637 | } 638 | -------------------------------------------------------------------------------- /io-kit-sys/src/pwr_mgt/pm.rs: -------------------------------------------------------------------------------- 1 | // exports from 2 | 3 | // IOPMMaxPowerStates 4 | pub const kIOPMMaxPowerStates: u32 = 10; 5 | pub const IOPMMaxPowerStates: u32 = kIOPMMaxPowerStates; 6 | 7 | // IOPMPowerFlags 8 | pub type IOPMPowerFlags = ::std::os::raw::c_ulong; 9 | pub const kIOPMPowerOn: u32 = 0x00000002; 10 | pub const kIOPMDeviceUsable: u32 = 0x00008000; 11 | pub const kIOPMLowPower: u32 = 0x00010000; 12 | pub const kIOPMPreventIdleSleep: u32 = 0x00000040; 13 | pub const kIOPMSleepCapability: u32 = 0x00000004; 14 | pub const kIOPMRestartCapability: u32 = 0x00000080; 15 | pub const kIOPMSleep: u32 = 0x00000001; 16 | pub const kIOPMRestart: u32 = 0x00000080; 17 | pub const kIOPMInitialDeviceState: u32 = 0x00000100; 18 | pub const kIOPMRootDomainState: u32 = 0x00000200; 19 | 20 | // Private IOPMPowerFlags 21 | pub const kIOPMClockNormal: u32 = 0x0004; 22 | pub const kIOPMClockRunning: u32 = 0x0008; 23 | pub const kIOPMPreventSystemSleep: u32 = 0x0010; 24 | pub const kIOPMDoze: u32 = 0x0400; 25 | pub const kIOPMChildClamp: u32 = 0x0080; 26 | pub const kIOPMChildClamp2: u32 = 0x0200; 27 | pub const kIOPMNotPowerManaged: u32 = 0x0800; 28 | 29 | // Deprecated IOPMPowerFlags 30 | pub const kIOPMMaxPerformance: u32 = 0x4000; 31 | pub const kIOPMPassThrough: u32 = 0x0100; 32 | pub const kIOPMAuxPowerOn: u32 = 0x0020; 33 | pub const kIOPMNotAttainable: u32 = 0x0001; 34 | pub const kIOPMContextRetained: u32 = 0x2000; 35 | pub const kIOPMConfigRetained: u32 = 0x1000; 36 | pub const kIOPMStaticPowerValid: u32 = 0x0800; 37 | pub const kIOPMSoftSleep: u32 = 0x0400; 38 | pub const kIOPMCapabilitiesMask: u32 = kIOPMPowerOn 39 | | kIOPMDeviceUsable 40 | | kIOPMMaxPerformance 41 | | kIOPMContextRetained 42 | | kIOPMConfigRetained 43 | | kIOPMSleepCapability 44 | | kIOPMRestartCapability; 45 | 46 | // Support for old names of IOPMPowerFlag constants 47 | pub const IOPMNotAttainable: u32 = kIOPMNotAttainable; 48 | pub const IOPMPowerOn: u32 = kIOPMPowerOn; 49 | pub const IOPMClockNormal: u32 = kIOPMClockNormal; 50 | pub const IOPMClockRunning: u32 = kIOPMClockRunning; 51 | pub const IOPMAuxPowerOn: u32 = kIOPMAuxPowerOn; 52 | pub const IOPMDeviceUsable: u32 = kIOPMDeviceUsable; 53 | pub const IOPMMaxPerformance: u32 = kIOPMMaxPerformance; 54 | pub const IOPMContextRetained: u32 = kIOPMContextRetained; 55 | pub const IOPMConfigRetained: u32 = kIOPMConfigRetained; 56 | pub const IOPMNotPowerManaged: u32 = kIOPMNotPowerManaged; 57 | pub const IOPMSoftSleep: u32 = kIOPMSoftSleep; 58 | 59 | pub const kIOPMNextHigherState: u32 = 1; 60 | pub const kIOPMHighestState: u32 = 2; 61 | pub const kIOPMNextLowerState: u32 = 3; 62 | pub const kIOPMLowestState: u32 = 4; 63 | 64 | pub const IOPMNextHigherState: u32 = kIOPMNextHigherState; 65 | pub const IOPMHighestState: u32 = kIOPMHighestState; 66 | pub const IOPMNextLowerState: u32 = kIOPMNextLowerState; 67 | pub const IOPMLowestState: u32 = kIOPMLowestState; 68 | 69 | // Internal commands used by power managment command queue 70 | pub const kIOPMBroadcastAggressiveness: u32 = 1; 71 | pub const kIOPMUnidleDevice: u32 = 2; 72 | 73 | // Power consumption unknown value 74 | pub const kIOPMUnknown: u32 = 0xFFFF; 75 | 76 | // AppleClamshellState 77 | pub const kAppleClamshellStateKey: *const ::std::os::raw::c_char = 78 | b"AppleClamshellState\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 79 | 80 | // AppleClamshellCausesSleep 81 | pub const kAppleClamshellCausesSleepKey: *const ::std::os::raw::c_char = 82 | b"AppleClamshellCausesSleep\x00" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 83 | 84 | // kIOPMSleepWakeUUIDKey 85 | pub const kIOPMSleepWakeUUIDKey: *const ::std::os::raw::c_char = 86 | b"SleepWakeUUID\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 87 | 88 | // kIOPMBootSessionUUIDKey 89 | pub const kIOPMBootSessionUUIDKey: *const ::std::os::raw::c_char = 90 | b"BootSessionUUID\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 91 | 92 | // kIOPMDeepSleepEnabledKey 93 | pub const kIOPMDeepSleepEnabledKey: *const ::std::os::raw::c_char = 94 | b"Standby Enabled\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 95 | 96 | // kIOPMDeepSleepDelayKey 97 | pub const kIOPMDeepSleepDelayKey: *const ::std::os::raw::c_char = 98 | b"Standby Delay\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 99 | 100 | // kIOPMDeepSleepDelayHighKey 101 | pub const kIOPMDeepSleepDelayHighKey: *const ::std::os::raw::c_char = 102 | b"High Standby Delay\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 103 | 104 | // kIOPMLowBatteryThresholdKey 105 | pub const kIOPMStandbyBatteryThresholdKey: *const ::std::os::raw::c_char = 106 | b"Standby Battery Threshold\x00" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 107 | 108 | // kIOPMDestroyFVKeyOnStandbyKey 109 | pub const kIOPMDestroyFVKeyOnStandbyKey: *const ::std::os::raw::c_char = 110 | b"DestroyFVKeyOnStandby\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 111 | 112 | // kIOPMResetPowerStateOnWakeKey 113 | pub const kIOPMResetPowerStateOnWakeKey: *const ::std::os::raw::c_char = 114 | b"IOPMResetPowerStateOnWake\x00" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 115 | 116 | // Driver Assertion bitfield description 117 | pub const kIOPMDriverAssertionCPUBit: u32 = 0x01; 118 | pub const kIOPMDriverAssertionUSBExternalDeviceBit: u32 = 0x04; 119 | pub const kIOPMDriverAssertionBluetoothHIDDevicePairedBit: u32 = 0x08; 120 | pub const kIOPMDriverAssertionExternalMediaMountedBit: u32 = 0x10; 121 | pub const kIOPMDriverAssertionReservedBit5: u32 = 0x20; 122 | pub const kIOPMDriverAssertionPreventDisplaySleepBit: u32 = 0x40; 123 | pub const kIOPMDriverAssertionReservedBit7: u32 = 0x80; 124 | pub const kIOPMDriverAssertionMagicPacketWakeEnabledBit: u32 = 0x100; 125 | pub const kIOPMDriverAssertionNetworkKeepAliveActiveBit: u32 = 0x200; 126 | 127 | // kIOPMAssertionsDriverKey 128 | pub const kIOPMAssertionsDriverKey: *const ::std::os::raw::c_char = 129 | b"DriverPMAssertions\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 130 | pub const kIOPMAssertionsDriverDetailedKey: *const ::std::os::raw::c_char = 131 | b"DriverPMAssertionsDetailed\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 132 | 133 | // Kernel Driver assertion detailed dictionary keys 134 | pub const kIOPMDriverAssertionIDKey: *const ::std::os::raw::c_char = 135 | b"ID\x00" as *const [u8; 3usize] as *const ::std::os::raw::c_char; 136 | pub const kIOPMDriverAssertionCreatedTimeKey: *const ::std::os::raw::c_char = 137 | b"CreatedTime\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 138 | pub const kIOPMDriverAssertionModifiedTimeKey: *const ::std::os::raw::c_char = 139 | b"ModifiedTime\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 140 | pub const kIOPMDriverAssertionOwnerStringKey: *const ::std::os::raw::c_char = 141 | b"Owner\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 142 | pub const kIOPMDriverAssertionOwnerServiceKey: *const ::std::os::raw::c_char = 143 | b"ServicePtr\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 144 | pub const kIOPMDriverAssertionRegistryEntryIDKey: *const ::std::os::raw::c_char = 145 | b"RegistryEntryID\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 146 | pub const kIOPMDriverAssertionLevelKey: *const ::std::os::raw::c_char = 147 | b"Level\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 148 | pub const kIOPMDriverAssertionAssertedKey: *const ::std::os::raw::c_char = 149 | b"Assertions\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 150 | 151 | // Root Domain general interest messages 152 | pub const kClamshellStateBit: u32 = 1 << 0; 153 | pub const kClamshellSleepBit: u32 = 1 << 1; 154 | pub const kInflowForciblyEnabledBit: u32 = 1 << 0; 155 | 156 | // Power commands issued to root domain 157 | pub const kIOPMSleepNow: u32 = 1 << 0; 158 | pub const kIOPMAllowSleep: u32 = 1 << 1; 159 | pub const kIOPMPreventSleep: u32 = 1 << 2; 160 | pub const kIOPMPowerButton: u32 = 1 << 3; 161 | pub const kIOPMClamshellClosed: u32 = 1 << 4; 162 | pub const kIOPMPowerEmergency: u32 = 1 << 5; 163 | pub const kIOPMDisableClamshell: u32 = 1 << 6; 164 | pub const kIOPMEnableClamshell: u32 = 1 << 7; 165 | pub const kIOPMProcessorSpeedChange: u32 = 1 << 8; 166 | pub const kIOPMOverTemp: u32 = 1 << 9; 167 | pub const kIOPMClamshellOpened: u32 = 1 << 10; 168 | pub const kIOPMDWOverTemp: u32 = 1 << 11; 169 | 170 | // Power Management Return Codes 171 | pub const kIOPMNoErr: u32 = 0; 172 | pub const kIOPMAckImplied: u32 = 0; 173 | pub const kIOPMWillAckLater: u32 = 1; 174 | pub const kIOPMBadSpecification: u32 = 4; 175 | pub const kIOPMNoSuchState: u32 = 5; 176 | pub const kIOPMCannotRaisePower: u32 = 6; 177 | pub const kIOPMParameterError: u32 = 7; 178 | pub const kIOPMNotYetInitialized: u32 = 8; 179 | // And the old constants; deprecated 180 | pub const IOPMNoErr: u32 = kIOPMNoErr; 181 | pub const IOPMAckImplied: u32 = kIOPMAckImplied; 182 | pub const IOPMWillAckLater: u32 = kIOPMWillAckLater; 183 | pub const IOPMBadSpecification: u32 = kIOPMBadSpecification; 184 | pub const IOPMNoSuchState: u32 = kIOPMNoSuchState; 185 | pub const IOPMCannotRaisePower: u32 = kIOPMCannotRaisePower; 186 | pub const IOPMParameterError: u32 = kIOPMParameterError; 187 | pub const IOPMNotYetInitialized: u32 = kIOPMNotYetInitialized; 188 | 189 | // IOPMPowerSource class descriptive strings 190 | pub const kIOPMPSExternalConnectedKey: *const ::std::os::raw::c_char = 191 | b"ExternalConnected\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 192 | pub const kIOPMPSExternalChargeCapableKey: *const ::std::os::raw::c_char = 193 | b"ExternalChargeCapable\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 194 | pub const kIOPMPSBatteryInstalledKey: *const ::std::os::raw::c_char = 195 | b"BatteryInstalled\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 196 | pub const kIOPMPSIsChargingKey: *const ::std::os::raw::c_char = 197 | b"IsCharging\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 198 | pub const kIOPMFullyChargedKey: *const ::std::os::raw::c_char = 199 | b"FullyCharged\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 200 | pub const kIOPMPSAtWarnLevelKey: *const ::std::os::raw::c_char = 201 | b"AtWarnLevel\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 202 | pub const kIOPMPSAtCriticalLevelKey: *const ::std::os::raw::c_char = 203 | b"AtCriticalLevel\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 204 | pub const kIOPMPSCurrentCapacityKey: *const ::std::os::raw::c_char = 205 | b"CurrentCapacity\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 206 | pub const kIOPMPSMaxCapacityKey: *const ::std::os::raw::c_char = 207 | b"MaxCapacity\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 208 | pub const kIOPMPSDesignCapacityKey: *const ::std::os::raw::c_char = 209 | b"DesignCapacity\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 210 | pub const kIOPMPSTimeRemainingKey: *const ::std::os::raw::c_char = 211 | b"TimeRemaining\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 212 | pub const kIOPMPSAmperageKey: *const ::std::os::raw::c_char = 213 | b"Amperage\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 214 | pub const kIOPMPSVoltageKey: *const ::std::os::raw::c_char = 215 | b"Voltage\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 216 | pub const kIOPMPSCycleCountKey: *const ::std::os::raw::c_char = 217 | b"CycleCount\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 218 | pub const kIOPMPSMaxErrKey: *const ::std::os::raw::c_char = 219 | b"MaxErr\x00" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 220 | pub const kIOPMPSAdapterInfoKey: *const ::std::os::raw::c_char = 221 | b"AdapterInfo\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 222 | pub const kIOPMPSLocationKey: *const ::std::os::raw::c_char = 223 | b"Location\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 224 | pub const kIOPMPSErrorConditionKey: *const ::std::os::raw::c_char = 225 | b"ErrorCondition\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 226 | pub const kIOPMPSManufacturerKey: *const ::std::os::raw::c_char = 227 | b"Manufacturer\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 228 | pub const kIOPMPSManufactureDateKey: *const ::std::os::raw::c_char = 229 | b"ManufactureDate\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 230 | pub const kIOPMPSModelKey: *const ::std::os::raw::c_char = 231 | b"Model\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 232 | pub const kIOPMPSSerialKey: *const ::std::os::raw::c_char = 233 | b"Serial\x00" as *const [u8; 7usize] as *const ::std::os::raw::c_char; 234 | pub const kIOPMDeviceNameKey: *const ::std::os::raw::c_char = 235 | b"DeviceName\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 236 | pub const kIOPMPSLegacyBatteryInfoKey: *const ::std::os::raw::c_char = 237 | b"LegacyBatteryInfo\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 238 | pub const kIOPMPSBatteryHealthKey: *const ::std::os::raw::c_char = 239 | b"BatteryHealth\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 240 | pub const kIOPMPSHealthConfidenceKey: *const ::std::os::raw::c_char = 241 | b"HealthConfidence\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 242 | pub const kIOPMPSCapacityEstimatedKey: *const ::std::os::raw::c_char = 243 | b"CapacityEstimated\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 244 | pub const kIOPMPSBatteryChargeStatusKey: *const ::std::os::raw::c_char = 245 | b"ChargeStatus\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 246 | pub const kIOPMPSBatteryTemperatureKey: *const ::std::os::raw::c_char = 247 | b"Temperature\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 248 | pub const kIOPMPSAdapterDetailsKey: *const ::std::os::raw::c_char = 249 | b"AdapterDetails\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 250 | pub const kIOPMPSChargerConfigurationKey: *const ::std::os::raw::c_char = 251 | b"ChargerConfiguration\x00" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 252 | 253 | // kIOPMPSBatteryChargeStatusKey may have one of the following values 254 | pub const kIOPMBatteryChargeStatusTooHot: *const ::std::os::raw::c_char = 255 | b"HighTemperature\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 256 | pub const kIOPMBatteryChargeStatusTooCold: *const ::std::os::raw::c_char = 257 | b"LowTemperature\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 258 | pub const kIOPMBatteryChargeStatusTooHotOrCold: *const ::std::os::raw::c_char = 259 | b"HighOrLowTemperature\x00" as *const [u8; 21usize] as *const ::std::os::raw::c_char; 260 | pub const kIOPMBatteryChargeStatusGradient: *const ::std::os::raw::c_char = 261 | b"BatteryTemperatureGradient\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 262 | 263 | // Definitions for battery location, in case of multiple batteries. 264 | pub const kIOPMPSLocationLeft: u32 = 1001; 265 | pub const kIOPMPSLocationRight: u32 = 1002; 266 | 267 | // Battery quality health types, specified by BatteryHealth and HealthConfidence 268 | pub const kIOPMUndefinedValue: u32 = 0; 269 | pub const kIOPMPoorValue: u32 = 1; 270 | pub const kIOPMFairValue: u32 = 2; 271 | pub const kIOPMGoodValue: u32 = 3; 272 | 273 | // Keys for kIOPMPSAdapterDetailsKey dictionary 274 | pub const kIOPMPSAdapterDetailsIDKey: *const ::std::os::raw::c_char = 275 | b"AdapterID\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 276 | pub const kIOPMPSAdapterDetailsWattsKey: *const ::std::os::raw::c_char = 277 | b"Watts\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 278 | pub const kIOPMPSAdapterDetailsRevisionKey: *const ::std::os::raw::c_char = 279 | b"AdapterRevision\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 280 | pub const kIOPMPSAdapterDetailsSerialNumberKey: *const ::std::os::raw::c_char = 281 | b"SerialNumber\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 282 | pub const kIOPMPSAdapterDetailsFamilyKey: *const ::std::os::raw::c_char = 283 | b"FamilyCode\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 284 | pub const kIOPMPSAdapterDetailsAmperageKey: *const ::std::os::raw::c_char = 285 | b"Amperage\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 286 | pub const kIOPMPSAdapterDetailsDescriptionKey: *const ::std::os::raw::c_char = 287 | b"Description\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 288 | pub const kIOPMPSAdapterDetailsPMUConfigurationKey: *const ::std::os::raw::c_char = 289 | b"PMUConfiguration\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 290 | pub const kIOPMPSAdapterDetailsVoltage: *const ::std::os::raw::c_char = 291 | b"AdapterVoltage\x00" as *const [u8; 15usize] as *const ::std::os::raw::c_char; 292 | pub const kIOPMPSAdapterDetailsSourceIDKey: *const ::std::os::raw::c_char = 293 | b"SourceID\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 294 | pub const kIOPMPSAdapterDetailsErrorFlagsKey: *const ::std::os::raw::c_char = 295 | b"ErrorFlags\x00" as *const [u8; 11usize] as *const ::std::os::raw::c_char; 296 | pub const kIOPMPSAdapterDetailsSharedSourceKey: *const ::std::os::raw::c_char = 297 | b"SharedSource\x00" as *const [u8; 13usize] as *const ::std::os::raw::c_char; 298 | pub const kIOPMPSAdapterDetailsCloakedKey: *const ::std::os::raw::c_char = 299 | b"CloakedSource\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 300 | 301 | // values for kIOPSPowerAdapterFamilyKey 302 | pub const kIOPSFamilyCodeDisconnected: i32 = 0; 303 | pub const kIOPSFamilyCodeUnsupported: i32 = -536870201; 304 | pub const kIOPSFamilyCodeFirewire: i32 = -536838144; 305 | pub const kIOPSFamilyCodeUSBHost: i32 = -536854528; 306 | pub const kIOPSFamilyCodeUSBHostSuspended: i32 = -536854527; 307 | pub const kIOPSFamilyCodeUSBDevice: i32 = -536854526; 308 | pub const kIOPSFamilyCodeUSBAdapter: i32 = -536854525; 309 | pub const kIOPSFamilyCodeUSBChargingPortDedicated: i32 = -536854524; 310 | pub const kIOPSFamilyCodeUSBChargingPortDownstream: i32 = -536854523; 311 | pub const kIOPSFamilyCodeUSBChargingPort: i32 = -536854522; 312 | pub const kIOPSFamilyCodeUSBUnknown: i32 = -536854521; 313 | pub const kIOPSFamilyCodeUSBCBrick: i32 = -536854520; 314 | pub const kIOPSFamilyCodeUSBCTypeC: i32 = -536854519; 315 | pub const kIOPSFamilyCodeUSBCPD: i32 = -536854518; 316 | pub const kIOPSFamilyCodeAC: i32 = -536723456; 317 | pub const kIOPSFamilyCodeExternal: i32 = -536723455; 318 | pub const kIOPSFamilyCodeExternal2: i32 = -536723454; 319 | pub const kIOPSFamilyCodeExternal3: i32 = -536723453; 320 | pub const kIOPSFamilyCodeExternal4: i32 = -536723452; 321 | pub const kIOPSFamilyCodeExternal5: i32 = -536723451; 322 | 323 | // values for kIOPMPSAdapterDetailsErrorFlagsKey 324 | pub const kIOPSAdapterErrorFlagNoErrors: u32 = 0; 325 | pub const kIOPSAdapterErrorFlagInsufficientAvailablePower: u32 = 2; 326 | pub const kIOPSAdapterErrorFlagForeignObjectDetected: u32 = 4; 327 | pub const kIOPSAdapterErrorFlagDeviceNeedsToBeRepositioned: u32 = 8; 328 | 329 | pub const kIOPMPSInvalidWakeSecondsKey: *const ::std::os::raw::c_char = 330 | b"BatteryInvalidWakeSeconds\x00" as *const [u8; 26usize] as *const ::std::os::raw::c_char; 331 | pub const kIOPMPSPostChargeWaitSecondsKey: *const ::std::os::raw::c_char = 332 | b"PostChargeWaitSeconds\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 333 | pub const kIOPMPSPostDishargeWaitSecondsKey: *const ::std::os::raw::c_char = 334 | b"PostDischargeWaitSeconds\x00" as *const [u8; 25usize] as *const ::std::os::raw::c_char; 335 | 336 | // CPU Power Management status keys 337 | pub const kIOPMGraphicsPowerLimitsKey: *const ::std::os::raw::c_char = 338 | b"Graphics_Power_Limits\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 339 | pub const kIOPMGraphicsPowerLimitPerformanceKey: *const ::std::os::raw::c_char = 340 | b"Graphics_Power_Performance\x00" as *const [u8; 27usize] as *const ::std::os::raw::c_char; 341 | pub const kIOPMCPUPowerLimitsKey: *const ::std::os::raw::c_char = 342 | b"CPU_Power_Limits\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 343 | pub const kIOPMCPUPowerLimitProcessorSpeedKey: *const ::std::os::raw::c_char = 344 | b"CPU_Speed_Limit\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 345 | pub const kIOPMCPUPowerLimitProcessorCountKey: *const ::std::os::raw::c_char = 346 | b"CPU_Available_CPUs\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 347 | pub const kIOPMCPUPowerLimitSchedulerTimeKey: *const ::std::os::raw::c_char = 348 | b"CPU_Scheduler_Limit\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 349 | pub const kIOPMThermalLevelWarningKey: *const ::std::os::raw::c_char = 350 | b"Thermal_Level_Warning\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 351 | 352 | // Thermal Warning Level values 353 | pub const kIOPMThermalLevelNormal: u32 = 0; 354 | pub const kIOPMThermalLevelDanger: u32 = 5; 355 | pub const kIOPMThermalLevelCritical: u32 = 10; 356 | pub const kIOPMThermalLevelWarning: u32 = 100; 357 | pub const kIOPMThermalLevelTrap: u32 = 110; 358 | pub const kIOPMThermalLevelUnknown: u32 = 255; 359 | 360 | // PM Settings Controller setting types 361 | pub const kIOPMSettingWakeOnRingKey: *const ::std::os::raw::c_char = 362 | b"Wake On Modem Ring\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 363 | pub const kIOPMSettingRestartOnPowerLossKey: *const ::std::os::raw::c_char = 364 | b"Automatic Restart On Power Loss\x00" as *const [u8; 32usize] as *const ::std::os::raw::c_char; 365 | pub const kIOPMSettingWakeOnACChangeKey: *const ::std::os::raw::c_char = 366 | b"Wake On AC Change\x00" as *const [u8; 18usize] as *const ::std::os::raw::c_char; 367 | pub const kIOPMSettingSleepOnPowerButtonKey: *const ::std::os::raw::c_char = 368 | b"Sleep On Power Button\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 369 | pub const kIOPMSettingWakeOnClamshellKey: *const ::std::os::raw::c_char = 370 | b"Wake On Clamshell Open\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 371 | pub const kIOPMSettingReduceBrightnessKey: *const ::std::os::raw::c_char = 372 | b"ReduceBrightness\x00" as *const [u8; 17usize] as *const ::std::os::raw::c_char; 373 | pub const kIOPMSettingDisplaySleepUsesDimKey: *const ::std::os::raw::c_char = 374 | b"Display Sleep Uses Dim\x00" as *const [u8; 23usize] as *const ::std::os::raw::c_char; 375 | pub const kIOPMSettingTimeZoneOffsetKey: *const ::std::os::raw::c_char = 376 | b"TimeZoneOffsetSeconds\x00" as *const [u8; 22usize] as *const ::std::os::raw::c_char; 377 | pub const kIOPMSettingMobileMotionModuleKey: *const ::std::os::raw::c_char = 378 | b"MobileMotionModule\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 379 | pub const kIOPMSettingGraphicsSwitchKey: *const ::std::os::raw::c_char = 380 | b"GPUSwitch\x00" as *const [u8; 10usize] as *const ::std::os::raw::c_char; 381 | 382 | // Setting controlling drivers can register to receive scheduled wake data 383 | pub const kIOPMSettingAutoWakeSecondsKey: *const ::std::os::raw::c_char = 384 | b"wake\x00" as *const [u8; 5usize] as *const ::std::os::raw::c_char; 385 | pub const kIOPMSettingAutoWakeCalendarKey: *const ::std::os::raw::c_char = 386 | b"WakeByCalendarDate\x00" as *const [u8; 19usize] as *const ::std::os::raw::c_char; 387 | pub const kIOPMSettingAutoPowerSecondsKey: *const ::std::os::raw::c_char = 388 | b"poweron\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 389 | pub const kIOPMSettingAutoPowerCalendarKey: *const ::std::os::raw::c_char = 390 | b"PowerByCalendarDate\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 391 | 392 | // Debug seconds auto wake 393 | pub const kIOPMSettingDebugWakeRelativeKey: *const ::std::os::raw::c_char = 394 | b"WakeRelativeToSleep\x00" as *const [u8; 20usize] as *const ::std::os::raw::c_char; 395 | pub const kIOPMSettingDebugPowerRelativeKey: *const ::std::os::raw::c_char = 396 | b"PowerRelativeToShutdown\x00" as *const [u8; 24usize] as *const ::std::os::raw::c_char; 397 | 398 | // Maintenance wake calendar. 399 | pub const kIOPMSettingMaintenanceWakeCalendarKey: *const ::std::os::raw::c_char = 400 | b"MaintenanceWakeCalendarDate\x00" as *const [u8; 28usize] as *const ::std::os::raw::c_char; 401 | 402 | // SetAggressiveness types 403 | pub const kPMGeneralAggressiveness: u32 = 0; 404 | pub const kPMMinutesToDim: u32 = 1; 405 | pub const kPMMinutesToSpinDown: u32 = 2; 406 | pub const kPMMinutesToSleep: u32 = 3; 407 | pub const kPMEthernetWakeOnLANSettings: u32 = 4; 408 | pub const kPMSetProcessorSpeed: u32 = 5; 409 | pub const kPMPowerSource: u32 = 6; 410 | pub const kPMMotionSensor: u32 = 7; 411 | pub const kPMLastAggressivenessType: u32 = 8; 412 | 413 | // SetAggressiveness values for the kPMPowerSource aggressiveness type 414 | pub const kIOPMInternalPower: u32 = 1; 415 | pub const kIOPMExternalPower: u32 = 2; 416 | 417 | pub const kIOREMSleepEnabledKey: *const ::std::os::raw::c_char = 418 | b"REMSleepEnabled\x00" as *const [u8; 16usize] as *const ::std::os::raw::c_char; 419 | 420 | // Strings for deciphering the dictionary returned from IOPMCopyBatteryInfo 421 | pub const kIOBatteryInfoKey: *const ::std::os::raw::c_char = 422 | b"IOBatteryInfo\x00" as *const [u8; 14usize] as *const ::std::os::raw::c_char; 423 | pub const kIOBatteryCurrentChargeKey: *const ::std::os::raw::c_char = 424 | b"Current\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 425 | pub const kIOBatteryCapacityKey: *const ::std::os::raw::c_char = 426 | b"Capacity\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 427 | pub const kIOBatteryFlagsKey: *const ::std::os::raw::c_char = 428 | b"Flags\x00" as *const [u8; 6usize] as *const ::std::os::raw::c_char; 429 | pub const kIOBatteryVoltageKey: *const ::std::os::raw::c_char = 430 | b"Voltage\x00" as *const [u8; 8usize] as *const ::std::os::raw::c_char; 431 | pub const kIOBatteryAmperageKey: *const ::std::os::raw::c_char = 432 | b"Amperage\x00" as *const [u8; 9usize] as *const ::std::os::raw::c_char; 433 | pub const kIOBatteryCycleCountKey: *const ::std::os::raw::c_char = 434 | b"Cycle Count\x00" as *const [u8; 12usize] as *const ::std::os::raw::c_char; 435 | 436 | pub const kIOBatteryInstalled: u32 = 1 << 2; 437 | pub const kIOBatteryCharge: u32 = 1 << 1; 438 | pub const kIOBatteryChargerConnect: u32 = 1 << 0; 439 | 440 | pub const IOPM_POWER_SOURCE_REV: u32 = 2; 441 | 442 | // For use with IOPMPowerSource bFlags 443 | pub const kIOPMACInstalled: u32 = kIOBatteryChargerConnect; 444 | pub const kIOPMBatteryCharging: u32 = kIOBatteryCharge; 445 | pub const kIOPMBatteryInstalled: u32 = kIOBatteryInstalled; 446 | pub const kIOPMUPSInstalled: u32 = 1 << 3; 447 | pub const kIOPMBatteryAtWarn: u32 = 1 << 4; 448 | pub const kIOPMBatteryDepleted: u32 = 1 << 5; 449 | pub const kIOPMACnoChargeCapability: u32 = 1 << 6; 450 | pub const kIOPMRawLowBattery: u32 = 1 << 7; 451 | pub const kIOPMForceLowSpeed: u32 = 1 << 8; 452 | pub const kIOPMClosedClamshell: u32 = 1 << 9; 453 | pub const kIOPMClamshellStateOnWake: u32 = 1 << 10; 454 | 455 | // IOPMSystemCapabilityChangeFlags 456 | pub const kIOPMSystemCapabilityWillChange: u32 = 0x01; 457 | pub const kIOPMSystemCapabilityDidChange: u32 = 0x02; 458 | 459 | pub const kIOPMSystemCapabilityCPU: u32 = 0x01; 460 | pub const kIOPMSystemCapabilityGraphics: u32 = 0x02; 461 | pub const kIOPMSystemCapabilityAudio: u32 = 0x04; 462 | pub const kIOPMSystemCapabilityNetwork: u32 = 0x08; 463 | 464 | #[repr(C)] 465 | #[derive(Debug, Copy, Clone)] 466 | pub struct IOPMCalendarStruct { 467 | pub year: ::std::os::raw::c_uint, 468 | pub month: ::std::os::raw::c_uchar, 469 | pub day: ::std::os::raw::c_uchar, 470 | pub hour: ::std::os::raw::c_uchar, 471 | pub minute: ::std::os::raw::c_uchar, 472 | pub second: ::std::os::raw::c_uchar, 473 | pub selector: ::std::os::raw::c_uchar, 474 | } 475 | 476 | #[repr(C)] 477 | #[derive(Debug, Copy, Clone)] 478 | pub struct IOPowerStateChangeNotification { 479 | pub powerRef: *mut ::std::os::raw::c_void, 480 | pub returnValue: ::std::os::raw::c_ulong, 481 | pub stateNumber: ::std::os::raw::c_ulong, 482 | pub stateFlags: IOPMPowerFlags, 483 | } 484 | pub type sleepWakeNote = IOPowerStateChangeNotification; 485 | 486 | #[repr(C)] 487 | #[derive(Debug, Copy, Clone)] 488 | pub struct IOPMSystemCapabilityChangeParameters { 489 | pub notifyRef: u32, 490 | pub maxWaitForReply: u32, 491 | pub changeFlags: u32, 492 | pub __reserved1: u32, 493 | pub fromCapabilities: u32, 494 | pub toCapabilities: u32, 495 | pub __reserved2: [u32; 4usize], 496 | } 497 | --------------------------------------------------------------------------------