this repo has no description
1
fork

Configure Feed

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

Remove `src/IOKit`

This code is no longer used

Thomas A 56c24582 d4b5a9ee

-1067
-43
src/IOKit/CMakeLists.txt
··· 1 - project(IOKit) 2 - 3 - cmake_minimum_required(VERSION 2.4.0) 4 - if(COMMAND cmake_policy) 5 - cmake_policy(SET CMP0003 NEW) 6 - endif(COMMAND cmake_policy) 7 - 8 - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -fconstant-string-class=NSConstantString -fobjc-nonfragile-abi -ggdb") 9 - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${DARLING_TOP_DIRECTORY}/darwin.map") 10 - 11 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 12 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) 13 - include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util) 14 - #include_directories(${DARLING_TOP_DIRECTORY}/src/external/libobjc2) 15 - include_directories(${DARLING_TOP_DIRECTORY}/src/external/corefoundation/Headers) 16 - include_directories(${CMAKE_BINARY_DIR}/src/external/corefoundation/Headers) 17 - include_directories(${DARLING_TOP_DIRECTORY}/src/external/foundation/Headers) 18 - include_directories(${DARLING_TOP_DIRECTORY}/basic-headers) 19 - 20 - add_definitions(-DOBJC2RUNTIME) 21 - 22 - set(IOKit_SRCS 23 - bsd.cpp 24 - port.c 25 - service.mm 26 - io_object.cpp 27 - io_iterator.cpp 28 - io_device_iterator.cpp 29 - io_device.cpp 30 - io_device_usb.cpp 31 - io_device_net.cpp 32 - ../util/debug.cpp 33 - ) 34 - 35 - SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/darling") 36 - SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 37 - SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 38 - 39 - add_library(IOKit SHARED ${IOKit_SRCS}) 40 - target_link_libraries(IOKit -ludev -lstdc++ CFF) 41 - 42 - install(TARGETS IOKit DESTINATION "${CMAKE_INSTALL_LIBDIR}/darling") 43 -
-56
src/IOKit/bsd.cpp
··· 1 - #include "bsd.h" 2 - #include "service.h" 3 - #include <cstring> 4 - #include <cstdio> 5 - #include <sys/types.h> 6 - #include <dirent.h> 7 - #include "constants.h" 8 - extern "C" { 9 - #include <CoreFoundation/CFString.h> 10 - } 11 - 12 - std::string DarlingTranslateBSDName(const char* name); 13 - bool DarlingFindBSDName(const char* name, char* path); 14 - 15 - #if 0 16 - CFMutableDictionaryRef IOBSDNameMatching(void* iokitPort, unsigned int options, const char* bsdName) 17 - { 18 - // Search /sys/class/* for a device called bsdName 19 - bsdName = DarlingTranslateBSDName(bsdName); 20 - 21 - char path[PATH_MAX]; 22 - 23 - if (DarlingFindBSDName(bsdName, path)) 24 - return IOServiceSysPath(path); 25 - else 26 - return NULL; 27 - } 28 - #endif 29 - 30 - 31 - std::string DarlingTranslateBSDName(const char* name) 32 - { 33 - int num; 34 - char linuxName[100]; 35 - 36 - // Macbooks have en0 = eth0, en1 = wlan0 37 - // We don't handle that yet 38 - if (sscanf(name, "en%d", &num) == 1) 39 - { 40 - sprintf(linuxName, "eth%d", num); 41 - return linuxName; 42 - } 43 - if (sscanf(name, "lo%d", &num) == 1) 44 - { 45 - return "lo"; 46 - } 47 - if (sscanf(name, "stf%d", &num) == 1) 48 - { 49 - sprintf(linuxName, "sit%d", num); 50 - return linuxName; 51 - } 52 - 53 - return name; 54 - } 55 - 56 -
-15
src/IOKit/bsd.h
··· 1 - #ifndef IOKIT_BSD_H 2 - #define IOKIT_BSD_H 3 - extern "C" { 4 - #include <CoreFoundation/CFDictionary.h> 5 - } 6 - #include <string> 7 - 8 - extern "C" 9 - CFMutableDictionaryRef IOBSDNameMatching(void* iokitPort, unsigned int options, const char* bsdName); 10 - 11 - std::string DarlingTranslateBSDName(const char* name); 12 - bool DarlingFindBSDName(const char* name, char* path); 13 - 14 - #endif 15 -
-30
src/IOKit/cfutil.h
··· 1 - #ifndef IOKIT_CFUTIL_H 2 - #define IOKIT_CFUTIL_H 3 - extern "C" { 4 - #include <CoreFoundation/CFString.h> 5 - #include <CoreFoundation/CFNumber.h> 6 - } 7 - #include <cstdlib> 8 - 9 - #define strCFEqual(cfs, cstr) (CFStringCompare(cfs, CFSTR(cstr), CFStringCompareFlags(0)) == 0) 10 - 11 - inline CFStringRef strToCF(const char* val, CFAllocatorRef all = kCFAllocatorDefault) 12 - { 13 - if (!val) 14 - return nullptr; 15 - return CFStringCreateWithCString(kCFAllocatorDefault, val, kCFStringEncodingUTF8); 16 - } 17 - 18 - inline CFNumberRef intToCF(int val, CFAllocatorRef all = kCFAllocatorDefault) 19 - { 20 - return CFNumberCreate(all, kCFNumberIntType, &val); 21 - } 22 - 23 - inline CFNumberRef intToCF(const char* val, CFAllocatorRef all = kCFAllocatorDefault) 24 - { 25 - if (!val) 26 - return nullptr; 27 - return intToCF(atoi(val), all); 28 - } 29 - 30 - #endif
-39
src/IOKit/constants.h
··· 1 - #ifndef IOKIT_CONSTANTS_H 2 - #define IOKIT_CONSTANTS_H 3 - 4 - #define kIOProviderClassKey "IOProviderClass" 5 - #define kIOBSDNameKey "BSD Name" 6 - #define kIONameMatchKey "IONameMatch" 7 - #define kIOPropertyMatchKey "IOPropertyMatch" 8 - #define kIOPathMatchKey "IOPathMatch" 9 - #define kIOLocationMatchKey "IOLocationMatch" 10 - #define kIOParentMatchKey "IOParentMatch" 11 - #define kIOResourceMatchKey "IOResourceMatch" 12 - #define kIOMatchedServiceCountKey "IOMatchedServiceCountMatch" 13 - #define kIONameMatchedKey "IONameMatched" 14 - #define kIOMatchCategoryKey "IOMatchCategory" 15 - #define kIODefaultMatchCategoryKey "IODefaultMatchCategory" 16 - 17 - // ethernet 18 - #define kIOEthernetAddressSize 6 19 - #define kIOEthernetInterfaceClass "IOEthernetInterface" 20 - 21 - // serial 22 - #define kIOSerialBSDServiceValue "IOSerialBSDClient" 23 - #define kIOSerialBSDAllTypes "IOSerialStream" 24 - #define kIOSerialBSDModemType "IOModemSerialStream" 25 - #define kIOSerialBSDRS232Type "IORS232SerialStream" 26 - 27 - #define kIOTTYDeviceKey "IOTTYDevice" 28 - #define kIOTTYBaseNameKey "IOTTYBaseName" 29 - #define kIOTTYSuffixKey "IOTTYSuffix" 30 - #define kIOCalloutDeviceKey "IOCalloutDevice" 31 - #define kIODialinDeviceKey "IODialinDevice" 32 - 33 - // USB 34 - #define kIOUSBDeviceClassName "IOUSBDevice" 35 - #define kIOUSBInterfaceClassName "IOUSBInterface" 36 - #define kIOHIDDeviceKey "IOHIDDevice" 37 - 38 - #endif 39 -
-161
src/IOKit/io_device.cpp
··· 1 - #include "io_device.h" 2 - #include <cstdlib> 3 - #include <cstring> 4 - #include "io_device_net.h" 5 - #include "cfutil.h" 6 - #include <util/debug.h> 7 - 8 - static CFTypeRef ListDevSymlinks(io_device* d, CFAllocatorRef a); 9 - 10 - static const property_mapping generic_properties[] = { 11 - property_mapping{ CFSTR("IOVendor"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { if (const char* name = d->property("ID_VENDOR")) return strToCF(name, a); else return strToCF(d->property("ID_VENDOR_FROM_DATABASE"), a); } }, 12 - property_mapping{ CFSTR("IOModel"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { if (const char* name = d->property("ID_MODEL")) return strToCF(name, a); else return strToCF(d->property("ID_MODEL_FROM_DATABASE"), a); } }, 13 - property_mapping{ CFSTR("BSD Name"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { if (const char* name = d->sysname()) return strToCF(name, a); else return strToCF(d->property("INTERFACE"), a); } }, // name or property INTERFACE 14 - property_mapping{ CFSTR("BSD Names"), ListDevSymlinks }, 15 - property_mapping{ CFSTR("BSD Major"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { return intToCF(d->property("MAJOR"), a); } }, 16 - property_mapping{ CFSTR("BSD Minor"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { return intToCF(d->property("MINOR"), a); } }, 17 - }; 18 - 19 - io_device::io_device(struct udev_device* dev) 20 - : m_device(dev) 21 - { 22 - } 23 - 24 - io_device::~io_device() 25 - { 26 - udev_device_unref(m_device); 27 - } 28 - 29 - io_device* io_device::create(udev_device* dev) 30 - { 31 - const char* subsystem = udev_device_get_subsystem(dev); 32 - 33 - LOG << "Creating an io_device for subsystem " << subsystem << std::endl; 34 - 35 - if (strcmp(subsystem, "net") == 0) 36 - return new io_device_net(dev); 37 - else 38 - return new io_device(dev); // generic device 39 - } 40 - 41 - bool io_device::operator==(const io_object& that) 42 - { 43 - const io_device* dthat = dynamic_cast<const io_device*>(&that); 44 - if (!dthat) 45 - return false; 46 - 47 - return strcmp(udev_device_get_syspath(m_device), udev_device_get_syspath(dthat->m_device)) == 0; 48 - } 49 - 50 - const char* io_device::property(const char* name) 51 - { 52 - return udev_device_get_property_value(m_device, name); 53 - } 54 - 55 - const char* io_device::sysattr(const char* name) 56 - { 57 - return udev_device_get_sysattr_value(m_device, name); 58 - } 59 - 60 - CFStringRef io_device::sysattrStr(const char* name, CFAllocatorRef allocator) 61 - { 62 - return strToCF(sysattr(name), allocator); 63 - } 64 - 65 - CFNumberRef io_device::sysattrNum(const char* name, CFAllocatorRef allocator) 66 - { 67 - const char* value = sysattr(name); 68 - if (!value) 69 - return nullptr; 70 - 71 - char* end; 72 - long lvalue = strtol(value, &end, 16); 73 - 74 - if (end == value) 75 - return nullptr; 76 - 77 - return CFNumberCreate(allocator, kCFNumberLongType, &lvalue); 78 - } 79 - 80 - CFTypeRef io_device::retrieve(const property_mapping* mapping, CFAllocatorRef allocator) 81 - { 82 - if (mapping->evaluator) 83 - return mapping->evaluator(this, allocator); 84 - else 85 - { 86 - const char* value = nullptr; 87 - if (mapping->linuxProperty) 88 - value = property(mapping->linuxProperty); 89 - else if (mapping->linuxSysAttr) 90 - value = sysattr(mapping->linuxSysAttr); 91 - if (!value) 92 - return nullptr; 93 - 94 - if (mapping->dataType == property_mapping::String) 95 - return strToCF(value, allocator); 96 - else 97 - { 98 - int base = (mapping->dataType == property_mapping::Number10) ? 10 : 16; 99 - char* end; 100 - long lvalue = strtol(value, &end, base); 101 - 102 - if (end == value) 103 - return nullptr; 104 - 105 - return CFNumberCreate(allocator, kCFNumberLongType, &lvalue); 106 - } 107 - } 108 - } 109 - 110 - void io_device::retrieveAll(CFMutableDictionaryRef dict, const property_mapping* mapping, size_t count, CFAllocatorRef allocator) 111 - { 112 - for (size_t i = 0; i < count; i++) 113 - { 114 - CFTypeRef val = retrieve(mapping + i, allocator); 115 - CFDictionarySetValue(dict, mapping[i].appleName, val); 116 - } 117 - } 118 - 119 - CFTypeRef io_device::retrieve(const property_mapping* mapping, size_t count, CFStringRef name, CFAllocatorRef allocator) 120 - { 121 - for (size_t i = 0; i < count; i++) 122 - { 123 - if (CFStringCompare(name, mapping[i].appleName, CFStringCompareFlags(0)) == 0) 124 - return retrieve(mapping + i, allocator); 125 - } 126 - return nullptr; 127 - } 128 - 129 - io_device* io_device::parent() 130 - { 131 - return nullptr; // not implemented yet 132 - } 133 - 134 - const char* io_device::sysname() 135 - { 136 - return udev_device_get_sysname(m_device); 137 - } 138 - 139 - void io_device::properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) 140 - { 141 - retrieveAll(dict, generic_properties, sizeof(generic_properties) / sizeof(generic_properties[0]), allocator); 142 - } 143 - 144 - CFTypeRef io_device::property(CFStringRef name, CFAllocatorRef allocator) 145 - { 146 - return retrieve(generic_properties, sizeof(generic_properties) / sizeof(generic_properties[0]), name, allocator); 147 - } 148 - 149 - CFTypeRef ListDevSymlinks(io_device* d, CFAllocatorRef a) 150 - { 151 - CFMutableDictionaryRef dict = CFDictionaryCreateMutable(a, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 152 - struct udev_list_entry* e = udev_device_get_devlinks_list_entry(d->device()); 153 - 154 - while (e != nullptr) 155 - { 156 - CFDictionarySetValue(dict, strToCF(udev_list_entry_get_name(e)), strToCF(udev_list_entry_get_value(e))); 157 - e = udev_list_entry_get_next(e); 158 - } 159 - 160 - return dict; 161 - }
-62
src/IOKit/io_device.h
··· 1 - #ifndef IOKIT_IODEVICE_H 2 - #define IOKIT_IODEVICE_H 3 - extern "C" { 4 - #include <CoreFoundation/CFString.h> 5 - #include <CoreFoundation/CFNumber.h> 6 - } 7 - #include <libudev.h> 8 - #include "io_object.h" 9 - 10 - struct property_mapping; 11 - 12 - class io_device : public io_object 13 - { 14 - public: 15 - io_device(struct udev_device* device); 16 - virtual ~io_device(); 17 - 18 - static io_device* create(udev_device* dev); 19 - 20 - virtual void properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator); 21 - virtual CFTypeRef property(CFStringRef name, CFAllocatorRef allocator); 22 - virtual io_device* parent(); 23 - virtual bool operator==(const io_object& that) override; 24 - 25 - const char* sysname(); 26 - const char* property(const char* name); 27 - const char* sysattr(const char* name); 28 - CFStringRef sysattrStr(const char* name, CFAllocatorRef allocator); 29 - CFNumberRef sysattrNum(const char* name, CFAllocatorRef allocator); 30 - inline struct udev_device* device() { return m_device; } 31 - protected: 32 - CFTypeRef retrieve(const property_mapping* mapping, CFAllocatorRef allocator); 33 - CFTypeRef retrieve(const property_mapping* mapping, size_t count, CFStringRef name, CFAllocatorRef allocator); 34 - void retrieveAll(CFMutableDictionaryRef dict, const property_mapping* mapping, size_t count, CFAllocatorRef allocator); 35 - protected: 36 - struct udev_device* m_device; 37 - }; 38 - 39 - struct property_mapping 40 - { 41 - enum DataType { String, Number10, Number16 }; 42 - typedef CFTypeRef (*EvaluatorType)(io_device*,CFAllocatorRef); 43 - 44 - property_mapping(CFStringRef appleName, const char* linuxProperty, const char* linuxSysAttr, DataType dataType) 45 - : appleName(appleName), linuxProperty(linuxProperty), linuxSysAttr(linuxSysAttr), dataType(dataType), evaluator(0) 46 - { 47 - } 48 - 49 - property_mapping(CFStringRef appleName, EvaluatorType ev) 50 - : appleName(appleName), evaluator(ev) 51 - { 52 - } 53 - 54 - CFStringRef appleName; 55 - const char* linuxProperty; 56 - const char* linuxSysAttr; 57 - 58 - DataType dataType; 59 - EvaluatorType evaluator; 60 - }; 61 - 62 - #endif
-41
src/IOKit/io_device_iterator.cpp
··· 1 - #include "io_device_iterator.h" 2 - #include "io_device.h" 3 - #include <libudev.h> 4 - #include <typeinfo> 5 - 6 - io_device_iterator::io_device_iterator(udev_enumerate* uenum) 7 - : m_uenum(uenum) 8 - { 9 - m_udev = udev_enumerate_get_udev(m_uenum); 10 - reset(); 11 - } 12 - 13 - void io_device_iterator::reset() 14 - { 15 - m_next = udev_enumerate_get_list_entry(m_uenum); 16 - } 17 - 18 - io_device_iterator::~io_device_iterator() 19 - { 20 - udev_enumerate_unref(m_uenum); 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; 29 - } 30 - 31 - io_object_t io_device_iterator::next() 32 - { 33 - if (!m_next) 34 - return nullptr; 35 - else 36 - { 37 - udev_device* dev = udev_device_new_from_syspath(m_udev, udev_list_entry_get_name(m_next)); 38 - m_next = udev_list_entry_get_next(m_next); 39 - return io_device::create(dev); 40 - } 41 - }
-21
src/IOKit/io_device_iterator.h
··· 1 - #ifndef IOKIT_IODEVICEITERATOR_H 2 - #define IOKIT_IODEVICEITERATOR_H 3 - #include "io_iterator.h" 4 - 5 - class io_device_iterator : public io_iterator 6 - { 7 - public: 8 - io_device_iterator(struct udev_enumerate* uenum); 9 - virtual ~io_device_iterator(); 10 - virtual io_object_t next() override; 11 - virtual void reset() override; 12 - virtual bool operator==(const io_object& that) override; 13 - private: 14 - struct udev* m_udev; 15 - struct udev_enumerate* m_uenum; 16 - struct udev_list_entry* m_next; 17 - }; 18 - 19 - typedef io_device_iterator* io_device_iterator_t; 20 - 21 - #endif
-129
src/IOKit/io_device_net.cpp
··· 1 - #include "io_device_net.h" 2 - #include "cfutil.h" 3 - #include <cstring> 4 - #include <cstdlib> 5 - #include <sys/types.h> 6 - #include <sys/socket.h> 7 - #include <linux/if_arp.h> 8 - #include <util/debug.h> 9 - 10 - /* 11 - #define kIOInterfaceUnit "IOInterfaceUnit" 12 - #define kIOInterfaceType "IOInterfaceType" 13 - #define kIOMACAddress "IOMACAddress" 14 - #define kIOPrimaryInterface "IOPrimaryInterface" 15 - */ 16 - 17 - #define kIOEthernetAddressSize 6 18 - 19 - static CFTypeRef ConvertInterfaceType(io_device* d, CFAllocatorRef allocator); 20 - static CFTypeRef ConvertMACAddress(io_device* d, CFAllocatorRef allocator); 21 - 22 - static const property_mapping iface_properties[] = { 23 - property_mapping{ CFSTR("IOMediaAddressLength"), nullptr, "addr_len", property_mapping::Number10 }, 24 - property_mapping{ CFSTR("IOInterfaceType"), ConvertInterfaceType }, 25 - property_mapping{ CFSTR("IOMaxTransferUnit"), nullptr, "mtu", property_mapping::Number10 }, 26 - property_mapping{ CFSTR("IOBuiltin"), [](io_device* d, CFAllocatorRef) -> CFTypeRef { return kCFBooleanFalse; } }, 27 - property_mapping{ CFSTR("IOPrimaryInterface"), [](io_device* d, CFAllocatorRef) -> CFTypeRef { return (strcmp(d->property("INTERFACE"), "eth0") == 0) ? kCFBooleanTrue : kCFBooleanFalse; } }, 28 - }; 29 - 30 - CFTypeRef io_device_net::property(CFStringRef name, CFAllocatorRef allocator) 31 - { 32 - LOG << "io_device_net::property(): " << CFStringGetCStringPtr(name, kCFStringEncodingASCII) << std::endl; 33 - CFTypeRef v = retrieve(iface_properties, sizeof(iface_properties) / sizeof(iface_properties[0]), name, allocator); 34 - if (v) 35 - return v; 36 - else 37 - return io_device::property(name, allocator); 38 - } 39 - 40 - void io_device_net::properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) 41 - { 42 - io_device::properties(dict, allocator); 43 - retrieveAll(dict, iface_properties, sizeof(iface_properties) / sizeof(iface_properties[0]), allocator); 44 - } 45 - 46 - static CFTypeRef ConvertInterfaceType(io_device* d, CFAllocatorRef allocator) 47 - { 48 - int type = atoi(d->sysattr("type")); 49 - int mtype = 0; 50 - 51 - // This is not complete, but could suffice 52 - switch (type) 53 - { 54 - case ARPHRD_ETHER: 55 - case ARPHRD_IEEE80211: // linux/include/linux/if_arp.h 56 - mtype = 6; // xnu-792/bsd/net/if_types.h 57 - break; 58 - case ARPHRD_LOOPBACK: 59 - mtype = 0x18; 60 - break; 61 - case ARPHRD_PPP: 62 - mtype = 0x17; 63 - break; 64 - case ARPHRD_ATM: 65 - mtype = 0x25; 66 - break; 67 - case ARPHRD_IEEE1394: 68 - mtype = 0x90; 69 - break; 70 - case ARPHRD_SLIP: 71 - mtype = 0x1c; 72 - break; 73 - } 74 - 75 - return intToCF(mtype, allocator); 76 - } 77 - 78 - io_device* io_device_net::parent() 79 - { 80 - return new io_device_net_ctrl(udev_device_ref(m_device)); 81 - } 82 - 83 - static const property_mapping ctrl_properties[] = { 84 - property_mapping{ CFSTR("IOLinkSpeed"), nullptr, "speed", property_mapping::Number10 }, 85 - property_mapping{ CFSTR("IOLinkStatus"), [](io_device* d, CFAllocatorRef a) -> CFTypeRef { int act = atoi(d->sysattr("carrier")); return intToCF(act ? 3 : 1, a); } }, // if_media.h 86 - property_mapping{ CFSTR("IOMACAddress"), ConvertMACAddress }, 87 - }; 88 - 89 - CFTypeRef io_device_net_ctrl::property(CFStringRef name, CFAllocatorRef allocator) 90 - { 91 - LOG << "io_device_net_ctrl::property(): " << CFStringGetCStringPtr(name, kCFStringEncodingASCII) << std::endl; 92 - 93 - CFTypeRef v = retrieve(ctrl_properties, sizeof(ctrl_properties) / sizeof(ctrl_properties[0]), name, allocator); 94 - if (v) 95 - return v; 96 - else 97 - return io_device::property(name, allocator); 98 - } 99 - 100 - void io_device_net_ctrl::properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) 101 - { 102 - io_device::properties(dict, allocator); 103 - } 104 - 105 - CFTypeRef ConvertMACAddress(io_device* d, CFAllocatorRef allocator) 106 - { 107 - int len = atoi(d->sysattr("addr_len")); 108 - const char* addr = d->sysattr("address"); 109 - 110 - if (!addr) 111 - return nullptr; 112 - 113 - UInt8* bytes = new UInt8[kIOEthernetAddressSize]; 114 - CFTypeRef rv; 115 - 116 - memset(bytes, 0, kIOEthernetAddressSize); 117 - 118 - for (int i = 0; i < std::min(len, kIOEthernetAddressSize); i++) 119 - { 120 - long byte = strtol(addr + i*3, nullptr, 16); 121 - bytes[i] = UInt8(byte); 122 - } 123 - 124 - rv = CFDataCreate(allocator, bytes, kIOEthernetAddressSize); 125 - 126 - delete [] bytes; 127 - return rv; 128 - } 129 -
-27
src/IOKit/io_device_net.h
··· 1 - #ifndef IOKIT_IODEVICENET_H 2 - #define IOKIT_IODEVICENET_H 3 - #include "io_device.h" 4 - 5 - // IONetworkInterface 6 - class io_device_net : public io_device 7 - { 8 - public: 9 - // error: inheriting constructors are not supported 10 - // using io_device::io_device; 11 - 12 - io_device_net(struct udev_device* device) : io_device(device) {} 13 - virtual CFTypeRef property(CFStringRef name, CFAllocatorRef allocator) override; 14 - virtual void properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) override; 15 - virtual io_device* parent() override; 16 - }; 17 - 18 - // IONetworkController 19 - class io_device_net_ctrl : public io_device 20 - { 21 - public: 22 - io_device_net_ctrl(struct udev_device* device) : io_device(device) {} 23 - virtual CFTypeRef property(CFStringRef name, CFAllocatorRef allocator) override; 24 - virtual void properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) override; 25 - }; 26 - 27 - #endif
-36
src/IOKit/io_device_usb.cpp
··· 1 - #include "io_device_usb.h" 2 - 3 - // https://developer.apple.com/library/mac/#documentation/IOKit/Reference/USBSpec_header_reference/Reference/reference.html 4 - static const property_mapping usb_properties[] = { 5 - property_mapping{ CFSTR("Serial Number"), nullptr, "serial", property_mapping::String }, 6 - property_mapping{ CFSTR("USB Product Name"), nullptr, "product", property_mapping::String }, 7 - property_mapping{ CFSTR("USB Vendor Name"), nullptr, "manufacturer", property_mapping::String }, 8 - property_mapping{ CFSTR("VendorID"), nullptr, "idVendor", property_mapping::Number16 }, 9 - property_mapping{ CFSTR("ProductID"), nullptr, "idProduct", property_mapping::Number16 }, 10 - property_mapping{ CFSTR("bInterfaceClass"), nullptr, "bInterfaceClass", property_mapping::Number16 }, 11 - property_mapping{ CFSTR("bInterfaceNumber"), nullptr, "bInterfaceNumber", property_mapping::Number16 }, 12 - property_mapping{ CFSTR("bDeviceClass"), nullptr, "bDeviceClass", property_mapping::Number16 }, 13 - property_mapping{ CFSTR("bDeviceSubClass"), nullptr, "bDeviceSubClass", property_mapping::Number16 }, 14 - property_mapping{ CFSTR("bDeviceProtocol"), nullptr, "bDeviceProtocol", property_mapping::Number16 }, 15 - property_mapping{ CFSTR("bMaxPacketSize0"), nullptr, "bMaxPacketSize0", property_mapping::Number10 }, 16 - property_mapping{ CFSTR("bNumConfigurations"), nullptr, "bNumConfigurations", property_mapping::Number10 }, 17 - property_mapping{ CFSTR("bNumEndpoints"), nullptr, "bNumEndpoints", property_mapping::Number10 }, 18 - property_mapping{ CFSTR("bConfigurationValue"), nullptr, "bConfigurationValue", property_mapping::Number10 }, 19 - property_mapping{ CFSTR("bcdDevice"), nullptr, "bcdDevice", property_mapping::Number16 }, 20 - }; 21 - 22 - 23 - CFTypeRef io_device_usb::property(CFStringRef name, CFAllocatorRef allocator) 24 - { 25 - CFTypeRef v = retrieve(usb_properties, sizeof(usb_properties) / sizeof(usb_properties[0]), name, allocator); 26 - if (v) 27 - return v; 28 - else 29 - return io_device::property(name, allocator); 30 - } 31 - 32 - void io_device_usb::properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) 33 - { 34 - io_device::properties(dict, allocator); 35 - retrieveAll(dict, usb_properties, sizeof(usb_properties) / sizeof(usb_properties[0]), allocator); 36 - }
-16
src/IOKit/io_device_usb.h
··· 1 - #ifndef IOKIT_IODEVICEUSB_H 2 - #define IOKIT_IODEVICEUSB_H 3 - #include "io_device.h" 4 - 5 - class io_device_usb : public io_device 6 - { 7 - public: 8 - // error: inheriting constructors are not supported 9 - // using io_device::io_device; 10 - 11 - io_device_usb(struct udev_device* device) : io_device(device) {} 12 - virtual CFTypeRef property(CFStringRef name, CFAllocatorRef allocator) override; 13 - virtual void properties(CFMutableDictionaryRef dict, CFAllocatorRef allocator) override; 14 - }; 15 - 16 - #endif
-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 - }
-18
src/IOKit/io_iterator.h
··· 1 - #ifndef IOKIT_IOITERATOR_H 2 - #define IOKIT_IOITERATOR_H 3 - #include "io_object.h" 4 - 5 - class io_iterator : public io_object 6 - { 7 - public: 8 - virtual io_object_t next() = 0; 9 - virtual void reset() = 0; 10 - }; 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); 17 - 18 - #endif
-58
src/IOKit/io_object.cpp
··· 1 - #include "io_object.h" 2 - 3 - io_object::io_object() 4 - : m_refs(1) 5 - { 6 - } 7 - 8 - io_object::~io_object() 9 - { 10 - } 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 - if (obj) 32 - obj->release(); 33 - return 0; 34 - } 35 - 36 - uint32_t IOObjectGetRetainCount(io_object_t obj) 37 - { 38 - if (!obj) 39 - return 0; 40 - return obj->refs(); 41 - } 42 - 43 - uint32_t IOObjectGetUserRetainCount(io_object_t obj) 44 - { 45 - if (!obj) 46 - return 0; 47 - return obj->refs(); 48 - } 49 - 50 - bool IOObjectIsEqualTo(io_object_t o1, io_object_t o2) 51 - { 52 - if (o1 == o2) 53 - return true; 54 - if (!o1 || !o2) 55 - return false; 56 - else 57 - return *o1 == *o2; 58 - }
-28
src/IOKit/io_object.h
··· 1 - #ifndef IOKIT_IOOBJECT_H 2 - #define IOKIT_IOOBJECT_H 3 - #include <stdint.h> 4 - 5 - class io_object 6 - { 7 - public: 8 - io_object(); 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; 17 - }; 18 - 19 - typedef io_object* io_object_t; 20 - 21 - extern "C" int IOObjectRetain(io_object_t obj); 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); 26 - 27 - #endif 28 -
-1
src/IOKit/os
··· 1 - ../libc/os
src/IOKit/port.c

