udev: modem port refactor; convert 'hso' to udev
Create a base MMPort class to handle both tty and net ports generically, and move plugins over to that. Also port the 'hso' plugin to udev.
This commit is contained in:
+8
-4
@@ -84,20 +84,24 @@ libmm_plugin_huawei_la_LDFLAGS = \
|
||||
# HSO
|
||||
|
||||
libmm_plugin_hso_la_SOURCES = \
|
||||
mm-plugin-hso.c \
|
||||
mm-plugin-hso.h \
|
||||
mm-modem-gsm-hso-glue.h \
|
||||
mm-modem-hso.c \
|
||||
mm-modem-hso.h \
|
||||
mm-plugin-hso.c \
|
||||
mm-plugin-hso.h
|
||||
mm-modem-hso.h
|
||||
|
||||
mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-hso.xml
|
||||
dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $<
|
||||
|
||||
libmm_plugin_hso_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
libmm_plugin_hso_la_LDFLAGS = -module -avoid-version
|
||||
libmm_plugin_hso_la_LDFLAGS = \
|
||||
$(GUDEV_LDFLAGS) \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
# MBM
|
||||
|
||||
|
||||
@@ -71,18 +71,11 @@ get_imsi (MMModemGsmCard *modem,
|
||||
{
|
||||
MMSerialPort *primary;
|
||||
MMCallbackInfo *info;
|
||||
GError *error = NULL;
|
||||
|
||||
info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
if (primary)
|
||||
mm_serial_port_queue_command_cached (primary, "+CIMI", 3, get_string_done, info);
|
||||
else {
|
||||
g_set_error (&error, MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||
"Operation not supported; primary port unusable");
|
||||
get_string_done (primary, NULL, error, user_data);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command_cached (primary, "+CIMI", 3, get_string_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+142
-70
@@ -1,4 +1,18 @@
|
||||
/* -*- 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) 2008 - 2009 Novell, Inc.
|
||||
* Copyright (C) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -7,9 +21,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "mm-modem-hso.h"
|
||||
#include "mm-modem-simple.h"
|
||||
#include "mm-serial.h"
|
||||
#include "mm-serial-parsers.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
@@ -34,26 +51,24 @@ typedef struct {
|
||||
#define OWANDATA_TAG "_OWANDATA: "
|
||||
|
||||
MMModem *
|
||||
mm_modem_hso_new (const char *serial_device,
|
||||
const char *network_device,
|
||||
const char *driver)
|
||||
mm_modem_hso_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin)
|
||||
{
|
||||
g_return_val_if_fail (serial_device != NULL, NULL);
|
||||
g_return_val_if_fail (network_device != NULL, NULL);
|
||||
g_return_val_if_fail (device != NULL, NULL);
|
||||
g_return_val_if_fail (driver != NULL, NULL);
|
||||
g_return_val_if_fail (plugin != NULL, NULL);
|
||||
|
||||
return MM_MODEM (g_object_new (MM_TYPE_MODEM_HSO,
|
||||
MM_SERIAL_DEVICE, serial_device,
|
||||
MM_SERIAL_SEND_DELAY, (guint64) 10000,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_DEVICE, network_device,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC,
|
||||
MM_MODEM_TYPE, MM_MODEM_TYPE_GSM,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
hso_enable_done (MMSerial *serial,
|
||||
hso_enable_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -86,11 +101,14 @@ hso_enable (MMModemHso *self,
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
char *command;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
command = g_strdup_printf ("AT_OWANCALL=%d,%d,1", hso_get_cid (self), enabled ? 1 : 0);
|
||||
mm_serial_queue_command (MM_SERIAL (self), command, 3, hso_enable_done, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, command, 3, hso_enable_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
@@ -161,19 +179,20 @@ hso_disabled (MMModem *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
auth_done (MMSerial *serial,
|
||||
auth_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemHso *self = MM_MODEM_HSO (info->modem);
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
mm_callback_info_schedule (info);
|
||||
} else
|
||||
/* success, kill any existing connections first */
|
||||
hso_enable (MM_MODEM_HSO (serial), FALSE, hso_disabled, info);
|
||||
hso_enable (self, FALSE, hso_disabled, info);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -184,24 +203,32 @@ mm_hso_modem_authenticate (MMModemHso *self,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
g_return_if_fail (MM_IS_MODEM_HSO (self));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
if (username || password) {
|
||||
char *command;
|
||||
|
||||
// FIXME: if QCPDPP fails, try OPDPP. AT&T Quicksilver uses a different
|
||||
// chipset (ie, not Qualcomm) and the auth command is OPDPP instead of
|
||||
// the Qualcomm-specific QCPDPP.
|
||||
|
||||
command = g_strdup_printf ("AT$QCPDPP=%d,1,\"%s\",\"%s\"",
|
||||
hso_get_cid (self),
|
||||
password ? password : "",
|
||||
username ? username : "");
|
||||
|
||||
mm_serial_queue_command (MM_SERIAL (self), command, 3, auth_done, info);
|
||||
mm_serial_port_queue_command (primary, command, 3, auth_done, info);
|
||||
g_free (command);
|
||||
} else
|
||||
auth_done (MM_SERIAL (self), NULL, NULL, info);
|
||||
auth_done (primary, NULL, NULL, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -234,7 +261,7 @@ parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||
}
|
||||
|
||||
static void
|
||||
modem_enable_done (MMSerial *serial,
|
||||
modem_enable_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -242,8 +269,8 @@ modem_enable_done (MMSerial *serial,
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModem *parent_modem_iface;
|
||||
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (serial));
|
||||
parent_modem_iface->enable (MM_MODEM (serial),
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
|
||||
parent_modem_iface->enable (info->modem,
|
||||
GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")),
|
||||
parent_enable_done, info);
|
||||
}
|
||||
@@ -255,14 +282,18 @@ enable (MMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_callback_info_set_data (info, "enable", GINT_TO_POINTER (enable), NULL);
|
||||
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
if (do_enable)
|
||||
modem_enable_done (MM_SERIAL (modem), NULL, NULL, info);
|
||||
modem_enable_done (primary, NULL, NULL, info);
|
||||
else
|
||||
mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, modem_enable_done, info);
|
||||
mm_serial_port_queue_command (primary, "AT_OWANCALL=1,0,0", 3, modem_enable_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -296,7 +327,7 @@ ip4_config_invoke (MMCallbackInfo *info)
|
||||
}
|
||||
|
||||
static void
|
||||
get_ip4_config_done (MMSerial *serial,
|
||||
get_ip4_config_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -317,7 +348,7 @@ get_ip4_config_done (MMSerial *serial,
|
||||
goto out;
|
||||
}
|
||||
|
||||
cid = hso_get_cid (MM_MODEM_HSO (serial));
|
||||
cid = hso_get_cid (MM_MODEM_HSO (info->modem));
|
||||
dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2);
|
||||
items = g_strsplit (response->str + strlen (OWANDATA_TAG), ", ", 0);
|
||||
|
||||
@@ -359,10 +390,13 @@ get_ip4_config (MMModem *modem,
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
char *command;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new_full (modem, ip4_config_invoke, G_CALLBACK (callback), user_data);
|
||||
command = g_strdup_printf ("AT_OWANDATA=%d", hso_get_cid (MM_MODEM_HSO (modem)));
|
||||
mm_serial_queue_command (MM_SERIAL (modem), command, 3, get_ip4_config_done, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, command, 3, get_ip4_config_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
@@ -372,9 +406,12 @@ disconnect (MMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, NULL, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT_OWANCALL=1,0,0", 3, NULL, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -408,23 +445,25 @@ impl_hso_authenticate (MMModemHso *self,
|
||||
}
|
||||
|
||||
static void
|
||||
connection_enabled (MMSerial *serial,
|
||||
connection_enabled (MMSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (user_data);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
char *str;
|
||||
|
||||
str = g_match_info_fetch (info, 2);
|
||||
if (str[0] == '1')
|
||||
connect_pending_done (MM_MODEM_HSO (serial));
|
||||
connect_pending_done (self);
|
||||
else if (str[0] == '3') {
|
||||
MMCallbackInfo *cb_info = MM_MODEM_HSO_GET_PRIVATE (serial)->connect_pending_data;
|
||||
MMCallbackInfo *cb_info = priv->connect_pending_data;
|
||||
|
||||
if (cb_info)
|
||||
cb_info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Call setup failed");
|
||||
|
||||
connect_pending_done (MM_MODEM_HSO (serial));
|
||||
connect_pending_done (self);
|
||||
} else if (str[0] == '0')
|
||||
/* FIXME: disconnected. do something when we have modem status signals */
|
||||
;
|
||||
@@ -521,16 +560,82 @@ simple_connect (MMModemSimple *simple,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GError **error)
|
||||
{
|
||||
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
const char *sys[] = { "tty", "net", NULL };
|
||||
GUdevClient *client;
|
||||
GUdevDevice *device = NULL;
|
||||
MMPort *port = NULL;
|
||||
const char *sysfs_path;
|
||||
|
||||
client = g_udev_client_new (sys);
|
||||
if (!client) {
|
||||
g_set_error (error, 0, 0, "Could not get udev client.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Could not get udev device.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (device);
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get udev device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
char *hsotype_path;
|
||||
char *contents = NULL;
|
||||
|
||||
hsotype_path = g_build_filename (sysfs_path, "hsotype", NULL);
|
||||
if (g_file_get_contents (hsotype_path, &contents, NULL, NULL)) {
|
||||
if (g_str_has_prefix (contents, "Control"))
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
g_free (contents);
|
||||
}
|
||||
g_free (hsotype_path);
|
||||
}
|
||||
|
||||
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
|
||||
if (!port)
|
||||
goto out;
|
||||
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_SEND_DELAY, (guint64) 10000, NULL);
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
GRegex *regex;
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (gsm, TRUE);
|
||||
|
||||
regex = g_regex_new ("_OWANCALL: (\\d), (\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, connection_enabled, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (device)
|
||||
g_object_unref (device);
|
||||
g_object_unref (client);
|
||||
return !!port;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_modem_hso_init (MMModemHso *self)
|
||||
{
|
||||
GRegex *regex;
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (self), TRUE);
|
||||
|
||||
regex = g_regex_new ("_OWANCALL: (\\d), (\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, connection_enabled, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -546,39 +651,7 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->connect = do_connect;
|
||||
modem_class->get_ip4_config = get_ip4_config;
|
||||
modem_class->disconnect = disconnect;
|
||||
}
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
char *modem_device;
|
||||
char *serial_device;
|
||||
|
||||
object = G_OBJECT_CLASS (mm_modem_hso_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
/* Make sure both serial device and data device are provided */
|
||||
g_object_get (object,
|
||||
MM_MODEM_DEVICE, &modem_device,
|
||||
MM_SERIAL_DEVICE, &serial_device,
|
||||
NULL);
|
||||
|
||||
if (!modem_device || !serial_device || !strcmp (modem_device, serial_device)) {
|
||||
g_warning ("No network device provided");
|
||||
g_object_unref (object);
|
||||
object = NULL;
|
||||
}
|
||||
|
||||
g_free (modem_device);
|
||||
g_free (serial_device);
|
||||
|
||||
return object;
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -599,7 +672,6 @@ mm_modem_hso_class_init (MMModemHsoClass *klass)
|
||||
g_type_class_add_private (object_class, sizeof (MMModemHsoPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->finalize = finalize;
|
||||
}
|
||||
|
||||
|
||||
+23
-9
@@ -1,16 +1,30 @@
|
||||
/* -*- 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) 2008 - 2009 Novell, Inc.
|
||||
* Copyright (C) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_HSO_H
|
||||
#define MM_MODEM_HSO_H
|
||||
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_MODEM_HSO (mm_modem_hso_get_type ())
|
||||
#define MM_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HSO, MMModemHso))
|
||||
#define MM_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_IS_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HSO))
|
||||
#define MM_IS_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HSO))
|
||||
#define MM_MODEM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_TYPE_MODEM_HSO (mm_modem_hso_get_type ())
|
||||
#define MM_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HSO, MMModemHso))
|
||||
#define MM_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_IS_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HSO))
|
||||
#define MM_IS_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HSO))
|
||||
#define MM_MODEM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsm parent;
|
||||
@@ -22,9 +36,9 @@ typedef struct {
|
||||
|
||||
GType mm_modem_hso_get_type (void);
|
||||
|
||||
MMModem *mm_modem_hso_new (const char *serial_device,
|
||||
const char *network_device,
|
||||
const char *driver);
|
||||
MMModem *mm_modem_hso_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin);
|
||||
|
||||
void mm_hso_modem_authenticate (MMModemHso *self,
|
||||
const char *username,
|
||||
|
||||
+29
-28
@@ -192,7 +192,7 @@ set_network_mode (MMModemGsmNetwork *modem,
|
||||
case MM_MODEM_GSM_NETWORK_MODE_3G_ONLY:
|
||||
/* Allowed values */
|
||||
mm_callback_info_set_data (info, "mode", GUINT_TO_POINTER (mode), NULL);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_network_mode_get_done, info);
|
||||
return;
|
||||
@@ -244,7 +244,7 @@ get_network_mode (MMModemGsmNetwork *modem,
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_network_mode_done, info);
|
||||
}
|
||||
@@ -329,7 +329,7 @@ set_band (MMModemGsmNetwork *modem,
|
||||
case MM_MODEM_GSM_NETWORK_BAND_U2100:
|
||||
case MM_MODEM_GSM_NETWORK_BAND_PCS:
|
||||
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (band), NULL);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_band_get_done, info);
|
||||
return;
|
||||
@@ -381,7 +381,7 @@ get_band (MMModemGsmNetwork *modem,
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_band_done, info);
|
||||
}
|
||||
@@ -503,11 +503,11 @@ grab_port (MMModem *modem,
|
||||
GError **error)
|
||||
{
|
||||
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
|
||||
MMSerialPortType ptype = MM_SERIAL_PORT_TYPE_IGNORED;
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
const char *sys[] = { "tty", NULL };
|
||||
GUdevClient *client;
|
||||
GUdevDevice *device = NULL;
|
||||
MMSerialPort *port = NULL;
|
||||
MMPort *port = NULL;
|
||||
int usbif;
|
||||
|
||||
client = g_udev_client_new (sys);
|
||||
@@ -529,41 +529,42 @@ grab_port (MMModem *modem,
|
||||
}
|
||||
|
||||
if (usbif == 0) {
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_SERIAL_PORT_TYPE_PRIMARY))
|
||||
ptype = MM_SERIAL_PORT_TYPE_PRIMARY;
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_PRIMARY))
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
} else if (usbif == 1) {
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_SERIAL_PORT_TYPE_SECONDARY))
|
||||
ptype = MM_SERIAL_PORT_TYPE_SECONDARY;
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_SECONDARY))
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
|
||||
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
|
||||
if (!port)
|
||||
goto out;
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) {
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
} else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY) {
|
||||
GRegex *regex;
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
if (ptype == MM_PORT_TYPE_SECONDARY) {
|
||||
GRegex *regex;
|
||||
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (modem), TRUE);
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (modem), TRUE);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^RSSI:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_signal_quality_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^RSSI:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_signal_quality_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^MODE:(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_mode_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^MODE:(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_mode_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^DSFLOWRPT:(.+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_status_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^DSFLOWRPT:(.+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_status_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^BOOT:.+\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, NULL, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^BOOT:.+\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
@@ -224,7 +224,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
+233
-196
@@ -1,18 +1,43 @@
|
||||
/* -*- 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) 2008 - 2009 Novell, Inc.
|
||||
* Copyright (C) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "mm-plugin-hso.h"
|
||||
#include "mm-modem-hso.h"
|
||||
|
||||
static void plugin_init (MMPlugin *plugin_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginHso, mm_plugin_hso, G_TYPE_OBJECT,
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN_BASE,
|
||||
0, G_IMPLEMENT_INTERFACE (MM_TYPE_PLUGIN, plugin_init))
|
||||
|
||||
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
|
||||
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
|
||||
|
||||
#define MM_PLUGIN_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_HSO, MMPluginHsoPrivate))
|
||||
|
||||
typedef struct {
|
||||
GUdevClient *client;
|
||||
} MMPluginHsoPrivate;
|
||||
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *
|
||||
mm_plugin_create (void)
|
||||
{
|
||||
@@ -21,204 +46,200 @@ mm_plugin_create (void)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static char *
|
||||
get_driver_name (GUdevDevice *device)
|
||||
{
|
||||
GUdevDevice *parent = NULL;
|
||||
const char *driver;
|
||||
char *ret;
|
||||
|
||||
driver = g_udev_device_get_driver (device);
|
||||
if (!driver) {
|
||||
parent = g_udev_device_get_parent (device);
|
||||
if (parent)
|
||||
driver = g_udev_device_get_driver (parent);
|
||||
}
|
||||
|
||||
if (driver)
|
||||
ret = g_strdup (driver);
|
||||
if (parent)
|
||||
g_object_unref (parent);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GUdevDevice *
|
||||
find_physical_device (GUdevDevice *child)
|
||||
{
|
||||
GUdevDevice *iter, *old = NULL;
|
||||
const char *type;
|
||||
|
||||
g_return_val_if_fail (child != NULL, NULL);
|
||||
|
||||
/* Walk the parents to find the first 'usb_device' for this device. */
|
||||
iter = g_object_ref (child);
|
||||
while (iter) {
|
||||
type = g_udev_device_get_devtype (iter);
|
||||
if (type && !strcmp (type, "usb_device"))
|
||||
return iter;
|
||||
|
||||
old = iter;
|
||||
iter = g_udev_device_get_parent (old);
|
||||
g_object_unref (old);
|
||||
}
|
||||
g_object_unref (child);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GUdevDevice *
|
||||
get_device (GUdevClient *client,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GUdevDevice **physdev,
|
||||
char **driver,
|
||||
GError **error)
|
||||
{
|
||||
GUdevDevice *device = NULL;
|
||||
|
||||
if (strcmp (subsys, "tty") && strcmp (subsys, "net")) {
|
||||
g_set_error (error, 0, 0, "Unsupported subsystem.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Coud not get port's udev device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*driver = get_driver_name (device);
|
||||
if (!*driver || strcmp (*driver, "hso")) {
|
||||
g_set_error (error, 0, 0, "Unsupported driver (not 'hso').");
|
||||
g_object_unref (device);
|
||||
device = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*physdev = find_physical_device (device);
|
||||
if (!*physdev) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical udev device.");
|
||||
g_object_unref (device);
|
||||
device = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
return device;
|
||||
}
|
||||
|
||||
static guint32
|
||||
supports_port (MMPlugin *plugin,
|
||||
const char *subsys,
|
||||
const char *name)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
|
||||
GUdevDevice *device, *physdev = NULL;
|
||||
guint32 level = 0;
|
||||
char *driver = NULL;
|
||||
|
||||
g_return_val_if_fail (plugin != NULL, 0);
|
||||
g_return_val_if_fail (MM_IS_PLUGIN (plugin), 0);
|
||||
g_return_val_if_fail (subsys != NULL, 0);
|
||||
g_return_val_if_fail (name != NULL, 0);
|
||||
|
||||
device = get_device (priv->client, subsys, name, &physdev, &driver, NULL);
|
||||
if (device)
|
||||
level = 10;
|
||||
|
||||
g_free (driver);
|
||||
if (physdev)
|
||||
g_object_unref (physdev);
|
||||
if (device)
|
||||
g_object_unref (device);
|
||||
return level;
|
||||
}
|
||||
|
||||
static MMModem *
|
||||
grab_port (MMPlugin *plugin,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GError **error)
|
||||
{
|
||||
MMPluginHso *self = MM_PLUGIN_HSO (plugin);
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
|
||||
GUdevDevice *device = NULL, *physdev = NULL;
|
||||
const char *sysfs_path = NULL;
|
||||
char *driver = NULL, *devfile = NULL;
|
||||
MMModem *modem = NULL;
|
||||
|
||||
g_return_val_if_fail (subsys != NULL, NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
device = get_device (priv->client, subsys, name, &physdev, &driver, error);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Could not get port's udev device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devfile = g_strdup (g_udev_device_get_device_file (device));
|
||||
if (!devfile) {
|
||||
if (!strcmp (subsys, "net")) {
|
||||
/* Apparently 'hso' doesn't set up the right links for the netdevice,
|
||||
* and thus libgudev can't get the sysfs file path for it.
|
||||
*/
|
||||
devfile = g_strdup_printf ("/sys/class/net/%s", name);
|
||||
if (!g_file_test (devfile, G_FILE_TEST_EXISTS)) {
|
||||
g_free (devfile);
|
||||
devfile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!devfile) {
|
||||
g_set_error (error, 0, 0, "Could not get port's sysfs file.");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
modem = mm_plugin_base_find_modem (MM_PLUGIN_BASE (self), sysfs_path);
|
||||
if (!modem) {
|
||||
modem = mm_modem_hso_new (sysfs_path,
|
||||
driver,
|
||||
mm_plugin_get_name (plugin));
|
||||
|
||||
if (modem) {
|
||||
if (!mm_modem_grab_port (modem, subsys, name, error)) {
|
||||
g_object_unref (modem);
|
||||
modem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (modem)
|
||||
mm_plugin_base_add_modem (MM_PLUGIN_BASE (self), modem);
|
||||
} else {
|
||||
if (!mm_modem_grab_port (modem, subsys, name, error))
|
||||
modem = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (devfile);
|
||||
g_free (driver);
|
||||
g_object_unref (device);
|
||||
g_object_unref (physdev);
|
||||
return modem;
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_name (MMPlugin *plugin)
|
||||
{
|
||||
return "HSO";
|
||||
}
|
||||
|
||||
static char **
|
||||
list_supported_udis (MMPlugin *plugin, LibHalContext *hal_ctx)
|
||||
{
|
||||
char **supported = NULL;
|
||||
char **devices;
|
||||
int num_devices;
|
||||
int i;
|
||||
|
||||
devices = libhal_find_device_by_capability (hal_ctx, "serial", &num_devices, NULL);
|
||||
if (devices) {
|
||||
GPtrArray *array;
|
||||
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
char *udi = devices[i];
|
||||
|
||||
if (mm_plugin_supports_udi (plugin, hal_ctx, udi))
|
||||
g_ptr_array_add (array, g_strdup (udi));
|
||||
}
|
||||
|
||||
if (array->len > 0) {
|
||||
g_ptr_array_add (array, NULL);
|
||||
supported = (char **) g_ptr_array_free (array, FALSE);
|
||||
} else
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
g_strfreev (devices);
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_driver_name (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
char *parent_udi;
|
||||
char *driver = NULL;
|
||||
|
||||
parent_udi = libhal_device_get_property_string (ctx, udi, "info.parent", NULL);
|
||||
if (parent_udi) {
|
||||
driver = libhal_device_get_property_string (ctx, parent_udi, "info.linux.driver", NULL);
|
||||
libhal_free_string (parent_udi);
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
supports_udi (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
|
||||
{
|
||||
char *driver_name;
|
||||
gboolean supported = FALSE;
|
||||
|
||||
driver_name = get_driver_name (hal_ctx, udi);
|
||||
if (driver_name && !strcmp (driver_name, "hso")) {
|
||||
char *sysfs_path;
|
||||
|
||||
sysfs_path = libhal_device_get_property_string (hal_ctx, udi, "linux.sysfs_path", NULL);
|
||||
if (sysfs_path) {
|
||||
char *hso_type_path;
|
||||
gchar *contents = NULL;
|
||||
gsize length;
|
||||
|
||||
hso_type_path = g_build_filename (sysfs_path, "hsotype", NULL);
|
||||
libhal_free_string (sysfs_path);
|
||||
|
||||
if (g_file_get_contents (hso_type_path, &contents, &length, NULL)) {
|
||||
if (g_str_has_prefix (contents, "Control"))
|
||||
supported = TRUE;
|
||||
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
g_free (hso_type_path);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (driver_name);
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_netdev (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
char *serial_parent, *netdev = NULL;
|
||||
char **netdevs;
|
||||
int num, i;
|
||||
|
||||
/* Get the serial interface's originating device UDI, used to find the
|
||||
* originating device's netdev.
|
||||
*/
|
||||
serial_parent = libhal_device_get_property_string (ctx, udi, "serial.originating_device", NULL);
|
||||
if (!serial_parent)
|
||||
serial_parent = libhal_device_get_property_string (ctx, udi, "info.parent", NULL);
|
||||
if (!serial_parent)
|
||||
return NULL;
|
||||
|
||||
/* Look for the originating device's netdev */
|
||||
netdevs = libhal_find_device_by_capability (ctx, "net", &num, NULL);
|
||||
for (i = 0; netdevs && !netdev && (i < num); i++) {
|
||||
char *netdev_parent, *tmp;
|
||||
|
||||
netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "net.originating_device", NULL);
|
||||
if (!netdev_parent)
|
||||
netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "net.physical_device", NULL);
|
||||
if (!netdev_parent)
|
||||
continue;
|
||||
|
||||
if (!strcmp (netdev_parent, serial_parent)) {
|
||||
/* We found it */
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.interface", NULL);
|
||||
if (tmp) {
|
||||
netdev = g_strdup (tmp);
|
||||
libhal_free_string (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (netdev_parent);
|
||||
}
|
||||
|
||||
if (!netdev) {
|
||||
/* Didn't find from netdev's parents. Try again with "grandparents" */
|
||||
char *serial_grandparent;
|
||||
|
||||
serial_grandparent = libhal_device_get_property_string (ctx, serial_parent, "info.parent", NULL);
|
||||
if (!serial_grandparent)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; netdevs && !netdev && (i < num); i++) {
|
||||
char *netdev_parent, *tmp;
|
||||
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.originating_device", NULL);
|
||||
if (!tmp)
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.physical_device", NULL);
|
||||
if (!tmp)
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "info.parent", NULL);
|
||||
if (!tmp)
|
||||
continue;
|
||||
|
||||
netdev_parent = libhal_device_get_property_string (ctx, tmp, "info.parent", NULL);
|
||||
libhal_free_string (tmp);
|
||||
|
||||
if (netdev_parent) {
|
||||
if (!strcmp (netdev_parent, serial_grandparent)) {
|
||||
/* We found it */
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.interface", NULL);
|
||||
if (tmp) {
|
||||
netdev = g_strdup (tmp);
|
||||
libhal_free_string (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (netdev_parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
libhal_free_string_array (netdevs);
|
||||
libhal_free_string (serial_parent);
|
||||
|
||||
return netdev;
|
||||
}
|
||||
|
||||
static MMModem *
|
||||
create_modem (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
|
||||
{
|
||||
char *serial_device;
|
||||
char *net_device;
|
||||
char *driver;
|
||||
MMModem *modem;
|
||||
|
||||
serial_device = libhal_device_get_property_string (hal_ctx, udi, "serial.device", NULL);
|
||||
g_return_val_if_fail (serial_device != NULL, NULL);
|
||||
|
||||
driver = get_driver_name (hal_ctx, udi);
|
||||
g_return_val_if_fail (driver != NULL, NULL);
|
||||
|
||||
net_device = get_netdev (hal_ctx, udi);
|
||||
g_return_val_if_fail (net_device != NULL, NULL);
|
||||
|
||||
modem = MM_MODEM (mm_modem_hso_new (serial_device, net_device, driver));
|
||||
|
||||
g_free (serial_device);
|
||||
g_free (net_device);
|
||||
g_free (driver);
|
||||
|
||||
return modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
@@ -226,17 +247,33 @@ plugin_init (MMPlugin *plugin_class)
|
||||
{
|
||||
/* interface implementation */
|
||||
plugin_class->get_name = get_name;
|
||||
plugin_class->list_supported_udis = list_supported_udis;
|
||||
plugin_class->supports_udi = supports_udi;
|
||||
plugin_class->create_modem = create_modem;
|
||||
plugin_class->supports_port = supports_port;
|
||||
plugin_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_hso_init (MMPluginHso *self)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (self);
|
||||
const char *subsys[] = { "tty", "net", NULL };
|
||||
|
||||
priv->client = g_udev_client_new (subsys);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (object);
|
||||
|
||||
g_object_unref (priv->client);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_hso_class_init (MMPluginHsoClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMPluginHsoPrivate));
|
||||
|
||||
object_class->dispose = dispose;
|
||||
}
|
||||
|
||||
+23
-8
@@ -1,24 +1,39 @@
|
||||
/* -*- 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) 2008 - 2009 Novell, Inc.
|
||||
* Copyright (C) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_PLUGIN_HSO_H
|
||||
#define MM_PLUGIN_HSO_H
|
||||
|
||||
#include "mm-plugin.h"
|
||||
#include "mm-plugin-base.h"
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_PLUGIN_HSO (mm_plugin_hso_get_type ())
|
||||
#define MM_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHso))
|
||||
#define MM_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_IS_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_IS_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_PLUGIN_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_TYPE_PLUGIN_HSO (mm_plugin_hso_get_type ())
|
||||
#define MM_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHso))
|
||||
#define MM_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_IS_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_IS_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_PLUGIN_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
|
||||
typedef struct {
|
||||
GObject parent;
|
||||
MMPluginBase parent;
|
||||
} MMPluginHso;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
MMPluginBaseClass parent;
|
||||
} MMPluginHsoClass;
|
||||
|
||||
GType mm_plugin_hso_get_type (void);
|
||||
|
||||
@@ -277,7 +277,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user