Skip to content

Commit 9394cd6

Browse files
committed
Code review feedback: comment about internal flags and implement path expansion logic for skipping data encoding
1 parent f2ed12e commit 9394cd6

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/app/codegen-data-model/CodegenDataModel_Read.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
#include "lib/core/CHIPError.h"
1718
#include <app/codegen-data-model/CodegenDataModel.h>
1819

1920
#include <optional>
@@ -112,7 +113,13 @@ std::optional<CHIP_ERROR> TryReadViaAccessInterface(const ConcreteAttributePath
112113

113114
if (err != CHIP_NO_ERROR)
114115
{
115-
return std::make_optional(err);
116+
// Implementation of 8.4.3.2 of the spec for path expansion
117+
if (path.mExpanded && (err == CHIP_IM_GLOBAL_STATUS(UnsupportedRead)))
118+
{
119+
return CHIP_NO_ERROR;
120+
}
121+
122+
return err;
116123
}
117124

118125
// If the encoder tried to encode, then a value should have been written.
@@ -293,8 +300,17 @@ CHIP_ERROR CodegenDataModel::ReadAttribute(const InteractionModel::ReadAttribute
293300
ReturnErrorCodeIf(!request.subjectDescriptor.has_value(), CHIP_ERROR_INVALID_ARGUMENT);
294301

295302
Access::RequestPath requestPath{ .cluster = request.path.mClusterId, .endpoint = request.path.mEndpointId };
296-
ReturnErrorOnFailure(Access::GetAccessControl().Check(*request.subjectDescriptor, requestPath,
297-
RequiredPrivilege::ForReadAttribute(request.path)));
303+
CHIP_ERROR err = Access::GetAccessControl().Check(*request.subjectDescriptor, requestPath,
304+
RequiredPrivilege::ForReadAttribute(request.path));
305+
if (err != CHIP_NO_ERROR)
306+
{
307+
// Implementation of 8.4.3.2 of the spec for path expansion
308+
if (request.path.mExpanded && (err == CHIP_ERROR_ACCESS_DENIED))
309+
{
310+
return CHIP_NO_ERROR;
311+
}
312+
return err;
313+
}
298314
}
299315

300316
auto metadata = FindAttributeMetadata(request.path);

src/app/data-model-interface/DataModel.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@ class DataModel : public DataModelMetadataTree
5555
// event emitting, path marking and other operations
5656
virtual InteractionModelContext CurrentContext() const { return mContext; }
5757

58+
/// TEMPORARY/TRANSITIONAL requirement for transitioning from ember-specific code
59+
/// ReadAttribute is REQUIRED to perform:
60+
/// - ACL validation (see notes on OperationFlags::kInternal)
61+
/// - Validation of readability/writability
62+
/// - use request.path.mExpanded to skip encoding replies for data according
63+
/// to 8.4.3.2 of the spec:
64+
/// > If the path indicates attribute data that is not readable, then the path SHALL
65+
/// be discarded.
66+
/// > Else if reading from the attribute in the path requires a privilege that is not
67+
/// granted to access the cluster in the path, then the path SHALL be discarded.
68+
///
5869
/// Return codes:
59-
/// CHIP_ERROR_ACCESS_DENIED:
60-
/// - May be ignored if reads use path expansion (e.g. to skip inaccessible attributes
61-
/// during subscription requests). This code MUST be used for ACL failures and only for ACL failures.
62-
/// CHIP_IM_GLOBAL_STATUS(UnsupportedRead):
63-
/// - May be ignored if reads use path expansion (e.g. to skip reading write-only attributes
64-
/// during subscription requests).
6570
/// CHIP_ERROR_NO_MEMORY or CHIP_ERROR_BUFFER_TOO_SMALL:
6671
/// - Indicates that list encoding had insufficient buffer space to encode elements.
6772
/// - encoder::GetState().AllowPartialData() determines if these errors are permanent (no partial

src/app/data-model-interface/OperationTypes.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ namespace InteractionModel {
3131
/// Contains common flags among all interaction model operations: read/write/invoke
3232
enum class OperationFlags : uint32_t
3333
{
34-
kInternal = 0x0001, // Internal request for data changes (can bypass checks/ACL etc.)
34+
// NOTE: temporary flag. This flag exists to faciliate transition from ember-compatibilty-functions
35+
// implementation to DataModel Interface functionality. Specifically currently the
36+
// model is expected to perform ACL and readability/writability checks.
37+
//
38+
// In the future, this flag will be removed and InteractionModelEngine/ReportingEngine
39+
// will perform the required validation.
40+
//
41+
// Currently the flag FORCES a bypass of:
42+
// - ACL validation (will allow any read/write)
43+
// - Access validation (will allow reading write-only data for example)
44+
kInternal = 0x0001,
3545
};
3646

3747
/// This information is available for ALL interactions: read/write/invoke
@@ -42,6 +52,8 @@ struct OperationRequest
4252
/// Current authentication data EXCEPT for internal requests.
4353
/// - Non-internal requests MUST have this set.
4454
/// - operationFlags.Has(OperationFlags::kInternal) MUST NOT have this set
55+
///
56+
/// NOTE: once kInternal flag is removed, this will become non-optional
4557
std::optional<chip::Access::SubjectDescriptor> subjectDescriptor;
4658
};
4759

0 commit comments

Comments
 (0)