Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought



  tp4(7)                              CLIX                              tp4(7)



  NAME

    tp4 - ISO/OSI Transport Layer Class 4 Protocol/Internetwork Protocol
    STREAMS multiplexer driver

  DESCRIPTION

    The tp4 driver is a ``cloneable'' (see clone) STREAMS multiplexing driver
    that provides the services of the ISO/OSI transport layer class 4 and ISO
    Internetwork Protocol (IP).

    The tp4 driver communicates using the AT&T Transport Provider Interface
    (TPI).  Using TPI allows applications to interface with tp4 using the AT&T
    Transport Layer Interface (TLI).  The driver provides the TLI network
    service type T_COTS, a connection-oriented protocol service without
    orderly release.  The tp4 transport protocols and connectionless network
    procotols (clnp) reside within the tp4 multiplexing driver.

    The tp4/clnp should be linked above the dlpi STREAMS driver that has been
    bound to the Logical Link Class 1 (LLC1) Link Service Access Point (LSAP)
    (such as 0xFE) to provide the tp4/clnp/llc1 functionality in accordance
    with US GOSIP version 1.  The incd daemon performs this binding at boot
    time.

    The tp4 address is represented in the following structure type:

    struct netbuf {
         unsigned maxlen;
         unsigned len;
         char *buf;
    };

    The maxlen member in the above should be greater or equal to the number of
    bytes in buf.  The len member should be the number of bytes in buf.

    The buf member should point to one of the following transport address
    types depending on the TLI call used:

    This structure is used in the t_bind() request:

    typedef struct {
         unsigned len;           /* length of address field */
         unsigned char addr[32]; /* the address field */
    } tsap_selector;

    typedef struct {
         unsigned len;           /* length of address field */
         unsigned char addr[20]; /* binary representation of address */
    } nsap_address;

    This structure is specified in the t_connect() request and returned in the



  2/94 - Intergraph Corporation                                              1






  tp4(7)                              CLIX                              tp4(7)



    t_listen() call:

    typedef struct {
         tsap_selector tsap; /* Transport SAP ID */
         nsap_address  nsap; /* Network SAP address */
    } tsap_address;

    The following functions can be invoked when using the tp4 interface:

    The t_open() function creates a logical device for the user to communicate
    with the local tp4 entity.  The user should specify /dev/tp4 as the device
    name when using t_open().

    The t_bind() function informs tp4 of the local tsap selector to be
    associated with the stream.  The t_bind() request contains tsap_selector
    in the address specification.

    The t_unbind() function disassociates a transport endpoint created by
    t_bind().

    The t_close() function closes the logical device associated with the tp4
    endpoint created by calling t_open().

    The t_getinfo() function works as specified in TLI and TPI.

    The t_connect() function opens a transport connection with a remote
    entity.  The t_connect() function contains the tsap_address in the address
    specification.

    The t_listen() function waits for a connection indication from a remote
    tp4 entity.  This function returns a tsap_address in the address
    specification.

    The t_accept() function accepts a connection indication from a remote
    entity.

    The t_snd() function sends normal or expedited data through an established
    tp4 connection.

    The t_rcv() function receives normal or expedited data from an established
    tp4 connection.  If the T_MORE flag is set, the user needs to issue
    another t_rcv() function to receive the remainder of a packet.

    The t_snddis() function uses the first longword in the udata field of the
    t_call() argument to t_snddis() to specify one of the following values as
    the disconnect reason:

    1     Congestion at tsap.

    2     Session entity not attached to tsap.




  2                                              Intergraph Corporation - 2/94






  tp4(7)                              CLIX                              tp4(7)



    128   Normal disconnect initiated by session entity.

    133   Protocol error.

    The t_rcvdis() function receives an indication that the remote tp4 entity
    rejected a proposed connection or simply aborted the connection.

  EXAMPLES

    1.  The following example is an example of a server program:

        #include <stdio.h>
        #include <tiuser.h>
        #include <fcntl.h>
        #include <stropts.h>

        typedef struct {
             unsigned len;           /* length of address field */
             unsigned char addr[32]; /* the address field */
        } tsap_selector;

        typedef struct {
             unsigned len;           /* length of address field */
             unsigned char addr[20]; /* binary representation of address */
        } nsap_address;

        typedef struct {
             tsap_selector tsap; /* Transport SAP ID */
             nsap_address  nsap; /* Network SAP address */
        } tsap_address;

        #define verbose  1       /* 1 on 0 off */
        #define bufsize  1024
        #define MAXBUFSZ 4*1024

        extern int t_errno;
        char data_buf[MAXBUFSZ];
        char rdata_buf[MAXBUFSZ];
        tsap_address *remaddr;

        main()
        {
             int fd, nbytes, i, flags;
             struct t_call *call;
             struct t_bind *bind;
             tsap_selector *loctsap;

             if ((fd = t_open("/dev/tp4", O_RDWR, NULL)) < 0) {
                  t_error("/dev/tp4 t_open failed");
                  exit(1);
             }



  2/94 - Intergraph Corporation                                              3






  tp4(7)                              CLIX                              tp4(7)



             /* Bind local to TSAP 0009*/
             if ((bind = (struct t_bind *) t_alloc(fd, T_BIND, T_ALL)) == NULL) {
                  t_error("tp4 t_bind failed");
                  t_close(fd); exit(2);
             }
             bind->addr.len = sizeof (tsap_selector);
             loctsap = (tsap_selector *) bind->addr.buf;
             loctsap->len = 2; loctsap->addr[0] = 0x0; loctsap->addr[1] = 0x9;
             bind->qlen = 1; /* passive */
             if (t_bind(fd, bind, bind) < 0) {
                  t_error("t_bind failed");
                  t_close(fd); exit(3);
             }
             t_free(bind);

             /* listen for incomming connection */
             if ((call = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == NULL) {
                  t_error("t_alloc of t_call struct failed");
                  t_close(fd); exit(3);
             }
             if (verbose) printf("posting a listen\n");
             if (t_listen(fd, call) < 0) {
                  t_error("t_listen failed for listen_fd");
                  t_close(fd); exit(6);
             }
             if (verbose) {
                  remaddr = (tsap_address *)call->addr.buf;
                  printf("t_listen completed: from_nsap (%d)[%x][%x]... ",
                       remaddr->nsap.len, remaddr->nsap.addr[0],
                       remaddr->nsap.addr[1]);
                  printf("from_tsap (%d)[%x][%x]...\n", remaddr->tsap.len,
                       remaddr->tsap.addr[0], remaddr->tsap.addr[1]);
             }

             if (t_accept(fd, fd, call) < 0) {
                  if (t_errno == TLOOK) {
                       if (t_close(fd) < 0) {
                            t_error("t_close failed for listen_fd");
                            exit(10);
                       }
                  }
                  t_error ("t_accept failed");
                  exit(7);
             }

             if (verbose) printf("t_accept success\n");
             t_free(call);

             for (i = 0; ; i++) {
                  int total = 0;




  4                                              Intergraph Corporation - 2/94






  tp4(7)                              CLIX                              tp4(7)



        rcv_again:
                  if ((nbytes = t_rcv(fd, &rdata_buf[total], bufsize-total,
                                      &flags)) < 0) {
                       printf("loop #%d: ", i);
                       if (t_errno == TLOOK) {
                            printf("t_rcv failed, t_look = %d\n", t_look(fd));
                            t_close(fd); exit(6);
                       }
                       t_error("t_rcv failed for fd");
                       t_close(fd); exit(8);
                  }

                  if (strncmp(rdata_buf, "END OF TEST", 11) == 0)
                       break;

                  total += nbytes;
                  if (total != bufsize) {
                       if (flags & T_MORE) {
                            if (verbose) printf(".");
                                 goto rcv_again;
                       }
                       printf("loop #%d: rcvd %d bytes instead of %d\n",
                               i, nbytes, bufsize);
                       continue;
                  } else if (verbose)
                       printf("received %d bytes, SUCCESS\n", total);

                  if ((nbytes = t_snd(fd, rdata_buf, bufsize, 0)) < 0) {
                       printf("loop #%d: ", i);
                       t_error("t_snd failed for fd");
                       t_close(fd); exit(5);
                  }

                  if (nbytes != bufsize) {
                       printf("loop #%d: ", i);
                       printf("sent %d bytes instead of %d\n");
                       continue;
                  }
             }

             /*
              * Send a finish response packet
              */
             if ((nbytes = t_snd(fd, "END OF TEST", 11, 0)) != 11) {
                  printf("Unable to send a fin response\n");
                  t_error("t_snd failed for fd");
                  exit(6);
             }

             for (;;) {
                  switch(t_look(fd)) {



  2/94 - Intergraph Corporation                                              5






  tp4(7)                              CLIX                              tp4(7)



                  case 0: /* No event */
                       sleep(1);
                       continue;
                  case T_DISCONNECT: {
                       struct t_discon *discon;

                       discon = (struct t_discon *)
                                 t_alloc(fd, T_DIS, T_ALL);
                       if (t_rcvdis(fd, discon) < 0)  {
                            t_error("t_rcvdis failed on tp4_fd");
                            break;
                       }
                       printf("Remote disconnect reason %d\n",
                              discon->reason);
                       t_free(discon);
                       t_close(fd); exit(0);
                  }
                  default:
                       printf("unexpected event\n");
                  }
             }
             t_close(fd);
        }


    2.  The following is an example of a client program:

        #include <stdio.h>
        #include <tiuser.h>
        #include <fcntl.h>
        #include <stropts.h>

        typedef struct  {
             unsigned len;           /* length of address field */
             unsigned char addr[32]; /* the address field */
        } tsap_selector;

        typedef struct {
             unsigned len;           /* length of address field */
             unsigned char addr[20]; /* binary representation of address */
        } nsap_address;

        typedef struct  {
             tsap_selector   tsap;   /* Transport SAP ID */
             nsap_address    nsap;   /* Network SAP address */
        } tsap_address;

        tsap_address remaddr;

        #define verbose  1       /* 1 on 0 off */
        #define nloop    10



  6                                              Intergraph Corporation - 2/94






  tp4(7)                              CLIX                              tp4(7)



        #define bufsize  1024
        #define MAXBUFSZ 4*1024

        extern int t_errno;
        char data_buf[MAXBUFSZ];
        char rdata_buf[MAXBUFSZ];

        main()
        {
             int fd, nbytes, i, j, flags, tbytes, reason;
             struct t_call *call;
             struct t_bind *bind;
             tsap_selector *loctsap;

             if ((fd = t_open("/dev/tp4", O_RDWR, NULL)) < 0) {
                  t_error("/dev/tp4 t_open failed");
                  exit(1);
             }

             /* Bind local to TSAP 0008*/
             if ((bind = (struct t_bind *) t_alloc(fd, T_BIND, T_ALL)) == NULL) {
                  t_error("tp4 t_bind failed");
                  t_close(fd); exit(2);
             }
             bind->addr.len = sizeof (tsap_selector);
             loctsap = (tsap_selector *) bind->addr.buf;
             loctsap->len = 2; loctsap->addr[0] = 0x0; loctsap->addr[1] = 0x8;
             if (t_bind(fd, bind, bind) < 0) {
                  t_error("t_bind failed");
                  t_close(fd); exit(3);
             }
             t_free(bind);

             /* Remote TSAP address */
             remaddr.tsap.len = 2;
             remaddr.tsap.addr[0] = 0x00; remaddr.tsap.addr[1] = 0x09;
             remaddr.nsap.len = 14;
             remaddr.nsap.addr[0] = 0x47;
             remaddr.nsap.addr[1] = 0x00;
             remaddr.nsap.addr[2] = 0x04;
             remaddr.nsap.addr[3] = 0x00;
             remaddr.nsap.addr[4] = 0x30;
             remaddr.nsap.addr[5] = 0x00;
             remaddr.nsap.addr[6] = 0x01;
             remaddr.nsap.addr[7] = 0x00;
             remaddr.nsap.addr[8] = 0x00;
             remaddr.nsap.addr[9] = 0x00;
             remaddr.nsap.addr[10] = 0x00;
             remaddr.nsap.addr[11] = 0x00;
             remaddr.nsap.addr[12] = 0x01;
             remaddr.nsap.addr[13] = 0x01;



  2/94 - Intergraph Corporation                                              7






  tp4(7)                              CLIX                              tp4(7)



             /* Get a connection established */
             if ((call = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == NULL) {
                  t_error("t_alloc of t_call struct failed");
                  t_close(fd); exit(3);
             }
             *((tsap_address *)call->addr.buf) = remaddr;
             call->addr.len = sizeof (tsap_address);
             if (t_connect(fd, call, NULL) < 0) {
                  if (t_errno == TLOOK) {
                       printf("t_rcv failed, t_look = %d\n", t_look(fd));
                       t_close(fd); exit(6);
                  }
                  t_error("t_connect failed");
                  t_close(fd); exit(4);
             }
             t_free(call);
             printf("t_connect success\n");

             /* Initialize the data buffer */
             for (i = 0; i < bufsize; i++) data_buf[i] = 0xEE;

             tbytes = 0;
             for (i = 0; i < nloop; i++) {
                  int total = 0;

                  if ((nbytes = t_snd(fd, data_buf, bufsize, 0)) < 0) {
                       printf("loop #%d: ", i);
                       t_error("t_snd failed for fd");
                       t_close(fd); exit(5);
                  }

                  if (nbytes != bufsize) {
                       printf("loop #%d: sent %d bytes instead of %d\n",
                               i, nbytes, bufsize);
                       continue;
                  } else {
                       tbytes += nbytes;
                       if (verbose)
                            printf("send %d bytes, SUCCESS\n", nbytes);
                  }
        rcv_again:
                  if ((nbytes = t_rcv(fd, &rdata_buf[total], bufsize-total,
                       &flags)) < 0) {
                       printf("loop #%d: ", i);
                            if (t_errno == TLOOK) {
                                 printf("t_rcv failed, t_look = %d\n",
                                         t_look(fd));
                                 t_close(fd); exit(6);
                            }
                       t_error("t_rcv failed for fd");
                       t_close(fd); exit(8);



  8                                              Intergraph Corporation - 2/94






  tp4(7)                              CLIX                              tp4(7)



                  }

                  tbytes += nbytes; total += nbytes;
                  if (total != bufsize) {
                       if (flags & T_MORE) {
                            if (verbose) printf(".");
                            goto rcv_again;
                       }
                       printf("loop #%d: rcvd %d bytes instead of %d\n",
                               i, total, bufsize);
                       continue;
                  }

                  for (j = 0; j < bufsize; j++) {
                       if ((unsigned char)rdata_buf[j]
                            != (unsigned char)0xEE) {
                            int b;
                            printf("loop #%d: ", i);
                            b = (int)rdata_buf[i];
                            printf("data error at byte #%d (%x)\n", j, b);
                            goto endloop;
                       }
                  }
        successloop:
                  if (verbose)
                       printf("loop #%d SUCCESS\n", i);
        endloop:
             }

             /* Send a finish packet */
             if ((nbytes = t_snd(fd, "END OF TEST", 11, 0)) != 11) {
                  printf("Unable to send a fin\n");
                  t_error("t_snd failed for fd");
                  exit(6);
             }

             /* Receive fin response packet */
             if ((nbytes = t_rcv(fd, rdata_buf, 64, &flags)) < 0) {
                  if (t_errno == TLOOK) {
                       printf("failed to rcv a fin response\n", t_look(fd));
                       t_close(fd); exit(6);
                  }
                  t_error("failed to rcv a fin response\n");
                  t_close(fd); exit(8);
             }
             if (strncmp(rdata_buf, "END OF TEST", 11) != 0) {
                  printf("Handshake close failed\n");
                  exit(10);
             }

             /* destroy the transport connection */



  2/94 - Intergraph Corporation                                              9






  tp4(7)                              CLIX                              tp4(7)



             if ((call = (struct t_call *)t_alloc(fd, T_CALL, T_ALL)) == NULL) {
                  t_error("t_alloc of t_call struct failed");
                  t_close(fd); exit(3);
             }
             call->udata.len = sizeof (int);
             reason = 128; /* NORMAL Disconnect */
             call->udata.buf = (char *)&reason;
             t_snddis(fd, call);
             t_free(call);

             sleep(2);
             t_close(fd);
        }


  RELATED INFORMATION

    AT&T UNIX System V STREAMS Programmer's Guide, AT&T UNIX System V Network
    Programmer's Guide



































  10                                             Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026