Exemplo n.º 1
0
boolean CUSBHIDDevice::Configure (void)
{
	if (GetNumEndpoints () < 1)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}
	
	TUSBEndpointDescriptor *pEndpointDesc =
		(TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT);
	if (   pEndpointDesc == 0
	    || (pEndpointDesc->bEndpointAddress & 0x80) != 0x80		// Input EP
	    || (pEndpointDesc->bmAttributes     & 0x3F)	!= 0x03)	// Interrupt EP
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	assert (m_pReportEndpoint == 0);
	m_pReportEndpoint = new CUSBEndpoint (GetDevice (), pEndpointDesc);
	assert (m_pReportEndpoint != 0);

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set interface");

		return FALSE;
	}

	if (GetHost ()->ControlMessage (GetEndpoint0 (),
					REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_INTERFACE,
					SET_PROTOCOL, BOOT_PROTOCOL,
					GetInterfaceNumber (), 0, 0) < 0)
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set boot protocol");

		return FALSE;
	}

	return StartRequest ();
}
Exemplo n.º 2
0
boolean CUSBBluetoothDevice::Configure (void)
{
	if (GetInterfaceNumber () != 0)
	{
		CLogger::Get ()->Write (FromBluetooth, LogWarning, "Voice channels are not supported");

		return FALSE;
	}

	if (GetNumEndpoints () != 3)
	{
		ConfigurationError (FromBluetooth);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointBulkIn != 0)
				{
					ConfigurationError (FromBluetooth);

					return FALSE;
				}

				m_pEndpointBulkIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointBulkOut != 0)
				{
					ConfigurationError (FromBluetooth);

					return FALSE;
				}

				m_pEndpointBulkOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
		else if ((pEndpointDesc->bmAttributes & 0x3F) == 0x03)		// Interrupt
		{
			if (m_pEndpointInterrupt != 0)
			{
				ConfigurationError (FromBluetooth);

				return FALSE;
			}

			m_pEndpointInterrupt = new CUSBEndpoint (GetDevice (), pEndpointDesc);
		}
	}

	if (   m_pEndpointBulkIn    == 0
	    || m_pEndpointBulkOut   == 0
	    || m_pEndpointInterrupt == 0)
	{
		ConfigurationError (FromBluetooth);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromBluetooth, LogError, "Cannot set interface");

		return FALSE;
	}

	m_pEventBuffer = new u8[m_pEndpointInterrupt->GetMaxPacketSize ()];
	assert (m_pEventBuffer != 0);

	CString DeviceName;
	DeviceName.Format ("ubt%u", s_nDeviceNumber++);
	CDeviceNameService::Get ()->AddDevice (DeviceName, this, FALSE);

	return TRUE;
}
Exemplo n.º 3
0
boolean CSMSC951xDevice::Configure (void)
{
	CBcmPropertyTags Tags;
	TPropertyTagMACAddress MACAddress;
	if (Tags.GetTag (PROPTAG_GET_MAC_ADDRESS, &MACAddress, sizeof MACAddress))
	{
		m_MACAddress.Set (MACAddress.Address);
	}
	else
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot get MAC address");

		return FALSE;
	}
	CString MACString;
	m_MACAddress.Format (&MACString);
	CLogger::Get ()->Write (FromSMSC951x, LogDebug, "MAC address is %s", (const char *) MACString);

	if (GetNumEndpoints () != 3)
	{
		ConfigurationError (FromSMSC951x);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointBulkIn != 0)
				{
					ConfigurationError (FromSMSC951x);

					return FALSE;
				}

				m_pEndpointBulkIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointBulkOut != 0)
				{
					ConfigurationError (FromSMSC951x);

					return FALSE;
				}

				m_pEndpointBulkOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (   m_pEndpointBulkIn  == 0
	    || m_pEndpointBulkOut == 0)
	{
		ConfigurationError (FromSMSC951x);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set interface");

		return FALSE;
	}

	u8 MACAddressBuffer[MAC_ADDRESS_SIZE];
	m_MACAddress.CopyTo (MACAddressBuffer);
	u16 usMACAddressHigh =   (u16) MACAddressBuffer[4]
			       | (u16) MACAddressBuffer[5] << 8;
	u32 nMACAddressLow   =   (u32) MACAddressBuffer[0]
			       | (u32) MACAddressBuffer[1] << 8
			       | (u32) MACAddressBuffer[2] << 16
			       | (u32) MACAddressBuffer[3] << 24;
	if (   !WriteReg (ADDRH, usMACAddressHigh)
	    || !WriteReg (ADDRL, nMACAddressLow))
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set MAC address");

		return FALSE;
	}

	if (   !WriteReg (LED_GPIO_CFG,   LED_GPIO_CFG_SPD_LED
					| LED_GPIO_CFG_LNK_LED
					| LED_GPIO_CFG_FDX_LED)
	    || !WriteReg (MAC_CR,  MAC_CR_RCVOWN
				 //| MAC_CR_PRMS		// promiscous mode
				 | MAC_CR_TXEN
				 | MAC_CR_RXEN)
	    || !WriteReg (TX_CFG, TX_CFG_ON))
	{
		CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot start device");

		return FALSE;
	}

	AddNetDevice ();

	return TRUE;
}
Exemplo n.º 4
0
boolean CUSBHIDDevice::Configure (unsigned nMaxReportSize)
{
	if (GetNumEndpoints () < 1)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x03)		// Interrupt EP
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input EP
			{
				if (m_pReportEndpoint != 0)
				{
					ConfigurationError (FromUSBHID);

					return FALSE;
				}

				m_pReportEndpoint = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output EP
			{
				if (m_pEndpointOut != 0)
				{
					ConfigurationError (FromUSBHID);

					return FALSE;
				}

				m_pEndpointOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (m_pReportEndpoint == 0)
	{
		ConfigurationError (FromUSBHID);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set interface");

		return FALSE;
	}

	if (   GetInterfaceClass ()    == 3	// HID class
	    && GetInterfaceSubClass () == 1)	// boot class
	{
		if (GetHost ()->ControlMessage (GetEndpoint0 (),
						REQUEST_OUT | REQUEST_CLASS | REQUEST_TO_INTERFACE,
						SET_PROTOCOL, BOOT_PROTOCOL,
						GetInterfaceNumber (), 0, 0) < 0)
		{
			CLogger::Get ()->Write (FromUSBHID, LogError, "Cannot set boot protocol");

			return FALSE;
		}
	}

	if (m_nMaxReportSize == 0)
	{
		m_nMaxReportSize = nMaxReportSize;
		assert (m_nMaxReportSize > 0);

		assert (m_pReportBuffer == 0);
		m_pReportBuffer = new u8[m_nMaxReportSize];
	}
	assert (m_pReportBuffer != 0);

	return TRUE;
}
Exemplo n.º 5
0
boolean CUSBPrinterDevice::Configure (void)
{
	m_Protocol = (TUSBPrinterProtocol) GetInterfaceProtocol ();
	if (   m_Protocol == USBPrinterProtocolUnknown
	    || m_Protocol > USBPrinterProtocolBidirectional)
	{
		CLogger::Get ()->Write (FromPrinter, LogError, "Protocol %u is not supported", (unsigned) m_Protocol);

		return FALSE;
	}

	if (GetNumEndpoints () < (m_Protocol == USBPrinterProtocolUnidirectional ? 1 : 2))
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	const TUSBEndpointDescriptor *pEndpointDesc;
	while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0)
	{
		if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02)		// Bulk
		{
			if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80)	// Input
			{
				if (m_pEndpointIn != 0)
				{
					ConfigurationError (FromPrinter);

					return FALSE;
				}

				m_pEndpointIn = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
			else							// Output
			{
				if (m_pEndpointOut != 0)
				{
					ConfigurationError (FromPrinter);

					return FALSE;
				}

				m_pEndpointOut = new CUSBEndpoint (GetDevice (), pEndpointDesc);
			}
		}
	}

	if (m_pEndpointOut == 0)
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	if (   m_Protocol != USBPrinterProtocolUnidirectional
	    && m_pEndpointIn == 0)
	{
		ConfigurationError (FromPrinter);

		return FALSE;
	}

	if (!CUSBFunction::Configure ())
	{
		CLogger::Get ()->Write (FromPrinter, LogError, "Cannot set interface");

		return FALSE;
	}

	CString DeviceName;
	DeviceName.Format ("uprn%u", s_nDeviceNumber++);
	CDeviceNameService::Get ()->AddDevice (DeviceName, this, FALSE);

	return TRUE;
}