From patchwork Fri Jan 6 11:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091279 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C5C8C5479D for ; Fri, 6 Jan 2023 11:18:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233150AbjAFLSq (ORCPT ); Fri, 6 Jan 2023 06:18:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233136AbjAFLSl (ORCPT ); Fri, 6 Jan 2023 06:18:41 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [IPv6:2001:4b98:dc4:8::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF9D7625DF for ; Fri, 6 Jan 2023 03:18:38 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id D3724240014; Fri, 6 Jan 2023 11:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/2VGcVxYVS1JEm5/Fm6gwZL3KFWld/QNwfbHBHWWzzo=; b=Kl0ii14kt1IbPJrL3Vl3xYSm8mgDRPvLWbMsqY4PpVwU6GmroGAuidQythqzMCTPlkAZqB ePuqdtf6NxES33x9dBOCxxKtrUhQtoDDJRum9E0HdwPne7KeZCLJTA6nAqfJcm/mMKFxTl iVViDpdqXoumVmuUqPy+EphKik6O1qSnVfOu3K0wrzKCvUHmoNwH3FdflcDUT77uq5Ixpk sTdJfKjglboeRn+jsRFVO0HdfE+nCLay+w8jBgUPTPPVR+/WJNNI/USNmbu/4z1ZUqvSiK n6bY2eJnkuLz1SnAY+8VJL3rNCabqm7bfgMy9ZWJ6Oy+8IBGzb3jVDc6ad/xHg== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 1/8] iwpan: Synchronize nl802154.h with the latest kernel Date: Fri, 6 Jan 2023 12:18:24 +0100 Message-Id: <20230106111831.692202-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org The low-level security commands are now listed inconditionnally, so let's reflect this change in the header so that the addition of further commands is made at the right location. Signed-off-by: Miquel Raynal --- src/nl802154.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nl802154.h b/src/nl802154.h index ddcee12..eb8ad48 100644 --- a/src/nl802154.h +++ b/src/nl802154.h @@ -56,9 +56,6 @@ enum nl802154_commands { NL802154_CMD_SET_WPAN_PHY_NETNS, - /* add new commands above here */ - -#ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL NL802154_CMD_SET_SEC_PARAMS, NL802154_CMD_GET_SEC_KEY, /* can dump */ NL802154_CMD_NEW_SEC_KEY, @@ -72,7 +69,8 @@ enum nl802154_commands { NL802154_CMD_GET_SEC_LEVEL, /* can dump */ NL802154_CMD_NEW_SEC_LEVEL, NL802154_CMD_DEL_SEC_LEVEL, -#endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */ + + /* add new commands above here */ /* used to define NL802154_CMD_MAX below */ __NL802154_CMD_AFTER_LAST, From patchwork Fri Jan 6 11:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091280 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FE6BC3DA7A for ; Fri, 6 Jan 2023 11:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233136AbjAFLSq (ORCPT ); Fri, 6 Jan 2023 06:18:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233167AbjAFLSm (ORCPT ); Fri, 6 Jan 2023 06:18:42 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [IPv6:2001:4b98:dc4:8::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C405625F5 for ; Fri, 6 Jan 2023 03:18:40 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 989DC240005; Fri, 6 Jan 2023 11:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SC+efU5PqAwVLFuiqQsRReY/dRs97fikxOlstcwAtdM=; b=Uy8IuXigPpLxV9AENRcog6XHdXK+2kbiGfw94jaUy4fcCapXJ5CHsXtvu8dITujZ1YYs/R c23MEFLlSb8y9jD6krdSoRhbyzJgffkIeMBb+jjuK0YMi6Gxfm8HkwnI9Ab45UHxPDViXW Sa0qaeVJap6zG/aHqFhbluT1/Pp1sD4YzTzds5sXvE/u+M4tLpPUEAl9Gp3LefnX51enXD vgYW2fV9ed3BrVDtdrjMa9Ai9QXGFRNYSC025mVCbpcx0eapZORyD5tRy0nNybmkkFtbnh EppC0D/mCNyFPkpCgMG4Wou94axPMoWyzUsjkp7WVAZLVqFIehGt7d6Hd+i9Uw== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Romuald Despres , Miquel Raynal Subject: [PATCH wpan-tools v2 2/8] iwpan: Fix the channels printing Date: Fri, 6 Jan 2023 12:18:25 +0100 Message-Id: <20230106111831.692202-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: Romuald Despres The presence of a channel capability is checked against the tb_msg netlink attributes array which is the root one, while here we are looking for channel capabilities, themselves being nested and parsed into tb_caps. Use tb_caps instead of tb_msg here otherwise we are accessing a random index in the upper attributes list. Signed-off-by: Romuald Despres Signed-off-by: Miquel Raynal --- src/info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/info.c b/src/info.c index f85690c..8ed5e4f 100644 --- a/src/info.c +++ b/src/info.c @@ -342,7 +342,7 @@ static int print_phy_handler(struct nl_msg *msg, void *arg) printf("\b \n"); } - if (tb_msg[NL802154_CAP_ATTR_CHANNELS]) { + if (tb_caps[NL802154_CAP_ATTR_CHANNELS]) { int counter = 0; int rem_pages; struct nlattr *nl_pages; From patchwork Fri Jan 6 11:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091283 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F0EEC54EBC for ; Fri, 6 Jan 2023 11:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229746AbjAFLSw (ORCPT ); Fri, 6 Jan 2023 06:18:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233197AbjAFLSs (ORCPT ); Fri, 6 Jan 2023 06:18:48 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [IPv6:2001:4b98:dc4:8::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D641C625F5 for ; Fri, 6 Jan 2023 03:18:41 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id EC4F024000A; Fri, 6 Jan 2023 11:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i3NuLMYQGegEDlsYXHWQTxM+kmTZB4g8rjBeozny6tE=; b=OJaEMt/kVgehjuKxONUiPNGkJLG6jjjmajBnycqWMcA2c60WKJV1q7HOajYvOCdGC8pUtK KWpW8bz2lQA/Fb/56L72WYkQ7seNRkqMO4Q8Hw2XWjMWhBCGazvklapc1fs0wlIAUvhbSQ 1F/gD7ZLd35rZw0+vRL2hOrrnDPAuiYBzFVw8qTTa1L0WThQ2QCtLk9QI3VGxjwvRGAiqq eBK0GC0Vfxyiq7XURpshccRYaH0I200siQXqg+Hhmx3VtYCArRHHufIFoZTPi+PxxQJCqb OmjQtuqc570GAk9axthhtt1vw8Y4lwOJXmWd+clu1fhPC8hYYW0xqtR6FbjT9A== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 3/8] iwpan: Export iwpan_debug Date: Fri, 6 Jan 2023 12:18:26 +0100 Message-Id: <20230106111831.692202-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: David Girault This debug flag will be used later on in different files. Signed-off-by: David Girault Signed-off-by: Miquel Raynal --- src/iwpan.c | 2 +- src/iwpan.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/iwpan.c b/src/iwpan.c index fb7bef1..3cf5fe2 100644 --- a/src/iwpan.c +++ b/src/iwpan.c @@ -21,7 +21,7 @@ /* TODO libnl 1.x compatibility code */ -static int iwpan_debug = 0; +int iwpan_debug = 0; static int nl802154_init(struct nl802154_state *state) { diff --git a/src/iwpan.h b/src/iwpan.h index 48c4f03..860dd37 100644 --- a/src/iwpan.h +++ b/src/iwpan.h @@ -120,4 +120,6 @@ DECLARE_SECTION(get); const char *iftype_name(enum nl802154_iftype iftype); +extern int iwpan_debug; + #endif /* __IWPAN_H */ From patchwork Fri Jan 6 11:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091281 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A45CC3DA7A for ; Fri, 6 Jan 2023 11:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233167AbjAFLSv (ORCPT ); Fri, 6 Jan 2023 06:18:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233204AbjAFLSs (ORCPT ); Fri, 6 Jan 2023 06:18:48 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D645D63187 for ; Fri, 6 Jan 2023 03:18:42 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4F416240012; Fri, 6 Jan 2023 11:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003921; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7DYGlaVj+dX75xjeCSEzO2H48Gb9JrtGwznnKQcBMSY=; b=Db+T7LspvUQVJ2DPqt9H/IgSG55GX7XRlgr8KJJBI+ywQj/plNHfX+fgnbHLVY0fVPr7lX aIBzEcF0fsiKNBTMf3z6FJUMo66dj41F743EKyu7LViT7bxi7vf3Rj07/7MPJuxWvvvpHL g679j9e3AFeCap5DXZGOHINDdM/ws4Gc2VKmfu4+fhwM1OWJ0xpKBHj2qHHmn4LmULG4Wt V2BoCqW7lP8zj9Ow75viSONXV1jI+TkvHXDC1O7owXjCsjBrsXZ2MH5EBlNUeRYOpMsXh6 vX3F2ytjwoqC9nxq18zQO3bzbq/cZqm4S5OvFS7Slty2cv6DqYvRelKoSlgBUQ== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 4/8] iwpan: Fix a comment Date: Fri, 6 Jan 2023 12:18:27 +0100 Message-Id: <20230106111831.692202-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org There are a couple of words missing, add them to clarify the comment. Signed-off-by: Miquel Raynal --- src/iwpan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iwpan.h b/src/iwpan.h index 860dd37..9d265c6 100644 --- a/src/iwpan.h +++ b/src/iwpan.h @@ -43,7 +43,7 @@ struct cmd { const enum command_identify_by idby; /* The handler should return a negative error code, * zero on success, 1 if the arguments were wrong - * and the usage message should and 2 otherwise. + * and the usage message should be displayed, 2 otherwise. */ int (*handler)(struct nl802154_state *state, struct nl_cb *cb, From patchwork Fri Jan 6 11:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091282 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35E9FC4708D for ; Fri, 6 Jan 2023 11:18:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233204AbjAFLSv (ORCPT ); Fri, 6 Jan 2023 06:18:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233219AbjAFLSs (ORCPT ); Fri, 6 Jan 2023 06:18:48 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50FCF63188 for ; Fri, 6 Jan 2023 03:18:45 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 95A65240013; Fri, 6 Jan 2023 11:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lEaI1Ym2paejQwXNvmzOV2cHFz6vGMqUYVMWC/hHsjg=; b=f1ARLXkhHcZliFUB9X0rSf5xEMzSHsOgzNFiqCjoMAkm64eIbeBdrNIB2n05e9uSyGuArw +sSCwiqPxVkR1lMhMJ8vSWqn1jGr57/ZB6BUFwchaNFR9XUSvtsw3DGe7RWwrQq0pz28hJ QWxtIpF/NVyICPQuAaOjxcYkYh4v3bSz9wcxc5rr398derPs+9Y37uEhXXoO6KMiTyd/sy +Q48GRkiWgVdxzZZZWU79LmXR4pNfLasWQE05rr2rRjJ/i7Wu678T7y0xhoSRYzFMH1kRU 7NwUK0OkPMhq6208yeb/xDXeBkZLc6g9qyaBkoaGXKVmMlcdkvZ+j/9HbpWOeA== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 5/8] iwpan: Remove duplicated SECTION Date: Fri, 6 Jan 2023 12:18:28 +0100 Message-Id: <20230106111831.692202-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: David Girault This section has been duplicated, drop one. Signed-off-by: David Girault Signed-off-by: Miquel Raynal --- src/iwpan.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/iwpan.h b/src/iwpan.h index 9d265c6..406940a 100644 --- a/src/iwpan.h +++ b/src/iwpan.h @@ -90,12 +90,6 @@ struct cmd { .handler = (_handler), \ .help = (_help), \ } -#define SECTION(_name) \ - struct cmd __section ## _ ## _name \ - __attribute__((used)) __attribute__((section("__cmd"))) = { \ - .name = (#_name), \ - .hidden = 1, \ - } #define SECTION(_name) \ struct cmd __section ## _ ## _name \ From patchwork Fri Jan 6 11:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091284 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C358C5479D for ; Fri, 6 Jan 2023 11:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233197AbjAFLSx (ORCPT ); Fri, 6 Jan 2023 06:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233252AbjAFLSt (ORCPT ); Fri, 6 Jan 2023 06:18:49 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3D3E65AC5 for ; Fri, 6 Jan 2023 03:18:46 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 4D353240009; Fri, 6 Jan 2023 11:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003925; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pkCgC2+vIP/TIDZlwCYhjc5qyOT835idDBUgPb0RERI=; b=lqbOVU+FdmxNcCjyJY/igrgf2j6eeRFhc6bOB7YtmacqEBGqUWRuGwAcB+Kd7qeh7Vi9nX z3Q2ymDYnANBOCzua6Q5y32uK51bKWV/s0lZZSF1yu7bS//KlbONOhOVIe0C5rCli8EUaR 4AmgR+08LrhM2YQh2Fo/Mt76SXpOAJSxMsrH1bvcdh/NQgzq5q2en4FFxn304629p9SSr4 hkq+0D3uideydV9NhwK5pNJ/ukhQuvyjqgL1lI7zuILmfkjkHzeBcZKIkErtgZrXJcdAQD DjONEeTeJ4JQ6dEwQTpdmuv2u+A+Jdp6gvh6wT0bC60XLIxNK9AiFuI30v8Wuw== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 6/8] iwpan: Synchronize nl802154.h with the latest scan changes Date: Fri, 6 Jan 2023 12:18:29 +0100 Message-Id: <20230106111831.692202-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org The content of this file has evolved, reflect the changes accepted in the mainline Linux kernel here with the additional scan definitions. Signed-off-by: Miquel Raynal --- src/nl802154.h | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/nl802154.h b/src/nl802154.h index eb8ad48..648fc93 100644 --- a/src/nl802154.h +++ b/src/nl802154.h @@ -70,6 +70,11 @@ enum nl802154_commands { NL802154_CMD_NEW_SEC_LEVEL, NL802154_CMD_DEL_SEC_LEVEL, + NL802154_CMD_SCAN_EVENT, + NL802154_CMD_TRIGGER_SCAN, + NL802154_CMD_ABORT_SCAN, + NL802154_CMD_SCAN_DONE, + /* add new commands above here */ /* used to define NL802154_CMD_MAX below */ @@ -129,6 +134,15 @@ enum nl802154_attrs { NL802154_ATTR_PID, NL802154_ATTR_NETNS_FD, + NL802154_ATTR_COORDINATOR, + NL802154_ATTR_SCAN_TYPE, + NL802154_ATTR_SCAN_FLAGS, + NL802154_ATTR_SCAN_CHANNELS, + NL802154_ATTR_SCAN_PREAMBLE_CODES, + NL802154_ATTR_SCAN_MEAN_PRF, + NL802154_ATTR_SCAN_DURATION, + NL802154_ATTR_SCAN_DONE_REASON, + /* add attributes here, update the policy in nl802154.c */ #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL @@ -215,6 +229,93 @@ enum nl802154_wpan_phy_capability_attr { NL802154_CAP_ATTR_MAX = __NL802154_CAP_ATTR_AFTER_LAST - 1 }; +/** + * enum nl802154_scan_types - Scan types + * + * @__NL802154_SCAN_INVALID: scan type number 0 is reserved + * @NL802154_SCAN_ED: An ED scan allows a device to obtain a measure of the peak + * energy in each requested channel + * @NL802154_SCAN_ACTIVE: Locate any coordinator transmitting Beacon frames using + * a Beacon Request command + * @NL802154_SCAN_PASSIVE: Locate any coordinator transmitting Beacon frames + * @NL802154_SCAN_ORPHAN: Relocate coordinator following a loss of synchronisation + * @NL802154_SCAN_ENHANCED_ACTIVE: Same as Active using Enhanced Beacon Request + * command instead of Beacon Request command + * @NL802154_SCAN_RIT_PASSIVE: Passive scan for RIT Data Request command frames + * instead of Beacon frames + * @NL802154_SCAN_ATTR_MAX: Maximum SCAN attribute number + */ +enum nl802154_scan_types { + __NL802154_SCAN_INVALID, + NL802154_SCAN_ED, + NL802154_SCAN_ACTIVE, + NL802154_SCAN_PASSIVE, + NL802154_SCAN_ORPHAN, + NL802154_SCAN_ENHANCED_ACTIVE, + NL802154_SCAN_RIT_PASSIVE, + + /* keep last */ + NL802154_SCAN_ATTR_MAX, +}; + +/** + * enum nl802154_scan_done_reasons - End of scan reasons + * + * @__NL802154_SCAN_DONE_REASON_INVALID: scan done reason number 0 is reserved. + * @NL802154_SCAN_DONE_REASON_FINISHED: The scan just finished naturally after + * going through all the requested and possible (complex) channels. + * @NL802154_SCAN_DONE_REASON_ABORTED: The scan was aborted upon user request. + * a Beacon Request command + * @NL802154_SCAN_DONE_REASON_MAX: Maximum scan done reason attribute number. + */ +enum nl802154_scan_done_reasons { + __NL802154_SCAN_DONE_REASON_INVALID, + NL802154_SCAN_DONE_REASON_FINISHED, + NL802154_SCAN_DONE_REASON_ABORTED, + + /* keep last */ + NL802154_SCAN_DONE_REASON_MAX, +}; + +/** + * enum nl802154_coord - Netlink attributes for a coordinator + * + * @__NL802154_COORD_INVALID: invalid + * @NL802154_COORD_PANID: PANID of the coordinator (2 bytes) + * @NL802154_COORD_ADDR: Coordinator address, (8 bytes or 2 bytes) + * @NL802154_COORD_CHANNEL: channel number, related to @NL802154_COORD_PAGE (u8) + * @NL802154_COORD_PAGE: channel page, related to @NL802154_COORD_CHANNEL (u8) + * @NL802154_COORD_PREAMBLE_CODE: Preamble code used when the beacon was received, + * this is PHY dependent and optional (u8) + * @NL802154_COORD_MEAN_PRF: Mean PRF used when the beacon was received, + * this is PHY dependent and optional (u8) + * @NL802154_COORD_SUPERFRAME_SPEC: superframe specification of the PAN (u16) + * @NL802154_COORD_LINK_QUALITY: signal quality of beacon in unspecified units, + * scaled to 0..255 (u8) + * @NL802154_COORD_GTS_PERMIT: set to true if GTS is permitted on this PAN + * @NL802154_COORD_PAYLOAD_DATA: binary data containing the raw data from the + * frame payload, (only if beacon or probe response had data) + * @NL802154_COORD_PAD: attribute used for padding for 64-bit alignment + * @NL802154_COORD_MAX: highest coordinator attribute + */ +enum nl802154_coord { + __NL802154_COORD_INVALID, + NL802154_COORD_PANID, + NL802154_COORD_ADDR, + NL802154_COORD_CHANNEL, + NL802154_COORD_PAGE, + NL802154_COORD_PREAMBLE_CODE, + NL802154_COORD_MEAN_PRF, + NL802154_COORD_SUPERFRAME_SPEC, + NL802154_COORD_LINK_QUALITY, + NL802154_COORD_GTS_PERMIT, + NL802154_COORD_PAYLOAD_DATA, + NL802154_COORD_PAD, + + /* keep last */ + NL802154_COORD_MAX, +}; + /** * enum nl802154_cca_modes - cca modes * From patchwork Fri Jan 6 11:18:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091285 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B43FEC3DA7A for ; Fri, 6 Jan 2023 11:18:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233219AbjAFLSx (ORCPT ); Fri, 6 Jan 2023 06:18:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233258AbjAFLSu (ORCPT ); Fri, 6 Jan 2023 06:18:50 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [IPv6:2001:4b98:dc4:8::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACC6168799 for ; Fri, 6 Jan 2023 03:18:48 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id E08B3240007; Fri, 6 Jan 2023 11:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003927; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UxLq8ur4wa0hdWWTM4JsjZxHX0BrXapAqEEdjCQEVCk=; b=j7VQBVXl+gmtmJ8nvN9XVm//V/kynuNjddty9zDB48V2LAUXdRQzSVm0UhSn0SpqwuTQtk 9UE6YM5E5wc3yvXoKtt3wTuxA9IJ3eBeTRNO/b48J5VeITz1/RyprqAxf+AzUW1x64thSt JXNLRLMFaOwgPh/j3M/Do/KiQCoFfHmEAU9RwR1SGdPL7npXc5JU+8UeXkEOrfqK/BIrZF oV7q6La/NLam7XIBvQjLUyEjQDXDgv0V7JIa0iFly1Jd/kejlXD34nmbTj5BdEZK4ruzkR iP+IPMNXOZ+YcoqNMF1inwg5q6eUwCZR31RvrOoHvxDTMed/093cXee+GC7nIg== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 7/8] iwpan: Add scan support Date: Fri, 6 Jan 2023 12:18:30 +0100 Message-Id: <20230106111831.692202-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: David Girault Bring support for different scanning operations, such as starting or aborting a scan operation with a given configuration, and dumping the discovered coordinators. Signed-off-by: David Girault Signed-off-by: Miquel Raynal --- src/Makefile.am | 1 + src/scan.c | 548 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 549 insertions(+) create mode 100644 src/scan.c diff --git a/src/Makefile.am b/src/Makefile.am index 2d54576..18b3569 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,6 +9,7 @@ iwpan_SOURCES = \ interface.c \ phy.c \ mac.c \ + scan.c \ nl_extras.h \ nl802154.h diff --git a/src/scan.c b/src/scan.c new file mode 100644 index 0000000..63a5e24 --- /dev/null +++ b/src/scan.c @@ -0,0 +1,548 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "nl802154.h" +#include "nl_extras.h" +#include "iwpan.h" + +static char scantypebuf[100]; + +static const char *scantype_name(enum nl802154_scan_types scantype) +{ + switch (scantype) { + case NL802154_SCAN_ED: + return "ed"; + case NL802154_SCAN_ACTIVE: + return "active"; + case NL802154_SCAN_PASSIVE: + return "passive"; + case NL802154_SCAN_ENHANCED_ACTIVE: + return "enhanced"; + case NL802154_SCAN_RIT_PASSIVE: + return "rit"; + default: + sprintf(scantypebuf, "Invalid scantype (%d)", scantype); + return scantypebuf; + } +} + +/* for help */ +#define SCAN_TYPES "Valid scanning types are: ed, active, passive, enhanced, rit." + +/* return 0 if ok, internal error otherwise */ +static int get_scan_type(int *argc, char ***argv, enum nl802154_scan_types *type) +{ + char *tpstr; + + if (*argc < 2) + return 1; + + if (strcmp((*argv)[0], "type")) + return 1; + + tpstr = (*argv)[1]; + *argc -= 2; + *argv += 2; + + if (strcmp(tpstr, "ed") == 0) { + *type = NL802154_SCAN_ED; + return 0; + } else if (strcmp(tpstr, "active") == 0) { + *type = NL802154_SCAN_ACTIVE; + return 0; + } else if (strcmp(tpstr, "passive") == 0) { + *type = NL802154_SCAN_PASSIVE; + return 0; + } else if (strcmp(tpstr, "enhanced") == 0) { + *type = NL802154_SCAN_ENHANCED_ACTIVE; + return 0; + } else if (strcmp(tpstr, "rit") == 0) { + *type = NL802154_SCAN_RIT_PASSIVE; + return 0; + } + + fprintf(stderr, "invalid interface type %s\n", tpstr); + return 2; +} + +static int get_option_value(int *argc, char ***argv, const char *marker, unsigned long *result, bool *valid) +{ + unsigned long value; + char *tpstr, *end; + + *valid = false; + + if (*argc < 2) + return 0; + + if (strcmp((*argv)[0], marker)) + return 0; + + tpstr = (*argv)[1]; + *argc -= 2; + *argv += 2; + + value = strtoul(tpstr, &end, 0); + if (*end != '\0') + return 1; + + *result = value; + *valid = true; + + return 0; +} + +static int scan_trigger_handler(struct nl802154_state *state, + struct nl_cb *cb, + struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + enum nl802154_scan_types type; + unsigned long page, channels, duration; + int tpset; + bool valid_page, valid_channels, valid_duration; + + if (argc < 2) + return 1; + + tpset = get_scan_type(&argc, &argv, &type); + if (tpset) + return tpset; + + tpset = get_option_value(&argc, &argv, "page", &page, &valid_page); + if (tpset) + return tpset; + if (valid_page && page > UINT8_MAX) + return 1; + + tpset = get_option_value(&argc, &argv, "channels", &channels, &valid_channels); + if (tpset) + return tpset; + if (valid_channels && channels > UINT32_MAX) + return 1; + + tpset = get_option_value(&argc, &argv, "duration", &duration, &valid_duration); + if (tpset) + return tpset; + if (valid_duration && duration > UINT8_MAX) + return 1; + + if (argc) + return 1; + + /* Mandatory argument */ + NLA_PUT_U8(msg, NL802154_ATTR_SCAN_TYPE, type); + /* Optional arguments */ + if (valid_duration) + NLA_PUT_U8(msg, NL802154_ATTR_SCAN_DURATION, duration); + if (valid_page) + NLA_PUT_U8(msg, NL802154_ATTR_PAGE, page); + if (valid_channels) + NLA_PUT_U32(msg, NL802154_ATTR_SCAN_CHANNELS, channels); + + /* TODO: support IES parameters for active scans */ + + return 0; + +nla_put_failure: + return -ENOBUFS; +} + +static int scan_abort_handler(struct nl802154_state *state, + struct nl_cb *cb, + struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + return 0; +} + +struct ieee802154_addr { + uint16_t pan_id; + uint8_t addr_len; + union { + uint16_t short_addr; + uint64_t extended_addr; + }; + struct ieee802154_addr *next; +}; + +static struct ieee802154_addr *known_coord_list; + +static bool coord_addrs_are_equal(struct ieee802154_addr *a, + struct ieee802154_addr *b) +{ + if (a->pan_id != b->pan_id) + return false; + + if (a->addr_len != b->addr_len) + return false; + + if (a->addr_len == 2 && a->short_addr == b->short_addr) + return true; + else if (a->extended_addr == b->extended_addr) + return true; + + return false; +} + +static bool coord_is_known(struct ieee802154_addr *addr) +{ + struct ieee802154_addr *item = known_coord_list; + + while (item) { + if (coord_addrs_are_equal(addr, item)) + return true; + + item = item->next; + } + + return false; +} + +static void record_coord(struct ieee802154_addr *addr) +{ + struct ieee802154_addr *item; + + if (!known_coord_list) { + known_coord_list = addr; + return; + } + + item = known_coord_list; + if (!item->next) { + item->next = addr; + return; + } + + do { + item = item->next; + } while (item->next); + + item->next = addr; +} + +static void flush_coords(void) +{ + struct ieee802154_addr *item, *next; + + if (!known_coord_list) + return; + + item = known_coord_list; + do { + next = item->next; + free(item); + item = next; + } while (item); +} + +static struct ieee802154_addr *parse_new_coordinator(struct nlattr *nestedcoord) +{ + struct nlattr *pan[NL802154_COORD_MAX + 1]; + static struct nla_policy pan_policy[NL802154_COORD_MAX + 1] = { + [NL802154_COORD_PANID] = { .type = NLA_U16, }, + [NL802154_COORD_ADDR] = { .minlen = 2, .maxlen = 8, }, /* 2 or 8 */ + [NL802154_COORD_CHANNEL] = { .type = NLA_U8, }, + [NL802154_COORD_PAGE] = { .type = NLA_U8, }, + [NL802154_COORD_PREAMBLE_CODE] = { .type = NLA_U8, }, + [NL802154_COORD_MEAN_PRF] = { .type = NLA_U8, }, + [NL802154_COORD_SUPERFRAME_SPEC] = { .type = NLA_U16, }, + [NL802154_COORD_LINK_QUALITY] = { .type = NLA_U8, }, + [NL802154_COORD_GTS_PERMIT] = { .type = NLA_FLAG, }, + }; + struct ieee802154_addr *addr; + struct nlattr *coord; + char dev[20]; + int ret; + + ret = nla_parse_nested(pan, NL802154_COORD_MAX, nestedcoord, pan_policy); + if (ret < 0) { + fprintf(stderr, "failed to parse nested attributes! (ret = %d)\n", + ret); + return NULL; + } + if (!pan[NL802154_COORD_PANID] || !pan[NL802154_COORD_ADDR]) + return NULL; + + addr = malloc(sizeof(*addr)); + if (!addr) + return NULL; + + addr->pan_id = nla_get_u16(pan[NL802154_COORD_PANID]); + coord = pan[NL802154_COORD_ADDR]; + addr->addr_len = nla_len(coord); + if (addr->addr_len == 2) + addr->short_addr = nla_get_u16(coord); + else + addr->extended_addr = nla_get_u64(coord); + + return addr; +} + +static int print_new_coordinator(struct nlattr *nestedcoord, + struct nlattr *ifattr) +{ + struct nlattr *pan[NL802154_COORD_MAX + 1]; + static struct nla_policy pan_policy[NL802154_COORD_MAX + 1] = { + [NL802154_COORD_PANID] = { .type = NLA_U16, }, + [NL802154_COORD_ADDR] = { .minlen = 2, .maxlen = 8, }, /* 2 or 8 */ + [NL802154_COORD_CHANNEL] = { .type = NLA_U8, }, + [NL802154_COORD_PAGE] = { .type = NLA_U8, }, + [NL802154_COORD_PREAMBLE_CODE] = { .type = NLA_U8, }, + [NL802154_COORD_MEAN_PRF] = { .type = NLA_U8, }, + [NL802154_COORD_SUPERFRAME_SPEC] = { .type = NLA_U16, }, + [NL802154_COORD_LINK_QUALITY] = { .type = NLA_U8, }, + [NL802154_COORD_GTS_PERMIT] = { .type = NLA_FLAG, }, + }; + char dev[20]; + int ret; + + ret = nla_parse_nested(pan, NL802154_COORD_MAX, nestedcoord, pan_policy); + if (ret < 0) { + fprintf(stderr, "failed to parse nested attributes! (ret = %d)\n", + ret); + return NL_SKIP; + } + if (!pan[NL802154_COORD_PANID]) + return NL_SKIP; + + printf("PAN 0x%04x", le16toh(nla_get_u16(pan[NL802154_COORD_PANID]))); + if (ifattr) { + if_indextoname(nla_get_u32(ifattr), dev); + printf(" (on %s)", dev); + } + printf("\n"); + if (pan[NL802154_COORD_ADDR]) { + struct nlattr *coord = pan[NL802154_COORD_ADDR]; + if (nla_len(coord) == 2) { + uint16_t addr = nla_get_u16(coord); + printf("\tcoordinator 0x%04x\n", le16toh(addr)); + } else { + uint64_t addr = nla_get_u64(coord); + printf("\tcoordinator 0x%016" PRIx64 "\n", le64toh(addr)); + } + } + if (pan[NL802154_COORD_PAGE]) { + printf("\tpage %u\n", nla_get_u8(pan[NL802154_COORD_PAGE])); + } + if (pan[NL802154_COORD_CHANNEL]) { + printf("\tchannel %u\n", nla_get_u8(pan[NL802154_COORD_CHANNEL])); + } + if (pan[NL802154_COORD_SUPERFRAME_SPEC]) { + printf("\tsuperframe spec. 0x%x\n", nla_get_u16( + pan[NL802154_COORD_SUPERFRAME_SPEC])); + } + if (pan[NL802154_COORD_LINK_QUALITY]) { + printf("\tLQI %x\n", nla_get_u8( + pan[NL802154_COORD_LINK_QUALITY])); + } + if (pan[NL802154_COORD_GTS_PERMIT]) { + printf("\tGTS permitted\n"); + } + + /* TODO: Beacon IES display/decoding */ + + return NL_OK; +} + +static int parse_and_print_new_coordinator(struct nlattr *nestedcoord, + struct nlattr *ifattr) +{ + struct ieee802154_addr *addr; + + addr = parse_new_coordinator(nestedcoord); + if (!addr) + return NL_SKIP; + + if (coord_is_known(addr)) { + free(addr); + } else { + record_coord(addr); + print_new_coordinator(nestedcoord, ifattr); + } + + return NL_OK; +} + +static int parse_and_print_scan_event(struct nl_msg *msg, void *arg) +{ + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL802154_ATTR_MAX + 1]; + struct nlattr *nestedcoord; + + nla_parse(tb, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + + nestedcoord = tb[NL802154_ATTR_COORDINATOR]; + if (!nestedcoord) { + fprintf(stderr, "coordinator info missing!\n"); + return NL_SKIP; + } + + return parse_and_print_new_coordinator(nestedcoord, tb[NL802154_ATTR_IFINDEX]); +} + +struct scan_done { + volatile int done; + int devidx; +}; + +static int scan_message_handler(struct nl_msg *msg, void *arg) +{ + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct scan_done *sd = (struct scan_done *)arg; + + if (gnlh->cmd == NL802154_CMD_SCAN_EVENT) + return parse_and_print_scan_event(msg, arg); + + if (gnlh->cmd != NL802154_CMD_SCAN_DONE && + gnlh->cmd != NL802154_CMD_ABORT_SCAN) + return 0; + + if (sd->devidx != -1) { + struct nlattr *tb[NL802154_ATTR_MAX + 1]; + nla_parse(tb, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + if (!tb[NL802154_ATTR_IFINDEX] || + nla_get_u32(tb[NL802154_ATTR_IFINDEX]) != sd->devidx) + return 0; + } + + sd->done = 1; + return 0; +} + +static int no_seq_check(struct nl_msg *msg, void *arg) +{ + return NL_OK; +} + +struct abort_info { + char *cmd[3]; + struct nl802154_state *state; + enum id_input id; + struct scan_done *sd; +}; + +static struct abort_info abort_info = { + .cmd = { NULL, "scan", "abort" }, +}; + +static void scan_sigint_handler(int signo) +{ + /* dev scan abort */ + handle_cmd(abort_info.state, abort_info.id, 3, abort_info.cmd); + abort_info.sd->done = 1; + nl_socket_set_nonblocking(abort_info.state->nl_sock); +} + +static int scan_handler(struct nl802154_state *state, struct nl_cb *cb, + struct nl_msg *msg, int argc, char **argv, + enum id_input id) +{ + struct scan_done sd; + int ret, group; + + /* Abort scan upon SIGINT */ + abort_info.cmd[0] = argv[0]; + abort_info.state = state; + abort_info.id = id; + abort_info.sd = &sd; + signal(SIGINT, scan_sigint_handler); + + /* Create netlink message to trigger the scan */ + msg = nlmsg_alloc(); + if (!msg) { + fprintf(stderr, "failed to allocate netlink message\n"); + return 2; + } + + cb = nl_cb_alloc(iwpan_debug ? NL_CB_DEBUG : NL_CB_DEFAULT); + if (!cb) { + fprintf(stderr, "failed to allocate netlink callbacks\n"); + ret = 2; + goto free_msg; + } + + genlmsg_put(msg, 0, 0, state->nl802154_id, 0, 0, + NL802154_CMD_TRIGGER_SCAN, 0); + + sd.devidx = if_nametoindex(*argv); + if (sd.devidx == 0) + sd.devidx = -1; + + NLA_PUT_U32(msg, NL802154_ATTR_IFINDEX, sd.devidx); + + /* Skip " scan" */ + argc -= 2; + argv += 2; + + /* Parse the "trigger" command */ + ret = scan_trigger_handler(state, cb, msg, argc, argv, id); + if (ret) + goto nla_put_failure; + + /* Configure socket to receive messages in Scan multicast group */ + group = genl_ctrl_resolve_grp(state->nl_sock, "nl802154", "scan"); + if (group < 0) { + ret = group; + goto nla_put_failure; + } + + ret = nl_socket_add_membership(state->nl_sock, group); + if (ret) + goto nla_put_failure; + + /* Install scan message handler */ + nl_socket_set_cb(state->nl_sock, cb); + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, scan_message_handler, &sd); + + /* No sequence checking for multicast messages */ + nl_socket_disable_seq_check(state->nl_sock); + + /* Trigger the scan */ + ret = nl_send_auto_complete(state->nl_sock, msg); + if (ret < 0) + goto nla_put_failure; + + ret = 0; + + /* Receive messages */ + sd.done = 0; + do { + nl_recvmsgs(state->nl_sock, cb); + } while (!sd.done); + + flush_coords(); + +nla_put_failure: + nl_cb_put(cb); +free_msg: + nlmsg_free(msg); + + return ret; +} +TOPLEVEL(scan, "type [page ] [channels ] [duration ]", + 0, 0, CIB_NETDEV, scan_handler, + "Scan on this virtual interface with the given configuration.\n" + SCAN_TYPES); +COMMAND(scan, abort, NULL, NL802154_CMD_ABORT_SCAN, 0, CIB_NETDEV, scan_abort_handler, + "Abort ongoing scanning on this virtual interface"); +COMMAND(scan, trigger, + "type [page ] [channels ] [duration ]", + NL802154_CMD_TRIGGER_SCAN, 0, CIB_NETDEV, scan_trigger_handler, + "Launch scanning on this virtual interface with the given configuration.\n" + SCAN_TYPES); From patchwork Fri Jan 6 11:18:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13091286 X-Patchwork-Delegate: stefan@osg.samsung.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0A13C54EBF for ; Fri, 6 Jan 2023 11:18:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233226AbjAFLSy (ORCPT ); Fri, 6 Jan 2023 06:18:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233195AbjAFLSv (ORCPT ); Fri, 6 Jan 2023 06:18:51 -0500 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200A2625DF for ; Fri, 6 Jan 2023 03:18:49 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 82FFD240008; Fri, 6 Jan 2023 11:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1673003928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t9BokGGjpAInouafUidXyQ6lPlLt+AXEAwDeJ9zY+Xk=; b=J2pK6bMS+ktIhfQfL1/w5YjFZQ64CiL8XvgmmYcHff1TQjd83Pq1OwNm5zbhw3znPPZeQJ f5A8AfJvYVU9KiFCgrAD7KPVdTMcusvVQJAbEaID1dvLdVGfCa5MTEGyeqcFWuaPvvFK47 wqy2JH7gQ/0VThYZhXBlW0Ws4qVQWWCTKwKuHAe/i0ErI9kp2jwT+KHf+asg0Yk56mRJny g8el1MyUFb8X+6s4MGn54oKaa19tv8Va1hCWVcvdue9vLBMxpwKERGxv9VXyNneSIzT3Us XynpKxQQ0OTlCmtp5MG6OeESy1/fCmdIxgdseFXRDFiTpRULFoh8EsOjY5Ea3Q== From: Miquel Raynal To: Alexander Aring , Stefan Schmidt , linux-wpan@vger.kernel.org Cc: David Girault , Romuald Despres , Frederic Blain , Nicolas Schodet , Guilhem Imberton , Thomas Petazzoni , Miquel Raynal Subject: [PATCH wpan-tools v2 8/8] iwpan: Add events support Date: Fri, 6 Jan 2023 12:18:31 +0100 Message-Id: <20230106111831.692202-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230106111831.692202-1-miquel.raynal@bootlin.com> References: <20230106111831.692202-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org From: David Girault Add the possibility to listen to the scan multicast netlink family in order to print all the events happening in the 802.15.4 stack, like the discovery of a new coordinator or an end of scan. Signed-off-by: David Girault Signed-off-by: Miquel Raynal --- src/Makefile.am | 1 + src/event.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 src/event.c diff --git a/src/Makefile.am b/src/Makefile.am index 18b3569..7933daf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ iwpan_SOURCES = \ phy.c \ mac.c \ scan.c \ + event.c \ nl_extras.h \ nl802154.h diff --git a/src/event.c b/src/event.c new file mode 100644 index 0000000..5ec597d --- /dev/null +++ b/src/event.c @@ -0,0 +1,230 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "nl802154.h" +#include "nl_extras.h" +#include "iwpan.h" + +struct print_event_args { + struct timeval ts; /* internal */ + bool have_ts; /* must be set false */ + bool frame, time, reltime; +}; + +static int print_event(struct nl_msg *msg, void *arg) +{ + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *tb[NL802154_ATTR_MAX + 1], *nst, *nestedcoord; + struct nlattr *pan[NL802154_COORD_MAX + 1]; + struct print_event_args *args = arg; + char ifname[100]; + static struct nla_policy pan_policy[NL802154_COORD_MAX + 1] = { + [NL802154_COORD_PANID] = { .type = NLA_U16, }, + [NL802154_COORD_ADDR] = { .minlen = 2, .maxlen = 8, }, /* 2 or 8 */ + }; + uint8_t reg_type; + uint32_t wpan_phy_idx = 0; + int rem_nst; + uint16_t status; + int ret; + + if (args->time || args->reltime) { + unsigned long long usecs, previous; + + previous = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; + gettimeofday(&args->ts, NULL); + usecs = 1000000ULL * args->ts.tv_sec + args->ts.tv_usec; + if (args->reltime) { + if (!args->have_ts) { + usecs = 0; + args->have_ts = true; + } else + usecs -= previous; + } + printf("%llu.%06llu: ", usecs/1000000, usecs % 1000000); + } + + nla_parse(tb, NL802154_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + + if (tb[NL802154_ATTR_IFINDEX] && tb[NL802154_ATTR_WPAN_PHY]) { + if_indextoname(nla_get_u32(tb[NL802154_ATTR_IFINDEX]), ifname); + printf("%s (phy #%d): ", ifname, nla_get_u32(tb[NL802154_ATTR_WPAN_PHY])); + } else if (tb[NL802154_ATTR_WPAN_DEV] && tb[NL802154_ATTR_WPAN_PHY]) { + printf("wdev 0x%llx (phy #%d): ", + (unsigned long long)nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]), + nla_get_u32(tb[NL802154_ATTR_WPAN_PHY])); + } else if (tb[NL802154_ATTR_IFINDEX]) { + if_indextoname(nla_get_u32(tb[NL802154_ATTR_IFINDEX]), ifname); + printf("%s: ", ifname); + } else if (tb[NL802154_ATTR_WPAN_DEV]) { + printf("wdev 0x%llx: ", (unsigned long long)nla_get_u64(tb[NL802154_ATTR_WPAN_DEV])); + } else if (tb[NL802154_ATTR_WPAN_PHY]) { + printf("phy #%d: ", nla_get_u32(tb[NL802154_ATTR_WPAN_PHY])); + } + + switch (gnlh->cmd) { + case NL802154_CMD_NEW_WPAN_PHY: + printf("renamed to %s\n", nla_get_string(tb[NL802154_ATTR_WPAN_PHY_NAME])); + break; + case NL802154_CMD_DEL_WPAN_PHY: + printf("delete wpan_phy\n"); + break; + case NL802154_CMD_TRIGGER_SCAN: + printf("scan started\n"); + break; + case NL802154_CMD_SCAN_DONE: + if (tb[NL802154_ATTR_SCAN_DONE_REASON]) + status = nla_get_u8(tb[NL802154_ATTR_SCAN_DONE_REASON]); + if (status == NL802154_SCAN_DONE_REASON_ABORTED) + printf("scan aborted\n"); + else + printf("scan finished\n"); + break; + case NL802154_CMD_ABORT_SCAN: + printf("scan aborted\n"); + break; + case NL802154_CMD_SCAN_EVENT: + nestedcoord = tb[NL802154_ATTR_COORDINATOR]; + if (!nestedcoord) + break; + ret = nla_parse_nested(pan, NL802154_COORD_MAX, nestedcoord, pan_policy); + if (ret < 0) + break; + if (!pan[NL802154_COORD_PANID]) + break; + printf("beacon received: PAN 0x%04x", + le16toh(nla_get_u16(pan[NL802154_COORD_PANID]))); + if (pan[NL802154_COORD_ADDR]) { + struct nlattr *coord = pan[NL802154_COORD_ADDR]; + if (nla_len(coord) == 2) { + uint16_t addr = nla_get_u16(coord); + printf(", addr 0x%04x\n", le16toh(addr)); + } else { + uint64_t addr = nla_get_u64(coord); + printf(", addr 0x%016" PRIx64 "\n", le64toh(addr)); + } + } + break; + default: + printf("unknown event %d\n", gnlh->cmd); + break; + } + fflush(stdout); + return NL_SKIP; +} + +static int __prepare_listen_events(struct nl802154_state *state) +{ + int mcid, ret; + + /* Configuration multicast group */ + mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME, + "config"); + if (mcid < 0) + return mcid; + ret = nl_socket_add_membership(state->nl_sock, mcid); + if (ret) + return ret; + + /* Scan multicast group */ + mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME, + "scan"); + if (mcid >= 0) { + ret = nl_socket_add_membership(state->nl_sock, mcid); + if (ret) + return ret; + } + + /* MLME multicast group */ + mcid = genl_ctrl_resolve_grp(state->nl_sock, NL802154_GENL_NAME, + "mlme"); + if (mcid >= 0) { + ret = nl_socket_add_membership(state->nl_sock, mcid); + if (ret) + return ret; + } + + return 0; +} + +static int __do_listen_events(struct nl802154_state *state, + struct print_event_args *args) +{ + struct nl_cb *cb = nl_cb_alloc(iwpan_debug ? NL_CB_DEBUG : NL_CB_DEFAULT); + if (!cb) { + fprintf(stderr, "failed to allocate netlink callbacks\n"); + return -ENOMEM; + } + nl_socket_set_cb(state->nl_sock, cb); + /* No sequence checking for multicast messages */ + nl_socket_disable_seq_check(state->nl_sock); + /* Install print_event message handler */ + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_event, args); + + /* Loop waiting until interrupted by signal */ + while (1) { + int ret = nl_recvmsgs(state->nl_sock, cb); + if (ret) { + fprintf(stderr, "nl_recvmsgs return error %d\n", ret); + break; + } + } + /* Free allocated nl_cb structure */ + nl_cb_put(cb); + return 0; +} + +static int print_events(struct nl802154_state *state, + struct nl_cb *cb, + struct nl_msg *msg, + int argc, char **argv, + enum id_input id) +{ + struct print_event_args args; + int ret; + + memset(&args, 0, sizeof(args)); + + argc--; + argv++; + + while (argc > 0) { + if (strcmp(argv[0], "-f") == 0) + args.frame = true; + else if (strcmp(argv[0], "-t") == 0) + args.time = true; + else if (strcmp(argv[0], "-r") == 0) + args.reltime = true; + else + return 1; + argc--; + argv++; + } + if (args.time && args.reltime) + return 1; + if (argc) + return 1; + + /* Prepare reception of all multicast messages */ + ret = __prepare_listen_events(state); + if (ret) + return ret; + + /* Read message loop */ + return __do_listen_events(state, &args); +} +TOPLEVEL(monitor, "[-t|-r] [-f]", 0, 0, CIB_NONE, print_events, + "Monitor events from the kernel.\n" + "-t - print timestamp\n" + "-r - print relative timestamp\n" + "-f - print full frame for auth/assoc etc.");