1 /* 2 * (c) 1999 Andreas Gal <gal@cs.uni-magdeburg.de> 3 * (c) 2000-2001 Vojtech Pavlik <vojtech@ucw.cz> 4 * (c) 2007-2009 Jiri Kosina 5 * 6 * HID debugging support 7 */ 8 9 /* 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * 24 * Should you need to contact me, the author, you can do so either by 25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 27 */ 28 29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30 31 #include <linux/debugfs.h> 32 #include <linux/seq_file.h> 33 #include <linux/sched.h> 34 #include <linux/export.h> 35 #include <linux/slab.h> 36 #include <linux/uaccess.h> 37 #include <linux/poll.h> 38 39 #include <linux/hid.h> 40 #include <linux/hid-debug.h> 41 42 static struct dentry *hid_debug_root; 43 44 struct hid_usage_entry { 45 unsigned page; 46 unsigned usage; 47 const char *description; 48 }; 49 50 static const struct hid_usage_entry hid_usage_table[] = { 51 { 0, 0, "Undefined" }, 52 { 1, 0, "GenericDesktop" }, 53 {0, 0x01, "Pointer"}, 54 {0, 0x02, "Mouse"}, 55 {0, 0x04, "Joystick"}, 56 {0, 0x05, "GamePad"}, 57 {0, 0x06, "Keyboard"}, 58 {0, 0x07, "Keypad"}, 59 {0, 0x08, "MultiAxis"}, 60 {0, 0x30, "X"}, 61 {0, 0x31, "Y"}, 62 {0, 0x32, "Z"}, 63 {0, 0x33, "Rx"}, 64 {0, 0x34, "Ry"}, 65 {0, 0x35, "Rz"}, 66 {0, 0x36, "Slider"}, 67 {0, 0x37, "Dial"}, 68 {0, 0x38, "Wheel"}, 69 {0, 0x39, "HatSwitch"}, 70 {0, 0x3a, "CountedBuffer"}, 71 {0, 0x3b, "ByteCount"}, 72 {0, 0x3c, "MotionWakeup"}, 73 {0, 0x3d, "Start"}, 74 {0, 0x3e, "Select"}, 75 {0, 0x40, "Vx"}, 76 {0, 0x41, "Vy"}, 77 {0, 0x42, "Vz"}, 78 {0, 0x43, "Vbrx"}, 79 {0, 0x44, "Vbry"}, 80 {0, 0x45, "Vbrz"}, 81 {0, 0x46, "Vno"}, 82 {0, 0x80, "SystemControl"}, 83 {0, 0x81, "SystemPowerDown"}, 84 {0, 0x82, "SystemSleep"}, 85 {0, 0x83, "SystemWakeUp"}, 86 {0, 0x84, "SystemContextMenu"}, 87 {0, 0x85, "SystemMainMenu"}, 88 {0, 0x86, "SystemAppMenu"}, 89 {0, 0x87, "SystemMenuHelp"}, 90 {0, 0x88, "SystemMenuExit"}, 91 {0, 0x89, "SystemMenuSelect"}, 92 {0, 0x8a, "SystemMenuRight"}, 93 {0, 0x8b, "SystemMenuLeft"}, 94 {0, 0x8c, "SystemMenuUp"}, 95 {0, 0x8d, "SystemMenuDown"}, 96 {0, 0x90, "D-PadUp"}, 97 {0, 0x91, "D-PadDown"}, 98 {0, 0x92, "D-PadRight"}, 99 {0, 0x93, "D-PadLeft"}, 100 { 2, 0, "Simulation" }, 101 {0, 0xb0, "Aileron"}, 102 {0, 0xb1, "AileronTrim"}, 103 {0, 0xb2, "Anti-Torque"}, 104 {0, 0xb3, "Autopilot"}, 105 {0, 0xb4, "Chaff"}, 106 {0, 0xb5, "Collective"}, 107 {0, 0xb6, "DiveBrake"}, 108 {0, 0xb7, "ElectronicCountermeasures"}, 109 {0, 0xb8, "Elevator"}, 110 {0, 0xb9, "ElevatorTrim"}, 111 {0, 0xba, "Rudder"}, 112 {0, 0xbb, "Throttle"}, 113 {0, 0xbc, "FlightCommunications"}, 114 {0, 0xbd, "FlareRelease"}, 115 {0, 0xbe, "LandingGear"}, 116 {0, 0xbf, "ToeBrake"}, 117 { 6, 0, "GenericDeviceControls" }, 118 {0, 0x20, "BatteryStrength" }, 119 {0, 0x21, "WirelessChannel" }, 120 {0, 0x22, "WirelessID" }, 121 {0, 0x23, "DiscoverWirelessControl" }, 122 {0, 0x24, "SecurityCodeCharacterEntered" }, 123 {0, 0x25, "SecurityCodeCharactedErased" }, 124 {0, 0x26, "SecurityCodeCleared" }, 125 { 7, 0, "Keyboard" }, 126 { 8, 0, "LED" }, 127 {0, 0x01, "NumLock"}, 128 {0, 0x02, "CapsLock"}, 129 {0, 0x03, "ScrollLock"}, 130 {0, 0x04, "Compose"}, 131 {0, 0x05, "Kana"}, 132 {0, 0x4b, "GenericIndicator"}, 133 { 9, 0, "Button" }, 134 { 10, 0, "Ordinal" }, 135 { 12, 0, "Consumer" }, 136 {0, 0x238, "HorizontalWheel"}, 137 { 13, 0, "Digitizers" }, 138 {0, 0x01, "Digitizer"}, 139 {0, 0x02, "Pen"}, 140 {0, 0x03, "LightPen"}, 141 {0, 0x04, "TouchScreen"}, 142 {0, 0x05, "TouchPad"}, 143 {0, 0x20, "Stylus"}, 144 {0, 0x21, "Puck"}, 145 {0, 0x22, "Finger"}, 146 {0, 0x30, "TipPressure"}, 147 {0, 0x31, "BarrelPressure"}, 148 {0, 0x32, "InRange"}, 149 {0, 0x33, "Touch"}, 150 {0, 0x34, "UnTouch"}, 151 {0, 0x35, "Tap"}, 152 {0, 0x39, "TabletFunctionKey"}, 153 {0, 0x3a, "ProgramChangeKey"}, 154 {0, 0x3c, "Invert"}, 155 {0, 0x42, "TipSwitch"}, 156 {0, 0x43, "SecondaryTipSwitch"}, 157 {0, 0x44, "BarrelSwitch"}, 158 {0, 0x45, "Eraser"}, 159 {0, 0x46, "TabletPick"}, 160 {0, 0x47, "Confidence"}, 161 {0, 0x48, "Width"}, 162 {0, 0x49, "Height"}, 163 {0, 0x51, "ContactID"}, 164 {0, 0x52, "InputMode"}, 165 {0, 0x53, "DeviceIndex"}, 166 {0, 0x54, "ContactCount"}, 167 {0, 0x55, "ContactMaximumNumber"}, 168 { 15, 0, "PhysicalInterfaceDevice" }, 169 {0, 0x00, "Undefined"}, 170 {0, 0x01, "Physical_Interface_Device"}, 171 {0, 0x20, "Normal"}, 172 {0, 0x21, "Set_Effect_Report"}, 173 {0, 0x22, "Effect_Block_Index"}, 174 {0, 0x23, "Parameter_Block_Offset"}, 175 {0, 0x24, "ROM_Flag"}, 176 {0, 0x25, "Effect_Type"}, 177 {0, 0x26, "ET_Constant_Force"}, 178 {0, 0x27, "ET_Ramp"}, 179 {0, 0x28, "ET_Custom_Force_Data"}, 180 {0, 0x30, "ET_Square"}, 181 {0, 0x31, "ET_Sine"}, 182 {0, 0x32, "ET_Triangle"}, 183 {0, 0x33, "ET_Sawtooth_Up"}, 184 {0, 0x34, "ET_Sawtooth_Down"}, 185 {0, 0x40, "ET_Spring"}, 186 {0, 0x41, "ET_Damper"}, 187 {0, 0x42, "ET_Inertia"}, 188 {0, 0x43, "ET_Friction"}, 189 {0, 0x50, "Duration"}, 190 {0, 0x51, "Sample_Period"}, 191 {0, 0x52, "Gain"}, 192 {0, 0x53, "Trigger_Button"}, 193 {0, 0x54, "Trigger_Repeat_Interval"}, 194 {0, 0x55, "Axes_Enable"}, 195 {0, 0x56, "Direction_Enable"}, 196 {0, 0x57, "Direction"}, 197 {0, 0x58, "Type_Specific_Block_Offset"}, 198 {0, 0x59, "Block_Type"}, 199 {0, 0x5A, "Set_Envelope_Report"}, 200 {0, 0x5B, "Attack_Level"}, 201 {0, 0x5C, "Attack_Time"}, 202 {0, 0x5D, "Fade_Level"}, 203 {0, 0x5E, "Fade_Time"}, 204 {0, 0x5F, "Set_Condition_Report"}, 205 {0, 0x60, "CP_Offset"}, 206 {0, 0x61, "Positive_Coefficient"}, 207 {0, 0x62, "Negative_Coefficient"}, 208 {0, 0x63, "Positive_Saturation"}, 209 {0, 0x64, "Negative_Saturation"}, 210 {0, 0x65, "Dead_Band"}, 211 {0, 0x66, "Download_Force_Sample"}, 212 {0, 0x67, "Isoch_Custom_Force_Enable"}, 213 {0, 0x68, "Custom_Force_Data_Report"}, 214 {0, 0x69, "Custom_Force_Data"}, 215 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"}, 216 {0, 0x6B, "Set_Custom_Force_Report"}, 217 {0, 0x6C, "Custom_Force_Data_Offset"}, 218 {0, 0x6D, "Sample_Count"}, 219 {0, 0x6E, "Set_Periodic_Report"}, 220 {0, 0x6F, "Offset"}, 221 {0, 0x70, "Magnitude"}, 222 {0, 0x71, "Phase"}, 223 {0, 0x72, "Period"}, 224 {0, 0x73, "Set_Constant_Force_Report"}, 225 {0, 0x74, "Set_Ramp_Force_Report"}, 226 {0, 0x75, "Ramp_Start"}, 227 {0, 0x76, "Ramp_End"}, 228 {0, 0x77, "Effect_Operation_Report"}, 229 {0, 0x78, "Effect_Operation"}, 230 {0, 0x79, "Op_Effect_Start"}, 231 {0, 0x7A, "Op_Effect_Start_Solo"}, 232 {0, 0x7B, "Op_Effect_Stop"}, 233 {0, 0x7C, "Loop_Count"}, 234 {0, 0x7D, "Device_Gain_Report"}, 235 {0, 0x7E, "Device_Gain"}, 236 {0, 0x7F, "PID_Pool_Report"}, 237 {0, 0x80, "RAM_Pool_Size"}, 238 {0, 0x81, "ROM_Pool_Size"}, 239 {0, 0x82, "ROM_Effect_Block_Count"}, 240 {0, 0x83, "Simultaneous_Effects_Max"}, 241 {0, 0x84, "Pool_Alignment"}, 242 {0, 0x85, "PID_Pool_Move_Report"}, 243 {0, 0x86, "Move_Source"}, 244 {0, 0x87, "Move_Destination"}, 245 {0, 0x88, "Move_Length"}, 246 {0, 0x89, "PID_Block_Load_Report"}, 247 {0, 0x8B, "Block_Load_Status"}, 248 {0, 0x8C, "Block_Load_Success"}, 249 {0, 0x8D, "Block_Load_Full"}, 250 {0, 0x8E, "Block_Load_Error"}, 251 {0, 0x8F, "Block_Handle"}, 252 {0, 0x90, "PID_Block_Free_Report"}, 253 {0, 0x91, "Type_Specific_Block_Handle"}, 254 {0, 0x92, "PID_State_Report"}, 255 {0, 0x94, "Effect_Playing"}, 256 {0, 0x95, "PID_Device_Control_Report"}, 257 {0, 0x96, "PID_Device_Control"}, 258 {0, 0x97, "DC_Enable_Actuators"}, 259 {0, 0x98, "DC_Disable_Actuators"}, 260 {0, 0x99, "DC_Stop_All_Effects"}, 261 {0, 0x9A, "DC_Device_Reset"}, 262 {0, 0x9B, "DC_Device_Pause"}, 263 {0, 0x9C, "DC_Device_Continue"}, 264 {0, 0x9F, "Device_Paused"}, 265 {0, 0xA0, "Actuators_Enabled"}, 266 {0, 0xA4, "Safety_Switch"}, 267 {0, 0xA5, "Actuator_Override_Switch"}, 268 {0, 0xA6, "Actuator_Power"}, 269 {0, 0xA7, "Start_Delay"}, 270 {0, 0xA8, "Parameter_Block_Size"}, 271 {0, 0xA9, "Device_Managed_Pool"}, 272 {0, 0xAA, "Shared_Parameter_Blocks"}, 273 {0, 0xAB, "Create_New_Effect_Report"}, 274 {0, 0xAC, "RAM_Pool_Available"}, 275 { 0x84, 0, "Power Device" }, 276 { 0x84, 0x02, "PresentStatus" }, 277 { 0x84, 0x03, "ChangeStatus" }, 278 { 0x84, 0x04, "UPS" }, 279 { 0x84, 0x05, "PowerSupply" }, 280 { 0x84, 0x10, "BatterySystem" }, 281 { 0x84, 0x11, "BatterySystemID" }, 282 { 0x84, 0x12, "Battery" }, 283 { 0x84, 0x13, "BatteryID" }, 284 { 0x84, 0x14, "Charger" }, 285 { 0x84, 0x15, "ChargerID" }, 286 { 0x84, 0x16, "PowerConverter" }, 287 { 0x84, 0x17, "PowerConverterID" }, 288 { 0x84, 0x18, "OutletSystem" }, 289 { 0x84, 0x19, "OutletSystemID" }, 290 { 0x84, 0x1a, "Input" }, 291 { 0x84, 0x1b, "InputID" }, 292 { 0x84, 0x1c, "Output" }, 293 { 0x84, 0x1d, "OutputID" }, 294 { 0x84, 0x1e, "Flow" }, 295 { 0x84, 0x1f, "FlowID" }, 296 { 0x84, 0x20, "Outlet" }, 297 { 0x84, 0x21, "OutletID" }, 298 { 0x84, 0x22, "Gang" }, 299 { 0x84, 0x24, "PowerSummary" }, 300 { 0x84, 0x25, "PowerSummaryID" }, 301 { 0x84, 0x30, "Voltage" }, 302 { 0x84, 0x31, "Current" }, 303 { 0x84, 0x32, "Frequency" }, 304 { 0x84, 0x33, "ApparentPower" }, 305 { 0x84, 0x35, "PercentLoad" }, 306 { 0x84, 0x40, "ConfigVoltage" }, 307 { 0x84, 0x41, "ConfigCurrent" }, 308 { 0x84, 0x43, "ConfigApparentPower" }, 309 { 0x84, 0x53, "LowVoltageTransfer" }, 310 { 0x84, 0x54, "HighVoltageTransfer" }, 311 { 0x84, 0x56, "DelayBeforeStartup" }, 312 { 0x84, 0x57, "DelayBeforeShutdown" }, 313 { 0x84, 0x58, "Test" }, 314 { 0x84, 0x5a, "AudibleAlarmControl" }, 315 { 0x84, 0x60, "Present" }, 316 { 0x84, 0x61, "Good" }, 317 { 0x84, 0x62, "InternalFailure" }, 318 { 0x84, 0x65, "Overload" }, 319 { 0x84, 0x66, "OverCharged" }, 320 { 0x84, 0x67, "OverTemperature" }, 321 { 0x84, 0x68, "ShutdownRequested" }, 322 { 0x84, 0x69, "ShutdownImminent" }, 323 { 0x84, 0x6b, "SwitchOn/Off" }, 324 { 0x84, 0x6c, "Switchable" }, 325 { 0x84, 0x6d, "Used" }, 326 { 0x84, 0x6e, "Boost" }, 327 { 0x84, 0x73, "CommunicationLost" }, 328 { 0x84, 0xfd, "iManufacturer" }, 329 { 0x84, 0xfe, "iProduct" }, 330 { 0x84, 0xff, "iSerialNumber" }, 331 { 0x85, 0, "Battery System" }, 332 { 0x85, 0x01, "SMBBatteryMode" }, 333 { 0x85, 0x02, "SMBBatteryStatus" }, 334 { 0x85, 0x03, "SMBAlarmWarning" }, 335 { 0x85, 0x04, "SMBChargerMode" }, 336 { 0x85, 0x05, "SMBChargerStatus" }, 337 { 0x85, 0x06, "SMBChargerSpecInfo" }, 338 { 0x85, 0x07, "SMBSelectorState" }, 339 { 0x85, 0x08, "SMBSelectorPresets" }, 340 { 0x85, 0x09, "SMBSelectorInfo" }, 341 { 0x85, 0x29, "RemainingCapacityLimit" }, 342 { 0x85, 0x2c, "CapacityMode" }, 343 { 0x85, 0x42, "BelowRemainingCapacityLimit" }, 344 { 0x85, 0x44, "Charging" }, 345 { 0x85, 0x45, "Discharging" }, 346 { 0x85, 0x4b, "NeedReplacement" }, 347 { 0x85, 0x66, "RemainingCapacity" }, 348 { 0x85, 0x68, "RunTimeToEmpty" }, 349 { 0x85, 0x6a, "AverageTimeToFull" }, 350 { 0x85, 0x83, "DesignCapacity" }, 351 { 0x85, 0x85, "ManufacturerDate" }, 352 { 0x85, 0x89, "iDeviceChemistry" }, 353 { 0x85, 0x8b, "Rechargeable" }, 354 { 0x85, 0x8f, "iOEMInformation" }, 355 { 0x85, 0x8d, "CapacityGranularity1" }, 356 { 0x85, 0xd0, "ACPresent" }, 357 /* pages 0xff00 to 0xffff are vendor-specific */ 358 { 0xffff, 0, "Vendor-specific-FF" }, 359 { 0, 0, NULL } 360 }; 361 362 /* Either output directly into simple seq_file, or (if f == NULL) 363 * allocate a separate buffer that will then be passed to the 'events' 364 * ringbuffer. 365 * 366 * This is because these functions can be called both for "one-shot" 367 * "rdesc" while resolving, or for blocking "events". 368 * 369 * This holds both for resolv_usage_page() and hid_resolv_usage(). 370 */ 371 static char *resolv_usage_page(unsigned page, struct seq_file *f) { 372 const struct hid_usage_entry *p; 373 char *buf = NULL; 374 375 if (!f) { 376 buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC); 377 if (!buf) 378 return ERR_PTR(-ENOMEM); 379 } 380 381 for (p = hid_usage_table; p->description; p++) 382 if (p->page == page) { 383 if (!f) { 384 snprintf(buf, HID_DEBUG_BUFSIZE, "%s", 385 p->description); 386 return buf; 387 } 388 else { 389 seq_printf(f, "%s", p->description); 390 return NULL; 391 } 392 } 393 if (!f) 394 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page); 395 else 396 seq_printf(f, "%04x", page); 397 return buf; 398 } 399 400 char *hid_resolv_usage(unsigned usage, struct seq_file *f) { 401 const struct hid_usage_entry *p; 402 char *buf = NULL; 403 int len = 0; 404 405 buf = resolv_usage_page(usage >> 16, f); 406 if (IS_ERR(buf)) { 407 pr_err("error allocating HID debug buffer\n"); 408 return NULL; 409 } 410 411 412 if (!f) { 413 len = strlen(buf); 414 snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), "."); 415 len++; 416 } 417 else { 418 seq_printf(f, "."); 419 } 420 for (p = hid_usage_table; p->description; p++) 421 if (p->page == (usage >> 16)) { 422 for(++p; p->description && p->usage != 0; p++) 423 if (p->usage == (usage & 0xffff)) { 424 if (!f) 425 snprintf(buf + len, 426 max(0,HID_DEBUG_BUFSIZE - len - 1), 427 "%s", p->description); 428 else 429 seq_printf(f, 430 "%s", 431 p->description); 432 return buf; 433 } 434 break; 435 } 436 if (!f) 437 snprintf(buf + len, max(0, HID_DEBUG_BUFSIZE - len - 1), 438 "%04x", usage & 0xffff); 439 else 440 seq_printf(f, "%04x", usage & 0xffff); 441 return buf; 442 } 443 EXPORT_SYMBOL_GPL(hid_resolv_usage); 444 445 static void tab(int n, struct seq_file *f) { 446 seq_printf(f, "%*s", n, ""); 447 } 448 449 void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) { 450 int j; 451 452 if (field->physical) { 453 tab(n, f); 454 seq_printf(f, "Physical("); 455 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n"); 456 } 457 if (field->logical) { 458 tab(n, f); 459 seq_printf(f, "Logical("); 460 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n"); 461 } 462 if (field->application) { 463 tab(n, f); 464 seq_printf(f, "Application("); 465 hid_resolv_usage(field->application, f); seq_printf(f, ")\n"); 466 } 467 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage); 468 for (j = 0; j < field->maxusage; j++) { 469 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n"); 470 } 471 if (field->logical_minimum != field->logical_maximum) { 472 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum); 473 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum); 474 } 475 if (field->physical_minimum != field->physical_maximum) { 476 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum); 477 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum); 478 } 479 if (field->unit_exponent) { 480 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent); 481 } 482 if (field->unit) { 483 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" }; 484 static const char *units[5][8] = { 485 { "None", "None", "None", "None", "None", "None", "None", "None" }, 486 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" }, 487 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" }, 488 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }, 489 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" } 490 }; 491 492 int i; 493 int sys; 494 __u32 data = field->unit; 495 496 /* First nibble tells us which system we're in. */ 497 sys = data & 0xf; 498 data >>= 4; 499 500 if(sys > 4) { 501 tab(n, f); seq_printf(f, "Unit(Invalid)\n"); 502 } 503 else { 504 int earlier_unit = 0; 505 506 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]); 507 508 for (i=1 ; i<sizeof(__u32)*2 ; i++) { 509 char nibble = data & 0xf; 510 data >>= 4; 511 if (nibble != 0) { 512 if(earlier_unit++ > 0) 513 seq_printf(f, "*"); 514 seq_printf(f, "%s", units[sys][i]); 515 if(nibble != 1) { 516 /* This is a _signed_ nibble(!) */ 517 518 int val = nibble & 0x7; 519 if(nibble & 0x08) 520 val = -((0x7 & ~val) +1); 521 seq_printf(f, "^%d", val); 522 } 523 } 524 } 525 seq_printf(f, ")\n"); 526 } 527 } 528 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size); 529 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count); 530 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset); 531 532 tab(n, f); seq_printf(f, "Flags( "); 533 j = field->flags; 534 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : ""); 535 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array "); 536 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute "); 537 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : ""); 538 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : ""); 539 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : ""); 540 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : ""); 541 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : ""); 542 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : ""); 543 seq_printf(f, ")\n"); 544 } 545 EXPORT_SYMBOL_GPL(hid_dump_field); 546 547 void hid_dump_device(struct hid_device *device, struct seq_file *f) 548 { 549 struct hid_report_enum *report_enum; 550 struct hid_report *report; 551 struct list_head *list; 552 unsigned i,k; 553 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"}; 554 555 for (i = 0; i < HID_REPORT_TYPES; i++) { 556 report_enum = device->report_enum + i; 557 list = report_enum->report_list.next; 558 while (list != &report_enum->report_list) { 559 report = (struct hid_report *) list; 560 tab(2, f); 561 seq_printf(f, "%s", table[i]); 562 if (report->id) 563 seq_printf(f, "(%d)", report->id); 564 seq_printf(f, "[%s]", table[report->type]); 565 seq_printf(f, "\n"); 566 for (k = 0; k < report->maxfield; k++) { 567 tab(4, f); 568 seq_printf(f, "Field(%d)\n", k); 569 hid_dump_field(report->field[k], 6, f); 570 } 571 list = list->next; 572 } 573 } 574 } 575 EXPORT_SYMBOL_GPL(hid_dump_device); 576 577 /* enqueue string to 'events' ring buffer */ 578 void hid_debug_event(struct hid_device *hdev, char *buf) 579 { 580 int i; 581 struct hid_debug_list *list; 582 unsigned long flags; 583 584 spin_lock_irqsave(&hdev->debug_list_lock, flags); 585 list_for_each_entry(list, &hdev->debug_list, node) { 586 for (i = 0; i < strlen(buf); i++) 587 list->hid_debug_buf[(list->tail + i) % HID_DEBUG_BUFSIZE] = 588 buf[i]; 589 list->tail = (list->tail + i) % HID_DEBUG_BUFSIZE; 590 } 591 spin_unlock_irqrestore(&hdev->debug_list_lock, flags); 592 593 wake_up_interruptible(&hdev->debug_wait); 594 } 595 EXPORT_SYMBOL_GPL(hid_debug_event); 596 597 void hid_dump_report(struct hid_device *hid, int type, u8 *data, 598 int size) 599 { 600 struct hid_report_enum *report_enum; 601 char *buf; 602 unsigned int i; 603 604 buf = kmalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_ATOMIC); 605 606 if (!buf) 607 return; 608 609 report_enum = hid->report_enum + type; 610 611 /* dump the report */ 612 snprintf(buf, HID_DEBUG_BUFSIZE - 1, 613 "\nreport (size %u) (%snumbered) = ", size, 614 report_enum->numbered ? "" : "un"); 615 hid_debug_event(hid, buf); 616 617 for (i = 0; i < size; i++) { 618 snprintf(buf, HID_DEBUG_BUFSIZE - 1, 619 " %02x", data[i]); 620 hid_debug_event(hid, buf); 621 } 622 hid_debug_event(hid, "\n"); 623 kfree(buf); 624 } 625 EXPORT_SYMBOL_GPL(hid_dump_report); 626 627 void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value) 628 { 629 char *buf; 630 int len; 631 632 buf = hid_resolv_usage(usage->hid, NULL); 633 if (!buf) 634 return; 635 len = strlen(buf); 636 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value); 637 638 hid_debug_event(hdev, buf); 639 640 kfree(buf); 641 wake_up_interruptible(&hdev->debug_wait); 642 643 } 644 EXPORT_SYMBOL_GPL(hid_dump_input); 645 646 static const char *events[EV_MAX + 1] = { 647 [EV_SYN] = "Sync", [EV_KEY] = "Key", 648 [EV_REL] = "Relative", [EV_ABS] = "Absolute", 649 [EV_MSC] = "Misc", [EV_LED] = "LED", 650 [EV_SND] = "Sound", [EV_REP] = "Repeat", 651 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power", 652 [EV_FF_STATUS] = "ForceFeedbackStatus", 653 }; 654 655 static const char *syncs[3] = { 656 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config", 657 [SYN_MT_REPORT] = "MT Report", 658 }; 659 660 static const char *keys[KEY_MAX + 1] = { 661 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc", 662 [KEY_1] = "1", [KEY_2] = "2", 663 [KEY_3] = "3", [KEY_4] = "4", 664 [KEY_5] = "5", [KEY_6] = "6", 665 [KEY_7] = "7", [KEY_8] = "8", 666 [KEY_9] = "9", [KEY_0] = "0", 667 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal", 668 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab", 669 [KEY_Q] = "Q", [KEY_W] = "W", 670 [KEY_E] = "E", [KEY_R] = "R", 671 [KEY_T] = "T", [KEY_Y] = "Y", 672 [KEY_U] = "U", [KEY_I] = "I", 673 [KEY_O] = "O", [KEY_P] = "P", 674 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace", 675 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl", 676 [KEY_A] = "A", [KEY_S] = "S", 677 [KEY_D] = "D", [KEY_F] = "F", 678 [KEY_G] = "G", [KEY_H] = "H", 679 [KEY_J] = "J", [KEY_K] = "K", 680 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon", 681 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave", 682 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash", 683 [KEY_Z] = "Z", [KEY_X] = "X", 684 [KEY_C] = "C", [KEY_V] = "V", 685 [KEY_B] = "B", [KEY_N] = "N", 686 [KEY_M] = "M", [KEY_COMMA] = "Comma", 687 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash", 688 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk", 689 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space", 690 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1", 691 [KEY_F2] = "F2", [KEY_F3] = "F3", 692 [KEY_F4] = "F4", [KEY_F5] = "F5", 693 [KEY_F6] = "F6", [KEY_F7] = "F7", 694 [KEY_F8] = "F8", [KEY_F9] = "F9", 695 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock", 696 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7", 697 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9", 698 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4", 699 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6", 700 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1", 701 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3", 702 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot", 703 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd", 704 [KEY_F11] = "F11", [KEY_F12] = "F12", 705 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana", 706 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan", 707 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan", 708 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter", 709 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash", 710 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt", 711 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home", 712 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp", 713 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right", 714 [KEY_END] = "End", [KEY_DOWN] = "Down", 715 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert", 716 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro", 717 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown", 718 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power", 719 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus", 720 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma", 721 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja", 722 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta", 723 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose", 724 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again", 725 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo", 726 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy", 727 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste", 728 [KEY_FIND] = "Find", [KEY_CUT] = "Cut", 729 [KEY_HELP] = "Help", [KEY_MENU] = "Menu", 730 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup", 731 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp", 732 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile", 733 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer", 734 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2", 735 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS", 736 [KEY_COFFEE] = "Coffee", [KEY_DIRECTION] = "Direction", 737 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail", 738 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer", 739 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward", 740 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD", 741 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong", 742 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong", 743 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record", 744 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone", 745 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config", 746 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh", 747 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move", 748 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp", 749 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis", 750 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New", 751 [KEY_REDO] = "Redo", [KEY_F13] = "F13", 752 [KEY_F14] = "F14", [KEY_F15] = "F15", 753 [KEY_F16] = "F16", [KEY_F17] = "F17", 754 [KEY_F18] = "F18", [KEY_F19] = "F19", 755 [KEY_F20] = "F20", [KEY_F21] = "F21", 756 [KEY_F22] = "F22", [KEY_F23] = "F23", 757 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD", 758 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3", 759 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend", 760 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play", 761 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost", 762 [KEY_PRINT] = "Print", [KEY_HP] = "HP", 763 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound", 764 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email", 765 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search", 766 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance", 767 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop", 768 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel", 769 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp", 770 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown", 771 [BTN_DPAD_UP] = "BtnDPadUp", [BTN_DPAD_DOWN] = "BtnDPadDown", 772 [BTN_DPAD_LEFT] = "BtnDPadLeft", [BTN_DPAD_RIGHT] = "BtnDPadRight", 773 [BTN_0] = "Btn0", [BTN_1] = "Btn1", 774 [BTN_2] = "Btn2", [BTN_3] = "Btn3", 775 [BTN_4] = "Btn4", [BTN_5] = "Btn5", 776 [BTN_6] = "Btn6", [BTN_7] = "Btn7", 777 [BTN_8] = "Btn8", [BTN_9] = "Btn9", 778 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn", 779 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn", 780 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn", 781 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn", 782 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn", 783 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn", 784 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn", 785 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2", 786 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4", 787 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6", 788 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA", 789 [BTN_B] = "BtnB", [BTN_C] = "BtnC", 790 [BTN_X] = "BtnX", [BTN_Y] = "BtnY", 791 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL", 792 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2", 793 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect", 794 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode", 795 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR", 796 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber", 797 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil", 798 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger", 799 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens", 800 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus", 801 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap", 802 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_TOOL_QUADTAP] = "ToolQuadrupleTap", 803 [BTN_GEAR_DOWN] = "WheelBtn", 804 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok", 805 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto", 806 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2", 807 [KEY_OPTION] = "Option", [KEY_INFO] = "Info", 808 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor", 809 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program", 810 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites", 811 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR", 812 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language", 813 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle", 814 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom", 815 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard", 816 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC", 817 [KEY_TV] = "TV", [KEY_TV2] = "TV2", 818 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2", 819 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2", 820 [KEY_CD] = "CD", [KEY_TAPE] = "Tape", 821 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner", 822 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text", 823 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux", 824 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio", 825 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory", 826 [KEY_LIST] = "List", [KEY_MEMO] = "Memo", 827 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red", 828 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow", 829 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp", 830 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First", 831 [KEY_LAST] = "Last", [KEY_AB] = "AB", 832 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart", 833 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle", 834 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous", 835 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN", 836 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL", 837 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine", 838 [KEY_DEL_LINE] = "DeleteLine", 839 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply", 840 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save", 841 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck", 842 [KEY_LOGOFF] = "Logoff", 843 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC", 844 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2", 845 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D", 846 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F", 847 [KEY_FN_S] = "Fn+S", 848 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2", 849 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4", 850 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6", 851 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8", 852 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10", 853 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12", 854 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle", 855 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown", 856 [KEY_KBDILLUMUP] = "KbdIlluminationUp", 857 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode", 858 }; 859 860 static const char *relatives[REL_MAX + 1] = { 861 [REL_X] = "X", [REL_Y] = "Y", 862 [REL_Z] = "Z", [REL_RX] = "Rx", 863 [REL_RY] = "Ry", [REL_RZ] = "Rz", 864 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial", 865 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc", 866 }; 867 868 static const char *absolutes[ABS_CNT] = { 869 [ABS_X] = "X", [ABS_Y] = "Y", 870 [ABS_Z] = "Z", [ABS_RX] = "Rx", 871 [ABS_RY] = "Ry", [ABS_RZ] = "Rz", 872 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder", 873 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas", 874 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X", 875 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X", 876 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X", 877 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X", 878 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure", 879 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt", 880 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth", 881 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc", 882 [ABS_MT_TOUCH_MAJOR] = "MTMajor", 883 [ABS_MT_TOUCH_MINOR] = "MTMinor", 884 [ABS_MT_WIDTH_MAJOR] = "MTMajorW", 885 [ABS_MT_WIDTH_MINOR] = "MTMinorW", 886 [ABS_MT_ORIENTATION] = "MTOrientation", 887 [ABS_MT_POSITION_X] = "MTPositionX", 888 [ABS_MT_POSITION_Y] = "MTPositionY", 889 [ABS_MT_TOOL_TYPE] = "MTToolType", 890 [ABS_MT_BLOB_ID] = "MTBlobID", 891 }; 892 893 static const char *misc[MSC_MAX + 1] = { 894 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled", 895 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData" 896 }; 897 898 static const char *leds[LED_MAX + 1] = { 899 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock", 900 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose", 901 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep", 902 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute", 903 [LED_MISC] = "Misc", 904 }; 905 906 static const char *repeats[REP_MAX + 1] = { 907 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period" 908 }; 909 910 static const char *sounds[SND_MAX + 1] = { 911 [SND_CLICK] = "Click", [SND_BELL] = "Bell", 912 [SND_TONE] = "Tone" 913 }; 914 915 static const char **names[EV_MAX + 1] = { 916 [EV_SYN] = syncs, [EV_KEY] = keys, 917 [EV_REL] = relatives, [EV_ABS] = absolutes, 918 [EV_MSC] = misc, [EV_LED] = leds, 919 [EV_SND] = sounds, [EV_REP] = repeats, 920 }; 921 922 static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f) 923 { 924 seq_printf(f, "%s.%s", events[type] ? events[type] : "?", 925 names[type] ? (names[type][code] ? names[type][code] : "?") : "?"); 926 } 927 928 static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f) 929 { 930 int i, j, k; 931 struct hid_report *report; 932 struct hid_usage *usage; 933 934 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) { 935 list_for_each_entry(report, &hid->report_enum[k].report_list, list) { 936 for (i = 0; i < report->maxfield; i++) { 937 for ( j = 0; j < report->field[i]->maxusage; j++) { 938 usage = report->field[i]->usage + j; 939 hid_resolv_usage(usage->hid, f); 940 seq_printf(f, " ---> "); 941 hid_resolv_event(usage->type, usage->code, f); 942 seq_printf(f, "\n"); 943 } 944 } 945 } 946 } 947 948 } 949 950 static int hid_debug_rdesc_show(struct seq_file *f, void *p) 951 { 952 struct hid_device *hdev = f->private; 953 const __u8 *rdesc = hdev->rdesc; 954 unsigned rsize = hdev->rsize; 955 int i; 956 957 if (!rdesc) { 958 rdesc = hdev->dev_rdesc; 959 rsize = hdev->dev_rsize; 960 } 961 962 /* dump HID report descriptor */ 963 for (i = 0; i < rsize; i++) 964 seq_printf(f, "%02x ", rdesc[i]); 965 seq_printf(f, "\n\n"); 966 967 /* dump parsed data and input mappings */ 968 hid_dump_device(hdev, f); 969 seq_printf(f, "\n"); 970 hid_dump_input_mapping(hdev, f); 971 972 return 0; 973 } 974 975 static int hid_debug_rdesc_open(struct inode *inode, struct file *file) 976 { 977 return single_open(file, hid_debug_rdesc_show, inode->i_private); 978 } 979 980 static int hid_debug_events_open(struct inode *inode, struct file *file) 981 { 982 int err = 0; 983 struct hid_debug_list *list; 984 unsigned long flags; 985 986 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) { 987 err = -ENOMEM; 988 goto out; 989 } 990 991 if (!(list->hid_debug_buf = kzalloc(sizeof(char) * HID_DEBUG_BUFSIZE, GFP_KERNEL))) { 992 err = -ENOMEM; 993 kfree(list); 994 goto out; 995 } 996 list->hdev = (struct hid_device *) inode->i_private; 997 file->private_data = list; 998 mutex_init(&list->read_mutex); 999 1000 spin_lock_irqsave(&list->hdev->debug_list_lock, flags); 1001 list_add_tail(&list->node, &list->hdev->debug_list); 1002 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags); 1003 1004 out: 1005 return err; 1006 } 1007 1008 static ssize_t hid_debug_events_read(struct file *file, char __user *buffer, 1009 size_t count, loff_t *ppos) 1010 { 1011 struct hid_debug_list *list = file->private_data; 1012 int ret = 0, len; 1013 DECLARE_WAITQUEUE(wait, current); 1014 1015 mutex_lock(&list->read_mutex); 1016 while (ret == 0) { 1017 if (list->head == list->tail) { 1018 add_wait_queue(&list->hdev->debug_wait, &wait); 1019 set_current_state(TASK_INTERRUPTIBLE); 1020 1021 while (list->head == list->tail) { 1022 if (file->f_flags & O_NONBLOCK) { 1023 ret = -EAGAIN; 1024 break; 1025 } 1026 if (signal_pending(current)) { 1027 ret = -ERESTARTSYS; 1028 break; 1029 } 1030 1031 if (!list->hdev || !list->hdev->debug) { 1032 ret = -EIO; 1033 break; 1034 } 1035 1036 /* allow O_NONBLOCK from other threads */ 1037 mutex_unlock(&list->read_mutex); 1038 schedule(); 1039 mutex_lock(&list->read_mutex); 1040 set_current_state(TASK_INTERRUPTIBLE); 1041 } 1042 1043 set_current_state(TASK_RUNNING); 1044 remove_wait_queue(&list->hdev->debug_wait, &wait); 1045 } 1046 1047 if (ret) 1048 goto out; 1049 1050 /* pass the ringbuffer contents to userspace */ 1051 copy_rest: 1052 if (list->tail == list->head) 1053 goto out; 1054 if (list->tail > list->head) { 1055 len = list->tail - list->head; 1056 1057 if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) { 1058 ret = -EFAULT; 1059 goto out; 1060 } 1061 ret += len; 1062 list->head += len; 1063 } else { 1064 len = HID_DEBUG_BUFSIZE - list->head; 1065 1066 if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) { 1067 ret = -EFAULT; 1068 goto out; 1069 } 1070 list->head = 0; 1071 ret += len; 1072 goto copy_rest; 1073 } 1074 1075 } 1076 out: 1077 mutex_unlock(&list->read_mutex); 1078 return ret; 1079 } 1080 1081 static unsigned int hid_debug_events_poll(struct file *file, poll_table *wait) 1082 { 1083 struct hid_debug_list *list = file->private_data; 1084 1085 poll_wait(file, &list->hdev->debug_wait, wait); 1086 if (list->head != list->tail) 1087 return POLLIN | POLLRDNORM; 1088 if (!list->hdev->debug) 1089 return POLLERR | POLLHUP; 1090 return 0; 1091 } 1092 1093 static int hid_debug_events_release(struct inode *inode, struct file *file) 1094 { 1095 struct hid_debug_list *list = file->private_data; 1096 unsigned long flags; 1097 1098 spin_lock_irqsave(&list->hdev->debug_list_lock, flags); 1099 list_del(&list->node); 1100 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags); 1101 kfree(list->hid_debug_buf); 1102 kfree(list); 1103 1104 return 0; 1105 } 1106 1107 static const struct file_operations hid_debug_rdesc_fops = { 1108 .open = hid_debug_rdesc_open, 1109 .read = seq_read, 1110 .llseek = seq_lseek, 1111 .release = single_release, 1112 }; 1113 1114 static const struct file_operations hid_debug_events_fops = { 1115 .owner = THIS_MODULE, 1116 .open = hid_debug_events_open, 1117 .read = hid_debug_events_read, 1118 .poll = hid_debug_events_poll, 1119 .release = hid_debug_events_release, 1120 .llseek = noop_llseek, 1121 }; 1122 1123 1124 void hid_debug_register(struct hid_device *hdev, const char *name) 1125 { 1126 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root); 1127 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400, 1128 hdev->debug_dir, hdev, &hid_debug_rdesc_fops); 1129 hdev->debug_events = debugfs_create_file("events", 0400, 1130 hdev->debug_dir, hdev, &hid_debug_events_fops); 1131 hdev->debug = 1; 1132 } 1133 1134 void hid_debug_unregister(struct hid_device *hdev) 1135 { 1136 hdev->debug = 0; 1137 wake_up_interruptible(&hdev->debug_wait); 1138 debugfs_remove(hdev->debug_rdesc); 1139 debugfs_remove(hdev->debug_events); 1140 debugfs_remove(hdev->debug_dir); 1141 } 1142 1143 void hid_debug_init(void) 1144 { 1145 hid_debug_root = debugfs_create_dir("hid", NULL); 1146 } 1147 1148 void hid_debug_exit(void) 1149 { 1150 debugfs_remove_recursive(hid_debug_root); 1151 } 1152 1153