crc8生成方式修改

This commit is contained in:
祝发冬 2023-09-09 22:37:07 +08:00
parent 128c00989c
commit de42bbdb79
1 changed files with 9 additions and 1 deletions

View File

@ -7,6 +7,7 @@
//
#import "JMAirKissEncoder.h"
#import "ESP_CRC8.h"
#define kRandomChar arc4random() % 127
@ -96,6 +97,8 @@
Byte bytes[numberOfBytes];
NSRange range = NSMakeRange(0, numberOfBytes);
[ssid getBytes:bytes maxLength:numberOfBytes usedLength:nil encoding:NSUTF8StringEncoding options:0 range:range remainingRange:NULL];
NSData *ssidData = [[NSData alloc]initWithBytes:bytes length:numberOfBytes];
[ssidData getBytes:bytes length:[ssidData length]];
UInt8 length = numberOfBytes + password.length + 1;
UInt8 magicCode[4] = {0x00,0x00,0x00,0x00};
magicCode[0] = 0x00 | (length >> 4 & 0xF);
@ -107,7 +110,12 @@
magicCode[1] = 0x10 | (length & 0xF);
UInt8 *cipherBuffer = (UInt8*)bytes;
UInt8 crc8 = CRC8(cipherBuffer, (int)numberOfBytes);
ESP_CRC8 *crc = [[ESP_CRC8 alloc]init];
[crc updateWithBuf:bytes Nbytes:(int)sizeof(bytes)];
Byte apSsidCrc = [crc getValue];
[crc reset];
UInt8 crc8 = apSsidCrc;//CRC8(cipherBuffer, (int)numberOfBytes);
magicCode[2] = 0x20 | (crc8 >> 4 & 0xF);
magicCode[3] = 0x30 | (crc8 & 0xF);