Annotation of 43BSDReno/contrib/isode-beta/h/tpkt.h, revision 1.1

1.1     ! root        1: /* tpkt.h - include file for transport providers (TS-PROVIDER) */
        !             2: 
        !             3: /* 
        !             4:  * $Header: /f/osi/h/RCS/tpkt.h,v 7.3 90/07/27 08:44:50 mrose Exp $
        !             5:  *
        !             6:  *
        !             7:  * $Log:       tpkt.h,v $
        !             8:  * Revision 7.3  90/07/27  08:44:50  mrose
        !             9:  * update
        !            10:  * 
        !            11:  * Revision 7.2  90/03/23  17:30:54  mrose
        !            12:  * 8
        !            13:  * 
        !            14:  * Revision 7.1  89/12/07  01:07:57  mrose
        !            15:  * queued writes
        !            16:  * 
        !            17:  * Revision 7.0  89/11/23  21:56:07  mrose
        !            18:  * Release 6.0
        !            19:  * 
        !            20:  */
        !            21: 
        !            22: /*
        !            23:  *                               NOTICE
        !            24:  *
        !            25:  *    Acquisition, use, and distribution of this module and related
        !            26:  *    materials are subject to the restrictions of a license agreement.
        !            27:  *    Consult the Preface in the User's Manual for the full terms of
        !            28:  *    this agreement.
        !            29:  *
        !            30:  */
        !            31: 
        !            32: 
        !            33: #include "tsap.h"              /* definitions for TS-USERs */
        !            34: 
        !            35: /*  */
        !            36: 
        !            37: 
        !            38: #define        tsapPsig(tb, sd) \
        !            39: { \
        !            40:     if ((tb = findtblk (sd)) == NULL) { \
        !            41:        (void) sigiomask (smask); \
        !            42:        return tsaplose (td, DR_PARAMETER, NULLCP, \
        !            43:                            "invalid transport descriptor"); \
        !            44:     } \
        !            45:     if (!(tb -> tb_flags & TB_CONN)) { \
        !            46:        (void) sigiomask (smask); \
        !            47:        return tsaplose (td, DR_OPERATION, NULLCP, \
        !            48:                            "transport descriptor not connected"); \
        !            49:     } \
        !            50: }
        !            51: 
        !            52: #define        missingP(p) \
        !            53: { \
        !            54:     if (p == NULL) \
        !            55:        return tsaplose (td, DR_PARAMETER, NULLCP, \
        !            56:                            "mandatory parameter \"%s\" missing", "p"); \
        !            57: }
        !            58: 
        !            59: #define        toomuchP(b,n,m,p) \
        !            60: { \
        !            61:     if (b == NULL) \
        !            62:        n = 0; \
        !            63:     else \
        !            64:        if (n > m) \
        !            65:            return tsaplose (td, DR_PARAMETER, NULLCP, \
        !            66:                            "too much %s user data, %d octets", p, n); \
        !            67: }
        !            68: 
        !            69: #define        copyTPKTdata(t,base,len) \
        !            70: { \
        !            71:     register struct udvec *uv = t -> t_udvec; \
        !            72:     if (len > 0) \
        !            73:        uv -> uv_base = base, uv -> uv_len = len, uv++; \
        !            74:     uv -> uv_base = NULL; \
        !            75: }
        !            76: 
        !            77: #ifndef        lint
        !            78: #ifndef        __STDC__
        !            79: #define        copyTSAPdata(base,len,d) \
        !            80: { \
        !            81:     register int i = len; \
        !            82:     if ((d -> d/* */_cc = min (i, sizeof d -> d/* */_data)) > 0) \
        !            83:        bcopy (base, d -> d/* */_data, d -> d/* */_cc); \
        !            84: }
        !            85: #else
        !            86: #define        copyTSAPdata(base,len,d) \
        !            87: { \
        !            88:     register int i = len; \
        !            89:     if ((d -> d##_cc = min (i, sizeof d -> d##_data)) > 0) \
        !            90:        bcopy (base, d -> d##_data, d -> d##_cc); \
        !            91: }
        !            92: #endif
        !            93: #else
        !            94: #define        copyTSAPdata(base,len,d)        bcopy (base, (char *) d, len)
        !            95: #endif
        !            96: 
        !            97: 
        !            98: int    tpktlose (), tsaplose ();
        !            99: 
        !           100: /*  */
        !           101: 
        !           102: struct tsapADDR {
        !           103:     struct NSAPaddr ta_addr;
        !           104:     int            ta_present;
        !           105: 
        !           106:     int            ta_selectlen;
        !           107:     
        !           108:     union {
        !           109:        char    ta_un_selector[TSSIZE];
        !           110: 
        !           111:        u_short ta_un_port;
        !           112:     }          un_ta;
        !           113: };
        !           114: 
        !           115:                                /* network type codes:
        !           116:                                        must be outside [0-9A-Fa-f] */
        !           117: #define        NT_TCP  'T'             /* TCP */
        !           118: #define        NT_X25  'X'             /* X.25 */
        !           119: #define        NT_BRG  'G'             /* Bridge */
        !           120: #define        NT_BSD  'Z'             /* 4.4BSD */
        !           121: #define        NT_SUN  'S'             /* SunLink OSI */
        !           122: 
        !           123: 
        !           124: struct tsapblk {
        !           125:     struct tsapblk *tb_forw;   /* doubly-linked list */
        !           126:     struct tsapblk *tb_back;   /*   .. */
        !           127: 
        !           128:     int     tb_fd;             /* file descriptor */
        !           129: 
        !           130:     char    tb_flags;          /* our state */
        !           131: #define        TB_NULL         0x00
        !           132: #define        TB_CONN         0x01    /* connected */
        !           133: #define        TB_ASYN         0x02    /* asynchronous */
        !           134: #define        TB_EXPD         0x04    /* expedited transfer selected */
        !           135: #define        TB_TCP          0x08    /* underlying service is TCP */
        !           136: #define        TB_X25          0x10    /*   ..               is X.25 */
        !           137: #define TB_BRG         0x20    /*   ..               is Bridge */
        !           138: #define        TB_TP0          (TB_TCP | TB_X25 | TB_BRG)
        !           139: #define        TB_TP4          0x40    /*   ..               is TP4 */
        !           140:                                /* all TP4's use this value as it make
        !           141:                                   sense to have only one TP4 service
        !           142:                                   compiled in... */
        !           143: #define        TB_QWRITES      0x80    /* queued writes OK */
        !           144: 
        !           145:     char   *tb_magic;          /* generic pointer */
        !           146: 
        !           147:                                /* saved retry variables */
        !           148:     char  *tb_data;            /* saved user data */
        !           149:     int    tb_cc;              /* saved user data count */
        !           150:     char   tb_expedited;       /* saved expedited */
        !           151:     struct TSAPaddr *tb_called;        /* saved addresses */
        !           152:     struct TSAPaddr *tb_calling;/*   .. */
        !           153: 
        !           154:     struct tsapkt *tb_retry;   /* initial tpkt */
        !           155: 
        !           156:     u_short tb_srcref;         /* source reference */
        !           157:     u_short tb_dstref;         /* destination reference */
        !           158: 
        !           159:     int            tb_tsdusize;        /* maximum TSDU size */
        !           160:     int            tb_tpduslop;        /*   .. */
        !           161:     int            tb_tpdusize;        /* for tp0ts */
        !           162: 
        !           163:     int            tb_sent;            /* TPDU bytes sent */
        !           164:     int            tb_recv;            /* TPDU bytes recv */
        !           165: 
        !           166:     struct QOStype tb_qos;     /* quality of service */
        !           167: 
        !           168:     struct qbuf tb_qbuf;       /* for segmented TSDUs */
        !           169:     int            tb_len;             /*   .. */
        !           170:     
        !           171:     struct tsapADDR tb_initiating;/* initiator */
        !           172:     struct tsapADDR tb_responding;/* responder */
        !           173: 
        !           174:     IFP            tb_retryfnx;        /* resume async connection */
        !           175: 
        !           176:     IFP            tb_connPfnx;        /* TP connect */
        !           177:     IFP            tb_retryPfnx;       /* TP retry connect */
        !           178:     IFP            tb_startPfnx;       /* TP start accept */
        !           179:     IFP            tb_acceptPfnx;      /* TP accept */
        !           180:     IFP            tb_writePfnx;       /* TP write data */
        !           181:     IFP            tb_readPfnx;        /* TP read data */
        !           182:     IFP            tb_discPfnx;        /* TP disconnect */
        !           183:     IFP            tb_losePfnx;        /* TP loses */
        !           184: 
        !           185:     IFP            tb_drainPfnx;       /* TP drain queued writes */
        !           186:     IFP            tb_queuePfnx;       /* TP note queued writes */
        !           187:     struct qbuf tb_qwrites;    /* queue of writes to retry */
        !           188: 
        !           189:     IFP            tb_initfnx;         /* init for read from network */
        !           190:     IFP            tb_readfnx;         /* read from network */
        !           191:     IFP            tb_writefnx;        /* write to network */
        !           192:     IFP            tb_closefnx;        /* close network */
        !           193:     IFP            tb_selectfnx;       /* select network */
        !           194:     IFP            tb_checkfnx;        /* check network prior to select */
        !           195:     IFP            tb_nreadfnx;        /* estimate of octets waiting to be read */
        !           196: 
        !           197:     IFP            tb_DataIndication;  /* INDICATION handlers */
        !           198:     IFP     tb_DiscIndication; /*   .. */
        !           199: 
        !           200: #ifdef  MGMT
        !           201:     IFP     tb_manfnx;          /* for management reports */
        !           202:     int     tb_pdus;            /* PDUs sent */
        !           203:     int     tb_pdur;            /* PDUs recv */
        !           204:     int     tb_bytes;           /* bytes sent since last report */
        !           205:     int     tb_byter;           /* bytes recv        ..         */
        !           206: #endif
        !           207: };
        !           208: #define        NULLBP          ((struct tsapblk *) 0)
        !           209: 
        !           210: 
        !           211: int    freetblk ();
        !           212: struct tsapblk *newtblk (), *findtblk ();
        !           213: 
        !           214: /*    TPKT datastructure */
        !           215: 
        !           216: struct tsapkt {
        !           217:     int                t_errno;
        !           218: 
        !           219:     struct {
        !           220:        u_char    pk_vrsn;
        !           221: #define        TPKT_VRSN       3
        !           222: 
        !           223:        u_char    pk_rsrvd;
        !           224: 
        !           225:        u_short   pk_length;
        !           226: #define        TPKT_MAXLEN     0xffff
        !           227:     }       t_pkthdr;
        !           228: #define        t_vrsn          t_pkthdr.pk_vrsn
        !           229: #define        t_rsrvd         t_pkthdr.pk_rsrvd
        !           230: #define        t_length        t_pkthdr.pk_length
        !           231: 
        !           232: #define TPKT_HDRLEN(t) (sizeof ((t) -> t_pkthdr) + sizeof ((t) -> t_li) \
        !           233:                            + sizeof ((t) -> t_code))
        !           234: 
        !           235:     struct {
        !           236:        u_char    tp_li;
        !           237: #ifndef        lint
        !           238: #ifndef        __STDC__
        !           239: #define        TPDU_MINLEN(t,c)        (c/* */_SIZE(t) + sizeof ((t) -> t_code))
        !           240: #else
        !           241: #define        TPDU_MINLEN(t,c)        (c##_SIZE(t) + sizeof ((t) -> t_code))
        !           242: #endif
        !           243: #else
        !           244: #define        TPDU_MINLEN(t,c)        (sizeof ((t) -> t_code))
        !           245: #endif
        !           246: #define        TPDU_MAXLEN(t)  \
        !           247:        (min (0xfe, (t) -> t_length - sizeof ((t) -> t_pkthdr) \
        !           248:                                    - sizeof ((t) -> t_li)))
        !           249: #define        TPDU_USRLEN(t)  \
        !           250:        ((t) -> t_length - sizeof ((t) -> t_pkthdr) \
        !           251:                         - sizeof ((t) -> t_li) - (t) -> t_li)
        !           252: 
        !           253:        u_char    tp_code;
        !           254: #define        TPDU_CODE(t)    ((t) -> t_code & 0xf0)
        !           255: #define        TPDU_CR         0xe0    /* CONNECTION REQUEST */
        !           256: #define        TPDU_CC         0xd0    /* CONNECTION CONFIRMATION */
        !           257: #define        TPDU_DR         0x80    /* DISCONNECT REQUEST */
        !           258: #define        TPDU_DC         0xc0    /* DISCONNECT CONFIRMATION */
        !           259: #define        TPDU_DT         0xf0    /* DATA */
        !           260: #define        TPDU_ED         0x10    /* EXPEDITED DATA */
        !           261: #define        TPDU_AK         0x60    /* ACKNOWLEDGE */
        !           262: #define        TPDU_EA         0x20    /* EXPEDITED ACKNOWLEDGE */
        !           263: #define        TPDU_RJ         0x50    /* REJECT */
        !           264: #define        TPDU_ER         0x70    /* ERROR */
        !           265: 
        !           266:        union {
        !           267:            struct {
        !           268:                                /* FIXED part */
        !           269:                u_short   un_cr_dstref;
        !           270:                u_short   un_cr_srcref;
        !           271: 
        !           272:                u_char    un_cr_class;
        !           273: #define        CR_CLASS(t)     ((t) -> t_cr.cr_class & 0xf0)
        !           274: #define        CR_CLASS_TP0    0x00    /* class 0 */
        !           275: #define        CR_CLASS_TP1    0x10    /*   ..  1 */
        !           276: #define        CR_CLASS_TP2    0x20    /*   ..  2 */
        !           277: #define        CR_CLASS_TP3    0x30    /*   ..  3 */
        !           278: #define        CR_CLASS_TP4    0x40    /*   ..  4 */
        !           279: #define        CR_OPT_EXTD     0x02    /* extended formats in classes 2-4 */
        !           280: #define        CR_OPT_EXPL     0x01    /* explicit flow control in class 2 */
        !           281: 
        !           282:                                /* VARIABLE part */
        !           283:                char      un_cr_called[TSSIZE];
        !           284:                int       un_cr_calledlen;
        !           285:                
        !           286:                char      un_cr_calling[TSSIZE];
        !           287:                int       un_cr_callinglen;
        !           288: 
        !           289:                u_char    un_cr_tpdusize;
        !           290: 
        !           291:                u_short   un_cr_options;
        !           292: 
        !           293:                u_char    un_cr_alternate;
        !           294:            }       un_cr;
        !           295: #define        cr_dstref       un_cr_dstref
        !           296: #define        cr_srcref       un_cr_srcref
        !           297: #define        cr_class        un_cr_class
        !           298: #define        cr_tpdusize     un_cr_tpdusize
        !           299: #define        cr_options      un_cr_options
        !           300: #define        cr_alternate    un_cr_alternate
        !           301: #define        CR_SIZE(t)      5
        !           302: 
        !           303: #define        un_cc           un_cr
        !           304: #define        cc_dstref       un_cr_dstref
        !           305: #define        cc_srcref       un_cr_srcref
        !           306: #define        cc_class        un_cr_class
        !           307: #define        cc_tpdusize     un_cr_tpdusize
        !           308: #define        cc_options      un_cr_options
        !           309: #define        CC_SIZE(t)      5
        !           310: 
        !           311:            struct {
        !           312:                                /* FIXED part */
        !           313:                u_short   un_dr_dstref;
        !           314:                u_short   un_dr_srcref;
        !           315:                u_char    un_dr_reason;
        !           316:            }       un_dr;
        !           317: #define        dr_dstref       un_dr_dstref
        !           318: #define        dr_srcref       un_dr_srcref
        !           319: #define        dr_reason       un_dr_reason
        !           320: #define        DR_SIZE(t)      5
        !           321: 
        !           322:            struct {
        !           323:                                /* FIXED part */
        !           324:                u_char   un_dt_nr;
        !           325: #define        DT_EOT          0x80
        !           326:            }       un_dt;
        !           327: #define        dt_nr           un_dt_nr
        !           328: #define        DT_SIZE(t)      1
        !           329: #define        DT_MAGIC        (2 + 1)
        !           330: 
        !           331: /* Expedited service is not allowed in TP0, but for testing purposes,
        !           332:    we permit it when the underlying service is TCP.  Note we use a
        !           333:    non-standard packet format (identical to the DT format).
        !           334:  */
        !           335: #define        un_ed           un_dt
        !           336: #define        ed_nr           un_dt_nr
        !           337: #define        ED_SIZE(t)      1
        !           338: 
        !           339:            struct {
        !           340:                                /* FIXED part */
        !           341:                u_short    un_er_dstref;
        !           342:                u_char     un_er_reject;
        !           343: #define        ER_REJ_NOTSPECIFIED     0x00    /* Reason not specified */
        !           344: #define        ER_REJ_CODE             0x01    /* Invalid parameter code */
        !           345: #define        ER_REJ_TPDU             0x02    /* Invalid TPDU type */
        !           346: #define        ER_REJ_VALUE            0x03    /* Invalid parameter value */
        !           347:            }       un_er;
        !           348: #define        er_dstref       un_er_dstref
        !           349: #define        er_reject       un_er_reject
        !           350: #define        ER_SIZE(t)      3
        !           351:        }       tp_un;
        !           352: #define        tp_cr           tp_un.un_cr
        !           353: #define        tp_cc           tp_un.un_cc
        !           354: #define        tp_dr           tp_un.un_dr
        !           355: #define        tp_dt           tp_un.un_dt
        !           356: #define        tp_ed           tp_un.un_ed
        !           357: #define        tp_er           tp_un.un_er
        !           358: 
        !           359:        int             tp_vlen;
        !           360:        char           *tp_vbase;
        !           361: 
        !           362:        struct qbuf    *tp_qbuf;        /* fd2tpkt ONLY */
        !           363: 
        !           364: #define        NTPUV           12              /* really should be
        !           365:                                                MSG_MAXIOVLEN - 4 */
        !           366:        struct udvec tp_udvec[NTPUV];   /* tpkt2fd ONLY */
        !           367:     }               t_tpdu;
        !           368: #define        t_li            t_tpdu.tp_li
        !           369: #define        t_code          t_tpdu.tp_code
        !           370: #define        t_cr            t_tpdu.tp_un.un_cr
        !           371: #define        t_called        t_tpdu.tp_un.un_cr.un_cr_called
        !           372: #define        t_calledlen     t_tpdu.tp_un.un_cr.un_cr_calledlen
        !           373: #define        t_calling       t_tpdu.tp_un.un_cr.un_cr_calling
        !           374: #define        t_callinglen    t_tpdu.tp_un.un_cr.un_cr_callinglen
        !           375: #define        t_tpdusize      t_tpdu.tp_un.un_cr.un_cr_tpdusize
        !           376: #define        t_options       t_tpdu.tp_un.un_cr.un_cr_options
        !           377: #define        t_alternate     t_tpdu.tp_un.un_cr.un_cr_alternate
        !           378: #define        t_cc            t_tpdu.tp_un.un_cc
        !           379: #define        t_dr            t_tpdu.tp_un.un_dr
        !           380: #define        t_dt            t_tpdu.tp_un.un_dt
        !           381: #define        t_ed            t_tpdu.tp_un.un_ed
        !           382: #define        t_er            t_tpdu.tp_un.un_er
        !           383: 
        !           384: #define        t_vdata         t_tpdu.tp_vbase
        !           385: #define        t_vlen          t_tpdu.tp_vlen
        !           386: 
        !           387: #define        t_qbuf          t_tpdu.tp_qbuf
        !           388: 
        !           389: #define        t_udvec         t_tpdu.tp_udvec
        !           390: };
        !           391: #define        NULLPKT         ((struct tsapkt *) 0)
        !           392: 
        !           393: 
        !           394: int    freetpkt ();
        !           395: struct tsapkt *newtpkt ();
        !           396: 
        !           397: void   text2tpkt (), tpkt2text ();
        !           398: 
        !           399: int    tpkt2fd ();
        !           400: struct tsapkt  *fd2tpkt ();
        !           401: 
        !           402: char   *tpkt2str ();
        !           403: struct tsapkt  *str2tpkt ();
        !           404: 
        !           405: /*    VARIABLE DATA codes, from ISO8073: */
        !           406: 
        !           407:                                        /* for CR/CC TPDUs */
        !           408: #define        VDAT_TSAP_SRV   0xc2            /* TSAP ID of the calling TSAP */
        !           409: #define        VDAT_TSAP_CLI   0xc1            /* TSAP ID of the called TSAP */
        !           410: #define        VDAT_SIZE       0xc0            /* TPDU SIZE */
        !           411: #define          SIZE_8K       0x0d            /*   8192 */
        !           412: #define          SIZE_4K       0x0c            /*   4096 */
        !           413: #define          SIZE_2K       0x0b            /*   2048 */
        !           414: #define          SIZE_1K       0x0a            /*   1024 */
        !           415: #define          SIZE_512      0x09            /*    512 */
        !           416: #define          SIZE_256      0x08            /*    256 */
        !           417: #define          SIZE_128      0x07            /*    128 */
        !           418: #define          SIZE_DFLT     SIZE_128
        !           419: #define          SIZE_MAXTP0   SIZE_2K
        !           420: #define        VDAT_VRSN       0xc4            /* Version number */
        !           421: #define        VDAT_SECURITY   0xc5            /* Security parameters */
        !           422: #define        VDAT_CHECKSUM   0xc3            /* Checksum */
        !           423: #define        VDAT_OPTIONS    0xc6            /* Additional option selections */
        !           424: #define          OPT_NEXPEDITE 0x08            /*     Use network expedited */
        !           425: #define          OPT_CONFIRM   0x04            /*     Use receipt confirmation */
        !           426: #define          OPT_CHECKSUM  0x02            /*     Use 16-bit checksum */
        !           427: #define          OPT_TEXPEDITE 0x01            /*     Use transport expedited */
        !           428: #define        VDAT_ALTERNATE  0xc7            /* Alterated protocol class(es) */
        !           429: #define          ALT_TP0         0x01          /*     class 0 */
        !           430: #define          ALT_TP1         0x02          /*     class 1 */
        !           431: #define          ALT_TP2         0x04          /*     class 2 */
        !           432: #define          ALT_TP3         0x08          /*     class 3 */
        !           433: #define          ALT_TP4         0x10          /*     class 4 */
        !           434: #define        VDAT_ACKTIME    0x85            /* Acknowledge time */
        !           435: #define        VDAT_THROUGHPUT 0x89            /* Throughput */
        !           436: #define        VDAT_ERRORATE   0x86            /* Residual error rate */
        !           437: #define        VDAT_PRIORITY   0x87            /* Priority */
        !           438: #define        VDAT_DELAY      0x88            /* Transit delay */
        !           439: #define        VDAT_TTR        0x8b            /* Reassignment time */
        !           440: 
        !           441:                                        /* for DR TPDUs */
        !           442: #define        VDAT_ADDITIONAL 0xe0            /* Additional information */
        !           443: 
        !           444:                                        /* for AK TPDUs */
        !           445: #define        VDAT_SUBSEQ     0x8c            /* Sub-sequence number */
        !           446: #define        VDAT_FLOWCTL    0x8b            /* Flow control confirmation */
        !           447: 
        !           448:                                        /* for ER TPDUs */
        !           449: #define        VDAT_INVALID    0xc1            /* invalid TPDU */
        !           450: 
        !           451: /*  */
        !           452: 
        !           453: /* TP0 is the protocol */
        !           454: 
        !           455: int    tp0init ();
        !           456: int    tp0write ();
        !           457: 
        !           458: 
        !           459: /* TCP is NS-provider */
        !           460: 
        !           461: int    tcpopen ();
        !           462: 
        !           463: char   *tcpsave ();
        !           464: int    tcprestore ();
        !           465: 
        !           466: 
        !           467: /* X.25 is NS-provider */
        !           468: 
        !           469: int    x25open ();
        !           470: 
        !           471: char   *x25save ();
        !           472: int    x25restore ();
        !           473: 
        !           474: 
        !           475: /* Bridge is NS-provider */
        !           476: 
        !           477: int    bridgeopen ();
        !           478: int    bridgediscrim ();
        !           479: 
        !           480: char   *bridgesave ();
        !           481: int    bridgerestore ();
        !           482: 
        !           483: 
        !           484: /* TP4 is the protocol and the TS-provider */
        !           485: 
        !           486: int    tp4init ();
        !           487: 
        !           488: int    tp4open ();
        !           489: 
        !           490: char   *tp4save ();
        !           491: int    tp4restore ();

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.