|
| 1 | +/** |
| 2 | + * |
| 3 | + * Copyright (c) 2022 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#import <Foundation/Foundation.h> |
| 19 | + |
| 20 | +/** |
| 21 | + * A representation of an OTA image header as defined in the Matter |
| 22 | + * specification's "Over-the-Air (OTA) Software Update File Format" section. |
| 23 | + */ |
| 24 | + |
| 25 | +NS_ASSUME_NONNULL_BEGIN |
| 26 | + |
| 27 | +typedef NS_ENUM(NSUInteger, MTROTAImageDigestType) { |
| 28 | + MTROTAImageDigestTypeSha256 = 1, |
| 29 | + MTROTAImageDigestTypeSha256_128, |
| 30 | + MTROTAImageDigestTypeSha256_120, |
| 31 | + MTROTAImageDigestTypeSha256_96, |
| 32 | + MTROTAImageDigestTypeSha256_64, |
| 33 | + MTROTAImageDigestTypeSha256_32, |
| 34 | + MTROTAImageDigestTypeSha384, |
| 35 | + MTROTAImageDigestTypeSha512, |
| 36 | + MTROTAImageDigestTypeSha3_224, |
| 37 | + MTROTAImageDigestTypeSha3_256, |
| 38 | + MTROTAImageDigestTypeSha3_384, |
| 39 | + MTROTAImageDigestTypeSha3_512, |
| 40 | +}; |
| 41 | + |
| 42 | +@interface MTROTAHeader : NSObject |
| 43 | + |
| 44 | +/** |
| 45 | + * The identifier of the vendor whose product this image is meant for. |
| 46 | + * |
| 47 | + * This field can be compared to the vendor id received in the Query Image |
| 48 | + * command to determine whether an image matches. |
| 49 | + * |
| 50 | + * This field may be 0, in which case the image might apply to products from |
| 51 | + * more than one vendor. If it's nonzero, it must match the vendor id in Query |
| 52 | + * Image for this image to be considered. |
| 53 | + */ |
| 54 | +@property (nonatomic, copy) NSNumber * vendorID; |
| 55 | +/** |
| 56 | + * The identifier of the specific product the image is meant for. May be 0, if |
| 57 | + * the image might apply to more than one product. This is allowed, but not |
| 58 | + * required, to be matched against the product id received in Query Image. |
| 59 | + */ |
| 60 | +@property (nonatomic, copy) NSNumber * productID; |
| 61 | +/** |
| 62 | + * The size of the actual image payload, which follows the header in the OTA |
| 63 | + * file. |
| 64 | + */ |
| 65 | +@property (nonatomic, copy) NSNumber * payloadSize; |
| 66 | +/** |
| 67 | + * The version of the software contained in this image. This is the version the |
| 68 | + * OTA requestor will be updated to if this image is installed. This can be |
| 69 | + * used to determine whether this image is newer than what the requestor is |
| 70 | + * currently running, by comparing it to the SoftwareVersion in the Query Image |
| 71 | + * command. |
| 72 | + */ |
| 73 | +@property (nonatomic, copy) NSNumber * softwareVersion; |
| 74 | +/** |
| 75 | + * Human-readable version of softwareVersion. This must not be used for |
| 76 | + * deciding which versions are newer or older; use softwareVersion for that. |
| 77 | + */ |
| 78 | +@property (nonatomic, copy) NSString * softwareVersionString; |
| 79 | +/** |
| 80 | + * If not nil a URL pointing to release notes for the software update |
| 81 | + * represented by the image. |
| 82 | + */ |
| 83 | +@property (nonatomic, copy, nullable) NSString * releaseNotesURL; |
| 84 | +/** |
| 85 | + * A digest of the payload that follows the header. Can be used to verify that |
| 86 | + * the payload is not truncated or corrupted. |
| 87 | + */ |
| 88 | +@property (nonatomic, copy) NSData * imageDigest; |
| 89 | +/** |
| 90 | + * The specific algorithm that was used to compute imageDigest. |
| 91 | + */ |
| 92 | +@property (nonatomic, assign) MTROTAImageDigestType imageDigestType; |
| 93 | +/** |
| 94 | + * If not nil, specifies the smallest software version that this update can be |
| 95 | + * applied on top of. In that case, this value must be compared to the |
| 96 | + * SoftwareVersion in the QueryImage command to check whether this image is |
| 97 | + * valid for the OTA requestor. |
| 98 | + */ |
| 99 | +@property (nonatomic, copy, nullable) NSNumber * minApplicableVersion; |
| 100 | +/** |
| 101 | + * If not nil, specifies the largest software version that this update can be |
| 102 | + * applied on top of. In that case, this value must be compared to the |
| 103 | + * SoftwareVersion in the QueryImage command to check whether this image is |
| 104 | + * valid for the OTA requestor. |
| 105 | + */ |
| 106 | +@property (nonatomic, copy, nullable) NSNumber * maxApplicableVersion; |
| 107 | + |
| 108 | ++ (nullable MTROTAHeader *)headerFromData:(NSData *)data error:(NSError * __autoreleasing *)error; |
| 109 | +@end |
| 110 | + |
| 111 | +NS_ASSUME_NONNULL_END |
0 commit comments