Wireshark-dev: [Wireshark-dev] lua dissector: using base.UNIT_STRING on ftypes.DOUBLE ProtoFiel

From: Dennis Lambe <dennis@xxxxxxxxxxxxxx>
Date: Mon, 20 Mar 2023 11:54:52 -0500
I am writing a dissector plugin in Lua, and I'm running into a problem
with unit strings. I'm new to Wireshark plugins and new to Lua, so I'm
not 100% sure any of what I'm doing is the right way to do it.

The protocol I'm dissecting contains fields which are transmitted as
integers, but should be adjusted by a scale and offset which may be
ints or floats. I want them displayed with unit strings. This works as
I expect it to with INT or UINT fields, but not with FLOAT or DOUBLE
fields.

When I create a new ProtoField with an INT or UINT type and include a
unit string, and then add a computed value to the tree, the unit
string appears after the value in the Packet Detail pane and in
columns created with Apply as Column, as I would expect.

```lua
field_PECCLimits1_limitPowerMax = ProtoField.new(
    "limitPowerMax", "pecclimits1.limitpowermax",
    ftypes.UINT24, {" W"}, bit.bor(base.DEC, base.UNIT_STRING), nil, ""
)
-- ... then, in the dissector
    local item = subtree:add(field_PECCLimits1_limitPowerMax, range(4,
2), value)
```

However, when I do the same thing with a FLOAT or DOUBLE ProtoField,
the value appears in the Packet Detail pane and in columns *without*
the unit string appended.

```lua
field_PECCLimits1_limitVoltageMax = ProtoField.new(
    "limitVoltageMax", "pecclimits1.limitvoltagemax",
    ftypes.DOUBLE, {" V"}, base.UNIT_STRING, nil, ""
)
-- ... then, in the dissector
   local item = subtree:add(field_PECCLimits1_limitVoltageMax,
range(2, 2), value)
```

I can see from the output of `tshark -G values` that the unit strings
are successfully associated with the fields, but they aren't showing
up in the UI.
U       pecclimits1.limitvoltagemax      V      (no plural)
U       pecclimits1.limitpowermax        W      (no plural)

I've attached a complete working example of code that demonstrates
these symptoms, a packet that can be dissected using it, and a
screenshot of what I'm seeing.

Wireshark Version 4.0.4 (v4.0.4-0-gea14d468d9ca) with Lua 5.2.4.

Can anybody shed some light on this mystery?

Thanks
-- 
Dennis Lambe (He/Him)
Lead Firmware Engineer
sparkcharge.io

Attachment: wireshark-lua-float-unit-string-bug-example-packet.png
Description: PNG image

Attachment: wireshark_pecclimits1.lua
Description: Binary data

Attachment: wireshark-lua-float-unit-string-bug-example-packet.pcapng
Description: Binary data