Networking: Improved status reporting and new carrier management interfaces. From Max Holtzberg

This commit is contained in:
Gregory Nutt 2014-01-21 10:21:45 -06:00
parent aadd63c7e7
commit 1919b2f6a3
5 changed files with 59 additions and 46 deletions

View File

@ -804,3 +804,6 @@
immediately (2014-1-17). immediately (2014-1-17).
* apps/system/vi: Add support for a tiny, VI work-alike editor. This * apps/system/vi: Add support for a tiny, VI work-alike editor. This
is still very much a work-in-progress on initial check-in (2014-1-20). is still very much a work-in-progress on initial check-in (2014-1-20).
* apps/netutils/uiplib: Support new definitions and state passing for
network device status. From Maz Holtzberg (2014-1-21).

View File

@ -80,7 +80,8 @@
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
#define EXTERN extern "C" #define EXTERN extern "C"
extern "C" { extern "C"
{
#else #else
#define EXTERN extern #define EXTERN extern
#endif #endif
@ -101,44 +102,45 @@ extern "C" {
* Return: Non-zero If the IP address was parsed. * Return: Non-zero If the IP address was parsed.
*/ */
EXTERN bool uiplib_ipaddrconv(const char *addrstr, uint8_t *addr); bool uiplib_ipaddrconv(FAR const char *addrstr, uint8_t *addr);
EXTERN bool uiplib_hwmacconv(const char *hwstr, uint8_t *hw); bool uiplib_hwmacconv(FAR const char *hwstr, uint8_t *hw);
/* Get and set IP/MAC addresses (Ethernet L2 only) */ /* Get and set IP/MAC addresses (Ethernet L2 only) */
#ifdef CONFIG_NET_ETHERNET #ifdef CONFIG_NET_ETHERNET
EXTERN int uip_setmacaddr(const char *ifname, const uint8_t *macaddr); int uip_setmacaddr(FAR const char *ifname, const uint8_t *macaddr);
EXTERN int uip_getmacaddr(const char *ifname, uint8_t *macaddr); int uip_getmacaddr(FAR const char *ifname, uint8_t *macaddr);
#endif #endif
/* IP address support */ /* IP address support */
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
EXTERN int uip_gethostaddr(const char *ifname, struct in6_addr *addr); int uip_gethostaddr(FAR const char *ifname, struct in6_addr *addr);
EXTERN int uip_sethostaddr(const char *ifname, const struct in6_addr *addr); int uip_sethostaddr(FAR const char *ifname, const struct in6_addr *addr);
EXTERN int uip_setdraddr(const char *ifname, const struct in6_addr *addr); int uip_setdraddr(FAR const char *ifname, const struct in6_addr *addr);
EXTERN int uip_setnetmask(const char *ifname, const struct in6_addr *addr); int uip_setnetmask(FAR const char *ifname, const struct in6_addr *addr);
#else #else
EXTERN int uip_gethostaddr(const char *ifname, struct in_addr *addr); int uip_gethostaddr(FAR const char *ifname, struct in_addr *addr);
EXTERN int uip_sethostaddr(const char *ifname, const struct in_addr *addr); int uip_sethostaddr(FAR const char *ifname, const struct in_addr *addr);
EXTERN int uip_setdraddr(const char *ifname, const struct in_addr *addr); int uip_setdraddr(FAR const char *ifname, const struct in_addr *addr);
EXTERN int uip_setnetmask(const char *ifname, const struct in_addr *addr); int uip_setnetmask(FAR const char *ifname, const struct in_addr *addr);
#endif #endif
/* HTTP support */ /* HTTP support */
EXTERN int uip_parsehttpurl(const char *url, uint16_t *port, int uip_parsehttpurl(FAR const char *url, uint16_t *port,
char *hostname, int hostlen, FAR char *hostname, int hostlen,
char *filename, int namelen); FAR char *filename, int namelen);
/* Generic server logic */ /* Generic server logic */
EXTERN int uip_listenon(uint16_t portno); int uip_listenon(uint16_t portno);
EXTERN void uip_server(uint16_t portno, pthread_startroutine_t handler, int stacksize); void uip_server(uint16_t portno, pthread_startroutine_t handler,
int stacksize);
EXTERN int uip_getifstatus(const char *ifname, bool *status); int uip_getifstatus(FAR const char *ifname, FAR uint8_t *flags);
EXTERN int uip_ifup(const char *ifname); int uip_ifup(FAR const char *ifname);
EXTERN int uip_ifdown(const char *ifname); int uip_ifdown(FAR const char *ifname);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* netutils/uiplib/uip_getifflag.c * netutils/uiplib/uip_getifflag.c
* *
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -65,14 +65,14 @@
* *
* Parameters: * Parameters:
* ifname The name of the interface to use * ifname The name of the interface to use
* status interface flag ifup or ifdown status * flags The interface flags returned by SIOCGIFFLAGS
* *
* Return: * Return:
* 0 on sucess; -1 on failure * 0 on sucess; -1 on failure
* *
****************************************************************************/ ****************************************************************************/
int uip_getifstatus(const char *ifname, bool *status) int uip_getifstatus(const char *ifname, uint8_t *flags)
{ {
int ret = ERROR; int ret = ERROR;
if (ifname) if (ifname)
@ -94,24 +94,13 @@ int uip_getifstatus(const char *ifname, bool *status)
ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&req); ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&req);
if (!ret) if (!ret)
{ {
/* Return the ifup or ifdown status */ *flags = req.ifr_flags;
if ((req.ifr_flags & IF_FLAG_IFUP) == (req.ifr_flags & IF_FLAG_IFDOWN))
{
ret = ERROR;
}
else if(req.ifr_flags & IF_FLAG_IFUP)
{
*status = true;
}
else
{
*status = false;
}
} }
close(sockfd); close(sockfd);
} }
} }
return ret; return ret;
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* netutils/uiplib/uip_setifflag.c * netutils/uiplib/uip_setifflag.c
* *
* Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -88,12 +88,14 @@ int uip_ifup(const char *ifname)
strncpy(req.ifr_name, ifname, IFNAMSIZ); strncpy(req.ifr_name, ifname, IFNAMSIZ);
/* Perform the ioctl to ifup flag */ /* Perform the ioctl to ifup flag */
req.ifr_flags |= IF_FLAG_IFUP;
req.ifr_flags |= IFF_UP;
ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req);
close(sockfd); close(sockfd);
} }
} }
return ret; return ret;
} }
@ -129,12 +131,14 @@ int uip_ifdown(const char *ifname)
strncpy(req.ifr_name, ifname, IFNAMSIZ); strncpy(req.ifr_name, ifname, IFNAMSIZ);
/* Perform the ioctl to ifup flag */ /* Perform the ioctl to ifup flag */
req.ifr_flags |= IF_FLAG_IFDOWN;
req.ifr_flags |= IFF_DOWN;
ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req);
close(sockfd); close(sockfd);
} }
} }
return ret; return ret;
} }

