Cleanup patches from Rune Magnussen
This commit is contained in:
@@ -9,53 +9,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <ftdi.h>
|
||||
#include "infnoise.h"
|
||||
#include "KeccakF-1600-interface.h"
|
||||
|
||||
// The FT240X has a 512 byte buffer. Must be multiple of 64
|
||||
// We also write this in one go to the Keccak sponge, which is at most 1600 bits
|
||||
#define BUFLEN 512
|
||||
|
||||
// This is how many previous bits are used to predict the next bit from the INM
|
||||
#define PREDICTION_BITS 14
|
||||
|
||||
// This is the maximum time we allow to pass to perform the I/O operations, since long
|
||||
// delays can reduce entropy from the INM.
|
||||
#define MAX_MICROSEC_FOR_SAMPLES 5000
|
||||
|
||||
// This is the gain of each of the two op-amp stages in the INM
|
||||
#define DESIGN_K 1.84
|
||||
|
||||
// This defines which pins on the FT240X are used
|
||||
#ifdef VERSION1
|
||||
|
||||
// The V1 version is the original raw board with the edge connector instead of a real USB plug
|
||||
#define COMP1 2
|
||||
#define COMP2 0
|
||||
#define SWEN1 4
|
||||
#define SWEN2 1
|
||||
|
||||
#else
|
||||
|
||||
// This is the production version with a real USB plug
|
||||
#define COMP1 1
|
||||
#define COMP2 4
|
||||
#define SWEN1 2
|
||||
#define SWEN2 0
|
||||
|
||||
#endif
|
||||
|
||||
// The remaining 8 bits are driven with 0 .. 15 to help track the cause of misfires
|
||||
#define ADDR0 3
|
||||
#define ADDR1 5
|
||||
#define ADDR2 6
|
||||
#define ADDR3 7
|
||||
|
||||
// All data bus bits of the FT240X are outputs, except COMP1 and COMP2
|
||||
#define MASK (0xff & ~(1 << COMP1) & ~(1 << COMP2))
|
||||
|
||||
// Convert an address value 0 to 15 to an 8-bit value using ADDR0 .. ADDR3.
|
||||
static uint8_t makeAddress(uint8_t addr) {
|
||||
uint8_t value = 0;
|
||||
@@ -92,7 +49,6 @@ static uint8_t extractAddress(uint8_t value) {
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
// Extract the INM output from the data received. Basically, either COMP1 or COMP2
|
||||
// changes, not both, so alternate reading bits from them. We get 1 INM bit of output
|
||||
// per byte read. Feed bits from the INM to the health checker. Return the expected
|
||||
@@ -293,6 +249,10 @@ int main(int argc, char **argv)
|
||||
xArg++;
|
||||
pidFileName = argv[xArg];
|
||||
pidFile = true;
|
||||
if(pidFileName == NULL || !strcmp("",pidFileName)) {
|
||||
fputs("--pidfile without file name\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
} else if(!strcmp(argv[xArg], "--daemon")) {
|
||||
runDaemon = true;
|
||||
} else {
|
||||
@@ -310,7 +270,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if(geteuid() != 0) {
|
||||
if(!isSuperUser()) {
|
||||
fputs("Super user access needed.\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
@@ -319,25 +279,8 @@ int main(int argc, char **argv)
|
||||
outputMultiplier = 2; // Don't throw away entropy when writing to /dev/random unless told to do so
|
||||
}
|
||||
|
||||
// If the user wants a pid-file, but no backgrounding then write the current PID.
|
||||
if (pidFile && !runDaemon) {
|
||||
writePid(getpid(), pidFileName);
|
||||
}
|
||||
|
||||
if (runDaemon) {
|
||||
pid_t pid = fork();
|
||||
if(pid < 0) {
|
||||
fputs("fork() failed\n", stderr);
|
||||
return 1;
|
||||
} else if(pid > 0) {
|
||||
// Parent
|
||||
if(pidFile) {
|
||||
return writePid(pid, pidFileName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// Pid == 0 - Child
|
||||
}
|
||||
// Optionally run in the background and optionally write a PID-file
|
||||
startDaemon(runDaemon, pidFile, pidFileName);
|
||||
|
||||
if(writeDevRandom) {
|
||||
inmWriteEntropyStart(BUFLEN/8, debug);
|
||||
|
||||
Reference in New Issue
Block a user