void usb_init(int (*spawnD)()) { if (!initialized) { notificationIterators = (io_iterator_t*)malloc( vendorIdCount * sizeof(io_iterator_t)); adb_mutex_init(&start_lock, NULL); adb_cond_init(&start_cond, NULL); D("Before thread_create"); if(spawnD()) fatal_errno("cannot create RunLoopThread"); D("After thread_create"); // Wait for initialization to finish adb_mutex_lock(&start_lock); adb_cond_wait(&start_cond, &start_lock); adb_mutex_unlock(&start_lock); adb_mutex_destroy(&start_lock); adb_cond_destroy(&start_cond); initialized = 1; } }
void usb_init() { if (!initialized) { adb_thread_t tid; notificationIterators = (io_iterator_t*)malloc( vendorIdCount * sizeof(io_iterator_t)); adb_mutex_init(&start_lock, NULL); adb_cond_init(&start_cond, NULL); if(adb_thread_create(&tid, RunLoopThread, NULL)) fatal_errno("cannot create input thread"); // Wait for initialization to finish adb_mutex_lock(&start_lock); adb_cond_wait(&start_cond, &start_lock); adb_mutex_unlock(&start_lock); adb_mutex_destroy(&start_lock); adb_cond_destroy(&start_cond); initialized = 1; } }
void usb_init() { usb_handle *h; adb_thread_t tid; int fd; h = calloc(1, sizeof(usb_handle)); h->fd = -1; adb_cond_init(&h->notify, 0); adb_mutex_init(&h->lock, 0); // Open the file /dev/android_adb_enable to trigger // the enabling of the adb USB function in the kernel. // We never touch this file again - just leave it open // indefinitely so the kernel will know when we are running // and when we are not. fd = unix_open("/dev/android_adb_enable", O_RDWR); if (fd < 0) { D("failed to open /dev/android_adb_enable\n"); } else { close_on_exec(fd); } D("[ usb_init - starting thread ]\n"); if(adb_thread_create(&tid, usb_open_thread, h)){ fatal_errno("cannot create usb thread"); } }
void usb_init() { static bool initialized = false; if (!initialized) { atexit(usb_cleanup); adb_mutex_init(&start_lock, NULL); adb_cond_init(&start_cond, NULL); if (!adb_thread_create(RunLoopThread, nullptr)) { fatal_errno("cannot create input thread"); } // Wait for initialization to finish adb_mutex_lock(&start_lock); adb_cond_wait(&start_cond, &start_lock); adb_mutex_unlock(&start_lock); adb_mutex_destroy(&start_lock); adb_cond_destroy(&start_cond); initialized = true; } }
void usb_init() { if (!initialized) { adb_thread_t tid; adb_mutex_init(&start_lock, NULL); adb_cond_init(&start_cond, NULL); if(adb_thread_create(&tid, RunLoopThread, NULL)) fatal_errno("cannot create input thread"); // Wait for initialization to finish adb_mutex_lock(&start_lock); adb_cond_wait(&start_cond, &start_lock); adb_mutex_unlock(&start_lock); adb_mutex_destroy(&start_lock); adb_cond_destroy(&start_cond); initialized = 1; } }
//* TODO: simplify this further since we only register to get ADB interface //* subclass+protocol events static usb_handle* CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 product) { usb_handle* handle = NULL; IOReturn kr; UInt8 interfaceNumEndpoints, interfaceClass, interfaceSubClass, interfaceProtocol; UInt8 endpoint; //* Now open the interface. This will cause the pipes associated with //* the endpoints in the interface descriptor to be instantiated kr = (*interface)->USBInterfaceOpen(interface); if (kr != kIOReturnSuccess) { DBG("ERR: Could not open interface: (%08x)\n", kr); return NULL; } //* Get the number of endpoints associated with this interface kr = (*interface)->GetNumEndpoints(interface, &interfaceNumEndpoints); if (kr != kIOReturnSuccess) { DBG("ERR: Unable to get number of endpoints: (%08x)\n", kr); goto err_get_num_ep; } //* Get interface class, subclass and protocol if ((*interface)->GetInterfaceClass(interface, &interfaceClass) != kIOReturnSuccess || (*interface)->GetInterfaceSubClass(interface, &interfaceSubClass) != kIOReturnSuccess || (*interface)->GetInterfaceProtocol(interface, &interfaceProtocol) != kIOReturnSuccess) { DBG("ERR: Unable to get interface class, subclass and protocol\n"); goto err_get_interface_class; } //* check to make sure interface class, subclass and protocol match ADB //* avoid opening mass storage endpoints if (!is_adb_interface(vendor, product, interfaceClass, interfaceSubClass, interfaceProtocol)) goto err_bad_adb_interface; handle = (usb_handle *)calloc(1, sizeof(usb_handle)); adb_mutex_init(&handle->lock, 0); //* Iterate over the endpoints for this interface and find the first //* bulk in/out pipes available. These will be our read/write pipes. for (endpoint = 0; endpoint <= interfaceNumEndpoints; endpoint++) { UInt8 transferType; UInt16 maxPacketSize; UInt8 interval; UInt8 number; UInt8 direction; kr = (*interface)->GetPipeProperties(interface, endpoint, &direction, &number, &transferType, &maxPacketSize, &interval); if (kIOReturnSuccess == kr) { if (kUSBBulk != transferType) continue; if (kUSBIn == direction) handle->bulkIn = endpoint; if (kUSBOut == direction) handle->bulkOut = endpoint; handle->zero_mask = maxPacketSize - 1; } else { DBG("ERR: FindDeviceInterface - could not get pipe properties\n"); goto err_get_pipe_props; } } handle->interface = interface; return handle; err_get_pipe_props: free(handle); err_bad_adb_interface: err_get_interface_class: err_get_num_ep: (*interface)->USBInterfaceClose(interface); return NULL; }