1 /*******************************************************************************
2 *
3 *   (c) 1998 by Computone Corporation
4 *
5 ********************************************************************************
6 *
7 *
8 *   PACKAGE:     Linux tty Device Driver for IntelliPort family of multiport
9 *                serial I/O controllers.
10 *
11 *   DESCRIPTION: Interpretive trace dump utility
12 *
13 *******************************************************************************/
14 
15 #include <sys/time.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <stdio.h>
19 #include <signal.h>
20 #include <sys/stat.h>
21 #include <fcntl.h>
22 #include <ctype.h>
23 #include "ip2trace.h"
24 
25 unsigned long namebuf[100];
26 
27 struct {
28 	int wrap,
29 	size,
30 	o_strip,
31 	o_stuff,
32 	strip,
33 	stuff;
34 	unsigned long buf[1000];
35 } tbuf;
36 
37 struct sigaction act;
38 
39 typedef enum { kChar, kInt, kAddr, kHex } eFormat;
40 
41 int active = 1;
quit()42 void quit() { active = 0; }
43 
main(int argc,char * argv[])44 int main (int argc, char *argv[])
45 {
46    int   fd = open ( "/dev/ip2trace", O_RDONLY );
47    int   cnt, i;
48 	unsigned long ts, td;
49    struct timeval timeout;
50    union ip2breadcrumb bc;
51 	eFormat fmt = kHex;
52 
53    if ( fd < 0 )
54    {
55       printf ( "Can't open device /dev/ip2trace\n" );
56       exit ( 1 );
57    }
58 
59    act.sa_handler = quit;
60    /*act.sa_mask = 0;*/
61 	sigemptyset(&act.sa_mask);
62    act.sa_flags = 0;
63    act.sa_restorer = NULL;
64 
65    sigaction ( SIGTERM, &act, NULL );
66 
67 	ioctl ( fd,  1, namebuf );
68 
69 	printf ( "iiSendPendingMail %p\n",        namebuf[0] );
70 	printf ( "i2InitChannels %p\n",           namebuf[1] );
71 	printf ( "i2QueueNeeds %p\n",             namebuf[2] );
72 	printf ( "i2QueueCommands %p\n",          namebuf[3] );
73 	printf ( "i2GetStatus %p\n",              namebuf[4] );
74 	printf ( "i2Input %p\n",                  namebuf[5] );
75 	printf ( "i2InputFlush %p\n",             namebuf[6] );
76 	printf ( "i2Output %p\n",                 namebuf[7] );
77 	printf ( "i2FlushOutput %p\n",            namebuf[8] );
78 	printf ( "i2DrainWakeup %p\n",            namebuf[9] );
79 	printf ( "i2DrainOutput %p\n",            namebuf[10] );
80 	printf ( "i2OutputFree %p\n",             namebuf[11] );
81 	printf ( "i2StripFifo %p\n",              namebuf[12] );
82 	printf ( "i2StuffFifoBypass %p\n",        namebuf[13] );
83 	printf ( "i2StuffFifoFlow %p\n",          namebuf[14] );
84 	printf ( "i2StuffFifoInline %p\n",        namebuf[15] );
85 	printf ( "i2ServiceBoard %p\n",           namebuf[16] );
86 	printf ( "serviceOutgoingFifo %p\n",      namebuf[17] );
87 	printf ( "ip2_init %p\n",                 namebuf[18] );
88 	printf ( "ip2_init_board %p\n",           namebuf[19] );
89 	printf ( "find_eisa_board %p\n",          namebuf[20] );
90 	printf ( "set_irq %p\n",                  namebuf[21] );
91 	printf ( "ex_details %p\n",               namebuf[22] );
92 	printf ( "ip2_interrupt %p\n",            namebuf[23] );
93 	printf ( "ip2_poll %p\n",                 namebuf[24] );
94 	printf ( "service_all_boards %p\n",        namebuf[25] );
95 	printf ( "do_input %p\n",                 namebuf[27] );
96 	printf ( "do_status %p\n",                namebuf[26] );
97 	printf ( "open_sanity_check %p\n",        namebuf[27] );
98 	printf ( "open_block_til_ready %p\n",     namebuf[28] );
99 	printf ( "ip2_open %p\n",                 namebuf[29] );
100 	printf ( "ip2_close %p\n",                namebuf[30] );
101 	printf ( "ip2_hangup %p\n",               namebuf[31] );
102 	printf ( "ip2_write %p\n",                namebuf[32] );
103 	printf ( "ip2_putchar %p\n",              namebuf[33] );
104 	printf ( "ip2_flush_chars %p\n",          namebuf[34] );
105 	printf ( "ip2_write_room %p\n",           namebuf[35] );
106 	printf ( "ip2_chars_in_buf %p\n",         namebuf[36] );
107 	printf ( "ip2_flush_buffer %p\n",         namebuf[37] );
108 	//printf ( "ip2_wait_until_sent %p\n",      namebuf[38] );
109 	printf ( "ip2_throttle %p\n",             namebuf[39] );
110 	printf ( "ip2_unthrottle %p\n",           namebuf[40] );
111 	printf ( "ip2_ioctl %p\n",                namebuf[41] );
112 	printf ( "get_modem_info %p\n",           namebuf[42] );
113 	printf ( "set_modem_info %p\n",           namebuf[43] );
114 	printf ( "get_serial_info %p\n",          namebuf[44] );
115 	printf ( "set_serial_info %p\n",          namebuf[45] );
116 	printf ( "ip2_set_termios %p\n",          namebuf[46] );
117 	printf ( "ip2_set_line_discipline %p\n",  namebuf[47] );
118 	printf ( "set_line_characteristics %p\n", namebuf[48] );
119 
120 	printf("\n-------------------------\n");
121 	printf("Start of trace\n");
122 
123    while ( active ) {
124       cnt = read ( fd, &tbuf, sizeof tbuf );
125 
126       if ( cnt ) {
127          if ( tbuf.wrap ) {
128             printf ( "\nTrace buffer: wrap=%d, strip=%d, stuff=%d\n",
129                      tbuf.wrap, tbuf.strip, tbuf.stuff );
130          }
131          for ( i = 0, bc.value = 0; i < cnt; ++i ) {
132 				if ( !bc.hdr.codes ) {
133 					td = tbuf.buf[i] - ts;
134 					ts = tbuf.buf[i++];
135 					bc.value = tbuf.buf[i];
136 
137 					printf ( "\n(%d) Port %3d ", ts, bc.hdr.port );
138 
139 					fmt = kHex;
140 
141 					switch ( bc.hdr.cat )
142 					{
143 					case ITRC_INIT:
144 						printf ( "Init       %d: ", bc.hdr.label );
145 						break;
146 
147 					case ITRC_OPEN:
148 						printf ( "Open       %d: ", bc.hdr.label );
149 						break;
150 
151 					case ITRC_CLOSE:
152 						printf ( "Close      %d: ", bc.hdr.label );
153 						break;
154 
155 					case ITRC_DRAIN:
156 						printf ( "Drain      %d: ", bc.hdr.label );
157 						fmt = kInt;
158 						break;
159 
160 					case ITRC_IOCTL:
161 						printf ( "Ioctl      %d: ", bc.hdr.label );
162 						break;
163 
164 					case ITRC_FLUSH:
165 						printf ( "Flush      %d: ", bc.hdr.label );
166 						break;
167 
168 					case ITRC_STATUS:
169 						printf ( "GetS       %d: ", bc.hdr.label );
170 						break;
171 
172 					case ITRC_HANGUP:
173 						printf ( "Hangup     %d: ", bc.hdr.label );
174 						break;
175 
176 					case ITRC_INTR:
177 						printf ( "*Intr      %d: ", bc.hdr.label );
178 						break;
179 
180 					case ITRC_SFLOW:
181 						printf ( "SFlow      %d: ", bc.hdr.label );
182 						fmt = kInt;
183 						break;
184 
185 					case ITRC_SBCMD:
186 						printf ( "Bypass CMD %d: ", bc.hdr.label );
187 						fmt = kInt;
188 						break;
189 
190 					case ITRC_SICMD:
191 						printf ( "Inline CMD %d: ", bc.hdr.label );
192 						fmt = kInt;
193 						break;
194 
195 					case ITRC_MODEM:
196 						printf ( "Modem      %d: ", bc.hdr.label );
197 						break;
198 
199 					case ITRC_INPUT:
200 						printf ( "Input      %d: ", bc.hdr.label );
201 						break;
202 
203 					case ITRC_OUTPUT:
204 						printf ( "Output     %d: ", bc.hdr.label );
205 						fmt = kInt;
206 						break;
207 
208 					case ITRC_PUTC:
209 						printf ( "Put char   %d: ", bc.hdr.label );
210 						fmt = kChar;
211 						break;
212 
213 					case ITRC_QUEUE:
214 						printf ( "Queue CMD  %d: ", bc.hdr.label );
215 						fmt = kInt;
216 						break;
217 
218 					case ITRC_STFLW:
219 						printf ( "Stat Flow  %d: ", bc.hdr.label );
220 						fmt = kInt;
221 						break;
222 
223 					case ITRC_SFIFO:
224 						printf ( "SFifo      %d: ", bc.hdr.label );
225 						break;
226 
227 					case ITRC_VERIFY:
228 						printf ( "Verfy      %d: ", bc.hdr.label );
229 						fmt = kHex;
230 						break;
231 
232 					case ITRC_WRITE:
233 						printf ( "Write      %d: ", bc.hdr.label );
234 						fmt = kChar;
235 						break;
236 
237 					case ITRC_ERROR:
238 						printf ( "ERROR      %d: ", bc.hdr.label );
239 						fmt = kInt;
240 						break;
241 
242 					default:
243 						printf ( "%08x          ", tbuf.buf[i] );
244 						break;
245 					}
246 				}
247 				else
248 				{
249                --bc.hdr.codes;
250 					switch ( fmt )
251 					{
252 					case kChar:
253 						printf ( "%c (0x%02x) ",
254 							isprint ( tbuf.buf[i] ) ? tbuf.buf[i] : '.', tbuf.buf[i] );
255 						break;
256 					case kInt:
257 						printf ( "%d ", tbuf.buf[i] );
258 						break;
259 
260 					case kAddr:
261 					case kHex:
262 						printf ( "0x%x ", tbuf.buf[i] );
263 						break;
264 					}
265 				}
266          }
267       }
268       fflush ( stdout );
269       timeout.tv_sec = 0;
270       timeout.tv_usec = 250;
271       select ( 0, NULL, NULL, NULL, &timeout );
272 
273    }
274 	printf("\n-------------------------\n");
275 	printf("End of trace\n");
276 
277    close ( fd );
278 }
279 
280