BOOL USBHostAndroidInit(BYTE address, DWORD flags, BYTE clientDriverID) { USB_INTERFACE_INFO *pIntInfo; USB_DEVICE_DESCRIPTOR *pDev; USB_DEVICE_INFO *pDevInfo = USBHostGetDeviceInfo(); // Initialize state memset(&gc_DevData, 0, sizeof gc_DevData); // Save device the address, VID, & PID gc_DevData.ID.deviceAddress = address; pDev = (USB_DEVICE_DESCRIPTOR *) USBHostGetDeviceDescriptor(address); gc_DevData.ID.vid = pDev->idVendor; gc_DevData.ID.pid = pDev->idProduct; // Save the endpoint addresses for the interfaces for (pIntInfo = pDevInfo->pInterfaceList; pIntInfo; pIntInfo = pIntInfo->next) { int i; log_printf("Encoutered interface %d, class 0x%x, subclass 0x%x, protocol, 0x%x", pIntInfo->interface, pIntInfo->type.cls, pIntInfo->type.subcls, pIntInfo->type.proto); for (i = 0; i < ARRAY_SIZE(interfaceTable); ++i) { InterfaceTableEntry *pEntry = &interfaceTable[i]; if (0 == memcmp(&pEntry->type, &pIntInfo->type, sizeof(USB_INTERFACE_TYPE_INFO))) { pEntry->func(pIntInfo, pEntry->userData); break; } } } gc_DevData.initialized = 1; log_printf("Android Client Initalized: flags=0x%lx address=%d VID=0x%x PID=0x%x", flags, address, gc_DevData.ID.vid, gc_DevData.ID.pid); return TRUE; } // USBHostAndroidInit
BOOL USBHostAndroidInit(BYTE address, DWORD flags, BYTE clientDriverID) { USB_INTERFACE_INFO *pIntInfo; USB_DEVICE_DESCRIPTOR *pDev; USB_DEVICE_INFO *pDevInfo = USBHostGetDeviceInfo(); USB_ENDPOINT_INFO *pFirstEpInfo; USB_ENDPOINT_INFO *pSecondEpInfo; // Initialize state memset(&gc_DevData, 0, sizeof gc_DevData); // Save device the address, VID, & PID gc_DevData.ID.deviceAddress = address; pDev = (USB_DEVICE_DESCRIPTOR *) USBHostGetDeviceDescriptor(address); gc_DevData.ID.vid = pDev->idVendor; gc_DevData.ID.pid = pDev->idProduct; // Save the endpoint addresses for the interfaces for (pIntInfo = pDevInfo->pInterfaceList; pIntInfo; pIntInfo = pIntInfo->next) { ANDROID_INTERFACE *pInterface; BYTE iid = pIntInfo->interface; if (iid >= ANDROID_INTERFACE_MAX) return FALSE; pInterface = &gc_DevData.interfaces[iid]; pFirstEpInfo = pIntInfo->pCurrentSetting->pEndpointList; if (!pFirstEpInfo) return FALSE; pSecondEpInfo = pFirstEpInfo->next; if (!pSecondEpInfo) return FALSE; if (pSecondEpInfo->next) return FALSE; // we expect exactly 2 endpoints. if (pFirstEpInfo->bEndpointAddress & 0x80) { if (pSecondEpInfo->bEndpointAddress & 0x80) return FALSE; pInterface->inEndpoint = pFirstEpInfo->bEndpointAddress; pInterface->outEndpoint = pSecondEpInfo->bEndpointAddress; } else { if (!(pSecondEpInfo->bEndpointAddress & 0x80)) return FALSE; pInterface->inEndpoint = pSecondEpInfo->bEndpointAddress; pInterface->outEndpoint = pFirstEpInfo->bEndpointAddress; } gc_DevData.interfaces[iid].flags.initialized = 1; log_printf("Successfully initialized Android inteface %d. IN_EP=0x%x OUT_EP=0x%x", iid, pInterface->inEndpoint, pInterface->outEndpoint); } gc_DevData.initialized = 1; log_printf("Android Client Initalized: flags=0x%lx address=%d VID=0x%x PID=0x%x", flags, address, gc_DevData.ID.vid, gc_DevData.ID.pid); return TRUE; } // USBHostAndroidInit