Commit Graph

788 Commits

Author SHA1 Message Date
Aleksander Morgado b464e60f4b AUTHORS: update 2014-12-24 13:42:20 +01:00
Aleksander Morgado 07235c4060 build: distribute the udev rules template regardless of --enable-qmi-username
Include the udev rules template in the distribution tarball even if the
`--enable-qmi-username' option wasn't specified.
2014-12-19 20:36:05 +01:00
Roshan Pius bec32bd8d5 libqmi-glib,proxy: Change ownership of QMI devices to the configured user.
Adding a udev rule to change ownership of all QMI devices to the
configured user specified at compile time using --enable-qmi-username
flag.
2014-12-19 20:32:12 +01:00
Aleksander Morgado b84db57fe2 qmi-codegen: fix printing contents of structs with fixed sized strings
If the fixed sized string contains no characters or is shorter than the explicit
size, NUL bytes will be included. If we try to append exactly the size of the
string, we'll end up with embedded NULs in our string to print, so the actual
output will be cut, even if the string is longer after the embedded NUL bytes.

E.g.:

    >>>>>> TLV:
    >>>>>>   type       = "GERAN Info" (0x10)
    >>>>>>   length     = 61
    >>>>>>   value      = 00:00:00:00:00:00:00:00:00:00:00:00:FF:FF:FF:FF:28:00:03:7D:6F:00:00:32:F4:51:B3:00:4D:00:11:2A:00:8A:3C:00:00:32:F4:51:B3:00:63:00:30:14:00:89:3C:00:00:32:F4:51:B3:00:59:00:11:0D:00
    >>>>>>   translated = [ cell_id = '0' plmn = '

With this fix, we avoid this by explicitly finishing ourselves the fixed sized
string with a NUL byte, and then adding the C string as the non-fixed sized
ones, i.e. until the first NUL byte is found.

E.g.:

    >>>>>> TLV:
    >>>>>>   type       = "GERAN Info" (0x10)
    >>>>>>   length     = 61
    >>>>>>   value      = 00:00:00:00:00:00:00:00:00:00:00:00:FF:FF:FF:FF:28:00:03:7D:6F:00:00:32:F4:51:B3:00:4D:00:11:2A:00:8A:3C:00:00:32:F4:51:B3:00:63:00:30:14:00:89:3C:00:00:32:F4:51:B3:00:59:00:11:0D:00
    >>>>>>   translated = [ cell_id = '0' plmn = '' lac = '0' geran_absolute_rf_channel_number = '0' base_station_identity_code = '0' timing_advance = '4294967295' rx_level = '40' cell = '{ [0] = '[ cell_id = '28541' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '77' base_station_identity_code = '17' rx_level = '42' ] ' [1] = '[ cell_id = '15498' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '99' base_station_identity_code = '48' rx_level = '20' ] ' [2] = '[ cell_id = '15497' plmn = '2\xf4Q' lac = '179' geran_absolute_rf_channel_number = '89' base_station_identity_code = '17' rx_level = '13' ] '}' ]
2014-12-12 10:22:44 +01:00
Aleksander Morgado b9c3701e33 qmi-codegen: fix public struct type generation
This change triggers an API break.

When building structs to be included in the public header, we were just relying
on using the 'public_format' of each variable. This is an error, as the variable
may be more complex than just public/private. E.g. could be another struct, or
an array, or a fixed sized string, as in the example.

In particular, this bug currently affects one public type, where one of its
elements changes from being just a pointer to a string to a fixed sized array of
4 bytes.

The following type is changed from:

    typedef struct _QmiMessageNasGetCellLocationInfoOutputGeranInfoCellElement {
        guint32 cell_id;
        gchar * plmn;
        guint16 lac;
        guint16 geran_absolute_rf_channel_number;
        guint8 base_station_identity_code;
        guint16 rx_level;
    } QmiMessageNasGetCellLocationInfoOutputGeranInfoCellElement;

To:

    typedef struct _QmiMessageNasGetCellLocationInfoOutputGeranInfoCellElement {
        guint32 cell_id;
        gchar plmn[4];
        guint16 lac;
        guint16 geran_absolute_rf_channel_number;
        guint8 base_station_identity_code;
        guint16 rx_level;
    } QmiMessageNasGetCellLocationInfoOutputGeranInfoCellElement;

Thanks to Joseba Sanjuan <joseba.sanjuan@gmail.com> for finding the bug.
2014-12-12 09:21:15 +01:00
Aleksander Morgado 3853840a31 libqmi,test: new test for QMI NAS Get Cell Info with GERAN
Which currently fails:

{*LOG(error):{Qmi-FATAL-CRITICAL: qmi_message_tlv_read_fixed_size_string: assertion 'out != NULL' failed}:LOG*}

(/home/aleksander/Development/foss/libqmi/src/libqmi-glib/test/.libs/test-generated:12179): Qmi-CRITICAL **: qmi_message_tlv_read_fixed_size_string: assertion 'out != NULL' failed

Program received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff717eae0 in g_logv () from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0  0x00007ffff717eae0 in g_logv () from /usr/lib/libglib-2.0.so.0
#1  0x00007ffff717ed1f in g_log () from /usr/lib/libglib-2.0.so.0
#2  0x00007ffff7a5381e in qmi_message_tlv_read_fixed_size_string (self=0x7fffe8007d30, tlv_offset=20, offset=0x7fffffffdcc8, string_length=3, out=0x0, error=0x0) at qmi-message.c:1817
#3  0x00007ffff7acce60 in __qmi_message_nas_get_cell_location_info_response_parse (message=0x7fffe8007d30, error=0x7fffffffded8) at qmi-nas.c:26772
#4  0x00007ffff7af46fa in get_cell_location_info_ready (device=0x64e8b0, res=0x65d990, simple=0x65d920) at qmi-nas.c:47982
#5  0x00007ffff76ff6d7 in g_simple_async_result_complete () from /usr/lib/libgio-2.0.so.0
#6  0x00007ffff76ff739 in ?? () from /usr/lib/libgio-2.0.so.0
#7  0x00007ffff717791d in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#8  0x00007ffff7177cf8 in ?? () from /usr/lib/libglib-2.0.so.0
#9  0x00007ffff7178022 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#10 0x0000000000403e9b in test_fixture_loop_run (fixture=0x63c800) at test-fixture.c:321
#11 0x0000000000406da4 in test_generated_nas_get_cell_location_info (fixture=0x63c800) at test-generated.c:562
#12 0x00007ffff719d0f3 in ?? () from /usr/lib/libglib-2.0.so.0
#13 0x00007ffff719d2c2 in ?? () from /usr/lib/libglib-2.0.so.0
#14 0x00007ffff719d2c2 in ?? () from /usr/lib/libglib-2.0.so.0
#15 0x00007ffff719d2c2 in ?? () from /usr/lib/libglib-2.0.so.0
#16 0x00007ffff719d62b in g_test_run_suite () from /usr/lib/libglib-2.0.so.0
#17 0x00007ffff719d661 in g_test_run () from /usr/lib/libglib-2.0.so.0
#18 0x0000000000406ef0 in main (argc=1, argv=0x7fffffffe678) at test-generated.c:584
(gdb) fr 3
#3  0x00007ffff7acce60 in __qmi_message_nas_get_cell_location_info_response_parse (message=0x7fffe8007d30, error=0x7fffffffded8) at qmi-nas.c:26772
warning: Source file is more recent than executable.
26772	                    if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, 3, &cell_aux.plmn[0], NULL))
(gdb) p cell_aux
$1 = {cell_id = 28541, plmn = 0x0, lac = 0, geran_absolute_rf_channel_number = 0, base_station_identity_code = 0 '\000', rx_level = 0}
2014-12-12 09:14:38 +01:00
Aleksander Morgado 739fc4f183 qmi-network: fix bashisms
Equivalent to the fix done in mbim-network, see:
https://bugs.freedesktop.org/show_bug.cgi?id=87093
2014-12-08 13:58:39 +01:00
Dan Williams e80e129be7 qmi-codegen: don't mark missing optional TLVs as set
In the optional TLV case, 'tlv_error' was never set to TRUE
when the optional TLV was missing, because the return value of
qmi_message_tlv_read_init() was ignored.  This caused
"self->arg_*_set" to always be TRUE and NULL strings to be
returned to callers requesting the TLV value later.

Also prevent incorrect "Left X bytes unread when getting..."
messages caused when the TLV is missing.

This bug was found when probing a modem that does not return
an MEID TLV to DMSGetIds (because it is GSM/UMTS/LTE only),
but qmi_message_dms_get_ids_output_get_meid() returned TRUE
and a NULL 'str':

    if (qmi_message_dms_get_ids_output_get_meid (output, &str, NULL) &&
-->     str[0] != '\0' && str[0] != '0') {

Bug introduced in b143b7f6 (qmi-codegen: use the new TLV reader API).

Before:
=======

    gsize offset = 0;
    gsize init_offset;
    gboolean tlv_error = FALSE;

    init_offset = qmi_message_tlv_read_init (message, QMI_INDICATION_DMS_EVENT_REPORT_OUTPUT_TLV_POWER_STATE, NULL, NULL);
    <<<snip>>>

    /* The remaining size of the buffer needs to be 0 if we successfully read the TLV */
    if ((offset = __qmi_message_tlv_read_remaining_size (message, init_offset, offset)) > 0) {
        g_warning ("Left '%" G_GSIZE_FORMAT "' bytes unread when getting the 'Power State' TLV", offset);
    }

qmi_indication_dms_event_report_output_power_state_out:
    if (!tlv_error)
        self->arg_power_state_set = TRUE;

After:
======

    gsize offset = 0;
    gsize init_offset;

    if ((init_offset = qmi_message_tlv_read_init (message, QMI_INDICATION_DMS_EVENT_REPORT_OUTPUT_TLV_POWER_STATE, NULL, NULL)) == 0) {
        goto qmi_indication_dms_event_report_output_power_state_out;
    }
    <<<snip>>>

    /* The remaining size of the buffer needs to be 0 if we successfully read the TLV */
    if ((offset = __qmi_message_tlv_read_remaining_size (message, init_offset, offset)) > 0) {
        g_warning ("Left '%" G_GSIZE_FORMAT "' bytes unread when getting the 'Power State' TLV", offset);
    }

    self->arg_power_state_set = TRUE;

qmi_indication_dms_event_report_output_power_state_out:
    ;
2014-11-21 16:59:10 -06:00
Aleksander Morgado ea189aee8a libqmi,utils: new internal __qmi_user_allowed() method
Allows to check whether the user is allowed to use the QMI device.

Also fixes qmi_proxy_open() to make sure we always set the GError when FALSE is
returned.
2014-11-18 17:03:01 +01:00
Aleksander Morgado 5f49dfb6ed build: rename '--enable-qmi-proxy-username' to '--enable-qmi-username'
This shouldn't be a proxy-only setting. We're going to chown the QMI devices to
this specific user, so we'll re-use this setting for that as well.
2014-11-18 17:03:01 +01:00
Roshan Pius c474d34db0 libqmi-glib,proxy: add a configure flag to set the user ID of QMI proxy
Currently, the QMI proxy process assumes that it is run as root user and
that all incoming client connection users are also root.
However, it's not always preferable to run the QMI proxy as root for
security reasons. On some platforms, the QMI proxy could be constrained
to run as a less-privileged user and specially granted the permission to
access the QMI device. So, adding a compile time flag in libqmi to check
for the specified user, rather than assume it to be the root user.  If the flag
is not sent, it'll revert to the existing behaviour of checking for
user=root(i.e UID=0)
2014-11-18 17:03:01 +01:00
Volker Sobek aafe3e64ab libqmi-glib,message: fix build (fdo #86128)
The build failed because g_return_val_if_fail was used in a void
function. Use g_return_if_fail instead.

https://bugs.freedesktop.org/show_bug.cgi?id=86128
2014-11-10 15:36:22 -06:00
Aleksander Morgado bef0cdb543 dms: "UIM Get IMSI" seems to be available in DMS 1.1 already
Reported by: Torsten Hilbrich <torsten.hilbrich@secunet.com>
2014-11-10 18:28:27 +01:00
Aleksander Morgado 8526859a20 libqmi-glib: always attach timeout and idles to the thread default main context
The standard timeout/idle methods will attach the sources to the default
context, not the thread default context. So, create the GSources ourselves
and attach them to the thread default context.
2014-11-10 18:23:55 +01:00
Aleksander Morgado bcf07ba98a libqmi-glib: always attach sources to the thread default main context
If NULL is specified in g_source_attach() it will attach to the default context,
not to the thread-default one if one was given with
g_main_context_push_thread_default().

This caused that QmiDevices started in the non-main thread would still attach
their socket listening sources to the GMainContext in the main thread.
2014-11-09 21:23:42 +01:00
Aleksander Morgado b143b7f6ba qmi-codegen: use the new TLV reader API 2014-11-09 20:15:56 +01:00
Aleksander Morgado 6af6f9d1cd test,message: fix leak in unit tests 2014-11-09 20:15:56 +01:00
Aleksander Morgado ff299c7a42 libqmi-glib,utils: flag reader utils as deprecated 2014-11-09 20:15:56 +01:00
Aleksander Morgado 8c086dc705 test,message: unit tests for the reader API 2014-11-09 20:15:56 +01:00
Aleksander Morgado 809356fd95 libqmi-glib,message: new TLV reader API 2014-11-09 20:15:56 +01:00
Aleksander Morgado 75d2b34c8c libqmi-glib,utils: fix documentation when reading fixed size strings 2014-11-09 20:15:56 +01:00
Aleksander Morgado bdd4fa5445 libqmi-glib,message: use TLV builder to create response messages 2014-11-09 20:15:55 +01:00
Aleksander Morgado 4d7a31bbd3 test,message: unit tests for the QmiMessage creator methods 2014-11-09 20:15:54 +01:00
Aleksander Morgado 654ad38ad9 qmi-codegen: use the new TLV builder API 2014-11-09 20:15:28 +01:00
Aleksander Morgado 8541fa485d libqmi-glib,message: update copyright 2014-11-09 20:15:28 +01:00
Aleksander Morgado 3e03b78fc6 libqmi-glib,utils: flag writer utils as deprecated 2014-11-09 20:15:28 +01:00
Aleksander Morgado 344598ac4c libqmi-glib,message: no need to pass error when asserting 2014-11-09 20:15:28 +01:00
Aleksander Morgado 2e9bbe3186 test,message: unit tests for the builder API 2014-11-09 20:15:26 +01:00
Aleksander Morgado 7a0f48562e libqmi-glib,message: new TLV builder API 2014-11-09 20:13:52 +01:00
Aleksander Morgado ffa016d95f libqmi-glib,device: fix device initialization
Initialization ended up broken in commit ec30daa1 when the new
'device-no-file-check' property was introduced.
2014-11-09 19:29:11 +01:00
Aleksander Morgado 48d5cb540d libqmi,test: check message builder/parser for "NAS Network Scan" 2014-11-09 18:31:16 +01:00
Aleksander Morgado 1025e3c9bc libqmi,test: check message builder/parser for "DMS UIM Verify PIN" 2014-11-09 17:58:13 +01:00
Aleksander Morgado 11c76f35c5 libqmi,test: check message builder/parser for "DMS UIM Get PIN Status" 2014-11-09 17:58:13 +01:00
Aleksander Morgado 88ac76dc00 libqmi,test: don't print message contents by default in tests 2014-11-09 17:58:13 +01:00
Aleksander Morgado dd5b4a9420 libqmi,message: avoid printing error in stderr 2014-11-09 17:58:13 +01:00
Aleksander Morgado f89a9e13f2 libqmi,test: check message builder/parser for "DMS Get IDs" 2014-11-09 17:58:13 +01:00
Aleksander Morgado 496ce55c39 libqmi,test: setup testing framework to test content of generated messages 2014-11-09 17:58:13 +01:00
Aleksander Morgado 32d95f442e libqmi-glib,device: new 'device-proxy-path' property
String which specifies which is the path of the abstract socket where the proxy
is listening.
2014-11-09 17:58:13 +01:00
Aleksander Morgado e9b20296e5 libqmi-glib,device: minor indentation fixes 2014-11-09 17:38:38 +01:00
Aleksander Morgado ec30daa1c5 libqmi-glib,device: new 'device-no-file-check' property
If set to TRUE, this property will make the QmiDevice not check for the
existence and file type of the given GFile.

This is a construct write-only property, and should be only used when
building the QmiDevice with g_async_initable_new_async() explicitly (i.e. no
library helper method given).
2014-11-09 17:38:37 +01:00
Aleksander Morgado 924f5d0e5b libqmi,message: fix qmi_message_set_transaction_id() in non-CTL messages
The transaction ID in non-CTL messages wasn't being written properly when
qmi_message_set_transaction_id() was used. Internally this never happened, but
this method is part of the API, so could be a big issue for users.
2014-11-09 00:42:37 +01:00
Aleksander Morgado ce723135ca dms: "UIM Get ICCID" seems to be available in DMS 1.1 already 2014-11-07 16:46:47 +01:00
Aleksander Morgado 6f25341a6a qmicli: fix license text, it should be GPLv2+ 2014-10-30 09:08:35 +01:00
Aleksander Morgado 93a188eb81 libqmi-glib,message: avoid g_byte_array_new_take()
It will break our unit tests, which are all executed with gc-friendly. See:
https://bugzilla.gnome.org/show_bug.cgi?id=738170
2014-10-13 15:43:51 +02:00
Aleksander Morgado 7134a910b9 libqmi-glib,proxy: add missing QmiProxy documentation 2014-10-12 18:09:11 +02:00
Albert Diserholt c369598da6 libqmi-glib,proxy: fix segfault
This patch fixes a segfault caused by a race condition where an incoming
request has just been accepted and allocated, but a device for it has yet
to be opened, and an old request is closed. The checks prevent a strcmp
against unexisting devices.

https://bugs.freedesktop.org/show_bug.cgi?id=77335
2014-10-10 14:19:03 +02:00
Aleksander Morgado 451d627530 qmi-codegen: make sure expected len is 4 bytes
Suggested by Thomas Haller <thaller@redhat.com>.
2014-10-08 11:13:09 +02:00
Aleksander Morgado 150768f6bb qmi-codegen: error out if invalid array size element in JSON
Suggested by Thomas Haller <thaller@redhat.com>.
2014-10-08 11:06:26 +02:00
Thomas Haller b439d6d13e qmi-codegen: avoid buffer overlow in emit_input_tlv_add()
https://bugzilla.redhat.com/show_bug.cgi?id=1031738

Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-08 10:50:39 +02:00
Thomas Haller c744b04814 libqmi,utils: assert input buffer size when writing strings to buffer
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-08 10:37:23 +02:00