/*****************************************************************************

 @(#) sdli.h,v 0.7 2000/11/25 07:22:11 brian Exp

 -----------------------------------------------------------------------------

     Copyright (C) 2000  Brian Bidulock.  All Rights Reserved.


                                  PUBLIC LICENSE

     This license is provided without fee, provided that the above copy-
     right notice and this public license must be retained on all copies,
     extracts, compilations and derivative works.  Use or distribution of
     this work in a manner that restricts its use except as provided here
     will render this license void.

     The author(s) hereby waive any and all other restrictions in respect
     of their copyright in this software and its associated documentation.
     The authors(s) of this software place in the public domain any novel
     methods or processes which are embodied in this software.

     The author(s) undertook to write it for the sake of the advancement
     of the Arts and Sciences, but it is provided as is, and the author(s)
     will not take any responsibility in it.

 -----------------------------------------------------------------------------

 Last Modified 2000/11/25 07:22:11 by brian

 sdli.h,v
 Revision 0.7  2000/11/25 07:22:11  brian
 Added SDLI interface below SDTI.

 *****************************************************************************/

#ident @(#) sdli.h,v 0.7 2000/11/25 07:22:11 brian Exp

#ifndef __SDLI_H__
#define __SDLI_H__

/*
 *  The purpose of the SDL interface is to provide separation between the
 *  SDTI (Signalling Data Terminal Interface) which provides SS7 Signalling
 *  Data Terminal (SDT) state machine services including AERM, SUERM and
 *  EIM, and the underlying driver which provides essentially HDLC
 *  capabilities (DAEDR and DAEDT).  The interface utilizes some FISU/LSSU
 *  compression techniques to increase the performance of the interface.
 */

enum {
    /*
     *  Downstream primitive for Local Management Services
     */
    SDL_INFO_REQ,
    SDL_ATTACH_REQ,
    SDL_DETACH_REQ,
    SDL_ENABLE_REQ,
    SDL_DISABLE_REQ,
    /*
     *  Downstream primitives for Protocol Functions
     */
    SDL_BITS_FOR_TRANSMISSION,
    SDL_DAEDT_START_REQ,
    SDL_DAEDR_START_REQ,
    /*
     *  Upstream primitives for Local Management Services
     */
    SDL_INFO_ACK,
    SDL_ENABLE_CON,
    SDL_DISABLE_CON,
    SDL_OK_ACK,
    SDL_ERROR_ACK,
    SDL_ERROR_IND,
    SDL_EVENT_IND,
    /*
     *  Upstream primitives for Protocol Functions
     */
    SDL_RECEIVED_BITS,
    SDL_DAEDR_CORRECT_SU_IND,
    SDL_DAEDR_SU_IN_ERROR_IND,
    SDL_DEADT_TRANSMISSION_IND,

    SDL_USTR_LAST = SDL_TRANSMISSION_IND,
    SDL_DSTR_LAST = SDL_DAEDR_START_REQ
};

/*
 *  SDLI device states
 */
enum {
    SDL_UNATTACHED,
    SDL_UNUSABLE,
    SDL_DISABLED,
    SDL_ENABLE_PENDING,
    SDL_ENABLED,
    SDL_DISABLE_PENDING
};

/*
 *  SDL_ERROR_ACK and SDL_ERROR_IND error return values
 */
enum {
    SDL_UNSPEC,     /* Unknwon or unspecified error */
    SDL_BADFRAME,   /* Defective SDU received       */
    SDL_BADPPA,     /* Invalid PPA identiifer       */
    SDL_BADPRIM,    /* Unrecognized primitive       */
    SDL_BADPARM,    /* Invalid parameter            */
    SDL_DISC,       /* Disconnected                 */
    SDL_EVENT,      /* Protocol-specific event      */
    SDL_FATALERR,   /* Device has become unusable   */
    SDL_INITFAILED, /* Link initialization failed   */
    SDL_NOTSUPP,    /* Primitive not supported      */
    SDL_OUTSTATE,   /* Primitive for invalid state  */
    SDL_PROTOSHORT, /* M_PROTO block too short      */
    SDL_SYSERR,     /* UNIX system error            */
    SDL_WRITEFAIL,  /* Write failed                 */
    SDL_TXFAIL,     /* Transmitter failure          */
    SDL_RXFAIL,     /* Receiver faliure             */
    SDL_TXERROR,    /* Transmitter error            */
    SDL_RXERROR,    /* Receiver error               */
    SDL_NOCARRIER,  /* Carrier failure              */
    SDL_NOGCARRIER  /* Group carrier failure        */
};

