From fb3bec5767db028a208ffb0782d0fe7d7c41a41d Mon Sep 17 00:00:00 2001 From: Yejiang Luo Date: Mon, 26 Aug 2024 17:20:07 +0800 Subject: [PATCH 1/3] [openwrt] fix definition of ubus method joinerremove This commit lets the caller know that `ubus call joinerremove` requires parameters to be passed in. Signed-off-by: Yejiang Luo --- src/openwrt/ubus/otubus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openwrt/ubus/otubus.cpp b/src/openwrt/ubus/otubus.cpp index b1f86b50c1d..ee35b6b4e02 100644 --- a/src/openwrt/ubus/otubus.cpp +++ b/src/openwrt/ubus/otubus.cpp @@ -195,7 +195,7 @@ static const struct ubus_method otbrMethods[] = { {"networkdata", &UbusServer::UbusNetworkdataHandler, 0, 0, nullptr, 0}, {"commissionerstart", &UbusServer::UbusCommissionerStartHandler, 0, 0, nullptr, 0}, {"joinernum", &UbusServer::UbusJoinerNumHandler, 0, 0, nullptr, 0}, - {"joinerremove", &UbusServer::UbusJoinerRemoveHandler, 0, 0, nullptr, 0}, + {"joinerremove", &UbusServer::UbusJoinerRemoveHandler, 0, 0, removeJoinerPolicy, ARRAY_SIZE(removeJoinerPolicy)}, {"macfiltersetstate", &UbusServer::UbusMacfilterSetStateHandler, 0, 0, macfilterSetStatePolicy, ARRAY_SIZE(macfilterSetStatePolicy)}, {"macfilteradd", &UbusServer::UbusMacfilterAddHandler, 0, 0, macfilterAddPolicy, ARRAY_SIZE(macfilterAddPolicy)}, From a088d34522e871b0d119511b8b8975c9a0c1546a Mon Sep 17 00:00:00 2001 From: Yejiang Luo Date: Mon, 26 Aug 2024 17:37:55 +0800 Subject: [PATCH 2/3] [openwrt] add timeout support in ubus call joineradd method Signed-off-by: Yejiang Luo --- src/openwrt/ubus/otubus.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/openwrt/ubus/otubus.cpp b/src/openwrt/ubus/otubus.cpp index ee35b6b4e02..be7942e2459 100644 --- a/src/openwrt/ubus/otubus.cpp +++ b/src/openwrt/ubus/otubus.cpp @@ -93,6 +93,7 @@ enum { PSKD, EUI64, + TIMEOUT, ADD_JOINER_MAX, }; @@ -152,8 +153,9 @@ static const struct blobmsg_policy removeJoinerPolicy[SET_NETWORK_MAX] = { }; static const struct blobmsg_policy addJoinerPolicy[ADD_JOINER_MAX] = { - [PSKD] = {.name = "pskd", .type = BLOBMSG_TYPE_STRING}, - [EUI64] = {.name = "eui64", .type = BLOBMSG_TYPE_STRING}, + [PSKD] = {.name = "pskd", .type = BLOBMSG_TYPE_STRING}, + [EUI64] = {.name = "eui64", .type = BLOBMSG_TYPE_STRING}, + [TIMEOUT] = {.name = "timeout", .type = BLOBMSG_TYPE_INT32}, }; static const struct blobmsg_policy mgmtsetPolicy[MGMTSET_MAX] = { @@ -960,6 +962,7 @@ int UbusServer::UbusCommissioner(struct ubus_context *aContext, otExtAddress addr; const otExtAddress *addrPtr = nullptr; char *pskd = nullptr; + unsigned long timeout = 0; blobmsg_parse(addJoinerPolicy, ADD_JOINER_MAX, tb, blob_data(aMsg), blob_len(aMsg)); if (tb[PSKD] != nullptr) @@ -981,7 +984,15 @@ int UbusServer::UbusCommissioner(struct ubus_context *aContext, } } - unsigned long timeout = kDefaultJoinerTimeout; + if (tb[TIMEOUT] != nullptr) + { + timeout = blobmsg_get_u32(tb[TIMEOUT]); + } + else + { + timeout = kDefaultJoinerTimeout; + } + SuccessOrExit(error = otCommissionerAddJoiner(mHost->GetInstance(), addrPtr, pskd, static_cast(timeout))); } From 7e5f0e120dd627dceed1f9f23b23d84488026ced Mon Sep 17 00:00:00 2001 From: Yejiang Luo Date: Mon, 26 Aug 2024 17:50:57 +0800 Subject: [PATCH 3/3] [openwrt] fix stack overflow in ubus call joinernum method This commit also adds the expiration_time parameter information. Signed-off-by: Yejiang Luo --- src/openwrt/ubus/otubus.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/openwrt/ubus/otubus.cpp b/src/openwrt/ubus/otubus.cpp index be7942e2459..c42df8d11c3 100644 --- a/src/openwrt/ubus/otubus.cpp +++ b/src/openwrt/ubus/otubus.cpp @@ -1226,9 +1226,9 @@ int UbusServer::UbusGetInformation(struct ubus_context *aContext, void *jsonTable = nullptr; void *jsonArray = nullptr; otJoinerInfo joinerInfo; - uint16_t iterator = 0; - int joinerNum = 0; - char eui64[EXTPANID] = ""; + uint16_t iterator = 0; + int joinerNum = 0; + char eui64[XPANID_LENGTH] = ""; blob_buf_init(&mBuf, 0); @@ -1240,6 +1240,7 @@ int UbusServer::UbusGetInformation(struct ubus_context *aContext, jsonTable = blobmsg_open_table(&mBuf, nullptr); blobmsg_add_string(&mBuf, "pskd", joinerInfo.mPskd.m8); + blobmsg_add_u64(&mBuf, "expiration_time", joinerInfo.mExpirationTime); switch (joinerInfo.mType) {