nrmenus.c

来自「在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LE」· C语言 代码 · 共 1,653 行 · 第 1/3 页

C
1,653
字号
/*
 * FILENAME: nrmenus.c
 *
 * Copyright 1997- 2000 By InterNiche Technologies Inc. All rights reserved
 *
 * Software Menus for InterNiche sample/demo TTY console.
 *
 * MODULE: MISCLIB
 *
 * ROUTINES: pktdump(), do_dtrap(), ishexdigit(), hexnibble(), 
 * ROUTINES: atoh(), atohl(), hex2bin(), agent(), setcommstr(), dumpqueues(), 
 * ROUTINES: dumpbufs(), qname(), showver(), sendtrap(), dump_bytes(), 
 * ROUTINES: menu_exit(), udpecho(), tcpecho(), show_routes(), 
 * ROUTINES: mn_add_route(), set_ipaddr(), gethostbyname()
 * ROUTINES: ping_sethost(), ping_setdelay(), ping_setlength(),
 *
 * PORTABLE: yes
 */

/* Additional Copyrights: */
/* Portions Copyright 1990-1996 by NetPort */


#include "ipport.h"

#ifdef IN_MENUS

#include "in_utils.h"

#include "q.h"          /* need these 3 to pull in ifNumber */
#include "netbuf.h"
#include "net.h"
#include "ether.h"
#include "arp.h"
#include "ip.h"
#include "icmp.h"
#include "udp.h"
#include "menu.h"
#include "app_ping.h"
#include "pmtu.h"

#include "dns.h"

#include "nvparms.h"
#include "minip.h"      /* (yaxon add) */

#define  t_time   unsigned long


extern   int   station_state(void * pio);
extern   int   mh_stats(void * pio);
extern   int   set_upc(void * pio);
extern   int   iface_stats(void * pio);
extern   int   linkstats(void * pio);
extern   int   dumpbufs(void * pio);
extern   int   dumpqueues(void * pio);
extern   int   showver (void * pio);
extern   int   dns_state (void * pio);
extern   int   set_nv_params (void * pio);
extern   int   edit_nv_params(void * pio);

#ifdef INCLUDE_TCP
#ifndef MINI_TCP
extern   int   mbuf_stat(void * pio);
extern   int   mbuf_list(void * pio);
#endif   /* MINI_TCP */
extern   int   tcp_stat(void * pio);
extern   int   sock_list(void * pio);
extern   int   tcp_bsdconnstat(void * pio);
extern   int   tcp_bsdsendstat(void * pio);
extern   int   tcp_bsdrcvstat(void * pio);
#endif   /* INCLUDE_TCP */

#ifdef IP_ROUTING
int   show_routes    (void * pio);
int   mn_add_route   (void * pio);
#endif   /* IP_ROUTING */

extern   int   vfs_dir(void * pio);
extern   int   tk_stats(void * pio);

#ifdef UDPSTEST
extern   int   udpecho(void * pio);
extern   int   udp_secho_init(void * pio);
extern   int   udp_cecho_close(void * pio);
extern   int   udp_secho_close(void * pio);
extern   int   udp_echo_stats(void * pio);
extern   int   udp_sendecho(void * pio, ip_addr fhost, int len, long times);
#endif

#ifdef TCP_ECHOTEST
extern   int   tcpecho(void * pio);
extern   int   tcp_secho_init (void * pio);
extern   int   tcp_secho_close(void * pio);
extern   int   tcp_cecho_close(void * pio);
extern   int   tcp_echo_stats (void * pio);
extern   int   tcp_sendecho(void * pio, ip_addr fhost, long len, long times);
#endif

#ifdef DNS_CLIENT
extern   int   gethostbynametest (void * pio);
extern   int   setdnssvr(void * pio);
#endif

#ifdef DNS_CLIENT_UPDT
extern   int   nsupdatetest (void * pio);
extern   int   dns_update(char * soa, char * dname, ip_addr ipaddr, u_long ttl,
                           void * pio);
#endif /* DNS_CLIENT_UPDT */

#ifdef DHCP_CLIENT
int   dhc_stats      (void * pio);
#endif

#ifdef  LOSSY_IO
int   setlossy(void * pio);
#endif

#ifdef   MINI_PING
int   mini_ping(void * pio);
#endif   /* MINI_PING */

