Line data Source code
1 : /* 2 : * Copyright (c) 2021 Project CHIP Authors 3 : * 4 : * Licensed under the Apache License, Version 2.0 (the "License"); 5 : * you may not use this file except in compliance with the License. 6 : * You may obtain a copy of the License at 7 : * 8 : * http://www.apache.org/licenses/LICENSE-2.0 9 : * 10 : * Unless required by applicable law or agreed to in writing, software 11 : * distributed under the License is distributed on an "AS IS" BASIS, 12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 : * See the License for the specific language governing permissions and 14 : * limitations under the License. 15 : */ 16 : 17 : #pragma once 18 : 19 : #include <app/util/basic-types.h> 20 : #include <lib/core/GroupId.h> 21 : #include <lib/core/ReferenceCounted.h> 22 : #include <lib/support/Pool.h> 23 : #include <transport/Session.h> 24 : 25 : namespace chip { 26 : namespace Transport { 27 : 28 : class IncomingGroupSession : public Session, public ReferenceCounted<IncomingGroupSession, NoopDeletor<IncomingGroupSession>, 0> 29 : { 30 : public: 31 0 : IncomingGroupSession(GroupId group, FabricIndex fabricIndex, NodeId peerNodeId) : mGroupId(group), mPeerNodeId(peerNodeId) 32 : { 33 0 : SetFabricIndex(fabricIndex); 34 0 : } 35 0 : ~IncomingGroupSession() override 36 0 : { 37 0 : NotifySessionReleased(); 38 0 : VerifyOrDie(GetReferenceCount() == 0); 39 0 : } 40 : 41 0 : void Retain() override { ReferenceCounted<IncomingGroupSession, NoopDeletor<IncomingGroupSession>, 0>::Retain(); } 42 0 : void Release() override { ReferenceCounted<IncomingGroupSession, NoopDeletor<IncomingGroupSession>, 0>::Release(); } 43 : 44 0 : bool IsActiveSession() const override { return true; } 45 : 46 0 : Session::SessionType GetSessionType() const override { return Session::SessionType::kGroupIncoming; } 47 : 48 0 : ScopedNodeId GetPeer() const override { return ScopedNodeId(mPeerNodeId, GetFabricIndex()); } 49 0 : ScopedNodeId GetLocalScopedNodeId() const override { return ScopedNodeId(kUndefinedNodeId, GetFabricIndex()); } 50 : 51 0 : Access::SubjectDescriptor GetSubjectDescriptor() const override 52 : { 53 0 : Access::SubjectDescriptor subjectDescriptor; 54 0 : subjectDescriptor.authMode = Access::AuthMode::kGroup; 55 0 : subjectDescriptor.subject = NodeIdFromGroupId(mGroupId); 56 0 : subjectDescriptor.fabricIndex = GetFabricIndex(); 57 0 : return subjectDescriptor; 58 : } 59 : 60 0 : bool AllowsMRP() const override { return false; } 61 0 : bool AllowsLargePayload() const override { return false; } 62 : 63 0 : const SessionParameters & GetRemoteSessionParameters() const override 64 : { 65 0 : static const SessionParameters cfg(GetDefaultMRPConfig()); 66 0 : VerifyOrDie(false); 67 : return cfg; 68 : } 69 : 70 0 : System::Clock::Timestamp GetMRPBaseTimeout() const override { return System::Clock::kZero; } 71 : 72 0 : System::Clock::Milliseconds32 GetAckTimeout() const override 73 : { 74 0 : VerifyOrDie(false); 75 : return System::Clock::Timeout(); 76 : } 77 : 78 0 : GroupId GetGroupId() const { return mGroupId; } 79 : 80 : private: 81 : const GroupId mGroupId; 82 : const NodeId mPeerNodeId; 83 : }; 84 : 85 : class OutgoingGroupSession : public Session, public ReferenceCounted<OutgoingGroupSession, NoopDeletor<OutgoingGroupSession>, 0> 86 : { 87 : public: 88 : OutgoingGroupSession(GroupId group, FabricIndex fabricIndex) : mGroupId(group) { SetFabricIndex(fabricIndex); } 89 : ~OutgoingGroupSession() override 90 : { 91 : NotifySessionReleased(); 92 : VerifyOrDie(GetReferenceCount() == 0); 93 : } 94 : 95 : void Retain() override { ReferenceCounted<OutgoingGroupSession, NoopDeletor<OutgoingGroupSession>, 0>::Retain(); } 96 : void Release() override { ReferenceCounted<OutgoingGroupSession, NoopDeletor<OutgoingGroupSession>, 0>::Release(); } 97 : 98 : bool IsActiveSession() const override { return true; } 99 : 100 : Session::SessionType GetSessionType() const override { return Session::SessionType::kGroupOutgoing; } 101 : 102 : // Peer node ID is unused: users care about the group, not the node 103 : ScopedNodeId GetPeer() const override { return ScopedNodeId(); } 104 : // Local node ID is unused: users care about the group, not the node 105 : ScopedNodeId GetLocalScopedNodeId() const override { return ScopedNodeId(); } 106 : 107 : Access::SubjectDescriptor GetSubjectDescriptor() const override 108 : { 109 : return Access::SubjectDescriptor(); // no subject exists for outgoing group session. 110 : } 111 : 112 : bool AllowsMRP() const override { return false; } 113 : bool AllowsLargePayload() const override { return false; } 114 : 115 : const SessionParameters & GetRemoteSessionParameters() const override 116 : { 117 : static const SessionParameters cfg(GetDefaultMRPConfig()); 118 : VerifyOrDie(false); 119 : return cfg; 120 : } 121 : 122 : System::Clock::Timestamp GetMRPBaseTimeout() const override { return System::Clock::kZero; } 123 : 124 : System::Clock::Milliseconds32 GetAckTimeout() const override 125 : { 126 : VerifyOrDie(false); 127 : return System::Clock::Timeout(); 128 : } 129 : 130 6 : GroupId GetGroupId() const { return mGroupId; } 131 : 132 : private: 133 : const GroupId mGroupId; 134 : }; 135 : 136 : } // namespace Transport 137 : } // namespace chip