-
Notifications
You must be signed in to change notification settings - Fork 7
/
wl2kserial.c
834 lines (738 loc) · 21.8 KB
/
wl2kserial.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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 2; c-brace-offset: -2; c-argdecl-indent: 2 -*- */
/* paclink-unix client for the Winlink 2000 ham radio email system.
*
* Copyright 2006 Nicholas S. Castellano <n2qz@arrl.net> and others,
* See the file AUTHORS for a list.
*
* Code for the SCS P4dragon was copied from SCS simple terminal
* file: term.c
* Copyright 2005-2012 SCS GmbH & Co. KG, Hanau, Germany
* written by Peter Mack (peter.mack@scs-ptc.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef __RCSID
__RCSID("$Id$");
#endif
#if HAVE_STDIO_H
# include <stdio.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_CTYPE_H
# include <ctype.h>
#endif
#include <sys/ioctl.h>
#include <linux/serial.h>
#include <fcntl.h>
#include <termios.h>
#ifndef bool
#include <stdbool.h>
#endif /* bool */
#include <getopt.h>
#include <gmime/gmime.h>
#include "compat.h"
#include "conf.h"
#include "timeout.h"
#include "wl2k.h"
#include "strutil.h"
#if defined(EXTA) && !defined(B19200)
# define B19200 EXTA
#endif
#if defined(EXTB) && !defined(B38400)
# define B38400 EXTB
#endif
/*
* Globals
*/
int gverbose_flag=FALSE;
int gsendmsgonly_flag=FALSE;
#define SCSMODEM_UNDEFINED 0
#define SCSMODEM_PTCIIPRO 1
#define SCSMODEM_P4DRAGON 2
/* Names of SCS pactor modems */
const struct modemtype {
const char *modem_name;
int modem;
} modems[] = {
{"PTC-IIpro", SCSMODEM_PTCIIPRO}, /* default */
{"P4dragon", SCSMODEM_P4DRAGON},
{NULL, 0}
};
const struct baudrate {
const char *asc;
speed_t num;
} baudrates[] = {
{"50", B50},
{"75", B75},
{"110", B110},
{"134", B134},
{"150", B150},
{"200", B200},
{"300", B300},
{"600", B600},
{"1200", B1200},
{"1800", B1800},
{"2400", B2400},
{"4800", B4800},
#ifdef B7200
{"7200", B7200},
#endif
{"9600", B9600},
#ifdef B14400
{"14400", B14400},
#endif
#ifdef B19200
{"19200", B19200},
#endif
#ifdef B28800
{"28800", B28800},
#endif
#ifdef B38400
{"38400", B38400},
#endif
#ifdef B57600
{"57600", B57600},
#endif
#ifdef B76800
{"76800", B76800},
#endif
#ifdef B115200
{"115200", B115200},
#endif
#ifdef B230400
{"230400", B230400},
#endif
#ifdef B460800
{"460800", B460800},
#endif
#ifdef B921600
{"921600", B921600},
#endif
{NULL, 0}
};
/*
* Config parameters struct
*/
typedef struct _wl2kserial_config {
char *mycall;
char *targetcall;
char *serialdevice;
char *emailaddr;
char *wl2k_password;
int modem;
speed_t baudrate;
unsigned int timeoutsecs;
int bVerbose;
int bSendonly;
FILE *modemfp;
}cfg_t;
static cfg_t cfg;
static bool loadconfig(int argc, char **argv, cfg_t *cfg);
static void usage(void);
static void displayversion(void);
static void displayconfig(cfg_t *config);
void disconnect(void);
/**
* Function: main
*
* The calling convention for this function is:
*
* wl2kserial -c targetcall -d device -b baudrate -t timeoutsecs -e emailaddress
*
* The parameters are:
* mycall : my call sign, which MUST be set in wl2k.conf
* targetcall: callsign to contact
* device: serial device to use
* baudrate: baudrate to set for serial device
* timeoutsecs: timeout in seconds
* emailaddress: email address where the retrieved message will be sent via sendmail
*
*/
int
main(int argc, char *argv[])
{
int fd;
FILE *fp;
char *line;
struct termios init;
struct termios t;
int flags;
loadconfig(argc, argv, &cfg);
g_mime_init(0);
setlinebuf(stdout);
settimeout(cfg.timeoutsecs);
/* open device */
printf("Opening %s ...\n", cfg.serialdevice);
if ((fd = open(cfg.serialdevice, O_RDWR | O_NONBLOCK)) == -1) {
perror("open()");
exit(EXIT_FAILURE);
}
flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
if ((tcgetattr(fd, &init)) == -1) {
perror("tcgetattr()");
exit(EXIT_FAILURE);
}
if ((tcgetattr(fd, &t)) == -1) {
perror("tcgetattr()");
exit(EXIT_FAILURE);
}
if ((cfsetspeed(&t, cfg.baudrate)) == -1) {
perror("cfsetspeed()");
exit(EXIT_FAILURE);
}
#if 0
cfmakeraw(&t);
#endif
#ifndef CRTSCTS
# define CRTSCTS 0
#endif
#ifndef CCTS_OFLOW
# define CCTS_OFLOW 0
#endif
#ifndef CCTS_IFLOW
# define CCTS_IFLOW 0
#endif
#ifndef MDMBUF
# define MDMBUF 0
#endif
t.c_iflag &= (tcflag_t)~(INPCK | ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
t.c_iflag |= (IGNBRK | IGNPAR);
t.c_oflag &= (tcflag_t)~OPOST;
t.c_cflag &= ~(CSIZE | PARENB | CRTSCTS | CCTS_OFLOW | CCTS_IFLOW | MDMBUF);
t.c_cflag |= (CS8 | CREAD | CLOCAL);
t.c_lflag &= (tcflag_t)~(ICANON | ISIG | IEXTEN | ECHO);
t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0;
/* set P4dragon serial port flags */
if (cfg.modem == SCSMODEM_P4DRAGON) {
t.c_oflag = 0;
t.c_lflag = 0;
t.c_cflag &= (unsigned int)~(CSTOPB | PARENB | PARODD | HUPCL);
t.c_cflag |= (CS8 | CRTSCTS | CREAD | CLOCAL);
}
if ((tcsetattr(fd, TCSAFLUSH, &t)) == -1) {
perror("tcsetattr()");
exit(EXIT_FAILURE);
}
/* set P4dragon baud rate */
if (cfg.modem == SCSMODEM_P4DRAGON) {
struct serial_struct sstruct;
/* get serial_struct */
if (ioctl(fd, TIOCGSERIAL, &sstruct) < 0) {
close (fd);
perror("ioctl(): could not get serial ioctl");
exit(EXIT_FAILURE);
}
/* set custom divisor to get 829440 baud */
sstruct.custom_divisor = 29;
sstruct.flags |= (int)ASYNC_SPD_CUST;
/* set serial_struct */
if (ioctl(fd, TIOCSSERIAL, &sstruct) < 0) {
close (fd);
perror("ioctl(): could not set custom comm baud divisor");
exit(EXIT_FAILURE);
}
}
resettimeout();
printf("Connected.\n");
if ((fp = fdopen(fd, "r+b")) == NULL) {
close(fd);
perror("fdopen()");
exit(EXIT_FAILURE);
}
/* save for disconnect */
cfg.modemfp = fp;
setbuf(fp, NULL);
fprintf(fp, "\r\n");
while ((line = wl2kgetline(fp)) != NULL) {
printf("%s\n", line);
if (strstr(line, "cmd:")) {
fprintf(fp, "mycall %s\r", cfg.mycall);
printf("mycall %s\n", cfg.mycall);
fprintf(fp, "tones 4\r");
printf("tones 4\n");
fprintf(fp, "chobell 0\r"); /* Changeover Bell off */
printf("chobell 0\n");
fprintf(fp, "lfignore 1\r"); /* xxx Insertion of Line feed */
printf("lfignore 1\n");
if (cfg.modem == SCSMODEM_P4DRAGON) {
/* Taken from BPQ32 SCSPactor.c file
* Copyright 2001-2015 John Wiseman G8BPQ
* The SCSPactor.c file is part of LinBPQ/BPQ32.
*
* Set P4 Dragon with KISS over Hostmade
*/
fprintf(fp, "MAXERR 30\r"); /* Max retries */
printf("MAXERR 30\n");
fprintf(fp, "MODE 0\r"); /* ASCII mode, no PTC II compression (Forwarding will use FBB Compression) */
printf("MODE 0\n");
fprintf(fp, "MAXSUM 20\r"); /* Max count for memory ARQ */
printf("MAXSUM 20\n");
fprintf(fp, "CWID 0\r"); /* CW ID disabled */
printf("CWID 0\n");
fprintf(fp, "PTCC 0\r"); /* Dragon out of PTC Compatibility Mode */
printf("PTCC 0\n");
fprintf(fp, "VER\r"); /* Try to determine Controller Type */
printf("VER\n");
fprintf(fp, "ADDLF 0\r"); /* Auto Line Feed disabled */
printf("ADDLF 0\n");
fprintf(fp, "ARX 0\r"); /* Amtor Phasing disabled */
printf("ARX 0\n");
fprintf(fp, "BC 0\r"); /* FEC reception is disabled */
printf("BC 0\n");
fprintf(fp, "BKCHR 2\r"); /* Breakin Char = 2*/
printf("BKCHR 2\n");
fprintf(fp, "CMSG 0\r"); /* Connect Message Off */
printf("CMSG 0\n");
fprintf(fp, "LISTEN 0\r"); /* Pactor Listen disabled */
printf("LISTEN 0\n");
fprintf(fp, "MAIL 0\r"); /* Disable internal mailbox reporting */
printf("MAIL 0\n");
fprintf(fp, "REMOTE 0\r"); /* Disable remote control */
printf("REMOTE 0\n");
fprintf(fp, "PAC CBELL 0\r");
printf("PAC CBELL 0\n");
fprintf(fp, "PAC CMSG 0\r");
printf("PAC CMSG 0\n");
fprintf(fp, "PAC PRBOX 0\r");
printf("PAC PRBOX 0\n");
/* Automatic Status must be enabled for paclink-unix??
* Pactor must use Host Mode Channel 31
* PDuplex must be set. The Node code relies on automatic IRS/ISS changeover
* 5 second duplex timer
*/
fprintf(fp, "STATUS 0\r");
printf("STATUS 0\n");
fprintf(fp, "PTCHN 31\r");
printf("PTCHN 31\n");
fprintf(fp, "PDUPLEX 1\r");
printf("PDUPLEX 1\n");
fprintf(fp, "PDTIMER 5\r");
printf("PDTIMER 5\n");
}
break;
}
fprintf(fp, "\r\n");
}
if (line == NULL) {
fprintf(stderr, "Connection closed by foreign host.\n");
exit(EXIT_FAILURE);
}
#if 0
while ((line = wl2kgetline(fp)) != NULL) {
printf("%s\n", line);
if (strstr(line, "Mycall:")) {
break;
}
}
if (line == NULL) {
fprintf(stderr, "Connection closed by foreign host.\n");
exit(EXIT_FAILURE);
}
#endif
while ((line = wl2kgetline(fp)) != NULL) {
printf("%s\n", line);
if (strstr(line, "cmd:")) {
fprintf(fp, "c %s\r", cfg.targetcall);
printf("c %s\n", cfg.targetcall);
break;
}
}
if (line == NULL) {
fprintf(stderr, "Connection closed by foreign host.\n");
exit(EXIT_FAILURE);
}
wl2k_exchange(cfg.mycall, cfg.targetcall, fp, fp, cfg.emailaddr, cfg.wl2k_password);
disconnect();
fclose(fp);
g_mime_shutdown();
exit(EXIT_SUCCESS);
return 1;
}
void disconnect(void) {
/* If D (Disconect) doesn't work try DD (Dirty Disconnect) */
if (cfg.modem == SCSMODEM_P4DRAGON) {
fprintf(cfg.modemfp, "D\r"); /* Disconnect from Dragon modem */
printf("Disconnect\n");
}
}
/*
* Print usage information and exit
* - does not return
*/
static void
usage(void)
{
printf("Usage: %s -c target_call -d serial_device -b baudrate -m modem_name options\n", getprogname());
printf(" -c --target-call Set callsign to call\n");
printf(" -d --device Set serial device name\n");
printf(" -b --baudrate Set baud rate of serial device\n");
printf(" -m --modem Set SCS modem type (PTC-IIpro, P4dragon)\n");
printf(" -t --timeout Set timeout in seconds\n");
printf(" -P --wl2k-passwd Set password for WL2K secure login\n");
printf(" -e --email-address Set your e-mail address\n");
printf(" -s --send-only Send messages only\n");
printf(" -V --verbose Print verbose messages\n");
printf(" -v --version Display version of this program\n");
printf(" -C --configuration Display configuration only\n");
printf(" -h --help Display this usage info\n");
exit(EXIT_SUCCESS);
}
/*
* Display package version of this program.
*/
static void
displayversion(void)
{
printf("%s %s ", getprogname(), PACKAGE_VERSION);
/* Check verbose flag for displaying gmime version */
if(gverbose_flag) {
printf("Using gmime version %d.%d.%d",
gmime_major_version, gmime_minor_version, gmime_micro_version);
}
printf("\n");
}
/*
* Display configuration parameters
* parsed from defaults, config file & command line
*/
static void
displayconfig(cfg_t *config)
{
struct baudrate const *bp;
struct modemtype const *mp;
printf("%s: Using this config:\n", getprogname());
if(config->mycall) {
printf(" My callsign: %s\n", config->mycall);
}
if(config->targetcall) {
printf(" Target callsign: %s\n", config->targetcall);
}
if(config->serialdevice) {
printf(" Serial device: %s\n", config->serialdevice);
}
printf(" Baud rate: ");
/* Loop through the baud rate table */
for (bp = baudrates; bp->asc != NULL; bp++) {
if (bp->num == config->baudrate) {
break;
}
}
if(bp->asc != NULL) {
printf(" %s\n", bp->asc);
} else {
printf("Invalid\n");
}
printf(" Modem type: ");
/* Loop through the modem name table */
for (mp = modems; mp->modem_name != NULL; mp++) {
if (mp->modem == config->modem) {
break;
}
}
if(mp->modem_name != NULL) {
printf(" %s\n", mp->modem_name);
} else {
printf("Invalid\n");
}
if(config->wl2k_password) {
printf(" WL2K secure login password: %s\n", config->wl2k_password);
}
printf(" Timeout: %d\n", config->timeoutsecs);
if(config->emailaddr) {
printf(" Email address: %s\n", config->emailaddr);
}
printf(" Flags: verbose = %s, send-only = %s\n",
config->bVerbose ? "On" : "Off",
config->bSendonly ? "On" : "Off");
}
/* Load these 7 config parameters:
* mycall targetcall device baudrate modem timeoutsecs emailaddress
*/
static bool
loadconfig(int argc, char **argv, cfg_t *config)
{
struct conf *fileconf;
char *endp;
struct baudrate const *bp;
speed_t baud;
struct modemtype const *mp;
int modemtype;
int next_option;
int option_index = 0; /* getopt_long stores the option index here. */
char *cfgbuf;
static int displayconfig_flag=FALSE;
bool bRequireConfig_pass = TRUE;
bool bDisplayVersion_flag = FALSE;
char strDefaultBaudRate[]="9600"; /* String of default baudrate */
char *pBaudRate = strDefaultBaudRate;
char strDefaultModemType[]="PTC-IIpro";
char *pModemType = strDefaultModemType;
/* short options */
static const char *short_options = "hVvsCc:t:e:d:b:P:m:";
/* long options */
static struct option long_options[] =
{
/* These options set a flag. */
{"verbose", no_argument, &gverbose_flag, TRUE},
{"config", no_argument, &displayconfig_flag, TRUE},
{"send-only", no_argument, &gsendmsgonly_flag, TRUE},
/* These options don't set a flag.
We distinguish them by their indices. */
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{"target-call", required_argument, NULL, 'c'},
{"timeout", required_argument, NULL, 't'},
{"email-address", required_argument, NULL, 'e'},
{"device", required_argument, NULL, 'd'},
{"baudrate", required_argument, NULL, 'b'},
{"wl2k-passwd", required_argument, NULL, 'P'},
{"modem", required_argument, NULL, 'm'},
{NULL, no_argument, NULL, 0} /* array termination */
};
/* get a temporary buffer to build strings */
cfgbuf = (char *)malloc(256);
if(cfgbuf == NULL) {
fprintf(stderr, "%s: loadconfig, out of memory\n", getprogname());
return(FALSE);
}
/*
* Initialize default config
*/
/* use either cuserid(NULL) or getenv("LOGNAME"),
* - getlogin() does NOT work */
sprintf(cfgbuf, "%s@localhost", cuserid(NULL) );
config->emailaddr = strdup(cfgbuf);
free(cfgbuf);
config->mycall = NULL;
config->targetcall = NULL;
config->timeoutsecs = DFLT_TIMEOUTSECS;
config->wl2k_password = NULL;
config->serialdevice = NULL;
config->baudrate = B9600;
config->bVerbose = FALSE;
config->bSendonly = FALSE;
config->modem = SCSMODEM_PTCIIPRO;
/*
* Get config from config file
*/
fileconf = conf_read();
if ((config->mycall = conf_get(fileconf, "mycall")) == NULL) {
fprintf(stderr, "%s: failed to read mycall from configuration file\n", getprogname());
exit(EXIT_FAILURE);
}
if ((cfgbuf = conf_get(fileconf, "timeout")) != NULL) {
config->timeoutsecs = (unsigned int) strtol(cfgbuf, &endp, 10);
if (*endp != '\0') {
usage(); /* does not return */
}
}
if ((cfgbuf = conf_get(fileconf, "email")) != NULL) {
config->emailaddr = cfgbuf;
}
if ((cfgbuf = conf_get(fileconf, "wl2k-password")) != NULL) {
config->wl2k_password = cfgbuf;
}
if ((cfgbuf = conf_get(fileconf, "device")) != NULL) {
config->serialdevice = cfgbuf;
}
/* Get pointer to an ASCII baud rate */
if ((cfgbuf = conf_get(fileconf, "baud")) != NULL) {
pBaudRate = cfgbuf;
}
/* Get pointer to an ASCII modem type */
if ((cfgbuf = conf_get(fileconf, "modem")) != NULL) {
pModemType = cfgbuf;
}
/*
* Get config from command line
*/
opterr = 0;
option_index = 0;
next_option = getopt_long (argc, argv, short_options,
long_options, &option_index);
while( next_option != -1 ) {
switch (next_option)
{
case 0: /* long option without a short arg */
/* If this option sets a flag, do nothing else now. */
if (long_options[option_index].flag != 0)
break;
fprintf (stderr, "Debug: option %s", long_options[option_index].name);
if (optarg)
fprintf (stderr," with arg %s", optarg);
fprintf (stderr,"\n");
break;
case 'v': /* set display version flag */
bDisplayVersion_flag = TRUE;
break;
case 'V': /* set verbose flag */
gverbose_flag = TRUE;
break;
case 'c': /* set callsign to contact */
config->targetcall = optarg;
break;
case 'C': /* set display config flag */
displayconfig_flag = TRUE;
break;
case 's': /* set send message only flag */
gsendmsgonly_flag = TRUE;
break;
case 't': /* set time out in seconds */
config->timeoutsecs = (unsigned int) strtol(optarg, &endp, 10);
if (*endp != '\0') {
usage(); /* does not return */
}
break;
case 'e': /* set email address */
config->emailaddr = optarg;
break;
case 'P': /* set secure login password */
config->wl2k_password = optarg;
break;
case 'd': /* set serial device name */
config->serialdevice = optarg;
break;
case 'b': /* Get pointer to an ASCII baud rate */
pBaudRate = optarg;
break;
case 'm': /* Get pointer to an ASCII modem type */
pModemType = optarg;
break;
case 'h':
usage(); /* does not return */
break;
case '?':
if (isprint (optopt)) {
fprintf (stderr, "%s: Unknown option `-%c'.\n",
getprogname(), optopt);
} else {
fprintf (stderr,"%s: Unknown option character `\\x%x'.\n",
getprogname(), optopt);
}
/* fall through */
default:
usage(); /* does not return */
break;
}
next_option = getopt_long (argc, argv, short_options,
long_options, &option_index);
}
/* set send only flag here in case long option was used */
config->bSendonly = gsendmsgonly_flag;
/* set verbose flag here in case long option was used */
config->bVerbose = gverbose_flag;
/* Set baud rate */
if(pBaudRate != NULL) {
/* Convert ASCII baud rate into some usable bits */
baud = B0;
for (bp = baudrates; bp->asc != NULL; bp++) {
if (strcmp(bp->asc, pBaudRate) == 0) {
baud = bp->num;
break;
}
}
/* Verify a valid baudrate */
if (baud == B0) {
fprintf(stderr, "%s: Invalid baud '%s' -- valid baud rates are: ",
getprogname(), pBaudRate);
for (bp = baudrates; bp->asc != NULL; bp++) {
fprintf(stderr, "%s ", bp->asc);
}
fprintf(stderr, "\n");
usage(); /* does not return */
}
/* Save the baudrate bits in the config struct */
config->baudrate = baud;
}
/* Set modem type */
if(pModemType != NULL) {
/* Convert ASCII modem type into an int */
modemtype = SCSMODEM_UNDEFINED;
for (mp = modems; mp->modem_name != NULL; mp++) {
if (strcasecmp(mp->modem_name, pModemType) == 0) {
modemtype = mp->modem;
break;
}
}
/* Verify a valid modem type */
if (modemtype == SCSMODEM_UNDEFINED) {
fprintf(stderr, "%s: Invalid modem '%s' -- valid modem names are: ",
getprogname(), pModemType);
for (mp = modems; mp->modem_name != NULL; mp++) {
fprintf(stderr, "%s ", mp->modem_name);
}
fprintf(stderr, "\n");
usage(); /* does not return */
}
/* Save modem type in the config struct */
config->modem = modemtype;
}
if (config->modem == SCSMODEM_P4DRAGON) {
/* custom divisor only works if baud is set to 38400 */
config->baudrate = B38400;
}
if(bDisplayVersion_flag) {
displayversion();
exit(EXIT_SUCCESS);
}
/* test for required parameters */
if(config->targetcall == NULL) {
fprintf(stderr, "%s: Need to specify target callsign\n", getprogname() );
bRequireConfig_pass = FALSE;
}
if(config->serialdevice == NULL) {
fprintf(stderr, "%s: Need to specify serial device\n", getprogname() );
bRequireConfig_pass = FALSE;
}
if(config->baudrate == 0) {
fprintf(stderr, "%s: Need to specify baud rate of serial device\n", getprogname() );
bRequireConfig_pass = FALSE;
}
strupper((char *) config->mycall);
strupper((char *) config->targetcall);
/* If display config flag set just dump the configuration & exit */
if(displayconfig_flag) {
displayversion();
displayconfig(config);
exit(EXIT_SUCCESS);
}
/* Check configuration requirements */
if(!bRequireConfig_pass) {
usage(); /* does not return */
}
/* Be verbose */
if(config->bVerbose) {
displayversion();
displayconfig(config);
}
return(TRUE);
}