18d5a6048SAxel Dörfler /* 28d5a6048SAxel Dörfler * Copyright (c) 1988, 1993 38d5a6048SAxel Dörfler * The Regents of the University of California. All rights reserved. 48d5a6048SAxel Dörfler * 58d5a6048SAxel Dörfler * Redistribution and use in source and binary forms, with or without 68d5a6048SAxel Dörfler * modification, are permitted provided that the following conditions 78d5a6048SAxel Dörfler * are met: 88d5a6048SAxel Dörfler * 1. Redistributions of source code must retain the above copyright 98d5a6048SAxel Dörfler * notice, this list of conditions and the following disclaimer. 108d5a6048SAxel Dörfler * 2. Redistributions in binary form must reproduce the above copyright 118d5a6048SAxel Dörfler * notice, this list of conditions and the following disclaimer in the 128d5a6048SAxel Dörfler * documentation and/or other materials provided with the distribution. 13*6b99b206SAugustin Cavalier * 3. Neither the name of the University nor the names of its contributors 148d5a6048SAxel Dörfler * may be used to endorse or promote products derived from this software 158d5a6048SAxel Dörfler * without specific prior written permission. 168d5a6048SAxel Dörfler * 178d5a6048SAxel Dörfler * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 188d5a6048SAxel Dörfler * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 198d5a6048SAxel Dörfler * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 208d5a6048SAxel Dörfler * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 218d5a6048SAxel Dörfler * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 228d5a6048SAxel Dörfler * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 238d5a6048SAxel Dörfler * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 248d5a6048SAxel Dörfler * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 258d5a6048SAxel Dörfler * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 268d5a6048SAxel Dörfler * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 278d5a6048SAxel Dörfler * SUCH DAMAGE. 288d5a6048SAxel Dörfler * 298d5a6048SAxel Dörfler * @(#)ring.h 8.1 (Berkeley) 6/6/93 30*6b99b206SAugustin Cavalier * $FreeBSD$ 318d5a6048SAxel Dörfler */ 328d5a6048SAxel Dörfler 338d5a6048SAxel Dörfler #if defined(P) 348d5a6048SAxel Dörfler # undef P 358d5a6048SAxel Dörfler #endif 368d5a6048SAxel Dörfler 378d5a6048SAxel Dörfler #if defined(__STDC__) || defined(LINT_ARGS) 388d5a6048SAxel Dörfler # define P(x) x 398d5a6048SAxel Dörfler #else 408d5a6048SAxel Dörfler # define P(x) () 418d5a6048SAxel Dörfler #endif 428d5a6048SAxel Dörfler 438d5a6048SAxel Dörfler /* 448d5a6048SAxel Dörfler * This defines a structure for a ring buffer. 458d5a6048SAxel Dörfler * 468d5a6048SAxel Dörfler * The circular buffer has two parts: 478d5a6048SAxel Dörfler *((( 488d5a6048SAxel Dörfler * full: [consume, supply) 498d5a6048SAxel Dörfler * empty: [supply, consume) 508d5a6048SAxel Dörfler *]]] 518d5a6048SAxel Dörfler * 528d5a6048SAxel Dörfler */ 538d5a6048SAxel Dörfler typedef struct { 548d5a6048SAxel Dörfler unsigned char *consume, /* where data comes out of */ 558d5a6048SAxel Dörfler *supply, /* where data comes in to */ 568d5a6048SAxel Dörfler *bottom, /* lowest address in buffer */ 578d5a6048SAxel Dörfler *top, /* highest address+1 in buffer */ 588d5a6048SAxel Dörfler *mark; /* marker (user defined) */ 598d5a6048SAxel Dörfler #ifdef ENCRYPTION 608d5a6048SAxel Dörfler unsigned char *clearto; /* Data to this point is clear text */ 618d5a6048SAxel Dörfler unsigned char *encryyptedto; /* Data is encrypted to here */ 628d5a6048SAxel Dörfler #endif /* ENCRYPTION */ 638d5a6048SAxel Dörfler int size; /* size in bytes of buffer */ 648d5a6048SAxel Dörfler u_long consumetime, /* help us keep straight full, empty, etc. */ 658d5a6048SAxel Dörfler supplytime; 668d5a6048SAxel Dörfler } Ring; 678d5a6048SAxel Dörfler 688d5a6048SAxel Dörfler /* Here are some functions and macros to deal with the ring buffer */ 698d5a6048SAxel Dörfler 708d5a6048SAxel Dörfler /* Initialization routine */ 718d5a6048SAxel Dörfler extern int 728d5a6048SAxel Dörfler ring_init(Ring *ring, unsigned char *buffer, int count); 738d5a6048SAxel Dörfler 748d5a6048SAxel Dörfler /* Data movement routines */ 758d5a6048SAxel Dörfler extern void 768d5a6048SAxel Dörfler ring_supply_data(Ring *ring, unsigned char *buffer, int count); 778d5a6048SAxel Dörfler #ifdef notdef 788d5a6048SAxel Dörfler extern void 798d5a6048SAxel Dörfler ring_consume_data(Ring *ring, unsigned char *buffer, int count); 808d5a6048SAxel Dörfler #endif 818d5a6048SAxel Dörfler 828d5a6048SAxel Dörfler /* Buffer state transition routines */ 838d5a6048SAxel Dörfler extern void 848d5a6048SAxel Dörfler ring_supplied(Ring *ring, int count), 858d5a6048SAxel Dörfler ring_consumed(Ring *ring, int count); 868d5a6048SAxel Dörfler 878d5a6048SAxel Dörfler /* Buffer state query routines */ 888d5a6048SAxel Dörfler extern int 898d5a6048SAxel Dörfler ring_at_mark(Ring *), 908d5a6048SAxel Dörfler ring_empty_count(Ring *ring), 918d5a6048SAxel Dörfler ring_empty_consecutive(Ring *ring), 928d5a6048SAxel Dörfler ring_full_count(Ring *ring), 938d5a6048SAxel Dörfler ring_full_consecutive(Ring *ring); 948d5a6048SAxel Dörfler 958d5a6048SAxel Dörfler #ifdef ENCRYPTION 968d5a6048SAxel Dörfler extern void 978d5a6048SAxel Dörfler ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)), 988d5a6048SAxel Dörfler ring_clearto(Ring *ring); 998d5a6048SAxel Dörfler #endif /* ENCRYPTION */ 1008d5a6048SAxel Dörfler 1018d5a6048SAxel Dörfler extern void 1028d5a6048SAxel Dörfler ring_clear_mark(Ring *), 1038d5a6048SAxel Dörfler ring_mark(Ring *); 104