home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / KISS.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  2KB  |  114 lines

  1. /* Routines for AX.25 encapsulation in KISS TNC
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4.  
  5. /****************************************************************************
  6. *    $Id: kiss.c 1.2 93/07/16 11:46:02 ROOT_DOS Exp $
  7. *    15 Jul 93    1.2        GT    AX25 conditional.                                *
  8. ****************************************************************************/
  9.  
  10. #include "global.h"
  11. #include "mbuf.h"
  12. #include "iface.h"
  13. #include "kiss.h"
  14. #include "devparam.h"
  15. #include "slip.h"
  16. #include "asy.h"
  17. #include "ax25.h"
  18. #include "config.h"
  19.  
  20. #if    AX25
  21.  
  22. /* Send raw data packet on KISS TNC */
  23. int
  24. kiss_raw(iface,data)
  25. struct iface *iface;
  26. struct mbuf *data;
  27. {
  28.     register struct mbuf *bp;
  29.  
  30.     /* Put type field for KISS TNC on front */
  31.     if((bp = pushdown(data,1)) == NULLBUF){
  32.         free_p(data);
  33.         return -1;
  34.     }
  35.     bp->data[0] = PARAM_DATA;
  36.     /* slip_raw also increments sndrawcnt */
  37.     slip_raw(iface,bp);
  38.     return 0;
  39. }
  40.  
  41. /* Process incoming KISS TNC frame */
  42. void
  43. kiss_recv(iface,bp)
  44. struct iface *iface;
  45. struct mbuf *bp;
  46. {
  47.     char kisstype;
  48.  
  49.     kisstype = PULLCHAR(&bp);
  50.     switch(kisstype & 0xf){
  51.     case PARAM_DATA:
  52.         ax_recv(iface,bp);
  53.         break;
  54.     default:
  55.         free_p(bp);
  56.         break;
  57.     }
  58. }
  59. /* Perform device control on KISS TNC by sending control messages */
  60. int32
  61. kiss_ioctl(iface,cmd,set,val)
  62. struct iface *iface;
  63. int cmd;
  64. int set;
  65. int32 val;
  66. {
  67.     struct mbuf *hbp;
  68.     char *cp;
  69.     int rval = 0;
  70.  
  71.     /* At present, only certain parameters are supported by
  72.      * stock KISS TNCs. As additional params are implemented,
  73.      * this will have to be edited
  74.      */
  75.     switch(cmd){
  76.     case PARAM_RETURN:
  77.         set = 1;    /* Note fall-thru */
  78.     case PARAM_TXDELAY:
  79.     case PARAM_PERSIST:
  80.     case PARAM_SLOTTIME:
  81.     case PARAM_TXTAIL:
  82.     case PARAM_FULLDUP:
  83.     case PARAM_HW:
  84.         if(!set){
  85.             rval = -1;    /* Can't read back */
  86.             break;
  87.         }
  88.         /* Allocate space for cmd and arg */
  89.         if((hbp = alloc_mbuf(2)) == NULLBUF){
  90.             free_p(hbp);
  91.             rval = -1;
  92.             break;
  93.         }
  94.         cp = hbp->data;
  95.         *cp++ = cmd;
  96.         *cp = val;
  97.         hbp->cnt = 2;
  98.         slip_raw(iface,hbp);    /* Even more "raw" than kiss_raw */
  99.         rval = val;        /* per Jay Maynard -- mce */
  100.         break;
  101.     case PARAM_SPEED:    /* These go to the local asy driver */
  102.     case PARAM_DTR:
  103.     case PARAM_RTS:
  104.         rval = asy_ioctl(iface,cmd,set,val);
  105.         break;
  106.     default:        /* Not implemented */
  107.         rval = -1;
  108.         break;
  109.     }
  110.     return rval;
  111. }
  112.  
  113. #endif    /* AX25 */
  114.