Driver commit for release MM6X18540.p7 2025-08-23

Firmware version for commit:
W8997-16.92.21.p153.4
W9098-17.92.1.p149.76
IW416-16.92.21.p153.4
W8987-16.92.21.p153.4
IW612-18.99.3.p26.7
IW610-18.99.5.p73
AW693-18.99.2.p145.99

Signed-off-by: AMIT CHOUDHARY <amit.kumar_13@nxp.com>
Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
This commit is contained in:
AMIT CHOUDHARY 2025-08-23 02:20:34 +05:30 • committed by Sherry Sun
parent 1e8b968f43
commit a250162547
86 changed files with 11922 additions and 375 deletions

View file

@ -175,7 +175,7 @@ APPDIR= $(shell if test -d "mapp"; then echo mapp; fi)
#############################################################################
ccflags-y += -I$(KERNELDIR)/include
ccflags-y += -DMLAN_RELEASE_VERSION='"540"'
ccflags-y += -DMLAN_RELEASE_VERSION='"540.p7"'
ccflags-y += -DFPNUM='"92"'
@ -590,7 +590,32 @@ endif
$(info $(PWD))
$(info $(src))
ccflags-y += -I$(PWD)/nanotls/include
ccflags-y += -I$(PWD)/nanotls/lib/include
ccflags-y += -I$(PWD)/nanotls/lib/aes/include
ccflags-y += -I$(src)/include
ccflags-y += -I$(src)/lib/include
ccflags-y += -I$(src)/lib/aes/include
ccflags-y += -I$(KERNELDIR)/include/linux
ccflags-y += -std=gnu99
ccflags-y += -Wno-format-security -Wno-unused-but-set-variable -Wno-declaration-after-statement
MLANOBJS += mlan/mlan_shc.o
MOALOBJS += nanotls/lib/src/blockwise.o \
nanotls/lib/src/chash.o \
nanotls/lib/src/hmac.o \
nanotls/lib/src/p256-m.o \
nanotls/lib/src/sha256.o \
nanotls/lib/aes/src/aes.o \
nanotls/lib/aes/src/gcm.o \
nanotls/src/nanotls-common.o \
nanotls/src/nanotls-hooks.o \
nanotls/src/nanotls-host.o \
nanotls/src/nanotls-device.o \
nanotls/src/nanotls-data.o \
mlinux/moal_shc.o
obj-m := mlan.o

3
README
View file

@ -217,6 +217,9 @@
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

@ -844,6 +844,18 @@ int wlan_cmd_append_116e_tlv(mlan_private *pmpriv, BSSDescriptor_t *pbss_desc,
return ret_len;
}
/**
* @brief This function checks whether the operation class is a 6G
*
* @param op_class global operation class
*
* @return 0--not allowed, other value allowed
*/
t_bool is_6ghz_op_class(t_u8 op_class)
{
return op_class >= 131 && op_class <= 137;
}
/**
* @brief This function check if 11AX is allowed in bandcfg
*

View file

@ -3,7 +3,7 @@
* @brief This file contains the functions for station ioctl.
*
*
* Copyright 2018-2022 NXP
* Copyright 2018-2022, 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
@ -69,6 +69,7 @@ int wlan_cmd_append_116e_tlv(mlan_private *pmpriv, BSSDescriptor_t *pbss_desc,
t_u8 **ppbuffer);
t_u8 wlan_get_6g_ap_bandconfig(BSSDescriptor_t *pbss_desc,
Band_Config_t *bandcfg);
t_bool is_6ghz_op_class(t_u8 op_class);
int wlan_cmd_append_11ax_tlv(mlan_private *pmpriv, BSSDescriptor_t *pbss_desc,
t_u8 **ppbuffer);

View file

@ -1895,7 +1895,7 @@ mlan_status wlan_cmd_recfg_tx_buf(mlan_private *priv, HostCmd_DS_COMMAND *cmd,
{
HostCmd_DS_TXBUF_CFG *ptx_buf = &cmd->params.tx_buf;
t_u16 action = (t_u16)cmd_action;
t_u16 buf_size = *((t_u16 *)pdata_buf);
t_u16 buf_size = read_u16_unaligned(priv->adapter, pdata_buf);
ENTER();
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_RECONFIGURE_TX_BUFF);

View file

@ -78,11 +78,12 @@ static int wlan_11n_form_amsdu_pkt(pmlan_adapter pmadapter, t_u8 *amsdu_buf,
(MLAN_MAC_ADDR_LENGTH)*2);
dt_offset = amsdu_buf_offset = (MLAN_MAC_ADDR_LENGTH)*2;
snap.snap_type = *(t_u16 *)(data + dt_offset);
snap.snap_type = read_u16_unaligned(pmadapter, data + dt_offset);
dt_offset += sizeof(t_u16);
*(t_u16 *)(amsdu_buf + amsdu_buf_offset) =
write_u16_unaligned(
pmadapter, amsdu_buf + amsdu_buf_offset,
mlan_htons(pkt_len + LLC_SNAP_LEN -
((2 * MLAN_MAC_ADDR_LENGTH) + sizeof(t_u16)));
((2 * MLAN_MAC_ADDR_LENGTH) + sizeof(t_u16))));
amsdu_buf_offset += sizeof(t_u16);
memcpy_ext(pmadapter, amsdu_buf + amsdu_buf_offset, &snap, LLC_SNAP_LEN,
LLC_SNAP_LEN);
@ -277,12 +278,13 @@ static int wlan_form_amsdu_subframe(pmlan_adapter pmadapter, mlan_buffer *pmbuf,
(MLAN_MAC_ADDR_LENGTH)*2);
dt_offset = amsdu_buf_offset = (MLAN_MAC_ADDR_LENGTH)*2;
snap.snap_type = *(t_u16 *)(data + dt_offset);
snap.snap_type = read_u16_unaligned(pmadapter, data + dt_offset);
dt_offset += sizeof(t_u16);
total_len = (t_u16)(pkt_len + LLC_SNAP_LEN -
((2 * MLAN_MAC_ADDR_LENGTH) + sizeof(t_u16)));
*(t_u16 *)(amsdu_buf + amsdu_buf_offset) = mlan_htons(total_len);
write_u16_unaligned(pmadapter, amsdu_buf + amsdu_buf_offset,
mlan_htons(total_len));
amsdu_buf_offset += sizeof(t_u16);
memcpy_ext(pmadapter, amsdu_buf + amsdu_buf_offset, &snap, LLC_SNAP_LEN,
@ -386,8 +388,8 @@ static int wlan_11n_get_num_aggrpkts(mlan_private *priv, t_u8 *data,
wlan_uap_check_forward(priv, data))
forward_flag = MTRUE;
/* Length will be in network format, change it to host */
pkt_len = mlan_ntohs(
(*(t_u16 *)(data + (2 * MLAN_MAC_ADDR_LENGTH))));
pkt_len = mlan_ntohs(read_u16_unaligned(
priv->adapter, data + (2 * MLAN_MAC_ADDR_LENGTH)));
if (pkt_len > total_pkt_len) {
PRINTM(MERROR, "Error in packet length.\n");
break;
@ -515,8 +517,8 @@ mlan_status wlan_11n_deaggregate_pkt(mlan_private *priv, pmlan_buffer pmbuf)
while (total_pkt_len >= hdr_len) {
prx_pkt = (RxPacketHdr_t *)data;
/* Length will be in network format, change it to host */
pkt_len = mlan_ntohs(
(*(t_u16 *)(data + (2 * MLAN_MAC_ADDR_LENGTH))));
pkt_len = mlan_ntohs(read_u16_unaligned(
priv->adapter, data + (2 * MLAN_MAC_ADDR_LENGTH)));
if (pkt_len > total_pkt_len) {
PRINTM(MERROR,
"Error in packet length: total_pkt_len = %d, pkt_len = %d\n",
@ -543,8 +545,9 @@ mlan_status wlan_11n_deaggregate_pkt(mlan_private *priv, pmlan_buffer pmbuf)
}
pkt_len += sizeof(Eth803Hdr_t) - LLC_SNAP_LEN;
} else {
*(t_u16 *)(data + (2 * MLAN_MAC_ADDR_LENGTH)) =
(t_u16)0;
write_u16_unaligned(priv->adapter,
data + (2 * MLAN_MAC_ADDR_LENGTH),
0);
pkt_len += sizeof(Eth803Hdr_t);
}
daggr_mbuf = wlan_alloc_mlan_buffer(pmadapter,

View file

@ -2517,8 +2517,8 @@ typedef struct _oper_bw_chan {
t_u8 global_oper_class;
/*bandwidth 0-20M 1-40M 2-80M 3-160M*/
t_u8 bandwidth;
/*channel list*/
t_u8 channel_list[13];
/*channel list, includes 6G*/
t_u8 channel_list[59]; /*size is based current largest channel array*/
} oper_bw_chan;
/** oper class table for US*/
@ -2548,6 +2548,35 @@ static oper_bw_chan oper_bw_chan_us[] = {
{128, 128, 2, {42, 58, 106, 122, 138, 155}},
{129, 129, 3, {50, 114}},
{130, 130, 2, {42, 58, 106, 122, 138, 155}},
/* 6G 20MHz */
{131, 131, 0, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37,
41, 45, 49, 53, 57, 61, 65, 69, 73, 77,
81, 85, 89, 93, 97, 101, 105, 109, 113, 117,
121, 125, 129, 133, 137, 141, 145, 149, 153, 157,
161, 165, 169, 173, 177, 181, 185, 189, 193, 197,
201, 205, 209, 213, 217, 221, 225, 229, 233}},
/* 6G 40MHz */
{132, 132, 1, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37,
41, 45, 49, 53, 57, 61, 65, 69, 73, 77,
81, 85, 89, 93, 97, 101, 105, 109, 113, 117,
121, 125, 129, 133, 137, 141, 145, 149, 153, 157,
161, 165, 169, 173, 177, 181, 185, 189, 193, 197,
201, 205, 209, 213, 217, 221, 225, 229, 233}},
/* 6G 80MHz */
{133, 133, 2, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37,
41, 45, 49, 53, 57, 61, 65, 69, 73, 77,
81, 85, 89, 93, 97, 101, 105, 109, 113, 117,
121, 125, 129, 133, 137, 141, 145, 149, 153, 157,
161, 165, 169, 173, 177, 181, 185, 189, 193, 197,
201, 205, 209, 213, 217, 221, 225, 229, 233}},
/* 6G 160MHz */
{134, 134, 3, {15, 47, 79, 111, 143, 175, 207}},
/* 6G 80+ MHz */
{135,
135,
0,
{7, 23, 39, 55, 71, 87, 103, 119, 135, 151, 167, 183, 199, 215}},
{136, 136, 0, {2}},
};
/** oper class table for EU*/
static oper_bw_chan oper_bw_chan_eu[] = {
@ -2568,6 +2597,20 @@ static oper_bw_chan oper_bw_chan_eu[] = {
{128, 128, 2, {42, 58, 106, 122, 138, 155}},
{129, 129, 3, {50, 114}},
{130, 130, 2, {42, 58, 106, 122, 138, 155}},
/* 6G 20MHz */
{131, 131, 0, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 40MHz */
{132, 132, 1, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 80MHz */
{133, 133, 2, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 160MHz */
{134, 134, 3, {15, 47, 79}},
/* 6G 80+ MHz */
{135, 135, 0, {7, 23, 39, 55, 71, 87}},
{136, 136, 0, {2}},
};
/** oper class table for Japan*/
static oper_bw_chan oper_bw_chan_jp[] = {
@ -2595,6 +2638,20 @@ static oper_bw_chan oper_bw_chan_jp[] = {
{128, 128, 2, {42, 58, 106, 122, 138, 155}},
{129, 129, 3, {50, 114}},
{130, 130, 2, {42, 58, 106, 122, 138, 155}},
/* 6G 20MHz */
{131, 131, 0, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 40MHz */
{132, 132, 1, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 80MHz */
{133, 133, 2, {1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45,
49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93}},
/* 6G 160MHz */
{134, 134, 3, {15, 47, 79}},
/* 6G 80+ MHz */
{135, 135, 0, {7, 23, 39, 55, 71, 87}},
{136, 136, 0, {2}},
};
/** oper class table for China*/
static oper_bw_chan oper_bw_chan_cn[] = {
@ -2765,7 +2822,8 @@ mlan_status wlan_check_operclass_validation(mlan_private *pmpriv, t_u8 channel,
* @return MLAN_STATUS_PENDING --success, otherwise fail
*/
mlan_status wlan_get_curr_oper_class(mlan_private *pmpriv, t_u8 channel,
t_u8 bw, t_u8 *oper_class)
t_u8 bw, t_u8 *oper_class,
t_u8 *global_oper_class)
{
oper_bw_chan *poper_bw_chan = MNULL;
t_u8 center_freq_idx = 0;
@ -2805,6 +2863,9 @@ mlan_status wlan_get_curr_oper_class(mlan_private *pmpriv, t_u8 channel,
channel) {
*oper_class =
poper_bw_chan[i].oper_class;
*global_oper_class =
poper_bw_chan[i]
.global_oper_class;
return MLAN_STATUS_SUCCESS;
}
}

View file

@ -46,6 +46,8 @@ Change Log:
#endif /* PCIE */
#include "mlan_init.h"
#include "mlan_shc.h"
/********************************************************
Local Variables
********************************************************/
@ -885,7 +887,8 @@ static t_u32 wlan_process_hostcmd_cfg(pmlan_private pmpriv, t_u16 cfg_type,
/* buf points to the allocated hostcmd->cmd, and
* hence valid */
// coverity[cert_exp33_c_violation:SUPPRESS]
cmd_len = *((t_u16 *)(buf + sizeof(t_u16)));
cmd_len = read_u16_unaligned(
pmadapter, buf + sizeof(t_u16));
hostcmd->len = cmd_len;
}
ret = wlan_prepare_cmd(pmpriv, 0, 0, 0, MNULL,
@ -1221,6 +1224,75 @@ static cmd_ctrl_node *wlan_get_bss_pending_ioctl_cmd(pmlan_adapter pmadapter,
return MNULL;
}
/**
* @brief This function will return the pointer to the first entry in
* pending cmd which has cmd_no equal to addba/delba/addbaresp
* @param pmpriv A pointer to mlan_private
*
* @return pcmd_node or MNULL
*/
static cmd_ctrl_node *wlan_get_ba_cmd_in_cmd_pending_q(pmlan_private pmpriv)
{
cmd_ctrl_node *pcmd_node = MNULL;
pmlan_adapter pmadapter = pmpriv->adapter;
ENTER();
pcmd_node = (cmd_ctrl_node *)util_peek_list(pmadapter->pmoal_handle,
&pmadapter->cmd_pending_q,
MNULL, MNULL);
if (!pcmd_node) {
LEAVE();
return MNULL;
}
while (pcmd_node != (cmd_ctrl_node *)&pmadapter->cmd_pending_q) {
if ((pcmd_node->priv == pmpriv) &&
(pcmd_node->cmd_no == HostCmd_CMD_11N_DELBA ||
pcmd_node->cmd_no == HostCmd_CMD_11N_ADDBA_REQ ||
pcmd_node->cmd_no == HostCmd_CMD_11N_ADDBA_RSP)) {
LEAVE();
return pcmd_node;
}
pcmd_node = pcmd_node->pnext;
}
LEAVE();
return MNULL;
}
/**
* @brief This function will return the pointer to the first entry in
* pending cmd which has cmd_no equal to addba/delba/addbaresp
* @param pmpriv A pointer to mlan_private
*
* @return pcmd_node or MNULL
*/
static cmd_ctrl_node *wlan_get_ba_cmd_in_ext_cmd_pending_q(pmlan_private pmpriv)
{
cmd_ctrl_node *pcmd_node = MNULL;
pmlan_adapter pmadapter = pmpriv->adapter;
ENTER();
pcmd_node =
(cmd_ctrl_node *)util_peek_list(pmadapter->pmoal_handle,
&pmadapter->ext_cmd_pending_q,
MNULL, MNULL);
if (!pcmd_node) {
LEAVE();
return MNULL;
}
while (pcmd_node != (cmd_ctrl_node *)&pmadapter->ext_cmd_pending_q) {
if ((pcmd_node->priv == pmpriv) &&
(pcmd_node->cmd_no == HostCmd_CMD_11N_DELBA ||
pcmd_node->cmd_no == HostCmd_CMD_11N_ADDBA_REQ ||
pcmd_node->cmd_no == HostCmd_CMD_11N_ADDBA_RSP)) {
LEAVE();
return pcmd_node;
}
pcmd_node = pcmd_node->pnext;
}
LEAVE();
return MNULL;
}
/**
* @brief This function handles the command response of host_cmd
*
@ -1422,7 +1494,8 @@ static mlan_status wlan_dnld_cmd_to_fw(mlan_private *pmpriv,
(pmadapter->dbg.last_cmd_index + 1) % DBG_CMD_NUM;
pmadapter->dbg.last_cmd_id[pmadapter->dbg.last_cmd_index] = cmd_code;
pmadapter->dbg.last_cmd_act[pmadapter->dbg.last_cmd_index] =
wlan_le16_to_cpu(*(t_u16 *)((t_u8 *)pcmd + S_DS_GEN));
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter,
(t_u8 *)pcmd + S_DS_GEN));
pmadapter->callbacks.moal_get_system_time(pmadapter->pmoal_handle,
&pmadapter->dnld_cmd_in_secs,
&age_ts_usec);
@ -1470,9 +1543,15 @@ static mlan_status wlan_dnld_cmd_to_fw(mlan_private *pmpriv,
PRINTM(MCMND,
"DNLD_CMD (%lu.%06lu): %s [0x%x], act 0x%x, len %d, seqno 0x%x timeout %d\n",
sec, usec, wlan_hostcmd_get_name(cmd_code), cmd_code,
wlan_le16_to_cpu(*(t_u16 *)((t_u8 *)pcmd + S_DS_GEN)), cmd_size,
wlan_le16_to_cpu(pcmd->seq_num), timeout);
DBG_HEXDUMP(MCMD_D, "DNLD_CMD", (t_u8 *)pcmd, cmd_size);
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter,
(t_u8 *)pcmd + S_DS_GEN)),
cmd_size, wlan_le16_to_cpu(pcmd->seq_num), timeout);
if (!pmadapter->shc_secure_host)
DBG_HEXDUMP(MCMD_D, "DNLD_CMD", (t_u8 *)pcmd, cmd_size);
if (pmadapter->shc_secure_host)
DBG_HEXDUMP(MSHC_D, "DNLD_CMD", (t_u8 *)pcmd, cmd_size);
#if defined(SDIO) || defined(PCIE)
if (!IS_USB(pmadapter->card_type)) {
@ -1482,6 +1561,21 @@ static mlan_status wlan_dnld_cmd_to_fw(mlan_private *pmpriv,
}
#endif
if (pmadapter->shc_secure_host &&
wlan_is_secure_host_cmd(pcmd->command) == MTRUE) {
if (wlan_shc_secure_hostcmd_process(pmadapter, pcmd) !=
MLAN_STATUS_FAILURE) {
pcmd_node->cmdbuf->data_len += 16;
PRINTM(MCMND, "%s is encrypted",
wlan_hostcmd_get_name(cmd_code));
DBG_HEXDUMP(MCMD_D, "Encrypted DNLD_CMD", (t_u8 *)pcmd,
pcmd->size);
} else {
ret = MLAN_STATUS_FAILURE;
goto done;
}
}
/* Send the command to lower layer */
ret = pmadapter->ops.host_to_card(pmpriv, MLAN_TYPE_CMD,
pcmd_node->cmdbuf, MNULL);
@ -2358,14 +2452,20 @@ done:
* @return N/A
*/
static void wlan_handle_cmd_error_in_pre_aleep(mlan_adapter *pmadapter,
t_u16 cmd_no)
t_u16 cmd_no,
HostCmd_DS_COMMAND *rsp)
{
cmd_ctrl_node *pcmd_node = MNULL;
ENTER();
PRINTM(MERROR, "CMD_RESP: 0x%x block in pre_asleep!\n", cmd_no);
wlan_request_cmd_lock(pmadapter);
pcmd_node = pmadapter->curr_cmd;
pmadapter->curr_cmd = MNULL;
if (pcmd_node) {
if (!IS_USB(pmadapter->card_type)) {
pcmd_node->cmdbuf->data_offset +=
@ -2379,8 +2479,16 @@ static void wlan_handle_cmd_error_in_pre_aleep(mlan_adapter *pmadapter,
MLAN_STATUS_SUCCESS);
pcmd_node->respbuf = MNULL;
}
if (pmadapter->shc_secure_host) {
memcpy_ext(pmadapter,
pcmd_node->cmdbuf->pbuf +
pcmd_node->cmdbuf->data_offset,
rsp, rsp->size, rsp->size);
pcmd_node->cmdbuf->data_len = rsp->size;
}
wlan_insert_cmd_to_pending_q(pmadapter, pcmd_node, MFALSE);
}
wlan_release_cmd_lock(pmadapter);
LEAVE();
}
@ -2441,6 +2549,14 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
resp = (HostCmd_DS_COMMAND *)(pmadapter->curr_cmd->respbuf->pbuf +
pmadapter->curr_cmd->respbuf->data_offset);
if (pmadapter->shc_secure_host) {
if (wlan_shc_secure_hostresp_process(pmadapter, resp) !=
MLAN_STATUS_SUCCESS) {
goto done;
}
}
orig_cmdresp_no = wlan_le16_to_cpu(resp->command);
cmdresp_no = (orig_cmdresp_no & HostCmd_CMD_ID_MASK);
if (pmadapter->curr_cmd->cmd_no != cmdresp_no) {
@ -2546,7 +2662,7 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
if (!IS_USB(pmadapter->card_type) && pmadapter->curr_cmd &&
cmdresp_result == HostCmd_RESULT_PRE_ASLEEP) {
wlan_handle_cmd_error_in_pre_aleep(pmadapter,
cmdresp_no);
cmdresp_no, resp);
ret = MLAN_STATUS_FAILURE;
goto done;
}
@ -2560,7 +2676,7 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
if (!IS_USB(pmadapter->card_type) && pmadapter->curr_cmd &&
cmdresp_result == HostCmd_RESULT_PRE_ASLEEP) {
wlan_handle_cmd_error_in_pre_aleep(pmadapter,
cmdresp_no);
cmdresp_no, resp);
ret = MLAN_STATUS_FAILURE;
goto done;
}
@ -2572,7 +2688,8 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
/* Check init command response */
if (pmadapter->hw_status == WlanHardwareStatusInitializing ||
pmadapter->hw_status == WlanHardwareStatusGetHwSpec) {
pmadapter->hw_status == WlanHardwareStatusGetHwSpec ||
pmadapter->hw_status == WlanHardwareStatusSecHandshake) {
if (ret == MLAN_STATUS_FAILURE) {
#if 0
//ignore command error for WARM RESET
@ -2591,6 +2708,11 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
PRINTM(MERROR,
"cmd 0x%02x failed during initialization\n",
cmdresp_no);
if (pmadapter->hw_status ==
WlanHardwareStatusSecHandshake) {
PRINTM(MERROR,
"secure host handshake incomplete\n");
}
wlan_init_fw_complete(pmadapter);
goto done;
}
@ -2666,6 +2788,26 @@ mlan_status wlan_process_cmdresp(mlan_adapter *pmadapter)
(HostCmd_CMD_GET_HW_SPEC == cmdresp_no)) {
pmadapter->hw_status = WlanHardwareStatusGetHwSpecdone;
}
#if defined(PCIEAW693)
else if (pmadapter->shc_secure_host &&
(pmadapter->hw_status == WlanHardwareStatusGetHwSpec) &&
(HostCmd_CMD_FUNC_INIT == cmdresp_no)) {
if (!pmadapter->second_mac) {
pmadapter->hw_status = WlanHardwareStatusSecHandshake;
PRINTM(MMSG, "secure host handshake start\n");
ret = mlan_shc_handshake(pmadapter, TLS_HOST_HELLO,
MNULL);
if (ret != MLAN_STATUS_SUCCESS) {
pmadapter->hw_status =
WlanHardwareStatusNotReady;
wlan_init_fw_complete(pmadapter);
}
} else {
wlan_adapter_get_hw_spec(pmadapter);
}
}
#endif
done:
LEAVE();
return ret;
@ -3059,6 +3201,38 @@ t_void wlan_cancel_bss_pending_cmd(pmlan_adapter pmadapter, t_u32 bss_index)
return;
}
/**
* @brief wlan_cancel_pending_ba_commands
*
* @param priv A pointer to mlan_private
*
* @return N/A
*/
t_void wlan_cancel_pending_ba_commands(pmlan_private priv)
{
cmd_ctrl_node *pcmd_node = MNULL;
pmlan_adapter pmadapter = priv->adapter;
ENTER();
PRINTM(MCMND, "Cancel pending BA commands on disconnect\n");
wlan_request_cmd_lock(pmadapter);
while ((pcmd_node = wlan_get_ba_cmd_in_cmd_pending_q(priv)) != MNULL) {
util_unlink_list(pmadapter->pmoal_handle,
&pmadapter->cmd_pending_q,
(pmlan_linked_list)pcmd_node, MNULL, MNULL);
wlan_insert_cmd_to_free_q(pmadapter, pcmd_node);
}
while ((pcmd_node = wlan_get_ba_cmd_in_ext_cmd_pending_q(priv)) !=
MNULL) {
util_unlink_list(pmadapter->pmoal_handle,
&pmadapter->ext_cmd_pending_q,
(pmlan_linked_list)pcmd_node, MNULL, MNULL);
wlan_insert_cmd_to_free_q(pmadapter, pcmd_node);
}
wlan_release_cmd_lock(pmadapter);
LEAVE();
return;
}
/**
* @brief Cancel pending ioctl cmd.
*
@ -3080,7 +3254,8 @@ t_void wlan_cancel_pending_ioctl(pmlan_adapter pmadapter,
ENTER();
PRINTM(MIOCTL, "MOAL Cancel IOCTL: 0x%x sub_id=0x%x action=%d\n",
pioctl_req->req_id, *((t_u32 *)pioctl_req->pbuf),
pioctl_req->req_id,
read_u32_unaligned(pmadapter, pioctl_req->pbuf),
(int)pioctl_req->action);
wlan_request_cmd_lock(pmadapter);
@ -4001,8 +4176,8 @@ mlan_status wlan_cmd_enh_power_mode(pmlan_private pmpriv,
psmode_enh->params.ext_param.param.header.type =
wlan_cpu_to_le16(TLV_TYPE_PS_EXT_PARAM);
psmode_enh->params.ext_param.param.header.len = sizeof(t_u32);
psmode_enh->params.ext_param.param.mode =
wlan_cpu_to_le32(*((t_u32 *)pdata_buf));
psmode_enh->params.ext_param.param.mode = wlan_cpu_to_le32(
read_u32_unaligned(pmpriv->adapter, pdata_buf));
} else if (cmd_action == EN_AUTO_PS) {
psmode_enh->action = wlan_cpu_to_le16(EN_AUTO_PS);
psmode_enh->params.auto_ps.ps_bitmap =
@ -5298,6 +5473,46 @@ mlan_status wlan_cmd_func_init(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd)
return MLAN_STATUS_SUCCESS;
}
mlan_status wlan_adapter_func_init(pmlan_adapter pmadapter)
{
mlan_status ret;
pmlan_private priv = wlan_get_priv(pmadapter, MLAN_BSS_ROLE_ANY);
ENTER();
#if defined(SDIO)
/*
* This should be issued in the very first to config
* SDIO_GPIO interrupt mode.
*/
if (IS_SD(pmadapter->card_type) &&
(wlan_set_sdio_gpio_int(priv) != MLAN_STATUS_SUCCESS)) {
ret = MLAN_STATUS_FAILURE;
goto done;
}
#endif
#ifdef PCIE
if (IS_PCIE(pmadapter->card_type) &&
(MLAN_STATUS_SUCCESS != wlan_set_pcie_buf_config(priv))) {
ret = MLAN_STATUS_FAILURE;
goto done;
}
#endif
ret = wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_INIT, HostCmd_ACT_GEN_SET,
0, MNULL, MNULL);
if (ret) {
ret = MLAN_STATUS_FAILURE;
goto done;
}
ret = MLAN_STATUS_PENDING;
done:
LEAVE();
return ret;
}
/**
* @brief This function issues adapter specific commands
* to initialize firmware
@ -5329,19 +5544,22 @@ mlan_status wlan_adapter_get_hw_spec(pmlan_adapter pmadapter)
#endif
#ifdef PCIE
if (IS_PCIE(pmadapter->card_type) &&
if (IS_PCIE(pmadapter->card_type) && !pmadapter->shc_secure_host &&
(MLAN_STATUS_SUCCESS != wlan_set_pcie_buf_config(priv))) {
ret = MLAN_STATUS_FAILURE;
goto done;
}
#endif
ret = wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_INIT, HostCmd_ACT_GEN_SET,
0, MNULL, MNULL);
if (ret) {
ret = MLAN_STATUS_FAILURE;
goto done;
if (!pmadapter->shc_secure_host) {
ret = wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_INIT,
HostCmd_ACT_GEN_SET, 0, MNULL, MNULL);
if (ret) {
ret = MLAN_STATUS_FAILURE;
goto done;
}
}
/** DPD data dnld cmd prepare */
if ((pmadapter->pdpd_data) && (pmadapter->dpd_data_len > 0)) {
ret = wlan_process_hostcmd_cfg(priv, CFG_TYPE_DPDFILE,
@ -6198,7 +6416,7 @@ mlan_status wlan_cmd_multi_chan_policy(pmlan_private pmpriv,
LEAVE();
return MLAN_STATUS_FAILURE;
}
policy = *((t_u16 *)pdata_buf);
policy = read_u16_unaligned(pmpriv->adapter, pdata_buf);
pmulti_chan_policy->policy = wlan_cpu_to_le16(policy);
PRINTM(MCMND, "Set multi-channel policy: %d\n", policy);
}
@ -6616,7 +6834,7 @@ mlan_status wlan_cmd_mac_control(pmlan_private pmpriv, HostCmd_DS_COMMAND *pcmd,
pcmd->size =
wlan_cpu_to_le16(sizeof(HostCmd_DS_MAC_CONTROL) + S_DS_GEN);
if (pdata_buf) {
action = *((t_u32 *)pdata_buf);
action = read_u32_unaligned(pmpriv->adapter, pdata_buf);
pmac->action = wlan_cpu_to_le32(action);
}
@ -6764,6 +6982,10 @@ mlan_status wlan_ret_get_hw_spec(pmlan_private pmpriv, HostCmd_DS_COMMAND *resp,
pmadapter->fw_bands |= BAND_AN;
if (!(pmadapter->fw_bands & BAND_G) && (pmadapter->fw_bands & BAND_GN))
pmadapter->fw_bands &= ~BAND_GN;
if (!(pmadapter->fw_bands & BAND_A) && (pmadapter->fw_bands & BAND_AAC))
pmadapter->fw_bands &= ~BAND_AAC;
if (!(pmadapter->fw_bands & BAND_G) && (pmadapter->fw_bands & BAND_GAC))
pmadapter->fw_bands &= ~BAND_GAC;
pmadapter->config_bands = pmadapter->fw_bands;
for (i = 0; i < pmadapter->priv_num; i++) {
@ -7265,7 +7487,7 @@ mlan_status wlan_cmd_wifi_direct_mode(pmlan_private pmpriv,
LEAVE();
return MLAN_STATUS_FAILURE;
}
mode = *((t_u16 *)pdata_buf);
mode = read_u16_unaligned(pmpriv->adapter, pdata_buf);
wfd_mode->mode = wlan_cpu_to_le16(mode);
}
LEAVE();
@ -9304,7 +9526,7 @@ mlan_status wlan_cmd_ps_inactivity_timeout(pmlan_private pmpriv,
LEAVE();
return MLAN_STATUS_FAILURE;
}
timeout = *((t_u16 *)pdata_buf);
timeout = read_u16_unaligned(pmpriv->adapter, pdata_buf);
ps_inact_tmo->inact_tmo = wlan_cpu_to_le16(timeout);
}
@ -9814,7 +10036,7 @@ static void wlan_fill_link_statistic(mlan_private *priv,
return;
}
*((t_u32 *)link_statistic) = num_radio;
write_u32_unaligned(priv->adapter, link_statistic, num_radio);
link_statistic += sizeof(num_radio);
/* Fill radio stats array*/
@ -10126,7 +10348,7 @@ mlan_status wlan_cmd_boot_sleep(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd,
LEAVE();
return MLAN_STATUS_FAILURE;
}
enable = *(t_u16 *)pdata_buf;
enable = read_u16_unaligned(pmpriv->adapter, pdata_buf);
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_BOOT_SLEEP);
boot_sleep = &cmd->params.boot_sleep;
boot_sleep->action = wlan_cpu_to_le16(cmd_action);
@ -10773,7 +10995,7 @@ mlan_status wlan_cmd_ips_config(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd,
LEAVE();
return MLAN_STATUS_FAILURE;
}
enable = *(t_u32 *)pdata_buf;
enable = read_u32_unaligned(pmpriv->adapter, pdata_buf);
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_IPS_CONFIG);
ips_cfg = &cmd->params.ips_cfg;
ips_cfg->enable = wlan_cpu_to_le32(enable);
@ -10896,6 +11118,45 @@ mlan_status wlan_cmd_tx_ampdu_prot_mode(pmlan_private pmpriv,
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepares command to enable/disable/force-enable
* preamble pwr boost feature
*
* @param pmpriv A pointer to mlan_private structure
* @param cmd A pointer to HostCmd_DS_COMMAND structure
* @param cmd_action the action: GET or SET
* @param pdata_buf A pointer to data buffer
* @return MLAN_STATUS_SUCCESS
*/
mlan_status wlan_cmd_preamble_pwr_boost(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action, t_void *pdata_buf)
{
HostCmd_DS_CMD_PREAMBLE_PWR_BOOST *cfg_cmd =
(HostCmd_DS_CMD_PREAMBLE_PWR_BOOST *)&cmd->params
.preamble_pwr_boost;
mlan_ds_misc_preamble_pwr_boost *cfg =
(mlan_ds_misc_preamble_pwr_boost *)pdata_buf;
ENTER();
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_PREAMBLE_PWR_BOOST);
cmd->size = wlan_cpu_to_le16(sizeof(HostCmd_DS_CMD_PREAMBLE_PWR_BOOST) +
S_DS_GEN);
cfg_cmd->action = wlan_cpu_to_le16(cmd_action);
if (cmd_action == HostCmd_ACT_GEN_SET) {
if (!cfg) {
LEAVE();
return MLAN_STATUS_FAILURE;
}
cfg_cmd->enable_mode = (t_u8)(cfg->enable_mode);
cfg_cmd->rssi_threshold = (t_s8)cfg->rssi_threshold;
}
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function handles the command response of Tx ampdu prot mode
*
@ -10925,6 +11186,37 @@ mlan_status wlan_ret_tx_ampdu_prot_mode(pmlan_private pmpriv,
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function handles the command response of preamble pwr boost
*
* @param pmpriv A pointer to mlan_private structure
* @param resp A pointer to HostCmd_DS_COMMAND
* @param pioctl_buf A pointer to mlan_ioctl_req structure
*
* @return MLAN_STATUS_SUCCESS
*/
mlan_status wlan_ret_preamble_pwr_boost(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf)
{
HostCmd_DS_CMD_PREAMBLE_PWR_BOOST *cfg_cmd =
(HostCmd_DS_CMD_PREAMBLE_PWR_BOOST *)&resp->params
.preamble_pwr_boost;
mlan_ds_misc_cfg *misc_cfg = MNULL;
ENTER();
if (pioctl_buf) {
misc_cfg = (mlan_ds_misc_cfg *)pioctl_buf->pbuf;
misc_cfg->param.preamble_pwr_boost.enable_mode =
(t_u8)(cfg_cmd->enable_mode);
misc_cfg->param.preamble_pwr_boost.rssi_threshold =
(t_s8)(cfg_cmd->rssi_threshold);
}
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepares command of Rate Adapt cfg
*
@ -11099,7 +11391,8 @@ mlan_status wlan_cmd_config_dyn_bw(pmlan_private pmpriv,
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_DYN_BW);
cmd->size = S_DS_GEN + sizeof(HostCmd_DS_DYN_BW);
dyn_bw_cmd->action = wlan_cpu_to_le16(cmd_action);
dyn_bw_cmd->dyn_bw = wlan_cpu_to_le16(*(t_u16 *)pdata_buf);
dyn_bw_cmd->dyn_bw = wlan_cpu_to_le16(
read_u16_unaligned(pmpriv->adapter, pdata_buf));
cmd->size = wlan_cpu_to_le16(cmd->size);
LEAVE();
@ -11142,13 +11435,17 @@ mlan_status wlan_ret_dyn_bw(pmlan_private pmpriv, HostCmd_DS_COMMAND *resp,
* @param pdata_buf A pointer to data buffer
* @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
*/
mlan_status wlan_cmd_get_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action, t_void *pdata_buf)
mlan_status wlan_cmd_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd, t_u16 cmd_action,
t_u32 cmd_oid, t_void *pdata_buf)
{
HostCmd_DS_CHANNEL_TRPC_CONFIG *trpc_cfg = &cmd->params.ch_trpc_config;
mlan_ds_misc_chan_trpc_cfg *cfg =
(mlan_ds_misc_chan_trpc_cfg *)pdata_buf;
mlan_ds_misc_per_band_txpwr_cap *cap =
(mlan_ds_misc_per_band_txpwr_cap *)pdata_buf;
MrvlIEtypes_per_band_txpwr_cap *tlv = MNULL;
t_u16 size = 0;
ENTER();
@ -11158,12 +11455,36 @@ mlan_status wlan_cmd_get_chan_trpc_config(pmlan_private pmpriv,
}
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_CHANNEL_TRPC_CONFIG);
trpc_cfg->action = wlan_cpu_to_le16(cmd_action);
cmd->size = wlan_cpu_to_le16(sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG) +
S_DS_GEN);
trpc_cfg->sub_band = wlan_cpu_to_le16(cfg->sub_band);
size = sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG) + S_DS_GEN;
if (cmd_oid == MLAN_OID_MISC_PER_BAND_TXPWR_CAP) {
if (MRVDRV_SIZE_OF_CMD_BUFFER <
(size + sizeof(MrvlIEtypes_per_band_txpwr_cap))) {
LEAVE();
return MLAN_STATUS_FAILURE;
}
tlv = (MrvlIEtypes_per_band_txpwr_cap
*)((t_u8 *)&cmd->params +
sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG));
tlv->header.type =
wlan_cpu_to_le16(TLV_TYPE_PER_BAND_TXPWR_CAP);
tlv->header.len = wlan_cpu_to_le16(
sizeof(MrvlIEtypes_per_band_txpwr_cap) -
sizeof(MrvlIEtypesHeader_t));
tlv->band = cap->band;
if (cmd_action == HostCmd_ACT_GEN_SET)
tlv->power = cap->power;
size += sizeof(MrvlIEtypes_per_band_txpwr_cap);
} else {
trpc_cfg->sub_band = wlan_cpu_to_le16(cfg->sub_band);
}
cmd->size = wlan_cpu_to_le16(size);
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepares command of LOW_POWER_MODE_CFG
*
@ -11186,7 +11507,7 @@ mlan_status wlan_cmd_set_get_low_power_mode_cfg(pmlan_private pmpriv,
LEAVE();
return MLAN_STATUS_FAILURE;
}
lpm = *(t_u16 *)pdata_buf;
lpm = read_u16_unaligned(pmpriv->adapter, pdata_buf);
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_LOW_POWER_MODE_CFG);
cmd->size = wlan_cpu_to_le16(sizeof(HostCmd_DS_LOW_POWER_MODE_CFG) +
@ -11239,24 +11560,51 @@ mlan_status wlan_ret_set_get_low_power_mode_cfg(pmlan_private pmpriv,
*
* @return MLAN_STATUS_SUCCESS
*/
mlan_status wlan_ret_get_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf)
mlan_status wlan_ret_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf)
{
mlan_ds_misc_cfg *misc = MNULL;
HostCmd_DS_CHANNEL_TRPC_CONFIG *trpc_cfg = &resp->params.ch_trpc_config;
mlan_ds_misc_chan_trpc_cfg *cfg = MNULL;
mlan_ds_misc_per_band_txpwr_cap *cap = MNULL;
MrvlIEtypesHeader_t *header = MNULL;
MrvlIEtypes_per_band_txpwr_cap *tlv = MNULL;
mlan_adapter *pmadapter = pmpriv->adapter;
t_u16 size = wlan_le16_to_cpu(resp->size) - S_DS_GEN;
ENTER();
if (pioctl_buf) {
misc = (mlan_ds_misc_cfg *)pioctl_buf->pbuf;
cfg = (mlan_ds_misc_chan_trpc_cfg *)&(misc->param.trpc_cfg);
cfg->sub_band = wlan_le16_to_cpu(trpc_cfg->sub_band);
cfg->length = resp->size;
memcpy_ext(pmadapter, cfg->trpc_buf, (t_u8 *)resp, cfg->length,
sizeof(cfg->trpc_buf));
if (size < (sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG) +
sizeof(MrvlIEtypesHeader_t)))
goto done;
header = (MrvlIEtypesHeader_t
*)((t_u8 *)&resp->params +
sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG));
if (wlan_le16_to_cpu(header->type) ==
TLV_TYPE_PER_BAND_TXPWR_CAP) {
if (size < (sizeof(HostCmd_DS_CHANNEL_TRPC_CONFIG) +
sizeof(MrvlIEtypes_per_band_txpwr_cap)))
goto done;
cap = (mlan_ds_misc_per_band_txpwr_cap *)&(
misc->param.per_band_txpwr_cap);
tlv = (MrvlIEtypes_per_band_txpwr_cap *)header;
cap->band = tlv->band;
cap->power = tlv->power;
} else {
cfg = (mlan_ds_misc_chan_trpc_cfg *)&(
misc->param.trpc_cfg);
cfg->sub_band = wlan_le16_to_cpu(trpc_cfg->sub_band);
cfg->length = resp->size;
memcpy_ext(pmadapter, cfg->trpc_buf, (t_u8 *)resp,
cfg->length, sizeof(cfg->trpc_buf));
}
}
done:
LEAVE();
return MLAN_STATUS_SUCCESS;
}
@ -11690,6 +12038,12 @@ mlan_status wlan_ret_get_sensor_temp(pmlan_private pmpriv,
return MLAN_STATUS_SUCCESS;
}
mlan_status wlan_process_secure_host_event(pmlan_private pmpriv, t_u8 *data,
t_u32 len)
{
return wlan_shc_process_secure_host_event(pmpriv, data, len);
}
/**
* @brief This function prepares command to configure edmac
*

View file

@ -477,6 +477,8 @@ typedef t_u8 mlan_802_11_mac_addr[MLAN_MAC_ADDR_LENGTH];
#define CARD_SDAW693 "SDAW693"
/** SDIW610 Card */
#define CARD_SDIW610 "SDIW610"
/** SDIW623 Card */
#define CARD_SDIW623 "SDIW623"
#endif
#ifdef PCIE
@ -522,6 +524,8 @@ typedef t_u8 mlan_802_11_mac_addr[MLAN_MAC_ADDR_LENGTH];
#define CARD_PCIEAW693 "PCIEAW693"
/** PCIEIW629 Card */
#define CARD_PCIEIW629 "PCIEIW629"
/** PCIEIW623 Card */
#define CARD_PCIEIW623 "PCIEIW623"
#endif
#ifdef USB
@ -683,6 +687,7 @@ typedef enum {
#define MFWDP_D MBIT(21)
#endif /*FWDUMP_VIA_PRINT*/
#define MSCH_D MBIT(22)
#define MSHC_D MBIT(23)
#define MENTRY MBIT(28)
#define MWARN MBIT(29)
#define MINFO MBIT(30)
@ -781,6 +786,29 @@ typedef struct _assoc_logger {
#define SCAN_STATE_EXT_SCAN_STATUS MBIT(9)
#define SCAN_STATE_SCAN_COMPLETE MBIT(10)
#ifdef UAP_SUPPORT
/* Agiled channel switch state */
typedef enum _agcs_state {
/** AGCS is desabled */
AGCS_STATE_IDLE = 0,
/** AGCS is enabled */
AGCS_STATE_START = 1,
/**When FW sends AGCS event to notify the driver to prepare for channel
switch.*/
AGCS_STATE_TRIGGERED = 2,
/** Start to scan the candidate channels */
AGCS_STATE_IN_SCAN = 3,
/** Receives the scan report */
AGCS_STATE_SCAN_REPORT = 4,
/** All candidate channels scanned done */
AGCS_STATE_SCAN_DONE = 5,
/** Start Channel Switch */
AGCS_STATE_CSA_START = 6,
/** Channel Switch Completed */
AGCS_STATE_COMPLETE = 7,
} agcs_state;
#endif /* UAP_SUPPORT */
#ifdef USB
/** mlan_usb_ep */
typedef enum _mlan_usb_ep {
@ -879,6 +907,10 @@ typedef enum _mlan_event_id {
#endif /* SSU_SUPPORT */
MLAN_EVENT_ID_CSI = 0x00000040,
MLAN_EVENT_ID_FW_TX_BULK_STATUS = 0x00000043,
#ifdef UAP_SUPPORT
/* Agiled channel switch triggered */
MLAN_EVENT_ID_FW_AGCS_TRIGGER = 0x00000044,
#endif /* UAP_SUPPORT */
/* Event generated by MLAN driver (MSB=1) */
MLAN_EVENT_ID_DRV_CONNECTED = 0x80000001,
MLAN_EVENT_ID_DRV_DEFER_HANDLING = 0x80000002,
@ -921,6 +953,7 @@ typedef enum _mlan_event_id {
MLAN_EVENT_ID_FW_CHAN_SWITCH_REGINFO = 0x80000038,
#endif
MLAN_EVENT_ID_DRV_ASSOC_FAILURE = 0x80000039,
MLAN_EVENT_ID_FW_WIFI_CHANNEL_AVOID_LIST = 0x8000003A,
MLAN_EVENT_ID_EMERGENCY_TEMP_REACHED = 0x80000040,
} mlan_event_id;
@ -1143,6 +1176,16 @@ typedef MLAN_PACK_START struct _chan_band_reginfo_t {
} MLAN_PACK_END chan_band_reginfo_t;
#endif
/** Structure to WiFi Channel Avoidance List */
typedef MLAN_PACK_START struct _wifi_chan_avoid_list_t {
/** Band Configuration */
Band_Config_t bandcfg;
/** Length */
t_u8 length;
/** Chanlist */
t_u8 chanList[];
} MLAN_PACK_END wifi_chan_avoid_list_t;
/** Channel usability flags */
#define NXP_CHANNEL_NO_OFDM MBIT(9)
#define NXP_CHANNEL_NO_CCK MBIT(8)
@ -2718,6 +2761,32 @@ typedef struct _mlan_callbacks {
t_s32 copy_delay);
mlan_status (*moal_calc_short_ssid)(t_u8 *pssid, t_u32 ssid_len,
t_u32 *pshort_ssid);
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);
/* Unaligned Access */
struct unaligned_access {
t_u16 (*moal_read_u16)(const void *src);
t_u32 (*moal_read_u32)(const void *src);
void (*moal_write_u16)(void *dest, t_u16 val);
void (*moal_write_u32)(void *dest, t_u32 val);
} moal_unaligned_access;
} mlan_callbacks, *pmlan_callbacks;
/** Parameter unchanged, use MLAN default setting */
@ -2897,6 +2966,7 @@ typedef struct _mlan_device {
t_u8 disable_11h_tpc;
t_u8 tpe_ie_ignore;
t_u32 amsdu_disable;
t_u32 secure_host;
} mlan_device, *pmlan_device;
/** MLAN API function prototype */

View file

@ -223,6 +223,11 @@ ENUM_ELEMENT(EVENT_DUMMY_HOST_WAKEUP_SIGNAL, 0x0001),
ENUM_ELEMENT(EVENT_EMERGENCY_TEMP_REACHED, 0x00A9),
#ifdef UAP_SUPPORT
/** Event ID: Agiled Channel Switch report */
ENUM_ELEMENT(EVENT_AGCS_REPORT, 0x00AA),
#endif /* UAP_SUPPORT */
ENUM_ELEMENT(EVENT_TSP_CONFIG, 0x00AB),
#if defined(PCIE) || defined(SDIO)
@ -230,5 +235,10 @@ ENUM_ELEMENT(EVENT_DUMMY_HOST_WAKEUP_SIGNAL, 0x0001),
ENUM_ELEMENT(EVENT_FW_IN_BAND_RESET, 0x00AD),
#endif
/** Event ID: WiFi uAP Channel Avoidance */
ENUM_ELEMENT(EVENT_WIFI_CHANNEL_AVOID_LIST, 0x00AF),
ENUM_ELEMENT(EVENT_SECURE_HOST_COMM, 0x00AE),
/* Always keep this last */
ENUM_ELEMENT_LAST(__HostEvent_Last)

View file

@ -933,6 +933,8 @@ enum host_cmd_id {
#define FW_CAPINFO_EASY_MESH MBIT(21)
/** FW cap info bit 22: ADDBA support with scan */
#define FW_CAPINFO_ALLOW_ADDBA_RESP_ON_SCAN MBIT(22)
/** FW cap info bit 23: MAC2 is not available */
#define FW_CAPINFO_EXT_NO_MAC2 MBIT(23)
/** Check if 5G 1x1 only is supported by firmware */
#define IS_FW_SUPPORT_5G_1X1_ONLY(_adapter) \
@ -1200,6 +1202,9 @@ typedef enum _ENH_PS_MODES {
EN_AUTO_PS = 0xff,
} ENH_PS_MODES;
/** Secure Host command, payload is encrypted*/
#define HostCmd_Encrypted_BIT 0x4000
/** Command RET code, MSB is set to 1 */
#define HostCmd_RET_BIT 0x8000
@ -2386,6 +2391,20 @@ typedef MLAN_PACK_START struct _HostCmd_DS_GTK_REKEY_PARAMS {
t_u32 replay_ctr_high;
} MLAN_PACK_END HostCmd_DS_GTK_REKEY_PARAMS;
typedef MLAN_PACK_START struct _SECURE_HOST_MSG_HEADER {
t_u32 magic;
t_u16 len;
t_u8 id;
t_u8 version;
} MLAN_PACK_END SECURE_HOST_MSG_HEADER;
typedef MLAN_PACK_START struct _HostCmd_DS_SECURE_HOST {
/** Action */
t_u16 action;
/** TLS handshake message data */
t_u8 tls_data[1024];
} MLAN_PACK_END HostCmd_DS_SECURE_HOST;
/** Data structure of WMM QoS information */
typedef MLAN_PACK_START struct _WmmQosInfo_t {
#ifdef BIG_ENDIAN_SUPPORT
@ -2520,8 +2539,6 @@ typedef MLAN_PACK_START struct _HostCmd_DS_CHANNEL_TRPC_CONFIG {
t_u16 action;
/** 0/1/2/3 */
t_u16 sub_band;
/** chan TRPC config */
// MrvlIETypes_ChanTRPCConfig_t tlv[];
} MLAN_PACK_END HostCmd_DS_CHANNEL_TRPC_CONFIG;
/** Address type: broadcast */
@ -3312,6 +3329,12 @@ typedef MLAN_PACK_START struct _HostCmd_DS_802_11_GET_LOG {
t_u32 TXpwrMethod;
/** DPD training status*/
t_u32 isDPDdone;
/*CCA count*/
t_u64 cca_cnt_us;
/*RX airtime count*/
t_u64 rxAirtime_us;
/*TX airtime count*/
t_u64 txAirtime_us;
} MLAN_PACK_END HostCmd_DS_802_11_GET_LOG;
/* maln wifi rate */
@ -7456,6 +7479,16 @@ typedef MLAN_PACK_START struct _HostCmd_DS_CMD_TX_AMPDU_PROT_MODE {
t_u16 mode;
} MLAN_PACK_END HostCmd_DS_CMD_TX_AMPDU_PROT_MODE;
/** HostCmd_CMD_PREAMBLE_PWR_BOOST */
typedef MLAN_PACK_START struct _HostCmd_DS_CMD_PREAMBLE_PWR_BOOST {
/** Action */
t_u16 action;
/** To force-enable/force-disable the preamble pwr boost feature*/
t_u8 enable_mode;
/** rssi pkt threshold */
t_s8 rssi_threshold;
} MLAN_PACK_END HostCmd_DS_CMD_PREAMBLE_PWR_BOOST;
/** HostCmd_DS_CMD_DOT11MC_UNASSOC_FTM_CFG */
typedef MLAN_PACK_START struct _HostCmd_DS_CMD_DOT11MC_UNASSOC_FTM_CFG {
/** Action */
@ -7560,7 +7593,7 @@ typedef MLAN_PACK_START struct _HostCmd_CMD_802_11_STA_TX_RATE {
/** actual number of entries in array */
t_u16 num_entries;
} HostCmd_CMD_802_11_STA_TX_RATE;
} MLAN_PACK_END HostCmd_CMD_802_11_STA_TX_RATE;
/** HostCmd_MCLIENT_SCHEDULE_CFG */
typedef MLAN_PACK_START struct _HostCmd_MCLIENT_SCHEDULE_CFG {
@ -7572,7 +7605,48 @@ typedef MLAN_PACK_START struct _HostCmd_MCLIENT_SCHEDULE_CFG {
/** enable PS mode change reporting */
t_u8 ps_mode_change_report;
} HostCmd_MCLIENT_SCHEDULE_CFG;
} MLAN_PACK_END HostCmd_MCLIENT_SCHEDULE_CFG;
#ifdef UAP_SUPPORT
/** HostCmd_DS_AGCS_CFG */
typedef MLAN_PACK_START struct _HostCmd_DS_AGCS_CFG {
/** action - get/set */
t_u16 action;
/* BIT0 - Enable Agile channel switching in CarPlay
* BIT1 - no specific interference type check, but only check Tx or Rx
* throughput drop
*/
t_u32 features;
/* Adjust the weight of TX/RX average packet count */
t_u8 avg_threshold_percentage;
/* The conservative amount of rx packet per second */
t_u16 rx_min_pkt_count;
/* The conservative amount of tx packet per second */
t_u16 tx_min_pkt_count;
/* Unit is ms */
t_u32 sample_time;
/* The latest sampled windows size */
t_u8 sample_count_window;
/* Continuous drop rapidly times */
t_u8 continuous_hit_count;
/* Make sure a reasonable rate can be sustained. */
t_s8 nf_margin;
/* Long duration packets threshold */
t_u16 nav_mitigation_th;
/* ch threshold to trigger channel switch for nighthawk */
t_u16 ch_th;
} MLAN_PACK_END HostCmd_DS_AGCS_CFG;
#endif /* UAP_SUPPORT */
/** HostCmd_DS_COMMAND */
typedef struct MLAN_PACK_START _HostCmd_DS_COMMAND {
@ -7836,6 +7910,7 @@ typedef struct MLAN_PACK_START _HostCmd_DS_COMMAND {
HostCmd_DS_CMD_NavMitigationHwCfg nav_mitigation_hw;
HostCmd_DS_CMD_LED_CFG ledcntrcfg;
HostCmd_DS_CMD_TX_AMPDU_PROT_MODE tx_ampdu_prot_mode;
HostCmd_DS_CMD_PREAMBLE_PWR_BOOST preamble_pwr_boost;
HostCmd_DS_CMD_RATE_ADAPT_CFG rate_adapt_cfg;
HostCmd_DS_CMD_CCK_DESENSE_CFG cck_desense_cfg;
/** trpc_config */
@ -7867,6 +7942,8 @@ typedef struct MLAN_PACK_START _HostCmd_DS_COMMAND {
HostCmd_CMD_802_11_STA_TX_RATE sta_rx_rate;
HostCmd_MCLIENT_SCHEDULE_CFG mclient_cfg;
HostCmd_DS_SECURE_HOST shc;
/** WMM HOST ADDTS */
HostCmd_DS_WMM_HOST_ADDTS_REQ host_add_ts;
/** WMM HOST DELTS */
@ -7874,6 +7951,10 @@ typedef struct MLAN_PACK_START _HostCmd_DS_COMMAND {
/** Auth, (Re)Assoc timeout configuration */
HostCmd_DS_AUTH_ASSOC_TIMEOUT_CFG auth_assoc_cfg;
t_u8 assoc_rsp_buf[ASSOC_RSP_BUF_SIZE];
#ifdef UAP_SUPPORT
/** Agiled channel switch configuration */
HostCmd_DS_AGCS_CFG agcs_cfg;
#endif /* UAP_SUPPORT */
} params;
} MLAN_PACK_END HostCmd_DS_COMMAND, *pHostCmd_DS_COMMAND;
@ -7915,6 +7996,16 @@ typedef MLAN_PACK_START struct _MrvlIEtypes_PsStaStatus_t {
t_u8 sleep;
} MLAN_PACK_END MrvlIEtypes_PsStaStatus_t;
/** per_band_txpwr_cap params */
typedef struct _MrvlIEtypes_per_band_txpwr_cap {
/** Header */
MrvlIEtypesHeader_t header;
/** band */
t_u8 band;
/** power value */
t_u8 power;
} MLAN_PACK_END MrvlIEtypes_per_band_txpwr_cap;
/** req host side download vdll block */
#define VDLL_IND_TYPE_REQ 0
/** notify vdll start offset in firmware image */
@ -7970,6 +8061,26 @@ typedef enum _BLOCK_6G_CHAN_SWITCH_REASON {
BLOCK_6G_CHAN_SWITCH_REASON_STA_RX_ECSA = 4,
} BLOCK_6G_CHAN_SWITCH_REASON;
#ifdef UAP_SUPPORT
/** FW trigger the agiled channel switch */
#define AGCS_TYPE_CS_TRIGGER 0
/** FW send current channel statistics */
#define AGCS_TYPE_STATS_REPORT 1
/* Fw agcs statistics structure */
typedef MLAN_PACK_START struct _agcs_stats_info_t {
/** This is STATS_REPORT or CS_TRIGGER */
t_u16 type;
/** Channel utilization in the last 100ms */
t_u16 ch_load;
/** noise in the last 100ms */
t_s16 noise;
/** nf_threshold is used to check the noise floor of candidate channels
*/
t_s16 nf_threshold;
} MLAN_PACK_END agcs_stats_info_t;
#endif /* UAP_SUPPORT */
#ifdef PRAGMA_PACK
#pragma pack(pop)
#endif
@ -7979,4 +8090,19 @@ typedef MLAN_PACK_START struct _Event_DPD_CAL_t {
t_u8 sub_band;
} MLAN_PACK_END Event_DPD_CAL_t;
typedef MLAN_PACK_START struct _SECURE_HOST_EVENT_HEADER {
/** Type ID */
t_u16 type_id;
t_u16 bbs;
/** Action */
t_u16 tls_action;
} MLAN_PACK_END SECURE_HOST_EVENT_HEADER;
typedef MLAN_PACK_START struct SECURE_HOST_EVENT {
/** TLS handshake message header */
SECURE_HOST_EVENT_HEADER tls_header;
/** TLS handshake message data */
t_u8 tls_data[];
} MLAN_PACK_END SECURE_HOST_EVENT;
#endif /* !_MLAN_FW_H_ */

View file

@ -482,6 +482,16 @@ ENUM_ELEMENT(HostCmd_CMD_GET_HW_SPEC, 0x0003),
/** Host Command ID : HS Event masking configuration */
ENUM_ELEMENT(HostCmd_CMD_HS_EVENT_MASK, 0x028a),
#ifdef UAP_SUPPORT
/** Host Command ID : Agiled channel switch configuration */
ENUM_ELEMENT(HostCmd_CMD_APCMD_AGCS_CFG, 0x0293),
#endif
ENUM_ELEMENT(HostCmd_CMD_NAV_MITIGATION_HW_CFG, 0x0294),
ENUM_ELEMENT(HostCmd_CMD_SECURE_HOST, 0x0295),
/** Host Command ID : To enable/disable/force-enable PPB feature */
ENUM_ELEMENT(HostCmd_CMD_PREAMBLE_PWR_BOOST, 0x0296),
/* Always keep this last */
ENUM_ELEMENT_LAST(__HostCmd_CMD_Last)

View file

@ -255,6 +255,10 @@ mlan_status wlan_allocate_adapter(pmlan_adapter pmadapter)
max_mp_regs = pmadapter->pcard_sd->reg->max_mp_regs;
mp_tx_aggr_buf_size = pmadapter->pcard_sd->mp_tx_aggr_buf_size;
mp_rx_aggr_buf_size = pmadapter->pcard_sd->mp_rx_aggr_buf_size;
mp_rx_aggr_buf_size = MIN(pmadapter->pcard_sd->max_seg_size,
mp_rx_aggr_buf_size);
mp_tx_aggr_buf_size = MIN(pmadapter->pcard_sd->max_seg_size,
mp_tx_aggr_buf_size);
}
#endif
@ -1574,7 +1578,11 @@ mlan_status wlan_init_fw(pmlan_adapter pmadapter)
#ifdef MFG_CMD_SUPPORT
if (pmadapter->mfg_mode != MTRUE) {
#endif
wlan_adapter_get_hw_spec(pmadapter);
if (pmadapter->shc_secure_host) {
wlan_adapter_func_init(pmadapter);
} else {
wlan_adapter_get_hw_spec(pmadapter);
}
#ifdef MFG_CMD_SUPPORT
}
#ifdef PCIE
@ -1584,7 +1592,9 @@ mlan_status wlan_init_fw(pmlan_adapter pmadapter)
goto done;
}
}
if (((pmadapter->card_type) & 0xff) == CARD_TYPE_AW693) {
if (((pmadapter->card_type) & 0xff) == CARD_TYPE_AW693 &&
(!pmadapter->shc_secure_host)) {
ret = wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_INIT,
HostCmd_ACT_GEN_SET, 0, MNULL, MNULL);
if (ret) {
@ -1644,7 +1654,10 @@ static void wlan_update_hw_spec(pmlan_adapter pmadapter)
pmadapter->fw_bands |= BAND_AN;
if (!(pmadapter->fw_bands & BAND_G) && (pmadapter->fw_bands & BAND_GN))
pmadapter->fw_bands &= ~BAND_GN;
if (!(pmadapter->fw_bands & BAND_A) && (pmadapter->fw_bands & BAND_AAC))
pmadapter->fw_bands &= ~BAND_AAC;
if (!(pmadapter->fw_bands & BAND_G) && (pmadapter->fw_bands & BAND_GAC))
pmadapter->fw_bands &= ~BAND_GAC;
pmadapter->config_bands = pmadapter->fw_bands;
for (i = 0; i < pmadapter->priv_num; i++) {
if (pmadapter->priv[i]) {

View file

@ -397,7 +397,11 @@ enum _mlan_ioctl_req_id {
MLAN_OID_MISC_PREV_ASSOC_INFO = 0x0020009A,
MLAN_OID_MISC_NAV_MITIGATION_HW = 0x0020009C,
MLAN_OID_MISC_PREAMBLE_PWR_BOOST = 0x0020009D,
MLAN_OID_MISC_PER_BAND_TXPWR_CAP = 0x0020009E,
#ifdef UAP_SUPPORT
MLAN_OID_MISC_AGCS_CONFIG = 0x0020009F,
#endif /* UAP_SUPPORT */
};
/** Sub command size */
@ -1863,6 +1867,12 @@ typedef struct _mlan_ds_get_stats {
t_u32 TXpwrMethod;
/** DPD training status*/
t_u32 isDPDdone;
/*CCA count*/
t_u64 cca_cnt_us;
/*RX airtime count*/
t_u64 rxAirtime_us;
/*TX airtime count*/
t_u64 txAirtime_us;
} mlan_ds_get_stats, *pmlan_ds_get_stats;
/** Type definition of mlan_ds_uap_stats for MLAN_OID_GET_STATS */
@ -4953,6 +4963,16 @@ typedef struct _mlan_ds_misc_tx_ampdu_prot_mode {
t_u16 mode;
} mlan_ds_misc_tx_ampdu_prot_mode;
/** Type definition of mlan_ds_misc_preamble_pwr_boost
* for MLAN_OID_MISC_PREAMBLE_PWR_BOOST
*/
typedef struct _mlan_ds_misc_preamble_pwr_boost {
/** To force-enable/force-disable the preamble pwr boost feature*/
t_u8 enable_mode;
/** rssi threshold */
t_s8 rssi_threshold;
} mlan_ds_misc_preamble_pwr_boost;
/** Type definition of mlan_ds_misc_dot11mc_unassoc_ftm_cfg
* for MLAN_OID_MISC_DOT11MC_UNASSOC_FTM_CFG
*/
@ -6556,6 +6576,14 @@ typedef struct _mlan_ds_ed_mac_cfg {
t_u32 ed_bitmap_txq_lock;
} mlan_ds_ed_mac_cfg;
/** per_band_txpwr_cap params */
typedef struct _mlan_ds_misc_per_band_txpwr_cap {
/** power value */
t_u8 power;
/** band */
t_u8 band;
} mlan_ds_misc_per_band_txpwr_cap;
/** valid range for mlan_ds_auth_assoc_timeout_cfg */
#define AUTH_TIMEOUT_MIN 500
#define AUTH_TIMEOUT_MAX 2400
@ -6586,6 +6614,37 @@ typedef struct _mlan_ds_auth_assoc_timeout_cfg {
t_u16 retry_timeout;
} mlan_ds_auth_assoc_timeout_cfg;
#ifdef UAP_SUPPORT
/** Agiled channel switch configuration parameters */
typedef struct _mlan_ds_agcs_cfg {
/**agcs cfg action 0-GET, 1-SET */
t_u16 action;
/* BIT0 - Enable Agile channel switching in CarPlay
* BIT1 - no specific interference type check, but only check Tx or Rx
* throughput drop
*/
t_u32 features;
/* Adjust the weight of TX/RX average packet count */
t_u8 avg_threshold_percentage;
/* The requires at least average rx packets per second */
t_u16 rx_min_pkt_count;
/* The requires at least average tx packets per second */
t_u16 tx_min_pkt_count;
/* Unit is ms */
t_u32 sample_time;
/* The latest sampled windows size */
t_u8 sample_count_window;
/* Continuous drop rapidly times */
t_u8 continuous_hit_count;
/* Make sure a reasonable rate can be sustained. */
t_s8 nf_margin;
/* Long duration packets threshold */
t_u16 nav_mitigation_th;
/* ch threshold to trigger channel switch for nighthawk */
t_u16 ch_th;
} mlan_ds_agcs_cfg;
#endif /* UAP_SUPPORT */
/** Type definition of mlan_ds_misc_cfg for MLAN_IOCTL_MISC_CFG */
typedef struct _mlan_ds_misc_cfg {
/** Sub-command */
@ -6732,6 +6791,7 @@ typedef struct _mlan_ds_misc_cfg {
mlan_ds_misc_nav_mitigation_hw nav_mitigation_hw;
mlan_ds_misc_led_cfg led_config;
mlan_ds_misc_tx_ampdu_prot_mode tx_ampdu_prot_mode;
mlan_ds_misc_preamble_pwr_boost preamble_pwr_boost;
mlan_ds_misc_rate_adapt_cfg rate_adapt_cfg;
mlan_ds_misc_cck_desense_cfg cck_desense_cfg;
mlan_ds_misc_chan_trpc_cfg trpc_cfg;
@ -6767,6 +6827,11 @@ typedef struct _mlan_ds_misc_cfg {
mlan_ds_ed_mac_cfg edmac_cfg;
mlan_ds_gpio_cfg_ops gpio_cfg_ops;
mlan_ds_auth_assoc_timeout_cfg auth_assoc_cfg;
mlan_ds_misc_per_band_txpwr_cap per_band_txpwr_cap;
#ifdef UAP_SUPPORT
/** config AGCS for MLAN_OID_MISC_AGCS_CONFIG */
mlan_ds_agcs_cfg agcs_cfg;
#endif /* UAP_SUPPORT */
} param;
} mlan_ds_misc_cfg, *pmlan_ds_misc_cfg;
@ -6805,4 +6870,34 @@ typedef struct _mlan_cfpinfo {
#define MLAN_REASON_CLASS3_FRAME_FROM_NOASSOC_STA 7
#define MLAN_REASON_DISASSOC_STA_HAS_LEFT 8
#define MLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
#ifdef UAP_SUPPORT
/* Processing AGCS report */
#define AGCS_EVENT_TYPE_PROCESS_EVENT 1
/* After AGCS scan, select and switch to new channel */
#define AGCS_EVENT_TYPE_SEL_CHANNEL 2
/** Type definition of agcs_stats for agcs_event */
typedef struct _agcs_stats {
/** All STAs support ECS */
t_u8 all_sta_ecs;
/** All STAs support 6g */
t_u8 all_sta_6g;
/** ch_load of current channel */
t_u16 ch_load;
/** noise of current channel */
t_s16 noise;
/** The noise floor threshold currently used by fw */
t_s16 nf_threshold;
} agcs_stats, *pagcs_stats;
/** Type definition of agcs_event for WOAL_EVENT_AGCS */
typedef struct _agcs_event {
/** AGCS_EVENT_TYPE_PROCESS_EVENT or AGCS_EVENT_TYPE_SEL_CHANNEL */
t_u32 type;
/** AGCS stats info */
agcs_stats stats;
} agcs_event, *pagcs_event;
#endif /* UAP_SUPPORT */
#endif /* !_MLAN_IOCTL_H_ */

View file

@ -565,7 +565,7 @@ static int wlan_cmd_append_osen_ie(mlan_private *priv, t_u8 **ppbuffer)
* @param len Length of ie rsn_ie data after IE header
* @param return rsn_cap
*/
static t_u16 wlan_get_rsn_cap(t_u8 *data, t_u8 len)
static t_u16 wlan_get_rsn_cap(mlan_private *pmpriv, t_u8 *data, t_u8 len)
{
t_u16 rsn_cap = 0;
t_u16 *ptr;
@ -588,7 +588,8 @@ static t_u16 wlan_get_rsn_cap(t_u8 *data, t_u8 len)
*/
end_ptr = (t_u16 *)(data + len);
ptr = (t_u16 *)(data + sizeof(t_u16) + 4 * sizeof(t_u8));
pairwise_cipher_count = wlan_le16_to_cpu(*ptr);
pairwise_cipher_count =
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter, ptr));
ptr = (t_u16 *)(data + sizeof(t_u16) + 4 * sizeof(t_u8) +
sizeof(t_u16) +
pairwise_cipher_count * PAIRWISE_CIPHER_SUITE_LEN);
@ -596,7 +597,8 @@ static t_u16 wlan_get_rsn_cap(t_u8 *data, t_u8 len)
PRINTM(MERROR, "RSNE: PAIRWISE_CIPHER not correct\n");
goto done;
}
akm_suite_count = wlan_le16_to_cpu(*ptr);
akm_suite_count =
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter, ptr));
ptr = (t_u16 *)(data + sizeof(t_u16) + 4 * sizeof(t_u8) +
sizeof(t_u16) +
pairwise_cipher_count * PAIRWISE_CIPHER_SUITE_LEN +
@ -605,7 +607,7 @@ static t_u16 wlan_get_rsn_cap(t_u8 *data, t_u8 len)
PRINTM(MERROR, "RSNE: AKM Suite or RSNCAP not correct\n");
goto done;
}
rsn_cap = wlan_le16_to_cpu(*ptr);
rsn_cap = wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter, ptr));
done:
PRINTM(MCMND, "rsn_cap=0x%x\n", rsn_cap);
@ -629,11 +631,11 @@ static t_u8 wlan_use_mfp(mlan_private *pmpriv, BSSDescriptor_t *pbss_desc)
if (pmpriv->wpa_ie[0] != RSN_IE)
return 0;
sta_rsn_cap =
wlan_get_rsn_cap(pmpriv->wpa_ie + 2, *(pmpriv->wpa_ie + 1));
sta_rsn_cap = wlan_get_rsn_cap(pmpriv, pmpriv->wpa_ie + 2,
*(pmpriv->wpa_ie + 1));
if (!pbss_desc->prsn_ie)
return 0;
ap_rsn_cap = wlan_get_rsn_cap(pbss_desc->prsn_ie->data,
ap_rsn_cap = wlan_get_rsn_cap(pmpriv, pbss_desc->prsn_ie->data,
pbss_desc->prsn_ie->ieee_hdr.len);
ap_mfpc = ((ap_rsn_cap & (0x1 << MFPC_BIT)) == (0x1 << MFPC_BIT));
ap_mfpr = ((ap_rsn_cap & (0x1 << MFPR_BIT)) == (0x1 << MFPR_BIT));
@ -730,7 +732,8 @@ static int wlan_update_rsn_ie(mlan_private *pmpriv,
ptr = ptlv_rsn_ie->rsn_ie + sizeof(t_u16) + 4 * sizeof(t_u8);
pairwise_cipher_count_ptr = ptr;
pairwise_cipher_count = wlan_le16_to_cpu(*(t_u16 *)ptr);
pairwise_cipher_count =
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter, ptr));
ptr += sizeof(t_u16);
if ((pairwise_cipher_count == 0) ||
@ -776,7 +779,8 @@ static int wlan_update_rsn_ie(mlan_private *pmpriv,
*/
ptr = ptlv_rsn_ie->rsn_ie + sizeof(t_u16) + 4 * sizeof(t_u8) +
sizeof(t_u16) + pairwise_cipher_count * PAIRWISE_CIPHER_SUITE_LEN;
akm_suite_count = wlan_le16_to_cpu(*(t_u16 *)ptr);
akm_suite_count =
wlan_le16_to_cpu(read_u16_unaligned(pmpriv->adapter, ptr));
ptr += sizeof(t_u16); // move pointer to AKM suite
if ((akm_suite_count == 0) || (ptr + AKM_SUITE_LEN * akm_suite_count +
@ -873,7 +877,8 @@ static int wlan_update_rsn_ie(mlan_private *pmpriv,
// PMKID
ptr += sizeof(t_u16);
if (end_ptr >= (ptr + sizeof(t_u16))) {
pmkid_count = wlan_le16_to_cpu(*(t_u16 *)ptr);
pmkid_count = wlan_le16_to_cpu(
read_u16_unaligned(pmpriv->adapter, ptr));
ptr += sizeof(t_u16);
if (pmkid_count &&
@ -890,24 +895,25 @@ static int wlan_update_rsn_ie(mlan_private *pmpriv,
/* Compose new RSNE */
// pairwiase
ptr = pairwise_cipher_count_ptr;
*(t_u16 *)ptr = wlan_cpu_to_le16(1);
write_u16_unaligned(pmadapter, ptr, wlan_cpu_to_le16(1));
ptr += sizeof(t_u16);
oui[3] = cipher_selected_id;
*(t_u32 *)ptr = *(t_u32 *)oui;
write_u32_unaligned(pmadapter, ptr, *(t_u32 *)oui);
ptr += PAIRWISE_CIPHER_SUITE_LEN;
// akm
*(t_u16 *)ptr = wlan_cpu_to_le16(1);
write_u16_unaligned(pmadapter, ptr, wlan_cpu_to_le16(1));
ptr += sizeof(t_u16);
oui[3] = akm_type_id;
*(t_u32 *)ptr = *(t_u32 *)oui;
write_u32_unaligned(pmadapter, ptr, *(t_u32 *)oui);
ptr += AKM_SUITE_LEN;
// RSNCAP
*(t_u16 *)ptr = wlan_cpu_to_le16(*prsn_cap);
write_u16_unaligned(pmadapter, ptr, wlan_cpu_to_le16(*prsn_cap));
ptr += sizeof(t_u16);
// PMKID list
if (pmkid_list_ptr || group_mgmt_cipher_suite_ptr) {
// Add PMKID
*(t_u16 *)ptr = wlan_cpu_to_le16(pmkid_count);
write_u16_unaligned(pmadapter, ptr,
wlan_cpu_to_le16(pmkid_count));
ptr += sizeof(t_u16);
if (pmkid_count) {
memcpy_ext(pmadapter, ptr, (t_u8 *)pmkid_list_ptr,
@ -960,10 +966,12 @@ t_u8 wlan_ft_akm_is_used(mlan_private *pmpriv, t_u8 *rsn_ie)
* PAIRWISE_CIPHER_SUITE_LEN (4) + 2 bytes akm_suite_count +
* akm_suite_count * AKM_SUITE_LEN (4)
*/
count = *(t_u16 *)(rsn_ie + 2 + 2 + 4 * sizeof(t_u8));
count = read_u16_unaligned(pmadapter,
rsn_ie + 2 + 2 + 4 * sizeof(t_u8));
pairwise_cipher_count = wlan_le16_to_cpu(count);
count = *(t_u16 *)(rsn_ie + 2 + 2 + 4 * sizeof(t_u8) + sizeof(t_u16) +
pairwise_cipher_count * 4);
count = read_u16_unaligned(
pmadapter, rsn_ie + 2 + 2 + 4 * sizeof(t_u8) + sizeof(t_u16) +
pairwise_cipher_count * 4);
akm_suite_count = wlan_le16_to_cpu(count);
temp = (t_u8 *)(rsn_ie + 2 + sizeof(t_u16) + 4 * sizeof(t_u8) +
sizeof(t_u16) + pairwise_cipher_count * 4 +
@ -1063,6 +1071,7 @@ mlan_status wlan_cmd_802_11_associate(mlan_private *pmpriv,
IEEEtypes_CapInfo_t *pcap_info;
t_u8 ft_akm = 0;
t_u8 oper_class;
t_u8 global_oper_class;
t_u8 oper_class_flag = MFALSE;
t_u8 akm_type = 0;
MrvlIEtypes_HostMlme_t *host_mlme_tlv = MNULL;
@ -1473,7 +1482,8 @@ mlan_status wlan_cmd_802_11_associate(mlan_private *pmpriv,
pmpriv,
pbss_desc->phy_param_set.ds_param_set
.current_chan,
pbss_desc->curr_bandwidth, &oper_class))
pbss_desc->curr_bandwidth, &oper_class,
&global_oper_class))
wlan_add_supported_oper_class_ie(pmpriv, &pos,
oper_class);
}
@ -1857,7 +1867,8 @@ mlan_status wlan_ret_802_11_associate(mlan_private *pmpriv,
"ASSOC_RESP: Association Failed, "
"status code = %d, error = 0x%x, a_id = 0x%x\n",
passoc_rsp->status_code,
wlan_le16_to_cpu(*(t_u16 *)&passoc_rsp->capability),
wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, &passoc_rsp->capability)),
wlan_le16_to_cpu(passoc_rsp->a_id));
memset(pmadapter, event_buf, 0, sizeof(event_buf));
pevent->bss_index = pmpriv->bss_index;
@ -2064,8 +2075,9 @@ done:
if (ret != MLAN_STATUS_SUCCESS) {
if (passoc_rsp->status_code)
pioctl_req->status_code =
(wlan_le16_to_cpu(*(t_u16 *)&passoc_rsp
->capability)
(wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter,
&passoc_rsp->capability))
<< 16) +
passoc_rsp->status_code;
else

View file

@ -30,6 +30,8 @@ Change log:
#ifndef _MLAN_MAIN_H_
#define _MLAN_MAIN_H_
#include "nanotls-host.h"
#ifdef DEBUG_LEVEL1
extern t_void (*print_callback)(t_pvoid pmoal_handle, t_u32 level,
char *pformat, IN...);
@ -610,9 +612,9 @@ extern t_void (*assert_callback)(t_void *pmoal_handle, t_u32 cond);
#define MIN_BA_THRESHOLD 16
/** High threshold at which to start drop packets */
#define RX_HIGH_THRESHOLD 1024
#define RX_HIGH_THRESHOLD 8192
/** Low threshold to allow Rx BA */
#define RX_LOW_THRESHOLD 128
#define RX_LOW_THRESHOLD 1024
#define MFG_CMD_SET_TEST_MODE 1
#define MFG_CMD_UNSET_TEST_MODE 0
@ -707,6 +709,7 @@ typedef enum _WLAN_HARDWARE_STATUS {
WlanHardwareStatusReady,
WlanHardwareStatusGetHwSpec,
WlanHardwareStatusGetHwSpecdone,
WlanHardwareStatusSecHandshake,
WlanHardwareStatusInitializing,
WlanHardwareStatusInitdone,
WlanHardwareStatusReset,
@ -1651,8 +1654,6 @@ struct _sta_node {
IEEEtypes_HTInfo_t HTInfo;
/** peer BSSCO_20_40*/
IEEEtypes_2040BSSCo_t BSSCO_20_40;
/*Extended capability*/
IEEEtypes_ExtCap_t ExtCap;
/*RSN IE*/
IEEEtypes_Generic_t rsn_ie;
/**Link ID*/
@ -1684,6 +1685,10 @@ struct _sta_node {
t_u8 vendor_oui[VENDOR_OUI_LEN * MAX_VENDOR_OUI_NUM];
/** vendor OUI count */
t_u8 vendor_oui_count;
/* Support operating class IE */
IEEEtypes_Generic_t OperClass;
/*Extended capability*/
IEEEtypes_ExtCap_t ExtCap;
};
/** 802.11h State information kept in the 'mlan_adapter' driver structure */
@ -3115,7 +3120,7 @@ struct _mlan_adapter {
/** LLDE enable/disable */
t_u8 llde_enabled;
/** LLDE modes 0 - default; 1 - carplay; 2 - gameplay; 3 - sound bar, 4
* <EFBFBD> validation, 5- event driven */
* - validation, 5- event driven */
t_u8 llde_mode;
/** high priority data packet type. 0: All traffic, 1: ping, 2: TCP ACK,
* 4: TCP Data, 8: UDP */
@ -3131,6 +3136,12 @@ struct _mlan_adapter {
/** iPhone device list */
t_u8 llde_iphonefilters[MAX_IPHONE_FILTER_ENTRIES *
MLAN_MAC_ADDR_LENGTH];
#ifdef UAP_SUPPORT
/** agiled channel switch info */
agcs_stats agcs_info;
#endif /* UAP_SUPPORT */
t_u32 shc_secure_host;
};
/** IPv4 ARP request header */
@ -3407,7 +3418,8 @@ t_void wlan_cancel_pending_ioctl(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req);
/**Cancel bss pending ioctl */
t_void wlan_cancel_bss_pending_cmd(pmlan_adapter pmadapter, t_u32 bss_index);
/** cancel pending BA commands */
t_void wlan_cancel_pending_ba_commands(pmlan_private priv);
/** Insert command to free queue */
t_void wlan_insert_cmd_to_free_q(mlan_adapter *pmadapter,
cmd_ctrl_node *pcmd_node);
@ -4025,6 +4037,12 @@ mlan_status wlan_cmd_tx_ampdu_prot_mode(pmlan_private pmpriv,
mlan_status wlan_ret_tx_ampdu_prot_mode(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf);
mlan_status wlan_cmd_preamble_pwr_boost(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action, t_void *pdata_buf);
mlan_status wlan_ret_preamble_pwr_boost(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf);
mlan_status wlan_cmd_dot11mc_unassoc_ftm_cfg(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action,
@ -4073,6 +4091,8 @@ mlan_status wlan_misc_ioctl_led(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req);
mlan_status wlan_misc_ioctl_tx_ampdu_prot_mode(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req);
mlan_status wlan_misc_ioctl_preamble_pwr_boost(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req);
mlan_status wlan_misc_ioctl_dot11mc_unassoc_ftm_cfg(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req);
mlan_status wlan_misc_ioctl_rate_adapt_cfg(pmlan_adapter pmadapter,
@ -4542,7 +4562,8 @@ mlan_status wlan_ret_boot_sleep(pmlan_private pmpriv, HostCmd_DS_COMMAND *resp,
int wlan_add_supported_oper_class_ie(mlan_private *pmpriv, t_u8 **pptlv_out,
t_u8 curr_oper_class);
mlan_status wlan_get_curr_oper_class(mlan_private *pmpriv, t_u8 channel,
t_u8 bw, t_u8 *oper_class);
t_u8 bw, t_u8 *oper_class,
t_u8 *global_oper_class);
mlan_status wlan_check_operclass_validation(mlan_private *pmpriv, t_u8 channel,
t_u8 oper_class, t_u8 bandwidth);
mlan_status wlan_misc_ioctl_operclass_validation(pmlan_adapter pmadapter,
@ -4695,12 +4716,12 @@ mlan_status wlan_get_rgchnpwr_cfg(pmlan_adapter pmadapter,
mlan_ioctl_req *pioctl_req);
mlan_status wlan_get_chan_trpc_cfg(pmlan_adapter pmadapter,
mlan_ioctl_req *pioctl_req);
mlan_status wlan_cmd_get_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action, t_void *pdata_buf);
mlan_status wlan_ret_get_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf);
mlan_status wlan_cmd_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd, t_u16 cmd_action,
t_u32 cmd_oid, t_void *pdata_buf);
mlan_status wlan_ret_chan_trpc_config(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf);
mlan_status wlan_cmd_ps_inactivity_timeout(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
@ -4781,6 +4802,8 @@ mlan_status wlan_cmd_edmac_cfg(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd,
mlan_status wlan_misc_ioctl_country_code(pmlan_adapter pmadapter,
mlan_ioctl_req *pioctl_req);
mlan_status wlan_misc_ioctl_per_band_txpwr_cap(pmlan_adapter pmadapter,
mlan_ioctl_req *pioctl_req);
/** Get custom Fw data */
mlan_status wlan_get_custom_fw_data(pmlan_adapter pmadapter, t_u8 *pdata);
#ifdef PCIE
@ -4899,6 +4922,12 @@ typedef enum _delay_unit {
SEC,
} t_delay_unit;
enum tls_message_id {
TLS_HOST_HELLO = 1,
TLS_DEVICE_HELLO = 2,
TLS_HOST_FINISHED = 3,
};
/** delay function */
t_void wlan_delay_func(mlan_adapter *pmadapter, t_u32 delay, t_delay_unit u);
@ -5154,6 +5183,20 @@ t_bool wlan_secure_add(t_void *datain, t_s32 add, t_void *dataout,
t_bool wlan_secure_sub(t_void *datain, t_s32 sub, t_void *dataout,
data_type type);
/* Use these inline functions while accessing packed structure elements that are
* not aligned */
#define read_u16_unaligned(pmadapter, src) \
pmadapter->callbacks.moal_unaligned_access.moal_read_u16(src)
#define read_u32_unaligned(pmadapter, src) \
pmadapter->callbacks.moal_unaligned_access.moal_read_u32(src)
#define write_u16_unaligned(pmadapter, dest, val) \
pmadapter->callbacks.moal_unaligned_access.moal_write_u16(dest, val)
#define write_u32_unaligned(pmadapter, dest, val) \
pmadapter->callbacks.moal_unaligned_access.moal_write_u32(dest, val)
void wlan_wmm_contention_init(
mlan_private *mlan,
const IEEEtypes_WmmAcParameters_t ac_params[MAX_AC_QUEUES]);
@ -5177,4 +5220,10 @@ void wlan_delete_iPhone_entry(mlan_private *priv, t_u8 *mac);
extern void print_chan_switch_block_event(t_u16 reason_code);
mlan_status wlan_adapter_func_init(pmlan_adapter pmadapter);
mlan_status wlan_cmd_secure_host(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd,
t_pvoid pdata_buf);
mlan_status wlan_process_secure_host_event(pmlan_private pmpriv, t_u8 *data,
t_u32 len);
#endif /* !_MLAN_MAIN_H_ */

View file

@ -4170,6 +4170,8 @@ void wlan_check_sta_capability(pmlan_private priv, pmlan_buffer pevent,
(MrvlIEtypesHeader_t *)(pevent->pbuf + pevent->data_offset +
ASSOC_EVENT_FIX_SIZE);
MrvlIETypes_MgmtFrameSet_t *mgmt_tlv = MNULL;
IEEEtypes_ExtCap_t *pExtCap = MNULL;
IEEEtypes_Generic_t *pOperClass = MNULL;
ENTER();
while (tlv_buf_left >= (int)sizeof(MrvlIEtypesHeader_t)) {
@ -4365,6 +4367,57 @@ void wlan_check_sta_capability(pmlan_private priv, pmlan_buffer pevent,
priv->adapter, assoc_req_ie, ie_len,
&sta_ptr->multi_ap_ie);
#endif
pExtCap = (IEEEtypes_ExtCap_t *)
wlan_get_specific_ie(priv, assoc_req_ie,
ie_len,
EXT_CAPABILITY, 0);
if (pExtCap) {
memcpy_ext(
priv->adapter,
(t_u8 *)&sta_ptr->ExtCap,
pExtCap,
pExtCap->ieee_hdr.len +
sizeof(IEEEtypes_Header_t),
sizeof(IEEEtypes_ExtCap_t));
sta_ptr->ExtCap.ieee_hdr.len = MIN(
pExtCap->ieee_hdr.len,
sizeof(IEEEtypes_ExtCap_t) -
sizeof(IEEEtypes_Header_t));
PRINTM(MCMND,
"Check STA capab mac_addr" MACSTR
" ExtChanSwitching:%d\n",
MAC2STR(sta_ptr->mac_addr),
sta_ptr->ExtCap.ext_cap
.ExtChanSwitching);
} else {
PRINTM(MCMND,
"STA doesn't support EXT_CAPABILITY\n");
}
pOperClass = (IEEEtypes_Generic_t *)
wlan_get_specific_ie(priv, assoc_req_ie,
ie_len,
REGULATORY_CLASS,
0);
if (pOperClass) {
memcpy_ext(
priv->adapter,
(t_u8 *)&sta_ptr->OperClass,
pOperClass,
pOperClass->ieee_hdr.len +
sizeof(MrvlIEtypesHeader_t),
sizeof(IEEEtypes_Generic_t));
sta_ptr->OperClass.ieee_hdr.len = MIN(
pOperClass->ieee_hdr.len,
sizeof(IEEEtypes_Generic_t) -
sizeof(IEEEtypes_Header_t));
PRINTM(MCMND,
"Check STA capab OperClass:%d",
sta_ptr->OperClass.data[0]);
} else {
PRINTM(MCMND,
"STA doesn't support REGULATORY_CLASS\n");
}
break;
}
}
@ -7273,6 +7326,41 @@ mlan_status wlan_get_chan_trpc_cfg(pmlan_adapter pmadapter,
return ret;
}
/**
* @brief Get/Set per_band_txpwr_cap
*
* @param pmadapter A pointer to mlan_adapter structure
* @param pioctl_req A pointer to ioctl request buffer
*
* @return MLAN_STATUS_PENDING --success, otherwise fail
*/
mlan_status wlan_misc_ioctl_per_band_txpwr_cap(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req)
{
pmlan_private pmpriv = pmadapter->priv[pioctl_req->bss_index];
mlan_ds_misc_cfg *misc = (mlan_ds_misc_cfg *)pioctl_req->pbuf;
mlan_status ret = MLAN_STATUS_SUCCESS;
t_u16 cmd_action = 0;
ENTER();
if (pioctl_req->action == MLAN_ACT_GET)
cmd_action = HostCmd_ACT_GEN_GET;
else
cmd_action = HostCmd_ACT_GEN_SET;
/* Send request to firmware */
ret = wlan_prepare_cmd(pmpriv, HostCmd_CMD_CHANNEL_TRPC_CONFIG,
cmd_action, misc->sub_command,
(t_void *)pioctl_req,
(t_void *)&misc->param.per_band_txpwr_cap);
if (ret == MLAN_STATUS_SUCCESS)
ret = MLAN_STATUS_PENDING;
LEAVE();
return ret;
}
/**
* @brief Get non-global operating class
*
@ -7286,7 +7374,7 @@ mlan_status wlan_misc_ioctl_oper_class(pmlan_adapter pmadapter,
{
pmlan_private pmpriv = pmadapter->priv[pioctl_req->bss_index];
mlan_ds_misc_cfg *misc = MNULL;
t_u8 channel, bandwidth, oper_class = 0;
t_u8 channel, bandwidth, oper_class = 0, global_oper_class = 0;
mlan_status ret = MLAN_STATUS_SUCCESS;
ENTER();
@ -7310,7 +7398,7 @@ mlan_status wlan_misc_ioctl_oper_class(pmlan_adapter pmadapter,
if (pioctl_req->action == MLAN_ACT_GET) {
ret = wlan_get_curr_oper_class(pmpriv, channel, bandwidth,
&oper_class);
&oper_class, &global_oper_class);
misc->param.bw_chan_oper.oper_class = oper_class;
} else {
PRINTM(MERROR, "Unsupported cmd_action\n");
@ -7821,6 +7909,37 @@ mlan_status wlan_misc_ioctl_tx_ampdu_prot_mode(pmlan_adapter pmadapter,
return ret;
}
/**
* @brief Preamble Pwr Boost Enablement
*
* @param pmadapter A pointer to mlan_adapter structure
* @param pioctl_req A pointer to ioctl request buffer
*
* @return MLAN_STATUS_PENDING --success, otherwise fail
*/
mlan_status wlan_misc_ioctl_preamble_pwr_boost(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req)
{
mlan_private *pmpriv = pmadapter->priv[pioctl_req->bss_index];
mlan_ds_misc_cfg *pmisc = (mlan_ds_misc_cfg *)pioctl_req->pbuf;
mlan_status ret = MLAN_STATUS_SUCCESS;
t_u16 cmd_action = 0;
ENTER();
if (pioctl_req->action == MLAN_ACT_SET)
cmd_action = HostCmd_ACT_GEN_SET;
else
cmd_action = HostCmd_ACT_GEN_GET;
ret = wlan_prepare_cmd(pmpriv, HostCmd_CMD_PREAMBLE_PWR_BOOST,
cmd_action, 0, (t_void *)pioctl_req,
&(pmisc->param.preamble_pwr_boost));
if (ret == MLAN_STATUS_SUCCESS)
ret = MLAN_STATUS_PENDING;
LEAVE();
return ret;
}
/**
* @brief Rate adapt config
*

View file

@ -951,17 +951,16 @@ static mlan_status wlan_pcie_send_vdll(mlan_adapter *pmadapter,
{
mlan_status ret = MLAN_STATUS_PENDING;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_u16 *tmp;
t_u8 *payload;
ENTER();
pmadapter->cmd_sent = MTRUE;
payload = pmbuf->pbuf + pmbuf->data_offset;
tmp = (t_u16 *)&payload[0];
*tmp = wlan_cpu_to_le16((t_u16)pmbuf->data_len);
tmp = (t_u16 *)&payload[2];
*tmp = wlan_cpu_to_le16(MLAN_TYPE_VDLL);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pmbuf->data_len));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_VDLL));
if (MLAN_STATUS_FAILURE ==
pcb->moal_map_memory(
@ -2528,7 +2527,6 @@ static mlan_status wlan_pcie_send_data(mlan_adapter *pmadapter, t_u8 type,
pmlan_callbacks pcb = &pmadapter->callbacks;
t_u32 rxbd_val = 0;
t_u32 wrindx;
t_u16 *tmp;
t_u8 *payload;
t_u32 wr_ptr_start = 0;
@ -2565,10 +2563,10 @@ static mlan_status wlan_pcie_send_data(mlan_adapter *pmadapter, t_u8 type,
pmadapter->data_sent = MTRUE;
payload = pmbuf->pbuf + pmbuf->data_offset;
tmp = (t_u16 *)&payload[0];
*tmp = wlan_cpu_to_le16((t_u16)pmbuf->data_len);
tmp = (t_u16 *)&payload[2];
*tmp = wlan_cpu_to_le16(type);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pmbuf->data_len));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(type));
/* Map pmbuf, and attach to tx ring */
if (MLAN_STATUS_FAILURE ==
@ -3180,9 +3178,11 @@ static mlan_status wlan_pcie_process_recv_data(mlan_adapter *pmadapter)
/* Get data length from interface header -
first 2 bytes are len, second 2 bytes are type */
rx_len = *((t_u16 *)(pmbuf->pbuf + pmbuf->data_offset));
rx_len = read_u16_unaligned(pmadapter,
pmbuf->pbuf + pmbuf->data_offset);
rx_len = wlan_le16_to_cpu(rx_len);
rx_type = *((t_u16 *)(pmbuf->pbuf + pmbuf->data_offset + 2));
rx_type = read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset + 2);
rx_type = wlan_le16_to_cpu(rx_type);
PRINTM(MINFO,
@ -3319,8 +3319,10 @@ static mlan_status wlan_pcie_send_cmd(mlan_adapter *pmadapter,
pmadapter->cmd_sent = MTRUE;
payload = pmbuf->pbuf + pmbuf->data_offset;
*(t_u16 *)&payload[0] = wlan_cpu_to_le16((t_u16)pmbuf->data_len);
*(t_u16 *)&payload[2] = wlan_cpu_to_le16(MLAN_TYPE_CMD);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pmbuf->data_len));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_CMD));
pcb = &pmadapter->callbacks;
if (MLAN_STATUS_FAILURE ==
@ -3430,7 +3432,7 @@ static void mlan_delay_for_sleep_cookie(mlan_adapter *pmadapter,
for (count = 0; count < max_delay_loop_cnt; count++) {
buffer = pmbuf->pbuf;
sleep_cookie = *(t_u32 *)buffer;
sleep_cookie = read_u32_unaligned(pmadapter, buffer);
if (sleep_cookie == MLAN_SLEEP_COOKIE_DEF) {
PRINTM(MINFO, "sleep cookie FOUND at count = %d!!\n",
@ -3473,10 +3475,12 @@ static mlan_status wlan_pcie_process_cmd_resp(mlan_adapter *pmadapter)
/* Get data length from interface header -
first 2 bytes are len, second 2 bytes are type */
resp_len = *((t_u16 *)(pmbuf->pbuf + pmbuf->data_offset));
resp_len =
read_u16_unaligned(pmadapter, pmbuf->pbuf + pmbuf->data_offset);
pmadapter->upld_len = wlan_le16_to_cpu(resp_len);
pmadapter->upld_len -= PCIE_INTF_HEADER_LEN;
wlan_secure_sub(&pmadapter->upld_len, PCIE_INTF_HEADER_LEN,
&pmadapter->upld_len, TYPE_UINT32);
cmd_buf = pmadapter->pcard_pcie->cmd_buf;
if (cmd_buf) {
pcb->moal_unmap_memory(pmadapter->pmoal_handle,
@ -3739,11 +3743,13 @@ static mlan_status wlan_pcie_process_event_ready(mlan_adapter *pmadapter)
return MLAN_STATUS_FAILURE;
}
event = *((t_u32 *)&pmbuf_evt->pbuf[pmbuf_evt->data_offset +
event = read_u32_unaligned(
pmadapter, &pmbuf_evt->pbuf[pmbuf_evt->data_offset +
PCIE_INTF_HEADER_LEN]);
/* The first 4bytes will be the event transfer header
len is 2 bytes followed by type which is 2 bytes */
evt_len = *((t_u16 *)&pmbuf_evt->pbuf[pmbuf_evt->data_offset]);
evt_len = read_u16_unaligned(
pmadapter, &pmbuf_evt->pbuf[pmbuf_evt->data_offset]);
evt_len = wlan_le16_to_cpu(evt_len);
if ((evt_len > 0) && (evt_len > MLAN_EVENT_HEADER_LEN) &&
@ -5491,7 +5497,6 @@ static mlan_status wlan_pcie_send_data_list(mlan_adapter *pmadapter, t_u8 type,
{
pmlan_buffer pmbuf;
t_u16 *tmp;
t_u8 *payload;
t_u8 i;
ENTER();
@ -5524,10 +5529,10 @@ static mlan_status wlan_pcie_send_data_list(mlan_adapter *pmadapter, t_u8 type,
/* first pkt */
if (i == 0) {
payload = pmbuf->pbuf + pmbuf->data_offset;
tmp = (t_u16 *)&payload[0];
*tmp = wlan_cpu_to_le16((t_u16)pkt_size);
tmp = (t_u16 *)&payload[2];
*tmp = wlan_cpu_to_le16(type);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pkt_size));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(type));
wlan_pcie_send_adma_data(pmadapter, pmbuf,
ADMA_BD_FLAG_SOP, pkt_size);
} else if (i == (num_pkt - 1)) { /* last pkt */

View file

@ -1948,6 +1948,7 @@ static mlan_status wlan_scan_setup_scan_config(
if (pmpriv->adapter->ecsa_enable) {
t_u8 bandwidth = BW_20MHZ;
t_u8 oper_class = 1;
t_u8 global_oper_class = 0;
t_u32 usr_dot_11n_dev_cap;
if (pmpriv->media_connected) {
if (pmpriv->config_bands & BAND_A)
@ -1966,7 +1967,7 @@ static mlan_status wlan_scan_setup_scan_config(
wlan_get_curr_oper_class(
pmpriv,
pmpriv->curr_bss_params.bss_descriptor.channel,
bandwidth, &oper_class);
bandwidth, &oper_class, &global_oper_class);
}
wlan_add_supported_oper_class_ie(pmpriv, &ptlv_pos, oper_class);
}
@ -6147,6 +6148,7 @@ mlan_status wlan_ret_802_11_scan_ext(mlan_private *pmpriv,
pmadapter->scan_state |= SCAN_STATE_SCAN_COMPLETE;
pmadapter->ext_scan_type = EXT_SCAN_DEFAULT;
wlan_release_cmd_lock(pmadapter);
wlan_move_cmd_to_cmd_pending_q(pmadapter);
/* Need to indicate IOCTL complete */
if (pioctl_req != MNULL) {
pioctl_req->status_code = MLAN_STATUS_SUCCESS;
@ -8697,6 +8699,7 @@ mlan_status wlan_cmd_bgscan_config(mlan_private *pmpriv,
t_u8 bandwidth = BW_20MHZ;
t_u8 oper_class = 1;
t_u32 usr_dot_11n_dev_cap;
t_u8 global_oper_class = 0;
if (pmpriv->media_connected) {
if (pmpriv->config_bands & BAND_A)
usr_dot_11n_dev_cap =
@ -8714,7 +8717,7 @@ mlan_status wlan_cmd_bgscan_config(mlan_private *pmpriv,
wlan_get_curr_oper_class(
pmpriv,
pmpriv->curr_bss_params.bss_descriptor.channel,
bandwidth, &oper_class);
bandwidth, &oper_class, &global_oper_class);
}
len = wlan_add_supported_oper_class_ie(pmpriv, &tlv,
oper_class);

View file

@ -885,7 +885,8 @@ static mlan_status wlan_sdio_card_to_host(mlan_adapter *pmadapter, t_u32 *type,
}
}
} while (ret == MLAN_STATUS_FAILURE);
*nb = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf + pmbuf->data_offset));
*nb = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset));
if (*nb > npayload) {
PRINTM(MERROR, "invalid packet, *nb=%d, npayload=%d\n", *nb,
npayload);
@ -897,8 +898,8 @@ static mlan_status wlan_sdio_card_to_host(mlan_adapter *pmadapter, t_u32 *type,
DBG_HEXDUMP(MIF_D, "SDIO Blk Rd", pmbuf->pbuf + pmbuf->data_offset,
MIN(*nb, MAX_DATA_DUMP_LEN));
*type = wlan_le16_to_cpu(
*(t_u16 *)(pmbuf->pbuf + pmbuf->data_offset + 2));
*type = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset + 2));
exit:
LEAVE();
@ -1327,7 +1328,7 @@ static mlan_status wlan_decode_rx_packet(mlan_adapter *pmadapter,
&offset, TYPE_UINT32)) {
PRINTM(MERROR, "offset is invalid\n");
}
event = *(t_u32 *)&pmbuf->pbuf[offset];
event = read_u32_unaligned(pmadapter, &pmbuf->pbuf[offset]);
pmadapter->event_cause = wlan_le32_to_cpu(event);
if ((pmadapter->upld_len > MLAN_EVENT_HEADER_LEN) &&
((pmadapter->upld_len - MLAN_EVENT_HEADER_LEN) <
@ -1484,12 +1485,13 @@ static mlan_status wlan_receive_mp_aggr_buf(mlan_adapter *pmadapter)
pind++) {
mbuf_deaggr =
pmadapter->pcard_sd->mpa_rx.mbuf_arr[pind];
pkt_len = wlan_le16_to_cpu(
*(t_u16 *)(mbuf_deaggr->pbuf +
mbuf_deaggr->data_offset));
pkt_type = wlan_le16_to_cpu(
*(t_u16 *)(mbuf_deaggr->pbuf +
mbuf_deaggr->data_offset + 2));
pkt_len = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
mbuf_deaggr->pbuf + mbuf_deaggr->data_offset));
pkt_type = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, mbuf_deaggr->pbuf +
mbuf_deaggr->data_offset +
2));
pmadapter->upld_len = pkt_len;
wlan_decode_rx_packet(pmadapter, mbuf_deaggr, pkt_type,
MFALSE);
@ -1505,8 +1507,10 @@ static mlan_status wlan_receive_mp_aggr_buf(mlan_adapter *pmadapter)
for (pind = 0; pind < pmadapter->pcard_sd->mpa_rx.pkt_cnt;
pind++) {
/* get curr PKT len & type */
pkt_len = wlan_le16_to_cpu(*(t_u16 *)&curr_ptr[0]);
pkt_type = wlan_le16_to_cpu(*(t_u16 *)&curr_ptr[2]);
pkt_len = wlan_le16_to_cpu(
read_u16_unaligned(pmadapter, &curr_ptr[0]));
pkt_type = wlan_le16_to_cpu(
read_u16_unaligned(pmadapter, &curr_ptr[2]));
PRINTM(MINFO, "RX: [%d] pktlen: %d pkt_type: 0x%x\n",
pind, pkt_len, pkt_type);
@ -1959,7 +1963,8 @@ tx_curr_single:
pmadapter->pcard_sd
->last_mp_wr_info[pmadapter->pcard_sd->last_mp_index *
mp_aggr_pkt_limit] =
*(t_u16 *)(mbuf->pbuf + mbuf->data_offset);
read_u16_unaligned(pmadapter,
mbuf->pbuf + mbuf->data_offset);
pmadapter->pcard_sd
->last_curr_wr_port[pmadapter->pcard_sd->last_mp_index] =
pmadapter->pcard_sd->curr_wr_port;
@ -2874,8 +2879,9 @@ mlan_status wlan_sdio_host_to_card(mlan_adapter *pmadapter, t_u8 type,
/* Allocate buffer and copy payload */
blksz = pmadapter->pcard_sd->sdio_blk_size;
buf_block_len = (pmbuf->data_len + blksz - 1) / blksz;
*(t_u16 *)&payload[0] = wlan_cpu_to_le16((t_u16)pmbuf->data_len);
*(t_u16 *)&payload[2] = wlan_cpu_to_le16(type);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pmbuf->data_len));
write_u16_unaligned(pmadapter, &payload[2], wlan_cpu_to_le16(type));
/*
* This is SDIO specific header
@ -2963,8 +2969,10 @@ static mlan_status wlan_sdio_send_vdll(mlan_adapter *pmadapter,
blksz = pmadapter->pcard_sd->sdio_blk_size;
buf_block_len = (pmbuf->data_len + blksz - 1) / blksz;
*(t_u16 *)&payload[0] = wlan_cpu_to_le16((t_u16)pmbuf->data_len);
*(t_u16 *)&payload[2] = wlan_cpu_to_le16(MLAN_TYPE_VDLL);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16((t_u16)pmbuf->data_len));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_VDLL));
pmbuf->data_len = buf_block_len * blksz;
@ -3056,8 +3064,8 @@ void wlan_decode_spa_buffer(mlan_adapter *pmadapter, t_u8 *buf, t_u32 len)
block_num, total_pkt_len);
break;
}
pkt_len = wlan_le16_to_cpu(
*(t_u16 *)(data + OFFSET_OF_SDIO_HEADER));
pkt_len = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, data + OFFSET_OF_SDIO_HEADER));
if ((pkt_len + OFFSET_OF_SDIO_HEADER) > block_size) {
PRINTM(MERROR,
"Error in pkt, pkt_len=%d, block_size=%d\n",
@ -3191,6 +3199,9 @@ mlan_status wlan_alloc_sdio_mpa_buffers(mlan_adapter *pmadapter,
pmadapter->pcard_sd->mpa_rx.buf = MNULL;
}
pmadapter->pcard_sd->mpa_rx.buf_size = mpa_rx_buf_size;
PRINTM(MMSG, "wlan: mpa_rx.buf_size=%d\n",
pmadapter->pcard_sd->mpa_rx.buf_size);
error:
if (ret != MLAN_STATUS_SUCCESS)
wlan_free_sdio_mpa_buffers(pmadapter);
@ -3244,8 +3255,10 @@ mlan_status wlan_re_alloc_sdio_rx_mpa_buffer(mlan_adapter *pmadapter)
mlan_status ret = MLAN_STATUS_SUCCESS;
pmlan_callbacks pcb = &pmadapter->callbacks;
t_u32 buf_size = 0;
t_u32 mpa_rx_buf_size = pmadapter->pcard_sd->mp_rx_aggr_buf_size;
t_u8 mp_aggr_pkt_limit = pmadapter->pcard_sd->mp_aggr_pkt_limit;
t_u32 mpa_rx_buf_size = pmadapter->pcard_sd->mp_tx_aggr_buf_size;
mpa_rx_buf_size =
MIN(pmadapter->pcard_sd->max_seg_size, mpa_rx_buf_size);
if (pmadapter->pcard_sd->mpa_rx.buf) {
pcb->moal_mfree(pmadapter->pmoal_handle,
@ -3305,7 +3318,7 @@ mlan_status wlan_re_alloc_sdio_rx_mpa_buffer(mlan_adapter *pmadapter)
pmadapter->pcard_sd->mpa_rx.buf = MNULL;
}
pmadapter->pcard_sd->mpa_rx.buf_size = mpa_rx_buf_size;
PRINTM(MMSG, "mpa_rx_buf_size=%d\n", mpa_rx_buf_size);
PRINTM(MMSG, "realloc: mpa_rx_buf_size=%d\n", mpa_rx_buf_size);
error:
return ret;
}

View file

@ -4,7 +4,7 @@
* driver.
*
*
* Copyright 2008-2021 NXP
* Copyright 2008-2021, 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
@ -182,7 +182,8 @@ Change log:
mbuf->pbuf + mbuf->data_offset, mbuf->data_len); \
a->pcard_sd->mpa_tx.buf_len += mbuf->data_len; \
a->pcard_sd->mpa_tx.mp_wr_info[a->pcard_sd->mpa_tx.pkt_cnt] = \
*(t_u16 *)(mbuf->pbuf + mbuf->data_offset); \
read_u16_unaligned(pmadapter, \
mbuf->pbuf + mbuf->data_offset); \
if (!a->pcard_sd->mpa_tx.pkt_cnt) { \
a->pcard_sd->mpa_tx.start_port = port; \
} \
@ -194,7 +195,8 @@ Change log:
do { \
a->pcard_sd->mpa_tx.buf_len += mbuf->data_len; \
a->pcard_sd->mpa_tx.mp_wr_info[a->pcard_sd->mpa_tx.pkt_cnt] = \
*(t_u16 *)(mbuf->pbuf + mbuf->data_offset); \
read_u16_unaligned(pmadapter, \
mbuf->pbuf + mbuf->data_offset); \
a->pcard_sd->mpa_tx.mbuf_arr[a->pcard_sd->mpa_tx.pkt_cnt] = \
mbuf; \
if (!a->pcard_sd->mpa_tx.pkt_cnt) { \

329
mlan/mlan_shc.c Executable file
View file

@ -0,0 +1,329 @@
/** @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;
}

39
mlan/mlan_shc.h Executable file
View file

@ -0,0 +1,39 @@
/** @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

33
mlan/mlan_shc_key.h Executable file
View file

@ -0,0 +1,33 @@
/** @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

@ -319,6 +319,11 @@ mlan_status mlan_register(pmlan_device pmdevice, t_void **ppmlan_adapter)
MASSERT(pcb->moal_do_div);
MASSERT(pcb->moal_get_host_time_ns);
MASSERT(pcb->moal_unaligned_access.moal_read_u16);
MASSERT(pcb->moal_unaligned_access.moal_read_u32);
MASSERT(pcb->moal_unaligned_access.moal_write_u16);
MASSERT(pcb->moal_unaligned_access.moal_write_u32);
/* Save pmoal_handle */
pmadapter->pmoal_handle = pmdevice->pmoal_handle;
@ -542,6 +547,16 @@ mlan_status mlan_register(pmlan_device pmdevice, t_void **ppmlan_adapter)
(t_u8)pmdevice->bss_attr[0].bss_num;
}
pmadapter->shc_secure_host = pmdevice->secure_host;
if (pmadapter->second_mac && pmadapter->shc_secure_host) {
if (pcb->moal_secure_host_derive_traffic_keys(
pmadapter->pmoal_handle) ||
pcb->moal_secure_host_data_ctx_init(
pmadapter->pmoal_handle)) {
goto error;
}
}
/* init function table */
for (j = 0; mlan_ops[j]; j++) {
if (mlan_ops[j]->bss_role == GET_BSS_ROLE(pmadapter->priv[0])) {
@ -1658,9 +1673,9 @@ mlan_status mlan_send_packet(t_void *padapter, pmlan_buffer pmbuf)
if (pmbuf->data_offset > UINT32_MAX - MLAN_ETHER_PKT_TYPE_OFFSET)
return MLAN_STATUS_FAILURE;
eth_type =
mlan_ntohs(*(t_u16 *)&pmbuf->pbuf[pmbuf->data_offset +
MLAN_ETHER_PKT_TYPE_OFFSET]);
eth_type = mlan_ntohs(read_u16_unaligned(
pmadapter,
&pmbuf->pbuf[pmbuf->data_offset + MLAN_ETHER_PKT_TYPE_OFFSET]));
#ifdef UAP_SUPPORT
/** Identify ICMP packet from ETH_IP packet. ICMP packet in IP header
@ -1863,7 +1878,8 @@ mlan_status mlan_recv(t_void *padapter, pmlan_buffer pmbuf, t_u32 port)
len = pmbuf->data_len;
MASSERT(len >= MLAN_TYPE_LEN);
recv_type = *(t_u32 *)pbuf;
recv_type = read_u32_unaligned(pmadapter, pbuf);
;
recv_type = wlan_le32_to_cpu(recv_type);
pbuf += MLAN_TYPE_LEN;
len -= MLAN_TYPE_LEN;
@ -2044,9 +2060,9 @@ void mlan_process_deaggr_pkt(t_void *padapter, pmlan_buffer pmbuf, t_u8 *drop)
*drop = MFALSE;
pmpriv = pmadapter->priv[pmbuf->bss_index];
eth_type =
mlan_ntohs(*(t_u16 *)&pmbuf->pbuf[pmbuf->data_offset +
MLAN_ETHER_PKT_TYPE_OFFSET]);
eth_type = mlan_ntohs(read_u16_unaligned(
pmadapter,
&pmbuf->pbuf[pmbuf->data_offset + MLAN_ETHER_PKT_TYPE_OFFSET]));
switch (eth_type) {
case MLAN_ETHER_PKT_TYPE_EAPOL:
PRINTM(MEVENT, "Recevie AMSDU EAPOL frame\n");

View file

@ -191,7 +191,8 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u8));
ul_temp = *((t_u32 *)pdata_buf);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
psnmp_mib->value[0] = (t_u8)ul_temp;
cmd->size += sizeof(t_u8);
}
@ -202,9 +203,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *((t_u32 *)pdata_buf);
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -214,9 +216,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *((t_u32 *)pdata_buf);
*(t_u16 *)(psnmp_mib->value) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -227,9 +230,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = (*(t_u32 *)pdata_buf);
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -239,9 +243,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -251,9 +256,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -263,9 +269,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -275,9 +282,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -287,9 +295,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -299,9 +308,10 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *((t_u32 *)pdata_buf);
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
}
break;
@ -315,7 +325,8 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
psnmp_mib->query_type =
wlan_cpu_to_le16(HostCmd_ACT_GEN_SET);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u32));
ul_temp = *((t_u32 *)pdata_buf);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
ul_temp = wlan_cpu_to_le32(ul_temp);
memcpy_ext(pmpriv->adapter, psnmp_mib->value, &ul_temp,
sizeof(t_u32), sizeof(t_u32));
@ -369,7 +380,8 @@ static mlan_status wlan_cmd_802_11_snmp_mib(pmlan_private pmpriv,
PRINTM(MINFO,
"SNMP_CMD: Action=0x%x, OID=0x%x, OIDSize=0x%x, Value=0x%x\n",
cmd_action, cmd_oid, wlan_le16_to_cpu(psnmp_mib->buf_size),
wlan_le16_to_cpu(*(t_u16 *)psnmp_mib->value));
wlan_le16_to_cpu(
read_u16_unaligned(pmpriv->adapter, psnmp_mib->value)));
LEAVE();
return MLAN_STATUS_SUCCESS;
}
@ -1090,7 +1102,8 @@ static mlan_status wlan_cmd_802_11_sleep_period(pmlan_private pmpriv,
LEAVE();
return MLAN_STATUS_FAILURE;
}
pcmd_sleep_pd->sleep_pd = wlan_cpu_to_le16(*(t_u16 *)pdata_buf);
pcmd_sleep_pd->sleep_pd = wlan_cpu_to_le16(
read_u16_unaligned(pmpriv->adapter, pdata_buf));
}
pcmd_sleep_pd->action = wlan_cpu_to_le16(cmd_action);
@ -1755,8 +1768,8 @@ static mlan_status wlan_cmd_802_11_rf_channel(pmlan_private pmpriv,
}
prf_chan->rf_type.bandcfg.chanWidth =
pmpriv->adapter->chan_bandwidth;
prf_chan->current_channel =
wlan_cpu_to_le16(*((t_u16 *)pdata_buf));
prf_chan->current_channel = wlan_cpu_to_le16(
read_u16_unaligned(pmpriv->adapter, pdata_buf));
}
prf_chan->action = wlan_cpu_to_le16(cmd_action);
LEAVE();
@ -2084,7 +2097,9 @@ static mlan_status wlan_cmd_tdls_oper(pmlan_private pmpriv,
if (sta_ptr) {
ptdls_oper->tdls_action = wlan_cpu_to_le16(TDLS_CONFIG);
/*capability*/
*(t_u16 *)pos = wlan_cpu_to_le16(sta_ptr->capability);
write_u16_unaligned(
pmpriv->adapter, pos,
wlan_cpu_to_le16(sta_ptr->capability));
travel_len += sizeof(sta_ptr->capability);
/*supported rate*/
@ -3885,6 +3900,23 @@ static mlan_status wlan_cmd_auth_assoc_timeout_cfg(pmlan_private pmpriv,
return MLAN_STATUS_SUCCESS;
}
mlan_status wlan_cmd_secure_host(pmlan_private pmpriv, HostCmd_DS_COMMAND *cmd,
t_void *pdata_buf)
{
HostCmd_DS_SECURE_HOST *shc = &cmd->params.shc;
SECURE_HOST_MSG_HEADER *tls_hdr = (SECURE_HOST_MSG_HEADER *)pdata_buf;
t_u16 tls_len = tls_hdr->len;
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_SECURE_HOST);
cmd->size = wlan_cpu_to_le16(S_DS_GEN + sizeof(shc->action) + tls_len);
shc->action = 0x0;
memcpy_ext(pmpriv->adapter, (void *)&shc->tls_data, (void *)pdata_buf,
tls_len, tls_len);
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepare the command before sending to firmware.
*
@ -4060,7 +4092,7 @@ mlan_status wlan_ops_sta_prepare_cmd(t_void *priv, t_u16 cmd_no,
case HostCmd_CMD_VERSION_EXT:
cmd_ptr->command = wlan_cpu_to_le16(cmd_no);
cmd_ptr->params.verext.version_str_sel =
(t_u8)(*((t_u32 *)pdata_buf));
read_u32_unaligned(pmpriv->adapter, pdata_buf) & 0xff;
cmd_ptr->size = wlan_cpu_to_le16(
sizeof(HostCmd_DS_VERSION_EXT) + S_DS_GEN);
ret = MLAN_STATUS_SUCCESS;
@ -4070,7 +4102,8 @@ mlan_status wlan_ops_sta_prepare_cmd(t_void *priv, t_u16 cmd_no,
cmd_ptr->params.rx_mgmt_ind.action =
wlan_cpu_to_le16(cmd_action);
cmd_ptr->params.rx_mgmt_ind.mgmt_subtype_mask =
wlan_cpu_to_le32((t_u32)(*((t_u32 *)pdata_buf)));
wlan_cpu_to_le32(
read_u32_unaligned(pmpriv->adapter, pdata_buf));
cmd_ptr->size = wlan_cpu_to_le16(
sizeof(HostCmd_DS_RX_MGMT_IND) + S_DS_GEN);
break;
@ -4443,6 +4476,10 @@ mlan_status wlan_ops_sta_prepare_cmd(t_void *priv, t_u16 cmd_no,
ret = wlan_cmd_tx_ampdu_prot_mode(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
break;
case HostCmd_CMD_PREAMBLE_PWR_BOOST:
ret = wlan_cmd_preamble_pwr_boost(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
break;
case HostCmd_CMD_DOT11MC_UNASSOC_FTM_CFG:
ret = wlan_cmd_dot11mc_unassoc_ftm_cfg(pmpriv, cmd_ptr,
cmd_action, pdata_buf);
@ -4456,8 +4493,8 @@ mlan_status wlan_ops_sta_prepare_cmd(t_void *priv, t_u16 cmd_no,
pdata_buf);
break;
case HostCmd_CMD_CHANNEL_TRPC_CONFIG:
ret = wlan_cmd_get_chan_trpc_config(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
ret = wlan_cmd_chan_trpc_config(pmpriv, cmd_ptr, cmd_action,
cmd_oid, pdata_buf);
break;
case HostCmd_CMD_LOW_POWER_MODE_CFG:
ret = wlan_cmd_set_get_low_power_mode_cfg(
@ -4501,6 +4538,10 @@ mlan_status wlan_ops_sta_prepare_cmd(t_void *priv, t_u16 cmd_no,
ret = wlan_cmd_auth_assoc_timeout_cfg(pmpriv, cmd_ptr,
cmd_action, pdata_buf);
break;
case HostCmd_CMD_SECURE_HOST:
ret = wlan_cmd_secure_host(pmpriv, cmd_ptr, pdata_buf);
break;
default:
PRINTM(MERROR, "PREP_CMD: unknown command- %#x\n", cmd_no);
ret = MLAN_STATUS_FAILURE;

View file

@ -37,6 +37,7 @@
#include "mlan_11ax.h"
#include "mlan_11h.h"
#include "mlan_meas.h"
#include "mlan_shc.h"
/********************************************************
* Local Variables
@ -580,34 +581,39 @@ static mlan_status wlan_ret_802_11_snmp_mib(pmlan_private pmpriv,
mib->param.dtim_period = ul_temp;
break;
case FragThresh_i:
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MINFO, "SNMP_RESP: FragThsd =%u\n", ul_temp);
if (mib)
mib->param.frag_threshold = ul_temp;
break;
case RtsThresh_i:
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MINFO, "SNMP_RESP: RTSThsd =%u\n", ul_temp);
if (mib)
mib->param.rts_threshold = ul_temp;
break;
case ShortRetryLim_i:
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MINFO, "SNMP_RESP: TxRetryCount=%u\n", ul_temp);
if (mib)
mib->param.retry_count = ul_temp;
break;
case WwsMode_i:
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MINFO, "SNMP_RESP: WWSCfg =%u\n", ul_temp);
if (pioctl_buf)
((mlan_ds_misc_cfg *)pioctl_buf->pbuf)
->param.wws_cfg = ul_temp;
break;
case Thermal_i:
ul_temp = wlan_le32_to_cpu(*((t_u32 *)(psmib->value)));
ul_temp = wlan_le32_to_cpu(read_u32_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MINFO, "SNMP_RESP: Thermal =%u\n", ul_temp);
if (pioctl_buf)
((mlan_ds_misc_cfg *)pioctl_buf->pbuf)
@ -631,7 +637,8 @@ static mlan_status wlan_ret_802_11_snmp_mib(pmlan_private pmpriv,
} else { /* (query_type == HostCmd_ACT_GEN_SET) */
/* Update state for 11d */
if (oid == Dot11D_i) {
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
/* Set 11d state to private */
pmpriv->state_11d.enable_11d = ul_temp;
/* Set user enable flag if called from ioctl */
@ -640,7 +647,8 @@ static mlan_status wlan_ret_802_11_snmp_mib(pmlan_private pmpriv,
}
/* Update state for 11h */
if (oid == Dot11H_i) {
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MCMND, "wlan: Dot11H_i=%d\n", ul_temp);
/* Set 11h state to priv */
pmpriv->intf_state_11h.is_11h_active =
@ -656,21 +664,24 @@ static mlan_status wlan_ret_802_11_snmp_mib(pmlan_private pmpriv,
/* Update state for 11h tpc disable */
if (oid == Dot11h_disable_tpc_i) {
/* Set 11h tpc to private */
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MCMND, "SNMP_RESP: Dot11h_disable_tpc_i =%u\n",
ul_temp);
}
/* Update state for Tpe Ie Ignore */
if (oid == Ignore_tpe_i) {
/* Set tpe ie ignore to private */
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(read_u16_unaligned(
pmpriv->adapter, psmib->value));
PRINTM(MCMND, "SNMP_RESP: Ignore_tpe_i = %u\n",
ul_temp);
}
}
if (oid == User_band_config_i) {
ul_temp = wlan_le16_to_cpu(*((t_u16 *)(psmib->value)));
ul_temp = wlan_le16_to_cpu(
read_u16_unaligned(pmpriv->adapter, psmib->value));
PRINTM(MCMND, "SNMP_RESP: user defined bandcfg =0x%x\n",
ul_temp);
}
@ -822,6 +833,13 @@ static mlan_status wlan_ret_get_log(pmlan_private pmpriv,
pget_info->param.stats.isDPDdone =
wlan_le32_to_cpu(pget_log->isDPDdone);
pget_info->param.stats.cca_cnt_us =
wlan_le64_to_cpu(pget_log->cca_cnt_us);
pget_info->param.stats.rxAirtime_us =
wlan_le64_to_cpu(pget_log->rxAirtime_us);
pget_info->param.stats.txAirtime_us =
wlan_le64_to_cpu(pget_log->txAirtime_us);
if (pmpriv->adapter->getlog_enable) {
pget_info->param.stats.tx_frag_cnt =
wlan_le32_to_cpu(pget_log->tx_frag_cnt);
@ -3457,6 +3475,8 @@ mlan_status wlan_ops_sta_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
case HostCmd_CMD_FUNC_INIT:
case HostCmd_CMD_FUNC_SHUTDOWN:
break;
case HostCmd_CMD_SECURE_HOST:
break;
case HostCmd_CMD_802_11_KEY_MATERIAL:
ret = wlan_ret_802_11_key_material(pmpriv, resp, pioctl_buf);
break;
@ -3770,6 +3790,9 @@ mlan_status wlan_ops_sta_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
case HostCmd_CMD_TX_AMPDU_PROT_MODE:
ret = wlan_ret_tx_ampdu_prot_mode(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_PREAMBLE_PWR_BOOST:
ret = wlan_ret_preamble_pwr_boost(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_DOT11MC_UNASSOC_FTM_CFG:
ret = wlan_ret_dot11mc_unassoc_ftm_cfg(pmpriv, resp,
pioctl_buf);
@ -3787,7 +3810,7 @@ mlan_status wlan_ops_sta_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
ret = wlan_ret_cck_desense_cfg(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_CHANNEL_TRPC_CONFIG:
ret = wlan_ret_get_chan_trpc_config(pmpriv, resp, pioctl_buf);
ret = wlan_ret_chan_trpc_config(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_LOW_POWER_MODE_CFG:
ret = wlan_ret_set_get_low_power_mode_cfg(pmpriv, resp,

View file

@ -428,7 +428,7 @@ t_void wlan_reset_connect_state(pmlan_private priv, t_u8 drv_disconnect)
ENTER();
PRINTM(MINFO, "Handles disconnect event.\n");
wlan_cancel_pending_ba_commands(priv);
#ifdef UAP_SUPPORT
/* If DFS repeater mode is enabled and station interface disconnects
* then make sure that all uAPs are stopped.
@ -789,9 +789,9 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
"wlan: Receive deauth event in wps session\n");
break;
}
reason_code = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause)));
reason_code = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmbuf->pbuf + pmbuf->data_offset + sizeof(eventcause)));
PRINTM(MMSG, "wlan: EVENT: Deauthenticated (reason 0x%x)\n",
reason_code);
wlan_print_disconnect_reason(reason_code);
@ -807,9 +807,9 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
"wlan: Receive disassociate event in wps session\n");
break;
}
reason_code = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause)));
reason_code = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmbuf->pbuf + pmbuf->data_offset + sizeof(eventcause)));
PRINTM(MMSG, "wlan: EVENT: Disassociated (reason 0x%x)\n",
reason_code);
wlan_print_disconnect_reason(reason_code);
@ -870,9 +870,9 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
.mac_address));
break;
}
reason_code = wlan_le16_to_cpu(
*(t_u16 *)(pmbuf->pbuf + pmbuf->data_offset +
sizeof(eventcause)));
reason_code = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset +
sizeof(eventcause)));
PRINTM(MMSG, "wlan: EVENT: Link lost (reason 0x%x)\n",
reason_code);
pmpriv->disconnect_reason_code = reason_code;
@ -978,9 +978,9 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
break;
case EVENT_CHAN_SWITCH_TO_6G_BLOCK:
reason_code = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause)));
reason_code = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmbuf->pbuf + pmbuf->data_offset + sizeof(eventcause)));
print_chan_switch_block_event(reason_code);
break;
@ -1268,14 +1268,15 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
break;
case EVENT_AMSDU_AGGR_CTRL:
PRINTM(MEVENT, "EVENT: AMSDU_AGGR_CTRL %d\n",
*(t_u16 *)pmadapter->event_body);
read_u16_unaligned(pmadapter, pmadapter->event_body));
pmadapter->tx_buf_size =
MIN(pmadapter->curr_tx_buf_size,
wlan_le16_to_cpu(*(t_u16 *)pmadapter->event_body));
wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmadapter->event_body)));
if (pmbuf->data_len == sizeof(eventcause) + sizeof(t_u32)) {
enable = wlan_le16_to_cpu(
*(t_u16 *)(pmadapter->event_body +
sizeof(t_u16)));
enable = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmadapter->event_body + sizeof(t_u16)));
if (enable)
pmpriv->amsdu_disable = MFALSE;
else
@ -1341,7 +1342,8 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
case EVENT_REMAIN_ON_CHANNEL_EXPIRED:
PRINTM_NETINTF(MEVENT, pmpriv);
PRINTM(MEVENT, "EVENT: REMAIN_ON_CHANNEL_EXPIRED reason=%d\n",
*(t_u16 *)pmadapter->event_body);
read_u16_unaligned(pmpriv->adapter,
pmadapter->event_body));
pmpriv->adapter->remain_on_channel = MFALSE;
wlan_recv_event(pmpriv, MLAN_EVENT_ID_DRV_FLUSH_RX_WORK, MNULL);
wlan_recv_event(pmpriv, MLAN_EVENT_ID_FW_REMAIN_ON_CHAN_EXPIRED,
@ -1546,9 +1548,9 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
break;
}
PRINTM(MEVENT, "EVENT: EVENT_FW_HANG_REPORT reasoncode=%d\n",
wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause))));
wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset +
sizeof(eventcause))));
pmadapter->fw_hang_report = MTRUE;
wlan_recv_event(pmpriv, MLAN_EVENT_ID_DRV_DBG_DUMP, MNULL);
break;
@ -1646,6 +1648,24 @@ mlan_status wlan_ops_sta_process_event(t_void *priv)
PRINTM(MEVENT,
"Ignoring the Channel Switch Reg Info Event\n");
break;
case EVENT_WIFI_CHANNEL_AVOID_LIST:
PRINTM(MEVENT, "EVENT: EVENT_WIFI_CHANNEL_AVOID_LIST (%#x)\n",
eventcause);
pevent->event_id = MLAN_EVENT_ID_FW_WIFI_CHANNEL_AVOID_LIST;
pevent->bss_index = pmpriv->bss_index;
pevent->event_len = pmbuf->data_len;
memcpy_ext(pmadapter, (t_u8 *)pevent->event_buf,
pmbuf->pbuf + pmbuf->data_offset, pevent->event_len,
pevent->event_len);
DBG_HEXDUMP(MCMD_D, "WiFi channel avoid list",
(t_u8 *)pevent->event_buf, pevent->event_len);
wlan_recv_event(pmpriv, pevent->event_id, pevent);
break;
case EVENT_SECURE_HOST_COMM:
ret = wlan_process_secure_host_event(
pmpriv, pmbuf->pbuf + pmbuf->data_offset,
pmbuf->data_len);
break;
default:
PRINTM(MEVENT, "EVENT: unknown event id: %#x\n", eventcause);
wlan_recv_event(pmpriv, MLAN_EVENT_ID_FW_UNKNOWN, MNULL);

View file

@ -1570,12 +1570,12 @@ static mlan_status wlan_power_ioctl_set_power(pmlan_adapter pmadapter,
power = (mlan_ds_power_cfg *)pioctl_req->pbuf;
if (!power->param.power_cfg.is_power_auto) {
dbm = (t_s8)power->param.power_cfg.power_level;
if ((dbm < pmpriv->min_tx_power_level) ||
(dbm > pmpriv->max_tx_power_level)) {
/*min_power value does not change in fw, it keeps default
* value(24 dBm), check max_power limit only*/
if (dbm > pmpriv->max_tx_power_level) {
PRINTM(MERROR,
"The set txpower value %d dBm is out of range (%d dBm-%d dBm)!\n",
dbm, pmpriv->min_tx_power_level,
pmpriv->max_tx_power_level);
"The set txpower value %d dBm is greater than current possible max %d dBm\n",
dbm, pmpriv->max_tx_power_level);
pioctl_req->status_code = MLAN_ERROR_INVALID_PARAMETER;
ret = MLAN_STATUS_FAILURE;
goto exit;
@ -5317,6 +5317,10 @@ static mlan_status wlan_misc_cfg_ioctl(pmlan_adapter pmadapter,
status = wlan_misc_ioctl_tx_ampdu_prot_mode(pmadapter,
pioctl_req);
break;
case MLAN_OID_MISC_PREAMBLE_PWR_BOOST:
status = wlan_misc_ioctl_preamble_pwr_boost(pmadapter,
pioctl_req);
break;
case MLAN_OID_MISC_DOT11MC_UNASSOC_FTM_CFG:
status = wlan_misc_ioctl_dot11mc_unassoc_ftm_cfg(pmadapter,
pioctl_req);
@ -5371,6 +5375,10 @@ static mlan_status wlan_misc_cfg_ioctl(pmlan_adapter pmadapter,
status =
wlan_misc_auth_assoc_timeout_cfg(pmadapter, pioctl_req);
break;
case MLAN_OID_MISC_PER_BAND_TXPWR_CAP:
status = wlan_misc_ioctl_per_band_txpwr_cap(pmadapter,
pioctl_req);
break;
default:
if (pioctl_req)
pioctl_req->status_code = MLAN_ERROR_IOCTL_INVALID;

View file

@ -150,7 +150,8 @@ void wlan_process_tdls_action_frame(pmlan_private priv, t_u8 *pbuf, t_u32 len)
return;
pos = pbuf + sizeof(EthII_Hdr_t) + 4;
/*payload 1+ category 1 + action 1 +dialog 1*/
sta_ptr->capability = mlan_ntohs(*(t_u16 *)pos);
sta_ptr->capability =
mlan_ntohs(read_u16_unaligned(priv->adapter, pos));
ie_len = len - sizeof(EthII_Hdr_t) - TDLS_REQ_FIX_LEN;
pos += 2;
} else if (action == 1) { /*setup respons*/
@ -160,7 +161,8 @@ void wlan_process_tdls_action_frame(pmlan_private priv, t_u8 *pbuf, t_u32 len)
return;
pos = pbuf + sizeof(EthII_Hdr_t) + 6;
/*payload 1+ category 1 + action 1 +dialog 1 +status 2*/
sta_ptr->capability = mlan_ntohs(*(t_u16 *)pos);
sta_ptr->capability =
mlan_ntohs(read_u16_unaligned(priv->adapter, pos));
ie_len = len - sizeof(EthII_Hdr_t) - TDLS_RESP_FIX_LEN;
pos += 2;
} else { /*setup confirm*/

View file

@ -507,5 +507,7 @@
#define VENDOR_IE_OUIS_TLV_ID (PROPRIETARY_TLV_BASE_ID + 357) /* 0x0265 */
#define TLV_TYPE_AP_INFO (PROPRIETARY_TLV_BASE_ID + 358) /* 0x0266 */
#define TLV_TYPE_CSI_AGC_CONFIG (PROPRIETARY_TLV_BASE_ID + 363) /* 0x026b */
#define TLV_TYPE_PER_BAND_TXPWR_CAP (PROPRIETARY_TLV_BASE_ID + 365) /* 0x026d \
*/
#endif /* !MLAN_TLV_IDS_H_ */

View file

@ -1621,6 +1621,7 @@ static mlan_status wlan_uap_cmd_sys_configure(pmlan_private pmpriv,
MrvlIEtypes_chan_bw_oper_t *poper_class_tlv = MNULL;
t_u8 length = 0;
t_u8 curr_oper_class = 1;
t_u8 global_oper_class = 0;
t_u8 *oper_class_ie = (t_u8 *)sys_config->tlv_buffer;
t_u16 i = 0;
t_u8 ac = 0;
@ -1808,7 +1809,7 @@ static mlan_status wlan_uap_cmd_sys_configure(pmlan_private pmpriv,
poper_class_tlv->ds_chan_bw_oper.channel,
poper_class_tlv->ds_chan_bw_oper
.bandwidth,
&curr_oper_class);
&curr_oper_class, &global_oper_class);
if (ret != MLAN_STATUS_SUCCESS) {
PRINTM(MERROR,
"Can not get current oper class! bandwidth = %d, channel = %d\n",
@ -1841,7 +1842,8 @@ static mlan_status wlan_uap_cmd_sys_configure(pmlan_private pmpriv,
default:
PRINTM(MERROR,
"Wrong data, or missing TLV_TYPE 0x%04x handler.\n",
*(t_u16 *)pdata_buf);
read_u16_unaligned(pmpriv->adapter,
pdata_buf));
break;
}
goto done;
@ -2931,6 +2933,15 @@ static mlan_status wlan_uap_ret_sys_config(pmlan_private pmpriv,
cust_ie->type = wlan_le16_to_cpu(cust_ie->type);
resp_len = cust_ie->len =
wlan_le16_to_cpu(cust_ie->len);
if ((cust_ie->len > resp->size) ||
(cust_ie->len > (MAX_MGMT_IE_INDEX_TO_FW *
sizeof(custom_ie)))) {
PRINTM(MERROR,
"Unexpected cust_ie length: %d",
cust_ie->len);
LEAVE();
return MLAN_STATUS_FAILURE;
}
travel_len = 0;
/* conversion for index, mask, len */
if (resp_len == sizeof(t_u16))
@ -2951,6 +2962,15 @@ static mlan_status wlan_uap_ret_sys_config(pmlan_private pmpriv,
cptr->mgmt_subtype_mask);
cptr->ie_length = wlan_le16_to_cpu(
cptr->ie_length);
if (resp_len <
(cptr->ie_length +
sizeof(custom_ie) - MAX_IE_SIZE)) {
PRINTM(MERROR,
"Incorrect resp_len remained: %d",
resp_len);
LEAVE();
return MLAN_STATUS_FAILURE;
}
travel_len += cptr->ie_length +
sizeof(custom_ie) -
MAX_IE_SIZE;
@ -2964,6 +2984,16 @@ static mlan_status wlan_uap_ret_sys_config(pmlan_private pmpriv,
sizeof(MrvlIEtypesHeader_t),
sizeof(mlan_ds_misc_custom_ie) -
sizeof(tlvbuf_max_mgmt_ie));
// check if max_mgmt_ie present
if (resp->size <=
(sizeof(HostCmd_DS_GEN) + cust_ie->len +
sizeof(MrvlIEtypesHeader_t) +
sizeof(sys_config->action))) {
PRINTM(MINFO,
"max_mgmt_ie not available");
LEAVE();
return MLAN_STATUS_SUCCESS;
}
max_mgmt_ie =
(tlvbuf_max_mgmt_ie
*)(sys_config->tlv_buffer +
@ -2978,6 +3008,15 @@ static mlan_status wlan_uap_ret_sys_config(pmlan_private pmpriv,
wlan_le16_to_cpu(
max_mgmt_ie
->len);
if (max_mgmt_ie->len >
(sizeof(tlvbuf_max_mgmt_ie) -
sizeof(MrvlIEtypesHeader_t))) {
PRINTM(MERROR,
"Incorrect max_mgmt_ie lenght: %d",
max_mgmt_ie->len);
LEAVE();
return MLAN_STATUS_FAILURE;
}
max_mgmt_ie->count =
wlan_le16_to_cpu(
max_mgmt_ie
@ -3147,12 +3186,14 @@ static mlan_status wlan_uap_cmd_snmp_mib(pmlan_private pmpriv,
psnmp_oid = (t_u8 *)&puap_snmp_mib->snmp_data;
for (i = 0; i < sizeof(snmp_oids); i++) {
/* SNMP OID header type */
*(t_u16 *)psnmp_oid =
wlan_cpu_to_le16(snmp_oids[i]);
write_u16_unaligned(
pmpriv->adapter, psnmp_oid,
wlan_cpu_to_le16(snmp_oids[i]));
psnmp_oid += sizeof(t_u16);
/* SNMP OID header length */
*(t_u16 *)psnmp_oid =
wlan_cpu_to_le16(sizeof(t_u32));
write_u16_unaligned(
pmpriv->adapter, psnmp_oid,
wlan_cpu_to_le16(sizeof(t_u32)));
psnmp_oid += sizeof(t_u16) + sizeof(t_u32);
}
}
@ -3167,9 +3208,10 @@ static mlan_status wlan_uap_cmd_snmp_mib(pmlan_private pmpriv,
case Dot11h_disable_tpc_i:
psnmp_mib->oid = wlan_cpu_to_le16((t_u16)cmd_oid);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
break;
case ECSAEnable_i:
@ -3182,9 +3224,10 @@ static mlan_status wlan_uap_cmd_snmp_mib(pmlan_private pmpriv,
case User_band_config_i:
psnmp_mib->oid = wlan_cpu_to_le16((t_u16)cmd_oid);
psnmp_mib->buf_size = wlan_cpu_to_le16(sizeof(t_u16));
ul_temp = *(t_u32 *)pdata_buf;
*((t_u16 *)(psnmp_mib->value)) =
wlan_cpu_to_le16((t_u16)ul_temp);
ul_temp =
read_u32_unaligned(pmpriv->adapter, pdata_buf);
write_u16_unaligned(pmpriv->adapter, psnmp_mib->value,
wlan_cpu_to_le16((t_u16)ul_temp));
cmd->size += sizeof(t_u16);
break;
case StopDeauth_i:
@ -3307,7 +3350,8 @@ static mlan_status wlan_uap_ret_snmp_mib(pmlan_private pmpriv,
while (tlv_buf_left >= sizeof(MrvlIEtypes_snmp_oid_t)) {
/* oid_offset cannot overflow struct size */
// coverity[overflow_sink:SUPPRESS]
tlv_type = wlan_le16_to_cpu(*(t_u16 *)psnmp_oid);
tlv_type = wlan_le16_to_cpu(
read_u16_unaligned(pmadapter, psnmp_oid));
psnmp_oid += sizeof(t_u16) + sizeof(t_u16);
// coverity[cert_arr30_c_violation:SUPPRESS]
// coverity[overrun:SUPPRESS]
@ -3398,7 +3442,8 @@ static mlan_status wlan_uap_ret_snmp_mib(pmlan_private pmpriv,
} else { /* ACT_SET */
switch (wlan_le16_to_cpu(psnmp_mib->oid)) {
case Dot11D_i:
data = wlan_le16_to_cpu(*((t_u16 *)(psnmp_mib->value)));
data = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, psnmp_mib->value));
/* Set 11d state to private */
pmpriv->state_11d.enable_11d = data;
/* Set user enable flag if called from ioctl */
@ -3406,7 +3451,8 @@ static mlan_status wlan_uap_ret_snmp_mib(pmlan_private pmpriv,
pmpriv->state_11d.user_enable_11d = data;
break;
case Dot11H_i:
data = wlan_le16_to_cpu(*((t_u16 *)(psnmp_mib->value)));
data = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, psnmp_mib->value));
PRINTM(MCMND, "wlan: uap Dot11H_i=%d\n", data);
/* Set 11h state to priv */
pmpriv->intf_state_11h.is_11h_active =
@ -3561,6 +3607,12 @@ static mlan_status wlan_uap_ret_get_log(pmlan_private pmpriv,
wlan_le32_to_cpu(pget_log->TXpwrMethod);
pget_info->param.stats.isDPDdone =
wlan_le32_to_cpu(pget_log->isDPDdone);
pget_info->param.stats.cca_cnt_us =
wlan_le64_to_cpu(pget_log->cca_cnt_us);
pget_info->param.stats.rxAirtime_us =
wlan_le64_to_cpu(pget_log->rxAirtime_us);
pget_info->param.stats.txAirtime_us =
wlan_le64_to_cpu(pget_log->txAirtime_us);
if (pmpriv->adapter->getlog_enable) {
pget_info->param.stats.tx_frag_cnt =
@ -5042,6 +5094,242 @@ static mlan_status wlan_ret_stats(pmlan_private pmpriv,
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function handles the command response of uap agcs config
*
* @param pmpriv A pointer to mlan_private structure
* @param resp A pointer to HostCmd_DS_COMMAND
* @param pioctl_buf A pointer to mlan_ioctl_req structure
*
* @return MLAN_STATUS_SUCCESS
*/
static mlan_status wlan_uap_ret_agcs_cfg(pmlan_private pmpriv,
HostCmd_DS_COMMAND *resp,
mlan_ioctl_req *pioctl_buf)
{
HostCmd_DS_AGCS_CFG *pcmd_agcs_cfg =
(HostCmd_DS_AGCS_CFG *)&resp->params.agcs_cfg;
mlan_ds_misc_cfg *misc_cfg = MNULL;
mlan_ds_agcs_cfg *pagcs_cfg = MNULL;
ENTER();
if (pioctl_buf && pioctl_buf->action == MLAN_ACT_GET) {
misc_cfg = (mlan_ds_misc_cfg *)pioctl_buf->pbuf;
pagcs_cfg = (mlan_ds_agcs_cfg *)&misc_cfg->param.agcs_cfg;
pagcs_cfg->features = wlan_le32_to_cpu(pcmd_agcs_cfg->features);
pagcs_cfg->avg_threshold_percentage =
pcmd_agcs_cfg->avg_threshold_percentage;
pagcs_cfg->rx_min_pkt_count =
wlan_le16_to_cpu(pcmd_agcs_cfg->rx_min_pkt_count);
pagcs_cfg->tx_min_pkt_count =
wlan_le16_to_cpu(pcmd_agcs_cfg->tx_min_pkt_count);
pagcs_cfg->sample_time =
wlan_le32_to_cpu(pcmd_agcs_cfg->sample_time);
pagcs_cfg->sample_count_window =
pcmd_agcs_cfg->sample_count_window;
pagcs_cfg->continuous_hit_count =
pcmd_agcs_cfg->continuous_hit_count;
pagcs_cfg->nf_margin = pcmd_agcs_cfg->nf_margin;
pagcs_cfg->nav_mitigation_th = pcmd_agcs_cfg->nav_mitigation_th;
pagcs_cfg->ch_th = pcmd_agcs_cfg->ch_th;
}
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function prepares command of AGCS_CFG
*
* @param pmpriv A pointer to mlan_private structure
* @param cmd A pointer to HostCmd_DS_COMMAND structure
* @param cmd_action
* @param pdata_buf A pointer to data buffer
* @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
*/
static mlan_status wlan_cmd_apcmd_agcs_cfg(pmlan_private pmpriv,
HostCmd_DS_COMMAND *cmd,
t_u16 cmd_action, t_void *pdata_buf)
{
HostCmd_DS_AGCS_CFG *pcmd_agcs_cfg =
(HostCmd_DS_AGCS_CFG *)&cmd->params.agcs_cfg;
mlan_ds_agcs_cfg *pagcs_cfg = (mlan_ds_agcs_cfg *)pdata_buf;
ENTER();
cmd->command = wlan_cpu_to_le16(HostCmd_CMD_APCMD_AGCS_CFG);
cmd->size = wlan_cpu_to_le16(sizeof(HostCmd_CMD_APCMD_AGCS_CFG) +
S_DS_GEN + sizeof(HostCmd_DS_AGCS_CFG));
pcmd_agcs_cfg->action = wlan_cpu_to_le16(cmd_action);
pcmd_agcs_cfg->features = wlan_cpu_to_le32(pagcs_cfg->features);
pcmd_agcs_cfg->avg_threshold_percentage =
pagcs_cfg->avg_threshold_percentage;
pcmd_agcs_cfg->rx_min_pkt_count =
wlan_cpu_to_le32(pagcs_cfg->rx_min_pkt_count);
pcmd_agcs_cfg->tx_min_pkt_count =
wlan_cpu_to_le32(pagcs_cfg->tx_min_pkt_count);
pcmd_agcs_cfg->sample_time = wlan_cpu_to_le32(pagcs_cfg->sample_time);
pcmd_agcs_cfg->sample_count_window = pagcs_cfg->sample_count_window;
pcmd_agcs_cfg->continuous_hit_count = pagcs_cfg->continuous_hit_count;
pcmd_agcs_cfg->nf_margin = pagcs_cfg->nf_margin;
pcmd_agcs_cfg->nav_mitigation_th = pagcs_cfg->nav_mitigation_th;
pcmd_agcs_cfg->ch_th = pagcs_cfg->ch_th;
LEAVE();
return MLAN_STATUS_SUCCESS;
}
/**
* @brief This function handle the agiled cs event
*
* @param priv A pointer to mlan_private structure
* @param pbuf A pointer to mlan_buffer which has event content.
*
* @return MLAN_STATUS_SUCCESS
*/
static mlan_status wlan_process_agcs_event(pmlan_private priv,
pmlan_buffer pmbuf)
{
pmlan_adapter pmadapter = priv->adapter;
mlan_status status = MLAN_STATUS_SUCCESS;
t_u8 *evt_buf = MNULL;
pmlan_callbacks pcb = &pmadapter->callbacks;
pmlan_event pevent;
pagcs_event pacs_start_event = MNULL;
agcs_stats_info_t *stats = MNULL;
ENTER();
stats = (agcs_stats_info_t *)(pmbuf->pbuf + pmbuf->data_offset +
sizeof(t_u32));
if (stats->type == AGCS_TYPE_STATS_REPORT) {
PRINTM(MMSG,
"AGCS stats report ch_load=%d, noise=%d, nf_threshold=%d",
stats->ch_load, stats->noise, stats->nf_threshold);
goto done;
} else if (stats->type == AGCS_TYPE_CS_TRIGGER) {
/* Allocate memory for event buffer */
status = pcb->moal_malloc(pmadapter->pmoal_handle,
MAX_EVENT_SIZE, MLAN_MEM_DEF,
&evt_buf);
if ((status == MLAN_STATUS_SUCCESS) && evt_buf) {
sta_node *sta_ptr;
t_u8 oper_class = 0;
t_u8 global_oper_class = 0;
t_u8 bandwidth;
if (wlan_is_station_list_empty(priv)) {
PRINTM(MERROR, "Not found any connected STA");
status = MLAN_STATUS_FAILURE;
goto done;
}
sta_ptr = (sta_node *)util_peek_list(
priv->adapter->pmoal_handle, &priv->sta_list,
priv->adapter->callbacks.moal_spin_lock,
priv->adapter->callbacks.moal_spin_unlock);
if (!sta_ptr) {
PRINTM(MERROR, "Not found any connected STA");
status = MLAN_STATUS_FAILURE;
goto done;
}
pevent = (pmlan_event)evt_buf;
pacs_start_event = (pagcs_event)pevent->event_buf;
pacs_start_event->type = AGCS_EVENT_TYPE_PROCESS_EVENT;
pacs_start_event->stats.ch_load =
(t_u16)wlan_le16_to_cpu(stats->ch_load);
pacs_start_event->stats.noise =
(t_s16)wlan_le16_to_cpu(stats->noise);
pacs_start_event->stats.nf_threshold =
(t_s16)wlan_le16_to_cpu(stats->nf_threshold);
pacs_start_event->stats.all_sta_ecs = MTRUE;
pacs_start_event->stats.all_sta_6g = MTRUE;
switch (priv->uap_bandwidth) {
case CHAN_BW_20MHZ:
bandwidth = BW_20MHZ;
break;
case CHAN_BW_40MHZ:
bandwidth = BW_40MHZ;
break;
case CHAN_BW_80MHZ:
bandwidth = BW_80MHZ;
break;
default:
bandwidth = BW_20MHZ;
break;
}
wlan_get_curr_oper_class(priv, priv->uap_channel,
bandwidth, &oper_class,
&global_oper_class);
while (sta_ptr &&
(sta_ptr != (sta_node *)&priv->sta_list)) {
PRINTM(MCMND,
"AGCS sta mac_addr" MACSTR
" ExtChanSwitching:%d is_11ax_enabled:%d OperClass:%d\n",
MAC2STR(sta_ptr->mac_addr),
sta_ptr->ExtCap.ext_cap.ExtChanSwitching,
sta_ptr->is_11ax_enabled,
sta_ptr->OperClass.data[0]);
if ((sta_ptr->ExtCap.ext_cap.ExtChanSwitching ==
0) &&
(global_oper_class != 128)) {
pacs_start_event->stats.all_sta_ecs =
MFALSE;
}
if (sta_ptr->is_11ax_enabled == 0) {
pacs_start_event->stats.all_sta_6g =
MFALSE;
} else {
int i;
t_bool t_support_6g = MFALSE;
for (i = 0;
i <
sta_ptr->OperClass.ieee_hdr.len;
i++) {
if (is_6ghz_op_class(
sta_ptr->OperClass
.data[i]) ==
MTRUE) {
t_support_6g = MTRUE;
break;
}
}
pacs_start_event->stats.all_sta_6g &=
t_support_6g;
}
sta_ptr = sta_ptr->pnext;
}
PRINTM(MCMND, "AGCS all_sta_ecs:%d all_sta_6g:%d",
pacs_start_event->stats.all_sta_ecs,
pacs_start_event->stats.all_sta_6g);
/* Send event to moal */
pevent->bss_index = priv->bss_index;
pevent->event_id = MLAN_EVENT_ID_FW_AGCS_TRIGGER;
/* Event length is the agcs_event length in byte */
pevent->event_len = sizeof(agcs_event);
/* keep agcs_info in pmadapter */
memcpy_ext(pmadapter, &pmadapter->agcs_info,
&pacs_start_event->stats, sizeof(agcs_stats),
sizeof(agcs_stats));
status =
wlan_recv_event(priv, pevent->event_id, pevent);
}
}
done:
if (evt_buf)
pcb->moal_mfree(pmadapter->pmoal_handle, evt_buf);
LEAVE();
return status;
}
/********************************************************
Global Functions
********************************************************/
@ -5228,7 +5516,7 @@ mlan_status wlan_ops_uap_prepare_cmd(t_void *priv, t_u16 cmd_no,
case HostCmd_CMD_VERSION_EXT:
cmd_ptr->command = wlan_cpu_to_le16(cmd_no);
cmd_ptr->params.verext.version_str_sel =
(t_u8)(*((t_u32 *)pdata_buf));
read_u32_unaligned(pmpriv->adapter, pdata_buf) & 0xff;
cmd_ptr->size = wlan_cpu_to_le16(
sizeof(HostCmd_DS_VERSION_EXT) + S_DS_GEN);
ret = MLAN_STATUS_SUCCESS;
@ -5238,7 +5526,8 @@ mlan_status wlan_ops_uap_prepare_cmd(t_void *priv, t_u16 cmd_no,
cmd_ptr->params.rx_mgmt_ind.action =
wlan_cpu_to_le16(cmd_action);
cmd_ptr->params.rx_mgmt_ind.mgmt_subtype_mask =
wlan_cpu_to_le32((t_u32)(*((t_u32 *)pdata_buf)));
wlan_cpu_to_le32(
read_u32_unaligned(pmpriv->adapter, pdata_buf));
cmd_ptr->size = wlan_cpu_to_le16(
sizeof(HostCmd_DS_RX_MGMT_IND) + S_DS_GEN);
break;
@ -5440,6 +5729,10 @@ mlan_status wlan_ops_uap_prepare_cmd(t_void *priv, t_u16 cmd_no,
ret = wlan_cmd_tx_ampdu_prot_mode(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
break;
case HostCmd_CMD_PREAMBLE_PWR_BOOST:
ret = wlan_cmd_preamble_pwr_boost(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
break;
case HostCmd_CMD_DOT11MC_UNASSOC_FTM_CFG:
ret = wlan_cmd_dot11mc_unassoc_ftm_cfg(pmpriv, cmd_ptr,
cmd_action, pdata_buf);
@ -5453,8 +5746,8 @@ mlan_status wlan_ops_uap_prepare_cmd(t_void *priv, t_u16 cmd_no,
pdata_buf);
break;
case HostCmd_CMD_CHANNEL_TRPC_CONFIG:
ret = wlan_cmd_get_chan_trpc_config(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
ret = wlan_cmd_chan_trpc_config(pmpriv, cmd_ptr, cmd_action,
cmd_oid, pdata_buf);
break;
case HostCmd_CMD_LOW_POWER_MODE_CFG:
ret = wlan_cmd_set_get_low_power_mode_cfg(
@ -5520,6 +5813,11 @@ mlan_status wlan_ops_uap_prepare_cmd(t_void *priv, t_u16 cmd_no,
cmd_action, pdata_buf);
break;
case HostCmd_CMD_APCMD_AGCS_CFG:
ret = wlan_cmd_apcmd_agcs_cfg(pmpriv, cmd_ptr, cmd_action,
pdata_buf);
break;
default:
PRINTM(MERROR, "PREP_CMD: unknown command- %#x\n", cmd_no);
if (pioctl_req)
@ -5592,6 +5890,7 @@ mlan_status wlan_ops_uap_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
wlan_11h_radar_detected_callback((t_void *)pmpriv);
wlan_coex_ampdu_rxwinsize(pmadapter);
pmpriv->uap_host_based = 0;
wlan_cancel_pending_ba_commands(pmpriv);
break;
case HostCmd_CMD_APCMD_BSS_START:
if (!pmpriv->intf_state_11h.is_11h_host &&
@ -5918,6 +6217,9 @@ mlan_status wlan_ops_uap_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
case HostCmd_CMD_TX_AMPDU_PROT_MODE:
ret = wlan_ret_tx_ampdu_prot_mode(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_PREAMBLE_PWR_BOOST:
ret = wlan_ret_preamble_pwr_boost(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_DOT11MC_UNASSOC_FTM_CFG:
ret = wlan_ret_dot11mc_unassoc_ftm_cfg(pmpriv, resp,
pioctl_buf);
@ -5932,7 +6234,7 @@ mlan_status wlan_ops_uap_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
ret = wlan_ret_cck_desense_cfg(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_CHANNEL_TRPC_CONFIG:
ret = wlan_ret_get_chan_trpc_config(pmpriv, resp, pioctl_buf);
ret = wlan_ret_chan_trpc_config(pmpriv, resp, pioctl_buf);
break;
case HostCmd_CMD_LOW_POWER_MODE_CFG:
ret = wlan_ret_set_get_low_power_mode_cfg(pmpriv, resp,
@ -5992,6 +6294,10 @@ mlan_status wlan_ops_uap_process_cmdresp(t_void *priv, t_u16 cmdresp_no,
case HostCmd_CMD_MCLIENT_SCHEDULE_CFG:
break;
case HostCmd_CMD_APCMD_AGCS_CFG:
ret = wlan_uap_ret_agcs_cfg(pmpriv, resp, pioctl_buf);
break;
default:
PRINTM(MERROR, "CMD_RESP: Unknown command response %#x\n",
resp->command);
@ -6170,7 +6476,8 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
wlan_recv_event(pmpriv, pevent->event_id, pevent);
memcpy_ext(pmadapter, sta_addr, pmadapter->event_body + 2,
MLAN_MAC_ADDR_LENGTH, MLAN_MAC_ADDR_LENGTH);
reason_code = *(t_u16 *)pmadapter->event_body;
reason_code =
read_u16_unaligned(pmadapter, pmadapter->event_body);
sta_ptr = wlan_get_station_entry(pmpriv, sta_addr);
PRINTM_NETINTF(MMSG, pmpriv);
@ -6232,14 +6539,15 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
break;
case EVENT_AMSDU_AGGR_CTRL:
PRINTM(MEVENT, "EVENT: AMSDU_AGGR_CTRL %d\n",
*(t_u16 *)pmadapter->event_body);
read_u16_unaligned(pmadapter, pmadapter->event_body));
pmadapter->tx_buf_size =
MIN(pmadapter->curr_tx_buf_size,
wlan_le16_to_cpu(*(t_u16 *)pmadapter->event_body));
wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmadapter->event_body)));
if (pmbuf->data_len == sizeof(eventcause) + sizeof(t_u32)) {
enable = wlan_le16_to_cpu(
*(t_u16 *)(pmadapter->event_body +
sizeof(t_u16)));
enable = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmadapter->event_body + sizeof(t_u16)));
if (enable)
pmpriv->amsdu_disable = MFALSE;
else
@ -6450,7 +6758,7 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
case EVENT_REMAIN_ON_CHANNEL_EXPIRED:
PRINTM_NETINTF(MEVENT, pmpriv);
PRINTM(MEVENT, "EVENT: REMAIN_ON_CHANNEL_EXPIRED reason=%d\n",
*(t_u16 *)pmadapter->event_body);
read_u16_unaligned(pmadapter, pmadapter->event_body));
pmpriv->adapter->remain_on_channel = MFALSE;
wlan_recv_event(pmpriv, MLAN_EVENT_ID_DRV_FLUSH_RX_WORK, MNULL);
pevent->event_id = MLAN_EVENT_ID_FW_REMAIN_ON_CHAN_EXPIRED;
@ -6485,9 +6793,9 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
#endif
case EVENT_CHAN_SWITCH_TO_6G_BLOCK:
reason_code = wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause)));
reason_code = wlan_le16_to_cpu(read_u16_unaligned(
pmadapter,
pmbuf->pbuf + pmbuf->data_offset + sizeof(eventcause)));
print_chan_switch_block_event(reason_code);
break;
@ -6547,17 +6855,17 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
break;
}
PRINTM(MEVENT, "EVENT: EVENT_FW_HANG_REPORT reasoncode=%d\n",
wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause))));
wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset +
sizeof(eventcause))));
pmadapter->fw_hang_report = MTRUE;
wlan_recv_event(pmpriv, MLAN_EVENT_ID_DRV_DBG_DUMP, MNULL);
break;
case EVENT_WATCHDOG_TMOUT:
PRINTM(MEVENT, "EVENT: EVENT_WATCHDOG_TMOUT reasoncode=%d\n",
wlan_le16_to_cpu(*(t_u16 *)(pmbuf->pbuf +
pmbuf->data_offset +
sizeof(eventcause))));
wlan_le16_to_cpu(read_u16_unaligned(
pmadapter, pmbuf->pbuf + pmbuf->data_offset +
sizeof(eventcause))));
pevent->event_id = MLAN_EVENT_ID_DRV_WIFI_STATUS;
pevent->event_len = sizeof(pevent->event_id) + sizeof(t_u16);
memcpy_ext(pmadapter, (t_u8 *)pevent->event_buf,
@ -6599,6 +6907,23 @@ mlan_status wlan_ops_uap_process_event(t_void *priv)
wlan_process_sta_ps_change_event(priv, pmbuf);
break;
case EVENT_AGCS_REPORT:
PRINTM(MEVENT, "EVENT: AGCS report\n");
wlan_process_agcs_event(priv, pmbuf);
break;
case EVENT_WIFI_CHANNEL_AVOID_LIST:
PRINTM(MEVENT, "EVENT: EVENT_WIFI_CHANNEL_AVOID_LIST\n");
pevent->event_id = MLAN_EVENT_ID_FW_WIFI_CHANNEL_AVOID_LIST;
pevent->bss_index = pmpriv->bss_index;
pevent->event_len = pmbuf->data_len;
memcpy_ext(pmadapter, (t_u8 *)pevent->event_buf,
pmbuf->pbuf + pmbuf->data_offset, pevent->event_len,
pevent->event_len);
DBG_HEXDUMP(MCMD_D, "WiFi channel avoid list",
(t_u8 *)pevent->event_buf, pevent->event_len);
wlan_recv_event(pmpriv, pevent->event_id, pevent);
break;
default:
pevent->event_id = MLAN_EVENT_ID_DRV_PASSTHRU;
break;

View file

@ -2026,6 +2026,43 @@ static mlan_status wlan_uap_snmp_mib_chan_track(pmlan_adapter pmadapter,
return ret;
}
/**
* @brief get/set Agiled channel switch cfg
*
* @param pmadapter A pointer to mlan_adapter structure
* @param pioctl_req Pointer to the IOCTL request buffer
*
* @return MLAN_STATUS_SUCCESS or MLAN_STATUS_FAILURE
*/
mlan_status wlan_uap_agcs_cfg(pmlan_adapter pmadapter,
pmlan_ioctl_req pioctl_req)
{
mlan_private *pmpriv = pmadapter->priv[pioctl_req->bss_index];
mlan_status ret = MLAN_STATUS_SUCCESS;
t_u16 cmd_action = 0;
mlan_ds_misc_cfg *misc = MNULL;
ENTER();
misc = (mlan_ds_misc_cfg *)pioctl_req->pbuf;
if (pioctl_req->action == MLAN_ACT_SET) {
cmd_action = HostCmd_ACT_GEN_SET;
} else {
cmd_action = HostCmd_ACT_GEN_GET;
}
/* Send request to firmware */
ret = wlan_prepare_cmd(pmpriv, HostCmd_CMD_APCMD_AGCS_CFG, cmd_action,
0, (t_void *)pioctl_req,
(t_void *)&misc->param.agcs_cfg);
if (ret == MLAN_STATUS_SUCCESS)
ret = MLAN_STATUS_PENDING;
LEAVE();
return ret;
}
/**
* @brief MLAN uap ioctl handler
*
@ -2365,6 +2402,9 @@ mlan_status wlan_ops_uap_ioctl(t_void *adapter, pmlan_ioctl_req pioctl_req)
else if (misc->sub_command == MLAN_OID_MISC_TX_AMPDU_PROT_MODE)
status = wlan_misc_ioctl_tx_ampdu_prot_mode(pmadapter,
pioctl_req);
else if (misc->sub_command == MLAN_OID_MISC_PREAMBLE_PWR_BOOST)
status = wlan_misc_ioctl_preamble_pwr_boost(pmadapter,
pioctl_req);
else if (misc->sub_command ==
MLAN_OID_MISC_DOT11MC_UNASSOC_FTM_CFG)
status = wlan_misc_ioctl_dot11mc_unassoc_ftm_cfg(
@ -2435,6 +2475,11 @@ mlan_status wlan_ops_uap_ioctl(t_void *adapter, pmlan_ioctl_req pioctl_req)
status = wlan_misc_csi(pmadapter, pioctl_req);
else if (misc->sub_command == MLAN_OID_MISC_MULTI_AP_CFG)
status = wlan_misc_multi_ap_cfg(pmadapter, pioctl_req);
else if (misc->sub_command == MLAN_OID_MISC_PER_BAND_TXPWR_CAP)
status = wlan_misc_ioctl_per_band_txpwr_cap(pmadapter,
pioctl_req);
else if (misc->sub_command == MLAN_OID_MISC_AGCS_CONFIG)
status = wlan_uap_agcs_cfg(pmadapter, pioctl_req);
break;
case MLAN_IOCTL_POWER_CFG:
power = (mlan_ds_power_cfg *)pioctl_req->pbuf;

View file

@ -593,14 +593,15 @@ wlan_usb_tx_copy_buf_to_aggr_v2(pmlan_adapter pmadapter,
pmbuf_aggr->data_len;
if (last) {
offset = pmbuf->data_len;
*(t_u16 *)&payload[2] =
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2 | 0x80);
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2 |
0x80));
} else {
offset = usb_tx_aggr_pad_len(pmbuf->data_len, pusb_tx_aggr);
*(t_u16 *)&payload[2] =
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2);
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2));
}
*(t_u16 *)&payload[0] = wlan_cpu_to_le16(offset);
write_u16_unaligned(pmadapter, &payload[0], wlan_cpu_to_le16(offset));
pmbuf_aggr->data_len += pmbuf->data_len;
PRINTM(MIF_D, "offset=%d len=%d\n", offset, pmbuf->data_len);
LEAVE();
@ -726,9 +727,11 @@ static inline t_void wlan_usb_tx_send_aggr(pmlan_adapter pmadapter,
} else if (pusb_tx_aggr->aggr_ctrl.aggr_mode ==
MLAN_USB_AGGR_MODE_LEN_V2) {
t_u8 *payload = pmbuf_aggr->pbuf + pmbuf_aggr->data_offset;
*(t_u16 *)&payload[0] = wlan_cpu_to_le16(pmbuf_aggr->data_len);
*(t_u16 *)&payload[2] =
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2 | 0x80);
write_u16_unaligned(pmadapter, &payload[0],
wlan_cpu_to_le16(pmbuf_aggr->data_len));
write_u16_unaligned(pmadapter, &payload[2],
wlan_cpu_to_le16(MLAN_TYPE_AGGR_DATA_V2 |
0x80));
PRINTM(MIF_D, "USB Send single packet len=%d\n",
pmbuf_aggr->data_len);
DBG_HEXDUMP(MIF_D, "USB Tx",
@ -904,15 +907,25 @@ mlan_status wlan_usb_deaggr_rx_pkt(pmlan_adapter pmadapter, pmlan_buffer pmbuf)
t_u8 *pdata;
t_s32 aggr_len;
pmlan_buffer pdeaggr_buf;
t_u16 max_loop_cnt = 0;
/* (8 * (MLAN_USB_BLOCK_SIZE * 4)) */
#define MAX_USB_RX_DATA_SIZE (MLAN_USB_RX_MAX_AGGR_NUM * MLAN_USB_MAX_PKT_SIZE)
ENTER();
pdata = pmbuf->pbuf + pmbuf->data_offset;
prx_pd = (RxPD *)pdata;
prx_pd = (RxPD *)(pmbuf->pbuf + pmbuf->data_offset);
curr_pkt_len = wlan_le16_to_cpu(prx_pd->rx_pkt_length) +
wlan_le16_to_cpu(prx_pd->rx_pkt_offset);
/* if non-aggregate, just send through, don’t process here */
aggr_len = pmbuf->data_len;
if (aggr_len < 0 || aggr_len > MAX_USB_RX_DATA_SIZE) {
PRINTM(MERROR, "ERR: Invalid aggr length: %d\n", aggr_len);
ret = MLAN_STATUS_FAILURE;
LEAVE();
return ret;
}
if ((aggr_len == (t_s32)curr_pkt_len) ||
(wlan_usb_deaggr_rx_num_pkts(pmadapter, pdata, aggr_len) == 1) ||
(pmadapter->pcard_usb->usb_rx_deaggr.aggr_ctrl.enable != MTRUE)) {
@ -921,7 +934,8 @@ mlan_status wlan_usb_deaggr_rx_pkt(pmlan_adapter pmadapter, pmlan_buffer pmbuf)
return ret;
}
while (aggr_len >= (t_s32)sizeof(RxPD)) {
while ((aggr_len >= (t_s32)sizeof(RxPD)) &&
(max_loop_cnt++ < MLAN_USB_RX_MAX_AGGR_NUM)) {
/* check for (all-zeroes) termination RxPD */
if (!memcmp(pmadapter, pdata, zero_rx_pd, sizeof(RxPD))) {
break;
@ -967,14 +981,20 @@ mlan_status wlan_usb_deaggr_rx_pkt(pmlan_adapter pmadapter, pmlan_buffer pmbuf)
(curr_pkt_len %
pmadapter->pcard_usb->usb_rx_deaggr
.aggr_ctrl.aggr_align));
/* curr_pkt_len should not be greate than the aggreated length*/
if (curr_pkt_len > aggr_len)
break;
/* point to next packet */
aggr_len -= curr_pkt_len;
aggr_len -= (t_s32)curr_pkt_len;
pdata += curr_pkt_len;
prx_pd = (RxPD *)pdata;
curr_pkt_len = wlan_le16_to_cpu(prx_pd->rx_pkt_length) +
wlan_le16_to_cpu(prx_pd->rx_pkt_offset);
}
if (max_loop_cnt >= MLAN_USB_RX_MAX_AGGR_NUM) {
PRINTM(MERROR, "ERR: max loop limit is exceeded\n");
ret = MLAN_STATUS_FAILURE;
}
/* free original pmbuf (since not sent for processing) */
pmadapter->callbacks.moal_recv_complete(pmadapter->pmoal_handle, pmbuf,
pmadapter->rx_data_ep, ret);

View file

@ -1312,8 +1312,9 @@ static t_bool wlan_wmm_process_ra_list_quoats(pmlan_adapter pmadapter,
ra_list->amsdu_in_ampdu ?
sta->budget.mpdu_with_amsdu_budget_init :
sta->budget.mpdu_no_amsdu_budget_init;
util_unlink_list_nl(pmadapter->pmoal_handle,
&ra_list->pending_txq_entry);
if (util_is_node_in_list(&ra_list->pending_txq_entry))
util_unlink_list_nl(pmadapter->pmoal_handle,
&ra_list->pending_txq_entry);
util_enqueue_list_tail_nl(
pmadapter->pmoal_handle,
@ -1515,7 +1516,9 @@ static raListTbl *wlan_wmm_get_next_priolist_ptr(pmlan_adapter pmadapter,
for (; mlan != MNULL; mlan = wlan_wmm_get_next_bss(pmadapter)) {
ra_list = mlan->wmm.selected_ra_list;
if (ra_list == MNULL || ra_list->total_pkts == 0) {
if (ra_list == MNULL || ra_list->total_pkts == 0 ||
MNULL == util_peek_list_nl(pmoal_handle,
&ra_list->buf_head)) {
ra_list = wlan_wmm_get_next_ra_list(pmadapter, mlan);
} else if (!wlan_wmm_process_ra_list_quoats(pmadapter, mlan,
ra_list)) {

View file

@ -477,6 +477,8 @@ typedef t_u8 mlan_802_11_mac_addr[MLAN_MAC_ADDR_LENGTH];
#define CARD_SDAW693 "SDAW693"
/** SDIW610 Card */
#define CARD_SDIW610 "SDIW610"
/** SDIW623 Card */
#define CARD_SDIW623 "SDIW623"
#endif
#ifdef PCIE
@ -522,6 +524,8 @@ typedef t_u8 mlan_802_11_mac_addr[MLAN_MAC_ADDR_LENGTH];
#define CARD_PCIEAW693 "PCIEAW693"
/** PCIEIW629 Card */
#define CARD_PCIEIW629 "PCIEIW629"
/** PCIEIW623 Card */
#define CARD_PCIEIW623 "PCIEIW623"
#endif
#ifdef USB
@ -683,6 +687,7 @@ typedef enum {
#define MFWDP_D MBIT(21)
#endif /*FWDUMP_VIA_PRINT*/
#define MSCH_D MBIT(22)
#define MSHC_D MBIT(23)
#define MENTRY MBIT(28)
#define MWARN MBIT(29)
#define MINFO MBIT(30)
@ -781,6 +786,29 @@ typedef struct _assoc_logger {
#define SCAN_STATE_EXT_SCAN_STATUS MBIT(9)
#define SCAN_STATE_SCAN_COMPLETE MBIT(10)
#ifdef UAP_SUPPORT
/* Agiled channel switch state */
typedef enum _agcs_state {
/** AGCS is desabled */
AGCS_STATE_IDLE = 0,
/** AGCS is enabled */
AGCS_STATE_START = 1,
/**When FW sends AGCS event to notify the driver to prepare for channel
switch.*/
AGCS_STATE_TRIGGERED = 2,
/** Start to scan the candidate channels */
AGCS_STATE_IN_SCAN = 3,
/** Receives the scan report */
AGCS_STATE_SCAN_REPORT = 4,
/** All candidate channels scanned done */
AGCS_STATE_SCAN_DONE = 5,
/** Start Channel Switch */
AGCS_STATE_CSA_START = 6,
/** Channel Switch Completed */
AGCS_STATE_COMPLETE = 7,
} agcs_state;
#endif /* UAP_SUPPORT */
#ifdef USB
/** mlan_usb_ep */
typedef enum _mlan_usb_ep {
@ -879,6 +907,10 @@ typedef enum _mlan_event_id {
#endif /* SSU_SUPPORT */
MLAN_EVENT_ID_CSI = 0x00000040,
MLAN_EVENT_ID_FW_TX_BULK_STATUS = 0x00000043,
#ifdef UAP_SUPPORT
/* Agiled channel switch triggered */
MLAN_EVENT_ID_FW_AGCS_TRIGGER = 0x00000044,
#endif /* UAP_SUPPORT */
/* Event generated by MLAN driver (MSB=1) */
MLAN_EVENT_ID_DRV_CONNECTED = 0x80000001,
MLAN_EVENT_ID_DRV_DEFER_HANDLING = 0x80000002,
@ -921,6 +953,7 @@ typedef enum _mlan_event_id {
MLAN_EVENT_ID_FW_CHAN_SWITCH_REGINFO = 0x80000038,
#endif
MLAN_EVENT_ID_DRV_ASSOC_FAILURE = 0x80000039,
MLAN_EVENT_ID_FW_WIFI_CHANNEL_AVOID_LIST = 0x8000003A,
MLAN_EVENT_ID_EMERGENCY_TEMP_REACHED = 0x80000040,
} mlan_event_id;
@ -1143,6 +1176,16 @@ typedef MLAN_PACK_START struct _chan_band_reginfo_t {
} MLAN_PACK_END chan_band_reginfo_t;
#endif
/** Structure to WiFi Channel Avoidance List */
typedef MLAN_PACK_START struct _wifi_chan_avoid_list_t {
/** Band Configuration */
Band_Config_t bandcfg;
/** Length */
t_u8 length;
/** Chanlist */
t_u8 chanList[];
} MLAN_PACK_END wifi_chan_avoid_list_t;
/** Channel usability flags */
#define NXP_CHANNEL_NO_OFDM MBIT(9)
#define NXP_CHANNEL_NO_CCK MBIT(8)
@ -2718,6 +2761,32 @@ typedef struct _mlan_callbacks {
t_s32 copy_delay);
mlan_status (*moal_calc_short_ssid)(t_u8 *pssid, t_u32 ssid_len,
t_u32 *pshort_ssid);
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);
/* Unaligned Access */
struct unaligned_access {
t_u16 (*moal_read_u16)(const void *src);
t_u32 (*moal_read_u32)(const void *src);
void (*moal_write_u16)(void *dest, t_u16 val);
void (*moal_write_u32)(void *dest, t_u32 val);
} moal_unaligned_access;
} mlan_callbacks, *pmlan_callbacks;
/** Parameter unchanged, use MLAN default setting */
@ -2897,6 +2966,7 @@ typedef struct _mlan_device {
t_u8 disable_11h_tpc;
t_u8 tpe_ie_ignore;
t_u32 amsdu_disable;
t_u32 secure_host;
} mlan_device, *pmlan_device;
/** MLAN API function prototype */

View file

@ -397,7 +397,11 @@ enum _mlan_ioctl_req_id {
MLAN_OID_MISC_PREV_ASSOC_INFO = 0x0020009A,
MLAN_OID_MISC_NAV_MITIGATION_HW = 0x0020009C,
MLAN_OID_MISC_PREAMBLE_PWR_BOOST = 0x0020009D,
MLAN_OID_MISC_PER_BAND_TXPWR_CAP = 0x0020009E,
#ifdef UAP_SUPPORT
MLAN_OID_MISC_AGCS_CONFIG = 0x0020009F,
#endif /* UAP_SUPPORT */
};
/** Sub command size */
@ -1863,6 +1867,12 @@ typedef struct _mlan_ds_get_stats {
t_u32 TXpwrMethod;
/** DPD training status*/
t_u32 isDPDdone;
/*CCA count*/
t_u64 cca_cnt_us;
/*RX airtime count*/
t_u64 rxAirtime_us;
/*TX airtime count*/
t_u64 txAirtime_us;
} mlan_ds_get_stats, *pmlan_ds_get_stats;
/** Type definition of mlan_ds_uap_stats for MLAN_OID_GET_STATS */
@ -4953,6 +4963,16 @@ typedef struct _mlan_ds_misc_tx_ampdu_prot_mode {
t_u16 mode;
} mlan_ds_misc_tx_ampdu_prot_mode;
/** Type definition of mlan_ds_misc_preamble_pwr_boost
* for MLAN_OID_MISC_PREAMBLE_PWR_BOOST
*/
typedef struct _mlan_ds_misc_preamble_pwr_boost {
/** To force-enable/force-disable the preamble pwr boost feature*/
t_u8 enable_mode;
/** rssi threshold */
t_s8 rssi_threshold;
} mlan_ds_misc_preamble_pwr_boost;
/** Type definition of mlan_ds_misc_dot11mc_unassoc_ftm_cfg
* for MLAN_OID_MISC_DOT11MC_UNASSOC_FTM_CFG
*/
@ -6556,6 +6576,14 @@ typedef struct _mlan_ds_ed_mac_cfg {
t_u32 ed_bitmap_txq_lock;
} mlan_ds_ed_mac_cfg;
/** per_band_txpwr_cap params */
typedef struct _mlan_ds_misc_per_band_txpwr_cap {
/** power value */
t_u8 power;
/** band */
t_u8 band;
} mlan_ds_misc_per_band_txpwr_cap;
/** valid range for mlan_ds_auth_assoc_timeout_cfg */
#define AUTH_TIMEOUT_MIN 500
#define AUTH_TIMEOUT_MAX 2400
@ -6586,6 +6614,37 @@ typedef struct _mlan_ds_auth_assoc_timeout_cfg {
t_u16 retry_timeout;
} mlan_ds_auth_assoc_timeout_cfg;
#ifdef UAP_SUPPORT
/** Agiled channel switch configuration parameters */
typedef struct _mlan_ds_agcs_cfg {
/**agcs cfg action 0-GET, 1-SET */
t_u16 action;
/* BIT0 - Enable Agile channel switching in CarPlay
* BIT1 - no specific interference type check, but only check Tx or Rx
* throughput drop
*/
t_u32 features;
/* Adjust the weight of TX/RX average packet count */
t_u8 avg_threshold_percentage;
/* The requires at least average rx packets per second */
t_u16 rx_min_pkt_count;
/* The requires at least average tx packets per second */
t_u16 tx_min_pkt_count;
/* Unit is ms */
t_u32 sample_time;
/* The latest sampled windows size */
t_u8 sample_count_window;
/* Continuous drop rapidly times */
t_u8 continuous_hit_count;
/* Make sure a reasonable rate can be sustained. */
t_s8 nf_margin;
/* Long duration packets threshold */
t_u16 nav_mitigation_th;
/* ch threshold to trigger channel switch for nighthawk */
t_u16 ch_th;
} mlan_ds_agcs_cfg;
#endif /* UAP_SUPPORT */
/** Type definition of mlan_ds_misc_cfg for MLAN_IOCTL_MISC_CFG */
typedef struct _mlan_ds_misc_cfg {
/** Sub-command */
@ -6732,6 +6791,7 @@ typedef struct _mlan_ds_misc_cfg {
mlan_ds_misc_nav_mitigation_hw nav_mitigation_hw;
mlan_ds_misc_led_cfg led_config;
mlan_ds_misc_tx_ampdu_prot_mode tx_ampdu_prot_mode;
mlan_ds_misc_preamble_pwr_boost preamble_pwr_boost;
mlan_ds_misc_rate_adapt_cfg rate_adapt_cfg;
mlan_ds_misc_cck_desense_cfg cck_desense_cfg;
mlan_ds_misc_chan_trpc_cfg trpc_cfg;
@ -6767,6 +6827,11 @@ typedef struct _mlan_ds_misc_cfg {
mlan_ds_ed_mac_cfg edmac_cfg;
mlan_ds_gpio_cfg_ops gpio_cfg_ops;
mlan_ds_auth_assoc_timeout_cfg auth_assoc_cfg;
mlan_ds_misc_per_band_txpwr_cap per_band_txpwr_cap;
#ifdef UAP_SUPPORT
/** config AGCS for MLAN_OID_MISC_AGCS_CONFIG */
mlan_ds_agcs_cfg agcs_cfg;
#endif /* UAP_SUPPORT */
} param;
} mlan_ds_misc_cfg, *pmlan_ds_misc_cfg;
@ -6805,4 +6870,34 @@ typedef struct _mlan_cfpinfo {
#define MLAN_REASON_CLASS3_FRAME_FROM_NOASSOC_STA 7
#define MLAN_REASON_DISASSOC_STA_HAS_LEFT 8
#define MLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
#ifdef UAP_SUPPORT
/* Processing AGCS report */
#define AGCS_EVENT_TYPE_PROCESS_EVENT 1
/* After AGCS scan, select and switch to new channel */
#define AGCS_EVENT_TYPE_SEL_CHANNEL 2
/** Type definition of agcs_stats for agcs_event */
typedef struct _agcs_stats {
/** All STAs support ECS */
t_u8 all_sta_ecs;
/** All STAs support 6g */
t_u8 all_sta_6g;
/** ch_load of current channel */
t_u16 ch_load;
/** noise of current channel */
t_s16 noise;
/** The noise floor threshold currently used by fw */
t_s16 nf_threshold;
} agcs_stats, *pagcs_stats;
/** Type definition of agcs_event for WOAL_EVENT_AGCS */
typedef struct _agcs_event {
/** AGCS_EVENT_TYPE_PROCESS_EVENT or AGCS_EVENT_TYPE_SEL_CHANNEL */
t_u32 type;
/** AGCS stats info */
agcs_stats stats;
} agcs_event, *pagcs_event;
#endif /* UAP_SUPPORT */
#endif /* !_MLAN_IOCTL_H_ */

View file

@ -6491,3 +6491,82 @@ done:
return status;
}
#endif
/**
* @brief Process the WiFi channel list avoidance event
*
* @param priv A pointer to the moal_private structure
* @param pwifi_chan_info Pointer to the WiFi channel list
* avoidance structure
*
* @return void
*/
void process_wifi_channel_avoid_list_event(
moal_private *priv, wifi_chan_avoid_list_t *pwifi_chan_info)
{
struct ieee80211_supported_band *sband = NULL;
struct ieee80211_channel *channel = NULL;
int index = 0, i = 0, j = 0;
if (!pwifi_chan_info)
return;
/* Process the event */
if (pwifi_chan_info->bandcfg.chanBand == BAND_2GHZ) {
PRINTM(MEVENT, "WiFi Channel Avoidance List band=%d len=%d\n",
pwifi_chan_info->bandcfg.chanBand,
pwifi_chan_info->length);
for (index = 0; index < MAX_MLAN_ADAPTER; index++) {
/* Reinitialize the sband for every adapter */
sband = NULL;
if (m_handle[index] && m_handle[index]->wiphy) {
sband = m_handle[index]
->wiphy
->bands[IEEE80211_BAND_2GHZ];
/* Move to next adapter with supporting band */
if (!sband)
continue;
PRINTM(MINFO,
"====== Iteration=%d ======", index);
/* Clearing NO-IR flags for all channels */
for (i = 0; i < sband->n_channels; i++) {
channel = &sband->channels[i];
channel->flags &= ~IEEE80211_CHAN_NO_IR;
}
/* Setting NO-IR flags as per the channel list
*/
for (j = 0; j < pwifi_chan_info->length; j++) {
for (i = 0; i < sband->n_channels;
i++) {
channel = &sband->channels[i];
if (channel->hw_value ==
pwifi_chan_info
->chanList[j]) {
PRINTM(MMSG,
"Marking channel = %d as NO-IR\n",
pwifi_chan_info->chanList
[j]);
channel->flags |=
IEEE80211_CHAN_NO_IR;
break;
}
}
}
/* Disabling beacon hints to avoid re-enabling
* of channels marked as NO-IR */
m_handle[index]->wiphy->regulatory_flags =
m_handle[index]
->wiphy->regulatory_flags |
REGULATORY_DISABLE_BEACON_HINTS;
}
}
} else
PRINTM(MEVENT,
"Ignoring the WiFi Channel Avoidance List Event\n");
return;
}

View file

@ -640,4 +640,7 @@ mlan_status woal_dnld_default_6e_psd_table(moal_private *priv);
mlan_status woal_request_set_host_mlme(moal_private *priv, t_u8 *bssid);
void process_wifi_channel_avoid_list_event(
moal_private *priv, wifi_chan_avoid_list_t *pwifi_chan_info);
#endif /* _MOAL_CFG80211_H_ */

File diff suppressed because it is too large Load diff

View file

@ -329,6 +329,8 @@ typedef struct _chan_stats {
#define TX_AMPDU_DYNAMIC_RTS_CTS 3
/**Private command to set tx ampdu protection mode */
#define PRIV_CMD_TX_AMPDU_PROT_MODE "tx_ampdu_prot_mode"
/**Private command to enable preamble pwr boost feature */
#define PRIV_CMD_PREAMBLE_PWR_BOOST "preamble_pwr_boost"
/**Private command to configure tx rate adapt config */
#define PRIV_CMD_RATE_ADAPT_CFG "rate_adapt_cfg"
#define CCK_DESENSE_MODE_DISABLED 0
@ -363,6 +365,9 @@ typedef struct _chan_stats {
#define PRIV_CMD_DMCS "dmcs"
/**Private command to configure per_band_txpwr_cap */
#define PRIV_CMD_PER_BAND_TXPWR_CAP "per_band_txpwr_cap"
#if defined(PCIE)
#define PRIV_CMD_SSU "ssu"
/** ssu_params_ctrl */
@ -795,4 +800,9 @@ typedef struct {
} __ATTRIB_PACK__ wlan_ieee80211_chan_list;
#define PRIV_CMD_TP_STATE "tp_state"
#ifdef UAP_SUPPORT
#define PRIV_CMD_AGCS "agcs"
#endif
#endif /* _WOAL_ETH_PRIV_H_ */

View file

@ -448,6 +448,9 @@ static int make_before_break = 0;
static int auto_11ax = 1;
static int reject_addba_req = 0;
/** secure host mode support */
int secure_host = 0;
/**
* @brief This function read a line in module parameter file
*
@ -1753,6 +1756,12 @@ static mlan_status parse_cfg_read_block(t_u8 *data, t_u32 size,
params->make_before_break = out_data;
PRINTM(MMSG, "make_before_break=%x\n",
params->make_before_break);
} else if (strncmp(line, "secure_host",
strlen("secure_host")) == 0) {
if (parse_line_read_int(line, &out_data) !=
MLAN_STATUS_SUCCESS)
goto err;
params->secure_host = out_data;
}
}
@ -1766,6 +1775,13 @@ static mlan_status parse_cfg_read_block(t_u8 *data, t_u32 size,
params->mclient_scheduling = 0;
#endif
#ifdef PCIE
if (!IS_PCIEAW693(handle->card_type))
params->secure_host = 0;
#else
params->secure_host = 0;
#endif
if (end)
return ret;
err:
@ -2224,6 +2240,16 @@ static void woal_setup_module_param(moal_handle *handle, moal_mod_para *params)
if (params)
handle->params.tpe_ie_ignore = params->tpe_ie_ignore;
handle->params.make_before_break = make_before_break;
handle->params.secure_host = secure_host;
if (params)
handle->params.secure_host = params->secure_host;
#ifdef PCIE
if (!IS_PCIEAW693(handle->card_type))
handle->params.secure_host = 0;
#else
handle->params.secure_host = 0;
#endif
}
/**
@ -2835,6 +2861,14 @@ void woal_init_from_dev_tree(void)
make_before_break = data;
}
}
else if (!strncmp(prop->name, "secure_host",
strlen("secure_host"))) {
if (!of_property_read_u32(dt_node, prop->name, &data)) {
PRINTM(MIOCTL, "secure_host=0x%x\n", data);
secure_host = data;
}
}
}
LEAVE();
return;
@ -3496,3 +3530,8 @@ module_param(make_before_break, int, 0);
MODULE_PARM_DESC(
make_before_break,
"1: make_before_break during roam; 0: no make_before_break during roam");
module_param(secure_host, int, 0660);
MODULE_PARM_DESC(
secure_host,
"0: Disable secure host mode(default); 1: Enable secure host mode");

View file

@ -3988,11 +3988,9 @@ mlan_status woal_cancel_hs(moal_private *priv, t_u8 wait_option)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
#if IS_ENABLED(CONFIG_IPV6)
if (priv->phandle->hs_auto_arp) {
PRINTM(MIOCTL, "Cancel Host Sleep... remove ipv6 offload\n");
/** Set ipv6 router advertisement message offload */
woal_set_ipv6_ra_offload(priv->phandle, MFALSE);
}
PRINTM(MIOCTL, "Cancel Host Sleep... remove ipv6 offload\n");
/** Set ipv6 router advertisement message offload */
woal_set_ipv6_ra_offload(priv->phandle, MFALSE);
/** Set Neighbor Solitation message offload */
woal_set_ipv6_ns_offload(priv->phandle, MFALSE);
#endif
@ -4337,10 +4335,12 @@ int woal_enable_hs(moal_private *priv)
media_connected = woal_check_media_connected(handle);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0)
#if IS_ENABLED(CONFIG_IPV6)
if (handle->hs_auto_arp && media_connected) {
if (media_connected) {
PRINTM(MIOCTL, "Host Sleep enabled... set ipv6 offload\n");
/** Set ipv6 router advertisement message offload */
woal_set_ipv6_ra_offload(handle, MTRUE);
}
if (handle->hs_auto_arp && media_connected) {
/** Set Neighbor Solitation message offload */
woal_set_ipv6_ns_offload(handle, MTRUE);
}

View file

@ -84,6 +84,7 @@ Change log:
#include <linux/rtc.h>
#include <linux/utsname.h>
#endif
#include "moal_shc.h"
/********************************************************
Global Variables
@ -1012,6 +1013,22 @@ static mlan_callbacks woal_callbacks = {
.moal_tp_accounting_rx_param = moal_tp_accounting_rx_param,
.moal_amsdu_tp_accounting = moal_amsdu_tp_accounting,
.moal_calc_short_ssid = moal_calc_short_ssid,
.moal_secure_host_get_msg_id = moal_secure_host_get_msg_id,
.moal_secure_host_init = moal_secure_host_init,
.moal_secure_host_cleanup = moal_secure_host_cleanup,
.moal_secure_host_do_hello = moal_secure_host_do_hello,
.moal_secure_host_device_hello_rcvd =
moal_secure_host_device_hello_rcvd,
.moal_secure_host_do_finished = moal_secure_host_do_finished,
.moal_secure_host_derive_traffic_keys =
moal_secure_host_derive_traffic_keys,
.moal_secure_host_data_ctx_init = moal_secure_host_data_ctx_init,
.moal_secure_host_data_encrypt = moal_secure_host_data_encrypt,
.moal_secure_host_data_decrypt = moal_secure_host_data_decrypt,
.moal_unaligned_access.moal_read_u16 = moal_read_unaligned_u16,
.moal_unaligned_access.moal_read_u32 = moal_read_unaligned_u32,
.moal_unaligned_access.moal_write_u16 = moal_write_unaligned_u16,
.moal_unaligned_access.moal_write_u32 = moal_write_unaligned_u32,
};
#define PLSTATS_FILTER_TX_BYTES MBIT(0)
@ -2557,6 +2574,8 @@ mlan_status woal_init_sw(moal_handle *handle)
t_void *pmlan;
int cfg80211_wext = handle->params.cfg80211_wext;
moal_handle *ref_handle = NULL;
ENTER();
/* Initialize moal_handle structure */
@ -2808,6 +2827,11 @@ mlan_status woal_init_sw(moal_handle *handle)
moal_extflg_isset(handle, EXT_SDIO_RX_AGGR);
device.int_mode = (t_u32)moal_extflg_isset(handle, EXT_INTMODE);
device.gpio_pin = (t_u32)handle->params.gpiopin;
device.spi_mode = (((sdio_mmc_card *)handle->card)
->func->card->host->caps &
MMC_CAP_SPI) ?
1 :
0;
#ifdef SDIO_MMC
device.sdio_blk_size = handle->sdio_blk_size;
device.max_blk_count =
@ -2818,6 +2842,10 @@ mlan_status woal_init_sw(moal_handle *handle)
->func->card->host->max_segs;
device.max_seg_size = ((sdio_mmc_card *)handle->card)
->func->card->host->max_seg_size;
if (device.spi_mode) {
device.max_seg_size =
device.sdio_blk_size * device.max_blk_count;
}
#endif
PRINTM(MMSG,
"SDIO: sdio_blk_size=%d max_blk_count=%d max_segs=%d max_seg_size=%d\n",
@ -2834,11 +2862,6 @@ mlan_status woal_init_sw(moal_handle *handle)
device.mpa_tx_cfg = MLAN_INIT_PARA_ENABLED;
device.mpa_rx_cfg = MLAN_INIT_PARA_ENABLED;
#endif /* SDIO_MMC */
device.spi_mode = (((sdio_mmc_card *)handle->card)
->func->card->host->caps &
MMC_CAP_SPI) ?
1 :
0;
}
#endif /* SDIO */
device.feature_control = handle->card_info->feature_control;
@ -2912,6 +2935,23 @@ mlan_status woal_init_sw(moal_handle *handle)
device.mclient_scheduling = handle->params.mclient_scheduling;
/* Clean up the mode_psd_string for 6E Indoor/Outdoor */
memset(handle->mode_psd_string, 0, sizeof(handle->mode_psd_string));
device.secure_host = (t_u32)handle->params.secure_host;
if (handle->second_mac && handle->params.secure_host &&
handle->pref_mac) {
ref_handle = (moal_handle *)handle->pref_mac;
handle->secure = ref_handle->secure;
}
if (handle->second_mac && handle->params.secure_host &&
!handle->secure) {
PRINTM(MERROR, "secure host handshake incomplete\n");
ret = MLAN_STATUS_FAILURE;
LEAVE();
return ret;
}
moal_memcpy_ext(handle, &device.callbacks, &woal_callbacks,
sizeof(mlan_callbacks), sizeof(mlan_callbacks));
if (!handle->params.amsdu_deaggr)
@ -2998,6 +3038,15 @@ void woal_free_moal_handle(moal_handle *handle)
kfree(fwdump_fname);
fwdump_fname = NULL;
}
if (handle->params.secure_host) {
moal_secure_host_cleanup(handle);
handle->secure = NULL;
if (handle->pref_mac) {
ref_handle = (moal_handle *)handle->pref_mac;
ref_handle->secure = NULL;
}
}
/* Free module params */
woal_free_module_param(handle);
/** clear pref_mac to avoid later crash */
@ -4356,6 +4405,56 @@ static ssize_t woal_set_rps_map(struct netdev_rx_queue *queue, const char *buf,
#endif
#endif
/**
* @brief Init independent reset configure
*
* @param priv Pointer to moal_private structure
*
* @return MLAN_STATUS_SUCCESS
*/
mlan_status woal_get_ind_rst_cfg(moal_handle *handle, t_u8 wait_option)
{
moal_private *priv = NULL;
mlan_ds_misc_cfg *misc = NULL;
mlan_ioctl_req *req = NULL;
mlan_status status = MLAN_STATUS_SUCCESS;
ENTER();
priv = woal_get_priv(handle, MLAN_BSS_ROLE_ANY);
if (!priv) {
LEAVE();
return MLAN_STATUS_FAILURE;
}
req = woal_alloc_mlan_ioctl_req(sizeof(mlan_ds_misc_cfg));
if (req == NULL) {
LEAVE();
return -ENOMEM;
}
misc = (mlan_ds_misc_cfg *)req->pbuf;
memset(misc, 0, sizeof(mlan_ds_misc_cfg));
misc->sub_command = MLAN_OID_MISC_IND_RST_CFG;
req->req_id = MLAN_IOCTL_MISC_CFG;
req->action = MLAN_ACT_GET;
status = woal_request_ioctl(priv, req, wait_option);
if (status != MLAN_STATUS_SUCCESS) {
goto done;
}
priv->phandle->params.indrstcfg =
(((int)(misc->param.ind_rst_cfg.gpio_pin) & 0xFF) << 8) |
((int)(misc->param.ind_rst_cfg.ir_mode) & 0xFF);
done:
if (status != MLAN_STATUS_PENDING)
kfree(req);
LEAVE();
return status;
}
/**
* @brief Add interfaces DPC
*
@ -4468,6 +4567,11 @@ static mlan_status woal_add_card_dpc(moal_handle *handle)
woal_set_sdio_slew_rate(handle);
#endif
if (MLAN_STATUS_SUCCESS !=
woal_get_ind_rst_cfg(handle, MOAL_IOCTL_WAIT)) {
PRINTM(MFATAL, "Set init ind_rst_cfg failed\n");
goto err;
}
if (moal_extflg_isset(handle, EXT_PMIC) && handle->card_info->pmic) {
if (MLAN_STATUS_SUCCESS !=
woal_pmic_configure(handle, MOAL_IOCTL_WAIT)) {
@ -4904,7 +5008,11 @@ static mlan_status woal_init_fw_dpc(moal_handle *handle)
PRINTM(MERROR,
"WLAN: Fail download FW with nowwait: %u\n",
moal_extflg_isset(handle, EXT_REQ_FW_NOWAIT));
if (handle->ops.reg_dbg)
if (handle->ops.reg_dbg
#ifdef PCIE
&& !IS_PCIEAW693(handle->card_type)
#endif
)
handle->ops.reg_dbg(handle);
goto done;
}
@ -4980,7 +5088,11 @@ static mlan_status woal_init_fw_dpc(moal_handle *handle)
if (handle->hardware_status != HardwareStatusReady) {
wifi_status = WIFI_STATUS_INIT_FW_FAIL;
handle->event_fw_dump = MFALSE;
if (handle->ops.reg_dbg)
if (handle->ops.reg_dbg
#ifdef PCIE
&& !IS_PCIEAW693(handle->card_type)
#endif
)
handle->ops.reg_dbg(handle);
#ifdef DEBUG_LEVEL1
if (drvdbg & MFW_D) {
@ -7174,34 +7286,6 @@ int woal_close(struct net_device *dev)
return 0;
}
#define DEF_MTU_SIZE 1500
/**
* @brief This function disable the ampdu
*
* @param priv A pointer to mlan_private structure
* @param new_mtu new mtu size
*
* @return 0 --success, otherwise fail
*/
static void woal_disable_ampdu(moal_private *priv)
{
mlan_ds_11n_aggr_prio_tbl aggr_prio_tbl;
int i;
memset(&aggr_prio_tbl, 0, sizeof(aggr_prio_tbl));
if (MLAN_STATUS_SUCCESS !=
woal_ioctl_aggr_prio_tbl(priv, MLAN_ACT_GET, &aggr_prio_tbl)) {
goto done;
}
for (i = 0; i < MAX_NUM_TID; i++)
aggr_prio_tbl.ampdu[i] = 0xff;
if (MLAN_STATUS_SUCCESS !=
woal_ioctl_aggr_prio_tbl(priv, MLAN_ACT_SET, &aggr_prio_tbl)) {
goto done;
}
done:
return;
}
/**
* @brief This function change the MTU size
*
@ -7212,12 +7296,9 @@ done:
*/
int woal_change_mtu(struct net_device *dev, int new_mtu)
{
moal_private *priv = (moal_private *)netdev_priv(dev);
dev->mtu = new_mtu;
// disable AMPDU with mtu size > 1500
if (new_mtu > DEF_MTU_SIZE)
woal_disable_ampdu(priv);
PRINTM(MCMND, "wlan: change_mtu to %d\n", new_mtu);
PRINTM(MCMND, "wlan: received MTU update, to %d\n", new_mtu);
return 0;
}
@ -10971,8 +11052,8 @@ t_void woal_send_disconnect_to_system(moal_private *priv,
}
#endif /* STA_SUPPORT */
#ifndef DUMP_TO_PROC
#if defined(PCIE)
#ifndef DUMP_TO_PROC
/**
* @brief This function stores the SSU dumps in a file
*
@ -11043,8 +11124,66 @@ save_ssudump:
LEAVE();
return;
}
#endif /* SSU_SUPPORT */
#else
/**
* @brief This function stores the SSU dumps received from events
*
* @param phandle A pointer to moal_handle
* @param pmevent A pointer to mlan_event structure
*
* @return N/A
*/
t_void woal_store_ssu_dump(moal_handle *phandle, mlan_event *pmevent)
{
int ret = 0;
t_u8 *pos;
t_u32 *tmpbuf;
ENTER();
if (!phandle || !pmevent) {
PRINTM(MERROR, "Could not dump ssu\n");
LEAVE();
return;
}
if (!phandle->ssu_dump_buf) {
ret = moal_vmalloc(phandle, MLAN_SSU_BUF_SIZE,
&phandle->ssu_dump_buf);
if (ret != MLAN_STATUS_SUCCESS || !phandle->ssu_dump_buf) {
PRINTM(MERROR, "Failed to vmalloc ssu dump buffer\n");
LEAVE();
return;
}
} else {
memset(phandle->ssu_dump_buf, 0x00, MLAN_SSU_BUF_SIZE);
}
phandle->ssu_dump_len = 0;
moal_memcpy_ext(phandle, &tmpbuf, pmevent->event_buf, sizeof(t_ptr),
sizeof(t_ptr));
PRINTM(MMSG, "==== Start Receive SSU dump event ====\n");
pos = phandle->ssu_dump_buf;
moal_memcpy_ext(phandle, pos, tmpbuf, pmevent->event_len,
MLAN_SSU_BUF_SIZE);
if (pmevent->event_len <= MLAN_SSU_BUF_SIZE) {
phandle->ssu_dump_len = pmevent->event_len;
} else {
PRINTM(MERROR, "event_len is invalid\n");
}
PRINTM(MINFO, "ssu dump event: evt_len=%d toal_len=%llu\n",
pmevent->event_len, phandle->ssu_dump_len);
PRINTM(MMSG, "==== SSU DUMP END: %ld bytes ====\n",
(long int)phandle->ssu_dump_len);
LEAVE();
return;
}
#endif
#endif /* SSU_SUPPORT */
#define OFFSET_SEQNUM 4
#define OFFSET_TYPE 8
@ -11579,7 +11718,11 @@ static int woal_dump_moal_drv_info(moal_handle *phandle, t_u8 *buf)
ptr += snprintf(ptr, MAX_BUF_LEN,
"------------moal_debug_info End-------------\n");
if (phandle->ops.dump_reg_info)
if (phandle->ops.dump_reg_info
#ifdef PCIE
&& !IS_PCIEAW693(phandle->card_type)
#endif
)
ptr += phandle->ops.dump_reg_info(phandle, ptr);
LEAVE();
@ -12502,7 +12645,11 @@ void woal_moal_debug_info(moal_private *priv, moal_handle *handle, u8 flag)
#ifdef PCIE
if (IS_PCIE(phandle->card_type)) {
#ifdef DEBUG_LEVEL1
if (phandle->ops.reg_dbg) {
if (phandle->ops.reg_dbg
#ifdef PCIE
&& !IS_PCIEAW693(phandle->card_type)
#endif
) {
phandle->ops.reg_dbg(phandle);
}
#endif
@ -12513,8 +12660,11 @@ void woal_moal_debug_info(moal_private *priv, moal_handle *handle, u8 flag)
if (flag && ((phandle->main_state == MOAL_END_MAIN_PROCESS) ||
(phandle->main_state == MOAL_STATE_IDLE))) {
#ifdef DEBUG_LEVEL1
if (phandle->ops.reg_dbg &&
(drvdbg & (MREG_D | MFW_D))) {
if (phandle->ops.reg_dbg && (drvdbg & (MREG_D | MFW_D))
#ifdef PCIE
&& !IS_PCIEAW693(phandle->card_type)
#endif
) {
phandle->ops.reg_dbg(phandle);
}
#endif
@ -13173,6 +13323,29 @@ done:
return;
}
/**
* @brief After STA is connected or UAP BSS_START, start recording
* active/busy time
*
* @param priv a pointer to moal_private structure
*
* @return N/A
*
*/
void woal_survey_dump_reset(moal_private *priv)
{
mlan_ds_get_stats stats;
memset(&stats, 0, sizeof(mlan_ds_get_stats));
if (MLAN_STATUS_SUCCESS ==
woal_get_stats_info(priv, MOAL_IOCTL_WAIT, &stats)) {
priv->cca_cnt_base = stats.cca_cnt_us;
priv->rx_airtime_base = stats.rxAirtime_us;
priv->tx_airtime_base = stats.txAirtime_us;
}
moal_get_host_time_ns(&priv->bss_active_time);
}
/**
* @brief This workqueue function handles woal event queue
*
@ -13311,6 +13484,24 @@ t_void woal_evt_work_queue(struct work_struct *work)
woal_print_linkstats_info((moal_private *)evt->priv,
MFALSE);
break;
#ifdef UAP_SUPPORT
case WOAL_EVENT_AGCS:
if (evt->agcs_evt.type ==
AGCS_EVENT_TYPE_PROCESS_EVENT) {
woal_process_agcs_event(
(moal_private *)evt->priv,
&evt->agcs_evt.stats);
} else if (evt->agcs_evt.type ==
AGCS_EVENT_TYPE_SEL_CHANNEL) {
woal_process_ch_sel_and_switch(
(moal_private *)evt->priv,
&evt->agcs_evt);
}
break;
#endif /* UAP_SUPPORT */
case WOAL_EVENT_SURVEY_DUMP_RESET:
woal_survey_dump_reset((moal_private *)evt->priv);
break;
default:
break;
}
@ -13666,7 +13857,11 @@ t_void woal_main_work_queue(struct work_struct *work)
}
if (handle->reg_dbg == MTRUE) {
handle->reg_dbg = MFALSE;
if (handle->ops.reg_dbg)
if (handle->ops.reg_dbg
#ifdef PCIE
&& !IS_PCIEAW693(handle->card_type)
#endif
)
handle->ops.reg_dbg(handle);
}
if (handle->fw_dbg == MTRUE) {
@ -14969,6 +15164,30 @@ int woal_request_fw_reload(moal_handle *phandle, t_u8 mode)
moal_handle *ref_handle = NULL;
ENTER();
if ((handle->params.indrstcfg & 0xff) == 1) {
if (mode == FW_RELOAD_SDIO_INBAND_RESET ||
mode == FW_RELOAD_PCIE_RESET ||
mode == FW_RELOAD_SDIO_HW_RESET ||
mode == FW_RELOAD_PCIE_INBAND_RESET) {
PRINTM(MERROR, "indrstcfg=1: mode %d is blocked\n",
mode);
LEAVE();
return -EINVAL;
}
} else if ((handle->params.indrstcfg & 0xff) == 2) {
if (mode == FW_RELOAD_NO_EMULATION ||
mode == FW_RELOAD_WITH_EMULATION) {
PRINTM(MERROR, "indrstcfg=2: mode %d is blocked\n",
mode);
LEAVE();
return -EINVAL;
}
} else {
PRINTM(MERROR, "indrstcfg=0: IR mode is disabled\n");
LEAVE();
return -EINVAL;
}
if (phandle->fw_dump) {
PRINTM(MMSG, "Ignore fw reload req, fw dump is ongoing\n");
LEAVE();

View file

@ -340,6 +340,19 @@ typedef t_u8 BOOLEAN;
#define MAX_TIME_LEN 128
#endif
/** FW cap info bit 12: 2G Support */
#ifndef ISSUPP_11AC2GENABLED
#define ISSUPP_11AC2GENABLED(FwCapInfo) (FwCapInfo & MBIT(12))
#endif
/** FW cap info bit 13: 5G Support */
#ifndef ISSUPP_11AC5GENABLED
#define ISSUPP_11AC5GENABLED(FwCapInfo) (FwCapInfo & MBIT(13))
#endif
/** FW cap info Ext bit 14: 6G Support */
#ifndef FW_CAPINFO_EXT_6G
#define FW_CAPINFO_EXT_6G MBIT(14)
#endif
/** Driver version */
extern char driver_version[MLAN_MAX_VER_STR_LEN];
@ -1295,6 +1308,10 @@ enum woal_event_type {
WOAL_EVENT_RGPWR_KEY_MISMATCH,
WOAL_EVENT_RESET_WIFI,
WOAL_EVENT_PRINT_LINKSTATS,
#ifdef UAP_SUPPORT
WOAL_EVENT_AGCS,
#endif /* UAP_SUPPORT */
WOAL_EVENT_SURVEY_DUMP_RESET,
};
/** chan_rpt_info */
@ -1328,6 +1345,10 @@ struct woal_event {
mlan_deauth_param deauth_info;
chan_radar_info radar_info;
t_u8 deauth_evt_cnt;
#ifdef UAP_SUPPORT
/** AGCS event data for WOAL_EVENT_AGCS */
agcs_event agcs_evt;
#endif /* UAP_SUPPORT */
};
};
@ -2190,6 +2211,15 @@ struct _moal_private {
moal_priv_linkstats_cfg plinkstats_cfg;
moal_priv_linkstats plinkstats;
/*BSS active time*/
t_u64 bss_active_time;
/*CCA count*/
t_u64 cca_cnt_base;
/*RX airtime count*/
t_u64 rx_airtime_base;
/*TX airtime count*/
t_u64 tx_airtime_base;
};
#ifdef SDIO
@ -2872,6 +2902,7 @@ typedef struct _moal_mod_para {
int tpe_ie_ignore;
/* make_before_break during roam */
int make_before_break;
int secure_host;
} moal_mod_para;
void woal_tp_acnt_timer_func(void *context);
@ -2945,6 +2976,41 @@ typedef struct _moal_tp_acnt_t {
moal_drv_timer timer;
} moal_tp_acnt_t;
#ifdef UAP_SUPPORT
typedef MLAN_PACK_START struct {
t_u16 action;
/* BIT0 - Enable Agile channel switching in CarPlay
* BIT1 - no specific interference type check, but only check Tx or Rx
* throughput drop
*/
t_u32 mode;
/* Adjust the weight of TX/RX average packet count */
t_u8 avg_threshold_percentage;
/* The conservative amount of rx packet per second */
t_u16 rx_min_pkt_count;
/* The conservative amount of tx packet per second */
t_u16 tx_min_pkt_count;
/* Unit is ms */
t_u32 sample_time;
/* The latest sampled windows size */
t_u8 sample_count_window;
/* Continuous drop rapidly times */
t_u8 continuous_hit_count;
/* Make sure a reasonable rate can be sustained. */
t_s8 nf_margin;
/* The channel load threshold that the new channel needs to reach. */
t_u8 chload_threshold_percentage;
/* channel switch announcement count, default is 5 */
t_u8 csa_cnt;
/** Variable number (fixed maximum) of channels to scan up */
wlan_user_scan_chan chan_list[WLAN_USER_SCAN_CHAN_MAX];
/* Long duration packets threshold */
t_u16 nav_mitigation_th;
/* ch threshold to trigger channel switch for nighthawk */
t_u16 ch_th;
} MLAN_PACK_END wlan_agcs_info;
#endif /* UAP_SUPPORT */
/** Handle data structure for MOAL */
struct _moal_handle {
/** MLAN adapter structure */
@ -3432,6 +3498,28 @@ struct _moal_handle {
t_u32 ips_ctrl;
BOOLEAN is_edmac_enabled;
bool driver_init;
#ifdef UAP_SUPPORT
/** agiled channel switch state */
t_u32 agcs_state;
/** The number of channels in the scan list */
t_u32 agcs_num_in_chan_stats;
/** Agiled channel switch info from cmd */
wlan_agcs_info agcs_info;
/* fw cap and cap_ext */
mlan_hw_info hw_info;
#endif /* UAP_SUPPORT */
void *secure;
#ifdef DUMP_TO_PROC
#if defined(PCIE)
/** ssu dump buffer total len */
t_u64 ssu_dump_len;
/** Pointer of ssu dump buffer */
t_u8 *ssu_dump_buf;
#endif
#endif
};
/**
@ -4262,10 +4350,10 @@ t_void woal_print_firmware_dump(moal_handle *phandle, char *fwdp_fname);
void woal_store_firmware_dump(moal_handle *phandle, pmlan_event pmevent);
void woal_send_fw_dump_complete_event(moal_private *priv);
#ifndef DUMP_TO_PROC
#if defined(PCIE)
void woal_store_ssu_dump(moal_handle *phandle, pmlan_event pmevent);
#endif /* SSU_SUPPORT */
#ifndef DUMP_TO_PROC
/** save hostcmd response to file */
t_void woal_save_host_cmdresp(moal_handle *phandle, mlan_cmdresp_event *pevent);
#endif
@ -4798,5 +4886,14 @@ mlan_status woal_ioctl_hostcmd_htc_cap(moal_private *priv, t_u16 action,
t_u8 *enable);
int woal_getset_regrdwr(moal_private *priv, t_u32 action, t_u32 type,
t_u32 offset, t_u32 *value);
#ifdef UAP_SUPPORT
extern void woal_process_agcs_event(moal_private *priv,
pagcs_stats pstart_event);
extern void woal_process_ch_sel_and_switch(moal_private *priv,
pagcs_event pevent);
extern mlan_status moal_agcs_trans_state(moal_private *priv,
agcs_state next_state);
extern void woal_agcs_event(moal_private *priv, pagcs_event pacs_start_event);
#endif /* UAP_SUPPORT */
#endif /* _MOAL_MAIN_H */

View file

@ -299,9 +299,7 @@ static mlan_status woal_reset_adma(moal_handle *handle)
t_u32 value;
t_u32 reset_reg = handle->card_info->fw_reset_reg;
t_u8 reset_adma_val = 0x97;
/* wake up device before set the reset reg */
handle->ops.read_reg(handle, handle->card_info->fw_wakeup_reg, &value);
udelay(100);
if (handle->ops.write_reg(handle, reset_reg, reset_adma_val) !=
MLAN_STATUS_SUCCESS) {
PRINTM(MERROR, "Failed to write register.\n");
@ -492,7 +490,11 @@ perform_init:
}
if (woal_init_fw(handle)) {
PRINTM(MFATAL, "Firmware Init Failed\n");
woal_pcie_reg_dbg(handle);
#ifdef PCIE
if (!IS_PCIEAW693(handle->card_type))
#endif
woal_pcie_reg_dbg(handle);
if (fw_serial_bkp)
moal_extflg_set(handle, EXT_FW_SERIAL);
goto err_init_fw;
@ -949,6 +951,11 @@ static void woal_pcie_reset_prepare(struct pci_dev *pdev)
pcie_service_card *card;
moal_handle *handle;
moal_handle *ref_handle = NULL;
#if defined(PCIEAW693)
pcie_service_card *ref_card = NULL;
t_u32 value;
t_u32 count = 0;
#endif
ENTER();
@ -984,8 +991,34 @@ static void woal_pcie_reset_prepare(struct pci_dev *pdev)
ref_handle = (moal_handle *)handle->pref_mac;
}
}
#if defined(PCIEAW693)
/* WAR to Poll firmware dump flag for 5 seconds */
while (count < 50 &&
(handle->fw_dump || (ref_handle && ref_handle->fw_dump))) {
woal_sched_timeout(100);
count++;
}
// This is just WAR for PRC release
/* wake up device before set the reset reg */
handle->ops.read_reg(handle, handle->card_info->fw_wakeup_reg, &value);
mdelay(50);
/*Disable L1 before start of FLR*/
pci_write_config_dword(card->dev, 0x80, 0x40);
if (ref_handle)
ref_card = (pcie_service_card *)ref_handle->card;
if (ref_card)
pci_write_config_dword(ref_card->dev, 0x80, 0x40);
#endif
handle->surprise_removed = MTRUE;
handle->fw_reseting = MTRUE;
if (ref_handle) {
ref_handle->surprise_removed = MTRUE;
ref_handle->fw_reseting = MTRUE;
}
// TODO: Can add more chips once the related code has been ported to fw
// v18
if (IS_PCIE9097(handle->card_type) || IS_PCIE9098(handle->card_type) ||
@ -995,8 +1028,6 @@ static void woal_pcie_reset_prepare(struct pci_dev *pdev)
woal_do_flr(handle, true, true);
if (ref_handle) {
ref_handle->surprise_removed = MTRUE;
ref_handle->fw_reseting = MTRUE;
woal_do_flr(ref_handle, true, true);
}
@ -1012,6 +1043,9 @@ static void woal_pcie_reset_done(struct pci_dev *pdev)
pcie_service_card *card;
moal_handle *handle;
moal_handle *ref_handle = NULL;
#if defined(PCIEAW693)
pcie_service_card *ref_card = NULL;
#endif
ENTER();
card = pci_get_drvdata(pdev);
@ -1058,6 +1092,17 @@ static void woal_pcie_reset_done(struct pci_dev *pdev)
wifi_status = WIFI_STATUS_OK;
if (handle)
woal_send_auto_recovery_complete_event(handle);
// This is just WAR for PRC release
#if defined(PCIEAW693)
/*Re-enable L1 before start of FLR*/
pci_write_config_dword(card->dev, 0x80, 0x143);
if (ref_handle)
ref_card = (pcie_service_card *)ref_handle->card;
if (ref_card)
pci_write_config_dword(ref_card->dev, 0x80, 0x143);
#endif
LEAVE();
}
#else
@ -3059,6 +3104,10 @@ static void woal_pcie_work(struct work_struct *work)
container_of(work, pcie_service_card, reset_work);
moal_handle *handle = NULL;
moal_handle *ref_handle = NULL;
#if defined(PCIEAW693)
pcie_service_card *ref_card = NULL;
t_u32 value;
#endif
handle = card->handle;
if (!handle)
return;
@ -3080,6 +3129,20 @@ static void woal_pcie_work(struct work_struct *work)
mlan_ioctl(ref_handle->pmlan_adapter, NULL);
}
}
// This is just WAR for PRC release
#if defined(PCIEAW693)
/* wake up device before set the reset reg */
handle->ops.read_reg(handle, handle->card_info->fw_wakeup_reg, &value);
mdelay(50);
/*Disable L1 state before start of IN-BAND RESET*/
pci_write_config_dword(card->dev, 0x80, 0x40);
if (ref_handle)
ref_card = (pcie_service_card *)ref_handle->card;
if (ref_card)
pci_write_config_dword(ref_card->dev, 0x80, 0x40);
#endif
handle->surprise_removed = MTRUE;
handle->fw_reseting = MTRUE;
// TODO: Can add more chips once the related code has been ported to fw
@ -3124,6 +3187,15 @@ static void woal_pcie_work(struct work_struct *work)
card->work_flags = MFALSE;
wifi_status = WIFI_STATUS_OK;
woal_send_auto_recovery_complete_event(handle);
// This is just WAR for PRC release
#if defined(PCIEAW693)
/*Re-enable L1 state once IN-BAND RESET is done*/
pci_write_config_dword(card->dev, 0x80, 0x143);
if (ref_card)
pci_write_config_dword(ref_card->dev, 0x80, 0x143);
#endif
PRINTM(MMSG, "========END IN-BAND RESET===========\n");
return;
}

View file

@ -2604,6 +2604,8 @@ static int woal_drv_dbg(moal_private *priv, struct iwreq *wrq)
#endif
printk(KERN_ALERT "MMPA_D (%08x) %s\n", MMPA_D,
(drvdbg & MMPA_D) ? "X" : "");
printk(KERN_ALERT "MSHC_D (%08x) %s\n", MSHC_D,
(drvdbg & MSHC_D) ? "X" : "");
printk(KERN_ALERT "MIF_D (%08x) %s\n", MIF_D,
(drvdbg & MIF_D) ? "X" : "");
printk(KERN_ALERT "MFW_D (%08x) %s\n", MFW_D,

View file

@ -1308,6 +1308,100 @@ static const struct file_operations fw_dump_fops = {
.release = single_release,
};
#endif
#if defined(PCIE)
static int woal_ssu_dump_read(struct seq_file *sfp, void *data)
{
moal_handle *handle = (moal_handle *)sfp->private;
int ret = 0;
t_u32 i;
t_u32 *tmpbuf;
unsigned char *sfpbuf;
char dw_string[10] = {0};
ENTER();
if (MODULE_GET == 0) {
LEAVE();
return 0;
}
if (!handle) {
PRINTM(MERROR, "handle is null!\n");
goto done;
}
if (!handle->ssu_dump_buf || !handle->ssu_dump_len) {
PRINTM(MERROR,
"ssu dump buffer is NULL or total length is zero\n");
goto done;
}
if (sfp->size < ((handle->ssu_dump_len * 9) / 4)) {
PRINTM(MCMND,
"ssu dump size too big, size=%d, ssu_dump_len=%ld\n",
(int)sfp->size,
(long int)((handle->ssu_dump_len * 9) / 4));
sfp->count = sfp->size;
ret = 0;
MODULE_PUT;
return ret;
}
tmpbuf = (t_u32 *)handle->ssu_dump_buf;
sfpbuf = sfp->buf;
for (i = 0; i < handle->ssu_dump_len / 4; i++) {
if ((i + 1) % 8 == 0)
snprintf(dw_string, sizeof(dw_string), "%08x\n",
*tmpbuf);
else
snprintf(dw_string, sizeof(dw_string), "%08x ",
*tmpbuf);
moal_memcpy_ext(handle, sfpbuf, dw_string, 9, 9);
tmpbuf++;
sfpbuf += 9;
}
sfp->count = ((handle->ssu_dump_len * 9) / 4);
moal_vfree(handle, handle->ssu_dump_buf);
handle->ssu_dump_buf = NULL;
handle->ssu_dump_len = 0;
done:
MODULE_PUT;
LEAVE();
return 0;
}
static int woal_ssu_dump_proc_open(struct inode *inode, struct file *file)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)
return single_open(file, woal_ssu_dump_read, pde_data(inode));
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)
return single_open(file, woal_ssu_dump_read, PDE_DATA(inode));
#else
return single_open(file, woal_ssu_dump_read, PDE(inode)->data);
#endif
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
static const struct proc_ops ssu_dump_fops = {
.proc_open = woal_ssu_dump_proc_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release,
};
#else
static const struct file_operations ssu_dump_fops = {
.owner = THIS_MODULE,
.open = woal_ssu_dump_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif
#endif
#endif
/**
@ -1467,6 +1561,9 @@ void woal_proc_init(moal_handle *handle)
#ifdef DUMP_TO_PROC
char drv_dump_dir[20];
char fw_dump_dir[20];
#if defined(PCIE)
char ssu_dump_dir[20];
#endif
#endif
ENTER();
@ -1552,6 +1649,22 @@ void woal_proc_init(moal_handle *handle)
#endif
if (!r)
PRINTM(MERROR, "Failed to create proc fw dump\n");
#if defined(PCIE)
strncpy(ssu_dump_dir, "ssu_dump", sizeof(ssu_dump_dir));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)
r = proc_create_data(ssu_dump_dir, 0644, handle->proc_wlan,
&ssu_dump_fops, handle);
#else
r = create_proc_entry(ssu_dump_dir, 0644, handle->proc_wlan);
if (r) {
r->data = handle;
r->proc_fops = &ssu_dump_fops;
}
#endif
if (!r)
PRINTM(MERROR, "Failed to create proc ssu dump\n");
#endif
#endif
done:
@ -1571,6 +1684,9 @@ void woal_proc_exit(moal_handle *handle)
#ifdef DUMP_TO_PROC
char drv_dump_dir[20];
char fw_dump_dir[20];
#if defined(PCIE)
char ssu_dump_dir[20];
#endif
#endif
ENTER();
@ -1584,6 +1700,10 @@ void woal_proc_exit(moal_handle *handle)
remove_proc_entry(drv_dump_dir, handle->proc_wlan);
strncpy(fw_dump_dir, "fw_dump", sizeof(fw_dump_dir));
remove_proc_entry(fw_dump_dir, handle->proc_wlan);
#if defined(PCIE)
strncpy(ssu_dump_dir, "ssu_dump", sizeof(ssu_dump_dir));
remove_proc_entry(ssu_dump_dir, handle->proc_wlan);
#endif
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
@ -1613,6 +1733,13 @@ void woal_proc_exit(moal_handle *handle)
handle->drv_dump_len = 0;
handle->drv_dump_buf = NULL;
}
#if defined(PCIE)
if (handle->ssu_dump_buf) {
moal_vfree(handle, handle->ssu_dump_buf);
handle->ssu_dump_buf = NULL;
handle->ssu_dump_len = 0;
}
#endif
#endif
LEAVE();
}

View file

@ -2278,8 +2278,13 @@ static rdwr_status woal_cmd52_rdwr_firmware(moal_handle *phandle, t_u8 doneflag,
}
if (trigger) {
PRINTM(MMSG, "Trigger FW dump...\n");
ret = woal_sdio_writeb(phandle, HOST_TO_CARD_EVENT_REG,
HOST_TO_CARD_EVENT);
if (IS_SDIW610(phandle->card_type)) {
ret = woal_sdio_writeb(phandle, HOST_TO_CARD_EVENT_REG,
HOST_RST_EVENT);
} else {
ret = woal_sdio_writeb(phandle, HOST_TO_CARD_EVENT_REG,
HOST_TO_CARD_EVENT);
}
if (ret) {
PRINTM(MERROR, "Fail to set HOST_TO_CARD_EVENT_REG\n");
return RDWR_STATUS_FAILURE;

356
mlinux/moal_shc.c Executable file
View file

@ -0,0 +1,356 @@
/** @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;
}

57
mlinux/moal_shc.h Executable file
View file

@ -0,0 +1,57 @@
/** @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_ */

View file

@ -936,7 +936,7 @@ mlan_status moal_get_hw_spec_complete(t_void *pmoal, mlan_status status,
moal_handle *handle = (moal_handle *)pmoal;
int i;
t_u32 drv_mode = handle->params.drv_mode;
#ifdef PCIE9098
#if defined(PCIE9098) || defined(PCIEAW693) || defined(SDAW693)
size_t drv_ver_len = strlen(driver_version);
#endif
ENTER();
@ -984,6 +984,47 @@ mlan_status moal_get_hw_spec_complete(t_void *pmoal, mlan_status status,
handle->driver_version[drv_ver_len] = '\0';
}
#endif
#ifdef PCIEAW693
/**
* Special/Temporary handling to manage the driver version
* string to identify AW693/IW623 based on fw_cap value set by
* Fw
*/
if ((phw->fw_cap_ext & MBIT(23)) &&
IS_PCIEAW693(handle->card_type)) {
moal_memcpy_ext(handle, driver_version, CARD_PCIEIW623,
strlen(CARD_PCIEIW623),
strlen(driver_version));
if (drv_ver_len >= MLAN_MAX_VER_STR_LEN - 1) {
drv_ver_len = MLAN_MAX_VER_STR_LEN - 1;
}
moal_memcpy_ext(handle, handle->driver_version,
driver_version, drv_ver_len,
MLAN_MAX_VER_STR_LEN - 1);
handle->driver_version[drv_ver_len] = '\0';
}
#endif
#ifdef SDAW693
/**
* Special/Temporary handling to manage the driver version
* string to identify AW693/IW623 based on fw_cap value set by
* Fw
*/
if ((phw->fw_cap_ext & MBIT(23)) &&
IS_SDAW693(handle->card_type)) {
moal_memcpy_ext(handle, driver_version, CARD_SDIW623,
strlen(CARD_SDIW623),
strlen(driver_version));
if (drv_ver_len >= MLAN_MAX_VER_STR_LEN - 1) {
drv_ver_len = MLAN_MAX_VER_STR_LEN - 1;
}
moal_memcpy_ext(handle, handle->driver_version,
driver_version, drv_ver_len,
MLAN_MAX_VER_STR_LEN - 1);
handle->driver_version[drv_ver_len] = '\0';
}
#endif
if (phw->fw_cap & FW_CAPINFO_DISABLE_NAN)
handle->params.drv_mode &= ~DRV_MODE_NAN;
/** FW should only enable DFS on one mac */
@ -1018,6 +1059,9 @@ mlan_status moal_get_hw_spec_complete(t_void *pmoal, mlan_status status,
}
PRINTM(MCMND, "org_drv_mode=0x%x drv_mode=0x%x\n", drv_mode,
handle->params.drv_mode);
moal_memcpy_ext(handle, &(handle->hw_info), phw,
sizeof(mlan_hw_info), sizeof(mlan_hw_info));
}
LEAVE();
return MLAN_STATUS_SUCCESS;
@ -3113,6 +3157,33 @@ static t_void woal_process_event_tx_status(moal_private *priv,
}
#endif
/**
* @brief This function handles survey dump reset event
*
* @param priv A pointer moal_private structure
*
* @return N/A
*/
static void woal_survey_dump_reset_event(moal_private *priv)
{
struct woal_event *evt;
unsigned long flags;
moal_handle *handle = priv->phandle;
evt = kzalloc(sizeof(struct woal_event), GFP_ATOMIC);
if (evt) {
evt->priv = priv;
evt->type = WOAL_EVENT_SURVEY_DUMP_RESET;
INIT_LIST_HEAD(&evt->link);
spin_lock_irqsave(&handle->evt_lock, flags);
list_add_tail(&evt->link, &handle->evt_queue);
spin_unlock_irqrestore(&handle->evt_lock, flags);
queue_work(handle->evt_workqueue, &handle->evt_work);
}
// coverity[misra_c_2012_rule_22_1_violation:SUPPRESS]
// coverity[leaked_storage]: SUPPRESS
}
/**
* @brief This function handles event receive
*
@ -3198,6 +3269,7 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
#if defined(STA_SUPPORT)
chan_band_reginfo_t *psta_reg_info = NULL;
#endif
wifi_chan_avoid_list_t *pwifi_chan_info = NULL;
char iwevent_str[256];
addba_timeout_event *evtbuf = NULL;
@ -3234,9 +3306,7 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
PRINTM(MEVENT, "event id:0x%x\n", pmevent->event_id);
#if defined(PCIE)
if (pmevent->event_id == MLAN_EVENT_ID_SSU_DUMP_FILE) {
#ifndef DUMP_TO_PROC
woal_store_ssu_dump(pmoal, pmevent);
#endif
goto done;
}
#endif /* SSU_SUPPORT */
@ -3305,6 +3375,8 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
netif_carrier_on(priv->netdev);
woal_wake_queue(priv->netdev);
moal_connection_status_check_pmqos(pmoal);
woal_survey_dump_reset_event(priv);
break;
case MLAN_EVENT_ID_DRV_ASSOC_FAILURE:
PRINTM(MERROR, "wlan:MLAN_EVENT_ASSOC_FAILURE\n");
@ -3403,6 +3475,7 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
priv->phandle->scan_time_start.time_usec = 0;
}
moal_agcs_trans_state(priv, AGCS_STATE_SCAN_REPORT);
break;
case MLAN_EVENT_ID_DRV_OBSS_SCAN_PARAM:
@ -3457,8 +3530,9 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
#if defined(STA_CFG80211) || defined(UAP_CFG80211)
/* 6E Indoor/Outdoor, download the default power table
* after disconnect/link-loss */
PRINTM(MEVENT, "Downloading default 6E table!!\n");
if (priv->phandle->fw_bands & BAND_6G) {
if ((priv->phandle->fw_bands & BAND_6G) &&
(priv->sme_current.channel->band == NL80211_BAND_6GHZ)) {
PRINTM(MEVENT, "Downloading default 6E table!!\n");
if (MLAN_STATUS_SUCCESS !=
woal_dnld_default_6e_psd_table(priv))
PRINTM(MERROR,
@ -4255,6 +4329,9 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
#endif
}
#endif
#ifdef UAP_SUPPORT
moal_agcs_trans_state(priv, AGCS_STATE_COMPLETE);
#endif /* UAP_SUPPORT */
break;
case MLAN_EVENT_ID_FW_STOP_TX:
woal_stop_queue(priv->netdev);
@ -4399,6 +4476,7 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
priv->chan_under_nop = MFALSE;
}
#endif
woal_survey_dump_reset_event(priv);
#endif
break;
#if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
@ -5360,6 +5438,18 @@ mlan_status moal_recv_event(t_void *pmoal, pmlan_event pmevent)
&priv->phandle->emergency_reset_work,
msecs_to_jiffies(fw_reset_time * 1000));
break;
#ifdef UAP_SUPPORT
case MLAN_EVENT_ID_FW_AGCS_TRIGGER: {
woal_agcs_event(priv, (pagcs_event)pmevent->event_buf);
} break;
#endif /* UAP_SUPPORT */
case MLAN_EVENT_ID_FW_WIFI_CHANNEL_AVOID_LIST:
pwifi_chan_info =
(wifi_chan_avoid_list_t *)(pmevent->event_buf +
sizeof(MrvlIEtypesHeader_t) +
4);
process_wifi_channel_avoid_list_event(priv, pwifi_chan_info);
break;
default:
break;
@ -5596,3 +5686,43 @@ mlan_status moal_calc_short_ssid(t_u8 *pssid, t_u32 ssid_len,
*pshort_ssid = ~crc32_le(~0, pssid, ssid_len);
return MLAN_STATUS_SUCCESS;
}
inline t_u16 moal_read_unaligned_u16(const void *src)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
return *((const t_u16 *)src);
#else
t_u16 val = 0;
memcpy(&val, src, sizeof(t_u16));
return val;
#endif
}
inline t_u32 moal_read_unaligned_u32(const void *src)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
return *((const t_u32 *)src);
#else
t_u32 val = 0;
memcpy(&val, src, sizeof(t_u32));
return val;
#endif
}
inline void moal_write_unaligned_u16(void *dest, t_u16 val)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
*((t_u16 *)dest) = val;
#else
memcpy(dest, &val, sizeof(t_u16));
#endif
}
inline void moal_write_unaligned_u32(void *dest, t_u32 val)
{
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
*((t_u32 *)dest) = val;
#else
memcpy(dest, &val, sizeof(t_u32));
#endif
}

View file

@ -4,7 +4,7 @@
* functions defined in moal module
*
*
* Copyright 2008-2021, 2024 NXP
* Copyright 2008-2021, 2025 NXP
*
* This software file (the File) is distributed by NXP
* under the terms of the GNU General Public License Version 2, June 1991
@ -129,4 +129,9 @@ void woal_release_busfreq_pmqos_remove(t_void *pmhandle);
mlan_status moal_calc_short_ssid(t_u8 *pssid, t_u32 ssid_len,
t_u32 *pshort_ssid);
inline t_u16 moal_read_unaligned_u16(const void *src);
inline t_u32 moal_read_unaligned_u32(const void *src);
inline void moal_write_unaligned_u16(void *dest, t_u16 val);
inline void moal_write_unaligned_u32(void *dest, t_u32 val);
#endif /*_MOAL_H */

View file

@ -689,6 +689,9 @@ static const struct wiphy_coalesce_support coalesce_support = {
/********************************************************
Global Variables
********************************************************/
#define delta64(later, earlier) \
((later >= earlier) ? later - earlier : \
(t_u64)(-1) - earlier + later + 1)
/********************************************************
Local Functions
@ -6816,10 +6819,14 @@ static int woal_cfg80211_dump_survey(struct wiphy *wiphy,
enum ieee80211_band band;
ChanStatistics_t *pchan_stats = NULL;
mlan_scan_resp scan_resp;
mlan_ds_get_stats stats;
t_u64 active_time = 0;
ENTER();
PRINTM(MIOCTL, "dump_survey idx=%d\n", idx);
moal_get_host_time_ns(&active_time);
memset(&scan_resp, 0, sizeof(scan_resp));
if (MLAN_STATUS_SUCCESS !=
woal_get_scan_table(priv, MOAL_IOCTL_WAIT, &scan_resp)) {
@ -6858,6 +6865,68 @@ static int woal_cfg80211_dump_survey(struct wiphy *wiphy,
survey->channel_time_busy = pchan_stats[idx].cca_busy_duration;
#endif
#endif
if (((priv->media_connected &&
(GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_STA)) ||
(priv->bss_started && (GET_BSS_ROLE(priv) == MLAN_BSS_ROLE_UAP))) &&
pchan_stats[idx].chan_num == priv->channel) {
memset(&stats, 0, sizeof(mlan_ds_get_stats));
if (MLAN_STATUS_SUCCESS ==
woal_get_stats_info(priv, MOAL_IOCTL_WAIT, &stats)) {
if (stats.cca_cnt_us != 0) {
#if CFG80211_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)
#if CFG80211_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)
survey->filled |= SURVEY_INFO_TIME |
SURVEY_INFO_TIME_BUSY |
SURVEY_INFO_TIME_RX |
SURVEY_INFO_TIME_TX;
survey->time = moal_do_div(
delta64(active_time,
priv->bss_active_time),
1000000);
survey->time_rx = moal_do_div(
delta64(stats.rxAirtime_us,
priv->rx_airtime_base),
1000);
survey->time_tx = moal_do_div(
delta64(stats.txAirtime_us,
priv->tx_airtime_base),
1000);
survey->time_busy =
moal_do_div(delta64(stats.cca_cnt_us,
priv->cca_cnt_base),
1000) +
survey->time_rx + survey->time_tx;
#else
survey->filled |=
SURVEY_INFO_CHANNEL_TIME |
SURVEY_INFO_CHANNEL_TIME_BUSY |
SURVEY_INFO_CHANNEL_TIME_RX |
SURVEY_INFO_CHANNEL_TIME_TX;
survey->channel_time = moal_do_div(
delta64(active_time,
priv->bss_active_time),
1000000);
survey->channel_time_rx = moal_do_div(
delta64(stats.rxAirtime_us,
priv->rx_airtime_base),
1000);
survey->channel_time_tx = moal_do_div(
delta64(stats.txAirtime_us,
priv->tx_airtime_base),
1000);
survey->channel_time_busy =
moal_do_div(delta64(stats.cca_cnt_us,
priv->cca_cnt_base),
1000) +
survey->channel_time_rx +
survey->channel_time_tx;
#endif
#endif
}
}
}
done:
LEAVE();
return ret;
@ -10958,6 +11027,13 @@ void woal_host_mlme_disconnect(moal_private *priv, u16 reason_code, u8 *sa)
);
#else
cfg80211_rx_mgmt(priv->netdev, freq, frame_buf, 26, GFP_ATOMIC);
#endif
#if CFG80211_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)
// Send Deauth frame to packet fate monitor framework
woal_packet_fate_monitor(priv, PACKET_TYPE_RX,
RX_PKT_FATE_SUCCESS,
FRAME_TYPE_80211_MGMT, 0, 0, frame_buf,
26);
#endif
}

View file

@ -1868,13 +1868,14 @@ static int woal_cfg80211_beacon_config(moal_private *priv,
->ht_cap.cap &
0x13ff)) |
0x0c;
else
else if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
sys_config->ht_cap_info =
(ht_cap &
(wiphy->bands[IEEE80211_BAND_5GHZ]
->ht_cap.cap &
0x13ff)) |
0x0c;
}
}
PRINTM(MCMND,
"11n=%d, ht_cap=0x%x, channel=%d, bandcfg:chanBand=0x%x chanWidth=0x%x chan2Offset=0x%x scanMode=0x%x\n",
@ -3224,14 +3225,19 @@ void woal_remove_virtual_interface(moal_handle *handle)
ref_handle->priv_num -= ref_vir_intf;
}
#endif
if (handle->mon_if) {
if (handle->mon_if && handle->mon_if->mon_ndev) {
netif_device_detach(handle->mon_if->mon_ndev);
if (handle->mon_if->mon_ndev->reg_state == NETREG_REGISTERED)
if (handle->mon_if->mon_ndev->reg_state == NETREG_REGISTERED) {
#if CFG80211_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
cfg80211_unregister_netdevice(handle->mon_if->mon_ndev);
if (handle->mon_if->mon_ndev->ieee80211_ptr)
cfg80211_unregister_netdevice(
handle->mon_if->mon_ndev);
else
unregister_netdevice(handle->mon_if->mon_ndev);
#else
unregister_netdevice(handle->mon_if->mon_ndev);
#endif
}
handle->mon_if = NULL;
}
rtnl_unlock();

315
nanotls/include/nanotls-common.h Executable file
View file

@ -0,0 +1,315 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_COMMON_H
#define NANOTLS_COMMON_H
#include <nanotls-config.h>
#include <nanotls-hooks.h>
#include <nanotls-proto.h>
#include <nanotls-types.h>
#include <uassert.h>
// TODO: cleanup
#undef memset
#define ABS(x) (((x) < 0) ? -(x) : (x))
#define offsetdiff(s, field_a, field_b) \
ABS(offsetof(s, field_b) - offsetof(s, field_a))
enum ecode nanotls_mem_eq(const void *a, const void *b, size_t size);
void nanotls_mem_erase(void *buf, size_t size);
static inline void nanotls_hdr_init(struct nanotls_message_hdr *hdr, size_t len,
enum nanotls_message_id id)
{
hdr->magic = NANOTLS_MAGIC;
hdr->len = (uint16_t)len;
hdr->message_id = (uint8_t)id;
hdr->protocol_version = NANOTLS_VERSION;
}
static inline enum ecode
nanotls_hdr_check(const struct nanotls_message_hdr *hdr, size_t len,
enum nanotls_message_id id)
{
if (hdr->magic != NANOTLS_MAGIC)
return E_INVALID;
if (hdr->len != (uint16_t)len)
return E_INVALID;
if (hdr->message_id != (uint8_t)id)
return E_INVALID;
if (hdr->protocol_version != NANOTLS_VERSION)
return E_INVALID;
return E_OK;
}
static inline enum ecode nanotls_data_add_init(struct nanotls_data_add *add,
size_t data_size)
{
if (data_size > NANOTLS_MAX_DATA_LEN)
return E_INVALID;
memset(add, 0, sizeof(*add));
add->version = NANOTLS_VERSION;
add->len = data_size;
return E_OK;
}
void nanotls_hkdf_sha256_extract(const void *salt, size_t salt_len,
const void *ikm, size_t ikm_len,
uint8_t prk_result[NANOTLS_SHA256_HASH_SIZE]);
/*
* TLS HKDF-Expand-Label(Secret, Label, Context, Hash.length) =
* HKDF-Expand(Secret, Length || Label || Context, Length) =
* HMAC-Hash(Secret, Length || Label || Context || 0x01, Length)
*
* Here Length is fixed to 32.
*/
void nanotls_hkdf_expand_label(const uint8_t secret[NANOTLS_SHA256_HASH_SIZE],
const void *label, size_t label_size,
const uint8_t *context, size_t context_size,
void *output, size_t output_length);
/* TLS Derive-Secret with fixed context size = hash size */
static inline void
nanotls_hkdf_derive_secret(const uint8_t secret[NANOTLS_SHA256_HASH_SIZE],
const void *label, size_t label_size,
const uint8_t context[NANOTLS_SHA256_HASH_SIZE],
uint8_t output[NANOTLS_SECRET_SIZE])
{
nanotls_hkdf_expand_label(secret, label, label_size, context,
NANOTLS_SHA256_HASH_SIZE, output,
NANOTLS_SECRET_SIZE);
}
/*
* HKDF-Expand-Label(Secret, Label, Context = "", Length) =
* HKDF-Expand(Secret, Length || Label || Context, Length) =
* HKDF-Expand(Secret, Length || Label, Length)
*/
static inline void
nanotls_hkdf_expand_label_noctx(const uint8_t secret[NANOTLS_SHA256_HASH_SIZE],
const void *label, size_t label_size,
uint8_t *output, size_t output_length)
{
nanotls_hkdf_expand_label(secret, label, label_size, NULL, 0, output,
output_length);
}
static inline void nanotls_derive_master_secret(
uint8_t master_secret[NANOTLS_SECRET_SIZE],
const uint8_t handshake_secret[NANOTLS_SECRET_SIZE])
{
uint8_t zeroes[NANOTLS_HASH_SIZE] = {0};
uint8_t dhs[NANOTLS_SECRET_SIZE];
nanotls_hkdf_expand_label_noctx(handshake_secret, NANOTLS_DERIVED_LABEL,
dhs, sizeof(dhs));
nanotls_hkdf_sha256_extract(dhs, sizeof(dhs), zeroes, sizeof(zeroes),
master_secret);
nanotls_mem_erase(dhs, sizeof(dhs));
}
void nanotls_write_finished(const nanotls_sha_ctx *handshake_hash,
const uint8_t hs_traffic_secret[NANOTLS_SECRET_SIZE],
uint8_t verify_data[NANOTLS_SHA256_HASH_SIZE]);
void nanotls_derive_key_iv(uint8_t key[NANOTLS_KEY_SIZE],
uint8_t iv[NANOTLS_IV_SIZE],
const uint8_t secret[NANOTLS_SECRET_SIZE]);
static inline void
nanotls_handshake_encrypt(void *buf, size_t size, struct auth_tag *auth_tag,
const uint8_t traffic_secret[NANOTLS_SECRET_SIZE])
{
#ifdef NANOTLS_CONFIG_ENCRYPTED_HANDSHAKE
nanotls_aes_context aes_ctx;
const struct nanotls_data_add add = {.version = NANOTLS_VERSION,
.len = (uint16_t)size};
uint8_t key[NANOTLS_KEY_SIZE];
uint8_t iv[NANOTLS_KEY_SIZE];
uassert(size <= NANOTLS_MAX_DATA_LEN);
nanotls_derive_key_iv(key, iv, traffic_secret);
nanotls_aes_ctx_init(&aes_ctx, key);
nanotls_mem_erase(key, sizeof(key));
nanotls_aes_encrypt(&aes_ctx, buf, buf, size, iv, &add, sizeof(add),
auth_tag->tag);
nanotls_mem_erase(iv, sizeof(iv));
nanotls_aes_ctx_destroy(&aes_ctx);
#else
(void)buf;
(void)size;
(void)auth_tag;
(void)traffic_secret;
#endif
}
static inline enum ecode nanotls_handshake_decrypt_verify(
void *buf, size_t size, const struct auth_tag *auth_tag,
const uint8_t traffic_secret[NANOTLS_SECRET_SIZE])
{
#ifdef NANOTLS_CONFIG_ENCRYPTED_HANDSHAKE
nanotls_aes_context aes_ctx;
const struct nanotls_data_add add = {.version = NANOTLS_VERSION,
.len = (uint16_t)size};
uint8_t key[NANOTLS_KEY_SIZE];
uint8_t iv[NANOTLS_KEY_SIZE];
uint8_t tag_calc[NANOTLS_AUTH_TAG_SIZE];
uassert(size <= NANOTLS_MAX_DATA_LEN);
nanotls_derive_key_iv(key, iv, traffic_secret);
nanotls_aes_ctx_init(&aes_ctx, key);
nanotls_mem_erase(key, sizeof(key));
nanotls_aes_decrypt(&aes_ctx, buf, buf, size, iv, &add, sizeof(add),
tag_calc);
nanotls_mem_erase(iv, sizeof(iv));
nanotls_aes_ctx_destroy(&aes_ctx);
return nanotls_mem_eq(tag_calc, auth_tag->tag, sizeof(tag_calc));
#else
(void)buf;
(void)size;
(void)auth_tag;
(void)traffic_secret;
return E_OK;
#endif
}
static inline void
nanotls_handshake_sig_hash(const uint8_t transcript_hash[NANOTLS_HASH_SIZE],
const char *context, size_t context_len,
uint8_t output_hash[NANOTLS_SHA256_HASH_SIZE])
{
nanotls_sha_ctx sha_ctx;
const uint8_t zero = 0;
/*
* The digital signature is then computed over the concatenation of:
* - A string that consists of octet 32 (0x20) repeated 64 times
* - The context string
* - A single 0 byte which serves as the separator
* - The content to be signed
*/
memset(output_hash, 0x20, NANOTLS_SHA256_HASH_SIZE);
nanotls_sha256_init(&sha_ctx);
/* 2x hash size = block size of 0x20 */
nanotls_sha256_update(&sha_ctx, output_hash, NANOTLS_SHA256_HASH_SIZE);
nanotls_sha256_update(&sha_ctx, output_hash, NANOTLS_SHA256_HASH_SIZE);
nanotls_sha256_update(&sha_ctx, context, context_len);
nanotls_sha256_update(&sha_ctx, &zero, sizeof(zero));
nanotls_sha256_update(&sha_ctx, transcript_hash,
NANOTLS_SHA256_HASH_SIZE);
nanotls_sha256_digest_final(&sha_ctx, output_hash);
}
static inline void nanotls_derive_traffic_keys(
const uint8_t master_secret[NANOTLS_SECRET_SIZE],
const uint8_t transcript_hash[NANOTLS_SHA256_HASH_SIZE],
const uint8_t *instance_label, size_t instance_label_len,
struct nanotls_traffic_keys *keys)
{
/*
* Device application traffic secret:
* device_traffic_secret = Derive-Secret(master_secret, label,
* transcript_hash(HostHello || DeviceHello || HostFinished)) =
* HKDF-Expand(master_secret, 32 || label || transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(master_secret, NANOTLS_DEVICE_AP_TS_LABEL,
transcript_hash, keys->d2h_secret);
if (instance_label) {
/*
* Device application traffic (instance) secret:
* device_traffic_secret_n =
* HKDF-Expand-Label(device_traffic_secret, instance_label, "")
*/
nanotls_hkdf_expand_label_noctx(
keys->d2h_secret, instance_label, instance_label_len,
keys->d2h_secret, NANOTLS_SECRET_SIZE);
}
nanotls_derive_key_iv(keys->d2h_key, keys->d2h_iv, keys->d2h_secret);
/*
* Host application traffic secret:
* host_traffic_secret = Derive-Secret(master_secret, label,
* transcript_hash(HostHello || DeviceHello || HostFinished)) =
* HKDF-Expand(master_secret, 32 || label || transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(master_secret, NANOTLS_HOST_AP_TS_LABEL,
transcript_hash, keys->h2d_secret);
if (instance_label) {
/*
* Host application traffic (instance) secret:
* host_traffic_secret_n =
* HKDF-Expand-Label(host_traffic_secret, instance_label, "")
*/
nanotls_hkdf_expand_label_noctx(
keys->h2d_secret, instance_label, instance_label_len,
keys->h2d_secret, NANOTLS_SECRET_SIZE);
}
nanotls_derive_key_iv(keys->h2d_key, keys->h2d_iv, keys->h2d_secret);
}
#ifdef NANOTLS_CONFIG_KEY_UPDATE
static inline enum ecode
nanotls_update_traffic_secret(uint8_t secret[NANOTLS_SECRET_SIZE],
uint8_t key[NANOTLS_KEY_SIZE],
uint8_t iv[NANOTLS_IV_SIZE])
{
/*
* Update the D2H traffic secret:
* xxx_secret(N+1) = HKDF-Expand-Label(xxx_secret(N), label, "")
*/
nanotls_hkdf_expand_label_noctx(secret, NANOTLS_KEY_UPDATE_LABEL,
secret, NANOTLS_SECRET_SIZE);
nanotls_derive_key_iv(key, iv, secret);
return E_OK;
}
#endif
#endif /* NANOTLS_COMMON_H */

View file

@ -0,0 +1,67 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_CONFIG_H
#define NANOTLS_CONFIG_H
/* nanoTLS compile-time configuration options */
/*
* Harden implementation against glitching, SCA, etc.
* Will increase the code size.
*/
//#define NANOTLS_CONFIG_HARDENING
/*
* Enable support for key update
*/
#define NANOTLS_CONFIG_KEY_UPDATE
/*
* Maximum number of failures during handshake before transitioning
* into error state.
* If not defined, then there is no limit (unsafe).
*/
#ifndef NANOTLS_CONFIG_MAX_ERR_CNT
#define NANOTLS_CONFIG_MAX_ERR_CNT 4
#endif
/*
* Maximum number of consecutive data AES-GCM tag failures before going into
* error state and erasing the keys. If not defined, then there is no limit
* (unsafe).
*/
#ifndef NANOTLS_CONFIG_MAX_DATA_TAG_MISMATCH_CNT
#define NANOTLS_CONFIG_MAX_DATA_TAG_MISMATCH_CNT 256
#endif
/*
* Enable encryption during handshake.
* ECDSA signature and Finished messages are encrypted.
* AES-GCM is used and authentication tag is generated and verified.
* Introduces dependency on AES API during handshake.
*
* NB: TLS 1.2 does not encrypt these messages, encryption introduced in TLS 1.3
*/
#define NANOTLS_CONFIG_ENCRYPTED_HANDSHAKE
#endif /* NANOTLS_CONFIG_H */

100
nanotls/include/nanotls-data.h Executable file
View file

@ -0,0 +1,100 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_DATA_H
#define NANOTLS_DATA_H
#include <linux/types.h>
#include <asm/string.h>
#include <nanotls-common.h>
#include <nanotls-proto.h>
#include <nanotls-hooks.h>
/*
* NanoTLS data layer - used for message encryption/decryption
* once handshake is completed.
*/
struct nanotls_ctx_data {
enum nanotls_role role;
uint64_t enc_seq_no;
uint8_t enc_iv[NANOTLS_IV_SIZE];
nanotls_aes_context aes_enc;
size_t enc_len_remaining;
uint64_t dec_seq_no;
uint8_t dec_iv[NANOTLS_IV_SIZE];
nanotls_aes_context aes_dec;
size_t dec_len_remaining;
size_t dec_tag_mismatch_count;
#ifdef NANOTLS_CONFIG_KEY_UPDATE
uint8_t enc_secret[NANOTLS_SECRET_SIZE];
uint8_t dec_secret[NANOTLS_SECRET_SIZE];
#endif
};
enum ecode nanotls_data_ctx_init(struct nanotls_ctx_data *ctx,
enum nanotls_role role,
const struct nanotls_traffic_keys *keys);
enum ecode nanotls_data_ctx_destroy(struct nanotls_ctx_data *ctx);
enum ecode nanotls_data_write_start(struct nanotls_ctx_data *ctx,
size_t data_size);
/*
* All but the final invocation MUST be called with length mod 16 == 0.
* Only the final call can have a partial block length of < 128 bits.
*/
enum ecode nanotls_data_write_update(struct nanotls_ctx_data *ctx,
void *enc_out, const void *plain_in,
size_t data_size);
enum ecode nanotls_data_write_finish(struct nanotls_ctx_data *ctx,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
enum ecode nanotls_data_write(struct nanotls_ctx_data *ctx, void *enc_out,
const void *plain_in, size_t data_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
enum ecode nanotls_data_read_start(struct nanotls_ctx_data *ctx,
size_t data_size);
/*
* All but the final invocation MUST be called with length mod 16 == 0.
* Only the final call can have a partial block length of < 128 bits.
*/
enum ecode nanotls_data_read_update(struct nanotls_ctx_data *ctx,
void *plain_out, const void *enc_in,
size_t data_size);
enum ecode
nanotls_data_read_finish(struct nanotls_ctx_data *ctx,
const uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
enum ecode nanotls_data_read(struct nanotls_ctx_data *ctx, void *plain_out,
const void *enc_in, size_t data_size,
const uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
#ifdef NANOTLS_CONFIG_KEY_UPDATE
enum ecode nanotls_data_write_key_update(struct nanotls_ctx_data *ctx);
enum ecode nanotls_data_read_key_update(struct nanotls_ctx_data *ctx);
#endif
#endif /* NANOTLS_DATA_H */

101
nanotls/include/nanotls-device.h Executable file
View file

@ -0,0 +1,101 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_DEVICE_H
#define NANOTLS_DEVICE_H
#include <nanotls-config.h>
#include <nanotls-hooks.h>
#include <nanotls-proto.h>
enum nanotls_device_state {
NANOTLS_DEV_UNINIT = 0,
#ifdef NANOTLS_CONFIG_HARDENING
NANOTLS_DEV_INIT = 0x32eaf5,
NANOTLS_DEV_HELLO_RCVD = 0x7a52ae,
NANOTLS_DEV_HELLO_SENT = 0x5e3a0a,
NANOTLS_DEV_DONE = 0xb09835,
NANOTLS_DEV_ERR = 0xed2312,
#else
NANOTLS_DEV_INIT,
NANOTLS_DEV_HELLO_RCVD,
NANOTLS_DEV_HELLO_SENT,
NANOTLS_DEV_DONE,
NANOTLS_DEV_ERR = -1,
#endif
};
struct nanotls_device_ctx {
enum nanotls_device_state state;
size_t error_count;
struct nanotls_device_info device_info;
/* ECDSA - Authentication */
uint8_t ecdsa_priv[NANOTLS_ECDSA_PRIVATE_KEY_SIZE];
/* ECDH - Key negotiation */
uint8_t ecdh_priv[NANOTLS_ECDH_PRIVATE_KEY_SIZE];
struct nanotls_key_share host_key_share;
/* Running transcript hash context */
nanotls_sha_ctx handshake_hash;
uint8_t handshake_h2_hash[NANOTLS_HASH_SIZE];
uint8_t handshake_secret[NANOTLS_SECRET_SIZE];
uint8_t master_secret[NANOTLS_SECRET_SIZE];
};
/**
* Initialize the device handshake context.
*
* @param ctx device handshake context
* @param ecdsa_priv device ECDSA private key (matching the host public key)
* @param device_info device information to be forwarded to the host as part of
* DeviceHello. Could optionally be NULL, then device_info will be filled with
* zeroes.
* @return E_OK in case of success, error code otherwise
*/
enum ecode
nanotls_device_init(struct nanotls_device_ctx *ctx,
const uint8_t ecdsa_priv[NANOTLS_ECDSA_PRIVATE_KEY_SIZE],
const struct nanotls_device_info *device_info);
enum ecode nanotls_device_host_hello_rcvd(struct nanotls_device_ctx *ctx,
const struct nanotls_host_hello *msg);
enum ecode nanotls_device_do_hello(struct nanotls_device_ctx *ctx,
struct nanotls_device_hello *msg);
enum ecode nanotls_device_host_finished_rcvd(struct nanotls_device_ctx *ctx,
struct nanotls_host_finished *msg);
enum ecode nanotls_device_derive_traffic_keys_instance(
const struct nanotls_device_ctx *ctx, struct nanotls_traffic_keys *keys,
size_t instance_idx);
enum ecode
nanotls_device_derive_traffic_keys(const struct nanotls_device_ctx *ctx,
struct nanotls_traffic_keys *keys);
enum ecode nanotls_device_cleanup(struct nanotls_device_ctx *ctx);
#endif /* NANOTLS_DEVICE_H */

121
nanotls/include/nanotls-hooks.h Executable file
View file

@ -0,0 +1,121 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_HOOKS_H
#define NANOTLS_HOOKS_H
#include <linux/types.h>
#include <asm/string.h>
#include <nanotls-types.h>
#include <sha2.h>
#include <hmac.h>
#include <gcm.h>
#define NANOTLS_SHA256_HASH_SIZE 32
#define NANOTLS_SHA256_BLOCK_SIZE 64
typedef cf_sha256_context nanotls_sha_ctx;
typedef cf_hmac_ctx nanotls_hmac_ctx;
// TODO: cleanup
#undef MIN
#undef MAX
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define ROUND_UP(x, align) ((((x) + (align)-1) / (align)) * (align))
#define ROUND_DN(x, align) (((x) / (align)) * (align))
// TODO: cleanup
//#define DIV_ROUND_UP(x, y) (((x) + (y)-1) / (y))
enum ecode nanotls_secure_random(void *buf, size_t size);
enum ecode nanotls_p256_gen_keypair(uint8_t priv[32], uint8_t pub[64]);
enum ecode nanotls_p256_ecdh_shared_secret(uint8_t secret[32],
const uint8_t priv[32],
const uint8_t pub[64]);
enum ecode nanotls_p256_ecdsa_sign(uint8_t sig[64], const uint8_t priv[32],
const uint8_t *hash, size_t hlen);
enum ecode nanotls_p256_ecdsa_verify(const uint8_t sig[64],
const uint8_t pub[64], const uint8_t *hash,
size_t hlen);
enum ecode nanotls_sha256_init(nanotls_sha_ctx *ctx);
enum ecode nanotls_sha256_update(nanotls_sha_ctx *ctx, const void *buf,
size_t size);
enum ecode nanotls_sha256_digest(const nanotls_sha_ctx *ctx,
uint8_t hash[NANOTLS_SHA256_HASH_SIZE]);
enum ecode nanotls_sha256_digest_final(nanotls_sha_ctx *ctx,
uint8_t hash[NANOTLS_SHA256_HASH_SIZE]);
enum ecode nanotls_hmac_sha256_init(nanotls_hmac_ctx *ctx, const void *key,
size_t key_size);
enum ecode nanotls_hmac_sha256_update(nanotls_hmac_ctx *ctx, const void *data,
size_t data_size);
enum ecode nanotls_hmac_sha256_finish(nanotls_hmac_ctx *ctx,
uint8_t result[NANOTLS_SHA256_HASH_SIZE]);
enum ecode nanotls_hmac_sha256(const void *key, size_t key_size,
const void *data, size_t data_size,
uint8_t result[NANOTLS_SHA256_HASH_SIZE]);
/*
* AES API - needed post-handshake.
* Only AES-GCM-128 is supported with fixed 12 byte IV size.
*/
#define NANOTLS_AES_KEY_SIZE 16
#define NANOTLS_AES_IV_SIZE 12
#define NANOTLS_AES_GCM_TAG_SIZE 16
typedef gcm_context nanotls_aes_context;
enum ecode nanotls_aes_ctx_init(nanotls_aes_context *ctx,
const uint8_t key[NANOTLS_AES_KEY_SIZE]);
enum ecode nanotls_aes_start_enc(nanotls_aes_context *ctx,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size);
enum ecode nanotls_aes_start_dec(nanotls_aes_context *ctx,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size);
/*
* All but the final invocation MUST be called with length mod 16 == 0.
* Only the final call can have a partial block length of < 128 bits.
*/
enum ecode nanotls_aes_update(nanotls_aes_context *ctx, void *out,
const void *in, size_t data_size);
enum ecode nanotls_aes_finish(nanotls_aes_context *ctx,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
enum ecode nanotls_aes_ctx_destroy(nanotls_aes_context *ctx);
enum ecode nanotls_aes_encrypt(nanotls_aes_context *ctx, void *out_data,
const void *in_data, size_t data_size,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
enum ecode nanotls_aes_decrypt(nanotls_aes_context *ctx, void *out_data,
const void *in_data, size_t data_size,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE]);
#endif /* NANOTLS_HOOKS_H */

145
nanotls/include/nanotls-host.h Executable file
View file

@ -0,0 +1,145 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_HOST_H
#define NANOTLS_HOST_H
#include <nanotls-config.h>
#include <nanotls-hooks.h>
#include <nanotls-proto.h>
enum nanotls_host_state {
NANOTLS_HOST_UNINIT = 0,
#ifdef NANOTLS_CONFIG_HARDENING
NANOTLS_HOST_INIT = 0x32eaf5,
NANOTLS_HOST_HELLO_SENT = 0x7a52ae,
NANOTLS_HOST_HELLO_RCVD = 0x5e3a0a,
NANOTLS_HOST_DONE = 0xb09835,
NANOTLS_HOST_ERR = 0xed2312,
#else
NANOTLS_HOST_INIT,
NANOTLS_HOST_HELLO_SENT,
NANOTLS_HOST_HELLO_RCVD,
NANOTLS_HOST_DONE,
NANOTLS_HOST_ERR = -1,
#endif
};
struct nanotls_host_ctx;
/**
* Public key request callback.
* A callback called from nanotls_host_device_hello_rcvd() called to
* request a device public key if it has not been provided during context init
* time.
* @param ctx [in] host handshake context (for reference)
* @param device_info [in] device information data provided by the device in
* DeviceHello. Could be used by the driver to narrow down the FW image search.
* @param ecdsa_pub [out] destination buffer callback function should write
* resulting ecdsa public key to
* @return E_OK in case of public key found and successfully written to
* ecdsa_pub buffer, error code otherwise
*/
typedef enum ecode (*nanotls_host_pub_key_req_cb)(
const struct nanotls_host_ctx *ctx,
const struct nanotls_device_info *device_info,
uint8_t ecdsa_pub[NANOTLS_ECDSA_PUBLIC_KEY_SIZE]);
struct nanotls_host_ctx {
enum nanotls_host_state state;
size_t error_count;
struct nanotls_device_info device_info;
/* ECDSA - Authentication */
uint8_t ecdsa_pub[NANOTLS_ECDSA_PUBLIC_KEY_SIZE];
nanotls_host_pub_key_req_cb pub_key_req_cb; /* callback to request the
public key */
/* ECDH - Key negotiation */
uint8_t ecdh_priv[NANOTLS_ECDH_PRIVATE_KEY_SIZE];
struct nanotls_key_share device_key_share;
/* Running transcript hash context */
nanotls_sha_ctx handshake_hash;
uint8_t handshake_h2_hash[NANOTLS_HASH_SIZE];
uint8_t handshake_secret[NANOTLS_SECRET_SIZE];
uint8_t master_secret[NANOTLS_SECRET_SIZE];
};
/**
* Initialize the host handshake context with the known public key.
*
* This init function flavor assumes the public key is known at the init time.
*
* @param ctx host handshake context
* @param ecdsa_pub host ECDSA public key (matching the device private key)
* @return E_OK in case of success, error code otherwise
*/
enum ecode
nanotls_host_init(struct nanotls_host_ctx *ctx,
const uint8_t ecdsa_pub[NANOTLS_ECDSA_PUBLIC_KEY_SIZE]);
/**
* Initialize the host handshake context with deferred public key lookup.
*
* This init function flavor assumes the public key is not known at the init
* time, so the pub_key_req_cb callback is called from
* nanotls_host_device_hello_rcvd() to look up and provide the public key using
* device_info provided in DeviceHello.
*
* @param ctx host handshake context
* @param pub_key_req_cb a callback to be called from
* nanotls_host_device_hello_rcvd() to provide lookup for the public key using
* device_info provided in DeviceHello.
* @return E_OK in case of success, error code otherwise
*/
enum ecode
nanotls_host_init_pubkey_cb(struct nanotls_host_ctx *ctx,
nanotls_host_pub_key_req_cb pub_key_req_cb);
enum ecode nanotls_host_do_hello(struct nanotls_host_ctx *ctx,
struct nanotls_host_hello *msg);
enum ecode nanotls_host_device_hello_rcvd(struct nanotls_host_ctx *ctx,
struct nanotls_device_hello *msg);
/* Get device info after DeviceHello has been processed */
enum ecode
nanotls_host_get_device_info(const struct nanotls_host_ctx *ctx,
struct nanotls_device_info *device_info);
enum ecode nanotls_host_do_finished(struct nanotls_host_ctx *ctx,
struct nanotls_host_finished *msg);
enum ecode
nanotls_host_derive_traffic_keys_instance(const struct nanotls_host_ctx *ctx,
struct nanotls_traffic_keys *keys,
size_t instance_idx);
enum ecode nanotls_host_derive_traffic_keys(const struct nanotls_host_ctx *ctx,
struct nanotls_traffic_keys *keys);
enum ecode nanotls_host_cleanup(struct nanotls_host_ctx *ctx);
#endif /* NANOTLS_HOST_H */

188
nanotls/include/nanotls-proto.h Executable file
View file

@ -0,0 +1,188 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_PROTO_H
#define NANOTLS_PROTO_H
#include <linux/types.h>
#include <asm/string.h>
#include <nanotls-config.h>
#define NANOTLS_MAGIC 0x43b826f3
#define NANOTLS_VERSION 1
#define NANOTLS_HASH_SIZE NANOTLS_SHA256_HASH_SIZE
#define NANOTLS_SECRET_SIZE NANOTLS_HASH_SIZE
#define NANOTLS_KEY_SIZE (128 / 8)
#define NANOTLS_IV_SIZE 12
#define NANOTLS_AUTH_TAG_SIZE 16
#define NANOTLS_ECDSA_PUBLIC_KEY_SIZE 64
#define NANOTLS_ECDSA_PRIVATE_KEY_SIZE 32
#define NANOTLS_ECDH_PUBLIC_KEY_SIZE 64
#define NANOTLS_ECDH_PRIVATE_KEY_SIZE 32
#define NANOTLS_UUID_LEN 16
#define NANOTLS_MAX_DATA_LEN 0xFFFF
#define NANOTLS_LABEL(string) string, strlen(string)
#define NANOTLS_DEVICE_HS_TS_LABEL NANOTLS_LABEL("D HS TS")
#define NANOTLS_DEVICE_AP_TS_LABEL NANOTLS_LABEL("D AP TS")
#define NANOTLS_HOST_HS_TS_LABEL NANOTLS_LABEL("H HS TS")
#define NANOTLS_HOST_AP_TS_LABEL NANOTLS_LABEL("H AP TS")
#define NANOTLS_FINISHED_LABEL NANOTLS_LABEL("finished")
#define NANOTLS_DERIVED_LABEL NANOTLS_LABEL("derived")
#define NANOTLS_KEY_UPDATE_LABEL NANOTLS_LABEL("key update")
#define NANOTLS_KEY_INSTANCE_LABEL NANOTLS_LABEL("key instance")
#define NANOTLS_DEVICE_HS_SIG_LABEL NANOTLS_LABEL("D HS SIG")
#define NANOTLS_HOST_HS_SIG_LABEL NANOTLS_LABEL("H HS SIG")
#define NANOTLS_KEYING_IV_LABEL NANOTLS_LABEL("iv")
#define NANOTLS_KEYING_KEY_LABEL NANOTLS_LABEL("key")
enum nanotls_message_id {
NANOTLS_HOST_HELLO = 1,
NANOTLS_DEVICE_HELLO = 2,
NANOTLS_HOST_FINISHED = 3,
};
enum nanotls_signature_algorithm {
NANOTLS_ECDSA_SECP256R1_SHA256 = 0x0403,
};
enum nanotls_key_exchange_type {
NANOTLS_ECDHE_SECP256R1 = 0x0017,
};
enum nanotls_cipher_suite {
NANOTLS_AES_128_GCM_SHA256 = 0x1301,
};
struct nanotls_key_share {
uint8_t pubkey[NANOTLS_ECDH_PUBLIC_KEY_SIZE]; /* P-256 ECDH public key,
two points */
};
struct nanotls_message_hdr {
uint32_t magic;
uint16_t len;
uint8_t message_id;
uint8_t protocol_version;
};
struct nanotls_signature {
uint8_t sig[64]; /* P-256 ECDSA signature, two points */
};
struct nanotls_finished {
uint8_t verify_data[32];
};
struct auth_tag {
uint8_t tag[NANOTLS_AUTH_TAG_SIZE];
};
struct nanotls_host_hello {
struct nanotls_message_hdr hdr;
uint16_t sig_alg;
uint16_t key_exchange_type;
uint16_t cipher_suite;
uint16_t reserved;
uint8_t random[32];
struct nanotls_key_share host_key_share; /* ECDHE */
};
/* DeviceHello's submessage */
struct nanotls_device_info {
uint16_t chip_id;
uint16_t device_flags;
uint8_t reserved[12];
uint8_t uuid[NANOTLS_UUID_LEN];
};
struct nanotls_device_hello {
struct nanotls_message_hdr hdr;
uint32_t reserved;
uint8_t random[32];
struct nanotls_key_share device_key_share; /* ECDHE */
/* Encrypted portion */
struct {
struct nanotls_device_info device_info; /* aka Certificate */
struct nanotls_signature device_handshake_sig; /* aka TLS
CertificateVerify
*/
struct nanotls_finished device_finished;
} enc;
struct auth_tag auth_tag; /* Auth tag for the encrypted portion */
};
#define NANOTLS_DEVICE_HELLO_SIG_CUTOFF_POS \
offsetof(struct nanotls_device_hello, enc)
#define NANOTLS_DEVICE_HELLO_FINISHED_ENC_CUTOFF_POS \
(offsetof(struct nanotls_device_hello, enc.device_finished) - \
NANOTLS_DEVICE_HELLO_SIG_CUTOFF_POS)
struct nanotls_host_finished {
struct nanotls_message_hdr hdr;
uint32_t reserved;
/* Encrypted portion */
struct {
struct nanotls_signature reserved2;
struct nanotls_finished host_finished;
} enc;
struct auth_tag auth_tag; /* Auth tag for the encrypted portion */
};
#define NANOTLS_HOST_HELLO_FINISHED_CUTOFF_POS \
offsetof(struct nanotls_host_finished, enc.host_finished)
struct nanotls_data_add {
uint8_t version; /* NANOTLS_VERSION */
uint8_t reserved[5]; /* zeroes */
uint16_t len;
};
struct nanotls_traffic_keys {
/*
* Data secrets are saved for future possible key update.
* !! Should not be used directly for encryption/decryption.
* !! Keys should be derived from it using HDKF-Expand().
*/
uint8_t h2d_secret[NANOTLS_SECRET_SIZE];
uint8_t d2h_secret[NANOTLS_SECRET_SIZE];
/* These keys below should be used for message encryption/decryption */
uint8_t h2d_iv[NANOTLS_IV_SIZE];
uint8_t h2d_key[NANOTLS_KEY_SIZE];
uint8_t d2h_iv[NANOTLS_IV_SIZE];
uint8_t d2h_key[NANOTLS_KEY_SIZE];
};
#endif /* NANOTLS_PROTO_H */

52
nanotls/include/nanotls-types.h Executable file
View file

@ -0,0 +1,52 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_TYPES_H
#define NANOTLS_TYPES_H
#include <nanotls-config.h>
enum nanotls_role {
NANOTLS_ROLE_UNKNOWN = 0,
#ifdef NANOTLS_CONFIG_HARDENING
NANOTLS_ROLE_HOST = 0x1ea71e,
NANOTLS_ROLE_DEVICE = 0xdb25cc,
#else
NANOTLS_ROLE_HOST = 1,
NANOTLS_ROLE_DEVICE = 2,
#endif
};
enum ecode {
#ifdef NANOTLS_CONFIG_HARDENING
/* Error codes with big Hamming distance for better hardening */
/* Not trivial enough, but still could be generated with single RISC-V
instruction */
E_OK = -1446, /* 0xFFFFFA5A */
E_INVALID = 0x153E95A5, /* Invalid value or state */
#else
E_OK = 0,
E_INVALID = -1,
#endif
};
#endif /* NANOTLS_TYPES_H */

63
nanotls/lib/aes/include/aes.h Executable file
View file

@ -0,0 +1,63 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef AES_HEADER
#define AES_HEADER
#include <linux/types.h>
#include <asm/string.h>
#define AES_CONFIG_128_BIT_ONLY
enum aes_op_mode {
AES_MODE_NONE = 0,
AES_MODE_ENCRYPT = 0x231d14,
AES_MODE_DECRYPT = 0x1676a1,
};
/******************************************************************************
* AES_CONTEXT : cipher context / holds inter-call data
******************************************************************************/
typedef struct {
int rounds; // keysize-based rounds count
uint32_t *rk; // pointer to current round key
uint32_t buf[68]; // key expansion buffer
} aes_context;
/******************************************************************************
* AES_SETKEY : called to expand the key for encryption or decryption
******************************************************************************/
int aes_setkey(aes_context *ctx, // pointer to context
const uint8_t *key, // AES input key
size_t keysize); // size in bytes (must be 16, 24, 32 for
// 128, 192 or 256-bit keys respectively)
// returns 0 for success
/******************************************************************************
* AES_CIPHER : called to encrypt or decrypt ONE 128-bit block of data
******************************************************************************/
int aes_cipher(aes_context *ctx, // pointer to context
const uint8_t input[16], // 128-bit block to en/decipher
uint8_t output[16]); // 128-bit output result block
// returns 0 for success
#endif /* AES_HEADER */

View file

@ -0,0 +1,246 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef AES_TABLES_H
#define AES_TABLES_H
#include <linux/types.h>
#include <asm/string.h>
/* Forward substitution box (FSb) */
static const uint8_t FSb[256] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
0xb0, 0x54, 0xbb, 0x16};
/* Forward key schedule assembly tables */
static const uint32_t FT0[256] = {
0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, 0xbd6b6bd6,
0xb16f6fde, 0x54c5c591, 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56,
0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec, 0x45caca8f, 0x9d82821f,
0x40c9c989, 0x877d7dfa, 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb,
0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453,
0x967272e4, 0x5bc0c09b, 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c,
0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, 0x5c343468, 0xf4a5a551,
0x34e5e5d1, 0x08f1f1f9, 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a,
0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637,
0x0f05050a, 0xb59a9a2f, 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df,
0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, 0x1b090912, 0x9e83831d,
0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b,
0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, 0x7b292952, 0x3ee3e3dd,
0x712f2f5e, 0x97848413, 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1,
0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, 0xbe6a6ad4, 0x46cbcb8d,
0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85,
0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, 0xc5434386, 0xd74d4d9a,
0x55333366, 0x94858511, 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe,
0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b, 0xf35151a2, 0xfea3a35d,
0xc0404080, 0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1,
0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020, 0x1affffe5,
0x0ef3f3fd, 0x6dd2d2bf, 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3,
0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e, 0x57c4c493, 0xf2a7a755,
0x827e7efc, 0x473d3d7a, 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6,
0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54,
0xab90903b, 0x8388880b, 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428,
0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, 0x3be0e0db, 0x56323264,
0x4e3a3a74, 0x1e0a0a14, 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8,
0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531,
0x37e4e4d3, 0x8b7979f2, 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda,
0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, 0xb46c6cd8, 0xfa5656ac,
0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810,
0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, 0x241c1c38, 0xf1a6a657,
0xc7b4b473, 0x51c6c697, 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e,
0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, 0x907070e0, 0x423e3e7c,
0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c,
0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, 0x91868617, 0x58c1c199,
0x271d1d3a, 0xb99e9e27, 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122,
0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433, 0xb69b9b2d, 0x221e1e3c,
0x92878715, 0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5,
0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65, 0x31e6e6d7,
0xc6424284, 0xb86868d0, 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e,
0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c,
};
static const uint32_t FT1[256] = {
0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, 0xf2f2ff0d, 0x6b6bd6bd,
0x6f6fdeb1, 0xc5c59154, 0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d,
0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a, 0xcaca8f45, 0x82821f9d,
0xc9c98940, 0x7d7dfa87, 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b,
0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, 0x9c9c23bf, 0xa4a453f7,
0x7272e496, 0xc0c09b5b, 0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a,
0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f, 0x3434685c, 0xa5a551f4,
0xe5e5d134, 0xf1f1f908, 0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f,
0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e, 0x18183028, 0x969637a1,
0x05050a0f, 0x9a9a2fb5, 0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d,
0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f, 0x0909121b, 0x83831d9e,
0x2c2c5874, 0x1a1a342e, 0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb,
0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce, 0x2929527b, 0xe3e3dd3e,
0x2f2f5e71, 0x84841397, 0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c,
0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed, 0x6a6ad4be, 0xcbcb8d46,
0xbebe67d9, 0x3939724b, 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a,
0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, 0x434386c5, 0x4d4d9ad7,
0x33336655, 0x85851194, 0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81,
0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3, 0x5151a2f3, 0xa3a35dfe,
0x404080c0, 0x8f8f058a, 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104,
0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, 0x10102030, 0xffffe51a,
0xf3f3fd0e, 0xd2d2bf6d, 0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f,
0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39, 0xc4c49357, 0xa7a755f2,
0x7e7efc82, 0x3d3d7a47, 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695,
0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f, 0x22224466, 0x2a2a547e,
0x90903bab, 0x88880b83, 0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c,
0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76, 0xe0e0db3b, 0x32326456,
0x3a3a744e, 0x0a0a141e, 0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4,
0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6, 0x919139a8, 0x959531a4,
0xe4e4d337, 0x7979f28b, 0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7,
0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0, 0x6c6cd8b4, 0x5656acfa,
0xf4f4f307, 0xeaeacf25, 0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018,
0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72, 0x1c1c3824, 0xa6a657f1,
0xb4b473c7, 0xc6c69751, 0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21,
0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85, 0x7070e090, 0x3e3e7c42,
0xb5b571c4, 0x6666ccaa, 0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12,
0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, 0x86861791, 0xc1c19958,
0x1d1d3a27, 0x9e9e27b9, 0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233,
0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7, 0x9b9b2db6, 0x1e1e3c22,
0x87871592, 0xe9e9c920, 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a,
0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, 0xbfbf65da, 0xe6e6d731,
0x424284c6, 0x6868d0b8, 0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11,
0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a,
};
static const uint32_t FT2[256] = {
0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, 0xf2ff0df2, 0x6bd6bd6b,
0x6fdeb16f, 0xc59154c5, 0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b,
0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76, 0xca8f45ca, 0x821f9d82,
0xc98940c9, 0x7dfa877d, 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0,
0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, 0x9c23bf9c, 0xa453f7a4,
0x72e49672, 0xc09b5bc0, 0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26,
0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc, 0x34685c34, 0xa551f4a5,
0xe5d134e5, 0xf1f908f1, 0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15,
0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3, 0x18302818, 0x9637a196,
0x050a0f05, 0x9a2fb59a, 0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2,
0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75, 0x09121b09, 0x831d9e83,
0x2c58742c, 0x1a342e1a, 0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0,
0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3, 0x29527b29, 0xe3dd3ee3,
0x2f5e712f, 0x84139784, 0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced,
0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b, 0x6ad4be6a, 0xcb8d46cb,
0xbe67d9be, 0x39724b39, 0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf,
0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, 0x4386c543, 0x4d9ad74d,
0x33665533, 0x85119485, 0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f,
0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8, 0x51a2f351, 0xa35dfea3,
0x4080c040, 0x8f058a8f, 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5,
0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, 0x10203010, 0xffe51aff,
0xf3fd0ef3, 0xd2bf6dd2, 0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec,
0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917, 0xc49357c4, 0xa755f2a7,
0x7efc827e, 0x3d7a473d, 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573,
0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc, 0x22446622, 0x2a547e2a,
0x903bab90, 0x880b8388, 0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14,
0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db, 0xe0db3be0, 0x32645632,
0x3a744e3a, 0x0a141e0a, 0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c,
0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662, 0x9139a891, 0x9531a495,
0xe4d337e4, 0x79f28b79, 0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d,
0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9, 0x6cd8b46c, 0x56acfa56,
0xf4f307f4, 0xeacf25ea, 0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808,
0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e, 0x1c38241c, 0xa657f1a6,
0xb473c7b4, 0xc69751c6, 0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f,
0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a, 0x70e09070, 0x3e7c423e,
0xb571c4b5, 0x66ccaa66, 0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e,
0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, 0x86179186, 0xc19958c1,
0x1d3a271d, 0x9e27b99e, 0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311,
0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794, 0x9b2db69b, 0x1e3c221e,
0x87159287, 0xe9c920e9, 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf,
0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, 0xbf65dabf, 0xe6d731e6,
0x4284c642, 0x68d0b868, 0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f,
0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16,
};
static const uint32_t FT3[256] = {
0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, 0xff0df2f2, 0xd6bd6b6b,
0xdeb16f6f, 0x9154c5c5, 0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b,
0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676, 0x8f45caca, 0x1f9d8282,
0x8940c9c9, 0xfa877d7d, 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0,
0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, 0x23bf9c9c, 0x53f7a4a4,
0xe4967272, 0x9b5bc0c0, 0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626,
0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc, 0x685c3434, 0x51f4a5a5,
0xd134e5e5, 0xf908f1f1, 0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515,
0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3, 0x30281818, 0x37a19696,
0x0a0f0505, 0x2fb59a9a, 0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2,
0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575, 0x121b0909, 0x1d9e8383,
0x58742c2c, 0x342e1a1a, 0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0,
0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3, 0x527b2929, 0xdd3ee3e3,
0x5e712f2f, 0x13978484, 0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded,
0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b, 0xd4be6a6a, 0x8d46cbcb,
0x67d9bebe, 0x724b3939, 0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf,
0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, 0x86c54343, 0x9ad74d4d,
0x66553333, 0x11948585, 0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f,
0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8, 0xa2f35151, 0x5dfea3a3,
0x80c04040, 0x058a8f8f, 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5,
0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, 0x20301010, 0xe51affff,
0xfd0ef3f3, 0xbf6dd2d2, 0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec,
0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717, 0x9357c4c4, 0x55f2a7a7,
0xfc827e7e, 0x7a473d3d, 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373,
0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc, 0x44662222, 0x547e2a2a,
0x3bab9090, 0x0b838888, 0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414,
0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb, 0xdb3be0e0, 0x64563232,
0x744e3a3a, 0x141e0a0a, 0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c,
0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262, 0x39a89191, 0x31a49595,
0xd337e4e4, 0xf28b7979, 0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d,
0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9, 0xd8b46c6c, 0xacfa5656,
0xf307f4f4, 0xcf25eaea, 0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808,
0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e, 0x38241c1c, 0x57f1a6a6,
0x73c7b4b4, 0x9751c6c6, 0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f,
0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a, 0xe0907070, 0x7c423e3e,
0x71c4b5b5, 0xccaa6666, 0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e,
0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, 0x17918686, 0x9958c1c1,
0x3a271d1d, 0x27b99e9e, 0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111,
0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494, 0x2db69b9b, 0x3c221e1e,
0x15928787, 0xc920e9e9, 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf,
0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, 0x65dabfbf, 0xd731e6e6,
0x84c64242, 0xd0b86868, 0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f,
0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616,
};
/* AES round constants */
static const uint8_t RCON[10] = {0x01, 0x02, 0x04, 0x08, 0x10,
0x20, 0x40, 0x80, 0x1b, 0x36};
#endif /* AES_TABLES_H */

172
nanotls/lib/aes/include/gcm.h Executable file
View file

@ -0,0 +1,172 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef GCM_HEADER
#define GCM_HEADER
#define GCM_AUTH_FAILURE 0x55555555 // authentication failure
#include "aes.h" // gcm_context includes aes_context
#include <linux/types.h>
#include <asm/string.h>
#define AES_GCM_FIXED_12_BYTE_IV
/******************************************************************************
* GCM_CONTEXT : GCM context / holds keytables, instance data, and AES ctx
******************************************************************************/
typedef struct {
enum aes_op_mode mode; // cipher direction: encrypt/decrypt
uint64_t len; // cipher data length processed so far
uint64_t add_len; // total add data length
uint64_t HL[16]; // precalculated lo-half HTable
uint64_t HH[16]; // precalculated hi-half HTable
uint8_t base_ectr[16]; // first counter-mode cipher output for tag
uint8_t y[16]; // the current cipher-input IV|Counter value
uint8_t buf[16]; // buf working value
aes_context aes_ctx; // cipher context used
} gcm_context;
/******************************************************************************
* GCM_SETKEY : sets the GCM (and AES) keying material for use
******************************************************************************/
int gcm_setkey(gcm_context *ctx, // caller-provided context ptr
const uint8_t *key, // pointer to cipher key
const size_t keysize // size in bytes (must be 16, 24, 32 for
// 128, 192 or 256-bit keys respectively)
); // returns 0 for success
/******************************************************************************
*
* GCM_CRYPT_AND_TAG
*
* This either encrypts or decrypts the user-provided data and, either
* way, generates an authentication tag of the requested length. It must be
* called with a GCM context whose key has already been set with GCM_SETKEY.
*
* The user would typically call this explicitly to ENCRYPT a buffer of data
* and optional associated data, and produce its an authentication tag.
*
* To reverse the process the user would typically call the companion
* GCM_AUTH_DECRYPT function to decrypt data and verify a user-provided
* authentication tag. The GCM_AUTH_DECRYPT function calls this function
* to perform its decryption and tag generation, which it then compares.
*
******************************************************************************/
int gcm_crypt_and_tag(gcm_context *ctx, // gcm context with key already setup
enum aes_op_mode mode, // cipher direction: ENCRYPT (1) or
// DECRYPT (0)
const uint8_t *iv, // pointer to the 12-byte
// initialization vector
size_t iv_len, // byte length if the IV. should always be
// 12
const uint8_t *add, // pointer to the non-ciphered
// additional data
size_t add_len, // byte length of the additional AEAD data
const uint8_t *input, // pointer to the cipher data source
uint8_t *output, // pointer to the cipher data destination
size_t length, // byte length of the cipher data
uint8_t *tag, // pointer to the tag to be generated
size_t tag_len); // byte length of the tag to be generated
/******************************************************************************
*
* GCM_AUTH_DECRYPT
*
* This DECRYPTS a user-provided data buffer with optional associated data.
* It then verifies a user-supplied authentication tag against the tag just
* re-created during decryption to verify that the data has not been altered.
*
* This function calls GCM_CRYPT_AND_TAG (above) to perform the decryption
* and authentication tag generation.
*
******************************************************************************/
int gcm_auth_decrypt(gcm_context *ctx, // gcm context with key already setup
const uint8_t *iv, // pointer to the 12-byte initialization
// vector
size_t iv_len, // byte length if the IV. should always be
// 12
const uint8_t *add, // pointer to the non-ciphered
// additional data
size_t add_len, // byte length of the additional AEAD data
const uint8_t *input, // pointer to the cipher data source
uint8_t *output, // pointer to the cipher data destination
size_t length, // byte length of the cipher data
const uint8_t *tag, // pointer to the tag to be
// authenticated
size_t tag_len); // byte length of the tag <= 16
/******************************************************************************
*
* GCM_START
*
* Given a user-provided GCM context, this initializes it, sets the encryption
* mode, and preprocesses the initialization vector and additional AEAD data.
*
******************************************************************************/
int gcm_start(gcm_context *ctx, // pointer to user-provided GCM context
enum aes_op_mode mode, // ENCRYPT (1) or DECRYPT (0)
const uint8_t *iv, // pointer to initialization vector
size_t iv_len, // IV length in bytes (should == 12)
const uint8_t *add, // pointer to additional AEAD data (NULL if
// none)
size_t add_len); // length of additional AEAD data (bytes)
/******************************************************************************
*
* GCM_UPDATE
*
* This is called once or more to process bulk plaintext or ciphertext data.
* We give this some number of bytes of input and it returns the same number
* of output bytes. If called multiple times (which is fine) all but the final
* invocation MUST be called with length mod 16 == 0. (Only the final call can
* have a partial block length of < 128 bits.)
*
******************************************************************************/
int gcm_update(gcm_context *ctx, // pointer to user-provided GCM context
size_t length, // length, in bytes, of data to process
const uint8_t *input, // pointer to source data
uint8_t *output); // pointer to destination data
/******************************************************************************
*
* GCM_FINISH
*
* This is called once after all calls to GCM_UPDATE to finalize the GCM.
* It performs the final GHASH to produce the resulting authentication TAG.
*
******************************************************************************/
int gcm_finish(gcm_context *ctx, // pointer to user-provided GCM context
uint8_t *tag, // ptr to tag buffer - NULL if tag_len = 0
size_t tag_len); // length, in bytes, of the tag-receiving buf
/******************************************************************************
*
* GCM_ZERO_CTX
*
* The GCM context contains both the GCM context and the AES context.
* This includes keying and key-related material which is security-
* sensitive, so it MUST be zeroed after use. This function does that.
*
******************************************************************************/
void gcm_zero_ctx(gcm_context *ctx);
#endif /* GCM_HEADER */

294
nanotls/lib/aes/src/aes.c Executable file
View file

@ -0,0 +1,294 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include "aes.h"
/*
* The following static local tables must be filled-in before the first use of
* the GCM or AES ciphers. They are used for the AES key expansion/scheduling
* and once built are read-only and thread safe.
*
* NOTE: GCM Encryption/Decryption does NOT REQUIRE AES decryption. Since
* GCM uses AES in counter-mode, where the AES cipher output is XORed with
* the GCM input, we ONLY NEED AES encryption.
*/
#include <aes_tables.h>
enum aes_rounds {
AES_128_ROUNDS = 10,
AES_192_ROUNDS = 12,
AES_256_ROUNDS = 14,
};
/*
* Platform Endianness Neutralizing Load and Store Macro definitions
* AES wants platform-neutral Little Endian (LE) byte ordering
*/
#define GET_UINT32_LE(n, b, i) \
{ \
(n) = ((uint32_t)(b)[(i)]) | ((uint32_t)(b)[(i) + 1] << 8) | \
((uint32_t)(b)[(i) + 2] << 16) | \
((uint32_t)(b)[(i) + 3] << 24); \
}
#define PUT_UINT32_LE(n, b, i) \
{ \
(b)[(i)] = (uint8_t)((n)); \
(b)[(i) + 1] = (uint8_t)((n) >> 8); \
(b)[(i) + 2] = (uint8_t)((n) >> 16); \
(b)[(i) + 3] = (uint8_t)((n) >> 24); \
}
/*
* AES forward and reverse encryption round processing macros
*/
#define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \
{ \
X0 = *RK++ ^ FT0[(Y0)&0xFF] ^ FT1[(Y1 >> 8) & 0xFF] ^ \
FT2[(Y2 >> 16) & 0xFF] ^ FT3[(Y3 >> 24) & 0xFF]; \
\
X1 = *RK++ ^ FT0[(Y1)&0xFF] ^ FT1[(Y2 >> 8) & 0xFF] ^ \
FT2[(Y3 >> 16) & 0xFF] ^ FT3[(Y0 >> 24) & 0xFF]; \
\
X2 = *RK++ ^ FT0[(Y2)&0xFF] ^ FT1[(Y3 >> 8) & 0xFF] ^ \
FT2[(Y0 >> 16) & 0xFF] ^ FT3[(Y1 >> 24) & 0xFF]; \
\
X3 = *RK++ ^ FT0[(Y3)&0xFF] ^ FT1[(Y0 >> 8) & 0xFF] ^ \
FT2[(Y1 >> 16) & 0xFF] ^ FT3[(Y2 >> 24) & 0xFF]; \
}
#define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \
{ \
X0 = *RK++ ^ RT0[(Y0)&0xFF] ^ RT1[(Y3 >> 8) & 0xFF] ^ \
RT2[(Y2 >> 16) & 0xFF] ^ RT3[(Y1 >> 24) & 0xFF]; \
\
X1 = *RK++ ^ RT0[(Y1)&0xFF] ^ RT1[(Y0 >> 8) & 0xFF] ^ \
RT2[(Y3 >> 16) & 0xFF] ^ RT3[(Y2 >> 24) & 0xFF]; \
\
X2 = *RK++ ^ RT0[(Y2)&0xFF] ^ RT1[(Y1 >> 8) & 0xFF] ^ \
RT2[(Y0 >> 16) & 0xFF] ^ RT3[(Y3 >> 24) & 0xFF]; \
\
X3 = *RK++ ^ RT0[(Y3)&0xFF] ^ RT1[(Y2 >> 8) & 0xFF] ^ \
RT2[(Y1 >> 16) & 0xFF] ^ RT3[(Y0 >> 24) & 0xFF]; \
}
/*
* These macros improve the readability of the key
* generation initialization code by collapsing
* repetitive common operations into logical pieces.
*/
#define ROTL8(x) ((x << 8) & 0xFFFFFFFF) | (x >> 24)
#define XTIME(x) ((x << 1) ^ ((x & 0x80) ? 0x1B : 0x00))
#define MUL(x, y) ((x && y) ? pow[(log[x] + log[y]) % 255] : 0)
#define MIX(x, y) \
{ \
y = ((y << 1) | (y >> 7)) & 0xFF; \
x ^= y; \
}
#define CPY128 \
{ \
*RK++ = *SK++; \
*RK++ = *SK++; \
*RK++ = *SK++; \
*RK++ = *SK++; \
}
/******************************************************************************
*
* AES_SET_ENCRYPTION_KEY
*
* This is called by 'aes_setkey' when we're establishing a key for
* subsequent encryption. We give it a pointer to the encryption
* context, a pointer to the key, and the key's length in bytes.
* Valid lengths are: 16, 24 or 32 bytes (128, 192, 256 bits).
*
******************************************************************************/
int aes_set_encryption_key(aes_context *ctx, const uint8_t *key, size_t keysize)
{
size_t i; // general purpose iteration local
uint32_t *RK = ctx->rk; // initialize our RoundKey buffer pointer
for (i = 0; i < (keysize >> 2); i++) {
GET_UINT32_LE(RK[i], key, i << 2);
}
switch (ctx->rounds) {
case 10:
for (i = 0; i < 10; i++, RK += 4) {
RK[4] = RK[0] ^ (uint32_t)RCON[i] ^
((uint32_t)FSb[(RK[3] >> 8) & 0xFF]) ^
((uint32_t)FSb[(RK[3] >> 16) & 0xFF] << 8) ^
((uint32_t)FSb[(RK[3] >> 24) & 0xFF] << 16) ^
((uint32_t)FSb[(RK[3]) & 0xFF] << 24);
RK[5] = RK[1] ^ RK[4];
RK[6] = RK[2] ^ RK[5];
RK[7] = RK[3] ^ RK[6];
}
break;
#ifndef AES_CONFIG_128_BIT_ONLY
case 12:
for (i = 0; i < 8; i++, RK += 6) {
RK[6] = RK[0] ^ (uint32_t)RCON[i] ^
((uint32_t)FSb[(RK[5] >> 8) & 0xFF]) ^
((uint32_t)FSb[(RK[5] >> 16) & 0xFF] << 8) ^
((uint32_t)FSb[(RK[5] >> 24) & 0xFF] << 16) ^
((uint32_t)FSb[(RK[5]) & 0xFF] << 24);
RK[7] = RK[1] ^ RK[6];
RK[8] = RK[2] ^ RK[7];
RK[9] = RK[3] ^ RK[8];
RK[10] = RK[4] ^ RK[9];
RK[11] = RK[5] ^ RK[10];
}
break;
case 14:
for (i = 0; i < 7; i++, RK += 8) {
RK[8] = RK[0] ^ (uint32_t)RCON[i] ^
((uint32_t)FSb[(RK[7] >> 8) & 0xFF]) ^
((uint32_t)FSb[(RK[7] >> 16) & 0xFF] << 8) ^
((uint32_t)FSb[(RK[7] >> 24) & 0xFF] << 16) ^
((uint32_t)FSb[(RK[7]) & 0xFF] << 24);
RK[9] = RK[1] ^ RK[8];
RK[10] = RK[2] ^ RK[9];
RK[11] = RK[3] ^ RK[10];
RK[12] = RK[4] ^ ((uint32_t)FSb[(RK[11]) & 0xFF]) ^
((uint32_t)FSb[(RK[11] >> 8) & 0xFF] << 8) ^
((uint32_t)FSb[(RK[11] >> 16) & 0xFF] << 16) ^
((uint32_t)FSb[(RK[11] >> 24) & 0xFF] << 24);
RK[13] = RK[5] ^ RK[12];
RK[14] = RK[6] ^ RK[13];
RK[15] = RK[7] ^ RK[14];
}
break;
#endif
default:
return -1;
}
return (0);
}
/******************************************************************************
*
* AES_SETKEY
*
* Invoked to establish the key schedule for subsequent encryption/decryption
*
******************************************************************************/
int aes_setkey(aes_context *ctx, // AES context provided by our caller
const uint8_t *key, // pointer to the key
size_t keysize) // key length in bytes
{
ctx->rk = ctx->buf; // initialize our round key pointer
switch (keysize) // set the rounds count based upon the keysize
{
case 16:
ctx->rounds = AES_128_ROUNDS;
break; // 16-byte, 128-bit key
#ifndef AES_CONFIG_128_BIT_ONLY
case 24:
ctx->rounds = AES_192_ROUNDS;
break; // 24-byte, 192-bit key
case 32:
ctx->rounds = AES_256_ROUNDS;
break; // 32-byte, 256-bit key
#endif
default:
return (-1);
}
return (aes_set_encryption_key(ctx, key, keysize));
}
/******************************************************************************
*
* AES_CIPHER
*
* Perform AES encryption and decryption.
* The AES context will have been setup with the encryption mode
* and all keying information appropriate for the task.
*
******************************************************************************/
int aes_cipher(aes_context *ctx, const uint8_t input[16], uint8_t output[16])
{
uint32_t *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; // general purpose locals
size_t rounds_loop = (ctx->rounds >> 1) - 1;
int i;
#ifdef AES_CONFIG_128_BIT_ONLY
rounds_loop = (AES_128_ROUNDS >> 1) - 1;
#endif
RK = ctx->rk;
GET_UINT32_LE(X0, input, 0);
X0 ^= *RK++; // load our 128-bit
GET_UINT32_LE(X1, input, 4);
X1 ^= *RK++; // input buffer in a storage
GET_UINT32_LE(X2, input, 8);
X2 ^= *RK++; // memory endian-neutral way
GET_UINT32_LE(X3, input, 12);
X3 ^= *RK++;
for (i = (ctx->rounds >> 1) - 1; i > 0; i--) {
AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3);
}
AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
X0 = *RK++ ^ ((uint32_t)FSb[(Y0)&0xFF]) ^
((uint32_t)FSb[(Y1 >> 8) & 0xFF] << 8) ^
((uint32_t)FSb[(Y2 >> 16) & 0xFF] << 16) ^
((uint32_t)FSb[(Y3 >> 24) & 0xFF] << 24);
X1 = *RK++ ^ ((uint32_t)FSb[(Y1)&0xFF]) ^
((uint32_t)FSb[(Y2 >> 8) & 0xFF] << 8) ^
((uint32_t)FSb[(Y3 >> 16) & 0xFF] << 16) ^
((uint32_t)FSb[(Y0 >> 24) & 0xFF] << 24);
X2 = *RK++ ^ ((uint32_t)FSb[(Y2)&0xFF]) ^
((uint32_t)FSb[(Y3 >> 8) & 0xFF] << 8) ^
((uint32_t)FSb[(Y0 >> 16) & 0xFF] << 16) ^
((uint32_t)FSb[(Y1 >> 24) & 0xFF] << 24);
X3 = *RK++ ^ ((uint32_t)FSb[(Y3)&0xFF]) ^
((uint32_t)FSb[(Y0 >> 8) & 0xFF] << 8) ^
((uint32_t)FSb[(Y1 >> 16) & 0xFF] << 16) ^
((uint32_t)FSb[(Y2 >> 24) & 0xFF] << 24);
PUT_UINT32_LE(X0, output, 0);
PUT_UINT32_LE(X1, output, 4);
PUT_UINT32_LE(X2, output, 8);
PUT_UINT32_LE(X3, output, 12);
return (0);
}
/* end of aes.c */

522
nanotls/lib/aes/src/gcm.c Executable file
View file

@ -0,0 +1,522 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include "gcm.h"
#include "aes.h"
#include <uassert.h>
/******************************************************************************
* ==== IMPLEMENTATION WARNING ====
*
* This code was developed for use within SQRL's fixed environmnent. Thus, it
* is somewhat less "general purpose" than it would be if it were designed as
* a general purpose AES-GCM library. Specifically, it bothers with almost NO
* error checking on parameter limits, buffer bounds, etc. It assumes that it
* is being invoked by its author or by someone who understands the values it
* expects to receive. Its behavior will be undefined otherwise.
*
* All functions that might fail are defined to return 'ints' to indicate a
* problem. Most do not do so now. But this allows for error propagation out
* of internal functions if robust error checking should ever be desired.
*
******************************************************************************/
/* Calculating the "GHASH"
*
* There are many ways of calculating the so-called GHASH in software, each with
* a traditional size vs performance tradeoff. The GHASH (Galois field hash) is
* an intriguing construction which takes two 128-bit strings (also the cipher's
* block size and the fundamental operation size for the system) and hashes them
* into a third 128-bit result.
*
* Many implementation solutions have been worked out that use large precomputed
* table lookups in place of more time consuming bit fiddling, and this approach
* can be scaled easily upward or downward as needed to change the time/space
* tradeoff. It's been studied extensively and there's a solid body of theory
* and practice. For example, without using any lookup tables an implementation
* might obtain 119 cycles per byte throughput, whereas using a simple, though
* large, key-specific 64 kbyte 8-bit lookup table the performance jumps to 13
* cycles per byte.
*
* And Intel's processors have, since 2010, included an instruction which does
* the entire 128x128->128 bit job in just several 64x64->128 bit pieces.
*
* Since SQRL is interactive, and only processing a few 128-bit blocks, I've
* settled upon a relatively slower but appealing small-table compromise which
* folds a bunch of not only time consuming but also bit twiddling into a simple
* 16-entry table which is attributed to Victor Shoup's 1996 work while at
* Bellcore: "On Fast and Provably Secure MessageAuthentication Based on
* Universal Hashing." See: http://www.shoup.net/papers/macs.pdf
* See, also section 4.1 of the "gcm-revised-spec" cited above.
*/
/*
* This 16-entry table of pre-computed constants is used by the
* GHASH multiplier to improve over a strictly table-free but
* significantly slower 128x128 bit multiple within GF(2^128).
*/
static const uint64_t last4[16] = {0x0000, 0x1c20, 0x3840, 0x2460,
0x7080, 0x6ca0, 0x48c0, 0x54e0,
0xe100, 0xfd20, 0xd940, 0xc560,
0x9180, 0x8da0, 0xa9c0, 0xb5e0};
/*
* Platform Endianness Neutralizing Load and Store Macro definitions
* GCM wants platform-neutral Big Endian (BE) byte ordering
*/
#define GET_UINT32_BE(n, b, i) \
{ \
(n) = ((uint32_t)(b)[(i)] << 24) | \
((uint32_t)(b)[(i) + 1] << 16) | \
((uint32_t)(b)[(i) + 2] << 8) | \
((uint32_t)(b)[(i) + 3]); \
}
#define PUT_UINT32_BE(n, b, i) \
{ \
(b)[(i)] = (uint8_t)((n) >> 24); \
(b)[(i) + 1] = (uint8_t)((n) >> 16); \
(b)[(i) + 2] = (uint8_t)((n) >> 8); \
(b)[(i) + 3] = (uint8_t)((n)); \
}
/******************************************************************************
*
* GCM_MULT
*
* Performs a GHASH operation on the 128-bit input vector 'x', setting
* the 128-bit output vector to 'x' times H using our precomputed tables.
* 'x' and 'output' are seen as elements of GCM's GF(2^128) Galois field.
*
******************************************************************************/
static void gcm_mult(gcm_context *ctx, // pointer to established context
const uint8_t x[16], // pointer to 128-bit input vector
uint8_t output[16]) // pointer to 128-bit output vector
{
int i;
uint8_t lo, hi, rem;
uint64_t zh, zl;
lo = (uint8_t)(x[15] & 0x0f);
hi = (uint8_t)(x[15] >> 4);
zh = ctx->HH[lo];
zl = ctx->HL[lo];
for (i = 15; i >= 0; i--) {
lo = (uint8_t)(x[i] & 0x0f);
hi = (uint8_t)(x[i] >> 4);
if (i != 15) {
rem = (uint8_t)(zl & 0x0f);
zl = (zh << 60) | (zl >> 4);
zh = (zh >> 4);
zh ^= (uint64_t)last4[rem] << 48;
zh ^= ctx->HH[lo];
zl ^= ctx->HL[lo];
}
rem = (uint8_t)(zl & 0x0f);
zl = (zh << 60) | (zl >> 4);
zh = (zh >> 4);
zh ^= (uint64_t)last4[rem] << 48;
zh ^= ctx->HH[hi];
zl ^= ctx->HL[hi];
}
PUT_UINT32_BE(zh >> 32, output, 0);
PUT_UINT32_BE(zh, output, 4);
PUT_UINT32_BE(zl >> 32, output, 8);
PUT_UINT32_BE(zl, output, 12);
}
/******************************************************************************
*
* GCM_SETKEY
*
* This is called to set the AES-GCM key. It initializes the AES key
* and populates the gcm context's pre-calculated HTables.
*
******************************************************************************/
int gcm_setkey(gcm_context *ctx, // pointer to caller-provided gcm context
const uint8_t *key, // pointer to the AES encryption key
const size_t keysize) // size in bytes (must be 16, 24, 32 for
// 128, 192 or 256-bit keys respectively)
{
int ret, i, j;
uint64_t hi, lo;
uint64_t vl, vh;
unsigned char h[16];
memset(ctx, 0, sizeof(gcm_context)); // zero caller-provided GCM context
memset(h, 0, 16); // initialize the block to encrypt
ctx->mode = AES_MODE_NONE;
// encrypt the null 128-bit block to generate a key-based value
// which is then used to initialize our GHASH lookup tables
if ((ret = aes_setkey(&ctx->aes_ctx, key, keysize)) != 0)
return (ret);
if ((ret = aes_cipher(&ctx->aes_ctx, h, h)) != 0)
return (ret);
GET_UINT32_BE(hi, h, 0); // pack h as two 64-bit ints, big-endian
GET_UINT32_BE(lo, h, 4);
vh = (uint64_t)hi << 32 | lo;
GET_UINT32_BE(hi, h, 8);
GET_UINT32_BE(lo, h, 12);
vl = (uint64_t)hi << 32 | lo;
ctx->HL[8] = vl; // 8 = 1000 corresponds to 1 in GF(2^128)
ctx->HH[8] = vh;
ctx->HH[0] = 0; // 0 corresponds to 0 in GF(2^128)
ctx->HL[0] = 0;
for (i = 4; i > 0; i >>= 1) {
uint32_t T = (uint32_t)(vl & 1) * 0xe1000000U;
vl = (vh << 63) | (vl >> 1);
vh = (vh >> 1) ^ ((uint64_t)T << 32);
ctx->HL[i] = vl;
ctx->HH[i] = vh;
}
for (i = 2; i < 16; i <<= 1) {
uint64_t *HiL = ctx->HL + i, *HiH = ctx->HH + i;
vh = *HiH;
vl = *HiL;
for (j = 1; j < i; j++) {
HiH[j] = vh ^ ctx->HH[j];
HiL[j] = vl ^ ctx->HL[j];
}
}
return (0);
}
/******************************************************************************
*
* GCM processing occurs four phases: SETKEY, START, UPDATE and FINISH.
*
* SETKEY:
*
* START: Sets the Encryption/Decryption mode.
* Accepts the initialization vector and additional data.
*
* UPDATE: Encrypts or decrypts the plaintext or ciphertext.
*
* FINISH: Performs a final GHASH to generate the authentication tag.
*
******************************************************************************
*
* GCM_START
*
* Given a user-provided GCM context, this initializes it, sets the encryption
* mode, and preprocesses the initialization vector and additional AEAD data.
*
******************************************************************************/
int gcm_start(gcm_context *ctx, // pointer to user-provided GCM context
enum aes_op_mode mode, // GCM_ENCRYPT or GCM_DECRYPT
const uint8_t *iv, // pointer to initialization vector
size_t iv_len, // IV length in bytes (should == 12)
const uint8_t *add, // ptr to additional AEAD data (NULL if none)
size_t add_len) // length of additional AEAD data (bytes)
{
int ret; // our error return if the AES encrypt fails
// TODO: cleanup
#ifndef AES_GCM_FIXED_12_BYTE_IV
uint8_t work_buf[16]; // XOR source built from provided IV if len != 16
#endif
const uint8_t *p; // general purpose array pointer
size_t use_len; // byte count to process, up to 16 bytes
size_t i; // local loop iterator
// since the context might be reused under the same key
// we zero the working buffers for this next new process
memset(ctx->y, 0x00, sizeof(ctx->y));
memset(ctx->buf, 0x00, sizeof(ctx->buf));
ctx->len = 0;
ctx->add_len = 0;
ctx->mode = mode; // set the GCM encryption/decryption mode
if (iv_len == 12) { // GCM natively uses a 12-byte, 96-bit IV
memcpy(ctx->y, iv, iv_len); // copy the IV to the top of the 'y'
// buff
ctx->y[15] = 1; // start "counting" from 1 (not 0)
}
#ifdef AES_GCM_FIXED_12_BYTE_IV
uassert(iv_len == 12);
#else
else // if we don't have a 12-byte IV, we GHASH whatever we've been
// given
{
memset(work_buf, 0x00, 16); // clear the working buffer
PUT_UINT32_BE(iv_len * 8, work_buf, 12); // place the IV into
// buffer
p = iv;
while (iv_len > 0) {
use_len = (iv_len < 16) ? iv_len : 16;
for (i = 0; i < use_len; i++)
ctx->y[i] ^= p[i];
gcm_mult(ctx, ctx->y, ctx->y);
iv_len -= use_len;
p += use_len;
}
for (i = 0; i < 16; i++)
ctx->y[i] ^= work_buf[i];
gcm_mult(ctx, ctx->y, ctx->y);
}
#endif
if ((ret = aes_cipher(&ctx->aes_ctx, ctx->y, ctx->base_ectr)) != 0)
return (ret);
ctx->add_len = add_len;
p = add;
while (add_len > 0) {
use_len = (add_len < 16) ? add_len : 16;
for (i = 0; i < use_len; i++)
ctx->buf[i] ^= p[i];
gcm_mult(ctx, ctx->buf, ctx->buf);
add_len -= use_len;
p += use_len;
}
return (0);
}
/******************************************************************************
*
* GCM_UPDATE
*
* This is called once or more to process bulk plaintext or ciphertext data.
* We give this some number of bytes of input and it returns the same number
* of output bytes. If called multiple times (which is fine) all but the final
* invocation MUST be called with length mod 16 == 0. (Only the final call can
* have a partial block length of < 128 bits.)
*
******************************************************************************/
int gcm_update(gcm_context *ctx, // pointer to user-provided GCM context
size_t length, // length, in bytes, of data to process
const uint8_t *input, // pointer to source data
uint8_t *output) // pointer to destination data
{
int ret; // our error return if the AES encrypt fails
uint8_t ectr[16]; // counter-mode cipher output for XORing
size_t use_len; // byte count to process, up to 16 bytes
size_t i; // local loop iterator
uassert(ctx->mode == AES_MODE_ENCRYPT || ctx->mode == AES_MODE_DECRYPT);
ctx->len += length; // bump the GCM context's running length count
while (length > 0) {
// clamp the length to process at 16 bytes
use_len = (length < 16) ? length : 16;
// increment the context's 128-bit IV||Counter 'y' vector
for (i = 16; i > 12; i--)
if (++ctx->y[i - 1] != 0)
break;
// encrypt the context's 'y' vector under the established key
if ((ret = aes_cipher(&ctx->aes_ctx, ctx->y, ectr)) != 0)
return (ret);
// encrypt or decrypt the input to the output
if (ctx->mode == AES_MODE_ENCRYPT) {
for (i = 0; i < use_len; i++) {
// XOR the cipher's ouptut vector (ectr) with
// our input
output[i] = (uint8_t)(ectr[i] ^ input[i]);
// now we mix in our data into the
// authentication hash. if we're ENcrypting we
// XOR in the post-XOR (output) results, but if
// we're DEcrypting we XOR in the input data
ctx->buf[i] ^= output[i];
}
} else if (ctx->mode == AES_MODE_DECRYPT) {
for (i = 0; i < use_len; i++) {
// but if we're DEcrypting we XOR in the input
// data first, i.e. before saving to ouput data,
// otherwise if the input and output buffer are
// the same (inplace decryption) we would not
// get the correct auth tag
ctx->buf[i] ^= input[i];
// XOR the cipher's ouptut vector (ectr) with
// our input
output[i] = (uint8_t)(ectr[i] ^ input[i]);
}
}
gcm_mult(ctx, ctx->buf, ctx->buf); // perform a GHASH operation
length -= use_len; // drop the remaining byte count to process
input += use_len; // bump our input pointer forward
output += use_len; // bump our output pointer forward
}
return (0);
}
/******************************************************************************
*
* GCM_FINISH
*
* This is called once after all calls to GCM_UPDATE to finalize the GCM.
* It performs the final GHASH to produce the resulting authentication TAG.
*
******************************************************************************/
int gcm_finish(gcm_context *ctx, // pointer to user-provided GCM context
uint8_t *tag, // pointer to buffer which receives the tag
size_t tag_len) // length, in bytes, of the tag-receiving buf
{
uint8_t work_buf[16];
uint64_t orig_len = ctx->len * 8;
uint64_t orig_add_len = ctx->add_len * 8;
size_t i;
uassert(ctx->mode == AES_MODE_ENCRYPT || ctx->mode == AES_MODE_DECRYPT);
if (tag_len != 0)
memcpy(tag, ctx->base_ectr, tag_len);
if (orig_len || orig_add_len) {
memset(work_buf, 0x00, 16);
PUT_UINT32_BE((orig_add_len >> 32), work_buf, 0);
PUT_UINT32_BE((orig_add_len), work_buf, 4);
PUT_UINT32_BE((orig_len >> 32), work_buf, 8);
PUT_UINT32_BE((orig_len), work_buf, 12);
for (i = 0; i < 16; i++)
ctx->buf[i] ^= work_buf[i];
gcm_mult(ctx, ctx->buf, ctx->buf);
for (i = 0; i < tag_len; i++)
tag[i] ^= ctx->buf[i];
}
return (0);
}
/******************************************************************************
*
* GCM_CRYPT_AND_TAG
*
* This either encrypts or decrypts the user-provided data and, either
* way, generates an authentication tag of the requested length. It must be
* called with a GCM context whose key has already been set with GCM_SETKEY.
*
* The user would typically call this explicitly to ENCRYPT a buffer of data
* and optional associated data, and produce its an authentication tag.
*
* To reverse the process the user would typically call the companion
* GCM_AUTH_DECRYPT function to decrypt data and verify a user-provided
* authentication tag. The GCM_AUTH_DECRYPT function calls this function
* to perform its decryption and tag generation, which it then compares.
*
******************************************************************************/
int gcm_crypt_and_tag(gcm_context *ctx, // gcm context with key already setup
enum aes_op_mode mode, // cipher direction: GCM_ENCRYPT or
// GCM_DECRYPT
const uint8_t *iv, // pointer to the 12-byte
// initialization vector
size_t iv_len, // byte length if the IV. should always be
// 12
const uint8_t *add, // pointer to the non-ciphered
// additional data
size_t add_len, // byte length of the additional AEAD data
const uint8_t *input, // pointer to the cipher data source
uint8_t *output, // pointer to the cipher data destination
size_t length, // byte length of the cipher data
uint8_t *tag, // pointer to the tag to be generated
size_t tag_len) // byte length of the tag to be generated
{ /*
assuming that the caller has already invoked gcm_setkey to
prepare the gcm context with the keying material, we simply
invoke each of the three GCM sub-functions in turn...
*/
gcm_start(ctx, mode, iv, iv_len, add, add_len);
gcm_update(ctx, length, input, output);
gcm_finish(ctx, tag, tag_len);
return (0);
}
/******************************************************************************
*
* GCM_AUTH_DECRYPT
*
* This DECRYPTS a user-provided data buffer with optional associated data.
* It then verifies a user-supplied authentication tag against the tag just
* re-created during decryption to verify that the data has not been altered.
*
* This function calls GCM_CRYPT_AND_TAG (above) to perform the decryption
* and authentication tag generation.
*
******************************************************************************/
int gcm_auth_decrypt(gcm_context *ctx, // gcm context with key already setup
const uint8_t *iv, // pointer to the 12-byte initialization
// vector
size_t iv_len, // byte length if the IV. should always be
// 12
const uint8_t *add, // pointer to the non-ciphered
// additional data
size_t add_len, // byte length of the additional AEAD data
const uint8_t *input, // pointer to the cipher data source
uint8_t *output, // pointer to the cipher data destination
size_t length, // byte length of the cipher data
const uint8_t *tag, // pointer to the tag to be
// authenticated
size_t tag_len) // byte length of the tag <= 16
{
uint8_t check_tag[16]; // the tag generated and returned by decryption
int diff; // an ORed flag to detect authentication errors
size_t i; // our local iterator
/*
we use GCM_DECRYPT_AND_TAG (above) to perform our decryption
(which is an identical XORing to reverse the previous one)
and also to re-generate the matching authentication tag
*/
gcm_crypt_and_tag(ctx, AES_MODE_DECRYPT, iv, iv_len, add, add_len,
input, output, length, check_tag, tag_len);
// now we verify the authentication tag in 'constant time'
for (diff = 0, i = 0; i < tag_len; i++)
diff |= tag[i] ^ check_tag[i];
if (diff != 0) { // see whether any bits differed?
memset(output, 0, length); // if so... wipe the output data
return (GCM_AUTH_FAILURE); // return GCM_AUTH_FAILURE
}
return (0);
}
/******************************************************************************
*
* GCM_ZERO_CTX
*
* The GCM context contains both the GCM context and the AES context.
* This includes keying and key-related material which is security-
* sensitive, so it MUST be zeroed after use. This function does that.
*
******************************************************************************/
void gcm_zero_ctx(gcm_context *ctx)
{
// zero the context originally provided to us
memset(ctx, 0, sizeof(gcm_context));
ctx->mode = AES_MODE_NONE;
}

281
nanotls/lib/include/bitops.h Executable file
View file

@ -0,0 +1,281 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef BITOPS_H
#define BITOPS_H
#include <linux/types.h>
/* Assorted bitwise and common operations used in ciphers. */
/** Circularly rotate right x by n bits.
* 0 > n > 32. */
static inline uint32_t rotr32(uint32_t x, unsigned n)
{
return (x >> n) | (x << (32 - n));
}
/** Circularly rotate left x by n bits.
* 0 > n > 32. */
static inline uint32_t rotl32(uint32_t x, unsigned n)
{
return (x << n) | (x >> (32 - n));
}
/** Circularly rotate right x by n bits.
* 0 > n > 64. */
static inline uint64_t rotr64(uint64_t x, unsigned n)
{
return (x >> n) | (x << (64 - n));
}
/** Circularly rotate left x by n bits.
* 0 > n > 64. */
static inline uint64_t rotl64(uint64_t x, unsigned n)
{
return (x << n) | (x >> (64 - n));
}
/** Read 4 bytes from buf, as a 32-bit big endian quantity. */
static inline uint32_t read32_be(const uint8_t buf[4])
{
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3]);
}
/** Read 4 bytes from buf, as a 32-bit little endian quantity. */
static inline uint32_t read32_le(const uint8_t buf[4])
{
return (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | (buf[0]);
}
/** Read 8 bytes from buf, as a 64-bit big endian quantity. */
static inline uint64_t read64_be(const uint8_t buf[8])
{
uint32_t hi = read32_be(buf), lo = read32_be(buf + 4);
return ((uint64_t)hi) << 32 | lo;
}
/** Read 8 bytes from buf, as a 64-bit little endian quantity. */
static inline uint64_t read64_le(const uint8_t buf[8])
{
uint32_t hi = read32_le(buf + 4), lo = read32_le(buf);
return ((uint64_t)hi) << 32 | lo;
}
/** Encode v as a 32-bit big endian quantity into buf. */
static inline void write32_be(uint32_t v, uint8_t buf[4])
{
*buf++ = (v >> 24) & 0xff;
*buf++ = (v >> 16) & 0xff;
*buf++ = (v >> 8) & 0xff;
*buf = v & 0xff;
}
/** Encode v as a 32-bit little endian quantity into buf. */
static inline void write32_le(uint32_t v, uint8_t buf[4])
{
*buf++ = v & 0xff;
*buf++ = (v >> 8) & 0xff;
*buf++ = (v >> 16) & 0xff;
*buf = (v >> 24) & 0xff;
}
/** Encode v as a 64-bit big endian quantity into buf. */
static inline void write64_be(uint64_t v, uint8_t buf[8])
{
*buf++ = (v >> 56) & 0xff;
*buf++ = (v >> 48) & 0xff;
*buf++ = (v >> 40) & 0xff;
*buf++ = (v >> 32) & 0xff;
*buf++ = (v >> 24) & 0xff;
*buf++ = (v >> 16) & 0xff;
*buf++ = (v >> 8) & 0xff;
*buf = v & 0xff;
}
/** Encode v as a 64-bit little endian quantity into buf. */
static inline void write64_le(uint64_t v, uint8_t buf[8])
{
*buf++ = v & 0xff;
*buf++ = (v >> 8) & 0xff;
*buf++ = (v >> 16) & 0xff;
*buf++ = (v >> 24) & 0xff;
*buf++ = (v >> 32) & 0xff;
*buf++ = (v >> 40) & 0xff;
*buf++ = (v >> 48) & 0xff;
*buf = (v >> 56) & 0xff;
}
/** out = in ^ b8.
* out and in may alias. */
static inline void xor_b8(uint8_t *out, const uint8_t *in, uint8_t b8,
size_t len)
{
for (size_t i = 0; i < len; i++)
out[i] = in[i] ^ b8;
}
/** out = x ^ y.
* out, x and y may alias. */
static inline void xor_bb(uint8_t *out, const uint8_t *x, const uint8_t *y,
size_t len)
{
for (size_t i = 0; i < len; i++)
out[i] = x[i] ^ y[i];
}
/* out ^= x
* out and x may alias. */
static inline void xor_words(uint32_t *out, const uint32_t *x, size_t nwords)
{
for (size_t i = 0; i < nwords; i++)
out[i] ^= x[i];
}
/** Produce 0xffffffff if x == y, zero otherwise, without branching. */
static inline uint32_t mask_u32(uint32_t x, uint32_t y)
{
uint32_t diff = x ^ y;
uint32_t diff_is_zero = ~diff & (diff - 1);
return -(diff_is_zero >> 31);
}
/** Product 0xff if x == y, zero otherwise, without branching. */
static inline uint8_t mask_u8(uint32_t x, uint32_t y)
{
uint32_t diff = x ^ y;
uint8_t diff_is_zero = ~diff & (diff - 1);
return -(diff_is_zero >> 7);
}
/** Select the ith entry from the given table of n values, in a side
* channel-silent way. */
static inline uint32_t select_u32(uint32_t i, volatile const uint32_t *tab,
uint32_t n)
{
uint32_t r = 0;
for (uint32_t ii = 0; ii < n; ii++) {
uint32_t mask = mask_u32(i, ii);
r = (r & ~mask) | (tab[ii] & mask);
}
return r;
}
/** Select the ith entry from the given table of n values, in a side
* channel-silent way. */
static inline uint8_t select_u8(uint32_t i, volatile const uint8_t *tab,
uint32_t n)
{
uint8_t r = 0;
for (uint32_t ii = 0; ii < n; ii++) {
uint8_t mask = mask_u8(i, ii);
r = (r & ~mask) | (tab[ii] & mask);
}
return r;
}
/** Select the ath, bth, cth and dth entries from the given table of n values,
* placing the results into a, b, c and d. */
static inline void select_u8x4(uint8_t *a, uint8_t *b, uint8_t *c, uint8_t *d,
volatile const uint8_t *tab, uint32_t n)
{
uint8_t ra = 0, rb = 0, rc = 0, rd = 0;
uint8_t mask;
for (uint32_t i = 0; i < n; i++) {
uint8_t item = tab[i];
mask = mask_u8(*a, i);
ra = (ra & ~mask) | (item & mask);
mask = mask_u8(*b, i);
rb = (rb & ~mask) | (item & mask);
mask = mask_u8(*c, i);
rc = (rc & ~mask) | (item & mask);
mask = mask_u8(*d, i);
rd = (rd & ~mask) | (item & mask);
}
*a = ra;
*b = rb;
*c = rc;
*d = rd;
}
/** out ^= if0 or if1, depending on the value of bit. */
static inline void select_xor128(uint32_t out[4], const uint32_t if0[4],
const uint32_t if1[4], uint8_t bit)
{
uint32_t mask1 = mask_u32(bit, 1);
uint32_t mask0 = ~mask1;
out[0] ^= (if0[0] & mask0) | (if1[0] & mask1);
out[1] ^= (if0[1] & mask0) | (if1[1] & mask1);
out[2] ^= (if0[2] & mask0) | (if1[2] & mask1);
out[3] ^= (if0[3] & mask0) | (if1[3] & mask1);
}
/** Increments the integer stored at v (of non-zero length len)
* with the least significant byte first. */
static inline void incr_le(uint8_t *v, size_t len)
{
size_t i = 0;
while (1) {
if (++v[i] != 0)
return;
i++;
if (i == len)
return;
}
}
/** Increments the integer stored at v (of non-zero length len)
* with the most significant byte last. */
static inline void incr_be(uint8_t *v, size_t len)
{
len--;
while (1) {
if (++v[len] != 0)
return;
if (len == 0)
return;
len--;
}
}
/** Copies len bytes from in to out, with in shifted left by offset bits
* to the right. */
static inline void copy_bytes_unaligned(uint8_t *out, const uint8_t *in,
size_t len, uint8_t offset)
{
uint8_t byte_off = offset / 8;
uint8_t bit_off = offset & 7;
uint8_t rmask = (1 << bit_off) - 1;
uint8_t lmask = ~rmask;
for (size_t i = 0; i < len; i++) {
out[i] = (in[i + byte_off] << bit_off) & lmask;
out[i] |= (in[i + byte_off + 1] >> (8 - bit_off)) & rmask;
}
}
static inline uint32_t count_trailing_zeroes(uint32_t x)
{
return (uint32_t)__builtin_ctzl(x);
}
#endif

135
nanotls/lib/include/blockwise.h Executable file
View file

@ -0,0 +1,135 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef BLOCKWISE_H
#define BLOCKWISE_H
#include <linux/types.h>
/* Processing function for cf_blockwise_accumulate. */
typedef void (*cf_blockwise_in_fn)(void *ctx, const uint8_t *data);
/* Processing function for cf_blockwise_xor. */
typedef void (*cf_blockwise_out_fn)(void *ctx, uint8_t *data);
/* This function manages the common abstraction of accumulating input in
* a buffer, and processing it when a full block is available.
*
* partial is the buffer (maintained by the caller)
* on entry, npartial is the currently valid count of used bytes on
* the front of partial.
* on exit, npartial is updated to reflect the status of partial.
* nblock is the blocksize to accumulate -- partial must be at least
* this long!
* input is the new data to process, of length nbytes.
* process is the processing function, passed ctx and a pointer
* to the data to process (always exactly nblock bytes long!)
* which may not neccessarily be the same as partial.
*/
void cf_blockwise_accumulate(uint8_t *partial, size_t *npartial, size_t nblock,
const void *input, size_t nbytes,
cf_blockwise_in_fn process, void *ctx);
/* This function manages the common abstraction of accumulating input in
* a buffer, and processing it when a full block is available.
* This version supports calling a different processing function for
* the last block.
*
* partial is the buffer (maintained by the caller)
* on entry, npartial is the currently valid count of used bytes on
* the front of partial.
* on exit, npartial is updated to reflect the status of partial.
* nblock is the blocksize to accumulate -- partial must be at least
* this long!
* input is the new data to process, of length nbytes.
* process is the processing function, passed ctx and a pointer
* to the data to process (always exactly nblock bytes long!)
* which may not neccessarily be the same as partial.
* process_final is called last (but may not be called at all if
* all input is buffered).
*/
void cf_blockwise_accumulate_final(uint8_t *partial, size_t *npartial,
size_t nblock, const void *input,
size_t nbytes, cf_blockwise_in_fn process,
cf_blockwise_in_fn process_final, void *ctx);
/* This function manages XORing an input stream with a keystream
* to produce an output stream. The keystream is produced in blocks
* (ala a block cipher in counter mode).
*
* partial is the keystream buffer (maintained by the caller)
* on entry, *npartial is the currently valid count of bytes in partial:
* unused bytes are at the *end*. So *npartial = 4 means the last four
* bytes of partial are usable as keystream.
* on exit, npartial is updated to reflect the new state of partial.
* nblock is the blocksize to accumulate -- partial must be at least
* this long!
* input is the new data to process, of length nbytes.
* output is where to write input xored with the keystream -- also length
* nbytes.
* process is the processing function, passed ctx and partial which it
* should fill with fresh key stream.
*/
void cf_blockwise_xor(uint8_t *partial, size_t *npartial, size_t nblock,
const void *input, void *output, size_t nbytes,
cf_blockwise_out_fn newblock, void *ctx);
/* This function processes a single byte a number of times. It's useful
* for padding, and more efficient than calling cf_blockwise_accumulate
* a bunch of times.
*
* partial is the buffer (maintained by the caller)
* on entry, npartial is the currently valid count of used bytes on
* the front of partial.
* on exit, npartial is updated to reflect the status of partial.
* nblock is the blocksize to accumulate -- partial must be at least
* this long!
* process is the processing function, passed ctx and a pointer
* to the data to process (always exactly nblock bytes long!)
* which may not neccessarily be the same as partial.
* byte is the byte to process, nbytes times.
*/
void cf_blockwise_acc_byte(uint8_t *partial, size_t *npartial, size_t nblock,
uint8_t byte, size_t nbytes,
cf_blockwise_in_fn process, void *ctx);
/* This function attempts to process patterns of bytes common in
* block cipher padding.
*
* This takes three bytes:
* - a first byte, fbyte,
* - a middle byte, mbyte,
* - a last byte, lbyte.
*
* If nbytes is zero, nothing happens.
* If nbytes is one, the byte fbyte ^ lbyte is processed.
* If nbytes is two, the fbyte then lbyte are processed.
* If nbytes is three or more, fbyte, then one or more mbytes, then fbyte
* is processed.
*
* partial is the buffer (maintained by the caller)
* on entry, npartial is the currently valid count of used bytes on
* the front of partial.
* on exit, npartial is updated to reflect the status of partial.
* nblock is the blocksize to accumulate -- partial must be at least
* this long!
* process is the processing function, passed ctx and a pointer
* to the data to process (always exactly nblock bytes long!)
* which may not neccessarily be the same as partial.
*/
void cf_blockwise_acc_pad(uint8_t *partial, size_t *npartial, size_t nblock,
uint8_t fbyte, uint8_t mbyte, uint8_t lbyte,
size_t nbytes, cf_blockwise_in_fn process, void *ctx);
#endif

134
nanotls/lib/include/chash.h Executable file
View file

@ -0,0 +1,134 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef CHASH_H
#define CHASH_H
#include <linux/types.h>
/**
* General hash function description
* =================================
* This allows us to make use of hash functions without depending
* on a specific one. This is useful in implementing, for example,
* :doc:`HMAC <hmac>`.
*/
/* .. c:type:: cf_chash_init
* Hashing initialisation function type.
*
* Functions of this type should initialise the context in preparation
* for hashing a message with `cf_chash_update` functions.
*
* :rtype: void
* :param ctx: hash function-specific context structure.
*/
typedef void (*cf_chash_init)(void *ctx);
/* .. c:type:: cf_chash_update
* Hashing data processing function type.
*
* Functions of this type hash `count` bytes of data at `data`,
* updating the contents of `ctx`.
*
* :rtype: void
* :param ctx: hash function-specific context structure.
* :param data: input data to hash.
* :param count: number of bytes to hash.
*/
typedef void (*cf_chash_update)(void *ctx, const void *data, size_t count);
/* .. c:type:: cf_chash_digest
* Hashing completion function type.
*
* Functions of this type complete a hashing operation,
* writing :c:member:`cf_chash.hashsz` bytes to `hash`.
*
* This function does not change `ctx` -- any padding which needs doing
* must be done seperately (in a copy of `ctx`, say).
*
* This means you can interlave `_update` and `_digest` calls to
* learn `H(A)` and `H(A || B)` without hashing `A` twice.
*
* :rtype: void
* :param ctx: hash function-specific context structure.
* :param hash: location to write hash result.
*/
typedef void (*cf_chash_digest)(const void *ctx, uint8_t *hash);
/* .. c:type:: cf_chash
* This type describes an incremental hash function in an abstract way.
*
* .. c:member:: cf_chash.hashsz
* The hash function's output, in bytes.
*
* .. c:member:: cf_chash.blocksz
* The hash function's internal block size, in bytes.
*
* .. c:member:: cf_chash.init
* Context initialisation function.
*
* .. c:member:: cf_chash:update
* Data processing function.
*
* .. c:member:: cf_chash:digest
* Completion function.
*
*/
typedef struct {
size_t hashsz;
size_t blocksz;
cf_chash_init init;
cf_chash_update update;
cf_chash_digest digest;
} cf_chash;
/* .. c:macro:: CF_CHASH_MAXCTX
* The maximum size of a :c:type:`cf_chash_ctx`. This allows
* use to put a structure in automatic storage that can
* store working data for any supported hash function. */
#define CF_CHASH_MAXCTX 390
/* .. c:macro:: CF_CHASH_MAXBLK
* Maximum hash function block size (in bytes). */
#define CF_CHASH_MAXBLK 128
/* .. c:macro:: CF_MAXHASH
* Maximum hash function output (in bytes). */
#define CF_MAXHASH 64
/* .. c:type:: cf_chash_ctx
* A type usable with any `cf_chash` as a context. */
typedef union {
uint8_t ctx[CF_CHASH_MAXCTX];
uint16_t u16;
uint32_t u32;
uint64_t u64;
} cf_chash_ctx;
/* .. c:function:: $DECL
* One shot hashing: `out = h(m)`.
*
* Using the hash function `h`, `nm` bytes at `m` are hashed and `h->hashsz`
* bytes of result is written to the buffer `out`.
*
* :param h: hash function description.
* :param m: message buffer.
* :param nm: message length.
* :param out: hash result buffer (written).
*/
void cf_hash(const cf_chash *h, const void *m, size_t nm, uint8_t *out);
#endif

119
nanotls/lib/include/handy.h Executable file
View file

@ -0,0 +1,119 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef HANDY_H
#define HANDY_H
#include <asm/string.h>
#include <uassert.h>
/*
* Handy CPP defines and C inline functions.
*/
/* Evaluates to the number of items in array-type variable arr. */
#define ARRAYCOUNT(arr) (sizeof arr / sizeof arr[0])
/* Normal MIN/MAX macros. Evaluate argument expressions only once. */
#ifndef MIN
#define MIN(x, y) \
({ \
typeof(x) __x = (x); \
typeof(y) __y = (y); \
__x < __y ? __x : __y; \
})
#endif
#ifndef MAX
#define MAX(x, y) \
({ \
typeof(x) __x = (x); \
typeof(y) __y = (y); \
__x > __y ? __x : __y; \
})
#endif
/* Swap two values. Uses GCC type inference magic. */
#ifndef SWAP
#define SWAP(x, y) \
do { \
typeof(x) __tmp = (x); \
(x) = (y); \
(y) = __tmp; \
} while (0)
#endif
/** Stringify its argument. */
#define STRINGIFY(x) STRINGIFY_(x)
#define STRINGIFY_(x) #x
/* Error handling macros.
*
* These expect a zero = success, non-zero = error convention.
*/
/** Error: return.
*
* If the expression fails, return the error from this function. */
#define ER(expr) \
do { \
typeof(expr) err_ = (expr); \
if (err_) \
return err_; \
} while (0)
/** Error: goto.
*
* If the expression fails, goto x_err. Assumes defn of label
* x_err and 'error_type err'. */
#define EG(expr) \
do { \
err = (expr); \
if (err) \
goto x_err; \
} while (0)
/** Like memset(ptr, 0, len), but not allowed to be removed by
* compilers. */
static inline void mem_clean(volatile void *v, size_t len)
{
if (len) {
memset((void *)v, 0, len);
(void)*((volatile uint8_t *)v);
}
}
/** Returns 1 if len bytes at va equal len bytes at vb, 0 if they do not.
* Does not leak length of common prefix through timing. */
static inline unsigned mem_eq(const void *va, const void *vb, size_t len)
{
const volatile uint8_t *a = va;
const volatile uint8_t *b = vb;
uint8_t diff = 0;
while (len--) {
diff |= *a++ ^ *b++;
}
return !diff;
}
#endif

72
nanotls/lib/include/hmac.h Executable file
View file

@ -0,0 +1,72 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef HMAC_H
#define HMAC_H
#include <linux/types.h>
#include "chash.h"
/**
* HMAC
* ====
* This is a one-shot and incremental interface to computing
* HMAC with any hash function.
*
* (Note: HMAC with SHA3 is possible, but is probably not a
* sensible thing to want.)
*/
/* .. c:type:: cf_hmac_ctx
* HMAC incremental interface context.
*
* .. c:member:: cf_hmac_ctx.hash
* Hash function description.
*
* .. c:member:: cf_hmac_ctx.inner
* Inner hash computation.
*
* .. c:member:: cf_hmac_ctx.outer
* Outer hash computation.
*/
typedef struct {
const cf_chash *hash;
cf_chash_ctx inner;
cf_chash_ctx outer;
} cf_hmac_ctx;
/* .. c:function:: $DECL
* Set up ctx for computing a HMAC using the given hash and key. */
void cf_hmac_init(cf_hmac_ctx *ctx, const cf_chash *hash, const uint8_t *key,
size_t nkey);
/* .. c:function:: $DECL
* Input data. */
void cf_hmac_update(cf_hmac_ctx *ctx, const void *data, size_t ndata);
/* .. c:function:: $DECL
* Finish and compute HMAC.
* `ctx->hash->hashsz` bytes are written to `out`. */
void cf_hmac_finish(cf_hmac_ctx *ctx, uint8_t *out);
/* .. c:function:: $DECL
* One shot interface: compute `HMAC_hash(key, msg)`, writing the
* answer (which is `hash->hashsz` long) to `out`.
*
* This function does not fail. */
void cf_hmac(const uint8_t *key, size_t nkey, const uint8_t *msg, size_t nmsg,
uint8_t *out, const cf_chash *hash);
#endif

144
nanotls/lib/include/p256-m.h Executable file
View file

@ -0,0 +1,144 @@
/*
* Interface of curve P-256 (ECDH and ECDSA)
*
* Copyright The Mbed TLS Contributors
* Author: Manuel Pégourié-Gonnard.
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
*/
#ifndef P256_M_H
#define P256_M_H
#include <linux/types.h>
#include <linux/random.h>
/* Status codes */
#define P256_SUCCESS 0
#define P256_RANDOM_FAILED -1
#define P256_INVALID_PUBKEY -2
#define P256_INVALID_PRIVKEY -3
#define P256_INVALID_SIGNATURE -4
#ifdef __cplusplus
extern "C" {
#endif
/*
* RNG function - must be provided externally and be cryptographically secure.
*
* in: output - must point to a writable buffer of at least output_size bytes.
* output_size - the number of random bytes to write to output.
* out: output is filled with output_size random bytes.
* return 0 on success, non-zero on errors.
*/
extern int p256_generate_random(uint8_t *output, unsigned output_size);
/*
* Zeroize function - function to zerioze memory.
*
* in: buf - buffer to be zeroize.
* bytes - number of bytes to zeroize.
* out: buffer is filled with zeroes.
*/
extern void p256_mem_zeroize(void *buf, size_t bytes);
/*
* ECDH/ECDSA generate key pair
*
* [in] draws from p256_generate_random()
* [out] priv: on success, holds the private key, as a big-endian integer
* [out] pub: on success, holds the public key, as two big-endian integers
*
* return: P256_SUCCESS on success
* P256_RANDOM_FAILED on failure
*/
int p256_gen_keypair(uint8_t priv[32], uint8_t pub[64]);
/*
* ECDH compute shared secret
*
* [out] secret: on success, holds the shared secret, as a big-endian integer
* [in] priv: our private key as a big-endian integer
* [in] pub: the peer's public key, as two big-endian integers
*
* return: P256_SUCCESS on success
* P256_INVALID_PRIVKEY if priv is invalid
* P256_INVALID_PUBKEY if pub is invalid
*/
int p256_ecdh_shared_secret(uint8_t secret[32], const uint8_t priv[32],
const uint8_t pub[64]);
/*
* ECDSA sign
*
* [in] draws from p256_generate_random()
* [out] sig: on success, holds the signature, as two big-endian integers
* [in] priv: our private key as a big-endian integer
* [in] hash: the hash of the message to be signed
* [in] hlen: the size of hash in bytes
*
* return: P256_SUCCESS on success
* P256_RANDOM_FAILED on failure
* P256_INVALID_PRIVKEY if priv is invalid
*/
int p256_ecdsa_sign(uint8_t sig[64], const uint8_t priv[32],
const uint8_t *hash, size_t hlen);
/*
* ECDSA verify
*
* [in] sig: the signature to be verified, as two big-endian integers
* [in] pub: the associated public key, as two big-endian integers
* [in] hash: the hash of the message that was signed
* [in] hlen: the size of hash in bytes
*
* return: P256_SUCCESS on success - the signature was verified as valid
* P256_INVALID_PUBKEY if pub is invalid
* P256_INVALID_SIGNATURE if the signature was found to be invalid
*/
int p256_ecdsa_verify(const uint8_t sig[64], const uint8_t pub[64],
const uint8_t *hash, size_t hlen);
/*
* Public key validation
*
* Note: you never need to call this function, as all other functions always
* validate their input; however it's availabe if you want to validate the key
* without performing an operation.
*
* [in] pub: the public key, as two big-endian integers
*
* return: P256_SUCCESS if the key is valid
* P256_INVALID_PUBKEY if pub is invalid
*/
int p256_validate_pubkey(const uint8_t pub[64]);
/*
* Private key validation
*
* Note: you never need to call this function, as all other functions always
* validate their input; however it's availabe if you want to validate the key
* without performing an operation.
*
* [in] priv: the private key, as a big-endian integer
*
* return: P256_SUCCESS if the key is valid
* P256_INVALID_PRIVKEY if priv is invalid
*/
int p256_validate_privkey(const uint8_t priv[32]);
/*
* Compute public key from private key
*
* [out] pub: the associated public key, as two big-endian integers
* [in] priv: the private key, as a big-endian integer
*
* return: P256_SUCCESS on success
* P256_INVALID_PRIVKEY if priv is invalid
*/
int p256_public_from_private(uint8_t pub[64], const uint8_t priv[32]);
#ifdef __cplusplus
}
#endif
#endif /* P256_M_H */

244
nanotls/lib/include/sha2.h Executable file
View file

@ -0,0 +1,244 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#ifndef SHA2_H
#define SHA2_H
#include <linux/types.h>
#include "chash.h"
/**
* SHA224/SHA256
* =============
*/
/* .. c:macro:: CF_SHA224_HASHSZ
* The output size of SHA224: 28 bytes. */
#define CF_SHA224_HASHSZ 28
/* .. c:macro:: CF_SHA224_BLOCKSZ
* The block size of SHA224: 64 bytes. */
#define CF_SHA224_BLOCKSZ 64
/* .. c:macro:: CF_SHA256_HASHSZ
* The output size of SHA256: 32 bytes. */
#define CF_SHA256_HASHSZ 32
/* .. c:macro:: CF_SHA256_BLOCKSZ
* The block size of SHA256: 64 bytes. */
#define CF_SHA256_BLOCKSZ 64
/* .. c:type:: cf_sha256_context
* Incremental SHA256 hashing context.
*
* .. c:member:: cf_sha256_context.H
* Intermediate values.
*
* .. c:member:: cf_sha256_context.partial
* Unprocessed input.
*
* .. c:member:: cf_sha256_context.npartial
* Number of bytes of unprocessed input.
*
* .. c:member:: cf_sha256_context.blocks
* Number of full blocks processed.
*/
typedef struct {
uint32_t H[8]; /* State. */
uint8_t partial[CF_SHA256_BLOCKSZ]; /* Partial block of input. */
uint32_t blocks; /* Number of full blocks processed into H. */
size_t npartial; /* Number of bytes in prefix of partial. */
} cf_sha256_context;
/* .. c:function:: $DECL
* Sets up `ctx` ready to hash a new message.
*/
extern void cf_sha256_init(cf_sha256_context *ctx);
/* .. c:function:: $DECL
* Hashes `nbytes` at `data`. Copies the data if there isn't enough to make
* a full block.
*/
extern void cf_sha256_update(cf_sha256_context *ctx, const void *data,
size_t nbytes);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA256_HASHSZ` bytes to `hash`.
*
* This leaves `ctx` unchanged.
*/
extern void cf_sha256_digest(const cf_sha256_context *ctx,
uint8_t hash[CF_SHA256_HASHSZ]);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA256_HASHSZ` bytes to `hash`.
*
* This destroys `ctx`, but uses less stack than :c:func:`cf_sha256_digest`.
*/
extern void cf_sha256_digest_final(cf_sha256_context *ctx,
uint8_t hash[CF_SHA256_HASHSZ]);
/* .. c:function:: $DECL
* Sets up `ctx` ready to hash a new message.
*
* nb. SHA224 uses SHA256's underlying types.
*/
extern void cf_sha224_init(cf_sha256_context *ctx);
/* .. c:function:: $DECL
* Hashes `nbytes` at `data`. Copies the data if there isn't enough to make
* a full block.
*/
extern void cf_sha224_update(cf_sha256_context *ctx, const void *data,
size_t nbytes);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA224_HASHSZ` bytes to `hash`.
*
* This leaves `ctx` unchanged.
*/
extern void cf_sha224_digest(const cf_sha256_context *ctx,
uint8_t hash[CF_SHA224_HASHSZ]);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA224_HASHSZ` bytes to `hash`.
*
* This destroys `ctx`, but uses less stack than :c:func:`cf_sha224_digest`.
*/
extern void cf_sha224_digest_final(cf_sha256_context *ctx,
uint8_t hash[CF_SHA224_HASHSZ]);
/* .. c:var:: cf_sha224
* Abstract interface to SHA224. See :c:type:`cf_chash` for more information.
*/
extern const cf_chash cf_sha224;
/* .. c:var:: cf_sha256
* Abstract interface to SHA256. See :c:type:`cf_chash` for more information.
*/
extern const cf_chash cf_sha256;
/**
* SHA384/SHA512
* =============
*/
/* .. c:macro:: CF_SHA384_HASHSZ
* The output size of SHA384: 48 bytes. */
#define CF_SHA384_HASHSZ 48
/* .. c:macro:: CF_SHA384_BLOCKSZ
* The block size of SHA384: 128 bytes. */
#define CF_SHA384_BLOCKSZ 128
/* .. c:macro:: CF_SHA512_HASHSZ
* The output size of SHA512: 64 bytes. */
#define CF_SHA512_HASHSZ 64
/* .. c:macro:: CF_SHA512_BLOCKSZ
* The block size of SHA512: 128 bytes. */
#define CF_SHA512_BLOCKSZ 128
/* .. c:type:: cf_sha512_context
* Incremental SHA512 hashing context.
*
* .. c:member:: cf_sha512_context.H
* Intermediate values.
*
* .. c:member:: cf_sha512_context.partial
* Unprocessed input.
*
* .. c:member:: cf_sha512_context.npartial
* Number of bytes of unprocessed input.
*
* .. c:member:: cf_sha512_context.blocks
* Number of full blocks processed.
*/
typedef struct {
uint64_t H[8];
uint8_t partial[CF_SHA512_BLOCKSZ];
uint32_t blocks;
size_t npartial;
} cf_sha512_context;
/* .. c:function:: $DECL
* Sets up `ctx` ready to hash a new message.
*/
extern void cf_sha512_init(cf_sha512_context *ctx);
/* .. c:function:: $DECL
* Hashes `nbytes` at `data`. Copies the data if there isn't enough to make
* a full block.
*/
extern void cf_sha512_update(cf_sha512_context *ctx, const void *data,
size_t nbytes);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA512_HASHSZ` bytes to `hash`.
*
* This leaves `ctx` unchanged.
*/
extern void cf_sha512_digest(const cf_sha512_context *ctx,
uint8_t hash[CF_SHA512_HASHSZ]);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA512_HASHSZ` bytes to `hash`.
*
* This destroys `ctx`, but uses less stack than :c:func:`cf_sha512_digest`.
*/
extern void cf_sha512_digest_final(cf_sha512_context *ctx,
uint8_t hash[CF_SHA512_HASHSZ]);
/* .. c:function:: $DECL
* Sets up `ctx` ready to hash a new message.
*
* nb. SHA384 uses SHA512's underlying types.
*/
extern void cf_sha384_init(cf_sha512_context *ctx);
/* .. c:function:: $DECL
* Hashes `nbytes` at `data`. Copies the data if there isn't enough to make
* a full block.
*/
extern void cf_sha384_update(cf_sha512_context *ctx, const void *data,
size_t nbytes);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA384_HASHSZ` bytes to `hash`.
*
* This leaves `ctx` unchanged.
*/
extern void cf_sha384_digest(const cf_sha512_context *ctx,
uint8_t hash[CF_SHA384_HASHSZ]);
/* .. c:function:: $DECL
* Finishes the hash operation, writing `CF_SHA384_HASHSZ` bytes to `hash`.
*
* This destroys `ctx`, but uses less stack than :c:func:`cf_sha384_digest`.
*/
extern void cf_sha384_digest_final(cf_sha512_context *ctx,
uint8_t hash[CF_SHA384_HASHSZ]);
/* .. c:var:: cf_sha384
* Abstract interface to SHA384. See :c:type:`cf_chash` for more information.
*/
extern const cf_chash cf_sha384;
/* .. c:var:: cf_sha512
* Abstract interface to SHA512. See :c:type:`cf_chash` for more information.
*/
extern const cf_chash cf_sha512;
#endif

36
nanotls/lib/include/uassert.h Executable file
View file

@ -0,0 +1,36 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#ifndef NANOTLS_UASSERT_H
#define NANOTLS_UASSERT_H
#include <linux/types.h>
static inline void uassert(__attribute__((unused)) bool cond)
{
#ifdef DEBUG
#include <assert.h>
assert(cond);
#endif
}
#endif /* NANOTLS_UASSERT_H */

186
nanotls/lib/src/blockwise.c Executable file
View file

@ -0,0 +1,186 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "blockwise.h"
#include "bitops.h"
#include "handy.h"
#include <asm/string.h>
void cf_blockwise_accumulate(uint8_t *partial, size_t *npartial, size_t nblock,
const void *inp, size_t nbytes,
cf_blockwise_in_fn process, void *ctx)
{
cf_blockwise_accumulate_final(partial, npartial, nblock, inp, nbytes,
process, process, ctx);
}
void cf_blockwise_accumulate_final(uint8_t *partial, size_t *npartial,
size_t nblock, const void *inp,
size_t nbytes, cf_blockwise_in_fn process,
cf_blockwise_in_fn process_final, void *ctx)
{
const uint8_t *bufin = inp;
uassert(partial && *npartial < nblock);
uassert(inp || !nbytes);
uassert(process && ctx);
/* If we have partial data, copy in to buffer. */
if (*npartial && nbytes) {
size_t space = nblock - *npartial;
size_t taken = MIN(space, nbytes);
memcpy(partial + *npartial, bufin, taken);
bufin += taken;
nbytes -= taken;
*npartial += taken;
/* If that gives us a full block, process it. */
if (*npartial == nblock) {
if (nbytes == 0)
process_final(ctx, partial);
else
process(ctx, partial);
*npartial = 0;
}
}
/* now nbytes < nblock or *npartial == 0. */
/* If we have a full block of data, process it directly. */
while (nbytes >= nblock) {
/* Partial buffer must be empty, or we're ignoring extant data
*/
uassert(*npartial == 0);
if (nbytes == nblock)
process_final(ctx, bufin);
else
process(ctx, bufin);
bufin += nblock;
nbytes -= nblock;
}
/* Finally, if we have remaining data, buffer it. */
while (nbytes) {
size_t space = nblock - *npartial;
size_t taken = MIN(space, nbytes);
memcpy(partial + *npartial, bufin, taken);
bufin += taken;
nbytes -= taken;
*npartial += taken;
/* If we started with *npartial, we must have copied it
* in first. */
uassert(*npartial < nblock);
}
}
void cf_blockwise_xor(uint8_t *partial, size_t *npartial, size_t nblock,
const void *inp, void *outp, size_t nbytes,
cf_blockwise_out_fn process, void *ctx)
{
const uint8_t *inb = inp;
uint8_t *outb = outp;
uassert(partial && *npartial < nblock);
uassert(inp || !nbytes);
uassert(process && ctx);
while (nbytes) {
/* If we're out of material, and need more, produce a block. */
if (*npartial == 0) {
process(ctx, partial);
*npartial = nblock;
}
size_t offset = nblock - *npartial;
size_t taken = MIN(*npartial, nbytes);
xor_bb(outb, inb, partial + offset, taken);
*npartial -= taken;
nbytes -= taken;
outb += taken;
inb += taken;
}
}
void cf_blockwise_acc_byte(uint8_t *partial, size_t *npartial, size_t nblock,
uint8_t byte, size_t nbytes,
cf_blockwise_in_fn process, void *ctx)
{
/* only memset the whole of the block once */
int filled = 0;
while (nbytes) {
size_t start = *npartial;
size_t count = MIN(nbytes, nblock - start);
if (!filled)
memset(partial + start, byte, count);
if (start == 0 && count == nblock)
filled = 1;
if (start + count == nblock) {
process(ctx, partial);
*npartial = 0;
} else {
*npartial += count;
}
nbytes -= count;
}
}
void cf_blockwise_acc_pad(uint8_t *partial, size_t *npartial, size_t nblock,
uint8_t fbyte, uint8_t mbyte, uint8_t lbyte,
size_t nbytes, cf_blockwise_in_fn process, void *ctx)
{
switch (nbytes) {
case 0:
break;
case 1:
fbyte ^= lbyte;
cf_blockwise_accumulate(partial, npartial, nblock, &fbyte, 1,
process, ctx);
break;
case 2:
cf_blockwise_accumulate(partial, npartial, nblock, &fbyte, 1,
process, ctx);
cf_blockwise_accumulate(partial, npartial, nblock, &lbyte, 1,
process, ctx);
break;
default:
cf_blockwise_accumulate(partial, npartial, nblock, &fbyte, 1,
process, ctx);
/* If the middle and last bytes differ, then process the last
* byte separately. Otherwise, just extend the middle block
* size. */
if (lbyte != mbyte) {
cf_blockwise_acc_byte(partial, npartial, nblock, mbyte,
nbytes - 2, process, ctx);
cf_blockwise_accumulate(partial, npartial, nblock,
&lbyte, 1, process, ctx);
} else {
cf_blockwise_acc_byte(partial, npartial, nblock, mbyte,
nbytes - 1, process, ctx);
}
break;
}
}

26
nanotls/lib/src/chash.c Executable file
View file

@ -0,0 +1,26 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "chash.h"
#include "handy.h"
void cf_hash(const cf_chash *h, const void *m, size_t nm, uint8_t *out)
{
cf_chash_ctx ctx;
uassert(h);
h->init(&ctx);
h->update(&ctx, m, nm);
h->digest(&ctx, out);
mem_clean(&ctx, sizeof ctx);
}

101
nanotls/lib/src/hmac.c Executable file
View file

@ -0,0 +1,101 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include "hmac.h"
#include "chash.h"
#include "bitops.h"
#include "handy.h"
#include <asm/string.h>
void cf_hmac_init(cf_hmac_ctx *ctx, const cf_chash *hash, const uint8_t *key,
size_t nkey)
{
uassert(ctx);
uassert(hash);
mem_clean(ctx, sizeof *ctx);
ctx->hash = hash;
/* Prepare key: */
uint8_t k[CF_CHASH_MAXBLK];
/* Shorten long keys. */
if (nkey > hash->blocksz) {
/* Standard doesn't cover case where blocksz < hashsz.
* FIPS186-1 seems to want to append a negative number of zero
* bytes. In any case, we only have a k buffer of
* CF_CHASH_MAXBLK! */
uassert(hash->hashsz <= hash->blocksz);
cf_hash(hash, key, nkey, k);
key = k;
nkey = hash->hashsz;
}
/* Right zero-pad short keys. */
if (k != key)
memcpy(k, key, nkey);
if (hash->blocksz > nkey)
memset(k + nkey, 0, hash->blocksz - nkey);
/* Start inner hash computation */
uint8_t blk[CF_CHASH_MAXBLK];
xor_b8(blk, k, 0x36, hash->blocksz);
hash->init(&ctx->inner);
hash->update(&ctx->inner, blk, hash->blocksz);
/* And outer. */
xor_b8(blk, k, 0x5c, hash->blocksz);
hash->init(&ctx->outer);
hash->update(&ctx->outer, blk, hash->blocksz);
mem_clean(blk, sizeof blk);
mem_clean(k, sizeof k);
}
void cf_hmac_update(cf_hmac_ctx *ctx, const void *data, size_t ndata)
{
uassert(ctx && ctx->hash);
ctx->hash->update(&ctx->inner, data, ndata);
}
void cf_hmac_finish(cf_hmac_ctx *ctx, uint8_t *out)
{
uassert(ctx && ctx->hash);
uassert(out);
uint8_t innerh[CF_MAXHASH];
ctx->hash->digest(&ctx->inner, innerh);
ctx->hash->update(&ctx->outer, innerh, ctx->hash->hashsz);
ctx->hash->digest(&ctx->outer, out);
mem_clean(ctx, sizeof *ctx);
}
void cf_hmac(const uint8_t *key, size_t nkey, const uint8_t *msg, size_t nmsg,
uint8_t *out, const cf_chash *hash)
{
cf_hmac_ctx ctx;
uassert(out);
uassert(hash);
cf_hmac_init(&ctx, hash, key, nkey);
cf_hmac_update(&ctx, msg, nmsg);
cf_hmac_finish(&ctx, out);
}

1530
nanotls/lib/src/p256-m.c Executable file

File diff suppressed because it is too large Load diff

216
nanotls/lib/src/sha256.c Executable file
View file

@ -0,0 +1,216 @@
/*
* cifra - embedded cryptography library
* Written in 2014 by Joseph Birr-Pixton <jpixton@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <linux/types.h>
#include <asm/posix_types.h>
#include <asm/string.h>
#include "sha2.h"
#include "blockwise.h"
#include "bitops.h"
#include "handy.h"
static const uint32_t K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
#define CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define BSIG0(x) (rotr32((x), 2) ^ rotr32((x), 13) ^ rotr32((x), 22))
#define BSIG1(x) (rotr32((x), 6) ^ rotr32((x), 11) ^ rotr32((x), 25))
#define SSIG0(x) (rotr32((x), 7) ^ rotr32((x), 18) ^ ((x) >> 3))
#define SSIG1(x) (rotr32((x), 17) ^ rotr32((x), 19) ^ ((x) >> 10))
void cf_sha256_init(cf_sha256_context *ctx)
{
memset(ctx, 0, sizeof *ctx);
ctx->H[0] = 0x6a09e667;
ctx->H[1] = 0xbb67ae85;
ctx->H[2] = 0x3c6ef372;
ctx->H[3] = 0xa54ff53a;
ctx->H[4] = 0x510e527f;
ctx->H[5] = 0x9b05688c;
ctx->H[6] = 0x1f83d9ab;
ctx->H[7] = 0x5be0cd19;
}
void cf_sha224_init(cf_sha256_context *ctx)
{
memset(ctx, 0, sizeof *ctx);
ctx->H[0] = 0xc1059ed8;
ctx->H[1] = 0x367cd507;
ctx->H[2] = 0x3070dd17;
ctx->H[3] = 0xf70e5939;
ctx->H[4] = 0xffc00b31;
ctx->H[5] = 0x68581511;
ctx->H[6] = 0x64f98fa7;
ctx->H[7] = 0xbefa4fa4;
}
static void sha256_update_block(void *vctx, const uint8_t *inp)
{
cf_sha256_context *ctx = vctx;
/* This is a 16-word window into the whole W array. */
uint32_t W[16];
uint32_t a = ctx->H[0], b = ctx->H[1], c = ctx->H[2], d = ctx->H[3],
e = ctx->H[4], f = ctx->H[5], g = ctx->H[6], h = ctx->H[7], Wt;
for (size_t t = 0; t < 64; t++) {
/* For W[0..16] we process the input into W.
* For W[16..64] we compute the next W value:
*
* W[t] = SSIG1(W[t - 2]) + W[t - 7] + SSIG0(W[t - 15]) + W[t -
* 16];
*
* But all W indices are reduced mod 16 into our window.
*/
if (t < 16) {
W[t] = Wt = read32_be(inp);
inp += 4;
} else {
Wt = SSIG1(W[(t - 2) % 16]) + W[(t - 7) % 16] +
SSIG0(W[(t - 15) % 16]) + W[(t - 16) % 16];
W[t % 16] = Wt;
}
uint32_t T1 = h + BSIG1(e) + CH(e, f, g) + K[t] + Wt;
uint32_t T2 = BSIG0(a) + MAJ(a, b, c);
h = g;
g = f;
f = e;
e = d + T1;
d = c;
c = b;
b = a;
a = T1 + T2;
}
ctx->H[0] += a;
ctx->H[1] += b;
ctx->H[2] += c;
ctx->H[3] += d;
ctx->H[4] += e;
ctx->H[5] += f;
ctx->H[6] += g;
ctx->H[7] += h;
ctx->blocks++;
}
void cf_sha256_update(cf_sha256_context *ctx, const void *data, size_t nbytes)
{
cf_blockwise_accumulate(ctx->partial, &ctx->npartial,
sizeof ctx->partial, data, nbytes,
sha256_update_block, ctx);
}
void cf_sha224_update(cf_sha256_context *ctx, const void *data, size_t nbytes)
{
cf_sha256_update(ctx, data, nbytes);
}
void cf_sha256_digest(const cf_sha256_context *ctx,
uint8_t hash[CF_SHA256_HASHSZ])
{
/* We copy the context, so the finalisation doesn't effect the caller's
* context. This means the caller can do:
*
* x = init()
* x.update('hello')
* h1 = x.digest()
* x.update(' world')
* h2 = x.digest()
*
* to get h1 = H('hello') and h2 = H('hello world')
*
* This wouldn't work if we applied MD-padding to *ctx.
*/
cf_sha256_context ours = *ctx;
cf_sha256_digest_final(&ours, hash);
}
void cf_sha256_digest_final(cf_sha256_context *ctx,
uint8_t hash[CF_SHA256_HASHSZ])
{
uint64_t digested_bytes = ctx->blocks;
digested_bytes = digested_bytes * CF_SHA256_BLOCKSZ + ctx->npartial;
uint64_t digested_bits = digested_bytes * 8;
size_t padbytes =
CF_SHA256_BLOCKSZ - ((digested_bytes + 8) % CF_SHA256_BLOCKSZ);
/* Hash 0x80 00 ... block first. */
cf_blockwise_acc_pad(ctx->partial, &ctx->npartial, sizeof ctx->partial,
0x80, 0x00, 0x00, padbytes, sha256_update_block,
ctx);
/* Now hash length. */
uint8_t buf[8];
write64_be(digested_bits, buf);
cf_sha256_update(ctx, buf, 8);
/* We ought to have got our padding calculation right! */
uassert(ctx->npartial == 0);
write32_be(ctx->H[0], hash + 0);
write32_be(ctx->H[1], hash + 4);
write32_be(ctx->H[2], hash + 8);
write32_be(ctx->H[3], hash + 12);
write32_be(ctx->H[4], hash + 16);
write32_be(ctx->H[5], hash + 20);
write32_be(ctx->H[6], hash + 24);
write32_be(ctx->H[7], hash + 28);
memset(ctx, 0, sizeof *ctx);
}
void cf_sha224_digest(const cf_sha256_context *ctx,
uint8_t hash[CF_SHA224_HASHSZ])
{
uint8_t full[CF_SHA256_HASHSZ];
cf_sha256_digest(ctx, full);
memcpy(hash, full, CF_SHA224_HASHSZ);
}
void cf_sha224_digest_final(cf_sha256_context *ctx,
uint8_t hash[CF_SHA224_HASHSZ])
{
uint8_t full[CF_SHA256_HASHSZ];
cf_sha256_digest_final(ctx, full);
memcpy(hash, full, CF_SHA224_HASHSZ);
}
const cf_chash cf_sha224 = {.hashsz = CF_SHA224_HASHSZ,
.blocksz = CF_SHA256_BLOCKSZ,
.init = (cf_chash_init)cf_sha224_init,
.update = (cf_chash_update)cf_sha224_update,
.digest = (cf_chash_digest)cf_sha224_digest};
const cf_chash cf_sha256 = {.hashsz = CF_SHA256_HASHSZ,
.blocksz = CF_SHA256_BLOCKSZ,
.init = (cf_chash_init)cf_sha256_init,
.update = (cf_chash_update)cf_sha256_update,
.digest = (cf_chash_digest)cf_sha256_digest};

130
nanotls/src/nanotls-common.c Executable file
View file

@ -0,0 +1,130 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include <nanotls-common.h>
#include <asm/string.h>
#include "uassert.h"
enum ecode nanotls_mem_eq(const void *a, const void *b, size_t size)
{
const volatile uint8_t *va = a;
const volatile uint8_t *vb = b;
uint8_t diff = 0;
while (size--) {
diff |= *va++ ^ *vb++;
}
return (diff == 0) ? E_OK : E_INVALID;
}
void nanotls_mem_erase(void *buf, size_t size)
{
memset(buf, 0, size);
}
void nanotls_hkdf_sha256_extract(const void *salt, size_t salt_len,
const void *ikm, size_t ikm_len,
uint8_t prk_result[NANOTLS_SHA256_HASH_SIZE])
{
if (salt_len > 0) {
nanotls_hmac_sha256(salt, salt_len, ikm, ikm_len, prk_result);
} else {
uint8_t zeroes[NANOTLS_SHA256_HASH_SIZE] = {0};
nanotls_hmac_sha256(zeroes, NANOTLS_SHA256_HASH_SIZE, ikm,
ikm_len, prk_result);
}
}
void nanotls_hkdf_expand_label(const uint8_t secret[NANOTLS_SHA256_HASH_SIZE],
const void *label, size_t label_size,
const uint8_t *context, size_t context_size,
void *output, size_t output_length)
{
uint8_t hmac_out[NANOTLS_SHA256_HASH_SIZE];
nanotls_hmac_ctx hmac_ctx;
const uint16_t length = output_length;
const uint8_t one = 0x01;
uassert(length <= NANOTLS_SHA256_HASH_SIZE);
nanotls_hmac_sha256_init(&hmac_ctx, secret, NANOTLS_SHA256_HASH_SIZE);
nanotls_hmac_sha256_update(&hmac_ctx, &length, sizeof(length));
nanotls_hmac_sha256_update(&hmac_ctx, label, label_size);
if (context && context_size > 0)
nanotls_hmac_sha256_update(&hmac_ctx, context, context_size);
nanotls_hmac_sha256_update(&hmac_ctx, &one, sizeof(one));
nanotls_hmac_sha256_finish(&hmac_ctx, hmac_out);
memcpy(output, hmac_out, output_length);
nanotls_mem_erase(hmac_out, sizeof(hmac_out));
}
void nanotls_write_finished(const nanotls_sha_ctx *handshake_hash,
const uint8_t hs_traffic_secret[NANOTLS_SECRET_SIZE],
uint8_t verify_data[NANOTLS_SHA256_HASH_SIZE])
{
uint8_t transcript_hash[NANOTLS_SHA256_HASH_SIZE];
uint8_t finished_key[NANOTLS_SHA256_HASH_SIZE]; /* HMAC key (not AES),
hence it's bigger */
/* Calculate transcript hash (transcript_hash) */
nanotls_sha256_digest(handshake_hash, transcript_hash);
/*
* Derive "Finished" key
* finished_key = HKDF-Expand-Label(hs_traffic_secret, "finished", "",
* Hash.length)
*/
nanotls_hkdf_expand_label_noctx(hs_traffic_secret,
NANOTLS_FINISHED_LABEL, finished_key,
sizeof(finished_key));
/*
* Create Finished.verify_data
* verify_data = HMAC(finished_key, transcript_hash)
*/
nanotls_hmac_sha256(finished_key, sizeof(finished_key), transcript_hash,
sizeof(transcript_hash), verify_data);
nanotls_mem_erase(finished_key, sizeof(finished_key));
}
void nanotls_derive_key_iv(uint8_t key[NANOTLS_KEY_SIZE],
uint8_t iv[NANOTLS_IV_SIZE],
const uint8_t secret[NANOTLS_SECRET_SIZE])
{
/* key = HKDF-Expand-Label(secret, "key", "") */
nanotls_hkdf_expand_label_noctx(secret, NANOTLS_KEYING_KEY_LABEL, key,
NANOTLS_KEY_SIZE);
/* iv = HKDF-Expand-Label(secret, "iv", "") */
nanotls_hkdf_expand_label_noctx(secret, NANOTLS_KEYING_IV_LABEL, iv,
NANOTLS_IV_SIZE);
}

380
nanotls/src/nanotls-data.c Executable file
View file

@ -0,0 +1,380 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include <nanotls-data.h>
#include <nanotls-hooks.h>
#include <asm/string.h>
#include <uassert.h>
static enum ecode nanotls_data_check_ctx(const struct nanotls_ctx_data *ctx)
{
if (ctx->role != NANOTLS_ROLE_HOST && ctx->role != NANOTLS_ROLE_DEVICE)
return E_INVALID;
return E_OK;
}
/* NONCE = IV ^ SEQ_NO */
static inline void nanotls_data_get_nonce(uint8_t nonce[NANOTLS_AES_IV_SIZE],
const uint8_t iv[NANOTLS_AES_IV_SIZE],
uint64_t seq_no)
{
size_t offset = sizeof(seq_no);
uint64_t tmp;
memcpy(&tmp, iv, sizeof(tmp));
tmp ^= seq_no;
memcpy(nonce, &tmp, sizeof(tmp));
memcpy(nonce + offset, iv + offset, NANOTLS_AES_IV_SIZE - offset);
}
enum ecode nanotls_data_ctx_init(struct nanotls_ctx_data *ctx,
enum nanotls_role role,
const struct nanotls_traffic_keys *keys)
{
const uint8_t *enc_key = NULL;
const uint8_t *dec_key = NULL;
enum ecode ret;
memset(ctx, 0, sizeof(*ctx));
ctx->role = role;
switch (role) {
case NANOTLS_ROLE_HOST:
memcpy(ctx->enc_iv, keys->h2d_iv, sizeof(ctx->enc_iv));
memcpy(ctx->dec_iv, keys->d2h_iv, sizeof(ctx->dec_iv));
#ifdef NANOTLS_CONFIG_KEY_UPDATE
memcpy(ctx->enc_secret, keys->h2d_secret,
sizeof(ctx->enc_secret));
memcpy(ctx->dec_secret, keys->d2h_secret,
sizeof(ctx->dec_secret));
#endif
enc_key = keys->h2d_key;
dec_key = keys->d2h_key;
break;
case NANOTLS_ROLE_DEVICE:
memcpy(ctx->enc_iv, keys->d2h_iv, sizeof(ctx->enc_iv));
memcpy(ctx->dec_iv, keys->h2d_iv, sizeof(ctx->dec_iv));
#ifdef NANOTLS_CONFIG_KEY_UPDATE
memcpy(ctx->enc_secret, keys->d2h_secret,
sizeof(ctx->enc_secret));
memcpy(ctx->dec_secret, keys->h2d_secret,
sizeof(ctx->dec_secret));
#endif
enc_key = keys->d2h_key;
dec_key = keys->h2d_key;
break;
default:
return E_INVALID;
}
ret = nanotls_aes_ctx_init(&ctx->aes_enc, enc_key);
if (ret != E_OK)
return ret;
ret = nanotls_aes_ctx_init(&ctx->aes_dec, dec_key);
if (ret != E_OK)
return ret;
ctx->dec_tag_mismatch_count = 0;
return E_OK;
}
enum ecode nanotls_data_ctx_destroy(struct nanotls_ctx_data *ctx)
{
enum ecode ret;
ret = nanotls_aes_ctx_destroy(&ctx->aes_enc);
if (ret != E_OK)
return ret;
ret = nanotls_aes_ctx_destroy(&ctx->aes_dec);
if (ret != E_OK)
return ret;
memset(ctx, 0, sizeof(*ctx));
ctx->role = NANOTLS_ROLE_UNKNOWN;
return E_OK;
}
enum ecode nanotls_data_write_start(struct nanotls_ctx_data *ctx,
size_t data_size)
{
struct nanotls_data_add add;
uint8_t nonce[NANOTLS_AES_IV_SIZE];
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
ret = nanotls_data_add_init(&add, data_size);
if (ret != E_OK)
return ret;
nanotls_data_get_nonce(nonce, ctx->enc_iv, ctx->enc_seq_no);
ret = nanotls_aes_start_enc(&ctx->aes_enc, nonce, &add, sizeof(add));
if (ret != E_OK)
return ret;
ctx->enc_len_remaining = data_size;
return E_OK;
}
enum ecode nanotls_data_write_update(struct nanotls_ctx_data *ctx,
void *enc_out, const void *plain_in,
size_t data_size)
{
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
if (data_size > ctx->enc_len_remaining)
return E_INVALID;
ret = nanotls_aes_update(&ctx->aes_enc, enc_out, plain_in, data_size);
if (ret != E_OK)
return ret;
ctx->enc_len_remaining -= data_size;
return E_OK;
}
enum ecode nanotls_data_write_finish(struct nanotls_ctx_data *ctx,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
if (ctx->enc_len_remaining > 0)
return E_INVALID;
ret = nanotls_aes_finish(&ctx->aes_enc, tag);
if (ret != E_OK)
return ret;
ctx->enc_seq_no++;
uassert(ctx->enc_seq_no != 0); /* should never happen */
return E_OK;
}
enum ecode nanotls_data_write(struct nanotls_ctx_data *ctx, void *enc_out,
const void *plain_in, size_t data_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
enum ecode ret;
ret = nanotls_data_write_start(ctx, data_size);
if (ret != E_OK)
return ret;
ret = nanotls_data_write_update(ctx, enc_out, plain_in, data_size);
if (ret != E_OK)
return ret;
return nanotls_data_write_finish(ctx, tag);
}
enum ecode nanotls_data_read_start(struct nanotls_ctx_data *ctx,
size_t data_size)
{
struct nanotls_data_add add;
uint8_t nonce[NANOTLS_AES_IV_SIZE];
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
ret = nanotls_data_add_init(&add, data_size);
if (ret != E_OK)
return ret;
nanotls_data_get_nonce(nonce, ctx->dec_iv, ctx->dec_seq_no);
ret = nanotls_aes_start_dec(&ctx->aes_dec, nonce, &add, sizeof(add));
if (ret != E_OK)
return ret;
ctx->dec_len_remaining = data_size;
return E_OK;
}
enum ecode nanotls_data_read_update(struct nanotls_ctx_data *ctx,
void *plain_out, const void *enc_in,
size_t data_size)
{
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
if (data_size > ctx->dec_len_remaining)
return E_INVALID;
ret = nanotls_aes_update(&ctx->aes_dec, plain_out, enc_in, data_size);
if (ret != E_OK)
return ret;
ctx->dec_len_remaining -= data_size;
return E_OK;
}
enum ecode nanotls_data_read_finish(struct nanotls_ctx_data *ctx,
const uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
uint8_t computed_tag[NANOTLS_AES_GCM_TAG_SIZE];
enum ecode ret;
ret = nanotls_data_check_ctx(ctx);
if (ret != E_OK)
return ret;
if (ctx->dec_len_remaining > 0)
return E_INVALID;
ret = nanotls_aes_finish(&ctx->aes_dec, computed_tag);
if (ret != E_OK)
return ret;
ret = nanotls_mem_eq(computed_tag, tag, NANOTLS_AES_GCM_TAG_SIZE);
if (ret != E_OK) {
ctx->dec_tag_mismatch_count++;
#ifdef NANOTLS_CONFIG_MAX_DATA_TAG_MISMATCH_CNT
if (ctx->dec_tag_mismatch_count >
NANOTLS_CONFIG_MAX_DATA_TAG_MISMATCH_CNT)
nanotls_data_ctx_destroy(ctx);
#endif
return ret;
}
ctx->dec_seq_no++;
uassert(ctx->dec_seq_no != 0); /* should never happen */
ctx->dec_tag_mismatch_count = 0;
return E_OK;
}
enum ecode nanotls_data_read(struct nanotls_ctx_data *ctx, void *plain_out,
const void *enc_in, size_t data_size,
const uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
enum ecode ret;
ret = nanotls_data_read_start(ctx, data_size);
if (ret != E_OK)
return ret;
ret = nanotls_data_read_update(ctx, plain_out, enc_in, data_size);
if (ret != E_OK)
return ret;
return nanotls_data_read_finish(ctx, tag);
}
#ifdef NANOTLS_CONFIG_KEY_UPDATE
static enum ecode nanotls_data_key_update(nanotls_aes_context *aes_ctx,
uint8_t iv[NANOTLS_IV_SIZE],
uint8_t secret[NANOTLS_SECRET_SIZE])
{
uint8_t key[NANOTLS_KEY_SIZE];
enum ecode ret;
ret = nanotls_update_traffic_secret(secret, key, iv);
if (ret != E_OK)
return ret;
ret = nanotls_aes_ctx_destroy(aes_ctx);
if (ret != E_OK)
return ret;
ret = nanotls_aes_ctx_init(aes_ctx, key);
if (ret != E_OK)
return ret;
nanotls_mem_erase(key, sizeof(key));
return E_OK;
}
enum ecode nanotls_data_write_key_update(struct nanotls_ctx_data *ctx)
{
uint8_t old_iv[NANOTLS_IV_SIZE];
enum ecode ret;
memcpy(old_iv, ctx->enc_iv, sizeof(old_iv));
ret = nanotls_data_key_update(&ctx->aes_enc, ctx->enc_iv,
ctx->enc_secret);
if (ret != E_OK)
return ret;
/* old IV and new IV should not match */
uassert(nanotls_mem_eq(old_iv, ctx->enc_iv, sizeof(old_iv)) != E_OK);
ctx->enc_seq_no = 0;
return E_OK;
}
enum ecode nanotls_data_read_key_update(struct nanotls_ctx_data *ctx)
{
uint8_t old_iv[NANOTLS_IV_SIZE];
enum ecode ret;
memcpy(old_iv, ctx->dec_iv, sizeof(old_iv));
ret = nanotls_data_key_update(&ctx->aes_dec, ctx->dec_iv,
ctx->dec_secret);
if (ret != E_OK)
return ret;
/* old IV and new IV should not match */
uassert(nanotls_mem_eq(old_iv, ctx->dec_iv, sizeof(old_iv)) != E_OK);
ctx->dec_seq_no = 0;
return E_OK;
}
#endif

374
nanotls/src/nanotls-device.c Executable file
View file

@ -0,0 +1,374 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include <nanotls-device.h>
#include <nanotls-common.h>
#include <nanotls-host.h>
#include <p256-m.h>
static enum ecode nanotls_device_handle_error(struct nanotls_device_ctx *ctx,
enum ecode ret)
{
ctx->error_count++;
#ifdef NANOTLS_CONFIG_MAX_ERR_CNT
if (ctx->error_count >= NANOTLS_CONFIG_MAX_ERR_CNT) {
nanotls_device_cleanup(ctx);
ctx->state = NANOTLS_DEV_ERR;
}
#endif
return ret;
}
enum ecode
nanotls_device_init(struct nanotls_device_ctx *ctx,
const uint8_t ecdsa_priv[NANOTLS_ECDSA_PRIVATE_KEY_SIZE],
const struct nanotls_device_info *device_info)
{
enum ecode ret;
ret = nanotls_secure_random(ctx, sizeof(*ctx));
if (ret != E_OK)
return ret;
nanotls_sha256_init(&ctx->handshake_hash);
memcpy(ctx->ecdsa_priv, ecdsa_priv, sizeof(ctx->ecdsa_priv));
if (device_info) {
memcpy(&ctx->device_info, device_info,
sizeof(ctx->device_info));
}
ctx->error_count = 0;
ctx->state = NANOTLS_DEV_INIT;
return E_OK;
}
enum ecode nanotls_device_host_hello_rcvd(struct nanotls_device_ctx *ctx,
const struct nanotls_host_hello *msg)
{
enum ecode ret = E_INVALID;
if (ctx->state != NANOTLS_DEV_INIT)
return nanotls_device_handle_error(ctx, E_INVALID);
ret = nanotls_hdr_check(&msg->hdr, sizeof(*msg), NANOTLS_HOST_HELLO);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/* Only support a single crypto algorithm combination for now */
if (msg->sig_alg != NANOTLS_ECDSA_SECP256R1_SHA256)
return nanotls_device_handle_error(ctx, E_INVALID);
if (msg->key_exchange_type != NANOTLS_ECDHE_SECP256R1)
return nanotls_device_handle_error(ctx, E_INVALID);
if (msg->cipher_suite != NANOTLS_AES_128_GCM_SHA256)
return nanotls_device_handle_error(ctx, E_INVALID);
/* Feed the entire HostHello to the transcript hash context */
nanotls_sha256_update(&ctx->handshake_hash, msg, sizeof(*msg));
/* Save Host's ECDHE key share (ephemeral public key) */
ctx->host_key_share = msg->host_key_share;
ctx->state = NANOTLS_DEV_HELLO_RCVD;
return E_OK;
}
static enum ecode
nanotls_device_hello_sign(const struct nanotls_device_ctx *ctx,
struct nanotls_device_hello *msg)
{
uint8_t hash_sig[NANOTLS_SHA256_HASH_SIZE];
/* Produce the hash value to sign, as defined in TLS */
nanotls_handshake_sig_hash(ctx->handshake_h2_hash,
NANOTLS_DEVICE_HS_SIG_LABEL, hash_sig);
return nanotls_p256_ecdsa_sign(msg->enc.device_handshake_sig.sig,
ctx->ecdsa_priv, hash_sig,
sizeof(hash_sig));
}
static enum ecode
nanotls_device_derive_hs_secrets(struct nanotls_device_ctx *ctx,
uint8_t hs_traffic_secret[NANOTLS_SECRET_SIZE])
{
uint8_t shared_secret[NANOTLS_SECRET_SIZE];
enum ecode ret = E_INVALID;
/* Compute ECDHE shared secret */
ret = nanotls_p256_ecdh_shared_secret(shared_secret, ctx->ecdh_priv,
ctx->host_key_share.pubkey);
if (ret != E_OK)
return ret;
/* Erase ECDHE private key */
nanotls_mem_erase(ctx->ecdh_priv, sizeof(ctx->ecdh_priv));
nanotls_mem_erase(ctx->host_key_share.pubkey,
sizeof(ctx->host_key_share.pubkey));
/*
* handshake_secret = HKDF-Extract(salt = "", ikm = ecdh_shared_secret)
*
* A deviation from TLS is that it takes a different fixed value of salt
* since we don't support PSK, we just use empty hash as fixed value for
* simplification (one fixed value vs another one).
*/
nanotls_hkdf_sha256_extract(NULL, 0, shared_secret,
sizeof(shared_secret),
ctx->handshake_secret);
/* Erase hared secret as it's no longer needed */
nanotls_mem_erase(shared_secret, sizeof(shared_secret));
/*
* Derive handshake traffic secret with Derive-Secret (HKDF-Expand)
* hs_traffic_secret = Derive-Secret(handshake_secret, label, hash) =
* = HKDF-Expand(handshake_secret, 32 | label |
* transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(ctx->handshake_secret,
NANOTLS_DEVICE_HS_TS_LABEL,
ctx->handshake_h2_hash, hs_traffic_secret);
return E_OK;
}
enum ecode nanotls_device_do_hello(struct nanotls_device_ctx *ctx,
struct nanotls_device_hello *msg)
{
const size_t sig_cutoff_pos = NANOTLS_DEVICE_HELLO_SIG_CUTOFF_POS;
uint8_t dev_hs_traffic_secret[NANOTLS_SECRET_SIZE];
enum ecode ret = E_INVALID;
if (ctx->state != NANOTLS_DEV_HELLO_RCVD)
return nanotls_device_handle_error(ctx, E_INVALID);
memset(msg, 0, sizeof(*msg));
nanotls_hdr_init(&msg->hdr, sizeof(*msg), NANOTLS_DEVICE_HELLO);
/* Fill in the Device Info */
memcpy(&msg->enc.device_info, &ctx->device_info,
sizeof(msg->enc.device_info));
/*
* Device's nonce - used for optional host authentication by device,
* replay protection, and MiTM attack protection.
*/
ret = nanotls_secure_random(msg->random, sizeof(msg->random));
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/* Device's ECDHE key share (ephemeral public key) */
ret = nanotls_p256_gen_keypair(ctx->ecdh_priv,
msg->device_key_share.pubkey);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/*
* [H2]
* Feed the DeviceHello content up until the handshake_sig to transcript
* hash context, handshake_sig (aka CertificateVerify) is yet to
* be generated using this transcript hash.
*/
nanotls_sha256_update(&ctx->handshake_hash, msg, sig_cutoff_pos);
nanotls_sha256_digest(&ctx->handshake_hash,
ctx->handshake_h2_hash); /* [H2] */
/*
* All ECDHE steps have been completed, now calculate ECDHE shared
* secret and derive Handshake Secrets from it.
*/
ret = nanotls_device_derive_hs_secrets(ctx, dev_hs_traffic_secret);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/*
* Generate handshake_sig (aka CertificateVerify)
* using Device's private key and handshake context (H2).
*/
ret = nanotls_device_hello_sign(ctx, msg);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/* Erase the ECDSA private key as it's not needed anymore */
nanotls_mem_erase(ctx->ecdsa_priv, sizeof(ctx->ecdsa_priv));
/* [H7] Update handshake transcript with the part before Finished */
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc,
NANOTLS_DEVICE_HELLO_FINISHED_ENC_CUTOFF_POS);
/* Produce a device_finished message (MAC over transcript hash). */
nanotls_write_finished(&ctx->handshake_hash, dev_hs_traffic_secret,
msg->enc.device_finished.verify_data);
/* [H3] Update handshake transcript with just created device_finished */
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc.device_finished,
sizeof(msg->enc.device_finished));
/* Encrypt device signature and Finished */
nanotls_handshake_encrypt(&msg->enc, sizeof(msg->enc), &msg->auth_tag,
dev_hs_traffic_secret);
nanotls_mem_erase(dev_hs_traffic_secret, sizeof(dev_hs_traffic_secret));
ctx->state = NANOTLS_DEV_HELLO_SENT;
return E_OK;
}
static enum ecode nanotls_device_verify_host_finished(
const struct nanotls_device_ctx *ctx,
const struct nanotls_host_finished *msg,
const uint8_t host_hs_traffic_secret[NANOTLS_SECRET_SIZE])
{
uint8_t verify_data[NANOTLS_SHA256_HASH_SIZE];
nanotls_write_finished(&ctx->handshake_hash, host_hs_traffic_secret,
verify_data);
return nanotls_mem_eq(verify_data, msg->enc.host_finished.verify_data,
sizeof(verify_data));
}
enum ecode nanotls_device_host_finished_rcvd(struct nanotls_device_ctx *ctx,
struct nanotls_host_finished *msg)
{
const size_t finished_cutoff_pos =
NANOTLS_HOST_HELLO_FINISHED_CUTOFF_POS;
uint8_t host_hs_traffic_secret[NANOTLS_SECRET_SIZE];
enum ecode ret = E_INVALID;
if (ctx->state != NANOTLS_DEV_HELLO_SENT)
return nanotls_device_handle_error(ctx, E_INVALID);
ret = nanotls_hdr_check(&msg->hdr, sizeof(*msg), NANOTLS_HOST_FINISHED);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/*
* Derive handshake traffic secret with Derive-Secret (HKDF-Expand)
* hs_traffic_secret = Derive-Secret(handshake_secret, label, hash) =
* = HKDF-Expand(handshake_secret, 32 | label |
* transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(ctx->handshake_secret,
NANOTLS_HOST_HS_TS_LABEL,
ctx->handshake_h2_hash,
host_hs_traffic_secret);
ret = nanotls_handshake_decrypt_verify(&msg->enc, sizeof(msg->enc),
&msg->auth_tag,
host_hs_traffic_secret);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/* [H9] Update handshake transcript with the starting part of
* HostFinished */
nanotls_sha256_update(&ctx->handshake_hash, msg, finished_cutoff_pos);
/*
* Verify host_finished message.
* It's a MAC over transcript hash computed using handshake secret
* computed by the Host.
*/
ret = nanotls_device_verify_host_finished(ctx, msg,
host_hs_traffic_secret);
if (ret != E_OK)
return nanotls_device_handle_error(ctx, ret);
/*
* [H4] - Full transcript hash
* Update handshake transcript with just processed host_finished
* H4 = SHA256(HostHello | DeviceHello | HostFinished)
*/
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc.host_finished,
sizeof(msg->enc.host_finished));
/*
* At this point, handshake is completed from the Device perspective.
* The Device has everything to derive the final Master Secret.
*
* Now call nanotls_device_derive_traffic_keys() to get the encryption
* keys.
*/
nanotls_derive_master_secret(ctx->master_secret, ctx->handshake_secret);
nanotls_mem_erase(host_hs_traffic_secret,
sizeof(host_hs_traffic_secret));
ctx->state = NANOTLS_DEV_DONE;
return E_OK;
}
enum ecode nanotls_device_derive_traffic_keys_instance(
const struct nanotls_device_ctx *ctx, struct nanotls_traffic_keys *keys,
size_t instance_idx)
{
uint8_t transcript_hash[NANOTLS_SHA256_HASH_SIZE];
uint8_t instance_label_hash[NANOTLS_SHA256_HASH_SIZE];
if (ctx->state != NANOTLS_DEV_DONE)
return E_INVALID;
nanotls_hkdf_sha256_extract(&instance_idx, sizeof(instance_idx),
NANOTLS_KEY_INSTANCE_LABEL,
instance_label_hash);
nanotls_sha256_digest(&ctx->handshake_hash, transcript_hash); /* [H4] */
nanotls_derive_traffic_keys(ctx->master_secret, transcript_hash,
instance_label_hash,
sizeof(instance_label_hash), keys);
return E_OK;
}
enum ecode
nanotls_device_derive_traffic_keys(const struct nanotls_device_ctx *ctx,
struct nanotls_traffic_keys *keys)
{
uint8_t hash[NANOTLS_SHA256_HASH_SIZE];
if (ctx->state != NANOTLS_DEV_DONE)
return E_INVALID;
nanotls_sha256_digest(&ctx->handshake_hash, hash); /* [H4] */
nanotls_derive_traffic_keys(ctx->master_secret, hash, NULL, 0, keys);
return E_OK;
}
enum ecode nanotls_device_cleanup(struct nanotls_device_ctx *ctx)
{
nanotls_mem_erase(ctx, sizeof(*ctx));
ctx->state = NANOTLS_DEV_UNINIT;
return E_OK;
}

269
nanotls/src/nanotls-hooks.c Executable file
View file

@ -0,0 +1,269 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include <nanotls-hooks.h>
#include <asm/string.h>
#include <linux/random.h>
#include <p256-m.h>
#include "nanotls-common.h"
enum ecode nanotls_secure_random(void *buf, size_t size)
{
get_random_bytes(buf, size);
return E_OK;
}
enum ecode nanotls_p256_gen_keypair(uint8_t priv[32], uint8_t pub[64])
{
return (p256_gen_keypair(priv, pub) == P256_SUCCESS) ? E_OK : E_INVALID;
}
enum ecode nanotls_p256_ecdh_shared_secret(uint8_t secret[32],
const uint8_t priv[32],
const uint8_t pub[64])
{
return (p256_ecdh_shared_secret(secret, priv, pub) == P256_SUCCESS) ?
E_OK :
E_INVALID;
}
enum ecode nanotls_p256_ecdsa_sign(uint8_t sig[64], const uint8_t priv[32],
const uint8_t *hash, size_t hlen)
{
return (p256_ecdsa_sign(sig, priv, hash, hlen) == P256_SUCCESS) ?
E_OK :
E_INVALID;
}
enum ecode nanotls_p256_ecdsa_verify(const uint8_t sig[64],
const uint8_t pub[64], const uint8_t *hash,
size_t hlen)
{
return (p256_ecdsa_verify(sig, pub, hash, hlen) == P256_SUCCESS) ?
E_OK :
E_INVALID;
}
enum ecode nanotls_sha256_init(nanotls_sha_ctx *ctx)
{
cf_sha256_init(ctx);
return E_OK;
}
enum ecode nanotls_sha256_update(nanotls_sha_ctx *ctx, const void *buf,
size_t size)
{
cf_sha256_update(ctx, buf, size);
return E_OK;
}
enum ecode nanotls_sha256_digest(const nanotls_sha_ctx *ctx,
uint8_t hash[NANOTLS_SHA256_HASH_SIZE])
{
cf_sha256_digest(ctx, hash);
return E_OK;
}
enum ecode nanotls_sha256_digest_final(nanotls_sha_ctx *ctx,
uint8_t hash[NANOTLS_SHA256_HASH_SIZE])
{
cf_sha256_digest_final(ctx, hash);
return E_OK;
}
enum ecode nanotls_hmac_sha256_init(nanotls_hmac_ctx *ctx, const void *key,
size_t key_size)
{
cf_hmac_init(ctx, &cf_sha256, key, key_size);
return E_OK;
}
enum ecode nanotls_hmac_sha256_update(nanotls_hmac_ctx *ctx, const void *data,
size_t data_size)
{
cf_hmac_update(ctx, data, data_size);
return E_OK;
}
enum ecode nanotls_hmac_sha256_finish(nanotls_hmac_ctx *ctx,
uint8_t result[NANOTLS_SHA256_HASH_SIZE])
{
cf_hmac_finish(ctx, result);
return E_OK;
}
enum ecode nanotls_hmac_sha256(const void *key, size_t key_size,
const void *data, size_t data_size,
uint8_t result[NANOTLS_SHA256_HASH_SIZE])
{
nanotls_hmac_ctx ctx;
enum ecode ret = E_INVALID;
ret = nanotls_hmac_sha256_init(&ctx, key, key_size);
if (ret != E_OK)
return ret;
ret = nanotls_hmac_sha256_update(&ctx, data, data_size);
if (ret != E_OK)
return ret;
ret = nanotls_hmac_sha256_finish(&ctx, result);
if (ret != E_OK)
return ret;
return E_OK;
}
/*
* AES API - needed post-handshake.
* Only AES-GCM-128 is supported with fixed 12 byte IV size.
*/
enum ecode nanotls_aes_ctx_init(nanotls_aes_context *ctx,
const uint8_t key[NANOTLS_AES_KEY_SIZE])
{
int ret;
ret = gcm_setkey(ctx, key, NANOTLS_AES_KEY_SIZE);
return (ret == 0) ? E_OK : E_INVALID;
}
enum ecode nanotls_aes_start_enc(nanotls_aes_context *ctx,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size)
{
int ret;
ret = gcm_start(ctx, AES_MODE_ENCRYPT, iv, NANOTLS_AES_IV_SIZE, add,
add_size);
return (ret == 0) ? E_OK : E_INVALID;
}
enum ecode nanotls_aes_start_dec(nanotls_aes_context *ctx,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size)
{
int ret;
ret = gcm_start(ctx, AES_MODE_DECRYPT, iv, NANOTLS_AES_IV_SIZE, add,
add_size);
return (ret == 0) ? E_OK : E_INVALID;
}
enum ecode nanotls_aes_update(nanotls_aes_context *ctx, void *out,
const void *in, size_t data_size)
{
int ret;
ret = gcm_update(ctx, data_size, in, out);
return (ret == 0) ? E_OK : E_INVALID;
}
enum ecode nanotls_aes_finish(nanotls_aes_context *ctx,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
int ret;
ret = gcm_finish(ctx, tag, NANOTLS_AES_GCM_TAG_SIZE);
return (ret == 0) ? E_OK : E_INVALID;
}
enum ecode nanotls_aes_ctx_destroy(nanotls_aes_context *ctx)
{
nanotls_mem_erase(ctx, sizeof(*ctx));
ctx->mode = AES_MODE_NONE;
/* Not needed as we're erasing it already */
/* gcm_zero_ctx(ctx); */
return E_OK;
}
enum ecode nanotls_aes_encrypt(nanotls_aes_context *ctx, void *out_data,
const void *in_data, size_t data_size,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
enum ecode ret;
ret = nanotls_aes_start_enc(ctx, iv, add, add_size);
if (ret != E_OK)
return ret;
ret = nanotls_aes_update(ctx, out_data, in_data, data_size);
if (ret != E_OK)
return ret;
ret = nanotls_aes_finish(ctx, tag);
if (ret != E_OK)
return ret;
return E_OK;
}
enum ecode nanotls_aes_decrypt(nanotls_aes_context *ctx, void *out_data,
const void *in_data, size_t data_size,
const uint8_t iv[NANOTLS_AES_IV_SIZE],
const void *add, size_t add_size,
uint8_t tag[NANOTLS_AES_GCM_TAG_SIZE])
{
enum ecode ret;
ret = nanotls_aes_start_dec(ctx, iv, add, add_size);
if (ret != E_OK)
return ret;
ret = nanotls_aes_update(ctx, out_data, in_data, data_size);
if (ret != E_OK)
return ret;
ret = nanotls_aes_finish(ctx, tag);
if (ret != E_OK)
return ret;
return E_OK;
}
/* Provide random API to P256 library (for ECDSA & ECDH) */
int p256_generate_random(uint8_t *output, unsigned output_size)
{
return (nanotls_secure_random(output, output_size) == E_OK) ? 0 : -1;
}
void p256_mem_zeroize(void *buf, size_t bytes)
{
nanotls_mem_erase(buf, bytes);
}

416
nanotls/src/nanotls-host.c Executable file
View file

@ -0,0 +1,416 @@
/*
* Copyright 2025 NXP
*
* NXP CONFIDENTIAL
* The source code contained or described herein and all documents related to
* the source code ("Materials") are owned by NXP, its
* suppliers and/or its licensors. Title to the Materials remains with NXP,
* its suppliers and/or its licensors. The Materials contain
* trade secrets and proprietary and confidential information of NXP, its
* suppliers and/or its licensors. The Materials are protected by worldwide
* copyright and trade secret laws and treaty provisions. No part of the
* Materials may be used, copied, reproduced, modified, published, uploaded,
* posted, transmitted, distributed, or disclosed in any way without NXP's prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by NXP in writing.
*/
#include <nanotls-host.h>
#include <nanotls-common.h>
#include <asm/string.h>
#include <p256-m.h>
static enum ecode nanotls_host_handle_error(struct nanotls_host_ctx *ctx,
enum ecode ret)
{
ctx->error_count++;
#ifdef NANOTLS_CONFIG_MAX_ERR_CNT
if (ctx->error_count >= NANOTLS_CONFIG_MAX_ERR_CNT) {
nanotls_host_cleanup(ctx);
ctx->state = NANOTLS_HOST_ERR;
}
#endif
return ret;
}
enum ecode
nanotls_host_init(struct nanotls_host_ctx *ctx,
const uint8_t ecdsa_pub[NANOTLS_ECDSA_PUBLIC_KEY_SIZE])
{
enum ecode ret;
ret = nanotls_secure_random(ctx, sizeof(*ctx));
if (ret != E_OK)
return ret;
nanotls_sha256_init(&ctx->handshake_hash);
if (ecdsa_pub) {
memcpy(ctx->ecdsa_pub, ecdsa_pub, sizeof(ctx->ecdsa_pub));
}
ctx->error_count = 0;
ctx->state = NANOTLS_HOST_INIT;
ctx->pub_key_req_cb = NULL;
return E_OK;
}
enum ecode
nanotls_host_init_pubkey_cb(struct nanotls_host_ctx *ctx,
nanotls_host_pub_key_req_cb pub_key_req_cb)
{
enum ecode ret;
ret = nanotls_host_init(ctx, NULL);
if (ret != E_OK)
return ret;
ctx->pub_key_req_cb = pub_key_req_cb;
return E_OK;
}
enum ecode nanotls_host_do_hello(struct nanotls_host_ctx *ctx,
struct nanotls_host_hello *msg)
{
enum ecode ret = E_INVALID;
if (ctx->state != NANOTLS_HOST_INIT)
return nanotls_host_handle_error(ctx, E_INVALID);
memset(msg, 0, sizeof(*msg));
nanotls_hdr_init(&msg->hdr, sizeof(*msg), NANOTLS_HOST_HELLO);
msg->sig_alg = NANOTLS_ECDSA_SECP256R1_SHA256;
msg->key_exchange_type = NANOTLS_ECDHE_SECP256R1;
msg->cipher_suite = NANOTLS_AES_128_GCM_SHA256;
/*
* Host's nonce - used for device authentication by host,
* replay protection, and MiTM attack protection.
*/
ret = nanotls_secure_random(msg->random, sizeof(msg->random));
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
/* Host's ECDHE key share (ephemeral public key) */
ret = nanotls_p256_gen_keypair(ctx->ecdh_priv,
msg->host_key_share.pubkey);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
/*
* Feed the entire HostHello to the transcript hash context.
* Important: our copy, hashed before sending (i.e. trusted).
*/
nanotls_sha256_update(&ctx->handshake_hash, msg, sizeof(*msg));
ctx->state = NANOTLS_HOST_HELLO_SENT;
return E_OK;
}
static enum ecode
nanotls_host_device_hello_sig_verify(const struct nanotls_host_ctx *ctx,
const struct nanotls_device_hello *msg)
{
uint8_t hash_sig[NANOTLS_HASH_SIZE];
/* Produce the hash value to sign, as defined in TLS */
nanotls_handshake_sig_hash(ctx->handshake_h2_hash,
NANOTLS_DEVICE_HS_SIG_LABEL, hash_sig);
return nanotls_p256_ecdsa_verify(msg->enc.device_handshake_sig.sig,
ctx->ecdsa_pub, hash_sig,
sizeof(hash_sig));
}
static enum ecode
nanotls_host_derive_hs_secrets(struct nanotls_host_ctx *ctx,
uint8_t hs_traffic_secret[NANOTLS_SECRET_SIZE])
{
uint8_t shared_secret[NANOTLS_SECRET_SIZE];
enum ecode ret = E_INVALID;
/* Compute ECDHE shared secret */
ret = nanotls_p256_ecdh_shared_secret(shared_secret, ctx->ecdh_priv,
ctx->device_key_share.pubkey);
if (ret != E_OK)
return ret;
/* Erase ECDHE keys */
nanotls_mem_erase(ctx->ecdh_priv, sizeof(ctx->ecdh_priv));
nanotls_mem_erase(ctx->device_key_share.pubkey,
sizeof(ctx->device_key_share.pubkey));
/*
* handshake_secret = HKDF-Extract(salt = "", ikm = ecdh_shared_secret)
*
* TLS deviation: it takes a different fixed value of salt
* since we don't support PSK, we just use empty hash as fixed value for
* simplification (one fixed value vs another one).
*/
nanotls_hkdf_sha256_extract(NULL, 0, shared_secret,
sizeof(shared_secret),
ctx->handshake_secret);
/* Erase hared secret as it's no longer needed */
nanotls_mem_erase(shared_secret, sizeof(shared_secret));
/*
* Derive handshake traffic secret with Derive-Secret (HKDF-Expand)
* hs_traffic_secret = Derive-Secret(handshake_secret, label, hash) =
* = HKDF-Expand(handshake_secret, 32 | label |
* transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(ctx->handshake_secret,
NANOTLS_DEVICE_HS_TS_LABEL,
ctx->handshake_h2_hash, hs_traffic_secret);
return E_OK;
}
static enum ecode nanotls_host_verify_device_finished(
const struct nanotls_host_ctx *ctx,
const struct nanotls_device_hello *msg,
const uint8_t hs_traffic_secret[NANOTLS_SECRET_SIZE])
{
uint8_t verify_data[NANOTLS_SHA256_HASH_SIZE];
nanotls_write_finished(&ctx->handshake_hash, hs_traffic_secret,
verify_data);
return nanotls_mem_eq(verify_data, msg->enc.device_finished.verify_data,
sizeof(verify_data));
}
enum ecode nanotls_host_device_hello_rcvd(struct nanotls_host_ctx *ctx,
struct nanotls_device_hello *msg)
{
const size_t sig_cutoff_pos = NANOTLS_DEVICE_HELLO_SIG_CUTOFF_POS;
uint8_t dev_hs_traffic_secret[NANOTLS_SECRET_SIZE];
enum ecode ret = E_INVALID;
if (ctx->state != NANOTLS_HOST_HELLO_SENT)
return nanotls_host_handle_error(ctx, E_INVALID);
ret = nanotls_hdr_check(&msg->hdr, sizeof(*msg), NANOTLS_DEVICE_HELLO);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
/*
* [H2]
* Feed the DeviceHello content up until the handshake_sig to transcript
* hash context.
*/
nanotls_sha256_update(&ctx->handshake_hash, msg, sig_cutoff_pos);
nanotls_sha256_digest(&ctx->handshake_hash,
ctx->handshake_h2_hash); /* [H2] */
/* Save Device's ECDHE key share (ephemeral public key) */
ctx->device_key_share = msg->device_key_share;
/*
* All ECDHE steps have been completed, now calculate ECDHE shared
* secret and derive Handshake Secret from it.
*/
ret = nanotls_host_derive_hs_secrets(ctx, dev_hs_traffic_secret);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
ret = nanotls_handshake_decrypt_verify(&msg->enc, sizeof(msg->enc),
&msg->auth_tag,
dev_hs_traffic_secret);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
memcpy(&ctx->device_info, &msg->enc.device_info,
sizeof(ctx->device_info));
/*
* Verify ECDSA signature handshake_sig using Device's public key.
*
* This is the key point where Device authentication happens:
* - Host generates a random (HostHello.random)
* - Device signs the entire handshake (incl. Host's random) with its
* private key (DeviceHello.device_handshake_sig)
* - Host now verifies ECDSA signature generated by device using
* Device's public key
*
* Only the device that possesses the proper private key could sign the
* Host's random.
* For this reason Host's random should be of a good quality and never
* repeat.
*
* If the device is an impostor and does not pose a valid private key,
* the handshake will fail at this point.
*/
if (ctx->pub_key_req_cb) {
/* device public key is not valid, and we need to first fetch it
* using callback */
ret = ctx->pub_key_req_cb(ctx, &msg->enc.device_info,
ctx->ecdsa_pub);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
}
ret = nanotls_host_device_hello_sig_verify(ctx, msg);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
/* [H7] Update handshake transcript with the part before Finished */
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc,
NANOTLS_DEVICE_HELLO_FINISHED_ENC_CUTOFF_POS);
/*
* Verify device_finished message.
* It's a MAC over transcript hash computed using handshake secret
* computed by the Device.
*/
ret = nanotls_host_verify_device_finished(ctx, msg,
dev_hs_traffic_secret);
if (ret != E_OK)
return nanotls_host_handle_error(ctx, ret);
/* [H3] Update handshake transcript with just processed device_finished
*/
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc.device_finished,
sizeof(msg->enc.device_finished));
nanotls_mem_erase(dev_hs_traffic_secret, sizeof(dev_hs_traffic_secret));
ctx->state = NANOTLS_HOST_HELLO_RCVD;
return E_OK;
}
enum ecode nanotls_host_get_device_info(const struct nanotls_host_ctx *ctx,
struct nanotls_device_info *device_info)
{
switch (ctx->state) {
case NANOTLS_HOST_HELLO_RCVD:
case NANOTLS_HOST_DONE:
break;
default:
return E_INVALID;
}
memcpy(device_info, &ctx->device_info, sizeof(ctx->device_info));
return E_OK;
}
enum ecode nanotls_host_do_finished(struct nanotls_host_ctx *ctx,
struct nanotls_host_finished *msg)
{
const size_t finished_cutoff_pos =
NANOTLS_HOST_HELLO_FINISHED_CUTOFF_POS;
uint8_t host_hs_traffic_secret[NANOTLS_SECRET_SIZE];
if (ctx->state != NANOTLS_HOST_HELLO_RCVD)
return nanotls_host_handle_error(ctx, E_INVALID);
memset(msg, 0, sizeof(*msg));
nanotls_hdr_init(&msg->hdr, sizeof(*msg), NANOTLS_HOST_FINISHED);
/* [H9] Update handshake transcript with the starting part of
* HostFinished */
nanotls_sha256_update(&ctx->handshake_hash, msg, finished_cutoff_pos);
/*
* Derive handshake traffic secret with Derive-Secret (HKDF-Expand)
* hs_traffic_secret = Derive-Secret(handshake_secret, label, hash) =
* = HKDF-Expand(handshake_secret, 32 | label |
* transcript_hash, 32)
*/
nanotls_hkdf_derive_secret(ctx->handshake_secret,
NANOTLS_HOST_HS_TS_LABEL,
ctx->handshake_h2_hash,
host_hs_traffic_secret);
/* Produce host_finished message (MAC over transcript hash [H9]). */
nanotls_write_finished(&ctx->handshake_hash, host_hs_traffic_secret,
msg->enc.host_finished.verify_data);
/*
* [H4] - Full transcript hash
* Update handshake transcript with just created host_finished.
* H4 = SHA256(HostHello | DeviceHello | HostFinished)
*/
nanotls_sha256_update(&ctx->handshake_hash, &msg->enc.host_finished,
sizeof(msg->enc.host_finished));
nanotls_handshake_encrypt(&msg->enc, sizeof(msg->enc), &msg->auth_tag,
host_hs_traffic_secret);
/*
* At this point, handshake is completed from the Host's perspective.
* Host Authenticated the Device and has everything to derive the final
* Master Secret.
*
* Now call nanotls_host_derive_traffic_keys() to get the encryption
* keys.
*/
nanotls_derive_master_secret(ctx->master_secret, ctx->handshake_secret);
nanotls_mem_erase(host_hs_traffic_secret,
sizeof(host_hs_traffic_secret));
ctx->state = NANOTLS_HOST_DONE;
return E_OK;
}
enum ecode
nanotls_host_derive_traffic_keys_instance(const struct nanotls_host_ctx *ctx,
struct nanotls_traffic_keys *keys,
size_t instance_idx)
{
uint8_t transcript_hash[NANOTLS_SHA256_HASH_SIZE];
uint8_t instance_label_hash[NANOTLS_SHA256_HASH_SIZE];
if (ctx->state != NANOTLS_HOST_DONE)
return E_INVALID;
nanotls_hkdf_sha256_extract(&instance_idx, sizeof(instance_idx),
NANOTLS_KEY_INSTANCE_LABEL,
instance_label_hash);
nanotls_sha256_digest(&ctx->handshake_hash, transcript_hash); /* [H4] */
nanotls_derive_traffic_keys(ctx->master_secret, transcript_hash,
instance_label_hash,
sizeof(instance_label_hash), keys);
return E_OK;
}
enum ecode nanotls_host_derive_traffic_keys(const struct nanotls_host_ctx *ctx,
struct nanotls_traffic_keys *keys)
{
uint8_t hash[NANOTLS_SHA256_HASH_SIZE];
if (ctx->state != NANOTLS_HOST_DONE)
return E_INVALID;
nanotls_sha256_digest(&ctx->handshake_hash, hash); /* [H4] */
nanotls_derive_traffic_keys(ctx->master_secret, hash, NULL, 0, keys);
return E_OK;
}
enum ecode nanotls_host_cleanup(struct nanotls_host_ctx *ctx)
{
nanotls_mem_erase(ctx, sizeof(*ctx));
ctx->state = NANOTLS_HOST_UNINIT;
return E_OK;
}