-
Notifications
You must be signed in to change notification settings - Fork 9
/
l2main_l.cpp
483 lines (451 loc) · 11.2 KB
/
l2main_l.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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/***************************************************************
BayCom(R) Packet-Radio fuer IBM PC
OpenBCM-Mailbox
------------------------------------
AX.25 Data Link Layer main functions
------------------------------------
Copyright (C) Florian Radlherr
Taubenbergstr. 32
83627 Warngau
Alle Rechte vorbehalten / All Rights Reserved
***************************************************************/
//19990215 OE3DZW added sample init.l2
//19991028 Jan changed printf to trace, removed paramsg.h
#include "baycom.h"
#undef fopen
#undef fclose
l2_para_t *wl = &w;
static unsigned linenumber = 0;
static int assignkanal = -1;
static int validl1 = 0;
static int errors = 0;
unsigned damatimer[KANAELE]; // wenn DAMA-Master erkannt wurde
byte damafree[KANAELE]; // Es darf ein Schwung Frames gesendet werden
int tfaellig; // Flag fuer Layer2-Timer zu bedienen
int rekfl;
byte rxdaflag;
/*---------------------------------------------------------------------------*/
char *beftab[]=
{
"CONNECT", "MONITOR", "MYCALL", "LINKS", "MODE",
"MCALLS", "CNOT", "CNUSER", "L2CTEXT",
"DCALL", "BADRESS", "ASSIGN", "MHLEN",
"TXDELAY", "TAIL", "DWAIT", "BEACON",
"MAXFRAME", "XMITOK", "BTEXT", "DEVICE", "PEER", "PORT", "TXPORT",
"BUFFER", "MBUFFER", "RBUFFER", "TPORTS",
"PACLEN", "ITIME", "RETRY", "FRACK", "RESPTIME",
"LINKTIME", "IPOLL", "DISCTIME", "MSELECT", NULL
};
static enum befnum
{ unsinn,
uc, moni, my, li, mode,
mcalls, cnot, cnuser, l2ct,
dc, ba, assign, xmhlen,
txdelay, txtail, dwait, btime,
maxframe, xmitok, _btext, device, peer, port, txport,
dezwerte
} cmd = unsinn;
static unsigned *vartab[55];
/*---------------------------------------------------------------------------*/
void l2init(void)
{
port_t *allocblk;
unsigned int pnummer;
allocblk = (port_t *) xalloc((ports + 2) * sizeof(port_t));
for (pnummer = 0; pnummer <= ports; pnummer++)
{
p = pfeld[pnummer] = allocblk + pnummer;
callcopy(w.val.mycall, p->adrfield + 7);
callcopy(w.unproto, p->adrfield);
p->adrfield[13] |= 1;
p->pid = 0xf0;
p->lstate = disconnected;
p->adrfield[13] |= 1;
p->number = pnummer;
p->mode.l2ctext = 1;
lreset(0);
}
pfeld[MSGPORT] = allocblk + ports;
dobeacon(TRUE);
}
/*---------------------------------------------------------------------------*/
void initax25 (int einschalt)
{
if (einschalt)
{
ports = w.maxports;
meminit();
l2init();
}
l1init(einschalt);
}
/*---------------------------------------------------------------------------*/
void varset (void)
{
unsigned int x = 0;
vartab[x++]=&wl->maxbuf;
vartab[x++]=&wl->maxmon;
vartab[x++]=&wl->maxrx;
vartab[x++]=&wl->maxports;
vartab[x++]=&wl->val.paclen;
vartab[x++]=&wl->val.itime;
vartab[x++]=&wl->val.retry;
vartab[x++]=&wl->val.frack;
vartab[x++]=&wl->val.resptime;
vartab[x++]=&wl->val.linktime;
vartab[x++]=&wl->val.ipoll;
vartab[x++]=&wl->val.disctime;
vartab[x++]=&wl->val.mselect;
}
/*---------------------------------------------------------------------------*/
void beftest (char *befbuf)
{
unsigned int i;
char *befbuf1 = befbuf;
befbuf += blkill(befbuf);
if (! (*befbuf)) return; /* kein Kommando eingegeben */
cmd = (befnum) readcmd(beftab, &befbuf, 0);
for (i = strlen(befbuf) - 1; i; i--)
{
if (befbuf[i] == ' ') befbuf[i] = 0;
else break;
}
switch (cmd)
{
case unsinn:
{
error:
trace(replog, "init.l2", "line %d: %s", linenumber, befbuf1);
errors++;
} break;
case moni:
{
long unsigned mm = 0;
while (*befbuf)
{
if (*befbuf > '9' || *befbuf < '0') goto error;
mm |= 1 << (nextdez(&befbuf));
wl->val.monitor = mm;
}
} break;
case dc:
{
if (readcall(befbuf, wl->val.dcall) < 3) goto error;
} break;
case uc:
{
readcall(befbuf, wl->unproto);
} break;
case my:
{
readclist(befbuf, wl->val.mycall, 4);
} break;
case mcalls:
{
readclist(befbuf, wl->val.mcalls, 10);
} break;
case cnot:
{
readclist(befbuf, wl->val.cnot, 10);
} break;
case l2ct:
{
sprintf(wl->val.l2ctext, "%.79s\r", befbuf);
} break;
case xmhlen:
{
int l = nextdez(&befbuf);
i = 0;
while (l)
{
i++;
l /= 2;
}
wl->mhlen = (1 << i) - 1;
} break;
case assign:
{
static int firstassign = 1;
if (firstassign) firstassign = 0;
if (assignkanal >= KANAELE)
{
trace(serious, "init.l2", "too many channels defined");
errors++;
}
else
{
strupr(befbuf);
validl1 = 1;
if (! strcmp(befbuf, "KISS"))
wl->mode[++assignkanal].chmode = c_kiss;
else if (! strcmp (befbuf, "AXIP"))
wl->mode[++assignkanal].chmode=c_axip;
else if (! strcmp (befbuf, "LOOP"))
{
++assignkanal;
wl->internkanal = assignkanal;
}
else goto error;
channels = assignkanal;
}
} break;
case _btext:
{
if (validl1)
{
wl->mode[assignkanal].btext[0] = 0xf0;
strcpy(wl->mode[assignkanal].btext, befbuf);
}
} break;
case peer:
case device:
if (validl1) strcpy(wl->mode[assignkanal].device, befbuf);
break;
case port:
if (validl1)
{
wl->mode[assignkanal].port = atoi(befbuf);
wl->mode[assignkanal].txport = atoi(befbuf);
}
break;
case txport:
if (validl1) wl->mode[assignkanal].txport = atoi(befbuf);
break;
case ba:
{
if (validl1) readclist(befbuf, wl->mode[assignkanal].badress, 8);
} break;
case mode:
{
if (validl1)
{
l1_mode_t *mm = &wl->mode[assignkanal];
mm->hbaud = nextdez(&befbuf);
mm->t = mm->r = mm->z = mm->d = mm->c=0;
while (*befbuf)
{
switch (toupper(*befbuf))
{
case 'T': mm->t = 1; break;
case 'R': mm->r = 1; break;
case 'Z': mm->z = 1; break;
case 'D': mm->d = 1; break;
case 'C': mm->c = 1; break;
}
befbuf++;
}
}
} break;
case li:
{ byte fromcall[7];
byte tocall[7];
int j;
if (*befbuf)
{
befbuf += readcall(befbuf, tocall);
if (*befbuf)
{
for (j = 0; j < 2; j++)
{
for (i = 0; i < MAXLINKS; i++)
{
if ((callcmp(tocall, wl->linkcall[i]) && ! j) || (! wl->linkcall[i][0] && j))
{
befbuf += readcall(befbuf, fromcall);
if ((j = ischannel(fromcall)) < 0)
{
for (j = 0; j < MAXLINKS; j++)
{
if (callcmp(fromcall, wl->linkcall[j]))
{
wl->linkkanal[i] = j + 128;
goto found;
}
}
goto error;
}
else wl->linkkanal[i] = j;
found: wl->linkoption[i] = *befbuf;
callcopy(tocall, wl->linkcall[i]);
goto endlinks;
}
}
}
}
endlinks:;
}
} break;
case txdelay:
case txtail:
case dwait:
case btime:
case maxframe:
case xmitok:
{
if (validl1)
{
sscanf(befbuf, "%d", &i);
if (assignkanal < 0)
{
trace(serious, "init.l2", "ASSIGN statement missing");
goto error;
}
switch (cmd)
{
case txdelay: wl->mode[assignkanal].txdelay = i; break;
case txtail: wl->mode[assignkanal].txtail = i; break;
case dwait: wl->mode[assignkanal].dwait = i; break;
case btime: wl->mode[assignkanal].btime = i; break;
case maxframe: wl->mode[assignkanal].maxframe = i; break;
case xmitok: wl->mode[assignkanal].xmitok = i; break;
default: break;
}
}
} break;
default:
{
if (cmd >= dezwerte)
{
if (*befbuf == '$') sscanf(befbuf + 1, "%x", &i);
else sscanf(befbuf, "%d", &i);
// *vartab[cmd - dezwerte] = i;
}
}
}
}
/*---------------------------------------------------------------------------*/
void initparameter (void)
{
unsigned int i;
// default l2 parameters
memset(wl, 0, sizeof(l2_para_t));
wl->val.headeron = 1;
wl->val.mcalls[6] = 1;
wl->val.cnot[6] = 1;
wl->val.paclen = 256;
wl->val.itime = 2;
wl->val.ipoll = 255;
wl->val.dama = 36;
wl->val.retry = 40;
wl->val.frack = 30;
wl->val.resptime = 1;
wl->val.linktime = 3;
wl->val.qtime = 30;
wl->val.disctime = 0;
wl->val.monitor = 0xffff;
wl->val.blink = 1;
wl->val.mycall[6] = 1;
for (i = 0; i < KANAELE; i++)
{
l1_mode_t *mm = &wl->mode[i];
mm->txdelay = 20;
mm->txtail = 2;
mm->dwait = 30;
mm->hbaud = 9600;
mm->c = 1;
mm->tchannel = i;
mm->maxframe = 7;
mm->xmitok = 1;
mm->chmode = c_unassigned;
strcpy(mm->device, "/dev/null");
}
wl->mhlen = MHLEN;
wl->sccint[0] = 7;
wl->comkanal = wl->fskkanal = wl->internkanal = (-1);
wl->maxports = 201;
wl->maxbuf = BUFLEN;
wl->maxmon = 20;
wl->maxrx = 20;
wl->ipxkanal = (-1);
wl->unproto[6] = 1;
wl->kennung = 0xaa55;
}
/*---------------------------------------------------------------------------*/
static char l2f_init[] =
"; Sample OpenBCM Layer2 Parameterfile for AX.25\n"
";\n"
"dcall df0ar-8 ; Digicall\n"
"monitor 4\n"
"mselect 0\n"
"mcalls -0\n"
";\n"
";assign kiss\n"
";mode 19200cd\n"
";device /dev/ttyS0 ; under Windows: device COM2\n"
";\n"
";assign axip\n"
";peer digi.local.net\n"
";port 4866\n"
";\n"
"assign axip\n"
"peer localhost\n"
"port 4866 ; rx-port number (udp port, no raw axip)\n"
"txport 4867 ; different tx-port number\n"
";------\n";
/*---------------------------------------------------------------------------*/
void parainit (void)
{
FILE *parmf;
unsigned int i = 0;
char inbuf[142];
parmf = fopen(L2INITNAME, "rt");
if (! parmf)
{
parmf = fopen(L2INITNAME, "w+t");
if (parmf)
{
fwrite(l2f_init, sizeof(l2f_init) - 1, 1, parmf);
rewind(parmf);
}
}
if (parmf)
{
while (fgets(inbuf, sizeof(inbuf) - 1, parmf))
{
i = 0;
while (inbuf[i] && inbuf[i] != LF && inbuf[i] != CR && inbuf[i] != ';')
{
if (inbuf[i] == 9) inbuf[i] = ' '; // Tab weg
i++;
}
linenumber++;
if (i)
{
inbuf[i] = 0;
beftest(inbuf);
}
}
fclose(parmf);
}
else
{
perror("init.l2");
errors = 100;
}
}
/*---------------------------------------------------------------------------*/
void call_l2 (int off)
// ruft layer2 routinen auf
{
static int sequence = 0;
if (! sequence)
{
sequence = 1;
paralloc();
initparameter();
varset();
parainit();
initax25(1);
}
if (off && sequence == 1)
{
sequence = 2;
initax25(0);
}
tfaellig += 2;
if (sequence == 1)
{
layer1();
layer2();
}
}