Skip to content

Commit

Permalink
Revert the change for reseting service data on hci events. They are n…
Browse files Browse the repository at this point in the history
…ow reset every non scan response event
  • Loading branch information
lordthorzonus authored and rzr committed Feb 24, 2023
1 parent 6711383 commit fd707b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/hci-socket/gap.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Gap.prototype.onHciLeAdvertisingReport = function (
address,
eir,
previouslyDiscovered,
hasScanResponse
type
);

debug(`advertisement = ${JSON.stringify(advertisement, null, 0)}`);
Expand Down Expand Up @@ -211,7 +211,7 @@ Gap.prototype.onHciLeExtendedAdvertisingReport = function (
address,
eir,
previouslyDiscovered,
hasScanResponse,
type,
txpower
);

Expand Down Expand Up @@ -258,7 +258,7 @@ Gap.prototype.parseServices = function (
address,
eir,
previouslyDiscovered,
hasScanResponse,
leMetaEventType,
txpower
) {
let i = 0;
Expand All @@ -273,7 +273,7 @@ Gap.prototype.parseServices = function (
solicitationServiceUuids: []
};

if (!hasScanResponse) {
if (leMetaEventType !== LE_META_EVENT_TYPE_SCAN_RESPONSE) {
// reset service data every non-scan response event
advertisement.serviceData = [];
advertisement.serviceUuids = [];
Expand Down
39 changes: 39 additions & 0 deletions test/lib/hci-socket/gap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,4 +1086,43 @@ describe('hci-socket gap', () => {
assert.notCalled(discoverCallback);
});
});

it('should reset the service data on non scan responses', () => {
const hci = {
on: sinon.spy()
};

const status = 'status';
const address = 'a:d:d:r:e:s:s';
const addressType = 'addressType';
const rssi = 'rssi';

const eirType = 0x21;
const serviceUuid = Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]);
const serviceData = Buffer.from([0x05, 0x06]);
const eirLength = serviceUuid.length + serviceData.length + 1;
const eirLengthAndType = Buffer.from([eirLength, eirType]);
const eir = Buffer.concat([eirLengthAndType, serviceUuid, serviceData]);

const discoverCallback = sinon.spy();

const gap = new Gap(hci);
gap.on('discover', discoverCallback);
gap.onHciLeAdvertisingReport(status, 0x04, address, addressType, eir, rssi);

const expectedServiceData = [
{
uuid: '0f0e0d0c0b0a09080706050403020100',
data: serviceData
}
];

should(gap._discoveries[address].advertisement.serviceData).deepEqual(expectedServiceData);

gap.onHciLeAdvertisingReport(status, 0x01, address, addressType, eir, rssi);

should(gap._discoveries[address].advertisement.serviceData).deepEqual(expectedServiceData);

assert.calledOnce(discoverCallback);
});
});

0 comments on commit fd707b4

Please sign in to comment.