Skip to content

Commit 539e08e

Browse files
committed
lib: stm32wba: 802.15.4 driver integration
Add 802.15.4 driver integration Signed-off-by: Vincent Tardy <vincent.tardy@st.com>
1 parent 3a4b521 commit 539e08e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+13124
-303
lines changed

lib/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
if(CONFIG_HAS_STM32LIB)
99
add_subdirectory_ifdef(CONFIG_BT_STM32_IPM stm32wb)
10-
add_subdirectory_ifdef(CONFIG_BT_STM32WBA stm32wba)
10+
if(DEFINED CONFIG_BT_STM32WBA OR DEFINED CONFIG_IEEE802154_STM32WBA)
11+
add_subdirectory(stm32wba)
12+
endif()
1113
add_subdirectory_ifdef(CONFIG_BT_STM32WB0 stm32wb0)
1214
endif()

lib/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Available libraries:
88
* stm32wb0:
99
STM32WB0 BLE controller interfacing library.
1010
* stm32wba:
11-
STM32WBA BLE controller interfacing library.
11+
STM32WBA BLE and 802.15.4 controller interfacing libraries.

lib/stm32wba/CMakeLists.txt

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,22 @@
1-
# Copyright (c) 2024 STMicroelectronics
1+
# Copyright (c) 2025 STMicroelectronics
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
5-
zephyr_compile_definitions( -DBLE )
6-
7-
zephyr_include_directories(BLE_TransparentMode/Core/Inc)
8-
zephyr_include_directories(BLE_TransparentMode/STM32_WPAN/Target)
9-
zephyr_include_directories(BLE_TransparentMode/System/Config/Debug_GPIO)
10-
zephyr_include_directories(BLE_TransparentMode/System/Config/Log)
114
zephyr_include_directories(Common/WPAN/Interfaces)
125
zephyr_include_directories(Common/WPAN/Modules)
136
zephyr_include_directories(Common/WPAN/Modules/Flash)
147
zephyr_include_directories(Common/WPAN/Modules/RTDebug)
158
zephyr_include_directories(Common/WPAN/Modules/Log)
16-
zephyr_include_directories(STM32_WPAN)
17-
zephyr_include_directories(STM32_WPAN/ble/stack/include)
18-
zephyr_include_directories(STM32_WPAN/ble/stack/include/auto)
19-
zephyr_include_directories(STM32_WPAN/link_layer/ll_cmd_lib/config/ble_full)
20-
zephyr_include_directories(STM32_WPAN/link_layer/ll_cmd_lib/inc)
21-
zephyr_include_directories(STM32_WPAN/link_layer/ll_cmd_lib/inc/_40nm_reg_files)
22-
zephyr_include_directories(STM32_WPAN/link_layer/ll_sys/inc)
9+
if (CONFIG_IEEE802154_STM32WBA)
10+
zephyr_include_directories(Common/WPAN/Modules/BasicAES)
11+
endif()
2312
zephyr_include_directories(Utilities/misc)
2413
zephyr_include_directories(Utilities/tim_serv)
25-
zephyr_include_directories(Utilities/trace/adv_trace)
14+
zephyr_include_directories(STM32_WPAN)
2615

27-
zephyr_sources(BLE_TransparentMode/STM32_WPAN/Target/bpka.c)
28-
zephyr_sources(BLE_TransparentMode/STM32_WPAN/Target/linklayer_plat.c)
29-
zephyr_sources(BLE_TransparentMode/STM32_WPAN/Target/ll_sys_if.c)
30-
zephyr_sources(BLE_TransparentMode/STM32_WPAN/Target/power_table.c)
31-
zephyr_sources(Common/WPAN/Modules/Log/log_module.c)
3216
zephyr_sources(Common/WPAN/Interfaces/hw_pka.c)
3317
zephyr_sources(Common/WPAN/Interfaces/hw_pka_p256.c)
3418
zephyr_sources(Common/WPAN/Modules/RTDebug/RTDebug.c)
35-
zephyr_sources(STM32_WPAN/link_layer/ll_sys/src/ll_sys_cs.c)
36-
zephyr_sources(STM32_WPAN/link_layer/ll_sys/src/ll_sys_dp_slp.c)
37-
zephyr_sources(STM32_WPAN/link_layer/ll_sys/src/ll_sys_intf.c)
38-
zephyr_sources(STM32_WPAN/link_layer/ll_sys/src/ll_sys_startup.c)
19+
3920

4021
if(CONFIG_FLASH)
4122
zephyr_sources(Common/WPAN/Modules/Flash/flash_manager.c)
@@ -44,6 +25,31 @@ if(CONFIG_FLASH)
4425
zephyr_sources(Common/WPAN/Modules/Flash/rf_timing_synchro.c)
4526
endif()
4627

