File tree Expand file tree Collapse file tree 2 files changed +36
-35
lines changed Expand file tree Collapse file tree 2 files changed +36
-35
lines changed Original file line number Diff line number Diff line change 55 * SPDX-License-Identifier: Apache-2.0
66 */
77
8- #include <zephyr/kernel.h>
8+ #include <zephyr/sys/check.h>
9+
910#include <zephyr/bluetooth/bluetooth.h>
1011
1112#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL
@@ -43,3 +44,37 @@ void bt_data_parse(struct net_buf_simple *ad,
4344 net_buf_simple_pull (ad , len - 1 );
4445 }
4546}
47+
48+ size_t bt_data_get_len (const struct bt_data data [], size_t data_count )
49+ {
50+ size_t total_len = 0 ;
51+
52+ for (size_t i = 0 ; i < data_count ; i ++ ) {
53+ total_len += sizeof (data [i ].data_len ) + sizeof (data [i ].type ) + data [i ].data_len ;
54+ }
55+
56+ return total_len ;
57+ }
58+
59+ size_t bt_data_serialize (const struct bt_data * input , uint8_t * output )
60+ {
61+ CHECKIF (input == NULL ) {
62+ LOG_DBG ("input is NULL" );
63+ return 0 ;
64+ }
65+
66+ CHECKIF (output == NULL ) {
67+ LOG_DBG ("output is NULL" );
68+ return 0 ;
69+ }
70+
71+ uint8_t ad_data_len = input -> data_len ;
72+ uint8_t data_len = ad_data_len + 1 ;
73+
74+ output [0 ] = data_len ;
75+ output [1 ] = input -> type ;
76+
77+ memcpy (& output [2 ], input -> data , ad_data_len );
78+
79+ return data_len + 1 ;
80+ }
Original file line number Diff line number Diff line change @@ -75,40 +75,6 @@ static int bt_ead_generate_nonce(const uint8_t iv[BT_EAD_IV_SIZE],
7575 return 0 ;
7676}
7777
78- size_t bt_data_get_len (const struct bt_data data [], size_t data_count )
79- {
80- size_t total_len = 0 ;
81-
82- for (size_t i = 0 ; i < data_count ; i ++ ) {
83- total_len += sizeof (data [i ].data_len ) + sizeof (data [i ].type ) + data [i ].data_len ;
84- }
85-
86- return total_len ;
87- }
88-
89- size_t bt_data_serialize (const struct bt_data * input , uint8_t * output )
90- {
91- CHECKIF (input == NULL ) {
92- LOG_DBG ("input is NULL" );
93- return 0 ;
94- }
95-
96- CHECKIF (output == NULL ) {
97- LOG_DBG ("output_ad_structure is NULL" );
98- return 0 ;
99- }
100-
101- uint8_t ad_data_len = input -> data_len ;
102- uint8_t data_len = ad_data_len + 1 ;
103-
104- output [0 ] = data_len ;
105- output [1 ] = input -> type ;
106-
107- memcpy (& output [2 ], input -> data , ad_data_len );
108-
109- return data_len + 1 ;
110- }
111-
11278static int ead_encrypt (const uint8_t session_key [BT_EAD_KEY_SIZE ], const uint8_t iv [BT_EAD_IV_SIZE ],
11379 const uint8_t randomizer [BT_EAD_RANDOMIZER_SIZE ], const uint8_t * payload ,
11480 size_t payload_size , uint8_t * encrypted_payload )
You can’t perform that action at this time.
0 commit comments