From 5b2cd323685d6ca9b1a2feb3aae26ed67aec9e43 Mon Sep 17 00:00:00 2001 From: shihchienc Date: Wed, 31 Jan 2024 07:13:52 +0000 Subject: [PATCH] [Thread] Implement write on socket interface Bug: 313425570 Test: build pass & manual test Change-Id: I2da14a563b795b0044362c1c248b53c1d3505d39 --- .../aidl/default/socket_interface.cpp | 12 ++++++++++ .../aidl/default/socket_interface.hpp | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/threadnetwork/aidl/default/socket_interface.cpp b/threadnetwork/aidl/default/socket_interface.cpp index a8b434af07..6b9b80eb07 100644 --- a/threadnetwork/aidl/default/socket_interface.cpp +++ b/threadnetwork/aidl/default/socket_interface.cpp @@ -83,6 +83,12 @@ void SocketInterface::Deinit(void) { mReceiveFrameBuffer = nullptr; } +otError SocketInterface::SendFrame(const uint8_t* aFrame, uint16_t aLength) { + Write(aFrame, aLength); + + return OT_ERROR_NONE; +} + void SocketInterface::UpdateFdSet(void* aMainloopContext) { otSysMainloopContext* context = reinterpret_cast(aMainloopContext); @@ -95,6 +101,12 @@ void SocketInterface::UpdateFdSet(void* aMainloopContext) { } } +void SocketInterface::Write(const uint8_t* aFrame, uint16_t aLength) { + ssize_t rval = TEMP_FAILURE_RETRY(write(mSockFd, aFrame, aLength)); + VerifyOrDie(rval >= 0, OT_EXIT_ERROR_ERRNO); + VerifyOrDie(rval > 0, OT_EXIT_FAILURE); +} + int SocketInterface::OpenFile(const ot::Url::Url& aRadioUrl) { int fd = -1; sockaddr_un serverAddress; diff --git a/threadnetwork/aidl/default/socket_interface.hpp b/threadnetwork/aidl/default/socket_interface.hpp index 23940f5fda..2dd315d125 100644 --- a/threadnetwork/aidl/default/socket_interface.hpp +++ b/threadnetwork/aidl/default/socket_interface.hpp @@ -72,6 +72,20 @@ class SocketInterface : public ot::Spinel::SpinelInterface { */ void Deinit(void); + /** + * Sends a Spinel frame to Radio Co-processor (RCP) over the + * socket. + * + * @param[in] aFrame A pointer to buffer containing the Spinel frame to + * send. + * @param[in] aLength The length (number of bytes) in the frame. + * + * @retval OT_ERROR_NONE Successfully sent the Spinel frame. + * @retval OT_ERROR_FAILED Failed to send a frame. + * + */ + otError SendFrame(const uint8_t* aFrame, uint16_t aLength); + /** * Updates the file descriptor sets with file descriptors used by the radio * driver. @@ -122,6 +136,15 @@ class SocketInterface : public ot::Spinel::SpinelInterface { } private: + /** + * Writes a given frame to the socket. + * + * @param[in] aFrame A pointer to buffer containing the frame to write. + * @param[in] aLength The length (number of bytes) in the frame. + * + */ + void Write(const uint8_t* aFrame, uint16_t aLength); + /** * Opens file specified by aRadioUrl. *