1
1
#include "bt_type_code.h"
2
2
#include <furi_hal_bt_hid.h>
3
+ #include <bt/bt_service/bt_i.h>
3
4
#include <storage/storage.h>
4
5
#include "../../types/common.h"
5
6
#include "../../types/token_info.h"
@@ -11,6 +12,26 @@ static inline bool totp_type_code_worker_stop_requested() {
11
12
return furi_thread_flags_get () & TotpBtTypeCodeWorkerEventStop ;
12
13
}
13
14
15
+ #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
16
+ static void totp_type_code_worker_bt_set_app_mac (uint8_t * mac ) {
17
+ uint8_t max_i ;
18
+ size_t uid_size = furi_hal_version_uid_size ();
19
+ if (uid_size < 6 ) {
20
+ max_i = uid_size ;
21
+ } else {
22
+ max_i = 6 ;
23
+ }
24
+
25
+ const uint8_t * uid = furi_hal_version_uid ();
26
+ memcpy (mac , uid , max_i );
27
+ for (uint8_t i = max_i ; i < 6 ; i ++ ) {
28
+ mac [i ] = 0 ;
29
+ }
30
+
31
+ mac [0 ] = 0b10 ;
32
+ }
33
+ #endif
34
+
14
35
static void totp_type_code_worker_type_code (TotpBtTypeCodeWorkerContext * context ) {
15
36
uint8_t i = 0 ;
16
37
do {
@@ -30,7 +51,7 @@ static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context
30
51
}
31
52
32
53
static int32_t totp_type_code_worker_callback (void * context ) {
33
- furi_assert (context );
54
+ furi_check (context );
34
55
FuriMutex * context_mutex = furi_mutex_alloc (FuriMutexTypeNormal );
35
56
if (context_mutex == NULL ) {
36
57
return 251 ;
@@ -74,7 +95,7 @@ void totp_bt_type_code_worker_start(
74
95
char * code_buf ,
75
96
uint8_t code_buf_length ,
76
97
FuriMutex * code_buf_update_sync ) {
77
- furi_assert (context != NULL );
98
+ furi_check (context != NULL );
78
99
context -> string = code_buf ;
79
100
context -> string_length = code_buf_length ;
80
101
context -> string_sync = code_buf_update_sync ;
@@ -87,7 +108,7 @@ void totp_bt_type_code_worker_start(
87
108
}
88
109
89
110
void totp_bt_type_code_worker_stop (TotpBtTypeCodeWorkerContext * context ) {
90
- furi_assert (context != NULL );
111
+ furi_check (context != NULL );
91
112
furi_thread_flags_set (furi_thread_get_id (context -> thread ), TotpBtTypeCodeWorkerEventStop );
92
113
furi_thread_join (context -> thread );
93
114
furi_thread_free (context -> thread );
@@ -98,7 +119,7 @@ void totp_bt_type_code_worker_notify(
98
119
TotpBtTypeCodeWorkerContext * context ,
99
120
TotpBtTypeCodeWorkerEvent event ,
100
121
uint8_t flags ) {
101
- furi_assert (context != NULL );
122
+ furi_check (context != NULL );
102
123
context -> flags = flags ;
103
124
furi_thread_flags_set (furi_thread_get_id (context -> thread ), event );
104
125
}
@@ -114,19 +135,41 @@ TotpBtTypeCodeWorkerContext* totp_bt_type_code_worker_init() {
114
135
furi_hal_bt_reinit ();
115
136
furi_delay_ms (200 );
116
137
bt_keys_storage_set_storage_path (context -> bt , HID_BT_KEYS_STORAGE_PATH );
138
+
139
+ #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
140
+ totp_type_code_worker_bt_set_app_mac (& context -> bt_mac [0 ]);
141
+ memcpy (
142
+ & context -> previous_bt_name [0 ],
143
+ furi_hal_bt_get_profile_adv_name (FuriHalBtProfileHidKeyboard ),
144
+ TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN );
145
+ memcpy (
146
+ & context -> previous_bt_mac [0 ],
147
+ furi_hal_bt_get_profile_mac_addr (FuriHalBtProfileHidKeyboard ),
148
+ TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN );
149
+ char new_name [TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN ];
150
+ snprintf (new_name , sizeof (new_name ), "%s TOTP Auth" , furi_hal_version_get_name_ptr ());
151
+ furi_hal_bt_set_profile_adv_name (FuriHalBtProfileHidKeyboard , new_name );
152
+ furi_hal_bt_set_profile_mac_addr (FuriHalBtProfileHidKeyboard , context -> bt_mac );
153
+ #endif
154
+
117
155
if (!bt_set_profile (context -> bt , BtProfileHidKeyboard )) {
118
156
FURI_LOG_E (LOGGING_TAG , "Failed to switch BT to keyboard HID profile" );
119
157
}
120
158
121
159
furi_hal_bt_start_advertising ();
160
+
161
+ #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
162
+ bt_enable_peer_key_update (context -> bt );
163
+ #endif
164
+
122
165
context -> is_advertising = true;
123
166
bt_set_status_changed_callback (context -> bt , connection_status_changed_callback , context );
124
167
125
168
return context ;
126
169
}
127
170
128
171
void totp_bt_type_code_worker_free (TotpBtTypeCodeWorkerContext * context ) {
129
- furi_assert (context != NULL );
172
+ furi_check (context != NULL );
130
173
131
174
if (context -> thread != NULL ) {
132
175
totp_bt_type_code_worker_stop (context );
@@ -142,6 +185,11 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context) {
142
185
furi_delay_ms (200 );
143
186
bt_keys_storage_set_default_path (context -> bt );
144
187
188
+ #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
189
+ furi_hal_bt_set_profile_adv_name (FuriHalBtProfileHidKeyboard , context -> previous_bt_name );
190
+ furi_hal_bt_set_profile_mac_addr (FuriHalBtProfileHidKeyboard , context -> previous_bt_mac );
191
+ #endif
192
+
145
193
if (!bt_set_profile (context -> bt , BtProfileSerial )) {
146
194
FURI_LOG_E (LOGGING_TAG , "Failed to switch BT to Serial profile" );
147
195
}
0 commit comments