View File

@ -54,6 +54,7 @@
#include <debug.h> #include <debug.h>
#include <net/ethernet.h> #include <net/ethernet.h>
#include <net/if.h>
#include <netinet/ether.h> #include <netinet/ether.h>
#include <nuttx/net/net.h> #include <nuttx/net/net.h>
@ -225,9 +226,9 @@ static inline void uip_statistics(FAR struct nsh_vtbl_s *vtbl)
nsh_output(vtbl, "\n"); nsh_output(vtbl, "\n");
#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_TCP
nsh_output(vtbl, " TCP ACK: %04x SYN: %04x\n", nsh_output(vtbl, " TCP ACK: %04x SYN: %04x\n",
uip_stat.tcp.ackerr, uip_stat.tcp.syndrop); uip_stat.tcp.ackerr, uip_stat.tcp.syndrop);
nsh_output(vtbl, " RST: %04x %04x\n", nsh_output(vtbl, " RST: %04x %04x\n",
uip_stat.tcp.rst, uip_stat.tcp.synrst); uip_stat.tcp.rst, uip_stat.tcp.synrst);
#endif #endif
@ -282,18 +283,32 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
{ {
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg; struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
struct in_addr addr; struct in_addr addr;
bool is_running = false; uint8_t iff;
const char *status;
int ret; int ret;
ret = uip_getifstatus(dev->d_ifname,&is_running); ret = uip_getifstatus(dev->d_ifname, &iff);
if (ret != OK) if (ret != OK)
{ {
nsh_output(vtbl, "\tGet %s interface flags error: %d\n", nsh_output(vtbl, "\tGet %s interface flags error: %d\n",
dev->d_ifname, ret); dev->d_ifname, ret);
} }
if (iff & IFF_RUNNING)
{
status = "RUNNING";
}
else if (iff & IFF_UP)
{
status = "UP";
}
else
{
status = "DOWN";
}
nsh_output(vtbl, "%s\tHWaddr %s at %s\n", nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
dev->d_ifname, ether_ntoa(&dev->d_mac), (is_running)?"UP":"DOWN"); dev->d_ifname, ether_ntoa(&dev->d_mac), status);
addr.s_addr = dev->d_ipaddr; addr.s_addr = dev->d_ipaddr;
nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr)); nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));