Skip to content

Commit

Permalink
Add support for the Xbox One S controller over Bluetooth
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Loup A. Griffais authored and johnv-valve committed Jun 8, 2017
1 parent 198990f commit 549c3dc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/hid/hid-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_3K) },
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_XBOX_ONE_S) },
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_OFFICE_KB) },
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_7K) },
{ HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_DIGITAL_MEDIA_600) },
Expand Down
2 changes: 2 additions & 0 deletions drivers/hid/hid-ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@
#define USB_DEVICE_ID_MS_TOUCH_COVER_2 0x07a7
#define USB_DEVICE_ID_MS_TYPE_COVER_2 0x07a9
#define USB_DEVICE_ID_MS_POWER_COVER 0x07da
#define USB_DEVICE_ID_MS_XBOX_ONE_S 0x02e0


#define USB_VENDOR_ID_MOJO 0x8282
#define USB_DEVICE_ID_RETRO_ADAPTER 0x3201
Expand Down
38 changes: 38 additions & 0 deletions drivers/hid/hid-microsoft.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define MS_RDESC 0x08
#define MS_NOGET 0x10
#define MS_DUPLICATE_USAGES 0x20
#define MS_RDESC_3K 0x40
#define MS_XBOX_ONE_S 0x80

static __u8 *ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
Expand Down Expand Up @@ -130,11 +132,43 @@ static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
return 1;
}

static int ms_xbox_one_s_quirk(struct hid_input *hi, struct hid_usage *usage,
unsigned long **bit, int *max)
{
switch (usage->hid & HID_USAGE_PAGE) {

case HID_UP_GENDESK:
if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
switch (usage->hid & 0xf) {
case 0x5:
/* override the default mapping of KEY_MENU */
ms_map_key_clear(BTN_MODE);
return 1;
default:
break;
}
break;
}
break;

default:
break;
}

/* Let the normal mapping happen for everything else */
return 0;
}

static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
{
unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);

if (quirks & MS_XBOX_ONE_S) {
int ret = ms_xbox_one_s_quirk(hi, usage, bit, max);
return ret;
}

if (quirks & MS_ERGONOMY) {
int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
Expand Down Expand Up @@ -281,6 +315,10 @@ static const struct hid_device_id ms_devices[] = {

{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
.driver_data = MS_PRESENTER },

{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_XBOX_ONE_S),
.driver_data = MS_XBOX_ONE_S },

{ }
};
MODULE_DEVICE_TABLE(hid, ms_devices);
Expand Down
9 changes: 9 additions & 0 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3214,6 +3214,14 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)

switch (chan->mode) {
case L2CAP_MODE_BASIC:
/* HACK FOR XBOX ONE S CONTROLLERS
* If we add options to the configuration request, the
* Xbox One S controller responds with:
* Result: Failure - unknown options (0x0003)
* For now, just don't send configuration options.
* Remove this hack once the controller supports it
*/
#if 0
if (disable_ertm)
break;

Expand All @@ -3230,6 +3238,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)

l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
(unsigned long) &rfc);
#endif
break;

case L2CAP_MODE_ERTM:
Expand Down

2 comments on commit 549c3dc

@Hellzed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Do you plan to get this patch upstream ? That would be super helpful for other distributions that don't support this controller yet.
Would it have any adverse effect on Android devices relying on that "back" HID event ?

@fledermaus
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi - doing a (belated) sweep of stuff not upstreamed yet.
This one will be submitted soon, I think. Not sure about android devices
(I guess that's one of the things that will come up).

Please sign in to comment.