PUD: add downlink socket, no handling yet
[olsrd.git] / lib / pud / src / pud.c
index 0c63510..5ad9452 100644 (file)
@@ -7,25 +7,15 @@
 #include "gpsConversion.h"
 #include "receiver.h"
 #include "dedup.h"
+#include "compiler.h"
 
 /* OLSRD includes */
-#include "olsr.h"
-#include "cfgparser/olsrd_conf.h"
 #include "ipcalc.h"
-#include "nmea/parser.h"
 #include "parser.h"
+#include "olsr.h"
 
 /* System includes */
-#include <nmea/parser.h>
-#include <stddef.h>
-#include <string.h>
-#include <errno.h>
-#include <stdarg.h>
 #include <assert.h>
-#include <stdio.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <unistd.h>
 
 /** The size of the buffer in which the received NMEA string is stored */
 #define BUFFER_SIZE_FOR_OLSR   2048
@@ -129,29 +119,15 @@ static void sendToAllTxInterfaces(unsigned char *buffer,
  */
 bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
                struct interface *in_if __attribute__ ((unused)), union olsr_ip_addr *ipaddr __attribute__ ((unused))) {
-       const union olsr_ip_addr * originator;
-       unsigned char *olsrMessagePayload;
+       const union olsr_ip_addr * originator = getOlsrMessageOriginator(
+                       olsr_cnf->ip_version, olsrMessage);
        unsigned int transmitStringLength;
        unsigned char buffer[BUFFER_SIZE_FROM_OLSR];
 
 #ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
-       unsigned int olsrMessageSize;
-#endif
-
-       /* determine the originator of the messsage */
-       if (olsr_cnf->ip_version == AF_INET) {
-               originator = (const union olsr_ip_addr *) &olsrMessage->v4.originator;
-               olsrMessagePayload = (unsigned char *) &olsrMessage->v4.message;
-#ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
-               olsrMessageSize = ntohs(olsrMessage->v4.olsr_msgsize);
-#endif
-       } else {
-               originator = (const union olsr_ip_addr *) &olsrMessage->v6.originator;
-               olsrMessagePayload = (unsigned char *) &olsrMessage->v6.message;
-#ifdef PUD_DUMP_GPS_PACKETS_RX_OLSR
-               olsrMessageSize = ntohs(olsrMessage->v6.olsr_msgsize);
+       unsigned short olsrMessageSize =
+                       getOlsrMessageSize(olsr_cnf->ip_version, olsrMessage);
 #endif
-       }
 
        /* when we do not loopback then check if the message originated from this
         * node: back off */
@@ -175,8 +151,7 @@ bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
        dump_packet((unsigned char *) olsrMessage, olsrMessageSize);
 #endif
 
-       transmitStringLength = gpsFromOlsr(olsrMessage, olsrMessagePayload,
-                       &buffer[0], sizeof(buffer));
+       transmitStringLength = gpsFromOlsr(olsrMessage, &buffer[0], sizeof(buffer));
        if (unlikely(transmitStringLength == 0)) {
                return false;
        }
@@ -186,6 +161,23 @@ bool packetReceivedFromOlsr(union olsr_message *olsrMessage,
        return true;
 }
 
+/**
+ Called by OLSR core when a packet for the plugin is received from the downlink.
+ It unpacks the messages and distributes them into OLSR and on the LAN.
+
+ @param skfd
+ the socket file descriptor on which the packet is received
+ @param data
+ a pointer to the network interface structure on which the packet was received
+ @param flags
+ unused
+ */
+static void packetReceivedFromDownlink(int skfd, void *data __attribute__ ((unused)), unsigned int flags __attribute__ ((unused))) {
+       if (skfd >= 0) {
+               // empty now
+       }
+}
+
 /**
  Called by OLSR core when a packet for the plugin is received from the non-OLSR
  network. It converts the packet into the internal OLSR wire format for a
@@ -275,8 +267,6 @@ bool initPud(void) {
                goto error;
        }
 
-       setupCachedValidityTimeMsn();
-
        initDeDupList(&deDupList, getDeDupDepth());
 
        /* set global transmit socket config */
@@ -291,7 +281,8 @@ bool initPud(void) {
         * Creates receive and transmit sockets and register the receive sockets
         * with the OLSR stack
         */
-       if (!createNetworkInterfaces(&packetReceivedForOlsr)) {
+       if (!createNetworkInterfaces(&packetReceivedForOlsr,
+                       &packetReceivedFromDownlink)) {
                pudError(false, "Could not create require network interfaces");
                goto error;
        }