Created
November 7, 2023 19:59
-
-
Save jigpu/4fa5f59a2c37ba0e9026d48dc0c4e137 to your computer and use it in GitHub Desktop.
AWK script to make some usbmon events a bit more readable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AWK script to annotate output from usbmon | |
# | |
# Usage: `awk -f usbmon-annotate.awk < usbmon.log` | |
# | |
# Output: If possible, each line of usbmon output will have a human- | |
# readable description of what it is printed out immediately before | |
# the usbmon line itself. | |
# | |
# For example, the following INPUT: | |
# | |
# ffffffbcd6b0f300 272301286 S Ci:1:001:0 s a3 00 0000 0001 0004 4 < | |
# ffffffbcd6b0f300 272301387 C Ci:1:001:0 0 4 = 07050000 | |
# ffffffbcc3ca1a00 272301412 S Ii:1:001:1 -115:2048 4 < | |
# ffffffbcc3ca1a00 272330034 C Ii:1:001:1 0:2048 1 = 02 | |
# | |
# Will produce the following OUTPUT: | |
# | |
# Hub: GET_STATUS (Port) Port=0001 | |
# ffffffbcd6b0f300 272301286 S Ci:1:001:0 s a3 00 0000 0001 0004 4 < | |
# ffffffbcd6b0f300 272301387 C Ci:1:001:0 0 4 = 07050000 | |
# INTERRUPT SUBMIT EP=1, Status=-EINPROGRESS | |
# ffffffbcc3ca1a00 272301412 S Ii:1:001:1 -115:2048 4 < | |
# INTERRUPT CALLBACK EP=1, Status=0 | |
# ffffffbcc3ca1a00 272330034 C Ii:1:001:1 0:2048 1 = 02 | |
function errno(i) | |
{ | |
if (i == -115) { return "-EINPROGRESS" } | |
if (i == -108) { return "-ESHUTDOWN" } | |
if (i == -2) { return "-ENOENT" } | |
return i | |
} | |
{ | |
EP = substr($4,10,1) | |
wValue = $8; wValueHi=substr(wValue,1,2); wValueLo=substr(wValue,3,2) | |
wIndex = $9; wIndexHi=substr(wIndex,1,2); wIndexLo=substr(wIndex,3,2) | |
} | |
/:0 s 80 00 / {print "Device: GET_STATUS"} | |
/:0 s 81 00 / {print "Interface: GET_STATUS"} | |
/:0 s 82 00 / {print "Endpoint: GET_STATUS"} | |
/:0 s 00 01 / {print "Device: CLEAR_FEATURE Feature=" wValue ", EP=" wIndex} | |
/:0 s 01 01 / {print "Interface: CLEAR_FEATURE Feature=" wValue ", EP=" wIndex} | |
/:0 s 02 01 / {print "Endpoint: CLEAR_FEATURE Feature=" wValue ", EP=" wIndex} | |
/:0 s 00 03 / {print "Device: SET_FEATURE Feature=" wValue ", Options=" substr(wIndex,1,1) ", EP=" substr(wIndex,2,1)} | |
/:0 s 01 03 / {print "Interface: SET_FEATURE Feature=" wValue ", Options=" substr(wIndex,1,1) ", EP=" substr(wIndex,2,1)} | |
/:0 s 02 03 / {print "Endpoint: SET_FEATURE Feature=" wValue ", Options=" substr(wIndex,1,1) ", EP=" substr(wIndex,2,1)} | |
/:0 s 00 05 / {print "Device: SET_ADDRESS Addr=" wValue} | |
/:0 s 80 06 01/ {print "Device: GET_DESCRIPTOR Type=Device, Index=" wValueLo} | |
/:0 s 80 06 02/ {print "Device: GET_DESCRIPTOR Type=Configuration, Index=" wValueLo} | |
/:0 s 80 06 03/ {print "Device: GET_DESCRIPTOR Type=String, Index=" wValueLo} | |
/:0 s 80 06 04/ {print "Device: GET_DESCRIPTOR Type=Interface, Index=" wValueLo} | |
/:0 s 80 06 05/ {print "Device: GET_DESCRIPTOR Type=Endpoint, Index=" wValueLo} | |
/:0 s 80 06 06/ {print "Device: GET_DESCRIPTOR Type=Reserved(06), Index=" wValueLo} | |
/:0 s 80 06 07/ {print "Device: GET_DESCRIPTOR Type=Reserved(07), Index=" wValueLo} | |
/:0 s 80 06 08/ {print "Device: GET_DESCRIPTOR Type=INTERFACE_POWER, Index=" wValueLo} | |
/:0 s 80 06 09/ {print "Device: GET_DESCRIPTOR Type=OTG, Index=" wValueLo} | |
/:0 s 80 06 0a/ {print "Device: GET_DESCRIPTOR Type=Debug, Index=" wValueLo} | |
/:0 s 80 06 0b/ {print "Device: GET_DESCRIPTOR Type=INTERFACE_ASSOCIATION, Index=" wValueLo} | |
/:0 s 80 06 0f/ {print "Device: GET_DESCRIPTOR Type=BOS, Index=" wValueLo} | |
/:0 s 80 06 10/ {print "Device: GET_DESCRIPTOR Type=DEVICE_CAPABILITY, Index=" wValueLo} | |
/:0 s 80 06 30/ {print "Device: GET_DESCRIPTOR Type=SUPERSPEED_USB_ENDPOINT_COMPANION, Index=" wValueLo} | |
/:0 s 80 06 31/ {print "Device: GET_DESCRIPTOR Type=SUPERSPEEDPLUS_ISOCHRONOUS_ENDPOINT_COMPANION, Index=" wValueLo} | |
/:0 s 00 07 01/ {print "Device: SET_DESCRIPTOR Type=Device, Index=" wValueLo} | |
/:0 s 00 07 02/ {print "Device: SET_DESCRIPTOR Type=Configuration, Index=" wValueLo} | |
/:0 s 00 07 03/ {print "Device: SET_DESCRIPTOR Type=String, Index=" wValueLo} | |
/:0 s 00 07 04/ {print "Device: SET_DESCRIPTOR Type=Interface, Index=" wValueLo} | |
/:0 s 00 07 05/ {print "Device: SET_DESCRIPTOR Type=Endpoint, Index=" wValueLo} | |
/:0 s 00 07 06/ {print "Device: SET_DESCRIPTOR Type=Reserved(06), Index=" wValueLo} | |
/:0 s 00 07 07/ {print "Device: SET_DESCRIPTOR Type=Reserved(07), Index=" wValueLo} | |
/:0 s 00 07 08/ {print "Device: SET_DESCRIPTOR Type=INTERFACE_POWER, Index=" wValueLo} | |
/:0 s 00 07 09/ {print "Device: SET_DESCRIPTOR Type=OTG, Index=" wValueLo} | |
/:0 s 00 07 0a/ {print "Device: SET_DESCRIPTOR Type=Debug, Index=" wValueLo} | |
/:0 s 00 07 0b/ {print "Device: SET_DESCRIPTOR Type=INTERFACE_ASSOCIATION, Index=" wValueLo} | |
/:0 s 00 07 0f/ {print "Device: SET_DESCRIPTOR Type=BOS, Index=" wValueLo} | |
/:0 s 00 07 10/ {print "Device: SET_DESCRIPTOR Type=DEVICE_CAPABILITY, Index=" wValueLo} | |
/:0 s 00 07 30/ {print "Device: SET_DESCRIPTOR Type=SUPERSPEED_USB_ENDPOINT_COMPANION, Index=" wValueLo} | |
/:0 s 00 07 31/ {print "Device: SET_DESCRIPTOR Type=SUPERSPEEDPLUS_ISOCHRONOUS_ENDPOINT_COMPANION, Index=" wValueLo} | |
/:0 s 80 08 / {print "Device: GET_CONFIGURATION"} | |
/:0 s 00 09 / {print "Device: SET_CONFIGURATION Config=" wValue} | |
/:0 s 81 0a / {print "Device: GET_INTERFACE Interface=" wIndex} | |
/:0 s 01 0b / {print "Device: SET_INTERFACE AltSetting=" wValue ", Interface=" wIndex} | |
/:0 s 82 12 / {print "Endpoint: SYNCH_FRAME EP=" wIndex} | |
/:0 s 20 01 / { print "Hub: CLEAR_FEATURE (Hub) Feature=" wValue} | |
/:0 s 23 01 / { print "Hub: CLEAR_FEATURE (Port) Feature=" wValue ", Port=" wIndex} | |
/:0 s a0 06 / { print "Hub: GET_DESCRIPTOR Type=" wValue} | |
/:0 s a0 00 / { print "Hub: GET_STATUS (Hub)"} | |
/:0 s a3 00 / { print "Hub: GET_STATUS (Port) Port=" wIndex} | |
/:0 s a3 0d / { print "Hub: GET_PORT_ERR_COUNT Port=" wIndex} | |
/:0 s 20 07 / { print "Hub: SET_DESCRIPTOR Type=" wValue} | |
/:0 s 20 03 / { print "Hub: SET_FEATURE (Hub) Feature=" wValue} | |
/:0 s 20 0c / { print "Hub: SET_HUB_DEPTH Depth=" wValue} | |
/:0 s 23 03 / { print "Hub: SET_FEATURE (Port) Feature=" wValue} | |
/:0 s 81 06 21/ {print "HID: GET_DESCRIPTOR Type=HID, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s 81 06 22/ {print "HID: GET_DESCRIPTOR Type=Report, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s 81 06 23/ {print "HID: GET_DESCRIPTOR Type=Physical, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s 01 07 21/ {print "HID: SET_DESCRIPTOR Type=HID, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s 01 07 22/ {print "HID: SET_DESCRIPTOR Type=Report, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s 01 07 23/ {print "HID: SET_DESCRIPTOR Type=Physical, Index=" wValueLo ", Interface=" wIndex} | |
/:0 s a1 01 01/ {print "HID: GET_REPORT Type=Input, ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s a1 01 02/ {print "HID: GET_REPORT Type=Output ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s a1 01 03/ {print "HID: GET_REPORT Type=Feature, ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s 21 09 01/ {print "HID: SET_REPORT Type=Input, ReportID= " wValueLo ", Interface=" wIndex} | |
/:0 s 21 09 02/ {print "HID: SET_REPORT Type=Output, ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s 21 09 03/ {print "HID: SET_REPORT Type=Feature, ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s a1 02 / {print "HID: GET_IDLE ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s 21 0a / {print "HID: SET_IDLE Duration=" wValueHi ", ReportID=" wValueLo ", Interface=" wIndex} | |
/:0 s a1 03 / {print "HID: GET_PROTOCOL" ", Interface=" wIndex} | |
/:0 s 21 0b 00/ {print "HID: SET_PROTOCOL Type=Boot" ", Interface=" wIndex} | |
/:0 s 21 0b 01/ {print "HID: SET_PROTOCOL Type=Report" ", Interface=" wIndex} | |
/S Ii:.....:. / {split($5, N, ":"); print "INTERRUPT SUBMIT EP=" EP ", Status=" errno(N[1])} | |
/C Ii:.....:. / {split($5, N, ":"); print "INTERRUPT CALLBACK EP=" EP ", Status=" errno(N[1])} | |
{print} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment