1 /*
2 Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
3 file at the top-level directory of this distribution.
4
5 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 option. This file may not be copied, modified, or distributed
9 except according to those terms.
10 */
11
12 #include <edhoc.h>
13 #include <stdbool.h>
14 #include <string.h>
15 #include "edhoc_tests.h"
16 bool rx_initiator_switch = false;
17
18 static uint8_t msg_cnt;
19
rx_init(void)20 void rx_init(void)
21 {
22 msg_cnt = 1;
23 }
24
rx(void * sock,uint8_t * data,uint32_t * data_len)25 enum err rx(void *sock, uint8_t *data, uint32_t *data_len)
26 {
27 if (rx_initiator_switch) {
28 PRINTF("TXRX wrapper test vectors\n");
29 /*The initiator must get msg2 and msg4*/
30 if (msg_cnt == 1) {
31 /*message 2*/
32 TRY(_memcpy_s(data, *data_len, m.m2, m.m2_len));
33 *data_len = m.m2_len;
34 msg_cnt++;
35 } else {
36 /*message 4*/
37 TRY(_memcpy_s(data, *data_len, m.m4, m.m4_len));
38 *data_len = m.m4_len;
39 msg_cnt = 1;
40 }
41 } else {
42 PRINTF("TXRX wrapper test vectors\n");
43
44 /*The responder must get msg1 and msg3*/
45 if (msg_cnt == 1) {
46 /*message 1 */
47 TRY(_memcpy_s(data, *data_len, m.m1, m.m1_len));
48 *data_len = m.m1_len;
49 msg_cnt++;
50 } else {
51 /*message 3*/
52 TRY(_memcpy_s(data, *data_len, m.m3, m.m3_len));
53 *data_len = m.m3_len;
54 msg_cnt = 1;
55 }
56 }
57 return ok;
58 }
59
tx(void * sock,uint8_t * data,uint32_t data_len)60 enum err tx(void *sock, uint8_t *data, uint32_t data_len)
61 { //todo add here a test
62 return ok;
63 }
64