eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

station.c (20718B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2018-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <arpa/inet.h>
     28 #include <ifaddrs.h>
     29 
     30 #include <ell/ell.h>
     31 
     32 #include "client/command.h"
     33 #include "client/dbus-proxy.h"
     34 #include "client/device.h"
     35 #include "client/network.h"
     36 #include "client/display.h"
     37 #include "client/diagnostic.h"
     38 #include "client/daemon.h"
     39 
     40 struct station {
     41 	bool scanning;
     42 	char *state;
     43 	const struct proxy_interface *connected_network;
     44 };
     45 
     46 static void *station_create(void)
     47 {
     48 	return l_new(struct station, 1);
     49 }
     50 
     51 static void station_destroy(void *data)
     52 {
     53 	struct station *station = data;
     54 
     55 	l_free(station->state);
     56 	station->connected_network = NULL;
     57 
     58 	l_free(station);
     59 }
     60 
     61 static const struct proxy_interface_type_ops station_ops = {
     62 	.create = station_create,
     63 	.destroy = station_destroy,
     64 };
     65 
     66 static const char *get_scanning_tostr(const void *data)
     67 {
     68 	const struct station *station = data;
     69 
     70 	return station->scanning ? "yes" : "no";
     71 }
     72 
     73 static void update_scanning(void *data, struct l_dbus_message_iter *variant)
     74 {
     75 	struct station *station = data;
     76 	bool value;
     77 
     78 	if (!l_dbus_message_iter_get_variant(variant, "b", &value)) {
     79 		station->scanning = false;
     80 		return;
     81 	}
     82 
     83 	station->scanning = value;
     84 }
     85 
     86 static const char *get_state(const void *data)
     87 {
     88 	const struct station *station = data;
     89 
     90 	return station->state;
     91 }
     92 
     93 static void update_state(void *data, struct l_dbus_message_iter *variant)
     94 {
     95 	struct station *station = data;
     96 	const char *value;
     97 
     98 	l_free(station->state);
     99 
    100 	if (!l_dbus_message_iter_get_variant(variant, "s", &value)) {
    101 		station->state = NULL;
    102 		return;
    103 	}
    104 
    105 	station->state = l_strdup(value);
    106 }
    107 
    108 static void update_connected_network(void *data,
    109 					struct l_dbus_message_iter *variant)
    110 {
    111 	struct station *station = data;
    112 	const char *path;
    113 
    114 	if (!l_dbus_message_iter_get_variant(variant, "o", &path)) {
    115 		station->connected_network = NULL;
    116 
    117 		return;
    118 	}
    119 
    120 	station->connected_network = proxy_interface_find(IWD_NETWORK_INTERFACE,
    121 									path);
    122 }
    123 
    124 static const struct proxy_interface_property station_properties[] = {
    125 	{ "Scanning",  "b", update_scanning,  get_scanning_tostr },
    126 	{ "State",    "s", update_state,    get_state },
    127 	{ "ConnectedNetwork",
    128 			"o", update_connected_network },
    129 	{ }
    130 };
    131 
    132 static struct proxy_interface_type station_interface_type = {
    133 	.interface = IWD_STATION_INTERFACE,
    134 	.properties = station_properties,
    135 	.ops = &station_ops,
    136 };
    137 
    138 static struct proxy_interface_type station_diagnostic_interface = {
    139 	.interface = IWD_STATION_DIAGNOSTIC_INTERFACE,
    140 };
    141 
    142 static void check_errors_method_callback(struct l_dbus_message *message,
    143 								void *user_data)
    144 {
    145 	dbus_message_has_error(message);
    146 }
    147 
    148 static void display_addresses(const char *device_name)
    149 {
    150 	struct ifaddrs *ifa;
    151 	struct ifaddrs *cur;
    152 	bool have_address = false;
    153 	char addrstr[INET6_ADDRSTRLEN];
    154 	int r;
    155 
    156 	if (getifaddrs(&ifa) == -1)
    157 		return;
    158 
    159 	for (cur = ifa; cur; cur = cur->ifa_next) {
    160 		if (cur->ifa_addr == NULL)
    161 			continue;
    162 
    163 		if (strcmp(cur->ifa_name, device_name))
    164 			continue;
    165 
    166 		if (cur->ifa_addr->sa_family == AF_INET6) {
    167 			struct sockaddr_in6 *si6 =
    168 					(struct sockaddr_in6 *) cur->ifa_addr;
    169 
    170 			if (IN6_IS_ADDR_LINKLOCAL(&si6->sin6_addr))
    171 				continue;
    172 
    173 			if (!inet_ntop(AF_INET6, &si6->sin6_addr,
    174 						addrstr, sizeof(addrstr)))
    175 				continue;
    176 
    177 			have_address = true;
    178 			display_table_row(MARGIN, 3, 8, "", 20,
    179 						"IPv6 address", 47, addrstr);
    180 		} else if (cur->ifa_addr->sa_family == AF_INET) {
    181 			struct sockaddr_in *si =
    182 					(struct sockaddr_in *) cur->ifa_addr;
    183 
    184 			if (!inet_ntop(AF_INET, &si->sin_addr,
    185 					addrstr, sizeof(addrstr)))
    186 				continue;
    187 
    188 			have_address = true;
    189 			display_table_row(MARGIN, 3, 8, "", 20, "IPv4 address", 47, addrstr);
    190 		}
    191 	}
    192 
    193 	freeifaddrs(ifa);
    194 
    195 	if (have_address)
    196 		return;
    197 
    198 	r = daemon_netconfig_enabled();
    199 	if (r < 0 || r == 1)
    200 		return;
    201 
    202 	display_table_row(MARGIN, 3, 8, "", 20, "No IP addresses", 47, "Is DHCP client configured?");
    203 }
    204 
    205 
    206 static void display_station(const char *device_name,
    207 					const struct proxy_interface *proxy)
    208 {
    209 	const struct station *station = proxy_interface_get_data(proxy);
    210 	char *caption = l_strdup_printf("%s: %s", "Station", device_name);
    211 
    212 	proxy_properties_display(proxy, caption, MARGIN, 20, 47);
    213 	l_free(caption);
    214 
    215 	if (station->connected_network) {
    216 		display_table_row(MARGIN, 3, 8, "", 20, "Connected network",
    217 			47, network_get_name(station->connected_network));
    218 
    219 		display_addresses(device_name);
    220 	}
    221 
    222 	/* The table footer is handled by cmd_show. */
    223 }
    224 
    225 static void display_station_inline(const char *margin, const void *data)
    226 {
    227 	const struct proxy_interface *station_i = data;
    228 	const struct station *station = proxy_interface_get_data(station_i);
    229 	struct proxy_interface *device_i =
    230 		proxy_interface_find(IWD_DEVICE_INTERFACE,
    231 					proxy_interface_get_path(station_i));
    232 	const char *identity;
    233 
    234 	if (!device_i)
    235 		return;
    236 
    237 	identity = proxy_interface_get_identity_str(device_i);
    238 	if (!identity)
    239 		return;
    240 
    241 	display_table_row(margin, 3, 20, identity, 15, station->state ? : "",
    242 				8, station->scanning ? "scanning" : "");
    243 }
    244 
    245 static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
    246 {
    247 	const struct l_queue_entry *entry;
    248 	struct l_queue *match =
    249 		proxy_interface_find_all(IWD_STATION_INTERFACE, NULL, NULL);
    250 
    251 	display_table_header("Devices in Station Mode",
    252 				MARGIN "%-*s  %-*s  %-*s",
    253 				20, "Name", 15, "State", 8, "Scanning");
    254 
    255 	if (!match) {
    256 		display("No devices in Station mode available.\n");
    257 		display_table_footer();
    258 
    259 		return CMD_STATUS_DONE;
    260 	}
    261 
    262 	for (entry = l_queue_get_entries(match); entry; entry = entry->next) {
    263 		const struct proxy_interface *station = entry->data;
    264 		display_station_inline(MARGIN, station);
    265 	}
    266 
    267 	display_table_footer();
    268 
    269 	l_queue_destroy(match, NULL);
    270 
    271 	return CMD_STATUS_DONE;
    272 }
    273 
    274 static char *connect_cmd_arg_completion(const char *text, int state,
    275 					const char *device_name)
    276 {
    277 	const struct proxy_interface *device = device_proxy_find(device_name,
    278 							IWD_STATION_INTERFACE);
    279 
    280 	if (!device)
    281 		return NULL;
    282 
    283 	return network_name_completion(device, text, state);
    284 }
    285 
    286 static const struct proxy_interface *find_network(const char *device_name,
    287 						const char *name,
    288 						const char *type)
    289 {
    290 	struct network_args network_args;
    291 	struct l_queue *match;
    292 	const struct proxy_interface *network_proxy;
    293 	const struct proxy_interface *device_proxy;
    294 
    295 	device_proxy = device_proxy_find_by_name(device_name);
    296 	if (!device_proxy)
    297 		return NULL;
    298 
    299 	network_args.name = name;
    300 	network_args.type = type;
    301 
    302 	match = network_match_by_device_and_args(device_proxy, &network_args);
    303 	if (!match) {
    304 		display("Invalid network name '%s'\n", network_args.name);
    305 		return NULL;
    306 	}
    307 
    308 	if (l_queue_length(match) > 1) {
    309 		if (!network_args.type) {
    310 			display("Provided network name is ambiguous. "
    311 				"Please specify security type.\n");
    312 		}
    313 
    314 		l_queue_destroy(match, NULL);
    315 
    316 		return NULL;
    317 	}
    318 
    319 	network_proxy = l_queue_pop_head(match);
    320 	l_queue_destroy(match, NULL);
    321 
    322 	return network_proxy;
    323 }
    324 
    325 static enum cmd_status cmd_connect(const char *device_name,
    326 						char **argv, int argc)
    327 {
    328 	const struct proxy_interface *network_proxy;
    329 
    330 	if (argc < 1)
    331 		return CMD_STATUS_INVALID_ARGS;
    332 
    333 	network_proxy = find_network(device_name, argv[0],
    334 					argc >= 2 ? argv[1] : NULL);
    335 	if (!network_proxy)
    336 		return CMD_STATUS_INVALID_VALUE;
    337 
    338 	network_connect(network_proxy);
    339 
    340 	return CMD_STATUS_TRIGGERED;
    341 }
    342 
    343 static enum cmd_status cmd_connect_hidden_network(const char *device_name,
    344 							char **argv,
    345 							int argc)
    346 {
    347 	const struct proxy_interface *station_i;
    348 
    349 	if (argc != 1)
    350 		return CMD_STATUS_INVALID_ARGS;
    351 
    352 	station_i = device_proxy_find(device_name, IWD_STATION_INTERFACE);
    353 	if (!station_i) {
    354 		display("No station on device: '%s'\n", device_name);
    355 		return CMD_STATUS_INVALID_VALUE;
    356 	}
    357 
    358 	proxy_interface_method_call(station_i, "ConnectHiddenNetwork", "s",
    359 					check_errors_method_callback,
    360 					argv[0]);
    361 
    362 	return CMD_STATUS_TRIGGERED;
    363 }
    364 
    365 static enum cmd_status cmd_disconnect(const char *device_name,
    366 						char **argv, int argc)
    367 {
    368 	const struct proxy_interface *station_i =
    369 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    370 
    371 	if (!station_i) {
    372 		display("No station on device: '%s'\n", device_name);
    373 		return CMD_STATUS_INVALID_VALUE;
    374 	}
    375 
    376 	proxy_interface_method_call(station_i, "Disconnect", "",
    377 						check_errors_method_callback);
    378 
    379 	return CMD_STATUS_TRIGGERED;
    380 }
    381 
    382 struct ordered_network {
    383 	char *network_path;
    384 	int16_t signal_strength;
    385 };
    386 
    387 static void ordered_networks_destroy(void *data)
    388 {
    389 	struct ordered_network *network = data;
    390 
    391 	l_free(network->network_path);
    392 	l_free(network);
    393 }
    394 
    395 static const char *dbms_tostars(int16_t dbms)
    396 {
    397 	if (dbms >= -6000)
    398 		return "****";
    399 
    400 	if (dbms >= -6700)
    401 		return "***" COLOR_BOLDGRAY("*");
    402 
    403 	if (dbms >= -7500)
    404 		return "**" COLOR_BOLDGRAY("**");
    405 
    406 	return "*" COLOR_BOLDGRAY("***");
    407 }
    408 
    409 #define RSSI_DBMS "rssi-dbms"
    410 #define RSSI_BARS "rssi-bars"
    411 
    412 static const struct {
    413 	const char *option;
    414 } ordered_networks_arg_options[] = {
    415 	{ RSSI_DBMS },
    416 	{ RSSI_BARS },
    417 	{ }
    418 };
    419 
    420 static bool display_signal_as_dbms;
    421 
    422 static void ordered_networks_display(struct l_queue *ordered_networks)
    423 {
    424 	char *dbms = NULL;
    425 	const struct l_queue_entry *entry;
    426 
    427 	display_table_header("Available networks", "%s%-*s  %-*s  %-*s  %*s",
    428 					MARGIN, 2, "", 32, "Network name",
    429 					18, "Security", 6, "Signal");
    430 
    431 	if (!l_queue_length(ordered_networks)) {
    432 		display("No networks available\n");
    433 		display_table_footer();
    434 
    435 		return;
    436 	}
    437 
    438 	for (entry = l_queue_get_entries(ordered_networks);
    439 						entry; entry = entry->next) {
    440 		struct ordered_network *network = entry->data;
    441 		const struct proxy_interface *network_i =
    442 				network_get_proxy(network->network_path);
    443 		const char *network_name = network_get_name(network_i);
    444 		const char *network_type = network_get_type(network_i);
    445 
    446 		if (!strcmp(network_type, "wep"))
    447 			network_type = "wep (unsupported)";
    448 
    449 		if (display_signal_as_dbms)
    450 			dbms = l_strdup_printf("%d", network->signal_strength);
    451 
    452 		display_table_row(MARGIN, 4, 2,
    453 				network_is_connected(network_i) ?
    454 				COLOR_BOLDGRAY("> ") : "",
    455 				32, network_name, 18, network_type, 6,
    456 				display_signal_as_dbms ? dbms :
    457 				dbms_tostars(network->signal_strength));
    458 
    459 		if (display_signal_as_dbms) {
    460 			l_free(dbms);
    461 			dbms = NULL;
    462 		}
    463 	}
    464 
    465 	display_table_footer();
    466 }
    467 
    468 static void ordered_networks_callback(struct l_dbus_message *message,
    469 								void *proxy)
    470 {
    471 	struct l_queue *networks = NULL;
    472 	struct ordered_network network;
    473 	struct l_dbus_message_iter iter;
    474 
    475 	if (dbus_message_has_error(message))
    476 		return;
    477 
    478 	if (!l_dbus_message_get_arguments(message, "a(on)", &iter)) {
    479 		l_error("Failed to parse ordered networks callback message");
    480 
    481 		return;
    482 	}
    483 
    484 	while (l_dbus_message_iter_next_entry(&iter,
    485 						&network.network_path,
    486 						&network.signal_strength)) {
    487 		struct ordered_network *net = l_new(struct ordered_network, 1);
    488 
    489 		if (!networks)
    490 			networks = l_queue_new();
    491 
    492 		net->network_path = l_strdup(network.network_path);
    493 		net->signal_strength = network.signal_strength;
    494 
    495 		l_queue_push_tail(networks, net);
    496 	}
    497 
    498 	ordered_networks_display(networks);
    499 
    500 	l_queue_destroy(networks, ordered_networks_destroy);
    501 }
    502 
    503 static char *get_networks_cmd_arg_completion(const char *text, int state,
    504 						const char *device_name)
    505 {
    506 	static int index;
    507 	static int len;
    508 	const char *arg;
    509 
    510 	if (!state) {
    511 		index = 0;
    512 		len = strlen(text);
    513 	}
    514 
    515 	while ((arg = ordered_networks_arg_options[index++].option)) {
    516 		if (!strncmp(arg, text, len))
    517 			return l_strdup(arg);
    518 	}
    519 
    520 	return NULL;
    521 }
    522 
    523 static enum cmd_status cmd_get_networks(const char *device_name,
    524 						char **argv, int argc)
    525 {
    526 	const struct proxy_interface *station_i =
    527 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    528 
    529 	if (!station_i) {
    530 		display("No station on device: '%s'\n", device_name);
    531 		return CMD_STATUS_INVALID_VALUE;
    532 	}
    533 
    534 	if (!argc)
    535 		goto proceed;
    536 
    537 	if (!strcmp(argv[0], RSSI_DBMS))
    538 		display_signal_as_dbms = true;
    539 	else
    540 		display_signal_as_dbms = false;
    541 
    542 proceed:
    543 	proxy_interface_method_call(station_i, "GetOrderedNetworks", "",
    544 					ordered_networks_callback);
    545 
    546 	return CMD_STATUS_TRIGGERED;
    547 }
    548 
    549 struct hidden_access_point {
    550 	char *address;
    551 	int16_t signal_strength;
    552 	char *type;
    553 };
    554 
    555 static void hidden_access_point_destroy(void *data)
    556 {
    557 	struct hidden_access_point *ap = data;
    558 
    559 	l_free(ap->address);
    560 	l_free(ap->type);
    561 	l_free(ap);
    562 }
    563 
    564 static void hidden_access_points_display(struct l_queue *access_points)
    565 {
    566 	const struct l_queue_entry *entry;
    567 
    568 	display_table_header("Available hidden APs", MARGIN "%-*s  %-*s  %*s",
    569 				20, "Address", 10, "Security", 6, "Signal");
    570 
    571 	if (l_queue_isempty(access_points)) {
    572 		display("No hidden APs are available.\n");
    573 		display_table_footer();
    574 
    575 		return;
    576 	}
    577 
    578 	for (entry = l_queue_get_entries(access_points); entry;
    579 							entry = entry->next) {
    580 		const struct hidden_access_point *ap = entry->data;
    581 		L_AUTO_FREE_VAR(char *, dbms) = NULL;
    582 
    583 		if (display_signal_as_dbms)
    584 			dbms = l_strdup_printf("%d", ap->signal_strength);
    585 
    586 		display_table_row(MARGIN, 3, 20, ap->address, 10, ap->type, 6,
    587 				dbms ? : dbms_tostars(ap->signal_strength));
    588 	}
    589 
    590 	display_table_footer();
    591 }
    592 
    593 static void hidden_access_points_callback(struct l_dbus_message *message,
    594 								void *proxy)
    595 {
    596 	struct l_queue *access_points = NULL;
    597 	struct l_dbus_message_iter iter;
    598 	const char *address;
    599 	uint16_t strength;
    600 	const char *type;
    601 
    602 	if (dbus_message_has_error(message))
    603 		return;
    604 
    605 	if (!l_dbus_message_get_arguments(message, "a(sns)", &iter)) {
    606 		l_error("Failed to parse hidden stations callback message");
    607 
    608 		return;
    609 	}
    610 
    611 	while (l_dbus_message_iter_next_entry(&iter, &address,
    612 						&strength, &type)) {
    613 		struct hidden_access_point *ap =
    614 			l_new(struct hidden_access_point, 1);
    615 
    616 		if (!access_points)
    617 			access_points = l_queue_new();
    618 
    619 		ap->address = l_strdup(address);
    620 		ap->signal_strength = strength;
    621 		ap->type = l_strdup(type);
    622 
    623 		l_queue_push_tail(access_points, ap);
    624 	}
    625 
    626 	hidden_access_points_display(access_points);
    627 
    628 	l_queue_destroy(access_points, hidden_access_point_destroy);
    629 }
    630 
    631 static enum cmd_status cmd_get_hidden_access_points(const char *device_name,
    632 							char **argv, int argc)
    633 {
    634 	const struct proxy_interface *station_i =
    635 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    636 
    637 	if (!station_i) {
    638 		display("Device '%s' is not in station mode.\n", device_name);
    639 		return CMD_STATUS_INVALID_VALUE;
    640 	}
    641 
    642 	if (!argc)
    643 		goto proceed;
    644 
    645 	if (!strcmp(argv[0], RSSI_DBMS))
    646 		display_signal_as_dbms = true;
    647 	else
    648 		display_signal_as_dbms = false;
    649 
    650 proceed:
    651 	proxy_interface_method_call(station_i, "GetHiddenAccessPoints", "",
    652 						hidden_access_points_callback);
    653 
    654 	return CMD_STATUS_TRIGGERED;
    655 }
    656 
    657 static enum cmd_status cmd_scan(const char *device_name,
    658 						char **argv, int argc)
    659 {
    660 	const struct proxy_interface *station_i =
    661 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    662 
    663 	if (!station_i) {
    664 		display("No station on device: '%s'\n", device_name);
    665 		return CMD_STATUS_INVALID_VALUE;
    666 	}
    667 
    668 	proxy_interface_method_call(station_i, "Scan", "",
    669 						check_errors_method_callback);
    670 
    671 	return CMD_STATUS_TRIGGERED;
    672 }
    673 
    674 static void get_diagnostics_callback(struct l_dbus_message *message,
    675 					void *user_data)
    676 {
    677 	struct l_dbus_message_iter iter;
    678 
    679 	if (dbus_message_has_error(message))
    680 		return;
    681 
    682 	if (!l_dbus_message_get_arguments(message, "a{sv}", &iter)) {
    683 		l_error("Failed to parse GetDiagnostics message");
    684 		goto done;
    685 	}
    686 
    687 	diagnostic_display(&iter, MARGIN, 20, 47);
    688 
    689 done:
    690 	/* Finish the table started by cmd_show */
    691 	display_table_footer();
    692 }
    693 
    694 static enum cmd_status cmd_show(const char *device_name,
    695 						char **argv, int argc)
    696 {
    697 	const struct proxy_interface *station =
    698 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    699 	const struct proxy_interface *diagnostic =
    700 					device_proxy_find(device_name,
    701 					IWD_STATION_DIAGNOSTIC_INTERFACE);
    702 
    703 	if (!station) {
    704 		display("No station on device: '%s'\n", device_name);
    705 		return CMD_STATUS_INVALID_VALUE;
    706 	}
    707 
    708 	display_station(device_name, station);
    709 
    710 	/*
    711 	 * No need to query additional diagnostic information if IWD has
    712 	 * no diagnostic interface.
    713 	 */
    714 	if (!diagnostic) {
    715 		display_table_footer();
    716 		return CMD_STATUS_DONE;
    717 	}
    718 
    719 	proxy_interface_method_call(diagnostic, "GetDiagnostics", "",
    720 					get_diagnostics_callback);
    721 
    722 	/* Don't display table footer, this will be done in the callback */
    723 	return CMD_STATUS_TRIGGERED;
    724 }
    725 
    726 
    727 static enum cmd_status cmd_get_bsses(const char *device_name,
    728 						char **argv, int argc)
    729 {
    730 	const struct proxy_interface *station_i =
    731 			device_proxy_find(device_name, IWD_STATION_INTERFACE);
    732 	const struct station *station = proxy_interface_get_data(station_i);
    733 	struct l_queue *bss_list;
    734 	const struct l_queue_entry *e;
    735 	const struct proxy_interface *network_proxy;
    736 	char header[256];
    737 
    738 	if (argc > 0)
    739 		network_proxy = find_network(device_name, argv[0],
    740 						argc >= 2 ? argv[1] : NULL);
    741 	else
    742 		network_proxy = station->connected_network;
    743 
    744 	if (!network_proxy) {
    745 		display_error("Can't find network");
    746 		return CMD_STATUS_INVALID_ARGS;
    747 	}
    748 
    749 	bss_list = network_get_bss_list(network_proxy);
    750 	if (!bss_list) {
    751 		display_error("No BSS list for network");
    752 		return CMD_STATUS_FAILED;
    753 	}
    754 
    755 	sprintf(header, "%s BasicServiceSets", network_get_name(network_proxy));
    756 
    757 	proxy_properties_display_header(header, MARGIN, 10, 18);
    758 
    759 	for (e = l_queue_get_entries(bss_list); e; e = e->next) {
    760 		const char *path = e->data;
    761 		const struct proxy_interface *bss_i = proxy_interface_find(
    762 						IWD_BSS_INTERFACE, path);
    763 
    764 		if (!bss_i)
    765 			continue;
    766 
    767 		display_table_row(MARGIN, 1, strlen(path), path);
    768 		proxy_properties_display_inline(bss_i, MARGIN, 10, 18);
    769 		display_table_row(MARGIN, 1, 1, "");
    770 	}
    771 
    772 	return CMD_STATUS_DONE;
    773 }
    774 
    775 static const struct command station_commands[] = {
    776 	{ NULL, "list", NULL, cmd_list, "List devices in Station mode", true },
    777 	{ "<wlan>", "connect",
    778 				"<\"network name\"> [security]",
    779 					cmd_connect,
    780 						"Connect to network", false,
    781 		connect_cmd_arg_completion },
    782 	{ "<wlan>", "connect-hidden",
    783 				"<\"network name\">",
    784 					cmd_connect_hidden_network,
    785 						"Connect to hidden network",
    786 									false },
    787 	{ "<wlan>", "disconnect",
    788 				NULL,   cmd_disconnect, "Disconnect" },
    789 	{ "<wlan>", "get-networks",
    790 				"[rssi-dbms/rssi-bars]",
    791 					cmd_get_networks,
    792 						"Get networks",       true,
    793 			get_networks_cmd_arg_completion },
    794 	{ "<wlan>", "get-hidden-access-points", "[rssi-dbms]",
    795 					cmd_get_hidden_access_points,
    796 						"Get hidden APs", true },
    797 	{ "<wlan>", "scan",     NULL,   cmd_scan, "Scan for networks" },
    798 	{ "<wlan>", "show",     NULL,   cmd_show, "Show station info", true },
    799 	{ "<wlan>", "get-bsses", "[network] [security]", cmd_get_bsses,
    800 				"Get BSS's for a network", true },
    801 	{ }
    802 };
    803 
    804 static char *family_arg_completion(const char *text, int state)
    805 {
    806 	return device_arg_completion(text, state, station_commands,
    807 							IWD_STATION_INTERFACE);
    808 }
    809 
    810 static char *entity_arg_completion(const char *text, int state)
    811 {
    812 	return command_entity_arg_completion(text, state, station_commands);
    813 }
    814 
    815 static struct command_family station_command_family = {
    816 	.caption = "Station",
    817 	.name = "station",
    818 	.command_list = station_commands,
    819 	.family_arg_completion = family_arg_completion,
    820 	.entity_arg_completion = entity_arg_completion,
    821 };
    822 
    823 static int station_command_family_init(void)
    824 {
    825 	command_family_register(&station_command_family);
    826 
    827 	return 0;
    828 }
    829 
    830 static void station_command_family_exit(void)
    831 {
    832 	command_family_unregister(&station_command_family);
    833 }
    834 
    835 COMMAND_FAMILY(station_command_family, station_command_family_init,
    836 						station_command_family_exit)
    837 
    838 static int station_interface_init(void)
    839 {
    840 	proxy_interface_type_register(&station_interface_type);
    841 	proxy_interface_type_register(&station_diagnostic_interface);
    842 
    843 	return 0;
    844 }
    845 
    846 static void station_interface_exit(void)
    847 {
    848 	proxy_interface_type_unregister(&station_interface_type);
    849 	proxy_interface_type_unregister(&station_diagnostic_interface);
    850 }
    851 
    852 INTERFACE_TYPE(station_interface_type,
    853 				station_interface_init, station_interface_exit)