Added BLE pairing security when this is the first time the watch is paired to a phone. Depending on the capabilities of the device, it might be required to enter a pass key for bonding.
This commit is contained in:
parent
41febe5fef
commit
7a6810a56e
@ -274,7 +274,7 @@ static void getBLEDeviceMACCb(const uint8_t **dev_mac)
|
|||||||
*dev_mac = ble_service_get_device_mac_address();
|
*dev_mac = ble_service_get_device_mac_address();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getBLEDevicePairingKeyCb(const uint32_t *pairing_key)
|
static void getBLEDevicePairingKeyCb(uint32_t *pairing_key)
|
||||||
{
|
{
|
||||||
*pairing_key = ble_service_get_active_pairing_passkey();
|
*pairing_key = ble_service_get_active_pairing_passkey();
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ static void _set_magnetometer_data_to_label(SettingsScreen_t * const settingsScr
|
|||||||
static void _set_bmp280_data_to_label(SettingsScreen_t * const settingsScreen);
|
static void _set_bmp280_data_to_label(SettingsScreen_t * const settingsScreen);
|
||||||
static void _reset_switch_pointers(SettingsScreen_t * const settingsScreen);
|
static void _reset_switch_pointers(SettingsScreen_t * const settingsScreen);
|
||||||
static void _enable_time_and_date_rollers(bool enabled, SettingsScreen_t * const settingsScreen);
|
static void _enable_time_and_date_rollers(bool enabled, SettingsScreen_t * const settingsScreen);
|
||||||
|
static void _show_ble_pairing_key(SettingsScreen_t * const settingsScreen, bool show);
|
||||||
|
|
||||||
static void _settings_screen_update_labels_language(SettingsScreen_t * const settingsScreen)
|
static void _settings_screen_update_labels_language(SettingsScreen_t * const settingsScreen)
|
||||||
{
|
{
|
||||||
@ -214,6 +215,7 @@ static void activation_switch_cb(lv_event_t *e)
|
|||||||
if(e->target == settingsScreen->ble_switch)
|
if(e->target == settingsScreen->ble_switch)
|
||||||
{
|
{
|
||||||
if(settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb(&toggled, SETTING_MODE_SET);
|
if(settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb(&toggled, SETTING_MODE_SET);
|
||||||
|
_show_ble_pairing_key(settingsScreen, toggled);
|
||||||
}
|
}
|
||||||
else if(e->target == settingsScreen->wifi_switch)
|
else if(e->target == settingsScreen->wifi_switch)
|
||||||
{
|
{
|
||||||
@ -514,29 +516,39 @@ static void load_connectivity_side_screen(SettingsScreen_t *settingsScreen)
|
|||||||
|
|
||||||
settingsScreen->ble_switch = lv_switch_create(settingsScreen->side_screen);
|
settingsScreen->ble_switch = lv_switch_create(settingsScreen->side_screen);
|
||||||
lv_obj_align_to(settingsScreen->ble_switch, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
lv_obj_align_to(settingsScreen->ble_switch, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
||||||
bool toggled = false;
|
bool ble_toggled = false;
|
||||||
if(settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb(&toggled, SETTING_MODE_GET);
|
if(settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setBLEEnabledSettingsCb(&ble_toggled, SETTING_MODE_GET);
|
||||||
if(toggled) lv_obj_add_state(settingsScreen->ble_switch, LV_STATE_CHECKED);
|
if(ble_toggled) lv_obj_add_state(settingsScreen->ble_switch, LV_STATE_CHECKED);
|
||||||
lv_obj_add_event_cb(settingsScreen->ble_switch, &(activation_switch_cb), LV_EVENT_VALUE_CHANGED, settingsScreen);
|
lv_obj_add_event_cb(settingsScreen->ble_switch, &(activation_switch_cb), LV_EVENT_VALUE_CHANGED, settingsScreen);
|
||||||
|
|
||||||
label = lv_label_create(settingsScreen->side_screen);
|
label = lv_label_create(settingsScreen->side_screen);
|
||||||
lv_label_set_text_static(label, "Bluetooth");
|
lv_label_set_text_static(label, "Bluetooth");
|
||||||
lv_obj_align_to(label, settingsScreen->ble_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
lv_obj_align_to(label, settingsScreen->ble_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
||||||
|
|
||||||
label = lv_label_create(settingsScreen->side_screen);
|
settingsScreen->ble_pairing_label = lv_label_create(settingsScreen->side_screen);
|
||||||
lv_label_set_text_static(label, "Device Name :");
|
lv_label_set_text_static(settingsScreen->ble_pairing_label, "Pairing Code :");
|
||||||
lv_obj_align_to(label, settingsScreen->ble_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
lv_obj_align_to(settingsScreen->ble_pairing_label, settingsScreen->ble_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_add_flag(settingsScreen->ble_pairing_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
lv_obj_t *dev_name_label = lv_label_create(settingsScreen->side_screen);
|
settingsScreen->ble_pairing_key.label = lv_label_create(settingsScreen->side_screen);
|
||||||
|
lv_obj_set_style_text_color(settingsScreen->ble_pairing_key.label, lv_color_make(130, 130, 130), LV_PART_MAIN);
|
||||||
|
lv_obj_align_to(settingsScreen->ble_pairing_key.label, settingsScreen->ble_pairing_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_add_flag(settingsScreen->ble_pairing_key.label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
|
settingsScreen->ble_dev_name_label = lv_label_create(settingsScreen->side_screen);
|
||||||
|
lv_label_set_text_static(settingsScreen->ble_dev_name_label, "Device Name :");
|
||||||
|
lv_obj_align_to(settingsScreen->ble_dev_name_label, settingsScreen->ble_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
|
||||||
|
settingsScreen->ble_dev_name_value = lv_label_create(settingsScreen->side_screen);
|
||||||
const char * ble_dev_name = NULL;
|
const char * ble_dev_name = NULL;
|
||||||
if(settingsScreen->settingsScreenAPIInterface.getBLEDeviceNameCb) settingsScreen->settingsScreenAPIInterface.getBLEDeviceNameCb(&ble_dev_name);
|
if(settingsScreen->settingsScreenAPIInterface.getBLEDeviceNameCb) settingsScreen->settingsScreenAPIInterface.getBLEDeviceNameCb(&ble_dev_name);
|
||||||
lv_label_set_text_static(dev_name_label, ble_dev_name);
|
lv_label_set_text_static(settingsScreen->ble_dev_name_value, ble_dev_name);
|
||||||
lv_obj_set_style_text_color(dev_name_label, lv_color_make(130, 130, 130), LV_PART_MAIN);
|
lv_obj_set_style_text_color(settingsScreen->ble_dev_name_value, lv_color_make(130, 130, 130), LV_PART_MAIN);
|
||||||
lv_obj_align_to(dev_name_label, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
lv_obj_align_to(settingsScreen->ble_dev_name_value, settingsScreen->ble_dev_name_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
|
||||||
label = lv_label_create(settingsScreen->side_screen);
|
settingsScreen->ble_dev_mac_label = lv_label_create(settingsScreen->side_screen);
|
||||||
lv_label_set_text_static(label, "Device MAC :");
|
lv_label_set_text_static(settingsScreen->ble_dev_mac_label, "Device MAC :");
|
||||||
lv_obj_align_to(label, dev_name_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
lv_obj_align_to(settingsScreen->ble_dev_mac_label, settingsScreen->ble_dev_name_value, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
|
||||||
settingsScreen->ble_mac_addr.label = lv_label_create(settingsScreen->side_screen);
|
settingsScreen->ble_mac_addr.label = lv_label_create(settingsScreen->side_screen);
|
||||||
const uint8_t *ble_dev_mac = NULL;
|
const uint8_t *ble_dev_mac = NULL;
|
||||||
@ -552,18 +564,22 @@ static void load_connectivity_side_screen(SettingsScreen_t *settingsScreen)
|
|||||||
}
|
}
|
||||||
lv_label_set_text_static(settingsScreen->ble_mac_addr.label, settingsScreen->ble_mac_addr.text);
|
lv_label_set_text_static(settingsScreen->ble_mac_addr.label, settingsScreen->ble_mac_addr.text);
|
||||||
lv_obj_set_style_text_color(settingsScreen->ble_mac_addr.label, lv_color_make(130, 130, 130), LV_PART_MAIN);
|
lv_obj_set_style_text_color(settingsScreen->ble_mac_addr.label, lv_color_make(130, 130, 130), LV_PART_MAIN);
|
||||||
lv_obj_align_to(settingsScreen->ble_mac_addr.label, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
lv_obj_align_to(settingsScreen->ble_mac_addr.label, settingsScreen->ble_dev_mac_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
|
||||||
settingsScreen->wifi_switch = lv_switch_create(settingsScreen->side_screen);
|
settingsScreen->wifi_switch = lv_switch_create(settingsScreen->side_screen);
|
||||||
lv_obj_align_to(settingsScreen->wifi_switch, settingsScreen->ble_mac_addr.label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
lv_obj_align_to(settingsScreen->wifi_switch, settingsScreen->ble_mac_addr.label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
||||||
if(settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb(&toggled, SETTING_MODE_GET);
|
bool wifi_toggled = false;
|
||||||
if(toggled) lv_obj_add_state(settingsScreen->wifi_switch, LV_STATE_CHECKED);
|
if(settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb)settingsScreen->settingsScreenAPIInterface.setWiFiEnabledSettingsCb(&wifi_toggled, SETTING_MODE_GET);
|
||||||
|
if(wifi_toggled) lv_obj_add_state(settingsScreen->wifi_switch, LV_STATE_CHECKED);
|
||||||
|
|
||||||
lv_obj_add_state(settingsScreen->wifi_switch, LV_STATE_DISABLED);
|
lv_obj_add_state(settingsScreen->wifi_switch, LV_STATE_DISABLED);
|
||||||
lv_obj_add_event_cb(settingsScreen->wifi_switch, &(activation_switch_cb), LV_EVENT_VALUE_CHANGED, settingsScreen);
|
lv_obj_add_event_cb(settingsScreen->wifi_switch, &(activation_switch_cb), LV_EVENT_VALUE_CHANGED, settingsScreen);
|
||||||
|
|
||||||
label = lv_label_create(settingsScreen->side_screen);
|
settingsScreen->wifi_label = lv_label_create(settingsScreen->side_screen);
|
||||||
lv_label_set_text_static(label, "WiFi");
|
lv_label_set_text_static(settingsScreen->wifi_label, "WiFi");
|
||||||
lv_obj_align_to(label, settingsScreen->wifi_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
lv_obj_align_to(settingsScreen->wifi_label, settingsScreen->wifi_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
||||||
|
|
||||||
|
_show_ble_pairing_key(settingsScreen, ble_toggled);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_language_side_screen(SettingsScreen_t *settingsScreen)
|
static void load_language_side_screen(SettingsScreen_t *settingsScreen)
|
||||||
@ -949,3 +965,31 @@ static void update_menu_list_item_text(lv_obj_t *menu_list_item, const char *tex
|
|||||||
lv_label_set_text(label, text);
|
lv_label_set_text(label, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _show_ble_pairing_key(SettingsScreen_t * const settingsScreen, bool show)
|
||||||
|
{
|
||||||
|
lv_obj_align_to(settingsScreen->ble_pairing_label, settingsScreen->ble_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
if(show)
|
||||||
|
{
|
||||||
|
uint32_t pairing_key = 0;
|
||||||
|
if(settingsScreen->settingsScreenAPIInterface.getBLEDevicePairingKeyCb)settingsScreen->settingsScreenAPIInterface.getBLEDevicePairingKeyCb(&pairing_key);
|
||||||
|
sprintf(settingsScreen->ble_pairing_key.text, "%u", pairing_key);
|
||||||
|
|
||||||
|
lv_label_set_text_static(settingsScreen->ble_pairing_key.label, settingsScreen->ble_pairing_key.text);
|
||||||
|
lv_obj_align_to(settingsScreen->ble_dev_name_label, settingsScreen->ble_pairing_key.label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_clear_flag(settingsScreen->ble_pairing_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lv_obj_clear_flag(settingsScreen->ble_pairing_key.label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lv_obj_add_flag(settingsScreen->ble_pairing_key.label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lv_obj_add_flag(settingsScreen->ble_pairing_label, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
lv_obj_align_to(settingsScreen->ble_dev_name_label, settingsScreen->ble_switch, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_obj_align_to(settingsScreen->ble_dev_name_value, settingsScreen->ble_dev_name_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_align_to(settingsScreen->ble_dev_mac_label, settingsScreen->ble_dev_name_value, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_align_to(settingsScreen->ble_mac_addr.label, settingsScreen->ble_dev_mac_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 5);
|
||||||
|
lv_obj_align_to(settingsScreen->wifi_switch, settingsScreen->ble_mac_addr.label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
||||||
|
lv_obj_align_to(settingsScreen->wifi_label, settingsScreen->wifi_switch, LV_ALIGN_OUT_RIGHT_MID, 10, 0);
|
||||||
|
}
|
||||||
|
@ -25,7 +25,7 @@ typedef struct SettingsScreenAPIInterface
|
|||||||
void (*setLanguageSettingsCb)(uint8_t *language, SettingMode_e mode);
|
void (*setLanguageSettingsCb)(uint8_t *language, SettingMode_e mode);
|
||||||
void (*getBLEDeviceNameCb)(const char **dev_name);
|
void (*getBLEDeviceNameCb)(const char **dev_name);
|
||||||
void (*getBLEDeviceMACCb)(const uint8_t **dev_mac);
|
void (*getBLEDeviceMACCb)(const uint8_t **dev_mac);
|
||||||
void (*getBLEDevicePairingKeyCb)(const uint32_t *pairing_key);
|
void (*getBLEDevicePairingKeyCb)(uint32_t *pairing_key);
|
||||||
void (*getBatteryVoltageCb)(uint16_t *battery_voltage);
|
void (*getBatteryVoltageCb)(uint16_t *battery_voltage);
|
||||||
void (*getMagnetometerRawDataCb)(int16_t *field_x, int16_t *field_y, int16_t *field_z, float *temperature);
|
void (*getMagnetometerRawDataCb)(int16_t *field_x, int16_t *field_y, int16_t *field_z, float *temperature);
|
||||||
void (*getBMP280DataCb)(float *temperature, float *pressure);
|
void (*getBMP280DataCb)(float *temperature, float *pressure);
|
||||||
@ -57,8 +57,13 @@ typedef struct SettingsScreen
|
|||||||
lv_obj_t *month_roller;
|
lv_obj_t *month_roller;
|
||||||
lv_obj_t *year_roller;
|
lv_obj_t *year_roller;
|
||||||
lv_obj_t *wrist_tilt_switch;
|
lv_obj_t *wrist_tilt_switch;
|
||||||
lv_obj_t *ble_switch;
|
|
||||||
lv_obj_t *wifi_switch;
|
lv_obj_t *wifi_switch;
|
||||||
|
lv_obj_t *wifi_label;
|
||||||
|
lv_obj_t *ble_switch;
|
||||||
|
lv_obj_t *ble_pairing_label;
|
||||||
|
lv_obj_t *ble_dev_name_label;
|
||||||
|
lv_obj_t *ble_dev_name_value;
|
||||||
|
lv_obj_t *ble_dev_mac_label;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -707,7 +707,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MYNEWT_VAL_BLE_SM_IO_CAP
|
#ifndef MYNEWT_VAL_BLE_SM_IO_CAP
|
||||||
#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT)
|
#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_DISPLAY_ONLY)// Default (BLE_HS_IO_NO_INPUT_OUTPUT)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS
|
#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS
|
||||||
|
Loading…
Reference in New Issue
Block a user