Skip to content

Commit 968cea2

Browse files
Remove unset threadNetwork Scan (#31704)
* divide android commissioning parameter * Fix countrycode copy issue * Restyled by clang-format * Update commissioningParameter --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 3dc2320 commit 968cea2

4 files changed

+53
-47
lines changed

src/controller/CommissioningDelegate.h

+3
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,12 @@ class CommissioningParameters
370370
mAttestationNonce.SetValue(attestationNonce);
371371
return *this;
372372
}
373+
374+
// If a WiFiCredentials is provided, then the WiFiNetworkScan will not be attempted
373375
CommissioningParameters & SetWiFiCredentials(WiFiCredentials wifiCreds)
374376
{
375377
mWiFiCreds.SetValue(wifiCreds);
378+
mAttemptWiFiNetworkScan.SetValue(false);
376379
return *this;
377380
}
378381

src/controller/java/AndroidDeviceControllerWrapper.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
104104
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate, jbyteArray nodeOperationalCertificate,
105105
jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId, uint16_t failsafeTimerSeconds,
106106
bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
107-
bool skipAttestationCertificateValidation, CHIP_ERROR * errInfoOnFailure)
107+
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure)
108108
{
109109
if (errInfoOnFailure == nullptr)
110110
{
@@ -207,11 +207,30 @@ AndroidDeviceControllerWrapper * AndroidDeviceControllerWrapper::AllocateNew(
207207
wrapper->mGroupDataProvider.SetStorageDelegate(wrapperStorage);
208208
wrapper->mGroupDataProvider.SetSessionKeystore(initParams.sessionKeystore);
209209

210-
CommissioningParameters params = wrapper->mAutoCommissioner.GetCommissioningParameters();
210+
CommissioningParameters params = wrapper->GetCommissioningParameters();
211211
params.SetFailsafeTimerSeconds(failsafeTimerSeconds);
212212
params.SetAttemptWiFiNetworkScan(attemptNetworkScanWiFi);
213213
params.SetAttemptThreadNetworkScan(attemptNetworkScanThread);
214214
params.SetSkipCommissioningComplete(skipCommissioningComplete);
215+
216+
if (countryCode != nullptr)
217+
{
218+
JniUtfString countryCodeJniString(env, countryCode);
219+
if (countryCodeJniString.size() != kCountryCodeBufferLen)
220+
{
221+
*errInfoOnFailure = CHIP_ERROR_INVALID_ARGUMENT;
222+
return nullptr;
223+
}
224+
225+
MutableCharSpan copiedCode(wrapper->mCountryCode);
226+
if (CopyCharSpanToMutableCharSpan(countryCodeJniString.charSpan(), copiedCode) != CHIP_NO_ERROR)
227+
{
228+
*errInfoOnFailure = CHIP_ERROR_INVALID_ARGUMENT;
229+
return nullptr;
230+
}
231+
params.SetCountryCode(copiedCode);
232+
}
233+
215234
wrapper->UpdateCommissioningParameters(params);
216235

217236
CHIP_ERROR err = wrapper->mGroupDataProvider.Init();
@@ -526,6 +545,7 @@ CHIP_ERROR AndroidDeviceControllerWrapper::UpdateCommissioningParameters(const c
526545
{
527546
// this will wipe out any custom attestationNonce and csrNonce that was being used.
528547
// however, Android APIs don't allow these to be set to custom values today.
548+
mCommissioningParameter = params;
529549
return mAutoCommissioner.SetCommissioningParameters(params);
530550
}
531551

src/controller/java/AndroidDeviceControllerWrapper.h

+17-15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
constexpr uint8_t kUserActiveModeTriggerInstructionBufferLen =
5252
128 + 1; // 128bytes is max UserActiveModeTriggerInstruction size and 1 byte is for escape sequence.
53+
54+
constexpr uint8_t kCountryCodeBufferLen = 2;
5355
/**
5456
* This class contains all relevant information for the JNI view of CHIPDeviceController
5557
* to handle all controller-related processing.
@@ -123,10 +125,7 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
123125

124126
chip::Credentials::PartialDACVerifier * GetPartialDACVerifier() { return &mPartialDACVerifier; }
125127

126-
const chip::Controller::CommissioningParameters & GetCommissioningParameters() const
127-
{
128-
return mAutoCommissioner.GetCommissioningParameters();
129-
}
128+
const chip::Controller::CommissioningParameters & GetCommissioningParameters() const { return mCommissioningParameter; }
130129

131130
static AndroidDeviceControllerWrapper * FromJNIHandle(jlong handle)
132131
{
@@ -171,20 +170,19 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
171170
* @param[in] skipCommissioningComplete whether to skip the CASE commissioningComplete command during commissioning
172171
* @param[out] errInfoOnFailure a pointer to a CHIP_ERROR that will be populated if this method returns nullptr
173172
*/
174-
static AndroidDeviceControllerWrapper *
175-
AllocateNew(JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId,
176-
const chip::CATValues & cats, chip::System::Layer * systemLayer,
177-
chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
178-
chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
173+
static AndroidDeviceControllerWrapper * AllocateNew(
174+
JavaVM * vm, jobject deviceControllerObj, chip::NodeId nodeId, chip::FabricId fabricId, const chip::CATValues & cats,
175+
chip::System::Layer * systemLayer, chip::Inet::EndPointManager<chip::Inet::TCPEndPoint> * tcpEndPointManager,
176+
chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
179177
#ifdef JAVA_MATTER_CONTROLLER_TEST
180-
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
178+
ExampleOperationalCredentialsIssuerPtr opCredsIssuer,
181179
#else
182-
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
180+
AndroidOperationalCredentialsIssuerPtr opCredsIssuer,
183181
#endif
184-
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
185-
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
186-
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread,
187-
bool skipCommissioningComplete, bool skipAttestationCertificateValidation, CHIP_ERROR * errInfoOnFailure);
182+
jobject keypairDelegate, jbyteArray rootCertificate, jbyteArray intermediateCertificate,
183+
jbyteArray nodeOperationalCertificate, jbyteArray ipkEpochKey, uint16_t listenPort, uint16_t controllerVendorId,
184+
uint16_t failsafeTimerSeconds, bool attemptNetworkScanWiFi, bool attemptNetworkScanThread, bool skipCommissioningComplete,
185+
bool skipAttestationCertificateValidation, jstring countryCode, CHIP_ERROR * errInfoOnFailure);
188186

189187
void Shutdown();
190188

@@ -246,6 +244,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
246244
std::vector<uint8_t> mIcacCertificate;
247245
std::vector<uint8_t> mRcacCertificate;
248246

247+
char mCountryCode[kCountryCodeBufferLen];
248+
249249
chip::Controller::AutoCommissioner mAutoCommissioner;
250250

251251
chip::Credentials::PartialDACVerifier mPartialDACVerifier;
@@ -262,6 +262,8 @@ class AndroidDeviceControllerWrapper : public chip::Controller::DevicePairingDel
262262
chip::MutableCharSpan mUserActiveModeTriggerInstruction = chip::MutableCharSpan(mUserActiveModeTriggerInstructionBuffer);
263263
chip::BitMask<chip::app::Clusters::IcdManagement::UserActiveModeTriggerBitmap> mUserActiveModeTriggerHint;
264264

265+
chip::Controller::CommissioningParameters mCommissioningParameter;
266+
265267
AndroidDeviceControllerWrapper(ChipDeviceControllerPtr controller,
266268
#ifdef JAVA_MATTER_CONTROLLER_TEST
267269
ExampleOperationalCredentialsIssuerPtr opCredsIssuer

src/controller/java/CHIPDeviceController-JNI.cpp

+11-30
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
371371
jobject countryCodeOptional = env->CallObjectMethod(controllerParams, getCountryCode);
372372
jobject regulatoryLocationOptional = env->CallObjectMethod(controllerParams, getRegulatoryLocation);
373373

374+
jobject countryCode;
375+
err = chip::JniReferences::GetInstance().GetOptionalValue(countryCodeOptional, countryCode);
376+
SuccessOrExit(err);
377+
374378
#ifdef JAVA_MATTER_CONTROLLER_TEST
375379
std::unique_ptr<chip::Controller::ExampleOperationalCredentialsIssuer> opCredsIssuer(
376380
new chip::Controller::ExampleOperationalCredentialsIssuer());
@@ -383,7 +387,7 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
383387
DeviceLayer::TCPEndPointManager(), DeviceLayer::UDPEndPointManager(), std::move(opCredsIssuer), keypairDelegate,
384388
rootCertificate, intermediateCertificate, operationalCertificate, ipk, listenPort, controllerVendorId,
385389
failsafeTimerSeconds, attemptNetworkScanWiFi, attemptNetworkScanThread, skipCommissioningComplete,
386-
skipAttestationCertificateValidation, &err);
390+
skipAttestationCertificateValidation, static_cast<jstring>(countryCode), &err);
387391
SuccessOrExit(err);
388392

389393
if (caseFailsafeTimerSeconds > 0)
@@ -411,29 +415,6 @@ JNI_METHOD(jlong, newDeviceController)(JNIEnv * env, jobject self, jobject contr
411415
}
412416
}
413417

414-
jobject countryCode;
415-
err = chip::JniReferences::GetInstance().GetOptionalValue(countryCodeOptional, countryCode);
416-
SuccessOrExit(err);
417-
418-
if (countryCode != nullptr)
419-
{
420-
jstring countryCodeStr = static_cast<jstring>(countryCode);
421-
JniUtfString countryCodeJniString(env, countryCodeStr);
422-
423-
VerifyOrExit(countryCodeJniString.size() == 2, err = CHIP_ERROR_INVALID_ARGUMENT);
424-
425-
chip::Controller::CommissioningParameters commissioningParams = wrapper->GetCommissioningParameters();
426-
commissioningParams.SetCountryCode(countryCodeJniString.charSpan());
427-
428-
// The wrapper internally has reserved storage for the country code and will copy the value.
429-
err = wrapper->UpdateCommissioningParameters(commissioningParams);
430-
if (err != CHIP_NO_ERROR)
431-
{
432-
ChipLogError(Controller, "UpdateCommissioningParameters failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
433-
SuccessOrExit(err);
434-
}
435-
}
436-
437418
jobject regulatoryLocation;
438419
err = chip::JniReferences::GetInstance().GetOptionalValue(regulatoryLocationOptional, regulatoryLocation);
439420
SuccessOrExit(err);
@@ -876,18 +857,18 @@ JNI_METHOD(void, updateCommissioningNetworkCredentials)
876857
chip::DeviceLayer::StackLock lock;
877858
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);
878859

879-
CommissioningParameters commissioningParams = wrapper->GetCommissioningParameters();
860+
CommissioningParameters commissioningParams = wrapper->GetAutoCommissioner()->GetCommissioningParameters();
880861
CHIP_ERROR err = wrapper->ApplyNetworkCredentials(commissioningParams, networkCredentials);
881862
if (err != CHIP_NO_ERROR)
882863
{
883864
ChipLogError(Controller, "ApplyNetworkCredentials failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
884865
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
885866
return;
886867
}
887-
err = wrapper->UpdateCommissioningParameters(commissioningParams);
868+
err = wrapper->GetAutoCommissioner()->SetCommissioningParameters(commissioningParams);
888869
if (err != CHIP_NO_ERROR)
889870
{
890-
ChipLogError(Controller, "UpdateCommissioningParameters failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
871+
ChipLogError(Controller, "SetCommissioningParameters failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
891872
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
892873
return;
893874
}
@@ -911,18 +892,18 @@ JNI_METHOD(void, updateCommissioningICDRegistrationInfo)
911892
chip::DeviceLayer::StackLock lock;
912893
AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle);
913894

914-
CommissioningParameters commissioningParams = wrapper->GetCommissioningParameters();
895+
CommissioningParameters commissioningParams = wrapper->GetAutoCommissioner()->GetCommissioningParameters();
915896
CHIP_ERROR err = wrapper->ApplyICDRegistrationInfo(commissioningParams, icdRegistrationInfo);
916897
if (err != CHIP_NO_ERROR)
917898
{
918899
ChipLogError(Controller, "ApplyICDRegistrationInfo failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
919900
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
920901
return;
921902
}
922-
err = wrapper->UpdateCommissioningParameters(commissioningParams);
903+
err = wrapper->GetAutoCommissioner()->SetCommissioningParameters(commissioningParams);
923904
if (err != CHIP_NO_ERROR)
924905
{
925-
ChipLogError(Controller, "UpdateCommissioningParameters failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
906+
ChipLogError(Controller, "SetCommissioningParameters failed. Err = %" CHIP_ERROR_FORMAT, err.Format());
926907
JniReferences::GetInstance().ThrowError(env, sChipDeviceControllerExceptionCls, err);
927908
return;
928909
}

0 commit comments

Comments
 (0)