| /* |
| * |
| * Copyright (c) 2021 Project CHIP Authors |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| // THIS FILE IS GENERATED BY ZAP |
| |
| #include <zap-generated/CHIPClientCallbacks.h> |
| |
| #include <cinttypes> |
| |
| #include <app-common/zap-generated/enums.h> |
| #include <app/Command.h> |
| #include <app/util/CHIPDeviceCallbacksMgr.h> |
| #include <app/util/af-enums.h> |
| #include <app/util/af.h> |
| #include <app/util/attribute-list-byte-span.h> |
| #include <app/util/basic-types.h> |
| #include <app/util/prepare-list.h> |
| #include <lib/core/CHIPEncoding.h> |
| #include <lib/support/SafeInt.h> |
| #include <lib/support/TypeTraits.h> |
| #include <lib/support/logging/CHIPLogging.h> |
| |
| using namespace ::chip; |
| using namespace ::chip::app::List; |
| |
| namespace { |
| [[maybe_unused]] constexpr uint16_t kByteSpanSizeLengthInBytes = 2; |
| } // namespace |
| |
| #define CHECK_STATUS_WITH_RETVAL(error, retval) \ |
| if (CHIP_NO_ERROR != error) \ |
| { \ |
| ChipLogError(Zcl, "CHECK_STATUS %s", ErrorStr(error)); \ |
| if (onFailureCallback != nullptr) \ |
| { \ |
| Callback::Callback<DefaultFailureCallback> * cb = \ |
| Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback); \ |
| cb->mCall(cb->mContext, static_cast<uint8_t>(EMBER_ZCL_STATUS_INVALID_VALUE)); \ |
| } \ |
| return retval; \ |
| } |
| |
| #define CHECK_STATUS(error) CHECK_STATUS_WITH_RETVAL(error, true) |
| #define CHECK_STATUS_VOID(error) CHECK_STATUS_WITH_RETVAL(error, ) |
| |
| #define CHECK_MESSAGE_LENGTH_WITH_RETVAL(value, retval) \ |
| if (!CanCastTo<uint16_t>(value)) \ |
| { \ |
| ChipLogError(Zcl, "CHECK_MESSAGE_LENGTH expects a uint16_t value, got: %d", value); \ |
| if (onFailureCallback != nullptr) \ |
| { \ |
| Callback::Callback<DefaultFailureCallback> * cb = \ |
| Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback); \ |
| cb->mCall(cb->mContext, static_cast<uint8_t>(EMBER_ZCL_STATUS_INVALID_VALUE)); \ |
| } \ |
| return retval; \ |
| } \ |
| \ |
| if (messageLen < value) \ |
| { \ |
| ChipLogError(Zcl, "Unexpected response length: %d", messageLen); \ |
| if (onFailureCallback != nullptr) \ |
| { \ |
| Callback::Callback<DefaultFailureCallback> * cb = \ |
| Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback); \ |
| cb->mCall(cb->mContext, static_cast<uint8_t>(EMBER_ZCL_STATUS_INVALID_VALUE)); \ |
| } \ |
| return retval; \ |
| } \ |
| \ |
| messageLen = static_cast<uint16_t>(messageLen - static_cast<uint16_t>(value)); |
| |
| #define CHECK_MESSAGE_LENGTH(value) CHECK_MESSAGE_LENGTH_WITH_RETVAL(value, true) |
| #define CHECK_MESSAGE_LENGTH_VOID(value) CHECK_MESSAGE_LENGTH_WITH_RETVAL(value, ) |
| |
| #define GET_RESPONSE_CALLBACKS(name) \ |
| Callback::Cancelable * onSuccessCallback = nullptr; \ |
| Callback::Cancelable * onFailureCallback = nullptr; \ |
| NodeId sourceId = emberAfCurrentCommand()->SourceNodeId(); \ |
| uint8_t sequenceNumber = emberAfCurrentCommand()->seqNum; \ |
| CHIP_ERROR err = gCallbacks.GetResponseCallback(sourceId, sequenceNumber, &onSuccessCallback, &onFailureCallback); \ |
| \ |
| if (CHIP_NO_ERROR != err) \ |
| { \ |
| if (onSuccessCallback == nullptr) \ |
| { \ |
| ChipLogDetail(Zcl, "%s: Missing success callback", name); \ |
| } \ |
| \ |
| if (onFailureCallback == nullptr) \ |
| { \ |
| ChipLogDetail(Zcl, "%s: Missing failure callback", name); \ |
| } \ |
| \ |
| return true; \ |
| } |
| |
| #define GET_CLUSTER_RESPONSE_CALLBACKS(name) \ |
| Callback::Cancelable * onSuccessCallback = nullptr; \ |
| Callback::Cancelable * onFailureCallback = nullptr; \ |
| NodeId sourceIdentifier = reinterpret_cast<NodeId>(commandObj); \ |
| /* #6559: Currently, we only have one commands for the IMInvokeCommands and to a device, so the seqNum is always set to 0. */ \ |
| CHIP_ERROR err = gCallbacks.GetResponseCallback(sourceIdentifier, 0, &onSuccessCallback, &onFailureCallback); \ |
| \ |
| if (CHIP_NO_ERROR != err) \ |
| { \ |
| if (onSuccessCallback == nullptr) \ |
| { \ |
| ChipLogDetail(Zcl, "%s: Missing success callback", name); \ |
| } \ |
| \ |
| if (onFailureCallback == nullptr) \ |
| { \ |
| ChipLogDetail(Zcl, "%s: Missing failure callback", name); \ |
| } \ |
| \ |
| return true; \ |
| } |
| |
| #define GET_ATTRIBUTE_RESPONSE_CALLBACKS(name) |
| |
| #define GET_REPORT_CALLBACK(name) \ |
| Callback::Cancelable * onReportCallback = nullptr; \ |
| CHIP_ERROR err = gCallbacks.GetReportCallback(sourceId, endpointId, clusterId, attributeId, &onReportCallback); \ |
| \ |
| if (CHIP_NO_ERROR != err) \ |
| { \ |
| if (onReportCallback == nullptr) \ |
| { \ |
| ChipLogDetail(Zcl, "%s: Missing report callback", name); \ |
| } \ |
| \ |
| return true; \ |
| } |
| |
| // TODO: These IM related callbacks contains small or no generated code, should be put into seperate file to reduce the size of |
| // template. Singleton instance of the callbacks manager |
| |
| app::CHIPDeviceCallbacksMgr & gCallbacks = app::CHIPDeviceCallbacksMgr::GetInstance(); |
| |
| bool emberAfConfigureReportingResponseCallback(ClusterId clusterId, uint8_t * message, uint16_t messageLen) |
| { |
| ChipLogProgress(Zcl, "ConfigureReportingResponseCallback:"); |
| ChipLogProgress(Zcl, " ClusterId: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); |
| |
| GET_RESPONSE_CALLBACKS("emberAfConfigureReportingResponseCallback"); |
| |
| // struct configureReportingResponseRecord[] |
| while (messageLen) |
| { |
| CHECK_MESSAGE_LENGTH(1); |
| uint8_t status = Encoding::Read8(message); // zclStatus |
| LogStatus(status); |
| |
| if (status == EMBER_ZCL_STATUS_SUCCESS) |
| { |
| Callback::Callback<DefaultSuccessCallback> * cb = |
| Callback::Callback<DefaultSuccessCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext); |
| } |
| else |
| { |
| CHECK_MESSAGE_LENGTH(1); |
| uint8_t direction = Encoding::Read8(message); // reportingRole |
| ChipLogProgress(Zcl, " direction: 0x%02x", direction); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read8 unconditionally here, because we |
| // want to advance the 'message' pointer even if we don't use |
| // direction. |
| UNUSED_VAR(direction); |
| |
| CHECK_MESSAGE_LENGTH(4); |
| AttributeId attributeId = Encoding::LittleEndian::Read32(message); // attribId |
| ChipLogProgress(Zcl, " attributeId: " ChipLogFormatMEI, ChipLogValueMEI(attributeId)); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read32 unconditionally here, because we |
| // want to advance the 'message' pointer even if we don't use |
| // direction. |
| UNUSED_VAR(attributeId); |
| |
| Callback::Callback<DefaultFailureCallback> * cb = |
| Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback); |
| cb->mCall(cb->mContext, status); |
| } |
| |
| // The current code is written matching the current API where there is a single attribute report |
| // per configure command. So if multiple attributes are configured at the same time, something is wrong |
| // somewhere. |
| if (messageLen) |
| { |
| ChipLogError(Zcl, "Multiple attributes reports configured at the same time. Something went wrong."); |
| break; |
| } |
| } |
| |
| return true; |
| } |
| |
| bool emberAfReadReportingConfigurationResponseCallback(ClusterId clusterId, uint8_t * message, uint16_t messageLen) |
| { |
| ChipLogProgress(Zcl, "ReadReportingConfigurationResponse:"); |
| ChipLogProgress(Zcl, " ClusterId: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); |
| |
| GET_RESPONSE_CALLBACKS("emberAfReadReportingConfigurationResponseCallback"); |
| |
| // struct readReportingConfigurationResponseRecord[] |
| while (messageLen) |
| { |
| CHECK_MESSAGE_LENGTH(1); |
| uint8_t direction = Encoding::Read8(message); // reportingRole |
| ChipLogProgress(Zcl, " direction: 0x%02x", direction); |
| |
| CHECK_MESSAGE_LENGTH(4); |
| AttributeId attributeId = Encoding::LittleEndian::Read32(message); // attribId |
| ChipLogProgress(Zcl, " attributeId: " ChipLogFormatMEI, ChipLogValueMEI(attributeId)); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read32 unconditionally here, because we |
| // want to advance the 'message' pointer even if we don't use |
| // attributeId. |
| UNUSED_VAR(attributeId); |
| |
| if (direction == EMBER_ZCL_REPORTING_DIRECTION_REPORTED) |
| { |
| CHECK_MESSAGE_LENGTH(1); |
| uint8_t attributeType = Encoding::Read8(message); // zclType |
| ChipLogProgress(Zcl, " attributeType: 0x%02x", attributeType); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read8 unconditionally here, because we |
| // want to advance the 'message' pointer even if we don't use |
| // attributeType. |
| UNUSED_VAR(attributeType); |
| |
| CHECK_MESSAGE_LENGTH(2); |
| uint16_t minimumReportingInterval = Encoding::LittleEndian::Read16(message); // uint16 |
| ChipLogProgress(Zcl, " minimumReportingInterval: %" PRIu16, minimumReportingInterval); |
| |
| CHECK_MESSAGE_LENGTH(2); |
| uint16_t maximumReportingInterval = Encoding::LittleEndian::Read16(message); // uint16 |
| ChipLogProgress(Zcl, " maximumReportingInterval: %" PRIu16, maximumReportingInterval); |
| |
| // FIXME: unk is not supported yet. |
| |
| Callback::Callback<ReadReportingConfigurationReportedCallback> * cb = |
| Callback::Callback<ReadReportingConfigurationReportedCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext, minimumReportingInterval, maximumReportingInterval); |
| } |
| else |
| { |
| CHECK_MESSAGE_LENGTH(2); |
| uint16_t timeout = Encoding::LittleEndian::Read16(message); // uint16 |
| ChipLogProgress(Zcl, " timeout: %" PRIu16, timeout); |
| |
| Callback::Callback<ReadReportingConfigurationReceivedCallback> * cb = |
| Callback::Callback<ReadReportingConfigurationReceivedCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext, timeout); |
| } |
| } |
| |
| return true; |
| } |
| |
| bool emberAfDiscoverAttributesResponseCallback(ClusterId clusterId, bool discoveryComplete, uint8_t * message, uint16_t messageLen, |
| bool extended) |
| { |
| ChipLogProgress(Zcl, "DiscoverAttributesResponse:"); |
| ChipLogProgress(Zcl, " ClusterId: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); |
| ChipLogProgress(Zcl, " discoveryComplete: %d", discoveryComplete); |
| ChipLogProgress(Zcl, " extended: %d", extended); |
| |
| GET_RESPONSE_CALLBACKS("emberAfDiscoverAttributesCallback"); |
| |
| // struct discoverAttributesResponseRecord[] |
| while (messageLen) |
| { |
| CHECK_MESSAGE_LENGTH(4); |
| AttributeId attributeId = Encoding::LittleEndian::Read32(message); // attribId |
| ChipLogProgress(Zcl, " attributeId: " ChipLogFormatMEI, ChipLogValueMEI(attributeId)); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read32 unconditionally here, because we |
| // want to advance the 'message' pointer even if we don't use |
| // attributeId. |
| UNUSED_VAR(attributeId); |
| |
| CHECK_MESSAGE_LENGTH(1); |
| uint8_t attributeType = Encoding::Read8(message); // zclType |
| ChipLogProgress(Zcl, " attributeType: 0x%02x", attributeType); |
| // Silence unused var warning if progress logging is disabled. Note |
| // that we _do_ want to call Read8 unconditionally here, because we want |
| // to advance the 'message' pointer even if we don't use attributeType. |
| UNUSED_VAR(attributeType); |
| } |
| |
| Callback::Callback<DefaultSuccessCallback> * cb = Callback::Callback<DefaultSuccessCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext); |
| return true; |
| } |
| |
| bool emberAfDiscoverCommandsGeneratedResponseCallback(ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete, |
| CommandId * commandIds, uint16_t commandIdCount) |
| { |
| ChipLogProgress(Zcl, "DiscoverCommandsGeneratedResponse:"); |
| ChipLogProgress(Zcl, " ClusterId: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); |
| ChipLogProgress(Zcl, " manufacturerCode: 0x%04x", manufacturerCode); |
| ChipLogProgress(Zcl, " discoveryComplete: %d", discoveryComplete); |
| ChipLogProgress(Zcl, " commandIdCount: %" PRIu16, commandIdCount); |
| |
| for (uint16_t i = 0; i < commandIdCount; i++) |
| { |
| ChipLogProgress(Zcl, " commandId: " ChipLogFormatMEI, ChipLogValueMEI(*commandIds)); |
| commandIds++; |
| } |
| |
| GET_RESPONSE_CALLBACKS("emberAfDiscoverCommandsGeneratedResponseCallback"); |
| Callback::Callback<DefaultSuccessCallback> * cb = Callback::Callback<DefaultSuccessCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext); |
| return true; |
| } |
| |
| bool emberAfDiscoverCommandsReceivedResponseCallback(ClusterId clusterId, uint16_t manufacturerCode, bool discoveryComplete, |
| CommandId * commandIds, uint16_t commandIdCount) |
| { |
| ChipLogProgress(Zcl, "DiscoverCommandsReceivedResponse:"); |
| ChipLogProgress(Zcl, " ClusterId: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); |
| ChipLogProgress(Zcl, " manufacturerCode: 0x%04x", manufacturerCode); |
| ChipLogProgress(Zcl, " discoveryComplete: %d", discoveryComplete); |
| ChipLogProgress(Zcl, " commandIdCount: %" PRIu16, commandIdCount); |
| |
| for (uint16_t i = 0; i < commandIdCount; i++) |
| { |
| ChipLogProgress(Zcl, " commandId: " ChipLogFormatMEI, ChipLogValueMEI(*commandIds)); |
| commandIds++; |
| } |
| |
| GET_RESPONSE_CALLBACKS("emberAfDiscoverCommandsGeneratedResponseCallback"); |
| Callback::Callback<DefaultSuccessCallback> * cb = Callback::Callback<DefaultSuccessCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext); |
| return true; |
| } |
| |
| bool emberAfOtaSoftwareUpdateProviderClusterApplyUpdateRequestResponseCallback(EndpointId endpoint, app::CommandSender * commandObj, |
| uint8_t action, uint32_t delayedActionTime) |
| { |
| ChipLogProgress(Zcl, "ApplyUpdateRequestResponse:"); |
| ChipLogProgress(Zcl, " action: %" PRIu8 "", action); |
| ChipLogProgress(Zcl, " delayedActionTime: %" PRIu32 "", delayedActionTime); |
| |
| GET_CLUSTER_RESPONSE_CALLBACKS("OtaSoftwareUpdateProviderClusterApplyUpdateRequestResponseCallback"); |
| |
| Callback::Callback<OtaSoftwareUpdateProviderClusterApplyUpdateRequestResponseCallback> * cb = |
| Callback::Callback<OtaSoftwareUpdateProviderClusterApplyUpdateRequestResponseCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext, action, delayedActionTime); |
| return true; |
| } |
| |
| bool emberAfOtaSoftwareUpdateProviderClusterQueryImageResponseCallback(EndpointId endpoint, app::CommandSender * commandObj, |
| uint8_t status, uint32_t delayedActionTime, |
| uint8_t * imageURI, uint32_t softwareVersion, |
| uint8_t * softwareVersionString, chip::ByteSpan updateToken, |
| bool userConsentNeeded, chip::ByteSpan metadataForRequestor) |
| { |
| ChipLogProgress(Zcl, "QueryImageResponse:"); |
| ChipLogProgress(Zcl, " status: %" PRIu8 "", status); |
| ChipLogProgress(Zcl, " delayedActionTime: %" PRIu32 "", delayedActionTime); |
| // Currently the generated code emits `uint8_t *` for CHAR_STRING, it needs to emits ByteSpan |
| // ChipLogProgress(Zcl, " imageURI: %.*s", imageURI.size(), imageURI.data()); |
| ChipLogProgress(Zcl, " softwareVersion: %" PRIu32 "", softwareVersion); |
| // Currently the generated code emits `uint8_t *` for CHAR_STRING, it needs to emits ByteSpan |
| // ChipLogProgress(Zcl, " softwareVersionString: %.*s", softwareVersionString.size(), softwareVersionString.data()); |
| ChipLogProgress(Zcl, " updateToken: %zu", updateToken.size()); |
| ChipLogProgress(Zcl, " userConsentNeeded: %d", userConsentNeeded); |
| ChipLogProgress(Zcl, " metadataForRequestor: %zu", metadataForRequestor.size()); |
| |
| GET_CLUSTER_RESPONSE_CALLBACKS("OtaSoftwareUpdateProviderClusterQueryImageResponseCallback"); |
| |
| Callback::Callback<OtaSoftwareUpdateProviderClusterQueryImageResponseCallback> * cb = |
| Callback::Callback<OtaSoftwareUpdateProviderClusterQueryImageResponseCallback>::FromCancelable(onSuccessCallback); |
| cb->mCall(cb->mContext, status, delayedActionTime, imageURI, softwareVersion, softwareVersionString, updateToken, |
| userConsentNeeded, metadataForRequestor); |
| return true; |
| } |