From patchwork Wed Aug 10 23:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941017 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A967146AA for ; Wed, 10 Aug 2022 23:16:23 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id g12so15061352pfb.3 for ; Wed, 10 Aug 2022 16:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=G4q47j3huIT85zBjDyk4T5pfIXgxJTCTADRl/zkiJhY=; b=eNY2R9e/vwMqACmHSabqZ6l2Zove48GaXb1g7m2OfbgyKoG1QldKcfLA3bGWcuI01f AoAt5NeuukGEG/MaPqE636u8WW7AefxQdnWXzu8h+CNOC2uefqwVfNv79XgcP6K8t/nJ Q9qLVEyvVtaJmoZCjKlSyDXbIMKX1ei2m4gG9JweMG1A4Hi2cK9ZA7Xzi9vjD1UcDZDy NEKWtCCNqxbZSf2LTJHzxLQS82k8bDM7jLeo5rIDwLKOdI7V+/9tN/6DoFXUIWphL5EO P35i9XUMlFJlkRqqGG7b6DNs+taC9qPq58/SmVCUf7f2y/Zdv+RCIX0j6S/+ihwzW9z6 TGAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=G4q47j3huIT85zBjDyk4T5pfIXgxJTCTADRl/zkiJhY=; b=g/s1jtxau9Bckxp5Axj1vKVGhuve6bUAuJDrJNzlWGg/DcyDaF4pZHAd6kh8iQvnOJ X17ibyqQusNuV0LTUEX0FZXNx1LDwW79d5+lJToJv3PeZB2Xg4EAi90mAV3k7N3O0K5h sCzFHo59eyVAuyfAuEIH7Qxms4pHenx4AXxFMG442yHzHWjCk5lwGZK5KSRZbx6hXdCy EbuE3v4u5sSP+17bjBRrXZewZC+csfnLc3xtdlApj4IyatbeNKq5VYSaT+OaSvD2+q9u 59rwtM+tsjpUZEcKR5D+JCn9zmKzFERBwlndFwvNY4G9t6OYsM3CxrolKu6tU31w3gEc vfRQ== X-Gm-Message-State: ACgBeo0f3Qa0k9Y0aTAP54rUHRDFK/APuViCqbuDAnWS9wsQg1Fef86e fyzM5k7OC88inpTg35LGL8p0xuD6wjI= X-Google-Smtp-Source: AA6agR4TYoHRbtbpSCQDnHhyaFfUql9qbKk0pTU2382Yk7pElAuHPndQ9DSlTtn0sohMJY8WS8zgAQ== X-Received: by 2002:a63:8bc8:0:b0:41c:6800:d4e9 with SMTP id j191-20020a638bc8000000b0041c6800d4e9mr23947915pge.45.1660173382946; Wed, 10 Aug 2022 16:16:22 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:22 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 1/8] network: make network const in network_bss_list_get_entries Date: Wed, 10 Aug 2022 16:16:14 -0700 Message-Id: <20220810231621.372514-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 No reason for this to not be const. --- src/network.c | 2 +- src/network.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network.c b/src/network.c index c0befa42..3099d102 100644 --- a/src/network.c +++ b/src/network.c @@ -1168,7 +1168,7 @@ struct erp_cache_entry *network_get_erp_cache(struct network *network) } const struct l_queue_entry *network_bss_list_get_entries( - struct network *network) + const struct network *network) { return l_queue_get_entries(network->bss_list); } diff --git a/src/network.h b/src/network.h index c6b99f6c..f29649f7 100644 --- a/src/network.h +++ b/src/network.h @@ -91,7 +91,7 @@ void network_blacklist_add(struct network *network, struct scan_bss *bss); struct erp_cache_entry *network_get_erp_cache(struct network *network); const struct l_queue_entry *network_bss_list_get_entries( - struct network *network); + const struct network *network); struct l_dbus_message *__network_connect(struct network *network, struct scan_bss *bss, From patchwork Wed Aug 10 23:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941018 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64F5446AE for ; Wed, 10 Aug 2022 23:16:24 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id e8-20020a17090a280800b001f2fef7886eso3561631pjd.3 for ; Wed, 10 Aug 2022 16:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=8/ZyNhNS+d/UW4nLhtskXD5Bho6Qy391QnV4HgLvIwQ=; b=P81RoiJGDkTCIbeBfXHbugLMIDV+C+uyFlYa0wbwKowbOZ+HktHUgeU0KvlhdF/sH6 C4ZEgQZ/DHpz2mNDQwwnT1EpVeOAtTDLTCsWhagRJ/Opud4zo99qXjL3xZJQdHUQEih7 ZfB+xkk1bcbGzv0C4Es3UOw6cXAQLYrH9aGouKsxkG3B4Lz3ORhv2HyffaF309fBYRwx G5d1Tor4JS3FueGD9XZiGqMi9HOk7+jfCXYD0WBD6qx3RWIl1N+Yh6QK89xPcE2tGRmz Sy1TIRRN77ZXSj5ctq/1NZbCzre1OQ84U14GhkyKoGzFKwehomXUmMTaIuyOG8tJsXwu T9cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=8/ZyNhNS+d/UW4nLhtskXD5Bho6Qy391QnV4HgLvIwQ=; b=PLcsv2/x6SAQ3wzfCS2BlrecqRgKz+b0vxbhjq+Qte/ncKyps0UTP2uSd08eP6WQ/r TExGNQog5H4KPY536T1WqlvSrOxwE+RN7QPSiigigvguRyb5FQM9pVSBllHCoG3Y02Pj 5GZ8O7SUyo/vfY0Nl/rW9/9mQUfo7waYOx2fMcsNtWcjgt4yhuyJSJUmN7F6gPS+UrLF 8bMIMf/YKXslUOPuQJrkmKyXJH2NE4T6w/Mg/7/UKslOfzybiUObXVPp+6MgrIPEFZNm IAI25EBufKL2CDK89ESBeeOX8tIinLdoyQ9cUffhStyhOtQ5UiVMkwYGXyn6VMF2iITg 5FQg== X-Gm-Message-State: ACgBeo2kvP/r6/M6NAEHiHQwBOqUDzrAnQztW8lU0RLizl/KYxpQdL5k tBkPyKqskJFBkb6qk3vKrULZXjPLxh0= X-Google-Smtp-Source: AA6agR4uWKyoqY7qd/+9TUzOl8+ZE0fSYuz/76EXCiWhVmlQ+trzsHPunDcOENobSDBoIc4I68CI5g== X-Received: by 2002:a17:902:d1d5:b0:16d:d21d:abb8 with SMTP id g21-20020a170902d1d500b0016dd21dabb8mr30074529plb.138.1660173383657; Wed, 10 Aug 2022 16:16:23 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:23 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 2/8] station: check for matching SSID in Roam() Date: Wed, 10 Aug 2022 16:16:15 -0700 Message-Id: <20220810231621.372514-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is a debug method, but still should verify the SSID in the target matches the current BSS. --- src/station.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/station.c b/src/station.c index 8c230b52..57dbd0d5 100644 --- a/src/station.c +++ b/src/station.c @@ -4373,6 +4373,13 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus, if (!target || target == station->connected_bss) return dbus_error_invalid_args(message); + if (station->connected_bss->ssid_len != target->ssid_len) + goto invalid_args; + + if (memcmp(station->connected_bss->ssid, target->ssid, + target->ssid_len)) + goto invalid_args; + l_debug("Attempting forced roam to BSS "MAC, MAC_STR(mac)); /* The various roam routines expect this to be set from scanning */ From patchwork Wed Aug 10 23:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941019 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 126D14A02 for ; Wed, 10 Aug 2022 23:16:24 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id h21-20020a17090aa89500b001f31a61b91dso3664301pjq.4 for ; Wed, 10 Aug 2022 16:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=o3Rjy5NwMKxNjMOHHbJXvC5jL9zULP6bFt4opPJz0LE=; b=hGBd7lJ0Fw5zwwtw8/XSwpj19stALC+RKF70sYaKBzXV5VAH+ttP54KPLyoTWatSNG T4BAtaTyLDUrpvGfwPkzVvQtiT0WiYt4C98jGjez99/bwd1liNSb4IdZkK8+wO5gWYHv DtRXlWEHwXRnE05IFlLcPxLvj4k1/syCVwh94aq6Eh8f+O767M5EzcWWMwJtUmJa7Hwv x+M3k1Iuk0N6pVOmNquqwVShCWsr5ILIuxuWiEvlBJnWmf6Lc6Dj0QpMKUjiUx0zjhwK ZndfFk9TP5Rh/fVVA+gv/cE67UdolDgEBchxWq6g1X1DV1ticOjy1jw4hu+SgLNhLJoI wfwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=o3Rjy5NwMKxNjMOHHbJXvC5jL9zULP6bFt4opPJz0LE=; b=v/ybiIS5RpAjBCpqLgcXJk26G0WJw/kP+aCG1ZcM6utQKE1RXH5oo6yRc13+V6mAHO b2ARVeseXiJGwrOWm7SaV/GcxLi1sXVjp9tsY/9t5O709/6lUpyQ5fCzxyO0C4ZIk/xP xmobGBmn3aqZtpsmU7mOZeOV2Zc5sMh6QqO9aTEPvBDw3j1GciRhjY++TmdCbJ1XFP5L 7hD3jS0n+2+dYVlH0TXtey1GpFNSuPgGhFDhTnBQhnZWEAFytQacl7h8fiqGO5oLmJMI XM1KRMeUxOWInCEUSMuMLshLsJtkS/6oSIaHrfWyhVZkmmYIOn85Hl+0v7bMt1kM48OV RDlA== X-Gm-Message-State: ACgBeo3qVZViXxx2Ar0kxraKd1iXo2itnawfGqwInmarUMY05wexLAxs +VXsQW9adtHRPS4D2bbmHhJUU/TEwjU= X-Google-Smtp-Source: AA6agR5EjBgnFyY7OoJ/eo5GHKAEh6Am7t1TPpaDf1ZxQM2VyOj0Wk97LPtw5mNGxVcC+34/Z0ESmQ== X-Received: by 2002:a17:902:e890:b0:170:c2f:cb4d with SMTP id w16-20020a170902e89000b001700c2fcb4dmr24417835plg.114.1660173384360; Wed, 10 Aug 2022 16:16:24 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:23 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 3/8] station: add debug method GetNetworks Date: Wed, 10 Aug 2022 16:16:16 -0700 Message-Id: <20220810231621.372514-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This gets all networks but includes individual entries for each BSS. --- src/station.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/station.c b/src/station.c index 57dbd0d5..4f0f2afc 100644 --- a/src/station.c +++ b/src/station.c @@ -4600,6 +4600,97 @@ static struct l_dbus_message *station_property_set_autoconnect( return l_dbus_message_new_method_return(message); } +static void station_append_byte_array(struct l_dbus_message_builder *builder, + const char *name, + const uint8_t *bytes, size_t len) +{ + size_t i; + + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', name); + l_dbus_message_builder_enter_variant(builder, "ay"); + l_dbus_message_builder_enter_array(builder, "y"); + + for (i = 0; i < len; i++) + l_dbus_message_builder_append_basic(builder, 'y', &bytes[i]); + + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); +} + +static void station_append_bss_list(struct l_dbus_message_builder *builder, + const struct l_queue_entry *entry) +{ + for (; entry; entry = entry->next) { + struct scan_bss *bss = entry->data; + int32_t rssi = bss->signal_strength / 100; + + l_dbus_message_builder_enter_array(builder, "{sv}"); + + dbus_append_dict_basic(builder, "Frequency", 'u', + &bss->frequency); + dbus_append_dict_basic(builder, "RSSI", 'i', + &rssi); + dbus_append_dict_basic(builder, "Rank", 'i', &bss->rank); + + station_append_byte_array(builder, "Address", bss->addr, 6); + station_append_byte_array(builder, "MDE", bss->mde, 3); + + l_dbus_message_builder_leave_array(builder); + } +} + +static struct l_dbus_message *station_debug_get_networks(struct l_dbus *dbus, + struct l_dbus_message *message, + void *user_data) +{ + struct station *station = user_data; + struct l_dbus_message *reply = + l_dbus_message_new_method_return(message); + struct l_dbus_message_builder *builder = + l_dbus_message_builder_new(reply); + const struct l_queue_entry *entry; + + l_dbus_message_builder_enter_array(builder, "{sv}"); + + for (entry = l_queue_get_entries(station->networks_sorted); entry; + entry = entry->next) { + const struct network *network = entry->data; + + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', + network_get_ssid(network)); + l_dbus_message_builder_enter_variant(builder, "aa{sv}"); + l_dbus_message_builder_enter_array(builder, "a{sv}"); + + station_append_bss_list(builder, + network_bss_list_get_entries(network)); + + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); + } + + /* Hidden Networks. Use an empty string for the SSID */ + l_dbus_message_builder_enter_dict(builder, "sv"); + l_dbus_message_builder_append_basic(builder, 's', ""); + l_dbus_message_builder_enter_variant(builder, "aa{sv}"); + l_dbus_message_builder_enter_array(builder, "a{sv}"); + station_append_bss_list(builder, + l_queue_get_entries(station->hidden_bss_list_sorted)); + l_dbus_message_builder_leave_array(builder); + l_dbus_message_builder_leave_variant(builder); + l_dbus_message_builder_leave_dict(builder); + + l_dbus_message_builder_leave_array(builder); + + l_dbus_message_builder_finalize(builder); + l_dbus_message_builder_destroy(builder); + + return reply; +} + static void station_setup_debug_interface( struct l_dbus_interface *interface) { @@ -4612,6 +4703,9 @@ static void station_setup_debug_interface( l_dbus_interface_method(interface, "Scan", 0, station_debug_scan, "", "aq", "frequencies"); + l_dbus_interface_method(interface, "GetNetworks", 0, + station_debug_get_networks, "a{sv}", "", + "networks"); l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data"); From patchwork Wed Aug 10 23:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941020 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C571246AE for ; Wed, 10 Aug 2022 23:16:25 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id o3so15557123ple.5 for ; Wed, 10 Aug 2022 16:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=JNi+R0Ux3MrRht4PnoVVb8YFjtCK0mjLNj/3g3NIMQc=; b=Pg+D36b8Oz48Yzn3dT7MjEypcawvY6vwzsiB/X77cx8F+HSMaBeb5HG8Ny2FoZ+VxE qhWhuex5cOw+mwl2lw7xUuoScy8AOYaoRnvWIjvh4w/XWu4bllW1PEs8j3u7MnOlqLWy l39EFSZSI1i0ILojkkATAaQBIlx1X3HMWOLkcgvr6+YoHh9J1/fPzka3q3FwDED3/Fz3 GnJWho++T6lEUJbY69IB2KGMkTNoZm131/kk93isgGF4O/dTjBKtDt/gRzv3SoHkGfnJ pX09yr5xjIU/P9ZvF8ba31ba9giYN5MaixhBqYMM4ukRFnhWdIeNl02ESBvxlQS6ZWB8 TnBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=JNi+R0Ux3MrRht4PnoVVb8YFjtCK0mjLNj/3g3NIMQc=; b=gY2dEHuvaA3BdMhVtYeKKVTXvZzKkuLDaNJl61PPWf//BWxJE5eF8JPjN2RlvCmvAE ZE4yGBXza7kHEqAO9XFOTQHT/ErPoPeUnpBWvbIL7Ubkcl1Y7sOKkKcLejlyHdvC4KHF K/D1gRzbVNEkcFk1qUzMvoT/3HQY3V0UVOwVH8e49ZELfZ+SbLBSQdXRwK3aCKq8gcFc izt4EmFsSChUhV+27Wks0L+sw1G+xv4fqKiullKaqdvGWqNuLJQZxGUtgzTVkhFpt4/a HlzKQf88/h4vBqnhCwZn6sOc2oYEs94Nc/TXlHf/hDRyAetpB+U4ffYkQ2M/o3Rfzs2t CDtw== X-Gm-Message-State: ACgBeo2oPHmG+8eRKqR7aL/B5gUbg3pDI3jKdfSJiZu/w4QmQP2dq6MQ E5FSVAmlVEUkLN+YcBSjCVBamQFKMh8= X-Google-Smtp-Source: AA6agR49e+vVzjVoWCJH02DIdUIJERrF0tclClP4FnLgegzOF24bUq+PMiHM356yGbmLrLrz506S/g== X-Received: by 2002:a17:902:a416:b0:16d:4cff:269c with SMTP id p22-20020a170902a41600b0016d4cff269cmr29763623plq.5.1660173385157; Wed, 10 Aug 2022 16:16:25 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:24 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 4/8] client: add developer mode option (-E) Date: Wed, 10 Aug 2022 16:16:17 -0700 Message-Id: <20220810231621.372514-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This puts iwctl into developer mode which allows IWD debug interfaces to be used. --- client/command.c | 26 ++++++++++++++++++-------- client/command.h | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/command.c b/client/command.c index c0576e97..80599620 100644 --- a/client/command.c +++ b/client/command.c @@ -38,6 +38,7 @@ static struct l_queue *command_families; static struct l_queue *command_options; static int exit_status; static bool interactive_mode; +static bool developer_mode; static struct command_noninteractive { char **argv; int argc; @@ -616,6 +617,11 @@ bool command_is_interactive_mode(void) return interactive_mode; } +bool command_is_developer_mode(void) +{ + return developer_mode; +} + void command_set_exit_status(int status) { exit_status = status; @@ -657,6 +663,7 @@ static const struct option command_opts[] = { { COMMAND_OPTION_PASSPHRASE, required_argument, NULL, 'P' }, { COMMAND_OPTION_DONTASK, no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, + { "developer", no_argument, NULL, 'E' }, { } }; @@ -671,17 +678,10 @@ bool command_init(char **argv, int argc) command_families = l_queue_new(); command_options = l_queue_new(); - for (desc = __start___command; desc < __stop___command; desc++) { - if (!desc->init) - continue; - - desc->init(); - } - for (;;) { struct command_option *option; - opt = getopt_long(argc, argv, "u:p:P:dh", command_opts, NULL); + opt = getopt_long(argc, argv, "u:p:P:dhE", command_opts, NULL); switch (opt) { case 'u': @@ -714,6 +714,9 @@ bool command_init(char **argv, int argc) l_queue_push_tail(command_options, option); + break; + case 'E': + developer_mode = true; break; case 'h': command_display_help(); @@ -731,6 +734,13 @@ bool command_init(char **argv, int argc) } options_parsed: + for (desc = __start___command; desc < __stop___command; desc++) { + if (!desc->init) + continue; + + desc->init(); + } + argv += optind; argc -= optind; diff --git a/client/command.h b/client/command.h index 23f23dc9..bdfc7e99 100644 --- a/client/command.h +++ b/client/command.h @@ -69,6 +69,7 @@ void command_process_prompt(char **argv, int argc); void command_noninteractive_trigger(void); bool command_is_interactive_mode(void); +bool command_is_developer_mode(void); int command_get_exit_status(void); void command_set_exit_status(int status); void command_reset_default_entities(void); From patchwork Wed Aug 10 23:16:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941021 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E2BB4A0B for ; Wed, 10 Aug 2022 23:16:26 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id g12so15061437pfb.3 for ; Wed, 10 Aug 2022 16:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=sjbKpslGm3MRx9TOqkKXNo+KYLOWHmHJqO+DfzSrVX0=; b=Ro1uAjefPcQ1Uy7AtagG4oRVMwpcYRGb2ffRs+UQrngXirkO2RqBkQb5muw7xd0GM+ TOFAMtg9LMGMoYdpf3umHVfxVy0iKJBN0RKXFkiF994iJr12g+gu7ZJ2ePbqZwakKDh6 x+G9qpMyuCjVZd8LLI/yJrTWWyKoZnonk7APuKEh+ypnGRi+3ENk+E7G9/cxmITZNEQu BwCFkPdtHriKOHDwVvrIZc5YuKOl5biTiyLIeFwMx6pMBZ1qYrS8XuS2g3iFsOqn1lF7 jNs6UN3jP6BvYVfcyqwWw40k5/lcn146DClIk4F6ijrEyYhed+ELjpmXu0XwRdoeeF9B N/2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=sjbKpslGm3MRx9TOqkKXNo+KYLOWHmHJqO+DfzSrVX0=; b=UQRIh+yWpp+wt5NvckiJhlGeCiUJPqAYdZGuc4OhYyl/FOeOuOHEEFrwDzjDsbLnTo uhqhIKf15CpDwvpFsjyvmD9np2bbf8fKOkjpuWYL3W08NYs+nSiz4+S8WjdLgWMlvUqw j5OceuLWCXiNKLykgaspua9OQNLtJ9NF0iQ79+CZLx/T9CMiamT05+MDF7o3VjX/Lh04 PVMn5QB/7xOb7aj+ubRV7XEmq9liwPMio00YblaTqiD3YPuG9etNMbpKILMVDh8MYvWV kkb1G2nGY81AbWoj+6as5Ekw057jwZvOTQ4haH25PbOUqLnZAGMiHTN2t1mqIaKgWgx+ MnZg== X-Gm-Message-State: ACgBeo3b96L51iMZ7IfZB0fP4e4l10kph4EECNoUaVu6jtmdmnYnS74F wR6OHMVNQo6/39L1lesKy7YDBQEluKc= X-Google-Smtp-Source: AA6agR7g0OL4eg2Dgzlh02DC41TqCjvCnnESSnAXr10WF3t2BsV9rgLMBPx820FzI8pAH9ukMoYxnQ== X-Received: by 2002:a05:6a00:1a44:b0:52a:ecd5:bbef with SMTP id h4-20020a056a001a4400b0052aecd5bbefmr28767611pfv.28.1660173385858; Wed, 10 Aug 2022 16:16:25 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:25 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 5/8] client: allow entity name to be passed to completion Date: Wed, 10 Aug 2022 16:16:18 -0700 Message-Id: <20220810231621.372514-5-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a limitation of libreadline where no context/userdata can be passed to completion functions. This effects iwctl since the entity value isn't known to completion functions. Workarounds such as getting the default device are employed but its not a great solution. Instead hack around this limitation by parsing the prompt to extract the entity (second arg). Then use a generic match function given to readline which can call the actual match function and include the entity. --- client/adapter.c | 3 ++- client/command.c | 39 ++++++++++++++++++++++++++++++++++++++- client/command.h | 9 ++++++--- client/device.c | 3 ++- client/known-networks.c | 3 ++- client/station.c | 6 ++++-- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/client/adapter.c b/client/adapter.c index 394eae0d..1719b970 100644 --- a/client/adapter.c +++ b/client/adapter.c @@ -319,7 +319,8 @@ static enum cmd_status cmd_set_property(const char *adapter_name, return CMD_STATUS_TRIGGERED; } -static char *set_property_cmd_arg_completion(const char *text, int state) +static char *set_property_cmd_arg_completion(const char *text, int state, + const char *phy) { return proxy_property_completion(adapter_properties, text, state); } diff --git a/client/command.c b/client/command.c index 80599620..835c00c5 100644 --- a/client/command.c +++ b/client/command.c @@ -214,20 +214,57 @@ bool command_line_find_token(const char *token, uint8_t num_to_inspect) return false; } +/* + * Work around readline limitations of not being able to pass a context pointer + * to match functions. Set the command match function/entity to these globals + * and call a generic match function which can call the _real_ match function + * and include the entity. + */ +static command_completion_func_t cmd_current_completion_func = NULL; +static const char *cmd_current_entity = NULL; + +static char *cmd_completion_generic(const char *text, int state) +{ + return cmd_current_completion_func(text, state, cmd_current_entity); +} + static char **cmd_completion_match_entity_cmd(const char *cmd, const char *text, const struct command *cmd_list) { char **matches = NULL; size_t i; + char *family = NULL; + char *entity = NULL; + char *prompt = NULL; for (i = 0; cmd_list[i].cmd; i++) { + char *tmp; + if (strcmp(cmd_list[i].cmd, cmd)) continue; if (!cmd_list[i].completion) break; - matches = rl_completion_matches(text, cmd_list[i].completion); + if (cmd_list[i].entity) { + prompt = rl_copy_text(0, rl_end); + + family = strtok_r(prompt, " ", &tmp); + if (!family) + goto done; + + entity = strtok_r(NULL, " ", &tmp); + } + +done: + cmd_current_completion_func = cmd_list[i].completion; + cmd_current_entity = entity; + + matches = rl_completion_matches(text, cmd_completion_generic); + + l_free(prompt); + cmd_current_completion_func = NULL; + cmd_current_entity = NULL; break; } diff --git a/client/command.h b/client/command.h index bdfc7e99..70a54e7e 100644 --- a/client/command.h +++ b/client/command.h @@ -25,7 +25,10 @@ #define COMMAND_OPTION_PASSPHRASE "passphrase" #define COMMAND_OPTION_DONTASK "dont-ask" -typedef char *(*command_completion_func_t) (const char *text, int state); +typedef char *(*command_completion_func_t)(const char *text, int state, + const char *entity); +typedef char *(*command_rl_completion_func_t)(const char *text, int state); + enum cmd_status { CMD_STATUS_TRIGGERED, @@ -51,8 +54,8 @@ struct command_family { const char *caption; const char *name; const struct command *command_list; - command_completion_func_t family_arg_completion; - command_completion_func_t entity_arg_completion; + command_rl_completion_func_t family_arg_completion; + command_rl_completion_func_t entity_arg_completion; void (*set_default_entity)(const char *entity); void (*reset_default_entity)(void); }; diff --git a/client/device.c b/client/device.c index 9f8d731c..8b27ddd2 100644 --- a/client/device.c +++ b/client/device.c @@ -398,7 +398,8 @@ static enum cmd_status cmd_set_property(const char *device_name, return CMD_STATUS_TRIGGERED; } -static char *set_property_cmd_arg_completion(const char *text, int state) +static char *set_property_cmd_arg_completion(const char *text, int state, + const char *device_name) { return proxy_property_completion(device_properties, text, state); } diff --git a/client/known-networks.c b/client/known-networks.c index 56c34a2e..b2023e35 100644 --- a/client/known-networks.c +++ b/client/known-networks.c @@ -387,7 +387,8 @@ static enum cmd_status cmd_set_property(const char *network_name, return CMD_STATUS_TRIGGERED; } -static char *set_property_cmd_arg_completion(const char *text, int state) +static char *set_property_cmd_arg_completion(const char *text, int state, + const char *network_name) { return proxy_property_completion(known_network_properties, text, state); } diff --git a/client/station.c b/client/station.c index 64becdbd..90291c88 100644 --- a/client/station.c +++ b/client/station.c @@ -277,7 +277,8 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) return CMD_STATUS_DONE; } -static char *connect_cmd_arg_completion(const char *text, int state) +static char *connect_cmd_arg_completion(const char *text, int state, + const char *device_name) { const struct proxy_interface *device = device_get_default(); @@ -489,7 +490,8 @@ static void ordered_networks_callback(struct l_dbus_message *message, l_queue_destroy(networks, ordered_networks_destroy); } -static char *get_networks_cmd_arg_completion(const char *text, int state) +static char *get_networks_cmd_arg_completion(const char *text, int state, + const char *device_name) { static int index; static int len; From patchwork Wed Aug 10 23:16:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941022 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CDE44A02 for ; Wed, 10 Aug 2022 23:16:27 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id 13so14113557plo.12 for ; Wed, 10 Aug 2022 16:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=h8rZW2gOtN49OqCge9lG30TpdQHxK7Xm2nwcx1D/OXA=; b=HG43XXOgVsbUqTNWb2qkX5y75RKdwxFCjbrh3HS/YNwF/TQok0AxM5xu4RjqVnPIPO e0pFiVtergypeGAKRpxPoRTxK0SYT6e9RdnNsOcb4vwAaCflaICxBO5oL4UznJvOl/hu lT4gdHPpkZ3qqdrd24qOUKTiahztY5VabIVplnn45yGZum74r3Tt+erADz1qX3RC3NOv IzrNF7DITy1VmHWF5UVijzQ1EQMwzQN0H9l9o7pUAbrVuXhcvlbAdvW7xlXK+y14cTSX qnhlZyTV0uhhEhpolPJuRAnUQMrLc/oZWGRoe4hCutwBZKw6F9C/pDgm/ZBXztRVQx7f pyaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=h8rZW2gOtN49OqCge9lG30TpdQHxK7Xm2nwcx1D/OXA=; b=KdtEpNzXwYKeYuwj/moxAtGtxt50do4OiOl2bjrdAfOHbak5X8W+dwUlOhN+5bOK6S 2fipqVlzl/rPCDtDunr0bcJUKGCcw4HOhtj87mRILvvnh7NAT2wxPjH4dUjW17t9QTtM 3ZSyqAKS4w11S74Hs/ogfPKpmlIipA7oNYRlDMT38ccDyVue3U0SoeUtYsFfFZKtt7xF /HOiAstf+Swm6VZJKYT2BOMe/1CWGFuL095eF++Zc6oSdconWANczJy48lPx+x1KLQBX Qa9rDMcpoN3wwwDBw8lkUQYv0UTOJqWJU13OVlKVp5mCkqpkaEr8KtMTLEPDxppnWLHP elMA== X-Gm-Message-State: ACgBeo0dN6ypMw8kViFPVUuh6yPjdeDQgbXQfThIK24lcXgdDX2qIa8d HP1fEYfUeA7gXeqGhYgx7oYrVU0NiZk= X-Google-Smtp-Source: AA6agR4RMP739TS+pS1IkgI64Xjpd9p1YwZWbGQXcpMPzQ3WWAslGJBdDbXoKBQPecuyzU+3C4yz6Q== X-Received: by 2002:a17:902:b214:b0:171:2e1f:6d1a with SMTP id t20-20020a170902b21400b001712e1f6d1amr6888899plr.147.1660173386548; Wed, 10 Aug 2022 16:16:26 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:26 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 6/8] client: add STATION_DEBUG_INTERFACE definition Date: Wed, 10 Aug 2022 16:16:19 -0700 Message-Id: <20220810231621.372514-6-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- client/dbus-proxy.h | 1 + 1 file changed, 1 insertion(+) diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h index 34917e82..0b4fec43 100644 --- a/client/dbus-proxy.h +++ b/client/dbus-proxy.h @@ -34,6 +34,7 @@ struct proxy_interface; #define IWD_WSC_INTERFACE "net.connman.iwd.SimpleConfiguration" #define IWD_STATION_INTERFACE "net.connman.iwd.Station" #define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic" +#define IWD_STATION_DEBUG_INTERFACE "net.connman.iwd.StationDebug" #define IWD_AP_DIAGNOSTIC_INTERFACE "net.connman.iwd.AccessPointDiagnostic" #define IWD_DAEMON_INTERFACE "net.connman.iwd.Daemon" #define IWD_DPP_INTERFACE "net.connman.iwd.DeviceProvisioning" From patchwork Wed Aug 10 23:16:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941023 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAD1F4A0B for ; Wed, 10 Aug 2022 23:16:27 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id l64so15709090pge.0 for ; Wed, 10 Aug 2022 16:16:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=nrMrHXj+Q3ApX7vId0w8i47zqx22NefJojzfDCg8v3s=; b=k4HBrlZwgjLKClEh3XlMNQ4MqtMQL0TMLix2tefvDU80nAjon4OglQbtgEhMxsGbye PafF2zockPMx+yadbQ9272gWuKIpnIi4nkazUSlxFw+8BFh2lHqMAyx1NYYINPQXNcww 01wNwt0xZuBLFfLrAG5868BGGE9tQr4o7C4PoVSdEKgi9IjJwpzrr8jDqX1RIl9wGaoQ XZy4wPXW54YbvU+765KOn/dSM8bjONHiAOz9MuHHALI7tTxHh1QSNo1zMEv3k7UOVLEl QDvcamoUrySTU7nOV+yRJ1Rza6YReCJ6DQEDoZVhErYY6/mMXn+Bxt3F0+inqqnFjFyO CuHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=nrMrHXj+Q3ApX7vId0w8i47zqx22NefJojzfDCg8v3s=; b=nVQxj7MmSIu9UTHF4r/YTF5mW5tQdK750Gfi14V4TbddW4dSvQrJPIgtKvKU+1XBca 4/yDLb/SgY23UD1xm9vrZgeWLLg2nXzaGii28Kz1getBvBy/wPesRiylUr3MYYMd0CoU fKgbs5IgAlh8awXoIZc1K0RBBYSPRPkeT4hapmaSHVK5oj5NHLPSMUtx1LK4T87jyWgx 4o3+X8EcAm4uxraO3jnvo5AK+hEKu5CWwA/GruQw3/oHhuwu7ISQDg1UFKEs2UjP+Rne aDfOD9SB83TqodFOZxhE92hPCoENjiptVAsqT5K+JmqIEeLUhrW3MYGcOBu90sumF1pC 7hOg== X-Gm-Message-State: ACgBeo1W5Lafb+g2FUj+4gYru0+EFXK65ts+keqQgZfRhhUXcCCJQO1b Bb5Ltwkq+LWOzNHpSKigKNRfCxDtZl8= X-Google-Smtp-Source: AA6agR65uFC7BYAjgZe5CGQl61iWnnO2VChfC6zuc4ujWBVio1CxD3w19eFcceyQyZKSkDUZofbl9w== X-Received: by 2002:a62:6545:0:b0:52b:6daa:1540 with SMTP id z66-20020a626545000000b0052b6daa1540mr29074479pfb.29.1660173387156; Wed, 10 Aug 2022 16:16:27 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:26 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 7/8] client: add station-debug command interface Date: Wed, 10 Aug 2022 16:16:20 -0700 Message-Id: <20220810231621.372514-7-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This lets iwctl call methods on .StationDebug. The command name is called 'debug'. This can only be used when both iwctl and IWD are in developer mode (-E) --- Makefile.am | 4 +- client/station-debug.c | 417 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 client/station-debug.c diff --git a/Makefile.am b/Makefile.am index cffb0738..ed93d000 100644 --- a/Makefile.am +++ b/Makefile.am @@ -301,7 +301,9 @@ client_iwctl_SOURCES = client/main.c \ client/wsc.c client/station.c \ client/diagnostic.c client/diagnostic.h \ client/daemon.c client/daemon.h \ - client/dpp.c + client/dpp.c client/station-debug.c \ + src/util.c src/util.h \ + src/band.c src/band.h client_iwctl_LDADD = $(ell_ldadd) $(READLINE_LIBS) diff --git a/client/station-debug.c b/client/station-debug.c new file mode 100644 index 00000000..9e1d8756 --- /dev/null +++ b/client/station-debug.c @@ -0,0 +1,417 @@ +#include +#include "ell/useful.h" + +#include "client/command.h" +#include "client/dbus-proxy.h" +#include "client/device.h" +#include "client/display.h" +#include "client/properties.h" +#include "src/util.h" + +struct station_debug { + struct l_queue *network_list; + bool autoconnect; +}; + +struct network { + char *ssid; + struct l_queue *bss_list; +}; + +struct bss { + uint8_t addr[6]; + uint32_t frequency; + int8_t rssi; + int32_t rank; + uint8_t mde[3]; +}; + +static void network_free(void *data) +{ + struct network *network = data; + + l_queue_destroy(network->bss_list, l_free); +} + +static void *station_debug_create(void) +{ + struct station_debug *debug = l_new(struct station_debug, 1); + + debug->network_list = l_queue_new(); + + return debug; +} + +static void station_debug_destroy(void *data) +{ + struct station_debug *debug = data; + + l_queue_destroy(debug->network_list, network_free); + + l_free(debug); +} + +static void check_errors_method_callback(struct l_dbus_message *message, + void *user_data) +{ + dbus_message_has_error(message); +} + +static enum cmd_status cmd_debug_connect(const char *device_name, + char **argv, int argc) +{ + + const struct proxy_interface *debug_i; + uint8_t addr[6]; + + if (argc < 1) + return CMD_STATUS_INVALID_ARGS; + + debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE); + if (!debug_i) + return CMD_STATUS_INVALID_VALUE; + + if (!util_string_to_address(argv[0], addr)) + return CMD_STATUS_INVALID_ARGS; + + proxy_interface_method_call(debug_i, "ConnectBssid", "ay", + check_errors_method_callback, 6, + addr[0], addr[1], addr[2], + addr[3], addr[4], addr[5]); + return CMD_STATUS_TRIGGERED; +} + +static enum cmd_status cmd_debug_roam(const char *device_name, + char **argv, int argc) +{ + const struct proxy_interface *debug_i; + uint8_t addr[6]; + + if (argc < 1) + return CMD_STATUS_INVALID_ARGS; + + debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE); + if (!debug_i) + return CMD_STATUS_INVALID_VALUE; + + if (!util_string_to_address(argv[0], addr)) + return CMD_STATUS_INVALID_ARGS; + + proxy_interface_method_call(debug_i, "Roam", "ay", + check_errors_method_callback, 6, + addr[0], addr[1], addr[2], + addr[3], addr[4], addr[5]); + return CMD_STATUS_TRIGGERED; +} + +static void get_byte_array(struct l_dbus_message_iter *variant, uint8_t *out, + unsigned int len) +{ + struct l_dbus_message_iter array; + uint32_t elems = 6; + uint8_t *a; + + if (!l_dbus_message_iter_get_variant(variant, "ay", &array)) + goto error; + + if (!l_dbus_message_iter_get_fixed_array(&array, &a, &elems)) + goto error; + + if (elems != len) + goto error; + + memcpy(out, a, len); + + return; + +error: + display_error("Invalid Address element"); +} + +static uint32_t get_u32(struct l_dbus_message_iter *variant) +{ + uint32_t u32 = 0; + + if (!l_dbus_message_iter_get_variant(variant, "u", &u32)) + display_error("Invalid Frequency element"); + + return u32; +} + +static uint32_t get_i32(struct l_dbus_message_iter *variant) +{ + int32_t i32 = 0; + + if (!l_dbus_message_iter_get_variant(variant, "i", &i32)) + display_error("Invalid Frequency element"); + + return i32; +} + +static void display_bss(struct bss *bss) +{ + char row[128]; + + sprintf(row, "%s%-*s "MAC" %-*i %-*u %-*i %02x%02x%02x", + MARGIN MARGIN, 4, "", MAC_STR(bss->addr), 4, bss->rssi, + 6, bss->frequency, 8, bss->rank, + bss->mde[0], bss->mde[1], bss->mde[2]); + + display("%s\n", row); + + return; +} + +static void get_networks_method_callback(struct l_dbus_message *message, + void *user_data) +{ + struct proxy_interface *debug_i = user_data; + struct station_debug *debug = proxy_interface_get_data(debug_i); + struct l_dbus_message_iter iter; + struct l_dbus_message_iter variant; + struct l_dbus_message_iter array; + struct l_dbus_message_iter dict; + const char *key; + + if (dbus_message_has_error(message)) + return; + + if (!l_dbus_message_get_arguments(message, "a{sv}", &iter)) { + l_error("Failed to parse GetDiagnostics message"); + return; + } + + display_table_header("Available Networks (debug)", + "%s%-*s %-*s %-*s %-*s %-*s %-*s %-*s", + "", 2, "", 4, "SSID", 17, "BSSID", 4, "RSSI", + 6, "Freq", 8, "Rank", 10, "MDE"); + + while (l_dbus_message_iter_next_entry(&iter, &key, &variant)) { + struct network *network = l_new(struct network, 1); + + network->ssid = l_strdup(key); + network->bss_list = l_queue_new(); + + if (!strcmp(network->ssid, "")) + display_table_row(MARGIN MARGIN, 3, 32, "Hidden BSS's", + 18, "", 6, ""); + else + display_table_row(MARGIN MARGIN, 3, 32, network->ssid, + 18, "", 6, ""); + + l_dbus_message_iter_get_variant(&variant, "aa{sv}", &array); + + while (l_dbus_message_iter_next_entry(&array, &dict)) { + struct bss *bss = l_new(struct bss, 1); + + while (l_dbus_message_iter_next_entry(&dict, &key, + &variant)) { + if (!strcmp(key, "Address")) + get_byte_array(&variant, bss->addr, 6); + else if (!strcmp(key, "Frequency")) + bss->frequency = get_u32(&variant); + else if (!strcmp(key, "RSSI")) + bss->rssi = get_i32(&variant); + else if (!strcmp(key, "Rank")) + bss->rank = get_i32(&variant); + else if (!strcmp(key, "MDE")) + get_byte_array(&variant, bss->mde, 3); + } + + display_bss(bss); + + l_queue_push_tail(network->bss_list, bss); + } + + l_queue_push_tail(debug->network_list, network); + } + + display_table_footer(); +} + +static enum cmd_status cmd_debug_get_networks(const char *device_name, + char **argv, int argc) +{ + const struct proxy_interface *debug_i; + + debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE); + if (!debug_i) + return CMD_STATUS_INVALID_VALUE; + + proxy_interface_method_call(debug_i, "GetNetworks", "", + get_networks_method_callback); + + return CMD_STATUS_TRIGGERED; +} + +static char *connect_debug_cmd_arg_completion(const char *text, int state, + const char *device_name) +{ + const struct proxy_interface *debug_i; + struct station_debug *debug; + static const struct l_queue_entry *n_entry; + static const struct l_queue_entry *b_entry; + size_t len = strlen(text); + + debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE); + if (!debug_i) + return NULL; + + debug = proxy_interface_get_data(debug_i); + + if (!state) + n_entry = l_queue_get_entries(debug->network_list); + + while (n_entry) { + struct network *network = n_entry->data; + + n_entry = n_entry->next; + + if (!b_entry) + b_entry = l_queue_get_entries(network->bss_list); + + while (b_entry) { + struct bss *bss = b_entry->data; + char addr_str[18]; + + b_entry = b_entry->next; + + sprintf(addr_str, MAC, MAC_STR(bss->addr)); + + if (len > strlen(addr_str)) + return NULL; + + if (strncmp(text, addr_str, len)) + continue; + + return l_strdup_printf(MAC, MAC_STR(bss->addr)); + } + } + + return NULL; +} + +static const char *get_autoconnect_tostr(const void *data) +{ + const struct station_debug *debug = data; + + return debug->autoconnect ? "on" : "off"; +} + +static void update_autoconnect(void *data, struct l_dbus_message_iter *variant) +{ + struct station_debug *debug = data; + bool value; + + if (!l_dbus_message_iter_get_variant(variant, "b", &value)) { + debug->autoconnect = false; + + return; + } + + debug->autoconnect = value; +} + +static const struct proxy_interface_property debug_properties[] = { + { "AutoConnect", "b", update_autoconnect, get_autoconnect_tostr, true, + properties_builder_append_on_off_variant, + properties_on_off_opts }, + { } +}; + +static enum cmd_status cmd_debug_set_autoconnect(const char *device_name, + char **argv, int argc) +{ + const struct proxy_interface *proxy = device_proxy_find(device_name, + IWD_STATION_DEBUG_INTERFACE); + + if (!proxy) + return CMD_STATUS_INVALID_VALUE; + + if (argc != 1) + return CMD_STATUS_INVALID_ARGS; + + if (!proxy_property_set(proxy, "AutoConnect", argv[0], + check_errors_method_callback)) + return CMD_STATUS_INVALID_VALUE; + + return CMD_STATUS_TRIGGERED; +} + +static const struct command station_debug_commands[] = { + { "", "connect", "", cmd_debug_connect, + "Connect to a specific BSS", false, + connect_debug_cmd_arg_completion }, + { "", "roam", "", cmd_debug_roam, + "Roam to a BSS", false }, + { "", "get-networks", NULL, cmd_debug_get_networks, + "Get networks", true }, + { "", "autoconnect", "on|off", cmd_debug_set_autoconnect, + "Set AutoConnect property", false }, + { } +}; + +static char *family_debug_arg_completion(const char *text, int state) +{ + return device_arg_completion(text, state, station_debug_commands, + IWD_STATION_DEBUG_INTERFACE); +} + +static char *entity_debug_arg_completion(const char *text, int state) +{ + return command_entity_arg_completion(text, state, + station_debug_commands); +} + +static struct command_family station_debug_command_family = { + .caption = "Station Debug", + .name = "debug", + .command_list = station_debug_commands, + .family_arg_completion = family_debug_arg_completion, + .entity_arg_completion = entity_debug_arg_completion, +}; + +static int station_debug_command_family_init(void) +{ + if (command_is_developer_mode()) + command_family_register(&station_debug_command_family); + + return 0; +} + +static void station_debug_command_family_exit(void) +{ + if (command_is_developer_mode()) + command_family_unregister(&station_debug_command_family); +} + +COMMAND_FAMILY(station_debug_command_family, station_debug_command_family_init, + station_debug_command_family_exit) + +static const struct proxy_interface_type_ops station_debug_ops = { + .create = station_debug_create, + .destroy = station_debug_destroy, +}; + +static struct proxy_interface_type station_debug_interface_type = { + .interface = IWD_STATION_DEBUG_INTERFACE, + .ops = &station_debug_ops, + .properties = debug_properties, +}; + +static int station_debug_interface_init(void) +{ + if (command_is_developer_mode()) + proxy_interface_type_register(&station_debug_interface_type); + + return 0; +} + +static void station_debug_interface_exit(void) +{ + if (command_is_developer_mode()) + proxy_interface_type_unregister(&station_debug_interface_type); +} + +INTERFACE_TYPE(station_debug_interface_type, station_debug_interface_init, + station_debug_interface_exit) From patchwork Wed Aug 10 23:16:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 12941024 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A68574A02 for ; Wed, 10 Aug 2022 23:16:28 +0000 (UTC) Received: by mail-pj1-f47.google.com with SMTP id pm17so16178409pjb.3 for ; Wed, 10 Aug 2022 16:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=JmingVSDa6aIkhua9EWpczKHECzAoIMQ6GHEYWePYuA=; b=GBbsQl3w7btnER6s1nc/mPn/qzQCSciBCw2ff5xPJsiOKWwZQik7vTms48fFjoUEQ1 JkKM0uoy5dxS+NyFWt1A7gmjIwg6tmQAKBxZuLku0+sgxDW0ve1eaW7b23wo9SVIE6+3 JE9srU1uXK1zJdUjEKzmGpRER3LTQKgxbQwjlwjgN/efPF7mn2thVE6J/bty4mdKuKzV or7k6NwD8w2k8nwkfC+N9oN4wQ0NQOIgMSHf2BNbjcXBwB4Xbs2T1C2OuSDKx98MH137 kuzwdktFGJQ4OyrwZg70KvxLgA/uZ55ARvi0N8ommLz3dwRHp+FzxMw9jsRSjGBcrZn8 rFkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=JmingVSDa6aIkhua9EWpczKHECzAoIMQ6GHEYWePYuA=; b=pYcDcyRlOVA2yZIbIGBAgDXHzY0ZFXQteL3UmMCsVrDoqpl/RpNvONbr78D6ePNkMf fA9fSxUtvhHd0VISh3KzGPPtWzYYpthvdfG3gWHPqwojotoOVWrWy7NjHgFMrAs8qOfX v3+rbLsdygToLb8LQweDl9fq9qs6Mfo/Xyqphwn58Fq24Mxavbf4f0V1nGrBpOOWHUit 4Xf+2NwQX1FbYVjeqPqpWZbSIlXo9Zwx0WababQEll3MMofqAKiJs3cd5GVzlFltlDnt Gf0m6LmU0UkVjZ8KSvXoRJQJaQ/ns/1X4dEn6N4C69mVb8Ge6eiWm2J/WLZxvW8BaNDl 0EDg== X-Gm-Message-State: ACgBeo3YvW7Z9N4lsgFW/FPq1bHMBOv2D596gI+qGKYamhtj1+zuL6og WGKUzibG0qSqBL4iw+H5OeNtfjiLNMs= X-Google-Smtp-Source: AA6agR7AKMsfudEWXk+skqTgBbvzdmidnwVh3JMPKwLH6iiuXJ/N2sXTJS7nIu8B5mibO6kJqEne4w== X-Received: by 2002:a17:90b:1d02:b0:1f5:8526:303 with SMTP id on2-20020a17090b1d0200b001f585260303mr5961917pjb.79.1660173388059; Wed, 10 Aug 2022 16:16:28 -0700 (PDT) Received: from jprestwo-xps.none ([50.39.168.145]) by smtp.gmail.com with ESMTPSA id t7-20020a170902e84700b0016d62ba5665sm13540246plg.254.2022.08.10.16.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 16:16:27 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH 8/8] client: fix station autocomplete with multiple phys Date: Wed, 10 Aug 2022 16:16:21 -0700 Message-Id: <20220810231621.372514-8-prestwoj@gmail.com> X-Mailer: git-send-email 2.34.3 In-Reply-To: <20220810231621.372514-1-prestwoj@gmail.com> References: <20220810231621.372514-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The limitations of readline required that the autocompletion choose a 'default' device. With multiple phys this doesn't work. Now the readline limitation has been worked around and station can look up the device for the command completion. --- client/station.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/station.c b/client/station.c index 90291c88..b070807b 100644 --- a/client/station.c +++ b/client/station.c @@ -280,7 +280,8 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc) static char *connect_cmd_arg_completion(const char *text, int state, const char *device_name) { - const struct proxy_interface *device = device_get_default(); + const struct proxy_interface *device = device_proxy_find(device_name, + IWD_STATION_INTERFACE); if (!device) return NULL;