|
36 | 36 |
|
37 | 37 | using namespace chip;
|
38 | 38 |
|
| 39 | +using namespace chip::app; |
| 40 | +using namespace chip::app::Clusters; |
| 41 | +using namespace chip::app::Clusters::AdministratorCommissioning; |
| 42 | + |
39 | 43 | #define ZCL_DESCRIPTOR_CLUSTER_REVISION (1u)
|
40 | 44 | #define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_CLUSTER_REVISION (2u)
|
41 | 45 | #define ZCL_BRIDGED_DEVICE_BASIC_INFORMATION_FEATURE_MAP (0u)
|
@@ -97,10 +101,62 @@ void AttemptRpcClientConnect(System::Layer * systemLayer, void * appState)
|
97 | 101 | }
|
98 | 102 | #endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
|
99 | 103 |
|
| 104 | +class AdministratorCommissioningCommandHandler : public CommandHandlerInterface |
| 105 | +{ |
| 106 | +public: |
| 107 | + // Register for the AdministratorCommissioning cluster on all endpoints. |
| 108 | + AdministratorCommissioningCommandHandler() : |
| 109 | + CommandHandlerInterface(Optional<EndpointId>::Missing(), AdministratorCommissioning::Id) |
| 110 | + {} |
| 111 | + |
| 112 | + void InvokeCommand(HandlerContext & handlerContext) override; |
| 113 | +}; |
| 114 | + |
| 115 | +void AdministratorCommissioningCommandHandler::InvokeCommand(HandlerContext & handlerContext) |
| 116 | +{ |
| 117 | + using Protocols::InteractionModel::Status; |
| 118 | + |
| 119 | + EndpointId endpointId = handlerContext.mRequestPath.mEndpointId; |
| 120 | + ChipLogProgress(NotSpecified, "Received command to open commissioning window on Endpoind: %d", endpointId); |
| 121 | + |
| 122 | + if (handlerContext.mRequestPath.mCommandId != Commands::OpenCommissioningWindow::Id || endpointId == kRootEndpointId) |
| 123 | + { |
| 124 | + // Proceed with default handling in Administrator Commissioning Server |
| 125 | + return; |
| 126 | + } |
| 127 | + |
| 128 | + handlerContext.SetCommandHandled(); |
| 129 | + Status status = Status::Success; |
| 130 | + |
| 131 | +#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE |
| 132 | + Device * device = DeviceMgr().GetDevice(endpointId); |
| 133 | + |
| 134 | + // TODO: issues:#33784, need to make OpenCommissioningWindow synchronous |
| 135 | + if (device != nullptr && OpenCommissioningWindow(device->GetNodeId()) == CHIP_NO_ERROR) |
| 136 | + { |
| 137 | + ChipLogProgress(NotSpecified, "Commissioning window is now open"); |
| 138 | + } |
| 139 | + else |
| 140 | + { |
| 141 | + status = Status::Failure; |
| 142 | + ChipLogProgress(NotSpecified, "Commissioning window is failed to open"); |
| 143 | + } |
| 144 | +#else |
| 145 | + status = Status::Failure; |
| 146 | + ChipLogProgress(NotSpecified, "Commissioning window failed to open: PW_RPC_FABRIC_BRIDGE_SERVICE not defined"); |
| 147 | +#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE |
| 148 | + |
| 149 | + handlerContext.mCommandHandler.AddStatus(handlerContext.mRequestPath, status); |
| 150 | +} |
| 151 | + |
| 152 | +AdministratorCommissioningCommandHandler gAdministratorCommissioningCommandHandler; |
| 153 | + |
100 | 154 | } // namespace
|
101 | 155 |
|
102 | 156 | void ApplicationInit()
|
103 | 157 | {
|
| 158 | + InteractionModelEngine::GetInstance()->RegisterCommandHandler(&gAdministratorCommissioningCommandHandler); |
| 159 | + |
104 | 160 | #if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
|
105 | 161 | InitRpcServer(kFabricBridgeServerPort);
|
106 | 162 | AttemptRpcClientConnect(&DeviceLayer::SystemLayer(), nullptr);
|
|
0 commit comments