int   menu_exit (void * pio);
int   pktdump (void * pio);
int   do_dtrap (void * pio);
int   defaulttype(void * pio);
int   dump_bytes(void * pio);
int   set_ipaddr(void * pio);

char * qname(PACKET pkt);  /* get name of queue packet is in */

extern   ip_addr  activehost;    /* default ping host */
extern   u_long   pingdelay;     /* 1 second between pings */
extern   int      deflength;     /* default ping packet length */

extern   int   settrapsize(void * pio);

#ifdef USE_PROFILER
extern   struct menu_op profmenu[5];
#endif

#ifdef NATRT
extern   void  nat_re_init(void);   /* refresh NAT router's parameters */
#endif

#ifdef ROUTE_TEST
extern   struct menu_op rt_menu[10];
#endif   /* ROUTE_TEST */

#ifdef CHANGE_PWD
int   change_pwd(void * pio);
#endif

/* (yaxon add) */
int   set_tel(void * pio);
int   reset_gsm(void * pio);

 /* array of menu options, see menu.h */
struct menu_op mainmenu[]  = 
{
   "general",  stooges,          "main menu",      /* menu ID */
   "help",     help,             "help with menus",
   "state",    station_state,    "show current station setup",
#ifdef UDPSTEST
   "uesend",   udpecho, "open UDP echo client, send UDP echo packet",
   "uesinit",  udp_secho_init,   "start UDP echo server",
   "uechalt",  udp_cecho_close,  "close UDP echo client",
   "ueshalt",  udp_secho_close,  "close UDP echo server",
   "uestats",  udp_echo_stats,   "UDP echo statistics",
#endif
#ifdef TCP_ECHOTEST
   "tesend",   tcpecho, "open TCP echo client, send TCP echo packet",
   "tesinit",  tcp_secho_init,   "start TCP echo server",
   "teshalt",  tcp_secho_close,  "close TCP echo server",
   "techalt",  tcp_cecho_close,  "close TCP echo client",
   "testats",  tcp_echo_stats,   "TCP echo statistics",
#endif
   /* the parameters set by three are used outside of ping, so these
    * routines should always be included even if PING_APP is not
    */
   "delay",    ping_setdelay,  "set milliseconds to wait between pings",
   "host",     ping_sethost,   "set default active IP host",
   "length",   ping_setlength, "set default ping packet length",
   "quit",     menu_exit,        "quit station program",
#ifdef   MINI_PING
   "ping",     mini_ping,        "send a ping",
#endif   /* MINI_PING */
#ifdef INCLUDE_NVPARMS
   "nvset",    set_nv_params,    "set non-volatile parameters",
   "nvedit",   edit_nv_params,   "edit non-volatile parameters",
#endif
   "setip",    set_ipaddr,       "set interface IP address",
   "version",  showver,          "display version information",
   "!command", NULL,             "pass command to OS shell",
   
   /* (yaxon add) */
   "settel",   set_tel,          "set my telephone",
   "resetgsm", reset_gsm,        "restart gsm",
   NULL,
};

