summaryrefslogtreecommitdiffstats
path: root/src/handshake.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-03-30 04:36:50 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-03-30 04:36:50 +0200
commit6f1f926bb82b7a4bb1fd3cfc981c7596843a9a6e (patch)
tree19d3345932e1328981eea1d5c25d041fc0f5e0e0 /src/handshake.h
parentca127fccb899627e9e9a69d139bd27d79b30cd54 (diff)
downloadfastd-6f1f926bb82b7a4bb1fd3cfc981c7596843a9a6e.tar
fastd-6f1f926bb82b7a4bb1fd3cfc981c7596843a9a6e.zip
Make ecfxp protocol work with new handshake
Diffstat (limited to 'src/handshake.h')
-rw-r--r--src/handshake.h34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/handshake.h b/src/handshake.h
index 064e167..c59d141 100644
--- a/src/handshake.h
+++ b/src/handshake.h
@@ -28,7 +28,6 @@
#define _FASTD_HANDSHAKE_H_
#include "fastd.h"
-#include "packet.h"
typedef enum _fastd_handshake_record_type {
@@ -38,6 +37,11 @@ typedef enum _fastd_handshake_record_type {
RECORD_FLAGS,
RECORD_MODE,
RECORD_PROTOCOL_NAME,
+ RECORD_PROTOCOL1,
+ RECORD_PROTOCOL2,
+ RECORD_PROTOCOL3,
+ RECORD_PROTOCOL4,
+ RECORD_PROTOCOL5,
RECORD_MAX,
} fastd_handshake_record_type;
@@ -56,6 +60,7 @@ typedef struct _fastd_handshake_record {
struct _fastd_handshake {
uint8_t req_id;
+ uint8_t type;
fastd_handshake_record records[RECORD_MAX];
};
@@ -66,4 +71,31 @@ fastd_buffer fastd_handshake_new_reply(fastd_context *ctx, fastd_peer *peer, con
void fastd_handshake_handle(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer);
+static inline void fastd_handshake_add(fastd_context *ctx, fastd_buffer *buffer, fastd_handshake_record_type type, size_t len, const void *data) {
+ if ((uint8_t*)buffer->data + buffer->len + 2 + len > (uint8_t*)buffer->base + buffer->base_len)
+ exit_bug(ctx, "not enough buffer allocated for handshake");
+
+ uint8_t *dst = (uint8_t*)buffer->data + buffer->len;
+
+ dst[0] = type;
+ dst[1] = len;
+ memcpy(dst+2, data, len);
+
+ buffer->len += 2 + len;
+}
+
+static inline void fastd_handshake_add_uint8(fastd_context *ctx, fastd_buffer *buffer, fastd_handshake_record_type type, uint8_t value) {
+ if ((uint8_t*)buffer->data + buffer->len + 3 > (uint8_t*)buffer->base + buffer->base_len)
+ exit_bug(ctx, "not enough buffer allocated for handshake");
+
+ uint8_t *dst = (uint8_t*)buffer->data + buffer->len;
+
+ dst[0] = type;
+ dst[1] = 1;
+ dst[2] = value;
+
+ buffer->len += 3;
+}
+
+
#endif /* _FASTD_HANDSHAKE_H_ */