3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-26 10:39:23 +01:00

network: Rework connect logic

This commit is contained in:
Denis Kenzior 2016-05-16 12:05:28 -05:00
parent 2fe80a8f86
commit bcb2ef3e40
3 changed files with 36 additions and 21 deletions

View File

@ -38,6 +38,7 @@ struct agent_request {
unsigned int id; unsigned int id;
void *user_data; void *user_data;
void *user_callback; void *user_callback;
struct l_dbus_message *trigger;
}; };
struct agent { struct agent {
@ -95,6 +96,10 @@ static void agent_request_free(void *user_data)
l_dbus_message_unref(request->message); l_dbus_message_unref(request->message);
if (request->trigger)
dbus_pending_reply(&request->trigger,
dbus_error_aborted(request->trigger));
l_free(request); l_free(request);
} }
@ -115,7 +120,7 @@ static void passphrase_reply(struct l_dbus_message *reply,
result = AGENT_RESULT_OK; result = AGENT_RESULT_OK;
done: done:
user_callback(result, passphrase, request->user_data); user_callback(result, passphrase, request->trigger, request->user_data);
} }
static void agent_finalize_pending(struct agent *agent, static void agent_finalize_pending(struct agent *agent,
@ -132,6 +137,11 @@ static void agent_finalize_pending(struct agent *agent,
passphrase_reply(reply, pending); passphrase_reply(reply, pending);
if (pending->trigger) {
l_dbus_message_unref(pending->trigger);
pending->trigger = NULL;
}
agent_request_free(pending); agent_request_free(pending);
} }
@ -214,7 +224,8 @@ static void agent_send_next_request(struct agent *agent)
static unsigned int agent_queue_request(struct agent *agent, static unsigned int agent_queue_request(struct agent *agent,
struct l_dbus_message *message, int timeout, struct l_dbus_message *message, int timeout,
void *callback, void *user_data) void *callback, struct l_dbus_message *trigger,
void *user_data)
{ {
struct agent_request *request; struct agent_request *request;
@ -224,6 +235,7 @@ static unsigned int agent_queue_request(struct agent *agent,
request->id = ++next_request_id; request->id = ++next_request_id;
request->user_data = user_data; request->user_data = user_data;
request->user_callback = callback; request->user_callback = callback;
request->trigger = l_dbus_message_ref(trigger);
agent->timeout_secs = timeout; agent->timeout_secs = timeout;
@ -239,13 +251,21 @@ static unsigned int agent_queue_request(struct agent *agent,
* agent_request_passphrase: * agent_request_passphrase:
* @path: object path related to this request (like network object path) * @path: object path related to this request (like network object path)
* @callback: user callback called when the request is ready * @callback: user callback called when the request is ready
* @trigger: Message associated with (e.g. that triggered) this request
* @user_data: user defined data * @user_data: user defined data
* *
* Called when a passphrase information is needed from the user. Returns an * Called when a passphrase information is needed from the user. Returns an
* id that can be used to cancel the request. * id that can be used to cancel the request.
*
* If @trigger is not NULL, then a reference is taken automatically. If
* agent_cancel_request is called subsequently, a dbus_aborted error is
* automatically generated for @trigger. Otherwise, after @callback is
* called, the reference to @trigger is dropped. It is assumed that the
* caller will take ownership of @trigger in the callback if needed.
*/ */
unsigned int agent_request_passphrase(const char *path, unsigned int agent_request_passphrase(const char *path,
agent_request_passphrase_func_t callback, agent_request_passphrase_func_t callback,
struct l_dbus_message *trigger,
void *user_data) void *user_data)
{ {
struct l_dbus_message *message; struct l_dbus_message *message;
@ -269,6 +289,7 @@ unsigned int agent_request_passphrase(const char *path,
return agent_queue_request(agent, message, return agent_queue_request(agent, message,
agent_timeout_input_request(), agent_timeout_input_request(),
callback, callback,
trigger,
user_data); user_data);
} }

View File

@ -29,6 +29,7 @@ enum agent_result {
typedef void (*agent_request_passphrase_func_t) (enum agent_result result, typedef void (*agent_request_passphrase_func_t) (enum agent_result result,
const char *passphrase, const char *passphrase,
struct l_dbus_message *message,
void *user_data); void *user_data);
bool agent_init(void); bool agent_init(void);
@ -37,5 +38,6 @@ bool agent_setup(struct l_dbus_interface *interface);
unsigned int agent_request_passphrase(const char *path, unsigned int agent_request_passphrase(const char *path,
agent_request_passphrase_func_t callback, agent_request_passphrase_func_t callback,
struct l_dbus_message *message,
void *user_data); void *user_data);
bool agent_request_cancel(unsigned int req_id); bool agent_request_cancel(unsigned int req_id);

View File

@ -311,10 +311,6 @@ static int mlme_authenticate_cmd(struct network *network, struct scan_bss *bss)
msg_append_attr(msg, NL80211_ATTR_AUTH_TYPE, 4, &auth_type); msg_append_attr(msg, NL80211_ATTR_AUTH_TYPE, 4, &auth_type);
l_genl_family_send(nl80211, msg, genl_connect_cb, netdev, NULL); l_genl_family_send(nl80211, msg, genl_connect_cb, netdev, NULL);
netdev->connected_bss = bss;
netdev->connected_network = network;
netdev_enter_state(netdev, DEVICE_STATE_CONNECTING);
return 0; return 0;
} }
@ -333,7 +329,9 @@ void device_connect_network(struct netdev *device, struct network *network,
} }
static void passphrase_callback(enum agent_result result, static void passphrase_callback(enum agent_result result,
const char *passphrase, void *user_data) const char *passphrase,
struct l_dbus_message *message,
void *user_data)
{ {
struct network *network = user_data; struct network *network = user_data;
struct netdev *netdev = network->netdev; struct netdev *netdev = network->netdev;
@ -345,8 +343,7 @@ static void passphrase_callback(enum agent_result result,
network->agent_request = 0; network->agent_request = 0;
if (result != AGENT_RESULT_OK) { if (result != AGENT_RESULT_OK) {
dbus_pending_reply(&netdev->connect_pending, dbus_pending_reply(&message, dbus_error_aborted(message));
dbus_error_aborted(netdev->connect_pending));
goto err; goto err;
} }
@ -354,8 +351,7 @@ static void passphrase_callback(enum agent_result result,
/* Did all good BSSes go away while we waited */ /* Did all good BSSes go away while we waited */
if (!bss) { if (!bss) {
dbus_pending_reply(&netdev->connect_pending, dbus_pending_reply(&message, dbus_error_failed(message));
dbus_error_failed(netdev->connect_pending));
goto err; goto err;
} }
@ -367,8 +363,7 @@ static void passphrase_callback(enum agent_result result,
network->psk) < 0) { network->psk) < 0) {
l_error("PMK generation failed. " l_error("PMK generation failed. "
"Ensure Crypto Engine is properly configured"); "Ensure Crypto Engine is properly configured");
dbus_pending_reply(&netdev->connect_pending, dbus_pending_reply(&message, dbus_error_failed(message));
dbus_error_failed(netdev->connect_pending));
goto err; goto err;
} }
@ -380,7 +375,7 @@ static void passphrase_callback(enum agent_result result,
*/ */
network->update_psk = true; network->update_psk = true;
mlme_authenticate_cmd(network, bss); device_connect_network(network->netdev, network, bss, message);
return; return;
err: err:
@ -429,14 +424,14 @@ static struct l_dbus_message *network_connect_psk(struct network *network,
network->agent_request = network->agent_request =
agent_request_passphrase(network->object_path, agent_request_passphrase(network->object_path,
passphrase_callback, passphrase_callback,
message,
network); network);
if (!network->agent_request) if (!network->agent_request)
return dbus_error_no_agent(message); return dbus_error_no_agent(message);
} else } else
mlme_authenticate_cmd(network, bss); device_connect_network(netdev, network, bss, message);
netdev->connect_pending = l_dbus_message_ref(message);
return NULL; return NULL;
} }
@ -469,14 +464,11 @@ static struct l_dbus_message *network_connect(struct l_dbus *dbus,
case SECURITY_PSK: case SECURITY_PSK:
return network_connect_psk(network, bss, message); return network_connect_psk(network, bss, message);
case SECURITY_NONE: case SECURITY_NONE:
mlme_authenticate_cmd(network, bss); device_connect_network(netdev, network, bss, message);
netdev->connect_pending = l_dbus_message_ref(message);
return NULL; return NULL;
case SECURITY_8021X: case SECURITY_8021X:
network_settings_load(network); network_settings_load(network);
device_connect_network(netdev, network, bss, message);
mlme_authenticate_cmd(network, bss);
netdev->connect_pending = l_dbus_message_ref(message);
return NULL; return NULL;
default: default:
return dbus_error_not_supported(message); return dbus_error_not_supported(message);