static void clean_up_nsps (NMDeviceWimax *self, gboolean notify) { NMDeviceWimaxPrivate *priv; g_return_if_fail (NM_IS_DEVICE_WIMAX (self)); priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (priv->active_nsp) { g_object_unref (priv->active_nsp); priv->active_nsp = NULL; } if (priv->nsps) { while (priv->nsps->len) { NMWimaxNsp *nsp = NM_WIMAX_NSP (g_ptr_array_index (priv->nsps, 0)); if (notify) g_signal_emit (self, signals[NSP_REMOVED], 0, nsp); g_ptr_array_remove (priv->nsps, nsp); g_object_unref (nsp); } g_ptr_array_free (priv->nsps, TRUE); priv->nsps = NULL; } }
static void dispose (GObject *object) { NMDeviceWimax *self = NM_DEVICE_WIMAX (object); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (priv->disposed) goto done; priv->disposed = TRUE; clear_activation_timeout (self); clear_link_timeout (self); clear_connected_poll (self); if (priv->sdk_action_defer_id) g_source_remove (priv->sdk_action_defer_id); if (priv->sdk) { iwmx_sdk_set_callbacks (priv->sdk, NULL, NULL, NULL, NULL, NULL, NULL); wmxsdk_unref (priv->sdk); } g_free (priv->bsid); set_current_nsp (self, NULL); g_slist_free_full (priv->nsp_list, g_object_unref); iwmx_sdk_new_callback_unregister (wmx_new_sdk_cb, self); nm_wimax_util_sdk_unref (); done: G_OBJECT_CLASS (nm_device_wimax_parent_class)->dispose (object); }
/** * nm_device_wimax_get_hw_address: * @wimax: a #NMDeviceWimax * * Gets the hardware (MAC) address of the #NMDeviceWimax * * Returns: the hardware address. This is the internal string used by the * device, and must not be modified. * * Deprecated: 1.2: WiMAX is no longer supported. **/ const char * nm_device_wimax_get_hw_address (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address); }
static void wmx_new_sdk_cb (struct wmxsdk *sdk, void *user_data) { NMDeviceWimax *self = NM_DEVICE_WIMAX (user_data); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); /* We only track one wmxsdk at a time because the WiMAX SDK is pretty stupid */ if (priv->sdk) { nm_log_dbg (LOGD_WIMAX, "(%s): WiMAX interface already known", sdk->ifname); return; } nm_log_dbg (LOGD_WIMAX, "(%s): new WiMAX interface (%s)", sdk->ifname, sdk->name); /* Now that we have an SDK, schedule an idle handler to start the device up */ priv->sdk = wmxsdk_ref (sdk); iwmx_sdk_set_callbacks(priv->sdk, wmx_state_change_cb, wmx_media_status_cb, wmx_connect_result_cb, wmx_scan_result_cb, wmx_removed_cb, self); iwmx_sdk_set_fast_reconnect_enabled (priv->sdk, 0); if (!priv->sdk_action_defer_id) priv->sdk_action_defer_id = g_idle_add (sdk_action_defer_cb, self); }
/** * nm_device_wimax_get_nsps: * @wimax: a #NMDeviceWimax * * Gets all the scanned NSPs of the #NMDeviceWimax. * * Returns: (element-type NMWimaxNsp): a #GPtrArray containing * all the scanned #NMWimaxNsps. * The returned array is owned by the client and should not be modified. * * Deprecated: 1.2: WiMAX is no longer supported. **/ const GPtrArray * nm_device_wimax_get_nsps (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps; }
static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMDeviceState state; state = nm_device_get_state (device); switch (state) { case NM_DEVICE_STATE_UNKNOWN: case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: case NM_DEVICE_STATE_DISCONNECTED: case NM_DEVICE_STATE_FAILED: if (priv->active_nsp) { g_object_unref (priv->active_nsp); priv->active_nsp = NULL; } _nm_object_queue_notify (NM_OBJECT (device), NM_DEVICE_WIMAX_ACTIVE_NSP); clear_link_status (self); break; case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: clear_link_status (self); break; default: break; } }
/** * nm_device_wimax_get_center_frequency: * @self: a #NMDeviceWimax * * Gets the center frequency (in KHz) of the radio channel the device is using * to communicate with the network when connected. Has no meaning when the * device is not connected. * * Returns: the center frequency in KHz, or 0 * * Deprecated: 1.2: WiMAX is no longer supported. **/ guint nm_device_wimax_get_center_frequency (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->center_freq; }
static NMActStageReturn real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); NMActRequest *req; GSList *iter; const char *path; clear_link_timeout (NM_DEVICE_WIMAX (device)); req = nm_device_get_act_request (device); if (!req) goto err; path = nm_act_request_get_specific_object (req); if (!path) goto err; for (iter = priv->nsp_list; iter; iter = iter->next) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); if (!strcmp (path, nm_wimax_nsp_get_dbus_path (nsp))) { set_current_nsp (NM_DEVICE_WIMAX (device), nsp); return NM_ACT_STAGE_RETURN_SUCCESS; } } err: *reason = NM_DEVICE_STATE_REASON_NONE; return NM_ACT_STAGE_RETURN_FAILURE; }
static NMActStageReturn real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); NMConnection *connection; NMSettingWimax *s_wimax; const char *nsp; int ret; connection = nm_act_request_get_connection (nm_device_get_act_request (device)); g_assert (connection); s_wimax = NM_SETTING_WIMAX (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX)); g_assert (s_wimax); nsp = nm_setting_wimax_get_network_name (s_wimax); g_assert (nsp); priv->connect_failed = FALSE; ret = iwmx_sdk_connect (priv->sdk, nsp); if (ret < 0 && ret != -EINPROGRESS) { nm_log_err (LOGD_WIMAX, "(%s): failed to connect to NSP '%s'", nm_device_get_iface (device), nsp); *reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED; return NM_ACT_STAGE_RETURN_FAILURE; } /* FIXME: Is 40 seconds good estimation? I have no idea */ priv->activation_timeout_id = g_timeout_add_seconds (40, activation_timed_out, device); return NM_ACT_STAGE_RETURN_POSTPONE; }
static void real_update_hw_address (NMDevice *dev) { NMDeviceWimax *self = NM_DEVICE_WIMAX (dev); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); struct ifreq req; int fd; const char *iface; iface = nm_device_get_iface (dev); fd = socket (PF_INET, SOCK_DGRAM, 0); if (fd < 0) { nm_log_warn (LOGD_HW, "(%s): couldn't open control socket.", iface); return; } memset (&req, 0, sizeof (struct ifreq)); strncpy (req.ifr_name, nm_device_get_iface (dev), IFNAMSIZ); errno = 0; if (ioctl (fd, SIOCGIFHWADDR, &req) < 0) { nm_log_err (LOGD_HW | LOGD_WIMAX, "(%s): failed to read hardware address (error %d)", iface, errno); } else { memcpy (&priv->hw_addr, &req.ifr_hwaddr.sa_data, ETH_ALEN); g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_HW_ADDRESS); } close (fd); }
NMWimaxNsp * nm_device_wimax_get_active_nsp (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->current_nsp; }
static void set_current_nsp (NMDeviceWimax *self, NMWimaxNsp *new_nsp) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMWimaxNsp *old_nsp; char *old_path = NULL; old_nsp = priv->current_nsp; if (old_nsp) { old_path = g_strdup (nm_wimax_nsp_get_dbus_path (old_nsp)); priv->current_nsp = NULL; } if (new_nsp) priv->current_nsp = g_object_ref (new_nsp); if (old_nsp) g_object_unref (old_nsp); /* Only notify if it's really changed */ if ( (!old_path && new_nsp) || (old_path && !new_nsp) || (old_path && new_nsp && strcmp (old_path, nm_wimax_nsp_get_dbus_path (new_nsp)))) g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_ACTIVE_NSP); g_free (old_path); }
static void device_state_changed (NMDevice *device, NMDeviceState new_state, NMDeviceState old_state, NMDeviceStateReason reason, gpointer user_data) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (new_state < NM_DEVICE_STATE_DISCONNECTED) remove_all_nsps (self); /* Request initial NSP list */ if ( new_state == NM_DEVICE_STATE_DISCONNECTED && old_state < NM_DEVICE_STATE_DISCONNECTED) { if (priv->sdk) iwmx_sdk_get_networks (priv->sdk); } if (new_state == NM_DEVICE_STATE_FAILED || new_state <= NM_DEVICE_STATE_DISCONNECTED) clear_activation_timeout (self); if (new_state == NM_DEVICE_STATE_ACTIVATED) { /* poll link quality and BSID */ clear_connected_poll (self); priv->poll_id = g_timeout_add_seconds (10, connected_poll_cb, self); connected_poll_cb (self); } else { clear_link_timeout (self); clear_connected_poll (self); set_link_status (self, NULL); } }
static void nm_device_wimax_init (NMDeviceWimax *self) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); priv->status = WIMAX_API_DEVICE_STATUS_UnInitialized; }
static void set_current_nsp (NMDeviceWimax *self, NMWimaxNsp *new_nsp) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMWimaxNsp *old_nsp; gboolean path_changed = FALSE; old_nsp = priv->current_nsp; priv->current_nsp = NULL; if (new_nsp) priv->current_nsp = g_object_ref (new_nsp); if (old_nsp && new_nsp) { path_changed = (g_strcmp0 (nm_wimax_nsp_get_dbus_path (old_nsp), nm_wimax_nsp_get_dbus_path (new_nsp)) != 0); } /* Only notify if it's really changed */ if (old_nsp != new_nsp || path_changed) g_object_notify (G_OBJECT (self), NM_DEVICE_WIMAX_ACTIVE_NSP); if (old_nsp) g_object_unref (old_nsp); }
/** * nm_device_wimax_get_active_nsp: * @wimax: a #NMDeviceWimax * * Gets the active #NMWimaxNsp. * * Returns: (transfer full): the access point or %NULL if none is active * * Deprecated: 1.2: WiMAX is no longer supported. **/ NMWimaxNsp * nm_device_wimax_get_active_nsp (NMDeviceWimax *wimax) { NMDeviceState state; g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); state = nm_device_get_state (NM_DEVICE (wimax)); switch (state) { case NM_DEVICE_STATE_PREPARE: case NM_DEVICE_STATE_CONFIG: case NM_DEVICE_STATE_NEED_AUTH: case NM_DEVICE_STATE_IP_CONFIG: case NM_DEVICE_STATE_IP_CHECK: case NM_DEVICE_STATE_SECONDARIES: case NM_DEVICE_STATE_ACTIVATED: case NM_DEVICE_STATE_DEACTIVATING: break; default: return NULL; break; } return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->active_nsp; }
/** * nm_device_wimax_get_bsid: * @self: a #NMDeviceWimax * * Gets the ID of the serving Base Station when the device is connected. * * Returns: the ID of the serving Base Station, or %NULL * * Deprecated: 1.2: WiMAX is no longer supported. **/ const char * nm_device_wimax_get_bsid (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL); return nm_str_not_empty (NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid); }
/** * nm_device_wimax_get_tx_power: * @self: a #NMDeviceWimax * * Average power of the last burst transmitted by the device, in units of * 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of * -5.5 dBm. Has no meaning when the device is not connected. * * Returns: the TX power in dBm, or 0 * * Deprecated: 1.2: WiMAX is no longer supported. **/ gint nm_device_wimax_get_tx_power (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->tx_power; }
static gboolean is_available (NMDevice *device) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device); const char *iface = nm_device_get_iface (device); if (!priv->enabled) { nm_log_dbg (LOGD_WIMAX, "(%s): not available because not enabled", iface); return FALSE; } if (!priv->wimaxd_enabled) { nm_log_dbg (LOGD_WIMAX, "(%s): not available because not enabled in wimaxd", iface); return FALSE; } if (!nm_wimax_util_sdk_is_initialized ()) { nm_log_dbg (LOGD_WIMAX, "(%s): not available because WiMAX SDK not initialized", iface); return FALSE; } if (!priv->sdk) { nm_log_dbg (LOGD_WIMAX, "(%s): not available because not known to WiMAX SDK", iface); return FALSE; } return iwmxsdk_status_get (priv->sdk) >= WIMAX_API_DEVICE_STATUS_Ready; }
static void set_enabled (NMDevice *device, gboolean enabled) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); gboolean old_available; int ret; const char *iface; iface = nm_device_get_iface (NM_DEVICE (self)); nm_log_dbg (LOGD_WIMAX, "(%s): setting radio enabled %d -> %d", iface, priv->enabled, enabled); if (priv->enabled == enabled) return; old_available = nm_device_is_available (NM_DEVICE (device)); priv->enabled = enabled; nm_log_dbg (LOGD_WIMAX, "(%s): radio now %s", iface, priv->enabled ? "enabled" : "disabled"); /* Set the WiMAX device RF state to the current user-specified enabled state */ if (priv->sdk) { ret = iwmx_sdk_rf_state_set (priv->sdk, enabled ? WIMAX_API_RF_ON : WIMAX_API_RF_OFF); if (ret < 0 && ret != -EINPROGRESS) { nm_log_warn (LOGD_WIMAX, "(%s): failed to %s radio", iface, priv->enabled ? "enable" : "disable"); } } update_availability (self, old_available); }
static void clear_link_status (NMDeviceWimax *self) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (priv->center_freq) { priv->center_freq = 0; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CENTER_FREQUENCY); } if (priv->rssi) { priv->rssi = 0; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_RSSI); } if (priv->cinr) { priv->cinr = 0; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_CINR); } if (priv->tx_power) { priv->tx_power = 0; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_TX_POWER); } if (priv->bsid) { g_free (priv->bsid); priv->bsid = NULL; _nm_object_queue_notify (NM_OBJECT (self), NM_DEVICE_WIMAX_BSID); } }
/** * nm_device_wimax_get_bsid: * @self: a #NMDeviceWimax * * Gets the ID of the serving Base Station when the device is connected. * * Returns: the ID of the serving Base Station, or %NULL * * Deprecated: 1.2: WiMAX is no longer supported. **/ const char * nm_device_wimax_get_bsid (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), NULL); _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->bsid; }
/** * nm_device_wimax_get_tx_power: * @self: a #NMDeviceWimax * * Average power of the last burst transmitted by the device, in units of * 0.5 dBm. i.e. a TxPower of -11 represents an actual device TX power of * -5.5 dBm. Has no meaning when the device is not connected. * * Returns: the TX power in dBm, or 0 * * Deprecated: 1.2: WiMAX is no longer supported. **/ gint nm_device_wimax_get_tx_power (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->tx_power; }
/** * nm_device_wimax_get_nsps: * @wimax: a #NMDeviceWimax * * Gets all the scanned NSPs of the #NMDeviceWimax. * * Returns: (element-type NMWimaxNsp): a #GPtrArray containing * all the scanned #NMWimaxNsps. * The returned array is owned by the client and should not be modified. * * Deprecated: 1.2: WiMAX is no longer supported. **/ const GPtrArray * nm_device_wimax_get_nsps (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); _nm_object_ensure_inited (NM_OBJECT (wimax)); return handle_ptr_array_return (NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->nsps); }
/** * nm_device_wimax_get_hw_address: * @wimax: a #NMDeviceWimax * * Gets the hardware (MAC) address of the #NMDeviceWimax * * Returns: the hardware address. This is the internal string used by the * device, and must not be modified. * * Deprecated: 1.2: WiMAX is no longer supported. **/ const char * nm_device_wimax_get_hw_address (NMDeviceWimax *wimax) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (wimax), NULL); _nm_object_ensure_inited (NM_OBJECT (wimax)); return NM_DEVICE_WIMAX_GET_PRIVATE (wimax)->hw_address; }
/** * nm_device_wimax_get_center_frequency: * @self: a #NMDeviceWimax * * Gets the center frequency (in KHz) of the radio channel the device is using * to communicate with the network when connected. Has no meaning when the * device is not connected. * * Returns: the center frequency in KHz, or 0 * * Deprecated: 1.2: WiMAX is no longer supported. **/ guint nm_device_wimax_get_center_frequency (NMDeviceWimax *self) { g_return_val_if_fail (NM_IS_DEVICE_WIMAX (self), 0); _nm_object_ensure_inited (NM_OBJECT (self)); return NM_DEVICE_WIMAX_GET_PRIVATE (self)->center_freq; }
static gboolean sdk_action_defer_cb (gpointer user_data) { NMDeviceWimax *self = NM_DEVICE_WIMAX (user_data); gboolean old_available = nm_device_is_available (NM_DEVICE (self)); NM_DEVICE_WIMAX_GET_PRIVATE (self)->sdk_action_defer_id = 0; update_availability (self, old_available); return FALSE; }
static void clear_link_timeout (NMDeviceWimax *self) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (priv->link_timeout_id) { g_source_remove (priv->link_timeout_id); priv->link_timeout_id = 0; } }
static gboolean activation_timed_out (gpointer data) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (data); priv->activation_timeout_id = 0; nm_device_state_changed (NM_DEVICE (data), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return FALSE; }
static void clear_connected_poll (NMDeviceWimax *self) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); if (priv->poll_id) { g_source_remove (priv->poll_id); priv->poll_id = 0; } }