示例#1
0
bool plDInputMgr::MsgReceive(plMessage* msg)
{
    plInputEventMsg* pMsg = plInputEventMsg::ConvertNoRef(msg);
    if (pMsg && pMsg->fEvent == plInputEventMsg::kConfigure)
    {
        ConfigureDevice();
    }
    return false;
}
HRESULT CLoopbackDevice::FinalConstruct() {
  // Perform tasks which may fail when the class CLoopbackDevice
  // is finally constructed. This involves creating the USB device 
  // object and initializing the device so that it is recognized
  // as a valid USB device by the controller
  HRESULT hr = S_OK;

  hr = CreateUSBDevice();
  IfFailHrGo(hr);

  hr = ConfigureDevice();
  IfFailHrGo(hr);

Exit:
    return hr;
}
示例#3
0
datatypes::ReturnType HaierCommonSDK::Update(const datatypes::RealDevice &device,
                                             const datatypes::AttributeValuePair &pair, void *extra) {

    if (pair.GetAttribute().GetAttributeName().compare(DEVICE_CONFIG) == 0) {
        std::vector<datatypes::ValueTypePair> vector = pair.GetValue().GetValues();
        char *ssid = (char *) vector[0].GetValue();
        char *password = (char *) vector[1].GetValue();
        char *deviceid = (char *) "";
        if (device.GetDeviceId() != "") {
            deviceid = (char *) device.GetDeviceId().c_str();
        }
        return ConfigureDevice(ssid, password, deviceid);
    }

    return ExecuteOperations(device.GetDeviceId().c_str(), pair);
}
示例#4
0
/*++
Routine Description:

This routine configures the USB device.
In this routines we get the device descriptor,
the configuration descriptor and select the
configuration.

Arguments:

Device - Handle to a framework device

Return Value:

NTSTATUS - NT status value.
--*/
NTSTATUS ReadAndSelectDescriptors(IN WDFDEVICE Device)
{
    NTSTATUS               status;
    PDEVICE_CONTEXT        pDeviceContext;

    PAGED_CODE();

    // initialize variables
    pDeviceContext = GetDeviceContext(Device);

    // Create a USB device handle so that we can communicate with the
    // underlying USB stack. The WDFUSBDEVICE handle is used to query,
    // configure, and manage all aspects of the USB device.
    // These aspects include device properties, bus properties,
    // and I/O creation and synchronization. We only create device the first
    // the PrepareHardware is called. If the device is restarted by pnp manager
    // for resource re-balance, we will use the same device handle but then select
    // the interfaces again because the USB stack could reconfigure the device on
    // restart.
    if (pDeviceContext->WdfUsbTargetDevice == NULL)
	{
        status = WdfUsbTargetDeviceCreate(Device, WDF_NO_OBJECT_ATTRIBUTES, &pDeviceContext->WdfUsbTargetDevice);
        if (!NT_SUCCESS(status))
		{
			PSDrv_DbgPrint(3, ("WdfUsbTargetDeviceCreate failed! (Status = %x)\n", status));
            return status;
        }
    }
    
    WdfUsbTargetDeviceGetDeviceDescriptor(pDeviceContext->WdfUsbTargetDevice, &pDeviceContext->UsbDeviceDescriptor);

    ASSERT(pDeviceContext->UsbDeviceDescriptor.bNumConfigurations);

    status = ConfigureDevice(Device);

    return status;
}
示例#5
0
/**
 * USB オープン
 * @param[in] vid VID
 * @param[in] pid PID
 * @retval true 成功
 * @retval false 失敗
 */
