Skip to content

Commit 95431ef

Browse files
Yuriy Vynnychekyurvyn
Yuriy Vynnychek
authored andcommitted
Added TLSR9 BLE controller support
1 parent c75d096 commit 95431ef

File tree

162 files changed

+11002
-2366
lines changed

Some content is hidden

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

162 files changed

+11002
-2366
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tlsr9/ble/proj_lib/lib"]
2+
path = tlsr9/ble/proj_lib/lib
3+
url = https://github.com/telink-semi/zephyr_hal_telink_b91_ble_lib.git

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Copyright (c) 2021, Telink
33
#
4-
# SPDX-License-Identifier: BSD-3-Clause
4+
# SPDX-License-Identifier: Apache-2.0
55
#
66

77
add_subdirectory_ifdef(CONFIG_HAS_TELINK_DRIVERS tlsr9)

Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2022 Telink Semiconductor
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if HAS_TELINK_DRIVERS
5+
6+
rsource "tlsr9/Kconfig"
7+
8+
endif # HAS_TELINK_DRIVERS

tlsr9/CMakeLists.txt

+45-14
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,68 @@
11
#
22
# Copyright (c) 2021, Telink
33
#
4-
# SPDX-License-Identifier: BSD-3-Clause
4+
# SPDX-License-Identifier: Apache-2.0
55
#
66

7+
zephyr_library()
8+
79
zephyr_include_directories(common)
810
zephyr_include_directories(drivers/B91/compatibility_pack)
911
zephyr_include_directories(drivers/B91/reg_include)
1012
zephyr_include_directories(drivers/B91)
1113

1214
# soc.c referance sources
13-
zephyr_sources(drivers/B91/sys.c)
14-
zephyr_sources(drivers/B91/pm.c)
15-
zephyr_sources(drivers/B91/clock.c)
16-
zephyr_sources(drivers/B91/analog.c)
15+
zephyr_library_sources_ifndef(CONFIG_BT_B91 drivers/B91/sys.c)
16+
zephyr_library_sources(drivers/B91/pm.c)
17+
zephyr_library_sources(drivers/B91/clock.c)
18+
zephyr_library_sources(drivers/B91/analog.c)
1719

1820
# Flash driver reference sources
19-
zephyr_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/flash.c)
20-
zephyr_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/plic.c)
21-
zephyr_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/stimer.c)
21+
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/flash.c)
22+
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/plic.c)
23+
zephyr_library_sources_ifdef(CONFIG_SOC_FLASH_TELINK_B91 drivers/B91/stimer.c)
2224

2325
# PWM driver reference sources
24-
zephyr_sources_ifdef(CONFIG_PWM_TELINK_B91 drivers/B91/pwm.c)
26+
zephyr_library_sources_ifdef(CONFIG_PWM_TELINK_B91 drivers/B91/pwm.c)
2527

2628
# SPI driver reference sources
27-
zephyr_sources_ifdef(CONFIG_SPI_TELINK_B91 drivers/B91/gpio.c)
29+
zephyr_library_sources_ifdef(CONFIG_SPI_TELINK_B91 drivers/B91/gpio.c)
2830

2931
# I2C driver reference sources
30-
zephyr_sources_ifdef(CONFIG_I2C_TELINK_B91 drivers/B91/i2c.c)
32+
zephyr_library_sources_ifdef(CONFIG_I2C_TELINK_B91 drivers/B91/i2c.c)
3133

3234
# RF driver reference sources
33-
zephyr_sources_ifdef(CONFIG_IEEE802154_TELINK_B91 drivers/B91/stimer.c)
34-
zephyr_sources_ifdef(CONFIG_IEEE802154_TELINK_B91 drivers/B91/rf.c)
35+
zephyr_library_sources_ifdef(CONFIG_IEEE802154_TELINK_B91 drivers/B91/stimer.c)
36+
zephyr_library_sources_ifdef(CONFIG_IEEE802154_TELINK_B91 drivers/B91/rf.c)
3537

3638
# Entropy driver reference sources
37-
zephyr_sources_ifdef(CONFIG_ENTROPY_TELINK_B91_TRNG drivers/B91/trng.c)
39+
zephyr_library_sources_ifdef(CONFIG_ENTROPY_TELINK_B91_TRNG drivers/B91/trng.c)
40+
41+
# BLE reference sources
42+
if (CONFIG_BT_B91)
43+
44+
zephyr_include_directories(
45+
ble
46+
ble/vendor/controller
47+
)
48+
49+
zephyr_library_sources(
50+
drivers/B91/pke.c
51+
drivers/B91/aes.c
52+
drivers/B91/flash.c
53+
drivers/B91/plic.c
54+
drivers/B91/stimer.c
55+
drivers/B91/ext_driver/software_pa.c
56+
ble/common/utility.c
57+
ble/vendor/controller/b91_bt.c
58+
ble/vendor/controller/b91_bt_init.c
59+
ble/vendor/controller/b91_bt_buffer.c
60+
)
61+
62+
if(${ZEPHYR_TOOLCHAIN_VARIANT} STREQUAL "zephyr")
63+
zephyr_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/ble/proj_lib/lib/liblt_9518_zephyr.a)
64+
else()
65+
zephyr_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/ble/proj_lib/lib/liblt_9518.a)
66+
endif()
67+
68+
endif() # CONFIG_BT_B91

tlsr9/Kconfig

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2022 Telink Semiconductor
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
rsource "ble/vendor/controller/Kconfig"

