Use shared functions for network operations and param changes
Instead of implementing these separately in various control interface handlers, use shared functions. These add some of the previously missing notification calls, too, for the affected areas.
This commit is contained in:
parent
8bac466b00
commit
86b89452f6
4 changed files with 253 additions and 131 deletions
|
@ -830,37 +830,20 @@ static int wpa_supplicant_ctrl_iface_select_network(
|
|||
/* cmd: "<network id>" or "any" */
|
||||
if (os_strcmp(cmd, "any") == 0) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
ssid->disabled = 0;
|
||||
ssid = ssid->next;
|
||||
}
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssid = NULL;
|
||||
} else {
|
||||
id = atoi(cmd);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
|
||||
|
||||
ssid = wpa_config_get_network(wpa_s->conf, id);
|
||||
if (ssid == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
|
||||
"id=%d", id);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
|
||||
"network id=%d", id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
|
||||
/* Mark all other networks disabled and trigger reassociation */
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
ssid->disabled = id != ssid->id;
|
||||
ssid = ssid->next;
|
||||
}
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
|
||||
wpa_supplicant_select_network(wpa_s, ssid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -875,36 +858,19 @@ static int wpa_supplicant_ctrl_iface_enable_network(
|
|||
/* cmd: "<network id>" or "all" */
|
||||
if (os_strcmp(cmd, "all") == 0) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
if (ssid == wpa_s->current_ssid && ssid->disabled)
|
||||
wpa_s->reassociate = 1;
|
||||
ssid->disabled = 0;
|
||||
ssid = ssid->next;
|
||||
}
|
||||
if (wpa_s->reassociate)
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssid = NULL;
|
||||
} else {
|
||||
id = atoi(cmd);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
|
||||
|
||||
ssid = wpa_config_get_network(wpa_s->conf, id);
|
||||
if (ssid == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
|
||||
"id=%d", id);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
|
||||
"network id=%d", id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wpa_s->current_ssid == NULL && ssid->disabled) {
|
||||
/*
|
||||
* Try to reassociate since there is no current configuration
|
||||
* and a new network was made available. */
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
}
|
||||
ssid->disabled = 0;
|
||||
wpa_supplicant_enable_network(wpa_s, ssid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -919,30 +885,19 @@ static int wpa_supplicant_ctrl_iface_disable_network(
|
|||
/* cmd: "<network id>" or "all" */
|
||||
if (os_strcmp(cmd, "all") == 0) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
ssid->disabled = 1;
|
||||
ssid = ssid->next;
|
||||
}
|
||||
if (wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(wpa_s,
|
||||
WLAN_REASON_DEAUTH_LEAVING);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssid = NULL;
|
||||
} else {
|
||||
id = atoi(cmd);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
|
||||
|
||||
ssid = wpa_config_get_network(wpa_s->conf, id);
|
||||
if (ssid == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
|
||||
"id=%d", id);
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
|
||||
"network id=%d", id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ssid == wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
ssid->disabled = 1;
|
||||
}
|
||||
wpa_supplicant_disable_network(wpa_s, ssid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1569,11 +1524,7 @@ static int wpa_supplicant_ctrl_iface_ap_scan(
|
|||
struct wpa_supplicant *wpa_s, char *cmd)
|
||||
{
|
||||
int ap_scan = atoi(cmd);
|
||||
|
||||
if (ap_scan < 0 || ap_scan > 2)
|
||||
return -1;
|
||||
wpa_s->conf->ap_scan = ap_scan;
|
||||
return 0;
|
||||
return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -310,19 +310,13 @@ DBusMessage * wpas_dbus_global_set_debugparams(DBusMessage *message,
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* check for allowed debuglevels */
|
||||
if (debug_level != MSG_MSGDUMP &&
|
||||
debug_level != MSG_DEBUG &&
|
||||
debug_level != MSG_INFO &&
|
||||
debug_level != MSG_WARNING &&
|
||||
debug_level != MSG_ERROR) {
|
||||
if (wpa_supplicant_set_debug_params(global, debug_level,
|
||||
debug_timestamp ? 1 : 0,
|
||||
debug_show_keys ? 1 : 0)) {
|
||||
reply = wpas_dbus_new_invalid_opts_error(message, NULL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
wpa_debug_level = debug_level;
|
||||
wpa_debug_timestamp = debug_timestamp ? 1 : 0;
|
||||
wpa_debug_show_keys = debug_show_keys ? 1 : 0;
|
||||
reply = wpas_dbus_new_success_reply(message);
|
||||
|
||||
out:
|
||||
|
@ -1065,16 +1059,7 @@ DBusMessage * wpas_dbus_iface_enable_network(DBusMessage *message,
|
|||
struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid)
|
||||
{
|
||||
if (wpa_s->current_ssid == NULL && ssid->disabled) {
|
||||
/*
|
||||
* Try to reassociate since there is no current configuration
|
||||
* and a new network was made available.
|
||||
*/
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
}
|
||||
ssid->disabled = 0;
|
||||
|
||||
wpa_supplicant_enable_network(wpa_s, ssid);
|
||||
return wpas_dbus_new_success_reply(message);
|
||||
}
|
||||
|
||||
|
@ -1093,10 +1078,7 @@ DBusMessage * wpas_dbus_iface_disable_network(DBusMessage *message,
|
|||
struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid)
|
||||
{
|
||||
if (ssid == wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
ssid->disabled = 1;
|
||||
|
||||
wpa_supplicant_disable_network(wpa_s, ssid);
|
||||
return wpas_dbus_new_success_reply(message);
|
||||
}
|
||||
|
||||
|
@ -1121,13 +1103,7 @@ DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
|
|||
|
||||
if (strlen(dbus_message_get_signature(message)) == 0) {
|
||||
/* Any network */
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
ssid->disabled = 0;
|
||||
ssid = ssid->next;
|
||||
}
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
ssid = NULL;
|
||||
} else {
|
||||
const char *obj_path;
|
||||
int nid;
|
||||
|
@ -1166,23 +1142,10 @@ DBusMessage * wpas_dbus_iface_select_network(DBusMessage *message,
|
|||
reply = wpas_dbus_new_invalid_network_error(message);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Finally, associate with the network */
|
||||
if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(
|
||||
wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
|
||||
/* Mark all other networks disabled and trigger reassociation
|
||||
*/
|
||||
ssid = wpa_s->conf->ssid;
|
||||
while (ssid) {
|
||||
ssid->disabled = (nid != ssid->id);
|
||||
ssid = ssid->next;
|
||||
}
|
||||
wpa_s->disconnected = 0;
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
}
|
||||
wpa_supplicant_select_network(wpa_s, ssid);
|
||||
|
||||
reply = wpas_dbus_new_success_reply(message);
|
||||
|
||||
|
@ -1233,11 +1196,11 @@ DBusMessage * wpas_dbus_iface_set_ap_scan(DBusMessage *message,
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (ap_scan > 2) {
|
||||
if (wpa_supplicant_set_ap_scan(wpa_s, ap_scan)) {
|
||||
reply = wpas_dbus_new_invalid_opts_error(message, NULL);
|
||||
goto out;
|
||||
}
|
||||
wpa_s->conf->ap_scan = ap_scan;
|
||||
|
||||
reply = wpas_dbus_new_success_reply(message);
|
||||
|
||||
out:
|
||||
|
|
|
@ -1349,6 +1349,202 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_enable_network - Mark a configured network as enabled
|
||||
* @wpa_s: wpa_supplicant structure for a network interface
|
||||
* @ssid: wpa_ssid structure for a configured network or %NULL
|
||||
*
|
||||
* Enables the specified network or all networks if no network specified.
|
||||
*/
|
||||
void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid)
|
||||
{
|
||||
struct wpa_ssid *other_ssid;
|
||||
int was_disabled;
|
||||
|
||||
if (ssid == NULL) {
|
||||
other_ssid = wpa_s->conf->ssid;
|
||||
while (other_ssid) {
|
||||
if (other_ssid == wpa_s->current_ssid &&
|
||||
other_ssid->disabled)
|
||||
wpa_s->reassociate = 1;
|
||||
|
||||
was_disabled = other_ssid->disabled;
|
||||
|
||||
other_ssid->disabled = 0;
|
||||
|
||||
if (was_disabled != other_ssid->disabled)
|
||||
wpas_notify_network_enabled_changed(
|
||||
wpa_s, other_ssid);
|
||||
|
||||
other_ssid = other_ssid->next;
|
||||
}
|
||||
if (wpa_s->reassociate)
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
} else if (wpa_s->current_ssid == NULL && ssid->disabled) {
|
||||
/*
|
||||
* Try to reassociate since there is no current configuration
|
||||
* and a new network was made available.
|
||||
*/
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
|
||||
was_disabled = ssid->disabled;
|
||||
|
||||
ssid->disabled = 0;
|
||||
|
||||
if (was_disabled != ssid->disabled)
|
||||
wpas_notify_network_enabled_changed(wpa_s, ssid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_disable_network - Mark a configured network as disabled
|
||||
* @wpa_s: wpa_supplicant structure for a network interface
|
||||
* @ssid: wpa_ssid structure for a configured network or %NULL
|
||||
*
|
||||
* Disables the specified network or all networks if no network specified.
|
||||
*/
|
||||
void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid)
|
||||
{
|
||||
struct wpa_ssid *other_ssid;
|
||||
int was_disabled;
|
||||
|
||||
if (ssid == NULL) {
|
||||
other_ssid = wpa_s->conf->ssid;
|
||||
while (other_ssid) {
|
||||
was_disabled = other_ssid->disabled;
|
||||
|
||||
other_ssid->disabled = 1;
|
||||
|
||||
if (was_disabled != other_ssid->disabled)
|
||||
wpas_notify_network_enabled_changed(
|
||||
wpa_s, other_ssid);
|
||||
|
||||
other_ssid = other_ssid->next;
|
||||
}
|
||||
if (wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(
|
||||
wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
} else {
|
||||
if (ssid == wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(
|
||||
wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
|
||||
was_disabled = ssid->disabled;
|
||||
|
||||
ssid->disabled = 1;
|
||||
|
||||
if (was_disabled != ssid->disabled)
|
||||
wpas_notify_network_enabled_changed(wpa_s, ssid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_select_network - Attempt association with a network
|
||||
* @wpa_s: wpa_supplicant structure for a network interface
|
||||
* @ssid: wpa_ssid structure for a configured network or %NULL for any network
|
||||
*/
|
||||
void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid)
|
||||
{
|
||||
|
||||
struct wpa_ssid *other_ssid;
|
||||
|
||||
if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid)
|
||||
wpa_supplicant_disassociate(
|
||||
wpa_s, WLAN_REASON_DEAUTH_LEAVING);
|
||||
|
||||
/*
|
||||
* Mark all other networks disabled or mark all networks enabled if no
|
||||
* network specified.
|
||||
*/
|
||||
other_ssid = wpa_s->conf->ssid;
|
||||
while (other_ssid) {
|
||||
int was_disabled = other_ssid->disabled;
|
||||
|
||||
other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
|
||||
|
||||
if (was_disabled != other_ssid->disabled)
|
||||
wpas_notify_network_enabled_changed(wpa_s, other_ssid);
|
||||
|
||||
other_ssid = other_ssid->next;
|
||||
}
|
||||
wpa_s->disconnected = 0;
|
||||
wpa_s->reassociate = 1;
|
||||
wpa_supplicant_req_scan(wpa_s, 0, 0);
|
||||
|
||||
wpas_notify_network_selected(wpa_s, ssid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_set_ap_scan - Set AP scan mode for interface
|
||||
* @wpa_s: wpa_supplicant structure for a network interface
|
||||
* @ap_scan: AP scan mode
|
||||
* Returns: 0 if succeed or -1 if ap_scan has an invalid value
|
||||
*
|
||||
*/
|
||||
int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
|
||||
{
|
||||
|
||||
int old_ap_scan;
|
||||
|
||||
if (ap_scan < 0 || ap_scan > 2)
|
||||
return -1;
|
||||
|
||||
old_ap_scan = wpa_s->conf->ap_scan;
|
||||
wpa_s->conf->ap_scan = ap_scan;
|
||||
|
||||
if (old_ap_scan != wpa_s->conf->ap_scan)
|
||||
wpas_notify_ap_scan_changed(wpa_s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpa_supplicant_set_debug_params - Set global debug params
|
||||
* @global: wpa_global structure
|
||||
* @debug_level: debug level
|
||||
* @debug_timestamp: determines if show timestamp in debug data
|
||||
* @debug_show_keys: determines if show keys in debug data
|
||||
* Returns: 0 if succeed or -1 if debug_level has wrong value
|
||||
*/
|
||||
int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
|
||||
int debug_timestamp, int debug_show_keys)
|
||||
{
|
||||
|
||||
int old_level, old_timestamp, old_show_keys;
|
||||
|
||||
/* check for allowed debuglevels */
|
||||
if (debug_level != MSG_MSGDUMP &&
|
||||
debug_level != MSG_DEBUG &&
|
||||
debug_level != MSG_INFO &&
|
||||
debug_level != MSG_WARNING &&
|
||||
debug_level != MSG_ERROR)
|
||||
return -1;
|
||||
|
||||
old_level = wpa_debug_level;
|
||||
old_timestamp = wpa_debug_timestamp;
|
||||
old_show_keys = wpa_debug_show_keys;
|
||||
|
||||
wpa_debug_level = debug_level;
|
||||
wpa_debug_timestamp = debug_timestamp ? 1 : 0;
|
||||
wpa_debug_show_keys = debug_show_keys ? 1 : 0;
|
||||
|
||||
if (wpa_debug_level != old_level ||
|
||||
wpa_debug_timestamp != old_timestamp ||
|
||||
wpa_debug_show_keys != old_show_keys)
|
||||
wpas_notify_debug_params_changed(global);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_supplicant_get_scan_results_old(struct wpa_supplicant *wpa_s)
|
||||
{
|
||||
#define SCAN_AP_LIMIT 128
|
||||
|
|
|
@ -418,6 +418,18 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
|
|||
void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
|
||||
int reason_code);
|
||||
|
||||
void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid);
|
||||
void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid);
|
||||
void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
|
||||
struct wpa_ssid *ssid);
|
||||
int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s,
|
||||
int ap_scan);
|
||||
int wpa_supplicant_set_debug_params(struct wpa_global *global,
|
||||
int debug_level, int debug_timestamp,
|
||||
int debug_show_keys);
|
||||
|
||||
void wpa_show_license(void);
|
||||
|
||||
struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
|
||||
|
|
Loading…
Reference in a new issue