bool CUsbDev::Open(unsigned int vid, unsigned int pid)
{
	// 探すデバイス
	const SInt32 usbVendor = vid;
	const SInt32 usbProduct = pid;

	// Set up matching dictionary for class IOUSBDevice and its subclasses
	CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
	if (matchingDict == NULL)
	{
		printf("Couldn't create a USB matching dictionary\n");
		return false;
	}

	// Add the vendor and product IDs to the matching dictionary.
	// This is the second key in the table of device-matching keys of the
	// USB Common Class Specification
	CFDictionarySetValue(matchingDict, CFSTR(kUSBVendorName), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor));
	CFDictionarySetValue(matchingDict, CFSTR(kUSBProductName), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbProduct));

	// インタフェイスを得る
	io_iterator_t iterator = 0;
	IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iterator);
	io_service_t usbDevice = IOIteratorNext(iterator);
	if (usbDevice == 0)
	{
		printf("Device not found\n");
		return false;
	}
	IOObjectRelease(iterator);

	// Create an intermediate plug-in
	IOCFPlugInInterface** plugInInterface = NULL;
	SInt32 score = 0;
	IOReturn kr = IOCreatePlugInInterfaceForService(usbDevice, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score);
	kr = IOObjectRelease(usbDevice);
	if ((kr != kIOReturnSuccess) || (plugInInterface == NULL))
	{
		printf("Unable to create a plug-in (%08x)\n", kr);
		return false;
	}

	// Now create the device interface
	IOUSBDeviceInterface** dev = NULL;
	HRESULT result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID), (LPVOID*)&dev);
	(*plugInInterface)->Release(plugInInterface);
	if ((result != S_OK) || (dev == NULL))
	{
		printf("Couldn't create a device interface (%08x)\n", (int)result);
		return false;
	}

	// Open the device to change its state
	kr = (*dev)->USBDeviceOpen(dev);
	if (kr != kIOReturnSuccess)
	{
		printf("Unable to open device: %08x\n", kr);
		(*dev)->Release(dev);
		return false;
	}

	// Configure device
	kr = ConfigureDevice(dev);
	if (kr != kIOReturnSuccess)
	{
		printf("Unable to configure device: %08x\n", kr);
		(*dev)->USBDeviceClose(dev);
		(*dev)->Release(dev);
		return false;
	}

	// Placing the constant kIOUSBFindInterfaceDontCare into the following
	// fields of the IOUSBFindInterfaceRequest structure will allow you
	// to find all the interfaces
	IOUSBFindInterfaceRequest request;
	request.bInterfaceClass = kIOUSBFindInterfaceDontCare;
	request.bInterfaceSubClass = kIOUSBFindInterfaceDontCare;
	request.bInterfaceProtocol = kIOUSBFindInterfaceDontCare;
	request.bAlternateSetting = kIOUSBFindInterfaceDontCare;

	// Get an iterator for the interfaces on the device
	io_iterator_t iterator2;
	kr = (*dev)->CreateInterfaceIterator(dev, &request, &iterator2);
	while (1 /*EVER*/)
	{
		io_service_t usbInterface = IOIteratorNext(iterator2);
		if (usbInterface == 0)
		{
			break;
		}

		// Create an intermediate plug-in
		IOCFPlugInInterface** plugInInterface = NULL;
		SInt32 score;
		kr = IOCreatePlugInInterfaceForService(usbInterface, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score);
		kr = IOObjectRelease(usbInterface);
		if ((kr != kIOReturnSuccess) || (plugInInterface == NULL))
		{
			printf("Unable to create a plug-in (%08x)\n", kr);
			continue;
		}

		// Now create the device interface for the interface
		IOUSBInterfaceInterface** interface = NULL;
		HRESULT result = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID), (LPVOID*)&interface);
		(*plugInInterface)->Release(plugInInterface);
		if ((result != S_OK) || (interface == NULL))
		{
			printf("Couldn't create a device interface for the interface(%08x)\n", (int) result);
			continue;
		}

		// Get interface class and subclass
		UInt8 interfaceClass;
		kr = (*interface)->GetInterfaceClass(interface, &interfaceClass);

		UInt8 interfaceSubClass;
		kr = (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass);

		printf("Interface class: %d, subclass: %d\n", interfaceClass, interfaceSubClass);

		// Now open the interface. This will cause the pipes associated with
		// the endpoints in the interface descriptor to be instantiated
		kr = (*interface)->USBInterfaceOpen(interface);
		if (kr != kIOReturnSuccess)
		{
			printf("Unable to open interface (%08x)\n", kr);
			(*interface)->Release(interface);
			continue;
		}

		// Get the number of endpoints associated with this interface
		UInt8 interfaceNumEndpoints;
		kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints);
		if (kr != kIOReturnSuccess)
		{
			printf("Unable to get number of endpoints (%08x)\n", kr);
			(*interface)->USBInterfaceClose(interface);
			(*interface)->Release(interface);
			continue;
		}
 
		printf("Interface has %d endpoints\n", interfaceNumEndpoints);
		// Access each pipe in turn, starting with the pipe at index 1
		// The pipe at index 0 is the default control pipe and should be
		// accessed using (*usbDevice)->DeviceRequest() instead
		for (int pipeRef = 1; pipeRef <= interfaceNumEndpoints; pipeRef++)
		{
			printf(" PipeRef %d: ", pipeRef);

			UInt8 direction;
			UInt8 number;
			UInt8 transferType;
			UInt16 maxPacketSize;
			UInt8 interval;
			kr = (*interface)->GetPipeProperties(interface, pipeRef, &direction, &number, &transferType, &maxPacketSize, &interval);
			if (kr != kIOReturnSuccess)
			{
				printf("Unable to get properties of pipe(%08x)\n", kr);
				continue;
			}

			const char* message;
			switch (direction)
			{
				case kUSBOut:
					message = "out";
					break;

				case kUSBIn:
					message = "in";
					break;

				case kUSBNone:
					message = "none";
					break;

				case kUSBAnyDirn:
					message = "any";
					break;

				default:
					message = "???";
					break;
			}
			printf("direction %s, ", message);

			switch (transferType)
			{
				case kUSBControl:
					message = "control";
					break;

				case kUSBIsoc:
					message = "isoc";
					break;

				case kUSBBulk:
					message = "bulk";
					break;

				case kUSBInterrupt:
					message = "interrupt";
					break;

				case kUSBAnyType:
					message = "any";
					break;

				default:
					message = "???";
					break;
			}
			printf("transfer type %s, maxPacketSize %d\n", message, maxPacketSize);
		}

		// Query G.I.M.I.C module info.
		m_device = dev;
		m_interface = interface;
		return true;
	}

	(*dev)->USBDeviceClose(dev);
	(*dev)->Release(dev);

	return false;
}
示例#6
0
//-------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------
void tDataSourcesDialog::CreateActions()
{
    /* Create these in order of importance.
    As many as possible will be added to the softkey bar in this order */

    m_pSelectAct = new tAction( tr( "Select" ), this );
    Connect( m_pSelectAct, SIGNAL( triggered() ), this, SLOT( Select() ) );
    m_ActionList << m_pSelectAct;

    m_pConfigureAct = new tAction( tr( "Configure device" ), this );
    Connect( m_pConfigureAct, SIGNAL( triggered() ), this, SLOT( ConfigureDevice() ) );
    m_ActionList << m_pConfigureAct;

    QString scopeName = tProductSettings::Instance().FullSimnetAllowed() ?
        tr( "Group", "The extent or effective range of a selection or setting" ) :
        tr( "Scope", "The extent or effective range of a selection or setting" );
    m_pScopeAct = new tListAction( scopeName, QStringList(), 0, Action::AutoShowPopup, this );
    SetScopeList( m_pScopeAct, true, true, true );
    Connect( m_pScopeAct, SIGNAL( ValueFinalised( int ) ), this, SLOT( OnScopeChanged( int ) ) );
    if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
    {
        m_ActionList << m_pScopeAct;
    }

    m_pRenameAct = new tAction( tr( "Rename" ), this );
    Connect( m_pRenameAct, SIGNAL( triggered() ), this, SLOT( RenameInst() ) );
    m_ActionList << m_pRenameAct;

    m_pNewInstanceAct = new tAction( tr( "New" ), this );
    Connect( m_pNewInstanceAct, SIGNAL( triggered() ), this, SLOT( NewInstance() ) );
    m_ActionList << m_pNewInstanceAct;

    m_pRemoveAct = new tAction( tr( "Remove" ), this );
    Connect( m_pRemoveAct, SIGNAL( triggered() ), this, SLOT( RemoveInst() ) );
    m_ActionList << m_pRemoveAct;

    QStringList numEnginesList = NumericStringList( 8 );
    m_pEngineNumSetAct = new tListAction( tr("Number of Engines"), numEnginesList, 0, Action::AutoShowPopup, this);
    Connect( m_pEngineNumSetAct, SIGNAL( ValueFinalised( int ) ), this, SLOT( OnUINumEnginesChanged( int ) ) );
    m_ActionList << m_pEngineNumSetAct;

    m_pTransNumSetAct = new tListAction( tr("Number of Transmissions"), numEnginesList, 0, Action::AutoShowPopup, this);
    Connect( m_pTransNumSetAct, SIGNAL( ValueFinalised( int ) ), this, SLOT( OnUINumTransChanged( int ) ) );
    m_ActionList << m_pTransNumSetAct;

    QStringList numTanksList = NumericStringList( 5 );
    m_pTankNumSetAct = new tListAction( tr("Number of Tanks"), numTanksList, 0, Action::AutoShowPopup, this);
    Connect( m_pTankNumSetAct, SIGNAL( ValueFinalised( int ) ), this, SLOT( OnUINumTanksChanged( int ) ) );
    m_ActionList << m_pTankNumSetAct;

    QStringList numTrimTabsList = NumericStringList( 3 );
    m_pTrimTabsNumSetAct = new tListAction( tr("Number of Trim Tabs"), numTrimTabsList, 0, Action::AutoShowPopup, this);
    Connect( m_pTrimTabsNumSetAct, SIGNAL( ValueFinalised( int ) ), this, SLOT( OnNumTrimTabsChanged( int ) ) );
    m_ActionList << m_pTrimTabsNumSetAct;

    if( tProductSettings::Instance().FullSimnetAllowed() )
    {
        m_pAutoSelectAct = new tAction( tr( "Auto Select" ), this );
        Connect( m_pAutoSelectAct, SIGNAL( triggered() ), this, SLOT( OnAutoSelect() ) );
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
        {
            m_ActionList << m_pAutoSelectAct;
        }
    }
    else
    {
        m_pAutoConfigureAct = new tAction( tr( "Auto Configure" ), this );
        Connect( m_pAutoConfigureAct, SIGNAL( triggered() ), this, SLOT( AutoConfigure() ) );
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
        {
            m_ActionList << m_pAutoConfigureAct;
        }
    }

    m_pGlobalResetAct = new tAction( tr( "Reset Global" ), this ); 
    Connect( m_pGlobalResetAct, SIGNAL( triggered() ), this, SLOT( ResetGlobal() ) );
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
    {
        m_ActionList << m_pGlobalResetAct;
    }

    m_pLocalResetAct = new tAction( tr( "Reset Local" ), this );
    Connect( m_pLocalResetAct, SIGNAL( triggered() ), this, SLOT( ResetLocal() ) );
        if (tHAL::Instance()->FeaturePresent(tHAL::ePF_NMEA2000) == true)
    {
        m_ActionList << m_pLocalResetAct;
    }

    // Add as many actions as possible to the softkey bar
    m_KeyList.clear();
    for( int i = 0; (i < m_NumKeys - 1) && (i < m_ActionList.size()); i++ )
    {
        m_KeyList << m_ActionList[i];
    }

    if ( HasTitleCloseButton() == false )
    {
        m_pCloseAct = new tAction( tr( "Close", "Text of the exit dialog button." ), this );
        Connect( m_pCloseAct, SIGNAL( triggered() ),  this, SIGNAL( CloseRequested() ) );
        m_KeyList << m_pCloseAct;
    }    

    // NSW-10765
    // Change what actions are displayed for Cougar
    // This should be done a better way - this will do for now.
    //
    // Configure Device
    // Scope
    // Rename
    // New
    // Remove
    // Auto Configure
    // Reset -> Sub menu
    //          Global
    //          Local

    if( tProductSettings::Instance().GetProductFamily() == tProductSettings::HDSGen2TouchFamily ||
        tProductSettings::Instance().GetProductFamily() == tProductSettings::HDSGen3TouchFamily )
    {
        m_KeyList.clear();

        m_KeyList << m_pConfigureAct;
        m_KeyList << m_pScopeAct;
        m_KeyList << m_pRenameAct;
        m_KeyList << m_pNewInstanceAct;
        m_KeyList << m_pRemoveAct;
        m_KeyList << m_pAutoConfigureAct;

        QList<tAction*> resetSubActions;
        resetSubActions << m_pGlobalResetAct;
        resetSubActions << m_pLocalResetAct;

        m_pResetAct = new tAction( tr("Reset") );
        m_pResetAct->SetSubActions(resetSubActions);
        m_ActionList << m_pSelectAct;

        m_KeyList << m_pResetAct;
    }

}
示例#7
0
int main_impl(const char *deviceName, const char *serverName, int port, const char *certFile, const char *keyFile, const char *caCertFile, const char *logFile)
{
	struct hostent *srv;
	int dev = -1;
	FILE* log = NULL;
	SOCKET sock = SOCKET_ERROR;
	struct sockaddr_in srvaddr;
	int keepalive = 1, hasCert, retCode;
	SSL_CTX *sslContext = NULL;
	SSL *sslSession = NULL;
	int sslRead;
	char b[100];

	// initial validation

	if (port < 1 || port > 65535)
	{
		printf("Port must be between 1 and 65535\n");
		return 3;
	}

	srv = gethostbyname(serverName);
	if (srv == NULL)
	{
		srv = gethostbyaddr(serverName, 4, AF_INET);
		if (srv == NULL)
		{
			printf("Cannot resolve server address: %s\n", serverName);
			return 3;
		}
	}

	hasCert = HAS_STR(certFile) + HAS_STR(keyFile) + HAS_STR(caCertFile);
	if (hasCert != 0 && hasCert != 3)
	{
		printf("Either all or none certificates must be specified\n");
		return 3;
	}

	// initial validation complete
	// connecting to server and opening device

	OpenLog(logFile);

	INFO("Opening device...\n");

	dev = open(deviceName, O_BINARY | O_RDWR | O_NOCTTY);
	if (dev == -1)
	{
		ERR("Failed to open device: %s\n", strerror(errno));
		RETURN(3);
	}

	DBG("Configuring device...\n");

	ConfigureDevice(dev);

	DBG("Creating a socket...\n");

	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (sock == SOCKET_ERROR)
	{
		ERR("Cannot create a socket\n");
		RETURN(3);
	}

	DBG("Enabling keep-alives on the socket...\n");
	if (0 != setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)))
	{
		WARN("Failed to enable keep-alives\n");
	}
	
	srvaddr.sin_family = AF_INET;
	srvaddr.sin_port = htons((u_short) port);
	memcpy(&srvaddr.sin_addr, srv->h_addr_list[0], 4);
	
	INFO("Connecting to server...\n");

	if (0 != connect(sock, (const struct sockaddr *) &srvaddr, sizeof(srvaddr)))
	{
		ERR("Cannot connect to %s:%d\n", serverName, port);
		RETURN(3);
	}

	if (0 != hasCert)
	{
		if (0 != SSLInit())
		{
			RETURN(3);
		}

		sslContext = SSLCreateContext(certFile, keyFile, caCertFile);
		if (sslContext == NULL)
		{
			RETURN(3);
		}

		sslSession = SSLHandshake(sock, sslContext);
		if (sslSession == NULL)
		{
			RETURN(3);
		}

		sslRead = SSL_read(sslSession, b, sizeof(b));
		switch (SSL_get_error(sslSession, sslRead))
		{
		case SSL_ERROR_NONE:
			break;

		case SSL_ERROR_ZERO_RETURN:
			DBG("Server has closed the SSL connection\n");

			SSLCloseSession(sslSession);

			sslSession = SSLHandshake(sock, sslContext);
			if (sslSession == NULL)
			{
				RETURN(3);
			}
			break;

		default:
			DEFAULT_HANDLER("Failed to receive server response", sslSession, sslRead);
			RETURN(3);
		}
	}
	
	
	IsTerminating = 0;

	signal(SIGTERM, sig_handler);
	signal(SIGINT, sig_handler);