28+
if (CONFIG_IEEE802154_STM32WBA)
29+
zephyr_sources(Common/WPAN/Modules/BasicAES/baes_ccm.c)
30+
zephyr_sources(Common/WPAN/Modules/BasicAES/baes_cmac.c)
31+
zephyr_sources(Common/WPAN/Modules/BasicAES/baes_ecb.c)
32+
endif()
33+
34+
if (CONFIG_IEEE802154_STM32WBA)
35+
add_library(stm32wba_ll_lib STATIC IMPORTED GLOBAL)
36+
if(CONFIG_OPENTHREAD)
37+
message(STATUS "WBA6_LinkLayer_Thread_lib.a lib selected")
38+
set_target_properties(
39+
stm32wba_ll_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../zephyr/blobs/stm32wba/lib/WBA6_LinkLayer_Thread_lib.a
40+
)
41+
else()
42+
message(STATUS "WBA6_LinkLayer15_4.a lib selected")
43+
set_target_properties(
44+
stm32wba_ll_lib PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../zephyr/blobs/stm32wba/lib/WBA6_LinkLayer15_4.a
45+
)
46+
endif()
47+
set(STM32WBA_LL_LIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/STM32_WPAN/link_layer/ll_cmd_lib)
48+
set_target_properties(stm32wba_ll_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${STM32WBA_LL_LIB_INCLUDE_DIR})
49+
target_link_libraries(app PUBLIC stm32wba_ll_lib)
50+
endif()
51+
52+
if (CONFIG_BT_STM32WBA)
4753
if (CONFIG_BT_EXT_ADV
4854
OR (CONFIG_BT_PER_ADV OR CONFIG_BT_PER_ADV_SYNC)
4955
OR CONFIG_BT_SCA_UPDATE
@@ -63,7 +69,6 @@ else()
6369
set(BLE_LIB_TYPE "BLE_LIB_BASIC")
6470
endif()
6571

66-
6772
set(STM32WBA_BLE_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../zephyr/blobs/stm32wba/lib)
6873
set(STM32WBA_BLE_LIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/STM32_WPAN/ble/stack)
6974
set(STM32WBA_LL_LIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/STM32_WPAN/link_layer/ll_cmd_lib)
@@ -118,3 +123,9 @@ set_target_properties(stm32wba_ll_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES $
118123

119124
target_link_libraries(app PUBLIC stm32wba_ble_lib)
120125
target_link_libraries(app PUBLIC stm32wba_ll_lib)
126+
endif()
127+
128+
add_subdirectory(STM32_WPAN)
129+
130+
add_subdirectory_ifdef(CONFIG_BT_STM32WBA ble)
131+
add_subdirectory_ifdef(CONFIG_IEEE802154_STM32WBA IEEE802154)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
******************************************************************************
3+
* @file baes.h
4+
* @author MCD Application Team
5+
* @brief This file contains the interface of the basic AES software module.
6+
******************************************************************************
7+
* @attention
8+
*
9+
* Copyright (c) 2024 STMicroelectronics.
10+
* All rights reserved.
11+
*
12+
* This software is licensed under terms that can be found in the LICENSE file
13+
* in the root directory of this software component.
14+
* If no LICENSE file comes with this software, it is provided AS-IS.
15+
*
16+
******************************************************************************
17+
*/
18+
19+
#ifndef BAES_H__
20+
#define BAES_H__
21+
22+
#include <stdint.h>
23+
24+
/* Basic AES module dedicated to BLE stack with the following features:
25+
* - AES ECB encryption
26+
* - AES CMAC computation
27+
*
28+
* Configuration: the file "app_common.h" is included in this module.
29+
* It must define:
30+
* - CFG_BAES_SW equals to 1 for software implementation
31+
* - CFG_BAES_SW equals to 0 for use of hardware accelerator
32+
*
33+
* Notes:
34+
* - only 128-bit key is supported
35+
* - re-entrance is not supported
36+
*/
37+
38+
/* General interface */
39+
40+
extern void BAES_Reset( void );
41+
42+
/* AES ECB interface */
43+
44+
extern void BAES_EcbCrypt( const uint8_t* key,
45+
const uint8_t* input,
46+
uint8_t* output,
47+
int enc );
48+
49+
/* AES CMAC interface */
50+
51+
extern void BAES_CmacSetKey( const uint8_t* key );
52+
53+
extern void BAES_CmacSetVector( const uint8_t * pIV );
54+
55+
extern void BAES_CmacCompute( const uint8_t* input,
56+
uint32_t size,
57+
uint8_t* output );
58+
59+
/* AES CCM interface */
60+
61+
extern int BAES_CcmCrypt( uint8_t mode,
62+
const uint8_t* key,
63+
uint8_t iv_length,
64+
const uint8_t* iv,
65+
uint16_t add_length,
66+
const uint8_t* add,
67+
uint16_t input_length,
68+
const uint8_t* input,
69+
uint8_t tag_length,
70+
uint8_t* tag,
71+
uint8_t* output );
72+
73+
#endif /* BAES_H__ */
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*****************************************************************************
2+
* @file baes_ccm.c
3+
*
4+
* @brief This file contains the AES CCM implementation.
5+
*****************************************************************************
6+
* @attention
7+
*
8+
* Copyright (c) 2018-2024 STMicroelectronics.
9+
* All rights reserved.
10+
*
11+
* This software is licensed under terms that can be found in the LICENSE file
12+
* in the root directory of this software component.
13+
* If no LICENSE file comes with this software, it is provided AS-IS.
14+
*
15+
*****************************************************************************
16+
*/
17+
18+
#include "baes_global.h"
19+
20+
/*****************************************************************************/
21+
22+
/* ---------------------------------------------------------------------------
23+
* Byte/word manipulation macro definitions
24+
* ---------------------------------------------------------------------------
25+
*/
26+
27+
/* Returns the least significant byte from a word */
28+
#define BYTE0(w) ((uint8_t)((w) >> 0))
29+
30+
/* Returns the second least significant byte from a word */
31+
#define BYTE1(w) ((uint8_t)((w) >> 8))
32+
33+
/* Macro to set a 16-bit word into a byte table in big endian */
34+
#define SET_U16_BE( b, i, v ) M_BEGIN uint16_t v_ = (uint16_t)(v); \
35+
uint8_t *b_ = &((uint8_t*)(b))[i]; \
36+
b_[1] = BYTE0(v_); \
37+
b_[0] = BYTE1(v_); M_END
38+
39+
int BAES_CcmCrypt( uint8_t mode,
40+
const uint8_t* key,
41+
uint8_t iv_length,
42+
const uint8_t* iv,
43+
uint16_t add_length,
44+
const uint8_t* add,
45+
uint16_t input_length,
46+
const uint8_t* input,
47+
uint8_t tag_length,
48+
uint8_t* tag,
49+
uint8_t* output )
50+
{
51+
#if CFG_BAES_SW == 0
52+
53+
/* This implementation of AES CCM only supports HW AES and it also only
54+
* supports the following range for input parameters:
55+
* - tag_length: 4..16 (multiple of 2)
56+
* - iv_length: 7..13
57+
* - add_length: 1..14
58+
*/
59+
uint32_t left_len, b0[4], bx[4];
60+
uint8_t len, *b;
61+
62+
/* Build B0 */
63+
b = (uint8_t*)b0;
64+
memset( b0, 0, 16 );
65+
b[0] = (1U << 6) | (((tag_length - 2) / 2) << 3) | (14U - iv_length);
66+
memcpy( b + 1, iv, iv_length );
67+
SET_U16_BE( b, 14, input_length );
68+
69+
/* Build B1 */
70+
b = (uint8_t*)bx;
71+
memset( bx, 0, 16 );
72+
b[1] = add_length;
73+
memcpy( b + 2, add, add_length );
74+
75+
/* Start CCM process with Init and Header phases */
76+
HW_AES_Enable( );
77+
HW_AES_InitCcm( mode, key, b0, bx );
78+
79+
/* Continue CCM process with Payload Phase */
80+
left_len = input_length;
81+
while ( left_len > 0 )
82+
{
83+
len = 16;
84+
if ( left_len < 16 )
85+
{
86+
len = (uint8_t)left_len;
87+
memset( bx, 0, 16 );
88+
89+
if ( mode )
90+
HW_AES_SetLast( len );
91+
}
92+
93+
memcpy( b, input, len );
94+
HW_AES_Crypt( bx, bx );
95+
memcpy( output, b, len );
96+
input += len;
97+
output += len;
98+
left_len -= len;
99+
}
100+
101+
/* End CCM process with Final Phase */
102+
HW_AES_EndCcm( tag_length, mode ? b : tag );
103+
HW_AES_Disable( );
104+
105+
/* Verification of the tag in case of decryption */
106+
if ( mode )
107+
{
108+
uint8_t diff = 0;
109+
for ( int i = 0; i < tag_length; i++ )
110+
diff |= tag[i] ^ b[i];
111+
112+
return (int)diff;
113+
}
114+
115+
#endif /* CFG_BAES_SW == 0 */
116+
117+
return 0;
118+
}
119+
120+
/*****************************************************************************/

0 commit comments

Comments
 (0)