diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-01-21 10:21:45 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-01-21 10:21:45 -0600 |
commit | 8388961f5ffae7cb5f2904b606d797d76c678257 (patch) | |
tree | ff83896512fd4ef3ede6247e139f79c3052e8b51 /apps | |
parent | 9fc3ffdbbe02c3f9bf128527aee96a52b5657fcb (diff) | |
download | px4-nuttx-8388961f5ffae7cb5f2904b606d797d76c678257.tar.gz px4-nuttx-8388961f5ffae7cb5f2904b606d797d76c678257.tar.bz2 px4-nuttx-8388961f5ffae7cb5f2904b606d797d76c678257.zip |
Networking: Improved status reporting and new carrier management interfaces. From Max Holtzberg
Diffstat (limited to 'apps')
-rw-r--r-- | apps/ChangeLog.txt | 3 | ||||
-rw-r--r-- | apps/include/netutils/uiplib.h | 44 | ||||
-rw-r--r-- | apps/netutils/uiplib/uip_getifflag.c | 23 | ||||
-rw-r--r-- | apps/netutils/uiplib/uip_setifflag.c | 10 | ||||
-rw-r--r-- | apps/nshlib/nsh_netcmds.c | 25 |
5 files changed, 59 insertions, 46 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt index 0e2fe2d66..7583a09b9 100644 --- a/apps/ChangeLog.txt +++ b/apps/ChangeLog.txt @@ -804,3 +804,6 @@ immediately (2014-1-17). * 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). + * apps/netutils/uiplib: Support new definitions and state passing for + network device status. From Maz Holtzberg (2014-1-21). + diff --git a/apps/include/netutils/uiplib.h b/apps/include/netutils/uiplib.h index 8e66fb970..9d13ed3ff 100644 --- a/apps/include/netutils/uiplib.h +++ b/apps/include/netutils/uiplib.h @@ -80,7 +80,8 @@ #undef EXTERN #if defined(__cplusplus) #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif @@ -101,44 +102,45 @@ extern "C" { * Return: Non-zero If the IP address was parsed. */ -EXTERN bool uiplib_ipaddrconv(const char *addrstr, uint8_t *addr); -EXTERN bool uiplib_hwmacconv(const char *hwstr, uint8_t *hw); +bool uiplib_ipaddrconv(FAR const char *addrstr, uint8_t *addr); +bool uiplib_hwmacconv(FAR const char *hwstr, uint8_t *hw); /* Get and set IP/MAC addresses (Ethernet L2 only) */ #ifdef CONFIG_NET_ETHERNET -EXTERN int uip_setmacaddr(const char *ifname, const uint8_t *macaddr); -EXTERN int uip_getmacaddr(const char *ifname, uint8_t *macaddr); +int uip_setmacaddr(FAR const char *ifname, const uint8_t *macaddr); +int uip_getmacaddr(FAR const char *ifname, uint8_t *macaddr); #endif /* IP address support */ #ifdef CONFIG_NET_IPv6 -EXTERN int uip_gethostaddr(const char *ifname, struct in6_addr *addr); -EXTERN int uip_sethostaddr(const char *ifname, const struct in6_addr *addr); -EXTERN int uip_setdraddr(const char *ifname, const struct in6_addr *addr); -EXTERN int uip_setnetmask(const char *ifname, const struct in6_addr *addr); +int uip_gethostaddr(FAR const char *ifname, struct in6_addr *addr); +int uip_sethostaddr(FAR const char *ifname, const struct in6_addr *addr); +int uip_setdraddr(FAR const char *ifname, const struct in6_addr *addr); +int uip_setnetmask(FAR const char *ifname, const struct in6_addr *addr); #else -EXTERN int uip_gethostaddr(const char *ifname, struct in_addr *addr); -EXTERN int uip_sethostaddr(const char *ifname, const struct in_addr *addr); -EXTERN int uip_setdraddr(const char *ifname, const struct in_addr *addr); -EXTERN int uip_setnetmask(const char *ifname, const struct in_addr *addr); +int uip_gethostaddr(FAR const char *ifname, struct in_addr *addr); +int uip_sethostaddr(FAR const char *ifname, const struct in_addr *addr); +int uip_setdraddr(FAR const char *ifname, const struct in_addr *addr); +int uip_setnetmask(FAR const char *ifname, const struct in_addr *addr); #endif /* HTTP support */ -EXTERN int uip_parsehttpurl(const char *url, uint16_t *port, - char *hostname, int hostlen, - char *filename, int namelen); +int uip_parsehttpurl(FAR const char *url, uint16_t *port, + FAR char *hostname, int hostlen, + FAR char *filename, int namelen); /* Generic server logic */ -EXTERN int uip_listenon(uint16_t portno); -EXTERN void uip_server(uint16_t portno, pthread_startroutine_t handler, int stacksize); +int uip_listenon(uint16_t portno); +void uip_server(uint16_t portno, pthread_startroutine_t handler, + int stacksize); -EXTERN int uip_getifstatus(const char *ifname, bool *status); -EXTERN int uip_ifup(const char *ifname); -EXTERN int uip_ifdown(const char *ifname); +int uip_getifstatus(FAR const char *ifname, FAR uint8_t *flags); +int uip_ifup(FAR const char *ifname); +int uip_ifdown(FAR const char *ifname); #undef EXTERN #ifdef __cplusplus diff --git a/apps/netutils/uiplib/uip_getifflag.c b/apps/netutils/uiplib/uip_getifflag.c index 8574d331a..0f292e4a1 100644 --- a/apps/netutils/uiplib/uip_getifflag.c +++ b/apps/netutils/uiplib/uip_getifflag.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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> * * Redistribution and use in source and binary forms, with or without @@ -65,14 +65,14 @@ * * Parameters: * ifname The name of the interface to use - * status interface flag ifup or ifdown status + * flags The interface flags returned by SIOCGIFFLAGS * * Return: * 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; if (ifname) @@ -94,24 +94,13 @@ int uip_getifstatus(const char *ifname, bool *status) ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&req); if (!ret) { - /* Return the ifup or ifdown status */ - - 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; - } + *flags = req.ifr_flags; } + close(sockfd); } } + return ret; } diff --git a/apps/netutils/uiplib/uip_setifflag.c b/apps/netutils/uiplib/uip_setifflag.c index 317ddcce1..f18ad00e4 100644 --- a/apps/netutils/uiplib/uip_setifflag.c +++ b/apps/netutils/uiplib/uip_setifflag.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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> * * 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); /* Perform the ioctl to ifup flag */ - req.ifr_flags |= IF_FLAG_IFUP; + + req.ifr_flags |= IFF_UP; ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); close(sockfd); } } + return ret; } @@ -129,12 +131,14 @@ int uip_ifdown(const char *ifname) strncpy(req.ifr_name, ifname, IFNAMSIZ); /* Perform the ioctl to ifup flag */ - req.ifr_flags |= IF_FLAG_IFDOWN; + + req.ifr_flags |= IFF_DOWN; ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&req); close(sockfd); } } + return ret; } diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c index 5c76aca0e..024fb248e 100644 --- a/apps/nshlib/nsh_netcmds.c +++ b/apps/nshlib/nsh_netcmds.c @@ -54,6 +54,7 @@ #include <debug.h> #include <net/ethernet.h> +#include <net/if.h> #include <netinet/ether.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"); #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); - nsh_output(vtbl, " RST: %04x %04x\n", + nsh_output(vtbl, " RST: %04x %04x\n", uip_stat.tcp.rst, uip_stat.tcp.synrst); #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 in_addr addr; - bool is_running = false; + uint8_t iff; + const char *status; int ret; - ret = uip_getifstatus(dev->d_ifname,&is_running); + ret = uip_getifstatus(dev->d_ifname, &iff); if (ret != OK) { nsh_output(vtbl, "\tGet %s interface flags error: %d\n", 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", - 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; nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr)); |