Ejemplo n.º 1
0
void
createHIDDeviceInterface(io_object_t hidDevice, IOHIDDeviceInterface ***hdi)
{
    io_name_t             className;
    IOCFPlugInInterface **plugInInterface = NULL;
    HRESULT               plugInResult = S_OK;
    SInt32                score = 0;
    IOReturn              ioReturnValue = kIOReturnSuccess;

    ioReturnValue = IOObjectGetClass(hidDevice, className);

    print_errmsg_if_io_err(ioReturnValue, "Failed to get class name.");

    ioReturnValue = IOCreatePlugInInterfaceForService(
                        hidDevice,
                        kIOHIDDeviceUserClientTypeID,
                        kIOCFPlugInInterfaceID,
                        &plugInInterface,
                        &score);

    if (ioReturnValue != kIOReturnSuccess)
        return;

    plugInResult = (*plugInInterface)->QueryInterface(
                        plugInInterface,
                        CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
                        (LPVOID)hdi);
    print_errmsg_if_err(plugInResult != S_OK,
                        "Failed to create device interface.\n");

    (*plugInInterface)->Release(plugInInterface);
}
Ejemplo n.º 2
0
static int CreateHIDDeviceInterface(io_object_t hidDevice,
                                    IOHIDDeviceInterface ***hidDeviceInterface)
{
    io_name_t className;
    IOCFPlugInInterface **plugInInterface = NULL;
    SInt32 score = 0;

    if (IOObjectGetClass(hidDevice, className) != kIOReturnSuccess)
        return -1;

    if (IOCreatePlugInInterfaceForService(hidDevice,
                                          kIOHIDDeviceUserClientTypeID,
                                          kIOCFPlugInInterfaceID,
                                          &plugInInterface,
                                          &score) != kIOReturnSuccess)
        return -1;

    // Call a method of the intermediate plugin to create the device interface
    if ((*plugInInterface)->QueryInterface(plugInInterface,
                                   CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
                                   (LPVOID)hidDeviceInterface) != S_OK
            || *hidDeviceInterface == NULL || **hidDeviceInterface == NULL) {
        (*plugInInterface)->Release(plugInInterface);
        return -1;
    }

    (*plugInInterface)->Release(plugInInterface);

    return 0;
}
Ejemplo n.º 3
0
void IOKitEventPublisher::newEvent(const io_service_t& device,
                                   IOKitEventContext::Action action) {
  auto ec = createEventContext();
  ec->action = action;

  {
    // The IORegistry name is not needed.
    io_name_t class_name = {0};
    if (IOObjectGetClass(device, class_name) != kIOReturnSuccess) {
      return;
    }
    ec->type = std::string(class_name);
  }

  // Get the device details
  CFMutableDictionaryRef details;
  IORegistryEntryCreateCFProperties(
      device, &details, kCFAllocatorDefault, kNilOptions);
  if (ec->type == kIOUSBDeviceClassName_) {
    ec->path = getIOKitProperty(details, "USB Address") + ":";
    ec->path += getIOKitProperty(details, "PortNum");
    ec->model = getIOKitProperty(details, "USB Product Name");
    ec->model_id = getIOKitProperty(details, "idProduct");
    ec->vendor = getIOKitProperty(details, "USB Vendor Name");
    ec->vendor_id = getIOKitProperty(details, "idVendor");
    idToHex(ec->vendor_id);
    idToHex(ec->model_id);
    ec->serial = getIOKitProperty(details, "USB Serial Number");
    if (ec->serial.size() == 0) {
      ec->serial = getIOKitProperty(details, "iSerialNumber");
    }
    ec->version = "";
    ec->driver = getIOKitProperty(details, "IOUserClientClass");
  } else if (ec->type == kIOPCIDeviceClassName_) {
    auto compatible = getIOKitProperty(details, "compatible");
    auto properties = IOKitPCIProperties(compatible);
    ec->model_id = properties.model_id;
    ec->vendor_id = properties.vendor_id;
    ec->driver = properties.driver;
    if (ec->driver.empty()) {
      ec->driver = getIOKitProperty(details, "IOName");
    }

    ec->path = getIOKitProperty(details, "pcidebug");
    ec->version = getIOKitProperty(details, "revision-id");
    ec->model = getIOKitProperty(details, "model");
  } else {
    // Get the name as the model.
    io_name_t name = {0};
    IORegistryEntryGetName(device, name);
    if (name[0] != 0) {
      ec->model = std::string(name);
    }
  }

  CFRelease(details);
  fire(ec);
}
 bool isNotPointingDevice(IOHIDDeviceRef devRef)
 {
   // List of the URI substrings for which the corresponding devices will be ignored
   io_name_t ignored[] = { "Keyboard", "AppleUSBTCButtons", "BNBTrackpadDevice", "AppleMikeyHIDDriver", "AppleUSBMultitouchDriver" };
   io_name_t className;
   IOObjectGetClass(IOHIDDeviceGetService(devRef), className);
   const int n = sizeof(ignored) / sizeof(ignored[0]);
   for (int i = 0; i < n; i++)
     if (strstr(className, ignored[i]) != NULL)
       return true;
   return false;
 }
