/**HEADER********************************************************************
* 
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 2004-2008 Embedded Access Inc.;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
*************************************************************************** 
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR 
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  
* IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
* THE POSSIBILITY OF SUCH DAMAGE.
*
**************************************************************************
*
* $FileName: sh_arpdisp.c$
* $Version : 3.0.4.0$
* $Date    : Jan-13-2009$
*
* Comments:
*
*   Example using RTCS Library.
*
*END************************************************************************/

#include <mqx.h>
#include <rtcs.h>
#include <enet.h>
#include "shell.h"
#include "sh_rtcs.h"
#include "sh_enet.h"


extern void ARP_display_if_table(_rtcs_if_handle   ihandle);
uint_32 RTCS_arp_delete
   (
      _rtcs_if_handle _PTR_   ihandle,
         /* [IN] the RTCS interface state structure */
      _ip_address                paddr
         /* [IN] the address to add */
   );
uint_32 RTCS_arp_add
   (
      _rtcs_if_handle _PTR_   ihandle,
         /* [IN] the RTCS interface state structure */
      _ip_address              paddr,
         /* [IN] the address to add */
      char           laddr[6]
   );

/*TASK*-----------------------------------------------------------------
*
* Function Name  : Shell_arpdisp
* Returned Value : void
* Comments       :
*
*END------------------------------------------------------------------*/

int_32 Shell_arpdisp(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   _rtcs_if_handle   ihandle = ipcfg_get_ihandle (IPCFG_default_enet_device);
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

    if (!print_usage)  {
      if (argc > 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  { 
        ARP_display_if_table(ihandle);
      }
    }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<ihandle>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<ihandle>] \n", argv[0]);
         printf("   <ihandle>  = Interface handle\n");
      }
   }

   return return_code;
} /* Endbody */

/*TASK*-----------------------------------------------------------------
*
* Function Name  : Shell_arpdel
* Returned Value : void
* Comments       :
*
*END------------------------------------------------------------------*/

int_32 Shell_arpdel(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   _ip_address       enet_ipaddr = IPCFG_default_ip_address;
   _rtcs_if_handle   ihandle = ipcfg_get_ihandle (IPCFG_default_enet_device);
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  if (! Shell_parse_ip_address( argv[1], &enet_ipaddr  ))  {
          printf("Error, invalid ip address\n");
          return_code = SHELL_EXIT_ERROR;
      }
      if (return_code == SHELL_EXIT_SUCCESS) {
          RTCS_arp_delete(ihandle,enet_ipaddr);
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <ip_address>\n", argv[0]);
      } else  {
         printf("Usage: %s <ip_address> \n", argv[0]);
         printf("   <ip_address>  = IP Address\n");
      }
   }

   return return_code;
} /* Endbody */

/*TASK*-----------------------------------------------------------------
*
* Function Name  : Shell_arpadd
* Returned Value : void
* Comments       :
*
*END------------------------------------------------------------------*/

int_32 Shell_arpadd(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;

   _rtcs_if_handle   ihandle = ipcfg_get_ihandle (IPCFG_default_enet_device);
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  { 
        ARP_display_if_table(ihandle);
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<ihandle>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<ihandle>] \n", argv[0]);
         printf("   <ihandle>  = Interface handle\n");
      }
   }

   return return_code;
} /* Endbody */



/* EOF */

