refclock_jupiter.c [plain text]
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if defined(REFCLOCK) && defined(CLOCK_JUPITER) && defined(HAVE_PPSAPI)
#include "ntpd.h"
#include "ntp_io.h"
#include "ntp_refclock.h"
#include "ntp_unixtime.h"
#include "ntp_stdlib.h"
#include <stdio.h>
#include <ctype.h>
#include "jupiter.h"
#ifdef HAVE_PPSAPI
# include "ppsapi_timepps.h"
#endif
#ifdef XNTP_BIG_ENDIAN
#define getshort(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#define putshort(s) ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff))
#else
#define getshort(s) (s)
#define putshort(s) (s)
#endif
#ifdef sun
char *strerror(int);
#endif
#define DEVICE "/dev/gps%d"
#define SPEED232 B9600
#define PRECISION (-18)
#define REFID "GPS\0"
#define DESCRIPTION "Rockwell Jupiter GPS Receiver"
#define DEFFUDGETIME 0
#define GPS_EPOCH 315964800
#define DS2UI(p) ((getshort((p)[1]) << 16) | getshort((p)[0]))
#define DS2I(p) ((getshort((p)[1]) << 16) | getshort((p)[0]))
#define WEEKSECS (7 * 24 * 60 * 60)
struct instance {
struct peer *peer;
u_int pollcnt;
u_int polled;
#ifdef HAVE_PPSAPI
pps_params_t pps_params;
pps_info_t pps_info;
pps_handle_t pps_handle;
u_int assert;
u_int hardpps;
struct timespec ts;
#endif
l_fp limit;
u_int gpos_gweek;
u_int gpos_sweek;
u_int gweek;
u_int32 lastsweek;
time_t timecode;
u_int32 stime;
int wantid;
u_int moving;
u_char sloppyclockflag;
u_short sbuf[512];
int ssize;
};
static void jupiter_canmsg P((struct instance *, u_int));
static u_short jupiter_cksum P((u_short *, u_int));
static int jupiter_config P((struct instance *));
static void jupiter_debug P((struct peer *, char *, char *, ...))
__attribute__ ((format (printf, 3, 4)));
static char * jupiter_parse_t P((struct instance *, u_short *));
static char * jupiter_parse_gpos P((struct instance *, u_short *));
static void jupiter_platform P((struct instance *, u_int));
static void jupiter_poll P((int, struct peer *));
static void jupiter_control P((int, struct refclockstat *, struct
refclockstat *, struct peer *));
#ifdef HAVE_PPSAPI
static int jupiter_ppsapi P((struct instance *));
static int jupiter_pps P((struct instance *));
#endif
static int jupiter_recv P((struct instance *));
static void jupiter_receive P((struct recvbuf *rbufp));
static void jupiter_reqmsg P((struct instance *, u_int, u_int));
static void jupiter_reqonemsg P((struct instance *, u_int));
static char * jupiter_send P((struct instance *, struct jheader *));
static void jupiter_shutdown P((int, struct peer *));
static int jupiter_start P((int, struct peer *));
struct refclock refclock_jupiter = {
jupiter_start,
jupiter_shutdown,
jupiter_poll,
jupiter_control,
noentry,
noentry,
NOFLAGS
};
static int
jupiter_start(
int unit,
struct peer *peer
)
{
struct refclockproc *pp;
struct instance *instance;
int fd = -1;
char gpsdev[20];
(void)sprintf(gpsdev, DEVICE, unit);
fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
if (fd == 0) {
jupiter_debug(peer, "jupiter_start", "open %s: %s",
gpsdev, strerror(errno));
return (0);
}
if ((instance = (struct instance *)
emalloc(sizeof(struct instance))) == NULL) {
(void) close(fd);
return (0);
}
memset((char *)instance, 0, sizeof(struct instance));
instance->peer = peer;
pp = peer->procptr;
pp->io.clock_recv = jupiter_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
(void) close(fd);
free(instance);
return (0);
}
pp->unitptr = (caddr_t)instance;
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
memcpy((char *)&pp->refid, REFID, 4);
#ifdef HAVE_PPSAPI
instance->assert = 1;
instance->hardpps = 0;
if (time_pps_create(fd, &instance->pps_handle) < 0) {
instance->pps_handle = 0;
msyslog(LOG_ERR,
"refclock_jupiter: time_pps_create failed: %m");
}
else if (!jupiter_ppsapi(instance))
goto clean_up;
#endif
if (!jupiter_config(instance))
goto clean_up;
return (1);
clean_up:
jupiter_shutdown(unit, peer);
pp->unitptr = 0;
return (0);
}
static void
jupiter_shutdown(int unit, struct peer *peer)
{
struct instance *instance;
struct refclockproc *pp;
pp = peer->procptr;
instance = (struct instance *)pp->unitptr;
if (!instance)
return;
#ifdef HAVE_PPSAPI
if (instance->pps_handle) {
time_pps_destroy(instance->pps_handle);
instance->pps_handle = 0;
}
#endif
io_closeclock(&pp->io);
free(instance);
}
static int
jupiter_config(struct instance *instance)
{
jupiter_debug(instance->peer, "jupiter_config", "init receiver");
instance->sloppyclockflag = instance->peer->procptr->sloppyclockflag;
instance->moving = !!(instance->sloppyclockflag & CLK_FLAG2);
if (instance->moving)
jupiter_debug(instance->peer, "jupiter_config",
"mobile platform");
instance->pollcnt = 2;
instance->polled = 0;
instance->gpos_gweek = 0;
instance->gpos_sweek = 0;
instance->gweek = 0;
instance->lastsweek = 2 * WEEKSECS;
instance->timecode = 0;
instance->stime = 0;
instance->ssize = 0;
jupiter_canmsg(instance, JUPITER_ALL);
jupiter_reqonemsg(instance, JUPITER_O_ID);
instance->wantid = 1;
jupiter_reqmsg(instance, JUPITER_O_PULSE, 1);
jupiter_reqmsg(instance, JUPITER_O_GPOS, 1);
if (instance->moving)
jupiter_platform(instance, JUPITER_I_PLAT_MED);
else
jupiter_platform(instance, JUPITER_I_PLAT_LOW);
return (1);
}
#ifdef HAVE_PPSAPI
int
jupiter_ppsapi(
struct instance *instance
)
{
int capability;
if (time_pps_getcap(instance->pps_handle, &capability) < 0) {
msyslog(LOG_ERR,
"refclock_jupiter: time_pps_getcap failed: %m");
return (0);
}
memset(&instance->pps_params, 0, sizeof(pps_params_t));
if (!instance->assert)
instance->pps_params.mode = capability & PPS_CAPTURECLEAR;
else
instance->pps_params.mode = capability & PPS_CAPTUREASSERT;
if (!(instance->pps_params.mode & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR))) {
msyslog(LOG_ERR,
"refclock_jupiter: invalid capture edge %d",
instance->assert);
return (0);
}
instance->pps_params.mode |= PPS_TSFMT_TSPEC;
if (time_pps_setparams(instance->pps_handle, &instance->pps_params) < 0) {
msyslog(LOG_ERR,
"refclock_jupiter: time_pps_setparams failed: %m");
return (0);
}
if (instance->hardpps) {
if (time_pps_kcbind(instance->pps_handle, PPS_KC_HARDPPS,
instance->pps_params.mode & ~PPS_TSFMT_TSPEC,
PPS_TSFMT_TSPEC) < 0) {
msyslog(LOG_ERR,
"refclock_jupiter: time_pps_kcbind failed: %m");
return (0);
}
pps_enable = 1;
}
#if DEBUG
if (debug) {
time_pps_getparams(instance->pps_handle, &instance->pps_params);
jupiter_debug(instance->peer, "refclock_jupiter",
"pps capability 0x%x version %d mode 0x%x kern %d",
capability, instance->pps_params.api_version,
instance->pps_params.mode, instance->hardpps);
}
#endif
return (1);
}
static int
jupiter_pps(struct instance *instance)
{
pps_info_t pps_info;
struct timespec timeout, ts;
double dtemp;
l_fp tstmp;
if (instance->pps_handle == 0)
return 1;
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
memcpy(&pps_info, &instance->pps_info, sizeof(pps_info_t));
if (time_pps_fetch(instance->pps_handle, PPS_TSFMT_TSPEC, &instance->pps_info,
&timeout) < 0)
return 1;
if (instance->pps_params.mode & PPS_CAPTUREASSERT) {
if (pps_info.assert_sequence ==
instance->pps_info.assert_sequence)
return 1;
ts = instance->pps_info.assert_timestamp;
} else if (instance->pps_params.mode & PPS_CAPTURECLEAR) {
if (pps_info.clear_sequence ==
instance->pps_info.clear_sequence)
return 1;
ts = instance->pps_info.clear_timestamp;
} else {
return 1;
}
if ((instance->ts.tv_sec == ts.tv_sec) && (instance->ts.tv_nsec == ts.tv_nsec))
return 1;
instance->ts = ts;
tstmp.l_ui = ts.tv_sec + JAN_1970;
dtemp = ts.tv_nsec * FRAC / 1e9;
tstmp.l_uf = (u_int32)dtemp;
instance->peer->procptr->lastrec = tstmp;
return 0;
}
#endif
static void
jupiter_poll(int unit, struct peer *peer)
{
struct instance *instance;
struct refclockproc *pp;
pp = peer->procptr;
instance = (struct instance *)pp->unitptr;
if (instance->pollcnt > 0) {
instance->pollcnt--;
} else {
refclock_report(peer, CEVNT_TIMEOUT);
jupiter_reqonemsg(instance, JUPITER_O_ID);
instance->wantid = 0;
}
instance->polled = 1;
pp->polls++;
}
static void
jupiter_control(
int unit,
struct refclockstat *in,
struct refclockstat *out,
struct peer *peer
)
{
struct refclockproc *pp;
struct instance *instance;
u_char sloppyclockflag;
pp = peer->procptr;
instance = (struct instance *)pp->unitptr;
DTOLFP(pp->fudgetime2, &instance->limit);
if (L_ISNEG(&instance->limit))
L_NEG(&instance->limit);
#ifdef HAVE_PPSAPI
instance->assert = !(pp->sloppyclockflag & CLK_FLAG3);
jupiter_ppsapi(instance);
#endif
sloppyclockflag = instance->sloppyclockflag;
instance->sloppyclockflag = pp->sloppyclockflag;
if ((instance->sloppyclockflag & CLK_FLAG2) !=
(sloppyclockflag & CLK_FLAG2)) {
jupiter_debug(peer,
"jupiter_control",
"mode switch: reset receiver");
jupiter_config(instance);
return;
}
}
static void
jupiter_receive(struct recvbuf *rbufp)
{
int bpcnt, cc, size, ppsret;
time_t last_timecode;
u_int32 laststime;
char *cp;
u_char *bp;
u_short *sp;
struct jid *ip;
struct jheader *hp;
struct peer *peer;
struct refclockproc *pp;
struct instance *instance;
l_fp tstamp;
peer = (struct peer *)rbufp->recv_srcclock;
pp = peer->procptr;
instance = (struct instance *)pp->unitptr;
bp = (u_char *)rbufp->recv_buffer;
bpcnt = rbufp->recv_length;
if (bpcnt > sizeof(instance->sbuf) - instance->ssize)
bpcnt = sizeof(instance->sbuf) - instance->ssize;
memcpy((u_char *)instance->sbuf + instance->ssize, bp, bpcnt);
instance->ssize += bpcnt;
while (instance->ssize > sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) {
instance->pollcnt = 2;
tstamp = rbufp->recv_time;
hp = (struct jheader *)instance->sbuf;
sp = (u_short *)(hp + 1);
size = cc - sizeof(*hp);
switch (getshort(hp->id)) {
case JUPITER_O_PULSE:
if (size != sizeof(struct jpulse)) {
jupiter_debug(peer,
"jupiter_receive", "pulse: len %d != %u",
size, (int)sizeof(struct jpulse));
refclock_report(peer, CEVNT_BADREPLY);
break;
}
laststime = instance->stime;
instance->stime = DS2UI(((struct jpulse *)sp)->stime);
if (laststime != 0 && instance->stime - laststime <= 21) {
jupiter_debug(peer, "jupiter_receive",
"avoided firmware bug (stime %.2f, laststime %.2f)",
(double)instance->stime * 0.01, (double)laststime * 0.01);
break;
}
ppsret = jupiter_pps(instance);
L_SUB(&tstamp, &pp->lastrec);
if (!L_ISGEQ(&tstamp, &instance->limit))
++pp->lastrec.l_ui;
last_timecode = instance->timecode;
if ((cp = jupiter_parse_t(instance, sp)) != NULL) {
jupiter_debug(peer,
"jupiter_receive", "pulse: %s", cp);
break;
}
if (ppsret)
break;
if (last_timecode == 0)
break;
tstamp.l_ui = JAN_1970 + last_timecode;
tstamp.l_uf = 0;
refclock_process_offset(pp, tstamp, pp->lastrec, pp->fudgetime1);
if (!instance->polled)
break;
instance->polled = 0;
pp->lastref = pp->lastrec;
refclock_receive(peer);
refclock_report(peer, CEVNT_NOMINAL);
instance->polled = 0;
break;
case JUPITER_O_GPOS:
if (size != sizeof(struct jgpos)) {
jupiter_debug(peer,
"jupiter_receive", "gpos: len %d != %u",
size, (int)sizeof(struct jgpos));
refclock_report(peer, CEVNT_BADREPLY);
break;
}
if ((cp = jupiter_parse_gpos(instance, sp)) != NULL) {
jupiter_debug(peer,
"jupiter_receive", "gpos: %s", cp);
break;
}
break;
case JUPITER_O_ID:
if (size != sizeof(struct jid)) {
jupiter_debug(peer,
"jupiter_receive", "id: len %d != %u",
size, (int)sizeof(struct jid));
refclock_report(peer, CEVNT_BADREPLY);
break;
}
ip = (struct jid *)sp;
jupiter_debug(peer,
"jupiter_receive", "%s chan ver %s, %s (%s)",
ip->chans, ip->vers, ip->date, ip->opts);
msyslog(LOG_DEBUG,
"jupiter_receive: %s chan ver %s, %s (%s)",
ip->chans, ip->vers, ip->date, ip->opts);
if (instance->wantid)
instance->wantid = 0;
else {
jupiter_debug(peer,
"jupiter_receive", "reset receiver");
jupiter_config(instance);
instance->ssize = cc;
}
break;
default:
jupiter_debug(peer,
"jupiter_receive", "unknown message id %d",
getshort(hp->id));
break;
}
instance->ssize -= cc;
if (instance->ssize < 0) {
fprintf(stderr, "jupiter_recv: negative ssize!\n");
abort();
} else if (instance->ssize > 0)
memcpy(instance->sbuf, (u_char *)instance->sbuf + cc, instance->ssize);
}
}
static char *
jupiter_parse_t(struct instance *instance, u_short *sp)
{
struct tm *tm;
char *cp;
struct jpulse *jp;
u_int32 sweek;
time_t last_timecode;
u_short flags;
jp = (struct jpulse *)sp;
sweek = DS2UI(jp->sweek) % WEEKSECS;
if (instance->gweek == 0) {
if (!instance->gpos_gweek) {
return ("jupiter_parse_t: Unknown gweek");
}
instance->gweek = instance->gpos_gweek;
if (instance->gpos_sweek >= sweek) {
if ((instance->gpos_sweek - sweek) > WEEKSECS / 2)
++instance->gweek;
}
else {
if ((sweek - instance->gpos_sweek) > WEEKSECS / 2)
--instance->gweek;
}
}
else if (sweek == 0 && instance->lastsweek == WEEKSECS - 1) {
++instance->gweek;
jupiter_debug(instance->peer,
"jupiter_parse_t", "NEW gps week %u", instance->gweek);
}
if (instance->lastsweek == sweek)
jupiter_debug(instance->peer,
"jupiter_parse_t", "gps sweek not incrementing (%d)",
sweek);
else if (instance->lastsweek != 2 * WEEKSECS &&
instance->lastsweek + 1 != sweek &&
!(sweek == 0 && instance->lastsweek == WEEKSECS - 1))
jupiter_debug(instance->peer,
"jupiter_parse_t", "gps sweek jumped (was %d, now %d)",
instance->lastsweek, sweek);
instance->lastsweek = sweek;
last_timecode = instance->timecode;
instance->timecode =
GPS_EPOCH + (instance->gweek * WEEKSECS) + sweek;
if (last_timecode == 0)
jupiter_debug(instance->peer,
"jupiter_parse_t", "UTC <none> (gweek/sweek %u/%u)",
instance->gweek, sweek);
else {
tm = gmtime(&last_timecode);
cp = asctime(tm);
jupiter_debug(instance->peer,
"jupiter_parse_t", "UTC %.24s (gweek/sweek %u/%u)",
cp, instance->gweek, sweek);
instance->peer->procptr->year = tm->tm_year + 1900;
instance->peer->procptr->day = tm->tm_yday + 1;
instance->peer->procptr->hour = tm->tm_hour;
instance->peer->procptr->minute = tm->tm_min;
instance->peer->procptr->second = tm->tm_sec;
}
flags = getshort(jp->flags);
if ((flags & JUPITER_O_PULSE_VALID) == 0) {
refclock_report(instance->peer, CEVNT_BADTIME);
return ("time mark not valid");
}
if ((flags & JUPITER_O_PULSE_UTC) == 0) {
refclock_report(instance->peer, CEVNT_BADTIME);
return ("time mark not sync'ed to UTC");
}
return (NULL);
}
static char *
jupiter_parse_gpos(struct instance *instance, u_short *sp)
{
struct jgpos *jg;
time_t t;
struct tm *tm;
char *cp;
jg = (struct jgpos *)sp;
if (jg->navval != 0) {
instance->gpos_gweek = 0;
instance->gpos_sweek = 0;
return ("Navigation solution not valid");
}
instance->gpos_gweek = jg->gweek;
instance->gpos_sweek = DS2UI(jg->sweek);
while(instance->gpos_sweek >= WEEKSECS) {
instance->gpos_sweek -= WEEKSECS;
++instance->gpos_gweek;
}
instance->gweek = 0;
t = GPS_EPOCH + (instance->gpos_gweek * WEEKSECS) + instance->gpos_sweek;
tm = gmtime(&t);
cp = asctime(tm);
jupiter_debug(instance->peer,
"jupiter_parse_g", "GPS %.24s (gweek/sweek %u/%u)",
cp, instance->gpos_gweek, instance->gpos_sweek);
return (NULL);
}
#if defined(__STDC__) || defined(SYS_WINNT)
static void
jupiter_debug(struct peer *peer, char *function, char *fmt, ...)
#else
static void
jupiter_debug(peer, function, fmt, va_alist)
struct peer *peer;
char *function;
char *fmt;
#endif
{
char buffer[200];
va_list ap;
#if defined(__STDC__) || defined(SYS_WINNT)
va_start(ap, fmt);
#else
va_start(ap);
#endif
vsnprintf(buffer, sizeof(buffer), fmt, ap);
record_clock_stats(&(peer->srcadr), buffer);
#ifdef DEBUG
if (debug) {
fprintf(stdout, "%s: ", function);
fprintf(stdout, buffer);
fprintf(stdout, "\n");
fflush(stdout);
}
#endif
va_end(ap);
}
static char *
jupiter_send(struct instance *instance, struct jheader *hp)
{
u_int len, size;
int cc;
u_short *sp;
static char errstr[132];
size = sizeof(*hp);
hp->hsum = putshort(jupiter_cksum((u_short *)hp,
(size / sizeof(u_short)) - 1));
len = getshort(hp->len);
if (len > 0) {
sp = (u_short *)(hp + 1);
sp[len] = putshort(jupiter_cksum(sp, len));
size += (len + 1) * sizeof(u_short);
}
if ((cc = write(instance->peer->procptr->io.fd, (char *)hp, size)) < 0) {
(void)sprintf(errstr, "write: %s", strerror(errno));
return (errstr);
} else if (cc != size) {
(void)sprintf(errstr, "short write (%d != %d)", cc, size);
return (errstr);
}
return (NULL);
}
static struct {
struct jheader jheader;
struct jrequest jrequest;
} reqmsg = {
{ putshort(JUPITER_SYNC), 0,
putshort((sizeof(struct jrequest) / sizeof(u_short)) - 1),
0, JUPITER_FLAG_REQUEST | JUPITER_FLAG_NAK |
JUPITER_FLAG_CONN | JUPITER_FLAG_LOG, 0 },
{ 0, 0, 0, 0 }
};
static void
jupiter_reqmsg(struct instance *instance, u_int id,
u_int interval)
{
struct jheader *hp;
struct jrequest *rp;
char *cp;
hp = &reqmsg.jheader;
hp->id = putshort(id);
rp = &reqmsg.jrequest;
rp->trigger = putshort(interval == 0);
rp->interval = putshort(interval);
if ((cp = jupiter_send(instance, hp)) != NULL)
jupiter_debug(instance->peer, "jupiter_reqmsg", "%u: %s", id, cp);
}
static struct jheader canmsg = {
putshort(JUPITER_SYNC), 0, 0, 0,
JUPITER_FLAG_REQUEST | JUPITER_FLAG_NAK | JUPITER_FLAG_DISC,
0
};
static void
jupiter_canmsg(struct instance *instance, u_int id)
{
struct jheader *hp;
char *cp;
hp = &canmsg;
hp->id = putshort(id);
if ((cp = jupiter_send(instance, hp)) != NULL)
jupiter_debug(instance->peer, "jupiter_canmsg", "%u: %s", id, cp);
}
static struct jheader reqonemsg = {
putshort(JUPITER_SYNC), 0, 0, 0,
JUPITER_FLAG_REQUEST | JUPITER_FLAG_NAK | JUPITER_FLAG_QUERY,
0
};
static void
jupiter_reqonemsg(struct instance *instance, u_int id)
{
struct jheader *hp;
char *cp;
hp = &reqonemsg;
hp->id = putshort(id);
if ((cp = jupiter_send(instance, hp)) != NULL)
jupiter_debug(instance->peer, "jupiter_reqonemsg", "%u: %s", id, cp);
}
static struct {
struct jheader jheader;
struct jplat jplat;
} platmsg = {
{ putshort(JUPITER_SYNC), putshort(JUPITER_I_PLAT),
putshort((sizeof(struct jplat) / sizeof(u_short)) - 1), 0,
JUPITER_FLAG_REQUEST | JUPITER_FLAG_NAK, 0 },
{ 0, 0, 0 }
};
static void
jupiter_platform(struct instance *instance, u_int platform)
{
struct jheader *hp;
struct jplat *pp;
char *cp;
hp = &platmsg.jheader;
pp = &platmsg.jplat;
pp->platform = putshort(platform);
if ((cp = jupiter_send(instance, hp)) != NULL)
jupiter_debug(instance->peer, "jupiter_platform", "%u: %s", platform, cp);
}
static u_short
jupiter_cksum(u_short *sp, u_int len)
{
u_short sum, x;
sum = 0;
while (len-- > 0) {
x = *sp++;
sum += getshort(x);
}
return (~sum + 1);
}
static int
jupiter_recv(struct instance *instance)
{
int n, len, size, cc;
struct jheader *hp;
u_char *bp;
u_short *sp;
cc = sizeof(*hp);
size = instance->ssize;
if (size < cc)
return (0);
sp = instance->sbuf;
hp = (struct jheader *)sp;
if (getshort(hp->sync) != JUPITER_SYNC) {
jupiter_debug(instance->peer, "jupiter_recv", "syncing");
bp = (u_char *)sp;
n = size;
while (n >= 2) {
if (bp[0] != (JUPITER_SYNC & 0xff)) {
++bp;
--n;
continue;
}
if (bp[1] == ((JUPITER_SYNC >> 8) & 0xff))
break;
bp += 2;
n -= 2;
}
if (n > 0)
memcpy(sp, bp, n);
size = n;
instance->ssize = size;
if (size < cc || hp->sync != JUPITER_SYNC)
return (0);
}
if (jupiter_cksum(sp, (cc / sizeof(u_short) - 1)) !=
getshort(hp->hsum)) {
jupiter_debug(instance->peer, "jupiter_recv", "bad header checksum!");
instance->ssize = 0;
return (0);
}
len = getshort(hp->len);
if (len > 0) {
n = (len + 1) * sizeof(u_short);
if (size < cc + n)
return (0);
sp = (u_short *)(hp + 1);
if (jupiter_cksum(sp, len) != getshort(sp[len])) {
jupiter_debug(instance->peer,
"jupiter_recv", "bad payload checksum!");
instance->ssize = 0;
return (0);
}
cc += n;
}
return (cc);
}
#else
int refclock_jupiter_bs;
#endif