ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] Dissect data on a bit-by-bit basis

From: Filipe Laíns <lains@xxxxxxxxxxxxx>
Date: Wed, 22 Jul 2020 02:04:30 +0100
Hi,

I am working on the USB HID dissector and I need to dissect data on a
bit by bit basis, instead of byte. The data structure is completely
dynamic (described by the HID descriptor) and the basic data block is
the bit. Any bit or sequence of bits can have a meaning, the data can
be completely unaligned. See the following example which shows
different fields distributed in a 2 byte packet.


0110000000011111
^^^\__^___/\_^_/
|||   |      |
|||   |      | Y axis (5 bit wide)
|||   |
|||   | X axis (8 bit wide)
|||
||| button 3
||
|| button 2
|
| button 1


What is the best way to dissect this data? I feel like I am going to
have to basically write a complicated internal wrapper around the tvb
API, and that won't even work properly in some cases.

Is modifying the tvb API to allow data control on a bit level
reasonable? I am not very aware of the internals, but as far as I can
tell that would not be trivial. Even if it is a bit complicated, is it
something that could be considered? Is USB HID the only protocol
running into this issue? I guess most stuff is aligned, but I if I had
to guess I'd a few other protocol would possibly need this finer
control.

I feel like I am opening a can of worms here, sorry about that :P

Cheers,
Filipe Laíns

Attachment: signature.asc
Description: This is a digitally signed message part