Raw Synchronous Library API Programmer's Guide

Introduction
Functions
Example
Error Codes
Tags
Frame Reception Overview
Network Lookup Overview
Function Reference

Copyright © 1997-2004 The Software Group Limited




Introduction

The Synchronous library allows a program to write synchronous data directly to a synchronous line. For raw framed synchronous links, the hardware adds/removes only start and end flags, zero bit insertion and a 16 bit CRC. For raw unframed synchronous links (only supported with some hardware), nothing is added to or removed from the data exchanged. In either case, all protocol headers are the responsibility of the user program. Outgoing frames are formed with the data buffer of each sync_write call (see example below).

The library is based on a concept called Tags, which it uses to obtain parameters for some functions. Tags should always be passed in pairs: the tag itself and its value. (An exception to this is the last tag, which must ALWAYS be TAG_END!)

Whenever a function specifies that it accepts a TAG LIST, a variable length argument list is expected to be passed to it. A variation on this is to pass a pointer to the first element of an array of TAG structures to the ...tags() variant of this function.

An Example:

   SCALLT *scallt;
   int rc, netid = 0;
   char *buf = "Hello World";

   scallt = sync_open (netid, TAG_END);
   rc = sync_write(scallt, ST_BUFFER, buf, ST_BUFLEN, sizeof(buf), TAG_END);
   sync_close(scallt);

Any function capable of accepting tag arguments can be called in either of two ways. The first is to pass a variable number of tag arguments This method allows for great flexibility, especially the ability to use C's conditional operator to create conditional tags. Example:

   SCALLT scallt;

   int buflen = 2048;
   int rc, currentbuf;

   rc = sync_read(scallt, currentbuf == 0 ? ST_BUFFER : ST_IGNORE, &buf0[0],
                  currentbuf == 1 ? ST_BUFFER : ST_IGNORE, &buf1[0],
                  ST_BUFLEN, buflen,
                  TAG_END);

The second way involves passing an array of tags, which must still include a TAG_END. This method results in faster execution in most cases, since the library normally converts variable argument tags into an array form before processing them. You may wish to use this method when you are passing the same tags over and over again. Example:

    SCALLT scallt;
    char buf[2048];
    TAGS mytags[] = { {ST_BUFFER, &buf[0]}, {ST_BUFLEN, 30}, {TAG_END, 0} };
    int rc;

    rc = sync_readtags(scallt, mytags);

Most functions will return 0 for success or -1 for failure.

Error handling is done by looking at the return of sync_geterror() or sync_error(). sync_errorstr() may be called to translate the error code into words.

A typical application will use the 5 basic functions, sync_open(), sync_read(), sync_write(), sync_look(), and sync_close() to perform the data transfer.

[ Functions | Introduction | Example | Errors | Tags | Reference ]


Synchronous Library Functions

General Functions

sync_open()
Open sync connection
sync_close()
Close sync connection
sync_read()
Read data
sync_write()
Write data

Frame Reception Status Functions

Please see Overview of Frame Reception Status Functions

sync_look()
Check for frames
sync_lookinit()
Initialize the selection list
sync_looksel()
Check for data on multiple links
sync_lookadd()
Add an SCALLT to the selection list
sync_lookdel()
Remove an SCALLT from the selection list
sync_lookclose()
Close/Free the selection list

Network Lookup Functions

These functions manipulate the file packetnets database which stores network IDs and their network types (protocols).
Please also see Overview of Network Lookup Functions

sync_setnetent()
Start Network file lookup operations
sync_endnetent()
Stop Network file lookup operations
sync_getnetent()
Get Network entry
sync_getnetbyname()
Lookup Network by Name
sync_getnetbynetid()
Lookup Network by Network ID
sync_setfilter()
Set the Network type filter

Error Handling Functions

sync_error()
Print Error Information
sync_errorstr()
Copy Error Information into buffer
sync_geterror()
Obtain error code
sync_getsyserror()
Obtain system error code

Adapter Statistics Functions

