0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0018
0019 #include <linux/debugfs.h>
0020 #include <linux/seq_file.h>
0021 #include <linux/kfifo.h>
0022 #include <linux/sched/signal.h>
0023 #include <linux/export.h>
0024 #include <linux/slab.h>
0025 #include <linux/uaccess.h>
0026 #include <linux/poll.h>
0027
0028 #include <linux/hid.h>
0029 #include <linux/hid-debug.h>
0030
0031 static struct dentry *hid_debug_root;
0032
0033 struct hid_usage_entry {
0034 unsigned page;
0035 unsigned usage;
0036 const char *description;
0037 };
0038
0039 static const struct hid_usage_entry hid_usage_table[] = {
0040 { 0, 0, "Undefined" },
0041 { 1, 0, "GenericDesktop" },
0042 {0, 0x01, "Pointer"},
0043 {0, 0x02, "Mouse"},
0044 {0, 0x04, "Joystick"},
0045 {0, 0x05, "GamePad"},
0046 {0, 0x06, "Keyboard"},
0047 {0, 0x07, "Keypad"},
0048 {0, 0x08, "MultiAxis"},
0049 {0, 0x30, "X"},
0050 {0, 0x31, "Y"},
0051 {0, 0x32, "Z"},
0052 {0, 0x33, "Rx"},
0053 {0, 0x34, "Ry"},
0054 {0, 0x35, "Rz"},
0055 {0, 0x36, "Slider"},
0056 {0, 0x37, "Dial"},
0057 {0, 0x38, "Wheel"},
0058 {0, 0x39, "HatSwitch"},
0059 {0, 0x3a, "CountedBuffer"},
0060 {0, 0x3b, "ByteCount"},
0061 {0, 0x3c, "MotionWakeup"},
0062 {0, 0x3d, "Start"},
0063 {0, 0x3e, "Select"},
0064 {0, 0x40, "Vx"},
0065 {0, 0x41, "Vy"},
0066 {0, 0x42, "Vz"},
0067 {0, 0x43, "Vbrx"},
0068 {0, 0x44, "Vbry"},
0069 {0, 0x45, "Vbrz"},
0070 {0, 0x46, "Vno"},
0071 {0, 0x80, "SystemControl"},
0072 {0, 0x81, "SystemPowerDown"},
0073 {0, 0x82, "SystemSleep"},
0074 {0, 0x83, "SystemWakeUp"},
0075 {0, 0x84, "SystemContextMenu"},
0076 {0, 0x85, "SystemMainMenu"},
0077 {0, 0x86, "SystemAppMenu"},
0078 {0, 0x87, "SystemMenuHelp"},
0079 {0, 0x88, "SystemMenuExit"},
0080 {0, 0x89, "SystemMenuSelect"},
0081 {0, 0x8a, "SystemMenuRight"},
0082 {0, 0x8b, "SystemMenuLeft"},
0083 {0, 0x8c, "SystemMenuUp"},
0084 {0, 0x8d, "SystemMenuDown"},
0085 {0, 0x90, "D-PadUp"},
0086 {0, 0x91, "D-PadDown"},
0087 {0, 0x92, "D-PadRight"},
0088 {0, 0x93, "D-PadLeft"},
0089 { 2, 0, "Simulation" },
0090 {0, 0xb0, "Aileron"},
0091 {0, 0xb1, "AileronTrim"},
0092 {0, 0xb2, "Anti-Torque"},
0093 {0, 0xb3, "Autopilot"},
0094 {0, 0xb4, "Chaff"},
0095 {0, 0xb5, "Collective"},
0096 {0, 0xb6, "DiveBrake"},
0097 {0, 0xb7, "ElectronicCountermeasures"},
0098 {0, 0xb8, "Elevator"},
0099 {0, 0xb9, "ElevatorTrim"},
0100 {0, 0xba, "Rudder"},
0101 {0, 0xbb, "Throttle"},
0102 {0, 0xbc, "FlightCommunications"},
0103 {0, 0xbd, "FlareRelease"},
0104 {0, 0xbe, "LandingGear"},
0105 {0, 0xbf, "ToeBrake"},
0106 { 6, 0, "GenericDeviceControls" },
0107 {0, 0x20, "BatteryStrength" },
0108 {0, 0x21, "WirelessChannel" },
0109 {0, 0x22, "WirelessID" },
0110 {0, 0x23, "DiscoverWirelessControl" },
0111 {0, 0x24, "SecurityCodeCharacterEntered" },
0112 {0, 0x25, "SecurityCodeCharactedErased" },
0113 {0, 0x26, "SecurityCodeCleared" },
0114 { 7, 0, "Keyboard" },
0115 { 8, 0, "LED" },
0116 {0, 0x01, "NumLock"},
0117 {0, 0x02, "CapsLock"},
0118 {0, 0x03, "ScrollLock"},
0119 {0, 0x04, "Compose"},
0120 {0, 0x05, "Kana"},
0121 {0, 0x4b, "GenericIndicator"},
0122 { 9, 0, "Button" },
0123 { 10, 0, "Ordinal" },
0124 { 12, 0, "Consumer" },
0125 {0, 0x003, "ProgrammableButtons"},
0126 {0, 0x238, "HorizontalWheel"},
0127 { 13, 0, "Digitizers" },
0128 {0, 0x01, "Digitizer"},
0129 {0, 0x02, "Pen"},
0130 {0, 0x03, "LightPen"},
0131 {0, 0x04, "TouchScreen"},
0132 {0, 0x05, "TouchPad"},
0133 {0, 0x0e, "DeviceConfiguration"},
0134 {0, 0x20, "Stylus"},
0135 {0, 0x21, "Puck"},
0136 {0, 0x22, "Finger"},
0137 {0, 0x23, "DeviceSettings"},
0138 {0, 0x30, "TipPressure"},
0139 {0, 0x31, "BarrelPressure"},
0140 {0, 0x32, "InRange"},
0141 {0, 0x33, "Touch"},
0142 {0, 0x34, "UnTouch"},
0143 {0, 0x35, "Tap"},
0144 {0, 0x38, "Transducer Index"},
0145 {0, 0x39, "TabletFunctionKey"},
0146 {0, 0x3a, "ProgramChangeKey"},
0147 {0, 0x3B, "Battery Strength"},
0148 {0, 0x3c, "Invert"},
0149 {0, 0x42, "TipSwitch"},
0150 {0, 0x43, "SecondaryTipSwitch"},
0151 {0, 0x44, "BarrelSwitch"},
0152 {0, 0x45, "Eraser"},
0153 {0, 0x46, "TabletPick"},
0154 {0, 0x47, "Confidence"},
0155 {0, 0x48, "Width"},
0156 {0, 0x49, "Height"},
0157 {0, 0x51, "ContactID"},
0158 {0, 0x52, "InputMode"},
0159 {0, 0x53, "DeviceIndex"},
0160 {0, 0x54, "ContactCount"},
0161 {0, 0x55, "ContactMaximumNumber"},
0162 {0, 0x59, "ButtonType"},
0163 {0, 0x5A, "SecondaryBarrelSwitch"},
0164 {0, 0x5B, "TransducerSerialNumber"},
0165 {0, 0x5C, "Preferred Color"},
0166 {0, 0x5D, "Preferred Color is Locked"},
0167 {0, 0x5E, "Preferred Line Width"},
0168 {0, 0x5F, "Preferred Line Width is Locked"},
0169 {0, 0x6e, "TransducerSerialNumber2"},
0170 {0, 0x70, "Preferred Line Style"},
0171 {0, 0x71, "Preferred Line Style is Locked"},
0172 {0, 0x72, "Ink"},
0173 {0, 0x73, "Pencil"},
0174 {0, 0x74, "Highlighter"},
0175 {0, 0x75, "Chisel Marker"},
0176 {0, 0x76, "Brush"},
0177 {0, 0x77, "No Preference"},
0178 {0, 0x80, "Digitizer Diagnostic"},
0179 {0, 0x81, "Digitizer Error"},
0180 {0, 0x82, "Err Normal Status"},
0181 {0, 0x83, "Err Transducers Exceeded"},
0182 {0, 0x84, "Err Full Trans Features Unavailable"},
0183 {0, 0x85, "Err Charge Low"},
0184 {0, 0x90, "Transducer Software Info"},
0185 {0, 0x91, "Transducer Vendor Id"},
0186 {0, 0x92, "Transducer Product Id"},
0187 {0, 0x93, "Device Supported Protocols"},
0188 {0, 0x94, "Transducer Supported Protocols"},
0189 {0, 0x95, "No Protocol"},
0190 {0, 0x96, "Wacom AES Protocol"},
0191 {0, 0x97, "USI Protocol"},
0192 {0, 0x98, "Microsoft Pen Protocol"},
0193 {0, 0xA0, "Supported Report Rates"},
0194 {0, 0xA1, "Report Rate"},
0195 {0, 0xA2, "Transducer Connected"},
0196 {0, 0xA3, "Switch Disabled"},
0197 {0, 0xA4, "Switch Unimplemented"},
0198 {0, 0xA5, "Transducer Switches"},
0199 { 15, 0, "PhysicalInterfaceDevice" },
0200 {0, 0x00, "Undefined"},
0201 {0, 0x01, "Physical_Interface_Device"},
0202 {0, 0x20, "Normal"},
0203 {0, 0x21, "Set_Effect_Report"},
0204 {0, 0x22, "Effect_Block_Index"},
0205 {0, 0x23, "Parameter_Block_Offset"},
0206 {0, 0x24, "ROM_Flag"},
0207 {0, 0x25, "Effect_Type"},
0208 {0, 0x26, "ET_Constant_Force"},
0209 {0, 0x27, "ET_Ramp"},
0210 {0, 0x28, "ET_Custom_Force_Data"},
0211 {0, 0x30, "ET_Square"},
0212 {0, 0x31, "ET_Sine"},
0213 {0, 0x32, "ET_Triangle"},
0214 {0, 0x33, "ET_Sawtooth_Up"},
0215 {0, 0x34, "ET_Sawtooth_Down"},
0216 {0, 0x40, "ET_Spring"},
0217 {0, 0x41, "ET_Damper"},
0218 {0, 0x42, "ET_Inertia"},
0219 {0, 0x43, "ET_Friction"},
0220 {0, 0x50, "Duration"},
0221 {0, 0x51, "Sample_Period"},
0222 {0, 0x52, "Gain"},
0223 {0, 0x53, "Trigger_Button"},
0224 {0, 0x54, "Trigger_Repeat_Interval"},
0225 {0, 0x55, "Axes_Enable"},
0226 {0, 0x56, "Direction_Enable"},
0227 {0, 0x57, "Direction"},
0228 {0, 0x58, "Type_Specific_Block_Offset"},
0229 {0, 0x59, "Block_Type"},
0230 {0, 0x5A, "Set_Envelope_Report"},
0231 {0, 0x5B, "Attack_Level"},
0232 {0, 0x5C, "Attack_Time"},
0233 {0, 0x5D, "Fade_Level"},
0234 {0, 0x5E, "Fade_Time"},
0235 {0, 0x5F, "Set_Condition_Report"},
0236 {0, 0x60, "CP_Offset"},
0237 {0, 0x61, "Positive_Coefficient"},
0238 {0, 0x62, "Negative_Coefficient"},
0239 {0, 0x63, "Positive_Saturation"},
0240 {0, 0x64, "Negative_Saturation"},
0241 {0, 0x65, "Dead_Band"},
0242 {0, 0x66, "Download_Force_Sample"},
0243 {0, 0x67, "Isoch_Custom_Force_Enable"},
0244 {0, 0x68, "Custom_Force_Data_Report"},
0245 {0, 0x69, "Custom_Force_Data"},
0246 {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},
0247 {0, 0x6B, "Set_Custom_Force_Report"},
0248 {0, 0x6C, "Custom_Force_Data_Offset"},
0249 {0, 0x6D, "Sample_Count"},
0250 {0, 0x6E, "Set_Periodic_Report"},
0251 {0, 0x6F, "Offset"},
0252 {0, 0x70, "Magnitude"},
0253 {0, 0x71, "Phase"},
0254 {0, 0x72, "Period"},
0255 {0, 0x73, "Set_Constant_Force_Report"},
0256 {0, 0x74, "Set_Ramp_Force_Report"},
0257 {0, 0x75, "Ramp_Start"},
0258 {0, 0x76, "Ramp_End"},
0259 {0, 0x77, "Effect_Operation_Report"},
0260 {0, 0x78, "Effect_Operation"},
0261 {0, 0x79, "Op_Effect_Start"},
0262 {0, 0x7A, "Op_Effect_Start_Solo"},
0263 {0, 0x7B, "Op_Effect_Stop"},
0264 {0, 0x7C, "Loop_Count"},
0265 {0, 0x7D, "Device_Gain_Report"},
0266 {0, 0x7E, "Device_Gain"},
0267 {0, 0x7F, "PID_Pool_Report"},
0268 {0, 0x80, "RAM_Pool_Size"},
0269 {0, 0x81, "ROM_Pool_Size"},
0270 {0, 0x82, "ROM_Effect_Block_Count"},
0271 {0, 0x83, "Simultaneous_Effects_Max"},
0272 {0, 0x84, "Pool_Alignment"},
0273 {0, 0x85, "PID_Pool_Move_Report"},
0274 {0, 0x86, "Move_Source"},
0275 {0, 0x87, "Move_Destination"},
0276 {0, 0x88, "Move_Length"},
0277 {0, 0x89, "PID_Block_Load_Report"},
0278 {0, 0x8B, "Block_Load_Status"},
0279 {0, 0x8C, "Block_Load_Success"},
0280 {0, 0x8D, "Block_Load_Full"},
0281 {0, 0x8E, "Block_Load_Error"},
0282 {0, 0x8F, "Block_Handle"},
0283 {0, 0x90, "PID_Block_Free_Report"},
0284 {0, 0x91, "Type_Specific_Block_Handle"},
0285 {0, 0x92, "PID_State_Report"},
0286 {0, 0x94, "Effect_Playing"},
0287 {0, 0x95, "PID_Device_Control_Report"},
0288 {0, 0x96, "PID_Device_Control"},
0289 {0, 0x97, "DC_Enable_Actuators"},
0290 {0, 0x98, "DC_Disable_Actuators"},
0291 {0, 0x99, "DC_Stop_All_Effects"},
0292 {0, 0x9A, "DC_Device_Reset"},
0293 {0, 0x9B, "DC_Device_Pause"},
0294 {0, 0x9C, "DC_Device_Continue"},
0295 {0, 0x9F, "Device_Paused"},
0296 {0, 0xA0, "Actuators_Enabled"},
0297 {0, 0xA4, "Safety_Switch"},
0298 {0, 0xA5, "Actuator_Override_Switch"},
0299 {0, 0xA6, "Actuator_Power"},
0300 {0, 0xA7, "Start_Delay"},
0301 {0, 0xA8, "Parameter_Block_Size"},
0302 {0, 0xA9, "Device_Managed_Pool"},
0303 {0, 0xAA, "Shared_Parameter_Blocks"},
0304 {0, 0xAB, "Create_New_Effect_Report"},
0305 {0, 0xAC, "RAM_Pool_Available"},
0306 { 0x20, 0, "Sensor" },
0307 { 0x20, 0x01, "Sensor" },
0308 { 0x20, 0x10, "Biometric" },
0309 { 0x20, 0x11, "BiometricHumanPresence" },
0310 { 0x20, 0x12, "BiometricHumanProximity" },
0311 { 0x20, 0x13, "BiometricHumanTouch" },
0312 { 0x20, 0x20, "Electrical" },
0313 { 0x20, 0x21, "ElectricalCapacitance" },
0314 { 0x20, 0x22, "ElectricalCurrent" },
0315 { 0x20, 0x23, "ElectricalPower" },
0316 { 0x20, 0x24, "ElectricalInductance" },
0317 { 0x20, 0x25, "ElectricalResistance" },
0318 { 0x20, 0x26, "ElectricalVoltage" },
0319 { 0x20, 0x27, "ElectricalPoteniometer" },
0320 { 0x20, 0x28, "ElectricalFrequency" },
0321 { 0x20, 0x29, "ElectricalPeriod" },
0322 { 0x20, 0x30, "Environmental" },
0323 { 0x20, 0x31, "EnvironmentalAtmosphericPressure" },
0324 { 0x20, 0x32, "EnvironmentalHumidity" },
0325 { 0x20, 0x33, "EnvironmentalTemperature" },
0326 { 0x20, 0x34, "EnvironmentalWindDirection" },
0327 { 0x20, 0x35, "EnvironmentalWindSpeed" },
0328 { 0x20, 0x40, "Light" },
0329 { 0x20, 0x41, "LightAmbientLight" },
0330 { 0x20, 0x42, "LightConsumerInfrared" },
0331 { 0x20, 0x50, "Location" },
0332 { 0x20, 0x51, "LocationBroadcast" },
0333 { 0x20, 0x52, "LocationDeadReckoning" },
0334 { 0x20, 0x53, "LocationGPS" },
0335 { 0x20, 0x54, "LocationLookup" },
0336 { 0x20, 0x55, "LocationOther" },
0337 { 0x20, 0x56, "LocationStatic" },
0338 { 0x20, 0x57, "LocationTriangulation" },
0339 { 0x20, 0x60, "Mechanical" },
0340 { 0x20, 0x61, "MechanicalBooleanSwitch" },
0341 { 0x20, 0x62, "MechanicalBooleanSwitchArray" },
0342 { 0x20, 0x63, "MechanicalMultivalueSwitch" },
0343 { 0x20, 0x64, "MechanicalForce" },
0344 { 0x20, 0x65, "MechanicalPressure" },
0345 { 0x20, 0x66, "MechanicalStrain" },
0346 { 0x20, 0x67, "MechanicalWeight" },
0347 { 0x20, 0x68, "MechanicalHapticVibrator" },
0348 { 0x20, 0x69, "MechanicalHallEffectSwitch" },
0349 { 0x20, 0x70, "Motion" },
0350 { 0x20, 0x71, "MotionAccelerometer1D" },
0351 { 0x20, 0x72, "MotionAccelerometer2D" },
0352 { 0x20, 0x73, "MotionAccelerometer3D" },
0353 { 0x20, 0x74, "MotionGyrometer1D" },
0354 { 0x20, 0x75, "MotionGyrometer2D" },
0355 { 0x20, 0x76, "MotionGyrometer3D" },
0356 { 0x20, 0x77, "MotionMotionDetector" },
0357 { 0x20, 0x78, "MotionSpeedometer" },
0358 { 0x20, 0x79, "MotionAccelerometer" },
0359 { 0x20, 0x7A, "MotionGyrometer" },
0360 { 0x20, 0x80, "Orientation" },
0361 { 0x20, 0x81, "OrientationCompass1D" },
0362 { 0x20, 0x82, "OrientationCompass2D" },
0363 { 0x20, 0x83, "OrientationCompass3D" },
0364 { 0x20, 0x84, "OrientationInclinometer1D" },
0365 { 0x20, 0x85, "OrientationInclinometer2D" },
0366 { 0x20, 0x86, "OrientationInclinometer3D" },
0367 { 0x20, 0x87, "OrientationDistance1D" },
0368 { 0x20, 0x88, "OrientationDistance2D" },
0369 { 0x20, 0x89, "OrientationDistance3D" },
0370 { 0x20, 0x8A, "OrientationDeviceOrientation" },
0371 { 0x20, 0x8B, "OrientationCompass" },
0372 { 0x20, 0x8C, "OrientationInclinometer" },
0373 { 0x20, 0x8D, "OrientationDistance" },
0374 { 0x20, 0x90, "Scanner" },
0375 { 0x20, 0x91, "ScannerBarcode" },
0376 { 0x20, 0x91, "ScannerRFID" },
0377 { 0x20, 0x91, "ScannerNFC" },
0378 { 0x20, 0xA0, "Time" },
0379 { 0x20, 0xA1, "TimeAlarmTimer" },
0380 { 0x20, 0xA2, "TimeRealTimeClock" },
0381 { 0x20, 0xE0, "Other" },
0382 { 0x20, 0xE1, "OtherCustom" },
0383 { 0x20, 0xE2, "OtherGeneric" },
0384 { 0x20, 0xE3, "OtherGenericEnumerator" },
0385 { 0x84, 0, "Power Device" },
0386 { 0x84, 0x02, "PresentStatus" },
0387 { 0x84, 0x03, "ChangeStatus" },
0388 { 0x84, 0x04, "UPS" },
0389 { 0x84, 0x05, "PowerSupply" },
0390 { 0x84, 0x10, "BatterySystem" },
0391 { 0x84, 0x11, "BatterySystemID" },
0392 { 0x84, 0x12, "Battery" },
0393 { 0x84, 0x13, "BatteryID" },
0394 { 0x84, 0x14, "Charger" },
0395 { 0x84, 0x15, "ChargerID" },
0396 { 0x84, 0x16, "PowerConverter" },
0397 { 0x84, 0x17, "PowerConverterID" },
0398 { 0x84, 0x18, "OutletSystem" },
0399 { 0x84, 0x19, "OutletSystemID" },
0400 { 0x84, 0x1a, "Input" },
0401 { 0x84, 0x1b, "InputID" },
0402 { 0x84, 0x1c, "Output" },
0403 { 0x84, 0x1d, "OutputID" },
0404 { 0x84, 0x1e, "Flow" },
0405 { 0x84, 0x1f, "FlowID" },
0406 { 0x84, 0x20, "Outlet" },
0407 { 0x84, 0x21, "OutletID" },
0408 { 0x84, 0x22, "Gang" },
0409 { 0x84, 0x24, "PowerSummary" },
0410 { 0x84, 0x25, "PowerSummaryID" },
0411 { 0x84, 0x30, "Voltage" },
0412 { 0x84, 0x31, "Current" },
0413 { 0x84, 0x32, "Frequency" },
0414 { 0x84, 0x33, "ApparentPower" },
0415 { 0x84, 0x35, "PercentLoad" },
0416 { 0x84, 0x40, "ConfigVoltage" },
0417 { 0x84, 0x41, "ConfigCurrent" },
0418 { 0x84, 0x43, "ConfigApparentPower" },
0419 { 0x84, 0x53, "LowVoltageTransfer" },
0420 { 0x84, 0x54, "HighVoltageTransfer" },
0421 { 0x84, 0x56, "DelayBeforeStartup" },
0422 { 0x84, 0x57, "DelayBeforeShutdown" },
0423 { 0x84, 0x58, "Test" },
0424 { 0x84, 0x5a, "AudibleAlarmControl" },
0425 { 0x84, 0x60, "Present" },
0426 { 0x84, 0x61, "Good" },
0427 { 0x84, 0x62, "InternalFailure" },
0428 { 0x84, 0x65, "Overload" },
0429 { 0x84, 0x66, "OverCharged" },
0430 { 0x84, 0x67, "OverTemperature" },
0431 { 0x84, 0x68, "ShutdownRequested" },
0432 { 0x84, 0x69, "ShutdownImminent" },
0433 { 0x84, 0x6b, "SwitchOn/Off" },
0434 { 0x84, 0x6c, "Switchable" },
0435 { 0x84, 0x6d, "Used" },
0436 { 0x84, 0x6e, "Boost" },
0437 { 0x84, 0x73, "CommunicationLost" },
0438 { 0x84, 0xfd, "iManufacturer" },
0439 { 0x84, 0xfe, "iProduct" },
0440 { 0x84, 0xff, "iSerialNumber" },
0441 { 0x85, 0, "Battery System" },
0442 { 0x85, 0x01, "SMBBatteryMode" },
0443 { 0x85, 0x02, "SMBBatteryStatus" },
0444 { 0x85, 0x03, "SMBAlarmWarning" },
0445 { 0x85, 0x04, "SMBChargerMode" },
0446 { 0x85, 0x05, "SMBChargerStatus" },
0447 { 0x85, 0x06, "SMBChargerSpecInfo" },
0448 { 0x85, 0x07, "SMBSelectorState" },
0449 { 0x85, 0x08, "SMBSelectorPresets" },
0450 { 0x85, 0x09, "SMBSelectorInfo" },
0451 { 0x85, 0x29, "RemainingCapacityLimit" },
0452 { 0x85, 0x2c, "CapacityMode" },
0453 { 0x85, 0x42, "BelowRemainingCapacityLimit" },
0454 { 0x85, 0x44, "Charging" },
0455 { 0x85, 0x45, "Discharging" },
0456 { 0x85, 0x4b, "NeedReplacement" },
0457 { 0x85, 0x65, "AbsoluteStateOfCharge" },
0458 { 0x85, 0x66, "RemainingCapacity" },
0459 { 0x85, 0x68, "RunTimeToEmpty" },
0460 { 0x85, 0x6a, "AverageTimeToFull" },
0461 { 0x85, 0x83, "DesignCapacity" },
0462 { 0x85, 0x85, "ManufacturerDate" },
0463 { 0x85, 0x89, "iDeviceChemistry" },
0464 { 0x85, 0x8b, "Rechargeable" },
0465 { 0x85, 0x8f, "iOEMInformation" },
0466 { 0x85, 0x8d, "CapacityGranularity1" },
0467 { 0x85, 0xd0, "ACPresent" },
0468
0469 { 0xffff, 0, "Vendor-specific-FF" },
0470 { 0, 0, NULL }
0471 };
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482 static char *resolv_usage_page(unsigned page, struct seq_file *f) {
0483 const struct hid_usage_entry *p;
0484 char *buf = NULL;
0485
0486 if (!f) {
0487 buf = kzalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
0488 if (!buf)
0489 return ERR_PTR(-ENOMEM);
0490 }
0491
0492 for (p = hid_usage_table; p->description; p++)
0493 if (p->page == page) {
0494 if (!f) {
0495 snprintf(buf, HID_DEBUG_BUFSIZE, "%s",
0496 p->description);
0497 return buf;
0498 }
0499 else {
0500 seq_printf(f, "%s", p->description);
0501 return NULL;
0502 }
0503 }
0504 if (!f)
0505 snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);
0506 else
0507 seq_printf(f, "%04x", page);
0508 return buf;
0509 }
0510
0511 char *hid_resolv_usage(unsigned usage, struct seq_file *f) {
0512 const struct hid_usage_entry *p;
0513 char *buf = NULL;
0514 int len = 0;
0515
0516 buf = resolv_usage_page(usage >> 16, f);
0517 if (IS_ERR(buf)) {
0518 pr_err("error allocating HID debug buffer\n");
0519 return NULL;
0520 }
0521
0522
0523 if (!f) {
0524 len = strlen(buf);
0525 len += scnprintf(buf + len, HID_DEBUG_BUFSIZE - len, ".");
0526 }
0527 else {
0528 seq_printf(f, ".");
0529 }
0530 for (p = hid_usage_table; p->description; p++)
0531 if (p->page == (usage >> 16)) {
0532 for(++p; p->description && p->usage != 0; p++)
0533 if (p->usage == (usage & 0xffff)) {
0534 if (!f)
0535 snprintf(buf + len,
0536 HID_DEBUG_BUFSIZE - len,
0537 "%s", p->description);
0538 else
0539 seq_printf(f,
0540 "%s",
0541 p->description);
0542 return buf;
0543 }
0544 break;
0545 }
0546 if (!f)
0547 snprintf(buf + len, HID_DEBUG_BUFSIZE - len, "%04x",
0548 usage & 0xffff);
0549 else
0550 seq_printf(f, "%04x", usage & 0xffff);
0551 return buf;
0552 }
0553 EXPORT_SYMBOL_GPL(hid_resolv_usage);
0554
0555 static void tab(int n, struct seq_file *f) {
0556 seq_printf(f, "%*s", n, "");
0557 }
0558
0559 void hid_dump_field(struct hid_field *field, int n, struct seq_file *f) {
0560 int j;
0561
0562 if (field->physical) {
0563 tab(n, f);
0564 seq_printf(f, "Physical(");
0565 hid_resolv_usage(field->physical, f); seq_printf(f, ")\n");
0566 }
0567 if (field->logical) {
0568 tab(n, f);
0569 seq_printf(f, "Logical(");
0570 hid_resolv_usage(field->logical, f); seq_printf(f, ")\n");
0571 }
0572 if (field->application) {
0573 tab(n, f);
0574 seq_printf(f, "Application(");
0575 hid_resolv_usage(field->application, f); seq_printf(f, ")\n");
0576 }
0577 tab(n, f); seq_printf(f, "Usage(%d)\n", field->maxusage);
0578 for (j = 0; j < field->maxusage; j++) {
0579 tab(n+2, f); hid_resolv_usage(field->usage[j].hid, f); seq_printf(f, "\n");
0580 }
0581 if (field->logical_minimum != field->logical_maximum) {
0582 tab(n, f); seq_printf(f, "Logical Minimum(%d)\n", field->logical_minimum);
0583 tab(n, f); seq_printf(f, "Logical Maximum(%d)\n", field->logical_maximum);
0584 }
0585 if (field->physical_minimum != field->physical_maximum) {
0586 tab(n, f); seq_printf(f, "Physical Minimum(%d)\n", field->physical_minimum);
0587 tab(n, f); seq_printf(f, "Physical Maximum(%d)\n", field->physical_maximum);
0588 }
0589 if (field->unit_exponent) {
0590 tab(n, f); seq_printf(f, "Unit Exponent(%d)\n", field->unit_exponent);
0591 }
0592 if (field->unit) {
0593 static const char *systems[5] = { "None", "SI Linear", "SI Rotation", "English Linear", "English Rotation" };
0594 static const char *units[5][8] = {
0595 { "None", "None", "None", "None", "None", "None", "None", "None" },
0596 { "None", "Centimeter", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
0597 { "None", "Radians", "Gram", "Seconds", "Kelvin", "Ampere", "Candela", "None" },
0598 { "None", "Inch", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" },
0599 { "None", "Degrees", "Slug", "Seconds", "Fahrenheit", "Ampere", "Candela", "None" }
0600 };
0601
0602 int i;
0603 int sys;
0604 __u32 data = field->unit;
0605
0606
0607 sys = data & 0xf;
0608 data >>= 4;
0609
0610 if(sys > 4) {
0611 tab(n, f); seq_printf(f, "Unit(Invalid)\n");
0612 }
0613 else {
0614 int earlier_unit = 0;
0615
0616 tab(n, f); seq_printf(f, "Unit(%s : ", systems[sys]);
0617
0618 for (i=1 ; i<sizeof(__u32)*2 ; i++) {
0619 char nibble = data & 0xf;
0620 data >>= 4;
0621 if (nibble != 0) {
0622 if(earlier_unit++ > 0)
0623 seq_printf(f, "*");
0624 seq_printf(f, "%s", units[sys][i]);
0625 if(nibble != 1) {
0626
0627
0628 int val = nibble & 0x7;
0629 if(nibble & 0x08)
0630 val = -((0x7 & ~val) +1);
0631 seq_printf(f, "^%d", val);
0632 }
0633 }
0634 }
0635 seq_printf(f, ")\n");
0636 }
0637 }
0638 tab(n, f); seq_printf(f, "Report Size(%u)\n", field->report_size);
0639 tab(n, f); seq_printf(f, "Report Count(%u)\n", field->report_count);
0640 tab(n, f); seq_printf(f, "Report Offset(%u)\n", field->report_offset);
0641
0642 tab(n, f); seq_printf(f, "Flags( ");
0643 j = field->flags;
0644 seq_printf(f, "%s", HID_MAIN_ITEM_CONSTANT & j ? "Constant " : "");
0645 seq_printf(f, "%s", HID_MAIN_ITEM_VARIABLE & j ? "Variable " : "Array ");
0646 seq_printf(f, "%s", HID_MAIN_ITEM_RELATIVE & j ? "Relative " : "Absolute ");
0647 seq_printf(f, "%s", HID_MAIN_ITEM_WRAP & j ? "Wrap " : "");
0648 seq_printf(f, "%s", HID_MAIN_ITEM_NONLINEAR & j ? "NonLinear " : "");
0649 seq_printf(f, "%s", HID_MAIN_ITEM_NO_PREFERRED & j ? "NoPreferredState " : "");
0650 seq_printf(f, "%s", HID_MAIN_ITEM_NULL_STATE & j ? "NullState " : "");
0651 seq_printf(f, "%s", HID_MAIN_ITEM_VOLATILE & j ? "Volatile " : "");
0652 seq_printf(f, "%s", HID_MAIN_ITEM_BUFFERED_BYTE & j ? "BufferedByte " : "");
0653 seq_printf(f, ")\n");
0654 }
0655 EXPORT_SYMBOL_GPL(hid_dump_field);
0656
0657 void hid_dump_device(struct hid_device *device, struct seq_file *f)
0658 {
0659 struct hid_report_enum *report_enum;
0660 struct hid_report *report;
0661 struct list_head *list;
0662 unsigned i,k;
0663 static const char *table[] = {"INPUT", "OUTPUT", "FEATURE"};
0664
0665 for (i = 0; i < HID_REPORT_TYPES; i++) {
0666 report_enum = device->report_enum + i;
0667 list = report_enum->report_list.next;
0668 while (list != &report_enum->report_list) {
0669 report = (struct hid_report *) list;
0670 tab(2, f);
0671 seq_printf(f, "%s", table[i]);
0672 if (report->id)
0673 seq_printf(f, "(%d)", report->id);
0674 seq_printf(f, "[%s]", table[report->type]);
0675 seq_printf(f, "\n");
0676 for (k = 0; k < report->maxfield; k++) {
0677 tab(4, f);
0678 seq_printf(f, "Field(%d)\n", k);
0679 hid_dump_field(report->field[k], 6, f);
0680 }
0681 list = list->next;
0682 }
0683 }
0684 }
0685 EXPORT_SYMBOL_GPL(hid_dump_device);
0686
0687
0688 void hid_debug_event(struct hid_device *hdev, char *buf)
0689 {
0690 struct hid_debug_list *list;
0691 unsigned long flags;
0692
0693 spin_lock_irqsave(&hdev->debug_list_lock, flags);
0694 list_for_each_entry(list, &hdev->debug_list, node)
0695 kfifo_in(&list->hid_debug_fifo, buf, strlen(buf));
0696 spin_unlock_irqrestore(&hdev->debug_list_lock, flags);
0697
0698 wake_up_interruptible(&hdev->debug_wait);
0699 }
0700 EXPORT_SYMBOL_GPL(hid_debug_event);
0701
0702 void hid_dump_report(struct hid_device *hid, int type, u8 *data,
0703 int size)
0704 {
0705 struct hid_report_enum *report_enum;
0706 char *buf;
0707 unsigned int i;
0708
0709 buf = kmalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);
0710
0711 if (!buf)
0712 return;
0713
0714 report_enum = hid->report_enum + type;
0715
0716
0717 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
0718 "\nreport (size %u) (%snumbered) = ", size,
0719 report_enum->numbered ? "" : "un");
0720 hid_debug_event(hid, buf);
0721
0722 for (i = 0; i < size; i++) {
0723 snprintf(buf, HID_DEBUG_BUFSIZE - 1,
0724 " %02x", data[i]);
0725 hid_debug_event(hid, buf);
0726 }
0727 hid_debug_event(hid, "\n");
0728 kfree(buf);
0729 }
0730 EXPORT_SYMBOL_GPL(hid_dump_report);
0731
0732 void hid_dump_input(struct hid_device *hdev, struct hid_usage *usage, __s32 value)
0733 {
0734 char *buf;
0735 int len;
0736
0737 buf = hid_resolv_usage(usage->hid, NULL);
0738 if (!buf)
0739 return;
0740 len = strlen(buf);
0741 snprintf(buf + len, HID_DEBUG_BUFSIZE - len - 1, " = %d\n", value);
0742
0743 hid_debug_event(hdev, buf);
0744
0745 kfree(buf);
0746 wake_up_interruptible(&hdev->debug_wait);
0747 }
0748 EXPORT_SYMBOL_GPL(hid_dump_input);
0749
0750 static const char *events[EV_MAX + 1] = {
0751 [EV_SYN] = "Sync", [EV_KEY] = "Key",
0752 [EV_REL] = "Relative", [EV_ABS] = "Absolute",
0753 [EV_MSC] = "Misc", [EV_LED] = "LED",
0754 [EV_SND] = "Sound", [EV_REP] = "Repeat",
0755 [EV_FF] = "ForceFeedback", [EV_PWR] = "Power",
0756 [EV_FF_STATUS] = "ForceFeedbackStatus",
0757 };
0758
0759 static const char *syncs[3] = {
0760 [SYN_REPORT] = "Report", [SYN_CONFIG] = "Config",
0761 [SYN_MT_REPORT] = "MT Report",
0762 };
0763
0764 static const char *keys[KEY_MAX + 1] = {
0765 [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc",
0766 [KEY_1] = "1", [KEY_2] = "2",
0767 [KEY_3] = "3", [KEY_4] = "4",
0768 [KEY_5] = "5", [KEY_6] = "6",
0769 [KEY_7] = "7", [KEY_8] = "8",
0770 [KEY_9] = "9", [KEY_0] = "0",
0771 [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal",
0772 [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab",
0773 [KEY_Q] = "Q", [KEY_W] = "W",
0774 [KEY_E] = "E", [KEY_R] = "R",
0775 [KEY_T] = "T", [KEY_Y] = "Y",
0776 [KEY_U] = "U", [KEY_I] = "I",
0777 [KEY_O] = "O", [KEY_P] = "P",
0778 [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace",
0779 [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl",
0780 [KEY_A] = "A", [KEY_S] = "S",
0781 [KEY_D] = "D", [KEY_F] = "F",
0782 [KEY_G] = "G", [KEY_H] = "H",
0783 [KEY_J] = "J", [KEY_K] = "K",
0784 [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon",
0785 [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave",
0786 [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash",
0787 [KEY_Z] = "Z", [KEY_X] = "X",
0788 [KEY_C] = "C", [KEY_V] = "V",
0789 [KEY_B] = "B", [KEY_N] = "N",
0790 [KEY_M] = "M", [KEY_COMMA] = "Comma",
0791 [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash",
0792 [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk",
0793 [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space",
0794 [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1",
0795 [KEY_F2] = "F2", [KEY_F3] = "F3",
0796 [KEY_F4] = "F4", [KEY_F5] = "F5",
0797 [KEY_F6] = "F6", [KEY_F7] = "F7",
0798 [KEY_F8] = "F8", [KEY_F9] = "F9",
0799 [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock",
0800 [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7",
0801 [KEY_KP8] = "KP8", [KEY_KP9] = "KP9",
0802 [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4",
0803 [KEY_KP5] = "KP5", [KEY_KP6] = "KP6",
0804 [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1",
0805 [KEY_KP2] = "KP2", [KEY_KP3] = "KP3",
0806 [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot",
0807 [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd",
0808 [KEY_F11] = "F11", [KEY_F12] = "F12",
0809 [KEY_RO] = "RO", [KEY_KATAKANA] = "Katakana",
0810 [KEY_HIRAGANA] = "HIRAGANA", [KEY_HENKAN] = "Henkan",
0811 [KEY_KATAKANAHIRAGANA] = "Katakana/Hiragana", [KEY_MUHENKAN] = "Muhenkan",
0812 [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter",
0813 [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash",
0814 [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt",
0815 [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home",
0816 [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp",
0817 [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right",
0818 [KEY_END] = "End", [KEY_DOWN] = "Down",
0819 [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert",
0820 [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro",
0821 [KEY_MUTE] = "Mute", [KEY_VOLUMEDOWN] = "VolumeDown",
0822 [KEY_VOLUMEUP] = "VolumeUp", [KEY_POWER] = "Power",
0823 [KEY_KPEQUAL] = "KPEqual", [KEY_KPPLUSMINUS] = "KPPlusMinus",
0824 [KEY_PAUSE] = "Pause", [KEY_KPCOMMA] = "KPComma",
0825 [KEY_HANGUEL] = "Hangeul", [KEY_HANJA] = "Hanja",
0826 [KEY_YEN] = "Yen", [KEY_LEFTMETA] = "LeftMeta",
0827 [KEY_RIGHTMETA] = "RightMeta", [KEY_COMPOSE] = "Compose",
0828 [KEY_STOP] = "Stop", [KEY_AGAIN] = "Again",
0829 [KEY_PROPS] = "Props", [KEY_UNDO] = "Undo",
0830 [KEY_FRONT] = "Front", [KEY_COPY] = "Copy",
0831 [KEY_OPEN] = "Open", [KEY_PASTE] = "Paste",
0832 [KEY_FIND] = "Find", [KEY_CUT] = "Cut",
0833 [KEY_HELP] = "Help", [KEY_MENU] = "Menu",
0834 [KEY_CALC] = "Calc", [KEY_SETUP] = "Setup",
0835 [KEY_SLEEP] = "Sleep", [KEY_WAKEUP] = "WakeUp",
0836 [KEY_FILE] = "File", [KEY_SENDFILE] = "SendFile",
0837 [KEY_DELETEFILE] = "DeleteFile", [KEY_XFER] = "X-fer",
0838 [KEY_PROG1] = "Prog1", [KEY_PROG2] = "Prog2",
0839 [KEY_WWW] = "WWW", [KEY_MSDOS] = "MSDOS",
0840 [KEY_COFFEE] = "Coffee", [KEY_ROTATE_DISPLAY] = "RotateDisplay",
0841 [KEY_CYCLEWINDOWS] = "CycleWindows", [KEY_MAIL] = "Mail",
0842 [KEY_BOOKMARKS] = "Bookmarks", [KEY_COMPUTER] = "Computer",
0843 [KEY_BACK] = "Back", [KEY_FORWARD] = "Forward",
0844 [KEY_CLOSECD] = "CloseCD", [KEY_EJECTCD] = "EjectCD",
0845 [KEY_EJECTCLOSECD] = "EjectCloseCD", [KEY_NEXTSONG] = "NextSong",
0846 [KEY_PLAYPAUSE] = "PlayPause", [KEY_PREVIOUSSONG] = "PreviousSong",
0847 [KEY_STOPCD] = "StopCD", [KEY_RECORD] = "Record",
0848 [KEY_REWIND] = "Rewind", [KEY_PHONE] = "Phone",
0849 [KEY_ISO] = "ISOKey", [KEY_CONFIG] = "Config",
0850 [KEY_HOMEPAGE] = "HomePage", [KEY_REFRESH] = "Refresh",
0851 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
0852 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
0853 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
0854 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
0855 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
0856 [KEY_F14] = "F14", [KEY_F15] = "F15",
0857 [KEY_F16] = "F16", [KEY_F17] = "F17",
0858 [KEY_F18] = "F18", [KEY_F19] = "F19",
0859 [KEY_F20] = "F20", [KEY_F21] = "F21",
0860 [KEY_F22] = "F22", [KEY_F23] = "F23",
0861 [KEY_F24] = "F24", [KEY_PLAYCD] = "PlayCD",
0862 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
0863 [KEY_PROG4] = "Prog4",
0864 [KEY_ALL_APPLICATIONS] = "AllApplications",
0865 [KEY_SUSPEND] = "Suspend",
0866 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
0867 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
0868 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
0869 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
0870 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
0871 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
0872 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
0873 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
0874 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
0875 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
0876 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
0877 [BTN_DPAD_UP] = "BtnDPadUp", [BTN_DPAD_DOWN] = "BtnDPadDown",
0878 [BTN_DPAD_LEFT] = "BtnDPadLeft", [BTN_DPAD_RIGHT] = "BtnDPadRight",
0879 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
0880 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
0881 [BTN_4] = "Btn4", [BTN_5] = "Btn5",
0882 [BTN_6] = "Btn6", [BTN_7] = "Btn7",
0883 [BTN_8] = "Btn8", [BTN_9] = "Btn9",
0884 [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn",
0885 [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn",
0886 [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn",
0887 [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn",
0888 [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn",
0889 [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn",
0890 [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn",
0891 [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2",
0892 [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4",
0893 [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6",
0894 [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA",
0895 [BTN_B] = "BtnB", [BTN_C] = "BtnC",
0896 [BTN_X] = "BtnX", [BTN_Y] = "BtnY",
0897 [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL",
0898 [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2",
0899 [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect",
0900 [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode",
0901 [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR",
0902 [BTN_TOOL_PEN] = "ToolPen", [BTN_TOOL_RUBBER] = "ToolRubber",
0903 [BTN_TOOL_BRUSH] = "ToolBrush", [BTN_TOOL_PENCIL] = "ToolPencil",
0904 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
0905 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
0906 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
0907 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
0908 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_TOOL_QUADTAP] = "ToolQuadrupleTap",
0909 [BTN_GEAR_DOWN] = "WheelBtn",
0910 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
0911 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
0912 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
0913 [KEY_OPTION] = "Option", [KEY_INFO] = "Info",
0914 [KEY_TIME] = "Time", [KEY_VENDOR] = "Vendor",
0915 [KEY_ARCHIVE] = "Archive", [KEY_PROGRAM] = "Program",
0916 [KEY_CHANNEL] = "Channel", [KEY_FAVORITES] = "Favorites",
0917 [KEY_EPG] = "EPG", [KEY_PVR] = "PVR",
0918 [KEY_MHP] = "MHP", [KEY_LANGUAGE] = "Language",
0919 [KEY_TITLE] = "Title", [KEY_SUBTITLE] = "Subtitle",
0920 [KEY_ANGLE] = "Angle", [KEY_ZOOM] = "Zoom",
0921 [KEY_MODE] = "Mode", [KEY_KEYBOARD] = "Keyboard",
0922 [KEY_SCREEN] = "Screen", [KEY_PC] = "PC",
0923 [KEY_TV] = "TV", [KEY_TV2] = "TV2",
0924 [KEY_VCR] = "VCR", [KEY_VCR2] = "VCR2",
0925 [KEY_SAT] = "Sat", [KEY_SAT2] = "Sat2",
0926 [KEY_CD] = "CD", [KEY_TAPE] = "Tape",
0927 [KEY_RADIO] = "Radio", [KEY_TUNER] = "Tuner",
0928 [KEY_PLAYER] = "Player", [KEY_TEXT] = "Text",
0929 [KEY_DVD] = "DVD", [KEY_AUX] = "Aux",
0930 [KEY_MP3] = "MP3", [KEY_AUDIO] = "Audio",
0931 [KEY_VIDEO] = "Video", [KEY_DIRECTORY] = "Directory",
0932 [KEY_LIST] = "List", [KEY_MEMO] = "Memo",
0933 [KEY_CALENDAR] = "Calendar", [KEY_RED] = "Red",
0934 [KEY_GREEN] = "Green", [KEY_YELLOW] = "Yellow",
0935 [KEY_BLUE] = "Blue", [KEY_CHANNELUP] = "ChannelUp",
0936 [KEY_CHANNELDOWN] = "ChannelDown", [KEY_FIRST] = "First",
0937 [KEY_LAST] = "Last", [KEY_AB] = "AB",
0938 [KEY_NEXT] = "Next", [KEY_RESTART] = "Restart",
0939 [KEY_SLOW] = "Slow", [KEY_SHUFFLE] = "Shuffle",
0940 [KEY_BREAK] = "Break", [KEY_PREVIOUS] = "Previous",
0941 [KEY_DIGITS] = "Digits", [KEY_TEEN] = "TEEN",
0942 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
0943 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
0944 [KEY_DEL_LINE] = "DeleteLine",
0945 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
0946 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
0947 [KEY_DOCUMENTS] = "Documents", [KEY_SPELLCHECK] = "SpellCheck",
0948 [KEY_LOGOFF] = "Logoff",
0949 [KEY_FN] = "Fn", [KEY_FN_ESC] = "Fn+ESC",
0950 [KEY_FN_1] = "Fn+1", [KEY_FN_2] = "Fn+2",
0951 [KEY_FN_B] = "Fn+B", [KEY_FN_D] = "Fn+D",
0952 [KEY_FN_E] = "Fn+E", [KEY_FN_F] = "Fn+F",
0953 [KEY_FN_S] = "Fn+S",
0954 [KEY_FN_F1] = "Fn+F1", [KEY_FN_F2] = "Fn+F2",
0955 [KEY_FN_F3] = "Fn+F3", [KEY_FN_F4] = "Fn+F4",
0956 [KEY_FN_F5] = "Fn+F5", [KEY_FN_F6] = "Fn+F6",
0957 [KEY_FN_F7] = "Fn+F7", [KEY_FN_F8] = "Fn+F8",
0958 [KEY_FN_F9] = "Fn+F9", [KEY_FN_F10] = "Fn+F10",
0959 [KEY_FN_F11] = "Fn+F11", [KEY_FN_F12] = "Fn+F12",
0960 [KEY_KBDILLUMTOGGLE] = "KbdIlluminationToggle",
0961 [KEY_KBDILLUMDOWN] = "KbdIlluminationDown",
0962 [KEY_KBDILLUMUP] = "KbdIlluminationUp",
0963 [KEY_SWITCHVIDEOMODE] = "SwitchVideoMode",
0964 [KEY_BUTTONCONFIG] = "ButtonConfig",
0965 [KEY_TASKMANAGER] = "TaskManager",
0966 [KEY_JOURNAL] = "Journal",
0967 [KEY_CONTROLPANEL] = "ControlPanel",
0968 [KEY_APPSELECT] = "AppSelect",
0969 [KEY_SCREENSAVER] = "ScreenSaver",
0970 [KEY_VOICECOMMAND] = "VoiceCommand",
0971 [KEY_ASSISTANT] = "Assistant",
0972 [KEY_KBD_LAYOUT_NEXT] = "KbdLayoutNext",
0973 [KEY_EMOJI_PICKER] = "EmojiPicker",
0974 [KEY_DICTATE] = "Dictate",
0975 [KEY_BRIGHTNESS_MIN] = "BrightnessMin",
0976 [KEY_BRIGHTNESS_MAX] = "BrightnessMax",
0977 [KEY_BRIGHTNESS_AUTO] = "BrightnessAuto",
0978 [KEY_KBDINPUTASSIST_PREV] = "KbdInputAssistPrev",
0979 [KEY_KBDINPUTASSIST_NEXT] = "KbdInputAssistNext",
0980 [KEY_KBDINPUTASSIST_PREVGROUP] = "KbdInputAssistPrevGroup",
0981 [KEY_KBDINPUTASSIST_NEXTGROUP] = "KbdInputAssistNextGroup",
0982 [KEY_KBDINPUTASSIST_ACCEPT] = "KbdInputAssistAccept",
0983 [KEY_KBDINPUTASSIST_CANCEL] = "KbdInputAssistCancel",
0984 [KEY_MACRO1] = "Macro1", [KEY_MACRO2] = "Macro2", [KEY_MACRO3] = "Macro3",
0985 [KEY_MACRO4] = "Macro4", [KEY_MACRO5] = "Macro5", [KEY_MACRO6] = "Macro6",
0986 [KEY_MACRO7] = "Macro7", [KEY_MACRO8] = "Macro8", [KEY_MACRO9] = "Macro9",
0987 [KEY_MACRO10] = "Macro10", [KEY_MACRO11] = "Macro11", [KEY_MACRO12] = "Macro12",
0988 [KEY_MACRO13] = "Macro13", [KEY_MACRO14] = "Macro14", [KEY_MACRO15] = "Macro15",
0989 [KEY_MACRO16] = "Macro16", [KEY_MACRO17] = "Macro17", [KEY_MACRO18] = "Macro18",
0990 [KEY_MACRO19] = "Macro19", [KEY_MACRO20] = "Macro20", [KEY_MACRO21] = "Macro21",
0991 [KEY_MACRO22] = "Macro22", [KEY_MACRO23] = "Macro23", [KEY_MACRO24] = "Macro24",
0992 [KEY_MACRO25] = "Macro25", [KEY_MACRO26] = "Macro26", [KEY_MACRO27] = "Macro27",
0993 [KEY_MACRO28] = "Macro28", [KEY_MACRO29] = "Macro29", [KEY_MACRO30] = "Macro30",
0994 };
0995
0996 static const char *relatives[REL_MAX + 1] = {
0997 [REL_X] = "X", [REL_Y] = "Y",
0998 [REL_Z] = "Z", [REL_RX] = "Rx",
0999 [REL_RY] = "Ry", [REL_RZ] = "Rz",
1000 [REL_HWHEEL] = "HWheel", [REL_DIAL] = "Dial",
1001 [REL_WHEEL] = "Wheel", [REL_MISC] = "Misc",
1002 };
1003
1004 static const char *absolutes[ABS_CNT] = {
1005 [ABS_X] = "X", [ABS_Y] = "Y",
1006 [ABS_Z] = "Z", [ABS_RX] = "Rx",
1007 [ABS_RY] = "Ry", [ABS_RZ] = "Rz",
1008 [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder",
1009 [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas",
1010 [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X",
1011 [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X",
1012 [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X",
1013 [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X",
1014 [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure",
1015 [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt",
1016 [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth",
1017 [ABS_VOLUME] = "Volume", [ABS_MISC] = "Misc",
1018 [ABS_MT_TOUCH_MAJOR] = "MTMajor",
1019 [ABS_MT_TOUCH_MINOR] = "MTMinor",
1020 [ABS_MT_WIDTH_MAJOR] = "MTMajorW",
1021 [ABS_MT_WIDTH_MINOR] = "MTMinorW",
1022 [ABS_MT_ORIENTATION] = "MTOrientation",
1023 [ABS_MT_POSITION_X] = "MTPositionX",
1024 [ABS_MT_POSITION_Y] = "MTPositionY",
1025 [ABS_MT_TOOL_TYPE] = "MTToolType",
1026 [ABS_MT_BLOB_ID] = "MTBlobID",
1027 };
1028
1029 static const char *misc[MSC_MAX + 1] = {
1030 [MSC_SERIAL] = "Serial", [MSC_PULSELED] = "Pulseled",
1031 [MSC_GESTURE] = "Gesture", [MSC_RAW] = "RawData"
1032 };
1033
1034 static const char *leds[LED_MAX + 1] = {
1035 [LED_NUML] = "NumLock", [LED_CAPSL] = "CapsLock",
1036 [LED_SCROLLL] = "ScrollLock", [LED_COMPOSE] = "Compose",
1037 [LED_KANA] = "Kana", [LED_SLEEP] = "Sleep",
1038 [LED_SUSPEND] = "Suspend", [LED_MUTE] = "Mute",
1039 [LED_MISC] = "Misc",
1040 };
1041
1042 static const char *repeats[REP_MAX + 1] = {
1043 [REP_DELAY] = "Delay", [REP_PERIOD] = "Period"
1044 };
1045
1046 static const char *sounds[SND_MAX + 1] = {
1047 [SND_CLICK] = "Click", [SND_BELL] = "Bell",
1048 [SND_TONE] = "Tone"
1049 };
1050
1051 static const char **names[EV_MAX + 1] = {
1052 [EV_SYN] = syncs, [EV_KEY] = keys,
1053 [EV_REL] = relatives, [EV_ABS] = absolutes,
1054 [EV_MSC] = misc, [EV_LED] = leds,
1055 [EV_SND] = sounds, [EV_REP] = repeats,
1056 };
1057
1058 static void hid_resolv_event(__u8 type, __u16 code, struct seq_file *f)
1059 {
1060 seq_printf(f, "%s.%s", events[type] ? events[type] : "?",
1061 names[type] ? (names[type][code] ? names[type][code] : "?") : "?");
1062 }
1063
1064 static void hid_dump_input_mapping(struct hid_device *hid, struct seq_file *f)
1065 {
1066 int i, j, k;
1067 struct hid_report *report;
1068 struct hid_usage *usage;
1069
1070 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
1071 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
1072 for (i = 0; i < report->maxfield; i++) {
1073 for ( j = 0; j < report->field[i]->maxusage; j++) {
1074 usage = report->field[i]->usage + j;
1075 hid_resolv_usage(usage->hid, f);
1076 seq_printf(f, " ---> ");
1077 hid_resolv_event(usage->type, usage->code, f);
1078 seq_printf(f, "\n");
1079 }
1080 }
1081 }
1082 }
1083
1084 }
1085
1086 static int hid_debug_rdesc_show(struct seq_file *f, void *p)
1087 {
1088 struct hid_device *hdev = f->private;
1089 const __u8 *rdesc = hdev->rdesc;
1090 unsigned rsize = hdev->rsize;
1091 int i;
1092
1093 if (!rdesc) {
1094 rdesc = hdev->dev_rdesc;
1095 rsize = hdev->dev_rsize;
1096 }
1097
1098
1099 for (i = 0; i < rsize; i++)
1100 seq_printf(f, "%02x ", rdesc[i]);
1101 seq_printf(f, "\n\n");
1102
1103
1104 if (down_interruptible(&hdev->driver_input_lock))
1105 return 0;
1106
1107 hid_dump_device(hdev, f);
1108 seq_printf(f, "\n");
1109 hid_dump_input_mapping(hdev, f);
1110
1111 up(&hdev->driver_input_lock);
1112
1113 return 0;
1114 }
1115
1116 static int hid_debug_events_open(struct inode *inode, struct file *file)
1117 {
1118 int err = 0;
1119 struct hid_debug_list *list;
1120 unsigned long flags;
1121
1122 if (!(list = kzalloc(sizeof(struct hid_debug_list), GFP_KERNEL))) {
1123 err = -ENOMEM;
1124 goto out;
1125 }
1126
1127 err = kfifo_alloc(&list->hid_debug_fifo, HID_DEBUG_FIFOSIZE, GFP_KERNEL);
1128 if (err) {
1129 kfree(list);
1130 goto out;
1131 }
1132 list->hdev = (struct hid_device *) inode->i_private;
1133 file->private_data = list;
1134 mutex_init(&list->read_mutex);
1135
1136 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
1137 list_add_tail(&list->node, &list->hdev->debug_list);
1138 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
1139
1140 out:
1141 return err;
1142 }
1143
1144 static ssize_t hid_debug_events_read(struct file *file, char __user *buffer,
1145 size_t count, loff_t *ppos)
1146 {
1147 struct hid_debug_list *list = file->private_data;
1148 int ret = 0, copied;
1149 DECLARE_WAITQUEUE(wait, current);
1150
1151 mutex_lock(&list->read_mutex);
1152 if (kfifo_is_empty(&list->hid_debug_fifo)) {
1153 add_wait_queue(&list->hdev->debug_wait, &wait);
1154 set_current_state(TASK_INTERRUPTIBLE);
1155
1156 while (kfifo_is_empty(&list->hid_debug_fifo)) {
1157 if (signal_pending(current)) {
1158 ret = -ERESTARTSYS;
1159 break;
1160 }
1161
1162
1163
1164
1165
1166
1167 if (!list->hdev || !list->hdev->debug) {
1168 ret = -EIO;
1169 set_current_state(TASK_RUNNING);
1170 goto out;
1171 }
1172
1173 if (file->f_flags & O_NONBLOCK) {
1174 ret = -EAGAIN;
1175 break;
1176 }
1177
1178
1179 mutex_unlock(&list->read_mutex);
1180 schedule();
1181 mutex_lock(&list->read_mutex);
1182 set_current_state(TASK_INTERRUPTIBLE);
1183 }
1184
1185 __set_current_state(TASK_RUNNING);
1186 remove_wait_queue(&list->hdev->debug_wait, &wait);
1187
1188 if (ret)
1189 goto out;
1190 }
1191
1192
1193
1194
1195 ret = kfifo_to_user(&list->hid_debug_fifo, buffer, count, &copied);
1196 if (ret)
1197 goto out;
1198 ret = copied;
1199 out:
1200 mutex_unlock(&list->read_mutex);
1201 return ret;
1202 }
1203
1204 static __poll_t hid_debug_events_poll(struct file *file, poll_table *wait)
1205 {
1206 struct hid_debug_list *list = file->private_data;
1207
1208 poll_wait(file, &list->hdev->debug_wait, wait);
1209 if (!kfifo_is_empty(&list->hid_debug_fifo))
1210 return EPOLLIN | EPOLLRDNORM;
1211 if (!list->hdev->debug)
1212 return EPOLLERR | EPOLLHUP;
1213 return 0;
1214 }
1215
1216 static int hid_debug_events_release(struct inode *inode, struct file *file)
1217 {
1218 struct hid_debug_list *list = file->private_data;
1219 unsigned long flags;
1220
1221 spin_lock_irqsave(&list->hdev->debug_list_lock, flags);
1222 list_del(&list->node);
1223 spin_unlock_irqrestore(&list->hdev->debug_list_lock, flags);
1224 kfifo_free(&list->hid_debug_fifo);
1225 kfree(list);
1226
1227 return 0;
1228 }
1229
1230 DEFINE_SHOW_ATTRIBUTE(hid_debug_rdesc);
1231
1232 static const struct file_operations hid_debug_events_fops = {
1233 .owner = THIS_MODULE,
1234 .open = hid_debug_events_open,
1235 .read = hid_debug_events_read,
1236 .poll = hid_debug_events_poll,
1237 .release = hid_debug_events_release,
1238 .llseek = noop_llseek,
1239 };
1240
1241
1242 void hid_debug_register(struct hid_device *hdev, const char *name)
1243 {
1244 hdev->debug_dir = debugfs_create_dir(name, hid_debug_root);
1245 hdev->debug_rdesc = debugfs_create_file("rdesc", 0400,
1246 hdev->debug_dir, hdev, &hid_debug_rdesc_fops);
1247 hdev->debug_events = debugfs_create_file("events", 0400,
1248 hdev->debug_dir, hdev, &hid_debug_events_fops);
1249 hdev->debug = 1;
1250 }
1251
1252 void hid_debug_unregister(struct hid_device *hdev)
1253 {
1254 hdev->debug = 0;
1255 wake_up_interruptible(&hdev->debug_wait);
1256 debugfs_remove(hdev->debug_rdesc);
1257 debugfs_remove(hdev->debug_events);
1258 debugfs_remove(hdev->debug_dir);
1259 }
1260
1261 void hid_debug_init(void)
1262 {
1263 hid_debug_root = debugfs_create_dir("hid", NULL);
1264 }
1265
1266 void hid_debug_exit(void)
1267 {
1268 debugfs_remove_recursive(hid_debug_root);
1269 }