Skip to content

Networking update: general refactoring, unifying EMAC, multi-if #4079

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
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d4d9deb
EMAC: Draft of the multi EMAC interaface
bulislaw Jan 5, 2017
ceddc5d
WIP: EMAC API changes; K64F EMAC port
bulislaw Jan 13, 2017
3042151
tests: Enable networking tests for EMAC eth
bulislaw Jan 20, 2017
790afb9
K64F: Use pbuf usage
bulislaw Jan 30, 2017
6a63021
Fix merge issue
bulislaw Jan 31, 2017
f319e41
Network: Refactor IP stack abstraction
bulislaw Jan 31, 2017
8dd959e
Add get_mac function to ipstack_lwip
bulislaw Jan 31, 2017
9545164
K64F: Remove LWIP dependency from K64F eth
bulislaw Jan 31, 2017
ee25f06
K64F: Make sure enet struct is accesible
bulislaw Jan 31, 2017
5e9c39a
Networking: Make sure MAC provisioning happens in the right place
bulislaw Jan 31, 2017
9582409
IPStack: Remove unnecessary function parameter
bulislaw Feb 1, 2017
2d20422
Merge branch 'master' into feature_multi_emac
bulislaw Mar 6, 2017
7be0ec3
Merge branch 'master' into feature_multi_emac
bulislaw Mar 14, 2017
7dcad05
Merge remote-tracking branch 'upstream/master' into feature_multi_emac
bulislaw Mar 20, 2017
d0ddd99
Merge remote-tracking branch 'upstream/master' into feature_multi_emac
bulislaw Mar 28, 2017
a9e7f0e
Add DEVICE_ETH, DEVICE_WIFI; remove DEVICE_EMAC flags
bulislaw Mar 29, 2017
b828904
Refactor networking file names and remove unused EthInterface class
bulislaw Mar 29, 2017
88bc5e0
Refactor mbed OS LWIP integration layer
bulislaw Mar 30, 2017
2a68188
Revert accidental change to unsupported directory
bulislaw Mar 30, 2017
8c28917
Merge remote-tracking branch 'upstream/master' into feature_multi_emac
bulislaw Apr 6, 2017
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
4 changes: 2 additions & 2 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_echo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include <algorithm>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Pressure tests are not supported by default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Parallel pressure tests are not supported by default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
4 changes: 2 additions & 2 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/udp_echo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif

#include "mbed.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Pressure tests are not supported by default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if !FEATURE_LWIP
#error [NOT_SUPPORTED] LWIP not supported for this target
#endif
#if DEVICE_EMAC
#error [NOT_SUPPORTED] Not supported for WiFi targets
#if !DEVICE_ETH
#error [NOT_SUPPORTED] Ethernet not supported for this target
#endif
#ifndef MBED_EXTENDED_TESTS
#error [NOT_SUPPORTED] Parallel pressure tests are not supported by default
Expand Down
124 changes: 107 additions & 17 deletions features/FEATURE_LWIP/lwip-interface/emac_lwip.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

#if DEVICE_EMAC

#include "emac_api.h"
#include "emac_stack_mem.h"
#include "lwip/tcpip.h"
Expand All @@ -26,12 +24,11 @@
static err_t emac_lwip_low_level_output(struct netif *netif, struct pbuf *p)
{
emac_interface_t *mac = (emac_interface_t *)netif->state;
bool ret = mac->ops.link_out(mac, (emac_stack_mem_t *)p);

bool ret = mac->ops->link_out(mac, (emac_stack_mem_chain_t *)p);
return ret ? ERR_OK : ERR_IF;
}

static void emac_lwip_input(void *data, emac_stack_t *buf)
static void emac_lwip_input(void *data, emac_stack_mem_t *buf)
{
struct pbuf *p = (struct pbuf *)buf;
struct netif *netif = (struct netif *)data;
Expand All @@ -55,35 +52,128 @@ static void emac_lwip_state_change(void *data, bool up)
}
}

#if LWIP_IGMP

#include "lwip/igmp.h"
/**
* IPv4 address filtering setup.
*
* \param[in] netif the lwip network interface structure
* \param[in] group IPv4 group to modify
* \param[in] action
* \return ERR_OK or error code
*/
static err_t igmp_mac_filter(struct netif *netif, const ip4_addr_t *group, u8_t action)
{
emac_interface_t *emac = netif->state;
if (emac->ops->add_multicast_group == NULL) {
return ERR_OK; /* This function is not mandatory */
}

switch (action) {
case NETIF_ADD_MAC_FILTER:
{
uint32_t group23 = ntohl(group->addr) & 0x007FFFFF;
uint8_t addr[6];
addr[0] = LL_IP4_MULTICAST_ADDR_0;
addr[1] = LL_IP4_MULTICAST_ADDR_1;
addr[2] = LL_IP4_MULTICAST_ADDR_2;
addr[3] = group23 >> 16;
addr[4] = group23 >> 8;
addr[5] = group23;
emac->ops->add_multicast_group(emac, addr);
return ERR_OK;
}
case NETIF_DEL_MAC_FILTER:
/* As we don't reference count, silently ignore delete requests */
return ERR_OK;
default:
return ERR_ARG;
}
}
#endif

