Commit 93486fc4 authored by Dan Williams's avatar Dan Williams

cli: add support for WiMAX devices and connections

parent 9d24269e
......@@ -38,8 +38,10 @@
#include <nm-setting-cdma.h>
#include <nm-setting-bluetooth.h>
#include <nm-setting-olpc-mesh.h>
#include <nm-setting-wimax.h>
#include <nm-device-ethernet.h>
#include <nm-device-wifi.h>
#include <nm-device-wimax.h>
#include <nm-gsm-device.h>
#include <nm-cdma-device.h>
#include <nm-device-bt.h>
......@@ -108,6 +110,7 @@ static NmcOutputField nmc_fields_settings_names[] = {
SETTING_FIELD (NM_SETTING_BLUETOOTH_SETTING_NAME, 0), /* 12 */
SETTING_FIELD (NM_SETTING_OLPC_MESH_SETTING_NAME, 0), /* 13 */
SETTING_FIELD (NM_SETTING_VPN_SETTING_NAME, 0), /* 14 */
SETTING_FIELD (NM_SETTING_WIMAX_SETTING_NAME, 0), /* 15 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTINGS_NAMES_ALL NM_SETTING_CONNECTION_SETTING_NAME","\
......@@ -124,7 +127,8 @@ static NmcOutputField nmc_fields_settings_names[] = {
NM_SETTING_CDMA_SETTING_NAME","\
NM_SETTING_BLUETOOTH_SETTING_NAME","\
NM_SETTING_OLPC_MESH_SETTING_NAME","\
NM_SETTING_VPN_SETTING_NAME
NM_SETTING_VPN_SETTING_NAME","\
NM_SETTING_WIMAX_SETTING_NAME
typedef struct {
......@@ -143,7 +147,7 @@ static void quit (void);
static void show_connection (NMConnection *data, gpointer user_data);
static NMConnection *find_connection (GSList *list, const char *filter_type, const char *filter_val);
static gboolean find_device_for_connection (NmCli *nmc, NMConnection *connection, const char *iface, const char *ap,
NMDevice **device, const char **spec_object, GError **error);
const char *nsp, NMDevice **device, const char **spec_object, GError **error);
static const char *active_connection_state_to_string (NMActiveConnectionState state);
static void active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpointer user_data);
static void activate_connection_cb (gpointer user_data, const char *path, GError *error);
......@@ -161,7 +165,7 @@ usage (void)
" COMMAND := { list | status | up | down }\n\n"
" list [id <id> | uuid <id> | system | user]\n"
" status\n"
" up id <id> | uuid <id> [iface <iface>] [ap <hwaddr>] [--nowait] [--timeout <timeout>]\n"
" up id <id> | uuid <id> [iface <iface>] [ap <hwaddr>] [nsp <name>] [--nowait] [--timeout <timeout>]\n"
" down id <id> | uuid <id>\n"));
}
......@@ -354,6 +358,15 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
continue;
}
}
if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[15].name)) {
setting = nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX);
if (setting) {
setting_wimax_details (setting, nmc);
was_output = TRUE;
continue;
}
}
}
if (print_settings_array)
......@@ -885,6 +898,51 @@ check_olpc_mesh_compatible (NMDeviceOlpcMesh *device, NMConnection *connection,
}
#endif
static gboolean
check_wimax_compatible (NMDeviceWimax *device, NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
NMSettingWimax *s_wimax;
const GByteArray *mac;
const char *device_mac_str;
struct ether_addr *device_mac = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_WIMAX_SETTING_NAME)) {
g_set_error (error, 0, 0,
"The connection was not a WiMAX connection.");
return FALSE;
}
s_wimax = NM_SETTING_WIMAX (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX));
if (!s_wimax) {
g_set_error (error, 0, 0,
"The connection was not a valid WiMAX connection.");
return FALSE;
}
device_mac_str = nm_device_wimax_get_hw_address (device);
if (device_mac_str)
device_mac = ether_aton (device_mac_str);
if (!device_mac) {
g_set_error (error, 0, 0, "Invalid device MAC address.");
return FALSE;
}
mac = nm_setting_wimax_get_mac_address (s_wimax);
if (mac && memcmp (mac->data, device_mac->ether_addr_octet, ETH_ALEN)) {
g_set_error (error, 0, 0,
"The connection's MAC address did not match this device.");
return FALSE;
}
return TRUE;
}
static gboolean
nm_device_is_connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
{
......@@ -899,6 +957,8 @@ nm_device_is_connection_compatible (NMDevice *device, NMConnection *connection,
return check_bt_compatible (NM_DEVICE_BT (device), connection, error);
// else if (NM_IS_DEVICE_OLPC_MESH (device))
// return check_olpc_mesh_compatible (NM_DEVICE_OLPC_MESH (device), connection, error);
else if (NM_IS_DEVICE_WIMAX (device))
return check_wimax_compatible (NM_DEVICE_WIMAX (device), connection, error);
g_set_error (error, 0, 0, "unhandled device type '%s'", G_OBJECT_TYPE_NAME (device));
return FALSE;
......@@ -989,13 +1049,20 @@ get_default_active_connection (NmCli *nmc, NMDevice **device)
* IN: connection: connection to activate
* iface: device interface name to use (optional)
* ap: access point to use (optional; valid just for 802-11-wireless)
* nsp: Network Service Provider to use (option; valid only for wimax)
* OUT: device: found device
* spec_object: specific_object path of NMAccessPoint
* RETURNS: TRUE when a device is found, FALSE otherwise.
*/
static gboolean
find_device_for_connection (NmCli *nmc, NMConnection *connection, const char *iface, const char *ap,
NMDevice **device, const char **spec_object, GError **error)
find_device_for_connection (NmCli *nmc,
NMConnection *connection,
const char *iface,
const char *ap,
const char *nsp,
NMDevice **device,
const char **spec_object,
GError **error)
{
NMSettingConnection *s_con;
const char *con_type;
......@@ -1082,6 +1149,25 @@ find_device_for_connection (NmCli *nmc, NMConnection *connection, const char *if
}
g_free (hwaddr_up);
}
if ( found_device
&& nsp
&& !strcmp (con_type, NM_SETTING_WIMAX_SETTING_NAME)
&& NM_IS_DEVICE_WIMAX (dev)) {
const GPtrArray *nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (dev));
found_device = NULL; /* Mark as not found; set to the device again later, only if NSP matches */
for (j = 0; 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);
if (!strcmp (nsp, candidate_name)) {
found_device = dev;
*spec_object = nm_object_get_path (NM_OBJECT (candidate_nsp));
break;
}
}
}
}
if (found_device) {
......@@ -1324,6 +1410,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
const char *con_type;
const char *iface = NULL;
const char *ap = NULL;
const char *nsp = NULL;
gboolean id_specified = FALSE;
gboolean wait = TRUE;
GError *error = NULL;
......@@ -1371,6 +1458,15 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
ap = *argv;
}
else if (strcmp (*argv, "nsp") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
nsp = *argv;
}
else if (strcmp (*argv, "--nowait") == 0) {
wait = FALSE;
} else if (strcmp (*argv, "--timeout") == 0) {
......@@ -1412,7 +1508,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
g_assert (s_con);
con_type = nm_setting_connection_get_connection_type (s_con);
device_found = find_device_for_connection (nmc, connection, iface, ap, &device, &spec_object, &error);
device_found = find_device_for_connection (nmc, connection, iface, ap, nsp, &device, &spec_object, &error);
if (!device_found) {
if (error)
......
This diff is collapsed.
......@@ -39,13 +39,16 @@ static NmcOutputField nmc_fields_nm_status[] = {
{"WIFI", N_("WIFI"), 10, NULL, 0}, /* 4 */
{"WWAN-HARDWARE", N_("WWAN-HARDWARE"), 15, NULL, 0}, /* 5 */
{"WWAN", N_("WWAN"), 10, NULL, 0}, /* 6 */
{NULL, NULL, 0, NULL, 0}
{"WIMAX-HARDWARE", N_("WIMAX-HARDWARE"), 15, NULL, 0}, /* 7 */
{"WIMAX", N_("WIMAX"), 10, NULL, 0}, /* 8 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
#define NMC_FIELDS_NM_STATUS_ALL "RUNNING,STATE,NET-ENABLED,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN,WIMAX-HARDWARE,WIMAX"
#define NMC_FIELDS_NM_STATUS_COMMON "RUNNING,STATE,WIFI-HARDWARE,WIFI,WWAN-HARDWARE,WWAN"
#define NMC_FIELDS_NM_NET_ENABLED "NET-ENABLED"
#define NMC_FIELDS_NM_WIFI "WIFI"
#define NMC_FIELDS_NM_WWAN "WWAN"
#define NMC_FIELDS_NM_WIMAX "WIMAX"
extern GMainLoop *loop;
......@@ -62,12 +65,13 @@ usage (void)
{
fprintf (stderr,
_("Usage: nmcli nm { COMMAND | help }\n\n"
" COMMAND := { status | enable | sleep | wifi | wwan }\n\n"
" COMMAND := { status | enable | sleep | wifi | wwan | wimax }\n\n"
" status\n"
" enable [true|false]\n"
" sleep [true|false]\n"
" wifi [on|off]\n"
" wwan [on|off]\n\n"));
" wwan [on|off]\n"
" wimax [on|off]\n\n"));
}
/* quit main loop */
......@@ -103,6 +107,7 @@ show_nm_status (NmCli *nmc)
NMState state;
const char *wireless_hw_enabled_str, *wireless_enabled_str;
const char *wwan_hw_enabled_str, *wwan_enabled_str;
const char *wimax_hw_enabled_str, *wimax_enabled_str;
GError *error = NULL;
const char *fields_str;
const char *fields_all = NMC_FIELDS_NM_STATUS_ALL;
......@@ -145,8 +150,10 @@ show_nm_status (NmCli *nmc)
wireless_enabled_str = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wwan_hw_enabled_str = nm_client_wwan_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wwan_enabled_str = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wimax_hw_enabled_str = nm_client_wimax_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wimax_enabled_str = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled");
} else {
wireless_hw_enabled_str = wireless_enabled_str = wwan_hw_enabled_str = wwan_enabled_str = _("unknown");
wireless_hw_enabled_str = wireless_enabled_str = wwan_hw_enabled_str = wwan_enabled_str = wimax_hw_enabled_str = wimax_enabled_str = _("unknown");
}
nmc->allowed_fields[0].value = nm_running ? _("running") : _("not running");
......@@ -156,6 +163,8 @@ show_nm_status (NmCli *nmc)
nmc->allowed_fields[4].value = wireless_enabled_str;
nmc->allowed_fields[5].value = wwan_hw_enabled_str;
nmc->allowed_fields[6].value = wwan_enabled_str;
nmc->allowed_fields[7].value = wimax_hw_enabled_str;
nmc->allowed_fields[8].value = wimax_enabled_str;
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
......@@ -208,6 +217,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
gboolean enable_net;
gboolean enable_wifi;
gboolean enable_wwan;
gboolean enable_wimax;
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;
......@@ -341,6 +351,38 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
nm_client_wwan_set_enabled (nmc->client, enable_wwan);
}
}
else if (matches (*argv, "wimax") == 0) {
if (next_arg (&argc, &argv) != 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
/* no argument, show current WiMAX state */
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WIMAX")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here; allowed fields: %s"),
nmc->required_fields, NMC_FIELDS_NM_WIMAX);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_NM_WIMAX, nmc->allowed_fields, NULL);
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 enabled");
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
nmc->allowed_fields[8].value = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print header */
} else {
if (!strcmp (*argv, "on"))
enable_wimax = TRUE;
else if (!strcmp (*argv, "off"))
enable_wimax = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wimax' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nm_client_wimax_set_enabled (nmc->client, enable_wimax);
}
}
else if (strcmp (*argv, "help") == 0) {
usage ();
}
......
......@@ -402,6 +402,18 @@ static NmcOutputField nmc_fields_setting_vpn[] = {
NM_SETTING_VPN_SECRETS
#define NMC_FIELDS_SETTING_VPN_COMMON NMC_FIELDS_SETTING_VPN_ALL
/* Available fields for NM_SETTING_WIMAX_SETTING_NAME */
static NmcOutputField nmc_fields_setting_wimax[] = {
SETTING_FIELD ("name", 6), /* 0 */
SETTING_FIELD (NM_SETTING_WIMAX_MAC_ADDRESS, 19), /* 1 */
SETTING_FIELD (NM_SETTING_WIMAX_NETWORK_NAME, 40), /* 2 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTING_WIMAX_ALL "name"","\
NM_SETTING_WIMAX_MAC_ADDRESS","\
NM_SETTING_WIMAX_NETWORK_NAME
#define NMC_FIELDS_SETTING_WIMAX_COMMON NMC_FIELDS_SETTING_WIMAX_ALL
static char *
wep_key_type_to_string (NMWepKeyType type)
......@@ -1381,3 +1393,37 @@ setting_vpn_details (NMSetting *setting, NmCli *nmc)
return TRUE;
}
gboolean
setting_wimax_details (NMSetting *setting, NmCli *nmc)
{
NMSettingWimax *s_wimax;
const GByteArray *mac;
char *device_mac_str = NULL;
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;
g_return_val_if_fail (NM_IS_SETTING_WIMAX (setting), FALSE);
s_wimax = (NMSettingWimax *) setting;
nmc->allowed_fields = nmc_fields_setting_wimax;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_WIMAX_ALL, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */
mac = nm_setting_wimax_get_mac_address (s_wimax);
if (mac)
device_mac_str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X", mac->data[0], mac->data[1], mac->data[2], mac->data[3], mac->data[4], mac->data[5]);
nmc->allowed_fields[0].value = NM_SETTING_WIMAX_SETTING_NAME;
nmc->allowed_fields[1].value = device_mac_str;
nmc->allowed_fields[2].value = nm_setting_wimax_get_network_name (s_wimax);
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 (device_mac_str);
return TRUE;
}
......@@ -35,6 +35,7 @@
#include <nm-setting-bluetooth.h>
#include <nm-setting-olpc-mesh.h>
#include <nm-setting-vpn.h>
#include <nm-setting-wimax.h>
#include "nmcli.h"
#include "utils.h"
......@@ -55,5 +56,6 @@ gboolean setting_cdma_details (NMSetting *setting, NmCli *nmc);
gboolean setting_bluetooth_details (NMSetting *setting, NmCli *nmc);
gboolean setting_olpc_mesh_details (NMSetting *setting, NmCli *nmc);
gboolean setting_vpn_details (NMSetting *setting, NmCli *nmc);
gboolean setting_wimax_details (NMSetting *setting, NmCli *nmc);
#endif /* NMC_SETTINGS_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment