[Thread] Implement write on socket interface
Bug: 313425570
Test: build pass & manual test
Change-Id: I2da14a563b795b0044362c1c248b53c1d3505d39
diff --git a/threadnetwork/aidl/default/socket_interface.cpp b/threadnetwork/aidl/default/socket_interface.cpp
index a8b434a..6b9b80e 100644
--- a/threadnetwork/aidl/default/socket_interface.cpp
+++ b/threadnetwork/aidl/default/socket_interface.cpp
@@ -83,6 +83,12 @@
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<otSysMainloopContext*>(aMainloopContext);
@@ -95,6 +101,12 @@
}
}
+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 23940f5..2dd315d 100644
--- a/threadnetwork/aidl/default/socket_interface.hpp
+++ b/threadnetwork/aidl/default/socket_interface.hpp
@@ -73,6 +73,20 @@
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.
*
@@ -123,6 +137,15 @@
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.
*
* @param[in] aRadioUrl A reference to object containing path to file and