summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-05-27 10:50:41 +0200
committerAleksander Morgado <aleksander@aleksander.es>2020-05-27 12:00:50 +0200
commitaedc73750a10f3bb18a72e0a9bb63863a6390c34 (patch)
tree17cdfe0fb22b90faca1a2d06f3a6d1c5e5bde883 /examples
parent8612624c1d674f9f23cd4b442060dce1d4d34873 (diff)
examples: new simple python tester for introspection support
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am1
-rw-r--r--examples/simple-tester-python/Makefile.am2
-rw-r--r--examples/simple-tester-python/README29
-rwxr-xr-xexamples/simple-tester-python/simple-tester-python102
4 files changed, 134 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..601971d
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = simple-tester-python
diff --git a/examples/simple-tester-python/Makefile.am b/examples/simple-tester-python/Makefile.am
new file mode 100644
index 0000000..81a8b07
--- /dev/null
+++ b/examples/simple-tester-python/Makefile.am
@@ -0,0 +1,2 @@
+
+EXTRA_DIST = simple-tester-python README
diff --git a/examples/simple-tester-python/README b/examples/simple-tester-python/README
new file mode 100644
index 0000000..42d8d75
--- /dev/null
+++ b/examples/simple-tester-python/README
@@ -0,0 +1,29 @@
+
+The simple-tester-python program makes use of the 'libmbim-glib' library
+through GObject Introspection.
+
+The program will:
+ * Open a connection to the mbim-proxy, or launch the mbim-proxy itself
+ if it isn't already running.
+ * Query device capabilities
+
+The output will look like this:
+
+$ ./simple-tester-python /dev/cdc-wdm0
+device type: embedded
+cellular class: gsm
+voice class: no-voice
+sim class: removable
+data class: gprs, edge, umts, hsdpa, hsupa, lte
+sms capabilities: pdu-receive, pdu-send
+control capabilities: reg-manual
+max sessions: 8
+custom data class: None
+device id: 013937003110648
+firmware info: FIH7160_V1.1_MODEM_01.1349.12
+hardware info: XMM7160_V1.1_MBIM_GNSS_NAND_RE
+
+Note that the program requires libmbim-glib to be installed in the system
+and the introspection typelibs available in the standard paths.
+
+Have fun! \ No newline at end of file
diff --git a/examples/simple-tester-python/simple-tester-python b/examples/simple-tester-python/simple-tester-python
new file mode 100755
index 0000000..0b0dc30
--- /dev/null
+++ b/examples/simple-tester-python/simple-tester-python
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 51
+# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es>
+#
+
+import sys, signal, gi
+
+gi.require_version('Mbim', '1.0')
+from gi.repository import GLib, GObject, Gio, Mbim
+
+main_loop = None
+
+def signal_handler(data):
+ main_loop.quit()
+
+def close_ready(mbimdev,result,user_data=None):
+ try:
+ mbimdev.close_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't close MBIM device: %s\n" % error.message)
+ main_loop.quit()
+
+def query_device_caps_ready(mbimdev,result,user_data=None):
+ try:
+ response = mbimdev.command_finish(result)
+ response.command_done_get_result()
+ success, devtype, cellclass, voiceclass, simclass, dataclass, smscaps, controlcaps, maxsessions, customdataclass, deviceid, firmwareinfo, hardwareinfo = response.device_caps_response_parse()
+
+ if success:
+ print("device type: %s" % Mbim.DeviceType.get_string(devtype))
+ print("cellular class: %s" % Mbim.CellularClass.build_string_from_mask(cellclass))
+ print("voice class: %s" % Mbim.VoiceClass.get_string(voiceclass))
+ print("sim class: %s" % Mbim.SimClass.build_string_from_mask(simclass))
+ print("data class: %s" % Mbim.DataClass.build_string_from_mask(dataclass))
+ print("sms capabilities: %s" % Mbim.SmsCaps.build_string_from_mask(smscaps))
+ print("control capabilities: %s" % Mbim.CtrlCaps.build_string_from_mask(controlcaps))
+ print("max sessions: %u" % maxsessions)
+ print("custom data class: %s" % customdataclass)
+ print("device id: %s" % deviceid)
+ print("firmware info: %s" % firmwareinfo)
+ print("hardware info: %s" % hardwareinfo)
+
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't run MBIM command: %s\n" % error.message)
+ main_loop.quit()
+
+ mbimdev.close(10, None, close_ready, None)
+
+def open_full_ready(mbimdev,result,user_data=None):
+ try:
+ mbimdev.open_full_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't open MBIM device: %s\n" % error.message)
+ main_loop.quit()
+
+ request = Mbim.Message.device_caps_query_new ()
+ mbimdev.command(request, 10, None, query_device_caps_ready, None)
+
+def new_ready(unused,result,user_data=None):
+ try:
+ mbimdev = Mbim.Device.new_finish(result)
+ except GLib.GError as error:
+ sys.stderr.write("Couldn't create MBIM device: %s\n" % error.message)
+ main_loop.quit()
+
+ mbimdev.open_full(Mbim.DeviceOpenFlags.PROXY, 10, None, open_full_ready, None)
+
+if __name__ == "__main__":
+
+ # Process input arguments
+ if len(sys.argv) != 2:
+ sys.stderr.write('error: wrong number of arguments\n')
+ sys.stdout.write('usage: simple-tester-python <DEVICE>\n')
+ sys.exit(1)
+
+ # Create Mbim device asynchronously
+ file = Gio.File.new_for_path(sys.argv[1])
+ Mbim.Device.new (file, None, new_ready, None)
+
+ # Main loop
+ main_loop = GLib.MainLoop()
+ GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGHUP, signal_handler, None)
+ GLib.unix_signal_add(GLib.PRIORITY_HIGH, signal.SIGTERM, signal_handler, None)
+ try:
+ main_loop.run()
+ except KeyboardInterrupt:
+ pass