2010-02-25 09:52:30 -08:00
|
|
|
/* nmcli - command-line tool to control NetworkManager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
2012-01-03 16:37:53 +01:00
|
|
|
* (C) Copyright 2010 - 2012 Red Hat, Inc.
|
2010-02-25 09:52:30 -08:00
|
|
|
*/
|
|
|
|
|
|
2011-03-14 01:00:56 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
2012-04-28 22:32:21 +01:00
|
|
|
#include <netinet/ether.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
|
|
#include <nm-client.h>
|
|
|
|
|
#include <nm-device.h>
|
|
|
|
|
#include <nm-device-ethernet.h>
|
2011-05-17 21:03:20 +03:00
|
|
|
#include <nm-device-adsl.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <nm-device-wifi.h>
|
2011-02-25 10:16:17 -06:00
|
|
|
#include <nm-device-modem.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <nm-device-bt.h>
|
2012-03-02 09:02:33 +01:00
|
|
|
#include <nm-device-olpc-mesh.h>
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
#include <nm-device-wimax.h>
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-11-03 11:04:38 -04:00
|
|
|
#include <nm-device-infiniband.h>
|
2012-03-06 11:31:03 +01:00
|
|
|
#include <nm-device-bond.h>
|
2012-10-30 17:11:28 -05:00
|
|
|
#include <nm-device-bridge.h>
|
2012-03-07 11:45:40 -06:00
|
|
|
#include <nm-device-vlan.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <nm-utils.h>
|
|
|
|
|
#include <nm-setting-ip4-config.h>
|
2010-06-29 18:36:22 +02:00
|
|
|
#include <nm-setting-ip6-config.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <nm-vpn-connection.h>
|
|
|
|
|
#include <nm-setting-connection.h>
|
|
|
|
|
#include <nm-setting-wired.h>
|
2011-05-17 21:03:20 +03:00
|
|
|
#include <nm-setting-adsl.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
#include <nm-setting-pppoe.h>
|
|
|
|
|
#include <nm-setting-wireless.h>
|
|
|
|
|
#include <nm-setting-gsm.h>
|
|
|
|
|
#include <nm-setting-cdma.h>
|
|
|
|
|
#include <nm-setting-bluetooth.h>
|
|
|
|
|
#include <nm-setting-olpc-mesh.h>
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
#include <nm-setting-wimax.h>
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-11-03 11:04:38 -04:00
|
|
|
#include <nm-setting-infiniband.h>
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
#include "utils.h"
|
2012-01-06 13:51:33 +01:00
|
|
|
#include "common.h"
|
2010-02-25 09:52:30 -08:00
|
|
|
#include "devices.h"
|
|
|
|
|
|
|
|
|
|
|
2013-04-03 10:15:00 +02:00
|
|
|
/* Available fields for 'device status' */
|
2010-03-18 15:39:15 +01:00
|
|
|
static NmcOutputField nmc_fields_dev_status[] = {
|
2010-09-24 14:38:50 +02:00
|
|
|
{"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 0 */
|
|
|
|
|
{"TYPE", N_("TYPE"), 17, NULL, 0}, /* 1 */
|
|
|
|
|
{"STATE", N_("STATE"), 13, NULL, 0}, /* 2 */
|
|
|
|
|
{"DBUS-PATH", N_("DBUS-PATH"), 43, NULL, 0}, /* 3 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
2010-03-18 15:39:15 +01:00
|
|
|
};
|
2010-09-24 14:38:50 +02:00
|
|
|
#define NMC_FIELDS_DEV_STATUS_ALL "DEVICE,TYPE,STATE,DBUS-PATH"
|
2010-03-18 15:39:15 +01:00
|
|
|
#define NMC_FIELDS_DEV_STATUS_COMMON "DEVICE,TYPE,STATE"
|
|
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available sections for 'device show' */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_sections[] = {
|
2010-03-24 19:05:35 +01:00
|
|
|
{"GENERAL", N_("GENERAL"), 0, NULL, 0}, /* 0 */
|
|
|
|
|
{"CAPABILITIES", N_("CAPABILITIES"), 0, NULL, 0}, /* 1 */
|
|
|
|
|
{"WIFI-PROPERTIES", N_("WIFI-PROPERTIES"), 0, NULL, 0}, /* 2 */
|
|
|
|
|
{"AP", N_("AP"), 0, NULL, 0}, /* 3 */
|
|
|
|
|
{"WIRED-PROPERTIES", N_("WIRED-PROPERTIES"), 0, NULL, 0}, /* 4 */
|
2011-01-06 17:01:55 -06:00
|
|
|
{"WIMAX-PROPERTIES", N_("WIMAX-PROPERTIES"), 0, NULL, 0}, /* 5 */
|
|
|
|
|
{"NSP", N_("NSP"), 0, NULL, 0}, /* 6 */
|
2012-01-03 16:37:53 +01:00
|
|
|
{"IP4", N_("IP4"), 0, NULL, 0}, /* 7 */
|
|
|
|
|
{"DHCP4", N_("DHCP4"), 0, NULL, 0}, /* 8 */
|
|
|
|
|
{"IP6", N_("IP6"), 0, NULL, 0}, /* 9 */
|
|
|
|
|
{"DHCP6", N_("DHCP6"), 0, NULL, 0}, /* 10 */
|
2012-10-22 14:31:11 +02:00
|
|
|
{"BOND", N_("BOND"), 0, NULL, 0}, /* 11 */
|
2012-10-22 15:18:34 +02:00
|
|
|
{"VLAN", N_("VLAN"), 0, NULL, 0}, /* 12 */
|
2012-08-31 12:48:27 +02:00
|
|
|
{"CONNECTIONS", N_("CONNECTIONS"), 0, NULL, 0}, /* 13 */
|
2010-03-24 19:05:35 +01:00
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,WIMAX-PROPERTIES,NSP,IP4,DHCP4,IP6,DHCP6"
|
2011-02-14 16:06:37 +01:00
|
|
|
#else
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_SECTIONS_ALL "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON "GENERAL,CAPABILITIES,BOND,VLAN,CONNECTIONS,WIFI-PROPERTIES,AP,WIRED-PROPERTIES,IP4,DHCP4,IP6,DHCP6"
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2010-03-24 19:05:35 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - GENERAL part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_general[] = {
|
2011-12-20 15:54:58 +01:00
|
|
|
{"NAME", N_("NAME"), 10, NULL, 0}, /* 0 */
|
|
|
|
|
{"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 1 */
|
|
|
|
|
{"TYPE", N_("TYPE"), 17, NULL, 0}, /* 2 */
|
|
|
|
|
{"VENDOR", N_("VENDOR"), 20, NULL, 0}, /* 3 */
|
|
|
|
|
{"PRODUCT", N_("PRODUCT"), 50, NULL, 0}, /* 4 */
|
|
|
|
|
{"DRIVER", N_("DRIVER"), 9, NULL, 0}, /* 5 */
|
2012-06-08 13:44:43 +02:00
|
|
|
{"DRIVER-VERSION", N_("DRIVER-VERSION"), 18, NULL, 0}, /* 6 */
|
|
|
|
|
{"FIRMWARE-VERSION", N_("FIRMWARE-VERSION"), 18, NULL, 0}, /* 7 */
|
|
|
|
|
{"HWADDR", N_("HWADDR"), 19, NULL, 0}, /* 8 */
|
|
|
|
|
{"STATE", N_("STATE"), 14, NULL, 0}, /* 9 */
|
|
|
|
|
{"REASON", N_("REASON"), 25, NULL, 0}, /* 10 */
|
|
|
|
|
{"UDI", N_("UDI"), 64, NULL, 0}, /* 11 */
|
|
|
|
|
{"IP-IFACE", N_("IP-IFACE"), 10, NULL, 0}, /* 12 */
|
|
|
|
|
{"NM-MANAGED", N_("NM-MANAGED"), 15, NULL, 0}, /* 13 */
|
|
|
|
|
{"AUTOCONNECT", N_("AUTOCONNECT"), 15, NULL, 0}, /* 14 */
|
|
|
|
|
{"FIRMWARE-MISSING", N_("FIRMWARE-MISSING"), 18, NULL, 0}, /* 15 */
|
|
|
|
|
{"CONNECTION", N_("CONNECTION"), 51, NULL, 0}, /* 16 */
|
2011-12-20 15:54:58 +01:00
|
|
|
{NULL, NULL, 0, NULL, 0}
|
2010-03-22 18:43:28 +01:00
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_GENERAL_ALL "NAME,DEVICE,TYPE,VENDOR,PRODUCT,DRIVER,DRIVER-VERSION,FIRMWARE-VERSION,HWADDR,STATE,REASON,UDI,IP-IFACE,"\
|
2012-08-31 12:48:27 +02:00
|
|
|
"NM-MANAGED,AUTOCONNECT,FIRMWARE-MISSING,CONNECTION"
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_GENERAL_COMMON "NAME,DEVICE,TYPE,VENDOR,PRODUCT,DRIVER,HWADDR,STATE"
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - CONNECTIONS part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_connections[] = {
|
2012-08-31 12:48:27 +02:00
|
|
|
{"NAME", N_("NAME"), 10, NULL, 0}, /* 0 */
|
|
|
|
|
{"AVAILABLE-CONNECTION-PATHS", N_("AVAILABLE-CONNECTION-PATHS"), 80, NULL, 0}, /* 1 */
|
|
|
|
|
{"AVAILABLE-CONNECTIONS", N_("AVAILABLE-CONNECTIONS"), 80, NULL, 0}, /* 2 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL "AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_CONNECTIONS_COMMON "AVAILABLE-CONNECTION-PATHS,AVAILABLE-CONNECTIONS"
|
2012-08-31 12:48:27 +02:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - CAPABILITIES part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_cap[] = {
|
2010-03-22 18:43:28 +01:00
|
|
|
{"NAME", N_("NAME"), 13, NULL, 0}, /* 0 */
|
|
|
|
|
{"CARRIER-DETECT", N_("CARRIER-DETECT"), 16, NULL, 0}, /* 1 */
|
|
|
|
|
{"SPEED", N_("SPEED"), 10, NULL, 0}, /* 2 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_CAP_ALL "NAME,CARRIER-DETECT,SPEED"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_CAP_COMMON "NAME,CARRIER-DETECT,SPEED"
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - wired properties part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_wired_prop[] = {
|
2010-03-22 18:43:28 +01:00
|
|
|
{"NAME", N_("NAME"), 18, NULL, 0}, /* 0 */
|
|
|
|
|
{"CARRIER", N_("CARRIER"), 10, NULL, 0}, /* 1 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL "NAME,CARRIER"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIRED_PROP_COMMON "NAME,CARRIER"
|
2010-03-22 18:43:28 +01:00
|
|
|
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - wireless properties part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_wifi_prop[] = {
|
2010-03-22 18:43:28 +01:00
|
|
|
{"NAME", N_("NAME"), 18, NULL, 0}, /* 0 */
|
|
|
|
|
{"WEP", N_("WEP"), 5, NULL, 0}, /* 1 */
|
|
|
|
|
{"WPA", N_("WPA"), 5, NULL, 0}, /* 2 */
|
|
|
|
|
{"WPA2", N_("WPA2"), 6, NULL, 0}, /* 3 */
|
|
|
|
|
{"TKIP", N_("TKIP"), 6, NULL, 0}, /* 4 */
|
|
|
|
|
{"CCMP", N_("CCMP"), 6, NULL, 0}, /* 5 */
|
2013-02-12 09:55:21 +01:00
|
|
|
{"AP", N_("AP"), 6, NULL, 0}, /* 6 */
|
|
|
|
|
{"ADHOC", N_("ADHOC"), 6, NULL, 0}, /* 7 */
|
2010-03-22 18:43:28 +01:00
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIFI_PROP_COMMON "NAME,WEP,WPA,WPA2,TKIP,CCMP,AP,ADHOC"
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - wimax properties part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_wimax_prop[] = {
|
2011-01-06 17:01:55 -06:00
|
|
|
{"NAME", N_("NAME"), 18, NULL, 0}, /* 0 */
|
|
|
|
|
{"CTR-FREQ", N_("CTR-FREQ"), 7, NULL, 0}, /* 1 */
|
|
|
|
|
{"RSSI", N_("RSSI"), 5, NULL, 0}, /* 2 */
|
|
|
|
|
{"CINR", N_("CINR"), 5, NULL, 0}, /* 3 */
|
|
|
|
|
{"TX-POW", N_("TX-POW"), 5, NULL, 0}, /* 4 */
|
|
|
|
|
{"BSID", N_("BSID"), 18, NULL, 0}, /* 5 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_WIMAX_PROP_COMMON "NAME,CTR-FREQ,RSSI,CINR,TX-POW,BSID"
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-01-06 17:01:55 -06:00
|
|
|
|
2013-04-03 10:15:00 +02:00
|
|
|
/* Available fields for 'device wifi list' */
|
2010-03-18 15:39:15 +01:00
|
|
|
static NmcOutputField nmc_fields_dev_wifi_list[] = {
|
2010-03-24 19:05:35 +01:00
|
|
|
{"NAME", N_("NAME"), 15, NULL, 0}, /* 0 */
|
|
|
|
|
{"SSID", N_("SSID"), 33, NULL, 0}, /* 1 */
|
|
|
|
|
{"BSSID", N_("BSSID"), 19, NULL, 0}, /* 2 */
|
|
|
|
|
{"MODE", N_("MODE"), 16, NULL, 0}, /* 3 */
|
|
|
|
|
{"FREQ", N_("FREQ"), 10, NULL, 0}, /* 4 */
|
|
|
|
|
{"RATE", N_("RATE"), 10, NULL, 0}, /* 5 */
|
|
|
|
|
{"SIGNAL", N_("SIGNAL"), 8, NULL, 0}, /* 6 */
|
|
|
|
|
{"SECURITY", N_("SECURITY"), 10, NULL, 0}, /* 7 */
|
|
|
|
|
{"WPA-FLAGS", N_("WPA-FLAGS"), 25, NULL, 0}, /* 8 */
|
|
|
|
|
{"RSN-FLAGS", N_("RSN-FLAGS"), 25, NULL, 0}, /* 9 */
|
|
|
|
|
{"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 10 */
|
|
|
|
|
{"ACTIVE", N_("ACTIVE"), 8, NULL, 0}, /* 11 */
|
2010-12-17 11:37:10 +01:00
|
|
|
{"DBUS-PATH", N_("DBUS-PATH"), 46, NULL, 0}, /* 12 */
|
2010-03-18 15:39:15 +01:00
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2010-12-17 11:37:10 +01:00
|
|
|
#define NMC_FIELDS_DEV_WIFI_LIST_ALL "SSID,BSSID,MODE,FREQ,RATE,SIGNAL,SECURITY,WPA-FLAGS,RSN-FLAGS,DEVICE,ACTIVE,DBUS-PATH"
|
2010-03-24 19:05:35 +01:00
|
|
|
#define NMC_FIELDS_DEV_WIFI_LIST_COMMON "SSID,BSSID,MODE,FREQ,RATE,SIGNAL,SECURITY,ACTIVE"
|
2010-03-22 18:43:28 +01:00
|
|
|
#define NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST "NAME,"NMC_FIELDS_DEV_WIFI_LIST_COMMON
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2013-04-03 10:15:00 +02:00
|
|
|
/* Available fields for 'device wimax list' */
|
2011-01-06 17:01:55 -06:00
|
|
|
static NmcOutputField nmc_fields_dev_wimax_list[] = {
|
|
|
|
|
{"NAME", N_("NAME"), 15, NULL, 0}, /* 0 */
|
|
|
|
|
{"NSP", N_("NSP"), 33, NULL, 0}, /* 1 */
|
|
|
|
|
{"SIGNAL", N_("SIGNAL"), 8, NULL, 0}, /* 2 */
|
|
|
|
|
{"TYPE", N_("TYPE"), 16, NULL, 0}, /* 3 */
|
|
|
|
|
{"DEVICE", N_("DEVICE"), 10, NULL, 0}, /* 4 */
|
|
|
|
|
{"ACTIVE", N_("ACTIVE"), 8, NULL, 0}, /* 5 */
|
|
|
|
|
{"DBUS-PATH", N_("DBUS-PATH"), 46, NULL, 0}, /* 6 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
#define NMC_FIELDS_DEV_WIMAX_LIST_ALL "NSP,SIGNAL,TYPE,DEVICE,ACTIVE,DBUS-PATH"
|
|
|
|
|
#define NMC_FIELDS_DEV_WIMAX_LIST_COMMON "NSP,SIGNAL,TYPE,DEVICE,ACTIVE"
|
|
|
|
|
#define NMC_FIELDS_DEV_WIMAX_LIST_FOR_DEV_LIST "NAME,"NMC_FIELDS_DEV_WIMAX_LIST_COMMON
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-01-06 17:01:55 -06:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - BOND part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_bond_prop[] = {
|
2012-10-22 14:31:11 +02:00
|
|
|
{"NAME", N_("NAME"), 18, NULL, 0}, /* 0 */
|
|
|
|
|
{"SLAVES", N_("SLAVES"), 20, NULL, 0}, /* 1 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_BOND_PROP_ALL "NAME,SLAVES"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_BOND_PROP_COMMON "NAME,SLAVES"
|
2012-10-22 14:31:11 +02:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Available fields for 'device show' - VLAN part */
|
|
|
|
|
static NmcOutputField nmc_fields_dev_show_vlan_prop[] = {
|
2012-10-22 15:18:34 +02:00
|
|
|
{"NAME", N_("NAME"), 18, NULL, 0}, /* 0 */
|
|
|
|
|
{"ID", N_("ID"), 5, NULL, 0}, /* 1 */
|
|
|
|
|
{NULL, NULL, 0, NULL, 0}
|
|
|
|
|
};
|
2013-04-03 10:01:42 +02:00
|
|
|
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,ID"
|
|
|
|
|
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,ID"
|
2012-10-22 15:18:34 +02:00
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2011-09-06 15:30:15 +02:00
|
|
|
/* glib main loop variable - defined in nmcli.c */
|
|
|
|
|
extern GMainLoop *loop;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2012-04-28 22:32:21 +01:00
|
|
|
static guint progress_id = 0; /* ID of event source for displaying progress */
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
static void
|
|
|
|
|
usage (void)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
cli: replace 'dev' and 'con' OBJECTs by 'device', resp. 'connection'
Shorter forms work as previously. Thus, all of these commands are valid:
nmcli device, nmcli devic, nmcli devi, nmcli dev, nmcli de, nmcli d
nmcli connection, nmcli connectio, ..., nmcli conn, nmcli con, ..., nmcli c
2012-11-13 14:43:14 +01:00
|
|
|
_("Usage: nmcli device { COMMAND | help }\n\n"
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2013-04-03 10:01:42 +02:00
|
|
|
" COMMAND := { status | show | disconnect | wifi | wimax }\n\n"
|
2011-02-14 16:06:37 +01:00
|
|
|
#else
|
2013-04-03 10:01:42 +02:00
|
|
|
" COMMAND := { status | show | disconnect | wifi }\n\n"
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2013-04-03 10:27:31 +02:00
|
|
|
" status\n\n"
|
|
|
|
|
" show [<iface>]\n\n"
|
|
|
|
|
" disconnect <iface> [--nowait] [--timeout <timeout>]\n\n"
|
|
|
|
|
" wifi [list [iface <iface>] [bssid <BSSID>]]\n\n"
|
|
|
|
|
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [iface <iface>] [bssid <BSSID>] [name <name>]\n\n"
|
|
|
|
|
" [--private] [--nowait] [--timeout <timeout>]\n\n"
|
|
|
|
|
" wifi scan [[iface] <iface>]\n\n"
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2013-04-03 10:27:31 +02:00
|
|
|
" wimax [list [iface <iface>] [nsp <name>]]\n\n"
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
|
|
|
|
));
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* quit main loop */
|
|
|
|
|
static void
|
|
|
|
|
quit (void)
|
|
|
|
|
{
|
2012-04-28 22:32:21 +01:00
|
|
|
if (progress_id) {
|
|
|
|
|
g_source_remove (progress_id);
|
|
|
|
|
nmc_terminal_erase_line ();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
g_main_loop_quit (loop); /* quit main loop */
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:28:51 +01:00
|
|
|
/* Convert device type to string. Use setting names strings to match with
|
|
|
|
|
* connection type names.
|
|
|
|
|
*/
|
2010-02-25 09:52:30 -08:00
|
|
|
static const char *
|
2011-02-25 10:16:17 -06:00
|
|
|
device_type_to_string (NMDevice *device)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
2011-02-25 10:16:17 -06:00
|
|
|
NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE;
|
|
|
|
|
|
|
|
|
|
switch (nm_device_get_device_type (device)) {
|
2011-02-21 16:28:51 +01:00
|
|
|
case NM_DEVICE_TYPE_ETHERNET:
|
2010-02-25 09:52:30 -08:00
|
|
|
return NM_SETTING_WIRED_SETTING_NAME;
|
2011-05-17 21:03:20 +03:00
|
|
|
case NM_DEVICE_TYPE_ADSL:
|
|
|
|
|
return NM_SETTING_ADSL_SETTING_NAME;
|
2011-02-21 16:28:51 +01:00
|
|
|
case NM_DEVICE_TYPE_WIFI:
|
2010-02-25 09:52:30 -08:00
|
|
|
return NM_SETTING_WIRELESS_SETTING_NAME;
|
2011-02-25 10:16:17 -06:00
|
|
|
case NM_DEVICE_TYPE_MODEM:
|
|
|
|
|
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
|
|
|
|
|
if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
|
|
|
|
|
return NM_SETTING_GSM_SETTING_NAME;
|
|
|
|
|
else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
|
|
|
|
|
return NM_SETTING_CDMA_SETTING_NAME;
|
|
|
|
|
return _("Unknown");
|
2011-02-21 16:28:51 +01:00
|
|
|
case NM_DEVICE_TYPE_BT:
|
2010-02-25 09:52:30 -08:00
|
|
|
return NM_SETTING_BLUETOOTH_SETTING_NAME;
|
2012-03-02 09:02:33 +01:00
|
|
|
case NM_DEVICE_TYPE_OLPC_MESH:
|
|
|
|
|
return NM_SETTING_OLPC_MESH_SETTING_NAME;
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-02-21 16:28:51 +01:00
|
|
|
case NM_DEVICE_TYPE_WIMAX:
|
2011-01-06 17:01:55 -06:00
|
|
|
return NM_SETTING_WIMAX_SETTING_NAME;
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-11-03 11:04:38 -04:00
|
|
|
case NM_DEVICE_TYPE_INFINIBAND:
|
|
|
|
|
return NM_SETTING_INFINIBAND_SETTING_NAME;
|
2012-03-06 11:31:03 +01:00
|
|
|
case NM_DEVICE_TYPE_BOND:
|
|
|
|
|
return NM_SETTING_BOND_SETTING_NAME;
|
2012-03-07 11:45:40 -06:00
|
|
|
case NM_DEVICE_TYPE_VLAN:
|
|
|
|
|
return NM_SETTING_VLAN_SETTING_NAME;
|
2012-10-30 17:11:28 -05:00
|
|
|
case NM_DEVICE_TYPE_BRIDGE:
|
|
|
|
|
return NM_SETTING_BRIDGE_SETTING_NAME;
|
2011-02-21 16:28:51 +01:00
|
|
|
default:
|
2010-02-25 09:52:30 -08:00
|
|
|
return _("Unknown");
|
2011-02-21 16:28:51 +01:00
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
2011-02-21 15:41:12 +01:00
|
|
|
ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
|
|
|
|
char *flags_str[16]; /* Enough space for flags and terminating NULL */
|
|
|
|
|
char *ret_str;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_PAIR_WEP40)
|
|
|
|
|
flags_str[i++] = g_strdup ("pair_wpe40");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_PAIR_WEP104)
|
|
|
|
|
flags_str[i++] = g_strdup ("pair_wpe104");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_PAIR_TKIP)
|
|
|
|
|
flags_str[i++] = g_strdup ("pair_tkip");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_PAIR_CCMP)
|
|
|
|
|
flags_str[i++] = g_strdup ("pair_ccmp");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_GROUP_WEP40)
|
|
|
|
|
flags_str[i++] = g_strdup ("group_wpe40");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_GROUP_WEP104)
|
|
|
|
|
flags_str[i++] = g_strdup ("group_wpe104");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_GROUP_TKIP)
|
|
|
|
|
flags_str[i++] = g_strdup ("group_tkip");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_GROUP_CCMP)
|
|
|
|
|
flags_str[i++] = g_strdup ("group_ccmp");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
|
|
|
|
|
flags_str[i++] = g_strdup ("psk");
|
|
|
|
|
if (flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
|
|
|
|
|
flags_str[i++] = g_strdup ("802.1X");
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
flags_str[i++] = g_strdup (_("(none)"));
|
|
|
|
|
|
|
|
|
|
flags_str[i] = NULL;
|
|
|
|
|
|
|
|
|
|
ret_str = g_strjoinv (" ", flags_str);
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
while (flags_str[i])
|
2012-04-28 22:54:02 +02:00
|
|
|
g_free (flags_str[i++]);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
return ret_str;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NmCli *nmc;
|
2010-03-24 19:05:35 +01:00
|
|
|
int index;
|
2010-03-18 15:39:15 +01:00
|
|
|
const char* active_bssid;
|
|
|
|
|
const char* device;
|
|
|
|
|
} APInfo;
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
static void
|
|
|
|
|
detail_access_point (gpointer data, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMAccessPoint *ap = NM_ACCESS_POINT (data);
|
2010-03-18 15:39:15 +01:00
|
|
|
APInfo *info = (APInfo *) user_data;
|
2010-02-25 09:52:30 -08:00
|
|
|
gboolean active = FALSE;
|
2011-02-21 15:41:12 +01:00
|
|
|
NM80211ApFlags flags;
|
|
|
|
|
NM80211ApSecurityFlags wpa_flags, rsn_flags;
|
|
|
|
|
guint32 freq, bitrate;
|
2010-03-18 15:39:15 +01:00
|
|
|
guint8 strength;
|
2011-09-06 13:37:23 +02:00
|
|
|
const GByteArray *ssid;
|
|
|
|
|
const char *bssid;
|
2010-03-18 15:39:15 +01:00
|
|
|
NM80211Mode mode;
|
|
|
|
|
char *freq_str, *ssid_str, *bitrate_str, *strength_str, *wpa_flags_str, *rsn_flags_str;
|
|
|
|
|
GString *security_str;
|
2010-03-24 19:05:35 +01:00
|
|
|
char *ap_name;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
if (info->active_bssid) {
|
2011-09-06 13:37:23 +02:00
|
|
|
const char *current_bssid = nm_access_point_get_bssid (ap);
|
2010-03-18 15:39:15 +01:00
|
|
|
if (current_bssid && !strcmp (current_bssid, info->active_bssid))
|
2010-02-25 09:52:30 -08:00
|
|
|
active = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
/* Get AP properties */
|
|
|
|
|
flags = nm_access_point_get_flags (ap);
|
|
|
|
|
wpa_flags = nm_access_point_get_wpa_flags (ap);
|
|
|
|
|
rsn_flags = nm_access_point_get_rsn_flags (ap);
|
|
|
|
|
ssid = nm_access_point_get_ssid (ap);
|
2011-09-06 13:37:23 +02:00
|
|
|
bssid = nm_access_point_get_bssid (ap);
|
2010-03-18 15:39:15 +01:00
|
|
|
freq = nm_access_point_get_frequency (ap);
|
|
|
|
|
mode = nm_access_point_get_mode (ap);
|
|
|
|
|
bitrate = nm_access_point_get_max_bitrate (ap);
|
|
|
|
|
strength = nm_access_point_get_strength (ap);
|
|
|
|
|
|
|
|
|
|
/* Convert to strings */
|
2010-03-24 23:28:00 +01:00
|
|
|
ssid_str = ssid_to_printable ((const char *) ssid->data, ssid->len);
|
2010-03-18 15:39:15 +01:00
|
|
|
freq_str = g_strdup_printf (_("%u MHz"), freq);
|
|
|
|
|
bitrate_str = g_strdup_printf (_("%u MB/s"), bitrate/1000);
|
|
|
|
|
strength_str = g_strdup_printf ("%u", strength);
|
|
|
|
|
wpa_flags_str = ap_wpa_rsn_flags_to_string (wpa_flags);
|
|
|
|
|
rsn_flags_str = ap_wpa_rsn_flags_to_string (rsn_flags);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
security_str = g_string_new (NULL);
|
2010-02-25 09:52:30 -08:00
|
|
|
if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY)
|
|
|
|
|
&& (wpa_flags != NM_802_11_AP_SEC_NONE)
|
|
|
|
|
&& (rsn_flags != NM_802_11_AP_SEC_NONE))
|
2010-03-18 15:39:15 +01:00
|
|
|
g_string_append (security_str, _("Encrypted: "));
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
if ( (flags & NM_802_11_AP_FLAGS_PRIVACY)
|
|
|
|
|
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
|
|
|
|
|
&& (rsn_flags == NM_802_11_AP_SEC_NONE))
|
2010-03-18 15:39:15 +01:00
|
|
|
g_string_append (security_str, _("WEP "));
|
2010-02-25 09:52:30 -08:00
|
|
|
if (wpa_flags != NM_802_11_AP_SEC_NONE)
|
2010-03-18 15:39:15 +01:00
|
|
|
g_string_append (security_str, _("WPA "));
|
2010-02-25 09:52:30 -08:00
|
|
|
if (rsn_flags != NM_802_11_AP_SEC_NONE)
|
2010-03-18 15:39:15 +01:00
|
|
|
g_string_append (security_str, _("WPA2 "));
|
2010-02-25 09:52:30 -08:00
|
|
|
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
|
|
|
|
|
|| (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
|
2010-03-18 15:39:15 +01:00
|
|
|
g_string_append (security_str, _("Enterprise "));
|
|
|
|
|
|
|
|
|
|
if (security_str->len > 0)
|
|
|
|
|
g_string_truncate (security_str, security_str->len-1); /* Chop off last space */
|
|
|
|
|
|
2012-08-29 10:39:09 +02:00
|
|
|
ap_name = g_strdup_printf ("AP[%d]", info->index++); /* AP */
|
2010-03-24 19:05:35 +01:00
|
|
|
info->nmc->allowed_fields[0].value = ap_name;
|
|
|
|
|
info->nmc->allowed_fields[1].value = ssid_str;
|
2013-03-05 15:50:11 +01:00
|
|
|
info->nmc->allowed_fields[2].value = (char *) bssid;
|
2012-07-06 14:47:48 +02:00
|
|
|
info->nmc->allowed_fields[3].value = mode == NM_802_11_MODE_ADHOC ? _("Ad-Hoc")
|
|
|
|
|
: mode == NM_802_11_MODE_INFRA ? _("Infrastructure")
|
|
|
|
|
: _("Unknown");
|
2010-03-24 19:05:35 +01:00
|
|
|
info->nmc->allowed_fields[4].value = freq_str;
|
|
|
|
|
info->nmc->allowed_fields[5].value = bitrate_str;
|
|
|
|
|
info->nmc->allowed_fields[6].value = strength_str;
|
|
|
|
|
info->nmc->allowed_fields[7].value = security_str->str;
|
|
|
|
|
info->nmc->allowed_fields[8].value = wpa_flags_str;
|
|
|
|
|
info->nmc->allowed_fields[9].value = rsn_flags_str;
|
2013-03-05 15:50:11 +01:00
|
|
|
info->nmc->allowed_fields[10].value = (char *) info->device;
|
2010-03-24 19:05:35 +01:00
|
|
|
info->nmc->allowed_fields[11].value = active ? _("yes") : _("no");
|
2013-03-05 15:50:11 +01:00
|
|
|
info->nmc->allowed_fields[12].value = (char *) nm_object_get_path (NM_OBJECT (ap));
|
2010-03-24 19:05:35 +01:00
|
|
|
|
|
|
|
|
info->nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
|
2010-03-18 15:39:15 +01:00
|
|
|
print_fields (info->nmc->print_fields, info->nmc->allowed_fields);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
g_free (ap_name);
|
2010-03-18 15:39:15 +01:00
|
|
|
g_free (ssid_str);
|
|
|
|
|
g_free (freq_str);
|
|
|
|
|
g_free (bitrate_str);
|
|
|
|
|
g_free (strength_str);
|
|
|
|
|
g_free (wpa_flags_str);
|
|
|
|
|
g_free (rsn_flags_str);
|
|
|
|
|
g_string_free (security_str, TRUE);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
static void
|
|
|
|
|
detail_wimax_nsp (NMWimaxNsp *nsp, NmCli *nmc, NMDevice *dev, int idx)
|
|
|
|
|
{
|
|
|
|
|
NMDeviceWimax *wimax = NM_DEVICE_WIMAX (dev);
|
|
|
|
|
char *nsp_name, *quality_str;
|
|
|
|
|
const char *ntype;
|
|
|
|
|
gboolean active = FALSE;
|
|
|
|
|
|
|
|
|
|
switch (nm_wimax_nsp_get_network_type (nsp)) {
|
|
|
|
|
case NM_WIMAX_NSP_NETWORK_TYPE_HOME:
|
|
|
|
|
ntype = _("Home");
|
|
|
|
|
break;
|
|
|
|
|
case NM_WIMAX_NSP_NETWORK_TYPE_PARTNER:
|
|
|
|
|
ntype = _("Partner");
|
|
|
|
|
break;
|
|
|
|
|
case NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER:
|
|
|
|
|
ntype = _("Roaming");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ntype = _("Unknown");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nm_device_get_state (dev) == NM_DEVICE_STATE_ACTIVATED) {
|
|
|
|
|
if (nsp == nm_device_wimax_get_active_nsp (wimax))
|
|
|
|
|
active = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quality_str = g_strdup_printf ("%u", nm_wimax_nsp_get_signal_quality (nsp));
|
2012-08-29 10:39:09 +02:00
|
|
|
nsp_name = g_strdup_printf ("NSP[%d]", idx); /* NSP */
|
2011-01-06 17:01:55 -06:00
|
|
|
|
|
|
|
|
nmc->allowed_fields[0].value = nsp_name;
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[1].value = (char *) nm_wimax_nsp_get_name (nsp);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->allowed_fields[2].value = quality_str;
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[3].value = (char *) ntype;
|
|
|
|
|
nmc->allowed_fields[4].value = (char *) nm_device_get_iface (dev);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->allowed_fields[5].value = active ? _("yes") : _("no");
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[6].value = (char *) nm_object_get_path (NM_OBJECT (nsp));
|
2011-01-06 17:01:55 -06:00
|
|
|
|
|
|
|
|
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields);
|
|
|
|
|
|
|
|
|
|
g_free (nsp_name);
|
|
|
|
|
g_free (quality_str);
|
|
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-01-06 17:01:55 -06:00
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
struct cb_info {
|
|
|
|
|
NMClient *client;
|
|
|
|
|
const GPtrArray *active;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_device_info (gpointer data, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NM_DEVICE (data);
|
2010-03-18 15:39:15 +01:00
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
2010-03-24 19:05:35 +01:00
|
|
|
GError *error = NULL;
|
2010-03-18 15:39:15 +01:00
|
|
|
APInfo *info;
|
2010-03-22 18:43:28 +01:00
|
|
|
const char *hwaddr = NULL;
|
2010-03-25 13:39:49 -07:00
|
|
|
NMDeviceState state = NM_DEVICE_STATE_UNKNOWN;
|
2012-02-09 15:39:57 +01:00
|
|
|
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
|
2011-02-21 16:38:02 +01:00
|
|
|
NMDeviceCapabilities caps;
|
2011-12-20 15:54:58 +01:00
|
|
|
NMActiveConnection *acon;
|
2010-02-25 09:52:30 -08:00
|
|
|
guint32 speed;
|
2010-03-22 18:43:28 +01:00
|
|
|
char *speed_str = NULL;
|
2012-02-09 15:39:57 +01:00
|
|
|
char *state_str = NULL;
|
|
|
|
|
char *reason_str = NULL;
|
2010-03-24 19:05:35 +01:00
|
|
|
GArray *sections_array;
|
|
|
|
|
int k;
|
|
|
|
|
char *fields_str;
|
2013-04-03 10:01:42 +02:00
|
|
|
char *fields_all = NMC_FIELDS_DEV_SHOW_SECTIONS_ALL;
|
|
|
|
|
char *fields_common = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON;
|
2010-03-22 18:43:28 +01:00
|
|
|
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
|
|
|
|
|
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
|
|
|
|
|
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
|
2010-03-24 19:05:35 +01:00
|
|
|
gboolean was_output = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
|
|
|
|
else
|
|
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
sections_array = parse_output_fields (fields_str, nmc_fields_dev_show_sections, &error);
|
2010-03-24 19:05:35 +01:00
|
|
|
if (error) {
|
|
|
|
|
if (error->code == 0)
|
2013-04-03 10:01:42 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device show': %s"), error->message);
|
2010-03-24 19:05:35 +01:00
|
|
|
else
|
2013-04-03 10:01:42 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device show': %s; allowed fields: %s"), error->message, NMC_FIELDS_DEV_SHOW_SECTIONS_ALL);
|
2010-03-24 19:05:35 +01:00
|
|
|
g_error_free (error);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* Main header */
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_general;
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ONLY;
|
2010-03-22 18:43:28 +01:00
|
|
|
nmc->print_fields.header_name = _("Device details");
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, nmc->allowed_fields, NULL);
|
2010-03-22 18:43:28 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* Loop through the required sections and print them. */
|
|
|
|
|
for (k = 0; k < sections_array->len; k++) {
|
|
|
|
|
int section_idx = g_array_index (sections_array, int, k);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
if (nmc->print_output != NMC_PRINT_TERSE && !nmc->multiline_output && was_output)
|
|
|
|
|
printf ("\n"); /* Empty line */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
was_output = FALSE;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2012-02-09 15:39:57 +01:00
|
|
|
state = nm_device_get_state_reason (device, &reason);
|
2010-03-25 13:39:49 -07:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* section GENERAL */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[0].name)) {
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_general;
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_GENERAL_ALL, nmc->allowed_fields, NULL);
|
2010-03-24 19:05:35 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
if (NM_IS_DEVICE_ETHERNET (device))
|
|
|
|
|
hwaddr = nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device));
|
|
|
|
|
else if (NM_IS_DEVICE_WIFI (device))
|
|
|
|
|
hwaddr = nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (device));
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
else if (NM_IS_DEVICE_WIMAX (device))
|
|
|
|
|
hwaddr = nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device));
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2011-11-03 11:04:38 -04:00
|
|
|
else if (NM_IS_DEVICE_INFINIBAND (device))
|
|
|
|
|
hwaddr = nm_device_infiniband_get_hw_address (NM_DEVICE_INFINIBAND (device));
|
2012-03-06 11:31:03 +01:00
|
|
|
else if (NM_IS_DEVICE_BOND (device))
|
|
|
|
|
hwaddr = nm_device_bond_get_hw_address (NM_DEVICE_BOND (device));
|
2012-03-07 11:45:40 -06:00
|
|
|
else if (NM_IS_DEVICE_VLAN (device))
|
|
|
|
|
hwaddr = nm_device_vlan_get_hw_address (NM_DEVICE_VLAN (device));
|
2012-10-30 17:11:28 -05:00
|
|
|
else if (NM_IS_DEVICE_BRIDGE (device))
|
|
|
|
|
hwaddr = nm_device_bridge_get_hw_address (NM_DEVICE_BRIDGE (device));
|
2012-02-09 15:39:57 +01:00
|
|
|
|
2012-05-09 12:35:27 +02:00
|
|
|
state_str = g_strdup_printf ("%d (%s)", state, nmc_device_state_to_string (state));
|
|
|
|
|
reason_str = g_strdup_printf ("%d (%s)", reason, nmc_device_reason_to_string (reason));
|
2012-02-09 15:39:57 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[0].name; /* "GENERAL"*/
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[1].value = (char *) nm_device_get_iface (device);
|
|
|
|
|
nmc->allowed_fields[2].value = (char *) device_type_to_string (device);
|
|
|
|
|
nmc->allowed_fields[3].value = (char *) nm_device_get_vendor (device);
|
|
|
|
|
nmc->allowed_fields[4].value = (char *) nm_device_get_product (device);
|
|
|
|
|
nmc->allowed_fields[5].value = (char *) (nm_device_get_driver (device) ? nm_device_get_driver (device) : _("(unknown)"));
|
|
|
|
|
nmc->allowed_fields[6].value = (char *) nm_device_get_driver_version (device);
|
|
|
|
|
nmc->allowed_fields[7].value = (char *) nm_device_get_firmware_version (device);
|
|
|
|
|
nmc->allowed_fields[8].value = (char *) (hwaddr ? hwaddr : _("(unknown)"));
|
|
|
|
|
nmc->allowed_fields[9].value = (char *) state_str;
|
|
|
|
|
nmc->allowed_fields[10].value = (char *) reason_str;
|
|
|
|
|
nmc->allowed_fields[11].value = (char *) nm_device_get_udi (device);
|
|
|
|
|
nmc->allowed_fields[12].value = (char *) nm_device_get_ip_iface (device);
|
2012-06-08 13:44:43 +02:00
|
|
|
nmc->allowed_fields[13].value = nm_device_get_managed (device) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[14].value = nm_device_get_autoconnect (device) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[15].value = nm_device_get_firmware_missing (device) ? _("yes") : _("no");
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[16].value = (char *) ((acon = nm_device_get_active_connection (device)) ?
|
|
|
|
|
nm_object_get_path (NM_OBJECT (acon)) : _("not connected"));
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
2012-02-09 15:39:57 +01:00
|
|
|
g_free (state_str);
|
|
|
|
|
g_free (reason_str);
|
2010-03-24 19:05:35 +01:00
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* section CAPABILITIES */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[1].name)) {
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_cap;
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_CAP_ALL, nmc->allowed_fields, NULL);
|
2010-03-24 19:05:35 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
caps = nm_device_get_capabilities (device);
|
|
|
|
|
speed = 0;
|
|
|
|
|
if (NM_IS_DEVICE_ETHERNET (device)) {
|
|
|
|
|
/* Speed in Mb/s */
|
|
|
|
|
speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (device));
|
|
|
|
|
} else if (NM_IS_DEVICE_WIFI (device)) {
|
|
|
|
|
/* Speed in b/s */
|
|
|
|
|
speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device));
|
|
|
|
|
speed /= 1000;
|
|
|
|
|
}
|
|
|
|
|
if (speed)
|
|
|
|
|
speed_str = g_strdup_printf (_("%u Mb/s"), speed);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[1].name; /* "CAPABILITIES" */
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->allowed_fields[1].value = (caps & NM_DEVICE_CAP_CARRIER_DETECT) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[2].value = speed_str ? speed_str : _("unknown");
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
g_free (speed_str);
|
|
|
|
|
was_output = TRUE;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2012-10-22 14:31:11 +02:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* Wireless specific information */
|
|
|
|
|
if ((NM_IS_DEVICE_WIFI (device))) {
|
2011-02-21 16:38:02 +01:00
|
|
|
NMDeviceWifiCapabilities wcaps;
|
2010-03-24 19:05:35 +01:00
|
|
|
NMAccessPoint *active_ap = NULL;
|
|
|
|
|
const char *active_bssid = NULL;
|
|
|
|
|
const GPtrArray *aps;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* section WIFI-PROPERTIES */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[2].name)) {
|
2010-03-24 19:05:35 +01:00
|
|
|
wcaps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_wifi_prop;
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIFI_PROP_ALL, nmc->allowed_fields, NULL);
|
2010-03-24 19:05:35 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[2].name; /* "WIFI-PROPERTIES" */
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->allowed_fields[1].value = (wcaps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[2].value = (wcaps & NM_WIFI_DEVICE_CAP_WPA) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[3].value = (wcaps & NM_WIFI_DEVICE_CAP_RSN) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[4].value = (wcaps & NM_WIFI_DEVICE_CAP_CIPHER_TKIP) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[5].value = (wcaps & NM_WIFI_DEVICE_CAP_CIPHER_CCMP) ? _("yes") : _("no");
|
2013-02-12 09:55:21 +01:00
|
|
|
nmc->allowed_fields[6].value = (wcaps & NM_WIFI_DEVICE_CAP_AP) ? _("yes") : _("no");
|
|
|
|
|
nmc->allowed_fields[7].value = (wcaps & NM_WIFI_DEVICE_CAP_ADHOC) ? _("yes") : _("no");
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
/* section AP */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[3].name)) {
|
2010-03-25 13:39:49 -07:00
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
2010-03-24 19:05:35 +01:00
|
|
|
active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device));
|
2011-09-06 13:37:23 +02:00
|
|
|
active_bssid = active_ap ? nm_access_point_get_bssid (active_ap) : NULL;
|
2010-03-24 19:05:35 +01:00
|
|
|
}
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_wifi_list;
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
|
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_WIFI_LIST_FOR_DEV_LIST, nmc->allowed_fields, NULL);
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
info = g_malloc0 (sizeof (APInfo));
|
|
|
|
|
info->nmc = nmc;
|
|
|
|
|
info->index = 1;
|
|
|
|
|
info->active_bssid = active_bssid;
|
|
|
|
|
info->device = nm_device_get_iface (device);
|
|
|
|
|
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
|
|
|
|
|
if (aps && aps->len)
|
|
|
|
|
g_ptr_array_foreach ((GPtrArray *) aps, detail_access_point, (gpointer) info);
|
|
|
|
|
g_free (info);
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
|
|
|
|
} else if (NM_IS_DEVICE_ETHERNET (device)) {
|
|
|
|
|
/* WIRED-PROPERTIES */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[4].name)) {
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_wired_prop;
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIRED_PROP_ALL, nmc->allowed_fields, NULL);
|
2010-03-24 19:05:35 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[4].name; /* "WIRED-PROPERTIES" */
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->allowed_fields[1].value = (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) ? _("on") : _("off");
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
}
|
|
|
|
|
#if WITH_WIMAX
|
|
|
|
|
else if (NM_IS_DEVICE_WIMAX (device)) {
|
2011-01-06 17:01:55 -06:00
|
|
|
/* WIMAX-PROPERTIES */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[5].name)) {
|
2011-01-06 17:01:55 -06:00
|
|
|
char *cfreq = NULL, *rssi = NULL, *cinr = NULL, *txpow = NULL;
|
|
|
|
|
guint tmp_uint;
|
|
|
|
|
gint tmp_int;
|
2013-03-05 15:50:11 +01:00
|
|
|
char *bsid;
|
2011-01-06 17:01:55 -06:00
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_wimax_prop;
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_WIMAX_PROP_ALL, nmc->allowed_fields, NULL);
|
2011-01-06 17:01:55 -06:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[5].name; /* "WIMAX-PROPERTIES" */
|
2011-01-06 17:01:55 -06:00
|
|
|
|
|
|
|
|
/* Center frequency */
|
|
|
|
|
tmp_uint = nm_device_wimax_get_center_frequency (NM_DEVICE_WIMAX (device));
|
|
|
|
|
if (tmp_uint)
|
|
|
|
|
cfreq = g_strdup_printf ("%'.1f MHz", (double) tmp_uint / 1000.0);
|
|
|
|
|
nmc->allowed_fields[1].value = cfreq ? cfreq : "";
|
|
|
|
|
|
|
|
|
|
/* RSSI */
|
|
|
|
|
tmp_int = nm_device_wimax_get_rssi (NM_DEVICE_WIMAX (device));
|
|
|
|
|
if (tmp_int)
|
|
|
|
|
rssi = g_strdup_printf ("%d dBm", tmp_int);
|
|
|
|
|
nmc->allowed_fields[2].value = rssi ? rssi : "";
|
|
|
|
|
|
|
|
|
|
/* CINR */
|
|
|
|
|
tmp_int = nm_device_wimax_get_cinr (NM_DEVICE_WIMAX (device));
|
|
|
|
|
if (tmp_int)
|
|
|
|
|
cinr = g_strdup_printf ("%d dB", tmp_int);
|
|
|
|
|
nmc->allowed_fields[3].value = cinr ? cinr : "";
|
|
|
|
|
|
|
|
|
|
/* TX Power */
|
|
|
|
|
tmp_int = nm_device_wimax_get_tx_power (NM_DEVICE_WIMAX (device));
|
|
|
|
|
if (tmp_int)
|
|
|
|
|
txpow = g_strdup_printf ("%'.2f dBm", (float) tmp_int / 2.0);
|
|
|
|
|
nmc->allowed_fields[4].value = txpow ? txpow : "";
|
|
|
|
|
|
|
|
|
|
/* BSID */
|
2013-03-05 15:50:11 +01:00
|
|
|
bsid = (char *) nm_device_wimax_get_bsid (NM_DEVICE_WIMAX (device));
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->allowed_fields[5].value = bsid ? bsid : "";
|
|
|
|
|
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* section NSP */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[6].name)) {
|
2011-01-06 17:01:55 -06:00
|
|
|
const GPtrArray *nsps;
|
|
|
|
|
int g, idx = 1;
|
|
|
|
|
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_wimax_list;
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
|
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_WIMAX_LIST_FOR_DEV_LIST, nmc->allowed_fields, NULL);
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
|
|
|
|
|
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
|
|
|
|
|
for (g = 0; nsps && g < nsps->len; g++) {
|
|
|
|
|
NMWimaxNsp *nsp = g_ptr_array_index (nsps, g);
|
|
|
|
|
|
|
|
|
|
detail_wimax_nsp (nsp, nmc, device, idx++);
|
|
|
|
|
}
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
2010-03-24 19:05:35 +01:00
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2012-01-03 16:37:53 +01:00
|
|
|
/* IP configuration info */
|
2010-03-24 19:05:35 +01:00
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
2010-06-29 18:36:22 +02:00
|
|
|
NMIP4Config *cfg4 = nm_device_get_ip4_config (device);
|
|
|
|
|
NMIP6Config *cfg6 = nm_device_get_ip6_config (device);
|
2012-01-03 16:37:53 +01:00
|
|
|
NMDHCP4Config *dhcp4 = nm_device_get_dhcp4_config (device);
|
|
|
|
|
NMDHCP6Config *dhcp6 = nm_device_get_dhcp6_config (device);
|
2010-03-22 18:43:28 +01:00
|
|
|
|
2012-01-03 16:37:53 +01:00
|
|
|
/* IP4 */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (cfg4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[7].name))
|
|
|
|
|
was_output = print_ip4_config (cfg4, nmc, nmc_fields_dev_show_sections[7].name);
|
2010-03-24 19:05:35 +01:00
|
|
|
|
2012-01-03 16:37:53 +01:00
|
|
|
/* DHCP4 */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (dhcp4 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[8].name))
|
|
|
|
|
was_output = print_dhcp4_config (dhcp4, nmc, nmc_fields_dev_show_sections[8].name);
|
2010-06-29 18:36:22 +02:00
|
|
|
|
2012-01-03 16:37:53 +01:00
|
|
|
/* IP6 */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (cfg6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[9].name))
|
|
|
|
|
was_output = print_ip6_config (cfg6, nmc, nmc_fields_dev_show_sections[9].name);
|
2010-06-29 18:36:22 +02:00
|
|
|
|
2012-01-03 16:37:53 +01:00
|
|
|
/* DHCP6 */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (dhcp6 && !strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[10].name))
|
|
|
|
|
was_output = print_dhcp6_config (dhcp6, nmc, nmc_fields_dev_show_sections[10].name);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
2012-10-22 14:31:11 +02:00
|
|
|
|
|
|
|
|
/* Bond-specific information */
|
|
|
|
|
if ((NM_IS_DEVICE_BOND (device))) {
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[11].name)) {
|
2012-10-22 14:31:11 +02:00
|
|
|
const GPtrArray *slaves;
|
|
|
|
|
GString *bond_slaves_str;
|
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
|
|
bond_slaves_str = g_string_new (NULL);
|
|
|
|
|
slaves = nm_device_bond_get_slaves (NM_DEVICE_BOND (device));
|
|
|
|
|
for (idx = 0; slaves && idx < slaves->len; idx++) {
|
|
|
|
|
NMDevice *slave = g_ptr_array_index (slaves, idx);
|
|
|
|
|
const char *iface = nm_device_get_iface (slave);
|
|
|
|
|
|
2013-02-05 10:00:58 +01:00
|
|
|
if (iface) {
|
|
|
|
|
g_string_append (bond_slaves_str, iface);
|
|
|
|
|
g_string_append_c (bond_slaves_str, ' ');
|
|
|
|
|
}
|
2012-10-22 14:31:11 +02:00
|
|
|
}
|
|
|
|
|
if (bond_slaves_str->len > 0)
|
|
|
|
|
g_string_truncate (bond_slaves_str, bond_slaves_str->len-1); /* Chop off last space */
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_bond_prop;
|
2012-10-22 14:31:11 +02:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_BOND_PROP_ALL, nmc->allowed_fields, NULL);
|
2012-10-22 14:31:11 +02:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[11].name; /* "BOND" */
|
2012-10-22 14:31:11 +02:00
|
|
|
nmc->allowed_fields[1].value = bond_slaves_str->str;
|
|
|
|
|
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
|
|
|
|
|
g_string_free (bond_slaves_str, TRUE);
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 15:18:34 +02:00
|
|
|
/* VLAN-specific information */
|
|
|
|
|
if ((NM_IS_DEVICE_VLAN (device))) {
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[12].name)) {
|
2012-10-22 15:18:34 +02:00
|
|
|
char * vlan_id_str = g_strdup_printf ("%u", nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device)));
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_vlan_prop;
|
2012-10-22 15:18:34 +02:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL, nmc->allowed_fields, NULL);
|
2012-10-22 15:18:34 +02:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields[0].value = (char *) nmc_fields_dev_show_sections[12].name; /* "VLAN" */
|
2012-10-22 15:18:34 +02:00
|
|
|
nmc->allowed_fields[1].value = vlan_id_str;
|
|
|
|
|
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
|
|
|
|
|
g_free (vlan_id_str);
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 12:48:27 +02:00
|
|
|
/* section CONNECTIONS */
|
2013-04-03 10:01:42 +02:00
|
|
|
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[13].name)) {
|
2012-08-31 12:48:27 +02:00
|
|
|
const GPtrArray *avail_cons;
|
|
|
|
|
GString *ac_paths_str;
|
|
|
|
|
char **ac_arr = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->allowed_fields = nmc_fields_dev_show_connections;
|
2012-08-31 12:48:27 +02:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_DEV_SHOW_CONNECTIONS_ALL, nmc->allowed_fields, NULL);
|
2012-08-31 12:48:27 +02:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
|
|
|
|
|
/* available-connections */
|
|
|
|
|
avail_cons = nm_device_get_available_connections (device);
|
|
|
|
|
ac_paths_str = g_string_new (NULL);
|
2013-02-26 11:44:22 +01:00
|
|
|
if (avail_cons && avail_cons->len) {
|
2012-08-31 12:48:27 +02:00
|
|
|
ac_arr = g_new (char *, avail_cons->len + 1);
|
|
|
|
|
ac_arr[avail_cons->len] = NULL;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; avail_cons && (i < avail_cons->len); i++) {
|
|
|
|
|
NMRemoteConnection *avail_con = g_ptr_array_index (avail_cons, i);
|
|
|
|
|
const char *ac_path = nm_connection_get_path (NM_CONNECTION (avail_con));
|
|
|
|
|
const char *ac_id = nm_connection_get_id (NM_CONNECTION (avail_con));
|
|
|
|
|
const char *ac_uuid = nm_connection_get_uuid (NM_CONNECTION (avail_con));
|
|
|
|
|
|
|
|
|
|
ac_arr[i] = g_strdup_printf ("%s | %s", ac_uuid, ac_id);
|
|
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
|
g_string_printf (ac_paths_str, "%s/{", NM_DBUS_PATH_SETTINGS);
|
|
|
|
|
else
|
|
|
|
|
g_string_append_c (ac_paths_str, ',');
|
|
|
|
|
g_string_append (ac_paths_str, strrchr (ac_path, '/') + 1);
|
|
|
|
|
}
|
|
|
|
|
if (ac_paths_str->len > 0)
|
|
|
|
|
g_string_append_c (ac_paths_str, '}');
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
set_val_str (nmc->allowed_fields, 0, (char *) nmc_fields_dev_show_sections[13].name); /* "CONNECTIONS" */
|
2012-08-31 12:48:27 +02:00
|
|
|
set_val_str (nmc->allowed_fields, 1, ac_paths_str->str);
|
2013-03-05 15:50:11 +01:00
|
|
|
set_val_arr (nmc->allowed_fields, 2, ac_arr);
|
2012-08-31 12:48:27 +02:00
|
|
|
|
|
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
|
|
|
|
|
|
|
|
|
|
g_string_free (ac_paths_str, TRUE);
|
|
|
|
|
g_strfreev (ac_arr);
|
|
|
|
|
was_output = TRUE;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
if (sections_array)
|
|
|
|
|
g_array_free (sections_array, TRUE);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_device_status (NMDevice *device, NmCli *nmc)
|
|
|
|
|
{
|
2013-03-05 15:50:11 +01:00
|
|
|
nmc->allowed_fields[0].value = (char *) nm_device_get_iface (device);
|
|
|
|
|
nmc->allowed_fields[1].value = (char *) device_type_to_string (device);
|
|
|
|
|
nmc->allowed_fields[2].value = (char *) nmc_device_state_to_string (nm_device_get_state (device));
|
|
|
|
|
nmc->allowed_fields[3].value = (char *) nm_object_get_path (NM_OBJECT (device));
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
|
2010-03-18 15:39:15 +01:00
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_devices_status (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2010-03-18 15:39:15 +01:00
|
|
|
GError *error = NULL;
|
2010-02-25 09:52:30 -08:00
|
|
|
const GPtrArray *devices;
|
|
|
|
|
int i;
|
2010-03-18 15:39:15 +01:00
|
|
|
char *fields_str;
|
|
|
|
|
char *fields_all = NMC_FIELDS_DEV_STATUS_ALL;
|
|
|
|
|
char *fields_common = NMC_FIELDS_DEV_STATUS_COMMON;
|
|
|
|
|
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
|
|
|
|
|
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
|
|
|
|
|
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
while (argc > 0) {
|
|
|
|
|
fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
2010-03-24 19:05:35 +01:00
|
|
|
else
|
2010-03-18 15:39:15 +01:00
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_status;
|
|
|
|
|
nmc->print_fields.indices = parse_output_fields (fields_str, nmc->allowed_fields, &error);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2010-03-20 14:08:06 +01:00
|
|
|
if (error->code == 0)
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device status': %s"), error->message);
|
2010-03-20 14:08:06 +01:00
|
|
|
else
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device status': %s; allowed fields: %s"),
|
|
|
|
|
error->message, NMC_FIELDS_DEV_STATUS_ALL);
|
2010-03-18 15:39:15 +01:00
|
|
|
g_error_free (error);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-03-18 15:39:15 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2011-02-10 14:21:18 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-16 17:36:50 +01:00
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
2011-02-10 14:21:18 +01:00
|
|
|
/* Print headers */
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
|
2010-03-18 15:39:15 +01:00
|
|
|
nmc->print_fields.header_name = _("Status of devices");
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2011-02-10 14:21:18 +01:00
|
|
|
devices = nm_client_get_devices (nmc->client);
|
2010-02-25 09:52:30 -08:00
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *device = g_ptr_array_index (devices, i);
|
|
|
|
|
show_device_status (device, nmc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NMC_RESULT_SUCCESS;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
2013-04-03 10:01:42 +02:00
|
|
|
do_devices_show (NmCli *nmc, int argc, char **argv)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
NMDevice *device = NULL;
|
|
|
|
|
const char *iface = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
if (argc == 1)
|
|
|
|
|
iface = *argv;
|
|
|
|
|
else if (argc > 1) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: invalid extra argument '%s'."), *(argv+1));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2010-02-25 09:52:30 -08:00
|
|
|
goto error;
|
2011-02-10 14:21:18 +01:00
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2011-02-16 17:36:50 +01:00
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
devices = nm_client_get_devices (nmc->client);
|
|
|
|
|
|
2013-04-03 10:01:42 +02:00
|
|
|
if (iface) {
|
|
|
|
|
/* Interface specified; show details only for the device */
|
2010-02-25 09:52:30 -08:00
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *candidate = g_ptr_array_index (devices, i);
|
|
|
|
|
const char *dev_iface = nm_device_get_iface (candidate);
|
|
|
|
|
|
2013-02-05 10:00:58 +01:00
|
|
|
if (!g_strcmp0 (dev_iface, iface))
|
2010-02-25 09:52:30 -08:00
|
|
|
device = candidate;
|
|
|
|
|
}
|
|
|
|
|
if (!device) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), iface);
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2010-03-18 15:39:15 +01:00
|
|
|
show_device_info (device, nmc);
|
2010-02-25 09:52:30 -08:00
|
|
|
} else {
|
2013-04-03 10:01:42 +02:00
|
|
|
/* Show details for all devices */
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *dev = g_ptr_array_index (devices, i);
|
|
|
|
|
|
|
|
|
|
show_device_info (dev, nmc);
|
|
|
|
|
if (i != devices->len-1)
|
|
|
|
|
printf ("\n"); /* Empty line */
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
NMDeviceState state;
|
|
|
|
|
|
|
|
|
|
state = nm_device_get_state (device);
|
|
|
|
|
|
|
|
|
|
if (state == NM_DEVICE_STATE_DISCONNECTED) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Success: Device '%s' successfully disconnected."), nm_device_get_iface (device));
|
|
|
|
|
quit ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
timeout_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* Time expired -> exit nmcli */
|
|
|
|
|
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Timeout %d sec expired."), nmc->timeout);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_TIMEOUT_EXPIRED;
|
|
|
|
|
quit ();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 11:54:52 +02:00
|
|
|
static gboolean
|
|
|
|
|
progress_cb (gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = (NMDevice *) user_data;
|
|
|
|
|
|
2012-05-09 12:35:27 +02:00
|
|
|
nmc_terminal_show_progress (device ? nmc_device_state_to_string (nm_device_get_state (device)) : "");
|
2012-05-03 11:54:52 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
static void
|
|
|
|
|
disconnect_device_cb (NMDevice *device, GError *error, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
NMDeviceState state;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' (%s) disconnecting failed: %s"),
|
|
|
|
|
nm_device_get_iface (device),
|
|
|
|
|
nm_object_get_path (NM_OBJECT (device)),
|
|
|
|
|
error->message ? error->message : _("(unknown)"));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_DEV_DISCONNECT;
|
|
|
|
|
quit ();
|
|
|
|
|
} else {
|
|
|
|
|
state = nm_device_get_state (device);
|
|
|
|
|
|
2010-07-29 16:16:20 +02:00
|
|
|
if (nmc->nowait_flag || state == NM_DEVICE_STATE_DISCONNECTED) {
|
2010-02-25 09:52:30 -08:00
|
|
|
/* Don't want to wait or device already disconnected */
|
2012-05-03 11:54:52 +02:00
|
|
|
if (state == NM_DEVICE_STATE_DISCONNECTED && nmc->print_output == NMC_PRINT_PRETTY) {
|
|
|
|
|
nmc_terminal_erase_line ();
|
|
|
|
|
printf (_("Device '%s' has been disconnected.\n"), nm_device_get_iface (device));
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
quit ();
|
|
|
|
|
} else {
|
|
|
|
|
g_signal_connect (device, "notify::state", G_CALLBACK (device_state_cb), nmc);
|
|
|
|
|
/* Start timer not to loop forever if "notify::state" signal is not issued */
|
|
|
|
|
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_disconnect (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
NMDevice *device = NULL;
|
|
|
|
|
const char *iface = NULL;
|
2012-11-23 12:54:30 +01:00
|
|
|
char *iface_ask = NULL;
|
2010-02-25 09:52:30 -08:00
|
|
|
gboolean wait = TRUE;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Set default timeout for disconnect operation */
|
|
|
|
|
nmc->timeout = 10;
|
|
|
|
|
|
2012-11-23 12:54:30 +01:00
|
|
|
if (argc == 0) {
|
|
|
|
|
if (nmc->ask) {
|
|
|
|
|
iface_ask = nmc_get_user_input ("Interface: ");
|
|
|
|
|
iface = iface_ask;
|
|
|
|
|
// TODO: list available devices when just Enter is pressed ?
|
|
|
|
|
}
|
|
|
|
|
if (!iface_ask) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No interface specified."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2013-04-02 19:18:32 +02:00
|
|
|
iface = *argv;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-02 19:18:32 +02:00
|
|
|
if (!iface) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No interface specified."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
next_arg (&argc, &argv);
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-02 19:18:32 +02:00
|
|
|
while (argc > 0) {
|
|
|
|
|
if (strcmp (*argv, "--nowait") == 0) {
|
|
|
|
|
wait = FALSE;
|
|
|
|
|
} else if (strcmp (*argv, "--timeout") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2013-04-02 19:18:32 +02:00
|
|
|
errno = 0;
|
|
|
|
|
nmc->timeout = strtol (*argv, NULL, 10);
|
|
|
|
|
if (errno || nmc->timeout < 0) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2013-04-02 19:18:32 +02:00
|
|
|
} else {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: unknown argument '%s'."), *argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2013-04-02 19:18:32 +02:00
|
|
|
next_arg (&argc, &argv);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2010-02-25 09:52:30 -08:00
|
|
|
goto error;
|
2011-02-10 14:21:18 +01:00
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
2011-02-16 17:36:50 +01:00
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
devices = nm_client_get_devices (nmc->client);
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *candidate = g_ptr_array_index (devices, i);
|
|
|
|
|
const char *dev_iface = nm_device_get_iface (candidate);
|
|
|
|
|
|
2013-02-05 10:00:58 +01:00
|
|
|
if (!g_strcmp0 (dev_iface, iface))
|
2010-02-25 09:52:30 -08:00
|
|
|
device = candidate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), iface);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-29 16:16:20 +02:00
|
|
|
/* Use nowait_flag instead of should_wait because exitting has to be postponed till disconnect_device_cb()
|
|
|
|
|
* is called, giving NM time to check our permissions */
|
|
|
|
|
nmc->nowait_flag = !wait;
|
|
|
|
|
nmc->should_wait = TRUE;
|
2010-02-25 09:52:30 -08:00
|
|
|
nm_device_disconnect (device, disconnect_device_cb, nmc);
|
|
|
|
|
|
2012-05-03 11:54:52 +02:00
|
|
|
/* Start progress indication */
|
|
|
|
|
if (nmc->print_output == NMC_PRINT_PRETTY)
|
|
|
|
|
progress_id = g_timeout_add (120, progress_cb, device);
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
error:
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2010-03-18 15:39:15 +01:00
|
|
|
show_acces_point_info (NMDevice *device, NmCli *nmc)
|
2010-02-25 09:52:30 -08:00
|
|
|
{
|
|
|
|
|
NMAccessPoint *active_ap = NULL;
|
|
|
|
|
const char *active_bssid = NULL;
|
|
|
|
|
const GPtrArray *aps;
|
2010-03-18 15:39:15 +01:00
|
|
|
APInfo *info;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
|
|
|
|
|
active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device));
|
2011-09-06 13:37:23 +02:00
|
|
|
active_bssid = active_ap ? nm_access_point_get_bssid (active_ap) : NULL;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
info = g_malloc0 (sizeof (APInfo));
|
|
|
|
|
info->nmc = nmc;
|
2010-03-24 19:05:35 +01:00
|
|
|
info->index = 1;
|
2010-03-18 15:39:15 +01:00
|
|
|
info->active_bssid = active_bssid;
|
|
|
|
|
info->device = nm_device_get_iface (device);
|
2010-02-25 09:52:30 -08:00
|
|
|
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
|
|
|
|
|
if (aps && aps->len)
|
2010-03-18 15:39:15 +01:00
|
|
|
g_ptr_array_foreach ((GPtrArray *) aps, detail_access_point, (gpointer) info);
|
|
|
|
|
g_free (info);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wifi_list (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2010-03-18 15:39:15 +01:00
|
|
|
GError *error = NULL;
|
2010-02-25 09:52:30 -08:00
|
|
|
NMDevice *device = NULL;
|
2010-03-18 15:39:15 +01:00
|
|
|
NMAccessPoint *ap = NULL;
|
2010-02-25 09:52:30 -08:00
|
|
|
const char *iface = NULL;
|
2011-09-06 13:37:23 +02:00
|
|
|
const char *bssid_user = NULL;
|
2010-03-18 15:39:15 +01:00
|
|
|
const GPtrArray *devices;
|
|
|
|
|
const GPtrArray *aps;
|
|
|
|
|
APInfo *info;
|
|
|
|
|
int i, j;
|
|
|
|
|
char *fields_str;
|
|
|
|
|
char *fields_all = NMC_FIELDS_DEV_WIFI_LIST_ALL;
|
|
|
|
|
char *fields_common = NMC_FIELDS_DEV_WIFI_LIST_COMMON;
|
|
|
|
|
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
|
|
|
|
|
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
|
|
|
|
|
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
while (argc > 0) {
|
|
|
|
|
if (strcmp (*argv, "iface") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-02-25 09:52:30 -08:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
iface = *argv;
|
2011-09-06 13:37:23 +02:00
|
|
|
} else if (strcmp (*argv, "bssid") == 0 || strcmp (*argv, "hwaddr") == 0) {
|
|
|
|
|
/* hwaddr is deprecated and will be removed later */
|
2010-03-18 15:39:15 +01:00
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-03-18 15:39:15 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
2011-09-06 13:37:23 +02:00
|
|
|
bssid_user = *argv;
|
2010-02-25 09:52:30 -08:00
|
|
|
} else {
|
|
|
|
|
fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
2010-03-24 19:05:35 +01:00
|
|
|
else
|
2010-03-18 15:39:15 +01:00
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_wifi_list;
|
|
|
|
|
nmc->print_fields.indices = parse_output_fields (fields_str, nmc->allowed_fields, &error);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
2010-03-20 14:08:06 +01:00
|
|
|
if (error->code == 0)
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s"), error->message);
|
2010-03-20 14:08:06 +01:00
|
|
|
else
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wifi': %s; allowed fields: %s"),
|
|
|
|
|
error->message, NMC_FIELDS_DEV_WIFI_LIST_ALL);
|
2010-03-18 15:39:15 +01:00
|
|
|
g_error_free (error);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-03-18 15:39:15 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2011-02-10 14:21:18 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-16 17:36:50 +01:00
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
2011-02-10 14:21:18 +01:00
|
|
|
/* Print headers */
|
2010-03-24 19:05:35 +01:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
|
2013-04-03 10:15:00 +02:00
|
|
|
nmc->print_fields.header_name = _("Wi-Fi scan list");
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2011-02-10 14:21:18 +01:00
|
|
|
devices = nm_client_get_devices (nmc->client);
|
2010-03-18 15:39:15 +01:00
|
|
|
if (iface) {
|
|
|
|
|
/* Device specified - list only APs of this interface */
|
2010-02-25 09:52:30 -08:00
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *candidate = g_ptr_array_index (devices, i);
|
|
|
|
|
const char *dev_iface = nm_device_get_iface (candidate);
|
|
|
|
|
|
2013-02-05 10:00:58 +01:00
|
|
|
if (!g_strcmp0 (dev_iface, iface)) {
|
2010-02-25 09:52:30 -08:00
|
|
|
device = candidate;
|
2010-03-18 15:39:15 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), iface);
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 15:39:15 +01:00
|
|
|
if (NM_IS_DEVICE_WIFI (device)) {
|
2011-09-06 13:37:23 +02:00
|
|
|
if (bssid_user) {
|
2010-03-18 15:39:15 +01:00
|
|
|
/* Specific AP requested - list only that */
|
|
|
|
|
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
|
|
|
|
|
for (j = 0; aps && (j < aps->len); j++) {
|
2011-09-06 13:37:23 +02:00
|
|
|
char *bssid_up;
|
2010-03-18 15:39:15 +01:00
|
|
|
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j);
|
2011-09-06 13:37:23 +02:00
|
|
|
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2011-09-06 13:37:23 +02:00
|
|
|
bssid_up = g_ascii_strup (bssid_user, -1);
|
|
|
|
|
if (!strcmp (bssid_up, candidate_bssid))
|
2010-03-18 15:39:15 +01:00
|
|
|
ap = candidate_ap;
|
2011-09-06 13:37:23 +02:00
|
|
|
g_free (bssid_up);
|
2010-03-18 15:39:15 +01:00
|
|
|
}
|
|
|
|
|
if (!ap) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."), bssid_user);
|
2010-03-18 15:39:15 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
info = g_malloc0 (sizeof (APInfo));
|
|
|
|
|
info->nmc = nmc;
|
2010-03-24 19:05:35 +01:00
|
|
|
info->index = 1;
|
2010-03-18 15:39:15 +01:00
|
|
|
info->active_bssid = NULL;
|
|
|
|
|
info->device = nm_device_get_iface (device);
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
detail_access_point (ap, info);
|
|
|
|
|
g_free (info);
|
|
|
|
|
} else {
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
show_acces_point_info (device, nmc);
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
} else {
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' is not a Wi-Fi device."), iface);
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-03-18 15:39:15 +01:00
|
|
|
/* List APs for all devices */
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
2011-09-06 13:37:23 +02:00
|
|
|
if (bssid_user) {
|
2010-03-18 15:39:15 +01:00
|
|
|
/* Specific AP requested - list only that */
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *dev = g_ptr_array_index (devices, i);
|
|
|
|
|
|
|
|
|
|
if (!NM_IS_DEVICE_WIFI (dev))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (dev));
|
|
|
|
|
for (j = 0; aps && (j < aps->len); j++) {
|
2011-09-06 13:37:23 +02:00
|
|
|
char *bssid_up;
|
2010-03-18 15:39:15 +01:00
|
|
|
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, j);
|
2011-09-06 13:37:23 +02:00
|
|
|
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
|
2010-03-18 15:39:15 +01:00
|
|
|
|
2011-09-06 13:37:23 +02:00
|
|
|
bssid_up = g_ascii_strup (bssid_user, -1);
|
|
|
|
|
if (!strcmp (bssid_up, candidate_bssid)) {
|
2010-03-18 15:39:15 +01:00
|
|
|
ap = candidate_ap;
|
|
|
|
|
|
|
|
|
|
info = g_malloc0 (sizeof (APInfo));
|
|
|
|
|
info->nmc = nmc;
|
2010-03-24 19:05:35 +01:00
|
|
|
info->index = 1;
|
2010-03-18 15:39:15 +01:00
|
|
|
info->active_bssid = NULL;
|
|
|
|
|
info->device = nm_device_get_iface (dev);
|
|
|
|
|
detail_access_point (ap, info);
|
|
|
|
|
g_free (info);
|
|
|
|
|
}
|
2011-09-06 13:37:23 +02:00
|
|
|
g_free (bssid_up);
|
2010-03-18 15:39:15 +01:00
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
2010-03-18 15:39:15 +01:00
|
|
|
if (!ap) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Access point with bssid '%s' not found."), bssid_user);
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-03-18 15:39:15 +01:00
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *dev = g_ptr_array_index (devices, i);
|
|
|
|
|
if (NM_IS_DEVICE_WIFI (dev))
|
|
|
|
|
show_acces_point_info (dev, nmc);
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-28 22:32:21 +01:00
|
|
|
static void
|
|
|
|
|
monitor_device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
NMDeviceState state;
|
|
|
|
|
NMDeviceStateReason reason;
|
|
|
|
|
|
|
|
|
|
state = nm_device_get_state_reason (device, &reason);
|
|
|
|
|
|
|
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
|
|
|
|
if (nmc->print_output == NMC_PRINT_PRETTY) {
|
|
|
|
|
NMActiveConnection *active = nm_device_get_active_connection (device);
|
|
|
|
|
|
|
|
|
|
nmc_terminal_erase_line ();
|
|
|
|
|
printf (_("Connection with UUID '%s' created and activated on device '%s'\n"),
|
|
|
|
|
nm_active_connection_get_uuid (active), nm_device_get_iface (device));
|
|
|
|
|
}
|
|
|
|
|
quit ();
|
|
|
|
|
} else if (state == NM_DEVICE_STATE_FAILED) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Connection activation failed: (%d) %s."),
|
2012-05-09 12:35:27 +02:00
|
|
|
reason, nmc_device_reason_to_string (reason));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
|
|
|
|
|
quit ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
NmCli *nmc;
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
} AddAndActivateInfo;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_and_activate_cb (NMClient *client,
|
|
|
|
|
NMActiveConnection *active,
|
|
|
|
|
const char *connection_path,
|
|
|
|
|
GError *error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
AddAndActivateInfo *info = (AddAndActivateInfo *) user_data;
|
|
|
|
|
NmCli *nmc = info->nmc;
|
|
|
|
|
NMDevice *device = info->device;
|
|
|
|
|
NMActiveConnectionState state;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Failed to add/activate new connection: (%d) %s"),
|
|
|
|
|
error->code, error->message);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
|
|
|
|
|
quit ();
|
|
|
|
|
} else {
|
|
|
|
|
state = nm_active_connection_get_state (active);
|
|
|
|
|
|
|
|
|
|
if (state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Failed to add/activate new connection: Unknown error"));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
|
|
|
|
|
quit ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
|
|
|
|
|
/* User doesn't want to wait or already activated */
|
|
|
|
|
if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED && nmc->print_output == NMC_PRINT_PRETTY) {
|
|
|
|
|
printf (_("Connection with UUID '%s' created and activated on device '%s'\n"),
|
|
|
|
|
nm_active_connection_get_uuid (active), nm_device_get_iface (device));
|
|
|
|
|
}
|
|
|
|
|
quit ();
|
|
|
|
|
} else {
|
|
|
|
|
g_signal_connect (device, "notify::state", G_CALLBACK (monitor_device_state_cb), nmc);
|
|
|
|
|
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc); /* Exit if timeout expires */
|
|
|
|
|
|
|
|
|
|
if (nmc->print_output == NMC_PRINT_PRETTY)
|
|
|
|
|
progress_id = g_timeout_add (120, progress_cb, device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find a Wi-Fi device with 'iface' in 'devices' array. If 'iface' is NULL,
|
|
|
|
|
* the first Wi-Fi device is returned. 'idx' parameter is updated to the point
|
|
|
|
|
* where the function finished so that the function can be called repeatedly
|
|
|
|
|
* to get next matching device.
|
|
|
|
|
* Returns: found device or NULL
|
|
|
|
|
*/
|
|
|
|
|
static NMDevice *
|
|
|
|
|
find_wifi_device_by_iface (const GPtrArray *devices, const char *iface, int *idx)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = *idx; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *candidate = g_ptr_array_index (devices, i);
|
|
|
|
|
const char *dev_iface = nm_device_get_iface (candidate);
|
|
|
|
|
|
|
|
|
|
if (!NM_IS_DEVICE_WIFI (candidate))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (iface) {
|
|
|
|
|
/* If a iface was specified then use it. */
|
2013-02-05 10:00:58 +01:00
|
|
|
if (g_strcmp0 (dev_iface, iface) == 0) {
|
2012-04-28 22:32:21 +01:00
|
|
|
device = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Else return the first Wi-Fi device. */
|
|
|
|
|
device = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*idx = i + 1;
|
|
|
|
|
return device;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Find AP on 'device' according to 'bssid' or 'ssid' parameter.
|
|
|
|
|
* Returns: found AP or NULL
|
|
|
|
|
*/
|
|
|
|
|
static NMAccessPoint *
|
|
|
|
|
find_ap_on_device (NMDevice *device, GByteArray *bssid, const char *ssid)
|
|
|
|
|
{
|
|
|
|
|
const GPtrArray *aps;
|
|
|
|
|
NMAccessPoint *ap = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL);
|
|
|
|
|
g_return_val_if_fail ((bssid && !ssid) || (!bssid && ssid), NULL);
|
|
|
|
|
|
|
|
|
|
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
|
|
|
|
|
for (i = 0; aps && (i < aps->len); i++) {
|
|
|
|
|
NMAccessPoint *candidate_ap = g_ptr_array_index (aps, i);
|
|
|
|
|
|
|
|
|
|
if (ssid) {
|
|
|
|
|
/* Parameter is SSID */
|
|
|
|
|
const GByteArray *candidate_ssid = nm_access_point_get_ssid (candidate_ap);
|
|
|
|
|
char *ssid_tmp = nm_utils_ssid_to_utf8 (candidate_ssid);
|
|
|
|
|
|
|
|
|
|
/* Compare SSIDs */
|
|
|
|
|
if (strcmp (ssid, ssid_tmp) == 0) {
|
|
|
|
|
ap = candidate_ap;
|
|
|
|
|
g_free (ssid_tmp);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_free (ssid_tmp);
|
|
|
|
|
} else if (bssid) {
|
|
|
|
|
/* Parameter is BSSID */
|
|
|
|
|
const char *candidate_bssid = nm_access_point_get_bssid (candidate_ap);
|
|
|
|
|
char *bssid_up = nm_utils_hwaddr_ntoa (bssid->data, ARPHRD_ETHER);
|
|
|
|
|
|
|
|
|
|
/* Compare BSSIDs */
|
|
|
|
|
if (strcmp (bssid_up, candidate_bssid) == 0) {
|
|
|
|
|
ap = candidate_ap;
|
|
|
|
|
g_free (bssid_up);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_free (bssid_up);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wifi_connect_network (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device = NULL;
|
|
|
|
|
NMAccessPoint *ap = NULL;
|
2012-11-22 14:32:45 +01:00
|
|
|
NM80211ApFlags ap_flags;
|
|
|
|
|
NM80211ApSecurityFlags ap_wpa_flags;
|
|
|
|
|
NM80211ApSecurityFlags ap_rsn_flags;
|
2012-04-28 22:32:21 +01:00
|
|
|
NMConnection *connection = NULL;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSettingWireless *s_wifi;
|
|
|
|
|
NMSettingWirelessSecurity *s_wsec;
|
|
|
|
|
AddAndActivateInfo *info;
|
|
|
|
|
const char *param_user = NULL;
|
|
|
|
|
const char *iface = NULL;
|
|
|
|
|
const char *bssid = NULL;
|
|
|
|
|
const char *password = NULL;
|
|
|
|
|
const char *con_name = NULL;
|
|
|
|
|
gboolean private = FALSE;
|
|
|
|
|
gboolean wait = TRUE;
|
|
|
|
|
gboolean wep_passphrase = FALSE;
|
|
|
|
|
GByteArray *bssid1_arr = NULL;
|
|
|
|
|
GByteArray *bssid2_arr = NULL;
|
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
int devices_idx;
|
2012-11-22 14:32:45 +01:00
|
|
|
char *ssid_ask = NULL;
|
|
|
|
|
char *passwd_ask = NULL;
|
2012-04-28 22:32:21 +01:00
|
|
|
|
|
|
|
|
/* Default timeout for waiting for operation completion */
|
|
|
|
|
nmc->timeout = 90;
|
|
|
|
|
|
|
|
|
|
/* Get the first compulsory argument (SSID or BSSID) */
|
|
|
|
|
if (argc > 0) {
|
|
|
|
|
param_user = *argv;
|
|
|
|
|
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ARPHRD_ETHER);
|
|
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
} else {
|
2012-11-22 14:32:45 +01:00
|
|
|
if (nmc->ask) {
|
|
|
|
|
ssid_ask = nmc_get_user_input ("SSID or BSSID: ");
|
|
|
|
|
param_user = ssid_ask ? ssid_ask : "";
|
|
|
|
|
bssid1_arr = nm_utils_hwaddr_atoba (param_user, ARPHRD_ETHER);
|
|
|
|
|
}
|
|
|
|
|
if (!ssid_ask) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: SSID or BSSID are missing."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
2012-04-28 22:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the rest of the parameters */
|
|
|
|
|
while (argc > 0) {
|
|
|
|
|
if (strcmp (*argv, "iface") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
iface = *argv;
|
|
|
|
|
} else if (strcmp (*argv, "bssid") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
bssid = *argv;
|
|
|
|
|
bssid2_arr = nm_utils_hwaddr_atoba (bssid, ARPHRD_ETHER);
|
|
|
|
|
if (!bssid2_arr) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: bssid argument value '%s' is not a valid BSSID."),
|
|
|
|
|
bssid);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else if (strcmp (*argv, "password") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
password = *argv;
|
|
|
|
|
} else if (strcmp (*argv, "wep-key-type") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (strcmp (*argv, "key") == 0)
|
|
|
|
|
wep_passphrase = FALSE;
|
|
|
|
|
else if (strcmp (*argv, "phrase") == 0)
|
|
|
|
|
wep_passphrase = TRUE;
|
|
|
|
|
else {
|
|
|
|
|
g_string_printf (nmc->return_text,
|
|
|
|
|
_("Error: wep-key-type argument value '%s' is invalid, use 'key' or 'phrase'."),
|
|
|
|
|
*argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else if (strcmp (*argv, "name") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
con_name = *argv;
|
|
|
|
|
} else if (strcmp (*argv, "--private") == 0) {
|
|
|
|
|
private = TRUE;
|
|
|
|
|
} else if (strcmp (*argv, "--nowait") == 0) {
|
|
|
|
|
wait = FALSE;
|
|
|
|
|
} else if (strcmp (*argv, "--timeout") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2012-04-28 22:32:21 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
nmc->timeout = strtol (*argv, NULL, 10);
|
|
|
|
|
if (errno || nmc->timeout < 0) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Verify SSID/BSSID parameters */
|
|
|
|
|
if (bssid1_arr && bssid2_arr && memcmp (bssid1_arr->data, bssid2_arr->data, ETH_ALEN)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: BSSID to connect to (%s) differs from bssid argument (%s)."),
|
|
|
|
|
param_user, bssid);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
if (!bssid1_arr && strlen (param_user) > 32) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Parameter '%s' is neither SSID nor BSSID."), param_user);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2012-04-28 22:32:21 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
devices = nm_client_get_devices (nmc->client);
|
|
|
|
|
|
|
|
|
|
/* Find a device to activate the connection on */
|
|
|
|
|
devices_idx = 0;
|
|
|
|
|
device = find_wifi_device_by_iface (devices, iface, &devices_idx);
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
|
|
|
|
if (iface)
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' is not a Wi-Fi device."), iface);
|
|
|
|
|
else
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No Wi-Fi device found."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find an AP to connect to */
|
|
|
|
|
ap = find_ap_on_device (device, bssid1_arr, bssid1_arr ? NULL : param_user);
|
|
|
|
|
if (!ap && !iface) {
|
|
|
|
|
/* AP not found. iface was not specified, so try finding the AP on another device. */
|
|
|
|
|
while ((device = find_wifi_device_by_iface (devices, NULL, &devices_idx)) != NULL) {
|
|
|
|
|
ap = find_ap_on_device (device, bssid1_arr, bssid1_arr ? NULL : param_user);
|
|
|
|
|
if (ap)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ap) {
|
|
|
|
|
if (!bssid1_arr)
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No network with SSID '%s' found."), param_user);
|
|
|
|
|
else
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No access point with BSSID '%s' found."), param_user);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If there are some connection data from user, create a connection and
|
|
|
|
|
* fill them into proper settings. */
|
|
|
|
|
if (con_name || private || bssid2_arr || password)
|
|
|
|
|
connection = nm_connection_new ();
|
|
|
|
|
|
|
|
|
|
if (con_name || private) {
|
|
|
|
|
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
|
|
|
|
|
|
|
|
|
/* Set user provided connection name */
|
|
|
|
|
if (con_name)
|
|
|
|
|
g_object_set (s_con, NM_SETTING_CONNECTION_ID, con_name, NULL);
|
|
|
|
|
|
|
|
|
|
/* Connection will only be visible to this user when '--private' is specified */
|
|
|
|
|
if (private)
|
|
|
|
|
nm_setting_connection_add_permission (s_con, "user", g_get_user_name (), NULL);
|
|
|
|
|
}
|
|
|
|
|
if (bssid2_arr) {
|
|
|
|
|
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
|
|
|
|
|
|
|
|
|
|
/* 'bssid' parameter is used to restrict the conenction only to the BSSID */
|
|
|
|
|
g_object_set (s_wifi, NM_SETTING_WIRELESS_BSSID, bssid2_arr, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 14:32:45 +01:00
|
|
|
/* handle password */
|
|
|
|
|
ap_flags = nm_access_point_get_flags (ap);
|
|
|
|
|
ap_wpa_flags = nm_access_point_get_wpa_flags (ap);
|
|
|
|
|
ap_rsn_flags = nm_access_point_get_rsn_flags (ap);
|
|
|
|
|
|
|
|
|
|
/* Set password for WEP or WPA-PSK. */
|
|
|
|
|
if (ap_flags & NM_802_11_AP_FLAGS_PRIVACY) {
|
|
|
|
|
/* Ask for missing password when one is expected and '--ask' is used */
|
|
|
|
|
if (!password && nmc->ask)
|
|
|
|
|
password = passwd_ask = nmc_get_user_input ("Password: ");
|
|
|
|
|
|
|
|
|
|
if (password) {
|
|
|
|
|
if (!connection)
|
|
|
|
|
connection = nm_connection_new ();
|
|
|
|
|
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
2012-04-28 22:32:21 +01:00
|
|
|
|
2012-11-22 14:32:45 +01:00
|
|
|
if (ap_wpa_flags == NM_802_11_AP_SEC_NONE && ap_rsn_flags == NM_802_11_AP_SEC_NONE) {
|
2012-04-28 22:32:21 +01:00
|
|
|
/* WEP */
|
|
|
|
|
nm_setting_wireless_security_set_wep_key (s_wsec, 0, password);
|
|
|
|
|
g_object_set (G_OBJECT (s_wsec),
|
|
|
|
|
NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE,
|
|
|
|
|
wep_passphrase ? NM_WEP_KEY_TYPE_PASSPHRASE: NM_WEP_KEY_TYPE_KEY,
|
|
|
|
|
NULL);
|
2012-11-22 14:32:45 +01:00
|
|
|
} else if ( !(ap_wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
|
|
|
|
|
&& !(ap_rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
|
2012-04-28 22:32:21 +01:00
|
|
|
/* WPA PSK */
|
|
|
|
|
g_object_set (s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK, password, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-22 14:32:45 +01:00
|
|
|
// FIXME: WPA-Enterprise is not supported yet.
|
|
|
|
|
// We are not able to determine and fill all the parameters for
|
|
|
|
|
// 802.1X authentication automatically without user providing
|
|
|
|
|
// the data. Adding nmcli options for the 8021x setting would
|
|
|
|
|
// clutter the command. However, that could be solved later by
|
|
|
|
|
// implementing add/edit connections support for nmcli.
|
2012-04-28 22:32:21 +01:00
|
|
|
|
|
|
|
|
/* nowait_flag indicates user input. should_wait says whether quit in start().
|
|
|
|
|
* We have to delay exit after add_and_activate_cb() is called, even if
|
|
|
|
|
* the user doesn't want to wait, in order to give NM time to check our
|
|
|
|
|
* permissions. */
|
|
|
|
|
nmc->nowait_flag = !wait;
|
|
|
|
|
nmc->should_wait = TRUE;
|
|
|
|
|
|
|
|
|
|
info = g_malloc0 (sizeof (AddAndActivateInfo));
|
|
|
|
|
info->nmc = nmc;
|
|
|
|
|
info->device = device;
|
|
|
|
|
|
|
|
|
|
nm_client_add_and_activate_connection (nmc->client,
|
|
|
|
|
connection,
|
|
|
|
|
device,
|
|
|
|
|
nm_object_get_path (NM_OBJECT (ap)),
|
|
|
|
|
add_and_activate_cb,
|
|
|
|
|
info);
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
if (bssid1_arr)
|
|
|
|
|
g_byte_array_free (bssid1_arr, TRUE);
|
|
|
|
|
if (bssid2_arr)
|
|
|
|
|
g_byte_array_free (bssid2_arr, TRUE);
|
2012-11-22 14:32:45 +01:00
|
|
|
g_free (ssid_ask);
|
|
|
|
|
g_free (passwd_ask);
|
2012-04-28 22:32:21 +01:00
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-19 17:10:56 +01:00
|
|
|
static void
|
|
|
|
|
request_scan_cb (NMDeviceWifi *device, GError *error, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NmCli *nmc = (NmCli *) user_data;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: %s."),
|
|
|
|
|
error->message ? error->message : _("unknown"));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
quit ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wifi_scan (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
const char *iface = NULL;
|
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
int devices_idx;
|
|
|
|
|
|
|
|
|
|
nmc->should_wait = TRUE;
|
|
|
|
|
|
|
|
|
|
/* Get the parameters */
|
|
|
|
|
if (argc > 0) {
|
|
|
|
|
if (strcmp (*argv, "iface") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
iface = *argv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find Wi-Fi device to scan on. When no iface is provided, the first Wi-Fi is used. */
|
|
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
devices = nm_client_get_devices (nmc->client);
|
|
|
|
|
devices_idx = 0;
|
|
|
|
|
device = find_wifi_device_by_iface (devices, iface, &devices_idx);
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
|
|
|
|
if (iface)
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' is not a Wi-Fi device."), iface);
|
|
|
|
|
else
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: No Wi-Fi device found."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm_device_wifi_request_scan_simple (NM_DEVICE_WIFI (device), request_scan_cb, nmc);
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
error:
|
|
|
|
|
nmc->should_wait = FALSE;
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-25 09:52:30 -08:00
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wifi (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
if (argc == 0)
|
|
|
|
|
nmc->return_value = do_device_wifi_list (nmc, argc-1, argv+1);
|
|
|
|
|
else if (argc > 0) {
|
|
|
|
|
if (matches (*argv, "list") == 0) {
|
|
|
|
|
nmc->return_value = do_device_wifi_list (nmc, argc-1, argv+1);
|
2012-04-28 22:32:21 +01:00
|
|
|
} else if (matches (*argv, "connect") == 0) {
|
|
|
|
|
nmc->return_value = do_device_wifi_connect_network (nmc, argc-1, argv+1);
|
2012-11-19 17:10:56 +01:00
|
|
|
} else if (matches (*argv, "scan") == 0) {
|
|
|
|
|
nmc->return_value = do_device_wifi_scan (nmc, argc-1, argv+1);
|
2012-04-28 22:32:21 +01:00
|
|
|
} else {
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wifi' command '%s' is not valid."), *argv);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
static void
|
|
|
|
|
show_nsp_info (NMDevice *device, NmCli *nmc)
|
|
|
|
|
{
|
|
|
|
|
const GPtrArray *nsps;
|
|
|
|
|
int i, idx = 1;
|
|
|
|
|
|
|
|
|
|
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
|
|
|
|
|
for (i = 0; nsps && i < nsps->len; i++) {
|
|
|
|
|
NMWimaxNsp *nsp = g_ptr_array_index (nsps, i);
|
|
|
|
|
|
|
|
|
|
detail_wimax_nsp (nsp, nmc, device, idx++);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wimax_list (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
NMDevice *device = NULL;
|
|
|
|
|
NMWimaxNsp *nsp = NULL;
|
|
|
|
|
const char *iface = NULL;
|
|
|
|
|
const char *nsp_user = NULL;
|
|
|
|
|
const GPtrArray *devices;
|
|
|
|
|
const GPtrArray *nsps;
|
|
|
|
|
int i, j;
|
|
|
|
|
char *fields_str;
|
|
|
|
|
char *fields_all = NMC_FIELDS_DEV_WIMAX_LIST_ALL;
|
|
|
|
|
char *fields_common = NMC_FIELDS_DEV_WIMAX_LIST_COMMON;
|
|
|
|
|
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
|
|
|
|
|
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
|
|
|
|
|
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
|
|
|
|
|
|
|
|
|
|
while (argc > 0) {
|
|
|
|
|
if (strcmp (*argv, "iface") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
iface = *argv;
|
|
|
|
|
} else if (strcmp (*argv, "nsp") == 0) {
|
|
|
|
|
if (next_arg (&argc, &argv) != 0) {
|
2012-11-16 22:43:29 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *(argv-1));
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
nsp_user = *argv;
|
|
|
|
|
} else {
|
|
|
|
|
fprintf (stderr, _("Unknown parameter: %s\n"), *argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
|
argv++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nmc->required_fields || strcasecmp (nmc->required_fields, "common") == 0)
|
|
|
|
|
fields_str = fields_common;
|
|
|
|
|
else if (!nmc->required_fields || strcasecmp (nmc->required_fields, "all") == 0)
|
|
|
|
|
fields_str = fields_all;
|
|
|
|
|
else
|
|
|
|
|
fields_str = nmc->required_fields;
|
|
|
|
|
|
|
|
|
|
nmc->allowed_fields = nmc_fields_dev_wimax_list;
|
|
|
|
|
nmc->print_fields.indices = parse_output_fields (fields_str, nmc->allowed_fields, &error);
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
if (error->code == 0)
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wimax': %s"), error->message);
|
2011-01-06 17:01:55 -06:00
|
|
|
else
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wimax': %s; allowed fields: %s"),
|
|
|
|
|
error->message, NMC_FIELDS_DEV_WIMAX_LIST_ALL);
|
2011-01-06 17:01:55 -06:00
|
|
|
g_error_free (error);
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-05 09:42:31 -06:00
|
|
|
nmc->get_client (nmc);
|
|
|
|
|
|
|
|
|
|
if (!nm_client_get_manager_running (nmc->client)) {
|
|
|
|
|
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
|
|
|
|
|
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
|
2011-02-16 17:36:50 +01:00
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nmc_versions_match (nmc))
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
/* Print headers */
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_MAIN_HEADER_ADD | NMC_PF_FLAG_FIELD_NAMES;
|
|
|
|
|
nmc->print_fields.header_name = _("WiMAX NSP list");
|
|
|
|
|
|
2011-02-16 17:36:50 +01:00
|
|
|
devices = nm_client_get_devices (nmc->client);
|
2011-01-06 17:01:55 -06:00
|
|
|
if (iface) {
|
|
|
|
|
/* Device specified - list only NSPs of this interface */
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *candidate = g_ptr_array_index (devices, i);
|
|
|
|
|
const char *dev_iface = nm_device_get_iface (candidate);
|
|
|
|
|
|
2013-02-05 10:00:58 +01:00
|
|
|
if (!g_strcmp0 (dev_iface, iface)) {
|
2011-01-06 17:01:55 -06:00
|
|
|
device = candidate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!device) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' not found."), iface);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NM_IS_DEVICE_WIMAX (device)) {
|
|
|
|
|
if (nsp_user) {
|
|
|
|
|
/* Specific NSP requested - list only that */
|
|
|
|
|
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device));
|
|
|
|
|
for (j = 0, nsp = NULL; nsps && (j < nsps->len); j++) {
|
|
|
|
|
NMWimaxNsp *candidate_nsp = g_ptr_array_index (nsps, j);
|
|
|
|
|
const char *candidate_name = nm_wimax_nsp_get_name (candidate_nsp);
|
|
|
|
|
char *nsp_up;
|
|
|
|
|
|
|
|
|
|
nsp_up = g_ascii_strup (nsp_user, -1);
|
|
|
|
|
if (!strcmp (nsp_up, candidate_name))
|
|
|
|
|
nsp = candidate_nsp;
|
|
|
|
|
g_free (nsp_up);
|
|
|
|
|
}
|
|
|
|
|
if (!nsp) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: NSP with name '%s' not found."), nsp_user);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
detail_wimax_nsp (nsp, nmc, device, 1);
|
|
|
|
|
} else {
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
show_nsp_info (device, nmc);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Device '%s' is not a WiMAX device."), iface);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* List NSPs for all devices */
|
|
|
|
|
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
|
|
|
|
|
if (nsp_user) {
|
|
|
|
|
/* Specific NSP requested - list only that */
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *dev = g_ptr_array_index (devices, i);
|
|
|
|
|
int idx = 1;
|
|
|
|
|
|
|
|
|
|
if (!NM_IS_DEVICE_WIMAX (dev))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (dev));
|
|
|
|
|
for (j = 0, nsp = NULL; nsps && (j < nsps->len); j++) {
|
|
|
|
|
NMWimaxNsp *candidate_nsp = g_ptr_array_index (nsps, j);
|
|
|
|
|
const char *candidate_name = nm_wimax_nsp_get_name (candidate_nsp);
|
|
|
|
|
char *nsp_up;
|
|
|
|
|
|
|
|
|
|
nsp_up = g_ascii_strup (nsp_user, -1);
|
|
|
|
|
if (!strcmp (nsp_up, candidate_name)) {
|
|
|
|
|
nsp = candidate_nsp;
|
|
|
|
|
detail_wimax_nsp (nsp, nmc, dev, idx);
|
|
|
|
|
}
|
|
|
|
|
g_free (nsp_up);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!nsp) {
|
2012-04-28 22:54:02 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: Access point with nsp '%s' not found."), nsp_user);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (i = 0; devices && (i < devices->len); i++) {
|
|
|
|
|
NMDevice *dev = g_ptr_array_index (devices, i);
|
|
|
|
|
if (NM_IS_DEVICE_WIMAX (dev))
|
|
|
|
|
show_nsp_info (dev, nmc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMCResultCode
|
|
|
|
|
do_device_wimax (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
if (argc == 0)
|
|
|
|
|
nmc->return_value = do_device_wimax_list (nmc, argc-1, argv+1);
|
|
|
|
|
else if (argc > 0) {
|
|
|
|
|
if (matches (*argv, "list") == 0) {
|
|
|
|
|
nmc->return_value = do_device_wimax_list (nmc, argc-1, argv+1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-04-03 10:15:00 +02:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'device wimax' command '%s' is not valid."), *argv);
|
2011-01-06 17:01:55 -06:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
NMCResultCode
|
|
|
|
|
do_devices (NmCli *nmc, int argc, char **argv)
|
|
|
|
|
{
|
2010-03-22 18:43:28 +01:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
|
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
|
2010-03-24 13:42:47 +01:00
|
|
|
goto opt_error;
|
2010-03-22 18:43:28 +01:00
|
|
|
nmc->return_value = do_devices_status (nmc, 0, NULL);
|
|
|
|
|
}
|
2010-02-25 09:52:30 -08:00
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
|
if (matches (*argv, "status") == 0) {
|
2010-03-22 18:43:28 +01:00
|
|
|
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
|
2010-03-24 13:42:47 +01:00
|
|
|
goto opt_error;
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = do_devices_status (nmc, argc-1, argv+1);
|
|
|
|
|
}
|
2013-04-03 10:01:42 +02:00
|
|
|
else if (matches (*argv, "show") == 0) {
|
2010-04-06 16:22:01 +02:00
|
|
|
if (!nmc->mode_specified)
|
2013-04-03 10:01:42 +02:00
|
|
|
nmc->multiline_output = TRUE; /* multiline mode is default for 'device show' */
|
|
|
|
|
nmc->return_value = do_devices_show (nmc, argc-1, argv+1);
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
else if (matches (*argv, "disconnect") == 0) {
|
|
|
|
|
nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1);
|
|
|
|
|
}
|
|
|
|
|
else if (matches (*argv, "wifi") == 0) {
|
2010-03-22 18:43:28 +01:00
|
|
|
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
|
2010-03-24 13:42:47 +01:00
|
|
|
goto opt_error;
|
2010-02-25 09:52:30 -08:00
|
|
|
nmc->return_value = do_device_wifi (nmc, argc-1, argv+1);
|
|
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
#if WITH_WIMAX
|
2011-01-06 17:01:55 -06:00
|
|
|
else if (matches (*argv, "wimax") == 0) {
|
|
|
|
|
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
|
|
|
|
|
goto opt_error;
|
|
|
|
|
nmc->return_value = do_device_wimax (nmc, argc-1, argv+1);
|
|
|
|
|
}
|
2011-02-14 16:06:37 +01:00
|
|
|
#endif
|
2012-11-13 14:19:49 +01:00
|
|
|
else if ( matches (*argv, "help") == 0
|
|
|
|
|
|| (g_str_has_prefix (*argv, "-") && matches ((*argv)+1, "help") == 0)
|
|
|
|
|
|| (g_str_has_prefix (*argv, "--") && matches ((*argv)+2, "help") == 0)) {
|
2010-02-25 09:52:30 -08:00
|
|
|
usage ();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-11-13 14:19:49 +01:00
|
|
|
usage ();
|
2010-02-25 09:52:30 -08:00
|
|
|
g_string_printf (nmc->return_text, _("Error: 'dev' command '%s' is not valid."), *argv);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-02-25 09:52:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-22 18:43:28 +01:00
|
|
|
return nmc->return_value;
|
|
|
|
|
|
2010-03-24 13:42:47 +01:00
|
|
|
opt_error:
|
2010-03-22 18:43:28 +01:00
|
|
|
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
|
2010-03-24 13:42:47 +01:00
|
|
|
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
|
2010-03-22 18:43:28 +01:00
|
|
|
g_error_free (error);
|
2010-02-25 09:52:30 -08:00
|
|
|
return nmc->return_value;
|
|
|
|
|
}
|