Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hidv5 USB_Halt & Halt all usbkeyboard requests when closing device #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions libogc/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ distribution.
#define USBV0_IOCTL_DEVREMOVALHOOK 26
#define USBV0_IOCTL_DEVINSERTHOOK 27
#define USBV0_IOCTL_DEVICECLASSCHANGE 28
#define USBV0_IOCTL_RESETDEVICE 29

#define USBV4_IOCTL_GETVERSION 6 // returns 0x40001
#define USBV4_IOCTL_CANCELINTERRUPT 8

#define USBV5_IOCTL_GETVERSION 0 // should return 0x50001
#define USBV5_IOCTL_GETDEVICECHANGE 1
Expand Down Expand Up @@ -1430,7 +1432,7 @@ s32 USB_SetAlternativeInterface(s32 fd, u8 interface, u8 alternateSetting)
return __usb_control_message(fd, (USB_CTRLTYPE_DIR_HOST2DEVICE | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_INTERFACE), USB_REQ_SETINTERFACE, alternateSetting, interface, 0, NULL, NULL, NULL);
}

static s32 USBV5_CancelEndpoint(s32 device_id, u8 endpoint)
static s32 USBV5_CancelEndpoint(s32 device_id)
{
s32 ret;
s32 fd;
Expand All @@ -1446,19 +1448,35 @@ static s32 USBV5_CancelEndpoint(s32 device_id, u8 endpoint)
if (buf==NULL) return IPC_ENOMEM;

buf[0] = device_id;
buf[2] = endpoint;

//Cancel all control messages
buf[2] = 0x00;
ret = IOS_Ioctl(fd, USBV5_IOCTL_CANCELENDPOINT, buf, 32, NULL, 0);
iosFree(hId, buf);
if(ret < 0)
goto ret;

//Cancel all incoming interrupts
buf[2] = 0x01 << 24;
ret = IOS_Ioctl(fd, USBV5_IOCTL_CANCELENDPOINT, buf, 32, NULL, 0);
if(ret < 0)
goto ret;

//Cancel all outgoing interrupts
buf[2] = 0x02 << 24;
ret = IOS_Ioctl(fd, USBV5_IOCTL_CANCELENDPOINT, buf, 32, NULL, 0);
if(ret < 0)
goto ret;

ret:
iosFree(hId, buf);
return ret;
}

s32 USB_ClearHalt(s32 fd, u8 endpoint)
{
if (fd>=0x20 || fd<-1)
return USBV5_CancelEndpoint(fd, endpoint);
return USBV5_CancelEndpoint(fd);
return __usb_control_message(fd, (USB_CTRLTYPE_DIR_HOST2DEVICE | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_ENDPOINT), USB_REQ_CLEARFEATURE, USB_FEATURE_ENDPOINT_HALT, endpoint, 0, NULL, NULL, NULL);
}

#endif /* defined(HW_RVL) */

6 changes: 3 additions & 3 deletions libwiikeyboard/usbkeyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@ void USBKeyboard_Close(void)
return;

if(_kbd->fd != -1)
{
USB_ClearHalt( _kbd->fd, _kbd->ep );
USB_CloseDevice(&_kbd->fd);
}

free(_kbd);
_kbd = NULL;

return;
}

Expand Down Expand Up @@ -458,7 +460,6 @@ s32 USBKeyboard_Scan(void)
}

_kbd->sc_odata = _kbd->sc_ndata;

return 0;
}

Expand Down Expand Up @@ -492,4 +493,3 @@ s32 USBKeyboard_ToggleLed(const USBKeyboard_led led)

return 1;
}