@onekeyfe/hd-transport-react-native 1.2.2-alpha.100 → 1.2.2-alpha.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bleStaleBond.d.ts +5 -0
- package/dist/bleStaleBond.d.ts.map +1 -0
- package/dist/bleStrategy.d.ts +1 -1
- package/dist/bleStrategy.d.ts.map +1 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +199 -73
- package/package.json +5 -5
- package/src/__tests__/bleStaleBond.test.ts +47 -0
- package/src/__tests__/bleStrategy.test.ts +2 -3
- package/src/__tests__/protocolV2Link.test.ts +286 -16
- package/src/bleStaleBond.ts +64 -0
- package/src/bleStrategy.ts +1 -3
- package/src/index.ts +231 -77
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { isBleStaleBondHardwareError } from '@onekeyfe/hd-shared';
|
|
2
|
+
export { isBleStaleBondHardwareError };
|
|
3
|
+
export declare const isNativeBleStaleBondError: (error: unknown) => boolean;
|
|
4
|
+
export declare const toBleStaleBondHardwareError: (error: unknown) => Error;
|
|
5
|
+
//# sourceMappingURL=bleStaleBond.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bleStaleBond.d.ts","sourceRoot":"","sources":["../src/bleStaleBond.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,2BAA2B,EAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,2BAA2B,EAAE,CAAC;AAmBvC,eAAO,MAAM,yBAAyB,UAAW,OAAO,KAAG,OAiB1D,CAAC;AAEF,eAAO,MAAM,2BAA2B,UAAW,OAAO,UAkBzD,CAAC"}
|
package/dist/bleStrategy.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function resolveProtocolV2PacketCapacity({ platform, iosPacketLen
|
|
|
11
11
|
mtu?: number | null;
|
|
12
12
|
}): number;
|
|
13
13
|
export declare function shouldRefreshNegotiatedMtu(mtu?: number | null): boolean;
|
|
14
|
-
export declare function shouldWriteProtocolV2WithResponse({
|
|
14
|
+
export declare function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }: {
|
|
15
15
|
platform: BlePlatform;
|
|
16
16
|
highThroughput: boolean;
|
|
17
17
|
requestedWithResponse?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAEvE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAA+C,EAC/C,mBAAuD,EACvD,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAMA;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAE7D;AAED,wBAAgB,iCAAiC,CAAC,EAChD,
|
|
1
|
+
{"version":3,"file":"bleStrategy.d.ts","sourceRoot":"","sources":["../src/bleStrategy.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,yBAAyB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC5C,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,kBAAkB,WAEvE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,eAA+C,EAC/C,mBAAuD,EACvD,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,UAMA;AAED,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,WAE7D;AAED,wBAAgB,iCAAiC,CAAC,EAChD,qBAAqB,EACrB,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,WAAW,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,kBAAkB,CAAC;CACpC,WAIA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,14 @@ type BleAcquireInput = {
|
|
|
38
38
|
protocolHint?: ProtocolType;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
type FirmwareInstallBleAcquireInput = BleAcquireInput & {
|
|
42
|
+
/**
|
|
43
|
+
* Reuse the already-verified protocol after an expected firmware-install
|
|
44
|
+
* disconnect. The install loader accepts status requests but may not answer
|
|
45
|
+
* the generic protocol probe used by a normal acquire.
|
|
46
|
+
*/
|
|
47
|
+
skipProtocolProbe?: boolean;
|
|
48
|
+
};
|
|
41
49
|
type FirmwareUploadWriteRetryType = 'congested';
|
|
42
50
|
type ResolvedBleCharacteristics = {
|
|
43
51
|
writeCharacteristic: Characteristic;
|
|
@@ -126,6 +134,14 @@ declare class ReactNativeBleTransport {
|
|
|
126
134
|
private confirmedProtocolV2;
|
|
127
135
|
/** Consecutive detections that failed while trusting sessionProtocols. */
|
|
128
136
|
private protocolReprobeFailures;
|
|
137
|
+
/**
|
|
138
|
+
* Native encryption/pairing failures seen before Protocol V2 probe starts.
|
|
139
|
+
* Pro2/Neo GATT connect can succeed on a stale iOS bond; the CCCD write then
|
|
140
|
+
* fails with ATT 5/15. Remember it so detectProtocol fails immediately.
|
|
141
|
+
*/
|
|
142
|
+
private staleBondErrors;
|
|
143
|
+
/** Strict or previously confirmed V2 target while acquire installs notifications. */
|
|
144
|
+
private acquiringProtocolV2;
|
|
129
145
|
private protocolV2Assemblers;
|
|
130
146
|
private protocolV2FrameQueues;
|
|
131
147
|
private protocolV2FramePromises;
|
|
@@ -155,7 +171,7 @@ declare class ReactNativeBleTransport {
|
|
|
155
171
|
*/
|
|
156
172
|
enumerate(): Promise<IOneKeyDevice[]>;
|
|
157
173
|
private installTransportForAcquire;
|
|
158
|
-
acquire(input:
|
|
174
|
+
acquire(input: FirmwareInstallBleAcquireInput): Promise<{
|
|
159
175
|
uuid: string;
|
|
160
176
|
protocolType: ProtocolType;
|
|
161
177
|
}>;
|
|
@@ -216,6 +232,8 @@ declare class ReactNativeBleTransport {
|
|
|
216
232
|
private resolveProtocolV2Frame;
|
|
217
233
|
private resetProtocolV2Frames;
|
|
218
234
|
private rejectProtocolV2Frames;
|
|
235
|
+
private rememberStaleBondError;
|
|
236
|
+
private throwIfStaleBondError;
|
|
219
237
|
private readProtocolV2Frame;
|
|
220
238
|
private writeProtocolV2Packet;
|
|
221
239
|
private writeProtocolV2Frame;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAGL,UAAU,IAAI,aAAa,EAG5B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,SAAS,EAAE,EAChB,KAAK,oBAAoB,EAIzB,KAAK,YAAY,EAKjB,KAAK,oB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ClB,iCAAiC;IA+C/C,OAAO,CAAC,wBAAwB;IAoChC,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,kBAAkB;YAcZ,cAAc;IA8C5B,OAAO,CAAC,kBAAkB;IA+B1B,OAAO,CAAC,eAAe;IAsDvB,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,4BAA4B;IAOpC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;YAIX,cAAc;YAuGd,iCAAiC;YAoDjC,eAAe;YAwBf,eAAe;IA4B7B,OAAO,CAAC,4BAA4B;IA2BpC,OAAO,CAAC,uBAAuB;IAS/B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,qBAAqB;YAOf,mBAAmB;YAiBnB,qBAAqB;YAgErB,oBAAoB;YAgCpB,cAAc;YAqEd,iCAAiC;IAiB/C,OAAO,CAAC,8BAA8B;YAQxB,mCAAmC;IAsBjD,OAAO,CAAC,yCAAyC;YAanC,gCAAgC;IAoB9C,OAAO,CAAC,uBAAuB;IAmD/B,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAGxD"}
|
package/dist/index.js
CHANGED
|
@@ -144,12 +144,12 @@ function resolveProtocolV2PacketCapacity({ platform, iosPacketLength = IOS_PROTO
|
|
|
144
144
|
function shouldRefreshNegotiatedMtu(mtu) {
|
|
145
145
|
return typeof mtu !== 'number' || !Number.isFinite(mtu) || mtu <= 23;
|
|
146
146
|
}
|
|
147
|
-
function shouldWriteProtocolV2WithResponse({
|
|
147
|
+
function shouldWriteProtocolV2WithResponse({ requestedWithResponse, characteristic, }) {
|
|
148
148
|
if (!characteristic.isWritableWithResponse)
|
|
149
149
|
return false;
|
|
150
150
|
if (!characteristic.isWritableWithoutResponse)
|
|
151
151
|
return true;
|
|
152
|
-
return requestedWithResponse === true
|
|
152
|
+
return requestedWithResponse === true;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
const timer = process.env.NODE_ENV === 'development'
|
|
@@ -194,6 +194,40 @@ const subscribeBleOn = (bleManager, ms = 1000) => new Promise((resolve, reject)
|
|
|
194
194
|
}, ms);
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
+
const ATT_INSUFFICIENT_AUTHENTICATION = 5;
|
|
198
|
+
const ATT_INSUFFICIENT_ENCRYPTION = 15;
|
|
199
|
+
const IOS_PEER_REMOVED_PAIRING_INFORMATION = 14;
|
|
200
|
+
const nativeErrorText = (error) => [error.reason, error.message]
|
|
201
|
+
.filter((value) => typeof value === 'string')
|
|
202
|
+
.join(' ');
|
|
203
|
+
const isNativeBleStaleBondError = (error) => {
|
|
204
|
+
if (!error || typeof error !== 'object') {
|
|
205
|
+
return typeof error === 'string' ? hdShared.isBleStaleBondErrorText(error) : false;
|
|
206
|
+
}
|
|
207
|
+
const nativeError = error;
|
|
208
|
+
if (nativeError.attErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
209
|
+
nativeError.attErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
210
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_AUTHENTICATION ||
|
|
211
|
+
nativeError.androidErrorCode === ATT_INSUFFICIENT_ENCRYPTION ||
|
|
212
|
+
nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
return hdShared.isBleStaleBondErrorText(nativeErrorText(nativeError));
|
|
216
|
+
};
|
|
217
|
+
const toBleStaleBondHardwareError = (error) => {
|
|
218
|
+
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
219
|
+
return error;
|
|
220
|
+
}
|
|
221
|
+
const nativeError = (error !== null && error !== void 0 ? error : {});
|
|
222
|
+
const text = nativeErrorText(nativeError);
|
|
223
|
+
const normalizedText = text.toLowerCase();
|
|
224
|
+
const peerRemoved = nativeError.iosErrorCode === IOS_PEER_REMOVED_PAIRING_INFORMATION ||
|
|
225
|
+
normalizedText.includes('peer removed pairing information');
|
|
226
|
+
return hdShared.ERRORS.TypedError(peerRemoved
|
|
227
|
+
? hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation
|
|
228
|
+
: hdShared.HardwareErrorCode.BleDeviceBondError, text || undefined);
|
|
229
|
+
};
|
|
230
|
+
|
|
197
231
|
const isHeaderChunk = (chunk) => {
|
|
198
232
|
if (chunk.length < 9)
|
|
199
233
|
return false;
|
|
@@ -375,9 +409,8 @@ const resolveNegotiatedMtu = (device) => requestNegotiatedMtu(device, 'connected
|
|
|
375
409
|
function remapError(error) {
|
|
376
410
|
var _a;
|
|
377
411
|
if (error instanceof reactNativeBlePlx.BleError) {
|
|
378
|
-
if (error
|
|
379
|
-
error
|
|
380
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
|
|
412
|
+
if (isNativeBleStaleBondError(error)) {
|
|
413
|
+
throw toBleStaleBondHardwareError(error);
|
|
381
414
|
}
|
|
382
415
|
if ((error === null || error === void 0 ? void 0 : error.attErrorCode) === 22) {
|
|
383
416
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceBondError);
|
|
@@ -408,6 +441,8 @@ class ReactNativeBleTransport {
|
|
|
408
441
|
this.sessionProtocols = new Map();
|
|
409
442
|
this.confirmedProtocolV2 = new Set();
|
|
410
443
|
this.protocolReprobeFailures = new Map();
|
|
444
|
+
this.staleBondErrors = new Map();
|
|
445
|
+
this.acquiringProtocolV2 = new Set();
|
|
411
446
|
this.protocolV2Assemblers = new Map();
|
|
412
447
|
this.protocolV2FrameQueues = new Map();
|
|
413
448
|
this.protocolV2FramePromises = new Map();
|
|
@@ -802,19 +837,46 @@ class ReactNativeBleTransport {
|
|
|
802
837
|
acquireUnlocked(input) {
|
|
803
838
|
var _a;
|
|
804
839
|
return __awaiter(this, void 0, void 0, function* () {
|
|
805
|
-
const { uuid, forceCleanRunPromise, expectedProtocol } = input;
|
|
840
|
+
const { uuid, forceCleanRunPromise, expectedProtocol, skipProtocolProbe } = input;
|
|
841
|
+
const shouldMapProtocolV2StaleBond = expectedProtocol
|
|
842
|
+
? expectedProtocol === 'V2'
|
|
843
|
+
: this.confirmedProtocolV2.has(uuid);
|
|
806
844
|
const cachedTransport = transportCache[uuid];
|
|
845
|
+
if (skipProtocolProbe && !cachedTransport && this.blePlxManager) {
|
|
846
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh uncached BLE connection for firmware install:', uuid);
|
|
847
|
+
const manager = this.blePlxManager;
|
|
848
|
+
yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
|
|
849
|
+
yield this.runBestEffortNativeOperation('firmware install reconnect: cancel uncached device connection', () => manager.cancelDeviceConnection(uuid));
|
|
850
|
+
}));
|
|
851
|
+
}
|
|
807
852
|
if (cachedTransport) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
(
|
|
813
|
-
|
|
814
|
-
|
|
853
|
+
if (skipProtocolProbe) {
|
|
854
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] refresh cached BLE connection for firmware install:', uuid);
|
|
855
|
+
const manager = this.blePlxManager;
|
|
856
|
+
yield this.releaseUnlocked(uuid, true);
|
|
857
|
+
yield this.runNativeTeardown(uuid, manager, () => __awaiter(this, void 0, void 0, function* () {
|
|
858
|
+
const operations = [];
|
|
859
|
+
if (manager) {
|
|
860
|
+
operations.push(this.runBestEffortNativeOperation('firmware install reconnect: cancel device connection', () => manager.cancelDeviceConnection(uuid)));
|
|
861
|
+
}
|
|
862
|
+
operations.push(this.runBestEffortNativeOperation('firmware install reconnect: device cancel connection', () => cachedTransport.device.cancelConnection()));
|
|
863
|
+
yield Promise.all(operations);
|
|
864
|
+
}));
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
const cachedProtocol = this.deviceProtocol.get(uuid);
|
|
868
|
+
const isCachedDeviceConnected = yield cachedTransport.device
|
|
869
|
+
.isConnected()
|
|
870
|
+
.catch(() => false);
|
|
871
|
+
if (isCachedDeviceConnected &&
|
|
872
|
+
cachedProtocol &&
|
|
873
|
+
(!expectedProtocol || cachedProtocol === expectedProtocol)) {
|
|
874
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] reuse cached BLE transport:', uuid, cachedProtocol);
|
|
875
|
+
return { uuid, protocolType: cachedProtocol };
|
|
876
|
+
}
|
|
877
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
|
|
878
|
+
yield this.releaseUnlocked(uuid, true);
|
|
815
879
|
}
|
|
816
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('transport not reusable, will release: ', uuid);
|
|
817
|
-
yield this.releaseUnlocked(uuid, true);
|
|
818
880
|
}
|
|
819
881
|
let device = null;
|
|
820
882
|
if (forceCleanRunPromise && this.runPromise) {
|
|
@@ -832,15 +894,6 @@ class ReactNativeBleTransport {
|
|
|
832
894
|
Log === null || Log === void 0 ? void 0 : Log.debug('subscribeBleOn error: ', error);
|
|
833
895
|
throw error;
|
|
834
896
|
}
|
|
835
|
-
if (reactNative.Platform.OS === 'android') {
|
|
836
|
-
const bondState = yield pairDevice(uuid);
|
|
837
|
-
if (bondState.bonding) {
|
|
838
|
-
yield onDeviceBondState(uuid);
|
|
839
|
-
}
|
|
840
|
-
else if (!bondState.bonded) {
|
|
841
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
897
|
if (!device) {
|
|
845
898
|
const devices = yield blePlxManager.devices([uuid]);
|
|
846
899
|
[device] = devices;
|
|
@@ -895,13 +948,16 @@ class ReactNativeBleTransport {
|
|
|
895
948
|
try {
|
|
896
949
|
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
|
|
897
950
|
}
|
|
898
|
-
catch (
|
|
899
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ',
|
|
900
|
-
if (
|
|
951
|
+
catch (fallbackError) {
|
|
952
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect error: ', fallbackError);
|
|
953
|
+
if (fallbackError.errorCode === reactNativeBlePlx.BleErrorCode.OperationCancelled) {
|
|
901
954
|
Log === null || Log === void 0 ? void 0 : Log.debug('last try to reconnect');
|
|
902
955
|
yield disconnectedDevice.cancelConnection();
|
|
903
956
|
device = yield this.connectWithTimeout(uuid, () => disconnectedDevice.connect(fallbackConnectOptions));
|
|
904
957
|
}
|
|
958
|
+
else {
|
|
959
|
+
remapError(fallbackError);
|
|
960
|
+
}
|
|
905
961
|
}
|
|
906
962
|
}
|
|
907
963
|
else {
|
|
@@ -909,6 +965,30 @@ class ReactNativeBleTransport {
|
|
|
909
965
|
}
|
|
910
966
|
}
|
|
911
967
|
}
|
|
968
|
+
if (reactNative.Platform.OS === 'android') {
|
|
969
|
+
const connectedDevice = device;
|
|
970
|
+
try {
|
|
971
|
+
if (!(yield connectedDevice.isConnected().catch(() => false))) {
|
|
972
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleConnectedError, `Device ${uuid} is not connected before bonding`);
|
|
973
|
+
}
|
|
974
|
+
const bondState = yield pairDevice(uuid);
|
|
975
|
+
if (bondState.bonding) {
|
|
976
|
+
yield onDeviceBondState(uuid);
|
|
977
|
+
}
|
|
978
|
+
else if (!bondState.bonded) {
|
|
979
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleDeviceNotBonded, 'device is not bonded');
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
catch (error) {
|
|
983
|
+
yield this.runNativeTeardown(uuid, blePlxManager, () => __awaiter(this, void 0, void 0, function* () {
|
|
984
|
+
yield Promise.all([
|
|
985
|
+
this.runBestEffortNativeOperation('bond failure: cancel manager connection', () => blePlxManager.cancelDeviceConnection(uuid)),
|
|
986
|
+
this.runBestEffortNativeOperation('bond failure: cancel device connection', () => connectedDevice.cancelConnection()),
|
|
987
|
+
]);
|
|
988
|
+
}));
|
|
989
|
+
throw error;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
912
992
|
device = yield resolveNegotiatedMtu(device);
|
|
913
993
|
const acquiredDevice = device;
|
|
914
994
|
const { writeCharacteristic, notifyCharacteristic } = yield this.resolveCharacteristicsWithTimeout(uuid, acquiredDevice);
|
|
@@ -919,11 +999,38 @@ class ReactNativeBleTransport {
|
|
|
919
999
|
if (protocolHint) {
|
|
920
1000
|
this.deviceProtocolHints.set(uuid, protocolHint);
|
|
921
1001
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
});
|
|
1002
|
+
if (shouldMapProtocolV2StaleBond) {
|
|
1003
|
+
this.acquiringProtocolV2.add(uuid);
|
|
1004
|
+
}
|
|
926
1005
|
try {
|
|
1006
|
+
yield this.installTransportForAcquire(uuid, acquiredDevice, {
|
|
1007
|
+
writeCharacteristic,
|
|
1008
|
+
notifyCharacteristic,
|
|
1009
|
+
});
|
|
1010
|
+
if (skipProtocolProbe) {
|
|
1011
|
+
if (!expectedProtocol) {
|
|
1012
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires an expected BLE protocol');
|
|
1013
|
+
}
|
|
1014
|
+
const hasConfirmedProtocol = this.sessionProtocols.get(uuid) === expectedProtocol ||
|
|
1015
|
+
(expectedProtocol === 'V2' && this.confirmedProtocolV2.has(uuid));
|
|
1016
|
+
if (!hasConfirmedProtocol) {
|
|
1017
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'skipProtocolProbe requires a previously confirmed protocol for this BLE endpoint');
|
|
1018
|
+
}
|
|
1019
|
+
this.deviceProtocol.set(uuid, expectedProtocol);
|
|
1020
|
+
this.sessionProtocols.set(uuid, expectedProtocol);
|
|
1021
|
+
this.protocolReprobeFailures.delete(uuid);
|
|
1022
|
+
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected without probe', {
|
|
1023
|
+
deviceId: uuid,
|
|
1024
|
+
protocol: expectedProtocol,
|
|
1025
|
+
source: 'firmware-install-reconnect',
|
|
1026
|
+
});
|
|
1027
|
+
const currentTransport = transportCache[uuid];
|
|
1028
|
+
if (!currentTransport) {
|
|
1029
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotFound);
|
|
1030
|
+
}
|
|
1031
|
+
this.attachDisconnectSubscription(currentTransport, currentTransport.device, uuid);
|
|
1032
|
+
return { uuid, protocolType: expectedProtocol };
|
|
1033
|
+
}
|
|
927
1034
|
const protocolType = yield this.detectProtocol(uuid, expectedProtocol, protocolHint, () => __awaiter(this, void 0, void 0, function* () {
|
|
928
1035
|
yield this.installTransportForAcquire(uuid, acquiredDevice);
|
|
929
1036
|
}));
|
|
@@ -935,7 +1042,7 @@ class ReactNativeBleTransport {
|
|
|
935
1042
|
return { uuid, protocolType };
|
|
936
1043
|
}
|
|
937
1044
|
catch (error) {
|
|
938
|
-
if ((error
|
|
1045
|
+
if (hdShared.isBleStaleBondHardwareError(error)) {
|
|
939
1046
|
yield this.disconnectUnlocked(uuid);
|
|
940
1047
|
}
|
|
941
1048
|
else {
|
|
@@ -943,13 +1050,16 @@ class ReactNativeBleTransport {
|
|
|
943
1050
|
}
|
|
944
1051
|
throw error;
|
|
945
1052
|
}
|
|
1053
|
+
finally {
|
|
1054
|
+
this.acquiringProtocolV2.delete(uuid);
|
|
1055
|
+
}
|
|
946
1056
|
});
|
|
947
1057
|
}
|
|
948
1058
|
_monitorCharacteristic(characteristic, uuid, monitorToken, notifyTransactionId) {
|
|
949
1059
|
let bufferLength = 0;
|
|
950
1060
|
let buffer$1 = [];
|
|
951
1061
|
const subscription = characteristic.monitor((error, c) => {
|
|
952
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
1062
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
953
1063
|
const isCurrentMonitor = this.monitorTokens.get(uuid) === monitorToken;
|
|
954
1064
|
if (error) {
|
|
955
1065
|
Log === null || Log === void 0 ? void 0 : Log.debug(`error monitor ${characteristic.uuid}, deviceId: ${characteristic.deviceID}: ${error}`);
|
|
@@ -961,19 +1071,21 @@ class ReactNativeBleTransport {
|
|
|
961
1071
|
Log === null || Log === void 0 ? void 0 : Log.debug('monitor error ignored for stale transport: ', uuid, notifyTransactionId);
|
|
962
1072
|
return;
|
|
963
1073
|
}
|
|
1074
|
+
if ((this.getActiveProtocol(uuid) === 'V2' || this.acquiringProtocolV2.has(uuid)) &&
|
|
1075
|
+
isNativeBleStaleBondError(error)) {
|
|
1076
|
+
this.rememberStaleBondError(uuid, toBleStaleBondHardwareError(error));
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
964
1079
|
if (this.getActiveProtocol(uuid) === 'V2') {
|
|
965
1080
|
let errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
966
1081
|
if ((_a = error.reason) === null || _a === void 0 ? void 0 : _a.includes('The connection has timed out unexpectedly')) {
|
|
967
1082
|
errorCode = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
968
1083
|
}
|
|
969
|
-
else if ((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
((
|
|
974
|
-
((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('The handle is invalid')) ||
|
|
975
|
-
((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('Writing is not permitted')) ||
|
|
976
|
-
((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('notify change failed for device'))) {
|
|
1084
|
+
else if (((_b = error.reason) === null || _b === void 0 ? void 0 : _b.includes('Cannot write client characteristic config descriptor')) ||
|
|
1085
|
+
((_c = error.reason) === null || _c === void 0 ? void 0 : _c.includes('Cannot find client characteristic config descriptor')) ||
|
|
1086
|
+
((_d = error.reason) === null || _d === void 0 ? void 0 : _d.includes('The handle is invalid')) ||
|
|
1087
|
+
((_e = error.reason) === null || _e === void 0 ? void 0 : _e.includes('Writing is not permitted')) ||
|
|
1088
|
+
((_f = error.reason) === null || _f === void 0 ? void 0 : _f.includes('notify change failed for device'))) {
|
|
977
1089
|
errorCode = hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure;
|
|
978
1090
|
}
|
|
979
1091
|
this.rejectProtocolV2Frames(uuid, hdShared.ERRORS.TypedError(errorCode));
|
|
@@ -981,17 +1093,14 @@ class ReactNativeBleTransport {
|
|
|
981
1093
|
}
|
|
982
1094
|
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
983
1095
|
let ERROR = hdShared.HardwareErrorCode.BleCharacteristicNotifyError;
|
|
984
|
-
if ((
|
|
1096
|
+
if ((_g = error.reason) === null || _g === void 0 ? void 0 : _g.includes('The connection has timed out unexpectedly')) {
|
|
985
1097
|
ERROR = hdShared.HardwareErrorCode.BleTimeoutError;
|
|
986
1098
|
}
|
|
987
|
-
if ((
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
((
|
|
992
|
-
((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('The handle is invalid')) ||
|
|
993
|
-
((_o = error.reason) === null || _o === void 0 ? void 0 : _o.includes('Writing is not permitted')) ||
|
|
994
|
-
((_p = error.reason) === null || _p === void 0 ? void 0 : _p.includes('notify change failed for device'))) {
|
|
1099
|
+
if (((_h = error.reason) === null || _h === void 0 ? void 0 : _h.includes('Cannot write client characteristic config descriptor')) ||
|
|
1100
|
+
((_j = error.reason) === null || _j === void 0 ? void 0 : _j.includes('Cannot find client characteristic config descriptor')) ||
|
|
1101
|
+
((_k = error.reason) === null || _k === void 0 ? void 0 : _k.includes('The handle is invalid')) ||
|
|
1102
|
+
((_l = error.reason) === null || _l === void 0 ? void 0 : _l.includes('Writing is not permitted')) ||
|
|
1103
|
+
((_m = error.reason) === null || _m === void 0 ? void 0 : _m.includes('notify change failed for device'))) {
|
|
995
1104
|
const notifyError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure);
|
|
996
1105
|
this.runPromise.reject(notifyError);
|
|
997
1106
|
Log === null || Log === void 0 ? void 0 : Log.debug(`${hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure} ${error.message} ${error.reason}`);
|
|
@@ -1033,7 +1142,7 @@ class ReactNativeBleTransport {
|
|
|
1033
1142
|
bufferLength = 0;
|
|
1034
1143
|
buffer$1 = [];
|
|
1035
1144
|
if (this.runPromiseDeviceId === uuid) {
|
|
1036
|
-
(
|
|
1145
|
+
(_o = this.runPromise) === null || _o === void 0 ? void 0 : _o.resolve(value.toString('hex'));
|
|
1037
1146
|
}
|
|
1038
1147
|
}
|
|
1039
1148
|
}
|
|
@@ -1044,7 +1153,7 @@ class ReactNativeBleTransport {
|
|
|
1044
1153
|
this.rejectProtocolV2Frames(uuid, notifyError);
|
|
1045
1154
|
}
|
|
1046
1155
|
else if (this.runPromiseDeviceId === uuid) {
|
|
1047
|
-
(
|
|
1156
|
+
(_p = this.runPromise) === null || _p === void 0 ? void 0 : _p.reject(notifyError);
|
|
1048
1157
|
}
|
|
1049
1158
|
}
|
|
1050
1159
|
}, notifyTransactionId);
|
|
@@ -1098,6 +1207,8 @@ class ReactNativeBleTransport {
|
|
|
1098
1207
|
this.protocolV2HighVolumeLogSignatures.delete(uuid);
|
|
1099
1208
|
this.deviceProtocol.delete(uuid);
|
|
1100
1209
|
this.probingProtocols.delete(uuid);
|
|
1210
|
+
this.staleBondErrors.delete(uuid);
|
|
1211
|
+
this.acquiringProtocolV2.delete(uuid);
|
|
1101
1212
|
(_e = this.protocolV2Assemblers.get(uuid)) === null || _e === void 0 ? void 0 : _e.reset();
|
|
1102
1213
|
this.protocolV2Assemblers.delete(uuid);
|
|
1103
1214
|
this.resetProtocolV2Frames(uuid);
|
|
@@ -1383,6 +1494,7 @@ class ReactNativeBleTransport {
|
|
|
1383
1494
|
}
|
|
1384
1495
|
this.deviceProtocol.delete(session);
|
|
1385
1496
|
this.probingProtocols.delete(session);
|
|
1497
|
+
this.staleBondErrors.delete(session);
|
|
1386
1498
|
this.deviceProtocolHints.delete(session);
|
|
1387
1499
|
this.sessionProtocols.delete(session);
|
|
1388
1500
|
this.protocolReprobeFailures.delete(session);
|
|
@@ -1561,6 +1673,8 @@ class ReactNativeBleTransport {
|
|
|
1561
1673
|
}
|
|
1562
1674
|
this.deviceProtocol.delete(uuid);
|
|
1563
1675
|
this.probingProtocols.delete(uuid);
|
|
1676
|
+
this.staleBondErrors.delete(uuid);
|
|
1677
|
+
this.acquiringProtocolV2.delete(uuid);
|
|
1564
1678
|
this.protocolV2Assemblers.delete(uuid);
|
|
1565
1679
|
this.resetProtocolV2Frames(uuid);
|
|
1566
1680
|
if (timeouts >= BLE_CONNECT_TIMEOUT_MANAGER_RESET_THRESHOLD) {
|
|
@@ -1630,6 +1744,8 @@ class ReactNativeBleTransport {
|
|
|
1630
1744
|
}
|
|
1631
1745
|
this.deviceProtocol.delete(uuid);
|
|
1632
1746
|
this.probingProtocols.delete(uuid);
|
|
1747
|
+
this.staleBondErrors.delete(uuid);
|
|
1748
|
+
this.acquiringProtocolV2.delete(uuid);
|
|
1633
1749
|
this.protocolV2Assemblers.delete(uuid);
|
|
1634
1750
|
this.resetProtocolV2Frames(uuid);
|
|
1635
1751
|
if (timeouts >= BLE_WRITE_TIMEOUT_MANAGER_RESET_THRESHOLD) {
|
|
@@ -1672,8 +1788,9 @@ class ReactNativeBleTransport {
|
|
|
1672
1788
|
});
|
|
1673
1789
|
this.deviceProtocol.clear();
|
|
1674
1790
|
this.probingProtocols.clear();
|
|
1791
|
+
this.staleBondErrors.clear();
|
|
1792
|
+
this.acquiringProtocolV2.clear();
|
|
1675
1793
|
this.sessionProtocols.clear();
|
|
1676
|
-
this.confirmedProtocolV2.clear();
|
|
1677
1794
|
this.protocolReprobeFailures.clear();
|
|
1678
1795
|
this.writeTimeoutCounts.clear();
|
|
1679
1796
|
this.connectionSetupTimeoutCounts.clear();
|
|
@@ -1686,9 +1803,8 @@ class ReactNativeBleTransport {
|
|
|
1686
1803
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] BLE manager destroy failed (ignored):', error);
|
|
1687
1804
|
}
|
|
1688
1805
|
}
|
|
1689
|
-
createProtocolMismatchError(expected
|
|
1690
|
-
|
|
1691
|
-
return hdShared.ERRORS.TypedError(isStaleV2Bond ? hdShared.HardwareErrorCode.BleDeviceBondError : hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1806
|
+
createProtocolMismatchError(expected) {
|
|
1807
|
+
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expected}, but device did not respond to expected protocol`);
|
|
1692
1808
|
}
|
|
1693
1809
|
createProtocolDetectionError() {
|
|
1694
1810
|
return hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BleTimeoutError, 'Unable to detect BLE protocol: device did not respond to Protocol V1 GetFeatures or Protocol V2 Ping');
|
|
@@ -1708,27 +1824,17 @@ class ReactNativeBleTransport {
|
|
|
1708
1824
|
detectProtocol(uuid, expectedProtocol, protocolHint, rebuildTransport) {
|
|
1709
1825
|
var _a;
|
|
1710
1826
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1711
|
-
if (
|
|
1712
|
-
this.deviceProtocol.set(uuid,
|
|
1827
|
+
if (expectedProtocol === 'V1') {
|
|
1828
|
+
this.deviceProtocol.set(uuid, 'V1');
|
|
1713
1829
|
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol selected', {
|
|
1714
1830
|
deviceId: uuid,
|
|
1715
|
-
protocol:
|
|
1831
|
+
protocol: 'V1',
|
|
1716
1832
|
source: 'expected',
|
|
1717
1833
|
});
|
|
1718
|
-
return
|
|
1834
|
+
return 'V1';
|
|
1719
1835
|
}
|
|
1720
|
-
if (expectedProtocol === '
|
|
1721
|
-
|
|
1722
|
-
this.deviceProtocol.set(uuid, 'V1');
|
|
1723
|
-
this.sessionProtocols.set(uuid, 'V1');
|
|
1724
|
-
Log === null || Log === void 0 ? void 0 : Log.debug('[ReactNativeBleTransport] protocol detected', {
|
|
1725
|
-
deviceId: uuid,
|
|
1726
|
-
protocol: 'V1',
|
|
1727
|
-
source: 'expected',
|
|
1728
|
-
});
|
|
1729
|
-
return 'V1';
|
|
1730
|
-
}
|
|
1731
|
-
throw this.createProtocolMismatchError(expectedProtocol, uuid);
|
|
1836
|
+
if (expectedProtocol === 'V2' || this.acquiringProtocolV2.has(uuid)) {
|
|
1837
|
+
this.throwIfStaleBondError(uuid);
|
|
1732
1838
|
}
|
|
1733
1839
|
if (expectedProtocol === 'V2') {
|
|
1734
1840
|
if (yield this.probeProtocolV2(uuid)) {
|
|
@@ -1742,7 +1848,7 @@ class ReactNativeBleTransport {
|
|
|
1742
1848
|
});
|
|
1743
1849
|
return 'V2';
|
|
1744
1850
|
}
|
|
1745
|
-
throw this.createProtocolMismatchError(expectedProtocol
|
|
1851
|
+
throw this.createProtocolMismatchError(expectedProtocol);
|
|
1746
1852
|
}
|
|
1747
1853
|
const sessionProtocol = this.sessionProtocols.get(uuid);
|
|
1748
1854
|
const reprobeFailures = (_a = this.protocolReprobeFailures.get(uuid)) !== null && _a !== void 0 ? _a : 0;
|
|
@@ -1860,6 +1966,7 @@ class ReactNativeBleTransport {
|
|
|
1860
1966
|
}
|
|
1861
1967
|
this.probingProtocols.set(uuid, 'V2');
|
|
1862
1968
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1969
|
+
this.throwIfStaleBondError(uuid);
|
|
1863
1970
|
const detected = yield transport.probeProtocolV2({
|
|
1864
1971
|
call: (name, data, options) => this.callProtocolV2(uuid, name, data, options),
|
|
1865
1972
|
timeoutMs: PROTOCOL_V2_PROBE_TIMEOUT_MS,
|
|
@@ -1870,6 +1977,7 @@ class ReactNativeBleTransport {
|
|
|
1870
1977
|
(_a = this.protocolV2Assemblers.get(uuid)) === null || _a === void 0 ? void 0 : _a.reset();
|
|
1871
1978
|
this.resetProtocolV2Frames(uuid);
|
|
1872
1979
|
},
|
|
1980
|
+
shouldRethrow: hdShared.isBleStaleBondHardwareError,
|
|
1873
1981
|
});
|
|
1874
1982
|
if (!detected) {
|
|
1875
1983
|
this.clearProbeProtocol(uuid, 'V2');
|
|
@@ -1930,6 +2038,19 @@ class ReactNativeBleTransport {
|
|
|
1930
2038
|
framePromise.reject(error);
|
|
1931
2039
|
}
|
|
1932
2040
|
}
|
|
2041
|
+
rememberStaleBondError(uuid, error) {
|
|
2042
|
+
this.staleBondErrors.set(uuid, error);
|
|
2043
|
+
this.rejectProtocolV2Frames(uuid, error);
|
|
2044
|
+
if (this.runPromise && this.runPromiseDeviceId === uuid) {
|
|
2045
|
+
this.runPromise.reject(error);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
throwIfStaleBondError(uuid) {
|
|
2049
|
+
const error = this.staleBondErrors.get(uuid);
|
|
2050
|
+
if (error) {
|
|
2051
|
+
throw error;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
1933
2054
|
readProtocolV2Frame(uuid) {
|
|
1934
2055
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1935
2056
|
const queuedFrame = this.getProtocolV2FrameQueue(uuid).shift();
|
|
@@ -1978,6 +2099,11 @@ class ReactNativeBleTransport {
|
|
|
1978
2099
|
return;
|
|
1979
2100
|
}
|
|
1980
2101
|
catch (error) {
|
|
2102
|
+
if (isNativeBleStaleBondError(error) || hdShared.isBleStaleBondHardwareError(error)) {
|
|
2103
|
+
const bondError = toBleStaleBondHardwareError(error);
|
|
2104
|
+
this.rememberStaleBondError(uuid, bondError);
|
|
2105
|
+
throw bondError;
|
|
2106
|
+
}
|
|
1981
2107
|
if (getFirmwareUploadWriteRetryType(error) !== 'congested' ||
|
|
1982
2108
|
attempt >= FIRMWARE_UPLOAD_WRITE_MAX_RETRIES) {
|
|
1983
2109
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-react-native",
|
|
3
|
-
"version": "1.2.2-alpha.
|
|
3
|
+
"version": "1.2.2-alpha.102",
|
|
4
4
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"lint:fix": "eslint . --fix"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@onekeyfe/hd-core": "1.2.2-alpha.
|
|
24
|
-
"@onekeyfe/hd-shared": "1.2.2-alpha.
|
|
25
|
-
"@onekeyfe/hd-transport": "1.2.2-alpha.
|
|
23
|
+
"@onekeyfe/hd-core": "1.2.2-alpha.102",
|
|
24
|
+
"@onekeyfe/hd-shared": "1.2.2-alpha.102",
|
|
25
|
+
"@onekeyfe/hd-transport": "1.2.2-alpha.102",
|
|
26
26
|
"@onekeyfe/react-native-ble-utils": "^0.1.6",
|
|
27
27
|
"react-native-ble-plx": "3.5.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "abddc95e03d794d9c6fce7765d59de1f48a684d0"
|
|
30
30
|
}
|