Skip to content

Commit 1966ca9

Browse files
authored
Merge pull request #441 from NordicSemiconductor/develop
Version 4.10.4
2 parents 546630b + cf84271 commit 1966ca9

File tree

21 files changed

+362
-135
lines changed

21 files changed

+362
-135
lines changed

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- iOSDFULibrary (4.10.3):
2+
- iOSDFULibrary (4.10.4):
33
- ZIPFoundation (= 0.9.11)
44
- ZIPFoundation (0.9.11)
55

@@ -15,7 +15,7 @@ EXTERNAL SOURCES:
1515
:path: "../"
1616

1717
SPEC CHECKSUMS:
18-
iOSDFULibrary: 7aade51a907d01ca9a87055003cd232b09efd78f
18+
iOSDFULibrary: 5d41d0ac69418d63755195db5f46e99588ae7d48
1919
ZIPFoundation: b1f0de4eed33e74a676f76e12559ab6b75990197
2020

2121
PODFILE CHECKSUM: 16697609d795697cac6384a823bc962ccbddb9d0

Example/Pods/Local Podspecs/iOSDFULibrary.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/iOSDFULibrary-iOS/iOSDFULibrary-iOS-Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/iOSDFULibrary-macOS/iOSDFULibrary-macOS-Info.plist

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>PreviewsEnabled</key>
6+
<false/>
7+
</dict>
8+
</plist>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let package = Package(
5656
dependencies: [
5757
.package(
5858
url: "https://github.com/NordicSemiconductor/IOS-Pods-DFU-Library",
59-
.upToNextMajor(from: "<Desired Version, e.g. 4.10.2>")
59+
.upToNextMajor(from: "<Desired Version, e.g. 4.10.4>")
6060
)
6161
],
6262
targets: [.target(name: "<Your Target Name>", dependencies: ["NordicDFU"])]

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
### Changelog
2+
- **4.10.4**
3+
- Fix for compilation error in Xcode 13 related to change in iOS API (#433, #439).
4+
- Improvement: State validation (#434, #435, #437).
5+
- Imporvement: Unnecessary fields removed from `SecureDFUExecutor` (#438).
6+
- Improvement: Accepting garbage after valid data in notifications (#440, #436).
7+
28
- **4.10.3**
39
- Project compilation available for Arm Simulators (#423).
410

iOSDFULibrary.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "iOSDFULibrary"
3-
s.version = "4.10.3"
3+
s.version = "4.10.4"
44
s.summary = "This repository contains a tested library for iOS 9+ devices to perform Device Firmware Update on the nRF5x devices"
55
s.description = <<-DESC
66
The nRF5x Series chips are flash-based SoCs, and as such they represent the most flexible solution available. A key feature of the nRF5x Series and their associated software architecture and S-Series SoftDevices is the possibility for Over-The-Air Device Firmware Upgrade (OTA-DFU). See Figure 1. OTA-DFU allows firmware upgrades to be issued and downloaded to products in the field via the cloud and so enables OEMs to fix bugs and introduce new features to products that are already out on the market. This brings added security and flexibility to product development when using the nRF5x Series SoCs.

iOSDFULibrary/Classes/Implementation/DFUServiceDelegate.swift

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ import Foundation
109109
/// Error raised when the CRC reported by the remote device does not match.
110110
/// Service has done 3 attempts to send the data.
111111
case crcError = 309
112+
/// The service went into an invalid state. The service will try to close
113+
/// without crashing. Recovery to a know state is not possible.
114+
case invalidInternalState = 500
112115

113116
/// Returns whether the error has been returned by the remote device or
114117
/// occurred locally.

iOSDFULibrary/Classes/Implementation/LegacyDFU/Characteristics/DFUControlPoint.swift

+32-11
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ internal struct Response {
142142
let status : DFUResultCode
143143

144144
init?(_ data: Data) {
145-
guard data.count == 3,
145+
guard data.count >= 3,
146146
let opCode = DFUOpCode(rawValue: data[0]),
147147
let requestOpCode = DFUOpCode(rawValue: data[1]),
148148
let status = DFUResultCode(rawValue: data[2]),
@@ -165,7 +165,7 @@ internal struct PacketReceiptNotification {
165165
let bytesReceived : UInt32
166166

167167
init?(_ data: Data) {
168-
guard data.count == 5,
168+
guard data.count >= 5,
169169
let opCode = DFUOpCode(rawValue: data[0]),
170170
opCode == .packetReceiptNotification else {
171171
return nil
@@ -216,13 +216,20 @@ internal struct PacketReceiptNotification {
216216
- parameter report: Method called in case of an error.
217217
*/
218218
func enableNotifications(onSuccess success: Callback?, onError report: ErrorCallback?) {
219+
// Get the peripheral object.
220+
#if swift(>=5.5)
221+
guard let peripheral = characteristic.service?.peripheral else {
222+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
223+
return
224+
}
225+
#else
226+
let peripheral = characteristic.service.peripheral
227+
#endif
228+
219229
// Save callbacks.
220230
self.success = success
221231
self.report = report
222232

223-
// Get the peripheral object.
224-
let peripheral = characteristic.service.peripheral
225-
226233
// Set the peripheral delegate to self.
227234
peripheral.delegate = self
228235

@@ -240,15 +247,22 @@ internal struct PacketReceiptNotification {
240247
- parameter report: Method called in case of an error.
241248
*/
242249
func send(_ request: Request, onSuccess success: Callback?, onError report: ErrorCallback?) {
250+
// Get the peripheral object.
251+
#if swift(>=5.5)
252+
guard let peripheral = characteristic.service?.peripheral else {
253+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
254+
return
255+
}
256+
#else
257+
let peripheral = characteristic.service.peripheral
258+
#endif
259+
243260
// Save callbacks and parameter.
244261
self.success = success
245262
self.report = report
246263
self.request = request
247264
self.resetSent = false
248265

249-
// Get the peripheral object.
250-
let peripheral = characteristic.service.peripheral
251-
252266
// Set the peripheral delegate to self.
253267
peripheral.delegate = self
254268

@@ -287,16 +301,23 @@ internal struct PacketReceiptNotification {
287301
func waitUntilUploadComplete(onSuccess success: Callback?,
288302
onPacketReceiptNofitication proceed: ProgressCallback?,
289303
onError report: ErrorCallback?) {
304+
// Get the peripheral object.
305+
#if swift(>=5.5)
306+
guard let peripheral = characteristic.service?.peripheral else {
307+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
308+
return
309+
}
310+
#else
311+
let peripheral = characteristic.service.peripheral
312+
#endif
313+
290314
// Save callbacks. The proceed callback will be called periodically whenever
291315
// a packet receipt notification is received. It resumes uploading.
292316
self.success = success
293317
self.proceed = proceed
294318
self.report = report
295319
self.uploadStartTime = CFAbsoluteTimeGetCurrent()
296320

297-
// Get the peripheral object.
298-
let peripheral = characteristic.service.peripheral
299-
300321
// Set the peripheral delegate to self.
301322
peripheral.delegate = self
302323
}

iOSDFULibrary/Classes/Implementation/LegacyDFU/Characteristics/DFUPacket.swift

+41-8
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,19 @@ internal class DFUPacket: DFUCharacteristic {
6363
Sends the firmware sizes in format [softdevice size, bootloader size, application size],
6464
where each size is a UInt32 number.
6565

66-
- parameter size: Sizes of firmware in the current part.
66+
- parameter size: Sizes of firmware in the current part.
67+
- parameter report: Method called in case of an error.
6768
*/
68-
func sendFirmwareSize(_ size: DFUFirmwareSize) {
69+
func sendFirmwareSize(_ size: DFUFirmwareSize, onError report: ErrorCallback?) {
6970
// Get the peripheral object
71+
#if swift(>=5.5)
72+
guard let peripheral = characteristic.service?.peripheral else {
73+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
74+
return
75+
}
76+
#else
7077
let peripheral = characteristic.service.peripheral
78+
#endif
7179

7280
let data = Data()
7381
+ size.softdevice.littleEndian
@@ -84,12 +92,20 @@ internal class DFUPacket: DFUCharacteristic {
8492
/**
8593
Sends the application firmware size in format [application size] (UInt32).
8694

87-
- parameter size: Sizes of firmware in the current part.
88-
Only the application size may be grater than 0.
95+
- parameter size: Sizes of firmware in the current part.
96+
Only the application size may be grater than 0.
97+
- parameter report: Method called in case of an error.
8998
*/
90-
func sendFirmwareSize_v1(_ size: DFUFirmwareSize) {
99+
func sendFirmwareSize_v1(_ size: DFUFirmwareSize, onError report: ErrorCallback?) {
91100
// Get the peripheral object.
101+
#if swift(>=5.5)
102+
guard let peripheral = characteristic.service?.peripheral else {
103+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
104+
return
105+
}
106+
#else
92107
let peripheral = characteristic.service.peripheral
108+
#endif
93109

94110
let data = Data() + size.application.littleEndian
95111

@@ -103,11 +119,19 @@ internal class DFUPacket: DFUCharacteristic {
103119
/**
104120
Sends the whole content of the data object.
105121

106-
- parameter data: The data to be sent.
122+
- parameter data: The data to be sent.
123+
- parameter report: Method called in case of an error.
107124
*/
108-
func sendInitPacket(_ data: Data) {
125+
func sendInitPacket(_ data: Data, onError report: ErrorCallback?) {
109126
// Get the peripheral object.
127+
#if swift(>=5.5)
128+
guard let peripheral = characteristic.service?.peripheral else {
129+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
130+
return
131+
}
132+
#else
110133
let peripheral = characteristic.service.peripheral
134+
#endif
111135

112136
// Data may be sent in up-to-20-bytes packets.
113137
var offset: UInt32 = 0
@@ -139,11 +163,20 @@ internal class DFUPacket: DFUCharacteristic {
139163
- parameter firmware: The firmware to be sent.
140164
- parameter progress: An optional progress delegate.
141165
- parameter queue: The queue to dispatch progress events on.
166+
- parameter report: Method called in case of an error.
142167
*/
143168
func sendNext(_ prnValue: UInt16, packetsOf firmware: DFUFirmware,
144-
andReportProgressTo progress: DFUProgressDelegate?, on queue: DispatchQueue) {
169+
andReportProgressTo progress: DFUProgressDelegate?, on queue: DispatchQueue,
170+
onError report: ErrorCallback?) {
145171
// Get the peripheral object.
172+
#if swift(>=5.5)
173+
guard let peripheral = characteristic.service?.peripheral else {
174+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
175+
return
176+
}
177+
#else
146178
let peripheral = characteristic.service.peripheral
179+
#endif
147180

148181
// Some super complicated computations...
149182
let bytesTotal = UInt32(firmware.data.count)

iOSDFULibrary/Classes/Implementation/LegacyDFU/Characteristics/DFUVersion.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ internal typealias VersionCallback = (_ major: UInt8, _ minor: UInt8) -> Void
6161
- parameter report: Method called on error of if version is not supported.
6262
*/
6363
func readVersion(onSuccess success: VersionCallback?, onError report: ErrorCallback?) {
64+
// Get the peripheral object.
65+
#if swift(>=5.5)
66+
guard let peripheral = characteristic.service?.peripheral else {
67+
report?(.invalidInternalState, "Assert characteristic.service?.peripheral != nil failed")
68+
return
69+
}
70+
#else
71+
let peripheral = characteristic.service.peripheral
72+
#endif
73+
6474
// Save callbacks.
6575
self.success = success
6676
self.report = report
6777

68-
// Get the peripheral object.
69-
let peripheral = characteristic.service.peripheral
70-
7178
// Set the peripheral delegate to self.
7279
peripheral.delegate = self
7380

iOSDFULibrary/Classes/Implementation/LegacyDFU/DFU/LegacyDFUExecutor.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ internal class LegacyDFUExecutor : DFUExecutor, LegacyDFUPeripheralDelegate {
6666
func peripheralDidBecomeReady() {
6767
if firmware.initPacket == nil && peripheral.isInitPacketRequired() {
6868
error(.extendedInitPacketRequired, didOccurWithMessage:
69-
"The init packet is required by the target device")
69+
"The init packet is required by the target device")
7070
return
7171
}
7272
delegate {
@@ -101,7 +101,7 @@ internal class LegacyDFUExecutor : DFUExecutor, LegacyDFUPeripheralDelegate {
101101
} else {
102102
// Operation can not be continued.
103103
error(.remoteLegacyDFUNotSupported, didOccurWithMessage:
104-
"Updating Softdevice or Bootloader is not supported")
104+
"Updating Softdevice or Bootloader is not supported")
105105
}
106106
}
107107

@@ -140,7 +140,7 @@ internal class LegacyDFUExecutor : DFUExecutor, LegacyDFUPeripheralDelegate {
140140
peripheral.start()
141141
} else {
142142
error(.remoteLegacyDFUInvalidState, didOccurWithMessage:
143-
"Peripheral is in an invalid state, please try to reset and start over again.")
143+
"Peripheral is in an invalid state, please try to reset and start over again.")
144144
}
145145
}
146146

@@ -157,8 +157,9 @@ internal class LegacyDFUExecutor : DFUExecutor, LegacyDFUPeripheralDelegate {
157157
// received by the DFU target before sending a new Packet Receipt Notification.
158158
// After receiving status Success it will send the firmware.
159159
peripheral.sendFirmware(firmware,
160-
withPacketReceiptNotificationNumber: initiator.packetReceiptNotificationParameter,
161-
andReportProgressTo: initiator.progressDelegate,
162-
on: initiator.progressDelegateQueue)
160+
withPacketReceiptNotificationNumber: initiator.packetReceiptNotificationParameter,
161+
andReportProgressTo: initiator.progressDelegate,
162+
on: initiator.progressDelegateQueue
163+
)
163164
}
164165
}

0 commit comments

Comments
 (0)