this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

IOKit: more function, USB fixes

+141 -25
+1
src/IOKit/CMakeLists.txt
··· 22 22 port.c 23 23 service.mm 24 24 io_object.cpp 25 + io_iterator.cpp 25 26 io_device_iterator.cpp 26 27 io_device.cpp 27 28 io_device_usb.cpp
+1 -3
src/IOKit/constants.h
··· 1 1 #ifndef IOKIT_CONSTANTS_H 2 2 #define IOKIT_CONSTANTS_H 3 3 4 - #define kIOMasterPortDefault NULL 5 - 6 4 #define kIOProviderClassKey "IOProviderClass" 7 5 #define kIOBSDNameKey "BSD Name" 8 6 #define kIONameMatchKey "IONameMatch" ··· 35 33 // USB 36 34 #define kIOUSBDeviceClassName "IOUSBDevice" 37 35 #define kIOUSBInterfaceClassName "IOUSBInterface" 38 - #define kIOHIDDeviceKey "IOHIDDevice" 36 + #define kIOHIDDeviceKey "IOHIDDevice" 39 37 40 38 #endif 41 39
+10
src/IOKit/io_device.cpp
··· 1 1 #include "io_device.h" 2 2 #include <cstdlib> 3 + #include <cstring> 3 4 #include "cfutil.h" 4 5 5 6 static const property_mapping generic_properties[] = { ··· 18 19 io_device::~io_device() 19 20 { 20 21 udev_device_unref(m_device); 22 + } 23 + 24 + bool io_device::operator==(const io_object& that) 25 + { 26 + const io_device* dthat = dynamic_cast<const io_device*>(&that); 27 + if (!dthat) 28 + return false; 29 + 30 + return strcmp(udev_device_get_syspath(m_device), udev_device_get_syspath(dthat->m_device)) == 0; 21 31 } 22 32 23 33 const char* io_device::property(const char* name)
+2
src/IOKit/io_device.h
··· 12 12 public: 13 13 io_device(struct udev_device* device); 14 14 virtual ~io_device(); 15 + 15 16 virtual void properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator); 16 17 virtual CFTypeRef property(CFStringRef name, CFAllocatorRef allocator); 17 18 virtual io_device* parent(); 19 + virtual bool operator==(const io_object& that) override; 18 20 19 21 const char* sysname(); 20 22 const char* property(const char* name);
+14 -1
src/IOKit/io_device_iterator.cpp
··· 1 1 #include "io_device_iterator.h" 2 2 #include "io_device.h" 3 3 #include <libudev.h> 4 + #include <typeinfo> 4 5 5 6 io_device_iterator::io_device_iterator(udev_enumerate* uenum) 6 7 : m_uenum(uenum) 7 8 { 8 9 m_udev = udev_new(); 9 - m_next = udev_enumerate_get_list_entry(uenum); 10 + reset(); 11 + } 12 + 13 + void io_device_iterator::reset() 14 + { 15 + m_next = udev_enumerate_get_list_entry(m_uenum); 10 16 } 11 17 12 18 io_device_iterator::~io_device_iterator() 13 19 { 14 20 udev_enumerate_unref(m_uenum); 15 21 udev_unref(m_udev); 22 + } 23 + 24 + bool io_device_iterator::operator==(const io_object& that) 25 + { 26 + if (typeid(*this) != typeid(that)) 27 + return false; 28 + return m_uenum == ((io_device_iterator*)&that)->m_uenum; 16 29 } 17 30 18 31 io_object_t io_device_iterator::next()
+2
src/IOKit/io_device_iterator.h
··· 8 8 io_device_iterator(struct udev_enumerate* uenum); 9 9 virtual ~io_device_iterator(); 10 10 virtual io_object_t next() override; 11 + virtual void reset() override; 12 + virtual bool operator==(const io_object& that) override; 11 13 private: 12 14 struct udev* m_udev; 13 15 struct udev_enumerate* m_uenum;
+16
src/IOKit/io_iterator.cpp
··· 1 + #include "io_iterator.h" 2 + 3 + int IOIteratorIsValid(io_iterator_t iter) 4 + { 5 + return iter != nullptr; 6 + } 7 + 8 + io_object_t IOIteratorNext(io_iterator_t iter) 9 + { 10 + return iter->next(); 11 + } 12 + 13 + void IOIteratorReset(io_iterator_t iter) 14 + { 15 + iter->reset(); 16 + }
+5
src/IOKit/io_iterator.h
··· 6 6 { 7 7 public: 8 8 virtual io_object_t next() = 0; 9 + virtual void reset() = 0; 9 10 }; 10 11 11 12 typedef io_iterator* io_iterator_t; 13 + 14 + extern "C" int IOIteratorIsValid(io_iterator_t iter); 15 + extern "C" io_object_t IOIteratorNext(io_iterator_t iter); 16 + extern "C" void IOIteratorReset(io_iterator_t iter); 12 17 13 18 #endif
+42
src/IOKit/io_object.cpp
··· 1 1 #include "io_object.h" 2 2 3 + io_object::io_object() 4 + : m_refs(1) 5 + { 6 + } 7 + 3 8 io_object::~io_object() 4 9 { 5 10 } 6 11 12 + void io_object::retain() 13 + { 14 + m_refs++; 15 + } 16 + 17 + void io_object::release() 18 + { 19 + if (!(--m_refs)) 20 + delete this; 21 + } 22 + 23 + int IOObjectRetain(io_object_t obj) 24 + { 25 + obj->retain(); 26 + return 0; 27 + } 28 + 29 + int IOObjectRelease(io_object_t obj) 30 + { 31 + obj->release(); 32 + return 0; 33 + } 34 + 35 + uint32_t IOObjectGetRetainCount(io_object_t obj) 36 + { 37 + return obj->refs(); 38 + } 39 + 40 + uint32_t IOObjectGetUserRetainCount(io_object_t obj) 41 + { 42 + return obj->refs(); 43 + } 44 + 45 + bool IOObjectIsEqualTo(io_object_t o1, io_object_t o2) 46 + { 47 + return *o1 == *o2; 48 + }
+13
src/IOKit/io_object.h
··· 1 1 #ifndef IOKIT_IOOBJECT_H 2 2 #define IOKIT_IOOBJECT_H 3 + #include <stdint.h> 3 4 4 5 class io_object 5 6 { 6 7 public: 8 + io_object(); 7 9 virtual ~io_object(); 10 + virtual bool operator==(const io_object& that) = 0; 11 + 12 + void retain(); 13 + void release(); 14 + int refs() const { return m_refs; } 15 + private: 16 + int m_refs; 8 17 }; 9 18 10 19 typedef io_object* io_object_t; 11 20 21 + extern "C" int IOObjectRetain(io_object_t obj); 12 22 extern "C" int IOObjectRelease(io_object_t obj); 23 + extern "C" uint32_t IOObjectGetRetainCount(io_object_t obj); 24 + extern "C" uint32_t IOObjectGetUserRetainCount(io_object_t obj); 25 + extern "C" bool IOObjectIsEqualTo(io_object_t o1, io_object_t o2); 13 26 14 27 #endif 15 28
+4 -3
src/IOKit/service.h
··· 8 8 #include "io_iterator.h" 9 9 #include <CoreFoundation/CFDictionary.h> 10 10 11 + extern "C" const void* kIOMasterPortDefault; 12 + 11 13 // This seems to give all children (e.g. all USB devices) 12 14 extern "C" CFMutableDictionaryRef IOServiceMatching(const char* service); 13 15 // This seems to give the root device (e.g. the USB driver) ··· 15 17 extern "C" CFMutableDictionaryRef IOBSDNameMatching(void* iokitPort, unsigned int options, const char* bsdName); 16 18 17 19 extern "C" int IOServiceGetMatchingServices(void* port, CFDictionaryRef rules, io_iterator_t* iter); 18 - extern "C" int IOIteratorIsValid(io_iterator_t iter); 19 - extern "C" io_object_t IOIteratorNext(io_iterator_t iter); 20 - extern "C" int IOObjectRelease(io_object_t obj); 21 20 21 + extern "C" int IORegistryEntryGetParentEntry(io_object_t obj, void* planeName /* TODO */, io_object_t* parent); 22 + extern "C" CFTypeRef IORegistryEntryCreateCFProperty(io_object_t obj, CFStringRef key, CFAllocatorRef allocator, int opts); 22 23 extern "C" int IORegistryEntryCreateCFProperties(io_object_t obj, CFMutableDictionaryRef* props, CFAllocatorRef allocator, int opts); 23 24 24 25 #endif
+31 -18
src/IOKit/service.mm
··· 15 15 #include "io_device_iterator.h" 16 16 #include "cfutil.h" 17 17 18 + const void* kIOMasterPortDefault = 0; 19 + 18 20 static void filterByBSDName(struct udev_enumerate* uenum, CFStringRef str); 19 21 static void filterByClass(struct udev_enumerate* uenum, CFStringRef str); 20 22 static void filterByDriver(struct udev_enumerate* uenum, CFStringRef str); 21 23 static void filterByProperties(struct udev_enumerate* uenum, CFDictionaryRef dict); 22 - 23 - io_object_t IOIteratorNext(io_iterator_t iter) 24 - { 25 - return iter->next(); 26 - } 27 24 28 25 static CFMutableDictionaryRef createMatchingDictionary(CFStringRef key, CFStringRef value) 29 26 { ··· 81 78 return 0; 82 79 } 83 80 84 - int IOIteratorIsValid(io_iterator_t iter) 81 + int IORegistryEntryCreateCFProperties(io_object_t obj, CFMutableDictionaryRef* props, CFAllocatorRef allocator, int opts) 85 82 { 86 - return iter != nullptr; 83 + io_device* dev = dynamic_cast<io_device*>(obj); 84 + 85 + if (!dev) 86 + { 87 + *props = nullptr; 88 + return -4; 89 + } 90 + else 91 + { 92 + *props = CFDictionaryCreateMutable(allocator, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 93 + dev->properties(*props, allocator); 94 + return 0; 95 + } 87 96 } 88 97 89 - int IOObjectRelease(io_object_t obj) 98 + CFTypeRef IORegistryEntryCreateCFProperty(io_object_t obj, CFStringRef key, CFAllocatorRef allocator, int opts) 90 99 { 91 - delete obj; 92 - return 0; 93 - } 100 + io_device* dev = dynamic_cast<io_device*>(obj); 94 101 102 + if (!dev) 103 + return nullptr; 104 + else 105 + return dev->property(key, allocator); 106 + } 95 107 96 - int IORegistryEntryCreateCFProperties(io_object_t obj, CFMutableDictionaryRef* props, CFAllocatorRef allocator, int opts) 108 + int IORegistryEntryGetParentEntry(io_object_t obj, void* planeName /* TODO */, io_object_t* parent) 97 109 { 98 110 io_device* dev = dynamic_cast<io_device*>(obj); 99 - 100 111 if (!dev) 101 112 { 102 - *props = nullptr; 103 - return -4; 113 + *parent = nullptr; 114 + return -1; 104 115 } 105 116 else 106 117 { 107 - *props = CFDictionaryCreateMutable(allocator, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 108 - dev->properties(*props, allocator); 118 + *parent = dev->parent(); 109 119 return 0; 110 120 } 111 121 } ··· 117 127 else if (strCFEqual(str, kIOSerialBSDServiceValue)) 118 128 udev_enumerate_add_match_subsystem(uenum, "tty"); 119 129 else if (strCFEqual(str, kIOUSBDeviceClassName)) 120 - udev_enumerate_add_match_subsystem(uenum, "usb"); 130 + udev_enumerate_add_match_property(uenum, "DEVTYPE", "usb_device"); 131 + else if (strCFEqual(str, kIOUSBInterfaceClassName)) 132 + udev_enumerate_add_match_property(uenum, "DEVTYPE", "usb_interface"); 121 133 else if (strCFEqual(str, kIOHIDDeviceKey)) 122 134 udev_enumerate_add_match_subsystem(uenum, "hidraw"); 123 135 } ··· 132 144 { 133 145 const char* driver = nullptr; 134 146 147 + // TODO: USB interface vs. device 135 148 if (strCFEqual(str, "AppleUSBEHCI")) 136 149 driver = "ehci_hcd"; 137 150 else if (strCFEqual(str, "AppleUSBOHCI"))