htc: implement much of worker receive logic

This commit is contained in:
Michael Scire
2021-02-08 14:11:01 -08:00
committed by SciresM
parent 8f85cc17dc
commit 679fec2ddc
19 changed files with 565 additions and 12 deletions

View File

@@ -82,8 +82,55 @@ namespace ams::htclow {
}
Result Worker::ProcessReceive() {
/* TODO */
AMS_ABORT("Worker::ProcessReceive");
/* Forever receive packets. */
u8 packet_header_storage[sizeof(m_packet_header)];
while (true) {
/* Receive the packet header. */
R_TRY(m_driver->Receive(packet_header_storage, sizeof(packet_header_storage)));
/* Check if the packet is a control packet. */
if (ctrl::HtcctrlPacketHeader *ctrl_header = reinterpret_cast<ctrl::HtcctrlPacketHeader *>(packet_header_storage); ctrl_header->signature == ctrl::HtcctrlSignature) {
/* Process the packet. */
R_TRY(this->ProcessReceive(*ctrl_header));
} else {
/* Otherwise, we must have a normal packet. */
PacketHeader *header = reinterpret_cast<PacketHeader *>(packet_header_storage);
R_UNLESS(header->signature == HtcGen2Signature, htclow::ResultProtocolError());
/* Process the packet. */
R_TRY(this->ProcessReceive(*header));
}
}
}
Result Worker::ProcessReceive(const ctrl::HtcctrlPacketHeader &header) {
/* Check the header. */
R_TRY(m_service->CheckReceivedHeader(header));
/* Receive the body, if we have one. */
if (header.body_size > 0) {
R_TRY(m_driver->Receive(m_receive_packet_body, header.body_size));
}
/* Process the received packet. */
m_service->ProcessReceivePacket(header, m_receive_packet_body, header.body_size);
return ResultSuccess();
}
Result Worker::ProcessReceive(const PacketHeader &header) {
/* Check the header. */
R_TRY(m_mux->CheckReceivedHeader(header));
/* Receive the body, if we have one. */
if (header.body_size > 0) {
R_TRY(m_driver->Receive(m_receive_packet_body, header.body_size));
}
/* Process the received packet. */
m_mux->ProcessReceivePacket(header, m_receive_packet_body, header.body_size);
return ResultSuccess();
}
Result Worker::ProcessSend() {