home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / s920603.zip / KISS.C < prev    next >
C/C++ Source or Header  |  1992-05-03  |  3KB  |  145 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. #include "pktdrvr.h"
  13.  
  14. /* Set up a SLIP link to use AX.25 */
  15. int
  16. kiss_init(ifp,vj)
  17. struct iface *ifp;
  18. int vj;    /* Unused */
  19. {
  20.     int xdev;
  21.     struct slip *sp;
  22.     char *ifn;
  23.  
  24.     for(xdev = 0;xdev < SLIP_MAX;xdev++){
  25.         sp = &Slip[xdev];
  26.         if(sp->iface == NULLIF)
  27.             break;
  28.     }
  29.     if(xdev >= SLIP_MAX) {
  30.         printf("Too many slip devices\n");
  31.         return -1;
  32.     }
  33.     setencap(ifp,"KISS");
  34.     ifp->ioctl = kiss_ioctl;
  35.     ifp->raw = kiss_raw;
  36.     ifp->show = slip_status;
  37.  
  38.     if(ifp->hwaddr == NULLCHAR)
  39.         ifp->hwaddr = mallocw(AXALEN);
  40.     memcpy(ifp->hwaddr,Mycall,AXALEN);
  41.     ifp->xdev = xdev;
  42.  
  43.     sp->iface = ifp;
  44.     sp->send = asy_send;
  45.     sp->get = get_asy;
  46.     sp->type = CL_KISS;
  47.     ifp->rxproc = newproc( ifn = if_name( ifp, " rx" ),
  48.         256,slip_rx,xdev,NULL,NULL,0);
  49.     free(ifn);
  50.     return 0;
  51. }
  52. int
  53. kiss_free(ifp)
  54. struct iface *ifp;
  55. {
  56.     if(Slip[ifp->xdev].iface == ifp)
  57.         Slip[ifp->xdev].iface = NULLIF;
  58.     return 0;
  59. }
  60. /* Send raw data packet on KISS TNC */
  61. int
  62. kiss_raw(iface,bp)
  63. struct iface *iface;
  64. struct mbuf *bp;
  65. {
  66.     /* Put type field for KISS TNC on front */
  67.     bp = pushdown(bp,1);
  68.     bp->data[0] = PARAM_DATA;
  69.     /* slip_raw also increments sndrawcnt */
  70.     slip_raw(iface,bp);
  71.     return 0;
  72. }
  73.  
  74. /* Process incoming KISS TNC frame */
  75. void
  76. kiss_recv(iface,bp)
  77. struct iface *iface;
  78. struct mbuf *bp;
  79. {
  80.     char kisstype;
  81.  
  82.     kisstype = PULLCHAR(&bp);
  83.     switch(kisstype & 0xf){
  84.     case PARAM_DATA:
  85.         ax_recv(iface,bp);
  86.         break;
  87.     default:
  88.         free_p(bp);
  89.         break;
  90.     }
  91. }
  92. /* Perform device control on KISS TNC by sending control messages */
  93. int32
  94. kiss_ioctl(iface,cmd,set,val)
  95. struct iface *iface;
  96. int cmd;
  97. int set;
  98. int32 val;
  99. {
  100.     struct mbuf *hbp;
  101.     char *cp;
  102.     int rval = 0;
  103.  
  104.     /* At present, only certain parameters are supported by
  105.      * stock KISS TNCs. As additional params are implemented,
  106.      * this will have to be edited
  107.      */
  108.     switch(cmd){
  109.     case PARAM_RETURN:
  110.         set = 1;    /* Note fall-thru */
  111.     case PARAM_TXDELAY:
  112.     case PARAM_PERSIST:
  113.     case PARAM_SLOTTIME:
  114.     case PARAM_TXTAIL:
  115.     case PARAM_FULLDUP:
  116.     case PARAM_HW:
  117.         if(!set){
  118.             rval = -1;    /* Can't read back */
  119.             break;
  120.         }
  121.         /* Allocate space for cmd and arg */
  122.         if((hbp = alloc_mbuf(2)) == NULLBUF){
  123.             free_p(hbp);
  124.             rval = -1;
  125.             break;
  126.         }
  127.         cp = hbp->data;
  128.         *cp++ = cmd;
  129.         *cp = val;
  130.         hbp->cnt = 2;
  131.         slip_raw(iface,hbp);    /* Even more "raw" than kiss_raw */
  132.         rval = val;        /* per Jay Maynard -- mce */
  133.         break;
  134.     case PARAM_SPEED:    /* These go to the local asy driver */
  135.     case PARAM_DTR:
  136.     case PARAM_RTS:
  137.         rval = asy_ioctl(iface,cmd,set,val);
  138.         break;
  139.     default:        /* Not implemented */
  140.         rval = -1;
  141.         break;
  142.     }
  143.     return rval;
  144. }
  145.