Skip to content

Commit 6a04f04

Browse files
authored
Merge branch 'Jason2866:release/v5.2' into release/v5.2
2 parents 91902b6 + 00b1214 commit 6a04f04

File tree

14 files changed

+154
-67
lines changed

14 files changed

+154
-67
lines changed

components/bt/esp_ble_mesh/core/net.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
* SPDX-FileCopyrightText: 2017 Intel Corporation
5-
* SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
5+
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
66
*
77
* SPDX-License-Identifier: Apache-2.0
88
*/
@@ -1129,23 +1129,34 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
11291129
if (((IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) ||
11301130
(IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en())) &&
11311131
(bt_mesh_fixed_group_match(tx->ctx->addr) || bt_mesh_elem_find(tx->ctx->addr))) {
1132-
if (cb && cb->start) {
1133-
cb->start(0, 0, cb_data);
1134-
}
1132+
/**
1133+
* If the target address isn't a unicast address, then the callback function
1134+
* will be called by `adv task` in place of here, to avoid the callback function
1135+
* being called twice.
1136+
* See BLEMESH24-76 for more details.
1137+
*/
1138+
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
1139+
if (cb && cb->start) {
1140+
cb->start(0, 0, cb_data);
1141+
}
11351142

1136-
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
1143+
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
11371144

1138-
if (cb && cb->end) {
1139-
cb->end(0, cb_data);
1140-
}
1145+
if (cb && cb->end) {
1146+
cb->end(0, cb_data);
1147+
}
11411148

1142-
bt_mesh_net_local();
1149+
bt_mesh_net_local();
1150+
1151+
err = 0;
11431152

1144-
err = 0;
1145-
/* If it is a group address, it still needs to be relayed */
1146-
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
11471153
goto done;
1154+
} else {
1155+
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
1156+
bt_mesh_net_local();
11481157
}
1158+
1159+
err = 0;
11491160
}
11501161

