Indented with indent.sh script.
This commit is contained in:
@@ -120,7 +120,8 @@ static const char *Capture_Filename = "mstp.cap";
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
|
||||
/* write packet to file in libpcap format */
|
||||
static void write_global_header(void)
|
||||
static void write_global_header(
|
||||
void)
|
||||
{
|
||||
uint32_t magic_number = 0xa1b2c3d4; /* magic number */
|
||||
uint16_t version_major = 2; /* major version number */
|
||||
@@ -141,11 +142,10 @@ static void write_global_header(void)
|
||||
fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
fwrite(&network, sizeof(network), 1, pFile);
|
||||
fflush(pFile);
|
||||
fprintf(stdout,"mstpcap: saving capture to %s\n",
|
||||
Capture_Filename);
|
||||
fprintf(stdout, "mstpcap: saving capture to %s\n", Capture_Filename);
|
||||
} else {
|
||||
fprintf(stderr,"mstpcap: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "mstpcap: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,12 +187,13 @@ static void write_received_packet(
|
||||
fwrite((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"mstpcap: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "mstpcap: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup(void)
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
if (pFile) {
|
||||
fflush(pFile); /* stream pointer */
|
||||
@@ -202,7 +203,8 @@ static void cleanup(void)
|
||||
}
|
||||
|
||||
#if (!defined(_WIN32))
|
||||
static void sig_int(int signo)
|
||||
static void sig_int(
|
||||
int signo)
|
||||
{
|
||||
(void) signo;
|
||||
|
||||
@@ -210,7 +212,8 @@ static void sig_int(int signo)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void signal_init(void)
|
||||
void signal_init(
|
||||
void)
|
||||
{
|
||||
signal(SIGINT, sig_int);
|
||||
signal(SIGHUP, sig_int);
|
||||
|
||||
@@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
|
||||
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
|
||||
return 0;
|
||||
}
|
||||
/* decode the command line parameters */
|
||||
cov_data.subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
|
||||
/* decode the command line parameters */ cov_data.
|
||||
subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
|
||||
cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0);
|
||||
cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0);
|
||||
cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0);
|
||||
|
||||
@@ -127,7 +127,8 @@ int dlmstp_send_pdu(
|
||||
packet.pdu_len = pdu_len;
|
||||
memmove(&packet.pdu[0], &pdu[0], pdu_len);
|
||||
memmove(&packet.address, dest, sizeof(packet.address));
|
||||
rc = mq_send(NPDU_Transmit_Queue, (const char *)&packet, sizeof(packet), 0);
|
||||
rc = mq_send(NPDU_Transmit_Queue, (const char *) &packet,
|
||||
sizeof(packet), 0);
|
||||
if (rc > 0)
|
||||
bytes_sent = rc;
|
||||
}
|
||||
@@ -168,11 +169,8 @@ uint16_t dlmstp_receive(
|
||||
epoch_time = time(NULL);
|
||||
queue_timeout.tv_sec += epoch_time;
|
||||
|
||||
received_bytes = mq_timedreceive(
|
||||
NPDU_Receive_Queue,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
&msg_prio,
|
||||
received_bytes =
|
||||
mq_timedreceive(NPDU_Receive_Queue, buffer, sizeof(buffer), &msg_prio,
|
||||
&queue_timeout);
|
||||
|
||||
/* See if there is a problem */
|
||||
@@ -182,8 +180,7 @@ uint16_t dlmstp_receive(
|
||||
/* was immediately available for reading. */
|
||||
if ((errno != EAGAIN) && (errno != ETIMEDOUT)) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MS/TP: NPDU Receive: %s\n",
|
||||
strerror(errno));
|
||||
fprintf(stderr, "MS/TP: NPDU Receive: %s\n", strerror(errno));
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
@@ -327,11 +324,8 @@ int dlmstp_get_transmit_packet(
|
||||
epoch_time = time(NULL);
|
||||
queue_timeout.tv_sec += epoch_time;
|
||||
|
||||
received_bytes = mq_timedreceive(
|
||||
NPDU_Transmit_Queue,
|
||||
buffer,
|
||||
sizeof(buffer),
|
||||
&msg_prio,
|
||||
received_bytes =
|
||||
mq_timedreceive(NPDU_Transmit_Queue, buffer, sizeof(buffer), &msg_prio,
|
||||
&queue_timeout);
|
||||
|
||||
/* See if there is a problem */
|
||||
@@ -341,7 +335,8 @@ int dlmstp_get_transmit_packet(
|
||||
/* was immediately available for reading. */
|
||||
if ((errno != EAGAIN) && (errno != ETIMEDOUT)) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MS/TP: Read error in Transmit_Client packet: %s\n",
|
||||
fprintf(stderr,
|
||||
"MS/TP: Read error in Transmit_Client packet: %s\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
}
|
||||
@@ -521,23 +516,23 @@ uint16_t MSTP_Get_Reply(
|
||||
/* is this the reply to the DER? */
|
||||
matched =
|
||||
dlmstp_compare_data_expecting_reply(&mstp_port->InputBuffer[0],
|
||||
mstp_port->DataLength, mstp_port->SourceAddress,
|
||||
&packet.pdu[0], packet.pdu_len,
|
||||
&packet.address);
|
||||
mstp_port->DataLength, mstp_port->SourceAddress, &packet.pdu[0],
|
||||
packet.pdu_len, &packet.address);
|
||||
if (matched) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MSTP: sending packet to FSM.\n");
|
||||
#endif
|
||||
/* convert the PDU into the MSTP Frame */
|
||||
pdu_len = MSTP_Create_Frame(&mstp_port->OutputBuffer[0],
|
||||
mstp_port->OutputBufferSize, packet.frame_type,
|
||||
destination, mstp_port->This_Station, &packet.pdu[0],
|
||||
packet.pdu_len);
|
||||
pdu_len =
|
||||
MSTP_Create_Frame(&mstp_port->OutputBuffer[0],
|
||||
mstp_port->OutputBufferSize, packet.frame_type, destination,
|
||||
mstp_port->This_Station, &packet.pdu[0], packet.pdu_len);
|
||||
/* not used here, but setting it anyway */
|
||||
packet.ready = false;
|
||||
} else {
|
||||
/* put it back into the queue */
|
||||
(void)mq_send(NPDU_Transmit_Queue, (char *)&packet, sizeof(packet), 1);
|
||||
(void) mq_send(NPDU_Transmit_Queue, (char *) &packet, sizeof(packet),
|
||||
1);
|
||||
}
|
||||
|
||||
return pdu_len;
|
||||
@@ -692,22 +687,18 @@ bool dlmstp_init(
|
||||
mqattr.mq_msgsize = sizeof(struct dlmstp_packet);
|
||||
/* create a queue for the NDPU data between MS/TP threads */
|
||||
snprintf(mqname, sizeof(mqname), "/MSTP_Rx_%d", getpid());
|
||||
NPDU_Transmit_Queue = mq_open(mqname,
|
||||
O_RDWR | O_CREAT, 0600, &mqattr);
|
||||
NPDU_Transmit_Queue = mq_open(mqname, O_RDWR | O_CREAT, 0600, &mqattr);
|
||||
if (NPDU_Transmit_Queue == -1) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MS/TP: Create NPDU Transmit Queue %s: %s\n",
|
||||
mqname,
|
||||
fprintf(stderr, "MS/TP: Create NPDU Transmit Queue %s: %s\n", mqname,
|
||||
strerror(errno));
|
||||
#endif
|
||||
}
|
||||
snprintf(mqname, sizeof(mqname), "/MSTP_Tx_%d", getpid());
|
||||
NPDU_Receive_Queue = mq_open(mqname,
|
||||
O_RDWR | O_CREAT, 0600, &mqattr);
|
||||
NPDU_Receive_Queue = mq_open(mqname, O_RDWR | O_CREAT, 0600, &mqattr);
|
||||
if (NPDU_Receive_Queue == -1) {
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "MS/TP: Create NPDU Receive Queue %s: %s\n",
|
||||
mqname,
|
||||
fprintf(stderr, "MS/TP: Create NPDU Receive Queue %s: %s\n", mqname,
|
||||
strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -91,7 +91,8 @@ void RS485_Set_Interface(
|
||||
* ALGORITHM: none
|
||||
* NOTES: none
|
||||
*********************************************************************/
|
||||
const char *RS485_Interface(void)
|
||||
const char *RS485_Interface(
|
||||
void)
|
||||
{
|
||||
return RS485_Port_Name;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ extern "C" {
|
||||
|
||||
void RS485_Set_Interface(
|
||||
char *ifname);
|
||||
const char * RS485_Interface(void);
|
||||
const char *RS485_Interface(
|
||||
void);
|
||||
|
||||
void RS485_Initialize(
|
||||
void);
|
||||
|
||||
@@ -149,7 +149,8 @@ static const char *Capture_Filename = "mstp.cap";
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
|
||||
/* write packet to file in libpcap format */
|
||||
static void write_global_header(void)
|
||||
static void write_global_header(
|
||||
void)
|
||||
{
|
||||
uint32_t magic_number = 0xa1b2c3d4; /* magic number */
|
||||
uint16_t version_major = 2; /* major version number */
|
||||
@@ -170,8 +171,8 @@ static void write_global_header(void)
|
||||
fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
fwrite(&network, sizeof(network), 1, pFile);
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,12 +214,13 @@ static void write_received_packet(
|
||||
fwrite(&(mstp_port->DataCRCActualLSB), 1, 1, pFile);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup(void)
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
if (pFile) {
|
||||
fflush(pFile); /* stream pointer */
|
||||
@@ -262,7 +264,8 @@ static void print_received_packet(
|
||||
}
|
||||
#endif
|
||||
|
||||
static void sig_int(int signo)
|
||||
static void sig_int(
|
||||
int signo)
|
||||
{
|
||||
(void) signo;
|
||||
|
||||
@@ -270,7 +273,8 @@ static void sig_int(int signo)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void signal_init(void)
|
||||
void signal_init(
|
||||
void)
|
||||
{
|
||||
signal(SIGINT, sig_int);
|
||||
signal(SIGHUP, sig_int);
|
||||
|
||||
@@ -53,7 +53,9 @@ struct timespec {
|
||||
};
|
||||
|
||||
|
||||
static inline int gettimeofday(struct timeval *tp, void *tzp)
|
||||
static inline int gettimeofday(
|
||||
struct timeval *tp,
|
||||
void *tzp)
|
||||
{
|
||||
struct _timeb timebuffer;
|
||||
|
||||
@@ -65,13 +67,14 @@ static inline int gettimeofday(struct timeval *tp, void *tzp)
|
||||
}
|
||||
|
||||
/* FIXME: not a complete implementation of the posix function */
|
||||
static inline int sem_timedwait(sem_t *sem,
|
||||
static inline int sem_timedwait(
|
||||
sem_t * sem,
|
||||
const struct timespec *abs_timeout)
|
||||
{
|
||||
struct timeval tp;
|
||||
DWORD wait_status = 0;
|
||||
DWORD dwMilliseconds = (abs_timeout->tv_sec * 1000) +
|
||||
(abs_timeout->tv_nsec / 1000);
|
||||
DWORD dwMilliseconds =
|
||||
(abs_timeout->tv_sec * 1000) + (abs_timeout->tv_nsec / 1000);
|
||||
|
||||
gettimeofday(&tp, NULL);
|
||||
if (abs_timeout->tv_sec >= tp.tv_sec) {
|
||||
@@ -91,11 +94,13 @@ static inline int sem_timedwait(sem_t *sem,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
static inline int sem_init(
|
||||
sem_t * sem,
|
||||
int pshared,
|
||||
unsigned int value)
|
||||
{
|
||||
(void) pshared;
|
||||
*sem = CreateSemaphore(
|
||||
NULL/*lpSecurityDescriptor*/,
|
||||
*sem = CreateSemaphore(NULL /*lpSecurityDescriptor */ ,
|
||||
value /* lInitialCount */ ,
|
||||
1 /* lMaximumCount */ ,
|
||||
NULL /* lpName */ );
|
||||
@@ -106,10 +111,11 @@ static inline int sem_init(sem_t *sem, int pshared, unsigned int value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
static inline int nanosleep(
|
||||
const struct timespec *rqtp,
|
||||
struct timespec *rmtp)
|
||||
{
|
||||
DWORD dwMilliseconds = (rqtp->tv_sec * 1000) +
|
||||
(rqtp->tv_nsec / 1000);
|
||||
DWORD dwMilliseconds = (rqtp->tv_sec * 1000) + (rqtp->tv_nsec / 1000);
|
||||
|
||||
Sleep(dwMilliseconds);
|
||||
|
||||
|
||||
@@ -97,7 +97,8 @@ void RS485_Set_Interface(
|
||||
}
|
||||
}
|
||||
|
||||
const char *RS485_Interface(void)
|
||||
const char *RS485_Interface(
|
||||
void)
|
||||
{
|
||||
return RS485_Port_Name;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ extern "C" {
|
||||
|
||||
void RS485_Set_Interface(
|
||||
char *ifname);
|
||||
const char * RS485_Interface(void);
|
||||
const char *RS485_Interface(
|
||||
void);
|
||||
|
||||
void RS485_Initialize(
|
||||
void);
|
||||
|
||||
@@ -170,8 +170,8 @@ static void print_received_packet(
|
||||
/* returns a delta timestamp */
|
||||
void timestamp(
|
||||
uint32_t * ts_sec, /* timestamp seconds since epoch (Unix) */
|
||||
uint32_t *ts_usec) /* timestamp microseconds (unix) */
|
||||
{
|
||||
uint32_t * ts_usec)
|
||||
{ /* timestamp microseconds (unix) */
|
||||
DWORD ticks = 0;
|
||||
static DWORD initial_ticks = 0;
|
||||
static time_t initial_seconds = 0;
|
||||
@@ -198,7 +198,8 @@ static const char *Capture_Filename = "mstp.cap";
|
||||
static FILE *pFile = NULL; /* stream pointer */
|
||||
|
||||
/* write packet to file in libpcap format */
|
||||
static void write_global_header(void)
|
||||
static void write_global_header(
|
||||
void)
|
||||
{
|
||||
uint32_t magic_number = 0xa1b2c3d4; /* magic number */
|
||||
uint16_t version_major = 2; /* major version number */
|
||||
@@ -219,8 +220,8 @@ static void write_global_header(void)
|
||||
fwrite(&snaplen, sizeof(snaplen), 1, pFile);
|
||||
fwrite(&network, sizeof(network), 1, pFile);
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,14 +260,15 @@ static void write_received_packet(
|
||||
fwrite(&(mstp_port->DataCRCActualLSB), 1, 1, pFile);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,"rx_fsm: failed to open %s: %s\n",
|
||||
Capture_Filename, strerror(errno));
|
||||
fprintf(stderr, "rx_fsm: failed to open %s: %s\n", Capture_Filename,
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
static char *Network_Interface = NULL;
|
||||
|
||||
static void cleanup(void)
|
||||
static void cleanup(
|
||||
void)
|
||||
{
|
||||
if (pFile) {
|
||||
fflush(pFile); /* stream pointer */
|
||||
|
||||
@@ -621,8 +621,7 @@ bool dlmstp_init(
|
||||
rv = sem_init(&Receive_Packet_Flag, 0, 0);
|
||||
Receive_Packet_Flag = CreateSemaphore(NULL, 0, 1, "dlmstpReceivePacket");
|
||||
if (rv) {
|
||||
fprintf(stderr,
|
||||
"MS/TP Interface: %s\n cannot allocate semaphore.",
|
||||
fprintf(stderr, "MS/TP Interface: %s\n cannot allocate semaphore.",
|
||||
ifname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
+341
-203
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user