-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBPQ.C
412 lines (382 loc) · 10.9 KB
/
BPQ.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/* code to allow nos to talk directly to bpqcode
*
* by paul h launspach n5faz
* (c) 1993,1994 FazCom
* 4-13-93
*/
/* $Id: bpq.c 1.5 1994/03/23 06:07:23 fz-phl Exp $ */
/* $Log: bpq.c $
* Revision 1.5 1994/03/23 06:07:23 fz-phl
* fixed compiles with new karn.
* cleaned up the ifdefs.
* added macro for DUMP and NET_ROUTE to bpq.c.
* bpq_raw now checks for free bufs in bpq before sending frames.
*
* Revision 1.4 1994/03/11 14:46:16 fz-phl
* added ifdef BPQJNOS for printf -> tprintf macro and
* for different dump and net_route calls.
*
* Revision 1.3 1994/03/11 14:36:32 Johan
* changed printf's to tprintf's
*
* Revision 1.2 1994/03/11 14:29:02 fz-phl
* added ifdef BPQSOCK and changed dump and netroute
* calls for jnos.
*
* Revision 1.1 1994/03/11 02:24:15 fz-phl
* Initial revision
*
*/
#include <stdio.h>
#include <dos.h>
#include "global.h"
#include "mbuf.h"
#include "proc.h"
#include "iface.h"
#include "ax25.h"
#include "trace.h"
#include "pktdrvr.h"
#include "config.h"
#ifdef BPQ
#include "bpq.h"
#ifdef BPQJNOS /* change printf to tprintf for jnos etc */
#define printf tprintf
#define DUMP(a,b,c) dump((a),(b),CL_AX25,(c))
#define NET_ROUTE(a,b) net_route((a),CL_AX25,(b))
#else
#define DUMP dump
#define NET_ROUTE net_route
#endif
static int bpq_stop (struct iface *iface);
static int bpq_raw (struct iface *iface, struct mbuf *bp);
struct bpqinfo Bpqinfo = {0};
extern int32 Ip_addr;
/* attach an interface to bpqcode
*
* init bpq:
* argv[0] = bpq
* argv[1] = init
* argv[2] = bpq_host intrupt vec in hex
* argv[3] = bpq_host stream number
* argv[4] = number of outgoing bpq_host sessions optional
*
* attach an iface:
* argv[0] = bpq
* argv[1] = bpq radio port number
* argv[2] = lable
* argv[3] = mtu optional
* argv[4] = callsign optional
*
*/
int
bpq_attach(argc,argv,p)
int argc;
char *argv[];
void *p;
{
char vec;
char streem;
int port;
int users;
uint16 mtu;
char hwaddr[AXALEN];
struct iface *ifp;
char *cp;
char buffer[6];
static char g8bpq[] = "G8BPQ";
if(strncmp(argv[1],"init",strlen(argv[1])) == 0){
if(argc < 4){
#ifdef BPQSOCK
printf("Usage: attach bpq init <vec> <stream> [<sessions>]\n");
#else
printf("Usage: attach bpq init <vec> <stream>\n");
#endif
return -1;
}
vec = htoi(argv[2]);
streem = atoi(argv[3]);
#ifdef BPQSOCK
users = argc > 4 ? atoi(argv[4]) : 0;
#endif
if(!Bpqinfo.vec){
/* check that bpqcode is loaded */
long vector = (long)getvect(vec);
movblock(FP_OFF(vector)-7, FP_SEG(vector),
FP_OFF(buffer),FP_SEG(buffer),strlen(g8bpq));
if(strncmp(buffer,g8bpq,strlen(g8bpq))){
printf("Bpqcode not found !\n");
return -1;
}
if(streem < 1 || streem > BPQMAXSTREAM){
printf("Stream must be between 1 and %d.\n",BPQMAXSTREAM);
return -1;
}
#ifdef BPQSOCK
if(users < 0 || streem + users >= BPQMAXSTREAM){
printf("Stream plus sessions must be less than %u.\n",
BPQMAXSTREAM);
return -1;
}
#endif
Bpqinfo.vec = vec;
Bpqinfo.monstream = streem;
Bpqinfo.minfree = bpq_int(BPQ_BUF,1,0,NULLCHAR);
#ifdef BPQSOCK
Bpqinfo.maxstream = streem + users;
Bpqinfo.window = BPQWINDOW;
Bpqinfo.rxproc = newproc("Bpq receive",256,bpqrxp,0,NULL,NULL,0);
#endif
#ifdef TRACE
Bpqinfo.ift.type = CL_AX25;
#ifndef BPQJNOS
Bpqinfo.ift.trace = ax25_dump;
Bpqinfo.ift.addrtest = ax_forus;
#endif
#endif /* trace */
} else {
printf("Bpq already initalized");
return -1;
}
return 0;
}
if(!Bpqinfo.vec){
printf("Bpq must be initilized with: attach bpq init <vec> <stream>\n");
return 1;
}
port = atoi(argv[1]);
mtu = (argc >3) ? max(256,atoi(argv[3])) : Paclen;
if(port < 1 || port > BPQMAXPORT){
printf("Port must be between 1 and %d.\n",BPQMAXPORT);
return -1;
}
if(Bpqinfo.ports[--port] != NULLIF){
printf("Port already used");
return -1;
}
if(if_lookup(argv[2]) != NULLIF){
printf("Interface %s already exists\n",argv[2]);
return -1;
}
if(Bpqinfo.tport[port] != NULLIF){
ifp = Bpqinfo.tport[port];
free(ifp->name);
Bpqinfo.tport[port] = NULLIF;
Bpqinfo.maxtrace--;
} else ifp = (struct iface *)callocw(1,sizeof(struct iface));
ifp->name = strdup(argv[2]);
ifp->addr = Ip_addr;
ifp->mtu = mtu;
ifp->dev = port+1;
ifp->raw = bpq_raw;
ifp->stop = bpq_stop;
setencap(ifp,"AX25");
ifp->hwaddr = mallocw(AXALEN);
if(argc > 4 && setcall(hwaddr,argv[4]) == 0)
memcpy(ifp->hwaddr,hwaddr,AXALEN);
else
memcpy(ifp->hwaddr,Mycall,AXALEN);
Bpqinfo.ports[port] = ifp;
ifp->next = Ifaces;
Ifaces = ifp;
#ifndef BPQJNOS
cp = if_name(ifp," tx");
ifp->txproc = newproc(cp,768,if_tx,0,ifp,NULL,0);
#endif
/* tell bpqcode to send us any received frames */
if(!Bpqinfo.maxport++
#ifdef TRACE
&& !Bpqinfo.maxtrace
#endif
) bpq_int(BPQ_SET,Bpqinfo.monstream,BPQ_MONITOR,NULLCHAR);
return 0;
}
/* detach a bpq interface
*/
static int
bpq_stop(iface)
struct iface *iface;
{
int port = iface->dev;
Bpqinfo.ports[port-1] = NULLIF;
if(--Bpqinfo.maxport == 0
#ifdef TRACE
&& !Bpqinfo.maxtrace
#endif
) /* stop bpqcode sending us frames */
bpq_int(BPQ_SET,Bpqinfo.monstream,0,NULLCHAR);
return 0;
}
/* raw send
*/
static int
bpq_raw(iface,bp)
struct iface *iface;
struct mbuf *bp;
{
uint16 i;
if(iface == NULLIF || bp == NULLBUF)
return -1;
if(bp->next != NULLBUF){
/* Copy to contiguous buffer */
struct mbuf *bp1 = copy_p(bp,len_p(bp));
free_p(bp);
if((bp = bp1) == NULLBUF)
return -1;
}
i = bpq_int(BPQ_BUF,1,0,NULLCHAR);
Bpqinfo.minfree = min(i,Bpqinfo.minfree);
if(i>20){ /* make sure there are free buf in bpqcode */
Bpqinfo.sendcnt++;
iface->rawsndcnt++;
iface->lastsent = secclock();
bpq_int(BPQ_TX,iface->dev,bp->cnt,bp->data);
}
free_p(bp);
return 0;
}
/* bpq raw receive handler
* called every tick
*/
void
bpqtimer(void)
{
char port;
int txf;
/* no bpq ports in use */
if(!Bpqinfo.maxport)
return;
for(;;){
/* get a mbuf to put received frame in */
if(Bpqinfo.buffer == NULLBUF)
if((Bpqinfo.buffer = alloc_mbuf(BPQSIZE +
sizeof(struct iface))) == NULLBUF)
return;
else
Bpqinfo.buffer->data += sizeof(struct iface);
/* no more frames at this time so return */
if((Bpqinfo.buffer->cnt = bpq_int(BPQ_RX,Bpqinfo.monstream,0,
Bpqinfo.buffer->data)) == 0)
return;
port = Bpqinfo.buffer->data[2]; /* get port number from bpqheader */
Bpqinfo.buffer->data += BPQHEADER; /* move past the 5 byte */
Bpqinfo.buffer->cnt -= BPQHEADER; /* header bpq sends us */
txf = port & 0x80; /* this is a transmited frame */
port &= 0x7f; /* mask off is tx frame bit */
if(port-- > BPQMAXPORT)
continue;
#ifdef TRACE
/* trace any unattached bpq ports */
if(Bpqinfo.tport[port] != NULLIF){
DUMP(Bpqinfo.tport[port],
txf ? IF_TRACE_OUT : IF_TRACE_IN,Bpqinfo.buffer);
continue;
}
#endif /* TRACE */
/* received frame not on a port we want so get another */
if(Bpqinfo.ports[port] == NULLIF)
continue;
/* send tracing done here so we can also see frames
* sent by other apps and bpq itself. */
if(txf){
DUMP(Bpqinfo.ports[port],IF_TRACE_OUT,Bpqinfo.buffer);
continue;
}
NET_ROUTE(Bpqinfo.ports[port],Bpqinfo.buffer);
Bpqinfo.buffer = NULLBUF;
Bpqinfo.recvcnt++;
}
}
/* common interupt routine for all bpq_host calls
*/
uint16
bpq_int(command,stream,flag,bp)
char command;
char stream;
int flag;
char *bp;
{
union REGS regs;
struct SREGS sregs;
uint16 rval;
segread(&sregs);
regs.h.ah = command;
regs.h.al = stream;
switch(command){
case BPQ_SET:
case BPQ_CONNECT:
regs.h.ch = regs.h.dh = 0;
regs.h.dl = hibyte(flag); /* appl mask */
regs.h.cl = lobyte(flag); /* appl flags */
Bpqinfo.contcnt++;
break;
case BPQ_SEND:
case BPQ_TX:
regs.x.cx = flag;
sregs.es = FP_SEG(bp);
regs.x.si = FP_OFF(bp);
Bpqinfo.txcnt++;
break;
case BPQ_RECV:
case BPQ_RX:
regs.x.di = FP_OFF(bp);
sregs.es = FP_SEG(bp);
Bpqinfo.rxcnt++;
break;
case BPQ_BUF:
case BPQ_UNACK:
case BPQ_RECVQUE:
regs.h.ah = BPQ_BUF;
Bpqinfo.contcnt++;
break;
case BPQ_USERCALL:
case BPQ_PACLEN:
case BPQ_MAXFR:
regs.h.ah = BPQ_USERCALL;
sregs.es = FP_SEG(bp);
regs.x.di = FP_OFF(bp);
Bpqinfo.contcnt++;
break;
case BPQ_BEACON:
regs.x.dx = 1;
sregs.es = FP_SEG(bp);
regs.x.si = FP_OFF(bp);
regs.x.cx = flag;
case BPQ_STATE:
case BPQ_ACKSTATE:
case BPQ_TIME:
Bpqinfo.contcnt++;
break;
default:
return -1;
}
int86x(Bpqinfo.vec,®s,®s,&sregs);
switch(command){
case BPQ_USERCALL:
bp[10] = '\0';
case BPQ_TIME:
rval = regs.x.ax;
break;
case BPQ_PACLEN:
case BPQ_RECVQUE:
rval = regs.x.bx;
break;
case BPQ_RECV:
case BPQ_RX:
case BPQ_UNACK:
rval = regs.x.cx;
break;
case BPQ_BUF:
rval = regs.x.dx;
break;
case BPQ_MAXFR:
rval = max(regs.x.cx,regs.x.dx);
break;
case BPQ_STATE:
rval = (regs.x.dx << 8) | regs.x.cx;
break;
default:
rval = 0;
}
return rval;
}
#endif /* BPQ */