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 2009 Novell, Inc.
22 #include "nm-default.h"
25 #include <netinet/ether.h>
27 #include "nm-setting-connection.h"
28 #include "nm-setting-wimax.h"
30 #include "nm-device-wimax.h"
31 #include "nm-object-private.h"
32 #include "nm-object-cache.h"
33 #include "nm-dbus-glib-types.h"
34 #include "nm-types-private.h"
35 #include "nm-device-private.h"
37 G_DEFINE_TYPE (NMDeviceWimax, nm_device_wimax, NM_TYPE_DEVICE)
39 #define NM_DEVICE_WIMAX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_WIMAX, NMDeviceWimaxPrivate))
41 void _nm_device_wimax_set_wireless_enabled (NMDeviceWimax *wimax, gboolean enabled);
47 NMWimaxNsp *active_nsp;
55 } NMDeviceWimaxPrivate;
77 static guint signals[LAST_SIGNAL] = { 0 };
80 * nm_device_wimax_error_quark:
82 * Registers an error quark for #NMDeviceWimax if necessary.
84 * Returns: the error quark used for #NMDeviceWimax errors.
86 * Deprecated: 1.2: WiMAX is no longer supported.
89 nm_device_wimax_error_quark (void)
91 static GQuark quark = 0;
93 if (G_UNLIKELY (quark == 0))
94 quark = g_quark_from_static_string ("nm-device-wimax-error-quark");
99 * nm_device_wimax_new:
100 * @connection: the #DBusGConnection
101 * @path: the D-Bus object path of the WiMAX device
103 * Creates a new #NMDeviceWimax.
105 * Returns: (transfer full): a new WiMAX device
107 * Deprecated: 1.2: WiMAX is no longer supported.
110 nm_device_wimax_new (DBusGConnection *connection, const char *path)
114 g_return_val_if_fail (connection != NULL, NULL);
115 g_return_val_if_fail (path != NULL, NULL);
117 device = g_object_new (NM_TYPE_DEVICE_WIMAX,
118 NM_OBJECT_DBUS_CONNECTION, connection,
119 NM_OBJECT_DBUS_PATH, path,
121 _nm_object_ensure_inited (NM_OBJECT (device));
126 * nm_device_wimax_get_hw_address:
127 * @wimax: a #NMDeviceWimax
129 * Gets the hardware (MAC) address of the #NMDeviceWimax
131 * Returns: the hardware address. This is the internal string used by the
132 * device, and must not be modified.
134 * Deprecated: 1.2: WiMAX is no longer supported.
137 nm_device_wimax_get_hw_address (NMDeviceWimax *wimax)
139 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
141 _nm_object_ensure_inited (NM_OBJECT (wimax));
142 return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address;
146 * nm_device_wimax_get_active_nsp:
147 * @wimax: a #NMDeviceWimax
149 * Gets the active #NMWimaxNsp.
151 * Returns: (transfer full): the access point or %NULL if none is active
153 * Deprecated: 1.2: WiMAX is no longer supported.
156 nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax)
160 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
162 state = nm_device_get_state (NM_DEVICE (wimax));
164 case NM_DEVICE_STATE_PREPARE:
165 case NM_DEVICE_STATE_CONFIG:
166 case NM_DEVICE_STATE_NEED_AUTH:
167 case NM_DEVICE_STATE_IP_CONFIG:
168 case NM_DEVICE_STATE_IP_CHECK:
169 case NM_DEVICE_STATE_SECONDARIES:
170 case NM_DEVICE_STATE_ACTIVATED:
171 case NM_DEVICE_STATE_DEACTIVATING:
178 _nm_object_ensure_inited (NM_OBJECT (wimax));
179 return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->active_nsp;
183 * nm_device_wimax_get_nsps:
184 * @wimax: a #NMDeviceWimax
186 * Gets all the scanned NSPs of the #NMDeviceWimax.
188 * Returns: (element-type NMWimaxNsp): a #GPtrArray containing
189 * all the scanned #NMWimaxNsps.
190 * The returned array is owned by the client and should not be modified.
192 * Deprecated: 1.2: WiMAX is no longer supported.
195 nm_device_wimax_get_nsps (NMDeviceWimax *wimax)
197 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
199 _nm_object_ensure_inited (NM_OBJECT (wimax));
200 return handle_ptr_array_return (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps);
204 * nm_device_wimax_get_nsp_by_path:
205 * @wimax: a #NMDeviceWimax
206 * @path: the object path of the NSP
208 * Gets a #NMWimaxNsp by path.
210 * Returns: (transfer none): the access point or %NULL if none is found.
212 * Deprecated: 1.2: WiMAX is no longer supported.
215 nm_device_wimax_get_nsp_by_path (NMDeviceWimax *wimax,
218 const GPtrArray *nsps;
220 NMWimaxNsp *nsp = NULL;
222 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL);
223 g_return_val_if_fail (path != NULL, NULL);
225 nsps = nm_device_wimax_get_nsps (wimax);
229 for (i = 0; i < nsps->len; i++) {
230 NMWimaxNsp *candidate = g_ptr_array_index (nsps, i);
231 if (!strcmp (nm_object_get_path (NM_OBJECT (candidate)), path)) {
241 clean_up_nsps (NMDeviceWimax *self, gboolean notify)
243 NMDeviceWimaxPrivate *priv;
245 g_return_if_fail (NM_IS_DEVICE_WIMAX (self));
247 priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
249 if (priv->active_nsp) {
250 g_object_unref (priv->active_nsp);
251 priv->active_nsp = NULL;
255 while (priv->nsps->len) {
256 NMWimaxNsp *nsp = NM_WIMAX_NSP (g_ptr_array_index (priv->nsps, 0));
259 g_signal_emit (self, signals[NSP_REMOVED], 0, nsp);
260 g_ptr_array_remove (priv->nsps, nsp);
261 g_object_unref (nsp);
263 g_ptr_array_free (priv->nsps, TRUE);
269 * nm_device_wimax_get_center_frequency:
270 * @self: a #NMDeviceWimax
272 * Gets the center frequency (in KHz) of the radio channel the device is using
273 * to communicate with the network when connected. Has no meaning when the
274 * device is not connected.
276 * Returns: the center frequency in KHz, or 0
278 * Deprecated: 1.2: WiMAX is no longer supported.
281 nm_device_wimax_get_center_frequency (NMDeviceWimax *self)
283 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
285 _nm_object_ensure_inited (NM_OBJECT (self));
286 return NM_DEVICE_WIMAX_GET_PRIVATE (self)->center_freq;
290 * nm_device_wimax_get_rssi:
291 * @self: a #NMDeviceWimax
293 * Gets the RSSI of the current radio link in dBm. This value indicates how
294 * strong the raw received RF signal from the base station is, but does not
295 * indicate the overall quality of the radio link. Has no meaning when the
296 * device is not connected.
298 * Returns: the RSSI in dBm, or 0
300 * Deprecated: 1.2: WiMAX is no longer supported.
303 nm_device_wimax_get_rssi (NMDeviceWimax *self)
305 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
307 _nm_object_ensure_inited (NM_OBJECT (self));
308 return NM_DEVICE_WIMAX_GET_PRIVATE (self)->rssi;
312 * nm_device_wimax_get_cinr:
313 * @self: a #NMDeviceWimax
315 * Gets the CINR (Carrier to Interference + Noise Ratio) of the current radio
316 * link in dB. CINR is a more accurate measure of radio link quality. Has no
317 * meaning when the device is not connected.
319 * Returns: the CINR in dB, or 0
321 * Deprecated: 1.2: WiMAX is no longer supported.
324 nm_device_wimax_get_cinr (NMDeviceWimax *self)
326 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
328 _nm_object_ensure_inited (NM_OBJECT (self));
329 return NM_DEVICE_WIMAX_GET_PRIVATE (self)->cinr;
333 * nm_device_wimax_get_tx_power:
334 * @self: a #NMDeviceWimax
336 * Average power of the last burst transmitted by the device, in units of
337 * 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of
338 * -5.5 dBm. Has no meaning when the device is not connected.
340 * Returns: the TX power in dBm, or 0
342 * Deprecated: 1.2: WiMAX is no longer supported.
345 nm_device_wimax_get_tx_power (NMDeviceWimax *self)
347 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0);
349 _nm_object_ensure_inited (NM_OBJECT (self));
350 return NM_DEVICE_WIMAX_GET_PRIVATE (self)->tx_power;
354 * nm_device_wimax_get_bsid:
355 * @self: a #NMDeviceWimax
357 * Gets the ID of the serving Base Station when the device is connected.
359 * Returns: the ID of the serving Base Station, or %NULL
361 * Deprecated: 1.2: WiMAX is no longer supported.
364 nm_device_wimax_get_bsid (NMDeviceWimax *self)
366 g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL);
368 _nm_object_ensure_inited (NM_OBJECT (self));
369 return NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid;
373 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
375 NMSettingConnection *s_con;
376 NMSettingWimax *s_wimax;
378 const GByteArray *mac;
380 struct ether_addr *hw_mac;
382 s_con = nm_connection_get_setting_connection (connection);
385 ctype = nm_setting_connection_get_connection_type (s_con);
386 if (strcmp (ctype, NM_SETTING_WIMAX_SETTING_NAME) != 0) {
387 g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_NOT_WIMAX_CONNECTION,
388 "The connection was not a Wimax connection.");
392 s_wimax = nm_connection_get_setting_wimax (connection);
394 g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_WIMAX_CONNECTION,
395 "The connection was not a valid Wimax connection.");
399 /* Check MAC address */
400 hw_str = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device));
402 hw_mac = ether_aton (hw_str);
404 g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_INVALID_DEVICE_MAC,
405 "Invalid device MAC address.");
408 mac = nm_setting_wimax_get_mac_address (s_wimax);
409 if (mac && hw_mac && memcmp (mac->data, hw_mac->ether_addr_octet, ETH_ALEN)) {
410 g_set_error (error, NM_DEVICE_WIMAX_ERROR, NM_DEVICE_WIMAX_ERROR_MAC_MISMATCH,
411 "The MACs of the device and the connection didn't match.");
416 return NM_DEVICE_CLASS (nm_device_wimax_parent_class)->connection_compatible (device, connection, error);
420 get_setting_type (NMDevice *device)
422 return NM_TYPE_SETTING_WIMAX;
426 get_hw_address (NMDevice *device)
428 return nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device));
431 /**************************************************************/
434 nm_device_wimax_init (NMDeviceWimax *device)
436 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_WIMAX);
440 get_property (GObject *object,
445 NMDeviceWimax *self = NM_DEVICE_WIMAX (object);
447 _nm_object_ensure_inited (NM_OBJECT (object));
450 case PROP_HW_ADDRESS:
451 g_value_set_string (value, nm_device_wimax_get_hw_address (self));
453 case PROP_ACTIVE_NSP:
454 g_value_set_object (value, nm_device_wimax_get_active_nsp (self));
456 case PROP_CENTER_FREQ:
457 g_value_set_uint (value, nm_device_wimax_get_center_frequency (self));
460 g_value_set_int (value, nm_device_wimax_get_rssi (self));
463 g_value_set_int (value, nm_device_wimax_get_cinr (self));
466 g_value_set_int (value, nm_device_wimax_get_tx_power (self));
469 g_value_set_string (value, nm_device_wimax_get_bsid (self));
472 g_value_set_boxed (value, nm_device_wimax_get_nsps (self));
475 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
481 clear_link_status (NMDeviceWimax *self)
483 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
485 if (priv->center_freq) {
486 priv->center_freq = 0;
487 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CENTER_FREQUENCY);
492 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_RSSI);
497 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CINR);
500 if (priv->tx_power) {
502 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_TX_POWER);
508 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_BSID);
513 state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
515 NMDeviceWimax *self = NM_DEVICE_WIMAX (device);
516 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
519 state = nm_device_get_state (device);
521 case NM_DEVICE_STATE_UNKNOWN:
522 case NM_DEVICE_STATE_UNMANAGED:
523 case NM_DEVICE_STATE_UNAVAILABLE:
524 case NM_DEVICE_STATE_DISCONNECTED:
525 case NM_DEVICE_STATE_FAILED:
526 if (priv->active_nsp) {
527 g_object_unref (priv->active_nsp);
528 priv->active_nsp = NULL;
530 _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIMAX_ACTIVE_NSP);
531 clear_link_status (self);
533 case NM_DEVICE_STATE_PREPARE:
534 case NM_DEVICE_STATE_CONFIG:
535 case NM_DEVICE_STATE_NEED_AUTH:
536 case NM_DEVICE_STATE_IP_CONFIG:
537 clear_link_status (self);
545 register_properties (NMDeviceWimax *wimax)
547 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (wimax);
548 const NMPropertiesInfo property_info[] = {
549 { NM_DEVICE_WIMAX_HW_ADDRESS, &priv->hw_address },
550 { NM_DEVICE_WIMAX_ACTIVE_NSP, &priv->active_nsp, NULL, NM_TYPE_WIMAX_NSP },
551 { NM_DEVICE_WIMAX_CENTER_FREQUENCY, &priv->center_freq },
552 { NM_DEVICE_WIMAX_RSSI, &priv->rssi },
553 { NM_DEVICE_WIMAX_CINR, &priv->cinr },
554 { NM_DEVICE_WIMAX_TX_POWER, &priv->tx_power },
555 { NM_DEVICE_WIMAX_BSID, &priv->bsid },
556 { NM_DEVICE_WIMAX_NSPS, &priv->nsps, NULL, NM_TYPE_WIMAX_NSP, "nsp" },
560 _nm_object_register_properties (NM_OBJECT (wimax),
566 nsp_removed (NMDeviceWimax *self, NMWimaxNsp *nsp)
568 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self);
570 if (nsp == priv->active_nsp) {
571 g_object_unref (priv->active_nsp);
572 priv->active_nsp = NULL;
573 _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_ACTIVE_NSP);
578 constructed (GObject *object)
580 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (object);
582 G_OBJECT_CLASS (nm_device_wimax_parent_class)->constructed (object);
584 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_WIMAX);
585 register_properties (NM_DEVICE_WIMAX (object));
587 g_signal_connect (object,
588 "notify::" NM_DEVICE_STATE,
589 G_CALLBACK (state_changed_cb),
594 dispose (GObject *object)
596 NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (object);
598 if (priv->hw_address) {
599 g_free (priv->hw_address);
600 priv->hw_address = NULL;
608 clean_up_nsps (NM_DEVICE_WIMAX (object), FALSE);
609 g_clear_object (&priv->proxy);
611 G_OBJECT_CLASS (nm_device_wimax_parent_class)->dispose (object);
615 nm_device_wimax_class_init (NMDeviceWimaxClass *wimax_class)
617 GObjectClass *object_class = G_OBJECT_CLASS (wimax_class);
618 NMDeviceClass *device_class = NM_DEVICE_CLASS (wimax_class);
620 g_type_class_add_private (wimax_class, sizeof (NMDeviceWimaxPrivate));
622 /* virtual methods */
623 object_class->constructed = constructed;
624 object_class->get_property = get_property;
625 object_class->dispose = dispose;
626 device_class->connection_compatible = connection_compatible;
627 device_class->get_setting_type = get_setting_type;
628 device_class->get_hw_address = get_hw_address;
629 wimax_class->nsp_removed = nsp_removed;
634 * NMDeviceWimax:hw-address:
636 * The hardware (MAC) address of the device.
638 * Deprecated: 1.2: WiMAX is no longer supported.
640 g_object_class_install_property
641 (object_class, PROP_HW_ADDRESS,
642 g_param_spec_string (NM_DEVICE_WIMAX_HW_ADDRESS, "", "",
645 G_PARAM_STATIC_STRINGS));
648 * NMDeviceWimax:active-nsp:
650 * The active #NMWimaxNsp of the device.
652 * Deprecated: 1.2: WiMAX is no longer supported.
654 g_object_class_install_property
655 (object_class, PROP_ACTIVE_NSP,
656 g_param_spec_object (NM_DEVICE_WIMAX_ACTIVE_NSP, "", "",
659 G_PARAM_STATIC_STRINGS));
662 * NMDeviceWimax:center-frequency:
664 * The center frequency (in KHz) of the radio channel the device is using to
665 * communicate with the network when connected. Has no meaning when the
666 * device is not connected.
668 * Deprecated: 1.2: WiMAX is no longer supported.
670 g_object_class_install_property
671 (object_class, PROP_CENTER_FREQ,
672 g_param_spec_uint (NM_DEVICE_WIMAX_CENTER_FREQUENCY, "", "",
675 G_PARAM_STATIC_STRINGS));
678 * NMDeviceWimax:rssi:
680 * RSSI of the current radio link in dBm. This value indicates how strong
681 * the raw received RF signal from the base station is, but does not
682 * indicate the overall quality of the radio link. Has no meaning when the
683 * device is not connected.
685 * Deprecated: 1.2: WiMAX is no longer supported.
687 g_object_class_install_property
688 (object_class, PROP_RSSI,
689 g_param_spec_int (NM_DEVICE_WIMAX_RSSI, "", "",
690 G_MININT, G_MAXINT, 0,
692 G_PARAM_STATIC_STRINGS));
695 * NMDeviceWimax:cinr:
697 * CINR (Carrier to Interference + Noise Ratio) of the current radio link
698 * in dB. CINR is a more accurate measure of radio link quality. Has no
699 * meaning when the device is not connected.
701 * Deprecated: 1.2: WiMAX is no longer supported.
703 g_object_class_install_property
704 (object_class, PROP_CINR,
705 g_param_spec_int (NM_DEVICE_WIMAX_CINR, "", "",
706 G_MININT, G_MAXINT, 0,
708 G_PARAM_STATIC_STRINGS));
711 * NMDeviceWimax:tx-power:
713 * Average power of the last burst transmitted by the device, in units of
714 * 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of
715 * -5.5 dBm. Has no meaning when the device is not connected.
717 * Deprecated: 1.2: WiMAX is no longer supported.
719 g_object_class_install_property
720 (object_class, PROP_TX_POWER,
721 g_param_spec_int (NM_DEVICE_WIMAX_TX_POWER, "", "",
722 G_MININT, G_MAXINT, 0,
724 G_PARAM_STATIC_STRINGS));
727 * NMDeviceWimax:bsid:
729 * The ID of the serving base station as received from the network. Has
730 * no meaning when the device is not connected.
732 * Deprecated: 1.2: WiMAX is no longer supported.
734 g_object_class_install_property
735 (object_class, PROP_BSID,
736 g_param_spec_string (NM_DEVICE_WIMAX_BSID, "", "",
739 G_PARAM_STATIC_STRINGS));
742 * NMDeviceWimax:nsps:
744 * List of all WiMAX Network Service Providers the device can see.
747 * Deprecated: 1.2: WiMAX is no longer supported.
749 g_object_class_install_property
750 (object_class, PROP_NSPS,
751 g_param_spec_boxed (NM_DEVICE_WIMAX_NSPS, "", "",
752 NM_TYPE_OBJECT_ARRAY,
754 G_PARAM_STATIC_STRINGS));
759 * NMDeviceWimax::nsp-added:
760 * @self: the wimax device that received the signal
763 * Notifies that a #NMWimaxNsp is added to the wimax device.
765 * Deprecated: 1.2: WiMAX is no longer supported.
768 g_signal_new ("nsp-added",
769 G_OBJECT_CLASS_TYPE (object_class),
771 G_STRUCT_OFFSET (NMDeviceWimaxClass, nsp_added),
773 g_cclosure_marshal_VOID__OBJECT,
778 * NMDeviceWimax::nsp-removed:
779 * @self: the wimax device that received the signal
780 * @nsp: the removed NSP
782 * Notifies that a #NMWimaxNsp is removed from the wimax device.
784 * Deprecated: 1.2: WiMAX is no longer supported.
786 signals[NSP_REMOVED] =
787 g_signal_new ("nsp-removed",
788 G_OBJECT_CLASS_TYPE (object_class),
790 G_STRUCT_OFFSET (NMDeviceWimaxClass, nsp_removed),
792 g_cclosure_marshal_VOID__OBJECT,