diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e8b45c9d..b93f8e607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 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 +- allow to choose the name of a provisioner when asking to create one using `IMeshNetwork.addProvisioner` method (defaults to `'DooZ Mesh Provisioner'`) + ## 0.4.0 - added a new scanning method where a user may choose the BLE services to look for diff --git a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshManagerApi.kt b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshManagerApi.kt index ad84ed988..b1784b29f 100644 --- a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshManagerApi.kt +++ b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshManagerApi.kt @@ -206,6 +206,23 @@ class DoozMeshManagerApi(context: Context, binaryMessenger: BinaryMessenger) : S mMeshManagerApi.createMeshPdu(address, meshMessage) result.success(null) } + "keyRefreshPhaseGet" -> { + val address = call.argument("address")!! + val netKeyIndex = call.argument("netKeyIndex")!! + val currentMeshNetwork = mMeshManagerApi.meshNetwork!! + val meshMessage: MeshMessage = ConfigKeyRefreshPhaseGet(currentMeshNetwork.netKeys[netKeyIndex]) + mMeshManagerApi.createMeshPdu(address, meshMessage) + result.success(null) + } + "keyRefreshPhaseSet" -> { + val address = call.argument("address")!! + val netKeyIndex = call.argument("netKeyIndex")!! + val transition = call.argument("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("elementAddress")!! val subscriptionAddress = call.argument("subscriptionAddress")!! diff --git a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshNetwork.kt b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshNetwork.kt index c98511239..33ef22e14 100644 --- a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshNetwork.kt +++ b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshNetwork.kt @@ -190,6 +190,7 @@ class DoozMeshNetwork(private val binaryMessenger: BinaryMessenger, var meshNetw result.success(maxAddress) } "addProvisioner" -> { + val name = call.argument("name")!! val unicastAddressRange = call.argument("unicastAddressRange")!! val groupAddressRange = call.argument("groupAddressRange")!! val sceneAddressRange = call.argument("sceneAddressRange")!! @@ -199,7 +200,7 @@ class DoozMeshNetwork(private val binaryMessenger: BinaryMessenger, var meshNetw val unicastRange: AllocatedUnicastRange = meshNetwork.nextAvailableUnicastAddressRange(unicastAddressRange) val groupRange: AllocatedGroupRange = meshNetwork.nextAvailableGroupAddressRange(groupAddressRange) val sceneRange: AllocatedSceneRange = meshNetwork.nextAvailableSceneAddressRange(sceneAddressRange)!! - val provisioner: Provisioner = meshNetwork.createProvisioner("DOOZ Mesh Provisioner", + val provisioner: Provisioner = meshNetwork.createProvisioner(name, unicastRange, groupRange, sceneRange) val unicastId = provisioner.allocatedUnicastRanges[0].lowAddress @@ -291,6 +292,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("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("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("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() } diff --git a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshStatusCallbacks.kt b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshStatusCallbacks.kt index fc9c6af57..37b07a644 100644 --- a/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshStatusCallbacks.kt +++ b/android/src/main/kotlin/fr/dooz/nordic_nrf_mesh/DoozMeshStatusCallbacks.kt @@ -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()) } diff --git a/example/lib/src/views/control_module/model.dart b/example/lib/src/views/control_module/model.dart index d71c6c2b0..9121d47db 100644 --- a/example/lib/src/views/control_module/model.dart +++ b/example/lib/src/views/control_module/model.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; class Model extends StatelessWidget { diff --git a/example/lib/src/views/control_module/node.dart b/example/lib/src/views/control_module/node.dart index 5b31759b3..385bc1a5e 100644 --- a/example/lib/src/views/control_module/node.dart +++ b/example/lib/src/views/control_module/node.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; import '../../data/board_data.dart'; diff --git a/example/pubspec.lock b/example/pubspec.lock index 25a138101..4cd9ea8b5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -326,7 +326,7 @@ packages: path: ".." relative: true source: path - version: "0.4.0" + version: "0.5.0" package_config: dependency: transitive description: diff --git a/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift b/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift index bca0dc349..7ee3109f4 100644 --- a/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift +++ b/ios/Classes/DoozMeshNetwork/DoozMeshNetwork.swift @@ -271,11 +271,12 @@ private extension DoozMeshNetwork { do { let provisionerUUID = UUID() + let name = String(data.name) let nextAvailableUnicastAddressRange = meshNetwork.nextAvailableUnicastAddressRange(ofSize: UInt16(data.unicastAddressRange))! let nextAvailableGroupAddressRange = meshNetwork.nextAvailableGroupAddressRange(ofSize: UInt16(data.groupAddressRange))! let nextAvailableSceneRange = meshNetwork.nextAvailableSceneRange(ofSize: UInt16(data.sceneAddressRange))! - let mProvisioner = Provisioner.init(name: UIDevice.current.name, uuid: provisionerUUID, allocatedUnicastRange: [nextAvailableUnicastAddressRange], allocatedGroupRange: [nextAvailableGroupAddressRange], allocatedSceneRange: [nextAvailableSceneRange]) + let mProvisioner = Provisioner.init(name: name, uuid: provisionerUUID, allocatedUnicastRange: [nextAvailableUnicastAddressRange], allocatedGroupRange: [nextAvailableGroupAddressRange], allocatedSceneRange: [nextAvailableSceneRange]) try meshNetwork.add(provisioner: mProvisioner) diff --git a/lib/nordic_nrf_mesh.dart b/lib/nordic_nrf_mesh.dart index 8f62691a5..070f55f7e 100644 --- a/lib/nordic_nrf_mesh.dart +++ b/lib/nordic_nrf_mesh.dart @@ -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'; diff --git a/lib/src/ble/ble_manager.dart b/lib/src/ble/ble_manager.dart index bbfebc932..6eec6c9b3 100644 --- a/lib/src/ble/ble_manager.dart +++ b/lib/src/ble/ble_manager.dart @@ -5,7 +5,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:meta/meta.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; -import 'package:nordic_nrf_mesh/src/ble/ble_manager_callbacks.dart'; const mtuSizeMax = 517; const maxPacketSize = 20; diff --git a/lib/src/ble/ble_mesh_manager.dart b/lib/src/ble/ble_mesh_manager.dart index ad705885f..e7e34fd54 100644 --- a/lib/src/ble/ble_mesh_manager.dart +++ b/lib/src/ble/ble_mesh_manager.dart @@ -6,8 +6,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; -import 'package:nordic_nrf_mesh/src/ble/ble_manager.dart'; -import 'package:nordic_nrf_mesh/src/ble/ble_mesh_manager_callbacks.dart'; import 'package:retry/retry.dart'; class BleMeshManager extends BleManager { diff --git a/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.dart b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.dart new file mode 100644 index 000000000..cd8ef144b --- /dev/null +++ b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.dart @@ -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 json) => + _$ConfigKeyRefreshPhaseStatusFromJson(json); +} diff --git a/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.freezed.dart b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.freezed.dart new file mode 100644 index 000000000..4fa91c187 --- /dev/null +++ b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.freezed.dart @@ -0,0 +1,256 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'config_key_refresh_phase_status.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ConfigKeyRefreshPhaseStatus _$ConfigKeyRefreshPhaseStatusFromJson(Map json) { + return _ConfigKeyRefreshPhaseStatus.fromJson(json); +} + +/// @nodoc +class _$ConfigKeyRefreshPhaseStatusTearOff { + const _$ConfigKeyRefreshPhaseStatusTearOff(); + + _ConfigKeyRefreshPhaseStatus call( + int source, int destination, int statusCode, String statusCodeName, int netKeyIndex, int transition) { + return _ConfigKeyRefreshPhaseStatus( + source, + destination, + statusCode, + statusCodeName, + netKeyIndex, + transition, + ); + } + + ConfigKeyRefreshPhaseStatus fromJson(Map json) { + return ConfigKeyRefreshPhaseStatus.fromJson(json); + } +} + +/// @nodoc +const $ConfigKeyRefreshPhaseStatus = _$ConfigKeyRefreshPhaseStatusTearOff(); + +/// @nodoc +mixin _$ConfigKeyRefreshPhaseStatus { + int get source => throw _privateConstructorUsedError; + int get destination => throw _privateConstructorUsedError; + int get statusCode => throw _privateConstructorUsedError; + String get statusCodeName => throw _privateConstructorUsedError; + int get netKeyIndex => throw _privateConstructorUsedError; + int get transition => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ConfigKeyRefreshPhaseStatusCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ConfigKeyRefreshPhaseStatusCopyWith<$Res> { + factory $ConfigKeyRefreshPhaseStatusCopyWith( + ConfigKeyRefreshPhaseStatus value, $Res Function(ConfigKeyRefreshPhaseStatus) then) = + _$ConfigKeyRefreshPhaseStatusCopyWithImpl<$Res>; + $Res call({int source, int destination, int statusCode, String statusCodeName, int netKeyIndex, int transition}); +} + +/// @nodoc +class _$ConfigKeyRefreshPhaseStatusCopyWithImpl<$Res> implements $ConfigKeyRefreshPhaseStatusCopyWith<$Res> { + _$ConfigKeyRefreshPhaseStatusCopyWithImpl(this._value, this._then); + + final ConfigKeyRefreshPhaseStatus _value; + // ignore: unused_field + final $Res Function(ConfigKeyRefreshPhaseStatus) _then; + + @override + $Res call({ + Object? source = freezed, + Object? destination = freezed, + Object? statusCode = freezed, + Object? statusCodeName = freezed, + Object? netKeyIndex = freezed, + Object? transition = freezed, + }) { + return _then(_value.copyWith( + source: source == freezed + ? _value.source + : source // ignore: cast_nullable_to_non_nullable + as int, + destination: destination == freezed + ? _value.destination + : destination // ignore: cast_nullable_to_non_nullable + as int, + statusCode: statusCode == freezed + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + statusCodeName: statusCodeName == freezed + ? _value.statusCodeName + : statusCodeName // ignore: cast_nullable_to_non_nullable + as String, + netKeyIndex: netKeyIndex == freezed + ? _value.netKeyIndex + : netKeyIndex // ignore: cast_nullable_to_non_nullable + as int, + transition: transition == freezed + ? _value.transition + : transition // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +abstract class _$ConfigKeyRefreshPhaseStatusCopyWith<$Res> implements $ConfigKeyRefreshPhaseStatusCopyWith<$Res> { + factory _$ConfigKeyRefreshPhaseStatusCopyWith( + _ConfigKeyRefreshPhaseStatus value, $Res Function(_ConfigKeyRefreshPhaseStatus) then) = + __$ConfigKeyRefreshPhaseStatusCopyWithImpl<$Res>; + @override + $Res call({int source, int destination, int statusCode, String statusCodeName, int netKeyIndex, int transition}); +} + +/// @nodoc +class __$ConfigKeyRefreshPhaseStatusCopyWithImpl<$Res> extends _$ConfigKeyRefreshPhaseStatusCopyWithImpl<$Res> + implements _$ConfigKeyRefreshPhaseStatusCopyWith<$Res> { + __$ConfigKeyRefreshPhaseStatusCopyWithImpl( + _ConfigKeyRefreshPhaseStatus _value, $Res Function(_ConfigKeyRefreshPhaseStatus) _then) + : super(_value, (v) => _then(v as _ConfigKeyRefreshPhaseStatus)); + + @override + _ConfigKeyRefreshPhaseStatus get _value => super._value as _ConfigKeyRefreshPhaseStatus; + + @override + $Res call({ + Object? source = freezed, + Object? destination = freezed, + Object? statusCode = freezed, + Object? statusCodeName = freezed, + Object? netKeyIndex = freezed, + Object? transition = freezed, + }) { + return _then(_ConfigKeyRefreshPhaseStatus( + source == freezed + ? _value.source + : source // ignore: cast_nullable_to_non_nullable + as int, + destination == freezed + ? _value.destination + : destination // ignore: cast_nullable_to_non_nullable + as int, + statusCode == freezed + ? _value.statusCode + : statusCode // ignore: cast_nullable_to_non_nullable + as int, + statusCodeName == freezed + ? _value.statusCodeName + : statusCodeName // ignore: cast_nullable_to_non_nullable + as String, + netKeyIndex == freezed + ? _value.netKeyIndex + : netKeyIndex // ignore: cast_nullable_to_non_nullable + as int, + transition == freezed + ? _value.transition + : transition // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ConfigKeyRefreshPhaseStatus implements _ConfigKeyRefreshPhaseStatus { + const _$_ConfigKeyRefreshPhaseStatus( + this.source, this.destination, this.statusCode, this.statusCodeName, this.netKeyIndex, this.transition); + + factory _$_ConfigKeyRefreshPhaseStatus.fromJson(Map json) => + _$_$_ConfigKeyRefreshPhaseStatusFromJson(json); + + @override + final int source; + @override + final int destination; + @override + final int statusCode; + @override + final String statusCodeName; + @override + final int netKeyIndex; + @override + final int transition; + + @override + String toString() { + return 'ConfigKeyRefreshPhaseStatus(source: $source, destination: $destination, statusCode: $statusCode, statusCodeName: $statusCodeName, netKeyIndex: $netKeyIndex, transition: $transition)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _ConfigKeyRefreshPhaseStatus && + (identical(other.source, source) || const DeepCollectionEquality().equals(other.source, source)) && + (identical(other.destination, destination) || + const DeepCollectionEquality().equals(other.destination, destination)) && + (identical(other.statusCode, statusCode) || + const DeepCollectionEquality().equals(other.statusCode, statusCode)) && + (identical(other.statusCodeName, statusCodeName) || + const DeepCollectionEquality().equals(other.statusCodeName, statusCodeName)) && + (identical(other.netKeyIndex, netKeyIndex) || + const DeepCollectionEquality().equals(other.netKeyIndex, netKeyIndex)) && + (identical(other.transition, transition) || + const DeepCollectionEquality().equals(other.transition, transition))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(source) ^ + const DeepCollectionEquality().hash(destination) ^ + const DeepCollectionEquality().hash(statusCode) ^ + const DeepCollectionEquality().hash(statusCodeName) ^ + const DeepCollectionEquality().hash(netKeyIndex) ^ + const DeepCollectionEquality().hash(transition); + + @JsonKey(ignore: true) + @override + _$ConfigKeyRefreshPhaseStatusCopyWith<_ConfigKeyRefreshPhaseStatus> get copyWith => + __$ConfigKeyRefreshPhaseStatusCopyWithImpl<_ConfigKeyRefreshPhaseStatus>(this, _$identity); + + @override + Map toJson() { + return _$_$_ConfigKeyRefreshPhaseStatusToJson(this); + } +} + +abstract class _ConfigKeyRefreshPhaseStatus implements ConfigKeyRefreshPhaseStatus { + const factory _ConfigKeyRefreshPhaseStatus( + int source, int destination, int statusCode, String statusCodeName, int netKeyIndex, int transition) = + _$_ConfigKeyRefreshPhaseStatus; + + factory _ConfigKeyRefreshPhaseStatus.fromJson(Map json) = _$_ConfigKeyRefreshPhaseStatus.fromJson; + + @override + int get source => throw _privateConstructorUsedError; + @override + int get destination => throw _privateConstructorUsedError; + @override + int get statusCode => throw _privateConstructorUsedError; + @override + String get statusCodeName => throw _privateConstructorUsedError; + @override + int get netKeyIndex => throw _privateConstructorUsedError; + @override + int get transition => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$ConfigKeyRefreshPhaseStatusCopyWith<_ConfigKeyRefreshPhaseStatus> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.g.dart b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.g.dart new file mode 100644 index 000000000..f08d794d0 --- /dev/null +++ b/lib/src/events/data/config_key_refresh_phase_status/config_key_refresh_phase_status.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'config_key_refresh_phase_status.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ConfigKeyRefreshPhaseStatus _$_$_ConfigKeyRefreshPhaseStatusFromJson(Map json) { + return _$_ConfigKeyRefreshPhaseStatus( + json['source'] as int, + json['destination'] as int, + json['statusCode'] as int, + json['statusCodeName'] as String, + json['netKeyIndex'] as int, + json['transition'] as int, + ); +} + +Map _$_$_ConfigKeyRefreshPhaseStatusToJson(_$_ConfigKeyRefreshPhaseStatus instance) => + { + 'source': instance.source, + 'destination': instance.destination, + 'statusCode': instance.statusCode, + 'statusCodeName': instance.statusCodeName, + 'netKeyIndex': instance.netKeyIndex, + 'transition': instance.transition, + }; diff --git a/lib/src/events/data/event_data.dart b/lib/src/events/data/event_data.dart index 6956159a3..5439c921e 100644 --- a/lib/src/events/data/event_data.dart +++ b/lib/src/events/data/event_data.dart @@ -1,6 +1,7 @@ export 'config_app_key_status/config_app_key_status.dart'; export 'config_composition_data_status/config_composition_data_status.dart'; export 'config_default_ttl_status/config_default_ttl_status.dart'; +export 'config_key_refresh_phase_status/config_key_refresh_phase_status.dart'; export 'config_model_app_status/config_model_app_status.dart'; export 'config_model_publication_status/config_model_publication_status.dart'; export 'config_model_subscription_status/config_model_subscription_status.dart'; diff --git a/lib/src/events/data/send_provisioning_pdu/send_provisioning_pdu.dart b/lib/src/events/data/send_provisioning_pdu/send_provisioning_pdu.dart index ca33a17c5..0cca78b8c 100644 --- a/lib/src/events/data/send_provisioning_pdu/send_provisioning_pdu.dart +++ b/lib/src/events/data/send_provisioning_pdu/send_provisioning_pdu.dart @@ -1,5 +1,5 @@ import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:nordic_nrf_mesh/src/unprovisioned_mesh_node.dart'; +import 'package:nordic_nrf_mesh/src/models/models.dart'; part 'send_provisioning_pdu.freezed.dart'; part 'send_provisioning_pdu.g.dart'; diff --git a/lib/src/events/mesh_manager_api_events.dart b/lib/src/events/mesh_manager_api_events.dart index 1ac855473..5f3e8cf5b 100644 --- a/lib/src/events/mesh_manager_api_events.dart +++ b/lib/src/events/mesh_manager_api_events.dart @@ -43,4 +43,5 @@ class MeshManagerApiEvent { static const configNodeResetStatus = MeshManagerApiEvent._('onConfigNodeResetStatus'); static const configNetworkTransmitStatus = MeshManagerApiEvent._('onConfigNetworkTransmitStatus'); static const configDefaultTtlStatus = MeshManagerApiEvent._('onConfigDefaultTtlStatus'); + static const configKeyRefreshPhaseStatus = MeshManagerApiEvent._('onConfigKeyRefreshPhaseStatus'); } diff --git a/lib/src/mesh_manager_api.dart b/lib/src/mesh_manager_api.dart index 1bddd1982..715754e5d 100644 --- a/lib/src/mesh_manager_api.dart +++ b/lib/src/mesh_manager_api.dart @@ -6,27 +6,8 @@ import 'package:flutter/services.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; import 'package:nordic_nrf_mesh/src/contants.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_app_key_status/config_app_key_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_composition_data_status/config_composition_data_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_model_app_status/config_model_app_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_model_publication_status/config_model_publication_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_model_subscription_status/config_model_subscription_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_network_transmit_status/config_network_transmit_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_default_ttl_status/config_default_ttl_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_node_reset_status/config_node_reset_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/generic_level_status/generic_level_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/generic_on_off_status/generic_on_off_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/light_ctl_status/light_ctl_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/light_hsl_status/light_hsl_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/light_lightness_status/light_lightness_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/magic_level_get_status/magic_level_get_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/magic_level_set_status/magic_level_set_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/mesh_network/mesh_network_event.dart'; -import 'package:nordic_nrf_mesh/src/events/data/mesh_provisioning_status/mesh_provisioning_status.dart'; -import 'package:nordic_nrf_mesh/src/events/data/send_provisioning_pdu/send_provisioning_pdu.dart'; import 'package:nordic_nrf_mesh/src/events/mesh_manager_api_events.dart'; import 'package:nordic_nrf_mesh/src/mesh_network.dart'; -import 'package:nordic_nrf_mesh/src/unprovisioned_mesh_node.dart'; import 'package:rxdart/rxdart.dart'; class MeshManagerApi { @@ -61,6 +42,7 @@ class MeshManagerApi { late final _onLightLightnessStatusController = StreamController.broadcast(); late final _onLightCtlStatusController = StreamController.broadcast(); late final _onLightHslStatusController = StreamController.broadcast(); + late final _onConfigKeyRefreshPhaseStatusController = StreamController.broadcast(); late StreamSubscription _onNetworkLoadedSubscription; late StreamSubscription _onNetworkImportedSubscription; @@ -89,6 +71,8 @@ class MeshManagerApi { late StreamSubscription _onLightCtlStatusSubscription; late StreamSubscription _onLightHslStatusSubscription; + late StreamSubscription _onConfigKeyRefreshPhaseStatusSubscription; + late Stream> _eventChannelStream; MeshNetwork? _lastMeshNetwork; @@ -199,6 +183,10 @@ class MeshManagerApi { .where((event) => event['eventName'] == MeshManagerApiEvent.configDefaultTtlStatus.value) .map((event) => ConfigDefaultTtlStatus.fromJson(event)) .listen(_onConfigDefaultTtlStatusController.add); + _onConfigKeyRefreshPhaseStatusSubscription = _eventChannelStream + .where((event) => event['eventName'] == MeshManagerApiEvent.configKeyRefreshPhaseStatus.value) + .map((event) => ConfigKeyRefreshPhaseStatus.fromJson(event)) + .listen(_onConfigKeyRefreshPhaseStatusController.add); } Stream get onConfigNetworkTransmitStatus => @@ -253,6 +241,9 @@ class MeshManagerApi { Stream get onLightHslStatus => _onLightHslStatusController.stream; + Stream get onConfigKeyRefreshPhaseStatus => + _onConfigKeyRefreshPhaseStatusController.stream; + Uuid get meshProvisioningUuidServiceKey => meshProvisioningUuid; Future isAdvertisedWithNodeIdentity(final List serviceData) async { @@ -335,7 +326,9 @@ class MeshManagerApi { _onV2MagicLevelGetStatusController.close(), _onConfigNodeResetStatusController.close(), _onConfigNetworkTransmitStatusController.close(), - _onConfigDefaultTtlStatusController.close() + _onConfigDefaultTtlStatusController.close(), + _onConfigKeyRefreshPhaseStatusSubscription.cancel(), + _onConfigKeyRefreshPhaseStatusController.close() ]); Future loadMeshNetwork() async { @@ -700,6 +693,53 @@ class MeshManagerApi { return status; } + Future keyRefreshPhaseGet({ + int address = 0xFFFF, + int netKeyIndex = 0, + }) async { + if (Platform.isAndroid) { + final status = _onConfigKeyRefreshPhaseStatusController.stream.firstWhere( + (element) => address != 0xFFFF || element.source == address, + orElse: () => const ConfigKeyRefreshPhaseStatus(-1, -1, -1, 'timeout', -1, -1), + ); + await _methodChannel.invokeMethod('keyRefreshPhaseGet', {'address': address, 'netKeyIndex': netKeyIndex}); + return status; + } else { + throw UnimplementedError('${Platform.environment} not supported'); + } + } + + // Key refresh phases (from Nordic's Android SDK) + // public static final int NORMAL_OPERATION = 0; + // public static final int KEY_DISTRIBUTION = 1; + // public static final int USING_NEW_KEYS = 2; + // public static final int REVOKING_OLD_KEYS = 3; This phase is instantaneous. + + // Transitions + static const int useNewKeys = 2; // Normal operation + static const int revokeOldKeys = 3; // Key Distribution + + Future keyRefreshPhaseSet({ + int address = 0xFFFF, + int netKeyIndex = 0, + int transition = useNewKeys, + }) async { + if (Platform.isAndroid) { + final status = _onConfigKeyRefreshPhaseStatusController.stream.firstWhere( + (element) => address != 0xFFFF || element.source == address, + orElse: () => const ConfigKeyRefreshPhaseStatus(-1, -1, -1, 'timeout', -1, -1), + ); + await _methodChannel.invokeMethod('keyRefreshPhaseSet', { + 'address': address, + 'netKeyIndex': netKeyIndex, + 'transition': transition, + }); + return status; + } else { + throw UnimplementedError('${Platform.environment} not supported'); + } + } + String getDeviceUuid(List serviceData) { var msb = 0; var lsb = 0; diff --git a/lib/src/mesh_network.dart b/lib/src/mesh_network.dart index d98b83eb7..9b5c5be97 100644 --- a/lib/src/mesh_network.dart +++ b/lib/src/mesh_network.dart @@ -4,9 +4,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:nordic_nrf_mesh/src/contants.dart'; -import 'package:nordic_nrf_mesh/src/models/group/group.dart'; -import 'package:nordic_nrf_mesh/src/models/provisioner/provisioner.dart'; -import 'package:nordic_nrf_mesh/src/provisioned_mesh_node.dart'; +import 'package:nordic_nrf_mesh/src/models/models.dart'; abstract class IMeshNetwork { Future> get groups; @@ -32,7 +30,13 @@ abstract class IMeshNetwork { Future selectProvisioner(int provisionerIndex); - Future addProvisioner(int unicastAddressRange, int groupAddressRange, int sceneAddressRange, int globalTtl); + Future addProvisioner( + int unicastAddressRange, + int groupAddressRange, + int sceneAddressRange, + int globalTtl, { + String name, + }); Future updateProvisioner(Provisioner provisioner); @@ -47,6 +51,14 @@ abstract class IMeshNetwork { Future getNode(int address); Future getNodeUsingUUID(String uuid); + + Future generateNetKey(); + + Future getNetKey(int netKeyIndex); + + Future removeNetKey(int netKeyIndex); + + Future distributeNetKey(int netKeyIndex); } class MeshNetwork implements IMeshNetwork { @@ -134,11 +146,17 @@ class MeshNetwork implements IMeshNetwork { @override Future addProvisioner( - int unicastAddressRange, int groupAddressRange, int sceneAddressRange, int globalTtl) async { + int unicastAddressRange, + int groupAddressRange, + int sceneAddressRange, + int globalTtl, { + String name = 'DooZ Mesh Provisioner', + }) async { if (Platform.isIOS || Platform.isAndroid) { return (await _methodChannel.invokeMethod( 'addProvisioner', { + 'name': name, 'unicastAddressRange': unicastAddressRange, 'groupAddressRange': groupAddressRange, 'sceneAddressRange': sceneAddressRange, @@ -239,4 +257,43 @@ class MeshNetwork implements IMeshNetwork { throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported'); } } + + @override + Future generateNetKey() async { + if (/* Platform.isIOS || */ Platform.isAndroid) { + final result = await _methodChannel.invokeMethod('generateNetKey'); + return NetworkKey.fromJson(Map.from(result!)); + } else { + throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported'); + } + } + + @override + Future getNetKey(int netKeyIndex) async { + if (/* Platform.isIOS || */ Platform.isAndroid) { + final result = await _methodChannel.invokeMethod('getNetKey', {'netKeyIndex': netKeyIndex}); + return NetworkKey.fromJson(Map.from(result!)); + } else { + throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported'); + } + } + + @override + Future removeNetKey(int netKeyIndex) async { + if (/* Platform.isIOS || */ Platform.isAndroid) { + return _methodChannel.invokeMethod('removeNetKey', {'netKeyIndex': netKeyIndex}); + } else { + throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported'); + } + } + + @override + Future distributeNetKey(int netKeyIndex) async { + if (/* Platform.isIOS || */ Platform.isAndroid) { + final result = await _methodChannel.invokeMethod('distributeNetKey', {'netKeyIndex': netKeyIndex}); + return NetworkKey.fromJson(Map.from(result!)); + } else { + throw UnsupportedError('Platform ${Platform.operatingSystem} is not supported'); + } + } } diff --git a/lib/src/provisioned_mesh_node.dart b/lib/src/models/mesh_node/provisioned_mesh_node.dart similarity index 100% rename from lib/src/provisioned_mesh_node.dart rename to lib/src/models/mesh_node/provisioned_mesh_node.dart diff --git a/lib/src/provisioned_mesh_node.g.dart b/lib/src/models/mesh_node/provisioned_mesh_node.g.dart similarity index 100% rename from lib/src/provisioned_mesh_node.g.dart rename to lib/src/models/mesh_node/provisioned_mesh_node.g.dart diff --git a/lib/src/unprovisioned_mesh_node.dart b/lib/src/models/mesh_node/unprovisioned_mesh_node.dart similarity index 100% rename from lib/src/unprovisioned_mesh_node.dart rename to lib/src/models/mesh_node/unprovisioned_mesh_node.dart diff --git a/lib/src/unprovisioned_mesh_node.g.dart b/lib/src/models/mesh_node/unprovisioned_mesh_node.g.dart similarity index 100% rename from lib/src/unprovisioned_mesh_node.g.dart rename to lib/src/models/mesh_node/unprovisioned_mesh_node.g.dart diff --git a/lib/src/models/models.dart b/lib/src/models/models.dart index d070bd31b..0ac5bfb28 100644 --- a/lib/src/models/models.dart +++ b/lib/src/models/models.dart @@ -1,2 +1,5 @@ export 'group/group.dart'; +export 'mesh_node/provisioned_mesh_node.dart'; +export 'mesh_node/unprovisioned_mesh_node.dart'; +export 'network_key/network_key.dart'; export 'provisioner/provisioner.dart'; diff --git a/lib/src/models/network_key/network_key.dart b/lib/src/models/network_key/network_key.dart new file mode 100644 index 000000000..e6625c7f0 --- /dev/null +++ b/lib/src/models/network_key/network_key.dart @@ -0,0 +1,24 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'network_key.freezed.dart'; +part 'network_key.g.dart'; + +@freezed +class NetworkKey with _$NetworkKey { + const factory NetworkKey( + String name, + int netKeyIndex, + int phase, + String phaseDescription, + bool isMinSecurity, + List netKeyBytes, + List? oldNetKeyBytes, + List txNetworkKey, + List identityKey, + List? oldIdentityKey, + String meshUuid, + int timestamp, + ) = _NetworkKey; + + factory NetworkKey.fromJson(Map json) => _$NetworkKeyFromJson(json); +} diff --git a/lib/src/models/network_key/network_key.freezed.dart b/lib/src/models/network_key/network_key.freezed.dart new file mode 100644 index 000000000..67e12a6d5 --- /dev/null +++ b/lib/src/models/network_key/network_key.freezed.dart @@ -0,0 +1,415 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides + +part of 'network_key.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +NetworkKey _$NetworkKeyFromJson(Map json) { + return _NetworkKey.fromJson(json); +} + +/// @nodoc +class _$NetworkKeyTearOff { + const _$NetworkKeyTearOff(); + + _NetworkKey call( + String name, + int netKeyIndex, + int phase, + String phaseDescription, + bool isMinSecurity, + List netKeyBytes, + List? oldNetKeyBytes, + List txNetworkKey, + List identityKey, + List? oldIdentityKey, + String meshUuid, + int timestamp) { + return _NetworkKey( + name, + netKeyIndex, + phase, + phaseDescription, + isMinSecurity, + netKeyBytes, + oldNetKeyBytes, + txNetworkKey, + identityKey, + oldIdentityKey, + meshUuid, + timestamp, + ); + } + + NetworkKey fromJson(Map json) { + return NetworkKey.fromJson(json); + } +} + +/// @nodoc +const $NetworkKey = _$NetworkKeyTearOff(); + +/// @nodoc +mixin _$NetworkKey { + String get name => throw _privateConstructorUsedError; + int get netKeyIndex => throw _privateConstructorUsedError; + int get phase => throw _privateConstructorUsedError; + String get phaseDescription => throw _privateConstructorUsedError; + bool get isMinSecurity => throw _privateConstructorUsedError; + List get netKeyBytes => throw _privateConstructorUsedError; + List? get oldNetKeyBytes => throw _privateConstructorUsedError; + List get txNetworkKey => throw _privateConstructorUsedError; + List get identityKey => throw _privateConstructorUsedError; + List? get oldIdentityKey => throw _privateConstructorUsedError; + String get meshUuid => throw _privateConstructorUsedError; + int get timestamp => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $NetworkKeyCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $NetworkKeyCopyWith<$Res> { + factory $NetworkKeyCopyWith(NetworkKey value, $Res Function(NetworkKey) then) = _$NetworkKeyCopyWithImpl<$Res>; + $Res call( + {String name, + int netKeyIndex, + int phase, + String phaseDescription, + bool isMinSecurity, + List netKeyBytes, + List? oldNetKeyBytes, + List txNetworkKey, + List identityKey, + List? oldIdentityKey, + String meshUuid, + int timestamp}); +} + +/// @nodoc +class _$NetworkKeyCopyWithImpl<$Res> implements $NetworkKeyCopyWith<$Res> { + _$NetworkKeyCopyWithImpl(this._value, this._then); + + final NetworkKey _value; + // ignore: unused_field + final $Res Function(NetworkKey) _then; + + @override + $Res call({ + Object? name = freezed, + Object? netKeyIndex = freezed, + Object? phase = freezed, + Object? phaseDescription = freezed, + Object? isMinSecurity = freezed, + Object? netKeyBytes = freezed, + Object? oldNetKeyBytes = freezed, + Object? txNetworkKey = freezed, + Object? identityKey = freezed, + Object? oldIdentityKey = freezed, + Object? meshUuid = freezed, + Object? timestamp = freezed, + }) { + return _then(_value.copyWith( + name: name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + netKeyIndex: netKeyIndex == freezed + ? _value.netKeyIndex + : netKeyIndex // ignore: cast_nullable_to_non_nullable + as int, + phase: phase == freezed + ? _value.phase + : phase // ignore: cast_nullable_to_non_nullable + as int, + phaseDescription: phaseDescription == freezed + ? _value.phaseDescription + : phaseDescription // ignore: cast_nullable_to_non_nullable + as String, + isMinSecurity: isMinSecurity == freezed + ? _value.isMinSecurity + : isMinSecurity // ignore: cast_nullable_to_non_nullable + as bool, + netKeyBytes: netKeyBytes == freezed + ? _value.netKeyBytes + : netKeyBytes // ignore: cast_nullable_to_non_nullable + as List, + oldNetKeyBytes: oldNetKeyBytes == freezed + ? _value.oldNetKeyBytes + : oldNetKeyBytes // ignore: cast_nullable_to_non_nullable + as List?, + txNetworkKey: txNetworkKey == freezed + ? _value.txNetworkKey + : txNetworkKey // ignore: cast_nullable_to_non_nullable + as List, + identityKey: identityKey == freezed + ? _value.identityKey + : identityKey // ignore: cast_nullable_to_non_nullable + as List, + oldIdentityKey: oldIdentityKey == freezed + ? _value.oldIdentityKey + : oldIdentityKey // ignore: cast_nullable_to_non_nullable + as List?, + meshUuid: meshUuid == freezed + ? _value.meshUuid + : meshUuid // ignore: cast_nullable_to_non_nullable + as String, + timestamp: timestamp == freezed + ? _value.timestamp + : timestamp // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +abstract class _$NetworkKeyCopyWith<$Res> implements $NetworkKeyCopyWith<$Res> { + factory _$NetworkKeyCopyWith(_NetworkKey value, $Res Function(_NetworkKey) then) = __$NetworkKeyCopyWithImpl<$Res>; + @override + $Res call( + {String name, + int netKeyIndex, + int phase, + String phaseDescription, + bool isMinSecurity, + List netKeyBytes, + List? oldNetKeyBytes, + List txNetworkKey, + List identityKey, + List? oldIdentityKey, + String meshUuid, + int timestamp}); +} + +/// @nodoc +class __$NetworkKeyCopyWithImpl<$Res> extends _$NetworkKeyCopyWithImpl<$Res> implements _$NetworkKeyCopyWith<$Res> { + __$NetworkKeyCopyWithImpl(_NetworkKey _value, $Res Function(_NetworkKey) _then) + : super(_value, (v) => _then(v as _NetworkKey)); + + @override + _NetworkKey get _value => super._value as _NetworkKey; + + @override + $Res call({ + Object? name = freezed, + Object? netKeyIndex = freezed, + Object? phase = freezed, + Object? phaseDescription = freezed, + Object? isMinSecurity = freezed, + Object? netKeyBytes = freezed, + Object? oldNetKeyBytes = freezed, + Object? txNetworkKey = freezed, + Object? identityKey = freezed, + Object? oldIdentityKey = freezed, + Object? meshUuid = freezed, + Object? timestamp = freezed, + }) { + return _then(_NetworkKey( + name == freezed + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + netKeyIndex == freezed + ? _value.netKeyIndex + : netKeyIndex // ignore: cast_nullable_to_non_nullable + as int, + phase == freezed + ? _value.phase + : phase // ignore: cast_nullable_to_non_nullable + as int, + phaseDescription == freezed + ? _value.phaseDescription + : phaseDescription // ignore: cast_nullable_to_non_nullable + as String, + isMinSecurity == freezed + ? _value.isMinSecurity + : isMinSecurity // ignore: cast_nullable_to_non_nullable + as bool, + netKeyBytes == freezed + ? _value.netKeyBytes + : netKeyBytes // ignore: cast_nullable_to_non_nullable + as List, + oldNetKeyBytes == freezed + ? _value.oldNetKeyBytes + : oldNetKeyBytes // ignore: cast_nullable_to_non_nullable + as List?, + txNetworkKey == freezed + ? _value.txNetworkKey + : txNetworkKey // ignore: cast_nullable_to_non_nullable + as List, + identityKey == freezed + ? _value.identityKey + : identityKey // ignore: cast_nullable_to_non_nullable + as List, + oldIdentityKey == freezed + ? _value.oldIdentityKey + : oldIdentityKey // ignore: cast_nullable_to_non_nullable + as List?, + meshUuid == freezed + ? _value.meshUuid + : meshUuid // ignore: cast_nullable_to_non_nullable + as String, + timestamp == freezed + ? _value.timestamp + : timestamp // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_NetworkKey implements _NetworkKey { + const _$_NetworkKey( + this.name, + this.netKeyIndex, + this.phase, + this.phaseDescription, + this.isMinSecurity, + this.netKeyBytes, + this.oldNetKeyBytes, + this.txNetworkKey, + this.identityKey, + this.oldIdentityKey, + this.meshUuid, + this.timestamp); + + factory _$_NetworkKey.fromJson(Map json) => _$_$_NetworkKeyFromJson(json); + + @override + final String name; + @override + final int netKeyIndex; + @override + final int phase; + @override + final String phaseDescription; + @override + final bool isMinSecurity; + @override + final List netKeyBytes; + @override + final List? oldNetKeyBytes; + @override + final List txNetworkKey; + @override + final List identityKey; + @override + final List? oldIdentityKey; + @override + final String meshUuid; + @override + final int timestamp; + + @override + String toString() { + return 'NetworkKey(name: $name, netKeyIndex: $netKeyIndex, phase: $phase, phaseDescription: $phaseDescription, isMinSecurity: $isMinSecurity, netKeyBytes: $netKeyBytes, oldNetKeyBytes: $oldNetKeyBytes, txNetworkKey: $txNetworkKey, identityKey: $identityKey, oldIdentityKey: $oldIdentityKey, meshUuid: $meshUuid, timestamp: $timestamp)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _NetworkKey && + (identical(other.name, name) || const DeepCollectionEquality().equals(other.name, name)) && + (identical(other.netKeyIndex, netKeyIndex) || + const DeepCollectionEquality().equals(other.netKeyIndex, netKeyIndex)) && + (identical(other.phase, phase) || const DeepCollectionEquality().equals(other.phase, phase)) && + (identical(other.phaseDescription, phaseDescription) || + const DeepCollectionEquality().equals(other.phaseDescription, phaseDescription)) && + (identical(other.isMinSecurity, isMinSecurity) || + const DeepCollectionEquality().equals(other.isMinSecurity, isMinSecurity)) && + (identical(other.netKeyBytes, netKeyBytes) || + const DeepCollectionEquality().equals(other.netKeyBytes, netKeyBytes)) && + (identical(other.oldNetKeyBytes, oldNetKeyBytes) || + const DeepCollectionEquality().equals(other.oldNetKeyBytes, oldNetKeyBytes)) && + (identical(other.txNetworkKey, txNetworkKey) || + const DeepCollectionEquality().equals(other.txNetworkKey, txNetworkKey)) && + (identical(other.identityKey, identityKey) || + const DeepCollectionEquality().equals(other.identityKey, identityKey)) && + (identical(other.oldIdentityKey, oldIdentityKey) || + const DeepCollectionEquality().equals(other.oldIdentityKey, oldIdentityKey)) && + (identical(other.meshUuid, meshUuid) || const DeepCollectionEquality().equals(other.meshUuid, meshUuid)) && + (identical(other.timestamp, timestamp) || + const DeepCollectionEquality().equals(other.timestamp, timestamp))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(name) ^ + const DeepCollectionEquality().hash(netKeyIndex) ^ + const DeepCollectionEquality().hash(phase) ^ + const DeepCollectionEquality().hash(phaseDescription) ^ + const DeepCollectionEquality().hash(isMinSecurity) ^ + const DeepCollectionEquality().hash(netKeyBytes) ^ + const DeepCollectionEquality().hash(oldNetKeyBytes) ^ + const DeepCollectionEquality().hash(txNetworkKey) ^ + const DeepCollectionEquality().hash(identityKey) ^ + const DeepCollectionEquality().hash(oldIdentityKey) ^ + const DeepCollectionEquality().hash(meshUuid) ^ + const DeepCollectionEquality().hash(timestamp); + + @JsonKey(ignore: true) + @override + _$NetworkKeyCopyWith<_NetworkKey> get copyWith => __$NetworkKeyCopyWithImpl<_NetworkKey>(this, _$identity); + + @override + Map toJson() { + return _$_$_NetworkKeyToJson(this); + } +} + +abstract class _NetworkKey implements NetworkKey { + const factory _NetworkKey( + String name, + int netKeyIndex, + int phase, + String phaseDescription, + bool isMinSecurity, + List netKeyBytes, + List? oldNetKeyBytes, + List txNetworkKey, + List identityKey, + List? oldIdentityKey, + String meshUuid, + int timestamp) = _$_NetworkKey; + + factory _NetworkKey.fromJson(Map json) = _$_NetworkKey.fromJson; + + @override + String get name => throw _privateConstructorUsedError; + @override + int get netKeyIndex => throw _privateConstructorUsedError; + @override + int get phase => throw _privateConstructorUsedError; + @override + String get phaseDescription => throw _privateConstructorUsedError; + @override + bool get isMinSecurity => throw _privateConstructorUsedError; + @override + List get netKeyBytes => throw _privateConstructorUsedError; + @override + List? get oldNetKeyBytes => throw _privateConstructorUsedError; + @override + List get txNetworkKey => throw _privateConstructorUsedError; + @override + List get identityKey => throw _privateConstructorUsedError; + @override + List? get oldIdentityKey => throw _privateConstructorUsedError; + @override + String get meshUuid => throw _privateConstructorUsedError; + @override + int get timestamp => throw _privateConstructorUsedError; + @override + @JsonKey(ignore: true) + _$NetworkKeyCopyWith<_NetworkKey> get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/src/models/network_key/network_key.g.dart b/lib/src/models/network_key/network_key.g.dart new file mode 100644 index 000000000..6c6cbdb5a --- /dev/null +++ b/lib/src/models/network_key/network_key.g.dart @@ -0,0 +1,39 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'network_key.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_NetworkKey _$_$_NetworkKeyFromJson(Map json) { + return _$_NetworkKey( + json['name'] as String, + json['netKeyIndex'] as int, + json['phase'] as int, + json['phaseDescription'] as String, + json['isMinSecurity'] as bool, + (json['netKeyBytes'] as List).map((e) => e as int).toList(), + (json['oldNetKeyBytes'] as List?)?.map((e) => e as int).toList(), + (json['txNetworkKey'] as List).map((e) => e as int).toList(), + (json['identityKey'] as List).map((e) => e as int).toList(), + (json['oldIdentityKey'] as List?)?.map((e) => e as int).toList(), + json['meshUuid'] as String, + json['timestamp'] as int, + ); +} + +Map _$_$_NetworkKeyToJson(_$_NetworkKey instance) => { + 'name': instance.name, + 'netKeyIndex': instance.netKeyIndex, + 'phase': instance.phase, + 'phaseDescription': instance.phaseDescription, + 'isMinSecurity': instance.isMinSecurity, + 'netKeyBytes': instance.netKeyBytes, + 'oldNetKeyBytes': instance.oldNetKeyBytes, + 'txNetworkKey': instance.txNetworkKey, + 'identityKey': instance.identityKey, + 'oldIdentityKey': instance.oldIdentityKey, + 'meshUuid': instance.meshUuid, + 'timestamp': instance.timestamp, + }; diff --git a/lib/src/nrf_mesh.dart b/lib/src/nrf_mesh.dart index fa1df1cf3..437bfda3c 100644 --- a/lib/src/nrf_mesh.dart +++ b/lib/src/nrf_mesh.dart @@ -3,12 +3,8 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:nordic_nrf_mesh/nordic_nrf_mesh.dart'; -import 'package:nordic_nrf_mesh/src/ble/ble_mesh_manager.dart'; import 'package:nordic_nrf_mesh/src/ble/ble_scanner.dart'; import 'package:nordic_nrf_mesh/src/contants.dart'; -import 'package:nordic_nrf_mesh/src/events/data/config_node_reset_status/config_node_reset_status.dart'; -import 'package:nordic_nrf_mesh/src/mesh_manager_api.dart'; -import 'package:nordic_nrf_mesh/src/provisioned_mesh_node.dart'; import 'package:nordic_nrf_mesh/src/utils/provisioning.dart' as utils_provisioning; class NordicNrfMesh { diff --git a/lib/src/utils/provisioning.dart b/lib/src/utils/provisioning.dart index a9b42836c..3c26f8f91 100644 --- a/lib/src/utils/provisioning.dart +++ b/lib/src/utils/provisioning.dart @@ -11,8 +11,7 @@ import 'package:nordic_nrf_mesh/src/contants.dart'; import 'package:nordic_nrf_mesh/src/events/data/config_node_reset_status/config_node_reset_status.dart'; import 'package:nordic_nrf_mesh/src/exceptions/exceptions.dart'; import 'package:nordic_nrf_mesh/src/mesh_manager_api.dart'; -import 'package:nordic_nrf_mesh/src/provisioned_mesh_node.dart'; -import 'package:nordic_nrf_mesh/src/unprovisioned_mesh_node.dart'; +import 'package:nordic_nrf_mesh/src/models/models.dart'; class _ProvisioningEvent { final _provisioningController = StreamController(); diff --git a/pubspec.yaml b/pubspec.yaml index 1c7456f11..8ef204857 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nordic_nrf_mesh description: A Flutter plugin to enable mesh network management and communication using Nordic's SDKs. It also provides the ability to open BLE connection with mesh nodes using some other flutter package. -version: 0.4.0 +version: 0.5.0 environment: sdk: ">=2.12.0 <3.0.0"