1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2011 - 2012 Red Hat, Inc.
19 * Copyright 2008 Novell, Inc.
22 #include "nm-default.h"
26 #include "nm-setting-connection.h"
27 #include "nm-setting-gsm.h"
28 #include "nm-setting-cdma.h"
30 #include "nm-device-modem.h"
31 #include "nm-device-private.h"
32 #include "nm-object-private.h"
34 G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
36 #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
41 NMDeviceModemCapabilities caps;
42 NMDeviceModemCapabilities current_caps;
43 } NMDeviceModemPrivate;
53 * nm_device_modem_error_quark:
55 * Registers an error quark for #NMDeviceModem if necessary.
57 * Returns: the error quark used for #NMDeviceModem errors.
60 nm_device_modem_error_quark (void)
62 static GQuark quark = 0;
64 if (G_UNLIKELY (quark == 0))
65 quark = g_quark_from_static_string ("nm-device-modem-error-quark");
70 * nm_device_modem_get_modem_capabilities:
71 * @self: a #NMDeviceModem
73 * Returns a bitfield of the generic access technology families the modem
74 * supports. Not all capabilities are available concurrently however; some
75 * may require a firmware reload or reinitialization.
77 * Returns: the generic access technology families the modem supports
79 NMDeviceModemCapabilities
80 nm_device_modem_get_modem_capabilities (NMDeviceModem *self)
82 g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
84 _nm_object_ensure_inited (NM_OBJECT (self));
85 return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps;
89 * nm_device_modem_get_current_capabilities:
90 * @self: a #NMDeviceModem
92 * Returns a bitfield of the generic access technology families the modem
93 * supports without a firmware reload or reinitialization. This value
94 * represents the network types the modem can immediately connect to.
96 * Returns: the generic access technology families the modem supports without
97 * a firmware reload or other reinitialization
99 NMDeviceModemCapabilities
100 nm_device_modem_get_current_capabilities (NMDeviceModem *self)
102 g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
104 _nm_object_ensure_inited (NM_OBJECT (self));
105 return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
109 get_type_description (NMDevice *device)
111 NMDeviceModemCapabilities caps;
113 caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
114 if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
116 else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
122 #define MODEM_CAPS_3GPP(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | \
123 NM_DEVICE_MODEM_CAPABILITY_LTE))
125 #define MODEM_CAPS_3GPP2(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))
128 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
130 NMSettingConnection *s_con;
132 NMSettingCdma *s_cdma;
134 NMDeviceModemCapabilities current_caps;
136 s_con = nm_connection_get_setting_connection (connection);
139 ctype = nm_setting_connection_get_connection_type (s_con);
140 if ( strcmp (ctype, NM_SETTING_GSM_SETTING_NAME) != 0
141 && strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME) != 0) {
142 g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION,
143 "The connection was not a modem connection.");
147 s_gsm = nm_connection_get_setting_gsm (connection);
148 s_cdma = nm_connection_get_setting_cdma (connection);
149 if (!s_cdma && !s_gsm) {
150 g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION,
151 "The connection was not a valid modem connection.");
155 current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
156 if (!(s_gsm && MODEM_CAPS_3GPP (current_caps)) && !(s_cdma && MODEM_CAPS_3GPP2 (current_caps))) {
157 g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS,
158 "The device missed capabilities required by the GSM/CDMA connection.");
162 return NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error);
166 get_setting_type (NMDevice *device)
168 NMDeviceModemCapabilities caps;
170 caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
171 if (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE))
172 return NM_TYPE_SETTING_GSM;
173 else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
174 return NM_TYPE_SETTING_CDMA;
176 return G_TYPE_INVALID;
179 /*******************************************************************/
182 nm_device_modem_init (NMDeviceModem *device)
184 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MODEM);
188 register_properties (NMDeviceModem *device)
190 NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device);
191 const NMPropertiesInfo property_info[] = {
192 { NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps },
193 { NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
197 _nm_object_register_properties (NM_OBJECT (device),
203 constructed (GObject *object)
205 NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
207 G_OBJECT_CLASS (nm_device_modem_parent_class)->constructed (object);
209 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_MODEM);
210 register_properties (NM_DEVICE_MODEM (object));
214 get_property (GObject *object,
219 NMDeviceModem *self = NM_DEVICE_MODEM (object);
221 _nm_object_ensure_inited (NM_OBJECT (object));
224 case PROP_MODEM_CAPS:
225 g_value_set_uint (value, nm_device_modem_get_modem_capabilities (self));
227 case PROP_CURRENT_CAPS:
228 g_value_set_uint (value, nm_device_modem_get_current_capabilities (self));
231 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237 dispose (GObject *object)
239 NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
241 g_clear_object (&priv->proxy);
243 G_OBJECT_CLASS (nm_device_modem_parent_class)->dispose (object);
247 nm_device_modem_class_init (NMDeviceModemClass *modem_class)
249 GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
250 NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class);
252 g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate));
254 /* virtual methods */
255 object_class->constructed = constructed;
256 object_class->get_property = get_property;
257 object_class->dispose = dispose;
259 device_class->get_type_description = get_type_description;
260 device_class->connection_compatible = connection_compatible;
261 device_class->get_setting_type = get_setting_type;
264 * NMDeviceModem:modem-capabilities:
266 * The generic family of access technologies the modem supports. Not all
267 * capabilities are available at the same time however; some modems require
268 * a firmware reload or other reinitialization to switch between eg
269 * CDMA/EVDO and GSM/UMTS.
271 g_object_class_install_property
272 (object_class, PROP_MODEM_CAPS,
273 g_param_spec_uint (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "",
276 G_PARAM_STATIC_STRINGS));
279 * NMDeviceModem:current-capabilities:
281 * The generic family of access technologies the modem currently supports
282 * without a firmware reload or reinitialization.
284 g_object_class_install_property
285 (object_class, PROP_CURRENT_CAPS,
286 g_param_spec_uint (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "",
289 G_PARAM_STATIC_STRINGS));