Skip to content

Commit b8303e7

Browse files
Merge pull request #621 from NordicSemiconductor/bugfix/invalid-configuration-failed-message
Handle initial configuration steps correctly
2 parents 417968a + 29562ac commit b8303e7

10 files changed

Lines changed: 115 additions & 105 deletions

File tree

app/src/main/java/no/nordicsemi/android/nrfmesh/MainActivity.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
7474
// setTheme, this is preferred in our case, as this also work for older platforms.
7575
setTheme(R.style.AppTheme);
7676
super.onCreate(savedInstanceState);
77-
EdgeToEdge.enable(this,
78-
SystemBarStyle.dark(Color.TRANSPARENT),
79-
SystemBarStyle.light(
80-
ContextCompat.getColor(this, R.color.colorSurfaceContain),
81-
ContextCompat.getColor(this, R.color.colorSurfaceContain)
82-
)
83-
);
77+
EdgeToEdge.enable(this);
8478
mViewModel = new ViewModelProvider(this).get(SharedViewModel.class);
8579

8680
// Set up the splash screen.

app/src/main/java/no/nordicsemi/android/nrfmesh/NetworkFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ private void handleActivityResult(final ActivityResult result) {
181181
final boolean compositionDataReceived = data.getBooleanExtra(Utils.COMPOSITION_DATA_COMPLETED, false);
182182
final boolean defaultTtlGetCompleted = data.getBooleanExtra(Utils.DEFAULT_GET_COMPLETED, false);
183183
final boolean appKeyAddCompleted = data.getBooleanExtra(Utils.APP_KEY_ADD_COMPLETED, false);
184-
final boolean networkRetransmitSetCompleted = data.getBooleanExtra(Utils.NETWORK_TRANSMIT_SET_COMPLETED, false);
184+
// final boolean networkRetransmitSetCompleted = data.getBooleanExtra(Utils.NETWORK_TRANSMIT_SET_COMPLETED, false);
185185
final String title = getString(R.string.title_init_config_error);
186186
final String message;
187187
if (compositionDataReceived) {
188188
if (defaultTtlGetCompleted) {
189189
if (appKeyAddCompleted) {
190-
if (!networkRetransmitSetCompleted) {
191-
message = getString(R.string.init_config_error_app_key_msg);
192-
showErrorDialog(title, message);
193-
}
190+
// if (!networkRetransmitSetCompleted) {
191+
// message = getString(R.string.init_config_error_app_key_msg);
192+
// showErrorDialog(title, message);
193+
// }
194194
} else {
195195
message = getString(R.string.init_config_error_app_key_msg);
196196
showErrorDialog(title, message);

app/src/main/java/no/nordicsemi/android/nrfmesh/ProvisioningActivity.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@ public void setupProvisionerStateObservers() {
358358
if (fragment != null)
359359
fragment.dismiss();
360360
break;
361+
case DEFAULT_TTL_STATUS_RECEIVED:
362+
if (mViewModel.isDefaultTtlReceived()) {
363+
if(mViewModel.getNetworkLiveData().getAppKeys().isEmpty()){
364+
if (getSupportFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_CONFIGURATION_STATUS) == null) {
365+
DialogFragmentConfigurationComplete fragmentConfigComplete = DialogFragmentConfigurationComplete.
366+
newInstance(getString(R.string.title_configuration_compete), getString(R.string.configuration_complete_summary));
367+
fragmentConfigComplete.show(getSupportFragmentManager(), DIALOG_FRAGMENT_CONFIGURATION_STATUS);
368+
}
369+
}
370+
}
371+
break;
361372
case APP_KEY_STATUS_RECEIVED:
362373
if (getSupportFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_CONFIGURATION_STATUS) == null) {
363374
DialogFragmentConfigurationComplete fragmentConfigComplete = DialogFragmentConfigurationComplete.
@@ -397,11 +408,14 @@ private void setResultIntent() {
397408
returnIntent.putExtra(Utils.COMPOSITION_DATA_COMPLETED, true);
398409
if (mViewModel.isDefaultTtlReceived()) {
399410
returnIntent.putExtra(Utils.DEFAULT_GET_COMPLETED, true);
400-
if (mViewModel.isNetworkRetransmitSetCompleted()) {
401-
returnIntent.putExtra(Utils.NETWORK_TRANSMIT_SET_COMPLETED, true);
402-
if (mViewModel.getNetworkLiveData().getMeshNetwork().getAppKeys().isEmpty() || mViewModel.isAppKeyAddCompleted()) {
403-
returnIntent.putExtra(Utils.APP_KEY_ADD_COMPLETED, true);
404-
}
411+
// if (mViewModel.isNetworkRetransmitSetCompleted()) {
412+
// returnIntent.putExtra(Utils.NETWORK_TRANSMIT_SET_COMPLETED, true);
413+
// if (mViewModel.getNetworkLiveData().getMeshNetwork().getAppKeys().isEmpty() || mViewModel.isAppKeyAddCompleted()) {
414+
// returnIntent.putExtra(Utils.APP_KEY_ADD_COMPLETED, true);
415+
// }
416+
// }
417+
if (mViewModel.getNetworkLiveData().getMeshNetwork().getAppKeys().isEmpty() || mViewModel.isAppKeyAddCompleted()) {
418+
returnIntent.putExtra(Utils.APP_KEY_ADD_COMPLETED, true);
405419
}
406420
}
407421
}

app/src/main/java/no/nordicsemi/android/nrfmesh/utils/ProvisionerStates.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public enum ProvisionerStates {
2626
DEFAULT_TTL_STATUS_RECEIVED(21),
2727
SENDING_APP_KEY_ADD(22),
2828
APP_KEY_STATUS_RECEIVED(23),
29-
SENDING_NETWORK_TRANSMIT_SET(24),
30-
NETWORK_TRANSMIT_STATUS_RECEIVED(25),
3129
SENDING_BLOCK_ACKNOWLEDGEMENT(98),
3230
BLOCK_ACKNOWLEDGEMENT_RECEIVED(99),
3331
PROVISIONER_UNASSIGNED(100);

app/src/main/java/no/nordicsemi/android/nrfmesh/utils/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class Utils {
6262
public static final String COMPOSITION_DATA_COMPLETED = "COMPOSITION_DATA_COMPLETED";
6363
public static final String DEFAULT_GET_COMPLETED = "DEFAULT_GET_COMPLETED";
6464
public static final String APP_KEY_ADD_COMPLETED = "APP_KEY_ADD_COMPLETED";
65-
public static final String NETWORK_TRANSMIT_SET_COMPLETED = "NETWORK_TRANSMIT_SET_COMPLETED";
65+
// public static final String NETWORK_TRANSMIT_SET_COMPLETED = "NETWORK_TRANSMIT_SET_COMPLETED";
6666
public static final String EXTRA_DATA = "EXTRA_DATA";
6767
private static final String PREFS_LOCATION_NOT_REQUIRED = "location_not_required";
6868
private static final String PREFS_PERMISSION_REQUESTED = "permission_requested";

app/src/main/java/no/nordicsemi/android/nrfmesh/viewmodels/NrfMeshRepository.java

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_MODEL_APP_STATUS;
1414
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_MODEL_PUBLICATION_STATUS;
1515
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_MODEL_SUBSCRIPTION_STATUS;
16+
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_NETWORK_TRANSMIT_STATUS;
1617
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_NODE_RESET_STATUS;
1718
import static no.nordicsemi.android.mesh.opcodes.ConfigMessageOpCodes.CONFIG_RELAY_STATUS;
1819
import static no.nordicsemi.android.nrfmesh.ble.BleMeshManager.MESH_PROXY_UUID;
@@ -62,6 +63,7 @@
6263
import no.nordicsemi.android.mesh.transport.ConfigModelAppStatus;
6364
import no.nordicsemi.android.mesh.transport.ConfigModelPublicationStatus;
6465
import no.nordicsemi.android.mesh.transport.ConfigModelSubscriptionStatus;
66+
import no.nordicsemi.android.mesh.transport.ConfigNetworkTransmitStatus;
6567
import no.nordicsemi.android.mesh.transport.ConfigNodeResetStatus;
6668
import no.nordicsemi.android.mesh.transport.ConfigRelayStatus;
6769
import no.nordicsemi.android.mesh.transport.ControlMessage;
@@ -766,39 +768,58 @@ public void onMeshMessageReceived(final int src, @NonNull final MeshMessage mesh
766768
}
767769
} else if (meshMessage.getOpCode() == CONFIG_DEFAULT_TTL_STATUS) {
768770
final ConfigDefaultTtlStatus status = (ConfigDefaultTtlStatus) meshMessage;
769-
/* if (mSetupProvisionedNode) {
771+
if (mSetupProvisionedNode) {
770772
mIsDefaultTtlReceived = true;
773+
if(mMeshNetworkLiveData.getAppKeys().isEmpty()){
774+
mSetupProvisionedNode = false;
775+
}
771776
mProvisionedMeshNodeLiveData.postValue(node);
772777
mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.DEFAULT_TTL_STATUS_RECEIVED);
773-
mHandler.postDelayed(() -> {
774-
final ConfigNetworkTransmitSet networkTransmitSet = new ConfigNetworkTransmitSet(2, 1);
775-
mMeshManagerApi.createMeshPdu(node.getUnicastAddress(), networkTransmitSet);
776-
}, 1500);
777-
} else {
778-
updateNode(node);
779-
mMeshMessageLiveData.postValue(status);
780-
}
781-
} else if (meshMessage.getOpCode() == CONFIG_NETWORK_TRANSMIT_STATUS) {
782-
final ConfigNetworkTransmitStatus status = (ConfigNetworkTransmitStatus) meshMessage;*/
783-
if (mSetupProvisionedNode) {
784-
mIsNetworkRetransmitSetCompleted = true;
785-
mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.NETWORK_TRANSMIT_STATUS_RECEIVED);
786-
final ApplicationKey appKey = mMeshNetworkLiveData.getSelectedAppKey();
787-
if (appKey != null) {
788-
mHandler.postDelayed(() -> {
789-
// We should use the app key's boundNetKeyIndex as the network key index when adding the default app key
790-
final NetworkKey networkKey = mMeshNetwork.getNetKeys().get(appKey.getBoundNetKeyIndex());
791-
final ConfigAppKeyAdd configAppKeyAdd = new ConfigAppKeyAdd(networkKey, appKey);
792-
mMeshManagerApi.createMeshPdu(node.getUnicastAddress(), configAppKeyAdd);
793-
}, 1500);
794-
} else {
795-
mSetupProvisionedNode = false;
796-
mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.APP_KEY_STATUS_RECEIVED);
778+
//mHandler.postDelayed(() -> {
779+
// final ConfigNetworkTransmitSet networkTransmitSet = new ConfigNetworkTransmitSet(2, 1);
780+
// mMeshManagerApi.createMeshPdu(node.getUnicastAddress(), networkTransmitSet);
781+
//}, 1500);
782+
if(!mMeshNetworkLiveData.getAppKeys().isEmpty()) {
783+
final ApplicationKey appKey = mMeshNetworkLiveData.getSelectedAppKey();
784+
if (appKey != null) {
785+
mHandler.postDelayed(() -> {
786+
// We should use the app key's boundNetKeyIndex as the network key index when adding the default app key
787+
final NetworkKey networkKey = mMeshNetwork.getNetKeys().get(appKey.getBoundNetKeyIndex());
788+
final ConfigAppKeyAdd configAppKeyAdd = new ConfigAppKeyAdd(networkKey, appKey);
789+
mMeshManagerApi.createMeshPdu(node.getUnicastAddress(), configAppKeyAdd);
790+
}, 1500);
791+
} else {
792+
mSetupProvisionedNode = false;
793+
mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.APP_KEY_STATUS_RECEIVED);
794+
}
797795
}
798796
} else {
799797
updateNode(node);
800798
mMeshMessageLiveData.postValue(status);
801799
}
800+
} else if (meshMessage.getOpCode() == CONFIG_NETWORK_TRANSMIT_STATUS) {
801+
final ConfigNetworkTransmitStatus status = (ConfigNetworkTransmitStatus) meshMessage;
802+
//if (mSetupProvisionedNode) {
803+
// mIsNetworkRetransmitSetCompleted = true;
804+
// mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.NETWORK_TRANSMIT_STATUS_RECEIVED);
805+
// final ApplicationKey appKey = mMeshNetworkLiveData.getSelectedAppKey();
806+
// if (appKey != null) {
807+
// mHandler.postDelayed(() -> {
808+
// // We should use the app key's boundNetKeyIndex as the network key index when adding the default app key
809+
// final NetworkKey networkKey = mMeshNetwork.getNetKeys().get(appKey.getBoundNetKeyIndex());
810+
// final ConfigAppKeyAdd configAppKeyAdd = new ConfigAppKeyAdd(networkKey, appKey);
811+
// mMeshManagerApi.createMeshPdu(node.getUnicastAddress(), configAppKeyAdd);
812+
// }, 1500);
813+
// } else {
814+
// mSetupProvisionedNode = false;
815+
// mProvisioningStateLiveData.onMeshNodeStateUpdated(ProvisionerStates.APP_KEY_STATUS_RECEIVED);
816+
// }
817+
//} else {
818+
// updateNode(node);
819+
// mMeshMessageLiveData.postValue(status);
820+
//}
821+
updateNode(node);
822+
mMeshMessageLiveData.postValue(status);
802823
} else if (meshMessage.getOpCode() == CONFIG_APPKEY_STATUS) {
803824
final ConfigAppKeyStatus status = (ConfigAppKeyStatus) meshMessage;
804825
if (mSetupProvisionedNode) {

app/src/main/java/no/nordicsemi/android/nrfmesh/viewmodels/ProvisioningStatusLiveData.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void onMeshNodeStateUpdated(final ProvisionerStates state) {
127127
mProvisioningProgress.add(provisioningProgress);
128128
break;
129129
case DEFAULT_TTL_STATUS_RECEIVED:
130-
provisioningProgress = new ProvisionerProgress(state, "Default TTL status received...", R.drawable.ic_arrow_forward);
130+
provisioningProgress = new ProvisionerProgress(state, "Default TTL status received...", R.drawable.ic_arrow_back);
131131
mProvisioningProgress.add(provisioningProgress);
132132
break;
133133
case SENDING_APP_KEY_ADD:
@@ -138,14 +138,6 @@ void onMeshNodeStateUpdated(final ProvisionerStates state) {
138138
provisioningProgress = new ProvisionerProgress(state, "App key status received...", R.drawable.ic_arrow_forward);
139139
mProvisioningProgress.add(provisioningProgress);
140140
break;
141-
case SENDING_NETWORK_TRANSMIT_SET:
142-
provisioningProgress = new ProvisionerProgress(state, "Sending network transmit set...", R.drawable.ic_arrow_forward);
143-
mProvisioningProgress.add(provisioningProgress);
144-
break;
145-
case NETWORK_TRANSMIT_STATUS_RECEIVED:
146-
provisioningProgress = new ProvisionerProgress(state, "Network transmit status received...", R.drawable.ic_arrow_forward);
147-
mProvisioningProgress.add(provisioningProgress);
148-
break;
149141
case SENDING_BLOCK_ACKNOWLEDGEMENT:
150142
provisioningProgress = new ProvisionerProgress(state, "Sending block acknowledgements", R.drawable.ic_arrow_forward);
151143
mProvisioningProgress.add(provisioningProgress);

mesh/src/main/java/no/nordicsemi/android/mesh/provisionerstates/ProvisioningDataState.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,22 @@ private void sendProvisioningData() {
8888
private byte[] createProvisioningDataPDU() {
8989

9090
final byte[] provisioningSalt = generateProvisioningSalt();
91-
MeshLogger.verbose(TAG, "Provisioning salt: " + MeshParserUtils.bytesToHex(provisioningSalt, false));
9291

9392
final byte[] ecdh = mUnprovisionedMeshNode.getSharedECDHSecret();
9493

9594
final byte[] t = SecureUtils.calculateCMAC(ecdh, provisioningSalt);
9695
/* Calculating the session key */
9796
final byte[] sessionKey = SecureUtils.calculateCMAC(SecureUtils.PRSK, t);
98-
MeshLogger.verbose(TAG, "Session key: " + MeshParserUtils.bytesToHex(sessionKey, false));
9997

10098
/* Calculate the Session nonce */
10199
final byte[] sessionNonce = generateSessionNonce(ecdh, provisioningSalt);
102-
MeshLogger.verbose(TAG, "Session nonce: " + MeshParserUtils.bytesToHex(sessionNonce, false));
103100

104101
/* Calculate the Device key */
105102
final byte[] deviceKey = SecureUtils.calculateCMAC(SecureUtils.PRDK, t);
106-
MeshLogger.verbose(TAG, "Device key: " + MeshParserUtils.bytesToHex(deviceKey, false));
107103
mUnprovisionedMeshNode.setDeviceKey(deviceKey);
108104

109105
/* Generate 16 byte Random network key */
110106
final byte[] networkKey = mUnprovisionedMeshNode.getNetworkKey();
111-
MeshLogger.verbose(TAG, "Network key: " + MeshParserUtils.bytesToHex(networkKey, false));
112107

113108
/* Generate random 2 byte Key index*/
114109
final byte[] keyIndex = MeshParserUtils.addKeyIndexPadding(mUnprovisionedMeshNode.getKeyIndex());

0 commit comments

Comments
 (0)