// The setup TD
setupTD = pipe.createTD(USB_PID_SETUP, true, setupPacket.getData(), 0, setupPacket.getSize(), false);
//log.debug("setupTD: " + setupTD + ", ls=" + ls);
// Add the data TD's
final USBPacket dataPacket = getDataPacket();
final int transferLength = setupPacket.getLength();
int length = transferLength;
int offset = 0;
final int dataPid = (setupPacket.isDirIn() ? USB_PID_IN : USB_PID_OUT);
boolean dataToggle = false; // Start with DATA1
final int maxPacketSize = pipe.getMaxPacketSize();
if (maxPacketSize <= 0) {
throw new USBException("Invalid maximum packet size " + maxPacketSize);
}
while (length > 0) {
// Create the TD for this part of the data packet
final TransferDescriptor dataTD;
final int curlen = Math.min(length, maxPacketSize);
dataTD = pipe.createTD(dataPid, dataToggle, dataPacket.getData(), offset, curlen, false);
// Add the TD to the list
setupTD.append(dataTD, false);
// Update fields
dataToggle = !dataToggle;