From 9f2a9373aab87194562c7935bc9812eeaf4a3d6c Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 9 Apr 2026 12:01:35 +0700 Subject: [PATCH] iwd_agent: surface Cancel + stub EAP methods, expose cancel hook iwd's Cancel(reason) now invokes a UI callback (registered via iwd_manager_set_cancel_handler) so the popup can tear down an open auth dialog. Stubbed RequestPrivateKeyPassphrase / RequestUserNameAndPassword / RequestUserPassword to return Canceled instead of leaving them unimplemented (which would unregister us). Co-Authored-By: Claude Opus 4.6 (1M context) --- src/iwd/iwd_agent.c | 40 +++++++++++++++++++++++++++++++++++++++- src/iwd/iwd_agent.h | 6 ++++++ src/iwd/iwd_manager.c | 7 +++++++ src/iwd/iwd_manager.h | 5 +++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/iwd/iwd_agent.c b/src/iwd/iwd_agent.c index f0337fc..6947f90 100644 --- a/src/iwd/iwd_agent.c +++ b/src/iwd/iwd_agent.c @@ -13,6 +13,8 @@ struct _Iwd_Agent Eldbus_Proxy *am_proxy; Iwd_Agent_Passphrase_Cb cb; void *data; + Iwd_Agent_Cancel_Cb cancel_cb; + void *cancel_data; }; struct _Iwd_Agent_Request @@ -36,10 +38,26 @@ static Eldbus_Message * _cancel_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) { - /* iwd dropped the auth attempt; we just ack. */ + /* iwd dropped the auth attempt; let the UI tear down its dialog. */ + const char *reason = NULL; + if (!eldbus_message_arguments_get(msg, "s", &reason)) reason = NULL; + if (_self && _self->cancel_cb) + _self->cancel_cb(_self->cancel_data, reason); return eldbus_message_method_return_new(msg); } +/* iwd may also call these for EAP networks. We don't have UI for them yet, + * so politely refuse — that just fails the connect attempt instead of + * getting our agent unregistered. */ +static Eldbus_Message * +_unsupported_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, + const Eldbus_Message *msg) +{ + return eldbus_message_error_new(msg, + "net.connman.iwd.Agent.Error.Canceled", + "Method not supported by this agent"); +} + static Eldbus_Message * _request_passphrase_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) @@ -70,6 +88,18 @@ static const Eldbus_Method _methods[] = { { "Cancel", ELDBUS_ARGS({ "s", "reason" }), NULL, _cancel_cb, 0 }, + { "RequestPrivateKeyPassphrase", + ELDBUS_ARGS({ "o", "network" }), + ELDBUS_ARGS({ "s", "passphrase" }), + _unsupported_cb, 0 }, + { "RequestUserNameAndPassword", + ELDBUS_ARGS({ "o", "network" }), + ELDBUS_ARGS({ "s", "user" }, { "s", "password" }), + _unsupported_cb, 0 }, + { "RequestUserPassword", + ELDBUS_ARGS({ "o", "network" }, { "s", "user" }), + ELDBUS_ARGS({ "s", "password" }), + _unsupported_cb, 0 }, { NULL, NULL, NULL, NULL, 0 } }; @@ -137,6 +167,14 @@ iwd_agent_new(Eldbus_Connection *conn, Iwd_Agent_Passphrase_Cb cb, void *data) return a; } +void +iwd_agent_set_cancel_cb(Iwd_Agent *a, Iwd_Agent_Cancel_Cb cb, void *data) +{ + if (!a) return; + a->cancel_cb = cb; + a->cancel_data = data; +} + void iwd_agent_free(Iwd_Agent *a) { diff --git a/src/iwd/iwd_agent.h b/src/iwd/iwd_agent.h index 3f899b8..9fcc168 100644 --- a/src/iwd/iwd_agent.h +++ b/src/iwd/iwd_agent.h @@ -13,8 +13,14 @@ typedef void (*Iwd_Agent_Passphrase_Cb)(void *data, Iwd_Agent_Request *req, const char *network_path); +/* Fired when iwd issues a Cancel(reason) for the in-flight passphrase + * request — the UI should tear down any open auth dialog. */ +typedef void (*Iwd_Agent_Cancel_Cb)(void *data, const char *reason); + Iwd_Agent *iwd_agent_new (Eldbus_Connection *conn, Iwd_Agent_Passphrase_Cb cb, void *data); + +void iwd_agent_set_cancel_cb(Iwd_Agent *a, Iwd_Agent_Cancel_Cb cb, void *data); void iwd_agent_free(Iwd_Agent *a); void iwd_agent_reply (Iwd_Agent_Request *req, const char *passphrase); diff --git a/src/iwd/iwd_manager.c b/src/iwd/iwd_manager.c index bc13db1..3332d69 100644 --- a/src/iwd/iwd_manager.c +++ b/src/iwd/iwd_manager.c @@ -43,6 +43,13 @@ iwd_manager_set_passphrase_handler(Iwd_Manager *m, Iwd_Agent_Passphrase_Cb cb, v m->pass_data = data; } +void +iwd_manager_set_cancel_handler(Iwd_Manager *m, Iwd_Agent_Cancel_Cb cb, void *data) +{ + if (!m) return; + iwd_agent_set_cancel_cb(m->agent, cb, data); +} + static void _recompute_state(Iwd_Manager *m); /* ----- listeners ------------------------------------------------------- */ diff --git a/src/iwd/iwd_manager.h b/src/iwd/iwd_manager.h index 25ccddf..900fad4 100644 --- a/src/iwd/iwd_manager.h +++ b/src/iwd/iwd_manager.h @@ -42,4 +42,9 @@ void iwd_manager_set_passphrase_handler(Iwd_Manager *m, Iwd_Agent_Passphrase_Cb cb, void *data); +/* Notified when iwd issues Agent.Cancel — UI should close any open prompt. */ +void iwd_manager_set_cancel_handler (Iwd_Manager *m, + Iwd_Agent_Cancel_Cb cb, + void *data); + #endif