summaryrefslogtreecommitdiffstats
path: root/src/handshake.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-20 17:51:20 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-20 17:51:20 +0200
commit6da79ddb9bfe5e9e6042e644ff00666912b644c3 (patch)
treed59e666a0c11fa7801674eba34f6f26afc06c5a8 /src/handshake.h
parent50390abdeea337b67402107e67bfdaff3bafaa59 (diff)
downloadfastd-6da79ddb9bfe5e9e6042e644ff00666912b644c3.tar
fastd-6da79ddb9bfe5e9e6042e644ff00666912b644c3.zip
Some handshake fixes for future protocol extensions
Extensions for arbitrary-length integers.
Diffstat (limited to 'src/handshake.h')
-rw-r--r--src/handshake.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/handshake.h b/src/handshake.h
index 2ea7166..a77b730 100644
--- a/src/handshake.h
+++ b/src/handshake.h
@@ -159,3 +159,34 @@ static inline void fastd_handshake_add_uint16(fastd_buffer_t *buffer, fastd_hand
dst[0] = value;
dst[1] = value >> 8;
}
+
+/** Adds an uint24 TLV record of given type and value to a handshake buffer */
+static inline void fastd_handshake_add_uint24(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) {
+ uint8_t *dst = fastd_handshake_extend(buffer, type, 3);
+
+ dst[0] = value;
+ dst[1] = value >> 8;
+ dst[2] = value >> 16;
+}
+
+/** Adds an uint32 TLV record of given type and value to a handshake buffer */
+static inline void fastd_handshake_add_uint32(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) {
+ uint8_t *dst = fastd_handshake_extend(buffer, type, 4);
+
+ dst[0] = value;
+ dst[1] = value >> 8;
+ dst[2] = value >> 16;
+ dst[3] = value >> 24;
+}
+
+/** Adds an TLV record of given type and value to a handshake buffer, automatically using a 1- to 4-byte value */
+static inline void fastd_handshake_add_uint(fastd_buffer_t *buffer, fastd_handshake_record_type_t type, uint32_t value) {
+ if (value > 0xffffff)
+ fastd_handshake_add_uint32(buffer, type, value);
+ if (value > 0xffff)
+ fastd_handshake_add_uint24(buffer, type, value);
+ if (value > 0xff)
+ fastd_handshake_add_uint16(buffer, type, value);
+ else
+ fastd_handshake_add_uint8(buffer, type, value);
+}