-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeDfuNitro.nitro.ts
More file actions
146 lines (127 loc) · 5.12 KB
/
NativeDfuNitro.nitro.ts
File metadata and controls
146 lines (127 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import type { HybridObject } from 'react-native-nitro-modules';
// ─── DFU State ───────────────────────────────────────────────────────────────
export enum DfuState {
Connecting = 0,
Starting = 1,
EnablingDfuMode = 2,
Uploading = 3,
Validating = 4,
Disconnecting = 5,
Completed = 6,
Aborted = 7,
}
// ─── DFU Error ───────────────────────────────────────────────────────────────
// Unified error codes covering both iOS (DFUError) and Android (DfuBaseService).
// iOS values are used as canonical; native implementations map platform codes.
export enum DfuError {
// Remote errors — Legacy DFU (1–6)
RemoteLegacyDfuInvalidState = 2,
RemoteLegacyDfuNotSupported = 3,
RemoteLegacyDfuDataExceedsLimit = 4,
RemoteLegacyDfuCrcError = 5,
RemoteLegacyDfuOperationFailed = 6,
// Remote errors — Secure DFU (11–21)
RemoteSecureDfuOpCodeNotSupported = 12,
RemoteSecureDfuInvalidParameter = 13,
RemoteSecureDfuInsufficientResources = 14,
RemoteSecureDfuInvalidObject = 15,
RemoteSecureDfuSignatureMismatch = 16,
RemoteSecureDfuUnsupportedType = 17,
RemoteSecureDfuOperationNotPermitted = 18,
RemoteSecureDfuOperationFailed = 20,
RemoteSecureDfuExtendedError = 21,
// Remote errors — Secure DFU Extended (22–33)
RemoteExtendedErrorWrongCommandFormat = 22,
RemoteExtendedErrorUnknownCommand = 23,
RemoteExtendedErrorInitCommandInvalid = 24,
RemoteExtendedErrorFwVersionFailure = 25,
RemoteExtendedErrorHwVersionFailure = 26,
RemoteExtendedErrorSdVersionFailure = 27,
RemoteExtendedErrorSignatureMissing = 28,
RemoteExtendedErrorWrongHashType = 29,
RemoteExtendedErrorHashFailed = 30,
RemoteExtendedErrorWrongSignatureType = 31,
RemoteExtendedErrorVerificationFailed = 32,
RemoteExtendedErrorInsufficientSpace = 33,
// Remote errors — Buttonless DFU (91–97)
RemoteButtonlessDfuOpCodeNotSupported = 92,
RemoteButtonlessDfuOperationFailed = 94,
RemoteButtonlessDfuInvalidAdvertisementName = 95,
RemoteButtonlessDfuBusy = 96,
RemoteButtonlessDfuNotBonded = 97,
// Remote errors — Experimental Buttonless DFU (9001–9004)
RemoteExperimentalButtonlessDfuOpCodeNotSupported = 9002,
RemoteExperimentalButtonlessDfuOperationFailed = 9004,
// File / Firmware errors (101–109)
FileNotSpecified = 101,
FileInvalid = 102,
ExtendedInitPacketRequired = 103,
InitPacketRequired = 104,
FileSizeInvalid = 105,
FileTypeUnsupported = 106,
FileIOError = 107,
// Connection errors (201–209)
FailedToConnect = 201,
DeviceDisconnected = 202,
BluetoothDisabled = 203,
DeviceNotBonded = 204,
// Service / Protocol errors (301–309, 500)
ServiceDiscoveryFailed = 301,
DeviceNotSupported = 302,
ReadingVersionFailed = 303,
EnablingControlPointFailed = 304,
WritingCharacteristicFailed = 305,
ReceivingNotificationFailed = 306,
UnsupportedResponse = 307,
BytesLost = 308,
CrcError = 309,
InvalidInternalState = 500,
}
// ─── Firmware Type ───────────────────────────────────────────────────────────
export enum DfuFirmwareType {
Application = 0,
Bootloader = 1,
SoftDevice = 2,
SoftDeviceBootloader = 3,
SoftDeviceBootloaderApplication = 4,
}
// ─── DFU Options ─────────────────────────────────────────────────────────────
export interface DfuOptions {
deviceId: string;
filePath: string;
firmwareType?: DfuFirmwareType;
packetReceiptNotificationParameter?: number;
forceDfu?: boolean;
enableUnsafeExperimentalButtonlessDfu?: boolean;
forceScanningForNewAddressInLegacyDfu?: boolean;
numberOfRetries?: number;
connectionTimeout?: number;
dataObjectPreparationDelay?: number;
alternativeAdvertisingNameEnabled?: boolean;
disableResume?: boolean;
}
// ─── Callback Types ──────────────────────────────────────────────────────────
export type DfuStateCallback = (state: DfuState) => void;
export type DfuProgressCallback = (
part: number,
totalParts: number,
progress: number,
currentSpeed: number,
avgSpeed: number,
) => void;
export type DfuErrorCallback = (error: DfuError, message: string) => void;
// ─── HybridObject Spec ──────────────────────────────────────────────────────
export interface NativeDfuNitro extends HybridObject<{
ios: 'swift';
android: 'kotlin';
}> {
startDfu(
options: DfuOptions,
stateCallback: DfuStateCallback,
progressCallback: DfuProgressCallback,
errorCallback: DfuErrorCallback
): void;
pauseDfu(): void;
resumeDfu(): void;
abortDfu(): void;
}