
/*****************************************************************************
* Copyright (c) 2008 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/

#ifndef TRUSERQUEUE_H
#define TRUSERQUEUE_H

/* 
 * This header file describes some fairly generic user queue functions that 
 * interact with packets of type ttPacket(Ptr). 
 * It is stolen rather directly from the trbypass source, but renamed for
 * generic use. The functions are intended for use by drivers that
 * interact directly with the treck stack, and have need to link packets
 * using fields (such as pktChainDataPtr) inside ttPacket.
 * The first user of these functions is the ethernet to wifi bridge.
 */

#ifdef __cplusplus
extern "C" {
#endif

/*
 *  Required Includes
 */

#include <trsocket.h>
#include <trmacro.h>
#include <trtype.h>
#include <trproto.h>


typedef struct
{
    ttPacketPtr head;
    ttPacketPtr tail;
    unsigned    cnt;

} tfUserQueue;

/*
 * Initialize a user queue 
 */
int tfUserQueueInit(tfUserQueue * pq);

/*
 * Add a packet to a user queue 
 */
int tfUserQueueAdd(tfUserQueue * pq, ttPacketPtr packet);

/*
 * Remove a packet from a user queue 
 */
ttPacketPtr tfUserQueueRemove(tfUserQueue * pq);

/*
 * Find a packet in a user queue and remove it.
 */
ttPacketPtr tfUserQueueRemovePacket(tfUserQueue * pq, ttPacketPtr packet);

/*
 * Get pointer and size of a data buffer
 */
int tfGetUserPacketDataBufferPtr(ttPacketPtr packet, char ** buffer_ptr, unsigned * length);

/*
 * Get link data pointer and size 
 */
int tfGetUserPacketDataPtr(ttPacketPtr packet, char ** buffer_ptr, unsigned * length);

/*
 * Store link data pointer and size 
 */
int tfStoreUserPacketDataPtr(ttPacketPtr packet, char * data_ptr, unsigned length);

/*
 * Lock device entry the way Treck does it, before calling device driver functions
 */
void tfUserLockDevice(ttUserInterface interfaceHandle);

/*
 * Unlock device entry.
 */
void tfUserUnlockDevice(ttUserInterface interfaceHandle);

/*
 * Set packet's device entry pointer and a user callback
 */
void tfSetUserPacketUserCallback(ttPacketPtr packet, 
                                   ttUserFreeFuncPtr user_fn);

ttUserFreeFuncPtr tfGetUserPacketUserCallback(ttPacketPtr packet);

void tfSetUserPacketDevicePtr(ttPacketPtr packet, 
                             struct tsDeviceEntry *p_dev_entry);

#ifdef __cplusplus
}
#endif

#endif /* TRUSERQUEUE_H */
