summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/enroll.proto14
-rw-r--r--src/lib/protobuf.c81
-rw-r--r--src/lib/serdes-oep.c37
3 files changed, 94 insertions, 38 deletions
diff --git a/src/lib/enroll.proto b/src/lib/enroll.proto
index 34ca1847..3b22ac17 100644
--- a/src/lib/enroll.proto
+++ b/src/lib/enroll.proto
@@ -25,16 +25,18 @@ import "ipcp_config.proto";
message enroll_req_msg {
/* TODO authentication */
- required uint32 magic = 1;
+ required bytes id = 1;
}
message enroll_resp_msg {
- required int64 t_sec = 1;
- required int32 t_nsec = 2;
- required int32 response = 3;
- optional ipcp_config_msg conf = 4;
+ required bytes id = 1;
+ required int64 t_sec = 2;
+ required int32 t_nsec = 3;
+ required int32 response = 4;
+ optional ipcp_config_msg conf = 5;
}
message enroll_ack_msg {
- required int32 response = 1;
+ required bytes id = 1;
+ required int32 result = 2;
}
diff --git a/src/lib/protobuf.c b/src/lib/protobuf.c
index 830efd40..937e4efc 100644
--- a/src/lib/protobuf.c
+++ b/src/lib/protobuf.c
@@ -343,62 +343,86 @@ struct qos_spec qos_spec_msg_to_s(const qosspec_msg_t * msg)
return s;
}
-enroll_req_msg_t * enroll_req_s_to_msg(void)
+enroll_req_msg_t * enroll_req_s_to_msg(const struct enroll_req * s)
{
enroll_req_msg_t * msg;
+ uint8_t * id;
msg = malloc(sizeof(*msg));
if (msg == NULL)
- return NULL;
+ goto fail_msg;
+
+ id = malloc(ENROLL_ID_LEN);
+ if (id == NULL)
+ goto fail_id;
+
+ memcpy(id, s->id, ENROLL_ID_LEN);
enroll_req_msg__init(msg);
- msg->magic = 0xC0FFEE;
+ msg->id.len = ENROLL_ID_LEN;
+ msg->id.data = id;
return msg;
+
+ fail_id:
+ free(msg);
+ fail_msg:
+ return NULL;
}
-int enroll_req_msg_to_s(const enroll_req_msg_t * msg)
+struct enroll_req enroll_req_msg_to_s(const enroll_req_msg_t * msg)
{
- (void) msg;
+ struct enroll_req s;
assert(msg != NULL);
- return 0;
+ memcpy(s.id, msg->id.data, ENROLL_ID_LEN);
+
+ return s;
}
enroll_resp_msg_t * enroll_resp_s_to_msg(const struct enroll_resp * s)
{
enroll_resp_msg_t * msg;
+ uint8_t * id;
assert(s != NULL);
msg = malloc(sizeof(*msg));
if (msg == NULL)
- goto fail_malloc;
+ goto fail_msg;
+
+ id = malloc(ENROLL_ID_LEN);
+ if (id == NULL)
+ goto fail_id;
+
+ memcpy(id, s->id, ENROLL_ID_LEN);
enroll_resp_msg__init(msg);
+ msg->id.len = ENROLL_ID_LEN;
+ msg->id.data = id;
+
msg->t_sec = s->t.tv_sec;
msg->t_nsec = s->t.tv_nsec;
msg->response = s->response;
-
if (msg->response < 0)
return msg;
msg->conf = ipcp_config_s_to_msg(&s->conf);
if (msg->conf == NULL)
- goto fail_conf;
+ goto fail_id;
return msg;
- fail_conf:
+ fail_id:
enroll_resp_msg__free_unpacked(msg, NULL);
- fail_malloc:
+ fail_msg:
return NULL;
}
-struct enroll_resp enroll_resp_msg_to_s(enroll_resp_msg_t * msg)
+struct enroll_resp enroll_resp_msg_to_s(const enroll_resp_msg_t * msg)
{
struct enroll_resp s;
@@ -411,27 +435,50 @@ struct enroll_resp enroll_resp_msg_to_s(enroll_resp_msg_t * msg)
s.t.tv_sec = msg->t_sec;
s.t.tv_nsec = msg->t_nsec;
+ memcpy(s.id, msg->id.data, ENROLL_ID_LEN);
+
return s;
}
-enroll_ack_msg_t * enroll_ack_s_to_msg(int response)
+enroll_ack_msg_t * enroll_ack_s_to_msg(const struct enroll_ack * s)
{
enroll_ack_msg_t * msg;
+ uint8_t * id;
msg = malloc(sizeof(*msg));
if (msg == NULL)
- return NULL;
+ goto fail_msg;
+
+ id = malloc(ENROLL_ID_LEN);
+ if (id == NULL)
+ goto fail_id;
+
+ memcpy(id, s->id, ENROLL_ID_LEN);
enroll_ack_msg__init(msg);
- msg->response = response;
+ msg->id.len = ENROLL_ID_LEN;
+ msg->id.data = id;
+
+ msg->result = s->result;
return msg;
+
+ fail_id:
+ enroll_ack_msg__free_unpacked(msg, NULL);
+ fail_msg:
+ return NULL;
}
-int enroll_ack_msg_to_s(const enroll_ack_msg_t * msg)
+struct enroll_ack enroll_ack_msg_to_s(const enroll_ack_msg_t * msg)
{
+ struct enroll_ack s;
+
assert(msg != NULL);
- return msg->response;
+ memcpy(s.id, msg->id.data, ENROLL_ID_LEN);
+
+ s.result = msg->result;
+
+ return s;
}
diff --git a/src/lib/serdes-oep.c b/src/lib/serdes-oep.c
index cae5c598..f5034a4a 100644
--- a/src/lib/serdes-oep.c
+++ b/src/lib/serdes-oep.c
@@ -26,12 +26,13 @@
#include <ouroboros/serdes-oep.h>
-ssize_t enroll_req_ser(buffer_t buf)
+ssize_t enroll_req_ser(const struct enroll_req * req,
+ buffer_t buf)
{
enroll_req_msg_t * msg;
ssize_t sz;
- msg = enroll_req_s_to_msg();
+ msg = enroll_req_s_to_msg(req);
if (msg == NULL)
goto fail_msg;
@@ -46,24 +47,33 @@ ssize_t enroll_req_ser(buffer_t buf)
return sz;
fail_pack:
- enroll_req_msg__free_unpacked(msg, NULL);
+ enroll_req_msg__free_unpacked(msg, NULL);
fail_msg:
return -1;
}
-int enroll_req_des(const buffer_t buf)
+int enroll_req_des(struct enroll_req * req,
+ const buffer_t buf)
{
enroll_req_msg_t * msg;
msg = enroll_req_msg__unpack(NULL, buf.len, buf.data);
if (msg == NULL)
- return -1;
+ goto fail_unpack;
- /* Nothing in request yet, if it unpacks, it's good. */
+ if (msg->id.len != ENROLL_ID_LEN)
+ goto fail_id;
+
+ *req = enroll_req_msg_to_s(msg);
enroll_req_msg__free_unpacked(msg, NULL);
return 0;
+
+ fail_id:
+ enroll_req_msg__free_unpacked(msg, NULL);
+ fail_unpack:
+ return -1;
}
ssize_t enroll_resp_ser(const struct enroll_resp * resp,
@@ -80,9 +90,6 @@ ssize_t enroll_resp_ser(const struct enroll_resp * resp,
if (sz < 0 || (size_t) sz > buf.len)
goto fail_pack;
- msg->t_sec = resp->t.tv_sec;
- msg->t_nsec = resp->t.tv_nsec;
-
enroll_resp_msg__pack(msg, buf.data);
enroll_resp_msg__free_unpacked(msg, NULL);
@@ -111,13 +118,13 @@ int enroll_resp_des(struct enroll_resp * resp,
return 0;
}
-ssize_t enroll_ack_ser(const int response,
- buffer_t buf)
+ssize_t enroll_ack_ser(const struct enroll_ack * ack,
+ buffer_t buf)
{
enroll_ack_msg_t * msg;
ssize_t sz;
- msg = enroll_ack_s_to_msg(response);
+ msg = enroll_ack_s_to_msg(ack);
if (msg == NULL)
goto fail_msg;
@@ -138,8 +145,8 @@ ssize_t enroll_ack_ser(const int response,
}
-int enroll_ack_des(int * response,
- const buffer_t buf)
+int enroll_ack_des(struct enroll_ack * ack,
+ const buffer_t buf)
{
enroll_ack_msg_t * msg;
@@ -147,7 +154,7 @@ int enroll_ack_des(int * response,
if (msg == NULL)
return -1;
- *response = enroll_ack_msg_to_s(msg);
+ *ack = enroll_ack_msg_to_s(msg);
enroll_ack_msg__free_unpacked(msg, NULL);