home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / KISS.C < prev    next >
C/C++ Source or Header  |  1991-05-13  |  2KB  |  103 lines

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