-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BDXTransferServer to src/protocols/bdx
- Loading branch information
1 parent
a0fa83f
commit 1d1a95a
Showing
8 changed files
with
589 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <lib/core/CHIPError.h> | ||
#include <lib/core/DataModelTypes.h> | ||
#include <lib/core/NodeId.h> | ||
#include <lib/support/Span.h> | ||
|
||
namespace chip { | ||
namespace bdx { | ||
|
||
/** | ||
* A proxy object to control the state of a specific BDX transfer. | ||
*/ | ||
|
||
class BDXTransferProxy | ||
{ | ||
public: | ||
virtual ~BDXTransferProxy(){}; | ||
|
||
virtual CHIP_ERROR Accept() = 0; | ||
virtual CHIP_ERROR Reject(CHIP_ERROR error) = 0; | ||
virtual CHIP_ERROR Continue() = 0; | ||
|
||
virtual CharSpan GetFileDesignator() const = 0; | ||
virtual FabricIndex GetFabricIndex() const = 0; | ||
virtual NodeId GetPeerNodeId() const = 0; | ||
}; | ||
|
||
} // namespace bdx | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "BdxTransferProxyDiagnosticLog.h" | ||
|
||
#include <lib/core/CHIPSafeCasts.h> | ||
#include <lib/support/CHIPMemString.h> | ||
#include <platform/LockTracker.h> | ||
|
||
namespace chip { | ||
namespace bdx { | ||
|
||
CHIP_ERROR BDXTransferProxyDiagnosticLog::Init(TransferSession * transferSession) | ||
{ | ||
VerifyOrReturnError(nullptr != transferSession, CHIP_ERROR_INVALID_ARGUMENT); | ||
VerifyOrReturnError(nullptr == mTransfer, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
uint16_t fileDesignatorLength = 0; | ||
auto fileDesignator = transferSession->GetFileDesignator(fileDesignatorLength); | ||
|
||
VerifyOrReturnError(fileDesignatorLength > 0, CHIP_ERROR_INVALID_STRING_LENGTH); | ||
VerifyOrReturnError(fileDesignatorLength <= DiagnosticLogs::kMaxFileDesignatorLen, CHIP_ERROR_INVALID_STRING_LENGTH); | ||
|
||
mTransfer = transferSession; | ||
mFileDesignatorLen = static_cast<uint8_t>(fileDesignatorLength); | ||
Platform::CopyString(mFileDesignator, ByteSpan(fileDesignator, fileDesignatorLength)); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR BDXTransferProxyDiagnosticLog::Accept() | ||
{ | ||
ReturnErrorOnFailure(EnsureState()); | ||
VerifyOrReturnError(nullptr != mTransfer, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
TransferSession::TransferAcceptData acceptData; | ||
acceptData.ControlMode = TransferControlFlags::kSenderDrive; | ||
acceptData.MaxBlockSize = mTransfer->GetTransferBlockSize(); | ||
acceptData.StartOffset = mTransfer->GetStartOffset(); | ||
acceptData.Length = mTransfer->GetTransferLength(); | ||
|
||
return mTransfer->AcceptTransfer(acceptData); | ||
} | ||
|
||
CHIP_ERROR BDXTransferProxyDiagnosticLog::Reject(CHIP_ERROR error) | ||
{ | ||
ReturnErrorOnFailure(EnsureState()); | ||
VerifyOrReturnError(nullptr != mTransfer, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
auto statusCode = GetBdxStatusCodeFromChipError(error); | ||
return mTransfer->AbortTransfer(statusCode); | ||
} | ||
|
||
CHIP_ERROR BDXTransferProxyDiagnosticLog::Continue() | ||
{ | ||
ReturnErrorOnFailure(EnsureState()); | ||
VerifyOrReturnError(nullptr != mTransfer, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
return mTransfer->PrepareBlockAck(); | ||
} | ||
|
||
void BDXTransferProxyDiagnosticLog::Reset() | ||
{ | ||
ReturnOnFailure(EnsureState()); | ||
VerifyOrReturn(nullptr != mTransfer); | ||
|
||
memset(mFileDesignator, 0, sizeof(mFileDesignator)); | ||
mFileDesignatorLen = 0; | ||
mTransfer = nullptr; | ||
mFabricIndex = kUndefinedFabricIndex; | ||
mPeerNodeId = kUndefinedNodeId; | ||
} | ||
|
||
CHIP_ERROR BDXTransferProxyDiagnosticLog::EnsureState() const | ||
{ | ||
assertChipStackLockedByCurrentThread(); | ||
VerifyOrReturnError(kUndefinedFabricIndex != mFabricIndex, CHIP_ERROR_INCORRECT_STATE); | ||
VerifyOrReturnError(kUndefinedNodeId != mPeerNodeId, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
||
} // namespace bdx | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <protocols/bdx/BdxTransferProxy.h> | ||
#include <protocols/bdx/BdxTransferSession.h> | ||
#include <protocols/bdx/DiagnosticLogs.h> | ||
|
||
namespace chip { | ||
namespace bdx { | ||
|
||
class BDXTransferProxyDiagnosticLog : public BDXTransferProxy | ||
{ | ||
public: | ||
CHIP_ERROR Init(TransferSession * transferSession); | ||
void Reset(); | ||
|
||
void SetFabricIndex(FabricIndex fabricIndex) { mFabricIndex = fabricIndex; } | ||
void SetPeerNodeId(NodeId nodeId) { mPeerNodeId = nodeId; } | ||
|
||
CHIP_ERROR Accept() override; | ||
CHIP_ERROR Reject(CHIP_ERROR error) override; | ||
CHIP_ERROR Continue() override; | ||
|
||
FabricIndex GetFabricIndex() const override { return mFabricIndex; } | ||
NodeId GetPeerNodeId() const override { return mPeerNodeId; } | ||
CharSpan GetFileDesignator() const override { return CharSpan(mFileDesignator, mFileDesignatorLen); }; | ||
|
||
private: | ||
CHIP_ERROR EnsureState() const; | ||
|
||
uint8_t mFileDesignatorLen = 0; | ||
char mFileDesignator[DiagnosticLogs::kMaxFileDesignatorLen + 1] = {}; | ||
TransferSession * mTransfer = nullptr; | ||
FabricIndex mFabricIndex = kUndefinedFabricIndex; | ||
NodeId mPeerNodeId = kUndefinedNodeId; | ||
}; | ||
|
||
} // namespace bdx | ||
} // namespace chip |
Oops, something went wrong.