forked from oe5hpm/openBCM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
l2interf.cpp
394 lines (357 loc) · 10.1 KB
/
l2interf.cpp
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
/***************************************************************
BayCom(R) Packet-Radio fuer IBM PC
OpenBCM-Mailbox
Layer1-Driver
-------------------------------------------------
AX.25 Data Link Layer Service Interface Functions
-------------------------------------------------
Copyright (C) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights reserved
***************************************************************/
#include "baycom.h"
/*---------------------------------------------------------------------------*/
int glob_messages = 0;
unsigned channels = 0;
int l2int = L2INT;
/*---------------------------------------------------------------------------*/
void chrout (byte zeichen)
//*************************************************************************
//
// sendet ein Zeichen auf einem bestimmten Port im AX.25-Protokol
// Auf Port 0 wird grundsaetzlich UI gesendet
//
//*************************************************************************
{
frame_t *td = p->txinfout;
if (p->number && ! p->lstate) return;
if (! td || td->len == MAXLEN)
{
disable();
if (bfree)
{
alloc(td);
enable();
td->next = p->txinfout;
p->txinfout = td;
td->len = 0;
td->index = 0;
}
else
{
enable();
}
}
td->inhalt[(td->len)++] = zeichen;
p->itimer = w.val.itime;
#ifdef __FLAT__
if (chainlen(p->txinfout) > 1)
{
p->itimer = 0;
tryinfo();
}
#endif
}
/*---------------------------------------------------------------------------*/
int chrout_frame (frame_t far *frame)
{
frame_t *tf;
if (bfree)
{
alloc(tf);
_fmemcpy(tf, frame, sizeof(frame_t));
tf->next = p->txinfout;
p->txinfout = tf;
p->itimer = 0;
tryinfo();
return OK;
}
return NO;
}
/*---------------------------------------------------------------------------*/
unsigned getlinks (void)
{
unsigned int i;
unsigned logins = 0;
for (i = 1; i < ports; i++)
if (pfeld[i] && pfeld[i]->lstate) logins++;
return logins;
}
/*---------------------------------------------------------------------------*/
static int chrin_frame (frame_t *fr)
{
if (p->busy && (chainlen(p->rxinfout) <= (w.maxrx / 2)))
rnrfrei(p->number);
if (p->rxinfout)
{
frame_t *rd = vonhinten(&(p->rxinfout));
_fmemcpy(fr, rd, sizeof(frame_t));
return OK;
}
else return NO;
}
/*---------------------------------------------------------------------------*/
static int chrin (unsigned int channel)
//*************************************************************************
//
// holt ein Zeichen aus dem Empfangspuffer.
// ist nichts im Puffer, so wird EOF uebergeben.
//
// Aus Port 0 kommt Monitorinformation, aufbereitet in ASCII,
// allerdings mit Farbinformation (0xff, 0xfe, 0xfd) versehen
//
//*************************************************************************
{
frame_t *rd = p->rxinfloc;
if (rd && rd->len == rd->index)
{
disable();
dealloc(p->rxinfloc);
enable();
rd = NULL;
}
if (! rd)
{
if (p->busy && (chainlen(p->rxinfout) <= (w.maxrx / 2)))
rnrfrei(p->number);
if (p->rxinfout)
{
rd = p->rxinfloc = vonhinten(&(p->rxinfout));
rd->index++; // jump over PID byte
if (rd->channel && p->number && ! glob_messages)
{
rd->index = rd->len;
return EOF;
}
}
else
return EOF;
}
if (rd->channel == channel)
return rd->inhalt[(rd->index)++];
else
return EOF;
}
/*---------------------------------------------------------------------------*/
static unsigned rxvalid (void)
{
frame_t *rd = p->rxinfloc;
if (rd && rd->len == rd->index)
{
disable();
dealloc(p->rxinfloc);
enable();
rd = NULL;
}
if (! rd)
{
if (p->busy && (chainlen(p->rxinfout) <= (w.maxrx / 2)))
rnrfrei(p->number);
if (p->rxinfout)
{
rd = p->rxinfloc = vonhinten(&(p->rxinfout));
rd->index++; // jump over PID byte
if (rd->channel && p->number && ! glob_messages)
{
rd->index = rd->len;
return NO;
}
}
else
return NO;
}
if (! rd->channel) return OK;
else return NO;
}
/*---------------------------------------------------------------------------*/
/*
static unsigned rxvalid(void)
{
frame_t *rd=p->rxinfloc;
if (rd->len == rd->index)
{
disable();
dealloc(p->rxinfloc);
enable();
rd=NULL;
}
if (! rd)
{
if (p->busy && (chainlen(p->rxinfout) <= (w.maxrx / 2)))
rnrfrei(p->number);
if (p->rxinfout)
rd = p->rxinfloc = vonhinten(&(p->rxinfout));
else
return 0;
}
return (rd->len - rd->index);
}
*/
/*---------------------------------------------------------------------------*/
#ifndef __FLAT__
void interrupt l2aufruf (int _bp, int _di, int _si, int ds, int es,
unsigned _dx, unsigned _cx, unsigned _bx, unsigned _ax)
{
static unsigned ss, sp, ax, bx, cx, dx, bp;
static char far *ptr;
asm jmp weiter;
asm db 'BayCom'
asm db 3
asm db 0
weiter:
/*
if (_ax < 128)
{ _ax = layer1 (_ax);
if (_ax) _dx = _DS;
else _dx = 0;
return;
}
*/
disable();
if (rekfl)
{
enable();
sound(1800);
delay(1000);
nosound();
return;
}
rekfl = TRUE;
ax = _ax;
bx = _bx;
cx = _cx;
dx = _dx;
bp = _BP;
ss = _SS;
sp = _SP;
_SS = FP_SEG(stack); // Statisches Array zuweisen
_SP = FP_OFF(stack) + STACKLEN; // Stackpointer ganz oben
_BP = _SP;
enable();
ptr = (char far *) MK_FP(dx, cx);
dx = FP_SEG((void far *) &w);
#else
int l2aufruf(int ax, int bx, int cx, byte *ptr)
{
#endif
p = pfeld[bx];
switch (ax)
{
case l2_put_char: chrout(cx); break; // BX stream CX char
case l2_set_pid: p->pid = cx; break; // BX stream CX contains new PID
case l2_get_lstate: p->mode.open = 1; ax = p->lstate; break;
case l2_get_outstanding: ax = p->outstanding; break;
case l2_put_flush: p->itimer = 0; tryinfo(); break; // BX stream
case l2_put_frame: ax = chrout_frame((frame_t *) ptr); break; // BX stream *DX:CX info field (including PID) (char *)
case l2_get_char: ax = chrin(0); break; // BX stream return AX
case l2_get_msg: ax = chrin(1); break; // BX stream return AX
case l2_get_frame: ax = chrin_frame((frame_t *) ptr); break; // BX stream return *DX:AX (char *)
case l2_put_free: // BX stream return AX
ax = 0;
if (((int) bx) == (-1))
dobeacon(TRUE);
else
{
#ifndef __FLAT__
if (chainlen(p->txinfout) <=
((w.mode[p->channel].maxframe * w.val.paclen) / 330 + 2) && bfree) ax = 255;
#else
if (chainlen(p->txinfout) <= 15 && bfree) ax = 255;
#endif
}
break;
case l2_get_valid: ax = rxvalid(); break; // BX stream return AX
case l2_connect_: // BX stream
_fmemcpy(l2buf, ptr + 1, 70);
connect(l2buf, l2buf + 7, ptr[0]);
break;
case l2_disconnect: disconnect(cx); break; // BX stream CX mode
case l2_get_l1state: ax = l1state(bx); break; // BX channel return AX
case l2_get_free: ax = chainlen(bfree); break; // return AX
case l2_get_channels: ax = channels; break; // return AX
case l2_get_streams: ax = ports; break; // return AX
case l2_get_mhlen: ax = w.mhlen; break; // return AX
case l2_get_parlen: ax = sizeof(w); break; // return AX
case l2_get_ticker: // return DX:AX (time_t)
#ifndef __FLAT__
ax = (unsigned) w.zeit;
dx = (*(((unsigned *) &w.zeit) + 1));
#else
ax = 0; // dx=(char *)time(NULL);
#endif
break;
case l2_get_newdata: ax = 0; break; // return AX (stream)
case l2_set_terminal: // BX 0:terminal off 1:terminal on 2:return state
if (bx != 2)
{
if (w.val.blink == 3) w.val.blink = 2;
w.sccon = bx;
}
ax = w.sccon;
break;
case l2_set_handler: break; // *DX:CX void interrupt (*handler)(...) (AX=stream)
case l2_set_msg: glob_messages = 1; break;
case l2_ptr_stream: ax = (unsigned) pfeld[bx]; break; // BX stream return *DX:AX (stream_t *)
case l2_ptr_l1_mode: ax = (unsigned) &w.mode[bx]; break; // BX channel return *DX:AX (l1_mode_t *)
case l2_ptr_values: ax = (unsigned) &w.val; break; // return *DX:AX (l2_value_t *)
case l2_ptr_mheard: ax = (unsigned) l2_mhlist; break; // return *DX:AX (mheard_t *)
case l2_ptr_par: ax = (unsigned) &w; break; // return *DX:AX (unknown *)
case l2_ptr_version: ax = (unsigned) VNUMMER; break; // return *DX:AX (char *)
#ifndef __FLAT__
default:
if (ax == 0xfffe)
{
for (unsigned int i = 0; pfeld[i]; i++)
{
if (pfeld[i]->lstate > disconnected)
{
printf("\aDisconnect streams before turning off.\n");
ax = 0;
goto end;
}
}
ax++;
}
if (ax == 0xffff)
{ /*
if (l1_user_on)
{
printf("\aL1-user still alive. Remove it and try again.\n");
ax = 0;
goto end;
}
*/
initax25(0);
freemem(((unsigned far *) MK_FP(_psp,0x2c))[0]);
freemem(_psp);
}
#endif
}
#ifndef __FLAT__
end:
disable();
rekfl = 0;
_SS = ss;
_SP = sp;
_BP = bp;
_ax = ax;
_dx = dx;
#else
return ax;
#endif
}
/*---------------------------------------------------------------------------*/
void intinit (int ein)
{
#ifndef __FLAT__
static void interrupt (*altvec47) (...);
if (ein)
{
altvec47 = getvect(l2int);
setvect(l2int, (void interrupt (*)(...)) l2aufruf);
}
else
setvect(l2int, altvec47);
#endif
}