3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-29 22:09:38 +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;
void *user_data;
void *user_callback;
struct l_dbus_message *trigger;
};
struct agent {
@ -95,6 +96,10 @@ static void agent_request_free(void *user_data)
l_dbus_message_unref(request->message);
if (request->trigger)
dbus_pending_reply(&request->trigger,
dbus_error_aborted(request->trigger));
l_free(request);
}
@ -115,7 +120,7 @@ static void passphrase_reply(struct l_dbus_message *reply,
result = AGENT_RESULT_OK;
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,
@ -132,6 +137,11 @@ static void agent_finalize_pending(struct agent *agent,
passphrase_reply(reply, pending);
if (pending->trigger) {
l_dbus_message_unref(pending->trigger);
pending->trigger = NULL;
}
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,
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;
@ -224,6 +235,7 @@ static unsigned int agent_queue_request(struct agent *agent,
request->id = ++next_request_id;
request->user_data = user_data;
request->user_callback = callback;
request->trigger = l_dbus_message_ref(trigger);
agent->timeout_secs = timeout;
@ -239,13 +251,21 @@ static unsigned int agent_queue_request(struct agent *agent,
* agent_request_passphrase:
* @path: object path related to this request (like network object path)
* @callback: user callback called when the request is ready
* @trigger: Message associated with (e.g. that triggered) this request
* @user_data: user defined data
*
* Called when a passphrase information is needed from the user. Returns an
* 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,
agent_request_passphrase_func_t callback,
struct l_dbus_message *trigger,
void *user_data)
{
struct l_dbus_message *message;
@ -269,6 +289,7 @@ unsigned int agent_request_passphrase(const char *path,
return agent_queue_request(agent, message,
agent_timeout_input_request(),
callback,
trigger,
user_data);
}

View File

@ -29,6 +29,7 @@ enum agent_result {
typedef void (*agent_request_passphrase_func_t) (enum agent_result result,
const char *passphrase,
struct l_dbus_message *message,
void *user_data);
bool agent_init(void);
@ -37,5 +38,6 @@ bool agent_setup(struct l_dbus_interface *interface);
unsigned int agent_request_passphrase(const char *path,
agent_request_passphrase_func_t callback,
struct l_dbus_message *message,
void *user_data);
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);
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;
}
@ -333,7 +329,9 @@ void device_connect_network(struct netdev *device, struct network *network,
}
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 netdev *netdev = network->netdev;
@ -345,8 +343,7 @@ static void passphrase_callback(enum agent_result result,
network->agent_request = 0;
if (result != AGENT_RESULT_OK) {
dbus_pending_reply(&netdev->connect_pending,
dbus_error_aborted(netdev->connect_pending));
dbus_pending_reply(&message, dbus_error_aborted(message));
goto err;
}
@ -354,8 +351,7 @@ static void passphrase_callback(enum agent_result result,
/* Did all good BSSes go away while we waited */
if (!bss) {
dbus_pending_reply(&netdev->connect_pending,
dbus_error_failed(netdev->connect_pending));
dbus_pending_reply(&message, dbus_error_failed(message));
goto err;
}
@ -367,8 +363,7 @@ static void passphrase_callback(enum agent_result result,
network->psk) < 0) {
l_error("PMK generation failed. "
"Ensure Crypto Engine is properly configured");
dbus_pending_reply(&netdev->connect_pending,
dbus_error_failed(netdev->connect_pending));
dbus_pending_reply(&message, dbus_error_failed(message));
goto err;
}
@ -380,7 +375,7 @@ static void passphrase_callback(enum agent_result result,
*/
network->update_psk = true;
mlme_authenticate_cmd(network, bss);
device_connect_network(network->netdev, network, bss, message);
return;
err:
@ -429,14 +424,14 @@ static struct l_dbus_message *network_connect_psk(struct network *network,
network->agent_request =
agent_request_passphrase(network->object_path,
passphrase_callback,
message,
network);
if (!network->agent_request)
return dbus_error_no_agent(message);
} else
mlme_authenticate_cmd(network, bss);
device_connect_network(netdev, network, bss, message);
netdev->connect_pending = l_dbus_message_ref(message);
return NULL;
}
@ -469,14 +464,11 @@ static struct l_dbus_message *network_connect(struct l_dbus *dbus,
case SECURITY_PSK:
return network_connect_psk(network, bss, message);
case SECURITY_NONE:
mlme_authenticate_cmd(network, bss);
netdev->connect_pending = l_dbus_message_ref(message);
device_connect_network(netdev, network, bss, message);
return NULL;
case SECURITY_8021X:
network_settings_load(network);
mlme_authenticate_cmd(network, bss);
netdev->connect_pending = l_dbus_message_ref(message);
device_connect_network(netdev, network, bss, message);
return NULL;
default:
return dbus_error_not_supported(message);