mxm_wifiex: clean up secure_host

Since the SECURE_HOST related files have been removed, the secure_host
in the README should also be cleaned up accordingly.

Also, some missing files in the mlan and mlinux folders have been
cleaned up.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
This commit is contained in:
Sherry Sun 2025-08-26 11:07:02 +08:00
parent f97f966e17
commit 60f40a222f
6 changed files with 0 additions and 817 deletions

3
README
View file

@ -217,9 +217,6 @@
this bit is only used with STA BSS
others -- reserved
secure_host=0|1 <Disable secure host interface (default) | Enable secure host interface>
Note: For secure_host=1, Firmware image shall be secure host enabled.
Note: On some platforms (e.g. PXA910/920) double quotation marks ("") need to used
for module parameters.
insmod sdxxx.ko "<para1> <para2> ..."

View file

@ -1,329 +0,0 @@
/** @file mlan_shc.c
*
* @brief This file contains the secure host interface functions.
*
*
* Copyright 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
* (the License). You may use, redistribute and/or modify the File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
#include "mlan.h"
#include "mlan_util.h"
#include "mlan_fw.h"
#include "mlan_shc.h"
#include "mlan_shc_key.h"
#include "nanotls-device.h"
#include "nanotls-host.h"
#include "nanotls-common.h"
/********************************************************
Local Variables
********************************************************/
enum action_status {
ACTION_HANDSHAKE = 0,
ACTION_HANDSHAKE_SUCCESS = 1,
ACTION_HANDSHAKE_FAIL = 2,
};
/********************************************************
Global Variables
********************************************************/
#define SECURE_HOST_TAG_LEN 16
/********************************************************
Local Functions
********************************************************/
/**
* @brief This function decrypts command response received
*
* @param pmadapter A pointer to mlan_adapter structure
* @param buf A pointer to command payload
* @param len Command payload length
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
static mlan_status mlan_shc_data_decrypt(pmlan_adapter pmadapter, t_u8 *buf,
t_u32 len)
{
mlan_status ret = MLAN_STATUS_SUCCESS;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_void *enc_data = MNULL;
ret = pcb->moal_malloc(pmadapter->pmoal_handle, len, MLAN_MEM_DEF,
(t_u8 **)&enc_data);
if (ret != MLAN_STATUS_SUCCESS)
return ret;
ret = pcb->moal_secure_host_data_decrypt(pmadapter->pmoal_handle,
&enc_data, (void *)&buf, len);
pcb->moal_mfree(pmadapter->pmoal_handle, enc_data);
return ret;
}
/**
* @brief This function encrypts command request to be transmitted
*
* @param pmadapter A pointer to mlan_adapter structure
* @param buf A pointer to command payload
* @param len Command payload length
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
static mlan_status mlan_shc_data_encrypt(pmlan_adapter pmadapter, t_u8 *buf,
t_u32 len)
{
mlan_status ret = MLAN_STATUS_SUCCESS;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_void *enc_data = MNULL;
ret = pcb->moal_malloc(pmadapter->pmoal_handle, len, MLAN_MEM_DEF,
(t_u8 **)&enc_data);
if (ret != MLAN_STATUS_SUCCESS)
return ret;
ret = pcb->moal_secure_host_data_encrypt(pmadapter->pmoal_handle,
&enc_data, (void *)&buf, len);
pcb->moal_mfree(pmadapter->pmoal_handle, enc_data);
return ret;
}
/**
* @brief This function prepares secure host handshake msg to be sent to fw
*
* @param pmadapter A pointer to mlan_adapter structure
* @msg A pointer to message
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
static mlan_status mlan_shc_prepare_msg(pmlan_adapter pmadapter, t_void *msg)
{
mlan_private *pmpriv = wlan_get_priv(pmadapter, MLAN_BSS_ROLE_ANY);
mlan_status ret = wlan_prepare_cmd(pmpriv, HostCmd_CMD_SECURE_HOST, 0,
0, MNULL, msg);
if (ret != MLAN_STATUS_SUCCESS)
PRINTM(MERROR, "secure host: command prepare failed\n");
return ret;
}
/**
* @brief This function initializes data path post secure host handshake
*
* @param pmadapter A pointer to mlan_adapter structure
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
static mlan_status mlan_shc_data_path_init(pmlan_adapter pmadapter)
{
pmlan_callbacks pcb = &pmadapter->callbacks;
if (!pcb->moal_secure_host_derive_traffic_keys(
pmadapter->pmoal_handle) &&
!pcb->moal_secure_host_data_ctx_init(pmadapter->pmoal_handle))
return MLAN_STATUS_SUCCESS;
return MLAN_STATUS_FAILURE;
}
/********************************************************
Global Functions
********************************************************/
/**
* @brief This function determines if command in secured or non-secured
*
* @param cmd_id Unique command id
* @return secured:MTRUE, MFALSE otherwise
*/
t_bool wlan_is_secure_host_cmd(t_u16 cmd_id)
{
switch (cmd_id) {
/** non-secure commands sent prior host and fw handshake */
case HostCmd_CMD_SECURE_HOST:
case HostCmd_CMD_FUNC_INIT:
case HostCmd_CMD_GET_HW_SPEC:
case HostCmd_CMD_MCLIENT_SCHEDULE_CFG:
case HostCmd_CMD_802_11_SNMP_MIB:
case HostCmd_CMD_RECONFIGURE_TX_BUFF:
case HostCmd_CMD_802_11_FW_WAKE_METHOD:
case HostCmd_CMD_PCIE_ADMA_INIT:
case HostCmd_CMD_802_11_RF_ANTENNA:
case HostCmd_CMD_DBGS_CFG:
return MFALSE;
/** list of secure host commands */
case HostCmd_CMD_802_11_KEY_MATERIAL:
case HostCmd_CMD_SUPPLICANT_PMK:
case HostCmd_CMD_SUPPLICANT_PROFILE:
case HostCmd_CMD_REGION_POWER_CFG:
case HostCmd_CMD_VERSION_EXT:
case HostCmd_CMD_CFG_DATA:
return MTRUE;
}
return MTRUE;
}
/**
* @brief This function process command request to be transmitted
*
* @param pmadapter A pointer to mlan_adapter structure
* @param pcmd A pointer to command request
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status wlan_shc_secure_hostcmd_process(pmlan_adapter pmadapter,
HostCmd_DS_COMMAND *pcmd)
{
t_u32 cmd_size = 0;
if ((!(pcmd->command & HostCmd_Encrypted_BIT)) &&
(mlan_shc_data_encrypt(pmadapter, ((t_u8 *)pcmd + S_DS_GEN),
(pcmd->size - S_DS_GEN)) !=
MLAN_STATUS_FAILURE)) {
pcmd->command |= HostCmd_Encrypted_BIT;
cmd_size = wlan_le16_to_cpu(pcmd->size);
cmd_size += SECURE_HOST_TAG_LEN;
pcmd->size = wlan_cpu_to_le16(cmd_size);
return MLAN_STATUS_SUCCESS;
}
return MLAN_STATUS_FAILURE;
}
/**
* @brief This function process received command response
*
* @param pmadapter A pointer to mlan_adapter structure
* @param resp A pointer to command response
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status wlan_shc_secure_hostresp_process(pmlan_adapter pmadapter,
HostCmd_DS_COMMAND *resp)
{
mlan_status ret = MLAN_STATUS_SUCCESS;
if (wlan_le16_to_cpu(resp->command) & HostCmd_Encrypted_BIT) {
ret = mlan_shc_data_decrypt(pmadapter,
((t_u8 *)resp + S_DS_GEN),
(resp->size - S_DS_GEN));
if (ret != MLAN_STATUS_FAILURE) {
resp->command &= ~HostCmd_Encrypted_BIT;
resp->size = wlan_le16_to_cpu(resp->size -
SECURE_HOST_TAG_LEN);
DBG_HEXDUMP(MSHC_D, "Decrypted CMD_RESP", resp,
resp->size);
}
}
return ret;
}
/**
* @brief This function handles firmware event post secure host handshake
*
* @param pmadapter A pointer to mlan private structure
* @param type A pointer to event data
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status wlan_shc_process_secure_host_event(pmlan_private pmpriv, t_u8 *data,
t_u32 len)
{
mlan_status ret = MLAN_STATUS_FAILURE;
pmlan_adapter pmadapter = pmpriv->adapter;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_u8 type;
SECURE_HOST_EVENT_HEADER *pevent = (SECURE_HOST_EVENT_HEADER *)data;
switch (pevent->tls_action) {
case ACTION_HANDSHAKE:
type = pcb->moal_secure_host_get_msg_id(
data + sizeof(SECURE_HOST_EVENT_HEADER));
ret = mlan_shc_handshake(
pmadapter, type,
data + sizeof(SECURE_HOST_EVENT_HEADER));
if (ret != MLAN_STATUS_SUCCESS) {
pmadapter->hw_status = WlanHardwareStatusNotReady;
wlan_init_fw_complete(pmadapter);
}
break;
case ACTION_HANDSHAKE_SUCCESS:
PRINTM(MMSG, "secure host handshake success\n");
if (!mlan_shc_data_path_init(pmadapter)) {
wlan_adapter_get_hw_spec(pmadapter);
ret = MLAN_STATUS_SUCCESS;
} else {
PRINTM(MERROR, "secure host data init failed\n");
}
break;
case ACTION_HANDSHAKE_FAIL:
PRINTM(MERROR,
"secure host handshake fail, event status (0x%x) received\n",
pevent->tls_action);
break;
default:
PRINTM(MERROR,
"secure host, invalid event status (0x%x) received\n");
break;
}
return ret;
}
/**
* @brief This function handles security handshake between host and FW
*
* @param pmadapter A pointer to mlan_adapter structure
* @param type One of the three message types
* @return success:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status mlan_shc_handshake(pmlan_adapter pmadapter, t_u8 type, t_void *msg)
{
mlan_status ret = MLAN_STATUS_FAILURE;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_void *buf = MNULL;
switch (type) {
case TLS_HOST_HELLO:
if (!pcb->moal_secure_host_init(pmadapter->pmoal_handle,
ecdsa_pub) &&
!pcb->moal_secure_host_do_hello(pmadapter->pmoal_handle,
&buf)) {
ret = mlan_shc_prepare_msg(pmadapter, buf);
}
break;
case TLS_DEVICE_HELLO:
/** Process TLS device hello (M2) message */
if (pcb->moal_secure_host_device_hello_rcvd(
pmadapter->pmoal_handle, msg))
break;
/* fall through */
case TLS_HOST_FINISHED:
if (!pcb->moal_secure_host_do_finished(pmadapter->pmoal_handle,
&buf) &&
!mlan_shc_prepare_msg(pmadapter, buf)) {
pmadapter->hw_status = WlanHardwareStatusGetHwSpec;
ret = MLAN_STATUS_SUCCESS;
}
break;
default:
PRINTM(MMSG, "Invalid shc message type:%x\n", type);
break;
}
return ret;
}

