net: openthread: Pass received frame to the proper thread.

Received frames shall be handled in the OpenThread thread, not in
the receiver thread.
Passed received frame to the function that will handle it in a proper
thread instead of calling otPlatRadioReceiveDone directly.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
This commit is contained in:
Marek Porwisz 2020-03-27 14:57:33 +01:00 committed by Jukka Rissanen
commit ccd74755d5
2 changed files with 10 additions and 29 deletions

View file

@ -256,30 +256,15 @@ static enum net_verdict openthread_recv(struct net_if *iface,
NET_DBG("Got 802.15.4 packet, sending to OT"); NET_DBG("Got 802.15.4 packet, sending to OT");
otRadioFrame recv_frame;
recv_frame.mPsdu = net_buf_frag_last(pkt->buffer)->data;
/* Length inc. CRC. */
recv_frame.mLength = net_buf_frags_len(pkt->buffer);
recv_frame.mChannel = platformRadioChannelGet(ot_context->instance);
recv_frame.mInfo.mRxInfo.mLqi = net_pkt_ieee802154_lqi(pkt);
recv_frame.mInfo.mRxInfo.mRssi = net_pkt_ieee802154_rssi(pkt);
if (IS_ENABLED(CONFIG_OPENTHREAD_L2_DEBUG_DUMP_IPV6)) { if (IS_ENABLED(CONFIG_OPENTHREAD_L2_DEBUG_DUMP_IPV6)) {
net_pkt_hexdump(pkt, "Received 802.15.4 frame"); net_pkt_hexdump(pkt, "Received 802.15.4 frame");
} }
if (IS_ENABLED(OPENTHREAD_ENABLE_DIAG) && otPlatDiagModeGet()) { if (notify_new_rx_frame(pkt) != 0) {
otPlatDiagRadioReceiveDone(ot_context->instance, NET_ERR("Failed to queue RX packet for OpenThread");
&recv_frame, OT_ERROR_NONE); return NET_DROP;
} else {
otPlatRadioReceiveDone(ot_context->instance,
&recv_frame, OT_ERROR_NONE);
} }
net_pkt_unref(pkt);
return NET_OK; return NET_OK;
} }

View file

@ -45,8 +45,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
#define OT_WORKER_STACK_SIZE 512 #define OT_WORKER_STACK_SIZE 512
#define OT_WORKER_PRIORITY K_PRIO_COOP(CONFIG_OPENTHREAD_THREAD_PRIORITY) #define OT_WORKER_PRIORITY K_PRIO_COOP(CONFIG_OPENTHREAD_THREAD_PRIORITY)
#define OT_RX_MESSAGES 5
enum pending_events { enum pending_events {
PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */ PENDING_EVENT_FRAME_RECEIVED, /* Radio has received new frame */
PENDING_EVENT_TX_STARTED, /* Radio has started transmitting */ PENDING_EVENT_TX_STARTED, /* Radio has started transmitting */
@ -85,7 +83,7 @@ K_THREAD_STACK_DEFINE(ot_task_stack, OT_WORKER_STACK_SIZE);
static struct k_work_q ot_work_q; static struct k_work_q ot_work_q;
static otError tx_result; static otError tx_result;
K_MSGQ_DEFINE(rx_pkt_queue, sizeof(struct net_pkt *), OT_RX_MESSAGES, 4); K_FIFO_DEFINE(rx_pkt_fifo);
static inline bool is_pending_event_set(enum pending_events event) static inline bool is_pending_event_set(enum pending_events event)
{ {
@ -297,14 +295,10 @@ static void openthread_handle_received_frame(otInstance *instance,
int notify_new_rx_frame(struct net_pkt *pkt) int notify_new_rx_frame(struct net_pkt *pkt)
{ {
int err = -ENOBUFS; k_fifo_put(&rx_pkt_fifo, pkt);
set_pending_event(PENDING_EVENT_FRAME_RECEIVED);
if (k_msgq_put(&rx_pkt_queue, &pkt, K_FOREVER) == 0) { return 0;
err = 0;
set_pending_event(PENDING_EVENT_FRAME_RECEIVED);
}
return err;
} }
static int run_tx_task(otInstance *aInstance) static int run_tx_task(otInstance *aInstance)
@ -332,7 +326,9 @@ void platformRadioProcess(otInstance *aInstance)
struct net_pkt *rx_pkt; struct net_pkt *rx_pkt;
reset_pending_event(PENDING_EVENT_FRAME_RECEIVED); reset_pending_event(PENDING_EVENT_FRAME_RECEIVED);
while (k_msgq_get(&rx_pkt_queue, &rx_pkt, K_NO_WAIT) == 0) { while ((rx_pkt = (struct net_pkt *)k_fifo_get(&rx_pkt_fifo,
K_NO_WAIT))
!= NULL) {
openthread_handle_received_frame(aInstance, rx_pkt); openthread_handle_received_frame(aInstance, rx_pkt);
} }
} }