/*
 *  Error explanations
 */
enum {
    SDL_CRCERR,     /* CRC or FCS error             */
    SDL_RESIDUE,    /* Resdiue error                */
    SDL_FORMAT,     /* Frame format error detected  */
    SDL_HDLC_ABORT, /* Aborted frame                */
    SDL_LOST_SYNC,  /* Lost flag syncrhonization    */
    SDL_TOO_SHORT,  /* Frame too short              */
    SDL_TOO_LONG,   /* Frame too long               */
    SDL_HDLC_IDLE,  /* HDLC line went idle          */
    SDL_BUSY,       /* Port was busy                */
    SDL_NOANSWER,   /* Connection went unanswered   */
    SDL_CALLREJECT, /* Connection rejected          */
    SDL_DSR_LOST,  ,/* Lost DSR signal              */
    SDL_CTS_LOST    /* Lost CTS signal              */
};

typedef unsigned long  sdl_ulong;
typedef unsigned short sdl_ushort;
typedef unsigned char  sdl_uchar;

/*
 *  SDL_INFO_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_INFO_REQ */
} sdl_info_req_t;

/*
 *  SDL_INFO_ACK, M_PROTO or M_PCPROTO (PPA in M_DATA)
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_INFO_ACK */
    sdl_ulong   sdl_version;    /* SDLI specification version       */
    sdl_ulong   sdl_state;
    sdl_ulong   sdl_max_sdu;
    sdl_ulong   sdl_min_sdu;
    sdl_ulong   sdl_ppa_style;
} sdl_info_ack_t;

#define SDL_STYLE1  0x00    /* PPA is implicitly bound by open(2)       */
#define SDL_STYLE2  0x01    /* PPA explicitly bound via SDL_ATTACH_REQ  */

/*
 *  SDL_ATTACH_REQ, M_PROTO or M_PCPROTO (PPA in M_DATA)
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ATTACH_REQ */
} sdl_attach_req_t;

/*
 *  SDL_DETACH_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DETACH_REQ */
} sdl_detach_req_t;

/*
 *  SDL_ENABLE_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ENABLE_REQ */
    sdl_ulong   sdl_rx_init;
    sdl_ulong   sdl_tx_init;
} sdl_enable_req_t;

/*
 *  SDL_ENABLE_CON, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ENABLE_CON */
    sdl_ulong   sdl_state;
} sdl_enable_con_t;

/*
 *  SDL_DISABLE_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DISABLE_REQ */
    sdl_ulong   sdl_rx_disp;
    sdl_ulong   sdl_tx_disp;
} sdl_disable_req_t;

/*
 *  SDL_DISABLE_CON, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DISABLE_CON */
    sdl_ulong   sdl_state;
} sdl_disable_con_t;

#define SDL_RX_NONE      0xffffffff /* Leave receivers alone    */
#define SDL_RX_OFF       0x00000000 /* Shut down receivers      */
#define SDL_RX_ON        0x00000001 /* only used for state      */
#define SDL_RX_DISABLE   0x00000003 /* Disable receivers        */

#define SDL_TX_NONE      0xffffffff /* Leave transmitters alone */
#define SDL_TX_OFF       0x00000000 /* Shut down transmitters   */
#define SDL_TX_ON        0x00000001 /* only used for state      */
#define SDL_TX_DISABLE   0x00000003 /* Disable transmitters     */
#define SDL_TX_IDLE_MARK 0x00000007 /* Transmitters idle mark   */
#define SDL_TX_IDLE_FLAG 0x00000003 /* Transmitters idle flag   */

/*
 *  SDL_DETACH_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DETACH_REQ */
} sdl_detach_req_t;

/*
 *  SDL_OK_ACK, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_OK_ACK */
    sdl_ulong   sdl_state;
    sdl_ulong   sdl_correct_primitive;
} sdl_ok_ack_t;

/*
 *  SDL_ERROR_ACK, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ERROR_ACK */
    sdl_ulong   sdl_state;
    sdl_ulong   sdl_error_primitive;
    sdl_ulong   sdl_errno;
    sdl_ulong   sdl_reason;
} sdl_error_ack_t;

/*
 *  SDL_ERROR_IND, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ERROR_IND */
    sdl_ulong   sdl_state;
    sdl_ulong   sdl_errno;
    sdl_ulong   sdl_reason;
} sdl_error_ind_t;

/*
 *  SDL_EVENT_IND, M_PROTO or M_PCPROTO (M_DATA)
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_EVENT_IND */
} sdl_event_ind_t;

/*
 *  Service Primitives
 */

