client: Update to the new GetHiddenAccessPoints API

This commit is contained in:
Denis Kenzior 2018-11-09 14:06:00 -06:00
parent 6df62ab68e
commit 48b74d6531
1 changed files with 38 additions and 37 deletions

View File

@ -452,57 +452,59 @@ proceed:
return CMD_STATUS_TRIGGERED; return CMD_STATUS_TRIGGERED;
} }
struct hidden_station { struct hidden_access_point {
char *address; char *address;
int16_t signal_strength; int16_t signal_strength;
char *type; char *type;
}; };
static void hidden_station_destroy(void *data) static void hidden_access_point_destroy(void *data)
{ {
struct hidden_station *station = data; struct hidden_access_point *ap = data;
l_free(station->address); l_free(ap->address);
l_free(station->type); l_free(ap->type);
l_free(station); l_free(ap);
} }
static void hidden_stations_display(struct l_queue *stations) static void hidden_access_points_display(struct l_queue *access_points)
{ {
const struct l_queue_entry *entry; const struct l_queue_entry *entry;
display_table_header("Available hidden stations", MARGIN "%-*s%-*s%*s", display_table_header("Available hidden APs", MARGIN "%-*s%-*s%*s",
20, "Address", 10, "Security", 6, "Signal"); 20, "Address", 10, "Security", 6, "Signal");
if (l_queue_isempty(stations)) { if (l_queue_isempty(access_points)) {
display("No hidden stations are available.\n"); display("No hidden APs are available.\n");
display_table_footer(); display_table_footer();
return; return;
} }
for (entry = l_queue_get_entries(stations); entry; for (entry = l_queue_get_entries(access_points); entry;
entry = entry->next) { entry = entry->next) {
const struct hidden_station *station = entry->data; const struct hidden_access_point *ap = entry->data;
L_AUTO_FREE_VAR(char *, dbms) = NULL; L_AUTO_FREE_VAR(char *, dbms) = NULL;
if (display_signal_as_dbms) if (display_signal_as_dbms)
dbms = l_strdup_printf("%d", station->signal_strength); dbms = l_strdup_printf("%d", ap->signal_strength);
display(MARGIN "%-*s%-*s%-*s\n", display(MARGIN "%-*s%-*s%-*s\n",
20, station->address, 10, station->type, 20, ap->address, 10, ap->type,
6, dbms ? : dbms_tostars(station->signal_strength)); 6, dbms ? : dbms_tostars(ap->signal_strength));
} }
display_table_footer(); display_table_footer();
} }
static void hidden_stations_callback(struct l_dbus_message *message, static void hidden_access_points_callback(struct l_dbus_message *message,
void *proxy) void *proxy)
{ {
struct l_queue *stations = NULL; struct l_queue *access_points = NULL;
struct hidden_station station;
struct l_dbus_message_iter iter; struct l_dbus_message_iter iter;
const char *address;
uint16_t strength;
const char *type;
if (dbus_message_has_error(message)) if (dbus_message_has_error(message))
return; return;
@ -513,28 +515,27 @@ static void hidden_stations_callback(struct l_dbus_message *message,
return; return;
} }
while (l_dbus_message_iter_next_entry(&iter, while (l_dbus_message_iter_next_entry(&iter, &address,
&station.address, &strength, &type)) {
&station.signal_strength, struct hidden_access_point *ap =
&station.type)) { l_new(struct hidden_access_point, 1);
struct hidden_station *sta = l_new(struct hidden_station, 1);
if (!stations) if (!access_points)
stations = l_queue_new(); access_points = l_queue_new();
sta->address = l_strdup(station.address); ap->address = l_strdup(address);
sta->signal_strength = station.signal_strength; ap->signal_strength = strength;
sta->type = l_strdup(station.type); ap->type = l_strdup(type);
l_queue_push_tail(stations, sta); l_queue_push_tail(access_points, ap);
} }
hidden_stations_display(stations); hidden_access_points_display(access_points);
l_queue_destroy(stations, hidden_station_destroy); l_queue_destroy(access_points, hidden_access_point_destroy);
} }
static enum cmd_status cmd_get_hidden_stations(const char *device_name, static enum cmd_status cmd_get_hidden_access_points(const char *device_name,
char **argv, int argc) char **argv, int argc)
{ {
const struct proxy_interface *station_i = const struct proxy_interface *station_i =
@ -554,8 +555,8 @@ static enum cmd_status cmd_get_hidden_stations(const char *device_name,
display_signal_as_dbms = false; display_signal_as_dbms = false;
proceed: proceed:
proxy_interface_method_call(station_i, "GetHiddenStations", "", proxy_interface_method_call(station_i, "GetHiddenAccessPoints", "",
hidden_stations_callback); hidden_access_points_callback);
return CMD_STATUS_TRIGGERED; return CMD_STATUS_TRIGGERED;
} }
@ -596,9 +597,9 @@ static const struct command station_commands[] = {
cmd_get_networks, cmd_get_networks,
"Get networks", true, "Get networks", true,
get_networks_cmd_arg_completion }, get_networks_cmd_arg_completion },
{ "<wlan>", "get-hidden-stations", "[rssi-dbms]", { "<wlan>", "get-hidden-access-points", "[rssi-dbms]",
cmd_get_hidden_stations, cmd_get_hidden_access_points,
"Get hidden stations", true }, "Get hidden APs", true },
{ "<wlan>", "scan", NULL, cmd_scan, "Scan for networks" }, { "<wlan>", "scan", NULL, cmd_scan, "Scan for networks" },
{ } { }
}; };