TLI.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Tim Diebert: November 21, 1989 4:02:59 pm PST
Willie-s, December 9, 1991 6:35 pm PST
DIRECTORY
CStrings USING [CString],
UnixTypes USING [CHARPtr, FileFlags];
TLI: CEDAR DEFINITIONS
~ BEGIN
This interface describes the various procedure calls related to the AT&T TLI (Transport Level Interface) from PCedar. In general all calls require a data structure that gets allocated by a mesa procedure. This is in an attempt to avoid having the C programs allocate and free storage using malloc.
The ConnectionDataRep is defined in ThreadsTLI.h.
ConnectionData: TYPE ~ REF ConnectionDataRep;
ConnectionDataRep: TYPE ~ MACHINE DEPENDENT RECORD [
flags: CARD32,  -- flags
rcvSize: INT32,  -- recieve buffer size
rcvBuf: UnixTypes.CHARPtr,  -- the bits
ctlSize: INT32,  -- the size of the control buffer
ctlBuf: UnixTypes.CHARPtr,  -- the bits
lookDBuf: UnixTypes.CHARPtr,  -- look data buffer
lookCBuf: UnixTypes.CHARPtr,  -- look control buffer
lookDSize: INT32,   -- the size of the data buffer
lookCSize: INT32,   -- the size of the control buffer
maxPsz: INT32,   -- the TIDU
servType: INT32,   -- the kind of service (COTS, CTSORD, CLTS)
lookFlag: INT32,   -- buffered look flag
fd: INT32,    -- the file descriptor of the underlying data stream
errno: TErrno,   -- the TLI global errno
info: TInfo    -- filled in on the call to open
];
The following are the error codes needed by both the kernel level transport providers and the user level library.
TErrno: TYPE ~ MACHINE DEPENDENT {
TBADADDR(1), -- incorrect addr format
TBADOPT(2), -- incorrect option format
TACCES(3),  -- incorrect permissions
TBADF(4),  -- illegal transport fd
TNOADDR(5), -- couldn't allocate addr
TOUTSTATE(6), -- out of state
TBADSEQ(7), -- bad call sequnce number
TSYSERR(8),  -- system error
TLOOK(9),  -- event requires attention
TBADDATA(10), -- illegal amount of data
TBUFOVFLW(11), -- buffer not large enough
TFLOW(12),  -- flow control
TNODATA(13), -- no data
TNODIS(14),  -- discon¬ind not found on q
TNOUDERR(15), -- unitdata error not found
TBADFLAG(16), -- bad flags
TNOREL(17), -- no ord rel found on q
TNOTSUPPORT(18), -- primitive not supported
TSTATECHNG(19), -- state is in process of changing
(LAST[CARD32])
};
The following are the events returned by TLook
LISTEN: INT ~ 00001h;  -- connection indication received
CONNECT: INT ~ 00002h;  -- connect confirmation received
DATA: INT ~ 00004h;  -- normal data received
EXDATA: INT ~ 00008h;  -- expedited data received
DISCONNECT: INT ~ 00010h; -- disconnect received
TERROR: INT ~ 00020h;  -- fatal error occurred
UDERR: INT ~ 00040h;  -- data gram error indication
ORDREL: INT ~ 00080h;  -- orderly release indication
EVENTS: INT ~ 000FFh;  -- event mask 
The following are the flag definitions needed by the user level library routines.
MORE: INT ~ 0001h; -- more data
EXPEDITED: INT ~ 0002h; -- expedited data
NEGOTIATE: INT ~ 0004h; -- set opts
CHECK: INT ~ 0008h; -- check opts
DEFAULT: INT ~ 0010h; -- get default opts
SUCCESS: INT ~ 0020h; -- successful
FAILURE: INT ~ 0040h; -- failure
Protocol specific service limits
TInfo: TYPE ~ MACHINE DEPENDENT RECORD [
addr: INT32,  -- size of protocol address
options: INT32, -- size of protocol options
tsdu: INT32,  -- size of max transport service data unit
etsdu: INT32, -- size of max expedited tsdu
connect: INT32, -- max data for connection primitives
discon: INT32, -- max data for disconnect primitives
servtype: INT32-- provider service type
];
Service type defines
COTS: INT ~ 01; -- connection oriented transport service
COTSORD: INT ~ 02; -- connection oriented w/ orderly release
CLTS: INT ~ 03; -- connectionless transport service
Netbuf structure
NetBuf: TYPE ~ MACHINE DEPENDENT RECORD [
maxlen: CARD,
len: CARD,
char: UnixTypes.CHARPtr
];
TBindCall - format of the addres and options arguments of bind
TBindCall: TYPE ~ MACHINE DEPENDENT RECORD [
addr: NetBuf,
qlen: CARD
];
Options management
TOptMgmt: TYPE ~ MACHINE DEPENDENT RECORD [
opt: NetBuf,
flags: INT
];
Disconnect structure
TDisCon: TYPE ~ MACHINE DEPENDENT RECORD [
udata: NetBuf,
reason: INT,
sequence: INT
];
Call structure
TCall: TYPE ~ MACHINE DEPENDENT RECORD [
addr: NetBuf,
opt: NetBuf,
udata: NetBuf,
sequence: INT
];
Data gram structure
TUnitData: TYPE ~ MACHINE DEPENDENT RECORD [
addr: NetBuf, -- address
opt: NetBuf,  -- options
udata: NetBuf -- user data
];
Unitdata error
TUDErr: TYPE ~ MACHINE DEPENDENT RECORD [
addr: NetBuf, -- address
opt: NetBuf,  -- options
error: INT  -- error code
];
The following are structure types used when dynamically allocating the above structures via TStructAlloc().
StructureType: TYPE ~ MACHINE DEPENDENT {
(0),
tbind (1), -- struct t¬bind
toptmgmt (2), -- struct t¬optmgmt
tcall (3), -- struct t¬call
tdis (4), -- struct t¬discon
tunitdata (5), -- struct t¬unitdata
tuderror (6), -- struct t¬uderr
tinfo (7), -- struct t¬info
(LAST[CARD32])
};
The following bits specify which fields of the above structures should be allocated by TStructAlloc().
StructureBits: TYPE ~ MACHINE DEPENDENT {
(0),
addr (01h), -- address
opt (02h), -- options
udata (04h), -- user data
all (07h), -- all the above
(LAST[CARD32])
};
The following are the states for the user
States: TYPE ~ MACHINE DEPENDENT {
uninit (0), -- uninitialized
unbnd (1), -- unbound
idle (2), -- idle
outcon (3), -- outgoing connection pending
incon (4), -- incoming connection pending
dataxfer (5), -- data transfer
outrel (6), -- outgoing release pending
inrel (7), -- incoming release pending
nostates  (8),
(LAST[CARD32])
};
Procedures
TOpen: PROC [cd: ConnectionData, path: CStrings.CString, flags: UnixTypes.FileFlags,
info: REF TInfo ¬ NIL] RETURNS [INT32] = TRUSTED MACHINE CODE { "XR←T←Open" };
This procedure opens the device indicated by path, using flags. If info is supplied, details about the transport are returned. For the Mentat xns code, path should be /dev/xr and flags should be RDWR. It is assumed that cd has been allocated prior to the call. The lower level code will allocate the various buffers using malloc after the sizes are determined by a get info call. -1 is returned on error with more detail available via cd.errno. A nonzero return value indicates success. This underlying device is closed prior to return on error.
TBind: PROC [cd: ConnectionData, request: REF TBindCall ¬ NIL, return: REF TBindCall ¬ NIL]
RETURNS [INT32] = TRUSTED MACHINE CODE { "XR←T𡤋ind" };
This procedure connects a local endpoint (socked) to the connection TOpen-ed above. If request is non-NIL and attempt is made to assign that endpoint to the connection. If return is non-NIL, it contains the true endpoint of the call. Since it's possible that the requested endpoint is already in use, the actual endpoint may be different. The request field is generallay associated with a server. For normal client operation, both request and return should be left NIL.
TUnBind: PROC [cd: ConnectionData] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←UnBind" };
This procedure destroys the binding to a socket by a previous call to TBind
TConnect: PROC [cd: ConnectionData, sndCall: REF TCall, rcvCall: REF TCall ¬ NIL]
RETURNS[INT32] = TRUSTED MACHINE CODE { "XR←T𡤌onnect" };
This proc makes a connection request to the address specified in the addr field of the sndCall. If rcvCall is supplied, the address of the remote socket is returned. It is assumed that the needed fields of both sndCall and rcvCall have memory allocated to them. If the call is successful 0 is returned, -1 is returned on error.
TSnd: PROC [cd: ConnectionData, buf: UnixTypes.CHARPtr, nbytes: CARD32, flags: INT32]
RETURNS[bytesSent: INT] = TRUSTED MACHINE CODE { "XR←T←Snd" };
This proc sends data to the socket on the remote machine. If this is not the last call in a logical message, flags must have the MORE bit set. To send expedited data the EXPEDITED flag must be set. -1 is returned to indicate an error has occured.
TSndRel: PROC [cd: ConnectionData] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←SndRel" };
This proc initiates and orderly release of the connection. Upon return, the initiator should perform and TRcvRel to determine that the release is complete. -1 is returned on error.
TSndDis: PROC [cd: ConnectionData, call: REF TCall] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←SndDis" };
This call initiates an abortive release on the connection. See the documentation on its use. -1 is returned on error. 0 is returned on completion.
TRcv: PROC [cd: ConnectionData, buf: UnixTypes.CHARPtr, nbytes: CARD32, flags: REF INT32]
RETURNS[bytesRcv: INT] = TRUSTED MACHINE CODE { "XR←T←Rcv" };
This proc reads bytes from the input stream and returns the number of bytes recieved from the other end. The call returns when the buffer is full, when EOM is present in the stream or when expedited data was recieved. If this is an attention packet, flags has EXPEDITED and MORE set. Since attention packet are recieved twice, the second time the packed is delivered the EXPEDITED bit will be set but the MORE won't be. If the buffer ran out of space, the MORE flag will be set. If EOM was sent with the message, the MORE will not be set.
TRcvRel: PROC [cd: ConnectionData] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←RcvRel" };
This proc retrieves the end of an orderly release indication. It is used to determine that the connection is released. This should only be called after TSndRel. 0 is return upon completion, -1 on error.
TRcvUData: PROC [cd: ConnectionData, unitdata: REF TUnitData, flags: REF INT32]
RETURNS [INT32] = TRUSTED MACHINE CODE { "XR←T←RcvUData" };
This procedure provides a connectionless mode request to receice data from another.
TSndUData: PROC [cd: ConnectionData, unitdata: REF TUnitData] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←SndUData" };
This procedure sends a connectionless chunk of data to a cooperating host.
TLook: PROC [cd: ConnectionData] RETURNS [events: INT32] =
TRUSTED MACHINE CODE { "XR←T←Look" };
TLook provides additional information when cd.errno = TLOOK. events is a collection of flags as defined above. -1 is returned on serious errors.
TRcvUDErr: PROC [cd: ConnectionData, uderr: REF TUDErr] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T←RcvUDErr" };
This proc is called when cd.errno = TLOOK for connectionless data call
TGetState: PROC [cd: ConnectionData] RETURNS [state: States] =
TRUSTED MACHINE CODE { "XR←T←GetState" };
Returns the current state of the underlying connection
TClose: PROC [cd: ConnectionData] RETURNS [INT32] =
TRUSTED MACHINE CODE { "XR←T𡤌lose" };
This proc closes the fd associated with the TOpen. This call really just blasts the connection away and does'n really care how it does it. This is not an orderly release.
END.