181cb6ddcSMark Murray /* 281cb6ddcSMark Murray * Copyright (c) 1988, 1993 381cb6ddcSMark Murray * The Regents of the University of California. All rights reserved. 481cb6ddcSMark Murray * 581cb6ddcSMark Murray * Redistribution and use in source and binary forms, with or without 681cb6ddcSMark Murray * modification, are permitted provided that the following conditions 781cb6ddcSMark Murray * are met: 881cb6ddcSMark Murray * 1. Redistributions of source code must retain the above copyright 981cb6ddcSMark Murray * notice, this list of conditions and the following disclaimer. 1081cb6ddcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright 1181cb6ddcSMark Murray * notice, this list of conditions and the following disclaimer in the 1281cb6ddcSMark Murray * documentation and/or other materials provided with the distribution. 1381cb6ddcSMark Murray * 3. All advertising materials mentioning features or use of this software 1481cb6ddcSMark Murray * must display the following acknowledgement: 1581cb6ddcSMark Murray * This product includes software developed by the University of 1681cb6ddcSMark Murray * California, Berkeley and its contributors. 1781cb6ddcSMark Murray * 4. Neither the name of the University nor the names of its contributors 1881cb6ddcSMark Murray * may be used to endorse or promote products derived from this software 1981cb6ddcSMark Murray * without specific prior written permission. 2081cb6ddcSMark Murray * 2181cb6ddcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2281cb6ddcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2381cb6ddcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2481cb6ddcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2581cb6ddcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2681cb6ddcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2781cb6ddcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2881cb6ddcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2981cb6ddcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3081cb6ddcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3181cb6ddcSMark Murray * SUCH DAMAGE. 3281cb6ddcSMark Murray * 3381cb6ddcSMark Murray * @(#)ring.h 8.1 (Berkeley) 6/6/93 3421f083c0SMark Murray * $FreeBSD$ 3581cb6ddcSMark Murray */ 3681cb6ddcSMark Murray 3781cb6ddcSMark Murray #if defined(P) 3881cb6ddcSMark Murray # undef P 3981cb6ddcSMark Murray #endif 4081cb6ddcSMark Murray 4181cb6ddcSMark Murray #if defined(__STDC__) || defined(LINT_ARGS) 4281cb6ddcSMark Murray # define P(x) x 4381cb6ddcSMark Murray #else 4481cb6ddcSMark Murray # define P(x) () 4581cb6ddcSMark Murray #endif 4681cb6ddcSMark Murray 4781cb6ddcSMark Murray /* 4881cb6ddcSMark Murray * This defines a structure for a ring buffer. 4981cb6ddcSMark Murray * 5081cb6ddcSMark Murray * The circular buffer has two parts: 5181cb6ddcSMark Murray *((( 5281cb6ddcSMark Murray * full: [consume, supply) 5381cb6ddcSMark Murray * empty: [supply, consume) 5481cb6ddcSMark Murray *]]] 5581cb6ddcSMark Murray * 5681cb6ddcSMark Murray */ 5781cb6ddcSMark Murray typedef struct { 5881cb6ddcSMark Murray unsigned char *consume, /* where data comes out of */ 5981cb6ddcSMark Murray *supply, /* where data comes in to */ 6081cb6ddcSMark Murray *bottom, /* lowest address in buffer */ 6181cb6ddcSMark Murray *top, /* highest address+1 in buffer */ 6281cb6ddcSMark Murray *mark; /* marker (user defined) */ 6381cb6ddcSMark Murray #ifdef ENCRYPTION 6481cb6ddcSMark Murray unsigned char *clearto; /* Data to this point is clear text */ 6581cb6ddcSMark Murray unsigned char *encryyptedto; /* Data is encrypted to here */ 6681cb6ddcSMark Murray #endif /* ENCRYPTION */ 6781cb6ddcSMark Murray int size; /* size in bytes of buffer */ 6881cb6ddcSMark Murray u_long consumetime, /* help us keep straight full, empty, etc. */ 6981cb6ddcSMark Murray supplytime; 7081cb6ddcSMark Murray } Ring; 7181cb6ddcSMark Murray 7281cb6ddcSMark Murray /* Here are some functions and macros to deal with the ring buffer */ 7381cb6ddcSMark Murray 7481cb6ddcSMark Murray /* Initialization routine */ 7581cb6ddcSMark Murray extern int 763138440aSMark Murray ring_init(Ring *ring, unsigned char *buffer, int count); 7781cb6ddcSMark Murray 7881cb6ddcSMark Murray /* Data movement routines */ 7981cb6ddcSMark Murray extern void 803138440aSMark Murray ring_supply_data(Ring *ring, unsigned char *buffer, int count); 8181cb6ddcSMark Murray #ifdef notdef 8281cb6ddcSMark Murray extern void 833138440aSMark Murray ring_consume_data(Ring *ring, unsigned char *buffer, int count); 8481cb6ddcSMark Murray #endif 8581cb6ddcSMark Murray 8681cb6ddcSMark Murray /* Buffer state transition routines */ 8781cb6ddcSMark Murray extern void 883138440aSMark Murray ring_supplied(Ring *ring, int count), 893138440aSMark Murray ring_consumed(Ring *ring, int count); 9081cb6ddcSMark Murray 9181cb6ddcSMark Murray /* Buffer state query routines */ 9281cb6ddcSMark Murray extern int 933138440aSMark Murray ring_at_mark(Ring *), 943138440aSMark Murray ring_empty_count(Ring *ring), 953138440aSMark Murray ring_empty_consecutive(Ring *ring), 963138440aSMark Murray ring_full_count(Ring *ring), 973138440aSMark Murray ring_full_consecutive(Ring *ring); 9881cb6ddcSMark Murray 9981cb6ddcSMark Murray #ifdef ENCRYPTION 10081cb6ddcSMark Murray extern void 1013138440aSMark Murray ring_encrypt(Ring *ring, void (*func)(unsigned char *, int)), 1023138440aSMark Murray ring_clearto(Ring *ring); 10381cb6ddcSMark Murray #endif /* ENCRYPTION */ 10481cb6ddcSMark Murray 10581cb6ddcSMark Murray extern void 1063138440aSMark Murray ring_clear_mark(Ring *), 1073138440aSMark Murray ring_mark(Ring *); 108