PERFORCE change 165326 for review

Sylvestre Gallon syl at FreeBSD.org
Sat Jun 27 18:17:33 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=165326

Change 165326 by syl at syl_atuin on 2009/06/27 18:16:31

	Add trace.
	Update the code to open the first memory stick device.

Affected files ...

.. //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test3/test3.c#4 edit

Differences ...

==== //depot/projects/soc2009/syl_usb/libusb-tests/transfers/test3/test3.c#4 (text+ko) ====

@@ -57,6 +57,7 @@
 {
 	int transferred = 0;
 
+	printf("do_io\n");
 	libusb_bulk_transfer(devh, ep, buff, len, &transferred, timeout);	
 	while(!transferred);
 }
@@ -67,6 +68,7 @@
 	umass_bbb_cbw_t cbw;
 	umass_bbb_csw_t csw;
 
+	printf("do_msc\n");
 	bzero(&cbw, sizeof(cbw));
 
 	USETDW(cbw.dCBWSignature, CBWSIGNATURE);
@@ -95,6 +97,7 @@
 {
 	static uint8_t cmd[10];
 
+	printf("do_read\n");
 	cmd[0] = 0x28;
 	len /= 512;
 
@@ -111,6 +114,11 @@
 int main(int ac, char *av[])
 {
 	volatile int transferred;
+	libusb_device **devs_list;
+	libusb_device_descriptor ddesc;
+	int found = 0;
+	int ret;
+	int i;
 
 	printf("this test dump the 512 first byte of a memory stick\n");
 	if (libusb_init(&ctx) != 0) {
@@ -118,32 +126,62 @@
 		return (EXIT_FAILURE);
 	}
 
-	transferred = 0;
-	if ((devh = libusb_open_device_with_vid_pid(ctx, VID_TEST, PID_TEST)) != NULL) {
-		libusb_detach_kernel_driver(devh, 1);
-		libusb_clear_halt(devh, EP_IN);
-		libusb_clear_halt(devh, EP_OUT);
+	if ((ret = libusb_get_device_list(ctx, &devs_list)) < 0 ) {
+		fprintf(stderr, "libusb_get_device_list failed with 0x%x error code\n",
+		    ret);
+		return (EXIT_FAILURE);
+	}
+
+	if (ret == 0) {
+		fprintf(stderr, "No device match or lack of permissions.\n");
+		return (EXIT_SUCCESS);
+	}
+	
+	for (i = 0 ; i < ret ; i++) {
+		libusb_get_device_descriptor(devs_list[i], &ddesc);
+		if (ddesc.bDeviceClass == 0x00) {
+			printf("found device %i\n", i);
+			found = i;
+			break ;
+		}
+	}
+
+	if (!found) {
+		printf("No USB stick found\n");
+		return (EXIT_FAILURE);
+	}
+
+	libusb_open(devs_list[found], &devh);
+	libusb_detach_kernel_driver(devh, 1);
+	
+	libusb_clear_halt(devh, EP_IN);
+	libusb_clear_halt(devh, EP_OUT);
 
-		do_msc_req(mode_sense_6, sizeof(mode_sense_6),0xc);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(request_sense, sizeof(request_sense), 0x12);
-		do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
-		do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
+	do_msc_req(mode_sense_6, sizeof(mode_sense_6),0xc);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(request_sense, sizeof(request_sense), 0x12);
+	do_msc_req(test_unit_ready, sizeof(test_unit_ready), 0xd);
+	do_msc_req(read_capacity, sizeof(read_capacity), 0x8);
 
-		do_read(0, BLOCK_SIZE);
+	do_read(0, BLOCK_SIZE);
+	for (i = 0 ; i < BLOCK_SIZE ; i++) {
+		if (i != 0 && (i % 0x10) == 0)
+			printf("\n");
+		printf("0.2x ", buffer[i]);
 	}
+	printf("\n");
 
 	return (EXIT_SUCCESS);
 }


More information about the p4-projects mailing list