status_t Device::SetConfigurationAt(uint8 index) { if (!fAvailable) return B_ERROR; if (index >= fDeviceDescriptor.num_configurations) return B_BAD_VALUE; if (&fConfigurations[index] == fCurrentConfiguration) return B_OK; // Destroy our open endpoints Unconfigure(false); // Tell the device to set the configuration status_t result = fDefaultPipe->SendRequest( USB_REQTYPE_DEVICE_OUT | USB_REQTYPE_STANDARD, USB_REQUEST_SET_CONFIGURATION, fConfigurations[index].descr->configuration_value, 0, 0, NULL, 0, NULL); if (result < B_OK) return result; // Set current configuration fCurrentConfiguration = &fConfigurations[index]; // Initialize all the endpoints that are now active InitEndpoints(-1); // Wait some for the configuration being finished if (!fIsRootHub) snooze(USB_DELAY_SET_CONFIGURATION); return B_OK; }
status_t Device::SetAltInterface(const usb_interface_info* interface) { uint8 interfaceNumber = interface->descr->interface_number; // Tell the device to set the alternate settings status_t result = fDefaultPipe->SendRequest( USB_REQTYPE_INTERFACE_OUT | USB_REQTYPE_STANDARD, USB_REQUEST_SET_INTERFACE, interface->descr->alternate_setting, interfaceNumber, 0, NULL, 0, NULL); if (result < B_OK) return result; // Clear the no longer active endpoints ClearEndpoints(interfaceNumber); // Update the active pointer of the interface list usb_interface_list* interfaceList = &fCurrentConfiguration->interface[interfaceNumber]; interfaceList->active = &interfaceList->alt[interface->descr->alternate_setting]; // Initialize the new endpoints InitEndpoints(interfaceNumber); return result; }
void USBSetupInterrupt() { SetEP(0); if (!ReceivedSetupInt()) return; Setup& setup = _setup; // global saves ~30 bytes Recv((u8*)&setup,8); ClearSetupInt(); if (setup.bmRequestType & DEVICETOHOST) WaitIN(); else ClearIN(); bool ok = true; u8 r = setup.bRequest; if (SET_ADDRESS == r) { WaitIN(); UDADDR = setup.wValueL | (1<<ADDEN); } else if (SET_CONFIGURATION == r) { _usbConfiguration = setup.wValueL; InitEndpoints(); } else if (GET_CONFIGURATION == r) { Send8(_usbConfiguration); } else if (GET_STATUS == r) { Send8(0); // All good as far as I know } else if (GET_DESCRIPTOR == r) { ok = SendDescriptor(); } else { ok = USBHook(); } if (ok) ClearIN(); else Stall(); }