Skip to content

Commit

Permalink
Fix session_id generate
Browse files Browse the repository at this point in the history
Fix the issue: DMTF#1424
Make session_id generate right.

Signed-off-by: Wenxing Hou <[email protected]>
  • Loading branch information
Wenxing-hou committed Dec 1, 2022
1 parent 8902251 commit eb72748
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
10 changes: 10 additions & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,16 @@ libspdm_return_t libspdm_append_message_f(void *context, void *spdm_session_info
bool is_requester, const void *message,
size_t message_size);

/**
* This function generate a new session ID by concatnating req_session_id and rsp_session_id.
*
* @param[in] req_session_id
* @param[in] rsp_session_id
*
* @return this new session ID.
**/
uint32_t libspdm_generate_session_id(uint16_t req_session_id, uint16_t rsp_session_id);

/**
* This function assigns a new session ID.
*
Expand Down
15 changes: 15 additions & 0 deletions library/spdm_common_lib/libspdm_com_context_data_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ void *libspdm_get_secured_message_context_via_session_info(void *spdm_session_in
}
}

/**
* This function generate a new session ID by concatnating req_session_id and rsp_session_id.
*
* @param[in] req_session_id
* @param[in] rsp_session_id
*
* @return this new session ID.
**/
uint32_t libspdm_generate_session_id(uint16_t req_session_id, uint16_t rsp_session_id)
{
uint32_t session_id;
session_id = (rsp_session_id << 16) | req_session_id;
return session_id;
}

/**
* This function assigns a new session ID.
*
Expand Down
2 changes: 1 addition & 1 deletion library/spdm_requester_lib/libspdm_req_key_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ static libspdm_return_t libspdm_try_send_receive_key_exchange(
}

rsp_session_id = spdm_response->rsp_session_id;
*session_id = (req_session_id << 16) | rsp_session_id;
*session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
session_info = libspdm_assign_session_id(spdm_context, *session_id, false);

/* session_info cannot be null as the check after libspdm_allocate_req_session_id assures
Expand Down
2 changes: 1 addition & 1 deletion library/spdm_requester_lib/libspdm_req_psk_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static libspdm_return_t libspdm_try_send_receive_psk_exchange(
*heartbeat_period = spdm_response->header.param1;
}
rsp_session_id = spdm_response->rsp_session_id;
*session_id = (req_session_id << 16) | rsp_session_id;
*session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
session_info = libspdm_assign_session_id(spdm_context, *session_id, true);
if (session_info == NULL) {
status = LIBSPDM_STATUS_SESSION_NUMBER_EXCEED;
Expand Down
2 changes: 1 addition & 1 deletion library/spdm_responder_lib/libspdm_rsp_key_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ libspdm_return_t libspdm_get_response_key_exchange(void *context,
spdm_context, SPDM_ERROR_CODE_SESSION_LIMIT_EXCEEDED, 0,
response_size, response);
}
session_id = (req_session_id << 16) | rsp_session_id;
session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
session_info = libspdm_assign_session_id(spdm_context, session_id, false);
if (session_info == NULL) {
return libspdm_generate_error_response(
Expand Down
2 changes: 1 addition & 1 deletion library/spdm_responder_lib/libspdm_rsp_psk_exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ libspdm_return_t libspdm_get_response_psk_exchange(void *context,
spdm_context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
response_size, response);
}
session_id = (req_session_id << 16) | rsp_session_id;
session_id = libspdm_generate_session_id(req_session_id, rsp_session_id);
session_info = libspdm_assign_session_id(spdm_context, session_id, true);
if (session_info == NULL) {
return libspdm_generate_error_response(
Expand Down

0 comments on commit eb72748

Please sign in to comment.