sync_openstats()
Open device for Stats Request
sync_closestats()
Close device for Stats Request
sync_getstats()
Obtain Statistics

Miscellaneous Functions

sync_getconfig()
Get link configuration items
sync_logmsg()
Log Message to a file or stderr
sync_setopts()
Set Global Tags
sync_getopts()
Obtain Global Tags
sync_findtag()
Find Tag given Tag list
sync_getdevtype()
Obtain Physical device type and name
sync_getdevicename()
Obtain Physical device type and the device string.
sync_setuservalue()
Set the value associated with a SCALLT
sync_getuservalue()
Get the value associated with a SCALLT

Macros (SCALLT *ct)

SYNC_FD(ct)
file descriptor for SCALLT
SYNC_FDEXCEPT(ct)
file descriptor for SCALLT control channel (SyncServer only)
SYNC_DEVNAME(ct)
device name for this SCALLT
SYNC_NETID(ct)
Network ID for this SCALLT
SYNC_ISINIT(ct)
Is the SCALLT structure initialized?

[ Functions | Introduction | Example | Errors | Tags | Reference ]




Example Program

/***********************************************************************
 *  Module Name: libtest.c
 *
 *  Description:
 *   Sends a string NUMTIMES times over a synchronous link
 ***********************************************************************/

#include <stdio.h>
#include "libsync.h"

#define NUMTIMES        100

int main(int argc, char **argv)
{
    SCALLT *ct;
    char errbuf[256];
    int i, netid = 0;
    char *buf = "This is the string being sent across the synchronous link";

    if (argc > 1)
        netid = atoi(argv[1]);
    /*
     * Prior to any sync activity, obtain a handle for operating
     * the link.
     */
    ct = sync_open(netid, TAG_END));
    if (!ct)
    {
	sync_errorstr(errbuf, sizeof(errbuf));
        printf("Error: sync_open: %s\n", errbuf);
        exit(1);
    }
    /*
     * Send the same string to the remote machine NUMTIMES times
     */
    for (i = 0; i < NUMTIMES; i ++)
    {
	if (sync_write(ct, 
	    ST_BUFFER, buf,
            ST_BUFLEN, strlen(buf),
            TAG_END) < 0)
        {
	    sync_errorstr(errbuf, sizeof(errbuf));
            printf("Error: sync_write: %s\n", errbuf);
            break;
        }
    }
    /*
     * Now we're done. Close and exit.
     */
    sync_close(ct);
    exit(0);
}

[ Functions | Introduction | Example | Errors | Tags | Reference ]




Synchronous Library Error Codes

The following is a list of error codes which sync_geterror() can return. If the error is set to SYE_SYSERR check errno for more details. sync_error() will write out both Synchronous Library errors and system errors to stdout. Writing to stdout is only supported by Console (Text mode) Applications. sync_errorstr() will write the error into a user supplied buffer.

SYE_SYSERR
System Error Message; refer to errno
SYE_BADMSG
Unexpected message from driver
SYE_BADERRMSG
Internal Error: Unknown Error Message From Protocol Driver
SYE_OUTSTATE
Internal Error: Protocol Driver Received Message Out of State
SYE_USERDATA
Bad supplied user data (check function arguments)
SYE_OPTERR
Bad supplied tag data (check tag argument)
SYE_FILEFMT
Internal Error: Bad File Format of Packetnets file
SYE_BADSCALLT
Bad SCALLT Structure
SYE_BADBUFFER
Zero Length or Null Pointer specified
SYE_BADNETID
Bad Network ID
SYE_NOTFOUND
Internal Error: Packetnets file not found
SYE_BADSAP
Bad SAP (for sync_bind)
SYE_BADPPA
Bad PPA (Physical Point of Attachment). Check that the associated netid is configured as a raw synchronous link and that it is not already in use.
SYE_BADMODE
Currently unused
SYE_ACCESS
Improper Permissions to access a driver resource or file
SYE_BADPRIM
Bad Primitive
SYE_BADCONFIG
Bad Configuration file
SYE_BADINIT
Bad physical initialization
SYE_NOSUPPORT
Service not supported
SYE_UNSUPPORTED
Service known, but not supported
SYE_UNDELIVERED
Transmitter failure, data undelivered
SYE_FAILCONFIG
Link Configuration Failed. Invalid config file or invalid netid
SYE_NOCONFIG
Configuration File Not Found
SYE_OPENFAIL
Open of Device Failed
SYE_BADPOINTER
Currently unused
SYE_TCPBADHOST
Unable to look up TCP host in packetnets
SYE_CANTCONNECT
Can't connect to TCP host
SYE_TIMEOUT
Timed out connection to TCP host
SYE_TCPCLOSED
Connection to TCP host closed unexpectedly

