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"
33 #include "nm-enum-types.h"
35 G_DEFINE_TYPE (NMDeviceModem, nm_device_modem, NM_TYPE_DEVICE)
37 #define NM_DEVICE_MODEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_MODEM, NMDeviceModemPrivate))
40 NMDeviceModemCapabilities caps;
41 NMDeviceModemCapabilities current_caps;
42 } NMDeviceModemPrivate;
52 * nm_device_modem_get_modem_capabilities:
53 * @self: a #NMDeviceModem
55 * Returns a bitfield of the generic access technology families the modem
56 * supports. Not all capabilities are available concurrently however; some
57 * may require a firmware reload or reinitialization.
59 * Returns: the generic access technology families the modem supports
61 NMDeviceModemCapabilities
62 nm_device_modem_get_modem_capabilities (NMDeviceModem *self)
64 g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
66 return NM_DEVICE_MODEM_GET_PRIVATE (self)->caps;
70 * nm_device_modem_get_current_capabilities:
71 * @self: a #NMDeviceModem
73 * Returns a bitfield of the generic access technology families the modem
74 * supports without a firmware reload or reinitialization. This value
75 * represents the network types the modem can immediately connect to.
77 * Returns: the generic access technology families the modem supports without
78 * a firmware reload or other reinitialization
80 NMDeviceModemCapabilities
81 nm_device_modem_get_current_capabilities (NMDeviceModem *self)
83 g_return_val_if_fail (NM_IS_DEVICE_MODEM (self), NM_DEVICE_MODEM_CAPABILITY_NONE);
85 return NM_DEVICE_MODEM_GET_PRIVATE (self)->current_caps;
89 get_type_description (NMDevice *device)
91 NMDeviceModemCapabilities caps;
93 caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
94 if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
96 else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
102 #define MODEM_CAPS_3GPP(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | \
103 NM_DEVICE_MODEM_CAPABILITY_LTE))
105 #define MODEM_CAPS_3GPP2(caps) (caps & (NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))
108 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
111 NMSettingCdma *s_cdma;
112 NMDeviceModemCapabilities current_caps;
114 if (!NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error))
117 if ( !nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME)
118 && !nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME)) {
119 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
120 _("The connection was not a modem connection."));
124 s_gsm = nm_connection_get_setting_gsm (connection);
125 s_cdma = nm_connection_get_setting_cdma (connection);
126 if (!s_cdma && !s_gsm) {
127 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
128 _("The connection was not a valid modem connection."));
132 current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
133 if (!(s_gsm && MODEM_CAPS_3GPP (current_caps)) && !(s_cdma && MODEM_CAPS_3GPP2 (current_caps))) {
134 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
135 _("The device is lacking capabilities required by the connection."));
143 get_setting_type (NMDevice *device)
145 NMDeviceModemCapabilities caps;
147 caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
148 if (caps & (NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS | NM_DEVICE_MODEM_CAPABILITY_LTE))
149 return NM_TYPE_SETTING_GSM;
150 else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
151 return NM_TYPE_SETTING_CDMA;
153 return G_TYPE_INVALID;
156 /*******************************************************************/
159 nm_device_modem_init (NMDeviceModem *device)
161 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_MODEM);
165 init_dbus (NMObject *object)
167 NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (object);
168 const NMPropertiesInfo property_info[] = {
169 { NM_DEVICE_MODEM_MODEM_CAPABILITIES, &priv->caps },
170 { NM_DEVICE_MODEM_CURRENT_CAPABILITIES, &priv->current_caps },
174 NM_OBJECT_CLASS (nm_device_modem_parent_class)->init_dbus (object);
176 _nm_object_register_properties (object,
177 NM_DBUS_INTERFACE_DEVICE_MODEM,
182 get_property (GObject *object,
187 NMDeviceModem *self = NM_DEVICE_MODEM (object);
190 case PROP_MODEM_CAPS:
191 g_value_set_flags (value, nm_device_modem_get_modem_capabilities (self));
193 case PROP_CURRENT_CAPS:
194 g_value_set_flags (value, nm_device_modem_get_current_capabilities (self));
197 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
203 nm_device_modem_class_init (NMDeviceModemClass *modem_class)
205 GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
206 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (modem_class);
207 NMDeviceClass *device_class = NM_DEVICE_CLASS (modem_class);
209 g_type_class_add_private (modem_class, sizeof (NMDeviceModemPrivate));
211 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_MODEM);
213 /* virtual methods */
214 object_class->get_property = get_property;
216 nm_object_class->init_dbus = init_dbus;
218 device_class->get_type_description = get_type_description;
219 device_class->connection_compatible = connection_compatible;
220 device_class->get_setting_type = get_setting_type;
223 * NMDeviceModem:modem-capabilities:
225 * The generic family of access technologies the modem supports. Not all
226 * capabilities are available at the same time however; some modems require
227 * a firmware reload or other reinitialization to switch between eg
228 * CDMA/EVDO and GSM/UMTS.
230 g_object_class_install_property
231 (object_class, PROP_MODEM_CAPS,
232 g_param_spec_flags (NM_DEVICE_MODEM_MODEM_CAPABILITIES, "", "",
233 NM_TYPE_DEVICE_MODEM_CAPABILITIES,
234 NM_DEVICE_MODEM_CAPABILITY_NONE,
236 G_PARAM_STATIC_STRINGS));
239 * NMDeviceModem:current-capabilities:
241 * The generic family of access technologies the modem currently supports
242 * without a firmware reload or reinitialization.
244 g_object_class_install_property
245 (object_class, PROP_CURRENT_CAPS,
246 g_param_spec_flags (NM_DEVICE_MODEM_CURRENT_CAPABILITIES, "", "",
247 NM_TYPE_DEVICE_MODEM_CAPABILITIES,
248 NM_DEVICE_MODEM_CAPABILITY_NONE,
250 G_PARAM_STATIC_STRINGS));