/* iaoctl.c */

/* IOCTL interface exported to diagnostic utilities */

/* Copyright (c) 2000  James M. Westall, Dept of Computer Science,
 *                     Clemson University, Clemson SC 29634 USA
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * To obtain a copy of the GNU General Public License write to the
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * This software is derived from software developed by the James Westall
 * and Robert Geist and carrying the following copyright.
 *
 * Copyright (c) 1996  Robert Geist and James Westall
 *                     Clemson University Dept. of Computer Science
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include "ia_defs.h"
#include "ia_comm.h"

/**/
/* Character device open entry point */

extern ia_softc_t *softc;
extern int        drop_sig_pkt;

static char msg[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

int ia_open(
struct inode *inode,
struct file *fp)
{

   return(0);
}

/**/
/* Character device ioctl entry point */

unsigned char sendbuf[3 * 1024];
unsigned char recvbuf[3 * 1024];

int ia_ioctl(
struct inode *inode,
struct file  *fp,
unsigned int  func_code,
unsigned long arg)
{
   unsigned int *word;
   aal_parms_t   aal;
   unsigned int *wordxxx;
   unsigned int  id;
   unsigned int  val;
   int           loc;
   int           len;
   int           rc;
   int           i;
   int           offset;
   unsigned char nvbuf[128];

   word = (unsigned int *)arg;
   rc = verify_area(VERIFY_WRITE, (char *)arg, 24);
   if (rc)
      return(rc);
   rc = 0;
/* printk("Ioctl called with code %d \n", func_code); */

   switch(func_code)
   {
   case IA_GETTXCTL:
      rc = verify_area(VERIFY_WRITE, (char *)word, 256);
      printk("Verify area returned %d \n", rc);
      if (rc)
         return(rc);
      copy_to_user(word, softc->brd_regs.ffred_mem, 256);
      get_user(id,  word);
      get_user(val, word + 1);
      return(256);
      break;

   case IA_FFRED:
      rc = verify_area(VERIFY_WRITE, (char *)word, sizeof(ffred_t));
      printk("Verify area returned %d \n", rc);
      if (rc)
         return(rc);
      copy_to_user(word, softc->brd_regs.ffred, sizeof(ffred_t));
      break;

   case IA_RFRED:
      rc = verify_area(VERIFY_WRITE, (char *)word, sizeof(rfred_t));
      printk("Verify area returned %d \n", rc);
      if (rc)
         return(rc);
      copy_to_user(word, softc->brd_regs.rfred, sizeof(rfred_t));
      break;

   case IA_FLIP:
      rc = verify_area(VERIFY_WRITE, (char *)word, sizeof(fl_internal_t));
      printk("Verify area returned %d \n", rc);
      if (rc)
         return(rc);
      copy_to_user(word, softc->brd_regs.flipper, sizeof(fl_internal_t));
      break;

   case IA_DRVSTAT:
      rc = verify_area(VERIFY_WRITE, (char *)word, sizeof(softc->driver_stat));
      printk("Verify area returned %d \n", rc);
      if (rc)
         return(rc);
      copy_to_user(word, &softc->driver_stat, sizeof(softc->driver_stat));
      break;

   case IA_SETTXPRM:
      rc = verify_area(VERIFY_READ, (char *)word, 4 * sizeof(int));
      {
         int rate;
         get_user(rate, word);
         ia_settxp(softc, rate);
      }

   case IA_LOG:
      softc->logtx ^= 1;
      softc->logrx ^= 1;
      break;

   case IA_DROPSIG:
      drop_sig_pkt = 1;
      break;

   case IA_DUMPRFQ:
      ia_dump_rx_free(softc);
      break;

   case IA_DUMPTXB:
      ia_dump_txb(softc);
      break;

   default: ;
   }

   return(rc);
}

/**/
/* Character device release */

int ia_release(
struct inode *inode,
struct file *fp)
{

/* printk("APE25: Close called \n"); */
/* atm_unmapdma(ape);  */

   return(0);
}

