1 #ifndef _PUD_WIREFORMAT_H_
2 #define _PUD_WIREFORMAT_H_
4 #include "olsr_protocol.h"
6 #include <OlsrdPudWireFormat/compiler.h>
11 #include <sys/socket.h>
18 /** The version of the wire format */
19 #define PUD_WIRE_FORMAT_VERSION 2
25 /** Flags that the GPS information contains the nodeId */
26 #define PUD_FLAGS_ID 0x80
28 /** Flags that the GPS information is originating from a gateway */
29 #define PUD_FLAGS_GATEWAY 0x40
35 /** The number of bits for the time field */
36 #define PUD_TIME_BITS 17
42 /** The number of bits for the latitude field */
43 #define PUD_LATITUDE_BITS 28
45 /** The maximum size of the string representation of the latitude
46 * sign [0,90] [0,59] dot [0,59] [0,999] */
47 #define PUD_TX_LATITUDE_DIGITS (1 + 2 + 2 + 1 + 2 + 3)
49 /** The number of decimals of the latitude in the transmit sentence */
50 #define PUD_TX_LATITUDE_DECIMALS "5"
56 /** The number of bits for the longitude field */
57 #define PUD_LONGITUDE_BITS 27
59 /** The maximum size of the string representation of the longitude
60 * sign [0,180] [0,59] dot [0,59] [0,999] */
61 #define PUD_TX_LONGITUDE_DIGITS (1 + 3 + 2 + 1 + 2 + 3)
63 /** The number of decimals of the longitude in the transmit sentence */
64 #define PUD_TX_LONGITUDE_DECIMALS "5"
70 /** The number of bits for the altitude field */
71 #define PUD_ALTITUDE_BITS 16
73 /** The minimum altitude */
74 #define PUD_ALTITUDE_MIN (-400)
76 /** The maximum altitude */
77 #define PUD_ALTITUDE_MAX (((1 << PUD_ALTITUDE_BITS) - 1) + PUD_ALTITUDE_MIN)
79 /** The maximum size of the string representation of the altitude */
80 #define PUD_TX_ALTITUDE_DIGITS 6
86 /** The number of bits for the speed field */
87 #define PUD_SPEED_BITS 12
89 /** The maximum speed value */
90 #define PUD_SPEED_MAX ((1 << PUD_SPEED_BITS) - 1)
92 /** The maximum size of the string representation of the speed */
93 #define PUD_TX_SPEED_DIGITS 4
99 /** The number of bits for the track angle field */
100 #define PUD_TRACK_BITS 9
102 /** The maximum size of the string representation of the track angle */
103 #define PUD_TX_TRACK_DIGITS 3
109 /** The number of bits for the HDOP field */
110 #define PUD_HDOP_BITS 11
112 /** The HDOP resolution (in m) */
113 #define PUD_HDOP_RESOLUTION (0.1)
115 /** The maximum HDOP value (in m) */
116 #define PUD_HDOP_MAX (((1 << PUD_HDOP_BITS) - 1) * PUD_HDOP_RESOLUTION)
118 /** The maximum size of the string representation of the HDOP */
119 #define PUD_TX_HDOP_DIGITS 5
121 /** The number of decimals of the HDOP in the transmit sentence */
122 #define PUD_TX_HDOP_DECIMALS "3"
128 /** nodeIdType legal values */
129 typedef enum _NodeIdType {
130 /** the first id of the globally unique node type IDs */
131 PUD_NODEIDTYPE_GLOBAL_FIRST = 0,
133 /** MAC address, 48 bits, 6 bytes */
134 PUD_NODEIDTYPE_MAC = 0,
136 /** MSISDN number, 15 digits, 50 bits, 7 bytes */
137 PUD_NODEIDTYPE_MSISDN = 1,
139 /** TETRA number, 17 digits, 57 bits, 8 bytes */
140 PUD_NODEIDTYPE_TETRA = 2,
142 /** DNS name, variable length */
143 PUD_NODEIDTYPE_DNS = 3,
145 /** IPv4 address, 32 bits, 4 bytes */
146 PUD_NODEIDTYPE_IPV4 = 4,
149 PUD_NODEIDTYPE_GAP1 = 5,
151 /** IPv6 address, 128 bits, 16 bytes */
152 PUD_NODEIDTYPE_IPV6 = 6,
154 /** AIS MMSI number, 9 digits, 30 bits, 4 bytes */
155 PUD_NODEIDTYPE_MMSI = 7,
157 /** URN number, 24 bits, 3 bytes */
158 PUD_NODEIDTYPE_URN = 8,
160 /** the last id of the globally unique node type IDs */
161 PUD_NODEIDTYPE_GLOBAL_LAST = PUD_NODEIDTYPE_URN,
163 /** the first id of the locally unique node type IDs */
164 PUD_NODEIDTYPE_LOCAL_FIRST = 192,
166 /** Brandweer number, 7 digits, 24 bits, 3 bytes */
167 PUD_NODEIDTYPE_192 = 192,
169 /** Ambulance number, 6 digits, 20 bits, 3 bytes */
170 PUD_NODEIDTYPE_193 = 193,
172 /** Number in the range [1, 8191], 4 digits, 13 bits, 2 bytes */
173 PUD_NODEIDTYPE_194 = 194,
175 /** the last id of the locally unique node type IDs */
176 PUD_NODEIDTYPE_LOCAL_LAST = PUD_NODEIDTYPE_194
179 /** the number of nodeId bytes for PUD_NODEIDTYPE_MAC (IFHWADDRLEN) */
180 #define PUD_NODEIDTYPE_MAC_BYTES 6
182 /** the number of nodeId bytes for PUD_NODEIDTYPE_MSISDN */
183 #define PUD_NODEIDTYPE_MSISDN_BYTES 7
185 /** the number of nodeId bytes for PUD_NODEIDTYPE_TETRA */
186 #define PUD_NODEIDTYPE_TETRA_BYTES 8
188 /** the number of nodeId bytes for PUD_NODEIDTYPE_MMSI */
189 #define PUD_NODEIDTYPE_MMSI_BYTES 4
191 /** the number of nodeId bytes for PUD_NODEIDTYPE_URN */
192 #define PUD_NODEIDTYPE_URN_BYTES 3
194 /** the number of nodeId bytes for PUD_NODEIDTYPE_192 */
195 #define PUD_NODEIDTYPE_192_BYTES 3
197 /** the number of nodeId bytes for PUD_NODEIDTYPE_193 */
198 #define PUD_NODEIDTYPE_193_BYTES 3
200 /** the number of nodeId bytes for PUD_NODEIDTYPE_194 */
201 #define PUD_NODEIDTYPE_194_BYTES 2
203 /** the number of nodeId bytes for PUD_NODEIDTYPE_IPV4 (sizeof(struct in_addr)) */
204 #define PUD_NODEIDTYPE_IPV4_BYTES 4
206 /** the number of nodeId bytes for PUD_NODEIDTYPE_IPV6 (sizeof(struct in6_addr)) */
207 #define PUD_NODEIDTYPE_IPV6_BYTES 16
209 /** The maximum size of the string representation of the nodeIdType */
210 #define PUD_TX_NODEIDTYPE_DIGITS 3
216 /** The maximum size of the string representation of the nodeId */
217 #define PUD_TX_NODEID_BUFFERSIZE 1023
220 * Wire Format Structures
223 /** Sub-format GPS information, 120 bits = 15 bytes */
224 typedef struct _GpsInfo {
225 uint32_t time :PUD_TIME_BITS; /**< the number of seconds since midnight, ALWAYS present */
226 uint32_t lat :PUD_LATITUDE_BITS; /**< latitude */
227 uint32_t lon :PUD_LONGITUDE_BITS; /**< longitude */
228 uint32_t alt :PUD_ALTITUDE_BITS; /**< altitude */
229 uint32_t speed :PUD_SPEED_BITS; /**< speed */
230 uint32_t track :PUD_TRACK_BITS; /**< track angle */
231 uint32_t hdop :PUD_HDOP_BITS; /**< HDOP */
232 }__attribute__((__packed__)) GpsInfo;
234 /** Sub-format Node information, 8 + variable bits = 1 + variable bytes */
235 typedef struct _NodeInfo {
236 uint8_t nodeIdType; /**< the nodeIdType */
237 unsigned char nodeId; /**< placeholder for variable length nodeId string */
238 }__attribute__((__packed__)) NodeInfo;
240 /** Complete format, 8+8+8+120+(8+variable) bits = 18+(1+variable) bytes*/
241 typedef struct _PudOlsrPositionUpdate {
242 uint8_t version; /**< the version of the sentence */
243 uint8_t validityTime; /**< the validity time of the sentence */
244 uint8_t smask; /**< mask signaling the contents of the sentence */
245 uint8_t flags; /**< mask signaling extra contents of the sentence */
246 GpsInfo gpsInfo; /**< the GPS information (MANDATORY) */
247 NodeInfo nodeInfo; /**< placeholder for node information (OPTIONAL) */
248 }__attribute__((__packed__)) PudOlsrPositionUpdate;
250 /** The size of the wire format, minus the size of the node information */
251 #define PUD_OLSRWIREFORMATSIZE (sizeof(PudOlsrPositionUpdate) - sizeof(NodeInfo))
257 /** the types of the uplink messages */
258 typedef enum _UplinkMessageType {
263 /** cluster leader message, 10 bytes (IPv4), 34 bytes (IPv6) */
264 typedef struct _UplinkClusterLeader {
265 uint8_t version; /**< the version of the message */
266 uint8_t validityTime; /**< the validity time of the sentence */
269 struct in_addr originator;
270 struct in_addr clusterLeader;
273 struct in6_addr originator;
274 struct in6_addr clusterLeader;
277 }__attribute__((__packed__)) UplinkClusterLeader;
279 /** TLV header for uplink messages, 4 bytes */
280 typedef struct _UplinkHeader {
281 uint8_t type; /**< stores a UplinkMessageType */
282 uint16_t length; /**< the length of the payload in txBuffer */
283 uint8_t ipv6 :1; /**< clear when IPv4, set when IPv6 */
284 uint8_t pad :7; /**< padding to align to 4 bytes */
285 }__attribute__((__packed__)) UplinkHeader;
287 /** uplink message */
288 typedef struct _UplinkMessage {
289 UplinkHeader header; /**< the uplink TLV header */
291 /** an olsr message (position update) */
292 union olsr_message olsrMessage;
294 /** a cluster leader message */
295 UplinkClusterLeader clusterLeader;
297 }__attribute__((__packed__)) UplinkMessage;
299 /* ************************************************************************
301 * ************************************************************************ */
307 static inline bool isValidNodeIdType(unsigned long long nodeIdType) {
311 (/* (nodeIdType >= PUD_NODEIDTYPE_GLOBAL_FIRST) && */ (nodeIdType <= PUD_NODEIDTYPE_GLOBAL_LAST)) ||
312 ( (nodeIdType >= PUD_NODEIDTYPE_LOCAL_FIRST ) && (nodeIdType <= PUD_NODEIDTYPE_LOCAL_LAST ))
316 (nodeIdType != PUD_NODEIDTYPE_GAP1)
325 /** Determine the validity time in seconds from the OLSR wire format value */
326 #define PUD_VALIDITY_TIME_FROM_OLSR(msn, lsn) ((((lsn) + 16) * (1 << (msn))) - 16)
329 Get the validity time from a message
331 @param validityTimeField
332 A pointer to the validity time field
335 The validity time in seconds
337 static inline unsigned long getValidityTime(uint8_t * validityTimeField) {
338 return PUD_VALIDITY_TIME_FROM_OLSR(*validityTimeField >> 4, *validityTimeField % 16);
341 void setValidityTime(uint8_t * validityTimeField,
342 unsigned long long validityTime);
349 Get the type of the uplink message
352 A pointer to the uplink message
354 The type of the uplink message
356 static inline uint8_t getUplinkMessageType(UplinkHeader * uplinkHeader) {
357 return uplinkHeader->type;
361 Set the type of the uplink message
364 A pointer to the uplink message
366 The type of the uplink message
368 static inline void setUplinkMessageType(UplinkHeader * uplinkHeader,
370 uplinkHeader->type = type;
374 Get the length of the uplink message
377 A pointer to the uplink message
379 The length of the uplink message
381 static inline uint16_t getUplinkMessageLength(UplinkHeader * uplinkHeader) {
382 return ntohs(uplinkHeader->length);
386 Set the length of the uplink message
389 A pointer to the uplink message
391 The length of the uplink message
393 static inline void setUplinkMessageLength(UplinkHeader * uplinkHeader,
395 uplinkHeader->length = ntohs(length);
399 Get the IPv6 status of the uplink message
402 A pointer to the uplink message
404 true when the uplink message is sent from an olsrd stack in IPv6 mode, false
407 static inline bool getUplinkMessageIPv6(UplinkHeader * uplinkHeader) {
408 return (uplinkHeader->ipv6 == 1);
412 Set the IPv6 status of the uplink message
415 A pointer to the uplink message
417 The IPv6 status of the uplink message (true when the uplink message is sent
418 from olsrd stack in IPv6 mode, false otherwise)
420 static inline void setUplinkMessageIPv6(UplinkHeader * uplinkHeader,
422 uplinkHeader->ipv6 = ipv6 ? 1 : 0;
426 Set the padding of the uplink message header
429 A pointer to the uplink message
431 The padding of the uplink message header
433 static inline void setUplinkMessagePadding(UplinkHeader * uplinkHeader,
435 uplinkHeader->pad = pad;
444 Determine the size of an OLSR message
449 A pointer to the OLSR message
451 The size of the OLSR message
453 static inline unsigned short getOlsrMessageSize(int ipVersion,
454 union olsr_message * olsrMessage) {
455 if (ipVersion == AF_INET) {
456 return ntohs(olsrMessage->v4.olsr_msgsize);
459 return ntohs(olsrMessage->v6.olsr_msgsize);
463 Get the originator of an OLSR message
466 The IP version (AF_INET or AF_INET6)
468 A pointer to the OLSR message
470 A pointer to the originator address
472 static inline union olsr_ip_addr * getOlsrMessageOriginator(int ipVersion,
473 union olsr_message * olsrMessage) {
474 if (ipVersion == AF_INET) {
475 return (union olsr_ip_addr *) &olsrMessage->v4.originator;
478 return (union olsr_ip_addr *) &olsrMessage->v6.originator;
482 Get the position update message in an OLSR message
485 The IP version (AF_INET or AF_INET6)
487 A pointer to the OLSR message
489 A pointer to the position update message
491 static inline PudOlsrPositionUpdate * getOlsrMessagePayload(int ipVersion,
492 union olsr_message * olsrMessage) {
493 if (ipVersion == AF_INET) {
494 return (PudOlsrPositionUpdate *) &olsrMessage->v4.message;
497 return (PudOlsrPositionUpdate *) &olsrMessage->v6.message;
501 * PudOlsrPositionUpdate
505 Get the version of the position update message
507 @param olsrGpsMessage
508 A pointer to the position update message
510 The version of the position update message
512 static inline uint8_t getPositionUpdateVersion(
513 PudOlsrPositionUpdate * olsrGpsMessage) {
514 return olsrGpsMessage->version;
518 Set the version of the position update message
520 @param olsrGpsMessage
521 A pointer to the position update message
523 The version of the position update message
525 static inline void setPositionUpdateVersion(
526 PudOlsrPositionUpdate * olsrGpsMessage, uint8_t version) {
527 olsrGpsMessage->version = version;
531 Get the smask of the position update message
533 @param olsrGpsMessage
534 A pointer to the position update message
536 The smask of the position update message
538 static inline uint8_t getPositionUpdateSmask(
539 PudOlsrPositionUpdate * olsrGpsMessage) {
540 return olsrGpsMessage->smask;
544 Set the smask of the position update message
546 @param olsrGpsMessage
547 A pointer to the position update message
549 The smask of the position update message
551 static inline void setPositionUpdateSmask(
552 PudOlsrPositionUpdate * olsrGpsMessage, uint8_t smask) {
553 olsrGpsMessage->smask = smask;
557 Get the flags of the position update message
559 @param olsrGpsMessage
560 A pointer to the position update message
562 The flags of the position update message
564 static inline uint8_t getPositionUpdateFlags(
565 PudOlsrPositionUpdate * olsrGpsMessage) {
566 return olsrGpsMessage->flags;
570 Set the flags of the position update message
572 @param olsrGpsMessage
573 A pointer to the position update message
575 The flags of the position update message
577 static inline void setPositionUpdateFlags(
578 PudOlsrPositionUpdate * olsrGpsMessage, uint8_t flags) {
579 olsrGpsMessage->flags = flags;
586 void getPositionUpdateTime(PudOlsrPositionUpdate * olsrGpsMessage,
587 time_t baseDate, struct tm *nowStruct);
590 Set the time of the position update message (the number of seconds after
593 @param olsrGpsMessage
594 A pointer to the position update message
602 static inline void setPositionUpdateTime(PudOlsrPositionUpdate * olsrGpsMessage,
603 int hour, int min, int sec) {
604 olsrGpsMessage->gpsInfo.time = ((hour * 60 * 60) + (min * 60) + sec);
608 Get the latitude of the position update message
610 @param olsrGpsMessage
611 A pointer to the position update message
614 The latitude converted to degrees: [-90, 90>
616 static inline double getPositionUpdateLatitude(
617 PudOlsrPositionUpdate * olsrGpsMessage) {
618 uint32_t olsrLat = olsrGpsMessage->gpsInfo.lat;
619 double lat = (double) olsrLat;
621 /* lat is in [0, 2^LATITUDE_BITS> */
623 /* take half of the rounding error */
626 lat /= (double) (1 << PUD_LATITUDE_BITS);
627 /* lat is now in [0, 1> */
630 /* lat is now in [-0.5, 0.5> */
633 /* lat is now in [-90, 90> */
639 Set the latitude of the position update message
641 @param olsrGpsMessage
642 A pointer to the position update message
644 The latitude in degrees: [-90, 90]
646 static inline void setPositionUpdateLatitude(
647 PudOlsrPositionUpdate * olsrGpsMessage, double latitude) {
648 double lat = latitude;
650 /* lat is in [-90, 90] */
651 assert(lat >= -90.0);
655 /* lat is now in [-0.5, 0.5] */
658 /* lat is now in [0, 1] */
660 lat *= (double) (1 << PUD_LATITUDE_BITS);
661 /* lat is now in [0, LATITUDE_BITS] */
664 if (unlikely(lat > (double)((1 << PUD_LATITUDE_BITS) - 1))) {
665 lat = (double) ((1 << PUD_LATITUDE_BITS) - 1);
667 /* lat is now in [0, 2^LATITUDE_BITS> */
669 olsrGpsMessage->gpsInfo.lat = lrint(lat);
673 Get the longitude of the position update message
675 @param olsrGpsMessage
676 A pointer to the position update message
679 The longitude converted to degrees: [-180, 180>
681 static inline double getPositionUpdateLongitude(
682 PudOlsrPositionUpdate * olsrGpsMessage) {
683 uint32_t olsrLon = olsrGpsMessage->gpsInfo.lon;
684 double lon = (double) olsrLon;
686 /* lon is in [0, 2^LONGITUDE_BITS> */
688 /* take half of the rounding error */
691 lon /= (1 << PUD_LONGITUDE_BITS);
692 /* lon is now in [0, 1> */
695 /* lon is now in [-0.5, 0.5> */
698 /* lon is now in [-180, 180> */
704 Set the longitude of the position update message
706 @param olsrGpsMessage
707 A pointer to the position update message
709 The longitude in degrees: [-90, 90]
711 static inline void setPositionUpdateLongitude(
712 PudOlsrPositionUpdate * olsrGpsMessage, double longitude) {
713 double lon = longitude;
715 /* lon is in [-180, 180] */
716 assert(lon >= -180.0);
717 assert(lon <= 180.0);
720 /* lon is now in [-0.5, 0.5] */
723 /* lon is now in [0, 1] */
725 lon *= (double) (1 << PUD_LONGITUDE_BITS);
726 /* lon is now in [0, LONGITUDE_BITS] */
729 if (unlikely(lon > (double)((1 << PUD_LATITUDE_BITS) - 1))) {
730 lon = (double) ((1 << PUD_LATITUDE_BITS) - 1);
733 /* lon is now in [0, 2^LONGITUDE_BITS> */
735 olsrGpsMessage->gpsInfo.lon = lrint(lon);
739 Get the altitude of the position update message
741 @param olsrGpsMessage
742 A pointer to the position update message
745 The altitude in meters
747 static inline long getPositionUpdateAltitude(
748 PudOlsrPositionUpdate * olsrGpsMessage) {
749 return ((long) olsrGpsMessage->gpsInfo.alt + PUD_ALTITUDE_MIN);
753 Set the altitude of the position update message
755 @param olsrGpsMessage
756 A pointer to the position update message
758 The altitude in meters
760 static inline void setPositionUpdateAltitude(
761 PudOlsrPositionUpdate * olsrGpsMessage, double altitude) {
762 double alt = altitude;
764 if (unlikely(alt > PUD_ALTITUDE_MAX)) {
765 alt = PUD_ALTITUDE_MAX;
766 } else if (unlikely(alt < PUD_ALTITUDE_MIN)) {
767 alt = PUD_ALTITUDE_MIN;
770 alt -= PUD_ALTITUDE_MIN;
772 olsrGpsMessage->gpsInfo.alt = lrint(alt);
776 Get the speed of the position update message
778 @param olsrGpsMessage
779 A pointer to the position update message
784 static inline unsigned long getPositionUpdateSpeed(
785 PudOlsrPositionUpdate * olsrGpsMessage) {
786 return olsrGpsMessage->gpsInfo.speed;
790 Set the speed of the position update message
792 @param olsrGpsMessage
793 A pointer to the position update message
797 static inline void setPositionUpdateSpeed(
798 PudOlsrPositionUpdate * olsrGpsMessage, double speed) {
801 if (unlikely(speed < 0)) {
803 } else if (unlikely(speed > PUD_SPEED_MAX)) {
807 olsrGpsMessage->gpsInfo.speed = lrint(spd);
811 Get the track angle of the position update message
813 @param olsrGpsMessage
814 A pointer to the position update message
817 The track angle in degrees
819 static inline unsigned long getPositionUpdateTrack(
820 PudOlsrPositionUpdate * olsrGpsMessage) {
821 return olsrGpsMessage->gpsInfo.track;
825 Set the track angle of the position update message
827 @param olsrGpsMessage
828 A pointer to the position update message
830 The track angle in degrees
832 static inline void setPositionUpdateTrack(
833 PudOlsrPositionUpdate * olsrGpsMessage, double track) {
834 olsrGpsMessage->gpsInfo.track = lrint(track);
838 Get the HDOP of the position update message
840 @param olsrGpsMessage
841 A pointer to the position update message
846 static inline double getPositionUpdateHdop(
847 PudOlsrPositionUpdate * olsrGpsMessage) {
848 return (olsrGpsMessage->gpsInfo.hdop * PUD_HDOP_RESOLUTION);
852 Set the HDOP of the position update message
854 @param olsrGpsMessage
855 A pointer to the position update message
859 static inline void setPositionUpdateHdop(PudOlsrPositionUpdate * olsrGpsMessage,
861 double hdopInternal = hdop;
863 if (unlikely(hdopInternal > PUD_HDOP_MAX)) {
864 hdopInternal = PUD_HDOP_MAX;
867 olsrGpsMessage->gpsInfo.hdop = lrint(hdopInternal / PUD_HDOP_RESOLUTION);
874 bool setupNodeIdNumberForOlsrCache(/*const char * nodeIdParameterName,*/
875 unsigned long long val, unsigned long long min, unsigned long long max,
877 bool setupNodeIdBinaryBufferForOlsrCache(void * val, size_t bytes);
880 Get the nodeIdType of the position update message
883 The IP version (AF_INET or AF_INET6)
884 @param olsrGpsMessage
885 A pointer to the position update message
890 static inline NodeIdType getPositionUpdateNodeIdType(int ipVersion,
891 PudOlsrPositionUpdate * olsrGpsMessage) {
892 if (getPositionUpdateFlags(olsrGpsMessage) & PUD_FLAGS_ID) {
893 return olsrGpsMessage->nodeInfo.nodeIdType;
896 return ((ipVersion == AF_INET) ? PUD_NODEIDTYPE_IPV4 : PUD_NODEIDTYPE_IPV6);
900 Set the nodeIdType of the position update message
902 @param olsrGpsMessage
903 A pointer to the position update message
907 static inline void setPositionUpdateNodeIdType(
908 PudOlsrPositionUpdate * olsrGpsMessage, NodeIdType nodeIdType) {
909 olsrGpsMessage->nodeInfo.nodeIdType = nodeIdType;
912 void getPositionUpdateNodeId(int ipVersion, union olsr_message * olsrMessage,
913 unsigned char ** nodeId, unsigned int * nodeIdSize);
916 Set the nodeId of the position update message
918 @param olsrGpsMessage
919 A pointer to the position update message
923 The number of bytes in nodeId
924 @param padWithNullByte
925 When true then an extra '\0' byte will be added at the end
927 static inline void setPositionUpdateNodeId(
928 PudOlsrPositionUpdate * olsrGpsMessage, unsigned char * nodeId,
929 unsigned int nodeIdSize, bool padWithNullByte) {
930 memcpy(&olsrGpsMessage->nodeInfo.nodeId, nodeId, nodeIdSize);
931 if (unlikely(padWithNullByte)) {
932 (&olsrGpsMessage->nodeInfo.nodeId)[nodeIdSize] = '\0';
936 size_t setPositionUpdateNodeInfo(int ipVersion,
937 PudOlsrPositionUpdate * olsrGpsMessage, unsigned int olsrMessageSize,
938 NodeIdType nodeIdType, unsigned char * nodeId, size_t nodeIdLength);
941 * UplinkClusterLeader
945 Get the version of the cluster leader message
947 @param clusterLeaderMessage
948 A pointer to the cluster leader message
950 The version of the cluster leader message
952 static inline uint8_t getClusterLeaderVersion(
953 UplinkClusterLeader * clusterLeaderMessage) {
954 return clusterLeaderMessage->version;
958 Set the version of the cluster leader message
960 @param clusterLeaderMessage
961 A pointer to the cluster leader message
963 The version of the cluster leader message
965 static inline void setClusterLeaderVersion(
966 UplinkClusterLeader * clusterLeaderMessage, uint8_t version) {
967 clusterLeaderMessage->version = version;
971 Get the originator of a cluster leader message
974 The IP version (AF_INET or AF_INET6)
975 @param clusterLeaderMessage
976 A pointer to the cluster leader message
978 A pointer to the originator address
980 static inline union olsr_ip_addr * getClusterLeaderOriginator(int ipVersion,
981 UplinkClusterLeader * clusterLeaderMessage) {
982 if (ipVersion == AF_INET) {
983 return (union olsr_ip_addr *) &clusterLeaderMessage->leader.v4.originator;
986 return (union olsr_ip_addr *) &clusterLeaderMessage->leader.v6.originator;
990 Get the cluster leader of a cluster leader message
993 The IP version (AF_INET or AF_INET6)
994 @param clusterLeaderMessage
995 A pointer to the cluster leader message
997 A pointer to the clust leader address
999 static inline union olsr_ip_addr * getClusterLeaderClusterLeader(int ipVersion,
1000 UplinkClusterLeader * clusterLeaderMessage) {
1001 if (ipVersion == AF_INET) {
1002 return (union olsr_ip_addr *) &clusterLeaderMessage->leader.v4.clusterLeader;
1005 return (union olsr_ip_addr *) &clusterLeaderMessage->leader.v6.clusterLeader;
1008 #endif /* _PUD_WIREFORMAT_H_ */