|
| 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 | +#pragma once |
| 19 | + |
| 20 | +#include <app-common/zap-generated/af-structs.h> |
| 21 | +#include <app-common/zap-generated/cluster-objects.h> |
| 22 | +#include <app/util/af-types.h> |
| 23 | +#include <app/util/attribute-metadata.h> |
| 24 | +#include <app/util/basic-types.h> |
| 25 | + |
| 26 | +#include <app/CommandHandler.h> |
| 27 | +#include <app/CommandSender.h> |
| 28 | +#include <app/ConcreteAttributePath.h> |
| 29 | +#include <app/ConcreteCommandPath.h> |
| 30 | +#include <lib/support/Span.h> |
| 31 | +#include <protocols/interaction_model/Constants.h> |
| 32 | + |
| 33 | +/** @brief Cluster Init |
| 34 | + * |
| 35 | + * This function is called when a specific cluster is initialized. It gives the |
| 36 | + * application an opportunity to take care of cluster initialization procedures. |
| 37 | + * It is called exactly once for each endpoint where cluster is present. |
| 38 | + * |
| 39 | + * @param endpoint Ver.: always |
| 40 | + * @param clusterId Ver.: always |
| 41 | + */ |
| 42 | +void emberAfClusterInitCallback(chip::EndpointId endpoint, chip::ClusterId clusterId); |
| 43 | + |
| 44 | +/** @brief Allow Network Write Attribute |
| 45 | + * |
| 46 | + * This function is called by the application framework before it writes an |
| 47 | + * attribute in response to a write attribute request from an external device. |
| 48 | + * The value passed into this callback is the value to which the attribute is to |
| 49 | + * be set by the framework. |
| 50 | + Example: In mirroring simple metering data |
| 51 | + * on an Energy Services Interface (ESI) (formerly called Energy Service Portal |
| 52 | + * (ESP) in SE 1.0).), a mirrored simple meter needs to write read-only |
| 53 | + * attributes on its mirror. The-meter-mirror sample application, located in |
| 54 | + * app/framework/sample-apps, uses this callback to allow the mirrored device to |
| 55 | + * write simple metering attributes on the mirror regardless of the fact that |
| 56 | + * most simple metering attributes are defined as read-only by the ZigBee |
| 57 | + * specification. |
| 58 | + Note: The ZCL specification does not (as of this |
| 59 | + * writing) specify any permission-level security for writing writeable |
| 60 | + * attributes. As far as the ZCL specification is concerned, if an attribute is |
| 61 | + * writeable, any device that has a link key for the device should be able to |
| 62 | + * write that attribute. Furthermore if an attribute is read only, it should not |
| 63 | + * be written over the air. Thus, if you implement permissions for writing |
| 64 | + * attributes as a feature, you MAY be operating outside the specification. This |
| 65 | + * is unlikely to be a problem for writing read-only attributes, but it may be a |
| 66 | + * problem for attributes that are writeable according to the specification but |
| 67 | + * restricted by the application implementing this callback. |
| 68 | + */ |
| 69 | +EmberAfAttributeWritePermission emberAfAllowNetworkWriteAttributeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, |
| 70 | + chip::AttributeId attributeId, uint8_t * value, |
| 71 | + uint8_t type); |
| 72 | + |
| 73 | +/** @brief Attribute Read Access |
| 74 | + * |
| 75 | + * This function is called whenever the Application Framework needs to check |
| 76 | + * access permission for an attribute read. |
| 77 | + */ |
| 78 | +bool emberAfAttributeReadAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); |
| 79 | + |
| 80 | +/** @brief Attribute Write Access |
| 81 | + * |
| 82 | + * This function is called whenever the Application Framework needs to check |
| 83 | + * access permission for an attribute write. |
| 84 | + */ |
| 85 | +bool emberAfAttributeWriteAccessCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId); |
| 86 | + |
| 87 | +/** @brief External Attribute Read |
| 88 | + * |
| 89 | + * Like emberAfExternalAttributeWriteCallback above, this function is called |
| 90 | + * when the framework needs to read an attribute that is not stored within the |
| 91 | + * Application Framework's data structures. |
| 92 | + All of the important |
| 93 | + * information about the attribute itself is passed as a pointer to an |
| 94 | + * EmberAfAttributeMetadata struct, which is stored within the application and |
| 95 | + * used to manage the attribute. A complete description of the |
| 96 | + * EmberAfAttributeMetadata struct is provided in |
| 97 | + * app/framework/include/af-types.h |
| 98 | + This function assumes that the |
| 99 | + * application is able to read the attribute, write it into the passed buffer, |
| 100 | + * and return immediately. Any attributes that require a state machine for |
| 101 | + * reading and writing are not really candidates for externalization at the |
| 102 | + * present time. The Application Framework does not currently include a state |
| 103 | + * machine for reading or writing attributes that must take place across a |
| 104 | + * series of application ticks. Attributes that cannot be read in a timely |
| 105 | + * manner should be stored within the Application Framework and updated |
| 106 | + * occasionally by the application code from within the |
| 107 | + * emberAfMainTickCallback. |
| 108 | + If the application was successfully able to |
| 109 | + * read the attribute and write it into the passed buffer, it should return a |
| 110 | + * value of EMBER_ZCL_STATUS_SUCCESS. Ensure that the size of the externally |
| 111 | + * managed attribute value is smaller than what the buffer can hold. In the case |
| 112 | + * of a buffer overflow throw an appropriate error such as |
| 113 | + * EMBER_ZCL_STATUS_INSUFFICIENT_SPACE. Any other return value indicates the |
| 114 | + * application was not able to read the attribute. |
| 115 | + */ |
| 116 | +EmberAfStatus emberAfExternalAttributeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, |
| 117 | + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, |
| 118 | + uint16_t maxReadLength); |
| 119 | + |
| 120 | +/** @brief External Attribute Write |
| 121 | + * |
| 122 | + * This function is called whenever the Application Framework needs to write an |
| 123 | + * attribute which is not stored within the data structures of the Application |
| 124 | + * Framework itself. One of the new features in Version 2 is the ability to |
| 125 | + * store attributes outside the Framework. This is particularly useful for |
| 126 | + * attributes that do not need to be stored because they can be read off the |
| 127 | + * hardware when they are needed, or are stored in some central location used by |
| 128 | + * many modules within the system. In this case, you can indicate that the |
| 129 | + * attribute is stored externally. When the framework needs to write an external |
| 130 | + * attribute, it makes a call to this callback. |
| 131 | + This callback is very |
| 132 | + * useful for host micros which need to store attributes in persistent memory. |
| 133 | + * Because each host micro (used with an Ember NCP) has its own type of |
| 134 | + * persistent memory storage, the Application Framework does not include the |
| 135 | + * ability to mark attributes as stored in flash the way that it does for Ember |
| 136 | + * SoCs like the EM35x. On a host micro, any attributes that need to be stored |
| 137 | + * in persistent memory should be marked as external and accessed through the |
| 138 | + * external read and write callbacks. Any host code associated with the |
| 139 | + * persistent storage should be implemented within this callback. |
| 140 | + All of |
| 141 | + * the important information about the attribute itself is passed as a pointer |
| 142 | + * to an EmberAfAttributeMetadata struct, which is stored within the application |
| 143 | + * and used to manage the attribute. A complete description of the |
| 144 | + * EmberAfAttributeMetadata struct is provided in |
| 145 | + * app/framework/include/af-types.h. |
| 146 | + This function assumes that the |
| 147 | + * application is able to write the attribute and return immediately. Any |
| 148 | + * attributes that require a state machine for reading and writing are not |
| 149 | + * candidates for externalization at the present time. The Application Framework |
| 150 | + * does not currently include a state machine for reading or writing attributes |
| 151 | + * that must take place across a series of application ticks. Attributes that |
| 152 | + * cannot be written immediately should be stored within the Application |
| 153 | + * Framework and updated occasionally by the application code from within the |
| 154 | + * emberAfMainTickCallback. |
| 155 | + If the application was successfully able to |
| 156 | + * write the attribute, it returns a value of EMBER_ZCL_STATUS_SUCCESS. Any |
| 157 | + * other return value indicates the application was not able to write the |
| 158 | + * attribute. |
| 159 | + */ |
| 160 | +EmberAfStatus emberAfExternalAttributeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, |
| 161 | + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); |
| 162 | + |
| 163 | +/** @brief Registration Abort |
| 164 | + * |
| 165 | + * This callback is called when the device should abort the registration |
| 166 | + * process. |
| 167 | + * |
| 168 | + */ |
| 169 | +void emberAfRegistrationAbortCallback(); |
| 170 | + |
| 171 | +/** @brief Start Move |
| 172 | + * |
| 173 | + * This function is called to initiate the process for a device to move (rejoin) |
| 174 | + * to a new parent. |
| 175 | + * |
| 176 | + */ |
| 177 | +bool emberAfStartMoveCallback(); |
| 178 | + |
| 179 | +/** @brief Pre Attribute Change |
| 180 | + * |
| 181 | + * This function is called by the application framework before it changes an |
| 182 | + * attribute value. The value passed into this callback is the value to which |
| 183 | + * the attribute is to be set by the framework. The application should return |
| 184 | + * chip::Protocols::InteractionModel::Status::Success to permit the change or |
| 185 | + * any other code to reject it. |
| 186 | + */ |
| 187 | +chip::Protocols::InteractionModel::Status MatterPreAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, |
| 188 | + uint8_t type, uint16_t size, uint8_t * value); |
| 189 | + |
| 190 | +/** @brief Post Attribute Change |
| 191 | + * |
| 192 | + * This function is called by the application framework after it changes an |
| 193 | + * attribute value. The value passed into this callback is the value to which |
| 194 | + * the attribute was set by the framework. |
| 195 | + */ |
| 196 | +void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, |
| 197 | + uint8_t * value); |
0 commit comments