[ Functions | Introduction | Example | Errors | Tags | Reference ]




Synchronous Library Tags

This is a list of currently supported tags and an explanation of their meaning.

Special Tags:

TAG_END
Signifies end of Tag List
TAG_DONE
Synonym for TAG_END
TAG_IGNORE
Ignore this tag and it's value

Global tags:

These can be passed to any function expecting tags.

ST_VERBOSE
Comment on progress to stdout on Console Applications
ST_BLOCK
Blocking call?
ST_OUTERR
FILE *ptr for error messages
ST_LOGFILE
Log file to use (defaults to stderr)

Function Specific Tags:

ST_NETNAME
Network Name
ST_BUFFER
Pointer to Buffer
ST_BUFLEN
Size of Buffer
ST_FLAGS
Flags to pass to open()
ST_SETCRC
Set CRC generation on/off (Boolean) (not supported on all hardware)
ST_SETDTR
Set state of DTR signal (Boolean).
ST_SETRTS
Set state of RTS signal (Boolean).
ST_GETDSR
Get state of DSR signal (Boolean).
ST_GETCTS
Get state of CTS signal (Boolean).
ST_GETDCD
Get state of DCD signal (Boolean).
ST_RAWOPEN
Do not attach or bind in sync_open()
ST_SETFM0
Set FM0 encoding in sync_open()
ST_FRAMESIZE
Set Maximum Frame Size encoding in sync_open()
ST_SPEED
Set speed of link (0 = external clocking) in sync_open()
ST_CONFIGFILE
Set name of configuration file in sync_open()
ST_TRACE
Allow tracing of the link in sync_open()
ST_REVDATA
Send and receive the most significant bit of each byte first.
ST_USEUDP
Use UDP in data transfer mode (Experimental).

[ Functions | Introduction | Example | Errors | Tags | Reference ]




Overview of Frame Reception Status Functions

The synchronous library has two mechanisms to determine the availability of data packets on one or more circuits.

If only one circuit is to be monitored, then using sync_look() is the simplest method. However, this approach does not easily scale when 2 or more circuits require monitoring.

The recommended method for multi-circuit applications is to use the sync_lookxxxx series of functions. This set of functions is used to manipulate and monitor a list of circuits. sync_lookinit() initializes the list, sync_lookadd() andsync_lookdel() manipulate list entries,sync_looksel() queries the list for available data packets andsync_lookclose() frees the list.

[ Functions | Introduction | Example | Errors | Tags | Reference ]




Overview of Network Lookup Functions

The synchronous library requires that a netid be used to identify a particular board and link combination. The following group of functions enable access to the database which contains the netid information. These functions are only needed if the application wishes to investigate the current system configuration to dynamically determine the netid to use.

Before using sync_getnetent() the function sync_setnetent() must be called which allocates necessary resources and enables the library to access the configuration database. At this pointsync_getnetent() can be used to scan through the list of synchronous netids in the system. An optional filter can be specified usingsync_setfilter() to limit or increase the types of netids returned by sync_getnetent(). To release the resources allocated by sync_setnetent() callsync_endnetent().

The functions sync_getnetbynetid() and sync_getnetbyname() use the above functions to search through the configuration database to locate the desired netid. These functions do not require the calling application to use sync_setnetent() orsync_endnetent().

[ Functions | Introduction | Example | Errors | Tags | Reference ]