Skip to content

Commit 21dc123

Browse files
committed
Log each AirPods advertisement with trace level
1 parent 212bf60 commit 21dc123

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

Source/Core/AirPods.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ namespace Core::AirPods
7070
{
7171
APD_ASSERT(IsDesiredAdv(data));
7272
_data = data;
73+
74+
auto protocol = AppleCP::As<AppleCP::AirPods>(GetMfrData());
75+
APD_ASSERT(protocol.has_value());
76+
_protocol = std::move(protocol.value());
7377
}
7478

7579
int16_t GetRssi() const
@@ -87,35 +91,35 @@ namespace Core::AirPods
8791
return _data.address;
8892
}
8993

90-
AppleCP::AirPods GetRawData() const
94+
std::vector<uint8_t> GetDesensitizedData() const
9195
{
92-
auto protocol = AppleCP::As<AppleCP::AirPods>(GetMfrData());
93-
APD_ASSERT(protocol.has_value());
94-
return protocol.value();
96+
auto desensitizedData = _protocol.Desensitize();
97+
98+
std::vector<uint8_t> result(sizeof(desensitizedData), 0);
99+
std::memcpy(result.data(), &desensitizedData, sizeof(desensitizedData));
100+
return result;
95101
}
96102

97103
DevState GetState() const
98104
{
99-
auto protocol = GetRawData();
100-
101105
DevState state;
102106

103-
state.model = protocol.GetModel();
104-
state.side = protocol.GetBroadcastedSide();
107+
state.model = _protocol.GetModel();
108+
state.side = _protocol.GetBroadcastedSide();
105109

106-
state.pods.left.battery = protocol.GetLeftBattery();
107-
state.pods.left.isCharging = protocol.IsLeftCharging();
108-
state.pods.left.isInEar = protocol.IsLeftInEar();
110+
state.pods.left.battery = _protocol.GetLeftBattery();
111+
state.pods.left.isCharging = _protocol.IsLeftCharging();
112+
state.pods.left.isInEar = _protocol.IsLeftInEar();
109113

110-
state.pods.right.battery = protocol.GetRightBattery();
111-
state.pods.right.isCharging = protocol.IsRightCharging();
112-
state.pods.right.isInEar = protocol.IsRightInEar();
114+
state.pods.right.battery = _protocol.GetRightBattery();
115+
state.pods.right.isCharging = _protocol.IsRightCharging();
116+
state.pods.right.isInEar = _protocol.IsRightInEar();
113117

114-
state.caseBox.battery = protocol.GetCaseBattery();
115-
state.caseBox.isCharging = protocol.IsCaseCharging();
118+
state.caseBox.battery = _protocol.GetCaseBattery();
119+
state.caseBox.isCharging = _protocol.IsCaseCharging();
116120

117-
state.caseBox.isBothPodsInCase = protocol.IsBothPodsInCase();
118-
state.caseBox.isLidOpened = protocol.IsLidOpened();
121+
state.caseBox.isBothPodsInCase = _protocol.IsBothPodsInCase();
122+
state.caseBox.isLidOpened = _protocol.IsLidOpened();
119123

120124
if (state.pods.left.battery.has_value()) {
121125
state.pods.left.battery = state.pods.left.battery.value() * 10;
@@ -132,6 +136,7 @@ namespace Core::AirPods
132136

133137
private:
134138
Bluetooth::AdvertisementWatcher::ReceivedData _data;
139+
AppleCP::AirPods _protocol;
135140

136141
const std::vector<uint8_t>& GetMfrData() const
137142
{
@@ -310,6 +315,12 @@ namespace Core::AirPods
310315
bool OnDevicesUpdated(const Bluetooth::AdvertisementWatcher::ReceivedData &data)
311316
{
312317
Advertisement adv{data};
318+
319+
spdlog::trace(
320+
"AirPods advertisement received. Data: {}",
321+
Helper::ToString(adv.GetDesensitizedData())
322+
);
323+
313324
auto state = adv.GetState();
314325

315326
if (_leftAdv.has_value() && Clock::now() - _leftAdv->first >= Timeout) {

Source/Core/AppleCP.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,16 @@ namespace Core::AppleCP
133133
return !IsRightCharging() && (IsRightBroadcasted() ? currInEar : anotInEar);
134134
}
135135

136+
AirPods AirPods::Desensitize() const
137+
{
138+
auto result = *this;
139+
140+
// This field may be some kind of hash or encrypted payload.
141+
// So it may contain personal information about the user.
142+
//
143+
std::memset(result.unk12, 0, sizeof(result.unk12));
144+
145+
return result;
146+
}
147+
136148
} // namespace Core::AppleCP

Source/Core/AppleCP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ namespace Core::AppleCP
125125
bool IsLeftInEar() const;
126126
bool IsRightInEar() const;
127127

128+
AirPods Desensitize() const;
129+
128130
private:
129131
uint8_t unk1[1];
130132
uint16_t modelId;

0 commit comments

Comments
 (0)