Ejemplo n.º 5
0
int drive_open(int device){
  CFMutableDictionaryRef main_dict = NULL;
  CFMutableDictionaryRef sec_dict  = NULL;
  io_name_t   cls_name;
  io_service_t  sd = IO_OBJECT_NULL;
  SInt32        score = 0;
  drive_data_s* dd = 0;
  int count;
  int ret = 1;

  dd = (drive_data_s*)calloc(1, sizeof(drive_data_s));
  if(!dd) return 0;
  dd->itt = IO_OBJECT_NULL;

  if((main_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks)) != NULL){
    if((sec_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)) != NULL){
      CFDictionarySetValue(sec_dict,CFSTR(kIOPropertySCSITaskDeviceCategory),CFSTR(kIOPropertySCSITaskAuthoringDevice));
      CFDictionarySetValue(main_dict,CFSTR(kIOPropertyMatchKey),sec_dict);
      CFRelease(sec_dict);
    }
  }

  if(IOServiceGetMatchingServices(kIOMasterPortDefault,main_dict,&dd->itt)){
    printf("no matching services\n");
    return 0;
  }

  for(count = 0;count < device;++count){
    sd = IOIteratorNext(dd->itt);
  }

  if(!sd){
    printf("could not find drive based off id\n");
    return 0;
  }

  if(!IOObjectGetClass(sd,cls_name) &&
      !IOCreatePlugInInterfaceForService(sd,kIOMMCDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&dd->plg_in_intf,&score) &&
      !(*dd->plg_in_intf)->QueryInterface(dd->plg_in_intf,CFUUIDGetUUIDBytes(kIOMMCDeviceInterfaceID),(LPVOID*)&dd->mmc_intf)){

    dd->dev_intf = (*dd->mmc_intf)->GetSCSITaskDeviceInterface(dd->mmc_intf);
    if(dd->dev_intf == NULL){
      ret = 0;
    }
      }
      if(IOObjectRelease(sd)){
        printf("could not release sd");
        return 0;
      }

      if(ret) return(int)dd;
      else return 0;
}
Ejemplo n.º 6
0
void IOKitDevicePrivate::init(const QString &udiString, const io_registry_entry_t &entry)
{
    Q_ASSERT(entry != MACH_PORT_NULL);

    udi = udiString;

    properties = getProperties(entry);

    io_name_t className;
    IOObjectGetClass(entry, className);
    properties["className"] = QString::fromUtf8(className);

    parentUdi = getParentDeviceUdi(entry);
    type = typeFromEntry(entry, properties);

    IOObjectRelease(entry);
}
Ejemplo n.º 7
0
unsigned int MT_HIDGamePad::FindGamePad()
{
    IOReturn ioReturnValue = kIOReturnSuccess;
    io_name_t className;

    while( (hidDevice = IOIteratorNext(hidObjectIterator)) )
    {
        ioReturnValue = IOObjectGetClass(hidDevice,className);
        if(ioReturnValue != kIOReturnSuccess) {
            fprintf(stderr,"Warning:  Could not get HID class name.\n");
            fflush(stderr);
        }
        if(strcmp(className,"IOUSBHIDDriver") == 0)
            return 0;
    }
    return 0;
}
kern_return_t
fake_IOServiceOpen(
  io_service_t service,
  task_port_t owningTask,
  uint32_t  type,
  io_connect_t  * connect )
{
  kern_return_t ret = IOServiceOpen(service, owningTask, type, connect);
  io_name_t className;
  IOObjectGetClass(service, className);
  printf("IOServiceOpen(service=%x, owningTask=%x, type=%x, connect=%p) (*connect after call = %x\n", service, owningTask, type, connect, *connect);
  printf("  (class: %s)\n", className);
  if (type == 0x100){
    //IGAccelVideoContextMain
    main_port = *connect;
  }
  return ret;
}
Ejemplo n.º 9
0
Boolean IsWholeMedia(io_service_t service)
{
  //
  // Determine if the object passed in represents an IOMedia (or subclass) object.
  // If it does, retrieve the "Whole" property.
  // If this is the whole media object, find out if it is a CD, DVD, or something else.
  // If it isn't the whole media object, iterate across its parents in the IORegistry
  // until the whole media object is found.
  //
  // Note that media types other than CD and DVD are not distinguished by class name
  // but are generic IOMedia objects.
  //

  Boolean isWholeMedia = false;
  io_name_t className;
  kern_return_t kernResult;

  if (IOObjectConformsTo(service, kIOMediaClass)) {

    CFTypeRef wholeMedia;

    wholeMedia = IORegistryEntryCreateCFProperty(service, CFSTR(kIOMediaWholeKey), kCFAllocatorDefault, 0);

    if (NULL == wholeMedia) {
      printf("Could not retrieve Whole property\n");
    } else {
      isWholeMedia = CFBooleanGetValue(wholeMedia);
      CFRelease(wholeMedia);
    }
  }

  if (isWholeMedia) {
    if (IOObjectConformsTo(service, kIOCDMediaClass)) {
      printf("is a CD\n");
    } else if (IOObjectConformsTo(service, kIODVDMediaClass)) {
      printf("is a DVD\n");
    } else {
      kernResult = IOObjectGetClass(service, className);
      printf("is of class %s\n", className);
    }
  }

  return isWholeMedia;
}
Ejemplo n.º 10
0
Archivo: rltkRegs.c Proyecto: OTiZ/osx
io_object_t getInterfaceWithName( mach_port_t masterPort, char *className )
{
    io_iterator_t	ite;
    io_object_t		obj = 0;
    io_name_t		name;
    kern_return_t	rc;
    kern_return_t	kr;


    kr = IORegistryCreateIterator(	masterPort,
                                    kIOServicePlane,
                                    true,					/* recursive */
                                    &ite );
    if ( kr != kIOReturnSuccess )
    {
        printf( "IORegistryCreateIterator() error %08lx\n", (unsigned long)kr );
        return 0;
    }

    while ( (obj = IOIteratorNext( ite )) )
    {
        if ( IOObjectConformsTo( obj, (char*)className ) )
        {
            //	printf( "Found Realtek UserClient !!\n" );
            break;
        }
        else
        {
            rc = IOObjectGetClass( obj, name );
            if ( rc == kIOReturnSuccess )
            {
                //	printf( "Skipping class %s\n", name );
            }
        }
        IOObjectRelease( obj );
        obj = 0;
    }

    IORegistryDisposeEnumerator( ite );

    return obj;
}/* end getInterfaceWithName */
Ejemplo n.º 11
0
void CreateDeviceInterfaceUsingOldMethod(io_object_t scsiDevice, IOSCSIDeviceInterface ***interface)
{
    io_name_t			className;
    IOCFPlugInInterface	**plugInInterface = NULL;
    HRESULT				plugInResult = S_OK;
    kern_return_t		kr = kIOReturnSuccess;
    SInt32				score = 0;

    // Get the object's class name just to display it
    kr = IOObjectGetClass(scsiDevice, className);

    if (kr != kIOReturnSuccess) {
        fprintf(stderr, "Failed to get class name. (0x%08x)\n", kr);
    }
    else {
        fprintf(stderr, "Found device class \"%s\" using old method.\n", className);

        // Create the base interface of type IOCFPlugInInterface.
        // This object will be used to create the SCSI device interface object.
        kr = IOCreatePlugInInterfaceForService( scsiDevice,
                          kIOSCSIUserClientTypeID, kIOCFPlugInInterfaceID,
                          &plugInInterface, &score);

        if (kr != kIOReturnSuccess) {
            fprintf(stderr, "Couldn't create a plugin interface for the io_service_t. (0x%08x)\n", kr);
        }
        else {
            // Query the base plugin interface for an instance of the specific SCSI device interface
            // object.
            plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, 
                                                CFUUIDGetUUIDBytes(kIOSCSIDeviceInterfaceID),
                          			(LPVOID *) interface);
            
            if (plugInResult != S_OK) {
                fprintf(stderr, "Couldn't create SCSI device interface. (%ld)\n", plugInResult);
            }
                    
            // We're now finished with the instance of IOCFPlugInInterface.
            IODestroyPlugInInterface(plugInInterface);
        }
    }
}
Ejemplo n.º 12
0
kern_return_t
fake_IOServiceOpen(
  io_service_t service,
  task_port_t owningTask,
  uint32_t  type,
  io_connect_t  * connect )
{
  kern_return_t ret = IOServiceOpen(service, owningTask, type, connect);
  io_name_t className;
  IOObjectGetClass(service, className);
  printf("IOServiceOpen(service=%x, owningTask=%x, type=%x, connect=%p) (*connect after call = %x\n", service, owningTask, type, connect, *connect);
  printf("  (class: %s)\n", className);
  if (type == 0x101){
    //IGAccelVideoContextMedia
    if (main_port != 0) {
      printf("$$$$$$$$$ got another service port/?\n");
    }
    main_port = *connect;
    printf("**************** found correct userclient **************\n");
  }
  return ret;
}
static IOReturn
PrintSMARTDataForBSDNode ( const char * bsdNode )
{


    IOReturn error   = kIOReturnError;
    io_object_t object  = MACH_PORT_NULL;
    io_object_t parent  = MACH_PORT_NULL;
    bool found   = false;
    char *                  bsdName = NULL;
    char deviceName[MAXPATHLEN];

    sprintf ( deviceName, "%s", bsdNode );

    if ( !strncmp ( deviceName, "/dev/r", 6 ) )
    {

        // Strip off the /dev/r from /dev/rdiskX
        bsdName = &deviceName[6];

    }

    else if ( !strncmp ( deviceName, "/dev/", 5 ) )
    {

        // Strip off the /dev/r from /dev/rdiskX
        bsdName = &deviceName[5];

    }

    else
    {

        bsdName = deviceName;

    }

    require_action ( ( strncmp ( bsdName, "disk", 4 ) == 0 ), ErrorExit, PrintUsage ( ) );

    object = IOServiceGetMatchingService (  kIOMasterPortDefault,
        IOBSDNameMatching ( kIOMasterPortDefault, 0, bsdName ) );

    require ( ( object != MACH_PORT_NULL ), ErrorExit );

    parent = object;
    while ( IOObjectConformsTo ( object, kIOATABlockStorageDeviceClass ) == false )
    {

                #if DEBUG

        io_name_t className;

        error = IOObjectGetClass ( object, className );
        printf ( "Object class = %s\n", ( char * ) className );

                #endif

        error = IORegistryEntryGetParentEntry ( object, kIOServicePlane, &parent );
        require ( ( error == kIOReturnSuccess ), ReleaseObject );
        require ( ( parent != MACH_PORT_NULL ), ReleaseObject );

        IOObjectRelease ( object );
        object = parent;

    }

    if ( IOObjectConformsTo ( object, kIOATABlockStorageDeviceClass ) )
    {

        PrintSMARTDataForDevice ( object );
        found = true;

    }


ReleaseObject:


    require ( ( object != MACH_PORT_NULL ), ErrorExit );
    IOObjectRelease ( object );
    object = MACH_PORT_NULL;


ErrorExit:


    if ( found == false )
    {
        printf ( "No S.M.A.R.T. capable device at %s\n", bsdNode );
    }

    return error;

}
Ejemplo n.º 14
0
drives_s* drives_available(){
  CFMutableDictionaryRef  main_dict = NULL;
  CFMutableDictionaryRef  sec_dict  = NULL;
  io_iterator_t           itt = IO_OBJECT_NULL;
  io_name_t               cls_name;
  io_service_t            sd = IO_OBJECT_NULL;
  IOCFPlugInInterface     **plg_in_intf = NULL;
  SCSITaskDeviceInterface **dev_intf = NULL;
  MMCDeviceInterface      **mmc_intf = NULL;
  SInt32                  score = 0;
  int count;
  int ret = 1;
  drive_s* d = 0;
  drives_s* dd = 0;

  if((main_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks)) != NULL){
    if((sec_dict = CFDictionaryCreateMutable(kCFAllocatorDefault,0,&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)) != NULL){
      CFDictionarySetValue(sec_dict,CFSTR(kIOPropertySCSITaskDeviceCategory),CFSTR(kIOPropertySCSITaskAuthoringDevice));
      CFDictionarySetValue(main_dict,CFSTR(kIOPropertyMatchKey),sec_dict);
      CFRelease(sec_dict);
    }
  }

  if(IOServiceGetMatchingServices(kIOMasterPortDefault,main_dict,&itt)){
    printf("no matching services\n");
    return 0;
  }

  count = 0;
  while((sd = IOIteratorNext(itt))) {
    if(!IOObjectGetClass(sd,cls_name)){
      if(!IOCreatePlugInInterfaceForService(sd,kIOMMCDeviceUserClientTypeID,kIOCFPlugInInterfaceID,&plg_in_intf,&score) &&
          !(*plg_in_intf)->QueryInterface(plg_in_intf,CFUUIDGetUUIDBytes(kIOMMCDeviceInterfaceID),(LPVOID*)&mmc_intf))
      {
        dev_intf = (*mmc_intf)->GetSCSITaskDeviceInterface(mmc_intf);
        if(dev_intf){
          drive_data_s dd;
          dd.mmc_intf = mmc_intf;
          dd.plg_in_intf = plg_in_intf;
          dd.itt = itt;
          dd.dev_intf = dev_intf;
          if(drive_type((int)&dd) == T_CDROM){
            inquiry_s* inq;
            count++;
            d = (drive_s*)realloc(d,count*sizeof(drive_s));
            inq = drive_inquiry((int)&dd);
            memcpy(&d[count-1].name,inq->p_id,sizeof(inq->p_id));
            d[count-1].id = count;
            free(inq);
          }
        }
      }
      if(IOObjectRelease(sd)) ret = 0;
    }
    if(mmc_intf != NULL)(*mmc_intf)->Release(mmc_intf);
    if(plg_in_intf != NULL)IODestroyPlugInInterface(plg_in_intf);
  }
  IOObjectRelease(itt);

  dd = (drives_s*)malloc(sizeof(drives_s));
  if(dd){
    dd->drives = d;
    dd->number = count;
  }else{
    free(d);
    return 0;
  }
  if(ret)
    return dd;
  else return 0;
}
Ejemplo n.º 15
0
void genIOKitDevice(const io_service_t& device,
                    const io_service_t& parent,
                    const io_name_t plane,
                    int depth,
                    QueryData& results) {
  Row r;
  io_name_t name, device_class;
  auto kr = IORegistryEntryGetName(device, name);
  if (kr == KERN_SUCCESS) {
    r["name"] = std::string(name);
  }

  // Get the device class.
  kr = IOObjectGetClass(device, device_class);
  if (kr == KERN_SUCCESS) {
    r["class"] = std::string(device_class);
  }

  // The entry into the registry is the ID, and is used for children as parent.
  uint64_t device_id, parent_id;
  kr = IORegistryEntryGetRegistryEntryID(device, &device_id);
  if (kr == KERN_SUCCESS) {
    r["id"] = BIGINT(device_id);
  } else {
    r["id"] = "-1";
  }

  kr = IORegistryEntryGetRegistryEntryID(parent, &parent_id);
  if (kr == KERN_SUCCESS) {
    r["parent"] = BIGINT(parent_id);
  } else {
    r["parent"] = "-1";
  }

  r["depth"] = INTEGER(depth);

  if (IORegistryEntryInPlane(device, kIODeviceTreePlane)) {
    io_string_t device_path;
    kr = IORegistryEntryGetPath(device, kIODeviceTreePlane, device_path);
    if (kr == KERN_SUCCESS) {
      // Remove the "IODeviceTree:" from the device tree path.
      r["device_path"] = std::string(device_path).substr(13);
    }
  }

  // Fill in service bits and busy/latency time.
  if (IOObjectConformsTo(device, "IOService")) {
    r["service"] = "1";
  } else {
    r["service"] = "0";
  }

  uint32_t busy_state;
  kr = IOServiceGetBusyState(device, &busy_state);
  if (kr == KERN_SUCCESS) {
    r["busy_state"] = INTEGER(busy_state);
  } else {
    r["busy_state"] = "0";
  }

  auto retain_count = IOObjectGetKernelRetainCount(device);
  r["retain_count"] = INTEGER(retain_count);

  results.push_back(r);
}
void traverse(unsigned int options,
	      io_name_t plane, io_iterator_t services,
	      io_registry_entry_t serviceUpNext,
	      int depth, UInt64 stackOfBits)
{
    io_registry_entry_t service;                                ///ok
    Boolean		doProps;

    // We loop for every service in the list of services provided.

    while ( (service = serviceUpNext) )
    {
        io_iterator_t		children;
        Boolean			hasChildren;
        io_name_t    		name;
        kern_return_t		status;
	io_registry_entry_t	child;
	int			busy;

        // Obtain the next service entry, if any.

        serviceUpNext = IOIteratorNext(services);

        // Obtain the current service entry's children, if any.

        status = IORegistryEntryGetChildIterator(service,
                                                 plane,
                                                 &children);
        assert(status == KERN_SUCCESS);

        child = IOIteratorNext(children); ///ok
        hasChildren = child ? true : false;

        // Save has-more-siblings state into stackOfBits for this depth.

        if (serviceUpNext)
            stackOfBits |=  (1 << depth);
        else
            stackOfBits &= ~(1 << depth);

        // Save has-children state into stackOfBits for this depth.

        if (hasChildren)
            stackOfBits |=  (2 << depth);
        else
            stackOfBits &= ~(2 << depth);

        indent(true, depth, stackOfBits);

        // Print out the name of the service.

        status = IORegistryEntryGetName(service, name);
        assert(status == KERN_SUCCESS);

        printf("%s", name);

	if (strcmp("Root", name))
            doProps = (options & kDoPropsOption) != 0;
	else
            doProps = (options & kDoRootOption) != 0;

        // Print out the class of the service.

        status = IOObjectGetClass(service, name);
        assert(status == KERN_SUCCESS);
        printf("  <class %s", name);

	status = IOServiceGetBusyState(service, &busy);
	if(status == KERN_SUCCESS)
            printf(", busy %d", busy);

        // Print out the retain count of the service.

        printf(", retain count %d>\n", IOObjectGetRetainCount(service));

        // Print out the properties of the service.

	if (doProps)
            properties(service, depth, stackOfBits);

        // Recurse down.

	traverse(options, plane, children, child, depth + 1, stackOfBits);

        // Release resources.

        IOObjectRelease(children); children = 0;
        IOObjectRelease(service);  service  = 0;
    }
}