s32 USB_SetAlternativeInterface(struct ehci_hcd * ehci,struct ehci_device *fd, u8 interface, u8 alternateSetting) { if(alternateSetting == 0) return -EINVAL; return __usb_control_message(ehci, fd, (USB_CTRLTYPE_DIR_HOST2DEVICE | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_INTERFACE), USB_REQ_SETINTERFACE, alternateSetting, interface, 0, NULL, NULL, NULL); }
s32 USB_GetDeviceDescription(s32 fd,usb_devdesc *devdesc) { s32 ret; usb_devdesc *p; p = iosAlloc(hId,USB_DT_DEVICE_SIZE); if(p==NULL) return IPC_ENOMEM; ret = __usb_control_message(fd,USB_ENDPOINT_IN,USB_REQ_GETDESCRIPTOR,(USB_DT_DEVICE<<8),0,USB_DT_DEVICE_SIZE,p,NULL,NULL); if(ret>=0) memcpy(devdesc,p,USB_DT_DEVICE_SIZE); devdesc->configurations = NULL; if(p!=NULL) iosFree(hId,p); return ret; }
s32 USB_GetConfiguration(struct ehci_hcd * ehci,struct ehci_device *fd, u8 *configuration) { u8 *_configuration; s32 retval; _configuration = USB_Alloc( 1); if(_configuration == NULL) return -ENOMEM; retval = __usb_control_message(ehci, fd, (USB_CTRLTYPE_DIR_DEVICE2HOST | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_DEVICE), USB_REQ_GETCONFIG, 0, 0, 1, _configuration, NULL, NULL); if(retval >= 0) *configuration = *_configuration; USB_Free( _configuration); return retval; }
s32 USB_GetConfiguration(s32 fd, u8 *configuration) { u8 *_configuration; s32 retval; _configuration = iosAlloc(hId, 1); if(_configuration == NULL) return IPC_ENOMEM; retval = __usb_control_message(fd, (USB_CTRLTYPE_DIR_DEVICE2HOST | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_DEVICE), USB_REQ_GETCONFIG, 0, 0, 1, _configuration, NULL, NULL); if(retval >= 0) *configuration = *_configuration; iosFree(hId, _configuration); return retval; }
s32 USB_GetAsciiString(s32 fd,u16 wIndex,u16 wLangID,u16 wLength,void *rpData) { s32 ret; u8 bo, ro; u8 *buf; u8 *rp = (u8 *)rpData; if(wLength > 255) wLength = 255; buf = iosAlloc(hId, 255); /* 255 is the highest possible length of a descriptor */ if(buf == NULL) return IPC_ENOMEM; ret = __usb_control_message(fd, USB_ENDPOINT_IN, USB_REQ_GETDESCRIPTOR, ((USB_DT_STRING << 8) + wIndex), wLangID, 255, buf, NULL, NULL); /* index 0 gets a list of supported languages */ if(wIndex == 0) { if(ret > 0) memcpy(rpData, buf, wLength); iosFree(hId, buf); return ret; } if(ret > 0) { bo = 2; ro = 0; while(ro < (wLength - 1) && bo < buf[0]) { if(buf[bo + 1]) rp[ro++] = '?'; else rp[ro++] = buf[bo]; bo += 2; } rp[ro] = 0; ret = ro - 1; } iosFree(hId, buf); return ret; }
static s32 __usb_getdesc(struct ehci_hcd * ehci,struct ehci_device * fd, u8 *buffer, u8 type, u8 index, u8 size) { printk("usb_get desc %X %X %p\n",type,index,buffer); return __usb_control_message(ehci,fd, USB_ENDPOINT_IN ,USB_REQ_GETDESCRIPTOR, (type << 8) | index, 0, size, buffer, NULL, NULL); }
s32 USB_ClearHalt(struct ehci_hcd * ehci,struct ehci_device *fd, u8 endpoint) { return __usb_control_message(ehci, 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); }
s32 USB_SetConfiguration(struct ehci_hcd * ehci,struct ehci_device *fd, u8 configuration) { return __usb_control_message(ehci, fd, (USB_CTRLTYPE_DIR_HOST2DEVICE | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_DEVICE), USB_REQ_SETCONFIG, configuration, 0, 0, NULL, NULL, NULL); }
s32 USB_WriteCtrlMsg(struct ehci_hcd * ehci,struct ehci_device *fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData) { return __usb_control_message(ehci, fd,bmRequestType,bmRequest,wValue,wIndex,wLength,rpData,NULL,NULL); }
s32 USB_SetAlternativeInterface(s32 fd, u8 interface, u8 alternateSetting) { if(alternateSetting == 0) return IPC_EINVAL; 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); }
s32 USB_SetConfiguration(s32 fd, u8 configuration) { return __usb_control_message(fd, (USB_CTRLTYPE_DIR_HOST2DEVICE | USB_CTRLTYPE_TYPE_STANDARD | USB_CTRLTYPE_REC_DEVICE), USB_REQ_SETCONFIG, configuration, 0, 0, NULL, NULL, NULL); }
s32 USB_WriteCtrlMsgAsync(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData,usbcallback cb,void *usrdata) { return __usb_control_message(fd,bmRequestType,bmRequest,wValue,wIndex,wLength,rpData,cb,usrdata); }
s32 USB_WriteCtrlMsg(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData) { return __usb_control_message(fd,bmRequestType,bmRequest,wValue,wIndex,wLength,rpData,NULL,NULL); }
static inline s32 __usb_getdesc(s32 fd, u8 *buffer, u8 type, u8 index, u8 size) { return __usb_control_message(fd, USB_ENDPOINT_IN ,USB_REQ_GETDESCRIPTOR, (type << 8) | index, 0, size, buffer, NULL, NULL); }