Skip to content

Commit 2461c4c

Browse files
committed
secure temp sensor fixes
1 parent 572e1d5 commit 2461c4c

5 files changed

Lines changed: 338 additions & 149 deletions

File tree

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,74 @@
1+
# Select a security setting to explore the BLE security
2+
#
3+
# security setting 0: Just works (pairing), no MITM (Man In The Middle) protection
4+
# client and server have no input or output support
5+
#
6+
# security setting 1: Numeric comparison with MITM protection
7+
# client can query yes or no from the user, server has a display only
8+
# server displays passkey
9+
# client displays passkey and user can select Yes or No if they agree the passkey is from the server
10+
#
11+
# security setting 2:
12+
# client has a keyboard and display, server has a display only
13+
# server displays passkey
14+
# client user enters the passkey displayed by the server
15+
#
16+
# security setting 3:
17+
# client has a display only, server has a display and keyboard
18+
# Client displays passkey
19+
# server user enters the passkey displayed by the server
20+
if (NOT DEFINED SECURITY_SETTING)
21+
set(SECURITY_SETTING 1)
22+
endif()
23+
124
# Standalone example that reads from the on board temperature sensor and sends notifications via BLE
225
# Flashes slowly each second to show it's running
3-
add_executable(secure_temp_sensor
26+
add_executable(secure_temp_server
427
server.c
5-
)
6-
target_link_libraries(secure_temp_sensor
28+
)
29+
target_link_libraries(secure_temp_server
730
pico_stdlib
831
pico_btstack_ble
932
pico_btstack_cyw43
1033
pico_cyw43_arch_none
1134
hardware_adc
12-
)
13-
target_include_directories(secure_temp_sensor PRIVATE
14-
${CMAKE_CURRENT_LIST_DIR}
15-
${CMAKE_CURRENT_LIST_DIR}/.. # For our common btstack config
16-
)
17-
pico_btstack_make_gatt_header(secure_temp_sensor PRIVATE "${CMAKE_CURRENT_LIST_DIR}/temp_sensor.gatt")
18-
19-
pico_add_extra_outputs(secure_temp_sensor)
35+
)
36+
target_include_directories(secure_temp_server PRIVATE
37+
${CMAKE_CURRENT_LIST_DIR} # For our btstack config
38+
)
39+
target_compile_definitions(secure_temp_server PRIVATE
40+
# Wait up to 3s for stdio USB to initialise, to avoid losing any debug on startup
41+
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=3000
42+
SECURITY_SETTING=${SECURITY_SETTING}
43+
#WANT_HCI_DUMP=1
44+
)
45+
pico_btstack_make_gatt_header(secure_temp_server PRIVATE "${CMAKE_CURRENT_LIST_DIR}/temp_sensor.gatt")
46+
pico_add_extra_outputs(secure_temp_server)
47+
pico_enable_stdio_usb(secure_temp_server 1)
48+
pico_enable_stdio_uart(secure_temp_server 1)
2049

21-
# Standalone example that connects to secure_temp_sensor and reads the temperature
50+
# Standalone example that connects to secure_temp_server and reads the temperature
2251
# Flahes once quickly each second when it's running but not connected to another device
2352
# Flashes twice quickly each second when connected to another device and reading it's temperature
24-
add_executable(secure_temp_reader
53+
add_executable(secure_temp_client
2554
client.c
2655
)
27-
target_link_libraries(secure_temp_reader
56+
target_link_libraries(secure_temp_client
2857
pico_stdlib
2958
pico_btstack_ble
3059
pico_btstack_cyw43
3160
pico_cyw43_arch_none
3261
hardware_adc
3362
)
34-
target_include_directories(secure_temp_reader PRIVATE
35-
${CMAKE_CURRENT_LIST_DIR}
36-
${CMAKE_CURRENT_LIST_DIR}/.. # For our common btstack config
63+
target_include_directories(secure_temp_client PRIVATE
64+
${CMAKE_CURRENT_LIST_DIR} # For our btstack config
3765
)
38-
target_compile_definitions(secure_temp_reader PRIVATE
39-
RUNNING_AS_CLIENT=1
66+
target_compile_definitions(secure_temp_client PRIVATE
67+
# Wait up to 3s for stdio USB to initialise, to avoid losing any debug on startup
68+
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=3000
69+
SECURITY_SETTING=${SECURITY_SETTING}
70+
#WANT_HCI_DUMP=1
4071
)
41-
42-
pico_add_extra_outputs(secure_temp_reader)
72+
pico_add_extra_outputs(secure_temp_client)
73+
pico_enable_stdio_usb(secure_temp_client 1)
74+
pico_enable_stdio_uart(secure_temp_client 1)

bluetooth/secure_temp_sensor/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@
22

33
This example uses BLE to communicate temperature between a pair of pico Ws. This example is a variant of temp sensor, using LE secure to provide a secure connection.
44

5-
In server.c and client.c there is a variable security_setting which you can change to explore different security options:
5+
secure_temp_server is a peripheral or server that transmits its temperature to another device
6+
secure_temp_client is a client that reads a temperature from another device
67

7-
Security setting 0: Just works (pairing), no MITM protection
8-
Security setting 1: Numeric comparison
9-
Security setting 2: Peripheral displays passkey, client enters passkey
10-
Security setting 3: Client displays passkey, peripheral enters passkey
8+
In server.c and client.c there is a define SECURITY_SETTING which you can change to explore different security options:
9+
10+
security setting 0: Just works (pairing), no MITM (Man In The Middle) protection
11+
client and server have no input or output support
12+
13+
security setting 1: Numeric comparison with MITM protection
14+
client can query yes or no from the user, server has a display only
15+
server displays passkey
16+
client displays passkey and user can select Yes or No if they agree the passkey is from the server
17+
18+
security setting 2:
19+
client has a keyboard and display, server has a display only
20+
server displays passkey
21+
client user enters the passkey displayed by the server
22+
23+
security setting 3:
24+
client has a display only, server has a display and keyboard
25+
Client displays passkey
26+
server user enters the passkey displayed by the server
27+
28+
You will need to use the console with both devices to see the passkeys and answer security prompts. Both stdio over UART and USB are enabled so you can use either.

bluetooth/secure_temp_sensor/btstack_config.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,4 @@
33

44
#include "../config/btstack_config_common.h"
55

6-
// security
7-
#define ENABLE_LE_SECURE_CONNECTIONS
8-
96
#endif

0 commit comments

Comments
 (0)