dlprims.c revision c7e4935f5b755b4bbeaec416f1ad24337aeac7a4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI" /* SunOS */
#include <stdlib.h>
#include <string.h>
#include <stropts.h>
#include <sys/sysmacros.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include "snoop.h"
#define DLMAXBUF (256)
static void sigalrm(int);
t_uscalar_t, void *, int);
static void syserr(const char *, ...);
static int timer_ctl(int);
static char *show_dlerror(int);
/*
* Issue DL_INFO_REQ and wait for DL_INFO_ACK.
*/
void
{
/* Copy the response to the caller */
}
/*
* Issue DL_ATTACH_REQ and wait for DL_OK_ACK.
*/
void
{
DL_OK_ACK_SIZE, dlareq, 0);
}
/*
* Issue DL_PROMISCON_REQ and wait for DL_OK_ACK.
*/
void
{
DL_OK_ACK_SIZE, dlpon, 0);
}
/*
* Issue DL_BIND_REQ and wait for DL_BIND_ACK
*/
void
{
dlbreq->dl_xidtest_flg = 0;
DL_BIND_ACK_SIZE, dlbreq, 0);
}
/*
* Common routine for dispatching and retrieving DLPI requests.
*/
static void
{
/* Start a timer */
syserr("snoop: Failed to start timer");
/* Put the primitive downstream */
syserr("snoop: error sending DLPI message to device: %s\t%s\n ",
}
/* Retrieve and check response to issued primitve */
syserr("snoop: error reading DLPI message from device: %s"
}
/* Stop the timer */
if (timer_ctl(0) < 0)
syserr("snoop: Failed to stop timer");
}
static int
{
}
/*
* Retrieve messages from the descriptor. Check the retrieved message
* is the desired response to the issued primitive.
*/
static int
{
int flags = 0;
int rc;
do {
return (-1);
/*
* The supplied DLMAXBUF sized buffers are large enough to
* retrieve all valid DLPI responses in one iteration.
* If MORECTL or MOREDATA are set this indicates that this
* message is NOT a response we are interested in.
* Temporary buffers are used to drain the remainder of this
* message. The special case we have to account for is if
* a higher priority messages is enqueued whilst handling
* this condition. We use a change in the flags parameter
* returned by getmsg() to indicate the message has changed.
*/
return (-1);
break;
}
}
return (0);
}
/*
* Checks the DLPI response for validity.
*/
static int
{
/*
* We need at least enough space for a primitive and a
* buffer to interpret.
*/
return (-1);
/*
* Fatal Error. However, first check that it's big
* enough to be a DL_ERROR_ACK and that it also in
* response to the primitive we issued
*/
if (size < DL_ERROR_ACK_SIZE)
return (-1);
/* Is it ours? */
return (-1);
/* As close as we can establish, it's our error */
syserr("snoop: fatal DLPI error: %d\t%s\nDevice: %s\n",
}
/*
* Check to see if the returned primitive is what we were
* expecting and if it is large enough to contain the minimum
* size.
*/
return (-1);
return (0);
}
static char *
show_dlerror(int dl_errno)
{
switch (dl_errno) {
case DL_ACCESS:
return ("Improper permissions for request");
case DL_BADADDR:
return ("DLSAP addr in improper format or invalid");
case DL_BADCORR:
return ("Seq number not from outstand DL_CONN_IND");
case DL_BADDATA:
return ("User data exceeded provider limit");
case DL_BADPPA:
return ("Specified PPA was invalid");
case DL_BADPRIM:
return ("Primitive received not known by provider");
case DL_BADQOSPARAM:
return ("QOS parameters contained invalid values");
case DL_BADQOSTYPE:
return ("QOS structure type is unknown/unsupported");
case DL_BADSAP:
return ("Bad LSAP selector");
case DL_BADTOKEN:
return ("Token used not an active stream");
case DL_BOUND:
return ("Attempted second bind with dl_max_conind");
case DL_INITFAILED:
return ("Physical Link initialization failed");
case DL_NOADDR:
return ("Provider couldn't allocate alt. address");
case DL_NOTINIT:
return ("Physical Link not initialized");
case DL_OUTSTATE:
return ("Primitive issued in improper state");
case DL_SYSERR:
return ("UNIX system error occurred");
case DL_UNSUPPORTED:
return ("Requested serv. not supplied by provider");
case DL_UNDELIVERABLE:
return ("Previous data unit could not be delivered");
case DL_NOTSUPPORTED:
return ("Primitive is known but not supported");
case DL_TOOMANY:
return ("Limit exceeded");
case DL_NOTENAB:
return ("Promiscuous mode not enabled");
case DL_BUSY:
return ("Other streams for PPA in post-attached");
case DL_NOAUTO:
return ("Automatic handling XID&TEST not supported");
case DL_NOXIDAUTO:
return ("Automatic handling of XID not supported");
case DL_NOTESTAUTO:
return ("Automatic handling of TEST not supported");
case DL_XIDAUTO:
return ("Automatic handling of XID response");
case DL_TESTAUTO:
return ("Automatic handling of TEST response");
case DL_PENDING:
return ("Pending outstanding connect indications");
}
return ("Unknown DLPI error");
}
static void
{
exit(1);
}
static int
{
}
/* ARGSUSED */
static void
{
syserr("sigalrm: TIMEOUT");
}