tlsr9/ble/algorithm/aes_ccm/aes_ccm.h

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/******************************************************************************
2+
* Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*****************************************************************************/
18+
#pragma once
19+
20+
#include "stack/ble/ble_format.h"
21+
22+
#define AES_BLOCK_SIZE 16
23+
24+
25+
#define SUCCESS 0
26+
enum {
27+
AES_SUCC = SUCCESS,
28+
AES_NO_BUF,
29+
AES_FAIL,
30+
};
31+
32+
33+
typedef struct {
34+
u32 pkt;
35+
u8 dir;
36+
u8 iv[8];
37+
} ble_cyrpt_nonce_t;
38+
39+
40+
typedef struct {
41+
u64 enc_pno;
42+
u64 dec_pno;
43+
u8 sk[16]; //session key
44+
ble_cyrpt_nonce_t nonce;
45+
u8 st;
46+
u8 enable; //1: slave enable; 2: master enable
47+
u8 mic_fail;
48+
} ble_crypt_para_t;
49+
50+
51+
struct CCM_FLAGS_TAG {
52+
union {
53+
struct {
54+
u8 L : 3;
55+
u8 M : 3;
56+
u8 aData :1;
57+
u8 reserved :1;
58+
} bf;
59+
u8 val;
60+
};
61+
};
62+
63+
typedef struct CCM_FLAGS_TAG ccm_flags_t;
64+
65+
66+
typedef struct {
67+
union {
68+
u8 A[AES_BLOCK_SIZE];
69+
u8 B[AES_BLOCK_SIZE];
70+
} bf;
71+
72+
u8 tmpResult[AES_BLOCK_SIZE];
73+
u8 newAstr[AES_BLOCK_SIZE];
74+
} aes_enc_t;
75+
76+
77+
enum{
78+
CRYPT_NONCE_TYPE_ACL = 0,
79+
CRYPT_NONCE_TYPE_CIS = 1,
80+
CRYPT_NONCE_TYPE_BIS = 2,
81+
};
82+
83+
84+
/**
85+
* @brief this function is used to encrypt the plaintext
86+
* @param[in] *key - aes key: 128 bit key for the encryption of the data, little--endian.
87+
* @param[in] *plaintext - 128 bit data block that is requested to be encrypted, little--endian.
88+
* @param[out] *result - 128 bit encrypted data block, little--endian.
89+
* @return none.
90+
* @Note Input data requires strict Word alignment
91+
*/
92+
void aes_ll_encryption(u8* key, u8* plaintext, u8 *encrypted_data);
93+
94+
95+
/**
96+
* @brief this function is used to initialize the aes_ccm initial value
97+
* @param[in] ltk - encryption key, LTK
98+
* @param[in] skdm -
99+
* @param[in] skds -
100+
* @param[in] ivm -
101+
* @param[in] ivs -
102+
* @param[in] pd - Reference structure ble_crypt_para_t
103+
* @return none
104+
*/
105+
void aes_ll_ccm_encryption_init (u8 *ltk, u8 *skdm, u8 *skds, u8 *ivm, u8 *ivs, ble_crypt_para_t *pd);
106+
107+
108+
/**
109+
* @brief this function is used to encrypt the aes_ccm value
110+
* @param[in] pkt - plaint_text
111+
* @param[in] master - ll_ccm_enc: Master role must use 1, Slave role must use 0;
112+
ll_ccm_dec: Master role must use 0, Slave role must use 1;
113+
* @param[in] pd - Reference structure ble_crypt_para_t
114+
* @return none
115+
*/
116+
//void aes_ll_ccm_encryption(u8 *pkt, int master, ble_crypt_para_t *pd);
117+
118+
119+
/**
120+
* @brief this function is used to encrypt the aes_ccm value, version2
121+
* @param[in] pd - Reference structure leCryptCtrl_t
122+
* @return none
123+
*/
124+
void aes_ll_ccm_encryption(llPhysChnPdu_t *pllPhysChnPdu, u8 role, u8 ll_type, ble_crypt_para_t *pd);
125+
126+
127+
/**
128+
* @brief this function is used to decrypt the aes_ccm value
129+
* @param[in] pkt - plaint_text
130+
* @param[in] master - ll_ccm_enc: Master role must use 1, Slave role must use 0;
131+
ll_ccm_dec: Master role must use 0, Slave role must use 1;
132+
* @param[in] pd - Reference structure ble_crypt_para_t
133+
* @return 0: decryption succeeded; 1: decryption failed
134+
*/
135+
//int aes_ll_ccm_decryption(u8 *pkt, int master, ble_crypt_para_t *pd);
136+
137+
138+
/**
139+
* @brief this function is used to decrypt the aes_ccm value, version2
140+
* @param[in] pd - Reference structure leCryptCtrl_t
141+
* @return 0: decryption succeeded; 1: decryption failed
142+
*/
143+
int aes_ll_ccm_decryption(llPhysChnPdu_t *pllPhysChnPdu, u8 role, u8 ll_type, ble_crypt_para_t *pd);
144+
145+
146+
147+
148+
149+

tlsr9/ble/algorithm/algorithm.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/******************************************************************************
2+
* Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*****************************************************************************/
18+
19+
#ifndef ALGORITHM_H_
20+
#define ALGORITHM_H_
21+
22+
#include "algorithm/aes_ccm/aes_ccm.h"
23+
#include "algorithm/crypto/crypto_alg.h"
24+
25+
26+
#include "algorithm/ecc/ecc_ll.h"
27+
#include "algorithm/ecc/hw_ecc.h"
28+
29+
#endif /* ALGORITHM_H_ */

0 commit comments

Comments
 (0)