home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / kiss.c < prev    next >
C/C++ Source or Header  |  1991-01-26  |  1KB  |  76 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 "slip.h"
  9. #include "ax25.h"
  10.  
  11. /* Send raw data packet on KISS TNC */
  12. int
  13. kiss_raw(iface,data)
  14. struct iface *iface;
  15. struct mbuf *data;
  16. {
  17.     register struct mbuf *bp;
  18.  
  19.     /* Put type field for KISS TNC on front */
  20.     if((bp = pushdown(data,1)) == NULLBUF){
  21.         free_p(data);
  22.         return -1;
  23.     }
  24.     bp->data[0] = KISS_DATA;
  25.     /* slip_raw also increments sndrawcnt */
  26.     slip_raw(iface,bp);
  27.     return 0;
  28. }
  29.  
  30. /* Process incoming KISS TNC frame */
  31. void
  32. kiss_recv(iface,bp)
  33. struct iface *iface;
  34. struct mbuf *bp;
  35. {
  36.     char kisstype;
  37.  
  38.     kisstype = PULLCHAR(&bp);
  39.     switch(kisstype & 0xf){
  40.     case KISS_DATA:
  41.         ax_recv(iface,bp);
  42.         break;
  43.     default:
  44.         free_p(bp);
  45.         break;
  46.     }
  47. }
  48. /* Perform device control on KISS TNC by sending control messages */
  49. int
  50. kiss_ioctl(iface,argc,argv)
  51. struct iface *iface;
  52. int argc;
  53. char *argv[];
  54. {
  55.     struct mbuf *hbp;
  56.     int i;
  57.     char *cp;
  58.  
  59.     if(argc < 1){
  60.         tprintf("Data field missing\n");
  61.         return 1;
  62.     }
  63.     /* Allocate space for arg bytes */
  64.     if((hbp = alloc_mbuf((int16)argc)) == NULLBUF){
  65.         free_p(hbp);
  66.         return 0;
  67.     }
  68.     hbp->cnt = argc;
  69.     hbp->next = NULLBUF;
  70.     for(i=0,cp = hbp->data;i < argc;)
  71.         *cp++ = atoi(argv[i++]);
  72.  
  73.     slip_raw(iface,hbp);    /* Even more "raw" than kiss_raw */
  74.     return 0;
  75. }
  76.