Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[openwrt] Adapt to OpenWRT platform #2458

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/openwrt/ubus/otubus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ enum
{
PSKD,
EUI64,
TIMEOUT,
ADD_JOINER_MAX,
};

Expand Down Expand Up @@ -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] = {
Expand Down Expand Up @@ -195,7 +197,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)},
Expand Down Expand Up @@ -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)
Expand All @@ -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<uint32_t>(timeout)));
}
Expand Down Expand Up @@ -1215,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);

Expand All @@ -1229,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)
{
Expand Down