Skip to content
Open
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
10 changes: 7 additions & 3 deletions components/bthome/bthome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,19 @@ void BTHome::build_advertisement_data_() {
size_t ciphertext_len = 0;

if (this->encrypt_payload_(plaintext, measurement_len, ciphertext, &ciphertext_len)) {
memcpy(this->adv_data_ + measurement_start, ciphertext, ciphertext_len);
pos = measurement_start + ciphertext_len;
size_t actual_ciphertext_len = ciphertext_len - 4;

memcpy(this->adv_data_ + measurement_start, ciphertext, actual_ciphertext_len);
pos = measurement_start + actual_ciphertext_len;

// Add counter (4 bytes, little-endian)
this->adv_data_[pos++] = this->counter_ & 0xFF;
this->adv_data_[pos++] = (this->counter_ >> 8) & 0xFF;
this->adv_data_[pos++] = (this->counter_ >> 16) & 0xFF;
this->adv_data_[pos++] = (this->counter_ >> 24) & 0xFF;

memcpy(this->adv_data_ + pos, ciphertext + actual_ciphertext_len, 4);
pos += 4;

this->counter_++;
}
}
Expand Down