View file

@ -1,39 +0,0 @@
/** @file mlan_shc.c
*
* @brief This file contains the secure host interface functions.
*
*
* Copyright 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
* (the License). You may use, redistribute and/or modify the File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
#ifndef _MLAN_SHC_H_
#define _MLAN_SHC_H_
#ifdef STA_SUPPORT
#include "mlan_join.h"
#endif
#include "mlan_main.h"
mlan_status mlan_shc_handshake(pmlan_adapter pmadapter, t_u8 type, t_void *msg);
mlan_status wlan_shc_process_secure_host_event(pmlan_private pmpriv, t_u8 *data,
t_u32 len);
mlan_status wlan_shc_secure_hostcmd_process(pmlan_adapter pmadapter,
HostCmd_DS_COMMAND *pcmd);
t_bool wlan_is_secure_host_cmd(t_u16 cmd_id);
mlan_status wlan_shc_secure_hostresp_process(pmlan_adapter pmadapter,
HostCmd_DS_COMMAND *resp);
mlan_status wlan_shc_prep_for_requeue(pmlan_adapter pmadapter,
HostCmd_DS_COMMAND *pcmd);
#endif

View file

@ -1,33 +0,0 @@
/** @file mlan_shc.c
*
* @brief This file contains the secure host interface functions.
*
*
* Copyright 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
* (the License). You may use, redistribute and/or modify the File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
#ifndef _MLAN_SHC_KEY_H_
#define _MLAN_SHC_KEY_H_
static const uint8_t ecdsa_pub[64] = {
0x60, 0xfe, 0xd4, 0xba, 0x25, 0x5a, 0x9d, 0x31, 0xc9, 0x61, 0xeb,
0x74, 0xc6, 0x35, 0x6d, 0x68, 0xc0, 0x49, 0xb8, 0x92, 0x3b, 0x61,
0xfa, 0x6c, 0xe6, 0x69, 0x62, 0x2e, 0x60, 0xf2, 0x9f, 0xb6, 0x79,
0x03, 0xfe, 0x10, 0x08, 0xb8, 0xbc, 0x99, 0xa4, 0x1a, 0xe9, 0xe9,
0x56, 0x28, 0xbc, 0x64, 0xf2, 0xf1, 0xb2, 0x0c, 0x2d, 0x7e, 0x9f,
0x51, 0x77, 0xa3, 0xc2, 0x94, 0xd4, 0x46, 0x22, 0x99,
};
#endif

View file

@ -1,356 +0,0 @@
/** @file moal_shc.c
*
* @brief This file contains callback functions for secure host interface.
*
*
* Copyright 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
* (the License). You may use, redistribute and/or modify the File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
#include "moal_shc.h"
/**
* @brief This function determines secure host message id
*
* @param msg A pointer to message
*
* @return success:valid message id, invalid otherwise
*/
t_u8 moal_secure_host_get_msg_id(t_void *msg)
{
struct nanotls_message_hdr *hdr = (struct nanotls_message_hdr *)msg;
return hdr->message_id;
}
/**
* @brief This function initialized host context
*
* @param pmoal A pointer to moal_handle structure
* @param enc_data A pointer to public key
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_init(t_void *pmoal, const t_u8 esdca_pub[64])
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
handle->secure = kzalloc(sizeof(secure_host_t), GFP_KERNEL);
if (!handle->secure) {
PRINTM(MERROR, "Failed to alloc memory for shc handler\n");
return MLAN_STATUS_FAILURE;
}
secure_host_t *secure = (secure_host_t *)handle->secure;
secure->host_ctx = kzalloc(sizeof(struct nanotls_host_ctx), GFP_KERNEL);
if (!secure->host_ctx) {
PRINTM(MERROR, "Failed to alloc memory for shc context\n");
return MLAN_STATUS_FAILURE;
}
ret = nanotls_host_init(secure->host_ctx, esdca_pub);
if (ret)
PRINTM(MERROR, "Failed to init shc context\n");
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function free up secure host memory
*
* @param pmoal A pointer to moal_handle structure
*
* @return N/A
*/
void moal_secure_host_cleanup(t_void *pmoal)
{
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
int idx = 0;
if (!handle->secure)
return;
PRINTM(MMSG, "Free secure host context\n");
nanotls_host_cleanup(secure->host_ctx);
for (idx = 0; idx < MAX_CTX_AND_KEY; idx++) {
if (secure->data_ctx[idx])
kfree(secure->data_ctx[idx]);
if (secure->host_keys[idx])
kfree(secure->host_keys[idx]);
}
if (secure->host_finished)
kfree(secure->host_finished);
if (secure->device_hello)
kfree(secure->device_hello);
if (secure->host_hello)
kfree(secure->host_hello);
if (secure->host_ctx)
kfree(secure->host_ctx);
kfree(secure);
}
/**
* @brief This function prepares host do hello message
*
* @param pmoal A pointer to moal_handle structure
* @param msg A pointer to do hello message
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_do_hello(t_void *pmoal, t_void **msg)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
secure->host_hello =
kzalloc(sizeof(struct nanotls_host_hello), GFP_KERNEL);
if (!secure->host_hello) {
PRINTM(MERROR, "Failed to alloc memory for host hello\n");
return MLAN_STATUS_FAILURE;
}
*msg = kzalloc(sizeof(struct nanotls_host_hello), GFP_KERNEL);
if (!secure->host_hello) {
PRINTM(MERROR, "Failed to alloc memory for host hello msg\n");
return MLAN_STATUS_FAILURE;
}
ret = nanotls_host_do_hello(secure->host_ctx, secure->host_hello);
if (!ret) {
moal_memcpy_ext(handle, *msg, secure->host_hello,
sizeof(struct nanotls_host_hello),
sizeof(struct nanotls_host_hello));
} else {
PRINTM(MERROR, "Failed to generate host hello\n");
}
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function process received device hello message
*
* @param pmoal A pointer to moal_handle structure
* @param msg A pointer to device hello message
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_device_hello_rcvd(t_void *pmoal, t_void *msg)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
secure->device_hello =
kzalloc(sizeof(struct nanotls_device_hello), GFP_KERNEL);
if (!secure->device_hello) {
PRINTM(MERROR, "Failed to alloc memory for device hello\n");
return MLAN_STATUS_FAILURE;
}
moal_memcpy_ext(handle, secure->device_hello, msg,
sizeof(struct nanotls_device_hello),
sizeof(struct nanotls_device_hello));
ret = nanotls_host_device_hello_rcvd(secure->host_ctx,
secure->device_hello);
if (ret)
PRINTM(MERROR, "Failed to process device hello\n");
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepares secure host finished message
*
* @param pmoal A pointer to moal_handle structure
* @param msg A pointer to secure host finished message
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_do_finished(t_void *pmoal, t_void **msg)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
secure->host_finished =
kzalloc(sizeof(struct nanotls_host_finished), GFP_KERNEL);
if (!secure->host_finished) {
PRINTM(MERROR, "Failed to alloc memory for host finished\n");
return MLAN_STATUS_FAILURE;
}
*msg = kzalloc(sizeof(struct nanotls_host_finished), GFP_KERNEL);
if (!(*msg)) {
PRINTM(MERROR, "Failed to alloc memory for host finish msg\n");
return MLAN_STATUS_FAILURE;
}
ret = nanotls_host_do_finished(secure->host_ctx, secure->host_finished);
if (!ret) {
moal_memcpy_ext(handle, *msg, secure->host_finished,
sizeof(struct nanotls_host_finished),
sizeof(struct nanotls_host_finished));
} else {
PRINTM(MERROR, "Failed to generate host finished msg\n");
}
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function derives traffice keys
*
* @param pmoal A pointer to moal_handle structure
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_derive_traffic_keys(t_void *pmoal)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
t_u8 idx = 0;
idx = handle->second_mac;
secure->host_keys[idx] =
kzalloc(sizeof(struct nanotls_traffic_keys), GFP_KERNEL);
if (!secure->host_keys[idx]) {
PRINTM(MERROR, "Failed to alloc memory for host keys\n");
return MLAN_STATUS_FAILURE;
}
ret = nanotls_host_derive_traffic_keys_instance(
secure->host_ctx, secure->host_keys[idx], idx);
if (ret)
PRINTM(MERROR, "Failed to derive host keys\n");
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function initializes data context
*
* @param pmoal A pointer to moal_handle structure
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_data_ctx_init(t_void *pmoal)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
t_u8 idx = 0;
idx = handle->second_mac;
secure->data_ctx[idx] =
kzalloc(sizeof(struct nanotls_ctx_data), GFP_KERNEL);
if (!secure->data_ctx[idx]) {
PRINTM(MERROR, "Failed to alloc memory for data context\n");
return MLAN_STATUS_FAILURE;
}
ret = nanotls_data_ctx_init(secure->data_ctx[idx], NANOTLS_ROLE_HOST,
secure->host_keys[idx]);
if (ret)
PRINTM(MERROR, "Failed to init data context\n");
return (ret != 0) ? MLAN_STATUS_FAILURE : MLAN_STATUS_SUCCESS;
}
/**
* @brief This function encrypts the payload
*
* @param pmoal A pointer to moal_handle structure
* @param enc_data A pointer to encrypted data
* @param payload A pointer to payload to be encrpted
* @param len Payload length
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_data_encrypt(t_void *pmoal, t_void **enc_data,
t_void **payload, t_u32 len)
{
int ret = 0;
t_u8 tag[NANOTLS_AES_GCM_TAG_SIZE];
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
t_u8 idx = 0;
if (!secure) {
PRINTM(MERROR, "encrypt:shc context not initialized\n");
return MLAN_STATUS_FAILURE;
}
idx = handle->second_mac;
ret = nanotls_data_write(secure->data_ctx[idx], *enc_data, *payload,
len, tag);
if (!ret) {
moal_memcpy_ext(handle, *payload, *enc_data, len, len);
moal_memcpy_ext(handle, *payload + len, tag,
NANOTLS_AES_GCM_TAG_SIZE,
NANOTLS_AES_GCM_TAG_SIZE);
return MLAN_STATUS_SUCCESS;
}
PRINTM(MERROR, "Failed to encrypt command request\n");
return MLAN_STATUS_FAILURE;
}
/**
* @brief This function decrypts the payload
*
* @param pmoal A pointer to moal_handle structure
* @param dec_data A pointer to decrypted data
* @param payload A pointer to encrypted payload
* @param len Payload length
*
* @return sucess:MLAN_STATUS_SUCCESS, MLAN_STATUS_FAILURE otherwise
*/
mlan_status moal_secure_host_data_decrypt(t_void *pmoal, t_void **dec_data,
t_void **payload, t_u32 len)
{
int ret = 0;
moal_handle *handle = (moal_handle *)pmoal;
secure_host_t *secure = (secure_host_t *)handle->secure;
t_u8 idx = 0;
if (!secure) {
PRINTM(MERROR, "decrypt: shc context not initialized\n");
return MLAN_STATUS_FAILURE;
}
idx = handle->second_mac;
ret = nanotls_data_read(secure->data_ctx[idx], *dec_data, *payload,
len - NANOTLS_AES_GCM_TAG_SIZE,
*payload + (len - NANOTLS_AES_GCM_TAG_SIZE));
if (!ret) {
moal_memcpy_ext(handle, *payload, *dec_data,
len - NANOTLS_AES_GCM_TAG_SIZE,
len - NANOTLS_AES_GCM_TAG_SIZE);
return MLAN_STATUS_SUCCESS;
}
PRINTM(MERROR, "Failed to decrypt command response\n");
return MLAN_STATUS_FAILURE;
}

