summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/parseutil/dcfd.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
committerdelphij <delphij@FreeBSD.org>2015-07-15 19:21:26 +0000
commit2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch)
treeb0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/parseutil/dcfd.c
parenta0741a75537b2e0514472ac3b28afc55a7846c30 (diff)
downloadFreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip
FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435: ntp 4.2.8p3. Relnotes: yes Approved by: re (?)
Diffstat (limited to 'contrib/ntp/parseutil/dcfd.c')
-rw-r--r--contrib/ntp/parseutil/dcfd.c127
1 files changed, 52 insertions, 75 deletions
diff --git a/contrib/ntp/parseutil/dcfd.c b/contrib/ntp/parseutil/dcfd.c
index c87ab35..969c1e3 100644
--- a/contrib/ntp/parseutil/dcfd.c
+++ b/contrib/ntp/parseutil/dcfd.c
@@ -1,6 +1,6 @@
/*
* /src/NTP/REPOSITORY/ntp4-dev/parseutil/dcfd.c,v 4.18 2005/10/07 22:08:18 kardel RELEASE_20051008_A
- *
+ *
* dcfd.c,v 4.18 2005/10/07 22:08:18 kardel RELEASE_20051008_A
*
* DCF77 100/200ms pulse synchronisation daemon program (via 50Baud serial line)
@@ -13,8 +13,8 @@
* Lacks:
* Leap second handling (at that level you should switch to NTP Version 4 - really!)
*
- * Copyright (c) 1995-2005 by Frank Kardel <kardel <AT> ntp.org>
- * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universität Erlangen-Nürnberg, Germany
+ * Copyright (c) 1995-2015 by Frank Kardel <kardel <AT> ntp.org>
+ * Copyright (c) 1989-1994 by Frank Kardel, Friedrich-Alexander Universitaet Erlangen-Nuernberg, Germany
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -185,7 +185,7 @@ static char pat[] = "-\\|/";
#define R_SHIFT(_X_, _Y_) (((_X_) < 0) ? -(-(_X_) >> (_Y_)) : ((_X_) >> (_Y_)))
-static struct timeval max_adj_offset = { 0, 128000 };
+static long max_adj_offset_usec = 128000;
static long clock_adjust = 0; /* current adjustment value (usec * 2^USECSCALE) */
static long accum_drift = 0; /* accumulated drift value (usec / ADJINTERVAL) */
@@ -195,10 +195,10 @@ static char skip_adjust = 1; /* discard first adjustment (bad samples) */
/*
* DCF77 state flags
*/
-#define DCFB_ANNOUNCE 0x0001 /* switch time zone warning (DST switch) */
-#define DCFB_DST 0x0002 /* DST in effect */
+#define DCFB_ANNOUNCE 0x0001 /* switch time zone warning (DST switch) */
+#define DCFB_DST 0x0002 /* DST in effect */
#define DCFB_LEAP 0x0004 /* LEAP warning (1 hour prior to occurrence) */
-#define DCFB_ALTERNATE 0x0008 /* alternate antenna used */
+#define DCFB_CALLBIT 0x0008 /* "call bit" used to signalize irregularities in the control facilities */
struct clocktime /* clock time broken up from time code */
{
@@ -219,9 +219,16 @@ typedef struct clocktime clocktime_t;
/*
* (usually) quick constant multiplications
*/
+#ifndef TIMES10
#define TIMES10(_X_) (((_X_) << 3) + ((_X_) << 1)) /* *8 + *2 */
+#endif
+#ifndef TIMES24
#define TIMES24(_X_) (((_X_) << 4) + ((_X_) << 3)) /* *16 + *8 */
+#endif
+#ifndef TIMES60
#define TIMES60(_X_) ((((_X_) << 4) - (_X_)) << 2) /* *(16 - 1) *4 */
+#endif
+
/*
* generic l_abs() function
*/
@@ -260,7 +267,8 @@ typedef struct clocktime clocktime_t;
* Second Contents
* 0 - 10 AM: free, FM: 0
* 11 - 14 free
- * 15 R - alternate antenna
+ * 15 R - "call bit" used to signalize irregularities in the control facilities
+ * (until 2003 indicated transmission via alternate antenna)
* 16 A1 - expect zone change (1 hour before)
* 17 - 18 Z1,Z2 - time zone
* 0 0 illegal
@@ -294,7 +302,7 @@ typedef struct clocktime clocktime_t;
* while the length is given as the difference between the start index and
* the start index of the following field.
*/
-static struct rawdcfcode
+static struct rawdcfcode
{
char offset; /* start bit */
} rawdcfcode[] =
@@ -361,7 +369,7 @@ static struct dcfparam
{
unsigned char onebits[60];
unsigned char zerobits[60];
-} dcfparam =
+} dcfparam =
{
"###############RADMLS1248124P124812P1248121241248112481248P", /* 'ONE' representation */
"--------------------s-------p------p----------------------p" /* 'ZERO' representation */
@@ -384,7 +392,7 @@ ext_bf(
register int i, first;
first = rawdcfcode[idx].offset;
-
+
for (i = rawdcfcode[idx+1].offset - 1; i >= first; i--)
{
sum <<= 1;
@@ -438,7 +446,7 @@ convert_rawdcf(
PRINTF("%-30s", "*** INCOMPLETE");
return CVT_NONE;
}
-
+
/*
* check Start and Parity bits
*/
@@ -495,7 +503,7 @@ convert_rawdcf(
clock_time->flags |= DCFB_LEAP;
if (ext_bf(buffer, DCF_R))
- clock_time->flags |= DCFB_ALTERNATE;
+ clock_time->flags |= DCFB_CALLBIT;
return CVT_OK;
}
@@ -587,7 +595,8 @@ cvt_rawdcf(
/*
* invalid character (no consecutive bit sequence)
*/
- dprintf(("parse: cvt_rawdcf: character check for 0x%x@%d FAILED\n", *s, s - buffer));
+ dprintf(("parse: cvt_rawdcf: character check for 0x%x@%ld FAILED\n",
+ (u_int)*s, (long)(s - buffer)));
*s = (unsigned char)~0;
rtc = CVT_FAIL|CVT_BADFMT;
}
@@ -738,7 +747,7 @@ cvt_rawdcf(
* if everything went well so far return the result of the symbolic
* conversion routine else just the accumulated errors
*/
- if (rtc != CVT_NONE)
+ if (rtc != CVT_NONE)
{
PRINTF("%-30s", "*** BAD DATA");
}
@@ -757,13 +766,13 @@ dcf_to_unixtime(
)
{
#define SETRTC(_X_) { if (cvtrtc) *cvtrtc = (_X_); }
- static int days_of_month[] =
+ static int days_of_month[] =
{
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
register int i;
time_t t;
-
+
/*
* map 2 digit years to 19xx (DCF77 is a 20th century item)
*/
@@ -846,7 +855,7 @@ dcf_to_unixtime(
*/
t = TIMES60(t) + clock_time->minute;
/* sec */
-
+
/*
* calculate UTC in minutes
*/
@@ -898,15 +907,19 @@ static const char *wday[8] =
*/
static char *
pr_timeval(
- struct timeval *val
- )
+ struct timeval *val
+ )
{
static char buf[20];
if (val->tv_sec == 0)
- sprintf(buf, "%c0.%06ld", (val->tv_usec < 0) ? '-' : '+', (long int)l_abs(val->tv_usec));
+ snprintf(buf, sizeof(buf), "%c0.%06ld",
+ (val->tv_usec < 0) ? '-' : '+',
+ (long int)l_abs(val->tv_usec));
else
- sprintf(buf, "%ld.%06ld", (long int)val->tv_sec, (long int)l_abs(val->tv_usec));
+ snprintf(buf, sizeof(buf), "%ld.%06ld",
+ (long int)val->tv_sec,
+ (long int)l_abs(val->tv_usec));
return buf;
}
@@ -1042,7 +1055,8 @@ adjust_clock(
toffset = *offset;
toffset.tv_sec = l_abs(toffset.tv_sec);
toffset.tv_usec = l_abs(toffset.tv_usec);
- if (timercmp(&toffset, &max_adj_offset, >))
+ if (toffset.tv_sec ||
+ (!toffset.tv_sec && toffset.tv_usec > max_adj_offset_usec))
{
/*
* hopeless - set the clock - and clear the timing
@@ -1241,7 +1255,7 @@ usage(
*/
static int
check_y2k( void )
-{
+{
int year; /* current working year */
int year0 = 1900; /* sarting year for NTP time */
int yearend; /* ending year we test for NTP time.
@@ -1300,7 +1314,7 @@ check_y2k( void )
* *a minor difference to arg2 type */
if ( ct.year != year )
{
- fprintf( stdout,
+ fprintf( stdout,
"%04d: dcf_to_unixtime(,%d) CORRUPTED ct.year: was %d\n",
(int)year, (int)Flag, (int)ct.year );
Error(year);
@@ -1310,52 +1324,15 @@ check_y2k( void )
Expected = t * 24 * 60 * 60;
if ( Observed != Expected || Flag )
{ /* time difference */
- fprintf( stdout,
+ fprintf( stdout,
"%04d: dcf_to_unixtime(,%d) FAILURE: was=%lu s/b=%lu (%ld)\n",
- year, (int)Flag,
+ year, (int)Flag,
(unsigned long)Observed, (unsigned long)Expected,
((long)Observed - (long)Expected) );
Error(year);
break;
}
- if ( year >= YEAR_PIVOT+1900 )
- {
- /* check year % 100 code we put into dcf_to_unixtime() */
- ct.year = year % 100;
- Flag = 0;
-
- Observed = dcf_to_unixtime( &ct, &Flag );
-
- if ( Observed != Expected || Flag )
- { /* time difference */
- fprintf( stdout,
-"%04d: dcf_to_unixtime(%d,%d) FAILURE: was=%lu s/b=%lu (%ld)\n",
- year, (int)ct.year, (int)Flag,
- (unsigned long)Observed, (unsigned long)Expected,
- ((long)Observed - (long)Expected) );
- Error(year);
- break;
- }
-
- /* check year - 1900 code we put into dcf_to_unixtime() */
- ct.year = year - 1900;
- Flag = 0;
-
- Observed = dcf_to_unixtime( &ct, &Flag );
-
- if ( Observed != Expected || Flag ) { /* time difference */
- fprintf( stdout,
- "%04d: dcf_to_unixtime(%d,%d) FAILURE: was=%lu s/b=%lu (%ld)\n",
- year, (int)ct.year, (int)Flag,
- (unsigned long)Observed, (unsigned long)Expected,
- ((long)Observed - (long)Expected) );
- Error(year);
- break;
- }
-
-
- }
}
return ( Fatals );
@@ -1375,7 +1352,7 @@ rawdcf_init(
* Here a voltage between the DTR and the RTS line is used. Unfortunately
* the name has changed from CIOCM_DTR to TIOCM_DTR recently.
*/
-
+
#ifdef TIOCM_DTR
int sl232 = TIOCM_DTR; /* turn on DTR for power supply */
#else
@@ -1469,7 +1446,7 @@ main(
errs=1;
}
break;
-
+
case 'd':
if (ac > 1)
{
@@ -1482,8 +1459,8 @@ main(
errs=1;
}
break;
-
- case 'Y':
+
+ case 'Y':
errs=check_y2k();
exit( errs ? 1 : 0 );
@@ -1550,7 +1527,7 @@ main(
unsigned int rtc = CVT_NONE;
rawdcf_init(fd);
-
+
timeout.tv_sec = 1;
timeout.tv_usec = 500000;
@@ -1591,7 +1568,7 @@ main(
*/
if (!interactive)
detach();
-
+
/*
* get syslog() initialized
*/
@@ -1609,7 +1586,7 @@ main(
struct sigaction act;
# ifdef HAVE_SA_SIGACTION_IN_STRUCT_SIGACTION
- act.sa_sigaction = (void (*) P((int, siginfo_t *, void *)))0;
+ act.sa_sigaction = (void (*) (int, siginfo_t *, void *))0;
# endif /* HAVE_SA_SIGACTION_IN_STRUCT_SIGACTION */
act.sa_handler = tick;
sigemptyset(&act.sa_mask);
@@ -1649,7 +1626,7 @@ main(
it.it_interval.tv_usec = 0;
it.it_value.tv_sec = 1<<ADJINTERVAL;
it.it_value.tv_usec = 0;
-
+
if (setitimer(ITIMER_REAL, &it, (struct itimerval *)0) == -1)
{
syslog(LOG_ERR, "setitimer: %m");
@@ -1828,7 +1805,7 @@ main(
wday[clock_time.wday],
clock_time.hour, clock_time.minute, i, clock_time.day, clock_time.month,
clock_time.year,
- (clock_time.flags & DCFB_ALTERNATE) ? "R" : "_",
+ (clock_time.flags & DCFB_CALLBIT) ? "R" : "_",
(clock_time.flags & DCFB_ANNOUNCE) ? "A" : "_",
(clock_time.flags & DCFB_DST) ? "D" : "_",
(clock_time.flags & DCFB_LEAP) ? "L" : "_",
@@ -1860,7 +1837,7 @@ main(
fflush(stdout);
}
} while ((rrc == -1) && (errno == EINTR));
-
+
/*
* lost IO - sorry guys
*/
@@ -1870,7 +1847,7 @@ main(
}
closelog();
-
+
return 0;
}
OpenPOWER on IntegriCloud