#if LWIP_IPV6_MLD

#include "lwip/mld6.h"
/**
* IPv6 address filtering setup.
*
* \param[in] netif the lwip network interface structure
* \param[in] group IPv6 group to modify
* \param[in] action
* \return ERR_OK or error code
*/
static err_t mld_mac_filter(struct netif *netif, const ip6_addr_t *group, u8_t action)
{
emac_interface_t *emac = netif->state;
if (emac->ops->add_multicast_group == NULL) {
return ERR_OK; /* This function is not mandatory */
}

switch (action) {
case NETIF_ADD_MAC_FILTER:
{
uint32_t group32 = ntohl(group->addr[3]);
uint8_t addr[6];
addr[0] = LL_IP6_MULTICAST_ADDR_0;
addr[1] = LL_IP6_MULTICAST_ADDR_1;
addr[2] = group32 >> 24;
addr[3] = group32 >> 16;
addr[4] = group32 >> 8;
addr[5] = group32;
emac->ops->add_multicast_group(emac, addr);
return ERR_OK;
}
case NETIF_DEL_MAC_FILTER:
/* As we don't reference count, silently ignore delete requests */
return ERR_OK;
default:
return ERR_ARG;
}
}
#endif

err_t emac_lwip_if_init(struct netif *netif)
{
int err = ERR_OK;
emac_interface_t *mac = (emac_interface_t *)netif->state;
emac_interface_t *emac = netif->state;

mac->ops.set_link_input_cb(mac, emac_lwip_input, netif);
mac->ops.set_link_state_cb(mac, emac_lwip_state_change, netif);
emac->ops->set_link_input_cb(emac, emac_lwip_input, netif);
emac->ops->set_link_state_cb(emac, emac_lwip_state_change, netif);

netif->hwaddr_len = mac->ops.get_hwaddr_size(mac);
mac->ops.get_hwaddr(mac, netif->hwaddr);

netif->mtu = mac->ops.get_mtu_size(mac);
netif->hwaddr_len = emac->ops->get_hwaddr_size(emac);
emac->ops->get_hwaddr(emac, netif->hwaddr);
netif->mtu = emac->ops->get_mtu_size(emac);

/* Interface capabilities */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET;

mac->ops.get_ifname(mac, netif->name, 2);
emac->ops->get_ifname(emac, netif->name, 2);

#if LWIP_IPV4
netif->output = etharp_output;
#if LWIP_IGMP
netif->igmp_mac_filter = igmp_mac_filter;
netif->flags |= NETIF_FLAG_IGMP;
#endif /* LWIP_IGMP */
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#if LWIP_IPV6_MLD
netif->mld_mac_filter = mld_mac_filter;
netif->flags |= NETIF_FLAG_MLD6;
#else
// Would need to enable all multicasts here - no API in fsl_enet to do that
#error "IPv6 multicasts won't be received if LWIP_IPV6_MLD is disabled, breaking the system"
#endif
#endif

netif->linkoutput = emac_lwip_low_level_output;

if (!mac->ops.power_up(mac)) {
if (!emac->ops->power_up(emac)) {
err = ERR_IF;
}

return err;
}

#endif /* DEVICE_EMAC */
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* EthernetInterface.h */
/* emac_lwip.h */
/* Copyright (C) 2012 mbed.org, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Expand All @@ -17,29 +17,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

// Architecture specific Ethernet interface
// Must be implemented by each target

#ifndef ETHARCH_H_
#define ETHARCH_H_
#ifndef EMAC_LWIP_H_
#define EMAC_LWIP_H_

#include "lwip/netif.h"

#ifdef __cplusplus
extern "C" {
#endif

#if DEVICE_EMAC
err_t emac_lwip_if_init(struct netif *netif);

#else /* DEVICE_EMAC */
void eth_arch_enable_interrupts(void);
void eth_arch_disable_interrupts(void);
err_t eth_arch_enetif_init(struct netif *netif);
#endif

#ifdef __cplusplus
}
#endif

#endif // #ifndef ETHARCHINTERFACE_H_
#endif // #ifndef EMAC_LWIP_H_
Loading