MCPcopy Create free account
hub / github.com/ReversecLabs/C3 / OnSend

Method OnSend

Src/Core/DeviceBridge.cpp:209–245  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

207
208////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209void 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}

Callers

nothing calls this directly

Calls 8

GetOutgoingPacketIdMethod · 0.80
to_stringFunction · 0.50
IsChannelMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected