1216 lines · 40.3 KB · C
RawDownload
// SPDX-License-Identifier: GPL-2.0-or-later/* *  (c) 1999 Andreas Gal		<gal@cs.uni-magdeburg.de> *  (c) 2000-2001 Vojtech Pavlik	<vojtech@ucw.cz> *  (c) 2007-2009 Jiri Kosina * *  HID debugging support */ /* * * Should you need to contact me, the author, you can do so either by * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail: * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/debugfs.h>#include <linux/seq_file.h>#include <linux/kfifo.h>#include <linux/sched/signal.h>#include <linux/export.h>#include <linux/slab.h>#include <linux/uaccess.h>#include <linux/poll.h> #include <linux/hid.h>#include <linux/hid-debug.h> static struct dentry *hid_debug_root; struct hid_usage_entry {	unsigned  page;	unsigned  usage;	const char     *description;}; static const struct hid_usage_entry hid_usage_table[] = {  {  0,      0, "Undefined" },  {  1,      0, "GenericDesktop" },    {0, 0x01, "Pointer"},    {0, 0x02, "Mouse"},    {0, 0x04, "Joystick"},    {0, 0x05, "GamePad"},    {0, 0x06, "Keyboard"},    {0, 0x07, "Keypad"},    {0, 0x08, "MultiAxis"},      {0, 0x30, "X"},      {0, 0x31, "Y"},      {0, 0x32, "Z"},      {0, 0x33, "Rx"},      {0, 0x34, "Ry"},      {0, 0x35, "Rz"},      {0, 0x36, "Slider"},      {0, 0x37, "Dial"},      {0, 0x38, "Wheel"},      {0, 0x39, "HatSwitch"},    {0, 0x3a, "CountedBuffer"},      {0, 0x3b, "ByteCount"},      {0, 0x3c, "MotionWakeup"},      {0, 0x3d, "Start"},      {0, 0x3e, "Select"},      {0, 0x40, "Vx"},      {0, 0x41, "Vy"},      {0, 0x42, "Vz"},      {0, 0x43, "Vbrx"},      {0, 0x44, "Vbry"},      {0, 0x45, "Vbrz"},      {0, 0x46, "Vno"},    {0, 0x80, "SystemControl"},      {0, 0x81, "SystemPowerDown"},      {0, 0x82, "SystemSleep"},      {0, 0x83, "SystemWakeUp"},      {0, 0x84, "SystemContextMenu"},      {0, 0x85, "SystemMainMenu"},      {0, 0x86, "SystemAppMenu"},      {0, 0x87, "SystemMenuHelp"},      {0, 0x88, "SystemMenuExit"},      {0, 0x89, "SystemMenuSelect"},      {0, 0x8a, "SystemMenuRight"},      {0, 0x8b, "SystemMenuLeft"},      {0, 0x8c, "SystemMenuUp"},      {0, 0x8d, "SystemMenuDown"},      {0, 0x90, "D-PadUp"},      {0, 0x91, "D-PadDown"},      {0, 0x92, "D-PadRight"},      {0, 0x93, "D-PadLeft"},  {  2, 0, "Simulation" },      {0, 0xb0, "Aileron"},      {0, 0xb1, "AileronTrim"},      {0, 0xb2, "Anti-Torque"},      {0, 0xb3, "Autopilot"},      {0, 0xb4, "Chaff"},      {0, 0xb5, "Collective"},      {0, 0xb6, "DiveBrake"},      {0, 0xb7, "ElectronicCountermeasures"},      {0, 0xb8, "Elevator"},      {0, 0xb9, "ElevatorTrim"},      {0, 0xba, "Rudder"},      {0, 0xbb, "Throttle"},      {0, 0xbc, "FlightCommunications"},      {0, 0xbd, "FlareRelease"},      {0, 0xbe, "LandingGear"},      {0, 0xbf, "ToeBrake"},  {  6, 0, "GenericDeviceControls" },      {0, 0x20, "BatteryStrength" },      {0, 0x21, "WirelessChannel" },      {0, 0x22, "WirelessID" },      {0, 0x23, "DiscoverWirelessControl" },      {0, 0x24, "SecurityCodeCharacterEntered" },      {0, 0x25, "SecurityCodeCharactedErased" },      {0, 0x26, "SecurityCodeCleared" },  {  7, 0, "Keyboard" },  {  8, 0, "LED" },      {0, 0x01, "NumLock"},      {0, 0x02, "CapsLock"},      {0, 0x03, "ScrollLock"},      {0, 0x04, "Compose"},      {0, 0x05, "Kana"},      {0, 0x4b, "GenericIndicator"},  {  9, 0, "Button" },  { 10, 0, "Ordinal" },  { 12, 0, "Consumer" },      {0, 0x238, "HorizontalWheel"},  { 13, 0, "Digitizers" },    {0, 0x01, "Digitizer"},    {0, 0x02, "Pen"},    {0, 0x03, "LightPen"},    {0, 0x04, "TouchScreen"},    {0, 0x05, "TouchPad"},    {0, 0x0e, "DeviceConfiguration"},    {0, 0x20, "Stylus"},    {0, 0x21, "Puck"},    {0, 0x22, "Finger"},    {0, 0x23, "DeviceSettings"},    {0, 0x30, "TipPressure"},    {0, 0x31, "BarrelPressure"},    {0, 0x32, "InRange"},    {0, 0x33, "Touch"},    {0, 0x34, "UnTouch"},    {0, 0x35, "Tap"},    {0, 0x39, "TabletFunctionKey"},    {0, 0x3a, "ProgramChangeKey"},    {0, 0x3c, "Invert"},    {0, 0x42, "TipSwitch"},    {0, 0x43, "SecondaryTipSwitch"},    {0, 0x44, "BarrelSwitch"},    {0, 0x45, "Eraser"},    {0, 0x46, "TabletPick"},    {0, 0x47, "Confidence"},    {0, 0x48, "Width"},    {0, 0x49, "Height"},    {0, 0x51, "ContactID"},    {0, 0x52, "InputMode"},    {0, 0x53, "DeviceIndex"},    {0, 0x54, "ContactCount"},    {0, 0x55, "ContactMaximumNumber"},    {0, 0x59, "ButtonType"},    {0, 0x5A, "SecondaryBarrelSwitch"},    {0, 0x5B, "TransducerSerialNumber"},  { 15, 0, "PhysicalInterfaceDevice" },    {0, 0x00, "Undefined"},    {0, 0x01, "Physical_Interface_Device"},      {0, 0x20, "Normal"},    {0, 0x21, "Set_Effect_Report"},      {0, 0x22, "Effect_Block_Index"},      {0, 0x23, "Parameter_Block_Offset"},      {0, 0x24, "ROM_Flag"},      {0, 0x25, "Effect_Type"},        {0, 0x26, "ET_Constant_Force"},        {0, 0x27, "ET_Ramp"},        {0, 0x28, "ET_Custom_Force_Data"},        {0, 0x30, "ET_Square"},        {0, 0x31, "ET_Sine"},        {0, 0x32, "ET_Triangle"},        {0, 0x33, "ET_Sawtooth_Up"},        {0, 0x34, "ET_Sawtooth_Down"},        {0, 0x40, "ET_Spring"},        {0, 0x41, "ET_Damper"},        {0, 0x42, "ET_Inertia"},        {0, 0x43, "ET_Friction"},      {0, 0x50, "Duration"},      {0, 0x51, "Sample_Period"},      {0, 0x52, "Gain"},      {0, 0x53, "Trigger_Button"},      {0, 0x54, "Trigger_Repeat_Interval"},      {0, 0x55, "Axes_Enable"},        {0, 0x56, "Direction_Enable"},      {0, 0x57, "Direction"},      {0, 0x58, "Type_Specific_Block_Offset"},        {0, 0x59, "Block_Type"},        {0, 0x5A, "Set_Envelope_Report"},          {0, 0x5B, "Attack_Level"},          {0, 0x5C, "Attack_Time"},          {0, 0x5D, "Fade_Level"},          {0, 0x5E, "Fade_Time"},        {0, 0x5F, "Set_Condition_Report"},        {0, 0x60, "CP_Offset"},        {0, 0x61, "Positive_Coefficient"},        {0, 0x62, "Negative_Coefficient"},        {0, 0x63, "Positive_Saturation"},        {0, 0x64, "Negative_Saturation"},        {0, 0x65, "Dead_Band"},      {0, 0x66, "Download_Force_Sample"},      {0, 0x67, "Isoch_Custom_Force_Enable"},      {0, 0x68, "Custom_Force_Data_Report"},        {0, 0x69, "Custom_Force_Data"},        {0, 0x6A, "Custom_Force_Vendor_Defined_Data"},      {0, 0x6B, "Set_Custom_Force_Report"},        {0, 0x6C, "Custom_Force_Data_Offset"},        {0, 0x6D, "Sample_Count"},      {0, 0x6E, "Set_Periodic_Report"},        {0, 0x6F, "Offset"},        {0, 0x70, "Magnitude"},        {0, 0x71, "Phase"},        {0, 0x72, "Period"},      {0, 0x73, "Set_Constant_Force_Report"},        {0, 0x74, "Set_Ramp_Force_Report"},        {0, 0x75, "Ramp_Start"},        {0, 0x76, "Ramp_End"},      {0, 0x77, "Effect_Operation_Report"},        {0, 0x78, "Effect_Operation"},          {0, 0x79, "Op_Effect_Start"},          {0, 0x7A, "Op_Effect_Start_Solo"},          {0, 0x7B, "Op_Effect_Stop"},          {0, 0x7C, "Loop_Count"},      {0, 0x7D, "Device_Gain_Report"},        {0, 0x7E, "Device_Gain"},    {0, 0x7F, "PID_Pool_Report"},      {0, 0x80, "RAM_Pool_Size"},      {0, 0x81, "ROM_Pool_Size"},      {0, 0x82, "ROM_Effect_Block_Count"},      {0, 0x83, "Simultaneous_Effects_Max"},      {0, 0x84, "Pool_Alignment"},    {0, 0x85, "PID_Pool_Move_Report"},      {0, 0x86, "Move_Source"},      {0, 0x87, "Move_Destination"},      {0, 0x88, "Move_Length"},    {0, 0x89, "PID_Block_Load_Report"},      {0, 0x8B, "Block_Load_Status"},      {0, 0x8C, "Block_Load_Success"},      {0, 0x8D, "Block_Load_Full"},      {0, 0x8E, "Block_Load_Error"},      {0, 0x8F, "Block_Handle"},      {0, 0x90, "PID_Block_Free_Report"},      {0, 0x91, "Type_Specific_Block_Handle"},    {0, 0x92, "PID_State_Report"},      {0, 0x94, "Effect_Playing"},      {0, 0x95, "PID_Device_Control_Report"},        {0, 0x96, "PID_Device_Control"},        {0, 0x97, "DC_Enable_Actuators"},        {0, 0x98, "DC_Disable_Actuators"},        {0, 0x99, "DC_Stop_All_Effects"},        {0, 0x9A, "DC_Device_Reset"},        {0, 0x9B, "DC_Device_Pause"},        {0, 0x9C, "DC_Device_Continue"},      {0, 0x9F, "Device_Paused"},      {0, 0xA0, "Actuators_Enabled"},      {0, 0xA4, "Safety_Switch"},      {0, 0xA5, "Actuator_Override_Switch"},      {0, 0xA6, "Actuator_Power"},    {0, 0xA7, "Start_Delay"},    {0, 0xA8, "Parameter_Block_Size"},    {0, 0xA9, "Device_Managed_Pool"},    {0, 0xAA, "Shared_Parameter_Blocks"},    {0, 0xAB, "Create_New_Effect_Report"},    {0, 0xAC, "RAM_Pool_Available"},  {  0x20, 0, "Sensor" },    { 0x20, 0x01, "Sensor" },    { 0x20, 0x10, "Biometric" },      { 0x20, 0x11, "BiometricHumanPresence" },      { 0x20, 0x12, "BiometricHumanProximity" },      { 0x20, 0x13, "BiometricHumanTouch" },    { 0x20, 0x20, "Electrical" },      { 0x20, 0x21, "ElectricalCapacitance" },      { 0x20, 0x22, "ElectricalCurrent" },      { 0x20, 0x23, "ElectricalPower" },      { 0x20, 0x24, "ElectricalInductance" },      { 0x20, 0x25, "ElectricalResistance" },      { 0x20, 0x26, "ElectricalVoltage" },      { 0x20, 0x27, "ElectricalPoteniometer" },      { 0x20, 0x28, "ElectricalFrequency" },      { 0x20, 0x29, "ElectricalPeriod" },    { 0x20, 0x30, "Environmental" },      { 0x20, 0x31, "EnvironmentalAtmosphericPressure" },      { 0x20, 0x32, "EnvironmentalHumidity" },      { 0x20, 0x33, "EnvironmentalTemperature" },      { 0x20, 0x34, "EnvironmentalWindDirection" },      { 0x20, 0x35, "EnvironmentalWindSpeed" },    { 0x20, 0x40, "Light" },      { 0x20, 0x41, "LightAmbientLight" },      { 0x20, 0x42, "LightConsumerInfrared" },    { 0x20, 0x50, "Location" },      { 0x20, 0x51, "LocationBroadcast" },      { 0x20, 0x52, "LocationDeadReckoning" },      { 0x20, 0x53, "LocationGPS" },      { 0x20, 0x54, "LocationLookup" },      { 0x20, 0x55, "LocationOther" },      { 0x20, 0x56, "LocationStatic" },      { 0x20, 0x57, "LocationTriangulation" },    { 0x20, 0x60, "Mechanical" },      { 0x20, 0x61, "MechanicalBooleanSwitch" },      { 0x20, 0x62, "MechanicalBooleanSwitchArray" },      { 0x20, 0x63, "MechanicalMultivalueSwitch" },      { 0x20, 0x64, "MechanicalForce" },      { 0x20, 0x65, "MechanicalPressure" },      { 0x20, 0x66, "MechanicalStrain" },      { 0x20, 0x67, "MechanicalWeight" },      { 0x20, 0x68, "MechanicalHapticVibrator" },      { 0x20, 0x69, "MechanicalHallEffectSwitch" },    { 0x20, 0x70, "Motion" },      { 0x20, 0x71, "MotionAccelerometer1D" },      { 0x20, 0x72, "MotionAccelerometer2D" },      { 0x20, 0x73, "MotionAccelerometer3D" },      { 0x20, 0x74, "MotionGyrometer1D" },      { 0x20, 0x75, "MotionGyrometer2D" },      { 0x20, 0x76, "MotionGyrometer3D" },      { 0x20, 0x77, "MotionMotionDetector" },      { 0x20, 0x78, "MotionSpeedometer" },      { 0x20, 0x79, "MotionAccelerometer" },      { 0x20, 0x7A, "MotionGyrometer" },    { 0x20, 0x80, "Orientation" },      { 0x20, 0x81, "OrientationCompass1D" },      { 0x20, 0x82, "OrientationCompass2D" },      { 0x20, 0x83, "OrientationCompass3D" },      { 0x20, 0x84, "OrientationInclinometer1D" },      { 0x20, 0x85, "OrientationInclinometer2D" },      { 0x20, 0x86, "OrientationInclinometer3D" },      { 0x20, 0x87, "OrientationDistance1D" },      { 0x20, 0x88, "OrientationDistance2D" },      { 0x20, 0x89, "OrientationDistance3D" },      { 0x20, 0x8A, "OrientationDeviceOrientation" },      { 0x20, 0x8B, "OrientationCompass" },      { 0x20, 0x8C, "OrientationInclinometer" },      { 0x20, 0x8D, "OrientationDistance" },    { 0x20, 0x90, "Scanner" },      { 0x20, 0x91, "ScannerBarcode" },      { 0x20, 0x91, "ScannerRFID" },      { 0x20, 0x91, "ScannerNFC" },    { 0x20, 0xA0, "Time" },      { 0x20, 0xA1, "TimeAlarmTimer" },      { 0x20, 0xA2, "TimeRealTimeClock" },    { 0x20, 0xE0, "Other" },      { 0x20, 0xE1, "OtherCustom" },      { 0x20, 0xE2, "OtherGeneric" },      { 0x20, 0xE3, "OtherGenericEnumerator" },  { 0x84, 0, "Power Device" },    { 0x84, 0x02, "PresentStatus" },    { 0x84, 0x03, "ChangeStatus" },    { 0x84, 0x04, "UPS" },    { 0x84, 0x05, "PowerSupply" },    { 0x84, 0x10, "BatterySystem" },    { 0x84, 0x11, "BatterySystemID" },    { 0x84, 0x12, "Battery" },    { 0x84, 0x13, "BatteryID" },    { 0x84, 0x14, "Charger" },    { 0x84, 0x15, "ChargerID" },    { 0x84, 0x16, "PowerConverter" },    { 0x84, 0x17, "PowerConverterID" },    { 0x84, 0x18, "OutletSystem" },    { 0x84, 0x19, "OutletSystemID" },    { 0x84, 0x1a, "Input" },    { 0x84, 0x1b, "InputID" },    { 0x84, 0x1c, "Output" },    { 0x84, 0x1d, "OutputID" },    { 0x84, 0x1e, "Flow" },    { 0x84, 0x1f, "FlowID" },    { 0x84, 0x20, "Outlet" },    { 0x84, 0x21, "OutletID" },    { 0x84, 0x22, "Gang" },    { 0x84, 0x24, "PowerSummary" },    { 0x84, 0x25, "PowerSummaryID" },    { 0x84, 0x30, "Voltage" },    { 0x84, 0x31, "Current" },    { 0x84, 0x32, "Frequency" },    { 0x84, 0x33, "ApparentPower" },    { 0x84, 0x35, "PercentLoad" },    { 0x84, 0x40, "ConfigVoltage" },    { 0x84, 0x41, "ConfigCurrent" },    { 0x84, 0x43, "ConfigApparentPower" },    { 0x84, 0x53, "LowVoltageTransfer" },    { 0x84, 0x54, "HighVoltageTransfer" },    { 0x84, 0x56, "DelayBeforeStartup" },    { 0x84, 0x57, "DelayBeforeShutdown" },    { 0x84, 0x58, "Test" },    { 0x84, 0x5a, "AudibleAlarmControl" },    { 0x84, 0x60, "Present" },    { 0x84, 0x61, "Good" },    { 0x84, 0x62, "InternalFailure" },    { 0x84, 0x65, "Overload" },    { 0x84, 0x66, "OverCharged" },    { 0x84, 0x67, "OverTemperature" },    { 0x84, 0x68, "ShutdownRequested" },    { 0x84, 0x69, "ShutdownImminent" },    { 0x84, 0x6b, "SwitchOn/Off" },    { 0x84, 0x6c, "Switchable" },    { 0x84, 0x6d, "Used" },    { 0x84, 0x6e, "Boost" },    { 0x84, 0x73, "CommunicationLost" },    { 0x84, 0xfd, "iManufacturer" },    { 0x84, 0xfe, "iProduct" },    { 0x84, 0xff, "iSerialNumber" },  { 0x85, 0, "Battery System" },    { 0x85, 0x01, "SMBBatteryMode" },    { 0x85, 0x02, "SMBBatteryStatus" },    { 0x85, 0x03, "SMBAlarmWarning" },    { 0x85, 0x04, "SMBChargerMode" },    { 0x85, 0x05, "SMBChargerStatus" },    { 0x85, 0x06, "SMBChargerSpecInfo" },    { 0x85, 0x07, "SMBSelectorState" },    { 0x85, 0x08, "SMBSelectorPresets" },    { 0x85, 0x09, "SMBSelectorInfo" },    { 0x85, 0x29, "RemainingCapacityLimit" },    { 0x85, 0x2c, "CapacityMode" },    { 0x85, 0x42, "BelowRemainingCapacityLimit" },    { 0x85, 0x44, "Charging" },    { 0x85, 0x45, "Discharging" },    { 0x85, 0x4b, "NeedReplacement" },    { 0x85, 0x66, "RemainingCapacity" },    { 0x85, 0x68, "RunTimeToEmpty" },    { 0x85, 0x6a, "AverageTimeToFull" },    { 0x85, 0x83, "DesignCapacity" },    { 0x85, 0x85, "ManufacturerDate" },    { 0x85, 0x89, "iDeviceChemistry" },    { 0x85, 0x8b, "Rechargeable" },    { 0x85, 0x8f, "iOEMInformation" },    { 0x85, 0x8d, "CapacityGranularity1" },    { 0x85, 0xd0, "ACPresent" },  /* pages 0xff00 to 0xffff are vendor-specific */  { 0xffff, 0, "Vendor-specific-FF" },  { 0, 0, NULL }}; /* Either output directly into simple seq_file, or (if f == NULL) * allocate a separate buffer that will then be passed to the 'events' * ringbuffer. * * This is because these functions can be called both for "one-shot" * "rdesc" while resolving, or for blocking "events". * * This holds both for resolv_usage_page() and hid_resolv_usage(). */static char *resolv_usage_page(unsigned page, struct seq_file *f) {	const struct hid_usage_entry *p;	char *buf = NULL; 	if (!f) {		buf = kzalloc(HID_DEBUG_BUFSIZE, GFP_ATOMIC);		if (!buf)			return ERR_PTR(-ENOMEM);	} 	for (p = hid_usage_table; p->description; p++)		if (p->page == page) {			if (!f) {				snprintf(buf, HID_DEBUG_BUFSIZE, "%s",						p->description);				return buf;			}			else {				seq_printf(f, "%s", p->description);				return NULL;			}		}	if (!f)		snprintf(buf, HID_DEBUG_BUFSIZE, "%04x", page);	else		seq_printf(f, "%04x", page);	return buf;} char *hid_resolv_usage(unsigned usage, struct seq_file *f) {	const struct hid_usage_entry *p;	char *buf = NULL;	int len = 0; 	buf = resolv_usage_page(usage >> 16, f);	if (IS_ERR(buf)) {		pr_err("error allocating HID debug buffer\n");		return NULL;	}  	if (!f) {		len = strlen(buf);		snprintf(buf+len, max(0, HID_DEBUG_BUFSIZE - len), ".");		len++;	}	else {		seq_printf(f, ".");	}	for (p = hid_usage_table; p->description; p++)		if (p->page == (usage >> 16)) {			for(++p; p->description && p->usage != 0; p++)				if (p->usage == (usage & 0xffff)) {					if (!f)						snprintf(buf + len,							max(0,HID_DEBUG_BUFSIZE - len - 1),							"%s", p->description);

Lines 1–500 of 1216.