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

Feature : Key Refresh procedure #199

Merged
9 commits merged into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0

- expose some of the API needed to execute a Key Refresh Procedure on Android using [this](https://github.com/NordicSemiconductor/Android-nRF-Mesh-Library/pull/381) Pull Request as reference

## 0.4.0

- added a new scanning method where a user may choose the BLE services to look for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,23 @@ class DoozMeshManagerApi(context: Context, binaryMessenger: BinaryMessenger) : S
mMeshManagerApi.createMeshPdu(address, meshMessage)
result.success(null)
}
"keyRefreshPhaseGet" -> {
val address = call.argument<Int>("address")!!
val netKeyIndex = call.argument<Int>("netKeyIndex")!!
val currentMeshNetwork = mMeshManagerApi.meshNetwork!!
val meshMessage: MeshMessage = ConfigKeyRefreshPhaseGet(currentMeshNetwork.netKeys[netKeyIndex])
mMeshManagerApi.createMeshPdu(address, meshMessage)
result.success(null)
}
"keyRefreshPhaseSet" -> {
val address = call.argument<Int>("address")!!
val netKeyIndex = call.argument<Int>("netKeyIndex")!!
val transition = call.argument<Int>("transition")!!
val currentMeshNetwork = mMeshManagerApi.meshNetwork!!
val meshMessage: MeshMessage = ConfigKeyRefreshPhaseSet(currentMeshNetwork.netKeys[netKeyIndex], transition)
mMeshManagerApi.createMeshPdu(address, meshMessage)
result.success(null)
}
"sendConfigModelSubscriptionAdd" -> {
val elementAddress = call.argument<Int>("elementAddress")!!
val subscriptionAddress = call.argument<Int>("subscriptionAddress")!!
Expand Down
69 changes: 69 additions & 0 deletions android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshNetwork.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,75 @@ class DoozMeshNetwork(private val binaryMessenger: BinaryMessenger, var meshNetw
}
result.success(subscribedAddresses)
}
"generateNetKey" -> {
Log.d(tag, "should generate a NetworkKey and return the associated data")
val netKey = meshNetwork.createNetworkKey()
result.success(mapOf(
"name" to netKey.getName(),
"netKeyIndex" to netKey.getKeyIndex(),
"phase" to netKey.getPhase(),
"phaseDescription" to netKey.getPhaseDescription(),
"isMinSecurity" to netKey.isMinSecurity(),
"netKeyBytes" to netKey.getKey(),
"oldNetKeyBytes" to netKey.getOldKey(),
"txNetworkKey" to netKey.getTxNetworkKey(),
"identityKey" to netKey.getIdentityKey(),
"oldIdentityKey" to netKey.getOldIdentityKey(),
"meshUuid" to netKey.getMeshUuid(),
"timestamp" to netKey.getTimestamp()
))
}
"getNetKey" -> {
val netKeyIndex = call.argument<Int>("netKeyIndex")!!
Log.d(tag, "should get NetworkKey at index " + netKeyIndex.toString())
val netKey = meshNetwork.getNetKey(netKeyIndex)
if(null != netKey) {
result.success(mapOf(
"name" to netKey.getName(),
"netKeyIndex" to netKey.getKeyIndex(),
"phase" to netKey.getPhase(),
"phaseDescription" to netKey.getPhaseDescription(),
"isMinSecurity" to netKey.isMinSecurity(),
"netKeyBytes" to netKey.getKey(),
"oldNetKeyBytes" to netKey.getOldKey(),
"txNetworkKey" to netKey.getTxNetworkKey(),
"identityKey" to netKey.getIdentityKey(),
"oldIdentityKey" to netKey.getOldIdentityKey(),
"meshUuid" to netKey.getMeshUuid(),
"timestamp" to netKey.getTimestamp()
))
} else {
result.error("NOT_FOUND", "No Network Key found", "Please check the given index")
}
}
"removeNetKey" -> {
val netKeyIndex = call.argument<Int>("netKeyIndex")!!
Log.d(tag, "should remove NetworkKey at index " + netKeyIndex.toString())
val netKey = meshNetwork.getNetKey(netKeyIndex)
if(null != netKey) {
result.success(meshNetwork.removeNetKey(netKey))
} else {
result.error("NOT_FOUND", "No Network Key found", "Please check the given index")
}
}
"distributeNetKey" -> {
val netKeyIndex = call.argument<Int>("netKeyIndex")!!
Log.d(tag, "should distribute NetworkKey at index " + netKeyIndex.toString())
val netKey = meshNetwork.getNetKey(netKeyIndex)
if(null != netKey) {
val netKeyBytes = netKey.getKey()
val updatedNetKey = meshNetwork.distributeNetKey(netKey, netKeyBytes)
result.success(mapOf(
"meshUuid" to updatedNetKey.getMeshUuid(),
"name" to updatedNetKey.getName(),
"netKeyIndex" to updatedNetKey.getKeyIndex(),
"oldPhase" to netKey.phase,
"phase" to updatedNetKey.phase
))
} else {
result.error("NOT_FOUND", "No Network Key found", "Please check the given index")
}
}
else -> {
result.notImplemented()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ class DoozMeshStatusCallbacks(var eventSink: EventChannel.EventSink?): MeshStatu
))
}
}
is ConfigKeyRefreshPhaseStatus -> {
Log.d(tag, "received a ConfigKeyRefreshPhaseStatus")
Handler(Looper.getMainLooper()).post {
eventSink?.success(mapOf(
"eventName" to "onConfigKeyRefreshPhaseStatus",
"source" to meshMessage.src,
"destination" to meshMessage.dst,
"statusCode" to meshMessage.statusCode,
"statusCodeName" to meshMessage.statusCodeName,
"netKeyIndex" to meshMessage.netKeyIndex,
"transition" to meshMessage.transition
))
}
}
else -> {
Log.d(tag, "Unknown message received :" + meshMessage.javaClass.toString())
}
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.0"
version: "0.5.0"
package_config:
dependency: transitive
description:
Expand Down
2 changes: 0 additions & 2 deletions lib/nordic_nrf_mesh.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export 'src/nrf_mesh.dart';
export 'src/mesh_network.dart' show IMeshNetwork;
export 'src/mesh_manager_api.dart';
export 'src/provisioned_mesh_node.dart';
export 'src/unprovisioned_mesh_node.dart';
export 'src/events/data/event_data.dart';
export 'src/models/models.dart';
export 'src/ble/ble_manager.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'config_key_refresh_phase_status.freezed.dart';
part 'config_key_refresh_phase_status.g.dart';

@freezed
class ConfigKeyRefreshPhaseStatus with _$ConfigKeyRefreshPhaseStatus {
const factory ConfigKeyRefreshPhaseStatus(
int source,
int destination,
int statusCode,
String statusCodeName,
int netKeyIndex,
int transition,
) = _ConfigKeyRefreshPhaseStatus;

factory ConfigKeyRefreshPhaseStatus.fromJson(Map<String, dynamic> json) =>
_$ConfigKeyRefreshPhaseStatusFromJson(json);
}
Loading