From 3796b33e6a5f2808cb111ef8fb98eb71ef0e9e9d Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 25 Jul 2018 02:20:41 -0700 Subject: [PATCH] [commissioner] add new API to get Provisioning URL (#2884) --- include/openthread/commissioner.h | 13 +++++++++++++ src/core/api/commissioner_api.cpp | 19 +++++++++++++++++++ src/core/meshcop/commissioner.cpp | 9 +++++++++ src/core/meshcop/commissioner.hpp | 12 ++++++++++++ 4 files changed, 53 insertions(+) diff --git a/include/openthread/commissioner.h b/include/openthread/commissioner.h index cc2db14b7..b40312ddd 100644 --- a/include/openthread/commissioner.h +++ b/include/openthread/commissioner.h @@ -121,6 +121,19 @@ OTAPI otError OTCALL otCommissionerAddJoiner(otInstance * aInstance, */ OTAPI otError OTCALL otCommissionerRemoveJoiner(otInstance *aInstance, const otExtAddress *aEui64); +/** + * This function gets the Provisioning URL. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[out] aLength A pointer to `uint16_t` to return the length (number of chars) in the URL string. + * + * Note that the returned URL string buffer is not necessarily null-terminated. + * + * @returns A pointer to char buffer containing the URL string, or NULL if @p aLength is NULL. + * + */ +const char *otCommissionerGetProvisioningUrl(otInstance *aInstance, uint16_t *aLength); + /** * This function sets the Provisioning URL. * diff --git a/src/core/api/commissioner_api.cpp b/src/core/api/commissioner_api.cpp index 9af9ddaaf..fcefe6a8a 100644 --- a/src/core/api/commissioner_api.cpp +++ b/src/core/api/commissioner_api.cpp @@ -124,6 +124,25 @@ otError otCommissionerSetProvisioningUrl(otInstance *aInstance, const char *aPro return error; } +const char *otCommissionerGetProvisioningUrl(otInstance *aInstance, uint16_t *aLength) +{ + const char *url = NULL; + +#if OPENTHREAD_FTD && OPENTHREAD_ENABLE_COMMISSIONER + Instance &instance = *static_cast(aInstance); + + if (aLength != NULL) + { + url = instance.GetThreadNetif().GetCommissioner().GetProvisioningUrl(*aLength); + } +#else + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aLength); +#endif + + return url; +} + otError otCommissionerAnnounceBegin(otInstance * aInstance, uint32_t aChannelMask, uint8_t aCount, diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 612b20186..f6025f62f 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -310,6 +310,15 @@ exit: return error; } +const char *Commissioner::GetProvisioningUrl(uint16_t &aLength) const +{ + ProvisioningUrlTlv &provisioningUrl = GetNetif().GetDtls().mProvisioningUrl; + + aLength = provisioningUrl.GetLength(); + + return provisioningUrl.GetProvisioningUrl(); +} + otError Commissioner::SetProvisioningUrl(const char *aProvisioningUrl) { return GetNetif().GetDtls().mProvisioningUrl.SetProvisioningUrl(aProvisioningUrl); diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index effef0480..a74b8ff48 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -116,6 +116,18 @@ public: */ otError RemoveJoiner(const Mac::ExtAddress *aEui64, uint32_t aDelay); + /** + * This method gets the Provisioning URL. + * + * @param[out] aLength A reference to `uint16_t` to return the length (number of chars) in the URL string. + * + * Note that the returned URL string buffer is not necessarily null-terminated. + * + * @returns A pointer to char buffer containing the URL string. + * + */ + const char *GetProvisioningUrl(uint16_t &aLength) const; + /** * This method sets the Provisioning URL. *