mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Refactor MIP strategy and first driver (CMSIS)
This commit is contained in:
parent
6f697db49d
commit
dceb4beb09
71
mongoose.c
71
mongoose.c
@ -398,7 +398,6 @@ void mg_resolve(struct mg_connection *c, const char *url) {
|
||||
}
|
||||
}
|
||||
|
||||
#if MG_ENABLE_MDNS
|
||||
static const uint8_t mdns_answer[] = {
|
||||
0, 1, // 2 bytes - record type, A
|
||||
0, 1, // 2 bytes - address class, INET
|
||||
@ -460,14 +459,13 @@ static void mdns_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd);
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip);
|
||||
struct mg_connection *mg_mdns_listen(struct mg_mgr *mgr, char *name) {
|
||||
struct mg_connection *c =
|
||||
mg_listen(mgr, "udp://224.0.0.251:5353", mdns_cb, name);
|
||||
if (c != NULL) mg_mcast_add("224.0.0.251", (MG_SOCKET_TYPE) (size_t) c->fd);
|
||||
if (c != NULL) mg_multicast_add(c, "224.0.0.251");
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MG_ENABLE_LINES
|
||||
#line 1 "src/event.c"
|
||||
@ -4446,13 +4444,13 @@ static void tx_dhcp_request_sel(struct mg_tcpip_if *ifp, uint32_t ip_req,
|
||||
uint8_t extra = (uint8_t) ((ifp->enable_req_dns ? 1 : 0) +
|
||||
(ifp->enable_req_sntp ? 1 : 0));
|
||||
size_t len = strlen(ifp->dhcp_name);
|
||||
size_t olen = 21 + len + extra + 2 + 1; // Total length of options
|
||||
#define OPTS_MAXLEN (21 + sizeof(ifp->dhcp_name) + 2 + 2 + 1)
|
||||
uint8_t opts[OPTS_MAXLEN]; // Allocate options (max size possible)
|
||||
size_t olen = 21 + len + extra + 2 + 1; // Total length of options
|
||||
#define OPTS_MAXLEN (21 + sizeof(ifp->dhcp_name) + 2 + 2 + 1)
|
||||
uint8_t opts[OPTS_MAXLEN]; // Allocate options (max size possible)
|
||||
uint8_t *p = opts;
|
||||
assert(olen <= sizeof(opts));
|
||||
memset(opts, 0, sizeof(opts));
|
||||
*p++ = 53, *p++ = 1, *p++ = 3; // Type: DHCP request
|
||||
*p++ = 53, *p++ = 1, *p++ = 3; // Type: DHCP request
|
||||
*p++ = 54, *p++ = 4, memcpy(p, &ip_srv, 4), p += 4; // DHCP server ID
|
||||
*p++ = 50, *p++ = 4, memcpy(p, &ip_req, 4), p += 4; // Requested IP
|
||||
*p++ = 12, *p++ = (uint8_t) (len & 255); // DHCP host
|
||||
@ -5253,6 +5251,13 @@ static void mac_resolved(struct mg_connection *c) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ip4_mcastmac(uint8_t *mac, uint32_t *ip) {
|
||||
uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group MAC
|
||||
memcpy(mac, mcastp, 3);
|
||||
memcpy(mac + 3, ((uint8_t *) ip) + 1, 3); // 23 LSb
|
||||
mac[3] &= 0x7F;
|
||||
}
|
||||
|
||||
void mg_connect_resolved(struct mg_connection *c) {
|
||||
struct mg_tcpip_if *ifp = c->mgr->ifp;
|
||||
uint32_t rem_ip;
|
||||
@ -5278,10 +5283,7 @@ void mg_connect_resolved(struct mg_connection *c) {
|
||||
c->is_arplooking = 1;
|
||||
} else if ((*((uint8_t *) &rem_ip) & 0xE0) == 0xE0) {
|
||||
struct connstate *s = (struct connstate *) (c + 1); // 224 to 239, E0 to EF
|
||||
uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group
|
||||
memcpy(s->mac, mcastp, 3);
|
||||
memcpy(s->mac + 3, ((uint8_t *) &rem_ip) + 1, 3); // 23 LSb
|
||||
s->mac[3] &= 0x7F;
|
||||
ip4_mcastmac(s->mac, &rem_ip); // multicast group
|
||||
mac_resolved(c);
|
||||
} else {
|
||||
struct connstate *s = (struct connstate *) (c + 1);
|
||||
@ -5384,11 +5386,12 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
return res;
|
||||
}
|
||||
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) { (void) ip; (void) fd; }
|
||||
|
||||
#if MG_TCPIP_MCAST
|
||||
const uint8_t mcast_addr[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb};
|
||||
#endif
|
||||
uint8_t mcast_addr[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb};
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
(void) ip; // ip4_mcastmac(mcast_mac, &ip);
|
||||
// TODO(): actual IP -> MAC; check database, update
|
||||
c->mgr->ifp->update_mac_hash_table = true; // mark dirty
|
||||
}
|
||||
|
||||
#endif // MG_ENABLE_TCPIP
|
||||
|
||||
@ -8382,8 +8385,7 @@ static void mg_set_non_blocking_mode(MG_SOCKET_TYPE fd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MG_ENABLE_MDNS
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) {
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
#if MG_ENABLE_RL
|
||||
#error UNSUPPORTED
|
||||
#elif MG_ENABLE_FREERTOS_TCP
|
||||
@ -8393,10 +8395,9 @@ void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) {
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(ip);
|
||||
mreq.imr_interface.s_addr = mg_htonl(INADDR_ANY);
|
||||
setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
setsockopt(FD(c), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
MG_SOCKET_TYPE fd = MG_INVALID_SOCKET;
|
||||
@ -19833,10 +19834,6 @@ static bool cmsis_init(struct mg_tcpip_if *ifp) {
|
||||
memcpy(&addr, ifp->mac, sizeof(addr));
|
||||
mac->SetMacAddress(&addr);
|
||||
}
|
||||
#if MG_TCPIP_MCAST
|
||||
memcpy(&addr, mcast_addr, sizeof(addr));
|
||||
mac->SetAddressFilter(&addr, 1);
|
||||
#endif
|
||||
phy->PowerControl(ARM_POWER_FULL);
|
||||
phy->SetInterface(cap.media_interface);
|
||||
phy->SetMode(ARM_ETH_PHY_AUTO_NEGOTIATE);
|
||||
@ -19853,7 +19850,20 @@ static size_t cmsis_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static void cmsis_update_hash_table(struct mg_tcpip_if *ifp) {
|
||||
// TODO(): read database, rebuild hash table
|
||||
ARM_DRIVER_ETH_MAC *mac = &Driver_ETH_MAC0;
|
||||
ARM_ETH_MAC_ADDR addr;
|
||||
memcpy(&addr, mcast_addr, sizeof(addr));
|
||||
mac->SetAddressFilter(&addr, 1);
|
||||
(void) ifp;
|
||||
}
|
||||
|
||||
static bool cmsis_poll(struct mg_tcpip_if *ifp, bool s1) {
|
||||
if (ifp->update_mac_hash_table) {
|
||||
cmsis_update_hash_table(ifp);
|
||||
ifp->update_mac_hash_table = false;
|
||||
}
|
||||
if (!s1) return false;
|
||||
ARM_DRIVER_ETH_PHY *phy = &Driver_ETH_PHY0;
|
||||
ARM_DRIVER_ETH_MAC *mac = &Driver_ETH_MAC0;
|
||||
@ -20700,10 +20710,6 @@ static bool cyw_init(uint8_t *mac) {
|
||||
MG_ERROR(("read MAC failed"));
|
||||
}
|
||||
}
|
||||
#if MG_TCPIP_MCAST
|
||||
val = 1; if (!cyw_ioctl_iovar_set2_(0, "mcast_list", (uint8_t *)&val, sizeof(val), (uint8_t *)mcast_addr, sizeof(mcast_addr))) return false;
|
||||
mg_delayms(50);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
@ -21104,6 +21110,11 @@ bool mg_wifi_ap_stop(void) {
|
||||
return cyw_wifi_ap_stop();
|
||||
}
|
||||
|
||||
void mg_tcpip_driver_multicast_add(const uint8_t mcast_addr) {
|
||||
val = 1; cyw_ioctl_iovar_set2_(0, "mcast_list", (uint8_t *)&val, sizeof(val), (uint8_t *)mcast_addr, sizeof(mcast_addr));
|
||||
//mg_delayms(50);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef MG_ENABLE_LINES
|
||||
@ -22806,7 +22817,7 @@ static bool mg_tcpip_driver_stm32f_init(struct mg_tcpip_if *ifp) {
|
||||
ETH->MACA0LR = (uint32_t) (ifp->mac[3] << 24) |
|
||||
((uint32_t) ifp->mac[2] << 16) |
|
||||
((uint32_t) ifp->mac[1] << 8) | ifp->mac[0];
|
||||
#if MG_TCPIP_MCAST
|
||||
#if 0 //MG_TCPIP_MCAST
|
||||
// enable multicast
|
||||
ETH->MACA1LR = (uint32_t) mcast_addr[3] << 24 |
|
||||
(uint32_t) mcast_addr[2] << 16 |
|
||||
|
37
mongoose.h
37
mongoose.h
@ -936,19 +936,6 @@ struct timeval {
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MDNS
|
||||
#define MG_ENABLE_MDNS 0
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_TCPIP
|
||||
#if MG_ENABLE_MDNS
|
||||
#undef MG_TCPIP_MCAST
|
||||
#define MG_TCPIP_MCAST 1
|
||||
#elif !defined(MG_TCPIP_MCAST)
|
||||
#define MG_TCPIP_MCAST 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2852,19 +2839,20 @@ typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev,
|
||||
void *ev_data);
|
||||
|
||||
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_USER // Starting ID for user events
|
||||
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_USER // Starting ID for user events
|
||||
};
|
||||
|
||||
|
||||
// Network interface
|
||||
struct mg_tcpip_if {
|
||||
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
|
||||
@ -2877,6 +2865,7 @@ struct mg_tcpip_if {
|
||||
bool enable_req_sntp; // DCHP client requests SNTP server
|
||||
bool enable_crc32_check; // Do a CRC check on RX frames and strip it
|
||||
bool enable_mac_check; // Do a MAC check on RX frames
|
||||
bool update_mac_hash_table; // Signal drivers to update MAC controller
|
||||
struct mg_tcpip_driver *driver; // Low level driver
|
||||
void *driver_data; // Driver-specific data
|
||||
mg_tcpip_event_handler_t fn; // User-specified event handler function
|
||||
|
13
src/config.h
13
src/config.h
@ -182,16 +182,3 @@
|
||||
#ifndef MG_ENABLE_TCPIP_PRINT_DEBUG_STATS
|
||||
#define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MDNS
|
||||
#define MG_ENABLE_MDNS 0
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_TCPIP
|
||||
#if MG_ENABLE_MDNS
|
||||
#undef MG_TCPIP_MCAST
|
||||
#define MG_TCPIP_MCAST 1
|
||||
#elif !defined(MG_TCPIP_MCAST)
|
||||
#define MG_TCPIP_MCAST 0
|
||||
#endif
|
||||
#endif
|
||||
|
@ -277,7 +277,6 @@ void mg_resolve(struct mg_connection *c, const char *url) {
|
||||
}
|
||||
}
|
||||
|
||||
#if MG_ENABLE_MDNS
|
||||
static const uint8_t mdns_answer[] = {
|
||||
0, 1, // 2 bytes - record type, A
|
||||
0, 1, // 2 bytes - address class, INET
|
||||
@ -339,11 +338,10 @@ static void mdns_cb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
(void) ev_data;
|
||||
}
|
||||
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd);
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip);
|
||||
struct mg_connection *mg_mdns_listen(struct mg_mgr *mgr, char *name) {
|
||||
struct mg_connection *c =
|
||||
mg_listen(mgr, "udp://224.0.0.251:5353", mdns_cb, name);
|
||||
if (c != NULL) mg_mcast_add("224.0.0.251", (MG_SOCKET_TYPE) (size_t) c->fd);
|
||||
if (c != NULL) mg_multicast_add(c, "224.0.0.251");
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
@ -40,10 +40,6 @@ static bool cmsis_init(struct mg_tcpip_if *ifp) {
|
||||
memcpy(&addr, ifp->mac, sizeof(addr));
|
||||
mac->SetMacAddress(&addr);
|
||||
}
|
||||
#if MG_TCPIP_MCAST
|
||||
memcpy(&addr, mcast_addr, sizeof(addr));
|
||||
mac->SetAddressFilter(&addr, 1);
|
||||
#endif
|
||||
phy->PowerControl(ARM_POWER_FULL);
|
||||
phy->SetInterface(cap.media_interface);
|
||||
phy->SetMode(ARM_ETH_PHY_AUTO_NEGOTIATE);
|
||||
@ -60,7 +56,20 @@ static size_t cmsis_tx(const void *buf, size_t len, struct mg_tcpip_if *ifp) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static void cmsis_update_hash_table(struct mg_tcpip_if *ifp) {
|
||||
// TODO(): read database, rebuild hash table
|
||||
ARM_DRIVER_ETH_MAC *mac = &Driver_ETH_MAC0;
|
||||
ARM_ETH_MAC_ADDR addr;
|
||||
memcpy(&addr, mcast_addr, sizeof(addr));
|
||||
mac->SetAddressFilter(&addr, 1);
|
||||
(void) ifp;
|
||||
}
|
||||
|
||||
static bool cmsis_poll(struct mg_tcpip_if *ifp, bool s1) {
|
||||
if (ifp->update_mac_hash_table) {
|
||||
cmsis_update_hash_table(ifp);
|
||||
ifp->update_mac_hash_table = false;
|
||||
}
|
||||
if (!s1) return false;
|
||||
ARM_DRIVER_ETH_PHY *phy = &Driver_ETH_PHY0;
|
||||
ARM_DRIVER_ETH_MAC *mac = &Driver_ETH_MAC0;
|
||||
|
@ -784,10 +784,6 @@ static bool cyw_init(uint8_t *mac) {
|
||||
MG_ERROR(("read MAC failed"));
|
||||
}
|
||||
}
|
||||
#if MG_TCPIP_MCAST
|
||||
val = 1; if (!cyw_ioctl_iovar_set2_(0, "mcast_list", (uint8_t *)&val, sizeof(val), (uint8_t *)mcast_addr, sizeof(mcast_addr))) return false;
|
||||
mg_delayms(50);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
@ -1188,4 +1184,9 @@ bool mg_wifi_ap_stop(void) {
|
||||
return cyw_wifi_ap_stop();
|
||||
}
|
||||
|
||||
void mg_tcpip_driver_multicast_add(const uint8_t mcast_addr) {
|
||||
val = 1; cyw_ioctl_iovar_set2_(0, "mcast_list", (uint8_t *)&val, sizeof(val), (uint8_t *)mcast_addr, sizeof(mcast_addr));
|
||||
//mg_delayms(50);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -152,7 +152,7 @@ static bool mg_tcpip_driver_stm32f_init(struct mg_tcpip_if *ifp) {
|
||||
ETH->MACA0LR = (uint32_t) (ifp->mac[3] << 24) |
|
||||
((uint32_t) ifp->mac[2] << 16) |
|
||||
((uint32_t) ifp->mac[1] << 8) | ifp->mac[0];
|
||||
#if MG_TCPIP_MCAST
|
||||
#if 0 //MG_TCPIP_MCAST
|
||||
// enable multicast
|
||||
ETH->MACA1LR = (uint32_t) mcast_addr[3] << 24 |
|
||||
(uint32_t) mcast_addr[2] << 16 |
|
||||
|
@ -283,13 +283,13 @@ static void tx_dhcp_request_sel(struct mg_tcpip_if *ifp, uint32_t ip_req,
|
||||
uint8_t extra = (uint8_t) ((ifp->enable_req_dns ? 1 : 0) +
|
||||
(ifp->enable_req_sntp ? 1 : 0));
|
||||
size_t len = strlen(ifp->dhcp_name);
|
||||
size_t olen = 21 + len + extra + 2 + 1; // Total length of options
|
||||
#define OPTS_MAXLEN (21 + sizeof(ifp->dhcp_name) + 2 + 2 + 1)
|
||||
uint8_t opts[OPTS_MAXLEN]; // Allocate options (max size possible)
|
||||
size_t olen = 21 + len + extra + 2 + 1; // Total length of options
|
||||
#define OPTS_MAXLEN (21 + sizeof(ifp->dhcp_name) + 2 + 2 + 1)
|
||||
uint8_t opts[OPTS_MAXLEN]; // Allocate options (max size possible)
|
||||
uint8_t *p = opts;
|
||||
assert(olen <= sizeof(opts));
|
||||
memset(opts, 0, sizeof(opts));
|
||||
*p++ = 53, *p++ = 1, *p++ = 3; // Type: DHCP request
|
||||
*p++ = 53, *p++ = 1, *p++ = 3; // Type: DHCP request
|
||||
*p++ = 54, *p++ = 4, memcpy(p, &ip_srv, 4), p += 4; // DHCP server ID
|
||||
*p++ = 50, *p++ = 4, memcpy(p, &ip_req, 4), p += 4; // Requested IP
|
||||
*p++ = 12, *p++ = (uint8_t) (len & 255); // DHCP host
|
||||
@ -1090,6 +1090,13 @@ static void mac_resolved(struct mg_connection *c) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ip4_mcastmac(uint8_t *mac, uint32_t *ip) {
|
||||
uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group MAC
|
||||
memcpy(mac, mcastp, 3);
|
||||
memcpy(mac + 3, ((uint8_t *) ip) + 1, 3); // 23 LSb
|
||||
mac[3] &= 0x7F;
|
||||
}
|
||||
|
||||
void mg_connect_resolved(struct mg_connection *c) {
|
||||
struct mg_tcpip_if *ifp = c->mgr->ifp;
|
||||
uint32_t rem_ip;
|
||||
@ -1115,10 +1122,7 @@ void mg_connect_resolved(struct mg_connection *c) {
|
||||
c->is_arplooking = 1;
|
||||
} else if ((*((uint8_t *) &rem_ip) & 0xE0) == 0xE0) {
|
||||
struct connstate *s = (struct connstate *) (c + 1); // 224 to 239, E0 to EF
|
||||
uint8_t mcastp[3] = {0x01, 0x00, 0x5E}; // multicast group
|
||||
memcpy(s->mac, mcastp, 3);
|
||||
memcpy(s->mac + 3, ((uint8_t *) &rem_ip) + 1, 3); // 23 LSb
|
||||
s->mac[3] &= 0x7F;
|
||||
ip4_mcastmac(s->mac, &rem_ip); // multicast group
|
||||
mac_resolved(c);
|
||||
} else {
|
||||
struct connstate *s = (struct connstate *) (c + 1);
|
||||
@ -1221,9 +1225,11 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
return res;
|
||||
}
|
||||
|
||||
#if MG_TCPIP_MCAST
|
||||
const uint8_t mcast_addr[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb};
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) { (void) ip; (void) fd; }
|
||||
#endif
|
||||
uint8_t mcast_addr[6] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb};
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
(void) ip; // ip4_mcastmac(mcast_mac, &ip);
|
||||
// TODO(): actual IP -> MAC; check database, update
|
||||
c->mgr->ifp->update_mac_hash_table = true; // mark dirty
|
||||
}
|
||||
|
||||
#endif // MG_ENABLE_TCPIP
|
||||
|
@ -20,19 +20,20 @@ typedef void (*mg_tcpip_event_handler_t)(struct mg_tcpip_if *ifp, int ev,
|
||||
void *ev_data);
|
||||
|
||||
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_USER // Starting ID for user events
|
||||
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_USER // Starting ID for user events
|
||||
};
|
||||
|
||||
|
||||
// Network interface
|
||||
struct mg_tcpip_if {
|
||||
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
|
||||
@ -45,6 +46,7 @@ struct mg_tcpip_if {
|
||||
bool enable_req_sntp; // DCHP client requests SNTP server
|
||||
bool enable_crc32_check; // Do a CRC check on RX frames and strip it
|
||||
bool enable_mac_check; // Do a MAC check on RX frames
|
||||
bool update_mac_hash_table; // Signal drivers to update MAC controller
|
||||
struct mg_tcpip_driver *driver; // Low level driver
|
||||
void *driver_data; // Driver-specific data
|
||||
mg_tcpip_event_handler_t fn; // User-specified event handler function
|
||||
|
@ -176,8 +176,7 @@ static void mg_set_non_blocking_mode(MG_SOCKET_TYPE fd) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MG_ENABLE_MDNS
|
||||
void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) {
|
||||
void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
#if MG_ENABLE_RL
|
||||
#error UNSUPPORTED
|
||||
#elif MG_ENABLE_FREERTOS_TCP
|
||||
@ -187,10 +186,9 @@ void mg_mcast_add(char *ip, MG_SOCKET_TYPE fd) {
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(ip);
|
||||
mreq.imr_interface.s_addr = mg_htonl(INADDR_ANY);
|
||||
setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
setsockopt(FD(c), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
bool mg_open_listener(struct mg_connection *c, const char *url) {
|
||||
MG_SOCKET_TYPE fd = MG_INVALID_SOCKET;
|
||||
|
@ -9,5 +9,4 @@
|
||||
#define MG_ENABLE_PACKED_FS 1
|
||||
#define MG_ENABLE_DRIVER_CMSIS 1
|
||||
#define MG_ENABLE_LINES 1
|
||||
#define MG_ENABLE_MDNS 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user