diff --git a/src/common/pf_lldp.c b/src/common/pf_lldp.c index a66892050..cbffcbb87 100644 --- a/src/common/pf_lldp.c +++ b/src/common/pf_lldp.c @@ -1062,6 +1062,8 @@ static void pf_lldp_send (pnet_t * net, int loc_port_num) p_buffer->len = pf_lldp_construct_frame (net, loc_port_num, p_buffer->payload); + pnal_set_port_num(p_buffer, loc_port_num); + (void)pf_eth_send (net, p_port_data->netif.handle, p_buffer); } @@ -1926,6 +1928,8 @@ int pf_lldp_recv ( int loc_port_num = pf_port_get_port_number (net, eth_handle); int err = 0; + pnal_get_port_num(p_frame_buf, &loc_port_num); + err = pf_lldp_parse_packet (buf, buf_len, &peer_data); if (!err) diff --git a/src/device/pf_cmina.c b/src/device/pf_cmina.c index 62092cd06..106d7c04a 100644 --- a/src/device/pf_cmina.c +++ b/src/device/pf_cmina.c @@ -1389,7 +1389,7 @@ void pf_cmina_port_statistics_show (pnet_t * net) } else { - printf ("Did not find port %s\n", p_port_data->netif.name); + printf ("Did not find statistics for port %s\n", p_port_data->netif.name); } port = pf_port_get_next (&port_iterator); diff --git a/src/pnal.h b/src/pnal.h index ab776d6ab..657de7371 100644 --- a/src/pnal.h +++ b/src/pnal.h @@ -263,6 +263,10 @@ pnal_buf_t * pnal_buf_alloc (uint16_t length); void pnal_buf_free (pnal_buf_t * p); uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment); +/* Functions to use when tail-tagging is enabled */ +void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num); +void pnal_set_port_num (pnal_buf_t * p, int loc_port_num); + /** * Network interface handle, forward declaration. */ diff --git a/src/ports/STM32Cube/pnal_eth.c b/src/ports/STM32Cube/pnal_eth.c index 1c301b2cb..e8c1a9f60 100644 --- a/src/ports/STM32Cube/pnal_eth.c +++ b/src/ports/STM32Cube/pnal_eth.c @@ -177,3 +177,13 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf) } return ret; } + +void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num) +{ + /* Not yet applicable for STM32Cube */ +} + +void pnal_set_port_num (pnal_buf_t * p, int loc_port_num) +{ + /* Not yet applicable for STM32Cube */ +} diff --git a/src/ports/linux/pnal_eth.c b/src/ports/linux/pnal_eth.c index 9f0795c8e..57fbec228 100644 --- a/src/ports/linux/pnal_eth.c +++ b/src/ports/linux/pnal_eth.c @@ -164,3 +164,13 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf) int ret = send (handle->socket, buf->payload, buf->len, 0); return ret; } + +void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num) +{ + /* Not applicable for Linux */ +} + +void pnal_set_port_num (pnal_buf_t * p, int loc_port_num) +{ + /* Not applicable for Linux */ +} diff --git a/src/ports/rt-kernel/pnal.c b/src/ports/rt-kernel/pnal.c index 2cb5abbb0..86e03c0f5 100644 --- a/src/ports/rt-kernel/pnal.c +++ b/src/ports/rt-kernel/pnal.c @@ -53,7 +53,11 @@ int pnal_set_ip_suite ( int pnal_get_macaddress (const char * interface_name, pnal_ethaddr_t * mac_addr) { - memcpy (mac_addr, netif_default->hwaddr, sizeof (pnal_ethaddr_t)); + phy_t * phy = phy_get_default_driver (); + uint8_t port = atoi (&interface_name[2]) - 1; + phy_mac_address_t phy_mac_addr = phy_get_port_mac_address (phy, port); + memcpy (mac_addr, phy_mac_addr.address, sizeof (pnal_ethaddr_t)); + return 0; } @@ -107,6 +111,12 @@ int pnal_get_port_statistics ( const char * interface_name, pnal_port_stats_t * port_stats) { + if (memcmp(interface_name, "en1", 3) != 0) + { + /* TODO: statistics for the external ports are not yet supported */ + return -1; + } + port_stats->if_in_octets = netif_default->mib2_counters.ifinoctets; port_stats->if_in_errors = netif_default->mib2_counters.ifinerrors; port_stats->if_in_discards = netif_default->mib2_counters.ifindiscards; @@ -202,11 +212,15 @@ int pnal_eth_get_status (const char * interface_name, pnal_eth_status_t * status ioctl_eth_status_t link; int error; - netif = netif_find (interface_name); + netif = netif_find ("en1"); /* There is only one initialized interface */ ASSERT (netif != NULL); drv = netif->state; ASSERT (drv != NULL); + + uint8_t port = atoi (&interface_name[2]) - 1; + link.state = port; + error = drv->ops->ioctl (drv, netif, IOCTL_ETH_GET_STATUS, &link); if (error) { diff --git a/src/ports/rt-kernel/pnal_eth.c b/src/ports/rt-kernel/pnal_eth.c index 675f58004..d0b97a6c1 100644 --- a/src/ports/rt-kernel/pnal_eth.c +++ b/src/ports/rt-kernel/pnal_eth.c @@ -25,8 +25,9 @@ #include #include #include +#include -#define MAX_NUMBER_OF_IF 1 +#define MAX_NUMBER_OF_IF 3 struct pnal_eth_handle { @@ -125,18 +126,12 @@ pnal_eth_handle_t * pnal_eth_init ( pnal_eth_callback_t * callback, void * arg) { + static struct netif * first_netif = NULL; pnal_eth_handle_t * handle; struct netif * netif; (void)receive_type; /* Ignore, for now all frames will be received. */ - netif = netif_find (if_name); - if (netif == NULL) - { - os_log (LOG_LEVEL_ERROR, "Network interface \"%s\" not found!\n", if_name); - return NULL; - } - handle = pnal_eth_allocate_handle(); if (handle == NULL) { @@ -144,12 +139,28 @@ pnal_eth_handle_t * pnal_eth_init ( return NULL; } + if (first_netif == NULL) + { + first_netif = netif_find (if_name); + if (first_netif == NULL) + { + os_log (LOG_LEVEL_ERROR, "Network interface \"%s\" not found!\n", if_name); + return NULL; + } + netif = first_netif; + + lwip_set_hook_for_unknown_eth_protocol (netif, pnal_eth_sys_recv); + } + else + { + netif = malloc (sizeof (struct netif)); + memcpy (netif, first_netif, sizeof (struct netif)); + } + handle->arg = arg; handle->eth_rx_callback = callback; handle->netif = netif; - lwip_set_hook_for_unknown_eth_protocol (netif, pnal_eth_sys_recv); - return handle; } @@ -170,3 +181,17 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf) } return ret; } + +void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num) +{ +#ifdef CFG_TAIL_TAGGING + *loc_port_num = p->port_num; +#endif +} + +void pnal_set_port_num (pnal_buf_t * p, int loc_port_num) +{ +#ifdef CFG_TAIL_TAGGING + p->port_num = loc_port_num; +#endif +} diff --git a/src/ports/rt-kernel/sampleapp_main.c b/src/ports/rt-kernel/sampleapp_main.c index fe5e42088..5bf1f38b9 100644 --- a/src/ports/rt-kernel/sampleapp_main.c +++ b/src/ports/rt-kernel/sampleapp_main.c @@ -28,7 +28,10 @@ #include -#define APP_DEFAULT_ETHERNET_INTERFACE "en1" +/* Make it look like there are three interfaces, + * even if only one interface is initialized. + */ +#define APP_DEFAULT_ETHERNET_INTERFACE "en1,en2,en3" #define APP_DEFAULT_FILE_DIRECTORY "/disk1" #define APP_LOG_LEVEL APP_LOG_LEVEL_INFO @@ -140,7 +143,7 @@ int main (void) APP_LOG_INFO ("\n** Starting P-Net sample application " PNET_VERSION " **\n"); - APP_LOG_INFO ("\nType help to a list ofsupported shell commands.\n" + APP_LOG_INFO ("\nType help to get a list of supported shell commands.\n" "Type help to get a command description.\n" "For example: help pnio_show\n\n"); APP_LOG_INFO (