We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 600

Summary: Some USB joysticks with multiple reports won't work on FreeBSD
Product: SDL Reporter: Dmitry Marakasov <amdmi3>
Component: joystickAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 1.2.13   
Hardware: x86   
OS: FreeBSD   

Description Dmitry Marakasov 2008-06-23 12:44:33 UTC
I have `Microsoft SideWinder Force Feedback 2 Joystick' joystick, and it doesn't work with SDL. To descript the cause, here's report of my custom utility based on libusbhid which is used by SDL on FreeBSD as well:

===> Initializing libusbhid...
===> Opening device...
===> Getting report descriptor...
===> USB_GET_REPORT_ID...
Ioctl returned 0, value = 0
===> Getting report sizes...
Input [0]: 0
Input [1]: 15
Input [-1]: 0
===> Parsing report descriptor...
collection {
  collection { // Axes X, Y, Rz
    Input, reportid=1, size=10, pos=0, page 0x1, usage 0x30
    Input, reportid=1, size=6, pos=10 (null)
    Input, reportid=1, size=10, pos=16, page 0x1, usage 0x31
    Input, reportid=1, size=6, pos=26 (null)
    Input, reportid=1, size=6, pos=32, page 0x1, usage 0x35
    Input, reportid=1, size=2, pos=38 (null)
  } // collection
  // Slider, HAT switch
  Input, reportid=1, size=7, pos=40, page 0x1, usage 0x36
  Input, reportid=1, size=1, pos=47 (null)
  Input, reportid=1, size=4, pos=48, page 0x1, usage 0x39
  Input, reportid=1, size=4, pos=52 (null)
  // Buttons
  Input, reportid=1, size=1, pos=56, page 0x9, usage 0x1
  Input, reportid=1, size=1, pos=57, page 0x9, usage 0x2
  Input, reportid=1, size=1, pos=58, page 0x9, usage 0x3
  Input, reportid=1, size=1, pos=59, page 0x9, usage 0x4
  Input, reportid=1, size=1, pos=60, page 0x9, usage 0x5
  Input, reportid=1, size=1, pos=61, page 0x9, usage 0x6
  Input, reportid=1, size=1, pos=62, page 0x9, usage 0x7
  Input, reportid=1, size=1, pos=63, page 0x9, usage 0x8
  Input, reportid=1, size=8, pos=64 (null)
  collection { // Another report with data on actuators and FF state
    Input, reportid=2, size=1, pos=0, page 0xf, usage 0x9f
    Input, reportid=2, size=1, pos=1, page 0xf, usage 0xa0
    Input, reportid=2, size=1, pos=2, page 0xf, usage 0xa4
    Input, reportid=2, size=1, pos=3, page 0xf, usage 0xa5
    Input, reportid=2, size=1, pos=4, page 0xf, usage 0xa6
    Input, reportid=2, size=1, pos=5 (null)
    Input, reportid=2, size=1, pos=6 (null)
    Input, reportid=2, size=1, pos=7 (null)
    Input, reportid=2, size=1, pos=8, page 0xf, usage 0x94
    Input, reportid=2, size=7, pos=9, page 0xf, usage 0x22
  } // collection
[some more report descriptor stuff]

So, as you can see, actual axes and buttons are accessible via report id 1, but SDL will use report id 0, which it got from USB_GET_REPORT_ID ioctl (joystick/bsd/SDL_sysjoystick.c:301), so SDL_SYS_JoystickOpen will fail (joystick/bsd/SDL_sysjoystick.c:310) -> joystick won't be recognized.

To fix this, ioctl should not be used. Instead, report descriptor should be parsed first to determine report ID for report that contains needed items (axes, buttons, etc), and report allocation should only be done after that.

Actually I plan to work on improving joystick support on FreeBSD (starting with implementing it from scratch in OIS (wgois.sf.net), then fixing SDL and possibly also plib), so later I may provide patch for this myself, but I feel like the bug should be reported anyway.
Comment 1 Sam Lantinga 2009-09-21 01:50:35 UTC
Go ahead and submit a bug report with patch for SDL 1.3, which is in active development.
http://www.libsdl.org/tmp/SDL-1.3.zip

Thanks!