aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-02-05 08:38:30 +0100
committerGuido Günther <agx@sigxcpu.org>2014-02-05 08:38:30 +0100
commit13ed135b9ae78c692dc359976eb8b54d0a3629b8 (patch)
treeae2ea713ad51d73980cf83db1411d6589dac5e8b /cli
parent14d771b90f5a7d3887e5e900d1fb4737477ad305 (diff)
Imported Upstream version 0.7.991upstream/0.7.991
Diffstat (limited to 'cli')
-rw-r--r--cli/Makefile.am32
-rw-r--r--cli/Makefile.in942
-rw-r--r--cli/mmcli-bearer.c391
-rw-r--r--cli/mmcli-common.c1180
-rw-r--r--cli/mmcli-common.h93
-rw-r--r--cli/mmcli-manager.c367
-rw-r--r--cli/mmcli-modem-3gpp.c565
-rw-r--r--cli/mmcli-modem-cdma.c236
-rw-r--r--cli/mmcli-modem-firmware.c333
-rw-r--r--cli/mmcli-modem-location.c589
-rw-r--r--cli/mmcli-modem-messaging.c478
-rw-r--r--cli/mmcli-modem-simple.c447
-rw-r--r--cli/mmcli-modem-time.c277
-rw-r--r--cli/mmcli-modem.c1372
-rw-r--r--cli/mmcli-sim.c482
-rw-r--r--cli/mmcli-sms.c457
-rw-r--r--cli/mmcli.c380
-rw-r--r--cli/mmcli.h128
18 files changed, 8749 insertions, 0 deletions
diff --git a/cli/Makefile.am b/cli/Makefile.am
new file mode 100644
index 0000000..12126ec
--- /dev/null
+++ b/cli/Makefile.am
@@ -0,0 +1,32 @@
+bin_PROGRAMS = mmcli
+
+mmcli_CPPFLAGS = \
+ $(MMCLI_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/include \
+ -I$(top_srcdir)/libmm-glib \
+ -I${top_srcdir}/libmm-glib/generated \
+ -I${top_builddir}/libmm-glib/generated
+
+mmcli_SOURCES = \
+ mmcli.h \
+ mmcli.c \
+ mmcli-common.h \
+ mmcli-common.c \
+ mmcli-manager.c \
+ mmcli-modem.c \
+ mmcli-modem-3gpp.c \
+ mmcli-modem-cdma.c \
+ mmcli-modem-simple.c \
+ mmcli-modem-location.c \
+ mmcli-modem-messaging.c \
+ mmcli-modem-time.c \
+ mmcli-modem-firmware.c \
+ mmcli-bearer.c \
+ mmcli-sim.c \
+ mmcli-sms.c
+
+mmcli_LDADD = \
+ $(MMCLI_LIBS) \
+ $(top_builddir)/libmm-glib/libmm-glib.la
diff --git a/cli/Makefile.in b/cli/Makefile.in
new file mode 100644
index 0000000..1cd45c6
--- /dev/null
+++ b/cli/Makefile.in
@@ -0,0 +1,942 @@
+# Makefile.in generated by automake 1.13.2 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
+am__make_running_with_option = \
+ case $${target_option-} in \
+ ?) ;; \
+ *) echo "am__make_running_with_option: internal error: invalid" \
+ "target option '$${target_option-}' specified" >&2; \
+ exit 1;; \
+ esac; \
+ has_opt=no; \
+ sane_makeflags=$$MAKEFLAGS; \
+ if $(am__is_gnu_make); then \
+ sane_makeflags=$$MFLAGS; \
+ else \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ bs=\\; \
+ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
+ esac; \
+ fi; \
+ skip_next=no; \
+ strip_trailopt () \
+ { \
+ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+ }; \
+ for flg in $$sane_makeflags; do \
+ test $$skip_next = yes && { skip_next=no; continue; }; \
+ case $$flg in \
+ *=*|--*) continue;; \
+ -*I) strip_trailopt 'I'; skip_next=yes;; \
+ -*I?*) strip_trailopt 'I';; \
+ -*O) strip_trailopt 'O'; skip_next=yes;; \
+ -*O?*) strip_trailopt 'O';; \
+ -*l) strip_trailopt 'l'; skip_next=yes;; \
+ -*l?*) strip_trailopt 'l';; \
+ -[dEDm]) skip_next=yes;; \
+ -[JT]) skip_next=yes;; \
+ esac; \
+ case $$flg in \
+ *$$target_option*) has_opt=yes; break;; \
+ esac; \
+ done; \
+ test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = mmcli$(EXEEXT)
+subdir = cli
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ $(top_srcdir)/depcomp
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
+ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gtk-doc.m4 \
+ $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \
+ $(top_srcdir)/m4/intltool.m4 $(top_srcdir)/m4/lib-ld.m4 \
+ $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+ $(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
+ $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_mmcli_OBJECTS = mmcli-mmcli.$(OBJEXT) mmcli-mmcli-common.$(OBJEXT) \
+ mmcli-mmcli-manager.$(OBJEXT) mmcli-mmcli-modem.$(OBJEXT) \
+ mmcli-mmcli-modem-3gpp.$(OBJEXT) \
+ mmcli-mmcli-modem-cdma.$(OBJEXT) \
+ mmcli-mmcli-modem-simple.$(OBJEXT) \
+ mmcli-mmcli-modem-location.$(OBJEXT) \
+ mmcli-mmcli-modem-messaging.$(OBJEXT) \
+ mmcli-mmcli-modem-time.$(OBJEXT) \
+ mmcli-mmcli-modem-firmware.$(OBJEXT) \
+ mmcli-mmcli-bearer.$(OBJEXT) mmcli-mmcli-sim.$(OBJEXT) \
+ mmcli-mmcli-sms.$(OBJEXT)
+mmcli_OBJECTS = $(am_mmcli_OBJECTS)
+am__DEPENDENCIES_1 =
+mmcli_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+ $(top_builddir)/libmm-glib/libmm-glib.la
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 =
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo " GEN " $@;
+am__v_GEN_1 =
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 =
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo " CC " $@;
+am__v_CC_1 =
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo " CCLD " $@;
+am__v_CCLD_1 =
+SOURCES = $(mmcli_SOURCES)
+DIST_SOURCES = $(mmcli_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates. Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+ BEGIN { nonempty = 0; } \
+ { items[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique. This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+ list='$(am__tagged_files)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALL_LINGUAS = @ALL_LINGUAS@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CATALOGS = @CATALOGS@
+CATOBJEXT = @CATOBJEXT@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DATADIRNAME = @DATADIRNAME@
+DBUS_SYS_DIR = @DBUS_SYS_DIR@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
+GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
+GLIB_GENMARSHAL = @GLIB_GENMARSHAL@
+GLIB_MKENUMS = @GLIB_MKENUMS@
+GMOFILES = @GMOFILES@
+GMSGFMT = @GMSGFMT@
+GMSGFMT_015 = @GMSGFMT_015@
+GREP = @GREP@
+GTKDOC_CHECK = @GTKDOC_CHECK@
+GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
+GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
+GTKDOC_MKPDF = @GTKDOC_MKPDF@
+GTKDOC_REBASE = @GTKDOC_REBASE@
+GUDEV_CFLAGS = @GUDEV_CFLAGS@
+GUDEV_LIBS = @GUDEV_LIBS@
+HTML_DIR = @HTML_DIR@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INSTOBJEXT = @INSTOBJEXT@
+INTLLIBS = @INTLLIBS@
+INTLTOOL_EXTRACT = @INTLTOOL_EXTRACT@
+INTLTOOL_MERGE = @INTLTOOL_MERGE@
+INTLTOOL_PERL = @INTLTOOL_PERL@
+INTLTOOL_UPDATE = @INTLTOOL_UPDATE@
+INTLTOOL_V_MERGE = @INTLTOOL_V_MERGE@
+INTLTOOL_V_MERGE_OPTIONS = @INTLTOOL_V_MERGE_OPTIONS@
+INTLTOOL__v_MERGE_ = @INTLTOOL__v_MERGE_@
+INTLTOOL__v_MERGE_0 = @INTLTOOL__v_MERGE_0@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBMM_GLIB_CFLAGS = @LIBMM_GLIB_CFLAGS@
+LIBMM_GLIB_LIBS = @LIBMM_GLIB_LIBS@
+LIBMM_LIBS = @LIBMM_LIBS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MBIM_CFLAGS = @MBIM_CFLAGS@
+MBIM_LIBS = @MBIM_LIBS@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MMCLI_CFLAGS = @MMCLI_CFLAGS@
+MMCLI_LIBS = @MMCLI_LIBS@
+MM_CFLAGS = @MM_CFLAGS@
+MM_LIBS = @MM_LIBS@
+MSGFMT = @MSGFMT@
+MSGFMT_015 = @MSGFMT_015@
+MSGFMT_OPTS = @MSGFMT_OPTS@
+MSGMERGE = @MSGMERGE@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+POFILES = @POFILES@
+POLKIT_CFLAGS = @POLKIT_CFLAGS@
+POLKIT_LIBS = @POLKIT_LIBS@
+POSUB = @POSUB@
+PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@
+PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@
+PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
+QMI_CFLAGS = @QMI_CFLAGS@
+QMI_LIBS = @QMI_LIBS@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+SYSTEMD_UNIT_DIR = @SYSTEMD_UNIT_DIR@
+UDEV_BASE_DIR = @UDEV_BASE_DIR@
+USE_NLS = @USE_NLS@
+VERSION = @VERSION@
+XGETTEXT = @XGETTEXT@
+XGETTEXT_015 = @XGETTEXT_015@
+XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+intltool__v_merge_options_ = @intltool__v_merge_options_@
+intltool__v_merge_options_0 = @intltool__v_merge_options_0@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+mmcli_CPPFLAGS = \
+ $(MMCLI_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/include \
+ -I$(top_srcdir)/libmm-glib \
+ -I${top_srcdir}/libmm-glib/generated \
+ -I${top_builddir}/libmm-glib/generated
+
+mmcli_SOURCES = \
+ mmcli.h \
+ mmcli.c \
+ mmcli-common.h \
+ mmcli-common.c \
+ mmcli-manager.c \
+ mmcli-modem.c \
+ mmcli-modem-3gpp.c \
+ mmcli-modem-cdma.c \
+ mmcli-modem-simple.c \
+ mmcli-modem-location.c \
+ mmcli-modem-messaging.c \
+ mmcli-modem-time.c \
+ mmcli-modem-firmware.c \
+ mmcli-bearer.c \
+ mmcli-sim.c \
+ mmcli-sms.c
+
+mmcli_LDADD = \
+ $(MMCLI_LIBS) \
+ $(top_builddir)/libmm-glib/libmm-glib.la
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu cli/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --gnu cli/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
+ fi; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p \
+ || test -f $$p1 \
+ ; then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' \
+ -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' \
+ `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+
+mmcli$(EXEEXT): $(mmcli_OBJECTS) $(mmcli_DEPENDENCIES) $(EXTRA_mmcli_DEPENDENCIES)
+ @rm -f mmcli$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(mmcli_OBJECTS) $(mmcli_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-bearer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-common.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-manager.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-3gpp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-cdma.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-firmware.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-location.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-messaging.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-simple.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem-time.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-modem.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-sim.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli-sms.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mmcli-mmcli.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
+
+mmcli-mmcli.o: mmcli.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli.Tpo -c -o mmcli-mmcli.o `test -f 'mmcli.c' || echo '$(srcdir)/'`mmcli.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli.Tpo $(DEPDIR)/mmcli-mmcli.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli.c' object='mmcli-mmcli.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli.o `test -f 'mmcli.c' || echo '$(srcdir)/'`mmcli.c
+
+mmcli-mmcli.obj: mmcli.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli.Tpo -c -o mmcli-mmcli.obj `if test -f 'mmcli.c'; then $(CYGPATH_W) 'mmcli.c'; else $(CYGPATH_W) '$(srcdir)/mmcli.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli.Tpo $(DEPDIR)/mmcli-mmcli.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli.c' object='mmcli-mmcli.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli.obj `if test -f 'mmcli.c'; then $(CYGPATH_W) 'mmcli.c'; else $(CYGPATH_W) '$(srcdir)/mmcli.c'; fi`
+
+mmcli-mmcli-common.o: mmcli-common.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-common.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-common.Tpo -c -o mmcli-mmcli-common.o `test -f 'mmcli-common.c' || echo '$(srcdir)/'`mmcli-common.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-common.Tpo $(DEPDIR)/mmcli-mmcli-common.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-common.c' object='mmcli-mmcli-common.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-common.o `test -f 'mmcli-common.c' || echo '$(srcdir)/'`mmcli-common.c
+
+mmcli-mmcli-common.obj: mmcli-common.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-common.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-common.Tpo -c -o mmcli-mmcli-common.obj `if test -f 'mmcli-common.c'; then $(CYGPATH_W) 'mmcli-common.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-common.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-common.Tpo $(DEPDIR)/mmcli-mmcli-common.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-common.c' object='mmcli-mmcli-common.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-common.obj `if test -f 'mmcli-common.c'; then $(CYGPATH_W) 'mmcli-common.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-common.c'; fi`
+
+mmcli-mmcli-manager.o: mmcli-manager.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-manager.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-manager.Tpo -c -o mmcli-mmcli-manager.o `test -f 'mmcli-manager.c' || echo '$(srcdir)/'`mmcli-manager.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-manager.Tpo $(DEPDIR)/mmcli-mmcli-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-manager.c' object='mmcli-mmcli-manager.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-manager.o `test -f 'mmcli-manager.c' || echo '$(srcdir)/'`mmcli-manager.c
+
+mmcli-mmcli-manager.obj: mmcli-manager.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-manager.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-manager.Tpo -c -o mmcli-mmcli-manager.obj `if test -f 'mmcli-manager.c'; then $(CYGPATH_W) 'mmcli-manager.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-manager.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-manager.Tpo $(DEPDIR)/mmcli-mmcli-manager.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-manager.c' object='mmcli-mmcli-manager.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-manager.obj `if test -f 'mmcli-manager.c'; then $(CYGPATH_W) 'mmcli-manager.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-manager.c'; fi`
+
+mmcli-mmcli-modem.o: mmcli-modem.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem.Tpo -c -o mmcli-mmcli-modem.o `test -f 'mmcli-modem.c' || echo '$(srcdir)/'`mmcli-modem.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem.Tpo $(DEPDIR)/mmcli-mmcli-modem.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem.c' object='mmcli-mmcli-modem.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem.o `test -f 'mmcli-modem.c' || echo '$(srcdir)/'`mmcli-modem.c
+
+mmcli-mmcli-modem.obj: mmcli-modem.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem.Tpo -c -o mmcli-mmcli-modem.obj `if test -f 'mmcli-modem.c'; then $(CYGPATH_W) 'mmcli-modem.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem.Tpo $(DEPDIR)/mmcli-mmcli-modem.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem.c' object='mmcli-mmcli-modem.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem.obj `if test -f 'mmcli-modem.c'; then $(CYGPATH_W) 'mmcli-modem.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem.c'; fi`
+
+mmcli-mmcli-modem-3gpp.o: mmcli-modem-3gpp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-3gpp.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-3gpp.Tpo -c -o mmcli-mmcli-modem-3gpp.o `test -f 'mmcli-modem-3gpp.c' || echo '$(srcdir)/'`mmcli-modem-3gpp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-3gpp.Tpo $(DEPDIR)/mmcli-mmcli-modem-3gpp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-3gpp.c' object='mmcli-mmcli-modem-3gpp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-3gpp.o `test -f 'mmcli-modem-3gpp.c' || echo '$(srcdir)/'`mmcli-modem-3gpp.c
+
+mmcli-mmcli-modem-3gpp.obj: mmcli-modem-3gpp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-3gpp.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-3gpp.Tpo -c -o mmcli-mmcli-modem-3gpp.obj `if test -f 'mmcli-modem-3gpp.c'; then $(CYGPATH_W) 'mmcli-modem-3gpp.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-3gpp.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-3gpp.Tpo $(DEPDIR)/mmcli-mmcli-modem-3gpp.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-3gpp.c' object='mmcli-mmcli-modem-3gpp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-3gpp.obj `if test -f 'mmcli-modem-3gpp.c'; then $(CYGPATH_W) 'mmcli-modem-3gpp.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-3gpp.c'; fi`
+
+mmcli-mmcli-modem-cdma.o: mmcli-modem-cdma.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-cdma.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-cdma.Tpo -c -o mmcli-mmcli-modem-cdma.o `test -f 'mmcli-modem-cdma.c' || echo '$(srcdir)/'`mmcli-modem-cdma.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-cdma.Tpo $(DEPDIR)/mmcli-mmcli-modem-cdma.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-cdma.c' object='mmcli-mmcli-modem-cdma.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-cdma.o `test -f 'mmcli-modem-cdma.c' || echo '$(srcdir)/'`mmcli-modem-cdma.c
+
+mmcli-mmcli-modem-cdma.obj: mmcli-modem-cdma.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-cdma.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-cdma.Tpo -c -o mmcli-mmcli-modem-cdma.obj `if test -f 'mmcli-modem-cdma.c'; then $(CYGPATH_W) 'mmcli-modem-cdma.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-cdma.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-cdma.Tpo $(DEPDIR)/mmcli-mmcli-modem-cdma.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-cdma.c' object='mmcli-mmcli-modem-cdma.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-cdma.obj `if test -f 'mmcli-modem-cdma.c'; then $(CYGPATH_W) 'mmcli-modem-cdma.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-cdma.c'; fi`
+
+mmcli-mmcli-modem-simple.o: mmcli-modem-simple.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-simple.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-simple.Tpo -c -o mmcli-mmcli-modem-simple.o `test -f 'mmcli-modem-simple.c' || echo '$(srcdir)/'`mmcli-modem-simple.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-simple.Tpo $(DEPDIR)/mmcli-mmcli-modem-simple.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-simple.c' object='mmcli-mmcli-modem-simple.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-simple.o `test -f 'mmcli-modem-simple.c' || echo '$(srcdir)/'`mmcli-modem-simple.c
+
+mmcli-mmcli-modem-simple.obj: mmcli-modem-simple.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-simple.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-simple.Tpo -c -o mmcli-mmcli-modem-simple.obj `if test -f 'mmcli-modem-simple.c'; then $(CYGPATH_W) 'mmcli-modem-simple.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-simple.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-simple.Tpo $(DEPDIR)/mmcli-mmcli-modem-simple.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-simple.c' object='mmcli-mmcli-modem-simple.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-simple.obj `if test -f 'mmcli-modem-simple.c'; then $(CYGPATH_W) 'mmcli-modem-simple.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-simple.c'; fi`
+
+mmcli-mmcli-modem-location.o: mmcli-modem-location.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-location.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-location.Tpo -c -o mmcli-mmcli-modem-location.o `test -f 'mmcli-modem-location.c' || echo '$(srcdir)/'`mmcli-modem-location.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-location.Tpo $(DEPDIR)/mmcli-mmcli-modem-location.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-location.c' object='mmcli-mmcli-modem-location.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-location.o `test -f 'mmcli-modem-location.c' || echo '$(srcdir)/'`mmcli-modem-location.c
+
+mmcli-mmcli-modem-location.obj: mmcli-modem-location.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-location.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-location.Tpo -c -o mmcli-mmcli-modem-location.obj `if test -f 'mmcli-modem-location.c'; then $(CYGPATH_W) 'mmcli-modem-location.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-location.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-location.Tpo $(DEPDIR)/mmcli-mmcli-modem-location.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-location.c' object='mmcli-mmcli-modem-location.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-location.obj `if test -f 'mmcli-modem-location.c'; then $(CYGPATH_W) 'mmcli-modem-location.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-location.c'; fi`
+
+mmcli-mmcli-modem-messaging.o: mmcli-modem-messaging.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-messaging.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-messaging.Tpo -c -o mmcli-mmcli-modem-messaging.o `test -f 'mmcli-modem-messaging.c' || echo '$(srcdir)/'`mmcli-modem-messaging.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-messaging.Tpo $(DEPDIR)/mmcli-mmcli-modem-messaging.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-messaging.c' object='mmcli-mmcli-modem-messaging.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-messaging.o `test -f 'mmcli-modem-messaging.c' || echo '$(srcdir)/'`mmcli-modem-messaging.c
+
+mmcli-mmcli-modem-messaging.obj: mmcli-modem-messaging.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-messaging.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-messaging.Tpo -c -o mmcli-mmcli-modem-messaging.obj `if test -f 'mmcli-modem-messaging.c'; then $(CYGPATH_W) 'mmcli-modem-messaging.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-messaging.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-messaging.Tpo $(DEPDIR)/mmcli-mmcli-modem-messaging.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-messaging.c' object='mmcli-mmcli-modem-messaging.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-messaging.obj `if test -f 'mmcli-modem-messaging.c'; then $(CYGPATH_W) 'mmcli-modem-messaging.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-messaging.c'; fi`
+
+mmcli-mmcli-modem-time.o: mmcli-modem-time.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-time.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-time.Tpo -c -o mmcli-mmcli-modem-time.o `test -f 'mmcli-modem-time.c' || echo '$(srcdir)/'`mmcli-modem-time.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-time.Tpo $(DEPDIR)/mmcli-mmcli-modem-time.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-time.c' object='mmcli-mmcli-modem-time.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-time.o `test -f 'mmcli-modem-time.c' || echo '$(srcdir)/'`mmcli-modem-time.c
+
+mmcli-mmcli-modem-time.obj: mmcli-modem-time.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-time.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-time.Tpo -c -o mmcli-mmcli-modem-time.obj `if test -f 'mmcli-modem-time.c'; then $(CYGPATH_W) 'mmcli-modem-time.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-time.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-time.Tpo $(DEPDIR)/mmcli-mmcli-modem-time.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-time.c' object='mmcli-mmcli-modem-time.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-time.obj `if test -f 'mmcli-modem-time.c'; then $(CYGPATH_W) 'mmcli-modem-time.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-time.c'; fi`
+
+mmcli-mmcli-modem-firmware.o: mmcli-modem-firmware.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-firmware.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-firmware.Tpo -c -o mmcli-mmcli-modem-firmware.o `test -f 'mmcli-modem-firmware.c' || echo '$(srcdir)/'`mmcli-modem-firmware.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-firmware.Tpo $(DEPDIR)/mmcli-mmcli-modem-firmware.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-firmware.c' object='mmcli-mmcli-modem-firmware.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-firmware.o `test -f 'mmcli-modem-firmware.c' || echo '$(srcdir)/'`mmcli-modem-firmware.c
+
+mmcli-mmcli-modem-firmware.obj: mmcli-modem-firmware.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-modem-firmware.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-modem-firmware.Tpo -c -o mmcli-mmcli-modem-firmware.obj `if test -f 'mmcli-modem-firmware.c'; then $(CYGPATH_W) 'mmcli-modem-firmware.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-firmware.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-modem-firmware.Tpo $(DEPDIR)/mmcli-mmcli-modem-firmware.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-modem-firmware.c' object='mmcli-mmcli-modem-firmware.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-modem-firmware.obj `if test -f 'mmcli-modem-firmware.c'; then $(CYGPATH_W) 'mmcli-modem-firmware.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-modem-firmware.c'; fi`
+
+mmcli-mmcli-bearer.o: mmcli-bearer.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-bearer.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-bearer.Tpo -c -o mmcli-mmcli-bearer.o `test -f 'mmcli-bearer.c' || echo '$(srcdir)/'`mmcli-bearer.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-bearer.Tpo $(DEPDIR)/mmcli-mmcli-bearer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-bearer.c' object='mmcli-mmcli-bearer.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-bearer.o `test -f 'mmcli-bearer.c' || echo '$(srcdir)/'`mmcli-bearer.c
+
+mmcli-mmcli-bearer.obj: mmcli-bearer.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-bearer.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-bearer.Tpo -c -o mmcli-mmcli-bearer.obj `if test -f 'mmcli-bearer.c'; then $(CYGPATH_W) 'mmcli-bearer.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-bearer.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-bearer.Tpo $(DEPDIR)/mmcli-mmcli-bearer.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-bearer.c' object='mmcli-mmcli-bearer.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-bearer.obj `if test -f 'mmcli-bearer.c'; then $(CYGPATH_W) 'mmcli-bearer.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-bearer.c'; fi`
+
+mmcli-mmcli-sim.o: mmcli-sim.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-sim.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-sim.Tpo -c -o mmcli-mmcli-sim.o `test -f 'mmcli-sim.c' || echo '$(srcdir)/'`mmcli-sim.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-sim.Tpo $(DEPDIR)/mmcli-mmcli-sim.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-sim.c' object='mmcli-mmcli-sim.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-sim.o `test -f 'mmcli-sim.c' || echo '$(srcdir)/'`mmcli-sim.c
+
+mmcli-mmcli-sim.obj: mmcli-sim.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-sim.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-sim.Tpo -c -o mmcli-mmcli-sim.obj `if test -f 'mmcli-sim.c'; then $(CYGPATH_W) 'mmcli-sim.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-sim.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-sim.Tpo $(DEPDIR)/mmcli-mmcli-sim.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-sim.c' object='mmcli-mmcli-sim.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-sim.obj `if test -f 'mmcli-sim.c'; then $(CYGPATH_W) 'mmcli-sim.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-sim.c'; fi`
+
+mmcli-mmcli-sms.o: mmcli-sms.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-sms.o -MD -MP -MF $(DEPDIR)/mmcli-mmcli-sms.Tpo -c -o mmcli-mmcli-sms.o `test -f 'mmcli-sms.c' || echo '$(srcdir)/'`mmcli-sms.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-sms.Tpo $(DEPDIR)/mmcli-mmcli-sms.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-sms.c' object='mmcli-mmcli-sms.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-sms.o `test -f 'mmcli-sms.c' || echo '$(srcdir)/'`mmcli-sms.c
+
+mmcli-mmcli-sms.obj: mmcli-sms.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mmcli-mmcli-sms.obj -MD -MP -MF $(DEPDIR)/mmcli-mmcli-sms.Tpo -c -o mmcli-mmcli-sms.obj `if test -f 'mmcli-sms.c'; then $(CYGPATH_W) 'mmcli-sms.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-sms.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mmcli-mmcli-sms.Tpo $(DEPDIR)/mmcli-mmcli-sms.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mmcli-sms.c' object='mmcli-mmcli-sms.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mmcli_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mmcli-mmcli-sms.obj `if test -f 'mmcli-sms.c'; then $(CYGPATH_W) 'mmcli-sms.c'; else $(CYGPATH_W) '$(srcdir)/mmcli-sms.c'; fi`
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+ $(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ set x; \
+ here=`pwd`; \
+ $(am__define_uniq_tagged_files); \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+ $(am__define_uniq_tagged_files); \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+ list='$(am__tagged_files)'; \
+ case "$(srcdir)" in \
+ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+ *) sdir=$(subdir)/$(srcdir) ;; \
+ esac; \
+ for i in $$list; do \
+ if test -f "$$i"; then \
+ echo "$(subdir)/$$i"; \
+ else \
+ echo "$$sdir/$$i"; \
+ fi; \
+ done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean \
+ clean-binPROGRAMS clean-generic clean-libtool cscopelist-am \
+ ctags ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-binPROGRAMS \
+ install-data install-data-am install-dvi install-dvi-am \
+ install-exec install-exec-am install-html install-html-am \
+ install-info install-info-am install-man install-pdf \
+ install-pdf-am install-ps install-ps-am install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS
+
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/cli/mmcli-bearer.c b/cli/mmcli-bearer.c
new file mode 100644
index 0000000..600be11
--- /dev/null
+++ b/cli/mmcli-bearer.c
@@ -0,0 +1,391 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control bearer status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ MMObject *object;
+ GCancellable *cancellable;
+ MMBearer *bearer;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean info_flag; /* set when no action found */
+static gboolean connect_flag;
+static gboolean disconnect_flag;
+
+static GOptionEntry entries[] = {
+ { "connect", 'c', 0, G_OPTION_ARG_NONE, &connect_flag,
+ "Connect a given bearer.",
+ NULL
+ },
+ { "disconnect", 'x', 0, G_OPTION_ARG_NONE, &disconnect_flag,
+ "Disconnect a given bearer.",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_bearer_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("bearer",
+ "Bearer options",
+ "Show bearer options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_bearer_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (connect_flag +
+ disconnect_flag);
+
+ if (n_actions == 0 && mmcli_get_common_bearer_string ()) {
+ /* default to info */
+ info_flag = TRUE;
+ n_actions++;
+ }
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many bearer actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (info_flag)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->bearer)
+ g_object_unref (ctx->bearer);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+void
+mmcli_bearer_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+print_bearer_info (MMBearer *bearer)
+{
+ MMBearerIpConfig *ipv4_config;
+ MMBearerIpConfig *ipv6_config;
+ MMBearerProperties *properties;
+
+ ipv4_config = mm_bearer_get_ipv4_config (bearer);
+ ipv6_config = mm_bearer_get_ipv6_config (bearer);
+ properties = mm_bearer_get_properties (bearer);
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+#undef VALIDATE_NONE
+#define VALIDATE_NONE(str) (str ? str : "none")
+
+ g_print ("Bearer '%s'\n",
+ mm_bearer_get_path (bearer));
+ g_print (" -------------------------\n"
+ " Status | connected: '%s'\n"
+ " | suspended: '%s'\n"
+ " | interface: '%s'\n"
+ " | IP timeout: '%u'\n",
+ mm_bearer_get_connected (bearer) ? "yes" : "no",
+ mm_bearer_get_suspended (bearer) ? "yes" : "no",
+ VALIDATE_UNKNOWN (mm_bearer_get_interface (bearer)),
+ mm_bearer_get_ip_timeout (bearer));
+
+ if (properties) {
+ gchar *ip_family_str;
+
+ ip_family_str = (mm_bearer_ip_family_build_string_from_mask (
+ mm_bearer_properties_get_ip_type (properties)));
+ g_print (" -------------------------\n"
+ " Properties | apn: '%s'\n"
+ " | roaming: '%s'\n"
+ " | IP type: '%s'\n"
+ " | user: '%s'\n"
+ " | password: '%s'\n"
+ " | number: '%s'\n"
+ " | Rm protocol: '%s'\n",
+ VALIDATE_NONE (mm_bearer_properties_get_apn (properties)),
+ mm_bearer_properties_get_allow_roaming (properties) ? "allowed" : "forbidden",
+ VALIDATE_UNKNOWN (ip_family_str),
+ VALIDATE_NONE (mm_bearer_properties_get_user (properties)),
+ VALIDATE_NONE (mm_bearer_properties_get_password (properties)),
+ VALIDATE_NONE (mm_bearer_properties_get_number (properties)),
+ VALIDATE_UNKNOWN (mm_modem_cdma_rm_protocol_get_string (
+ mm_bearer_properties_get_rm_protocol (properties))));
+ g_free (ip_family_str);
+ }
+
+ /* IPv4 */
+ g_print (" -------------------------\n"
+ " IPv4 configuration | method: '%s'\n",
+ (ipv4_config ?
+ mm_bearer_ip_method_get_string (mm_bearer_ip_config_get_method (ipv4_config)) :
+ "none"));
+ if (ipv4_config &&
+ mm_bearer_ip_config_get_method (ipv4_config) == MM_BEARER_IP_METHOD_STATIC) {
+ const gchar **dns;
+ guint i;
+
+ dns = mm_bearer_ip_config_get_dns (ipv4_config);
+ g_print (" | address: '%s'\n"
+ " | prefix: '%u'\n"
+ " | gateway: '%s'\n"
+ " | DNS: '%s'",
+ VALIDATE_UNKNOWN (mm_bearer_ip_config_get_address (ipv4_config)),
+ mm_bearer_ip_config_get_prefix (ipv4_config),
+ VALIDATE_UNKNOWN (mm_bearer_ip_config_get_gateway (ipv4_config)),
+ VALIDATE_UNKNOWN (dns[0]));
+ /* Additional DNS addresses */
+ for (i = 1; dns[i]; i++)
+ g_print (", '%s'", dns[i]);
+ g_print ("\n");
+ }
+
+ /* IPv6 */
+ g_print (" -------------------------\n"
+ " IPv6 configuration | method: '%s'\n",
+ (ipv6_config ?
+ mm_bearer_ip_method_get_string (mm_bearer_ip_config_get_method (ipv6_config)) :
+ "none"));
+ if (ipv6_config &&
+ mm_bearer_ip_config_get_method (ipv6_config) == MM_BEARER_IP_METHOD_STATIC) {
+ const gchar **dns;
+ guint i;
+
+ dns = mm_bearer_ip_config_get_dns (ipv6_config);
+ g_print (" | address: '%s'\n"
+ " | prefix: '%u'\n"
+ " | gateway: '%s'\n"
+ " | DNS: '%s'",
+ VALIDATE_UNKNOWN(mm_bearer_ip_config_get_address (ipv6_config)),
+ mm_bearer_ip_config_get_prefix (ipv6_config),
+ VALIDATE_UNKNOWN(mm_bearer_ip_config_get_gateway (ipv6_config)),
+ VALIDATE_UNKNOWN(dns[0]));
+ /* Additional DNS addresses */
+ for (i = 1; dns[i]; i++)
+ g_print (", '%s'", dns[i]);
+ g_print ("\n");
+ }
+
+ g_clear_object (&properties);
+ g_clear_object (&ipv4_config);
+ g_clear_object (&ipv6_config);
+}
+
+static void
+connect_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't connect the bearer: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully connected the bearer\n");
+}
+
+static void
+connect_ready (MMBearer *bearer,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_bearer_connect_finish (bearer, result, &error);
+ connect_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+disconnect_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't disconnect the bearer: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully disconnected the bearer\n");
+}
+
+static void
+disconnect_ready (MMBearer *bearer,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_bearer_disconnect_finish (bearer, result, &error);
+ disconnect_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_bearer_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->bearer = mmcli_get_bearer_finish (result,
+ &ctx->manager,
+ &ctx->object);
+
+ if (info_flag)
+ g_assert_not_reached ();
+
+ /* Request to connect the bearer? */
+ if (connect_flag) {
+ g_debug ("Asynchronously connecting bearer...");
+ mm_bearer_connect (ctx->bearer,
+ ctx->cancellable,
+ (GAsyncReadyCallback)connect_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to disconnect the bearer? */
+ if (disconnect_flag) {
+ g_debug ("Asynchronously disconnecting bearer...");
+ mm_bearer_disconnect (ctx->bearer,
+ ctx->cancellable,
+ (GAsyncReadyCallback)disconnect_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_bearer_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper bearer */
+ mmcli_get_bearer (connection,
+ mmcli_get_common_bearer_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_bearer_ready,
+ NULL);
+}
+
+void
+mmcli_bearer_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->bearer = mmcli_get_bearer_sync (connection,
+ mmcli_get_common_bearer_string (),
+ &ctx->manager,
+ &ctx->object);
+
+ /* Request to get info from bearer? */
+ if (info_flag) {
+ g_debug ("Printing bearer info...");
+ print_bearer_info (ctx->bearer);
+ return;
+ }
+
+ /* Request to connect the bearer? */
+ if (connect_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously connecting bearer...");
+ result = mm_bearer_connect_sync (ctx->bearer,
+ NULL,
+ &error);
+ connect_process_reply (result, error);
+ return;
+ }
+
+ /* Request to disconnect the bearer? */
+ if (disconnect_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously disconnecting bearer...");
+ result = mm_bearer_disconnect_sync (ctx->bearer, NULL, &error);
+ disconnect_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-common.c b/cli/mmcli-common.c
new file mode 100644
index 0000000..016d8bc
--- /dev/null
+++ b/cli/mmcli-common.c
@@ -0,0 +1,1180 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli-common.h"
+
+static void
+manager_new_ready (GDBusConnection *connection,
+ GAsyncResult *res,
+ GSimpleAsyncResult *simple)
+{
+ MMManager *manager;
+ gchar *name_owner;
+ GError *error = NULL;
+
+ manager = mm_manager_new_finish (res, &error);
+ if (!manager) {
+ g_printerr ("error: couldn't create manager: %s\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
+ if (!name_owner) {
+ g_printerr ("error: couldn't find the ModemManager process in the bus\n");
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("ModemManager process found at '%s'", name_owner);
+ g_free (name_owner);
+
+
+
+ g_simple_async_result_set_op_res_gpointer (simple, manager, NULL);
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+MMManager *
+mmcli_get_manager_finish (GAsyncResult *res)
+{
+ return g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+}
+
+void
+mmcli_get_manager (GDBusConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ mmcli_get_manager);
+ mm_manager_new (connection,
+ G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
+ cancellable,
+ (GAsyncReadyCallback)manager_new_ready,
+ result);
+}
+
+MMManager *
+mmcli_get_manager_sync (GDBusConnection *connection)
+{
+ MMManager *manager;
+ gchar *name_owner;
+ GError *error = NULL;
+
+ manager = mm_manager_new_sync (connection,
+ G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START,
+ NULL,
+ &error);
+ if (!manager) {
+ g_printerr ("error: couldn't create manager: %s\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ name_owner = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (manager));
+ if (!name_owner) {
+ g_printerr ("error: couldn't find the ModemManager process in the bus\n");
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("ModemManager process found at '%s'", name_owner);
+ g_free (name_owner);
+
+ return manager;
+}
+
+static MMObject *
+find_modem (MMManager *manager,
+ const gchar *modem_path)
+{
+ GList *modems;
+ GList *l;
+ MMObject *found = NULL;
+
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
+ for (l = modems; l; l = g_list_next (l)) {
+ MMObject *modem = MM_OBJECT (l->data);
+
+ if (g_str_equal (mm_object_get_path (modem), modem_path)) {
+ found = g_object_ref (modem);
+ break;
+ }
+ }
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+
+ if (!found) {
+ g_printerr ("error: couldn't find modem at '%s'\n", modem_path);
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("Modem found at '%s'\n", modem_path);
+
+ return found;
+}
+
+typedef struct {
+ GSimpleAsyncResult *result;
+ GCancellable *cancellable;
+ gchar *modem_path;
+} GetModemContext;
+
+typedef struct {
+ MMManager *manager;
+ MMObject *object;
+} GetModemResults;
+
+static void
+get_modem_results_free (GetModemResults *results)
+{
+ g_object_unref (results->manager);
+ g_object_unref (results->object);
+ g_free (results);
+}
+
+static void
+get_modem_context_complete_and_free (GetModemContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ g_free (ctx->modem_path);
+ g_free (ctx);
+}
+
+MMObject *
+mmcli_get_modem_finish (GAsyncResult *res,
+ MMManager **o_manager)
+{
+ GetModemResults *results;
+
+ results = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ if (o_manager)
+ *o_manager = g_object_ref (results->manager);
+
+ return g_object_ref (results->object);
+}
+
+static void
+get_manager_ready (GDBusConnection *connection,
+ GAsyncResult *res,
+ GetModemContext *ctx)
+{
+ GetModemResults *results;
+
+ results = g_new (GetModemResults, 1);
+ results->manager = mmcli_get_manager_finish (res);
+ results->object = find_modem (results->manager, ctx->modem_path);
+
+ /* Set operation results */
+ g_simple_async_result_set_op_res_gpointer (
+ ctx->result,
+ results,
+ (GDestroyNotify)get_modem_results_free);
+
+ get_modem_context_complete_and_free (ctx);
+}
+
+static gchar *
+get_modem_path (const gchar *path_or_index)
+{
+ gchar *modem_path;
+
+ /* We must have a given modem specified */
+ if (!path_or_index) {
+ g_printerr ("error: no modem was specified\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Modem path may come in two ways: full DBus path or just modem index.
+ * If it is a modem index, we'll need to generate the DBus path ourselves */
+ if (g_str_has_prefix (path_or_index, MM_DBUS_MODEM_PREFIX)) {
+ g_debug ("Assuming '%s' is the full modem path", path_or_index);
+ modem_path = g_strdup (path_or_index);
+ } else if (g_ascii_isdigit (path_or_index[0])) {
+ g_debug ("Assuming '%s' is the modem index", path_or_index);
+ modem_path = g_strdup_printf (MM_DBUS_MODEM_PREFIX "/%s", path_or_index);
+ } else {
+ g_printerr ("error: invalid path or index string specified: '%s'\n",
+ path_or_index);
+ exit (EXIT_FAILURE);
+ }
+
+ return modem_path;
+}
+
+void
+mmcli_get_modem (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GetModemContext *ctx;
+
+ ctx = g_new0 (GetModemContext, 1);
+ ctx->modem_path = get_modem_path (path_or_index);
+ ctx->result = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ mmcli_get_modem);
+
+ mmcli_get_manager (connection,
+ cancellable,
+ (GAsyncReadyCallback)get_manager_ready,
+ ctx);
+}
+
+MMObject *
+mmcli_get_modem_sync (GDBusConnection *connection,
+ const gchar *modem_str,
+ MMManager **o_manager)
+{
+ MMManager *manager;
+ MMObject *found;
+ gchar *modem_path;
+
+ manager = mmcli_get_manager_sync (connection);
+ modem_path = get_modem_path (modem_str);
+ found = find_modem (manager, modem_path);
+
+ if (o_manager)
+ *o_manager = manager;
+ else
+ g_object_unref (manager);
+ g_free (modem_path);
+
+ return found;
+}
+
+typedef struct {
+ GSimpleAsyncResult *result;
+ GCancellable *cancellable;
+ gchar *bearer_path;
+ MMManager *manager;
+ GList *modems;
+ MMObject *current;
+ MMBearer *bearer;
+} GetBearerContext;
+
+static void
+get_bearer_context_free (GetBearerContext *ctx)
+{
+ if (ctx->current)
+ g_object_unref (ctx->current);
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ if (ctx->bearer)
+ g_object_unref (ctx->bearer);
+ g_list_free_full (ctx->modems, (GDestroyNotify) g_object_unref);
+ g_free (ctx->bearer_path);
+ g_free (ctx);
+}
+
+static void
+get_bearer_context_complete (GetBearerContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ ctx->result = NULL;
+}
+
+MMBearer *
+mmcli_get_bearer_finish (GAsyncResult *res,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ GetBearerContext *ctx;
+
+ ctx = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ if (o_manager)
+ *o_manager = g_object_ref (ctx->manager);
+ if (o_object)
+ *o_object = g_object_ref (ctx->current);
+ return g_object_ref (ctx->bearer);
+}
+
+static void look_for_bearer_in_modem (GetBearerContext *ctx);
+
+static MMBearer *
+find_bearer_in_list (GList *list,
+ const gchar *bearer_path)
+{
+ GList *l;
+
+ for (l = list; l; l = g_list_next (l)) {
+ MMBearer *bearer = MM_BEARER (l->data);
+
+ if (g_str_equal (mm_bearer_get_path (bearer), bearer_path)) {
+ g_debug ("Bearer found at '%s'\n", bearer_path);
+ return g_object_ref (bearer);
+ }
+ }
+
+ return NULL;
+}
+
+static void
+list_bearers_ready (MMModem *modem,
+ GAsyncResult *res,
+ GetBearerContext *ctx)
+{
+ GList *bearers;
+ GError *error = NULL;
+
+ bearers = mm_modem_list_bearers_finish (modem, res, &error);
+ if (error) {
+ g_printerr ("error: couldn't list bearers at '%s': '%s'\n",
+ mm_modem_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ ctx->bearer = find_bearer_in_list (bearers, ctx->bearer_path);
+ g_list_free_full (bearers, (GDestroyNotify) g_object_unref);
+
+ /* Found! */
+ if (ctx->bearer) {
+ g_simple_async_result_set_op_res_gpointer (
+ ctx->result,
+ ctx,
+ (GDestroyNotify)get_bearer_context_free);
+ get_bearer_context_complete (ctx);
+ return;
+ }
+
+ /* Not found, try with next modem */
+ look_for_bearer_in_modem (ctx);
+}
+
+static void
+look_for_bearer_in_modem (GetBearerContext *ctx)
+{
+ MMModem *modem;
+
+ if (!ctx->modems) {
+ g_printerr ("error: couldn't find bearer at '%s': 'not found in any modem'\n",
+ ctx->bearer_path);
+ exit (EXIT_FAILURE);
+ }
+
+ /* Loop looking for the bearer in each modem found */
+ ctx->current = MM_OBJECT (ctx->modems->data);
+ ctx->modems = g_list_delete_link (ctx->modems, ctx->modems);
+
+ modem = mm_object_get_modem (ctx->current);
+
+ /* Don't look for bearers in modems which are not fully initialized */
+ if (mm_modem_get_state (modem) < MM_MODEM_STATE_DISABLED) {
+ g_debug ("Skipping modem '%s' when looking for bearers "
+ "(not fully initialized)",
+ mm_object_get_path (ctx->current));
+ g_object_unref (modem);
+ look_for_bearer_in_modem (ctx);
+ return;
+ }
+
+ g_debug ("Looking for bearer '%s' in modem '%s'...",
+ ctx->bearer_path,
+ mm_object_get_path (ctx->current));
+
+ mm_modem_list_bearers (modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)list_bearers_ready,
+ ctx);
+ g_object_unref (modem);
+}
+
+static void
+get_bearer_manager_ready (GDBusConnection *connection,
+ GAsyncResult *res,
+ GetBearerContext *ctx)
+{
+ ctx->manager = mmcli_get_manager_finish (res);
+ ctx->modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (ctx->manager));
+ if (!ctx->modems) {
+ g_printerr ("error: couldn't find bearer at '%s': 'no modems found'\n",
+ ctx->bearer_path);
+ exit (EXIT_FAILURE);
+ }
+
+ look_for_bearer_in_modem (ctx);
+}
+
+static gchar *
+get_bearer_path (const gchar *path_or_index)
+{
+ gchar *bearer_path;
+
+ /* We must have a given bearer specified */
+ if (!path_or_index) {
+ g_printerr ("error: no bearer was specified\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Bearer path may come in two ways: full DBus path or just bearer index.
+ * If it is a bearer index, we'll need to generate the DBus path ourselves */
+ if (g_str_has_prefix (path_or_index, MM_DBUS_BEARER_PREFIX)) {
+ g_debug ("Assuming '%s' is the full bearer path", path_or_index);
+ bearer_path = g_strdup (path_or_index);
+ } else if (g_ascii_isdigit (path_or_index[0])) {
+ g_debug ("Assuming '%s' is the bearer index", path_or_index);
+ bearer_path = g_strdup_printf (MM_DBUS_BEARER_PREFIX "/%s", path_or_index);
+ } else {
+ g_printerr ("error: invalid path or index string specified: '%s'\n",
+ path_or_index);
+ exit (EXIT_FAILURE);
+ }
+
+ return bearer_path;
+}
+
+void
+mmcli_get_bearer (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GetBearerContext *ctx;
+
+ ctx = g_new0 (GetBearerContext, 1);
+ ctx->bearer_path = get_bearer_path (path_or_index);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->result = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ mmcli_get_modem);
+ mmcli_get_manager (connection,
+ cancellable,
+ (GAsyncReadyCallback)get_bearer_manager_ready,
+ ctx);
+}
+
+MMBearer *
+mmcli_get_bearer_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ MMManager *manager;
+ GList *modems;
+ GList *l;
+ MMBearer *found = NULL;
+ gchar *bearer_path;
+
+ bearer_path = get_bearer_path (path_or_index);
+
+ manager = mmcli_get_manager_sync (connection);
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
+ if (!modems) {
+ g_printerr ("error: couldn't find bearer at '%s': 'no modems found'\n",
+ bearer_path);
+ exit (EXIT_FAILURE);
+ }
+
+ for (l = modems; !found && l; l = g_list_next (l)) {
+ GError *error = NULL;
+ MMObject *object;
+ MMModem *modem;
+ GList *bearers;
+
+ object = MM_OBJECT (l->data);
+ modem = mm_object_get_modem (object);
+
+ /* Don't look for bearers in modems which are not fully initialized */
+ if (mm_modem_get_state (modem) < MM_MODEM_STATE_DISABLED) {
+ g_debug ("Skipping modem '%s' when looking for bearers "
+ "(not fully initialized)",
+ mm_object_get_path (object));
+ g_object_unref (modem);
+ continue;
+ }
+
+ bearers = mm_modem_list_bearers_sync (modem, NULL, &error);
+ if (error) {
+ g_printerr ("error: couldn't list bearers at '%s': '%s'\n",
+ mm_modem_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ found = find_bearer_in_list (bearers, bearer_path);
+ g_list_free_full (bearers, (GDestroyNotify) g_object_unref);
+
+ if (found && o_object)
+ *o_object = g_object_ref (object);
+
+ g_object_unref (modem);
+ }
+
+ if (!found) {
+ g_printerr ("error: couldn't find bearer at '%s': 'not found in any modem'\n",
+ bearer_path);
+ exit (EXIT_FAILURE);
+ }
+
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+ g_free (bearer_path);
+
+ if (o_manager)
+ *o_manager = manager;
+ else
+ g_object_unref (manager);
+
+ return found;
+}
+
+typedef struct {
+ GSimpleAsyncResult *result;
+ GCancellable *cancellable;
+ gchar *sim_path;
+ MMManager *manager;
+ MMObject *modem;
+ MMSim *sim;
+} GetSimContext;
+
+static void
+get_sim_context_free (GetSimContext *ctx)
+{
+ if (ctx->modem)
+ g_object_unref (ctx->modem);
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ if (ctx->sim)
+ g_object_unref (ctx->sim);
+ g_free (ctx->sim_path);
+ g_free (ctx);
+}
+
+static void
+get_sim_context_complete (GetSimContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ ctx->result = NULL;
+}
+
+MMSim *
+mmcli_get_sim_finish (GAsyncResult *res,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ GetSimContext *ctx;
+
+ ctx = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ if (o_manager)
+ *o_manager = g_object_ref (ctx->manager);
+ if (o_object)
+ *o_object = g_object_ref (ctx->modem);
+ return g_object_ref (ctx->sim);
+}
+
+static void
+get_sim_ready (MMModem *modem,
+ GAsyncResult *res,
+ GetSimContext *ctx)
+{
+ GError *error = NULL;
+
+ ctx->sim = mm_modem_get_sim_finish (modem, res, &error);
+ if (error) {
+ g_printerr ("error: couldn't get sim '%s' at '%s': '%s'\n",
+ ctx->sim_path,
+ mm_modem_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_simple_async_result_set_op_res_gpointer (
+ ctx->result,
+ ctx,
+ (GDestroyNotify)get_sim_context_free);
+ get_sim_context_complete (ctx);
+}
+
+static void
+get_sim_manager_ready (GDBusConnection *connection,
+ GAsyncResult *res,
+ GetSimContext *ctx)
+{
+ GList *l;
+ GList *modems;
+
+ ctx->manager = mmcli_get_manager_finish (res);
+
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (ctx->manager));
+ if (!modems) {
+ g_printerr ("error: couldn't find sim at '%s': 'no modems found'\n",
+ ctx->sim_path);
+ exit (EXIT_FAILURE);
+ }
+
+ for (l = modems; l; l = g_list_next (l)) {
+ MMObject *object;
+ MMModem *modem;
+
+ object = MM_OBJECT (l->data);
+ modem = mm_object_get_modem (object);
+ if (g_str_equal (ctx->sim_path, mm_modem_get_sim_path (modem))) {
+ ctx->modem = g_object_ref (object);
+ mm_modem_get_sim (modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)get_sim_ready,
+ ctx);
+ break;
+ }
+ g_object_unref (modem);
+ }
+
+ if (!ctx->modem) {
+ g_printerr ("error: couldn't find sim at '%s'\n",
+ ctx->sim_path);
+ exit (EXIT_FAILURE);
+ }
+
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+}
+
+static gchar *
+get_sim_path (const gchar *path_or_index)
+{
+ gchar *sim_path;
+
+ /* We must have a given sim specified */
+ if (!path_or_index) {
+ g_printerr ("error: no sim was specified\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Sim path may come in two ways: full DBus path or just sim index.
+ * If it is a sim index, we'll need to generate the DBus path ourselves */
+ if (g_str_has_prefix (path_or_index, MM_DBUS_SIM_PREFIX)) {
+ g_debug ("Assuming '%s' is the full SIM path", path_or_index);
+ sim_path = g_strdup (path_or_index);
+ } else if (g_ascii_isdigit (path_or_index[0])) {
+ g_debug ("Assuming '%s' is the SIM index", path_or_index);
+ sim_path = g_strdup_printf (MM_DBUS_SIM_PREFIX "/%s", path_or_index);
+ } else {
+ g_printerr ("error: invalid index string specified: '%s'\n",
+ path_or_index);
+ exit (EXIT_FAILURE);
+ }
+
+ return sim_path;
+}
+
+void
+mmcli_get_sim (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GetSimContext *ctx;
+
+ ctx = g_new0 (GetSimContext, 1);
+ ctx->sim_path = get_sim_path (path_or_index);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->result = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ mmcli_get_modem);
+ mmcli_get_manager (connection,
+ cancellable,
+ (GAsyncReadyCallback)get_sim_manager_ready,
+ ctx);
+}
+
+MMSim *
+mmcli_get_sim_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ MMManager *manager;
+ GList *modems;
+ GList *l;
+ MMSim *found = NULL;
+ gchar *sim_path;
+
+ sim_path = get_sim_path (path_or_index);
+
+ manager = mmcli_get_manager_sync (connection);
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
+ if (!modems) {
+ g_printerr ("error: couldn't find sim at '%s': 'no modems found'\n",
+ sim_path);
+ exit (EXIT_FAILURE);
+ }
+
+ for (l = modems; !found && l; l = g_list_next (l)) {
+ GError *error = NULL;
+ MMObject *object;
+ MMModem *modem;
+
+ object = MM_OBJECT (l->data);
+ modem = mm_object_get_modem (object);
+ if (g_str_equal (sim_path, mm_modem_get_sim_path (modem))) {
+ found = mm_modem_get_sim_sync (modem, NULL, &error);
+ if (error) {
+ g_printerr ("error: couldn't get sim '%s' in modem '%s': '%s'\n",
+ sim_path,
+ mm_modem_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ if (found && o_object)
+ *o_object = g_object_ref (object);
+ }
+
+ g_object_unref (modem);
+ }
+
+ if (!found) {
+ g_printerr ("error: couldn't find sim at '%s'\n", sim_path);
+ exit (EXIT_FAILURE);
+ }
+
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+ g_free (sim_path);
+
+ if (o_manager)
+ *o_manager = manager;
+ else
+ g_object_unref (manager);
+
+ return found;
+}
+
+typedef struct {
+ GSimpleAsyncResult *result;
+ GCancellable *cancellable;
+ gchar *sms_path;
+ MMManager *manager;
+ GList *modems;
+ MMObject *current;
+ MMSms *sms;
+} GetSmsContext;
+
+static void
+get_sms_context_free (GetSmsContext *ctx)
+{
+ if (ctx->current)
+ g_object_unref (ctx->current);
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ if (ctx->sms)
+ g_object_unref (ctx->sms);
+ g_list_free_full (ctx->modems, (GDestroyNotify) g_object_unref);
+ g_free (ctx->sms_path);
+ g_free (ctx);
+}
+
+static void
+get_sms_context_complete (GetSmsContext *ctx)
+{
+ g_simple_async_result_complete (ctx->result);
+ g_object_unref (ctx->result);
+ ctx->result = NULL;
+}
+
+MMSms *
+mmcli_get_sms_finish (GAsyncResult *res,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ GetSmsContext *ctx;
+
+ ctx = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
+ if (o_manager)
+ *o_manager = g_object_ref (ctx->manager);
+ if (o_object)
+ *o_object = g_object_ref (ctx->current);
+ return g_object_ref (ctx->sms);
+}
+
+static void look_for_sms_in_modem (GetSmsContext *ctx);
+
+static MMSms *
+find_sms_in_list (GList *list,
+ const gchar *sms_path)
+{
+ GList *l;
+
+ for (l = list; l; l = g_list_next (l)) {
+ MMSms *sms = MM_SMS (l->data);
+
+ if (g_str_equal (mm_sms_get_path (sms), sms_path)) {
+ g_debug ("Sms found at '%s'\n", sms_path);
+ return g_object_ref (sms);
+ }
+ }
+
+ return NULL;
+}
+
+static void
+list_sms_ready (MMModemMessaging *modem,
+ GAsyncResult *res,
+ GetSmsContext *ctx)
+{
+ GList *sms_list;
+ GError *error = NULL;
+
+ sms_list = mm_modem_messaging_list_finish (modem, res, &error);
+ if (error) {
+ g_printerr ("error: couldn't list SMS at '%s': '%s'\n",
+ mm_modem_messaging_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ ctx->sms = find_sms_in_list (sms_list, ctx->sms_path);
+ g_list_free_full (sms_list, (GDestroyNotify) g_object_unref);
+
+ /* Found! */
+ if (ctx->sms) {
+ g_simple_async_result_set_op_res_gpointer (
+ ctx->result,
+ ctx,
+ (GDestroyNotify)get_sms_context_free);
+ get_sms_context_complete (ctx);
+ return;
+ }
+
+ /* Not found, try with next modem */
+ look_for_sms_in_modem (ctx);
+}
+
+static void
+look_for_sms_in_modem (GetSmsContext *ctx)
+{
+ MMModemMessaging *modem;
+
+ if (!ctx->modems) {
+ g_printerr ("error: couldn't find SMS at '%s': 'not found in any modem'\n",
+ ctx->sms_path);
+ exit (EXIT_FAILURE);
+ }
+
+ /* Loop looking for the sms in each modem found */
+ ctx->current = MM_OBJECT (ctx->modems->data);
+ ctx->modems = g_list_delete_link (ctx->modems, ctx->modems);
+
+ modem = mm_object_get_modem_messaging (ctx->current);
+ if (modem) {
+ g_debug ("Looking for sms '%s' in modem '%s'...",
+ ctx->sms_path,
+ mm_object_get_path (ctx->current));
+ mm_modem_messaging_list (modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)list_sms_ready,
+ ctx);
+ g_object_unref (modem);
+ return;
+ }
+
+ /* Current modem has no messaging capabilities, try with next modem */
+ look_for_sms_in_modem (ctx);
+}
+
+static void
+get_sms_manager_ready (GDBusConnection *connection,
+ GAsyncResult *res,
+ GetSmsContext *ctx)
+{
+ ctx->manager = mmcli_get_manager_finish (res);
+ ctx->modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (ctx->manager));
+ if (!ctx->modems) {
+ g_printerr ("error: couldn't find SMS at '%s': 'no modems found'\n",
+ ctx->sms_path);
+ exit (EXIT_FAILURE);
+ }
+
+ look_for_sms_in_modem (ctx);
+}
+
+static gchar *
+get_sms_path (const gchar *path_or_index)
+{
+ gchar *sms_path;
+
+ /* We must have a given sms specified */
+ if (!path_or_index) {
+ g_printerr ("error: no SMS was specified\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Sms path may come in two ways: full DBus path or just sms index.
+ * If it is a sms index, we'll need to generate the DBus path ourselves */
+ if (g_str_has_prefix (path_or_index, MM_DBUS_SMS_PREFIX)) {
+ g_debug ("Assuming '%s' is the full SMS path", path_or_index);
+ sms_path = g_strdup (path_or_index);
+ } else if (g_ascii_isdigit (path_or_index[0])) {
+ g_debug ("Assuming '%s' is the SMS index", path_or_index);
+ sms_path = g_strdup_printf (MM_DBUS_SMS_PREFIX "/%s", path_or_index);
+ } else {
+ g_printerr ("error: invalid path or index string specified: '%s'\n",
+ path_or_index);
+ exit (EXIT_FAILURE);
+ }
+
+ return sms_path;
+}
+
+void
+mmcli_get_sms (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GetSmsContext *ctx;
+
+ ctx = g_new0 (GetSmsContext, 1);
+ ctx->sms_path = get_sms_path (path_or_index);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+ ctx->result = g_simple_async_result_new (G_OBJECT (connection),
+ callback,
+ user_data,
+ mmcli_get_modem);
+ mmcli_get_manager (connection,
+ cancellable,
+ (GAsyncReadyCallback)get_sms_manager_ready,
+ ctx);
+}
+
+MMSms *
+mmcli_get_sms_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **o_manager,
+ MMObject **o_object)
+{
+ MMManager *manager;
+ GList *modems;
+ GList *l;
+ MMSms *found = NULL;
+ gchar *sms_path;
+
+ sms_path = get_sms_path (path_or_index);
+
+ manager = mmcli_get_manager_sync (connection);
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (manager));
+ if (!modems) {
+ g_printerr ("error: couldn't find sms at '%s': 'no modems found'\n",
+ sms_path);
+ exit (EXIT_FAILURE);
+ }
+
+ for (l = modems; !found && l; l = g_list_next (l)) {
+ GError *error = NULL;
+ MMObject *object;
+ MMModemMessaging *modem;
+ GList *sms_list;
+
+ object = MM_OBJECT (l->data);
+ modem = mm_object_get_modem_messaging (object);
+
+ /* If this modem doesn't implement messaging, continue to next one */
+ if (!modem)
+ continue;
+
+ sms_list = mm_modem_messaging_list_sync (modem, NULL, &error);
+ if (error) {
+ g_printerr ("error: couldn't list SMS at '%s': '%s'\n",
+ mm_modem_messaging_get_path (modem),
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ found = find_sms_in_list (sms_list, sms_path);
+ g_list_free_full (sms_list, (GDestroyNotify) g_object_unref);
+
+ if (found && o_object)
+ *o_object = g_object_ref (object);
+
+ g_object_unref (modem);
+ }
+
+ if (!found) {
+ g_printerr ("error: couldn't find SMS at '%s': 'not found in any modem'\n",
+ sms_path);
+ exit (EXIT_FAILURE);
+ }
+
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+ g_free (sms_path);
+
+ if (o_manager)
+ *o_manager = manager;
+ else
+ g_object_unref (manager);
+
+ return found;
+}
+
+const gchar *
+mmcli_get_state_reason_string (MMModemStateChangeReason reason)
+{
+ switch (reason) {
+ case MM_MODEM_STATE_CHANGE_REASON_UNKNOWN:
+ return "None or unknown";
+ case MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED:
+ return "User request";
+ case MM_MODEM_STATE_CHANGE_REASON_SUSPEND:
+ return "Suspend";
+ case MM_MODEM_STATE_CHANGE_REASON_FAILURE:
+ return "Failure";
+ }
+
+ g_warn_if_reached ();
+ return NULL;
+}
+
+/* Common options */
+static gchar *modem_str;
+static gchar *bearer_str;
+static gchar *sim_str;
+static gchar *sms_str;
+
+static GOptionEntry entries[] = {
+ { "modem", 'm', 0, G_OPTION_ARG_STRING, &modem_str,
+ "Specify modem by path or index. Shows modem information if no action specified.",
+ "[PATH|INDEX]"
+ },
+ { "bearer", 'b', 0, G_OPTION_ARG_STRING, &bearer_str,
+ "Specify bearer by path or index. Shows bearer information if no action specified.",
+ "[PATH|INDEX]"
+ },
+ { "sim", 'i', 0, G_OPTION_ARG_STRING, &sim_str,
+ "Specify SIM card by path or index. Shows SIM card information if no action specified.",
+ "[PATH|INDEX]"
+ },
+ { "sms", 's', 0, G_OPTION_ARG_STRING, &sms_str,
+ "Specify SMS by path or index. Shows SMS information if no action specified.",
+ "[PATH|INDEX]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_get_common_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("common",
+ "Common options",
+ "Show common options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+const gchar *
+mmcli_get_common_modem_string (void)
+{
+ return modem_str;
+}
+
+const gchar *
+mmcli_get_common_bearer_string (void)
+{
+ return bearer_str;
+}
+
+const gchar *
+mmcli_get_common_sim_string (void)
+{
+ return sim_str;
+}
+
+const gchar *
+mmcli_get_common_sms_string (void)
+{
+ return sms_str;
+}
+
+gchar *
+mmcli_prefix_newlines (const gchar *prefix,
+ const gchar *str)
+{
+ GString *prefixed_string = NULL;
+ const gchar *line_start = str;
+ const gchar *line_end;
+
+ do {
+ gssize line_length;
+
+ line_end = strchr (line_start, '\n');
+ if (line_end)
+ line_length = line_end - line_start;
+ else
+ line_length = strlen (line_start);
+
+ if (line_start[line_length - 1] == '\r')
+ line_length--;
+
+ if (line_length > 0) {
+ if (prefixed_string) {
+ /* If not the first line, add the prefix */
+ g_string_append_printf (prefixed_string,
+ "\n%s", prefix);
+ } else {
+ prefixed_string = g_string_new ("");
+ }
+
+ g_string_append_len (prefixed_string,
+ line_start,
+ line_length);
+ }
+
+ line_start = (line_end ? line_end + 1 : NULL);
+ } while (line_start != NULL);
+
+ return (prefixed_string ?
+ g_string_free (prefixed_string, FALSE) :
+ g_strdup (str));
+}
diff --git a/cli/mmcli-common.h b/cli/mmcli-common.h
new file mode 100644
index 0000000..615f521
--- /dev/null
+++ b/cli/mmcli-common.h
@@ -0,0 +1,93 @@
+/* -*- Mode: C; 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 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 General Public License for more details:
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#ifndef _MMCLI_COMMON_H_
+#define _MMCLI_COMMON_H_
+
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+void mmcli_get_manager (GDBusConnection *connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMManager *mmcli_get_manager_finish (GAsyncResult *res);
+MMManager *mmcli_get_manager_sync (GDBusConnection *connection);
+
+
+void mmcli_get_modem (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMObject *mmcli_get_modem_finish (GAsyncResult *res,
+ MMManager **o_manager);
+MMObject *mmcli_get_modem_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **o_manager);
+
+void mmcli_get_bearer (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMBearer *mmcli_get_bearer_finish (GAsyncResult *res,
+ MMManager **manager,
+ MMObject **object);
+MMBearer *mmcli_get_bearer_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **manager,
+ MMObject **object);
+
+void mmcli_get_sim (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMSim *mmcli_get_sim_finish (GAsyncResult *res,
+ MMManager **manager,
+ MMObject **object);
+MMSim *mmcli_get_sim_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **manager,
+ MMObject **object);
+
+void mmcli_get_sms (GDBusConnection *connection,
+ const gchar *path_or_index,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMSms *mmcli_get_sms_finish (GAsyncResult *res,
+ MMManager **manager,
+ MMObject **object);
+MMSms *mmcli_get_sms_sync (GDBusConnection *connection,
+ const gchar *path_or_index,
+ MMManager **manager,
+ MMObject **object);
+
+const gchar *mmcli_get_state_reason_string (MMModemStateChangeReason reason);
+
+GOptionGroup *mmcli_get_common_option_group (void);
+const gchar *mmcli_get_common_modem_string (void);
+const gchar *mmcli_get_common_bearer_string (void);
+const gchar *mmcli_get_common_sim_string (void);
+const gchar *mmcli_get_common_sms_string (void);
+
+gchar *mmcli_prefix_newlines (const gchar *prefix,
+ const gchar *str);
+
+#endif /* _MMCLI_COMMON_H_ */
diff --git a/cli/mmcli-manager.c b/cli/mmcli-manager.c
new file mode 100644
index 0000000..d3bd48e
--- /dev/null
+++ b/cli/mmcli-manager.c
@@ -0,0 +1,367 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ * Copyright (C) 2011 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include "libmm-glib.h"
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean list_modems_flag;
+static gboolean monitor_modems_flag;
+static gboolean scan_modems_flag;
+static gchar *set_logging_str;
+
+static GOptionEntry entries[] = {
+ { "set-logging", 'G', 0, G_OPTION_ARG_STRING, &set_logging_str,
+ "Set logging level in the ModemManager daemon",
+ "[ERR,WARN,INFO,DEBUG]",
+ },
+ { "list-modems", 'L', 0, G_OPTION_ARG_NONE, &list_modems_flag,
+ "List available modems",
+ NULL
+ },
+ { "monitor-modems", 'M', 0, G_OPTION_ARG_NONE, &monitor_modems_flag,
+ "List available modems and monitor additions and removals",
+ NULL
+ },
+ { "scan-modems", 'S', 0, G_OPTION_ARG_NONE, &scan_modems_flag,
+ "Request to re-scan looking for modems",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_manager_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("manager",
+ "Manager options",
+ "Show manager options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_manager_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (list_modems_flag +
+ monitor_modems_flag +
+ scan_modems_flag +
+ !!set_logging_str);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many manager actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (monitor_modems_flag)
+ mmcli_force_async_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ g_free (ctx);
+}
+
+void
+mmcli_manager_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+set_logging_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set logging level: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("Successfully set logging level\n");
+}
+
+static void
+set_logging_ready (MMManager *manager,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_manager_set_logging_finish (manager,
+ result,
+ &error);
+ set_logging_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+scan_devices_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't request to scan devices: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully requested to scan devices\n");
+}
+
+static void
+scan_devices_ready (MMManager *manager,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_manager_scan_devices_finish (manager,
+ result,
+ &error);
+ scan_devices_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+print_modem_short_info (MMObject *modem)
+{
+ g_print ("\t%s [%s] %s\n",
+ mm_object_get_path (modem),
+ mm_modem_get_manufacturer (mm_object_peek_modem (modem)),
+ mm_modem_get_model (mm_object_peek_modem (modem)));
+}
+
+static void
+device_added (MMManager *manager,
+ MMObject *modem)
+{
+ g_print ("Added modem:\n");
+ print_modem_short_info (modem);
+ fflush (stdout);
+}
+
+static void
+device_removed (MMManager *manager,
+ MMObject *modem)
+{
+ g_print ("Removed modem:\n");
+ print_modem_short_info (modem);
+ fflush (stdout);
+}
+
+static void
+list_current_modems (MMManager *manager)
+{
+ GList *modems;
+
+ modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (ctx->manager));
+
+ g_print ("\n");
+ if (!modems)
+ g_print ("No modems were found\n");
+ else {
+ GList *l;
+
+ g_print ("Found %u modems:\n", g_list_length (modems));
+ for (l = modems; l; l = g_list_next (l)) {
+ print_modem_short_info (MM_OBJECT (l->data));
+ }
+ g_list_free_full (modems, (GDestroyNotify) g_object_unref);
+ }
+ g_print ("\n");
+}
+
+static void
+cancelled (GCancellable *cancellable)
+{
+ mmcli_async_operation_done ();
+}
+
+static void
+get_manager_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->manager = mmcli_get_manager_finish (result);
+
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (mm_manager_peek_proxy (ctx->manager));
+
+ /* Request to set log level? */
+ if (set_logging_str) {
+ mm_manager_set_logging (ctx->manager,
+ set_logging_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_logging_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to scan modems? */
+ if (scan_modems_flag) {
+ mm_manager_scan_devices (ctx->manager,
+ ctx->cancellable,
+ (GAsyncReadyCallback)scan_devices_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to monitor modems? */
+ if (monitor_modems_flag) {
+ g_signal_connect (ctx->manager,
+ "object-added",
+ G_CALLBACK (device_added),
+ NULL);
+ g_signal_connect (ctx->manager,
+ "object-removed",
+ G_CALLBACK (device_removed),
+ NULL);
+ list_current_modems (ctx->manager);
+
+ /* If we get cancelled, operation done */
+ g_cancellable_connect (ctx->cancellable,
+ G_CALLBACK (cancelled),
+ NULL,
+ NULL);
+ return;
+ }
+
+ /* Request to list modems? */
+ if (list_modems_flag) {
+ list_current_modems (ctx->manager);
+ mmcli_async_operation_done ();
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_manager_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Create a new Manager object asynchronously */
+ mmcli_get_manager (connection,
+ cancellable,
+ (GAsyncReadyCallback)get_manager_ready,
+ NULL);
+}
+
+void
+mmcli_manager_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (monitor_modems_flag) {
+ g_printerr ("error: monitoring modems cannot be done synchronously\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->manager = mmcli_get_manager_sync (connection);
+
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (mm_manager_peek_proxy (ctx->manager));
+
+ /* Request to set log level? */
+ if (set_logging_str) {
+ gboolean result;
+
+ result = mm_manager_set_logging_sync (ctx->manager,
+ set_logging_str,
+ NULL,
+ &error);
+ set_logging_process_reply (result, error);
+ return;
+ }
+
+ /* Request to scan modems? */
+ if (scan_modems_flag) {
+ gboolean result;
+
+ result = mm_manager_scan_devices_sync (ctx->manager,
+ NULL,
+ &error);
+ scan_devices_process_reply (result, error);
+ return;
+ }
+
+ /* Request to list modems? */
+ if (list_modems_flag) {
+ list_current_modems (ctx->manager);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-3gpp.c b/cli/mmcli-modem-3gpp.c
new file mode 100644
index 0000000..f88ce62
--- /dev/null
+++ b/cli/mmcli-modem-3gpp.c
@@ -0,0 +1,565 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 - 2012 Aleksander Morgado <aleksander@gnu.org>
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModem3gpp *modem_3gpp;
+ MMModem3gppUssd *modem_3gpp_ussd;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean scan_flag;
+static gboolean register_home_flag;
+static gchar *register_in_operator_str;
+static gboolean ussd_status_flag;
+static gchar *ussd_initiate_str;
+static gchar *ussd_respond_str;
+static gboolean ussd_cancel_flag;
+
+static GOptionEntry entries[] = {
+ { "3gpp-scan", 0, 0, G_OPTION_ARG_NONE, &scan_flag,
+ "Scan for available networks in a given modem.",
+ NULL
+ },
+ { "3gpp-register-home", 0, 0, G_OPTION_ARG_NONE, &register_home_flag,
+ "Request a given modem to register in its home network",
+ NULL
+ },
+ { "3gpp-register-in-operator", 0, 0, G_OPTION_ARG_STRING, &register_in_operator_str,
+ "Request a given modem to register in the network of the given operator",
+ "[MCCMNC]"
+ },
+ { "3gpp-ussd-status", 0, 0, G_OPTION_ARG_NONE, &ussd_status_flag,
+ "Show status of any ongoing USSD session",
+ NULL
+ },
+ { "3gpp-ussd-initiate", 0, 0, G_OPTION_ARG_STRING, &ussd_initiate_str,
+ "Request a given modem to initiate a USSD session",
+ "[command]"
+ },
+ { "3gpp-ussd-respond", 0, 0, G_OPTION_ARG_STRING, &ussd_respond_str,
+ "Request a given modem to initiate a USSD session",
+ "[response]"
+ },
+ { "3gpp-ussd-cancel", 0, 0, G_OPTION_ARG_NONE, &ussd_cancel_flag,
+ "Request to cancel any ongoing USSD session",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_3gpp_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("3gpp",
+ "3GPP options",
+ "Show 3GPP related options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_3gpp_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (scan_flag +
+ register_home_flag +
+ !!register_in_operator_str +
+ ussd_status_flag +
+ !!ussd_initiate_str +
+ !!ussd_respond_str +
+ ussd_cancel_flag);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many 3GPP actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Scanning networks takes really a long time, so we do it asynchronously
+ * always to avoid DBus timeouts */
+ if (scan_flag)
+ mmcli_force_async_operation ();
+
+ /* USSD initiate and respond will wait for URCs to get finished, so
+ * these are truly async. */
+ if (ussd_initiate_str || ussd_respond_str)
+ mmcli_force_async_operation ();
+
+ if (ussd_status_flag)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_3gpp)
+ g_object_unref (ctx->modem_3gpp);
+ if (ctx->modem_3gpp_ussd)
+ g_object_unref (ctx->modem_3gpp_ussd);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_3gpp (void)
+{
+ if (mm_modem_get_state (mm_object_peek_modem (ctx->object)) < MM_MODEM_STATE_ENABLED) {
+ g_printerr ("error: modem not enabled yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_3gpp) {
+ g_printerr ("error: modem has no 3GPP capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+static void
+ensure_modem_3gpp_ussd (void)
+{
+ if (mm_modem_get_unlock_required (mm_object_peek_modem (ctx->object)) != MM_MODEM_LOCK_NONE) {
+ g_printerr ("error: modem not unlocked yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_3gpp_ussd) {
+ g_printerr ("error: modem has no USSD capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_3gpp_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+print_network_info (MMModem3gppNetwork *network)
+{
+ const gchar *name;
+ gchar *access_technologies;
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE
+#define VALIDATE(str) (str ? str : "unknown")
+
+ access_technologies = (mm_modem_access_technology_build_string_from_mask (
+ mm_modem_3gpp_network_get_access_technology (network)));
+
+ /* Prefer long name */
+ name = mm_modem_3gpp_network_get_operator_long (network);
+ if (!name)
+ name = mm_modem_3gpp_network_get_operator_short (network);
+
+ g_print ("%s - %s (%s, %s)\n",
+ VALIDATE (mm_modem_3gpp_network_get_operator_code (network)),
+ VALIDATE (name),
+ access_technologies,
+ mm_modem_3gpp_network_availability_get_string (
+ mm_modem_3gpp_network_get_availability (network)));
+ g_free (access_technologies);
+}
+
+static void
+scan_process_reply (GList *result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't scan networks in the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("\n");
+ if (!result)
+ g_print ("No networks were found\n");
+ else {
+ GList *l;
+
+ g_print ("Found %u networks:\n", g_list_length (result));
+ for (l = result; l; l = g_list_next (l)) {
+ print_network_info ((MMModem3gppNetwork *)(l->data));
+ }
+ g_list_free_full (result, (GDestroyNotify) mm_modem_3gpp_network_free);
+ }
+ g_print ("\n");
+}
+
+static void
+scan_ready (MMModem3gpp *modem_3gpp,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ GList *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_3gpp_scan_finish (modem_3gpp, result, &error);
+ scan_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+register_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't register the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully registered the modem\n");
+}
+
+static void
+register_ready (MMModem3gpp *modem_3gpp,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_3gpp_register_finish (modem_3gpp, result, &error);
+ register_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+print_ussd_status (void)
+{
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE
+#define VALIDATE(str) (str ? str : "none")
+
+ g_print ("\n"
+ "%s\n"
+ " ----------------------------\n"
+ " USSD | status: '%s'\n"
+ " | network request: '%s'\n"
+ " | network notification: '%s'\n",
+ mm_modem_3gpp_ussd_get_path (ctx->modem_3gpp_ussd),
+ mm_modem_3gpp_ussd_session_state_get_string (
+ mm_modem_3gpp_ussd_get_state (ctx->modem_3gpp_ussd)),
+ VALIDATE (mm_modem_3gpp_ussd_get_network_request (ctx->modem_3gpp_ussd)),
+ VALIDATE (mm_modem_3gpp_ussd_get_network_notification (ctx->modem_3gpp_ussd)));
+}
+
+static void
+ussd_initiate_process_reply (gchar *result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't initiate USSD session: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("USSD session initiated; "
+ "new reply from network: '%s'\n", result);
+ g_free (result);
+}
+
+static void
+ussd_initiate_ready (MMModem3gppUssd *modem_3gpp_ussd,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gchar *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_3gpp_ussd_initiate_finish (modem_3gpp_ussd, result, &error);
+ ussd_initiate_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+ussd_respond_process_reply (gchar *result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't send response in USSD session: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("response successfully sent in USSD session; "
+ "new reply from network: '%s'\n", result);
+ g_free (result);
+}
+
+static void
+ussd_respond_ready (MMModem3gppUssd *modem_3gpp_ussd,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gchar *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_3gpp_ussd_respond_finish (modem_3gpp_ussd, result, &error);
+ ussd_respond_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+ussd_cancel_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't cancel USSD session: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully cancelled USSD session\n");
+}
+
+static void
+ussd_cancel_ready (MMModem3gppUssd *modem_3gpp_ussd,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_3gpp_ussd_cancel_finish (modem_3gpp_ussd, result, &error);
+ ussd_cancel_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
+ ctx->modem_3gpp_ussd = mm_object_get_modem_3gpp_ussd (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_3gpp)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
+ if (ctx->modem_3gpp_ussd)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp_ussd));
+
+ ensure_modem_3gpp ();
+
+ if (ussd_status_flag)
+ g_assert_not_reached ();
+
+ /* Request to scan networks? */
+ if (scan_flag) {
+ g_debug ("Asynchronously scanning for networks...");
+ mm_modem_3gpp_scan (ctx->modem_3gpp,
+ ctx->cancellable,
+ (GAsyncReadyCallback)scan_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to register the modem? */
+ if (register_in_operator_str || register_home_flag) {
+ g_debug ("Asynchronously registering the modem...");
+ mm_modem_3gpp_register (ctx->modem_3gpp,
+ (register_in_operator_str ? register_in_operator_str : ""),
+ ctx->cancellable,
+ (GAsyncReadyCallback)register_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to initiate USSD session? */
+ if (ussd_initiate_str) {
+ ensure_modem_3gpp_ussd ();
+
+ g_debug ("Asynchronously initiating USSD session...");
+ mm_modem_3gpp_ussd_initiate (ctx->modem_3gpp_ussd,
+ ussd_initiate_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)ussd_initiate_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to respond in USSD session? */
+ if (ussd_respond_str) {
+ ensure_modem_3gpp_ussd ();
+
+ g_debug ("Asynchronously sending response in USSD session...");
+ mm_modem_3gpp_ussd_respond (ctx->modem_3gpp_ussd,
+ ussd_respond_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)ussd_respond_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to cancel USSD session? */
+ if (ussd_cancel_flag) {
+ ensure_modem_3gpp_ussd ();
+
+ g_debug ("Asynchronously cancelling USSD session...");
+ mm_modem_3gpp_ussd_cancel (ctx->modem_3gpp_ussd,
+ ctx->cancellable,
+ (GAsyncReadyCallback)ussd_cancel_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_3gpp_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_3gpp_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
+ ctx->modem_3gpp_ussd = mm_object_get_modem_3gpp_ussd (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_3gpp)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
+ if (ctx->modem_3gpp_ussd)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp_ussd));
+
+ ensure_modem_3gpp ();
+
+ if (scan_flag)
+ g_assert_not_reached ();
+ if (ussd_initiate_str)
+ g_assert_not_reached ();
+ if (ussd_respond_str)
+ g_assert_not_reached ();
+
+ /* Request to register the modem? */
+ if (register_in_operator_str || register_home_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously registering the modem...");
+ result = mm_modem_3gpp_register_sync (
+ ctx->modem_3gpp,
+ (register_in_operator_str ? register_in_operator_str : ""),
+ NULL,
+ &error);
+ register_process_reply (result, error);
+ return;
+ }
+
+ /* Request to show USSD status? */
+ if (ussd_status_flag) {
+ ensure_modem_3gpp_ussd ();
+
+ g_debug ("Printing USSD status...");
+ print_ussd_status ();
+ return;
+ }
+
+ /* Request to cancel USSD session? */
+ if (ussd_cancel_flag) {
+ gboolean result;
+
+ ensure_modem_3gpp_ussd ();
+
+ g_debug ("Asynchronously cancelling USSD session...");
+ result = mm_modem_3gpp_ussd_cancel_sync (ctx->modem_3gpp_ussd,
+ NULL,
+ &error);
+ ussd_cancel_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-cdma.c b/cli/mmcli-modem-cdma.c
new file mode 100644
index 0000000..8841f7e
--- /dev/null
+++ b/cli/mmcli-modem-cdma.c
@@ -0,0 +1,236 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 - Google Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemCdma *modem_cdma;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gchar *activate_str;
+
+static GOptionEntry entries[] = {
+ { "cdma-activate", 0, 0, G_OPTION_ARG_STRING, &activate_str,
+ "Provision the modem to use with a given carrier using OTA settings.",
+ "[CARRIER]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_cdma_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("cdma",
+ "CDMA options",
+ "Show CDMA related options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_cdma_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (!!activate_str);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many CDMA actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_cdma)
+ g_object_unref (ctx->modem_cdma);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_cdma (void)
+{
+ if (mm_modem_get_state (mm_object_peek_modem (ctx->object)) < MM_MODEM_STATE_ENABLED) {
+ g_printerr ("error: modem not enabled yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_cdma) {
+ g_printerr ("error: modem has no CDMA capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_cdma_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+activate_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't activate the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully activated the modem\n");
+}
+
+static void
+activate_ready (MMModemCdma *modem_cdma,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_cdma_activate_finish (modem_cdma, result, &error);
+ activate_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_cdma)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
+
+ ensure_modem_cdma ();
+
+ /* Request to activate the modem? */
+ if (activate_str) {
+ g_debug ("Asynchronously activating the modem...");
+ mm_modem_cdma_activate (ctx->modem_cdma,
+ activate_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)activate_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_cdma_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_cdma_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_cdma)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
+
+ ensure_modem_cdma ();
+
+ /* Request to activate the modem? */
+ if (activate_str) {
+ gboolean result;
+
+ g_debug ("Synchronously activating the modem...");
+ result = mm_modem_cdma_activate_sync (
+ ctx->modem_cdma,
+ activate_str,
+ NULL,
+ &error);
+ activate_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-firmware.c b/cli/mmcli-modem-firmware.c
new file mode 100644
index 0000000..166c76e
--- /dev/null
+++ b/cli/mmcli-modem-firmware.c
@@ -0,0 +1,333 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemFirmware *modem_firmware;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean list_flag;
+static gchar *select_str;
+
+static GOptionEntry entries[] = {
+ { "firmware-list", 0, 0, G_OPTION_ARG_NONE, &list_flag,
+ "List firmware images installed in a given modem",
+ NULL
+ },
+ { "firmware-select", 0, 0, G_OPTION_ARG_STRING, &select_str,
+ "Select a given firmware image",
+ "[Unique ID]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_firmware_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("firmware",
+ "Firmware options",
+ "Show Firmware options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_firmware_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (list_flag +
+ !!select_str);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many Firmware actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_firmware)
+ g_object_unref (ctx->modem_firmware);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_firmware (void)
+{
+ if (!ctx->modem_firmware) {
+ g_printerr ("error: modem has no firmware capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_firmware_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+list_process_reply (MMFirmwareProperties *selected,
+ GList *result,
+ const GError *error)
+{
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+
+ if (error) {
+ g_printerr ("error: couldn't list firmware images: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("\n");
+ if (!result) {
+ g_print ("No firmware images were found\n");
+ } else {
+ GList *l;
+ guint i;
+
+ g_print ("Found %u firmware images:\n", g_list_length (result));
+ for (l = result, i = 0; l; l = g_list_next (l), i++) {
+ MMFirmwareProperties *props = MM_FIRMWARE_PROPERTIES (l->data);
+
+ g_print ("\t[%u] %s%s\n"
+ "\t\tType: '%s'\n",
+ i,
+ mm_firmware_properties_get_unique_id (props),
+ ((selected &&
+ g_str_equal (mm_firmware_properties_get_unique_id (props),
+ mm_firmware_properties_get_unique_id (selected))) ?
+ " (CURRENT)" : ""),
+ mm_firmware_image_type_get_string (
+ mm_firmware_properties_get_image_type (props)));
+
+ if (mm_firmware_properties_get_image_type (props) == MM_FIRMWARE_IMAGE_TYPE_GOBI) {
+ g_print ("\t\t[Gobi] PRI version: '%s'\n"
+ "\t\t[Gobi] PRI info: '%s'\n"
+ "\t\t[Gobi] Boot version: '%s'\n"
+ "\t\t[Gobi] PRI Unique ID: '%s'\n"
+ "\t\t[Gobi] Modem Unique ID: '%s'\n",
+ VALIDATE_UNKNOWN (mm_firmware_properties_get_gobi_pri_version (props)),
+ VALIDATE_UNKNOWN (mm_firmware_properties_get_gobi_pri_info (props)),
+ VALIDATE_UNKNOWN (mm_firmware_properties_get_gobi_boot_version (props)),
+ VALIDATE_UNKNOWN (mm_firmware_properties_get_gobi_pri_unique_id (props)),
+ VALIDATE_UNKNOWN (mm_firmware_properties_get_gobi_modem_unique_id (props)));
+ }
+
+ g_object_unref (props);
+ }
+ g_list_free (result);
+ }
+
+ if (selected)
+ g_object_unref (selected);
+}
+
+static void
+list_ready (MMModemFirmware *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ GList *installed = NULL;
+ MMFirmwareProperties *selected = NULL;
+ GError *error = NULL;
+
+ mm_modem_firmware_list_finish (modem, result, &selected, &installed, &error);
+ list_process_reply (selected, installed, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+select_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't select firmware image: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("Successfully selected firmware image\n");
+}
+
+static void
+create_ready (MMModemFirmware *modem,
+ GAsyncResult *result)
+{
+ gboolean res;
+ GError *error = NULL;
+
+ res = mm_modem_firmware_select_finish (modem, result, &error);
+ select_process_reply (res, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_firmware = mm_object_get_modem_firmware (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_firmware)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_firmware));
+
+ ensure_modem_firmware ();
+
+ /* Request to list images? */
+ if (list_flag) {
+ g_debug ("Asynchronously listing firmware images in modem...");
+ mm_modem_firmware_list (ctx->modem_firmware,
+ ctx->cancellable,
+ (GAsyncReadyCallback)list_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to select a given image? */
+ if (select_str) {
+ g_debug ("Asynchronously selecting firmware image in modem...");
+ mm_modem_firmware_select (ctx->modem_firmware,
+ select_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)create_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_firmware_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_firmware_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_firmware = mm_object_get_modem_firmware (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_firmware)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_firmware));
+
+ ensure_modem_firmware ();
+
+ /* Request to list firmware images? */
+ if (list_flag) {
+ GList *installed = NULL;
+ MMFirmwareProperties *selected = NULL;
+
+ g_debug ("Synchronously listing firmware images in modem...");
+ mm_modem_firmware_list_sync (ctx->modem_firmware,
+ &selected,
+ &installed,
+ NULL,
+ &error);
+ list_process_reply (selected, installed, error);
+ return;
+ }
+
+ /* Request to select a given image? */
+ if (select_str) {
+ gboolean result;
+ GError *error = NULL;
+
+ g_debug ("Synchronously selecting firmware image in modem...");
+ result = mm_modem_firmware_select_sync (ctx->modem_firmware,
+ select_str,
+ NULL,
+ &error);
+ select_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-location.c b/cli/mmcli-modem-location.c
new file mode 100644
index 0000000..caf1bf2
--- /dev/null
+++ b/cli/mmcli-modem-location.c
@@ -0,0 +1,589 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 Google, Inc.
+ * Copyright (C) 2012 Lanedo GmbH <aleksander@lanedo.com>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemLocation *modem_location;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean status_flag;
+static gboolean enable_3gpp_flag;
+static gboolean disable_3gpp_flag;
+static gboolean get_3gpp_flag;
+static gboolean enable_gps_nmea_flag;
+static gboolean disable_gps_nmea_flag;
+static gboolean get_gps_nmea_flag;
+static gboolean enable_gps_raw_flag;
+static gboolean disable_gps_raw_flag;
+static gboolean get_gps_raw_flag;
+static gboolean enable_cdma_bs_flag;
+static gboolean disable_cdma_bs_flag;
+static gboolean get_cdma_bs_flag;
+static gboolean get_all_flag;
+
+static GOptionEntry entries[] = {
+ { "location-status", 0, 0, G_OPTION_ARG_NONE, &status_flag,
+ "Show status of location gathering.",
+ NULL
+ },
+ { "location-get", 0, 0, G_OPTION_ARG_NONE, &get_all_flag,
+ "Get all available location information.",
+ NULL
+ },
+ { "location-enable-3gpp", 0, 0, G_OPTION_ARG_NONE, &enable_3gpp_flag,
+ "Enable 3GPP location gathering.",
+ NULL
+ },
+ { "location-disable-3gpp", 0, 0, G_OPTION_ARG_NONE, &disable_3gpp_flag,
+ "Disable 3GPP location gathering.",
+ NULL
+ },
+ { "location-get-3gpp", 0, 0, G_OPTION_ARG_NONE, &get_3gpp_flag,
+ "Get 3GPP-based location.",
+ NULL
+ },
+ { "location-enable-gps-nmea", 0, 0, G_OPTION_ARG_NONE, &enable_gps_nmea_flag,
+ "Enable NMEA-based GPS location gathering.",
+ NULL
+ },
+ { "location-disable-gps-nmea", 0, 0, G_OPTION_ARG_NONE, &disable_gps_nmea_flag,
+ "Disable NMEA-based GPS location gathering.",
+ NULL
+ },
+ { "location-get-gps-nmea", 0, 0, G_OPTION_ARG_NONE, &get_gps_nmea_flag,
+ "Get NMEA GPS traces.",
+ NULL
+ },
+ { "location-enable-gps-raw", 0, 0, G_OPTION_ARG_NONE, &enable_gps_raw_flag,
+ "Enable raw GPS location gathering.",
+ NULL
+ },
+ { "location-disable-gps-raw", 0, 0, G_OPTION_ARG_NONE, &disable_gps_raw_flag,
+ "Disable raw GPS location gathering.",
+ NULL
+ },
+ { "location-get-gps-raw", 0, 0, G_OPTION_ARG_NONE, &get_gps_raw_flag,
+ "Get raw GPS location.",
+ NULL
+ },
+ { "location-enable-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &enable_cdma_bs_flag,
+ "Enable CDMA base station location gathering.",
+ NULL
+ },
+ { "location-disable-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &disable_cdma_bs_flag,
+ "Disable CDMA base station location gathering.",
+ NULL
+ },
+ { "location-get-cdma-bs", 0, 0, G_OPTION_ARG_NONE, &get_cdma_bs_flag,
+ "Get CDMA base station location.",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_location_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("location",
+ "Location options",
+ "Show Location options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_location_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ if ((enable_3gpp_flag && disable_3gpp_flag) ||
+ (enable_gps_nmea_flag && disable_gps_nmea_flag) ||
+ (enable_gps_raw_flag && disable_gps_raw_flag) ||
+ (enable_cdma_bs_flag && disable_cdma_bs_flag)) {
+ g_printerr ("error: cannot enable and disable the same source\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (get_all_flag) {
+ get_3gpp_flag = TRUE;
+ get_gps_nmea_flag = TRUE;
+ get_gps_raw_flag = TRUE;
+ get_cdma_bs_flag = TRUE;
+ }
+
+ n_actions = (status_flag +
+ !!(enable_3gpp_flag +
+ disable_3gpp_flag +
+ enable_gps_nmea_flag +
+ disable_gps_nmea_flag +
+ enable_gps_raw_flag +
+ disable_gps_raw_flag +
+ enable_cdma_bs_flag +
+ disable_cdma_bs_flag) +
+ !!(get_3gpp_flag +
+ get_gps_nmea_flag +
+ get_gps_raw_flag +
+ get_cdma_bs_flag));
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many Location actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (status_flag)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_location)
+ g_object_unref (ctx->modem_location);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_location (void)
+{
+ if (mm_modem_get_state (mm_object_peek_modem (ctx->object)) < MM_MODEM_STATE_ENABLED) {
+ g_printerr ("error: modem not enabled yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_location) {
+ g_printerr ("error: modem has no location capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_location_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+print_location_status (void)
+{
+ gchar *capabilities_str;
+ gchar *enabled_str;
+
+ capabilities_str = (mm_modem_location_source_build_string_from_mask (
+ mm_modem_location_get_capabilities (ctx->modem_location)));
+ enabled_str = (mm_modem_location_source_build_string_from_mask (
+ mm_modem_location_get_enabled (ctx->modem_location)));
+ g_print ("\n"
+ "%s\n"
+ " ----------------------------\n"
+ " Location | capabilities: '%s'\n"
+ " | enabled: '%s'\n"
+ " | signals: '%s'\n",
+ mm_modem_location_get_path (ctx->modem_location),
+ capabilities_str,
+ enabled_str,
+ mm_modem_location_signals_location (ctx->modem_location) ? "yes" : "no");
+ g_free (capabilities_str);
+ g_free (enabled_str);
+}
+
+static void
+setup_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't setup location gathering: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully setup location gathering\n");
+}
+
+static void
+setup_ready (MMModemLocation *modem_location,
+ GAsyncResult *result)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_location_setup_finish (modem_location, result, &error);
+ setup_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static MMModemLocationSource
+build_sources_from_flags (void)
+{
+ MMModemLocationSource sources;
+
+ /* Base the new actions on the previously enabled sources */
+ sources = mm_modem_location_get_enabled (ctx->modem_location);
+
+ if (enable_3gpp_flag)
+ sources |= MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI;
+ if (disable_3gpp_flag)
+ sources &= ~MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI;
+
+ if (enable_gps_nmea_flag)
+ sources |= MM_MODEM_LOCATION_SOURCE_GPS_NMEA;
+ if (disable_gps_nmea_flag)
+ sources &= ~MM_MODEM_LOCATION_SOURCE_GPS_NMEA;
+
+ if (enable_gps_raw_flag)
+ sources |= MM_MODEM_LOCATION_SOURCE_GPS_RAW;
+ if (disable_gps_raw_flag)
+ sources &= ~MM_MODEM_LOCATION_SOURCE_GPS_RAW;
+
+ if (enable_cdma_bs_flag)
+ sources |= MM_MODEM_LOCATION_SOURCE_CDMA_BS;
+ if (disable_cdma_bs_flag)
+ sources &= ~MM_MODEM_LOCATION_SOURCE_CDMA_BS;
+
+ return sources;
+}
+
+static void
+get_location_process_reply (MMLocation3gpp *location_3gpp,
+ MMLocationGpsNmea *location_gps_nmea,
+ MMLocationGpsRaw *location_gps_raw,
+ MMLocationCdmaBs *location_cdma_bs,
+ const GError *error)
+{
+ /* First, check for failures */
+ if (!get_all_flag) {
+ gboolean exit_error = FALSE;
+
+ if (get_3gpp_flag && !location_3gpp) {
+ g_printerr ("error: couldn't get 3GPP-based location from the modem: '%s'\n",
+ error ? error->message : "not available");
+ exit_error = TRUE;
+ }
+
+ if (get_gps_nmea_flag && !location_gps_nmea) {
+ g_printerr ("error: couldn't get NMEA GPS traces from the modem: '%s'\n",
+ error ? error->message : "not available");
+ exit_error = TRUE;
+ }
+
+ if (get_gps_raw_flag && !location_gps_raw) {
+ g_printerr ("error: couldn't get raw GPS location from the modem: '%s'\n",
+ error ? error->message : "not available");
+ exit_error = TRUE;
+ }
+
+ if (get_cdma_bs_flag && !location_cdma_bs) {
+ g_printerr ("error: couldn't get CDMA base station location from the modem: '%s'\n",
+ error ? error->message : "not available");
+ exit_error = TRUE;
+ }
+
+ if (exit_error)
+ exit (EXIT_FAILURE);
+ } else if (error) {
+ g_printerr ("error: couldn't get location from the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("\n"
+ "%s\n",
+ mm_modem_location_get_path (ctx->modem_location));
+
+ if (get_3gpp_flag) {
+ if (location_3gpp)
+ g_print (" -------------------------\n"
+ " 3GPP location | Mobile country code: '%u'\n"
+ " | Mobile network code: '%u'\n"
+ " | Location area code: '%lu'\n"
+ " | Cell ID: '%lu'\n",
+ mm_location_3gpp_get_mobile_country_code (location_3gpp),
+ mm_location_3gpp_get_mobile_network_code (location_3gpp),
+ mm_location_3gpp_get_location_area_code (location_3gpp),
+ mm_location_3gpp_get_cell_id (location_3gpp));
+ else
+ g_print (" -------------------------\n"
+ " 3GPP location | Not available\n");
+ }
+
+ if (get_gps_nmea_flag) {
+ gchar *full = NULL;
+
+ if (location_gps_nmea)
+ full = mm_location_gps_nmea_build_full (location_gps_nmea);
+
+ if (full) {
+ gchar *prefixed;
+
+ prefixed = mmcli_prefix_newlines (" | ", full);
+ g_print (" -------------------------\n"
+ " GPS NMEA traces | %s\n",
+ prefixed);
+ g_free (prefixed);
+ g_free (full);
+ } else
+ g_print (" -------------------------\n"
+ " GPS NMEA traces | Not available\n");
+ }
+
+ if (get_gps_raw_flag) {
+ if (location_gps_raw)
+ g_print (" -------------------------\n"
+ " Raw GPS | UTC time: '%s'\n"
+ " | Longitude: '%lf'\n"
+ " | Latitude: '%lf'\n"
+ " | Altitude: '%lf'\n",
+ mm_location_gps_raw_get_utc_time (location_gps_raw),
+ mm_location_gps_raw_get_longitude (location_gps_raw),
+ mm_location_gps_raw_get_latitude (location_gps_raw),
+ mm_location_gps_raw_get_altitude (location_gps_raw));
+ else
+ g_print (" -------------------------\n"
+ " Raw GPS | Not available\n");
+ }
+
+ if (get_cdma_bs_flag) {
+ if (location_cdma_bs)
+ g_print (" -------------------------\n"
+ " CDMA BS | Longitude: '%lf'\n"
+ " | Latitude: '%lf'\n",
+ mm_location_cdma_bs_get_longitude (location_cdma_bs),
+ mm_location_cdma_bs_get_latitude (location_cdma_bs));
+ else
+ g_print (" -------------------------\n"
+ " CDMA BS | Not available\n");
+ }
+
+ if (location_3gpp)
+ g_object_unref (location_3gpp);
+ if (location_gps_nmea)
+ g_object_unref (location_gps_nmea);
+ if (location_gps_raw)
+ g_object_unref (location_gps_raw);
+ if (location_cdma_bs)
+ g_object_unref (location_cdma_bs);
+}
+
+static void
+get_location_ready (MMModemLocation *modem_location,
+ GAsyncResult *result)
+{
+ MMLocation3gpp *location_3gpp = NULL;
+ MMLocationGpsNmea *location_gps_nmea = NULL;
+ MMLocationGpsRaw *location_gps_raw = NULL;
+ MMLocationCdmaBs *location_cdma_bs = NULL;
+ GError *error = NULL;
+
+ mm_modem_location_get_full_finish (modem_location,
+ result,
+ get_3gpp_flag ? &location_3gpp : NULL,
+ get_gps_nmea_flag ? &location_gps_nmea : NULL,
+ get_gps_raw_flag ? &location_gps_raw : NULL,
+ get_cdma_bs_flag ? &location_cdma_bs : NULL,
+ &error);
+ get_location_process_reply (location_3gpp, location_gps_nmea, location_gps_raw, location_cdma_bs, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_location = mm_object_get_modem_location (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_location)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_location));
+
+ ensure_modem_location ();
+
+ if (status_flag)
+ g_assert_not_reached ();
+
+ /* Request to setup location gathering? */
+ if (enable_3gpp_flag ||
+ disable_3gpp_flag ||
+ enable_gps_nmea_flag ||
+ disable_gps_nmea_flag ||
+ enable_gps_raw_flag ||
+ disable_gps_raw_flag ||
+ enable_cdma_bs_flag ||
+ disable_cdma_bs_flag) {
+ g_debug ("Asynchronously setting up location gathering...");
+ mm_modem_location_setup (ctx->modem_location,
+ build_sources_from_flags (),
+ mm_modem_location_signals_location (ctx->modem_location),
+ ctx->cancellable,
+ (GAsyncReadyCallback)setup_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to get location from the modem? */
+ if (get_3gpp_flag ||
+ get_gps_nmea_flag ||
+ get_gps_raw_flag ||
+ get_cdma_bs_flag) {
+ g_debug ("Asynchronously getting location from the modem...");
+ mm_modem_location_get_full (ctx->modem_location,
+ ctx->cancellable,
+ (GAsyncReadyCallback)get_location_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_location_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_location_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_location = mm_object_get_modem_location (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_location)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_location));
+
+ ensure_modem_location ();
+
+ /* Request to get location status? */
+ if (status_flag) {
+ g_debug ("Printing location status...");
+ print_location_status ();
+ return;
+ }
+
+ /* Request to setup location gathering? */
+ if (enable_3gpp_flag ||
+ disable_3gpp_flag ||
+ enable_gps_nmea_flag ||
+ disable_gps_nmea_flag ||
+ enable_gps_raw_flag ||
+ disable_gps_raw_flag ||
+ enable_cdma_bs_flag ||
+ disable_cdma_bs_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously setting up location gathering...");
+ result = mm_modem_location_setup_sync (ctx->modem_location,
+ build_sources_from_flags (),
+ mm_modem_location_signals_location (ctx->modem_location),
+ NULL,
+ &error);
+ setup_process_reply (result, error);
+ return;
+ }
+
+ /* Request to get location from the modem? */
+ if (get_3gpp_flag ||
+ get_gps_nmea_flag ||
+ get_gps_raw_flag ||
+ get_cdma_bs_flag) {
+ MMLocation3gpp *location_3gpp = NULL;
+ MMLocationGpsNmea *location_gps_nmea = NULL;
+ MMLocationGpsRaw *location_gps_raw = NULL;
+ MMLocationCdmaBs *location_cdma_bs = NULL;
+
+ g_debug ("Synchronously getting location from the modem...");
+ mm_modem_location_get_full_sync (ctx->modem_location,
+ get_3gpp_flag ? &location_3gpp : NULL,
+ get_gps_nmea_flag ? &location_gps_nmea : NULL,
+ get_gps_raw_flag ? &location_gps_raw : NULL,
+ get_cdma_bs_flag ? &location_cdma_bs : NULL,
+ NULL,
+ &error);
+ get_location_process_reply (location_3gpp, location_gps_nmea, location_gps_raw, location_cdma_bs, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-messaging.c b/cli/mmcli-modem-messaging.c
new file mode 100644
index 0000000..604bf90
--- /dev/null
+++ b/cli/mmcli-modem-messaging.c
@@ -0,0 +1,478 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemMessaging *modem_messaging;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean status_flag;
+static gboolean list_flag;
+static gchar *create_str;
+static gchar *create_with_data_str;
+static gchar *delete_str;
+
+static GOptionEntry entries[] = {
+ { "messaging-status", 0, 0, G_OPTION_ARG_NONE, &status_flag,
+ "Show status of messaging support.",
+ NULL
+ },
+ { "messaging-list-sms", 0, 0, G_OPTION_ARG_NONE, &list_flag,
+ "List SMS messages available in a given modem",
+ NULL
+ },
+ { "messaging-create-sms", 0, 0, G_OPTION_ARG_STRING, &create_str,
+ "Create a new SMS in a given modem",
+ "[\"key=value,...\"]"
+ },
+ { "messaging-create-sms-with-data", 0, 0, G_OPTION_ARG_STRING, &create_with_data_str,
+ "Pass the given file as data contents when creating a new SMS",
+ "[File path]"
+ },
+ { "messaging-delete-sms", 0, 0, G_OPTION_ARG_STRING, &delete_str,
+ "Delete a SMS from a given modem",
+ "[PATH]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_messaging_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("messaging",
+ "Messaging options",
+ "Show Messaging options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_messaging_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (status_flag +
+ list_flag +
+ !!create_str +
+ !!delete_str);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many Messaging actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (create_with_data_str && !create_str) {
+ g_printerr ("error: `--messaging-create-with-data' must be given along "
+ "with `--messaging-create-sms'\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (status_flag)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_messaging)
+ g_object_unref (ctx->modem_messaging);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_messaging (void)
+{
+ if (mm_modem_get_state (mm_object_peek_modem (ctx->object)) < MM_MODEM_STATE_ENABLED) {
+ g_printerr ("error: modem not enabled yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_messaging) {
+ g_printerr ("error: modem has no messaging capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_messaging_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static MMSmsProperties *
+build_sms_properties_from_input (const gchar *properties_string,
+ const gchar *data_file)
+{
+ GError *error = NULL;
+ MMSmsProperties *properties;
+
+ properties = mm_sms_properties_new_from_string (properties_string, &error);
+ if (!properties) {
+ g_printerr ("error: cannot parse properties string: '%s'\n", error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ if (data_file) {
+ gchar *path;
+ GFile *file;
+ gchar *contents;
+ gsize contents_size;
+
+ g_debug ("Reading data from file '%s'", data_file);
+
+ file = g_file_new_for_commandline_arg (data_file);
+ path = g_file_get_path (file);
+ if (!g_file_get_contents (path,
+ &contents,
+ &contents_size,
+ &error)) {
+ g_printerr ("error: cannot read from file '%s': '%s'\n",
+ data_file, error->message);
+ exit (EXIT_FAILURE);
+ }
+ g_free (path);
+ g_object_unref (file);
+
+ mm_sms_properties_set_data (properties, (guint8 *)contents, contents_size);
+ }
+
+ return properties;
+}
+
+static void
+print_messaging_status (void)
+{
+ MMSmsStorage *supported = NULL;
+ guint supported_len = 0;
+ gchar *supported_str = NULL;
+
+ mm_modem_messaging_get_supported_storages (ctx->modem_messaging,
+ &supported,
+ &supported_len);
+ if (supported)
+ supported_str = mm_common_build_sms_storages_string (supported, supported_len);
+
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+
+ g_print ("\n"
+ "%s\n"
+ " ----------------------------\n"
+ " Messaging | supported storages: '%s'\n"
+ " | default storage: '%s'\n",
+ mm_modem_messaging_get_path (ctx->modem_messaging),
+ VALIDATE_UNKNOWN (supported_str),
+ VALIDATE_UNKNOWN (mm_sms_storage_get_string (
+ mm_modem_messaging_get_default_storage (
+ ctx->modem_messaging))));
+ g_free (supported_str);
+}
+
+static void
+print_sms_short_info (MMSms *sms)
+{
+ g_print ("\t%s (%s)\n",
+ mm_sms_get_path (sms),
+ mm_sms_state_get_string (mm_sms_get_state (sms)));
+}
+
+static void
+list_process_reply (GList *result,
+ const GError *error)
+{
+ if (error) {
+ g_printerr ("error: couldn't list SMS: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("\n");
+ if (!result) {
+ g_print ("No SMS messages were found\n");
+ } else {
+ GList *l;
+
+ g_print ("Found %u SMS messages:\n", g_list_length (result));
+ for (l = result; l; l = g_list_next (l)) {
+ MMSms *sms = MM_SMS (l->data);
+
+ print_sms_short_info (sms);
+ g_object_unref (sms);
+ }
+ g_list_free (result);
+ }
+}
+
+static void
+list_ready (MMModemMessaging *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ GList *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_messaging_list_finish (modem, result, &error);
+ list_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+create_process_reply (MMSms *sms,
+ const GError *error)
+{
+ if (!sms) {
+ g_printerr ("error: couldn't create new SMS: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("Successfully created new SMS:\n");
+ print_sms_short_info (sms);
+ g_object_unref (sms);
+}
+
+static void
+create_ready (MMModemMessaging *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ MMSms *sms;
+ GError *error = NULL;
+
+ sms = mm_modem_messaging_create_finish (modem, result, &error);
+ create_process_reply (sms, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+delete_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't delete SMS: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully deleted SMS from modem\n");
+}
+
+static void
+delete_ready (MMModemMessaging *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_messaging_delete_finish (modem, result, &error);
+ delete_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_messaging)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));
+
+ ensure_modem_messaging ();
+
+ if (status_flag)
+ g_assert_not_reached ();
+
+ /* Request to list SMS? */
+ if (list_flag) {
+ g_debug ("Asynchronously listing SMS in modem...");
+ mm_modem_messaging_list (ctx->modem_messaging,
+ ctx->cancellable,
+ (GAsyncReadyCallback)list_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to create a new SMS? */
+ if (create_str) {
+ MMSmsProperties *properties;
+
+ properties = build_sms_properties_from_input (create_str,
+ create_with_data_str);
+ g_debug ("Asynchronously creating new SMS in modem...");
+ mm_modem_messaging_create (ctx->modem_messaging,
+ properties,
+ ctx->cancellable,
+ (GAsyncReadyCallback)create_ready,
+ NULL);
+ g_object_unref (properties);
+ return;
+ }
+
+ /* Request to delete a given SMS? */
+ if (delete_str) {
+ mm_modem_messaging_delete (ctx->modem_messaging,
+ delete_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)delete_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_messaging_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_messaging_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_messaging = mm_object_get_modem_messaging (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_messaging)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_messaging));
+
+ ensure_modem_messaging ();
+
+ /* Request to get location status? */
+ if (status_flag) {
+ g_debug ("Printing messaging status...");
+ print_messaging_status ();
+ return;
+ }
+
+ /* Request to list the SMS? */
+ if (list_flag) {
+ GList *result;
+
+ g_debug ("Synchronously listing SMS messages...");
+ result = mm_modem_messaging_list_sync (ctx->modem_messaging, NULL, &error);
+ list_process_reply (result, error);
+ return;
+ }
+
+ /* Request to create a new SMS? */
+ if (create_str) {
+ MMSms *sms;
+ GError *error = NULL;
+ MMSmsProperties *properties;
+
+ properties = build_sms_properties_from_input (create_str,
+ create_with_data_str);
+ g_debug ("Synchronously creating new SMS in modem...");
+ sms = mm_modem_messaging_create_sync (ctx->modem_messaging,
+ properties,
+ NULL,
+ &error);
+ g_object_unref (properties);
+
+ create_process_reply (sms, error);
+ return;
+ }
+
+ /* Request to delete a given SMS? */
+ if (delete_str) {
+ gboolean result;
+
+ result = mm_modem_messaging_delete_sync (ctx->modem_messaging,
+ delete_str,
+ NULL,
+ &error);
+
+ delete_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-simple.c b/cli/mmcli-modem-simple.c
new file mode 100644
index 0000000..22976a9
--- /dev/null
+++ b/cli/mmcli-modem-simple.c
@@ -0,0 +1,447 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemSimple *modem_simple;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gchar *connect_str;
+static gboolean disconnect_flag;
+static gboolean status_flag;
+
+static GOptionEntry entries[] = {
+ { "simple-connect", 0, 0, G_OPTION_ARG_STRING, &connect_str,
+ "Run full connection sequence.",
+ "[\"key=value,...\"]"
+ },
+ { "simple-disconnect", 0, 0, G_OPTION_ARG_NONE, &disconnect_flag,
+ "Disconnect all connected bearers.",
+ NULL
+ },
+ { "simple-status", 0, 0, G_OPTION_ARG_NONE, &status_flag,
+ "Show compilation of status properties.",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_simple_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("simple",
+ "Simple options",
+ "Show Simple options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_simple_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (!!connect_str +
+ disconnect_flag +
+ status_flag);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many Simple actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Simple connection may take really a long time, so we do it asynchronously
+ * always to avoid DBus timeouts */
+ if (connect_str)
+ mmcli_force_async_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_simple)
+ g_object_unref (ctx->modem_simple);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_simple (void)
+{
+ if (!ctx->modem_simple) {
+ g_printerr ("error: modem has no Simple capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_simple_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+connect_process_reply (MMBearer *result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't connect the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully connected the modem\n");
+ g_object_unref (result);
+}
+
+static void
+connect_ready (MMModemSimple *modem_simple,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ MMBearer *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_simple_connect_finish (modem_simple, result, &error);
+ connect_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+disconnect_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't disconnect all bearers in the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully disconnected all bearers in the modem\n");
+}
+
+static void
+disconnect_ready (MMModemSimple *modem_simple,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_simple_disconnect_finish (modem_simple, result, &error);
+ disconnect_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+status_process_reply (MMSimpleStatus *result,
+ const GError *error)
+{
+ MMModemState state;
+
+ if (!result) {
+ g_printerr ("error: couldn't get status from the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+
+ g_print ("\n"
+ "%s\n",
+ VALIDATE_UNKNOWN (mm_modem_simple_get_path (ctx->modem_simple)));
+
+ state = mm_simple_status_get_state (result);
+
+
+ g_print (" -------------------------\n"
+ " Status | state: '%s'\n",
+ mm_modem_state_get_string (state));
+
+ if (state >= MM_MODEM_STATE_REGISTERED) {
+ const MMModemBand *bands = NULL;
+ guint n_bands = 0;
+ gchar *bands_str;
+ gchar *access_tech_str;
+ guint signal_quality;
+ gboolean signal_quality_recent = FALSE;
+
+ signal_quality = (mm_simple_status_get_signal_quality (
+ result,
+ &signal_quality_recent));
+ mm_simple_status_get_current_bands (result, &bands, &n_bands);
+ bands_str = mm_common_build_bands_string (bands, n_bands);
+ access_tech_str = (mm_modem_access_technology_build_string_from_mask (
+ mm_simple_status_get_access_technologies (result)));
+
+ g_print (" | signal quality: '%u' (%s)\n"
+ " | bands: '%s'\n"
+ " | access tech: '%s'\n",
+ signal_quality, signal_quality_recent ? "recent" : "cached",
+ VALIDATE_UNKNOWN (bands_str),
+ VALIDATE_UNKNOWN (access_tech_str));
+
+ if ((mm_simple_status_get_3gpp_registration_state (result) ==
+ MM_MODEM_3GPP_REGISTRATION_STATE_HOME) ||
+ (mm_simple_status_get_3gpp_registration_state (result) ==
+ MM_MODEM_3GPP_REGISTRATION_STATE_ROAMING)) {
+ g_print (" -------------------------\n"
+ " 3GPP | registration: '%s'\n"
+ " | operator code: '%s'\n"
+ " | operator name: '%s'\n",
+ mm_modem_3gpp_registration_state_get_string (
+ mm_simple_status_get_3gpp_registration_state (result)),
+ VALIDATE_UNKNOWN (mm_simple_status_get_3gpp_operator_code (result)),
+ VALIDATE_UNKNOWN (mm_simple_status_get_3gpp_operator_name (result)));
+ }
+
+ if ((mm_simple_status_get_cdma_cdma1x_registration_state (result) !=
+ MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN) ||
+ (mm_simple_status_get_cdma_evdo_registration_state (result) !=
+ MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN)) {
+ guint sid;
+ guint nid;
+ gchar *sid_str = NULL;
+ gchar *nid_str = NULL;
+
+ sid = mm_simple_status_get_cdma_sid (result);
+ sid_str = (sid != MM_MODEM_CDMA_SID_UNKNOWN ?
+ g_strdup_printf ("%u", sid) :
+ NULL);
+ nid = mm_simple_status_get_cdma_nid (result);
+ nid_str = (nid != MM_MODEM_CDMA_NID_UNKNOWN ?
+ g_strdup_printf ("%u", nid) :
+ NULL);
+
+ g_print (" -------------------------\n"
+ " CDMA | sid: '%s'\n"
+ " | nid: '%s'\n"
+ " | registration: CDMA1x '%s'\n"
+ " | EV-DO '%s'\n",
+ VALIDATE_UNKNOWN (sid_str),
+ VALIDATE_UNKNOWN (nid_str),
+ mm_modem_cdma_registration_state_get_string (
+ mm_simple_status_get_cdma_cdma1x_registration_state (result)),
+ mm_modem_cdma_registration_state_get_string (
+ mm_simple_status_get_cdma_evdo_registration_state (result)));
+
+ g_free (sid_str);
+ g_free (nid_str);
+ }
+
+ g_free (access_tech_str);
+ g_free (bands_str);
+ }
+
+ g_print ("\n");
+ g_object_unref (result);
+}
+
+static void
+status_ready (MMModemSimple *modem_simple,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ MMSimpleStatus *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_simple_get_status_finish (modem_simple, result, &error);
+ status_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_simple = mm_object_get_modem_simple (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_simple)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_simple));
+
+ ensure_modem_simple ();
+
+ /* Request to connect the modem? */
+ if (connect_str) {
+ GError *error = NULL;
+ MMSimpleConnectProperties *properties;
+
+ g_debug ("Asynchronously connecting the modem...");
+
+ properties = mm_simple_connect_properties_new_from_string (connect_str, &error);
+ if (!properties) {
+ g_printerr ("Error parsing connect string: '%s'\n", error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ mm_modem_simple_connect (ctx->modem_simple,
+ properties,
+ ctx->cancellable,
+ (GAsyncReadyCallback)connect_ready,
+ NULL);
+ g_object_unref (properties);
+ return;
+ }
+
+ /* Request to disconnect all bearers in the modem? */
+ if (disconnect_flag) {
+ g_debug ("Asynchronously disconnecting all bearers in the modem...");
+
+ mm_modem_simple_disconnect (ctx->modem_simple,
+ NULL,
+ ctx->cancellable,
+ (GAsyncReadyCallback)disconnect_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to get status from the modem? */
+ if (status_flag) {
+ g_debug ("Asynchronously getting status from the modem...");
+
+ mm_modem_simple_get_status (ctx->modem_simple,
+ ctx->cancellable,
+ (GAsyncReadyCallback)status_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_simple_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_simple_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_simple = mm_object_get_modem_simple (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_simple)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_simple));
+
+ ensure_modem_simple ();
+
+ if (connect_str)
+ g_assert_not_reached ();
+
+ /* Request to disconnect all bearers in the modem? */
+ if (disconnect_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously disconnecting all bearers in the modem...");
+
+ result = mm_modem_simple_disconnect_sync (ctx->modem_simple,
+ NULL,
+ NULL,
+ &error);
+ disconnect_process_reply (result, error);
+ return;
+ }
+
+ /* Request to get status from the modem? */
+ if (status_flag) {
+ MMSimpleStatus *result;
+
+ g_debug ("Synchronously getting status from the modem...");
+
+ result = mm_modem_simple_get_status_sync (ctx->modem_simple,
+ NULL,
+ &error);
+ status_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem-time.c b/cli/mmcli-modem-time.c
new file mode 100644
index 0000000..8dde6f4
--- /dev/null
+++ b/cli/mmcli-modem-time.c
@@ -0,0 +1,277 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModemTime *modem_time;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean time_flag;
+
+static GOptionEntry entries[] = {
+ { "time", 0, 0, G_OPTION_ARG_NONE, &time_flag,
+ "Get current network time",
+ NULL
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_time_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ group = g_option_group_new ("time",
+ "Time options",
+ "Show Time options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_time_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (time_flag);
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many Time actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem_time)
+ g_object_unref (ctx->modem_time);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+static void
+ensure_modem_time (void)
+{
+ if (mm_modem_get_state (mm_object_peek_modem (ctx->object)) < MM_MODEM_STATE_ENABLED) {
+ g_printerr ("error: modem not enabled yet\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!ctx->modem_time) {
+ g_printerr ("error: modem has no time capabilities\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Success */
+}
+
+void
+mmcli_modem_time_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+get_network_time_process_reply (gchar *time_string,
+ MMNetworkTimezone *timezone,
+ const GError *error)
+{
+ gchar *offset = NULL;
+ gchar *dst_offset = NULL;
+ gchar *leap_seconds = NULL;
+
+ if (error)
+ g_printerr ("error: couldn't get current network time: '%s'\n",
+ error->message);
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE
+#define VALIDATE(str) (str ? str : "not available")
+
+ if (timezone) {
+ if (mm_network_timezone_get_offset (timezone) != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
+ offset = g_strdup_printf ("%" G_GINT32_FORMAT, mm_network_timezone_get_offset (timezone));
+
+ if (mm_network_timezone_get_dst_offset (timezone) != MM_NETWORK_TIMEZONE_OFFSET_UNKNOWN)
+ dst_offset = g_strdup_printf ("%" G_GINT32_FORMAT, mm_network_timezone_get_dst_offset (timezone));
+
+ if (mm_network_timezone_get_leap_seconds (timezone) != MM_NETWORK_TIMEZONE_LEAP_SECONDS_UNKNOWN)
+ leap_seconds = g_strdup_printf ("%" G_GINT32_FORMAT, mm_network_timezone_get_leap_seconds (timezone));
+ }
+
+ g_print ("\n"
+ "%s\n"
+ " ----------------------------\n"
+ " Time | Current: '%s'\n"
+ " ----------------------------\n"
+ " Timezone | Offset: '%s'\n"
+ " | DST offset: '%s'\n"
+ " | Leap seconds: '%s'\n",
+ mm_modem_time_get_path (ctx->modem_time),
+ VALIDATE (time_string),
+ VALIDATE (offset),
+ VALIDATE (dst_offset),
+ VALIDATE (leap_seconds));
+
+ g_free (offset);
+ g_free (dst_offset);
+ g_free (leap_seconds);
+ g_free (time_string);
+
+ if (error)
+ exit (EXIT_FAILURE);
+}
+
+static void
+get_network_time_ready (MMModemTime *modem_time,
+ GAsyncResult *result)
+{
+ MMNetworkTimezone *timezone;
+ gchar *time_string;
+ GError *error = NULL;
+
+ time_string = mm_modem_time_get_network_time_finish (modem_time, result, &error);
+ timezone = mm_modem_time_get_network_timezone (modem_time);
+ get_network_time_process_reply (time_string, timezone, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem_time = mm_object_get_modem_time (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_time)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_time));
+
+ ensure_modem_time ();
+
+ /* Request to get network time from the modem? */
+ if (time_flag) {
+ g_debug ("Asynchronously getting network time from the modem...");
+
+ mm_modem_time_get_network_time (ctx->modem_time,
+ ctx->cancellable,
+ (GAsyncReadyCallback)get_network_time_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_time_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_time_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem_time = mm_object_get_modem_time (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem_time)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_time));
+
+ ensure_modem_time ();
+
+ /* Request to get network time from the modem? */
+ if (time_flag) {
+ gchar *time_string;
+ MMNetworkTimezone *timezone;
+
+ g_debug ("Synchronously getting network time from the modem...");
+
+ time_string = mm_modem_time_get_network_time_sync (ctx->modem_time,
+ NULL,
+ &error);
+ timezone = mm_modem_time_get_network_timezone (ctx->modem_time);
+ get_network_time_process_reply (time_string, timezone, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-modem.c b/cli/mmcli-modem.c
new file mode 100644
index 0000000..0a7f151
--- /dev/null
+++ b/cli/mmcli-modem.c
@@ -0,0 +1,1372 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ GCancellable *cancellable;
+ MMObject *object;
+ MMModem *modem;
+ MMModem3gpp *modem_3gpp;
+ MMModemCdma *modem_cdma;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean info_flag; /* set when no action found */
+static gboolean monitor_state_flag;
+static gboolean enable_flag;
+static gboolean disable_flag;
+static gboolean set_power_state_on_flag;
+static gboolean set_power_state_low_flag;
+static gboolean reset_flag;
+static gchar *factory_reset_str;
+static gchar *command_str;
+static gboolean list_bearers_flag;
+static gchar *create_bearer_str;
+static gchar *delete_bearer_str;
+static gchar *set_current_capabilities_str;
+static gchar *set_allowed_modes_str;
+static gchar *set_preferred_mode_str;
+static gchar *set_current_bands_str;
+
+static GOptionEntry entries[] = {
+ { "monitor-state", 'w', 0, G_OPTION_ARG_NONE, &monitor_state_flag,
+ "Monitor state of a given modem",
+ NULL
+ },
+ { "enable", 'e', 0, G_OPTION_ARG_NONE, &enable_flag,
+ "Enable a given modem",
+ NULL
+ },
+ { "disable", 'd', 0, G_OPTION_ARG_NONE, &disable_flag,
+ "Disable a given modem",
+ NULL
+ },
+ { "set-power-state-on", 0, 0, G_OPTION_ARG_NONE, &set_power_state_on_flag,
+ "Set full power state in the modem",
+ NULL
+ },
+ { "set-power-state-low", 0, 0, G_OPTION_ARG_NONE, &set_power_state_low_flag,
+ "Set low power state in the modem",
+ NULL
+ },
+ { "reset", 'r', 0, G_OPTION_ARG_NONE, &reset_flag,
+ "Reset a given modem",
+ NULL
+ },
+ { "factory-reset", 0, 0, G_OPTION_ARG_STRING, &factory_reset_str,
+ "Reset a given modem to its factory state",
+ "[CODE]"
+ },
+ { "command", 0, 0, G_OPTION_ARG_STRING, &command_str,
+ "Send an AT command to the modem",
+ "[COMMAND]"
+ },
+ { "list-bearers", 0, 0, G_OPTION_ARG_NONE, &list_bearers_flag,
+ "List packet data bearers available in a given modem",
+ NULL
+ },
+ { "create-bearer", 0, 0, G_OPTION_ARG_STRING, &create_bearer_str,
+ "Create a new packet data bearer in a given modem",
+ "[\"key=value,...\"]"
+ },
+ { "delete-bearer", 0, 0, G_OPTION_ARG_STRING, &delete_bearer_str,
+ "Delete a data bearer from a given modem",
+ "[PATH]"
+ },
+ { "set-current-capabilities", 0, 0, G_OPTION_ARG_STRING, &set_current_capabilities_str,
+ "Set current modem capabilities.",
+ "[CAPABILITY1|CAPABILITY2...]"
+ },
+ { "set-allowed-modes", 0, 0, G_OPTION_ARG_STRING, &set_allowed_modes_str,
+ "Set allowed modes in a given modem.",
+ "[MODE1|MODE2...]"
+ },
+ { "set-preferred-mode", 0, 0, G_OPTION_ARG_STRING, &set_preferred_mode_str,
+ "Set preferred mode in a given modem (Must give allowed modes with --set-allowed-modes)",
+ "[MODE]"
+ },
+ { "set-current-bands", 0, 0, G_OPTION_ARG_STRING, &set_current_bands_str,
+ "Set bands to be used by a given modem.",
+ "[BAND1|BAND2...]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_modem_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("modem",
+ "Modem options",
+ "Show modem options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_modem_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (monitor_state_flag +
+ enable_flag +
+ disable_flag +
+ set_power_state_on_flag +
+ set_power_state_low_flag +
+ reset_flag +
+ list_bearers_flag +
+ !!create_bearer_str +
+ !!delete_bearer_str +
+ !!factory_reset_str +
+ !!command_str +
+ !!set_current_capabilities_str +
+ !!set_allowed_modes_str +
+ !!set_preferred_mode_str +
+ !!set_current_bands_str);
+
+ if (n_actions == 0 && mmcli_get_common_modem_string ()) {
+ /* default to info */
+ info_flag = TRUE;
+ n_actions++;
+ }
+
+ if (set_preferred_mode_str) {
+ if (!set_allowed_modes_str) {
+ g_printerr ("error: setting preferred mode requires list of allowed modes\n");
+ exit (EXIT_FAILURE);
+ }
+ n_actions--;
+ }
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many modem actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (monitor_state_flag)
+ mmcli_force_async_operation ();
+
+ if (info_flag)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->modem)
+ g_object_unref (ctx->modem);
+ if (ctx->modem_3gpp)
+ g_object_unref (ctx->modem_3gpp);
+ if (ctx->modem_cdma)
+ g_object_unref (ctx->modem_cdma);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+void
+mmcli_modem_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+cancelled (GCancellable *cancellable)
+{
+ mmcli_async_operation_done ();
+}
+
+static void
+print_bearer_short_info (MMBearer *bearer)
+{
+ g_print ("\t%s\n",
+ mm_bearer_get_path (bearer));
+}
+
+static void
+print_modem_info (void)
+{
+ gchar *drivers_string;
+ gchar *prefixed_revision;
+ gchar *supported_capabilities_string;
+ MMModemCapability *capabilities = NULL;
+ guint n_capabilities = 0;
+ gchar *current_capabilities_string;
+ gchar *access_technologies_string;
+ MMModemModeCombination *modes = NULL;
+ guint n_modes = 0;
+ gchar *supported_modes_string;
+ MMModemMode allowed_modes;
+ gchar *allowed_modes_string = NULL;
+ MMModemMode preferred_mode;
+ gchar *preferred_mode_string = NULL;
+ gchar *supported_bands_string;
+ gchar *current_bands_string;
+ gchar *supported_ip_families_string;
+ gchar *unlock_retries_string;
+ gchar *own_numbers_string;
+ MMModemBand *bands = NULL;
+ guint n_bands = 0;
+ MMUnlockRetries *unlock_retries;
+ guint signal_quality = 0;
+ gboolean signal_quality_recent = FALSE;
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE_UNKNOWN
+#define VALIDATE_UNKNOWN(str) (str ? str : "unknown")
+#undef VALIDATE_PATH
+#define VALIDATE_PATH(str) ((str && !g_str_equal (str, "/")) ? str : "none")
+
+ /* Strings in heap */
+ mm_modem_get_supported_capabilities (ctx->modem, &capabilities, &n_capabilities);
+ supported_capabilities_string = mm_common_build_capabilities_string (capabilities, n_capabilities);
+ g_free (capabilities);
+ current_capabilities_string = mm_modem_capability_build_string_from_mask (
+ mm_modem_get_current_capabilities (ctx->modem));
+ access_technologies_string = mm_modem_access_technology_build_string_from_mask (
+ mm_modem_get_access_technologies (ctx->modem));
+ mm_modem_get_supported_modes (ctx->modem, &modes, &n_modes);
+ supported_modes_string = mm_common_build_mode_combinations_string (modes, n_modes);
+ g_free (modes);
+ mm_modem_get_current_bands (ctx->modem, &bands, &n_bands);
+ current_bands_string = mm_common_build_bands_string (bands, n_bands);
+ g_free (bands);
+ mm_modem_get_supported_bands (ctx->modem, &bands, &n_bands);
+ supported_bands_string = mm_common_build_bands_string (bands, n_bands);
+ g_free (bands);
+ if (mm_modem_get_current_modes (ctx->modem, &allowed_modes, &preferred_mode)) {
+ allowed_modes_string = mm_modem_mode_build_string_from_mask (allowed_modes);
+ preferred_mode_string = mm_modem_mode_build_string_from_mask (preferred_mode);
+ }
+ supported_ip_families_string = mm_bearer_ip_family_build_string_from_mask (
+ mm_modem_get_supported_ip_families (ctx->modem));
+
+ unlock_retries = mm_modem_get_unlock_retries (ctx->modem);
+ unlock_retries_string = mm_unlock_retries_build_string (unlock_retries);
+ g_object_unref (unlock_retries);
+
+ if (mm_modem_get_own_numbers (ctx->modem)) {
+ own_numbers_string = g_strjoinv (", ", (gchar **)mm_modem_get_own_numbers (ctx->modem));
+ if (!own_numbers_string[0]) {
+ g_free (own_numbers_string);
+ own_numbers_string = NULL;
+ }
+ } else
+ own_numbers_string = NULL;
+
+ if (mm_modem_get_drivers (ctx->modem)) {
+ drivers_string = g_strjoinv (", ", (gchar **)mm_modem_get_drivers (ctx->modem));
+ if (!drivers_string[0]) {
+ g_free (drivers_string);
+ drivers_string = NULL;
+ }
+ } else
+ drivers_string = NULL;
+
+ /* Rework possible multiline strings */
+ if (mm_modem_get_revision (ctx->modem))
+ prefixed_revision = mmcli_prefix_newlines (" | ",
+ mm_modem_get_revision (ctx->modem));
+ else
+ prefixed_revision = NULL;
+
+ if (supported_modes_string) {
+ gchar *prefixed;
+
+ prefixed = mmcli_prefix_newlines (" | ",
+ supported_modes_string);
+ g_free (supported_modes_string);
+ supported_modes_string = prefixed;
+ }
+
+ if (supported_capabilities_string) {
+ gchar *prefixed;
+
+ prefixed = mmcli_prefix_newlines (" | ",
+ supported_capabilities_string);
+ g_free (supported_capabilities_string);
+ supported_capabilities_string = prefixed;
+ }
+
+ /* Get signal quality info */
+ signal_quality = mm_modem_get_signal_quality (ctx->modem, &signal_quality_recent);
+
+ /* Global IDs */
+ g_print ("\n"
+ "%s (device id '%s')\n",
+ VALIDATE_UNKNOWN (mm_modem_get_path (ctx->modem)),
+ VALIDATE_UNKNOWN (mm_modem_get_device_identifier (ctx->modem)));
+
+ /* Hardware related stuff */
+ g_print (" -------------------------\n"
+ " Hardware | manufacturer: '%s'\n"
+ " | model: '%s'\n"
+ " | revision: '%s'\n"
+ " | supported: '%s'\n"
+ " | current: '%s'\n"
+ " | equipment id: '%s'\n",
+ VALIDATE_UNKNOWN (mm_modem_get_manufacturer (ctx->modem)),
+ VALIDATE_UNKNOWN (mm_modem_get_model (ctx->modem)),
+ VALIDATE_UNKNOWN (prefixed_revision),
+ VALIDATE_UNKNOWN (supported_capabilities_string),
+ VALIDATE_UNKNOWN (current_capabilities_string),
+ VALIDATE_UNKNOWN (mm_modem_get_equipment_identifier (ctx->modem)));
+
+ /* System related stuff */
+ g_print (" -------------------------\n"
+ " System | device: '%s'\n"
+ " | drivers: '%s'\n"
+ " | plugin: '%s'\n"
+ " | primary port: '%s'\n",
+ VALIDATE_UNKNOWN (mm_modem_get_device (ctx->modem)),
+ VALIDATE_UNKNOWN (drivers_string),
+ VALIDATE_UNKNOWN (mm_modem_get_plugin (ctx->modem)),
+ VALIDATE_UNKNOWN (mm_modem_get_primary_port (ctx->modem)));
+
+ /* Numbers related stuff */
+ g_print (" -------------------------\n"
+ " Numbers | own : '%s'\n",
+ VALIDATE_UNKNOWN (own_numbers_string));
+
+ /* Status related stuff */
+ g_print (" -------------------------\n"
+ " Status | lock: '%s'\n"
+ " | unlock retries: '%s'\n"
+ " | state: '%s'\n",
+ mm_modem_lock_get_string (mm_modem_get_unlock_required (ctx->modem)),
+ VALIDATE_UNKNOWN (unlock_retries_string),
+ VALIDATE_UNKNOWN (mm_modem_state_get_string (mm_modem_get_state (ctx->modem))));
+
+ if (mm_modem_get_state (ctx->modem) == MM_MODEM_STATE_FAILED)
+ g_print (" | failed reason: '%s'\n",
+ VALIDATE_UNKNOWN (mm_modem_state_failed_reason_get_string (mm_modem_get_state_failed_reason (ctx->modem))));
+
+ g_print (" | power state: '%s'\n"
+ " | access tech: '%s'\n"
+ " | signal quality: '%u' (%s)\n",
+ VALIDATE_UNKNOWN (mm_modem_power_state_get_string (mm_modem_get_power_state (ctx->modem))),
+ VALIDATE_UNKNOWN (access_technologies_string),
+ signal_quality, signal_quality_recent ? "recent" : "cached");
+
+ /* Modes */
+ g_print (" -------------------------\n"
+ " Modes | supported: '%s'\n"
+ " | current: 'allowed: %s; preferred: %s'\n",
+ VALIDATE_UNKNOWN (supported_modes_string),
+ VALIDATE_UNKNOWN (allowed_modes_string),
+ VALIDATE_UNKNOWN (preferred_mode_string));
+
+ /* Band related stuff */
+ g_print (" -------------------------\n"
+ " Bands | supported: '%s'\n"
+ " | current: '%s'\n",
+ VALIDATE_UNKNOWN (supported_bands_string),
+ VALIDATE_UNKNOWN (current_bands_string));
+
+ /* IP families */
+ g_print (" -------------------------\n"
+ " IP | supported: '%s'\n",
+ VALIDATE_UNKNOWN (supported_ip_families_string));
+
+ /* If available, 3GPP related stuff */
+ if (ctx->modem_3gpp) {
+ gchar *facility_locks;
+
+ facility_locks = (mm_modem_3gpp_facility_build_string_from_mask (
+ mm_modem_3gpp_get_enabled_facility_locks (ctx->modem_3gpp)));
+ g_print (" -------------------------\n"
+ " 3GPP | imei: '%s'\n"
+ " | enabled locks: '%s'\n"
+ " | operator id: '%s'\n"
+ " | operator name: '%s'\n"
+ " | registration: '%s'\n",
+ VALIDATE_UNKNOWN (mm_modem_3gpp_get_imei (ctx->modem_3gpp)),
+ facility_locks,
+ VALIDATE_UNKNOWN (mm_modem_3gpp_get_operator_code (ctx->modem_3gpp)),
+ VALIDATE_UNKNOWN (mm_modem_3gpp_get_operator_name (ctx->modem_3gpp)),
+ mm_modem_3gpp_registration_state_get_string (
+ mm_modem_3gpp_get_registration_state ((ctx->modem_3gpp))));
+
+ g_free (facility_locks);
+ }
+
+ /* If available, CDMA related stuff */
+ if (ctx->modem_cdma) {
+ guint sid;
+ guint nid;
+ gchar *sid_str;
+ gchar *nid_str;
+
+ sid = mm_modem_cdma_get_sid (ctx->modem_cdma);
+ sid_str = (sid != MM_MODEM_CDMA_SID_UNKNOWN ?
+ g_strdup_printf ("%u", sid) :
+ NULL);
+ nid = mm_modem_cdma_get_nid (ctx->modem_cdma);
+ nid_str = (nid != MM_MODEM_CDMA_NID_UNKNOWN ?
+ g_strdup_printf ("%u", nid) :
+ NULL);
+
+ g_print (" -------------------------\n"
+ " CDMA | meid: '%s'\n"
+ " | esn: '%s'\n"
+ " | sid: '%s'\n"
+ " | nid: '%s'\n"
+ " | registration: CDMA1x '%s'\n"
+ " | EV-DO '%s'\n"
+ " | activation: '%s'\n",
+ VALIDATE_UNKNOWN (mm_modem_cdma_get_meid (ctx->modem_cdma)),
+ VALIDATE_UNKNOWN (mm_modem_cdma_get_esn (ctx->modem_cdma)),
+ VALIDATE_UNKNOWN (sid_str),
+ VALIDATE_UNKNOWN (nid_str),
+ mm_modem_cdma_registration_state_get_string (
+ mm_modem_cdma_get_cdma1x_registration_state (ctx->modem_cdma)),
+ mm_modem_cdma_registration_state_get_string (
+ mm_modem_cdma_get_evdo_registration_state (ctx->modem_cdma)),
+ mm_modem_cdma_activation_state_get_string (
+ mm_modem_cdma_get_activation_state (ctx->modem_cdma)));
+
+ g_free (sid_str);
+ g_free (nid_str);
+ }
+
+ /* SIM */
+ g_print (" -------------------------\n"
+ " SIM | path: '%s'\n",
+ VALIDATE_PATH (mm_modem_get_sim_path (ctx->modem)));
+ g_print ("\n");
+
+ g_free (supported_ip_families_string);
+ g_free (current_bands_string);
+ g_free (supported_bands_string);
+ g_free (access_technologies_string);
+ g_free (supported_capabilities_string);
+ g_free (current_capabilities_string);
+ g_free (prefixed_revision);
+ g_free (allowed_modes_string);
+ g_free (preferred_mode_string);
+ g_free (supported_modes_string);
+ g_free (unlock_retries_string);
+ g_free (own_numbers_string);
+ g_free (drivers_string);
+}
+
+static void
+enable_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't enable the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully enabled the modem\n");
+}
+
+static void
+enable_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_enable_finish (modem, result, &error);
+ enable_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+disable_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't disable the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully disabled the modem\n");
+}
+
+static void
+disable_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_disable_finish (modem, result, &error);
+ disable_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+set_power_state_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set new power state in the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully set new power state in the modem\n");
+}
+
+static void
+set_power_state_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_set_power_state_finish (modem, result, &error);
+ set_power_state_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+reset_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't reset the modem: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully reseted the modem\n");
+}
+
+static void
+reset_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_reset_finish (modem, result, &error);
+ reset_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+factory_reset_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't reset the modem to factory state: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully reseted the modem to factory state\n");
+}
+
+static void
+factory_reset_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_factory_reset_finish (modem, result, &error);
+ factory_reset_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+
+static void
+command_process_reply (gchar *result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: command failed: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("response: '%s'\n", result);
+ g_free (result);
+}
+
+static void
+command_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gchar * operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_command_finish (modem, result, &error);
+ command_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static guint
+command_get_timeout (MMModem *modem)
+{
+ gint timeout;
+
+ /* If --timeout was given, it should already have been set in the proxy */
+ timeout = (g_dbus_proxy_get_default_timeout (G_DBUS_PROXY (modem)) / 1000) - 1;
+ if (timeout <= 0) {
+ g_printerr ("error: timeout is too short (%d)\n", timeout);
+ exit (EXIT_FAILURE);
+ }
+
+ return (guint)timeout;
+}
+
+static void
+list_bearers_process_reply (GList *result,
+ const GError *error)
+{
+ if (error) {
+ g_printerr ("error: couldn't list bearers: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("\n");
+ if (!result) {
+ g_print ("No bearers were found\n");
+ } else {
+ GList *l;
+
+ g_print ("Found %u bearers:\n", g_list_length (result));
+ for (l = result; l; l = g_list_next (l)) {
+ MMBearer *bearer = MM_BEARER (l->data);
+
+ g_print ("\n");
+ print_bearer_short_info (bearer);
+ g_object_unref (bearer);
+ }
+ g_list_free (result);
+ }
+}
+
+static void
+list_bearers_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ GList *operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_list_bearers_finish (modem, result, &error);
+ list_bearers_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+create_bearer_process_reply (MMBearer *bearer,
+ const GError *error)
+{
+ if (!bearer) {
+ g_printerr ("error: couldn't create new bearer: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("Successfully created new bearer in modem:\n");
+ print_bearer_short_info (bearer);
+ g_object_unref (bearer);
+}
+
+static void
+create_bearer_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ MMBearer *bearer;
+ GError *error = NULL;
+
+ bearer = mm_modem_create_bearer_finish (modem, result, &error);
+ create_bearer_process_reply (bearer, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+delete_bearer_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't delete bearer: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully deleted bearer from modem\n");
+}
+
+static void
+delete_bearer_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_delete_bearer_finish (modem, result, &error);
+ delete_bearer_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+set_current_capabilities_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set current capabilities: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully set current capabilities in the modem\n");
+}
+
+static void
+set_current_capabilities_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_set_current_capabilities_finish (modem, result, &error);
+ set_current_capabilities_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+parse_current_capabilities (MMModemCapability *capabilities)
+{
+ GError *error = NULL;
+
+ *capabilities = mm_common_get_capabilities_from_string (set_current_capabilities_str,
+ &error);
+ if (error) {
+ g_printerr ("error: couldn't parse list of capabilities: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+}
+
+static void
+set_current_modes_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set current modes: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully set current modes in the modem\n");
+}
+
+static void
+set_current_modes_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_set_current_modes_finish (modem, result, &error);
+ set_current_modes_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+parse_modes (MMModemMode *allowed,
+ MMModemMode *preferred)
+{
+ GError *error = NULL;
+
+ *allowed = mm_common_get_modes_from_string (set_allowed_modes_str, &error);
+ if (error) {
+ g_printerr ("error: couldn't parse list of allowed modes: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ *preferred = (set_preferred_mode_str ?
+ mm_common_get_modes_from_string (set_preferred_mode_str, &error) :
+ MM_MODEM_MODE_NONE);
+ if (error) {
+ g_printerr ("error: couldn't parse preferred mode: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+}
+
+static void
+set_current_bands_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't set current bands: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully set current bands in the modem\n");
+}
+
+static void
+set_current_bands_ready (MMModem *modem,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_modem_set_current_bands_finish (modem, result, &error);
+ set_current_bands_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+parse_current_bands (MMModemBand **bands,
+ guint *n_bands)
+{
+ GError *error = NULL;
+
+ mm_common_get_bands_from_string (set_current_bands_str,
+ bands,
+ n_bands,
+ &error);
+ if (error) {
+ g_printerr ("error: couldn't parse list of bands: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+}
+
+static void
+state_changed (MMModem *modem,
+ MMModemState old_state,
+ MMModemState new_state,
+ MMModemStateChangeReason reason)
+{
+ g_print ("\t%s: State changed, '%s' --> '%s' (Reason: %s)\n",
+ mm_modem_get_path (modem),
+ mm_modem_state_get_string (old_state),
+ mm_modem_state_get_string (new_state),
+ mmcli_get_state_reason_string (reason));
+ fflush (stdout);
+}
+
+static void
+get_modem_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->object = mmcli_get_modem_finish (result, &ctx->manager);
+ ctx->modem = mm_object_get_modem (ctx->object);
+ ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
+ ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem));
+ if (ctx->modem_3gpp)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
+ if (ctx->modem_cdma)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
+
+ if (info_flag)
+ g_assert_not_reached ();
+
+ /* Request to monitor modems? */
+ if (monitor_state_flag) {
+ MMModemState current;
+
+ g_signal_connect (ctx->modem,
+ "state-changed",
+ G_CALLBACK (state_changed),
+ NULL);
+
+ current = mm_modem_get_state (ctx->modem);
+ g_print ("\t%s: Initial state, '%s'\n",
+ mm_object_get_path (ctx->object),
+ mm_modem_state_get_string (current));
+
+ /* If we get cancelled, operation done */
+ g_cancellable_connect (ctx->cancellable,
+ G_CALLBACK (cancelled),
+ NULL,
+ NULL);
+ return;
+ }
+
+ /* Request to enable the modem? */
+ if (enable_flag) {
+ g_debug ("Asynchronously enabling modem...");
+ mm_modem_enable (ctx->modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)enable_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to disable the modem? */
+ if (disable_flag) {
+ g_debug ("Asynchronously disabling modem...");
+ mm_modem_disable (ctx->modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)disable_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to full power the modem? */
+ if (set_power_state_on_flag) {
+ g_debug ("Asynchronously setting full power...");
+ mm_modem_set_power_state (ctx->modem,
+ MM_MODEM_POWER_STATE_ON,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_power_state_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to low power the modem? */
+ if (set_power_state_low_flag) {
+ g_debug ("Asynchronously setting low power...");
+ mm_modem_set_power_state (ctx->modem,
+ MM_MODEM_POWER_STATE_LOW,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_power_state_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to reset the modem? */
+ if (reset_flag) {
+ g_debug ("Asynchronously reseting modem...");
+ mm_modem_reset (ctx->modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)reset_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to reset the modem to factory state? */
+ if (factory_reset_str) {
+ g_debug ("Asynchronously factory-reseting modem...");
+ mm_modem_factory_reset (ctx->modem,
+ factory_reset_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)factory_reset_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to send a command to the modem? */
+ if (command_str) {
+ guint timeout;
+
+ timeout = command_get_timeout (ctx->modem);
+
+ g_debug ("Asynchronously sending a command to the modem (%u seconds timeout)...",
+ timeout);
+
+ mm_modem_command (ctx->modem,
+ command_str,
+ timeout,
+ ctx->cancellable,
+ (GAsyncReadyCallback)command_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to list bearers? */
+ if (list_bearers_flag) {
+ g_debug ("Asynchronously listing bearers in modem...");
+ mm_modem_list_bearers (ctx->modem,
+ ctx->cancellable,
+ (GAsyncReadyCallback)list_bearers_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to create a new bearer? */
+ if (create_bearer_str) {
+ GError *error = NULL;
+ MMBearerProperties *properties;
+
+ properties = mm_bearer_properties_new_from_string (create_bearer_str, &error);
+ if (!properties) {
+ g_printerr ("Error parsing properties string: '%s'\n", error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("Asynchronously creating new bearer in modem...");
+ mm_modem_create_bearer (ctx->modem,
+ properties,
+ ctx->cancellable,
+ (GAsyncReadyCallback)create_bearer_ready,
+ NULL);
+ g_object_unref (properties);
+ return;
+ }
+
+ /* Request to delete a given bearer? */
+ if (delete_bearer_str) {
+ mm_modem_delete_bearer (ctx->modem,
+ delete_bearer_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)delete_bearer_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to set current capabilities in a given modem? */
+ if (set_current_capabilities_str) {
+ MMModemCapability current_capabilities;
+
+ parse_current_capabilities (&current_capabilities);
+ mm_modem_set_current_capabilities (ctx->modem,
+ current_capabilities,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_current_capabilities_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to set allowed modes in a given modem? */
+ if (set_allowed_modes_str) {
+ MMModemMode allowed;
+ MMModemMode preferred;
+
+ parse_modes (&allowed, &preferred);
+ mm_modem_set_current_modes (ctx->modem,
+ allowed,
+ preferred,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_current_modes_ready,
+ NULL);
+ return;
+ }
+
+ /* Request to set current bands in a given modem? */
+ if (set_current_bands_str) {
+ MMModemBand *current_bands;
+ guint n_current_bands;
+
+ parse_current_bands (&current_bands, &n_current_bands);
+ mm_modem_set_current_bands (ctx->modem,
+ current_bands,
+ n_current_bands,
+ ctx->cancellable,
+ (GAsyncReadyCallback)set_current_bands_ready,
+ NULL);
+ g_free (current_bands);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_modem_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper modem */
+ mmcli_get_modem (connection,
+ mmcli_get_common_modem_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_modem_ready,
+ NULL);
+}
+
+void
+mmcli_modem_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ if (monitor_state_flag)
+ g_assert_not_reached ();
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->object = mmcli_get_modem_sync (connection,
+ mmcli_get_common_modem_string (),
+ &ctx->manager);
+ ctx->modem = mm_object_get_modem (ctx->object);
+ ctx->modem_3gpp = mm_object_get_modem_3gpp (ctx->object);
+ ctx->modem_cdma = mm_object_get_modem_cdma (ctx->object);
+
+ /* Setup operation timeout */
+ if (ctx->modem)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem));
+ if (ctx->modem_3gpp)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_3gpp));
+ if (ctx->modem_cdma)
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->modem_cdma));
+
+ /* Request to get info from modem? */
+ if (info_flag) {
+ g_debug ("Printing modem info...");
+ print_modem_info ();
+ return;
+ }
+
+ /* Request to enable the modem? */
+ if (enable_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously enabling modem...");
+ result = mm_modem_enable_sync (ctx->modem, NULL, &error);
+ enable_process_reply (result, error);
+ return;
+ }
+
+ /* Request to disable the modem? */
+ if (disable_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously disabling modem...");
+ result = mm_modem_disable_sync (ctx->modem, NULL, &error);
+ disable_process_reply (result, error);
+ return;
+ }
+
+ /* Request to set full power state? */
+ if (set_power_state_on_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously setting full power...");
+ result = mm_modem_set_power_state_sync (ctx->modem, MM_MODEM_POWER_STATE_ON, NULL, &error);
+ set_power_state_process_reply (result, error);
+ return;
+ }
+
+ /* Request to set low power state? */
+ if (set_power_state_low_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously setting low power...");
+ result = mm_modem_set_power_state_sync (ctx->modem, MM_MODEM_POWER_STATE_LOW, NULL, &error);
+ set_power_state_process_reply (result, error);
+ return;
+ }
+
+ /* Request to reset the modem? */
+ if (reset_flag) {
+ gboolean result;
+
+ g_debug ("Synchronously reseting modem...");
+ result = mm_modem_reset_sync (ctx->modem, NULL, &error);
+ reset_process_reply (result, error);
+ return;
+ }
+
+ /* Request to reset the modem to factory state? */
+ if (factory_reset_str) {
+ gboolean result;
+
+ g_debug ("Synchronously factory-reseting modem...");
+ result = mm_modem_factory_reset_sync (ctx->modem,
+ factory_reset_str,
+ NULL,
+ &error);
+ factory_reset_process_reply (result, error);
+ return;
+ }
+
+
+ /* Request to send a command to the modem? */
+ if (command_str) {
+ gchar *result;
+ guint timeout;
+
+ timeout = command_get_timeout (ctx->modem);
+
+ g_debug ("Synchronously sending command to modem (%u seconds timeout)...",
+ timeout);
+
+ result = mm_modem_command_sync (ctx->modem,
+ command_str,
+ timeout,
+ NULL,
+ &error);
+ command_process_reply (result, error);
+ return;
+ }
+
+ /* Request to list the bearers? */
+ if (list_bearers_flag) {
+ GList *result;
+
+ g_debug ("Synchronously listing bearers...");
+ result = mm_modem_list_bearers_sync (ctx->modem, NULL, &error);
+ list_bearers_process_reply (result, error);
+ return;
+ }
+
+ /* Request to create a new bearer? */
+ if (create_bearer_str) {
+ MMBearer *bearer;
+ GError *error = NULL;
+ MMBearerProperties *properties;
+
+ properties = mm_bearer_properties_new_from_string (create_bearer_str, &error);
+ if (!properties) {
+ g_printerr ("Error parsing properties string: '%s'\n", error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_debug ("Synchronously creating new bearer in modem...");
+ bearer = mm_modem_create_bearer_sync (ctx->modem,
+ properties,
+ NULL,
+ &error);
+ g_object_unref (properties);
+
+ create_bearer_process_reply (bearer, error);
+ return;
+ }
+
+ /* Request to delete a given bearer? */
+ if (delete_bearer_str) {
+ gboolean result;
+
+ result = mm_modem_delete_bearer_sync (ctx->modem,
+ delete_bearer_str,
+ NULL,
+ &error);
+
+ delete_bearer_process_reply (result, error);
+ return;
+ }
+
+ /* Request to set capabilities in a given modem? */
+ if (set_current_capabilities_str) {
+ gboolean result;
+ MMModemCapability current_capabilities;
+
+ parse_current_capabilities (&current_capabilities);
+ result = mm_modem_set_current_capabilities_sync (ctx->modem,
+ current_capabilities,
+ NULL,
+ &error);
+ set_current_capabilities_process_reply (result, error);
+ return;
+ }
+
+ /* Request to set allowed modes in a given modem? */
+ if (set_allowed_modes_str) {
+ MMModemMode allowed;
+ MMModemMode preferred;
+ gboolean result;
+
+ parse_modes (&allowed, &preferred);
+ result = mm_modem_set_current_modes_sync (ctx->modem,
+ allowed,
+ preferred,
+ NULL,
+ &error);
+
+ set_current_modes_process_reply (result, error);
+ return;
+ }
+
+ /* Request to set allowed bands in a given modem? */
+ if (set_current_bands_str) {
+ gboolean result;
+ MMModemBand *current_bands;
+ guint n_current_bands;
+
+ parse_current_bands (&current_bands, &n_current_bands);
+ result = mm_modem_set_current_bands_sync (ctx->modem,
+ current_bands,
+ n_current_bands,
+ NULL,
+ &error);
+ g_free (current_bands);
+ set_current_bands_process_reply (result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-sim.c b/cli/mmcli-sim.c
new file mode 100644
index 0000000..085f335
--- /dev/null
+++ b/cli/mmcli-sim.c
@@ -0,0 +1,482 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control sim status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ MMObject *object;
+ GCancellable *cancellable;
+ MMSim *sim;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean info_flag; /* set when no action found */
+static gchar *pin_str;
+static gchar *puk_str;
+static gboolean enable_pin_flag;
+static gboolean disable_pin_flag;
+static gchar *change_pin_str;
+
+static GOptionEntry entries[] = {
+ { "pin", 0, 0, G_OPTION_ARG_STRING, &pin_str,
+ "Send PIN code to a given SIM.",
+ "[PIN]"
+ },
+ { "puk", 0, 0, G_OPTION_ARG_STRING, &puk_str,
+ "Send PUK code to a given SIM (must send the new PIN with --pin).",
+ "[PUK]"
+ },
+ { "enable-pin", 0, 0, G_OPTION_ARG_NONE, &enable_pin_flag,
+ "Enable PIN request in a given SIM (must send the current PIN with --pin).",
+ NULL
+ },
+ { "disable-pin", 0, 0, G_OPTION_ARG_NONE, &disable_pin_flag,
+ "Disable PIN request in a given SIM (must send the current PIN with --pin).",
+ NULL
+ },
+ { "change-pin", 0, 0, G_OPTION_ARG_STRING, &change_pin_str,
+ "Change the PIN in a given SIM (must send the current PIN with --pin).",
+ "[New PIN]"
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_sim_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("sim",
+ "SIM options",
+ "Show SIM options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_sim_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (!!puk_str +
+ enable_pin_flag +
+ disable_pin_flag +
+ !!change_pin_str);
+
+ if (n_actions == 1) {
+ if (!pin_str) {
+ g_printerr ("error: action requires also the PIN code\n");
+ exit (EXIT_FAILURE);
+ }
+ } else if (n_actions == 0)
+ n_actions += !!pin_str;
+
+ if (n_actions == 0 && mmcli_get_common_sim_string ()) {
+ /* default to info */
+ info_flag = TRUE;
+ n_actions++;
+ }
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many sim actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->sim)
+ g_object_unref (ctx->sim);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+void
+mmcli_sim_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+print_sim_info (MMSim *sim)
+{
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE
+#define VALIDATE(str) (str ? str : "unknown")
+
+ g_print ("SIM '%s'\n",
+ mm_sim_get_path (sim));
+ g_print (" -------------------------\n"
+ " Properties | imsi : '%s'\n"
+ " | id : '%s'\n"
+ " | operator id : '%s'\n"
+ " | operator name : '%s'\n",
+ VALIDATE (mm_sim_get_imsi (sim)),
+ VALIDATE (mm_sim_get_identifier (sim)),
+ VALIDATE (mm_sim_get_operator_identifier (sim)),
+ VALIDATE (mm_sim_get_operator_name (sim)));
+}
+
+static void
+send_pin_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't send PIN code to the SIM: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully sent PIN code to the SIM\n");
+}
+
+static void
+send_pin_ready (MMSim *sim,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sim_send_pin_finish (sim, result, &error);
+ send_pin_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+send_puk_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't send PUK code to the SIM: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully sent PUK code to the SIM\n");
+}
+
+static void
+send_puk_ready (MMSim *sim,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sim_send_puk_finish (sim, result, &error);
+ send_puk_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+enable_pin_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't enable PIN code request in the SIM: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully enabled PIN code request in the SIM\n");
+}
+
+static void
+enable_pin_ready (MMSim *sim,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sim_enable_pin_finish (sim, result, &error);
+ enable_pin_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+disable_pin_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't disable PIN code request in the SIM: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully disabled PIN code request in the SIM\n");
+}
+
+static void
+disable_pin_ready (MMSim *sim,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sim_disable_pin_finish (sim, result, &error);
+ disable_pin_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+change_pin_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't change PIN code in the SIM: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully changed PIN code in the SIM\n");
+}
+
+static void
+change_pin_ready (MMSim *sim,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sim_change_pin_finish (sim, result, &error);
+ change_pin_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_sim_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->sim = mmcli_get_sim_finish (result,
+ &ctx->manager,
+ &ctx->object);
+
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sim));
+
+ if (info_flag)
+ g_assert_not_reached ();
+
+ /* Requesting to enable PIN? */
+ if (enable_pin_flag) {
+ mm_sim_enable_pin (ctx->sim,
+ pin_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)enable_pin_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to disable PIN? */
+ if (disable_pin_flag) {
+ mm_sim_disable_pin (ctx->sim,
+ pin_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)disable_pin_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to change PIN? */
+ if (change_pin_str) {
+ mm_sim_change_pin (ctx->sim,
+ pin_str, /* current */
+ change_pin_str, /* new */
+ ctx->cancellable,
+ (GAsyncReadyCallback)change_pin_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to send PUK? */
+ if (puk_str) {
+ mm_sim_send_puk (ctx->sim,
+ puk_str,
+ pin_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)send_puk_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to send PIN? (always LAST check!) */
+ if (pin_str) {
+ mm_sim_send_pin (ctx->sim,
+ pin_str,
+ ctx->cancellable,
+ (GAsyncReadyCallback)send_pin_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_sim_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper sim */
+ mmcli_get_sim (connection,
+ mmcli_get_common_sim_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_sim_ready,
+ NULL);
+}
+
+void
+mmcli_sim_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->sim = mmcli_get_sim_sync (connection,
+ mmcli_get_common_sim_string (),
+ &ctx->manager,
+ &ctx->object);
+
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sim));
+
+ /* Request to get info from SIM? */
+ if (info_flag) {
+ g_debug ("Printing sim info...");
+ print_sim_info (ctx->sim);
+ return;
+ }
+
+ /* Requesting to enable PIN? */
+ if (enable_pin_flag) {
+ gboolean operation_result;
+
+ operation_result = mm_sim_enable_pin_sync (ctx->sim,
+ pin_str,
+ NULL,
+ &error);
+ enable_pin_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to disable PIN? */
+ if (disable_pin_flag) {
+ gboolean operation_result;
+
+ operation_result = mm_sim_disable_pin_sync (ctx->sim,
+ pin_str,
+ NULL,
+ &error);
+ disable_pin_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to change PIN? */
+ if (change_pin_str) {
+ gboolean operation_result;
+
+ operation_result = mm_sim_change_pin_sync (ctx->sim,
+ pin_str, /* current */
+ change_pin_str, /* new */
+ NULL,
+ &error);
+ change_pin_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to send PUK? */
+ if (puk_str) {
+ gboolean operation_result;
+
+ operation_result = mm_sim_send_puk_sync (ctx->sim,
+ puk_str,
+ pin_str,
+ NULL,
+ &error);
+ send_puk_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to send PIN? (always LAST check!) */
+ if (pin_str) {
+ gboolean operation_result;
+
+ operation_result = mm_sim_send_pin_sync (ctx->sim,
+ pin_str,
+ NULL,
+ &error);
+ send_pin_process_reply (operation_result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli-sms.c b/cli/mmcli-sms.c
new file mode 100644
index 0000000..a9c2cb1
--- /dev/null
+++ b/cli/mmcli-sms.c
@@ -0,0 +1,457 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control sms status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2012 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+/* Context */
+typedef struct {
+ MMManager *manager;
+ MMObject *object;
+ GCancellable *cancellable;
+ MMSms *sms;
+} Context;
+static Context *ctx;
+
+/* Options */
+static gboolean info_flag; /* set when no action found */
+static gboolean send_flag;
+static gboolean store_flag;
+static gchar *store_in_storage_str;
+static gchar *create_file_with_data_str;
+
+static GOptionEntry entries[] = {
+ { "send", 0, 0, G_OPTION_ARG_NONE, &send_flag,
+ "Send SMS.",
+ NULL,
+ },
+ { "store", 0, 0, G_OPTION_ARG_NONE, &store_flag,
+ "Store the SMS in the device, at the default storage",
+ NULL,
+ },
+ { "store-in-storage", 0, 0, G_OPTION_ARG_STRING, &store_in_storage_str,
+ "Store the SMS in the device, at the specified storage",
+ "[Storage]",
+ },
+ { "create-file-with-data", 0, 0, G_OPTION_ARG_STRING, &create_file_with_data_str,
+ "Create a file with the data contents of the SMS.",
+ "[File path]",
+ },
+ { NULL }
+};
+
+GOptionGroup *
+mmcli_sms_get_option_group (void)
+{
+ GOptionGroup *group;
+
+ /* Status options */
+ group = g_option_group_new ("sms",
+ "SMS options",
+ "Show SMS options",
+ NULL,
+ NULL);
+ g_option_group_add_entries (group, entries);
+
+ return group;
+}
+
+gboolean
+mmcli_sms_options_enabled (void)
+{
+ static guint n_actions = 0;
+ static gboolean checked = FALSE;
+
+ if (checked)
+ return !!n_actions;
+
+ n_actions = (send_flag +
+ store_flag +
+ !!store_in_storage_str +
+ !!create_file_with_data_str);
+
+ if (n_actions == 0 && mmcli_get_common_sms_string ()) {
+ /* default to info */
+ info_flag = TRUE;
+ n_actions++;
+ }
+
+ if (n_actions > 1) {
+ g_printerr ("error: too many SMS actions requested\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (info_flag)
+ mmcli_force_sync_operation ();
+
+ if (create_file_with_data_str)
+ mmcli_force_sync_operation ();
+
+ checked = TRUE;
+ return !!n_actions;
+}
+
+static void
+context_free (Context *ctx)
+{
+ if (!ctx)
+ return;
+
+ if (ctx->cancellable)
+ g_object_unref (ctx->cancellable);
+ if (ctx->sms)
+ g_object_unref (ctx->sms);
+ if (ctx->object)
+ g_object_unref (ctx->object);
+ if (ctx->manager)
+ g_object_unref (ctx->manager);
+ g_free (ctx);
+}
+
+void
+mmcli_sms_shutdown (void)
+{
+ context_free (ctx);
+}
+
+static void
+print_sms_info (MMSms *sms)
+{
+ MMSmsPduType pdu_type;
+ const guint8 *data;
+ gsize data_size;
+
+ /* Not the best thing to do, as we may be doing _get() calls twice, but
+ * easiest to maintain */
+#undef VALIDATE
+#define VALIDATE(str) (str ? str : "unknown")
+
+ pdu_type = mm_sms_get_pdu_type (sms);
+
+ g_print ("SMS '%s'\n",
+ mm_sms_get_path (sms));
+ g_print (" -----------------------------------\n"
+ " Content | number: '%s'\n",
+ VALIDATE (mm_sms_get_number (sms)));
+
+ if (mm_sms_get_text (sms))
+ g_print (" | text: '%s'\n",
+ VALIDATE (mm_sms_get_text (sms)));
+
+ data = mm_sms_get_data (sms, &data_size);
+ if (data) {
+ gchar *data_hex;
+
+ data_hex = mm_utils_bin2hexstr (data, data_size);
+ g_print (" | data: '%s'\n",
+ VALIDATE (data_hex));
+ g_free (data_hex);
+ }
+
+ g_print (" -----------------------------------\n"
+ " Properties | PDU type: '%s'\n"
+ " | state: '%s'\n"
+ " | smsc: '%s'\n",
+ mm_sms_pdu_type_get_string (pdu_type),
+ mm_sms_state_get_string (mm_sms_get_state (sms)),
+ VALIDATE (mm_sms_get_smsc (sms)));
+
+ if (mm_sms_get_validity_type (sms) == MM_SMS_VALIDITY_TYPE_RELATIVE)
+ g_print (" | validity (relative): '%u'\n",
+ mm_sms_get_validity_relative (sms));
+
+ g_print (" | class: '%u'\n"
+ " | storage: '%s'\n",
+ mm_sms_get_class (sms),
+ mm_sms_storage_get_string (mm_sms_get_storage (sms)));
+
+ if (pdu_type == MM_SMS_PDU_TYPE_SUBMIT)
+ g_print (" | delivery report: '%s'\n",
+ mm_sms_get_delivery_report_request (sms) ? "requested" : "not requested");
+
+ if (pdu_type == MM_SMS_PDU_TYPE_STATUS_REPORT ||
+ pdu_type == MM_SMS_PDU_TYPE_SUBMIT)
+ g_print (" | message reference: '%u'\n",
+ mm_sms_get_message_reference (sms));
+
+ if (pdu_type == MM_SMS_PDU_TYPE_STATUS_REPORT ||
+ pdu_type == MM_SMS_PDU_TYPE_DELIVER)
+ g_print (" | timestamp: '%s'\n",
+ VALIDATE (mm_sms_get_timestamp (sms)));
+
+ if (pdu_type == MM_SMS_PDU_TYPE_STATUS_REPORT) {
+ g_print (" | delivery state: '%s' (0x%X)\n",
+ VALIDATE (mm_sms_delivery_state_get_string_extended (mm_sms_get_delivery_state (sms))),
+ mm_sms_get_delivery_state (sms));
+ g_print (" | discharge timestamp: '%s'\n",
+ VALIDATE (mm_sms_get_discharge_timestamp (sms)));
+ }
+}
+
+static void
+create_file_with_data (MMSms *sms,
+ const gchar *input_path_str)
+{
+ GError *error = NULL;
+ gchar *path;
+ GFile *file;
+ const guint8 *data;
+ gsize data_size;
+
+ file = g_file_new_for_commandline_arg (input_path_str);
+ path = g_file_get_path (file);
+
+ data = mm_sms_get_data (sms, &data_size);
+ if (!data) {
+ g_printerr ("error: couldn't create file: SMS has no data\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (!g_file_set_contents (path,
+ (const gchar *)data,
+ data_size,
+ &error)) {
+ g_printerr ("error: cannot write to file '%s': '%s'\n",
+ input_path_str, error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ g_free (path);
+ g_object_unref (file);
+}
+
+static void
+send_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't send the SMS: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully sent the SMS\n");
+}
+
+static void
+send_ready (MMSms *sms,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sms_send_finish (sms, result, &error);
+ send_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+store_process_reply (gboolean result,
+ const GError *error)
+{
+ if (!result) {
+ g_printerr ("error: couldn't store the SMS: '%s'\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("successfully stored the SMS\n");
+}
+
+static void
+store_ready (MMSms *sms,
+ GAsyncResult *result,
+ gpointer nothing)
+{
+ gboolean operation_result;
+ GError *error = NULL;
+
+ operation_result = mm_sms_store_finish (sms, result, &error);
+ store_process_reply (operation_result, error);
+
+ mmcli_async_operation_done ();
+}
+
+static void
+get_sms_ready (GObject *source,
+ GAsyncResult *result,
+ gpointer none)
+{
+ ctx->sms = mmcli_get_sms_finish (result,
+ &ctx->manager,
+ &ctx->object);
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sms));
+
+ if (info_flag)
+ g_assert_not_reached ();
+
+ if (create_file_with_data_str)
+ g_assert_not_reached ();
+
+ /* Requesting to send the SMS? */
+ if (send_flag) {
+ mm_sms_send (ctx->sms,
+ ctx->cancellable,
+ (GAsyncReadyCallback)send_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to store the SMS? */
+ if (store_flag) {
+ mm_sms_store (ctx->sms,
+ MM_SMS_STORAGE_UNKNOWN,
+ ctx->cancellable,
+ (GAsyncReadyCallback)store_ready,
+ NULL);
+ return;
+ }
+
+ /* Requesting to store the SMS in a specific storage? */
+ if (store_in_storage_str) {
+ MMSmsStorage storage;
+ GError *error = NULL;
+
+ storage = mm_common_get_sms_storage_from_string (store_in_storage_str, &error);
+ if (error) {
+ g_printerr ("error: couldn't store the SMS: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ mm_sms_store (ctx->sms,
+ storage,
+ ctx->cancellable,
+ (GAsyncReadyCallback)store_ready,
+ NULL);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
+
+void
+mmcli_sms_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable)
+{
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ if (cancellable)
+ ctx->cancellable = g_object_ref (cancellable);
+
+ /* Get proper sms */
+ mmcli_get_sms (connection,
+ mmcli_get_common_sms_string (),
+ cancellable,
+ (GAsyncReadyCallback)get_sms_ready,
+ NULL);
+}
+
+void
+mmcli_sms_run_synchronous (GDBusConnection *connection)
+{
+ GError *error = NULL;
+
+ /* Initialize context */
+ ctx = g_new0 (Context, 1);
+ ctx->sms = mmcli_get_sms_sync (connection,
+ mmcli_get_common_sms_string (),
+ &ctx->manager,
+ &ctx->object);
+
+ /* Setup operation timeout */
+ mmcli_force_operation_timeout (G_DBUS_PROXY (ctx->sms));
+
+ /* Request to get info from SMS? */
+ if (info_flag) {
+ g_debug ("Printing SMS info...");
+ print_sms_info (ctx->sms);
+ return;
+ }
+
+ /* Request to create a new file with the data from the SMS? */
+ if (create_file_with_data_str) {
+ g_debug ("Creating file with SMS data...");
+ create_file_with_data (ctx->sms, create_file_with_data_str);
+ return;
+ }
+
+ /* Requesting to send the SMS? */
+ if (send_flag) {
+ gboolean operation_result;
+
+ operation_result = mm_sms_send_sync (ctx->sms,
+ NULL,
+ &error);
+ send_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to store the SMS? */
+ if (store_flag) {
+ gboolean operation_result;
+
+ operation_result = mm_sms_store_sync (ctx->sms,
+ MM_SMS_STORAGE_UNKNOWN,
+ NULL,
+ &error);
+ store_process_reply (operation_result, error);
+ return;
+ }
+
+ /* Requesting to store the SMS in a specific storage? */
+ if (store_in_storage_str) {
+ gboolean operation_result;
+ MMSmsStorage storage;
+ GError *error = NULL;
+
+ storage = mm_common_get_sms_storage_from_string (store_in_storage_str, &error);
+ if (error) {
+ g_printerr ("error: couldn't store the SMS: '%s'\n",
+ error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ operation_result = mm_sms_store_sync (ctx->sms,
+ storage,
+ NULL,
+ &error);
+ store_process_reply (operation_result, error);
+ return;
+ }
+
+ g_warn_if_reached ();
+}
diff --git a/cli/mmcli.c b/cli/mmcli.c
new file mode 100644
index 0000000..da68780
--- /dev/null
+++ b/cli/mmcli.c
@@ -0,0 +1,380 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ * Copyright (C) 2011 Google, Inc.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <string.h>
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#define _LIBMM_INSIDE_MMCLI
+#include <libmm-glib.h>
+
+#include "mmcli.h"
+#include "mmcli-common.h"
+
+#define PROGRAM_NAME "mmcli"
+#define PROGRAM_VERSION PACKAGE_VERSION
+
+/* Globals */
+static GMainLoop *loop;
+static GCancellable *cancellable;
+
+/* Context */
+static gboolean verbose_flag;
+static gboolean version_flag;
+static gboolean async_flag;
+static gint timeout = 30; /* by default, use 30s for all operations */
+
+static GOptionEntry main_entries[] = {
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag,
+ "Run action with verbose logs",
+ NULL
+ },
+ { "version", 'V', 0, G_OPTION_ARG_NONE, &version_flag,
+ "Print version",
+ NULL
+ },
+ { "async", 'a', 0, G_OPTION_ARG_NONE, &async_flag,
+ "Use asynchronous methods",
+ NULL
+ },
+ { "timeout", 0, 0, G_OPTION_ARG_INT, &timeout,
+ "Timeout for the operation",
+ "[SECONDS]"
+ },
+ { NULL }
+};
+
+static void
+signals_handler (int signum)
+{
+ if (cancellable) {
+ /* Ignore consecutive requests of cancellation */
+ if (!g_cancellable_is_cancelled (cancellable)) {
+ g_printerr ("%s\n",
+ "cancelling the operation...\n");
+ g_cancellable_cancel (cancellable);
+ }
+ return;
+ }
+
+ if (loop &&
+ g_main_loop_is_running (loop)) {
+ g_printerr ("%s\n",
+ "cancelling the main loop...\n");
+ g_main_loop_quit (loop);
+ }
+}
+
+static void
+log_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
+{
+ const gchar *log_level_str;
+ time_t now;
+ gchar time_str[64];
+ struct tm *local_time;
+
+ now = time ((time_t *) NULL);
+ local_time = localtime (&now);
+ strftime (time_str, 64, "%d %b %Y, %H:%M:%S", local_time);
+
+ switch (log_level) {
+ case G_LOG_LEVEL_WARNING:
+ log_level_str = "-Warning **";
+ break;
+
+ case G_LOG_LEVEL_CRITICAL:
+ case G_LOG_FLAG_FATAL:
+ case G_LOG_LEVEL_ERROR:
+ log_level_str = "-Error **";
+ break;
+
+ case G_LOG_LEVEL_DEBUG:
+ log_level_str = "[Debug]";
+ break;
+
+ default:
+ log_level_str = "";
+ break;
+ }
+
+ g_print ("[%s] %s %s\n", time_str, log_level_str, message);
+}
+
+static void
+print_version_and_exit (void)
+{
+ g_print ("\n"
+ PROGRAM_NAME " " PROGRAM_VERSION "\n"
+ "Copyright (2011) Aleksander Morgado\n"
+ "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>\n"
+ "This is free software: you are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law.\n"
+ "\n");
+ exit (EXIT_SUCCESS);
+}
+
+void
+mmcli_async_operation_done (void)
+{
+ if (cancellable) {
+ g_object_unref (cancellable);
+ cancellable = NULL;
+ }
+
+ g_main_loop_quit (loop);
+}
+
+void
+mmcli_force_async_operation (void)
+{
+ if (!async_flag) {
+ g_debug ("Forcing request to be run asynchronously");
+ async_flag = TRUE;
+ }
+}
+
+void
+mmcli_force_sync_operation (void)
+{
+ if (async_flag) {
+ g_debug ("Ignoring request to run asynchronously");
+ async_flag = FALSE;
+ }
+}
+
+void
+mmcli_force_operation_timeout (GDBusProxy *proxy)
+{
+ g_dbus_proxy_set_default_timeout (proxy, timeout * 1000);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ GDBusConnection *connection;
+ GOptionContext *context;
+ GError *error = NULL;
+
+ setlocale (LC_ALL, "");
+
+ g_type_init ();
+
+ /* Setup option context, process it and destroy it */
+ context = g_option_context_new ("- Control and monitor the ModemManager");
+ g_option_context_add_group (context,
+ mmcli_manager_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_get_common_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_3gpp_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_cdma_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_simple_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_location_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_messaging_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_time_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_modem_firmware_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_sim_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_bearer_get_option_group ());
+ g_option_context_add_group (context,
+ mmcli_sms_get_option_group ());
+ g_option_context_add_main_entries (context, main_entries, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ if (version_flag)
+ print_version_and_exit ();
+
+ if (verbose_flag)
+ g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, log_handler, NULL);
+
+ /* Setup signals */
+ signal (SIGINT, signals_handler);
+ signal (SIGHUP, signals_handler);
+ signal (SIGTERM, signals_handler);
+
+ /* Setup dbus connection to use */
+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (!connection) {
+ g_printerr ("error: couldn't get bus: %s\n",
+ error ? error->message : "unknown error");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Create requirements for async options */
+ cancellable = g_cancellable_new ();
+ loop = g_main_loop_new (NULL, FALSE);
+
+ /* Manager options? */
+ if (mmcli_manager_options_enabled ()) {
+ /* Ensure options from different groups are not enabled */
+ if (mmcli_modem_options_enabled ()) {
+ g_printerr ("error: cannot use manager and modem options "
+ "at the same time\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (async_flag)
+ mmcli_manager_run_asynchronous (connection, cancellable);
+ else
+ mmcli_manager_run_synchronous (connection);
+ }
+ /* Sim options? */
+ else if (mmcli_sim_options_enabled ()) {
+ if (async_flag)
+ mmcli_sim_run_asynchronous (connection, cancellable);
+ else
+ mmcli_sim_run_synchronous (connection);
+ }
+ /* Bearer options? */
+ else if (mmcli_bearer_options_enabled ()) {
+ if (async_flag)
+ mmcli_bearer_run_asynchronous (connection, cancellable);
+ else
+ mmcli_bearer_run_synchronous (connection);
+ }
+ /* Sms options? */
+ else if (mmcli_sms_options_enabled ()) {
+ if (async_flag)
+ mmcli_sms_run_asynchronous (connection, cancellable);
+ else
+ mmcli_sms_run_synchronous (connection);
+ }
+ /* Modem 3GPP options? */
+ else if (mmcli_modem_3gpp_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_3gpp_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_3gpp_run_synchronous (connection);
+ }
+ /* Modem CDMA options? */
+ else if (mmcli_modem_cdma_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_cdma_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_cdma_run_synchronous (connection);
+ }
+ /* Modem Simple options? */
+ else if (mmcli_modem_simple_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_simple_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_simple_run_synchronous (connection);
+ }
+ /* Modem Location options? */
+ else if (mmcli_modem_location_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_location_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_location_run_synchronous (connection);
+ }
+ /* Modem Messaging options? */
+ else if (mmcli_modem_messaging_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_messaging_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_messaging_run_synchronous (connection);
+ }
+ /* Modem Time options? */
+ else if (mmcli_modem_time_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_time_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_time_run_synchronous (connection);
+ }
+ /* Modem Firmware options? */
+ else if (mmcli_modem_firmware_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_firmware_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_firmware_run_synchronous (connection);
+ }
+ /* Modem options?
+ * NOTE: let this check be always the last one, as other groups also need
+ * having a modem specified, and therefore if -m is set, modem options
+ * are always enabled. */
+ else if (mmcli_modem_options_enabled ()) {
+ if (async_flag)
+ mmcli_modem_run_asynchronous (connection, cancellable);
+ else
+ mmcli_modem_run_synchronous (connection);
+ }
+ /* No options? */
+ else {
+ g_printerr ("error: no actions specified\n");
+ exit (EXIT_FAILURE);
+ }
+
+ /* Run loop only in async operations */
+ if (async_flag)
+ g_main_loop_run (loop);
+
+ if (mmcli_manager_options_enabled ()) {
+ mmcli_manager_shutdown ();
+ } else if (mmcli_modem_3gpp_options_enabled ()) {
+ mmcli_modem_3gpp_shutdown ();
+ } else if (mmcli_modem_cdma_options_enabled ()) {
+ mmcli_modem_cdma_shutdown ();
+ } else if (mmcli_modem_simple_options_enabled ()) {
+ mmcli_modem_simple_shutdown ();
+ } else if (mmcli_modem_location_options_enabled ()) {
+ mmcli_modem_location_shutdown ();
+ } else if (mmcli_modem_messaging_options_enabled ()) {
+ mmcli_modem_messaging_shutdown ();
+ } else if (mmcli_modem_time_options_enabled ()) {
+ mmcli_modem_time_shutdown ();
+ } else if (mmcli_modem_firmware_options_enabled ()) {
+ mmcli_modem_firmware_shutdown ();
+ } else if (mmcli_sim_options_enabled ()) {
+ mmcli_sim_shutdown ();
+ } else if (mmcli_bearer_options_enabled ()) {
+ mmcli_bearer_shutdown ();
+ } else if (mmcli_sms_options_enabled ()) {
+ mmcli_sms_shutdown ();
+ } else if (mmcli_modem_options_enabled ()) {
+ mmcli_modem_shutdown ();
+ }
+
+ if (cancellable)
+ g_object_unref (cancellable);
+ g_main_loop_unref (loop);
+ g_object_unref (connection);
+
+ return EXIT_SUCCESS;
+}
diff --git a/cli/mmcli.h b/cli/mmcli.h
new file mode 100644
index 0000000..5243969
--- /dev/null
+++ b/cli/mmcli.h
@@ -0,0 +1,128 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * mmcli -- Control modem status & access information from the command line
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2011 Aleksander Morgado <aleksander@gnu.org>
+ */
+
+#include <glib.h>
+
+#ifndef __MMCLI_H__
+#define __MMCLI_H__
+
+/* Common */
+void mmcli_async_operation_done (void);
+void mmcli_force_async_operation (void);
+void mmcli_force_sync_operation (void);
+void mmcli_force_operation_timeout (GDBusProxy *proxy);
+
+/* Manager group */
+GOptionGroup *mmcli_manager_get_option_group (void);
+gboolean mmcli_manager_options_enabled (void);
+void mmcli_manager_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_manager_run_synchronous (GDBusConnection *connection);
+void mmcli_manager_shutdown (void);
+
+/* Modem group */
+GOptionGroup *mmcli_modem_get_option_group (void);
+gboolean mmcli_modem_options_enabled (void);
+void mmcli_modem_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_shutdown (void);
+
+/* 3GPP group */
+GOptionGroup *mmcli_modem_3gpp_get_option_group (void);
+gboolean mmcli_modem_3gpp_options_enabled (void);
+void mmcli_modem_3gpp_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_3gpp_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_3gpp_shutdown (void);
+
+/* CDMA group */
+GOptionGroup *mmcli_modem_cdma_get_option_group (void);
+gboolean mmcli_modem_cdma_options_enabled (void);
+void mmcli_modem_cdma_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_cdma_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_cdma_shutdown (void);
+
+/* Simple group */
+GOptionGroup *mmcli_modem_simple_get_option_group (void);
+gboolean mmcli_modem_simple_options_enabled (void);
+void mmcli_modem_simple_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_simple_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_simple_shutdown (void);
+
+/* Location group */
+GOptionGroup *mmcli_modem_location_get_option_group (void);
+gboolean mmcli_modem_location_options_enabled (void);
+void mmcli_modem_location_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_location_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_location_shutdown (void);
+
+/* Messaging group */
+GOptionGroup *mmcli_modem_messaging_get_option_group (void);
+gboolean mmcli_modem_messaging_options_enabled (void);
+void mmcli_modem_messaging_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_messaging_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_messaging_shutdown (void);
+
+/* Time group */
+GOptionGroup *mmcli_modem_time_get_option_group (void);
+gboolean mmcli_modem_time_options_enabled (void);
+void mmcli_modem_time_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_time_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_time_shutdown (void);
+
+/* Firmware group */
+GOptionGroup *mmcli_modem_firmware_get_option_group (void);
+gboolean mmcli_modem_firmware_options_enabled (void);
+void mmcli_modem_firmware_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_modem_firmware_run_synchronous (GDBusConnection *connection);
+void mmcli_modem_firmware_shutdown (void);
+
+/* Bearer group */
+GOptionGroup *mmcli_bearer_get_option_group (void);
+gboolean mmcli_bearer_options_enabled (void);
+void mmcli_bearer_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_bearer_run_synchronous (GDBusConnection *connection);
+void mmcli_bearer_shutdown (void);
+
+/* SIM group */
+GOptionGroup *mmcli_sim_get_option_group (void);
+gboolean mmcli_sim_options_enabled (void);
+void mmcli_sim_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_sim_run_synchronous (GDBusConnection *connection);
+void mmcli_sim_shutdown (void);
+
+/* SMS group */
+GOptionGroup *mmcli_sms_get_option_group (void);
+gboolean mmcli_sms_options_enabled (void);
+void mmcli_sms_run_asynchronous (GDBusConnection *connection,
+ GCancellable *cancellable);
+void mmcli_sms_run_synchronous (GDBusConnection *connection);
+void mmcli_sms_shutdown (void);
+
+#endif /* __MMCLI_H__ */