Home | History | Annotate | Download | only in snoop
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright (c) 1991-2001 by Sun Microsystems, Inc.
     24  * All rights reserved.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #include <stdio.h>
     30 #include <sys/types.h>
     31 
     32 #include <at.h>
     33 #include <snoop.h>
     34 
     35 static char *adsp_ctrl(uint8_t);
     36 
     37 void
     38 interpret_adsp(int flags, struct ddp_adsphdr *adp, int len)
     39 {
     40 	struct ddp_adsp_open *apo;
     41 
     42 	if (flags & F_SUM) {
     43 		if (len < sizeof (struct ddp_adsphdr)) {
     44 			(void) snprintf(get_sum_line(), MAXLINE,
     45 			    "ADSP (short packet)");
     46 			return;
     47 		}
     48 		(void) snprintf(get_sum_line(), MAXLINE,
     49 		    "ADSP ConnID=%u (%s)",
     50 		    get_short(adp->ad_connid),
     51 		    adsp_ctrl(adp->ad_desc));
     52 	}
     53 
     54 	if (flags & F_DTAIL) {
     55 		show_header("ADSP: ", "ADSP Header",
     56 		    len - sizeof (struct ddp_adsphdr));
     57 		show_space();
     58 
     59 		if (len < sizeof (struct ddp_adsphdr)) {
     60 			(void) snprintf(get_line(0, 0), get_line_remain(),
     61 			    "(short packet)");
     62 			return;
     63 		}
     64 
     65 		(void) snprintf(get_line(0, 0), get_line_remain(),
     66 		    "ConnID = %u, ByteSeq = %u, RecvSeq = %u",
     67 		    get_short(adp->ad_connid),
     68 		    get_long(adp->ad_fbseq),
     69 		    get_long(adp->ad_nrseq));
     70 
     71 		(void) snprintf(get_line(0, 0), get_line_remain(),
     72 		    "RcvWin = %u, Ctrl = 0x%x (%s)",
     73 		    get_short(adp->ad_rcvwin),
     74 		    adp->ad_desc,
     75 		    adsp_ctrl(adp->ad_desc));
     76 
     77 		switch (adp->ad_desc) {
     78 		case AD_CREQ:		/* open requests */
     79 		case AD_CACK:
     80 		case AD_CREQ_ACK:
     81 		case AD_CDENY:
     82 			apo = (struct ddp_adsp_open *)adp;
     83 			if (len < sizeof (struct ddp_adsp_open)) {
     84 				(void) snprintf(get_line(0, 0),
     85 				    get_line_remain(),
     86 				    "(short packet)");
     87 				return;
     88 			}
     89 			(void) snprintf(get_line(0, 0), get_line_remain(),
     90 			    "Dest ConnID = %u, AttRcvSeq = %u",
     91 			    get_short(apo->ad_dconnid),
     92 			    get_long(apo->ad_attseq));
     93 			break;
     94 		}
     95 
     96 		if (adp->ad_desc & AD_ATT) {
     97 			(void) snprintf(get_line(0, 0), get_line_remain(),
     98 			    "AttCode = 0x%x",
     99 			    get_short(((struct ddp_adsp_att *)adp)->
    100 				ad_att_code));
    101 		}
    102 	}
    103 }
    104 
    105 static char *adsp_ctrl_msg[] = {
    106 	"Probe/Ack",
    107 	"OpenConnReq",
    108 	"OpenConnAck",
    109 	"OpenConnReq+Ack",
    110 	"OpenConnDeny",
    111 	"CloseConnAdv",
    112 	"ForwReset",
    113 	"ForwReset Ack",
    114 	"RetransAdv",
    115 	"9", "10", "11", "12", "13", "14", "15",
    116 };
    117 
    118 static char *
    119 adsp_ctrl(uint8_t ctrl)
    120 {
    121 	static char buf[50];
    122 	char *p = buf;
    123 	char *tail = &buf[sizeof (buf)];
    124 
    125 	if (ctrl & AD_ACKREQ)
    126 		p += snprintf(p, tail-p, "AckReq");
    127 
    128 	if (ctrl & AD_EOM) {
    129 		p += snprintf(p, tail-p, p == buf ? "EOM" : " EOM");
    130 	}
    131 
    132 	if (ctrl & AD_ATT) {
    133 		p += snprintf(p, tail-p, p == buf ? "Att" : " Att");
    134 	}
    135 
    136 	if (ctrl & AD_CTRL) {
    137 		(void) snprintf(p, tail-p, "%s%s", p == buf ? "" : " ",
    138 		    adsp_ctrl_msg[ctrl & AD_CTRL_MASK]);
    139 	}
    140 
    141 	return (buf);
    142 }
    143