net: openthread: Add possibility to register ot state changed app cb

It may be useful for the application to register its own callback for
ot state changed event which does not override the current one.

Signed-off-by: Lukasz Maciejonczyk <lukasz.maciejonczyk@nordicsemi.no>
This commit is contained in:
Lukasz Maciejonczyk 2020-06-16 11:27:04 +02:00 committed by Jukka Rissanen
commit 74b1c617af
2 changed files with 12 additions and 0 deletions

View file

@ -30,6 +30,8 @@ struct openthread_context {
struct pkt_list_elem pkt_list[CONFIG_OPENTHREAD_PKT_LIST_SIZE];
};
void openthread_set_state_changed_cb(otStateChangedCallback cb);
k_tid_t openthread_thread_id_get(void);
struct openthread_context *openthread_get_default_context(void);

View file

@ -98,6 +98,7 @@ K_THREAD_STACK_DEFINE(ot_stack_area, OT_STACK_SIZE);
static struct k_thread ot_thread_data;
static k_tid_t ot_tid;
static struct net_linkaddr *ll_addr;
static otStateChangedCallback state_changed_cb;
static struct net_mgmt_event_callback ip6_addr_cb;
@ -165,6 +166,10 @@ void ot_state_changed_handler(uint32_t flags, void *context)
NET_DBG("Ipv6 multicast address added");
add_ipv6_maddr_to_zephyr(ot_context);
}
if (state_changed_cb) {
state_changed_cb(flags, context);
}
}
void ot_receive_handler(otMessage *aMessage, void *context)
@ -477,5 +482,10 @@ struct otInstance *openthread_get_default_instance(void)
return ot_context ? ot_context->instance : NULL;
}
void openthread_set_state_changed_cb(otStateChangedCallback cb)
{
state_changed_cb = cb;
}
NET_L2_INIT(OPENTHREAD_L2, openthread_recv, openthread_send,
NULL, openthread_flags);