2023-09-07 18:36:16 +08:00
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
// WIFI配网
|
2023-09-07 18:36:16 +08:00
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
import 'package:crypto/crypto.dart' as crypto;
|
|
|
|
|
|
|
2023-09-07 18:36:16 +08:00
|
|
|
|
import '../io_reply.dart';
|
|
|
|
|
|
import '../io_sender.dart';
|
|
|
|
|
|
import '../io_tool/io_tool.dart';
|
|
|
|
|
|
import '../io_type.dart';
|
|
|
|
|
|
import '../sm4Encipher/sm4.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class SenderConfiguringWifiCommand extends SenderProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
SenderConfiguringWifiCommand({
|
|
|
|
|
|
this.keyID,
|
|
|
|
|
|
this.userID,
|
|
|
|
|
|
this.ssid,
|
|
|
|
|
|
this.password,
|
2024-12-23 15:19:57 +08:00
|
|
|
|
this.peerId,
|
2023-09-07 18:36:16 +08:00
|
|
|
|
this.numberOfServers,
|
|
|
|
|
|
this.listOfServers,
|
2023-12-11 13:44:15 +08:00
|
|
|
|
this.numberOfPhone,
|
|
|
|
|
|
this.listOfPhone,
|
2023-09-07 18:36:16 +08:00
|
|
|
|
this.token,
|
|
|
|
|
|
this.needAuthor,
|
|
|
|
|
|
this.publicKey,
|
|
|
|
|
|
this.privateKey,
|
|
|
|
|
|
}) : super(CommandType.generalExtendedCommond);
|
|
|
|
|
|
|
2024-10-15 14:24:35 +08:00
|
|
|
|
String? keyID;
|
|
|
|
|
|
String? userID;
|
|
|
|
|
|
String? ssid;
|
|
|
|
|
|
String? password;
|
2024-12-23 15:19:57 +08:00
|
|
|
|
String? peerId;
|
2024-10-15 14:24:35 +08:00
|
|
|
|
int? numberOfServers;
|
|
|
|
|
|
List<int>? listOfServers;
|
|
|
|
|
|
int? numberOfPhone;
|
|
|
|
|
|
List<String>? listOfPhone;
|
|
|
|
|
|
List<int>? token;
|
|
|
|
|
|
int? needAuthor;
|
|
|
|
|
|
List<int>? publicKey;
|
|
|
|
|
|
List<int>? privateKey;
|
|
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
String toString() {
|
|
|
|
|
|
return 'SenderConfiguringWifiCommand{keyID: $keyID, userID: $userID, '
|
2024-12-23 15:19:57 +08:00
|
|
|
|
'ssid: $ssid, password: $password,peerId: $peerId, numberOfServers: $numberOfServers, '
|
2024-05-03 14:38:09 +08:00
|
|
|
|
'listOfServers: $listOfServers, numberOfPhone: $numberOfPhone, '
|
|
|
|
|
|
'listOfPhone: $listOfPhone, token: $token, needAuthor: $needAuthor, '
|
|
|
|
|
|
'publicKey: $publicKey, privateKey: $privateKey}';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-07 18:36:16 +08:00
|
|
|
|
@override
|
|
|
|
|
|
List<int> messageDetail() {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final List<int> data = <int>[];
|
|
|
|
|
|
List<int> subData = <int>[];
|
|
|
|
|
|
List<int> ebcData = <int>[];
|
2023-09-07 18:36:16 +08:00
|
|
|
|
|
|
|
|
|
|
// 指令类型
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int type = commandType!.typeValue;
|
|
|
|
|
|
final double typeDouble = type / 256;
|
|
|
|
|
|
final int type1 = typeDouble.toInt();
|
|
|
|
|
|
final int type2 = type % 256;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
data.add(type1);
|
|
|
|
|
|
data.add(type2);
|
|
|
|
|
|
|
|
|
|
|
|
// 子命令类型
|
|
|
|
|
|
data.add(50);
|
|
|
|
|
|
|
|
|
|
|
|
// keyID 40
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int keyIDLength = utf8.encode(keyID!).length;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
subData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 40 - keyIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
//userID 20
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int userIDLength = utf8.encode(userID!).length;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
subData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - userIDLength);
|
|
|
|
|
|
|
|
|
|
|
|
//SSID 30
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int ssidLength = utf8.encode(ssid!).length;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
subData.addAll(utf8.encode(ssid!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 30 - ssidLength);
|
|
|
|
|
|
|
|
|
|
|
|
//Password 20
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int passwordLength = utf8.encode(password!).length;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
subData.addAll(utf8.encode(password!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - passwordLength);
|
|
|
|
|
|
|
2024-12-23 15:19:57 +08:00
|
|
|
|
//peerId 44
|
|
|
|
|
|
final int peerIdLength = utf8.encode(peerId!).length;
|
|
|
|
|
|
subData.addAll(utf8.encode(peerId!));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 44 - peerIdLength);
|
|
|
|
|
|
|
2023-09-07 18:36:16 +08:00
|
|
|
|
// NumberOfServers
|
|
|
|
|
|
subData.add(numberOfServers!);
|
|
|
|
|
|
|
|
|
|
|
|
// listOfServers
|
2023-11-18 10:38:13 +08:00
|
|
|
|
subData.addAll(listOfServers!);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
|
2023-12-11 13:44:15 +08:00
|
|
|
|
// NumberOfPhone
|
|
|
|
|
|
subData.add(numberOfPhone!);
|
|
|
|
|
|
|
|
|
|
|
|
// listOfPhone
|
2024-10-15 14:24:35 +08:00
|
|
|
|
listOfPhone!.forEach((String element) {
|
|
|
|
|
|
final int phoneLength = utf8.encode(element).length;
|
2023-12-11 13:44:15 +08:00
|
|
|
|
subData.addAll(utf8.encode(element));
|
|
|
|
|
|
subData = getFixedLengthList(subData, 20 - phoneLength);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2023-09-07 18:36:16 +08:00
|
|
|
|
// token
|
|
|
|
|
|
// subData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
if(needAuthor == 0){
|
|
|
|
|
|
//AuthCodeLen 1
|
|
|
|
|
|
subData.add(0);
|
|
|
|
|
|
} else {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final List<int> authCodeData = <int>[];
|
2023-09-07 18:36:16 +08:00
|
|
|
|
|
|
|
|
|
|
//userID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(userID!));
|
|
|
|
|
|
|
|
|
|
|
|
//KeyID
|
|
|
|
|
|
authCodeData.addAll(utf8.encode(keyID!));
|
|
|
|
|
|
|
|
|
|
|
|
//token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。
|
|
|
|
|
|
authCodeData.addAll(token!);
|
|
|
|
|
|
|
|
|
|
|
|
authCodeData.addAll(publicKey!);
|
|
|
|
|
|
|
|
|
|
|
|
// 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final crypto.Digest authCode = crypto.md5.convert(authCodeData);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
|
|
|
|
|
|
subData.add(authCode.bytes.length);
|
|
|
|
|
|
subData.addAll(authCode.bytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
data.add(subData.length);
|
|
|
|
|
|
data.addAll(subData);
|
|
|
|
|
|
|
|
|
|
|
|
if ((data.length % 16) != 0) {
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int add = 16 - data.length % 16;
|
2023-09-07 18:36:16 +08:00
|
|
|
|
for (int i = 0; i < add; i++) {
|
|
|
|
|
|
data.add(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-19 18:13:34 +08:00
|
|
|
|
|
2024-05-03 14:38:09 +08:00
|
|
|
|
printLog(data);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
// 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864
|
|
|
|
|
|
ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB);
|
|
|
|
|
|
return ebcData;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SenderConfiguringWifiReply extends Reply {
|
|
|
|
|
|
SenderConfiguringWifiReply.parseData(CommandType commandType, List<int> dataDetail)
|
|
|
|
|
|
: super.parseData(commandType, dataDetail) {
|
|
|
|
|
|
data = dataDetail;
|
2024-10-15 14:24:35 +08:00
|
|
|
|
final int status = data[5];
|
2024-04-19 18:13:34 +08:00
|
|
|
|
errorWithStstus(status);
|
2023-09-07 18:36:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|