/* array of menu options, see menu.h */
struct menu_op diagmenu[]  = 
{
   "diagnostic",stooges,      "diagnostic aid menu",
#if defined(NET_STATS) && defined(INCLUDE_ARP)
   "arps",     arp_stats,     "display ARP stats and table",
#endif   /* INCLUDE_ARP && NET_STATS */
   "buffers",  dumpbufs,      "display free q buffer stats",
   "queues",   dumpqueues,    "dump packet buffer queues",
   "dbytes",   dump_bytes,    "dump block of memory",
   "debug",    setdebug,      "set IP stack debug tracing",
   "dtrap",    do_dtrap,      "try to hook debugger",
   "dump",     pktdump,       "hexdump incoming packets",
#ifdef VFS_FILES
   "dir",      vfs_dir,       "directory of VFS files",
#endif   /* VFS_FILES */
#ifdef  LOSSY_IO
   "lossy",    setlossy,      "set lossy packet IO options",
#endif
#ifdef NET_STATS
   "iface",    iface_stats,   "display net interface stats",
#endif
   "linkstats",linkstats,     "display link layer specific stats",
#ifdef HEAP_STATS    /* statistics keeping npalloc() and npfree() */
   "memory",   mh_stats,      "list currently alloced memory",
#endif   /* HEAP_STATS */

#ifdef DNS_CLIENT
   "nslookup", gethostbynametest, "do DNS gethostbyname()",
   "setdnssvr", setdnssvr,    "set up DNS Servers",
#ifdef  DNS_CLIENT_UPDT 
   "nsupdate", nsupdatetest,  "do Dynamic DNS update",
#endif  /* DNS_CLIENT_UPDT */
#ifdef NET_STATS
   "dnsstats", dns_state,     "DNS setup & statistics",
#endif
#endif   /* DNS_CLIENT */

#ifdef INCLUDE_TCP
#ifdef NET_STATS
#ifndef MINI_TCP
   "mbuf",     mbuf_stat,      "display mbuf stats",
   "mlist",    mbuf_list,      "display mbufs in use",
#endif   /* MINI_TCP */
   "tcp",      tcp_stat,       "display TCP stats",
   "sockets",  sock_list,      "display socket list", 
   "tbconn",   tcp_bsdconnstat,"tcp BSD connection stats",
   "tbsend",   tcp_bsdsendstat,"tcp BSD send stats",
   "tbrcv",    tcp_bsdrcvstat, "tcp BSD receive stats",
#endif   /* NET_STATS */
#endif   /* INCLUDE_TCP */

#ifdef IP_ROUTING
   "routes",   show_routes,    "display IP route table",
   "rtadd",    mn_add_route,   "manually add IP route to table",
#endif   /* IP_ROUTING */
   "allocsize",settrapsize,    "set size for alloc() breakpoint",
#ifdef NET_STATS
   "ipstat",   ip_stats,       "display IP layer stats",
   "icmpstat", icmp_stats,     "display ICMP layer stats",
   "udp",      udp_stats,      "display UDP layer stats",
#endif
   "upcall",   set_upc,        "trace received packets",
#if defined(INICHE_TASKS) || defined(CHRONOS)
   "tkstats",  tk_stats,       "tasking system status",
#endif
#ifdef DHCP_CLIENT
#ifdef NET_STATS
   "dcstats",  dhc_stats,      "DHCP Client statistics",
#endif
#endif
#ifdef IP_PMTU
#ifdef NET_STATS
   "pmtu",     pmtu_stats,     "Path MTU cache statistics",
#endif
#endif
#ifdef CHANGE_PWD
   "changepwd",change_pwd,    "change user password",
#endif
   NULL,
};

struct menu_op *  menus[] =      /* array of ptrs to menu groups */
{
   &mainmenu[0],  /* general menu should come 1st */
   &diagmenu[0],  /* Diagnostic menu              */
#ifdef ROUTE_TEST
   &rt_menu[0],
#endif   /* ROUTE_TEST */
#ifdef USE_PROFILER
   &profmenu[0],
#endif
   /* add new menus here */
   NULL,          /* spare slot(s) for dymanic menu additions */
   NULL,          /* Eg., RIP , NATRT, TELNET, PING install dynamic menus */
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,          /* NULL slot at end - end of menus marker */
};

int      nummenus = (sizeof(menus)/sizeof(void*)); /* number of menus */
int      snmp_dump_packet;
NET      if_netbytext(void * pio, char * iftext);
int      if_configbyname(NET);   /* configure a net based on it's name */


/* FUNCTION: pktdump()
 * 
 * PARAM1: void * pio
 *
 * RETURNS: 
 */

int
pktdump(void * pio)
{
   if (snmp_dump_packet)   /* toggle state of DUMP flag */
      snmp_dump_packet = FALSE;
   else
      snmp_dump_packet = TRUE;

   ns_printf(pio,"Packet hex dumping %sabled\n", 
    (snmp_dump_packet)?"en":"dis");
   return 0;
}



/* FUNCTION: do_dtrap()
 * 
 * PARAM1: void * pio
 *
 * RETURNS: 
 */

int do_dtrap(void * pio)
{
   USE_VOID(pio);
   dtrap("nrmenus 0\n");
   return 0;
}



/* FUNCTION: ishexdigit()
 *
 * some hex digit manipulation routines:
 * 
 * PARAM1: char digit
 *
 * RETURNS: 
 */