/*
 *  SDL_DAEDR_RECEIVED_SU_IND, M_PROTO, M_PCPROTO or M_DATA
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDR_RECEIVED_SU_IND */
    sdl_ulong   sdl_count;
} sdl_daedr_received_su_ind_t;

/*
 *  SDL_DAEDR_START_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDR_START_REQ */
} sdl_daedr_start_req_t;

/*
 *  SDL_DAEDR_CORRECT_SU_IND, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDR_CORRECT_SU_IND */
    sdl_ulong   sdl_count;
} sdl_daedr_correct_su_ind_t;

/*
 *  SDL_DAEDR_SU_IN_ERROR_IND, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDR_SU_IN_ERROR */
    sdl_ulong   sdl_count;
    sdl_ulong   sdl_error;
} sdl_daedr_su_in_error_t;

/*
 *  SDL_DAEDT_START_REQ, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDT_START_REQ */
} sdl_daedt_start_req_t;

/*
 *  SDL_DAEDT_TRANSMISSION_IND, M_PROTO or M_PCPROTO
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_DAEDT_TRANSMISSION_IND */
    sdl_ulong   sdl_hint;
} sdl_daedt_transmission_ind_t;

/*
 *  SDL_DAEDT_TRANSMISSION_REQ, M_PROTO, M_PCPROTO or M_DATA
 */
typedef struct {
    sdl_ulong   sdl_primitive;  /* SDL_ */
    sdl_ulong   sdl_repeat;
} sdl_daedt_transmission_req_t;

union SDL_primitives {
    sdl_ulong                   sdl_primitive;
    sdl_info_req_t                  info_req;
    sdl_info_ack_t                  info_ack;
    sdl_attach_req_t                attach_req;
    sdl_detach_req_t                detach_req;
    sdl_enable_req_t                enable_req;
    sdl_enable_con_t                enable_con;
    sdl_disable_req_t               disable_req;
    sdl_disable_con_t               disable_con;
    sdl_detach_req_t                detach_req;
    sdl_ok_ack_t                    ok_ack;
    sdl_error_ack_t                 error_ack;
    sdl_error_ind_t                 error_ind;
    sdl_event_ind_t                 event_ind;
    sdl_daedr_received_su_ind_t     daedr_received_su_ind;
    sdl_daedr_start_req_t           daedr_start_req;
    sdl_daedr_correct_su_ind_t      daedr_correct_su_ind;
    sdl_daedr_su_in_error_t         daedr_su_in_error;
    sdl_daedt_start_req_t           daedt_start_req;
    sdl_daedt_transmission_ind_t    daedt_transmission_ind;
    sdl_daedt_transmission_req_t    daedt_transmission_req;
};

#define SDL_INFO_REQ_SIZE               sizeof(info_req_t)
#define SDL_INFO_ACK_SIZE               sizeof(info_ack_t)
#define SDL_ATTACH_REQ_SIZE             sizeof(attach_req_t)
#define SDL_DETACH_REQ_SIZE             sizeof(detach_req_t)
#define SDL_ENABLE_REQ_SIZE             sizeof(enable_req_t)
#define SDL_ENABLE_CON_SIZE             sizeof(enable_con_t)
#define SDL_DISABLE_REQ_SIZE            sizeof(disable_req_t)
#define SDL_DISABLE_CON_SIZE            sizeof(disable_con_t)
#define SDL_DETACH_REQ_SIZE             sizeof(detach_req_t)
#define SDL_OK_ACK_SIZE                 sizeof(ok_ack_t)
#define SDL_ERROR_ACK_SIZE              sizeof(error_ack_t)
#define SDL_ERROR_IND_SIZE              sizeof(error_ind_t)
#define SDL_EVENT_IND_SIZE              sizeof(event_ind_t)
#define SDL_DAEDR_RECEIVED_SU_IND_SIZE  sizeof(daedr_received_su_ind_t)
#define SDL_DAEDR_START_REQ_SIZE        sizeof(daedr_start_req_t)
#define SDL_DAEDR_CORRECT_SU_IND_SIZE   sizeof(daedr_correct_su_ind_t)
#define SDL_DAEDR_SU_IN_ERROR_SIZE      sizeof(daedr_su_in_error_t)
#define SDL_DAEDT_START_REQ_SIZE        sizeof(daedt_start_req_t)
#define SDL_DAEDT_TRANSMISSION_IND_SIZE sizeof(daedt_transmission_ind_t)
#define SDL_DAEDT_TRANSMISSION_REQ_SIZE sizeof(daedt_transmission_req_t)

#endif  __SDLI_H__
