@@ -179,7 +179,7 @@ erpc_status_t RPMsgTTYRTOSTransport::init(uint32_t src_addr, uint32_t dst_addr,
179179 ready_cb ();
180180 }
181181
182- ( void ) rpmsg_lite_wait_for_link_up (s_rpmsg, RL_BLOCK);
182+ static_cast < void >( rpmsg_lite_wait_for_link_up (s_rpmsg, RL_BLOCK) );
183183
184184#if RL_USE_STATIC_API
185185 m_rpmsg_queue = rpmsg_queue_create (s_rpmsg, m_queue_stack, &m_queue_context);
@@ -257,32 +257,63 @@ erpc_status_t RPMsgTTYRTOSTransport::receive(MessageBuffer *message)
257257 erpc_status_t status = kErpcStatus_Success ;
258258 FramedTransport::Header h;
259259 char *buf = NULL ;
260+ char *buf2 = NULL ;
260261 uint32_t length = 0 ;
261262 int32_t ret_val = rpmsg_queue_recv_nocopy (s_rpmsg, m_rpmsg_queue, &m_dst_addr, &buf, &length, RL_BLOCK);
262263 uint16_t computedCrc;
263264
264265 erpc_assert ((m_crcImpl != NULL ) && (" Uninitialized Crc16 object." != NULL ));
265- erpc_assert (buf != NULL );
266266
267267 if (ret_val == RL_SUCCESS)
268268 {
269- (void )memcpy (reinterpret_cast <uint8_t *>(&h), buf, sizeof (h));
270- message->set (&(reinterpret_cast <uint8_t *>(buf))[sizeof (h)], length - sizeof (h));
271-
272- /* Verify CRC. */
273- computedCrc = m_crcImpl->computeCRC16 (&(reinterpret_cast <uint8_t *>(buf))[sizeof (h)], h.m_messageSize );
274- if (computedCrc != h.m_crc )
269+ erpc_assert (buf != NULL );
270+ if (length < sizeof (h))
275271 {
276- status = kErpcStatus_CrcCheckFailed ;
272+ status = kErpcStatus_ReceiveFailed ;
277273 }
278- else
274+ if (status == kErpcStatus_Success )
279275 {
280- message->setUsed (h.m_messageSize );
276+ static_cast <void >(memcpy (reinterpret_cast <uint8_t *>(&h), buf, sizeof (h)));
277+ /* If header and body is sent in two packets, we need call receive again to get body part. */
278+ if (length == sizeof (h))
279+ {
280+ ret_val = rpmsg_queue_recv_nocopy (s_rpmsg, m_rpmsg_queue, &m_dst_addr, &buf2, &length, RL_BLOCK);
281+ if (ret_val == RL_SUCCESS)
282+ {
283+ erpc_assert (buf2 != NULL );
284+ erpc_assert ((length + sizeof (h)) <= ERPC_DEFAULT_BUFFER_SIZE);
285+ static_cast <void >(memcpy (&buf[sizeof (h)], buf2, length));
286+ }
287+ static_cast <void >(rpmsg_lite_release_rx_buffer (s_rpmsg, buf2));
288+ }
289+ else
290+ {
291+ length -= sizeof (h); /* offset for MessageBuffer */
292+ }
293+ buf = &buf[sizeof (h)]; /* offset for MessageBuffer */
281294 }
282295 }
283- else
296+ if (status == kErpcStatus_Success )
284297 {
285- status = kErpcStatus_ReceiveFailed ;
298+ if (ret_val == RL_SUCCESS)
299+ {
300+ message->set (reinterpret_cast <uint8_t *>(buf), length);
301+
302+ /* Verify CRC. */
303+ computedCrc = m_crcImpl->computeCRC16 (reinterpret_cast <uint8_t *>(buf), h.m_messageSize );
304+ if (computedCrc != h.m_crc )
305+ {
306+ status = kErpcStatus_CrcCheckFailed ;
307+ }
308+ else
309+ {
310+ message->setUsed (h.m_messageSize );
311+ }
312+ }
313+ else
314+ {
315+ status = kErpcStatus_ReceiveFailed ;
316+ }
286317 }
287318
288319 return status;
@@ -303,7 +334,7 @@ erpc_status_t RPMsgTTYRTOSTransport::send(MessageBuffer *message)
303334 h.m_crc = m_crcImpl->computeCRC16 (buf, used);
304335 h.m_messageSize = used;
305336
306- ( void ) memcpy (&buf[-sizeof (h)], (uint8_t *)&h, sizeof (h));
337+ static_cast < void >( memcpy (&buf[-sizeof (h)], (uint8_t *)&h, sizeof (h) ));
307338
308339 ret_val = rpmsg_lite_send_nocopy (s_rpmsg, m_rpmsg_ept, m_dst_addr, &buf[-sizeof (h)], used + sizeof (h));
309340 if (ret_val == RL_SUCCESS)
0 commit comments