int   /* boolean */
ishexdigit(char digit)  /* return TRUE is char is hex digit */
{
   if (isdigit(digit))
      return TRUE;

   digit |= 0x20;       /* mask letters to lowercase */
   if ((digit >= 'a') && (digit <= 'f'))
      return TRUE;
   else
      return FALSE;
}



/* FUNCTION: hexnibble()
 * 
 * PARAM1: char digit
 *
 * RETURNS: 
 */

unsigned hexnibble(char digit)
{
   if (digit <= '9')
      return (digit-'0'    );

   digit &= ~0x20;   /* letter make uppercase */
   return (digit-'A')+10 ;
}



/* FUNCTION: atoh()
 *
 * atoh() - convert hex ascii string to unsigned. number may be preceeded
 * by whitspace or "0x". Halts at first non hex digit character.
 *
 * 
 * PARAM1: char * buf
 *
 * RETURNS: 
 */

unsigned
atoh(char * buf)
{
   unsigned retval = 0;
   char *   cp;
   char  digit;

   cp = buf;

   /* skip past spaces and tabs */
   while (*cp == ' ' || *cp == 9)
      cp++;

   /* while we see digits and the optional 'x' */
   while (ishexdigit(digit = *cp++) || (digit == 'x'))
   {
      /* its questionable what we should do with input like '1x234', 
       * or for that matter '1x2x3', what this does is ignore all 
       */
      if (digit == 'x')
         retval = 0;
      else
         retval = (retval << 4) + hexnibble(digit);
   }

   return retval;
}


/* FUNCTION: atohl()
 *
 * atohl() - same as atoh() above, except returns a long
 * 
 * PARAM1: char * buf
 *
 * RETURNS: 
 */

unsigned long
atohl(char * buf)
{
   unsigned long retval = 0;
   char *   cp;
   char  digit;

   cp = buf;

   /* skip past spaces and tabs */
   while (*cp == ' ' || *cp == 9)
      cp++;

   /* while we see digits and the optional 'x' */
   while (ishexdigit(digit = *cp++) || (digit == 'x'))
   {
      /* its questionable what we should do with input like '1x234', 
       * or for that matter '1x2x3', what this does is ignore all 
       */
      if (digit == 'x')
         retval = 0;
      else
         retval = (retval << 4) + hexnibble(digit);
   }

   return retval;
}


/* FUNCTION: hex2bin()
 *
 * hex2bin() - convert hexadecimal text into binary. Returns 0 if OK 
 * else error code in invalid hex char encountered in input string. 
 *
 * 
 * PARAM1: char * inbuf
 * PARAM2: unsigned char * outbuf
 * PARAM3: int bcount
 *
 * RETURNS: 
 */

int
hex2bin(char * inbuf, unsigned char * outbuf, int bcount)
{
   int   i;
   char *   cp =  inbuf;

   for (i = 0; i < bcount; i++)
   {
      if (ishexdigit(*cp))
         outbuf[i] = (unsigned char)(hexnibble(*cp) << 4);
      else
         return -1;
      cp++;
      if (ishexdigit(*cp))
         outbuf[i] |= (unsigned char)hexnibble(*cp);
      else
         return -1;
      cp++;
   }
   return 0;
}

#ifdef  LOSSY_IO
extern int  in_lossrate;

int
setlossy(void * pio)
{
   char *   cp =  nextarg( ((GEN_IO)pio)->inbuf );

   if(*cp == 'r')
   {
      NDEBUG |= LOSSY_RX;
   }
   else if(*cp == 't')
   {
      NDEBUG |=  LOSSY_TX;
   }
   else if(*cp == 'o')
   {
      NDEBUG &= ~(LOSSY_TX|LOSSY_RX);
   }
   else if(isdigit(*cp))
   {
      in_lossrate = atoi(cp);
   }
   else
   {
      ns_printf(pio, "usage: lossrate <'rx'|'tx'|'off'|rate>\n");
   }

   if(in_lossrate && ((NDEBUG & (LOSSY_RX|LOSSY_TX)) == 0))
      ns_printf(pio, "lossy data is disabled\n");
   else
   {
      ns_printf(pio, "pkt loss rate currently 1 in %d ", in_lossrate);
      if(NDEBUG & LOSSY_RX)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?