This is a binary file and will not be displayed.

src/IOKit/port.h

This is a binary file and will not be displayed.

-30
src/IOKit/service.h
··· 1 - #ifndef IOKIT_SERVICE_H 2 - #define IOKIT_SERVICE_H 3 - #ifndef __STDC_LIMIT_MACROS 4 - # define __STDC_LIMIT_MACROS 5 - #endif 6 - 7 - #include "io_object.h" 8 - #include "io_device_iterator.h" 9 - extern "C" { 10 - #include <CoreFoundation/CFDictionary.h> 11 - } 12 - 13 - extern "C" const void* kIOMasterPortDefault; 14 - 15 - // This seems to give all children (e.g. all USB devices) 16 - extern "C" CFMutableDictionaryRef IOServiceMatching(const char* service); 17 - // This seems to give the root device (e.g. the USB driver) 18 - extern "C" CFMutableDictionaryRef IOServiceNameMatching(const char* name); 19 - extern "C" CFMutableDictionaryRef IOBSDNameMatching(void* iokitPort, unsigned int options, const char* bsdName); 20 - 21 - extern "C" int IOServiceGetMatchingServices(void* port, CFDictionaryRef rules, io_device_iterator_t* iter); 22 - 23 - extern "C" int IORegistryEntryGetParentEntry(io_object_t obj, void* planeName /* TODO */, io_object_t* parent); 24 - extern "C" CFTypeRef IORegistryEntryCreateCFProperty(io_object_t obj, CFStringRef key, CFAllocatorRef allocator, int opts); 25 - extern "C" int IORegistryEntryCreateCFProperties(io_object_t obj, CFMutableDictionaryRef* props, CFAllocatorRef allocator, int opts); 26 - 27 - extern "C" int IOMasterPort(void* bootstrapPort, void** masterPort); 28 - 29 - #endif 30 -
-240
src/IOKit/service.mm
··· 1 - #include "service.h" 2 - #include "constants.h" 3 - #include "bsd.h" 4 - #include <Foundation/NSString.h> 5 - #include <CoreFoundation/CFString.h> 6 - #include <libudev.h> 7 - #include <stdlib.h> 8 - #include <list> 9 - #include <string> 10 - #include <fstream> 11 - #include <sys/types.h> 12 - #include <dirent.h> 13 - #include <cstdlib> 14 - #include "../util/stlutils.h" 15 - #include "../util/log.h" 16 - #include "io_device.h" 17 - #include "io_device_iterator.h" 18 - #include "cfutil.h" 19 - 20 - const void* kIOMasterPortDefault = 0; 21 - 22 - static void filterByBSDName(struct udev_enumerate* uenum, CFStringRef str); 23 - static void filterByClass(struct udev_enumerate* uenum, CFStringRef str); 24 - static void filterByDriver(struct udev_enumerate* uenum, CFStringRef str); 25 - static void filterByProperties(struct udev_enumerate* uenum, CFDictionaryRef dict); 26 - 27 - static CFMutableDictionaryRef createMatchingDictionary(CFStringRef key, CFStringRef value) 28 - { 29 - CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 30 - CFDictionarySetValue(dict, key, value); 31 - return dict; 32 - } 33 - 34 - int IOMasterPort(void* bootstrapPort, void** masterPort) 35 - { 36 - *masterPort = (void*) kIOMasterPortDefault; 37 - return 0; 38 - } 39 - 40 - CFMutableDictionaryRef IOServiceMatching(const char* service) 41 - { 42 - static CFStringRef str = CFSTR(kIOProviderClassKey); 43 - return createMatchingDictionary(str, strToCF(service)); 44 - } 45 - 46 - CFMutableDictionaryRef IOServiceNameMatching(const char* name) 47 - { 48 - static CFStringRef str = CFSTR(kIONameMatchKey); 49 - return createMatchingDictionary(str, strToCF(name)); 50 - } 51 - 52 - CFMutableDictionaryRef IOBSDNameMatching(void* iokitPort, unsigned int options, const char* bsdName) 53 - { 54 - static CFStringRef str = CFSTR(kIOBSDNameKey); 55 - return createMatchingDictionary(str, strToCF(bsdName)); 56 - } 57 - 58 - int IOServiceGetMatchingServices(void* port, CFDictionaryRef rules, io_device_iterator_t* iter) 59 - { 60 - //size_t size = CFDictionaryGetCount(rules); 61 - //std::unique_ptr<CFStringRef[]> keys (new CFStringRef[size]); 62 - //CFDictionaryGetKeysAndValues(rules, (const void **) keys, nullptr); 63 - struct udev* udev; 64 - struct udev_enumerate* uenum; 65 - struct udev_list_entry* list; 66 - const void* value; 67 - 68 - udev = udev_new(); 69 - uenum = udev_enumerate_new(udev); 70 - 71 - if ((value = CFDictionaryGetValue(rules, CFSTR(kIOProviderClassKey)))) 72 - filterByClass(uenum, (CFStringRef) value); 73 - 74 - if ((value = CFDictionaryGetValue(rules, CFSTR(kIOBSDNameKey)))) 75 - filterByBSDName(uenum, (CFStringRef) value); 76 - 77 - if ((value = CFDictionaryGetValue(rules, CFSTR(kIOPropertyMatchKey)))) 78 - filterByProperties(uenum, (CFDictionaryRef) value); 79 - 80 - udev_enumerate_scan_devices(uenum); 81 - *iter = new io_device_iterator(uenum); 82 - 83 - return 0; 84 - } 85 - 86 - int IORegistryEntryCreateCFProperties(io_object_t obj, CFMutableDictionaryRef* props, CFAllocatorRef allocator, int opts) 87 - { 88 - io_device* dev = dynamic_cast<io_device*>(obj); 89 - 90 - if (!dev) 91 - { 92 - *props = nullptr; 93 - return -4; 94 - } 95 - else 96 - { 97 - *props = CFDictionaryCreateMutable(allocator, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 98 - dev->properties(*props, allocator); 99 - return 0; 100 - } 101 - } 102 - 103 - CFTypeRef IORegistryEntryCreateCFProperty(io_object_t obj, CFStringRef key, CFAllocatorRef allocator, int opts) 104 - { 105 - io_device* dev = dynamic_cast<io_device*>(obj); 106 - 107 - if (!dev) 108 - return nullptr; 109 - else 110 - return dev->property(key, allocator); 111 - } 112 - 113 - int IORegistryEntryGetParentEntry(io_object_t obj, void* planeName /* TODO */, io_object_t* parent) 114 - { 115 - io_device* dev = dynamic_cast<io_device*>(obj); 116 - if (!dev) 117 - { 118 - *parent = nullptr; 119 - return -1; 120 - } 121 - else 122 - { 123 - *parent = dev->parent(); 124 - return 0; 125 - } 126 - } 127 - 128 - void filterByClass(struct udev_enumerate* uenum, CFStringRef str) 129 - { 130 - if (strCFEqual(str, kIOEthernetInterfaceClass)) 131 - udev_enumerate_add_match_subsystem(uenum, "net"); 132 - else if (strCFEqual(str, kIOSerialBSDServiceValue)) 133 - udev_enumerate_add_match_subsystem(uenum, "tty"); 134 - else if (strCFEqual(str, kIOUSBDeviceClassName)) 135 - udev_enumerate_add_match_property(uenum, "DEVTYPE", "usb_device"); 136 - else if (strCFEqual(str, kIOUSBInterfaceClassName)) 137 - udev_enumerate_add_match_property(uenum, "DEVTYPE", "usb_interface"); 138 - else if (strCFEqual(str, kIOHIDDeviceKey)) 139 - udev_enumerate_add_match_subsystem(uenum, "hidraw"); 140 - } 141 - 142 - void filterByBSDName(struct udev_enumerate* uenum, CFStringRef str) 143 - { 144 - std::string translated = DarlingTranslateBSDName([(NSString*) str UTF8String]); 145 - udev_enumerate_add_match_sysname(uenum, translated.c_str()); 146 - } 147 - 148 - void filterByDriver(struct udev_enumerate* uenum, CFStringRef str) 149 - { 150 - const char* driver = nullptr; 151 - 152 - // TODO: USB interface vs. device 153 - if (strCFEqual(str, "AppleUSBEHCI")) 154 - driver = "ehci_hcd"; 155 - else if (strCFEqual(str, "AppleUSBOHCI")) 156 - driver = "ohci_hcd"; 157 - else if (strCFEqual(str, "AppleUSBUHCI")) 158 - driver = "uhci_hcd"; 159 - else if (strCFEqual(str, "AppleUSBCDC")) 160 - driver = "cdc_acm"; 161 - else if (strCFEqual(str, "processor")) 162 - driver = "processor"; 163 - else 164 - driver = [(NSString*) str UTF8String]; 165 - 166 - udev_enumerate_add_match_property(uenum, "driver", driver); 167 - } 168 - 169 - static std::string detectPrimaryInterface() 170 - { 171 - std::ifstream routes; 172 - 173 - if (const char* iface = getenv("IOKIT_PRIMARY_IFACE")) 174 - return iface; 175 - 176 - routes.open("/proc/net/route"); 177 - 178 - if (routes.is_open()) 179 - { 180 - std::string ifaceName, destination; 181 - 182 - while (!routes.eof()) 183 - { 184 - routes >> ifaceName >> destination; 185 - 186 - if (destination == "00000000") 187 - { 188 - LOG << "Primary network interface detected to be " << ifaceName << std::endl; 189 - return ifaceName; 190 - } 191 - 192 - std::getline(routes, ifaceName); // drop the rest of the line 193 - } 194 - } 195 - 196 - return std::string(); 197 - } 198 - 199 - void filterByProperties(struct udev_enumerate* uenum, CFDictionaryRef dict) 200 - { 201 - size_t size = CFDictionaryGetCount(dict); 202 - CFStringRef* keys = new CFStringRef[size]; 203 - CFDictionaryGetKeysAndValues(dict, (const void **) keys, nullptr); 204 - 205 - for (size_t i = 0; i < size; i++) 206 - { 207 - const void* value = CFDictionaryGetValue(dict, keys[i]); 208 - const char* key = nullptr; 209 - CFStringRef str = keys[i]; 210 - std::string svalue; 211 - 212 - if (strCFEqual(str, "VendorID")) 213 - { 214 - key = "ID_VENDOR_ID"; 215 - svalue = [(NSString*)value UTF8String]; 216 - } 217 - else if (strCFEqual(str, "ProductID")) 218 - { 219 - key = "ID_MODEL_ID"; 220 - svalue = [(NSString*)value UTF8String]; 221 - } 222 - else if (strCFEqual(str, "IOPrimaryInterface")) 223 - { 224 - svalue = detectPrimaryInterface(); 225 - if (!svalue.empty()) 226 - key = "INTERFACE"; 227 - //svalue = "eth0"; 228 - } 229 - 230 - if (key != nullptr) 231 - udev_enumerate_add_match_property(uenum, key, svalue.c_str()); 232 - else 233 - LOG << "Ignoring property " << [(NSString*) str UTF8String] << " in IOKit filterByProperties\n"; 234 - } 235 - 236 - delete [] keys; 237 - } 238 - 239 - 240 -