mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-17 05:38:33 +03:00
python sniffer host side
This commit is contained in:
63
usb_application/sniffer.py
Executable file
63
usb_application/sniffer.py
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import usb.core
|
||||
import usb.util
|
||||
import sys
|
||||
|
||||
|
||||
def find_dev():
|
||||
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
|
||||
if dev is None:
|
||||
raise ValueError("Device not found")
|
||||
else:
|
||||
print("Found device")
|
||||
return dev
|
||||
|
||||
def find_eps(dev):
|
||||
dev.set_configuration()
|
||||
|
||||
cfg = dev.get_active_configuration()
|
||||
print("Active config: ")
|
||||
print(cfg)
|
||||
intf = cfg[(0,0)]
|
||||
|
||||
ep_in = usb.util.find_descriptor(
|
||||
intf,
|
||||
custom_match = \
|
||||
lambda e: \
|
||||
usb.util.endpoint_direction(e.bEndpointAddress) == \
|
||||
usb.util.ENDPOINT_IN)
|
||||
|
||||
assert ep_in is not None
|
||||
|
||||
ep_out = usb.util.find_descriptor(
|
||||
intf,
|
||||
custom_match = \
|
||||
lambda e: \
|
||||
usb.util.endpoint_direction(e.bEndpointAddress) == \
|
||||
usb.util.ENDPOINT_OUT)
|
||||
|
||||
assert ep_out is not None
|
||||
print("****")
|
||||
print(ep_in)
|
||||
print(ep_out)
|
||||
return (ep_in, ep_out)
|
||||
|
||||
# main code
|
||||
def main():
|
||||
dev = find_dev()
|
||||
# (epi, epo) = find_eps(dev)
|
||||
|
||||
while True:
|
||||
#ep_out.write("Hello")
|
||||
try:
|
||||
ans = dev.read(0x82, 64, 1000)
|
||||
print("".join("%02x " % b for b in ans))
|
||||
except KeyboardInterrupt:
|
||||
print("Bye")
|
||||
sys.exit()
|
||||
except:
|
||||
print("Timeout")
|
||||
# print(ep_in.read(1, 5000));
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user