|
Packit Service |
87a54e |
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2014 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <gmodule.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "devices/nm-device-factory.h"
|
|
Packit |
5756e2 |
#include "nm-setting-gsm.h"
|
|
Packit |
5756e2 |
#include "nm-setting-cdma.h"
|
|
Packit |
5756e2 |
#include "nm-modem-manager.h"
|
|
Packit |
5756e2 |
#include "nm-device-modem.h"
|
|
Packit |
5756e2 |
#include "platform/nm-platform.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_TYPE_WWAN_FACTORY (nm_wwan_factory_get_type())
|
|
Packit Service |
a1bd4f |
#define NM_WWAN_FACTORY(obj) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_WWAN_FACTORY, NMWwanFactory))
|
|
Packit Service |
a1bd4f |
#define NM_WWAN_FACTORY_CLASS(klass) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_WWAN_FACTORY, NMWwanFactoryClass))
|
|
Packit Service |
a1bd4f |
#define NM_IS_WWAN_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_WWAN_FACTORY))
|
|
Packit Service |
a1bd4f |
#define NM_IS_WWAN_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_WWAN_FACTORY))
|
|
Packit Service |
a1bd4f |
#define NM_WWAN_FACTORY_GET_CLASS(obj) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_WWAN_FACTORY, NMWwanFactoryClass))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NMModemManager *mm;
|
|
Packit |
5756e2 |
} NMWwanFactoryPrivate;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NMDeviceFactory parent;
|
|
Packit Service |
a1bd4f |
NMWwanFactoryPrivate _priv;
|
|
Packit |
5756e2 |
} NMWwanFactory;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NMDeviceFactoryClass parent;
|
|
Packit |
5756e2 |
} NMWwanFactoryClass;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
static GType nm_wwan_factory_get_type(void);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NMWwanFactory, nm_wwan_factory, NM_TYPE_DEVICE_FACTORY)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_WWAN_FACTORY_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMWwanFactory, NM_IS_WWAN_FACTORY)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_DEVICE_FACTORY_DECLARE_TYPES(NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(
|
|
Packit Service |
a1bd4f |
NM_LINK_TYPE_WWAN_NET) NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_GSM_SETTING_NAME,
|
|
Packit Service |
a1bd4f |
NM_SETTING_CDMA_SETTING_NAME))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
G_MODULE_EXPORT NMDeviceFactory *
|
|
Packit Service |
a1bd4f |
nm_device_factory_create(GError **error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return g_object_new(NM_TYPE_WWAN_FACTORY, NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
modem_added_cb(NMModemManager *manager, NMModem *modem, gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMWwanFactory * self = NM_WWAN_FACTORY(user_data);
|
|
Packit Service |
a1bd4f |
gs_unref_object NMDevice *device = NULL;
|
|
Packit Service |
a1bd4f |
const char * driver;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (nm_modem_is_claimed(modem))
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
driver = nm_modem_get_driver(modem);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* If it was a Bluetooth modem and no bluetooth device claimed it, ignore
|
|
Packit Service |
a1bd4f |
* it. The rfcomm port (and thus the modem) gets created automatically
|
|
Packit Service |
a1bd4f |
* by the Bluetooth code during the connection process.
|
|
Packit Service |
a1bd4f |
*/
|
|
Packit Service |
a1bd4f |
if (driver && strstr(driver, "bluetooth")) {
|
|
Packit Service |
a1bd4f |
nm_log_dbg(
|
|
Packit Service |
a1bd4f |
LOGD_MB,
|
|
Packit Service |
a1bd4f |
"WWAN factory ignores bluetooth modem '%s' which should be handled by bluetooth plugin",
|
|
Packit Service |
a1bd4f |
nm_modem_get_control_port(modem));
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Make the new modem device */
|
|
Packit Service |
a1bd4f |
device = nm_device_modem_new(modem);
|
|
Packit Service |
a1bd4f |
g_signal_emit_by_name(self, NM_DEVICE_FACTORY_DEVICE_ADDED, device);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMDevice *
|
|
Packit Service |
a1bd4f |
create_device(NMDeviceFactory * factory,
|
|
Packit Service |
a1bd4f |
const char * iface,
|
|
Packit Service |
a1bd4f |
const NMPlatformLink *plink,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
gboolean * out_ignore)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(plink, NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(plink->type == NM_LINK_TYPE_WWAN_NET, NULL);
|
|
Packit Service |
a1bd4f |
*out_ignore = TRUE;
|
|
Packit Service |
a1bd4f |
return NULL;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
start(NMDeviceFactory *factory)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMWwanFactory * self = NM_WWAN_FACTORY(factory);
|
|
Packit Service |
a1bd4f |
NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE(self);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
priv->mm = g_object_ref(nm_modem_manager_get());
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_signal_connect(priv->mm, NM_MODEM_MANAGER_MODEM_ADDED, G_CALLBACK(modem_added_cb), self);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_wwan_factory_init(NMWwanFactory *self)
|
|
Packit Service |
a1bd4f |
{}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
dispose(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMWwanFactory * self = NM_WWAN_FACTORY(object);
|
|
Packit Service |
a1bd4f |
NMWwanFactoryPrivate *priv = NM_WWAN_FACTORY_GET_PRIVATE(self);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
if (priv->mm)
|
|
Packit Service |
a1bd4f |
g_signal_handlers_disconnect_by_func(priv->mm, modem_added_cb, self);
|
|
Packit Service |
a1bd4f |
g_clear_object(&priv->mm);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Chain up to the parent class */
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nm_wwan_factory_parent_class)->dispose(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_wwan_factory_class_init(NMWwanFactoryClass *klass)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass * object_class = G_OBJECT_CLASS(klass);
|
|
Packit Service |
a1bd4f |
NMDeviceFactoryClass *factory_class = NM_DEVICE_FACTORY_CLASS(klass);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
object_class->dispose = dispose;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
factory_class->get_supported_types = get_supported_types;
|
|
Packit Service |
a1bd4f |
factory_class->create_device = create_device;
|
|
Packit Service |
a1bd4f |
factory_class->start = start;
|
|
Packit |
5756e2 |
}
|