-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAX25DUMP.C
281 lines (270 loc) · 7.57 KB
/
AX25DUMP.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* AX25 header tracing
* Copyright 1991 Phil Karn, KA9Q
*/
/* Mods by PA0GRI */
/* Tracing to sockets, mods April '95 by Johan. K. Reinalda, WG7J */
#include "global.h"
#ifdef AX25
#include "mbuf.h"
#include "proc.h"
#include "ax25.h"
#include "lapb.h"
#include "trace.h"
#include "socket.h"
#ifdef UNIX
/* We can't use usputc since we don't intercept that call for rerouting to
the trace screen (for efficiency or stubbornness, hard to say which! n5knx
*/
#define PUTNL(s) usputs(s,"\n")
#else
#define PUTNL(s) usputc(s,'\n')
#endif
static char *decode_type __ARGS((int16 type));
/* Dump an AX.25 packet header */
void
ax25_dump(s,bpp,check)
int s;
struct mbuf **bpp;
int check; /* Not used */
{
char tmp[AXBUF];
char frmr[3];
int control,pid,seg;
int16 type;
int unsegmented;
struct ax25 hdr;
char *hp;
#ifdef MONITOR
if (!Trace_compact_header)
#endif
usprintf(s,"AX25: ");
/* Extract the address header */
if(ntohax25(&hdr,bpp) < 0){
/* Something wrong with the header */
usprintf(s," bad header!\n");
return;
}
usprintf(s,"%s",pax25(tmp,hdr.source));
usprintf(s,"->%s",pax25(tmp,hdr.dest));
if(hdr.ndigis > 0){
#ifdef MONITOR
if (!Trace_compact_header)
#endif
usprintf(s," v");
for(hp = hdr.digis[0]; hp < &hdr.digis[hdr.ndigis][0];
hp += AXALEN){
/* Print digi string */
usprintf(s," %s%s",pax25(tmp,hp),
(hp[ALEN] & REPEATED) ? "*":"");
}
}
if((control = PULLCHAR(bpp)) == -1)
return;
type = ftype(control);
#ifdef MONITOR
if (!Trace_compact_header || (type != I && type != UI))
{
#endif
usprintf(s," %s",decode_type(type));
/* Dump poll/final bit */
if(control & PF){
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, "!");
else
#endif
switch(hdr.cmdrsp){
case LAPB_COMMAND:
usprintf(s,"(P)");
break;
case LAPB_RESPONSE:
usprintf(s,"(F)");
break;
default:
usprintf(s,"(P/F)");
break;
}
}
#ifdef MONITOR
}
#endif
/* Dump sequence numbers */
#ifdef MONITOR
if (!Trace_compact_header)
#endif
if((type & 0x3) != U) /* I or S frame? */
usprintf(s," NR=%d",(control>>5)&7);
if(type == I || type == UI){
#ifdef MONITOR
if (!Trace_compact_header)
#endif
if(type == I)
usprintf(s," NS=%d",(control>>1)&7);
/* Decode I field */
if((pid = PULLCHAR(bpp)) != -1){ /* Get pid */
if(pid == PID_SEGMENT){
unsegmented = 0;
seg = PULLCHAR(bpp);
#ifdef MONITOR
if (!Trace_compact_header)
#endif
usprintf(s,"%s remain %u",seg & SEG_FIRST ?
" First seg;" : "",seg & SEG_REM);
if(seg & SEG_FIRST)
pid = PULLCHAR(bpp);
} else
unsegmented = 1;
switch(pid){
case PID_SEGMENT:
PUTNL(s);
break; /* Already displayed */
case PID_ARP:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " ARP ");
else
#endif
usprintf(s," pid=ARP\n");
arp_dump(s,bpp);
break;
case PID_RARP:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " RARP ");
else
#endif
usprintf(s," pid=RARP\n");
arp_dump(s,bpp);
break;
#ifdef NETROM
case PID_NETROM:
#ifdef MONITOR
if (Trace_compact_header)
usputs(s, " ");
else
#endif
usprintf(s," pid=NET/ROM\n");
/* Don't verify checksums unless unsegmented */
netrom_dump(s,bpp,unsegmented);
break;
#endif
case PID_IP:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " IP ");
else
#endif
usprintf(s," pid=IP\n");
/* Don't verify checksums unless unsegmented */
ip_dump(s,bpp,unsegmented);
break;
case PID_X25:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " X.25\n");
else
#endif
usprintf(s," pid=X.25\n");
break;
case PID_TEXNET:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " TEXNET\n");
else
#endif
usprintf(s," pid=TEXNET\n");
break;
case PID_NO_L3:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, "\n");
else
#endif
usprintf(s," pid=Text\n");
break;
default:
#ifdef MONITOR
if (Trace_compact_header)
usprintf(s, " [0x%x]\n", pid);
else
#endif
usprintf(s," pid=0x%x\n",pid);
}
}
else PUTNL(s);
} else if(type == FRMR && pullup(bpp,frmr,3) == 3){
usprintf(s,": %s",decode_type(ftype(frmr[0])));
usprintf(s," Vr = %d Vs = %d",(frmr[1] >> 5) & MMASK,
(frmr[1] >> 1) & MMASK);
if(frmr[2] & W)
usprintf(s," Invalid control field");
if(frmr[2] & X)
usprintf(s," Illegal I-field");
if(frmr[2] & Y)
usprintf(s," Too-long I-field");
if(frmr[2] & Z)
usprintf(s," Invalid seq number");
PUTNL(s);
} else
PUTNL(s);
}
static char *
decode_type(type)
int16 type;
{
switch(type){
case I:
return "I";
case SABM:
return "SABM";
case DISC:
return "DISC";
case DM:
return "DM";
case UA:
return "UA";
case RR:
return "RR";
case RNR:
return "RNR";
case REJ:
return "REJ";
case FRMR:
return "FRMR";
case UI:
return "UI";
default:
return "[invalid]";
}
}
/* Return 1 if this packet is directed to us, 0 otherwise. Note that
* this checks only the ultimate destination, not the digipeater field
*/
int
ax_forus(iface,bp)
struct iface *iface;
struct mbuf *bp;
{
struct mbuf *bpp;
char dest[AXALEN];
/* Duplicate the destination address */
if(dup_p(&bpp,bp,0,AXALEN) != AXALEN){
free_p(bpp);
return 0;
}
if(pullup(&bpp,dest,AXALEN) < AXALEN)
return 0;
if(addreq(dest,iface->hwaddr))
return 1;
else
if(addreq(dest,iface->ax25->cdigi))
return 1;
#ifdef MAILBOX
else
if(addreq(dest,iface->ax25->bbscall))
return 1;
#endif
else
return 0;
}
#endif /* AX25 */