home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1 / HamRadio.cdr / misc / tcpipsrc / ppp.h < prev    next >
C/C++ Source or Header  |  1991-01-15  |  13KB  |  325 lines

  1. #ifndef _PPP_H
  2. #define _PPP_H
  3. /*
  4.  *    PPP.H
  5.  *
  6.  *    12-89    -- Katie Stevens (dkstevens@ucdavis.edu)
  7.  *           UC Davis, Computing Services
  8.  *    PPP.07    04-90    [ks] start with same peer addr during IPCP
  9.  *    PPP.08    05-90    [ks] improve statistic and trace reporting
  10.  *    PPP.09    05-90    [ks] add UPAP processing
  11.  *    PPP.10    06-90    [ks] improve keybd input of UPAP password
  12.  *                 make ppp open/close/reset work properly
  13.  *                 add peerID-to-IPaddr lookup table
  14.  *                 add peer IP lookup pool
  15.  *    PPP.13    08-90    [ks] add timestamp for PPP open
  16.  *    PPP.14    08-90    [ks] change UPAP to PAP for consistency with RFC1172
  17.  *                 add RLSD link up/down signal handling
  18.  *                 add autobaud link speed message handling
  19.  *                 make LCP/IPCP timeouts configurable
  20.  *    PPP.15    09-90    [ks] update to KA9Q NOS v900828
  21.  */
  22.  
  23. #ifndef    _GLOBAL_H
  24. #include "global.h"
  25. #endif
  26.  
  27. #ifndef    _MBUF_H
  28. #include "mbuf.h"
  29. #endif
  30.  
  31. #ifndef    _IFACE_H
  32. #include "iface.h"
  33. #endif
  34.  
  35. #ifndef _IP_H
  36. #include "ip.h"
  37. #endif
  38.  
  39. #ifndef _SLIP_H
  40. #include "slip.h"
  41. #endif
  42.  
  43. #ifndef _TIMER_H
  44. #include "timer.h"
  45. #endif
  46.  
  47. /* PPP definitions */
  48. #define    PPP_ALLOC    100    /* Receiver allocation increment */
  49.  
  50. /* Bit masks for escaped element of Slip[] control block */
  51. #define PPP_BIT_BUCKET    0x01        /* Discard bytes until next frame */
  52. #define PPP_ESCAPED    0x02        /* Un-complement next rcv char */
  53. #define PPP_RCV_ACCOMP    0x04        /* Compress HDLC addr/ctl fields */
  54. #define PPP_RCV_PRCOMP    0x08        /* Compress PPP protocol field */
  55. #define PPP_XMT_ACCOMP    0x10        /* Compress HDLC addr/ctl fields */
  56. #define PPP_XMT_PRCOMP    0x20        /* Compress PPP protocol field */
  57. #define PPP_RCV_VJCOMPR    0x40        /* Van Jacobson TCP header compress */
  58. #define PPP_XMT_VJCOMPR    0x80        /* VJ TCP header compression on send */
  59.  
  60. /* Table for LCP configuration requests */
  61. struct lcpparm {
  62.     unsigned char neg_mru;        /* Attempt/accept MRU negotiation */
  63.     int16 mru;                /* Maximum Receive Unit value */
  64.     unsigned char neg_ctl_map;        /* Attempt/accept ctl map neg */
  65.     int32 ctl_map;            /* Async Control Map value */
  66.     unsigned char neg_auth_type;    /* Attempt/accept auth type neg */
  67.     int16 auth_type;            /* Authentication Type */
  68.     unsigned char neg_encr_type;    /* Attempt/accept encrpytion neg */
  69.     int16 encr_type;            /* Encryption Type */
  70.     unsigned char neg_magic_num;    /* Attempt/accept magic number neg */
  71.     int32 magic_num;            /* Magic number value */
  72.     unsigned char neg_keepalive;    /* Attempt/accept keepalive neg */
  73.     unsigned char keepalive;        /* Keepalive value */
  74.     unsigned char neg_prot_compress;    /* Attempt/accept protocol compr neg */
  75.     int prot_compress;            /* Protocol Compression boolean */
  76.     unsigned char neg_ac_compress;    /* Attmept/accept addr/ctl compr neg */
  77.     int ac_compress;            /* Addr/Ctl Compression boolean */
  78. };
  79. /* Default configuration option values */
  80. #define DEF_MRU        1500        /* Max Receive Unit = 1500 bytes */
  81. #define DEF_CTL_MAP    0xffffffff    /* Async Ctl Map = esc all controls */
  82. #define DEF_AUTH_TYPE    0x0000        /* No Authentication protocol */
  83. #define DEF_ENCR_TYPE    0x0000        /* No Encryption protocol */
  84. #define DEF_MAGIC_NUM    0x00000000    /* No Magic Number */
  85. #define DEF_LINK_QUAL    0x00        /* No Link Quality Monitoring */
  86. #define DEF_PROT_COMPR    0x00        /* No Protocol Compression */
  87. #define DEF_AC_COMPR    0x00        /* No Addr/Ctl Compression */
  88. /* Other configuration option values */
  89. #define MIN_MRU        128        /* Set a lower limit */
  90. #define PAP_AUTH_TYPE    0xc023        /* Password Auth Protocol */
  91.  
  92.  
  93. /* LCP control block */
  94. struct lcpctl {
  95.     char active;            /* 0=passive open; non-0=active open */
  96.     char lcp_state;            /* State of Link Control exchange */
  97. #define LCP_CLOSED    0x00
  98. #define LCP_LISTEN    0x01
  99. #define LCP_REQ_SENT    0x02
  100. #define LCP_ACK_RCVD    0x03
  101. #define LCP_ACK_SENT    0x04
  102. #define LCP_OPEN    0x05
  103. #define LCP_TERMINATE    0x06
  104.     unsigned char lastid;        /* ID of last REQ we sent */
  105.     struct timer lcp_tm;        /* Timer against response to our REQ */
  106.     unsigned char ack_retry;        /* Retry counter for timeouts */
  107.  
  108.     struct lcpparm initparm;        /* First request of local parameters */
  109.     struct lcpparm lclparm;        /* Negotiated local parameters */
  110.     struct lcpparm remparm;        /* Negotiated remote parameters */
  111.  
  112.     char pap_state;            /* Current state of PAP */
  113. #define PAP_CLOSED    0x00
  114. #define PAP_LISTEN    0x01
  115. #define PAP_REQ_SENT    0x02
  116. #define PAP_REQ_RCVD    0x03
  117. #define PAP_OPEN    0x04
  118.     char *pap_user;            /* Peer ID for PAP AUTH_REQ */
  119.     char *pap_pass;            /* Password for PAP AUTH_REQ */
  120. };
  121. #define LCP_TIMEOUT     3        /* 3 sec timeout wait for response */
  122. #define LCP_RETRY_MAX    10        /* Retry on timeout at most 10 times */
  123. #define LCP_TERM_RETRY     2        /* Minimal retry on TERM REQ */
  124. #define PAP_RETRY_MAX    20        /* Retry on timeout at most 20 times */
  125. #define PAP_FAIL_MAX     4        /* At most 5 attempts at peer auth */
  126. /* Permissions bit for use with userlogin() in FTPSERV.C */
  127. /* Other bit values in FTPSERV.H, AX_MBX.H               */
  128. #define PPP_ACCESS_PRIV    0x0100        /* Priv bit for PPP connection */
  129. #define PPP_PWD_LOOKUP    0x0200        /* Priv bit for peerID/pass lookup */
  130.  
  131. /* IPCP pool of addresses when remote peer requests address assignment */
  132. struct ipcppool {
  133.     int32 peer_min;            /* First IP address in pool */
  134.     int32 peer_max;            /* Last IP address in pool */
  135.     int32 peer_next;        /* Next address to assign */
  136. };
  137. #define NULLPOOL (struct ipcppool *)0
  138.  
  139. /* IPCP control block */
  140. struct ipcpctl {
  141.     char active;            /* 0=passive open; non-0=active open */
  142.     char ipcp_state;            /* State of Link Control exchange */
  143. #define IPCP_CLOSED    0x00
  144. #define IPCP_LISTEN    0x01
  145. #define IPCP_REQ_SENT    0x02
  146. #define IPCP_ACK_RCVD    0x03
  147. #define IPCP_ACK_SENT    0x04
  148. #define IPCP_OPEN    0x05
  149. #define IPCP_TERMINATE    0x06
  150.     unsigned char lastid;        /* ID of last REQ we sent */
  151.     struct timer ipcp_tm;        /* Timer against response to our REQ */
  152.     unsigned char ack_retry;        /* Retry counter for timeouts */
  153.  
  154.     int32 peer_addr;            /* IP address of remote peer */
  155.     struct ipcppool *peer_pool;        /* Pool of IP addresses for peer */
  156.     unsigned char attempt_addrs;    /* 1=send a ConfigReq with our addrs */
  157.     int32 attempt_src;            /* Addr to send with config request */
  158.     int32 attempt_dest;            /* Addr to send with config request */
  159.     unsigned char accept_addrs;        /* 1=accept addrs from remote host */
  160.     int32 accept_src;            /* Src addr given by remote host */
  161.     int32 accept_dest;            /* Dest addr given by remote host */
  162.     unsigned char neg_ip_compr;        /* 1=negotiate IP packet compression */
  163.     int16 ip_compr_type;        /* Type of IP packet compression */
  164.     unsigned char attempt_ip_compr;    /* 1=we will request IP compression */
  165.     int16 lcl_ip_compr;            /* Type of IP compression we want */
  166.     unsigned char accept_ip_compr;    /* 1=we will accept IP compr request */
  167.     int16 rem_ip_compr;            /* Type of IP compression requested */
  168. };
  169. #define IPCP_TIMEOUT      3        /* 3 sec timeout wait for response */
  170. #define IPCP_RETRY_MAX    254        /* Retry for a long time */
  171. #define IPCP_TERM_RETRY      2        /* Minimal retry on TERM REQ */
  172. #define IPCP_VJCOMPR    0x0037        /* Van Jacobson TCP header compr */
  173. #define DEF_IP_COMPR    0x00        /* No IP compression */
  174.  
  175. /* PPP control block */
  176. struct pppctl {
  177.     int16 calc_fcs;            /* Cummulative FCS value (rcv pkts) */
  178.     int32 ctlmap;            /* Async control map (xmt pkts) */
  179.  
  180.     char state;                /* Overall PPP link state */
  181. #define PPP_PL_DOWN    0x00            /* Physical Layer Down */
  182. #define PPP_AUTOBAUD    0x01            /* Waiting for autobaud msg */
  183. #define PPP_CLOSED    0x02            /* Idle State */
  184. #define PPP_LCP        0x03            /* Negotiating LCP options */
  185. #define PPP_PAP        0x04            /* Password authentication */
  186. #define PPP_IPCP    0x05            /* Negotiating IP options */
  187. #define PPP_OPEN    0x06            /* Link open for all traffic */
  188.     struct lcpctl lcpio;        /* Control block for LCP negotiation */
  189.     struct ipcpctl ipcpio;        /* Ctl block for IPCP negotiation */
  190.  
  191. #ifndef PPP_NO_STATS
  192.     int32 upsince;            /* Timestamp when state is PPP_OPEN */
  193.     int32 sndpkt;            /* # packets sent on PPP interface */
  194.     int16 snderr;            /* # pkts with PPP error on send */
  195.     int32 rcvpkt;            /* # packets rcvd on PPP interface */
  196.     int16 rcverr;            /* # pkts with error */
  197.     int16 csumerr;            /* # rcv pkts with bad PPP checksum */
  198.  
  199.     int16 sndlcp;            /* # LCP packets sent */
  200.     int16 sndpap;            /* # PAP packets sent */
  201.     int16 sndipcp;            /* # IPCP packets sent */
  202.     int32 sndip;            /* # IP packets sent */
  203.     int16 rcvlcp;            /* # LCP packets received */
  204.     int16 rcvpap;            /* # PAP packets received */
  205.     int16 rcvipcp;            /* # IPCP packets received */
  206.     int32 rcvip;            /* # IP packets received */
  207.     int16 rcvunk;            /* # unknown packets received */
  208. #endif
  209. };
  210. #define NULLPPPCTL    (struct pppctl *)0
  211.  
  212. struct ppphdr {
  213.     unsigned char addr;        /* Address field (always 0xff) */
  214.     char control;        /* Control field (always 0x03) */
  215.     int16 type;            /* Protocol field (IP, IPCP, LCP, PAP) */
  216. #define PPP_IP_TYPE    0x0021    /* DOD Internet Protocol */
  217. #define PPP_COMPR_TYPE    0x002d    /* Van Jacobson Compressed TCP/IP */
  218. #define PPP_UNCOMP_TYPE    0x002f    /* Van Jacobson Uncompressed TCP/IP */
  219.  
  220. #define PPP_IPCP_TYPE    0x8021    /* DOD Internet Protocol Control Protocol */
  221.  
  222. #define PPP_LCP_TYPE    0xc021    /* Link Control Protocol */
  223. #define PPP_PAP_TYPE    0xc023    /* Password Authentication Protocol */
  224. };
  225. #define PPP_HDRLEN    4    /* Max bytes for PPP/HDLC envelope header */
  226.  
  227. /* HDLC envelope constants */
  228. #define HDLC_ENVLEN    0x06    /* Max bytes for HDLC envelope (outgoing) */
  229.  
  230. #define HDLC_FLAG    0x7e    /* HDLC async start/stop flag */
  231. #define HDLC_ALL_ADDR    0x00ff    /* HDLC all-station address flag */
  232. #define HDLC_UI        0x03    /* HDLC Unnumbered Info control flag */
  233. #define HDLC_ESC_ASYNC    0x7d    /* HDLC transparency escape flag for async */
  234. #define HDLC_ESC_COMPL    0x20    /* HDLC transparency bit complement mask */
  235.  
  236. #define HDLC_FCS_START    0xffff    /* Starting bit string for FCS calculation */
  237. #define HDLC_FCS_FINAL    0xf0b8    /* FCS when summed over frame and sender FCS */
  238.  
  239. /* LCP/IPCP config packet header */
  240. struct cnfhdr {
  241.     char code;
  242. /* LCP/IPCP config packet codes */
  243. #define CONFIG_REQ    0x01
  244. #define CONFIG_ACK    0x02
  245. #define CONFIG_NAK    0x03
  246. #define CONFIG_REJ    0x04
  247. #define TERMINATE_REQ    0x05
  248. #define TERMINATE_ACK    0x06
  249. #define CODE_REJ    0x07
  250. #define PROT_REJ    0x08
  251. #define ECHO_REQ    0x09
  252. #define ECHO_REPLY    0x0a
  253. #define DISCARD_REQ    0x0b
  254. /* PAP config packet codes */
  255. #define AUTH_REQ    0x01
  256. #define AUTH_ACK    0x02
  257. #define AUTH_NAK    0x03
  258.     unsigned char id;
  259.     int16 len;
  260. };
  261. #define CNF_HDRLEN    4    /* Length of LCP/IPCP config packet header */
  262.  
  263. /* LCP/IPCP config option header */
  264. struct opthdr {
  265.     char type;
  266. /* LCP option types */
  267. #define MAX_RCV_UNIT    0x01
  268. #define ASYNC_CTL_MAP    0x02
  269. #define AUTH_TYPE    0x03
  270. #define ENCR_TYPE    0x04
  271. #define MAGIC_NUMBER    0x05
  272. #define LINK_QUALITY    0x06
  273. #define PROT_COMPRESS    0x07
  274. #define AC_COMPRESS    0x08
  275. /* IPCP option types */
  276. #define IP_ADDRS    0x01
  277. #define IP_COMPR_TYPE    0x02
  278.     unsigned char len;
  279. };
  280. #define OPT_HDRLEN    2    /* Length of LCP/IPCP config option header */
  281. #define NULLOPTHDR    (struct opthdr *)0
  282.  
  283. /* In ppp.c: */
  284. int ntohppp __ARGS((struct ppphdr *ppp, struct mbuf **bpp));
  285. int ppp_send __ARGS((struct mbuf *data,struct iface *iface,int32 gateway,int prec,
  286.     int del,int tput,int rel));
  287. int ppp_output __ARGS((struct iface *iface, char dest[], char source[],
  288.     int16 type, struct mbuf *data));
  289. int ppp_raw __ARGS((struct iface *iface,struct mbuf *data));
  290. void ppp_recv __ARGS((int dev,void *p1,void *p2));
  291. void ppp_autobaud __ARGS((int dev,void *p1,void *p2));
  292. void ppp_rlsd __ARGS((int dev,void *p1,void *p2));
  293. int ppp_init __ARGS((int dev, char rlsd, long autospeed));
  294. int ppp_close __ARGS((struct slip *sp, int pl_too));
  295. void pproc __ARGS((struct iface *iface,struct mbuf *bp));
  296.  
  297. /* In ppplcp.c: */
  298. struct mbuf *htoncnf __ARGS((struct cnfhdr *cnf, struct mbuf *data));
  299. int ntohcnf __ARGS((struct cnfhdr *cnf, struct mbuf **bpp));
  300. struct mbuf *htonopt __ARGS((struct opthdr *opt));
  301. int ntohopt __ARGS((struct opthdr *opt, struct mbuf **bpp));
  302.  
  303. void lcp_init __ARGS((struct slip *sp));
  304. int lcp_reset __ARGS((struct pppctl *pppiop));
  305. int lcp_close __ARGS((struct slip *sp));
  306. int lcp_start __ARGS((struct slip *sp));
  307. void lcp_shutdown __ARGS((struct slip *sp));
  308. void lcpproc __ARGS((struct iface *iface, struct mbuf *bp));
  309.  
  310. /* In pppipcp.c: */
  311. void ipcp_init __ARGS((struct slip *sp));
  312. int ipcp_reset __ARGS((struct slip *sp));
  313. int ipcp_close __ARGS((struct slip *sp));
  314. int ipcp_start __ARGS((struct slip *sp));
  315. void ipcpproc __ARGS((struct iface *iface, struct mbuf *bp));
  316.  
  317. /* In ppppap.c: */
  318. void pap_init __ARGS((struct slip *sp));
  319. int pap_reset __ARGS((struct pppctl *pppiop));
  320. int pap_start __ARGS((struct slip *sp));
  321. int pap_getpass __ARGS((struct slip *sp,int mustask));
  322. void papproc __ARGS((struct iface *iface, struct mbuf *bp));
  323.  
  324. #endif    /* _PPP_H */
  325.