[ncp] update MESHCOP_JOINER_COMMISSIONING to allow vendor info to be given (#3767)

This commit updates `SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING`
definition to allow vendor info (name, model, sw version, data) to be
specified. All new parameters are optional and if not specified in the
spinel frame (or an empty string is given), OpenThread default values
will be used instead.

This change in `SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING` format keeps
it backward compatible with previous definition, ensuring any driver
using the previous format will be parsed in the same way.
This commit is contained in:
Abtin Keshavarzian
2019-04-17 19:08:11 -07:00
committed by Jonathan Hui
parent bd2e3ef8f9
commit 987e96ba0d
2 changed files with 74 additions and 15 deletions
+58 -9
View File
@@ -1446,24 +1446,73 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_MESHCOP_JOINER_STATE>
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING>(void)
{
otError error = OT_ERROR_NONE;
bool action = false;
const char *psk = NULL;
const char *provisioningUrl = NULL;
otError error = OT_ERROR_NONE;
const char *vendorName = NULL;
const char *vendorModel = NULL;
const char *vendorSwVersion = NULL;
const char *vendorData = NULL;
SuccessOrExit(error = mDecoder.ReadBool(action));
SuccessOrExit(error = mDecoder.ReadUtf8(psk));
SuccessOrExit(error = mDecoder.ReadUtf8(provisioningUrl));
if (action)
{
error = otJoinerStart(mInstance, psk, provisioningUrl, PACKAGE_NAME, OPENTHREAD_CONFIG_PLATFORM_INFO,
PACKAGE_VERSION, NULL, &NcpBase::HandleJoinerCallback_Jump, this);
}
else
if (action == false)
{
error = otJoinerStop(mInstance);
ExitNow();
}
SuccessOrExit(error = mDecoder.ReadUtf8(psk));
// Parse optional fields
if (!mDecoder.IsAllReadInStruct())
{
SuccessOrExit(error = mDecoder.ReadUtf8(provisioningUrl));
}
if (!mDecoder.IsAllReadInStruct())
{
SuccessOrExit(error = mDecoder.ReadUtf8(vendorName));
}
if (!mDecoder.IsAllReadInStruct())
{
SuccessOrExit(error = mDecoder.ReadUtf8(vendorModel));
}
if (!mDecoder.IsAllReadInStruct())
{
SuccessOrExit(error = mDecoder.ReadUtf8(vendorSwVersion));
}
if (!mDecoder.IsAllReadInStruct())
{
SuccessOrExit(error = mDecoder.ReadUtf8(vendorData));
}
// Use OpenThread default values for vendor name, mode, sw version if
// not specified or an empty string is given.
if ((vendorName == NULL) || (vendorName[0] == 0))
{
vendorName = PACKAGE_NAME;
}
if ((vendorModel == NULL) || (vendorModel[0] == 0))
{
vendorModel = OPENTHREAD_CONFIG_PLATFORM_INFO;
}
if ((vendorSwVersion == NULL) || (vendorSwVersion[0] == 0))
{
vendorSwVersion = PACKAGE_VERSION;
}
error = otJoinerStart(mInstance, psk, provisioningUrl, vendorName, vendorModel, vendorSwVersion, vendorData,
&NcpBase::HandleJoinerCallback_Jump, this);
exit:
return error;
}
+16 -6
View File
@@ -2638,7 +2638,7 @@ typedef enum
SPINEL_PROP_MESHCOP_JOINER_STATE = SPINEL_PROP_MESHCOP__BEGIN + 0, ///<[C]
/// Thread Joiner Commissioning command and the parameters
/** Format `bUU` - Write Only
/** Format `b` or `bU(UUUUU)` (fields in parenthesis are optional) - Write Only
*
* This property starts or stops Joiner's commissioning process
*
@@ -2649,7 +2649,7 @@ typedef enum
* the Joiner commissioning process.
*
* After a successful start operation, the join process outcome is reported through an
* asynchronous `VALUE_IS(LAST_STATUS)` update with one of the following error status values:
* asynchronous `VALUE_IS(LAST_STATUS)` update with one of the following error status values:
*
* - SPINEL_STATUS_JOIN_SUCCESS the join process succeeded.
* - SPINEL_STATUS_JOIN_SECURITY the join process failed due to security credentials.
@@ -2657,11 +2657,21 @@ typedef enum
* - SPINEL_STATUS_JOIN_RSP_TIMEOUT if a response timed out.
* - SPINEL_STATUS_JOIN_FAILURE join failure.
*
* Data per item is:
* Frame format:
*
* `b` : Start or stop commissioning process
* `U` : Joiner's PSKd if start commissioning, empty string if stop commissioning
* `U` : Provisioning url if start commissioning, empty string if stop commissioning
* `b` : Start or stop commissioning process (true to start).
*
* Only if the start commissioning.
*
* `U` : Joiner's PSKd.
*
* The next fields are all optional. If not provided, OpenThread default values would be used.
*
* `U` : Provisioning URL (use empty string if not required).
* `U` : Vendor Name. If not specified or empty string, use OpenThread default (PACKAGE_NAME).
* `U` : Vendor Model. If not specified or empty string, use OpenThread default (OPENTHREAD_CONFIG_PLATFORM_INFO).
* `U` : Vendor Sw Version. If not specified or empty string, use OpenThread default (PACKAGE_VERSION).
* `U` : Vendor Data String. Will not be appended if not specified.
*
*/
SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING = SPINEL_PROP_MESHCOP__BEGIN + 1,