///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 207 | |
| 208 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 209 | void FSecure::C3::Core::DeviceBridge::OnSend(ByteView command) |
| 210 | { |
| 211 | // Send to peripheral |
| 212 | if (!m_Device->IsChannel()) |
| 213 | { |
| 214 | m_Device->OnCommandFromConnector(command); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Send to channel. |
| 219 | |
| 220 | // Negotiation channel does not support chunking. Just pass packet and leave. |
| 221 | if (m_IsNegotiationChannel) |
| 222 | { |
| 223 | auto sent = GetDevice()->OnSendToChannelInternal(command); |
| 224 | if (sent != command.size()) |
| 225 | throw std::runtime_error{ OBF("Negotiation channel does not support chunking. Packet size: ") + std::to_string(command.size()) + OBF(" Channel sent: ") + std::to_string(sent) }; |
| 226 | |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | // Chunk message. |
| 231 | auto originalSize = static_cast<uint32_t>(command.size()); |
| 232 | auto messageId = m_QoS.GetOutgoingPacketId(); |
| 233 | uint32_t chunkId = 0u; |
| 234 | while (!command.empty()) |
| 235 | { |
| 236 | auto data = ByteVector{}.Write(messageId, chunkId, originalSize).Concat(command); |
| 237 | auto sent = GetDevice()->OnSendToChannelInternal(data); |
| 238 | |
| 239 | if (sent >= QualityOfService::s_MinFrameSize || sent == data.size()) // if this condition were not channel must resend data. |
| 240 | { |
| 241 | chunkId++; |
| 242 | command.remove_prefix(sent - QualityOfService::s_HeaderSize); |
| 243 | } |
| 244 | } |
| 245 | } |
nothing calls this directly
no test coverage detected