Implement per modem type DBus interfaces.

A major code reorganization.
This commit is contained in:
Tambet Ingo
2008-08-21 09:11:17 +03:00
parent 751a9f8273
commit 149b41f220
17 changed files with 1404 additions and 869 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
EXTRA_DIST = \
mm-manager.xml \
mm-modem.xml
mm-modem.xml \
mm-gsm-modem.xml \
mm-cdma-modem.xml
+2
View File
@@ -24,4 +24,6 @@
<xi:include href="mm-manager.xml"/>
<xi:include href="mm-modem.xml"/>
<xi:include href="mm-cdma-modem.xml"/>
<xi:include href="mm-gsm-modem.xml"/>
</tp:spec>
+31
View File
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.ModemManager.Modem.Cdma">
<method name="GetSignalQuality">
<tp:docstring>
Get the current signal quality.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_cdma_modem_get_signal_quality"/>
<arg name="quality" type="u" direction="out">
<tp:docstring>
Signal quality (percent).
</tp:docstring>
</arg>
</method>
<signal name="SignalQuality">
<tp:docstring>
The signal quality changed.
</tp:docstring>
<arg name="quality" type="u">
<tp:docstring>
The new quality in percent, 0..100.
</tp:docstring>
</arg>
</signal>
</interface>
</node>
+243
View File
@@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.freedesktop.ModemManager.Modem.Gsm">
<method name="SetPin">
<tp:docstring>
Set the PIN (or PUK) to unlock the SIM card.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_set_pin"/>
<arg name="pin" type="s" direction="in">
The PIN code.
</arg>
</method>
<method name="Register">
<tp:docstring>
Register the device to network.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_register"/>
<arg name="network_id" type="s" direction="in">
<tp:docstring>
The network ID to register. An empty string can be used to register to the home network.
</tp:docstring>
</arg>
</method>
<method name="Scan">
<tp:docstring>
Scan for available networks.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_scan"/>
<arg name="results" type="aa{ss}" direction="out">
<tp:docstring>
Found networks. It's an array of dictionaries (strings for keys and values), the list of known keys is the following: status, operator-long, operator-short, operator-num.
</tp:docstring>
</arg>
</method>
<method name="SetAPN">
<tp:docstring>
Set the APN.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_set_apn"/>
<arg name="apn" type="s" direction="in">
The APN.
</arg>
</method>
<method name="GetSignalQuality">
<tp:docstring>
Get the current signal quality.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_signal_quality"/>
<arg name="quality" type="u" direction="out">
<tp:docstring>
Signal quality (percent).
</tp:docstring>
</arg>
</method>
<method name="SetBand">
<tp:docstring>
Set the GSM band.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_set_band"/>
<arg name="band" type="u" direction="in" tp:type="MM_GSM_MODEM_BAND">
<tp:docstring>
The band.
</tp:docstring>
</arg>
</method>
<method name="GetBand">
<tp:docstring>
Get the current band.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_band"/>
<arg name="band" type="u" direction="out" tp:type="MM_GSM_MODEM_BAND">
<tp:docstring>
The current band.
</tp:docstring>
</arg>
</method>
<method name="SetNetworkMode">
<tp:docstring>
Set the GSM network mode.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_set_network_mode"/>
<arg name="mode" type="u" direction="in" tp:type="MM_GSM_MODEM_NETWORK_MODE">
<tp:docstring>
The GSM network mode.
</tp:docstring>
</arg>
</method>
<method name="GetNetworkMode">
<tp:docstring>
Get the network mode.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_get_network_mode"/>
<arg name="mode" type="u" direction="out" tp:type="MM_GSM_MODEM_NETWORK_MODE">
<tp:docstring>
The current network mode.
</tp:docstring>
</arg>
</method>
<signal name="SignalQuality">
<tp:docstring>
The signal quality changed.
</tp:docstring>
<arg name="quality" type="u">
<tp:docstring>
The new quality in percent, 0..100.
</tp:docstring>
</arg>
</signal>
<signal name="NetworkMode">
<tp:docstring>
The network mode changed.
</tp:docstring>
<arg name="mode" type="u" tp:type="MM_GSM_MODEM_NETWORK_MODE">
<tp:docstring>
The new network mode.
</tp:docstring>
</arg>
</signal>
<tp:enum name="MM_GSM_MODEM_NETWORK_MODE" type="u">
<tp:enumvalue suffix="ANY" value="0">
<tp:docstring>
Any network mode can be used.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="GPRS" value="1">
<tp:docstring>
GPRS
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="EDGE" value="2">
<tp:docstring>
EDGE
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="3G" value="3">
<tp:docstring>
3G
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="HSDPA" value="4">
<tp:docstring>
HSDPA
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PREFER_2G" value="5">
<tp:docstring>
Prefer 2G (GPRS or EDGE).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PREFER_3G" value="6">
<tp:docstring>
Prefer 3G (3G or HSDPA).
</tp:docstring>
</tp:enumvalue>
</tp:enum>
<tp:enum name="MM_GSM_MODEM_BAND" type="u">
<tp:enumvalue suffix="ANY" value="0">
<tp:docstring>
Any band can be used.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="EGSM" value="1">
<tp:docstring>
EGSM (900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="DCS" value="2">
<tp:docstring>
DCS (1800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PCS" value="3">
<tp:docstring>
PCS (1900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="G850" value="4">
<tp:docstring>
G850 (850 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U2100" value="5">
<tp:docstring>
U2100 (WCDMA 2100 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U1700" value="6">
<tp:docstring>
U1700 (WCDMA 3GPP UMTS1800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="17IV" value="7">
<tp:docstring>
17IV (WCDMA 3GPP AWS 1700/2100 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U800" value="8">
<tp:docstring>
U800 (WCDMA 3GPP UMTS800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U850" value="9">
<tp:docstring>
U850 (WCDMA 3GPP UMTS850 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U900" value="10">
<tp:docstring>
U900 (WCDMA 3GPP UMTS900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U17IX" value="11">
<tp:docstring>
U17IX (WCDMA 3GPP UMTS MHz).
</tp:docstring>
</tp:enumvalue>
</tp:enum>
</interface>
</node>
+1 -231
View File
@@ -4,7 +4,7 @@
<interface name="org.freedesktop.ModemManager.Modem">
<method name="Enable">
<tp:docstring>
Enable the device. Initializes the modem and checks whether PIN (or PUK) is needed.
Enable the device. Initializes the modem.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_enable"/>
@@ -15,30 +15,6 @@
</arg>
</method>
<method name="SetPin">
<tp:docstring>
Set the PIN (or PUK) to unlock the SIM card.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_set_pin"/>
<arg name="pin" type="s" direction="in">
The PIN code.
</arg>
</method>
<method name="Register">
<tp:docstring>
Register the device to network.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_register"/>
<arg name="network_id" type="s" direction="in">
<tp:docstring>
The network ID to register. An empty string can be used to register to the home network.
</tp:docstring>
</arg>
</method>
<method name="Connect">
<tp:docstring>
Dial in.
@@ -50,11 +26,6 @@
The number to use for dialing.
</tp:docstring>
</arg>
<arg name="apn" type="s" direction="in">
<tp:docstring>
The APN to use. Can be an empty string to use the default APN from the SIM card.
</tp:docstring>
</arg>
</method>
<method name="Disconnect">
@@ -65,84 +36,6 @@
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_disconnect"/>
</method>
<method name="Scan">
<tp:docstring>
Scan for available networks.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_scan"/>
<arg name="results" type="aa{ss}" direction="out">
<tp:docstring>
Found networks. It's an array of dictionaries (strings for keys and values), the list of known keys is the following: status, operator-long, operator-short, operator-num.
</tp:docstring>
</arg>
</method>
<method name="GetSignalQuality">
<tp:docstring>
Get the current signal quality.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_get_signal_quality"/>
<arg name="quality" type="u" direction="out">
<tp:docstring>
Signal quality (percent).
</tp:docstring>
</arg>
</method>
<method name="SetBand">
<tp:docstring>
Set the band.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_set_band"/>
<arg name="band" type="u" direction="in" tp:type="MM_MODEM_BAND">
<tp:docstring>
The new band.
</tp:docstring>
</arg>
</method>
<method name="GetBand">
<tp:docstring>
Get the current band.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_get_band"/>
<arg name="band" type="u" direction="out" tp:type="MM_MODEM_BAND">
<tp:docstring>
The current band.
</tp:docstring>
</arg>
</method>
<method name="SetNetworkMode">
<tp:docstring>
Set the network mode.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_set_network_mode"/>
<arg name="mode" type="u" direction="in" tp:type="MM_MODEM_NETWORK_MODE">
<tp:docstring>
The new mode.
</tp:docstring>
</arg>
</method>
<method name="GetNetworkMode">
<tp:docstring>
Get the network mode.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_modem_get_network_mode"/>
<arg name="mode" type="u" direction="out">
<tp:docstring>
The current network mode.
</tp:docstring>
</arg>
</method>
<property name="DataDevice" type="s" access="read">
<tp:docstring>
The serial device which can be used to start pppd.
@@ -161,28 +54,6 @@
</tp:docstring>
</property>
<signal name="SignalQuality">
<tp:docstring>
The signal quality changed.
</tp:docstring>
<arg name="quality" type="u">
<tp:docstring>
The new quality in percent, 0..100.
</tp:docstring>
</arg>
</signal>
<signal name="NetworkMode">
<tp:docstring>
The network mode changed.
</tp:docstring>
<arg name="mode" type="u" tp:type="MM_MODEM_NETWORK_MODE">
<tp:docstring>
The new network mode.
</tp:docstring>
</arg>
</signal>
<tp:enum name="MM_MODEM_TYPE" type="u">
<tp:enumvalue suffix="GSM" value="1">
<tp:docstring>
@@ -196,106 +67,5 @@
</tp:enumvalue>
</tp:enum>
<tp:enum name="MM_MODEM_NETWORK_MODE" type="u">
<tp:enumvalue suffix="ANY" value="0">
<tp:docstring>
Any network mode can be used.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="GPRS" value="1">
<tp:docstring>
GPRS
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="EDGE" value="2">
<tp:docstring>
EDGE
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="3G" value="3">
<tp:docstring>
3G
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="HSDPA" value="4">
<tp:docstring>
HSDPA
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PREFER_2G" value="5">
<tp:docstring>
Prefer 2G (GPRS or EDGE).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PREFER_3G" value="6">
<tp:docstring>
Prefer 3G (3G or HSDPA).
</tp:docstring>
</tp:enumvalue>
</tp:enum>
<tp:enum name="MM_MODEM_BAND" type="u">
<tp:enumvalue suffix="ANY" value="0">
<tp:docstring>
Any band can be used.
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="EGSM" value="1">
<tp:docstring>
EGSM (900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="DCS" value="2">
<tp:docstring>
DCS (1800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="PCS" value="3">
<tp:docstring>
PCS (1900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="G850" value="4">
<tp:docstring>
G850 (850 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U2100" value="5">
<tp:docstring>
U2100 (WCDMA 2100 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U1700" value="6">
<tp:docstring>
U1700 (WCDMA 3GPP UMTS1800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="17IV" value="7">
<tp:docstring>
17IV (WCDMA 3GPP AWS 1700/2100 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U800" value="8">
<tp:docstring>
U800 (WCDMA 3GPP UMTS800 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U850" value="9">
<tp:docstring>
U850 (WCDMA 3GPP UMTS850 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U900" value="10">
<tp:docstring>
U900 (WCDMA 3GPP UMTS900 MHz).
</tp:docstring>
</tp:enumvalue>
<tp:enumvalue suffix="U17IX" value="11">
<tp:docstring>
U17IX (WCDMA 3GPP UMTS MHz).
</tp:docstring>
</tp:enumvalue>
</tp:enum>
</interface>
</node>
+144 -108
View File
@@ -4,15 +4,11 @@
#include <stdio.h>
#include <string.h>
#include "mm-modem-huawei.h"
#include "mm-gsm-modem.h"
#include "mm-modem-error.h"
#include "mm-callback-info.h"
static MMModem *parent_class_iface = NULL;
static void modem_init (MMModem *modem_class);
G_DEFINE_TYPE_EXTENDED (MMModemHuawei, mm_modem_huawei, MM_TYPE_GENERIC_GSM,
0, G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
static gpointer mm_modem_huawei_parent_class = NULL;
#define MM_MODEM_HUAWEI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_HUAWEI, MMModemHuaweiPrivate))
@@ -48,7 +44,7 @@ mm_modem_huawei_new (const char *data_device,
/*****************************************************************************/
static void
parse_monitor_line (MMModem *modem, char *buf)
parse_monitor_line (MMGsmModem *gsm_modem, char *buf)
{
char **lines;
char **iter;
@@ -75,25 +71,25 @@ parse_monitor_line (MMModem *modem, char *buf)
quality = quality * 100 / 31;
g_debug ("Signal quality: %d", quality);
mm_modem_signal_quality (modem, (guint32) quality);
mm_gsm_modem_signal_quality (gsm_modem, (guint32) quality);
} else if (!strncmp (line, "MODE:", 5)) {
MMModemNetworkMode mode = 0;
MMGsmModemNetworkMode mode = 0;
int a;
int b;
if (sscanf (line + 5, "%d,%d", &a, &b)) {
if (a == 3 && b == 2)
mode = MM_MODEM_NETWORK_MODE_GPRS;
mode = MM_GSM_MODEM_NETWORK_MODE_GPRS;
else if (a == 3 && b == 3)
mode = MM_MODEM_NETWORK_MODE_EDGE;
mode = MM_GSM_MODEM_NETWORK_MODE_EDGE;
else if (a == 5 && b == 4)
mode = MM_MODEM_NETWORK_MODE_3G;
mode = MM_GSM_MODEM_NETWORK_MODE_3G;
else if (a ==5 && b == 5)
mode = MM_MODEM_NETWORK_MODE_HSDPA;
mode = MM_GSM_MODEM_NETWORK_MODE_HSDPA;
if (mode) {
g_debug ("Mode: %d", mode);
mm_modem_network_mode (modem, mode);
mm_gsm_modem_network_mode (gsm_modem, mode);
}
}
}
@@ -117,7 +113,7 @@ monitor_device_got_data (GIOChannel *source,
if (bytes_read) {
buf[bytes_read] = '\0';
parse_monitor_line (MM_MODEM (data), buf);
parse_monitor_line (MM_GSM_MODEM (data), buf);
}
} while (bytes_read == 4096 || status == G_IO_STATUS_AGAIN);
}
@@ -136,8 +132,10 @@ enable (MMModem *modem,
gpointer user_data)
{
MMModemHuaweiPrivate *priv = MM_MODEM_HUAWEI_GET_PRIVATE (modem);
MMModem *parent_modem_iface;
parent_class_iface->enable (modem, enable, callback, user_data);
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
parent_modem_iface->enable (modem, enable, callback, user_data);
if (enable) {
GIOChannel *channel;
@@ -158,6 +156,7 @@ enable (MMModem *modem,
mm_serial_close (priv->monitor_device);
}
}
}
static gboolean
@@ -172,51 +171,6 @@ parse_syscfg (const char *reply, int *mode_a, int *mode_b, guint32 *band, int *u
return FALSE;
}
static void
get_network_mode_done (MMSerial *serial, const char *reply, gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
int a, b, u1, u2;
guint32 band;
if (parse_syscfg (reply, &a, &b, &band, &u1, &u2)) {
if (a == 2 && b == 1)
info->uint_result = MM_MODEM_NETWORK_MODE_PREFER_2G;
else if (a == 2 && b == 2)
info->uint_result = MM_MODEM_NETWORK_MODE_PREFER_3G;
else if (a == 13 && b == 1)
info->uint_result = MM_MODEM_NETWORK_MODE_GPRS;
else if (a == 14 && b == 2)
info->uint_result = MM_MODEM_NETWORK_MODE_3G;
}
if (info->uint_result == 0)
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse network mode results");
mm_callback_info_schedule (info);
}
static void
get_network_mode (MMModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_uint_new (modem, callback, user_data);
if (mm_serial_send_command_string (MM_SERIAL (modem), "AT^SYSCFG?"))
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_network_mode_done, info);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Getting network mode failed.");
mm_callback_info_schedule (info);
}
}
static void
set_network_mode_done (MMSerial *serial,
int reply_index,
@@ -266,8 +220,8 @@ set_network_mode_get_done (MMSerial *serial, const char *reply, gpointer user_da
}
static void
set_network_mode (MMModem *modem,
MMModemNetworkMode mode,
set_network_mode (MMGsmModem *modem,
MMGsmModemNetworkMode mode,
MMModemFn callback,
gpointer user_data)
{
@@ -275,29 +229,29 @@ set_network_mode (MMModem *modem,
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_new (modem, callback, user_data);
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
switch (mode) {
case MM_MODEM_NETWORK_MODE_ANY:
case MM_GSM_MODEM_NETWORK_MODE_ANY:
/* Do nothing */
mm_callback_info_schedule (info);
return;
break;
case MM_MODEM_NETWORK_MODE_GPRS:
case MM_MODEM_NETWORK_MODE_EDGE:
case MM_GSM_MODEM_NETWORK_MODE_GPRS:
case MM_GSM_MODEM_NETWORK_MODE_EDGE:
mm_callback_info_set_data (info, "mode-a", GINT_TO_POINTER (13), NULL);
mm_callback_info_set_data (info, "mode-b", GINT_TO_POINTER (1), NULL);
break;
case MM_MODEM_NETWORK_MODE_3G:
case MM_MODEM_NETWORK_MODE_HSDPA:
case MM_GSM_MODEM_NETWORK_MODE_3G:
case MM_GSM_MODEM_NETWORK_MODE_HSDPA:
mm_callback_info_set_data (info, "mode-a", GINT_TO_POINTER (14), NULL);
mm_callback_info_set_data (info, "mode-b", GINT_TO_POINTER (2), NULL);
break;
case MM_MODEM_NETWORK_MODE_PREFER_2G:
case MM_GSM_MODEM_NETWORK_MODE_PREFER_2G:
mm_callback_info_set_data (info, "mode-a", GINT_TO_POINTER (2), NULL);
mm_callback_info_set_data (info, "mode-b", GINT_TO_POINTER (1), NULL);
break;
case MM_MODEM_NETWORK_MODE_PREFER_3G:
case MM_GSM_MODEM_NETWORK_MODE_PREFER_3G:
mm_callback_info_set_data (info, "mode-a", GINT_TO_POINTER (2), NULL);
mm_callback_info_set_data (info, "mode-b", GINT_TO_POINTER (2), NULL);
break;
@@ -318,56 +272,54 @@ set_network_mode (MMModem *modem,
}
static void
get_band_done (MMSerial *serial, const char *reply, gpointer user_data)
get_network_mode_done (MMSerial *serial, const char *reply, gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
int a, b, u1, u2;
guint32 band;
info->uint_result = 0xdeadbeaf;
if (parse_syscfg (reply, &a, &b, &band, &u1, &u2)) {
if (band == 0x3FFFFFFF)
info->uint_result = MM_MODEM_BAND_ANY;
else if (band == 0x400380)
info->uint_result = MM_MODEM_BAND_DCS;
else if (band == 0x200000)
info->uint_result = MM_MODEM_BAND_PCS;
if (a == 2 && b == 1)
info->uint_result = MM_GSM_MODEM_NETWORK_MODE_PREFER_2G;
else if (a == 2 && b == 2)
info->uint_result = MM_GSM_MODEM_NETWORK_MODE_PREFER_3G;
else if (a == 13 && b == 1)
info->uint_result = MM_GSM_MODEM_NETWORK_MODE_GPRS;
else if (a == 14 && b == 2)
info->uint_result = MM_GSM_MODEM_NETWORK_MODE_3G;
}
if (info->uint_result == 0xdeadbeaf) {
info->uint_result = 0;
if (info->uint_result == 0)
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse band results");
}
"%s", "Could not parse network mode results");
mm_callback_info_schedule (info);
}
static void
get_band (MMModem *modem,
MMModemUIntFn callback,
gpointer user_data)
get_network_mode (MMGsmModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_uint_new (modem, callback, user_data);
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
if (mm_serial_send_command_string (MM_SERIAL (modem), "AT^SYSCFG?"))
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_band_done, info);
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_network_mode_done, info);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Getting band failed.");
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Getting network mode failed.");
mm_callback_info_schedule (info);
}
}
static void
set_band_done (MMSerial *serial,
int reply_index,
gpointer user_data)
int reply_index,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
@@ -412,8 +364,8 @@ set_band_get_done (MMSerial *serial, const char *reply, gpointer user_data)
}
static void
set_band (MMModem *modem,
MMModemBand band,
set_band (MMGsmModem *modem,
MMGsmModemBand band,
MMModemFn callback,
gpointer user_data)
{
@@ -421,18 +373,18 @@ set_band (MMModem *modem,
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_new (modem, callback, user_data);
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
switch (band) {
case MM_MODEM_BAND_ANY:
case MM_GSM_MODEM_BAND_ANY:
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (0x3FFFFFFF), NULL);
break;
case MM_MODEM_BAND_EGSM:
case MM_MODEM_BAND_DCS:
case MM_MODEM_BAND_U2100:
case MM_GSM_MODEM_BAND_EGSM:
case MM_GSM_MODEM_BAND_DCS:
case MM_GSM_MODEM_BAND_U2100:
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (0x400380), NULL);
break;
case MM_MODEM_BAND_PCS:
case MM_GSM_MODEM_BAND_PCS:
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (0x200000), NULL);
break;
default:
@@ -451,19 +403,68 @@ set_band (MMModem *modem,
}
}
static void
get_band_done (MMSerial *serial, const char *reply, gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
int a, b, u1, u2;
guint32 band;
info->uint_result = 0xdeadbeaf;
if (parse_syscfg (reply, &a, &b, &band, &u1, &u2)) {
if (band == 0x3FFFFFFF)
info->uint_result = MM_GSM_MODEM_BAND_ANY;
else if (band == 0x400380)
info->uint_result = MM_GSM_MODEM_BAND_DCS;
else if (band == 0x200000)
info->uint_result = MM_GSM_MODEM_BAND_PCS;
}
if (info->uint_result == 0xdeadbeaf) {
info->uint_result = 0;
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse band results");
}
mm_callback_info_schedule (info);
}
static void
get_band (MMGsmModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
if (mm_serial_send_command_string (MM_SERIAL (modem), "AT^SYSCFG?"))
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_band_done, info);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Getting band failed.");
mm_callback_info_schedule (info);
}
}
/*****************************************************************************/
static void
modem_init (MMModem *modem_class)
{
parent_class_iface = g_type_interface_peek_parent (modem_class);
/* interface implementation */
modem_class->enable = enable;
modem_class->set_network_mode = set_network_mode;
modem_class->get_network_mode = get_network_mode;
modem_class->set_band = set_band;
modem_class->get_band = get_band;
}
static void
gsm_modem_init (MMGsmModem *gsm_modem_class)
{
gsm_modem_class->set_network_mode = set_network_mode;
gsm_modem_class->get_network_mode = get_network_mode;
gsm_modem_class->set_band = set_band;
gsm_modem_class->get_band = get_band;
}
static void
@@ -552,6 +553,7 @@ mm_modem_huawei_class_init (MMModemHuaweiClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
mm_modem_huawei_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (object_class, sizeof (MMModemHuaweiPrivate));
/* Virtual methods */
@@ -559,7 +561,6 @@ mm_modem_huawei_class_init (MMModemHuaweiClass *klass)
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
/* Properties */
g_object_class_install_property
(object_class, PROP_MONITOR_DEVICE,
@@ -569,3 +570,38 @@ mm_modem_huawei_class_init (MMModemHuaweiClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
GType
mm_modem_huawei_get_type (void)
{
static GType modem_huawei_type = 0;
if (G_UNLIKELY (modem_huawei_type == 0)) {
static const GTypeInfo modem_huawei_type_info = {
sizeof (MMModemHuaweiClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) mm_modem_huawei_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (MMModemHuawei),
0, /* n_preallocs */
(GInstanceInitFunc) mm_modem_huawei_init,
};
static const GInterfaceInfo modem_iface_info = {
(GInterfaceInitFunc) modem_init
};
static const GInterfaceInfo gsm_modem_iface_info = {
(GInterfaceInitFunc) gsm_modem_init
};
modem_huawei_type = g_type_register_static (MM_TYPE_GENERIC_GSM, "MMModemHuawei", &modem_huawei_type_info, 0);
g_type_add_interface_static (modem_huawei_type, MM_TYPE_MODEM, &modem_iface_info);
g_type_add_interface_static (modem_huawei_type, MM_TYPE_GSM_MODEM, &gsm_modem_iface_info);
}
return modem_huawei_type;
}
+12
View File
@@ -11,10 +11,14 @@ modem_manager_SOURCES = \
main.c \
mm-callback-info.c \
mm-callback-info.h \
mm-cdma-modem.c \
mm-cdma-modem.h \
mm-generic-cdma.c \
mm-generic-cdma.h \
mm-generic-gsm.c \
mm-generic-gsm.h \
mm-gsm-modem.c \
mm-gsm-modem.h \
mm-manager.c \
mm-manager.h \
mm-modem.c \
@@ -32,7 +36,15 @@ mm-manager-glue.h: $(top_srcdir)/introspection/mm-manager.xml
mm-modem-glue.h: $(top_srcdir)/introspection/mm-modem.xml
dbus-binding-tool --prefix=mm_modem --mode=glib-server --output=$@ $<
mm-gsm-modem-glue.h: $(top_srcdir)/introspection/mm-gsm-modem.xml
dbus-binding-tool --prefix=mm_gsm_modem --mode=glib-server --output=$@ $<
mm-cdma-modem-glue.h: $(top_srcdir)/introspection/mm-cdma-modem.xml
dbus-binding-tool --prefix=mm_cdma_modem --mode=glib-server --output=$@ $<
BUILT_SOURCES = \
mm-cdma-modem-glue.h \
mm-gsm-modem-glue.h \
mm-manager-glue.h \
mm-modem-glue.h
+128
View File
@@ -0,0 +1,128 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-cdma-modem.h"
#include "mm-modem-error.h"
#include "mm-callback-info.h"
static void impl_cdma_modem_get_signal_quality (MMCdmaModem *modem, DBusGMethodInvocation *context);
#include "mm-cdma-modem-glue.h"
enum {
SIGNAL_QUALITY,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void
uint_op_not_supported (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_uint_new (self, callback, user_data);
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"%s", "Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_call_done (MMModem *modem, guint32 result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
void
mm_cdma_modem_get_signal_quality (MMCdmaModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_CDMA_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_CDMA_MODEM_GET_INTERFACE (self)->get_signal_quality)
MM_CDMA_MODEM_GET_INTERFACE (self)->get_signal_quality (self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_cdma_modem_get_signal_quality (MMCdmaModem *modem, DBusGMethodInvocation *context)
{
mm_cdma_modem_get_signal_quality (modem, uint_call_done, context);
}
void
mm_cdma_modem_signal_quality (MMCdmaModem *self,
guint32 quality)
{
g_return_if_fail (MM_IS_CDMA_MODEM (self));
g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality);
}
/*****************************************************************************/
static void
mm_cdma_modem_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Signals */
signals[SIGNAL_QUALITY] =
g_signal_new ("signal-quality",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMCdmaModem, signal_quality),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
initialized = TRUE;
}
GType
mm_cdma_modem_get_type (void)
{
static GType modem_type = 0;
if (!G_UNLIKELY (modem_type)) {
const GTypeInfo modem_info = {
sizeof (MMCdmaModem), /* class_size */
mm_cdma_modem_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
modem_type = g_type_register_static (G_TYPE_INTERFACE,
"MMCdmaModem",
&modem_info, 0);
g_type_interface_add_prerequisite (modem_type, MM_TYPE_MODEM);
dbus_g_object_type_install_info (modem_type, &dbus_glib_mm_cdma_modem_object_info);
}
return modem_type;
}
+39
View File
@@ -0,0 +1,39 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef MM_CDMA_MODEM_H
#define MM_CDMA_MODEM_H
#include <mm-modem.h>
#define MM_TYPE_CDMA_MODEM (mm_cdma_modem_get_type ())
#define MM_CDMA_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CDMA_MODEM, MMCdmaModem))
#define MM_IS_CDMA_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CDMA_MODEM))
#define MM_CDMA_MODEM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_CDMA_MODEM, MMCdmaModem))
typedef struct _MMCdmaModem MMCdmaModem;
struct _MMCdmaModem {
GTypeInterface g_iface;
/* Methods */
void (*get_signal_quality) (MMCdmaModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Signals */
void (*signal_quality) (MMCdmaModem *self,
guint32 quality);
};
GType mm_cdma_modem_get_type (void);
void mm_cdma_modem_get_signal_quality (MMCdmaModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Protected */
void mm_cdma_modem_signal_quality (MMCdmaModem *self,
guint32 quality);
#endif /* MM_CDMA_MODEM_H */
+95 -7
View File
@@ -1,13 +1,14 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <string.h>
#include <stdio.h>
#include "mm-generic-cdma.h"
#include "mm-cdma-modem.h"
#include "mm-modem-error.h"
#include "mm-callback-info.h"
static void modem_init (MMModem *modem_class);
G_DEFINE_TYPE_EXTENDED (MMGenericCdma, mm_generic_cdma, MM_TYPE_SERIAL,
0, G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
static gpointer mm_generic_cdma_parent_class = NULL;
#define MM_GENERIC_CDMA_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_GENERIC_CDMA, MMGenericCdmaPrivate))
@@ -131,7 +132,6 @@ dial_done (MMSerial *serial,
static void
connect (MMModem *modem,
const char *number,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
@@ -166,17 +166,71 @@ disconnect (MMModem *modem,
mm_callback_info_schedule (info);
}
static void
get_signal_quality_done (MMSerial *serial, const char *reply, gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
guint32 result = 0;
if (!strncmp (reply, "+CSQ: ", 6)) {
/* Got valid reply */
int quality;
int ber;
reply += 6;
if (sscanf (reply, "%d,%d", &quality, &ber)) {
/* 99 means unknown */
if (quality != 99)
/* Normalize the quality */
result = quality * 100 / 31;
} else
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse signal quality results");
} else
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Could not parse signal quality results");
info->uint_result = result;
mm_callback_info_schedule (info);
}
static void
get_signal_quality (MMCdmaModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
if (mm_serial_send_command_string (MM_SERIAL (modem), "AT+CSQ"))
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_signal_quality_done, info);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Getting signal quality failed.");
mm_callback_info_schedule (info);
}
}
/*****************************************************************************/
static void
modem_init (MMModem *modem_class)
{
/* interface implementation */
modem_class->enable = enable;
modem_class->connect = connect;
modem_class->disconnect = disconnect;
}
static void
cdma_modem_init (MMCdmaModem *cdma_modem_class)
{
cdma_modem_class->get_signal_quality = get_signal_quality;
}
static void
mm_generic_cdma_init (MMGenericCdma *self)
{
@@ -235,6 +289,7 @@ mm_generic_cdma_class_init (MMGenericCdmaClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
mm_generic_cdma_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (object_class, sizeof (MMGenericCdmaPrivate));
/* Virtual methods */
@@ -254,6 +309,39 @@ mm_generic_cdma_class_init (MMGenericCdmaClass *klass)
g_object_class_override_property (object_class,
MM_MODEM_PROP_TYPE,
MM_MODEM_TYPE);
}
mm_modem_install_dbus_info (G_TYPE_FROM_CLASS (klass));
GType
mm_generic_cdma_get_type (void)
{
static GType generic_cdma_type = 0;
if (G_UNLIKELY (generic_cdma_type == 0)) {
static const GTypeInfo generic_cdma_type_info = {
sizeof (MMGenericCdmaClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) mm_generic_cdma_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (MMGenericCdma),
0, /* n_preallocs */
(GInstanceInitFunc) mm_generic_cdma_init,
};
static const GInterfaceInfo modem_iface_info = {
(GInterfaceInitFunc) modem_init
};
static const GInterfaceInfo cdma_modem_iface_info = {
(GInterfaceInitFunc) cdma_modem_init
};
generic_cdma_type = g_type_register_static (MM_TYPE_SERIAL, "MMGenericCdma", &generic_cdma_type_info, 0);
g_type_add_interface_static (generic_cdma_type, MM_TYPE_MODEM, &modem_iface_info);
g_type_add_interface_static (generic_cdma_type, MM_TYPE_CDMA_MODEM, &cdma_modem_iface_info);
}
return generic_cdma_type;
}
+132 -92
View File
@@ -4,22 +4,21 @@
#include <stdio.h>
#include <string.h>
#include "mm-generic-gsm.h"
#include "mm-gsm-modem.h"
#include "mm-modem-error.h"
#include "mm-callback-info.h"
static void modem_init (MMModem *modem_class);
G_DEFINE_TYPE_EXTENDED (MMGenericGsm, mm_generic_gsm, MM_TYPE_SERIAL,
0, G_IMPLEMENT_INTERFACE (MM_TYPE_MODEM, modem_init))
static gpointer mm_generic_gsm_parent_class = NULL;
#define MM_GENERIC_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_GENERIC_GSM, MMGenericGsmPrivate))
typedef struct {
char *driver;
guint32 cid;
guint32 pending_id;
} MMGenericGsmPrivate;
static void register_auto (MMModem *modem, MMCallbackInfo *info);
static void register_auto (MMGsmModem *modem, MMCallbackInfo *info);
MMModem *
mm_generic_gsm_new (const char *serial_device, const char *driver)
@@ -33,6 +32,14 @@ mm_generic_gsm_new (const char *serial_device, const char *driver)
NULL));
}
guint32
mm_generic_gsm_get_cid (MMGenericGsm *modem)
{
g_return_val_if_fail (MM_IS_GENERIC_GSM (modem), 0);
return MM_GENERIC_GSM_GET_PRIVATE (modem)->cid;
}
/*****************************************************************************/
static void
@@ -175,7 +182,7 @@ set_pin_done (MMSerial *serial,
}
static void
set_pin (MMModem *modem,
set_pin (MMGsmModem *modem,
const char *pin,
MMModemFn callback,
gpointer user_data)
@@ -185,7 +192,7 @@ set_pin (MMModem *modem,
char *responses[] = { "OK", "ERROR", "ERR", NULL };
guint id = 0;
info = mm_callback_info_new (modem, callback, user_data);
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
command = g_strdup_printf ("AT+CPIN=\"%s\"", pin);
if (mm_serial_send_command_string (MM_SERIAL (modem), command))
@@ -222,7 +229,7 @@ register_manual_done (MMSerial *serial,
}
static void
register_manual (MMModem *modem, const char *network_id, MMCallbackInfo *info)
register_manual (MMGsmModem *modem, const char *network_id, MMCallbackInfo *info)
{
char *command;
char *responses[] = { "OK", "ERROR", "ERR", NULL };
@@ -246,7 +253,7 @@ automatic_registration_again (gpointer data)
{
MMCallbackInfo *info = (MMCallbackInfo *) data;
register_auto (MM_MODEM (mm_callback_info_get_data (info, "modem")), info);
register_auto (MM_GSM_MODEM (mm_callback_info_get_data (info, "modem")), info);
mm_callback_info_set_data (info, "modem", NULL, NULL);
@@ -292,7 +299,7 @@ register_auto_done (MMSerial *serial,
}
static void
register_auto (MMModem *modem, MMCallbackInfo *info)
register_auto (MMGsmModem *modem, MMCallbackInfo *info)
{
char *responses[] = { "+CREG: 0,0", "+CREG: 0,1", "+CREG: 0,2", "+CREG: 0,3", "+CREG: 0,5", NULL };
char *terminators[] = { "OK", "ERROR", "ERR", NULL };
@@ -309,14 +316,14 @@ register_auto (MMModem *modem, MMCallbackInfo *info)
}
static void
do_register (MMModem *modem,
do_register (MMGsmModem *modem,
const char *network_id,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (modem, callback, user_data);
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
if (network_id)
register_manual (modem, network_id, info);
@@ -325,9 +332,9 @@ do_register (MMModem *modem,
}
static void
dial_done (MMSerial *serial,
int reply_index,
gpointer user_data)
connect_done (MMSerial *serial,
int reply_index,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
@@ -355,15 +362,21 @@ dial_done (MMSerial *serial,
mm_callback_info_schedule (info);
}
static void
dial (MMModem *modem, guint cid, const char *number, MMCallbackInfo *info)
connect (MMModem *modem,
const char *number,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *command;
char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL };
guint id = 0;
guint32 cid = mm_generic_gsm_get_cid (MM_GENERIC_GSM (modem));
if (cid) {
info = mm_callback_info_new (modem, callback, user_data);
if (cid > 0) {
GString *str;
str = g_string_new ("ATD");
@@ -378,7 +391,7 @@ dial (MMModem *modem, guint cid, const char *number, MMCallbackInfo *info)
command = g_strconcat ("ATDT", number, NULL);
if (mm_serial_send_command_string (MM_SERIAL (modem), command))
id = mm_serial_wait_for_reply (MM_SERIAL (modem), 60, responses, responses, dial_done, info);
id = mm_serial_wait_for_reply (MM_SERIAL (modem), 60, responses, responses, connect_done, info);
g_free (command);
@@ -388,65 +401,6 @@ dial (MMModem *modem, guint cid, const char *number, MMCallbackInfo *info)
}
}
static void
set_apn_done (MMSerial *serial,
int reply_index,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
const char *number = (char *) mm_callback_info_get_data (info, "number");
switch (reply_index) {
case 0:
dial (MM_MODEM (serial), 1, number, info);
break;
default:
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Setting APN failed");
break;
}
if (info->error)
mm_callback_info_schedule (info);
}
static void
set_apn (MMModem *modem, const char *apn, MMCallbackInfo *info)
{
char *command;
char *responses[] = { "OK", "ERROR", NULL };
guint cid = 1;
guint id = 0;
command = g_strdup_printf ("AT+CGDCONT=%d, \"IP\", \"%s\"", cid, apn);
if (mm_serial_send_command_string (MM_SERIAL (modem), command))
id = mm_serial_wait_for_reply (MM_SERIAL (modem), 3, responses, responses, set_apn_done, info);
g_free (command);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Setting APN failed.");
mm_callback_info_schedule (info);
}
}
static void
connect (MMModem *modem,
const char *number,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (modem, callback, user_data);
if (apn) {
mm_callback_info_set_data (info, "number", g_strdup (number), g_free);
set_apn (modem, apn, info);
} else
dial (modem, 0, number, info);
}
static void
disconnect (MMModem *modem,
MMModemFn callback,
@@ -465,15 +419,15 @@ scan_callback_wrapper (MMModem *modem,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
MMModemScanFn scan_fn;
MMGsmModemScanFn scan_fn;
GPtrArray *results;
gpointer data;
scan_fn = (MMModemScanFn) mm_callback_info_get_data (info, "scan-callback");
scan_fn = (MMGsmModemScanFn) mm_callback_info_get_data (info, "scan-callback");
results = (GPtrArray *) mm_callback_info_get_data (info, "scan-results");
data = mm_callback_info_get_data (info, "scan-data");
scan_fn (modem, results, error, data);
scan_fn (MM_GSM_MODEM (modem), results, error, data);
}
static void
@@ -536,15 +490,15 @@ scan_done (MMSerial *serial, const char *reply, gpointer user_data)
}
static void
scan (MMModem *modem,
MMModemScanFn callback,
scan (MMGsmModem *modem,
MMGsmModemScanFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_new (modem, scan_callback_wrapper, NULL);
info = mm_callback_info_new (MM_MODEM (modem), scan_callback_wrapper, NULL);
info->user_data = info;
mm_callback_info_set_data (info, "scan-callback", callback, NULL);
mm_callback_info_set_data (info, "scan-data", user_data, NULL);
@@ -558,6 +512,53 @@ scan (MMModem *modem,
}
}
static void
set_apn_done (MMSerial *serial,
int reply_index,
gpointer user_data)
{
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
switch (reply_index) {
case 0:
/* success */
MM_GENERIC_GSM_GET_PRIVATE (serial)->cid = GPOINTER_TO_UINT (mm_callback_info_get_data (info, "CID"));
break;
default:
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Setting APN failed");
break;
}
mm_callback_info_schedule (info);
}
static void
set_apn (MMGsmModem *modem,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
char *command;
char *responses[] = { "OK", "ERROR", NULL };
guint cid = 1;
guint id = 0;
info = mm_callback_info_new (MM_MODEM (modem), callback, user_data);
mm_callback_info_set_data (info, "CID", GUINT_TO_POINTER (cid), NULL);
command = g_strdup_printf ("AT+CGDCONT=%d, \"IP\", \"%s\"", cid, apn);
if (mm_serial_send_command_string (MM_SERIAL (modem), command))
id = mm_serial_wait_for_reply (MM_SERIAL (modem), 3, responses, responses, set_apn_done, info);
g_free (command);
if (!id) {
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Setting APN failed.");
mm_callback_info_schedule (info);
}
}
static void
get_signal_quality_done (MMSerial *serial, const char *reply, gpointer user_data)
{
@@ -588,7 +589,7 @@ get_signal_quality_done (MMSerial *serial, const char *reply, gpointer user_data
}
static void
get_signal_quality (MMModem *modem,
get_signal_quality (MMGsmModem *modem,
MMModemUIntFn callback,
gpointer user_data)
{
@@ -596,7 +597,7 @@ get_signal_quality (MMModem *modem,
char *terminators = "\r\n";
guint id = 0;
info = mm_callback_info_uint_new (modem, callback, user_data);
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
if (mm_serial_send_command_string (MM_SERIAL (modem), "AT+CSQ"))
id = mm_serial_get_reply (MM_SERIAL (modem), 10, terminators, get_signal_quality_done, info);
@@ -612,14 +613,19 @@ get_signal_quality (MMModem *modem,
static void
modem_init (MMModem *modem_class)
{
/* interface implementation */
modem_class->enable = enable;
modem_class->set_pin = set_pin;
modem_class->do_register = do_register;
modem_class->connect = connect;
modem_class->disconnect = disconnect;
modem_class->scan = scan;
modem_class->get_signal_quality = get_signal_quality;
}
static void
gsm_modem_init (MMGsmModem *gsm_modem_class)
{
gsm_modem_class->set_pin = set_pin;
gsm_modem_class->do_register = do_register;
gsm_modem_class->set_apn = set_apn;
gsm_modem_class->scan = scan;
gsm_modem_class->get_signal_quality = get_signal_quality;
}
static void
@@ -685,6 +691,7 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
mm_generic_gsm_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (object_class, sizeof (MMGenericGsmPrivate));
/* Virtual methods */
@@ -704,6 +711,39 @@ mm_generic_gsm_class_init (MMGenericGsmClass *klass)
g_object_class_override_property (object_class,
MM_MODEM_PROP_TYPE,
MM_MODEM_TYPE);
}
mm_modem_install_dbus_info (G_TYPE_FROM_CLASS (klass));
GType
mm_generic_gsm_get_type (void)
{
static GType generic_gsm_type = 0;
if (G_UNLIKELY (generic_gsm_type == 0)) {
static const GTypeInfo generic_gsm_type_info = {
sizeof (MMGenericGsmClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) mm_generic_gsm_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (MMGenericGsm),
0, /* n_preallocs */
(GInstanceInitFunc) mm_generic_gsm_init,
};
static const GInterfaceInfo modem_iface_info = {
(GInterfaceInitFunc) modem_init
};
static const GInterfaceInfo gsm_modem_iface_info = {
(GInterfaceInitFunc) gsm_modem_init
};
generic_gsm_type = g_type_register_static (MM_TYPE_SERIAL, "MMGenericGsm", &generic_gsm_type_info, 0);
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM, &modem_iface_info);
g_type_add_interface_static (generic_gsm_type, MM_TYPE_GSM_MODEM, &gsm_modem_iface_info);
}
return generic_gsm_type;
}
+2
View File
@@ -26,4 +26,6 @@ GType mm_generic_gsm_get_type (void);
MMModem *mm_generic_gsm_new (const char *serial_device,
const char *driver);
guint32 mm_generic_gsm_get_cid (MMGenericGsm *modem);
#endif /* MM_GENERIC_GSM_H */
+396
View File
@@ -0,0 +1,396 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <string.h>
#include <dbus/dbus-glib.h>
#include "mm-gsm-modem.h"
#include "mm-modem-error.h"
#include "mm-callback-info.h"
static void impl_gsm_modem_set_pin (MMGsmModem *modem, const char *pin, DBusGMethodInvocation *context);
static void impl_gsm_modem_register (MMGsmModem *modem, const char *network_id, DBusGMethodInvocation *context);
static void impl_gsm_modem_scan (MMGsmModem *modem, DBusGMethodInvocation *context);
static void impl_gsm_modem_set_apn (MMGsmModem *modem, const char *apn, DBusGMethodInvocation *context);
static void impl_gsm_modem_get_signal_quality (MMGsmModem *modem, DBusGMethodInvocation *context);
static void impl_gsm_modem_set_band (MMGsmModem *modem, guint32 band, DBusGMethodInvocation *context);
static void impl_gsm_modem_get_band (MMGsmModem *modem, DBusGMethodInvocation *context);
static void impl_gsm_modem_set_network_mode (MMGsmModem *modem, guint32 mode, DBusGMethodInvocation *context);
static void impl_gsm_modem_get_network_mode (MMGsmModem *modem, DBusGMethodInvocation *context);
#include "mm-gsm-modem-glue.h"
enum {
SIGNAL_QUALITY,
NETWORK_MODE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void
async_op_not_supported (MMModem *self,
MMModemFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_new (self, callback, user_data);
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"%s", "Operation not supported");
mm_callback_info_schedule (info);
}
static void
async_call_done (MMModem *modem, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context);
}
static void
uint_op_not_supported (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_uint_new (self, callback, user_data);
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"%s", "Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_call_done (MMModem *modem, guint32 result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
void
mm_gsm_modem_set_pin (MMGsmModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
g_return_if_fail (pin != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->set_pin)
MM_GSM_MODEM_GET_INTERFACE (self)->set_pin (self, pin, callback, user_data);
else
async_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_set_pin (MMGsmModem *modem,
const char *pin,
DBusGMethodInvocation *context)
{
mm_gsm_modem_set_pin (modem, pin, async_call_done, context);
}
void
mm_gsm_modem_register (MMGsmModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->do_register)
MM_GSM_MODEM_GET_INTERFACE (self)->do_register (self, network_id, callback, user_data);
else
async_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_register (MMGsmModem *modem,
const char *network_id,
DBusGMethodInvocation *context)
{
const char *id;
/* DBus does not support NULL strings, so the caller should pass an empty string
for manual registration. */
if (strlen (network_id) < 1)
id = NULL;
else
id = network_id;
mm_gsm_modem_register (modem, id, async_call_done, context);
}
void
mm_gsm_modem_scan (MMGsmModem *self,
MMGsmModemScanFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->scan)
MM_GSM_MODEM_GET_INTERFACE (self)->scan (self, callback, user_data);
else
/* FIXME */ ;
}
static void
impl_scan_done (MMGsmModem *modem, GPtrArray *results, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, results);
}
static void
impl_gsm_modem_scan (MMGsmModem *modem,
DBusGMethodInvocation *context)
{
mm_gsm_modem_scan (modem, impl_scan_done, context);
}
void
mm_gsm_modem_set_apn (MMGsmModem *self,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (apn != NULL);
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->set_apn)
MM_GSM_MODEM_GET_INTERFACE (self)->set_apn (self, apn, callback, user_data);
else
async_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_set_apn (MMGsmModem *modem,
const char *apn,
DBusGMethodInvocation *context)
{
mm_gsm_modem_set_apn (modem, apn, async_call_done, context);
}
void
mm_gsm_modem_get_signal_quality (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->get_signal_quality)
MM_GSM_MODEM_GET_INTERFACE (self)->get_signal_quality (self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_get_signal_quality (MMGsmModem *modem, DBusGMethodInvocation *context)
{
mm_gsm_modem_get_signal_quality (modem, uint_call_done, context);
}
void
mm_gsm_modem_set_band (MMGsmModem *self,
MMGsmModemBand band,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->set_band)
MM_GSM_MODEM_GET_INTERFACE (self)->set_band (self, band, callback, user_data);
else
async_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_set_band (MMGsmModem *modem,
guint32 band,
DBusGMethodInvocation *context)
{
if (band >= MM_GSM_MODEM_BAND_ANY && band <= MM_GSM_MODEM_BAND_LAST)
mm_gsm_modem_set_band (modem, (MMGsmModemBand) band, async_call_done, context);
else {
GError *error;
error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Invalid band");
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
void
mm_gsm_modem_get_band (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->get_band)
MM_GSM_MODEM_GET_INTERFACE (self)->get_band (self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_get_band (MMGsmModem *modem, DBusGMethodInvocation *context)
{
mm_gsm_modem_get_band (modem, uint_call_done, context);
}
void
mm_gsm_modem_set_network_mode (MMGsmModem *self,
MMGsmModemNetworkMode mode,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->set_network_mode)
MM_GSM_MODEM_GET_INTERFACE (self)->set_network_mode (self, mode, callback, user_data);
else
async_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_set_network_mode (MMGsmModem *modem,
guint32 mode,
DBusGMethodInvocation *context)
{
if (mode >= MM_GSM_MODEM_NETWORK_MODE_ANY && mode <= MM_GSM_MODEM_NETWORK_MODE_LAST)
mm_gsm_modem_set_network_mode (modem, (MMGsmModemNetworkMode) mode, async_call_done, context);
else {
GError *error;
error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
"%s", "Invalid network mode");
dbus_g_method_return_error (context, error);
g_error_free (error);
}
}
void
mm_gsm_modem_get_network_mode (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_GSM_MODEM_GET_INTERFACE (self)->get_network_mode)
MM_GSM_MODEM_GET_INTERFACE (self)->get_network_mode (self, callback, user_data);
else
uint_op_not_supported (MM_MODEM (self), callback, user_data);
}
static void
impl_gsm_modem_get_network_mode (MMGsmModem *modem, DBusGMethodInvocation *context)
{
mm_gsm_modem_get_network_mode (modem, uint_call_done, context);
}
void
mm_gsm_modem_signal_quality (MMGsmModem *self,
guint32 quality)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality);
}
void
mm_gsm_modem_network_mode (MMGsmModem *self,
MMGsmModemNetworkMode mode)
{
g_return_if_fail (MM_IS_GSM_MODEM (self));
g_signal_emit (self, signals[NETWORK_MODE], 0, mode);
}
/*****************************************************************************/
static void
mm_gsm_modem_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
return;
/* Signals */
signals[SIGNAL_QUALITY] =
g_signal_new ("signal-quality",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMGsmModem, signal_quality),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
signals[NETWORK_MODE] =
g_signal_new ("network-mode",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMGsmModem, network_mode),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
initialized = TRUE;
}
GType
mm_gsm_modem_get_type (void)
{
static GType modem_type = 0;
if (!G_UNLIKELY (modem_type)) {
const GTypeInfo modem_info = {
sizeof (MMGsmModem), /* class_size */
mm_gsm_modem_init, /* base_init */
NULL, /* base_finalize */
NULL,
NULL, /* class_finalize */
NULL, /* class_data */
0,
0, /* n_preallocs */
NULL
};
modem_type = g_type_register_static (G_TYPE_INTERFACE,
"MMGsmModem",
&modem_info, 0);
g_type_interface_add_prerequisite (modem_type, MM_TYPE_MODEM);
dbus_g_object_type_install_info (modem_type, &dbus_glib_mm_gsm_modem_object_info);
}
return modem_type;
}
+154
View File
@@ -0,0 +1,154 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef MM_GSM_MODEM_H
#define MM_GSM_MODEM_H
#include <mm-modem.h>
#define MM_TYPE_GSM_MODEM (mm_gsm_modem_get_type ())
#define MM_GSM_MODEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GSM_MODEM, MMGsmModem))
#define MM_IS_GSM_MODEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_GSM_MODEM))
#define MM_GSM_MODEM_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_GSM_MODEM, MMGsmModem))
typedef enum {
MM_GSM_MODEM_NETWORK_MODE_ANY = 0,
MM_GSM_MODEM_NETWORK_MODE_GPRS = 1,
MM_GSM_MODEM_NETWORK_MODE_EDGE = 2,
MM_GSM_MODEM_NETWORK_MODE_3G = 3,
MM_GSM_MODEM_NETWORK_MODE_HSDPA = 4,
MM_GSM_MODEM_NETWORK_MODE_PREFER_2G = 5,
MM_GSM_MODEM_NETWORK_MODE_PREFER_3G = 6,
MM_GSM_MODEM_NETWORK_MODE_LAST = MM_GSM_MODEM_NETWORK_MODE_PREFER_3G
} MMGsmModemNetworkMode;
typedef enum {
MM_GSM_MODEM_BAND_ANY = 0,
MM_GSM_MODEM_BAND_EGSM = 1, /* 900 MHz */
MM_GSM_MODEM_BAND_DCS = 2, /* 1800 MHz */
MM_GSM_MODEM_BAND_PCS = 3, /* 1900 MHz */
MM_GSM_MODEM_BAND_G850 = 4, /* 850 MHz */
MM_GSM_MODEM_BAND_U2100 = 5, /* WCDMA 2100 MHz (Class I) */
MM_GSM_MODEM_BAND_U1700 = 6, /* WCDMA 3GPP UMTS1800 MHz (Class III) */
MM_GSM_MODEM_BAND_17IV = 7, /* WCDMA 3GPP AWS 1700/2100 MHz (Class IV) */
MM_GSM_MODEM_BAND_U800 = 8, /* WCDMA 3GPP UMTS800 MHz (Class VI) */
MM_GSM_MODEM_BAND_U850 = 9, /* WCDMA 3GPP UMTS850 MHz (Class V) */
MM_GSM_MODEM_BAND_U900 = 10, /* WCDMA 3GPP UMTS900 MHz (Class VIII) */
MM_GSM_MODEM_BAND_U17IX = 11, /* WCDMA 3GPP UMTS MHz (Class IX) */
MM_GSM_MODEM_BAND_LAST = MM_GSM_MODEM_BAND_U17IX
} MMGsmModemBand;
typedef struct _MMGsmModem MMGsmModem;
typedef void (*MMGsmModemScanFn) (MMGsmModem *modem,
GPtrArray *results,
GError *error,
gpointer user_data);
struct _MMGsmModem {
GTypeInterface g_iface;
/* Methods */
void (*set_pin) (MMGsmModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
/* 'register' is a reserved word */
void (*do_register) (MMGsmModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void (*scan) (MMGsmModem *self,
MMGsmModemScanFn callback,
gpointer user_data);
void (*get_signal_quality) (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_apn) (MMGsmModem *self,
const char *apn,
MMModemFn callback,
gpointer user_data);
void (*set_band) (MMGsmModem *self,
MMGsmModemBand band,
MMModemFn callback,
gpointer user_data);
void (*get_band) (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_network_mode) (MMGsmModem *self,
MMGsmModemNetworkMode mode,
MMModemFn callback,
gpointer user_data);
void (*get_network_mode) (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Signals */
void (*signal_quality) (MMGsmModem *self,
guint32 quality);
void (*network_mode) (MMGsmModem *self,
MMGsmModemNetworkMode mode);
};
GType mm_gsm_modem_get_type (void);
void mm_gsm_modem_set_pin (MMGsmModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
void mm_gsm_modem_register (MMGsmModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void mm_gsm_modem_scan (MMGsmModem *self,
MMGsmModemScanFn callback,
gpointer user_data);
void mm_gsm_modem_set_apn (MMGsmModem *self,
const char *apn,
MMModemFn callback,
gpointer user_data);
void mm_gsm_modem_get_signal_quality (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_gsm_modem_set_band (MMGsmModem *self,
MMGsmModemBand band,
MMModemFn callback,
gpointer user_data);
void mm_gsm_modem_get_band (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_gsm_modem_set_network_mode (MMGsmModem *self,
MMGsmModemNetworkMode mode,
MMModemFn callback,
gpointer user_data);
void mm_gsm_modem_get_network_mode (MMGsmModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Protected */
void mm_gsm_modem_signal_quality (MMGsmModem *self,
guint32 quality);
void mm_gsm_modem_network_mode (MMGsmModem *self,
MMGsmModemNetworkMode mode);
#endif /* MM_GSM_MODEM_H */
+17 -16
View File
@@ -222,28 +222,29 @@ create_initial_modems_from_plugins (MMManager *manager)
for (iter = priv->plugins; iter; iter = iter->next) {
MMPlugin *plugin = MM_PLUGIN (iter->data);
GSList *udis;
GSList *udi_iter;
char **udis;
int i;
udis = mm_plugin_list_supported_udis (plugin, priv->hal_ctx);
for (udi_iter = udis; udi_iter; udi_iter = udi_iter->next) {
char *udi = (char *) udi_iter->data;
MMModem *modem;
if (udis) {
for (i = 0; udis[i]; i++) {
char *udi = udis[i];
MMModem *modem;
if (modem_exists (manager, udi)) {
g_warning ("Modem for UDI %s already exists, ignoring", udi);
continue;
if (modem_exists (manager, udi)) {
g_warning ("Modem for UDI %s already exists, ignoring", udi);
continue;
}
modem = mm_plugin_create_modem (plugin, priv->hal_ctx, udi);
if (modem)
add_modem (manager, udi, modem);
else
g_warning ("Plugin failed to create modem for UDI %s", udi);
}
modem = mm_plugin_create_modem (plugin, priv->hal_ctx, udi);
if (modem)
add_modem (manager, udi, modem);
else
g_warning ("Plugin failed to create modem for UDI %s", udi);
g_strfreev (udis);
}
g_slist_foreach (udis, (GFunc) g_free, NULL);
g_slist_free (udis);
}
}
+5 -291
View File
@@ -7,28 +7,11 @@
#include "mm-callback-info.h"
static void impl_modem_enable (MMModem *modem, gboolean enable, DBusGMethodInvocation *context);
static void impl_modem_set_pin (MMModem *modem, const char *pin, DBusGMethodInvocation *context);
static void impl_modem_register (MMModem *modem, const char *network_id, DBusGMethodInvocation *context);
static void impl_modem_connect (MMModem *modem, const char *number, const char *apn, DBusGMethodInvocation *context);
static void impl_modem_connect (MMModem *modem, const char *number, DBusGMethodInvocation *context);
static void impl_modem_disconnect (MMModem *modem, DBusGMethodInvocation *context);
static void impl_modem_scan (MMModem *modem, DBusGMethodInvocation *context);
static void impl_modem_get_signal_quality (MMModem *modem, DBusGMethodInvocation *context);
static void impl_modem_set_band (MMModem *modem, guint32 band, DBusGMethodInvocation *context);
static void impl_modem_get_band (MMModem *modem, DBusGMethodInvocation *context);
static void impl_modem_set_network_mode (MMModem *modem, guint32 mode, DBusGMethodInvocation *context);
static void impl_modem_get_network_mode (MMModem *modem, DBusGMethodInvocation *context);
#include "mm-modem-glue.h"
enum {
SIGNAL_QUALITY,
NETWORK_MODE,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void
async_op_not_supported (MMModem *self,
MMModemFn callback,
@@ -53,30 +36,6 @@ async_call_done (MMModem *modem, GError *error, gpointer user_data)
dbus_g_method_return (context);
}
static void
uint_op_not_supported (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
MMCallbackInfo *info;
info = mm_callback_info_uint_new (self, callback, user_data);
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
"%s", "Operation not supported");
mm_callback_info_schedule (info);
}
static void
uint_call_done (MMModem *modem, guint32 result, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, result);
}
void
mm_modem_enable (MMModem *self,
gboolean enable,
@@ -100,66 +59,9 @@ impl_modem_enable (MMModem *modem,
mm_modem_enable (modem, enable, async_call_done, context);
}
void
mm_modem_set_pin (MMModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
g_return_if_fail (pin != NULL);
if (MM_MODEM_GET_INTERFACE (self)->set_pin)
MM_MODEM_GET_INTERFACE (self)->set_pin (self, pin, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
static void
impl_modem_set_pin (MMModem *modem,
const char *pin,
DBusGMethodInvocation *context)
{
mm_modem_set_pin (modem, pin, async_call_done, context);
}
void
mm_modem_register (MMModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->do_register)
MM_MODEM_GET_INTERFACE (self)->do_register (self, network_id, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
static void
impl_modem_register (MMModem *modem,
const char *network_id,
DBusGMethodInvocation *context)
{
const char *id;
/* DBus does not support NULL strings, so the caller should pass an empty string
for manual registration. */
if (strlen (network_id) < 1)
id = NULL;
else
id = network_id;
mm_modem_register (modem, id, async_call_done, context);
}
void
mm_modem_connect (MMModem *self,
const char *number,
const char *apn,
MMModemFn callback,
gpointer user_data)
{
@@ -168,7 +70,7 @@ mm_modem_connect (MMModem *self,
g_return_if_fail (number != NULL);
if (MM_MODEM_GET_INTERFACE (self)->connect)
MM_MODEM_GET_INTERFACE (self)->connect (self, number, apn, callback, user_data);
MM_MODEM_GET_INTERFACE (self)->connect (self, number, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
@@ -176,19 +78,9 @@ mm_modem_connect (MMModem *self,
static void
impl_modem_connect (MMModem *modem,
const char *number,
const char *apn,
DBusGMethodInvocation *context)
{
const char *real_apn;
/* DBus does not support NULL strings, so the caller should pass an empty string
for no APN. */
if (strlen (apn) < 1)
real_apn = NULL;
else
real_apn = apn;
mm_modem_connect (modem, number, real_apn, async_call_done, context);
mm_modem_connect (modem, number, async_call_done, context);
}
void
@@ -212,171 +104,12 @@ impl_modem_disconnect (MMModem *modem,
mm_modem_disconnect (modem, async_call_done, context);
}
void
mm_modem_scan (MMModem *self,
MMModemScanFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->scan)
MM_MODEM_GET_INTERFACE (self)->scan (self, callback, user_data);
else
/* FIXME */ ;
}
static void
impl_scan_done (MMModem *modem, GPtrArray *results, GError *error, gpointer user_data)
{
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
if (error)
dbus_g_method_return_error (context, error);
else
dbus_g_method_return (context, results);
}
static void
impl_modem_scan (MMModem *modem,
DBusGMethodInvocation *context)
{
mm_modem_scan (modem, impl_scan_done, context);
}
void
mm_modem_get_signal_quality (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->get_signal_quality)
MM_MODEM_GET_INTERFACE (self)->get_signal_quality (self, callback, user_data);
else
uint_op_not_supported (self, callback, user_data);
}
static void
impl_modem_get_signal_quality (MMModem *modem, DBusGMethodInvocation *context)
{
mm_modem_get_signal_quality (modem, uint_call_done, context);
}
void
mm_modem_set_band (MMModem *self,
MMModemBand band,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->set_band)
MM_MODEM_GET_INTERFACE (self)->set_band (self, band, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
static void
impl_modem_set_band (MMModem *modem, guint32 band, DBusGMethodInvocation *context)
{
mm_modem_set_band (modem, band, async_call_done, context);
}
void
mm_modem_get_band (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->get_band)
MM_MODEM_GET_INTERFACE (self)->get_band (self, callback, user_data);
else
uint_op_not_supported (self, callback, user_data);
}
static void
impl_modem_get_band (MMModem *modem, DBusGMethodInvocation *context)
{
mm_modem_get_band (modem, uint_call_done, context);
}
void
mm_modem_set_network_mode (MMModem *self,
MMModemNetworkMode mode,
MMModemFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->set_network_mode)
MM_MODEM_GET_INTERFACE (self)->set_network_mode (self, mode, callback, user_data);
else
async_op_not_supported (self, callback, user_data);
}
static void
impl_modem_set_network_mode (MMModem *modem, guint32 mode, DBusGMethodInvocation *context)
{
mm_modem_set_network_mode (modem, mode, async_call_done, context);
}
void
mm_modem_get_network_mode (MMModem *self,
MMModemUIntFn callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM (self));
g_return_if_fail (callback != NULL);
if (MM_MODEM_GET_INTERFACE (self)->get_network_mode)
MM_MODEM_GET_INTERFACE (self)->get_network_mode (self, callback, user_data);
else
uint_op_not_supported (self, callback, user_data);
}
static void
impl_modem_get_network_mode (MMModem *modem, DBusGMethodInvocation *context)
{
mm_modem_get_network_mode (modem, uint_call_done, context);
}
void
mm_modem_install_dbus_info (GType type)
{
dbus_g_object_type_install_info (type, &dbus_glib_mm_modem_object_info);
}
void
mm_modem_signal_quality (MMModem *self,
guint32 quality)
{
g_return_if_fail (MM_IS_MODEM (self));
g_signal_emit (self, signals[SIGNAL_QUALITY], 0, quality);
}
void
mm_modem_network_mode (MMModem *self,
MMModemNetworkMode mode)
{
g_return_if_fail (MM_IS_MODEM (self));
g_signal_emit (self, signals[NETWORK_MODE], 0, mode);
}
/*****************************************************************************/
static void
mm_modem_init (gpointer g_iface)
{
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
static gboolean initialized = FALSE;
if (initialized)
@@ -407,27 +140,6 @@ mm_modem_init (gpointer g_iface)
0, G_MAXUINT32, 0,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/* Signals */
signals[SIGNAL_QUALITY] =
g_signal_new ("signal-quality",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModem, signal_quality),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
signals[NETWORK_MODE] =
g_signal_new ("network-mode",
iface_type,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMModem, network_mode),
NULL, NULL,
g_cclosure_marshal_VOID__UINT,
G_TYPE_NONE, 1,
G_TYPE_UINT);
initialized = TRUE;
}
@@ -454,6 +166,8 @@ mm_modem_get_type (void)
&modem_info, 0);
g_type_interface_add_prerequisite (modem_type, G_TYPE_OBJECT);
dbus_g_object_type_install_info (modem_type, &dbus_glib_mm_modem_object_info);
}
return modem_type;
-122
View File
@@ -25,31 +25,6 @@ typedef enum {
MM_MODEM_PROP_TYPE
} MMModemProp;
typedef enum {
MM_MODEM_NETWORK_MODE_ANY = 0,
MM_MODEM_NETWORK_MODE_GPRS = 1,
MM_MODEM_NETWORK_MODE_EDGE = 2,
MM_MODEM_NETWORK_MODE_3G = 3,
MM_MODEM_NETWORK_MODE_HSDPA = 4,
MM_MODEM_NETWORK_MODE_PREFER_2G = 5,
MM_MODEM_NETWORK_MODE_PREFER_3G = 6
} MMModemNetworkMode;
typedef enum {
MM_MODEM_BAND_ANY = 0,
MM_MODEM_BAND_EGSM = 1, /* 900 MHz */
MM_MODEM_BAND_DCS = 2, /* 1800 MHz */
MM_MODEM_BAND_PCS = 3, /* 1900 MHz */
MM_MODEM_BAND_G850 = 4, /* 850 MHz */
MM_MODEM_BAND_U2100 = 5, /* WCDMA 2100 MHz (Class I) */
MM_MODEM_BAND_U1700 = 6, /* WCDMA 3GPP UMTS1800 MHz (Class III) */
MM_MODEM_BAND_17IV = 7, /* WCDMA 3GPP AWS 1700/2100 MHz (Class IV) */
MM_MODEM_BAND_U800 = 8, /* WCDMA 3GPP UMTS800 MHz (Class VI) */
MM_MODEM_BAND_U850 = 9, /* WCDMA 3GPP UMTS850 MHz (Class V) */
MM_MODEM_BAND_U900 = 10, /* WCDMA 3GPP UMTS900 MHz (Class VIII) */
MM_MODEM_BAND_U17IX = 11 /* WCDMA 3GPP UMTS MHz (Class IX) */
} MMModemBand;
typedef struct _MMModem MMModem;
typedef void (*MMModemFn) (MMModem *modem,
@@ -61,11 +36,6 @@ typedef void (*MMModemUIntFn) (MMModem *modem,
GError *error,
gpointer user_data);
typedef void (*MMModemScanFn) (MMModem *modem,
GPtrArray *results,
GError *error,
gpointer user_data);
struct _MMModem {
GTypeInterface g_iface;
@@ -75,59 +45,14 @@ struct _MMModem {
MMModemFn callback,
gpointer user_data);
void (*set_pin) (MMModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
/* 'register' is a reserved word */
void (*do_register) (MMModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void (*connect) (MMModem *self,
const char *number,
const char *apn,
MMModemFn callback,
gpointer user_data);
void (*disconnect) (MMModem *self,
MMModemFn callback,
gpointer user_data);
void (*scan) (MMModem *self,
MMModemScanFn callback,
gpointer user_data);
void (*get_signal_quality) (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_band) (MMModem *self,
MMModemBand band,
MMModemFn callback,
gpointer user_data);
void (*get_band) (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void (*set_network_mode) (MMModem *self,
MMModemNetworkMode mode,
MMModemFn callback,
gpointer user_data);
void (*get_network_mode) (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Signals */
void (*signal_quality) (MMModem *self,
guint32 quality);
void (*network_mode) (MMModem *self,
MMModemNetworkMode mode);
};
GType mm_modem_get_type (void);
@@ -137,19 +62,8 @@ void mm_modem_enable (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_set_pin (MMModem *self,
const char *pin,
MMModemFn callback,
gpointer user_data);
void mm_modem_register (MMModem *self,
const char *network_id,
MMModemFn callback,
gpointer user_data);
void mm_modem_connect (MMModem *self,
const char *number,
const char *apn,
MMModemFn callback,
gpointer user_data);
@@ -157,40 +71,4 @@ void mm_modem_disconnect (MMModem *self,
MMModemFn callback,
gpointer user_data);
void mm_modem_scan (MMModem *self,
MMModemScanFn callback,
gpointer user_data);
void mm_modem_get_signal_quality (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_set_band (MMModem *self,
MMModemBand band,
MMModemFn callback,
gpointer user_data);
void mm_modem_get_band (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
void mm_modem_set_network_mode (MMModem *self,
MMModemNetworkMode mode,
MMModemFn callback,
gpointer user_data);
void mm_modem_get_network_mode (MMModem *self,
MMModemUIntFn callback,
gpointer user_data);
/* Protected */
void mm_modem_install_dbus_info (GType type);
void mm_modem_signal_quality (MMModem *self,
guint32 quality);
void mm_modem_network_mode (MMModem *self,
MMModemNetworkMode mode);
#endif /* MM_MODEM_H */