Add support for VS985 and others

The udev rules and Wireshark dissector still have idProduct hardcoded
for the time being, but lglaf.py detection logic is converted to use
heuristics instead.

Thanks to @invisiblek for testing and providing lsusb output.
This commit is contained in:
Peter Wu 2015-12-29 11:38:38 +01:00
parent e7e9036fb9
commit d26f0717a9
3 changed files with 25 additions and 4 deletions

View file

@ -95,5 +95,6 @@ end
function lglaf.init()
local usb_product = DissectorTable.get("usb.product");
usb_product:add(0x1004633e, lglaf)
usb_product:add(0x1004633e, lglaf) -- LG G3 D855
usb_product:add(0x1004627f, lglaf) -- LG G3 VS985
end

View file

@ -13,7 +13,7 @@ import argparse, logging, re, struct, sys
try: import readline
except ImportError: pass
# Try USB interface
try: import usb.core
try: import usb.core, usb.util
except ImportError: pass
# Windows registry for serial port detection
try: import winreg
@ -192,13 +192,31 @@ class FileCommunication(Communication):
class USBCommunication(Communication):
EP_IN = 0x85
EP_OUT = 3
VENDOR_ID_LG = 0x1004
# Read timeout. Set to 0 to disable timeouts
READ_TIMEOUT_MS = 0
def __init__(self):
super(USBCommunication, self).__init__()
self.usbdev = usb.core.find(idVendor=0x1004, idProduct=0x633e)
# Match device using heuristics on the interface/endpoint descriptors,
# this avoids hardcoding idProduct.
self.usbdev = usb.core.find(idVendor=self.VENDOR_ID_LG,
custom_match = self._match_device)
if self.usbdev is None:
raise RuntimeError("USB device not found")
def _match_device(self, device):
return any(
usb.util.find_descriptor(cfg, bInterfaceClass=255,
bInterfaceSubClass=255, bInterfaceProtocol=255,
custom_match=self._match_interface)
for cfg in device
)
def _match_interface(self, intf):
return intf.bNumEndpoints == 2 and all(
ep.bEndpointAddress in (self.EP_IN, self.EP_OUT) and
usb.util.endpoint_type(ep.bmAttributes) ==
usb.util.ENDPOINT_TYPE_BULK
for ep in intf
)
def _read(self, n):
# device seems to use 16 KiB buffers.
array = self.usbdev.read(self.EP_IN, 2**14, timeout=self.READ_TIMEOUT_MS)

View file

@ -1,3 +1,5 @@
# /etc/udev/rules.d/42-usb-lglaf.rules
# LG G3 in download mode
# LG G3 (D855) in download mode
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", ATTRS{idProduct}=="633e", TAG+="uaccess"
# LG G3 (VS985) in download mode
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", ATTRS{idProduct}=="627f", TAG+="uaccess"