Skip to content

Commit 51990bf

Browse files
TejasvOnlyvrockz747ParnikaGupta9
committed
feat: Add session apis in core
Co-authored-by: Vaibhav Sethia <vrockz747@gmail.com> Co-authored-by: Parnika Gupta <parnika@cypherock.com>
1 parent 8493eb9 commit 51990bf

File tree

12 files changed

+997
-17
lines changed

12 files changed

+997
-17
lines changed

apps/manager_app/device_authentication_api.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
#include "atca_basic.h"
7171
#include "device_authentication_api.h"
7272

73-
#define SIGNATURE_SIZE 64
74-
#define POSTFIX1_SIZE 7
75-
#define POSTFIX2_SIZE 23
7673
#define RANDOM_CHALLENGE_SIZE 32
7774

7875
atecc_data_t atecc_data = {0};

apps/manager_app/device_authentication_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* MACROS AND DEFINES
2727
*****************************************************************************/
2828
#define DEFAULT_ATECC_RETRIES 5
29+
#define SIGNATURE_SIZE 64
30+
#define POSTFIX1_SIZE 7
31+
#define POSTFIX2_SIZE 23
2932
#define DEVICE_SERIAL_SIZE 32
3033

3134
/*****************************************************************************

common/core/core_api.c

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <core.pb.h>
6666

6767
#include "assert_conf.h"
68+
#include "core_session.h"
6869
#include "pb_encode.h"
6970
#include "status_api.h"
7071
#include "usb_api.h"
@@ -130,7 +131,6 @@ void send_response_to_host(const uint8_t *msg, const uint32_t size) {
130131
core_msg.cmd.applet_id = get_applet_id();
131132

132133
send_core_msg(&core_msg, msg, size);
133-
return;
134134
}
135135

136136
void send_core_error_msg_to_host(uint32_t core_error_type) {
@@ -139,7 +139,6 @@ void send_core_error_msg_to_host(uint32_t core_error_type) {
139139
core_msg.error.type = (core_error_type_t)core_error_type;
140140

141141
send_core_msg(&core_msg, NULL, 0);
142-
return;
143142
}
144143

145144
void send_app_version_list_to_host(
@@ -154,5 +153,54 @@ void send_app_version_list_to_host(
154153
sizeof(core_app_version_result_response_t));
155154

156155
send_core_msg(&core_msg, NULL, 0);
157-
return;
158-
}
156+
}
157+
158+
void send_core_session_start_response_to_host(const uint8_t *payload) {
159+
core_msg_t core_msg = CORE_MSG_INIT_ZERO;
160+
core_msg.which_type = CORE_MSG_SESSION_START_TAG;
161+
core_msg.session_start.which_cmd = CORE_SESSION_START_CMD_RESPONSE_TAG;
162+
core_msg.session_start.response.which_response =
163+
CORE_SESSION_START_RESPONSE_CONFIRMATION_INITIATE_TAG;
164+
uint32_t offset = 0;
165+
memcpy(core_msg.session_start.response.confirmation_initiate
166+
.device_random_public,
167+
payload + offset,
168+
SESSION_PUB_KEY_SIZE);
169+
offset += SESSION_PUB_KEY_SIZE;
170+
memcpy(core_msg.session_start.response.confirmation_initiate.device_id,
171+
payload + offset,
172+
DEVICE_SERIAL_SIZE);
173+
offset += DEVICE_SERIAL_SIZE;
174+
memcpy(core_msg.session_start.response.confirmation_initiate.signature,
175+
payload + offset,
176+
SIGNATURE_SIZE);
177+
offset += SIGNATURE_SIZE;
178+
memcpy(core_msg.session_start.response.confirmation_initiate.postfix1,
179+
payload + offset,
180+
POSTFIX1_SIZE);
181+
offset += POSTFIX1_SIZE;
182+
memcpy(core_msg.session_start.response.confirmation_initiate.postfix2,
183+
payload + offset,
184+
POSTFIX2_SIZE);
185+
186+
send_core_msg(&core_msg, NULL, 0);
187+
}
188+
189+
void send_core_session_start_ack_to_host() {
190+
core_msg_t core_msg = CORE_MSG_INIT_ZERO;
191+
core_msg.which_type = CORE_MSG_SESSION_START_TAG;
192+
core_msg.session_start.which_cmd = CORE_SESSION_START_CMD_RESPONSE_TAG;
193+
core_msg.session_start.response.which_response =
194+
CORE_SESSION_START_RESPONSE_CONFIRMATION_START_TAG;
195+
send_core_msg(&core_msg, NULL, 0);
196+
}
197+
198+
void send_core_session_close_response_to_host() {
199+
core_msg_t core_msg = CORE_MSG_INIT_ZERO;
200+
core_msg.which_type = CORE_MSG_SESSION_CLOSE_TAG;
201+
core_msg.session_close.which_cmd = CORE_SESSION_CLOSE_CMD_RESPONSE_TAG;
202+
core_msg.session_close.response.which_response =
203+
CORE_SESSION_CLOSE_RESPONSE_CLEAR_TAG;
204+
205+
send_core_msg(&core_msg, NULL, 0);
206+
}

common/core/core_api.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void send_response_to_host(const uint8_t *msg, const uint32_t size);
4949
*
5050
* @param which_error The enum type of the error which needs to be sent
5151
*/
52-
void send_core_error_msg_to_host(uint32_t which_error);
52+
void send_core_error_msg_to_host(uint32_t core_error_type);
5353

5454
/**
5555
* @brief Helper API for core to send a response containing a list of
@@ -60,4 +60,10 @@ void send_core_error_msg_to_host(uint32_t which_error);
6060
*/
6161
void send_app_version_list_to_host(
6262
const core_app_version_result_response_t *version_resp);
63-
#endif /* CORE_API_H */
63+
64+
void send_core_session_start_response_to_host(const uint8_t *payload);
65+
66+
void send_core_session_start_ack_to_host();
67+
68+
void send_core_session_close_response_to_host();
69+
#endif /* CORE_API_H */

0 commit comments

Comments
 (0)