Fixed the weird libusb issue...

This commit is contained in:
2019-10-26 16:46:07 -04:00
parent 48202b23aa
commit 2edfdb1589
5 changed files with 32 additions and 37 deletions

17
.idea/workspace.xml generated
View File

@@ -13,7 +13,11 @@
</component>
<component name="ChangeListManager">
<list default="true" id="b2f61e55-9467-486e-b84a-47b98c1101b5" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/libusb/config.h" beforeDir="false" afterPath="$PROJECT_DIR$/libusb/config.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/libusb_helpers.c" beforeDir="false" afterPath="$PROJECT_DIR$/libusb_helpers.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/libusb_helpers.h" beforeDir="false" afterPath="$PROJECT_DIR$/libusb_helpers.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/main.c" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@@ -94,14 +98,9 @@
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/libusb_helpers.c</url>
<line>133</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/libusb/libusb/os/linux_usbfs.c</url>
<line>2719</line>
<option name="timeStamp" value="3" />
<url>file://$PROJECT_DIR$/libusb/libusb/io.c</url>
<line>1579</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>

View File

@@ -5,10 +5,10 @@
#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
/* Start with debug message logging enabled */
#define ENABLE_DEBUG_LOGGING 1
//#define ENABLE_DEBUG_LOGGING 1
/* Message logging */
#define ENABLE_LOGGING 1
//#define ENABLE_LOGGING 1
/* Define to 1 if you have the <asm/types.h> header file. */
/* #undef HAVE_ASM_TYPES_H */

View File

@@ -1,11 +1,6 @@
//
// Created by grg on 10/23/19.
//
#include "libusb_helpers.h"
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
@@ -44,15 +39,14 @@ void libusb1_async_ctrl_transfer(libusb_device_handle *handle,
unsigned int timeout)
{
struct timeval start, end;
unsigned char usb_transfer_buf[8 + 2 + data_len];
unsigned char usb_transfer_buf[8 + data_len];
int ret;
gettimeofday(&start, NULL);
struct libusb_transfer *usb_transfer = libusb_alloc_transfer(0);
libusb_fill_control_setup(usb_transfer_buf, bmRequestType, bRequest, wValue, wIndex, 0xC0);
memset(&usb_transfer_buf[8], data_len, 2);
memcpy(&usb_transfer_buf[10], data, data_len);
memcpy(&usb_transfer_buf[8], data, data_len);
libusb_fill_control_transfer(usb_transfer, handle, usb_transfer_buf, NULL, NULL, 1);
ret = libusb_submit_transfer(usb_transfer);
@@ -69,13 +63,11 @@ void libusb1_async_ctrl_transfer(libusb_device_handle *handle,
if(end.tv_usec - start.tv_usec > timeout)
{
ret = libusb_cancel_transfer(usb_transfer);
libusb_free_transfer(usb_transfer);
if(ret != 0)
{
printf("Failed to cancel async USB transfer: %s\n", libusb_error_name(ret));
exit(ret);
}
return;
}
}
@@ -113,7 +105,7 @@ void stall(libusb_device_handle *handle)
printf("Stall\n");
unsigned char *data = malloc(0xC0);
memset(data, 0xA, 0xC0);
libusb1_async_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0xC0, 1000);
libusb1_async_ctrl_transfer(handle, 0x80, 6, 0x304, 0x40A, data, 0xC0, 1);
free(data);
}

View File

@@ -1,7 +1,7 @@
#ifndef IPWNDFU_REWRITE_C_LIBUSB_HELPERS_H
#define IPWNDFU_REWRITE_C_LIBUSB_HELPERS_H
#include "libusb-1.0/libusb.h"
#include <libusb-1.0/libusb.h>
struct libusb_device_bundle
{

32
main.c
View File

@@ -49,21 +49,25 @@ int main()
usb_req_leak(usb_handle);
no_leak(usb_handle);
// libusb_close(usb_handle);
// libusb_exit(usb_ctx);
//
// usb_bundle.handle = NULL;
//
// // section 2
// libusb_init(&usb_ctx);
// get_test_device(usb_ctx, &usb_bundle);
// if(usb_bundle.handle == NULL)
// {
// libusb_exit(usb_ctx);
// printf("Could not find device\n");
// return 1;
// }
libusb_reset_device(usb_handle);
libusb_close(usb_handle);
libusb_exit(usb_ctx);
usb_bundle.handle = NULL;
// section 2
libusb_init(&usb_ctx);
get_test_device(usb_ctx, &usb_bundle);
if(usb_bundle.handle == NULL)
{
libusb_exit(usb_ctx);
printf("Could not find device\n");
return 1;
}
usb_handle = usb_bundle.handle;
usb_desc = usb_bundle.descriptor;
return 0;
}