#ifdef WIN32
	signal(SIGBREAK, sig_handler);
#endif

	retCode = worker(dev, sock, sslSession, certFile, keyFile, caCertFile);

	RETURN(retCode);
}
NTSTATUS AndroidUsbDeviceObject::OnEvtDevicePrepareHardware(
    WDFCMRESLIST resources_raw,
    WDFCMRESLIST resources_translated) {
  ASSERT_IRQL_PASSIVE();

  // Create a USB device handle so that we can communicate with the underlying
  // USB stack. The wdf_target_device_ handle is used to query, configure, and
  // manage all aspects of the USB device. These aspects include device
  // properties, bus properties, and I/O creation and synchronization. This
  // call gets the device and configuration descriptors and stores them in
  // wdf_target_device_ object.
  NTSTATUS status = WdfUsbTargetDeviceCreate(wdf_device(),
                                             WDF_NO_OBJECT_ATTRIBUTES,
                                             &wdf_target_device_);
  ASSERT(NT_SUCCESS(status) && (NULL != wdf_target_device_));
  if (!NT_SUCCESS(status))
    return status;

  // Retrieve USBD version information, port driver capabilites and device
  // capabilites such as speed, power, etc.
  WDF_USB_DEVICE_INFORMATION_INIT(&usb_device_info_);
  status = WdfUsbTargetDeviceRetrieveInformation(wdf_target_device(),
                                                 &usb_device_info_);
  ASSERT(NT_SUCCESS(status));
  if (!NT_SUCCESS(status))
    return status;

  WdfUsbTargetDeviceGetDeviceDescriptor(wdf_target_device(),
                                        &usb_device_descriptor_);
#if DBG
  PrintUsbTargedDeviceInformation(usb_device_info());
  PrintUsbDeviceDescriptor(&usb_device_descriptor_);
#endif  // DBG

  // Save device serial number
  status =
    WdfUsbTargetDeviceAllocAndQueryString(wdf_target_device(),
                                          WDF_NO_OBJECT_ATTRIBUTES,
                                          &serial_number_handle_,
                                          &serial_number_char_len_,
                                          usb_device_descriptor_.iSerialNumber,
                                          0x0409);  // English (US)
  if (!NT_SUCCESS(status))
    return status;

#if DBG
  UNICODE_STRING ser_num;
  ser_num.Length = serial_number_byte_len();
  ser_num.MaximumLength = ser_num.Length;
  ser_num.Buffer = const_cast<WCHAR*>
    (serial_number());
  GoogleDbgPrint("\n*** Device serial number %wZ", &ser_num);
#endif  // DBG

  // Configure our device now
  status = ConfigureDevice();
  ASSERT(NT_SUCCESS(status));
  if (!NT_SUCCESS(status))
    return status;

  // Select device interfaces
  status = SelectInterfaces();
  if (!NT_SUCCESS(status))
    return status;

  return status;
}
示例#9
0
void RawDeviceAdded(void *refCon, io_iterator_t iterator)
{
    kern_return_t               kr;
    io_service_t                usbDevice;
    IOCFPlugInInterface         **plugInInterface = NULL;
    IOUSBDeviceInterface        **dev = NULL;
    HRESULT                     result;
    SInt32                      score;
    UInt16                      vendor;
    UInt16                      product;
    UInt16                      release;
 
    while (usbDevice = IOIteratorNext(iterator))
    {
        //Create an intermediate plug-in
        kr = IOCreatePlugInInterfaceForService(usbDevice,
                    kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID,
                    &plugInInterface, &score);
        //Don’t need the device object after intermediate plug-in is created
        kr = IOObjectRelease(usbDevice);
        if ((kIOReturnSuccess != kr) || !plugInInterface)
        {
            printf("Unable to create a plug-in (%08x)\n", kr);
            continue;
        }
        //Now create the device interface
        result = (*plugInInterface)->QueryInterface(plugInInterface,
                        CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID),
                        (LPVOID *)&dev);
        //Don’t need the intermediate plug-in after device interface
        //is created
        (*plugInInterface)->Release(plugInInterface);
 
        if (result || !dev)
        {
            printf("Couldn’t create a device interface (%08x)\n",
                                                    (int) result);
            continue;
        }
 
        //Check these values for confirmation
        kr = (*dev)->GetDeviceVendor(dev, &vendor);
        kr = (*dev)->GetDeviceProduct(dev, &product);
        kr = (*dev)->GetDeviceReleaseNumber(dev, &release);
        if ((vendor != kOurVendorID) || (product != kOurProductID) ||
            (release != 1))
        {
            printf("Found unwanted device (vendor = %d, product = %d)\n",
                    vendor, product);
            printf("(or the release was not equal to 1: release = %d)\n", release);
            (void) (*dev)->Release(dev);
            continue;
        }
 
        //Open the device to change its state
        kr = (*dev)->USBDeviceOpen(dev);
        if (kr != kIOReturnSuccess)
        {
            printf("Unable to open device: %08x\n", kr);
            (void) (*dev)->Release(dev);
            continue;
        }
        //Configure device
        kr = ConfigureDevice(dev);
        if (kr != kIOReturnSuccess)
        {
            printf("Unable to configure device: %08x\n", kr);
            (void) (*dev)->USBDeviceClose(dev);
            (void) (*dev)->Release(dev);
            continue;
        }
/* 
        //Download firmware to device
        kr = DownloadToDevice(dev);
        if (kr != kIOReturnSuccess)
        {
            printf("Unable to download firmware to device: %08x\n", kr);
            (void) (*dev)->USBDeviceClose(dev);
            (void) (*dev)->Release(dev);
            continue;
        }
 */
        //Close this device and release object
        kr = (*dev)->USBDeviceClose(dev);
        kr = (*dev)->Release(dev);
    }
}
示例#10
0
void HandleUpdate() {
	ConfigureDevice();
	Updater();
}