Skip to content

Commit 95dba3b

Browse files
author
Kiyotaka ATSUMI
committed
testing claim interface
1 parent 05112e5 commit 95dba3b

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ merge.sh
1010
.project
1111
.cproject
1212
test/relaytest/relaytest
13+
typescript

src/Plugins/Devices/DeviceProxy_LibUSB.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "myDebug.h"
3333

3434
int DeviceProxy_LibUSB::debugLevel=0;
35+
int resetCount = 1;
3536

3637
static DeviceProxy_LibUSB *proxy;
3738

@@ -336,14 +337,17 @@ char* DeviceProxy_LibUSB::toString() {
336337
}
337338

338339
int DeviceProxy_LibUSB::control_request(const usb_ctrlrequest *setup_packet, int *nbytes, __u8* dataptr,int timeout) {
340+
int rc;
339341
dbgMessage("");
340342
if (debugLevel>1) {
341343
char* hex=hex_string((void*)setup_packet,sizeof(*setup_packet));
342344
printf("LibUSB> %s\n",hex);
343345
free(hex);
344346
}
347+
345348
dbgMessage("");
346-
int rc=libusb_control_transfer(dev_handle,setup_packet->bRequestType,setup_packet->bRequest,setup_packet->wValue,setup_packet->wIndex,dataptr,setup_packet->wLength,timeout);
349+
rc=libusb_control_transfer(dev_handle,setup_packet->bRequestType,setup_packet->bRequest,setup_packet->wValue,setup_packet->wIndex,dataptr,setup_packet->wLength,timeout);
350+
347351
dbgMessage(""); fprintf( stderr, "%d=libusb_control_transfer(%x, %02x, %02x, %04x, %04x, %04x, %d)\n", rc,dev_handle,setup_packet->bRequestType,setup_packet->bRequest,setup_packet->wValue,setup_packet->wIndex,dataptr,setup_packet->wLength,timeout); myDump( dataptr, rc);
348352
if (rc<0) {
349353
if (debugLevel) {fprintf(stderr,"Error %d[%s] sending setup packet.\n",rc,libusb_error_name(rc));}
@@ -359,7 +363,8 @@ int DeviceProxy_LibUSB::control_request(const usb_ctrlrequest *setup_packet, int
359363

360364
// modified 20141001 atsumi@aizulab.com
361365
// to reset after recieving mirrorlink magic packet.
362-
if ( setup_packet->bRequestType == 0x40 && setup_packet->bRequest == 0xf0) {
366+
if ( resetCount > 0 && setup_packet->bRequestType == 0x40 && setup_packet->bRequest == 0xf0) {
367+
resetCount--;
363368
sleep(1);
364369
kill( 0, SIGHUP);
365370
}
@@ -372,6 +377,8 @@ __u8 DeviceProxy_LibUSB::get_address() {
372377
return libusb_get_device_address(dvc);
373378
}
374379

380+
// modified 20141002 atsumi@aizulab.com
381+
// It should claim interface right before beginning data transmission.
375382
void DeviceProxy_LibUSB::send_data(__u8 endpoint,__u8 attributes,__u16 maxPacketSize,__u8* dataptr,int length) {
376383
dbgMessage("");
377384
int transferred;
@@ -439,11 +446,20 @@ void DeviceProxy_LibUSB::receive_data(__u8 endpoint,__u8 attributes,__u16 maxPac
439446
void DeviceProxy_LibUSB::claim_interface(__u8 interface) {
440447
int rc;
441448

449+
dbgMessage("");
442450
// for test code 20140912 atsumi@aizulab.com
443451
__u8 buf[256];
444452
usb_ctrlrequest setup_packet;
445453
int len=0;
446454

455+
// modified 20141002 atsumi@aizulab.com
456+
// casual hack for nokia701 because it will be setting wrong altinterface.
457+
// for mirrorLink
458+
//if ( interface == 3) {
459+
// libusb_set_interface_alt_setting( dev_handle, 3, 1);
460+
//}
461+
462+
/*
447463
setup_packet.bRequestType=USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
448464
setup_packet.bRequest=USB_REQ_GET_CONFIGURATION;
449465
setup_packet.wValue= 0;
@@ -453,19 +469,6 @@ void DeviceProxy_LibUSB::claim_interface(__u8 interface) {
453469
len = 0;
454470
control_request(&setup_packet,&len,buf);
455471
dbgMessage(""); myDump( buf, len);
456-
457-
/*
458-
for ( int i = 0; i < 3; i++) {
459-
setup_packet.bRequestType=USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
460-
setup_packet.bRequest=USB_REQ_GET_DESCRIPTOR;
461-
setup_packet.wValue= ((USB_DT_CONFIG)<<8) | i;
462-
setup_packet.wIndex=0;
463-
setup_packet.wLength=256;
464-
len=0;
465-
dbgMessage("USB_REQ_GET_DESCRIPTOR(CONFIG)");
466-
control_request(&setup_packet,&len,buf);
467-
dbgMessage(""); myDump( buf, len);
468-
}
469472
*/
470473

471474
if (is_connected()) {

src/lib/Manager.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,13 @@ void Manager::start_data_relaying() {
500500
}
501501

502502
//Claim interfaces
503-
dbgMessage("");
504-
for (ifc_idx=0;ifc_idx<ifc_cnt;ifc_idx++) {
505-
dbgMessage("");
506-
deviceProxy->claim_interface(ifc_idx);
507-
}
503+
// deleted 20141002 atsumi@aizulab.com
504+
// claim_interface should be called when an endpoint in each interface.
505+
// dbgMessage("");
506+
// for (ifc_idx=0;ifc_idx<ifc_cnt;ifc_idx++) {
507+
// dbgMessage("");
508+
// deviceProxy->claim_interface(ifc_idx);
509+
// }
508510

509511
dbgMessage("");
510512
for(i=1;i<16;i++) {

0 commit comments

Comments
 (0)