blob: f4c22cc41f74c9fc081ed99fc278ef65bb6f32d2 [file] [log] [blame]
Christina Quast98369332015-03-02 16:08:40 +01001#!/usr/bin/env python3
2
3import usb.core
4import usb.util
5import sys
Christina Quast2b8a18b2015-04-12 09:31:36 +02006import array
Christina Quast98369332015-03-02 16:08:40 +01007
Christina Quast2b8a18b2015-04-12 09:31:36 +02008from constants import PHONE_RD
Christina Quast98369332015-03-02 16:08:40 +01009
10def find_dev():
11 dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
12 if dev is None:
13 raise ValueError("Device not found")
14 else:
15 print("Found device")
16 return dev
17
18def find_eps(dev):
19 dev.set_configuration()
20
21 cfg = dev.get_active_configuration()
22 print("Active config: ")
23 print(cfg)
24 intf = cfg[(0,0)]
25
26 ep_in = usb.util.find_descriptor(
27 intf,
28 custom_match = \
29 lambda e: \
30 usb.util.endpoint_direction(e.bEndpointAddress) == \
31 usb.util.ENDPOINT_IN)
32
33 assert ep_in is not None
34
35 ep_out = usb.util.find_descriptor(
36 intf,
37 custom_match = \
38 lambda e: \
39 usb.util.endpoint_direction(e.bEndpointAddress) == \
40 usb.util.ENDPOINT_OUT)
41
42 assert ep_out is not None
43 print("****")
44 print(ep_in)
45 print(ep_out)
46 return (ep_in, ep_out)
47
48# main code
Christina Quastf2582fc2015-03-06 19:09:35 +010049def sniff():
Christina Quast98369332015-03-02 16:08:40 +010050 dev = find_dev()
Christina Quast2b8a18b2015-04-12 09:31:36 +020051 ans = array.array('B', [])
Christina Quast98369332015-03-02 16:08:40 +010052
53 while True:
54 #ep_out.write("Hello")
55 try:
Christina Quast2b8a18b2015-04-12 09:31:36 +020056 ans += dev.read(PHONE_RD, 64, 1000)
Christina Quast98369332015-03-02 16:08:40 +010057 except KeyboardInterrupt:
58 print("Bye")
59 sys.exit()
Christina Quast2b8a18b2015-04-12 09:31:36 +020060 except Exception as e:
61 print e
62
63 if len(ans) >= 15:
64 print("".join("%02x " % b for b in ans))
65 ans = array.array('B', [])