11511162
if ((bearer & BLE_MESH_ADV_BEARER) &&

components/esp_wifi/include/esp_wifi_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ typedef struct {
961961
typedef enum {
962962
WPS_FAIL_REASON_NORMAL = 0, /**< WPS normal fail reason */
963963
WPS_FAIL_REASON_RECV_M2D, /**< WPS receive M2D frame */
964+
WPS_FAIL_REASON_RECV_DEAUTH, /**< Recv deauth from AP while wps handshake */
964965
WPS_FAIL_REASON_MAX
965966
} wifi_event_sta_wps_fail_reason_t;
966967

components/ulp/lp_core/lp_core_i2c.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ static esp_err_t lp_i2c_gpio_is_cfg_valid(gpio_num_t sda_io_num, gpio_num_t scl_
4545

4646
static esp_err_t lp_i2c_configure_io(gpio_num_t io_num, bool pullup_en)
4747
{
48+
/* Set the IO pin to high to avoid them from toggling from Low to High state during initialization. This can register a spurious I2C start condition. */
49+
ESP_RETURN_ON_ERROR(rtc_gpio_set_level(io_num, 1), LPI2C_TAG, "LP GPIO failed to set level to high for %d", io_num);
4850
/* Initialize IO Pin */
4951
ESP_RETURN_ON_ERROR(rtc_gpio_init(io_num), LPI2C_TAG, "LP GPIO Init failed for GPIO %d", io_num);
50-
5152
/* Set direction to input+output open-drain mode */
5253
ESP_RETURN_ON_ERROR(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_OUTPUT_OD), LPI2C_TAG, "LP GPIO Set direction failed for %d", io_num);
5354
/* Disable pulldown on the io pin */
@@ -72,12 +73,16 @@ static esp_err_t lp_i2c_set_pin(const lp_core_i2c_cfg_t *cfg)
7273
/* Verify that the LP I2C GPIOs are valid */
7374
ESP_RETURN_ON_ERROR(lp_i2c_gpio_is_cfg_valid(sda_io_num, scl_io_num), LPI2C_TAG, "LP I2C GPIO config invalid");
7475

75-
/* Initialize SDA Pin */
76-
ESP_RETURN_ON_ERROR(lp_i2c_configure_io(sda_io_num, sda_pullup_en), LPI2C_TAG, "LP I2C SDA pin config failed");
76+
// NOTE: We always initialize the SCL pin first, then the SDA pin.
77+
// This order of initialization is important to avoid any spurious
78+
// I2C start conditions on the bus.
7779

7880
/* Initialize SCL Pin */
7981
ESP_RETURN_ON_ERROR(lp_i2c_configure_io(scl_io_num, scl_pullup_en), LPI2C_TAG, "LP I2C SCL pin config failed");
8082

83+
/* Initialize SDA Pin */
84+
ESP_RETURN_ON_ERROR(lp_i2c_configure_io(sda_io_num, sda_pullup_en), LPI2C_TAG, "LP I2C SDA pin config failed");
85+
8186
/* Select LP I2C function for the SDA Pin */
8287
lp_io_dev->gpio[sda_io_num].mcu_sel = 1;
8388

@@ -103,7 +108,7 @@ static esp_err_t lp_i2c_config_clk(const lp_core_i2c_cfg_t *cfg)
103108
}
104109
}
105110

106-
/* Fetch the clock source fequency */
111+
/* Fetch the clock source frequency */
107112
ESP_RETURN_ON_ERROR(esp_clk_tree_src_get_freq_hz(source_clk, ESP_CLK_TREE_SRC_FREQ_PRECISION_APPROX, &source_freq), LPI2C_TAG, "Invalid LP I2C source clock selected");
108113

109114
/* Verify that the I2C_SCLK operates at a frequency 20 times larger than the requested SCL bus frequency */
@@ -141,6 +146,9 @@ esp_err_t lp_core_i2c_master_init(i2c_port_t lp_i2c_num, const lp_core_i2c_cfg_t
141146
/* Initialize LP I2C HAL */
142147
i2c_hal_init(&i2c_hal, lp_i2c_num);
143148

149+
/* Clear any pending interrupts */
150+
i2c_ll_clear_intr_mask(i2c_hal.dev, UINT32_MAX);
151+
144152
/* Initialize LP I2C Master mode */
145153
i2c_hal_master_init(&i2c_hal);
146154

components/ulp/ulp_riscv/ulp_riscv_i2c.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ static esp_err_t i2c_gpio_is_cfg_valid(gpio_num_t sda_io_num, gpio_num_t scl_io_
7272

7373
static esp_err_t i2c_configure_io(gpio_num_t io_num, bool pullup_en)
7474
{
75+
/* Set the IO pin to high to avoid them from toggling from Low to High state during initialization. This can register a spurious I2C start condition. */
76+
ESP_RETURN_ON_ERROR(rtc_gpio_set_level(io_num, 1), RTCI2C_TAG, "RTC GPIO failed to set level to high for %d", io_num);
7577
/* Initialize IO Pin */
7678
ESP_RETURN_ON_ERROR(rtc_gpio_init(io_num), RTCI2C_TAG, "RTC GPIO Init failed for GPIO %d", io_num);
7779
/* Set direction to input+output */
@@ -98,12 +100,16 @@ static esp_err_t i2c_set_pin(const ulp_riscv_i2c_cfg_t *cfg)
98100
/* Verify that the I2C GPIOs are valid */
99101
ESP_RETURN_ON_ERROR(i2c_gpio_is_cfg_valid(sda_io_num, scl_io_num), RTCI2C_TAG, "RTC I2C GPIO config invalid");
100102

101-
/* Initialize SDA Pin */
102-
ESP_RETURN_ON_ERROR(i2c_configure_io(sda_io_num, sda_pullup_en), RTCI2C_TAG, "RTC I2C SDA pin config failed");
103+
// NOTE: We always initialize the SCL pin first, then the SDA pin.
104+
// This order of initialization is important to avoid any spurious
105+
// I2C start conditions on the bus.
103106

104107
/* Initialize SCL Pin */
105108
ESP_RETURN_ON_ERROR(i2c_configure_io(scl_io_num, scl_pullup_en), RTCI2C_TAG, "RTC I2C SCL pin config failed");
106109

110+
/* Initialize SDA Pin */
111+
ESP_RETURN_ON_ERROR(i2c_configure_io(sda_io_num, sda_pullup_en), RTCI2C_TAG, "RTC I2C SDA pin config failed");
112+
107113
/* Route SDA IO signal to the RTC subsystem */
108114
rtc_io_dev->touch_pad[sda_io_num].mux_sel = 1;
109115

@@ -471,6 +477,12 @@ esp_err_t ulp_riscv_i2c_master_init(const ulp_riscv_i2c_cfg_t *cfg)
471477
WRITE_PERI_REG(RTC_I2C_CTRL_REG, 0);
472478
WRITE_PERI_REG(SENS_SAR_I2C_CTRL_REG, 0);
473479

480+
/* Verify that the input cfg param is valid */
481+
ESP_RETURN_ON_FALSE(cfg, ESP_ERR_INVALID_ARG, RTCI2C_TAG, "RTC I2C configuration is NULL");
482+
483+
/* Configure RTC I2C GPIOs */
484+
ESP_RETURN_ON_ERROR(i2c_set_pin(cfg), RTCI2C_TAG, "Failed to configure RTC I2C GPIOs");
485+
474486
/* Reset RTC I2C */
475487
#if CONFIG_IDF_TARGET_ESP32S2
476488
i2c_dev->ctrl.i2c_reset = 1;
@@ -484,12 +496,6 @@ esp_err_t ulp_riscv_i2c_master_init(const ulp_riscv_i2c_cfg_t *cfg)
484496
CLEAR_PERI_REG_MASK(SENS_SAR_PERI_RESET_CONF_REG, SENS_RTC_I2C_RESET);
485497
#endif // CONFIG_IDF_TARGET_ESP32S2
486498

487-
/* Verify that the input cfg param is valid */
488-
ESP_RETURN_ON_FALSE(cfg, ESP_ERR_INVALID_ARG, RTCI2C_TAG, "RTC I2C configuration is NULL");
489-
490-
/* Configure RTC I2C GPIOs */
491-
ESP_RETURN_ON_ERROR(i2c_set_pin(cfg), RTCI2C_TAG, "Failed to configure RTC I2C GPIOs");
492-
493499
/* Enable internal open-drain mode for SDA and SCL lines */
494500
#if CONFIG_IDF_TARGET_ESP32S2
495501
i2c_dev->ctrl.sda_force_out = 0;
@@ -519,6 +525,9 @@ esp_err_t ulp_riscv_i2c_master_init(const ulp_riscv_i2c_cfg_t *cfg)
519525
/* Configure RTC I2C timing parameters */
520526
ESP_RETURN_ON_ERROR(i2c_set_timing(cfg), RTCI2C_TAG, "Failed to configure RTC I2C timing");
521527

528+
/* Clear any pending interrupts */
529+
WRITE_PERI_REG(RTC_I2C_INT_CLR_REG, UINT32_MAX);
530+
522531
/* Enable RTC I2C interrupts */
523532
SET_PERI_REG_MASK(RTC_I2C_INT_ENA_REG, RTC_I2C_RX_DATA_INT_ENA |
524533
RTC_I2C_TX_DATA_INT_ENA |

components/wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls-ec.c

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -26,7 +26,8 @@
2626
#include "mbedtls/error.h"
2727
#include "mbedtls/oid.h"
2828

29-
#define ECP_PRV_DER_MAX_BYTES 29 + 3 * MBEDTLS_ECP_MAX_BYTES
29+
#define ECP_PRV_DER_MAX_BYTES ( 29 + 3 * MBEDTLS_ECP_MAX_BYTES )
30+
#define ECP_PUB_DER_MAX_BYTES ( 30 + 2 * MBEDTLS_ECP_MAX_BYTES )
3031

3132
#ifdef CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT
3233
#define ACCESS_ECDH(S, var) S->MBEDTLS_PRIVATE(var)
@@ -518,6 +519,7 @@ struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *gro
518519
struct crypto_key *pkey = NULL;
519520
int ret;
520521
mbedtls_pk_context *key = (mbedtls_pk_context *)crypto_alloc_key();
522+
mbedtls_ecp_group *ecp_grp = (mbedtls_ecp_group *)group;
521523

522524
if (!key) {
523525
wpa_printf(MSG_ERROR, "%s: memory allocation failed", __func__);
@@ -538,7 +540,7 @@ struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *gro
538540
goto fail;
539541
}
540542

541-
if (mbedtls_ecp_check_pubkey((mbedtls_ecp_group *)group, point) < 0) { //typecast
543+
if (mbedtls_ecp_check_pubkey(ecp_grp, point) < 0) {
542544
// ideally should have failed in upper condition, duplicate code??
543545
wpa_printf(MSG_ERROR, "Invalid key");
544546
goto fail;
@@ -547,8 +549,9 @@ struct crypto_key * crypto_ec_set_pubkey_point(const struct crypto_ec_group *gro
547549
if( ( ret = mbedtls_pk_setup( key,
548550
mbedtls_pk_info_from_type(MBEDTLS_PK_ECKEY) ) ) != 0 )
549551
goto fail;
552+
550553
mbedtls_ecp_copy(&mbedtls_pk_ec(*key)->MBEDTLS_PRIVATE(Q), point);
551-
mbedtls_ecp_group_load(&mbedtls_pk_ec(*key)->MBEDTLS_PRIVATE(grp), MBEDTLS_ECP_DP_SECP256R1);
554+
mbedtls_ecp_group_load(&mbedtls_pk_ec(*key)->MBEDTLS_PRIVATE(grp), ecp_grp->id);
552555

553556
pkey = (struct crypto_key *)key;
554557
crypto_ec_point_deinit((struct crypto_ec_point *)point, 0);
@@ -581,19 +584,27 @@ struct crypto_ec_point *crypto_ec_get_public_key(struct crypto_key *key)
581584
int crypto_ec_get_priv_key_der(struct crypto_key *key, unsigned char **key_data, int *key_len)
582585
{
583586
mbedtls_pk_context *pkey = (mbedtls_pk_context *)key;
584-
char der_data[ECP_PRV_DER_MAX_BYTES];
587+
char *der_data = os_malloc(ECP_PRV_DER_MAX_BYTES);
585588

589+
if (!der_data) {
590+
wpa_printf(MSG_ERROR, "memory allocation failed");
591+
return -1;
592+
}
586593
*key_len = mbedtls_pk_write_key_der(pkey, (unsigned char *)der_data, ECP_PRV_DER_MAX_BYTES);
587-
if (*key_len <= 0)
594+
if (*key_len <= 0) {
595+
wpa_printf(MSG_ERROR, "Failed to write priv key");
596+
os_free(der_data);
588597
return -1;
589-
598+
}
590599
*key_data = os_malloc(*key_len);
591600

592601
if (!*key_data) {
593602
wpa_printf(MSG_ERROR, "memory allocation failed");
603+
os_free(der_data);
594604
return -1;
595605
}
596-
os_memcpy(*key_data, der_data, *key_len);
606+
os_memcpy(*key_data, der_data + ECP_PRV_DER_MAX_BYTES - *key_len, *key_len);
607+
os_free(der_data);
597608

598609
return 0;
599610
}
@@ -643,16 +654,25 @@ int crypto_ec_get_publickey_buf(struct crypto_key *key, u8 *key_buf, int len)
643654

644655
int crypto_write_pubkey_der(struct crypto_key *key, unsigned char **key_buf)
645656
{
646-
unsigned char output_buf[1600] = {0};
647-
int len = mbedtls_pk_write_pubkey_der((mbedtls_pk_context *)key, output_buf, 1600);
648-
if (len <= 0)
649-
return 0;
657+
unsigned char *buf = os_malloc(ECP_PUB_DER_MAX_BYTES);
658+
659+
if(!buf) {
660+
wpa_printf(MSG_ERROR, "memory allocation failed");
661+
return -1;
662+
}
663+
int len = mbedtls_pk_write_pubkey_der((mbedtls_pk_context *)key, buf, ECP_PUB_DER_MAX_BYTES);
664+
if (len <= 0) {
665+
os_free(buf);
666+
return -1;
667+
}
650668

651669
*key_buf = os_malloc(len);
652670
if (!*key_buf) {
653-
return 0;
671+
os_free(buf);
672+
return -1;
654673
}
655-
os_memcpy(*key_buf, output_buf + 1600 - len, len);
674+
os_memcpy(*key_buf, buf + ECP_PUB_DER_MAX_BYTES - len, len);
675+
os_free(buf);
656676

657677
return len;
658678
}
@@ -812,28 +832,21 @@ int crypto_ecdsa_get_sign(unsigned char *hash,
812832
int crypto_edcsa_sign_verify(const unsigned char *hash,
813833
const struct crypto_bignum *r, const struct crypto_bignum *s, struct crypto_key *csign, int hlen)
814834
{
815-
mbedtls_pk_context *pkey = (mbedtls_pk_context *)csign;
816-
int ret = 0;
817-
818-
mbedtls_ecdsa_context *ctx = os_malloc(sizeof(*ctx));
819-
if (!ctx) {
820-
wpa_printf(MSG_ERROR, "failed to allcate memory");
821-
return ret;
835+
/* (mbedtls_ecdsa_context *) */
836+
mbedtls_ecp_keypair *ecp_kp = mbedtls_pk_ec(*(mbedtls_pk_context *)csign);
837+
if (!ecp_kp) {
838+
return -1;
822839
}
823-
mbedtls_ecdsa_init(ctx);
824-
825-
if (mbedtls_ecdsa_from_keypair(ctx, mbedtls_pk_ec(*pkey)) < 0)
826-
return ret;
827840

828-
if((ret = mbedtls_ecdsa_verify(&ctx->MBEDTLS_PRIVATE(grp), hash, hlen,
829-
&ctx->MBEDTLS_PRIVATE(Q), (mbedtls_mpi *)r, (mbedtls_mpi *)s)) != 0){
841+
mbedtls_ecp_group *ecp_kp_grp = &ecp_kp->MBEDTLS_PRIVATE(grp);
842+
mbedtls_ecp_point *ecp_kp_q = &ecp_kp->MBEDTLS_PRIVATE(Q);
843+
int ret = mbedtls_ecdsa_verify(ecp_kp_grp, hash, hlen,
844+
ecp_kp_q, (mbedtls_mpi *)r, (mbedtls_mpi *)s);
845+
if (ret != 0) {
830846
wpa_printf(MSG_ERROR, "ecdsa verification failed");
831847
return ret;
832848
}
833849

834-
mbedtls_ecdsa_free(ctx);
835-
os_free(ctx);
836-
837850
return ret;
838851
}
839852

@@ -861,14 +874,18 @@ struct crypto_key *crypto_ec_parse_subpub_key(const unsigned char *p, size_t len
861874
{
862875
int ret;
863876
mbedtls_pk_context *pkey = (mbedtls_pk_context *)crypto_alloc_key();
864-
ret = mbedtls_pk_parse_subpubkey((unsigned char **)&p, p + len, pkey);
865877

866-
if (ret < 0) {
867-
os_free(pkey);
878+
if (!pkey) {
868879
return NULL;
869880
}
881+
ret = mbedtls_pk_parse_subpubkey((unsigned char **)&p, p + len, pkey);
882+
if (ret == 0) {
883+
return (struct crypto_key *)pkey;
884+
}
870885

871-
return (struct crypto_key *)pkey;
886+
mbedtls_pk_free(pkey);
887+
os_free(pkey);
888+
return NULL;
872889
}
873890

874891
int crypto_is_ec_key(struct crypto_key *key)

0 commit comments

Comments
 (0)