I have used the wifi sta samples as the base for my wifi/network handling code running on custom product board using nrf5340/nrf7002 with NCS 2.8.
However, I have trouble understanding a couple of things about the net_mgmt events/callbacks, and can't work out how to reliably start network dependant code on top of them.
Q1: I use the following code to say 'tell me when the events I want happen':
net_mgmt_init_event_callback(&(ctx->wifi_sta_mgmt_cb), _wifi_mgmt_event_handler, // bizarre to or these when they are not bitmask seperated.. NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT | NET_EVENT_WIFI_IFACE_STATUS| NET_EVENT_WIFI_CMD_DISCONNECT_COMPLETE); net_mgmt_add_event_callback(&(ctx->wifi_sta_mgmt_cb)); net_mgmt_init_event_callback(&(ctx->net_addr_mgmt_cb), _net_mgmt_event_handler, NET_EVENT_IPV4_DHCP_START|NET_EVENT_IPV4_DHCP_BOUND|NET_EVENT_IPV4_DHCP_STOP); net_mgmt_add_event_callback(&(ctx->net_addr_mgmt_cb)); net_mgmt_init_event_callback(&(ctx->net_l4_mgmt_cb), _net_l4_event_handler, NET_EVENT_L4_CONNECTED|NET_EVENT_L4_DISCONNECTED); net_mgmt_add_event_callback(&(ctx->net_l4_mgmt_cb));
How does the 'event mask' parameter work, given that the various event enums are not in fact bit masks (they are just 1, 2, 3 valued, not 1,2,4,8 etc)? Seems like if I OR these toegther the mask is not going to match an event very well?
Q2: as you can see in the code, I want to get a NET_EVENT_L4_CONNECTED event. This was what I expected would tell me that the networking stack was ready to be used for IP based operation. Specifically, the definition of this event in net_event.h is: