From c62f8b4e93b766d1d19a6bbfd1f25bb358a5c94a Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Thu, 21 May 2026 14:27:14 -0300 Subject: [PATCH] rename ifp state change event --- mongoose.c | 16 +++++------ mongoose.h | 27 +++++++++---------- src/drivers/cyw.c | 2 +- src/drivers/nxp_wifi.c | 2 +- src/drivers/pico-w.c | 2 +- src/drivers/st67w6.c | 2 +- src/net_builtin.c | 8 +++--- src/net_builtin.h | 27 +++++++++---------- test/mip_test.c | 4 +-- test/tls_multirec/patched_mongoose.c | 2 +- .../source/main.c | 10 +++---- tutorials/rp/pico-rm2/wifi.c | 10 +++---- tutorials/rp/pico-w/wifi.c | 10 +++---- .../stm32/nucleo-f429zi/minimal-rm2/main.c | 10 +++---- .../stm32/nucleo-f746zg/minimal-rm2/main.c | 10 +++---- tutorials/tcpip/pcap-driver/main.c | 4 +-- tutorials/tcpip/tap-driver/main.c | 2 +- 17 files changed, 73 insertions(+), 75 deletions(-) diff --git a/mongoose.c b/mongoose.c index 283e98f5..d06865ae 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6974,11 +6974,11 @@ bool mg_l2_poll(struct mg_tcpip_if *ifp, bool expired_1000ms); static void mg_tcpip_call(struct mg_tcpip_if *ifp, int ev, void *ev_data) { #if 0 && MG_ENABLE_PROFILE - const char *names[] = {"TCPIP_EV_ST_CHG", "TCPIP_EV_DHCP_DNS", + const char *names[] = {"TCPIP_EV_STATE_CHANGE", "TCPIP_EV_DHCP_DNS", "TCPIP_EV_DHCP_SNTP", "TCPIP_EV_ARP", "TCPIP_EV_TIMER_1S", "TCPIP_EV_WIFI_SCAN_RESULT", "TCPIP_EV_WIFI_SCAN_END", "TCPIP_EV_WIFI_CONNECT_ERR", - "TCPIP_EV_DRIVER", "MG_TCPIP_EV_ST6_CHG", + "TCPIP_EV_DRIVER", "TCPIP_EV_STATE6_CHANGE", "TCPIP_EV_USER"}; if (ev != MG_TCPIP_EV_TIMER_1S && ev < (int) (sizeof(names) / sizeof(names[0]))) { MG_PROF_ADD(ifp, names[ev]); // TODO(): call MG_PROF_DUMP() MG_PROF_FREE() @@ -7163,7 +7163,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) { } else if (ifp->state == MG_TCPIP_STATE_DOWN) { MG_ERROR(("Link down")); } - mg_tcpip_call(ifp, MG_TCPIP_EV_ST_CHG, &ifp->state); + mg_tcpip_call(ifp, MG_TCPIP_EV_STATE_CHANGE, &ifp->state); } static struct ip *tx_ip(struct mg_tcpip_if *ifp, uint8_t *l2_dst, uint8_t proto, @@ -7845,7 +7845,7 @@ static void onstate6change(struct mg_tcpip_if *ifp) { MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll)); } if (ifp->state6 > MG_TCPIP_STATE_UP) - mg_tcpip_call(ifp, MG_TCPIP_EV_ST6_CHG, &ifp->state6); + mg_tcpip_call(ifp, MG_TCPIP_EV_STATE6_CHANGE, &ifp->state6); } #endif @@ -24929,7 +24929,7 @@ static bool s_link, s_auth, s_join; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; s_mask = ifp->mask, ifp->mask = wifi->apmask; @@ -26590,7 +26590,7 @@ static uint32_t s_ip, s_mask; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; @@ -26843,7 +26843,7 @@ static bool s_stalink = false, s_connecting = false; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_pico_w_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; @@ -27926,7 +27926,7 @@ static bool s_link = false, s_connecting = false; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_st67w6_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; diff --git a/mongoose.h b/mongoose.h index e936e5e6..efb8d370 100644 --- a/mongoose.h +++ b/mongoose.h @@ -3441,22 +3441,21 @@ struct mg_tcpip_driver { typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev, void *ev_data); +//clang-format off enum { - MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state) - MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr - MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr - MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str * - MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL - MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct - // mg_wifi_scan_bss_data * - MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL - MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and - // chip specific - MG_TCPIP_EV_DRIVER, // Driver event driver specific - MG_TCPIP_EV_ST6_CHG, // state6 change uint8_t * - // (&ifp->state6) - MG_TCPIP_EV_USER // Starting ID for user events + MG_TCPIP_EV_STATE_CHANGE, // state change uint8_t *(&ifp->state) + MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr + MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr + MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str * + MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL + MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct mg_wifi_scan_bss_data * + MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL + MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and chip specific + MG_TCPIP_EV_DRIVER, // Driver event driver specific + MG_TCPIP_EV_STATE6_CHANGE, // state6 change uint8_t *(&ifp->state6) + MG_TCPIP_EV_USER // Starting ID for user events }; +//clang-format on // Network interface struct mg_tcpip_if { diff --git a/src/drivers/cyw.c b/src/drivers/cyw.c index b8c4d694..92c45b83 100644 --- a/src/drivers/cyw.c +++ b/src/drivers/cyw.c @@ -18,7 +18,7 @@ static bool s_link, s_auth, s_join; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; s_mask = ifp->mask, ifp->mask = wifi->apmask; diff --git a/src/drivers/nxp_wifi.c b/src/drivers/nxp_wifi.c index 36179c5f..f5bc2f3e 100644 --- a/src/drivers/nxp_wifi.c +++ b/src/drivers/nxp_wifi.c @@ -33,7 +33,7 @@ static uint32_t s_ip, s_mask; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; diff --git a/src/drivers/pico-w.c b/src/drivers/pico-w.c index 398875ae..e0199b8f 100644 --- a/src/drivers/pico-w.c +++ b/src/drivers/pico-w.c @@ -13,7 +13,7 @@ static bool s_stalink = false, s_connecting = false; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_pico_w_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; diff --git a/src/drivers/st67w6.c b/src/drivers/st67w6.c index 0c27b530..3790020b 100644 --- a/src/drivers/st67w6.c +++ b/src/drivers/st67w6.c @@ -11,7 +11,7 @@ static bool s_link = false, s_connecting = false; static void wifi_cb(struct mg_tcpip_if *ifp, int ev, void *ev_data) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_st67w6_data *) ifp->driver_data)->wifi; - if (wifi->apmode && ev == MG_TCPIP_EV_ST_CHG && + if (wifi->apmode && ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_UP) { MG_DEBUG(("Access Point started")); s_ip = ifp->ip, ifp->ip = wifi->apip; diff --git a/src/net_builtin.c b/src/net_builtin.c index bea2bc72..a4d9ff92 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -210,11 +210,11 @@ bool mg_l2_poll(struct mg_tcpip_if *ifp, bool expired_1000ms); static void mg_tcpip_call(struct mg_tcpip_if *ifp, int ev, void *ev_data) { #if 0 && MG_ENABLE_PROFILE - const char *names[] = {"TCPIP_EV_ST_CHG", "TCPIP_EV_DHCP_DNS", + const char *names[] = {"TCPIP_EV_STATE_CHANGE", "TCPIP_EV_DHCP_DNS", "TCPIP_EV_DHCP_SNTP", "TCPIP_EV_ARP", "TCPIP_EV_TIMER_1S", "TCPIP_EV_WIFI_SCAN_RESULT", "TCPIP_EV_WIFI_SCAN_END", "TCPIP_EV_WIFI_CONNECT_ERR", - "TCPIP_EV_DRIVER", "MG_TCPIP_EV_ST6_CHG", + "TCPIP_EV_DRIVER", "TCPIP_EV_STATE6_CHANGE", "TCPIP_EV_USER"}; if (ev != MG_TCPIP_EV_TIMER_1S && ev < (int) (sizeof(names) / sizeof(names[0]))) { MG_PROF_ADD(ifp, names[ev]); // TODO(): call MG_PROF_DUMP() MG_PROF_FREE() @@ -399,7 +399,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) { } else if (ifp->state == MG_TCPIP_STATE_DOWN) { MG_ERROR(("Link down")); } - mg_tcpip_call(ifp, MG_TCPIP_EV_ST_CHG, &ifp->state); + mg_tcpip_call(ifp, MG_TCPIP_EV_STATE_CHANGE, &ifp->state); } static struct ip *tx_ip(struct mg_tcpip_if *ifp, uint8_t *l2_dst, uint8_t proto, @@ -1081,7 +1081,7 @@ static void onstate6change(struct mg_tcpip_if *ifp) { MG_INFO(("IP: %M", mg_print_ip6, &ifp->ip6ll)); } if (ifp->state6 > MG_TCPIP_STATE_UP) - mg_tcpip_call(ifp, MG_TCPIP_EV_ST6_CHG, &ifp->state6); + mg_tcpip_call(ifp, MG_TCPIP_EV_STATE6_CHANGE, &ifp->state6); } #endif diff --git a/src/net_builtin.h b/src/net_builtin.h index d9e93547..3c7145e8 100644 --- a/src/net_builtin.h +++ b/src/net_builtin.h @@ -20,22 +20,21 @@ struct mg_tcpip_driver { typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev, void *ev_data); +//clang-format off enum { - MG_TCPIP_EV_ST_CHG, // state change uint8_t * (&ifp->state) - MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr - MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr - MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str * - MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL - MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct - // mg_wifi_scan_bss_data * - MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL - MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and - // chip specific - MG_TCPIP_EV_DRIVER, // Driver event driver specific - MG_TCPIP_EV_ST6_CHG, // state6 change uint8_t * - // (&ifp->state6) - MG_TCPIP_EV_USER // Starting ID for user events + MG_TCPIP_EV_STATE_CHANGE, // state change uint8_t *(&ifp->state) + MG_TCPIP_EV_DHCP_DNS, // DHCP DNS assignment uint32_t *ipaddr + MG_TCPIP_EV_DHCP_SNTP, // DHCP SNTP assignment uint32_t *ipaddr + MG_TCPIP_EV_ARP, // Got ARP packet struct mg_str * + MG_TCPIP_EV_TIMER_1S, // 1 second timer NULL + MG_TCPIP_EV_WIFI_SCAN_RESULT, // Wi-Fi scan results struct mg_wifi_scan_bss_data * + MG_TCPIP_EV_WIFI_SCAN_END, // Wi-Fi scan has finished NULL + MG_TCPIP_EV_WIFI_CONNECT_ERR, // Wi-Fi connect has failed driver and chip specific + MG_TCPIP_EV_DRIVER, // Driver event driver specific + MG_TCPIP_EV_STATE6_CHANGE, // state6 change uint8_t *(&ifp->state6) + MG_TCPIP_EV_USER // Starting ID for user events }; +//clang-format on // Network interface struct mg_tcpip_if { diff --git a/test/mip_test.c b/test/mip_test.c index ca63981b..10773b53 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -61,7 +61,7 @@ static void test_csum(void) { static bool executed = false; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_UP); executed = true; } @@ -81,7 +81,7 @@ static void test_statechange(void) { } #if MG_ENABLE_IPV6 static void mif6_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { - if (ev == MG_TCPIP_EV_ST6_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_REQ); executed = true; } diff --git a/test/tls_multirec/patched_mongoose.c b/test/tls_multirec/patched_mongoose.c index b3f1c83a..aa576077 100644 --- a/test/tls_multirec/patched_mongoose.c +++ b/test/tls_multirec/patched_mongoose.c @@ -4294,7 +4294,7 @@ static void onstatechange(struct mg_tcpip_if *ifp) { } else if (ifp->state == MG_TCPIP_STATE_DOWN) { MG_ERROR(("Link down")); } - mg_tcpip_call(ifp, MG_TCPIP_EV_ST_CHG, &ifp->state); + mg_tcpip_call(ifp, MG_TCPIP_EV_STATE_CHANGE, &ifp->state); } static struct ip *tx_ip(struct mg_tcpip_if *ifp, uint8_t *mac_dst, diff --git a/tutorials/nxp/frdm-rw612-xpresso-freertos-builtin-wifi/source/main.c b/tutorials/nxp/frdm-rw612-xpresso-freertos-builtin-wifi/source/main.c index 04209106..9ce9c1f0 100644 --- a/tutorials/nxp/frdm-rw612-xpresso-freertos-builtin-wifi/source/main.c +++ b/tutorials/nxp/frdm-rw612-xpresso-freertos-builtin-wifi/source/main.c @@ -27,12 +27,12 @@ static unsigned int state; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { // TODO(): should we include this inside ifp ? add an fn_data ? - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } switch(state) { case AP: // we are in AP mode, wait for a user connection to trigger a scan or a connection to a network - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("Access Point READY !")); // simulate user request to scan for networks @@ -57,7 +57,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case STOPPING_AP: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi; wifi->apmode = false; @@ -70,7 +70,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case CONNECTING: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("READY!")); state = READY; @@ -84,7 +84,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { break; case READY: // go back to AP mode after a disconnection (simulation 2/2), you could retry - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_nxp_wifi_data *) ifp->driver_data)->wifi; bool res = mg_wifi_ap_start(wifi); MG_INFO(("Disconnected")); diff --git a/tutorials/rp/pico-rm2/wifi.c b/tutorials/rp/pico-rm2/wifi.c index fb67f2e2..d208e68a 100644 --- a/tutorials/rp/pico-rm2/wifi.c +++ b/tutorials/rp/pico-rm2/wifi.c @@ -183,13 +183,13 @@ static unsigned int state; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { // TODO(): should we include this inside ifp ? add an fn_data ? - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } switch (state) { case AP: // we are in AP mode, wait for a user connection to trigger a scan // or a connection to a network - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("Access Point READY !")); @@ -219,7 +219,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case STOPPING_AP: - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; @@ -234,7 +234,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case CONNECTING: - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("READY!")); state = READY; @@ -251,7 +251,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { case READY: // go back to AP mode after a disconnection (simulation 2/2), you could // retry - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; diff --git a/tutorials/rp/pico-w/wifi.c b/tutorials/rp/pico-w/wifi.c index 0dbb1f8a..4e0e4372 100644 --- a/tutorials/rp/pico-w/wifi.c +++ b/tutorials/rp/pico-w/wifi.c @@ -17,13 +17,13 @@ static unsigned int state; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { // TODO(): should we include this inside ifp ? add an fn_data ? - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } switch (state) { case AP: // we are in AP mode, wait for a user connection to trigger a scan // or a connection to a network - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("Access Point READY !")); @@ -53,7 +53,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case STOPPING_AP: - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_pico_w_data *) ifp->driver_data)->wifi; @@ -68,7 +68,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case CONNECTING: - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("READY!")); state = READY; @@ -85,7 +85,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { case READY: // go back to AP mode after a disconnection (simulation 2/2), you could // retry - if (ev == MG_TCPIP_EV_ST_CHG && + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_pico_w_data *) ifp->driver_data)->wifi; diff --git a/tutorials/stm32/nucleo-f429zi/minimal-rm2/main.c b/tutorials/stm32/nucleo-f429zi/minimal-rm2/main.c index 052e12cd..d8c0fe77 100644 --- a/tutorials/stm32/nucleo-f429zi/minimal-rm2/main.c +++ b/tutorials/stm32/nucleo-f429zi/minimal-rm2/main.c @@ -89,12 +89,12 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { if (ev == MG_TCPIP_EV_DRIVER) { spi_setup(CYWSPI, 3); // /16: 2.8MHz SPI3, 5.6MHz SPI1 (< 50MHz) } - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } switch(state) { case AP: // we are in AP mode, wait for a user connection to trigger a scan or a connection to a network - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("Access Point READY !")); // simulate user request to scan for networks @@ -119,7 +119,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case STOPPING_AP: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; wifi->apmode = false; @@ -132,7 +132,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case CONNECTING: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("READY!")); state = READY; @@ -146,7 +146,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { break; case READY: // go back to AP mode after a disconnection (simulation 2/2), you could retry - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; bool res = mg_wifi_ap_start(wifi); MG_INFO(("Disconnected")); diff --git a/tutorials/stm32/nucleo-f746zg/minimal-rm2/main.c b/tutorials/stm32/nucleo-f746zg/minimal-rm2/main.c index 69f495f4..72822dd0 100644 --- a/tutorials/stm32/nucleo-f746zg/minimal-rm2/main.c +++ b/tutorials/stm32/nucleo-f746zg/minimal-rm2/main.c @@ -89,12 +89,12 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { if (ev == MG_TCPIP_EV_DRIVER) { spi_setup(CYWSPI, 3); // /16: 3.4MHz SPI3, 6.75MHz SPI1 (< 50MHz) } - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } switch(state) { case AP: // we are in AP mode, wait for a user connection to trigger a scan or a connection to a network - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("Access Point READY !")); // simulate user request to scan for networks @@ -119,7 +119,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case STOPPING_AP: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; wifi->apmode = false; @@ -132,7 +132,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { } break; case CONNECTING: - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_READY) { MG_INFO(("READY!")); state = READY; @@ -146,7 +146,7 @@ static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { break; case READY: // go back to AP mode after a disconnection (simulation 2/2), you could retry - if (ev == MG_TCPIP_EV_ST_CHG && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && *(uint8_t *) ev_data == MG_TCPIP_STATE_DOWN) { struct mg_wifi_data *wifi = &((struct mg_tcpip_driver_cyw_data *) ifp->driver_data)->wifi; bool res = mg_wifi_ap_start(wifi); MG_INFO(("Disconnected")); diff --git a/tutorials/tcpip/pcap-driver/main.c b/tutorials/tcpip/pcap-driver/main.c index fd8a79e2..cee4430e 100644 --- a/tutorials/tcpip/pcap-driver/main.c +++ b/tutorials/tcpip/pcap-driver/main.c @@ -171,7 +171,7 @@ static void mqtt_ev_handler(struct mg_connection *c, int ev, void *ev_data) { static void if_ev_handler(struct mg_tcpip_if *ifp, int ev, void *ev_data) { // Trigger MQTT connection when we have an IP address - if (ifp->state == MG_TCPIP_STATE_READY && ev == MG_TCPIP_EV_ST_CHG) { + if (ifp->state == MG_TCPIP_STATE_READY && ev == MG_TCPIP_EV_STATE_CHANGE) { struct mg_mqtt_opts opts = {.clean = true}; // mg_mqtt_connect(ifp->mgr, MQTT_URL, &opts, mqtt_ev_handler, NULL); mg_mqtt_connect(ifp->mgr, MQTTS_URL, &opts, mqtt_ev_handler, "tls enabled"); @@ -185,7 +185,7 @@ static void if_ev_handler(struct mg_tcpip_if *ifp, int ev, void *ev_data) { if (ip == 0) ip = MG_IPV4(169, 254, 2, 100); // restart process on link change - if (ev == MG_TCPIP_EV_ST_CHG && ifp->state == MG_TCPIP_STATE_DOWN) { + if (ev == MG_TCPIP_EV_STATE_CHANGE && ifp->state == MG_TCPIP_STATE_DOWN) { ifp->ip = 0; counter = 0; } diff --git a/tutorials/tcpip/tap-driver/main.c b/tutorials/tcpip/tap-driver/main.c index f297466f..957c34d1 100644 --- a/tutorials/tcpip/tap-driver/main.c +++ b/tutorials/tcpip/tap-driver/main.c @@ -45,7 +45,7 @@ static size_t tap_rx(void *buf, size_t len, struct mg_tcpip_if *ifp) { char *s_sntp = NULL; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { - if (ev == MG_TCPIP_EV_ST_CHG) { + if (ev == MG_TCPIP_EV_STATE_CHANGE) { MG_INFO(("State change: %u", *(uint8_t *) ev_data)); } else if (ev == MG_TCPIP_EV_DHCP_DNS) { MG_INFO(("Got DNS from DHCP: %M", mg_print_ip4, (uint32_t *) ev_data));