Skip to content

UBLOX_EVK_ODIN_W2 bridge implementation #9204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion features/lwipstack/LWIPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen)
LWIP::Interface::Interface() :
hw(NULL), has_addr_state(0),
connected(NSAPI_STATUS_DISCONNECTED),
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false)
dhcp_started(false), dhcp_has_to_be_set(false), blocking(true), ppp(false), _broadcast_to_self(false)
{
memset(&netif, 0, sizeof netif);

Expand Down Expand Up @@ -648,3 +648,12 @@ nsapi_error_t LWIP::Interface::bringdown()
}
return 0;
}
void LWIP::Interface::set_broadcast_to_self(bool enabled)
{
_broadcast_to_self = enabled;
}

bool LWIP::Interface::get_broadcast_to_self(void)
{
return _broadcast_to_self;
}
19 changes: 19 additions & 0 deletions features/lwipstack/LWIPInterfaceEMAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

#include "LWIPStack.h"

#if MBED_EMAC_LWIP_L2_BRIDGE
#include "lwip_l2_bridge.h"
#endif

#if LWIP_ETHERNET

err_t LWIP::Interface::emac_low_level_output(struct netif *netif, struct pbuf *p)
Expand All @@ -32,13 +36,21 @@ err_t LWIP::Interface::emac_low_level_output(struct netif *netif, struct pbuf *p
it after output */
pbuf_ref(p);

#if MBED_EMAC_LWIP_L2_BRIDGE
return emac_lwip_l2b_output(netif, (emac_mem_buf_t *) p);
#else

LWIP::Interface *mbed_if = static_cast<LWIP::Interface *>(netif->state);
bool ret = mbed_if->emac->link_out(p);
return ret ? ERR_OK : ERR_IF;
#endif
}

void LWIP::Interface::emac_input(emac_mem_buf_t *buf)
{
#if MBED_EMAC_LWIP_L2_BRIDGE
emac_lwip_l2b_input(&netif, buf);
#else
struct pbuf *p = static_cast<struct pbuf *>(buf);

/* pass all packets to ethernet_input, which decides what packets it supports */
Expand All @@ -47,6 +59,7 @@ void LWIP::Interface::emac_input(emac_mem_buf_t *buf)

pbuf_free(p);
}
#endif
}

void LWIP::Interface::emac_state_change(bool up)
Expand Down Expand Up @@ -178,6 +191,12 @@ err_t LWIP::Interface::emac_if_init(struct netif *netif)

netif->linkoutput = &LWIP::Interface::emac_low_level_output;

#if MBED_EMAC_LWIP_L2_BRIDGE
if (err == ERR_OK) {
emac_lwip_l2b_register_interface(netif);
}
#endif

return err;
}

Expand Down
5 changes: 5 additions & 0 deletions features/lwipstack/LWIPMemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ void LWIPMemoryManager::set_total_len(struct pbuf *pbuf)
pbuf = pbuf->next;
}
}

void LWIPMemoryManager::ref(emac_mem_buf_t *buf)
{
pbuf_ref(static_cast<struct pbuf *>(buf));
}
7 changes: 7 additions & 0 deletions features/lwipstack/LWIPMemoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ class LWIPMemoryManager : public EMACMemoryManager {
*/
virtual void set_len(emac_mem_buf_t *buf, uint32_t len);

/**
* Increases the reference count on the provided buffer
*
* @param buf Memory buffer
*/
virtual void ref(emac_mem_buf_t *buf);

private:

/**
Expand Down
8 changes: 8 additions & 0 deletions features/lwipstack/LWIPStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,23 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
*/
virtual char *get_gateway(char *buf, nsapi_size_t buflen);

virtual void set_broadcast_to_self(bool enabled);
virtual bool get_broadcast_to_self(void);

private:
friend LWIP;
friend err_t output_from_netif_to_netifs(struct netif *net, emac_mem_buf_t *buf);
friend err_t output_from_local_to_netifs(emac_mem_buf_t *buf);
friend err_t emac_lwip_l2b_output(struct netif *netif, emac_mem_buf_t *buf);
friend err_t emac_lwip_l2b_input(struct netif *net, emac_mem_buf_t *buf);

Interface();

nsapi_error_t set_dhcp();
static void netif_link_irq(struct netif *netif);
static void netif_status_irq(struct netif *netif);
static Interface *our_if_from_netif(struct netif *netif);
bool _broadcast_to_self;

#if LWIP_ETHERNET
static err_t emac_low_level_output(struct netif *netif, struct pbuf *p);
Expand Down
1 change: 1 addition & 0 deletions features/lwipstack/lwip-sys/arch/lwip_sys_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ void sys_init(void) {
lwip_sys_mutex_attr.name = "lwip_sys_mutex";
lwip_sys_mutex_attr.cb_mem = &lwip_sys_mutex_data;
lwip_sys_mutex_attr.cb_size = sizeof(lwip_sys_mutex_data);
lwip_sys_mutex_attr.attr_bits = osMutexRecursive;
lwip_sys_mutex = osMutexNew(&lwip_sys_mutex_attr);
if (lwip_sys_mutex == NULL)
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_NETWORK_STACK, MBED_ERROR_CODE_INITIALIZATION_FAILED), "sys_init error, mutex initialization failed\n");
Expand Down
Loading