1#!/bin/env python3 2# SPDX-License-Identifier: GPL-2.0 3# -*- coding: utf-8 -*- 4# 5# Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com> 6# Copyright (c) 2017 Red Hat, Inc. 7# 8# This program is free software: you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program. If not, see <http://www.gnu.org/licenses/>. 20# 21 22# This is for generic devices 23 24from . import base 25import logging 26 27logger = logging.getLogger("hidtools.test.hid") 28 29 30class TestCollectionOverflow(base.BaseTestCase.TestUhid): 31 """ 32 Test class to test re-allocation of the HID collection stack in 33 hid-core.c. 34 """ 35 36 def create_device(self): 37 # fmt: off 38 report_descriptor = [ 39 0x05, 0x01, # .Usage Page (Generic Desktop) 40 0x09, 0x02, # .Usage (Mouse) 41 0xa1, 0x01, # .Collection (Application) 42 0x09, 0x02, # ..Usage (Mouse) 43 0xa1, 0x02, # ..Collection (Logical) 44 0x09, 0x01, # ...Usage (Pointer) 45 0xa1, 0x00, # ...Collection (Physical) 46 0x05, 0x09, # ....Usage Page (Button) 47 0x19, 0x01, # ....Usage Minimum (1) 48 0x29, 0x03, # ....Usage Maximum (3) 49 0x15, 0x00, # ....Logical Minimum (0) 50 0x25, 0x01, # ....Logical Maximum (1) 51 0x75, 0x01, # ....Report Size (1) 52 0x95, 0x03, # ....Report Count (3) 53 0x81, 0x02, # ....Input (Data,Var,Abs) 54 0x75, 0x05, # ....Report Size (5) 55 0x95, 0x01, # ....Report Count (1) 56 0x81, 0x03, # ....Input (Cnst,Var,Abs) 57 0xa1, 0x02, # ....Collection (Logical) 58 0x09, 0x01, # .....Usage (Pointer) 59 0xa1, 0x02, # ....Collection (Logical) 60 0x09, 0x01, # .....Usage (Pointer) 61 0xa1, 0x02, # ....Collection (Logical) 62 0x09, 0x01, # .....Usage (Pointer) 63 0xa1, 0x02, # ....Collection (Logical) 64 0x09, 0x01, # .....Usage (Pointer) 65 0xa1, 0x02, # ....Collection (Logical) 66 0x09, 0x01, # .....Usage (Pointer) 67 0xa1, 0x02, # ....Collection (Logical) 68 0x09, 0x01, # .....Usage (Pointer) 69 0xa1, 0x02, # ....Collection (Logical) 70 0x09, 0x01, # .....Usage (Pointer) 71 0xa1, 0x02, # ....Collection (Logical) 72 0x09, 0x01, # .....Usage (Pointer) 73 0xa1, 0x02, # ....Collection (Logical) 74 0x09, 0x01, # .....Usage (Pointer) 75 0xa1, 0x02, # ....Collection (Logical) 76 0x09, 0x01, # .....Usage (Pointer) 77 0xa1, 0x02, # ....Collection (Logical) 78 0x09, 0x01, # .....Usage (Pointer) 79 0xa1, 0x02, # ....Collection (Logical) 80 0x09, 0x01, # .....Usage (Pointer) 81 0xa1, 0x02, # ....Collection (Logical) 82 0x09, 0x01, # .....Usage (Pointer) 83 0xa1, 0x02, # ....Collection (Logical) 84 0x09, 0x01, # .....Usage (Pointer) 85 0xa1, 0x02, # ....Collection (Logical) 86 0x09, 0x01, # .....Usage (Pointer) 87 0xa1, 0x02, # ....Collection (Logical) 88 0x09, 0x01, # .....Usage (Pointer) 89 0xa1, 0x02, # ....Collection (Logical) 90 0x09, 0x01, # .....Usage (Pointer) 91 0x05, 0x01, # .....Usage Page (Generic Desktop) 92 0x09, 0x30, # .....Usage (X) 93 0x09, 0x31, # .....Usage (Y) 94 0x15, 0x81, # .....Logical Minimum (-127) 95 0x25, 0x7f, # .....Logical Maximum (127) 96 0x75, 0x08, # .....Report Size (8) 97 0x95, 0x02, # .....Report Count (2) 98 0x81, 0x06, # .....Input (Data,Var,Rel) 99 0xa1, 0x02, # ...Collection (Logical) 100 0x85, 0x12, # ....Report ID (18) 101 0x09, 0x48, # ....Usage (Resolution Multiplier) 102 0x95, 0x01, # ....Report Count (1) 103 0x75, 0x02, # ....Report Size (2) 104 0x15, 0x00, # ....Logical Minimum (0) 105 0x25, 0x01, # ....Logical Maximum (1) 106 0x35, 0x01, # ....Physical Minimum (1) 107 0x45, 0x0c, # ....Physical Maximum (12) 108 0xb1, 0x02, # ....Feature (Data,Var,Abs) 109 0x85, 0x1a, # ....Report ID (26) 110 0x09, 0x38, # ....Usage (Wheel) 111 0x35, 0x00, # ....Physical Minimum (0) 112 0x45, 0x00, # ....Physical Maximum (0) 113 0x95, 0x01, # ....Report Count (1) 114 0x75, 0x10, # ....Report Size (16) 115 0x16, 0x01, 0x80, # ....Logical Minimum (-32767) 116 0x26, 0xff, 0x7f, # ....Logical Maximum (32767) 117 0x81, 0x06, # ....Input (Data,Var,Rel) 118 0xc0, # ...End Collection 119 0xc0, # ...End Collection 120 0xc0, # ...End Collection 121 0xc0, # ...End Collection 122 0xc0, # ...End Collection 123 0xc0, # ...End Collection 124 0xc0, # ...End Collection 125 0xc0, # ...End Collection 126 0xc0, # ...End Collection 127 0xc0, # ...End Collection 128 0xc0, # ...End Collection 129 0xc0, # ...End Collection 130 0xc0, # ...End Collection 131 0xc0, # ...End Collection 132 0xc0, # ...End Collection 133 0xc0, # ...End Collection 134 0xc0, # ...End Collection 135 0xc0, # ...End Collection 136 0xc0, # ...End Collection 137 0xc0, # ..End Collection 138 0xc0, # .End Collection 139 ] 140 # fmt: on 141 return base.UHIDTestDevice( 142 name=None, rdesc=report_descriptor, application="Mouse" 143 ) 144 145 def test_rdesc(self): 146 """ 147 This test can only check for negatives. If the kernel crashes, you 148 know why. If this test passes, either the bug isn't present or just 149 didn't get triggered. No way to know. 150 151 For an explanation, see kernel patch 152 HID: core: replace the collection tree pointers with indices 153 """ 154 pass 155