Message/TLV builder API

Aleksander Morgado aleksander at aleksander.es
Sun Nov 9 11:28:41 PST 2014


On Fri, Oct 10, 2014 at 2:13 PM, Aleksander Morgado
<aleksander at aleksander.es> wrote:
> The qmi_utils_write_{something}_to_buffer() methods are really a bit
>> error prone, as the caller needs to make sure that there is enough
>> space in the buffer to write the variable that is being written, and
>> failure to do so would make some nasty assert()s.
>>
>> I've now developed a new TLV writer API which does bounds checking and
>> error reporting, and also changed the libqmi implementation to avoid
>> relying on fixed-size stack buffers. We now rely on GByteArray to grow
>> the QmiMessage as we're adding more contents to the TLV. Note that
>> there won't be one realloc() per qmi_message_tlv_write_{something}()
>> call, as GByteArray does internally reallocs to the closest power-of-2
>> IIRC.
>>
>> This work is in the 'aleksander/tlv-api' branch in upstream git.
>>
>> This is WIP, but comments on the API are greatly appreciated. Relevant
>> commit is:
>> http://cgit.freedesktop.org/libqmi/commit/?h=aleksander/tlv-api&id=5b223047864b0ae0f423d33ea284df5b01eacb57
>>
>> I'm also going to update the TLV reader API, and end up with all those
>> qmi_utils_read/write methods deprecated in the API.
>
> Also wrote now the TLV reader API, and updated qmi-codegen with
> several changes. There is no longer TLV validation() methods before
> reading the TLV contents. Instead, we just try to read one by one the
> fields, checking for out-of-TLV reads, and flag the TLV as unavailable
> if there is any error reading.
>
> http://cgit.freedesktop.org/libqmi/log/?h=aleksander/tlv-api

After making sure that these changes didn't break the message
building/parsing logic with the new unit tests, I merged this branch
to git master. I believe the logic is much safer now, as e.g. we won't
assert() when trying to read invalid contents from a buffer (which
could happen before if malformed messages where received from the
modems).

-- 
Aleksander
https://aleksander.es


More information about the libqmi-devel mailing list