-
Notifications
You must be signed in to change notification settings - Fork 70
/
interface.c
1945 lines (1649 loc) · 58.3 KB
/
interface.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
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* **************************************************************** *
* *
* APRX -- 2nd generation APRS iGate and digi with *
* minimal requirement of esoteric facilities or *
* libraries of any kind beyond UNIX system libc. *
* *
* (c) Matti Aarnio - OH2MQK, 2007-2014 *
* *
* **************************************************************** */
#include "aprx.h"
#include <sys/socket.h>
/*
* The interface subsystem describes all interfaces in one
* coherent way, independent of their actual implementation.
*
*/
/*
<interface>
serial-device /dev/ttyUSB1 19200 8n1 KISS
tx-ok false # receive only (default)
callsign OH2XYZ-R2 # KISS subif 0
initstring "...." # initstring option
timeout 900 # 900 seconds of no Rx
</interface>
<interface>
serial-device /dev/ttyUSB2 19200 8n1 KISS
initstring "...."
timeout 900 # 900 seconds of no Rx
<kiss-subif 0>
callsign OH2XYZ-2
tx-ok true # This is our transmitter
</kiss-subif>
<kiss-subif 1>
callsign OH2XYZ-R3 # This is receiver
tx-ok false # receive only (default)
</kiss-subif>
</interface>
<interface>
tcp-device 172.168.1.1 4001 KISS
tx-ok false # receive only (default)
callsign OH2XYZ-R4 # KISS subif 0
initstring "...." # initstring option
timeout 900 # 900 seconds of no Rx
</interface>
<interface>
ax25-device OH2XYZ-6 # Works only on Linux systems
tx-ok true # This is also transmitter
</interface>
*/
struct aprx_interface **all_interfaces;
int all_interfaces_count;
int top_interfaces_group;
// Init-code stores this with ifindex = 0.
// This is necessary even for system where igate is removed
struct aprx_interface aprsis_interface = {
IFTYPE_APRSIS, 0, 0, 0, "APRSIS",
{'A'<<1,'P'<<1,'R'<<1,'S'<<1,'I'<<1,'S'<<1, 0x60},
0, NULL,
0, 0, 0, // subif, txrefcount, tx_ok
1, 1, 0, // telemeter-to-is, telemeter-to-rf, telemeter-newformat
0, NULL,
NULL,
#ifdef ENABLE_AGWPE
NULL,
#endif
NULL,
0, NULL
};
int interface_is_beaconable(const struct aprx_interface *aif)
{
switch (aif->iftype) {
case IFTYPE_AX25:
case IFTYPE_SERIAL:
case IFTYPE_TCPIP:
case IFTYPE_NULL:
case IFTYPE_APRSIS:
// case IFTYPE_AGWPE:
// These are beaconable.
return 1;
default:
break;
}
return 0;
}
int interface_is_telemetrable(const struct aprx_interface *aif) {
// Check if the interface type is really an RF rx and/or tx
switch (aif->iftype) {
case IFTYPE_AX25:
case IFTYPE_SERIAL:
case IFTYPE_TCPIP:
// case IFTYPE_AGWPE:
// These are real interfaces, and telemetry sources
return 1;
default:
break;
}
return 0;
}
#ifndef DISABLE_IGATE
/*
* A helper for interface_receive_ax25() - analyze 3rd-party packets received
* via radio. If data content inside has path saying "TCPIP" or "TCPXX", consider
* the packet to be indication that fromcall is an IGate.
*/
static void rx_analyze_3rdparty( historydb_t *historydb, struct pbuf_t *pb )
{
const char *e = pb->data + pb->packet_len - 6;
const char *p = pb->info_start;
int from_igate = 0;
history_cell_t *hist_rx;
if (!p) return; // Bad packet..
++p;
for ( ; p < e; ++p ) {
if (*p == ':') break;
if (*p == ',') {
// The "TCPIP*" or "TCPXX*" will always have preceding ","
if (memcmp(",TCPIP*", p, 7) == 0) {
from_igate = 1;
break;
}
if (memcmp(",TCPXX*", p, 7) == 0) {
from_igate = 1;
break;
}
} // Start with 'T'.
}
if (!from_igate) return; // Not recognized as being sent from another TX-IGATE
// OK, this packet originated from an TX-IGATE
// Insert it afresh
hist_rx = historydb_insert_heard(historydb, pb);
if (hist_rx != NULL) {
// Explicitly mark it as "received from APRSIS"
// The packet was received from a TX-IGATE, therefore
// the source of that packet is now logged as "from APRSIS".
hist_rx->last_heard[0] = pb->t;
}
}
#endif
static char *interface_default_aliases[] = { "RELAY","WIDE","TRACE" };
static void interface_store(struct aprx_interface *aif)
{
if (debug)
printf("interface_store() aif->callsign = '%s'\n", aif->callsign);
// Init the interface specific Erlang accounting
erlang_add(aif->callsign, ERLANG_RX, 0, 0);
all_interfaces_count += 1;
all_interfaces = realloc(all_interfaces,
sizeof(*all_interfaces) * all_interfaces_count);
all_interfaces[all_interfaces_count -1] = aif;
if (aif->ifindex < 0)
aif->ifindex = all_interfaces_count -1;
if (aif->ifgroup < 0) {
aif->ifgroup = all_interfaces_count; // starting at 1. the 0 is for APRSIS
/* -- no hard upper limit anymore
if (aif->ifgroup >= MAX_IF_GROUP)
aif->ifgroup = MAX_IF_GROUP -1;
*/
}
if (top_interfaces_group <= aif->ifgroup)
top_interfaces_group = aif->ifgroup +1;
}
struct aprx_interface *find_interface_by_callsign(const char *callsign)
{
int i;
for (i = 0; i < all_interfaces_count; ++i) {
if ((all_interfaces[i]->callsign != NULL) &&
(strcasecmp(callsign, all_interfaces[i]->callsign) == 0)) {
return all_interfaces[i];
}
}
return NULL; // Not found!
}
struct aprx_interface *find_interface_by_index(const int index)
{
if (index >= all_interfaces_count ||
index < 0) {
return NULL; // Invalid index value
} else {
return all_interfaces[index];
}
}
static int config_kiss_subif(struct configfile *cf, struct aprx_interface *aifp, char *param1, char *str, int maxsubif)
{
struct aprx_interface *aif;
int fail = 0;
char *name;
int parlen = 0;
char *initstring = NULL;
int initlength = 0;
char *callsign = NULL;
int subif = 0;
int tx_ok = 0;
int telemeter_to_is = 1;
int telemeter_to_rf = 1;
int aliascount = 0;
char **aliases = NULL;
int ifgroup = -1;
const char *p = param1;
int c;
if (aifp == NULL || aifp->tty == NULL) {
printf("%s:%d ERROR: <kiss-subif> on bad type of <interface> entry.\n",
cf->name, cf->linenum);
return 1;
}
for ( ; *p; ++p ) {
c = *p;
if ('0' <= c && c <= '9') {
subif = subif * 10 + (c - '0');
} else if (c == '>') {
// all fine..
break;
} else {
// FIXME: <KISS-SubIF nnn> parameter value is bad!
printf("%s:%d ERROR: <kiss-subif %s parameter value is bad\n",
cf->name, cf->linenum, param1);
return 1;
}
}
if (subif >= maxsubif) {
// FIXME: <KISS-SubIF nnn> parameter value is bad!
printf("%s:%d ERROR: <kiss-subif %s parameter value is too large for this KISS variant.\n",
cf->name, cf->linenum, param1);
return 1;
}
while (readconfigline(cf) != NULL) {
if (configline_is_comment(cf))
continue; /* Comment line, or empty line */
// It can be severely indented...
str = config_SKIPSPACE(cf->buf);
name = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
config_STRLOWER(name);
param1 = str;
str = config_SKIPTEXT(str, &parlen);
str = config_SKIPSPACE(str);
if (strcmp(name, "</kiss-subif>") == 0) {
break; // End of this sub-group
}
if (strcmp(name, "callsign") == 0) {
if (strcasecmp(param1,"$mycall") == 0)
callsign = strdup(mycall);
else
callsign = strdup(param1);
if (!validate_callsign_input(callsign,tx_ok)) {
if (tx_ok)
printf("%s:%d ERROR: The CALLSIGN parameter on AX25-DEVICE must be of valid AX.25 format! '%s'\n",
cf->name, cf->linenum, callsign);
else
printf("%s:%d ERROR: The CALLSIGN parameter on AX25-DEVICE must be of valid APRSIS format! '%s'\n",
cf->name, cf->linenum, callsign);
fail = 1;
break;
}
if (find_interface_by_callsign(callsign) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, callsign);
fail = 1;
continue;
}
} else if (strcmp(name, "initstring") == 0) {
if (initstring == NULL) {
initlength = parlen;
initstring = malloc(parlen);
memcpy(initstring, param1, parlen);
} else {
printf("%s:%d ERROR: Double-definition of initstring parameter.\n",
cf->name, cf->linenum);
fail = 1;
break;
}
} else if (strcmp(name, "tx-ok") == 0) {
if (!config_parse_boolean(param1, &tx_ok)) {
printf("%s:%d ERROR: Bad TX-OK parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
fail = 1;
break;
}
} else if (strcmp(name, "telem-to-is") == 0) {
if (!config_parse_boolean(param1, &telemeter_to_is)) {
printf("%s:%d ERROR: Bad TELEM-TO-IS parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
fail = 1;
break;
}
} else if (strcmp(name, "telem-to-rf") == 0) {
if (!config_parse_boolean(param1, &telemeter_to_rf)) {
printf("%s:%d ERROR: Bad TELEM-TO-RF parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
fail = 1;
break;
}
} else if (strcmp(name, "alias") == 0) {
char *k = strtok(param1, ",");
for (; k ; k = strtok(NULL,",")) {
++aliascount;
if (debug) printf(" n=%d alias='%s'\n",aliascount,k);
aliases = realloc(aliases, sizeof(char*) * aliascount);
aliases[aliascount-1] = strdup(k);
}
#ifndef DISABLE_IGATE
} else if (strcmp(name, "igate-group") == 0) {
// param1 = integer 1 to N.
ifgroup = atol(param1);
if (ifgroup < 1) {
printf("%s:%d ERROR: interface 'igate-group' parameter value: '%s' is an integer with minimum value of 1.\n",
cf->name, cf->linenum, param1);
fail = 1;
break;
/* -- no hard upper limit anymore
} else if (ifgroup >= MAX_IF_GROUP) {
printf("%s:%d ERROR: interface 'igate-group' parameter value: '%s' is an integer with maximum value of %d.\n",
cf->name, cf->linenum, param1, MAX_IF_GROUP-1);
fail = 1;
break;
*/
}
#endif
} else {
printf("%s:%d ERROR: Unrecognized <interface> block keyword: %s\n",
cf->name, cf->linenum, name);
fail = 1;
break;
}
}
if (fail) {
ERRORMEMFREE:
if (aliases != NULL) free(aliases);
if (initstring != NULL) free(initstring);
return 1; // this leaks memory (but also diagnoses bad input)
}
if (callsign == NULL) {
// FIXME: Must define at least a callsign!
printf("%s:%d ERROR: <kiss-subif ..> MUST define CALLSIGN parameter!\n",
cf->name, cf->linenum);
goto ERRORMEMFREE;
}
if (find_interface_by_callsign(callsign) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, callsign);
goto ERRORMEMFREE;
}
if (debug)
printf(" Defining <kiss-subif %d> callsign=%s txok=%s\n", subif, callsign,
tx_ok ? "true":"false");
aif = malloc(sizeof(*aif));
memcpy(aif, aifp, sizeof(*aif));
aif->callsign = callsign;
parse_ax25addr(aif->ax25call, callsign, 0x60);
aif->subif = subif;
aif->tx_ok = tx_ok;
aif->telemeter_to_is = telemeter_to_is;
aif->telemeter_to_rf = telemeter_to_rf;
// aif->telemeter_newformat = ...
aif->ifindex = -1; // system sets automatically at store time
aif->ifgroup = ifgroup; // either user sets, or system sets at store time
aifp->tty->interface [subif] = aif;
aifp->tty->ttycallsign[subif] = callsign;
#ifdef PF_AX25 /* PF_AX25 exists -- highly likely a Linux system ! */
aifp->tty->netax25 [subif] = netax25_open(callsign);
#endif
if (initstring != NULL) {
aifp->tty->initlen[subif] = initlength;
aifp->tty->initstring[subif] = initstring;
}
if (aliascount == 0 || aliases == NULL) {
aif->aliascount = 3;
aif->aliases = interface_default_aliases;
} else {
aif->aliascount = aliascount;
aif->aliases = aliases;
}
return 0;
}
void interface_init()
{
interface_store( &aprsis_interface );
}
int interface_config(struct configfile *cf)
{
struct aprx_interface *aif = calloc(1, sizeof(*aif));
char *name, *param1;
char *str = cf->buf;
int parlen = 0;
int have_fault = 0;
int maxsubif = 16; // 16 for most KISS modes, 8 for SMACK
int defined_subinterface_count = 0;
int ifgroup = -1;
aif->iftype = IFTYPE_UNSET;
aif->aliascount = 3;
aif->aliases = interface_default_aliases;
aif->ifindex = -1; // system sets automatically at store time
aif->ifgroup = ifgroup; // either user sets, or system sets at store time
aif->tx_ok = 0;
aif->telemeter_to_is = 1;
aif->telemeter_to_rf = 1;
aif->telemeter_newformat = 0;
while (readconfigline(cf) != NULL) {
if (configline_is_comment(cf))
continue; /* Comment line, or empty line */
// It can be severely indented...
str = config_SKIPSPACE(cf->buf);
name = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
config_STRLOWER(name);
param1 = str;
str = config_SKIPTEXT(str, &parlen);
str = config_SKIPSPACE(str);
if (strcmp(name, "</interface>") == 0) {
// End of this interface definition
// make the interface...
break;
}
if (strcmp(name, "<kiss-subif") == 0) {
if (config_kiss_subif(cf, aif, param1, str, maxsubif)) {
// Bad inputs.. complained already
have_fault = 1;
}
// Always count as defined, even when an error happened!
++defined_subinterface_count;
continue;
}
// Interface parameters
if (strcmp(name,"ax25-device") == 0) {
#ifdef PF_AX25 // PF_AX25 exists -- highly likely a Linux system !
if (aif->iftype == IFTYPE_UNSET) {
aif->iftype = IFTYPE_AX25;
// aif->nax25p = NULL;
} else {
printf("%s:%d ERROR: Only single device specification per interface block!\n",
cf->name, cf->linenum);
have_fault = 1;
continue;
}
if (strcasecmp(param1,"$mycall") == 0)
param1 = strdup(mycall);
if (!validate_callsign_input(param1,1)) {
printf("%s:%d ERROR: The CALLSIGN parameter on AX25-DEVICE must be of valid AX.25 format! '%s'\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
if (find_interface_by_callsign(param1) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
if (debug)
printf("%s:%d: AX25-DEVICE '%s' '%s'\n",
cf->name, cf->linenum, param1, str);
aif->callsign = strdup(param1);
parse_ax25addr(aif->ax25call, aif->callsign, 0x60);
aif->nax25p = netax25_addrxport(param1, aif);
if (aif->nax25p == NULL) {
printf("%s:%d ERROR: Failed to open this AX25-DEVICE: '%s'\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
#else
printf("%s:%d ERROR: AX25-DEVICE interfaces are not supported at this system!\n",
cf->name, cf->linenum);
have_fault = 1;
#endif
} else if ((strcmp(name,"serial-device") == 0) && (aif->tty == NULL)) {
if (aif->iftype == IFTYPE_UNSET) {
aif->iftype = IFTYPE_SERIAL;
aif->tty = ttyreader_new();
aif->tty->ttyname = strdup(param1);
aif->tty->interface[0] = aif;
aif->tty->ttycallsign[0] = mycall;
// end processing registers it
} else {
printf("%s:%d ERROR: Only single device specification per interface block!\n",
cf->name, cf->linenum);
have_fault = 1;
continue;
}
if (debug)
printf(".. new style serial: '%s' '%s'.. tncid=0\n",
aif->tty->ttyname, str);
have_fault |= ttyreader_parse_ttyparams(cf, aif->tty, str);
switch (aif->tty->linetype) {
case LINETYPE_KISSSMACK:
maxsubif = 8; // 16 for most KISS modes, 8 for SMACK
break;
case LINETYPE_KISSFLEXNET:
// ???
break;
default:
break;
}
// Always count as defined, even when an error happened!
++defined_subinterface_count;
} else if ((strcmp(name,"tcp-device") == 0) && (aif->tty == NULL)) {
int len;
char *host, *port;
if (aif->iftype == IFTYPE_UNSET) {
aif->iftype = IFTYPE_TCPIP;
aif->tty = ttyreader_new();
aif->tty->interface[0] = aif;
aif->tty->ttycallsign[0] = mycall;
// end-step processing registers it
} else {
printf("%s:%d ERROR: Only single device specification per interface block!\n",
cf->name, cf->linenum);
have_fault = 1;
continue;
}
host = param1;
port = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
if (debug)
printf(".. new style tcp!: '%s' '%s' '%s'..\n",
host, port, str);
len = strlen(host) + strlen(port) + 8;
aif->tty->ttyname = malloc(len);
sprintf((char *) (aif->tty->ttyname), "tcp!%s!%s!", host, port);
have_fault |= ttyreader_parse_ttyparams( cf, aif->tty, str );
switch (aif->tty->linetype) {
case LINETYPE_KISSSMACK:
maxsubif = 8; // 16 for most KISS modes, 8 for SMACK
break;
case LINETYPE_KISSFLEXNET:
// ???
break;
default:
break;
}
// Always count as defined, even when an error happened!
++defined_subinterface_count;
} else if (strcmp(name,"null-device") == 0) {
if (aif->iftype == IFTYPE_UNSET) {
aif->iftype = IFTYPE_NULL;
// aif->nax25p = NULL;
} else {
printf("%s:%d ERROR: Only single device specification per interface block!\n",
cf->name, cf->linenum);
have_fault = 1;
continue;
}
aif->tx_ok = 1;
if (strcasecmp(param1,"$mycall") == 0)
param1 = strdup(mycall);
if (find_interface_by_callsign(param1) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
if (!have_fault) {
aif->iftype = IFTYPE_TCPIP;
aif->tty = ttyreader_new();
aif->tty->interface[0] = aif;
aif->tty->ttycallsign[0] = mycall;
}
have_fault |= ttyreader_parse_nullparams(cf, aif->tty, str);
if (debug)
printf("%s:%d: NULL-DEVICE '%s' '%s'\n",
cf->name, cf->linenum, param1, str);
aif->callsign = strdup(param1);
parse_ax25addr(aif->ax25call, aif->callsign, 0x60);
#ifdef ENABLE_AGWPE
} else if ((strcmp(name,"agwpe-device") == 0) && (aif->tty == NULL)) {
// agwpe-device hostname hostport callsign agwpeportnum
int len;
const char *hostname, *hostport;
char *callsign, *agwpeportnum;
if (aif->iftype == IFTYPE_UNSET) {
aif->iftype = IFTYPE_AGWPE;
aif->tty = ttyreader_new();
aif->tty->interface[0] = aif;
aif->tty->ttycallsign[0] = mycall;
// end-step processing registers it
} else {
printf("%s:%d ERROR: Only single device specification per interface block!\n",
cf->name, cf->linenum);
have_fault = 1;
continue;
}
hostname = strdup(param1);
hostport = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
hostport = strdup(hostport);
callsign = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
agwpeportnum = str;
str = config_SKIPTEXT(str, NULL);
str = config_SKIPSPACE(str);
if (debug)
printf(".. AGWPE-DEVICE: '%s' '%s' '%s' '%s' ('%s'...)\n",
hostname, hostport, callsign, agwpeportnum, str);
len = strlen(hostname) + strlen(hostport) + strlen(agwpeportnum) + 8;
aif->tty->ttyname = malloc(len);
sprintf((char *) (aif->tty->ttyname), "tcp!%s!%s[%s]",
hostname, hostport, agwpeportnum);
if (strcasecmp(callsign,"$mycall") == 0)
callsign = strdup(mycall);
else
callsign = strdup(callsign);
if (!validate_callsign_input(callsign,1)) {
printf("%s:%d ERROR: The CALLSIGN parameter on AGWPE-DEVICE must be of valid AX.25 format! '%s'\n",
cf->name, cf->linenum, callsign);
have_fault = 1;
continue;
}
if (find_interface_by_callsign(callsign) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, callsign);
have_fault = 1;
continue;
}
aif->callsign = callsign;
parse_ax25addr(aif->ax25call, aif->callsign, 0x60);
aif->agwpe = agwpe_addport(hostname, hostport, agwpeportnum, aif);
if (aif->agwpe == NULL) {
printf("%s:%d ERROR: Failed to setup this AGWPE-DEVICE: '%s'\n",
cf->name, cf->linenum, callsign);
have_fault = 1;
continue;
}
// Always count as defined, even when an error happened!
++defined_subinterface_count;
#endif
} else if (strcmp(name,"tx-ok") == 0) {
int bool;
if (!config_parse_boolean(param1, &bool)) {
printf("%s:%d ERROR: Bad TX-OK parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
aif->tx_ok = bool;
if (bool && aif->callsign) {
if (!validate_callsign_input(aif->callsign,bool)) { // Transmitters REQUIRE valid AX.25 address
printf("%s:%d: ERROR: TX-OK 'TRUE' -- BUT PREVIOUSLY SET CALLSIGN IS NOT VALID AX.25 ADDRESS \n",
cf->name, cf->linenum);
continue;
}
}
} else if (strcmp(name, "telem-to-is") == 0) {
int bool;
if (!config_parse_boolean(param1, &bool)) {
printf("%s:%d ERROR: Bad TELEM-TO-IS parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
have_fault = 1;
break;
}
aif->telemeter_to_is = bool;
} else if (strcmp(name, "telem-to-rf") == 0) {
int bool;
if (!config_parse_boolean(param1, &bool)) {
printf("%s:%d ERROR: Bad TELEM-TO-RF parameter value -- not a recognized boolean: %s\n",
cf->name, cf->linenum, param1);
have_fault = 1;
break;
}
aif->telemeter_to_rf = bool;
} else if (strcmp(name,"timeout") == 0) {
if (config_parse_interval(param1, &(aif->timeout) ) ||
(aif->timeout < 0) || (aif->timeout > 14400)) {
aif->timeout = 0;
printf("%s:%d ERROR: Bad TIMEOUT parameter value: '%s' accepted range: 0s to 4h.\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
if (aif->tty != NULL) {
aif->tty->read_timeout = aif->timeout;
}
} else if (strcmp(name, "callsign") == 0) {
if (strcasecmp(param1,"$mycall") == 0)
param1 = strdup(mycall);
if (find_interface_by_callsign(param1) != NULL) {
// An interface with THIS callsign does exist already!
printf("%s:%d ERROR: Same callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
if (!validate_callsign_input(param1, aif->tx_ok)) {
if (aif->tx_ok && aif->iftype != IFTYPE_NULL) {
printf("%s:%d ERROR: The CALLSIGN parameter on transmit capable interface must be of valid AX.25 format! '%s'\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
}
}
if (aif->callsign != NULL)
free(aif->callsign);
aif->callsign = strdup(param1);
parse_ax25addr(aif->ax25call, aif->callsign, 0x60);
if (aif->tty != NULL)
aif->tty->ttycallsign[0] = aif->callsign;
if (debug)
printf(" callsign= '%s'\n", aif->callsign);
} else if (strcmp(name, "initstring") == 0) {
if (aif->tty != NULL) {
int initlength = parlen;
char *initstring = malloc(parlen);
memcpy(initstring, param1, parlen);
aif->tty->initstring[0] = initstring;
aif->tty->initlen[0] = initlength;
}
} else if (strcmp(name, "alias") == 0) {
char *k = strtok(param1, ",");
if (aif->aliases == interface_default_aliases) {
aif->aliascount = 0;
aif->aliases = NULL;
}
for (; k ; k = strtok(NULL,",")) {
aif->aliascount += 1;
if (debug) printf(" n=%d alias='%s'\n",aif->aliascount,k);
aif->aliases = realloc(aif->aliases, sizeof(char*) * aif->aliascount);
aif->aliases[aif->aliascount-1] = strdup(k);
}
#ifndef DISABLE_IGATE
} else if (strcmp(name, "igate-group") == 0) {
// param1 = integer 1 to N.
ifgroup = atol(param1);
if (ifgroup < 1) {
printf("%s:%d ERROR: interface 'igate-group' parameter value: '%s' is an integer with minimum value of 1.\n",
cf->name, cf->linenum, param1);
have_fault = 1;
continue;
/* -- no hard upper limit anymore
} else if (ifgroup >= MAX_IF_GROUP) {
printf("%s:%d ERROR: interface 'igate-group' parameter value: '%s' is an integer with maximum value of %d.\n",
cf->name, cf->linenum, param1, MAX_IF_GROUP-1);
have_fault = 1;
continue;
*/
}
#endif
} else {
printf("%s:%d ERROR: Unknown <interface> config entry name: '%s'\n",
cf->name, cf->linenum, name);
have_fault = 1;
}
}
while (!have_fault &&
aif->callsign == NULL &&
(aif->iftype == IFTYPE_SERIAL || aif->iftype == IFTYPE_TCPIP) &&
defined_subinterface_count == 1) {
// First check if there already is an interface with $mycall
// callsign on it..
if (find_interface_by_callsign(mycall) != NULL) {
// An interface with $MYCALL callsign does exist already!
printf("%s:%d ERROR: The $MYCALL callsign (%s) exists already on another interface.\n",
cf->name, cf->linenum, mycall);
have_fault = 1;
break;
}
// Supply a default value
aif->callsign = strdup(mycall);
parse_ax25addr(aif->ax25call, aif->callsign, 0x60);
#ifdef PF_AX25 // PF_AX25 exists -- highly likely a Linux system !
// With enough defaults being used, the callsign is defined
// by global "macro" mycall, and never ends up activating
// the tty -> linux kernel kiss/smack pty interface.
// This part does that final step for minimalistic config.
if (aif->tty != NULL &&
aif->tty->netax25[0] == NULL &&
aif->tty->ttycallsign[0] != NULL) {
aif->tty->netax25[0]
= netax25_open(aif->tty->ttycallsign[0]);
}
#endif
// Done it, leave..
break;
}
if (!have_fault) {
int i;
if (aif->tty != NULL) {
// Register all tty subinterfaces
if (debug) printf(" .. store tty subinterfaces\n");
for (i = 0; i < maxsubif; ++i) {
if (aif->tty->interface[i] != NULL) {
if (debug) printf(" .. store interface[%d] callsign='%s'\n",i, aif->tty->interface[i]->callsign);
interface_store(aif->tty->interface[i]);
}
}
} else {
// Not TTY multiplexed ( = KISS ) interface,
// register just the primary.
aif->ifgroup = ifgroup; // either user sets, or system sets at store time
interface_store(aif);
if (debug) printf(" .. store other interface\n");
}
if (aif->iftype == IFTYPE_SERIAL)
ttyreader_register(aif->tty);
if (aif->iftype == IFTYPE_TCPIP)
ttyreader_register(aif->tty);
} else {
if (aif->callsign) free(aif->callsign);
if (aif->tty) {
if (aif->tty->ttyname) free((void*)(aif->tty->ttyname));
}
free(aif);
}
// coverity[leaked_storage]
return have_fault;
}
/*
* Process received AX.25 packet
* - from AIF do find all DIGIPEATERS wanting this source.
* - If there are none, end processing.
* - Parse the received frame for possible latter filters
* - Feed the resulting parsed packet to each digipeater
*
*
* Tx-IGate rules:
*
// 2) - sending station has not been heard recently
// on radio
// 1) - verify receiving station has been heard
// recently on radio
// 4) - the receiving station has not been heard via
// the Internet within a predefined time period.
// (Note that _this_ packet is heard from internet,
// so one must not confuse this to history..
// Nor this siblings that are being created
// one for each tx-interface...)
//
// A station is said to be heard via the Internet if packets
// from the station contain TCPIP* or TCPXX* in the header or
// if gated (3rd-party) packets are seen on RF gated by the
// station and containing TCPIP or TCPXX in the 3rd-party
// header (in other words, the station is seen on RF as being
// an IGate).
*
* That is, this part of code collects knowledge of RF-wise near-by TX-IGATEs.
*/
void interface_receive_ax25(const struct aprx_interface *aif,
const char *ifaddress, const int is_aprs, const int ui_pid,