From f6c964466a65b9434c84a3d038ef1793cf27aa83 Mon Sep 17 00:00:00 2001 From: Marco Crespi Date: Thu, 19 Nov 2020 17:11:42 +0100 Subject: [PATCH] feat(hci): Use gatt command mutex --- lib/bindings/hci/gatt/remote/Gatt.d.ts | 5 +- lib/bindings/hci/gatt/remote/Gatt.js | 69 ++++++++++++-------- lib/bindings/hci/gatt/remote/Gatt.js.map | 2 +- src/bindings/hci/gatt/remote/Gatt.ts | 83 +++++++++++++++--------- 4 files changed, 100 insertions(+), 59 deletions(-) diff --git a/lib/bindings/hci/gatt/remote/Gatt.d.ts b/lib/bindings/hci/gatt/remote/Gatt.d.ts index e235b881..e0cfd959 100644 --- a/lib/bindings/hci/gatt/remote/Gatt.d.ts +++ b/lib/bindings/hci/gatt/remote/Gatt.d.ts @@ -8,12 +8,13 @@ export declare class HciGattRemote extends GattRemote { private hci; private handle; private security; + private mtuWasExchanged; + private mutex; private currentCommand; - private commandQueue; services: Map; constructor(peripheral: Peripheral, hci: Hci, handle: number); - private processCommands; dispose(): void; + private onHciStateChange; private onAclStreamData; private writeAtt; private errorResponse; diff --git a/lib/bindings/hci/gatt/remote/Gatt.js b/lib/bindings/hci/gatt/remote/Gatt.js index 2a7d4689..e441da76 100644 --- a/lib/bindings/hci/gatt/remote/Gatt.js +++ b/lib/bindings/hci/gatt/remote/Gatt.js @@ -20,6 +20,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HciGattRemote = void 0; +const async_mutex_1 = require("async-mutex"); const models_1 = require("../../../../models"); const CONST = __importStar(require("../Constants")); const Characteristic_1 = require("./Characteristic"); @@ -28,19 +29,29 @@ const Service_1 = require("./Service"); class HciGattRemote extends models_1.GattRemote { constructor(peripheral, hci, handle) { super(peripheral); + this.mtuWasExchanged = false; this.currentCommand = null; - this.commandQueue = []; this.services = new Map(); + this.onHciStateChange = async (newState) => { + // If the underlaying socket shuts down we're doomed + if (newState === 'poweredOff') { + if (this.currentCommand) { + this.currentCommand.onResponse(null); + this.currentCommand = null; + } + } + }; this.onAclStreamData = async (handle, cid, data) => { if (handle !== this.handle || cid !== CONST.ATT_CID) { return; } if (this.currentCommand && data.toString('hex') === this.currentCommand.buffer.toString('hex')) { // NO-OP + // This is just a confirmation for the command we just sent? } else if (data[0] % 2 === 0) { // NO-OP - // This used to be noble multi role stuff + // This used to be noble multi role stuff - these are all commands meant for a central node } else if (data[0] === CONST.ATT_OP_HANDLE_NOTIFY || data[0] === CONST.ATT_OP_HANDLE_IND) { /*const valueHandle = data.readUInt16LE(1); @@ -71,31 +82,22 @@ class HciGattRemote extends models_1.GattRemote { // this.aclStream.encrypt(); return; } - this.currentCommand.resolve(data); - this.currentCommand = null; - this.processCommands(); + this.currentCommand.onResponse(data); } }; this.hci = hci; this.hci.on('aclDataPkt', this.onAclStreamData); + this.hci.on('stateChange', this.onHciStateChange); + this.mutex = new async_mutex_1.Mutex(); this.handle = handle; } - processCommands() { - while (this.commandQueue.length) { - this.currentCommand = this.commandQueue.shift(); - this.writeAtt(this.currentCommand.buffer); - if (this.currentCommand.resolve) { - // If the command has a callback stop processing and wait for the callback - break; - } - else if (this.currentCommand.resolveOnWrite) { - this.currentCommand.resolveOnWrite(); - this.currentCommand = null; - } - } - } dispose() { + if (this.currentCommand) { + this.currentCommand.onResponse(null); + this.currentCommand = null; + } this.hci.off('aclDataPkt', this.onAclStreamData); + this.hci.off('stateChange', this.onHciStateChange); this.hci = null; this.handle = null; } @@ -111,14 +113,25 @@ class HciGattRemote extends models_1.GattRemote { return buf; } async queueCommand(buffer, resolveOnWrite) { - return new Promise((resolve) => { - this.commandQueue.push({ + const release = await this.mutex.acquire(); + return new Promise((resolve, reject) => { + const onDone = (data) => { + this.currentCommand = null; + release(); + if (data === null) { + reject(`GATT command failed`); + } + else { + resolve(data); + } + }; + this.currentCommand = { buffer: buffer, - resolve: !resolveOnWrite ? (data) => resolve(data) : undefined, - resolveOnWrite: resolveOnWrite ? () => resolve() : undefined - }); - if (!this.currentCommand) { - this.processCommands(); + onResponse: onDone + }; + this.writeAtt(buffer); + if (resolveOnWrite) { + onDone(); } }); } @@ -195,11 +208,15 @@ class HciGattRemote extends models_1.GattRemote { return buf; } async exchangeMtu(mtu) { + if (this.mtuWasExchanged) { + return this.mtu; + } const data = await this.queueCommand(this.mtuRequest(mtu), false); const opcode = data[0]; if (opcode === CONST.ATT_OP_MTU_RESP) { const newMtu = data.readUInt16LE(1); this._mtu = Math.min(mtu, newMtu); + this.mtuWasExchanged = true; } else { throw new Error('Exchanging mtu failed'); diff --git a/lib/bindings/hci/gatt/remote/Gatt.js.map b/lib/bindings/hci/gatt/remote/Gatt.js.map index a821f0f8..92e03b38 100644 --- a/lib/bindings/hci/gatt/remote/Gatt.js.map +++ b/lib/bindings/hci/gatt/remote/Gatt.js.map @@ -1 +1 @@ -{"version":3,"file":"Gatt.js","sourceRoot":"","sources":["../../../../../src/bindings/hci/gatt/remote/Gatt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4D;AAE5D,oDAAsC;AAEtC,qDAA+D;AAC/D,6CAAuD;AACvD,uCAAiD;AAQjD,MAAa,aAAc,SAAQ,mBAAU;IAW5C,YAAmB,UAAsB,EAAE,GAAQ,EAAE,MAAc;QAClE,KAAK,CAAC,UAAU,CAAC,CAAC;QANX,mBAAc,GAAgB,IAAI,CAAC;QACnC,iBAAY,GAAkB,EAAE,CAAC;QAElC,aAAQ,GAAsC,IAAI,GAAG,EAAE,CAAC;QAiCvD,oBAAe,GAAG,KAAK,EAAE,MAAc,EAAE,GAAW,EAAE,IAAY,EAAE,EAAE;YAC7E,IAAI,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,OAAO,EAAE;gBACpD,OAAO;aACP;YAED,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,Q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indings/hci/gatt/remote/Gatt.ts index 2e2df560..45dd2770 100644 --- a/src/bindings/hci/gatt/remote/Gatt.ts +++ b/src/bindings/hci/gatt/remote/Gatt.ts @@ -1,3 +1,5 @@ +import { Mutex } from 'async-mutex'; + import { GattRemote, Peripheral } from '../../../../models'; import { Hci } from '../../misc'; import * as CONST from '../Constants'; @@ -8,8 +10,7 @@ import { HciGattServiceRemote } from './Service'; interface GattCommand { buffer: Buffer; - resolve: (data: Buffer) => void; - resolveOnWrite: () => void; + onResponse: (data: Buffer) => void; } export class HciGattRemote extends GattRemote { @@ -17,9 +18,10 @@ export class HciGattRemote extends GattRemote { private handle: number; private security: string; + private mtuWasExchanged: boolean = false; + private mutex: Mutex; private currentCommand: GattCommand = null; - private commandQueue: GattCommand[] = []; public services: Map = new Map(); @@ -28,32 +30,35 @@ export class HciGattRemote extends GattRemote { this.hci = hci; this.hci.on('aclDataPkt', this.onAclStreamData); + this.hci.on('stateChange', this.onHciStateChange); + this.mutex = new Mutex(); this.handle = handle; } - private processCommands() { - while (this.commandQueue.length) { - this.currentCommand = this.commandQueue.shift(); - - this.writeAtt(this.currentCommand.buffer); - - if (this.currentCommand.resolve) { - // If the command has a callback stop processing and wait for the callback - break; - } else if (this.currentCommand.resolveOnWrite) { - this.currentCommand.resolveOnWrite(); - this.currentCommand = null; - } + public dispose() { + if (this.currentCommand) { + this.currentCommand.onResponse(null); + this.currentCommand = null; } - } - public dispose() { this.hci.off('aclDataPkt', this.onAclStreamData); + this.hci.off('stateChange', this.onHciStateChange); this.hci = null; + this.handle = null; } + private onHciStateChange = async (newState: string) => { + // If the underlaying socket shuts down we're doomed + if (newState === 'poweredOff') { + if (this.currentCommand) { + this.currentCommand.onResponse(null); + this.currentCommand = null; + } + } + }; + private onAclStreamData = async (handle: number, cid: number, data: Buffer) => { if (handle !== this.handle || cid !== CONST.ATT_CID) { return; @@ -61,9 +66,10 @@ export class HciGattRemote extends GattRemote { if (this.currentCommand && data.toString('hex') === this.currentCommand.buffer.toString('hex')) { // NO-OP + // This is just a confirmation for the command we just sent? } else if (data[0] % 2 === 0) { // NO-OP - // This used to be noble multi role stuff + // This used to be noble multi role stuff - these are all commands meant for a central node } else if (data[0] === CONST.ATT_OP_HANDLE_NOTIFY || data[0] === CONST.ATT_OP_HANDLE_IND) { /*const valueHandle = data.readUInt16LE(1); const valueData = data.slice(3); @@ -96,10 +102,7 @@ export class HciGattRemote extends GattRemote { return; } - this.currentCommand.resolve(data); - - this.currentCommand = null; - this.processCommands(); + this.currentCommand.onResponse(data); } }; @@ -121,15 +124,30 @@ export class HciGattRemote extends GattRemote { private async queueCommand(buffer: Buffer, resolveOnWrite: true): Promise; private async queueCommand(buffer: Buffer, resolveOnWrite: false): Promise; private async queueCommand(buffer: Buffer, resolveOnWrite: boolean) { - return new Promise((resolve) => { - this.commandQueue.push({ + const release = await this.mutex.acquire(); + + return new Promise((resolve, reject) => { + const onDone = (data?: Buffer) => { + this.currentCommand = null; + + release(); + + if (data === null) { + reject(`GATT command failed`); + } else { + resolve(data); + } + }; + + this.currentCommand = { buffer: buffer, - resolve: !resolveOnWrite ? (data) => resolve(data) : undefined, - resolveOnWrite: resolveOnWrite ? () => resolve() : undefined - }); + onResponse: onDone + }; - if (!this.currentCommand) { - this.processCommands(); + this.writeAtt(buffer); + + if (resolveOnWrite) { + onDone(); } }); } @@ -239,12 +257,17 @@ export class HciGattRemote extends GattRemote { } public async exchangeMtu(mtu: number) { + if (this.mtuWasExchanged) { + return this.mtu; + } + const data = await this.queueCommand(this.mtuRequest(mtu), false); const opcode = data[0]; if (opcode === CONST.ATT_OP_MTU_RESP) { const newMtu = data.readUInt16LE(1); this._mtu = Math.min(mtu, newMtu); + this.mtuWasExchanged = true; } else { throw new Error('Exchanging mtu failed'); }