补充一下,在USBSwitch中找到如下代码:
int switchHuaweiMode () {
int ret;
SHOW_PROGRESS("Sending Huawei control message ...\n");
ret = usb_control_msg(devh, USB_TYPE_STANDARD + USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, 00000001, 0, buffer, 0, 1000);
if (ret != 0) {
fprintf(stderr, "Error: sending Huawei control message failed (error %d). Aborting.\n\n", ret);
exit(1);
} else
SHOW_PROGRESS(" OK, Huawei control message sent\n");
}
int switchSierraMode () {
int ret;
SHOW_PROGRESS("Trying to send Sierra control message\n");
ret = usb_control_msg(devh, 0x40, 0x0b, 00000001, 0, buffer, 0, 1000);
if (ret != 0) {
fprintf(stderr, "Error: sending Sierra control message failed (error %d). Aborting.\n\n", ret);
exit(1);
} else
SHOW_PROGRESS(" OK, Sierra control message sent\n");
}
int switchSonyMode () {
int i, found, ret;
detachDriver();
if (CheckSuccess) {
printf("Note: CheckSuccess pointless with Sony mode, disabling\n");
CheckSuccess = 0;
}
SHOW_PROGRESS("Trying to send Sony control message\n");
ret = usb_control_msg(devh, 0xc0, 0x11, 2, 0, buffer, 3, 100);
if (ret < 0) {
fprintf(stderr, "Error: sending Sony control message failed (error %d). Aborting.\n\n", ret);
exit(1);
} else
SHOW_PROGRESS(" OK, control message sent, waiting for device to return ...\n");
usb_close(devh);
i=0;
dev = NULL;
while ( dev == NULL && i < 30 ) {
if ( i > 5 ) {
usb_find_busses();
usb_find_devices();
dev = search_devices(&found, DefaultVendor, DefaultProduct, TargetClass);
}
if ( dev != NULL )
break;
sleep(1);
if (show_progress) {
printf("#");
fflush(stdout);
}
i++;
}
SHOW_PROGRESS("\n After %d seconds:",i);
if ( dev != NULL ) {
SHOW_PROGRESS(" device came back, proceeding\n");
devh = NULL;
devh = usb_open( dev );
if (devh == NULL) {
fprintf(stderr, "Error: could not get handle on device\n");
return 0;
}
} else {
SHOW_PROGRESS(" device still gone, cancelling\n");
return 0;
}
sleep(1);
// switchAltSetting();
// sleep(1);
SHOW_PROGRESS("Sending Sony control message again ...\n");
ret = usb_control_msg(devh, 0xc0, 0x11, 2, 0, buffer, 3, 100);
if (ret < 0) {
fprintf(stderr, "Error: sending Sony control message (2) failed (error %d)\n", ret);
return 0;
} else {
SHOW_PROGRESS(" OK, control message sent\n");
return 1;
}
Interface=8;
AltSetting=2;
}
// Detach driver either as the main action or as preparation for other modes
int detachDriver() {
int ret;
#ifndef LIBUSB_HAS_GET_DRIVER_NP
printf(" Cant't do driver detection and detaching on this platform.\n");
return 2;
#endif
SHOW_PROGRESS("Looking for active driver ...\n");
ret = usb_get_driver_np(devh, Interface, buffer, BUF_SIZE);
if (ret != 0) {
SHOW_PROGRESS(" No driver found. Either detached before or never attached\n");
return 1;
}
SHOW_PROGRESS(" OK, driver found ("%s")\n", buffer);
if (DetachStorageOnly && strcmp(buffer,"usb-storage")) {
SHOW_PROGRESS(" Driver is not usb-storage, leaving it alone\n");
return 1;
}
#ifndef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
SHOW_PROGRESS(" Can't do driver detaching on this platform\n");
return 2;
#endif
ret = usb_detach_kernel_driver_np(devh, Interface);
if (ret == 0) {
SHOW_PROGRESS(" OK, driver "%s" detached\n", buffer);
// usb_clear_halt(devh, MessageEndpoint);
// usb_clear_halt(devh, ResponseEndpoint);
} else
SHOW_PROGRESS(" Driver "%s" detach failed with error %d. Trying to continue\n", buffer, ret);
return 1;
}
复制代码
不知道是否是使用这个来完成的,如果转换到wince应该怎么写这句话,是应该使用IssueControlTransfer向端点0发送一个指令吗???