Vault 7: Projects

This publication series is about specific projects related to the Vault 7 main publication.

Syntax
USB_HANDLE USBGetNextHandle(uint8_t ep_num, uint8_t ep_dir);
Description
Retrieves the handle to the next endpoint BDT that the USBTransferOnePacket() will use. Useful for initialization and when
ping pong buffering will be used on application endpoints.
Remarks
This API is useful for initializing USB_HANDLEs during initialization of the application firmware. It is also useful when
ping-pong bufferring is enabled, and the application firmware wishes to arm both the even and odd BDTs for an endpoint
simultaneously. In this case, the application firmware for sending data to the host would typically be something like follows:
USB_HANDLE Handle1;
USB_HANDLE Handle2;
USB_HANDLE* pHandle = &Handle1;
uint8_t UserDataBuffer1[64];
uint8_t UserDataBuffer2[64];
uint8_t* pDataBuffer = &UserDataBuffer1[0];
//Add some code that loads UserDataBuffer1[] with useful data to send,
//using the pDataBuffer pointer, for example:
//for(i = 0; i < 64; i++)
//{
// *pDataBuffer++ = [useful data value];
//}
//Check if the next USB endpoint BDT is available
if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST))
{
//The endpoint is available. Send the data.
*pHandle = USBTransferOnePacket(ep_num, ep_dir, pDataBuffer, bytecount);
//Toggle the handle and buffer pointer for the next transaction
if(pHandle == &Handle1)
{
pHandle = &Handle2;
pDataBuffer = &UserDataBuffer2[0];
}
else
{
pHandle = &Handle1;
pDataBuffer = &UserDataBuffer1[0];
}
}
//The firmware can then load the next data buffer (in this case
//UserDataBuffer2)with useful data, and send it using the same
//process. For example:
//Add some code that loads UserDataBuffer2[] with useful data to send,
//using the pDataBuffer pointer, for example:
//for(i = 0; i < 64; i++)
//{
// *pDataBuffer++ = [useful data value];
//}
//Check if the next USB endpoint BDT is available
if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST))
{
//The endpoint is available. Send the data.
*pHandle = USBTransferOnePacket(ep_num, ep_dir, pDataBuffer, bytecount);
//Toggle the handle and buffer pointer for the next transaction
if(pHandle == &Handle1)
{
pHandle = &Handle2;
pDataBuffer = &UserDataBuffer2[0];
}
else
{
1.4 Library Interface MLA - USB Library Help Device/Peripheral
52

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh