Merge pull request #1843 from cesanta/mip

Expose mip guts
This commit is contained in:
Sergio R. Caprile authored and GitHub committed 2022-11-09 17:40:46 -03:00
commit dfae1b3f70
15 files changed
+222 -258

No files matched your search

+7 -3
View File
@@ -22,9 +22,13 @@ void setup() {
delay(3000);
MG_INFO(("Starting TCP/IP stack..."));
// Init TCP/IP stack. Set MAC address. Set IP to 0, to enable DHCP
struct mip_cfg c = {.mac = {0, 0, 1, 2, 3, 4}, .ip = 0, .mask = 0, .gw = 0};
mip_init(&mgr, &c, &mip_driver_w5500, &spi);
struct mip_if mif = {
.mac = {0, 0, 1, 2, 3, 5},
.use_dhcp = true,
.driver = &mip_driver_w5500,
.driver_data = &spi,
};
mip_init(&mgr, &mif);
// Start a 5 sec timer, print status message periodically
mg_timer_add(
+4 -5
View File
@@ -95,12 +95,11 @@ int main(int argc, char *argv[]) {
struct mg_mgr mgr; // Event manager
mg_mgr_init(&mgr); // Initialise event manager
struct mip_cfg c = {.ip = 0, .mask = 0, .gw = 0};
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &c.mac[0], &c.mac[1], &c.mac[2],
&c.mac[3], &c.mac[4], &c.mac[5]);
struct mip_driver driver = {.tx = pcap_tx, .up = pcap_up, .rx = pcap_rx};
mip_init(&mgr, &c, &driver, ph);
struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = ph};
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1],
&mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);
mip_init(&mgr, &mif);
MG_INFO(("Init done, starting main loop"));
extern void device_dashboard_fn(struct mg_connection *, int, void *, void *);
+7 -8
View File
@@ -3,10 +3,10 @@
//
// example using MIP and a TUN/TAP interface
#include "mongoose.h"
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include "mongoose.h"
static int s_signo;
void signal_handler(int signo) {
@@ -14,7 +14,7 @@ void signal_handler(int signo) {
}
static size_t tap_tx(const void *buf, size_t len, void *userdata) {
ssize_t res = write((int) userdata, buf, len);
ssize_t res = write((int) (size_t) userdata, buf, len);
if (res < 0) {
MG_ERROR(("tap_tx failed: %d", errno));
return 0;
@@ -27,7 +27,7 @@ static bool tap_up(void *userdata) {
}
static size_t tap_rx(void *buf, size_t len, void *userdata) {
ssize_t received = read((int) userdata, buf, len);
ssize_t received = read(*(int *) userdata, buf, len);
usleep(1); // This is to avoid 100% CPU
if (received < 0) return 0;
return (size_t) received;
@@ -70,12 +70,11 @@ int main(int argc, char *argv[]) {
struct mg_mgr mgr; // Event manager
mg_mgr_init(&mgr); // Initialise event manager
struct mip_cfg c = {.ip = 0, .mask = 0, .gw = 0};
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &c.mac[0], &c.mac[1], &c.mac[2],
&c.mac[3], &c.mac[4], &c.mac[5]);
struct mip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx};
mip_init(&mgr, &c, &driver, (void *) (size_t) fd);
struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = &fd};
sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1],
&mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]);
mip_init(&mgr, &mif);
MG_INFO(("Init done, starting main loop"));
extern void device_dashboard_fn(struct mg_connection *, int, void *, void *);
@@ -70,11 +70,16 @@ int main(void) {
// Initialise Mongoose network stack
// Specify MAC address, and use 0 for IP, mask, GW - i.e. use DHCP
// For static configuration, specify IP/mask/GW in network byte order
struct mip_cfg c = {.mac = {0, 0, 1, 2, 3, 5}, .ip = 0, .mask = 0, .gw = 0};
struct mip_driver_stm32 driver_data = {.mdc_cr = 4}; // See driver_stm32.h
mip_init(&mgr, &c, &mip_driver_stm32, &driver_data);
MG_INFO(("Init done, starting main loop"));
struct mip_if mif = {
.mac = {0, 0, 1, 2, 3, 5},
.use_dhcp = true,
.driver = &mip_driver_stm32,
.driver_data = &driver_data,
};
mip_init(&mgr, &mif);
MG_INFO(("Init done, starting main loop"));
extern void device_dashboard_fn(struct mg_connection *, int, void *, void *);
mg_http_listen(&mgr, "http://0.0.0.0", device_dashboard_fn, &mgr);
for (;;) mg_mgr_poll(&mgr, 0); // Infinite event loop
@@ -70,9 +70,14 @@ int main(void) {
// Initialise Mongoose network stack
// Specify MAC address, and use 0 for IP, mask, GW - i.e. use DHCP
// For static configuration, specify IP/mask/GW in network byte order
struct mip_cfg c = {.mac = {0, 0, 1, 2, 3, 4}, .ip = 0, .mask = 0, .gw = 0};
struct mip_driver_stm32 driver_data = {.mdc_cr = 4}; // See driver_stm32.h
mip_init(&mgr, &c, &mip_driver_stm32, &driver_data);
struct mip_if mif = {
.mac = {0, 0, 1, 2, 3, 5},
.use_dhcp = true,
.driver = &mip_driver_stm32,
.driver_data = &driver_data,
};
mip_init(&mgr, &mif);
MG_INFO(("Init done, starting main loop"));
extern void device_dashboard_fn(struct mg_connection *, int, void *, void *);