runing with ledger interface
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include "client2.h"
|
||||
#include <iostream>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float IntToFloat(int num) {
|
||||
return static_cast<float>(num) / 65536.0f;
|
||||
@@ -32,7 +34,62 @@ void ReversalBuff(uint8_t* buff, int start, int length) {
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MAC<41><43>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>䵽<EFBFBD><E4B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void GetMAC(const std::string& strMAC, std::vector<unsigned char>& packet, size_t startIndex) {
|
||||
//lnk20250808
|
||||
static inline int hex_nibble(char c) {
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
||||
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><>ȫ<EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true/false
|
||||
bool GetMAC(const std::string& strMAC,
|
||||
std::vector<unsigned char>& packet,
|
||||
size_t startIndex,
|
||||
std::string* err = nullptr) {
|
||||
// 1) <20>淶<EFBFBD><E6B7B6><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5> '-', ':', ' '
|
||||
std::string s;
|
||||
s.reserve(strMAC.size());
|
||||
for (char c : strMAC) {
|
||||
if (c == '-' || c == ':' || c == ' ') continue;
|
||||
s.push_back(c);
|
||||
}
|
||||
|
||||
// 2) <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||||
if (s.size() != 12) {
|
||||
if (err) *err = "MAC<EFBFBD><EFBFBD><EFBFBD>ȱ<EFBFBD><EFBFBD><EFBFBD>Ϊ12<EFBFBD><EFBFBD>ʮ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3) ʮ<><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3> + <20><><EFBFBD><EFBFBD>
|
||||
std::array<unsigned char, 6> mac{};
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
int hi = hex_nibble(s[2*i]);
|
||||
int lo = hex_nibble(s[2*i + 1]);
|
||||
if (hi < 0 || lo < 0) {
|
||||
if (err) *err = "MAC<EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ַ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0-9<><39>A-F)";
|
||||
return false;
|
||||
}
|
||||
mac[i] = static_cast<unsigned char>((hi << 4) | lo);
|
||||
}
|
||||
|
||||
// 4) ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㹻д<E3B9BB><D0B4>64<36>ֽڣ<D6BD>MAC 6<>ֽ<EFBFBD> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣩
|
||||
const size_t need = startIndex + 64;
|
||||
if (packet.size() < need) packet.resize(need, 0);
|
||||
|
||||
// 5) д<><D0B4>MAC
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
packet[startIndex + i] = mac[i];
|
||||
}
|
||||
|
||||
// 6) <20><><EFBFBD><EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2>㣨<EFBFBD><E3A3A8> resize <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤һ<D6A4>£<EFBFBD>
|
||||
for (size_t i = 6; i < 64; ++i) {
|
||||
packet[startIndex + i] = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/*void GetMAC(const std::string& strMAC, std::vector<unsigned char>& packet, size_t startIndex) {
|
||||
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>пո<D0BF><D5B8>Ͷ̺<CDB6><CCBA><EFBFBD>
|
||||
std::string cleanedMAC = strMAC;
|
||||
cleanedMAC.erase(std::remove(cleanedMAC.begin(), cleanedMAC.end(), ' '), cleanedMAC.end());
|
||||
@@ -70,7 +127,7 @@ void GetMAC(const std::string& strMAC, std::vector<unsigned char>& packet, size_
|
||||
catch (const std::exception& e) {
|
||||
throw std::invalid_argument("<22><>Ч<EFBFBD><D0A7>MAC<41><43>ַ: " + std::string(e.what()));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// CRC<52><43><EFBFBD>㺯<EFBFBD><E3BAAF>
|
||||
unsigned char GetCrcSum(const std::vector<unsigned char>& Check, int nOffset, int nLen) {
|
||||
@@ -292,7 +349,13 @@ std::vector<unsigned char> generate_frontlogin_message(const std::string& strMac
|
||||
// [16-19] <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2 (<28><><EFBFBD><EFBFBD>Ϊ0)
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>MAC<41><43>ַ (<28><>λ<EFBFBD><CEBB>20<32><30>ʼ<EFBFBD><CABC>64<36>ֽ<EFBFBD>)
|
||||
GetMAC(strMac, packet, 20);
|
||||
//GetMAC(strMac, packet, 20);
|
||||
//lnk20250808
|
||||
std::string err;
|
||||
if (!GetMAC(strMac, packet, 0, &err)) {
|
||||
std::cerr << "[GetMAC] parse failed: " << err << "\n";
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD> (<28><>ƫ<EFBFBD><C6AB>8<EFBFBD><38>137)
|
||||
unsigned char checksum = 0;
|
||||
|
||||
Reference in New Issue
Block a user