how to initialize GIOStream and GDBus Connection to cellular modem device in C with mmlib-glib

godjohnson

New Member
Joined
Sep 24, 2022
Messages
2
Reaction score
0
Credits
21
I am trying to use [mmlib-glib documentation](https://developer-old.gnome.org/libmm-glib/unstable/) to put together a program to gather cellular modem information on Linux (Ubuntu 20.04). My question is how do I establish a GIOStream, and subsequently a GDBusConnection to the device.

You will notice in the code I have a few different paths I provide to try and construct a GFile to interact with the modem, as I am uncertain how to interface with it.

How should I get a file associated with the modem, I would suspect opening a file using a serial tty device the modem is on might work, but I note modem manager states it is "ignoring" the tty devices, except for GPS. Another idea was to try and use the /org/freedesktop/... path modemmanager provides, but this has seemed to prove unsuccessful.


Steps:
1. get a GFile associated with the modem
2. construct a GIOStream to the modem with the GFile
3. construct a DBusConnection with the GIOStream
4. contruct a MMManager with the DBusConnection
5. Use MMManager to query the specific modem.




Code:
Compilation:

gcc main.c -I/usr/include/libmm-glib -I/usr/include/ModemManager -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -lglib-2.0 -lz -lgio-2.0 -lpthread -lmm-glib

Code:
#include <libmm-glib.h>
#include <gio/gio.h>
//#include <gtk/gtk.h>
#include <stdio.h>
int main (void)
{
    GDBusObjectManagerClientFlags    flags = G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE;

    //GFile * save = g_file_new_for_path("/dev/ttyUSB0");
    GFile * save = g_file_new_for_path("/dev/cdc-wdm0");

    GFileIOStream *pStream = g_file_open_readwrite(save, NULL, NULL);

    GDBusConnection *pConnection= g_dbus_connection_new_sync(pStream,
                                                      NULL, // for authent. as a server
                                                      flags,
                                                      NULL, // observer,
                                                      NULL, // cancellable,
                                                      NULL);

    MMManager  *pManager = mm_manager_new_sync(pConnection,
                      flags,
                      cancellable,
                      ppError);


    mm_manager_scan_devices_sync(pManager,
                 cancellable,
                 ppError);

    MMObject modem;

    //const gchar* pChar = mm_object_get_path(&modem);
 
    printf("end\n");
    return(0);
}


Code:
-----------------------------
  General  |              path: /org/freedesktop/ModemManager1/Modem/3
           |         device id:
  -----------------------------
  Hardware |      manufacturer: Telit
           |             model: LE910C4-NF
           | firmware revision: 25.21.660  1  [Mar 04 2021 12:00:00]
           |    carrier config: default
           |      h/w revision: 1.30
           |         supported: gsm-umts, lte
           |           current: gsm-umts, lte
           |      equipment id:
  -----------------------------
  System   |            device: /sys/devices/platform/soc@0/32c00000.bus/32e50000.usb/ci_hdrc.1/usb1/1-1/1-1.3
           |           drivers: qmi_wwan, option
           |            plugin: telit
           |      primary port: cdc-wdm0
           |             ports: cdc-wdm0 (qmi), ttyUSB0 (ignored), ttyUSB1 (gps),
           |                    ttyUSB4 (ignored), wwan0 (net)
  -----------------------------
  Status   |             state: failed
           |     failed reason: sim-missing
           |       power state: on
           |    signal quality: 0% (cached)
  -----------------------------
  Modes    |         supported: allowed: 3g; preferred: none
           |                    allowed: 4g; preferred: none
           |                    allowed: 3g, 4g; preferred: 4g
           |                    allowed: 3g, 4g; preferred: 3g
           |           current: allowed: any; preferred: none
  -----------------------------
  Bands    |         supported: utran-4, utran-5, utran-2, eutran-2, eutran-4, eutran-5,
           |                    eutran-12, eutran-13, eutran-14, eutran-66, eutran-71
  -----------------------------
  IP       |         supported: ipv4, ipv6, ipv4v6
  -----------------------------
  SIM      |    sim slot paths: slot 1: none (active)
           |                    slot 2: none
 
Last edited:

Members online


Latest posts

Top