Recommendations for programming HID in FreeBSD 9
Hans Petter Selasky
hselasky at c2i.net
Fri Jun 1 16:29:21 UTC 2012
On Friday 01 June 2012 18:12:20 Engineering wrote:
> From: Hans Petter Selasky [mailto:hselasky at c2i.net]
>
> >> uhid is not going to get obsoleted, though using libraries from
>
> user-space is sometimes more convenient.
>
> Thanks HPS (and Xiaofan)
>
> I definitely agree with that, but I've got legacy code...
>
> Last question - I've updated my code to convert the old 'usb_ctl_report'
> and such to the new generic descriptors at runtime, and I've got two HIDs
> up and running.
>
> As I read uhid.c, it seems to assume only one feature report ID and size. I
> have devices that have multiple feature report sizes. And one device which
> I'm pretty sure has bad device descriptors, so the size is wrong.
>
> In the BSD7, I added the following fakery to uhid.c:
>
> case USB_SET_REPORTZ: // report id and size are in first two bytes
> re = (struct usb_ctl_report *)addr;
> id = re->ucr_data[0];
> size = re->ucr_data[1];
> err = usbd_set_report(sc->sc_iface, re->ucr_report, id,
> &re->ucr_data[2],size);
> if (err)
> {
> return (EIO);
> }
> break;
>
> Do you think it would make sense to do this again with the BSD9 uhid.c?
I think mav @ did some work in that area?
Are you sure you cannot use:
case USB_SET_REPORT:
if (!(fflags & FWRITE)) {
error = EPERM;
break;
}
ugd = addr;
switch (ugd->ugd_report_type) {
case UHID_INPUT_REPORT:
size = sc->sc_isize;
id = sc->sc_iid;
break;
case UHID_OUTPUT_REPORT:
size = sc->sc_osize;
id = sc->sc_oid;
break;
case UHID_FEATURE_REPORT:
size = sc->sc_fsize;
id = sc->sc_fid;
break;
default:
return (EINVAL);
}
if (id != 0)
copyin(ugd->ugd_data, &id, 1);
error = uhid_set_report(sc, ugd->ugd_report_type, id,
NULL, ugd->ugd_data, imin(ugd->ugd_maxlen, size));
break;
--HPS
More information about the freebsd-usb
mailing list