View file

@ -1,57 +0,0 @@
/** @file moal_shc.c
*
* @brief This file contains callback functions for secure host interface.
*
*
* Copyright 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
* (the License). You may use, redistribute and/or modify the File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*
*/
#ifndef _MOAL_SHC_H_
#define _MOAL_SHC_H_
#include "moal_main.h"
#include "nanotls-device.h"
#include "nanotls-host.h"
#include "nanotls-common.h"
#include "nanotls-data.h"
/* Unique data context and traffic key per MAC */
#define MAX_CTX_AND_KEY 2
typedef struct _secure_host_t {
struct nanotls_host_ctx *host_ctx;
struct nanotls_host_hello *host_hello;
struct nanotls_device_hello *device_hello;
struct nanotls_host_finished *host_finished;
struct nanotls_traffic_keys *host_keys[MAX_CTX_AND_KEY];
struct nanotls_ctx_data *data_ctx[MAX_CTX_AND_KEY];
} secure_host_t;
t_u8 moal_secure_host_get_msg_id(t_void *msg);
mlan_status moal_secure_host_init(t_void *pmoal, const t_u8 esdca_pub[64]);
void moal_secure_host_cleanup(t_void *pmoal);
mlan_status moal_secure_host_do_hello(t_void *pmoal, t_void **msg);
mlan_status moal_secure_host_device_hello_rcvd(t_void *pmoal, t_void *msg);
mlan_status moal_secure_host_do_finished(t_void *pmoal, t_void **msg);
mlan_status moal_secure_host_derive_traffic_keys(t_void *pmoal);
mlan_status moal_secure_host_data_ctx_init(t_void *pmoal);
mlan_status moal_secure_host_data_encrypt(t_void *pmoal, t_void **enc_data,
t_void **payload, t_u32 len);
mlan_status moal_secure_host_data_decrypt(t_void *pmoal, t_void **dec_data,
t_void **payload, t_u32 len);
#endif /* _MOAL_SHC_H_ */