Networking: Improved status reporting and new carrier management interfaces. From Max Holtzberg
This commit is contained in:
parent
aadd63c7e7
commit
1919b2f6a3
@ -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).
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user