static GObject* constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; NMModemPrivate *priv; object = G_OBJECT_CLASS (nm_modem_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_MODEM_GET_PRIVATE (object); if (!priv->data_port && !priv->control_port) { nm_log_err (LOGD_HW, "neither modem command nor data interface provided"); goto err; } if (!priv->path) { nm_log_err (LOGD_HW, "D-Bus path not provided"); goto err; } return object; err: g_object_unref (object); return NULL; }
static void force_disconnect (NMDeviceWimax *self, struct wmxsdk *sdk) { WIMAX_API_DEVICE_STATUS status; int ret; const char *iface; g_return_if_fail (sdk != NULL); iface = nm_device_get_iface (NM_DEVICE (self)); status = iwmxsdk_status_get (sdk); if ((int) status < 0) { nm_log_err (LOGD_WIMAX, "(%s): failed to read WiMAX device status: %d", iface, status); return; } if ( status == WIMAX_API_DEVICE_STATUS_Connecting || status == WIMAX_API_DEVICE_STATUS_Data_Connected) { nm_log_dbg (LOGD_WIMAX, "(%s): requesting disconnect", iface); ret = iwmx_sdk_disconnect (sdk); if (ret < 0 && ret != -EINPROGRESS) { nm_log_err (LOGD_WIMAX, "(%s): failed to disconnect WiMAX device: %d", iface, ret); } } }
gboolean nm_team_update_slave_connection (NMDevice *slave, NMConnection *connection) { NMSettingTeamPort *s_port; const char *iface = nm_device_get_iface (slave); char *port_config = NULL; gboolean with_teamdctl = FALSE; int err = 0; #if WITH_TEAMDCTL const char *master_iface; int master_ifindex; struct teamdctl *tdc; const char *team_port_config = NULL; #endif g_return_val_if_fail (NM_IS_DEVICE (slave), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); #if WITH_TEAMDCTL master_ifindex = nm_platform_link_get_master (nm_device_get_ifindex (slave)); g_assert (master_ifindex > 0); master_iface = nm_platform_link_get_name (master_ifindex); g_assert (master_iface); tdc = teamdctl_alloc (); g_assert (tdc); err = teamdctl_connect (tdc, master_iface, NULL, NULL); if (err) { nm_log_err (LOGD_TEAM, "(%s): failed to connect to teamd for master %s (err=%d)", iface, master_iface, err); teamdctl_free (tdc); return FALSE; } err = teamdctl_port_config_get_raw_direct (tdc, iface, (char **)&team_port_config); port_config = g_strdup (team_port_config); teamdctl_free (tdc); with_teamdctl = TRUE; #endif s_port = nm_connection_get_setting_team_port (connection); if (!s_port) { s_port = (NMSettingTeamPort *) nm_setting_team_port_new (); nm_connection_add_setting (connection, NM_SETTING (s_port)); } g_object_set (G_OBJECT (s_port), NM_SETTING_TEAM_PORT_CONFIG, port_config, NULL); g_free (port_config); if (!with_teamdctl || err != 0) { if (!with_teamdctl) nm_log_err (LOGD_TEAM, "(%s): failed to read teamd port configuration " " (compiled without libteamdctl support)", iface); else nm_log_err (LOGD_TEAM, "(%s): failed to read teamd port configuration (err=%d)", iface, err); return FALSE; } return TRUE; }
/* * If the device is connected but we don't know about the network, * create the knowledge of it. * * Asks the WiMAX API to report which NSP we are connected to and we * create/update a network_el in the device's network list. Then * return it. * * Returns NULL on error. * */ WIMAX_API_CONNECTED_NSP_INFO_EX *iwmx_sdk_get_connected_network(struct wmxsdk *wmxsdk) { WIMAX_API_CONNECTED_NSP_INFO_EX *nsp_info = NULL; WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); nsp_info = malloc(sizeof (*nsp_info)); if (!nsp_info) { nm_log_err(LOGD_WIMAX, "wmxsdk: cannot allocate NSP info"); return NULL; } r = GetConnectedNSPEx(&wmxsdk->device_id, nsp_info); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot get connected NSP info: %d (%s)", r, errstr); free (nsp_info); nsp_info = NULL; } else { /* Migth be 0 sometimes; fix that up */ if (nsp_info->linkQuality == 0) { int linkq_expected = cinr_to_percentage(nsp_info->CINR - 10); if (linkq_expected != nsp_info->linkQuality) nsp_info->linkQuality = linkq_expected; } } return nsp_info; }
/* * Asks the WiMAX API to report current link statistics. * * Returns NULL on error. * */ WIMAX_API_LINK_STATUS_INFO_EX *iwmx_sdk_get_link_status_info(struct wmxsdk *wmxsdk) { WIMAX_API_LINK_STATUS_INFO_EX *stats = NULL; WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); /* Only report if connected */ if (iwmxsdk_status_get(wmxsdk) < WIMAX_API_DEVICE_STATUS_Connecting) { nm_log_err(LOGD_WIMAX, "wmxsdk: cannot get link status info unless connected"); return NULL; } stats = malloc(sizeof (*stats)); if (!stats) { nm_log_err(LOGD_WIMAX, "wmxsdk: cannot allocate links status info"); return NULL; } r = GetLinkStatusEx(&wmxsdk->device_id, stats); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot get link status info: %d (%s)", r, errstr); free (stats); stats = NULL; } return stats; }
static void iwmx_sdk_addremove_cb(WIMAX_API_DEVICE_ID *devid, BOOL presence) { unsigned int cnt; WIMAX_API_RET r; WIMAX_API_HW_DEVICE_ID device_id_list[5]; UINT32 device_id_list_size = ARRAY_SIZE(device_id_list); char errstr[512]; UINT32 errstr_size = sizeof(errstr); g_mutex_lock(&add_remove_mutex); nm_log_dbg(LOGD_WIMAX, "cb: handle %u index #%u is %d", devid->sdkHandle, devid->deviceIndex, presence); r = GetListDevice(devid, device_id_list, &device_id_list_size); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(devid, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot obtain list of devices: %d (%s)", r, errstr); goto out; } if (device_id_list_size == 0) { nm_log_dbg(LOGD_WIMAX, "No WiMAX devices reported"); } else { for (cnt = 0; cnt < device_id_list_size; cnt++) { WIMAX_API_HW_DEVICE_ID *dev = device_id_list + cnt; nm_log_dbg(LOGD_WIMAX, "#%u index #%u device %s", cnt, dev->deviceIndex, dev->deviceName); } } if (presence) { WIMAX_API_HW_DEVICE_ID *dev; /* Make sure the wimax NS isn't lying to us */ if (device_id_list_size < devid->deviceIndex) { nm_log_err(LOGD_WIMAX, "wmxsdk: changed device (%u) not in the list? (%u items)", devid->deviceIndex, device_id_list_size); goto out; } /* Add the device to our internal list */ dev = device_id_list + devid->deviceIndex; iwmx_sdk_dev_add(devid->deviceIndex, dev->deviceIndex, dev->deviceName); } else { /* Remove the device from our internal list */ int idx = deviceid_to_index(devid); if (idx >= 0) iwmx_sdk_dev_rm(idx); } out: g_mutex_unlock(&add_remove_mutex); }
/* * Initialize the WiMAX API, register with it, setup callbacks for * device coming up / dissapearing */ int iwmx_sdk_api_init(void) { int result; unsigned int cnt; WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); WIMAX_API_HW_DEVICE_ID device_id_list[5]; UINT32 device_id_list_size = ARRAY_SIZE(device_id_list); memset(&g_api, 0, sizeof(g_api)); g_api.privilege = WIMAX_API_PRIVILEGE_READ_WRITE; result = -EIO; r = WiMaxAPIOpen(&g_api); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&g_api, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: WiMaxAPIOpen failed with %d (%s)", r, errstr); goto error_wimaxapiopen; } r = SubscribeDeviceInsertRemove(&g_api, iwmx_sdk_addremove_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&g_api, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: insert/remove subscribe failed with %d (%s)", r, errstr); goto error_close; } r = GetListDevice(&g_api, device_id_list, &device_id_list_size); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&g_api, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot obtain list of devices: %d (%s)", r, errstr); goto error_close; } if (device_id_list_size < g_api.deviceIndex) { nm_log_err(LOGD_WIMAX, "wmxsdk: changed device (%u) not in the list? (%u items)", g_api.deviceIndex, device_id_list_size); } if (device_id_list_size == 0) { nm_log_dbg(LOGD_WIMAX, "No WiMAX devices reported"); } else { for (cnt = 0; cnt < device_id_list_size; cnt++) { WIMAX_API_HW_DEVICE_ID *dev = device_id_list + cnt; nm_log_dbg(LOGD_WIMAX, "#%u index #%u device %s", cnt, dev->deviceIndex, dev->deviceName); iwmx_sdk_dev_add(cnt, dev->deviceIndex, dev->deviceName); } } return 0; error_close: WiMaxAPIClose(&g_api); error_wimaxapiopen: return result; }
static NMIP6Device * nm_ip6_device_new (NMIP6Manager *manager, int ifindex, const guint8 *hwaddr, guint hwaddr_len) { NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager); NMIP6Device *device; g_return_val_if_fail (ifindex > 0, NULL); g_return_val_if_fail (hwaddr != NULL, NULL); g_return_val_if_fail (hwaddr_len > 0, NULL); g_return_val_if_fail (hwaddr_len <= NM_UTILS_HWADDR_LEN_MAX, NULL); device = g_slice_new0 (NMIP6Device); if (!device) { nm_log_err (LOGD_IP6, "(%d): out of memory creating IP6 addrconf object.", ifindex); return NULL; } device->ifindex = ifindex; device->iface = nm_netlink_index_to_iface (ifindex); if (!device->iface) { nm_log_err (LOGD_IP6, "(%d): could not find interface name from index.", ifindex); goto error; } memcpy (device->hwaddr, hwaddr, hwaddr_len); device->hwaddr_len = hwaddr_len; device->manager = manager; device->rdnss_servers = g_array_new (FALSE, FALSE, sizeof (NMIP6RDNSS)); device->dnssl_domains = g_array_new (FALSE, FALSE, sizeof (NMIP6DNSSL)); g_hash_table_replace (priv->devices, GINT_TO_POINTER (device->ifindex), device); /* and the original value of IPv6 enable/disable */ device->disable_ip6_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/disable_ipv6", device->iface); g_assert (device->disable_ip6_path); device->disable_ip6_save_valid = nm_utils_get_proc_sys_net_value_with_bounds (device->disable_ip6_path, device->iface, &device->disable_ip6_save, 0, 1); return device; error: nm_ip6_device_destroy (device); return NULL; }
/* Register our service on the bus; shouldn't be called until * all necessary message handlers have been registered, because * when we register on the bus, clients may start to call. */ gboolean nm_dbus_manager_start_service (NMDBusManager *self) { NMDBusManagerPrivate *priv; int result; GError *err = NULL; g_return_val_if_fail (NM_IS_DBUS_MANAGER (self), FALSE); priv = NM_DBUS_MANAGER_GET_PRIVATE (self); if (priv->started) { nm_log_err (LOGD_CORE, "Service has already started."); return FALSE; } if (!dbus_g_proxy_call (priv->proxy, "RequestName", &err, G_TYPE_STRING, NM_DBUS_SERVICE, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service.\n" " Error: '%s'", (err && err->message) ? err->message : "(unknown)"); g_error_free (err); return FALSE; } if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { nm_log_err (LOGD_CORE, "Could not acquire the NetworkManager service as it is already taken."); return FALSE; } if (!dbus_g_proxy_call (priv->proxy, "RequestName", &err, G_TYPE_STRING, NM_DBUS_SERVICE_SYSTEM_SETTINGS, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { nm_log_warn (LOGD_CORE, "Could not acquire the NetworkManagerSystemSettings service.\n" " Message: '%s'", err->message); g_error_free (err); return FALSE; } if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { nm_log_warn (LOGD_CORE, "Could not acquire the NetworkManagerSystemSettings service " "as it is already taken."); return FALSE; } priv->started = TRUE; return priv->started; }
static void iwmx_sdk_dev_add(unsigned idx, unsigned api_idx, const char *name) { struct wmxsdk *wmxsdk; const char *s; if (idx >= IWMX_SDK_DEV_MAX) { nm_log_err(LOGD_WIMAX, "BUG! idx (%u) >= IWMX_SDK_DEV_MAX (%u)", idx, IWMX_SDK_DEV_MAX); return; } if (g_iwmx_sdk_devs[idx] != NULL) { nm_log_err(LOGD_WIMAX, "BUG! device index %u already enumerated?", idx); return; } wmxsdk = wmxsdk_new(); if (wmxsdk == NULL) { nm_log_err(LOGD_WIMAX, "Can't allocate %zu bytes", sizeof(*wmxsdk)); return; } /* * This depends on a hack in the WiMAX Network Service; it has * to return, as part of the device name, a string "if:IFNAME" * where the OS's device name is stored. */ s = strstr(name, "if:"); if (s == NULL || sscanf(s, "if:%15[^ \f\n\r\t\v]", wmxsdk->ifname) != 1) { nm_log_err(LOGD_WIMAX, "Cannot extract network interface name off '%s'", name); goto error; } nm_log_dbg(LOGD_WIMAX, "network interface name: '%s'", wmxsdk->ifname); strncpy(wmxsdk->name, name, sizeof(wmxsdk->name)); wmxsdk->device_id.privilege = WIMAX_API_PRIVILEGE_READ_WRITE; wmxsdk->device_id.deviceIndex = api_idx; if (iwmx_sdk_setup(wmxsdk) != 0) { nm_log_err(LOGD_WIMAX, "wxmsdk: %s: cannot set up interface", wmxsdk->ifname); goto error; } g_iwmx_sdk_devs[idx] = wmxsdk; /* Notify listeners of new devices */ iwmx_sdk_call_new_callbacks (wmxsdk); return; error: wmxsdk_unref(wmxsdk); return; }
/* * Disconnect from a network * * This function tells the device to disconnect; the state change * callback will take care of inform NetworkManager's internals. */ int iwmx_sdk_disconnect(struct wmxsdk *wmxsdk) { int result; WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); WIMAX_API_DEVICE_STATUS dev_status; g_mutex_lock(&wmxsdk->connect_mutex); /* Guess what the current radio state is; if it is ON * already, don't redo it. */ dev_status = iwmx_sdk_get_device_status(wmxsdk); if ((int) dev_status < 0) { result = dev_status; goto error_get_status; } switch (dev_status) { case WIMAX_API_DEVICE_STATUS_UnInitialized: nm_log_err(LOGD_WIMAX, "wmxsdk: SW BUG? HW is uninitialized"); result = -EINVAL; goto error_cant_do; case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW: case WIMAX_API_DEVICE_STATUS_RF_OFF_HW: case WIMAX_API_DEVICE_STATUS_RF_OFF_SW: nm_log_dbg(LOGD_WIMAX, "Cannot disconnect, radio is off; ignoring"); result = 0; goto error_cant_do; case WIMAX_API_DEVICE_STATUS_Ready: case WIMAX_API_DEVICE_STATUS_Scanning: nm_log_dbg(LOGD_WIMAX, "Cannot disconnect, already disconnected; ignoring"); result = 0; goto error_cant_do; case WIMAX_API_DEVICE_STATUS_Connecting: case WIMAX_API_DEVICE_STATUS_Data_Connected: break; default: g_assert(1); } /* Ok, flip the radio */ r = CmdDisconnectFromNetwork(&wmxsdk->device_id); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot disconnect from network: %d (%s)", r, errstr); result = -EIO; } else result = -EINPROGRESS; error_cant_do: error_get_status: g_mutex_unlock(&wmxsdk->connect_mutex); return result; }
static gboolean wifi_wext_set_mesh_ssid (WifiData *data, const guint8 *ssid, gsize len) { WifiDataWext *wext = (WifiDataWext *) data; struct iwreq wrq; char buf[IW_ESSID_MAX_SIZE + 1]; memset (buf, 0, sizeof (buf)); memcpy (buf, ssid, MIN (sizeof (buf) - 1, len)); wrq.u.essid.pointer = (caddr_t) buf; wrq.u.essid.length = len; wrq.u.essid.flags = (len > 0) ? 1 : 0; /* 1=enable SSID, 0=disable/any */ nm_utils_ifname_cpy (wrq.ifr_name, wext->parent.iface); if (ioctl (wext->fd, SIOCSIWESSID, &wrq) == 0) return TRUE; if (errno != ENODEV) { nm_log_err (LOGD_PLATFORM | LOGD_WIFI | LOGD_OLPC, "(%s): error setting SSID to '%s': %s", wext->parent.iface, ssid ? nm_utils_escape_ssid (ssid, len) : "(null)", strerror (errno)); } return FALSE; }
static void update_connection (NMDevice *device, NMConnection *connection) { NMSettingTeam *s_team = nm_connection_get_setting_team (connection); const char *iface = nm_device_get_iface (device); if (!s_team) { s_team = (NMSettingTeam *) nm_setting_team_new (); nm_connection_add_setting (connection, (NMSetting *) s_team); g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_INTERFACE_NAME, iface, NULL); } g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, NULL, NULL); #if WITH_TEAMDCTL if (ensure_teamd_connection (device)) { const char *config = NULL; int err; err = teamdctl_config_get_raw_direct (NM_DEVICE_TEAM_GET_PRIVATE (device)->tdc, (char **)&config); if (err == 0) g_object_set (G_OBJECT (s_team), NM_SETTING_TEAM_CONFIG, config, NULL); else nm_log_err (LOGD_TEAM, "(%s): failed to read teamd config (err=%d)", iface, err); } #endif }
/* * Called to ask the device to scan for networks * * We don't really scan as the WiMAX SDK daemon scans in the * background for us. We just get the results and hand them back via * the scan_result_cb callback. */ int iwmx_sdk_get_networks(struct wmxsdk *wmxsdk) { int result; UINT32 nsp_list_length = 10; WIMAX_API_NSP_INFO_EX nsp_list[10]; /* FIXME: up to 32? */ WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); r = GetNetworkListEx(&wmxsdk->device_id, nsp_list, &nsp_list_length); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot get network list: %d (%s)", r, errstr); result = -EIO; goto error_scan; } if (nsp_list_length == 0) { nm_log_dbg(LOGD_WIMAX, "no networks"); } else __iwmx_sdk_scan_common_cb(&wmxsdk->device_id, nsp_list, nsp_list_length); result = 0; error_scan: return result; }
static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object); switch (prop_id) { case PROP_HW_ADDRESS: /* Construct only */ priv->bdaddr = g_ascii_strup (g_value_get_string (value), -1); if (!nm_utils_hwaddr_aton (priv->bdaddr, ARPHRD_ETHER, &priv->hw_addr)) nm_log_err (LOGD_HW, "Failed to convert BT address '%s'", priv->bdaddr); break; case PROP_BT_NAME: /* Construct only */ priv->name = g_value_dup_string (value); break; case PROP_BT_CAPABILITIES: /* Construct only */ priv->capabilities = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void init_auditd (NMAuditManager *self) { NMAuditManagerPrivate *priv = NM_AUDIT_MANAGER_GET_PRIVATE (self); NMConfigData *data = nm_config_get_data (priv->config); if (nm_config_data_get_value_boolean (data, NM_CONFIG_KEYFILE_GROUP_LOGGING, NM_CONFIG_KEYFILE_KEY_AUDIT, NM_CONFIG_DEFAULT_LOGGING_AUDIT)) { if (priv->auditd_fd < 0) { priv->auditd_fd = audit_open (); if (priv->auditd_fd < 0) { nm_log_err (LOGD_CORE, "failed to open auditd socket: %s", strerror (errno)); } else nm_log_dbg (LOGD_CORE, "audit socket created"); } } else { if (priv->auditd_fd >= 0) { audit_close (priv->auditd_fd); priv->auditd_fd = -1; nm_log_dbg (LOGD_CORE, "audit socket closed"); } } }
static gboolean run_check (gpointer user_data) { NMConnectivity *self = NM_CONNECTIVITY (user_data); NMConnectivityPrivate *priv; SoupURI *soup_uri; SoupMessage *msg; g_return_val_if_fail (NM_IS_CONNECTIVITY (self), FALSE); priv = NM_CONNECTIVITY_GET_PRIVATE (self); /* check given url async */ soup_uri = soup_uri_new (priv->uri); if (soup_uri && SOUP_URI_VALID_FOR_HTTP (soup_uri)) { msg = soup_message_new_from_uri ("GET", soup_uri); soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT); soup_session_queue_message (priv->soup_session, msg, nm_connectivity_check_cb, self); priv->running = TRUE; g_object_notify (G_OBJECT (self), NM_CONNECTIVITY_RUNNING); nm_log_dbg (LOGD_CORE, "Connectivity check with uri '%s' started.", priv->uri); } else nm_log_err (LOGD_CORE, "Invalid uri '%s' for connectivity check.", priv->uri); if (soup_uri) soup_uri_free (soup_uri); return TRUE; /* keep firing */ }
static GByteArray * wifi_wext_get_ssid (WifiData *data) { WifiDataWext *wext = (WifiDataWext *) data; struct iwreq wrq; char ssid[IW_ESSID_MAX_SIZE + 2]; guint32 len; GByteArray *array = NULL; memset (ssid, 0, sizeof (ssid)); wrq.u.essid.pointer = (caddr_t) &ssid; wrq.u.essid.length = sizeof (ssid); wrq.u.essid.flags = 0; strncpy (wrq.ifr_name, wext->parent.iface, IFNAMSIZ); if (ioctl (wext->fd, SIOCGIWESSID, &wrq) < 0) { nm_log_err (LOGD_HW | LOGD_WIFI, "(%s): couldn't get SSID: %d", wext->parent.iface, errno); return NULL; } len = wrq.u.essid.length; if (nm_utils_is_empty_ssid ((guint8 *) ssid, len) == FALSE) { array = g_byte_array_sized_new (len); g_byte_array_append (array, (const guint8 *) ssid, len); } return array; }
void nm_ap_export_to_dbus (NMAccessPoint *ap) { NMAccessPointPrivate *priv; NMDBusManager *mgr; DBusGConnection *g_connection; static guint32 counter = 0; g_return_if_fail (NM_IS_AP (ap)); priv = NM_AP_GET_PRIVATE (ap); if (priv->dbus_path) { nm_log_err (LOGD_CORE, "Tried to export AP %s twice.", priv->dbus_path); return; } mgr = nm_dbus_manager_get (); g_assert (mgr); g_connection = nm_dbus_manager_get_connection (mgr); g_assert (g_connection); priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++); dbus_g_connection_register_g_object (g_connection, priv->dbus_path, G_OBJECT (ap)); g_object_unref (mgr); }
static gboolean ethtool_get (const char *name, gpointer edata) { struct ifreq ifr; int fd; if (!name || !*name) return FALSE; if (!nmp_utils_device_exists (name)) return FALSE; /* nmp_utils_device_exists() already errors out if @name is invalid. */ nm_assert (strlen (name) < IFNAMSIZ); memset (&ifr, 0, sizeof (ifr)); nm_utils_ifname_cpy (ifr.ifr_name, name); ifr.ifr_data = edata; fd = socket (PF_INET, SOCK_DGRAM, 0); if (fd < 0) { nm_log_err (LOGD_PLATFORM, "ethtool: Could not open socket."); return FALSE; } if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) { nm_log_dbg (LOGD_PLATFORM, "ethtool: Request failed: %s", strerror (errno)); close (fd); return FALSE; } close (fd); return TRUE; }
NMIP4Config * nm_dhcp_manager_test_ip4_options_to_config (const char *dhcp_client, const char *iface, GHashTable *options, const char *reason) { NMDHCPClient *client; NMIP4Config *config; GType client_type; GError *error = NULL; client_type = get_client_type (dhcp_client, &error); if (!client_type) { nm_log_err (LOGD_DHCP4, "error: %s", error ? error->message : "(unknown)"); g_clear_error (&error); return NULL; } client = (NMDHCPClient *) g_object_new (client_type, NM_DHCP_CLIENT_INTERFACE, iface, NULL); g_return_val_if_fail (client != NULL, NULL); nm_dhcp_client_new_options (client, options, reason); config = nm_dhcp_client_get_ip4_config (client, TRUE); g_object_unref (client); return config; }
static void interface_get_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; gs_unref_variant GVariant *variant = NULL; gs_free_error GError *error = NULL; const char *path; variant = _nm_dbus_proxy_call_finish (proxy, result, G_VARIANT_TYPE ("(o)"), &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) return; self = NM_SUPPLICANT_INTERFACE (user_data); priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (variant) { g_variant_get (variant, "(&o)", &path); interface_add_done (self, path); } else { g_dbus_error_strip_remote_error (error); nm_log_err (LOGD_SUPPLICANT, "(%s): error getting interface: %s", priv->dev, error->message); set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN); } }
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); }
static gboolean ck_load_cache (GHashTable *cache) { GKeyFile *keyfile = g_key_file_new (); char **groups = NULL; GError *error = NULL; gsize i, len; gboolean finished = FALSE; if (!g_key_file_load_from_file (keyfile, CKDB_PATH, G_KEY_FILE_NONE, &error)) goto out; if (!(groups = g_key_file_get_groups (keyfile, &len))) { nm_log_err (LOGD_CORE, "Could not load groups from " CKDB_PATH); goto out; } g_hash_table_remove_all (cache); for (i = 0; i < len; i++) { guint uid = G_MAXUINT; CkSession session = { .active = FALSE }; if (!g_str_has_prefix (groups[i], "CkSession ")) continue; uid = g_key_file_get_integer (keyfile, groups[i], "uid", &error); if (error) goto out; session.active = g_key_file_get_boolean (keyfile, groups[i], "is_active", &error); if (error) goto out; g_hash_table_insert (cache, GUINT_TO_POINTER (uid), g_memdup (&session, sizeof session)); } finished = TRUE; out: if (error) nm_log_err (LOGD_CORE, "ConsoleKit: Failed to load database: %s", error->message); g_clear_error (&error); g_clear_pointer (&groups, g_strfreev); g_clear_pointer (&keyfile, g_key_file_free); return finished; }
static gboolean enslave_slave (NMDevice *device, NMDevice *slave, NMConnection *connection, gboolean configure) { #if WITH_TEAMDCTL NMDeviceTeamPrivate *priv = NM_DEVICE_TEAM_GET_PRIVATE (device); #endif gboolean success = TRUE, no_firmware = FALSE; const char *iface = nm_device_get_ip_iface (device); const char *slave_iface = nm_device_get_ip_iface (slave); NMSettingTeamPort *s_team_port; nm_device_master_check_slave_physical_port (device, slave, LOGD_TEAM); if (configure) { nm_device_take_down (slave, TRUE); s_team_port = nm_connection_get_setting_team_port (connection); if (s_team_port) { const char *config = nm_setting_team_port_get_config (s_team_port); if (config) { #if WITH_TEAMDCTL if (!priv->tdc) { nm_log_warn (LOGD_TEAM, "(%s): enslaved team port %s config not changed, not connected to teamd", iface, slave_iface); } else { int err; char *sanitized_config; sanitized_config = g_strdelimit (g_strdup (config), "\r\n", ' '); err = teamdctl_port_config_update_raw (priv->tdc, slave_iface, sanitized_config); g_free (sanitized_config); if (err != 0) { nm_log_err (LOGD_TEAM, "(%s): failed to update config for port %s (err=%d)", iface, slave_iface, err); return FALSE; } } #else nm_log_warn (LOGD_TEAM, "(%s): enslaved team port %s config not changed due to lack of Teamd control support", iface, slave_iface); #endif } } success = nm_platform_link_enslave (nm_device_get_ip_ifindex (device), nm_device_get_ip_ifindex (slave)); nm_device_bring_up (slave, TRUE, &no_firmware); } if (success) { nm_log_info (LOGD_TEAM, "(%s): enslaved team port %s", iface, slave_iface); g_object_notify (G_OBJECT (device), "slaves"); } return success; }
/* * Callback for a Disconnect command * * Called by the WiMAX API when a command sent to connect is * completed. This is just a confirmation of what happened with the * command. * * When the device changes state, the state change callback is called * and that will fiddle with the NetworkManager internals. * * We just update the result of the command and wake up anybody who is * waiting for this conditional variable. */ static void __iwmx_sdk_disconnect_cb(WIMAX_API_DEVICE_ID *device_id, WIMAX_API_NETWORK_CONNECTION_RESP resp) { struct wmxsdk *wmxsdk = deviceid_to_wmxsdk(device_id); WIMAX_API_DEVICE_STATUS status; status = iwmxsdk_status_get(wmxsdk); if (resp == WIMAX_API_CONNECTION_SUCCESS) { if (status == WIMAX_API_DEVICE_STATUS_Data_Connected) { nm_log_err(LOGD_WIMAX, "wmxsdk: error: disconnect worked, " "but state didn't change (now it is %d [%s])", status, iwmx_sdk_dev_status_to_str(status)); } } else nm_log_err(LOGD_WIMAX, "wmxsdk: failed to disconnect (status %d: %s)", status, iwmx_sdk_dev_status_to_str(status)); }
static void nm_session_monitor_init (NMSessionMonitor *self) { GError *error = NULL; GFile *file; #if NO_CONSOLEKIT return; #endif /* Sessions-by-user is responsible for destroying the Session objects */ self->sessions_by_user = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) session_free); self->sessions_by_uid = g_hash_table_new (g_direct_hash, g_direct_equal); error = NULL; if (!ensure_database (self, &error)) { /* Ignore the first error if the CK database isn't found yet */ if (g_error_matches (error, NM_SESSION_MONITOR_ERROR, NM_SESSION_MONITOR_ERROR_NO_DATABASE) == FALSE) { nm_log_err (LOGD_CORE, "Error loading " CKDB_PATH ": %s", error->message); } g_error_free (error); } error = NULL; file = g_file_new_for_path (CKDB_PATH); self->database_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error); g_object_unref (file); if (self->database_monitor == NULL) { nm_log_err (LOGD_CORE, "Error monitoring " CKDB_PATH ": %s", error->message); g_error_free (error); } else { g_signal_connect (self->database_monitor, "changed", G_CALLBACK (on_file_monitor_changed), self); } }
static gboolean br2684_create_iface (NMDeviceAdsl *self, NMSettingAdsl *s_adsl) { NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self); const char *iface = nm_device_get_iface (NM_DEVICE (self)); struct atm_newif_br2684 ni; int err, fd; gboolean success = FALSE; guint num = 0; g_return_val_if_fail (s_adsl != NULL, FALSE); fd = socket (PF_ATMPVC, SOCK_DGRAM, ATM_AAL5); if (fd < 0) { nm_log_err (LOGD_ADSL, "(%s): failed to open ATM control socket (%d)", iface, errno); return FALSE; } memset (&ni, 0, sizeof (ni)); ni.backend_num = ATM_BACKEND_BR2684; ni.media = BR2684_MEDIA_ETHERNET; ni.mtu = 1500; /* Loop attempting to create an interface that doesn't exist yet. The * kernel can create one for us automatically, but due to API issues it * cannot return that name to us. Since we want to know the name right * away, just brute-force it. */ while (num < 10000) { memset (&ni.ifname, 0, sizeof (ni.ifname)); snprintf (ni.ifname, sizeof (ni.ifname), "nas%d", num); err = ioctl (fd, ATM_NEWBACKENDIF, &ni); if (err == 0) { set_nas_iface (self, -1, ni.ifname); nm_log_info (LOGD_ADSL, "(%s): using NAS interface %s (%d)", iface, priv->nas_ifname, priv->nas_ifindex); success = TRUE; break; } else if (errno == -EEXIST) { /* Try again */ num++; } else { nm_log_warn (LOGD_ADSL, "(%s): failed to create br2684 interface (%d)", iface, errno); break; } } close (fd); return success; }
static void interface_add_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) { NMSupplicantInterface *self; NMSupplicantInterfacePrivate *priv; gs_free_error GError *error = NULL; gs_unref_variant GVariant *variant = NULL; const char *path; variant = _nm_dbus_proxy_call_finish (proxy, result, G_VARIANT_TYPE ("(o)"), &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) return; self = NM_SUPPLICANT_INTERFACE (user_data); priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (variant) { g_variant_get (variant, "(&o)", &path); interface_add_done (self, path); } else if (_nm_dbus_error_has_name (error, WPAS_ERROR_EXISTS_ERROR)) { /* Interface already added, just get its object path */ g_dbus_proxy_call (priv->wpas_proxy, "GetInterface", g_variant_new ("(s)", priv->dev), G_DBUS_CALL_FLAGS_NONE, -1, priv->init_cancellable, (GAsyncReadyCallback) interface_get_cb, self); } else if ( g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_EXEC_FAILED) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FORK_FAILED) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_FAILED) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMEOUT) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_TIMED_OUT) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND)) { /* Supplicant wasn't running and could not be launched via service * activation. Wait for it to start by moving back to the INIT * state. */ g_dbus_error_strip_remote_error (error); nm_log_dbg (LOGD_SUPPLICANT, "(%s): failed to activate supplicant: %s", priv->dev, error->message); set_state (self, NM_SUPPLICANT_INTERFACE_STATE_INIT); } else { g_dbus_error_strip_remote_error (error); nm_log_err (LOGD_SUPPLICANT, "(%s): error adding interface: %s", priv->dev, error->message); set_state (self, NM_SUPPLICANT_INTERFACE_STATE_DOWN); } }