|
|
@@ -5,6 +5,19 @@ static const size_t MAC_LEN = 8; |
|
|
|
static const size_t CHALLENGE_LEN = 16; |
|
|
|
static const uint8_t domain[] = "com.funkthat.lora.irrigation.shared.v0.0.1"; |
|
|
|
|
|
|
|
static int comms_pktbuf_equal(struct pktbuf a, struct pktbuf b); |
|
|
|
|
|
|
|
/* returns 1 if equal, 0 if not equal */ |
|
|
|
static int |
|
|
|
comms_pktbuf_equal(struct pktbuf a, struct pktbuf b) |
|
|
|
{ |
|
|
|
|
|
|
|
if (a.pktlen != b.pktlen) |
|
|
|
return 0; |
|
|
|
|
|
|
|
return memcmp(a.pkt, b.pkt, a.pktlen) == 0; |
|
|
|
} |
|
|
|
|
|
|
|
size_t |
|
|
|
_strobe_state_size() |
|
|
|
{ |
|
|
@@ -48,6 +61,14 @@ comms_process(struct comms_state *cs, struct pktbuf pbin, struct pktbuf *pbout) |
|
|
|
struct pktbuf pbmsg, pbrep; |
|
|
|
ssize_t cnt, ret, msglen; |
|
|
|
|
|
|
|
/* if the current msg matches the previous */ |
|
|
|
if (comms_pktbuf_equal(pbin, cs->cs_prevmsg)) { |
|
|
|
/* send the previous response */ |
|
|
|
pbout->pktlen = cs->cs_prevmsgresp.pktlen; |
|
|
|
memcpy(pbout->pkt, cs->cs_prevmsgresp.pkt, pbout->pktlen); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
strobe_attach_buffer(&cs->cs_state, pbin.pkt, pbin.pktlen); |
|
|
|
|
|
|
|
cnt = strobe_get(&cs->cs_state, APP_CIPHERTEXT, buf, pbin.pktlen - |
|
|
@@ -108,8 +129,23 @@ comms_process(struct comms_state *cs, struct pktbuf pbin, struct pktbuf *pbout) |
|
|
|
ret += strobe_put(&cs->cs_state, MAC, NULL, MAC_LEN); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* set the output buffer length */ |
|
|
|
pbout->pktlen = ret; |
|
|
|
|
|
|
|
if (ret != 0) { |
|
|
|
/* we accepted a new message store it */ |
|
|
|
|
|
|
|
/* store the req */ |
|
|
|
cs->cs_prevmsg.pkt = cs->cs_prevmsgbuf; |
|
|
|
cs->cs_prevmsg.pktlen = pbin.pktlen; |
|
|
|
memcpy(cs->cs_prevmsg.pkt, pbin.pkt, pbin.pktlen); |
|
|
|
|
|
|
|
/* store the response */ |
|
|
|
cs->cs_prevmsgresp.pkt = cs->cs_prevmsgrespbuf; |
|
|
|
cs->cs_prevmsgresp.pktlen = pbout->pktlen; |
|
|
|
memcpy(cs->cs_prevmsgresp.pkt, pbout->pkt, pbout->pktlen); |
|
|
|
} |
|
|
|
} |