mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
reverting the changes to SDK
This commit is contained in:
+4
-51
@@ -5,16 +5,15 @@
|
||||
.SUFFIXES:
|
||||
.SECONDARY:
|
||||
|
||||
GTEST_DIR = ../third_party/gtest/googletest/
|
||||
GMOCK_DIR = ../third_party/gtest/googlemock/
|
||||
MBEDTLS_DIR = ../third_party/mbedtls/
|
||||
MICROECC_DIR = ../third_party/micro-ecc/
|
||||
GTEST_DIR = ../third_party/gtest/googletest/
|
||||
GMOCK_DIR = ../third_party/gtest/googlemock/
|
||||
MBEDTLS_DIR = ../third_party/mbedtls/
|
||||
|
||||
|
||||
ARCH ?= host
|
||||
OUT_DIR_NAME ?= $(ARCH)
|
||||
OUT_DIR = out/$(OUT_DIR_NAME)
|
||||
DIST_DIR = dist/$(OUT_DIR_NAME)
|
||||
MICROECC_OUT_DIR = $(OUT_DIR)/third_party/micro-ecc
|
||||
|
||||
CFLAGS := -Wall
|
||||
COMMON_INCLUDE_DIRS :=
|
||||
@@ -91,10 +90,6 @@ ifdef NEARBY_FP_ENABLE_BATTERY_NOTIFICATION
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_BATTERY_NOTIFICATION=$(NEARBY_FP_ENABLE_BATTERY_NOTIFICATION)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_BATTERY_REMAINING_TIME
|
||||
CFLAGS += -DNEARBY_BATTERY_REMAINING_TIME=$(NEARBY_BATTERY_REMAINING_TIME)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_ADDITIONAL_DATA=$(NEARBY_FP_ENABLE_ADDITIONAL_DATA)
|
||||
endif
|
||||
@@ -118,23 +113,6 @@ endif
|
||||
ifdef NEARBY_FP_PREFER_LE_TRANSPORT
|
||||
CFLAGS += -DNEARBY_FP_PREFER_LE_TRANSPORT=$(NEARBY_FP_PREFER_LE_TRANSPORT)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_ENABLE_SASS
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_SASS=$(NEARBY_FP_ENABLE_SASS)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK
|
||||
CFLAGS += -DNEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK=$(NEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT
|
||||
CFLAGS += -DNEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT=$(NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES
|
||||
CFLAGS += -DNEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=$(NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES)
|
||||
endif
|
||||
|
||||
COMMON_INCLUDE_DIRS += \
|
||||
-I. \
|
||||
-I$(ARCH_COMMON_DIR) \
|
||||
@@ -145,10 +123,6 @@ ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
COMMON_INCLUDE_DIRS += -I$(MBEDTLS_DIR)/include
|
||||
endif
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC),1)
|
||||
COMMON_INCLUDE_DIRS += -I$(MICROECC_DIR)
|
||||
endif
|
||||
|
||||
CLIENT_INCLUDES += \
|
||||
-I$(CLIENT_DIR) \
|
||||
-Iclient/target
|
||||
@@ -159,8 +133,6 @@ COMMON_C_FILES += \
|
||||
CLIENT_SRCS += \
|
||||
$(wildcard $(CLIENT_DIR)/*.c)
|
||||
|
||||
MICROECC_TARGET_SRCS := $(wildcard common/source/micro-ecc/*.c)
|
||||
|
||||
CFLAGS += $(COMMON_INCLUDE_DIRS)
|
||||
|
||||
CROSS_COMPILE ?= arm-none-eabi-
|
||||
@@ -171,8 +143,6 @@ COMMON_OBJS = $(patsubst %.c,$(OUT_DIR)/%.o,$(ALL_C_FILES))
|
||||
CLIENT_OBJS = $(patsubst %.c,$(OUT_DIR)/%.o,$(CLIENT_SRCS))
|
||||
NEARBY_LIB_OBJS = $(COMMON_OBJS) $(CLIENT_OBJS)
|
||||
|
||||
MICROECC_TARGET_OBJS := $(patsubst %.c,$(OUT_DIR)/%.o,$(MICROECC_TARGET_SRCS))
|
||||
|
||||
NEARBY_HEADERS += $(patsubst common/target/%.h,$(DIST_DIR)/%.h,$(wildcard common/target/*.h))
|
||||
NEARBY_HEADERS += $(patsubst common/target/$(ARCH_COMMON_NAME)/%.h,$(DIST_DIR)/%.h,$(wildcard common/target/$(ARCH_COMMON_NAME)/*.h))
|
||||
NEARBY_HEADERS += $(patsubst client/target/%,$(DIST_DIR)/%,$(wildcard client/target/*.h))
|
||||
@@ -227,23 +197,6 @@ $(CLIENT_OBJS) : $(OUT_DIR)/%.o : %.c
|
||||
$(COMMON_OBJS) : $(OUT_DIR)/%.o: %.c
|
||||
$(call compile_c,$(CFLAGS))
|
||||
|
||||
# nearby provider micro-ecc code
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
# micro-ecc interface files
|
||||
$(MICROECC_TARGET_OBJS) : $(OUT_DIR)/%.o: %.c
|
||||
$(call compile_c,$(TEST_INCLUDES) -I. -std=c99 -c $(CFLAGS))
|
||||
endif
|
||||
|
||||
# micro-ecc code
|
||||
# note micro-ecc does not tolerate address-sanitizer
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
$(MICROECC_OUT_DIR)/libmicro-ecc.a: $(MICROECC_DIR)/uECC.c
|
||||
@echo "Compiling libmicro-ecc.a"
|
||||
@mkdir -p $(MICROECC_OUT_DIR)
|
||||
$(CC) $(CFLAGS) -fno-sanitize=address -c -o $(MICROECC_OUT_DIR)/uECC.o $(MICROECC_DIR)/uECC.c
|
||||
$(AR) rcs $(MICROECC_OUT_DIR)/libmicro-ecc.a $(MICROECC_OUT_DIR)/uECC.o
|
||||
endif
|
||||
|
||||
ALL_OBJS += $(NEARBY_LIB_OBJS) $(CLIENT_OBJS)
|
||||
|
||||
DEPFILES = $(ALL_OBJS:.o=.d)
|
||||
|
||||
+1
-7
@@ -1,7 +1,7 @@
|
||||
# Nearby embedded SDK library
|
||||
|
||||
This repository contains Nearby SDK library for embedded systems. Nearby SDK
|
||||
implements the Fast Pair protocol along with SPOT and its future versions per
|
||||
implements the Fast Pair protocol and its future versions per
|
||||
https://developers.google.com/nearby/fast-pair/spec
|
||||
|
||||
|
||||
@@ -41,9 +41,3 @@ implementations, with the config.mk flag `NEARBY_PLATFORM_USE_MBEDTLS`.
|
||||
2. *gen_secret* located in `common/source/mbedtls/gen_secret.c` implements `nearby_platform_GenSec256r1Secret()`.
|
||||
|
||||
*gen_secret* generates a shared secret based on a given private key on platforms that don't support hardware SE. *gen_secret* module is enabled `NEARBY_PLATFORM_USE_MBEDTLS` is set and `NEARBY_PLATFORM_HAS_SE` is *not* set. When `NEARBY_PLATFORM_HAS_SE` is set, the platform needs to provide their own `nearby_platform_GenSec256r1Secret()` routine.
|
||||
|
||||
3. *micro-ecc* located in `common/source/micro-ecc/micro-ecc.c` implements `nearby_platform_GetSecp160r1PublicKey()`.
|
||||
|
||||
Nearby SDK can be configured to use the [micro ecc](https://github.com/kmackay/micro-ecc), commonly available for 8-bit,32-bit, and 64-bit processors, with the config.mk flag `NEARBY_PLATFORM_USE_MICROECC`.
|
||||
|
||||
`nearby_platform_GetSecp160r1PublicKey()` generates public key based on a given private key for SECP 160r1 curve and hash field which is required for Eddystone frame.
|
||||
@@ -33,10 +33,6 @@
|
||||
#include "nearby_platform_os.h"
|
||||
#include "nearby_platform_persistence.h"
|
||||
#include "nearby_platform_se.h"
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
#include "nearby_spot.h"
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
#include "nearby_advert.h"
|
||||
#include "nearby_trace.h"
|
||||
#include "nearby_utils.h"
|
||||
|
||||
@@ -77,6 +73,9 @@
|
||||
|
||||
#define INVALID_PEER_ADDRESS 0
|
||||
|
||||
// One byte per left, right and charging case
|
||||
#define BATTERY_LEVELS_SIZE 3
|
||||
|
||||
// Size of battery remaining time (16 bits)
|
||||
#define BATTERY_TIME_SIZE 2
|
||||
|
||||
@@ -102,9 +101,6 @@
|
||||
#define SASS_NOTIFY_MULTIPOINT_SWITCH_EVENT_TARGET_THIS_DEVICE 1
|
||||
#define SASS_NOTIFY_MULTIPOINT_SWITCH_EVENT_TARGET_ANOTHER_DEVICE 2
|
||||
|
||||
// Default sass custom data value
|
||||
#define DEFAULT_CUSTOM_DATA 0
|
||||
|
||||
enum PairingState {
|
||||
kPairingStateIdle,
|
||||
kPairingStateWaitingForPairingRequest,
|
||||
@@ -127,8 +123,9 @@ static void* address_rotation_task = NULL;
|
||||
#if NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
static uint8_t additional_data_id;
|
||||
#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
static const uint16_t kSassVersion = 0x101;
|
||||
static uint8_t sass_custom_data = 0;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
#define RETURN_IF_ERROR(X) \
|
||||
@@ -157,9 +154,6 @@ typedef struct {
|
||||
uint8_t capabilities;
|
||||
uint8_t platform_type;
|
||||
uint8_t platform_build;
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
uint8_t sass_custom_data;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
} rfcomm_input;
|
||||
|
||||
static void InitRfcommInput(uint64_t peer_address, rfcomm_input* input) {
|
||||
@@ -178,7 +172,7 @@ static void InitRfcommInput(uint64_t peer_address, rfcomm_input* input) {
|
||||
}
|
||||
|
||||
static rfcomm_input rfcomm_inputs[NEARBY_MAX_RFCOMM_CONNECTIONS];
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
static void UpdateAndNotifySass(const rfcomm_input* seeker);
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
@@ -280,24 +274,7 @@ static bool ShowPairingIndicator() {
|
||||
return advertisement_mode & NEARBY_FP_ADVERTISEMENT_PAIRING_UI_INDICATOR;
|
||||
}
|
||||
|
||||
static void SetPairingState(enum PairingState state) {
|
||||
// NEARBY_TRACE(VERBOSE, "%s pairing_state %u->%u \n", __func__,
|
||||
// pairing_state, state);
|
||||
pairing_state = state;
|
||||
}
|
||||
|
||||
static void ResetPairingState(uint64_t peer_address) {
|
||||
NEARBY_TRACE(VERBOSE,
|
||||
"%s peer_address=0x%lx "
|
||||
"peer_public_address=0x%lx gatt_peer_address=0x%lx\n",
|
||||
__func__, peer_address, peer_public_address, gatt_peer_address);
|
||||
if (peer_public_address == peer_address ||
|
||||
gatt_peer_address == peer_address) {
|
||||
SetPairingState(kPairingStateIdle);
|
||||
}
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
|
||||
static bool IsSassSeeker(const rfcomm_input* input) {
|
||||
return input->state.peer_address != INVALID_PEER_ADDRESS &&
|
||||
@@ -324,24 +301,13 @@ static uint8_t* FindInUseKey() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint8_t GetCustomData() {
|
||||
// If the audio source is not an FP Seeker, return 0.
|
||||
uint64_t peer_address = nearby_platform_GetActiveAudioSource();
|
||||
if (peer_address != INVALID_PEER_ADDRESS) {
|
||||
for (int i = 0; i < NEARBY_MAX_RFCOMM_CONNECTIONS; i++) {
|
||||
rfcomm_input* input = &rfcomm_inputs[i];
|
||||
if (input->state.peer_address == peer_address) {
|
||||
return input->sass_custom_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return DEFAULT_CUSTOM_DATA;
|
||||
}
|
||||
static uint8_t GetCustomData() { return sass_custom_data; }
|
||||
static void SetCustomData(uint8_t data) { sass_custom_data = data; }
|
||||
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
static bool IncludeSass() {
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
return advertisement_mode & NEARBY_FP_ADVERTISEMENT_SASS;
|
||||
#else
|
||||
return false;
|
||||
@@ -349,7 +315,7 @@ static bool IncludeSass() {
|
||||
}
|
||||
|
||||
static uint8_t* SelectInUseKey() {
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
return IncludeSass() ? FindInUseKey() : NULL;
|
||||
#else
|
||||
return NULL;
|
||||
@@ -376,11 +342,11 @@ static bool IncludeBatteryInfo() {
|
||||
static nearby_platform_BatteryInfo* PrepareBatteryInfo(
|
||||
nearby_platform_BatteryInfo* battery_info) {
|
||||
nearby_platform_status status;
|
||||
for (int i = 0; i < NEARBY_BATTERY_LEVELS_SIZE; i++)
|
||||
battery_info->battery_level[i] = INVALID_BATTERY_LEVEL;
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
|
||||
battery_info->is_charging = false;
|
||||
battery_info->right_bud_battery_level = battery_info->left_bud_battery_level =
|
||||
battery_info->charging_case_battery_level = INVALID_BATTERY_LEVEL;
|
||||
battery_info->remaining_time_minutes = 0;
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
status = nearby_platform_GetBatteryInfo(battery_info);
|
||||
if (status != kNearbyStatusOK) {
|
||||
NEARBY_TRACE(ERROR, "GetBatteryInfo() failed with error %d", status);
|
||||
@@ -391,7 +357,7 @@ static nearby_platform_BatteryInfo* PrepareBatteryInfo(
|
||||
|
||||
#if NEARBY_FP_MESSAGE_STREAM
|
||||
static nearby_platform_status SendBatteryInfoMessage(uint64_t peer_address) {
|
||||
uint8_t levels[NEARBY_BATTERY_LEVELS_SIZE];
|
||||
uint8_t levels[BATTERY_LEVELS_SIZE];
|
||||
nearby_message_stream_Message message = {
|
||||
.message_group = MESSAGE_GROUP_DEVICE_INFORMATION_EVENT,
|
||||
.message_code = MESSAGE_CODE_BATTERY_UPDATED,
|
||||
@@ -404,7 +370,6 @@ static nearby_platform_status SendBatteryInfoMessage(uint64_t peer_address) {
|
||||
return nearby_message_stream_Send(peer_address, &message);
|
||||
}
|
||||
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
static nearby_platform_status SendBatteryTimeMessage(uint64_t peer_address) {
|
||||
uint8_t time[BATTERY_TIME_SIZE];
|
||||
nearby_message_stream_Message message = {
|
||||
@@ -424,30 +389,9 @@ static nearby_platform_status SendBatteryTimeMessage(uint64_t peer_address) {
|
||||
}
|
||||
return nearby_message_stream_Send(peer_address, &message);
|
||||
}
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
#endif /* NEARBY_FP_MESSAGE_STREAM */
|
||||
#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */
|
||||
|
||||
#if NEARBY_FP_MESSAGE_STREAM
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
static nearby_platform_status SendCurrentEddystoneIdMessage(
|
||||
uint64_t peer_address) {
|
||||
uint8_t current_time_eid[EPHEMERAL_ID_SIZE + sizeof(uint32_t)];
|
||||
nearby_message_stream_Message message = {
|
||||
.message_group = MESSAGE_GROUP_DEVICE_INFORMATION_EVENT,
|
||||
.message_code = MESSAGE_CODE_CURRENT_EDDYSTONE_IDENTIFIER,
|
||||
.length = sizeof(current_time_eid),
|
||||
.data = current_time_eid};
|
||||
nearby_utils_CopyBigEndian(
|
||||
&message.data[0], nearby_platform_GetPersistentTime(), sizeof(uint32_t));
|
||||
if (nearby_spot_GetEid(&message.data[sizeof(uint32_t)]) == kNearbyStatusOK)
|
||||
return nearby_message_stream_Send(peer_address, &message);
|
||||
else
|
||||
return kNearbyStatusError;
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
#endif /* NEARBY_FP_MESSAGE_STREAM */
|
||||
|
||||
static void AccountKeyRejected() {
|
||||
if (++pairing_failure_count == MAX_PAIRING_FAILURE_COUNT) {
|
||||
reject_pairing_time_start_ms = nearby_platform_GetCurrentTimeMs();
|
||||
@@ -473,7 +417,7 @@ static void DiscardPendingAccountKey() {
|
||||
|
||||
static void RotateBleAddress() {
|
||||
address_rotation_timestamp = nearby_platform_GetCurrentTimeMs();
|
||||
nearby_SetFpAdvertisement(NULL, 0, kDisabled);
|
||||
nearby_platform_SetAdvertisement(NULL, 0, kDisabled);
|
||||
#ifdef NEARBY_FP_HAVE_BLE_ADDRESS_ROTATION
|
||||
uint64_t address = nearby_platform_RotateBleAddress();
|
||||
NEARBY_TRACE(INFO, "Rotated BLE address to: %s",
|
||||
@@ -491,7 +435,7 @@ static void RotateBleAddress() {
|
||||
nearby_platform_SetBleAddress(address);
|
||||
#if NEARBY_FP_MESSAGE_STREAM
|
||||
SendBleAddressUpdatedToAll();
|
||||
#endif /* NEARBY_FP_MESSAGE_STREAM */
|
||||
#endif
|
||||
#endif /* NEARBY_FP_HAVE_BLE_ADDRESS_ROTATION */
|
||||
}
|
||||
|
||||
@@ -581,7 +525,7 @@ static nearby_platform_status OnAdditionalDataWrite(uint64_t peer_address,
|
||||
status = SaveAdditionalData(request + ADDITIONAL_DATA_HEADER_SIZE,
|
||||
length - ADDITIONAL_DATA_HEADER_SIZE);
|
||||
}
|
||||
SetPairingState(kPairingStateIdle);
|
||||
pairing_state = kPairingStateIdle;
|
||||
return status;
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */
|
||||
@@ -634,9 +578,9 @@ static nearby_platform_status HandleKeyBasedPairingRequest(
|
||||
NEARBY_TRACE(INFO, "Send pairing request to %s",
|
||||
nearby_utils_MacToString(peer_public_address));
|
||||
nearby_platform_SendPairingRequest(peer_public_address);
|
||||
SetPairingState(kPairingStateWaitingForPasskey);
|
||||
pairing_state = kPairingStateWaitingForPasskey;
|
||||
} else {
|
||||
SetPairingState(kPairingStateWaitingForPairingRequest);
|
||||
pairing_state = kPairingStateWaitingForPairingRequest;
|
||||
timeout_start_ms = nearby_platform_GetCurrentTimeMs();
|
||||
}
|
||||
return kNearbyStatusOK;
|
||||
@@ -653,7 +597,7 @@ static nearby_platform_status HandleActionRequest(
|
||||
}
|
||||
#if NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
if (flags & ACTION_REQUEST_WILL_WRITE_DATA_CHARACTERISTIC_MASK) {
|
||||
SetPairingState(kPairingStateWaitingForAdditionalData);
|
||||
pairing_state = kPairingStateWaitingForAdditionalData;
|
||||
additional_data_id = request[10];
|
||||
}
|
||||
return kNearbyStatusOK;
|
||||
@@ -717,7 +661,7 @@ static nearby_platform_status OnWriteKeyBasedPairing(uint64_t peer_address,
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
memcpy(account_key_info.account_key, key, ACCOUNT_KEY_SIZE_BYTES);
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
account_key_info.peer_address = peer_address;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
} else if (length == ENCRYPTED_REQUEST_LENGTH) {
|
||||
@@ -738,7 +682,7 @@ static nearby_platform_status OnWriteKeyBasedPairing(uint64_t peer_address,
|
||||
decrypted_request + REQUEST_BT_ADDRESS_OFFSET)) {
|
||||
NEARBY_TRACE(VERBOSE, "Matched key number: %d", i);
|
||||
nearby_fp_CopyAccountKey(&account_key_info, i);
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
// The existing account key could be for a different peer, so let's
|
||||
// add it again with the current peer address
|
||||
account_key_info.peer_address = peer_address;
|
||||
@@ -856,7 +800,7 @@ static nearby_platform_status OnPasskeyWrite(uint64_t peer_address,
|
||||
raw_passkey_block[0]);
|
||||
return kNearbyStatusError;
|
||||
}
|
||||
SetPairingState(kPairingStateWaitingForPairingResult);
|
||||
pairing_state = kPairingStateWaitingForPairingResult;
|
||||
NotifyProviderPasskey(peer_address);
|
||||
seeker_passkey = nearby_utils_GetBigEndian24(raw_passkey_block + 1);
|
||||
nearby_platform_SetRemotePasskey(seeker_passkey);
|
||||
@@ -877,7 +821,7 @@ static nearby_platform_status SetNonDiscoverableAdvertisement() {
|
||||
length = nearby_fp_CreateNondiscoverableAdvertisement(
|
||||
advertisement, sizeof(advertisement), ShowPairingIndicator());
|
||||
#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
if (IncludeSass() && (nearby_fp_GetAccountKeyCount() > 0)) {
|
||||
uint8_t device_bitmap[MAX_DEVICE_BITMAP_SIZE];
|
||||
size_t device_bitmap_length = sizeof(device_bitmap);
|
||||
@@ -904,25 +848,14 @@ static nearby_platform_status SetNonDiscoverableAdvertisement() {
|
||||
length += nearby_fp_AppendTxPower(advertisement + length,
|
||||
sizeof(advertisement) - length,
|
||||
nearby_platform_GetTxLevel());
|
||||
return nearby_SetFpAdvertisement(advertisement, length, kNoLargerThan250ms);
|
||||
return nearby_platform_SetAdvertisement(advertisement, length,
|
||||
kNoLargerThan250ms);
|
||||
}
|
||||
|
||||
// Steps executed after successful pairing with a seeker and receiving the
|
||||
// account key.
|
||||
static void RunPostPairingSteps(
|
||||
uint64_t peer_address, const nearby_platform_AccountKeyInfo* account_key) {
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
if (nearby_fp_GetAccountKeyCount() == 0) {
|
||||
// This is the first account key. Lets' use it for SPOT advertisements
|
||||
nearby_platform_status status =
|
||||
nearby_spot_SetBeaconAccountKey(account_key->account_key);
|
||||
if (status != kNearbyStatusOK) {
|
||||
NEARBY_TRACE(WARNING, "Failed to save owner account key: reason %d",
|
||||
status);
|
||||
}
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
nearby_fp_AddAccountKey(account_key);
|
||||
nearby_fp_SaveAccountKeys();
|
||||
DiscardPendingAccountKey();
|
||||
@@ -943,14 +876,14 @@ static void RunPostPairingSteps(
|
||||
}
|
||||
#endif /* NEARBY_FP_RETROACTIVE_PAIRING */
|
||||
|
||||
SetPairingState(kPairingStateIdle);
|
||||
pairing_state = kPairingStateIdle;
|
||||
#if NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
SetPairingState(kPairingStateWaitingForAdditionalData);
|
||||
pairing_state = kPairingStateWaitingForAdditionalData;
|
||||
additional_data_id = PERSONALIZED_NAME_DATA_ID;
|
||||
#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */
|
||||
#endif
|
||||
if (advertisement_mode & NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE) {
|
||||
NEARBY_TRACE(INFO, "Account key added, update advertisement");
|
||||
nearby_SetFpAdvertisement(NULL, 0, kDisabled);
|
||||
nearby_platform_SetAdvertisement(NULL, 0, kDisabled);
|
||||
SetNonDiscoverableAdvertisement();
|
||||
}
|
||||
}
|
||||
@@ -1021,7 +954,7 @@ static nearby_platform_status OnAccountKeyWrite(uint64_t peer_address,
|
||||
decrypted_request[0]);
|
||||
return kNearbyStatusError;
|
||||
}
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
key_info.peer_address = peer_address;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
if (wait_until_paired) {
|
||||
@@ -1046,12 +979,6 @@ static nearby_platform_status OnGattWrite(
|
||||
return OnPasskeyWrite(peer_address, request, length);
|
||||
case kAccountKey:
|
||||
return OnAccountKeyWrite(peer_address, request, length);
|
||||
case kBeaconActions:
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
return nearby_spot_WriteBeaconAction(peer_address, request, length);
|
||||
#else
|
||||
break;
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
case kAdditionalData:
|
||||
#if NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
return OnAdditionalDataWrite(peer_address, request, length);
|
||||
@@ -1101,12 +1028,6 @@ static nearby_platform_status OnGattRead(
|
||||
switch (characteristic) {
|
||||
case kModelId:
|
||||
return nearby_fp_GattReadModelId(output, length);
|
||||
case kBeaconActions:
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
return nearby_spot_ReadBeaconAction(peer_address, output, length);
|
||||
#else
|
||||
break;
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
case kMessageStreamPsm:
|
||||
return OnMesssageStreamPsmRead(output, length);
|
||||
case kKeyBasedPairing:
|
||||
@@ -1124,9 +1045,9 @@ static void OnPairingRequest(uint64_t peer_address) {
|
||||
nearby_utils_MacToString(peer_address));
|
||||
if (pairing_state == kPairingStateWaitingForPairingRequest) {
|
||||
if (ShouldTimeout(WAIT_FOR_PAIRING_REQUEST_TIME_MS)) {
|
||||
SetPairingState(kPairingStateIdle);
|
||||
pairing_state = kPairingStateIdle;
|
||||
} else {
|
||||
SetPairingState(kPairingStateWaitingForPasskey);
|
||||
pairing_state = kPairingStateWaitingForPasskey;
|
||||
peer_public_address = peer_address;
|
||||
timeout_start_ms = nearby_platform_GetCurrentTimeMs();
|
||||
}
|
||||
@@ -1142,7 +1063,7 @@ static void OnPaired(uint64_t peer_address) {
|
||||
}
|
||||
peer_public_address = peer_address;
|
||||
if (pairing_state == kPairingStateWaitingForPairingResult) {
|
||||
SetPairingState(kPairingStateWaitingForAccountKeyWrite);
|
||||
pairing_state = kPairingStateWaitingForAccountKeyWrite;
|
||||
timeout_start_ms = nearby_platform_GetCurrentTimeMs();
|
||||
}
|
||||
#if NEARBY_FP_RETROACTIVE_PAIRING
|
||||
@@ -1157,8 +1078,6 @@ static void OnPairingFailed(uint64_t peer_address) {
|
||||
nearby_utils_MacToString(peer_address));
|
||||
DiscardAccountKey();
|
||||
DiscardPendingAccountKey();
|
||||
|
||||
ResetPairingState(peer_address);
|
||||
}
|
||||
|
||||
#if NEARBY_FP_MESSAGE_STREAM
|
||||
@@ -1287,17 +1206,15 @@ static void OnMessageStreamConnected(uint64_t peer_address) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
// Send session nonce
|
||||
message.message_code = MESSAGE_CODE_SESSION_NONCE;
|
||||
message.length = SESSION_NONCE_SIZE;
|
||||
memcpy(message.data, input->session_nonce, SESSION_NONCE_SIZE);
|
||||
message.data = input->session_nonce;
|
||||
status = nearby_message_stream_Send(peer_address, &message);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(ERROR, "Failed to send session nonce, status: %d", status);
|
||||
return;
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION
|
||||
status = SendBatteryInfoMessage(peer_address);
|
||||
@@ -1307,7 +1224,6 @@ static void OnMessageStreamConnected(uint64_t peer_address) {
|
||||
status, nearby_utils_MacToString(peer_address));
|
||||
return;
|
||||
}
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
status = SendBatteryTimeMessage(peer_address);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(ERROR,
|
||||
@@ -1315,43 +1231,8 @@ static void OnMessageStreamConnected(uint64_t peer_address) {
|
||||
status, nearby_utils_MacToString(peer_address));
|
||||
return;
|
||||
}
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */
|
||||
|
||||
memset(message.data, 0, MAX_MESSAGE_STREAM_PAYLOAD_SIZE);
|
||||
const char* fw_str = nearby_platform_GetFirmwareRevision();
|
||||
length = strlen(fw_str);
|
||||
// Limiting the string to max payload size and keeping one byte at end for
|
||||
// null character
|
||||
if (length >= MAX_MESSAGE_STREAM_PAYLOAD_SIZE)
|
||||
length = MAX_MESSAGE_STREAM_PAYLOAD_SIZE - 1;
|
||||
strncpy((char*)message.data, fw_str, length);
|
||||
buffer[length] = '\0';
|
||||
message.length = length + 1;
|
||||
message.message_group = MESSAGE_GROUP_DEVICE_INFORMATION_EVENT;
|
||||
message.message_code = MESSAGE_CODE_FIRMWARE_REVISION;
|
||||
|
||||
status = nearby_message_stream_Send(peer_address, &message);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(
|
||||
ERROR,
|
||||
"Failed to send firmware revision string, status: %d Peer address: %s",
|
||||
status, nearby_utils_MacToString(peer_address));
|
||||
return;
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
if (nearby_spot_IsProvisioned()) {
|
||||
status = SendCurrentEddystoneIdMessage(peer_address);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(ERROR,
|
||||
"Failed to send current EID, status: %d Peer address: %s",
|
||||
status, nearby_utils_MacToString(peer_address));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
if (client_callbacks != NULL && client_callbacks->on_event != NULL) {
|
||||
nearby_event_MessageStreamConnected payload = {.peer_address =
|
||||
peer_address};
|
||||
@@ -1373,7 +1254,7 @@ static void OnMessageStreamDisconnected(uint64_t peer_address) {
|
||||
nearby_utils_MacToString(peer_address));
|
||||
return;
|
||||
}
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
bool update_advert = IncludeSass() && IsSassSeeker(input);
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
input->state.peer_address = INVALID_PEER_ADDRESS;
|
||||
@@ -1389,15 +1270,11 @@ static void OnMessageStreamDisconnected(uint64_t peer_address) {
|
||||
#if NEARBY_FP_RETROACTIVE_PAIRING
|
||||
RemoveRetroactivePairingPeer(peer_address);
|
||||
#endif /*NEARBY_FP_RETROACTIVE_PAIRING */
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
if (update_advert) {
|
||||
UpdateAndNotifySass(NULL);
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
#if NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT
|
||||
ResetPairingState(peer_address);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void OnMessageStreamReceived(uint64_t peer_address,
|
||||
@@ -1439,7 +1316,7 @@ static nearby_platform_status SendResponse(
|
||||
}
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
static uint8_t GetActiveDeviceFlag(uint64_t peer_address) {
|
||||
uint64_t active_address = nearby_platform_GetActiveAudioSource();
|
||||
if (IsDeviceSass(active_address) == false && active_address != 0x0) {
|
||||
@@ -1592,53 +1469,44 @@ static void PrepareNotifySwitchingPreferenceResponse(
|
||||
message->data[1] = 0;
|
||||
}
|
||||
|
||||
// Finds the index of the account key used to generate the Message
|
||||
// Authentication Code. Returns -1 if none of the account keys matches.
|
||||
static int FindAccountKeyMatchingMac(
|
||||
const nearby_message_stream_Message* message, const rfcomm_input* input) {
|
||||
int offset = 0;
|
||||
while (true) {
|
||||
offset = nearby_fp_GetNextUniqueAccountKeyIndex(offset);
|
||||
if (offset == -1) {
|
||||
return offset;
|
||||
} else if (kNearbyStatusOK ==
|
||||
nearby_fp_VerifyMessageAuthenticationCode(
|
||||
message->data, message->length,
|
||||
nearby_fp_GetAccountKey(offset)->account_key,
|
||||
input->session_nonce)) {
|
||||
return offset;
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
// Verifies MAC and sends a NACK if verification failed.
|
||||
static nearby_platform_status VerifyMac(
|
||||
uint64_t peer_address, const nearby_message_stream_Message* message,
|
||||
rfcomm_input* input) {
|
||||
if (FindAccountKeyMatchingMac(message, input) >= 0) {
|
||||
return kNearbyStatusOK;
|
||||
nearby_platform_status status = nearby_fp_VerifyMessageAuthenticationCode(
|
||||
message->data, message->length, input->in_use_account_key,
|
||||
input->session_nonce);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(WARNING, "Invalid MAC on message %d", message->message_code);
|
||||
nearby_message_stream_SendNack(peer_address, message,
|
||||
FAIL_REASON_INVALID_MAC);
|
||||
}
|
||||
NEARBY_TRACE(WARNING, "Invalid MAC on message %d", message->message_code);
|
||||
nearby_message_stream_SendNack(peer_address, message,
|
||||
FAIL_REASON_INVALID_MAC);
|
||||
return kNearbyStatusInvalidInput;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Finds the account key which was used to encode |message| and marks it at
|
||||
// the in-use key for this session
|
||||
static nearby_platform_status IndicateInUseKey(
|
||||
const nearby_message_stream_Message* message, rfcomm_input* input) {
|
||||
int offset = FindAccountKeyMatchingMac(message, input);
|
||||
if (offset >= 0) {
|
||||
memcpy(input->in_use_account_key,
|
||||
nearby_fp_GetAccountKey(offset)->account_key,
|
||||
ACCOUNT_KEY_SIZE_BYTES);
|
||||
nearby_fp_MarkAccountKeyAsActive(offset);
|
||||
UpdateAndNotifySass(NULL);
|
||||
return kNearbyStatusOK;
|
||||
int offset = 0;
|
||||
while (true) {
|
||||
offset = nearby_fp_GetNextUniqueAccountKeyIndex(offset);
|
||||
if (offset == -1) {
|
||||
return kNearbyStatusInvalidInput;
|
||||
} else if (kNearbyStatusOK ==
|
||||
nearby_fp_VerifyMessageAuthenticationCode(
|
||||
message->data, message->length,
|
||||
nearby_fp_GetAccountKey(offset)->account_key,
|
||||
input->session_nonce)) {
|
||||
memcpy(input->in_use_account_key,
|
||||
nearby_fp_GetAccountKey(offset)->account_key,
|
||||
ACCOUNT_KEY_SIZE_BYTES);
|
||||
nearby_fp_MarkAccountKeyAsActive(offset);
|
||||
UpdateAndNotifySass(NULL);
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
offset++;
|
||||
}
|
||||
return kNearbyStatusInvalidInput;
|
||||
}
|
||||
|
||||
// Selects a next, preferred audio source. The request to change the audio
|
||||
@@ -1739,8 +1607,8 @@ static nearby_platform_status HandleSassMessage(
|
||||
RETURN_IF_ERROR(VerifyMac(peer_address, message, input));
|
||||
uint8_t data = message->data[0];
|
||||
NEARBY_TRACE(INFO, "Send custom data: 0x%x", data);
|
||||
if (data != input->sass_custom_data) {
|
||||
input->sass_custom_data = data;
|
||||
if (GetCustomData() != data) {
|
||||
SetCustomData(data);
|
||||
UpdateAndNotifySass(input);
|
||||
}
|
||||
return SendResponse(peer_address, message, kNearbyStatusOK);
|
||||
@@ -1768,22 +1636,6 @@ static void PrepareActiveComponentResponse(
|
||||
nearby_platform_GetEarbudRightStatus();
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
static void PrepareSpotCapabilityResponse(
|
||||
nearby_message_stream_Message* message) {
|
||||
NEARBY_ASSERT(message->length >= (BT_ADDRESS_LENGTH + sizeof(uint8_t)));
|
||||
message->message_code = MESSAGE_CODE_EDDYSTONE_TRACKING;
|
||||
// Addtional length is 1 byte for provisiong state + BT address length
|
||||
message->length = (BT_ADDRESS_LENGTH + sizeof(uint8_t));
|
||||
message->data[0] = nearby_spot_IsProvisioned()
|
||||
? MESSAGE_CODE_EDDYSTONE_PROVISIONED
|
||||
: MESSAGE_CODE_EDDYSTONE_UNPROVISIONED;
|
||||
nearby_utils_CopyBigEndian(&message->data[sizeof(uint8_t)],
|
||||
nearby_platform_GetBleAddress(),
|
||||
BT_ADDRESS_LENGTH);
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
static nearby_platform_status HandleGeneralMessage(
|
||||
uint64_t peer_address, nearby_message_stream_Message* message) {
|
||||
rfcomm_input* input = GetRfcommInput(peer_address);
|
||||
@@ -1835,23 +1687,7 @@ static nearby_platform_status HandleGeneralMessage(
|
||||
if (message->length > 1) timeout = message->data[1];
|
||||
NEARBY_TRACE(INFO, "Set ring device: 0x%x %d", command, timeout);
|
||||
return SendResponse(peer_address, message,
|
||||
nearby_platform_Ring(command, (timeout * 10),
|
||||
kRingingVolumeDefault));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MESSAGE_GROUP_DEVICE_CAPABILITY_SYNC_EVENT: {
|
||||
reply.message_group = MESSAGE_GROUP_DEVICE_CAPABILITY_SYNC_EVENT;
|
||||
switch (message->message_code) {
|
||||
case MESSAGE_CODE_REQUEST_CAPABILITY_UPDATE: {
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
NEARBY_TRACE(INFO,
|
||||
"message stream received "
|
||||
"MESSAGE_CODE_REQUEST_CAPABILITY_UPDATE");
|
||||
PrepareSpotCapabilityResponse(&reply);
|
||||
return nearby_message_stream_Send(peer_address, &reply);
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
nearby_platform_Ring(command, timeout * 10));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1871,7 +1707,7 @@ static void OnMessageReceived(uint64_t peer_address,
|
||||
return;
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
if (message->message_group == MESSAGE_GROUP_SASS) {
|
||||
nearby_platform_status status = HandleSassMessage(peer_address, message);
|
||||
if (kNearbyStatusOK != status) {
|
||||
@@ -1930,7 +1766,7 @@ static void OnBatteryChanged(void) {
|
||||
|
||||
if (IncludeBatteryInfo() &&
|
||||
(advertisement_mode & NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE)) {
|
||||
status = nearby_SetFpAdvertisement(NULL, 0, kDisabled);
|
||||
status = nearby_platform_SetAdvertisement(NULL, 0, kDisabled);
|
||||
if (status != kNearbyStatusOK) {
|
||||
NEARBY_TRACE(ERROR, "Failed to update battery change, status: %d",
|
||||
status);
|
||||
@@ -1957,7 +1793,6 @@ static void OnBatteryChanged(void) {
|
||||
status,
|
||||
nearby_utils_MacToString(input->state.peer_address));
|
||||
}
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
status = SendBatteryTimeMessage(input->state.peer_address);
|
||||
if (status != kNearbyStatusOK) {
|
||||
NEARBY_TRACE(ERROR,
|
||||
@@ -1966,7 +1801,6 @@ static void OnBatteryChanged(void) {
|
||||
status,
|
||||
nearby_utils_MacToString(input->state.peer_address));
|
||||
}
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
}
|
||||
}
|
||||
#endif /* NEARBY_FP_MESSAGE_STREAM */
|
||||
@@ -1997,7 +1831,7 @@ static nearby_platform_BatteryInterface kBatteryInterface = {
|
||||
|
||||
static nearby_platform_status EnterDisabledMode() {
|
||||
nearby_platform_SetDefaultCapabilities();
|
||||
return nearby_SetFpAdvertisement(NULL, 0, kDisabled);
|
||||
return nearby_platform_SetAdvertisement(NULL, 0, kDisabled);
|
||||
}
|
||||
|
||||
static nearby_platform_status EnterDiscoverableMode() {
|
||||
@@ -2014,7 +1848,8 @@ static nearby_platform_status EnterDiscoverableMode() {
|
||||
length += nearby_fp_AppendTxPower(advertisement + length,
|
||||
sizeof(advertisement) - length,
|
||||
nearby_platform_GetTxLevel());
|
||||
return nearby_SetFpAdvertisement(advertisement, length, kNoLargerThan100ms);
|
||||
return nearby_platform_SetAdvertisement(advertisement, length,
|
||||
kNoLargerThan100ms);
|
||||
}
|
||||
|
||||
static nearby_platform_status EnterNonDiscoverableMode() {
|
||||
@@ -2040,13 +1875,13 @@ static bool ShouldRotateBleAddress(int mode) {
|
||||
|
||||
static uint32_t GetRotationDelayMs() {
|
||||
uint32_t delay_ms = ADDRESS_ROTATION_PERIOD_MS;
|
||||
// Rotation should happen every 1024 seconds on average.
|
||||
// The suggested approach to randomize the rotation time,
|
||||
// is to set it to the next anticipated rotation time(if not randomization was
|
||||
// applied) plus a positive randomized time factor.It is recommended that the
|
||||
// time factor will be in the range of 1 - 204 seconds.
|
||||
|
||||
delay_ms += ((1 + (nearby_platform_Rand() % 204)) * 1000);
|
||||
// Rotation should happen every 1024 seconds on average. It is required that
|
||||
// the precise point at which the beacon starts advertising the new
|
||||
// identifier is randomized within the window. This logic should give us
|
||||
// +/-200 seconds variability.
|
||||
for (int i = 0; i < 5; i++) {
|
||||
delay_ms += (50 << i) * (int8_t)nearby_platform_Rand();
|
||||
}
|
||||
return delay_ms;
|
||||
}
|
||||
|
||||
@@ -2067,21 +1902,7 @@ static void ScheduleAddressRotation() {
|
||||
}
|
||||
|
||||
static nearby_platform_status UpdateAdvertisements() {
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
nearby_platform_status status = nearby_spot_SetAdvertisement(
|
||||
advertisement_mode & NEARBY_FP_ADVERTISEMENT_SPOT);
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(WARNING, "SPOT adertisement error: %d", status);
|
||||
if (!(advertisement_mode & ~NEARBY_FP_ADVERTISEMENT_SPOT)) {
|
||||
// Fail if the client asked for SPOT advertisement only
|
||||
return status;
|
||||
}
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
if ((advertisement_mode & (NEARBY_FP_ADVERTISEMENT_DISCOVERABLE |
|
||||
NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE)) ==
|
||||
NEARBY_FP_ADVERTISEMENT_NONE) {
|
||||
if (advertisement_mode == NEARBY_FP_ADVERTISEMENT_NONE) {
|
||||
return EnterDisabledMode();
|
||||
}
|
||||
if (advertisement_mode & NEARBY_FP_ADVERTISEMENT_DISCOVERABLE) {
|
||||
@@ -2093,49 +1914,12 @@ static nearby_platform_status UpdateAdvertisements() {
|
||||
return kNearbyStatusUnsupported;
|
||||
}
|
||||
|
||||
static void MaybeRotateSpotAddress() {
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
#if NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES
|
||||
// If UnwantedTracking protection is On, rotate SPOT address, if 24 hrs
|
||||
// have passed since last rotation,
|
||||
if (nearby_spot_GetUnwantedTrackingProtectionModeState()) {
|
||||
unsigned int cur_ms = nearby_platform_GetCurrentTimeMs();
|
||||
if ((cur_ms - nearby_spot_GetAddressRotationTimestamp()) >=
|
||||
ADDRESS_ROTATION_PERIOD_UNWANTED_TRACKING_PROTECTION_MS) {
|
||||
nearby_spot_GenerateRandomizedAddress();
|
||||
}
|
||||
}
|
||||
#endif /* NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES */
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
}
|
||||
|
||||
static bool IsAddressRotationBlocked() {
|
||||
// If NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=1, return false, as the BLE address
|
||||
// rotation should not be blocked
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
#if NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES == 0
|
||||
/* Once Unwanted Tracking Protection mode was activated, the beacon should
|
||||
reduce MAC address (RPA) rotation frequency to once per 24h. The advertised
|
||||
Ephemeral ID should keep rotating as usual.*/
|
||||
if (nearby_spot_GetUnwantedTrackingProtectionModeState() &&
|
||||
((nearby_platform_GetCurrentTimeMs() - address_rotation_timestamp) <
|
||||
ADDRESS_ROTATION_PERIOD_UNWANTED_TRACKING_PROTECTION_MS)) {
|
||||
return true;
|
||||
}
|
||||
#endif /* NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES */
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
return false;
|
||||
}
|
||||
|
||||
static void MaybeRotateBleAddress() {
|
||||
ScheduleAddressRotation();
|
||||
if (IsInPairingMode()) {
|
||||
return;
|
||||
}
|
||||
if (!IsAddressRotationBlocked()) RotateBleAddress();
|
||||
|
||||
MaybeRotateSpotAddress();
|
||||
|
||||
RotateBleAddress();
|
||||
UpdateAdvertisements();
|
||||
}
|
||||
|
||||
@@ -2143,11 +1927,7 @@ static bool NeedsPeriodicAddressRotation() {
|
||||
// FP spec says we should rotate BLE adress every ~15 minutes when
|
||||
// advertising
|
||||
return (advertisement_mode & (NEARBY_FP_ADVERTISEMENT_DISCOVERABLE |
|
||||
NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
| NEARBY_FP_ADVERTISEMENT_SPOT
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
)) != 0;
|
||||
NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE)) != 0;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_fp_client_SetAdvertisement(int mode) {
|
||||
@@ -2158,7 +1938,6 @@ nearby_platform_status nearby_fp_client_SetAdvertisement(int mode) {
|
||||
CancelAddressRotationTimer();
|
||||
RotateBleAddress();
|
||||
}
|
||||
MaybeRotateSpotAddress();
|
||||
advertisement_mode = mode;
|
||||
if (NeedsPeriodicAddressRotation() && address_rotation_task == NULL) {
|
||||
ScheduleAddressRotation();
|
||||
@@ -2187,26 +1966,12 @@ nearby_platform_status nearby_fp_client_GetSeekerInfo(
|
||||
}
|
||||
#endif /* NEARBY_FP_MESSAGE_STREAM */
|
||||
|
||||
static void OnRingStateChange() {
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
NEARBY_TRACE(VERBOSE, "OnRingStateChange");
|
||||
nearby_platform_status status = nearby_spot_OnRingStateChange();
|
||||
if (kNearbyStatusOK != status) {
|
||||
NEARBY_TRACE(WARNING, "OnRingStateChange failed with %d", status);
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
}
|
||||
|
||||
static const nearby_platform_OsInterface kOsInterface = {
|
||||
.on_ring_state_change = OnRingStateChange,
|
||||
};
|
||||
|
||||
nearby_platform_status nearby_fp_client_Init(
|
||||
const nearby_fp_client_Callbacks* callbacks) {
|
||||
nearby_platform_status status;
|
||||
|
||||
client_callbacks = callbacks;
|
||||
SetPairingState(kPairingStateIdle);
|
||||
pairing_state = kPairingStateIdle;
|
||||
pairing_failure_count = 0;
|
||||
#if NEARBY_FP_MESSAGE_STREAM
|
||||
memset(rfcomm_inputs, 0, sizeof(rfcomm_inputs));
|
||||
@@ -2216,7 +1981,7 @@ nearby_platform_status nearby_fp_client_Init(
|
||||
peer_public_address = 0;
|
||||
DiscardPendingAccountKey();
|
||||
|
||||
status = nearby_platform_OsInit(&kOsInterface);
|
||||
status = nearby_platform_OsInit();
|
||||
if (status != kNearbyStatusOK) return status;
|
||||
|
||||
status = nearby_platform_SecureElementInit();
|
||||
@@ -2239,19 +2004,13 @@ nearby_platform_status nearby_fp_client_Init(
|
||||
status = nearby_fp_LoadAccountKeys();
|
||||
if (status != kNearbyStatusOK) return status;
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
SetCustomData(0);
|
||||
status = nearby_platform_AudioInit(&kAudioInterface);
|
||||
if (status != kNearbyStatusOK) return status;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
RotateBleAddress();
|
||||
|
||||
// SPOT init needs to be after RotateBleAddress, in order for SPOT address
|
||||
// to be the same as the Ble address in the initial state
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
status = nearby_spot_Init();
|
||||
if (status != kNearbyStatusOK) return status;
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -60,24 +60,12 @@ typedef struct {
|
||||
// NEARBY_FP_ADVERTISEMENT_INCLUDE_BATTERY_INFO
|
||||
#define NEARBY_FP_ADVERTISEMENT_BATTERY_UI_INDICATOR 0x10
|
||||
#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
// Include SASS advertisement. This flag can be
|
||||
// combined with NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE
|
||||
#define NEARBY_FP_ADVERTISEMENT_SASS 0x20
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Include Eddystone-E2EE-EID (SPOT) advertisement, which helps the user locate
|
||||
// their misplaced device. This flag can be combined with
|
||||
// NEARBY_FP_ADVERTISEMENT_DISCOVERABLE,
|
||||
// NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE, or it can be used alone (wuthout FP
|
||||
// adertisement). It is recommended to enable SPOT at all times, even when
|
||||
// device is turned off. A notable exception is when buds are placed in the
|
||||
// charging case - the buds can have the SPOT off and only the charing case can
|
||||
// advertise its location.
|
||||
#define NEARBY_FP_ADVERTISEMENT_SPOT 0x80
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Sets Fast Pair advertisement type
|
||||
nearby_platform_status nearby_fp_client_SetAdvertisement(int mode);
|
||||
|
||||
|
||||
@@ -126,7 +126,6 @@ uint64_t nearby_platform_GetActiveAudioSource() { return active_peer_address; }
|
||||
|
||||
void nearby_test_fakes_SetActiveAudioSource(uint64_t peer_address) {
|
||||
active_peer_address = peer_address;
|
||||
callbacks->on_state_change();
|
||||
}
|
||||
|
||||
// Initializes Audio module
|
||||
|
||||
@@ -16,25 +16,12 @@
|
||||
#include "nearby.h"
|
||||
#include "nearby_platform_battery.h"
|
||||
|
||||
#ifdef NEARBY_SPOT_BATTERY_LEVEL_INDICATION
|
||||
#include "nearby_spot.h"
|
||||
#endif /* NEARBY_SPOT_BATTERY_LEVEL_INDICATION */
|
||||
|
||||
constexpr nearby_platform_BatteryInfo kDefaultBatteryInfo = {
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE == 1
|
||||
{NEARBY_PLATFORM_SET_BATTERY_LEVEL(85, true)}
|
||||
#elif NEARBY_BATTERY_LEVELS_SIZE == 2
|
||||
{NEARBY_PLATFORM_SET_BATTERY_LEVEL(85, true), \
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(80, true)}
|
||||
#elif NEARBY_BATTERY_LEVELS_SIZE == 3
|
||||
{NEARBY_PLATFORM_SET_BATTERY_LEVEL(85, true), \
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(80, true), \
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(90, true)}
|
||||
#endif /* NEARBY_BATTERY_LEVELS_SIZE */
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
,100
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
};
|
||||
.is_charging = true,
|
||||
.right_bud_battery_level = 80,
|
||||
.left_bud_battery_level = 85,
|
||||
.charging_case_battery_level = 90,
|
||||
.remaining_time_minutes = 100};
|
||||
static nearby_platform_BatteryInfo test_battery_info = kDefaultBatteryInfo;
|
||||
static nearby_platform_status get_battery_info_result = kNearbyStatusOK;
|
||||
|
||||
@@ -46,58 +33,24 @@ nearby_platform_status nearby_platform_GetBatteryInfo(
|
||||
}
|
||||
|
||||
void nearby_test_fakes_SetIsCharging(bool charging) {
|
||||
uint8_t level = 0;
|
||||
uint8_t charging_bit = NEARBY_PLATFORM_BATTERY_INFO_NOT_CHARGING;
|
||||
// If charging is true set the charging bit to 1
|
||||
if (charging) {
|
||||
charging_bit = NEARBY_PLATFORM_BATTERY_INFO_CHARGING;
|
||||
}
|
||||
|
||||
level = NEARBY_PLATFORM_GET_BATTERY_LEVEL(test_battery_info.battery_level[kNearbyLeftBudBatteryLevel]);
|
||||
test_battery_info.battery_level[kNearbyLeftBudBatteryLevel] = charging_bit | level;
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 2
|
||||
level = NEARBY_PLATFORM_GET_BATTERY_LEVEL(test_battery_info.battery_level[kNearbyRightBudBatteryLevel]);
|
||||
test_battery_info.battery_level[kNearbyRightBudBatteryLevel] = charging_bit | level;
|
||||
#endif
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 3
|
||||
level = NEARBY_PLATFORM_GET_BATTERY_LEVEL(test_battery_info.battery_level[kNearbyChargingCaseBatteryLevel]);
|
||||
test_battery_info.battery_level[kNearbyChargingCaseBatteryLevel] = charging_bit | level;
|
||||
#endif
|
||||
test_battery_info.is_charging = charging;
|
||||
}
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 2
|
||||
void nearby_test_fakes_SetRightBudBatteryLevel(unsigned battery_level, bool charging) {
|
||||
test_battery_info.battery_level[kNearbyRightBudBatteryLevel] =
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(battery_level, charging);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nearby_test_fakes_SetLeftBudBatteryLevel(unsigned battery_level, bool charging) {
|
||||
test_battery_info.battery_level[kNearbyLeftBudBatteryLevel] =
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(battery_level, charging);
|
||||
void nearby_test_fakes_SetRightBudBatteryLevel(unsigned battery_level) {
|
||||
test_battery_info.right_bud_battery_level = battery_level;
|
||||
}
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 3
|
||||
void nearby_test_fakes_SetChargingCaseBatteryLevel(unsigned battery_level, bool charging) {
|
||||
test_battery_info.battery_level[kNearbyChargingCaseBatteryLevel] =
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(battery_level, charging);
|
||||
void nearby_test_fakes_SetLeftBudBatteryLevel(unsigned battery_level) {
|
||||
test_battery_info.left_bud_battery_level = battery_level;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NEARBY_SPOT_BATTERY_LEVEL_INDICATION
|
||||
void nearby_test_fakes_SetMainBatteryLevel(unsigned battery_level) {
|
||||
test_battery_info.battery_level[0] =
|
||||
NEARBY_PLATFORM_SET_BATTERY_LEVEL(battery_level, false);
|
||||
void nearby_test_fakes_SetChargingCaseBatteryLevel(unsigned battery_level) {
|
||||
test_battery_info.charging_case_battery_level = battery_level;
|
||||
}
|
||||
#endif /* NEARBY_SPOT_BATTERY_LEVEL_INDICATION */
|
||||
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
void nearby_test_fakes_BatteryTime(uint16_t battery_time) {
|
||||
test_battery_info.remaining_time_minutes = battery_time;
|
||||
}
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
|
||||
void nearby_test_fakes_SetGetBatteryInfoResult(nearby_platform_status status) {
|
||||
get_battery_info_result = status;
|
||||
|
||||
@@ -25,13 +25,11 @@
|
||||
|
||||
constexpr uint64_t kDefaultBleAddress = 0xbabababa;
|
||||
static uint64_t ble_address = kDefaultBleAddress;
|
||||
static uint64_t spot_address = kDefaultBleAddress;
|
||||
static uint64_t peer_address = 0x345678ab;
|
||||
static const nearby_platform_BleInterface* ble_interface;
|
||||
static std::map<nearby_fp_Characteristic, std::vector<uint8_t>> notifications;
|
||||
static std::vector<uint8_t> advertisement;
|
||||
static nearby_fp_AvertisementInterval interval;
|
||||
static std::vector<uint8_t> spot_advertisement;
|
||||
constexpr int32_t kDefaultPsm = -1;
|
||||
static int32_t psm = kDefaultPsm;
|
||||
|
||||
@@ -75,14 +73,6 @@ nearby_platform_status nearby_platform_GattNotify(
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_GattNotifyAll(
|
||||
nearby_fp_Characteristic characteristic, const uint8_t* message,
|
||||
size_t length) {
|
||||
notifications.emplace(characteristic,
|
||||
std::vector<uint8_t>(message, message + length));
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_SetAdvertisement(
|
||||
const uint8_t* payload, size_t length,
|
||||
nearby_fp_AvertisementInterval interval) {
|
||||
@@ -95,17 +85,6 @@ nearby_platform_status nearby_platform_SetAdvertisement(
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_SetSpotAdvertisement(uint64_t address,
|
||||
const uint8_t* payload, size_t length) {
|
||||
if (payload == NULL || length == 0) {
|
||||
spot_advertisement.clear();
|
||||
} else {
|
||||
spot_advertisement.assign(payload, payload + length);
|
||||
}
|
||||
spot_address = address;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
int32_t nearby_platform_GetMessageStreamPsm() { return psm; }
|
||||
|
||||
// Initializes BLE
|
||||
@@ -114,11 +93,9 @@ nearby_platform_status nearby_platform_BleInit(
|
||||
ble_interface = callbacks;
|
||||
notifications.clear();
|
||||
advertisement.clear();
|
||||
spot_advertisement.clear();
|
||||
interval = kDisabled;
|
||||
ble_address = kDefaultBleAddress;
|
||||
psm = kDefaultPsm;
|
||||
spot_address = kDefaultBleAddress;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
@@ -128,31 +105,6 @@ std::vector<uint8_t>& nearby_test_fakes_GetAdvertisement() {
|
||||
return advertisement;
|
||||
}
|
||||
|
||||
std::vector<uint8_t>& nearby_test_fakes_GetSpotAdvertisement() {
|
||||
#ifdef NEARBY_FP_HAVE_MULTIPLE_ADVERTISEMENTS
|
||||
return spot_advertisement;
|
||||
#else
|
||||
return nearby_test_fakes_GetAdvertisement();
|
||||
#endif /* NEARBY_FP_HAVE_MULTIPLE_ADVERTISEMENTS */
|
||||
}
|
||||
|
||||
uint64_t nearby_test_fakes_GetSpotAddress() {
|
||||
return spot_address;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattRead(
|
||||
nearby_fp_Characteristic characteristic, uint8_t* output, size_t* length) {
|
||||
return ble_interface->on_gatt_read(peer_address, characteristic, output,
|
||||
length);
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattWrite(
|
||||
nearby_fp_Characteristic characteristic, const uint8_t* request,
|
||||
size_t length) {
|
||||
return ble_interface->on_gatt_write(peer_address, characteristic, request,
|
||||
length);
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattReadModelId(uint8_t* output,
|
||||
size_t* length) {
|
||||
return ble_interface->on_gatt_read(peer_address, kModelId, output, length);
|
||||
|
||||
@@ -21,22 +21,12 @@
|
||||
|
||||
#include "nearby.h"
|
||||
#include "nearby_platform_ble.h"
|
||||
#include "nearby_platform_os.h"
|
||||
#include "nearby_platform_battery.h"
|
||||
|
||||
|
||||
void nearby_test_fakes_SetRandomNumber(unsigned int value);
|
||||
void nearby_test_fakes_SetRandomNumberSequence(std::vector<uint8_t>& value);
|
||||
|
||||
std::vector<uint8_t> nearby_test_fakes_GetRawAccountKeys();
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattRead(
|
||||
nearby_fp_Characteristic characteristic, uint8_t* output, size_t* length);
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattWrite(
|
||||
nearby_fp_Characteristic characteristic, const uint8_t* request,
|
||||
size_t length);
|
||||
|
||||
nearby_platform_status nearby_test_fakes_GattReadModelId(uint8_t* output,
|
||||
size_t* length);
|
||||
|
||||
@@ -62,8 +52,6 @@ nearby_platform_status nearby_test_fakes_Aes128Encrypt(
|
||||
const uint8_t key[AES_MESSAGE_SIZE_BYTES]);
|
||||
|
||||
std::vector<uint8_t>& nearby_test_fakes_GetAdvertisement();
|
||||
std::vector<uint8_t>& nearby_test_fakes_GetSpotAdvertisement();
|
||||
uint64_t nearby_test_fakes_GetSpotAddress();
|
||||
|
||||
std::map<nearby_fp_Characteristic, std::vector<uint8_t>>&
|
||||
nearby_test_fakes_GetGattNotifications();
|
||||
@@ -110,7 +98,7 @@ class AccountKeyList {
|
||||
|
||||
for (size_t i = 0; i < list->num_keys; i++) {
|
||||
uint64_t address = 0;
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
address = list->key[i].peer_address;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
key_pairs_.emplace_back(
|
||||
@@ -132,7 +120,7 @@ class AccountKeyList {
|
||||
RawAccountKeyList account_keys;
|
||||
account_keys.num_keys = size();
|
||||
for (size_t i = 0; i < size(); i++) {
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
account_keys.key[i].peer_address = key_pairs_[i].address_;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
for (size_t j = 0; j < key_pairs_[i].account_key_.size(); j++) {
|
||||
@@ -147,9 +135,6 @@ class AccountKeyList {
|
||||
std::vector<AccountKeyPair> key_pairs_;
|
||||
};
|
||||
|
||||
void nearby_test_fakes_SetRingingInfo(const nearby_platform_RingingInfo* info);
|
||||
void nearby_test_fakes_NotifyRingStateChanged();
|
||||
|
||||
void nearby_test_fakes_SetAccountKeys(const uint8_t* input, size_t length);
|
||||
void nearby_test_fakes_SetAccountKeys(
|
||||
std::vector<AccountKeyPair>& account_key_pairs);
|
||||
@@ -159,23 +144,13 @@ AccountKeyList nearby_test_fakes_GetAccountKeys();
|
||||
|
||||
void nearby_test_fakes_SetIsCharging(bool charging);
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 2
|
||||
void nearby_test_fakes_SetRightBudBatteryLevel(unsigned battery_level, bool charging);
|
||||
#endif
|
||||
void nearby_test_fakes_SetRightBudBatteryLevel(unsigned battery_level);
|
||||
|
||||
void nearby_test_fakes_SetLeftBudBatteryLevel(unsigned battery_level, bool charging);
|
||||
void nearby_test_fakes_SetLeftBudBatteryLevel(unsigned battery_level);
|
||||
|
||||
#if NEARBY_BATTERY_LEVELS_SIZE >= 3
|
||||
void nearby_test_fakes_SetChargingCaseBatteryLevel(unsigned battery_level, bool charging);
|
||||
#endif
|
||||
void nearby_test_fakes_SetChargingCaseBatteryLevel(unsigned battery_level);
|
||||
|
||||
#ifdef NEARBY_SPOT_BATTERY_LEVEL_INDICATION
|
||||
void nearby_test_fakes_SetMainBatteryLevel(unsigned battery_level);
|
||||
#endif /* NEARBY_SPOT_BATTERY_LEVEL_INDICATION */
|
||||
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
void nearby_test_fakes_BatteryTime(uint16_t battery_time);
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
|
||||
void nearby_test_fakes_SetGetBatteryInfoResult(nearby_platform_status status);
|
||||
|
||||
@@ -196,10 +171,6 @@ void nearby_test_fakes_SetCurrentTimeMs(uint32_t ms);
|
||||
|
||||
void nearby_test_fakes_SetInPairingMode(bool in_pairing_mode);
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
void nearby_test_fakes_SetHasUserContentForReadingEik(bool has_user_consent);
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
uint8_t nearby_test_fakes_GetRingCommand(void);
|
||||
|
||||
uint16_t nearby_test_fakes_GetRingTimeout(void);
|
||||
@@ -216,7 +187,7 @@ void nearby_test_fakes_SassMultipointSwitch(uint8_t reason,
|
||||
uint64_t peer_address,
|
||||
const char* name);
|
||||
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
void nearby_test_fakes_SetActiveAudioSource(uint64_t peer_address);
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
|
||||
|
||||
@@ -12,40 +12,21 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
|
||||
#include "nearby.h"
|
||||
#include "nearby_assert.h"
|
||||
#include "nearby_fp_library.h"
|
||||
#include "nearby_platform_os.h"
|
||||
|
||||
const char firmware_revision[] = {'1', '.', '0', '.', '0', '\0'};
|
||||
bool has_user_consent_for_reading_eik = false;
|
||||
|
||||
typedef void (*timer)();
|
||||
struct TimerInfo {
|
||||
TimerInfo(timer callback, uint32_t trigger_time)
|
||||
: callback_(callback), trigger_time_(trigger_time) {}
|
||||
timer callback_;
|
||||
uint32_t trigger_time_;
|
||||
bool has_run_ = false;
|
||||
};
|
||||
static std::map<long, TimerInfo> timers;
|
||||
static long timer_key = 0;
|
||||
static timer timer_callback;
|
||||
static uint32_t timer_trigger_time;
|
||||
static bool timer_has_run;
|
||||
static uint32_t current_time;
|
||||
static const nearby_platform_OsInterface* callbacks;
|
||||
static uint32_t seconds = 50000;
|
||||
static constexpr nearby_platform_RingingInfo kDefaultRingingInfo = {
|
||||
.ring_state = kRingStateStoppedReasonTimeout,
|
||||
.num_components = 3,
|
||||
.components = 0,
|
||||
.timeout = 0,
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
.volume = kRingingVolumeDefault,
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
};
|
||||
|
||||
static nearby_platform_RingingInfo ringing_info = kDefaultRingingInfo;
|
||||
@@ -53,92 +34,37 @@ static nearby_platform_RingingInfo ringing_info = kDefaultRingingInfo;
|
||||
// Gets current time in ms.
|
||||
unsigned int nearby_platform_GetCurrentTimeMs() { return current_time; }
|
||||
|
||||
uint32_t nearby_platform_GetPersistentTime() { return seconds; }
|
||||
|
||||
nearby_platform_status nearby_platform_GetRingingInfo(
|
||||
nearby_platform_RingingInfo* ringing_info) {
|
||||
*ringing_info = ::ringing_info;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_Ring(
|
||||
uint8_t command, uint16_t timeout, nearby_platform_RingingVolume volume) {
|
||||
ringing_info.components = command;
|
||||
ringing_info.timeout = timeout;
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
ringing_info.volume = volume;
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
ringing_info.ring_state = kRingStateStarted;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
/* returns user consent as true if reading of EIK is permitted (when in
|
||||
EIK recovery mode) by a button press or other user action */
|
||||
bool nearby_platform_HasUserConsentForReadingEik(void)
|
||||
{
|
||||
return has_user_consent_for_reading_eik;
|
||||
}
|
||||
|
||||
void nearby_test_fakes_SetHasUserContentForReadingEik(bool has_user_consent) {
|
||||
has_user_consent_for_reading_eik = has_user_consent;
|
||||
}
|
||||
|
||||
/* Perform a factory reset and clear all stored Account Keys */
|
||||
nearby_platform_status nearby_platform_FactoryReset() {
|
||||
// Clear all the account keys
|
||||
return nearby_fp_ClearAccountKeys();
|
||||
}
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Starts a timer. Returns an opaque timer handle or null on error.
|
||||
void* nearby_platform_StartTimer(void (*callback)(), unsigned int delay_ms) {
|
||||
long key = timer_key++;
|
||||
timers.emplace(std::make_pair(
|
||||
key, TimerInfo(callback, nearby_platform_GetCurrentTimeMs() + delay_ms)));
|
||||
return reinterpret_cast<void*>(key);
|
||||
timer_callback = callback;
|
||||
timer_trigger_time = nearby_platform_GetCurrentTimeMs() + delay_ms;
|
||||
timer_has_run = false;
|
||||
return (void*)timer_callback;
|
||||
}
|
||||
|
||||
// Cancels a timer
|
||||
nearby_platform_status nearby_platform_CancelTimer(void* timer) {
|
||||
long key = reinterpret_cast<long>(timer);
|
||||
auto timer_info = timers.find(key);
|
||||
NEARBY_ASSERT(timer_info != timers.end());
|
||||
timers.erase(timer_info);
|
||||
NEARBY_ASSERT(timer == timer_callback);
|
||||
timer_callback = NULL;
|
||||
timer_trigger_time = 0;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
uint32_t nearby_test_fakes_GetNextTimerMs() {
|
||||
uint32_t timer_trigger_time = std::numeric_limits<uint32_t>::max();
|
||||
std::for_each(
|
||||
timers.begin(), timers.end(),
|
||||
[&timer_trigger_time](std::pair<long, TimerInfo> elem) {
|
||||
auto timer = elem.second;
|
||||
if (!timer.has_run_ && timer.trigger_time_ < timer_trigger_time) {
|
||||
timer_trigger_time = timer.trigger_time_;
|
||||
}
|
||||
});
|
||||
// Returns 0 if there are no timers set
|
||||
return timer_trigger_time != std::numeric_limits<uint32_t>::max()
|
||||
? timer_trigger_time
|
||||
: 0;
|
||||
}
|
||||
uint32_t nearby_test_fakes_GetNextTimerMs() { return timer_trigger_time; }
|
||||
|
||||
void nearby_test_fakes_SetCurrentTimeMs(uint32_t ms) {
|
||||
current_time = ms;
|
||||
std::for_each(timers.begin(), timers.end(),
|
||||
[ms](std::pair<long, TimerInfo> elem) {
|
||||
auto timer = elem.second;
|
||||
if (!timer.has_run_ && timer.callback_ != NULL &&
|
||||
timer.trigger_time_ <= ms) {
|
||||
timer.has_run_ = true;
|
||||
timer.callback_();
|
||||
}
|
||||
});
|
||||
if (!timer_has_run && timer_callback != NULL && timer_trigger_time <= ms) {
|
||||
timer_has_run = true;
|
||||
timer_callback();
|
||||
}
|
||||
}
|
||||
|
||||
void nearby_test_fakes_SetRingingInfo(const nearby_platform_RingingInfo* info) {
|
||||
ringing_info = *info;
|
||||
nearby_platform_status nearby_platform_Ring(uint8_t command, uint16_t timeout) {
|
||||
ringing_info.components = command;
|
||||
ringing_info.timeout = timeout;
|
||||
ringing_info.ring_state = kRingStateStarted;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
uint8_t nearby_test_fakes_GetRingCommand(void) {
|
||||
@@ -147,21 +73,10 @@ uint8_t nearby_test_fakes_GetRingCommand(void) {
|
||||
|
||||
uint16_t nearby_test_fakes_GetRingTimeout(void) { return ringing_info.timeout; }
|
||||
|
||||
void nearby_test_fakes_NotifyRingStateChanged() {
|
||||
callbacks->on_ring_state_change();
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_OsInit(
|
||||
const nearby_platform_OsInterface* os_interface) {
|
||||
callbacks = os_interface;
|
||||
nearby_platform_status nearby_platform_OsInit() {
|
||||
current_time = 0;
|
||||
timers.clear();
|
||||
ringing_info = kDefaultRingingInfo;
|
||||
has_user_consent_for_reading_eik = false;
|
||||
timer_callback = NULL;
|
||||
timer_trigger_time = 0;
|
||||
timer_has_run = false;
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
// Gets the firmware string
|
||||
const char* nearby_platform_GetFirmwareRevision(void) {
|
||||
return firmware_revision;
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <vector>
|
||||
|
||||
#include "fakes.h"
|
||||
#include "nearby.h"
|
||||
#include "nearby_platform_persistence.h"
|
||||
|
||||
static std::map<nearby_fp_StoredKey, std::vector<uint8_t>> storage;
|
||||
@@ -47,16 +46,6 @@ nearby_platform_status nearby_platform_SaveValue(nearby_fp_StoredKey key,
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_ClearValue(nearby_fp_StoredKey key) {
|
||||
storage.erase(key);
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_ClearAllValue() {
|
||||
storage.clear();
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_platform_PersistenceInit() {
|
||||
storage.clear();
|
||||
return kNearbyStatusOK;
|
||||
|
||||
@@ -26,11 +26,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "fakes.h"
|
||||
#include "nearby.h"
|
||||
#include "nearby_platform_se.h"
|
||||
#include "nearby_trace.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
@@ -200,27 +196,6 @@ nearby_platform_status nearby_platform_GenSec256r1Secret(
|
||||
}
|
||||
#endif /* NEARBY_PLATFORM_HAS_SE */
|
||||
|
||||
#ifndef NEARBY_PLATFORM_USE_MBEDTLS
|
||||
nearby_platform_status nearby_platform_Aes256Encrypt(const uint8_t input[16],
|
||||
uint8_t output[16],
|
||||
const uint8_t key[32]) {
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
int input_length = 16;
|
||||
int output_length = 16;
|
||||
uint8_t buffer[16];
|
||||
|
||||
EVP_EncryptInit(ctx, EVP_aes_256_ecb(), key, NULL);
|
||||
|
||||
if (1 !=
|
||||
EVP_EncryptUpdate(ctx, buffer, &output_length, input, input_length)) {
|
||||
return kNearbyStatusError;
|
||||
}
|
||||
memcpy(output, buffer, 16);
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nearby_test_fakes_SetRandomNumber(unsigned int value) {
|
||||
random_value = value;
|
||||
}
|
||||
@@ -284,4 +259,4 @@ nearby_platform_status nearby_platform_SecureElementInit() {
|
||||
random_value = 0;
|
||||
random_sequence = std::queue<uint8_t>();
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -119,23 +119,3 @@ exit:
|
||||
mbedtls_aes_free(&ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a data block with AES256 in ECB mode. The `input` and `output`
|
||||
* parameters may be the same array.
|
||||
*/
|
||||
nearby_platform_status nearby_platform_Aes256Encrypt(
|
||||
const uint8_t input[AES_MESSAGE_SIZE_BYTES],
|
||||
uint8_t output[AES_MESSAGE_SIZE_BYTES],
|
||||
const uint8_t key[AES256_KEY_SIZE]) {
|
||||
nearby_platform_status status = kNearbyStatusError;
|
||||
mbedtls_aes_context ctx;
|
||||
mbedtls_aes_init(&ctx);
|
||||
if (mbedtls_aes_setkey_enc(&ctx, key, 256) != 0) goto exit;
|
||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, input, output) != 0)
|
||||
goto exit;
|
||||
status = kNearbyStatusOK;
|
||||
exit:
|
||||
mbedtls_aes_free(&ctx);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
all:
|
||||
gcc -DuECC_ENABLE_VLI_API=1 -DuECC_VLI_NATIVE_LITTLE_ENDIAN=1 -DuECC_SUPPORTS_secp160r1=1 -c -o uECC.o uECC.c
|
||||
ar rcs libmicro-ecc.a uECC.o
|
||||
cp libmicro-ecc.a ../../../out/gLinux/third_party/micro-ecc
|
||||
clean:
|
||||
rm -f libmicro-ecc.a
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <nearby.h>
|
||||
#include <uECC.h>
|
||||
#include <uECC_vli.h>
|
||||
|
||||
#include "nearby_fp_library.h"
|
||||
#include "nearby_platform_se.h"
|
||||
#include "nearby_trace.h"
|
||||
|
||||
nearby_platform_status nearby_platform_GetSecp160r1PublicKey(
|
||||
const uint8_t private_key[32], uint8_t output[20],
|
||||
uint8_t *hashed_flag_field) {
|
||||
uECC_Curve curve = uECC_secp160r1();
|
||||
uint8_t public_key[40];
|
||||
uint8_t priv[48];
|
||||
|
||||
memset(priv, 0, 48);
|
||||
memset(public_key, 0, 40);
|
||||
memset(output, 0, 20);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
priv[i] = private_key[31 - i];
|
||||
}
|
||||
|
||||
uECC_vli_mmod((uECC_word_t *)priv, (uECC_word_t *)priv, uECC_curve_n(curve),
|
||||
uECC_curve_num_n_words(curve));
|
||||
|
||||
// r should be aligned to the curve’s size: zeros should be added as most
|
||||
// significant bits if its representation is shorter than 160/256 bits, or the
|
||||
// most significant bits should be truncated if its representation is larger
|
||||
// than 160/256 bits.
|
||||
// make sure big endian format is passed as SHA256 input
|
||||
for (int i = 0; i < 20; i++) {
|
||||
output[i] = priv[19 - i];
|
||||
}
|
||||
|
||||
if (nearby_fp_Sha256(public_key, output, 20) != kNearbyStatusOK) {
|
||||
NEARBY_TRACE(ERROR, "failed to generate hashed field");
|
||||
*hashed_flag_field = 0;
|
||||
} else {
|
||||
// the least significant byte of SHA256(r)
|
||||
*hashed_flag_field = public_key[31];
|
||||
}
|
||||
|
||||
memset(public_key, 0, 40);
|
||||
int ret = uECC_compute_public_key(priv, public_key, curve);
|
||||
|
||||
memset(output, 0, 20);
|
||||
if (ret == 1) {
|
||||
NEARBY_TRACE(INFO, "public key generated");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
output[i] = public_key[19 - i];
|
||||
}
|
||||
return kNearbyStatusOK;
|
||||
}
|
||||
NEARBY_TRACE(ERROR, "failed to generate public key: %d", ret);
|
||||
return kNearbyStatusError;
|
||||
}
|
||||
@@ -20,24 +20,11 @@
|
||||
#define NEARBY_FP_ENABLE_BATTERY_NOTIFICATION 1
|
||||
#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */
|
||||
|
||||
// Define number of battery component used
|
||||
#define NEARBY_BATTERY_LEVELS_SIZE 3
|
||||
|
||||
// Support FP Battery Remaining Time
|
||||
#ifndef NEARBY_BATTERY_REMAINING_TIME
|
||||
#define NEARBY_BATTERY_REMAINING_TIME 1
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
|
||||
// Support FP Additional Data extension
|
||||
#ifndef NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
#define NEARBY_FP_ENABLE_ADDITIONAL_DATA 1
|
||||
#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */
|
||||
|
||||
// Support Eddystone-E2EE-EID aka SPOT
|
||||
#ifndef NEARBY_FP_ENABLE_SPOT
|
||||
#define NEARBY_FP_ENABLE_SPOT 1
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Personalized name max size in bytes
|
||||
#define PERSONALIZED_NAME_MAX_SIZE 64
|
||||
|
||||
@@ -52,25 +39,12 @@
|
||||
// Does the platform have a native BLE address rotation routine?
|
||||
// #define NEARBY_FP_HAVE_BLE_ADDRESS_ROTATION
|
||||
|
||||
// Does the platform support interleaving LE advertisements?
|
||||
// If yes, the controller can be configured to send both FP and SPOT
|
||||
// advertisements at different intervals. The platform should implemnt both
|
||||
// `nearby_platform_SetAdvertisement()` and
|
||||
// `nearby_platform_SetSpotAdvertisement()` in this case.
|
||||
//
|
||||
// If not, Nearby SDK will alternate between FP and SPOT advertisements. The
|
||||
// plaftorm should implement only `nearby_platform_SetAdvertisement()` in this
|
||||
// case.
|
||||
#define NEARBY_FP_HAVE_MULTIPLE_ADVERTISEMENTS
|
||||
|
||||
// Support Smart Audio Source Switching
|
||||
#ifndef NEARBY_FP_ENABLE_SASS
|
||||
#define NEARBY_FP_ENABLE_SASS 1
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
// #define NEARBY_FP_ENABLE_SASS
|
||||
|
||||
// The maximum size in bytes of additional data in a message in Message Stream.
|
||||
// Bigger payloads will be truncated.
|
||||
#define MAX_MESSAGE_STREAM_PAYLOAD_SIZE 36
|
||||
#define MAX_MESSAGE_STREAM_PAYLOAD_SIZE 22
|
||||
|
||||
// The maximum number of concurrent RFCOMM connections
|
||||
#define NEARBY_MAX_RFCOMM_CONNECTIONS 2
|
||||
@@ -83,26 +57,6 @@
|
||||
// The maximum number of concurrent retroactive pairing process
|
||||
#define NEARBY_MAX_RETROACTIVE_PAIRING 2
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Add Battery level indication in Spot Advertisement
|
||||
#define NEARBY_SPOT_BATTERY_LEVEL_INDICATION
|
||||
|
||||
// Battery level threshold macros to define Normal, low and critically low
|
||||
#define NEARBY_SPOT_BATTERY_LEVEL_LOW_THRESHOLD 20
|
||||
#define NEARBY_SPOT_BATTERY_LEVEL_CRITICALLY_LOW_THRESHOLD 10
|
||||
|
||||
// Define size of the curve used by SPOT: 20 (BT4.2) for SECP160R1 and 32
|
||||
// (BT 5.0 & above) for SECP256R1
|
||||
#define NEARBY_SPOT_SECP_CURVE_SIZE 20
|
||||
|
||||
// Reset the device to factory defaults when Ephemeral Identity Key is
|
||||
// cleared for Locator Tags
|
||||
#ifndef NEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK
|
||||
#define NEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK 0
|
||||
#endif
|
||||
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Is this platform a BLE-only device?
|
||||
#ifndef NEARBY_FP_BLE_ONLY
|
||||
#define NEARBY_FP_BLE_ONLY 0
|
||||
@@ -122,18 +76,4 @@
|
||||
|
||||
// The maximum number of account keys that can be stored on the device.
|
||||
#define NEARBY_MAX_ACCOUNT_KEYS 5
|
||||
|
||||
// When this flag is On, if the Seeker disconnects from the rfcomm/l2cap
|
||||
// endpoint during pairing, the pairing state will be reset, and pairing attempt
|
||||
// terminated.
|
||||
#ifndef NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT
|
||||
#define NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT 1
|
||||
#endif /* NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT */
|
||||
|
||||
// Set to 1 if the platform supports sending advertisements from different
|
||||
// BLE addresses at the same time.
|
||||
#ifndef NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES
|
||||
#define NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES 0
|
||||
#endif /* NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES */
|
||||
|
||||
#endif /* NEARBY_CONFIG_H */
|
||||
|
||||
@@ -112,16 +112,6 @@ typedef struct {
|
||||
// Handled by: Client app
|
||||
#define MESSAGE_CODE_PLATFORM_TYPE 8
|
||||
|
||||
// Direction: Provider -> Seeker
|
||||
// Handled by: Nearby Fast Pair library
|
||||
#define MESSAGE_CODE_FIRMWARE_REVISION 9
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Direction: Provider -> Seeker
|
||||
// Handled by: Client app
|
||||
#define MESSAGE_CODE_CURRENT_EDDYSTONE_IDENTIFIER 0x0B
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Direction: Provider -> Seeker
|
||||
// Handled by: Nearby Fast Pair library
|
||||
#define MESSAGE_CODE_SESSION_NONCE 0x0A
|
||||
@@ -136,26 +126,6 @@ typedef struct {
|
||||
#define MESSAGE_CODE_RING_LEFT 0
|
||||
#define MESSAGE_CODE_RING_RIGHT 1
|
||||
|
||||
// Message group Device capability sync event
|
||||
#define MESSAGE_GROUP_DEVICE_CAPABILITY_SYNC_EVENT 6
|
||||
|
||||
// Direction: Seeker -> Provider
|
||||
// Handled by: Nearby Fast Pair library
|
||||
#define MESSAGE_CODE_REQUEST_CAPABILITY_UPDATE 1
|
||||
|
||||
// Direction: Provider -> Seeker
|
||||
// Handled by: Nearby Fast Pair library
|
||||
#define MESSAGE_CODE_DYNAMIC_BUFFER_SIZE 2
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Direction: Provider -> Seeker
|
||||
// Handled by: Nearby Fast Pair library
|
||||
#define MESSAGE_CODE_EDDYSTONE_TRACKING 3
|
||||
|
||||
#define MESSAGE_CODE_EDDYSTONE_UNPROVISIONED 0
|
||||
#define MESSAGE_CODE_EDDYSTONE_PROVISIONED 1
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Payload for |kNearbyEventMessageStreamReceived| event. See
|
||||
// https://developers.google.com/nearby/fast-pair/spec#MessageStream
|
||||
typedef struct {
|
||||
|
||||
@@ -48,9 +48,13 @@ typedef struct {
|
||||
#define ACCOUNT_KEY_LIST_SIZE_BYTES sizeof(AccountKeyList)
|
||||
#define SHOW_PAIRING_INDICATION_BYTE 0
|
||||
#define DONT_SHOW_PAIRING_INDICATION_BYTE 2
|
||||
#define SHOW_BATTERY_INDICATION_BYTE ((NEARBY_BATTERY_LEVELS_SIZE << 4) | 0x3)
|
||||
#define DONT_SHOW_BATTERY_INDICATION_BYTE \
|
||||
((NEARBY_BATTERY_LEVELS_SIZE << 4) | 0x4)
|
||||
#define SHOW_BATTERY_INDICATION_BYTE 0x33
|
||||
#define DONT_SHOW_BATTERY_INDICATION_BYTE 0x34
|
||||
#define BATTERY_INFO_CHARGING (1 << 7)
|
||||
#define BATTERY_INFO_NOT_CHARGING 0
|
||||
// In the battery values, the highest bit indicates charging, the lower 7 are
|
||||
// the battery level
|
||||
#define BATTERY_LEVEL_MASK 0x7F
|
||||
#define SALT_FIELD_LENGTH_AND_TYPE_BYTE ((NEARBY_FP_SALT_SIZE << 4) | 1)
|
||||
#define BATTERY_INFO_SIZE_BYTES 4
|
||||
// Response for seekers that don't support BLE-only devices.
|
||||
@@ -190,7 +194,7 @@ static bool AccountKeyInfoEquals(const nearby_platform_AccountKeyInfo* a,
|
||||
const nearby_platform_AccountKeyInfo* b) {
|
||||
return a == b ||
|
||||
(
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
a->peer_address == b->peer_address &&
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
!memcmp(a->account_key, b->account_key, ACCOUNT_KEY_SIZE_BYTES));
|
||||
@@ -248,11 +252,15 @@ size_t nearby_fp_CreateDiscoverableAdvertisement(uint8_t* output,
|
||||
#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION
|
||||
void SerializeBatteryInfo(uint8_t* output,
|
||||
const nearby_platform_BatteryInfo* battery_info) {
|
||||
int i;
|
||||
for (i = 0; i < NEARBY_BATTERY_LEVELS_SIZE; i++)
|
||||
output[i] = battery_info->battery_level[i];
|
||||
uint8_t charging = battery_info->is_charging ? BATTERY_INFO_CHARGING
|
||||
: BATTERY_INFO_NOT_CHARGING;
|
||||
output[0] =
|
||||
charging | (battery_info->left_bud_battery_level & BATTERY_LEVEL_MASK);
|
||||
output[1] =
|
||||
charging | (battery_info->right_bud_battery_level & BATTERY_LEVEL_MASK);
|
||||
output[2] = charging |
|
||||
(battery_info->charging_case_battery_level & BATTERY_LEVEL_MASK);
|
||||
}
|
||||
|
||||
static void AddBatteryInfo(uint8_t* output, size_t length,
|
||||
bool show_ui_indicator,
|
||||
const nearby_platform_BatteryInfo* battery_info) {
|
||||
@@ -463,12 +471,6 @@ nearby_platform_status nearby_fp_SaveAccountKeys() {
|
||||
GetAccountKeyListUsedSize());
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_fp_ClearAccountKeys() {
|
||||
size_t length = sizeof(account_key_list);
|
||||
memset(&account_key_list, 0, length);
|
||||
return nearby_platform_ClearAllValue();
|
||||
}
|
||||
|
||||
nearby_platform_status nearby_fp_GattReadModelId(uint8_t* output,
|
||||
size_t* length) {
|
||||
NEARBY_ASSERT(*length >= FP_MODEL_ID_SIZE);
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
|
||||
#define BT_ADDRESS_LENGTH 6
|
||||
#define DISCOVERABLE_ADV_SIZE_BYTES 10
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
// Sufficent for 5 account keys, battery notification and SASS info
|
||||
#define NON_DISCOVERABLE_ADV_SIZE_BYTES 32
|
||||
#else
|
||||
@@ -101,8 +101,6 @@ size_t nearby_fp_AppendTxPower(uint8_t* advertisement, size_t length,
|
||||
nearby_platform_status nearby_fp_LoadAccountKeys();
|
||||
// Saves account keys to NV storage.
|
||||
nearby_platform_status nearby_fp_SaveAccountKeys();
|
||||
// Clears account keys from NV storage
|
||||
nearby_platform_status nearby_fp_ClearAccountKeys();
|
||||
|
||||
// Gets Specific key by number to buffer
|
||||
//
|
||||
|
||||
@@ -32,20 +32,16 @@ void nearby_utils_CopyLittleEndian(uint8_t* dest, uint64_t source, int bytes) {
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t nearby_utils_GetBigEndian16(const uint8_t* buffer) {
|
||||
return (256 * buffer[0]) + buffer[1];
|
||||
}
|
||||
|
||||
uint32_t nearby_utils_GetBigEndian24(const uint8_t* buffer) {
|
||||
uint32_t nearby_utils_GetBigEndian24(uint8_t* buffer) {
|
||||
return (256 * 256 * buffer[0]) + (256 * buffer[1]) + buffer[2];
|
||||
}
|
||||
|
||||
uint32_t nearby_utils_GetBigEndian32(const uint8_t* buffer) {
|
||||
uint32_t nearby_utils_GetBigEndian32(uint8_t* buffer) {
|
||||
return (256 * 256 * 256 * buffer[0]) + (256 * 256 * buffer[1]) +
|
||||
(256 * buffer[2]) + buffer[3];
|
||||
}
|
||||
|
||||
uint64_t nearby_utils_GetBigEndian48(const uint8_t* b) {
|
||||
uint64_t nearby_utils_GetBigEndian48(uint8_t* b) {
|
||||
return (((uint64_t)b[0]) << 40) | (((uint64_t)b[1]) << 32) |
|
||||
(((uint64_t)b[2]) << 24) | (((uint64_t)b[3]) << 16) |
|
||||
(((uint64_t)b[4]) << 8) | (uint64_t)b[5];
|
||||
|
||||
@@ -26,10 +26,9 @@ uint8_t nearby_utils_GetByte(uint64_t source, int byteNumber);
|
||||
void nearby_utils_CopyBigEndian(uint8_t* dest, uint64_t source, int bytes);
|
||||
void nearby_utils_CopyLittleEndian(uint8_t* dest, uint64_t source, int bytes);
|
||||
|
||||
uint16_t nearby_utils_GetBigEndian16(const uint8_t* buffer);
|
||||
uint32_t nearby_utils_GetBigEndian24(const uint8_t* buffer);
|
||||
uint32_t nearby_utils_GetBigEndian32(const uint8_t* buffer);
|
||||
uint64_t nearby_utils_GetBigEndian48(const uint8_t* buffer);
|
||||
uint32_t nearby_utils_GetBigEndian24(uint8_t* buffer);
|
||||
uint32_t nearby_utils_GetBigEndian32(uint8_t* buffer);
|
||||
uint64_t nearby_utils_GetBigEndian48(uint8_t* buffer);
|
||||
|
||||
// Converts the data to a hex string for debugging. Returns a pointer to a
|
||||
// static buffer. Don't call it twice in the same log message!
|
||||
|
||||
@@ -35,7 +35,7 @@ extern "C" {
|
||||
|
||||
typedef struct {
|
||||
uint8_t account_key[ACCOUNT_KEY_SIZE_BYTES];
|
||||
#if NEARBY_FP_ENABLE_SASS
|
||||
#ifdef NEARBY_FP_ENABLE_SASS
|
||||
uint64_t peer_address;
|
||||
#endif /* NEARBY_FP_ENABLE_SASS */
|
||||
} nearby_platform_AccountKeyInfo;
|
||||
|
||||
@@ -21,38 +21,17 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
// One byte per left, right and charging case
|
||||
#define NEARBY_BATTERY_LEVELS_SIZE 3
|
||||
|
||||
#define NEARBY_PLATFORM_BATTERY_INFO_CHARGING (1 << 7)
|
||||
#define NEARBY_PLATFORM_BATTERY_INFO_NOT_CHARGING 0
|
||||
// In the battery values, the highest bit indicates charging, the lower 7 are
|
||||
// the battery level
|
||||
#define NEARBY_PLATFORM_BATTERY_LEVEL_MASK 0x7F
|
||||
|
||||
enum NearbyBatteryLevelIndex {
|
||||
kNearbyLeftBudBatteryLevel = 0,
|
||||
kNearbyRightBudBatteryLevel = 1,
|
||||
kNearbyChargingCaseBatteryLevel = 2
|
||||
};
|
||||
|
||||
#define NEARBY_PLATFORM_SET_BATTERY_LEVEL(level, charging) \
|
||||
(charging << 7) | (level & NEARBY_PLATFORM_BATTERY_LEVEL_MASK)
|
||||
|
||||
#define NEARBY_PLATFORM_GET_BATTERY_LEVEL(level) \
|
||||
(level & NEARBY_PLATFORM_BATTERY_LEVEL_MASK)
|
||||
|
||||
#define NEARBY_PLATFORM_GET_IS_CHARGING(level) \
|
||||
(level & NEARBY_PLATFORM_BATTERY_INFO_CHARGING)
|
||||
|
||||
typedef struct {
|
||||
// Bit 7 : Set to 1 if the device is charging.
|
||||
// Bit 6-0: Battery level 0 - 100 range.
|
||||
uint8_t battery_level[NEARBY_BATTERY_LEVELS_SIZE];
|
||||
#if NEARBY_BATTERY_REMAINING_TIME
|
||||
// Set to true if the device is charging.
|
||||
bool is_charging;
|
||||
// Battery level of the right bud. 0 - 100 range.
|
||||
uint8_t right_bud_battery_level;
|
||||
// Battery level of the left bud. 0 - 100 range.
|
||||
uint8_t left_bud_battery_level;
|
||||
// Battery level of the charging case . 0 - 100 range.
|
||||
uint8_t charging_case_battery_level;
|
||||
// Battery remaining time in minutes, 0-65335 range.
|
||||
uint16_t remaining_time_minutes;
|
||||
#endif /* NEARBY_BATTERY_REMAINING_TIME */
|
||||
} nearby_platform_BatteryInfo;
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
#ifndef NEARBY_PLATFORM_BLE_H
|
||||
#define NEARBY_PLATFORM_BLE_H
|
||||
|
||||
// clang-format off
|
||||
#include "nearby_config.h"
|
||||
// clang-format on
|
||||
#include "nearby.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -31,7 +28,6 @@ typedef enum {
|
||||
kAccountKey, // FE2C1236-8366-4814-8EB0-01DE32100BEA (write)
|
||||
kFirmwareRevision, // 0x2A26
|
||||
kAdditionalData, // FE2C1237-8366-4814-8EB0-01DE32100BEA
|
||||
kBeaconActions, // FE2C1238-8366-4814-8EB0-01DE32100BEA
|
||||
// Message Stream PSM characteristic is required to establish an L2CAP
|
||||
// communication channel between Seeker and Provider. Platforms that don't
|
||||
// support L2CAP channel may choose not to implement this characteristic.
|
||||
@@ -42,8 +38,7 @@ typedef enum {
|
||||
typedef enum {
|
||||
kDisabled,
|
||||
kNoLargerThan100ms,
|
||||
kNoLargerThan250ms,
|
||||
kNoLargerThan2Seconds,
|
||||
kNoLargerThan250ms
|
||||
} nearby_fp_AvertisementInterval;
|
||||
|
||||
typedef struct {
|
||||
@@ -90,15 +85,6 @@ nearby_platform_status nearby_platform_GattNotify(
|
||||
uint64_t peer_address, nearby_fp_Characteristic characteristic,
|
||||
const uint8_t* message, size_t length);
|
||||
|
||||
// Sends a notification to all subscribed GATT clients.
|
||||
//
|
||||
// characteristic - Characteristic UUID
|
||||
// message - Message buffer to transmit.
|
||||
// length - Length of message in buffer.
|
||||
nearby_platform_status nearby_platform_GattNotifyAll(
|
||||
nearby_fp_Characteristic characteristic, const uint8_t* message,
|
||||
size_t length);
|
||||
|
||||
// Sets the Fast Pair advertisement payload and starts advertising at a given
|
||||
// interval.
|
||||
//
|
||||
@@ -109,20 +95,6 @@ nearby_platform_status nearby_platform_SetAdvertisement(
|
||||
const uint8_t* payload, size_t length,
|
||||
nearby_fp_AvertisementInterval interval);
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Sets the spot advertisement payload and starts advertising. When `payload` is
|
||||
// null, the advertising should stop.
|
||||
// The spot advertisement should be advertised once every 2 seconds, interleaved
|
||||
// with Fast Pair advertisements if necessary. Ideally, the advertisement should
|
||||
// continue even when the device is turned off. How else would the user find it?
|
||||
//
|
||||
// payload - Advertising data.
|
||||
// length - Length of data.
|
||||
// address - the BLE address that the advertisements should be sent from.
|
||||
nearby_platform_status nearby_platform_SetSpotAdvertisement(
|
||||
uint64_t address, const uint8_t* payload, size_t length);
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Initializes BLE
|
||||
//
|
||||
// ble_interface - GATT read and write callbacks structure.
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
#ifndef NEARBY_PLATFORM_OS_H
|
||||
#define NEARBY_PLATFORM_OS_H
|
||||
|
||||
// clang-format off
|
||||
#include "nearby_config.h"
|
||||
// clang-format on
|
||||
#include "nearby.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -32,13 +29,6 @@ typedef enum {
|
||||
kRingStateStoppedReasonNearbyRequest
|
||||
} nearby_platform_RingState;
|
||||
|
||||
typedef enum {
|
||||
kRingingVolumeDefault = 0,
|
||||
kRingingVolumeLow,
|
||||
kRingingVolumeMedium,
|
||||
kRingingVolumeHigh
|
||||
} nearby_platform_RingingVolume;
|
||||
|
||||
typedef struct {
|
||||
nearby_platform_RingState ring_state;
|
||||
// The number of components capable of ringing
|
||||
@@ -52,68 +42,11 @@ typedef struct {
|
||||
uint8_t components;
|
||||
// Remaining ringing timeout in deciseconds
|
||||
uint16_t timeout;
|
||||
// A byte indicates the ringing volume :
|
||||
// 0x00 : default
|
||||
// 0x01 : low
|
||||
// 0x02 : medium
|
||||
// 0x03 : high
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
nearby_platform_RingingVolume volume;
|
||||
#endif
|
||||
} nearby_platform_RingingInfo;
|
||||
|
||||
typedef struct {
|
||||
// Notifies Nearby SDK that ring state has changed
|
||||
void (*on_ring_state_change)();
|
||||
} nearby_platform_OsInterface;
|
||||
|
||||
// Gets current time in ms.
|
||||
unsigned int nearby_platform_GetCurrentTimeMs();
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Gets current, persistent time in seconds.
|
||||
// This clock must be (at least) 32 bit. Since the resolving of the Eddystone
|
||||
// identifier is strongly tied to its clock value at the time of the
|
||||
// advertisement, it is important that the Provider is able to recover its clock
|
||||
// value in the event of power loss. We recommend that it writes its current
|
||||
// clock value to non-volatile memory once per day, and that at boot time it
|
||||
// checks the NVM to see if there's a value present from which to initialise.
|
||||
// Resolvers of the ephemeral ID would implement resolution over a time window
|
||||
// sufficient to allow for both reasonable clock drift and this type of power
|
||||
// loss recovery.
|
||||
uint32_t nearby_platform_GetPersistentTime();
|
||||
|
||||
nearby_platform_status nearby_platform_GetRingingInfo(
|
||||
nearby_platform_RingingInfo* ringing_info);
|
||||
|
||||
// Returns true if the device has consented to read EIK (Ephemeral Identity Key)
|
||||
// typically done during EIK recovery mode. The EIK recovery mode can be entered for
|
||||
// some limited time after a physical button was pressed on the device (which constitutes the “user
|
||||
// consent”).
|
||||
bool nearby_platform_HasUserConsentForReadingEik(void);
|
||||
|
||||
// Perform factory reset of device
|
||||
nearby_platform_status nearby_platform_FactoryReset(void);
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Starts ringing
|
||||
//
|
||||
// `command` - the requested ringing state as a bitmap:
|
||||
// Bit 1 (0x01): ring right
|
||||
// Bit 2 (0x02): ring left
|
||||
// Bit 3 (0x04): ring case
|
||||
// Alternatively, `command` hold a special value of 0xFF to ring all
|
||||
// components that can ring.
|
||||
// `timeout` - the timeout in deciseconds. The timeout overrides the one already
|
||||
// in effect if any component of the device is already ringing.
|
||||
// 'volume' - the requested ringing volume :
|
||||
// 0x00 : default
|
||||
// 0x01 : low
|
||||
// 0x02 : medium
|
||||
// 0x03 : high
|
||||
nearby_platform_status nearby_platform_Ring(
|
||||
uint8_t command, uint16_t timeout, nearby_platform_RingingVolume volume);
|
||||
|
||||
// Starts a timer. Returns an opaque timer handle or null on error.
|
||||
//
|
||||
// callback - Function to call when timer matures.
|
||||
@@ -126,11 +59,20 @@ void* nearby_platform_StartTimer(void (*callback)(), unsigned int delay_ms);
|
||||
nearby_platform_status nearby_platform_CancelTimer(void* timer);
|
||||
|
||||
// Initializes OS module
|
||||
nearby_platform_status nearby_platform_OsInit(
|
||||
const nearby_platform_OsInterface* os_interface);
|
||||
nearby_platform_status nearby_platform_OsInit();
|
||||
|
||||
// Starts ringing
|
||||
//
|
||||
// `command` - the requested ringing state as a bitmap:
|
||||
// Bit 1 (0x01): ring right
|
||||
// Bit 2 (0x02): ring left
|
||||
// Bit 3 (0x04): ring case
|
||||
// Alternatively, `command` hold a special value of 0xFF to ring all
|
||||
// components that can ring.
|
||||
// `timeout` - the timeout in deciseconds. The timeout overrides the one already
|
||||
// in effect if any component of the device is already ringing.
|
||||
nearby_platform_status nearby_platform_Ring(uint8_t command, uint16_t timeout);
|
||||
|
||||
// Returns the firmware string
|
||||
const char* nearby_platform_GetFirmwareRevision(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -23,9 +23,7 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
kStoredKeyAccountKeyList,
|
||||
kStoredKeyPersonalizedName,
|
||||
kStoredKeyOwnerKey,
|
||||
kStoredKeyEphemeralKey
|
||||
kStoredKeyPersonalizedName
|
||||
} nearby_fp_StoredKey;
|
||||
|
||||
// Loads stored key
|
||||
@@ -47,12 +45,6 @@ nearby_platform_status nearby_platform_SaveValue(nearby_fp_StoredKey key,
|
||||
const uint8_t* input,
|
||||
size_t length);
|
||||
|
||||
// Clears the `key`, if it exists, from persistent storage.
|
||||
nearby_platform_status nearby_platform_ClearValue(nearby_fp_StoredKey key);
|
||||
|
||||
// Clears all keys from persistent storage.
|
||||
nearby_platform_status nearby_platform_ClearAllValue();
|
||||
|
||||
// Initializes persistence module
|
||||
nearby_platform_status nearby_platform_PersistenceInit();
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define AES256_KEY_SIZE 32
|
||||
|
||||
// Generates a random number.
|
||||
uint8_t nearby_platform_Rand();
|
||||
|
||||
@@ -72,27 +70,6 @@ nearby_platform_status nearby_platform_Aes128Decrypt(
|
||||
nearby_platform_status nearby_platform_GenSec256r1Secret(
|
||||
const uint8_t remote_party_public_key[64], uint8_t secret[32]);
|
||||
|
||||
#if NEARBY_FP_ENABLE_SPOT
|
||||
// Encrypts a data block with AES256 in ECB mode. The `input` and `output`
|
||||
// parameters may be the same array.
|
||||
nearby_platform_status nearby_platform_Aes256Encrypt(
|
||||
const uint8_t input[16], uint8_t output[16],
|
||||
const uint8_t key[AES256_KEY_SIZE]);
|
||||
|
||||
// Calculates the SECP160R1 public key from private key with hashed flag
|
||||
//
|
||||
// private_key - non-normalized private key
|
||||
// output - The 'x' coordinate of the public key
|
||||
// hashed_flag_lsb - least significant byte of SHA256(r) which is used as
|
||||
// output
|
||||
//
|
||||
// The `private_key` must be normalized to elliptic curve's finite field:
|
||||
// 'p = private_key mod n', where 'n' is SECP160R1's order.
|
||||
nearby_platform_status nearby_platform_GetSecp160r1PublicKey(
|
||||
const uint8_t private_key[32], uint8_t output[20],
|
||||
uint8_t* hashed_flag_lsb);
|
||||
#endif /* NEARBY_FP_ENABLE_SPOT */
|
||||
|
||||
// Returns anti-spoofing 128 bit private key.
|
||||
// Only used if the implementation also uses the
|
||||
// nearby_platform_GenSec256r1Secret() routine defined in gen_secret.c.
|
||||
|
||||
@@ -1,31 +1,17 @@
|
||||
### Nearby SDK for embedded systems release notes
|
||||
|
||||
## v2.2.0-embedded
|
||||
## v1.1.0-embedded-RC1
|
||||
Support GFPS 3.2 specification per [specification](https://developers.google.com/nearby/fast-pair/specifications/introduction).
|
||||
|
||||
New features:
|
||||
* Find My Device Network added
|
||||
* Added micro-ecc component
|
||||
|
||||
Other changes:
|
||||
* Merged all feature to main.
|
||||
* Fixed all the build issues.
|
||||
* Guarded the features with Macros.
|
||||
|
||||
## v1.1.0-embedded RC1
|
||||
Initial release supporting GFPS 3.2 per [specification](https://developers.google.com/nearby/fast-pair/specifications/introduction).
|
||||
|
||||
Supported features include:
|
||||
* Initial pairing with discoverable advertisement
|
||||
* Subsequent pairing with non-discoverable advertisement
|
||||
* Retroactive Active Key for provisioning after manual pairing
|
||||
* Battery Notification
|
||||
* Personalized Name
|
||||
* RFCOMM message stream
|
||||
* Unit-tests on a simulated gLinux platform implementation
|
||||
* Smart Audio Source Switching (SASS)
|
||||
* Two byte salt for improved security
|
||||
|
||||
Other changes:
|
||||
* Added optional encryption modules based on mbedtls.
|
||||
* Fixed build issues.
|
||||
* More verbose and readable logs.
|
||||
|
||||
## v1.0.0-embedded
|
||||
Initial release supporting GFPS 3.1 per [specification](https://developers.google.com/nearby/fast-pair/specifications/introduction).
|
||||
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
# Use MBEDTLS for test SSL i mplementation instead of OPENSSL
|
||||
# Use MBEDTLS for test SSL implementation instead of OPENSSL
|
||||
# Compiles in mbedtls implementation of a number of functions in se.h
|
||||
NEARBY_PLATFORM_USE_MBEDTLS ?= 0
|
||||
|
||||
# Use the hardware SE to generate the secp256r1 secret. Alternatively, generate
|
||||
# the secret in software.
|
||||
NEARBY_PLATFORM_HAS_SE ?= 1
|
||||
|
||||
# Use Micro-ecc for test nearby_platform_GetSecp160r1PublicKey implementation
|
||||
# instead of OPENSSL.
|
||||
NEARBY_PLATFORM_USE_MICROECC ?= 1
|
||||
|
||||
CFLAGS_EXTRA ?=
|
||||
CFLAGS += -g \
|
||||
-MD \
|
||||
@@ -22,7 +17,9 @@ CFLAGS += -g \
|
||||
-DNEARBY_ALL_MODULE_DEBUG \
|
||||
-DNEARBY_UNIT_TEST_ENABLED \
|
||||
$(CFLAGS_EXTRA)
|
||||
|
||||
NEARBY_TRACE_LEVEL = VERBOSE
|
||||
|
||||
ifeq ($(OPTIMIZED_BUILD),1)
|
||||
CFLAGS += -O2
|
||||
else
|
||||
@@ -33,37 +30,10 @@ ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
CFLAGS += -DNEARBY_PLATFORM_USE_MBEDTLS
|
||||
endif
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC),1)
|
||||
CFLAGS += -DNEARBY_PLATFORM_USE_MICROECC
|
||||
CFLAGS += -DuECC_ENABLE_VLI_API=1
|
||||
CFLAGS += -DuECC_VLI_NATIVE_LITTLE_ENDIAN=1
|
||||
CFLAGS += -DuECC_SUPPORTS_secp160r1=1
|
||||
endif
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_HAS_SE),1)
|
||||
CFLAGS += -DNEARBY_PLATFORM_HAS_SE
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_ENABLE_BATTERY_NOTIFICATION
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_BATTERY_NOTIFICATION=$(NEARBY_FP_ENABLE_BATTERY_NOTIFICATION)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_ENABLE_ADDITIONAL_DATA
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_ADDITIONAL_DATA=$(NEARBY_FP_ENABLE_ADDITIONAL_DATA)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_ENABLE_SPOT
|
||||
CFLAGS += -DNEARBY_FP_ENABLE_SPOT=$(NEARBY_FP_ENABLE_SPOT)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_MESSAGE_STREAM
|
||||
CFLAGS += -DNEARBY_FP_MESSAGE_STREAM=$(NEARBY_FP_MESSAGE_STREAM)
|
||||
endif
|
||||
|
||||
ifdef NEARBY_FP_RETROACTIVE_PAIRING
|
||||
CFLAGS += -DNEARBY_FP_RETROACTIVE_PAIRING=$(NEARBY_FP_RETROACTIVE_PAIRING)
|
||||
endif
|
||||
|
||||
TEST_INCLUDES = \
|
||||
-I$(GTEST_DIR)/include -I$(GTEST_DIR) \
|
||||
-I$(GMOCK_DIR)/include -I$(GMOCK_DIR) \
|
||||
@@ -74,8 +44,4 @@ TEST_INCLUDES = \
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
TEST_INCLUDES += -I$(MBEDTLS_DIR)/include
|
||||
endif
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC),1)
|
||||
TEST_INCLUDES += -I$(MICROECC_DIR)
|
||||
endif
|
||||
@@ -9,7 +9,6 @@ TEST_SRCS := $(filter-out $(TEST_SRCS_EXCLUDE), $(TEST_SRCS))
|
||||
TEST_OBJS += $(patsubst %.cc,$(OUT_DIR)/%.o,$(TEST_SRCS))
|
||||
GLINUX_TARGET_SRCS := $(wildcard client/tests/glinux/*.cc)
|
||||
MBEDTLS_TARGET_SRCS := $(wildcard common/source/mbedtls/*.c)
|
||||
|
||||
GTEST_SRCS = $(GTEST_DIR)/src/gtest-all.cc $(GMOCK_DIR)/src/gmock-all.cc
|
||||
EMPTY_TARGET_SRCS := $(wildcard client/tests/empty_target/*.c)
|
||||
|
||||
@@ -27,9 +26,6 @@ ALL_TEST_OBJS += $(EMPTY_TARGET_OBJS)
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
ALL_TEST_OBJS += $(MBEDTLS_TARGET_OBJS)
|
||||
endif
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
ALL_TEST_OBJS += $(MICROECC_TARGET_OBJS)
|
||||
endif
|
||||
|
||||
# The glinux target layer
|
||||
$(GLINUX_TARGET_OBJS) : $(OUT_DIR)/%.o: %.cc
|
||||
@@ -38,7 +34,6 @@ $(GLINUX_TARGET_OBJS) : $(OUT_DIR)/%.o: %.cc
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
# Mbed TLS interface files
|
||||
$(MBEDTLS_TARGET_OBJS) : $(OUT_DIR)/%.o: %.c
|
||||
@echo "mbedtls"
|
||||
$(call compile_c,$(TEST_INCLUDES) -I. -std=c99 -c $(CFLAGS))
|
||||
endif
|
||||
|
||||
@@ -65,16 +60,11 @@ TARGET_OBJS ?= $(GLINUX_TARGET_OBJS)
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
TARGET_OBJS += $(MBEDTLS_TARGET_OBJS)
|
||||
endif
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
TARGET_OBJS += $(MICROECC_TARGET_OBJS)
|
||||
endif
|
||||
|
||||
TARGET_OS_SRCS := $(wildcard client/tests/gLinux/*.cc)
|
||||
TARGET_MBEDTLS_SRCS += $(wildcard common/source/mbedtls/*.c)
|
||||
TARGET_MICROECC_SRCS += $(wildcard common/source/micro-ecc/*.c)
|
||||
TARGET_OS_OBJS ?= $(patsubst %.cc,$(OUT_DIR)/%.o,$(TARGET_OS_SRCS))
|
||||
TARGET_MBEDTLS_OBJS ?= $(patsubst %.c,$(OUT_DIR)/%.o,$(TARGET_MBEDTLS_SRCS))
|
||||
TARGET_MICROECC_OBJS ?= $(patsubst %.c,$(OUT_DIR)/%.o,$(TARGET_MICROECC_SRCS))
|
||||
$(TARGET_OS_OBJS) : $(OUT_DIR)/%.o: %.cc
|
||||
$(call compile_c,$(TEST_INCLUDES) -I. -std=c++14 $(CFLAGS))
|
||||
$(TARGET_MBED_OBJS) : $(OUT_DIR)/%.o: %.c
|
||||
@@ -85,9 +75,6 @@ ALL_TEST_OBJS += $(TARGET_OS_OBJS)
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
ALL_TEST_OBJS += $(TARGET_MBEDTLS_OBJS)
|
||||
endif
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
ALL_TEST_OBJS += $(TARGET_MICROECC_OBJS)
|
||||
endif
|
||||
|
||||
ALL_OBJS += $(ALL_TEST_OBJS)
|
||||
# Must include the .d files for test sources here since gLinux.rules is included
|
||||
@@ -98,20 +85,11 @@ EMPTY_TARGET_TEST = $(OUT_DIR)/client/tests/empty_target_test
|
||||
$(EMPTY_TARGET_TEST) : TARGET_OBJS = $(EMPTY_TARGET_OBJS)
|
||||
$(EMPTY_TARGET_TEST) : $(EMPTY_TARGET_OBJS)
|
||||
TEST_BINARIES = $(patsubst %.cc,$(OUT_DIR)/%,$(TEST_SRCS))
|
||||
|
||||
TEST_DEPS = $(NAME) $(GTEST_OBJS) $(GLINUX_TARGET_OBJS)
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MBEDTLS),1)
|
||||
TEST_DEPS += $(MBEDTLS_TARGET_OBJS)
|
||||
$(TEST_BINARIES) : $(NAME) $(GTEST_OBJS) $(GLINUX_TARGET_OBJS) $(MBEDTLS_TARGET_OBJS)
|
||||
else
|
||||
$(TEST_BINARIES) : $(NAME) $(GTEST_OBJS) $(GLINUX_TARGET_OBJS)
|
||||
endif
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
TEST_DEPS += $(MICROECC_TARGET_OBJS)
|
||||
endif
|
||||
|
||||
$(TEST_BINARIES) : $(TEST_DEPS)
|
||||
|
||||
$(TEST_BINARIES) : $(TARGET_OS_OBJS)
|
||||
|
||||
LIBS ?= -L $(OUT_DIR) -lnearby -lcrypto -lssl -lpthread -lstdc++
|
||||
@@ -124,13 +102,7 @@ $(TEST_BINARIES) : $(MBEDTLS_LIBS)
|
||||
LIBS += -L $(MBEDTLS_DIR)/library -lmbedtls -lmbedcrypto
|
||||
endif
|
||||
|
||||
ifeq ($(NEARBY_PLATFORM_USE_MICROECC), 1)
|
||||
LIBS += -L $(MICROECC_OUT_DIR) -lmicro-ecc
|
||||
$(TEST_BINARIES) : $(MICROECC_OUT_DIR)/libmicro-ecc.a
|
||||
endif
|
||||
|
||||
$(TEST_BINARIES) : % : %.o
|
||||
@echo "Compiling test binaries"
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) -o $@ $< \
|
||||
$(CFLAGS) \
|
||||
|
||||
Reference in New Issue
Block a user